Lines Matching +full:a +full:- +full:gpio
1 /*-
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * Support routines usable by any SoC sdhci bridge driver that uses gpio pins
33 #include <sys/gpio.h>
38 #include <dev/gpio/gpiobusvar.h>
65 struct sdhci_fdt_gpio *gpio = arg; in cd_intr() local
67 sdhci_handle_card_present(gpio->slot, sdhci_fdt_gpio_get_present(gpio)); in cd_intr()
74 cd_setup(struct sdhci_fdt_gpio *gpio, phandle_t node) in cd_setup() argument
80 dev = gpio->dev; in cd_setup()
83 * If the device is flagged as non-removable, set that slot option, and in cd_setup()
84 * set a flag to make sdhci_fdt_gpio_get_present() always return true. in cd_setup()
86 if (OF_hasprop(node, "non-removable")) { in cd_setup()
87 gpio->slot->opt |= SDHCI_NON_REMOVABLE; in cd_setup()
88 gpio->cd_disabled = true; in cd_setup()
90 device_printf(dev, "Non-removable media\n"); in cd_setup()
95 * If there is no cd-gpios property, then presumably the hardware in cd_setup()
100 * If there is a property, make sure we can read the pin. in cd_setup()
102 if (gpio_pin_get_by_ofw_property(dev, node, "cd-gpios", &gpio->cd_pin)) in cd_setup()
105 if (gpio_pin_getcaps(gpio->cd_pin, &pincaps) != 0 || in cd_setup()
107 device_printf(dev, "Cannot read card-detect gpio pin; " in cd_setup()
108 "setting card-always-present flag.\n"); in cd_setup()
109 gpio->cd_disabled = true; in cd_setup()
113 if (OF_hasprop(node, "cd-inverted")) in cd_setup()
114 gpio->cd_inverted = true; in cd_setup()
131 if ((gpio->cd_ires = gpio_alloc_intr_resource(dev, &gpio->cd_irid, in cd_setup()
132 RF_ACTIVE, gpio->cd_pin, GPIO_INTR_EDGE_BOTH)) == NULL) { in cd_setup()
135 "detect GPIO\n"); in cd_setup()
139 if (bus_setup_intr(dev, gpio->cd_ires, INTR_TYPE_BIO | INTR_MPSAFE, in cd_setup()
140 NULL, cd_intr, gpio, &gpio->cd_ihandler) != 0) { in cd_setup()
141 device_printf(dev, "Unable to setup card-detect irq handler\n"); in cd_setup()
142 gpio->cd_ihandler = NULL; in cd_setup()
149 * If we have a readable gpio pin, but didn't successfully configure in cd_setup()
150 * gpio interrupts, ask the sdhci driver to poll from a callout. in cd_setup()
152 if (gpio->cd_ihandler == NULL) { in cd_setup()
154 gpio->slot->quirks |= SDHCI_QUIRK_POLL_CARD_PRESENT; in cd_setup()
162 device_get_nameunit(gpio->cd_pin->dev), gpio->cd_pin->pin, in cd_setup()
171 wp_setup(struct sdhci_fdt_gpio *gpio, phandle_t node) in wp_setup() argument
175 dev = gpio->dev; in wp_setup()
177 if (OF_hasprop(node, "wp-disable")) { in wp_setup()
178 gpio->wp_disabled = true; in wp_setup()
184 if (gpio_pin_get_by_ofw_property(dev, node, "wp-gpios", &gpio->wp_pin)) in wp_setup()
187 if (OF_hasprop(node, "wp-inverted")) in wp_setup()
188 gpio->wp_inverted = true; in wp_setup()
192 device_get_nameunit(gpio->wp_pin->dev), gpio->wp_pin->pin); in wp_setup()
199 struct sdhci_fdt_gpio *gpio; in sdhci_fdt_gpio_setup() local
201 gpio = malloc(sizeof(*gpio), M_DEVBUF, M_ZERO | M_WAITOK); in sdhci_fdt_gpio_setup()
202 gpio->dev = dev; in sdhci_fdt_gpio_setup()
203 gpio->slot = slot; in sdhci_fdt_gpio_setup()
207 wp_setup(gpio, node); in sdhci_fdt_gpio_setup()
208 cd_setup(gpio, node); in sdhci_fdt_gpio_setup()
210 return (gpio); in sdhci_fdt_gpio_setup()
214 sdhci_fdt_gpio_teardown(struct sdhci_fdt_gpio *gpio) in sdhci_fdt_gpio_teardown() argument
217 if (gpio == NULL) in sdhci_fdt_gpio_teardown()
220 if (gpio->cd_ihandler != NULL) in sdhci_fdt_gpio_teardown()
221 bus_teardown_intr(gpio->dev, gpio->cd_ires, gpio->cd_ihandler); in sdhci_fdt_gpio_teardown()
222 if (gpio->wp_pin != NULL) in sdhci_fdt_gpio_teardown()
223 gpio_pin_release(gpio->wp_pin); in sdhci_fdt_gpio_teardown()
224 if (gpio->cd_pin != NULL) in sdhci_fdt_gpio_teardown()
225 gpio_pin_release(gpio->cd_pin); in sdhci_fdt_gpio_teardown()
226 if (gpio->cd_ires != NULL) in sdhci_fdt_gpio_teardown()
227 bus_release_resource(gpio->dev, SYS_RES_IRQ, 0, gpio->cd_ires); in sdhci_fdt_gpio_teardown()
229 free(gpio, M_DEVBUF); in sdhci_fdt_gpio_teardown()
233 sdhci_fdt_gpio_get_present(struct sdhci_fdt_gpio *gpio) in sdhci_fdt_gpio_get_present() argument
237 if (gpio->cd_disabled) in sdhci_fdt_gpio_get_present()
240 if (gpio->cd_pin == NULL) in sdhci_fdt_gpio_get_present()
241 return (sdhci_generic_get_card_present(gpio->slot->bus, in sdhci_fdt_gpio_get_present()
242 gpio->slot)); in sdhci_fdt_gpio_get_present()
244 gpio_pin_is_active(gpio->cd_pin, &pinstate); in sdhci_fdt_gpio_get_present()
246 return (pinstate ^ gpio->cd_inverted); in sdhci_fdt_gpio_get_present()
250 sdhci_fdt_gpio_get_readonly(struct sdhci_fdt_gpio *gpio) in sdhci_fdt_gpio_get_readonly() argument
254 if (gpio->wp_disabled) in sdhci_fdt_gpio_get_readonly()
257 if (gpio->wp_pin == NULL) in sdhci_fdt_gpio_get_readonly()
258 return (sdhci_generic_get_ro(gpio->slot->bus, gpio->slot->dev)); in sdhci_fdt_gpio_get_readonly()
260 gpio_pin_is_active(gpio->wp_pin, &pinstate); in sdhci_fdt_gpio_get_readonly()
262 return (pinstate ^ gpio->wp_inverted); in sdhci_fdt_gpio_get_readonly()