Lines Matching +full:pin +full:- +full:val
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
59 { -1, 0, 0 }
65 return (bus_read_4(sc->sc_res[0], off)); in amdgpio_read_4()
70 uint32_t val) in amdgpio_write_4() argument
72 bus_write_4(sc->sc_res[0], off, val); in amdgpio_write_4()
76 amdgpio_is_pin_output(struct amdgpio_softc *sc, uint32_t pin) in amdgpio_is_pin_output() argument
78 uint32_t reg, val; in amdgpio_is_pin_output() local
81 /* Get the current pin state */ in amdgpio_is_pin_output()
84 reg = AMDGPIO_PIN_REGISTER(pin); in amdgpio_is_pin_output()
85 val = amdgpio_read_4(sc, reg); in amdgpio_is_pin_output()
87 if (val & BIT(OUTPUT_ENABLE_OFF)) in amdgpio_is_pin_output()
104 dprintf("busdev %p\n", sc->sc_busdev); in amdgpio_get_bus()
105 return (sc->sc_busdev); in amdgpio_get_bus()
115 *maxpin = sc->sc_npins - 1; in amdgpio_pin_max()
116 dprintf("npins %d maxpin %d\n", sc->sc_npins, *maxpin); in amdgpio_pin_max()
122 amdgpio_valid_pin(struct amdgpio_softc *sc, int pin) in amdgpio_valid_pin() argument
124 dprintf("pin %d\n", pin); in amdgpio_valid_pin()
125 if (sc->sc_res[0] == NULL) in amdgpio_valid_pin()
128 if ((sc->sc_gpio_pins[pin].gp_pin == pin) && in amdgpio_valid_pin()
129 (sc->sc_gpio_pins[pin].gp_caps != 0)) in amdgpio_valid_pin()
136 amdgpio_pin_getname(device_t dev, uint32_t pin, char *name) in amdgpio_pin_getname() argument
140 dprintf("pin %d\n", pin); in amdgpio_pin_getname()
143 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_getname()
147 snprintf(name, GPIOMAXNAME, "%s", sc->sc_gpio_pins[pin].gp_name); in amdgpio_pin_getname()
148 name[GPIOMAXNAME - 1] = '\0'; in amdgpio_pin_getname()
150 dprintf("pin %d name %s\n", pin, name); in amdgpio_pin_getname()
156 amdgpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) in amdgpio_pin_getcaps() argument
162 dprintf("pin %d\n", pin); in amdgpio_pin_getcaps()
163 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_getcaps()
166 *caps = sc->sc_gpio_pins[pin].gp_caps; in amdgpio_pin_getcaps()
168 dprintf("pin %d caps 0x%x\n", pin, *caps); in amdgpio_pin_getcaps()
174 amdgpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) in amdgpio_pin_getflags() argument
180 dprintf("pin %d\n", pin); in amdgpio_pin_getflags()
181 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_getflags()
186 *flags = sc->sc_gpio_pins[pin].gp_flags; in amdgpio_pin_getflags()
188 dprintf("pin %d flags 0x%x\n", pin, *flags); in amdgpio_pin_getflags()
196 amdgpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) in amdgpio_pin_setflags() argument
199 uint32_t reg, val, allowed; in amdgpio_pin_setflags() local
203 dprintf("pin %d flags 0x%x\n", pin, flags); in amdgpio_pin_setflags()
204 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_setflags()
224 reg = AMDGPIO_PIN_REGISTER(pin); in amdgpio_pin_setflags()
225 val = amdgpio_read_4(sc, reg); in amdgpio_pin_setflags()
228 val &= ~BIT(OUTPUT_ENABLE_OFF); in amdgpio_pin_setflags()
229 sc->sc_gpio_pins[pin].gp_flags = GPIO_PIN_INPUT; in amdgpio_pin_setflags()
231 val |= BIT(OUTPUT_ENABLE_OFF); in amdgpio_pin_setflags()
232 sc->sc_gpio_pins[pin].gp_flags = GPIO_PIN_OUTPUT; in amdgpio_pin_setflags()
235 amdgpio_write_4(sc, reg, val); in amdgpio_pin_setflags()
237 dprintf("pin %d flags 0x%x val 0x%x gp_flags 0x%x\n", in amdgpio_pin_setflags()
238 pin, flags, val, sc->sc_gpio_pins[pin].gp_flags); in amdgpio_pin_setflags()
246 amdgpio_pin_get(device_t dev, uint32_t pin, unsigned int *value) in amdgpio_pin_get() argument
249 uint32_t reg, val; in amdgpio_pin_get() local
253 dprintf("pin %d\n", pin); in amdgpio_pin_get()
254 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_get()
261 reg = AMDGPIO_PIN_REGISTER(pin); in amdgpio_pin_get()
262 val = amdgpio_read_4(sc, reg); in amdgpio_pin_get()
264 if ((sc->sc_gpio_pins[pin].gp_flags & GPIO_PIN_OUTPUT) != 0) { in amdgpio_pin_get()
265 if (val & BIT(OUTPUT_VALUE_OFF)) in amdgpio_pin_get()
270 if (val & BIT(PIN_STS_OFF)) in amdgpio_pin_get()
276 dprintf("pin %d value 0x%x\n", pin, *value); in amdgpio_pin_get()
284 amdgpio_pin_set(device_t dev, uint32_t pin, unsigned int value) in amdgpio_pin_set() argument
287 uint32_t reg, val; in amdgpio_pin_set() local
291 dprintf("pin %d value 0x%x\n", pin, value); in amdgpio_pin_set()
292 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_set()
295 if (!amdgpio_is_pin_output(sc, pin)) in amdgpio_pin_set()
300 reg = AMDGPIO_PIN_REGISTER(pin); in amdgpio_pin_set()
301 val = amdgpio_read_4(sc, reg); in amdgpio_pin_set()
304 val &= ~BIT(OUTPUT_VALUE_OFF); in amdgpio_pin_set()
306 val |= BIT(OUTPUT_VALUE_OFF); in amdgpio_pin_set()
308 amdgpio_write_4(sc, reg, val); in amdgpio_pin_set()
310 dprintf("pin %d value 0x%x val 0x%x\n", pin, value, val); in amdgpio_pin_set()
318 amdgpio_pin_toggle(device_t dev, uint32_t pin) in amdgpio_pin_toggle() argument
321 uint32_t reg, val; in amdgpio_pin_toggle() local
325 dprintf("pin %d\n", pin); in amdgpio_pin_toggle()
326 if (!amdgpio_valid_pin(sc, pin)) in amdgpio_pin_toggle()
329 if (!amdgpio_is_pin_output(sc, pin)) in amdgpio_pin_toggle()
332 /* Toggle the pin */ in amdgpio_pin_toggle()
335 reg = AMDGPIO_PIN_REGISTER(pin); in amdgpio_pin_toggle()
336 val = amdgpio_read_4(sc, reg); in amdgpio_pin_toggle()
337 dprintf("pin %d value before 0x%x\n", pin, val); in amdgpio_pin_toggle()
338 val = val ^ BIT(OUTPUT_VALUE_OFF); in amdgpio_pin_toggle()
339 dprintf("pin %d value after 0x%x\n", pin, val); in amdgpio_pin_toggle()
340 amdgpio_write_4(sc, reg, val); in amdgpio_pin_toggle()
366 int i, pin, bank; in amdgpio_attach() local
369 sc->sc_dev = dev; in amdgpio_attach()
370 sc->sc_handle = acpi_get_handle(dev); in amdgpio_attach()
374 sc->sc_nbanks = AMD_GPIO_NUM_PIN_BANK; in amdgpio_attach()
375 sc->sc_npins = AMD_GPIO_PINS_MAX; in amdgpio_attach()
376 sc->sc_bank_prefix = AMD_GPIO_PREFIX; in amdgpio_attach()
377 sc->sc_pin_info = kernzp_pins; in amdgpio_attach()
378 sc->sc_ngroups = nitems(kernzp_groups); in amdgpio_attach()
379 sc->sc_groups = kernzp_groups; in amdgpio_attach()
381 if (bus_alloc_resources(dev, amdgpio_spec, sc->sc_res)) { in amdgpio_attach()
386 sc->sc_bst = rman_get_bustag(sc->sc_res[0]); in amdgpio_attach()
387 sc->sc_bsh = rman_get_bushandle(sc->sc_res[0]); in amdgpio_attach()
391 snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME, in amdgpio_attach()
392 "Unexposed PIN %d", i); in amdgpio_attach()
393 sc->sc_gpio_pins[i].gp_pin = -1; in amdgpio_attach()
394 sc->sc_gpio_pins[i].gp_caps = 0; in amdgpio_attach()
395 sc->sc_gpio_pins[i].gp_flags = 0; in amdgpio_attach()
400 pin = kernzp_pins[i].pin_num; in amdgpio_attach()
401 bank = pin/AMD_GPIO_PINS_PER_BANK; in amdgpio_attach()
402 snprintf(sc->sc_gpio_pins[pin].gp_name, GPIOMAXNAME, "%s%d_%s", in amdgpio_attach()
404 sc->sc_gpio_pins[pin].gp_pin = pin; in amdgpio_attach()
405 sc->sc_gpio_pins[pin].gp_caps = AMDGPIO_DEFAULT_CAPS; in amdgpio_attach()
406 sc->sc_gpio_pins[pin].gp_flags = in amdgpio_attach()
407 amdgpio_is_pin_output(sc, pin) ? in amdgpio_attach()
411 sc->sc_busdev = gpiobus_attach_bus(dev); in amdgpio_attach()
412 if (sc->sc_busdev == NULL) { in amdgpio_attach()
420 bus_release_resources(dev, amdgpio_spec, sc->sc_res); in amdgpio_attach()
434 if (sc->sc_busdev) in amdgpio_detach()
437 bus_release_resources(dev, amdgpio_spec, sc->sc_res); in amdgpio_detach()