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> |
Jon Hunter | cdd6928 | 2013-02-08 16:46:13 -0600 | [diff] [blame^] | 29 | #include <linux/of_address.h> |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 30 | #include <linux/of_mtd.h> |
| 31 | #include <linux/of_device.h> |
| 32 | #include <linux/mtd/nand.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 33 | |
Afzal Mohammed | bc3668e | 2012-09-29 12:26:13 +0530 | [diff] [blame] | 34 | #include <linux/platform_data/mtd-nand-omap2.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 35 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 36 | #include <asm/mach-types.h> |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 37 | |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 38 | #include "soc.h" |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 39 | #include "common.h" |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 40 | #include "omap_device.h" |
Afzal Mohammed | 3ef5d00 | 2012-10-05 10:37:27 +0530 | [diff] [blame] | 41 | #include "gpmc.h" |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 42 | #include "gpmc-nand.h" |
Ezequiel Garcia | 75d3625 | 2013-01-25 09:23:11 -0300 | [diff] [blame] | 43 | #include "gpmc-onenand.h" |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 44 | |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 45 | #define DEVICE_NAME "omap-gpmc" |
| 46 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 47 | /* GPMC register offsets */ |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 48 | #define GPMC_REVISION 0x00 |
| 49 | #define GPMC_SYSCONFIG 0x10 |
| 50 | #define GPMC_SYSSTATUS 0x14 |
| 51 | #define GPMC_IRQSTATUS 0x18 |
| 52 | #define GPMC_IRQENABLE 0x1c |
| 53 | #define GPMC_TIMEOUT_CONTROL 0x40 |
| 54 | #define GPMC_ERR_ADDRESS 0x44 |
| 55 | #define GPMC_ERR_TYPE 0x48 |
| 56 | #define GPMC_CONFIG 0x50 |
| 57 | #define GPMC_STATUS 0x54 |
| 58 | #define GPMC_PREFETCH_CONFIG1 0x1e0 |
| 59 | #define GPMC_PREFETCH_CONFIG2 0x1e4 |
Thara Gopinath | 15e02a3 | 2008-04-28 16:55:01 +0530 | [diff] [blame] | 60 | #define GPMC_PREFETCH_CONTROL 0x1ec |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 61 | #define GPMC_PREFETCH_STATUS 0x1f0 |
| 62 | #define GPMC_ECC_CONFIG 0x1f4 |
| 63 | #define GPMC_ECC_CONTROL 0x1f8 |
| 64 | #define GPMC_ECC_SIZE_CONFIG 0x1fc |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 65 | #define GPMC_ECC1_RESULT 0x200 |
Ivan Djelic | 8d602cf | 2012-04-26 14:17:49 +0200 | [diff] [blame] | 66 | #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */ |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 67 | #define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */ |
| 68 | #define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */ |
| 69 | #define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */ |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 70 | |
Yegor Yefremov | 2c65e74 | 2012-05-09 08:32:49 -0700 | [diff] [blame] | 71 | /* GPMC ECC control settings */ |
| 72 | #define GPMC_ECC_CTRL_ECCCLEAR 0x100 |
| 73 | #define GPMC_ECC_CTRL_ECCDISABLE 0x000 |
| 74 | #define GPMC_ECC_CTRL_ECCREG1 0x001 |
| 75 | #define GPMC_ECC_CTRL_ECCREG2 0x002 |
| 76 | #define GPMC_ECC_CTRL_ECCREG3 0x003 |
| 77 | #define GPMC_ECC_CTRL_ECCREG4 0x004 |
| 78 | #define GPMC_ECC_CTRL_ECCREG5 0x005 |
| 79 | #define GPMC_ECC_CTRL_ECCREG6 0x006 |
| 80 | #define GPMC_ECC_CTRL_ECCREG7 0x007 |
| 81 | #define GPMC_ECC_CTRL_ECCREG8 0x008 |
| 82 | #define GPMC_ECC_CTRL_ECCREG9 0x009 |
| 83 | |
Afzal Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 84 | #define GPMC_CONFIG2_CSEXTRADELAY BIT(7) |
| 85 | #define GPMC_CONFIG3_ADVEXTRADELAY BIT(7) |
| 86 | #define GPMC_CONFIG4_OEEXTRADELAY BIT(7) |
| 87 | #define GPMC_CONFIG4_WEEXTRADELAY BIT(23) |
| 88 | #define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6) |
| 89 | #define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7) |
| 90 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 91 | #define GPMC_CS0_OFFSET 0x60 |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 92 | #define GPMC_CS_SIZE 0x30 |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 93 | #define GPMC_BCH_SIZE 0x10 |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 94 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 95 | #define GPMC_MEM_START 0x00000000 |
| 96 | #define GPMC_MEM_END 0x3FFFFFFF |
| 97 | #define BOOT_ROM_SPACE 0x100000 /* 1MB */ |
| 98 | |
| 99 | #define GPMC_CHUNK_SHIFT 24 /* 16 MB */ |
| 100 | #define GPMC_SECTION_SHIFT 28 /* 128 MB */ |
| 101 | |
vimal singh | 59e9c5a | 2009-07-13 16:26:24 +0530 | [diff] [blame] | 102 | #define CS_NUM_SHIFT 24 |
| 103 | #define ENABLE_PREFETCH (0x1 << 7) |
| 104 | #define DMA_MPU_MODE 2 |
| 105 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 106 | #define GPMC_REVISION_MAJOR(l) ((l >> 4) & 0xf) |
| 107 | #define GPMC_REVISION_MINOR(l) (l & 0xf) |
| 108 | |
| 109 | #define GPMC_HAS_WR_ACCESS 0x1 |
| 110 | #define GPMC_HAS_WR_DATA_MUX_BUS 0x2 |
Jon Hunter | aa8d476 | 2013-02-21 15:25:23 -0600 | [diff] [blame] | 111 | #define GPMC_HAS_MUX_AAD 0x4 |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 112 | |
Jon Hunter | 9f83315 | 2013-02-20 15:53:38 -0600 | [diff] [blame] | 113 | #define GPMC_NR_WAITPINS 4 |
| 114 | |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 115 | /* XXX: Only NAND irq has been considered,currently these are the only ones used |
| 116 | */ |
| 117 | #define GPMC_NR_IRQ 2 |
| 118 | |
| 119 | struct gpmc_client_irq { |
| 120 | unsigned irq; |
| 121 | u32 bitmask; |
| 122 | }; |
| 123 | |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 124 | /* Structure to save gpmc cs context */ |
| 125 | struct gpmc_cs_config { |
| 126 | u32 config1; |
| 127 | u32 config2; |
| 128 | u32 config3; |
| 129 | u32 config4; |
| 130 | u32 config5; |
| 131 | u32 config6; |
| 132 | u32 config7; |
| 133 | int is_valid; |
| 134 | }; |
| 135 | |
| 136 | /* |
| 137 | * Structure to save/restore gpmc context |
| 138 | * to support core off on OMAP3 |
| 139 | */ |
| 140 | struct omap3_gpmc_regs { |
| 141 | u32 sysconfig; |
| 142 | u32 irqenable; |
| 143 | u32 timeout_ctrl; |
| 144 | u32 config; |
| 145 | u32 prefetch_config1; |
| 146 | u32 prefetch_config2; |
| 147 | u32 prefetch_control; |
| 148 | struct gpmc_cs_config cs_context[GPMC_CS_NUM]; |
| 149 | }; |
| 150 | |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 151 | static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ]; |
| 152 | static struct irq_chip gpmc_irq_chip; |
| 153 | static unsigned gpmc_irq_start; |
| 154 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 155 | static struct resource gpmc_mem_root; |
| 156 | static struct resource gpmc_cs_mem[GPMC_CS_NUM]; |
Thomas Gleixner | 87b247c | 2007-05-10 22:33:04 -0700 | [diff] [blame] | 157 | static DEFINE_SPINLOCK(gpmc_mem_lock); |
Jon Hunter | 6797b4f | 2013-02-01 10:38:45 -0600 | [diff] [blame] | 158 | /* Define chip-selects as reserved by default until probe completes */ |
| 159 | static unsigned int gpmc_cs_map = ((1 << GPMC_CS_NUM) - 1); |
Jon Hunter | 9f83315 | 2013-02-20 15:53:38 -0600 | [diff] [blame] | 160 | static unsigned int gpmc_nr_waitpins; |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 161 | static struct device *gpmc_dev; |
| 162 | static int gpmc_irq; |
| 163 | static resource_size_t phys_base, mem_size; |
| 164 | static unsigned gpmc_capability; |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 165 | static void __iomem *gpmc_base; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 166 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 167 | static struct clk *gpmc_l3_clk; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 168 | |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 169 | static irqreturn_t gpmc_handle_irq(int irq, void *dev); |
| 170 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 171 | static void gpmc_write_reg(int idx, u32 val) |
| 172 | { |
| 173 | __raw_writel(val, gpmc_base + idx); |
| 174 | } |
| 175 | |
| 176 | static u32 gpmc_read_reg(int idx) |
| 177 | { |
| 178 | return __raw_readl(gpmc_base + idx); |
| 179 | } |
| 180 | |
| 181 | void gpmc_cs_write_reg(int cs, int idx, u32 val) |
| 182 | { |
| 183 | void __iomem *reg_addr; |
| 184 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 185 | reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 186 | __raw_writel(val, reg_addr); |
| 187 | } |
| 188 | |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 189 | static u32 gpmc_cs_read_reg(int cs, int idx) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 190 | { |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 191 | void __iomem *reg_addr; |
| 192 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 193 | reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 194 | return __raw_readl(reg_addr); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 197 | /* TODO: Add support for gpmc_fck to clock framework and use it */ |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 198 | static unsigned long gpmc_get_fclk_period(void) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 199 | { |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 200 | unsigned long rate = clk_get_rate(gpmc_l3_clk); |
| 201 | |
| 202 | if (rate == 0) { |
| 203 | printk(KERN_WARNING "gpmc_l3_clk not enabled\n"); |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | rate /= 1000; |
| 208 | rate = 1000000000 / rate; /* In picoseconds */ |
| 209 | |
| 210 | return rate; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 213 | static unsigned int gpmc_ns_to_ticks(unsigned int time_ns) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 214 | { |
| 215 | unsigned long tick_ps; |
| 216 | |
| 217 | /* Calculate in picosecs to yield more exact results */ |
| 218 | tick_ps = gpmc_get_fclk_period(); |
| 219 | |
| 220 | return (time_ns * 1000 + tick_ps - 1) / tick_ps; |
| 221 | } |
| 222 | |
Ezequiel Garcia | 3fc089e | 2013-02-12 16:22:17 -0300 | [diff] [blame] | 223 | static unsigned int gpmc_ps_to_ticks(unsigned int time_ps) |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 224 | { |
| 225 | unsigned long tick_ps; |
| 226 | |
| 227 | /* Calculate in picosecs to yield more exact results */ |
| 228 | tick_ps = gpmc_get_fclk_period(); |
| 229 | |
| 230 | return (time_ps + tick_ps - 1) / tick_ps; |
| 231 | } |
| 232 | |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 233 | unsigned int gpmc_ticks_to_ns(unsigned int ticks) |
| 234 | { |
| 235 | return ticks * gpmc_get_fclk_period() / 1000; |
| 236 | } |
| 237 | |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 238 | static unsigned int gpmc_ticks_to_ps(unsigned int ticks) |
| 239 | { |
| 240 | return ticks * gpmc_get_fclk_period(); |
| 241 | } |
| 242 | |
| 243 | static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps) |
| 244 | { |
| 245 | unsigned long ticks = gpmc_ps_to_ticks(time_ps); |
| 246 | |
| 247 | return ticks * gpmc_get_fclk_period(); |
| 248 | } |
| 249 | |
Afzal Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 250 | static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value) |
| 251 | { |
| 252 | u32 l; |
| 253 | |
| 254 | l = gpmc_cs_read_reg(cs, reg); |
| 255 | if (value) |
| 256 | l |= mask; |
| 257 | else |
| 258 | l &= ~mask; |
| 259 | gpmc_cs_write_reg(cs, reg, l); |
| 260 | } |
| 261 | |
| 262 | static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p) |
| 263 | { |
| 264 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1, |
| 265 | GPMC_CONFIG1_TIME_PARA_GRAN, |
| 266 | p->time_para_granularity); |
| 267 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2, |
| 268 | GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay); |
| 269 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3, |
| 270 | GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay); |
| 271 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4, |
| 272 | GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay); |
| 273 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4, |
| 274 | GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay); |
| 275 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6, |
| 276 | GPMC_CONFIG6_CYCLE2CYCLESAMECSEN, |
| 277 | p->cycle2cyclesamecsen); |
| 278 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6, |
| 279 | GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN, |
| 280 | p->cycle2cyclediffcsen); |
| 281 | } |
| 282 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 283 | #ifdef DEBUG |
| 284 | 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] | 285 | int time, const char *name) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 286 | #else |
| 287 | static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, |
| 288 | int time) |
| 289 | #endif |
| 290 | { |
| 291 | u32 l; |
| 292 | int ticks, mask, nr_bits; |
| 293 | |
| 294 | if (time == 0) |
| 295 | ticks = 0; |
| 296 | else |
| 297 | ticks = gpmc_ns_to_ticks(time); |
| 298 | nr_bits = end_bit - st_bit + 1; |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 299 | if (ticks >= 1 << nr_bits) { |
| 300 | #ifdef DEBUG |
| 301 | printk(KERN_INFO "GPMC CS%d: %-10s* %3d ns, %3d ticks >= %d\n", |
| 302 | cs, name, time, ticks, 1 << nr_bits); |
| 303 | #endif |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 304 | return -1; |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 305 | } |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 306 | |
| 307 | mask = (1 << nr_bits) - 1; |
| 308 | l = gpmc_cs_read_reg(cs, reg); |
| 309 | #ifdef DEBUG |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 310 | printk(KERN_INFO |
| 311 | "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] | 312 | cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000, |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 313 | (l >> st_bit) & mask, time); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 314 | #endif |
| 315 | l &= ~(mask << st_bit); |
| 316 | l |= ticks << st_bit; |
| 317 | gpmc_cs_write_reg(cs, reg, l); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | #ifdef DEBUG |
| 323 | #define GPMC_SET_ONE(reg, st, end, field) \ |
| 324 | if (set_gpmc_timing_reg(cs, (reg), (st), (end), \ |
| 325 | t->field, #field) < 0) \ |
| 326 | return -1 |
| 327 | #else |
| 328 | #define GPMC_SET_ONE(reg, st, end, field) \ |
| 329 | if (set_gpmc_timing_reg(cs, (reg), (st), (end), t->field) < 0) \ |
| 330 | return -1 |
| 331 | #endif |
| 332 | |
Afzal Mohammed | 1b47ca1 | 2012-08-19 18:29:45 +0530 | [diff] [blame] | 333 | int gpmc_calc_divider(unsigned int sync_clk) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 334 | { |
| 335 | int div; |
| 336 | u32 l; |
| 337 | |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 338 | l = sync_clk + (gpmc_get_fclk_period() - 1); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 339 | div = l / gpmc_get_fclk_period(); |
| 340 | if (div > 4) |
| 341 | return -1; |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 342 | if (div <= 0) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 343 | div = 1; |
| 344 | |
| 345 | return div; |
| 346 | } |
| 347 | |
| 348 | int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t) |
| 349 | { |
| 350 | int div; |
| 351 | u32 l; |
| 352 | |
Afzal Mohammed | 1b47ca1 | 2012-08-19 18:29:45 +0530 | [diff] [blame] | 353 | div = gpmc_calc_divider(t->sync_clk); |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 354 | if (div < 0) |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 355 | return div; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 356 | |
| 357 | GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on); |
| 358 | GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off); |
| 359 | GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off); |
| 360 | |
| 361 | GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on); |
| 362 | GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off); |
| 363 | GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off); |
| 364 | |
| 365 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on); |
| 366 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off); |
| 367 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on); |
| 368 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off); |
| 369 | |
| 370 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle); |
| 371 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle); |
| 372 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access); |
| 373 | |
| 374 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access); |
| 375 | |
Afzal Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 376 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround); |
| 377 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay); |
| 378 | |
| 379 | GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring); |
| 380 | GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation); |
| 381 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 382 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 383 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 384 | if (gpmc_capability & GPMC_HAS_WR_ACCESS) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 385 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access); |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 386 | |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 387 | /* caller is expected to have initialized CONFIG1 to cover |
| 388 | * at least sync vs async |
| 389 | */ |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 390 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
David Brownell | 1c22cc1 | 2006-12-06 17:13:55 -0800 | [diff] [blame] | 391 | if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) { |
| 392 | #ifdef DEBUG |
| 393 | printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n", |
| 394 | cs, (div * gpmc_get_fclk_period()) / 1000, div); |
| 395 | #endif |
| 396 | l &= ~0x03; |
| 397 | l |= (div - 1); |
| 398 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l); |
| 399 | } |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 400 | |
Afzal Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 401 | gpmc_cs_bool_timings(cs, &t->bool_timings); |
| 402 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 403 | return 0; |
| 404 | } |
| 405 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 406 | static void gpmc_cs_enable_mem(int cs, u32 base, u32 size) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 407 | { |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 408 | u32 l; |
| 409 | u32 mask; |
| 410 | |
| 411 | mask = (1 << GPMC_SECTION_SHIFT) - size; |
| 412 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); |
| 413 | l &= ~0x3f; |
| 414 | l = (base >> GPMC_CHUNK_SHIFT) & 0x3f; |
| 415 | l &= ~(0x0f << 8); |
| 416 | l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8; |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 417 | l |= GPMC_CONFIG7_CSVALID; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 418 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); |
| 419 | } |
| 420 | |
| 421 | static void gpmc_cs_disable_mem(int cs) |
| 422 | { |
| 423 | u32 l; |
| 424 | |
| 425 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 426 | l &= ~GPMC_CONFIG7_CSVALID; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 427 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); |
| 428 | } |
| 429 | |
| 430 | static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size) |
| 431 | { |
| 432 | u32 l; |
| 433 | u32 mask; |
| 434 | |
| 435 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); |
| 436 | *base = (l & 0x3f) << GPMC_CHUNK_SHIFT; |
| 437 | mask = (l >> 8) & 0x0f; |
| 438 | *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT); |
| 439 | } |
| 440 | |
| 441 | static int gpmc_cs_mem_enabled(int cs) |
| 442 | { |
| 443 | u32 l; |
| 444 | |
| 445 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 446 | return l & GPMC_CONFIG7_CSVALID; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 447 | } |
| 448 | |
Ezequiel Garcia | f5d8eda | 2013-02-12 16:22:24 -0300 | [diff] [blame] | 449 | static void gpmc_cs_set_reserved(int cs, int reserved) |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 450 | { |
| 451 | gpmc_cs_map &= ~(1 << cs); |
| 452 | gpmc_cs_map |= (reserved ? 1 : 0) << cs; |
| 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 | { |
| 457 | return gpmc_cs_map & (1 << cs); |
| 458 | } |
| 459 | |
| 460 | static unsigned long gpmc_mem_align(unsigned long size) |
| 461 | { |
| 462 | int order; |
| 463 | |
| 464 | size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1); |
| 465 | order = GPMC_CHUNK_SHIFT - 1; |
| 466 | do { |
| 467 | size >>= 1; |
| 468 | order++; |
| 469 | } while (size); |
| 470 | size = 1 << order; |
| 471 | return size; |
| 472 | } |
| 473 | |
| 474 | static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size) |
| 475 | { |
| 476 | struct resource *res = &gpmc_cs_mem[cs]; |
| 477 | int r; |
| 478 | |
| 479 | size = gpmc_mem_align(size); |
| 480 | spin_lock(&gpmc_mem_lock); |
| 481 | res->start = base; |
| 482 | res->end = base + size - 1; |
| 483 | r = request_resource(&gpmc_mem_root, res); |
| 484 | spin_unlock(&gpmc_mem_lock); |
| 485 | |
| 486 | return r; |
| 487 | } |
| 488 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 489 | static int gpmc_cs_delete_mem(int cs) |
| 490 | { |
| 491 | struct resource *res = &gpmc_cs_mem[cs]; |
| 492 | int r; |
| 493 | |
| 494 | spin_lock(&gpmc_mem_lock); |
| 495 | r = release_resource(&gpmc_cs_mem[cs]); |
| 496 | res->start = 0; |
| 497 | res->end = 0; |
| 498 | spin_unlock(&gpmc_mem_lock); |
| 499 | |
| 500 | return r; |
| 501 | } |
| 502 | |
Jon Hunter | cdd6928 | 2013-02-08 16:46:13 -0600 | [diff] [blame^] | 503 | /** |
| 504 | * gpmc_cs_remap - remaps a chip-select physical base address |
| 505 | * @cs: chip-select to remap |
| 506 | * @base: physical base address to re-map chip-select to |
| 507 | * |
| 508 | * Re-maps a chip-select to a new physical base address specified by |
| 509 | * "base". Returns 0 on success and appropriate negative error code |
| 510 | * on failure. |
| 511 | */ |
| 512 | static int gpmc_cs_remap(int cs, u32 base) |
| 513 | { |
| 514 | int ret; |
| 515 | u32 old_base, size; |
| 516 | |
| 517 | if (cs > GPMC_CS_NUM) |
| 518 | return -ENODEV; |
| 519 | gpmc_cs_get_memconf(cs, &old_base, &size); |
| 520 | if (base == old_base) |
| 521 | return 0; |
| 522 | gpmc_cs_disable_mem(cs); |
| 523 | ret = gpmc_cs_delete_mem(cs); |
| 524 | if (ret < 0) |
| 525 | return ret; |
| 526 | ret = gpmc_cs_insert_mem(cs, base, size); |
| 527 | if (ret < 0) |
| 528 | return ret; |
| 529 | gpmc_cs_enable_mem(cs, base, size); |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 534 | int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) |
| 535 | { |
| 536 | struct resource *res = &gpmc_cs_mem[cs]; |
| 537 | int r = -1; |
| 538 | |
| 539 | if (cs > GPMC_CS_NUM) |
| 540 | return -ENODEV; |
| 541 | |
| 542 | size = gpmc_mem_align(size); |
| 543 | if (size > (1 << GPMC_SECTION_SHIFT)) |
| 544 | return -ENOMEM; |
| 545 | |
| 546 | spin_lock(&gpmc_mem_lock); |
| 547 | if (gpmc_cs_reserved(cs)) { |
| 548 | r = -EBUSY; |
| 549 | goto out; |
| 550 | } |
| 551 | if (gpmc_cs_mem_enabled(cs)) |
| 552 | r = adjust_resource(res, res->start & ~(size - 1), size); |
| 553 | if (r < 0) |
| 554 | r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0, |
| 555 | size, NULL, NULL); |
| 556 | if (r < 0) |
| 557 | goto out; |
| 558 | |
Tobias Klauser | 6d13524 | 2009-11-10 18:55:19 -0800 | [diff] [blame] | 559 | gpmc_cs_enable_mem(cs, res->start, resource_size(res)); |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 560 | *base = res->start; |
| 561 | gpmc_cs_set_reserved(cs, 1); |
| 562 | out: |
| 563 | spin_unlock(&gpmc_mem_lock); |
| 564 | return r; |
| 565 | } |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 566 | EXPORT_SYMBOL(gpmc_cs_request); |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 567 | |
| 568 | void gpmc_cs_free(int cs) |
| 569 | { |
| 570 | spin_lock(&gpmc_mem_lock); |
Roel Kluin | e7fdc60 | 2009-11-17 14:39:06 -0800 | [diff] [blame] | 571 | if (cs >= GPMC_CS_NUM || cs < 0 || !gpmc_cs_reserved(cs)) { |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 572 | printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs); |
| 573 | BUG(); |
| 574 | spin_unlock(&gpmc_mem_lock); |
| 575 | return; |
| 576 | } |
| 577 | gpmc_cs_disable_mem(cs); |
| 578 | release_resource(&gpmc_cs_mem[cs]); |
| 579 | gpmc_cs_set_reserved(cs, 0); |
| 580 | spin_unlock(&gpmc_mem_lock); |
| 581 | } |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 582 | EXPORT_SYMBOL(gpmc_cs_free); |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 583 | |
vimal singh | 59e9c5a | 2009-07-13 16:26:24 +0530 | [diff] [blame] | 584 | /** |
Jon Hunter | 3a54435 | 2013-02-21 13:00:21 -0600 | [diff] [blame] | 585 | * gpmc_configure - write request to configure gpmc |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 586 | * @cmd: command type |
| 587 | * @wval: value to write |
| 588 | * @return status of the operation |
| 589 | */ |
Jon Hunter | 3a54435 | 2013-02-21 13:00:21 -0600 | [diff] [blame] | 590 | int gpmc_configure(int cmd, int wval) |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 591 | { |
Jon Hunter | 3a54435 | 2013-02-21 13:00:21 -0600 | [diff] [blame] | 592 | u32 regval; |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 593 | |
| 594 | switch (cmd) { |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 595 | case GPMC_ENABLE_IRQ: |
| 596 | gpmc_write_reg(GPMC_IRQENABLE, wval); |
| 597 | break; |
| 598 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 599 | case GPMC_SET_IRQ_STATUS: |
| 600 | gpmc_write_reg(GPMC_IRQSTATUS, wval); |
| 601 | break; |
| 602 | |
| 603 | case GPMC_CONFIG_WP: |
| 604 | regval = gpmc_read_reg(GPMC_CONFIG); |
| 605 | if (wval) |
| 606 | regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */ |
| 607 | else |
| 608 | regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */ |
| 609 | gpmc_write_reg(GPMC_CONFIG, regval); |
| 610 | break; |
| 611 | |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 612 | default: |
Jon Hunter | 3a54435 | 2013-02-21 13:00:21 -0600 | [diff] [blame] | 613 | pr_err("%s: command not supported\n", __func__); |
| 614 | return -EINVAL; |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Jon Hunter | 3a54435 | 2013-02-21 13:00:21 -0600 | [diff] [blame] | 617 | return 0; |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 618 | } |
Jon Hunter | 3a54435 | 2013-02-21 13:00:21 -0600 | [diff] [blame] | 619 | EXPORT_SYMBOL(gpmc_configure); |
Sukumar Ghorai | 948d38e | 2010-07-09 09:14:44 +0000 | [diff] [blame] | 620 | |
Afzal Mohammed | 52bd138 | 2012-08-30 12:53:22 -0700 | [diff] [blame] | 621 | void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs) |
| 622 | { |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 623 | int i; |
| 624 | |
Afzal Mohammed | 52bd138 | 2012-08-30 12:53:22 -0700 | [diff] [blame] | 625 | reg->gpmc_status = gpmc_base + GPMC_STATUS; |
| 626 | reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET + |
| 627 | GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs; |
| 628 | reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET + |
| 629 | GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs; |
| 630 | reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET + |
| 631 | GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs; |
| 632 | reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1; |
| 633 | reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2; |
| 634 | reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL; |
| 635 | reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS; |
| 636 | reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG; |
| 637 | reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL; |
| 638 | reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG; |
| 639 | reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT; |
Afzal Mohammed | 2fdf0c9 | 2012-10-04 15:49:04 +0530 | [diff] [blame] | 640 | |
| 641 | for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) { |
| 642 | reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 + |
| 643 | GPMC_BCH_SIZE * i; |
| 644 | reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 + |
| 645 | GPMC_BCH_SIZE * i; |
| 646 | reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 + |
| 647 | GPMC_BCH_SIZE * i; |
| 648 | reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 + |
| 649 | GPMC_BCH_SIZE * i; |
| 650 | } |
Afzal Mohammed | 52bd138 | 2012-08-30 12:53:22 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 653 | int gpmc_get_client_irq(unsigned irq_config) |
| 654 | { |
| 655 | int i; |
| 656 | |
| 657 | if (hweight32(irq_config) > 1) |
| 658 | return 0; |
| 659 | |
| 660 | for (i = 0; i < GPMC_NR_IRQ; i++) |
| 661 | if (gpmc_client_irq[i].bitmask & irq_config) |
| 662 | return gpmc_client_irq[i].irq; |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int gpmc_irq_endis(unsigned irq, bool endis) |
| 668 | { |
| 669 | int i; |
| 670 | u32 regval; |
| 671 | |
| 672 | for (i = 0; i < GPMC_NR_IRQ; i++) |
| 673 | if (irq == gpmc_client_irq[i].irq) { |
| 674 | regval = gpmc_read_reg(GPMC_IRQENABLE); |
| 675 | if (endis) |
| 676 | regval |= gpmc_client_irq[i].bitmask; |
| 677 | else |
| 678 | regval &= ~gpmc_client_irq[i].bitmask; |
| 679 | gpmc_write_reg(GPMC_IRQENABLE, regval); |
| 680 | break; |
| 681 | } |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static void gpmc_irq_disable(struct irq_data *p) |
| 687 | { |
| 688 | gpmc_irq_endis(p->irq, false); |
| 689 | } |
| 690 | |
| 691 | static void gpmc_irq_enable(struct irq_data *p) |
| 692 | { |
| 693 | gpmc_irq_endis(p->irq, true); |
| 694 | } |
| 695 | |
| 696 | static void gpmc_irq_noop(struct irq_data *data) { } |
| 697 | |
| 698 | static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; } |
| 699 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 700 | static int gpmc_setup_irq(void) |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 701 | { |
| 702 | int i; |
| 703 | u32 regval; |
| 704 | |
| 705 | if (!gpmc_irq) |
| 706 | return -EINVAL; |
| 707 | |
| 708 | gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 709 | if (gpmc_irq_start < 0) { |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 710 | pr_err("irq_alloc_descs failed\n"); |
| 711 | return gpmc_irq_start; |
| 712 | } |
| 713 | |
| 714 | gpmc_irq_chip.name = "gpmc"; |
| 715 | gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret; |
| 716 | gpmc_irq_chip.irq_enable = gpmc_irq_enable; |
| 717 | gpmc_irq_chip.irq_disable = gpmc_irq_disable; |
| 718 | gpmc_irq_chip.irq_shutdown = gpmc_irq_noop; |
| 719 | gpmc_irq_chip.irq_ack = gpmc_irq_noop; |
| 720 | gpmc_irq_chip.irq_mask = gpmc_irq_noop; |
| 721 | gpmc_irq_chip.irq_unmask = gpmc_irq_noop; |
| 722 | |
| 723 | gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE; |
| 724 | gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT; |
| 725 | |
| 726 | for (i = 0; i < GPMC_NR_IRQ; i++) { |
| 727 | gpmc_client_irq[i].irq = gpmc_irq_start + i; |
| 728 | irq_set_chip_and_handler(gpmc_client_irq[i].irq, |
| 729 | &gpmc_irq_chip, handle_simple_irq); |
| 730 | set_irq_flags(gpmc_client_irq[i].irq, |
| 731 | IRQF_VALID | IRQF_NOAUTOEN); |
| 732 | } |
| 733 | |
| 734 | /* Disable interrupts */ |
| 735 | gpmc_write_reg(GPMC_IRQENABLE, 0); |
| 736 | |
| 737 | /* clear interrupts */ |
| 738 | regval = gpmc_read_reg(GPMC_IRQSTATUS); |
| 739 | gpmc_write_reg(GPMC_IRQSTATUS, regval); |
| 740 | |
| 741 | return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL); |
| 742 | } |
| 743 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 744 | static int gpmc_free_irq(void) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 745 | { |
| 746 | int i; |
| 747 | |
| 748 | if (gpmc_irq) |
| 749 | free_irq(gpmc_irq, NULL); |
| 750 | |
| 751 | for (i = 0; i < GPMC_NR_IRQ; i++) { |
| 752 | irq_set_handler(gpmc_client_irq[i].irq, NULL); |
| 753 | irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip); |
| 754 | irq_modify_status(gpmc_client_irq[i].irq, 0, 0); |
| 755 | } |
| 756 | |
| 757 | irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ); |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 762 | static void gpmc_mem_exit(void) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 763 | { |
| 764 | int cs; |
| 765 | |
| 766 | for (cs = 0; cs < GPMC_CS_NUM; cs++) { |
| 767 | if (!gpmc_cs_mem_enabled(cs)) |
| 768 | continue; |
| 769 | gpmc_cs_delete_mem(cs); |
| 770 | } |
| 771 | |
| 772 | } |
| 773 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 774 | static int gpmc_mem_init(void) |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 775 | { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 776 | int cs, rc; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 777 | unsigned long boot_rom_space = 0; |
| 778 | |
Kyungmin Park | 7f24516 | 2006-12-29 16:48:51 -0800 | [diff] [blame] | 779 | /* never allocate the first page, to facilitate bug detection; |
| 780 | * even if we didn't boot from ROM. |
| 781 | */ |
| 782 | boot_rom_space = BOOT_ROM_SPACE; |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 783 | gpmc_mem_root.start = GPMC_MEM_START + boot_rom_space; |
| 784 | gpmc_mem_root.end = GPMC_MEM_END; |
| 785 | |
| 786 | /* Reserve all regions that has been set up by bootloader */ |
| 787 | for (cs = 0; cs < GPMC_CS_NUM; cs++) { |
| 788 | u32 base, size; |
| 789 | |
| 790 | if (!gpmc_cs_mem_enabled(cs)) |
| 791 | continue; |
| 792 | gpmc_cs_get_memconf(cs, &base, &size); |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 793 | rc = gpmc_cs_insert_mem(cs, base, size); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 794 | if (rc < 0) { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 795 | while (--cs >= 0) |
| 796 | if (gpmc_cs_mem_enabled(cs)) |
| 797 | gpmc_cs_delete_mem(cs); |
| 798 | return rc; |
| 799 | } |
Imre Deak | f37e458 | 2006-09-25 12:41:33 +0300 | [diff] [blame] | 800 | } |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 801 | |
| 802 | return 0; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 805 | static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk) |
| 806 | { |
| 807 | u32 temp; |
| 808 | int div; |
| 809 | |
| 810 | div = gpmc_calc_divider(sync_clk); |
| 811 | temp = gpmc_ps_to_ticks(time_ps); |
| 812 | temp = (temp + div - 1) / div; |
| 813 | return gpmc_ticks_to_ps(temp * div); |
| 814 | } |
| 815 | |
| 816 | /* XXX: can the cycles be avoided ? */ |
| 817 | static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 818 | struct gpmc_device_timings *dev_t, |
| 819 | bool mux) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 820 | { |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 821 | u32 temp; |
| 822 | |
| 823 | /* adv_rd_off */ |
| 824 | temp = dev_t->t_avdp_r; |
| 825 | /* XXX: mux check required ? */ |
| 826 | if (mux) { |
| 827 | /* XXX: t_avdp not to be required for sync, only added for tusb |
| 828 | * this indirectly necessitates requirement of t_avdp_r and |
| 829 | * t_avdp_w instead of having a single t_avdp |
| 830 | */ |
| 831 | temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh); |
| 832 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 833 | } |
| 834 | gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); |
| 835 | |
| 836 | /* oe_on */ |
| 837 | temp = dev_t->t_oeasu; /* XXX: remove this ? */ |
| 838 | if (mux) { |
| 839 | temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach); |
| 840 | temp = max_t(u32, temp, gpmc_t->adv_rd_off + |
| 841 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe)); |
| 842 | } |
| 843 | gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); |
| 844 | |
| 845 | /* access */ |
| 846 | /* XXX: any scope for improvement ?, by combining oe_on |
| 847 | * and clk_activation, need to check whether |
| 848 | * access = clk_activation + round to sync clk ? |
| 849 | */ |
| 850 | temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk); |
| 851 | temp += gpmc_t->clk_activation; |
| 852 | if (dev_t->cyc_oe) |
| 853 | temp = max_t(u32, temp, gpmc_t->oe_on + |
| 854 | gpmc_ticks_to_ps(dev_t->cyc_oe)); |
| 855 | gpmc_t->access = gpmc_round_ps_to_ticks(temp); |
| 856 | |
| 857 | gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); |
| 858 | gpmc_t->cs_rd_off = gpmc_t->oe_off; |
| 859 | |
| 860 | /* rd_cycle */ |
| 861 | temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez); |
| 862 | temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) + |
| 863 | gpmc_t->access; |
| 864 | /* XXX: barter t_ce_rdyz with t_cez_r ? */ |
| 865 | if (dev_t->t_ce_rdyz) |
| 866 | temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz); |
| 867 | gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 873 | struct gpmc_device_timings *dev_t, |
| 874 | bool mux) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 875 | { |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 876 | u32 temp; |
| 877 | |
| 878 | /* adv_wr_off */ |
| 879 | temp = dev_t->t_avdp_w; |
| 880 | if (mux) { |
| 881 | temp = max_t(u32, temp, |
| 882 | gpmc_t->clk_activation + dev_t->t_avdh); |
| 883 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 884 | } |
| 885 | gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); |
| 886 | |
| 887 | /* wr_data_mux_bus */ |
| 888 | temp = max_t(u32, dev_t->t_weasu, |
| 889 | gpmc_t->clk_activation + dev_t->t_rdyo); |
| 890 | /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?, |
| 891 | * and in that case remember to handle we_on properly |
| 892 | */ |
| 893 | if (mux) { |
| 894 | temp = max_t(u32, temp, |
| 895 | gpmc_t->adv_wr_off + dev_t->t_aavdh); |
| 896 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + |
| 897 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); |
| 898 | } |
| 899 | gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); |
| 900 | |
| 901 | /* we_on */ |
| 902 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) |
| 903 | gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); |
| 904 | else |
| 905 | gpmc_t->we_on = gpmc_t->wr_data_mux_bus; |
| 906 | |
| 907 | /* wr_access */ |
| 908 | /* XXX: gpmc_capability check reqd ? , even if not, will not harm */ |
| 909 | gpmc_t->wr_access = gpmc_t->access; |
| 910 | |
| 911 | /* we_off */ |
| 912 | temp = gpmc_t->we_on + dev_t->t_wpl; |
| 913 | temp = max_t(u32, temp, |
| 914 | gpmc_t->wr_access + gpmc_ticks_to_ps(1)); |
| 915 | temp = max_t(u32, temp, |
| 916 | gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl)); |
| 917 | gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); |
| 918 | |
| 919 | gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + |
| 920 | dev_t->t_wph); |
| 921 | |
| 922 | /* wr_cycle */ |
| 923 | temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk); |
| 924 | temp += gpmc_t->wr_access; |
| 925 | /* XXX: barter t_ce_rdyz with t_cez_w ? */ |
| 926 | if (dev_t->t_ce_rdyz) |
| 927 | temp = max_t(u32, temp, |
| 928 | gpmc_t->cs_wr_off + dev_t->t_ce_rdyz); |
| 929 | gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 935 | struct gpmc_device_timings *dev_t, |
| 936 | bool mux) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 937 | { |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 938 | u32 temp; |
| 939 | |
| 940 | /* adv_rd_off */ |
| 941 | temp = dev_t->t_avdp_r; |
| 942 | if (mux) |
| 943 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 944 | gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); |
| 945 | |
| 946 | /* oe_on */ |
| 947 | temp = dev_t->t_oeasu; |
| 948 | if (mux) |
| 949 | temp = max_t(u32, temp, |
| 950 | gpmc_t->adv_rd_off + dev_t->t_aavdh); |
| 951 | gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); |
| 952 | |
| 953 | /* access */ |
| 954 | temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */ |
| 955 | gpmc_t->oe_on + dev_t->t_oe); |
| 956 | temp = max_t(u32, temp, |
| 957 | gpmc_t->cs_on + dev_t->t_ce); |
| 958 | temp = max_t(u32, temp, |
| 959 | gpmc_t->adv_on + dev_t->t_aa); |
| 960 | gpmc_t->access = gpmc_round_ps_to_ticks(temp); |
| 961 | |
| 962 | gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); |
| 963 | gpmc_t->cs_rd_off = gpmc_t->oe_off; |
| 964 | |
| 965 | /* rd_cycle */ |
| 966 | temp = max_t(u32, dev_t->t_rd_cycle, |
| 967 | gpmc_t->cs_rd_off + dev_t->t_cez_r); |
| 968 | temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez); |
| 969 | gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 975 | struct gpmc_device_timings *dev_t, |
| 976 | bool mux) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 977 | { |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 978 | u32 temp; |
| 979 | |
| 980 | /* adv_wr_off */ |
| 981 | temp = dev_t->t_avdp_w; |
| 982 | if (mux) |
| 983 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); |
| 984 | gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); |
| 985 | |
| 986 | /* wr_data_mux_bus */ |
| 987 | temp = dev_t->t_weasu; |
| 988 | if (mux) { |
| 989 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh); |
| 990 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + |
| 991 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); |
| 992 | } |
| 993 | gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); |
| 994 | |
| 995 | /* we_on */ |
| 996 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) |
| 997 | gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); |
| 998 | else |
| 999 | gpmc_t->we_on = gpmc_t->wr_data_mux_bus; |
| 1000 | |
| 1001 | /* we_off */ |
| 1002 | temp = gpmc_t->we_on + dev_t->t_wpl; |
| 1003 | gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); |
| 1004 | |
| 1005 | gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + |
| 1006 | dev_t->t_wph); |
| 1007 | |
| 1008 | /* wr_cycle */ |
| 1009 | temp = max_t(u32, dev_t->t_wr_cycle, |
| 1010 | gpmc_t->cs_wr_off + dev_t->t_cez_w); |
| 1011 | gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t, |
| 1017 | struct gpmc_device_timings *dev_t) |
| 1018 | { |
| 1019 | u32 temp; |
| 1020 | |
| 1021 | gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) * |
| 1022 | gpmc_get_fclk_period(); |
| 1023 | |
| 1024 | gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk( |
| 1025 | dev_t->t_bacc, |
| 1026 | gpmc_t->sync_clk); |
| 1027 | |
| 1028 | temp = max_t(u32, dev_t->t_ces, dev_t->t_avds); |
| 1029 | gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp); |
| 1030 | |
| 1031 | if (gpmc_calc_divider(gpmc_t->sync_clk) != 1) |
| 1032 | return 0; |
| 1033 | |
| 1034 | if (dev_t->ce_xdelay) |
| 1035 | gpmc_t->bool_timings.cs_extra_delay = true; |
| 1036 | if (dev_t->avd_xdelay) |
| 1037 | gpmc_t->bool_timings.adv_extra_delay = true; |
| 1038 | if (dev_t->oe_xdelay) |
| 1039 | gpmc_t->bool_timings.oe_extra_delay = true; |
| 1040 | if (dev_t->we_xdelay) |
| 1041 | gpmc_t->bool_timings.we_extra_delay = true; |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1047 | struct gpmc_device_timings *dev_t, |
| 1048 | bool sync) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1049 | { |
| 1050 | u32 temp; |
| 1051 | |
| 1052 | /* cs_on */ |
| 1053 | gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu); |
| 1054 | |
| 1055 | /* adv_on */ |
| 1056 | temp = dev_t->t_avdasu; |
| 1057 | if (dev_t->t_ce_avd) |
| 1058 | temp = max_t(u32, temp, |
| 1059 | gpmc_t->cs_on + dev_t->t_ce_avd); |
| 1060 | gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp); |
| 1061 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1062 | if (sync) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1063 | gpmc_calc_sync_common_timings(gpmc_t, dev_t); |
| 1064 | |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
| 1068 | /* TODO: remove this function once all peripherals are confirmed to |
| 1069 | * work with generic timing. Simultaneously gpmc_cs_set_timings() |
| 1070 | * has to be modified to handle timings in ps instead of ns |
| 1071 | */ |
| 1072 | static void gpmc_convert_ps_to_ns(struct gpmc_timings *t) |
| 1073 | { |
| 1074 | t->cs_on /= 1000; |
| 1075 | t->cs_rd_off /= 1000; |
| 1076 | t->cs_wr_off /= 1000; |
| 1077 | t->adv_on /= 1000; |
| 1078 | t->adv_rd_off /= 1000; |
| 1079 | t->adv_wr_off /= 1000; |
| 1080 | t->we_on /= 1000; |
| 1081 | t->we_off /= 1000; |
| 1082 | t->oe_on /= 1000; |
| 1083 | t->oe_off /= 1000; |
| 1084 | t->page_burst_access /= 1000; |
| 1085 | t->access /= 1000; |
| 1086 | t->rd_cycle /= 1000; |
| 1087 | t->wr_cycle /= 1000; |
| 1088 | t->bus_turnaround /= 1000; |
| 1089 | t->cycle2cycle_delay /= 1000; |
| 1090 | t->wait_monitoring /= 1000; |
| 1091 | t->clk_activation /= 1000; |
| 1092 | t->wr_access /= 1000; |
| 1093 | t->wr_data_mux_bus /= 1000; |
| 1094 | } |
| 1095 | |
| 1096 | int gpmc_calc_timings(struct gpmc_timings *gpmc_t, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1097 | struct gpmc_settings *gpmc_s, |
| 1098 | struct gpmc_device_timings *dev_t) |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1099 | { |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1100 | bool mux = false, sync = false; |
| 1101 | |
| 1102 | if (gpmc_s) { |
| 1103 | mux = gpmc_s->mux_add_data ? true : false; |
| 1104 | sync = (gpmc_s->sync_read || gpmc_s->sync_write); |
| 1105 | } |
| 1106 | |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1107 | memset(gpmc_t, 0, sizeof(*gpmc_t)); |
| 1108 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1109 | gpmc_calc_common_timings(gpmc_t, dev_t, sync); |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1110 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1111 | if (gpmc_s && gpmc_s->sync_read) |
| 1112 | gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux); |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1113 | else |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1114 | gpmc_calc_async_read_timings(gpmc_t, dev_t, mux); |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1115 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1116 | if (gpmc_s && gpmc_s->sync_write) |
| 1117 | gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux); |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1118 | else |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 1119 | gpmc_calc_async_write_timings(gpmc_t, dev_t, mux); |
Afzal Mohammed | 246da26 | 2012-08-02 20:02:10 +0530 | [diff] [blame] | 1120 | |
| 1121 | /* TODO: remove, see function definition */ |
| 1122 | gpmc_convert_ps_to_ns(gpmc_t); |
| 1123 | |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
Jon Hunter | aa8d476 | 2013-02-21 15:25:23 -0600 | [diff] [blame] | 1127 | /** |
| 1128 | * gpmc_cs_program_settings - programs non-timing related settings |
| 1129 | * @cs: GPMC chip-select to program |
| 1130 | * @p: pointer to GPMC settings structure |
| 1131 | * |
| 1132 | * Programs non-timing related settings for a GPMC chip-select, such as |
| 1133 | * bus-width, burst configuration, etc. Function should be called once |
| 1134 | * for each chip-select that is being used and must be called before |
| 1135 | * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1 |
| 1136 | * register will be initialised to zero by this function. Returns 0 on |
| 1137 | * success and appropriate negative error code on failure. |
| 1138 | */ |
| 1139 | int gpmc_cs_program_settings(int cs, struct gpmc_settings *p) |
| 1140 | { |
| 1141 | u32 config1; |
| 1142 | |
| 1143 | if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) { |
| 1144 | pr_err("%s: invalid width %d!", __func__, p->device_width); |
| 1145 | return -EINVAL; |
| 1146 | } |
| 1147 | |
| 1148 | /* Address-data multiplexing not supported for NAND devices */ |
| 1149 | if (p->device_nand && p->mux_add_data) { |
| 1150 | pr_err("%s: invalid configuration!\n", __func__); |
| 1151 | return -EINVAL; |
| 1152 | } |
| 1153 | |
| 1154 | if ((p->mux_add_data > GPMC_MUX_AD) || |
| 1155 | ((p->mux_add_data == GPMC_MUX_AAD) && |
| 1156 | !(gpmc_capability & GPMC_HAS_MUX_AAD))) { |
| 1157 | pr_err("%s: invalid multiplex configuration!\n", __func__); |
| 1158 | return -EINVAL; |
| 1159 | } |
| 1160 | |
| 1161 | /* Page/burst mode supports lengths of 4, 8 and 16 bytes */ |
| 1162 | if (p->burst_read || p->burst_write) { |
| 1163 | switch (p->burst_len) { |
| 1164 | case GPMC_BURST_4: |
| 1165 | case GPMC_BURST_8: |
| 1166 | case GPMC_BURST_16: |
| 1167 | break; |
| 1168 | default: |
| 1169 | pr_err("%s: invalid page/burst-length (%d)\n", |
| 1170 | __func__, p->burst_len); |
| 1171 | return -EINVAL; |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | if ((p->wait_on_read || p->wait_on_write) && |
| 1176 | (p->wait_pin > gpmc_nr_waitpins)) { |
| 1177 | pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin); |
| 1178 | return -EINVAL; |
| 1179 | } |
| 1180 | |
| 1181 | config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1)); |
| 1182 | |
| 1183 | if (p->sync_read) |
| 1184 | config1 |= GPMC_CONFIG1_READTYPE_SYNC; |
| 1185 | if (p->sync_write) |
| 1186 | config1 |= GPMC_CONFIG1_WRITETYPE_SYNC; |
| 1187 | if (p->wait_on_read) |
| 1188 | config1 |= GPMC_CONFIG1_WAIT_READ_MON; |
| 1189 | if (p->wait_on_write) |
| 1190 | config1 |= GPMC_CONFIG1_WAIT_WRITE_MON; |
| 1191 | if (p->wait_on_read || p->wait_on_write) |
| 1192 | config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin); |
| 1193 | if (p->device_nand) |
| 1194 | config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND); |
| 1195 | if (p->mux_add_data) |
| 1196 | config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data); |
| 1197 | if (p->burst_read) |
| 1198 | config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP; |
| 1199 | if (p->burst_write) |
| 1200 | config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP; |
| 1201 | if (p->burst_read || p->burst_write) { |
| 1202 | config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3); |
| 1203 | config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0; |
| 1204 | } |
| 1205 | |
| 1206 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1); |
| 1207 | |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1211 | #ifdef CONFIG_OF |
| 1212 | static struct of_device_id gpmc_dt_ids[] = { |
| 1213 | { .compatible = "ti,omap2420-gpmc" }, |
| 1214 | { .compatible = "ti,omap2430-gpmc" }, |
| 1215 | { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */ |
| 1216 | { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */ |
| 1217 | { .compatible = "ti,am3352-gpmc" }, /* am335x devices */ |
| 1218 | { } |
| 1219 | }; |
| 1220 | MODULE_DEVICE_TABLE(of, gpmc_dt_ids); |
| 1221 | |
Jon Hunter | 8c8a7771 | 2013-02-20 15:53:12 -0600 | [diff] [blame] | 1222 | /** |
| 1223 | * gpmc_read_settings_dt - read gpmc settings from device-tree |
| 1224 | * @np: pointer to device-tree node for a gpmc child device |
| 1225 | * @p: pointer to gpmc settings structure |
| 1226 | * |
| 1227 | * Reads the GPMC settings for a GPMC child device from device-tree and |
| 1228 | * stores them in the GPMC settings structure passed. The GPMC settings |
| 1229 | * structure is initialised to zero by this function and so any |
| 1230 | * previously stored settings will be cleared. |
| 1231 | */ |
| 1232 | void gpmc_read_settings_dt(struct device_node *np, struct gpmc_settings *p) |
| 1233 | { |
| 1234 | memset(p, 0, sizeof(struct gpmc_settings)); |
| 1235 | |
| 1236 | p->sync_read = of_property_read_bool(np, "gpmc,sync-read"); |
| 1237 | p->sync_write = of_property_read_bool(np, "gpmc,sync-write"); |
| 1238 | p->device_nand = of_property_read_bool(np, "gpmc,device-nand"); |
| 1239 | of_property_read_u32(np, "gpmc,device-width", &p->device_width); |
| 1240 | of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data); |
| 1241 | |
| 1242 | if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) { |
| 1243 | p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap"); |
| 1244 | p->burst_read = of_property_read_bool(np, "gpmc,burst-read"); |
| 1245 | p->burst_write = of_property_read_bool(np, "gpmc,burst-write"); |
| 1246 | if (!p->burst_read && !p->burst_write) |
| 1247 | pr_warn("%s: page/burst-length set but not used!\n", |
| 1248 | __func__); |
| 1249 | } |
| 1250 | |
| 1251 | if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) { |
| 1252 | p->wait_on_read = of_property_read_bool(np, |
| 1253 | "gpmc,wait-on-read"); |
| 1254 | p->wait_on_write = of_property_read_bool(np, |
| 1255 | "gpmc,wait-on-write"); |
| 1256 | if (!p->wait_on_read && !p->wait_on_write) |
| 1257 | pr_warn("%s: read/write wait monitoring not enabled!\n", |
| 1258 | __func__); |
| 1259 | } |
| 1260 | } |
| 1261 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1262 | static void __maybe_unused gpmc_read_timings_dt(struct device_node *np, |
| 1263 | struct gpmc_timings *gpmc_t) |
| 1264 | { |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1265 | struct gpmc_bool_timings *p; |
| 1266 | |
| 1267 | if (!np || !gpmc_t) |
| 1268 | return; |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1269 | |
| 1270 | memset(gpmc_t, 0, sizeof(*gpmc_t)); |
| 1271 | |
| 1272 | /* minimum clock period for syncronous mode */ |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1273 | of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1274 | |
| 1275 | /* chip select timtings */ |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1276 | of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on); |
| 1277 | of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off); |
| 1278 | of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1279 | |
| 1280 | /* ADV signal timings */ |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1281 | of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on); |
| 1282 | of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off); |
| 1283 | of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1284 | |
| 1285 | /* WE signal timings */ |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1286 | of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on); |
| 1287 | of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1288 | |
| 1289 | /* OE signal timings */ |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1290 | of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on); |
| 1291 | of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1292 | |
| 1293 | /* access and cycle timings */ |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1294 | of_property_read_u32(np, "gpmc,page-burst-access-ns", |
| 1295 | &gpmc_t->page_burst_access); |
| 1296 | of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access); |
| 1297 | of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle); |
| 1298 | of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle); |
| 1299 | of_property_read_u32(np, "gpmc,bus-turnaround-ns", |
| 1300 | &gpmc_t->bus_turnaround); |
| 1301 | of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns", |
| 1302 | &gpmc_t->cycle2cycle_delay); |
| 1303 | of_property_read_u32(np, "gpmc,wait-monitoring-ns", |
| 1304 | &gpmc_t->wait_monitoring); |
| 1305 | of_property_read_u32(np, "gpmc,clk-activation-ns", |
| 1306 | &gpmc_t->clk_activation); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1307 | |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1308 | /* only applicable to OMAP3+ */ |
| 1309 | of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access); |
| 1310 | of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns", |
| 1311 | &gpmc_t->wr_data_mux_bus); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1312 | |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1313 | /* bool timing parameters */ |
| 1314 | p = &gpmc_t->bool_timings; |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1315 | |
Jon Hunter | d36b4cd | 2013-02-21 18:51:27 -0600 | [diff] [blame] | 1316 | p->cycle2cyclediffcsen = |
| 1317 | of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen"); |
| 1318 | p->cycle2cyclesamecsen = |
| 1319 | of_property_read_bool(np, "gpmc,cycle2cycle-samecsen"); |
| 1320 | p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay"); |
| 1321 | p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay"); |
| 1322 | p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay"); |
| 1323 | p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay"); |
| 1324 | p->time_para_granularity = |
| 1325 | of_property_read_bool(np, "gpmc,time-para-granularity"); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | #ifdef CONFIG_MTD_NAND |
| 1329 | |
| 1330 | static const char * const nand_ecc_opts[] = { |
| 1331 | [OMAP_ECC_HAMMING_CODE_DEFAULT] = "sw", |
| 1332 | [OMAP_ECC_HAMMING_CODE_HW] = "hw", |
| 1333 | [OMAP_ECC_HAMMING_CODE_HW_ROMCODE] = "hw-romcode", |
| 1334 | [OMAP_ECC_BCH4_CODE_HW] = "bch4", |
| 1335 | [OMAP_ECC_BCH8_CODE_HW] = "bch8", |
| 1336 | }; |
| 1337 | |
| 1338 | static int gpmc_probe_nand_child(struct platform_device *pdev, |
| 1339 | struct device_node *child) |
| 1340 | { |
| 1341 | u32 val; |
| 1342 | const char *s; |
| 1343 | struct gpmc_timings gpmc_t; |
| 1344 | struct omap_nand_platform_data *gpmc_nand_data; |
| 1345 | |
| 1346 | if (of_property_read_u32(child, "reg", &val) < 0) { |
| 1347 | dev_err(&pdev->dev, "%s has no 'reg' property\n", |
| 1348 | child->full_name); |
| 1349 | return -ENODEV; |
| 1350 | } |
| 1351 | |
| 1352 | gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data), |
| 1353 | GFP_KERNEL); |
| 1354 | if (!gpmc_nand_data) |
| 1355 | return -ENOMEM; |
| 1356 | |
| 1357 | gpmc_nand_data->cs = val; |
| 1358 | gpmc_nand_data->of_node = child; |
| 1359 | |
| 1360 | if (!of_property_read_string(child, "ti,nand-ecc-opt", &s)) |
| 1361 | for (val = 0; val < ARRAY_SIZE(nand_ecc_opts); val++) |
| 1362 | if (!strcasecmp(s, nand_ecc_opts[val])) { |
| 1363 | gpmc_nand_data->ecc_opt = val; |
| 1364 | break; |
| 1365 | } |
| 1366 | |
| 1367 | val = of_get_nand_bus_width(child); |
| 1368 | if (val == 16) |
| 1369 | gpmc_nand_data->devsize = NAND_BUSWIDTH_16; |
| 1370 | |
| 1371 | gpmc_read_timings_dt(child, &gpmc_t); |
| 1372 | gpmc_nand_init(gpmc_nand_data, &gpmc_t); |
| 1373 | |
| 1374 | return 0; |
| 1375 | } |
| 1376 | #else |
| 1377 | static int gpmc_probe_nand_child(struct platform_device *pdev, |
| 1378 | struct device_node *child) |
| 1379 | { |
| 1380 | return 0; |
| 1381 | } |
| 1382 | #endif |
| 1383 | |
Ezequiel Garcia | 75d3625 | 2013-01-25 09:23:11 -0300 | [diff] [blame] | 1384 | #ifdef CONFIG_MTD_ONENAND |
| 1385 | static int gpmc_probe_onenand_child(struct platform_device *pdev, |
| 1386 | struct device_node *child) |
| 1387 | { |
| 1388 | u32 val; |
| 1389 | struct omap_onenand_platform_data *gpmc_onenand_data; |
| 1390 | |
| 1391 | if (of_property_read_u32(child, "reg", &val) < 0) { |
| 1392 | dev_err(&pdev->dev, "%s has no 'reg' property\n", |
| 1393 | child->full_name); |
| 1394 | return -ENODEV; |
| 1395 | } |
| 1396 | |
| 1397 | gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data), |
| 1398 | GFP_KERNEL); |
| 1399 | if (!gpmc_onenand_data) |
| 1400 | return -ENOMEM; |
| 1401 | |
| 1402 | gpmc_onenand_data->cs = val; |
| 1403 | gpmc_onenand_data->of_node = child; |
| 1404 | gpmc_onenand_data->dma_channel = -1; |
| 1405 | |
| 1406 | if (!of_property_read_u32(child, "dma-channel", &val)) |
| 1407 | gpmc_onenand_data->dma_channel = val; |
| 1408 | |
| 1409 | gpmc_onenand_init(gpmc_onenand_data); |
| 1410 | |
| 1411 | return 0; |
| 1412 | } |
| 1413 | #else |
| 1414 | static int gpmc_probe_onenand_child(struct platform_device *pdev, |
| 1415 | struct device_node *child) |
| 1416 | { |
| 1417 | return 0; |
| 1418 | } |
| 1419 | #endif |
| 1420 | |
Jon Hunter | cdd6928 | 2013-02-08 16:46:13 -0600 | [diff] [blame^] | 1421 | /** |
| 1422 | * gpmc_probe_nor_child - configures the gpmc for a nor device |
| 1423 | * @pdev: pointer to gpmc platform device |
| 1424 | * @child: pointer to device-tree node for nor device |
| 1425 | * |
| 1426 | * Allocates and configures a GPMC chip-select for a NOR flash device. |
| 1427 | * Returns 0 on success and appropriate negative error code on failure. |
| 1428 | */ |
| 1429 | static int gpmc_probe_nor_child(struct platform_device *pdev, |
| 1430 | struct device_node *child) |
| 1431 | { |
| 1432 | struct gpmc_settings gpmc_s; |
| 1433 | struct gpmc_timings gpmc_t; |
| 1434 | struct resource res; |
| 1435 | unsigned long base; |
| 1436 | int ret, cs; |
| 1437 | |
| 1438 | if (of_property_read_u32(child, "reg", &cs) < 0) { |
| 1439 | dev_err(&pdev->dev, "%s has no 'reg' property\n", |
| 1440 | child->full_name); |
| 1441 | return -ENODEV; |
| 1442 | } |
| 1443 | |
| 1444 | if (of_address_to_resource(child, 0, &res) < 0) { |
| 1445 | dev_err(&pdev->dev, "%s has malformed 'reg' property\n", |
| 1446 | child->full_name); |
| 1447 | return -ENODEV; |
| 1448 | } |
| 1449 | |
| 1450 | ret = gpmc_cs_request(cs, resource_size(&res), &base); |
| 1451 | if (ret < 0) { |
| 1452 | dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs); |
| 1453 | return ret; |
| 1454 | } |
| 1455 | |
| 1456 | /* |
| 1457 | * FIXME: gpmc_cs_request() will map the CS to an arbitary |
| 1458 | * location in the gpmc address space. When booting with |
| 1459 | * device-tree we want the NOR flash to be mapped to the |
| 1460 | * location specified in the device-tree blob. So remap the |
| 1461 | * CS to this location. Once DT migration is complete should |
| 1462 | * just make gpmc_cs_request() map a specific address. |
| 1463 | */ |
| 1464 | ret = gpmc_cs_remap(cs, res.start); |
| 1465 | if (ret < 0) { |
| 1466 | dev_err(&pdev->dev, "cannot remap GPMC CS %d to 0x%x\n", |
| 1467 | cs, res.start); |
| 1468 | goto err; |
| 1469 | } |
| 1470 | |
| 1471 | gpmc_read_settings_dt(child, &gpmc_s); |
| 1472 | |
| 1473 | ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width); |
| 1474 | if (ret < 0) |
| 1475 | goto err; |
| 1476 | |
| 1477 | ret = gpmc_cs_program_settings(cs, &gpmc_s); |
| 1478 | if (ret < 0) |
| 1479 | goto err; |
| 1480 | |
| 1481 | gpmc_read_timings_dt(child, &gpmc_t); |
| 1482 | gpmc_cs_set_timings(cs, &gpmc_t); |
| 1483 | |
| 1484 | if (of_platform_device_create(child, NULL, &pdev->dev)) |
| 1485 | return 0; |
| 1486 | |
| 1487 | dev_err(&pdev->dev, "failed to create gpmc child %s\n", child->name); |
| 1488 | |
| 1489 | err: |
| 1490 | gpmc_cs_free(cs); |
| 1491 | |
| 1492 | return ret; |
| 1493 | } |
| 1494 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1495 | static int gpmc_probe_dt(struct platform_device *pdev) |
| 1496 | { |
| 1497 | int ret; |
| 1498 | struct device_node *child; |
| 1499 | const struct of_device_id *of_id = |
| 1500 | of_match_device(gpmc_dt_ids, &pdev->dev); |
| 1501 | |
| 1502 | if (!of_id) |
| 1503 | return 0; |
| 1504 | |
Jon Hunter | 9f83315 | 2013-02-20 15:53:38 -0600 | [diff] [blame] | 1505 | ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins", |
| 1506 | &gpmc_nr_waitpins); |
| 1507 | if (ret < 0) { |
| 1508 | pr_err("%s: number of wait pins not found!\n", __func__); |
| 1509 | return ret; |
| 1510 | } |
| 1511 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1512 | for_each_node_by_name(child, "nand") { |
| 1513 | ret = gpmc_probe_nand_child(pdev, child); |
Ezequiel Garcia | a167237 | 2013-01-25 09:19:47 -0300 | [diff] [blame] | 1514 | if (ret < 0) { |
| 1515 | of_node_put(child); |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1516 | return ret; |
Ezequiel Garcia | a167237 | 2013-01-25 09:19:47 -0300 | [diff] [blame] | 1517 | } |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1518 | } |
| 1519 | |
Ezequiel Garcia | 75d3625 | 2013-01-25 09:23:11 -0300 | [diff] [blame] | 1520 | for_each_node_by_name(child, "onenand") { |
| 1521 | ret = gpmc_probe_onenand_child(pdev, child); |
| 1522 | if (ret < 0) { |
| 1523 | of_node_put(child); |
| 1524 | return ret; |
| 1525 | } |
| 1526 | } |
Jon Hunter | cdd6928 | 2013-02-08 16:46:13 -0600 | [diff] [blame^] | 1527 | |
| 1528 | for_each_node_by_name(child, "nor") { |
| 1529 | ret = gpmc_probe_nor_child(pdev, child); |
| 1530 | if (ret < 0) { |
| 1531 | of_node_put(child); |
| 1532 | return ret; |
| 1533 | } |
| 1534 | } |
| 1535 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1536 | return 0; |
| 1537 | } |
| 1538 | #else |
| 1539 | static int gpmc_probe_dt(struct platform_device *pdev) |
| 1540 | { |
| 1541 | return 0; |
| 1542 | } |
| 1543 | #endif |
| 1544 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 1545 | static int gpmc_probe(struct platform_device *pdev) |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1546 | { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 1547 | int rc; |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 1548 | u32 l; |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1549 | struct resource *res; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1550 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1551 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1552 | if (res == NULL) |
| 1553 | return -ENOENT; |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 1554 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1555 | phys_base = res->start; |
| 1556 | mem_size = resource_size(res); |
Kevin Hilman | 8d08436 | 2010-01-29 14:20:06 -0800 | [diff] [blame] | 1557 | |
Thierry Reding | 5857bd9 | 2013-01-21 11:08:55 +0100 | [diff] [blame] | 1558 | gpmc_base = devm_ioremap_resource(&pdev->dev, res); |
| 1559 | if (IS_ERR(gpmc_base)) |
| 1560 | return PTR_ERR(gpmc_base); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1561 | |
| 1562 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1563 | if (res == NULL) |
| 1564 | dev_warn(&pdev->dev, "Failed to get resource: irq\n"); |
| 1565 | else |
| 1566 | gpmc_irq = res->start; |
| 1567 | |
| 1568 | gpmc_l3_clk = clk_get(&pdev->dev, "fck"); |
| 1569 | if (IS_ERR(gpmc_l3_clk)) { |
| 1570 | dev_err(&pdev->dev, "error: clk_get\n"); |
| 1571 | gpmc_irq = 0; |
| 1572 | return PTR_ERR(gpmc_l3_clk); |
Paul Walmsley | fd1dc87 | 2008-10-06 15:49:17 +0300 | [diff] [blame] | 1573 | } |
| 1574 | |
Rajendra Nayak | 4d7cb45 | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 1575 | clk_prepare_enable(gpmc_l3_clk); |
Olof Johansson | 1daa8c1 | 2010-01-20 22:39:29 +0000 | [diff] [blame] | 1576 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1577 | gpmc_dev = &pdev->dev; |
| 1578 | |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1579 | l = gpmc_read_reg(GPMC_REVISION); |
Jon Hunter | aa8d476 | 2013-02-21 15:25:23 -0600 | [diff] [blame] | 1580 | |
| 1581 | /* |
| 1582 | * FIXME: Once device-tree migration is complete the below flags |
| 1583 | * should be populated based upon the device-tree compatible |
| 1584 | * string. For now just use the IP revision. OMAP3+ devices have |
| 1585 | * the wr_access and wr_data_mux_bus register fields. OMAP4+ |
| 1586 | * devices support the addr-addr-data multiplex protocol. |
| 1587 | * |
| 1588 | * GPMC IP revisions: |
| 1589 | * - OMAP24xx = 2.0 |
| 1590 | * - OMAP3xxx = 5.0 |
| 1591 | * - OMAP44xx/54xx/AM335x = 6.0 |
| 1592 | */ |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1593 | if (GPMC_REVISION_MAJOR(l) > 0x4) |
| 1594 | gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS; |
Jon Hunter | aa8d476 | 2013-02-21 15:25:23 -0600 | [diff] [blame] | 1595 | if (GPMC_REVISION_MAJOR(l) > 0x5) |
| 1596 | gpmc_capability |= GPMC_HAS_MUX_AAD; |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1597 | dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l), |
| 1598 | GPMC_REVISION_MINOR(l)); |
| 1599 | |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 1600 | rc = gpmc_mem_init(); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 1601 | if (rc < 0) { |
Jon Hunter | 8119024 | 2012-10-17 09:41:25 -0500 | [diff] [blame] | 1602 | clk_disable_unprepare(gpmc_l3_clk); |
| 1603 | clk_put(gpmc_l3_clk); |
| 1604 | dev_err(gpmc_dev, "failed to reserve memory\n"); |
| 1605 | return rc; |
| 1606 | } |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1607 | |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 1608 | if (gpmc_setup_irq() < 0) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1609 | dev_warn(gpmc_dev, "gpmc_setup_irq failed\n"); |
| 1610 | |
Jon Hunter | 31d9adc | 2013-02-18 07:57:39 -0600 | [diff] [blame] | 1611 | /* Now the GPMC is initialised, unreserve the chip-selects */ |
| 1612 | gpmc_cs_map = 0; |
| 1613 | |
Jon Hunter | 9f83315 | 2013-02-20 15:53:38 -0600 | [diff] [blame] | 1614 | if (!pdev->dev.of_node) |
| 1615 | gpmc_nr_waitpins = GPMC_NR_WAITPINS; |
| 1616 | |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1617 | rc = gpmc_probe_dt(pdev); |
| 1618 | if (rc < 0) { |
| 1619 | clk_disable_unprepare(gpmc_l3_clk); |
| 1620 | clk_put(gpmc_l3_clk); |
| 1621 | dev_err(gpmc_dev, "failed to probe DT parameters\n"); |
| 1622 | return rc; |
| 1623 | } |
| 1624 | |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1625 | return 0; |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1626 | } |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1627 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 1628 | static int gpmc_remove(struct platform_device *pdev) |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1629 | { |
| 1630 | gpmc_free_irq(); |
| 1631 | gpmc_mem_exit(); |
| 1632 | gpmc_dev = NULL; |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
| 1636 | static struct platform_driver gpmc_driver = { |
| 1637 | .probe = gpmc_probe, |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 1638 | .remove = gpmc_remove, |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1639 | .driver = { |
| 1640 | .name = DEVICE_NAME, |
| 1641 | .owner = THIS_MODULE, |
Daniel Mack | bc6b1e7 | 2012-12-14 11:36:44 +0100 | [diff] [blame] | 1642 | .of_match_table = of_match_ptr(gpmc_dt_ids), |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1643 | }, |
| 1644 | }; |
| 1645 | |
| 1646 | static __init int gpmc_init(void) |
| 1647 | { |
| 1648 | return platform_driver_register(&gpmc_driver); |
| 1649 | } |
| 1650 | |
| 1651 | static __exit void gpmc_exit(void) |
| 1652 | { |
| 1653 | platform_driver_unregister(&gpmc_driver); |
| 1654 | |
| 1655 | } |
| 1656 | |
Tony Lindgren | b76c8b19 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 1657 | omap_postcore_initcall(gpmc_init); |
Afzal Mohammed | da49687 | 2012-09-23 17:28:25 -0600 | [diff] [blame] | 1658 | module_exit(gpmc_exit); |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1659 | |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1660 | static int __init omap_gpmc_init(void) |
| 1661 | { |
| 1662 | struct omap_hwmod *oh; |
| 1663 | struct platform_device *pdev; |
| 1664 | char *oh_name = "gpmc"; |
| 1665 | |
Daniel Mack | 2f98ca8 | 2012-12-14 11:36:40 +0100 | [diff] [blame] | 1666 | /* |
| 1667 | * if the board boots up with a populated DT, do not |
| 1668 | * manually add the device from this initcall |
| 1669 | */ |
| 1670 | if (of_have_populated_dt()) |
| 1671 | return -ENODEV; |
| 1672 | |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1673 | oh = omap_hwmod_lookup(oh_name); |
| 1674 | if (!oh) { |
| 1675 | pr_err("Could not look up %s\n", oh_name); |
| 1676 | return -ENODEV; |
| 1677 | } |
| 1678 | |
Paul Walmsley | c1d1cd5 | 2013-01-26 00:48:53 -0700 | [diff] [blame] | 1679 | pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0); |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1680 | WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name); |
| 1681 | |
| 1682 | return IS_ERR(pdev) ? PTR_ERR(pdev) : 0; |
| 1683 | } |
Tony Lindgren | b76c8b19 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 1684 | omap_postcore_initcall(omap_gpmc_init); |
Afzal Mohammed | 4be48fd | 2012-09-23 17:28:24 -0600 | [diff] [blame] | 1685 | |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1686 | static irqreturn_t gpmc_handle_irq(int irq, void *dev) |
| 1687 | { |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 1688 | int i; |
| 1689 | u32 regval; |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1690 | |
Afzal Mohammed | 6b6c32f | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 1691 | regval = gpmc_read_reg(GPMC_IRQSTATUS); |
| 1692 | |
| 1693 | if (!regval) |
| 1694 | return IRQ_NONE; |
| 1695 | |
| 1696 | for (i = 0; i < GPMC_NR_IRQ; i++) |
| 1697 | if (regval & gpmc_client_irq[i].bitmask) |
| 1698 | generic_handle_irq(gpmc_client_irq[i].irq); |
| 1699 | |
| 1700 | gpmc_write_reg(GPMC_IRQSTATUS, regval); |
Sukumar Ghorai | db97eb7d | 2011-01-28 15:42:05 +0530 | [diff] [blame] | 1701 | |
| 1702 | return IRQ_HANDLED; |
Juha Yrjola | 4bbbc1a | 2006-06-26 16:16:16 -0700 | [diff] [blame] | 1703 | } |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1704 | |
| 1705 | #ifdef CONFIG_ARCH_OMAP3 |
| 1706 | static struct omap3_gpmc_regs gpmc_context; |
| 1707 | |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1708 | void omap3_gpmc_save_context(void) |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1709 | { |
| 1710 | int i; |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1711 | |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1712 | gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG); |
| 1713 | gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE); |
| 1714 | gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL); |
| 1715 | gpmc_context.config = gpmc_read_reg(GPMC_CONFIG); |
| 1716 | gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1); |
| 1717 | gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2); |
| 1718 | gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL); |
| 1719 | for (i = 0; i < GPMC_CS_NUM; i++) { |
| 1720 | gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i); |
| 1721 | if (gpmc_context.cs_context[i].is_valid) { |
| 1722 | gpmc_context.cs_context[i].config1 = |
| 1723 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG1); |
| 1724 | gpmc_context.cs_context[i].config2 = |
| 1725 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG2); |
| 1726 | gpmc_context.cs_context[i].config3 = |
| 1727 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG3); |
| 1728 | gpmc_context.cs_context[i].config4 = |
| 1729 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG4); |
| 1730 | gpmc_context.cs_context[i].config5 = |
| 1731 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG5); |
| 1732 | gpmc_context.cs_context[i].config6 = |
| 1733 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG6); |
| 1734 | gpmc_context.cs_context[i].config7 = |
| 1735 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG7); |
| 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1740 | void omap3_gpmc_restore_context(void) |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1741 | { |
| 1742 | int i; |
Felipe Balbi | b2fa3b7 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1743 | |
Rajendra Nayak | a2d3e7b | 2008-09-26 17:47:33 +0530 | [diff] [blame] | 1744 | gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig); |
| 1745 | gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable); |
| 1746 | gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl); |
| 1747 | gpmc_write_reg(GPMC_CONFIG, gpmc_context.config); |
| 1748 | gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1); |
| 1749 | gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2); |
| 1750 | gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control); |
| 1751 | for (i = 0; i < GPMC_CS_NUM; i++) { |
| 1752 | if (gpmc_context.cs_context[i].is_valid) { |
| 1753 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG1, |
| 1754 | gpmc_context.cs_context[i].config1); |
| 1755 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG2, |
| 1756 | gpmc_context.cs_context[i].config2); |
| 1757 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG3, |
| 1758 | gpmc_context.cs_context[i].config3); |
| 1759 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG4, |
| 1760 | gpmc_context.cs_context[i].config4); |
| 1761 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG5, |
| 1762 | gpmc_context.cs_context[i].config5); |
| 1763 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG6, |
| 1764 | gpmc_context.cs_context[i].config6); |
| 1765 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG7, |
| 1766 | gpmc_context.cs_context[i].config7); |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | #endif /* CONFIG_ARCH_OMAP3 */ |