Lines Matching +full:bus +full:- +full:err

6  * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
28 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_to_irq() local
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()
43 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_chipco_get_value() local
45 return !!ssb_chipco_gpio_in(&bus->chipco, 1 << gpio); in ssb_gpio_chipco_get_value()
51 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_chipco_set_value() local
53 ssb_chipco_gpio_out(&bus->chipco, 1 << gpio, value ? 1 << gpio : 0); in ssb_gpio_chipco_set_value()
59 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_chipco_direction_input() local
61 ssb_chipco_gpio_outen(&bus->chipco, 1 << gpio, 0); in ssb_gpio_chipco_direction_input()
68 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_chipco_direction_output() local
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()
77 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_chipco_request() local
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()
90 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_chipco_free() local
93 ssb_chipco_gpio_pullup(&bus->chipco, 1 << gpio, 0); in ssb_gpio_chipco_free()
99 struct ssb_bus *bus = irq_data_get_irq_chip_data(d); in ssb_gpio_irq_chipco_mask() local
102 ssb_chipco_gpio_intmask(&bus->chipco, BIT(gpio), 0); in ssb_gpio_irq_chipco_mask()
107 struct ssb_bus *bus = irq_data_get_irq_chip_data(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",
123 struct ssb_bus *bus = dev_id; in ssb_gpio_irq_chipco_handler() local
124 struct ssb_chipcommon *chipco = &bus->chipco; in ssb_gpio_irq_chipco_handler()
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()
142 static int ssb_gpio_irq_chipco_domain_init(struct ssb_bus *bus) in ssb_gpio_irq_chipco_domain_init() argument
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()
160 irq_set_chip_data(irq, bus); in ssb_gpio_irq_chipco_domain_init()
165 hwirq = ssb_mips_irq(bus->chipco.dev) + 2; in ssb_gpio_irq_chipco_domain_init()
166 err = request_irq(hwirq, ssb_gpio_irq_chipco_handler, IRQF_SHARED, in ssb_gpio_irq_chipco_domain_init()
167 "gpio", bus); in ssb_gpio_irq_chipco_domain_init()
168 if (err) 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()
184 return err; in ssb_gpio_irq_chipco_domain_init()
187 static void ssb_gpio_irq_chipco_domain_exit(struct ssb_bus *bus) in ssb_gpio_irq_chipco_domain_exit() argument
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()
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()
206 static int ssb_gpio_irq_chipco_domain_init(struct ssb_bus *bus) in ssb_gpio_irq_chipco_domain_init() argument
211 static void ssb_gpio_irq_chipco_domain_exit(struct ssb_bus *bus) in ssb_gpio_irq_chipco_domain_exit() argument
216 static int ssb_gpio_chipco_init(struct ssb_bus *bus) in ssb_gpio_chipco_init() argument
218 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_chipco_init()
219 int err; in ssb_gpio_chipco_init() local
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()
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()
242 err = ssb_gpio_irq_chipco_domain_init(bus); in ssb_gpio_chipco_init()
243 if (err) in ssb_gpio_chipco_init()
244 return err; in ssb_gpio_chipco_init()
246 err = gpiochip_add_data(chip, bus); in ssb_gpio_chipco_init()
247 if (err) { in ssb_gpio_chipco_init()
248 ssb_gpio_irq_chipco_domain_exit(bus); in ssb_gpio_chipco_init()
249 return err; in ssb_gpio_chipco_init()
263 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_extif_get_value() local
265 return !!ssb_extif_gpio_in(&bus->extif, 1 << gpio); in ssb_gpio_extif_get_value()
271 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_extif_set_value() local
273 ssb_extif_gpio_out(&bus->extif, 1 << gpio, value ? 1 << gpio : 0); in ssb_gpio_extif_set_value()
279 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_extif_direction_input() local
281 ssb_extif_gpio_outen(&bus->extif, 1 << gpio, 0); in ssb_gpio_extif_direction_input()
288 struct ssb_bus *bus = gpiochip_get_data(chip); in ssb_gpio_extif_direction_output() local
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()
298 struct ssb_bus *bus = irq_data_get_irq_chip_data(d); in ssb_gpio_irq_extif_mask() local
301 ssb_extif_gpio_intmask(&bus->extif, BIT(gpio), 0); in ssb_gpio_irq_extif_mask()
306 struct ssb_bus *bus = irq_data_get_irq_chip_data(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",
322 struct ssb_bus *bus = dev_id; in ssb_gpio_irq_extif_handler() local
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()
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()
341 static int ssb_gpio_irq_extif_domain_init(struct ssb_bus *bus) in ssb_gpio_irq_extif_domain_init() argument
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()
359 irq_set_chip_data(irq, bus); in ssb_gpio_irq_extif_domain_init()
364 hwirq = ssb_mips_irq(bus->extif.dev) + 2; in ssb_gpio_irq_extif_domain_init()
365 err = request_irq(hwirq, ssb_gpio_irq_extif_handler, IRQF_SHARED, in ssb_gpio_irq_extif_domain_init()
366 "gpio", bus); in ssb_gpio_irq_extif_domain_init()
367 if (err) 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()
382 return err; in ssb_gpio_irq_extif_domain_init()
385 static void ssb_gpio_irq_extif_domain_exit(struct ssb_bus *bus) in ssb_gpio_irq_extif_domain_exit() argument
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()
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()
403 static int ssb_gpio_irq_extif_domain_init(struct ssb_bus *bus) in ssb_gpio_irq_extif_domain_init() argument
408 static void ssb_gpio_irq_extif_domain_exit(struct ssb_bus *bus) in ssb_gpio_irq_extif_domain_exit() argument
413 static int ssb_gpio_extif_init(struct ssb_bus *bus) in ssb_gpio_extif_init() argument
415 struct gpio_chip *chip = &bus->gpio; in ssb_gpio_extif_init()
416 int err; in ssb_gpio_extif_init() local
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()
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()
437 err = ssb_gpio_irq_extif_domain_init(bus); in ssb_gpio_extif_init()
438 if (err) in ssb_gpio_extif_init()
439 return err; in ssb_gpio_extif_init()
441 err = gpiochip_add_data(chip, bus); in ssb_gpio_extif_init()
442 if (err) { in ssb_gpio_extif_init()
443 ssb_gpio_irq_extif_domain_exit(bus); in ssb_gpio_extif_init()
444 return err; in ssb_gpio_extif_init()
451 static int ssb_gpio_extif_init(struct ssb_bus *bus) in ssb_gpio_extif_init() argument
453 return -ENOTSUPP; in ssb_gpio_extif_init()
461 int ssb_gpio_init(struct ssb_bus *bus) in ssb_gpio_init() argument
463 if (ssb_chipco_available(&bus->chipco)) in ssb_gpio_init()
464 return ssb_gpio_chipco_init(bus); in ssb_gpio_init()
465 else if (ssb_extif_available(&bus->extif)) in ssb_gpio_init()
466 return ssb_gpio_extif_init(bus); in ssb_gpio_init()
467 return -1; in ssb_gpio_init()
470 int ssb_gpio_unregister(struct ssb_bus *bus) in ssb_gpio_unregister() argument
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()