b29a6a264a1cf491152f73c241b0f45ed09f53db
[openwrt/openwrt.git] / target / linux / ixp4xx / patches-2.6.25 / 010-rtc_isl1208_new_style.patch
1 ---
2 drivers/rtc/rtc-isl1208.c | 357 +++++++++++++++++++++-------------------------
3 1 file changed, 170 insertions(+), 187 deletions(-)
4
5 Index: linux-2.6.25.4/drivers/rtc/rtc-isl1208.c
6 ===================================================================
7 --- linux-2.6.25.4.orig/drivers/rtc/rtc-isl1208.c
8 +++ linux-2.6.25.4/drivers/rtc/rtc-isl1208.c
9 @@ -15,16 +15,15 @@
10 #include <linux/bcd.h>
11 #include <linux/rtc.h>
12
13 -#define DRV_NAME "isl1208"
14 -#define DRV_VERSION "0.2"
15 +#define DRV_VERSION "0.3"
16
17 /* Register map */
18 /* rtc section */
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
29 @@ -33,14 +32,14 @@
30
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
50
51 @@ -58,39 +57,21 @@
52 #define ISL1208_REG_USR2 0x13
53 #define ISL1208_USR_SECTION_LEN 2
54
55 -/* i2c configuration */
56 -#define ISL1208_I2C_ADDR 0xde
57 -
58 -static const unsigned short normal_i2c[] = {
59 - ISL1208_I2C_ADDR>>1, I2C_CLIENT_END
60 -};
61 -I2C_CLIENT_INSMOD; /* defines addr_data */
62 -
63 -static int isl1208_attach_adapter(struct i2c_adapter *adapter);
64 -static int isl1208_detach_client(struct i2c_client *client);
65 -
66 -static struct i2c_driver isl1208_driver = {
67 - .driver = {
68 - .name = DRV_NAME,
69 - },
70 - .id = I2C_DRIVERID_ISL1208,
71 - .attach_adapter = &isl1208_attach_adapter,
72 - .detach_client = &isl1208_detach_client,
73 -};
74 +static struct i2c_driver isl1208_driver;
75
76 /* block read */
77 static int
78 isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
79 - unsigned len)
80 + unsigned len)
81 {
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}
87 + ,
88 + {client->addr, client->flags | I2C_M_RD, len, buf}
89 };
90 int ret;
91
92 - BUG_ON(len == 0);
93 BUG_ON(reg > ISL1208_REG_USR2);
94 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
95
96 @@ -103,15 +84,14 @@ isl1208_i2c_read_regs(struct i2c_client
97 /* block write */
98 static int
99 isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
100 - unsigned len)
101 + unsigned len)
102 {
103 u8 i2c_buf[ISL1208_REG_USR2 + 2];
104 struct i2c_msg msgs[1] = {
105 - { client->addr, client->flags, len + 1, i2c_buf }
106 + {client->addr, client->flags, len + 1, i2c_buf}
107 };
108 int ret;
109
110 - BUG_ON(len == 0);
111 BUG_ON(reg > ISL1208_REG_USR2);
112 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
113
114 @@ -125,7 +105,8 @@ isl1208_i2c_set_regs(struct i2c_client *
115 }
116
117 /* simple check to see wether we have a isl1208 */
118 -static int isl1208_i2c_validate_client(struct i2c_client *client)
119 +static int
120 +isl1208_i2c_validate_client(struct i2c_client *client)
121 {
122 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
123 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
124 @@ -139,24 +120,29 @@ static int isl1208_i2c_validate_client(s
125 return ret;
126
127 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
128 - if (regs[i] & zero_mask[i]) /* check if bits are cleared */
129 + if (regs[i] & zero_mask[i]) /* check if bits are cleared */
130 return -ENODEV;
131 }
132
133 return 0;
134 }
135
136 -static int isl1208_i2c_get_sr(struct i2c_client *client)
137 +static int
138 +isl1208_i2c_get_sr(struct i2c_client *client)
139 {
140 - return i2c_smbus_read_byte_data(client, ISL1208_REG_SR) == -1 ? -EIO:0;
141 + int sr = i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
142 + if (sr < 0)
143 + return -EIO;
144 +
145 + return sr;
146 }
147
148 -static int isl1208_i2c_get_atr(struct i2c_client *client)
149 +static int
150 +isl1208_i2c_get_atr(struct i2c_client *client)
151 {
152 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
153 -
154 if (atr < 0)
155 - return -EIO;
156 + return atr;
157
158 /* The 6bit value in the ATR register controls the load
159 * capacitance C_load * in steps of 0.25pF
160 @@ -169,51 +155,54 @@ static int isl1208_i2c_get_atr(struct i2
161 *
162 */
163
164 - atr &= 0x3f; /* mask out lsb */
165 - atr ^= 1<<5; /* invert 6th bit */
166 - atr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
167 + atr &= 0x3f; /* mask out lsb */
168 + atr ^= 1 << 5; /* invert 6th bit */
169 + atr += 2 * 9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
170
171 return atr;
172 }
173
174 -static int isl1208_i2c_get_dtr(struct i2c_client *client)
175 +static int
176 +isl1208_i2c_get_dtr(struct i2c_client *client)
177 {
178 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
179 -
180 if (dtr < 0)
181 return -EIO;
182
183 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
184 - dtr = ((dtr & 0x3) * 20) * (dtr & (1<<2) ? -1 : 1);
185 + dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
186
187 return dtr;
188 }
189
190 -static int isl1208_i2c_get_usr(struct i2c_client *client)
191 +static int
192 +isl1208_i2c_get_usr(struct i2c_client *client)
193 {
194 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
195 int ret;
196
197 - ret = isl1208_i2c_read_regs (client, ISL1208_REG_USR1, buf,
198 - ISL1208_USR_SECTION_LEN);
199 + ret = isl1208_i2c_read_regs(client, ISL1208_REG_USR1, buf,
200 + ISL1208_USR_SECTION_LEN);
201 if (ret < 0)
202 return ret;
203
204 return (buf[1] << 8) | buf[0];
205 }
206
207 -static int isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
208 +static int
209 +isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
210 {
211 u8 buf[ISL1208_USR_SECTION_LEN];
212
213 buf[0] = usr & 0xff;
214 buf[1] = (usr >> 8) & 0xff;
215
216 - return isl1208_i2c_set_regs (client, ISL1208_REG_USR1, buf,
217 - ISL1208_USR_SECTION_LEN);
218 + return isl1208_i2c_set_regs(client, ISL1208_REG_USR1, buf,
219 + ISL1208_USR_SECTION_LEN);
220 }
221
222 -static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
223 +static int
224 +isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
225 {
226 struct i2c_client *const client = to_i2c_client(dev);
227 int sr, dtr, atr, usr;
228 @@ -230,20 +219,19 @@ static int isl1208_rtc_proc(struct devic
229 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
230 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
231 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
232 - (sr & ISL1208_REG_SR_ARST) ? " ARST" : "",
233 - sr);
234 + (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", sr);
235
236 seq_printf(seq, "batt_status\t: %s\n",
237 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
238
239 dtr = isl1208_i2c_get_dtr(client);
240 - if (dtr >= 0 -1)
241 + if (dtr >= 0 - 1)
242 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr);
243
244 atr = isl1208_i2c_get_atr(client);
245 if (atr >= 0)
246 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
247 - atr>>2, (atr&0x3)*25);
248 + atr >> 2, (atr & 0x3) * 25);
249
250 usr = isl1208_i2c_get_usr(client);
251 if (usr >= 0)
252 @@ -252,9 +240,8 @@ static int isl1208_rtc_proc(struct devic
253 return 0;
254 }
255
256 -
257 -static int isl1208_i2c_read_time(struct i2c_client *client,
258 - struct rtc_time *tm)
259 +static int
260 +isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
261 {
262 int sr;
263 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
264 @@ -274,27 +261,30 @@ static int isl1208_i2c_read_time(struct
265
266 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]);
267 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]);
268 - { /* HR field has a more complex interpretation */
269 +
270 + /* HR field has a more complex interpretation */
271 + {
272 const u8 _hr = regs[ISL1208_REG_HR];
273 - if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
274 + if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
275 tm->tm_hour = BCD2BIN(_hr & 0x3f);
276 - else { // 12h format
277 + else {
278 + /* 12h format */
279 tm->tm_hour = BCD2BIN(_hr & 0x1f);
280 - if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
281 + if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
282 tm->tm_hour += 12;
283 }
284 }
285
286 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]);
287 - tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
288 + tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
289 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100;
290 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]);
291
292 return 0;
293 }
294
295 -static int isl1208_i2c_read_alarm(struct i2c_client *client,
296 - struct rtc_wkalrm *alarm)
297 +static int
298 +isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
299 {
300 struct rtc_time *const tm = &alarm->time;
301 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
302 @@ -307,7 +297,7 @@ static int isl1208_i2c_read_alarm(struct
303 }
304
305 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
306 - ISL1208_ALARM_SECTION_LEN);
307 + ISL1208_ALARM_SECTION_LEN);
308 if (sr < 0) {
309 dev_err(&client->dev, "%s: reading alarm section failed\n",
310 __func__);
311 @@ -315,23 +305,25 @@ static int isl1208_i2c_read_alarm(struct
312 }
313
314 /* MSB of each alarm register is an enable bit */
315 - tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA-ISL1208_REG_SCA] & 0x7f);
316 - tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA-ISL1208_REG_SCA] & 0x7f);
317 - tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA-ISL1208_REG_SCA] & 0x3f);
318 - tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA-ISL1208_REG_SCA] & 0x3f);
319 - tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MOA-ISL1208_REG_SCA] & 0x1f)-1;
320 - tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA-ISL1208_REG_SCA] & 0x03);
321 + tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
322 + tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
323 + tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
324 + tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
325 + tm->tm_mon =
326 + BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
327 + tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
328
329 return 0;
330 }
331
332 -static int isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
333 +static int
334 +isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
335 {
336 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
337 }
338
339 -static int isl1208_i2c_set_time(struct i2c_client *client,
340 - struct rtc_time const *tm)
341 +static int
342 +isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
343 {
344 int sr;
345 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
346 @@ -353,7 +345,7 @@ static int isl1208_i2c_set_time(struct i
347 }
348
349 /* set WRTC */
350 - sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
351 + sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
352 sr | ISL1208_REG_SR_WRTC);
353 if (sr < 0) {
354 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
355 @@ -369,7 +361,7 @@ static int isl1208_i2c_set_time(struct i
356 }
357
358 /* clear WRTC again */
359 - sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
360 + sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
361 sr & ~ISL1208_REG_SR_WRTC);
362 if (sr < 0) {
363 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
364 @@ -380,70 +372,69 @@ static int isl1208_i2c_set_time(struct i
365 }
366
367
368 -static int isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
369 +static int
370 +isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
371 {
372 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
373 }
374
375 -static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
376 +static int
377 +isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
378 {
379 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
380 }
381
382 static const struct rtc_class_ops isl1208_rtc_ops = {
383 - .proc = isl1208_rtc_proc,
384 - .read_time = isl1208_rtc_read_time,
385 - .set_time = isl1208_rtc_set_time,
386 - .read_alarm = isl1208_rtc_read_alarm,
387 - //.set_alarm = isl1208_rtc_set_alarm,
388 + .proc = isl1208_rtc_proc,
389 + .read_time = isl1208_rtc_read_time,
390 + .set_time = isl1208_rtc_set_time,
391 + .read_alarm = isl1208_rtc_read_alarm,
392 + /*.set_alarm = isl1208_rtc_set_alarm, */
393 };
394
395 /* sysfs interface */
396
397 -static ssize_t isl1208_sysfs_show_atrim(struct device *dev,
398 - struct device_attribute *attr,
399 - char *buf)
400 +static ssize_t
401 +isl1208_sysfs_show_atrim(struct device *dev,
402 + struct device_attribute *attr, char *buf)
403 {
404 - int atr;
405 -
406 - atr = isl1208_i2c_get_atr(to_i2c_client(dev));
407 + int atr = isl1208_i2c_get_atr(to_i2c_client(dev));
408 if (atr < 0)
409 return atr;
410
411 - return sprintf(buf, "%d.%.2d pF\n", atr>>2, (atr&0x3)*25);
412 + return sprintf(buf, "%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
413 }
414 +
415 static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
416
417 -static ssize_t isl1208_sysfs_show_dtrim(struct device *dev,
418 - struct device_attribute *attr,
419 - char *buf)
420 +static ssize_t
421 +isl1208_sysfs_show_dtrim(struct device *dev,
422 + struct device_attribute *attr, char *buf)
423 {
424 - int dtr;
425 -
426 - dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
427 + int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
428 if (dtr < 0)
429 return dtr;
430
431 return sprintf(buf, "%d ppm\n", dtr);
432 }
433 +
434 static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
435
436 -static ssize_t isl1208_sysfs_show_usr(struct device *dev,
437 - struct device_attribute *attr,
438 - char *buf)
439 +static ssize_t
440 +isl1208_sysfs_show_usr(struct device *dev,
441 + struct device_attribute *attr, char *buf)
442 {
443 - int usr;
444 -
445 - usr = isl1208_i2c_get_usr(to_i2c_client(dev));
446 + int usr = isl1208_i2c_get_usr(to_i2c_client(dev));
447 if (usr < 0)
448 return usr;
449
450 return sprintf(buf, "0x%.4x\n", usr);
451 }
452
453 -static ssize_t isl1208_sysfs_store_usr(struct device *dev,
454 - struct device_attribute *attr,
455 - const char *buf, size_t count)
456 +static ssize_t
457 +isl1208_sysfs_store_usr(struct device *dev,
458 + struct device_attribute *attr,
459 + const char *buf, size_t count)
460 {
461 int usr = -1;
462
463 @@ -460,124 +451,116 @@ static ssize_t isl1208_sysfs_store_usr(s
464
465 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
466 }
467 +
468 static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
469 isl1208_sysfs_store_usr);
470
471 static int
472 -isl1208_probe(struct i2c_adapter *adapter, int addr, int kind)
473 +isl1208_sysfs_register(struct device *dev)
474 {
475 - int rc = 0;
476 - struct i2c_client *new_client = NULL;
477 - struct rtc_device *rtc = NULL;
478 + int err;
479 +
480 + err = device_create_file(dev, &dev_attr_atrim);
481 + if (err)
482 + return err;
483
484 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
485 - rc = -ENODEV;
486 - goto failout;
487 + err = device_create_file(dev, &dev_attr_dtrim);
488 + if (err) {
489 + device_remove_file(dev, &dev_attr_atrim);
490 + return err;
491 }
492
493 - new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
494 - if (new_client == NULL) {
495 - rc = -ENOMEM;
496 - goto failout;
497 + err = device_create_file(dev, &dev_attr_usr);
498 + if (err) {
499 + device_remove_file(dev, &dev_attr_atrim);
500 + device_remove_file(dev, &dev_attr_dtrim);
501 }
502
503 - new_client->addr = addr;
504 - new_client->adapter = adapter;
505 - new_client->driver = &isl1208_driver;
506 - new_client->flags = 0;
507 - strcpy(new_client->name, DRV_NAME);
508 + return 0;
509 +}
510
511 - if (kind < 0) {
512 - rc = isl1208_i2c_validate_client(new_client);
513 - if (rc < 0)
514 - goto failout;
515 - }
516 +static int
517 +isl1208_sysfs_unregister(struct device *dev)
518 +{
519 + device_remove_file(dev, &dev_attr_atrim);
520 + device_remove_file(dev, &dev_attr_atrim);
521 + device_remove_file(dev, &dev_attr_usr);
522 +
523 + return 0;
524 +}
525 +
526 +static int
527 +isl1208_probe(struct i2c_client *client)
528 +{
529 + int rc = 0;
530 + struct rtc_device *rtc;
531
532 - rc = i2c_attach_client(new_client);
533 - if (rc < 0)
534 - goto failout;
535 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
536 + return -ENODEV;
537
538 - dev_info(&new_client->dev,
539 + if (isl1208_i2c_validate_client(client) < 0)
540 + return -ENODEV;
541 +
542 + dev_info(&client->dev,
543 "chip found, driver version " DRV_VERSION "\n");
544
545 rtc = rtc_device_register(isl1208_driver.driver.name,
546 - &new_client->dev,
547 - &isl1208_rtc_ops, THIS_MODULE);
548 -
549 - if (IS_ERR(rtc)) {
550 - rc = PTR_ERR(rtc);
551 - goto failout_detach;
552 - }
553 + &client->dev, &isl1208_rtc_ops,
554 + THIS_MODULE);
555 + if (IS_ERR(rtc))
556 + return PTR_ERR(rtc);
557
558 - i2c_set_clientdata(new_client, rtc);
559 + i2c_set_clientdata(client, rtc);
560
561 - rc = isl1208_i2c_get_sr(new_client);
562 + rc = isl1208_i2c_get_sr(client);
563 if (rc < 0) {
564 - dev_err(&new_client->dev, "reading status failed\n");
565 - goto failout_unregister;
566 + dev_err(&client->dev, "reading status failed\n");
567 + goto exit_unregister;
568 }
569
570 if (rc & ISL1208_REG_SR_RTCF)
571 - dev_warn(&new_client->dev, "rtc power failure detected, "
572 + dev_warn(&client->dev, "rtc power failure detected, "
573 "please set clock.\n");
574
575 - rc = device_create_file(&new_client->dev, &dev_attr_atrim);
576 - if (rc < 0)
577 - goto failout_unregister;
578 - rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
579 - if (rc < 0)
580 - goto failout_atrim;
581 - rc = device_create_file(&new_client->dev, &dev_attr_usr);
582 - if (rc < 0)
583 - goto failout_dtrim;
584 + rc = isl1208_sysfs_register(&client->dev);
585 + if (rc)
586 + goto exit_unregister;
587
588 return 0;
589
590 - failout_dtrim:
591 - device_remove_file(&new_client->dev, &dev_attr_dtrim);
592 - failout_atrim:
593 - device_remove_file(&new_client->dev, &dev_attr_atrim);
594 - failout_unregister:
595 + exit_unregister:
596 rtc_device_unregister(rtc);
597 - failout_detach:
598 - i2c_detach_client(new_client);
599 - failout:
600 - kfree(new_client);
601 - return rc;
602 -}
603
604 -static int
605 -isl1208_attach_adapter (struct i2c_adapter *adapter)
606 -{
607 - return i2c_probe(adapter, &addr_data, isl1208_probe);
608 + return rc;
609 }
610
611 static int
612 -isl1208_detach_client(struct i2c_client *client)
613 +isl1208_remove(struct i2c_client *client)
614 {
615 - int rc;
616 - struct rtc_device *const rtc = i2c_get_clientdata(client);
617 -
618 - if (rtc)
619 - rtc_device_unregister(rtc); /* do we need to kfree? */
620 -
621 - rc = i2c_detach_client(client);
622 - if (rc)
623 - return rc;
624 + struct rtc_device *rtc = i2c_get_clientdata(client);
625
626 - kfree(client);
627 + isl1208_sysfs_unregister(&client->dev);
628 + rtc_device_unregister(rtc);
629
630 return 0;
631 }
632
633 -/* module management */
634 +static struct i2c_driver isl1208_driver = {
635 + .driver = {
636 + .name = "rtc-isl1208",
637 + },
638 + .probe = isl1208_probe,
639 + .remove = isl1208_remove,
640 +};
641
642 -static int __init isl1208_init(void)
643 +static int __init
644 +isl1208_init(void)
645 {
646 return i2c_add_driver(&isl1208_driver);
647 }
648
649 -static void __exit isl1208_exit(void)
650 +static void __exit
651 +isl1208_exit(void)
652 {
653 i2c_del_driver(&isl1208_driver);
654 }