2 drivers/rtc/rtc-isl1208.c | 357 +++++++++++++++++++++-------------------------
3 1 file changed, 170 insertions(+), 187 deletions(-)
5 Index: linux-2.6.24-arm/drivers/rtc/rtc-isl1208.c
6 ===================================================================
7 --- linux-2.6.24-arm.orig/drivers/rtc/rtc-isl1208.c 2008-02-01 13:33:11.000000000 +1030
8 +++ linux-2.6.24-arm/drivers/rtc/rtc-isl1208.c 2008-02-01 13:36:24.000000000 +1030
10 #include <linux/bcd.h>
11 #include <linux/rtc.h>
13 -#define DRV_NAME "isl1208"
14 -#define DRV_VERSION "0.2"
15 +#define DRV_VERSION "0.3"
19 #define ISL1208_REG_SC 0x00
20 #define ISL1208_REG_MN 0x01
21 #define ISL1208_REG_HR 0x02
22 -#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */
23 -#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
24 +#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */
25 +#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
26 #define ISL1208_REG_DT 0x03
27 #define ISL1208_REG_MO 0x04
28 #define ISL1208_REG_YR 0x05
31 /* control/status section */
32 #define ISL1208_REG_SR 0x07
33 -#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */
34 -#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */
35 -#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */
36 -#define ISL1208_REG_SR_ALM (1<<2) /* alarm */
37 -#define ISL1208_REG_SR_BAT (1<<1) /* battery */
38 -#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */
39 +#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */
40 +#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */
41 +#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */
42 +#define ISL1208_REG_SR_ALM (1<<2) /* alarm */
43 +#define ISL1208_REG_SR_BAT (1<<1) /* battery */
44 +#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */
45 #define ISL1208_REG_INT 0x08
46 -#define ISL1208_REG_09 0x09 /* reserved */
47 +#define ISL1208_REG_09 0x09 /* reserved */
48 #define ISL1208_REG_ATR 0x0a
49 #define ISL1208_REG_DTR 0x0b
52 #define ISL1208_REG_USR2 0x13
53 #define ISL1208_USR_SECTION_LEN 2
55 -/* i2c configuration */
56 -#define ISL1208_I2C_ADDR 0xde
58 -static unsigned short normal_i2c[] = {
59 - ISL1208_I2C_ADDR>>1, I2C_CLIENT_END
61 -I2C_CLIENT_INSMOD; /* defines addr_data */
63 -static int isl1208_attach_adapter(struct i2c_adapter *adapter);
64 -static int isl1208_detach_client(struct i2c_client *client);
66 -static struct i2c_driver isl1208_driver = {
70 - .id = I2C_DRIVERID_ISL1208,
71 - .attach_adapter = &isl1208_attach_adapter,
72 - .detach_client = &isl1208_detach_client,
74 +static struct i2c_driver isl1208_driver;
78 isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
82 u8 reg_addr[1] = { reg };
83 struct i2c_msg msgs[2] = {
84 - { client->addr, client->flags, sizeof(reg_addr), reg_addr },
85 - { client->addr, client->flags | I2C_M_RD, len, buf }
86 + {client->addr, client->flags, sizeof(reg_addr), reg_addr}
88 + {client->addr, client->flags | I2C_M_RD, len, buf}
95 isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
99 u8 i2c_buf[ISL1208_REG_USR2 + 2];
100 struct i2c_msg msgs[1] = {
101 - { client->addr, client->flags, len + 1, i2c_buf }
102 + {client->addr, client->flags, len + 1, i2c_buf}
107 BUG_ON(reg > ISL1208_REG_USR2);
108 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
113 /* simple check to see wether we have a isl1208 */
114 -static int isl1208_i2c_validate_client(struct i2c_client *client)
116 +isl1208_i2c_validate_client(struct i2c_client *client)
118 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
119 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
120 @@ -139,24 +121,29 @@
123 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
124 - if (regs[i] & zero_mask[i]) /* check if bits are cleared */
125 + if (regs[i] & zero_mask[i]) /* check if bits are cleared */
132 -static int isl1208_i2c_get_sr(struct i2c_client *client)
134 +isl1208_i2c_get_sr(struct i2c_client *client)
136 - return i2c_smbus_read_byte_data(client, ISL1208_REG_SR) == -1 ? -EIO:0;
137 + int sr = i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
144 -static int isl1208_i2c_get_atr(struct i2c_client *client)
146 +isl1208_i2c_get_atr(struct i2c_client *client)
148 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
154 /* The 6bit value in the ATR register controls the load
155 * capacitance C_load * in steps of 0.25pF
156 @@ -169,51 +156,54 @@
160 - atr &= 0x3f; /* mask out lsb */
161 - atr ^= 1<<5; /* invert 6th bit */
162 - atr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
163 + atr &= 0x3f; /* mask out lsb */
164 + atr ^= 1 << 5; /* invert 6th bit */
165 + atr += 2 * 9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
170 -static int isl1208_i2c_get_dtr(struct i2c_client *client)
172 +isl1208_i2c_get_dtr(struct i2c_client *client)
174 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
179 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
180 - dtr = ((dtr & 0x3) * 20) * (dtr & (1<<2) ? -1 : 1);
181 + dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
186 -static int isl1208_i2c_get_usr(struct i2c_client *client)
188 +isl1208_i2c_get_usr(struct i2c_client *client)
190 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
193 - ret = isl1208_i2c_read_regs (client, ISL1208_REG_USR1, buf,
194 - ISL1208_USR_SECTION_LEN);
195 + ret = isl1208_i2c_read_regs(client, ISL1208_REG_USR1, buf,
196 + ISL1208_USR_SECTION_LEN);
200 return (buf[1] << 8) | buf[0];
203 -static int isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
205 +isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
207 u8 buf[ISL1208_USR_SECTION_LEN];
210 buf[1] = (usr >> 8) & 0xff;
212 - return isl1208_i2c_set_regs (client, ISL1208_REG_USR1, buf,
213 - ISL1208_USR_SECTION_LEN);
214 + return isl1208_i2c_set_regs(client, ISL1208_REG_USR1, buf,
215 + ISL1208_USR_SECTION_LEN);
218 -static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
220 +isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
222 struct i2c_client *const client = to_i2c_client(dev);
223 int sr, dtr, atr, usr;
224 @@ -230,20 +220,19 @@
225 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
226 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
227 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
228 - (sr & ISL1208_REG_SR_ARST) ? " ARST" : "",
230 + (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", sr);
232 seq_printf(seq, "batt_status\t: %s\n",
233 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
235 dtr = isl1208_i2c_get_dtr(client);
238 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr);
240 atr = isl1208_i2c_get_atr(client);
242 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
243 - atr>>2, (atr&0x3)*25);
244 + atr >> 2, (atr & 0x3) * 25);
246 usr = isl1208_i2c_get_usr(client);
253 -static int isl1208_i2c_read_time(struct i2c_client *client,
254 - struct rtc_time *tm)
256 +isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
259 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
260 @@ -274,27 +262,30 @@
262 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]);
263 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]);
264 - { /* HR field has a more complex interpretation */
266 + /* HR field has a more complex interpretation */
268 const u8 _hr = regs[ISL1208_REG_HR];
269 - if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
270 + if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
271 tm->tm_hour = BCD2BIN(_hr & 0x3f);
272 - else { // 12h format
275 tm->tm_hour = BCD2BIN(_hr & 0x1f);
276 - if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
277 + if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
282 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]);
283 - tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
284 + tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
285 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100;
286 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]);
291 -static int isl1208_i2c_read_alarm(struct i2c_client *client,
292 - struct rtc_wkalrm *alarm)
294 +isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
296 struct rtc_time *const tm = &alarm->time;
297 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
301 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
302 - ISL1208_ALARM_SECTION_LEN);
303 + ISL1208_ALARM_SECTION_LEN);
305 dev_err(&client->dev, "%s: reading alarm section failed\n",
307 @@ -315,23 +306,25 @@
310 /* MSB of each alarm register is an enable bit */
311 - tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA-ISL1208_REG_SCA] & 0x7f);
312 - tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA-ISL1208_REG_SCA] & 0x7f);
313 - tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA-ISL1208_REG_SCA] & 0x3f);
314 - tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA-ISL1208_REG_SCA] & 0x3f);
315 - tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MOA-ISL1208_REG_SCA] & 0x1f)-1;
316 - tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA-ISL1208_REG_SCA] & 0x03);
317 + tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
318 + tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
319 + tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
320 + tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
322 + BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
323 + tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
328 -static int isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
330 +isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
332 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
335 -static int isl1208_i2c_set_time(struct i2c_client *client,
336 - struct rtc_time const *tm)
338 +isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
341 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
346 - sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
347 + sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
348 sr | ISL1208_REG_SR_WRTC);
350 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
354 /* clear WRTC again */
355 - sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
356 + sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
357 sr & ~ISL1208_REG_SR_WRTC);
359 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
360 @@ -380,70 +373,69 @@
364 -static int isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
366 +isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
368 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
371 -static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
373 +isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
375 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
378 static const struct rtc_class_ops isl1208_rtc_ops = {
379 - .proc = isl1208_rtc_proc,
380 - .read_time = isl1208_rtc_read_time,
381 - .set_time = isl1208_rtc_set_time,
382 - .read_alarm = isl1208_rtc_read_alarm,
383 - //.set_alarm = isl1208_rtc_set_alarm,
384 + .proc = isl1208_rtc_proc,
385 + .read_time = isl1208_rtc_read_time,
386 + .set_time = isl1208_rtc_set_time,
387 + .read_alarm = isl1208_rtc_read_alarm,
388 + /*.set_alarm = isl1208_rtc_set_alarm, */
391 /* sysfs interface */
393 -static ssize_t isl1208_sysfs_show_atrim(struct device *dev,
394 - struct device_attribute *attr,
397 +isl1208_sysfs_show_atrim(struct device *dev,
398 + struct device_attribute *attr, char *buf)
402 - atr = isl1208_i2c_get_atr(to_i2c_client(dev));
403 + int atr = isl1208_i2c_get_atr(to_i2c_client(dev));
407 - return sprintf(buf, "%d.%.2d pF\n", atr>>2, (atr&0x3)*25);
408 + return sprintf(buf, "%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
411 static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
413 -static ssize_t isl1208_sysfs_show_dtrim(struct device *dev,
414 - struct device_attribute *attr,
417 +isl1208_sysfs_show_dtrim(struct device *dev,
418 + struct device_attribute *attr, char *buf)
422 - dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
423 + int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
427 return sprintf(buf, "%d ppm\n", dtr);
430 static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
432 -static ssize_t isl1208_sysfs_show_usr(struct device *dev,
433 - struct device_attribute *attr,
436 +isl1208_sysfs_show_usr(struct device *dev,
437 + struct device_attribute *attr, char *buf)
441 - usr = isl1208_i2c_get_usr(to_i2c_client(dev));
442 + int usr = isl1208_i2c_get_usr(to_i2c_client(dev));
446 return sprintf(buf, "0x%.4x\n", usr);
449 -static ssize_t isl1208_sysfs_store_usr(struct device *dev,
450 - struct device_attribute *attr,
451 - const char *buf, size_t count)
453 +isl1208_sysfs_store_usr(struct device *dev,
454 + struct device_attribute *attr,
455 + const char *buf, size_t count)
459 @@ -460,124 +452,116 @@
461 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
464 static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
465 isl1208_sysfs_store_usr);
468 -isl1208_probe(struct i2c_adapter *adapter, int addr, int kind)
469 +isl1208_sysfs_register(struct device *dev)
472 - struct i2c_client *new_client = NULL;
473 - struct rtc_device *rtc = NULL;
476 + err = device_create_file(dev, &dev_attr_atrim);
480 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
483 + err = device_create_file(dev, &dev_attr_dtrim);
485 + device_remove_file(dev, &dev_attr_atrim);
489 - new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
490 - if (new_client == NULL) {
493 + err = device_create_file(dev, &dev_attr_usr);
495 + device_remove_file(dev, &dev_attr_atrim);
496 + device_remove_file(dev, &dev_attr_dtrim);
499 - new_client->addr = addr;
500 - new_client->adapter = adapter;
501 - new_client->driver = &isl1208_driver;
502 - new_client->flags = 0;
503 - strcpy(new_client->name, DRV_NAME);
508 - rc = isl1208_i2c_validate_client(new_client);
513 +isl1208_sysfs_unregister(struct device *dev)
515 + device_remove_file(dev, &dev_attr_atrim);
516 + device_remove_file(dev, &dev_attr_atrim);
517 + device_remove_file(dev, &dev_attr_usr);
523 +isl1208_probe(struct i2c_client *client)
526 + struct rtc_device *rtc;
528 - rc = i2c_attach_client(new_client);
531 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
534 - dev_info(&new_client->dev,
535 + if (isl1208_i2c_validate_client(client) < 0)
538 + dev_info(&client->dev,
539 "chip found, driver version " DRV_VERSION "\n");
541 rtc = rtc_device_register(isl1208_driver.driver.name,
543 - &isl1208_rtc_ops, THIS_MODULE);
547 - goto failout_detach;
549 + &client->dev, &isl1208_rtc_ops,
552 + return PTR_ERR(rtc);
554 - i2c_set_clientdata(new_client, rtc);
555 + i2c_set_clientdata(client, rtc);
557 - rc = isl1208_i2c_get_sr(new_client);
558 + rc = isl1208_i2c_get_sr(client);
560 - dev_err(&new_client->dev, "reading status failed\n");
561 - goto failout_unregister;
562 + dev_err(&client->dev, "reading status failed\n");
563 + goto exit_unregister;
566 if (rc & ISL1208_REG_SR_RTCF)
567 - dev_warn(&new_client->dev, "rtc power failure detected, "
568 + dev_warn(&client->dev, "rtc power failure detected, "
569 "please set clock.\n");
571 - rc = device_create_file(&new_client->dev, &dev_attr_atrim);
573 - goto failout_unregister;
574 - rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
576 - goto failout_atrim;
577 - rc = device_create_file(&new_client->dev, &dev_attr_usr);
579 - goto failout_dtrim;
580 + rc = isl1208_sysfs_register(&client->dev);
582 + goto exit_unregister;
587 - device_remove_file(&new_client->dev, &dev_attr_dtrim);
589 - device_remove_file(&new_client->dev, &dev_attr_atrim);
590 - failout_unregister:
592 rtc_device_unregister(rtc);
594 - i2c_detach_client(new_client);
601 -isl1208_attach_adapter (struct i2c_adapter *adapter)
603 - return i2c_probe(adapter, &addr_data, isl1208_probe);
608 -isl1208_detach_client(struct i2c_client *client)
609 +isl1208_remove(struct i2c_client *client)
612 - struct rtc_device *const rtc = i2c_get_clientdata(client);
615 - rtc_device_unregister(rtc); /* do we need to kfree? */
617 - rc = i2c_detach_client(client);
620 + struct rtc_device *rtc = i2c_get_clientdata(client);
623 + isl1208_sysfs_unregister(&client->dev);
624 + rtc_device_unregister(rtc);
629 -/* module management */
630 +static struct i2c_driver isl1208_driver = {
632 + .name = "rtc-isl1208",
634 + .probe = isl1208_probe,
635 + .remove = isl1208_remove,
638 -static int __init isl1208_init(void)
642 return i2c_add_driver(&isl1208_driver);
645 -static void __exit isl1208_exit(void)
649 i2c_del_driver(&isl1208_driver);
652 drivers/rtc/rtc-pcf8563.c | 109 +++++++++++++---------------------------------
653 1 file changed, 32 insertions(+), 77 deletions(-)
655 Index: linux-2.6.24-armeb/drivers/rtc/rtc-pcf8563.c
656 ===================================================================
657 --- linux-2.6.24-armeb.orig/drivers/rtc/rtc-pcf8563.c 2008-01-30 13:50:01.000000000 +1030
658 +++ linux-2.6.24-armeb/drivers/rtc/rtc-pcf8563.c 2008-01-30 13:51:55.000000000 +1030
660 #include <linux/bcd.h>
661 #include <linux/rtc.h>
663 -#define DRV_VERSION "0.4.2"
665 -/* Addresses to scan: none
666 - * This chip cannot be reliably autodetected. An empty eeprom
667 - * located at 0x51 will pass the validation routine due to
668 - * the way the registers are implemented.
670 -static unsigned short normal_i2c[] = { I2C_CLIENT_END };
672 -/* Module parameters */
674 +#define DRV_VERSION "0.4.3"
676 #define PCF8563_REG_ST1 0x00 /* status */
677 #define PCF8563_REG_ST2 0x01
679 #define PCF8563_SC_LV 0x80 /* low voltage */
680 #define PCF8563_MO_C 0x80 /* century */
682 +static struct i2c_driver pcf8563_driver;
685 - struct i2c_client client;
686 + struct rtc_device *rtc;
688 * The meaning of MO_C bit varies by the chip type.
689 * From PCF8563 datasheet: this bit is toggled when the years
691 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
694 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
695 -static int pcf8563_detach(struct i2c_client *client);
698 * In the routines that deal directly with the pcf8563 hardware, we use
699 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
701 static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
703 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
704 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
705 unsigned char buf[13] = { PCF8563_REG_ST1 };
707 struct i2c_msg msgs[] = {
710 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
712 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
713 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
715 unsigned char buf[9];
717 @@ -257,100 +246,66 @@
718 .set_time = pcf8563_rtc_set_time,
721 -static int pcf8563_attach(struct i2c_adapter *adapter)
723 - return i2c_probe(adapter, &addr_data, pcf8563_probe);
726 -static struct i2c_driver pcf8563_driver = {
730 - .id = I2C_DRIVERID_PCF8563,
731 - .attach_adapter = &pcf8563_attach,
732 - .detach_client = &pcf8563_detach,
735 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
736 +static int pcf8563_probe(struct i2c_client *client)
738 struct pcf8563 *pcf8563;
739 - struct i2c_client *client;
740 - struct rtc_device *rtc;
744 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
745 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
747 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
751 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
754 - if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) {
759 - client = &pcf8563->client;
760 - client->addr = address;
761 - client->driver = &pcf8563_driver;
762 - client->adapter = adapter;
764 - strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
765 + if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL)))
768 /* Verify the chip is really an PCF8563 */
770 - if (pcf8563_validate_client(client) < 0) {
776 - /* Inform the i2c layer */
777 - if ((err = i2c_attach_client(client)))
778 + if (pcf8563_validate_client(client) < 0) {
783 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
785 - rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
786 + pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
787 &pcf8563_rtc_ops, THIS_MODULE);
790 - err = PTR_ERR(rtc);
792 + if (IS_ERR(pcf8563->rtc)) {
793 + err = PTR_ERR(pcf8563->rtc);
797 - i2c_set_clientdata(client, rtc);
798 + i2c_set_clientdata(client, pcf8563);
803 - i2c_detach_client(client);
812 -static int pcf8563_detach(struct i2c_client *client)
813 +static int pcf8563_remove(struct i2c_client *client)
815 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
817 - struct rtc_device *rtc = i2c_get_clientdata(client);
818 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
821 - rtc_device_unregister(rtc);
823 - if ((err = i2c_detach_client(client)))
826 + rtc_device_unregister(pcf8563->rtc);
833 +static struct i2c_driver pcf8563_driver = {
835 + .name = "rtc-pcf8563",
837 + .probe = pcf8563_probe,
838 + .remove = pcf8563_remove,
841 static int __init pcf8563_init(void)
843 return i2c_add_driver(&pcf8563_driver);
845 drivers/rtc/rtc-x1205.c | 128 ++++++++++++++++--------------------------------
846 1 file changed, 43 insertions(+), 85 deletions(-)
848 Index: linux-2.6.24-armeb/drivers/rtc/rtc-x1205.c
849 ===================================================================
850 --- linux-2.6.24-armeb.orig/drivers/rtc/rtc-x1205.c 2008-01-30 13:50:44.000000000 +1030
851 +++ linux-2.6.24-armeb/drivers/rtc/rtc-x1205.c 2008-01-30 13:51:35.000000000 +1030
853 #include <linux/rtc.h>
854 #include <linux/delay.h>
856 -#define DRV_VERSION "1.0.7"
858 -/* Addresses to scan: none. This chip is located at
859 - * 0x6f and uses a two bytes register addressing.
860 - * Two bytes need to be written to read a single register,
861 - * while most other chips just require one and take the second
862 - * one as the data to be written. To prevent corrupting
863 - * unknown chips, the user must explicitly set the probe parameter.
866 -static unsigned short normal_i2c[] = { I2C_CLIENT_END };
868 -/* Insmod parameters */
870 +#define DRV_VERSION "1.0.8"
872 /* offsets into CCR area */
876 #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
879 -static int x1205_attach(struct i2c_adapter *adapter);
880 -static int x1205_detach(struct i2c_client *client);
881 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
883 -static struct i2c_driver x1205_driver = {
887 - .id = I2C_DRIVERID_X1205,
888 - .attach_adapter = &x1205_attach,
889 - .detach_client = &x1205_detach,
891 +static struct i2c_driver x1205_driver;
894 * In the routines that deal directly with the x1205 hardware, we use
895 @@ -497,58 +472,51 @@
897 static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
899 -static int x1205_attach(struct i2c_adapter *adapter)
900 +static int x1205_sysfs_register(struct device *dev)
904 + err = device_create_file(dev, &dev_attr_atrim);
908 + err = device_create_file(dev, &dev_attr_dtrim);
910 + device_remove_file(dev, &dev_attr_atrim);
915 +static void x1205_sysfs_unregister(struct device *dev)
917 - return i2c_probe(adapter, &addr_data, x1205_probe);
918 + device_remove_file(dev, &dev_attr_atrim);
919 + device_remove_file(dev, &dev_attr_dtrim);
922 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
924 +static int x1205_probe(struct i2c_client *client)
928 - struct i2c_client *client;
929 struct rtc_device *rtc;
931 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
932 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
934 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
937 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
941 - if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
944 + if (x1205_validate_client(client) < 0) {
949 - client->addr = address;
950 - client->driver = &x1205_driver;
951 - client->adapter = adapter;
953 - strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE);
955 - /* Verify the chip is really an X1205 */
957 - if (x1205_validate_client(client) < 0) {
963 - /* Inform the i2c layer */
964 - if ((err = i2c_attach_client(client)))
967 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
969 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
970 &x1205_rtc_ops, THIS_MODULE);
973 - err = PTR_ERR(rtc);
977 + return PTR_ERR(rtc);
979 i2c_set_clientdata(client, rtc);
981 @@ -565,45 +533,35 @@
983 dev_err(&client->dev, "couldn't read status\n");
985 - err = device_create_file(&client->dev, &dev_attr_atrim);
986 - if (err) goto exit_devreg;
987 - err = device_create_file(&client->dev, &dev_attr_dtrim);
988 - if (err) goto exit_atrim;
989 + err = x1205_sysfs_register(&client->dev);
996 - device_remove_file(&client->dev, &dev_attr_atrim);
999 rtc_device_unregister(rtc);
1002 - i2c_detach_client(client);
1011 -static int x1205_detach(struct i2c_client *client)
1012 +static int x1205_remove(struct i2c_client *client)
1015 struct rtc_device *rtc = i2c_get_clientdata(client);
1018 - rtc_device_unregister(rtc);
1020 - if ((err = i2c_detach_client(client)))
1025 + rtc_device_unregister(rtc);
1026 + x1205_sysfs_unregister(&client->dev);
1030 +static struct i2c_driver x1205_driver = {
1032 + .name = "rtc-x1205",
1034 + .probe = x1205_probe,
1035 + .remove = x1205_remove,
1038 static int __init x1205_init(void)
1040 return i2c_add_driver(&x1205_driver);