diff options
author | Steven A. Falco <sfalco@harris.com> | 2008-10-16 01:03:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 14:21:40 -0400 |
commit | d3a126fcf9df7dc59f1cc553c2fb2e668264e86c (patch) | |
tree | 3e6359d3ad55bc0ecf585eed8ab0361f89889a92 /drivers/rtc/rtc-m41t80.c | |
parent | 03274572215a1dfc7c382ef9b18c562612b4d466 (diff) |
rtc: rtc-m41t80.c: add support for the ST M41T65 RTC
Add support for M41T65 Real Time Clock chip.
The main differences I see between the M41T65 and M41T80 are that:
1) The M41T65 watchdog timer has three bits controlling resolution
(versus two for the M41T80).
2) There is no register 0x13 for controlling square-wave output.
Signed-off-by: Steven A. Falco <sfalco@harris.com>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
Acked-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-m41t80.c')
-rw-r--r-- | drivers/rtc/rtc-m41t80.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index 24bc1689fc74..470fb2d29545 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
@@ -56,21 +56,27 @@ | |||
56 | #define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */ | 56 | #define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */ |
57 | #define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */ | 57 | #define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */ |
58 | #define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */ | 58 | #define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */ |
59 | #define M41T80_WATCHDOG_RB2 (1 << 7) /* RB: Watchdog resolution */ | ||
60 | #define M41T80_WATCHDOG_RB1 (1 << 1) /* RB: Watchdog resolution */ | ||
61 | #define M41T80_WATCHDOG_RB0 (1 << 0) /* RB: Watchdog resolution */ | ||
59 | 62 | ||
60 | #define M41T80_FEATURE_HT (1 << 0) | 63 | #define M41T80_FEATURE_HT (1 << 0) /* Halt feature */ |
61 | #define M41T80_FEATURE_BL (1 << 1) | 64 | #define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */ |
65 | #define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */ | ||
66 | #define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */ | ||
62 | 67 | ||
63 | #define DRV_VERSION "0.05" | 68 | #define DRV_VERSION "0.05" |
64 | 69 | ||
65 | static const struct i2c_device_id m41t80_id[] = { | 70 | static const struct i2c_device_id m41t80_id[] = { |
66 | { "m41t80", 0 }, | 71 | { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, |
67 | { "m41t81", M41T80_FEATURE_HT }, | 72 | { "m41t80", M41T80_FEATURE_SQ }, |
68 | { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | 73 | { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ}, |
69 | { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | 74 | { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
70 | { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | 75 | { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
71 | { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | 76 | { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
72 | { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | 77 | { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
73 | { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | 78 | { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
79 | { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, | ||
74 | { } | 80 | { } |
75 | }; | 81 | }; |
76 | MODULE_DEVICE_TABLE(i2c, m41t80_id); | 82 | MODULE_DEVICE_TABLE(i2c, m41t80_id); |
@@ -386,8 +392,12 @@ static ssize_t m41t80_sysfs_show_sqwfreq(struct device *dev, | |||
386 | struct device_attribute *attr, char *buf) | 392 | struct device_attribute *attr, char *buf) |
387 | { | 393 | { |
388 | struct i2c_client *client = to_i2c_client(dev); | 394 | struct i2c_client *client = to_i2c_client(dev); |
395 | struct m41t80_data *clientdata = i2c_get_clientdata(client); | ||
389 | int val; | 396 | int val; |
390 | 397 | ||
398 | if (!(clientdata->features & M41T80_FEATURE_SQ)) | ||
399 | return -EINVAL; | ||
400 | |||
391 | val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW); | 401 | val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW); |
392 | if (val < 0) | 402 | if (val < 0) |
393 | return -EIO; | 403 | return -EIO; |
@@ -408,9 +418,13 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev, | |||
408 | const char *buf, size_t count) | 418 | const char *buf, size_t count) |
409 | { | 419 | { |
410 | struct i2c_client *client = to_i2c_client(dev); | 420 | struct i2c_client *client = to_i2c_client(dev); |
421 | struct m41t80_data *clientdata = i2c_get_clientdata(client); | ||
411 | int almon, sqw; | 422 | int almon, sqw; |
412 | int val = simple_strtoul(buf, NULL, 0); | 423 | int val = simple_strtoul(buf, NULL, 0); |
413 | 424 | ||
425 | if (!(clientdata->features & M41T80_FEATURE_SQ)) | ||
426 | return -EINVAL; | ||
427 | |||
414 | if (val) { | 428 | if (val) { |
415 | if (!is_power_of_2(val)) | 429 | if (!is_power_of_2(val)) |
416 | return -EINVAL; | 430 | return -EINVAL; |
@@ -499,6 +513,8 @@ static void wdt_ping(void) | |||
499 | .buf = i2c_data, | 513 | .buf = i2c_data, |
500 | }, | 514 | }, |
501 | }; | 515 | }; |
516 | struct m41t80_data *clientdata = i2c_get_clientdata(save_client); | ||
517 | |||
502 | i2c_data[0] = 0x09; /* watchdog register */ | 518 | i2c_data[0] = 0x09; /* watchdog register */ |
503 | 519 | ||
504 | if (wdt_margin > 31) | 520 | if (wdt_margin > 31) |
@@ -509,6 +525,13 @@ static void wdt_ping(void) | |||
509 | */ | 525 | */ |
510 | i2c_data[1] = wdt_margin<<2 | 0x82; | 526 | i2c_data[1] = wdt_margin<<2 | 0x82; |
511 | 527 | ||
528 | /* | ||
529 | * M41T65 has three bits for watchdog resolution. Don't set bit 7, as | ||
530 | * that would be an invalid resolution. | ||
531 | */ | ||
532 | if (clientdata->features & M41T80_FEATURE_WD) | ||
533 | i2c_data[1] &= ~M41T80_WATCHDOG_RB2; | ||
534 | |||
512 | i2c_transfer(save_client->adapter, msgs1, 1); | 535 | i2c_transfer(save_client->adapter, msgs1, 1); |
513 | } | 536 | } |
514 | 537 | ||