diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-01-09 02:38:23 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-01-09 02:38:23 -0500 |
commit | da733563be5a9da26fe81d9f007262d00b846e22 (patch) | |
tree | db28291df94a2043af2123911984c5c173da4e6f /drivers/gpio/gpio-ml-ioh.c | |
parent | 6ccbcf2cb41131f8d56ef0723bf3f7c1f8486076 (diff) | |
parent | dab78d7924598ea4031663dd10db814e2e324928 (diff) |
Merge branch 'next' into for-linus
Diffstat (limited to 'drivers/gpio/gpio-ml-ioh.c')
-rw-r--r-- | drivers/gpio/gpio-ml-ioh.c | 255 |
1 files changed, 247 insertions, 8 deletions
diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index a9016f56ed7e..ea8e73869250 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c | |||
@@ -14,10 +14,22 @@ | |||
14 | * along with this program; if not, write to the Free Software | 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. | 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
16 | */ | 16 | */ |
17 | #include <linux/module.h> | ||
17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
18 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
19 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
20 | #include <linux/gpio.h> | 21 | #include <linux/gpio.h> |
22 | #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 | ||
21 | 33 | ||
22 | #define PCI_VENDOR_ID_ROHM 0x10DB | 34 | #define PCI_VENDOR_ID_ROHM 0x10DB |
23 | 35 | ||
@@ -46,12 +58,22 @@ struct ioh_regs { | |||
46 | 58 | ||
47 | /** | 59 | /** |
48 | * struct ioh_gpio_reg_data - The register store data. | 60 | * struct ioh_gpio_reg_data - The register store data. |
61 | * @ien_reg To store contents of interrupt enable register. | ||
62 | * @imask_reg: To store contents of interrupt mask regist | ||
49 | * @po_reg: To store contents of PO register. | 63 | * @po_reg: To store contents of PO register. |
50 | * @pm_reg: To store contents of PM register. | 64 | * @pm_reg: To store contents of PM register. |
65 | * @im0_reg: To store contents of interrupt mode regist0 | ||
66 | * @im1_reg: To store contents of interrupt mode regist1 | ||
67 | * @use_sel_reg: To store contents of GPIO_USE_SEL0~3 | ||
51 | */ | 68 | */ |
52 | struct ioh_gpio_reg_data { | 69 | struct ioh_gpio_reg_data { |
70 | u32 ien_reg; | ||
71 | u32 imask_reg; | ||
53 | u32 po_reg; | 72 | u32 po_reg; |
54 | u32 pm_reg; | 73 | u32 pm_reg; |
74 | u32 im0_reg; | ||
75 | u32 im1_reg; | ||
76 | u32 use_sel_reg; | ||
55 | }; | 77 | }; |
56 | 78 | ||
57 | /** | 79 | /** |
@@ -62,7 +84,11 @@ struct ioh_gpio_reg_data { | |||
62 | * @gpio: Data for GPIO infrastructure. | 84 | * @gpio: Data for GPIO infrastructure. |
63 | * @ioh_gpio_reg: Memory mapped Register data is saved here | 85 | * @ioh_gpio_reg: Memory mapped Register data is saved here |
64 | * when suspend. | 86 | * when suspend. |
87 | * @gpio_use_sel: Save GPIO_USE_SEL1~4 register for PM | ||
65 | * @ch: Indicate GPIO channel | 88 | * @ch: Indicate GPIO channel |
89 | * @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; | ||
66 | */ | 92 | */ |
67 | struct ioh_gpio { | 93 | struct ioh_gpio { |
68 | void __iomem *base; | 94 | void __iomem *base; |
@@ -70,8 +96,11 @@ struct ioh_gpio { | |||
70 | struct device *dev; | 96 | struct device *dev; |
71 | struct gpio_chip gpio; | 97 | struct gpio_chip gpio; |
72 | struct ioh_gpio_reg_data ioh_gpio_reg; | 98 | struct ioh_gpio_reg_data ioh_gpio_reg; |
99 | u32 gpio_use_sel; | ||
73 | struct mutex lock; | 100 | struct mutex lock; |
74 | int ch; | 101 | int ch; |
102 | int irq_base; | ||
103 | spinlock_t spinlock; | ||
75 | }; | 104 | }; |
76 | 105 | ||
77 | static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12}; | 106 | static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12}; |
@@ -145,8 +174,25 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
145 | */ | 174 | */ |
146 | static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) | 175 | static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) |
147 | { | 176 | { |
148 | chip->ioh_gpio_reg.po_reg = ioread32(&chip->reg->regs[chip->ch].po); | 177 | int i; |
149 | chip->ioh_gpio_reg.pm_reg = ioread32(&chip->reg->regs[chip->ch].pm); | 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 | } | ||
150 | } | 196 | } |
151 | 197 | ||
152 | /* | 198 | /* |
@@ -154,13 +200,34 @@ static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) | |||
154 | */ | 200 | */ |
155 | static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) | 201 | static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) |
156 | { | 202 | { |
157 | /* to store contents of PO register */ | 203 | int i; |
158 | iowrite32(chip->ioh_gpio_reg.po_reg, &chip->reg->regs[chip->ch].po); | 204 | |
159 | /* to store contents of PM register */ | 205 | for (i = 0; i < 8; i ++, chip++) { |
160 | iowrite32(chip->ioh_gpio_reg.pm_reg, &chip->reg->regs[chip->ch].pm); | 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 | } | ||
161 | } | 222 | } |
162 | #endif | 223 | #endif |
163 | 224 | ||
225 | static 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 | |||
164 | static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port) | 231 | static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port) |
165 | { | 232 | { |
166 | struct gpio_chip *gpio = &chip->gpio; | 233 | struct gpio_chip *gpio = &chip->gpio; |
@@ -175,16 +242,148 @@ static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port) | |||
175 | gpio->base = -1; | 242 | gpio->base = -1; |
176 | gpio->ngpio = num_port; | 243 | gpio->ngpio = num_port; |
177 | gpio->can_sleep = 0; | 244 | gpio->can_sleep = 0; |
245 | gpio->to_irq = ioh_gpio_to_irq; | ||
246 | } | ||
247 | |||
248 | static int ioh_irq_type(struct irq_data *d, unsigned int type) | ||
249 | { | ||
250 | u32 im; | ||
251 | u32 *im_reg; | ||
252 | 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); | ||
311 | end: | ||
312 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
313 | |||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static 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 | |||
326 | static 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 | |||
335 | static irqreturn_t ioh_gpio_handler(int irq, void *dev_id) | ||
336 | { | ||
337 | struct ioh_gpio *chip = dev_id; | ||
338 | u32 reg_val; | ||
339 | int i, j; | ||
340 | int ret = IRQ_NONE; | ||
341 | |||
342 | for (i = 0; i < 8; i++) { | ||
343 | reg_val = ioread32(&chip->reg->regs[i].istatus); | ||
344 | for (j = 0; j < num_ports[i]; j++) { | ||
345 | if (reg_val & BIT(j)) { | ||
346 | dev_dbg(chip->dev, | ||
347 | "%s:[%d]:irq=%d status=0x%x\n", | ||
348 | __func__, j, irq, reg_val); | ||
349 | iowrite32(BIT(j), | ||
350 | &chip->reg->regs[chip->ch].iclr); | ||
351 | generic_handle_irq(chip->irq_base + j); | ||
352 | ret = IRQ_HANDLED; | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | return ret; | ||
357 | } | ||
358 | |||
359 | static __devinit void ioh_gpio_alloc_generic_chip(struct ioh_gpio *chip, | ||
360 | unsigned int irq_start, unsigned int num) | ||
361 | { | ||
362 | struct irq_chip_generic *gc; | ||
363 | struct irq_chip_type *ct; | ||
364 | |||
365 | gc = irq_alloc_generic_chip("ioh_gpio", 1, irq_start, chip->base, | ||
366 | handle_simple_irq); | ||
367 | gc->private = chip; | ||
368 | ct = gc->chip_types; | ||
369 | |||
370 | ct->chip.irq_mask = ioh_irq_mask; | ||
371 | ct->chip.irq_unmask = ioh_irq_unmask; | ||
372 | ct->chip.irq_set_type = ioh_irq_type; | ||
373 | |||
374 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, | ||
375 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); | ||
178 | } | 376 | } |
179 | 377 | ||
180 | static int __devinit ioh_gpio_probe(struct pci_dev *pdev, | 378 | static int __devinit ioh_gpio_probe(struct pci_dev *pdev, |
181 | const struct pci_device_id *id) | 379 | const struct pci_device_id *id) |
182 | { | 380 | { |
183 | int ret; | 381 | int ret; |
184 | int i; | 382 | int i, j; |
185 | struct ioh_gpio *chip; | 383 | struct ioh_gpio *chip; |
186 | void __iomem *base; | 384 | void __iomem *base; |
187 | void __iomem *chip_save; | 385 | void __iomem *chip_save; |
386 | int irq_base; | ||
188 | 387 | ||
189 | ret = pci_enable_device(pdev); | 388 | ret = pci_enable_device(pdev); |
190 | if (ret) { | 389 | if (ret) { |
@@ -228,10 +427,41 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev, | |||
228 | } | 427 | } |
229 | 428 | ||
230 | chip = chip_save; | 429 | chip = chip_save; |
430 | for (j = 0; j < 8; j++, chip++) { | ||
431 | irq_base = irq_alloc_descs(-1, IOH_IRQ_BASE, num_ports[j], | ||
432 | NUMA_NO_NODE); | ||
433 | if (irq_base < 0) { | ||
434 | dev_warn(&pdev->dev, | ||
435 | "ml_ioh_gpio: Failed to get IRQ base num\n"); | ||
436 | chip->irq_base = -1; | ||
437 | goto err_irq_alloc_descs; | ||
438 | } | ||
439 | chip->irq_base = irq_base; | ||
440 | ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]); | ||
441 | } | ||
442 | |||
443 | chip = chip_save; | ||
444 | ret = request_irq(pdev->irq, ioh_gpio_handler, | ||
445 | IRQF_SHARED, KBUILD_MODNAME, chip); | ||
446 | if (ret != 0) { | ||
447 | dev_err(&pdev->dev, | ||
448 | "%s request_irq failed\n", __func__); | ||
449 | goto err_request_irq; | ||
450 | } | ||
451 | |||
231 | pci_set_drvdata(pdev, chip); | 452 | pci_set_drvdata(pdev, chip); |
232 | 453 | ||
233 | return 0; | 454 | return 0; |
234 | 455 | ||
456 | err_request_irq: | ||
457 | chip = chip_save; | ||
458 | err_irq_alloc_descs: | ||
459 | while (--j >= 0) { | ||
460 | chip--; | ||
461 | irq_free_descs(chip->irq_base, num_ports[j]); | ||
462 | } | ||
463 | |||
464 | chip = chip_save; | ||
235 | err_gpiochip_add: | 465 | err_gpiochip_add: |
236 | while (--i >= 0) { | 466 | while (--i >= 0) { |
237 | chip--; | 467 | chip--; |
@@ -264,7 +494,11 @@ static void __devexit ioh_gpio_remove(struct pci_dev *pdev) | |||
264 | void __iomem *chip_save; | 494 | void __iomem *chip_save; |
265 | 495 | ||
266 | chip_save = chip; | 496 | chip_save = chip; |
497 | |||
498 | free_irq(pdev->irq, chip); | ||
499 | |||
267 | for (i = 0; i < 8; i++, chip++) { | 500 | for (i = 0; i < 8; i++, chip++) { |
501 | irq_free_descs(chip->irq_base, num_ports[i]); | ||
268 | err = gpiochip_remove(&chip->gpio); | 502 | err = gpiochip_remove(&chip->gpio); |
269 | if (err) | 503 | if (err) |
270 | dev_err(&pdev->dev, "Failed gpiochip_remove\n"); | 504 | dev_err(&pdev->dev, "Failed gpiochip_remove\n"); |
@@ -282,9 +516,11 @@ static int ioh_gpio_suspend(struct pci_dev *pdev, pm_message_t state) | |||
282 | { | 516 | { |
283 | s32 ret; | 517 | s32 ret; |
284 | struct ioh_gpio *chip = pci_get_drvdata(pdev); | 518 | struct ioh_gpio *chip = pci_get_drvdata(pdev); |
519 | unsigned long flags; | ||
285 | 520 | ||
521 | spin_lock_irqsave(&chip->spinlock, flags); | ||
286 | ioh_gpio_save_reg_conf(chip); | 522 | ioh_gpio_save_reg_conf(chip); |
287 | ioh_gpio_restore_reg_conf(chip); | 523 | spin_unlock_irqrestore(&chip->spinlock, flags); |
288 | 524 | ||
289 | ret = pci_save_state(pdev); | 525 | ret = pci_save_state(pdev); |
290 | if (ret) { | 526 | if (ret) { |
@@ -304,6 +540,7 @@ static int ioh_gpio_resume(struct pci_dev *pdev) | |||
304 | { | 540 | { |
305 | s32 ret; | 541 | s32 ret; |
306 | struct ioh_gpio *chip = pci_get_drvdata(pdev); | 542 | struct ioh_gpio *chip = pci_get_drvdata(pdev); |
543 | unsigned long flags; | ||
307 | 544 | ||
308 | ret = pci_enable_wake(pdev, PCI_D0, 0); | 545 | ret = pci_enable_wake(pdev, PCI_D0, 0); |
309 | 546 | ||
@@ -315,9 +552,11 @@ static int ioh_gpio_resume(struct pci_dev *pdev) | |||
315 | } | 552 | } |
316 | pci_restore_state(pdev); | 553 | pci_restore_state(pdev); |
317 | 554 | ||
555 | spin_lock_irqsave(&chip->spinlock, flags); | ||
318 | iowrite32(0x01, &chip->reg->srst); | 556 | iowrite32(0x01, &chip->reg->srst); |
319 | iowrite32(0x00, &chip->reg->srst); | 557 | iowrite32(0x00, &chip->reg->srst); |
320 | ioh_gpio_restore_reg_conf(chip); | 558 | ioh_gpio_restore_reg_conf(chip); |
559 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
321 | 560 | ||
322 | return 0; | 561 | return 0; |
323 | } | 562 | } |