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