aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>2010-12-16 15:31:32 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2010-12-21 09:53:43 -0500
commitd2ccb52d88dcb7eb3539d0e0c77a7028b8d46037 (patch)
tree335bde43defe6cb2916ebb92b23b85cb1d6c3712
parent47bb3b31ab2c95e275b850a291794a29aaaa31cd (diff)
ARM: 6455/2: Better use of the RTC framework for sa11xx.
This patch uses the RTC framework to treat some common ioctl. In particular, it fixes the behaviour of rtc_irq_set_freq(), which did not work as expected because the timer was not beeing retriggered. Signed-off-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--drivers/rtc/rtc-sa1100.c98
1 files changed, 74 insertions, 24 deletions
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index b0985f727078..88ea52b8647a 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -42,7 +42,7 @@
42#define RTC_DEF_DIVIDER (32768 - 1) 42#define RTC_DEF_DIVIDER (32768 - 1)
43#define RTC_DEF_TRIM 0 43#define RTC_DEF_TRIM 0
44 44
45static unsigned long rtc_freq = 1024; 45static const unsigned long RTC_FREQ = 1024;
46static unsigned long timer_freq; 46static unsigned long timer_freq;
47static struct rtc_time rtc_alarm; 47static struct rtc_time rtc_alarm;
48static DEFINE_SPINLOCK(sa1100_rtc_lock); 48static DEFINE_SPINLOCK(sa1100_rtc_lock);
@@ -156,8 +156,58 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
156 return IRQ_HANDLED; 156 return IRQ_HANDLED;
157} 157}
158 158
159static int sa1100_irq_set_freq(struct device *dev, int freq)
160{
161 if (freq < 1 || freq > timer_freq) {
162 return -EINVAL;
163 } else {
164 struct rtc_device *rtc = (struct rtc_device *)dev;
165
166 rtc->irq_freq = freq;
167
168 return 0;
169 }
170}
171
159static int rtc_timer1_count; 172static int rtc_timer1_count;
160 173
174static int sa1100_irq_set_state(struct device *dev, int enabled)
175{
176 spin_lock_irq(&sa1100_rtc_lock);
177 if (enabled) {
178 struct rtc_device *rtc = (struct rtc_device *)dev;
179
180 OSMR1 = timer_freq / rtc->irq_freq + OSCR;
181 OIER |= OIER_E1;
182 rtc_timer1_count = 1;
183 } else {
184 OIER &= ~OIER_E1;
185 }
186 spin_unlock_irq(&sa1100_rtc_lock);
187
188 return 0;
189}
190
191static inline int sa1100_timer1_retrigger(struct rtc_device *rtc)
192{
193 unsigned long diff;
194 unsigned long period = timer_freq / rtc->irq_freq;
195
196 spin_lock_irq(&sa1100_rtc_lock);
197
198 do {
199 OSMR1 += period;
200 diff = OSMR1 - OSCR;
201 /* If OSCR > OSMR1, diff is a very large number (unsigned
202 * math). This means we have a lost interrupt. */
203 } while (diff > period);
204 OIER |= OIER_E1;
205
206 spin_unlock_irq(&sa1100_rtc_lock);
207
208 return 0;
209}
210
161static irqreturn_t timer1_interrupt(int irq, void *dev_id) 211static irqreturn_t timer1_interrupt(int irq, void *dev_id)
162{ 212{
163 struct platform_device *pdev = to_platform_device(dev_id); 213 struct platform_device *pdev = to_platform_device(dev_id);
@@ -175,7 +225,11 @@ static irqreturn_t timer1_interrupt(int irq, void *dev_id)
175 rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); 225 rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF);
176 226
177 if (rtc_timer1_count == 1) 227 if (rtc_timer1_count == 1)
178 rtc_timer1_count = (rtc_freq * ((1 << 30) / (timer_freq >> 2))); 228 rtc_timer1_count =
229 (rtc->irq_freq * ((1 << 30) / (timer_freq >> 2)));
230
231 /* retrigger. */
232 sa1100_timer1_retrigger(rtc);
179 233
180 return IRQ_HANDLED; 234 return IRQ_HANDLED;
181} 235}
@@ -183,8 +237,10 @@ static irqreturn_t timer1_interrupt(int irq, void *dev_id)
183static int sa1100_rtc_read_callback(struct device *dev, int data) 237static int sa1100_rtc_read_callback(struct device *dev, int data)
184{ 238{
185 if (data & RTC_PF) { 239 if (data & RTC_PF) {
240 struct rtc_device *rtc = (struct rtc_device *)dev;
241
186 /* interpolate missed periods and set match for the next */ 242 /* interpolate missed periods and set match for the next */
187 unsigned long period = timer_freq / rtc_freq; 243 unsigned long period = timer_freq / rtc->irq_freq;
188 unsigned long oscr = OSCR; 244 unsigned long oscr = OSCR;
189 unsigned long osmr1 = OSMR1; 245 unsigned long osmr1 = OSMR1;
190 unsigned long missed = (oscr - osmr1)/period; 246 unsigned long missed = (oscr - osmr1)/period;
@@ -207,6 +263,7 @@ static int sa1100_rtc_read_callback(struct device *dev, int data)
207static int sa1100_rtc_open(struct device *dev) 263static int sa1100_rtc_open(struct device *dev)
208{ 264{
209 int ret; 265 int ret;
266 struct rtc_device *rtc = (struct rtc_device *)dev;
210 267
211 ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED, 268 ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED,
212 "rtc 1Hz", dev); 269 "rtc 1Hz", dev);
@@ -226,6 +283,9 @@ static int sa1100_rtc_open(struct device *dev)
226 dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1); 283 dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1);
227 goto fail_pi; 284 goto fail_pi;
228 } 285 }
286 rtc->max_user_freq = RTC_FREQ;
287 sa1100_irq_set_freq(dev, RTC_FREQ);
288
229 return 0; 289 return 0;
230 290
231 fail_pi: 291 fail_pi:
@@ -274,25 +334,6 @@ static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd,
274 RTSR |= RTSR_HZE; 334 RTSR |= RTSR_HZE;
275 spin_unlock_irq(&sa1100_rtc_lock); 335 spin_unlock_irq(&sa1100_rtc_lock);
276 return 0; 336 return 0;
277 case RTC_PIE_OFF:
278 spin_lock_irq(&sa1100_rtc_lock);
279 OIER &= ~OIER_E1;
280 spin_unlock_irq(&sa1100_rtc_lock);
281 return 0;
282 case RTC_PIE_ON:
283 spin_lock_irq(&sa1100_rtc_lock);
284 OSMR1 = timer_freq / rtc_freq + OSCR;
285 OIER |= OIER_E1;
286 rtc_timer1_count = 1;
287 spin_unlock_irq(&sa1100_rtc_lock);
288 return 0;
289 case RTC_IRQP_READ:
290 return put_user(rtc_freq, (unsigned long *)arg);
291 case RTC_IRQP_SET:
292 if (arg < 1 || arg > timer_freq)
293 return -EINVAL;
294 rtc_freq = arg;
295 return 0;
296 } 337 }
297 return -ENOIOCTLCMD; 338 return -ENOIOCTLCMD;
298} 339}
@@ -344,12 +385,14 @@ static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
344 385
345static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) 386static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
346{ 387{
388 struct rtc_device *rtc = (struct rtc_device *)dev;
389
347 seq_printf(seq, "trim/divider\t: 0x%08x\n", (u32) RTTR); 390 seq_printf(seq, "trim/divider\t: 0x%08x\n", (u32) RTTR);
348 seq_printf(seq, "update_IRQ\t: %s\n", 391 seq_printf(seq, "update_IRQ\t: %s\n",
349 (RTSR & RTSR_HZE) ? "yes" : "no"); 392 (RTSR & RTSR_HZE) ? "yes" : "no");
350 seq_printf(seq, "periodic_IRQ\t: %s\n", 393 seq_printf(seq, "periodic_IRQ\t: %s\n",
351 (OIER & OIER_E1) ? "yes" : "no"); 394 (OIER & OIER_E1) ? "yes" : "no");
352 seq_printf(seq, "periodic_freq\t: %ld\n", rtc_freq); 395 seq_printf(seq, "periodic_freq\t: %d\n", rtc->irq_freq);
353 seq_printf(seq, "RTSR\t\t: 0x%08x\n", (u32)RTSR); 396 seq_printf(seq, "RTSR\t\t: 0x%08x\n", (u32)RTSR);
354 397
355 return 0; 398 return 0;
@@ -365,6 +408,8 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
365 .read_alarm = sa1100_rtc_read_alarm, 408 .read_alarm = sa1100_rtc_read_alarm,
366 .set_alarm = sa1100_rtc_set_alarm, 409 .set_alarm = sa1100_rtc_set_alarm,
367 .proc = sa1100_rtc_proc, 410 .proc = sa1100_rtc_proc,
411 .irq_set_freq = sa1100_irq_set_freq,
412 .irq_set_state = sa1100_irq_set_state,
368}; 413};
369 414
370static int sa1100_rtc_probe(struct platform_device *pdev) 415static int sa1100_rtc_probe(struct platform_device *pdev)
@@ -391,13 +436,18 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
391 device_init_wakeup(&pdev->dev, 1); 436 device_init_wakeup(&pdev->dev, 1);
392 437
393 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, 438 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
394 THIS_MODULE); 439 THIS_MODULE);
395 440
396 if (IS_ERR(rtc)) 441 if (IS_ERR(rtc))
397 return PTR_ERR(rtc); 442 return PTR_ERR(rtc);
398 443
399 platform_set_drvdata(pdev, rtc); 444 platform_set_drvdata(pdev, rtc);
400 445
446 /* Set the irq_freq */
447 /*TODO: Find out who is messing with this value after we initialize
448 * it here.*/
449 rtc->irq_freq = RTC_FREQ;
450
401 /* Fix for a nasty initialization problem the in SA11xx RTSR register. 451 /* Fix for a nasty initialization problem the in SA11xx RTSR register.
402 * See also the comments in sa1100_rtc_interrupt(). 452 * See also the comments in sa1100_rtc_interrupt().
403 * 453 *