bcm963xx: serial port support
[openwrt.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-arm/drivers/rtc/rtc-isl1208.c
6 ===================================================================
7 --- linux-2.6.24-arm.orig/drivers/rtc/rtc-isl1208.c 2008-02-01 13:33:11.000000000 +1030
8 +++ linux-2.6.24-arm/drivers/rtc/rtc-isl1208.c 2008-02-01 13:36:24.000000000 +1030
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 ---
652 drivers/rtc/rtc-pcf8563.c | 109 +++++++++++++---------------------------------
653 1 file changed, 32 insertions(+), 77 deletions(-)
654
655 Index: linux-2.6.24-armeb/drivers/rtc/rtc-pcf8563.c
656 ===================================================================
657 --- linux-2.6.24-armeb.orig/drivers/rtc/rtc-pcf8563.c 2008-01-30 13:50:01.000000000 +1030
658 +++ linux-2.6.24-armeb/drivers/rtc/rtc-pcf8563.c 2008-01-30 13:51:55.000000000 +1030
659 @@ -18,17 +18,7 @@
660 #include <linux/bcd.h>
661 #include <linux/rtc.h>
662
663 -#define DRV_VERSION "0.4.2"
664 -
665 -/* Addresses to scan: none
666 - * This chip cannot be reliably autodetected. An empty eeprom
667 - * located at 0x51 will pass the validation routine due to
668 - * the way the registers are implemented.
669 - */
670 -static unsigned short normal_i2c[] = { I2C_CLIENT_END };
671 -
672 -/* Module parameters */
673 -I2C_CLIENT_INSMOD;
674 +#define DRV_VERSION "0.4.3"
675
676 #define PCF8563_REG_ST1 0x00 /* status */
677 #define PCF8563_REG_ST2 0x01
678 @@ -53,8 +43,10 @@
679 #define PCF8563_SC_LV 0x80 /* low voltage */
680 #define PCF8563_MO_C 0x80 /* century */
681
682 +static struct i2c_driver pcf8563_driver;
683 +
684 struct pcf8563 {
685 - struct i2c_client client;
686 + struct rtc_device *rtc;
687 /*
688 * The meaning of MO_C bit varies by the chip type.
689 * From PCF8563 datasheet: this bit is toggled when the years
690 @@ -72,16 +64,13 @@
691 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
692 };
693
694 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
695 -static int pcf8563_detach(struct i2c_client *client);
696 -
697 /*
698 * In the routines that deal directly with the pcf8563 hardware, we use
699 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
700 */
701 static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
702 {
703 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
704 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
705 unsigned char buf[13] = { PCF8563_REG_ST1 };
706
707 struct i2c_msg msgs[] = {
708 @@ -138,7 +127,7 @@
709
710 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
711 {
712 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
713 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
714 int i, err;
715 unsigned char buf[9];
716
717 @@ -257,100 +246,66 @@
718 .set_time = pcf8563_rtc_set_time,
719 };
720
721 -static int pcf8563_attach(struct i2c_adapter *adapter)
722 -{
723 - return i2c_probe(adapter, &addr_data, pcf8563_probe);
724 -}
725 -
726 -static struct i2c_driver pcf8563_driver = {
727 - .driver = {
728 - .name = "pcf8563",
729 - },
730 - .id = I2C_DRIVERID_PCF8563,
731 - .attach_adapter = &pcf8563_attach,
732 - .detach_client = &pcf8563_detach,
733 -};
734 -
735 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
736 +static int pcf8563_probe(struct i2c_client *client)
737 {
738 struct pcf8563 *pcf8563;
739 - struct i2c_client *client;
740 - struct rtc_device *rtc;
741
742 int err = 0;
743
744 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
745 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
746
747 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
748 - err = -ENODEV;
749 - goto exit;
750 - }
751 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
752 + return -ENODEV;
753
754 - if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) {
755 - err = -ENOMEM;
756 - goto exit;
757 - }
758 -
759 - client = &pcf8563->client;
760 - client->addr = address;
761 - client->driver = &pcf8563_driver;
762 - client->adapter = adapter;
763 -
764 - strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
765 + if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL)))
766 + return -ENOMEM;
767
768 /* Verify the chip is really an PCF8563 */
769 - if (kind < 0) {
770 - if (pcf8563_validate_client(client) < 0) {
771 - err = -ENODEV;
772 - goto exit_kfree;
773 - }
774 - }
775 -
776 - /* Inform the i2c layer */
777 - if ((err = i2c_attach_client(client)))
778 + if (pcf8563_validate_client(client) < 0) {
779 + err = -ENODEV;
780 goto exit_kfree;
781 + }
782
783 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
784
785 - rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
786 + pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
787 &pcf8563_rtc_ops, THIS_MODULE);
788
789 - if (IS_ERR(rtc)) {
790 - err = PTR_ERR(rtc);
791 - goto exit_detach;
792 + if (IS_ERR(pcf8563->rtc)) {
793 + err = PTR_ERR(pcf8563->rtc);
794 + goto exit_kfree;
795 }
796
797 - i2c_set_clientdata(client, rtc);
798 + i2c_set_clientdata(client, pcf8563);
799
800 return 0;
801
802 -exit_detach:
803 - i2c_detach_client(client);
804 -
805 exit_kfree:
806 kfree(pcf8563);
807
808 -exit:
809 return err;
810 }
811
812 -static int pcf8563_detach(struct i2c_client *client)
813 +static int pcf8563_remove(struct i2c_client *client)
814 {
815 - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
816 - int err;
817 - struct rtc_device *rtc = i2c_get_clientdata(client);
818 + struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
819
820 - if (rtc)
821 - rtc_device_unregister(rtc);
822 -
823 - if ((err = i2c_detach_client(client)))
824 - return err;
825 + if (pcf8563->rtc)
826 + rtc_device_unregister(pcf8563->rtc);
827
828 kfree(pcf8563);
829
830 return 0;
831 }
832
833 +static struct i2c_driver pcf8563_driver = {
834 + .driver = {
835 + .name = "rtc-pcf8563",
836 + },
837 + .probe = pcf8563_probe,
838 + .remove = pcf8563_remove,
839 +};
840 +
841 static int __init pcf8563_init(void)
842 {
843 return i2c_add_driver(&pcf8563_driver);
844 ---
845 drivers/rtc/rtc-x1205.c | 128 ++++++++++++++++--------------------------------
846 1 file changed, 43 insertions(+), 85 deletions(-)
847
848 Index: linux-2.6.24-armeb/drivers/rtc/rtc-x1205.c
849 ===================================================================
850 --- linux-2.6.24-armeb.orig/drivers/rtc/rtc-x1205.c 2008-01-30 13:50:44.000000000 +1030
851 +++ linux-2.6.24-armeb/drivers/rtc/rtc-x1205.c 2008-01-30 13:51:35.000000000 +1030
852 @@ -22,20 +22,7 @@
853 #include <linux/rtc.h>
854 #include <linux/delay.h>
855
856 -#define DRV_VERSION "1.0.7"
857 -
858 -/* Addresses to scan: none. This chip is located at
859 - * 0x6f and uses a two bytes register addressing.
860 - * Two bytes need to be written to read a single register,
861 - * while most other chips just require one and take the second
862 - * one as the data to be written. To prevent corrupting
863 - * unknown chips, the user must explicitly set the probe parameter.
864 - */
865 -
866 -static unsigned short normal_i2c[] = { I2C_CLIENT_END };
867 -
868 -/* Insmod parameters */
869 -I2C_CLIENT_INSMOD;
870 +#define DRV_VERSION "1.0.8"
871
872 /* offsets into CCR area */
873
874 @@ -91,19 +78,7 @@
875
876 #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
877
878 -/* Prototypes */
879 -static int x1205_attach(struct i2c_adapter *adapter);
880 -static int x1205_detach(struct i2c_client *client);
881 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
882 -
883 -static struct i2c_driver x1205_driver = {
884 - .driver = {
885 - .name = "x1205",
886 - },
887 - .id = I2C_DRIVERID_X1205,
888 - .attach_adapter = &x1205_attach,
889 - .detach_client = &x1205_detach,
890 -};
891 +static struct i2c_driver x1205_driver;
892
893 /*
894 * In the routines that deal directly with the x1205 hardware, we use
895 @@ -497,58 +472,51 @@
896 }
897 static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
898
899 -static int x1205_attach(struct i2c_adapter *adapter)
900 +static int x1205_sysfs_register(struct device *dev)
901 +{
902 + int err;
903 +
904 + err = device_create_file(dev, &dev_attr_atrim);
905 + if (err)
906 + return err;
907 +
908 + err = device_create_file(dev, &dev_attr_dtrim);
909 + if (err)
910 + device_remove_file(dev, &dev_attr_atrim);
911 +
912 + return err;
913 +}
914 +
915 +static void x1205_sysfs_unregister(struct device *dev)
916 {
917 - return i2c_probe(adapter, &addr_data, x1205_probe);
918 + device_remove_file(dev, &dev_attr_atrim);
919 + device_remove_file(dev, &dev_attr_dtrim);
920 }
921
922 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
923 +
924 +static int x1205_probe(struct i2c_client *client)
925 {
926 int err = 0;
927 unsigned char sr;
928 - struct i2c_client *client;
929 struct rtc_device *rtc;
930
931 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
932 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
933
934 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
935 - err = -ENODEV;
936 - goto exit;
937 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
938 + return -ENODEV;
939 }
940
941 - if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
942 - err = -ENOMEM;
943 - goto exit;
944 + if (x1205_validate_client(client) < 0) {
945 + return -ENODEV;
946 }
947
948 - /* I2C client */
949 - client->addr = address;
950 - client->driver = &x1205_driver;
951 - client->adapter = adapter;
952 -
953 - strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE);
954 -
955 - /* Verify the chip is really an X1205 */
956 - if (kind < 0) {
957 - if (x1205_validate_client(client) < 0) {
958 - err = -ENODEV;
959 - goto exit_kfree;
960 - }
961 - }
962 -
963 - /* Inform the i2c layer */
964 - if ((err = i2c_attach_client(client)))
965 - goto exit_kfree;
966 -
967 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
968
969 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
970 &x1205_rtc_ops, THIS_MODULE);
971
972 - if (IS_ERR(rtc)) {
973 - err = PTR_ERR(rtc);
974 - goto exit_detach;
975 - }
976 + if (IS_ERR(rtc))
977 + return PTR_ERR(rtc);
978
979 i2c_set_clientdata(client, rtc);
980
981 @@ -565,45 +533,35 @@
982 else
983 dev_err(&client->dev, "couldn't read status\n");
984
985 - err = device_create_file(&client->dev, &dev_attr_atrim);
986 - if (err) goto exit_devreg;
987 - err = device_create_file(&client->dev, &dev_attr_dtrim);
988 - if (err) goto exit_atrim;
989 + err = x1205_sysfs_register(&client->dev);
990 + if (err)
991 + goto exit_devreg;
992
993 return 0;
994
995 -exit_atrim:
996 - device_remove_file(&client->dev, &dev_attr_atrim);
997 -
998 exit_devreg:
999 rtc_device_unregister(rtc);
1000
1001 -exit_detach:
1002 - i2c_detach_client(client);
1003 -
1004 -exit_kfree:
1005 - kfree(client);
1006 -
1007 -exit:
1008 return err;
1009 }
1010
1011 -static int x1205_detach(struct i2c_client *client)
1012 +static int x1205_remove(struct i2c_client *client)
1013 {
1014 - int err;
1015 struct rtc_device *rtc = i2c_get_clientdata(client);
1016
1017 - if (rtc)
1018 - rtc_device_unregister(rtc);
1019 -
1020 - if ((err = i2c_detach_client(client)))
1021 - return err;
1022 -
1023 - kfree(client);
1024 -
1025 + rtc_device_unregister(rtc);
1026 + x1205_sysfs_unregister(&client->dev);
1027 return 0;
1028 }
1029
1030 +static struct i2c_driver x1205_driver = {
1031 + .driver = {
1032 + .name = "rtc-x1205",
1033 + },
1034 + .probe = x1205_probe,
1035 + .remove = x1205_remove,
1036 +};
1037 +
1038 static int __init x1205_init(void)
1039 {
1040 return i2c_add_driver(&x1205_driver);
This page took 0.11955 seconds and 5 git commands to generate.