xref: /linux/arch/arm/mach-omap2/sdrc.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f2ab9977SPaul Walmsley /*
3f2ab9977SPaul Walmsley  * SMS/SDRC (SDRAM controller) common code for OMAP2/3
4f2ab9977SPaul Walmsley  *
5f2ab9977SPaul Walmsley  * Copyright (C) 2005, 2008 Texas Instruments Inc.
6f2ab9977SPaul Walmsley  * Copyright (C) 2005, 2008 Nokia Corporation
7f2ab9977SPaul Walmsley  *
8f2ab9977SPaul Walmsley  * Tony Lindgren <tony@atomide.com>
9f2ab9977SPaul Walmsley  * Paul Walmsley
10f2ab9977SPaul Walmsley  * Richard Woodruff <r-woodruff2@ti.com>
11f2ab9977SPaul Walmsley  */
1287246b75SPaul Walmsley #undef DEBUG
13f2ab9977SPaul Walmsley 
14f2ab9977SPaul Walmsley #include <linux/module.h>
15f2ab9977SPaul Walmsley #include <linux/kernel.h>
16f2ab9977SPaul Walmsley #include <linux/device.h>
17f2ab9977SPaul Walmsley #include <linux/list.h>
18f2ab9977SPaul Walmsley #include <linux/errno.h>
19f2ab9977SPaul Walmsley #include <linux/delay.h>
20f2ab9977SPaul Walmsley #include <linux/clk.h>
21f2ab9977SPaul Walmsley #include <linux/io.h>
22f2ab9977SPaul Walmsley 
23a135eaaeSPaul Walmsley #include "common.h"
24a135eaaeSPaul Walmsley #include "clock.h"
25f2ab9977SPaul Walmsley #include "sdrc.h"
26f2ab9977SPaul Walmsley 
2758cda884SJean Pihet static struct omap_sdrc_params *sdrc_init_params_cs0, *sdrc_init_params_cs1;
2887246b75SPaul Walmsley 
29f2ab9977SPaul Walmsley void __iomem *omap2_sdrc_base;
30f2ab9977SPaul Walmsley void __iomem *omap2_sms_base;
31f2ab9977SPaul Walmsley 
328a917d2fSKalle Jokiniemi struct omap2_sms_regs {
338a917d2fSKalle Jokiniemi 	u32	sms_sysconfig;
348a917d2fSKalle Jokiniemi };
358a917d2fSKalle Jokiniemi 
368a917d2fSKalle Jokiniemi static struct omap2_sms_regs sms_context;
378a917d2fSKalle Jokiniemi 
3898cfe5abSPaul Walmsley /* SDRC_POWER register bits */
3998cfe5abSPaul Walmsley #define SDRC_POWER_EXTCLKDIS_SHIFT		3
4098cfe5abSPaul Walmsley #define SDRC_POWER_PWDENA_SHIFT			2
4198cfe5abSPaul Walmsley #define SDRC_POWER_PAGEPOLICY_SHIFT		0
4287246b75SPaul Walmsley 
4387246b75SPaul Walmsley /**
448a917d2fSKalle Jokiniemi  * omap2_sms_save_context - Save SMS registers
458a917d2fSKalle Jokiniemi  *
468a917d2fSKalle Jokiniemi  * Save SMS registers that need to be restored after off mode.
478a917d2fSKalle Jokiniemi  */
omap2_sms_save_context(void)48*6aeb51c1SArnd Bergmann static void omap2_sms_save_context(void)
498a917d2fSKalle Jokiniemi {
508a917d2fSKalle Jokiniemi 	sms_context.sms_sysconfig = sms_read_reg(SMS_SYSCONFIG);
518a917d2fSKalle Jokiniemi }
528a917d2fSKalle Jokiniemi 
538a917d2fSKalle Jokiniemi /**
548a917d2fSKalle Jokiniemi  * omap2_sms_restore_context - Restore SMS registers
558a917d2fSKalle Jokiniemi  *
568a917d2fSKalle Jokiniemi  * Restore SMS registers that need to be Restored after off mode.
578a917d2fSKalle Jokiniemi  */
omap2_sms_restore_context(void)588a917d2fSKalle Jokiniemi void omap2_sms_restore_context(void)
598a917d2fSKalle Jokiniemi {
608a917d2fSKalle Jokiniemi 	sms_write_reg(sms_context.sms_sysconfig, SMS_SYSCONFIG);
618a917d2fSKalle Jokiniemi }
628a917d2fSKalle Jokiniemi 
omap2_set_globals_sdrc(void __iomem * sdrc,void __iomem * sms)63b6a4226cSPaul Walmsley void __init omap2_set_globals_sdrc(void __iomem *sdrc, void __iomem *sms)
64f2ab9977SPaul Walmsley {
65b6a4226cSPaul Walmsley 	omap2_sdrc_base = sdrc;
66b6a4226cSPaul Walmsley 	omap2_sms_base = sms;
67f2ab9977SPaul Walmsley }
68f2ab9977SPaul Walmsley 
6998cfe5abSPaul Walmsley /**
7098cfe5abSPaul Walmsley  * omap2_sdrc_init - initialize SMS, SDRC devices on boot
7158cda884SJean Pihet  * @sdrc_cs[01]: pointers to a null-terminated list of struct omap_sdrc_params
7258cda884SJean Pihet  *  Support for 2 chip selects timings
7398cfe5abSPaul Walmsley  *
7498cfe5abSPaul Walmsley  * Turn on smart idle modes for SDRAM scheduler and controller.
7598cfe5abSPaul Walmsley  * Program a known-good configuration for the SDRC to deal with buggy
7698cfe5abSPaul Walmsley  * bootloaders.
7798cfe5abSPaul Walmsley  */
omap2_sdrc_init(struct omap_sdrc_params * sdrc_cs0,struct omap_sdrc_params * sdrc_cs1)7858cda884SJean Pihet void __init omap2_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
7958cda884SJean Pihet 			    struct omap_sdrc_params *sdrc_cs1)
80f2ab9977SPaul Walmsley {
81f2ab9977SPaul Walmsley 	u32 l;
82f2ab9977SPaul Walmsley 
83f2ab9977SPaul Walmsley 	l = sms_read_reg(SMS_SYSCONFIG);
84f2ab9977SPaul Walmsley 	l &= ~(0x3 << 3);
85f2ab9977SPaul Walmsley 	l |= (0x2 << 3);
86f2ab9977SPaul Walmsley 	sms_write_reg(l, SMS_SYSCONFIG);
87f2ab9977SPaul Walmsley 
88f2ab9977SPaul Walmsley 	l = sdrc_read_reg(SDRC_SYSCONFIG);
89f2ab9977SPaul Walmsley 	l &= ~(0x3 << 3);
90f2ab9977SPaul Walmsley 	l |= (0x2 << 3);
91f2ab9977SPaul Walmsley 	sdrc_write_reg(l, SDRC_SYSCONFIG);
9287246b75SPaul Walmsley 
9358cda884SJean Pihet 	sdrc_init_params_cs0 = sdrc_cs0;
9458cda884SJean Pihet 	sdrc_init_params_cs1 = sdrc_cs1;
9598cfe5abSPaul Walmsley 
9698cfe5abSPaul Walmsley 	/* XXX Enable SRFRONIDLEREQ here also? */
9775f251e3SPaul Walmsley 	/*
9875f251e3SPaul Walmsley 	 * PWDENA should not be set due to 34xx erratum 1.150 - PWDENA
9975f251e3SPaul Walmsley 	 * can cause random memory corruption
10075f251e3SPaul Walmsley 	 */
10198cfe5abSPaul Walmsley 	l = (1 << SDRC_POWER_EXTCLKDIS_SHIFT) |
10298cfe5abSPaul Walmsley 		(1 << SDRC_POWER_PAGEPOLICY_SHIFT);
10398cfe5abSPaul Walmsley 	sdrc_write_reg(l, SDRC_POWER);
1048a917d2fSKalle Jokiniemi 	omap2_sms_save_context();
105f2ab9977SPaul Walmsley }
106