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