usb: dwc3: rockchip: fix possible circular deadlock
[firefly-linux-kernel-4.4.55.git] / drivers / gpio / tca6424.c
1 /*
2  * Copyright (C) 2010 ROCKCHIP, Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
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 /*******************************************************************/
14 /*        COPYRIGHT (C)  ROCK-CHIPS FUZHOU . ALL RIGHTS RESERVED.*/
15 /*******************************************************************
16 FILE                    :       tca6424.c
17 MODIFY          :       sxj
18 DATE            :       2010-8-11
19 NOTES           :
20 ********************************************************************/
21 #include <asm/mach/time.h>
22 #include <linux/clk.h>
23 #include <linux/errno.h>
24 #include <linux/interrupt.h>
25 #include <asm/mach-types.h>
26 #include <linux/irq.h>
27 #include <linux/debugfs.h>
28 #include <linux/seq_file.h>
29 #include <linux/kernel.h>
30 #include <linux/list.h>
31 #include <linux/module.h>
32 #include <linux/io.h>
33 #include <mach/hardware.h>
34 #include <mach/gpio.h>
35 #include <mach/rk2818_iomap.h>
36 #include <mach/iomux.h>
37 #include <linux/device.h>
38 #include <mach/gpio.h>
39 #include <asm/gpio.h>
40 #include <linux/i2c.h>
41 #include <linux/workqueue.h>
42 #include <mach/board.h>
43 #include <linux/delay.h>
44 #include <linux/i2c/tca6424.h>
45 #include <linux/ktime.h>
46 #include "../drivers/gpio/expand_gpio_soft_interrupt.h"
47
48 #if 0
49 #define DBG(x...)       printk(KERN_INFO x)
50 #else
51 #define DBG(x...)
52 #endif
53 #define DBGERR(x...)    printk(KERN_INFO x)
54
55
56 struct tca6424_chip {
57         
58         unsigned int gpio_start;
59         unsigned int gpio_pin_num;
60
61         #ifdef TCA6424_OUTREGLOCK
62                 struct mutex outreglock;
63         #endif
64         #ifdef TCA6424_INPUTREGLOCK
65                 struct mutex inputreglock;
66         #endif
67         #ifdef TCA6424_CONFIGREGLOCK
68                 struct mutex configreglock;
69         #endif
70
71         struct i2c_client *client;
72         struct expand_gpio_soft_int *expand;
73         struct expand_gpio_global_variable gtca6424_struct;
74         struct gpio_chip gpio_chip;
75         char **names;
76 };
77
78 static const struct i2c_device_id tca6424_id[] = 
79 {
80     {"extend_gpio_tca6424",8,}, 
81     { }
82 };
83 MODULE_DEVICE_TABLE(i2c, tca6424_id);
84
85 static short int portnum[TCA6424_PortNum]={ TCA6424_Port0PinNum,
86                                             TCA6424_Port1PinNum,TCA6424_Port2PinNum};
87
88 extern inline struct gpio_chip *gpio_to_chip(unsigned gpio);
89
90 int tca6424_irq_read_inputreg(void *data,char *buf)
91 {
92
93         struct tca6424_chip *tca6424data=(struct tca6424_chip *)data;
94         int ret = -1;
95         ret = i2c_master_reg8_recv(tca6424data->client, TCA6424_Auto_InputLevel_Reg, buf, 3, TCA6424_I2C_RATE);
96         return (ret>0)?0:ret;
97 }
98
99 static int tca6424_write_reg(struct i2c_client *client, uint8_t reg, uint8_t val)
100 {
101         int ret=-1;
102         struct i2c_adapter *adap;
103         struct i2c_msg msg;
104         char tx_buf[2];
105         if(!client)
106                 return ret;    
107         adap = client->adapter;         
108         tx_buf[0] = reg;
109         tx_buf[1]= val;
110
111         msg.addr = client->addr;
112         msg.buf = tx_buf;
113         msg.len = 1 +1;
114         msg.flags = client->flags;   
115         msg.scl_rate = TCA6424_I2C_RATE;
116         ret = i2c_transfer(adap, &msg, 1);
117         return ret;  
118 }
119
120 static int tca6424_read_reg(struct i2c_client *client, uint8_t reg, uint8_t *val)
121 {
122         int ret=-1;
123     struct i2c_adapter *adap;
124     struct i2c_msg msgs[2];
125         
126     if(!client)
127                 return ret;    
128     adap = client->adapter;             
129     //·¢ËͼĴæÆ÷µØÖ·
130     msgs[0].addr = client->addr;
131     msgs[0].buf = &reg;
132     msgs[0].flags = client->flags;
133     msgs[0].len = 1;
134     msgs[0].scl_rate = TCA6424_I2C_RATE;
135     //½ÓÊÕÊý¾Ý
136     msgs[1].buf = val;
137     msgs[1].addr = client->addr;
138     msgs[1].flags = client->flags | I2C_M_RD;
139     msgs[1].len = 1;
140     msgs[1].scl_rate = TCA6424_I2C_RATE;
141
142     ret = i2c_transfer(adap, msgs, 2);
143     return ret;   
144
145 }
146
147 static int tca6424_write_three_reg(struct i2c_client *client, const char reg, const char *buf, int count, int rate)
148 {
149         int ret = -1;
150         ret = i2c_master_reg8_send(client, reg, buf, count, rate);
151         return (ret>0)?0:ret;
152 }
153
154 static int tca6424_read_three_reg(struct i2c_client *client, const char reg, char *buf, int count, int rate)
155 {
156         int ret = -1;
157         ret = i2c_master_reg8_recv(client, reg, buf, count, rate);
158         return (ret>0)?0:ret;
159 }
160
161 static int tca6424_gpio_direction_input(struct gpio_chip *gc, unsigned pin_num)
162 {
163         struct tca6424_chip *chip;
164         uint8_t gpioPortNum;
165         uint8_t gpioPortPinNum;
166         uint8_t reg_val; 
167         uint8_t Regaddr;
168         int ret = -1;
169         
170         chip = container_of(gc, struct tca6424_chip, gpio_chip);
171         gpioPortNum = pin_num/8;
172         gpioPortPinNum= pin_num%8;
173         if((gpioPortNum>=TCA6424_PortNum)||(gpioPortPinNum>=portnum[gpioPortNum]))
174                 return ret;
175         Regaddr = TCA6424_Config_Reg+gpioPortNum;       
176         
177         #ifdef TCA6424_CONFIGREGLOCK
178         if (!mutex_trylock(&chip->configreglock))
179         {
180                 DBGERR("**%s[%d]Did not get the configreglock**\n",__FUNCTION__,__LINE__);
181                 return -1;
182         }
183         #endif
184
185         if(((chip->gtca6424_struct.reg_direction[gpioPortNum]>>gpioPortPinNum)& 0x01)==EXTGPIO_OUTPUT)
186         {
187                 reg_val = tca6424setbit(chip->gtca6424_struct.reg_direction[gpioPortNum], gpioPortPinNum);
188                 ret = tca6424_write_reg(chip->client, Regaddr, reg_val);
189                 if(ret<0)
190                         goto err;
191                 chip->gtca6424_struct.reg_direction[gpioPortNum] = reg_val;
192                 //DBG("**%s[%d],set config address[0x%2x]=%2x,ret=%d**\n",__FUNCTION__,__LINE__,Regaddr,reg_val,ret);   
193         }
194 err:
195         #ifdef TCA6424_CONFIGREGLOCK
196                 mutex_unlock(&chip->configreglock);
197         #endif
198         return (ret<0)?-1:0;
199 }
200
201 static int tca6424_gpio_direction_output(struct gpio_chip *gc, unsigned pin_num, int val)
202 {
203         struct tca6424_chip *chip;
204         uint8_t gpioPortNum;
205         uint8_t gpioPortPinNum;    
206         uint8_t reg_val = 0;
207         uint8_t Regaddr = 0;
208         int ret = -1;
209         
210         chip = container_of(gc, struct tca6424_chip, gpio_chip);
211         gpioPortNum = pin_num/8;
212         gpioPortPinNum = pin_num%8;
213         if((gpioPortNum>=TCA6424_PortNum)||(gpioPortPinNum>=portnum[gpioPortNum]))
214                 return ret;
215         Regaddr = TCA6424_Config_Reg+gpioPortNum;       
216
217         #ifdef TCA6424_CONFIGREGLOCK
218         if (!mutex_trylock(&chip->configreglock))
219         {
220                 DBGERR("**%s[%d]Did not get the configreglock**\n",__FUNCTION__,__LINE__);
221                 return -1;
222         }
223         #endif
224
225         if(((chip->gtca6424_struct.reg_direction[gpioPortNum]>>gpioPortPinNum)& 0x01)==EXTGPIO_INPUT)
226         {
227                 reg_val = tca6424clearbit(chip->gtca6424_struct.reg_direction[gpioPortNum], gpioPortPinNum);
228                 //DBG("**%s[%d],set config address[0x%2x]=%2x,**\n",__FUNCTION__,__LINE__,Regaddr,reg_val);     
229                 ret = tca6424_write_reg(chip->client, Regaddr, reg_val);
230                 if(ret<0)
231                 {
232                         #ifdef TCA6424_CONFIGREGLOCK
233                         mutex_unlock(&chip->configreglock);
234                         #endif
235                         DBGERR("**%s[%d] set direction reg is error,reg_val=%x,ret=%d**\n",__FUNCTION__,__LINE__,reg_val,ret);
236                 return ret;
237                 }
238                 chip->gtca6424_struct.reg_direction[gpioPortNum] = reg_val;
239         }
240         
241         #ifdef TCA6424_CONFIGREGLOCK
242         mutex_unlock(&chip->configreglock);
243         #endif
244         
245         ret = -1;
246     #ifdef TCA6424_OUTREGLOCK
247         if (!mutex_trylock(&chip->outreglock))
248         {
249                 DBGERR("**%s[%d] Did not get the outreglock**\n",__FUNCTION__,__LINE__);
250                 return ret;
251         }
252         #endif
253
254         if(((chip->gtca6424_struct.reg_output[gpioPortNum]>>gpioPortPinNum)& 0x01) != val)
255         {
256                 if (val)
257                         reg_val = tca6424setbit(chip->gtca6424_struct.reg_output[gpioPortNum], gpioPortPinNum);
258                 else
259                         reg_val = tca6424clearbit(chip->gtca6424_struct.reg_output[gpioPortNum], gpioPortPinNum);
260
261                 Regaddr = TCA6424_OutputLevel_Reg+gpioPortNum;  
262                 ret = tca6424_write_reg(chip->client, Regaddr, reg_val);
263                 if (ret<0)
264                 {
265                         #ifdef TCA6424_OUTREGLOCK
266                                 mutex_unlock(&chip->outreglock);
267                         #endif
268                         DBGERR("**%s[%d] set out reg is error,reg_val=%x,ret=%d**\n",__FUNCTION__,__LINE__,reg_val,ret);
269                         return ret;
270                 }
271                 chip->gtca6424_struct.reg_output[gpioPortNum] = reg_val;
272         }
273
274         #ifdef TCA6424_OUTREGLOCK
275                 mutex_unlock(&chip->outreglock);
276         #endif
277         //DBG("**%s[%d],set output address[0x%2x]=%2x,ret=%d**\n",__FUNCTION__,__LINE__,Regaddr,reg_val,ret);   
278     return (ret<0)?-1:0;
279 }
280
281 static int tca6424_gpio_get_value(struct gpio_chip *gc, unsigned pin_num)
282 {
283         struct tca6424_chip *chip;
284         uint8_t gpioPortNum;
285         uint8_t gpioPortPinNum;
286         uint8_t Regaddr;
287         int ret;
288
289         chip = container_of(gc, struct tca6424_chip, gpio_chip);
290
291         #ifdef CONFIG_EXPAND_GPIO_SOFT_INTERRUPT
292         ret = wait_untill_input_reg_flash( );
293         if(ret<0)
294         {
295                 return -1;
296                 DBGERR("**********tca6424 get value error***************\n");
297         }
298         #endif
299         
300         gpioPortNum = pin_num/8;
301         gpioPortPinNum= pin_num%8;
302         Regaddr = TCA6424_OutputLevel_Reg+gpioPortNum;  
303         
304         if((gpioPortNum>=TCA6424_PortNum)||(gpioPortPinNum>=portnum[gpioPortNum]))
305                 return -1;
306
307         #ifndef CONFIG_EXPAND_GPIO_SOFT_INTERRUPT
308         uint8_t reg_val;
309         ret = tca6424_read_reg(chip->client, Regaddr, &reg_val);
310         if (ret < 0) 
311                 return -1;
312         chip->gtca6424_struct.reg_input[gpioPortNum] = reg_val;
313         #endif
314
315         //DBG("**%s[%d] read input address[0x%2x]=%2x**\n",__FUNCTION__,__LINE__,Regaddr,chip->reg_input[gpioPortNum]);
316         return ((chip->gtca6424_struct.reg_input[gpioPortNum] >> gpioPortPinNum) & 0x01);
317 }
318
319 static void tca6424_gpio_set_value(struct gpio_chip *gc, unsigned pin_num, int val)
320 {
321         struct tca6424_chip *chip;
322         uint8_t gpioPortNum;
323         uint8_t gpioPortPinNum;
324         uint8_t reg_val;
325         uint8_t Regaddr;
326         int ret=-1;
327         
328         chip = container_of(gc, struct tca6424_chip, gpio_chip);
329         gpioPortNum = pin_num/8;
330         gpioPortPinNum= pin_num%8;
331         if((gpioPortNum>=TCA6424_PortNum)||(gpioPortPinNum>=portnum[gpioPortNum]))
332                 return;
333         Regaddr = TCA6424_OutputLevel_Reg+gpioPortNum;  
334         if(tca6424getbit(chip->gtca6424_struct.reg_direction[gpioPortNum],gpioPortPinNum)) // input state
335         {
336                 return;
337         }
338                 
339         #ifdef TCA6424_OUTREGLOCK
340         if (!mutex_trylock(&chip->outreglock))
341         {
342                 DBGERR("**%s[%d] Did not get the outreglock**\n",__FUNCTION__,__LINE__);
343                 return;
344         }
345         #endif
346         if(((chip->gtca6424_struct.reg_output[gpioPortNum]>>gpioPortPinNum)& 0x01) != val)
347         {
348                 if(val)
349                         reg_val = tca6424setbit(chip->gtca6424_struct.reg_output[gpioPortNum], gpioPortPinNum);
350                 else
351                         reg_val = tca6424clearbit(chip->gtca6424_struct.reg_output[gpioPortNum], gpioPortPinNum);
352
353                 ret = tca6424_write_reg(chip->client, Regaddr, reg_val);
354                 if (ret<0)
355                         goto err;
356                 chip->gtca6424_struct.reg_output[gpioPortNum] = reg_val;
357                 //DBG("**%s[%d],set output address[0x%2x]=%2x,ret=%d**\n",__FUNCTION__,__LINE__,Regaddr,reg_val,ret);
358         }
359 err: 
360         #ifdef TCA6424_OUTREGLOCK
361                 mutex_unlock(&chip->outreglock);
362         #endif
363         return;
364 }
365
366 int tca6424_checkrange(int start,int num,int val)
367 {   
368         if((val<(start+num))&&(val>=start))
369                 return 0;
370         else 
371                 return -1;
372 }
373
374 static int tca6424_gpio_to_irq(struct gpio_chip *chip,unsigned offset)
375 {
376     struct tca6424_chip *pchip = container_of(chip, struct tca6424_chip, gpio_chip);
377         if(((pchip->gpio_start+offset)>=chip->base)&&((pchip->gpio_start+offset)<(chip->base+chip->ngpio)))
378         {
379                 //DBG("**%s,offset=%d,gpio_irq_start=%d,base=%d,ngpio=%d,gpio_irq_start=%d**\n",
380                 //      __FUNCTION__,offset,pchip->expand->gpio_irq_start,chip->base,chip->ngpio,pchip->expand->gpio_irq_start);
381                 return (offset+pchip->expand->gpio_irq_start);
382         }
383         else
384         {
385                 return -1;
386         }
387 }
388
389 static void tca6424_setup_gpio(struct tca6424_chip *chip, int gpios)
390 {
391     struct gpio_chip *gc;
392     gc = &chip->gpio_chip;
393     gc->direction_input  = tca6424_gpio_direction_input;
394     gc->direction_output = tca6424_gpio_direction_output;
395     gc->get = tca6424_gpio_get_value;
396     gc->set = tca6424_gpio_set_value;
397     gc->to_irq = tca6424_gpio_to_irq;
398     gc->can_sleep = 1;
399     gc->base = chip->gpio_start;
400     gc->ngpio = chip->gpio_pin_num;
401     gc->label = chip->client->name;
402     gc->dev = &chip->client->dev;
403     gc->owner = THIS_MODULE;
404     gc->names = chip->names;
405 }
406
407 int tca6424_init_pintype(struct tca6424_chip *chip,struct i2c_client *client)
408 {
409         struct tca6424_platform_data *platform_data=(struct tca6424_platform_data *)client->dev.platform_data;
410         struct rk2818_gpio_expander_info *tca6424_gpio_settinginfo;
411         uint8_t reg_output[TCA6424_PortNum]={0,0,0};
412         uint8_t reg_direction[TCA6424_PortNum]={0,0,0};
413         uint8_t reg_invert[TCA6424_PortNum]={0,0,0};
414         uint8_t tca6424_pin_num;
415         uint8_t gpioPortNum;
416         uint8_t gpioPortPinNum,tca6424_settingpin_num=0;
417         int i = 0;
418         if(platform_data)
419         {
420                 tca6424_gpio_settinginfo=platform_data->settinginfo;
421                 if(tca6424_gpio_settinginfo)
422                 {
423                         tca6424_settingpin_num=platform_data->settinginfolen;
424                         for(i=0;i<tca6424_settingpin_num;i++)
425                         {
426                                 if(!tca6424_checkrange(chip->gpio_start,chip->gpio_pin_num,tca6424_gpio_settinginfo[i].gpio_num))
427                                 {
428                                         tca6424_pin_num=tca6424_gpio_settinginfo[i].gpio_num-chip->gpio_start;
429                                         gpioPortNum = tca6424_pin_num/ TCA6424_PortPinNum;
430                                         gpioPortPinNum= tca6424_pin_num% TCA6424_PortPinNum;
431                                         //DBG("gpioPortNum=%d,gpioPortNum=%d,tca6424_pin_num=%d,reg_direction=%x,reg_output=%x,reg_input=%x\n",gpioPortNum,gpioPortPinNum,tca6424_pin_num,reg_direction[i],reg_output[i]);
432                                         if((gpioPortNum>=TCA6424_PortNum)||(gpioPortPinNum>=portnum[gpioPortNum]))
433                                                 continue;
434                                         if(tca6424_gpio_settinginfo[i].pin_type==GPIO_IN)
435                                         {
436                                                 reg_direction[gpioPortNum]=tca6424setbit(reg_direction[gpioPortNum],gpioPortPinNum);
437                                         }
438                                         else
439                                         {
440                                                 if(tca6424_gpio_settinginfo[i].pin_value==GPIO_HIGH)
441                                                 {
442                                                         reg_output[gpioPortNum]=tca6424setbit(reg_output[gpioPortNum],gpioPortPinNum);
443                                                 }
444                                         }
445                                         
446                                 }
447                         }
448                 }
449         }
450         #ifdef TCA6424_OUTREGLOCK
451         mutex_init(&chip->outreglock);
452     #endif 
453         #ifdef TCA6424_INPUTREGLOCK
454         mutex_init(&chip->inputreglock);
455         #endif
456         #ifdef TCA6424_OUTREGLOCK
457         mutex_init(&chip->configreglock);
458         #endif
459
460         if(tca6424_write_three_reg(client, TCA6424_Auto_Config_Reg , &reg_direction[0], 3, TCA6424_I2C_RATE)<0)
461         {
462                 DBGERR("*%s %d* write reg err\n",__FUNCTION__,__LINE__);
463                 return -1;
464         }
465         if (tca6424_write_three_reg(client, TCA6424_Auto_OutputLevel_Reg, &reg_output[0], 3, TCA6424_I2C_RATE)<0)
466         {
467                 DBGERR("*%s %d* write reg err\n",__FUNCTION__,__LINE__);
468                 return -1;
469         }
470         if (tca6424_write_three_reg(client, TCA6424_Auto_Invert_Reg, &reg_invert[0], 3, TCA6424_I2C_RATE)<0)            //make sure this reg be 0
471         {
472                 DBGERR("*%s %d* write reg err\n",__FUNCTION__,__LINE__);
473                 return -1;
474         }
475         if(tca6424_read_three_reg(client, TCA6424_Auto_InputLevel_Reg, &chip->gtca6424_struct.reg_input[0], 3, TCA6424_I2C_RATE)<0)
476         {
477                 DBGERR("*%s %d  read reg err*\n",__FUNCTION__,__LINE__);
478                 return -1;
479         }         
480         for(i=0; i<TCA6424_PortNum; i++)
481         {
482                 chip->gtca6424_struct.reg_direction[i]=reg_direction[i];
483                 chip->gtca6424_struct.reg_output[i]=reg_output[i];
484                 DBG("reg_direction=%x,reg_output=%x,reg_input=%x\n",chip->gtca6424_struct.reg_direction[i],chip->gtca6424_struct.reg_output[i],chip->gtca6424_struct.reg_input[i]);
485         }
486         return 0;
487 }
488
489 static int __devinit tca6424_probe(struct i2c_client *client,const struct i2c_device_id *id)
490 {
491         struct tca6424_chip *chip;
492         struct tca6424_platform_data  *pdata;
493         int ret;
494         DBG(KERN_ALERT"*******gpio %s in %d line,dev adr is %x**\n",__FUNCTION__,__LINE__,client->addr);
495         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
496                 return -EIO;
497
498         chip = kzalloc(sizeof(struct tca6424_chip), GFP_KERNEL);
499         if (chip == NULL)
500                 return -ENOMEM;
501         pdata = client->dev.platform_data;
502         if (pdata == NULL) {
503                 DBGERR(" %s no platform data\n",__FUNCTION__);
504                 ret = -EINVAL;
505                 goto out_failed;
506         }
507         //used by old tca6424,it will remove later
508         client->adapter->dev.platform_data = pdata;
509         
510         chip->gpio_start = pdata->gpio_base;
511         chip->gpio_pin_num=pdata->gpio_pin_num;
512         chip->client = client;
513         chip->names = pdata->names;
514
515         #ifdef CONFIG_EXPAND_GPIO_SOFT_INTERRUPT
516         chip->expand = &expand_irq_data;
517         chip->expand->gpio_irq_start =pdata->gpio_irq_start;
518         chip->expand->irq_pin_num = pdata->irq_pin_num;
519         chip->expand->irq_gpiopin=pdata->tca6424_irq_pin;
520         chip->expand->irq_chain = gpio_to_irq(pdata->tca6424_irq_pin);
521         chip->expand->expand_port_group   = pdata->expand_port_group;\r
522         chip->expand->expand_port_pinnum = pdata->expand_port_pinnum;\r
523         chip->expand->rk_irq_mode =  pdata->rk_irq_mode;\r
524         chip->expand->rk_irq_gpio_pull_up_down = pdata->rk_irq_gpio_pull_up_down;
525         #endif
526         
527         /* initialize cached registers from their original values.
528         * we can't share this chip with another i2c master.
529         */
530         tca6424_setup_gpio(chip, id->driver_data);
531         ret = gpiochip_add(&chip->gpio_chip);
532         if (ret)
533                 goto out_failed;
534         if(tca6424_init_pintype(chip,client))
535                 goto out_failed;
536         if (pdata->setup) {
537                 ret = pdata->setup(client, chip->gpio_chip.base,
538                                 chip->gpio_chip.ngpio, pdata->context);
539                 if (ret < 0)
540                         DBGERR(" %s setup failed, %d\n",__FUNCTION__,ret);
541         }
542         i2c_set_clientdata(client, chip);
543
544         #ifdef CONFIG_EXPAND_GPIO_SOFT_INTERRUPT
545         expand_irq_init(chip,&chip->gtca6424_struct,tca6424_irq_read_inputreg);
546         #endif
547         return 0;
548 out_failed:
549         kfree(chip);
550     return 0;
551 }
552
553 static int tca6424_remove(struct i2c_client *client)
554 {
555         struct tca6424_platform_data *pdata = client->dev.platform_data;
556         struct tca6424_chip *chip = i2c_get_clientdata(client);
557         int ret = 0;
558
559         if (pdata->teardown) {
560                 ret = pdata->teardown(client, chip->gpio_chip.base,
561                 chip->gpio_chip.ngpio, pdata->context);
562                 if (ret < 0) {
563                         DBGERR(" %s failed, %d\n",__FUNCTION__,ret);
564                         return ret;
565                 }
566         }
567
568         ret = gpiochip_remove(&chip->gpio_chip);
569         if (ret) {
570                 dev_err(&client->dev, "%s failed, %d\n",
571                 "gpiochip_remove()", ret);
572                 return ret;
573         }
574         kfree(chip);
575         return 0;
576 }
577
578 static int tca6424_suspend(struct i2c_client *client, pm_message_t mesg)
579 {
580         DBG("*****************tca6424 suspend*******************");
581         return 0;
582 }
583
584 static int tca6424_resume(struct i2c_client *client)
585 {
586         DBG("*****************tca6424 resume*******************");
587         return 0;
588 }
589
590 static struct i2c_driver tca6424_driver = {
591     .driver = {
592                 .owner  = THIS_MODULE,
593         .name   = "extend_gpio_tca6424",
594     },
595     .probe      = tca6424_probe,
596     .remove     = tca6424_remove,
597     .id_table   = tca6424_id,
598     .resume = tca6424_resume,
599     .suspend = tca6424_suspend,
600 };
601 static int __init tca6424_init(void)
602 {
603         int tmp;
604         DBG(KERN_ALERT"**********tca6424_init**********\n");
605         tmp=i2c_add_driver(&tca6424_driver);
606         return 0;
607 }
608 subsys_initcall(tca6424_init);
609
610 static void __exit tca6424_exit(void)
611 {
612     DBG(KERN_ALERT"**********tca6424_exit**********\n");
613         i2c_del_driver(&tca6424_driver);
614 }
615 module_exit(tca6424_exit);
616
617 MODULE_AUTHOR(" XXX  XXX@rock-chips.com");
618 MODULE_DESCRIPTION("Driver for rk2818 tca6424 device");
619 MODULE_LICENSE("GPL");
620