2 * SMS/SDRC (SDRAM controller) common code for OMAP2/3
4 * Copyright (C) 2005, 2008 Texas Instruments Inc.
5 * Copyright (C) 2005, 2008 Nokia Corporation
7 * Tony Lindgren <tony@atomide.com>
9 * Richard Woodruff <r-woodruff2@ti.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/device.h>
20 #include <linux/list.h>
21 #include <linux/errno.h>
22 #include <linux/delay.h>
23 #include <linux/clk.h>
26 #include <plat/common.h>
27 #include <plat/clock.h>
28 #include <plat/sram.h>
32 #include <plat/sdrc.h>
35 static struct omap_sdrc_params
*sdrc_init_params_cs0
, *sdrc_init_params_cs1
;
37 void __iomem
*omap2_sdrc_base
;
38 void __iomem
*omap2_sms_base
;
40 struct omap2_sms_regs
{
44 static struct omap2_sms_regs sms_context
;
46 /* SDRC_POWER register bits */
47 #define SDRC_POWER_EXTCLKDIS_SHIFT 3
48 #define SDRC_POWER_PWDENA_SHIFT 2
49 #define SDRC_POWER_PAGEPOLICY_SHIFT 0
52 * omap2_sms_save_context - Save SMS registers
54 * Save SMS registers that need to be restored after off mode.
56 void omap2_sms_save_context(void)
58 sms_context
.sms_sysconfig
= sms_read_reg(SMS_SYSCONFIG
);
62 * omap2_sms_restore_context - Restore SMS registers
64 * Restore SMS registers that need to be Restored after off mode.
66 void omap2_sms_restore_context(void)
68 sms_write_reg(sms_context
.sms_sysconfig
, SMS_SYSCONFIG
);
72 * omap2_sdrc_get_params - return SDRC register values for a given clock rate
73 * @r: SDRC clock rate (in Hz)
74 * @sdrc_cs0: chip select 0 ram timings **
75 * @sdrc_cs1: chip select 1 ram timings **
77 * Return pre-calculated values for the SDRC_ACTIM_CTRLA,
78 * SDRC_ACTIM_CTRLB, SDRC_RFR_CTRL and SDRC_MR registers in sdrc_cs[01]
79 * structs,for a given SDRC clock rate 'r'.
80 * These parameters control various timing delays in the SDRAM controller
81 * that are expressed in terms of the number of SDRC clock cycles to
82 * wait; hence the clock rate dependency.
84 * Supports 2 different timing parameters for both chip selects.
86 * Note 1: the sdrc_init_params_cs[01] must be sorted rate descending.
87 * Note 2: If sdrc_init_params_cs_1 is not NULL it must be of same size
88 * as sdrc_init_params_cs_0.
90 * Fills in the struct omap_sdrc_params * for each chip select.
91 * Returns 0 upon success or -1 upon failure.
93 int omap2_sdrc_get_params(unsigned long r
,
94 struct omap_sdrc_params
**sdrc_cs0
,
95 struct omap_sdrc_params
**sdrc_cs1
)
97 struct omap_sdrc_params
*sp0
, *sp1
;
99 if (!sdrc_init_params_cs0
)
102 sp0
= sdrc_init_params_cs0
;
103 sp1
= sdrc_init_params_cs1
;
105 while (sp0
->rate
&& sp0
->rate
!= r
) {
107 if (sdrc_init_params_cs1
)
120 void __init
omap2_set_globals_sdrc(struct omap_globals
*omap2_globals
)
122 omap2_sdrc_base
= omap2_globals
->sdrc
;
123 omap2_sms_base
= omap2_globals
->sms
;
127 * omap2_sdrc_init - initialize SMS, SDRC devices on boot
128 * @sdrc_cs[01]: pointers to a null-terminated list of struct omap_sdrc_params
129 * Support for 2 chip selects timings
131 * Turn on smart idle modes for SDRAM scheduler and controller.
132 * Program a known-good configuration for the SDRC to deal with buggy
135 void __init
omap2_sdrc_init(struct omap_sdrc_params
*sdrc_cs0
,
136 struct omap_sdrc_params
*sdrc_cs1
)
140 l
= sms_read_reg(SMS_SYSCONFIG
);
143 sms_write_reg(l
, SMS_SYSCONFIG
);
145 l
= sdrc_read_reg(SDRC_SYSCONFIG
);
148 sdrc_write_reg(l
, SDRC_SYSCONFIG
);
150 sdrc_init_params_cs0
= sdrc_cs0
;
151 sdrc_init_params_cs1
= sdrc_cs1
;
153 /* XXX Enable SRFRONIDLEREQ here also? */
155 * PWDENA should not be set due to 34xx erratum 1.150 - PWDENA
156 * can cause random memory corruption
158 l
= (1 << SDRC_POWER_EXTCLKDIS_SHIFT
) |
159 (1 << SDRC_POWER_PAGEPOLICY_SHIFT
);
160 sdrc_write_reg(l
, SDRC_POWER
);
161 omap2_sms_save_context();