FROMLIST: clk: rockchip: add clock flag parameter when register pll
[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_year -= 1900;                    //inorder to cooperate the systerm time 
231         if(tm->tm_year < 0)
232                 tm->tm_year = 0;        
233         tm->tm_isdst = 0;       
234
235         pr_debug("%4d-%02d-%02d(%d) %02d:%02d:%02d\n",
236                 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, tm->tm_wday,
237                 tm->tm_hour, tm->tm_min, tm->tm_sec);
238
239         return 0;
240 }
241
242 static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
243 {
244         return hym8563_read_datetime(to_i2c_client(dev), tm);
245 }
246
247 static int hym8563_set_time(struct i2c_client *client, struct rtc_time *tm)     
248 {
249         struct hym8563 *hym8563 = i2c_get_clientdata(client);
250         u8 regs[HYM8563_RTC_SECTION_LEN] = { 0, };
251         u8 mon_day;
252         //u8 ret = 0;
253
254         pr_debug("%4d-%02d-%02d(%d) %02d:%02d:%02d\n",
255                 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, tm->tm_wday,
256                 tm->tm_hour, tm->tm_min, tm->tm_sec);
257
258         mon_day = rtc_month_days((tm->tm_mon), tm->tm_year + 1900);
259         
260         if(tm->tm_sec >= 60 || tm->tm_sec < 0 )         //set  sec
261                 regs[0x00] = bin2bcd(0x00);
262         else
263                 regs[0x00] = bin2bcd(tm->tm_sec);
264         
265         if(tm->tm_min >= 60 || tm->tm_min < 0 )         //set  min      
266                 regs[0x01] = bin2bcd(0x00);
267         else
268                 regs[0x01] = bin2bcd(tm->tm_min);
269
270         if(tm->tm_hour >= 24 || tm->tm_hour < 0 )               //set  hour
271                 regs[0x02] = bin2bcd(0x00);
272         else
273                 regs[0x02] = bin2bcd(tm->tm_hour);
274         
275         if((tm->tm_mday) > mon_day)                             //if the input month day is bigger than the biggest day of this month, set the biggest day 
276                 regs[0x03] = bin2bcd(mon_day);
277         else if((tm->tm_mday) > 0)
278                 regs[0x03] = bin2bcd(tm->tm_mday);
279         else if((tm->tm_mday) <= 0)
280                 regs[0x03] = bin2bcd(0x01);
281
282         if( tm->tm_year >= 200)         // year >= 2100
283                 regs[0x06] = bin2bcd(99);       //year = 2099
284         else if(tm->tm_year >= 100)                     // 2000 <= year < 2100
285                 regs[0x06] = bin2bcd(tm->tm_year - 100);
286         else if(tm->tm_year >= 0){                              // 1900 <= year < 2000
287                 regs[0x06] = bin2bcd(tm->tm_year);      
288                 regs[0x05] |= 0x80;     
289         }else{                                                                  // year < 1900
290                 regs[0x06] = bin2bcd(0);        //year = 1900   
291                 regs[0x05] |= 0x80;     
292         }       
293         regs[0x04] = bin2bcd(tm->tm_wday);              //set  the  weekday
294         regs[0x05] = (regs[0x05] & 0x80)| (bin2bcd(tm->tm_mon + 1) & 0x7F);             //set  the  month
295         
296         mutex_lock(&hym8563->mutex);
297 //      for(i=0;i<HYM8563_RTC_SECTION_LEN;i++){
298 //              ret = hym8563_i2c_set_regs(client, RTC_SEC+i, &regs[i], 1);
299 //      }
300         hym8563_i2c_set_regs(client, RTC_SEC, regs, HYM8563_RTC_SECTION_LEN);
301
302         mutex_unlock(&hym8563->mutex);
303
304         return 0;
305 }
306
307 static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
308 {
309         return hym8563_set_time(to_i2c_client(dev), tm);
310 }
311
312 static int hym8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
313 {
314         struct i2c_client *client = to_i2c_client(dev);
315         struct hym8563 *hym8563 = i2c_get_clientdata(client);
316         u8 regs[4] = { 0, };
317         
318         pr_debug("enter\n");
319         mutex_lock(&hym8563->mutex);
320         hym8563_i2c_read_regs(client, RTC_A_MIN, regs, 4);
321         regs[0] = 0x0;
322         regs[0] |= TIE;
323         hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
324         mutex_unlock(&hym8563->mutex);
325         return 0;
326 }
327
328 static int hym8563_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
329 {       
330         struct i2c_client *client = to_i2c_client(dev);
331         struct hym8563 *hym8563 = i2c_get_clientdata(client);
332         struct rtc_time now, *tm = &alarm->time;
333         u8 regs[4] = { 0, };
334         u8 mon_day;     
335         unsigned long   alarm_sec, now_sec;
336         int diff_sec = 0;
337         
338         pr_debug("%4d-%02d-%02d(%d) %02d:%02d:%02d enabled %d\n",
339                 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, tm->tm_wday,
340                 tm->tm_hour, tm->tm_min, tm->tm_sec, alarm->enabled);
341         
342         
343         hym8563_read_datetime(client, &now);
344
345         
346         mutex_lock(&hym8563->mutex);
347         rtc_tm_to_time(tm, &alarm_sec);
348         rtc_tm_to_time(&now, &now_sec);
349         
350         diff_sec = alarm_sec - now_sec;
351         
352         if((diff_sec > 0) && (diff_sec < 256))
353         {       
354                 printk("%s:diff_sec= %ds , use time\n",__func__, diff_sec);     
355                                                                 
356                 if (alarm->enabled == 1)
357                 {
358                         hym8563_set_count(client, diff_sec);
359                         hym8563_enable_count(client, 1);
360                 }
361                         
362                 else
363                 {
364                         hym8563_enable_count(client, 0);
365                 }
366                 
367         }
368         else
369         {                               
370                 printk("%s:diff_sec= %ds , use alarm\n",__func__, diff_sec);
371                 hym8563_enable_count(client, 0);
372                 
373                 if(tm->tm_sec > 0)
374                 {
375                         rtc_tm_to_time(tm, &alarm_sec);
376                         rtc_time_to_tm(alarm_sec, tm);
377                 }
378
379                 hym8563->alarm = *alarm;
380
381                 regs[0] = 0x0;
382                 hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
383                 mon_day = rtc_month_days(tm->tm_mon, tm->tm_year + 1900);
384                 hym8563_i2c_read_regs(client, RTC_A_MIN, regs, 4);
385
386                 if (tm->tm_min >= 60 || tm->tm_min < 0)         //set  min
387                 regs[0x00] = bin2bcd(0x00) & 0x7f;
388                 else
389                 regs[0x00] = bin2bcd(tm->tm_min) & 0x7f;
390                 if (tm->tm_hour >= 24 || tm->tm_hour < 0)       //set  hour
391                 regs[0x01] = bin2bcd(0x00) & 0x7f;
392                 else
393                 regs[0x01] = bin2bcd(tm->tm_hour) & 0x7f;
394                 regs[0x03] = bin2bcd (tm->tm_wday) & 0x7f;
395
396                 /* if the input month day is bigger than the biggest day of this month, set the biggest day */
397                 if (tm->tm_mday > mon_day)
398                 regs[0x02] = bin2bcd(mon_day) & 0x7f;
399                 else if (tm->tm_mday > 0)
400                 regs[0x02] = bin2bcd(tm->tm_mday) & 0x7f;
401                 else if (tm->tm_mday <= 0)
402                 regs[0x02] = bin2bcd(0x01) & 0x7f;
403
404                 hym8563_i2c_set_regs(client, RTC_A_MIN, regs, 4);       
405                 hym8563_i2c_read_regs(client, RTC_A_MIN, regs, 4);      
406                 hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
407                 if (alarm->enabled == 1)
408                 regs[0] |= AIE;
409                 else
410                 regs[0] &= 0x0;
411                 hym8563_i2c_set_regs(client, RTC_CTL2, regs, 1);
412                 hym8563_i2c_read_regs(client, RTC_CTL2, regs, 1);
413
414                 if(diff_sec <= 0)
415                 {               
416                         pr_info("alarm sec  <= now sec\n");
417                 }                       
418
419         }
420         
421         mutex_unlock(&hym8563->mutex);
422
423         return 0;
424 }
425 #ifdef CONFIG_HDMI_SAVE_DATA
426 int hdmi_get_data(void)
427 {
428     u8 regs=0;
429     if(gClient)
430         hym8563_i2c_read_regs(gClient, RTC_T_COUNT, &regs, 1);
431     else 
432     {
433         printk("%s rtc has no init\n",__func__);
434         return -1;
435     }
436     if(regs==0 || regs==0xff){
437         printk("%s rtc has no hdmi data\n",__func__);
438         return -1;
439     }
440     return (regs-1);
441 }
442
443 int hdmi_set_data(int data)
444 {
445     u8 regs = (data+1)&0xff;
446     if(gClient)
447         hym8563_i2c_set_regs(gClient, RTC_T_COUNT, &regs, 1);
448     else 
449     {
450         printk("%s rtc has no init\n",__func__);
451         return -1;
452     }   
453     return 0;
454 }
455
456 EXPORT_SYMBOL(hdmi_get_data);
457 EXPORT_SYMBOL(hdmi_set_data);
458 #endif
459 #if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
460 static int hym8563_i2c_open_alarm(struct i2c_client *client)
461 {
462         u8 data;        
463         hym8563_i2c_read_regs(client, RTC_CTL2, &data, 1);
464         data |= AIE;
465         hym8563_i2c_set_regs(client, RTC_CTL2, &data, 1);
466
467         return 0;
468 }
469
470 static int hym8563_i2c_close_alarm(struct i2c_client *client)
471 {
472         u8 data;        
473         hym8563_i2c_read_regs(client, RTC_CTL2, &data, 1);
474         data &= ~AIE;
475         hym8563_i2c_set_regs(client, RTC_CTL2, &data, 1);
476
477         return 0;
478 }
479
480 static int hym8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
481 {
482         struct i2c_client *client = to_i2c_client(dev);
483         
484         switch (cmd) {
485         case RTC_AIE_OFF:
486                 if(hym8563_i2c_close_alarm(client) < 0)
487                         goto err;
488                 break;
489         case RTC_AIE_ON:
490                 if(hym8563_i2c_open_alarm(client))
491                         goto err;
492                 break;
493         default:
494                 return -ENOIOCTLCMD;
495         }       
496         return 0;
497 err:
498         return -EIO;
499 }
500 #else
501 #define hym8563_rtc_ioctl NULL
502 #endif
503
504 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
505 static int hym8563_rtc_proc(struct device *dev, struct seq_file *seq)
506 {
507         return 0;
508 }
509 #else
510 #define hym8563_rtc_proc NULL
511 #endif
512
513 static irqreturn_t hym8563_wakeup_irq(int irq, void *data)
514 {
515         struct hym8563 *hym8563 = data; 
516         struct i2c_client *client = hym8563->client;    
517         u8 value;
518         
519         mutex_lock(&hym8563->mutex);
520         hym8563_i2c_read_regs(client, RTC_CTL2, &value, 1);
521         value &= ~(AF|TF);
522         hym8563_i2c_set_regs(client, RTC_CTL2, &value, 1);      
523         mutex_unlock(&hym8563->mutex);
524         
525         rtc_update_irq(hym8563->rtc, 1, RTC_IRQF | RTC_AF | RTC_UF);
526
527         //printk("%s:irq=%d\n",__func__,irq);
528         return IRQ_HANDLED;
529 }
530
531 static const struct rtc_class_ops hym8563_rtc_ops = {
532         .read_time      = hym8563_rtc_read_time,
533         .set_time       = hym8563_rtc_set_time,
534         .read_alarm     = hym8563_rtc_read_alarm,
535         .set_alarm      = hym8563_rtc_set_alarm,
536         .ioctl          = hym8563_rtc_ioctl,
537         .proc           = hym8563_rtc_proc
538 };
539
540 static int  hym8563_probe(struct i2c_client *client, const struct i2c_device_id *id)
541 {
542         int rc = 0;
543         u8 reg = 0;
544         struct hym8563 *hym8563;
545         struct rtc_device *rtc = NULL;
546         struct rtc_time tm_read, tm = {
547                 .tm_wday = 6,
548                 .tm_year = 111,
549                 .tm_mon = 0,
550                 .tm_mday = 1,
551                 .tm_hour = 12,
552                 .tm_min = 0,
553                 .tm_sec = 0,
554         };      
555
556         struct device_node *np = client->dev.of_node;
557         unsigned long irq_flags;
558         int result;
559         
560         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
561                 return -ENODEV;
562                 
563         hym8563 = devm_kzalloc(&client->dev,sizeof(*hym8563), GFP_KERNEL);
564         if (!hym8563) {
565                 return -ENOMEM;
566         }
567
568         gClient = client;       
569         hym8563->client = client;
570         hym8563->alarm.enabled = 0;
571         client->irq = 0;
572         mutex_init(&hym8563->mutex);
573         wake_lock_init(&hym8563->wake_lock, WAKE_LOCK_SUSPEND, "rtc_hym8563");
574         i2c_set_clientdata(client, hym8563);
575
576         hym8563_init_device(client);    
577         hym8563_enable_count(client, 0);        
578         
579         // check power down 
580         hym8563_i2c_read_regs(client,RTC_SEC,&reg,1);
581         if (reg&0x80) {
582                 dev_info(&client->dev, "clock/calendar information is no longer guaranteed\n");
583                 hym8563_set_time(client, &tm);
584         }
585
586         hym8563_read_datetime(client, &tm_read);        //read time from hym8563
587         
588         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
589         {
590                 hym8563_set_time(client, &tm);  //initialize the hym8563 
591         }       
592         
593         client->irq = of_get_named_gpio_flags(np, "irq_gpio", 0,(enum of_gpio_flags *)&irq_flags);
594         if(client->irq >= 0)
595         {
596                 hym8563->irq = gpio_to_irq(client->irq);
597                 result = devm_request_threaded_irq(&client->dev, hym8563->irq, NULL, hym8563_wakeup_irq, irq_flags | IRQF_ONESHOT, client->dev.driver->name,hym8563 );
598                 if (result) {
599                         printk(KERN_ERR "%s:fail to request irq = %d, ret = 0x%x\n",__func__, hym8563->irq, result);
600                         goto exit;
601                 }
602                 enable_irq_wake(hym8563->irq);
603                 device_init_wakeup(&client->dev, 1);
604         }
605         rtc = devm_rtc_device_register(&client->dev,
606                         client->name,
607                         &hym8563_rtc_ops, THIS_MODULE);
608         if (IS_ERR(rtc)) {
609                 rc = PTR_ERR(rtc);
610                 rtc = NULL;
611                 goto exit;
612         }
613         hym8563->rtc = rtc;
614
615         return 0;
616
617 exit:
618         if (hym8563) {
619                 wake_lock_destroy(&hym8563->wake_lock);
620         }
621         return rc;
622 }
623
624 static int  hym8563_remove(struct i2c_client *client)
625 {
626         struct hym8563 *hym8563 = i2c_get_clientdata(client);
627
628         wake_lock_destroy(&hym8563->wake_lock);
629
630         return 0;
631 }
632
633
634 void hym8563_shutdown(struct i2c_client * client)
635 {       u8 regs[2];     
636     int ret;    
637     //disable clkout    
638     regs[0] = 0x00;     
639     ret=hym8563_i2c_set_regs(client, RTC_CLKOUT, regs, 1);      
640     if(ret<0)   
641         printk("rtc shutdown is error\n");
642 }
643
644
645
646 static const struct i2c_device_id hym8563_id[] = {
647         { "rtc_hym8563", 0 },
648         { }
649 };
650 MODULE_DEVICE_TABLE(i2c, hym8563_id);
651
652 static struct of_device_id rtc_dt_ids[] = {
653         { .compatible = "rtc,hym8563" },
654         {},
655 };
656
657 struct i2c_driver hym8563_driver = {
658         .driver         = {
659                 .name   = "rtc_hym8563",
660                 .owner  = THIS_MODULE,
661                 .of_match_table = of_match_ptr(rtc_dt_ids),
662         },
663         .probe          = hym8563_probe,
664         .remove         = hym8563_remove,
665         //.shutdown=hym8563_shutdown,
666         .id_table       = hym8563_id,
667 };
668
669 static int __init hym8563_init(void)
670 {
671         return i2c_add_driver(&hym8563_driver);
672 }
673
674 static void __exit hym8563_exit(void)
675 {
676         i2c_del_driver(&hym8563_driver);
677 }
678
679 MODULE_AUTHOR("lhh lhh@rock-chips.com");
680 MODULE_DESCRIPTION("HYM8563 RTC driver");
681 MODULE_LICENSE("GPL");
682
683 module_init(hym8563_init);
684 module_exit(hym8563_exit);
685