-
Notifications
You must be signed in to change notification settings - Fork 0
/
hswgpio.c
350 lines (320 loc) · 6.38 KB
/
hswgpio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
typedef const uint16_t cte16_t;
typedef const uint32_t cte32_t;
/* Number of GPIOs (array size) */
#define GPIO_ARR_SIZE 95
/* Bit macro */
#define BIT(x) (1 << (x))
/* FIXME: Read these values from elsewhere */
static cte32_t gpio_own[3] = {
0xffff7fff,
0xff7bff7f,
0x7fffffbf,
};
static cte16_t pirq_to_ioxapic = 0x8400;
static cte32_t gpo_blink = 0x00000000;
static cte16_t gpi_nmi_en = 0x0000;
/*
* Note that inteltool only prints one GPI_ROUT register.
* Please also use the two RESERVED values right below GPI_ROUT.
*/
static cte32_t gpi_rout[3] = {
0x00050000,
0x00000000,
0x00050000,
};
static cte32_t alt_gpi_smi_en = 0x00000080;
static cte32_t gp_rst_sel[3] = {
0x01000000,
0x00000000,
0x00000000,
};
static cte32_t gpio_gc = 0x00000000;
static cte32_t gpi_ie[3] = {
0x00000000,
0x00000000,
0x00000000,
};
static cte32_t gp_config[GPIO_ARR_SIZE + GPIO_ARR_SIZE] = {
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x00000004,
0x00000004,
0x00000004,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x40000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x0000001d,
0x00000000,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000004,
0x00000004,
0x40000004,
0x00000004,
0x40000004,
0x00000004,
0x00000005,
0x00000004,
0x40000005,
0x00000004,
0x00000005,
0x00000004,
0x40000005,
0x00000000,
0x00000005,
0x00000000,
0x40000005,
0x00000004,
0x40000004,
0x00000004,
0x00000004,
0x00000004,
0x40000001,
0x00000004,
0x00000004,
0x00000004,
0x00000004,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x4000000d,
0x00000000,
0x40000004,
0x00000004,
0x40000004,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x40000005,
0x00000000,
0x40000015,
0x00000000,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x00000005,
0x00000000,
0x00000005,
0x00000000,
0x40000015,
0x00000000,
0x00000005,
0x00000004,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x00000005,
0x00000004,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x40000000,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x4000001d,
0x00000000,
0x00000005,
0x00000004,
0x40000004,
0x00000004,
0x40000005,
0x00000004,
0x40000004,
0x00000004,
0x40000004,
0x00000004,
0x00000005,
0x00000004,
0xc0000011,
0x00000004,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x40000005,
0x00000004,
0x00000000,
0x00000004,
0x40000004,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
0x00000005,
0x00000004,
};
#define GPIO_OWNER(gpio) (!!(gpio_own[(gpio) / 32] & BIT((gpio) % 32)))
#define GPIO_OWNER_ACPI 0
#define GPIO_OWNER_GPIO 1
#define GPO_BLINK(gpio) (!!(gpo_blink & BIT(gpio)))
#define GPI_NMI_EN(gpio) (!!(gpi_nmi_en & BIT((gpio) - 32)))
#define GPI_ROUT(gpio) (!!(gpi_rout[(gpio) / 32] & BIT((gpio) % 32)))
#define GPI_ROUT_SCI 0
#define GPI_ROUT_NMI_SMI 1
#define ALT_GPI_SMI_EN(gpio) (!!(alt_gpi_smi_en & BIT((gpio) - 32)))
#define GP_RST_SEL(gpio) (!!(gp_rst_sel[(gpio) / 32] & BIT((gpio) % 32)))
#define GPI_IE(gpio) (!!(gpi_ie[(gpio) / 32] & BIT((gpio) % 32)))
/* Accessors for GPnCONFIGA and GPnCONFIGB */
#define GP_CFG_A(gpio) (gp_config[0 + (gpio) + (gpio)])
#define GP_CFG_B(gpio) (gp_config[1 + (gpio) + (gpio)])
static const char *gpio_cfg(cte32_t gpio)
{
printf("\t{\n");
printf("\t\t.conf0 = 0x%08x,\n", GP_CFG_A(gpio));
printf("\t\t.conf1 = 0x%08x,\n", GP_CFG_B(gpio));
printf("\t\t.owner = %u,\n", GPIO_OWNER(gpio));
printf("\t\t.route = %u,\n", GPI_ROUT(gpio));
printf("\t\t.irqen = %u,\n", GPI_IE(gpio));
printf("\t\t.reset = %u,\n", GP_RST_SEL(gpio));
if (gpio < 32)
printf("\t\t.blink = %u,\n", GPO_BLINK(gpio));
return "}";
#if 0
cte32_t gpio_owner_gpio = GPIO_OWNER(gpio);
cte32_t gpio_route_smi = GPI_ROUT(gpio);
cte32_t gpio_irq_enable = GPI_IE(gpio);
cte32_t gpio_mode_gpio = GP_CFG_A(gpio) & (1 << 0);
cte32_t gpio_dir_input = GP_CFG_A(gpio) & (1 << 2);
cte32_t gpio_invert = GP_CFG_A(gpio) & (1 << 3);
cte32_t gpio_irq_level = GP_CFG_A(gpio) & (1 << 4);
cte32_t gpo_level_high = GP_CFG_A(gpio) & (1 << 31);
cte32_t gpio_pull_down = GP_CFG_B(gpio) & (1 << 0);
cte32_t gpio_pull_up = GP_CFG_B(gpio) & (1 << 1);
cte32_t gpio_sense_disable = GP_CFG_B(gpio) & (1 << 2);
if (!gpio_mode_gpio)
return "LP_GPIO_NATIVE";
if (gpio_dir_input) {
if (gpio_owner_gpio) {
if (gpio_sense_disable) {
return "LP_GPIO_UNUSED";
} else if (gpio_invert) {
return "LP_GPIO_INPUT_INVERT";
} else if (gpio_irq_enable) {
return (gpio_irq_level) ?
"LP_GPIO_IRQ_LEVEL":
"LP_GPIO_IRQ_EDGE";
} else {
return "LP_GPIO_INPUT";
}
} else {
if (gpio_invert) {
return (gpio_route_smi) ?
"LP_GPIO_ACPI_SMI":
"LP_GPIO_ACPI_SCI";
} else {
/* This should not happen */
return "LP_GPIO_UNUSED /* FIXME: Double-check this. */";
}
}
} else {
if (gpio_sense_disable) {
return (gpo_level_high) ?
"LP_GPIO_OUT_HIGH":
"LP_GPIO_OUT_LOW";
} else {
/* This should not happen */
return "LP_GPIO_UNUSED /* FIXME: Double-check this as well. */";
}
}
return "LP_GPIO_UNUSED /* FIXME: Confirm this is correct. */"; /* Default */
#endif
}
int main(void)
{
printf("/* SPDX-License-Identifier: GPL-2.0-only */\n");
printf("\n");
printf("#include <southbridge/intel/lynxpoint/lp_gpio.h>\n");
printf("\n");
printf("const struct pch_lp_gpio_map mainboard_gpio_map[] =\n{\n");
for (uint32_t i = 0; i < GPIO_ARR_SIZE; i++) {
printf("\t%s,\n", gpio_cfg(i));
}
printf("\tLP_GPIO_END,\n};\n\n");
return EXIT_SUCCESS;
}