Merge remote-tracking branch 'origin/develop-3.10' into develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / drivers / rtc / rtc-HYM8563.c
1 /* drivers/rtc/rtc-HYM8563.c - driver for HYM8563
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 //#define DEBUG
16 #define pr_fmt(fmt) "rtc: %s: " fmt, __func__
17
18 #include <linux/module.h>
19 #include <linux/i2c.h>
20 #include <linux/bcd.h>
21 #include <linux/rtc.h>
22 #include <linux/delay.h>
23 #include <linux/wakelock.h>
24 #include <linux/slab.h>
25 #include "rtc-HYM8563.h"
26 #include <linux/of_gpio.h>
27 #include <linux/irqdomain.h>
28 #define RTC_SPEED       200 * 1000
29
30 struct hym8563 {
31         int irq;
32         struct i2c_client *client;
33         struct mutex mutex;
34         struct rtc_device *rtc;
35         struct rtc_wkalrm alarm;
36         struct wake_lock wake_lock;
37 };
38 static struct i2c_client *gClient = NULL;
39
40 static int i2c_master_reg8_send(const struct i2c_client *client, const char reg, const char *buf, int count, int scl_rate)
41 {
42         struct i2c_adapter *adap=client->adapter;
43         struct i2c_msg msg;
44         int ret;
45         char *tx_buf = (char *)kzalloc(count + 1, GFP_KERNEL);
46         if(!tx_buf)
47                 return -ENOMEM;
48         tx_buf[0] = reg;
49         memcpy(tx_buf+1, buf, count); 
50
51         msg.addr = client->addr;
52         msg.flags = client->flags;
53         msg.len = count + 1;
54         msg.buf = (char *)tx_buf;
55         msg.scl_rate = scl_rate;
56
57         ret = i2c_transfer(adap, &msg, 1);
58         kfree(tx_buf);
59         return (ret == 1) ? count : ret;
60
61 }
62
63 static int i2c_master_reg8_recv(const struct i2c_client *client, const char reg, char *buf, int count, int scl_rate)
64 {
65         struct i2c_adapter *adap=client->adapter;
66         struct i2c_msg msgs[2];
67         int ret;
68         char reg_buf = reg;
69         
70         msgs[0].addr = client->addr;
71         msgs[0].flags = client->flags;
72         msgs[0].len = 1;
73         msgs[0].buf = &reg_buf;
74         msgs[0].scl_rate = scl_rate;
75
76         msgs[1].addr = client->addr;
77         msgs[1].flags = client->flags | I2C_M_RD;
78         msgs[1].len = count;
79         msgs[1].buf = (char *)buf;
80         msgs[1].scl_rate = scl_rate;
81
82         ret = i2c_transfer(adap, msgs, 2);
83
84         return (ret == 2)? count : ret;
85 }
86
87
88
89 static int hym8563_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], unsigned len)
90 {
91         int ret; 
92         ret = i2c_master_reg8_recv(client, reg, buf, len, RTC_SPEED);
93         return ret; 
94 }
95
96 static int hym8563_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], __u16 len)
97 {
98         int ret; 
99         ret = i2c_master_reg8_send(client, reg, buf, (int)len, RTC_SPEED);
100         return ret;
101 }
102
103
104 int hym8563_enable_count(struct i2c_client *client, int en)
105 {
106         struct hym8563 *hym8563 = i2c_get_clientdata(client);   
107         u8 regs[2];
108
109         if (!hym8563)
110                 return -1;
111
112         if (en) {
113                 hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
114                 regs[0] |= TIE;
115                 hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
116                 regs[0] = 0;
117                 regs[0] |= (TE | TD1);
118                 hym8563_i2c_set_regs(client, RTC_T_CTL, regs, 1);
119         }
120         else {
121                 hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
122                 regs[0] &= ~TIE;
123                 hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
124                 regs[0] = 0;
125                 regs[0] |= (TD0 | TD1);
126                 hym8563_i2c_set_regs(client, RTC_T_CTL, regs, 1);
127         }
128         return 0;
129 }
130
131 //0 < sec <=255
132 int hym8563_set_count(struct i2c_client *client, int sec)
133 {       
134         struct hym8563 *hym8563 = i2c_get_clientdata(client);
135         u8 regs[2];
136
137         if (!hym8563)
138                 return -1;
139                 
140         if (sec >= 255)
141                 regs[0] = 255;
142         else if (sec <= 1)
143                 regs[0] = 1;
144         else
145                 regs[0] = sec;
146         
147         hym8563_i2c_set_regs(client, RTC_T_COUNT, regs, 1);
148         
149         return 0;
150 }
151
152
153 /*the init of the hym8563 at first time */
154 static int hym8563_init_device(struct i2c_client *client)       
155 {
156         struct hym8563 *hym8563 = i2c_get_clientdata(client);
157         u8 regs[2];
158         int sr;
159
160         mutex_lock(&hym8563->mutex);
161         regs[0]=0;
162         sr = hym8563_i2c_set_regs(client, RTC_CTL1, regs, 1);           
163         if (sr < 0)
164                 goto exit;
165         
166         //disable clkout
167         regs[0] = 0x80;
168         sr = hym8563_i2c_set_regs(client, RTC_CLKOUT, regs, 1);
169         if (sr < 0)
170                 goto exit;
171
172         /*enable alarm && count interrupt*/
173         sr = hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
174         if (sr < 0)
175                 goto exit;
176         regs[0] = 0x0;
177         regs[0] |= (AIE | TIE);
178         sr = hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
179         if (sr < 0)
180                 goto exit;
181         sr = hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
182         if (sr < 0)
183                 goto exit;
184
185         sr = hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
186         if (sr < 0) {
187                 pr_err("read CTL2 err\n");
188                 goto exit;
189         }
190         
191         if(regs[0] & (AF|TF))
192         {
193                 regs[0] &= ~(AF|TF);
194                 sr = hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
195         }
196         
197 exit:
198         mutex_unlock(&hym8563->mutex);
199         
200         return sr;
201 }
202
203 static int hym8563_read_datetime(struct i2c_client *client, struct rtc_time *tm)
204 {
205         struct hym8563 *hym8563 = i2c_get_clientdata(client);
206         u8 regs[HYM8563_RTC_SECTION_LEN] = { 0, };
207         mutex_lock(&hym8563->mutex);
208 //      for (i = 0; i < HYM8563_RTC_SECTION_LEN; i++) {
209 //              hym8563_i2c_read_regs(client, RTC_SEC+i, &regs[i], 1);
210 //      }
211         hym8563_i2c_read_regs(client, RTC_SEC, regs, HYM8563_RTC_SECTION_LEN);
212
213         mutex_unlock(&hym8563->mutex);
214         
215         tm->tm_sec = bcd2bin(regs[0x00] & 0x7F);
216         tm->tm_min = bcd2bin(regs[0x01] & 0x7F);
217         tm->tm_hour = bcd2bin(regs[0x02] & 0x3F);
218         tm->tm_mday = bcd2bin(regs[0x03] & 0x3F);
219         tm->tm_wday = bcd2bin(regs[0x04] & 0x07);       
220         
221         tm->tm_mon = bcd2bin(regs[0x05] & 0x1F) ; 
222         tm->tm_mon -= 1;                        //inorder to cooperate the systerm time
223         
224         tm->tm_year = bcd2bin(regs[0x06] & 0xFF);
225         if(regs[5] & 0x80)
226                 tm->tm_year += 1900;
227         else
228                 tm->tm_year += 2000;
229                 
230         tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);      
231         tm->tm_year -= 1900;                    //inorder to cooperate the systerm time 
232         if(tm->tm_year < 0)
233                 tm->tm_year = 0;        
234         tm->tm_isdst = 0;       
235
236         pr_debug("%4d-%02d-%02d(%d) %02d:%02d:%02d\n",
237                 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, tm->tm_wday,
238                 tm->tm_hour, tm->tm_min, tm->tm_sec);
239
240         return 0;
241 }
242
243 static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
244 {
245         return hym8563_read_datetime(to_i2c_client(dev), tm);
246 }
247
248 static int hym8563_set_time(struct i2c_client *client, struct rtc_time *tm)     
249 {
250         struct hym8563 *hym8563 = i2c_get_clientdata(client);
251         u8 regs[HYM8563_RTC_SECTION_LEN] = { 0, };
252         u8 mon_day;
253         //u8 ret = 0;
254
255         pr_debug("%4d-%02d-%02d(%d) %02d:%02d:%02d\n",
256                 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, tm->tm_wday,
257                 tm->tm_hour, tm->tm_min, tm->tm_sec);
258
259         mon_day = rtc_month_days((tm->tm_mon), tm->tm_year + 1900);
260         
261         if(tm->tm_sec >= 60 || tm->tm_sec < 0 )         //set  sec
262                 regs[0x00] = bin2bcd(0x00);
263         else
264                 regs[0x00] = bin2bcd(tm->tm_sec);
265         
266         if(tm->tm_min >= 60 || tm->tm_min < 0 )         //set  min      
267                 regs[0x01] = bin2bcd(0x00);
268         else
269                 regs[0x01] = bin2bcd(tm->tm_min);
270
271         if(tm->tm_hour >= 24 || tm->tm_hour < 0 )               //set  hour
272                 regs[0x02] = bin2bcd(0x00);
273         else
274                 regs[0x02] = bin2bcd(tm->tm_hour);
275         
276         if((tm->tm_mday) > mon_day)                             //if the input month day is bigger than the biggest day of this month, set the biggest day 
277                 regs[0x03] = bin2bcd(mon_day);
278         else if((tm->tm_mday) > 0)
279                 regs[0x03] = bin2bcd(tm->tm_mday);
280         else if((tm->tm_mday) <= 0)
281                 regs[0x03] = bin2bcd(0x01);
282
283         if( tm->tm_year >= 200)         // year >= 2100
284                 regs[0x06] = bin2bcd(99);       //year = 2099
285         else if(tm->tm_year >= 100)                     // 2000 <= year < 2100
286                 regs[0x06] = bin2bcd(tm->tm_year - 100);
287         else if(tm->tm_year >= 0){                              // 1900 <= year < 2000
288                 regs[0x06] = bin2bcd(tm->tm_year);      
289                 regs[0x05] |= 0x80;     
290         }else{                                                                  // year < 1900
291                 regs[0x06] = bin2bcd(0);        //year = 1900   
292                 regs[0x05] |= 0x80;     
293         }       
294         regs[0x04] = bin2bcd(tm->tm_wday);              //set  the  weekday
295         regs[0x05] = (regs[0x05] & 0x80)| (bin2bcd(tm->tm_mon + 1) & 0x7F);             //set  the  month
296         
297         mutex_lock(&hym8563->mutex);
298 //      for(i=0;i<HYM8563_RTC_SECTION_LEN;i++){
299 //              ret = hym8563_i2c_set_regs(client, RTC_SEC+i, &regs[i], 1);
300 //      }
301         hym8563_i2c_set_regs(client, RTC_SEC, regs, HYM8563_RTC_SECTION_LEN);
302
303         mutex_unlock(&hym8563->mutex);
304
305         return 0;
306 }
307
308 static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
309 {
310         return hym8563_set_time(to_i2c_client(dev), tm);
311 }
312
313 static int hym8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
314 {
315         struct i2c_client *client = to_i2c_client(dev);
316         struct hym8563 *hym8563 = i2c_get_clientdata(client);
317         u8 regs[4] = { 0, };
318         
319         pr_debug("enter\n");
320         mutex_lock(&hym8563->mutex);
321         hym8563_i2c_read_regs(client, RTC_A_MIN, regs, 4);
322         regs[0] = 0x0;
323         regs[0] |= TIE;
324         hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
325         mutex_unlock(&hym8563->mutex);
326         return 0;
327 }
328
329 static int hym8563_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
330 {       
331         struct i2c_client *client = to_i2c_client(dev);
332         struct hym8563 *hym8563 = i2c_get_clientdata(client);
333         struct rtc_time now, *tm = &alarm->time;
334         u8 regs[4] = { 0, };
335         u8 mon_day;     
336         unsigned long   alarm_sec, now_sec;
337         int diff_sec = 0;
338         
339         pr_debug("%4d-%02d-%02d(%d) %02d:%02d:%02d enabled %d\n",
340                 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, tm->tm_wday,
341                 tm->tm_hour, tm->tm_min, tm->tm_sec, alarm->enabled);
342         
343         
344         hym8563_read_datetime(client, &now);
345
346         
347         mutex_lock(&hym8563->mutex);
348         rtc_tm_to_time(tm, &alarm_sec);
349         rtc_tm_to_time(&now, &now_sec);
350         
351         diff_sec = alarm_sec - now_sec;
352         
353         if((diff_sec > 0) && (diff_sec < 256))
354         {       
355                 printk("%s:diff_sec= %ds , use time\n",__func__, diff_sec);     
356                                                                 
357                 if (alarm->enabled == 1)
358                 {
359                         hym8563_set_count(client, diff_sec);
360                         hym8563_enable_count(client, 1);
361                 }
362                         
363                 else
364                 {
365                         hym8563_enable_count(client, 0);
366                 }
367                 
368         }
369         else
370         {                               
371                 printk("%s:diff_sec= %ds , use alarm\n",__func__, diff_sec);
372                 hym8563_enable_count(client, 0);
373                 
374                 if(tm->tm_sec > 0)
375                 {
376                         rtc_tm_to_time(tm, &alarm_sec);
377                         rtc_time_to_tm(alarm_sec, tm);
378                 }
379
380                 hym8563->alarm = *alarm;
381
382                 regs[0] = 0x0;
383                 hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
384                 mon_day = rtc_month_days(tm->tm_mon, tm->tm_year + 1900);
385                 hym8563_i2c_read_regs(client, RTC_A_MIN, regs, 4);
386
387                 if (tm->tm_min >= 60 || tm->tm_min < 0)         //set  min
388                 regs[0x00] = bin2bcd(0x00) & 0x7f;
389                 else
390                 regs[0x00] = bin2bcd(tm->tm_min) & 0x7f;
391                 if (tm->tm_hour >= 24 || tm->tm_hour < 0)       //set  hour
392                 regs[0x01] = bin2bcd(0x00) & 0x7f;
393                 else
394                 regs[0x01] = bin2bcd(tm->tm_hour) & 0x7f;
395                 regs[0x03] = bin2bcd (tm->tm_wday) & 0x7f;
396
397                 /* if the input month day is bigger than the biggest day of this month, set the biggest day */
398                 if (tm->tm_mday > mon_day)
399                 regs[0x02] = bin2bcd(mon_day) & 0x7f;
400                 else if (tm->tm_mday > 0)
401                 regs[0x02] = bin2bcd(tm->tm_mday) & 0x7f;
402                 else if (tm->tm_mday <= 0)
403                 regs[0x02] = bin2bcd(0x01) & 0x7f;
404
405                 hym8563_i2c_set_regs(client, RTC_A_MIN, regs, 4);       
406                 hym8563_i2c_read_regs(client, RTC_A_MIN, regs, 4);      
407                 hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
408                 if (alarm->enabled == 1)
409                 regs[0] |= AIE;
410                 else
411                 regs[0] &= 0x0;
412                 hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
413                 hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
414
415                 if(diff_sec <= 0)
416                 {               
417                         pr_info("alarm sec  <= now sec\n");
418                 }                       
419
420         }
421         
422         mutex_unlock(&hym8563->mutex);
423
424         return 0;
425 }
426 #ifdef CONFIG_HDMI_SAVE_DATA
427 int hdmi_get_data(void)
428 {
429     u8 regs=0;
430     if(gClient)
431         hym8563_i2c_read_regs(gClient, RTC_T_COUNT, &regs, 1);
432     else 
433     {
434         printk("%s rtc has no init\n",__func__);
435         return -1;
436     }
437     if(regs==0 || regs==0xff){
438         printk("%s rtc has no hdmi data\n",__func__);
439         return -1;
440     }
441     return (regs-1);
442 }
443
444 int hdmi_set_data(int data)
445 {
446     u8 regs = (data+1)&0xff;
447     if(gClient)
448         hym8563_i2c_set_regs(gClient, RTC_T_COUNT, &regs, 1);
449     else 
450     {
451         printk("%s rtc has no init\n",__func__);
452         return -1;
453     }   
454     return 0;
455 }
456
457 EXPORT_SYMBOL(hdmi_get_data);
458 EXPORT_SYMBOL(hdmi_set_data);
459 #endif
460 #if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
461 static int hym8563_i2c_open_alarm(struct i2c_client *client)
462 {
463         u8 data;        
464         hym8563_i2c_read_regs(client, RTC_CTL2, &data, 1);
465         data |= AIE;
466         hym8563_i2c_set_regs(client, RTC_CTL2, &data, 1);
467
468         return 0;
469 }
470
471 static int hym8563_i2c_close_alarm(struct i2c_client *client)
472 {
473         u8 data;        
474         hym8563_i2c_read_regs(client, RTC_CTL2, &data, 1);
475         data &= ~AIE;
476         hym8563_i2c_set_regs(client, RTC_CTL2, &data, 1);
477
478         return 0;
479 }
480
481 static int hym8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
482 {
483         struct i2c_client *client = to_i2c_client(dev);
484         
485         switch (cmd) {
486         case RTC_AIE_OFF:
487                 if(hym8563_i2c_close_alarm(client) < 0)
488                         goto err;
489                 break;
490         case RTC_AIE_ON:
491                 if(hym8563_i2c_open_alarm(client))
492                         goto err;
493                 break;
494         default:
495                 return -ENOIOCTLCMD;
496         }       
497         return 0;
498 err:
499         return -EIO;
500 }
501 #else
502 #define hym8563_rtc_ioctl NULL
503 #endif
504
505 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
506 static int hym8563_rtc_proc(struct device *dev, struct seq_file *seq)
507 {
508         return 0;
509 }
510 #else
511 #define hym8563_rtc_proc NULL
512 #endif
513
514 static irqreturn_t hym8563_wakeup_irq(int irq, void *data)
515 {
516         struct hym8563 *hym8563 = data; 
517         struct i2c_client *client = hym8563->client;    
518         u8 value;
519         
520         mutex_lock(&hym8563->mutex);
521         hym8563_i2c_read_regs(client, RTC_CTL2, &value, 1);
522         value &= ~(AF|TF);
523         hym8563_i2c_set_regs(client, RTC_CTL2, &value, 1);      
524         mutex_unlock(&hym8563->mutex);
525         
526         rtc_update_irq(hym8563->rtc, 1, RTC_IRQF | RTC_AF | RTC_UF);
527
528         //printk("%s:irq=%d\n",__func__,irq);
529         return IRQ_HANDLED;
530 }
531
532 static const struct rtc_class_ops hym8563_rtc_ops = {
533         .read_time      = hym8563_rtc_read_time,
534         .set_time       = hym8563_rtc_set_time,
535         .read_alarm     = hym8563_rtc_read_alarm,
536         .set_alarm      = hym8563_rtc_set_alarm,
537         .ioctl          = hym8563_rtc_ioctl,
538         .proc           = hym8563_rtc_proc
539 };
540
541 static int  hym8563_probe(struct i2c_client *client, const struct i2c_device_id *id)
542 {
543         int rc = 0;
544         u8 reg = 0;
545         struct hym8563 *hym8563;
546         struct rtc_device *rtc = NULL;
547         struct rtc_time tm_read, tm = {
548                 .tm_wday = 6,
549                 .tm_year = 111,
550                 .tm_mon = 0,
551                 .tm_mday = 1,
552                 .tm_hour = 12,
553                 .tm_min = 0,
554                 .tm_sec = 0,
555         };      
556
557         struct device_node *np = client->dev.of_node;
558         unsigned long irq_flags;
559         int result;
560         
561         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
562                 return -ENODEV;
563                 
564         hym8563 = devm_kzalloc(&client->dev,sizeof(*hym8563), GFP_KERNEL);
565         if (!hym8563) {
566                 return -ENOMEM;
567         }
568
569         gClient = client;       
570         hym8563->client = client;
571         hym8563->alarm.enabled = 0;
572         client->irq = 0;
573         mutex_init(&hym8563->mutex);
574         wake_lock_init(&hym8563->wake_lock, WAKE_LOCK_SUSPEND, "rtc_hym8563");
575         i2c_set_clientdata(client, hym8563);
576
577         hym8563_init_device(client);    
578         hym8563_enable_count(client, 0);        
579         
580         // check power down 
581         hym8563_i2c_read_regs(client,RTC_SEC,&reg,1);
582         if (reg&0x80) {
583                 dev_info(&client->dev, "clock/calendar information is no longer guaranteed\n");
584                 hym8563_set_time(client, &tm);
585         }
586
587         hym8563_read_datetime(client, &tm_read);        //read time from hym8563
588         
589         if(((tm_read.tm_year < 70) | (tm_read.tm_year > 137 )) | (tm_read.tm_mon == -1) | (rtc_valid_tm(&tm_read) != 0)) //if the hym8563 haven't initialized
590         {
591                 hym8563_set_time(client, &tm);  //initialize the hym8563 
592         }       
593         
594         client->irq = of_get_named_gpio_flags(np, "irq_gpio", 0,(enum of_gpio_flags *)&irq_flags);
595         if(client->irq >= 0)
596         {
597                 hym8563->irq = gpio_to_irq(client->irq);
598                 result = devm_request_threaded_irq(&client->dev, hym8563->irq, NULL, hym8563_wakeup_irq, irq_flags | IRQF_ONESHOT, client->dev.driver->name,hym8563 );
599                 if (result) {
600                         printk(KERN_ERR "%s:fail to request irq = %d, ret = 0x%x\n",__func__, hym8563->irq, result);
601                         goto exit;
602                 }
603                 enable_irq_wake(hym8563->irq);
604                 device_init_wakeup(&client->dev, 1);
605         }
606         rtc = devm_rtc_device_register(&client->dev,
607                         client->name,
608                         &hym8563_rtc_ops, THIS_MODULE);
609         if (IS_ERR(rtc)) {
610                 rc = PTR_ERR(rtc);
611                 rtc = NULL;
612                 goto exit;
613         }
614         hym8563->rtc = rtc;
615
616         return 0;
617
618 exit:
619         if (hym8563) {
620                 wake_lock_destroy(&hym8563->wake_lock);
621         }
622         return rc;
623 }
624
625 static int  hym8563_remove(struct i2c_client *client)
626 {
627         struct hym8563 *hym8563 = i2c_get_clientdata(client);
628
629         wake_lock_destroy(&hym8563->wake_lock);
630
631         return 0;
632 }
633
634
635 void hym8563_shutdown(struct i2c_client * client)
636 {       u8 regs[2];     
637     int ret;    
638     //disable clkout    
639     regs[0] = 0x00;     
640     ret=hym8563_i2c_set_regs(client, RTC_CLKOUT, regs, 1);      
641     if(ret<0)   
642         printk("rtc shutdown is error\n");
643 }
644
645
646
647 static const struct i2c_device_id hym8563_id[] = {
648         { "rtc_hym8563", 0 },
649         { }
650 };
651 MODULE_DEVICE_TABLE(i2c, hym8563_id);
652
653 static struct of_device_id rtc_dt_ids[] = {
654         { .compatible = "rtc,hym8563" },
655         {},
656 };
657
658 struct i2c_driver hym8563_driver = {
659         .driver         = {
660                 .name   = "rtc_hym8563",
661                 .owner  = THIS_MODULE,
662                 .of_match_table = of_match_ptr(rtc_dt_ids),
663         },
664         .probe          = hym8563_probe,
665         .remove         = hym8563_remove,
666         //.shutdown=hym8563_shutdown,
667         .id_table       = hym8563_id,
668 };
669
670 static int __init hym8563_init(void)
671 {
672         return i2c_add_driver(&hym8563_driver);
673 }
674
675 static void __exit hym8563_exit(void)
676 {
677         i2c_del_driver(&hym8563_driver);
678 }
679
680 MODULE_AUTHOR("lhh lhh@rock-chips.com");
681 MODULE_DESCRIPTION("HYM8563 RTC driver");
682 MODULE_LICENSE("GPL");
683
684 module_init(hym8563_init);
685 module_exit(hym8563_exit);
686