diff options
author | Magnus Damm <magnus.damm@gmail.com> | 2008-02-06 04:38:54 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-06 13:41:14 -0500 |
commit | 75b6102257874a4ea796af686de2f72cfa0452f9 (patch) | |
tree | 1605df88c3a77a61cc77be5eec6836793fca2143 /drivers | |
parent | 2805b9698445e898ca6e5ffdc132e80d94664a0f (diff) |
rtc: add support for Epson RTC-9701JE V4
Add support for the Epson RTC-9701JE SPI RTC device.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: 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')
-rw-r--r-- | drivers/rtc/rtc-r9701.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c index 926e8fda83c0..a64626a82d0b 100644 --- a/drivers/rtc/rtc-r9701.c +++ b/drivers/rtc/rtc-r9701.c | |||
@@ -1,10 +1,9 @@ | |||
1 | /* drivers/rtc/rtc-r9701.c | 1 | /* |
2 | * | ||
3 | * Driver for Epson RTC-9701JE | 2 | * Driver for Epson RTC-9701JE |
4 | * | 3 | * |
5 | * Copyright (C) 2008 Magnus Damm | 4 | * Copyright (C) 2008 Magnus Damm |
6 | * | 5 | * |
7 | * Based on drivers/rtc/rtc-max6902.c | 6 | * Based on rtc-max6902.c |
8 | * | 7 | * |
9 | * Copyright (C) 2006 8D Technologies inc. | 8 | * Copyright (C) 2006 8D Technologies inc. |
10 | * Copyright (C) 2004 Compulab Ltd. | 9 | * Copyright (C) 2004 Compulab Ltd. |
@@ -72,13 +71,12 @@ static int read_regs(struct device *dev, unsigned char *regs, int no_regs) | |||
72 | 71 | ||
73 | static int r9701_get_datetime(struct device *dev, struct rtc_time *dt) | 72 | static int r9701_get_datetime(struct device *dev, struct rtc_time *dt) |
74 | { | 73 | { |
75 | struct spi_device *spi = to_spi_device(dev); | ||
76 | unsigned long time; | 74 | unsigned long time; |
77 | int ret; | 75 | int ret; |
78 | unsigned char buf[] = { RSECCNT, RMINCNT, RHRCNT, | 76 | unsigned char buf[] = { RSECCNT, RMINCNT, RHRCNT, |
79 | RDAYCNT, RMONCNT, RYRCNT }; | 77 | RDAYCNT, RMONCNT, RYRCNT }; |
80 | 78 | ||
81 | ret = read_regs(&spi->dev, buf, ARRAY_SIZE(buf)); | 79 | ret = read_regs(dev, buf, ARRAY_SIZE(buf)); |
82 | if (ret) | 80 | if (ret) |
83 | return ret; | 81 | return ret; |
84 | 82 | ||
@@ -96,17 +94,7 @@ static int r9701_get_datetime(struct device *dev, struct rtc_time *dt) | |||
96 | * according to the data sheet. make sure they are valid. | 94 | * according to the data sheet. make sure they are valid. |
97 | */ | 95 | */ |
98 | 96 | ||
99 | ret = rtc_valid_tm(dt); | 97 | return rtc_valid_tm(dt); |
100 | if (ret) | ||
101 | return ret; | ||
102 | |||
103 | /* don't bother with yday, wday and isdst. | ||
104 | * let the rtc core calculate them for us. | ||
105 | */ | ||
106 | |||
107 | rtc_tm_to_time(dt, &time); | ||
108 | rtc_time_to_tm(time, dt); | ||
109 | return 0; | ||
110 | } | 98 | } |
111 | 99 | ||
112 | static int r9701_set_datetime(struct device *dev, struct rtc_time *dt) | 100 | static int r9701_set_datetime(struct device *dev, struct rtc_time *dt) |
@@ -118,12 +106,12 @@ static int r9701_set_datetime(struct device *dev, struct rtc_time *dt) | |||
118 | return -EINVAL; | 106 | return -EINVAL; |
119 | 107 | ||
120 | ret = write_reg(dev, RHRCNT, BIN2BCD(dt->tm_hour)); | 108 | ret = write_reg(dev, RHRCNT, BIN2BCD(dt->tm_hour)); |
121 | ret |= write_reg(dev, RMINCNT, BIN2BCD(dt->tm_min)); | 109 | ret = ret ? ret : write_reg(dev, RMINCNT, BIN2BCD(dt->tm_min)); |
122 | ret |= write_reg(dev, RSECCNT, BIN2BCD(dt->tm_sec)); | 110 | ret = ret ? ret : write_reg(dev, RSECCNT, BIN2BCD(dt->tm_sec)); |
123 | ret |= write_reg(dev, RDAYCNT, BIN2BCD(dt->tm_mday)); | 111 | ret = ret ? ret : write_reg(dev, RDAYCNT, BIN2BCD(dt->tm_mday)); |
124 | ret |= write_reg(dev, RMONCNT, BIN2BCD(dt->tm_mon + 1)); | 112 | ret = ret ? ret : write_reg(dev, RMONCNT, BIN2BCD(dt->tm_mon + 1)); |
125 | ret |= write_reg(dev, RYRCNT, BIN2BCD(dt->tm_year - 100)); | 113 | ret = ret ? ret : write_reg(dev, RYRCNT, BIN2BCD(dt->tm_year - 100)); |
126 | ret |= write_reg(dev, RWKCNT, 1 << dt->tm_wday); | 114 | ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday); |
127 | 115 | ||
128 | return ret; | 116 | return ret; |
129 | } | 117 | } |
@@ -146,10 +134,6 @@ static int __devinit r9701_probe(struct spi_device *spi) | |||
146 | 134 | ||
147 | dev_set_drvdata(&spi->dev, rtc); | 135 | dev_set_drvdata(&spi->dev, rtc); |
148 | 136 | ||
149 | spi->mode = SPI_MODE_3; | ||
150 | spi->bits_per_word = 8; | ||
151 | spi_setup(spi); | ||
152 | |||
153 | tmp = R100CNT; | 137 | tmp = R100CNT; |
154 | res = read_regs(&spi->dev, &tmp, 1); | 138 | res = read_regs(&spi->dev, &tmp, 1); |
155 | if (res || tmp != 0x20) { | 139 | if (res || tmp != 0x20) { |
@@ -171,7 +155,6 @@ static int __devexit r9701_remove(struct spi_device *spi) | |||
171 | static struct spi_driver r9701_driver = { | 155 | static struct spi_driver r9701_driver = { |
172 | .driver = { | 156 | .driver = { |
173 | .name = "rtc-r9701", | 157 | .name = "rtc-r9701", |
174 | .bus = &spi_bus_type, | ||
175 | .owner = THIS_MODULE, | 158 | .owner = THIS_MODULE, |
176 | }, | 159 | }, |
177 | .probe = r9701_probe, | 160 | .probe = r9701_probe, |