Lines Matching +full:standby +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * AppliedMicro X-Gene SoC GPIO-Standby Driver
18 #include "gpiolib-acpi.h"
21 #define XGENE_NIRQ_PROPERTY "apm,nr-irqs"
22 #define XGENE_NGPIO_PROPERTY "apm,nr-gpios"
23 #define XGENE_IRQ_START_PROPERTY "apm,irq-start"
40 * struct xgene_gpio_sb - GPIO-Standby private data structure.
41 * @gc: memory-mapped GPIO controllers.
57 #define HWIRQ_TO_GPIO(priv, hwirq) ((hwirq) + (priv)->irq_start)
58 #define GPIO_TO_HWIRQ(priv, gpio) ((gpio) - (priv)->irq_start)
65 data = gc->read_reg(reg); in xgene_gpio_set_bit()
70 gc->write_reg(reg, data); in xgene_gpio_set_bit()
76 int gpio = HWIRQ_TO_GPIO(priv, d->hwirq); in xgene_gpio_sb_irq_set_type()
92 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, in xgene_gpio_sb_irq_set_type()
94 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_INT_LVL, in xgene_gpio_sb_irq_set_type()
95 d->hwirq, lvl_type); in xgene_gpio_sb_irq_set_type()
117 if ((gpio < priv->irq_start) || in xgene_gpio_sb_to_irq()
118 (gpio > HWIRQ_TO_GPIO(priv, priv->nirq))) in xgene_gpio_sb_to_irq()
119 return -ENXIO; in xgene_gpio_sb_to_irq()
121 fwspec.fwnode = gc->parent->fwnode; in xgene_gpio_sb_to_irq()
132 struct xgene_gpio_sb *priv = d->host_data; in xgene_gpio_sb_domain_activate()
133 u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); in xgene_gpio_sb_domain_activate()
136 ret = gpiochip_lock_as_irq(&priv->gc, gpio); in xgene_gpio_sb_domain_activate()
138 dev_err(priv->gc.parent, in xgene_gpio_sb_domain_activate()
139 "Unable to configure XGene GPIO standby pin %d as IRQ\n", in xgene_gpio_sb_domain_activate()
144 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, in xgene_gpio_sb_domain_activate()
152 struct xgene_gpio_sb *priv = d->host_data; in xgene_gpio_sb_domain_deactivate()
153 u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); in xgene_gpio_sb_domain_deactivate()
155 gpiochip_unlock_as_irq(&priv->gc, gpio); in xgene_gpio_sb_domain_deactivate()
156 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, in xgene_gpio_sb_domain_deactivate()
165 struct xgene_gpio_sb *priv = d->host_data; in xgene_gpio_sb_domain_translate()
167 if ((fwspec->param_count != 2) || in xgene_gpio_sb_domain_translate()
168 (fwspec->param[0] >= priv->nirq)) in xgene_gpio_sb_domain_translate()
169 return -EINVAL; in xgene_gpio_sb_domain_translate()
170 *hwirq = fwspec->param[0]; in xgene_gpio_sb_domain_translate()
171 *type = fwspec->param[1]; in xgene_gpio_sb_domain_translate()
181 struct xgene_gpio_sb *priv = domain->host_data; in xgene_gpio_sb_domain_alloc()
185 hwirq = fwspec->param[0]; in xgene_gpio_sb_domain_alloc()
190 parent_fwspec.fwnode = domain->parent->fwnode; in xgene_gpio_sb_domain_alloc()
195 parent_fwspec.param[1] = hwirq + priv->parent_irq_base - 32; in xgene_gpio_sb_domain_alloc()
196 parent_fwspec.param[2] = fwspec->param[1]; in xgene_gpio_sb_domain_alloc()
199 parent_fwspec.param[0] = hwirq + priv->parent_irq_base; in xgene_gpio_sb_domain_alloc()
200 parent_fwspec.param[1] = fwspec->param[1]; in xgene_gpio_sb_domain_alloc()
202 return -EINVAL; in xgene_gpio_sb_domain_alloc()
224 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in xgene_gpio_sb_probe()
226 return -ENOMEM; in xgene_gpio_sb_probe()
232 priv->regs = regs; in xgene_gpio_sb_probe()
236 priv->parent_irq_base = irq_get_irq_data(ret)->hwirq; in xgene_gpio_sb_probe()
237 parent_domain = irq_get_irq_data(ret)->domain; in xgene_gpio_sb_probe()
240 dev_err(&pdev->dev, "unable to obtain parent domain\n"); in xgene_gpio_sb_probe()
241 return -ENODEV; in xgene_gpio_sb_probe()
244 ret = bgpio_init(&priv->gc, &pdev->dev, 4, in xgene_gpio_sb_probe()
251 priv->gc.to_irq = xgene_gpio_sb_to_irq; in xgene_gpio_sb_probe()
254 priv->irq_start = XGENE_DFLT_IRQ_START_PIN; in xgene_gpio_sb_probe()
255 if (!device_property_read_u32(&pdev->dev, in xgene_gpio_sb_probe()
257 priv->irq_start = val32; in xgene_gpio_sb_probe()
260 priv->nirq = XGENE_DFLT_MAX_NIRQ; in xgene_gpio_sb_probe()
261 if (!device_property_read_u32(&pdev->dev, XGENE_NIRQ_PROPERTY, &val32)) in xgene_gpio_sb_probe()
262 priv->nirq = val32; in xgene_gpio_sb_probe()
265 priv->gc.ngpio = XGENE_DFLT_MAX_NGPIO; in xgene_gpio_sb_probe()
266 if (!device_property_read_u32(&pdev->dev, XGENE_NGPIO_PROPERTY, &val32)) in xgene_gpio_sb_probe()
267 priv->gc.ngpio = val32; in xgene_gpio_sb_probe()
269 dev_info(&pdev->dev, "Support %d gpios, %d irqs start from pin %d\n", in xgene_gpio_sb_probe()
270 priv->gc.ngpio, priv->nirq, priv->irq_start); in xgene_gpio_sb_probe()
274 priv->irq_domain = irq_domain_create_hierarchy(parent_domain, in xgene_gpio_sb_probe()
275 0, priv->nirq, pdev->dev.fwnode, in xgene_gpio_sb_probe()
277 if (!priv->irq_domain) in xgene_gpio_sb_probe()
278 return -ENODEV; in xgene_gpio_sb_probe()
280 priv->gc.irq.domain = priv->irq_domain; in xgene_gpio_sb_probe()
282 ret = devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv); in xgene_gpio_sb_probe()
284 dev_err(&pdev->dev, in xgene_gpio_sb_probe()
285 "failed to register X-Gene GPIO Standby driver\n"); in xgene_gpio_sb_probe()
286 irq_domain_remove(priv->irq_domain); in xgene_gpio_sb_probe()
290 dev_info(&pdev->dev, "X-Gene GPIO Standby driver registered\n"); in xgene_gpio_sb_probe()
293 acpi_gpiochip_request_interrupts(&priv->gc); in xgene_gpio_sb_probe()
302 acpi_gpiochip_free_interrupts(&priv->gc); in xgene_gpio_sb_remove()
304 irq_domain_remove(priv->irq_domain); in xgene_gpio_sb_remove()
308 {.compatible = "apm,xgene-gpio-sb", },
323 .name = "xgene-gpio-sb",
333 MODULE_DESCRIPTION("APM X-Gene GPIO Standby driver");