Lines Matching +full:output +full:- +full:ngpios

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2017-2018 Cadence
8 * Boris Brezillon <boris.brezillon@free-electrons.com>
43 raw_spin_lock_irqsave(&chip->bgpio_lock, flags); in cdns_gpio_request()
45 iowrite32(ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE) & ~BIT(offset), in cdns_gpio_request()
46 cgpio->regs + CDNS_GPIO_BYPASS_MODE); in cdns_gpio_request()
48 raw_spin_unlock_irqrestore(&chip->bgpio_lock, flags); in cdns_gpio_request()
57 raw_spin_lock_irqsave(&chip->bgpio_lock, flags); in cdns_gpio_free()
59 iowrite32(ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE) | in cdns_gpio_free()
60 (BIT(offset) & cgpio->bypass_orig), in cdns_gpio_free()
61 cgpio->regs + CDNS_GPIO_BYPASS_MODE); in cdns_gpio_free()
63 raw_spin_unlock_irqrestore(&chip->bgpio_lock, flags); in cdns_gpio_free()
71 iowrite32(BIT(d->hwirq), cgpio->regs + CDNS_GPIO_IRQ_DIS); in cdns_gpio_irq_mask()
81 iowrite32(BIT(d->hwirq), cgpio->regs + CDNS_GPIO_IRQ_EN); in cdns_gpio_irq_unmask()
91 u32 mask = BIT(d->hwirq); in cdns_gpio_irq_set_type()
94 raw_spin_lock_irqsave(&chip->bgpio_lock, flags); in cdns_gpio_irq_set_type()
96 int_value = ioread32(cgpio->regs + CDNS_GPIO_IRQ_VALUE) & ~mask; in cdns_gpio_irq_set_type()
97 int_type = ioread32(cgpio->regs + CDNS_GPIO_IRQ_TYPE) & ~mask; in cdns_gpio_irq_set_type()
111 ret = -EINVAL; in cdns_gpio_irq_set_type()
115 iowrite32(int_value, cgpio->regs + CDNS_GPIO_IRQ_VALUE); in cdns_gpio_irq_set_type()
116 iowrite32(int_type, cgpio->regs + CDNS_GPIO_IRQ_TYPE); in cdns_gpio_irq_set_type()
119 raw_spin_unlock_irqrestore(&chip->bgpio_lock, flags); in cdns_gpio_irq_set_type()
133 status = ioread32(cgpio->regs + CDNS_GPIO_IRQ_STATUS) & in cdns_gpio_irq_handler()
134 ~ioread32(cgpio->regs + CDNS_GPIO_IRQ_MASK); in cdns_gpio_irq_handler()
136 for_each_set_bit(hwirq, &status, chip->ngpio) in cdns_gpio_irq_handler()
137 generic_handle_domain_irq(chip->irq.domain, hwirq); in cdns_gpio_irq_handler()
143 .name = "cdns-gpio",
159 cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL); in cdns_gpio_probe()
161 return -ENOMEM; in cdns_gpio_probe()
163 cgpio->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_gpio_probe()
164 if (IS_ERR(cgpio->regs)) in cdns_gpio_probe()
165 return PTR_ERR(cgpio->regs); in cdns_gpio_probe()
167 of_property_read_u32(pdev->dev.of_node, "ngpios", &num_gpios); in cdns_gpio_probe()
170 dev_err(&pdev->dev, "ngpios must be less or equal 32\n"); in cdns_gpio_probe()
171 return -EINVAL; in cdns_gpio_probe()
177 * tried to flag a GPIO set as output for IRQ in cdns_gpio_probe()
181 dir_prev = ioread32(cgpio->regs + CDNS_GPIO_DIRECTION_MODE); in cdns_gpio_probe()
182 iowrite32(GENMASK(num_gpios - 1, 0), in cdns_gpio_probe()
183 cgpio->regs + CDNS_GPIO_DIRECTION_MODE); in cdns_gpio_probe()
185 ret = bgpio_init(&cgpio->gc, &pdev->dev, 4, in cdns_gpio_probe()
186 cgpio->regs + CDNS_GPIO_INPUT_VALUE, in cdns_gpio_probe()
187 cgpio->regs + CDNS_GPIO_OUTPUT_VALUE, in cdns_gpio_probe()
190 cgpio->regs + CDNS_GPIO_DIRECTION_MODE, in cdns_gpio_probe()
193 dev_err(&pdev->dev, "Failed to register generic gpio, %d\n", in cdns_gpio_probe()
198 cgpio->gc.label = dev_name(&pdev->dev); in cdns_gpio_probe()
199 cgpio->gc.ngpio = num_gpios; in cdns_gpio_probe()
200 cgpio->gc.parent = &pdev->dev; in cdns_gpio_probe()
201 cgpio->gc.base = -1; in cdns_gpio_probe()
202 cgpio->gc.owner = THIS_MODULE; in cdns_gpio_probe()
203 cgpio->gc.request = cdns_gpio_request; in cdns_gpio_probe()
204 cgpio->gc.free = cdns_gpio_free; in cdns_gpio_probe()
206 clk = devm_clk_get_enabled(&pdev->dev, NULL); in cdns_gpio_probe()
209 dev_err(&pdev->dev, in cdns_gpio_probe()
221 girq = &cgpio->gc.irq; in cdns_gpio_probe()
223 girq->parent_handler = cdns_gpio_irq_handler; in cdns_gpio_probe()
224 girq->num_parents = 1; in cdns_gpio_probe()
225 girq->parents = devm_kcalloc(&pdev->dev, 1, in cdns_gpio_probe()
226 sizeof(*girq->parents), in cdns_gpio_probe()
228 if (!girq->parents) { in cdns_gpio_probe()
229 ret = -ENOMEM; in cdns_gpio_probe()
232 girq->parents[0] = irq; in cdns_gpio_probe()
233 girq->default_type = IRQ_TYPE_NONE; in cdns_gpio_probe()
234 girq->handler = handle_level_irq; in cdns_gpio_probe()
237 ret = devm_gpiochip_add_data(&pdev->dev, &cgpio->gc, cgpio); in cdns_gpio_probe()
239 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); in cdns_gpio_probe()
243 cgpio->bypass_orig = ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE); in cdns_gpio_probe()
248 iowrite32(GENMASK(num_gpios - 1, 0), in cdns_gpio_probe()
249 cgpio->regs + CDNS_GPIO_OUTPUT_EN); in cdns_gpio_probe()
250 iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE); in cdns_gpio_probe()
256 iowrite32(dir_prev, cgpio->regs + CDNS_GPIO_DIRECTION_MODE); in cdns_gpio_probe()
265 iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE); in cdns_gpio_remove()
269 { .compatible = "cdns,gpio-r1p02" },
276 .name = "cdns-gpio",
287 MODULE_ALIAS("platform:cdns-gpio");