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