blob: 5619d1b486684cb62011e52fd6ea5a58577271aa [file] [log] [blame]
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001/*
2 * GPMC support functions
3 *
4 * Copyright (C) 2005-2006 Nokia Corporation
5 *
6 * Author: Juha Yrjola
7 *
Santosh Shilimkar44169072009-05-28 14:16:04 -07008 * Copyright (C) 2009 Texas Instruments
9 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
10 *
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070011 * 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 Walmsleyfd1dc872008-10-06 15:49:17 +030015#undef DEBUG
16
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +053017#include <linux/irq.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070018#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/err.h>
21#include <linux/clk.h>
Imre Deakf37e4582006-09-25 12:41:33 +030022#include <linux/ioport.h>
23#include <linux/spinlock.h>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
Paul Walmsleyfd1dc872008-10-06 15:49:17 +030025#include <linux/module.h>
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +053026#include <linux/interrupt.h>
Afzal Mohammedda496872012-09-23 17:28:25 -060027#include <linux/platform_device.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070028
Afzal Mohammedbc3668e2012-09-29 12:26:13 +053029#include <linux/platform_data/mtd-nand-omap2.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070030
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070031#include <asm/mach-types.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070032
Tony Lindgrendbc04162012-08-31 10:59:07 -070033#include "soc.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070034#include "common.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070035#include "omap_device.h"
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053036#include "gpmc.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070037
Afzal Mohammed4be48fd2012-09-23 17:28:24 -060038#define DEVICE_NAME "omap-gpmc"
39
Paul Walmsleyfd1dc872008-10-06 15:49:17 +030040/* GPMC register offsets */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070041#define GPMC_REVISION 0x00
42#define GPMC_SYSCONFIG 0x10
43#define GPMC_SYSSTATUS 0x14
44#define GPMC_IRQSTATUS 0x18
45#define GPMC_IRQENABLE 0x1c
46#define GPMC_TIMEOUT_CONTROL 0x40
47#define GPMC_ERR_ADDRESS 0x44
48#define GPMC_ERR_TYPE 0x48
49#define GPMC_CONFIG 0x50
50#define GPMC_STATUS 0x54
51#define GPMC_PREFETCH_CONFIG1 0x1e0
52#define GPMC_PREFETCH_CONFIG2 0x1e4
Thara Gopinath15e02a32008-04-28 16:55:01 +053053#define GPMC_PREFETCH_CONTROL 0x1ec
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070054#define GPMC_PREFETCH_STATUS 0x1f0
55#define GPMC_ECC_CONFIG 0x1f4
56#define GPMC_ECC_CONTROL 0x1f8
57#define GPMC_ECC_SIZE_CONFIG 0x1fc
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000058#define GPMC_ECC1_RESULT 0x200
Ivan Djelic8d602cf2012-04-26 14:17:49 +020059#define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053060#define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
61#define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
62#define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070063
Yegor Yefremov2c65e742012-05-09 08:32:49 -070064/* GPMC ECC control settings */
65#define GPMC_ECC_CTRL_ECCCLEAR 0x100
66#define GPMC_ECC_CTRL_ECCDISABLE 0x000
67#define GPMC_ECC_CTRL_ECCREG1 0x001
68#define GPMC_ECC_CTRL_ECCREG2 0x002
69#define GPMC_ECC_CTRL_ECCREG3 0x003
70#define GPMC_ECC_CTRL_ECCREG4 0x004
71#define GPMC_ECC_CTRL_ECCREG5 0x005
72#define GPMC_ECC_CTRL_ECCREG6 0x006
73#define GPMC_ECC_CTRL_ECCREG7 0x007
74#define GPMC_ECC_CTRL_ECCREG8 0x008
75#define GPMC_ECC_CTRL_ECCREG9 0x009
76
Afzal Mohammed559d94b2012-05-28 17:51:37 +053077#define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
78#define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
79#define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
80#define GPMC_CONFIG4_WEEXTRADELAY BIT(23)
81#define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6)
82#define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7)
83
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000084#define GPMC_CS0_OFFSET 0x60
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070085#define GPMC_CS_SIZE 0x30
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053086#define GPMC_BCH_SIZE 0x10
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070087
Imre Deakf37e4582006-09-25 12:41:33 +030088#define GPMC_MEM_START 0x00000000
89#define GPMC_MEM_END 0x3FFFFFFF
90#define BOOT_ROM_SPACE 0x100000 /* 1MB */
91
92#define GPMC_CHUNK_SHIFT 24 /* 16 MB */
93#define GPMC_SECTION_SHIFT 28 /* 128 MB */
94
vimal singh59e9c5a2009-07-13 16:26:24 +053095#define CS_NUM_SHIFT 24
96#define ENABLE_PREFETCH (0x1 << 7)
97#define DMA_MPU_MODE 2
98
Afzal Mohammedda496872012-09-23 17:28:25 -060099#define GPMC_REVISION_MAJOR(l) ((l >> 4) & 0xf)
100#define GPMC_REVISION_MINOR(l) (l & 0xf)
101
102#define GPMC_HAS_WR_ACCESS 0x1
103#define GPMC_HAS_WR_DATA_MUX_BUS 0x2
104
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700105/* XXX: Only NAND irq has been considered,currently these are the only ones used
106 */
107#define GPMC_NR_IRQ 2
108
109struct gpmc_client_irq {
110 unsigned irq;
111 u32 bitmask;
112};
113
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530114/* Structure to save gpmc cs context */
115struct gpmc_cs_config {
116 u32 config1;
117 u32 config2;
118 u32 config3;
119 u32 config4;
120 u32 config5;
121 u32 config6;
122 u32 config7;
123 int is_valid;
124};
125
126/*
127 * Structure to save/restore gpmc context
128 * to support core off on OMAP3
129 */
130struct omap3_gpmc_regs {
131 u32 sysconfig;
132 u32 irqenable;
133 u32 timeout_ctrl;
134 u32 config;
135 u32 prefetch_config1;
136 u32 prefetch_config2;
137 u32 prefetch_control;
138 struct gpmc_cs_config cs_context[GPMC_CS_NUM];
139};
140
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700141static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
142static struct irq_chip gpmc_irq_chip;
143static unsigned gpmc_irq_start;
144
Imre Deakf37e4582006-09-25 12:41:33 +0300145static struct resource gpmc_mem_root;
146static struct resource gpmc_cs_mem[GPMC_CS_NUM];
Thomas Gleixner87b247c2007-05-10 22:33:04 -0700147static DEFINE_SPINLOCK(gpmc_mem_lock);
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000148static unsigned int gpmc_cs_map; /* flag for cs which are initialized */
Afzal Mohammedda496872012-09-23 17:28:25 -0600149static struct device *gpmc_dev;
150static int gpmc_irq;
151static resource_size_t phys_base, mem_size;
152static unsigned gpmc_capability;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300153static void __iomem *gpmc_base;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700154
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300155static struct clk *gpmc_l3_clk;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700156
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530157static irqreturn_t gpmc_handle_irq(int irq, void *dev);
158
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700159static void gpmc_write_reg(int idx, u32 val)
160{
161 __raw_writel(val, gpmc_base + idx);
162}
163
164static u32 gpmc_read_reg(int idx)
165{
166 return __raw_readl(gpmc_base + idx);
167}
168
169void gpmc_cs_write_reg(int cs, int idx, u32 val)
170{
171 void __iomem *reg_addr;
172
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000173 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700174 __raw_writel(val, reg_addr);
175}
176
177u32 gpmc_cs_read_reg(int cs, int idx)
178{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300179 void __iomem *reg_addr;
180
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000181 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300182 return __raw_readl(reg_addr);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700183}
184
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300185/* TODO: Add support for gpmc_fck to clock framework and use it */
David Brownell1c22cc12006-12-06 17:13:55 -0800186unsigned long gpmc_get_fclk_period(void)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700187{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300188 unsigned long rate = clk_get_rate(gpmc_l3_clk);
189
190 if (rate == 0) {
191 printk(KERN_WARNING "gpmc_l3_clk not enabled\n");
192 return 0;
193 }
194
195 rate /= 1000;
196 rate = 1000000000 / rate; /* In picoseconds */
197
198 return rate;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700199}
200
201unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
202{
203 unsigned long tick_ps;
204
205 /* Calculate in picosecs to yield more exact results */
206 tick_ps = gpmc_get_fclk_period();
207
208 return (time_ns * 1000 + tick_ps - 1) / tick_ps;
209}
210
Adrian Huntera3551f52010-12-09 10:48:27 +0200211unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
212{
213 unsigned long tick_ps;
214
215 /* Calculate in picosecs to yield more exact results */
216 tick_ps = gpmc_get_fclk_period();
217
218 return (time_ps + tick_ps - 1) / tick_ps;
219}
220
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300221unsigned int gpmc_ticks_to_ns(unsigned int ticks)
222{
223 return ticks * gpmc_get_fclk_period() / 1000;
224}
225
Kai Svahn23300592007-01-26 12:29:40 -0800226unsigned int gpmc_round_ns_to_ticks(unsigned int time_ns)
227{
228 unsigned long ticks = gpmc_ns_to_ticks(time_ns);
229
230 return ticks * gpmc_get_fclk_period() / 1000;
231}
232
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530233static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value)
234{
235 u32 l;
236
237 l = gpmc_cs_read_reg(cs, reg);
238 if (value)
239 l |= mask;
240 else
241 l &= ~mask;
242 gpmc_cs_write_reg(cs, reg, l);
243}
244
245static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
246{
247 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1,
248 GPMC_CONFIG1_TIME_PARA_GRAN,
249 p->time_para_granularity);
250 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2,
251 GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay);
252 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3,
253 GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay);
254 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
255 GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay);
256 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
257 GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay);
258 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
259 GPMC_CONFIG6_CYCLE2CYCLESAMECSEN,
260 p->cycle2cyclesamecsen);
261 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
262 GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN,
263 p->cycle2cyclediffcsen);
264}
265
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700266#ifdef DEBUG
267static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
Juha Yrjola2aab6462006-06-26 16:16:21 -0700268 int time, const char *name)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700269#else
270static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
271 int time)
272#endif
273{
274 u32 l;
275 int ticks, mask, nr_bits;
276
277 if (time == 0)
278 ticks = 0;
279 else
280 ticks = gpmc_ns_to_ticks(time);
281 nr_bits = end_bit - st_bit + 1;
David Brownell1c22cc12006-12-06 17:13:55 -0800282 if (ticks >= 1 << nr_bits) {
283#ifdef DEBUG
284 printk(KERN_INFO "GPMC CS%d: %-10s* %3d ns, %3d ticks >= %d\n",
285 cs, name, time, ticks, 1 << nr_bits);
286#endif
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700287 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800288 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700289
290 mask = (1 << nr_bits) - 1;
291 l = gpmc_cs_read_reg(cs, reg);
292#ifdef DEBUG
David Brownell1c22cc12006-12-06 17:13:55 -0800293 printk(KERN_INFO
294 "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n",
Juha Yrjola2aab6462006-06-26 16:16:21 -0700295 cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000,
David Brownell1c22cc12006-12-06 17:13:55 -0800296 (l >> st_bit) & mask, time);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700297#endif
298 l &= ~(mask << st_bit);
299 l |= ticks << st_bit;
300 gpmc_cs_write_reg(cs, reg, l);
301
302 return 0;
303}
304
305#ifdef DEBUG
306#define GPMC_SET_ONE(reg, st, end, field) \
307 if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
308 t->field, #field) < 0) \
309 return -1
310#else
311#define GPMC_SET_ONE(reg, st, end, field) \
312 if (set_gpmc_timing_reg(cs, (reg), (st), (end), t->field) < 0) \
313 return -1
314#endif
315
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530316int gpmc_calc_divider(unsigned int sync_clk)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700317{
318 int div;
319 u32 l;
320
Adrian Huntera3551f52010-12-09 10:48:27 +0200321 l = sync_clk + (gpmc_get_fclk_period() - 1);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700322 div = l / gpmc_get_fclk_period();
323 if (div > 4)
324 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800325 if (div <= 0)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700326 div = 1;
327
328 return div;
329}
330
331int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
332{
333 int div;
334 u32 l;
335
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530336 div = gpmc_calc_divider(t->sync_clk);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700337 if (div < 0)
Paul Walmsleya032d332012-08-03 09:21:10 -0600338 return div;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700339
340 GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
341 GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
342 GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
343
344 GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on);
345 GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off);
346 GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
347
348 GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on);
349 GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off);
350 GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
351 GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
352
353 GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle);
354 GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle);
355 GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
356
357 GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
358
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530359 GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
360 GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
361
362 GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring);
363 GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation);
364
Afzal Mohammedda496872012-09-23 17:28:25 -0600365 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300366 GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
Afzal Mohammedda496872012-09-23 17:28:25 -0600367 if (gpmc_capability & GPMC_HAS_WR_ACCESS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300368 GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300369
David Brownell1c22cc12006-12-06 17:13:55 -0800370 /* caller is expected to have initialized CONFIG1 to cover
371 * at least sync vs async
372 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700373 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
David Brownell1c22cc12006-12-06 17:13:55 -0800374 if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) {
375#ifdef DEBUG
376 printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n",
377 cs, (div * gpmc_get_fclk_period()) / 1000, div);
378#endif
379 l &= ~0x03;
380 l |= (div - 1);
381 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
382 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700383
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530384 gpmc_cs_bool_timings(cs, &t->bool_timings);
385
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700386 return 0;
387}
388
Imre Deakf37e4582006-09-25 12:41:33 +0300389static void gpmc_cs_enable_mem(int cs, u32 base, u32 size)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700390{
Imre Deakf37e4582006-09-25 12:41:33 +0300391 u32 l;
392 u32 mask;
393
394 mask = (1 << GPMC_SECTION_SHIFT) - size;
395 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
396 l &= ~0x3f;
397 l = (base >> GPMC_CHUNK_SHIFT) & 0x3f;
398 l &= ~(0x0f << 8);
399 l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8;
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530400 l |= GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300401 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
402}
403
404static void gpmc_cs_disable_mem(int cs)
405{
406 u32 l;
407
408 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530409 l &= ~GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300410 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
411}
412
413static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size)
414{
415 u32 l;
416 u32 mask;
417
418 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
419 *base = (l & 0x3f) << GPMC_CHUNK_SHIFT;
420 mask = (l >> 8) & 0x0f;
421 *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT);
422}
423
424static int gpmc_cs_mem_enabled(int cs)
425{
426 u32 l;
427
428 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530429 return l & GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300430}
431
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800432int gpmc_cs_set_reserved(int cs, int reserved)
Imre Deakf37e4582006-09-25 12:41:33 +0300433{
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800434 if (cs > GPMC_CS_NUM)
435 return -ENODEV;
436
Imre Deakf37e4582006-09-25 12:41:33 +0300437 gpmc_cs_map &= ~(1 << cs);
438 gpmc_cs_map |= (reserved ? 1 : 0) << cs;
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800439
440 return 0;
Imre Deakf37e4582006-09-25 12:41:33 +0300441}
442
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800443int gpmc_cs_reserved(int cs)
Imre Deakf37e4582006-09-25 12:41:33 +0300444{
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800445 if (cs > GPMC_CS_NUM)
446 return -ENODEV;
447
Imre Deakf37e4582006-09-25 12:41:33 +0300448 return gpmc_cs_map & (1 << cs);
449}
450
451static unsigned long gpmc_mem_align(unsigned long size)
452{
453 int order;
454
455 size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1);
456 order = GPMC_CHUNK_SHIFT - 1;
457 do {
458 size >>= 1;
459 order++;
460 } while (size);
461 size = 1 << order;
462 return size;
463}
464
465static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
466{
467 struct resource *res = &gpmc_cs_mem[cs];
468 int r;
469
470 size = gpmc_mem_align(size);
471 spin_lock(&gpmc_mem_lock);
472 res->start = base;
473 res->end = base + size - 1;
474 r = request_resource(&gpmc_mem_root, res);
475 spin_unlock(&gpmc_mem_lock);
476
477 return r;
478}
479
Afzal Mohammedda496872012-09-23 17:28:25 -0600480static int gpmc_cs_delete_mem(int cs)
481{
482 struct resource *res = &gpmc_cs_mem[cs];
483 int r;
484
485 spin_lock(&gpmc_mem_lock);
486 r = release_resource(&gpmc_cs_mem[cs]);
487 res->start = 0;
488 res->end = 0;
489 spin_unlock(&gpmc_mem_lock);
490
491 return r;
492}
493
Imre Deakf37e4582006-09-25 12:41:33 +0300494int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
495{
496 struct resource *res = &gpmc_cs_mem[cs];
497 int r = -1;
498
499 if (cs > GPMC_CS_NUM)
500 return -ENODEV;
501
502 size = gpmc_mem_align(size);
503 if (size > (1 << GPMC_SECTION_SHIFT))
504 return -ENOMEM;
505
506 spin_lock(&gpmc_mem_lock);
507 if (gpmc_cs_reserved(cs)) {
508 r = -EBUSY;
509 goto out;
510 }
511 if (gpmc_cs_mem_enabled(cs))
512 r = adjust_resource(res, res->start & ~(size - 1), size);
513 if (r < 0)
514 r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
515 size, NULL, NULL);
516 if (r < 0)
517 goto out;
518
Tobias Klauser6d135242009-11-10 18:55:19 -0800519 gpmc_cs_enable_mem(cs, res->start, resource_size(res));
Imre Deakf37e4582006-09-25 12:41:33 +0300520 *base = res->start;
521 gpmc_cs_set_reserved(cs, 1);
522out:
523 spin_unlock(&gpmc_mem_lock);
524 return r;
525}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300526EXPORT_SYMBOL(gpmc_cs_request);
Imre Deakf37e4582006-09-25 12:41:33 +0300527
528void gpmc_cs_free(int cs)
529{
530 spin_lock(&gpmc_mem_lock);
Roel Kluine7fdc602009-11-17 14:39:06 -0800531 if (cs >= GPMC_CS_NUM || cs < 0 || !gpmc_cs_reserved(cs)) {
Imre Deakf37e4582006-09-25 12:41:33 +0300532 printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
533 BUG();
534 spin_unlock(&gpmc_mem_lock);
535 return;
536 }
537 gpmc_cs_disable_mem(cs);
538 release_resource(&gpmc_cs_mem[cs]);
539 gpmc_cs_set_reserved(cs, 0);
540 spin_unlock(&gpmc_mem_lock);
541}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300542EXPORT_SYMBOL(gpmc_cs_free);
Imre Deakf37e4582006-09-25 12:41:33 +0300543
vimal singh59e9c5a2009-07-13 16:26:24 +0530544/**
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000545 * gpmc_cs_configure - write request to configure gpmc
546 * @cs: chip select number
547 * @cmd: command type
548 * @wval: value to write
549 * @return status of the operation
550 */
551int gpmc_cs_configure(int cs, int cmd, int wval)
552{
553 int err = 0;
554 u32 regval = 0;
555
556 switch (cmd) {
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530557 case GPMC_ENABLE_IRQ:
558 gpmc_write_reg(GPMC_IRQENABLE, wval);
559 break;
560
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000561 case GPMC_SET_IRQ_STATUS:
562 gpmc_write_reg(GPMC_IRQSTATUS, wval);
563 break;
564
565 case GPMC_CONFIG_WP:
566 regval = gpmc_read_reg(GPMC_CONFIG);
567 if (wval)
568 regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
569 else
570 regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
571 gpmc_write_reg(GPMC_CONFIG, regval);
572 break;
573
574 case GPMC_CONFIG_RDY_BSY:
575 regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
576 if (wval)
577 regval |= WR_RD_PIN_MONITORING;
578 else
579 regval &= ~WR_RD_PIN_MONITORING;
580 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
581 break;
582
583 case GPMC_CONFIG_DEV_SIZE:
584 regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
Yegor Yefremov8ef5d842012-01-23 08:32:23 +0100585
586 /* clear 2 target bits */
587 regval &= ~GPMC_CONFIG1_DEVICESIZE(3);
588
589 /* set the proper value */
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000590 regval |= GPMC_CONFIG1_DEVICESIZE(wval);
Yegor Yefremov8ef5d842012-01-23 08:32:23 +0100591
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000592 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
593 break;
594
595 case GPMC_CONFIG_DEV_TYPE:
596 regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
597 regval |= GPMC_CONFIG1_DEVICETYPE(wval);
598 if (wval == GPMC_DEVICETYPE_NOR)
599 regval |= GPMC_CONFIG1_MUXADDDATA;
600 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
601 break;
602
603 default:
604 printk(KERN_ERR "gpmc_configure_cs: Not supported\n");
605 err = -EINVAL;
606 }
607
608 return err;
609}
610EXPORT_SYMBOL(gpmc_cs_configure);
611
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700612void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
613{
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530614 int i;
615
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700616 reg->gpmc_status = gpmc_base + GPMC_STATUS;
617 reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
618 GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
619 reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
620 GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
621 reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
622 GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
623 reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
624 reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
625 reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
626 reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
627 reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
628 reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
629 reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
630 reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530631
632 for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
633 reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
634 GPMC_BCH_SIZE * i;
635 reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
636 GPMC_BCH_SIZE * i;
637 reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
638 GPMC_BCH_SIZE * i;
639 reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
640 GPMC_BCH_SIZE * i;
641 }
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700642}
643
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700644int gpmc_get_client_irq(unsigned irq_config)
645{
646 int i;
647
648 if (hweight32(irq_config) > 1)
649 return 0;
650
651 for (i = 0; i < GPMC_NR_IRQ; i++)
652 if (gpmc_client_irq[i].bitmask & irq_config)
653 return gpmc_client_irq[i].irq;
654
655 return 0;
656}
657
658static int gpmc_irq_endis(unsigned irq, bool endis)
659{
660 int i;
661 u32 regval;
662
663 for (i = 0; i < GPMC_NR_IRQ; i++)
664 if (irq == gpmc_client_irq[i].irq) {
665 regval = gpmc_read_reg(GPMC_IRQENABLE);
666 if (endis)
667 regval |= gpmc_client_irq[i].bitmask;
668 else
669 regval &= ~gpmc_client_irq[i].bitmask;
670 gpmc_write_reg(GPMC_IRQENABLE, regval);
671 break;
672 }
673
674 return 0;
675}
676
677static void gpmc_irq_disable(struct irq_data *p)
678{
679 gpmc_irq_endis(p->irq, false);
680}
681
682static void gpmc_irq_enable(struct irq_data *p)
683{
684 gpmc_irq_endis(p->irq, true);
685}
686
687static void gpmc_irq_noop(struct irq_data *data) { }
688
689static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
690
Afzal Mohammedda496872012-09-23 17:28:25 -0600691static int gpmc_setup_irq(void)
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700692{
693 int i;
694 u32 regval;
695
696 if (!gpmc_irq)
697 return -EINVAL;
698
699 gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
700 if (IS_ERR_VALUE(gpmc_irq_start)) {
701 pr_err("irq_alloc_descs failed\n");
702 return gpmc_irq_start;
703 }
704
705 gpmc_irq_chip.name = "gpmc";
706 gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
707 gpmc_irq_chip.irq_enable = gpmc_irq_enable;
708 gpmc_irq_chip.irq_disable = gpmc_irq_disable;
709 gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
710 gpmc_irq_chip.irq_ack = gpmc_irq_noop;
711 gpmc_irq_chip.irq_mask = gpmc_irq_noop;
712 gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
713
714 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
715 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
716
717 for (i = 0; i < GPMC_NR_IRQ; i++) {
718 gpmc_client_irq[i].irq = gpmc_irq_start + i;
719 irq_set_chip_and_handler(gpmc_client_irq[i].irq,
720 &gpmc_irq_chip, handle_simple_irq);
721 set_irq_flags(gpmc_client_irq[i].irq,
722 IRQF_VALID | IRQF_NOAUTOEN);
723 }
724
725 /* Disable interrupts */
726 gpmc_write_reg(GPMC_IRQENABLE, 0);
727
728 /* clear interrupts */
729 regval = gpmc_read_reg(GPMC_IRQSTATUS);
730 gpmc_write_reg(GPMC_IRQSTATUS, regval);
731
732 return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
733}
734
Afzal Mohammed61687c62012-10-04 14:01:57 +0530735static __devexit int gpmc_free_irq(void)
Afzal Mohammedda496872012-09-23 17:28:25 -0600736{
737 int i;
738
739 if (gpmc_irq)
740 free_irq(gpmc_irq, NULL);
741
742 for (i = 0; i < GPMC_NR_IRQ; i++) {
743 irq_set_handler(gpmc_client_irq[i].irq, NULL);
744 irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
745 irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
746 }
747
748 irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
749
750 return 0;
751}
752
753static void __devexit gpmc_mem_exit(void)
754{
755 int cs;
756
757 for (cs = 0; cs < GPMC_CS_NUM; cs++) {
758 if (!gpmc_cs_mem_enabled(cs))
759 continue;
760 gpmc_cs_delete_mem(cs);
761 }
762
763}
764
Jon Hunter81190242012-10-17 09:41:25 -0500765static int __devinit gpmc_mem_init(void)
Imre Deakf37e4582006-09-25 12:41:33 +0300766{
Jon Hunter81190242012-10-17 09:41:25 -0500767 int cs, rc;
Imre Deakf37e4582006-09-25 12:41:33 +0300768 unsigned long boot_rom_space = 0;
769
Kyungmin Park7f245162006-12-29 16:48:51 -0800770 /* never allocate the first page, to facilitate bug detection;
771 * even if we didn't boot from ROM.
772 */
773 boot_rom_space = BOOT_ROM_SPACE;
774 /* In apollon the CS0 is mapped as 0x0000 0000 */
775 if (machine_is_omap_apollon())
776 boot_rom_space = 0;
Imre Deakf37e4582006-09-25 12:41:33 +0300777 gpmc_mem_root.start = GPMC_MEM_START + boot_rom_space;
778 gpmc_mem_root.end = GPMC_MEM_END;
779
780 /* Reserve all regions that has been set up by bootloader */
781 for (cs = 0; cs < GPMC_CS_NUM; cs++) {
782 u32 base, size;
783
784 if (!gpmc_cs_mem_enabled(cs))
785 continue;
786 gpmc_cs_get_memconf(cs, &base, &size);
Jon Hunter81190242012-10-17 09:41:25 -0500787 rc = gpmc_cs_insert_mem(cs, base, size);
788 if (IS_ERR_VALUE(rc)) {
789 while (--cs >= 0)
790 if (gpmc_cs_mem_enabled(cs))
791 gpmc_cs_delete_mem(cs);
792 return rc;
793 }
Imre Deakf37e4582006-09-25 12:41:33 +0300794 }
Jon Hunter81190242012-10-17 09:41:25 -0500795
796 return 0;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700797}
798
Afzal Mohammedda496872012-09-23 17:28:25 -0600799static __devinit int gpmc_probe(struct platform_device *pdev)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700800{
Jon Hunter81190242012-10-17 09:41:25 -0500801 int rc;
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700802 u32 l;
Afzal Mohammedda496872012-09-23 17:28:25 -0600803 struct resource *res;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700804
Afzal Mohammedda496872012-09-23 17:28:25 -0600805 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
806 if (res == NULL)
807 return -ENOENT;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300808
Afzal Mohammedda496872012-09-23 17:28:25 -0600809 phys_base = res->start;
810 mem_size = resource_size(res);
Kevin Hilman8d084362010-01-29 14:20:06 -0800811
Afzal Mohammedda496872012-09-23 17:28:25 -0600812 gpmc_base = devm_request_and_ioremap(&pdev->dev, res);
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300813 if (!gpmc_base) {
Afzal Mohammedda496872012-09-23 17:28:25 -0600814 dev_err(&pdev->dev, "error: request memory / ioremap\n");
815 return -EADDRNOTAVAIL;
816 }
817
818 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
819 if (res == NULL)
820 dev_warn(&pdev->dev, "Failed to get resource: irq\n");
821 else
822 gpmc_irq = res->start;
823
824 gpmc_l3_clk = clk_get(&pdev->dev, "fck");
825 if (IS_ERR(gpmc_l3_clk)) {
826 dev_err(&pdev->dev, "error: clk_get\n");
827 gpmc_irq = 0;
828 return PTR_ERR(gpmc_l3_clk);
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300829 }
830
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600831 clk_prepare_enable(gpmc_l3_clk);
Olof Johansson1daa8c12010-01-20 22:39:29 +0000832
Afzal Mohammedda496872012-09-23 17:28:25 -0600833 gpmc_dev = &pdev->dev;
834
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700835 l = gpmc_read_reg(GPMC_REVISION);
Afzal Mohammedda496872012-09-23 17:28:25 -0600836 if (GPMC_REVISION_MAJOR(l) > 0x4)
837 gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
838 dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
839 GPMC_REVISION_MINOR(l));
840
Jon Hunter81190242012-10-17 09:41:25 -0500841 rc = gpmc_mem_init();
842 if (IS_ERR_VALUE(rc)) {
843 clk_disable_unprepare(gpmc_l3_clk);
844 clk_put(gpmc_l3_clk);
845 dev_err(gpmc_dev, "failed to reserve memory\n");
846 return rc;
847 }
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530848
Afzal Mohammedda496872012-09-23 17:28:25 -0600849 if (IS_ERR_VALUE(gpmc_setup_irq()))
850 dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
851
852 return 0;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530853}
Afzal Mohammedda496872012-09-23 17:28:25 -0600854
Afzal Mohammed61687c62012-10-04 14:01:57 +0530855static __devexit int gpmc_remove(struct platform_device *pdev)
Afzal Mohammedda496872012-09-23 17:28:25 -0600856{
857 gpmc_free_irq();
858 gpmc_mem_exit();
859 gpmc_dev = NULL;
860 return 0;
861}
862
863static struct platform_driver gpmc_driver = {
864 .probe = gpmc_probe,
865 .remove = __devexit_p(gpmc_remove),
866 .driver = {
867 .name = DEVICE_NAME,
868 .owner = THIS_MODULE,
869 },
870};
871
872static __init int gpmc_init(void)
873{
874 return platform_driver_register(&gpmc_driver);
875}
876
877static __exit void gpmc_exit(void)
878{
879 platform_driver_unregister(&gpmc_driver);
880
881}
882
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530883postcore_initcall(gpmc_init);
Afzal Mohammedda496872012-09-23 17:28:25 -0600884module_exit(gpmc_exit);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530885
Afzal Mohammed4be48fd2012-09-23 17:28:24 -0600886static int __init omap_gpmc_init(void)
887{
888 struct omap_hwmod *oh;
889 struct platform_device *pdev;
890 char *oh_name = "gpmc";
891
892 oh = omap_hwmod_lookup(oh_name);
893 if (!oh) {
894 pr_err("Could not look up %s\n", oh_name);
895 return -ENODEV;
896 }
897
898 pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0, NULL, 0, 0);
899 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
900
901 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
902}
903postcore_initcall(omap_gpmc_init);
904
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530905static irqreturn_t gpmc_handle_irq(int irq, void *dev)
906{
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700907 int i;
908 u32 regval;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530909
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700910 regval = gpmc_read_reg(GPMC_IRQSTATUS);
911
912 if (!regval)
913 return IRQ_NONE;
914
915 for (i = 0; i < GPMC_NR_IRQ; i++)
916 if (regval & gpmc_client_irq[i].bitmask)
917 generic_handle_irq(gpmc_client_irq[i].irq);
918
919 gpmc_write_reg(GPMC_IRQSTATUS, regval);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530920
921 return IRQ_HANDLED;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700922}
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530923
924#ifdef CONFIG_ARCH_OMAP3
925static struct omap3_gpmc_regs gpmc_context;
926
Felipe Balbib2fa3b72010-02-15 10:03:33 -0800927void omap3_gpmc_save_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530928{
929 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -0800930
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530931 gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
932 gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
933 gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
934 gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
935 gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
936 gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
937 gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
938 for (i = 0; i < GPMC_CS_NUM; i++) {
939 gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
940 if (gpmc_context.cs_context[i].is_valid) {
941 gpmc_context.cs_context[i].config1 =
942 gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
943 gpmc_context.cs_context[i].config2 =
944 gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
945 gpmc_context.cs_context[i].config3 =
946 gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
947 gpmc_context.cs_context[i].config4 =
948 gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
949 gpmc_context.cs_context[i].config5 =
950 gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
951 gpmc_context.cs_context[i].config6 =
952 gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
953 gpmc_context.cs_context[i].config7 =
954 gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
955 }
956 }
957}
958
Felipe Balbib2fa3b72010-02-15 10:03:33 -0800959void omap3_gpmc_restore_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530960{
961 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -0800962
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530963 gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
964 gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
965 gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
966 gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
967 gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
968 gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
969 gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
970 for (i = 0; i < GPMC_CS_NUM; i++) {
971 if (gpmc_context.cs_context[i].is_valid) {
972 gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
973 gpmc_context.cs_context[i].config1);
974 gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
975 gpmc_context.cs_context[i].config2);
976 gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
977 gpmc_context.cs_context[i].config3);
978 gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
979 gpmc_context.cs_context[i].config4);
980 gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
981 gpmc_context.cs_context[i].config5);
982 gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
983 gpmc_context.cs_context[i].config6);
984 gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
985 gpmc_context.cs_context[i].config7);
986 }
987 }
988}
989#endif /* CONFIG_ARCH_OMAP3 */