blob: e3d345f464094c0709382b9ab160ef70384f581d [file] [log] [blame]
Paul Walmsleyf2ab9972009-01-28 12:27:37 -07001/*
2 * SMS/SDRC (SDRAM controller) common code for OMAP2/3
3 *
4 * Copyright (C) 2005, 2008 Texas Instruments Inc.
5 * Copyright (C) 2005, 2008 Nokia Corporation
6 *
7 * Tony Lindgren <tony@atomide.com>
8 * Paul Walmsley
9 * Richard Woodruff <r-woodruff2@ti.com>
10 *
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.
14 */
Paul Walmsley87246b72009-01-28 12:27:39 -070015#undef DEBUG
Paul Walmsleyf2ab9972009-01-28 12:27:37 -070016
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>
24#include <linux/io.h>
25
Tony Lindgren4e653312011-11-10 22:45:17 +010026#include "common.h"
Tony Lindgrence491cf2009-10-20 09:40:47 -070027#include <plat/clock.h>
28#include <plat/sram.h>
Paul Walmsleyf2ab9972009-01-28 12:27:37 -070029
Tony Lindgrence491cf2009-10-20 09:40:47 -070030#include <plat/sdrc.h>
Paul Walmsleyf2ab9972009-01-28 12:27:37 -070031#include "sdrc.h"
32
Jean Pihet58cda882009-07-24 19:43:25 -060033static struct omap_sdrc_params *sdrc_init_params_cs0, *sdrc_init_params_cs1;
Paul Walmsley87246b72009-01-28 12:27:39 -070034
Paul Walmsleyf2ab9972009-01-28 12:27:37 -070035void __iomem *omap2_sdrc_base;
36void __iomem *omap2_sms_base;
37
Kalle Jokiniemi8a917d22009-05-13 13:32:11 +030038struct omap2_sms_regs {
39 u32 sms_sysconfig;
40};
41
42static struct omap2_sms_regs sms_context;
43
Paul Walmsley98cfe5a2009-05-12 17:27:09 -060044/* SDRC_POWER register bits */
45#define SDRC_POWER_EXTCLKDIS_SHIFT 3
46#define SDRC_POWER_PWDENA_SHIFT 2
47#define SDRC_POWER_PAGEPOLICY_SHIFT 0
Paul Walmsley87246b72009-01-28 12:27:39 -070048
49/**
Kalle Jokiniemi8a917d22009-05-13 13:32:11 +030050 * omap2_sms_save_context - Save SMS registers
51 *
52 * Save SMS registers that need to be restored after off mode.
53 */
54void omap2_sms_save_context(void)
55{
56 sms_context.sms_sysconfig = sms_read_reg(SMS_SYSCONFIG);
57}
58
59/**
60 * omap2_sms_restore_context - Restore SMS registers
61 *
62 * Restore SMS registers that need to be Restored after off mode.
63 */
64void omap2_sms_restore_context(void)
65{
66 sms_write_reg(sms_context.sms_sysconfig, SMS_SYSCONFIG);
67}
68
69/**
Paul Walmsley87246b72009-01-28 12:27:39 -070070 * omap2_sdrc_get_params - return SDRC register values for a given clock rate
71 * @r: SDRC clock rate (in Hz)
Jean Pihet58cda882009-07-24 19:43:25 -060072 * @sdrc_cs0: chip select 0 ram timings **
73 * @sdrc_cs1: chip select 1 ram timings **
Paul Walmsley87246b72009-01-28 12:27:39 -070074 *
75 * Return pre-calculated values for the SDRC_ACTIM_CTRLA,
Jean Pihet58cda882009-07-24 19:43:25 -060076 * SDRC_ACTIM_CTRLB, SDRC_RFR_CTRL and SDRC_MR registers in sdrc_cs[01]
77 * structs,for a given SDRC clock rate 'r'.
78 * These parameters control various timing delays in the SDRAM controller
79 * that are expressed in terms of the number of SDRC clock cycles to
80 * wait; hence the clock rate dependency.
81 *
82 * Supports 2 different timing parameters for both chip selects.
83 *
84 * Note 1: the sdrc_init_params_cs[01] must be sorted rate descending.
85 * Note 2: If sdrc_init_params_cs_1 is not NULL it must be of same size
86 * as sdrc_init_params_cs_0.
87 *
88 * Fills in the struct omap_sdrc_params * for each chip select.
89 * Returns 0 upon success or -1 upon failure.
Paul Walmsley87246b72009-01-28 12:27:39 -070090 */
Jean Pihet58cda882009-07-24 19:43:25 -060091int omap2_sdrc_get_params(unsigned long r,
92 struct omap_sdrc_params **sdrc_cs0,
93 struct omap_sdrc_params **sdrc_cs1)
Paul Walmsley87246b72009-01-28 12:27:39 -070094{
Jean Pihet58cda882009-07-24 19:43:25 -060095 struct omap_sdrc_params *sp0, *sp1;
Paul Walmsley87246b72009-01-28 12:27:39 -070096
Jean Pihet58cda882009-07-24 19:43:25 -060097 if (!sdrc_init_params_cs0)
98 return -1;
Kevin Hilman8bd22942009-05-28 10:56:16 -070099
Jean Pihet58cda882009-07-24 19:43:25 -0600100 sp0 = sdrc_init_params_cs0;
101 sp1 = sdrc_init_params_cs1;
Paul Walmsley87246b72009-01-28 12:27:39 -0700102
Jean Pihet58cda882009-07-24 19:43:25 -0600103 while (sp0->rate && sp0->rate != r) {
104 sp0++;
105 if (sdrc_init_params_cs1)
106 sp1++;
107 }
Paul Walmsley87246b72009-01-28 12:27:39 -0700108
Jean Pihet58cda882009-07-24 19:43:25 -0600109 if (!sp0->rate)
110 return -1;
Paul Walmsley87246b72009-01-28 12:27:39 -0700111
Jean Pihet58cda882009-07-24 19:43:25 -0600112 *sdrc_cs0 = sp0;
113 *sdrc_cs1 = sp1;
114 return 0;
Paul Walmsley87246b72009-01-28 12:27:39 -0700115}
116
117
Paul Walmsleyf2ab9972009-01-28 12:27:37 -0700118void __init omap2_set_globals_sdrc(struct omap_globals *omap2_globals)
119{
Tony Lindgren4c3cf902011-10-04 18:17:41 -0700120 if (omap2_globals->sdrc)
121 omap2_sdrc_base = omap2_globals->sdrc;
122 if (omap2_globals->sms)
123 omap2_sms_base = omap2_globals->sms;
Paul Walmsleyf2ab9972009-01-28 12:27:37 -0700124}
125
Paul Walmsley98cfe5a2009-05-12 17:27:09 -0600126/**
127 * omap2_sdrc_init - initialize SMS, SDRC devices on boot
Jean Pihet58cda882009-07-24 19:43:25 -0600128 * @sdrc_cs[01]: pointers to a null-terminated list of struct omap_sdrc_params
129 * Support for 2 chip selects timings
Paul Walmsley98cfe5a2009-05-12 17:27:09 -0600130 *
131 * Turn on smart idle modes for SDRAM scheduler and controller.
132 * Program a known-good configuration for the SDRC to deal with buggy
133 * bootloaders.
134 */
Jean Pihet58cda882009-07-24 19:43:25 -0600135void __init omap2_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
136 struct omap_sdrc_params *sdrc_cs1)
Paul Walmsleyf2ab9972009-01-28 12:27:37 -0700137{
138 u32 l;
139
140 l = sms_read_reg(SMS_SYSCONFIG);
141 l &= ~(0x3 << 3);
142 l |= (0x2 << 3);
143 sms_write_reg(l, SMS_SYSCONFIG);
144
145 l = sdrc_read_reg(SDRC_SYSCONFIG);
146 l &= ~(0x3 << 3);
147 l |= (0x2 << 3);
148 sdrc_write_reg(l, SDRC_SYSCONFIG);
Paul Walmsley87246b72009-01-28 12:27:39 -0700149
Jean Pihet58cda882009-07-24 19:43:25 -0600150 sdrc_init_params_cs0 = sdrc_cs0;
151 sdrc_init_params_cs1 = sdrc_cs1;
Paul Walmsley98cfe5a2009-05-12 17:27:09 -0600152
153 /* XXX Enable SRFRONIDLEREQ here also? */
Paul Walmsley75f251e2009-07-24 19:44:01 -0600154 /*
155 * PWDENA should not be set due to 34xx erratum 1.150 - PWDENA
156 * can cause random memory corruption
157 */
Paul Walmsley98cfe5a2009-05-12 17:27:09 -0600158 l = (1 << SDRC_POWER_EXTCLKDIS_SHIFT) |
Paul Walmsley98cfe5a2009-05-12 17:27:09 -0600159 (1 << SDRC_POWER_PAGEPOLICY_SHIFT);
160 sdrc_write_reg(l, SDRC_POWER);
Kalle Jokiniemi8a917d22009-05-13 13:32:11 +0300161 omap2_sms_save_context();
Paul Walmsleyf2ab9972009-01-28 12:27:37 -0700162}
Tomi Valkeinenb90f8e72009-08-07 11:26:12 +0300163
164void omap2_sms_write_rot_control(u32 val, unsigned ctx)
165{
166 sms_write_reg(val, SMS_ROT_CONTROL(ctx));
167}
168
169void omap2_sms_write_rot_size(u32 val, unsigned ctx)
170{
171 sms_write_reg(val, SMS_ROT_SIZE(ctx));
172}
173
174void omap2_sms_write_rot_physical_ba(u32 val, unsigned ctx)
175{
176 sms_write_reg(val, SMS_ROT_PHYSICAL_BA(ctx));
177}
178