Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * GPMC support functions |
| 3 | * |
| 4 | * Copyright (C) 2005-2006 Nokia Corporation |
| 5 | * |
| 6 | * Author: Juha Yrjola |
| 7 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 8 | * Copyright (C) 2009 Texas Instruments |
| 9 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 10 | * |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 15 | #undef DEBUG |
| 16 | |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 17 | #include <linux/irq.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/clk.h> |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 22 | #include <linux/ioport.h> |
| 23 | #include <linux/spinlock.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 25 | #include <linux/module.h> |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 28 | #include <linux/of.h> |
| 29 | #include <linux/of_mtd.h> |
| 30 | #include <linux/of_device.h> |
| 31 | #include <linux/mtd/nand.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 32 | |
Afzal Mohammed | bc3668e | 2012-09-29 12:26:13 +0530 | [diff] [blame] | 33 | #include <linux/platform_data/mtd-nand-omap2.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 34 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 35 | #include <asm/mach-types.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 36 | |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 37 | #include "soc.h" |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 38 | #include "common.h" |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 39 | #include "omap_device.h" |
Afzal Mohammed | 3ef5d00 | 2012-10-05 10:37:27 +0530 | [diff] [blame] | 40 | #include "gpmc.h" |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 41 | #include "gpmc-nand.h" |
Ezequiel Garcia | 75d3625 | 2013-01-25 09:23:11 -0300 | [diff] [blame] | 42 | #include "gpmc-onenand.h" |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 43 | |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 44 | #define DEVICE_NAME "omap-gpmc" |
| 45 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 46 | /* GPMC register offsets */ |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 47 | #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 Gopinath | 15e02a3 | 2008-04-28 16:55:01 +0530 | [diff] [blame] | 59 | #define GPMC_PREFETCH_CONTROL 0x1ec |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 60 | #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 Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 64 | #define GPMC_ECC1_RESULT 0x200 |
Ivan Djelic | 8d602cf | 2012-04-26 14:17:49 +0200 | [diff] [blame] | 65 | #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */ |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 66 | #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 Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 69 | |
Yegor Yefremov | 2c65e74 | 2012-05-09 08:32:49 -0700 | [diff] [blame] | 70 | /* 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 Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 83 | #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 Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 90 | #define GPMC_CS0_OFFSET 0x60 |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 91 | #define GPMC_CS_SIZE 0x30 |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 92 | #define GPMC_BCH_SIZE 0x10 |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 93 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 94 | #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 singh | 59e9c5a | 2009-07-13 16:26:24 +0530 | [diff] [blame] | 101 | #define CS_NUM_SHIFT 24 |
| 102 | #define ENABLE_PREFETCH (0x1 << 7) |
| 103 | #define DMA_MPU_MODE 2 |
| 104 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 105 | #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 Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 111 | /* XXX: Only NAND irq has been considered,currently these are the only ones used |
| 112 | */ |
| 113 | #define GPMC_NR_IRQ 2 |
| 114 | |
| 115 | struct gpmc_client_irq { |
| 116 | unsigned irq; |
| 117 | u32 bitmask; |
| 118 | }; |
| 119 | |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 120 | /* Structure to save gpmc cs context */ |
| 121 | struct 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 | */ |
| 136 | struct 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 Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 147 | static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ]; |
| 148 | static struct irq_chip gpmc_irq_chip; |
| 149 | static unsigned gpmc_irq_start; |
| 150 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 151 | static struct resource gpmc_mem_root; |
| 152 | static struct resource gpmc_cs_mem[GPMC_CS_NUM]; |
Thomas Gleixner | 87b247c | 2007-05-10 22:33:04 -0700 | [diff] [blame] | 153 | static DEFINE_SPINLOCK(gpmc_mem_lock); |
Jon Hunter | 6797b4f | 2013-02-01 10:38:45 -0600 | [diff] [blame] | 154 | /* Define chip-selects as reserved by default until probe completes */ |
| 155 | static unsigned int gpmc_cs_map = ((1 << GPMC_CS_NUM) - 1); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 156 | static struct device *gpmc_dev; |
| 157 | static int gpmc_irq; |
| 158 | static resource_size_t phys_base, mem_size; |
| 159 | static unsigned gpmc_capability; |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 160 | static void __iomem *gpmc_base; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 161 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 162 | static struct clk *gpmc_l3_clk; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 163 | |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 164 | static irqreturn_t gpmc_handle_irq(int irq, void *dev); |
| 165 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 166 | static void gpmc_write_reg(int idx, u32 val) |
| 167 | { |
| 168 | __raw_writel(val, gpmc_base + idx); |
| 169 | } |
| 170 | |
| 171 | static u32 gpmc_read_reg(int idx) |
| 172 | { |
| 173 | return __raw_readl(gpmc_base + idx); |
| 174 | } |
| 175 | |
| 176 | void gpmc_cs_write_reg(int cs, int idx, u32 val) |
| 177 | { |
| 178 | void __iomem *reg_addr; |
| 179 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 180 | reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 181 | __raw_writel(val, reg_addr); |
| 182 | } |
| 183 | |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 184 | static u32 gpmc_cs_read_reg(int cs, int idx) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 185 | { |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 186 | void __iomem *reg_addr; |
| 187 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 188 | reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 189 | return __raw_readl(reg_addr); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 192 | /* TODO: Add support for gpmc_fck to clock framework and use it */ |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 193 | static unsigned long gpmc_get_fclk_period(void) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 194 | { |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 195 | 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 Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 208 | static unsigned int gpmc_ns_to_ticks(unsigned int time_ns) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 209 | { |
| 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 Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 218 | static unsigned int gpmc_ps_to_ticks(unsigned int time_ps) |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 219 | { |
| 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 Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 228 | unsigned int gpmc_ticks_to_ns(unsigned int ticks) |
| 229 | { |
| 230 | return ticks * gpmc_get_fclk_period() / 1000; |
| 231 | } |
| 232 | |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 233 | static unsigned int gpmc_ticks_to_ps(unsigned int ticks) |
| 234 | { |
| 235 | return ticks * gpmc_get_fclk_period(); |
| 236 | } |
| 237 | |
| 238 | static 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 Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 245 | static 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 | |
| 257 | static 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 Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 278 | #ifdef DEBUG |
| 279 | static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, |
Juha Yrjola | 2aab646 | 2006-06-26 16:16:21 -0700 | [diff] [blame] | 280 | int time, const char *name) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 281 | #else |
| 282 | static 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 Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 294 | 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 Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 299 | return -1; |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 300 | } |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 301 | |
| 302 | mask = (1 << nr_bits) - 1; |
| 303 | l = gpmc_cs_read_reg(cs, reg); |
| 304 | #ifdef DEBUG |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 305 | printk(KERN_INFO |
| 306 | "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n", |
Juha Yrjola | 2aab646 | 2006-06-26 16:16:21 -0700 | [diff] [blame] | 307 | cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000, |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 308 | (l >> st_bit) & mask, time); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 309 | #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 Mohammed | 1b47ca1 | 2012-08-19 18:29:45 +0530 | [diff] [blame] | 328 | int gpmc_calc_divider(unsigned int sync_clk) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 329 | { |
| 330 | int div; |
| 331 | u32 l; |
| 332 | |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 333 | l = sync_clk + (gpmc_get_fclk_period() - 1); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 334 | div = l / gpmc_get_fclk_period(); |
| 335 | if (div > 4) |
| 336 | return -1; |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 337 | if (div <= 0) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 338 | div = 1; |
| 339 | |
| 340 | return div; |
| 341 | } |
| 342 | |
| 343 | int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t) |
| 344 | { |
| 345 | int div; |
| 346 | u32 l; |
| 347 | |
Afzal Mohammed | 1b47ca1 | 2012-08-19 18:29:45 +0530 | [diff] [blame] | 348 | div = gpmc_calc_divider(t->sync_clk); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 349 | if (div < 0) |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 350 | return div; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 351 | |
| 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 Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 371 | 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 Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 377 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 378 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 379 | if (gpmc_capability & GPMC_HAS_WR_ACCESS) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 380 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access); |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 381 | |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 382 | /* caller is expected to have initialized CONFIG1 to cover |
| 383 | * at least sync vs async |
| 384 | */ |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 385 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 386 | 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 Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 395 | |
Afzal Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 396 | gpmc_cs_bool_timings(cs, &t->bool_timings); |
| 397 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 401 | static void gpmc_cs_enable_mem(int cs, u32 base, u32 size) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 402 | { |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 403 | 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 Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 412 | l |= GPMC_CONFIG7_CSVALID; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 413 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); |
| 414 | } |
| 415 | |
| 416 | static void gpmc_cs_disable_mem(int cs) |
| 417 | { |
| 418 | u32 l; |
| 419 | |
| 420 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 421 | l &= ~GPMC_CONFIG7_CSVALID; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 422 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); |
| 423 | } |
| 424 | |
| 425 | static 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 | |
| 436 | static int gpmc_cs_mem_enabled(int cs) |
| 437 | { |
| 438 | u32 l; |
| 439 | |
| 440 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 441 | return l & GPMC_CONFIG7_CSVALID; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 442 | } |
| 443 | |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 444 | static int gpmc_cs_set_reserved(int cs, int reserved) |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 445 | { |
Tony Lindgren | c40fae95 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 446 | if (cs > GPMC_CS_NUM) |
| 447 | return -ENODEV; |
| 448 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 449 | gpmc_cs_map &= ~(1 << cs); |
| 450 | gpmc_cs_map |= (reserved ? 1 : 0) << cs; |
Tony Lindgren | c40fae95 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 451 | |
| 452 | return 0; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 453 | } |
| 454 | |
Ezequiel Garcia | ae9d908 | 2013-02-12 16:22:19 -0300 | [diff] [blame^] | 455 | static bool gpmc_cs_reserved(int cs) |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 456 | { |
Tony Lindgren | c40fae95 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 457 | if (cs > GPMC_CS_NUM) |
Ezequiel Garcia | ae9d908 | 2013-02-12 16:22:19 -0300 | [diff] [blame^] | 458 | return true; |
Tony Lindgren | c40fae95 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 459 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 460 | return gpmc_cs_map & (1 << cs); |
| 461 | } |
| 462 | |
| 463 | static unsigned long gpmc_mem_align(unsigned long size) |
| 464 | { |
| 465 | int order; |
| 466 | |
| 467 | size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1); |
| 468 | order = GPMC_CHUNK_SHIFT - 1; |
| 469 | do { |
| 470 | size >>= 1; |
| 471 | order++; |
| 472 | } while (size); |
| 473 | size = 1 << order; |
| 474 | return size; |
| 475 | } |
| 476 | |
| 477 | static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size) |
| 478 | { |
| 479 | struct resource *res = &gpmc_cs_mem[cs]; |
| 480 | int r; |
| 481 | |
| 482 | size = gpmc_mem_align(size); |
| 483 | spin_lock(&gpmc_mem_lock); |
| 484 | res->start = base; |
| 485 | res->end = base + size - 1; |
| 486 | r = request_resource(&gpmc_mem_root, res); |
| 487 | spin_unlock(&gpmc_mem_lock); |
| 488 | |
| 489 | return r; |
| 490 | } |
| 491 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 492 | static int gpmc_cs_delete_mem(int cs) |
| 493 | { |
| 494 | struct resource *res = &gpmc_cs_mem[cs]; |
| 495 | int r; |
| 496 | |
| 497 | spin_lock(&gpmc_mem_lock); |
| 498 | r = release_resource(&gpmc_cs_mem[cs]); |
| 499 | res->start = 0; |
| 500 | res->end = 0; |
| 501 | spin_unlock(&gpmc_mem_lock); |
| 502 | |
| 503 | return r; |
| 504 | } |
| 505 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 506 | int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) |
| 507 | { |
| 508 | struct resource *res = &gpmc_cs_mem[cs]; |
| 509 | int r = -1; |
| 510 | |
| 511 | if (cs > GPMC_CS_NUM) |
| 512 | return -ENODEV; |
| 513 | |
| 514 | size = gpmc_mem_align(size); |
| 515 | if (size > (1 << GPMC_SECTION_SHIFT)) |
| 516 | return -ENOMEM; |
| 517 | |
| 518 | spin_lock(&gpmc_mem_lock); |
| 519 | if (gpmc_cs_reserved(cs)) { |
| 520 | r = -EBUSY; |
| 521 | goto out; |
| 522 | } |
| 523 | if (gpmc_cs_mem_enabled(cs)) |
| 524 | r = adjust_resource(res, res->start & ~(size - 1), size); |
| 525 | if (r < 0) |
| 526 | r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0, |
| 527 | size, NULL, NULL); |
| 528 | if (r < 0) |
| 529 | goto out; |
| 530 | |
Tobias Klauser | 6d13524 | 2009-11-10 18:55:19 -0800 | [diff] [blame] | 531 | gpmc_cs_enable_mem(cs, res->start, resource_size(res)); |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 532 | *base = res->start; |
| 533 | gpmc_cs_set_reserved(cs, 1); |
| 534 | out: |
| 535 | spin_unlock(&gpmc_mem_lock); |
| 536 | return r; |
| 537 | } |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 538 | EXPORT_SYMBOL(gpmc_cs_request); |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 539 | |
| 540 | void gpmc_cs_free(int cs) |
| 541 | { |
| 542 | spin_lock(&gpmc_mem_lock); |
Roel Kluin | e7fdc60 | 2009-11-17 14:39:06 -0800 | [diff] [blame] | 543 | if (cs >= GPMC_CS_NUM || cs < 0 || !gpmc_cs_reserved(cs)) { |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 544 | printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs); |
| 545 | BUG(); |
| 546 | spin_unlock(&gpmc_mem_lock); |
| 547 | return; |
| 548 | } |
| 549 | gpmc_cs_disable_mem(cs); |
| 550 | release_resource(&gpmc_cs_mem[cs]); |
| 551 | gpmc_cs_set_reserved(cs, 0); |
| 552 | spin_unlock(&gpmc_mem_lock); |
| 553 | } |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 554 | EXPORT_SYMBOL(gpmc_cs_free); |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 555 | |
vimal singh | 59e9c5a | 2009-07-13 16:26:24 +0530 | [diff] [blame] | 556 | /** |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 557 | * gpmc_cs_configure - write request to configure gpmc |
| 558 | * @cs: chip select number |
| 559 | * @cmd: command type |
| 560 | * @wval: value to write |
| 561 | * @return status of the operation |
| 562 | */ |
| 563 | int gpmc_cs_configure(int cs, int cmd, int wval) |
| 564 | { |
| 565 | int err = 0; |
| 566 | u32 regval = 0; |
| 567 | |
| 568 | switch (cmd) { |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 569 | case GPMC_ENABLE_IRQ: |
| 570 | gpmc_write_reg(GPMC_IRQENABLE, wval); |
| 571 | break; |
| 572 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 573 | case GPMC_SET_IRQ_STATUS: |
| 574 | gpmc_write_reg(GPMC_IRQSTATUS, wval); |
| 575 | break; |
| 576 | |
| 577 | case GPMC_CONFIG_WP: |
| 578 | regval = gpmc_read_reg(GPMC_CONFIG); |
| 579 | if (wval) |
| 580 | regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */ |
| 581 | else |
| 582 | regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */ |
| 583 | gpmc_write_reg(GPMC_CONFIG, regval); |
| 584 | break; |
| 585 | |
| 586 | case GPMC_CONFIG_RDY_BSY: |
| 587 | regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
| 588 | if (wval) |
| 589 | regval |= WR_RD_PIN_MONITORING; |
| 590 | else |
| 591 | regval &= ~WR_RD_PIN_MONITORING; |
| 592 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval); |
| 593 | break; |
| 594 | |
| 595 | case GPMC_CONFIG_DEV_SIZE: |
| 596 | regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
Yegor Yefremov | 8ef5d84 | 2012-01-23 08:32:23 +0100 | [diff] [blame] | 597 | |
| 598 | /* clear 2 target bits */ |
| 599 | regval &= ~GPMC_CONFIG1_DEVICESIZE(3); |
| 600 | |
| 601 | /* set the proper value */ |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 602 | regval |= GPMC_CONFIG1_DEVICESIZE(wval); |
Yegor Yefremov | 8ef5d84 | 2012-01-23 08:32:23 +0100 | [diff] [blame] | 603 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 604 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval); |
| 605 | break; |
| 606 | |
| 607 | case GPMC_CONFIG_DEV_TYPE: |
| 608 | regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
Mark Jackson | c9fb809 | 2013-03-05 10:13:40 +0000 | [diff] [blame] | 609 | /* clear 4 target bits */ |
| 610 | regval &= ~(GPMC_CONFIG1_DEVICETYPE(3) | |
| 611 | GPMC_CONFIG1_MUXTYPE(3)); |
| 612 | /* set the proper value */ |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 613 | regval |= GPMC_CONFIG1_DEVICETYPE(wval); |
| 614 | if (wval == GPMC_DEVICETYPE_NOR) |
| 615 | regval |= GPMC_CONFIG1_MUXADDDATA; |
| 616 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval); |
| 617 | break; |
| 618 | |
| 619 | default: |
| 620 | printk(KERN_ERR "gpmc_configure_cs: Not supported\n"); |
| 621 | err = -EINVAL; |
| 622 | } |
| 623 | |
| 624 | return err; |
| 625 | } |
| 626 | EXPORT_SYMBOL(gpmc_cs_configure); |
| 627 | |
Afzal Mohammed | 52bd138 | 2012-08-30 12:53:22 -0700 | [diff] [blame] | 628 | void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs) |
| 629 | { |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 630 | int i; |
| 631 | |
Afzal Mohammed | 52bd138 | 2012-08-30 12:53:22 -0700 | [diff] [blame] | 632 | reg->gpmc_status = gpmc_base + GPMC_STATUS; |
| 633 | reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET + |
| 634 | GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs; |
| 635 | reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET + |
| 636 | GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs; |
| 637 | reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET + |
| 638 | GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs; |
| 639 | reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1; |
| 640 | reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2; |
| 641 | reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL; |
| 642 | reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS; |
| 643 | reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG; |
| 644 | reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL; |
| 645 | reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG; |
| 646 | reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT; |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 647 | |
| 648 | for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) { |
| 649 | reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 + |
| 650 | GPMC_BCH_SIZE * i; |
| 651 | reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 + |
| 652 | GPMC_BCH_SIZE * i; |
| 653 | reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 + |
| 654 | GPMC_BCH_SIZE * i; |
| 655 | reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 + |
| 656 | GPMC_BCH_SIZE * i; |
| 657 | } |
Afzal Mohammed | 52bd138 | 2012-08-30 12:53:22 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 660 | int gpmc_get_client_irq(unsigned irq_config) |
| 661 | { |
| 662 | int i; |
| 663 | |
| 664 | if (hweight32(irq_config) > 1) |
| 665 | return 0; |
| 666 | |
| 667 | for (i = 0; i < GPMC_NR_IRQ; i++) |
| 668 | if (gpmc_client_irq[i].bitmask & irq_config) |
| 669 | return gpmc_client_irq[i].irq; |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static int gpmc_irq_endis(unsigned irq, bool endis) |
| 675 | { |
| 676 | int i; |
| 677 | u32 regval; |
| 678 | |
| 679 | for (i = 0; i < GPMC_NR_IRQ; i++) |
| 680 | if (irq == gpmc_client_irq[i].irq) { |
| 681 | regval = gpmc_read_reg(GPMC_IRQENABLE); |
| 682 | if (endis) |
| 683 | regval |= gpmc_client_irq[i].bitmask; |
| 684 | else |
| 685 | regval &= ~gpmc_client_irq[i].bitmask; |
| 686 | gpmc_write_reg(GPMC_IRQENABLE, regval); |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static void gpmc_irq_disable(struct irq_data *p) |
| 694 | { |
| 695 | gpmc_irq_endis(p->irq, false); |
| 696 | } |
| 697 | |
| 698 | static void gpmc_irq_enable(struct irq_data *p) |
| 699 | { |
| 700 | gpmc_irq_endis(p->irq, true); |
| 701 | } |
| 702 | |
| 703 | static void gpmc_irq_noop(struct irq_data *data) { } |
| 704 | |
| 705 | static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; } |
| 706 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 707 | static int gpmc_setup_irq(void) |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 708 | { |
| 709 | int i; |
| 710 | u32 regval; |
| 711 | |
| 712 | if (!gpmc_irq) |
| 713 | return -EINVAL; |
| 714 | |
| 715 | gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 716 | if (gpmc_irq_start < 0) { |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 717 | pr_err("irq_alloc_descs failed\n"); |
| 718 | return gpmc_irq_start; |
| 719 | } |
| 720 | |
| 721 | gpmc_irq_chip.name = "gpmc"; |
| 722 | gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret; |
| 723 | gpmc_irq_chip.irq_enable = gpmc_irq_enable; |
| 724 | gpmc_irq_chip.irq_disable = gpmc_irq_disable; |
| 725 | gpmc_irq_chip.irq_shutdown = gpmc_irq_noop; |
| 726 | gpmc_irq_chip.irq_ack = gpmc_irq_noop; |
| 727 | gpmc_irq_chip.irq_mask = gpmc_irq_noop; |
| 728 | gpmc_irq_chip.irq_unmask = gpmc_irq_noop; |
| 729 | |
| 730 | gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE; |
| 731 | gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT; |
| 732 | |
| 733 | for (i = 0; i < GPMC_NR_IRQ; i++) { |
| 734 | gpmc_client_irq[i].irq = gpmc_irq_start + i; |
| 735 | irq_set_chip_and_handler(gpmc_client_irq[i].irq, |
| 736 | &gpmc_irq_chip, handle_simple_irq); |
| 737 | set_irq_flags(gpmc_client_irq[i].irq, |
| 738 | IRQF_VALID | IRQF_NOAUTOEN); |
| 739 | } |
| 740 | |
| 741 | /* Disable interrupts */ |
| 742 | gpmc_write_reg(GPMC_IRQENABLE, 0); |
| 743 | |
| 744 | /* clear interrupts */ |
| 745 | regval = gpmc_read_reg(GPMC_IRQSTATUS); |
| 746 | gpmc_write_reg(GPMC_IRQSTATUS, regval); |
| 747 | |
| 748 | return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL); |
| 749 | } |
| 750 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 751 | static int gpmc_free_irq(void) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 752 | { |
| 753 | int i; |
| 754 | |
| 755 | if (gpmc_irq) |
| 756 | free_irq(gpmc_irq, NULL); |
| 757 | |
| 758 | for (i = 0; i < GPMC_NR_IRQ; i++) { |
| 759 | irq_set_handler(gpmc_client_irq[i].irq, NULL); |
| 760 | irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip); |
| 761 | irq_modify_status(gpmc_client_irq[i].irq, 0, 0); |
| 762 | } |
| 763 | |
| 764 | irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ); |
| 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 769 | static void gpmc_mem_exit(void) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 770 | { |
| 771 | int cs; |
| 772 | |
| 773 | for (cs = 0; cs < GPMC_CS_NUM; cs++) { |
| 774 | if (!gpmc_cs_mem_enabled(cs)) |
| 775 | continue; |
| 776 | gpmc_cs_delete_mem(cs); |
| 777 | } |
| 778 | |
| 779 | } |
| 780 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 781 | static int gpmc_mem_init(void) |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 782 | { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 783 | int cs, rc; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 784 | unsigned long boot_rom_space = 0; |
| 785 | |
Kyungmin Park | 7f24516 | 2006-12-29 16:48:51 -0800 | [diff] [blame] | 786 | /* never allocate the first page, to facilitate bug detection; |
| 787 | * even if we didn't boot from ROM. |
| 788 | */ |
| 789 | boot_rom_space = BOOT_ROM_SPACE; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 790 | gpmc_mem_root.start = GPMC_MEM_START + boot_rom_space; |
| 791 | gpmc_mem_root.end = GPMC_MEM_END; |
| 792 | |
| 793 | /* Reserve all regions that has been set up by bootloader */ |
| 794 | for (cs = 0; cs < GPMC_CS_NUM; cs++) { |
| 795 | u32 base, size; |
| 796 | |
| 797 | if (!gpmc_cs_mem_enabled(cs)) |
| 798 | continue; |
| 799 | gpmc_cs_get_memconf(cs, &base, &size); |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 800 | rc = gpmc_cs_insert_mem(cs, base, size); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 801 | if (rc < 0) { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 802 | while (--cs >= 0) |
| 803 | if (gpmc_cs_mem_enabled(cs)) |
| 804 | gpmc_cs_delete_mem(cs); |
| 805 | return rc; |
| 806 | } |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 807 | } |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 808 | |
| 809 | return 0; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 812 | static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk) |
| 813 | { |
| 814 | u32 temp; |
| 815 | int div; |
| 816 | |
| 817 | div = gpmc_calc_divider(sync_clk); |
| 818 | temp = gpmc_ps_to_ticks(time_ps); |
| 819 | temp = (temp + div - 1) / div; |
| 820 | return gpmc_ticks_to_ps(temp * div); |
| 821 | } |
| 822 | |
| 823 | /* XXX: can the cycles be avoided ? */ |
| 824 | static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t, |
| 825 | struct gpmc_device_timings *dev_t) |
| 826 | { |
| 827 | bool mux = dev_t->mux; |
| 828 | u32 temp; |
| 829 | |
| 830 | /* adv_rd_off */ |
| 831 | temp = dev_t->t_avdp_r; |
| 832 | /* XXX: mux check required ? */ |
| 833 | if (mux) { |
| 834 | /* XXX: t_avdp not to be required for sync, only added for tusb |
| 835 | * this indirectly necessitates requirement of t_avdp_r and |
| 836 | * t_avdp_w instead of having a single t_avdp |
| 837 | */ |
| 838 | temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh); |
| 839 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 840 | } |
| 841 | gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); |
| 842 | |
| 843 | /* oe_on */ |
| 844 | temp = dev_t->t_oeasu; /* XXX: remove this ? */ |
| 845 | if (mux) { |
| 846 | temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach); |
| 847 | temp = max_t(u32, temp, gpmc_t->adv_rd_off + |
| 848 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe)); |
| 849 | } |
| 850 | gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); |
| 851 | |
| 852 | /* access */ |
| 853 | /* XXX: any scope for improvement ?, by combining oe_on |
| 854 | * and clk_activation, need to check whether |
| 855 | * access = clk_activation + round to sync clk ? |
| 856 | */ |
| 857 | temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk); |
| 858 | temp += gpmc_t->clk_activation; |
| 859 | if (dev_t->cyc_oe) |
| 860 | temp = max_t(u32, temp, gpmc_t->oe_on + |
| 861 | gpmc_ticks_to_ps(dev_t->cyc_oe)); |
| 862 | gpmc_t->access = gpmc_round_ps_to_ticks(temp); |
| 863 | |
| 864 | gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); |
| 865 | gpmc_t->cs_rd_off = gpmc_t->oe_off; |
| 866 | |
| 867 | /* rd_cycle */ |
| 868 | temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez); |
| 869 | temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) + |
| 870 | gpmc_t->access; |
| 871 | /* XXX: barter t_ce_rdyz with t_cez_r ? */ |
| 872 | if (dev_t->t_ce_rdyz) |
| 873 | temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz); |
| 874 | gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t, |
| 880 | struct gpmc_device_timings *dev_t) |
| 881 | { |
| 882 | bool mux = dev_t->mux; |
| 883 | u32 temp; |
| 884 | |
| 885 | /* adv_wr_off */ |
| 886 | temp = dev_t->t_avdp_w; |
| 887 | if (mux) { |
| 888 | temp = max_t(u32, temp, |
| 889 | gpmc_t->clk_activation + dev_t->t_avdh); |
| 890 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 891 | } |
| 892 | gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); |
| 893 | |
| 894 | /* wr_data_mux_bus */ |
| 895 | temp = max_t(u32, dev_t->t_weasu, |
| 896 | gpmc_t->clk_activation + dev_t->t_rdyo); |
| 897 | /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?, |
| 898 | * and in that case remember to handle we_on properly |
| 899 | */ |
| 900 | if (mux) { |
| 901 | temp = max_t(u32, temp, |
| 902 | gpmc_t->adv_wr_off + dev_t->t_aavdh); |
| 903 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + |
| 904 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); |
| 905 | } |
| 906 | gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); |
| 907 | |
| 908 | /* we_on */ |
| 909 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) |
| 910 | gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); |
| 911 | else |
| 912 | gpmc_t->we_on = gpmc_t->wr_data_mux_bus; |
| 913 | |
| 914 | /* wr_access */ |
| 915 | /* XXX: gpmc_capability check reqd ? , even if not, will not harm */ |
| 916 | gpmc_t->wr_access = gpmc_t->access; |
| 917 | |
| 918 | /* we_off */ |
| 919 | temp = gpmc_t->we_on + dev_t->t_wpl; |
| 920 | temp = max_t(u32, temp, |
| 921 | gpmc_t->wr_access + gpmc_ticks_to_ps(1)); |
| 922 | temp = max_t(u32, temp, |
| 923 | gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl)); |
| 924 | gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); |
| 925 | |
| 926 | gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + |
| 927 | dev_t->t_wph); |
| 928 | |
| 929 | /* wr_cycle */ |
| 930 | temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk); |
| 931 | temp += gpmc_t->wr_access; |
| 932 | /* XXX: barter t_ce_rdyz with t_cez_w ? */ |
| 933 | if (dev_t->t_ce_rdyz) |
| 934 | temp = max_t(u32, temp, |
| 935 | gpmc_t->cs_wr_off + dev_t->t_ce_rdyz); |
| 936 | gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t, |
| 942 | struct gpmc_device_timings *dev_t) |
| 943 | { |
| 944 | bool mux = dev_t->mux; |
| 945 | u32 temp; |
| 946 | |
| 947 | /* adv_rd_off */ |
| 948 | temp = dev_t->t_avdp_r; |
| 949 | if (mux) |
| 950 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 951 | gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); |
| 952 | |
| 953 | /* oe_on */ |
| 954 | temp = dev_t->t_oeasu; |
| 955 | if (mux) |
| 956 | temp = max_t(u32, temp, |
| 957 | gpmc_t->adv_rd_off + dev_t->t_aavdh); |
| 958 | gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); |
| 959 | |
| 960 | /* access */ |
| 961 | temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */ |
| 962 | gpmc_t->oe_on + dev_t->t_oe); |
| 963 | temp = max_t(u32, temp, |
| 964 | gpmc_t->cs_on + dev_t->t_ce); |
| 965 | temp = max_t(u32, temp, |
| 966 | gpmc_t->adv_on + dev_t->t_aa); |
| 967 | gpmc_t->access = gpmc_round_ps_to_ticks(temp); |
| 968 | |
| 969 | gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); |
| 970 | gpmc_t->cs_rd_off = gpmc_t->oe_off; |
| 971 | |
| 972 | /* rd_cycle */ |
| 973 | temp = max_t(u32, dev_t->t_rd_cycle, |
| 974 | gpmc_t->cs_rd_off + dev_t->t_cez_r); |
| 975 | temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez); |
| 976 | gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); |
| 977 | |
| 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t, |
| 982 | struct gpmc_device_timings *dev_t) |
| 983 | { |
| 984 | bool mux = dev_t->mux; |
| 985 | u32 temp; |
| 986 | |
| 987 | /* adv_wr_off */ |
| 988 | temp = dev_t->t_avdp_w; |
| 989 | if (mux) |
| 990 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 991 | gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); |
| 992 | |
| 993 | /* wr_data_mux_bus */ |
| 994 | temp = dev_t->t_weasu; |
| 995 | if (mux) { |
| 996 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh); |
| 997 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + |
| 998 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); |
| 999 | } |
| 1000 | gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); |
| 1001 | |
| 1002 | /* we_on */ |
| 1003 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) |
| 1004 | gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); |
| 1005 | else |
| 1006 | gpmc_t->we_on = gpmc_t->wr_data_mux_bus; |
| 1007 | |
| 1008 | /* we_off */ |
| 1009 | temp = gpmc_t->we_on + dev_t->t_wpl; |
| 1010 | gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); |
| 1011 | |
| 1012 | gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + |
| 1013 | dev_t->t_wph); |
| 1014 | |
| 1015 | /* wr_cycle */ |
| 1016 | temp = max_t(u32, dev_t->t_wr_cycle, |
| 1017 | gpmc_t->cs_wr_off + dev_t->t_cez_w); |
| 1018 | gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t, |
| 1024 | struct gpmc_device_timings *dev_t) |
| 1025 | { |
| 1026 | u32 temp; |
| 1027 | |
| 1028 | gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) * |
| 1029 | gpmc_get_fclk_period(); |
| 1030 | |
| 1031 | gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk( |
| 1032 | dev_t->t_bacc, |
| 1033 | gpmc_t->sync_clk); |
| 1034 | |
| 1035 | temp = max_t(u32, dev_t->t_ces, dev_t->t_avds); |
| 1036 | gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp); |
| 1037 | |
| 1038 | if (gpmc_calc_divider(gpmc_t->sync_clk) != 1) |
| 1039 | return 0; |
| 1040 | |
| 1041 | if (dev_t->ce_xdelay) |
| 1042 | gpmc_t->bool_timings.cs_extra_delay = true; |
| 1043 | if (dev_t->avd_xdelay) |
| 1044 | gpmc_t->bool_timings.adv_extra_delay = true; |
| 1045 | if (dev_t->oe_xdelay) |
| 1046 | gpmc_t->bool_timings.oe_extra_delay = true; |
| 1047 | if (dev_t->we_xdelay) |
| 1048 | gpmc_t->bool_timings.we_extra_delay = true; |
| 1049 | |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
| 1053 | static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t, |
| 1054 | struct gpmc_device_timings *dev_t) |
| 1055 | { |
| 1056 | u32 temp; |
| 1057 | |
| 1058 | /* cs_on */ |
| 1059 | gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu); |
| 1060 | |
| 1061 | /* adv_on */ |
| 1062 | temp = dev_t->t_avdasu; |
| 1063 | if (dev_t->t_ce_avd) |
| 1064 | temp = max_t(u32, temp, |
| 1065 | gpmc_t->cs_on + dev_t->t_ce_avd); |
| 1066 | gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp); |
| 1067 | |
| 1068 | if (dev_t->sync_write || dev_t->sync_read) |
| 1069 | gpmc_calc_sync_common_timings(gpmc_t, dev_t); |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | /* TODO: remove this function once all peripherals are confirmed to |
| 1075 | * work with generic timing. Simultaneously gpmc_cs_set_timings() |
| 1076 | * has to be modified to handle timings in ps instead of ns |
| 1077 | */ |
| 1078 | static void gpmc_convert_ps_to_ns(struct gpmc_timings *t) |
| 1079 | { |
| 1080 | t->cs_on /= 1000; |
| 1081 | t->cs_rd_off /= 1000; |
| 1082 | t->cs_wr_off /= 1000; |
| 1083 | t->adv_on /= 1000; |
| 1084 | t->adv_rd_off /= 1000; |
| 1085 | t->adv_wr_off /= 1000; |
| 1086 | t->we_on /= 1000; |
| 1087 | t->we_off /= 1000; |
| 1088 | t->oe_on /= 1000; |
| 1089 | t->oe_off /= 1000; |
| 1090 | t->page_burst_access /= 1000; |
| 1091 | t->access /= 1000; |
| 1092 | t->rd_cycle /= 1000; |
| 1093 | t->wr_cycle /= 1000; |
| 1094 | t->bus_turnaround /= 1000; |
| 1095 | t->cycle2cycle_delay /= 1000; |
| 1096 | t->wait_monitoring /= 1000; |
| 1097 | t->clk_activation /= 1000; |
| 1098 | t->wr_access /= 1000; |
| 1099 | t->wr_data_mux_bus /= 1000; |
| 1100 | } |
| 1101 | |
| 1102 | int gpmc_calc_timings(struct gpmc_timings *gpmc_t, |
| 1103 | struct gpmc_device_timings *dev_t) |
| 1104 | { |
| 1105 | memset(gpmc_t, 0, sizeof(*gpmc_t)); |
| 1106 | |
| 1107 | gpmc_calc_common_timings(gpmc_t, dev_t); |
| 1108 | |
| 1109 | if (dev_t->sync_read) |
| 1110 | gpmc_calc_sync_read_timings(gpmc_t, dev_t); |
| 1111 | else |
| 1112 | gpmc_calc_async_read_timings(gpmc_t, dev_t); |
| 1113 | |
| 1114 | if (dev_t->sync_write) |
| 1115 | gpmc_calc_sync_write_timings(gpmc_t, dev_t); |
| 1116 | else |
| 1117 | gpmc_calc_async_write_timings(gpmc_t, dev_t); |
| 1118 | |
| 1119 | /* TODO: remove, see function definition */ |
| 1120 | gpmc_convert_ps_to_ns(gpmc_t); |
| 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1125 | #ifdef CONFIG_OF |
| 1126 | static struct of_device_id gpmc_dt_ids[] = { |
| 1127 | { .compatible = "ti,omap2420-gpmc" }, |
| 1128 | { .compatible = "ti,omap2430-gpmc" }, |
| 1129 | { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */ |
| 1130 | { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */ |
| 1131 | { .compatible = "ti,am3352-gpmc" }, /* am335x devices */ |
| 1132 | { } |
| 1133 | }; |
| 1134 | MODULE_DEVICE_TABLE(of, gpmc_dt_ids); |
| 1135 | |
| 1136 | static void __maybe_unused gpmc_read_timings_dt(struct device_node *np, |
| 1137 | struct gpmc_timings *gpmc_t) |
| 1138 | { |
| 1139 | u32 val; |
| 1140 | |
| 1141 | memset(gpmc_t, 0, sizeof(*gpmc_t)); |
| 1142 | |
| 1143 | /* minimum clock period for syncronous mode */ |
| 1144 | if (!of_property_read_u32(np, "gpmc,sync-clk", &val)) |
| 1145 | gpmc_t->sync_clk = val; |
| 1146 | |
| 1147 | /* chip select timtings */ |
| 1148 | if (!of_property_read_u32(np, "gpmc,cs-on", &val)) |
| 1149 | gpmc_t->cs_on = val; |
| 1150 | |
| 1151 | if (!of_property_read_u32(np, "gpmc,cs-rd-off", &val)) |
| 1152 | gpmc_t->cs_rd_off = val; |
| 1153 | |
| 1154 | if (!of_property_read_u32(np, "gpmc,cs-wr-off", &val)) |
| 1155 | gpmc_t->cs_wr_off = val; |
| 1156 | |
| 1157 | /* ADV signal timings */ |
| 1158 | if (!of_property_read_u32(np, "gpmc,adv-on", &val)) |
| 1159 | gpmc_t->adv_on = val; |
| 1160 | |
| 1161 | if (!of_property_read_u32(np, "gpmc,adv-rd-off", &val)) |
| 1162 | gpmc_t->adv_rd_off = val; |
| 1163 | |
| 1164 | if (!of_property_read_u32(np, "gpmc,adv-wr-off", &val)) |
| 1165 | gpmc_t->adv_wr_off = val; |
| 1166 | |
| 1167 | /* WE signal timings */ |
| 1168 | if (!of_property_read_u32(np, "gpmc,we-on", &val)) |
| 1169 | gpmc_t->we_on = val; |
| 1170 | |
| 1171 | if (!of_property_read_u32(np, "gpmc,we-off", &val)) |
| 1172 | gpmc_t->we_off = val; |
| 1173 | |
| 1174 | /* OE signal timings */ |
| 1175 | if (!of_property_read_u32(np, "gpmc,oe-on", &val)) |
| 1176 | gpmc_t->oe_on = val; |
| 1177 | |
| 1178 | if (!of_property_read_u32(np, "gpmc,oe-off", &val)) |
| 1179 | gpmc_t->oe_off = val; |
| 1180 | |
| 1181 | /* access and cycle timings */ |
| 1182 | if (!of_property_read_u32(np, "gpmc,page-burst-access", &val)) |
| 1183 | gpmc_t->page_burst_access = val; |
| 1184 | |
| 1185 | if (!of_property_read_u32(np, "gpmc,access", &val)) |
| 1186 | gpmc_t->access = val; |
| 1187 | |
| 1188 | if (!of_property_read_u32(np, "gpmc,rd-cycle", &val)) |
| 1189 | gpmc_t->rd_cycle = val; |
| 1190 | |
| 1191 | if (!of_property_read_u32(np, "gpmc,wr-cycle", &val)) |
| 1192 | gpmc_t->wr_cycle = val; |
| 1193 | |
| 1194 | /* only for OMAP3430 */ |
| 1195 | if (!of_property_read_u32(np, "gpmc,wr-access", &val)) |
| 1196 | gpmc_t->wr_access = val; |
| 1197 | |
| 1198 | if (!of_property_read_u32(np, "gpmc,wr-data-mux-bus", &val)) |
| 1199 | gpmc_t->wr_data_mux_bus = val; |
| 1200 | } |
| 1201 | |
| 1202 | #ifdef CONFIG_MTD_NAND |
| 1203 | |
| 1204 | static const char * const nand_ecc_opts[] = { |
| 1205 | [OMAP_ECC_HAMMING_CODE_DEFAULT] = "sw", |
| 1206 | [OMAP_ECC_HAMMING_CODE_HW] = "hw", |
| 1207 | [OMAP_ECC_HAMMING_CODE_HW_ROMCODE] = "hw-romcode", |
| 1208 | [OMAP_ECC_BCH4_CODE_HW] = "bch4", |
| 1209 | [OMAP_ECC_BCH8_CODE_HW] = "bch8", |
| 1210 | }; |
| 1211 | |
| 1212 | static int gpmc_probe_nand_child(struct platform_device *pdev, |
| 1213 | struct device_node *child) |
| 1214 | { |
| 1215 | u32 val; |
| 1216 | const char *s; |
| 1217 | struct gpmc_timings gpmc_t; |
| 1218 | struct omap_nand_platform_data *gpmc_nand_data; |
| 1219 | |
| 1220 | if (of_property_read_u32(child, "reg", &val) < 0) { |
| 1221 | dev_err(&pdev->dev, "%s has no 'reg' property\n", |
| 1222 | child->full_name); |
| 1223 | return -ENODEV; |
| 1224 | } |
| 1225 | |
| 1226 | gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data), |
| 1227 | GFP_KERNEL); |
| 1228 | if (!gpmc_nand_data) |
| 1229 | return -ENOMEM; |
| 1230 | |
| 1231 | gpmc_nand_data->cs = val; |
| 1232 | gpmc_nand_data->of_node = child; |
| 1233 | |
| 1234 | if (!of_property_read_string(child, "ti,nand-ecc-opt", &s)) |
| 1235 | for (val = 0; val < ARRAY_SIZE(nand_ecc_opts); val++) |
| 1236 | if (!strcasecmp(s, nand_ecc_opts[val])) { |
| 1237 | gpmc_nand_data->ecc_opt = val; |
| 1238 | break; |
| 1239 | } |
| 1240 | |
| 1241 | val = of_get_nand_bus_width(child); |
| 1242 | if (val == 16) |
| 1243 | gpmc_nand_data->devsize = NAND_BUSWIDTH_16; |
| 1244 | |
| 1245 | gpmc_read_timings_dt(child, &gpmc_t); |
| 1246 | gpmc_nand_init(gpmc_nand_data, &gpmc_t); |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | #else |
| 1251 | static int gpmc_probe_nand_child(struct platform_device *pdev, |
| 1252 | struct device_node *child) |
| 1253 | { |
| 1254 | return 0; |
| 1255 | } |
| 1256 | #endif |
| 1257 | |
Ezequiel Garcia | 75d3625 | 2013-01-25 09:23:11 -0300 | [diff] [blame] | 1258 | #ifdef CONFIG_MTD_ONENAND |
| 1259 | static int gpmc_probe_onenand_child(struct platform_device *pdev, |
| 1260 | struct device_node *child) |
| 1261 | { |
| 1262 | u32 val; |
| 1263 | struct omap_onenand_platform_data *gpmc_onenand_data; |
| 1264 | |
| 1265 | if (of_property_read_u32(child, "reg", &val) < 0) { |
| 1266 | dev_err(&pdev->dev, "%s has no 'reg' property\n", |
| 1267 | child->full_name); |
| 1268 | return -ENODEV; |
| 1269 | } |
| 1270 | |
| 1271 | gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data), |
| 1272 | GFP_KERNEL); |
| 1273 | if (!gpmc_onenand_data) |
| 1274 | return -ENOMEM; |
| 1275 | |
| 1276 | gpmc_onenand_data->cs = val; |
| 1277 | gpmc_onenand_data->of_node = child; |
| 1278 | gpmc_onenand_data->dma_channel = -1; |
| 1279 | |
| 1280 | if (!of_property_read_u32(child, "dma-channel", &val)) |
| 1281 | gpmc_onenand_data->dma_channel = val; |
| 1282 | |
| 1283 | gpmc_onenand_init(gpmc_onenand_data); |
| 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | #else |
| 1288 | static int gpmc_probe_onenand_child(struct platform_device *pdev, |
| 1289 | struct device_node *child) |
| 1290 | { |
| 1291 | return 0; |
| 1292 | } |
| 1293 | #endif |
| 1294 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1295 | static int gpmc_probe_dt(struct platform_device *pdev) |
| 1296 | { |
| 1297 | int ret; |
| 1298 | struct device_node *child; |
| 1299 | const struct of_device_id *of_id = |
| 1300 | of_match_device(gpmc_dt_ids, &pdev->dev); |
| 1301 | |
| 1302 | if (!of_id) |
| 1303 | return 0; |
| 1304 | |
| 1305 | for_each_node_by_name(child, "nand") { |
| 1306 | ret = gpmc_probe_nand_child(pdev, child); |
Ezequiel Garcia | a167237 | 2013-01-25 09:19:47 -0300 | [diff] [blame] | 1307 | if (ret < 0) { |
| 1308 | of_node_put(child); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1309 | return ret; |
Ezequiel Garcia | a167237 | 2013-01-25 09:19:47 -0300 | [diff] [blame] | 1310 | } |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
Ezequiel Garcia | 75d3625 | 2013-01-25 09:23:11 -0300 | [diff] [blame] | 1313 | for_each_node_by_name(child, "onenand") { |
| 1314 | ret = gpmc_probe_onenand_child(pdev, child); |
| 1315 | if (ret < 0) { |
| 1316 | of_node_put(child); |
| 1317 | return ret; |
| 1318 | } |
| 1319 | } |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
| 1322 | #else |
| 1323 | static int gpmc_probe_dt(struct platform_device *pdev) |
| 1324 | { |
| 1325 | return 0; |
| 1326 | } |
| 1327 | #endif |
| 1328 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 1329 | static int gpmc_probe(struct platform_device *pdev) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1330 | { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 1331 | int rc; |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 1332 | u32 l; |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1333 | struct resource *res; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1334 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1335 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1336 | if (res == NULL) |
| 1337 | return -ENOENT; |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 1338 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1339 | phys_base = res->start; |
| 1340 | mem_size = resource_size(res); |
Kevin Hilman | 8d08436 | 2010-01-29 14:20:06 -0800 | [diff] [blame] | 1341 | |
Thierry Reding | 5857bd9 | 2013-01-21 11:08:55 +0100 | [diff] [blame] | 1342 | gpmc_base = devm_ioremap_resource(&pdev->dev, res); |
| 1343 | if (IS_ERR(gpmc_base)) |
| 1344 | return PTR_ERR(gpmc_base); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1345 | |
| 1346 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1347 | if (res == NULL) |
| 1348 | dev_warn(&pdev->dev, "Failed to get resource: irq\n"); |
| 1349 | else |
| 1350 | gpmc_irq = res->start; |
| 1351 | |
| 1352 | gpmc_l3_clk = clk_get(&pdev->dev, "fck"); |
| 1353 | if (IS_ERR(gpmc_l3_clk)) { |
| 1354 | dev_err(&pdev->dev, "error: clk_get\n"); |
| 1355 | gpmc_irq = 0; |
| 1356 | return PTR_ERR(gpmc_l3_clk); |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 1357 | } |
| 1358 | |
Rajendra Nayak | 4d7cb45 | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 1359 | clk_prepare_enable(gpmc_l3_clk); |
Olof Johansson | 1daa8c1 | 2010-01-20 22:39:29 +0000 | [diff] [blame] | 1360 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1361 | gpmc_dev = &pdev->dev; |
| 1362 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1363 | l = gpmc_read_reg(GPMC_REVISION); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1364 | if (GPMC_REVISION_MAJOR(l) > 0x4) |
| 1365 | gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS; |
| 1366 | dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l), |
| 1367 | GPMC_REVISION_MINOR(l)); |
| 1368 | |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 1369 | rc = gpmc_mem_init(); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 1370 | if (rc < 0) { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 1371 | clk_disable_unprepare(gpmc_l3_clk); |
| 1372 | clk_put(gpmc_l3_clk); |
| 1373 | dev_err(gpmc_dev, "failed to reserve memory\n"); |
| 1374 | return rc; |
| 1375 | } |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1376 | |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 1377 | if (gpmc_setup_irq() < 0) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1378 | dev_warn(gpmc_dev, "gpmc_setup_irq failed\n"); |
| 1379 | |
Jon Hunter | 31d9adc | 2013-02-18 07:57:39 -0600 | [diff] [blame] | 1380 | /* Now the GPMC is initialised, unreserve the chip-selects */ |
| 1381 | gpmc_cs_map = 0; |
| 1382 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1383 | rc = gpmc_probe_dt(pdev); |
| 1384 | if (rc < 0) { |
| 1385 | clk_disable_unprepare(gpmc_l3_clk); |
| 1386 | clk_put(gpmc_l3_clk); |
| 1387 | dev_err(gpmc_dev, "failed to probe DT parameters\n"); |
| 1388 | return rc; |
| 1389 | } |
| 1390 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1391 | return 0; |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1392 | } |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1393 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 1394 | static int gpmc_remove(struct platform_device *pdev) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1395 | { |
| 1396 | gpmc_free_irq(); |
| 1397 | gpmc_mem_exit(); |
| 1398 | gpmc_dev = NULL; |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
| 1402 | static struct platform_driver gpmc_driver = { |
| 1403 | .probe = gpmc_probe, |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 1404 | .remove = gpmc_remove, |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1405 | .driver = { |
| 1406 | .name = DEVICE_NAME, |
| 1407 | .owner = THIS_MODULE, |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1408 | .of_match_table = of_match_ptr(gpmc_dt_ids), |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1409 | }, |
| 1410 | }; |
| 1411 | |
| 1412 | static __init int gpmc_init(void) |
| 1413 | { |
| 1414 | return platform_driver_register(&gpmc_driver); |
| 1415 | } |
| 1416 | |
| 1417 | static __exit void gpmc_exit(void) |
| 1418 | { |
| 1419 | platform_driver_unregister(&gpmc_driver); |
| 1420 | |
| 1421 | } |
| 1422 | |
Tony Lindgren | b76c8b19 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 1423 | omap_postcore_initcall(gpmc_init); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1424 | module_exit(gpmc_exit); |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1425 | |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1426 | static int __init omap_gpmc_init(void) |
| 1427 | { |
| 1428 | struct omap_hwmod *oh; |
| 1429 | struct platform_device *pdev; |
| 1430 | char *oh_name = "gpmc"; |
| 1431 | |
Daniel Mack | 2f98ca8 | 2012-12-14 11:36:40 +0100 | [diff] [blame] | 1432 | /* |
| 1433 | * if the board boots up with a populated DT, do not |
| 1434 | * manually add the device from this initcall |
| 1435 | */ |
| 1436 | if (of_have_populated_dt()) |
| 1437 | return -ENODEV; |
| 1438 | |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1439 | oh = omap_hwmod_lookup(oh_name); |
| 1440 | if (!oh) { |
| 1441 | pr_err("Could not look up %s\n", oh_name); |
| 1442 | return -ENODEV; |
| 1443 | } |
| 1444 | |
Paul Walmsley | c1d1cd5 | 2013-01-26 00:48:53 -0700 | [diff] [blame] | 1445 | pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0); |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1446 | WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name); |
| 1447 | |
| 1448 | return IS_ERR(pdev) ? PTR_ERR(pdev) : 0; |
| 1449 | } |
Tony Lindgren | b76c8b19 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 1450 | omap_postcore_initcall(omap_gpmc_init); |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1451 | |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1452 | static irqreturn_t gpmc_handle_irq(int irq, void *dev) |
| 1453 | { |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 1454 | int i; |
| 1455 | u32 regval; |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1456 | |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 1457 | regval = gpmc_read_reg(GPMC_IRQSTATUS); |
| 1458 | |
| 1459 | if (!regval) |
| 1460 | return IRQ_NONE; |
| 1461 | |
| 1462 | for (i = 0; i < GPMC_NR_IRQ; i++) |
| 1463 | if (regval & gpmc_client_irq[i].bitmask) |
| 1464 | generic_handle_irq(gpmc_client_irq[i].irq); |
| 1465 | |
| 1466 | gpmc_write_reg(GPMC_IRQSTATUS, regval); |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1467 | |
| 1468 | return IRQ_HANDLED; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1469 | } |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1470 | |
| 1471 | #ifdef CONFIG_ARCH_OMAP3 |
| 1472 | static struct omap3_gpmc_regs gpmc_context; |
| 1473 | |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1474 | void omap3_gpmc_save_context(void) |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1475 | { |
| 1476 | int i; |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1477 | |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1478 | gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG); |
| 1479 | gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE); |
| 1480 | gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL); |
| 1481 | gpmc_context.config = gpmc_read_reg(GPMC_CONFIG); |
| 1482 | gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1); |
| 1483 | gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2); |
| 1484 | gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL); |
| 1485 | for (i = 0; i < GPMC_CS_NUM; i++) { |
| 1486 | gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i); |
| 1487 | if (gpmc_context.cs_context[i].is_valid) { |
| 1488 | gpmc_context.cs_context[i].config1 = |
| 1489 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG1); |
| 1490 | gpmc_context.cs_context[i].config2 = |
| 1491 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG2); |
| 1492 | gpmc_context.cs_context[i].config3 = |
| 1493 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG3); |
| 1494 | gpmc_context.cs_context[i].config4 = |
| 1495 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG4); |
| 1496 | gpmc_context.cs_context[i].config5 = |
| 1497 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG5); |
| 1498 | gpmc_context.cs_context[i].config6 = |
| 1499 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG6); |
| 1500 | gpmc_context.cs_context[i].config7 = |
| 1501 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG7); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1506 | void omap3_gpmc_restore_context(void) |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1507 | { |
| 1508 | int i; |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1509 | |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1510 | gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig); |
| 1511 | gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable); |
| 1512 | gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl); |
| 1513 | gpmc_write_reg(GPMC_CONFIG, gpmc_context.config); |
| 1514 | gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1); |
| 1515 | gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2); |
| 1516 | gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control); |
| 1517 | for (i = 0; i < GPMC_CS_NUM; i++) { |
| 1518 | if (gpmc_context.cs_context[i].is_valid) { |
| 1519 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG1, |
| 1520 | gpmc_context.cs_context[i].config1); |
| 1521 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG2, |
| 1522 | gpmc_context.cs_context[i].config2); |
| 1523 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG3, |
| 1524 | gpmc_context.cs_context[i].config3); |
| 1525 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG4, |
| 1526 | gpmc_context.cs_context[i].config4); |
| 1527 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG5, |
| 1528 | gpmc_context.cs_context[i].config5); |
| 1529 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG6, |
| 1530 | gpmc_context.cs_context[i].config6); |
| 1531 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG7, |
| 1532 | gpmc_context.cs_context[i].config7); |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | #endif /* CONFIG_ARCH_OMAP3 */ |