x86, ioapic: Print IR_IO_APIC_route_entry when IR is enabled
[pandora-kernel.git] / drivers / gpio / pca953x.c
1 /*
2  *  pca953x.c - 4/8/16 bit I/O ports
3  *
4  *  Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
5  *  Copyright (C) 2007 Marvell International Ltd.
6  *
7  *  Derived from drivers/i2c/chips/pca9539.c
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; version 2 of the License.
12  */
13
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/gpio.h>
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
19 #include <linux/i2c.h>
20 #include <linux/i2c/pca953x.h>
21 #include <linux/slab.h>
22 #ifdef CONFIG_OF_GPIO
23 #include <linux/of_platform.h>
24 #include <linux/of_gpio.h>
25 #endif
26
27 #define PCA953X_INPUT           0
28 #define PCA953X_OUTPUT          1
29 #define PCA953X_INVERT          2
30 #define PCA953X_DIRECTION       3
31
32 #define PCA957X_IN              0
33 #define PCA957X_INVRT           1
34 #define PCA957X_BKEN            2
35 #define PCA957X_PUPD            3
36 #define PCA957X_CFG             4
37 #define PCA957X_OUT             5
38 #define PCA957X_MSK             6
39 #define PCA957X_INTS            7
40
41 #define PCA_GPIO_MASK           0x00FF
42 #define PCA_INT                 0x0100
43 #define PCA953X_TYPE            0x1000
44 #define PCA957X_TYPE            0x2000
45
46 static const struct i2c_device_id pca953x_id[] = {
47         { "pca9534", 8  | PCA953X_TYPE | PCA_INT, },
48         { "pca9535", 16 | PCA953X_TYPE | PCA_INT, },
49         { "pca9536", 4  | PCA953X_TYPE, },
50         { "pca9537", 4  | PCA953X_TYPE | PCA_INT, },
51         { "pca9538", 8  | PCA953X_TYPE | PCA_INT, },
52         { "pca9539", 16 | PCA953X_TYPE | PCA_INT, },
53         { "pca9554", 8  | PCA953X_TYPE | PCA_INT, },
54         { "pca9555", 16 | PCA953X_TYPE | PCA_INT, },
55         { "pca9556", 8  | PCA953X_TYPE, },
56         { "pca9557", 8  | PCA953X_TYPE, },
57         { "pca9574", 8  | PCA957X_TYPE | PCA_INT, },
58         { "pca9575", 16 | PCA957X_TYPE | PCA_INT, },
59
60         { "max7310", 8  | PCA953X_TYPE, },
61         { "max7312", 16 | PCA953X_TYPE | PCA_INT, },
62         { "max7313", 16 | PCA953X_TYPE | PCA_INT, },
63         { "max7315", 8  | PCA953X_TYPE | PCA_INT, },
64         { "pca6107", 8  | PCA953X_TYPE | PCA_INT, },
65         { "tca6408", 8  | PCA953X_TYPE | PCA_INT, },
66         { "tca6416", 16 | PCA953X_TYPE | PCA_INT, },
67         /* NYET:  { "tca6424", 24, }, */
68         { }
69 };
70 MODULE_DEVICE_TABLE(i2c, pca953x_id);
71
72 struct pca953x_chip {
73         unsigned gpio_start;
74         uint16_t reg_output;
75         uint16_t reg_direction;
76         struct mutex i2c_lock;
77
78 #ifdef CONFIG_GPIO_PCA953X_IRQ
79         struct mutex irq_lock;
80         uint16_t irq_mask;
81         uint16_t irq_stat;
82         uint16_t irq_trig_raise;
83         uint16_t irq_trig_fall;
84         int      irq_base;
85 #endif
86
87         struct i2c_client *client;
88         struct pca953x_platform_data *dyn_pdata;
89         struct gpio_chip gpio_chip;
90         const char *const *names;
91         int     chip_type;
92 };
93
94 static int pca953x_write_reg(struct pca953x_chip *chip, int reg, uint16_t val)
95 {
96         int ret = 0;
97
98         if (chip->gpio_chip.ngpio <= 8)
99                 ret = i2c_smbus_write_byte_data(chip->client, reg, val);
100         else {
101                 switch (chip->chip_type) {
102                 case PCA953X_TYPE:
103                         ret = i2c_smbus_write_word_data(chip->client,
104                                                         reg << 1, val);
105                         break;
106                 case PCA957X_TYPE:
107                         ret = i2c_smbus_write_byte_data(chip->client, reg << 1,
108                                                         val & 0xff);
109                         if (ret < 0)
110                                 break;
111                         ret = i2c_smbus_write_byte_data(chip->client,
112                                                         (reg << 1) + 1,
113                                                         (val & 0xff00) >> 8);
114                         break;
115                 }
116         }
117
118         if (ret < 0) {
119                 dev_err(&chip->client->dev, "failed writing register\n");
120                 return ret;
121         }
122
123         return 0;
124 }
125
126 static int pca953x_read_reg(struct pca953x_chip *chip, int reg, uint16_t *val)
127 {
128         int ret;
129
130         if (chip->gpio_chip.ngpio <= 8)
131                 ret = i2c_smbus_read_byte_data(chip->client, reg);
132         else
133                 ret = i2c_smbus_read_word_data(chip->client, reg << 1);
134
135         if (ret < 0) {
136                 dev_err(&chip->client->dev, "failed reading register\n");
137                 return ret;
138         }
139
140         *val = (uint16_t)ret;
141         return 0;
142 }
143
144 static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
145 {
146         struct pca953x_chip *chip;
147         uint16_t reg_val;
148         int ret, offset = 0;
149
150         chip = container_of(gc, struct pca953x_chip, gpio_chip);
151
152         mutex_lock(&chip->i2c_lock);
153         reg_val = chip->reg_direction | (1u << off);
154
155         switch (chip->chip_type) {
156         case PCA953X_TYPE:
157                 offset = PCA953X_DIRECTION;
158                 break;
159         case PCA957X_TYPE:
160                 offset = PCA957X_CFG;
161                 break;
162         }
163         ret = pca953x_write_reg(chip, offset, reg_val);
164         if (ret)
165                 goto exit;
166
167         chip->reg_direction = reg_val;
168         ret = 0;
169 exit:
170         mutex_unlock(&chip->i2c_lock);
171         return ret;
172 }
173
174 static int pca953x_gpio_direction_output(struct gpio_chip *gc,
175                 unsigned off, int val)
176 {
177         struct pca953x_chip *chip;
178         uint16_t reg_val;
179         int ret, offset = 0;
180
181         chip = container_of(gc, struct pca953x_chip, gpio_chip);
182
183         mutex_lock(&chip->i2c_lock);
184         /* set output level */
185         if (val)
186                 reg_val = chip->reg_output | (1u << off);
187         else
188                 reg_val = chip->reg_output & ~(1u << off);
189
190         switch (chip->chip_type) {
191         case PCA953X_TYPE:
192                 offset = PCA953X_OUTPUT;
193                 break;
194         case PCA957X_TYPE:
195                 offset = PCA957X_OUT;
196                 break;
197         }
198         ret = pca953x_write_reg(chip, offset, reg_val);
199         if (ret)
200                 goto exit;
201
202         chip->reg_output = reg_val;
203
204         /* then direction */
205         reg_val = chip->reg_direction & ~(1u << off);
206         switch (chip->chip_type) {
207         case PCA953X_TYPE:
208                 offset = PCA953X_DIRECTION;
209                 break;
210         case PCA957X_TYPE:
211                 offset = PCA957X_CFG;
212                 break;
213         }
214         ret = pca953x_write_reg(chip, offset, reg_val);
215         if (ret)
216                 goto exit;
217
218         chip->reg_direction = reg_val;
219         ret = 0;
220 exit:
221         mutex_unlock(&chip->i2c_lock);
222         return ret;
223 }
224
225 static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
226 {
227         struct pca953x_chip *chip;
228         uint16_t reg_val;
229         int ret, offset = 0;
230
231         chip = container_of(gc, struct pca953x_chip, gpio_chip);
232
233         mutex_lock(&chip->i2c_lock);
234         switch (chip->chip_type) {
235         case PCA953X_TYPE:
236                 offset = PCA953X_INPUT;
237                 break;
238         case PCA957X_TYPE:
239                 offset = PCA957X_IN;
240                 break;
241         }
242         ret = pca953x_read_reg(chip, offset, &reg_val);
243         mutex_unlock(&chip->i2c_lock);
244         if (ret < 0) {
245                 /* NOTE:  diagnostic already emitted; that's all we should
246                  * do unless gpio_*_value_cansleep() calls become different
247                  * from their nonsleeping siblings (and report faults).
248                  */
249                 return 0;
250         }
251
252         return (reg_val & (1u << off)) ? 1 : 0;
253 }
254
255 static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
256 {
257         struct pca953x_chip *chip;
258         uint16_t reg_val;
259         int ret, offset = 0;
260
261         chip = container_of(gc, struct pca953x_chip, gpio_chip);
262
263         mutex_lock(&chip->i2c_lock);
264         if (val)
265                 reg_val = chip->reg_output | (1u << off);
266         else
267                 reg_val = chip->reg_output & ~(1u << off);
268
269         switch (chip->chip_type) {
270         case PCA953X_TYPE:
271                 offset = PCA953X_OUTPUT;
272                 break;
273         case PCA957X_TYPE:
274                 offset = PCA957X_OUT;
275                 break;
276         }
277         ret = pca953x_write_reg(chip, offset, reg_val);
278         if (ret)
279                 goto exit;
280
281         chip->reg_output = reg_val;
282 exit:
283         mutex_unlock(&chip->i2c_lock);
284 }
285
286 static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
287 {
288         struct gpio_chip *gc;
289
290         gc = &chip->gpio_chip;
291
292         gc->direction_input  = pca953x_gpio_direction_input;
293         gc->direction_output = pca953x_gpio_direction_output;
294         gc->get = pca953x_gpio_get_value;
295         gc->set = pca953x_gpio_set_value;
296         gc->can_sleep = 1;
297
298         gc->base = chip->gpio_start;
299         gc->ngpio = gpios;
300         gc->label = chip->client->name;
301         gc->dev = &chip->client->dev;
302         gc->owner = THIS_MODULE;
303         gc->names = chip->names;
304 }
305
306 #ifdef CONFIG_GPIO_PCA953X_IRQ
307 static int pca953x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
308 {
309         struct pca953x_chip *chip;
310
311         chip = container_of(gc, struct pca953x_chip, gpio_chip);
312         return chip->irq_base + off;
313 }
314
315 static void pca953x_irq_mask(struct irq_data *d)
316 {
317         struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
318
319         chip->irq_mask &= ~(1 << (d->irq - chip->irq_base));
320 }
321
322 static void pca953x_irq_unmask(struct irq_data *d)
323 {
324         struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
325
326         chip->irq_mask |= 1 << (d->irq - chip->irq_base);
327 }
328
329 static void pca953x_irq_bus_lock(struct irq_data *d)
330 {
331         struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
332
333         mutex_lock(&chip->irq_lock);
334 }
335
336 static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
337 {
338         struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
339         uint16_t new_irqs;
340         uint16_t level;
341
342         /* Look for any newly setup interrupt */
343         new_irqs = chip->irq_trig_fall | chip->irq_trig_raise;
344         new_irqs &= ~chip->reg_direction;
345
346         while (new_irqs) {
347                 level = __ffs(new_irqs);
348                 pca953x_gpio_direction_input(&chip->gpio_chip, level);
349                 new_irqs &= ~(1 << level);
350         }
351
352         mutex_unlock(&chip->irq_lock);
353 }
354
355 static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
356 {
357         struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
358         uint16_t level = d->irq - chip->irq_base;
359         uint16_t mask = 1 << level;
360
361         if (!(type & IRQ_TYPE_EDGE_BOTH)) {
362                 dev_err(&chip->client->dev, "irq %d: unsupported type %d\n",
363                         d->irq, type);
364                 return -EINVAL;
365         }
366
367         if (type & IRQ_TYPE_EDGE_FALLING)
368                 chip->irq_trig_fall |= mask;
369         else
370                 chip->irq_trig_fall &= ~mask;
371
372         if (type & IRQ_TYPE_EDGE_RISING)
373                 chip->irq_trig_raise |= mask;
374         else
375                 chip->irq_trig_raise &= ~mask;
376
377         return 0;
378 }
379
380 static struct irq_chip pca953x_irq_chip = {
381         .name                   = "pca953x",
382         .irq_mask               = pca953x_irq_mask,
383         .irq_unmask             = pca953x_irq_unmask,
384         .irq_bus_lock           = pca953x_irq_bus_lock,
385         .irq_bus_sync_unlock    = pca953x_irq_bus_sync_unlock,
386         .irq_set_type           = pca953x_irq_set_type,
387 };
388
389 static uint16_t pca953x_irq_pending(struct pca953x_chip *chip)
390 {
391         uint16_t cur_stat;
392         uint16_t old_stat;
393         uint16_t pending;
394         uint16_t trigger;
395         int ret, offset = 0;
396
397         switch (chip->chip_type) {
398         case PCA953X_TYPE:
399                 offset = PCA953X_INPUT;
400                 break;
401         case PCA957X_TYPE:
402                 offset = PCA957X_IN;
403                 break;
404         }
405         ret = pca953x_read_reg(chip, offset, &cur_stat);
406         if (ret)
407                 return 0;
408
409         /* Remove output pins from the equation */
410         cur_stat &= chip->reg_direction;
411
412         old_stat = chip->irq_stat;
413         trigger = (cur_stat ^ old_stat) & chip->irq_mask;
414
415         if (!trigger)
416                 return 0;
417
418         chip->irq_stat = cur_stat;
419
420         pending = (old_stat & chip->irq_trig_fall) |
421                   (cur_stat & chip->irq_trig_raise);
422         pending &= trigger;
423
424         return pending;
425 }
426
427 static irqreturn_t pca953x_irq_handler(int irq, void *devid)
428 {
429         struct pca953x_chip *chip = devid;
430         uint16_t pending;
431         uint16_t level;
432
433         pending = pca953x_irq_pending(chip);
434
435         if (!pending)
436                 return IRQ_HANDLED;
437
438         do {
439                 level = __ffs(pending);
440                 generic_handle_irq(level + chip->irq_base);
441
442                 pending &= ~(1 << level);
443         } while (pending);
444
445         return IRQ_HANDLED;
446 }
447
448 static int pca953x_irq_setup(struct pca953x_chip *chip,
449                              const struct i2c_device_id *id)
450 {
451         struct i2c_client *client = chip->client;
452         struct pca953x_platform_data *pdata = client->dev.platform_data;
453         int ret, offset = 0;
454
455         if (pdata->irq_base != -1
456                         && (id->driver_data & PCA_INT)) {
457                 int lvl;
458
459                 switch (chip->chip_type) {
460                 case PCA953X_TYPE:
461                         offset = PCA953X_INPUT;
462                         break;
463                 case PCA957X_TYPE:
464                         offset = PCA957X_IN;
465                         break;
466                 }
467                 ret = pca953x_read_reg(chip, offset, &chip->irq_stat);
468                 if (ret)
469                         goto out_failed;
470
471                 /*
472                  * There is no way to know which GPIO line generated the
473                  * interrupt.  We have to rely on the previous read for
474                  * this purpose.
475                  */
476                 chip->irq_stat &= chip->reg_direction;
477                 chip->irq_base = pdata->irq_base;
478                 mutex_init(&chip->irq_lock);
479
480                 for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) {
481                         int irq = lvl + chip->irq_base;
482
483                         irq_set_chip_data(irq, chip);
484                         irq_set_chip_and_handler(irq, &pca953x_irq_chip,
485                                                  handle_simple_irq);
486 #ifdef CONFIG_ARM
487                         set_irq_flags(irq, IRQF_VALID);
488 #else
489                         irq_set_noprobe(irq);
490 #endif
491                 }
492
493                 ret = request_threaded_irq(client->irq,
494                                            NULL,
495                                            pca953x_irq_handler,
496                                            IRQF_TRIGGER_RISING |
497                                            IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
498                                            dev_name(&client->dev), chip);
499                 if (ret) {
500                         dev_err(&client->dev, "failed to request irq %d\n",
501                                 client->irq);
502                         goto out_failed;
503                 }
504
505                 chip->gpio_chip.to_irq = pca953x_gpio_to_irq;
506         }
507
508         return 0;
509
510 out_failed:
511         chip->irq_base = -1;
512         return ret;
513 }
514
515 static void pca953x_irq_teardown(struct pca953x_chip *chip)
516 {
517         if (chip->irq_base != -1)
518                 free_irq(chip->client->irq, chip);
519 }
520 #else /* CONFIG_GPIO_PCA953X_IRQ */
521 static int pca953x_irq_setup(struct pca953x_chip *chip,
522                              const struct i2c_device_id *id)
523 {
524         struct i2c_client *client = chip->client;
525         struct pca953x_platform_data *pdata = client->dev.platform_data;
526
527         if (pdata->irq_base != -1 && (id->driver_data & PCA_INT))
528                 dev_warn(&client->dev, "interrupt support not compiled in\n");
529
530         return 0;
531 }
532
533 static void pca953x_irq_teardown(struct pca953x_chip *chip)
534 {
535 }
536 #endif
537
538 /*
539  * Handlers for alternative sources of platform_data
540  */
541 #ifdef CONFIG_OF_GPIO
542 /*
543  * Translate OpenFirmware node properties into platform_data
544  */
545 static struct pca953x_platform_data *
546 pca953x_get_alt_pdata(struct i2c_client *client)
547 {
548         struct pca953x_platform_data *pdata;
549         struct device_node *node;
550         const __be32 *val;
551         int size;
552
553         node = client->dev.of_node;
554         if (node == NULL)
555                 return NULL;
556
557         pdata = kzalloc(sizeof(struct pca953x_platform_data), GFP_KERNEL);
558         if (pdata == NULL) {
559                 dev_err(&client->dev, "Unable to allocate platform_data\n");
560                 return NULL;
561         }
562
563         pdata->gpio_base = -1;
564         val = of_get_property(node, "linux,gpio-base", &size);
565         if (val) {
566                 if (size != sizeof(*val))
567                         dev_warn(&client->dev, "%s: wrong linux,gpio-base\n",
568                                  node->full_name);
569                 else
570                         pdata->gpio_base = be32_to_cpup(val);
571         }
572
573         val = of_get_property(node, "polarity", NULL);
574         if (val)
575                 pdata->invert = *val;
576
577         return pdata;
578 }
579 #else
580 static struct pca953x_platform_data *
581 pca953x_get_alt_pdata(struct i2c_client *client)
582 {
583         return NULL;
584 }
585 #endif
586
587 static int __devinit device_pca953x_init(struct pca953x_chip *chip, int invert)
588 {
589         int ret;
590
591         ret = pca953x_read_reg(chip, PCA953X_OUTPUT, &chip->reg_output);
592         if (ret)
593                 goto out;
594
595         ret = pca953x_read_reg(chip, PCA953X_DIRECTION,
596                                &chip->reg_direction);
597         if (ret)
598                 goto out;
599
600         /* set platform specific polarity inversion */
601         ret = pca953x_write_reg(chip, PCA953X_INVERT, invert);
602         if (ret)
603                 goto out;
604         return 0;
605 out:
606         return ret;
607 }
608
609 static int __devinit device_pca957x_init(struct pca953x_chip *chip, int invert)
610 {
611         int ret;
612         uint16_t val = 0;
613
614         /* Let every port in proper state, that could save power */
615         pca953x_write_reg(chip, PCA957X_PUPD, 0x0);
616         pca953x_write_reg(chip, PCA957X_CFG, 0xffff);
617         pca953x_write_reg(chip, PCA957X_OUT, 0x0);
618
619         ret = pca953x_read_reg(chip, PCA957X_IN, &val);
620         if (ret)
621                 goto out;
622         ret = pca953x_read_reg(chip, PCA957X_OUT, &chip->reg_output);
623         if (ret)
624                 goto out;
625         ret = pca953x_read_reg(chip, PCA957X_CFG, &chip->reg_direction);
626         if (ret)
627                 goto out;
628
629         /* set platform specific polarity inversion */
630         pca953x_write_reg(chip, PCA957X_INVRT, invert);
631
632         /* To enable register 6, 7 to controll pull up and pull down */
633         pca953x_write_reg(chip, PCA957X_BKEN, 0x202);
634
635         return 0;
636 out:
637         return ret;
638 }
639
640 static int __devinit pca953x_probe(struct i2c_client *client,
641                                    const struct i2c_device_id *id)
642 {
643         struct pca953x_platform_data *pdata;
644         struct pca953x_chip *chip;
645         int ret = 0;
646
647         chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
648         if (chip == NULL)
649                 return -ENOMEM;
650
651         pdata = client->dev.platform_data;
652         if (pdata == NULL) {
653                 pdata = pca953x_get_alt_pdata(client);
654                 /*
655                  * Unlike normal platform_data, this is allocated
656                  * dynamically and must be freed in the driver
657                  */
658                 chip->dyn_pdata = pdata;
659         }
660
661         if (pdata == NULL) {
662                 dev_dbg(&client->dev, "no platform data\n");
663                 ret = -EINVAL;
664                 goto out_failed;
665         }
666
667         chip->client = client;
668
669         chip->gpio_start = pdata->gpio_base;
670
671         chip->names = pdata->names;
672         chip->chip_type = id->driver_data & (PCA953X_TYPE | PCA957X_TYPE);
673
674         mutex_init(&chip->i2c_lock);
675
676         /* initialize cached registers from their original values.
677          * we can't share this chip with another i2c master.
678          */
679         pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK);
680
681         if (chip->chip_type == PCA953X_TYPE)
682                 device_pca953x_init(chip, pdata->invert);
683         else if (chip->chip_type == PCA957X_TYPE)
684                 device_pca957x_init(chip, pdata->invert);
685         else
686                 goto out_failed;
687
688         ret = pca953x_irq_setup(chip, id);
689         if (ret)
690                 goto out_failed;
691
692         ret = gpiochip_add(&chip->gpio_chip);
693         if (ret)
694                 goto out_failed_irq;
695
696         if (pdata->setup) {
697                 ret = pdata->setup(client, chip->gpio_chip.base,
698                                 chip->gpio_chip.ngpio, pdata->context);
699                 if (ret < 0)
700                         dev_warn(&client->dev, "setup failed, %d\n", ret);
701         }
702
703         i2c_set_clientdata(client, chip);
704         return 0;
705
706 out_failed_irq:
707         pca953x_irq_teardown(chip);
708 out_failed:
709         kfree(chip->dyn_pdata);
710         kfree(chip);
711         return ret;
712 }
713
714 static int pca953x_remove(struct i2c_client *client)
715 {
716         struct pca953x_platform_data *pdata = client->dev.platform_data;
717         struct pca953x_chip *chip = i2c_get_clientdata(client);
718         int ret = 0;
719
720         if (pdata->teardown) {
721                 ret = pdata->teardown(client, chip->gpio_chip.base,
722                                 chip->gpio_chip.ngpio, pdata->context);
723                 if (ret < 0) {
724                         dev_err(&client->dev, "%s failed, %d\n",
725                                         "teardown", ret);
726                         return ret;
727                 }
728         }
729
730         ret = gpiochip_remove(&chip->gpio_chip);
731         if (ret) {
732                 dev_err(&client->dev, "%s failed, %d\n",
733                                 "gpiochip_remove()", ret);
734                 return ret;
735         }
736
737         pca953x_irq_teardown(chip);
738         kfree(chip->dyn_pdata);
739         kfree(chip);
740         return 0;
741 }
742
743 static struct i2c_driver pca953x_driver = {
744         .driver = {
745                 .name   = "pca953x",
746         },
747         .probe          = pca953x_probe,
748         .remove         = pca953x_remove,
749         .id_table       = pca953x_id,
750 };
751
752 static int __init pca953x_init(void)
753 {
754         return i2c_add_driver(&pca953x_driver);
755 }
756 /* register after i2c postcore initcall and before
757  * subsys initcalls that may rely on these GPIOs
758  */
759 subsys_initcall(pca953x_init);
760
761 static void __exit pca953x_exit(void)
762 {
763         i2c_del_driver(&pca953x_driver);
764 }
765 module_exit(pca953x_exit);
766
767 MODULE_AUTHOR("eric miao <eric.miao@marvell.com>");
768 MODULE_DESCRIPTION("GPIO expander driver for PCA953x");
769 MODULE_LICENSE("GPL");