Lines Matching refs:gpio
77 struct dwapb_gpio *gpio; member
92 static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) in dwapb_read() argument
94 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_read()
95 void __iomem *reg_base = gpio->regs; in dwapb_read()
100 static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, in dwapb_write() argument
103 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_write()
104 void __iomem *reg_base = gpio->regs; in dwapb_write()
112 struct dwapb_gpio *gpio = port->gpio; in dwapb_gpio_to_irq() local
114 return irq_find_mapping(gpio->domain, offset); in dwapb_gpio_to_irq()
117 static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs) in dwapb_toggle_trigger() argument
119 u32 v = dwapb_read(gpio, GPIO_INT_POLARITY); in dwapb_toggle_trigger()
121 if (gpio_get_value(gpio->ports[0].gc.base + offs)) in dwapb_toggle_trigger()
126 dwapb_write(gpio, GPIO_INT_POLARITY, v); in dwapb_toggle_trigger()
129 static u32 dwapb_do_irq(struct dwapb_gpio *gpio) in dwapb_do_irq() argument
131 u32 irq_status = readl_relaxed(gpio->regs + GPIO_INTSTATUS); in dwapb_do_irq()
136 int gpio_irq = irq_find_mapping(gpio->domain, hwirq); in dwapb_do_irq()
143 dwapb_toggle_trigger(gpio, hwirq); in dwapb_do_irq()
151 struct dwapb_gpio *gpio = irq_desc_get_handler_data(desc); in dwapb_irq_handler() local
154 dwapb_do_irq(gpio); in dwapb_irq_handler()
163 struct dwapb_gpio *gpio = igc->private; in dwapb_irq_enable() local
164 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_irq_enable()
169 val = dwapb_read(gpio, GPIO_INTEN); in dwapb_irq_enable()
171 dwapb_write(gpio, GPIO_INTEN, val); in dwapb_irq_enable()
178 struct dwapb_gpio *gpio = igc->private; in dwapb_irq_disable() local
179 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_irq_disable()
184 val = dwapb_read(gpio, GPIO_INTEN); in dwapb_irq_disable()
186 dwapb_write(gpio, GPIO_INTEN, val); in dwapb_irq_disable()
193 struct dwapb_gpio *gpio = igc->private; in dwapb_irq_reqres() local
194 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_irq_reqres()
197 dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", in dwapb_irq_reqres()
207 struct dwapb_gpio *gpio = igc->private; in dwapb_irq_relres() local
208 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_irq_relres()
216 struct dwapb_gpio *gpio = igc->private; in dwapb_irq_set_type() local
217 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_irq_set_type()
226 level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); in dwapb_irq_set_type()
227 polarity = dwapb_read(gpio, GPIO_INT_POLARITY); in dwapb_irq_set_type()
232 dwapb_toggle_trigger(gpio, bit); in dwapb_irq_set_type()
254 dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level); in dwapb_irq_set_type()
255 dwapb_write(gpio, GPIO_INT_POLARITY, polarity); in dwapb_irq_set_type()
265 struct dwapb_gpio *gpio = port->gpio; in dwapb_gpio_set_debounce() local
271 val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); in dwapb_gpio_set_debounce()
273 dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb | mask); in dwapb_gpio_set_debounce()
275 dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); in dwapb_gpio_set_debounce()
285 struct dwapb_gpio *gpio = dev_id; in dwapb_irq_handler_mfd() local
287 worked = dwapb_do_irq(gpio); in dwapb_irq_handler_mfd()
292 static void dwapb_configure_irqs(struct dwapb_gpio *gpio, in dwapb_configure_irqs() argument
303 gpio->domain = irq_domain_create_linear(fwnode, ngpio, in dwapb_configure_irqs()
304 &irq_generic_chip_ops, gpio); in dwapb_configure_irqs()
305 if (!gpio->domain) in dwapb_configure_irqs()
308 err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 2, in dwapb_configure_irqs()
313 dev_info(gpio->dev, "irq_alloc_domain_generic_chips failed\n"); in dwapb_configure_irqs()
314 irq_domain_remove(gpio->domain); in dwapb_configure_irqs()
315 gpio->domain = NULL; in dwapb_configure_irqs()
319 irq_gc = irq_get_domain_generic_chip(gpio->domain, 0); in dwapb_configure_irqs()
321 irq_domain_remove(gpio->domain); in dwapb_configure_irqs()
322 gpio->domain = NULL; in dwapb_configure_irqs()
326 irq_gc->reg_base = gpio->regs; in dwapb_configure_irqs()
327 irq_gc->private = gpio; in dwapb_configure_irqs()
350 gpio); in dwapb_configure_irqs()
356 err = devm_request_irq(gpio->dev, pp->irq, in dwapb_configure_irqs()
358 IRQF_SHARED, "gpio-dwapb-mfd", gpio); in dwapb_configure_irqs()
360 dev_err(gpio->dev, "error requesting IRQ\n"); in dwapb_configure_irqs()
361 irq_domain_remove(gpio->domain); in dwapb_configure_irqs()
362 gpio->domain = NULL; in dwapb_configure_irqs()
368 irq_create_mapping(gpio->domain, hwirq); in dwapb_configure_irqs()
373 static void dwapb_irq_teardown(struct dwapb_gpio *gpio) in dwapb_irq_teardown() argument
375 struct dwapb_gpio_port *port = &gpio->ports[0]; in dwapb_irq_teardown()
380 if (!gpio->domain) in dwapb_irq_teardown()
384 irq_dispose_mapping(irq_find_mapping(gpio->domain, hwirq)); in dwapb_irq_teardown()
386 irq_domain_remove(gpio->domain); in dwapb_irq_teardown()
387 gpio->domain = NULL; in dwapb_irq_teardown()
390 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, in dwapb_gpio_add_port() argument
398 port = &gpio->ports[offs]; in dwapb_gpio_add_port()
399 port->gpio = gpio; in dwapb_gpio_add_port()
403 port->ctx = devm_kzalloc(gpio->dev, sizeof(*port->ctx), GFP_KERNEL); in dwapb_gpio_add_port()
408 dat = gpio->regs + GPIO_EXT_PORTA + (pp->idx * GPIO_EXT_PORT_SIZE); in dwapb_gpio_add_port()
409 set = gpio->regs + GPIO_SWPORTA_DR + (pp->idx * GPIO_SWPORT_DR_SIZE); in dwapb_gpio_add_port()
410 dirout = gpio->regs + GPIO_SWPORTA_DDR + in dwapb_gpio_add_port()
413 err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, in dwapb_gpio_add_port()
416 dev_err(gpio->dev, "failed to init gpio chip for port%d\n", in dwapb_gpio_add_port()
432 dwapb_configure_irqs(gpio, port, pp); in dwapb_gpio_add_port()
436 dev_err(gpio->dev, "failed to register gpiochip for port%d\n", in dwapb_gpio_add_port()
448 static void dwapb_gpio_unregister(struct dwapb_gpio *gpio) in dwapb_gpio_unregister() argument
452 for (m = 0; m < gpio->nr_ports; ++m) in dwapb_gpio_unregister()
453 if (gpio->ports[m].is_registered) in dwapb_gpio_unregister()
454 gpiochip_remove(&gpio->ports[m].gc); in dwapb_gpio_unregister()
527 struct dwapb_gpio *gpio; in dwapb_gpio_probe() local
541 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); in dwapb_gpio_probe()
542 if (!gpio) in dwapb_gpio_probe()
545 gpio->dev = &pdev->dev; in dwapb_gpio_probe()
546 gpio->nr_ports = pdata->nports; in dwapb_gpio_probe()
548 gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, in dwapb_gpio_probe()
549 sizeof(*gpio->ports), GFP_KERNEL); in dwapb_gpio_probe()
550 if (!gpio->ports) in dwapb_gpio_probe()
554 gpio->regs = devm_ioremap_resource(&pdev->dev, res); in dwapb_gpio_probe()
555 if (IS_ERR(gpio->regs)) in dwapb_gpio_probe()
556 return PTR_ERR(gpio->regs); in dwapb_gpio_probe()
558 for (i = 0; i < gpio->nr_ports; i++) { in dwapb_gpio_probe()
559 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); in dwapb_gpio_probe()
563 platform_set_drvdata(pdev, gpio); in dwapb_gpio_probe()
568 dwapb_gpio_unregister(gpio); in dwapb_gpio_probe()
569 dwapb_irq_teardown(gpio); in dwapb_gpio_probe()
576 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); in dwapb_gpio_remove() local
578 dwapb_gpio_unregister(gpio); in dwapb_gpio_remove()
579 dwapb_irq_teardown(gpio); in dwapb_gpio_remove()
601 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); in dwapb_gpio_suspend() local
602 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_gpio_suspend()
607 for (i = 0; i < gpio->nr_ports; i++) { in dwapb_gpio_suspend()
609 unsigned int idx = gpio->ports[i].idx; in dwapb_gpio_suspend()
610 struct dwapb_context *ctx = gpio->ports[i].ctx; in dwapb_gpio_suspend()
615 ctx->dir = dwapb_read(gpio, offset); in dwapb_gpio_suspend()
618 ctx->data = dwapb_read(gpio, offset); in dwapb_gpio_suspend()
621 ctx->ext = dwapb_read(gpio, offset); in dwapb_gpio_suspend()
625 ctx->int_mask = dwapb_read(gpio, GPIO_INTMASK); in dwapb_gpio_suspend()
626 ctx->int_en = dwapb_read(gpio, GPIO_INTEN); in dwapb_gpio_suspend()
627 ctx->int_pol = dwapb_read(gpio, GPIO_INT_POLARITY); in dwapb_gpio_suspend()
628 ctx->int_type = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); in dwapb_gpio_suspend()
629 ctx->int_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); in dwapb_gpio_suspend()
632 dwapb_write(gpio, GPIO_INTMASK, 0xffffffff); in dwapb_gpio_suspend()
643 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); in dwapb_gpio_resume() local
644 struct gpio_chip *gc = &gpio->ports[0].gc; in dwapb_gpio_resume()
649 for (i = 0; i < gpio->nr_ports; i++) { in dwapb_gpio_resume()
651 unsigned int idx = gpio->ports[i].idx; in dwapb_gpio_resume()
652 struct dwapb_context *ctx = gpio->ports[i].ctx; in dwapb_gpio_resume()
657 dwapb_write(gpio, offset, ctx->data); in dwapb_gpio_resume()
660 dwapb_write(gpio, offset, ctx->dir); in dwapb_gpio_resume()
663 dwapb_write(gpio, offset, ctx->ext); in dwapb_gpio_resume()
667 dwapb_write(gpio, GPIO_INTTYPE_LEVEL, ctx->int_type); in dwapb_gpio_resume()
668 dwapb_write(gpio, GPIO_INT_POLARITY, ctx->int_pol); in dwapb_gpio_resume()
669 dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, ctx->int_deb); in dwapb_gpio_resume()
670 dwapb_write(gpio, GPIO_INTEN, ctx->int_en); in dwapb_gpio_resume()
671 dwapb_write(gpio, GPIO_INTMASK, ctx->int_mask); in dwapb_gpio_resume()
674 dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff); in dwapb_gpio_resume()