gpio-ixp4xx.c (3c938cc5cebcbd2291fe97f523c0705a2c24c77d) gpio-ixp4xx.c (c83227a5d05ed77b634ce4c2fc5f143ae2a4d6f5)
1// SPDX-License-Identifier: GPL-2.0
2//
3// IXP4 GPIO driver
4// Copyright (C) 2019 Linus Walleij <linus.walleij@linaro.org>
5//
6// based on previous work and know-how from:
7// Deepak Saxena <dsaxena@plexity.net>
8
9#include <linux/gpio/driver.h>
10#include <linux/io.h>
11#include <linux/irq.h>
12#include <linux/irqdomain.h>
13#include <linux/irqchip.h>
14#include <linux/of_irq.h>
15#include <linux/platform_device.h>
16#include <linux/bitops.h>
1// SPDX-License-Identifier: GPL-2.0
2//
3// IXP4 GPIO driver
4// Copyright (C) 2019 Linus Walleij <linus.walleij@linaro.org>
5//
6// based on previous work and know-how from:
7// Deepak Saxena <dsaxena@plexity.net>
8
9#include <linux/gpio/driver.h>
10#include <linux/io.h>
11#include <linux/irq.h>
12#include <linux/irqdomain.h>
13#include <linux/irqchip.h>
14#include <linux/of_irq.h>
15#include <linux/platform_device.h>
16#include <linux/bitops.h>
17/* Include that go away with DT transition */
18#include <linux/irqchip/irq-ixp4xx.h>
19
20#define IXP4XX_REG_GPOUT 0x00
21#define IXP4XX_REG_GPOE 0x04
22#define IXP4XX_REG_GPIN 0x08
23#define IXP4XX_REG_GPIS 0x0C
24#define IXP4XX_REG_GPIT1 0x10
25#define IXP4XX_REG_GPIT2 0x14
26#define IXP4XX_REG_GPCLK 0x18

--- 161 unchanged lines hidden (view full) ---

188{
189 unsigned long flags;
190 struct device *dev = &pdev->dev;
191 struct device_node *np = dev->of_node;
192 struct irq_domain *parent;
193 struct resource *res;
194 struct ixp4xx_gpio *g;
195 struct gpio_irq_chip *girq;
17
18#define IXP4XX_REG_GPOUT 0x00
19#define IXP4XX_REG_GPOE 0x04
20#define IXP4XX_REG_GPIN 0x08
21#define IXP4XX_REG_GPIS 0x0C
22#define IXP4XX_REG_GPIT1 0x10
23#define IXP4XX_REG_GPIT2 0x14
24#define IXP4XX_REG_GPCLK 0x18

--- 161 unchanged lines hidden (view full) ---

186{
187 unsigned long flags;
188 struct device *dev = &pdev->dev;
189 struct device_node *np = dev->of_node;
190 struct irq_domain *parent;
191 struct resource *res;
192 struct ixp4xx_gpio *g;
193 struct gpio_irq_chip *girq;
194 struct device_node *irq_parent;
196 int ret;
197
198 g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL);
199 if (!g)
200 return -ENOMEM;
201 g->dev = dev;
202
203 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
204 g->base = devm_ioremap_resource(dev, res);
205 if (IS_ERR(g->base))
206 return PTR_ERR(g->base);
207
195 int ret;
196
197 g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL);
198 if (!g)
199 return -ENOMEM;
200 g->dev = dev;
201
202 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
203 g->base = devm_ioremap_resource(dev, res);
204 if (IS_ERR(g->base))
205 return PTR_ERR(g->base);
206
208 /*
209 * When we convert to device tree we will simply look up the
210 * parent irqdomain using irq_find_host(parent) as parent comes
211 * from IRQCHIP_DECLARE(), then use of_node_to_fwnode() to get
212 * the fwnode. For now we need this boardfile style code.
213 */
214 if (np) {
215 struct device_node *irq_parent;
216
217 irq_parent = of_irq_find_parent(np);
218 if (!irq_parent) {
219 dev_err(dev, "no IRQ parent node\n");
220 return -ENODEV;
221 }
222 parent = irq_find_host(irq_parent);
223 if (!parent) {
224 dev_err(dev, "no IRQ parent domain\n");
225 return -ENODEV;
226 }
227 g->fwnode = of_node_to_fwnode(np);
228 } else {
229 parent = ixp4xx_get_irq_domain();
230 g->fwnode = irq_domain_alloc_fwnode(&res->start);
231 if (!g->fwnode) {
232 dev_err(dev, "no domain base\n");
233 return -ENODEV;
234 }
207 irq_parent = of_irq_find_parent(np);
208 if (!irq_parent) {
209 dev_err(dev, "no IRQ parent node\n");
210 return -ENODEV;
235 }
211 }
212 parent = irq_find_host(irq_parent);
213 if (!parent) {
214 dev_err(dev, "no IRQ parent domain\n");
215 return -ENODEV;
216 }
217 g->fwnode = of_node_to_fwnode(np);
236
237 /*
238 * Make sure GPIO 14 and 15 are NOT used as clocks but GPIO on
239 * specific machines.
240 */
241 if (of_machine_is_compatible("dlink,dsm-g600-a") ||
242 of_machine_is_compatible("iom,nas-100d"))
243 __raw_writel(0x0, g->base + IXP4XX_REG_GPCLK);

--- 75 unchanged lines hidden ---
218
219 /*
220 * Make sure GPIO 14 and 15 are NOT used as clocks but GPIO on
221 * specific machines.
222 */
223 if (of_machine_is_compatible("dlink,dsm-g600-a") ||
224 of_machine_is_compatible("iom,nas-100d"))
225 __raw_writel(0x0, g->base + IXP4XX_REG_GPCLK);

--- 75 unchanged lines hidden ---