Skip to content

Commit 54896b6

Browse files
committed
qcomgpio: Add reserved pin list and add one more ACPI pin mapping
1 parent 75430fc commit 54896b6

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

sys/dev/acpi/qcomgpio.c

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $ */
22

33
/*-
44
* Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
3030
*/
3131

3232
#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 $");
3434

3535
#include <sys/param.h>
3636
#include <sys/bus.h>
@@ -54,9 +54,16 @@ typedef enum {
5454
QCOMGPIO_X1E,
5555
} qcomgpio_type;
5656

57+
struct qcomgpio_reserved {
58+
int start;
59+
int count;
60+
};
61+
5762
struct qcomgpio_config {
5863
u_int num_pins;
5964
int (*translate)(ACPI_RESOURCE_GPIO *);
65+
struct qcomgpio_reserved *reserved;
66+
u_int num_reserved;
6067
};
6168

6269
struct qcomgpio_intr_handler {
@@ -87,6 +94,7 @@ struct qcomgpio_softc {
8794
static int qcomgpio_match(device_t, cfdata_t, void *);
8895
static void qcomgpio_attach(device_t, device_t, void *);
8996

97+
static bool qcomgpio_pin_reserved(struct qcomgpio_softc *, int);
9098
static int qcomgpio_pin_read(void *, int);
9199
static void qcomgpio_pin_write(void *, int, int);
92100
static void qcomgpio_pin_ctl(void *, int, int);
@@ -107,6 +115,13 @@ CFATTACH_DECL_NEW(qcomgpio, sizeof(struct qcomgpio_softc),
107115

108116
#define X1E_NUM_PINS 239
109117

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+
110125
static int
111126
qcomgpio_x1e_translate(ACPI_RESOURCE_GPIO *gpio)
112127
{
@@ -119,6 +134,8 @@ qcomgpio_x1e_translate(ACPI_RESOURCE_GPIO *gpio)
119134
switch (pin) {
120135
case 0x180:
121136
return 67;
137+
case 0x340:
138+
return 92;
122139
case 0x380:
123140
return 3;
124141
default:
@@ -129,6 +146,8 @@ qcomgpio_x1e_translate(ACPI_RESOURCE_GPIO *gpio)
129146
static struct qcomgpio_config qcomgpio_x1e_config = {
130147
.num_pins = X1E_NUM_PINS,
131148
.translate = qcomgpio_x1e_translate,
149+
.reserved = qcomgpio_x1e_reserved,
150+
.num_reserved = __arraycount(qcomgpio_x1e_reserved),
132151
};
133152

134153
static const struct device_compatible_entry compat_data[] = {
@@ -193,37 +212,13 @@ qcomgpio_attach(device_t parent, device_t self, void *aux)
193212
sc->sc_pins = kmem_zalloc(sizeof(*sc->sc_pins) *
194213
sc->sc_config->num_pins, KM_SLEEP);
195214
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);
219217
sc->sc_pins[pin].pin_num = pin;
220218
sc->sc_pins[pin].pin_intrcaps =
221219
GPIO_INTR_POS_EDGE | GPIO_INTR_NEG_EDGE |
222220
GPIO_INTR_DOUBLE_EDGE | GPIO_INTR_HIGH_LEVEL |
223221
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;
227222
}
228223

229224
sc->sc_gc.gp_cookie = sc;
@@ -346,6 +341,22 @@ qcomgpio_register_event(void *priv, struct acpi_event *ev,
346341
}
347342
}
348343

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+
349360
static int
350361
qcomgpio_pin_read(void *priv, int pin)
351362
{

0 commit comments

Comments
 (0)