blob: bf3b9597abd80807f76395cfcdc88c76b1091c6b [file] [log] [blame]
Grant Likelyc103de22011-06-04 18:38:28 -06001/*
2 * Moorestown platform Langwell chip GPIO driver
3 *
Andy Shevchenko611a4852013-05-22 13:20:14 +03004 * Copyright (c) 2008, 2009, 2013, Intel Corporation.
Alek Du8bf02612009-09-22 16:46:36 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20/* Supports:
21 * Moorestown platform Langwell chip.
Alek Du8081c842010-05-26 14:42:25 -070022 * Medfield platform Penwell chip.
Alek Du8bf02612009-09-22 16:46:36 -070023 */
24
25#include <linux/module.h>
26#include <linux/pci.h>
Alan Cox72b43792010-10-27 15:33:23 -070027#include <linux/platform_device.h>
Alek Du8bf02612009-09-22 16:46:36 -070028#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/stddef.h>
31#include <linux/interrupt.h>
32#include <linux/init.h>
33#include <linux/irq.h>
34#include <linux/io.h>
35#include <linux/gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Kristen Carlson Accardi78128032011-05-10 14:23:45 +010037#include <linux/pm_runtime.h>
Mika Westerberg465f2bd2012-05-02 11:15:50 +030038#include <linux/irqdomain.h>
Alek Du8bf02612009-09-22 16:46:36 -070039
David Cohend56d6b32013-10-04 13:01:40 -070040#define LNW_IRQ_TYPE_EDGE (1 << 0)
41#define LNW_IRQ_TYPE_LEVEL (1 << 1)
42
Alek Du8081c842010-05-26 14:42:25 -070043/*
44 * Langwell chip has 64 pins and thus there are 2 32bit registers to control
45 * each feature, while Penwell chip has 96 pins for each block, and need 3 32bit
46 * registers to control them, so we only define the order here instead of a
47 * structure, to get a bit offset for a pin (use GPDR as an example):
48 *
49 * nreg = ngpio / 32;
50 * reg = offset / 32;
51 * bit = offset % 32;
52 * reg_addr = reg_base + GPDR * nreg * 4 + reg * 4;
53 *
54 * so the bit of reg_addr is to control pin offset's GPDR feature
55*/
56
57enum GPIO_REG {
58 GPLR = 0, /* pin level read-only */
59 GPDR, /* pin direction */
60 GPSR, /* pin set */
61 GPCR, /* pin clear */
62 GRER, /* rising edge detect */
63 GFER, /* falling edge detect */
64 GEDR, /* edge detect result */
Adrian Hunter8c0f7b12011-10-03 14:36:07 +030065 GAFR, /* alt function */
Alek Du8bf02612009-09-22 16:46:36 -070066};
67
David Cohend56d6b32013-10-04 13:01:40 -070068/* langwell gpio driver data */
69struct lnw_gpio_ddata {
70 u16 ngpio; /* number of gpio pins */
71 u32 gplr_offset; /* offset of first GPLR register from base */
72 u32 flis_base; /* base address of FLIS registers */
73 u32 flis_len; /* length of FLIS registers */
74 u32 (*get_flis_offset)(int gpio);
75 u32 chip_irq_type; /* chip interrupt type */
76};
77
Alek Du8bf02612009-09-22 16:46:36 -070078struct lnw_gpio {
79 struct gpio_chip chip;
Andy Shevchenko64c8cbc2013-05-22 13:20:11 +030080 void __iomem *reg_base;
Alek Du8bf02612009-09-22 16:46:36 -070081 spinlock_t lock;
Kristen Carlson Accardi78128032011-05-10 14:23:45 +010082 struct pci_dev *pdev;
Mika Westerberg465f2bd2012-05-02 11:15:50 +030083 struct irq_domain *domain;
Alek Du8bf02612009-09-22 16:46:36 -070084};
85
David Cohen46ebfbc2012-12-20 14:45:51 -080086#define to_lnw_priv(chip) container_of(chip, struct lnw_gpio, chip)
87
Alek Du8081c842010-05-26 14:42:25 -070088static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset,
Andy Shevchenko611a4852013-05-22 13:20:14 +030089 enum GPIO_REG reg_type)
Alek Du8bf02612009-09-22 16:46:36 -070090{
David Cohen46ebfbc2012-12-20 14:45:51 -080091 struct lnw_gpio *lnw = to_lnw_priv(chip);
Alek Du8081c842010-05-26 14:42:25 -070092 unsigned nreg = chip->ngpio / 32;
Alek Du8bf02612009-09-22 16:46:36 -070093 u8 reg = offset / 32;
Alek Du8bf02612009-09-22 16:46:36 -070094
Andy Shevchenko611a4852013-05-22 13:20:14 +030095 return lnw->reg_base + reg_type * nreg * 4 + reg * 4;
Alek Du8081c842010-05-26 14:42:25 -070096}
97
Adrian Hunter8c0f7b12011-10-03 14:36:07 +030098static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset,
99 enum GPIO_REG reg_type)
100{
David Cohen46ebfbc2012-12-20 14:45:51 -0800101 struct lnw_gpio *lnw = to_lnw_priv(chip);
Adrian Hunter8c0f7b12011-10-03 14:36:07 +0300102 unsigned nreg = chip->ngpio / 32;
103 u8 reg = offset / 16;
Adrian Hunter8c0f7b12011-10-03 14:36:07 +0300104
Andy Shevchenko611a4852013-05-22 13:20:14 +0300105 return lnw->reg_base + reg_type * nreg * 4 + reg * 4;
Adrian Hunter8c0f7b12011-10-03 14:36:07 +0300106}
107
108static int lnw_gpio_request(struct gpio_chip *chip, unsigned offset)
109{
110 void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR);
111 u32 value = readl(gafr);
112 int shift = (offset % 16) << 1, af = (value >> shift) & 3;
113
114 if (af) {
115 value &= ~(3 << shift);
116 writel(value, gafr);
117 }
118 return 0;
119}
120
Alek Du8081c842010-05-26 14:42:25 -0700121static int lnw_gpio_get(struct gpio_chip *chip, unsigned offset)
122{
123 void __iomem *gplr = gpio_reg(chip, offset, GPLR);
124
Alek Du8bf02612009-09-22 16:46:36 -0700125 return readl(gplr) & BIT(offset % 32);
126}
127
128static void lnw_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
129{
Alek Du8bf02612009-09-22 16:46:36 -0700130 void __iomem *gpsr, *gpcr;
131
132 if (value) {
Alek Du8081c842010-05-26 14:42:25 -0700133 gpsr = gpio_reg(chip, offset, GPSR);
Alek Du8bf02612009-09-22 16:46:36 -0700134 writel(BIT(offset % 32), gpsr);
135 } else {
Alek Du8081c842010-05-26 14:42:25 -0700136 gpcr = gpio_reg(chip, offset, GPCR);
Alek Du8bf02612009-09-22 16:46:36 -0700137 writel(BIT(offset % 32), gpcr);
138 }
139}
140
141static int lnw_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
142{
David Cohen46ebfbc2012-12-20 14:45:51 -0800143 struct lnw_gpio *lnw = to_lnw_priv(chip);
Alek Du8081c842010-05-26 14:42:25 -0700144 void __iomem *gpdr = gpio_reg(chip, offset, GPDR);
Alek Du8bf02612009-09-22 16:46:36 -0700145 u32 value;
146 unsigned long flags;
Alek Du8bf02612009-09-22 16:46:36 -0700147
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100148 if (lnw->pdev)
149 pm_runtime_get(&lnw->pdev->dev);
150
Alek Du8bf02612009-09-22 16:46:36 -0700151 spin_lock_irqsave(&lnw->lock, flags);
152 value = readl(gpdr);
153 value &= ~BIT(offset % 32);
154 writel(value, gpdr);
155 spin_unlock_irqrestore(&lnw->lock, flags);
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100156
157 if (lnw->pdev)
158 pm_runtime_put(&lnw->pdev->dev);
159
Alek Du8bf02612009-09-22 16:46:36 -0700160 return 0;
161}
162
163static int lnw_gpio_direction_output(struct gpio_chip *chip,
164 unsigned offset, int value)
165{
David Cohen46ebfbc2012-12-20 14:45:51 -0800166 struct lnw_gpio *lnw = to_lnw_priv(chip);
Alek Du8081c842010-05-26 14:42:25 -0700167 void __iomem *gpdr = gpio_reg(chip, offset, GPDR);
Alek Du8bf02612009-09-22 16:46:36 -0700168 unsigned long flags;
Alek Du8bf02612009-09-22 16:46:36 -0700169
170 lnw_gpio_set(chip, offset, value);
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100171
172 if (lnw->pdev)
173 pm_runtime_get(&lnw->pdev->dev);
174
Alek Du8bf02612009-09-22 16:46:36 -0700175 spin_lock_irqsave(&lnw->lock, flags);
176 value = readl(gpdr);
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700177 value |= BIT(offset % 32);
Alek Du8bf02612009-09-22 16:46:36 -0700178 writel(value, gpdr);
179 spin_unlock_irqrestore(&lnw->lock, flags);
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100180
181 if (lnw->pdev)
182 pm_runtime_put(&lnw->pdev->dev);
183
Alek Du8bf02612009-09-22 16:46:36 -0700184 return 0;
185}
186
187static int lnw_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
188{
David Cohen46ebfbc2012-12-20 14:45:51 -0800189 struct lnw_gpio *lnw = to_lnw_priv(chip);
Mika Westerberg465f2bd2012-05-02 11:15:50 +0300190 return irq_create_mapping(lnw->domain, offset);
Alek Du8bf02612009-09-22 16:46:36 -0700191}
192
Lennert Buytenhek5ffd72c2011-01-12 17:00:13 -0800193static int lnw_irq_type(struct irq_data *d, unsigned type)
Alek Du8bf02612009-09-22 16:46:36 -0700194{
Lennert Buytenhek5ffd72c2011-01-12 17:00:13 -0800195 struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d);
Mika Westerberg465f2bd2012-05-02 11:15:50 +0300196 u32 gpio = irqd_to_hwirq(d);
Alek Du8bf02612009-09-22 16:46:36 -0700197 unsigned long flags;
198 u32 value;
Alek Du8081c842010-05-26 14:42:25 -0700199 void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER);
200 void __iomem *gfer = gpio_reg(&lnw->chip, gpio, GFER);
Alek Du8bf02612009-09-22 16:46:36 -0700201
Roel Kluin4efec622009-12-15 16:46:18 -0800202 if (gpio >= lnw->chip.ngpio)
Alek Du8bf02612009-09-22 16:46:36 -0700203 return -EINVAL;
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100204
205 if (lnw->pdev)
206 pm_runtime_get(&lnw->pdev->dev);
207
Alek Du8bf02612009-09-22 16:46:36 -0700208 spin_lock_irqsave(&lnw->lock, flags);
209 if (type & IRQ_TYPE_EDGE_RISING)
210 value = readl(grer) | BIT(gpio % 32);
211 else
212 value = readl(grer) & (~BIT(gpio % 32));
213 writel(value, grer);
214
215 if (type & IRQ_TYPE_EDGE_FALLING)
216 value = readl(gfer) | BIT(gpio % 32);
217 else
218 value = readl(gfer) & (~BIT(gpio % 32));
219 writel(value, gfer);
220 spin_unlock_irqrestore(&lnw->lock, flags);
221
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100222 if (lnw->pdev)
223 pm_runtime_put(&lnw->pdev->dev);
224
Alek Du8bf02612009-09-22 16:46:36 -0700225 return 0;
Andrew Mortonfd0574c2010-10-27 15:33:22 -0700226}
Alek Du8bf02612009-09-22 16:46:36 -0700227
Lennert Buytenhek5ffd72c2011-01-12 17:00:13 -0800228static void lnw_irq_unmask(struct irq_data *d)
Alek Du8bf02612009-09-22 16:46:36 -0700229{
Andrew Mortonfd0574c2010-10-27 15:33:22 -0700230}
Alek Du8bf02612009-09-22 16:46:36 -0700231
Lennert Buytenhek5ffd72c2011-01-12 17:00:13 -0800232static void lnw_irq_mask(struct irq_data *d)
Alek Du8bf02612009-09-22 16:46:36 -0700233{
Andrew Mortonfd0574c2010-10-27 15:33:22 -0700234}
Alek Du8bf02612009-09-22 16:46:36 -0700235
236static struct irq_chip lnw_irqchip = {
237 .name = "LNW-GPIO",
Lennert Buytenhek5ffd72c2011-01-12 17:00:13 -0800238 .irq_mask = lnw_irq_mask,
239 .irq_unmask = lnw_irq_unmask,
240 .irq_set_type = lnw_irq_type,
Alek Du8bf02612009-09-22 16:46:36 -0700241};
242
David Cohend56d6b32013-10-04 13:01:40 -0700243static const struct lnw_gpio_ddata gpio_lincroft = {
244 .ngpio = 64,
245};
246
247static const struct lnw_gpio_ddata gpio_penwell_aon = {
248 .ngpio = 96,
249 .chip_irq_type = LNW_IRQ_TYPE_EDGE,
250};
251
252static const struct lnw_gpio_ddata gpio_penwell_core = {
253 .ngpio = 96,
254 .chip_irq_type = LNW_IRQ_TYPE_EDGE,
255};
256
257static const struct lnw_gpio_ddata gpio_cloverview_aon = {
258 .ngpio = 96,
259 .chip_irq_type = LNW_IRQ_TYPE_EDGE | LNW_IRQ_TYPE_LEVEL,
260};
261
262static const struct lnw_gpio_ddata gpio_cloverview_core = {
263 .ngpio = 96,
264 .chip_irq_type = LNW_IRQ_TYPE_EDGE,
265};
266
267static const struct lnw_gpio_ddata gpio_tangier = {
268 .ngpio = 192,
269 .gplr_offset = 4,
270 .flis_base = 0xff0c0000,
271 .flis_len = 0x8000,
272 .get_flis_offset = NULL,
273 .chip_irq_type = LNW_IRQ_TYPE_EDGE,
274};
275
276static DEFINE_PCI_DEVICE_TABLE(lnw_gpio_ids) = {
277 {
278 /* Lincroft */
279 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080f),
280 .driver_data = (kernel_ulong_t)&gpio_lincroft,
281 },
282 {
283 /* Penwell AON */
284 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081f),
285 .driver_data = (kernel_ulong_t)&gpio_penwell_aon,
286 },
287 {
288 /* Penwell Core */
289 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081a),
290 .driver_data = (kernel_ulong_t)&gpio_penwell_core,
291 },
292 {
293 /* Cloverview Aon */
294 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08eb),
295 .driver_data = (kernel_ulong_t)&gpio_cloverview_aon,
296 },
297 {
298 /* Cloverview Core */
299 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7),
300 .driver_data = (kernel_ulong_t)&gpio_cloverview_core,
301 },
302 {
303 /* Tangier */
304 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1199),
305 .driver_data = (kernel_ulong_t)&gpio_tangier,
306 },
307 { 0 }
Alek Du8bf02612009-09-22 16:46:36 -0700308};
309MODULE_DEVICE_TABLE(pci, lnw_gpio_ids);
310
311static void lnw_irq_handler(unsigned irq, struct irq_desc *desc)
312{
Thomas Gleixner20e2aa92011-03-17 19:32:49 +0000313 struct irq_data *data = irq_desc_get_irq_data(desc);
314 struct lnw_gpio *lnw = irq_data_get_irq_handler_data(data);
315 struct irq_chip *chip = irq_data_get_irq_chip(data);
Thomas Gleixner84bead62011-03-17 19:32:58 +0000316 u32 base, gpio, mask;
Thomas Gleixner732063b2011-03-17 19:32:55 +0000317 unsigned long pending;
Alek Du8bf02612009-09-22 16:46:36 -0700318 void __iomem *gedr;
Alek Du8bf02612009-09-22 16:46:36 -0700319
320 /* check GPIO controller to check which pin triggered the interrupt */
Alek Du8081c842010-05-26 14:42:25 -0700321 for (base = 0; base < lnw->chip.ngpio; base += 32) {
322 gedr = gpio_reg(&lnw->chip, base, GEDR);
Mika Westerbergc8f925b2012-05-10 13:01:22 +0300323 while ((pending = readl(gedr))) {
Mathias Nyman2345b202011-07-08 10:02:18 +0100324 gpio = __ffs(pending);
Thomas Gleixner84bead62011-03-17 19:32:58 +0000325 mask = BIT(gpio);
Thomas Gleixner84bead62011-03-17 19:32:58 +0000326 /* Clear before handling so we can't lose an edge */
327 writel(mask, gedr);
Mika Westerberg465f2bd2012-05-02 11:15:50 +0300328 generic_handle_irq(irq_find_mapping(lnw->domain,
329 base + gpio));
Thomas Gleixner732063b2011-03-17 19:32:55 +0000330 }
Alek Du8bf02612009-09-22 16:46:36 -0700331 }
Feng Tang0766d202011-01-25 15:07:15 -0800332
Thomas Gleixner20e2aa92011-03-17 19:32:49 +0000333 chip->irq_eoi(data);
Alek Du8bf02612009-09-22 16:46:36 -0700334}
335
Mika Westerbergf5f93112012-04-05 12:15:17 +0300336static void lnw_irq_init_hw(struct lnw_gpio *lnw)
337{
338 void __iomem *reg;
339 unsigned base;
340
341 for (base = 0; base < lnw->chip.ngpio; base += 32) {
342 /* Clear the rising-edge detect register */
343 reg = gpio_reg(&lnw->chip, base, GRER);
344 writel(0, reg);
345 /* Clear the falling-edge detect register */
346 reg = gpio_reg(&lnw->chip, base, GFER);
347 writel(0, reg);
348 /* Clear the edge detect status register */
349 reg = gpio_reg(&lnw->chip, base, GEDR);
350 writel(~0, reg);
351 }
352}
353
Mika Westerberg465f2bd2012-05-02 11:15:50 +0300354static int lnw_gpio_irq_map(struct irq_domain *d, unsigned int virq,
355 irq_hw_number_t hw)
356{
357 struct lnw_gpio *lnw = d->host_data;
358
359 irq_set_chip_and_handler_name(virq, &lnw_irqchip, handle_simple_irq,
360 "demux");
361 irq_set_chip_data(virq, lnw);
362 irq_set_irq_type(virq, IRQ_TYPE_NONE);
363
364 return 0;
365}
366
367static const struct irq_domain_ops lnw_gpio_irq_ops = {
368 .map = lnw_gpio_irq_map,
369 .xlate = irq_domain_xlate_twocell,
370};
371
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100372static int lnw_gpio_runtime_idle(struct device *dev)
373{
Rafael J. Wysocki45f0a852013-06-03 21:49:52 +0200374 pm_schedule_suspend(dev, 500);
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100375 return -EBUSY;
376}
377
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100378static const struct dev_pm_ops lnw_gpio_pm_ops = {
David Cohen46ebfbc2012-12-20 14:45:51 -0800379 SET_RUNTIME_PM_OPS(NULL, NULL, lnw_gpio_runtime_idle)
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100380};
381
Bill Pemberton38363092012-11-19 13:22:34 -0500382static int lnw_gpio_probe(struct pci_dev *pdev,
Andy Shevchenko64c8cbc2013-05-22 13:20:11 +0300383 const struct pci_device_id *id)
Alek Du8bf02612009-09-22 16:46:36 -0700384{
Andy Shevchenko64c8cbc2013-05-22 13:20:11 +0300385 void __iomem *base;
Alek Du8bf02612009-09-22 16:46:36 -0700386 struct lnw_gpio *lnw;
Alek Du8bf02612009-09-22 16:46:36 -0700387 u32 gpio_base;
David Cohen2519f9a2013-05-06 16:11:03 -0700388 u32 irq_base;
Julia Lawalld6a2b7b2012-08-05 11:52:34 +0200389 int retval;
David Cohend56d6b32013-10-04 13:01:40 -0700390 struct lnw_gpio_ddata *ddata = (struct lnw_gpio_ddata *)id->driver_data;
Alek Du8bf02612009-09-22 16:46:36 -0700391
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300392 retval = pcim_enable_device(pdev);
Alek Du8bf02612009-09-22 16:46:36 -0700393 if (retval)
Mika Westerberg8302c742012-04-05 12:15:15 +0300394 return retval;
Alek Du8bf02612009-09-22 16:46:36 -0700395
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300396 retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev));
Alek Du8bf02612009-09-22 16:46:36 -0700397 if (retval) {
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300398 dev_err(&pdev->dev, "I/O memory mapping error\n");
399 return retval;
Alek Du8bf02612009-09-22 16:46:36 -0700400 }
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300401
402 base = pcim_iomap_table(pdev)[1];
Andy Shevchenko64c8cbc2013-05-22 13:20:11 +0300403
404 irq_base = readl(base);
405 gpio_base = readl(sizeof(u32) + base);
406
Alek Du8bf02612009-09-22 16:46:36 -0700407 /* release the IO mapping, since we already get the info from bar1 */
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300408 pcim_iounmap_regions(pdev, 1 << 1);
Alek Du8bf02612009-09-22 16:46:36 -0700409
David Cohen46ebfbc2012-12-20 14:45:51 -0800410 lnw = devm_kzalloc(&pdev->dev, sizeof(*lnw), GFP_KERNEL);
Alek Du8bf02612009-09-22 16:46:36 -0700411 if (!lnw) {
Andy Shevchenko8aca1192013-05-22 13:20:13 +0300412 dev_err(&pdev->dev, "can't allocate chip data\n");
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300413 return -ENOMEM;
Alek Du8bf02612009-09-22 16:46:36 -0700414 }
Mika Westerbergb3e35af2012-04-05 12:15:16 +0300415
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300416 lnw->reg_base = pcim_iomap_table(pdev)[0];
Alek Du8bf02612009-09-22 16:46:36 -0700417 lnw->chip.label = dev_name(&pdev->dev);
Adrian Hunter8c0f7b12011-10-03 14:36:07 +0300418 lnw->chip.request = lnw_gpio_request;
Alek Du8bf02612009-09-22 16:46:36 -0700419 lnw->chip.direction_input = lnw_gpio_direction_input;
420 lnw->chip.direction_output = lnw_gpio_direction_output;
421 lnw->chip.get = lnw_gpio_get;
422 lnw->chip.set = lnw_gpio_set;
423 lnw->chip.to_irq = lnw_gpio_to_irq;
424 lnw->chip.base = gpio_base;
David Cohend56d6b32013-10-04 13:01:40 -0700425 lnw->chip.ngpio = ddata->ngpio;
Alek Du8bf02612009-09-22 16:46:36 -0700426 lnw->chip.can_sleep = 0;
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100427 lnw->pdev = pdev;
David Cohen2519f9a2013-05-06 16:11:03 -0700428
Andy Shevchenkoaeb168f2013-05-22 13:20:10 +0300429 spin_lock_init(&lnw->lock);
430
David Cohend56d6b32013-10-04 13:01:40 -0700431 lnw->domain = irq_domain_add_simple(pdev->dev.of_node, ddata->ngpio,
432 irq_base, &lnw_gpio_irq_ops, lnw);
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300433 if (!lnw->domain)
434 return -ENOMEM;
David Cohen2519f9a2013-05-06 16:11:03 -0700435
Alek Du8bf02612009-09-22 16:46:36 -0700436 pci_set_drvdata(pdev, lnw);
437 retval = gpiochip_add(&lnw->chip);
438 if (retval) {
Andy Shevchenko8aca1192013-05-22 13:20:13 +0300439 dev_err(&pdev->dev, "gpiochip_add error %d\n", retval);
Andy Shevchenko786e07e2013-05-22 13:20:12 +0300440 return retval;
Alek Du8bf02612009-09-22 16:46:36 -0700441 }
Mika Westerbergf5f93112012-04-05 12:15:17 +0300442
443 lnw_irq_init_hw(lnw);
444
Thomas Gleixner674db902011-03-17 19:32:52 +0000445 irq_set_handler_data(pdev->irq, lnw);
446 irq_set_chained_handler(pdev->irq, lnw_irq_handler);
Alek Du8bf02612009-09-22 16:46:36 -0700447
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100448 pm_runtime_put_noidle(&pdev->dev);
449 pm_runtime_allow(&pdev->dev);
450
Mika Westerberg8302c742012-04-05 12:15:15 +0300451 return 0;
Alek Du8bf02612009-09-22 16:46:36 -0700452}
453
454static struct pci_driver lnw_gpio_driver = {
455 .name = "langwell_gpio",
456 .id_table = lnw_gpio_ids,
457 .probe = lnw_gpio_probe,
Kristen Carlson Accardi78128032011-05-10 14:23:45 +0100458 .driver = {
459 .pm = &lnw_gpio_pm_ops,
460 },
Alek Du8bf02612009-09-22 16:46:36 -0700461};
462
463static int __init lnw_gpio_init(void)
464{
Andy Shevchenko10b20a92013-06-17 16:57:06 +0300465 return pci_register_driver(&lnw_gpio_driver);
Alek Du8bf02612009-09-22 16:46:36 -0700466}
467
468device_initcall(lnw_gpio_init);