Skip to content

Commit 461932d

Browse files
lokeshvutlaPaul Walmsley
authored andcommitted
ARM: OMAP2+: hwmod: RTC: Add lock and unlock functions
RTC IP have kicker feature which prevents spurious writes to its registers. In order to write into any of the RTC registers, KICK values has to be written to KICK registers. Also, RTC busy flag needs to be polled for non-TC registers as well, without which update is not proper and confirmed it by testing on DRA7-evm. Introduce omap_hwmod_rtc_unlock/lock functions, which writes into these KICK registers inorder to lock and unlock RTC registers. Signed-off-by: Lokesh Vutla <[email protected]> [[email protected]: fixed subject line] Signed-off-by: Paul Walmsley <[email protected]>
1 parent b05ff3c commit 461932d

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

arch/arm/mach-omap2/omap_hwmod.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh);
754754
*/
755755

756756
extern int omap_hwmod_aess_preprogram(struct omap_hwmod *oh);
757+
void omap_hwmod_rtc_unlock(struct omap_hwmod *oh);
758+
void omap_hwmod_rtc_lock(struct omap_hwmod *oh);
757759

758760
/*
759761
* Chip variant-specific hwmod init routines - XXX should be converted

arch/arm/mach-omap2/omap_hwmod_reset.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#include <sound/aess.h>
3030

3131
#include "omap_hwmod.h"
32+
#include "common.h"
33+
34+
#define OMAP_RTC_STATUS_REG 0x44
35+
#define OMAP_RTC_KICK0_REG 0x6c
36+
#define OMAP_RTC_KICK1_REG 0x70
37+
38+
#define OMAP_RTC_KICK0_VALUE 0x83E70B13
39+
#define OMAP_RTC_KICK1_VALUE 0x95A4F1E0
40+
#define OMAP_RTC_STATUS_BUSY BIT(0)
41+
#define OMAP_RTC_MAX_READY_TIME 50
3242

3343
/**
3444
* omap_hwmod_aess_preprogram - enable AESS internal autogating
@@ -51,3 +61,58 @@ int omap_hwmod_aess_preprogram(struct omap_hwmod *oh)
5161

5262
return 0;
5363
}
64+
65+
/**
66+
* omap_rtc_wait_not_busy - Wait for the RTC BUSY flag
67+
* @oh: struct omap_hwmod *
68+
*
69+
* For updating certain RTC registers, the MPU must wait
70+
* for the BUSY status in OMAP_RTC_STATUS_REG to become zero.
71+
* Once the BUSY status is zero, there is a 15 microseconds access
72+
* period in which the MPU can program.
73+
*/
74+
static void omap_rtc_wait_not_busy(struct omap_hwmod *oh)
75+
{
76+
int i;
77+
78+
/* BUSY may stay active for 1/32768 second (~30 usec) */
79+
omap_test_timeout(omap_hwmod_read(oh, OMAP_RTC_STATUS_REG)
80+
& OMAP_RTC_STATUS_BUSY, OMAP_RTC_MAX_READY_TIME, i);
81+
/* now we have ~15 microseconds to read/write various registers */
82+
}
83+
84+
/**
85+
* omap_hwmod_rtc_unlock - Unlock the Kicker mechanism.
86+
* @oh: struct omap_hwmod *
87+
*
88+
* RTC IP have kicker feature. This prevents spurious writes to its registers.
89+
* In order to write into any of the RTC registers, KICK values has te be
90+
* written in respective KICK registers. This is needed for hwmod to write into
91+
* sysconfig register.
92+
*/
93+
void omap_hwmod_rtc_unlock(struct omap_hwmod *oh)
94+
{
95+
local_irq_disable();
96+
omap_rtc_wait_not_busy(oh);
97+
omap_hwmod_write(OMAP_RTC_KICK0_VALUE, oh, OMAP_RTC_KICK0_REG);
98+
omap_hwmod_write(OMAP_RTC_KICK1_VALUE, oh, OMAP_RTC_KICK1_REG);
99+
local_irq_enable();
100+
}
101+
102+
/**
103+
* omap_hwmod_rtc_lock - Lock the Kicker mechanism.
104+
* @oh: struct omap_hwmod *
105+
*
106+
* RTC IP have kicker feature. This prevents spurious writes to its registers.
107+
* Once the RTC registers are written, KICK mechanism needs to be locked,
108+
* in order to prevent any spurious writes. This function locks back the RTC
109+
* registers once hwmod completes its write into sysconfig register.
110+
*/
111+
void omap_hwmod_rtc_lock(struct omap_hwmod *oh)
112+
{
113+
local_irq_disable();
114+
omap_rtc_wait_not_busy(oh);
115+
omap_hwmod_write(0x0, oh, OMAP_RTC_KICK0_REG);
116+
omap_hwmod_write(0x0, oh, OMAP_RTC_KICK1_REG);
117+
local_irq_enable();
118+
}

0 commit comments

Comments
 (0)