diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 2 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-at91rm9200.c (renamed from drivers/rtc/rtc-at91.c) | 0 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1672.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-lib.c | 81 | ||||
-rw-r--r-- | drivers/rtc/rtc-pcf8563.c | 6 | ||||
-rw-r--r-- | drivers/rtc/rtc-rs5c372.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-sh.c | 245 | ||||
-rw-r--r-- | drivers/rtc/rtc-x1205.c | 10 |
9 files changed, 304 insertions, 46 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 2a63ab2b47f4..09660e2ab051 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -288,7 +288,7 @@ config RTC_DRV_PL031 | |||
288 | To compile this driver as a module, choose M here: the | 288 | To compile this driver as a module, choose M here: the |
289 | module will be called rtc-pl031. | 289 | module will be called rtc-pl031. |
290 | 290 | ||
291 | config RTC_DRV_AT91 | 291 | config RTC_DRV_AT91RM9200 |
292 | tristate "AT91RM9200" | 292 | tristate "AT91RM9200" |
293 | depends on RTC_CLASS && ARCH_AT91RM9200 | 293 | depends on RTC_CLASS && ARCH_AT91RM9200 |
294 | help | 294 | help |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index bd4c45d333f0..e6beedacc966 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -35,5 +35,5 @@ obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o | |||
35 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o | 35 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o |
36 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o | 36 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o |
37 | obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o | 37 | obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o |
38 | obj-$(CONFIG_RTC_DRV_AT91) += rtc-at91.o | 38 | obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o |
39 | obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o | 39 | obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o |
diff --git a/drivers/rtc/rtc-at91.c b/drivers/rtc/rtc-at91rm9200.c index 5c8addcaf1fb..5c8addcaf1fb 100644 --- a/drivers/rtc/rtc-at91.c +++ b/drivers/rtc/rtc-at91rm9200.c | |||
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c index dfef1637bfb8..205fa28593b7 100644 --- a/drivers/rtc/rtc-ds1672.c +++ b/drivers/rtc/rtc-ds1672.c | |||
@@ -199,7 +199,7 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind) | |||
199 | struct i2c_client *client; | 199 | struct i2c_client *client; |
200 | struct rtc_device *rtc; | 200 | struct rtc_device *rtc; |
201 | 201 | ||
202 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | 202 | dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__); |
203 | 203 | ||
204 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { | 204 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { |
205 | err = -ENODEV; | 205 | err = -ENODEV; |
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index ba795a4db1e9..7bbc26a34bd2 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c | |||
@@ -117,4 +117,85 @@ int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) | |||
117 | } | 117 | } |
118 | EXPORT_SYMBOL(rtc_tm_to_time); | 118 | EXPORT_SYMBOL(rtc_tm_to_time); |
119 | 119 | ||
120 | |||
121 | /* Merge the valid (i.e. non-negative) fields of alarm into the current | ||
122 | * time. If the valid alarm fields are earlier than the equivalent | ||
123 | * fields in the time, carry one into the least significant invalid | ||
124 | * field, so that the alarm expiry is in the future. It assumes that the | ||
125 | * least significant invalid field is more significant than the most | ||
126 | * significant valid field, and that the seconds field is valid. | ||
127 | * | ||
128 | * This is used by alarms that take relative (rather than absolute) | ||
129 | * times, and/or have a simple binary second counter instead of | ||
130 | * day/hour/minute/sec registers. | ||
131 | */ | ||
132 | void rtc_merge_alarm(struct rtc_time *now, struct rtc_time *alarm) | ||
133 | { | ||
134 | int *alarmp = &alarm->tm_sec; | ||
135 | int *timep = &now->tm_sec; | ||
136 | int carry_into, i; | ||
137 | |||
138 | /* Ignore everything past the 6th element (tm_year). */ | ||
139 | for (i = 5; i > 0; i--) { | ||
140 | if (alarmp[i] < 0) | ||
141 | alarmp[i] = timep[i]; | ||
142 | else | ||
143 | break; | ||
144 | } | ||
145 | |||
146 | /* No carry needed if all fields are valid. */ | ||
147 | if (i == 5) | ||
148 | return; | ||
149 | |||
150 | for (carry_into = i + 1; i >= 0; i--) { | ||
151 | if (alarmp[i] < timep[i]) | ||
152 | break; | ||
153 | |||
154 | if (alarmp[i] > timep[i]) | ||
155 | return; | ||
156 | } | ||
157 | |||
158 | switch (carry_into) { | ||
159 | case 1: | ||
160 | alarm->tm_min++; | ||
161 | |||
162 | if (alarm->tm_min < 60) | ||
163 | return; | ||
164 | |||
165 | alarm->tm_min = 0; | ||
166 | /* fall-through */ | ||
167 | |||
168 | case 2: | ||
169 | alarm->tm_hour++; | ||
170 | |||
171 | if (alarm->tm_hour < 60) | ||
172 | return; | ||
173 | |||
174 | alarm->tm_hour = 0; | ||
175 | /* fall-through */ | ||
176 | |||
177 | case 3: | ||
178 | alarm->tm_mday++; | ||
179 | |||
180 | if (alarm->tm_mday <= rtc_days_in_month[alarm->tm_mon]) | ||
181 | return; | ||
182 | |||
183 | alarm->tm_mday = 1; | ||
184 | /* fall-through */ | ||
185 | |||
186 | case 4: | ||
187 | alarm->tm_mon++; | ||
188 | |||
189 | if (alarm->tm_mon <= 12) | ||
190 | return; | ||
191 | |||
192 | alarm->tm_mon = 1; | ||
193 | /* fall-through */ | ||
194 | |||
195 | case 5: | ||
196 | alarm->tm_year++; | ||
197 | } | ||
198 | } | ||
199 | EXPORT_SYMBOL(rtc_merge_alarm); | ||
200 | |||
120 | MODULE_LICENSE("GPL"); | 201 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index a760cf69af90..4b72b8ef5d66 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c | |||
@@ -192,7 +192,7 @@ static int pcf8563_validate_client(struct i2c_client *client) | |||
192 | xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); | 192 | xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); |
193 | 193 | ||
194 | if (xfer != ARRAY_SIZE(msgs)) { | 194 | if (xfer != ARRAY_SIZE(msgs)) { |
195 | dev_err(&client->adapter->dev, | 195 | dev_err(&client->dev, |
196 | "%s: could not read register 0x%02X\n", | 196 | "%s: could not read register 0x%02X\n", |
197 | __FUNCTION__, pattern[i].reg); | 197 | __FUNCTION__, pattern[i].reg); |
198 | 198 | ||
@@ -203,7 +203,7 @@ static int pcf8563_validate_client(struct i2c_client *client) | |||
203 | 203 | ||
204 | if (value > pattern[i].max || | 204 | if (value > pattern[i].max || |
205 | value < pattern[i].min) { | 205 | value < pattern[i].min) { |
206 | dev_dbg(&client->adapter->dev, | 206 | dev_dbg(&client->dev, |
207 | "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, " | 207 | "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, " |
208 | "max=%d, value=%d, raw=0x%02X\n", | 208 | "max=%d, value=%d, raw=0x%02X\n", |
209 | __FUNCTION__, i, pattern[i].reg, pattern[i].mask, | 209 | __FUNCTION__, i, pattern[i].reg, pattern[i].mask, |
@@ -253,7 +253,7 @@ static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind) | |||
253 | 253 | ||
254 | int err = 0; | 254 | int err = 0; |
255 | 255 | ||
256 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | 256 | dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__); |
257 | 257 | ||
258 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { | 258 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { |
259 | err = -ENODEV; | 259 | err = -ENODEV; |
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c index e2c7698fdba3..1460f6b769f2 100644 --- a/drivers/rtc/rtc-rs5c372.c +++ b/drivers/rtc/rtc-rs5c372.c | |||
@@ -200,7 +200,7 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind) | |||
200 | struct i2c_client *client; | 200 | struct i2c_client *client; |
201 | struct rs5c372 *rs5c372; | 201 | struct rs5c372 *rs5c372; |
202 | 202 | ||
203 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | 203 | dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__); |
204 | 204 | ||
205 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { | 205 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { |
206 | err = -ENODEV; | 206 | err = -ENODEV; |
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c index 143302a8e79c..72ba1a70f35f 100644 --- a/drivers/rtc/rtc-sh.c +++ b/drivers/rtc/rtc-sh.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * SuperH On-Chip RTC Support | 2 | * SuperH On-Chip RTC Support |
3 | * | 3 | * |
4 | * Copyright (C) 2006 Paul Mundt | 4 | * Copyright (C) 2006 Paul Mundt |
5 | * Copyright (C) 2006 Jamie Lenehan | ||
5 | * | 6 | * |
6 | * Based on the old arch/sh/kernel/cpu/rtc.c by: | 7 | * Based on the old arch/sh/kernel/cpu/rtc.c by: |
7 | * | 8 | * |
@@ -21,7 +22,10 @@ | |||
21 | #include <linux/seq_file.h> | 22 | #include <linux/seq_file.h> |
22 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
23 | #include <linux/spinlock.h> | 24 | #include <linux/spinlock.h> |
24 | #include <asm/io.h> | 25 | #include <linux/io.h> |
26 | |||
27 | #define DRV_NAME "sh-rtc" | ||
28 | #define DRV_VERSION "0.1.2" | ||
25 | 29 | ||
26 | #ifdef CONFIG_CPU_SH3 | 30 | #ifdef CONFIG_CPU_SH3 |
27 | #define rtc_reg_size sizeof(u16) | 31 | #define rtc_reg_size sizeof(u16) |
@@ -33,22 +37,26 @@ | |||
33 | 37 | ||
34 | #define RTC_REG(r) ((r) * rtc_reg_size) | 38 | #define RTC_REG(r) ((r) * rtc_reg_size) |
35 | 39 | ||
36 | #define R64CNT RTC_REG(0) | 40 | #define R64CNT RTC_REG(0) |
37 | #define RSECCNT RTC_REG(1) | 41 | |
38 | #define RMINCNT RTC_REG(2) | 42 | #define RSECCNT RTC_REG(1) /* RTC sec */ |
39 | #define RHRCNT RTC_REG(3) | 43 | #define RMINCNT RTC_REG(2) /* RTC min */ |
40 | #define RWKCNT RTC_REG(4) | 44 | #define RHRCNT RTC_REG(3) /* RTC hour */ |
41 | #define RDAYCNT RTC_REG(5) | 45 | #define RWKCNT RTC_REG(4) /* RTC week */ |
42 | #define RMONCNT RTC_REG(6) | 46 | #define RDAYCNT RTC_REG(5) /* RTC day */ |
43 | #define RYRCNT RTC_REG(7) | 47 | #define RMONCNT RTC_REG(6) /* RTC month */ |
44 | #define RSECAR RTC_REG(8) | 48 | #define RYRCNT RTC_REG(7) /* RTC year */ |
45 | #define RMINAR RTC_REG(9) | 49 | #define RSECAR RTC_REG(8) /* ALARM sec */ |
46 | #define RHRAR RTC_REG(10) | 50 | #define RMINAR RTC_REG(9) /* ALARM min */ |
47 | #define RWKAR RTC_REG(11) | 51 | #define RHRAR RTC_REG(10) /* ALARM hour */ |
48 | #define RDAYAR RTC_REG(12) | 52 | #define RWKAR RTC_REG(11) /* ALARM week */ |
49 | #define RMONAR RTC_REG(13) | 53 | #define RDAYAR RTC_REG(12) /* ALARM day */ |
50 | #define RCR1 RTC_REG(14) | 54 | #define RMONAR RTC_REG(13) /* ALARM month */ |
51 | #define RCR2 RTC_REG(15) | 55 | #define RCR1 RTC_REG(14) /* Control */ |
56 | #define RCR2 RTC_REG(15) /* Control */ | ||
57 | |||
58 | /* ALARM Bits - or with BCD encoded value */ | ||
59 | #define AR_ENB 0x80 /* Enable for alarm cmp */ | ||
52 | 60 | ||
53 | /* RCR1 Bits */ | 61 | /* RCR1 Bits */ |
54 | #define RCR1_CF 0x80 /* Carry Flag */ | 62 | #define RCR1_CF 0x80 /* Carry Flag */ |
@@ -71,22 +79,28 @@ struct sh_rtc { | |||
71 | unsigned int alarm_irq, periodic_irq, carry_irq; | 79 | unsigned int alarm_irq, periodic_irq, carry_irq; |
72 | struct rtc_device *rtc_dev; | 80 | struct rtc_device *rtc_dev; |
73 | spinlock_t lock; | 81 | spinlock_t lock; |
82 | int rearm_aie; | ||
74 | }; | 83 | }; |
75 | 84 | ||
76 | static irqreturn_t sh_rtc_interrupt(int irq, void *id) | 85 | static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id) |
77 | { | 86 | { |
78 | struct platform_device *pdev = id; | 87 | struct platform_device *pdev = to_platform_device(dev_id); |
79 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | 88 | struct sh_rtc *rtc = platform_get_drvdata(pdev); |
80 | unsigned int tmp, events = 0; | 89 | unsigned int tmp, events = 0; |
81 | 90 | ||
82 | spin_lock(&rtc->lock); | 91 | spin_lock(&rtc->lock); |
83 | 92 | ||
84 | tmp = readb(rtc->regbase + RCR1); | 93 | tmp = readb(rtc->regbase + RCR1); |
94 | tmp &= ~RCR1_CF; | ||
85 | 95 | ||
86 | if (tmp & RCR1_AF) | 96 | if (rtc->rearm_aie) { |
87 | events |= RTC_AF | RTC_IRQF; | 97 | if (tmp & RCR1_AF) |
88 | 98 | tmp &= ~RCR1_AF; /* try to clear AF again */ | |
89 | tmp &= ~(RCR1_CF | RCR1_AF); | 99 | else { |
100 | tmp |= RCR1_AIE; /* AF has cleared, rearm IRQ */ | ||
101 | rtc->rearm_aie = 0; | ||
102 | } | ||
103 | } | ||
90 | 104 | ||
91 | writeb(tmp, rtc->regbase + RCR1); | 105 | writeb(tmp, rtc->regbase + RCR1); |
92 | 106 | ||
@@ -97,9 +111,45 @@ static irqreturn_t sh_rtc_interrupt(int irq, void *id) | |||
97 | return IRQ_HANDLED; | 111 | return IRQ_HANDLED; |
98 | } | 112 | } |
99 | 113 | ||
100 | static irqreturn_t sh_rtc_periodic(int irq, void *id) | 114 | static irqreturn_t sh_rtc_alarm(int irq, void *dev_id) |
115 | { | ||
116 | struct platform_device *pdev = to_platform_device(dev_id); | ||
117 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
118 | unsigned int tmp, events = 0; | ||
119 | |||
120 | spin_lock(&rtc->lock); | ||
121 | |||
122 | tmp = readb(rtc->regbase + RCR1); | ||
123 | |||
124 | /* | ||
125 | * If AF is set then the alarm has triggered. If we clear AF while | ||
126 | * the alarm time still matches the RTC time then AF will | ||
127 | * immediately be set again, and if AIE is enabled then the alarm | ||
128 | * interrupt will immediately be retrigger. So we clear AIE here | ||
129 | * and use rtc->rearm_aie so that the carry interrupt will keep | ||
130 | * trying to clear AF and once it stays cleared it'll re-enable | ||
131 | * AIE. | ||
132 | */ | ||
133 | if (tmp & RCR1_AF) { | ||
134 | events |= RTC_AF | RTC_IRQF; | ||
135 | |||
136 | tmp &= ~(RCR1_AF|RCR1_AIE); | ||
137 | |||
138 | writeb(tmp, rtc->regbase + RCR1); | ||
139 | |||
140 | rtc->rearm_aie = 1; | ||
141 | |||
142 | rtc_update_irq(&rtc->rtc_dev->class_dev, 1, events); | ||
143 | } | ||
144 | |||
145 | spin_unlock(&rtc->lock); | ||
146 | return IRQ_HANDLED; | ||
147 | } | ||
148 | |||
149 | static irqreturn_t sh_rtc_periodic(int irq, void *dev_id) | ||
101 | { | 150 | { |
102 | struct sh_rtc *rtc = dev_get_drvdata(id); | 151 | struct platform_device *pdev = to_platform_device(dev_id); |
152 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
103 | 153 | ||
104 | spin_lock(&rtc->lock); | 154 | spin_lock(&rtc->lock); |
105 | 155 | ||
@@ -139,10 +189,11 @@ static inline void sh_rtc_setaie(struct device *dev, unsigned int enable) | |||
139 | 189 | ||
140 | tmp = readb(rtc->regbase + RCR1); | 190 | tmp = readb(rtc->regbase + RCR1); |
141 | 191 | ||
142 | if (enable) | 192 | if (!enable) { |
143 | tmp |= RCR1_AIE; | ||
144 | else | ||
145 | tmp &= ~RCR1_AIE; | 193 | tmp &= ~RCR1_AIE; |
194 | rtc->rearm_aie = 0; | ||
195 | } else if (rtc->rearm_aie == 0) | ||
196 | tmp |= RCR1_AIE; | ||
146 | 197 | ||
147 | writeb(tmp, rtc->regbase + RCR1); | 198 | writeb(tmp, rtc->regbase + RCR1); |
148 | 199 | ||
@@ -177,7 +228,7 @@ static int sh_rtc_open(struct device *dev) | |||
177 | goto err_bad_carry; | 228 | goto err_bad_carry; |
178 | } | 229 | } |
179 | 230 | ||
180 | ret = request_irq(rtc->alarm_irq, sh_rtc_interrupt, IRQF_DISABLED, | 231 | ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, IRQF_DISABLED, |
181 | "sh-rtc alarm", dev); | 232 | "sh-rtc alarm", dev); |
182 | if (unlikely(ret)) { | 233 | if (unlikely(ret)) { |
183 | dev_err(dev, "request alarm IRQ failed with %d, IRQ %d\n", | 234 | dev_err(dev, "request alarm IRQ failed with %d, IRQ %d\n", |
@@ -200,6 +251,7 @@ static void sh_rtc_release(struct device *dev) | |||
200 | struct sh_rtc *rtc = dev_get_drvdata(dev); | 251 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
201 | 252 | ||
202 | sh_rtc_setpie(dev, 0); | 253 | sh_rtc_setpie(dev, 0); |
254 | sh_rtc_setaie(dev, 0); | ||
203 | 255 | ||
204 | free_irq(rtc->periodic_irq, dev); | 256 | free_irq(rtc->periodic_irq, dev); |
205 | free_irq(rtc->carry_irq, dev); | 257 | free_irq(rtc->carry_irq, dev); |
@@ -267,7 +319,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
267 | tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT)); | 319 | tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT)); |
268 | tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT)); | 320 | tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT)); |
269 | tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT)); | 321 | tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT)); |
270 | tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)); | 322 | tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)) - 1; |
271 | 323 | ||
272 | #if defined(CONFIG_CPU_SH4) | 324 | #if defined(CONFIG_CPU_SH4) |
273 | yr = readw(rtc->regbase + RYRCNT); | 325 | yr = readw(rtc->regbase + RYRCNT); |
@@ -295,7 +347,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
295 | "mday=%d, mon=%d, year=%d, wday=%d\n", | 347 | "mday=%d, mon=%d, year=%d, wday=%d\n", |
296 | __FUNCTION__, | 348 | __FUNCTION__, |
297 | tm->tm_sec, tm->tm_min, tm->tm_hour, | 349 | tm->tm_sec, tm->tm_min, tm->tm_hour, |
298 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | 350 | tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); |
299 | 351 | ||
300 | if (rtc_valid_tm(tm) < 0) | 352 | if (rtc_valid_tm(tm) < 0) |
301 | dev_err(dev, "invalid date\n"); | 353 | dev_err(dev, "invalid date\n"); |
@@ -322,7 +374,7 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
322 | writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT); | 374 | writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT); |
323 | writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT); | 375 | writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT); |
324 | writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT); | 376 | writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT); |
325 | writeb(BIN2BCD(tm->tm_mon), rtc->regbase + RMONCNT); | 377 | writeb(BIN2BCD(tm->tm_mon + 1), rtc->regbase + RMONCNT); |
326 | 378 | ||
327 | #ifdef CONFIG_CPU_SH3 | 379 | #ifdef CONFIG_CPU_SH3 |
328 | year = tm->tm_year % 100; | 380 | year = tm->tm_year % 100; |
@@ -344,12 +396,136 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
344 | return 0; | 396 | return 0; |
345 | } | 397 | } |
346 | 398 | ||
399 | static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off) | ||
400 | { | ||
401 | unsigned int byte; | ||
402 | int value = 0xff; /* return 0xff for ignored values */ | ||
403 | |||
404 | byte = readb(rtc->regbase + reg_off); | ||
405 | if (byte & AR_ENB) { | ||
406 | byte &= ~AR_ENB; /* strip the enable bit */ | ||
407 | value = BCD2BIN(byte); | ||
408 | } | ||
409 | |||
410 | return value; | ||
411 | } | ||
412 | |||
413 | static int sh_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | ||
414 | { | ||
415 | struct platform_device *pdev = to_platform_device(dev); | ||
416 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
417 | struct rtc_time* tm = &wkalrm->time; | ||
418 | |||
419 | spin_lock_irq(&rtc->lock); | ||
420 | |||
421 | tm->tm_sec = sh_rtc_read_alarm_value(rtc, RSECAR); | ||
422 | tm->tm_min = sh_rtc_read_alarm_value(rtc, RMINAR); | ||
423 | tm->tm_hour = sh_rtc_read_alarm_value(rtc, RHRAR); | ||
424 | tm->tm_wday = sh_rtc_read_alarm_value(rtc, RWKAR); | ||
425 | tm->tm_mday = sh_rtc_read_alarm_value(rtc, RDAYAR); | ||
426 | tm->tm_mon = sh_rtc_read_alarm_value(rtc, RMONAR); | ||
427 | if (tm->tm_mon > 0) | ||
428 | tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ | ||
429 | tm->tm_year = 0xffff; | ||
430 | |||
431 | spin_unlock_irq(&rtc->lock); | ||
432 | |||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc, | ||
437 | int value, int reg_off) | ||
438 | { | ||
439 | /* < 0 for a value that is ignored */ | ||
440 | if (value < 0) | ||
441 | writeb(0, rtc->regbase + reg_off); | ||
442 | else | ||
443 | writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off); | ||
444 | } | ||
445 | |||
446 | static int sh_rtc_check_alarm(struct rtc_time* tm) | ||
447 | { | ||
448 | /* | ||
449 | * The original rtc says anything > 0xc0 is "don't care" or "match | ||
450 | * all" - most users use 0xff but rtc-dev uses -1 for the same thing. | ||
451 | * The original rtc doesn't support years - some things use -1 and | ||
452 | * some 0xffff. We use -1 to make out tests easier. | ||
453 | */ | ||
454 | if (tm->tm_year == 0xffff) | ||
455 | tm->tm_year = -1; | ||
456 | if (tm->tm_mon >= 0xff) | ||
457 | tm->tm_mon = -1; | ||
458 | if (tm->tm_mday >= 0xff) | ||
459 | tm->tm_mday = -1; | ||
460 | if (tm->tm_wday >= 0xff) | ||
461 | tm->tm_wday = -1; | ||
462 | if (tm->tm_hour >= 0xff) | ||
463 | tm->tm_hour = -1; | ||
464 | if (tm->tm_min >= 0xff) | ||
465 | tm->tm_min = -1; | ||
466 | if (tm->tm_sec >= 0xff) | ||
467 | tm->tm_sec = -1; | ||
468 | |||
469 | if (tm->tm_year > 9999 || | ||
470 | tm->tm_mon >= 12 || | ||
471 | tm->tm_mday == 0 || tm->tm_mday >= 32 || | ||
472 | tm->tm_wday >= 7 || | ||
473 | tm->tm_hour >= 24 || | ||
474 | tm->tm_min >= 60 || | ||
475 | tm->tm_sec >= 60) | ||
476 | return -EINVAL; | ||
477 | |||
478 | return 0; | ||
479 | } | ||
480 | |||
481 | static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | ||
482 | { | ||
483 | struct platform_device *pdev = to_platform_device(dev); | ||
484 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
485 | unsigned int rcr1; | ||
486 | struct rtc_time *tm = &wkalrm->time; | ||
487 | int mon, err; | ||
488 | |||
489 | err = sh_rtc_check_alarm(tm); | ||
490 | if (unlikely(err < 0)) | ||
491 | return err; | ||
492 | |||
493 | spin_lock_irq(&rtc->lock); | ||
494 | |||
495 | /* disable alarm interrupt and clear flag */ | ||
496 | rcr1 = readb(rtc->regbase + RCR1); | ||
497 | rcr1 &= ~RCR1_AF; | ||
498 | writeb(rcr1 & ~RCR1_AIE, rtc->regbase + RCR1); | ||
499 | |||
500 | rtc->rearm_aie = 0; | ||
501 | |||
502 | /* set alarm time */ | ||
503 | sh_rtc_write_alarm_value(rtc, tm->tm_sec, RSECAR); | ||
504 | sh_rtc_write_alarm_value(rtc, tm->tm_min, RMINAR); | ||
505 | sh_rtc_write_alarm_value(rtc, tm->tm_hour, RHRAR); | ||
506 | sh_rtc_write_alarm_value(rtc, tm->tm_wday, RWKAR); | ||
507 | sh_rtc_write_alarm_value(rtc, tm->tm_mday, RDAYAR); | ||
508 | mon = tm->tm_mon; | ||
509 | if (mon >= 0) | ||
510 | mon += 1; | ||
511 | sh_rtc_write_alarm_value(rtc, mon, RMONAR); | ||
512 | |||
513 | /* Restore interrupt activation status */ | ||
514 | writeb(rcr1, rtc->regbase + RCR1); | ||
515 | |||
516 | spin_unlock_irq(&rtc->lock); | ||
517 | |||
518 | return 0; | ||
519 | } | ||
520 | |||
347 | static struct rtc_class_ops sh_rtc_ops = { | 521 | static struct rtc_class_ops sh_rtc_ops = { |
348 | .open = sh_rtc_open, | 522 | .open = sh_rtc_open, |
349 | .release = sh_rtc_release, | 523 | .release = sh_rtc_release, |
350 | .ioctl = sh_rtc_ioctl, | 524 | .ioctl = sh_rtc_ioctl, |
351 | .read_time = sh_rtc_read_time, | 525 | .read_time = sh_rtc_read_time, |
352 | .set_time = sh_rtc_set_time, | 526 | .set_time = sh_rtc_set_time, |
527 | .read_alarm = sh_rtc_read_alarm, | ||
528 | .set_alarm = sh_rtc_set_alarm, | ||
353 | .proc = sh_rtc_proc, | 529 | .proc = sh_rtc_proc, |
354 | }; | 530 | }; |
355 | 531 | ||
@@ -442,7 +618,7 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev) | |||
442 | } | 618 | } |
443 | static struct platform_driver sh_rtc_platform_driver = { | 619 | static struct platform_driver sh_rtc_platform_driver = { |
444 | .driver = { | 620 | .driver = { |
445 | .name = "sh-rtc", | 621 | .name = DRV_NAME, |
446 | .owner = THIS_MODULE, | 622 | .owner = THIS_MODULE, |
447 | }, | 623 | }, |
448 | .probe = sh_rtc_probe, | 624 | .probe = sh_rtc_probe, |
@@ -463,5 +639,6 @@ module_init(sh_rtc_init); | |||
463 | module_exit(sh_rtc_exit); | 639 | module_exit(sh_rtc_exit); |
464 | 640 | ||
465 | MODULE_DESCRIPTION("SuperH on-chip RTC driver"); | 641 | MODULE_DESCRIPTION("SuperH on-chip RTC driver"); |
466 | MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>"); | 642 | MODULE_VERSION(DRV_VERSION); |
643 | MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, Jamie Lenehan <lenehan@twibble.org>"); | ||
467 | MODULE_LICENSE("GPL"); | 644 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index 9a67487d086b..019ae255b0c8 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
@@ -372,7 +372,7 @@ static int x1205_validate_client(struct i2c_client *client) | |||
372 | }; | 372 | }; |
373 | 373 | ||
374 | if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { | 374 | if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { |
375 | dev_err(&client->adapter->dev, | 375 | dev_err(&client->dev, |
376 | "%s: could not read register %x\n", | 376 | "%s: could not read register %x\n", |
377 | __FUNCTION__, probe_zero_pattern[i]); | 377 | __FUNCTION__, probe_zero_pattern[i]); |
378 | 378 | ||
@@ -380,7 +380,7 @@ static int x1205_validate_client(struct i2c_client *client) | |||
380 | } | 380 | } |
381 | 381 | ||
382 | if ((buf & probe_zero_pattern[i+1]) != 0) { | 382 | if ((buf & probe_zero_pattern[i+1]) != 0) { |
383 | dev_err(&client->adapter->dev, | 383 | dev_err(&client->dev, |
384 | "%s: register=%02x, zero pattern=%d, value=%x\n", | 384 | "%s: register=%02x, zero pattern=%d, value=%x\n", |
385 | __FUNCTION__, probe_zero_pattern[i], i, buf); | 385 | __FUNCTION__, probe_zero_pattern[i], i, buf); |
386 | 386 | ||
@@ -400,7 +400,7 @@ static int x1205_validate_client(struct i2c_client *client) | |||
400 | }; | 400 | }; |
401 | 401 | ||
402 | if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { | 402 | if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { |
403 | dev_err(&client->adapter->dev, | 403 | dev_err(&client->dev, |
404 | "%s: could not read register %x\n", | 404 | "%s: could not read register %x\n", |
405 | __FUNCTION__, probe_limits_pattern[i].reg); | 405 | __FUNCTION__, probe_limits_pattern[i].reg); |
406 | 406 | ||
@@ -411,7 +411,7 @@ static int x1205_validate_client(struct i2c_client *client) | |||
411 | 411 | ||
412 | if (value > probe_limits_pattern[i].max || | 412 | if (value > probe_limits_pattern[i].max || |
413 | value < probe_limits_pattern[i].min) { | 413 | value < probe_limits_pattern[i].min) { |
414 | dev_dbg(&client->adapter->dev, | 414 | dev_dbg(&client->dev, |
415 | "%s: register=%x, lim pattern=%d, value=%d\n", | 415 | "%s: register=%x, lim pattern=%d, value=%d\n", |
416 | __FUNCTION__, probe_limits_pattern[i].reg, | 416 | __FUNCTION__, probe_limits_pattern[i].reg, |
417 | i, value); | 417 | i, value); |
@@ -506,7 +506,7 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind) | |||
506 | struct i2c_client *client; | 506 | struct i2c_client *client; |
507 | struct rtc_device *rtc; | 507 | struct rtc_device *rtc; |
508 | 508 | ||
509 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | 509 | dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__); |
510 | 510 | ||
511 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { | 511 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { |
512 | err = -ENODEV; | 512 | err = -ENODEV; |