diff options
| author | Tony Lindgren <tony@atomide.com> | 2014-11-20 12:13:42 -0500 |
|---|---|---|
| committer | Tony Lindgren <tony@atomide.com> | 2014-11-28 15:54:39 -0500 |
| commit | 186401937927426f85a28bd798e82ca18e4e5549 (patch) | |
| tree | c7d392c85bbf5fdb055389ddd4faf704b8457a6b /drivers/memory | |
| parent | a86128093845e1947454c68040d69259c805f882 (diff) | |
memory: gpmc: Move omap gpmc code to live under drivers
Just move to drivers as further clean-up can now happen there
finally.
Let's also add Roger and me to the MAINTAINERS so we get
notified for any patches related to GPMC.
Cc: Arnd Bergmann <arnd@arndb.de>
Acked-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'drivers/memory')
| -rw-r--r-- | drivers/memory/Kconfig | 8 | ||||
| -rw-r--r-- | drivers/memory/Makefile | 1 | ||||
| -rw-r--r-- | drivers/memory/omap-gpmc.c | 2094 |
3 files changed, 2103 insertions, 0 deletions
diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig index 6d91c27fd4c8..6759de7ce209 100644 --- a/drivers/memory/Kconfig +++ b/drivers/memory/Kconfig | |||
| @@ -41,6 +41,14 @@ config TI_EMIF | |||
| 41 | parameters and other settings during frequency, voltage and | 41 | parameters and other settings during frequency, voltage and |
| 42 | temperature changes | 42 | temperature changes |
| 43 | 43 | ||
| 44 | config OMAP_GPMC | ||
| 45 | bool | ||
| 46 | help | ||
| 47 | This driver is for the General Purpose Memory Controller (GPMC) | ||
| 48 | present on Texas Instruments SoCs (e.g. OMAP2+). GPMC allows | ||
| 49 | interfacing to a variety of asynchronous as well as synchronous | ||
| 50 | memory drives like NOR, NAND, OneNAND, SRAM. | ||
| 51 | |||
| 44 | config MVEBU_DEVBUS | 52 | config MVEBU_DEVBUS |
| 45 | bool "Marvell EBU Device Bus Controller" | 53 | bool "Marvell EBU Device Bus Controller" |
| 46 | default y | 54 | default y |
diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index c32d31981be3..a7d410f3ca32 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile | |||
| @@ -8,6 +8,7 @@ endif | |||
| 8 | obj-$(CONFIG_ATMEL_SDRAMC) += atmel-sdramc.o | 8 | obj-$(CONFIG_ATMEL_SDRAMC) += atmel-sdramc.o |
| 9 | obj-$(CONFIG_TI_AEMIF) += ti-aemif.o | 9 | obj-$(CONFIG_TI_AEMIF) += ti-aemif.o |
| 10 | obj-$(CONFIG_TI_EMIF) += emif.o | 10 | obj-$(CONFIG_TI_EMIF) += emif.o |
| 11 | obj-$(CONFIG_OMAP_GPMC) += omap-gpmc.o | ||
| 11 | obj-$(CONFIG_FSL_CORENET_CF) += fsl-corenet-cf.o | 12 | obj-$(CONFIG_FSL_CORENET_CF) += fsl-corenet-cf.o |
| 12 | obj-$(CONFIG_FSL_IFC) += fsl_ifc.o | 13 | obj-$(CONFIG_FSL_IFC) += fsl_ifc.o |
| 13 | obj-$(CONFIG_MVEBU_DEVBUS) += mvebu-devbus.o | 14 | obj-$(CONFIG_MVEBU_DEVBUS) += mvebu-devbus.o |
diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c new file mode 100644 index 000000000000..abfc0ddd076e --- /dev/null +++ b/drivers/memory/omap-gpmc.c | |||
| @@ -0,0 +1,2094 @@ | |||
| 1 | /* | ||
| 2 | * GPMC support functions | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2006 Nokia Corporation | ||
| 5 | * | ||
| 6 | * Author: Juha Yrjola | ||
| 7 | * | ||
| 8 | * Copyright (C) 2009 Texas Instruments | ||
| 9 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> | ||
| 10 | * | ||
| 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 | */ | ||
| 15 | #undef DEBUG | ||
| 16 | |||
| 17 | #include <linux/irq.h> | ||
| 18 | #include <linux/kernel.h> | ||
| 19 | #include <linux/init.h> | ||
| 20 | #include <linux/err.h> | ||
| 21 | #include <linux/clk.h> | ||
| 22 | #include <linux/ioport.h> | ||
| 23 | #include <linux/spinlock.h> | ||
| 24 | #include <linux/io.h> | ||
| 25 | #include <linux/module.h> | ||
| 26 | #include <linux/interrupt.h> | ||
| 27 | #include <linux/platform_device.h> | ||
| 28 | #include <linux/of.h> | ||
| 29 | #include <linux/of_address.h> | ||
| 30 | #include <linux/of_mtd.h> | ||
| 31 | #include <linux/of_device.h> | ||
| 32 | #include <linux/omap-gpmc.h> | ||
| 33 | #include <linux/mtd/nand.h> | ||
| 34 | #include <linux/pm_runtime.h> | ||
| 35 | |||
| 36 | #include <linux/platform_data/mtd-nand-omap2.h> | ||
| 37 | #include <linux/platform_data/mtd-onenand-omap2.h> | ||
| 38 | |||
| 39 | #include <asm/mach-types.h> | ||
| 40 | |||
| 41 | #define DEVICE_NAME "omap-gpmc" | ||
| 42 | |||
| 43 | /* GPMC register offsets */ | ||
| 44 | #define GPMC_REVISION 0x00 | ||
| 45 | #define GPMC_SYSCONFIG 0x10 | ||
| 46 | #define GPMC_SYSSTATUS 0x14 | ||
| 47 | #define GPMC_IRQSTATUS 0x18 | ||
| 48 | #define GPMC_IRQENABLE 0x1c | ||
| 49 | #define GPMC_TIMEOUT_CONTROL 0x40 | ||
| 50 | #define GPMC_ERR_ADDRESS 0x44 | ||
| 51 | #define GPMC_ERR_TYPE 0x48 | ||
| 52 | #define GPMC_CONFIG 0x50 | ||
| 53 | #define GPMC_STATUS 0x54 | ||
| 54 | #define GPMC_PREFETCH_CONFIG1 0x1e0 | ||
| 55 | #define GPMC_PREFETCH_CONFIG2 0x1e4 | ||
| 56 | #define GPMC_PREFETCH_CONTROL 0x1ec | ||
| 57 | #define GPMC_PREFETCH_STATUS 0x1f0 | ||
| 58 | #define GPMC_ECC_CONFIG 0x1f4 | ||
| 59 | #define GPMC_ECC_CONTROL 0x1f8 | ||
| 60 | #define GPMC_ECC_SIZE_CONFIG 0x1fc | ||
| 61 | #define GPMC_ECC1_RESULT 0x200 | ||
| 62 | #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */ | ||
| 63 | #define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */ | ||
| 64 | #define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */ | ||
| 65 | #define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */ | ||
| 66 | #define GPMC_ECC_BCH_RESULT_4 0x300 /* not available on OMAP2 */ | ||
| 67 | #define GPMC_ECC_BCH_RESULT_5 0x304 /* not available on OMAP2 */ | ||
| 68 | #define GPMC_ECC_BCH_RESULT_6 0x308 /* not available on OMAP2 */ | ||
| 69 | |||
| 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 | |||
| 83 | #define GPMC_CONFIG_LIMITEDADDRESS BIT(1) | ||
| 84 | |||
| 85 | #define GPMC_CONFIG2_CSEXTRADELAY BIT(7) | ||
| 86 | #define GPMC_CONFIG3_ADVEXTRADELAY BIT(7) | ||
| 87 | #define GPMC_CONFIG4_OEEXTRADELAY BIT(7) | ||
| 88 | #define GPMC_CONFIG4_WEEXTRADELAY BIT(23) | ||
| 89 | #define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6) | ||
| 90 | #define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7) | ||
| 91 | |||
| 92 | #define GPMC_CS0_OFFSET 0x60 | ||
| 93 | #define GPMC_CS_SIZE 0x30 | ||
| 94 | #define GPMC_BCH_SIZE 0x10 | ||
| 95 | |||
| 96 | #define GPMC_MEM_END 0x3FFFFFFF | ||
| 97 | |||
| 98 | #define GPMC_CHUNK_SHIFT 24 /* 16 MB */ | ||
| 99 | #define GPMC_SECTION_SHIFT 28 /* 128 MB */ | ||
| 100 | |||
| 101 | #define CS_NUM_SHIFT 24 | ||
| 102 | #define ENABLE_PREFETCH (0x1 << 7) | ||
| 103 | #define DMA_MPU_MODE 2 | ||
| 104 | |||
| 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 | #define GPMC_HAS_MUX_AAD 0x4 | ||
| 111 | |||
| 112 | #define GPMC_NR_WAITPINS 4 | ||
| 113 | |||
| 114 | #define GPMC_CS_CONFIG1 0x00 | ||
| 115 | #define GPMC_CS_CONFIG2 0x04 | ||
| 116 | #define GPMC_CS_CONFIG3 0x08 | ||
| 117 | #define GPMC_CS_CONFIG4 0x0c | ||
| 118 | #define GPMC_CS_CONFIG5 0x10 | ||
| 119 | #define GPMC_CS_CONFIG6 0x14 | ||
| 120 | #define GPMC_CS_CONFIG7 0x18 | ||
| 121 | #define GPMC_CS_NAND_COMMAND 0x1c | ||
| 122 | #define GPMC_CS_NAND_ADDRESS 0x20 | ||
| 123 | #define GPMC_CS_NAND_DATA 0x24 | ||
| 124 | |||
| 125 | /* Control Commands */ | ||
| 126 | #define GPMC_CONFIG_RDY_BSY 0x00000001 | ||
| 127 | #define GPMC_CONFIG_DEV_SIZE 0x00000002 | ||
| 128 | #define GPMC_CONFIG_DEV_TYPE 0x00000003 | ||
| 129 | #define GPMC_SET_IRQ_STATUS 0x00000004 | ||
| 130 | |||
| 131 | #define GPMC_CONFIG1_WRAPBURST_SUPP (1 << 31) | ||
| 132 | #define GPMC_CONFIG1_READMULTIPLE_SUPP (1 << 30) | ||
| 133 | #define GPMC_CONFIG1_READTYPE_ASYNC (0 << 29) | ||
| 134 | #define GPMC_CONFIG1_READTYPE_SYNC (1 << 29) | ||
| 135 | #define GPMC_CONFIG1_WRITEMULTIPLE_SUPP (1 << 28) | ||
| 136 | #define GPMC_CONFIG1_WRITETYPE_ASYNC (0 << 27) | ||
| 137 | #define GPMC_CONFIG1_WRITETYPE_SYNC (1 << 27) | ||
| 138 | #define GPMC_CONFIG1_CLKACTIVATIONTIME(val) ((val & 3) << 25) | ||
| 139 | #define GPMC_CONFIG1_PAGE_LEN(val) ((val & 3) << 23) | ||
| 140 | #define GPMC_CONFIG1_WAIT_READ_MON (1 << 22) | ||
| 141 | #define GPMC_CONFIG1_WAIT_WRITE_MON (1 << 21) | ||
| 142 | #define GPMC_CONFIG1_WAIT_MON_IIME(val) ((val & 3) << 18) | ||
| 143 | #define GPMC_CONFIG1_WAIT_PIN_SEL(val) ((val & 3) << 16) | ||
| 144 | #define GPMC_CONFIG1_DEVICESIZE(val) ((val & 3) << 12) | ||
| 145 | #define GPMC_CONFIG1_DEVICESIZE_16 GPMC_CONFIG1_DEVICESIZE(1) | ||
| 146 | #define GPMC_CONFIG1_DEVICETYPE(val) ((val & 3) << 10) | ||
| 147 | #define GPMC_CONFIG1_DEVICETYPE_NOR GPMC_CONFIG1_DEVICETYPE(0) | ||
| 148 | #define GPMC_CONFIG1_MUXTYPE(val) ((val & 3) << 8) | ||
| 149 | #define GPMC_CONFIG1_TIME_PARA_GRAN (1 << 4) | ||
| 150 | #define GPMC_CONFIG1_FCLK_DIV(val) (val & 3) | ||
| 151 | #define GPMC_CONFIG1_FCLK_DIV2 (GPMC_CONFIG1_FCLK_DIV(1)) | ||
| 152 | #define GPMC_CONFIG1_FCLK_DIV3 (GPMC_CONFIG1_FCLK_DIV(2)) | ||
| 153 | #define GPMC_CONFIG1_FCLK_DIV4 (GPMC_CONFIG1_FCLK_DIV(3)) | ||
| 154 | #define GPMC_CONFIG7_CSVALID (1 << 6) | ||
| 155 | |||
| 156 | #define GPMC_DEVICETYPE_NOR 0 | ||
| 157 | #define GPMC_DEVICETYPE_NAND 2 | ||
| 158 | #define GPMC_CONFIG_WRITEPROTECT 0x00000010 | ||
| 159 | #define WR_RD_PIN_MONITORING 0x00600000 | ||
| 160 | |||
| 161 | #define GPMC_ENABLE_IRQ 0x0000000d | ||
| 162 | |||
| 163 | /* ECC commands */ | ||
| 164 | #define GPMC_ECC_READ 0 /* Reset Hardware ECC for read */ | ||
| 165 | #define GPMC_ECC_WRITE 1 /* Reset Hardware ECC for write */ | ||
| 166 | #define GPMC_ECC_READSYN 2 /* Reset before syndrom is read back */ | ||
| 167 | |||
| 168 | /* XXX: Only NAND irq has been considered,currently these are the only ones used | ||
| 169 | */ | ||
| 170 | #define GPMC_NR_IRQ 2 | ||
| 171 | |||
| 172 | struct gpmc_cs_data { | ||
| 173 | const char *name; | ||
| 174 | |||
| 175 | #define GPMC_CS_RESERVED (1 << 0) | ||
| 176 | u32 flags; | ||
| 177 | |||
| 178 | struct resource mem; | ||
| 179 | }; | ||
| 180 | |||
| 181 | struct gpmc_client_irq { | ||
| 182 | unsigned irq; | ||
| 183 | u32 bitmask; | ||
| 184 | }; | ||
| 185 | |||
| 186 | /* Structure to save gpmc cs context */ | ||
| 187 | struct gpmc_cs_config { | ||
| 188 | u32 config1; | ||
| 189 | u32 config2; | ||
| 190 | u32 config3; | ||
| 191 | u32 config4; | ||
| 192 | u32 config5; | ||
| 193 | u32 config6; | ||
| 194 | u32 config7; | ||
| 195 | int is_valid; | ||
| 196 | }; | ||
| 197 | |||
| 198 | /* | ||
| 199 | * Structure to save/restore gpmc context | ||
| 200 | * to support core off on OMAP3 | ||
| 201 | */ | ||
| 202 | struct omap3_gpmc_regs { | ||
| 203 | u32 sysconfig; | ||
| 204 | u32 irqenable; | ||
| 205 | u32 timeout_ctrl; | ||
| 206 | u32 config; | ||
| 207 | u32 prefetch_config1; | ||
| 208 | u32 prefetch_config2; | ||
| 209 | u32 prefetch_control; | ||
| 210 | struct gpmc_cs_config cs_context[GPMC_CS_NUM]; | ||
| 211 | }; | ||
| 212 | |||
| 213 | static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ]; | ||
| 214 | static struct irq_chip gpmc_irq_chip; | ||
| 215 | static int gpmc_irq_start; | ||
| 216 | |||
| 217 | static struct resource gpmc_mem_root; | ||
| 218 | static struct gpmc_cs_data gpmc_cs[GPMC_CS_NUM]; | ||
| 219 | static DEFINE_SPINLOCK(gpmc_mem_lock); | ||
| 220 | /* Define chip-selects as reserved by default until probe completes */ | ||
| 221 | static unsigned int gpmc_cs_num = GPMC_CS_NUM; | ||
| 222 | static unsigned int gpmc_nr_waitpins; | ||
| 223 | static struct device *gpmc_dev; | ||
| 224 | static int gpmc_irq; | ||
| 225 | static resource_size_t phys_base, mem_size; | ||
| 226 | static unsigned gpmc_capability; | ||
| 227 | static void __iomem *gpmc_base; | ||
| 228 | |||
| 229 | static struct clk *gpmc_l3_clk; | ||
| 230 | |||
| 231 | static irqreturn_t gpmc_handle_irq(int irq, void *dev); | ||
| 232 | |||
| 233 | static void gpmc_write_reg(int idx, u32 val) | ||
| 234 | { | ||
| 235 | writel_relaxed(val, gpmc_base + idx); | ||
| 236 | } | ||
| 237 | |||
| 238 | static u32 gpmc_read_reg(int idx) | ||
| 239 | { | ||
| 240 | return readl_relaxed(gpmc_base + idx); | ||
| 241 | } | ||
| 242 | |||
| 243 | void gpmc_cs_write_reg(int cs, int idx, u32 val) | ||
| 244 | { | ||
| 245 | void __iomem *reg_addr; | ||
| 246 | |||
| 247 | reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; | ||
| 248 | writel_relaxed(val, reg_addr); | ||
| 249 | } | ||
| 250 | |||
| 251 | static u32 gpmc_cs_read_reg(int cs, int idx) | ||
| 252 | { | ||
| 253 | void __iomem *reg_addr; | ||
| 254 | |||
| 255 | reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; | ||
| 256 | return readl_relaxed(reg_addr); | ||
| 257 | } | ||
| 258 | |||
| 259 | /* TODO: Add support for gpmc_fck to clock framework and use it */ | ||
| 260 | static unsigned long gpmc_get_fclk_period(void) | ||
| 261 | { | ||
| 262 | unsigned long rate = clk_get_rate(gpmc_l3_clk); | ||
| 263 | |||
| 264 | rate /= 1000; | ||
| 265 | rate = 1000000000 / rate; /* In picoseconds */ | ||
| 266 | |||
| 267 | return rate; | ||
| 268 | } | ||
| 269 | |||
| 270 | static unsigned int gpmc_ns_to_ticks(unsigned int time_ns) | ||
| 271 | { | ||
| 272 | unsigned long tick_ps; | ||
| 273 | |||
| 274 | /* Calculate in picosecs to yield more exact results */ | ||
| 275 | tick_ps = gpmc_get_fclk_period(); | ||
| 276 | |||
| 277 | return (time_ns * 1000 + tick_ps - 1) / tick_ps; | ||
| 278 | } | ||
| 279 | |||
| 280 | static unsigned int gpmc_ps_to_ticks(unsigned int time_ps) | ||
| 281 | { | ||
| 282 | unsigned long tick_ps; | ||
| 283 | |||
| 284 | /* Calculate in picosecs to yield more exact results */ | ||
| 285 | tick_ps = gpmc_get_fclk_period(); | ||
| 286 | |||
| 287 | return (time_ps + tick_ps - 1) / tick_ps; | ||
| 288 | } | ||
| 289 | |||
| 290 | unsigned int gpmc_ticks_to_ns(unsigned int ticks) | ||
| 291 | { | ||
| 292 | return ticks * gpmc_get_fclk_period() / 1000; | ||
| 293 | } | ||
| 294 | |||
| 295 | static unsigned int gpmc_ticks_to_ps(unsigned int ticks) | ||
| 296 | { | ||
| 297 | return ticks * gpmc_get_fclk_period(); | ||
| 298 | } | ||
| 299 | |||
| 300 | static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps) | ||
| 301 | { | ||
| 302 | unsigned long ticks = gpmc_ps_to_ticks(time_ps); | ||
| 303 | |||
| 304 | return ticks * gpmc_get_fclk_period(); | ||
| 305 | } | ||
| 306 | |||
| 307 | static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value) | ||
| 308 | { | ||
| 309 | u32 l; | ||
| 310 | |||
| 311 | l = gpmc_cs_read_reg(cs, reg); | ||
| 312 | if (value) | ||
| 313 | l |= mask; | ||
| 314 | else | ||
| 315 | l &= ~mask; | ||
| 316 | gpmc_cs_write_reg(cs, reg, l); | ||
| 317 | } | ||
| 318 | |||
| 319 | static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p) | ||
| 320 | { | ||
| 321 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1, | ||
| 322 | GPMC_CONFIG1_TIME_PARA_GRAN, | ||
| 323 | p->time_para_granularity); | ||
| 324 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2, | ||
| 325 | GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay); | ||
| 326 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3, | ||
| 327 | GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay); | ||
| 328 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4, | ||
| 329 | GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay); | ||
| 330 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4, | ||
| 331 | GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay); | ||
| 332 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6, | ||
| 333 | GPMC_CONFIG6_CYCLE2CYCLESAMECSEN, | ||
| 334 | p->cycle2cyclesamecsen); | ||
| 335 | gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6, | ||
| 336 | GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN, | ||
| 337 | p->cycle2cyclediffcsen); | ||
| 338 | } | ||
| 339 | |||
| 340 | #ifdef DEBUG | ||
| 341 | static int get_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, | ||
| 342 | bool raw, bool noval, int shift, | ||
| 343 | const char *name) | ||
| 344 | { | ||
| 345 | u32 l; | ||
| 346 | int nr_bits, max_value, mask; | ||
| 347 | |||
| 348 | l = gpmc_cs_read_reg(cs, reg); | ||
| 349 | nr_bits = end_bit - st_bit + 1; | ||
| 350 | max_value = (1 << nr_bits) - 1; | ||
| 351 | mask = max_value << st_bit; | ||
| 352 | l = (l & mask) >> st_bit; | ||
| 353 | if (shift) | ||
| 354 | l = (shift << l); | ||
| 355 | if (noval && (l == 0)) | ||
| 356 | return 0; | ||
| 357 | if (!raw) { | ||
| 358 | unsigned int time_ns_min, time_ns, time_ns_max; | ||
| 359 | |||
| 360 | time_ns_min = gpmc_ticks_to_ns(l ? l - 1 : 0); | ||
| 361 | time_ns = gpmc_ticks_to_ns(l); | ||
| 362 | time_ns_max = gpmc_ticks_to_ns(l + 1 > max_value ? | ||
| 363 | max_value : l + 1); | ||
| 364 | pr_info("gpmc,%s = <%u> (%u - %u ns, %i ticks)\n", | ||
| 365 | name, time_ns, time_ns_min, time_ns_max, l); | ||
| 366 | } else { | ||
| 367 | pr_info("gpmc,%s = <%u>\n", name, l); | ||
| 368 | } | ||
| 369 | |||
| 370 | return l; | ||
| 371 | } | ||
| 372 | |||
| 373 | #define GPMC_PRINT_CONFIG(cs, config) \ | ||
| 374 | pr_info("cs%i %s: 0x%08x\n", cs, #config, \ | ||
| 375 | gpmc_cs_read_reg(cs, config)) | ||
| 376 | #define GPMC_GET_RAW(reg, st, end, field) \ | ||
| 377 | get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 0, 0, field) | ||
| 378 | #define GPMC_GET_RAW_BOOL(reg, st, end, field) \ | ||
| 379 | get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, 0, field) | ||
| 380 | #define GPMC_GET_RAW_SHIFT(reg, st, end, shift, field) \ | ||
| 381 | get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, (shift), field) | ||
| 382 | #define GPMC_GET_TICKS(reg, st, end, field) \ | ||
| 383 | get_gpmc_timing_reg(cs, (reg), (st), (end), 0, 0, 0, field) | ||
| 384 | |||
| 385 | static void gpmc_show_regs(int cs, const char *desc) | ||
| 386 | { | ||
| 387 | pr_info("gpmc cs%i %s:\n", cs, desc); | ||
| 388 | GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG1); | ||
| 389 | GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG2); | ||
| 390 | GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG3); | ||
| 391 | GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG4); | ||
| 392 | GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG5); | ||
| 393 | GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG6); | ||
| 394 | } | ||
| 395 | |||
| 396 | /* | ||
| 397 | * Note that gpmc,wait-pin handing wrongly assumes bit 8 is available, | ||
| 398 | * see commit c9fb809. | ||
| 399 | */ | ||
| 400 | static void gpmc_cs_show_timings(int cs, const char *desc) | ||
| 401 | { | ||
| 402 | gpmc_show_regs(cs, desc); | ||
| 403 | |||
| 404 | pr_info("gpmc cs%i access configuration:\n", cs); | ||
| 405 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 4, 4, "time-para-granularity"); | ||
| 406 | GPMC_GET_RAW(GPMC_CS_CONFIG1, 8, 9, "mux-add-data"); | ||
| 407 | GPMC_GET_RAW(GPMC_CS_CONFIG1, 12, 13, "device-width"); | ||
| 408 | GPMC_GET_RAW(GPMC_CS_CONFIG1, 16, 17, "wait-pin"); | ||
| 409 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 21, 21, "wait-on-write"); | ||
| 410 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 22, 22, "wait-on-read"); | ||
| 411 | GPMC_GET_RAW_SHIFT(GPMC_CS_CONFIG1, 23, 24, 4, "burst-length"); | ||
| 412 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 27, 27, "sync-write"); | ||
| 413 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 28, 28, "burst-write"); | ||
| 414 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 29, 29, "gpmc,sync-read"); | ||
| 415 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 30, 30, "burst-read"); | ||
| 416 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 31, 31, "burst-wrap"); | ||
| 417 | |||
| 418 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay"); | ||
| 419 | |||
| 420 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG3, 7, 7, "adv-extra-delay"); | ||
| 421 | |||
| 422 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 23, 23, "we-extra-delay"); | ||
| 423 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 7, 7, "oe-extra-delay"); | ||
| 424 | |||
| 425 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 7, 7, "cycle2cycle-samecsen"); | ||
| 426 | GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 6, 6, "cycle2cycle-diffcsen"); | ||
| 427 | |||
| 428 | pr_info("gpmc cs%i timings configuration:\n", cs); | ||
| 429 | GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns"); | ||
| 430 | GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns"); | ||
| 431 | GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns"); | ||
| 432 | |||
| 433 | GPMC_GET_TICKS(GPMC_CS_CONFIG3, 0, 3, "adv-on-ns"); | ||
| 434 | GPMC_GET_TICKS(GPMC_CS_CONFIG3, 8, 12, "adv-rd-off-ns"); | ||
| 435 | GPMC_GET_TICKS(GPMC_CS_CONFIG3, 16, 20, "adv-wr-off-ns"); | ||
| 436 | |||
| 437 | GPMC_GET_TICKS(GPMC_CS_CONFIG4, 0, 3, "oe-on-ns"); | ||
| 438 | GPMC_GET_TICKS(GPMC_CS_CONFIG4, 8, 12, "oe-off-ns"); | ||
| 439 | GPMC_GET_TICKS(GPMC_CS_CONFIG4, 16, 19, "we-on-ns"); | ||
| 440 | GPMC_GET_TICKS(GPMC_CS_CONFIG4, 24, 28, "we-off-ns"); | ||
| 441 | |||
| 442 | GPMC_GET_TICKS(GPMC_CS_CONFIG5, 0, 4, "rd-cycle-ns"); | ||
| 443 | GPMC_GET_TICKS(GPMC_CS_CONFIG5, 8, 12, "wr-cycle-ns"); | ||
| 444 | GPMC_GET_TICKS(GPMC_CS_CONFIG5, 16, 20, "access-ns"); | ||
| 445 | |||
| 446 | GPMC_GET_TICKS(GPMC_CS_CONFIG5, 24, 27, "page-burst-access-ns"); | ||
| 447 | |||
| 448 | GPMC_GET_TICKS(GPMC_CS_CONFIG6, 0, 3, "bus-turnaround-ns"); | ||
| 449 | GPMC_GET_TICKS(GPMC_CS_CONFIG6, 8, 11, "cycle2cycle-delay-ns"); | ||
| 450 | |||
| 451 | GPMC_GET_TICKS(GPMC_CS_CONFIG1, 18, 19, "wait-monitoring-ns"); | ||
| 452 | GPMC_GET_TICKS(GPMC_CS_CONFIG1, 25, 26, "clk-activation-ns"); | ||
| 453 | |||
| 454 | GPMC_GET_TICKS(GPMC_CS_CONFIG6, 16, 19, "wr-data-mux-bus-ns"); | ||
| 455 | GPMC_GET_TICKS(GPMC_CS_CONFIG6, 24, 28, "wr-access-ns"); | ||
| 456 | } | ||
| 457 | #else | ||
| 458 | static inline void gpmc_cs_show_timings(int cs, const char *desc) | ||
| 459 | { | ||
| 460 | } | ||
| 461 | #endif | ||
| 462 | |||
| 463 | static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, | ||
| 464 | int time, const char *name) | ||
| 465 | { | ||
| 466 | u32 l; | ||
| 467 | int ticks, mask, nr_bits; | ||
| 468 | |||
| 469 | if (time == 0) | ||
| 470 | ticks = 0; | ||
| 471 | else | ||
| 472 | ticks = gpmc_ns_to_ticks(time); | ||
| 473 | nr_bits = end_bit - st_bit + 1; | ||
| 474 | mask = (1 << nr_bits) - 1; | ||
| 475 | |||
| 476 | if (ticks > mask) { | ||
| 477 | pr_err("%s: GPMC error! CS%d: %s: %d ns, %d ticks > %d\n", | ||
| 478 | __func__, cs, name, time, ticks, mask); | ||
| 479 | |||
| 480 | return -1; | ||
| 481 | } | ||
| 482 | |||
| 483 | l = gpmc_cs_read_reg(cs, reg); | ||
| 484 | #ifdef DEBUG | ||
| 485 | printk(KERN_INFO | ||
| 486 | "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n", | ||
| 487 | cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000, | ||
| 488 | (l >> st_bit) & mask, time); | ||
| 489 | #endif | ||
| 490 | l &= ~(mask << st_bit); | ||
| 491 | l |= ticks << st_bit; | ||
| 492 | gpmc_cs_write_reg(cs, reg, l); | ||
| 493 | |||
| 494 | return 0; | ||
| 495 | } | ||
| 496 | |||
| 497 | #define GPMC_SET_ONE(reg, st, end, field) \ | ||
| 498 | if (set_gpmc_timing_reg(cs, (reg), (st), (end), \ | ||
| 499 | t->field, #field) < 0) \ | ||
| 500 | return -1 | ||
| 501 | |||
| 502 | int gpmc_calc_divider(unsigned int sync_clk) | ||
| 503 | { | ||
| 504 | int div; | ||
| 505 | u32 l; | ||
| 506 | |||
| 507 | l = sync_clk + (gpmc_get_fclk_period() - 1); | ||
| 508 | div = l / gpmc_get_fclk_period(); | ||
| 509 | if (div > 4) | ||
| 510 | return -1; | ||
| 511 | if (div <= 0) | ||
| 512 | div = 1; | ||
| 513 | |||
| 514 | return div; | ||
| 515 | } | ||
| 516 | |||
| 517 | int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t) | ||
| 518 | { | ||
| 519 | int div; | ||
| 520 | u32 l; | ||
| 521 | |||
| 522 | gpmc_cs_show_timings(cs, "before gpmc_cs_set_timings"); | ||
| 523 | div = gpmc_calc_divider(t->sync_clk); | ||
| 524 | if (div < 0) | ||
| 525 | return div; | ||
| 526 | |||
| 527 | GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on); | ||
| 528 | GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off); | ||
| 529 | GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off); | ||
| 530 | |||
| 531 | GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on); | ||
| 532 | GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off); | ||
| 533 | GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off); | ||
| 534 | |||
| 535 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on); | ||
| 536 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off); | ||
| 537 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on); | ||
| 538 | GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off); | ||
| 539 | |||
| 540 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle); | ||
| 541 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle); | ||
| 542 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access); | ||
| 543 | |||
| 544 | GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access); | ||
| 545 | |||
| 546 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround); | ||
| 547 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay); | ||
| 548 | |||
| 549 | GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring); | ||
| 550 | GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation); | ||
| 551 | |||
| 552 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) | ||
| 553 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus); | ||
| 554 | if (gpmc_capability & GPMC_HAS_WR_ACCESS) | ||
| 555 | GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access); | ||
| 556 | |||
| 557 | /* caller is expected to have initialized CONFIG1 to cover | ||
| 558 | * at least sync vs async | ||
| 559 | */ | ||
| 560 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); | ||
| 561 | if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) { | ||
| 562 | #ifdef DEBUG | ||
| 563 | printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n", | ||
| 564 | cs, (div * gpmc_get_fclk_period()) / 1000, div); | ||
| 565 | #endif | ||
| 566 | l &= ~0x03; | ||
| 567 | l |= (div - 1); | ||
| 568 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l); | ||
| 569 | } | ||
| 570 | |||
| 571 | gpmc_cs_bool_timings(cs, &t->bool_timings); | ||
| 572 | gpmc_cs_show_timings(cs, "after gpmc_cs_set_timings"); | ||
| 573 | |||
| 574 | return 0; | ||
| 575 | } | ||
| 576 | |||
| 577 | static int gpmc_cs_set_memconf(int cs, u32 base, u32 size) | ||
| 578 | { | ||
| 579 | u32 l; | ||
| 580 | u32 mask; | ||
| 581 | |||
| 582 | /* | ||
| 583 | * Ensure that base address is aligned on a | ||
| 584 | * boundary equal to or greater than size. | ||
| 585 | */ | ||
| 586 | if (base & (size - 1)) | ||
| 587 | return -EINVAL; | ||
| 588 | |||
| 589 | mask = (1 << GPMC_SECTION_SHIFT) - size; | ||
| 590 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); | ||
| 591 | l &= ~0x3f; | ||
| 592 | l = (base >> GPMC_CHUNK_SHIFT) & 0x3f; | ||
| 593 | l &= ~(0x0f << 8); | ||
| 594 | l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8; | ||
| 595 | l |= GPMC_CONFIG7_CSVALID; | ||
| 596 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); | ||
| 597 | |||
| 598 | return 0; | ||
| 599 | } | ||
| 600 | |||
| 601 | static void gpmc_cs_enable_mem(int cs) | ||
| 602 | { | ||
| 603 | u32 l; | ||
| 604 | |||
| 605 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); | ||
| 606 | l |= GPMC_CONFIG7_CSVALID; | ||
| 607 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); | ||
| 608 | } | ||
| 609 | |||
| 610 | static void gpmc_cs_disable_mem(int cs) | ||
| 611 | { | ||
| 612 | u32 l; | ||
| 613 | |||
| 614 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); | ||
| 615 | l &= ~GPMC_CONFIG7_CSVALID; | ||
| 616 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); | ||
| 617 | } | ||
| 618 | |||
| 619 | static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size) | ||
| 620 | { | ||
| 621 | u32 l; | ||
| 622 | u32 mask; | ||
| 623 | |||
| 624 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); | ||
| 625 | *base = (l & 0x3f) << GPMC_CHUNK_SHIFT; | ||
| 626 | mask = (l >> 8) & 0x0f; | ||
| 627 | *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT); | ||
| 628 | } | ||
| 629 | |||
| 630 | static int gpmc_cs_mem_enabled(int cs) | ||
| 631 | { | ||
| 632 | u32 l; | ||
| 633 | |||
| 634 | l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); | ||
| 635 | return l & GPMC_CONFIG7_CSVALID; | ||
| 636 | } | ||
| 637 | |||
| 638 | static void gpmc_cs_set_reserved(int cs, int reserved) | ||
| 639 | { | ||
| 640 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 641 | |||
| 642 | gpmc->flags |= GPMC_CS_RESERVED; | ||
| 643 | } | ||
| 644 | |||
| 645 | static bool gpmc_cs_reserved(int cs) | ||
| 646 | { | ||
| 647 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 648 | |||
| 649 | return gpmc->flags & GPMC_CS_RESERVED; | ||
| 650 | } | ||
| 651 | |||
| 652 | static void gpmc_cs_set_name(int cs, const char *name) | ||
| 653 | { | ||
| 654 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 655 | |||
| 656 | gpmc->name = name; | ||
| 657 | } | ||
| 658 | |||
| 659 | const char *gpmc_cs_get_name(int cs) | ||
| 660 | { | ||
| 661 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 662 | |||
| 663 | return gpmc->name; | ||
| 664 | } | ||
| 665 | |||
| 666 | static unsigned long gpmc_mem_align(unsigned long size) | ||
| 667 | { | ||
| 668 | int order; | ||
| 669 | |||
| 670 | size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1); | ||
| 671 | order = GPMC_CHUNK_SHIFT - 1; | ||
| 672 | do { | ||
| 673 | size >>= 1; | ||
| 674 | order++; | ||
| 675 | } while (size); | ||
| 676 | size = 1 << order; | ||
| 677 | return size; | ||
| 678 | } | ||
| 679 | |||
| 680 | static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size) | ||
| 681 | { | ||
| 682 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 683 | struct resource *res = &gpmc->mem; | ||
| 684 | int r; | ||
| 685 | |||
| 686 | size = gpmc_mem_align(size); | ||
| 687 | spin_lock(&gpmc_mem_lock); | ||
| 688 | res->start = base; | ||
| 689 | res->end = base + size - 1; | ||
| 690 | r = request_resource(&gpmc_mem_root, res); | ||
| 691 | spin_unlock(&gpmc_mem_lock); | ||
| 692 | |||
| 693 | return r; | ||
| 694 | } | ||
| 695 | |||
| 696 | static int gpmc_cs_delete_mem(int cs) | ||
| 697 | { | ||
| 698 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 699 | struct resource *res = &gpmc->mem; | ||
| 700 | int r; | ||
| 701 | |||
| 702 | spin_lock(&gpmc_mem_lock); | ||
| 703 | r = release_resource(res); | ||
| 704 | res->start = 0; | ||
| 705 | res->end = 0; | ||
| 706 | spin_unlock(&gpmc_mem_lock); | ||
| 707 | |||
| 708 | return r; | ||
| 709 | } | ||
| 710 | |||
| 711 | /** | ||
| 712 | * gpmc_cs_remap - remaps a chip-select physical base address | ||
| 713 | * @cs: chip-select to remap | ||
| 714 | * @base: physical base address to re-map chip-select to | ||
| 715 | * | ||
| 716 | * Re-maps a chip-select to a new physical base address specified by | ||
| 717 | * "base". Returns 0 on success and appropriate negative error code | ||
| 718 | * on failure. | ||
| 719 | */ | ||
| 720 | static int gpmc_cs_remap(int cs, u32 base) | ||
| 721 | { | ||
| 722 | int ret; | ||
| 723 | u32 old_base, size; | ||
| 724 | |||
| 725 | if (cs > gpmc_cs_num) { | ||
| 726 | pr_err("%s: requested chip-select is disabled\n", __func__); | ||
| 727 | return -ENODEV; | ||
| 728 | } | ||
| 729 | |||
| 730 | /* | ||
| 731 | * Make sure we ignore any device offsets from the GPMC partition | ||
| 732 | * allocated for the chip select and that the new base confirms | ||
| 733 | * to the GPMC 16MB minimum granularity. | ||
| 734 | */ | ||
| 735 | base &= ~(SZ_16M - 1); | ||
| 736 | |||
| 737 | gpmc_cs_get_memconf(cs, &old_base, &size); | ||
| 738 | if (base == old_base) | ||
| 739 | return 0; | ||
| 740 | |||
| 741 | ret = gpmc_cs_delete_mem(cs); | ||
| 742 | if (ret < 0) | ||
| 743 | return ret; | ||
| 744 | |||
| 745 | ret = gpmc_cs_insert_mem(cs, base, size); | ||
| 746 | if (ret < 0) | ||
| 747 | return ret; | ||
| 748 | |||
| 749 | ret = gpmc_cs_set_memconf(cs, base, size); | ||
| 750 | |||
| 751 | return ret; | ||
| 752 | } | ||
| 753 | |||
| 754 | int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) | ||
| 755 | { | ||
| 756 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 757 | struct resource *res = &gpmc->mem; | ||
| 758 | int r = -1; | ||
| 759 | |||
| 760 | if (cs > gpmc_cs_num) { | ||
| 761 | pr_err("%s: requested chip-select is disabled\n", __func__); | ||
| 762 | return -ENODEV; | ||
| 763 | } | ||
| 764 | size = gpmc_mem_align(size); | ||
| 765 | if (size > (1 << GPMC_SECTION_SHIFT)) | ||
| 766 | return -ENOMEM; | ||
| 767 | |||
| 768 | spin_lock(&gpmc_mem_lock); | ||
| 769 | if (gpmc_cs_reserved(cs)) { | ||
| 770 | r = -EBUSY; | ||
| 771 | goto out; | ||
| 772 | } | ||
| 773 | if (gpmc_cs_mem_enabled(cs)) | ||
| 774 | r = adjust_resource(res, res->start & ~(size - 1), size); | ||
| 775 | if (r < 0) | ||
| 776 | r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0, | ||
| 777 | size, NULL, NULL); | ||
| 778 | if (r < 0) | ||
| 779 | goto out; | ||
| 780 | |||
| 781 | /* Disable CS while changing base address and size mask */ | ||
| 782 | gpmc_cs_disable_mem(cs); | ||
| 783 | |||
| 784 | r = gpmc_cs_set_memconf(cs, res->start, resource_size(res)); | ||
| 785 | if (r < 0) { | ||
| 786 | release_resource(res); | ||
| 787 | goto out; | ||
| 788 | } | ||
| 789 | |||
| 790 | /* Enable CS */ | ||
| 791 | gpmc_cs_enable_mem(cs); | ||
| 792 | *base = res->start; | ||
| 793 | gpmc_cs_set_reserved(cs, 1); | ||
| 794 | out: | ||
| 795 | spin_unlock(&gpmc_mem_lock); | ||
| 796 | return r; | ||
| 797 | } | ||
| 798 | EXPORT_SYMBOL(gpmc_cs_request); | ||
| 799 | |||
| 800 | void gpmc_cs_free(int cs) | ||
| 801 | { | ||
| 802 | struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; | ||
| 803 | struct resource *res = &gpmc->mem; | ||
| 804 | |||
| 805 | spin_lock(&gpmc_mem_lock); | ||
| 806 | if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { | ||
| 807 | printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs); | ||
| 808 | BUG(); | ||
| 809 | spin_unlock(&gpmc_mem_lock); | ||
| 810 | return; | ||
| 811 | } | ||
| 812 | gpmc_cs_disable_mem(cs); | ||
| 813 | if (res->flags) | ||
| 814 | release_resource(res); | ||
| 815 | gpmc_cs_set_reserved(cs, 0); | ||
| 816 | spin_unlock(&gpmc_mem_lock); | ||
| 817 | } | ||
| 818 | EXPORT_SYMBOL(gpmc_cs_free); | ||
| 819 | |||
| 820 | /** | ||
| 821 | * gpmc_configure - write request to configure gpmc | ||
| 822 | * @cmd: command type | ||
| 823 | * @wval: value to write | ||
| 824 | * @return status of the operation | ||
| 825 | */ | ||
| 826 | int gpmc_configure(int cmd, int wval) | ||
| 827 | { | ||
| 828 | u32 regval; | ||
| 829 | |||
| 830 | switch (cmd) { | ||
| 831 | case GPMC_ENABLE_IRQ: | ||
| 832 | gpmc_write_reg(GPMC_IRQENABLE, wval); | ||
| 833 | break; | ||
| 834 | |||
| 835 | case GPMC_SET_IRQ_STATUS: | ||
| 836 | gpmc_write_reg(GPMC_IRQSTATUS, wval); | ||
| 837 | break; | ||
| 838 | |||
| 839 | case GPMC_CONFIG_WP: | ||
| 840 | regval = gpmc_read_reg(GPMC_CONFIG); | ||
| 841 | if (wval) | ||
| 842 | regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */ | ||
| 843 | else | ||
| 844 | regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */ | ||
| 845 | gpmc_write_reg(GPMC_CONFIG, regval); | ||
| 846 | break; | ||
| 847 | |||
| 848 | default: | ||
| 849 | pr_err("%s: command not supported\n", __func__); | ||
| 850 | return -EINVAL; | ||
| 851 | } | ||
| 852 | |||
| 853 | return 0; | ||
| 854 | } | ||
| 855 | EXPORT_SYMBOL(gpmc_configure); | ||
| 856 | |||
| 857 | void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs) | ||
| 858 | { | ||
| 859 | int i; | ||
| 860 | |||
| 861 | reg->gpmc_status = gpmc_base + GPMC_STATUS; | ||
| 862 | reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET + | ||
| 863 | GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs; | ||
| 864 | reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET + | ||
| 865 | GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs; | ||
| 866 | reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET + | ||
| 867 | GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs; | ||
| 868 | reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1; | ||
| 869 | reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2; | ||
| 870 | reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL; | ||
| 871 | reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS; | ||
| 872 | reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG; | ||
| 873 | reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL; | ||
| 874 | reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG; | ||
| 875 | reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT; | ||
| 876 | |||
| 877 | for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) { | ||
| 878 | reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 + | ||
| 879 | GPMC_BCH_SIZE * i; | ||
| 880 | reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 + | ||
| 881 | GPMC_BCH_SIZE * i; | ||
| 882 | reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 + | ||
| 883 | GPMC_BCH_SIZE * i; | ||
| 884 | reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 + | ||
| 885 | GPMC_BCH_SIZE * i; | ||
| 886 | reg->gpmc_bch_result4[i] = gpmc_base + GPMC_ECC_BCH_RESULT_4 + | ||
| 887 | i * GPMC_BCH_SIZE; | ||
| 888 | reg->gpmc_bch_result5[i] = gpmc_base + GPMC_ECC_BCH_RESULT_5 + | ||
| 889 | i * GPMC_BCH_SIZE; | ||
| 890 | reg->gpmc_bch_result6[i] = gpmc_base + GPMC_ECC_BCH_RESULT_6 + | ||
| 891 | i * GPMC_BCH_SIZE; | ||
| 892 | } | ||
| 893 | } | ||
| 894 | |||
| 895 | int gpmc_get_client_irq(unsigned irq_config) | ||
| 896 | { | ||
| 897 | int i; | ||
| 898 | |||
| 899 | if (hweight32(irq_config) > 1) | ||
| 900 | return 0; | ||
| 901 | |||
| 902 | for (i = 0; i < GPMC_NR_IRQ; i++) | ||
| 903 | if (gpmc_client_irq[i].bitmask & irq_config) | ||
| 904 | return gpmc_client_irq[i].irq; | ||
| 905 | |||
| 906 | return 0; | ||
| 907 | } | ||
| 908 | |||
| 909 | static int gpmc_irq_endis(unsigned irq, bool endis) | ||
| 910 | { | ||
| 911 | int i; | ||
| 912 | u32 regval; | ||
| 913 | |||
| 914 | for (i = 0; i < GPMC_NR_IRQ; i++) | ||
| 915 | if (irq == gpmc_client_irq[i].irq) { | ||
| 916 | regval = gpmc_read_reg(GPMC_IRQENABLE); | ||
| 917 | if (endis) | ||
| 918 | regval |= gpmc_client_irq[i].bitmask; | ||
| 919 | else | ||
| 920 | regval &= ~gpmc_client_irq[i].bitmask; | ||
| 921 | gpmc_write_reg(GPMC_IRQENABLE, regval); | ||
| 922 | break; | ||
| 923 | } | ||
| 924 | |||
| 925 | return 0; | ||
| 926 | } | ||
| 927 | |||
| 928 | static void gpmc_irq_disable(struct irq_data *p) | ||
| 929 | { | ||
| 930 | gpmc_irq_endis(p->irq, false); | ||
| 931 | } | ||
| 932 | |||
| 933 | static void gpmc_irq_enable(struct irq_data *p) | ||
| 934 | { | ||
| 935 | gpmc_irq_endis(p->irq, true); | ||
| 936 | } | ||
| 937 | |||
| 938 | static void gpmc_irq_noop(struct irq_data *data) { } | ||
| 939 | |||
| 940 | static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; } | ||
| 941 | |||
| 942 | static int gpmc_setup_irq(void) | ||
| 943 | { | ||
| 944 | int i; | ||
| 945 | u32 regval; | ||
| 946 | |||
| 947 | if (!gpmc_irq) | ||
| 948 | return -EINVAL; | ||
| 949 | |||
| 950 | gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0); | ||
| 951 | if (gpmc_irq_start < 0) { | ||
| 952 | pr_err("irq_alloc_descs failed\n"); | ||
| 953 | return gpmc_irq_start; | ||
| 954 | } | ||
| 955 | |||
| 956 | gpmc_irq_chip.name = "gpmc"; | ||
| 957 | gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret; | ||
| 958 | gpmc_irq_chip.irq_enable = gpmc_irq_enable; | ||
| 959 | gpmc_irq_chip.irq_disable = gpmc_irq_disable; | ||
| 960 | gpmc_irq_chip.irq_shutdown = gpmc_irq_noop; | ||
| 961 | gpmc_irq_chip.irq_ack = gpmc_irq_noop; | ||
| 962 | gpmc_irq_chip.irq_mask = gpmc_irq_noop; | ||
| 963 | gpmc_irq_chip.irq_unmask = gpmc_irq_noop; | ||
| 964 | |||
| 965 | gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE; | ||
| 966 | gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT; | ||
| 967 | |||
| 968 | for (i = 0; i < GPMC_NR_IRQ; i++) { | ||
| 969 | gpmc_client_irq[i].irq = gpmc_irq_start + i; | ||
| 970 | irq_set_chip_and_handler(gpmc_client_irq[i].irq, | ||
| 971 | &gpmc_irq_chip, handle_simple_irq); | ||
| 972 | set_irq_flags(gpmc_client_irq[i].irq, | ||
| 973 | IRQF_VALID | IRQF_NOAUTOEN); | ||
| 974 | } | ||
| 975 | |||
| 976 | /* Disable interrupts */ | ||
| 977 | gpmc_write_reg(GPMC_IRQENABLE, 0); | ||
| 978 | |||
| 979 | /* clear interrupts */ | ||
| 980 | regval = gpmc_read_reg(GPMC_IRQSTATUS); | ||
| 981 | gpmc_write_reg(GPMC_IRQSTATUS, regval); | ||
| 982 | |||
| 983 | return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL); | ||
| 984 | } | ||
| 985 | |||
| 986 | static int gpmc_free_irq(void) | ||
| 987 | { | ||
| 988 | int i; | ||
| 989 | |||
| 990 | if (gpmc_irq) | ||
| 991 | free_irq(gpmc_irq, NULL); | ||
| 992 | |||
| 993 | for (i = 0; i < GPMC_NR_IRQ; i++) { | ||
| 994 | irq_set_handler(gpmc_client_irq[i].irq, NULL); | ||
| 995 | irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip); | ||
| 996 | irq_modify_status(gpmc_client_irq[i].irq, 0, 0); | ||
| 997 | } | ||
| 998 | |||
| 999 | irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ); | ||
| 1000 | |||
| 1001 | return 0; | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | static void gpmc_mem_exit(void) | ||
| 1005 | { | ||
| 1006 | int cs; | ||
| 1007 | |||
| 1008 | for (cs = 0; cs < gpmc_cs_num; cs++) { | ||
| 1009 | if (!gpmc_cs_mem_enabled(cs)) | ||
| 1010 | continue; | ||
| 1011 | gpmc_cs_delete_mem(cs); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | } | ||
| 1015 | |||
| 1016 | static void gpmc_mem_init(void) | ||
| 1017 | { | ||
| 1018 | int cs; | ||
| 1019 | |||
| 1020 | /* | ||
| 1021 | * The first 1MB of GPMC address space is typically mapped to | ||
| 1022 | * the internal ROM. Never allocate the first page, to | ||
| 1023 | * facilitate bug detection; even if we didn't boot from ROM. | ||
| 1024 | */ | ||
| 1025 | gpmc_mem_root.start = SZ_1M; | ||
| 1026 | gpmc_mem_root.end = GPMC_MEM_END; | ||
| 1027 | |||
| 1028 | /* Reserve all regions that has been set up by bootloader */ | ||
| 1029 | for (cs = 0; cs < gpmc_cs_num; cs++) { | ||
| 1030 | u32 base, size; | ||
| 1031 | |||
| 1032 | if (!gpmc_cs_mem_enabled(cs)) | ||
| 1033 | continue; | ||
| 1034 | gpmc_cs_get_memconf(cs, &base, &size); | ||
| 1035 | if (gpmc_cs_insert_mem(cs, base, size)) { | ||
| 1036 | pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n", | ||
| 1037 | __func__, cs, base, base + size); | ||
| 1038 | gpmc_cs_disable_mem(cs); | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk) | ||
| 1044 | { | ||
| 1045 | u32 temp; | ||
| 1046 | int div; | ||
| 1047 | |||
| 1048 | div = gpmc_calc_divider(sync_clk); | ||
| 1049 | temp = gpmc_ps_to_ticks(time_ps); | ||
| 1050 | temp = (temp + div - 1) / div; | ||
| 1051 | return gpmc_ticks_to_ps(temp * div); | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | /* XXX: can the cycles be avoided ? */ | ||
| 1055 | static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t, | ||
| 1056 | struct gpmc_device_timings *dev_t, | ||
| 1057 | bool mux) | ||
| 1058 | { | ||
| 1059 | u32 temp; | ||
| 1060 | |||
| 1061 | /* adv_rd_off */ | ||
| 1062 | temp = dev_t->t_avdp_r; | ||
| 1063 | /* XXX: mux check required ? */ | ||
| 1064 | if (mux) { | ||
| 1065 | /* XXX: t_avdp not to be required for sync, only added for tusb | ||
| 1066 | * this indirectly necessitates requirement of t_avdp_r and | ||
| 1067 | * t_avdp_w instead of having a single t_avdp | ||
| 1068 | */ | ||
| 1069 | temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh); | ||
| 1070 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); | ||
| 1071 | } | ||
| 1072 | gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); | ||
| 1073 | |||
| 1074 | /* oe_on */ | ||
| 1075 | temp = dev_t->t_oeasu; /* XXX: remove this ? */ | ||
| 1076 | if (mux) { | ||
| 1077 | temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach); | ||
| 1078 | temp = max_t(u32, temp, gpmc_t->adv_rd_off + | ||
| 1079 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe)); | ||
| 1080 | } | ||
| 1081 | gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); | ||
| 1082 | |||
| 1083 | /* access */ | ||
| 1084 | /* XXX: any scope for improvement ?, by combining oe_on | ||
| 1085 | * and clk_activation, need to check whether | ||
| 1086 | * access = clk_activation + round to sync clk ? | ||
| 1087 | */ | ||
| 1088 | temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk); | ||
| 1089 | temp += gpmc_t->clk_activation; | ||
| 1090 | if (dev_t->cyc_oe) | ||
| 1091 | temp = max_t(u32, temp, gpmc_t->oe_on + | ||
| 1092 | gpmc_ticks_to_ps(dev_t->cyc_oe)); | ||
| 1093 | gpmc_t->access = gpmc_round_ps_to_ticks(temp); | ||
| 1094 | |||
| 1095 | gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); | ||
| 1096 | gpmc_t->cs_rd_off = gpmc_t->oe_off; | ||
| 1097 | |||
| 1098 | /* rd_cycle */ | ||
| 1099 | temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez); | ||
| 1100 | temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) + | ||
| 1101 | gpmc_t->access; | ||
| 1102 | /* XXX: barter t_ce_rdyz with t_cez_r ? */ | ||
| 1103 | if (dev_t->t_ce_rdyz) | ||
| 1104 | temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz); | ||
| 1105 | gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); | ||
| 1106 | |||
| 1107 | return 0; | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t, | ||
| 1111 | struct gpmc_device_timings *dev_t, | ||
| 1112 | bool mux) | ||
| 1113 | { | ||
| 1114 | u32 temp; | ||
| 1115 | |||
| 1116 | /* adv_wr_off */ | ||
| 1117 | temp = dev_t->t_avdp_w; | ||
| 1118 | if (mux) { | ||
| 1119 | temp = max_t(u32, temp, | ||
| 1120 | gpmc_t->clk_activation + dev_t->t_avdh); | ||
| 1121 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); | ||
| 1122 | } | ||
| 1123 | gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); | ||
| 1124 | |||
| 1125 | /* wr_data_mux_bus */ | ||
| 1126 | temp = max_t(u32, dev_t->t_weasu, | ||
| 1127 | gpmc_t->clk_activation + dev_t->t_rdyo); | ||
| 1128 | /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?, | ||
| 1129 | * and in that case remember to handle we_on properly | ||
| 1130 | */ | ||
| 1131 | if (mux) { | ||
| 1132 | temp = max_t(u32, temp, | ||
| 1133 | gpmc_t->adv_wr_off + dev_t->t_aavdh); | ||
| 1134 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + | ||
| 1135 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); | ||
| 1136 | } | ||
| 1137 | gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); | ||
| 1138 | |||
| 1139 | /* we_on */ | ||
| 1140 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) | ||
| 1141 | gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); | ||
| 1142 | else | ||
| 1143 | gpmc_t->we_on = gpmc_t->wr_data_mux_bus; | ||
| 1144 | |||
| 1145 | /* wr_access */ | ||
| 1146 | /* XXX: gpmc_capability check reqd ? , even if not, will not harm */ | ||
| 1147 | gpmc_t->wr_access = gpmc_t->access; | ||
| 1148 | |||
| 1149 | /* we_off */ | ||
| 1150 | temp = gpmc_t->we_on + dev_t->t_wpl; | ||
| 1151 | temp = max_t(u32, temp, | ||
| 1152 | gpmc_t->wr_access + gpmc_ticks_to_ps(1)); | ||
| 1153 | temp = max_t(u32, temp, | ||
| 1154 | gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl)); | ||
| 1155 | gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); | ||
| 1156 | |||
| 1157 | gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + | ||
| 1158 | dev_t->t_wph); | ||
| 1159 | |||
| 1160 | /* wr_cycle */ | ||
| 1161 | temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk); | ||
| 1162 | temp += gpmc_t->wr_access; | ||
| 1163 | /* XXX: barter t_ce_rdyz with t_cez_w ? */ | ||
| 1164 | if (dev_t->t_ce_rdyz) | ||
| 1165 | temp = max_t(u32, temp, | ||
| 1166 | gpmc_t->cs_wr_off + dev_t->t_ce_rdyz); | ||
| 1167 | gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); | ||
| 1168 | |||
| 1169 | return 0; | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t, | ||
| 1173 | struct gpmc_device_timings *dev_t, | ||
| 1174 | bool mux) | ||
| 1175 | { | ||
| 1176 | u32 temp; | ||
| 1177 | |||
| 1178 | /* adv_rd_off */ | ||
| 1179 | temp = dev_t->t_avdp_r; | ||
| 1180 | if (mux) | ||
| 1181 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); | ||
| 1182 | gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); | ||
| 1183 | |||
| 1184 | /* oe_on */ | ||
| 1185 | temp = dev_t->t_oeasu; | ||
| 1186 | if (mux) | ||
| 1187 | temp = max_t(u32, temp, | ||
| 1188 | gpmc_t->adv_rd_off + dev_t->t_aavdh); | ||
| 1189 | gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); | ||
| 1190 | |||
| 1191 | /* access */ | ||
| 1192 | temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */ | ||
| 1193 | gpmc_t->oe_on + dev_t->t_oe); | ||
| 1194 | temp = max_t(u32, temp, | ||
| 1195 | gpmc_t->cs_on + dev_t->t_ce); | ||
| 1196 | temp = max_t(u32, temp, | ||
| 1197 | gpmc_t->adv_on + dev_t->t_aa); | ||
| 1198 | gpmc_t->access = gpmc_round_ps_to_ticks(temp); | ||
| 1199 | |||
| 1200 | gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); | ||
| 1201 | gpmc_t->cs_rd_off = gpmc_t->oe_off; | ||
| 1202 | |||
| 1203 | /* rd_cycle */ | ||
| 1204 | temp = max_t(u32, dev_t->t_rd_cycle, | ||
| 1205 | gpmc_t->cs_rd_off + dev_t->t_cez_r); | ||
| 1206 | temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez); | ||
| 1207 | gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); | ||
| 1208 | |||
| 1209 | return 0; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t, | ||
| 1213 | struct gpmc_device_timings *dev_t, | ||
| 1214 | bool mux) | ||
| 1215 | { | ||
| 1216 | u32 temp; | ||
| 1217 | |||
| 1218 | /* adv_wr_off */ | ||
| 1219 | temp = dev_t->t_avdp_w; | ||
| 1220 | if (mux) | ||
| 1221 | temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); | ||
| 1222 | gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); | ||
| 1223 | |||
| 1224 | /* wr_data_mux_bus */ | ||
| 1225 | temp = dev_t->t_weasu; | ||
| 1226 | if (mux) { | ||
| 1227 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh); | ||
| 1228 | temp = max_t(u32, temp, gpmc_t->adv_wr_off + | ||
| 1229 | gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); | ||
| 1230 | } | ||
| 1231 | gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); | ||
| 1232 | |||
| 1233 | /* we_on */ | ||
| 1234 | if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) | ||
| 1235 | gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); | ||
| 1236 | else | ||
| 1237 | gpmc_t->we_on = gpmc_t->wr_data_mux_bus; | ||
| 1238 | |||
| 1239 | /* we_off */ | ||
| 1240 | temp = gpmc_t->we_on + dev_t->t_wpl; | ||
| 1241 | gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); | ||
| 1242 | |||
| 1243 | gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + | ||
| 1244 | dev_t->t_wph); | ||
| 1245 | |||
| 1246 | /* wr_cycle */ | ||
| 1247 | temp = max_t(u32, dev_t->t_wr_cycle, | ||
| 1248 | gpmc_t->cs_wr_off + dev_t->t_cez_w); | ||
| 1249 | gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); | ||
| 1250 | |||
| 1251 | return 0; | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t, | ||
| 1255 | struct gpmc_device_timings *dev_t) | ||
| 1256 | { | ||
| 1257 | u32 temp; | ||
| 1258 | |||
| 1259 | gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) * | ||
| 1260 | gpmc_get_fclk_period(); | ||
| 1261 | |||
| 1262 | gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk( | ||
| 1263 | dev_t->t_bacc, | ||
| 1264 | gpmc_t->sync_clk); | ||
| 1265 | |||
| 1266 | temp = max_t(u32, dev_t->t_ces, dev_t->t_avds); | ||
| 1267 | gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp); | ||
| 1268 | |||
| 1269 | if (gpmc_calc_divider(gpmc_t->sync_clk) != 1) | ||
| 1270 | return 0; | ||
| 1271 | |||
| 1272 | if (dev_t->ce_xdelay) | ||
| 1273 | gpmc_t->bool_timings.cs_extra_delay = true; | ||
| 1274 | if (dev_t->avd_xdelay) | ||
| 1275 | gpmc_t->bool_timings.adv_extra_delay = true; | ||
| 1276 | if (dev_t->oe_xdelay) | ||
| 1277 | gpmc_t->bool_timings.oe_extra_delay = true; | ||
| 1278 | if (dev_t->we_xdelay) | ||
| 1279 | gpmc_t->bool_timings.we_extra_delay = true; | ||
| 1280 | |||
| 1281 | return 0; | ||
| 1282 | } | ||
| 1283 | |||
| 1284 | static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t, | ||
| 1285 | struct gpmc_device_timings *dev_t, | ||
| 1286 | bool sync) | ||
| 1287 | { | ||
| 1288 | u32 temp; | ||
| 1289 | |||
| 1290 | /* cs_on */ | ||
| 1291 | gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu); | ||
| 1292 | |||
| 1293 | /* adv_on */ | ||
| 1294 | temp = dev_t->t_avdasu; | ||
| 1295 | if (dev_t->t_ce_avd) | ||
| 1296 | temp = max_t(u32, temp, | ||
| 1297 | gpmc_t->cs_on + dev_t->t_ce_avd); | ||
| 1298 | gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp); | ||
| 1299 | |||
| 1300 | if (sync) | ||
| 1301 | gpmc_calc_sync_common_timings(gpmc_t, dev_t); | ||
| 1302 | |||
| 1303 | return 0; | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | /* TODO: remove this function once all peripherals are confirmed to | ||
| 1307 | * work with generic timing. Simultaneously gpmc_cs_set_timings() | ||
| 1308 | * has to be modified to handle timings in ps instead of ns | ||
| 1309 | */ | ||
| 1310 | static void gpmc_convert_ps_to_ns(struct gpmc_timings *t) | ||
| 1311 | { | ||
| 1312 | t->cs_on /= 1000; | ||
| 1313 | t->cs_rd_off /= 1000; | ||
| 1314 | t->cs_wr_off /= 1000; | ||
| 1315 | t->adv_on /= 1000; | ||
| 1316 | t->adv_rd_off /= 1000; | ||
| 1317 | t->adv_wr_off /= 1000; | ||
| 1318 | t->we_on /= 1000; | ||
| 1319 | t->we_off /= 1000; | ||
| 1320 | t->oe_on /= 1000; | ||
| 1321 | t->oe_off /= 1000; | ||
| 1322 | t->page_burst_access /= 1000; | ||
| 1323 | t->access /= 1000; | ||
| 1324 | t->rd_cycle /= 1000; | ||
| 1325 | t->wr_cycle /= 1000; | ||
| 1326 | t->bus_turnaround /= 1000; | ||
| 1327 | t->cycle2cycle_delay /= 1000; | ||
| 1328 | t->wait_monitoring /= 1000; | ||
| 1329 | t->clk_activation /= 1000; | ||
| 1330 | t->wr_access /= 1000; | ||
| 1331 | t->wr_data_mux_bus /= 1000; | ||
| 1332 | } | ||
| 1333 | |||
| 1334 | int gpmc_calc_timings(struct gpmc_timings *gpmc_t, | ||
| 1335 | struct gpmc_settings *gpmc_s, | ||
| 1336 | struct gpmc_device_timings *dev_t) | ||
| 1337 | { | ||
| 1338 | bool mux = false, sync = false; | ||
| 1339 | |||
| 1340 | if (gpmc_s) { | ||
| 1341 | mux = gpmc_s->mux_add_data ? true : false; | ||
| 1342 | sync = (gpmc_s->sync_read || gpmc_s->sync_write); | ||
| 1343 | } | ||
| 1344 | |||
| 1345 | memset(gpmc_t, 0, sizeof(*gpmc_t)); | ||
| 1346 | |||
| 1347 | gpmc_calc_common_timings(gpmc_t, dev_t, sync); | ||
| 1348 | |||
| 1349 | if (gpmc_s && gpmc_s->sync_read) | ||
| 1350 | gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux); | ||
| 1351 | else | ||
| 1352 | gpmc_calc_async_read_timings(gpmc_t, dev_t, mux); | ||
| 1353 | |||
| 1354 | if (gpmc_s && gpmc_s->sync_write) | ||
| 1355 | gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux); | ||
| 1356 | else | ||
| 1357 | gpmc_calc_async_write_timings(gpmc_t, dev_t, mux); | ||
| 1358 | |||
| 1359 | /* TODO: remove, see function definition */ | ||
| 1360 | gpmc_convert_ps_to_ns(gpmc_t); | ||
| 1361 | |||
| 1362 | return 0; | ||
| 1363 | } | ||
| 1364 | |||
| 1365 | /** | ||
| 1366 | * gpmc_cs_program_settings - programs non-timing related settings | ||
| 1367 | * @cs: GPMC chip-select to program | ||
| 1368 | * @p: pointer to GPMC settings structure | ||
| 1369 | * | ||
| 1370 | * Programs non-timing related settings for a GPMC chip-select, such as | ||
| 1371 | * bus-width, burst configuration, etc. Function should be called once | ||
| 1372 | * for each chip-select that is being used and must be called before | ||
| 1373 | * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1 | ||
| 1374 | * register will be initialised to zero by this function. Returns 0 on | ||
| 1375 | * success and appropriate negative error code on failure. | ||
| 1376 | */ | ||
| 1377 | int gpmc_cs_program_settings(int cs, struct gpmc_settings *p) | ||
| 1378 | { | ||
| 1379 | u32 config1; | ||
| 1380 | |||
| 1381 | if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) { | ||
| 1382 | pr_err("%s: invalid width %d!", __func__, p->device_width); | ||
| 1383 | return -EINVAL; | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | /* Address-data multiplexing not supported for NAND devices */ | ||
| 1387 | if (p->device_nand && p->mux_add_data) { | ||
| 1388 | pr_err("%s: invalid configuration!\n", __func__); | ||
| 1389 | return -EINVAL; | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | if ((p->mux_add_data > GPMC_MUX_AD) || | ||
| 1393 | ((p->mux_add_data == GPMC_MUX_AAD) && | ||
| 1394 | !(gpmc_capability & GPMC_HAS_MUX_AAD))) { | ||
| 1395 | pr_err("%s: invalid multiplex configuration!\n", __func__); | ||
| 1396 | return -EINVAL; | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | /* Page/burst mode supports lengths of 4, 8 and 16 bytes */ | ||
| 1400 | if (p->burst_read || p->burst_write) { | ||
| 1401 | switch (p->burst_len) { | ||
| 1402 | case GPMC_BURST_4: | ||
| 1403 | case GPMC_BURST_8: | ||
| 1404 | case GPMC_BURST_16: | ||
| 1405 | break; | ||
| 1406 | default: | ||
| 1407 | pr_err("%s: invalid page/burst-length (%d)\n", | ||
| 1408 | __func__, p->burst_len); | ||
| 1409 | return -EINVAL; | ||
| 1410 | } | ||
| 1411 | } | ||
| 1412 | |||
| 1413 | if (p->wait_pin > gpmc_nr_waitpins) { | ||
| 1414 | pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin); | ||
| 1415 | return -EINVAL; | ||
| 1416 | } | ||
| 1417 | |||
| 1418 | config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1)); | ||
| 1419 | |||
| 1420 | if (p->sync_read) | ||
| 1421 | config1 |= GPMC_CONFIG1_READTYPE_SYNC; | ||
| 1422 | if (p->sync_write) | ||
| 1423 | config1 |= GPMC_CONFIG1_WRITETYPE_SYNC; | ||
| 1424 | if (p->wait_on_read) | ||
| 1425 | config1 |= GPMC_CONFIG1_WAIT_READ_MON; | ||
| 1426 | if (p->wait_on_write) | ||
| 1427 | config1 |= GPMC_CONFIG1_WAIT_WRITE_MON; | ||
| 1428 | if (p->wait_on_read || p->wait_on_write) | ||
| 1429 | config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin); | ||
| 1430 | if (p->device_nand) | ||
| 1431 | config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND); | ||
| 1432 | if (p->mux_add_data) | ||
| 1433 | config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data); | ||
| 1434 | if (p->burst_read) | ||
| 1435 | config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP; | ||
| 1436 | if (p->burst_write) | ||
| 1437 | config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP; | ||
| 1438 | if (p->burst_read || p->burst_write) { | ||
| 1439 | config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3); | ||
| 1440 | config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0; | ||
| 1441 | } | ||
| 1442 | |||
| 1443 | gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1); | ||
| 1444 | |||
| 1445 | return 0; | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | #ifdef CONFIG_OF | ||
| 1449 | static const struct of_device_id gpmc_dt_ids[] = { | ||
| 1450 | { .compatible = "ti,omap2420-gpmc" }, | ||
| 1451 | { .compatible = "ti,omap2430-gpmc" }, | ||
| 1452 | { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */ | ||
| 1453 | { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */ | ||
| 1454 | { .compatible = "ti,am3352-gpmc" }, /* am335x devices */ | ||
| 1455 | { } | ||
| 1456 | }; | ||
| 1457 | MODULE_DEVICE_TABLE(of, gpmc_dt_ids); | ||
| 1458 | |||
| 1459 | /** | ||
| 1460 | * gpmc_read_settings_dt - read gpmc settings from device-tree | ||
| 1461 | * @np: pointer to device-tree node for a gpmc child device | ||
| 1462 | * @p: pointer to gpmc settings structure | ||
| 1463 | * | ||
| 1464 | * Reads the GPMC settings for a GPMC child device from device-tree and | ||
| 1465 | * stores them in the GPMC settings structure passed. The GPMC settings | ||
| 1466 | * structure is initialised to zero by this function and so any | ||
| 1467 | * previously stored settings will be cleared. | ||
| 1468 | */ | ||
| 1469 | void gpmc_read_settings_dt(struct device_node *np, struct gpmc_settings *p) | ||
| 1470 | { | ||
| 1471 | memset(p, 0, sizeof(struct gpmc_settings)); | ||
| 1472 | |||
| 1473 | p->sync_read = of_property_read_bool(np, "gpmc,sync-read"); | ||
| 1474 | p->sync_write = of_property_read_bool(np, "gpmc,sync-write"); | ||
| 1475 | of_property_read_u32(np, "gpmc,device-width", &p->device_width); | ||
| 1476 | of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data); | ||
| 1477 | |||
| 1478 | if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) { | ||
| 1479 | p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap"); | ||
| 1480 | p->burst_read = of_property_read_bool(np, "gpmc,burst-read"); | ||
| 1481 | p->burst_write = of_property_read_bool(np, "gpmc,burst-write"); | ||
| 1482 | if (!p->burst_read && !p->burst_write) | ||
| 1483 | pr_warn("%s: page/burst-length set but not used!\n", | ||
| 1484 | __func__); | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) { | ||
| 1488 | p->wait_on_read = of_property_read_bool(np, | ||
| 1489 | "gpmc,wait-on-read"); | ||
| 1490 | p->wait_on_write = of_property_read_bool(np, | ||
| 1491 | "gpmc,wait-on-write"); | ||
| 1492 | if (!p->wait_on_read && !p->wait_on_write) | ||
| 1493 | pr_debug("%s: rd/wr wait monitoring not enabled!\n", | ||
| 1494 | __func__); | ||
| 1495 | } | ||
| 1496 | } | ||
| 1497 | |||
| 1498 | static void __maybe_unused gpmc_read_timings_dt(struct device_node *np, | ||
| 1499 | struct gpmc_timings *gpmc_t) | ||
| 1500 | { | ||
| 1501 | struct gpmc_bool_timings *p; | ||
| 1502 | |||
| 1503 | if (!np || !gpmc_t) | ||
| 1504 | return; | ||
| 1505 | |||
| 1506 | memset(gpmc_t, 0, sizeof(*gpmc_t)); | ||
| 1507 | |||
| 1508 | /* minimum clock period for syncronous mode */ | ||
| 1509 | of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk); | ||
| 1510 | |||
| 1511 | /* chip select timtings */ | ||
| 1512 | of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on); | ||
| 1513 | of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off); | ||
| 1514 | of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off); | ||
| 1515 | |||
| 1516 | /* ADV signal timings */ | ||
| 1517 | of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on); | ||
| 1518 | of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off); | ||
| 1519 | of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off); | ||
| 1520 | |||
| 1521 | /* WE signal timings */ | ||
| 1522 | of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on); | ||
| 1523 | of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off); | ||
| 1524 | |||
| 1525 | /* OE signal timings */ | ||
| 1526 | of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on); | ||
| 1527 | of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off); | ||
| 1528 | |||
| 1529 | /* access and cycle timings */ | ||
| 1530 | of_property_read_u32(np, "gpmc,page-burst-access-ns", | ||
| 1531 | &gpmc_t->page_burst_access); | ||
| 1532 | of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access); | ||
| 1533 | of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle); | ||
| 1534 | of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle); | ||
| 1535 | of_property_read_u32(np, "gpmc,bus-turnaround-ns", | ||
| 1536 | &gpmc_t->bus_turnaround); | ||
| 1537 | of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns", | ||
| 1538 | &gpmc_t->cycle2cycle_delay); | ||
| 1539 | of_property_read_u32(np, "gpmc,wait-monitoring-ns", | ||
| 1540 | &gpmc_t->wait_monitoring); | ||
| 1541 | of_property_read_u32(np, "gpmc,clk-activation-ns", | ||
| 1542 | &gpmc_t->clk_activation); | ||
| 1543 | |||
| 1544 | /* only applicable to OMAP3+ */ | ||
| 1545 | of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access); | ||
| 1546 | of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns", | ||
| 1547 | &gpmc_t->wr_data_mux_bus); | ||
| 1548 | |||
| 1549 | /* bool timing parameters */ | ||
| 1550 | p = &gpmc_t->bool_timings; | ||
| 1551 | |||
| 1552 | p->cycle2cyclediffcsen = | ||
| 1553 | of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen"); | ||
| 1554 | p->cycle2cyclesamecsen = | ||
| 1555 | of_property_read_bool(np, "gpmc,cycle2cycle-samecsen"); | ||
| 1556 | p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay"); | ||
| 1557 | p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay"); | ||
| 1558 | p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay"); | ||
| 1559 | p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay"); | ||
| 1560 | p->time_para_granularity = | ||
| 1561 | of_property_read_bool(np, "gpmc,time-para-granularity"); | ||
| 1562 | } | ||
| 1563 | |||
| 1564 | #if IS_ENABLED(CONFIG_MTD_NAND) | ||
| 1565 | |||
| 1566 | static const char * const nand_xfer_types[] = { | ||
| 1567 | [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled", | ||
| 1568 | [NAND_OMAP_POLLED] = "polled", | ||
| 1569 | [NAND_OMAP_PREFETCH_DMA] = "prefetch-dma", | ||
| 1570 | [NAND_OMAP_PREFETCH_IRQ] = "prefetch-irq", | ||
| 1571 | }; | ||
| 1572 | |||
| 1573 | static int gpmc_probe_nand_child(struct platform_device *pdev, | ||
| 1574 | struct device_node *child) | ||
| 1575 | { | ||
| 1576 | u32 val; | ||
| 1577 | const char *s; | ||
| 1578 | struct gpmc_timings gpmc_t; | ||
| 1579 | struct omap_nand_platform_data *gpmc_nand_data; | ||
| 1580 | |||
| 1581 | if (of_property_read_u32(child, "reg", &val) < 0) { | ||
| 1582 | dev_err(&pdev->dev, "%s has no 'reg' property\n", | ||
| 1583 | child->full_name); | ||
| 1584 | return -ENODEV; | ||
| 1585 | } | ||
| 1586 | |||
| 1587 | gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data), | ||
| 1588 | GFP_KERNEL); | ||
| 1589 | if (!gpmc_nand_data) | ||
| 1590 | return -ENOMEM; | ||
| 1591 | |||
| 1592 | gpmc_nand_data->cs = val; | ||
| 1593 | gpmc_nand_data->of_node = child; | ||
| 1594 | |||
| 1595 | /* Detect availability of ELM module */ | ||
| 1596 | gpmc_nand_data->elm_of_node = of_parse_phandle(child, "ti,elm-id", 0); | ||
| 1597 | if (gpmc_nand_data->elm_of_node == NULL) | ||
| 1598 | gpmc_nand_data->elm_of_node = | ||
| 1599 | of_parse_phandle(child, "elm_id", 0); | ||
| 1600 | if (gpmc_nand_data->elm_of_node == NULL) | ||
| 1601 | pr_warn("%s: ti,elm-id property not found\n", __func__); | ||
| 1602 | |||
| 1603 | /* select ecc-scheme for NAND */ | ||
| 1604 | if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) { | ||
| 1605 | pr_err("%s: ti,nand-ecc-opt not found\n", __func__); | ||
| 1606 | return -ENODEV; | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | if (!strcmp(s, "sw")) | ||
| 1610 | gpmc_nand_data->ecc_opt = OMAP_ECC_HAM1_CODE_SW; | ||
| 1611 | else if (!strcmp(s, "ham1") || | ||
| 1612 | !strcmp(s, "hw") || !strcmp(s, "hw-romcode")) | ||
| 1613 | gpmc_nand_data->ecc_opt = | ||
| 1614 | OMAP_ECC_HAM1_CODE_HW; | ||
| 1615 | else if (!strcmp(s, "bch4")) | ||
| 1616 | if (gpmc_nand_data->elm_of_node) | ||
| 1617 | gpmc_nand_data->ecc_opt = | ||
| 1618 | OMAP_ECC_BCH4_CODE_HW; | ||
| 1619 | else | ||
| 1620 | gpmc_nand_data->ecc_opt = | ||
| 1621 | OMAP_ECC_BCH4_CODE_HW_DETECTION_SW; | ||
| 1622 | else if (!strcmp(s, "bch8")) | ||
| 1623 | if (gpmc_nand_data->elm_of_node) | ||
| 1624 | gpmc_nand_data->ecc_opt = | ||
| 1625 | OMAP_ECC_BCH8_CODE_HW; | ||
| 1626 | else | ||
| 1627 | gpmc_nand_data->ecc_opt = | ||
| 1628 | OMAP_ECC_BCH8_CODE_HW_DETECTION_SW; | ||
| 1629 | else if (!strcmp(s, "bch16")) | ||
| 1630 | if (gpmc_nand_data->elm_of_node) | ||
| 1631 | gpmc_nand_data->ecc_opt = | ||
| 1632 | OMAP_ECC_BCH16_CODE_HW; | ||
| 1633 | else | ||
| 1634 | pr_err("%s: BCH16 requires ELM support\n", __func__); | ||
| 1635 | else | ||
| 1636 | pr_err("%s: ti,nand-ecc-opt invalid value\n", __func__); | ||
| 1637 | |||
| 1638 | /* select data transfer mode for NAND controller */ | ||
| 1639 | if (!of_property_read_string(child, "ti,nand-xfer-type", &s)) | ||
| 1640 | for (val = 0; val < ARRAY_SIZE(nand_xfer_types); val++) | ||
| 1641 | if (!strcasecmp(s, nand_xfer_types[val])) { | ||
| 1642 | gpmc_nand_data->xfer_type = val; | ||
| 1643 | break; | ||
| 1644 | } | ||
| 1645 | |||
| 1646 | gpmc_nand_data->flash_bbt = of_get_nand_on_flash_bbt(child); | ||
| 1647 | |||
| 1648 | val = of_get_nand_bus_width(child); | ||
| 1649 | if (val == 16) | ||
| 1650 | gpmc_nand_data->devsize = NAND_BUSWIDTH_16; | ||
| 1651 | |||
| 1652 | gpmc_read_timings_dt(child, &gpmc_t); | ||
| 1653 | gpmc_nand_init(gpmc_nand_data, &gpmc_t); | ||
| 1654 | |||
| 1655 | return 0; | ||
| 1656 | } | ||
| 1657 | #else | ||
| 1658 | static int gpmc_probe_nand_child(struct platform_device *pdev, | ||
| 1659 | struct device_node *child) | ||
| 1660 | { | ||
| 1661 | return 0; | ||
| 1662 | } | ||
| 1663 | #endif | ||
| 1664 | |||
| 1665 | #if IS_ENABLED(CONFIG_MTD_ONENAND) | ||
| 1666 | static int gpmc_probe_onenand_child(struct platform_device *pdev, | ||
| 1667 | struct device_node *child) | ||
| 1668 | { | ||
| 1669 | u32 val; | ||
| 1670 | struct omap_onenand_platform_data *gpmc_onenand_data; | ||
| 1671 | |||
| 1672 | if (of_property_read_u32(child, "reg", &val) < 0) { | ||
| 1673 | dev_err(&pdev->dev, "%s has no 'reg' property\n", | ||
| 1674 | child->full_name); | ||
| 1675 | return -ENODEV; | ||
| 1676 | } | ||
| 1677 | |||
| 1678 | gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data), | ||
| 1679 | GFP_KERNEL); | ||
| 1680 | if (!gpmc_onenand_data) | ||
| 1681 | return -ENOMEM; | ||
| 1682 | |||
| 1683 | gpmc_onenand_data->cs = val; | ||
| 1684 | gpmc_onenand_data->of_node = child; | ||
| 1685 | gpmc_onenand_data->dma_channel = -1; | ||
| 1686 | |||
| 1687 | if (!of_property_read_u32(child, "dma-channel", &val)) | ||
| 1688 | gpmc_onenand_data->dma_channel = val; | ||
| 1689 | |||
| 1690 | gpmc_onenand_init(gpmc_onenand_data); | ||
| 1691 | |||
| 1692 | return 0; | ||
| 1693 | } | ||
| 1694 | #else | ||
| 1695 | static int gpmc_probe_onenand_child(struct platform_device *pdev, | ||
| 1696 | struct device_node *child) | ||
| 1697 | { | ||
| 1698 | return 0; | ||
| 1699 | } | ||
| 1700 | #endif | ||
| 1701 | |||
| 1702 | /** | ||
| 1703 | * gpmc_probe_generic_child - configures the gpmc for a child device | ||
| 1704 | * @pdev: pointer to gpmc platform device | ||
| 1705 | * @child: pointer to device-tree node for child device | ||
| 1706 | * | ||
| 1707 | * Allocates and configures a GPMC chip-select for a child device. | ||
| 1708 | * Returns 0 on success and appropriate negative error code on failure. | ||
| 1709 | */ | ||
| 1710 | static int gpmc_probe_generic_child(struct platform_device *pdev, | ||
| 1711 | struct device_node *child) | ||
| 1712 | { | ||
| 1713 | struct gpmc_settings gpmc_s; | ||
| 1714 | struct gpmc_timings gpmc_t; | ||
| 1715 | struct resource res; | ||
| 1716 | unsigned long base; | ||
| 1717 | const char *name; | ||
| 1718 | int ret, cs; | ||
| 1719 | u32 val; | ||
| 1720 | |||
| 1721 | if (of_property_read_u32(child, "reg", &cs) < 0) { | ||
| 1722 | dev_err(&pdev->dev, "%s has no 'reg' property\n", | ||
| 1723 | child->full_name); | ||
| 1724 | return -ENODEV; | ||
| 1725 | } | ||
| 1726 | |||
| 1727 | if (of_address_to_resource(child, 0, &res) < 0) { | ||
| 1728 | dev_err(&pdev->dev, "%s has malformed 'reg' property\n", | ||
| 1729 | child->full_name); | ||
| 1730 | return -ENODEV; | ||
| 1731 | } | ||
| 1732 | |||
| 1733 | /* | ||
| 1734 | * Check if we have multiple instances of the same device | ||
| 1735 | * on a single chip select. If so, use the already initialized | ||
| 1736 | * timings. | ||
| 1737 | */ | ||
| 1738 | name = gpmc_cs_get_name(cs); | ||
| 1739 | if (name && child->name && of_node_cmp(child->name, name) == 0) | ||
| 1740 | goto no_timings; | ||
| 1741 | |||
| 1742 | ret = gpmc_cs_request(cs, resource_size(&res), &base); | ||
| 1743 | if (ret < 0) { | ||
| 1744 | dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs); | ||
| 1745 | return ret; | ||
| 1746 | } | ||
| 1747 | gpmc_cs_set_name(cs, child->name); | ||
| 1748 | |||
| 1749 | gpmc_read_settings_dt(child, &gpmc_s); | ||
| 1750 | gpmc_read_timings_dt(child, &gpmc_t); | ||
| 1751 | |||
| 1752 | /* | ||
| 1753 | * For some GPMC devices we still need to rely on the bootloader | ||
| 1754 | * timings because the devices can be connected via FPGA. | ||
| 1755 | * REVISIT: Add timing support from slls644g.pdf. | ||
| 1756 | */ | ||
| 1757 | if (!gpmc_t.cs_rd_off) { | ||
| 1758 | WARN(1, "enable GPMC debug to configure .dts timings for CS%i\n", | ||
| 1759 | cs); | ||
| 1760 | gpmc_cs_show_timings(cs, | ||
| 1761 | "please add GPMC bootloader timings to .dts"); | ||
| 1762 | goto no_timings; | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | /* CS must be disabled while making changes to gpmc configuration */ | ||
| 1766 | gpmc_cs_disable_mem(cs); | ||
| 1767 | |||
| 1768 | /* | ||
| 1769 | * FIXME: gpmc_cs_request() will map the CS to an arbitary | ||
| 1770 | * location in the gpmc address space. When booting with | ||
| 1771 | * device-tree we want the NOR flash to be mapped to the | ||
| 1772 | * location specified in the device-tree blob. So remap the | ||
| 1773 | * CS to this location. Once DT migration is complete should | ||
| 1774 | * just make gpmc_cs_request() map a specific address. | ||
| 1775 | */ | ||
| 1776 | ret = gpmc_cs_remap(cs, res.start); | ||
| 1777 | if (ret < 0) { | ||
| 1778 | dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n", | ||
| 1779 | cs, &res.start); | ||
| 1780 | goto err; | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width); | ||
| 1784 | if (ret < 0) | ||
| 1785 | goto err; | ||
| 1786 | |||
| 1787 | ret = gpmc_cs_program_settings(cs, &gpmc_s); | ||
| 1788 | if (ret < 0) | ||
| 1789 | goto err; | ||
| 1790 | |||
| 1791 | ret = gpmc_cs_set_timings(cs, &gpmc_t); | ||
| 1792 | if (ret) { | ||
| 1793 | dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n", | ||
| 1794 | child->name); | ||
| 1795 | goto err; | ||
| 1796 | } | ||
| 1797 | |||
| 1798 | /* Clear limited address i.e. enable A26-A11 */ | ||
| 1799 | val = gpmc_read_reg(GPMC_CONFIG); | ||
| 1800 | val &= ~GPMC_CONFIG_LIMITEDADDRESS; | ||
| 1801 | gpmc_write_reg(GPMC_CONFIG, val); | ||
| 1802 | |||
| 1803 | /* Enable CS region */ | ||
| 1804 | gpmc_cs_enable_mem(cs); | ||
| 1805 | |||
| 1806 | no_timings: | ||
| 1807 | if (of_platform_device_create(child, NULL, &pdev->dev)) | ||
| 1808 | return 0; | ||
| 1809 | |||
| 1810 | dev_err(&pdev->dev, "failed to create gpmc child %s\n", child->name); | ||
| 1811 | ret = -ENODEV; | ||
| 1812 | |||
| 1813 | err: | ||
| 1814 | gpmc_cs_free(cs); | ||
| 1815 | |||
| 1816 | return ret; | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | static int gpmc_probe_dt(struct platform_device *pdev) | ||
| 1820 | { | ||
| 1821 | int ret; | ||
| 1822 | struct device_node *child; | ||
| 1823 | const struct of_device_id *of_id = | ||
| 1824 | of_match_device(gpmc_dt_ids, &pdev->dev); | ||
| 1825 | |||
| 1826 | if (!of_id) | ||
| 1827 | return 0; | ||
| 1828 | |||
| 1829 | ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs", | ||
| 1830 | &gpmc_cs_num); | ||
| 1831 | if (ret < 0) { | ||
| 1832 | pr_err("%s: number of chip-selects not defined\n", __func__); | ||
| 1833 | return ret; | ||
| 1834 | } else if (gpmc_cs_num < 1) { | ||
| 1835 | pr_err("%s: all chip-selects are disabled\n", __func__); | ||
| 1836 | return -EINVAL; | ||
| 1837 | } else if (gpmc_cs_num > GPMC_CS_NUM) { | ||
| 1838 | pr_err("%s: number of supported chip-selects cannot be > %d\n", | ||
| 1839 | __func__, GPMC_CS_NUM); | ||
| 1840 | return -EINVAL; | ||
| 1841 | } | ||
| 1842 | |||
| 1843 | ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins", | ||
| 1844 | &gpmc_nr_waitpins); | ||
| 1845 | if (ret < 0) { | ||
| 1846 | pr_err("%s: number of wait pins not found!\n", __func__); | ||
| 1847 | return ret; | ||
| 1848 | } | ||
| 1849 | |||
| 1850 | for_each_available_child_of_node(pdev->dev.of_node, child) { | ||
| 1851 | |||
| 1852 | if (!child->name) | ||
| 1853 | continue; | ||
| 1854 | |||
| 1855 | if (of_node_cmp(child->name, "nand") == 0) | ||
| 1856 | ret = gpmc_probe_nand_child(pdev, child); | ||
| 1857 | else if (of_node_cmp(child->name, "onenand") == 0) | ||
| 1858 | ret = gpmc_probe_onenand_child(pdev, child); | ||
| 1859 | else if (of_node_cmp(child->name, "ethernet") == 0 || | ||
| 1860 | of_node_cmp(child->name, "nor") == 0 || | ||
| 1861 | of_node_cmp(child->name, "uart") == 0) | ||
| 1862 | ret = gpmc_probe_generic_child(pdev, child); | ||
| 1863 | |||
| 1864 | if (WARN(ret < 0, "%s: probing gpmc child %s failed\n", | ||
| 1865 | __func__, child->full_name)) | ||
| 1866 | of_node_put(child); | ||
| 1867 | } | ||
| 1868 | |||
| 1869 | return 0; | ||
| 1870 | } | ||
| 1871 | #else | ||
| 1872 | static int gpmc_probe_dt(struct platform_device *pdev) | ||
| 1873 | { | ||
| 1874 | return 0; | ||
| 1875 | } | ||
| 1876 | #endif | ||
| 1877 | |||
| 1878 | static int gpmc_probe(struct platform_device *pdev) | ||
| 1879 | { | ||
| 1880 | int rc; | ||
| 1881 | u32 l; | ||
| 1882 | struct resource *res; | ||
| 1883 | |||
| 1884 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 1885 | if (res == NULL) | ||
| 1886 | return -ENOENT; | ||
| 1887 | |||
| 1888 | phys_base = res->start; | ||
| 1889 | mem_size = resource_size(res); | ||
| 1890 | |||
| 1891 | gpmc_base = devm_ioremap_resource(&pdev->dev, res); | ||
| 1892 | if (IS_ERR(gpmc_base)) | ||
| 1893 | return PTR_ERR(gpmc_base); | ||
| 1894 | |||
| 1895 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
| 1896 | if (res == NULL) | ||
| 1897 | dev_warn(&pdev->dev, "Failed to get resource: irq\n"); | ||
| 1898 | else | ||
| 1899 | gpmc_irq = res->start; | ||
| 1900 | |||
| 1901 | gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck"); | ||
| 1902 | if (IS_ERR(gpmc_l3_clk)) { | ||
| 1903 | dev_err(&pdev->dev, "Failed to get GPMC fck\n"); | ||
| 1904 | gpmc_irq = 0; | ||
| 1905 | return PTR_ERR(gpmc_l3_clk); | ||
| 1906 | } | ||
| 1907 | |||
| 1908 | if (!clk_get_rate(gpmc_l3_clk)) { | ||
| 1909 | dev_err(&pdev->dev, "Invalid GPMC fck clock rate\n"); | ||
| 1910 | return -EINVAL; | ||
| 1911 | } | ||
| 1912 | |||
| 1913 | pm_runtime_enable(&pdev->dev); | ||
| 1914 | pm_runtime_get_sync(&pdev->dev); | ||
| 1915 | |||
| 1916 | gpmc_dev = &pdev->dev; | ||
| 1917 | |||
| 1918 | l = gpmc_read_reg(GPMC_REVISION); | ||
| 1919 | |||
| 1920 | /* | ||
| 1921 | * FIXME: Once device-tree migration is complete the below flags | ||
| 1922 | * should be populated based upon the device-tree compatible | ||
| 1923 | * string. For now just use the IP revision. OMAP3+ devices have | ||
| 1924 | * the wr_access and wr_data_mux_bus register fields. OMAP4+ | ||
| 1925 | * devices support the addr-addr-data multiplex protocol. | ||
| 1926 | * | ||
| 1927 | * GPMC IP revisions: | ||
| 1928 | * - OMAP24xx = 2.0 | ||
| 1929 | * - OMAP3xxx = 5.0 | ||
| 1930 | * - OMAP44xx/54xx/AM335x = 6.0 | ||
| 1931 | */ | ||
| 1932 | if (GPMC_REVISION_MAJOR(l) > 0x4) | ||
| 1933 | gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS; | ||
| 1934 | if (GPMC_REVISION_MAJOR(l) > 0x5) | ||
| 1935 | gpmc_capability |= GPMC_HAS_MUX_AAD; | ||
| 1936 | dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l), | ||
| 1937 | GPMC_REVISION_MINOR(l)); | ||
| 1938 | |||
| 1939 | gpmc_mem_init(); | ||
| 1940 | |||
| 1941 | if (gpmc_setup_irq() < 0) | ||
| 1942 | dev_warn(gpmc_dev, "gpmc_setup_irq failed\n"); | ||
| 1943 | |||
| 1944 | if (!pdev->dev.of_node) { | ||
| 1945 | gpmc_cs_num = GPMC_CS_NUM; | ||
| 1946 | gpmc_nr_waitpins = GPMC_NR_WAITPINS; | ||
| 1947 | } | ||
| 1948 | |||
| 1949 | rc = gpmc_probe_dt(pdev); | ||
| 1950 | if (rc < 0) { | ||
| 1951 | pm_runtime_put_sync(&pdev->dev); | ||
| 1952 | dev_err(gpmc_dev, "failed to probe DT parameters\n"); | ||
| 1953 | return rc; | ||
| 1954 | } | ||
| 1955 | |||
| 1956 | return 0; | ||
| 1957 | } | ||
| 1958 | |||
| 1959 | static int gpmc_remove(struct platform_device *pdev) | ||
| 1960 | { | ||
| 1961 | gpmc_free_irq(); | ||
| 1962 | gpmc_mem_exit(); | ||
| 1963 | pm_runtime_put_sync(&pdev->dev); | ||
| 1964 | pm_runtime_disable(&pdev->dev); | ||
| 1965 | gpmc_dev = NULL; | ||
| 1966 | return 0; | ||
| 1967 | } | ||
| 1968 | |||
| 1969 | #ifdef CONFIG_PM_SLEEP | ||
| 1970 | static int gpmc_suspend(struct device *dev) | ||
| 1971 | { | ||
| 1972 | omap3_gpmc_save_context(); | ||
| 1973 | pm_runtime_put_sync(dev); | ||
| 1974 | return 0; | ||
| 1975 | } | ||
| 1976 | |||
| 1977 | static int gpmc_resume(struct device *dev) | ||
| 1978 | { | ||
| 1979 | pm_runtime_get_sync(dev); | ||
| 1980 | omap3_gpmc_restore_context(); | ||
| 1981 | return 0; | ||
| 1982 | } | ||
| 1983 | #endif | ||
| 1984 | |||
| 1985 | static SIMPLE_DEV_PM_OPS(gpmc_pm_ops, gpmc_suspend, gpmc_resume); | ||
| 1986 | |||
| 1987 | static struct platform_driver gpmc_driver = { | ||
| 1988 | .probe = gpmc_probe, | ||
| 1989 | .remove = gpmc_remove, | ||
| 1990 | .driver = { | ||
| 1991 | .name = DEVICE_NAME, | ||
| 1992 | .owner = THIS_MODULE, | ||
| 1993 | .of_match_table = of_match_ptr(gpmc_dt_ids), | ||
| 1994 | .pm = &gpmc_pm_ops, | ||
| 1995 | }, | ||
| 1996 | }; | ||
| 1997 | |||
| 1998 | static __init int gpmc_init(void) | ||
| 1999 | { | ||
| 2000 | return platform_driver_register(&gpmc_driver); | ||
| 2001 | } | ||
| 2002 | |||
| 2003 | static __exit void gpmc_exit(void) | ||
| 2004 | { | ||
| 2005 | platform_driver_unregister(&gpmc_driver); | ||
| 2006 | |||
| 2007 | } | ||
| 2008 | |||
| 2009 | postcore_initcall(gpmc_init); | ||
| 2010 | module_exit(gpmc_exit); | ||
| 2011 | |||
| 2012 | static irqreturn_t gpmc_handle_irq(int irq, void *dev) | ||
| 2013 | { | ||
| 2014 | int i; | ||
| 2015 | u32 regval; | ||
| 2016 | |||
| 2017 | regval = gpmc_read_reg(GPMC_IRQSTATUS); | ||
| 2018 | |||
| 2019 | if (!regval) | ||
| 2020 | return IRQ_NONE; | ||
| 2021 | |||
| 2022 | for (i = 0; i < GPMC_NR_IRQ; i++) | ||
| 2023 | if (regval & gpmc_client_irq[i].bitmask) | ||
| 2024 | generic_handle_irq(gpmc_client_irq[i].irq); | ||
| 2025 | |||
| 2026 | gpmc_write_reg(GPMC_IRQSTATUS, regval); | ||
| 2027 | |||
| 2028 | return IRQ_HANDLED; | ||
| 2029 | } | ||
| 2030 | |||
| 2031 | static struct omap3_gpmc_regs gpmc_context; | ||
| 2032 | |||
| 2033 | void omap3_gpmc_save_context(void) | ||
| 2034 | { | ||
| 2035 | int i; | ||
| 2036 | |||
| 2037 | gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG); | ||
| 2038 | gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE); | ||
| 2039 | gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL); | ||
| 2040 | gpmc_context.config = gpmc_read_reg(GPMC_CONFIG); | ||
| 2041 | gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1); | ||
| 2042 | gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2); | ||
| 2043 | gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL); | ||
| 2044 | for (i = 0; i < gpmc_cs_num; i++) { | ||
| 2045 | gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i); | ||
| 2046 | if (gpmc_context.cs_context[i].is_valid) { | ||
| 2047 | gpmc_context.cs_context[i].config1 = | ||
| 2048 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG1); | ||
| 2049 | gpmc_context.cs_context[i].config2 = | ||
| 2050 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG2); | ||
| 2051 | gpmc_context.cs_context[i].config3 = | ||
| 2052 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG3); | ||
| 2053 | gpmc_context.cs_context[i].config4 = | ||
| 2054 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG4); | ||
| 2055 | gpmc_context.cs_context[i].config5 = | ||
| 2056 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG5); | ||
| 2057 | gpmc_context.cs_context[i].config6 = | ||
| 2058 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG6); | ||
| 2059 | gpmc_context.cs_context[i].config7 = | ||
| 2060 | gpmc_cs_read_reg(i, GPMC_CS_CONFIG7); | ||
| 2061 | } | ||
| 2062 | } | ||
| 2063 | } | ||
| 2064 | |||
| 2065 | void omap3_gpmc_restore_context(void) | ||
| 2066 | { | ||
| 2067 | int i; | ||
| 2068 | |||
| 2069 | gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig); | ||
| 2070 | gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable); | ||
| 2071 | gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl); | ||
| 2072 | gpmc_write_reg(GPMC_CONFIG, gpmc_context.config); | ||
| 2073 | gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1); | ||
| 2074 | gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2); | ||
| 2075 | gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control); | ||
| 2076 | for (i = 0; i < gpmc_cs_num; i++) { | ||
| 2077 | if (gpmc_context.cs_context[i].is_valid) { | ||
| 2078 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG1, | ||
| 2079 | gpmc_context.cs_context[i].config1); | ||
| 2080 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG2, | ||
| 2081 | gpmc_context.cs_context[i].config2); | ||
| 2082 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG3, | ||
| 2083 | gpmc_context.cs_context[i].config3); | ||
| 2084 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG4, | ||
| 2085 | gpmc_context.cs_context[i].config4); | ||
| 2086 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG5, | ||
| 2087 | gpmc_context.cs_context[i].config5); | ||
| 2088 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG6, | ||
| 2089 | gpmc_context.cs_context[i].config6); | ||
| 2090 | gpmc_cs_write_reg(i, GPMC_CS_CONFIG7, | ||
| 2091 | gpmc_context.cs_context[i].config7); | ||
| 2092 | } | ||
| 2093 | } | ||
| 2094 | } | ||
