aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig5
-rw-r--r--drivers/rtc/rtc-at91rm9200.c12
-rw-r--r--drivers/rtc/rtc-at91sam9.c2
-rw-r--r--drivers/rtc/rtc-ds1302.c2
-rw-r--r--drivers/rtc/rtc-ds1511.c6
-rw-r--r--drivers/rtc/rtc-ds1672.c14
-rw-r--r--drivers/rtc/rtc-isl1208.c357
-rw-r--r--drivers/rtc/rtc-max6900.c6
-rw-r--r--drivers/rtc/rtc-max6902.c4
-rw-r--r--drivers/rtc/rtc-pcf8563.c126
-rw-r--r--drivers/rtc/rtc-pcf8583.c2
-rw-r--r--drivers/rtc/rtc-rs5c313.c4
-rw-r--r--drivers/rtc/rtc-rs5c372.c18
-rw-r--r--drivers/rtc/rtc-s3c.c6
-rw-r--r--drivers/rtc/rtc-sh.c2
-rw-r--r--drivers/rtc/rtc-sysfs.c12
-rw-r--r--drivers/rtc/rtc-test.c8
-rw-r--r--drivers/rtc/rtc-v3020.c4
-rw-r--r--drivers/rtc/rtc-x1205.c170
19 files changed, 330 insertions, 430 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 02a4c8cf2b2d..6cc2c0330230 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -20,10 +20,6 @@ menuconfig RTC_CLASS
20 20
21if RTC_CLASS 21if RTC_CLASS
22 22
23if GEN_RTC || RTC
24comment "Conflicting RTC option has been selected, check GEN_RTC and RTC"
25endif
26
27config RTC_HCTOSYS 23config RTC_HCTOSYS
28 bool "Set system time from RTC on startup and resume" 24 bool "Set system time from RTC on startup and resume"
29 depends on RTC_CLASS = y 25 depends on RTC_CLASS = y
@@ -304,6 +300,7 @@ comment "Platform RTC drivers"
304config RTC_DRV_CMOS 300config RTC_DRV_CMOS
305 tristate "PC-style 'CMOS'" 301 tristate "PC-style 'CMOS'"
306 depends on X86 || ALPHA || ARM || M32R || ATARI || PPC || MIPS 302 depends on X86 || ALPHA || ARM || M32R || ATARI || PPC || MIPS
303 default y if X86
307 help 304 help
308 Say "yes" here to get direct support for the real time clock 305 Say "yes" here to get direct support for the real time clock
309 found in every PC or ACPI-based system, and some other boards. 306 found in every PC or ACPI-based system, and some other boards.
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 52abffc86bcd..39e64ab1ecb7 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -83,7 +83,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
83 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 83 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
84 tm->tm_year = tm->tm_year - 1900; 84 tm->tm_year = tm->tm_year - 1900;
85 85
86 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 86 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
87 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 87 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
88 tm->tm_hour, tm->tm_min, tm->tm_sec); 88 tm->tm_hour, tm->tm_min, tm->tm_sec);
89 89
@@ -97,7 +97,7 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
97{ 97{
98 unsigned long cr; 98 unsigned long cr;
99 99
100 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 100 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
101 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 101 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
102 tm->tm_hour, tm->tm_min, tm->tm_sec); 102 tm->tm_hour, tm->tm_min, tm->tm_sec);
103 103
@@ -142,7 +142,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
142 alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM) 142 alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM)
143 ? 1 : 0; 143 ? 1 : 0;
144 144
145 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 145 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
146 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 146 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
147 tm->tm_hour, tm->tm_min, tm->tm_sec); 147 tm->tm_hour, tm->tm_min, tm->tm_sec);
148 148
@@ -178,7 +178,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
178 if (alrm->enabled) 178 if (alrm->enabled)
179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM); 179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
180 180
181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
183 tm.tm_min, tm.tm_sec); 183 tm.tm_min, tm.tm_sec);
184 184
@@ -193,7 +193,7 @@ static int at91_rtc_ioctl(struct device *dev, unsigned int cmd,
193{ 193{
194 int ret = 0; 194 int ret = 0;
195 195
196 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __FUNCTION__, cmd, arg); 196 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __func__, cmd, arg);
197 197
198 switch (cmd) { 198 switch (cmd) {
199 case RTC_AIE_OFF: /* alarm off */ 199 case RTC_AIE_OFF: /* alarm off */
@@ -265,7 +265,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
265 265
266 rtc_update_irq(rtc, 1, events); 266 rtc_update_irq(rtc, 1, events);
267 267
268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__, 268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __func__,
269 events >> 8, events & 0x000000FF); 269 events >> 8, events & 0x000000FF);
270 270
271 return IRQ_HANDLED; 271 return IRQ_HANDLED;
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 56728a2a3385..38d8742a4bdf 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -288,7 +288,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *_rtc)
288 288
289 rtc_update_irq(rtc->rtcdev, 1, events); 289 rtc_update_irq(rtc->rtcdev, 1, events);
290 290
291 pr_debug("%s: num=%ld, events=0x%02lx\n", __FUNCTION__, 291 pr_debug("%s: num=%ld, events=0x%02lx\n", __func__,
292 events >> 8, events & 0x000000FF); 292 events >> 8, events & 0x000000FF);
293 293
294 return IRQ_HANDLED; 294 return IRQ_HANDLED;
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index 7b002ceeaa7d..b9397818f73a 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -122,7 +122,7 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
122 122
123 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 123 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
124 "mday=%d, mon=%d, year=%d, wday=%d\n", 124 "mday=%d, mon=%d, year=%d, wday=%d\n",
125 __FUNCTION__, 125 __func__,
126 tm->tm_sec, tm->tm_min, tm->tm_hour, 126 tm->tm_sec, tm->tm_min, tm->tm_hour,
127 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); 127 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
128 128
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index d08912f18ddd..a83a40b3ebaa 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -181,8 +181,7 @@ ds1511_wdog_disable(void)
181 * stupidly, some callers call with year unmolested; 181 * stupidly, some callers call with year unmolested;
182 * and some call with year = year - 1900. thanks. 182 * and some call with year = year - 1900. thanks.
183 */ 183 */
184 int 184static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
185ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
186{ 185{
187 u8 mon, day, dow, hrs, min, sec, yrs, cen; 186 u8 mon, day, dow, hrs, min, sec, yrs, cen;
188 unsigned int flags; 187 unsigned int flags;
@@ -245,8 +244,7 @@ ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
245 return 0; 244 return 0;
246} 245}
247 246
248 int 247static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
249ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
250{ 248{
251 unsigned int century; 249 unsigned int century;
252 unsigned int flags; 250 unsigned int flags;
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index e0900ca678ec..6fa4556f5f5c 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -50,13 +50,13 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
50 50
51 /* read date registers */ 51 /* read date registers */
52 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 52 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
53 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 53 dev_err(&client->dev, "%s: read error\n", __func__);
54 return -EIO; 54 return -EIO;
55 } 55 }
56 56
57 dev_dbg(&client->dev, 57 dev_dbg(&client->dev,
58 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n", 58 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n",
59 __FUNCTION__, buf[0], buf[1], buf[2], buf[3]); 59 __func__, buf[0], buf[1], buf[2], buf[3]);
60 60
61 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; 61 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
62 62
@@ -64,7 +64,7 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
64 64
65 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 65 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
66 "mday=%d, mon=%d, year=%d, wday=%d\n", 66 "mday=%d, mon=%d, year=%d, wday=%d\n",
67 __FUNCTION__, tm->tm_sec, tm->tm_min, tm->tm_hour, 67 __func__, tm->tm_sec, tm->tm_min, tm->tm_hour,
68 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 68 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
69 69
70 return 0; 70 return 0;
@@ -84,7 +84,7 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
84 84
85 xfer = i2c_master_send(client, buf, 6); 85 xfer = i2c_master_send(client, buf, 6);
86 if (xfer != 6) { 86 if (xfer != 6) {
87 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer); 87 dev_err(&client->dev, "%s: send: %d\n", __func__, xfer);
88 return -EIO; 88 return -EIO;
89 } 89 }
90 90
@@ -98,7 +98,7 @@ static int ds1672_set_datetime(struct i2c_client *client, struct rtc_time *tm)
98 dev_dbg(&client->dev, 98 dev_dbg(&client->dev,
99 "%s: secs=%d, mins=%d, hours=%d, " 99 "%s: secs=%d, mins=%d, hours=%d, "
100 "mday=%d, mon=%d, year=%d, wday=%d\n", 100 "mday=%d, mon=%d, year=%d, wday=%d\n",
101 __FUNCTION__, 101 __func__,
102 tm->tm_sec, tm->tm_min, tm->tm_hour, 102 tm->tm_sec, tm->tm_min, tm->tm_hour,
103 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 103 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
104 104
@@ -133,7 +133,7 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
133 133
134 /* read control register */ 134 /* read control register */
135 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 135 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
136 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 136 dev_err(&client->dev, "%s: read error\n", __func__);
137 return -EIO; 137 return -EIO;
138 } 138 }
139 139
@@ -199,7 +199,7 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
199 struct i2c_client *client; 199 struct i2c_client *client;
200 struct rtc_device *rtc; 200 struct rtc_device *rtc;
201 201
202 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 202 dev_dbg(&adapter->dev, "%s\n", __func__);
203 203
204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
205 err = -ENODEV; 205 err = -ENODEV;
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index 725b0c73c333..fb15e3fb4ce2 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -15,16 +15,15 @@
15#include <linux/bcd.h> 15#include <linux/bcd.h>
16#include <linux/rtc.h> 16#include <linux/rtc.h>
17 17
18#define DRV_NAME "isl1208" 18#define DRV_VERSION "0.3"
19#define DRV_VERSION "0.2"
20 19
21/* Register map */ 20/* Register map */
22/* rtc section */ 21/* rtc section */
23#define ISL1208_REG_SC 0x00 22#define ISL1208_REG_SC 0x00
24#define ISL1208_REG_MN 0x01 23#define ISL1208_REG_MN 0x01
25#define ISL1208_REG_HR 0x02 24#define ISL1208_REG_HR 0x02
26#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */ 25#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */
27#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */ 26#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
28#define ISL1208_REG_DT 0x03 27#define ISL1208_REG_DT 0x03
29#define ISL1208_REG_MO 0x04 28#define ISL1208_REG_MO 0x04
30#define ISL1208_REG_YR 0x05 29#define ISL1208_REG_YR 0x05
@@ -33,14 +32,14 @@
33 32
34/* control/status section */ 33/* control/status section */
35#define ISL1208_REG_SR 0x07 34#define ISL1208_REG_SR 0x07
36#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */ 35#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */
37#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */ 36#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */
38#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */ 37#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */
39#define ISL1208_REG_SR_ALM (1<<2) /* alarm */ 38#define ISL1208_REG_SR_ALM (1<<2) /* alarm */
40#define ISL1208_REG_SR_BAT (1<<1) /* battery */ 39#define ISL1208_REG_SR_BAT (1<<1) /* battery */
41#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */ 40#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */
42#define ISL1208_REG_INT 0x08 41#define ISL1208_REG_INT 0x08
43#define ISL1208_REG_09 0x09 /* reserved */ 42#define ISL1208_REG_09 0x09 /* reserved */
44#define ISL1208_REG_ATR 0x0a 43#define ISL1208_REG_ATR 0x0a
45#define ISL1208_REG_DTR 0x0b 44#define ISL1208_REG_DTR 0x0b
46 45
@@ -58,39 +57,21 @@
58#define ISL1208_REG_USR2 0x13 57#define ISL1208_REG_USR2 0x13
59#define ISL1208_USR_SECTION_LEN 2 58#define ISL1208_USR_SECTION_LEN 2
60 59
61/* i2c configuration */ 60static struct i2c_driver isl1208_driver;
62#define ISL1208_I2C_ADDR 0xde
63
64static const unsigned short normal_i2c[] = {
65 ISL1208_I2C_ADDR>>1, I2C_CLIENT_END
66};
67I2C_CLIENT_INSMOD; /* defines addr_data */
68
69static int isl1208_attach_adapter(struct i2c_adapter *adapter);
70static int isl1208_detach_client(struct i2c_client *client);
71
72static struct i2c_driver isl1208_driver = {
73 .driver = {
74 .name = DRV_NAME,
75 },
76 .id = I2C_DRIVERID_ISL1208,
77 .attach_adapter = &isl1208_attach_adapter,
78 .detach_client = &isl1208_detach_client,
79};
80 61
81/* block read */ 62/* block read */
82static int 63static int
83isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], 64isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
84 unsigned len) 65 unsigned len)
85{ 66{
86 u8 reg_addr[1] = { reg }; 67 u8 reg_addr[1] = { reg };
87 struct i2c_msg msgs[2] = { 68 struct i2c_msg msgs[2] = {
88 { client->addr, client->flags, sizeof(reg_addr), reg_addr }, 69 {client->addr, 0, sizeof(reg_addr), reg_addr}
89 { client->addr, client->flags | I2C_M_RD, len, buf } 70 ,
71 {client->addr, I2C_M_RD, len, buf}
90 }; 72 };
91 int ret; 73 int ret;
92 74
93 BUG_ON(len == 0);
94 BUG_ON(reg > ISL1208_REG_USR2); 75 BUG_ON(reg > ISL1208_REG_USR2);
95 BUG_ON(reg + len > ISL1208_REG_USR2 + 1); 76 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
96 77
@@ -103,15 +84,14 @@ isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
103/* block write */ 84/* block write */
104static int 85static int
105isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], 86isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
106 unsigned len) 87 unsigned len)
107{ 88{
108 u8 i2c_buf[ISL1208_REG_USR2 + 2]; 89 u8 i2c_buf[ISL1208_REG_USR2 + 2];
109 struct i2c_msg msgs[1] = { 90 struct i2c_msg msgs[1] = {
110 { client->addr, client->flags, len + 1, i2c_buf } 91 {client->addr, 0, len + 1, i2c_buf}
111 }; 92 };
112 int ret; 93 int ret;
113 94
114 BUG_ON(len == 0);
115 BUG_ON(reg > ISL1208_REG_USR2); 95 BUG_ON(reg > ISL1208_REG_USR2);
116 BUG_ON(reg + len > ISL1208_REG_USR2 + 1); 96 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
117 97
@@ -125,7 +105,8 @@ isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
125} 105}
126 106
127/* simple check to see wether we have a isl1208 */ 107/* simple check to see wether we have a isl1208 */
128static int isl1208_i2c_validate_client(struct i2c_client *client) 108static int
109isl1208_i2c_validate_client(struct i2c_client *client)
129{ 110{
130 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 111 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
131 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = { 112 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
@@ -139,24 +120,29 @@ static int isl1208_i2c_validate_client(struct i2c_client *client)
139 return ret; 120 return ret;
140 121
141 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) { 122 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
142 if (regs[i] & zero_mask[i]) /* check if bits are cleared */ 123 if (regs[i] & zero_mask[i]) /* check if bits are cleared */
143 return -ENODEV; 124 return -ENODEV;
144 } 125 }
145 126
146 return 0; 127 return 0;
147} 128}
148 129
149static int isl1208_i2c_get_sr(struct i2c_client *client) 130static int
131isl1208_i2c_get_sr(struct i2c_client *client)
150{ 132{
151 return i2c_smbus_read_byte_data(client, ISL1208_REG_SR) == -1 ? -EIO:0; 133 int sr = i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
134 if (sr < 0)
135 return -EIO;
136
137 return sr;
152} 138}
153 139
154static int isl1208_i2c_get_atr(struct i2c_client *client) 140static int
141isl1208_i2c_get_atr(struct i2c_client *client)
155{ 142{
156 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR); 143 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
157
158 if (atr < 0) 144 if (atr < 0)
159 return -EIO; 145 return atr;
160 146
161 /* The 6bit value in the ATR register controls the load 147 /* The 6bit value in the ATR register controls the load
162 * capacitance C_load * in steps of 0.25pF 148 * capacitance C_load * in steps of 0.25pF
@@ -169,51 +155,54 @@ static int isl1208_i2c_get_atr(struct i2c_client *client)
169 * 155 *
170 */ 156 */
171 157
172 atr &= 0x3f; /* mask out lsb */ 158 atr &= 0x3f; /* mask out lsb */
173 atr ^= 1<<5; /* invert 6th bit */ 159 atr ^= 1 << 5; /* invert 6th bit */
174 atr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */ 160 atr += 2 * 9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
175 161
176 return atr; 162 return atr;
177} 163}
178 164
179static int isl1208_i2c_get_dtr(struct i2c_client *client) 165static int
166isl1208_i2c_get_dtr(struct i2c_client *client)
180{ 167{
181 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR); 168 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
182
183 if (dtr < 0) 169 if (dtr < 0)
184 return -EIO; 170 return -EIO;
185 171
186 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */ 172 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
187 dtr = ((dtr & 0x3) * 20) * (dtr & (1<<2) ? -1 : 1); 173 dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
188 174
189 return dtr; 175 return dtr;
190} 176}
191 177
192static int isl1208_i2c_get_usr(struct i2c_client *client) 178static int
179isl1208_i2c_get_usr(struct i2c_client *client)
193{ 180{
194 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, }; 181 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
195 int ret; 182 int ret;
196 183
197 ret = isl1208_i2c_read_regs (client, ISL1208_REG_USR1, buf, 184 ret = isl1208_i2c_read_regs(client, ISL1208_REG_USR1, buf,
198 ISL1208_USR_SECTION_LEN); 185 ISL1208_USR_SECTION_LEN);
199 if (ret < 0) 186 if (ret < 0)
200 return ret; 187 return ret;
201 188
202 return (buf[1] << 8) | buf[0]; 189 return (buf[1] << 8) | buf[0];
203} 190}
204 191
205static int isl1208_i2c_set_usr(struct i2c_client *client, u16 usr) 192static int
193isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
206{ 194{
207 u8 buf[ISL1208_USR_SECTION_LEN]; 195 u8 buf[ISL1208_USR_SECTION_LEN];
208 196
209 buf[0] = usr & 0xff; 197 buf[0] = usr & 0xff;
210 buf[1] = (usr >> 8) & 0xff; 198 buf[1] = (usr >> 8) & 0xff;
211 199
212 return isl1208_i2c_set_regs (client, ISL1208_REG_USR1, buf, 200 return isl1208_i2c_set_regs(client, ISL1208_REG_USR1, buf,
213 ISL1208_USR_SECTION_LEN); 201 ISL1208_USR_SECTION_LEN);
214} 202}
215 203
216static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq) 204static int
205isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
217{ 206{
218 struct i2c_client *const client = to_i2c_client(dev); 207 struct i2c_client *const client = to_i2c_client(dev);
219 int sr, dtr, atr, usr; 208 int sr, dtr, atr, usr;
@@ -230,20 +219,19 @@ static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
230 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "", 219 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
231 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "", 220 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
232 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "", 221 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
233 (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", 222 (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", sr);
234 sr);
235 223
236 seq_printf(seq, "batt_status\t: %s\n", 224 seq_printf(seq, "batt_status\t: %s\n",
237 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay"); 225 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
238 226
239 dtr = isl1208_i2c_get_dtr(client); 227 dtr = isl1208_i2c_get_dtr(client);
240 if (dtr >= 0 -1) 228 if (dtr >= 0 - 1)
241 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr); 229 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr);
242 230
243 atr = isl1208_i2c_get_atr(client); 231 atr = isl1208_i2c_get_atr(client);
244 if (atr >= 0) 232 if (atr >= 0)
245 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n", 233 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
246 atr>>2, (atr&0x3)*25); 234 atr >> 2, (atr & 0x3) * 25);
247 235
248 usr = isl1208_i2c_get_usr(client); 236 usr = isl1208_i2c_get_usr(client);
249 if (usr >= 0) 237 if (usr >= 0)
@@ -252,9 +240,8 @@ static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
252 return 0; 240 return 0;
253} 241}
254 242
255 243static int
256static int isl1208_i2c_read_time(struct i2c_client *client, 244isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
257 struct rtc_time *tm)
258{ 245{
259 int sr; 246 int sr;
260 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 247 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
@@ -274,27 +261,30 @@ static int isl1208_i2c_read_time(struct i2c_client *client,
274 261
275 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]); 262 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]);
276 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]); 263 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]);
277 { /* HR field has a more complex interpretation */ 264
265 /* HR field has a more complex interpretation */
266 {
278 const u8 _hr = regs[ISL1208_REG_HR]; 267 const u8 _hr = regs[ISL1208_REG_HR];
279 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */ 268 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
280 tm->tm_hour = BCD2BIN(_hr & 0x3f); 269 tm->tm_hour = BCD2BIN(_hr & 0x3f);
281 else { // 12h format 270 else {
271 /* 12h format */
282 tm->tm_hour = BCD2BIN(_hr & 0x1f); 272 tm->tm_hour = BCD2BIN(_hr & 0x1f);
283 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */ 273 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
284 tm->tm_hour += 12; 274 tm->tm_hour += 12;
285 } 275 }
286 } 276 }
287 277
288 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]); 278 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]);
289 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */ 279 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
290 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100; 280 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100;
291 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]); 281 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]);
292 282
293 return 0; 283 return 0;
294} 284}
295 285
296static int isl1208_i2c_read_alarm(struct i2c_client *client, 286static int
297 struct rtc_wkalrm *alarm) 287isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
298{ 288{
299 struct rtc_time *const tm = &alarm->time; 289 struct rtc_time *const tm = &alarm->time;
300 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, }; 290 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
@@ -307,7 +297,7 @@ static int isl1208_i2c_read_alarm(struct i2c_client *client,
307 } 297 }
308 298
309 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs, 299 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
310 ISL1208_ALARM_SECTION_LEN); 300 ISL1208_ALARM_SECTION_LEN);
311 if (sr < 0) { 301 if (sr < 0) {
312 dev_err(&client->dev, "%s: reading alarm section failed\n", 302 dev_err(&client->dev, "%s: reading alarm section failed\n",
313 __func__); 303 __func__);
@@ -315,23 +305,25 @@ static int isl1208_i2c_read_alarm(struct i2c_client *client,
315 } 305 }
316 306
317 /* MSB of each alarm register is an enable bit */ 307 /* MSB of each alarm register is an enable bit */
318 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA-ISL1208_REG_SCA] & 0x7f); 308 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
319 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA-ISL1208_REG_SCA] & 0x7f); 309 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
320 tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA-ISL1208_REG_SCA] & 0x3f); 310 tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
321 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA-ISL1208_REG_SCA] & 0x3f); 311 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
322 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MOA-ISL1208_REG_SCA] & 0x1f)-1; 312 tm->tm_mon =
323 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA-ISL1208_REG_SCA] & 0x03); 313 BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
314 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
324 315
325 return 0; 316 return 0;
326} 317}
327 318
328static int isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm) 319static int
320isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
329{ 321{
330 return isl1208_i2c_read_time(to_i2c_client(dev), tm); 322 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
331} 323}
332 324
333static int isl1208_i2c_set_time(struct i2c_client *client, 325static int
334 struct rtc_time const *tm) 326isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
335{ 327{
336 int sr; 328 int sr;
337 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 329 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
@@ -353,7 +345,7 @@ static int isl1208_i2c_set_time(struct i2c_client *client,
353 } 345 }
354 346
355 /* set WRTC */ 347 /* set WRTC */
356 sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR, 348 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
357 sr | ISL1208_REG_SR_WRTC); 349 sr | ISL1208_REG_SR_WRTC);
358 if (sr < 0) { 350 if (sr < 0) {
359 dev_err(&client->dev, "%s: writing SR failed\n", __func__); 351 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
@@ -369,7 +361,7 @@ static int isl1208_i2c_set_time(struct i2c_client *client,
369 } 361 }
370 362
371 /* clear WRTC again */ 363 /* clear WRTC again */
372 sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR, 364 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
373 sr & ~ISL1208_REG_SR_WRTC); 365 sr & ~ISL1208_REG_SR_WRTC);
374 if (sr < 0) { 366 if (sr < 0) {
375 dev_err(&client->dev, "%s: writing SR failed\n", __func__); 367 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
@@ -380,70 +372,69 @@ static int isl1208_i2c_set_time(struct i2c_client *client,
380} 372}
381 373
382 374
383static int isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm) 375static int
376isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
384{ 377{
385 return isl1208_i2c_set_time(to_i2c_client(dev), tm); 378 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
386} 379}
387 380
388static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 381static int
382isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
389{ 383{
390 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm); 384 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
391} 385}
392 386
393static const struct rtc_class_ops isl1208_rtc_ops = { 387static const struct rtc_class_ops isl1208_rtc_ops = {
394 .proc = isl1208_rtc_proc, 388 .proc = isl1208_rtc_proc,
395 .read_time = isl1208_rtc_read_time, 389 .read_time = isl1208_rtc_read_time,
396 .set_time = isl1208_rtc_set_time, 390 .set_time = isl1208_rtc_set_time,
397 .read_alarm = isl1208_rtc_read_alarm, 391 .read_alarm = isl1208_rtc_read_alarm,
398 //.set_alarm = isl1208_rtc_set_alarm, 392 /*.set_alarm = isl1208_rtc_set_alarm, */
399}; 393};
400 394
401/* sysfs interface */ 395/* sysfs interface */
402 396
403static ssize_t isl1208_sysfs_show_atrim(struct device *dev, 397static ssize_t
404 struct device_attribute *attr, 398isl1208_sysfs_show_atrim(struct device *dev,
405 char *buf) 399 struct device_attribute *attr, char *buf)
406{ 400{
407 int atr; 401 int atr = isl1208_i2c_get_atr(to_i2c_client(dev));
408
409 atr = isl1208_i2c_get_atr(to_i2c_client(dev));
410 if (atr < 0) 402 if (atr < 0)
411 return atr; 403 return atr;
412 404
413 return sprintf(buf, "%d.%.2d pF\n", atr>>2, (atr&0x3)*25); 405 return sprintf(buf, "%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
414} 406}
407
415static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL); 408static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
416 409
417static ssize_t isl1208_sysfs_show_dtrim(struct device *dev, 410static ssize_t
418 struct device_attribute *attr, 411isl1208_sysfs_show_dtrim(struct device *dev,
419 char *buf) 412 struct device_attribute *attr, char *buf)
420{ 413{
421 int dtr; 414 int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
422
423 dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
424 if (dtr < 0) 415 if (dtr < 0)
425 return dtr; 416 return dtr;
426 417
427 return sprintf(buf, "%d ppm\n", dtr); 418 return sprintf(buf, "%d ppm\n", dtr);
428} 419}
420
429static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL); 421static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
430 422
431static ssize_t isl1208_sysfs_show_usr(struct device *dev, 423static ssize_t
432 struct device_attribute *attr, 424isl1208_sysfs_show_usr(struct device *dev,
433 char *buf) 425 struct device_attribute *attr, char *buf)
434{ 426{
435 int usr; 427 int usr = isl1208_i2c_get_usr(to_i2c_client(dev));
436
437 usr = isl1208_i2c_get_usr(to_i2c_client(dev));
438 if (usr < 0) 428 if (usr < 0)
439 return usr; 429 return usr;
440 430
441 return sprintf(buf, "0x%.4x\n", usr); 431 return sprintf(buf, "0x%.4x\n", usr);
442} 432}
443 433
444static ssize_t isl1208_sysfs_store_usr(struct device *dev, 434static ssize_t
445 struct device_attribute *attr, 435isl1208_sysfs_store_usr(struct device *dev,
446 const char *buf, size_t count) 436 struct device_attribute *attr,
437 const char *buf, size_t count)
447{ 438{
448 int usr = -1; 439 int usr = -1;
449 440
@@ -460,124 +451,116 @@ static ssize_t isl1208_sysfs_store_usr(struct device *dev,
460 451
461 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count; 452 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
462} 453}
454
463static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr, 455static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
464 isl1208_sysfs_store_usr); 456 isl1208_sysfs_store_usr);
465 457
466static int 458static int
467isl1208_probe(struct i2c_adapter *adapter, int addr, int kind) 459isl1208_sysfs_register(struct device *dev)
468{ 460{
469 int rc = 0; 461 int err;
470 struct i2c_client *new_client = NULL; 462
471 struct rtc_device *rtc = NULL; 463 err = device_create_file(dev, &dev_attr_atrim);
464 if (err)
465 return err;
472 466
473 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 467 err = device_create_file(dev, &dev_attr_dtrim);
474 rc = -ENODEV; 468 if (err) {
475 goto failout; 469 device_remove_file(dev, &dev_attr_atrim);
470 return err;
476 } 471 }
477 472
478 new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 473 err = device_create_file(dev, &dev_attr_usr);
479 if (new_client == NULL) { 474 if (err) {
480 rc = -ENOMEM; 475 device_remove_file(dev, &dev_attr_atrim);
481 goto failout; 476 device_remove_file(dev, &dev_attr_dtrim);
482 } 477 }
483 478
484 new_client->addr = addr; 479 return 0;
485 new_client->adapter = adapter; 480}
486 new_client->driver = &isl1208_driver;
487 new_client->flags = 0;
488 strcpy(new_client->name, DRV_NAME);
489 481
490 if (kind < 0) { 482static int
491 rc = isl1208_i2c_validate_client(new_client); 483isl1208_sysfs_unregister(struct device *dev)
492 if (rc < 0) 484{
493 goto failout; 485 device_remove_file(dev, &dev_attr_atrim);
494 } 486 device_remove_file(dev, &dev_attr_atrim);
487 device_remove_file(dev, &dev_attr_usr);
488
489 return 0;
490}
491
492static int
493isl1208_probe(struct i2c_client *client)
494{
495 int rc = 0;
496 struct rtc_device *rtc;
495 497
496 rc = i2c_attach_client(new_client); 498 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
497 if (rc < 0) 499 return -ENODEV;
498 goto failout;
499 500
500 dev_info(&new_client->dev, 501 if (isl1208_i2c_validate_client(client) < 0)
502 return -ENODEV;
503
504 dev_info(&client->dev,
501 "chip found, driver version " DRV_VERSION "\n"); 505 "chip found, driver version " DRV_VERSION "\n");
502 506
503 rtc = rtc_device_register(isl1208_driver.driver.name, 507 rtc = rtc_device_register(isl1208_driver.driver.name,
504 &new_client->dev, 508 &client->dev, &isl1208_rtc_ops,
505 &isl1208_rtc_ops, THIS_MODULE); 509 THIS_MODULE);
506 510 if (IS_ERR(rtc))
507 if (IS_ERR(rtc)) { 511 return PTR_ERR(rtc);
508 rc = PTR_ERR(rtc);
509 goto failout_detach;
510 }
511 512
512 i2c_set_clientdata(new_client, rtc); 513 i2c_set_clientdata(client, rtc);
513 514
514 rc = isl1208_i2c_get_sr(new_client); 515 rc = isl1208_i2c_get_sr(client);
515 if (rc < 0) { 516 if (rc < 0) {
516 dev_err(&new_client->dev, "reading status failed\n"); 517 dev_err(&client->dev, "reading status failed\n");
517 goto failout_unregister; 518 goto exit_unregister;
518 } 519 }
519 520
520 if (rc & ISL1208_REG_SR_RTCF) 521 if (rc & ISL1208_REG_SR_RTCF)
521 dev_warn(&new_client->dev, "rtc power failure detected, " 522 dev_warn(&client->dev, "rtc power failure detected, "
522 "please set clock.\n"); 523 "please set clock.\n");
523 524
524 rc = device_create_file(&new_client->dev, &dev_attr_atrim); 525 rc = isl1208_sysfs_register(&client->dev);
525 if (rc < 0) 526 if (rc)
526 goto failout_unregister; 527 goto exit_unregister;
527 rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
528 if (rc < 0)
529 goto failout_atrim;
530 rc = device_create_file(&new_client->dev, &dev_attr_usr);
531 if (rc < 0)
532 goto failout_dtrim;
533 528
534 return 0; 529 return 0;
535 530
536 failout_dtrim: 531exit_unregister:
537 device_remove_file(&new_client->dev, &dev_attr_dtrim);
538 failout_atrim:
539 device_remove_file(&new_client->dev, &dev_attr_atrim);
540 failout_unregister:
541 rtc_device_unregister(rtc); 532 rtc_device_unregister(rtc);
542 failout_detach:
543 i2c_detach_client(new_client);
544 failout:
545 kfree(new_client);
546 return rc;
547}
548 533
549static int 534 return rc;
550isl1208_attach_adapter (struct i2c_adapter *adapter)
551{
552 return i2c_probe(adapter, &addr_data, isl1208_probe);
553} 535}
554 536
555static int 537static int
556isl1208_detach_client(struct i2c_client *client) 538isl1208_remove(struct i2c_client *client)
557{ 539{
558 int rc; 540 struct rtc_device *rtc = i2c_get_clientdata(client);
559 struct rtc_device *const rtc = i2c_get_clientdata(client);
560
561 if (rtc)
562 rtc_device_unregister(rtc); /* do we need to kfree? */
563
564 rc = i2c_detach_client(client);
565 if (rc)
566 return rc;
567 541
568 kfree(client); 542 isl1208_sysfs_unregister(&client->dev);
543 rtc_device_unregister(rtc);
569 544
570 return 0; 545 return 0;
571} 546}
572 547
573/* module management */ 548static struct i2c_driver isl1208_driver = {
549 .driver = {
550 .name = "rtc-isl1208",
551 },
552 .probe = isl1208_probe,
553 .remove = isl1208_remove,
554};
574 555
575static int __init isl1208_init(void) 556static int __init
557isl1208_init(void)
576{ 558{
577 return i2c_add_driver(&isl1208_driver); 559 return i2c_add_driver(&isl1208_driver);
578} 560}
579 561
580static void __exit isl1208_exit(void) 562static void __exit
563isl1208_exit(void)
581{ 564{
582 i2c_del_driver(&isl1208_driver); 565 i2c_del_driver(&isl1208_driver);
583} 566}
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index 7683412970c4..ded3c0abad83 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -98,7 +98,7 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
98 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 98 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
99 if (rc != ARRAY_SIZE(msgs)) { 99 if (rc != ARRAY_SIZE(msgs)) {
100 dev_err(&client->dev, "%s: register read failed\n", 100 dev_err(&client->dev, "%s: register read failed\n",
101 __FUNCTION__); 101 __func__);
102 return -EIO; 102 return -EIO;
103 } 103 }
104 return 0; 104 return 0;
@@ -150,7 +150,7 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
150 150
151write_failed: 151write_failed:
152 dev_err(&client->dev, "%s: register write failed\n", 152 dev_err(&client->dev, "%s: register write failed\n",
153 __FUNCTION__); 153 __func__);
154 return -EIO; 154 return -EIO;
155} 155}
156 156
@@ -214,7 +214,7 @@ static int max6900_i2c_clear_write_protect(struct i2c_client *client)
214 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0); 214 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0);
215 if (rc < 0) { 215 if (rc < 0) {
216 dev_err(&client->dev, "%s: control register write failed\n", 216 dev_err(&client->dev, "%s: control register write failed\n",
217 __FUNCTION__); 217 __func__);
218 return -EIO; 218 return -EIO;
219 } 219 }
220 return 0; 220 return 0;
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 1f956dc5d56e..12f0310ae89c 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -140,7 +140,7 @@ static int max6902_get_datetime(struct device *dev, struct rtc_time *dt)
140 dt->tm_year -= 1900; 140 dt->tm_year -= 1900;
141 141
142#ifdef MAX6902_DEBUG 142#ifdef MAX6902_DEBUG
143 printk("\n%s : Read RTC values\n",__FUNCTION__); 143 printk("\n%s : Read RTC values\n",__func__);
144 printk("tm_hour: %i\n",dt->tm_hour); 144 printk("tm_hour: %i\n",dt->tm_hour);
145 printk("tm_min : %i\n",dt->tm_min); 145 printk("tm_min : %i\n",dt->tm_min);
146 printk("tm_sec : %i\n",dt->tm_sec); 146 printk("tm_sec : %i\n",dt->tm_sec);
@@ -158,7 +158,7 @@ static int max6902_set_datetime(struct device *dev, struct rtc_time *dt)
158 dt->tm_year = dt->tm_year+1900; 158 dt->tm_year = dt->tm_year+1900;
159 159
160#ifdef MAX6902_DEBUG 160#ifdef MAX6902_DEBUG
161 printk("\n%s : Setting RTC values\n",__FUNCTION__); 161 printk("\n%s : Setting RTC values\n",__func__);
162 printk("tm_sec : %i\n",dt->tm_sec); 162 printk("tm_sec : %i\n",dt->tm_sec);
163 printk("tm_min : %i\n",dt->tm_min); 163 printk("tm_min : %i\n",dt->tm_min);
164 printk("tm_hour: %i\n",dt->tm_hour); 164 printk("tm_hour: %i\n",dt->tm_hour);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index b3317fcc16c3..a41681d26eba 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -18,17 +18,7 @@
18#include <linux/bcd.h> 18#include <linux/bcd.h>
19#include <linux/rtc.h> 19#include <linux/rtc.h>
20 20
21#define DRV_VERSION "0.4.2" 21#define DRV_VERSION "0.4.3"
22
23/* Addresses to scan: none
24 * This chip cannot be reliably autodetected. An empty eeprom
25 * located at 0x51 will pass the validation routine due to
26 * the way the registers are implemented.
27 */
28static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
29
30/* Module parameters */
31I2C_CLIENT_INSMOD;
32 22
33#define PCF8563_REG_ST1 0x00 /* status */ 23#define PCF8563_REG_ST1 0x00 /* status */
34#define PCF8563_REG_ST2 0x01 24#define PCF8563_REG_ST2 0x01
@@ -53,8 +43,10 @@ I2C_CLIENT_INSMOD;
53#define PCF8563_SC_LV 0x80 /* low voltage */ 43#define PCF8563_SC_LV 0x80 /* low voltage */
54#define PCF8563_MO_C 0x80 /* century */ 44#define PCF8563_MO_C 0x80 /* century */
55 45
46static struct i2c_driver pcf8563_driver;
47
56struct pcf8563 { 48struct pcf8563 {
57 struct i2c_client client; 49 struct rtc_device *rtc;
58 /* 50 /*
59 * The meaning of MO_C bit varies by the chip type. 51 * The meaning of MO_C bit varies by the chip type.
60 * From PCF8563 datasheet: this bit is toggled when the years 52 * From PCF8563 datasheet: this bit is toggled when the years
@@ -72,16 +64,13 @@ struct pcf8563 {
72 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */ 64 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
73}; 65};
74 66
75static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
76static int pcf8563_detach(struct i2c_client *client);
77
78/* 67/*
79 * In the routines that deal directly with the pcf8563 hardware, we use 68 * In the routines that deal directly with the pcf8563 hardware, we use
80 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 69 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
81 */ 70 */
82static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm) 71static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
83{ 72{
84 struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); 73 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
85 unsigned char buf[13] = { PCF8563_REG_ST1 }; 74 unsigned char buf[13] = { PCF8563_REG_ST1 };
86 75
87 struct i2c_msg msgs[] = { 76 struct i2c_msg msgs[] = {
@@ -91,7 +80,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
91 80
92 /* read registers */ 81 /* read registers */
93 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) { 82 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
94 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 83 dev_err(&client->dev, "%s: read error\n", __func__);
95 return -EIO; 84 return -EIO;
96 } 85 }
97 86
@@ -102,7 +91,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
102 dev_dbg(&client->dev, 91 dev_dbg(&client->dev,
103 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, " 92 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
104 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n", 93 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
105 __FUNCTION__, 94 __func__,
106 buf[0], buf[1], buf[2], buf[3], 95 buf[0], buf[1], buf[2], buf[3],
107 buf[4], buf[5], buf[6], buf[7], 96 buf[4], buf[5], buf[6], buf[7],
108 buf[8]); 97 buf[8]);
@@ -123,7 +112,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
123 112
124 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 113 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
125 "mday=%d, mon=%d, year=%d, wday=%d\n", 114 "mday=%d, mon=%d, year=%d, wday=%d\n",
126 __FUNCTION__, 115 __func__,
127 tm->tm_sec, tm->tm_min, tm->tm_hour, 116 tm->tm_sec, tm->tm_min, tm->tm_hour,
128 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 117 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
129 118
@@ -138,13 +127,13 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
138 127
139static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) 128static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
140{ 129{
141 struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); 130 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
142 int i, err; 131 int i, err;
143 unsigned char buf[9]; 132 unsigned char buf[9];
144 133
145 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " 134 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
146 "mday=%d, mon=%d, year=%d, wday=%d\n", 135 "mday=%d, mon=%d, year=%d, wday=%d\n",
147 __FUNCTION__, 136 __func__,
148 tm->tm_sec, tm->tm_min, tm->tm_hour, 137 tm->tm_sec, tm->tm_min, tm->tm_hour,
149 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 138 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
150 139
@@ -174,7 +163,7 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
174 if (err != sizeof(data)) { 163 if (err != sizeof(data)) {
175 dev_err(&client->dev, 164 dev_err(&client->dev,
176 "%s: err=%d addr=%02x, data=%02x\n", 165 "%s: err=%d addr=%02x, data=%02x\n",
177 __FUNCTION__, err, data[0], data[1]); 166 __func__, err, data[0], data[1]);
178 return -EIO; 167 return -EIO;
179 } 168 }
180 }; 169 };
@@ -219,7 +208,7 @@ static int pcf8563_validate_client(struct i2c_client *client)
219 if (xfer != ARRAY_SIZE(msgs)) { 208 if (xfer != ARRAY_SIZE(msgs)) {
220 dev_err(&client->dev, 209 dev_err(&client->dev,
221 "%s: could not read register 0x%02X\n", 210 "%s: could not read register 0x%02X\n",
222 __FUNCTION__, pattern[i].reg); 211 __func__, pattern[i].reg);
223 212
224 return -EIO; 213 return -EIO;
225 } 214 }
@@ -231,7 +220,7 @@ static int pcf8563_validate_client(struct i2c_client *client)
231 dev_dbg(&client->dev, 220 dev_dbg(&client->dev,
232 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, " 221 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
233 "max=%d, value=%d, raw=0x%02X\n", 222 "max=%d, value=%d, raw=0x%02X\n",
234 __FUNCTION__, i, pattern[i].reg, pattern[i].mask, 223 __func__, i, pattern[i].reg, pattern[i].mask,
235 pattern[i].min, pattern[i].max, 224 pattern[i].min, pattern[i].max,
236 value, buf); 225 value, buf);
237 226
@@ -257,100 +246,67 @@ static const struct rtc_class_ops pcf8563_rtc_ops = {
257 .set_time = pcf8563_rtc_set_time, 246 .set_time = pcf8563_rtc_set_time,
258}; 247};
259 248
260static int pcf8563_attach(struct i2c_adapter *adapter) 249static int pcf8563_probe(struct i2c_client *client)
261{
262 return i2c_probe(adapter, &addr_data, pcf8563_probe);
263}
264
265static struct i2c_driver pcf8563_driver = {
266 .driver = {
267 .name = "pcf8563",
268 },
269 .id = I2C_DRIVERID_PCF8563,
270 .attach_adapter = &pcf8563_attach,
271 .detach_client = &pcf8563_detach,
272};
273
274static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
275{ 250{
276 struct pcf8563 *pcf8563; 251 struct pcf8563 *pcf8563;
277 struct i2c_client *client;
278 struct rtc_device *rtc;
279 252
280 int err = 0; 253 int err = 0;
281 254
282 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 255 dev_dbg(&client->dev, "%s\n", __func__);
283 256
284 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 257 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
285 err = -ENODEV; 258 return -ENODEV;
286 goto exit;
287 }
288 259
289 if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) { 260 pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL);
290 err = -ENOMEM; 261 if (!pcf8563)
291 goto exit; 262 return -ENOMEM;
292 }
293
294 client = &pcf8563->client;
295 client->addr = address;
296 client->driver = &pcf8563_driver;
297 client->adapter = adapter;
298
299 strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
300 263
301 /* Verify the chip is really an PCF8563 */ 264 /* Verify the chip is really an PCF8563 */
302 if (kind < 0) { 265 if (pcf8563_validate_client(client) < 0) {
303 if (pcf8563_validate_client(client) < 0) { 266 err = -ENODEV;
304 err = -ENODEV;
305 goto exit_kfree;
306 }
307 }
308
309 /* Inform the i2c layer */
310 if ((err = i2c_attach_client(client)))
311 goto exit_kfree; 267 goto exit_kfree;
268 }
312 269
313 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 270 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
314 271
315 rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev, 272 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name,
316 &pcf8563_rtc_ops, THIS_MODULE); 273 &client->dev, &pcf8563_rtc_ops, THIS_MODULE);
317 274
318 if (IS_ERR(rtc)) { 275 if (IS_ERR(pcf8563->rtc)) {
319 err = PTR_ERR(rtc); 276 err = PTR_ERR(pcf8563->rtc);
320 goto exit_detach; 277 goto exit_kfree;
321 } 278 }
322 279
323 i2c_set_clientdata(client, rtc); 280 i2c_set_clientdata(client, pcf8563);
324 281
325 return 0; 282 return 0;
326 283
327exit_detach:
328 i2c_detach_client(client);
329
330exit_kfree: 284exit_kfree:
331 kfree(pcf8563); 285 kfree(pcf8563);
332 286
333exit:
334 return err; 287 return err;
335} 288}
336 289
337static int pcf8563_detach(struct i2c_client *client) 290static int pcf8563_remove(struct i2c_client *client)
338{ 291{
339 struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); 292 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
340 int err;
341 struct rtc_device *rtc = i2c_get_clientdata(client);
342 293
343 if (rtc) 294 if (pcf8563->rtc)
344 rtc_device_unregister(rtc); 295 rtc_device_unregister(pcf8563->rtc);
345
346 if ((err = i2c_detach_client(client)))
347 return err;
348 296
349 kfree(pcf8563); 297 kfree(pcf8563);
350 298
351 return 0; 299 return 0;
352} 300}
353 301
302static struct i2c_driver pcf8563_driver = {
303 .driver = {
304 .name = "rtc-pcf8563",
305 },
306 .probe = pcf8563_probe,
307 .remove = pcf8563_remove,
308};
309
354static int __init pcf8563_init(void) 310static int __init pcf8563_init(void)
355{ 311{
356 return i2c_add_driver(&pcf8563_driver); 312 return i2c_add_driver(&pcf8563_driver);
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 8b3997007506..3d09d8f0b1f0 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -15,7 +15,7 @@
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/mc146818rtc.h> 18#include <linux/rtc.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/bcd.h> 21#include <linux/bcd.h>
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index 664e89a817ed..1c14d4497c4d 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -228,7 +228,7 @@ static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
228 ndelay(700); /* CE:L */ 228 ndelay(700); /* CE:L */
229 229
230 if (cnt++ > 100) { 230 if (cnt++ > 100) {
231 dev_err(dev, "%s: timeout error\n", __FUNCTION__); 231 dev_err(dev, "%s: timeout error\n", __func__);
232 return -EIO; 232 return -EIO;
233 } 233 }
234 } 234 }
@@ -289,7 +289,7 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
289 ndelay(700); /* CE:L */ 289 ndelay(700); /* CE:L */
290 290
291 if (cnt++ > 100) { 291 if (cnt++ > 100) {
292 dev_err(dev, "%s: timeout error\n", __FUNCTION__); 292 dev_err(dev, "%s: timeout error\n", __func__);
293 return -EIO; 293 return -EIO;
294 } 294 }
295 } 295 }
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 6b67b5097927..7e63074708eb 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -99,7 +99,7 @@ static int rs5c_get_regs(struct rs5c372 *rs5c)
99 * least 80219 chips; this works around that bug. 99 * least 80219 chips; this works around that bug.
100 */ 100 */
101 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) { 101 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
102 pr_debug("%s: can't read registers\n", rs5c->rtc->name); 102 dev_warn(&client->dev, "can't read registers\n");
103 return -EIO; 103 return -EIO;
104 } 104 }
105 105
@@ -166,7 +166,7 @@ static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
166 166
167 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 167 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
168 "mday=%d, mon=%d, year=%d, wday=%d\n", 168 "mday=%d, mon=%d, year=%d, wday=%d\n",
169 __FUNCTION__, 169 __func__,
170 tm->tm_sec, tm->tm_min, tm->tm_hour, 170 tm->tm_sec, tm->tm_min, tm->tm_hour,
171 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 171 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
172 172
@@ -181,7 +181,7 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
181 181
182 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " 182 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d "
183 "mday=%d, mon=%d, year=%d, wday=%d\n", 183 "mday=%d, mon=%d, year=%d, wday=%d\n",
184 __FUNCTION__, 184 __func__,
185 tm->tm_sec, tm->tm_min, tm->tm_hour, 185 tm->tm_sec, tm->tm_min, tm->tm_hour,
186 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 186 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
187 187
@@ -195,7 +195,7 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
195 buf[7] = BIN2BCD(tm->tm_year - 100); 195 buf[7] = BIN2BCD(tm->tm_year - 100);
196 196
197 if ((i2c_master_send(client, buf, 8)) != 8) { 197 if ((i2c_master_send(client, buf, 8)) != 8) {
198 dev_err(&client->dev, "%s: write error\n", __FUNCTION__); 198 dev_err(&client->dev, "%s: write error\n", __func__);
199 return -EIO; 199 return -EIO;
200 } 200 }
201 201
@@ -220,7 +220,7 @@ static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim)
220 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768; 220 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768;
221 221
222 if (trim) { 222 if (trim) {
223 dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, tmp); 223 dev_dbg(&client->dev, "%s: raw trim=%x\n", __func__, tmp);
224 tmp &= RS5C372_TRIM_MASK; 224 tmp &= RS5C372_TRIM_MASK;
225 if (tmp & 0x3e) { 225 if (tmp & 0x3e) {
226 int t = tmp & 0x3f; 226 int t = tmp & 0x3f;
@@ -500,7 +500,7 @@ static int rs5c372_probe(struct i2c_client *client)
500 struct rs5c372 *rs5c372; 500 struct rs5c372 *rs5c372;
501 struct rtc_time tm; 501 struct rtc_time tm;
502 502
503 dev_dbg(&client->dev, "%s\n", __FUNCTION__); 503 dev_dbg(&client->dev, "%s\n", __func__);
504 504
505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
506 err = -ENODEV; 506 err = -ENODEV;
@@ -512,12 +512,12 @@ static int rs5c372_probe(struct i2c_client *client)
512 goto exit; 512 goto exit;
513 } 513 }
514 514
515 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
516 rs5c372->regs=&rs5c372->buf[1];
517
518 rs5c372->client = client; 515 rs5c372->client = client;
519 i2c_set_clientdata(client, rs5c372); 516 i2c_set_clientdata(client, rs5c372);
520 517
518 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
519 rs5c372->regs = &rs5c372->buf[1];
520
521 err = rs5c_get_regs(rs5c372); 521 err = rs5c_get_regs(rs5c372);
522 if (err < 0) 522 if (err < 0)
523 goto exit_kfree; 523 goto exit_kfree;
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 9f4d5129a496..f26e0cad8f16 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -68,7 +68,7 @@ static void s3c_rtc_setaie(int to)
68{ 68{
69 unsigned int tmp; 69 unsigned int tmp;
70 70
71 pr_debug("%s: aie=%d\n", __FUNCTION__, to); 71 pr_debug("%s: aie=%d\n", __func__, to);
72 72
73 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 73 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
74 74
@@ -82,7 +82,7 @@ static void s3c_rtc_setpie(int to)
82{ 82{
83 unsigned int tmp; 83 unsigned int tmp;
84 84
85 pr_debug("%s: pie=%d\n", __FUNCTION__, to); 85 pr_debug("%s: pie=%d\n", __func__, to);
86 86
87 spin_lock_irq(&s3c_rtc_pie_lock); 87 spin_lock_irq(&s3c_rtc_pie_lock);
88 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE; 88 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
@@ -457,7 +457,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
457 struct resource *res; 457 struct resource *res;
458 int ret; 458 int ret;
459 459
460 pr_debug("%s: probe=%p\n", __FUNCTION__, pdev); 460 pr_debug("%s: probe=%p\n", __func__, pdev);
461 461
462 /* find the IRQs */ 462 /* find the IRQs */
463 463
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index c594b34c6767..110699bb4787 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -361,7 +361,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
361 361
362 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 362 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
363 "mday=%d, mon=%d, year=%d, wday=%d\n", 363 "mday=%d, mon=%d, year=%d, wday=%d\n",
364 __FUNCTION__, 364 __func__,
365 tm->tm_sec, tm->tm_min, tm->tm_hour, 365 tm->tm_sec, tm->tm_min, tm->tm_hour,
366 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); 366 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
367 367
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 4d27ccc4fc06..2531ce4c9db0 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -145,6 +145,8 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
145 unsigned long now, alarm; 145 unsigned long now, alarm;
146 struct rtc_wkalrm alm; 146 struct rtc_wkalrm alm;
147 struct rtc_device *rtc = to_rtc_device(dev); 147 struct rtc_device *rtc = to_rtc_device(dev);
148 char *buf_ptr;
149 int adjust = 0;
148 150
149 /* Only request alarms that trigger in the future. Disable them 151 /* Only request alarms that trigger in the future. Disable them
150 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC. 152 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
@@ -154,7 +156,15 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
154 return retval; 156 return retval;
155 rtc_tm_to_time(&alm.time, &now); 157 rtc_tm_to_time(&alm.time, &now);
156 158
157 alarm = simple_strtoul(buf, NULL, 0); 159 buf_ptr = (char *)buf;
160 if (*buf_ptr == '+') {
161 buf_ptr++;
162 adjust = 1;
163 }
164 alarm = simple_strtoul(buf_ptr, NULL, 0);
165 if (adjust) {
166 alarm += now;
167 }
158 if (alarm > now) { 168 if (alarm > now) {
159 /* Avoid accidentally clobbering active alarms; we can't 169 /* Avoid accidentally clobbering active alarms; we can't
160 * entirely prevent that here, without even the minimal 170 * entirely prevent that here, without even the minimal
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 254c9fce27da..bc930022004a 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -147,7 +147,7 @@ static int __devexit test_remove(struct platform_device *plat_dev)
147 return 0; 147 return 0;
148} 148}
149 149
150static struct platform_driver test_drv = { 150static struct platform_driver test_driver = {
151 .probe = test_probe, 151 .probe = test_probe,
152 .remove = __devexit_p(test_remove), 152 .remove = __devexit_p(test_remove),
153 .driver = { 153 .driver = {
@@ -160,7 +160,7 @@ static int __init test_init(void)
160{ 160{
161 int err; 161 int err;
162 162
163 if ((err = platform_driver_register(&test_drv))) 163 if ((err = platform_driver_register(&test_driver)))
164 return err; 164 return err;
165 165
166 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) { 166 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
@@ -191,7 +191,7 @@ exit_free_test0:
191 platform_device_put(test0); 191 platform_device_put(test0);
192 192
193exit_driver_unregister: 193exit_driver_unregister:
194 platform_driver_unregister(&test_drv); 194 platform_driver_unregister(&test_driver);
195 return err; 195 return err;
196} 196}
197 197
@@ -199,7 +199,7 @@ static void __exit test_exit(void)
199{ 199{
200 platform_device_unregister(test0); 200 platform_device_unregister(test0);
201 platform_device_unregister(test1); 201 platform_device_unregister(test1);
202 platform_driver_unregister(&test_drv); 202 platform_driver_unregister(&test_driver);
203} 203}
204 204
205MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 205MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index 24203a06051a..10025d840268 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -107,7 +107,7 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt)
107 dt->tm_year = BCD2BIN(tmp)+100; 107 dt->tm_year = BCD2BIN(tmp)+100;
108 108
109#ifdef DEBUG 109#ifdef DEBUG
110 printk("\n%s : Read RTC values\n",__FUNCTION__); 110 printk("\n%s : Read RTC values\n",__func__);
111 printk("tm_hour: %i\n",dt->tm_hour); 111 printk("tm_hour: %i\n",dt->tm_hour);
112 printk("tm_min : %i\n",dt->tm_min); 112 printk("tm_min : %i\n",dt->tm_min);
113 printk("tm_sec : %i\n",dt->tm_sec); 113 printk("tm_sec : %i\n",dt->tm_sec);
@@ -126,7 +126,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)
126 struct v3020 *chip = dev_get_drvdata(dev); 126 struct v3020 *chip = dev_get_drvdata(dev);
127 127
128#ifdef DEBUG 128#ifdef DEBUG
129 printk("\n%s : Setting RTC values\n",__FUNCTION__); 129 printk("\n%s : Setting RTC values\n",__func__);
130 printk("tm_sec : %i\n",dt->tm_sec); 130 printk("tm_sec : %i\n",dt->tm_sec);
131 printk("tm_min : %i\n",dt->tm_min); 131 printk("tm_min : %i\n",dt->tm_min);
132 printk("tm_hour: %i\n",dt->tm_hour); 132 printk("tm_hour: %i\n",dt->tm_hour);
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index b90fb1866ce9..095282f63523 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -22,20 +22,7 @@
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24 24
25#define DRV_VERSION "1.0.7" 25#define DRV_VERSION "1.0.8"
26
27/* Addresses to scan: none. This chip is located at
28 * 0x6f and uses a two bytes register addressing.
29 * Two bytes need to be written to read a single register,
30 * while most other chips just require one and take the second
31 * one as the data to be written. To prevent corrupting
32 * unknown chips, the user must explicitly set the probe parameter.
33 */
34
35static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
36
37/* Insmod parameters */
38I2C_CLIENT_INSMOD;
39 26
40/* offsets into CCR area */ 27/* offsets into CCR area */
41 28
@@ -91,19 +78,7 @@ I2C_CLIENT_INSMOD;
91 78
92#define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ 79#define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
93 80
94/* Prototypes */ 81static struct i2c_driver x1205_driver;
95static int x1205_attach(struct i2c_adapter *adapter);
96static int x1205_detach(struct i2c_client *client);
97static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
98
99static struct i2c_driver x1205_driver = {
100 .driver = {
101 .name = "x1205",
102 },
103 .id = I2C_DRIVERID_X1205,
104 .attach_adapter = &x1205_attach,
105 .detach_client = &x1205_detach,
106};
107 82
108/* 83/*
109 * In the routines that deal directly with the x1205 hardware, we use 84 * In the routines that deal directly with the x1205 hardware, we use
@@ -124,14 +99,14 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
124 99
125 /* read date registers */ 100 /* read date registers */
126 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 101 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
127 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 102 dev_err(&client->dev, "%s: read error\n", __func__);
128 return -EIO; 103 return -EIO;
129 } 104 }
130 105
131 dev_dbg(&client->dev, 106 dev_dbg(&client->dev,
132 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, " 107 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
133 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n", 108 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
134 __FUNCTION__, 109 __func__,
135 buf[0], buf[1], buf[2], buf[3], 110 buf[0], buf[1], buf[2], buf[3],
136 buf[4], buf[5], buf[6], buf[7]); 111 buf[4], buf[5], buf[6], buf[7]);
137 112
@@ -146,7 +121,7 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
146 121
147 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 122 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
148 "mday=%d, mon=%d, year=%d, wday=%d\n", 123 "mday=%d, mon=%d, year=%d, wday=%d\n",
149 __FUNCTION__, 124 __func__,
150 tm->tm_sec, tm->tm_min, tm->tm_hour, 125 tm->tm_sec, tm->tm_min, tm->tm_hour,
151 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 126 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
152 127
@@ -164,7 +139,7 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
164 139
165 /* read status register */ 140 /* read status register */
166 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 141 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
167 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 142 dev_err(&client->dev, "%s: read error\n", __func__);
168 return -EIO; 143 return -EIO;
169 } 144 }
170 145
@@ -187,7 +162,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
187 162
188 dev_dbg(&client->dev, 163 dev_dbg(&client->dev,
189 "%s: secs=%d, mins=%d, hours=%d\n", 164 "%s: secs=%d, mins=%d, hours=%d\n",
190 __FUNCTION__, 165 __func__,
191 tm->tm_sec, tm->tm_min, tm->tm_hour); 166 tm->tm_sec, tm->tm_min, tm->tm_hour);
192 167
193 buf[CCR_SEC] = BIN2BCD(tm->tm_sec); 168 buf[CCR_SEC] = BIN2BCD(tm->tm_sec);
@@ -200,7 +175,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
200 if (datetoo) { 175 if (datetoo) {
201 dev_dbg(&client->dev, 176 dev_dbg(&client->dev,
202 "%s: mday=%d, mon=%d, year=%d, wday=%d\n", 177 "%s: mday=%d, mon=%d, year=%d, wday=%d\n",
203 __FUNCTION__, 178 __func__,
204 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 179 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
205 180
206 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); 181 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday);
@@ -216,12 +191,12 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
216 191
217 /* this sequence is required to unlock the chip */ 192 /* this sequence is required to unlock the chip */
218 if ((xfer = i2c_master_send(client, wel, 3)) != 3) { 193 if ((xfer = i2c_master_send(client, wel, 3)) != 3) {
219 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer); 194 dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer);
220 return -EIO; 195 return -EIO;
221 } 196 }
222 197
223 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) { 198 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) {
224 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer); 199 dev_err(&client->dev, "%s: rwel - %d\n", __func__, xfer);
225 return -EIO; 200 return -EIO;
226 } 201 }
227 202
@@ -233,7 +208,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
233 if (xfer != 3) { 208 if (xfer != 3) {
234 dev_err(&client->dev, 209 dev_err(&client->dev,
235 "%s: xfer=%d addr=%02x, data=%02x\n", 210 "%s: xfer=%d addr=%02x, data=%02x\n",
236 __FUNCTION__, 211 __func__,
237 xfer, rdata[1], rdata[2]); 212 xfer, rdata[1], rdata[2]);
238 return -EIO; 213 return -EIO;
239 } 214 }
@@ -241,7 +216,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
241 216
242 /* disable further writes */ 217 /* disable further writes */
243 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { 218 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) {
244 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer); 219 dev_err(&client->dev, "%s: diswe - %d\n", __func__, xfer);
245 return -EIO; 220 return -EIO;
246 } 221 }
247 222
@@ -274,11 +249,11 @@ static int x1205_get_dtrim(struct i2c_client *client, int *trim)
274 249
275 /* read dtr register */ 250 /* read dtr register */
276 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 251 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
277 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 252 dev_err(&client->dev, "%s: read error\n", __func__);
278 return -EIO; 253 return -EIO;
279 } 254 }
280 255
281 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __FUNCTION__, dtr); 256 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __func__, dtr);
282 257
283 *trim = 0; 258 *trim = 0;
284 259
@@ -306,11 +281,11 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
306 281
307 /* read atr register */ 282 /* read atr register */
308 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 283 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
309 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 284 dev_err(&client->dev, "%s: read error\n", __func__);
310 return -EIO; 285 return -EIO;
311 } 286 }
312 287
313 dev_dbg(&client->dev, "%s: raw atr=%x\n", __FUNCTION__, atr); 288 dev_dbg(&client->dev, "%s: raw atr=%x\n", __func__, atr);
314 289
315 /* atr is a two's complement value on 6 bits, 290 /* atr is a two's complement value on 6 bits,
316 * perform sign extension. The formula is 291 * perform sign extension. The formula is
@@ -319,11 +294,11 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
319 if (atr & 0x20) 294 if (atr & 0x20)
320 atr |= 0xC0; 295 atr |= 0xC0;
321 296
322 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __FUNCTION__, atr, atr); 297 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr);
323 298
324 *trim = (atr * 250) + 11000; 299 *trim = (atr * 250) + 11000;
325 300
326 dev_dbg(&client->dev, "%s: real=%d\n", __FUNCTION__, *trim); 301 dev_dbg(&client->dev, "%s: real=%d\n", __func__, *trim);
327 302
328 return 0; 303 return 0;
329} 304}
@@ -377,7 +352,7 @@ static int x1205_validate_client(struct i2c_client *client)
377 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 352 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
378 dev_err(&client->dev, 353 dev_err(&client->dev,
379 "%s: could not read register %x\n", 354 "%s: could not read register %x\n",
380 __FUNCTION__, probe_zero_pattern[i]); 355 __func__, probe_zero_pattern[i]);
381 356
382 return -EIO; 357 return -EIO;
383 } 358 }
@@ -385,7 +360,7 @@ static int x1205_validate_client(struct i2c_client *client)
385 if ((buf & probe_zero_pattern[i+1]) != 0) { 360 if ((buf & probe_zero_pattern[i+1]) != 0) {
386 dev_err(&client->dev, 361 dev_err(&client->dev,
387 "%s: register=%02x, zero pattern=%d, value=%x\n", 362 "%s: register=%02x, zero pattern=%d, value=%x\n",
388 __FUNCTION__, probe_zero_pattern[i], i, buf); 363 __func__, probe_zero_pattern[i], i, buf);
389 364
390 return -ENODEV; 365 return -ENODEV;
391 } 366 }
@@ -405,7 +380,7 @@ static int x1205_validate_client(struct i2c_client *client)
405 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 380 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
406 dev_err(&client->dev, 381 dev_err(&client->dev,
407 "%s: could not read register %x\n", 382 "%s: could not read register %x\n",
408 __FUNCTION__, probe_limits_pattern[i].reg); 383 __func__, probe_limits_pattern[i].reg);
409 384
410 return -EIO; 385 return -EIO;
411 } 386 }
@@ -416,7 +391,7 @@ static int x1205_validate_client(struct i2c_client *client)
416 value < probe_limits_pattern[i].min) { 391 value < probe_limits_pattern[i].min) {
417 dev_dbg(&client->dev, 392 dev_dbg(&client->dev,
418 "%s: register=%x, lim pattern=%d, value=%d\n", 393 "%s: register=%x, lim pattern=%d, value=%d\n",
419 __FUNCTION__, probe_limits_pattern[i].reg, 394 __func__, probe_limits_pattern[i].reg,
420 i, value); 395 i, value);
421 396
422 return -ENODEV; 397 return -ENODEV;
@@ -497,58 +472,49 @@ static ssize_t x1205_sysfs_show_dtrim(struct device *dev,
497} 472}
498static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL); 473static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
499 474
500static int x1205_attach(struct i2c_adapter *adapter) 475static int x1205_sysfs_register(struct device *dev)
476{
477 int err;
478
479 err = device_create_file(dev, &dev_attr_atrim);
480 if (err)
481 return err;
482
483 err = device_create_file(dev, &dev_attr_dtrim);
484 if (err)
485 device_remove_file(dev, &dev_attr_atrim);
486
487 return err;
488}
489
490static void x1205_sysfs_unregister(struct device *dev)
501{ 491{
502 return i2c_probe(adapter, &addr_data, x1205_probe); 492 device_remove_file(dev, &dev_attr_atrim);
493 device_remove_file(dev, &dev_attr_dtrim);
503} 494}
504 495
505static int x1205_probe(struct i2c_adapter *adapter, int address, int kind) 496
497static int x1205_probe(struct i2c_client *client)
506{ 498{
507 int err = 0; 499 int err = 0;
508 unsigned char sr; 500 unsigned char sr;
509 struct i2c_client *client;
510 struct rtc_device *rtc; 501 struct rtc_device *rtc;
511 502
512 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 503 dev_dbg(&client->dev, "%s\n", __func__);
513
514 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
515 err = -ENODEV;
516 goto exit;
517 }
518
519 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
520 err = -ENOMEM;
521 goto exit;
522 }
523
524 /* I2C client */
525 client->addr = address;
526 client->driver = &x1205_driver;
527 client->adapter = adapter;
528 504
529 strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE); 505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
530 506 return -ENODEV;
531 /* Verify the chip is really an X1205 */
532 if (kind < 0) {
533 if (x1205_validate_client(client) < 0) {
534 err = -ENODEV;
535 goto exit_kfree;
536 }
537 }
538 507
539 /* Inform the i2c layer */ 508 if (x1205_validate_client(client) < 0)
540 if ((err = i2c_attach_client(client))) 509 return -ENODEV;
541 goto exit_kfree;
542 510
543 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 511 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
544 512
545 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev, 513 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
546 &x1205_rtc_ops, THIS_MODULE); 514 &x1205_rtc_ops, THIS_MODULE);
547 515
548 if (IS_ERR(rtc)) { 516 if (IS_ERR(rtc))
549 err = PTR_ERR(rtc); 517 return PTR_ERR(rtc);
550 goto exit_detach;
551 }
552 518
553 i2c_set_clientdata(client, rtc); 519 i2c_set_clientdata(client, rtc);
554 520
@@ -565,45 +531,35 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
565 else 531 else
566 dev_err(&client->dev, "couldn't read status\n"); 532 dev_err(&client->dev, "couldn't read status\n");
567 533
568 err = device_create_file(&client->dev, &dev_attr_atrim); 534 err = x1205_sysfs_register(&client->dev);
569 if (err) goto exit_devreg; 535 if (err)
570 err = device_create_file(&client->dev, &dev_attr_dtrim); 536 goto exit_devreg;
571 if (err) goto exit_atrim;
572 537
573 return 0; 538 return 0;
574 539
575exit_atrim:
576 device_remove_file(&client->dev, &dev_attr_atrim);
577
578exit_devreg: 540exit_devreg:
579 rtc_device_unregister(rtc); 541 rtc_device_unregister(rtc);
580 542
581exit_detach:
582 i2c_detach_client(client);
583
584exit_kfree:
585 kfree(client);
586
587exit:
588 return err; 543 return err;
589} 544}
590 545
591static int x1205_detach(struct i2c_client *client) 546static int x1205_remove(struct i2c_client *client)
592{ 547{
593 int err;
594 struct rtc_device *rtc = i2c_get_clientdata(client); 548 struct rtc_device *rtc = i2c_get_clientdata(client);
595 549
596 if (rtc) 550 rtc_device_unregister(rtc);
597 rtc_device_unregister(rtc); 551 x1205_sysfs_unregister(&client->dev);
598
599 if ((err = i2c_detach_client(client)))
600 return err;
601
602 kfree(client);
603
604 return 0; 552 return 0;
605} 553}
606 554
555static struct i2c_driver x1205_driver = {
556 .driver = {
557 .name = "rtc-x1205",
558 },
559 .probe = x1205_probe,
560 .remove = x1205_remove,
561};
562
607static int __init x1205_init(void) 563static int __init x1205_init(void)
608{ 564{
609 return i2c_add_driver(&x1205_driver); 565 return i2c_add_driver(&x1205_driver);