blob: 2a82e8999a4299553a4ebeec273a69b55663df61 [file] [log] [blame]
Rabin Vincentd88b25b2010-05-10 23:43:47 +02001/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/platform_device.h>
12#include <linux/slab.h>
13#include <linux/gpio.h>
14#include <linux/irq.h>
15#include <linux/interrupt.h>
Sundar Iyerc6eda6c2010-12-13 09:33:12 +053016#include <linux/mfd/tc3589x.h>
Rabin Vincentd88b25b2010-05-10 23:43:47 +020017
18/*
19 * These registers are modified under the irq bus lock and cached to avoid
20 * unnecessary writes in bus_sync_unlock.
21 */
22enum { REG_IBE, REG_IEV, REG_IS, REG_IE };
23
24#define CACHE_NR_REGS 4
25#define CACHE_NR_BANKS 3
26
Sundar Iyer20406eb2010-12-13 09:33:14 +053027struct tc3589x_gpio {
Rabin Vincentd88b25b2010-05-10 23:43:47 +020028 struct gpio_chip chip;
Sundar Iyer20406eb2010-12-13 09:33:14 +053029 struct tc3589x *tc3589x;
Rabin Vincentd88b25b2010-05-10 23:43:47 +020030 struct device *dev;
31 struct mutex irq_lock;
32
33 int irq_base;
34
35 /* Caches of interrupt control registers for bus_lock */
36 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
37 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
38};
39
Sundar Iyer20406eb2010-12-13 09:33:14 +053040static inline struct tc3589x_gpio *to_tc3589x_gpio(struct gpio_chip *chip)
Rabin Vincentd88b25b2010-05-10 23:43:47 +020041{
Sundar Iyer20406eb2010-12-13 09:33:14 +053042 return container_of(chip, struct tc3589x_gpio, chip);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020043}
44
Sundar Iyer20406eb2010-12-13 09:33:14 +053045static int tc3589x_gpio_get(struct gpio_chip *chip, unsigned offset)
Rabin Vincentd88b25b2010-05-10 23:43:47 +020046{
Sundar Iyer20406eb2010-12-13 09:33:14 +053047 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
48 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
49 u8 reg = TC3589x_GPIODATA0 + (offset / 8) * 2;
Rabin Vincentd88b25b2010-05-10 23:43:47 +020050 u8 mask = 1 << (offset % 8);
51 int ret;
52
Sundar Iyer20406eb2010-12-13 09:33:14 +053053 ret = tc3589x_reg_read(tc3589x, reg);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020054 if (ret < 0)
55 return ret;
56
57 return ret & mask;
58}
59
Sundar Iyer20406eb2010-12-13 09:33:14 +053060static void tc3589x_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
Rabin Vincentd88b25b2010-05-10 23:43:47 +020061{
Sundar Iyer20406eb2010-12-13 09:33:14 +053062 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
63 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
64 u8 reg = TC3589x_GPIODATA0 + (offset / 8) * 2;
Rabin Vincentd88b25b2010-05-10 23:43:47 +020065 unsigned pos = offset % 8;
66 u8 data[] = {!!val << pos, 1 << pos};
67
Sundar Iyer20406eb2010-12-13 09:33:14 +053068 tc3589x_block_write(tc3589x, reg, ARRAY_SIZE(data), data);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020069}
70
Sundar Iyer20406eb2010-12-13 09:33:14 +053071static int tc3589x_gpio_direction_output(struct gpio_chip *chip,
Rabin Vincentd88b25b2010-05-10 23:43:47 +020072 unsigned offset, int val)
73{
Sundar Iyer20406eb2010-12-13 09:33:14 +053074 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
75 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
76 u8 reg = TC3589x_GPIODIR0 + offset / 8;
Rabin Vincentd88b25b2010-05-10 23:43:47 +020077 unsigned pos = offset % 8;
78
Sundar Iyer20406eb2010-12-13 09:33:14 +053079 tc3589x_gpio_set(chip, offset, val);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020080
Sundar Iyer20406eb2010-12-13 09:33:14 +053081 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 1 << pos);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020082}
83
Sundar Iyer20406eb2010-12-13 09:33:14 +053084static int tc3589x_gpio_direction_input(struct gpio_chip *chip,
Rabin Vincentd88b25b2010-05-10 23:43:47 +020085 unsigned offset)
86{
Sundar Iyer20406eb2010-12-13 09:33:14 +053087 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
88 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
89 u8 reg = TC3589x_GPIODIR0 + offset / 8;
Rabin Vincentd88b25b2010-05-10 23:43:47 +020090 unsigned pos = offset % 8;
91
Sundar Iyer20406eb2010-12-13 09:33:14 +053092 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020093}
94
Sundar Iyer20406eb2010-12-13 09:33:14 +053095static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
Rabin Vincentd88b25b2010-05-10 23:43:47 +020096{
Sundar Iyer20406eb2010-12-13 09:33:14 +053097 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
Rabin Vincentd88b25b2010-05-10 23:43:47 +020098
Sundar Iyer20406eb2010-12-13 09:33:14 +053099 return tc3589x_gpio->irq_base + offset;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200100}
101
102static struct gpio_chip template_chip = {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530103 .label = "tc3589x",
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200104 .owner = THIS_MODULE,
Sundar Iyer20406eb2010-12-13 09:33:14 +0530105 .direction_input = tc3589x_gpio_direction_input,
106 .get = tc3589x_gpio_get,
107 .direction_output = tc3589x_gpio_direction_output,
108 .set = tc3589x_gpio_set,
109 .to_irq = tc3589x_gpio_to_irq,
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200110 .can_sleep = 1,
111};
112
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800113static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200114{
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800115 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
116 int offset = d->irq - tc3589x_gpio->irq_base;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200117 int regoffset = offset / 8;
118 int mask = 1 << (offset % 8);
119
120 if (type == IRQ_TYPE_EDGE_BOTH) {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530121 tc3589x_gpio->regs[REG_IBE][regoffset] |= mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200122 return 0;
123 }
124
Sundar Iyer20406eb2010-12-13 09:33:14 +0530125 tc3589x_gpio->regs[REG_IBE][regoffset] &= ~mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200126
127 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
Sundar Iyer20406eb2010-12-13 09:33:14 +0530128 tc3589x_gpio->regs[REG_IS][regoffset] |= mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200129 else
Sundar Iyer20406eb2010-12-13 09:33:14 +0530130 tc3589x_gpio->regs[REG_IS][regoffset] &= ~mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200131
132 if (type == IRQ_TYPE_EDGE_RISING || type == IRQ_TYPE_LEVEL_HIGH)
Sundar Iyer20406eb2010-12-13 09:33:14 +0530133 tc3589x_gpio->regs[REG_IEV][regoffset] |= mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200134 else
Sundar Iyer20406eb2010-12-13 09:33:14 +0530135 tc3589x_gpio->regs[REG_IEV][regoffset] &= ~mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200136
137 return 0;
138}
139
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800140static void tc3589x_gpio_irq_lock(struct irq_data *d)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200141{
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800142 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200143
Sundar Iyer20406eb2010-12-13 09:33:14 +0530144 mutex_lock(&tc3589x_gpio->irq_lock);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200145}
146
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800147static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200148{
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800149 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
Sundar Iyer20406eb2010-12-13 09:33:14 +0530150 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200151 static const u8 regmap[] = {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530152 [REG_IBE] = TC3589x_GPIOIBE0,
153 [REG_IEV] = TC3589x_GPIOIEV0,
154 [REG_IS] = TC3589x_GPIOIS0,
155 [REG_IE] = TC3589x_GPIOIE0,
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200156 };
157 int i, j;
158
159 for (i = 0; i < CACHE_NR_REGS; i++) {
160 for (j = 0; j < CACHE_NR_BANKS; j++) {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530161 u8 old = tc3589x_gpio->oldregs[i][j];
162 u8 new = tc3589x_gpio->regs[i][j];
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200163
164 if (new == old)
165 continue;
166
Sundar Iyer20406eb2010-12-13 09:33:14 +0530167 tc3589x_gpio->oldregs[i][j] = new;
168 tc3589x_reg_write(tc3589x, regmap[i] + j * 8, new);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200169 }
170 }
171
Sundar Iyer20406eb2010-12-13 09:33:14 +0530172 mutex_unlock(&tc3589x_gpio->irq_lock);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200173}
174
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800175static void tc3589x_gpio_irq_mask(struct irq_data *d)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200176{
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800177 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
178 int offset = d->irq - tc3589x_gpio->irq_base;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200179 int regoffset = offset / 8;
180 int mask = 1 << (offset % 8);
181
Sundar Iyer20406eb2010-12-13 09:33:14 +0530182 tc3589x_gpio->regs[REG_IE][regoffset] &= ~mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200183}
184
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800185static void tc3589x_gpio_irq_unmask(struct irq_data *d)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200186{
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800187 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
188 int offset = d->irq - tc3589x_gpio->irq_base;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200189 int regoffset = offset / 8;
190 int mask = 1 << (offset % 8);
191
Sundar Iyer20406eb2010-12-13 09:33:14 +0530192 tc3589x_gpio->regs[REG_IE][regoffset] |= mask;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200193}
194
Sundar Iyer20406eb2010-12-13 09:33:14 +0530195static struct irq_chip tc3589x_gpio_irq_chip = {
196 .name = "tc3589x-gpio",
Lennert Buytenhek33fcc1b2011-01-12 17:00:19 -0800197 .irq_bus_lock = tc3589x_gpio_irq_lock,
198 .irq_bus_sync_unlock = tc3589x_gpio_irq_sync_unlock,
199 .irq_mask = tc3589x_gpio_irq_mask,
200 .irq_unmask = tc3589x_gpio_irq_unmask,
201 .irq_set_type = tc3589x_gpio_irq_set_type,
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200202};
203
Sundar Iyer20406eb2010-12-13 09:33:14 +0530204static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200205{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530206 struct tc3589x_gpio *tc3589x_gpio = dev;
207 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200208 u8 status[CACHE_NR_BANKS];
209 int ret;
210 int i;
211
Sundar Iyer20406eb2010-12-13 09:33:14 +0530212 ret = tc3589x_block_read(tc3589x, TC3589x_GPIOMIS0,
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200213 ARRAY_SIZE(status), status);
214 if (ret < 0)
215 return IRQ_NONE;
216
217 for (i = 0; i < ARRAY_SIZE(status); i++) {
218 unsigned int stat = status[i];
219 if (!stat)
220 continue;
221
222 while (stat) {
223 int bit = __ffs(stat);
224 int line = i * 8 + bit;
225
Sundar Iyer20406eb2010-12-13 09:33:14 +0530226 handle_nested_irq(tc3589x_gpio->irq_base + line);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200227 stat &= ~(1 << bit);
228 }
229
Sundar Iyer20406eb2010-12-13 09:33:14 +0530230 tc3589x_reg_write(tc3589x, TC3589x_GPIOIC0 + i, status[i]);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200231 }
232
233 return IRQ_HANDLED;
234}
235
Sundar Iyer20406eb2010-12-13 09:33:14 +0530236static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200237{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530238 int base = tc3589x_gpio->irq_base;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200239 int irq;
240
Sundar Iyer20406eb2010-12-13 09:33:14 +0530241 for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) {
Thomas Gleixnerb51804b2011-03-24 21:27:36 +0000242 irq_set_chip_data(irq, tc3589x_gpio);
243 irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip,
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200244 handle_simple_irq);
Thomas Gleixnerb51804b2011-03-24 21:27:36 +0000245 irq_set_nested_thread(irq, 1);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200246#ifdef CONFIG_ARM
247 set_irq_flags(irq, IRQF_VALID);
248#else
Thomas Gleixnerb51804b2011-03-24 21:27:36 +0000249 irq_set_noprobe(irq);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200250#endif
251 }
252
253 return 0;
254}
255
Sundar Iyer20406eb2010-12-13 09:33:14 +0530256static void tc3589x_gpio_irq_remove(struct tc3589x_gpio *tc3589x_gpio)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200257{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530258 int base = tc3589x_gpio->irq_base;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200259 int irq;
260
Sundar Iyer20406eb2010-12-13 09:33:14 +0530261 for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) {
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200262#ifdef CONFIG_ARM
263 set_irq_flags(irq, 0);
264#endif
Thomas Gleixnerb51804b2011-03-24 21:27:36 +0000265 irq_set_chip_and_handler(irq, NULL, NULL);
266 irq_set_chip_data(irq, NULL);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200267 }
268}
269
Sundar Iyer20406eb2010-12-13 09:33:14 +0530270static int __devinit tc3589x_gpio_probe(struct platform_device *pdev)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200271{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530272 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
273 struct tc3589x_gpio_platform_data *pdata;
274 struct tc3589x_gpio *tc3589x_gpio;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200275 int ret;
276 int irq;
277
Sundar Iyer20406eb2010-12-13 09:33:14 +0530278 pdata = tc3589x->pdata->gpio;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200279 if (!pdata)
280 return -ENODEV;
281
282 irq = platform_get_irq(pdev, 0);
283 if (irq < 0)
284 return irq;
285
Sundar Iyer20406eb2010-12-13 09:33:14 +0530286 tc3589x_gpio = kzalloc(sizeof(struct tc3589x_gpio), GFP_KERNEL);
287 if (!tc3589x_gpio)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200288 return -ENOMEM;
289
Sundar Iyer20406eb2010-12-13 09:33:14 +0530290 mutex_init(&tc3589x_gpio->irq_lock);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200291
Sundar Iyer20406eb2010-12-13 09:33:14 +0530292 tc3589x_gpio->dev = &pdev->dev;
293 tc3589x_gpio->tc3589x = tc3589x;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200294
Sundar Iyer20406eb2010-12-13 09:33:14 +0530295 tc3589x_gpio->chip = template_chip;
296 tc3589x_gpio->chip.ngpio = tc3589x->num_gpio;
297 tc3589x_gpio->chip.dev = &pdev->dev;
298 tc3589x_gpio->chip.base = pdata->gpio_base;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200299
Sundar Iyer20406eb2010-12-13 09:33:14 +0530300 tc3589x_gpio->irq_base = tc3589x->irq_base + TC3589x_INT_GPIO(0);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200301
302 /* Bring the GPIO module out of reset */
Sundar Iyer20406eb2010-12-13 09:33:14 +0530303 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL,
304 TC3589x_RSTCTRL_GPIRST, 0);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200305 if (ret < 0)
306 goto out_free;
307
Sundar Iyer20406eb2010-12-13 09:33:14 +0530308 ret = tc3589x_gpio_irq_init(tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200309 if (ret)
310 goto out_free;
311
Sundar Iyer20406eb2010-12-13 09:33:14 +0530312 ret = request_threaded_irq(irq, NULL, tc3589x_gpio_irq, IRQF_ONESHOT,
313 "tc3589x-gpio", tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200314 if (ret) {
315 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
316 goto out_removeirq;
317 }
318
Sundar Iyer20406eb2010-12-13 09:33:14 +0530319 ret = gpiochip_add(&tc3589x_gpio->chip);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200320 if (ret) {
321 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
322 goto out_freeirq;
323 }
324
Rabin Vincentf0a7a982010-09-13 13:04:02 +0100325 if (pdata->setup)
Sundar Iyer20406eb2010-12-13 09:33:14 +0530326 pdata->setup(tc3589x, tc3589x_gpio->chip.base);
Rabin Vincentf0a7a982010-09-13 13:04:02 +0100327
Sundar Iyer20406eb2010-12-13 09:33:14 +0530328 platform_set_drvdata(pdev, tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200329
330 return 0;
331
332out_freeirq:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530333 free_irq(irq, tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200334out_removeirq:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530335 tc3589x_gpio_irq_remove(tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200336out_free:
Sundar Iyer20406eb2010-12-13 09:33:14 +0530337 kfree(tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200338 return ret;
339}
340
Sundar Iyer20406eb2010-12-13 09:33:14 +0530341static int __devexit tc3589x_gpio_remove(struct platform_device *pdev)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200342{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530343 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev);
344 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
345 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio;
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200346 int irq = platform_get_irq(pdev, 0);
347 int ret;
348
Rabin Vincentf0a7a982010-09-13 13:04:02 +0100349 if (pdata->remove)
Sundar Iyer20406eb2010-12-13 09:33:14 +0530350 pdata->remove(tc3589x, tc3589x_gpio->chip.base);
Rabin Vincentf0a7a982010-09-13 13:04:02 +0100351
Sundar Iyer20406eb2010-12-13 09:33:14 +0530352 ret = gpiochip_remove(&tc3589x_gpio->chip);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200353 if (ret < 0) {
Sundar Iyer20406eb2010-12-13 09:33:14 +0530354 dev_err(tc3589x_gpio->dev,
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200355 "unable to remove gpiochip: %d\n", ret);
356 return ret;
357 }
358
Sundar Iyer20406eb2010-12-13 09:33:14 +0530359 free_irq(irq, tc3589x_gpio);
360 tc3589x_gpio_irq_remove(tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200361
362 platform_set_drvdata(pdev, NULL);
Sundar Iyer20406eb2010-12-13 09:33:14 +0530363 kfree(tc3589x_gpio);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200364
365 return 0;
366}
367
Sundar Iyer20406eb2010-12-13 09:33:14 +0530368static struct platform_driver tc3589x_gpio_driver = {
369 .driver.name = "tc3589x-gpio",
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200370 .driver.owner = THIS_MODULE,
Sundar Iyer20406eb2010-12-13 09:33:14 +0530371 .probe = tc3589x_gpio_probe,
372 .remove = __devexit_p(tc3589x_gpio_remove),
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200373};
374
Sundar Iyer20406eb2010-12-13 09:33:14 +0530375static int __init tc3589x_gpio_init(void)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200376{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530377 return platform_driver_register(&tc3589x_gpio_driver);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200378}
Sundar Iyer20406eb2010-12-13 09:33:14 +0530379subsys_initcall(tc3589x_gpio_init);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200380
Sundar Iyer20406eb2010-12-13 09:33:14 +0530381static void __exit tc3589x_gpio_exit(void)
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200382{
Sundar Iyer20406eb2010-12-13 09:33:14 +0530383 platform_driver_unregister(&tc3589x_gpio_driver);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200384}
Sundar Iyer20406eb2010-12-13 09:33:14 +0530385module_exit(tc3589x_gpio_exit);
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200386
387MODULE_LICENSE("GPL v2");
Sundar Iyer20406eb2010-12-13 09:33:14 +0530388MODULE_DESCRIPTION("TC3589x GPIO driver");
Rabin Vincentd88b25b2010-05-10 23:43:47 +0200389MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");