blob: 586dba7e5f238657c9d2a54b64c0fe839111a91a [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>
29#include <linux/of_mtd.h>
30#include <linux/of_device.h>
31#include <linux/mtd/nand.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070032
Afzal Mohammedbc3668e2012-09-29 12:26:13 +053033#include <linux/platform_data/mtd-nand-omap2.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070034
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070035#include <asm/mach-types.h>
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070036
Tony Lindgrendbc04162012-08-31 10:59:07 -070037#include "soc.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070038#include "common.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070039#include "omap_device.h"
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053040#include "gpmc.h"
Daniel Mackbc6b1e72012-12-14 11:36:44 +010041#include "gpmc-nand.h"
Ezequiel Garcia75d36252013-01-25 09:23:11 -030042#include "gpmc-onenand.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070043
Afzal Mohammed4be48fd2012-09-23 17:28:24 -060044#define DEVICE_NAME "omap-gpmc"
45
Paul Walmsleyfd1dc872008-10-06 15:49:17 +030046/* GPMC register offsets */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070047#define GPMC_REVISION 0x00
48#define GPMC_SYSCONFIG 0x10
49#define GPMC_SYSSTATUS 0x14
50#define GPMC_IRQSTATUS 0x18
51#define GPMC_IRQENABLE 0x1c
52#define GPMC_TIMEOUT_CONTROL 0x40
53#define GPMC_ERR_ADDRESS 0x44
54#define GPMC_ERR_TYPE 0x48
55#define GPMC_CONFIG 0x50
56#define GPMC_STATUS 0x54
57#define GPMC_PREFETCH_CONFIG1 0x1e0
58#define GPMC_PREFETCH_CONFIG2 0x1e4
Thara Gopinath15e02a32008-04-28 16:55:01 +053059#define GPMC_PREFETCH_CONTROL 0x1ec
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070060#define GPMC_PREFETCH_STATUS 0x1f0
61#define GPMC_ECC_CONFIG 0x1f4
62#define GPMC_ECC_CONTROL 0x1f8
63#define GPMC_ECC_SIZE_CONFIG 0x1fc
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000064#define GPMC_ECC1_RESULT 0x200
Ivan Djelic8d602cf2012-04-26 14:17:49 +020065#define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053066#define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
67#define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
68#define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070069
Yegor Yefremov2c65e742012-05-09 08:32:49 -070070/* GPMC ECC control settings */
71#define GPMC_ECC_CTRL_ECCCLEAR 0x100
72#define GPMC_ECC_CTRL_ECCDISABLE 0x000
73#define GPMC_ECC_CTRL_ECCREG1 0x001
74#define GPMC_ECC_CTRL_ECCREG2 0x002
75#define GPMC_ECC_CTRL_ECCREG3 0x003
76#define GPMC_ECC_CTRL_ECCREG4 0x004
77#define GPMC_ECC_CTRL_ECCREG5 0x005
78#define GPMC_ECC_CTRL_ECCREG6 0x006
79#define GPMC_ECC_CTRL_ECCREG7 0x007
80#define GPMC_ECC_CTRL_ECCREG8 0x008
81#define GPMC_ECC_CTRL_ECCREG9 0x009
82
Afzal Mohammed559d94b2012-05-28 17:51:37 +053083#define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
84#define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
85#define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
86#define GPMC_CONFIG4_WEEXTRADELAY BIT(23)
87#define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6)
88#define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7)
89
Sukumar Ghorai948d38e2010-07-09 09:14:44 +000090#define GPMC_CS0_OFFSET 0x60
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070091#define GPMC_CS_SIZE 0x30
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +053092#define GPMC_BCH_SIZE 0x10
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -070093
Imre Deakf37e4582006-09-25 12:41:33 +030094#define GPMC_MEM_START 0x00000000
95#define GPMC_MEM_END 0x3FFFFFFF
96#define BOOT_ROM_SPACE 0x100000 /* 1MB */
97
98#define GPMC_CHUNK_SHIFT 24 /* 16 MB */
99#define GPMC_SECTION_SHIFT 28 /* 128 MB */
100
vimal singh59e9c5a2009-07-13 16:26:24 +0530101#define CS_NUM_SHIFT 24
102#define ENABLE_PREFETCH (0x1 << 7)
103#define DMA_MPU_MODE 2
104
Afzal Mohammedda496872012-09-23 17:28:25 -0600105#define GPMC_REVISION_MAJOR(l) ((l >> 4) & 0xf)
106#define GPMC_REVISION_MINOR(l) (l & 0xf)
107
108#define GPMC_HAS_WR_ACCESS 0x1
109#define GPMC_HAS_WR_DATA_MUX_BUS 0x2
110
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700111/* XXX: Only NAND irq has been considered,currently these are the only ones used
112 */
113#define GPMC_NR_IRQ 2
114
115struct gpmc_client_irq {
116 unsigned irq;
117 u32 bitmask;
118};
119
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530120/* Structure to save gpmc cs context */
121struct gpmc_cs_config {
122 u32 config1;
123 u32 config2;
124 u32 config3;
125 u32 config4;
126 u32 config5;
127 u32 config6;
128 u32 config7;
129 int is_valid;
130};
131
132/*
133 * Structure to save/restore gpmc context
134 * to support core off on OMAP3
135 */
136struct omap3_gpmc_regs {
137 u32 sysconfig;
138 u32 irqenable;
139 u32 timeout_ctrl;
140 u32 config;
141 u32 prefetch_config1;
142 u32 prefetch_config2;
143 u32 prefetch_control;
144 struct gpmc_cs_config cs_context[GPMC_CS_NUM];
145};
146
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700147static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
148static struct irq_chip gpmc_irq_chip;
149static unsigned gpmc_irq_start;
150
Imre Deakf37e4582006-09-25 12:41:33 +0300151static struct resource gpmc_mem_root;
152static struct resource gpmc_cs_mem[GPMC_CS_NUM];
Thomas Gleixner87b247c2007-05-10 22:33:04 -0700153static DEFINE_SPINLOCK(gpmc_mem_lock);
Jon Hunter6797b4f2013-02-01 10:38:45 -0600154/* Define chip-selects as reserved by default until probe completes */
155static unsigned int gpmc_cs_map = ((1 << GPMC_CS_NUM) - 1);
Afzal Mohammedda496872012-09-23 17:28:25 -0600156static struct device *gpmc_dev;
157static int gpmc_irq;
158static resource_size_t phys_base, mem_size;
159static unsigned gpmc_capability;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300160static void __iomem *gpmc_base;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700161
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300162static struct clk *gpmc_l3_clk;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700163
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530164static irqreturn_t gpmc_handle_irq(int irq, void *dev);
165
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700166static void gpmc_write_reg(int idx, u32 val)
167{
168 __raw_writel(val, gpmc_base + idx);
169}
170
171static u32 gpmc_read_reg(int idx)
172{
173 return __raw_readl(gpmc_base + idx);
174}
175
176void gpmc_cs_write_reg(int cs, int idx, u32 val)
177{
178 void __iomem *reg_addr;
179
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000180 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700181 __raw_writel(val, reg_addr);
182}
183
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300184static u32 gpmc_cs_read_reg(int cs, int idx)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700185{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300186 void __iomem *reg_addr;
187
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000188 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300189 return __raw_readl(reg_addr);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700190}
191
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300192/* TODO: Add support for gpmc_fck to clock framework and use it */
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300193static unsigned long gpmc_get_fclk_period(void)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700194{
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300195 unsigned long rate = clk_get_rate(gpmc_l3_clk);
196
197 if (rate == 0) {
198 printk(KERN_WARNING "gpmc_l3_clk not enabled\n");
199 return 0;
200 }
201
202 rate /= 1000;
203 rate = 1000000000 / rate; /* In picoseconds */
204
205 return rate;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700206}
207
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300208static unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700209{
210 unsigned long tick_ps;
211
212 /* Calculate in picosecs to yield more exact results */
213 tick_ps = gpmc_get_fclk_period();
214
215 return (time_ns * 1000 + tick_ps - 1) / tick_ps;
216}
217
Ezequiel Garcia3fc089e2013-02-12 16:22:17 -0300218static unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
Adrian Huntera3551f52010-12-09 10:48:27 +0200219{
220 unsigned long tick_ps;
221
222 /* Calculate in picosecs to yield more exact results */
223 tick_ps = gpmc_get_fclk_period();
224
225 return (time_ps + tick_ps - 1) / tick_ps;
226}
227
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300228unsigned int gpmc_ticks_to_ns(unsigned int ticks)
229{
230 return ticks * gpmc_get_fclk_period() / 1000;
231}
232
Afzal Mohammed246da262012-08-02 20:02:10 +0530233static unsigned int gpmc_ticks_to_ps(unsigned int ticks)
234{
235 return ticks * gpmc_get_fclk_period();
236}
237
238static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps)
239{
240 unsigned long ticks = gpmc_ps_to_ticks(time_ps);
241
242 return ticks * gpmc_get_fclk_period();
243}
244
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530245static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value)
246{
247 u32 l;
248
249 l = gpmc_cs_read_reg(cs, reg);
250 if (value)
251 l |= mask;
252 else
253 l &= ~mask;
254 gpmc_cs_write_reg(cs, reg, l);
255}
256
257static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
258{
259 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1,
260 GPMC_CONFIG1_TIME_PARA_GRAN,
261 p->time_para_granularity);
262 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2,
263 GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay);
264 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3,
265 GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay);
266 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
267 GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay);
268 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
269 GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay);
270 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
271 GPMC_CONFIG6_CYCLE2CYCLESAMECSEN,
272 p->cycle2cyclesamecsen);
273 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
274 GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN,
275 p->cycle2cyclediffcsen);
276}
277
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700278#ifdef DEBUG
279static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
Juha Yrjola2aab6462006-06-26 16:16:21 -0700280 int time, const char *name)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700281#else
282static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
283 int time)
284#endif
285{
286 u32 l;
287 int ticks, mask, nr_bits;
288
289 if (time == 0)
290 ticks = 0;
291 else
292 ticks = gpmc_ns_to_ticks(time);
293 nr_bits = end_bit - st_bit + 1;
David Brownell1c22cc12006-12-06 17:13:55 -0800294 if (ticks >= 1 << nr_bits) {
295#ifdef DEBUG
296 printk(KERN_INFO "GPMC CS%d: %-10s* %3d ns, %3d ticks >= %d\n",
297 cs, name, time, ticks, 1 << nr_bits);
298#endif
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700299 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800300 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700301
302 mask = (1 << nr_bits) - 1;
303 l = gpmc_cs_read_reg(cs, reg);
304#ifdef DEBUG
David Brownell1c22cc12006-12-06 17:13:55 -0800305 printk(KERN_INFO
306 "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n",
Juha Yrjola2aab6462006-06-26 16:16:21 -0700307 cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000,
David Brownell1c22cc12006-12-06 17:13:55 -0800308 (l >> st_bit) & mask, time);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700309#endif
310 l &= ~(mask << st_bit);
311 l |= ticks << st_bit;
312 gpmc_cs_write_reg(cs, reg, l);
313
314 return 0;
315}
316
317#ifdef DEBUG
318#define GPMC_SET_ONE(reg, st, end, field) \
319 if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
320 t->field, #field) < 0) \
321 return -1
322#else
323#define GPMC_SET_ONE(reg, st, end, field) \
324 if (set_gpmc_timing_reg(cs, (reg), (st), (end), t->field) < 0) \
325 return -1
326#endif
327
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530328int gpmc_calc_divider(unsigned int sync_clk)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700329{
330 int div;
331 u32 l;
332
Adrian Huntera3551f52010-12-09 10:48:27 +0200333 l = sync_clk + (gpmc_get_fclk_period() - 1);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700334 div = l / gpmc_get_fclk_period();
335 if (div > 4)
336 return -1;
David Brownell1c22cc12006-12-06 17:13:55 -0800337 if (div <= 0)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700338 div = 1;
339
340 return div;
341}
342
343int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
344{
345 int div;
346 u32 l;
347
Afzal Mohammed1b47ca12012-08-19 18:29:45 +0530348 div = gpmc_calc_divider(t->sync_clk);
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700349 if (div < 0)
Paul Walmsleya032d332012-08-03 09:21:10 -0600350 return div;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700351
352 GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
353 GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
354 GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
355
356 GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on);
357 GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off);
358 GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
359
360 GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on);
361 GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off);
362 GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
363 GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
364
365 GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle);
366 GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle);
367 GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
368
369 GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
370
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530371 GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
372 GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
373
374 GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring);
375 GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation);
376
Afzal Mohammedda496872012-09-23 17:28:25 -0600377 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300378 GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
Afzal Mohammedda496872012-09-23 17:28:25 -0600379 if (gpmc_capability & GPMC_HAS_WR_ACCESS)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300380 GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300381
David Brownell1c22cc12006-12-06 17:13:55 -0800382 /* caller is expected to have initialized CONFIG1 to cover
383 * at least sync vs async
384 */
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700385 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
David Brownell1c22cc12006-12-06 17:13:55 -0800386 if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) {
387#ifdef DEBUG
388 printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n",
389 cs, (div * gpmc_get_fclk_period()) / 1000, div);
390#endif
391 l &= ~0x03;
392 l |= (div - 1);
393 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
394 }
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700395
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530396 gpmc_cs_bool_timings(cs, &t->bool_timings);
397
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700398 return 0;
399}
400
Imre Deakf37e4582006-09-25 12:41:33 +0300401static void gpmc_cs_enable_mem(int cs, u32 base, u32 size)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700402{
Imre Deakf37e4582006-09-25 12:41:33 +0300403 u32 l;
404 u32 mask;
405
406 mask = (1 << GPMC_SECTION_SHIFT) - size;
407 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
408 l &= ~0x3f;
409 l = (base >> GPMC_CHUNK_SHIFT) & 0x3f;
410 l &= ~(0x0f << 8);
411 l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8;
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530412 l |= GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300413 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
414}
415
416static void gpmc_cs_disable_mem(int cs)
417{
418 u32 l;
419
420 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530421 l &= ~GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300422 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
423}
424
425static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size)
426{
427 u32 l;
428 u32 mask;
429
430 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
431 *base = (l & 0x3f) << GPMC_CHUNK_SHIFT;
432 mask = (l >> 8) & 0x0f;
433 *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT);
434}
435
436static int gpmc_cs_mem_enabled(int cs)
437{
438 u32 l;
439
440 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +0530441 return l & GPMC_CONFIG7_CSVALID;
Imre Deakf37e4582006-09-25 12:41:33 +0300442}
443
Ezequiel Garciaf5d8eda2013-02-12 16:22:24 -0300444static void gpmc_cs_set_reserved(int cs, int reserved)
Imre Deakf37e4582006-09-25 12:41:33 +0300445{
446 gpmc_cs_map &= ~(1 << cs);
447 gpmc_cs_map |= (reserved ? 1 : 0) << cs;
448}
449
Ezequiel Garciaae9d9082013-02-12 16:22:19 -0300450static bool gpmc_cs_reserved(int cs)
Imre Deakf37e4582006-09-25 12:41:33 +0300451{
452 return gpmc_cs_map & (1 << cs);
453}
454
455static unsigned long gpmc_mem_align(unsigned long size)
456{
457 int order;
458
459 size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1);
460 order = GPMC_CHUNK_SHIFT - 1;
461 do {
462 size >>= 1;
463 order++;
464 } while (size);
465 size = 1 << order;
466 return size;
467}
468
469static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
470{
471 struct resource *res = &gpmc_cs_mem[cs];
472 int r;
473
474 size = gpmc_mem_align(size);
475 spin_lock(&gpmc_mem_lock);
476 res->start = base;
477 res->end = base + size - 1;
478 r = request_resource(&gpmc_mem_root, res);
479 spin_unlock(&gpmc_mem_lock);
480
481 return r;
482}
483
Afzal Mohammedda496872012-09-23 17:28:25 -0600484static int gpmc_cs_delete_mem(int cs)
485{
486 struct resource *res = &gpmc_cs_mem[cs];
487 int r;
488
489 spin_lock(&gpmc_mem_lock);
490 r = release_resource(&gpmc_cs_mem[cs]);
491 res->start = 0;
492 res->end = 0;
493 spin_unlock(&gpmc_mem_lock);
494
495 return r;
496}
497
Imre Deakf37e4582006-09-25 12:41:33 +0300498int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
499{
500 struct resource *res = &gpmc_cs_mem[cs];
501 int r = -1;
502
503 if (cs > GPMC_CS_NUM)
504 return -ENODEV;
505
506 size = gpmc_mem_align(size);
507 if (size > (1 << GPMC_SECTION_SHIFT))
508 return -ENOMEM;
509
510 spin_lock(&gpmc_mem_lock);
511 if (gpmc_cs_reserved(cs)) {
512 r = -EBUSY;
513 goto out;
514 }
515 if (gpmc_cs_mem_enabled(cs))
516 r = adjust_resource(res, res->start & ~(size - 1), size);
517 if (r < 0)
518 r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
519 size, NULL, NULL);
520 if (r < 0)
521 goto out;
522
Tobias Klauser6d135242009-11-10 18:55:19 -0800523 gpmc_cs_enable_mem(cs, res->start, resource_size(res));
Imre Deakf37e4582006-09-25 12:41:33 +0300524 *base = res->start;
525 gpmc_cs_set_reserved(cs, 1);
526out:
527 spin_unlock(&gpmc_mem_lock);
528 return r;
529}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300530EXPORT_SYMBOL(gpmc_cs_request);
Imre Deakf37e4582006-09-25 12:41:33 +0300531
532void gpmc_cs_free(int cs)
533{
534 spin_lock(&gpmc_mem_lock);
Roel Kluine7fdc602009-11-17 14:39:06 -0800535 if (cs >= GPMC_CS_NUM || cs < 0 || !gpmc_cs_reserved(cs)) {
Imre Deakf37e4582006-09-25 12:41:33 +0300536 printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
537 BUG();
538 spin_unlock(&gpmc_mem_lock);
539 return;
540 }
541 gpmc_cs_disable_mem(cs);
542 release_resource(&gpmc_cs_mem[cs]);
543 gpmc_cs_set_reserved(cs, 0);
544 spin_unlock(&gpmc_mem_lock);
545}
Paul Walmsleyfd1dc872008-10-06 15:49:17 +0300546EXPORT_SYMBOL(gpmc_cs_free);
Imre Deakf37e4582006-09-25 12:41:33 +0300547
vimal singh59e9c5a2009-07-13 16:26:24 +0530548/**
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000549 * gpmc_cs_configure - write request to configure gpmc
550 * @cs: chip select number
551 * @cmd: command type
552 * @wval: value to write
553 * @return status of the operation
554 */
555int gpmc_cs_configure(int cs, int cmd, int wval)
556{
557 int err = 0;
558 u32 regval = 0;
559
560 switch (cmd) {
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +0530561 case GPMC_ENABLE_IRQ:
562 gpmc_write_reg(GPMC_IRQENABLE, wval);
563 break;
564
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000565 case GPMC_SET_IRQ_STATUS:
566 gpmc_write_reg(GPMC_IRQSTATUS, wval);
567 break;
568
569 case GPMC_CONFIG_WP:
570 regval = gpmc_read_reg(GPMC_CONFIG);
571 if (wval)
572 regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
573 else
574 regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
575 gpmc_write_reg(GPMC_CONFIG, regval);
576 break;
577
578 case GPMC_CONFIG_RDY_BSY:
579 regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
580 if (wval)
581 regval |= WR_RD_PIN_MONITORING;
582 else
583 regval &= ~WR_RD_PIN_MONITORING;
584 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
585 break;
586
587 case GPMC_CONFIG_DEV_SIZE:
588 regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
Yegor Yefremov8ef5d842012-01-23 08:32:23 +0100589
590 /* clear 2 target bits */
591 regval &= ~GPMC_CONFIG1_DEVICESIZE(3);
592
593 /* set the proper value */
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000594 regval |= GPMC_CONFIG1_DEVICESIZE(wval);
Yegor Yefremov8ef5d842012-01-23 08:32:23 +0100595
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000596 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
597 break;
598
599 case GPMC_CONFIG_DEV_TYPE:
600 regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
Mark Jacksonc9fb8092013-03-05 10:13:40 +0000601 /* clear 4 target bits */
602 regval &= ~(GPMC_CONFIG1_DEVICETYPE(3) |
603 GPMC_CONFIG1_MUXTYPE(3));
604 /* set the proper value */
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000605 regval |= GPMC_CONFIG1_DEVICETYPE(wval);
606 if (wval == GPMC_DEVICETYPE_NOR)
607 regval |= GPMC_CONFIG1_MUXADDDATA;
608 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
609 break;
610
611 default:
612 printk(KERN_ERR "gpmc_configure_cs: Not supported\n");
613 err = -EINVAL;
614 }
615
616 return err;
617}
618EXPORT_SYMBOL(gpmc_cs_configure);
619
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700620void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
621{
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530622 int i;
623
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700624 reg->gpmc_status = gpmc_base + GPMC_STATUS;
625 reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
626 GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
627 reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
628 GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
629 reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
630 GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
631 reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
632 reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
633 reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
634 reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
635 reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
636 reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
637 reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
638 reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
Afzal Mohammed2fdf0c92012-10-04 15:49:04 +0530639
640 for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
641 reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
642 GPMC_BCH_SIZE * i;
643 reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
644 GPMC_BCH_SIZE * i;
645 reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
646 GPMC_BCH_SIZE * i;
647 reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
648 GPMC_BCH_SIZE * i;
649 }
Afzal Mohammed52bd1382012-08-30 12:53:22 -0700650}
651
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700652int gpmc_get_client_irq(unsigned irq_config)
653{
654 int i;
655
656 if (hweight32(irq_config) > 1)
657 return 0;
658
659 for (i = 0; i < GPMC_NR_IRQ; i++)
660 if (gpmc_client_irq[i].bitmask & irq_config)
661 return gpmc_client_irq[i].irq;
662
663 return 0;
664}
665
666static int gpmc_irq_endis(unsigned irq, bool endis)
667{
668 int i;
669 u32 regval;
670
671 for (i = 0; i < GPMC_NR_IRQ; i++)
672 if (irq == gpmc_client_irq[i].irq) {
673 regval = gpmc_read_reg(GPMC_IRQENABLE);
674 if (endis)
675 regval |= gpmc_client_irq[i].bitmask;
676 else
677 regval &= ~gpmc_client_irq[i].bitmask;
678 gpmc_write_reg(GPMC_IRQENABLE, regval);
679 break;
680 }
681
682 return 0;
683}
684
685static void gpmc_irq_disable(struct irq_data *p)
686{
687 gpmc_irq_endis(p->irq, false);
688}
689
690static void gpmc_irq_enable(struct irq_data *p)
691{
692 gpmc_irq_endis(p->irq, true);
693}
694
695static void gpmc_irq_noop(struct irq_data *data) { }
696
697static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
698
Afzal Mohammedda496872012-09-23 17:28:25 -0600699static int gpmc_setup_irq(void)
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700700{
701 int i;
702 u32 regval;
703
704 if (!gpmc_irq)
705 return -EINVAL;
706
707 gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
Russell King71856842013-03-13 20:44:21 +0000708 if (gpmc_irq_start < 0) {
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -0700709 pr_err("irq_alloc_descs failed\n");
710 return gpmc_irq_start;
711 }
712
713 gpmc_irq_chip.name = "gpmc";
714 gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
715 gpmc_irq_chip.irq_enable = gpmc_irq_enable;
716 gpmc_irq_chip.irq_disable = gpmc_irq_disable;
717 gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
718 gpmc_irq_chip.irq_ack = gpmc_irq_noop;
719 gpmc_irq_chip.irq_mask = gpmc_irq_noop;
720 gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
721
722 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
723 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
724
725 for (i = 0; i < GPMC_NR_IRQ; i++) {
726 gpmc_client_irq[i].irq = gpmc_irq_start + i;
727 irq_set_chip_and_handler(gpmc_client_irq[i].irq,
728 &gpmc_irq_chip, handle_simple_irq);
729 set_irq_flags(gpmc_client_irq[i].irq,
730 IRQF_VALID | IRQF_NOAUTOEN);
731 }
732
733 /* Disable interrupts */
734 gpmc_write_reg(GPMC_IRQENABLE, 0);
735
736 /* clear interrupts */
737 regval = gpmc_read_reg(GPMC_IRQSTATUS);
738 gpmc_write_reg(GPMC_IRQSTATUS, regval);
739
740 return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
741}
742
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800743static int gpmc_free_irq(void)
Afzal Mohammedda496872012-09-23 17:28:25 -0600744{
745 int i;
746
747 if (gpmc_irq)
748 free_irq(gpmc_irq, NULL);
749
750 for (i = 0; i < GPMC_NR_IRQ; i++) {
751 irq_set_handler(gpmc_client_irq[i].irq, NULL);
752 irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
753 irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
754 }
755
756 irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
757
758 return 0;
759}
760
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800761static void gpmc_mem_exit(void)
Afzal Mohammedda496872012-09-23 17:28:25 -0600762{
763 int cs;
764
765 for (cs = 0; cs < GPMC_CS_NUM; cs++) {
766 if (!gpmc_cs_mem_enabled(cs))
767 continue;
768 gpmc_cs_delete_mem(cs);
769 }
770
771}
772
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800773static int gpmc_mem_init(void)
Imre Deakf37e4582006-09-25 12:41:33 +0300774{
Jon Hunter81190242012-10-17 09:41:25 -0500775 int cs, rc;
Imre Deakf37e4582006-09-25 12:41:33 +0300776 unsigned long boot_rom_space = 0;
777
Kyungmin Park7f245162006-12-29 16:48:51 -0800778 /* never allocate the first page, to facilitate bug detection;
779 * even if we didn't boot from ROM.
780 */
781 boot_rom_space = BOOT_ROM_SPACE;
Imre Deakf37e4582006-09-25 12:41:33 +0300782 gpmc_mem_root.start = GPMC_MEM_START + boot_rom_space;
783 gpmc_mem_root.end = GPMC_MEM_END;
784
785 /* Reserve all regions that has been set up by bootloader */
786 for (cs = 0; cs < GPMC_CS_NUM; cs++) {
787 u32 base, size;
788
789 if (!gpmc_cs_mem_enabled(cs))
790 continue;
791 gpmc_cs_get_memconf(cs, &base, &size);
Jon Hunter81190242012-10-17 09:41:25 -0500792 rc = gpmc_cs_insert_mem(cs, base, size);
Russell King71856842013-03-13 20:44:21 +0000793 if (rc < 0) {
Jon Hunter81190242012-10-17 09:41:25 -0500794 while (--cs >= 0)
795 if (gpmc_cs_mem_enabled(cs))
796 gpmc_cs_delete_mem(cs);
797 return rc;
798 }
Imre Deakf37e4582006-09-25 12:41:33 +0300799 }
Jon Hunter81190242012-10-17 09:41:25 -0500800
801 return 0;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -0700802}
803
Afzal Mohammed246da262012-08-02 20:02:10 +0530804static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk)
805{
806 u32 temp;
807 int div;
808
809 div = gpmc_calc_divider(sync_clk);
810 temp = gpmc_ps_to_ticks(time_ps);
811 temp = (temp + div - 1) / div;
812 return gpmc_ticks_to_ps(temp * div);
813}
814
815/* XXX: can the cycles be avoided ? */
816static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t,
817 struct gpmc_device_timings *dev_t)
818{
819 bool mux = dev_t->mux;
820 u32 temp;
821
822 /* adv_rd_off */
823 temp = dev_t->t_avdp_r;
824 /* XXX: mux check required ? */
825 if (mux) {
826 /* XXX: t_avdp not to be required for sync, only added for tusb
827 * this indirectly necessitates requirement of t_avdp_r and
828 * t_avdp_w instead of having a single t_avdp
829 */
830 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh);
831 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
832 }
833 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
834
835 /* oe_on */
836 temp = dev_t->t_oeasu; /* XXX: remove this ? */
837 if (mux) {
838 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach);
839 temp = max_t(u32, temp, gpmc_t->adv_rd_off +
840 gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe));
841 }
842 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
843
844 /* access */
845 /* XXX: any scope for improvement ?, by combining oe_on
846 * and clk_activation, need to check whether
847 * access = clk_activation + round to sync clk ?
848 */
849 temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk);
850 temp += gpmc_t->clk_activation;
851 if (dev_t->cyc_oe)
852 temp = max_t(u32, temp, gpmc_t->oe_on +
853 gpmc_ticks_to_ps(dev_t->cyc_oe));
854 gpmc_t->access = gpmc_round_ps_to_ticks(temp);
855
856 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
857 gpmc_t->cs_rd_off = gpmc_t->oe_off;
858
859 /* rd_cycle */
860 temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez);
861 temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) +
862 gpmc_t->access;
863 /* XXX: barter t_ce_rdyz with t_cez_r ? */
864 if (dev_t->t_ce_rdyz)
865 temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz);
866 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
867
868 return 0;
869}
870
871static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t,
872 struct gpmc_device_timings *dev_t)
873{
874 bool mux = dev_t->mux;
875 u32 temp;
876
877 /* adv_wr_off */
878 temp = dev_t->t_avdp_w;
879 if (mux) {
880 temp = max_t(u32, temp,
881 gpmc_t->clk_activation + dev_t->t_avdh);
882 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
883 }
884 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
885
886 /* wr_data_mux_bus */
887 temp = max_t(u32, dev_t->t_weasu,
888 gpmc_t->clk_activation + dev_t->t_rdyo);
889 /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?,
890 * and in that case remember to handle we_on properly
891 */
892 if (mux) {
893 temp = max_t(u32, temp,
894 gpmc_t->adv_wr_off + dev_t->t_aavdh);
895 temp = max_t(u32, temp, gpmc_t->adv_wr_off +
896 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
897 }
898 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
899
900 /* we_on */
901 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
902 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
903 else
904 gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
905
906 /* wr_access */
907 /* XXX: gpmc_capability check reqd ? , even if not, will not harm */
908 gpmc_t->wr_access = gpmc_t->access;
909
910 /* we_off */
911 temp = gpmc_t->we_on + dev_t->t_wpl;
912 temp = max_t(u32, temp,
913 gpmc_t->wr_access + gpmc_ticks_to_ps(1));
914 temp = max_t(u32, temp,
915 gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl));
916 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
917
918 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
919 dev_t->t_wph);
920
921 /* wr_cycle */
922 temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk);
923 temp += gpmc_t->wr_access;
924 /* XXX: barter t_ce_rdyz with t_cez_w ? */
925 if (dev_t->t_ce_rdyz)
926 temp = max_t(u32, temp,
927 gpmc_t->cs_wr_off + dev_t->t_ce_rdyz);
928 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
929
930 return 0;
931}
932
933static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t,
934 struct gpmc_device_timings *dev_t)
935{
936 bool mux = dev_t->mux;
937 u32 temp;
938
939 /* adv_rd_off */
940 temp = dev_t->t_avdp_r;
941 if (mux)
942 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
943 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
944
945 /* oe_on */
946 temp = dev_t->t_oeasu;
947 if (mux)
948 temp = max_t(u32, temp,
949 gpmc_t->adv_rd_off + dev_t->t_aavdh);
950 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
951
952 /* access */
953 temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */
954 gpmc_t->oe_on + dev_t->t_oe);
955 temp = max_t(u32, temp,
956 gpmc_t->cs_on + dev_t->t_ce);
957 temp = max_t(u32, temp,
958 gpmc_t->adv_on + dev_t->t_aa);
959 gpmc_t->access = gpmc_round_ps_to_ticks(temp);
960
961 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
962 gpmc_t->cs_rd_off = gpmc_t->oe_off;
963
964 /* rd_cycle */
965 temp = max_t(u32, dev_t->t_rd_cycle,
966 gpmc_t->cs_rd_off + dev_t->t_cez_r);
967 temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez);
968 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
969
970 return 0;
971}
972
973static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t,
974 struct gpmc_device_timings *dev_t)
975{
976 bool mux = dev_t->mux;
977 u32 temp;
978
979 /* adv_wr_off */
980 temp = dev_t->t_avdp_w;
981 if (mux)
982 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
983 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
984
985 /* wr_data_mux_bus */
986 temp = dev_t->t_weasu;
987 if (mux) {
988 temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh);
989 temp = max_t(u32, temp, gpmc_t->adv_wr_off +
990 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
991 }
992 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
993
994 /* we_on */
995 if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
996 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
997 else
998 gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
999
1000 /* we_off */
1001 temp = gpmc_t->we_on + dev_t->t_wpl;
1002 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
1003
1004 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
1005 dev_t->t_wph);
1006
1007 /* wr_cycle */
1008 temp = max_t(u32, dev_t->t_wr_cycle,
1009 gpmc_t->cs_wr_off + dev_t->t_cez_w);
1010 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
1011
1012 return 0;
1013}
1014
1015static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t,
1016 struct gpmc_device_timings *dev_t)
1017{
1018 u32 temp;
1019
1020 gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) *
1021 gpmc_get_fclk_period();
1022
1023 gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk(
1024 dev_t->t_bacc,
1025 gpmc_t->sync_clk);
1026
1027 temp = max_t(u32, dev_t->t_ces, dev_t->t_avds);
1028 gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp);
1029
1030 if (gpmc_calc_divider(gpmc_t->sync_clk) != 1)
1031 return 0;
1032
1033 if (dev_t->ce_xdelay)
1034 gpmc_t->bool_timings.cs_extra_delay = true;
1035 if (dev_t->avd_xdelay)
1036 gpmc_t->bool_timings.adv_extra_delay = true;
1037 if (dev_t->oe_xdelay)
1038 gpmc_t->bool_timings.oe_extra_delay = true;
1039 if (dev_t->we_xdelay)
1040 gpmc_t->bool_timings.we_extra_delay = true;
1041
1042 return 0;
1043}
1044
1045static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t,
1046 struct gpmc_device_timings *dev_t)
1047{
1048 u32 temp;
1049
1050 /* cs_on */
1051 gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu);
1052
1053 /* adv_on */
1054 temp = dev_t->t_avdasu;
1055 if (dev_t->t_ce_avd)
1056 temp = max_t(u32, temp,
1057 gpmc_t->cs_on + dev_t->t_ce_avd);
1058 gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp);
1059
1060 if (dev_t->sync_write || dev_t->sync_read)
1061 gpmc_calc_sync_common_timings(gpmc_t, dev_t);
1062
1063 return 0;
1064}
1065
1066/* TODO: remove this function once all peripherals are confirmed to
1067 * work with generic timing. Simultaneously gpmc_cs_set_timings()
1068 * has to be modified to handle timings in ps instead of ns
1069*/
1070static void gpmc_convert_ps_to_ns(struct gpmc_timings *t)
1071{
1072 t->cs_on /= 1000;
1073 t->cs_rd_off /= 1000;
1074 t->cs_wr_off /= 1000;
1075 t->adv_on /= 1000;
1076 t->adv_rd_off /= 1000;
1077 t->adv_wr_off /= 1000;
1078 t->we_on /= 1000;
1079 t->we_off /= 1000;
1080 t->oe_on /= 1000;
1081 t->oe_off /= 1000;
1082 t->page_burst_access /= 1000;
1083 t->access /= 1000;
1084 t->rd_cycle /= 1000;
1085 t->wr_cycle /= 1000;
1086 t->bus_turnaround /= 1000;
1087 t->cycle2cycle_delay /= 1000;
1088 t->wait_monitoring /= 1000;
1089 t->clk_activation /= 1000;
1090 t->wr_access /= 1000;
1091 t->wr_data_mux_bus /= 1000;
1092}
1093
1094int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
1095 struct gpmc_device_timings *dev_t)
1096{
1097 memset(gpmc_t, 0, sizeof(*gpmc_t));
1098
1099 gpmc_calc_common_timings(gpmc_t, dev_t);
1100
1101 if (dev_t->sync_read)
1102 gpmc_calc_sync_read_timings(gpmc_t, dev_t);
1103 else
1104 gpmc_calc_async_read_timings(gpmc_t, dev_t);
1105
1106 if (dev_t->sync_write)
1107 gpmc_calc_sync_write_timings(gpmc_t, dev_t);
1108 else
1109 gpmc_calc_async_write_timings(gpmc_t, dev_t);
1110
1111 /* TODO: remove, see function definition */
1112 gpmc_convert_ps_to_ns(gpmc_t);
1113
1114 return 0;
1115}
1116
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001117#ifdef CONFIG_OF
1118static struct of_device_id gpmc_dt_ids[] = {
1119 { .compatible = "ti,omap2420-gpmc" },
1120 { .compatible = "ti,omap2430-gpmc" },
1121 { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
1122 { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
1123 { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
1124 { }
1125};
1126MODULE_DEVICE_TABLE(of, gpmc_dt_ids);
1127
1128static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
1129 struct gpmc_timings *gpmc_t)
1130{
1131 u32 val;
1132
1133 memset(gpmc_t, 0, sizeof(*gpmc_t));
1134
1135 /* minimum clock period for syncronous mode */
1136 if (!of_property_read_u32(np, "gpmc,sync-clk", &val))
1137 gpmc_t->sync_clk = val;
1138
1139 /* chip select timtings */
1140 if (!of_property_read_u32(np, "gpmc,cs-on", &val))
1141 gpmc_t->cs_on = val;
1142
1143 if (!of_property_read_u32(np, "gpmc,cs-rd-off", &val))
1144 gpmc_t->cs_rd_off = val;
1145
1146 if (!of_property_read_u32(np, "gpmc,cs-wr-off", &val))
1147 gpmc_t->cs_wr_off = val;
1148
1149 /* ADV signal timings */
1150 if (!of_property_read_u32(np, "gpmc,adv-on", &val))
1151 gpmc_t->adv_on = val;
1152
1153 if (!of_property_read_u32(np, "gpmc,adv-rd-off", &val))
1154 gpmc_t->adv_rd_off = val;
1155
1156 if (!of_property_read_u32(np, "gpmc,adv-wr-off", &val))
1157 gpmc_t->adv_wr_off = val;
1158
1159 /* WE signal timings */
1160 if (!of_property_read_u32(np, "gpmc,we-on", &val))
1161 gpmc_t->we_on = val;
1162
1163 if (!of_property_read_u32(np, "gpmc,we-off", &val))
1164 gpmc_t->we_off = val;
1165
1166 /* OE signal timings */
1167 if (!of_property_read_u32(np, "gpmc,oe-on", &val))
1168 gpmc_t->oe_on = val;
1169
1170 if (!of_property_read_u32(np, "gpmc,oe-off", &val))
1171 gpmc_t->oe_off = val;
1172
1173 /* access and cycle timings */
1174 if (!of_property_read_u32(np, "gpmc,page-burst-access", &val))
1175 gpmc_t->page_burst_access = val;
1176
1177 if (!of_property_read_u32(np, "gpmc,access", &val))
1178 gpmc_t->access = val;
1179
1180 if (!of_property_read_u32(np, "gpmc,rd-cycle", &val))
1181 gpmc_t->rd_cycle = val;
1182
1183 if (!of_property_read_u32(np, "gpmc,wr-cycle", &val))
1184 gpmc_t->wr_cycle = val;
1185
1186 /* only for OMAP3430 */
1187 if (!of_property_read_u32(np, "gpmc,wr-access", &val))
1188 gpmc_t->wr_access = val;
1189
1190 if (!of_property_read_u32(np, "gpmc,wr-data-mux-bus", &val))
1191 gpmc_t->wr_data_mux_bus = val;
1192}
1193
1194#ifdef CONFIG_MTD_NAND
1195
1196static const char * const nand_ecc_opts[] = {
1197 [OMAP_ECC_HAMMING_CODE_DEFAULT] = "sw",
1198 [OMAP_ECC_HAMMING_CODE_HW] = "hw",
1199 [OMAP_ECC_HAMMING_CODE_HW_ROMCODE] = "hw-romcode",
1200 [OMAP_ECC_BCH4_CODE_HW] = "bch4",
1201 [OMAP_ECC_BCH8_CODE_HW] = "bch8",
1202};
1203
1204static int gpmc_probe_nand_child(struct platform_device *pdev,
1205 struct device_node *child)
1206{
1207 u32 val;
1208 const char *s;
1209 struct gpmc_timings gpmc_t;
1210 struct omap_nand_platform_data *gpmc_nand_data;
1211
1212 if (of_property_read_u32(child, "reg", &val) < 0) {
1213 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1214 child->full_name);
1215 return -ENODEV;
1216 }
1217
1218 gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
1219 GFP_KERNEL);
1220 if (!gpmc_nand_data)
1221 return -ENOMEM;
1222
1223 gpmc_nand_data->cs = val;
1224 gpmc_nand_data->of_node = child;
1225
1226 if (!of_property_read_string(child, "ti,nand-ecc-opt", &s))
1227 for (val = 0; val < ARRAY_SIZE(nand_ecc_opts); val++)
1228 if (!strcasecmp(s, nand_ecc_opts[val])) {
1229 gpmc_nand_data->ecc_opt = val;
1230 break;
1231 }
1232
1233 val = of_get_nand_bus_width(child);
1234 if (val == 16)
1235 gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
1236
1237 gpmc_read_timings_dt(child, &gpmc_t);
1238 gpmc_nand_init(gpmc_nand_data, &gpmc_t);
1239
1240 return 0;
1241}
1242#else
1243static int gpmc_probe_nand_child(struct platform_device *pdev,
1244 struct device_node *child)
1245{
1246 return 0;
1247}
1248#endif
1249
Ezequiel Garcia75d36252013-01-25 09:23:11 -03001250#ifdef CONFIG_MTD_ONENAND
1251static int gpmc_probe_onenand_child(struct platform_device *pdev,
1252 struct device_node *child)
1253{
1254 u32 val;
1255 struct omap_onenand_platform_data *gpmc_onenand_data;
1256
1257 if (of_property_read_u32(child, "reg", &val) < 0) {
1258 dev_err(&pdev->dev, "%s has no 'reg' property\n",
1259 child->full_name);
1260 return -ENODEV;
1261 }
1262
1263 gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
1264 GFP_KERNEL);
1265 if (!gpmc_onenand_data)
1266 return -ENOMEM;
1267
1268 gpmc_onenand_data->cs = val;
1269 gpmc_onenand_data->of_node = child;
1270 gpmc_onenand_data->dma_channel = -1;
1271
1272 if (!of_property_read_u32(child, "dma-channel", &val))
1273 gpmc_onenand_data->dma_channel = val;
1274
1275 gpmc_onenand_init(gpmc_onenand_data);
1276
1277 return 0;
1278}
1279#else
1280static int gpmc_probe_onenand_child(struct platform_device *pdev,
1281 struct device_node *child)
1282{
1283 return 0;
1284}
1285#endif
1286
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001287static int gpmc_probe_dt(struct platform_device *pdev)
1288{
1289 int ret;
1290 struct device_node *child;
1291 const struct of_device_id *of_id =
1292 of_match_device(gpmc_dt_ids, &pdev->dev);
1293
1294 if (!of_id)
1295 return 0;
1296
1297 for_each_node_by_name(child, "nand") {
1298 ret = gpmc_probe_nand_child(pdev, child);
Ezequiel Garciaa1672372013-01-25 09:19:47 -03001299 if (ret < 0) {
1300 of_node_put(child);
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001301 return ret;
Ezequiel Garciaa1672372013-01-25 09:19:47 -03001302 }
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001303 }
1304
Ezequiel Garcia75d36252013-01-25 09:23:11 -03001305 for_each_node_by_name(child, "onenand") {
1306 ret = gpmc_probe_onenand_child(pdev, child);
1307 if (ret < 0) {
1308 of_node_put(child);
1309 return ret;
1310 }
1311 }
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001312 return 0;
1313}
1314#else
1315static int gpmc_probe_dt(struct platform_device *pdev)
1316{
1317 return 0;
1318}
1319#endif
1320
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001321static int gpmc_probe(struct platform_device *pdev)
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001322{
Jon Hunter81190242012-10-17 09:41:25 -05001323 int rc;
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001324 u32 l;
Afzal Mohammedda496872012-09-23 17:28:25 -06001325 struct resource *res;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001326
Afzal Mohammedda496872012-09-23 17:28:25 -06001327 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1328 if (res == NULL)
1329 return -ENOENT;
Paul Walmsleyfd1dc872008-10-06 15:49:17 +03001330
Afzal Mohammedda496872012-09-23 17:28:25 -06001331 phys_base = res->start;
1332 mem_size = resource_size(res);
Kevin Hilman8d084362010-01-29 14:20:06 -08001333
Thierry Reding5857bd92013-01-21 11:08:55 +01001334 gpmc_base = devm_ioremap_resource(&pdev->dev, res);
1335 if (IS_ERR(gpmc_base))
1336 return PTR_ERR(gpmc_base);
Afzal Mohammedda496872012-09-23 17:28:25 -06001337
1338 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1339 if (res == NULL)
1340 dev_warn(&pdev->dev, "Failed to get resource: irq\n");
1341 else
1342 gpmc_irq = res->start;
1343
1344 gpmc_l3_clk = clk_get(&pdev->dev, "fck");
1345 if (IS_ERR(gpmc_l3_clk)) {
1346 dev_err(&pdev->dev, "error: clk_get\n");
1347 gpmc_irq = 0;
1348 return PTR_ERR(gpmc_l3_clk);
Paul Walmsleyfd1dc872008-10-06 15:49:17 +03001349 }
1350
Rajendra Nayak4d7cb452012-09-22 02:24:16 -06001351 clk_prepare_enable(gpmc_l3_clk);
Olof Johansson1daa8c12010-01-20 22:39:29 +00001352
Afzal Mohammedda496872012-09-23 17:28:25 -06001353 gpmc_dev = &pdev->dev;
1354
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001355 l = gpmc_read_reg(GPMC_REVISION);
Afzal Mohammedda496872012-09-23 17:28:25 -06001356 if (GPMC_REVISION_MAJOR(l) > 0x4)
1357 gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
1358 dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
1359 GPMC_REVISION_MINOR(l));
1360
Jon Hunter81190242012-10-17 09:41:25 -05001361 rc = gpmc_mem_init();
Russell King71856842013-03-13 20:44:21 +00001362 if (rc < 0) {
Jon Hunter81190242012-10-17 09:41:25 -05001363 clk_disable_unprepare(gpmc_l3_clk);
1364 clk_put(gpmc_l3_clk);
1365 dev_err(gpmc_dev, "failed to reserve memory\n");
1366 return rc;
1367 }
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301368
Russell King71856842013-03-13 20:44:21 +00001369 if (gpmc_setup_irq() < 0)
Afzal Mohammedda496872012-09-23 17:28:25 -06001370 dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
1371
Jon Hunter31d9adc2013-02-18 07:57:39 -06001372 /* Now the GPMC is initialised, unreserve the chip-selects */
1373 gpmc_cs_map = 0;
1374
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001375 rc = gpmc_probe_dt(pdev);
1376 if (rc < 0) {
1377 clk_disable_unprepare(gpmc_l3_clk);
1378 clk_put(gpmc_l3_clk);
1379 dev_err(gpmc_dev, "failed to probe DT parameters\n");
1380 return rc;
1381 }
1382
Afzal Mohammedda496872012-09-23 17:28:25 -06001383 return 0;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301384}
Afzal Mohammedda496872012-09-23 17:28:25 -06001385
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001386static int gpmc_remove(struct platform_device *pdev)
Afzal Mohammedda496872012-09-23 17:28:25 -06001387{
1388 gpmc_free_irq();
1389 gpmc_mem_exit();
1390 gpmc_dev = NULL;
1391 return 0;
1392}
1393
1394static struct platform_driver gpmc_driver = {
1395 .probe = gpmc_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -08001396 .remove = gpmc_remove,
Afzal Mohammedda496872012-09-23 17:28:25 -06001397 .driver = {
1398 .name = DEVICE_NAME,
1399 .owner = THIS_MODULE,
Daniel Mackbc6b1e72012-12-14 11:36:44 +01001400 .of_match_table = of_match_ptr(gpmc_dt_ids),
Afzal Mohammedda496872012-09-23 17:28:25 -06001401 },
1402};
1403
1404static __init int gpmc_init(void)
1405{
1406 return platform_driver_register(&gpmc_driver);
1407}
1408
1409static __exit void gpmc_exit(void)
1410{
1411 platform_driver_unregister(&gpmc_driver);
1412
1413}
1414
Tony Lindgrenb76c8b12013-01-11 11:24:18 -08001415omap_postcore_initcall(gpmc_init);
Afzal Mohammedda496872012-09-23 17:28:25 -06001416module_exit(gpmc_exit);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301417
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001418static int __init omap_gpmc_init(void)
1419{
1420 struct omap_hwmod *oh;
1421 struct platform_device *pdev;
1422 char *oh_name = "gpmc";
1423
Daniel Mack2f98ca82012-12-14 11:36:40 +01001424 /*
1425 * if the board boots up with a populated DT, do not
1426 * manually add the device from this initcall
1427 */
1428 if (of_have_populated_dt())
1429 return -ENODEV;
1430
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001431 oh = omap_hwmod_lookup(oh_name);
1432 if (!oh) {
1433 pr_err("Could not look up %s\n", oh_name);
1434 return -ENODEV;
1435 }
1436
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -07001437 pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0);
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001438 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
1439
1440 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
1441}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -08001442omap_postcore_initcall(omap_gpmc_init);
Afzal Mohammed4be48fd2012-09-23 17:28:24 -06001443
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301444static irqreturn_t gpmc_handle_irq(int irq, void *dev)
1445{
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001446 int i;
1447 u32 regval;
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301448
Afzal Mohammed6b6c32f2012-08-30 12:53:23 -07001449 regval = gpmc_read_reg(GPMC_IRQSTATUS);
1450
1451 if (!regval)
1452 return IRQ_NONE;
1453
1454 for (i = 0; i < GPMC_NR_IRQ; i++)
1455 if (regval & gpmc_client_irq[i].bitmask)
1456 generic_handle_irq(gpmc_client_irq[i].irq);
1457
1458 gpmc_write_reg(GPMC_IRQSTATUS, regval);
Sukumar Ghoraidb97eb7d2011-01-28 15:42:05 +05301459
1460 return IRQ_HANDLED;
Juha Yrjola4bbbc1a2006-06-26 16:16:16 -07001461}
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301462
1463#ifdef CONFIG_ARCH_OMAP3
1464static struct omap3_gpmc_regs gpmc_context;
1465
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001466void omap3_gpmc_save_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301467{
1468 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001469
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301470 gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
1471 gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
1472 gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
1473 gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
1474 gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
1475 gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
1476 gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
1477 for (i = 0; i < GPMC_CS_NUM; i++) {
1478 gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
1479 if (gpmc_context.cs_context[i].is_valid) {
1480 gpmc_context.cs_context[i].config1 =
1481 gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
1482 gpmc_context.cs_context[i].config2 =
1483 gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
1484 gpmc_context.cs_context[i].config3 =
1485 gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
1486 gpmc_context.cs_context[i].config4 =
1487 gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
1488 gpmc_context.cs_context[i].config5 =
1489 gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
1490 gpmc_context.cs_context[i].config6 =
1491 gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
1492 gpmc_context.cs_context[i].config7 =
1493 gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
1494 }
1495 }
1496}
1497
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001498void omap3_gpmc_restore_context(void)
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301499{
1500 int i;
Felipe Balbib2fa3b72010-02-15 10:03:33 -08001501
Rajendra Nayaka2d3e7b2008-09-26 17:47:33 +05301502 gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
1503 gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
1504 gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
1505 gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
1506 gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
1507 gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
1508 gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
1509 for (i = 0; i < GPMC_CS_NUM; i++) {
1510 if (gpmc_context.cs_context[i].is_valid) {
1511 gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
1512 gpmc_context.cs_context[i].config1);
1513 gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
1514 gpmc_context.cs_context[i].config2);
1515 gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
1516 gpmc_context.cs_context[i].config3);
1517 gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
1518 gpmc_context.cs_context[i].config4);
1519 gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
1520 gpmc_context.cs_context[i].config5);
1521 gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
1522 gpmc_context.cs_context[i].config6);
1523 gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
1524 gpmc_context.cs_context[i].config7);
1525 }
1526 }
1527}
1528#endif /* CONFIG_ARCH_OMAP3 */