Updated upstream Git repositories
[opendreambox.git] / meta-dreambox / recipes-kernel / linux / linux-dreambox-3.4 / 0001-dream-dont-reset-wktmr-on-warm-boot.patch
1 From d9a585852522eb0859f879cf704665bf3ede3a84 Mon Sep 17 00:00:00 2001
2 From: Andreas Monzner <andreas.monzner@dream-property.net>
3 Date: Tue, 20 Dec 2016 15:40:33 +0100
4 Subject: [PATCH] dream: dont reset wktmr on warm boot
5
6 ---
7  arch/mips/brcmstb/time.c | 10 ++++++++++
8  drivers/brcmstb/bchip.c  | 20 +++++++++++---------
9  2 files changed, 21 insertions(+), 9 deletions(-)
10
11 diff --git a/arch/mips/brcmstb/time.c b/arch/mips/brcmstb/time.c
12 index 197a2c4..c38f56a 100644
13 --- a/arch/mips/brcmstb/time.c
14 +++ b/arch/mips/brcmstb/time.c
15 @@ -65,13 +65,23 @@ static DEFINE_SPINLOCK(wktmr_lock);
16  
17  static cycle_t wktmr_cs_read(struct clocksource *cs)
18  {
19 +       static struct wktmr_time offs = { (uint32_t)-1, (uint32_t)-1 };
20         struct wktmr_time t;
21         unsigned long flags;
22  
23         spin_lock_irqsave(&wktmr_lock, flags);
24         wktmr_read(&t);
25 +       if (offs.pre == (uint32_t)-1 && offs.sec == offs.pre)
26 +               offs = t;
27         spin_unlock_irqrestore(&wktmr_lock, flags);
28  
29 +       t.sec -= offs.sec;
30 +       t.pre -= offs.pre;
31 +       if ((int32_t)t.pre < 0) {
32 +               t.pre += WKTMR_FREQ;
33 +               --t.sec;
34 +       }
35 +
36         return (t.sec * (cycle_t)WKTMR_FREQ) + t.pre;
37  }
38  
39 diff --git a/drivers/brcmstb/bchip.c b/drivers/brcmstb/bchip.c
40 index 148d573..7bae487 100644
41 --- a/drivers/brcmstb/bchip.c
42 +++ b/drivers/brcmstb/bchip.c
43 @@ -459,14 +459,16 @@ void __init bchip_early_setup(void)
44  #if defined(CONFIG_BRCM_HAS_WKTMR)
45         struct wktmr_time t;
46  
47 -       BDEV_WR_F_RB(WKTMR_EVENT, wktmr_alarm_event, 1);
48 -       BDEV_WR_F_RB(WKTMR_PRESCALER, wktmr_prescaler, WKTMR_FREQ);
49 -       BDEV_WR_F_RB(WKTMR_COUNTER, wktmr_counter, 0);
50 -
51 -       /* wait for first tick so we know the counter is ready to use */
52 -       wktmr_read(&t);
53 -       while (wktmr_elapsed(&t) == 0)
54 -               ;
55 +       if (!(BDEV_RD(AON_RAM(122)) & (3<<30))) {
56 +               BDEV_WR_F_RB(WKTMR_EVENT, wktmr_alarm_event, 1);
57 +               BDEV_WR_F_RB(WKTMR_PRESCALER, wktmr_prescaler, WKTMR_FREQ);
58 +               BDEV_WR_F_RB(WKTMR_COUNTER, wktmr_counter, 0);
59 +
60 +               /* wait for first tick so we know the counter is ready to use */
61 +               wktmr_read(&t);
62 +               while (wktmr_elapsed(&t) == 0)
63 +                       ;
64 +       }
65  #endif
66  
67  #ifdef CONFIG_PCI
68 @@ -548,7 +550,7 @@ unsigned long wktmr_elapsed(struct wktmr_time *t)
69  
70         wktmr_read(&now);
71         now.sec -= t->sec;
72 -       if (now.pre > t->pre) {
73 +       if (now.pre >= t->pre) {
74                 now.pre -= t->pre;
75         } else {
76                 now.pre = WKTMR_FREQ + now.pre - t->pre;
77 -- 
78 2.1.4
79