blob: 92898687181c143cac8b218500ff4182591e0505 [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 */
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +053015#include <linux/irq.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070016#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/clk.h>
Imre Deakf37e4582006-09-25 12:41:33 +030020#include <linux/ioport.h>
21#include <linux/spinlock.h>
Russell Kingfced80c2008-09-06 12:10:45 +010022#include <linux/io.h>
Paul Walmsleyfd1dc872008-10-06 15:49:17 +030023#include <linux/module.h>
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +053024#include <linux/interrupt.h>
Afzal Mohammedda496872012-09-23 17:28:25 -060025#include <linux/platform_device.h>
Daniel Mackbc6b1e72012-12-14 11:36:44 +010026#include <linux/of.h>
Jon Huntercdd69282013-02-08 16:46:13 -060027#include <linux/of_address.h>
Daniel Mackbc6b1e72012-12-14 11:36:44 +010028#include <linux/of_mtd.h>
29#include <linux/of_device.h>
Robert ABELb1dc1ca2015-02-27 16:56:49 +010030#include <linux/of_platform.h>
Tony Lindgrene639cd52014-11-20 12:11:25 -080031#include <linux/omap-gpmc.h>
Daniel Mackbc6b1e72012-12-14 11:36:44 +010032#include <linux/mtd/nand.h>
avinash philipb3f55252013-06-12 16:30:56 +053033#include <linux/pm_runtime.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070034
Afzal Mohammedbc3668e2012-09-29 12:26:13 +053035#include <linux/platform_data/mtd-nand-omap2.h>
Tony Lindgrene639cd52014-11-20 12:11:25 -080036#include <linux/platform_data/mtd-onenand-omap2.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070037
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070038#include <asm/mach-types.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070039
Afzal Mohammed4be48fd2012-09-23 17:28:24 -060040#define DEVICE_NAME "omap-gpmc"
41
Paul Walmsleyfd1dc872008-10-06 15:49:17 +030042/* GPMC register offsets */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070043#define GPMC_REVISION 0x00
44#define GPMC_SYSCONFIG 0x10
45#define GPMC_SYSSTATUS 0x14
46#define GPMC_IRQSTATUS 0x18
47#define GPMC_IRQENABLE 0x1c
48#define GPMC_TIMEOUT_CONTROL 0x40
49#define GPMC_ERR_ADDRESS 0x44
50#define GPMC_ERR_TYPE 0x48
51#define GPMC_CONFIG 0x50
52#define GPMC_STATUS 0x54
53#define GPMC_PREFETCH_CONFIG1 0x1e0
54#define GPMC_PREFETCH_CONFIG2 0x1e4
Thara Gopinath15e02a32008-04-28 16:55:01 +053055#define GPMC_PREFETCH_CONTROL 0x1ec
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070056#define GPMC_PREFETCH_STATUS 0x1f0
57#define GPMC_ECC_CONFIG 0x1f4
58#define GPMC_ECC_CONTROL 0x1f8
59#define GPMC_ECC_SIZE_CONFIG 0x1fc
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000060#define GPMC_ECC1_RESULT 0x200
Ivan Djelic8d602cf2012-04-26 14:17:49 +020061#define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053062#define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
63#define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
64#define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
pekon gupta27c9fd62014-05-19 13:24:39 +053065#define GPMC_ECC_BCH_RESULT_4 0x300 /* not available on OMAP2 */
66#define GPMC_ECC_BCH_RESULT_5 0x304 /* not available on OMAP2 */
67#define GPMC_ECC_BCH_RESULT_6 0x308 /* not available on OMAP2 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070068
Yegor Yefremov2c65e742012-05-09 08:32:49 -070069/* GPMC ECC control settings */
70#define GPMC_ECC_CTRL_ECCCLEAR 0x100
71#define GPMC_ECC_CTRL_ECCDISABLE 0x000
72#define GPMC_ECC_CTRL_ECCREG1 0x001
73#define GPMC_ECC_CTRL_ECCREG2 0x002
74#define GPMC_ECC_CTRL_ECCREG3 0x003
75#define GPMC_ECC_CTRL_ECCREG4 0x004
76#define GPMC_ECC_CTRL_ECCREG5 0x005
77#define GPMC_ECC_CTRL_ECCREG6 0x006
78#define GPMC_ECC_CTRL_ECCREG7 0x007
79#define GPMC_ECC_CTRL_ECCREG8 0x008
80#define GPMC_ECC_CTRL_ECCREG9 0x009
81
Roger Quadrose378d222014-08-29 19:11:52 +030082#define GPMC_CONFIG_LIMITEDADDRESS BIT(1)
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
Tony Lindgrene639cd52014-11-20 12:11:25 -0800113#define GPMC_CS_CONFIG1 0x00
114#define GPMC_CS_CONFIG2 0x04
115#define GPMC_CS_CONFIG3 0x08
116#define GPMC_CS_CONFIG4 0x0c
117#define GPMC_CS_CONFIG5 0x10
118#define GPMC_CS_CONFIG6 0x14
119#define GPMC_CS_CONFIG7 0x18
120#define GPMC_CS_NAND_COMMAND 0x1c
121#define GPMC_CS_NAND_ADDRESS 0x20
122#define GPMC_CS_NAND_DATA 0x24
123
124/* Control Commands */
125#define GPMC_CONFIG_RDY_BSY 0x00000001
126#define GPMC_CONFIG_DEV_SIZE 0x00000002
127#define GPMC_CONFIG_DEV_TYPE 0x00000003
128#define GPMC_SET_IRQ_STATUS 0x00000004
129
130#define GPMC_CONFIG1_WRAPBURST_SUPP (1 << 31)
131#define GPMC_CONFIG1_READMULTIPLE_SUPP (1 << 30)
132#define GPMC_CONFIG1_READTYPE_ASYNC (0 << 29)
133#define GPMC_CONFIG1_READTYPE_SYNC (1 << 29)
134#define GPMC_CONFIG1_WRITEMULTIPLE_SUPP (1 << 28)
135#define GPMC_CONFIG1_WRITETYPE_ASYNC (0 << 27)
136#define GPMC_CONFIG1_WRITETYPE_SYNC (1 << 27)
137#define GPMC_CONFIG1_CLKACTIVATIONTIME(val) ((val & 3) << 25)
138#define GPMC_CONFIG1_PAGE_LEN(val) ((val & 3) << 23)
139#define GPMC_CONFIG1_WAIT_READ_MON (1 << 22)
140#define GPMC_CONFIG1_WAIT_WRITE_MON (1 << 21)
141#define GPMC_CONFIG1_WAIT_MON_IIME(val) ((val & 3) << 18)
142#define GPMC_CONFIG1_WAIT_PIN_SEL(val) ((val & 3) << 16)
143#define GPMC_CONFIG1_DEVICESIZE(val) ((val & 3) << 12)
144#define GPMC_CONFIG1_DEVICESIZE_16 GPMC_CONFIG1_DEVICESIZE(1)
145#define GPMC_CONFIG1_DEVICETYPE(val) ((val & 3) << 10)
146#define GPMC_CONFIG1_DEVICETYPE_NOR GPMC_CONFIG1_DEVICETYPE(0)
147#define GPMC_CONFIG1_MUXTYPE(val) ((val & 3) << 8)
148#define GPMC_CONFIG1_TIME_PARA_GRAN (1 << 4)
149#define GPMC_CONFIG1_FCLK_DIV(val) (val & 3)
150#define GPMC_CONFIG1_FCLK_DIV2 (GPMC_CONFIG1_FCLK_DIV(1))
151#define GPMC_CONFIG1_FCLK_DIV3 (GPMC_CONFIG1_FCLK_DIV(2))
152#define GPMC_CONFIG1_FCLK_DIV4 (GPMC_CONFIG1_FCLK_DIV(3))
153#define GPMC_CONFIG7_CSVALID (1 << 6)
154
Semen Protsenko9c4f7572015-01-24 22:28:38 +0200155#define GPMC_CONFIG7_BASEADDRESS_MASK 0x3f
156#define GPMC_CONFIG7_CSVALID_MASK BIT(6)
157#define GPMC_CONFIG7_MASKADDRESS_OFFSET 8
158#define GPMC_CONFIG7_MASKADDRESS_MASK (0xf << GPMC_CONFIG7_MASKADDRESS_OFFSET)
159/* All CONFIG7 bits except reserved bits */
160#define GPMC_CONFIG7_MASK (GPMC_CONFIG7_BASEADDRESS_MASK | \
161 GPMC_CONFIG7_CSVALID_MASK | \
162 GPMC_CONFIG7_MASKADDRESS_MASK)
163
Tony Lindgrene639cd52014-11-20 12:11:25 -0800164#define GPMC_DEVICETYPE_NOR 0
165#define GPMC_DEVICETYPE_NAND 2
166#define GPMC_CONFIG_WRITEPROTECT 0x00000010
167#define WR_RD_PIN_MONITORING 0x00600000
168
169#define GPMC_ENABLE_IRQ 0x0000000d
170
171/* ECC commands */
172#define GPMC_ECC_READ 0 /* Reset Hardware ECC for read */
173#define GPMC_ECC_WRITE 1 /* Reset Hardware ECC for write */
174#define GPMC_ECC_READSYN 2 /* Reset before syndrom is read back */
175
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700176/* XXX: Only NAND irq has been considered,currently these are the only ones used
177 */
178#define GPMC_NR_IRQ 2
179
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800180struct gpmc_cs_data {
181 const char *name;
182
183#define GPMC_CS_RESERVED (1 << 0)
184 u32 flags;
185
186 struct resource mem;
187};
188
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700189struct gpmc_client_irq {
190 unsigned irq;
191 u32 bitmask;
192};
193
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530194/* Structure to save gpmc cs context */
195struct gpmc_cs_config {
196 u32 config1;
197 u32 config2;
198 u32 config3;
199 u32 config4;
200 u32 config5;
201 u32 config6;
202 u32 config7;
203 int is_valid;
204};
205
206/*
207 * Structure to save/restore gpmc context
208 * to support core off on OMAP3
209 */
210struct omap3_gpmc_regs {
211 u32 sysconfig;
212 u32 irqenable;
213 u32 timeout_ctrl;
214 u32 config;
215 u32 prefetch_config1;
216 u32 prefetch_config2;
217 u32 prefetch_control;
218 struct gpmc_cs_config cs_context[GPMC_CS_NUM];
219};
220
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700221static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
222static struct irq_chip gpmc_irq_chip;
Chen Gangaf072192013-08-22 15:47:21 +0800223static int gpmc_irq_start;
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700224
Imre Deakf37e4582006-09-25 12:41:33 +0300225static struct resource gpmc_mem_root;
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800226static struct gpmc_cs_data gpmc_cs[GPMC_CS_NUM];
Thomas Gleixner87b247c2007-05-10 22:33:04 -0700227static DEFINE_SPINLOCK(gpmc_mem_lock);
Jon Hunter6797b4f2013-02-01 10:38:45 -0600228/* Define chip-selects as reserved by default until probe completes */
Gupta Pekonf34f3712013-05-31 17:31:30 +0530229static unsigned int gpmc_cs_num = GPMC_CS_NUM;
Jon Hunter9f833152013-02-20 15:53:38 -0600230static unsigned int gpmc_nr_waitpins;
Afzal Mohammedda496872012-09-23 17:28:25 -0600231static struct device *gpmc_dev;
232static int gpmc_irq;
233static resource_size_t phys_base, mem_size;
234static unsigned gpmc_capability;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300235static void __iomem *gpmc_base;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700236
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300237static struct clk *gpmc_l3_clk;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700238
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530239static irqreturn_t gpmc_handle_irq(int irq, void *dev);
240
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700241static void gpmc_write_reg(int idx, u32 val)
242{
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300243 writel_relaxed(val, gpmc_base + idx);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700244}
245
246static u32 gpmc_read_reg(int idx)
247{
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300248 return readl_relaxed(gpmc_base + idx);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700249}
250
251void gpmc_cs_write_reg(int cs, int idx, u32 val)
252{
253 void __iomem *reg_addr;
254
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000255 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300256 writel_relaxed(val, reg_addr);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700257}
258
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300259static u32 gpmc_cs_read_reg(int cs, int idx)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700260{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300261 void __iomem *reg_addr;
262
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000263 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300264 return readl_relaxed(reg_addr);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700265}
266
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300267/* TODO: Add support for gpmc_fck to clock framework and use it */
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300268static unsigned long gpmc_get_fclk_period(void)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700269{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300270 unsigned long rate = clk_get_rate(gpmc_l3_clk);
271
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300272 rate /= 1000;
273 rate = 1000000000 / rate; /* In picoseconds */
274
275 return rate;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700276}
277
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300278static unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700279{
280 unsigned long tick_ps;
281
282 /* Calculate in picosecs to yield more exact results */
283 tick_ps = gpmc_get_fclk_period();
284
285 return (time_ns * 1000 + tick_ps - 1) / tick_ps;
286}
287
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300288static unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
Adrian Huntera3551f52010-12-09 10:48:27 +0200289{
290 unsigned long tick_ps;
291
292 /* Calculate in picosecs to yield more exact results */
293 tick_ps = gpmc_get_fclk_period();
294
295 return (time_ps + tick_ps - 1) / tick_ps;
296}
297
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300298unsigned int gpmc_ticks_to_ns(unsigned int ticks)
299{
300 return ticks * gpmc_get_fclk_period() / 1000;
301}
302
Afzal Mohammed246da262012-08-02 20:02:10 +0530303static unsigned int gpmc_ticks_to_ps(unsigned int ticks)
304{
305 return ticks * gpmc_get_fclk_period();
306}
307
308static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps)
309{
310 unsigned long ticks = gpmc_ps_to_ticks(time_ps);
311
312 return ticks * gpmc_get_fclk_period();
313}
314
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530315static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value)
316{
317 u32 l;
318
319 l = gpmc_cs_read_reg(cs, reg);
320 if (value)
321 l |= mask;
322 else
323 l &= ~mask;
324 gpmc_cs_write_reg(cs, reg, l);
325}
326
327static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
328{
329 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1,
330 GPMC_CONFIG1_TIME_PARA_GRAN,
331 p->time_para_granularity);
332 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2,
333 GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay);
334 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3,
335 GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay);
336 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
337 GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay);
338 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
339 GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay);
340 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
341 GPMC_CONFIG6_CYCLE2CYCLESAMECSEN,
342 p->cycle2cyclesamecsen);
343 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
344 GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN,
345 p->cycle2cyclediffcsen);
346}
347
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700348#ifdef DEBUG
Tony Lindgren35ac0512014-11-03 17:45:01 -0800349static int get_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
350 bool raw, bool noval, int shift,
351 const char *name)
352{
353 u32 l;
354 int nr_bits, max_value, mask;
355
356 l = gpmc_cs_read_reg(cs, reg);
357 nr_bits = end_bit - st_bit + 1;
358 max_value = (1 << nr_bits) - 1;
359 mask = max_value << st_bit;
360 l = (l & mask) >> st_bit;
361 if (shift)
362 l = (shift << l);
363 if (noval && (l == 0))
364 return 0;
365 if (!raw) {
366 unsigned int time_ns_min, time_ns, time_ns_max;
367
368 time_ns_min = gpmc_ticks_to_ns(l ? l - 1 : 0);
369 time_ns = gpmc_ticks_to_ns(l);
370 time_ns_max = gpmc_ticks_to_ns(l + 1 > max_value ?
371 max_value : l + 1);
372 pr_info("gpmc,%s = <%u> (%u - %u ns, %i ticks)\n",
373 name, time_ns, time_ns_min, time_ns_max, l);
374 } else {
375 pr_info("gpmc,%s = <%u>\n", name, l);
376 }
377
378 return l;
379}
380
381#define GPMC_PRINT_CONFIG(cs, config) \
382 pr_info("cs%i %s: 0x%08x\n", cs, #config, \
383 gpmc_cs_read_reg(cs, config))
384#define GPMC_GET_RAW(reg, st, end, field) \
385 get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 0, 0, field)
386#define GPMC_GET_RAW_BOOL(reg, st, end, field) \
387 get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, 0, field)
388#define GPMC_GET_RAW_SHIFT(reg, st, end, shift, field) \
389 get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, (shift), field)
390#define GPMC_GET_TICKS(reg, st, end, field) \
391 get_gpmc_timing_reg(cs, (reg), (st), (end), 0, 0, 0, field)
392
393static void gpmc_show_regs(int cs, const char *desc)
394{
395 pr_info("gpmc cs%i %s:\n", cs, desc);
396 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG1);
397 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG2);
398 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG3);
399 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG4);
400 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG5);
401 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG6);
402}
403
404/*
405 * Note that gpmc,wait-pin handing wrongly assumes bit 8 is available,
406 * see commit c9fb809.
407 */
408static void gpmc_cs_show_timings(int cs, const char *desc)
409{
410 gpmc_show_regs(cs, desc);
411
412 pr_info("gpmc cs%i access configuration:\n", cs);
413 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 4, 4, "time-para-granularity");
414 GPMC_GET_RAW(GPMC_CS_CONFIG1, 8, 9, "mux-add-data");
415 GPMC_GET_RAW(GPMC_CS_CONFIG1, 12, 13, "device-width");
416 GPMC_GET_RAW(GPMC_CS_CONFIG1, 16, 17, "wait-pin");
417 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 21, 21, "wait-on-write");
418 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 22, 22, "wait-on-read");
419 GPMC_GET_RAW_SHIFT(GPMC_CS_CONFIG1, 23, 24, 4, "burst-length");
420 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 27, 27, "sync-write");
421 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 28, 28, "burst-write");
422 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 29, 29, "gpmc,sync-read");
423 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 30, 30, "burst-read");
424 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 31, 31, "burst-wrap");
425
426 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay");
427
428 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG3, 7, 7, "adv-extra-delay");
429
430 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 23, 23, "we-extra-delay");
431 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 7, 7, "oe-extra-delay");
432
433 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 7, 7, "cycle2cycle-samecsen");
434 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 6, 6, "cycle2cycle-diffcsen");
435
436 pr_info("gpmc cs%i timings configuration:\n", cs);
437 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns");
438 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns");
439 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns");
440
441 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 0, 3, "adv-on-ns");
442 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 8, 12, "adv-rd-off-ns");
443 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 16, 20, "adv-wr-off-ns");
444
445 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 0, 3, "oe-on-ns");
446 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 8, 12, "oe-off-ns");
447 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 16, 19, "we-on-ns");
448 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 24, 28, "we-off-ns");
449
450 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 0, 4, "rd-cycle-ns");
451 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 8, 12, "wr-cycle-ns");
452 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 16, 20, "access-ns");
453
454 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 24, 27, "page-burst-access-ns");
455
456 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 0, 3, "bus-turnaround-ns");
457 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 8, 11, "cycle2cycle-delay-ns");
458
459 GPMC_GET_TICKS(GPMC_CS_CONFIG1, 18, 19, "wait-monitoring-ns");
460 GPMC_GET_TICKS(GPMC_CS_CONFIG1, 25, 26, "clk-activation-ns");
461
462 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 16, 19, "wr-data-mux-bus-ns");
463 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 24, 28, "wr-access-ns");
464}
465#else
466static inline void gpmc_cs_show_timings(int cs, const char *desc)
467{
468}
469#endif
470
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700471static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
Juha Yrjola2aab6462006-06-26 16:16:21 -0700472 int time, const char *name)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700473{
474 u32 l;
475 int ticks, mask, nr_bits;
476
477 if (time == 0)
478 ticks = 0;
479 else
480 ticks = gpmc_ns_to_ticks(time);
481 nr_bits = end_bit - st_bit + 1;
Roger Quadros80323742014-08-29 19:11:50 +0300482 mask = (1 << nr_bits) - 1;
483
484 if (ticks > mask) {
485 pr_err("%s: GPMC error! CS%d: %s: %d ns, %d ticks > %d\n",
486 __func__, cs, name, time, ticks, mask);
487
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700488 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800489 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700490
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700491 l = gpmc_cs_read_reg(cs, reg);
492#ifdef DEBUG
David Brownell1c22cc12006-12-06 17:13:55 -0800493 printk(KERN_INFO
Robert ABEL2affc812015-02-27 16:56:50 +0100494 "GPMC CS%d: %-17s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n",
Juha Yrjola2aab6462006-06-26 16:16:21 -0700495 cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000,
David Brownell1c22cc12006-12-06 17:13:55 -0800496 (l >> st_bit) & mask, time);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700497#endif
498 l &= ~(mask << st_bit);
499 l |= ticks << st_bit;
500 gpmc_cs_write_reg(cs, reg, l);
501
502 return 0;
503}
504
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700505#define GPMC_SET_ONE(reg, st, end, field) \
506 if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
507 t->field, #field) < 0) \
508 return -1
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700509
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530510int gpmc_calc_divider(unsigned int sync_clk)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700511{
512 int div;
513 u32 l;
514
Adrian Huntera3551f52010-12-09 10:48:27 +0200515 l = sync_clk + (gpmc_get_fclk_period() - 1);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700516 div = l / gpmc_get_fclk_period();
517 if (div > 4)
518 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800519 if (div <= 0)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700520 div = 1;
521
522 return div;
523}
524
525int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
526{
527 int div;
528 u32 l;
529
Tony Lindgren35ac0512014-11-03 17:45:01 -0800530 gpmc_cs_show_timings(cs, "before gpmc_cs_set_timings");
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530531 div = gpmc_calc_divider(t->sync_clk);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700532 if (div < 0)
Paul Walmsleya032d332012-08-03 09:21:10 -0600533 return div;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700534
535 GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
536 GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
537 GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
538
539 GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on);
540 GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off);
541 GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
542
543 GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on);
544 GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off);
545 GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
546 GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
547
548 GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle);
549 GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle);
550 GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
551
552 GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
553
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530554 GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
555 GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
556
557 GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring);
558 GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation);
559
Afzal Mohammedda496872012-09-23 17:28:25 -0600560 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300561 GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
Afzal Mohammedda496872012-09-23 17:28:25 -0600562 if (gpmc_capability & GPMC_HAS_WR_ACCESS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300563 GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300564
David Brownell1c22cc12006-12-06 17:13:55 -0800565 /* caller is expected to have initialized CONFIG1 to cover
566 * at least sync vs async
567 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700568 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
David Brownell1c22cc12006-12-06 17:13:55 -0800569 if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) {
570#ifdef DEBUG
571 printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n",
572 cs, (div * gpmc_get_fclk_period()) / 1000, div);
573#endif
574 l &= ~0x03;
575 l |= (div - 1);
576 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
577 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700578
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530579 gpmc_cs_bool_timings(cs, &t->bool_timings);
Tony Lindgren35ac0512014-11-03 17:45:01 -0800580 gpmc_cs_show_timings(cs, "after gpmc_cs_set_timings");
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530581
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700582 return 0;
583}
584
Roger Quadros4cf27d22014-08-29 19:11:53 +0300585static int gpmc_cs_set_memconf(int cs, u32 base, u32 size)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700586{
Imre Deakf37e4582006-09-25 12:41:33 +0300587 u32 l;
588 u32 mask;
589
Jon Hunterc71f8e92013-03-06 12:00:10 -0600590 /*
591 * Ensure that base address is aligned on a
592 * boundary equal to or greater than size.
593 */
594 if (base & (size - 1))
595 return -EINVAL;
596
Semen Protsenko9c4f7572015-01-24 22:28:38 +0200597 base >>= GPMC_CHUNK_SHIFT;
Imre Deakf37e4582006-09-25 12:41:33 +0300598 mask = (1 << GPMC_SECTION_SHIFT) - size;
Semen Protsenko9c4f7572015-01-24 22:28:38 +0200599 mask >>= GPMC_CHUNK_SHIFT;
600 mask <<= GPMC_CONFIG7_MASKADDRESS_OFFSET;
601
Imre Deakf37e4582006-09-25 12:41:33 +0300602 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Semen Protsenko9c4f7572015-01-24 22:28:38 +0200603 l &= ~GPMC_CONFIG7_MASK;
604 l |= base & GPMC_CONFIG7_BASEADDRESS_MASK;
605 l |= mask & GPMC_CONFIG7_MASKADDRESS_MASK;
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530606 l |= GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300607 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
Jon Hunterc71f8e92013-03-06 12:00:10 -0600608
609 return 0;
Imre Deakf37e4582006-09-25 12:41:33 +0300610}
611
Roger Quadros4cf27d22014-08-29 19:11:53 +0300612static void gpmc_cs_enable_mem(int cs)
613{
614 u32 l;
615
616 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
617 l |= GPMC_CONFIG7_CSVALID;
618 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
619}
620
Imre Deakf37e4582006-09-25 12:41:33 +0300621static void gpmc_cs_disable_mem(int cs)
622{
623 u32 l;
624
625 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530626 l &= ~GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300627 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
628}
629
630static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size)
631{
632 u32 l;
633 u32 mask;
634
635 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
636 *base = (l & 0x3f) << GPMC_CHUNK_SHIFT;
637 mask = (l >> 8) & 0x0f;
638 *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT);
639}
640
641static int gpmc_cs_mem_enabled(int cs)
642{
643 u32 l;
644
645 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530646 return l & GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300647}
648
Ezequiel Garciaf5d8eda2013-02-12 16:22:24 -0300649static void gpmc_cs_set_reserved(int cs, int reserved)
Imre Deakf37e4582006-09-25 12:41:33 +0300650{
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800651 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
652
653 gpmc->flags |= GPMC_CS_RESERVED;
Imre Deakf37e4582006-09-25 12:41:33 +0300654}
655
Ezequiel Garciaae9d9082013-02-12 16:22:19 -0300656static bool gpmc_cs_reserved(int cs)
Imre Deakf37e4582006-09-25 12:41:33 +0300657{
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800658 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
659
660 return gpmc->flags & GPMC_CS_RESERVED;
661}
662
663static void gpmc_cs_set_name(int cs, const char *name)
664{
665 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
666
667 gpmc->name = name;
668}
669
Semen Protsenko2e25b0e2015-01-24 22:28:39 +0200670static const char *gpmc_cs_get_name(int cs)
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800671{
672 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
673
674 return gpmc->name;
Imre Deakf37e4582006-09-25 12:41:33 +0300675}
676
677static unsigned long gpmc_mem_align(unsigned long size)
678{
679 int order;
680
681 size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1);
682 order = GPMC_CHUNK_SHIFT - 1;
683 do {
684 size >>= 1;
685 order++;
686 } while (size);
687 size = 1 << order;
688 return size;
689}
690
691static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
692{
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800693 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
694 struct resource *res = &gpmc->mem;
Imre Deakf37e4582006-09-25 12:41:33 +0300695 int r;
696
697 size = gpmc_mem_align(size);
698 spin_lock(&gpmc_mem_lock);
699 res->start = base;
700 res->end = base + size - 1;
701 r = request_resource(&gpmc_mem_root, res);
702 spin_unlock(&gpmc_mem_lock);
703
704 return r;
705}
706
Afzal Mohammedda496872012-09-23 17:28:25 -0600707static int gpmc_cs_delete_mem(int cs)
708{
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800709 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
710 struct resource *res = &gpmc->mem;
Afzal Mohammedda496872012-09-23 17:28:25 -0600711 int r;
712
713 spin_lock(&gpmc_mem_lock);
Tony Lindgrenefe80722014-04-21 19:26:13 -0700714 r = release_resource(res);
Afzal Mohammedda496872012-09-23 17:28:25 -0600715 res->start = 0;
716 res->end = 0;
717 spin_unlock(&gpmc_mem_lock);
718
719 return r;
720}
721
Jon Huntercdd69282013-02-08 16:46:13 -0600722/**
723 * gpmc_cs_remap - remaps a chip-select physical base address
724 * @cs: chip-select to remap
725 * @base: physical base address to re-map chip-select to
726 *
727 * Re-maps a chip-select to a new physical base address specified by
728 * "base". Returns 0 on success and appropriate negative error code
729 * on failure.
730 */
731static int gpmc_cs_remap(int cs, u32 base)
732{
733 int ret;
734 u32 old_base, size;
735
Gupta Pekonf34f3712013-05-31 17:31:30 +0530736 if (cs > gpmc_cs_num) {
737 pr_err("%s: requested chip-select is disabled\n", __func__);
Jon Huntercdd69282013-02-08 16:46:13 -0600738 return -ENODEV;
Gupta Pekonf34f3712013-05-31 17:31:30 +0530739 }
Tony Lindgrenfb677ef2014-04-21 19:26:13 -0700740
741 /*
742 * Make sure we ignore any device offsets from the GPMC partition
743 * allocated for the chip select and that the new base confirms
744 * to the GPMC 16MB minimum granularity.
745 */
746 base &= ~(SZ_16M - 1);
747
Jon Huntercdd69282013-02-08 16:46:13 -0600748 gpmc_cs_get_memconf(cs, &old_base, &size);
749 if (base == old_base)
750 return 0;
Roger Quadros4cf27d22014-08-29 19:11:53 +0300751
Jon Huntercdd69282013-02-08 16:46:13 -0600752 ret = gpmc_cs_delete_mem(cs);
753 if (ret < 0)
754 return ret;
Roger Quadros4cf27d22014-08-29 19:11:53 +0300755
Jon Huntercdd69282013-02-08 16:46:13 -0600756 ret = gpmc_cs_insert_mem(cs, base, size);
757 if (ret < 0)
758 return ret;
Jon Huntercdd69282013-02-08 16:46:13 -0600759
Roger Quadros4cf27d22014-08-29 19:11:53 +0300760 ret = gpmc_cs_set_memconf(cs, base, size);
761
762 return ret;
Jon Huntercdd69282013-02-08 16:46:13 -0600763}
764
Imre Deakf37e4582006-09-25 12:41:33 +0300765int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
766{
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800767 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
768 struct resource *res = &gpmc->mem;
Imre Deakf37e4582006-09-25 12:41:33 +0300769 int r = -1;
770
Gupta Pekonf34f3712013-05-31 17:31:30 +0530771 if (cs > gpmc_cs_num) {
772 pr_err("%s: requested chip-select is disabled\n", __func__);
Imre Deakf37e4582006-09-25 12:41:33 +0300773 return -ENODEV;
Gupta Pekonf34f3712013-05-31 17:31:30 +0530774 }
Imre Deakf37e4582006-09-25 12:41:33 +0300775 size = gpmc_mem_align(size);
776 if (size > (1 << GPMC_SECTION_SHIFT))
777 return -ENOMEM;
778
779 spin_lock(&gpmc_mem_lock);
780 if (gpmc_cs_reserved(cs)) {
781 r = -EBUSY;
782 goto out;
783 }
784 if (gpmc_cs_mem_enabled(cs))
785 r = adjust_resource(res, res->start & ~(size - 1), size);
786 if (r < 0)
787 r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
788 size, NULL, NULL);
789 if (r < 0)
790 goto out;
791
Roger Quadros4cf27d22014-08-29 19:11:53 +0300792 /* Disable CS while changing base address and size mask */
793 gpmc_cs_disable_mem(cs);
794
795 r = gpmc_cs_set_memconf(cs, res->start, resource_size(res));
Jon Hunterc71f8e92013-03-06 12:00:10 -0600796 if (r < 0) {
797 release_resource(res);
798 goto out;
799 }
800
Roger Quadros4cf27d22014-08-29 19:11:53 +0300801 /* Enable CS */
802 gpmc_cs_enable_mem(cs);
Imre Deakf37e4582006-09-25 12:41:33 +0300803 *base = res->start;
804 gpmc_cs_set_reserved(cs, 1);
805out:
806 spin_unlock(&gpmc_mem_lock);
807 return r;
808}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300809EXPORT_SYMBOL(gpmc_cs_request);
Imre Deakf37e4582006-09-25 12:41:33 +0300810
811void gpmc_cs_free(int cs)
812{
Tony Lindgren9ed7a772014-11-03 17:45:01 -0800813 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
814 struct resource *res = &gpmc->mem;
Tony Lindgrenefe80722014-04-21 19:26:13 -0700815
Imre Deakf37e4582006-09-25 12:41:33 +0300816 spin_lock(&gpmc_mem_lock);
Gupta Pekonf34f3712013-05-31 17:31:30 +0530817 if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) {
Imre Deakf37e4582006-09-25 12:41:33 +0300818 printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
819 BUG();
820 spin_unlock(&gpmc_mem_lock);
821 return;
822 }
823 gpmc_cs_disable_mem(cs);
Tony Lindgrenefe80722014-04-21 19:26:13 -0700824 if (res->flags)
825 release_resource(res);
Imre Deakf37e4582006-09-25 12:41:33 +0300826 gpmc_cs_set_reserved(cs, 0);
827 spin_unlock(&gpmc_mem_lock);
828}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300829EXPORT_SYMBOL(gpmc_cs_free);
Imre Deakf37e4582006-09-25 12:41:33 +0300830
vimal singh59e9c5a2009-07-13 16:26:24 +0530831/**
Jon Hunter3a544352013-02-21 13:00:21 -0600832 * gpmc_configure - write request to configure gpmc
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000833 * @cmd: command type
834 * @wval: value to write
835 * @return status of the operation
836 */
Jon Hunter3a544352013-02-21 13:00:21 -0600837int gpmc_configure(int cmd, int wval)
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000838{
Jon Hunter3a544352013-02-21 13:00:21 -0600839 u32 regval;
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000840
841 switch (cmd) {
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530842 case GPMC_ENABLE_IRQ:
843 gpmc_write_reg(GPMC_IRQENABLE, wval);
844 break;
845
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000846 case GPMC_SET_IRQ_STATUS:
847 gpmc_write_reg(GPMC_IRQSTATUS, wval);
848 break;
849
850 case GPMC_CONFIG_WP:
851 regval = gpmc_read_reg(GPMC_CONFIG);
852 if (wval)
853 regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
854 else
855 regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
856 gpmc_write_reg(GPMC_CONFIG, regval);
857 break;
858
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000859 default:
Jon Hunter3a544352013-02-21 13:00:21 -0600860 pr_err("%s: command not supported\n", __func__);
861 return -EINVAL;
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000862 }
863
Jon Hunter3a544352013-02-21 13:00:21 -0600864 return 0;
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000865}
Jon Hunter3a544352013-02-21 13:00:21 -0600866EXPORT_SYMBOL(gpmc_configure);
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000867
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700868void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
869{
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530870 int i;
871
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700872 reg->gpmc_status = gpmc_base + GPMC_STATUS;
873 reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
874 GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
875 reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
876 GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
877 reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
878 GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
879 reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
880 reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
881 reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
882 reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
883 reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
884 reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
885 reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
886 reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530887
888 for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
889 reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
890 GPMC_BCH_SIZE * i;
891 reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
892 GPMC_BCH_SIZE * i;
893 reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
894 GPMC_BCH_SIZE * i;
895 reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
896 GPMC_BCH_SIZE * i;
pekon gupta27c9fd62014-05-19 13:24:39 +0530897 reg->gpmc_bch_result4[i] = gpmc_base + GPMC_ECC_BCH_RESULT_4 +
898 i * GPMC_BCH_SIZE;
899 reg->gpmc_bch_result5[i] = gpmc_base + GPMC_ECC_BCH_RESULT_5 +
900 i * GPMC_BCH_SIZE;
901 reg->gpmc_bch_result6[i] = gpmc_base + GPMC_ECC_BCH_RESULT_6 +
902 i * GPMC_BCH_SIZE;
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530903 }
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700904}
905
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700906int gpmc_get_client_irq(unsigned irq_config)
907{
908 int i;
909
910 if (hweight32(irq_config) > 1)
911 return 0;
912
913 for (i = 0; i < GPMC_NR_IRQ; i++)
914 if (gpmc_client_irq[i].bitmask & irq_config)
915 return gpmc_client_irq[i].irq;
916
917 return 0;
918}
919
920static int gpmc_irq_endis(unsigned irq, bool endis)
921{
922 int i;
923 u32 regval;
924
925 for (i = 0; i < GPMC_NR_IRQ; i++)
926 if (irq == gpmc_client_irq[i].irq) {
927 regval = gpmc_read_reg(GPMC_IRQENABLE);
928 if (endis)
929 regval |= gpmc_client_irq[i].bitmask;
930 else
931 regval &= ~gpmc_client_irq[i].bitmask;
932 gpmc_write_reg(GPMC_IRQENABLE, regval);
933 break;
934 }
935
936 return 0;
937}
938
939static void gpmc_irq_disable(struct irq_data *p)
940{
941 gpmc_irq_endis(p->irq, false);
942}
943
944static void gpmc_irq_enable(struct irq_data *p)
945{
946 gpmc_irq_endis(p->irq, true);
947}
948
949static void gpmc_irq_noop(struct irq_data *data) { }
950
951static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
952
Afzal Mohammedda496872012-09-23 17:28:25 -0600953static int gpmc_setup_irq(void)
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700954{
955 int i;
956 u32 regval;
957
958 if (!gpmc_irq)
959 return -EINVAL;
960
961 gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
Russell King71856842013-03-13 20:44:21 +0000962 if (gpmc_irq_start < 0) {
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700963 pr_err("irq_alloc_descs failed\n");
964 return gpmc_irq_start;
965 }
966
967 gpmc_irq_chip.name = "gpmc";
968 gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
969 gpmc_irq_chip.irq_enable = gpmc_irq_enable;
970 gpmc_irq_chip.irq_disable = gpmc_irq_disable;
971 gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
972 gpmc_irq_chip.irq_ack = gpmc_irq_noop;
973 gpmc_irq_chip.irq_mask = gpmc_irq_noop;
974 gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
975
976 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
977 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
978
979 for (i = 0; i < GPMC_NR_IRQ; i++) {
980 gpmc_client_irq[i].irq = gpmc_irq_start + i;
981 irq_set_chip_and_handler(gpmc_client_irq[i].irq,
982 &gpmc_irq_chip, handle_simple_irq);
983 set_irq_flags(gpmc_client_irq[i].irq,
984 IRQF_VALID | IRQF_NOAUTOEN);
985 }
986
987 /* Disable interrupts */
988 gpmc_write_reg(GPMC_IRQENABLE, 0);
989
990 /* clear interrupts */
991 regval = gpmc_read_reg(GPMC_IRQSTATUS);
992 gpmc_write_reg(GPMC_IRQSTATUS, regval);
993
994 return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
995}
996
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800997static int gpmc_free_irq(void)
Afzal Mohammedda496872012-09-23 17:28:25 -0600998{
999 int i;
1000
1001 if (gpmc_irq)
1002 free_irq(gpmc_irq, NULL);
1003
1004 for (i = 0; i < GPMC_NR_IRQ; i++) {
1005 irq_set_handler(gpmc_client_irq[i].irq, NULL);
1006 irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
1007 irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
1008 }
1009
1010 irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
1011
1012 return 0;
1013}
1014
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001015static void gpmc_mem_exit(void)
Afzal Mohammedda496872012-09-23 17:28:25 -06001016{
1017 int cs;
1018
Gupta Pekonf34f3712013-05-31 17:31:30 +05301019 for (cs = 0; cs < gpmc_cs_num; cs++) {
Afzal Mohammedda496872012-09-23 17:28:25 -06001020 if (!gpmc_cs_mem_enabled(cs))
1021 continue;
1022 gpmc_cs_delete_mem(cs);
1023 }
1024
1025}
1026
Jon Hunter84b00f02013-03-06 14:36:47 -06001027static void gpmc_mem_init(void)
Imre Deakf37e4582006-09-25 12:41:33 +03001028{
Jon Hunter84b00f02013-03-06 14:36:47 -06001029 int cs;
Imre Deakf37e4582006-09-25 12:41:33 +03001030
Jon Hunterbf234392013-03-06 14:12:59 -06001031 /*
1032 * The first 1MB of GPMC address space is typically mapped to
1033 * the internal ROM. Never allocate the first page, to
1034 * facilitate bug detection; even if we didn't boot from ROM.
Kyungmin Park7f245162006-12-29 16:48:51 -08001035 */
Jon Hunterbf234392013-03-06 14:12:59 -06001036 gpmc_mem_root.start = SZ_1M;
Imre Deakf37e4582006-09-25 12:41:33 +03001037 gpmc_mem_root.end = GPMC_MEM_END;
1038
1039 /* Reserve all regions that has been set up by bootloader */
Gupta Pekonf34f3712013-05-31 17:31:30 +05301040 for (cs = 0; cs < gpmc_cs_num; cs++) {
Imre Deakf37e4582006-09-25 12:41:33 +03001041 u32 base, size;
1042
1043 if (!gpmc_cs_mem_enabled(cs))
1044 continue;
1045 gpmc_cs_get_memconf(cs, &base, &size);
Jon Hunter84b00f02013-03-06 14:36:47 -06001046 if (gpmc_cs_insert_mem(cs, base, size)) {
1047 pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n",
1048 __func__, cs, base, base + size);
1049 gpmc_cs_disable_mem(cs);
Jon Hunter81190242012-10-17 09:41:25 -05001050 }
Imre Deakf37e4582006-09-25 12:41:33 +03001051 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001052}
1053
Afzal Mohammed246da262012-08-02 20:02:10 +05301054static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk)
1055{
1056 u32 temp;
1057 int div;
1058
1059 div = gpmc_calc_divider(sync_clk);
1060 temp = gpmc_ps_to_ticks(time_ps);
1061 temp = (temp + div - 1) / div;
1062 return gpmc_ticks_to_ps(temp * div);
1063}
1064
1065/* XXX: can the cycles be avoided ? */
1066static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001067 struct gpmc_device_timings *dev_t,
1068 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +05301069{
Afzal Mohammed246da262012-08-02 20:02:10 +05301070 u32 temp;
1071
1072 /* adv_rd_off */
1073 temp = dev_t->t_avdp_r;
1074 /* XXX: mux check required ? */
1075 if (mux) {
1076 /* XXX: t_avdp not to be required for sync, only added for tusb
1077 * this indirectly necessitates requirement of t_avdp_r and
1078 * t_avdp_w instead of having a single t_avdp
1079 */
1080 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh);
1081 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
1082 }
1083 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
1084
1085 /* oe_on */
1086 temp = dev_t->t_oeasu; /* XXX: remove this ? */
1087 if (mux) {
1088 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach);
1089 temp = max_t(u32, temp, gpmc_t->adv_rd_off +
1090 gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe));
1091 }
1092 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
1093
1094 /* access */
1095 /* XXX: any scope for improvement ?, by combining oe_on
1096 * and clk_activation, need to check whether
1097 * access = clk_activation + round to sync clk ?
1098 */
1099 temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk);
1100 temp += gpmc_t->clk_activation;
1101 if (dev_t->cyc_oe)
1102 temp = max_t(u32, temp, gpmc_t->oe_on +
1103 gpmc_ticks_to_ps(dev_t->cyc_oe));
1104 gpmc_t->access = gpmc_round_ps_to_ticks(temp);
1105
1106 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
1107 gpmc_t->cs_rd_off = gpmc_t->oe_off;
1108
1109 /* rd_cycle */
1110 temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez);
1111 temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) +
1112 gpmc_t->access;
1113 /* XXX: barter t_ce_rdyz with t_cez_r ? */
1114 if (dev_t->t_ce_rdyz)
1115 temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz);
1116 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
1117
1118 return 0;
1119}
1120
1121static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001122 struct gpmc_device_timings *dev_t,
1123 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +05301124{
Afzal Mohammed246da262012-08-02 20:02:10 +05301125 u32 temp;
1126
1127 /* adv_wr_off */
1128 temp = dev_t->t_avdp_w;
1129 if (mux) {
1130 temp = max_t(u32, temp,
1131 gpmc_t->clk_activation + dev_t->t_avdh);
1132 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
1133 }
1134 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
1135
1136 /* wr_data_mux_bus */
1137 temp = max_t(u32, dev_t->t_weasu,
1138 gpmc_t->clk_activation + dev_t->t_rdyo);
1139 /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?,
1140 * and in that case remember to handle we_on properly
1141 */
1142 if (mux) {
1143 temp = max_t(u32, temp,
1144 gpmc_t->adv_wr_off + dev_t->t_aavdh);
1145 temp = max_t(u32, temp, gpmc_t->adv_wr_off +
1146 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
1147 }
1148 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
1149
1150 /* we_on */
1151 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
1152 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
1153 else
1154 gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
1155
1156 /* wr_access */
1157 /* XXX: gpmc_capability check reqd ? , even if not, will not harm */
1158 gpmc_t->wr_access = gpmc_t->access;
1159
1160 /* we_off */
1161 temp = gpmc_t->we_on + dev_t->t_wpl;
1162 temp = max_t(u32, temp,
1163 gpmc_t->wr_access + gpmc_ticks_to_ps(1));
1164 temp = max_t(u32, temp,
1165 gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl));
1166 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
1167
1168 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
1169 dev_t->t_wph);
1170
1171 /* wr_cycle */
1172 temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk);
1173 temp += gpmc_t->wr_access;
1174 /* XXX: barter t_ce_rdyz with t_cez_w ? */
1175 if (dev_t->t_ce_rdyz)
1176 temp = max_t(u32, temp,
1177 gpmc_t->cs_wr_off + dev_t->t_ce_rdyz);
1178 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
1179
1180 return 0;
1181}
1182
1183static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001184 struct gpmc_device_timings *dev_t,
1185 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +05301186{
Afzal Mohammed246da262012-08-02 20:02:10 +05301187 u32 temp;
1188
1189 /* adv_rd_off */
1190 temp = dev_t->t_avdp_r;
1191 if (mux)
1192 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
1193 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
1194
1195 /* oe_on */
1196 temp = dev_t->t_oeasu;
1197 if (mux)
1198 temp = max_t(u32, temp,
1199 gpmc_t->adv_rd_off + dev_t->t_aavdh);
1200 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
1201
1202 /* access */
1203 temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */
1204 gpmc_t->oe_on + dev_t->t_oe);
1205 temp = max_t(u32, temp,
1206 gpmc_t->cs_on + dev_t->t_ce);
1207 temp = max_t(u32, temp,
1208 gpmc_t->adv_on + dev_t->t_aa);
1209 gpmc_t->access = gpmc_round_ps_to_ticks(temp);
1210
1211 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
1212 gpmc_t->cs_rd_off = gpmc_t->oe_off;
1213
1214 /* rd_cycle */
1215 temp = max_t(u32, dev_t->t_rd_cycle,
1216 gpmc_t->cs_rd_off + dev_t->t_cez_r);
1217 temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez);
1218 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
1219
1220 return 0;
1221}
1222
1223static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001224 struct gpmc_device_timings *dev_t,
1225 bool mux)
Afzal Mohammed246da262012-08-02 20:02:10 +05301226{
Afzal Mohammed246da262012-08-02 20:02:10 +05301227 u32 temp;
1228
1229 /* adv_wr_off */
1230 temp = dev_t->t_avdp_w;
1231 if (mux)
1232 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
1233 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
1234
1235 /* wr_data_mux_bus */
1236 temp = dev_t->t_weasu;
1237 if (mux) {
1238 temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh);
1239 temp = max_t(u32, temp, gpmc_t->adv_wr_off +
1240 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
1241 }
1242 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
1243
1244 /* we_on */
1245 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
1246 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
1247 else
1248 gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
1249
1250 /* we_off */
1251 temp = gpmc_t->we_on + dev_t->t_wpl;
1252 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
1253
1254 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
1255 dev_t->t_wph);
1256
1257 /* wr_cycle */
1258 temp = max_t(u32, dev_t->t_wr_cycle,
1259 gpmc_t->cs_wr_off + dev_t->t_cez_w);
1260 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
1261
1262 return 0;
1263}
1264
1265static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t,
1266 struct gpmc_device_timings *dev_t)
1267{
1268 u32 temp;
1269
1270 gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) *
1271 gpmc_get_fclk_period();
1272
1273 gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk(
1274 dev_t->t_bacc,
1275 gpmc_t->sync_clk);
1276
1277 temp = max_t(u32, dev_t->t_ces, dev_t->t_avds);
1278 gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp);
1279
1280 if (gpmc_calc_divider(gpmc_t->sync_clk) != 1)
1281 return 0;
1282
1283 if (dev_t->ce_xdelay)
1284 gpmc_t->bool_timings.cs_extra_delay = true;
1285 if (dev_t->avd_xdelay)
1286 gpmc_t->bool_timings.adv_extra_delay = true;
1287 if (dev_t->oe_xdelay)
1288 gpmc_t->bool_timings.oe_extra_delay = true;
1289 if (dev_t->we_xdelay)
1290 gpmc_t->bool_timings.we_extra_delay = true;
1291
1292 return 0;
1293}
1294
1295static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001296 struct gpmc_device_timings *dev_t,
1297 bool sync)
Afzal Mohammed246da262012-08-02 20:02:10 +05301298{
1299 u32 temp;
1300
1301 /* cs_on */
1302 gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu);
1303
1304 /* adv_on */
1305 temp = dev_t->t_avdasu;
1306 if (dev_t->t_ce_avd)
1307 temp = max_t(u32, temp,
1308 gpmc_t->cs_on + dev_t->t_ce_avd);
1309 gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp);
1310
Jon Hunterc3be5b42013-02-21 13:46:22 -06001311 if (sync)
Afzal Mohammed246da262012-08-02 20:02:10 +05301312 gpmc_calc_sync_common_timings(gpmc_t, dev_t);
1313
1314 return 0;
1315}
1316
1317/* TODO: remove this function once all peripherals are confirmed to
1318 * work with generic timing. Simultaneously gpmc_cs_set_timings()
1319 * has to be modified to handle timings in ps instead of ns
1320*/
1321static void gpmc_convert_ps_to_ns(struct gpmc_timings *t)
1322{
1323 t->cs_on /= 1000;
1324 t->cs_rd_off /= 1000;
1325 t->cs_wr_off /= 1000;
1326 t->adv_on /= 1000;
1327 t->adv_rd_off /= 1000;
1328 t->adv_wr_off /= 1000;
1329 t->we_on /= 1000;
1330 t->we_off /= 1000;
1331 t->oe_on /= 1000;
1332 t->oe_off /= 1000;
1333 t->page_burst_access /= 1000;
1334 t->access /= 1000;
1335 t->rd_cycle /= 1000;
1336 t->wr_cycle /= 1000;
1337 t->bus_turnaround /= 1000;
1338 t->cycle2cycle_delay /= 1000;
1339 t->wait_monitoring /= 1000;
1340 t->clk_activation /= 1000;
1341 t->wr_access /= 1000;
1342 t->wr_data_mux_bus /= 1000;
1343}
1344
1345int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
Jon Hunterc3be5b42013-02-21 13:46:22 -06001346 struct gpmc_settings *gpmc_s,
1347 struct gpmc_device_timings *dev_t)
Afzal Mohammed246da262012-08-02 20:02:10 +05301348{
Jon Hunterc3be5b42013-02-21 13:46:22 -06001349 bool mux = false, sync = false;
1350
1351 if (gpmc_s) {
1352 mux = gpmc_s->mux_add_data ? true : false;
1353 sync = (gpmc_s->sync_read || gpmc_s->sync_write);
1354 }
1355
Afzal Mohammed246da262012-08-02 20:02:10 +05301356 memset(gpmc_t, 0, sizeof(*gpmc_t));
1357
Jon Hunterc3be5b42013-02-21 13:46:22 -06001358 gpmc_calc_common_timings(gpmc_t, dev_t, sync);
Afzal Mohammed246da262012-08-02 20:02:10 +05301359
Jon Hunterc3be5b42013-02-21 13:46:22 -06001360 if (gpmc_s && gpmc_s->sync_read)
1361 gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301362 else
Jon Hunterc3be5b42013-02-21 13:46:22 -06001363 gpmc_calc_async_read_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301364
Jon Hunterc3be5b42013-02-21 13:46:22 -06001365 if (gpmc_s && gpmc_s->sync_write)
1366 gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301367 else
Jon Hunterc3be5b42013-02-21 13:46:22 -06001368 gpmc_calc_async_write_timings(gpmc_t, dev_t, mux);
Afzal Mohammed246da262012-08-02 20:02:10 +05301369
1370 /* TODO: remove, see function definition */
1371 gpmc_convert_ps_to_ns(gpmc_t);
1372
1373 return 0;
1374}
1375
Jon Hunteraa8d4762013-02-21 15:25:23 -06001376/**
1377 * gpmc_cs_program_settings - programs non-timing related settings
1378 * @cs: GPMC chip-select to program
1379 * @p: pointer to GPMC settings structure
1380 *
1381 * Programs non-timing related settings for a GPMC chip-select, such as
1382 * bus-width, burst configuration, etc. Function should be called once
1383 * for each chip-select that is being used and must be called before
1384 * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1
1385 * register will be initialised to zero by this function. Returns 0 on
1386 * success and appropriate negative error code on failure.
1387 */
1388int gpmc_cs_program_settings(int cs, struct gpmc_settings *p)
1389{
1390 u32 config1;
1391
1392 if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) {
1393 pr_err("%s: invalid width %d!", __func__, p->device_width);
1394 return -EINVAL;
1395 }
1396
1397 /* Address-data multiplexing not supported for NAND devices */
1398 if (p->device_nand && p->mux_add_data) {
1399 pr_err("%s: invalid configuration!\n", __func__);
1400 return -EINVAL;
1401 }
1402
1403 if ((p->mux_add_data > GPMC_MUX_AD) ||
1404 ((p->mux_add_data == GPMC_MUX_AAD) &&
1405 !(gpmc_capability & GPMC_HAS_MUX_AAD))) {
1406 pr_err("%s: invalid multiplex configuration!\n", __func__);
1407 return -EINVAL;
1408 }
1409
1410 /* Page/burst mode supports lengths of 4, 8 and 16 bytes */
1411 if (p->burst_read || p->burst_write) {
1412 switch (p->burst_len) {
1413 case GPMC_BURST_4:
1414 case GPMC_BURST_8:
1415 case GPMC_BURST_16:
1416 break;
1417 default:
1418 pr_err("%s: invalid page/burst-length (%d)\n",
1419 __func__, p->burst_len);
1420 return -EINVAL;
1421 }
1422 }
1423
Roger Quadros2b540572014-09-02 16:57:06 +03001424 if (p->wait_pin > gpmc_nr_waitpins) {
Jon Hunteraa8d4762013-02-21 15:25:23 -06001425 pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin);
1426 return -EINVAL;
1427 }
1428
1429 config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1));
1430
1431 if (p->sync_read)
1432 config1 |= GPMC_CONFIG1_READTYPE_SYNC;
1433 if (p->sync_write)
1434 config1 |= GPMC_CONFIG1_WRITETYPE_SYNC;
1435 if (p->wait_on_read)
1436 config1 |= GPMC_CONFIG1_WAIT_READ_MON;
1437 if (p->wait_on_write)
1438 config1 |= GPMC_CONFIG1_WAIT_WRITE_MON;
1439 if (p->wait_on_read || p->wait_on_write)
1440 config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin);
1441 if (p->device_nand)
1442 config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND);
1443 if (p->mux_add_data)
1444 config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data);
1445 if (p->burst_read)
1446 config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP;
1447 if (p->burst_write)
1448 config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP;
1449 if (p->burst_read || p->burst_write) {
1450 config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3);
1451 config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0;
1452 }
1453
1454 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1);
1455
1456 return 0;
1457}
1458
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001459#ifdef CONFIG_OF
Uwe Kleine-König31957602014-09-10 10:26:17 +02001460static const struct of_device_id gpmc_dt_ids[] = {
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001461 { .compatible = "ti,omap2420-gpmc" },
1462 { .compatible = "ti,omap2430-gpmc" },
1463 { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
1464 { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
1465 { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
1466 { }
1467};
1468MODULE_DEVICE_TABLE(of, gpmc_dt_ids);
1469
Jon Hunter8c8a77712013-02-20 15:53:12 -06001470/**
1471 * gpmc_read_settings_dt - read gpmc settings from device-tree
1472 * @np: pointer to device-tree node for a gpmc child device
1473 * @p: pointer to gpmc settings structure
1474 *
1475 * Reads the GPMC settings for a GPMC child device from device-tree and
1476 * stores them in the GPMC settings structure passed. The GPMC settings
1477 * structure is initialised to zero by this function and so any
1478 * previously stored settings will be cleared.
1479 */
1480void gpmc_read_settings_dt(struct device_node *np, struct gpmc_settings *p)
1481{
1482 memset(p, 0, sizeof(struct gpmc_settings));
1483
1484 p->sync_read = of_property_read_bool(np, "gpmc,sync-read");
1485 p->sync_write = of_property_read_bool(np, "gpmc,sync-write");
Jon Hunter8c8a77712013-02-20 15:53:12 -06001486 of_property_read_u32(np, "gpmc,device-width", &p->device_width);
1487 of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data);
1488
1489 if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) {
1490 p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap");
1491 p->burst_read = of_property_read_bool(np, "gpmc,burst-read");
1492 p->burst_write = of_property_read_bool(np, "gpmc,burst-write");
1493 if (!p->burst_read && !p->burst_write)
1494 pr_warn("%s: page/burst-length set but not used!\n",
1495 __func__);
1496 }
1497
1498 if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) {
1499 p->wait_on_read = of_property_read_bool(np,
1500 "gpmc,wait-on-read");
1501 p->wait_on_write = of_property_read_bool(np,
1502 "gpmc,wait-on-write");
1503 if (!p->wait_on_read && !p->wait_on_write)
Roger Quadros2b540572014-09-02 16:57:06 +03001504 pr_debug("%s: rd/wr wait monitoring not enabled!\n",
1505 __func__);
Jon Hunter8c8a77712013-02-20 15:53:12 -06001506 }
1507}
1508
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001509static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
1510 struct gpmc_timings *gpmc_t)
1511{
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001512 struct gpmc_bool_timings *p;
1513
1514 if (!np || !gpmc_t)
1515 return;
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001516
1517 memset(gpmc_t, 0, sizeof(*gpmc_t));
1518
1519 /* minimum clock period for syncronous mode */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001520 of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001521
1522 /* chip select timtings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001523 of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on);
1524 of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off);
1525 of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001526
1527 /* ADV signal timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001528 of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on);
1529 of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off);
1530 of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001531
1532 /* WE signal timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001533 of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on);
1534 of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001535
1536 /* OE signal timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001537 of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on);
1538 of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001539
1540 /* access and cycle timings */
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001541 of_property_read_u32(np, "gpmc,page-burst-access-ns",
1542 &gpmc_t->page_burst_access);
1543 of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access);
1544 of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle);
1545 of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle);
1546 of_property_read_u32(np, "gpmc,bus-turnaround-ns",
1547 &gpmc_t->bus_turnaround);
1548 of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns",
1549 &gpmc_t->cycle2cycle_delay);
1550 of_property_read_u32(np, "gpmc,wait-monitoring-ns",
1551 &gpmc_t->wait_monitoring);
1552 of_property_read_u32(np, "gpmc,clk-activation-ns",
1553 &gpmc_t->clk_activation);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001554
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001555 /* only applicable to OMAP3+ */
1556 of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access);
1557 of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns",
1558 &gpmc_t->wr_data_mux_bus);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001559
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001560 /* bool timing parameters */
1561 p = &gpmc_t->bool_timings;
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001562
Jon Hunterd36b4cd2013-02-21 18:51:27 -06001563 p->cycle2cyclediffcsen =
1564 of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen");
1565 p->cycle2cyclesamecsen =
1566 of_property_read_bool(np, "gpmc,cycle2cycle-samecsen");
1567 p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay");
1568 p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay");
1569 p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay");
1570 p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay");
1571 p->time_para_granularity =
1572 of_property_read_bool(np, "gpmc,time-para-granularity");
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001573}
1574
Pekon Gupta6b187b22014-01-28 11:42:40 +05301575#if IS_ENABLED(CONFIG_MTD_NAND)
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001576
Mark Jackson496c8a02013-04-19 21:08:28 +01001577static const char * const nand_xfer_types[] = {
1578 [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled",
1579 [NAND_OMAP_POLLED] = "polled",
1580 [NAND_OMAP_PREFETCH_DMA] = "prefetch-dma",
1581 [NAND_OMAP_PREFETCH_IRQ] = "prefetch-irq",
1582};
1583
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001584static int gpmc_probe_nand_child(struct platform_device *pdev,
1585 struct device_node *child)
1586{
1587 u32 val;
1588 const char *s;
1589 struct gpmc_timings gpmc_t;
1590 struct omap_nand_platform_data *gpmc_nand_data;
1591
1592 if (of_property_read_u32(child, "reg", &val) < 0) {
1593 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1594 child->full_name);
1595 return -ENODEV;
1596 }
1597
1598 gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
1599 GFP_KERNEL);
1600 if (!gpmc_nand_data)
1601 return -ENOMEM;
1602
1603 gpmc_nand_data->cs = val;
1604 gpmc_nand_data->of_node = child;
1605
Pekon Guptaac65caf2013-10-24 18:20:17 +05301606 /* Detect availability of ELM module */
1607 gpmc_nand_data->elm_of_node = of_parse_phandle(child, "ti,elm-id", 0);
1608 if (gpmc_nand_data->elm_of_node == NULL)
1609 gpmc_nand_data->elm_of_node =
1610 of_parse_phandle(child, "elm_id", 0);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001611
Pekon Guptaac65caf2013-10-24 18:20:17 +05301612 /* select ecc-scheme for NAND */
1613 if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) {
1614 pr_err("%s: ti,nand-ecc-opt not found\n", __func__);
1615 return -ENODEV;
1616 }
Roger Quadrosa3e83f02014-08-25 16:15:33 -07001617
1618 if (!strcmp(s, "sw"))
1619 gpmc_nand_data->ecc_opt = OMAP_ECC_HAM1_CODE_SW;
1620 else if (!strcmp(s, "ham1") ||
1621 !strcmp(s, "hw") || !strcmp(s, "hw-romcode"))
Pekon Guptaac65caf2013-10-24 18:20:17 +05301622 gpmc_nand_data->ecc_opt =
1623 OMAP_ECC_HAM1_CODE_HW;
1624 else if (!strcmp(s, "bch4"))
1625 if (gpmc_nand_data->elm_of_node)
1626 gpmc_nand_data->ecc_opt =
1627 OMAP_ECC_BCH4_CODE_HW;
1628 else
1629 gpmc_nand_data->ecc_opt =
1630 OMAP_ECC_BCH4_CODE_HW_DETECTION_SW;
1631 else if (!strcmp(s, "bch8"))
1632 if (gpmc_nand_data->elm_of_node)
1633 gpmc_nand_data->ecc_opt =
1634 OMAP_ECC_BCH8_CODE_HW;
1635 else
1636 gpmc_nand_data->ecc_opt =
1637 OMAP_ECC_BCH8_CODE_HW_DETECTION_SW;
pekon gupta27c9fd62014-05-19 13:24:39 +05301638 else if (!strcmp(s, "bch16"))
1639 if (gpmc_nand_data->elm_of_node)
1640 gpmc_nand_data->ecc_opt =
1641 OMAP_ECC_BCH16_CODE_HW;
1642 else
1643 pr_err("%s: BCH16 requires ELM support\n", __func__);
Pekon Guptaac65caf2013-10-24 18:20:17 +05301644 else
1645 pr_err("%s: ti,nand-ecc-opt invalid value\n", __func__);
1646
1647 /* select data transfer mode for NAND controller */
Mark Jackson496c8a02013-04-19 21:08:28 +01001648 if (!of_property_read_string(child, "ti,nand-xfer-type", &s))
1649 for (val = 0; val < ARRAY_SIZE(nand_xfer_types); val++)
1650 if (!strcasecmp(s, nand_xfer_types[val])) {
1651 gpmc_nand_data->xfer_type = val;
1652 break;
1653 }
1654
Ezequiel Garcíafef775c2014-09-11 12:02:08 -03001655 gpmc_nand_data->flash_bbt = of_get_nand_on_flash_bbt(child);
1656
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001657 val = of_get_nand_bus_width(child);
1658 if (val == 16)
1659 gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
1660
1661 gpmc_read_timings_dt(child, &gpmc_t);
1662 gpmc_nand_init(gpmc_nand_data, &gpmc_t);
1663
1664 return 0;
1665}
1666#else
1667static int gpmc_probe_nand_child(struct platform_device *pdev,
1668 struct device_node *child)
1669{
1670 return 0;
1671}
1672#endif
1673
Pekon Gupta980386d2014-01-28 11:42:41 +05301674#if IS_ENABLED(CONFIG_MTD_ONENAND)
Ezequiel Garcia75d36252013-01-25 09:23:11 -03001675static int gpmc_probe_onenand_child(struct platform_device *pdev,
1676 struct device_node *child)
1677{
1678 u32 val;
1679 struct omap_onenand_platform_data *gpmc_onenand_data;
1680
1681 if (of_property_read_u32(child, "reg", &val) < 0) {
1682 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1683 child->full_name);
1684 return -ENODEV;
1685 }
1686
1687 gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
1688 GFP_KERNEL);
1689 if (!gpmc_onenand_data)
1690 return -ENOMEM;
1691
1692 gpmc_onenand_data->cs = val;
1693 gpmc_onenand_data->of_node = child;
1694 gpmc_onenand_data->dma_channel = -1;
1695
1696 if (!of_property_read_u32(child, "dma-channel", &val))
1697 gpmc_onenand_data->dma_channel = val;
1698
1699 gpmc_onenand_init(gpmc_onenand_data);
1700
1701 return 0;
1702}
1703#else
1704static int gpmc_probe_onenand_child(struct platform_device *pdev,
1705 struct device_node *child)
1706{
1707 return 0;
1708}
1709#endif
1710
Jon Huntercdd69282013-02-08 16:46:13 -06001711/**
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001712 * gpmc_probe_generic_child - configures the gpmc for a child device
Jon Huntercdd69282013-02-08 16:46:13 -06001713 * @pdev: pointer to gpmc platform device
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001714 * @child: pointer to device-tree node for child device
Jon Huntercdd69282013-02-08 16:46:13 -06001715 *
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001716 * Allocates and configures a GPMC chip-select for a child device.
Jon Huntercdd69282013-02-08 16:46:13 -06001717 * Returns 0 on success and appropriate negative error code on failure.
1718 */
Javier Martinez Canillas3af91cf2013-03-14 16:09:21 +01001719static int gpmc_probe_generic_child(struct platform_device *pdev,
Jon Huntercdd69282013-02-08 16:46:13 -06001720 struct device_node *child)
1721{
1722 struct gpmc_settings gpmc_s;
1723 struct gpmc_timings gpmc_t;
1724 struct resource res;
1725 unsigned long base;
Tony Lindgren9ed7a772014-11-03 17:45:01 -08001726 const char *name;
Jon Huntercdd69282013-02-08 16:46:13 -06001727 int ret, cs;
Roger Quadrose378d222014-08-29 19:11:52 +03001728 u32 val;
Jon Huntercdd69282013-02-08 16:46:13 -06001729
1730 if (of_property_read_u32(child, "reg", &cs) < 0) {
1731 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1732 child->full_name);
1733 return -ENODEV;
1734 }
1735
1736 if (of_address_to_resource(child, 0, &res) < 0) {
1737 dev_err(&pdev->dev, "%s has malformed 'reg' property\n",
1738 child->full_name);
1739 return -ENODEV;
1740 }
1741
Tony Lindgren9ed7a772014-11-03 17:45:01 -08001742 /*
1743 * Check if we have multiple instances of the same device
1744 * on a single chip select. If so, use the already initialized
1745 * timings.
1746 */
1747 name = gpmc_cs_get_name(cs);
1748 if (name && child->name && of_node_cmp(child->name, name) == 0)
1749 goto no_timings;
1750
Jon Huntercdd69282013-02-08 16:46:13 -06001751 ret = gpmc_cs_request(cs, resource_size(&res), &base);
1752 if (ret < 0) {
1753 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
1754 return ret;
1755 }
Tony Lindgren9ed7a772014-11-03 17:45:01 -08001756 gpmc_cs_set_name(cs, child->name);
Jon Huntercdd69282013-02-08 16:46:13 -06001757
Tony Lindgren35ac0512014-11-03 17:45:01 -08001758 gpmc_read_settings_dt(child, &gpmc_s);
1759 gpmc_read_timings_dt(child, &gpmc_t);
Jon Huntercdd69282013-02-08 16:46:13 -06001760
1761 /*
Tony Lindgrenfd4446f2013-11-14 15:25:09 -08001762 * For some GPMC devices we still need to rely on the bootloader
Tony Lindgren35ac0512014-11-03 17:45:01 -08001763 * timings because the devices can be connected via FPGA.
1764 * REVISIT: Add timing support from slls644g.pdf.
Tony Lindgrenfd4446f2013-11-14 15:25:09 -08001765 */
Tony Lindgren35ac0512014-11-03 17:45:01 -08001766 if (!gpmc_t.cs_rd_off) {
1767 WARN(1, "enable GPMC debug to configure .dts timings for CS%i\n",
1768 cs);
1769 gpmc_cs_show_timings(cs,
1770 "please add GPMC bootloader timings to .dts");
Tony Lindgrenfd4446f2013-11-14 15:25:09 -08001771 goto no_timings;
1772 }
1773
Roger Quadros4cf27d22014-08-29 19:11:53 +03001774 /* CS must be disabled while making changes to gpmc configuration */
1775 gpmc_cs_disable_mem(cs);
1776
Tony Lindgrenfd4446f2013-11-14 15:25:09 -08001777 /*
Jon Huntercdd69282013-02-08 16:46:13 -06001778 * FIXME: gpmc_cs_request() will map the CS to an arbitary
1779 * location in the gpmc address space. When booting with
1780 * device-tree we want the NOR flash to be mapped to the
1781 * location specified in the device-tree blob. So remap the
1782 * CS to this location. Once DT migration is complete should
1783 * just make gpmc_cs_request() map a specific address.
1784 */
1785 ret = gpmc_cs_remap(cs, res.start);
1786 if (ret < 0) {
Fabio Estevamf70bf2a2013-09-18 12:01:59 -07001787 dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n",
1788 cs, &res.start);
Jon Huntercdd69282013-02-08 16:46:13 -06001789 goto err;
1790 }
1791
Jon Huntercdd69282013-02-08 16:46:13 -06001792 ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width);
1793 if (ret < 0)
1794 goto err;
1795
1796 ret = gpmc_cs_program_settings(cs, &gpmc_s);
1797 if (ret < 0)
1798 goto err;
1799
Roger Quadros7604baf2014-08-29 19:11:51 +03001800 ret = gpmc_cs_set_timings(cs, &gpmc_t);
1801 if (ret) {
1802 dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n",
1803 child->name);
1804 goto err;
1805 }
Jon Huntercdd69282013-02-08 16:46:13 -06001806
Roger Quadrose378d222014-08-29 19:11:52 +03001807 /* Clear limited address i.e. enable A26-A11 */
1808 val = gpmc_read_reg(GPMC_CONFIG);
1809 val &= ~GPMC_CONFIG_LIMITEDADDRESS;
1810 gpmc_write_reg(GPMC_CONFIG, val);
1811
Roger Quadros4cf27d22014-08-29 19:11:53 +03001812 /* Enable CS region */
1813 gpmc_cs_enable_mem(cs);
Jon Huntercdd69282013-02-08 16:46:13 -06001814
Tony Lindgrenfd4446f2013-11-14 15:25:09 -08001815no_timings:
Robert ABELb1dc1ca2015-02-27 16:56:49 +01001816
1817 /* create platform device, NULL on error or when disabled */
1818 if (!of_platform_device_create(child, NULL, &pdev->dev))
1819 goto err_child_fail;
1820
1821 /* is child a common bus? */
1822 if (of_match_node(of_default_bus_match_table, child))
1823 /* create children and other common bus children */
1824 if (of_platform_populate(child, of_default_bus_match_table,
1825 NULL, &pdev->dev))
1826 goto err_child_fail;
1827
1828 return 0;
1829
1830err_child_fail:
Jon Huntercdd69282013-02-08 16:46:13 -06001831
1832 dev_err(&pdev->dev, "failed to create gpmc child %s\n", child->name);
Javier Martinez Canillase8ffd6f2013-03-14 16:09:20 +01001833 ret = -ENODEV;
Jon Huntercdd69282013-02-08 16:46:13 -06001834
1835err:
1836 gpmc_cs_free(cs);
1837
1838 return ret;
1839}
1840
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001841static int gpmc_probe_dt(struct platform_device *pdev)
1842{
1843 int ret;
1844 struct device_node *child;
1845 const struct of_device_id *of_id =
1846 of_match_device(gpmc_dt_ids, &pdev->dev);
1847
1848 if (!of_id)
1849 return 0;
1850
Gupta Pekonf34f3712013-05-31 17:31:30 +05301851 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs",
1852 &gpmc_cs_num);
1853 if (ret < 0) {
1854 pr_err("%s: number of chip-selects not defined\n", __func__);
1855 return ret;
1856 } else if (gpmc_cs_num < 1) {
1857 pr_err("%s: all chip-selects are disabled\n", __func__);
1858 return -EINVAL;
1859 } else if (gpmc_cs_num > GPMC_CS_NUM) {
1860 pr_err("%s: number of supported chip-selects cannot be > %d\n",
1861 __func__, GPMC_CS_NUM);
1862 return -EINVAL;
1863 }
1864
Jon Hunter9f833152013-02-20 15:53:38 -06001865 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins",
1866 &gpmc_nr_waitpins);
1867 if (ret < 0) {
1868 pr_err("%s: number of wait pins not found!\n", __func__);
1869 return ret;
1870 }
1871
Guido Martínez68e2eb52014-07-02 10:35:18 -03001872 for_each_available_child_of_node(pdev->dev.of_node, child) {
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001873
Javier Martinez Canillasf2b09f62013-04-17 22:34:11 +02001874 if (!child->name)
1875 continue;
Jon Huntercdd69282013-02-08 16:46:13 -06001876
Javier Martinez Canillasf2b09f62013-04-17 22:34:11 +02001877 if (of_node_cmp(child->name, "nand") == 0)
1878 ret = gpmc_probe_nand_child(pdev, child);
1879 else if (of_node_cmp(child->name, "onenand") == 0)
1880 ret = gpmc_probe_onenand_child(pdev, child);
1881 else if (of_node_cmp(child->name, "ethernet") == 0 ||
Tony Lindgrenfd4446f2013-11-14 15:25:09 -08001882 of_node_cmp(child->name, "nor") == 0 ||
1883 of_node_cmp(child->name, "uart") == 0)
Javier Martinez Canillasf2b09f62013-04-17 22:34:11 +02001884 ret = gpmc_probe_generic_child(pdev, child);
Jon Huntercdd69282013-02-08 16:46:13 -06001885
Javier Martinez Canillasb327b362013-04-17 22:34:12 +02001886 if (WARN(ret < 0, "%s: probing gpmc child %s failed\n",
1887 __func__, child->full_name))
Javier Martinez Canillas5330dc12013-03-14 22:54:11 +01001888 of_node_put(child);
Javier Martinez Canillas5330dc12013-03-14 22:54:11 +01001889 }
1890
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001891 return 0;
1892}
1893#else
1894static int gpmc_probe_dt(struct platform_device *pdev)
1895{
1896 return 0;
1897}
1898#endif
1899
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001900static int gpmc_probe(struct platform_device *pdev)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001901{
Jon Hunter81190242012-10-17 09:41:25 -05001902 int rc;
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001903 u32 l;
Afzal Mohammedda496872012-09-23 17:28:25 -06001904 struct resource *res;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001905
Afzal Mohammedda496872012-09-23 17:28:25 -06001906 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1907 if (res == NULL)
1908 return -ENOENT;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +03001909
Afzal Mohammedda496872012-09-23 17:28:25 -06001910 phys_base = res->start;
1911 mem_size = resource_size(res);
Kevin Hilman8d084362010-01-29 14:20:06 -08001912
Thierry Reding5857bd92013-01-21 11:08:55 +01001913 gpmc_base = devm_ioremap_resource(&pdev->dev, res);
1914 if (IS_ERR(gpmc_base))
1915 return PTR_ERR(gpmc_base);
Afzal Mohammedda496872012-09-23 17:28:25 -06001916
1917 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1918 if (res == NULL)
1919 dev_warn(&pdev->dev, "Failed to get resource: irq\n");
1920 else
1921 gpmc_irq = res->start;
1922
Roger Quadros8bf9be52014-09-01 15:18:56 +03001923 gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck");
Afzal Mohammedda496872012-09-23 17:28:25 -06001924 if (IS_ERR(gpmc_l3_clk)) {
Roger Quadros8bf9be52014-09-01 15:18:56 +03001925 dev_err(&pdev->dev, "Failed to get GPMC fck\n");
Afzal Mohammedda496872012-09-23 17:28:25 -06001926 gpmc_irq = 0;
1927 return PTR_ERR(gpmc_l3_clk);
Paul Walmsleyfd1dc872008-10-06 15:49:17 +03001928 }
1929
Roger Quadros8bf9be52014-09-01 15:18:56 +03001930 if (!clk_get_rate(gpmc_l3_clk)) {
1931 dev_err(&pdev->dev, "Invalid GPMC fck clock rate\n");
1932 return -EINVAL;
1933 }
1934
avinash philipb3f55252013-06-12 16:30:56 +05301935 pm_runtime_enable(&pdev->dev);
1936 pm_runtime_get_sync(&pdev->dev);
Olof Johansson1daa8c12010-01-20 22:39:29 +00001937
Afzal Mohammedda496872012-09-23 17:28:25 -06001938 gpmc_dev = &pdev->dev;
1939
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001940 l = gpmc_read_reg(GPMC_REVISION);
Jon Hunteraa8d4762013-02-21 15:25:23 -06001941
1942 /*
1943 * FIXME: Once device-tree migration is complete the below flags
1944 * should be populated based upon the device-tree compatible
1945 * string. For now just use the IP revision. OMAP3+ devices have
1946 * the wr_access and wr_data_mux_bus register fields. OMAP4+
1947 * devices support the addr-addr-data multiplex protocol.
1948 *
1949 * GPMC IP revisions:
1950 * - OMAP24xx = 2.0
1951 * - OMAP3xxx = 5.0
1952 * - OMAP44xx/54xx/AM335x = 6.0
1953 */
Afzal Mohammedda496872012-09-23 17:28:25 -06001954 if (GPMC_REVISION_MAJOR(l) > 0x4)
1955 gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
Jon Hunteraa8d4762013-02-21 15:25:23 -06001956 if (GPMC_REVISION_MAJOR(l) > 0x5)
1957 gpmc_capability |= GPMC_HAS_MUX_AAD;
Afzal Mohammedda496872012-09-23 17:28:25 -06001958 dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
1959 GPMC_REVISION_MINOR(l));
1960
Jon Hunter84b00f02013-03-06 14:36:47 -06001961 gpmc_mem_init();
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301962
Russell King71856842013-03-13 20:44:21 +00001963 if (gpmc_setup_irq() < 0)
Afzal Mohammedda496872012-09-23 17:28:25 -06001964 dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
1965
Gupta Pekonf34f3712013-05-31 17:31:30 +05301966 if (!pdev->dev.of_node) {
1967 gpmc_cs_num = GPMC_CS_NUM;
Jon Hunter9f833152013-02-20 15:53:38 -06001968 gpmc_nr_waitpins = GPMC_NR_WAITPINS;
Gupta Pekonf34f3712013-05-31 17:31:30 +05301969 }
Jon Hunter9f833152013-02-20 15:53:38 -06001970
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001971 rc = gpmc_probe_dt(pdev);
1972 if (rc < 0) {
avinash philipb3f55252013-06-12 16:30:56 +05301973 pm_runtime_put_sync(&pdev->dev);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001974 dev_err(gpmc_dev, "failed to probe DT parameters\n");
1975 return rc;
1976 }
1977
Afzal Mohammedda496872012-09-23 17:28:25 -06001978 return 0;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301979}
Afzal Mohammedda496872012-09-23 17:28:25 -06001980
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001981static int gpmc_remove(struct platform_device *pdev)
Afzal Mohammedda496872012-09-23 17:28:25 -06001982{
1983 gpmc_free_irq();
1984 gpmc_mem_exit();
avinash philipb3f55252013-06-12 16:30:56 +05301985 pm_runtime_put_sync(&pdev->dev);
1986 pm_runtime_disable(&pdev->dev);
Afzal Mohammedda496872012-09-23 17:28:25 -06001987 gpmc_dev = NULL;
1988 return 0;
1989}
1990
avinash philipb536dd42013-06-18 00:16:38 +05301991#ifdef CONFIG_PM_SLEEP
1992static int gpmc_suspend(struct device *dev)
1993{
1994 omap3_gpmc_save_context();
1995 pm_runtime_put_sync(dev);
1996 return 0;
1997}
1998
1999static int gpmc_resume(struct device *dev)
2000{
2001 pm_runtime_get_sync(dev);
2002 omap3_gpmc_restore_context();
2003 return 0;
2004}
2005#endif
2006
2007static SIMPLE_DEV_PM_OPS(gpmc_pm_ops, gpmc_suspend, gpmc_resume);
2008
Afzal Mohammedda496872012-09-23 17:28:25 -06002009static struct platform_driver gpmc_driver = {
2010 .probe = gpmc_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08002011 .remove = gpmc_remove,
Afzal Mohammedda496872012-09-23 17:28:25 -06002012 .driver = {
2013 .name = DEVICE_NAME,
Daniel Mackbc6b1e72012-12-14 11:36:44 +01002014 .of_match_table = of_match_ptr(gpmc_dt_ids),
avinash philipb536dd42013-06-18 00:16:38 +05302015 .pm = &gpmc_pm_ops,
Afzal Mohammedda496872012-09-23 17:28:25 -06002016 },
2017};
2018
2019static __init int gpmc_init(void)
2020{
2021 return platform_driver_register(&gpmc_driver);
2022}
2023
2024static __exit void gpmc_exit(void)
2025{
2026 platform_driver_unregister(&gpmc_driver);
2027
2028}
2029
Tony Lindgrena8612802014-11-20 12:45:43 -08002030postcore_initcall(gpmc_init);
Afzal Mohammedda496872012-09-23 17:28:25 -06002031module_exit(gpmc_exit);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05302032
2033static irqreturn_t gpmc_handle_irq(int irq, void *dev)
2034{
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07002035 int i;
2036 u32 regval;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05302037
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07002038 regval = gpmc_read_reg(GPMC_IRQSTATUS);
2039
2040 if (!regval)
2041 return IRQ_NONE;
2042
2043 for (i = 0; i < GPMC_NR_IRQ; i++)
2044 if (regval & gpmc_client_irq[i].bitmask)
2045 generic_handle_irq(gpmc_client_irq[i].irq);
2046
2047 gpmc_write_reg(GPMC_IRQSTATUS, regval);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05302048
2049 return IRQ_HANDLED;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07002050}
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302051
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302052static struct omap3_gpmc_regs gpmc_context;
2053
Felipe Balbib2fa3b72010-02-15 10:03:33 -08002054void omap3_gpmc_save_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302055{
2056 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -08002057
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302058 gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
2059 gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
2060 gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
2061 gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
2062 gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
2063 gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
2064 gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
Gupta Pekonf34f3712013-05-31 17:31:30 +05302065 for (i = 0; i < gpmc_cs_num; i++) {
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302066 gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
2067 if (gpmc_context.cs_context[i].is_valid) {
2068 gpmc_context.cs_context[i].config1 =
2069 gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
2070 gpmc_context.cs_context[i].config2 =
2071 gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
2072 gpmc_context.cs_context[i].config3 =
2073 gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
2074 gpmc_context.cs_context[i].config4 =
2075 gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
2076 gpmc_context.cs_context[i].config5 =
2077 gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
2078 gpmc_context.cs_context[i].config6 =
2079 gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
2080 gpmc_context.cs_context[i].config7 =
2081 gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
2082 }
2083 }
2084}
2085
Felipe Balbib2fa3b72010-02-15 10:03:33 -08002086void omap3_gpmc_restore_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302087{
2088 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -08002089
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302090 gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
2091 gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
2092 gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
2093 gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
2094 gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
2095 gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
2096 gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
Gupta Pekonf34f3712013-05-31 17:31:30 +05302097 for (i = 0; i < gpmc_cs_num; i++) {
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05302098 if (gpmc_context.cs_context[i].is_valid) {
2099 gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
2100 gpmc_context.cs_context[i].config1);
2101 gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
2102 gpmc_context.cs_context[i].config2);
2103 gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
2104 gpmc_context.cs_context[i].config3);
2105 gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
2106 gpmc_context.cs_context[i].config4);
2107 gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
2108 gpmc_context.cs_context[i].config5);
2109 gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
2110 gpmc_context.cs_context[i].config6);
2111 gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
2112 gpmc_context.cs_context[i].config7);
2113 }
2114 }
2115}