Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap2/gpmc-onenand.c |
| 3 | * |
| 4 | * Copyright (C) 2006 - 2009 Nokia Corporation |
| 5 | * Contacts: Juha Yrjola |
| 6 | * Tony Lindgren |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
Paul Gortmaker | d44b28c | 2011-07-31 10:52:44 -0400 | [diff] [blame] | 13 | #include <linux/string.h> |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/mtd/onenand_regs.h> |
| 17 | #include <linux/io.h> |
Arnd Bergmann | 2203747 | 2012-08-24 15:21:06 +0200 | [diff] [blame] | 18 | #include <linux/platform_data/mtd-onenand-omap2.h> |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 19 | #include <linux/err.h> |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/mach/flash.h> |
| 22 | |
Afzal Mohammed | 3ef5d00 | 2012-10-05 10:37:27 +0530 | [diff] [blame] | 23 | #include "gpmc.h" |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 24 | #include "soc.h" |
Afzal Mohammed | b6ab13e | 2012-09-29 10:32:42 +0530 | [diff] [blame] | 25 | #include "gpmc-onenand.h" |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 26 | |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 27 | #define ONENAND_IO_SIZE SZ_128K |
| 28 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 29 | #define ONENAND_FLAG_SYNCREAD (1 << 0) |
| 30 | #define ONENAND_FLAG_SYNCWRITE (1 << 1) |
| 31 | #define ONENAND_FLAG_HF (1 << 2) |
| 32 | #define ONENAND_FLAG_VHF (1 << 3) |
| 33 | |
| 34 | static unsigned onenand_flags; |
| 35 | static unsigned latency; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 36 | |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 37 | static struct omap_onenand_platform_data *gpmc_onenand_data; |
| 38 | |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 39 | static struct resource gpmc_onenand_resource = { |
| 40 | .flags = IORESOURCE_MEM, |
| 41 | }; |
| 42 | |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 43 | static struct platform_device gpmc_onenand_device = { |
| 44 | .name = "omap2-onenand", |
| 45 | .id = -1, |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 46 | .num_resources = 1, |
| 47 | .resource = &gpmc_onenand_resource, |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 50 | static struct gpmc_settings onenand_async = { |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 51 | .device_width = GPMC_DEVWIDTH_16BIT, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 52 | .mux_add_data = GPMC_MUX_AD, |
| 53 | }; |
| 54 | |
| 55 | static struct gpmc_settings onenand_sync = { |
| 56 | .burst_read = true, |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 57 | .burst_wrap = true, |
| 58 | .burst_len = GPMC_BURST_16, |
| 59 | .device_width = GPMC_DEVWIDTH_16BIT, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 60 | .mux_add_data = GPMC_MUX_AD, |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 61 | .wait_pin = 0, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 62 | }; |
| 63 | |
Jon Hunter | be9f10c | 2013-02-21 15:20:53 -0600 | [diff] [blame] | 64 | static void omap2_onenand_calc_async_timings(struct gpmc_timings *t) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 65 | { |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 66 | struct gpmc_device_timings dev_t; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 67 | const int t_cer = 15; |
| 68 | const int t_avdp = 12; |
| 69 | const int t_aavdh = 7; |
| 70 | const int t_ce = 76; |
| 71 | const int t_aa = 76; |
| 72 | const int t_oe = 20; |
| 73 | const int t_cez = 20; /* max of t_cez, t_oez */ |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 74 | const int t_wpl = 40; |
| 75 | const int t_wph = 30; |
| 76 | |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 77 | memset(&dev_t, 0, sizeof(dev_t)); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 78 | |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 79 | dev_t.t_avdp_r = max_t(int, t_avdp, t_cer) * 1000; |
| 80 | dev_t.t_avdp_w = dev_t.t_avdp_r; |
| 81 | dev_t.t_aavdh = t_aavdh * 1000; |
| 82 | dev_t.t_aa = t_aa * 1000; |
| 83 | dev_t.t_ce = t_ce * 1000; |
| 84 | dev_t.t_oe = t_oe * 1000; |
| 85 | dev_t.t_cez_r = t_cez * 1000; |
| 86 | dev_t.t_cez_w = dev_t.t_cez_r; |
| 87 | dev_t.t_wpl = t_wpl * 1000; |
| 88 | dev_t.t_wph = t_wph * 1000; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 89 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 90 | gpmc_calc_timings(t, &onenand_async, &dev_t); |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 91 | } |
| 92 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 93 | static void omap2_onenand_set_async_mode(void __iomem *onenand_base) |
| 94 | { |
| 95 | u32 reg; |
Adrian Hunter | 6d453e8 | 2009-06-23 13:30:24 +0300 | [diff] [blame] | 96 | |
| 97 | /* Ensure sync read and sync write are disabled */ |
| 98 | reg = readw(onenand_base + ONENAND_REG_SYS_CFG1); |
| 99 | reg &= ~ONENAND_SYS_CFG1_SYNC_READ & ~ONENAND_SYS_CFG1_SYNC_WRITE; |
| 100 | writew(reg, onenand_base + ONENAND_REG_SYS_CFG1); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 103 | static void set_onenand_cfg(void __iomem *onenand_base) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 104 | { |
| 105 | u32 reg; |
| 106 | |
| 107 | reg = readw(onenand_base + ONENAND_REG_SYS_CFG1); |
| 108 | reg &= ~((0x7 << ONENAND_SYS_CFG1_BRL_SHIFT) | (0x7 << 9)); |
| 109 | reg |= (latency << ONENAND_SYS_CFG1_BRL_SHIFT) | |
| 110 | ONENAND_SYS_CFG1_BL_16; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 111 | if (onenand_flags & ONENAND_FLAG_SYNCREAD) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 112 | reg |= ONENAND_SYS_CFG1_SYNC_READ; |
| 113 | else |
| 114 | reg &= ~ONENAND_SYS_CFG1_SYNC_READ; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 115 | if (onenand_flags & ONENAND_FLAG_SYNCWRITE) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 116 | reg |= ONENAND_SYS_CFG1_SYNC_WRITE; |
| 117 | else |
| 118 | reg &= ~ONENAND_SYS_CFG1_SYNC_WRITE; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 119 | if (onenand_flags & ONENAND_FLAG_HF) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 120 | reg |= ONENAND_SYS_CFG1_HF; |
| 121 | else |
| 122 | reg &= ~ONENAND_SYS_CFG1_HF; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 123 | if (onenand_flags & ONENAND_FLAG_VHF) |
Adrian Hunter | 1435ca0 | 2011-02-07 10:46:58 +0200 | [diff] [blame] | 124 | reg |= ONENAND_SYS_CFG1_VHF; |
| 125 | else |
| 126 | reg &= ~ONENAND_SYS_CFG1_VHF; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 127 | writew(reg, onenand_base + ONENAND_REG_SYS_CFG1); |
| 128 | } |
| 129 | |
Adrian Hunter | 5714b7ed | 2011-02-07 10:47:00 +0200 | [diff] [blame] | 130 | static int omap2_onenand_get_freq(struct omap_onenand_platform_data *cfg, |
Jon Hunter | 757ef79 | 2012-06-28 13:41:29 -0500 | [diff] [blame] | 131 | void __iomem *onenand_base) |
Adrian Hunter | 5714b7ed | 2011-02-07 10:47:00 +0200 | [diff] [blame] | 132 | { |
| 133 | u16 ver = readw(onenand_base + ONENAND_REG_VERSION_ID); |
Jon Hunter | 757ef79 | 2012-06-28 13:41:29 -0500 | [diff] [blame] | 134 | int freq; |
Adrian Hunter | 5714b7ed | 2011-02-07 10:47:00 +0200 | [diff] [blame] | 135 | |
| 136 | switch ((ver >> 4) & 0xf) { |
| 137 | case 0: |
| 138 | freq = 40; |
| 139 | break; |
| 140 | case 1: |
| 141 | freq = 54; |
| 142 | break; |
| 143 | case 2: |
| 144 | freq = 66; |
| 145 | break; |
| 146 | case 3: |
| 147 | freq = 83; |
| 148 | break; |
| 149 | case 4: |
| 150 | freq = 104; |
| 151 | break; |
| 152 | default: |
| 153 | freq = 54; |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | return freq; |
| 158 | } |
| 159 | |
Jon Hunter | be9f10c | 2013-02-21 15:20:53 -0600 | [diff] [blame] | 160 | static void omap2_onenand_calc_sync_timings(struct gpmc_timings *t, |
| 161 | unsigned int flags, |
| 162 | int freq) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 163 | { |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 164 | struct gpmc_device_timings dev_t; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 165 | const int t_cer = 15; |
| 166 | const int t_avdp = 12; |
| 167 | const int t_cez = 20; /* max of t_cez, t_oez */ |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 168 | const int t_wpl = 40; |
| 169 | const int t_wph = 30; |
| 170 | int min_gpmc_clk_period, t_ces, t_avds, t_avdh, t_ach, t_aavdh, t_rdyo; |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 171 | int div, gpmc_clk_ns; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 172 | |
Jon Hunter | be9f10c | 2013-02-21 15:20:53 -0600 | [diff] [blame] | 173 | if (flags & ONENAND_SYNC_READ) |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 174 | onenand_flags = ONENAND_FLAG_SYNCREAD; |
Jon Hunter | be9f10c | 2013-02-21 15:20:53 -0600 | [diff] [blame] | 175 | else if (flags & ONENAND_SYNC_READWRITE) |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 176 | onenand_flags = ONENAND_FLAG_SYNCREAD | ONENAND_FLAG_SYNCWRITE; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 177 | |
| 178 | switch (freq) { |
Adrian Hunter | 4931445 | 2010-12-09 11:22:50 +0200 | [diff] [blame] | 179 | case 104: |
| 180 | min_gpmc_clk_period = 9600; /* 104 MHz */ |
| 181 | t_ces = 3; |
| 182 | t_avds = 4; |
| 183 | t_avdh = 2; |
| 184 | t_ach = 3; |
| 185 | t_aavdh = 6; |
Adrian Hunter | 1435ca0 | 2011-02-07 10:46:58 +0200 | [diff] [blame] | 186 | t_rdyo = 6; |
Adrian Hunter | 4931445 | 2010-12-09 11:22:50 +0200 | [diff] [blame] | 187 | break; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 188 | case 83: |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 189 | min_gpmc_clk_period = 12000; /* 83 MHz */ |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 190 | t_ces = 5; |
| 191 | t_avds = 4; |
| 192 | t_avdh = 2; |
| 193 | t_ach = 6; |
| 194 | t_aavdh = 6; |
| 195 | t_rdyo = 9; |
| 196 | break; |
| 197 | case 66: |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 198 | min_gpmc_clk_period = 15000; /* 66 MHz */ |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 199 | t_ces = 6; |
| 200 | t_avds = 5; |
| 201 | t_avdh = 2; |
| 202 | t_ach = 6; |
| 203 | t_aavdh = 6; |
| 204 | t_rdyo = 11; |
| 205 | break; |
| 206 | default: |
Adrian Hunter | a3551f5 | 2010-12-09 10:48:27 +0200 | [diff] [blame] | 207 | min_gpmc_clk_period = 18500; /* 54 MHz */ |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 208 | t_ces = 7; |
| 209 | t_avds = 7; |
| 210 | t_avdh = 7; |
| 211 | t_ach = 9; |
| 212 | t_aavdh = 7; |
| 213 | t_rdyo = 15; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 214 | onenand_flags &= ~ONENAND_FLAG_SYNCWRITE; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | |
Afzal Mohammed | 1b47ca1 | 2012-08-19 18:29:45 +0530 | [diff] [blame] | 218 | div = gpmc_calc_divider(min_gpmc_clk_period); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 219 | gpmc_clk_ns = gpmc_ticks_to_ns(div); |
| 220 | if (gpmc_clk_ns < 15) /* >66Mhz */ |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 221 | onenand_flags |= ONENAND_FLAG_HF; |
| 222 | else |
| 223 | onenand_flags &= ~ONENAND_FLAG_HF; |
Adrian Hunter | 1435ca0 | 2011-02-07 10:46:58 +0200 | [diff] [blame] | 224 | if (gpmc_clk_ns < 12) /* >83Mhz */ |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 225 | onenand_flags |= ONENAND_FLAG_VHF; |
| 226 | else |
| 227 | onenand_flags &= ~ONENAND_FLAG_VHF; |
| 228 | if (onenand_flags & ONENAND_FLAG_VHF) |
Adrian Hunter | 1435ca0 | 2011-02-07 10:46:58 +0200 | [diff] [blame] | 229 | latency = 8; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 230 | else if (onenand_flags & ONENAND_FLAG_HF) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 231 | latency = 6; |
| 232 | else if (gpmc_clk_ns >= 25) /* 40 MHz*/ |
| 233 | latency = 3; |
| 234 | else |
| 235 | latency = 4; |
| 236 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 237 | /* Set synchronous read timings */ |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 238 | memset(&dev_t, 0, sizeof(dev_t)); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 239 | |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 240 | if (onenand_flags & ONENAND_FLAG_SYNCREAD) |
| 241 | onenand_sync.sync_read = true; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 242 | if (onenand_flags & ONENAND_FLAG_SYNCWRITE) { |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 243 | onenand_sync.sync_write = true; |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 244 | onenand_sync.burst_write = true; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 245 | } else { |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 246 | dev_t.t_avdp_w = max(t_avdp, t_cer) * 1000; |
| 247 | dev_t.t_wpl = t_wpl * 1000; |
| 248 | dev_t.t_wph = t_wph * 1000; |
| 249 | dev_t.t_aavdh = t_aavdh * 1000; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 250 | } |
Afzal Mohammed | 4f4426f | 2012-11-09 18:05:17 +0530 | [diff] [blame] | 251 | dev_t.ce_xdelay = true; |
| 252 | dev_t.avd_xdelay = true; |
| 253 | dev_t.oe_xdelay = true; |
| 254 | dev_t.we_xdelay = true; |
| 255 | dev_t.clk = min_gpmc_clk_period; |
| 256 | dev_t.t_bacc = dev_t.clk; |
| 257 | dev_t.t_ces = t_ces * 1000; |
| 258 | dev_t.t_avds = t_avds * 1000; |
| 259 | dev_t.t_avdh = t_avdh * 1000; |
| 260 | dev_t.t_ach = t_ach * 1000; |
| 261 | dev_t.cyc_iaa = (latency + 1); |
| 262 | dev_t.t_cez_r = t_cez * 1000; |
| 263 | dev_t.t_cez_w = dev_t.t_cez_r; |
| 264 | dev_t.cyc_aavdh_oe = 1; |
| 265 | dev_t.t_rdyo = t_rdyo * 1000 + min_gpmc_clk_period; |
| 266 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 267 | gpmc_calc_timings(t, &onenand_sync, &dev_t); |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 268 | } |
| 269 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 270 | static int omap2_onenand_setup_async(void __iomem *onenand_base) |
| 271 | { |
| 272 | struct gpmc_timings t; |
| 273 | int ret; |
| 274 | |
Aaro Koskinen | 1dc1c33 | 2013-09-20 23:01:06 +0300 | [diff] [blame] | 275 | if (gpmc_onenand_data->of_node) { |
Jon Hunter | 32cde0b | 2013-02-25 11:37:58 -0600 | [diff] [blame] | 276 | gpmc_read_settings_dt(gpmc_onenand_data->of_node, |
| 277 | &onenand_async); |
Aaro Koskinen | 1dc1c33 | 2013-09-20 23:01:06 +0300 | [diff] [blame] | 278 | if (onenand_async.sync_read || onenand_async.sync_write) { |
| 279 | if (onenand_async.sync_write) |
| 280 | gpmc_onenand_data->flags |= |
| 281 | ONENAND_SYNC_READWRITE; |
| 282 | else |
| 283 | gpmc_onenand_data->flags |= ONENAND_SYNC_READ; |
| 284 | onenand_async.sync_read = false; |
| 285 | onenand_async.sync_write = false; |
| 286 | } |
| 287 | } |
Jon Hunter | 32cde0b | 2013-02-25 11:37:58 -0600 | [diff] [blame] | 288 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 289 | omap2_onenand_set_async_mode(onenand_base); |
| 290 | |
Jon Hunter | be9f10c | 2013-02-21 15:20:53 -0600 | [diff] [blame] | 291 | omap2_onenand_calc_async_timings(&t); |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 292 | |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 293 | ret = gpmc_cs_program_settings(gpmc_onenand_data->cs, &onenand_async); |
| 294 | if (ret < 0) |
| 295 | return ret; |
| 296 | |
| 297 | ret = gpmc_cs_set_timings(gpmc_onenand_data->cs, &t); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 298 | if (ret < 0) |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 299 | return ret; |
| 300 | |
| 301 | omap2_onenand_set_async_mode(onenand_base); |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int omap2_onenand_setup_sync(void __iomem *onenand_base, int *freq_ptr) |
| 307 | { |
| 308 | int ret, freq = *freq_ptr; |
| 309 | struct gpmc_timings t; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 310 | |
| 311 | if (!freq) { |
| 312 | /* Very first call freq is not known */ |
Jon Hunter | 757ef79 | 2012-06-28 13:41:29 -0500 | [diff] [blame] | 313 | freq = omap2_onenand_get_freq(gpmc_onenand_data, onenand_base); |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 314 | set_onenand_cfg(onenand_base); |
| 315 | } |
| 316 | |
Jon Hunter | 32cde0b | 2013-02-25 11:37:58 -0600 | [diff] [blame] | 317 | if (gpmc_onenand_data->of_node) { |
| 318 | gpmc_read_settings_dt(gpmc_onenand_data->of_node, |
| 319 | &onenand_sync); |
| 320 | } else { |
| 321 | /* |
| 322 | * FIXME: Appears to be legacy code from initial ONENAND commit. |
| 323 | * Unclear what boards this is for and if this can be removed. |
| 324 | */ |
| 325 | if (!cpu_is_omap34xx()) |
| 326 | onenand_sync.wait_on_read = true; |
| 327 | } |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 328 | |
Jon Hunter | be9f10c | 2013-02-21 15:20:53 -0600 | [diff] [blame] | 329 | omap2_onenand_calc_sync_timings(&t, gpmc_onenand_data->flags, freq); |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 330 | |
Jon Hunter | 3aef65e | 2013-02-21 12:42:22 -0600 | [diff] [blame] | 331 | ret = gpmc_cs_program_settings(gpmc_onenand_data->cs, &onenand_sync); |
| 332 | if (ret < 0) |
| 333 | return ret; |
| 334 | |
| 335 | ret = gpmc_cs_set_timings(gpmc_onenand_data->cs, &t); |
Russell King | 7185684 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 336 | if (ret < 0) |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 337 | return ret; |
| 338 | |
| 339 | set_onenand_cfg(onenand_base); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 340 | |
Adrian Hunter | 3ad2d86 | 2011-02-07 10:46:59 +0200 | [diff] [blame] | 341 | *freq_ptr = freq; |
| 342 | |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Adrian Hunter | 3ad2d86 | 2011-02-07 10:46:59 +0200 | [diff] [blame] | 346 | static int gpmc_onenand_setup(void __iomem *onenand_base, int *freq_ptr) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 347 | { |
| 348 | struct device *dev = &gpmc_onenand_device.dev; |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 349 | unsigned l = ONENAND_SYNC_READ | ONENAND_SYNC_READWRITE; |
| 350 | int ret; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 351 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 352 | ret = omap2_onenand_setup_async(onenand_base); |
| 353 | if (ret) { |
| 354 | dev_err(dev, "unable to set to async mode\n"); |
| 355 | return ret; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Afzal Mohammed | 4637688 | 2012-06-05 10:11:48 +0530 | [diff] [blame] | 358 | if (!(gpmc_onenand_data->flags & l)) |
| 359 | return 0; |
| 360 | |
| 361 | ret = omap2_onenand_setup_sync(onenand_base, freq_ptr); |
| 362 | if (ret) |
| 363 | dev_err(dev, "unable to set to sync mode\n"); |
| 364 | return ret; |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Ezequiel Garcia | faf5d2f | 2013-01-25 09:23:10 -0300 | [diff] [blame] | 367 | void gpmc_onenand_init(struct omap_onenand_platform_data *_onenand_data) |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 368 | { |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 369 | int err; |
Ezequiel Garcia | df25cb4 | 2013-02-12 16:22:22 -0300 | [diff] [blame] | 370 | struct device *dev = &gpmc_onenand_device.dev; |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 371 | |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 372 | gpmc_onenand_data = _onenand_data; |
| 373 | gpmc_onenand_data->onenand_setup = gpmc_onenand_setup; |
| 374 | gpmc_onenand_device.dev.platform_data = gpmc_onenand_data; |
| 375 | |
| 376 | if (cpu_is_omap24xx() && |
| 377 | (gpmc_onenand_data->flags & ONENAND_SYNC_READWRITE)) { |
Ezequiel Garcia | 7ab9159 | 2013-02-12 16:22:23 -0300 | [diff] [blame] | 378 | dev_warn(dev, "OneNAND using only SYNC_READ on 24xx\n"); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 379 | gpmc_onenand_data->flags &= ~ONENAND_SYNC_READWRITE; |
| 380 | gpmc_onenand_data->flags |= ONENAND_SYNC_READ; |
| 381 | } |
| 382 | |
Afzal Mohammed | eb77b6a | 2012-10-05 11:39:54 +0530 | [diff] [blame] | 383 | if (cpu_is_omap34xx()) |
| 384 | gpmc_onenand_data->flags |= ONENAND_IN_OMAP34XX; |
| 385 | else |
| 386 | gpmc_onenand_data->flags &= ~ONENAND_IN_OMAP34XX; |
| 387 | |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 388 | err = gpmc_cs_request(gpmc_onenand_data->cs, ONENAND_IO_SIZE, |
| 389 | (unsigned long *)&gpmc_onenand_resource.start); |
| 390 | if (err < 0) { |
Ezequiel Garcia | df25cb4 | 2013-02-12 16:22:22 -0300 | [diff] [blame] | 391 | dev_err(dev, "Cannot request GPMC CS %d, error %d\n", |
| 392 | gpmc_onenand_data->cs, err); |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
| 396 | gpmc_onenand_resource.end = gpmc_onenand_resource.start + |
| 397 | ONENAND_IO_SIZE - 1; |
| 398 | |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 399 | if (platform_device_register(&gpmc_onenand_device) < 0) { |
Ezequiel Garcia | df25cb4 | 2013-02-12 16:22:22 -0300 | [diff] [blame] | 400 | dev_err(dev, "Unable to register OneNAND device\n"); |
Afzal Mohammed | 681988b | 2012-08-30 12:53:23 -0700 | [diff] [blame] | 401 | gpmc_cs_free(gpmc_onenand_data->cs); |
Juha Yrjola | aa62e90 | 2009-05-28 13:23:52 -0700 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | } |