blob: 21b963604430f190f1c5314bd02d4e79cf95d225 [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>
Daniel Mackbc6b1e72012-12-14 11:36:44 +010028#include <linux/of.h>
Jon Huntercdd69282013-02-08 16:46:13 -060029#include <linux/of_address.h>
Daniel Mackbc6b1e72012-12-14 11:36:44 +010030#include <linux/of_mtd.h>
31#include <linux/of_device.h>
32#include <linux/mtd/nand.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070033
Afzal Mohammedbc3668e2012-09-29 12:26:13 +053034#include <linux/platform_data/mtd-nand-omap2.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070035
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070036#include <asm/mach-types.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070037
Tony Lindgrendbc04162012-08-31 10:59:07 -070038#include "soc.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070039#include "common.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070040#include "omap_device.h"
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053041#include "gpmc.h"
Daniel Mackbc6b1e72012-12-14 11:36:44 +010042#include "gpmc-nand.h"
Ezequiel Garcia75d36252013-01-25 09:23:11 -030043#include "gpmc-onenand.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070044
Afzal Mohammed4be48fd2012-09-23 17:28:24 -060045#define DEVICE_NAME "omap-gpmc"
46
Paul Walmsleyfd1dc872008-10-06 15:49:17 +030047/* GPMC register offsets */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070048#define GPMC_REVISION 0x00
49#define GPMC_SYSCONFIG 0x10
50#define GPMC_SYSSTATUS 0x14
51#define GPMC_IRQSTATUS 0x18
52#define GPMC_IRQENABLE 0x1c
53#define GPMC_TIMEOUT_CONTROL 0x40
54#define GPMC_ERR_ADDRESS 0x44
55#define GPMC_ERR_TYPE 0x48
56#define GPMC_CONFIG 0x50
57#define GPMC_STATUS 0x54
58#define GPMC_PREFETCH_CONFIG1 0x1e0
59#define GPMC_PREFETCH_CONFIG2 0x1e4
Thara Gopinath15e02a32008-04-28 16:55:01 +053060#define GPMC_PREFETCH_CONTROL 0x1ec
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070061#define GPMC_PREFETCH_STATUS 0x1f0
62#define GPMC_ECC_CONFIG 0x1f4
63#define GPMC_ECC_CONTROL 0x1f8
64#define GPMC_ECC_SIZE_CONFIG 0x1fc
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000065#define GPMC_ECC1_RESULT 0x200
Ivan Djelic8d602cf2012-04-26 14:17:49 +020066#define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053067#define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
68#define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
69#define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070070
Yegor Yefremov2c65e742012-05-09 08:32:49 -070071/* GPMC ECC control settings */
72#define GPMC_ECC_CTRL_ECCCLEAR 0x100
73#define GPMC_ECC_CTRL_ECCDISABLE 0x000
74#define GPMC_ECC_CTRL_ECCREG1 0x001
75#define GPMC_ECC_CTRL_ECCREG2 0x002
76#define GPMC_ECC_CTRL_ECCREG3 0x003
77#define GPMC_ECC_CTRL_ECCREG4 0x004
78#define GPMC_ECC_CTRL_ECCREG5 0x005
79#define GPMC_ECC_CTRL_ECCREG6 0x006
80#define GPMC_ECC_CTRL_ECCREG7 0x007
81#define GPMC_ECC_CTRL_ECCREG8 0x008
82#define GPMC_ECC_CTRL_ECCREG9 0x009
83
Afzal Mohammed559d94b2012-05-28 17:51:37 +053084#define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
85#define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
86#define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
87#define GPMC_CONFIG4_WEEXTRADELAY BIT(23)
88#define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6)
89#define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7)
90
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000091#define GPMC_CS0_OFFSET 0x60
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070092#define GPMC_CS_SIZE 0x30
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053093#define GPMC_BCH_SIZE 0x10
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070094
Imre Deakf37e4582006-09-25 12:41:33 +030095#define GPMC_MEM_END 0x3FFFFFFF
Imre Deakf37e4582006-09-25 12:41:33 +030096
97#define GPMC_CHUNK_SHIFT 24 /* 16 MB */
98#define GPMC_SECTION_SHIFT 28 /* 128 MB */
99
vimal singh59e9c5a2009-07-13 16:26:24 +0530100#define CS_NUM_SHIFT 24
101#define ENABLE_PREFETCH (0x1 << 7)
102#define DMA_MPU_MODE 2
103
Afzal Mohammedda496872012-09-23 17:28:25 -0600104#define GPMC_REVISION_MAJOR(l) ((l >> 4) & 0xf)
105#define GPMC_REVISION_MINOR(l) (l & 0xf)
106
107#define GPMC_HAS_WR_ACCESS 0x1
108#define GPMC_HAS_WR_DATA_MUX_BUS 0x2
Jon Hunteraa8d4762013-02-21 15:25:23 -0600109#define GPMC_HAS_MUX_AAD 0x4
Afzal Mohammedda496872012-09-23 17:28:25 -0600110
Jon Hunter9f833152013-02-20 15:53:38 -0600111#define GPMC_NR_WAITPINS 4
112
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700113/* XXX: Only NAND irq has been considered,currently these are the only ones used
114 */
115#define GPMC_NR_IRQ 2
116
117struct gpmc_client_irq {
118 unsigned irq;
119 u32 bitmask;
120};
121
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530122/* Structure to save gpmc cs context */
123struct gpmc_cs_config {
124 u32 config1;
125 u32 config2;
126 u32 config3;
127 u32 config4;
128 u32 config5;
129 u32 config6;
130 u32 config7;
131 int is_valid;
132};
133
134/*
135 * Structure to save/restore gpmc context
136 * to support core off on OMAP3
137 */
138struct omap3_gpmc_regs {
139 u32 sysconfig;
140 u32 irqenable;
141 u32 timeout_ctrl;
142 u32 config;
143 u32 prefetch_config1;
144 u32 prefetch_config2;
145 u32 prefetch_control;
146 struct gpmc_cs_config cs_context[GPMC_CS_NUM];
147};
148
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700149static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
150static struct irq_chip gpmc_irq_chip;
151static unsigned gpmc_irq_start;
152
Imre Deakf37e4582006-09-25 12:41:33 +0300153static struct resource gpmc_mem_root;
154static struct resource gpmc_cs_mem[GPMC_CS_NUM];
Thomas Gleixner87b247c2007-05-10 22:33:04 -0700155static DEFINE_SPINLOCK(gpmc_mem_lock);
Jon Hunter6797b4f2013-02-01 10:38:45 -0600156/* Define chip-selects as reserved by default until probe completes */
157static unsigned int gpmc_cs_map = ((1 << GPMC_CS_NUM) - 1);
Gupta Pekonf34f3712013-05-31 17:31:30 +0530158static unsigned int gpmc_cs_num = GPMC_CS_NUM;
Jon Hunter9f833152013-02-20 15:53:38 -0600159static unsigned int gpmc_nr_waitpins;
Afzal Mohammedda496872012-09-23 17:28:25 -0600160static struct device *gpmc_dev;
161static int gpmc_irq;
162static resource_size_t phys_base, mem_size;
163static unsigned gpmc_capability;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300164static void __iomem *gpmc_base;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700165
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300166static struct clk *gpmc_l3_clk;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700167
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530168static irqreturn_t gpmc_handle_irq(int irq, void *dev);
169
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700170static void gpmc_write_reg(int idx, u32 val)
171{
172 __raw_writel(val, gpmc_base + idx);
173}
174
175static u32 gpmc_read_reg(int idx)
176{
177 return __raw_readl(gpmc_base + idx);
178}
179
180void gpmc_cs_write_reg(int cs, int idx, u32 val)
181{
182 void __iomem *reg_addr;
183
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000184 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700185 __raw_writel(val, reg_addr);
186}
187
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300188static u32 gpmc_cs_read_reg(int cs, int idx)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700189{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300190 void __iomem *reg_addr;
191
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000192 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300193 return __raw_readl(reg_addr);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700194}
195
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300196/* TODO: Add support for gpmc_fck to clock framework and use it */
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300197static unsigned long gpmc_get_fclk_period(void)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700198{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300199 unsigned long rate = clk_get_rate(gpmc_l3_clk);
200
201 if (rate == 0) {
202 printk(KERN_WARNING "gpmc_l3_clk not enabled\n");
203 return 0;
204 }
205
206 rate /= 1000;
207 rate = 1000000000 / rate; /* In picoseconds */
208
209 return rate;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700210}
211
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300212static unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700213{
214 unsigned long tick_ps;
215
216 /* Calculate in picosecs to yield more exact results */
217 tick_ps = gpmc_get_fclk_period();
218
219 return (time_ns * 1000 + tick_ps - 1) / tick_ps;
220}
221
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300222static unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
Adrian Huntera3551f52010-12-09 10:48:27 +0200223{
224 unsigned long tick_ps;
225
226 /* Calculate in picosecs to yield more exact results */
227 tick_ps = gpmc_get_fclk_period();
228
229 return (time_ps + tick_ps - 1) / tick_ps;
230}
231
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300232unsigned int gpmc_ticks_to_ns(unsigned int ticks)
233{
234 return ticks * gpmc_get_fclk_period() / 1000;
235}
236
Afzal Mohammed246da262012-08-02 20:02:10 +0530237static unsigned int gpmc_ticks_to_ps(unsigned int ticks)
238{
239 return ticks * gpmc_get_fclk_period();
240}
241
242static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps)
243{
244 unsigned long ticks = gpmc_ps_to_ticks(time_ps);
245
246 return ticks * gpmc_get_fclk_period();
247}
248
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530249static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value)
250{
251 u32 l;
252
253 l = gpmc_cs_read_reg(cs, reg);
254 if (value)
255 l |= mask;
256 else
257 l &= ~mask;
258 gpmc_cs_write_reg(cs, reg, l);
259}
260
261static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
262{
263 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1,
264 GPMC_CONFIG1_TIME_PARA_GRAN,
265 p->time_para_granularity);
266 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2,
267 GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay);
268 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3,
269 GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay);
270 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
271 GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay);
272 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
273 GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay);
274 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
275 GPMC_CONFIG6_CYCLE2CYCLESAMECSEN,
276 p->cycle2cyclesamecsen);
277 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
278 GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN,
279 p->cycle2cyclediffcsen);
280}
281
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700282#ifdef DEBUG
283static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
Juha Yrjola2aab6462006-06-26 16:16:21 -0700284 int time, const char *name)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700285#else
286static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
287 int time)
288#endif
289{
290 u32 l;
291 int ticks, mask, nr_bits;
292
293 if (time == 0)
294 ticks = 0;
295 else
296 ticks = gpmc_ns_to_ticks(time);
297 nr_bits = end_bit - st_bit + 1;
David Brownell1c22cc12006-12-06 17:13:55 -0800298 if (ticks >= 1 << nr_bits) {
299#ifdef DEBUG
300 printk(KERN_INFO "GPMC CS%d: %-10s* %3d ns, %3d ticks >= %d\n",
301 cs, name, time, ticks, 1 << nr_bits);
302#endif
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700303 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800304 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700305
306 mask = (1 << nr_bits) - 1;
307 l = gpmc_cs_read_reg(cs, reg);
308#ifdef DEBUG
David Brownell1c22cc12006-12-06 17:13:55 -0800309 printk(KERN_INFO
310 "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n",
Juha Yrjola2aab6462006-06-26 16:16:21 -0700311 cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000,
David Brownell1c22cc12006-12-06 17:13:55 -0800312 (l >> st_bit) & mask, time);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700313#endif
314 l &= ~(mask << st_bit);
315 l |= ticks << st_bit;
316 gpmc_cs_write_reg(cs, reg, l);
317
318 return 0;
319}
320
321#ifdef DEBUG
322#define GPMC_SET_ONE(reg, st, end, field) \
323 if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
324 t->field, #field) < 0) \
325 return -1
326#else
327#define GPMC_SET_ONE(reg, st, end, field) \
328 if (set_gpmc_timing_reg(cs, (reg), (st), (end), t->field) < 0) \
329 return -1
330#endif
331
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530332int gpmc_calc_divider(unsigned int sync_clk)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700333{
334 int div;
335 u32 l;
336
Adrian Huntera3551f52010-12-09 10:48:27 +0200337 l = sync_clk + (gpmc_get_fclk_period() - 1);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700338 div = l / gpmc_get_fclk_period();
339 if (div > 4)
340 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800341 if (div <= 0)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700342 div = 1;
343
344 return div;
345}
346
347int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
348{
349 int div;
350 u32 l;
351
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530352 div = gpmc_calc_divider(t->sync_clk);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700353 if (div < 0)
Paul Walmsleya032d332012-08-03 09:21:10 -0600354 return div;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700355
356 GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
357 GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
358 GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
359
360 GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on);
361 GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off);
362 GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
363
364 GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on);
365 GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off);
366 GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
367 GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
368
369 GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle);
370 GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle);
371 GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
372
373 GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
374
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530375 GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
376 GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
377
378 GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring);
379 GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation);
380
Afzal Mohammedda496872012-09-23 17:28:25 -0600381 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300382 GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
Afzal Mohammedda496872012-09-23 17:28:25 -0600383 if (gpmc_capability & GPMC_HAS_WR_ACCESS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300384 GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300385
David Brownell1c22cc12006-12-06 17:13:55 -0800386 /* caller is expected to have initialized CONFIG1 to cover
387 * at least sync vs async
388 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700389 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
David Brownell1c22cc12006-12-06 17:13:55 -0800390 if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) {
391#ifdef DEBUG
392 printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n",
393 cs, (div * gpmc_get_fclk_period()) / 1000, div);
394#endif
395 l &= ~0x03;
396 l |= (div - 1);
397 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
398 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700399
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530400 gpmc_cs_bool_timings(cs, &t->bool_timings);
401
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700402 return 0;
403}
404
Jon Hunterc71f8e92013-03-06 12:00:10 -0600405static int gpmc_cs_enable_mem(int cs, u32 base, u32 size)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700406{
Imre Deakf37e4582006-09-25 12:41:33 +0300407 u32 l;
408 u32 mask;
409
Jon Hunterc71f8e92013-03-06 12:00:10 -0600410 /*
411 * Ensure that base address is aligned on a
412 * boundary equal to or greater than size.
413 */
414 if (base & (size - 1))
415 return -EINVAL;
416
Imre Deakf37e4582006-09-25 12:41:33 +0300417 mask = (1 << GPMC_SECTION_SHIFT) - size;
418 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
419 l &= ~0x3f;
420 l = (base >> GPMC_CHUNK_SHIFT) & 0x3f;
421 l &= ~(0x0f << 8);
422 l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8;
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530423 l |= GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300424 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
Jon Hunterc71f8e92013-03-06 12:00:10 -0600425
426 return 0;
Imre Deakf37e4582006-09-25 12:41:33 +0300427}
428
429static void gpmc_cs_disable_mem(int cs)
430{
431 u32 l;
432
433 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530434 l &= ~GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300435 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
436}
437
438static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size)
439{
440 u32 l;
441 u32 mask;
442
443 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
444 *base = (l & 0x3f) << GPMC_CHUNK_SHIFT;
445 mask = (l >> 8) & 0x0f;
446 *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT);
447}
448
449static int gpmc_cs_mem_enabled(int cs)
450{
451 u32 l;
452
453 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530454 return l & GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300455}
456
Ezequiel Garciaf5d8eda2013-02-12 16:22:24 -0300457static void gpmc_cs_set_reserved(int cs, int reserved)
Imre Deakf37e4582006-09-25 12:41:33 +0300458{
459 gpmc_cs_map &= ~(1 << cs);
460 gpmc_cs_map |= (reserved ? 1 : 0) << cs;
461}
462
Ezequiel Garciaae9d9082013-02-12 16:22:19 -0300463static bool gpmc_cs_reserved(int cs)
Imre Deakf37e4582006-09-25 12:41:33 +0300464{
465 return gpmc_cs_map & (1 << cs);
466}
467
468static unsigned long gpmc_mem_align(unsigned long size)
469{
470 int order;
471
472 size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1);
473 order = GPMC_CHUNK_SHIFT - 1;
474 do {
475 size >>= 1;
476 order++;
477 } while (size);
478 size = 1 << order;
479 return size;
480}
481
482static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
483{
484 struct resource *res = &gpmc_cs_mem[cs];
485 int r;
486
487 size = gpmc_mem_align(size);
488 spin_lock(&gpmc_mem_lock);
489 res->start = base;
490 res->end = base + size - 1;
491 r = request_resource(&gpmc_mem_root, res);
492 spin_unlock(&gpmc_mem_lock);
493
494 return r;
495}
496
Afzal Mohammedda496872012-09-23 17:28:25 -0600497static int gpmc_cs_delete_mem(int cs)
498{
499 struct resource *res = &gpmc_cs_mem[cs];
500 int r;
501
502 spin_lock(&gpmc_mem_lock);
503 r = release_resource(&gpmc_cs_mem[cs]);
504 res->start = 0;
505 res->end = 0;
506 spin_unlock(&gpmc_mem_lock);
507
508 return r;
509}
510
Jon Huntercdd69282013-02-08 16:46:13 -0600511/**
512 * gpmc_cs_remap - remaps a chip-select physical base address
513 * @cs: chip-select to remap
514 * @base: physical base address to re-map chip-select to
515 *
516 * Re-maps a chip-select to a new physical base address specified by
517 * "base". Returns 0 on success and appropriate negative error code
518 * on failure.
519 */
520static int gpmc_cs_remap(int cs, u32 base)
521{
522 int ret;
523 u32 old_base, size;
524
Gupta Pekonf34f3712013-05-31 17:31:30 +0530525 if (cs > gpmc_cs_num) {
526 pr_err("%s: requested chip-select is disabled\n", __func__);
Jon Huntercdd69282013-02-08 16:46:13 -0600527 return -ENODEV;
Gupta Pekonf34f3712013-05-31 17:31:30 +0530528 }
Jon Huntercdd69282013-02-08 16:46:13 -0600529 gpmc_cs_get_memconf(cs, &old_base, &size);
530 if (base == old_base)
531 return 0;
532 gpmc_cs_disable_mem(cs);
533 ret = gpmc_cs_delete_mem(cs);
534 if (ret < 0)
535 return ret;
536 ret = gpmc_cs_insert_mem(cs, base, size);
537 if (ret < 0)
538 return ret;
Jon Hunterc71f8e92013-03-06 12:00:10 -0600539 ret = gpmc_cs_enable_mem(cs, base, size);
540 if (ret < 0)
541 return ret;
Jon Huntercdd69282013-02-08 16:46:13 -0600542
543 return 0;
544}
545
Imre Deakf37e4582006-09-25 12:41:33 +0300546int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
547{
548 struct resource *res = &gpmc_cs_mem[cs];
549 int r = -1;
550
Gupta Pekonf34f3712013-05-31 17:31:30 +0530551 if (cs > gpmc_cs_num) {
552 pr_err("%s: requested chip-select is disabled\n", __func__);
Imre Deakf37e4582006-09-25 12:41:33 +0300553 return -ENODEV;
Gupta Pekonf34f3712013-05-31 17:31:30 +0530554 }
Imre Deakf37e4582006-09-25 12:41:33 +0300555 size = gpmc_mem_align(size);
556 if (size > (1 << GPMC_SECTION_SHIFT))
557 return -ENOMEM;
558
559 spin_lock(&gpmc_mem_lock);
560 if (gpmc_cs_reserved(cs)) {
561 r = -EBUSY;
562 goto out;
563 }
564 if (gpmc_cs_mem_enabled(cs))
565 r = adjust_resource(res, res->start & ~(size - 1), size);
566 if (r < 0)
567 r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
568 size, NULL, NULL);
569 if (r < 0)
570 goto out;
571
Jon Hunterc71f8e92013-03-06 12:00:10 -0600572 r = gpmc_cs_enable_mem(cs, res->start, resource_size(res));
573 if (r < 0) {
574 release_resource(res);
575 goto out;
576 }
577
Imre Deakf37e4582006-09-25 12:41:33 +0300578 *base = res->start;
579 gpmc_cs_set_reserved(cs, 1);
580out:
581 spin_unlock(&gpmc_mem_lock);
582 return r;
583}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300584EXPORT_SYMBOL(gpmc_cs_request);
Imre Deakf37e4582006-09-25 12:41:33 +0300585
586void gpmc_cs_free(int cs)
587{
588 spin_lock(&gpmc_mem_lock);
Gupta Pekonf34f3712013-05-31 17:31:30 +0530589 if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) {
Imre Deakf37e4582006-09-25 12:41:33 +0300590 printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
591 BUG();
592 spin_unlock(&gpmc_mem_lock);
593 return;
594 }
595 gpmc_cs_disable_mem(cs);
596 release_resource(&gpmc_cs_mem[cs]);
597 gpmc_cs_set_reserved(cs, 0);
598 spin_unlock(&gpmc_mem_lock);
599}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300600EXPORT_SYMBOL(gpmc_cs_free);
Imre Deakf37e4582006-09-25 12:41:33 +0300601
vimal singh59e9c5a2009-07-13 16:26:24 +0530602/**
Jon Hunter3a544352013-02-21 13:00:21 -0600603 * gpmc_configure - write request to configure gpmc
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000604 * @cmd: command type
605 * @wval: value to write
606 * @return status of the operation
607 */
Jon Hunter3a544352013-02-21 13:00:21 -0600608int gpmc_configure(int cmd, int wval)
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000609{
Jon Hunter3a544352013-02-21 13:00:21 -0600610 u32 regval;
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000611
612 switch (cmd) {
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530613 case GPMC_ENABLE_IRQ:
614 gpmc_write_reg(GPMC_IRQENABLE, wval);
615 break;
616
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000617 case GPMC_SET_IRQ_STATUS:
618 gpmc_write_reg(GPMC_IRQSTATUS, wval);
619 break;
620
621 case GPMC_CONFIG_WP:
622 regval = gpmc_read_reg(GPMC_CONFIG);
623 if (wval)
624 regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
625 else
626 regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
627 gpmc_write_reg(GPMC_CONFIG, regval);
628 break;
629
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000630 default:
Jon Hunter3a544352013-02-21 13:00:21 -0600631 pr_err("%s: command not supported\n", __func__);
632 return -EINVAL;
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000633 }
634
Jon Hunter3a544352013-02-21 13:00:21 -0600635 return 0;
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000636}
Jon Hunter3a544352013-02-21 13:00:21 -0600637EXPORT_SYMBOL(gpmc_configure);
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000638
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700639void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
640{
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530641 int i;
642
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700643 reg->gpmc_status = gpmc_base + GPMC_STATUS;
644 reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
645 GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
646 reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
647 GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
648 reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
649 GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
650 reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
651 reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
652 reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
653 reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
654 reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
655 reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
656 reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
657 reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530658
659 for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
660 reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
661 GPMC_BCH_SIZE * i;
662 reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
663 GPMC_BCH_SIZE * i;
664 reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
665 GPMC_BCH_SIZE * i;
666 reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
667 GPMC_BCH_SIZE * i;
668 }
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700669}
670
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700671int gpmc_get_client_irq(unsigned irq_config)
672{
673 int i;
674
675 if (hweight32(irq_config) > 1)
676 return 0;
677
678 for (i = 0; i < GPMC_NR_IRQ; i++)
679 if (gpmc_client_irq[i].bitmask & irq_config)
680 return gpmc_client_irq[i].irq;
681
682 return 0;
683}
684
685static int gpmc_irq_endis(unsigned irq, bool endis)
686{
687 int i;
688 u32 regval;
689
690 for (i = 0; i < GPMC_NR_IRQ; i++)
691 if (irq == gpmc_client_irq[i].irq) {
692 regval = gpmc_read_reg(GPMC_IRQENABLE);
693 if (endis)
694 regval |= gpmc_client_irq[i].bitmask;
695 else
696 regval &= ~gpmc_client_irq[i].bitmask;
697 gpmc_write_reg(GPMC_IRQENABLE, regval);
698 break;
699 }
700
701 return 0;
702}
703
704static void gpmc_irq_disable(struct irq_data *p)
705{
706 gpmc_irq_endis(p->irq, false);
707}
708
709static void gpmc_irq_enable(struct irq_data *p)
710{
711 gpmc_irq_endis(p->irq, true);
712}
713
714static void gpmc_irq_noop(struct irq_data *data) { }
715
716static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
717
Afzal Mohammedda496872012-09-23 17:28:25 -0600718static int gpmc_setup_irq(void)
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700719{
720 int i;
721 u32 regval;
722
723 if (!gpmc_irq)
724 return -EINVAL;
725
726 gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
Russell King71856842013-03-13 20:44:21 +0000727 if (gpmc_irq_start < 0) {
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700728 pr_err("irq_alloc_descs failed\n");
729 return gpmc_irq_start;
730 }
731
732 gpmc_irq_chip.name = "gpmc";
733 gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
734 gpmc_irq_chip.irq_enable = gpmc_irq_enable;
735 gpmc_irq_chip.irq_disable = gpmc_irq_disable;
736 gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
737 gpmc_irq_chip.irq_ack = gpmc_irq_noop;
738 gpmc_irq_chip.irq_mask = gpmc_irq_noop;
739 gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
740
741 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
742 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
743
744 for (i = 0; i < GPMC_NR_IRQ; i++) {
745 gpmc_client_irq[i].irq = gpmc_irq_start + i;
746 irq_set_chip_and_handler(gpmc_client_irq[i].irq,
747 &gpmc_irq_chip, handle_simple_irq);
748 set_irq_flags(gpmc_client_irq[i].irq,
749 IRQF_VALID | IRQF_NOAUTOEN);
750 }
751
752 /* Disable interrupts */
753 gpmc_write_reg(GPMC_IRQENABLE, 0);
754
755 /* clear interrupts */
756 regval = gpmc_read_reg(GPMC_IRQSTATUS);
757 gpmc_write_reg(GPMC_IRQSTATUS, regval);
758
759 return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
760}
761
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800762static int gpmc_free_irq(void)
Afzal Mohammedda496872012-09-23 17:28:25 -0600763{
764 int i;
765
766 if (gpmc_irq)
767 free_irq(gpmc_irq, NULL);
768
769 for (i = 0; i < GPMC_NR_IRQ; i++) {
770 irq_set_handler(gpmc_client_irq[i].irq, NULL);
771 irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
772 irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
773 }
774
775 irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
776
777 return 0;
778}
779
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800780static void gpmc_mem_exit(void)
Afzal Mohammedda496872012-09-23 17:28:25 -0600781{
782 int cs;
783
Gupta Pekonf34f3712013-05-31 17:31:30 +0530784 for (cs = 0; cs < gpmc_cs_num; cs++) {
Afzal Mohammedda496872012-09-23 17:28:25 -0600785 if (!gpmc_cs_mem_enabled(cs))
786 continue;
787 gpmc_cs_delete_mem(cs);
788 }
789
790}
791
Jon Hunter84b00f02013-03-06 14:36:47 -0600792static void gpmc_mem_init(void)
Imre Deakf37e4582006-09-25 12:41:33 +0300793{
Jon Hunter84b00f02013-03-06 14:36:47 -0600794 int cs;
Imre Deakf37e4582006-09-25 12:41:33 +0300795
Jon Hunterbf234392013-03-06 14:12:59 -0600796 /*
797 * The first 1MB of GPMC address space is typically mapped to
798 * the internal ROM. Never allocate the first page, to
799 * facilitate bug detection; even if we didn't boot from ROM.
Kyungmin Park7f245162006-12-29 16:48:51 -0800800 */
Jon Hunterbf234392013-03-06 14:12:59 -0600801 gpmc_mem_root.start = SZ_1M;
Imre Deakf37e4582006-09-25 12:41:33 +0300802 gpmc_mem_root.end = GPMC_MEM_END;
803
804 /* Reserve all regions that has been set up by bootloader */
Gupta Pekonf34f3712013-05-31 17:31:30 +0530805 for (cs = 0; cs < gpmc_cs_num; cs++) {
Imre Deakf37e4582006-09-25 12:41:33 +0300806 u32 base, size;
807
808 if (!gpmc_cs_mem_enabled(cs))
809 continue;
810 gpmc_cs_get_memconf(cs, &base, &size);
Jon Hunter84b00f02013-03-06 14:36:47 -0600811 if (gpmc_cs_insert_mem(cs, base, size)) {
812 pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n",
813 __func__, cs, base, base + size);
814 gpmc_cs_disable_mem(cs);
Jon Hunter81190242012-10-17 09:41:25 -0500815 }
Imre Deakf37e4582006-09-25 12:41:33 +0300816 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700817}
818
Afzal Mohammed246da262012-08-02 20:02:10 +0530819static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk)
820{
821 u32 temp;
822 int div;
823
824 div = gpmc_calc_divider(sync_clk);
825 temp = gpmc_ps_to_ticks(time_ps);
826 temp = (temp + div - 1) / div;
827 return gpmc_ticks_to_ps(temp * div);
828}
829
830/* XXX: can the cycles be avoided ? */
831static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -0600832 struct gpmc_device_timings *dev_t,
833 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +0530834{
Afzal Mohammed246da262012-08-02 20:02:10 +0530835 u32 temp;
836
837 /* adv_rd_off */
838 temp = dev_t->t_avdp_r;
839 /* XXX: mux check required ? */
840 if (mux) {
841 /* XXX: t_avdp not to be required for sync, only added for tusb
842 * this indirectly necessitates requirement of t_avdp_r and
843 * t_avdp_w instead of having a single t_avdp
844 */
845 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh);
846 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
847 }
848 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
849
850 /* oe_on */
851 temp = dev_t->t_oeasu; /* XXX: remove this ? */
852 if (mux) {
853 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach);
854 temp = max_t(u32, temp, gpmc_t->adv_rd_off +
855 gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe));
856 }
857 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
858
859 /* access */
860 /* XXX: any scope for improvement ?, by combining oe_on
861 * and clk_activation, need to check whether
862 * access = clk_activation + round to sync clk ?
863 */
864 temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk);
865 temp += gpmc_t->clk_activation;
866 if (dev_t->cyc_oe)
867 temp = max_t(u32, temp, gpmc_t->oe_on +
868 gpmc_ticks_to_ps(dev_t->cyc_oe));
869 gpmc_t->access = gpmc_round_ps_to_ticks(temp);
870
871 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
872 gpmc_t->cs_rd_off = gpmc_t->oe_off;
873
874 /* rd_cycle */
875 temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez);
876 temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) +
877 gpmc_t->access;
878 /* XXX: barter t_ce_rdyz with t_cez_r ? */
879 if (dev_t->t_ce_rdyz)
880 temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz);
881 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
882
883 return 0;
884}
885
886static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -0600887 struct gpmc_device_timings *dev_t,
888 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +0530889{
Afzal Mohammed246da262012-08-02 20:02:10 +0530890 u32 temp;
891
892 /* adv_wr_off */
893 temp = dev_t->t_avdp_w;
894 if (mux) {
895 temp = max_t(u32, temp,
896 gpmc_t->clk_activation + dev_t->t_avdh);
897 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
898 }
899 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
900
901 /* wr_data_mux_bus */
902 temp = max_t(u32, dev_t->t_weasu,
903 gpmc_t->clk_activation + dev_t->t_rdyo);
904 /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?,
905 * and in that case remember to handle we_on properly
906 */
907 if (mux) {
908 temp = max_t(u32, temp,
909 gpmc_t->adv_wr_off + dev_t->t_aavdh);
910 temp = max_t(u32, temp, gpmc_t->adv_wr_off +
911 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
912 }
913 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
914
915 /* we_on */
916 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
917 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
918 else
919 gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
920
921 /* wr_access */
922 /* XXX: gpmc_capability check reqd ? , even if not, will not harm */
923 gpmc_t->wr_access = gpmc_t->access;
924
925 /* we_off */
926 temp = gpmc_t->we_on + dev_t->t_wpl;
927 temp = max_t(u32, temp,
928 gpmc_t->wr_access + gpmc_ticks_to_ps(1));
929 temp = max_t(u32, temp,
930 gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl));
931 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
932
933 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
934 dev_t->t_wph);
935
936 /* wr_cycle */
937 temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk);
938 temp += gpmc_t->wr_access;
939 /* XXX: barter t_ce_rdyz with t_cez_w ? */
940 if (dev_t->t_ce_rdyz)
941 temp = max_t(u32, temp,
942 gpmc_t->cs_wr_off + dev_t->t_ce_rdyz);
943 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
944
945 return 0;
946}
947
948static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -0600949 struct gpmc_device_timings *dev_t,
950 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +0530951{
Afzal Mohammed246da262012-08-02 20:02:10 +0530952 u32 temp;
953
954 /* adv_rd_off */
955 temp = dev_t->t_avdp_r;
956 if (mux)
957 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
958 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
959
960 /* oe_on */
961 temp = dev_t->t_oeasu;
962 if (mux)
963 temp = max_t(u32, temp,
964 gpmc_t->adv_rd_off + dev_t->t_aavdh);
965 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
966
967 /* access */
968 temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */
969 gpmc_t->oe_on + dev_t->t_oe);
970 temp = max_t(u32, temp,
971 gpmc_t->cs_on + dev_t->t_ce);
972 temp = max_t(u32, temp,
973 gpmc_t->adv_on + dev_t->t_aa);
974 gpmc_t->access = gpmc_round_ps_to_ticks(temp);
975
976 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
977 gpmc_t->cs_rd_off = gpmc_t->oe_off;
978
979 /* rd_cycle */
980 temp = max_t(u32, dev_t->t_rd_cycle,
981 gpmc_t->cs_rd_off + dev_t->t_cez_r);
982 temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez);
983 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
984
985 return 0;
986}
987
988static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -0600989 struct gpmc_device_timings *dev_t,
990 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +0530991{
Afzal Mohammed246da262012-08-02 20:02:10 +0530992 u32 temp;
993
994 /* adv_wr_off */
995 temp = dev_t->t_avdp_w;
996 if (mux)
997 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
998 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
999
1000 /* wr_data_mux_bus */
1001 temp = dev_t->t_weasu;
1002 if (mux) {
1003 temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh);
1004 temp = max_t(u32, temp, gpmc_t->adv_wr_off +
1005 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
1006 }
1007 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
1008
1009 /* we_on */
1010 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
1011 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
1012 else
1013 gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
1014
1015 /* we_off */
1016 temp = gpmc_t->we_on + dev_t->t_wpl;
1017 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
1018
1019 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
1020 dev_t->t_wph);
1021
1022 /* wr_cycle */
1023 temp = max_t(u32, dev_t->t_wr_cycle,
1024 gpmc_t->cs_wr_off + dev_t->t_cez_w);
1025 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
1026
1027 return 0;
1028}
1029
1030static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t,
1031 struct gpmc_device_timings *dev_t)
1032{
1033 u32 temp;
1034
1035 gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) *
1036 gpmc_get_fclk_period();
1037
1038 gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk(
1039 dev_t->t_bacc,
1040 gpmc_t->sync_clk);
1041
1042 temp = max_t(u32, dev_t->t_ces, dev_t->t_avds);
1043 gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp);
1044
1045 if (gpmc_calc_divider(gpmc_t->sync_clk) != 1)
1046 return 0;
1047
1048 if (dev_t->ce_xdelay)
1049 gpmc_t->bool_timings.cs_extra_delay = true;
1050 if (dev_t->avd_xdelay)
1051 gpmc_t->bool_timings.adv_extra_delay = true;
1052 if (dev_t->oe_xdelay)
1053 gpmc_t->bool_timings.oe_extra_delay = true;
1054 if (dev_t->we_xdelay)
1055 gpmc_t->bool_timings.we_extra_delay = true;
1056
1057 return 0;
1058}
1059
1060static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001061 struct gpmc_device_timings *dev_t,
1062 bool sync)
Afzal Mohammed246da262012-08-02 20:02:10 +05301063{
1064 u32 temp;
1065
1066 /* cs_on */
1067 gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu);
1068
1069 /* adv_on */
1070 temp = dev_t->t_avdasu;
1071 if (dev_t->t_ce_avd)
1072 temp = max_t(u32, temp,
1073 gpmc_t->cs_on + dev_t->t_ce_avd);
1074 gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp);
1075
Jon Hunterc3be5b42013-02-21 13:46:22 -06001076 if (sync)
Afzal Mohammed246da262012-08-02 20:02:10 +05301077 gpmc_calc_sync_common_timings(gpmc_t, dev_t);
1078
1079 return 0;
1080}
1081
1082/* TODO: remove this function once all peripherals are confirmed to
1083 * work with generic timing. Simultaneously gpmc_cs_set_timings()
1084 * has to be modified to handle timings in ps instead of ns
1085*/
1086static void gpmc_convert_ps_to_ns(struct gpmc_timings *t)
1087{
1088 t->cs_on /= 1000;
1089 t->cs_rd_off /= 1000;
1090 t->cs_wr_off /= 1000;
1091 t->adv_on /= 1000;
1092 t->adv_rd_off /= 1000;
1093 t->adv_wr_off /= 1000;
1094 t->we_on /= 1000;
1095 t->we_off /= 1000;
1096 t->oe_on /= 1000;
1097 t->oe_off /= 1000;
1098 t->page_burst_access /= 1000;
1099 t->access /= 1000;
1100 t->rd_cycle /= 1000;
1101 t->wr_cycle /= 1000;
1102 t->bus_turnaround /= 1000;
1103 t->cycle2cycle_delay /= 1000;
1104 t->wait_monitoring /= 1000;
1105 t->clk_activation /= 1000;
1106 t->wr_access /= 1000;
1107 t->wr_data_mux_bus /= 1000;
1108}
1109
1110int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001111 struct gpmc_settings *gpmc_s,
1112 struct gpmc_device_timings *dev_t)
Afzal Mohammed246da262012-08-02 20:02:10 +05301113{
Jon Hunterc3be5b42013-02-21 13:46:22 -06001114 bool mux = false, sync = false;
1115
1116 if (gpmc_s) {
1117 mux = gpmc_s->mux_add_data ? true : false;
1118 sync = (gpmc_s->sync_read || gpmc_s->sync_write);
1119 }
1120
Afzal Mohammed246da262012-08-02 20:02:10 +05301121 memset(gpmc_t, 0, sizeof(*gpmc_t));
1122
Jon Hunterc3be5b42013-02-21 13:46:22 -06001123 gpmc_calc_common_timings(gpmc_t, dev_t, sync);
Afzal Mohammed246da262012-08-02 20:02:10 +05301124
Jon Hunterc3be5b42013-02-21 13:46:22 -06001125 if (gpmc_s && gpmc_s->sync_read)
1126 gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301127 else
Jon Hunterc3be5b42013-02-21 13:46:22 -06001128 gpmc_calc_async_read_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301129
Jon Hunterc3be5b42013-02-21 13:46:22 -06001130 if (gpmc_s && gpmc_s->sync_write)
1131 gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301132 else
Jon Hunterc3be5b42013-02-21 13:46:22 -06001133 gpmc_calc_async_write_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301134
1135 /* TODO: remove, see function definition */
1136 gpmc_convert_ps_to_ns(gpmc_t);
1137
1138 return 0;
1139}
1140
Jon Hunteraa8d4762013-02-21 15:25:23 -06001141/**
1142 * gpmc_cs_program_settings - programs non-timing related settings
1143 * @cs: GPMC chip-select to program
1144 * @p: pointer to GPMC settings structure
1145 *
1146 * Programs non-timing related settings for a GPMC chip-select, such as
1147 * bus-width, burst configuration, etc. Function should be called once
1148 * for each chip-select that is being used and must be called before
1149 * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1
1150 * register will be initialised to zero by this function. Returns 0 on
1151 * success and appropriate negative error code on failure.
1152 */
1153int gpmc_cs_program_settings(int cs, struct gpmc_settings *p)
1154{
1155 u32 config1;
1156
1157 if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) {
1158 pr_err("%s: invalid width %d!", __func__, p->device_width);
1159 return -EINVAL;
1160 }
1161
1162 /* Address-data multiplexing not supported for NAND devices */
1163 if (p->device_nand && p->mux_add_data) {
1164 pr_err("%s: invalid configuration!\n", __func__);
1165 return -EINVAL;
1166 }
1167
1168 if ((p->mux_add_data > GPMC_MUX_AD) ||
1169 ((p->mux_add_data == GPMC_MUX_AAD) &&
1170 !(gpmc_capability & GPMC_HAS_MUX_AAD))) {
1171 pr_err("%s: invalid multiplex configuration!\n", __func__);
1172 return -EINVAL;
1173 }
1174
1175 /* Page/burst mode supports lengths of 4, 8 and 16 bytes */
1176 if (p->burst_read || p->burst_write) {
1177 switch (p->burst_len) {
1178 case GPMC_BURST_4:
1179 case GPMC_BURST_8:
1180 case GPMC_BURST_16:
1181 break;
1182 default:
1183 pr_err("%s: invalid page/burst-length (%d)\n",
1184 __func__, p->burst_len);
1185 return -EINVAL;
1186 }
1187 }
1188
1189 if ((p->wait_on_read || p->wait_on_write) &&
1190 (p->wait_pin > gpmc_nr_waitpins)) {
1191 pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin);
1192 return -EINVAL;
1193 }
1194
1195 config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1));
1196
1197 if (p->sync_read)
1198 config1 |= GPMC_CONFIG1_READTYPE_SYNC;
1199 if (p->sync_write)
1200 config1 |= GPMC_CONFIG1_WRITETYPE_SYNC;
1201 if (p->wait_on_read)
1202 config1 |= GPMC_CONFIG1_WAIT_READ_MON;
1203 if (p->wait_on_write)
1204 config1 |= GPMC_CONFIG1_WAIT_WRITE_MON;
1205 if (p->wait_on_read || p->wait_on_write)
1206 config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin);
1207 if (p->device_nand)
1208 config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND);
1209 if (p->mux_add_data)
1210 config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data);
1211 if (p->burst_read)
1212 config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP;
1213 if (p->burst_write)
1214 config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP;
1215 if (p->burst_read || p->burst_write) {
1216 config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3);
1217 config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0;
1218 }
1219
1220 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1);
1221
1222 return 0;
1223}
1224
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001225#ifdef CONFIG_OF
1226static struct of_device_id gpmc_dt_ids[] = {
1227 { .compatible = "ti,omap2420-gpmc" },
1228 { .compatible = "ti,omap2430-gpmc" },
1229 { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
1230 { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
1231 { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
1232 { }
1233};
1234MODULE_DEVICE_TABLE(of, gpmc_dt_ids);
1235
Jon Hunter8c8a77712013-02-20 15:53:12 -06001236/**
1237 * gpmc_read_settings_dt - read gpmc settings from device-tree
1238 * @np: pointer to device-tree node for a gpmc child device
1239 * @p: pointer to gpmc settings structure
1240 *
1241 * Reads the GPMC settings for a GPMC child device from device-tree and
1242 * stores them in the GPMC settings structure passed. The GPMC settings
1243 * structure is initialised to zero by this function and so any
1244 * previously stored settings will be cleared.
1245 */
1246void gpmc_read_settings_dt(struct device_node *np, struct gpmc_settings *p)
1247{
1248 memset(p, 0, sizeof(struct gpmc_settings));
1249
1250 p->sync_read = of_property_read_bool(np, "gpmc,sync-read");
1251 p->sync_write = of_property_read_bool(np, "gpmc,sync-write");
Jon Hunter8c8a77712013-02-20 15:53:12 -06001252 of_property_read_u32(np, "gpmc,device-width", &p->device_width);
1253 of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data);
1254
1255 if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) {
1256 p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap");
1257 p->burst_read = of_property_read_bool(np, "gpmc,burst-read");
1258 p->burst_write = of_property_read_bool(np, "gpmc,burst-write");
1259 if (!p->burst_read && !p->burst_write)
1260 pr_warn("%s: page/burst-length set but not used!\n",
1261 __func__);
1262 }
1263
1264 if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) {
1265 p->wait_on_read = of_property_read_bool(np,
1266 "gpmc,wait-on-read");
1267 p->wait_on_write = of_property_read_bool(np,
1268 "gpmc,wait-on-write");
1269 if (!p->wait_on_read && !p->wait_on_write)
1270 pr_warn("%s: read/write wait monitoring not enabled!\n",
1271 __func__);
1272 }
1273}
1274
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001275static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
1276 struct gpmc_timings *gpmc_t)
1277{
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001278 struct gpmc_bool_timings *p;
1279
1280 if (!np || !gpmc_t)
1281 return;
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001282
1283 memset(gpmc_t, 0, sizeof(*gpmc_t));
1284
1285 /* minimum clock period for syncronous mode */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001286 of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001287
1288 /* chip select timtings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001289 of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on);
1290 of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off);
1291 of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001292
1293 /* ADV signal timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001294 of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on);
1295 of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off);
1296 of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001297
1298 /* WE signal timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001299 of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on);
1300 of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001301
1302 /* OE signal timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001303 of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on);
1304 of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001305
1306 /* access and cycle timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001307 of_property_read_u32(np, "gpmc,page-burst-access-ns",
1308 &gpmc_t->page_burst_access);
1309 of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access);
1310 of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle);
1311 of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle);
1312 of_property_read_u32(np, "gpmc,bus-turnaround-ns",
1313 &gpmc_t->bus_turnaround);
1314 of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns",
1315 &gpmc_t->cycle2cycle_delay);
1316 of_property_read_u32(np, "gpmc,wait-monitoring-ns",
1317 &gpmc_t->wait_monitoring);
1318 of_property_read_u32(np, "gpmc,clk-activation-ns",
1319 &gpmc_t->clk_activation);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001320
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001321 /* only applicable to OMAP3+ */
1322 of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access);
1323 of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns",
1324 &gpmc_t->wr_data_mux_bus);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001325
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001326 /* bool timing parameters */
1327 p = &gpmc_t->bool_timings;
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001328
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001329 p->cycle2cyclediffcsen =
1330 of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen");
1331 p->cycle2cyclesamecsen =
1332 of_property_read_bool(np, "gpmc,cycle2cycle-samecsen");
1333 p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay");
1334 p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay");
1335 p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay");
1336 p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay");
1337 p->time_para_granularity =
1338 of_property_read_bool(np, "gpmc,time-para-granularity");
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001339}
1340
1341#ifdef CONFIG_MTD_NAND
1342
1343static const char * const nand_ecc_opts[] = {
1344 [OMAP_ECC_HAMMING_CODE_DEFAULT] = "sw",
1345 [OMAP_ECC_HAMMING_CODE_HW] = "hw",
1346 [OMAP_ECC_HAMMING_CODE_HW_ROMCODE] = "hw-romcode",
1347 [OMAP_ECC_BCH4_CODE_HW] = "bch4",
1348 [OMAP_ECC_BCH8_CODE_HW] = "bch8",
1349};
1350
Mark Jackson496c8a02013-04-19 21:08:28 +01001351static const char * const nand_xfer_types[] = {
1352 [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled",
1353 [NAND_OMAP_POLLED] = "polled",
1354 [NAND_OMAP_PREFETCH_DMA] = "prefetch-dma",
1355 [NAND_OMAP_PREFETCH_IRQ] = "prefetch-irq",
1356};
1357
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001358static int gpmc_probe_nand_child(struct platform_device *pdev,
1359 struct device_node *child)
1360{
1361 u32 val;
1362 const char *s;
1363 struct gpmc_timings gpmc_t;
1364 struct omap_nand_platform_data *gpmc_nand_data;
1365
1366 if (of_property_read_u32(child, "reg", &val) < 0) {
1367 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1368 child->full_name);
1369 return -ENODEV;
1370 }
1371
1372 gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
1373 GFP_KERNEL);
1374 if (!gpmc_nand_data)
1375 return -ENOMEM;
1376
1377 gpmc_nand_data->cs = val;
1378 gpmc_nand_data->of_node = child;
1379
1380 if (!of_property_read_string(child, "ti,nand-ecc-opt", &s))
1381 for (val = 0; val < ARRAY_SIZE(nand_ecc_opts); val++)
1382 if (!strcasecmp(s, nand_ecc_opts[val])) {
1383 gpmc_nand_data->ecc_opt = val;
1384 break;
1385 }
1386
Mark Jackson496c8a02013-04-19 21:08:28 +01001387 if (!of_property_read_string(child, "ti,nand-xfer-type", &s))
1388 for (val = 0; val < ARRAY_SIZE(nand_xfer_types); val++)
1389 if (!strcasecmp(s, nand_xfer_types[val])) {
1390 gpmc_nand_data->xfer_type = val;
1391 break;
1392 }
1393
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001394 val = of_get_nand_bus_width(child);
1395 if (val == 16)
1396 gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
1397
1398 gpmc_read_timings_dt(child, &gpmc_t);
1399 gpmc_nand_init(gpmc_nand_data, &gpmc_t);
1400
1401 return 0;
1402}
1403#else
1404static int gpmc_probe_nand_child(struct platform_device *pdev,
1405 struct device_node *child)
1406{
1407 return 0;
1408}
1409#endif
1410
Ezequiel Garcia75d36252013-01-25 09:23:11 -03001411#ifdef CONFIG_MTD_ONENAND
1412static int gpmc_probe_onenand_child(struct platform_device *pdev,
1413 struct device_node *child)
1414{
1415 u32 val;
1416 struct omap_onenand_platform_data *gpmc_onenand_data;
1417
1418 if (of_property_read_u32(child, "reg", &val) < 0) {
1419 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1420 child->full_name);
1421 return -ENODEV;
1422 }
1423
1424 gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
1425 GFP_KERNEL);
1426 if (!gpmc_onenand_data)
1427 return -ENOMEM;
1428
1429 gpmc_onenand_data->cs = val;
1430 gpmc_onenand_data->of_node = child;
1431 gpmc_onenand_data->dma_channel = -1;
1432
1433 if (!of_property_read_u32(child, "dma-channel", &val))
1434 gpmc_onenand_data->dma_channel = val;
1435
1436 gpmc_onenand_init(gpmc_onenand_data);
1437
1438 return 0;
1439}
1440#else
1441static int gpmc_probe_onenand_child(struct platform_device *pdev,
1442 struct device_node *child)
1443{
1444 return 0;
1445}
1446#endif
1447
Jon Huntercdd69282013-02-08 16:46:13 -06001448/**
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001449 * gpmc_probe_generic_child - configures the gpmc for a child device
Jon Huntercdd69282013-02-08 16:46:13 -06001450 * @pdev: pointer to gpmc platform device
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001451 * @child: pointer to device-tree node for child device
Jon Huntercdd69282013-02-08 16:46:13 -06001452 *
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001453 * Allocates and configures a GPMC chip-select for a child device.
Jon Huntercdd69282013-02-08 16:46:13 -06001454 * Returns 0 on success and appropriate negative error code on failure.
1455 */
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001456static int gpmc_probe_generic_child(struct platform_device *pdev,
Jon Huntercdd69282013-02-08 16:46:13 -06001457 struct device_node *child)
1458{
1459 struct gpmc_settings gpmc_s;
1460 struct gpmc_timings gpmc_t;
1461 struct resource res;
1462 unsigned long base;
1463 int ret, cs;
1464
1465 if (of_property_read_u32(child, "reg", &cs) < 0) {
1466 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1467 child->full_name);
1468 return -ENODEV;
1469 }
1470
1471 if (of_address_to_resource(child, 0, &res) < 0) {
1472 dev_err(&pdev->dev, "%s has malformed 'reg' property\n",
1473 child->full_name);
1474 return -ENODEV;
1475 }
1476
1477 ret = gpmc_cs_request(cs, resource_size(&res), &base);
1478 if (ret < 0) {
1479 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
1480 return ret;
1481 }
1482
1483 /*
1484 * FIXME: gpmc_cs_request() will map the CS to an arbitary
1485 * location in the gpmc address space. When booting with
1486 * device-tree we want the NOR flash to be mapped to the
1487 * location specified in the device-tree blob. So remap the
1488 * CS to this location. Once DT migration is complete should
1489 * just make gpmc_cs_request() map a specific address.
1490 */
1491 ret = gpmc_cs_remap(cs, res.start);
1492 if (ret < 0) {
1493 dev_err(&pdev->dev, "cannot remap GPMC CS %d to 0x%x\n",
1494 cs, res.start);
1495 goto err;
1496 }
1497
1498 gpmc_read_settings_dt(child, &gpmc_s);
1499
1500 ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width);
1501 if (ret < 0)
1502 goto err;
1503
1504 ret = gpmc_cs_program_settings(cs, &gpmc_s);
1505 if (ret < 0)
1506 goto err;
1507
1508 gpmc_read_timings_dt(child, &gpmc_t);
1509 gpmc_cs_set_timings(cs, &gpmc_t);
1510
1511 if (of_platform_device_create(child, NULL, &pdev->dev))
1512 return 0;
1513
1514 dev_err(&pdev->dev, "failed to create gpmc child %s\n", child->name);
Javier Martinez Canillase8ffd6f2013-03-14 16:09:20 +01001515 ret = -ENODEV;
Jon Huntercdd69282013-02-08 16:46:13 -06001516
1517err:
1518 gpmc_cs_free(cs);
1519
1520 return ret;
1521}
1522
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001523static int gpmc_probe_dt(struct platform_device *pdev)
1524{
1525 int ret;
1526 struct device_node *child;
1527 const struct of_device_id *of_id =
1528 of_match_device(gpmc_dt_ids, &pdev->dev);
1529
1530 if (!of_id)
1531 return 0;
1532
Gupta Pekonf34f3712013-05-31 17:31:30 +05301533 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs",
1534 &gpmc_cs_num);
1535 if (ret < 0) {
1536 pr_err("%s: number of chip-selects not defined\n", __func__);
1537 return ret;
1538 } else if (gpmc_cs_num < 1) {
1539 pr_err("%s: all chip-selects are disabled\n", __func__);
1540 return -EINVAL;
1541 } else if (gpmc_cs_num > GPMC_CS_NUM) {
1542 pr_err("%s: number of supported chip-selects cannot be > %d\n",
1543 __func__, GPMC_CS_NUM);
1544 return -EINVAL;
1545 }
1546
Jon Hunter9f833152013-02-20 15:53:38 -06001547 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins",
1548 &gpmc_nr_waitpins);
1549 if (ret < 0) {
1550 pr_err("%s: number of wait pins not found!\n", __func__);
1551 return ret;
1552 }
1553
Javier Martinez Canillasf2b09f62013-04-17 22:34:11 +02001554 for_each_child_of_node(pdev->dev.of_node, child) {
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001555
Javier Martinez Canillasf2b09f62013-04-17 22:34:11 +02001556 if (!child->name)
1557 continue;
Jon Huntercdd69282013-02-08 16:46:13 -06001558
Javier Martinez Canillasf2b09f62013-04-17 22:34:11 +02001559 if (of_node_cmp(child->name, "nand") == 0)
1560 ret = gpmc_probe_nand_child(pdev, child);
1561 else if (of_node_cmp(child->name, "onenand") == 0)
1562 ret = gpmc_probe_onenand_child(pdev, child);
1563 else if (of_node_cmp(child->name, "ethernet") == 0 ||
1564 of_node_cmp(child->name, "nor") == 0)
1565 ret = gpmc_probe_generic_child(pdev, child);
Jon Huntercdd69282013-02-08 16:46:13 -06001566
Javier Martinez Canillasb327b362013-04-17 22:34:12 +02001567 if (WARN(ret < 0, "%s: probing gpmc child %s failed\n",
1568 __func__, child->full_name))
Javier Martinez Canillas5330dc12013-03-14 22:54:11 +01001569 of_node_put(child);
Javier Martinez Canillas5330dc12013-03-14 22:54:11 +01001570 }
1571
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001572 return 0;
1573}
1574#else
1575static int gpmc_probe_dt(struct platform_device *pdev)
1576{
1577 return 0;
1578}
1579#endif
1580
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001581static int gpmc_probe(struct platform_device *pdev)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001582{
Jon Hunter81190242012-10-17 09:41:25 -05001583 int rc;
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001584 u32 l;
Afzal Mohammedda496872012-09-23 17:28:25 -06001585 struct resource *res;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001586
Afzal Mohammedda496872012-09-23 17:28:25 -06001587 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1588 if (res == NULL)
1589 return -ENOENT;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +03001590
Afzal Mohammedda496872012-09-23 17:28:25 -06001591 phys_base = res->start;
1592 mem_size = resource_size(res);
Kevin Hilman8d084362010-01-29 14:20:06 -08001593
Thierry Reding5857bd92013-01-21 11:08:55 +01001594 gpmc_base = devm_ioremap_resource(&pdev->dev, res);
1595 if (IS_ERR(gpmc_base))
1596 return PTR_ERR(gpmc_base);
Afzal Mohammedda496872012-09-23 17:28:25 -06001597
1598 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1599 if (res == NULL)
1600 dev_warn(&pdev->dev, "Failed to get resource: irq\n");
1601 else
1602 gpmc_irq = res->start;
1603
1604 gpmc_l3_clk = clk_get(&pdev->dev, "fck");
1605 if (IS_ERR(gpmc_l3_clk)) {
1606 dev_err(&pdev->dev, "error: clk_get\n");
1607 gpmc_irq = 0;
1608 return PTR_ERR(gpmc_l3_clk);
Paul Walmsleyfd1dc872008-10-06 15:49:17 +03001609 }
1610
Rajendra Nayak4d7cb452012-09-22 02:24:16 -06001611 clk_prepare_enable(gpmc_l3_clk);
Olof Johansson1daa8c12010-01-20 22:39:29 +00001612
Afzal Mohammedda496872012-09-23 17:28:25 -06001613 gpmc_dev = &pdev->dev;
1614
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001615 l = gpmc_read_reg(GPMC_REVISION);
Jon Hunteraa8d4762013-02-21 15:25:23 -06001616
1617 /*
1618 * FIXME: Once device-tree migration is complete the below flags
1619 * should be populated based upon the device-tree compatible
1620 * string. For now just use the IP revision. OMAP3+ devices have
1621 * the wr_access and wr_data_mux_bus register fields. OMAP4+
1622 * devices support the addr-addr-data multiplex protocol.
1623 *
1624 * GPMC IP revisions:
1625 * - OMAP24xx = 2.0
1626 * - OMAP3xxx = 5.0
1627 * - OMAP44xx/54xx/AM335x = 6.0
1628 */
Afzal Mohammedda496872012-09-23 17:28:25 -06001629 if (GPMC_REVISION_MAJOR(l) > 0x4)
1630 gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
Jon Hunteraa8d4762013-02-21 15:25:23 -06001631 if (GPMC_REVISION_MAJOR(l) > 0x5)
1632 gpmc_capability |= GPMC_HAS_MUX_AAD;
Afzal Mohammedda496872012-09-23 17:28:25 -06001633 dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
1634 GPMC_REVISION_MINOR(l));
1635
Jon Hunter84b00f02013-03-06 14:36:47 -06001636 gpmc_mem_init();
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301637
Russell King71856842013-03-13 20:44:21 +00001638 if (gpmc_setup_irq() < 0)
Afzal Mohammedda496872012-09-23 17:28:25 -06001639 dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
1640
Jon Hunter31d9adc2013-02-18 07:57:39 -06001641 /* Now the GPMC is initialised, unreserve the chip-selects */
1642 gpmc_cs_map = 0;
1643
Gupta Pekonf34f3712013-05-31 17:31:30 +05301644 if (!pdev->dev.of_node) {
1645 gpmc_cs_num = GPMC_CS_NUM;
Jon Hunter9f833152013-02-20 15:53:38 -06001646 gpmc_nr_waitpins = GPMC_NR_WAITPINS;
Gupta Pekonf34f3712013-05-31 17:31:30 +05301647 }
Jon Hunter9f833152013-02-20 15:53:38 -06001648
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001649 rc = gpmc_probe_dt(pdev);
1650 if (rc < 0) {
1651 clk_disable_unprepare(gpmc_l3_clk);
1652 clk_put(gpmc_l3_clk);
1653 dev_err(gpmc_dev, "failed to probe DT parameters\n");
1654 return rc;
1655 }
1656
Afzal Mohammedda496872012-09-23 17:28:25 -06001657 return 0;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301658}
Afzal Mohammedda496872012-09-23 17:28:25 -06001659
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001660static int gpmc_remove(struct platform_device *pdev)
Afzal Mohammedda496872012-09-23 17:28:25 -06001661{
1662 gpmc_free_irq();
1663 gpmc_mem_exit();
1664 gpmc_dev = NULL;
1665 return 0;
1666}
1667
1668static struct platform_driver gpmc_driver = {
1669 .probe = gpmc_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001670 .remove = gpmc_remove,
Afzal Mohammedda496872012-09-23 17:28:25 -06001671 .driver = {
1672 .name = DEVICE_NAME,
1673 .owner = THIS_MODULE,
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001674 .of_match_table = of_match_ptr(gpmc_dt_ids),
Afzal Mohammedda496872012-09-23 17:28:25 -06001675 },
1676};
1677
1678static __init int gpmc_init(void)
1679{
1680 return platform_driver_register(&gpmc_driver);
1681}
1682
1683static __exit void gpmc_exit(void)
1684{
1685 platform_driver_unregister(&gpmc_driver);
1686
1687}
1688
Tony Lindgrenb76c8b12013-01-11 11:24:18 -08001689omap_postcore_initcall(gpmc_init);
Afzal Mohammedda496872012-09-23 17:28:25 -06001690module_exit(gpmc_exit);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301691
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001692static int __init omap_gpmc_init(void)
1693{
1694 struct omap_hwmod *oh;
1695 struct platform_device *pdev;
1696 char *oh_name = "gpmc";
1697
Daniel Mack2f98ca82012-12-14 11:36:40 +01001698 /*
1699 * if the board boots up with a populated DT, do not
1700 * manually add the device from this initcall
1701 */
1702 if (of_have_populated_dt())
1703 return -ENODEV;
1704
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001705 oh = omap_hwmod_lookup(oh_name);
1706 if (!oh) {
1707 pr_err("Could not look up %s\n", oh_name);
1708 return -ENODEV;
1709 }
1710
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -07001711 pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0);
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001712 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
1713
1714 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
1715}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -08001716omap_postcore_initcall(omap_gpmc_init);
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001717
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301718static irqreturn_t gpmc_handle_irq(int irq, void *dev)
1719{
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001720 int i;
1721 u32 regval;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301722
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001723 regval = gpmc_read_reg(GPMC_IRQSTATUS);
1724
1725 if (!regval)
1726 return IRQ_NONE;
1727
1728 for (i = 0; i < GPMC_NR_IRQ; i++)
1729 if (regval & gpmc_client_irq[i].bitmask)
1730 generic_handle_irq(gpmc_client_irq[i].irq);
1731
1732 gpmc_write_reg(GPMC_IRQSTATUS, regval);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301733
1734 return IRQ_HANDLED;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001735}
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301736
1737#ifdef CONFIG_ARCH_OMAP3
1738static struct omap3_gpmc_regs gpmc_context;
1739
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001740void omap3_gpmc_save_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301741{
1742 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001743
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301744 gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
1745 gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
1746 gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
1747 gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
1748 gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
1749 gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
1750 gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
Gupta Pekonf34f3712013-05-31 17:31:30 +05301751 for (i = 0; i < gpmc_cs_num; i++) {
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301752 gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
1753 if (gpmc_context.cs_context[i].is_valid) {
1754 gpmc_context.cs_context[i].config1 =
1755 gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
1756 gpmc_context.cs_context[i].config2 =
1757 gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
1758 gpmc_context.cs_context[i].config3 =
1759 gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
1760 gpmc_context.cs_context[i].config4 =
1761 gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
1762 gpmc_context.cs_context[i].config5 =
1763 gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
1764 gpmc_context.cs_context[i].config6 =
1765 gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
1766 gpmc_context.cs_context[i].config7 =
1767 gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
1768 }
1769 }
1770}
1771
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001772void omap3_gpmc_restore_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301773{
1774 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001775
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301776 gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
1777 gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
1778 gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
1779 gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
1780 gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
1781 gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
1782 gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
Gupta Pekonf34f3712013-05-31 17:31:30 +05301783 for (i = 0; i < gpmc_cs_num; i++) {
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301784 if (gpmc_context.cs_context[i].is_valid) {
1785 gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
1786 gpmc_context.cs_context[i].config1);
1787 gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
1788 gpmc_context.cs_context[i].config2);
1789 gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
1790 gpmc_context.cs_context[i].config3);
1791 gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
1792 gpmc_context.cs_context[i].config4);
1793 gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
1794 gpmc_context.cs_context[i].config5);
1795 gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
1796 gpmc_context.cs_context[i].config6);
1797 gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
1798 gpmc_context.cs_context[i].config7);
1799 }
1800 }
1801}
1802#endif /* CONFIG_ARCH_OMAP3 */