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