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