Lines Matching +full:gpio +full:- +full:pol
3 * GPIO driver
6 * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
13 #include <linux/gpio/driver.h>
26 static int ssb_gpio_to_irq(struct gpio_chip *chip, unsigned int gpio) in ssb_gpio_to_irq() argument
30 if (bus->bustype == SSB_BUSTYPE_SSB) in ssb_gpio_to_irq()
31 return irq_find_mapping(bus->irq_domain, gpio); in ssb_gpio_to_irq()
33 return -EINVAL; in ssb_gpio_to_irq()
41 static int ssb_gpio_chipco_get_value(struct gpio_chip *chip, unsigned int gpio) in ssb_gpio_chipco_get_value() argument
45 return !!ssb_chipco_gpio_in(&bus->chipco, 1 << gpio); in ssb_gpio_chipco_get_value()
48 static void ssb_gpio_chipco_set_value(struct gpio_chip *chip, unsigned int gpio, in ssb_gpio_chipco_set_value() argument
53 ssb_chipco_gpio_out(&bus->chipco, 1 << gpio, value ? 1 << gpio : 0); in ssb_gpio_chipco_set_value()
57 unsigned int gpio) in ssb_gpio_chipco_direction_input() argument
61 ssb_chipco_gpio_outen(&bus->chipco, 1 << gpio, 0); in ssb_gpio_chipco_direction_input()
66 unsigned int gpio, int value) in ssb_gpio_chipco_direction_output() argument
70 ssb_chipco_gpio_outen(&bus->chipco, 1 << gpio, 1 << gpio); in ssb_gpio_chipco_direction_output()
71 ssb_chipco_gpio_out(&bus->chipco, 1 << gpio, value ? 1 << gpio : 0); in ssb_gpio_chipco_direction_output()
75 static int ssb_gpio_chipco_request(struct gpio_chip *chip, unsigned int gpio) in ssb_gpio_chipco_request() argument
79 ssb_chipco_gpio_control(&bus->chipco, 1 << gpio, 0); in ssb_gpio_chipco_request()
81 ssb_chipco_gpio_pulldown(&bus->chipco, 1 << gpio, 0); in ssb_gpio_chipco_request()
83 ssb_chipco_gpio_pullup(&bus->chipco, 1 << gpio, 1 << gpio); in ssb_gpio_chipco_request()
88 static void ssb_gpio_chipco_free(struct gpio_chip *chip, unsigned int gpio) in ssb_gpio_chipco_free() argument
93 ssb_chipco_gpio_pullup(&bus->chipco, 1 << gpio, 0); in ssb_gpio_chipco_free()
100 int gpio = irqd_to_hwirq(d); in ssb_gpio_irq_chipco_mask() local
102 ssb_chipco_gpio_intmask(&bus->chipco, BIT(gpio), 0); in ssb_gpio_irq_chipco_mask()
108 int gpio = irqd_to_hwirq(d); in ssb_gpio_irq_chipco_unmask() local
109 u32 val = ssb_chipco_gpio_in(&bus->chipco, BIT(gpio)); in ssb_gpio_irq_chipco_unmask()
111 ssb_chipco_gpio_polarity(&bus->chipco, BIT(gpio), val); in ssb_gpio_irq_chipco_unmask()
112 ssb_chipco_gpio_intmask(&bus->chipco, BIT(gpio), BIT(gpio)); in ssb_gpio_irq_chipco_unmask()
116 .name = "SSB-GPIO-CC",
124 struct ssb_chipcommon *chipco = &bus->chipco; in ssb_gpio_irq_chipco_handler()
127 u32 pol = chipco_read32(chipco, SSB_CHIPCO_GPIOPOL); in ssb_gpio_irq_chipco_handler() local
128 unsigned long irqs = (val ^ pol) & mask; in ssb_gpio_irq_chipco_handler()
129 int gpio; in ssb_gpio_irq_chipco_handler() local
134 for_each_set_bit(gpio, &irqs, bus->gpio.ngpio) in ssb_gpio_irq_chipco_handler()
135 generic_handle_domain_irq_safe(bus->irq_domain, gpio); in ssb_gpio_irq_chipco_handler()
144 struct ssb_chipcommon *chipco = &bus->chipco; in ssb_gpio_irq_chipco_domain_init()
145 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_irq_chipco_domain_init()
146 int gpio, hwirq, err; in ssb_gpio_irq_chipco_domain_init() local
148 if (bus->bustype != SSB_BUSTYPE_SSB) in ssb_gpio_irq_chipco_domain_init()
151 bus->irq_domain = irq_domain_add_linear(NULL, chip->ngpio, in ssb_gpio_irq_chipco_domain_init()
153 if (!bus->irq_domain) { in ssb_gpio_irq_chipco_domain_init()
154 err = -ENODEV; in ssb_gpio_irq_chipco_domain_init()
157 for (gpio = 0; gpio < chip->ngpio; gpio++) { in ssb_gpio_irq_chipco_domain_init()
158 int irq = irq_create_mapping(bus->irq_domain, gpio); in ssb_gpio_irq_chipco_domain_init()
165 hwirq = ssb_mips_irq(bus->chipco.dev) + 2; in ssb_gpio_irq_chipco_domain_init()
167 "gpio", bus); in ssb_gpio_irq_chipco_domain_init()
171 ssb_chipco_gpio_intmask(&bus->chipco, ~0, 0); in ssb_gpio_irq_chipco_domain_init()
177 for (gpio = 0; gpio < chip->ngpio; gpio++) { in ssb_gpio_irq_chipco_domain_init()
178 int irq = irq_find_mapping(bus->irq_domain, gpio); in ssb_gpio_irq_chipco_domain_init()
182 irq_domain_remove(bus->irq_domain); in ssb_gpio_irq_chipco_domain_init()
189 struct ssb_chipcommon *chipco = &bus->chipco; in ssb_gpio_irq_chipco_domain_exit()
190 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_irq_chipco_domain_exit()
191 int gpio; in ssb_gpio_irq_chipco_domain_exit() local
193 if (bus->bustype != SSB_BUSTYPE_SSB) in ssb_gpio_irq_chipco_domain_exit()
197 free_irq(ssb_mips_irq(bus->chipco.dev) + 2, chipco); in ssb_gpio_irq_chipco_domain_exit()
198 for (gpio = 0; gpio < chip->ngpio; gpio++) { in ssb_gpio_irq_chipco_domain_exit()
199 int irq = irq_find_mapping(bus->irq_domain, gpio); in ssb_gpio_irq_chipco_domain_exit()
203 irq_domain_remove(bus->irq_domain); in ssb_gpio_irq_chipco_domain_exit()
218 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_chipco_init()
221 chip->label = "ssb_chipco_gpio"; in ssb_gpio_chipco_init()
222 chip->owner = THIS_MODULE; in ssb_gpio_chipco_init()
223 chip->request = ssb_gpio_chipco_request; in ssb_gpio_chipco_init()
224 chip->free = ssb_gpio_chipco_free; in ssb_gpio_chipco_init()
225 chip->get = ssb_gpio_chipco_get_value; in ssb_gpio_chipco_init()
226 chip->set = ssb_gpio_chipco_set_value; in ssb_gpio_chipco_init()
227 chip->direction_input = ssb_gpio_chipco_direction_input; in ssb_gpio_chipco_init()
228 chip->direction_output = ssb_gpio_chipco_direction_output; in ssb_gpio_chipco_init()
230 chip->to_irq = ssb_gpio_to_irq; in ssb_gpio_chipco_init()
232 chip->ngpio = 16; in ssb_gpio_chipco_init()
233 /* There is just one SoC in one device and its GPIO addresses should be in ssb_gpio_chipco_init()
237 if (bus->bustype == SSB_BUSTYPE_SSB) in ssb_gpio_chipco_init()
238 chip->base = 0; in ssb_gpio_chipco_init()
240 chip->base = -1; in ssb_gpio_chipco_init()
261 static int ssb_gpio_extif_get_value(struct gpio_chip *chip, unsigned int gpio) in ssb_gpio_extif_get_value() argument
265 return !!ssb_extif_gpio_in(&bus->extif, 1 << gpio); in ssb_gpio_extif_get_value()
268 static void ssb_gpio_extif_set_value(struct gpio_chip *chip, unsigned int gpio, in ssb_gpio_extif_set_value() argument
273 ssb_extif_gpio_out(&bus->extif, 1 << gpio, value ? 1 << gpio : 0); in ssb_gpio_extif_set_value()
277 unsigned int gpio) in ssb_gpio_extif_direction_input() argument
281 ssb_extif_gpio_outen(&bus->extif, 1 << gpio, 0); in ssb_gpio_extif_direction_input()
286 unsigned int gpio, int value) in ssb_gpio_extif_direction_output() argument
290 ssb_extif_gpio_outen(&bus->extif, 1 << gpio, 1 << gpio); in ssb_gpio_extif_direction_output()
291 ssb_extif_gpio_out(&bus->extif, 1 << gpio, value ? 1 << gpio : 0); in ssb_gpio_extif_direction_output()
299 int gpio = irqd_to_hwirq(d); in ssb_gpio_irq_extif_mask() local
301 ssb_extif_gpio_intmask(&bus->extif, BIT(gpio), 0); in ssb_gpio_irq_extif_mask()
307 int gpio = irqd_to_hwirq(d); in ssb_gpio_irq_extif_unmask() local
308 u32 val = ssb_extif_gpio_in(&bus->extif, BIT(gpio)); in ssb_gpio_irq_extif_unmask()
310 ssb_extif_gpio_polarity(&bus->extif, BIT(gpio), val); in ssb_gpio_irq_extif_unmask()
311 ssb_extif_gpio_intmask(&bus->extif, BIT(gpio), BIT(gpio)); in ssb_gpio_irq_extif_unmask()
315 .name = "SSB-GPIO-EXTIF",
323 struct ssb_extif *extif = &bus->extif; in ssb_gpio_irq_extif_handler()
324 u32 val = ssb_read32(extif->dev, SSB_EXTIF_GPIO_IN); in ssb_gpio_irq_extif_handler()
325 u32 mask = ssb_read32(extif->dev, SSB_EXTIF_GPIO_INTMASK); in ssb_gpio_irq_extif_handler()
326 u32 pol = ssb_read32(extif->dev, SSB_EXTIF_GPIO_INTPOL); in ssb_gpio_irq_extif_handler() local
327 unsigned long irqs = (val ^ pol) & mask; in ssb_gpio_irq_extif_handler()
328 int gpio; in ssb_gpio_irq_extif_handler() local
333 for_each_set_bit(gpio, &irqs, bus->gpio.ngpio) in ssb_gpio_irq_extif_handler()
334 generic_handle_domain_irq_safe(bus->irq_domain, gpio); in ssb_gpio_irq_extif_handler()
343 struct ssb_extif *extif = &bus->extif; in ssb_gpio_irq_extif_domain_init()
344 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_irq_extif_domain_init()
345 int gpio, hwirq, err; in ssb_gpio_irq_extif_domain_init() local
347 if (bus->bustype != SSB_BUSTYPE_SSB) in ssb_gpio_irq_extif_domain_init()
350 bus->irq_domain = irq_domain_add_linear(NULL, chip->ngpio, in ssb_gpio_irq_extif_domain_init()
352 if (!bus->irq_domain) { in ssb_gpio_irq_extif_domain_init()
353 err = -ENODEV; in ssb_gpio_irq_extif_domain_init()
356 for (gpio = 0; gpio < chip->ngpio; gpio++) { in ssb_gpio_irq_extif_domain_init()
357 int irq = irq_create_mapping(bus->irq_domain, gpio); in ssb_gpio_irq_extif_domain_init()
364 hwirq = ssb_mips_irq(bus->extif.dev) + 2; in ssb_gpio_irq_extif_domain_init()
366 "gpio", bus); in ssb_gpio_irq_extif_domain_init()
370 ssb_extif_gpio_intmask(&bus->extif, ~0, 0); in ssb_gpio_irq_extif_domain_init()
375 for (gpio = 0; gpio < chip->ngpio; gpio++) { in ssb_gpio_irq_extif_domain_init()
376 int irq = irq_find_mapping(bus->irq_domain, gpio); in ssb_gpio_irq_extif_domain_init()
380 irq_domain_remove(bus->irq_domain); in ssb_gpio_irq_extif_domain_init()
387 struct ssb_extif *extif = &bus->extif; in ssb_gpio_irq_extif_domain_exit()
388 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_irq_extif_domain_exit()
389 int gpio; in ssb_gpio_irq_extif_domain_exit() local
391 if (bus->bustype != SSB_BUSTYPE_SSB) in ssb_gpio_irq_extif_domain_exit()
394 free_irq(ssb_mips_irq(bus->extif.dev) + 2, extif); in ssb_gpio_irq_extif_domain_exit()
395 for (gpio = 0; gpio < chip->ngpio; gpio++) { in ssb_gpio_irq_extif_domain_exit()
396 int irq = irq_find_mapping(bus->irq_domain, gpio); in ssb_gpio_irq_extif_domain_exit()
400 irq_domain_remove(bus->irq_domain); in ssb_gpio_irq_extif_domain_exit()
415 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_extif_init()
418 chip->label = "ssb_extif_gpio"; in ssb_gpio_extif_init()
419 chip->owner = THIS_MODULE; in ssb_gpio_extif_init()
420 chip->get = ssb_gpio_extif_get_value; in ssb_gpio_extif_init()
421 chip->set = ssb_gpio_extif_set_value; in ssb_gpio_extif_init()
422 chip->direction_input = ssb_gpio_extif_direction_input; in ssb_gpio_extif_init()
423 chip->direction_output = ssb_gpio_extif_direction_output; in ssb_gpio_extif_init()
425 chip->to_irq = ssb_gpio_to_irq; in ssb_gpio_extif_init()
427 chip->ngpio = 5; in ssb_gpio_extif_init()
428 /* There is just one SoC in one device and its GPIO addresses should be in ssb_gpio_extif_init()
432 if (bus->bustype == SSB_BUSTYPE_SSB) in ssb_gpio_extif_init()
433 chip->base = 0; in ssb_gpio_extif_init()
435 chip->base = -1; in ssb_gpio_extif_init()
453 return -ENOTSUPP; in ssb_gpio_extif_init()
463 if (ssb_chipco_available(&bus->chipco)) in ssb_gpio_init()
465 else if (ssb_extif_available(&bus->extif)) in ssb_gpio_init()
467 return -1; in ssb_gpio_init()
472 if (ssb_chipco_available(&bus->chipco) || in ssb_gpio_unregister()
473 ssb_extif_available(&bus->extif)) { in ssb_gpio_unregister()
474 gpiochip_remove(&bus->gpio); in ssb_gpio_unregister()
477 return -1; in ssb_gpio_unregister()