Skip to content

Commit eaedc0d

Browse files
claudiubeznealdesroches
authored andcommitted
ARM: at91: pm: add ULP1 support for SAM9X60
Add ULP1 support for SAM9X60. In pm_suspend.S enable RC oscillator in PMC if it is not enabled. At resume the state before suspend is restored. Signed-off-by: Claudiu Beznea <[email protected]> Acked-by: Stephen Boyd <[email protected]> Signed-off-by: Alexandre Belloni <[email protected]> Signed-off-by: Ludovic Desroches <[email protected]>
1 parent a958156 commit eaedc0d

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

arch/arm/mach-at91/pm.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ static const struct wakeup_source_info ws_info[] = {
100100
{ .pmc_fsmr_bit = AT91_PMC_RTCAL, .shdwc_mr_bit = BIT(17) },
101101
{ .pmc_fsmr_bit = AT91_PMC_USBAL },
102102
{ .pmc_fsmr_bit = AT91_PMC_SDMMC_CD },
103+
{ .pmc_fsmr_bit = AT91_PMC_RTTAL },
104+
{ .pmc_fsmr_bit = AT91_PMC_RXLP_MCE },
103105
};
104106

105107
static const struct of_device_id sama5d2_ws_ids[] = {
@@ -114,6 +116,17 @@ static const struct of_device_id sama5d2_ws_ids[] = {
114116
{ /* sentinel */ }
115117
};
116118

119+
static const struct of_device_id sam9x60_ws_ids[] = {
120+
{ .compatible = "atmel,at91sam9x5-rtc", .data = &ws_info[1] },
121+
{ .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
122+
{ .compatible = "usb-ohci", .data = &ws_info[2] },
123+
{ .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
124+
{ .compatible = "usb-ehci", .data = &ws_info[2] },
125+
{ .compatible = "atmel,at91sam9260-rtt", .data = &ws_info[4] },
126+
{ .compatible = "cdns,sam9x60-macb", .data = &ws_info[5] },
127+
{ /* sentinel */ }
128+
};
129+
117130
static int at91_pm_config_ws(unsigned int pm_mode, bool set)
118131
{
119132
const struct wakeup_source_info *wsi;
@@ -192,6 +205,13 @@ static int at91_sama5d2_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
192205
return 0;
193206
}
194207

208+
static int at91_sam9x60_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
209+
{
210+
writel(mode, pmc + AT91_PMC_FSMR);
211+
212+
return 0;
213+
}
214+
195215
/*
196216
* Called after processes are frozen, but before we shutdown devices.
197217
*/
@@ -789,8 +809,12 @@ void __init sam9x60_pm_init(void)
789809
if (!IS_ENABLED(CONFIG_SOC_AT91SAM9))
790810
return;
791811

812+
at91_pm_modes_init();
792813
at91_dt_ramc();
793814
at91_pm_init(at91sam9x60_idle);
815+
816+
soc_pm.ws_ids = sam9x60_ws_ids;
817+
soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
794818
}
795819

796820
void __init at91sam9_pm_init(void)

arch/arm/mach-at91/pm_suspend.S

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,26 @@ ENDPROC(at91_backup_mode)
197197
.macro at91_pm_ulp1_mode
198198
ldr pmc, .pmc_base
199199

200-
/* Switch the main clock source to 12-MHz RC oscillator */
200+
/* Save RC oscillator state and check if it is enabled. */
201+
ldr tmp1, [pmc, #AT91_PMC_SR]
202+
str tmp1, .saved_osc_status
203+
tst tmp1, #AT91_PMC_MOSCRCS
204+
bne 2f
205+
206+
/* Enable RC oscillator */
201207
ldr tmp1, [pmc, #AT91_CKGR_MOR]
208+
orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
209+
bic tmp1, tmp1, #AT91_PMC_KEY_MASK
210+
orr tmp1, tmp1, #AT91_PMC_KEY
211+
str tmp1, [pmc, #AT91_CKGR_MOR]
212+
213+
/* Wait main RC stabilization */
214+
1: ldr tmp1, [pmc, #AT91_PMC_SR]
215+
tst tmp1, #AT91_PMC_MOSCRCS
216+
beq 1b
217+
218+
/* Switch the main clock source to 12-MHz RC oscillator */
219+
2: ldr tmp1, [pmc, #AT91_CKGR_MOR]
202220
bic tmp1, tmp1, #AT91_PMC_MOSCSEL
203221
bic tmp1, tmp1, #AT91_PMC_KEY_MASK
204222
orr tmp1, tmp1, #AT91_PMC_KEY
@@ -262,6 +280,25 @@ ENDPROC(at91_backup_mode)
262280
str tmp1, [pmc, #AT91_PMC_MCKR]
263281

264282
wait_mckrdy
283+
284+
/* Restore RC oscillator state */
285+
ldr tmp1, .saved_osc_status
286+
tst tmp1, #AT91_PMC_MOSCRCS
287+
bne 3f
288+
289+
/* Disable RC oscillator */
290+
ldr tmp1, [pmc, #AT91_CKGR_MOR]
291+
bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
292+
bic tmp1, tmp1, #AT91_PMC_KEY_MASK
293+
orr tmp1, tmp1, #AT91_PMC_KEY
294+
str tmp1, [pmc, #AT91_CKGR_MOR]
295+
296+
/* Wait RC oscillator disable done */
297+
4: ldr tmp1, [pmc, #AT91_PMC_SR]
298+
tst tmp1, #AT91_PMC_MOSCRCS
299+
bne 4b
300+
301+
3:
265302
.endm
266303

267304
ENTRY(at91_ulp_mode)
@@ -475,6 +512,8 @@ ENDPROC(at91_sramc_self_refresh)
475512
.word 0
476513
.saved_sam9_mdr1:
477514
.word 0
515+
.saved_osc_status:
516+
.word 0
478517

479518
ENTRY(at91_pm_suspend_in_sram_sz)
480519
.word .-at91_pm_suspend_in_sram

include/linux/clk/at91_pmc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159

160160
#define AT91_PMC_FSMR 0x70 /* Fast Startup Mode Register */
161161
#define AT91_PMC_FSTT(n) BIT(n)
162+
#define AT91_PMC_RTTAL BIT(16)
162163
#define AT91_PMC_RTCAL BIT(17) /* RTC Alarm Enable */
163164
#define AT91_PMC_USBAL BIT(18) /* USB Resume Enable */
164165
#define AT91_PMC_SDMMC_CD BIT(19) /* SDMMC Card Detect Enable */

0 commit comments

Comments
 (0)