blob: 03d6dd5dcb77c0092c5297acb34bd4da59a5f81a [file] [log] [blame]
Tomoya MORINAGA49a36792011-01-12 17:00:22 -08001/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
Paul Gortmakerbb207ef2011-07-03 13:38:09 -040017#include <linux/module.h>
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080018#include <linux/kernel.h>
Andrew Morton545554e2011-05-24 17:13:43 -070019#include <linux/slab.h>
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080020#include <linux/pci.h>
21#include <linux/gpio.h>
Tomoya MORINAGA54be5662011-08-05 13:04:21 +090022#include <linux/interrupt.h>
23#include <linux/irq.h>
24
25#define IOH_EDGE_FALLING 0
26#define IOH_EDGE_RISING BIT(0)
27#define IOH_LEVEL_L BIT(1)
28#define IOH_LEVEL_H (BIT(0) | BIT(1))
29#define IOH_EDGE_BOTH BIT(2)
30#define IOH_IM_MASK (BIT(0) | BIT(1) | BIT(2))
31
32#define IOH_IRQ_BASE 0
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080033
34#define PCI_VENDOR_ID_ROHM 0x10DB
35
36struct ioh_reg_comn {
37 u32 ien;
38 u32 istatus;
39 u32 idisp;
40 u32 iclr;
41 u32 imask;
42 u32 imaskclr;
43 u32 po;
44 u32 pi;
45 u32 pm;
46 u32 im_0;
47 u32 im_1;
48 u32 reserved;
49};
50
51struct ioh_regs {
52 struct ioh_reg_comn regs[8];
53 u32 reserve1[16];
54 u32 ioh_sel_reg[4];
55 u32 reserve2[11];
56 u32 srst;
57};
58
59/**
60 * struct ioh_gpio_reg_data - The register store data.
Tomoya MORINAGA54be5662011-08-05 13:04:21 +090061 * @ien_reg To store contents of interrupt enable register.
62 * @imask_reg: To store contents of interrupt mask regist
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080063 * @po_reg: To store contents of PO register.
64 * @pm_reg: To store contents of PM register.
Tomoya MORINAGA54be5662011-08-05 13:04:21 +090065 * @im0_reg: To store contents of interrupt mode regist0
66 * @im1_reg: To store contents of interrupt mode regist1
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +090067 * @use_sel_reg: To store contents of GPIO_USE_SEL0~3
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080068 */
69struct ioh_gpio_reg_data {
Tomoya MORINAGA54be5662011-08-05 13:04:21 +090070 u32 ien_reg;
71 u32 imask_reg;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080072 u32 po_reg;
73 u32 pm_reg;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +090074 u32 im0_reg;
75 u32 im1_reg;
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +090076 u32 use_sel_reg;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080077};
78
79/**
80 * struct ioh_gpio - GPIO private data structure.
81 * @base: PCI base address of Memory mapped I/O register.
82 * @reg: Memory mapped IOH GPIO register list.
83 * @dev: Pointer to device structure.
84 * @gpio: Data for GPIO infrastructure.
85 * @ioh_gpio_reg: Memory mapped Register data is saved here
86 * when suspend.
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +090087 * @gpio_use_sel: Save GPIO_USE_SEL1~4 register for PM
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080088 * @ch: Indicate GPIO channel
Tomoya MORINAGA54be5662011-08-05 13:04:21 +090089 * @irq_base: Save base of IRQ number for interrupt
90 * @spinlock: Used for register access protection in
91 * interrupt context ioh_irq_type and PM;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -080092 */
93struct ioh_gpio {
94 void __iomem *base;
95 struct ioh_regs __iomem *reg;
96 struct device *dev;
97 struct gpio_chip gpio;
98 struct ioh_gpio_reg_data ioh_gpio_reg;
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +090099 u32 gpio_use_sel;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800100 struct mutex lock;
101 int ch;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900102 int irq_base;
103 spinlock_t spinlock;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800104};
105
106static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12};
107
108static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
109{
110 u32 reg_val;
111 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
112
113 mutex_lock(&chip->lock);
114 reg_val = ioread32(&chip->reg->regs[chip->ch].po);
115 if (val)
116 reg_val |= (1 << nr);
117 else
118 reg_val &= ~(1 << nr);
119
120 iowrite32(reg_val, &chip->reg->regs[chip->ch].po);
121 mutex_unlock(&chip->lock);
122}
123
124static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr)
125{
126 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
127
128 return ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr);
129}
130
131static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
132 int val)
133{
134 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
135 u32 pm;
136 u32 reg_val;
137
138 mutex_lock(&chip->lock);
139 pm = ioread32(&chip->reg->regs[chip->ch].pm) &
140 ((1 << num_ports[chip->ch]) - 1);
141 pm |= (1 << nr);
142 iowrite32(pm, &chip->reg->regs[chip->ch].pm);
143
144 reg_val = ioread32(&chip->reg->regs[chip->ch].po);
145 if (val)
146 reg_val |= (1 << nr);
147 else
148 reg_val &= ~(1 << nr);
Peter Tyserba438612011-03-24 18:17:14 -0500149 iowrite32(reg_val, &chip->reg->regs[chip->ch].po);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800150
151 mutex_unlock(&chip->lock);
152
153 return 0;
154}
155
156static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
157{
158 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
159 u32 pm;
160
161 mutex_lock(&chip->lock);
162 pm = ioread32(&chip->reg->regs[chip->ch].pm) &
163 ((1 << num_ports[chip->ch]) - 1);
164 pm &= ~(1 << nr);
165 iowrite32(pm, &chip->reg->regs[chip->ch].pm);
166 mutex_unlock(&chip->lock);
167
168 return 0;
169}
170
Andrew Morton545554e2011-05-24 17:13:43 -0700171#ifdef CONFIG_PM
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800172/*
173 * Save register configuration and disable interrupts.
174 */
175static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
176{
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900177 int i;
178
179 for (i = 0; i < 8; i ++, chip++) {
180 chip->ioh_gpio_reg.po_reg =
181 ioread32(&chip->reg->regs[chip->ch].po);
182 chip->ioh_gpio_reg.pm_reg =
183 ioread32(&chip->reg->regs[chip->ch].pm);
184 chip->ioh_gpio_reg.ien_reg =
185 ioread32(&chip->reg->regs[chip->ch].ien);
186 chip->ioh_gpio_reg.imask_reg =
187 ioread32(&chip->reg->regs[chip->ch].imask);
188 chip->ioh_gpio_reg.im0_reg =
189 ioread32(&chip->reg->regs[chip->ch].im_0);
190 chip->ioh_gpio_reg.im1_reg =
191 ioread32(&chip->reg->regs[chip->ch].im_1);
192 if (i < 4)
193 chip->ioh_gpio_reg.use_sel_reg =
194 ioread32(&chip->reg->ioh_sel_reg[i]);
195 }
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800196}
197
198/*
199 * This function restores the register configuration of the GPIO device.
200 */
201static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip)
202{
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900203 int i;
204
205 for (i = 0; i < 8; i ++, chip++) {
206 iowrite32(chip->ioh_gpio_reg.po_reg,
207 &chip->reg->regs[chip->ch].po);
208 iowrite32(chip->ioh_gpio_reg.pm_reg,
209 &chip->reg->regs[chip->ch].pm);
210 iowrite32(chip->ioh_gpio_reg.ien_reg,
211 &chip->reg->regs[chip->ch].ien);
212 iowrite32(chip->ioh_gpio_reg.imask_reg,
213 &chip->reg->regs[chip->ch].imask);
214 iowrite32(chip->ioh_gpio_reg.im0_reg,
215 &chip->reg->regs[chip->ch].im_0);
216 iowrite32(chip->ioh_gpio_reg.im1_reg,
217 &chip->reg->regs[chip->ch].im_1);
218 if (i < 4)
219 iowrite32(chip->ioh_gpio_reg.use_sel_reg,
220 &chip->reg->ioh_sel_reg[i]);
221 }
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800222}
Andrew Morton545554e2011-05-24 17:13:43 -0700223#endif
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800224
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900225static int ioh_gpio_to_irq(struct gpio_chip *gpio, unsigned offset)
226{
227 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
228 return chip->irq_base + offset;
229}
230
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800231static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port)
232{
233 struct gpio_chip *gpio = &chip->gpio;
234
235 gpio->label = dev_name(chip->dev);
236 gpio->owner = THIS_MODULE;
237 gpio->direction_input = ioh_gpio_direction_input;
238 gpio->get = ioh_gpio_get;
239 gpio->direction_output = ioh_gpio_direction_output;
240 gpio->set = ioh_gpio_set;
241 gpio->dbg_show = NULL;
242 gpio->base = -1;
243 gpio->ngpio = num_port;
244 gpio->can_sleep = 0;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900245 gpio->to_irq = ioh_gpio_to_irq;
246}
247
248static int ioh_irq_type(struct irq_data *d, unsigned int type)
249{
250 u32 im;
Márton Némethdd9328a2012-01-15 10:57:34 +0100251 void __iomem *im_reg;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900252 u32 ien;
253 u32 im_pos;
254 int ch;
255 unsigned long flags;
256 u32 val;
257 int irq = d->irq;
258 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
259 struct ioh_gpio *chip = gc->private;
260
261 ch = irq - chip->irq_base;
262 if (irq <= chip->irq_base + 7) {
263 im_reg = &chip->reg->regs[chip->ch].im_0;
264 im_pos = ch;
265 } else {
266 im_reg = &chip->reg->regs[chip->ch].im_1;
267 im_pos = ch - 8;
268 }
269 dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d type=%d\n",
270 __func__, irq, type, ch, im_pos, type);
271
272 spin_lock_irqsave(&chip->spinlock, flags);
273
274 switch (type) {
275 case IRQ_TYPE_EDGE_RISING:
276 val = IOH_EDGE_RISING;
277 break;
278 case IRQ_TYPE_EDGE_FALLING:
279 val = IOH_EDGE_FALLING;
280 break;
281 case IRQ_TYPE_EDGE_BOTH:
282 val = IOH_EDGE_BOTH;
283 break;
284 case IRQ_TYPE_LEVEL_HIGH:
285 val = IOH_LEVEL_H;
286 break;
287 case IRQ_TYPE_LEVEL_LOW:
288 val = IOH_LEVEL_L;
289 break;
290 case IRQ_TYPE_PROBE:
291 goto end;
292 default:
293 dev_warn(chip->dev, "%s: unknown type(%dd)",
294 __func__, type);
295 goto end;
296 }
297
298 /* Set interrupt mode */
299 im = ioread32(im_reg) & ~(IOH_IM_MASK << (im_pos * 4));
300 iowrite32(im | (val << (im_pos * 4)), im_reg);
301
302 /* iclr */
303 iowrite32(BIT(ch), &chip->reg->regs[chip->ch].iclr);
304
305 /* IMASKCLR */
306 iowrite32(BIT(ch), &chip->reg->regs[chip->ch].imaskclr);
307
308 /* Enable interrupt */
309 ien = ioread32(&chip->reg->regs[chip->ch].ien);
310 iowrite32(ien | BIT(ch), &chip->reg->regs[chip->ch].ien);
311end:
312 spin_unlock_irqrestore(&chip->spinlock, flags);
313
314 return 0;
315}
316
317static void ioh_irq_unmask(struct irq_data *d)
318{
319 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
320 struct ioh_gpio *chip = gc->private;
321
322 iowrite32(1 << (d->irq - chip->irq_base),
323 &chip->reg->regs[chip->ch].imaskclr);
324}
325
326static void ioh_irq_mask(struct irq_data *d)
327{
328 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
329 struct ioh_gpio *chip = gc->private;
330
331 iowrite32(1 << (d->irq - chip->irq_base),
332 &chip->reg->regs[chip->ch].imask);
333}
334
Feng Tang4d052212011-12-13 23:53:50 +0800335static void ioh_irq_disable(struct irq_data *d)
336{
337 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
338 struct ioh_gpio *chip = gc->private;
339 unsigned long flags;
340 u32 ien;
341
342 spin_lock_irqsave(&chip->spinlock, flags);
343 ien = ioread32(&chip->reg->regs[chip->ch].ien);
344 ien &= ~(1 << (d->irq - chip->irq_base));
345 iowrite32(ien, &chip->reg->regs[chip->ch].ien);
346 spin_unlock_irqrestore(&chip->spinlock, flags);
347}
348
349static void ioh_irq_enable(struct irq_data *d)
350{
351 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
352 struct ioh_gpio *chip = gc->private;
353 unsigned long flags;
354 u32 ien;
355
356 spin_lock_irqsave(&chip->spinlock, flags);
357 ien = ioread32(&chip->reg->regs[chip->ch].ien);
358 ien |= 1 << (d->irq - chip->irq_base);
359 iowrite32(ien, &chip->reg->regs[chip->ch].ien);
360 spin_unlock_irqrestore(&chip->spinlock, flags);
361}
362
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900363static irqreturn_t ioh_gpio_handler(int irq, void *dev_id)
364{
365 struct ioh_gpio *chip = dev_id;
366 u32 reg_val;
367 int i, j;
368 int ret = IRQ_NONE;
369
Feng Tangf9ea14e2011-12-13 23:53:49 +0800370 for (i = 0; i < 8; i++, chip++) {
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900371 reg_val = ioread32(&chip->reg->regs[i].istatus);
372 for (j = 0; j < num_ports[i]; j++) {
373 if (reg_val & BIT(j)) {
374 dev_dbg(chip->dev,
375 "%s:[%d]:irq=%d status=0x%x\n",
376 __func__, j, irq, reg_val);
377 iowrite32(BIT(j),
378 &chip->reg->regs[chip->ch].iclr);
379 generic_handle_irq(chip->irq_base + j);
380 ret = IRQ_HANDLED;
381 }
382 }
383 }
384 return ret;
385}
386
387static __devinit void ioh_gpio_alloc_generic_chip(struct ioh_gpio *chip,
388 unsigned int irq_start, unsigned int num)
389{
390 struct irq_chip_generic *gc;
391 struct irq_chip_type *ct;
392
393 gc = irq_alloc_generic_chip("ioh_gpio", 1, irq_start, chip->base,
394 handle_simple_irq);
395 gc->private = chip;
396 ct = gc->chip_types;
397
398 ct->chip.irq_mask = ioh_irq_mask;
399 ct->chip.irq_unmask = ioh_irq_unmask;
400 ct->chip.irq_set_type = ioh_irq_type;
Feng Tang4d052212011-12-13 23:53:50 +0800401 ct->chip.irq_disable = ioh_irq_disable;
402 ct->chip.irq_enable = ioh_irq_enable;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900403
404 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
405 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800406}
407
408static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
409 const struct pci_device_id *id)
410{
411 int ret;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900412 int i, j;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800413 struct ioh_gpio *chip;
414 void __iomem *base;
Márton Némethdd9328a2012-01-15 10:57:34 +0100415 void *chip_save;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900416 int irq_base;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800417
418 ret = pci_enable_device(pdev);
419 if (ret) {
420 dev_err(&pdev->dev, "%s : pci_enable_device failed", __func__);
421 goto err_pci_enable;
422 }
423
424 ret = pci_request_regions(pdev, KBUILD_MODNAME);
425 if (ret) {
426 dev_err(&pdev->dev, "pci_request_regions failed-%d", ret);
427 goto err_request_regions;
428 }
429
430 base = pci_iomap(pdev, 1, 0);
Márton Németh2bd1c852012-01-15 10:57:43 +0100431 if (!base) {
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800432 dev_err(&pdev->dev, "%s : pci_iomap failed", __func__);
433 ret = -ENOMEM;
434 goto err_iomap;
435 }
436
437 chip_save = kzalloc(sizeof(*chip) * 8, GFP_KERNEL);
438 if (chip_save == NULL) {
439 dev_err(&pdev->dev, "%s : kzalloc failed", __func__);
440 ret = -ENOMEM;
441 goto err_kzalloc;
442 }
443
444 chip = chip_save;
445 for (i = 0; i < 8; i++, chip++) {
446 chip->dev = &pdev->dev;
447 chip->base = base;
448 chip->reg = chip->base;
449 chip->ch = i;
450 mutex_init(&chip->lock);
451 ioh_gpio_setup(chip, num_ports[i]);
452 ret = gpiochip_add(&chip->gpio);
453 if (ret) {
454 dev_err(&pdev->dev, "IOH gpio: Failed to register GPIO\n");
455 goto err_gpiochip_add;
456 }
457 }
458
459 chip = chip_save;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900460 for (j = 0; j < 8; j++, chip++) {
461 irq_base = irq_alloc_descs(-1, IOH_IRQ_BASE, num_ports[j],
Tomoya MORINAGAa7aaa4f2011-10-19 10:37:40 +0900462 NUMA_NO_NODE);
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900463 if (irq_base < 0) {
464 dev_warn(&pdev->dev,
465 "ml_ioh_gpio: Failed to get IRQ base num\n");
466 chip->irq_base = -1;
467 goto err_irq_alloc_descs;
468 }
469 chip->irq_base = irq_base;
470 ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]);
471 }
472
473 chip = chip_save;
474 ret = request_irq(pdev->irq, ioh_gpio_handler,
475 IRQF_SHARED, KBUILD_MODNAME, chip);
476 if (ret != 0) {
477 dev_err(&pdev->dev,
478 "%s request_irq failed\n", __func__);
479 goto err_request_irq;
480 }
481
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800482 pci_set_drvdata(pdev, chip);
483
484 return 0;
485
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900486err_request_irq:
487 chip = chip_save;
488err_irq_alloc_descs:
489 while (--j >= 0) {
490 chip--;
491 irq_free_descs(chip->irq_base, num_ports[j]);
492 }
493
494 chip = chip_save;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800495err_gpiochip_add:
Axel Lin33300572011-06-14 19:12:57 +0800496 while (--i >= 0) {
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800497 chip--;
498 ret = gpiochip_remove(&chip->gpio);
499 if (ret)
500 dev_err(&pdev->dev, "Failed gpiochip_remove(%d)\n", i);
501 }
502 kfree(chip_save);
503
504err_kzalloc:
505 pci_iounmap(pdev, base);
506
507err_iomap:
508 pci_release_regions(pdev);
509
510err_request_regions:
511 pci_disable_device(pdev);
512
513err_pci_enable:
514
515 dev_err(&pdev->dev, "%s Failed returns %d\n", __func__, ret);
516 return ret;
517}
518
519static void __devexit ioh_gpio_remove(struct pci_dev *pdev)
520{
521 int err;
522 int i;
523 struct ioh_gpio *chip = pci_get_drvdata(pdev);
Márton Némethdd9328a2012-01-15 10:57:34 +0100524 void *chip_save;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800525
526 chip_save = chip;
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900527
528 free_irq(pdev->irq, chip);
529
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800530 for (i = 0; i < 8; i++, chip++) {
Tomoya MORINAGA54be5662011-08-05 13:04:21 +0900531 irq_free_descs(chip->irq_base, num_ports[i]);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800532 err = gpiochip_remove(&chip->gpio);
533 if (err)
534 dev_err(&pdev->dev, "Failed gpiochip_remove\n");
535 }
536
537 chip = chip_save;
538 pci_iounmap(pdev, chip->base);
539 pci_release_regions(pdev);
540 pci_disable_device(pdev);
541 kfree(chip);
542}
543
544#ifdef CONFIG_PM
545static int ioh_gpio_suspend(struct pci_dev *pdev, pm_message_t state)
546{
547 s32 ret;
548 struct ioh_gpio *chip = pci_get_drvdata(pdev);
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900549 unsigned long flags;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800550
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900551 spin_lock_irqsave(&chip->spinlock, flags);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800552 ioh_gpio_save_reg_conf(chip);
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900553 spin_unlock_irqrestore(&chip->spinlock, flags);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800554
555 ret = pci_save_state(pdev);
556 if (ret) {
557 dev_err(&pdev->dev, "pci_save_state Failed-%d\n", ret);
558 return ret;
559 }
560 pci_disable_device(pdev);
561 pci_set_power_state(pdev, PCI_D0);
562 ret = pci_enable_wake(pdev, PCI_D0, 1);
563 if (ret)
564 dev_err(&pdev->dev, "pci_enable_wake Failed -%d\n", ret);
565
566 return 0;
567}
568
569static int ioh_gpio_resume(struct pci_dev *pdev)
570{
571 s32 ret;
572 struct ioh_gpio *chip = pci_get_drvdata(pdev);
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900573 unsigned long flags;
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800574
575 ret = pci_enable_wake(pdev, PCI_D0, 0);
576
577 pci_set_power_state(pdev, PCI_D0);
578 ret = pci_enable_device(pdev);
579 if (ret) {
580 dev_err(&pdev->dev, "pci_enable_device Failed-%d ", ret);
581 return ret;
582 }
583 pci_restore_state(pdev);
584
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900585 spin_lock_irqsave(&chip->spinlock, flags);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800586 iowrite32(0x01, &chip->reg->srst);
587 iowrite32(0x00, &chip->reg->srst);
588 ioh_gpio_restore_reg_conf(chip);
Tomoya MORINAGAb490fa02011-08-05 13:04:22 +0900589 spin_unlock_irqrestore(&chip->spinlock, flags);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800590
591 return 0;
592}
593#else
594#define ioh_gpio_suspend NULL
595#define ioh_gpio_resume NULL
596#endif
597
598static DEFINE_PCI_DEVICE_TABLE(ioh_gpio_pcidev_id) = {
599 { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x802E) },
600 { 0, }
601};
Axel Lin19234cd2011-03-11 14:58:30 -0800602MODULE_DEVICE_TABLE(pci, ioh_gpio_pcidev_id);
Tomoya MORINAGA49a36792011-01-12 17:00:22 -0800603
604static struct pci_driver ioh_gpio_driver = {
605 .name = "ml_ioh_gpio",
606 .id_table = ioh_gpio_pcidev_id,
607 .probe = ioh_gpio_probe,
608 .remove = __devexit_p(ioh_gpio_remove),
609 .suspend = ioh_gpio_suspend,
610 .resume = ioh_gpio_resume
611};
612
613static int __init ioh_gpio_pci_init(void)
614{
615 return pci_register_driver(&ioh_gpio_driver);
616}
617module_init(ioh_gpio_pci_init);
618
619static void __exit ioh_gpio_pci_exit(void)
620{
621 pci_unregister_driver(&ioh_gpio_driver);
622}
623module_exit(ioh_gpio_pci_exit);
624
625MODULE_DESCRIPTION("OKI SEMICONDUCTOR ML-IOH series GPIO Driver");
626MODULE_LICENSE("GPL");