Lines Matching +full:standby +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * AppliedMicro X-Gene SoC GPIO-Standby Driver
19 #include "gpiolib-acpi.h"
22 #define XGENE_NIRQ_PROPERTY "apm,nr-irqs"
23 #define XGENE_NGPIO_PROPERTY "apm,nr-gpios"
24 #define XGENE_IRQ_START_PROPERTY "apm,irq-start"
41 * struct xgene_gpio_sb - GPIO-Standby private data structure.
42 * @gc: memory-mapped GPIO controllers.
58 #define HWIRQ_TO_GPIO(priv, hwirq) ((hwirq) + (priv)->irq_start)
59 #define GPIO_TO_HWIRQ(priv, gpio) ((gpio) - (priv)->irq_start)
66 data = gc->read_reg(reg); in xgene_gpio_set_bit()
71 gc->write_reg(reg, data); in xgene_gpio_set_bit()
77 int gpio = HWIRQ_TO_GPIO(priv, d->hwirq); in xgene_gpio_sb_irq_set_type()
93 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, in xgene_gpio_sb_irq_set_type()
95 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_INT_LVL, in xgene_gpio_sb_irq_set_type()
96 d->hwirq, lvl_type); in xgene_gpio_sb_irq_set_type()
118 if ((gpio < priv->irq_start) || in xgene_gpio_sb_to_irq()
119 (gpio > HWIRQ_TO_GPIO(priv, priv->nirq))) in xgene_gpio_sb_to_irq()
120 return -ENXIO; in xgene_gpio_sb_to_irq()
122 fwspec.fwnode = gc->parent->fwnode; in xgene_gpio_sb_to_irq()
133 struct xgene_gpio_sb *priv = d->host_data; in xgene_gpio_sb_domain_activate()
134 u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); in xgene_gpio_sb_domain_activate()
137 ret = gpiochip_lock_as_irq(&priv->gc, gpio); in xgene_gpio_sb_domain_activate()
139 dev_err(priv->gc.parent, in xgene_gpio_sb_domain_activate()
140 "Unable to configure XGene GPIO standby pin %d as IRQ\n", in xgene_gpio_sb_domain_activate()
145 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, in xgene_gpio_sb_domain_activate()
153 struct xgene_gpio_sb *priv = d->host_data; in xgene_gpio_sb_domain_deactivate()
154 u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); in xgene_gpio_sb_domain_deactivate()
156 gpiochip_unlock_as_irq(&priv->gc, gpio); in xgene_gpio_sb_domain_deactivate()
157 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, in xgene_gpio_sb_domain_deactivate()
166 struct xgene_gpio_sb *priv = d->host_data; in xgene_gpio_sb_domain_translate()
168 if ((fwspec->param_count != 2) || in xgene_gpio_sb_domain_translate()
169 (fwspec->param[0] >= priv->nirq)) in xgene_gpio_sb_domain_translate()
170 return -EINVAL; in xgene_gpio_sb_domain_translate()
171 *hwirq = fwspec->param[0]; in xgene_gpio_sb_domain_translate()
172 *type = fwspec->param[1]; in xgene_gpio_sb_domain_translate()
182 struct xgene_gpio_sb *priv = domain->host_data; in xgene_gpio_sb_domain_alloc()
186 hwirq = fwspec->param[0]; in xgene_gpio_sb_domain_alloc()
191 parent_fwspec.fwnode = domain->parent->fwnode; in xgene_gpio_sb_domain_alloc()
196 parent_fwspec.param[1] = hwirq + priv->parent_irq_base - 32; in xgene_gpio_sb_domain_alloc()
197 parent_fwspec.param[2] = fwspec->param[1]; in xgene_gpio_sb_domain_alloc()
200 parent_fwspec.param[0] = hwirq + priv->parent_irq_base; in xgene_gpio_sb_domain_alloc()
201 parent_fwspec.param[1] = fwspec->param[1]; in xgene_gpio_sb_domain_alloc()
203 return -EINVAL; in xgene_gpio_sb_domain_alloc()
225 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in xgene_gpio_sb_probe()
227 return -ENOMEM; in xgene_gpio_sb_probe()
233 priv->regs = regs; in xgene_gpio_sb_probe()
237 priv->parent_irq_base = irq_get_irq_data(ret)->hwirq; in xgene_gpio_sb_probe()
238 parent_domain = irq_get_irq_data(ret)->domain; in xgene_gpio_sb_probe()
241 dev_err(&pdev->dev, "unable to obtain parent domain\n"); in xgene_gpio_sb_probe()
242 return -ENODEV; in xgene_gpio_sb_probe()
245 ret = bgpio_init(&priv->gc, &pdev->dev, 4, in xgene_gpio_sb_probe()
252 priv->gc.to_irq = xgene_gpio_sb_to_irq; in xgene_gpio_sb_probe()
255 priv->irq_start = XGENE_DFLT_IRQ_START_PIN; in xgene_gpio_sb_probe()
256 if (!device_property_read_u32(&pdev->dev, in xgene_gpio_sb_probe()
258 priv->irq_start = val32; in xgene_gpio_sb_probe()
261 priv->nirq = XGENE_DFLT_MAX_NIRQ; in xgene_gpio_sb_probe()
262 if (!device_property_read_u32(&pdev->dev, XGENE_NIRQ_PROPERTY, &val32)) in xgene_gpio_sb_probe()
263 priv->nirq = val32; in xgene_gpio_sb_probe()
266 priv->gc.ngpio = XGENE_DFLT_MAX_NGPIO; in xgene_gpio_sb_probe()
267 if (!device_property_read_u32(&pdev->dev, XGENE_NGPIO_PROPERTY, &val32)) in xgene_gpio_sb_probe()
268 priv->gc.ngpio = val32; in xgene_gpio_sb_probe()
270 dev_info(&pdev->dev, "Support %d gpios, %d irqs start from pin %d\n", in xgene_gpio_sb_probe()
271 priv->gc.ngpio, priv->nirq, priv->irq_start); in xgene_gpio_sb_probe()
275 priv->irq_domain = irq_domain_create_hierarchy(parent_domain, in xgene_gpio_sb_probe()
276 0, priv->nirq, pdev->dev.fwnode, in xgene_gpio_sb_probe()
278 if (!priv->irq_domain) in xgene_gpio_sb_probe()
279 return -ENODEV; in xgene_gpio_sb_probe()
281 priv->gc.irq.domain = priv->irq_domain; in xgene_gpio_sb_probe()
283 ret = devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv); in xgene_gpio_sb_probe()
285 dev_err(&pdev->dev, in xgene_gpio_sb_probe()
286 "failed to register X-Gene GPIO Standby driver\n"); in xgene_gpio_sb_probe()
287 irq_domain_remove(priv->irq_domain); in xgene_gpio_sb_probe()
291 dev_info(&pdev->dev, "X-Gene GPIO Standby driver registered\n"); in xgene_gpio_sb_probe()
294 acpi_gpiochip_request_interrupts(&priv->gc); in xgene_gpio_sb_probe()
303 acpi_gpiochip_free_interrupts(&priv->gc); in xgene_gpio_sb_remove()
305 irq_domain_remove(priv->irq_domain); in xgene_gpio_sb_remove()
311 {.compatible = "apm,xgene-gpio-sb", },
326 .name = "xgene-gpio-sb",
336 MODULE_DESCRIPTION("APM X-Gene GPIO Standby driver");