1
- /* $NetBSD: qcomgpio.c,v 1.2 2024/12/09 22:10:25 jmcneill Exp $ */
1
+ /* $NetBSD: qcomgpio.c,v 1.3 2024/12/11 00:59:16 jmcneill Exp $ */
2
2
3
3
/*-
4
4
* Copyright (c) 2024 The NetBSD Foundation, Inc.
30
30
*/
31
31
32
32
#include <sys/cdefs.h>
33
- __KERNEL_RCSID (0 , "$NetBSD: qcomgpio.c,v 1.2 2024/12/09 22:10:25 jmcneill Exp $" );
33
+ __KERNEL_RCSID (0 , "$NetBSD: qcomgpio.c,v 1.3 2024/12/11 00:59:16 jmcneill Exp $" );
34
34
35
35
#include <sys/param.h>
36
36
#include <sys/bus.h>
@@ -54,9 +54,16 @@ typedef enum {
54
54
QCOMGPIO_X1E ,
55
55
} qcomgpio_type ;
56
56
57
+ struct qcomgpio_reserved {
58
+ int start ;
59
+ int count ;
60
+ };
61
+
57
62
struct qcomgpio_config {
58
63
u_int num_pins ;
59
64
int (* translate )(ACPI_RESOURCE_GPIO * );
65
+ struct qcomgpio_reserved * reserved ;
66
+ u_int num_reserved ;
60
67
};
61
68
62
69
struct qcomgpio_intr_handler {
@@ -87,6 +94,7 @@ struct qcomgpio_softc {
87
94
static int qcomgpio_match (device_t , cfdata_t , void * );
88
95
static void qcomgpio_attach (device_t , device_t , void * );
89
96
97
+ static bool qcomgpio_pin_reserved (struct qcomgpio_softc * , int );
90
98
static int qcomgpio_pin_read (void * , int );
91
99
static void qcomgpio_pin_write (void * , int , int );
92
100
static void qcomgpio_pin_ctl (void * , int , int );
@@ -107,6 +115,13 @@ CFATTACH_DECL_NEW(qcomgpio, sizeof(struct qcomgpio_softc),
107
115
108
116
#define X1E_NUM_PINS 239
109
117
118
+ static struct qcomgpio_reserved qcomgpio_x1e_reserved [] = {
119
+ { .start = 34 , .count = 2 },
120
+ { .start = 44 , .count = 4 },
121
+ { .start = 72 , .count = 2 },
122
+ { .start = 238 , .count = 1 },
123
+ };
124
+
110
125
static int
111
126
qcomgpio_x1e_translate (ACPI_RESOURCE_GPIO * gpio )
112
127
{
@@ -119,6 +134,8 @@ qcomgpio_x1e_translate(ACPI_RESOURCE_GPIO *gpio)
119
134
switch (pin ) {
120
135
case 0x180 :
121
136
return 67 ;
137
+ case 0x340 :
138
+ return 92 ;
122
139
case 0x380 :
123
140
return 3 ;
124
141
default :
@@ -129,6 +146,8 @@ qcomgpio_x1e_translate(ACPI_RESOURCE_GPIO *gpio)
129
146
static struct qcomgpio_config qcomgpio_x1e_config = {
130
147
.num_pins = X1E_NUM_PINS ,
131
148
.translate = qcomgpio_x1e_translate ,
149
+ .reserved = qcomgpio_x1e_reserved ,
150
+ .num_reserved = __arraycount (qcomgpio_x1e_reserved ),
132
151
};
133
152
134
153
static const struct device_compatible_entry compat_data [] = {
@@ -193,37 +212,13 @@ qcomgpio_attach(device_t parent, device_t self, void *aux)
193
212
sc -> sc_pins = kmem_zalloc (sizeof (* sc -> sc_pins ) *
194
213
sc -> sc_config -> num_pins , KM_SLEEP );
195
214
for (pin = 0 ; pin < sc -> sc_config -> num_pins ; pin ++ ) {
196
- #if notyet
197
- uint32_t ctl , func ;
198
-
199
- aprint_debuf_dev (self , "pin %u: " , pin );
200
- ctl = RD4 (sc , TLMM_GPIO_CTL (pin ));
201
- func = __SHIFTOUT (ctl , TLMM_GPIO_CTL_MUX );
202
-
203
- sc -> sc_pins [pin ].pin_caps = 0 ;
204
- if (func == TLMM_GPIO_CTL_MUX_GPIO ) {
205
- if ((ctl & TLMM_GPIO_CTL_OE ) != 0 ) {
206
- sc -> sc_pins [pin ].pin_caps |= GPIO_PIN_OUTPUT ;
207
- aprint_debug ("gpio output\n" );
208
- } else {
209
- sc -> sc_pins [pin ].pin_caps |= GPIO_PIN_INPUT ;
210
- aprint_debug ("gpio input\n" );
211
- }
212
- } else {
213
- aprint_debug ("func %#x\n" , func );
214
- }
215
- #else
216
- sc -> sc_pins [pin ].pin_caps =
217
- GPIO_PIN_INPUT | GPIO_PIN_OUTPUT ;
218
- #endif
215
+ sc -> sc_pins [pin ].pin_caps = qcomgpio_pin_reserved (sc , pin ) ?
216
+ 0 : (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT );
219
217
sc -> sc_pins [pin ].pin_num = pin ;
220
218
sc -> sc_pins [pin ].pin_intrcaps =
221
219
GPIO_INTR_POS_EDGE | GPIO_INTR_NEG_EDGE |
222
220
GPIO_INTR_DOUBLE_EDGE | GPIO_INTR_HIGH_LEVEL |
223
221
GPIO_INTR_LOW_LEVEL | GPIO_INTR_MPSAFE ;
224
-
225
- /* It's not safe to read all pins, so leave pin state unknown */
226
- sc -> sc_pins [pin ].pin_state = 0 ;
227
222
}
228
223
229
224
sc -> sc_gc .gp_cookie = sc ;
@@ -346,6 +341,22 @@ qcomgpio_register_event(void *priv, struct acpi_event *ev,
346
341
}
347
342
}
348
343
344
+ static bool
345
+ qcomgpio_pin_reserved (struct qcomgpio_softc * sc , int pin )
346
+ {
347
+ u_int n ;
348
+
349
+ for (n = 0 ; n < sc -> sc_config -> num_reserved ; n ++ ) {
350
+ if (pin >= sc -> sc_config -> reserved [n ].start &&
351
+ pin < sc -> sc_config -> reserved [n ].start +
352
+ sc -> sc_config -> reserved [n ].count ) {
353
+ return true;
354
+ }
355
+ }
356
+
357
+ return false;
358
+ }
359
+
349
360
static int
350
361
qcomgpio_pin_read (void * priv , int pin )
351
362
{
0 commit comments