generate package for the new IXP4xx crpyto driver
[openwrt/svn-archive/archive.git] / target / linux / ixp4xx / patches-2.6.24 / 010-rtc_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.24.7/drivers/rtc/rtc-isl1208.c
6 ===================================================================
7 --- linux-2.6.24.7.orig/drivers/rtc/rtc-isl1208.c
8 +++ linux-2.6.24.7/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,35 +57,18 @@
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 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 @@ -103,15 +85,14 @@ isl1208_i2c_read_regs(struct i2c_client
93 /* block write */
94 static int
95 isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
96 - unsigned len)
97 + unsigned len)
98 {
99 u8 i2c_buf[ISL1208_REG_USR2 + 2];
100 struct i2c_msg msgs[1] = {
101 - { client->addr, client->flags, len + 1, i2c_buf }
102 + {client->addr, client->flags, len + 1, i2c_buf}
103 };
104 int ret;
105
106 - BUG_ON(len == 0);
107 BUG_ON(reg > ISL1208_REG_USR2);
108 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
109
110 @@ -125,7 +106,8 @@ isl1208_i2c_set_regs(struct i2c_client *
111 }
112
113 /* simple check to see wether we have a isl1208 */
114 -static int isl1208_i2c_validate_client(struct i2c_client *client)
115 +static int
116 +isl1208_i2c_validate_client(struct i2c_client *client)
117 {
118 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
119 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
120 @@ -139,24 +121,29 @@ static int isl1208_i2c_validate_client(s
121 return ret;
122
123 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
124 - if (regs[i] & zero_mask[i]) /* check if bits are cleared */
125 + if (regs[i] & zero_mask[i]) /* check if bits are cleared */
126 return -ENODEV;
127 }
128
129 return 0;
130 }
131
132 -static int isl1208_i2c_get_sr(struct i2c_client *client)
133 +static int
134 +isl1208_i2c_get_sr(struct i2c_client *client)
135 {
136 - return i2c_smbus_read_byte_data(client, ISL1208_REG_SR) == -1 ? -EIO:0;
137 + int sr = i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
138 + if (sr < 0)
139 + return -EIO;
140 +
141 + return sr;
142 }
143
144 -static int isl1208_i2c_get_atr(struct i2c_client *client)
145 +static int
146 +isl1208_i2c_get_atr(struct i2c_client *client)
147 {
148 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
149 -
150 if (atr < 0)
151 - return -EIO;
152 + return atr;
153
154 /* The 6bit value in the ATR register controls the load
155 * capacitance C_load * in steps of 0.25pF
156 @@ -169,51 +156,54 @@ static int isl1208_i2c_get_atr(struct i2
157 *
158 */
159
160 - atr &= 0x3f; /* mask out lsb */
161 - atr ^= 1<<5; /* invert 6th bit */
162 - atr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
163 + atr &= 0x3f; /* mask out lsb */
164 + atr ^= 1 << 5; /* invert 6th bit */
165 + atr += 2 * 9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
166
167 return atr;
168 }
169
170 -static int isl1208_i2c_get_dtr(struct i2c_client *client)
171 +static int
172 +isl1208_i2c_get_dtr(struct i2c_client *client)
173 {
174 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
175 -
176 if (dtr < 0)
177 return -EIO;
178
179 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
180 - dtr = ((dtr & 0x3) * 20) * (dtr & (1<<2) ? -1 : 1);
181 + dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
182
183 return dtr;
184 }
185
186 -static int isl1208_i2c_get_usr(struct i2c_client *client)
187 +static int
188 +isl1208_i2c_get_usr(struct i2c_client *client)
189 {
190 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
191 int ret;
192
193 - ret = isl1208_i2c_read_regs (client, ISL1208_REG_USR1, buf,
194 - ISL1208_USR_SECTION_LEN);
195 + ret = isl1208_i2c_read_regs(client, ISL1208_REG_USR1, buf,
196 + ISL1208_USR_SECTION_LEN);
197 if (ret < 0)
198 return ret;
199
200 return (buf[1] << 8) | buf[0];
201 }
202
203 -static int isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
204 +static int
205 +isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
206 {
207 u8 buf[ISL1208_USR_SECTION_LEN];
208
209 buf[0] = usr & 0xff;
210 buf[1] = (usr >> 8) & 0xff;
211
212 - return isl1208_i2c_set_regs (client, ISL1208_REG_USR1, buf,
213 - ISL1208_USR_SECTION_LEN);
214 + return isl1208_i2c_set_regs(client, ISL1208_REG_USR1, buf,
215 + ISL1208_USR_SECTION_LEN);
216 }
217
218 -static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
219 +static int
220 +isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
221 {
222 struct i2c_client *const client = to_i2c_client(dev);
223 int sr, dtr, atr, usr;
224 @@ -230,20 +220,19 @@ static int isl1208_rtc_proc(struct devic
225 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
226 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
227 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
228 - (sr & ISL1208_REG_SR_ARST) ? " ARST" : "",
229 - sr);
230 + (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", sr);
231
232 seq_printf(seq, "batt_status\t: %s\n",
233 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
234
235 dtr = isl1208_i2c_get_dtr(client);
236 - if (dtr >= 0 -1)
237 + if (dtr >= 0 - 1)
238 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr);
239
240 atr = isl1208_i2c_get_atr(client);
241 if (atr >= 0)
242 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
243 - atr>>2, (atr&0x3)*25);
244 + atr >> 2, (atr & 0x3) * 25);
245
246 usr = isl1208_i2c_get_usr(client);
247 if (usr >= 0)
248 @@ -252,9 +241,8 @@ static int isl1208_rtc_proc(struct devic
249 return 0;
250 }
251
252 -
253 -static int isl1208_i2c_read_time(struct i2c_client *client,
254 - struct rtc_time *tm)
255 +static int
256 +isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
257 {
258 int sr;
259 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
260 @@ -274,27 +262,30 @@ static int isl1208_i2c_read_time(struct
261
262 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]);
263 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]);
264 - { /* HR field has a more complex interpretation */
265 +
266 + /* HR field has a more complex interpretation */
267 + {
268 const u8 _hr = regs[ISL1208_REG_HR];
269 - if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
270 + if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
271 tm->tm_hour = BCD2BIN(_hr & 0x3f);
272 - else { // 12h format
273 + else {
274 + /* 12h format */
275 tm->tm_hour = BCD2BIN(_hr & 0x1f);
276 - if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
277 + if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
278 tm->tm_hour += 12;
279 }
280 }
281
282 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]);
283 - tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
284 + tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
285 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100;
286 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]);
287
288 return 0;
289 }
290
291 -static int isl1208_i2c_read_alarm(struct i2c_client *client,
292 - struct rtc_wkalrm *alarm)
293 +static int
294 +isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
295 {
296 struct rtc_time *const tm = &alarm->time;
297 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
298 @@ -307,7 +298,7 @@ static int isl1208_i2c_read_alarm(struct
299 }
300
301 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
302 - ISL1208_ALARM_SECTION_LEN);
303 + ISL1208_ALARM_SECTION_LEN);
304 if (sr < 0) {
305 dev_err(&client->dev, "%s: reading alarm section failed\n",
306 __func__);
307 @@ -315,23 +306,25 @@ static int isl1208_i2c_read_alarm(struct
308 }
309
310 /* MSB of each alarm register is an enable bit */
311 - tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA-ISL1208_REG_SCA] & 0x7f);
312 - tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA-ISL1208_REG_SCA] & 0x7f);
313 - tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA-ISL1208_REG_SCA] & 0x3f);
314 - tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA-ISL1208_REG_SCA] & 0x3f);
315 - tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MOA-ISL1208_REG_SCA] & 0x1f)-1;
316 - tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA-ISL1208_REG_SCA] & 0x03);
317 + tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
318 + tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
319 + tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
320 + tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
321 + tm->tm_mon =
322 + BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
323 + tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
324
325 return 0;
326 }
327
328 -static int isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
329 +static int
330 +isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
331 {
332 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
333 }
334
335 -static int isl1208_i2c_set_time(struct i2c_client *client,
336 - struct rtc_time const *tm)
337 +static int
338 +isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
339 {
340 int sr;
341 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
342 @@ -353,7 +346,7 @@ static int isl1208_i2c_set_time(struct i
343 }
344
345 /* set WRTC */
346 - sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
347 + sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
348 sr | ISL1208_REG_SR_WRTC);
349 if (sr < 0) {
350 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
351 @@ -369,7 +362,7 @@ static int isl1208_i2c_set_time(struct i
352 }
353
354 /* clear WRTC again */
355 - sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
356 + sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
357 sr & ~ISL1208_REG_SR_WRTC);
358 if (sr < 0) {
359 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
360 @@ -380,70 +373,69 @@ static int isl1208_i2c_set_time(struct i
361 }
362
363
364 -static int isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
365 +static int
366 +isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
367 {
368 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
369 }
370
371 -static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
372 +static int
373 +isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
374 {
375 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
376 }
377
378 static const struct rtc_class_ops isl1208_rtc_ops = {
379 - .proc = isl1208_rtc_proc,
380 - .read_time = isl1208_rtc_read_time,
381 - .set_time = isl1208_rtc_set_time,
382 - .read_alarm = isl1208_rtc_read_alarm,
383 - //.set_alarm = isl1208_rtc_set_alarm,
384 + .proc = isl1208_rtc_proc,
385 + .read_time = isl1208_rtc_read_time,
386 + .set_time = isl1208_rtc_set_time,
387 + .read_alarm = isl1208_rtc_read_alarm,
388 + /*.set_alarm = isl1208_rtc_set_alarm, */
389 };
390
391 /* sysfs interface */
392
393 -static ssize_t isl1208_sysfs_show_atrim(struct device *dev,
394 - struct device_attribute *attr,
395 - char *buf)
396 +static ssize_t
397 +isl1208_sysfs_show_atrim(struct device *dev,
398 + struct device_attribute *attr, char *buf)
399 {
400 - int atr;
401 -
402 - atr = isl1208_i2c_get_atr(to_i2c_client(dev));
403 + int atr = isl1208_i2c_get_atr(to_i2c_client(dev));
404 if (atr < 0)
405 return atr;
406
407 - return sprintf(buf, "%d.%.2d pF\n", atr>>2, (atr&0x3)*25);
408 + return sprintf(buf, "%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
409 }
410 +
411 static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
412
413 -static ssize_t isl1208_sysfs_show_dtrim(struct device *dev,
414 - struct device_attribute *attr,
415 - char *buf)
416 +static ssize_t
417 +isl1208_sysfs_show_dtrim(struct device *dev,
418 + struct device_attribute *attr, char *buf)
419 {
420 - int dtr;
421 -
422 - dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
423 + int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
424 if (dtr < 0)
425 return dtr;
426
427 return sprintf(buf, "%d ppm\n", dtr);
428 }
429 +
430 static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
431
432 -static ssize_t isl1208_sysfs_show_usr(struct device *dev,
433 - struct device_attribute *attr,
434 - char *buf)
435 +static ssize_t
436 +isl1208_sysfs_show_usr(struct device *dev,
437 + struct device_attribute *attr, char *buf)
438 {
439 - int usr;
440 -
441 - usr = isl1208_i2c_get_usr(to_i2c_client(dev));
442 + int usr = isl1208_i2c_get_usr(to_i2c_client(dev));
443 if (usr < 0)
444 return usr;
445
446 return sprintf(buf, "0x%.4x\n", usr);
447 }
448
449 -static ssize_t isl1208_sysfs_store_usr(struct device *dev,
450 - struct device_attribute *attr,
451 - const char *buf, size_t count)
452 +static ssize_t
453 +isl1208_sysfs_store_usr(struct device *dev,
454 + struct device_attribute *attr,
455 + const char *buf, size_t count)
456 {
457 int usr = -1;
458
459 @@ -460,124 +452,116 @@ static ssize_t isl1208_sysfs_store_usr(s
460
461 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
462 }
463 +
464 static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
465 isl1208_sysfs_store_usr);
466
467 static int
468 -isl1208_probe(struct i2c_adapter *adapter, int addr, int kind)
469 +isl1208_sysfs_register(struct device *dev)
470 {
471 - int rc = 0;
472 - struct i2c_client *new_client = NULL;
473 - struct rtc_device *rtc = NULL;
474 + int err;
475 +
476 + err = device_create_file(dev, &dev_attr_atrim);
477 + if (err)
478 + return err;
479
480 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
481 - rc = -ENODEV;
482 - goto failout;
483 + err = device_create_file(dev, &dev_attr_dtrim);
484 + if (err) {
485 + device_remove_file(dev, &dev_attr_atrim);
486 + return err;
487 }
488
489 - new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
490 - if (new_client == NULL) {
491 - rc = -ENOMEM;
492 - goto failout;
493 + err = device_create_file(dev, &dev_attr_usr);
494 + if (err) {
495 + device_remove_file(dev, &dev_attr_atrim);
496 + device_remove_file(dev, &dev_attr_dtrim);
497 }
498
499 - new_client->addr = addr;
500 - new_client->adapter = adapter;
501 - new_client->driver = &isl1208_driver;
502 - new_client->flags = 0;
503 - strcpy(new_client->name, DRV_NAME);
504 + return 0;
505 +}
506
507 - if (kind < 0) {
508 - rc = isl1208_i2c_validate_client(new_client);
509 - if (rc < 0)
510 - goto failout;
511 - }
512 +static int
513 +isl1208_sysfs_unregister(struct device *dev)
514 +{
515 + device_remove_file(dev, &dev_attr_atrim);
516 + device_remove_file(dev, &dev_attr_atrim);
517 + device_remove_file(dev, &dev_attr_usr);
518 +
519 + return 0;
520 +}
521 +
522 +static int
523 +isl1208_probe(struct i2c_client *client)
524 +{
525 + int rc = 0;
526 + struct rtc_device *rtc;
527
528 - rc = i2c_attach_client(new_client);
529 - if (rc < 0)
530 - goto failout;
531 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
532 + return -ENODEV;
533
534 - dev_info(&new_client->dev,
535 + if (isl1208_i2c_validate_client(client) < 0)
536 + return -ENODEV;
537 +
538 + dev_info(&client->dev,
539 "chip found, driver version " DRV_VERSION "\n");
540
541 rtc = rtc_device_register(isl1208_driver.driver.name,
542 - &new_client->dev,
543 - &isl1208_rtc_ops, THIS_MODULE);
544 -
545 - if (IS_ERR(rtc)) {
546 - rc = PTR_ERR(rtc);
547 - goto failout_detach;
548 - }
549 + &client->dev, &isl1208_rtc_ops,
550 + THIS_MODULE);
551 + if (IS_ERR(rtc))
552 + return PTR_ERR(rtc);
553
554 - i2c_set_clientdata(new_client, rtc);
555 + i2c_set_clientdata(client, rtc);
556
557 - rc = isl1208_i2c_get_sr(new_client);
558 + rc = isl1208_i2c_get_sr(client);
559 if (rc < 0) {
560 - dev_err(&new_client->dev, "reading status failed\n");
561 - goto failout_unregister;
562 + dev_err(&client->dev, "reading status failed\n");
563 + goto exit_unregister;
564 }
565
566 if (rc & ISL1208_REG_SR_RTCF)
567 - dev_warn(&new_client->dev, "rtc power failure detected, "
568 + dev_warn(&client->dev, "rtc power failure detected, "
569 "please set clock.\n");
570
571 - rc = device_create_file(&new_client->dev, &dev_attr_atrim);
572 - if (rc < 0)
573 - goto failout_unregister;
574 - rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
575 - if (rc < 0)
576 - goto failout_atrim;
577 - rc = device_create_file(&new_client->dev, &dev_attr_usr);
578 - if (rc < 0)
579 - goto failout_dtrim;
580 + rc = isl1208_sysfs_register(&client->dev);
581 + if (rc)
582 + goto exit_unregister;
583
584 return 0;
585
586 - failout_dtrim:
587 - device_remove_file(&new_client->dev, &dev_attr_dtrim);
588 - failout_atrim:
589 - device_remove_file(&new_client->dev, &dev_attr_atrim);
590 - failout_unregister:
591 + exit_unregister:
592 rtc_device_unregister(rtc);
593 - failout_detach:
594 - i2c_detach_client(new_client);
595 - failout:
596 - kfree(new_client);
597 - return rc;
598 -}
599
600 -static int
601 -isl1208_attach_adapter (struct i2c_adapter *adapter)
602 -{
603 - return i2c_probe(adapter, &addr_data, isl1208_probe);
604 + return rc;
605 }
606
607 static int
608 -isl1208_detach_client(struct i2c_client *client)
609 +isl1208_remove(struct i2c_client *client)
610 {
611 - int rc;
612 - struct rtc_device *const rtc = i2c_get_clientdata(client);
613 -
614 - if (rtc)
615 - rtc_device_unregister(rtc); /* do we need to kfree? */
616 -
617 - rc = i2c_detach_client(client);
618 - if (rc)
619 - return rc;
620 + struct rtc_device *rtc = i2c_get_clientdata(client);
621
622 - kfree(client);
623 + isl1208_sysfs_unregister(&client->dev);
624 + rtc_device_unregister(rtc);
625
626 return 0;
627 }
628
629 -/* module management */
630 +static struct i2c_driver isl1208_driver = {
631 + .driver = {
632 + .name = "rtc-isl1208",
633 + },
634 + .probe = isl1208_probe,
635 + .remove = isl1208_remove,
636 +};
637
638 -static int __init isl1208_init(void)
639 +static int __init
640 +isl1208_init(void)
641 {
642 return i2c_add_driver(&isl1208_driver);
643 }
644
645 -static void __exit isl1208_exit(void)
646 +static void __exit
647 +isl1208_exit(void)
648 {
649 i2c_del_driver(&isl1208_driver);
650 }
651 Index: linux-2.6.24.7/drivers/rtc/rtc-pcf8563.c
652 ===================================================================
653 --- linux-2.6.24.7.orig/drivers/rtc/rtc-pcf8563.c
654 +++ linux-2.6.24.7/drivers/rtc/rtc-pcf8563.c
655 @@ -18,17 +18,7 @@
656 #include <linux/bcd.h>
657 #include <linux/rtc.h>
658
659 -#define DRV_VERSION "0.4.2"
660 -
661 -/* Addresses to scan: none
662 - * This chip cannot be reliably autodetected. An empty eeprom
663 - * located at 0x51 will pass the validation routine due to
664 - * the way the registers are implemented.
665 - */
666 -static unsigned short normal_i2c[] = { I2C_CLIENT_END };
667 -
668 -/* Module parameters */
669 -I2C_CLIENT_INSMOD;
670 +#define DRV_VERSION "0.4.3"
671
672 #define PCF8563_REG_ST1 0x00 /* status */
673 #define PCF8563_REG_ST2 0x01
674 @@ -53,8 +43,10 @@ I2C_CLIENT_INSMOD;
675 #define PCF8563_SC_LV 0x80 /* low voltage */
676 #define PCF8563_MO_C 0x80 /* century */
677
678 +static struct i2c_driver pcf8563_driver;
679 +
680 struct pcf8563 {
681 - struct i2c_client client;
682 + struct rtc_device *rtc;
683 /*
684 * The meaning of MO_C bit varies by the chip type.
685 * From PCF8563 datasheet: this bit is toggled when the years
686 @@ -72,16 +64,13 @@ struct pcf8563 {
687 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
688 };
689
690 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
691 -static int pcf8563_detach(struct i2c_client *client);
692 -
693 /*
694 * In the routines that deal directly with the pcf8563 hardware, we use
695 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
696 */
697 static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
698 {
699 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
700 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
701 unsigned char buf[13] = { PCF8563_REG_ST1 };
702
703 struct i2c_msg msgs[] = {
704 @@ -138,7 +127,7 @@ static int pcf8563_get_datetime(struct i
705
706 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
707 {
708 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
709 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
710 int i, err;
711 unsigned char buf[9];
712
713 @@ -257,100 +246,66 @@ static const struct rtc_class_ops pcf856
714 .set_time = pcf8563_rtc_set_time,
715 };
716
717 -static int pcf8563_attach(struct i2c_adapter *adapter)
718 -{
719 - return i2c_probe(adapter, &addr_data, pcf8563_probe);
720 -}
721 -
722 -static struct i2c_driver pcf8563_driver = {
723 - .driver = {
724 - .name = "pcf8563",
725 - },
726 - .id = I2C_DRIVERID_PCF8563,
727 - .attach_adapter = &pcf8563_attach,
728 - .detach_client = &pcf8563_detach,
729 -};
730 -
731 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
732 +static int pcf8563_probe(struct i2c_client *client)
733 {
734 struct pcf8563 *pcf8563;
735 - struct i2c_client *client;
736 - struct rtc_device *rtc;
737
738 int err = 0;
739
740 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
741 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
742
743 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
744 - err = -ENODEV;
745 - goto exit;
746 - }
747 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
748 + return -ENODEV;
749
750 - if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) {
751 - err = -ENOMEM;
752 - goto exit;
753 - }
754 -
755 - client = &pcf8563->client;
756 - client->addr = address;
757 - client->driver = &pcf8563_driver;
758 - client->adapter = adapter;
759 -
760 - strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
761 + if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL)))
762 + return -ENOMEM;
763
764 /* Verify the chip is really an PCF8563 */
765 - if (kind < 0) {
766 - if (pcf8563_validate_client(client) < 0) {
767 - err = -ENODEV;
768 - goto exit_kfree;
769 - }
770 - }
771 -
772 - /* Inform the i2c layer */
773 - if ((err = i2c_attach_client(client)))
774 + if (pcf8563_validate_client(client) < 0) {
775 + err = -ENODEV;
776 goto exit_kfree;
777 + }
778
779 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
780
781 - rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
782 + pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
783 &pcf8563_rtc_ops, THIS_MODULE);
784
785 - if (IS_ERR(rtc)) {
786 - err = PTR_ERR(rtc);
787 - goto exit_detach;
788 + if (IS_ERR(pcf8563->rtc)) {
789 + err = PTR_ERR(pcf8563->rtc);
790 + goto exit_kfree;
791 }
792
793 - i2c_set_clientdata(client, rtc);
794 + i2c_set_clientdata(client, pcf8563);
795
796 return 0;
797
798 -exit_detach:
799 - i2c_detach_client(client);
800 -
801 exit_kfree:
802 kfree(pcf8563);
803
804 -exit:
805 return err;
806 }
807
808 -static int pcf8563_detach(struct i2c_client *client)
809 +static int pcf8563_remove(struct i2c_client *client)
810 {
811 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
812 - int err;
813 - struct rtc_device *rtc = i2c_get_clientdata(client);
814 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
815
816 - if (rtc)
817 - rtc_device_unregister(rtc);
818 -
819 - if ((err = i2c_detach_client(client)))
820 - return err;
821 + if (pcf8563->rtc)
822 + rtc_device_unregister(pcf8563->rtc);
823
824 kfree(pcf8563);
825
826 return 0;
827 }
828
829 +static struct i2c_driver pcf8563_driver = {
830 + .driver = {
831 + .name = "rtc-pcf8563",
832 + },
833 + .probe = pcf8563_probe,
834 + .remove = pcf8563_remove,
835 +};
836 +
837 static int __init pcf8563_init(void)
838 {
839 return i2c_add_driver(&pcf8563_driver);
840 Index: linux-2.6.24.7/drivers/rtc/rtc-x1205.c
841 ===================================================================
842 --- linux-2.6.24.7.orig/drivers/rtc/rtc-x1205.c
843 +++ linux-2.6.24.7/drivers/rtc/rtc-x1205.c
844 @@ -22,20 +22,7 @@
845 #include <linux/rtc.h>
846 #include <linux/delay.h>
847
848 -#define DRV_VERSION "1.0.7"
849 -
850 -/* Addresses to scan: none. This chip is located at
851 - * 0x6f and uses a two bytes register addressing.
852 - * Two bytes need to be written to read a single register,
853 - * while most other chips just require one and take the second
854 - * one as the data to be written. To prevent corrupting
855 - * unknown chips, the user must explicitly set the probe parameter.
856 - */
857 -
858 -static unsigned short normal_i2c[] = { I2C_CLIENT_END };
859 -
860 -/* Insmod parameters */
861 -I2C_CLIENT_INSMOD;
862 +#define DRV_VERSION "1.0.8"
863
864 /* offsets into CCR area */
865
866 @@ -91,19 +78,7 @@ I2C_CLIENT_INSMOD;
867
868 #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
869
870 -/* Prototypes */
871 -static int x1205_attach(struct i2c_adapter *adapter);
872 -static int x1205_detach(struct i2c_client *client);
873 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
874 -
875 -static struct i2c_driver x1205_driver = {
876 - .driver = {
877 - .name = "x1205",
878 - },
879 - .id = I2C_DRIVERID_X1205,
880 - .attach_adapter = &x1205_attach,
881 - .detach_client = &x1205_detach,
882 -};
883 +static struct i2c_driver x1205_driver;
884
885 /*
886 * In the routines that deal directly with the x1205 hardware, we use
887 @@ -497,58 +472,51 @@ static ssize_t x1205_sysfs_show_dtrim(st
888 }
889 static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
890
891 -static int x1205_attach(struct i2c_adapter *adapter)
892 +static int x1205_sysfs_register(struct device *dev)
893 +{
894 + int err;
895 +
896 + err = device_create_file(dev, &dev_attr_atrim);
897 + if (err)
898 + return err;
899 +
900 + err = device_create_file(dev, &dev_attr_dtrim);
901 + if (err)
902 + device_remove_file(dev, &dev_attr_atrim);
903 +
904 + return err;
905 +}
906 +
907 +static void x1205_sysfs_unregister(struct device *dev)
908 {
909 - return i2c_probe(adapter, &addr_data, x1205_probe);
910 + device_remove_file(dev, &dev_attr_atrim);
911 + device_remove_file(dev, &dev_attr_dtrim);
912 }
913
914 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
915 +
916 +static int x1205_probe(struct i2c_client *client)
917 {
918 int err = 0;
919 unsigned char sr;
920 - struct i2c_client *client;
921 struct rtc_device *rtc;
922
923 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
924 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
925
926 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
927 - err = -ENODEV;
928 - goto exit;
929 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
930 + return -ENODEV;
931 }
932
933 - if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
934 - err = -ENOMEM;
935 - goto exit;
936 + if (x1205_validate_client(client) < 0) {
937 + return -ENODEV;
938 }
939
940 - /* I2C client */
941 - client->addr = address;
942 - client->driver = &x1205_driver;
943 - client->adapter = adapter;
944 -
945 - strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE);
946 -
947 - /* Verify the chip is really an X1205 */
948 - if (kind < 0) {
949 - if (x1205_validate_client(client) < 0) {
950 - err = -ENODEV;
951 - goto exit_kfree;
952 - }
953 - }
954 -
955 - /* Inform the i2c layer */
956 - if ((err = i2c_attach_client(client)))
957 - goto exit_kfree;
958 -
959 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
960
961 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
962 &x1205_rtc_ops, THIS_MODULE);
963
964 - if (IS_ERR(rtc)) {
965 - err = PTR_ERR(rtc);
966 - goto exit_detach;
967 - }
968 + if (IS_ERR(rtc))
969 + return PTR_ERR(rtc);
970
971 i2c_set_clientdata(client, rtc);
972
973 @@ -565,45 +533,35 @@ static int x1205_probe(struct i2c_adapte
974 else
975 dev_err(&client->dev, "couldn't read status\n");
976
977 - err = device_create_file(&client->dev, &dev_attr_atrim);
978 - if (err) goto exit_devreg;
979 - err = device_create_file(&client->dev, &dev_attr_dtrim);
980 - if (err) goto exit_atrim;
981 + err = x1205_sysfs_register(&client->dev);
982 + if (err)
983 + goto exit_devreg;
984
985 return 0;
986
987 -exit_atrim:
988 - device_remove_file(&client->dev, &dev_attr_atrim);
989 -
990 exit_devreg:
991 rtc_device_unregister(rtc);
992
993 -exit_detach:
994 - i2c_detach_client(client);
995 -
996 -exit_kfree:
997 - kfree(client);
998 -
999 -exit:
1000 return err;
1001 }
1002
1003 -static int x1205_detach(struct i2c_client *client)
1004 +static int x1205_remove(struct i2c_client *client)
1005 {
1006 - int err;
1007 struct rtc_device *rtc = i2c_get_clientdata(client);
1008
1009 - if (rtc)
1010 - rtc_device_unregister(rtc);
1011 -
1012 - if ((err = i2c_detach_client(client)))
1013 - return err;
1014 -
1015 - kfree(client);
1016 -
1017 + rtc_device_unregister(rtc);
1018 + x1205_sysfs_unregister(&client->dev);
1019 return 0;
1020 }
1021
1022 +static struct i2c_driver x1205_driver = {
1023 + .driver = {
1024 + .name = "rtc-x1205",
1025 + },
1026 + .probe = x1205_probe,
1027 + .remove = x1205_remove,
1028 +};
1029 +
1030 static int __init x1205_init(void)
1031 {
1032 return i2c_add_driver(&x1205_driver);