Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * NAND Flash Controller Device Driver |
| 3 | * Copyright © 2009-2010, Intel Corporation and its suppliers. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/delay.h> |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 22 | #include <linux/dma-mapping.h> |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 23 | #include <linux/wait.h> |
| 24 | #include <linux/mutex.h> |
David Miller | b8664b3 | 2010-08-04 22:57:51 -0700 | [diff] [blame] | 25 | #include <linux/slab.h> |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 26 | #include <linux/pci.h> |
| 27 | #include <linux/mtd/mtd.h> |
| 28 | #include <linux/module.h> |
| 29 | |
| 30 | #include "denali.h" |
| 31 | |
| 32 | MODULE_LICENSE("GPL"); |
| 33 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 34 | /* We define a module parameter that allows the user to override |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 35 | * the hardware and decide what timing mode should be used. |
| 36 | */ |
| 37 | #define NAND_DEFAULT_TIMINGS -1 |
| 38 | |
| 39 | static int onfi_timing_mode = NAND_DEFAULT_TIMINGS; |
| 40 | module_param(onfi_timing_mode, int, S_IRUGO); |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 41 | MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting." |
| 42 | " -1 indicates use default timings"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 43 | |
| 44 | #define DENALI_NAND_NAME "denali-nand" |
| 45 | |
| 46 | /* We define a macro here that combines all interrupts this driver uses into |
| 47 | * a single constant value, for convenience. */ |
| 48 | #define DENALI_IRQ_ALL (INTR_STATUS0__DMA_CMD_COMP | \ |
| 49 | INTR_STATUS0__ECC_TRANSACTION_DONE | \ |
| 50 | INTR_STATUS0__ECC_ERR | \ |
| 51 | INTR_STATUS0__PROGRAM_FAIL | \ |
| 52 | INTR_STATUS0__LOAD_COMP | \ |
| 53 | INTR_STATUS0__PROGRAM_COMP | \ |
| 54 | INTR_STATUS0__TIME_OUT | \ |
| 55 | INTR_STATUS0__ERASE_FAIL | \ |
| 56 | INTR_STATUS0__RST_COMP | \ |
| 57 | INTR_STATUS0__ERASE_COMP) |
| 58 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 59 | /* indicates whether or not the internal value for the flash bank is |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 60 | * valid or not */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 61 | #define CHIP_SELECT_INVALID -1 |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 62 | |
| 63 | #define SUPPORT_8BITECC 1 |
| 64 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 65 | /* This macro divides two integers and rounds fractional values up |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 66 | * to the nearest integer value. */ |
| 67 | #define CEIL_DIV(X, Y) (((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y))) |
| 68 | |
| 69 | /* this macro allows us to convert from an MTD structure to our own |
| 70 | * device context (denali) structure. |
| 71 | */ |
| 72 | #define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd) |
| 73 | |
| 74 | /* These constants are defined by the driver to enable common driver |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 75 | * configuration options. */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 76 | #define SPARE_ACCESS 0x41 |
| 77 | #define MAIN_ACCESS 0x42 |
| 78 | #define MAIN_SPARE_ACCESS 0x43 |
| 79 | |
| 80 | #define DENALI_READ 0 |
| 81 | #define DENALI_WRITE 0x100 |
| 82 | |
| 83 | /* types of device accesses. We can issue commands and get status */ |
| 84 | #define COMMAND_CYCLE 0 |
| 85 | #define ADDR_CYCLE 1 |
| 86 | #define STATUS_CYCLE 2 |
| 87 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 88 | /* this is a helper macro that allows us to |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 89 | * format the bank into the proper bits for the controller */ |
| 90 | #define BANK(x) ((x) << 24) |
| 91 | |
| 92 | /* List of platforms this NAND controller has be integrated into */ |
| 93 | static const struct pci_device_id denali_pci_ids[] = { |
| 94 | { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 }, |
| 95 | { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST }, |
| 96 | { /* end: all zeroes */ } |
| 97 | }; |
| 98 | |
| 99 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 100 | /* these are static lookup tables that give us easy access to |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 101 | * registers in the NAND controller. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 102 | */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 103 | static const uint32_t intr_status_addresses[4] = {INTR_STATUS0, |
| 104 | INTR_STATUS1, |
| 105 | INTR_STATUS2, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 106 | INTR_STATUS3}; |
| 107 | |
| 108 | static const uint32_t device_reset_banks[4] = {DEVICE_RESET__BANK0, |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 109 | DEVICE_RESET__BANK1, |
| 110 | DEVICE_RESET__BANK2, |
| 111 | DEVICE_RESET__BANK3}; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 112 | |
| 113 | static const uint32_t operation_timeout[4] = {INTR_STATUS0__TIME_OUT, |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 114 | INTR_STATUS1__TIME_OUT, |
| 115 | INTR_STATUS2__TIME_OUT, |
| 116 | INTR_STATUS3__TIME_OUT}; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 117 | |
| 118 | static const uint32_t reset_complete[4] = {INTR_STATUS0__RST_COMP, |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 119 | INTR_STATUS1__RST_COMP, |
| 120 | INTR_STATUS2__RST_COMP, |
| 121 | INTR_STATUS3__RST_COMP}; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 122 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 123 | /* forward declarations */ |
| 124 | static void clear_interrupts(struct denali_nand_info *denali); |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 125 | static uint32_t wait_for_irq(struct denali_nand_info *denali, |
| 126 | uint32_t irq_mask); |
| 127 | static void denali_irq_enable(struct denali_nand_info *denali, |
| 128 | uint32_t int_mask); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 129 | static uint32_t read_interrupt_status(struct denali_nand_info *denali); |
| 130 | |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 131 | /* Certain operations for the denali NAND controller use |
| 132 | * an indexed mode to read/write data. The operation is |
| 133 | * performed by writing the address value of the command |
| 134 | * to the device memory followed by the data. This function |
| 135 | * abstracts this common operation. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 136 | */ |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 137 | static void index_addr(struct denali_nand_info *denali, |
| 138 | uint32_t address, uint32_t data) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 139 | { |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 140 | iowrite32(address, denali->flash_mem); |
| 141 | iowrite32(data, denali->flash_mem + 0x10); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Perform an indexed read of the device */ |
| 145 | static void index_addr_read_data(struct denali_nand_info *denali, |
| 146 | uint32_t address, uint32_t *pdata) |
| 147 | { |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 148 | iowrite32(address, denali->flash_mem); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 149 | *pdata = ioread32(denali->flash_mem + 0x10); |
| 150 | } |
| 151 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 152 | /* We need to buffer some data for some of the NAND core routines. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 153 | * The operations manage buffering that data. */ |
| 154 | static void reset_buf(struct denali_nand_info *denali) |
| 155 | { |
| 156 | denali->buf.head = denali->buf.tail = 0; |
| 157 | } |
| 158 | |
| 159 | static void write_byte_to_buf(struct denali_nand_info *denali, uint8_t byte) |
| 160 | { |
| 161 | BUG_ON(denali->buf.tail >= sizeof(denali->buf.buf)); |
| 162 | denali->buf.buf[denali->buf.tail++] = byte; |
| 163 | } |
| 164 | |
| 165 | /* reads the status of the device */ |
| 166 | static void read_status(struct denali_nand_info *denali) |
| 167 | { |
| 168 | uint32_t cmd = 0x0; |
| 169 | |
| 170 | /* initialize the data buffer to store status */ |
| 171 | reset_buf(denali); |
| 172 | |
Chuanxiao Dong | f0bc0c7 | 2010-08-11 17:14:59 +0800 | [diff] [blame] | 173 | cmd = ioread32(denali->flash_reg + WRITE_PROTECT); |
| 174 | if (cmd) |
| 175 | write_byte_to_buf(denali, NAND_STATUS_WP); |
| 176 | else |
| 177 | write_byte_to_buf(denali, 0); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* resets a specific device connected to the core */ |
| 181 | static void reset_bank(struct denali_nand_info *denali) |
| 182 | { |
| 183 | uint32_t irq_status = 0; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 184 | uint32_t irq_mask = reset_complete[denali->flash_bank] | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 185 | operation_timeout[denali->flash_bank]; |
| 186 | int bank = 0; |
| 187 | |
| 188 | clear_interrupts(denali); |
| 189 | |
| 190 | bank = device_reset_banks[denali->flash_bank]; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 191 | iowrite32(bank, denali->flash_reg + DEVICE_RESET); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 192 | |
| 193 | irq_status = wait_for_irq(denali, irq_mask); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 194 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 195 | if (irq_status & operation_timeout[denali->flash_bank]) |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 196 | dev_err(denali->dev, "reset bank failed.\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* Reset the flash controller */ |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 200 | static uint16_t denali_nand_reset(struct denali_nand_info *denali) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 201 | { |
| 202 | uint32_t i; |
| 203 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 204 | dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 205 | __FILE__, __LINE__, __func__); |
| 206 | |
| 207 | for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 208 | iowrite32(reset_complete[i] | operation_timeout[i], |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 209 | denali->flash_reg + intr_status_addresses[i]); |
| 210 | |
| 211 | for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) { |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 212 | iowrite32(device_reset_banks[i], |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 213 | denali->flash_reg + DEVICE_RESET); |
| 214 | while (!(ioread32(denali->flash_reg + |
Chuanxiao Dong | 628bfd41 | 2010-08-11 17:53:29 +0800 | [diff] [blame] | 215 | intr_status_addresses[i]) & |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 216 | (reset_complete[i] | operation_timeout[i]))) |
Chuanxiao Dong | 628bfd41 | 2010-08-11 17:53:29 +0800 | [diff] [blame] | 217 | cpu_relax(); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 218 | if (ioread32(denali->flash_reg + intr_status_addresses[i]) & |
| 219 | operation_timeout[i]) |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 220 | dev_dbg(denali->dev, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 221 | "NAND Reset operation timed out on bank %d\n", i); |
| 222 | } |
| 223 | |
| 224 | for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 225 | iowrite32(reset_complete[i] | operation_timeout[i], |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 226 | denali->flash_reg + intr_status_addresses[i]); |
| 227 | |
| 228 | return PASS; |
| 229 | } |
| 230 | |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 231 | /* this routine calculates the ONFI timing values for a given mode and |
| 232 | * programs the clocking register accordingly. The mode is determined by |
| 233 | * the get_onfi_nand_para routine. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 234 | */ |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 235 | static void nand_onfi_timing_set(struct denali_nand_info *denali, |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 236 | uint16_t mode) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 237 | { |
| 238 | uint16_t Trea[6] = {40, 30, 25, 20, 20, 16}; |
| 239 | uint16_t Trp[6] = {50, 25, 17, 15, 12, 10}; |
| 240 | uint16_t Treh[6] = {30, 15, 15, 10, 10, 7}; |
| 241 | uint16_t Trc[6] = {100, 50, 35, 30, 25, 20}; |
| 242 | uint16_t Trhoh[6] = {0, 15, 15, 15, 15, 15}; |
| 243 | uint16_t Trloh[6] = {0, 0, 0, 0, 5, 5}; |
| 244 | uint16_t Tcea[6] = {100, 45, 30, 25, 25, 25}; |
| 245 | uint16_t Tadl[6] = {200, 100, 100, 100, 70, 70}; |
| 246 | uint16_t Trhw[6] = {200, 100, 100, 100, 100, 100}; |
| 247 | uint16_t Trhz[6] = {200, 100, 100, 100, 100, 100}; |
| 248 | uint16_t Twhr[6] = {120, 80, 80, 60, 60, 60}; |
| 249 | uint16_t Tcs[6] = {70, 35, 25, 25, 20, 15}; |
| 250 | |
| 251 | uint16_t TclsRising = 1; |
| 252 | uint16_t data_invalid_rhoh, data_invalid_rloh, data_invalid; |
| 253 | uint16_t dv_window = 0; |
| 254 | uint16_t en_lo, en_hi; |
| 255 | uint16_t acc_clks; |
| 256 | uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt; |
| 257 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 258 | dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 259 | __FILE__, __LINE__, __func__); |
| 260 | |
| 261 | en_lo = CEIL_DIV(Trp[mode], CLK_X); |
| 262 | en_hi = CEIL_DIV(Treh[mode], CLK_X); |
| 263 | #if ONFI_BLOOM_TIME |
| 264 | if ((en_hi * CLK_X) < (Treh[mode] + 2)) |
| 265 | en_hi++; |
| 266 | #endif |
| 267 | |
| 268 | if ((en_lo + en_hi) * CLK_X < Trc[mode]) |
| 269 | en_lo += CEIL_DIV((Trc[mode] - (en_lo + en_hi) * CLK_X), CLK_X); |
| 270 | |
| 271 | if ((en_lo + en_hi) < CLK_MULTI) |
| 272 | en_lo += CLK_MULTI - en_lo - en_hi; |
| 273 | |
| 274 | while (dv_window < 8) { |
| 275 | data_invalid_rhoh = en_lo * CLK_X + Trhoh[mode]; |
| 276 | |
| 277 | data_invalid_rloh = (en_lo + en_hi) * CLK_X + Trloh[mode]; |
| 278 | |
| 279 | data_invalid = |
| 280 | data_invalid_rhoh < |
| 281 | data_invalid_rloh ? data_invalid_rhoh : data_invalid_rloh; |
| 282 | |
| 283 | dv_window = data_invalid - Trea[mode]; |
| 284 | |
| 285 | if (dv_window < 8) |
| 286 | en_lo++; |
| 287 | } |
| 288 | |
| 289 | acc_clks = CEIL_DIV(Trea[mode], CLK_X); |
| 290 | |
| 291 | while (((acc_clks * CLK_X) - Trea[mode]) < 3) |
| 292 | acc_clks++; |
| 293 | |
| 294 | if ((data_invalid - acc_clks * CLK_X) < 2) |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 295 | dev_warn(denali->dev, "%s, Line %d: Warning!\n", |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 296 | __FILE__, __LINE__); |
| 297 | |
| 298 | addr_2_data = CEIL_DIV(Tadl[mode], CLK_X); |
| 299 | re_2_we = CEIL_DIV(Trhw[mode], CLK_X); |
| 300 | re_2_re = CEIL_DIV(Trhz[mode], CLK_X); |
| 301 | we_2_re = CEIL_DIV(Twhr[mode], CLK_X); |
| 302 | cs_cnt = CEIL_DIV((Tcs[mode] - Trp[mode]), CLK_X); |
| 303 | if (!TclsRising) |
| 304 | cs_cnt = CEIL_DIV(Tcs[mode], CLK_X); |
| 305 | if (cs_cnt == 0) |
| 306 | cs_cnt = 1; |
| 307 | |
| 308 | if (Tcea[mode]) { |
| 309 | while (((cs_cnt * CLK_X) + Trea[mode]) < Tcea[mode]) |
| 310 | cs_cnt++; |
| 311 | } |
| 312 | |
| 313 | #if MODE5_WORKAROUND |
| 314 | if (mode == 5) |
| 315 | acc_clks = 5; |
| 316 | #endif |
| 317 | |
| 318 | /* Sighting 3462430: Temporary hack for MT29F128G08CJABAWP:B */ |
| 319 | if ((ioread32(denali->flash_reg + MANUFACTURER_ID) == 0) && |
| 320 | (ioread32(denali->flash_reg + DEVICE_ID) == 0x88)) |
| 321 | acc_clks = 6; |
| 322 | |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 323 | iowrite32(acc_clks, denali->flash_reg + ACC_CLKS); |
| 324 | iowrite32(re_2_we, denali->flash_reg + RE_2_WE); |
| 325 | iowrite32(re_2_re, denali->flash_reg + RE_2_RE); |
| 326 | iowrite32(we_2_re, denali->flash_reg + WE_2_RE); |
| 327 | iowrite32(addr_2_data, denali->flash_reg + ADDR_2_DATA); |
| 328 | iowrite32(en_lo, denali->flash_reg + RDWR_EN_LO_CNT); |
| 329 | iowrite32(en_hi, denali->flash_reg + RDWR_EN_HI_CNT); |
| 330 | iowrite32(cs_cnt, denali->flash_reg + CS_SETUP_CNT); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 333 | /* queries the NAND device to see what ONFI modes it supports. */ |
| 334 | static uint16_t get_onfi_nand_para(struct denali_nand_info *denali) |
| 335 | { |
| 336 | int i; |
Chuanxiao Dong | 4c03bbd | 2010-08-06 15:45:19 +0800 | [diff] [blame] | 337 | /* we needn't to do a reset here because driver has already |
| 338 | * reset all the banks before |
| 339 | * */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 340 | if (!(ioread32(denali->flash_reg + ONFI_TIMING_MODE) & |
| 341 | ONFI_TIMING_MODE__VALUE)) |
| 342 | return FAIL; |
| 343 | |
| 344 | for (i = 5; i > 0; i--) { |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 345 | if (ioread32(denali->flash_reg + ONFI_TIMING_MODE) & |
| 346 | (0x01 << i)) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 350 | nand_onfi_timing_set(denali, i); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 351 | |
| 352 | /* By now, all the ONFI devices we know support the page cache */ |
| 353 | /* rw feature. So here we enable the pipeline_rw_ahead feature */ |
| 354 | /* iowrite32(1, denali->flash_reg + CACHE_WRITE_ENABLE); */ |
| 355 | /* iowrite32(1, denali->flash_reg + CACHE_READ_ENABLE); */ |
| 356 | |
| 357 | return PASS; |
| 358 | } |
| 359 | |
Chuanxiao Dong | 4c03bbd | 2010-08-06 15:45:19 +0800 | [diff] [blame] | 360 | static void get_samsung_nand_para(struct denali_nand_info *denali, |
| 361 | uint8_t device_id) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 362 | { |
Chuanxiao Dong | 4c03bbd | 2010-08-06 15:45:19 +0800 | [diff] [blame] | 363 | if (device_id == 0xd3) { /* Samsung K9WAG08U1A */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 364 | /* Set timing register values according to datasheet */ |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 365 | iowrite32(5, denali->flash_reg + ACC_CLKS); |
| 366 | iowrite32(20, denali->flash_reg + RE_2_WE); |
| 367 | iowrite32(12, denali->flash_reg + WE_2_RE); |
| 368 | iowrite32(14, denali->flash_reg + ADDR_2_DATA); |
| 369 | iowrite32(3, denali->flash_reg + RDWR_EN_LO_CNT); |
| 370 | iowrite32(2, denali->flash_reg + RDWR_EN_HI_CNT); |
| 371 | iowrite32(2, denali->flash_reg + CS_SETUP_CNT); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 372 | } |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static void get_toshiba_nand_para(struct denali_nand_info *denali) |
| 376 | { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 377 | uint32_t tmp; |
| 378 | |
| 379 | /* Workaround to fix a controller bug which reports a wrong */ |
| 380 | /* spare area size for some kind of Toshiba NAND device */ |
| 381 | if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) == 4096) && |
| 382 | (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) == 64)) { |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 383 | iowrite32(216, denali->flash_reg + DEVICE_SPARE_AREA_SIZE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 384 | tmp = ioread32(denali->flash_reg + DEVICES_CONNECTED) * |
| 385 | ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE); |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 386 | iowrite32(tmp, |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 387 | denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 388 | #if SUPPORT_15BITECC |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 389 | iowrite32(15, denali->flash_reg + ECC_CORRECTION); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 390 | #elif SUPPORT_8BITECC |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 391 | iowrite32(8, denali->flash_reg + ECC_CORRECTION); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 392 | #endif |
| 393 | } |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 394 | } |
| 395 | |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 396 | static void get_hynix_nand_para(struct denali_nand_info *denali, |
| 397 | uint8_t device_id) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 398 | { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 399 | uint32_t main_size, spare_size; |
| 400 | |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 401 | switch (device_id) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 402 | case 0xD5: /* Hynix H27UAG8T2A, H27UBG8U5A or H27UCG8VFA */ |
| 403 | case 0xD7: /* Hynix H27UDG8VEM, H27UCG8UDM or H27UCG8V5A */ |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 404 | iowrite32(128, denali->flash_reg + PAGES_PER_BLOCK); |
| 405 | iowrite32(4096, denali->flash_reg + DEVICE_MAIN_AREA_SIZE); |
| 406 | iowrite32(224, denali->flash_reg + DEVICE_SPARE_AREA_SIZE); |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 407 | main_size = 4096 * |
| 408 | ioread32(denali->flash_reg + DEVICES_CONNECTED); |
| 409 | spare_size = 224 * |
| 410 | ioread32(denali->flash_reg + DEVICES_CONNECTED); |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 411 | iowrite32(main_size, |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 412 | denali->flash_reg + LOGICAL_PAGE_DATA_SIZE); |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 413 | iowrite32(spare_size, |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 414 | denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE); |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 415 | iowrite32(0, denali->flash_reg + DEVICE_WIDTH); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 416 | #if SUPPORT_15BITECC |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 417 | iowrite32(15, denali->flash_reg + ECC_CORRECTION); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 418 | #elif SUPPORT_8BITECC |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 419 | iowrite32(8, denali->flash_reg + ECC_CORRECTION); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 420 | #endif |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 421 | break; |
| 422 | default: |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 423 | dev_warn(denali->dev, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 424 | "Spectra: Unknown Hynix NAND (Device ID: 0x%x)." |
| 425 | "Will use default parameter values instead.\n", |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 426 | device_id); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | /* determines how many NAND chips are connected to the controller. Note for |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 431 | * Intel CE4100 devices we don't support more than one device. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 432 | */ |
| 433 | static void find_valid_banks(struct denali_nand_info *denali) |
| 434 | { |
| 435 | uint32_t id[LLD_MAX_FLASH_BANKS]; |
| 436 | int i; |
| 437 | |
| 438 | denali->total_used_banks = 1; |
| 439 | for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) { |
| 440 | index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90); |
| 441 | index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0); |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 442 | index_addr_read_data(denali, |
| 443 | (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 444 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 445 | dev_dbg(denali->dev, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 446 | "Return 1st ID for bank[%d]: %x\n", i, id[i]); |
| 447 | |
| 448 | if (i == 0) { |
| 449 | if (!(id[i] & 0x0ff)) |
| 450 | break; /* WTF? */ |
| 451 | } else { |
| 452 | if ((id[i] & 0x0ff) == (id[0] & 0x0ff)) |
| 453 | denali->total_used_banks++; |
| 454 | else |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 459 | if (denali->platform == INTEL_CE4100) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 460 | /* Platform limitations of the CE4100 device limit |
| 461 | * users to a single chip solution for NAND. |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 462 | * Multichip support is not enabled. |
| 463 | */ |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 464 | if (denali->total_used_banks != 1) { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 465 | dev_err(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 466 | "Sorry, Intel CE4100 only supports " |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 467 | "a single NAND device.\n"); |
| 468 | BUG(); |
| 469 | } |
| 470 | } |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 471 | dev_dbg(denali->dev, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 472 | "denali->total_used_banks: %d\n", denali->total_used_banks); |
| 473 | } |
| 474 | |
| 475 | static void detect_partition_feature(struct denali_nand_info *denali) |
| 476 | { |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 477 | /* For MRST platform, denali->fwblks represent the |
| 478 | * number of blocks firmware is taken, |
| 479 | * FW is in protect partition and MTD driver has no |
| 480 | * permission to access it. So let driver know how many |
| 481 | * blocks it can't touch. |
| 482 | * */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 483 | if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) { |
| 484 | if ((ioread32(denali->flash_reg + PERM_SRC_ID_1) & |
| 485 | PERM_SRC_ID_1__SRCID) == SPECTRA_PARTITION_ID) { |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 486 | denali->fwblks = |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 487 | ((ioread32(denali->flash_reg + MIN_MAX_BANK_1) & |
| 488 | MIN_MAX_BANK_1__MIN_VALUE) * |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 489 | denali->blksperchip) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 490 | + |
| 491 | (ioread32(denali->flash_reg + MIN_BLK_ADDR_1) & |
| 492 | MIN_BLK_ADDR_1__VALUE); |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 493 | } else |
| 494 | denali->fwblks = SPECTRA_START_BLOCK; |
| 495 | } else |
| 496 | denali->fwblks = SPECTRA_START_BLOCK; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 499 | static uint16_t denali_nand_timing_set(struct denali_nand_info *denali) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 500 | { |
| 501 | uint16_t status = PASS; |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 502 | uint32_t id_bytes[5], addr; |
| 503 | uint8_t i, maf_id, device_id; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 504 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 505 | dev_dbg(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 506 | "%s, Line %d, Function: %s\n", |
| 507 | __FILE__, __LINE__, __func__); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 508 | |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 509 | /* Use read id method to get device ID and other |
| 510 | * params. For some NAND chips, controller can't |
| 511 | * report the correct device ID by reading from |
| 512 | * DEVICE_ID register |
| 513 | * */ |
| 514 | addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); |
| 515 | index_addr(denali, (uint32_t)addr | 0, 0x90); |
| 516 | index_addr(denali, (uint32_t)addr | 1, 0); |
| 517 | for (i = 0; i < 5; i++) |
| 518 | index_addr_read_data(denali, addr | 2, &id_bytes[i]); |
| 519 | maf_id = id_bytes[0]; |
| 520 | device_id = id_bytes[1]; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 521 | |
| 522 | if (ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_LUNS) & |
| 523 | ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE) { /* ONFI 1.0 NAND */ |
| 524 | if (FAIL == get_onfi_nand_para(denali)) |
| 525 | return FAIL; |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 526 | } else if (maf_id == 0xEC) { /* Samsung NAND */ |
Chuanxiao Dong | 4c03bbd | 2010-08-06 15:45:19 +0800 | [diff] [blame] | 527 | get_samsung_nand_para(denali, device_id); |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 528 | } else if (maf_id == 0x98) { /* Toshiba NAND */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 529 | get_toshiba_nand_para(denali); |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 530 | } else if (maf_id == 0xAD) { /* Hynix NAND */ |
| 531 | get_hynix_nand_para(denali, device_id); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 534 | dev_info(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 535 | "Dump timing register values:" |
| 536 | "acc_clks: %d, re_2_we: %d, re_2_re: %d\n" |
| 537 | "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n" |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 538 | "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n", |
| 539 | ioread32(denali->flash_reg + ACC_CLKS), |
| 540 | ioread32(denali->flash_reg + RE_2_WE), |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 541 | ioread32(denali->flash_reg + RE_2_RE), |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 542 | ioread32(denali->flash_reg + WE_2_RE), |
| 543 | ioread32(denali->flash_reg + ADDR_2_DATA), |
| 544 | ioread32(denali->flash_reg + RDWR_EN_LO_CNT), |
| 545 | ioread32(denali->flash_reg + RDWR_EN_HI_CNT), |
| 546 | ioread32(denali->flash_reg + CS_SETUP_CNT)); |
| 547 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 548 | find_valid_banks(denali); |
| 549 | |
| 550 | detect_partition_feature(denali); |
| 551 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 552 | /* If the user specified to override the default timings |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 553 | * with a specific ONFI mode, we apply those changes here. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 554 | */ |
| 555 | if (onfi_timing_mode != NAND_DEFAULT_TIMINGS) |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 556 | nand_onfi_timing_set(denali, onfi_timing_mode); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 557 | |
| 558 | return status; |
| 559 | } |
| 560 | |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 561 | static void denali_set_intr_modes(struct denali_nand_info *denali, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 562 | uint16_t INT_ENABLE) |
| 563 | { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 564 | dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 565 | __FILE__, __LINE__, __func__); |
| 566 | |
| 567 | if (INT_ENABLE) |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 568 | iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 569 | else |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 570 | iowrite32(0, denali->flash_reg + GLOBAL_INT_ENABLE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* validation function to verify that the controlling software is making |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 574 | * a valid request |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 575 | */ |
| 576 | static inline bool is_flash_bank_valid(int flash_bank) |
| 577 | { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 578 | return (flash_bank >= 0 && flash_bank < 4); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void denali_irq_init(struct denali_nand_info *denali) |
| 582 | { |
| 583 | uint32_t int_mask = 0; |
| 584 | |
| 585 | /* Disable global interrupts */ |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 586 | denali_set_intr_modes(denali, false); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 587 | |
| 588 | int_mask = DENALI_IRQ_ALL; |
| 589 | |
| 590 | /* Clear all status bits */ |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 591 | iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS0); |
| 592 | iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS1); |
| 593 | iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS2); |
| 594 | iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS3); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 595 | |
| 596 | denali_irq_enable(denali, int_mask); |
| 597 | } |
| 598 | |
| 599 | static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali) |
| 600 | { |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 601 | denali_set_intr_modes(denali, false); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 602 | free_irq(irqnum, denali); |
| 603 | } |
| 604 | |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 605 | static void denali_irq_enable(struct denali_nand_info *denali, |
| 606 | uint32_t int_mask) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 607 | { |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 608 | iowrite32(int_mask, denali->flash_reg + INTR_EN0); |
| 609 | iowrite32(int_mask, denali->flash_reg + INTR_EN1); |
| 610 | iowrite32(int_mask, denali->flash_reg + INTR_EN2); |
| 611 | iowrite32(int_mask, denali->flash_reg + INTR_EN3); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /* This function only returns when an interrupt that this driver cares about |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 615 | * occurs. This is to reduce the overhead of servicing interrupts |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 616 | */ |
| 617 | static inline uint32_t denali_irq_detected(struct denali_nand_info *denali) |
| 618 | { |
Chuanxiao Dong | a99d179 | 2010-07-27 11:32:21 +0800 | [diff] [blame] | 619 | return read_interrupt_status(denali) & DENALI_IRQ_ALL; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /* Interrupts are cleared by writing a 1 to the appropriate status bit */ |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 623 | static inline void clear_interrupt(struct denali_nand_info *denali, |
| 624 | uint32_t irq_mask) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 625 | { |
| 626 | uint32_t intr_status_reg = 0; |
| 627 | |
| 628 | intr_status_reg = intr_status_addresses[denali->flash_bank]; |
| 629 | |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 630 | iowrite32(irq_mask, denali->flash_reg + intr_status_reg); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static void clear_interrupts(struct denali_nand_info *denali) |
| 634 | { |
| 635 | uint32_t status = 0x0; |
| 636 | spin_lock_irq(&denali->irq_lock); |
| 637 | |
| 638 | status = read_interrupt_status(denali); |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 639 | clear_interrupt(denali, status); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 640 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 641 | denali->irq_status = 0x0; |
| 642 | spin_unlock_irq(&denali->irq_lock); |
| 643 | } |
| 644 | |
| 645 | static uint32_t read_interrupt_status(struct denali_nand_info *denali) |
| 646 | { |
| 647 | uint32_t intr_status_reg = 0; |
| 648 | |
| 649 | intr_status_reg = intr_status_addresses[denali->flash_bank]; |
| 650 | |
| 651 | return ioread32(denali->flash_reg + intr_status_reg); |
| 652 | } |
| 653 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 654 | /* This is the interrupt service routine. It handles all interrupts |
| 655 | * sent to this device. Note that on CE4100, this is a shared |
| 656 | * interrupt. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 657 | */ |
| 658 | static irqreturn_t denali_isr(int irq, void *dev_id) |
| 659 | { |
| 660 | struct denali_nand_info *denali = dev_id; |
| 661 | uint32_t irq_status = 0x0; |
| 662 | irqreturn_t result = IRQ_NONE; |
| 663 | |
| 664 | spin_lock(&denali->irq_lock); |
| 665 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 666 | /* check to see if a valid NAND chip has |
| 667 | * been selected. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 668 | */ |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 669 | if (is_flash_bank_valid(denali->flash_bank)) { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 670 | /* check to see if controller generated |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 671 | * the interrupt, since this is a shared interrupt */ |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 672 | irq_status = denali_irq_detected(denali); |
| 673 | if (irq_status != 0) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 674 | /* handle interrupt */ |
| 675 | /* first acknowledge it */ |
| 676 | clear_interrupt(denali, irq_status); |
| 677 | /* store the status in the device context for someone |
| 678 | to read */ |
| 679 | denali->irq_status |= irq_status; |
| 680 | /* notify anyone who cares that it happened */ |
| 681 | complete(&denali->complete); |
| 682 | /* tell the OS that we've handled this */ |
| 683 | result = IRQ_HANDLED; |
| 684 | } |
| 685 | } |
| 686 | spin_unlock(&denali->irq_lock); |
| 687 | return result; |
| 688 | } |
| 689 | #define BANK(x) ((x) << 24) |
| 690 | |
| 691 | static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask) |
| 692 | { |
| 693 | unsigned long comp_res = 0; |
| 694 | uint32_t intr_status = 0; |
| 695 | bool retry = false; |
| 696 | unsigned long timeout = msecs_to_jiffies(1000); |
| 697 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 698 | do { |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 699 | comp_res = |
| 700 | wait_for_completion_timeout(&denali->complete, timeout); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 701 | spin_lock_irq(&denali->irq_lock); |
| 702 | intr_status = denali->irq_status; |
| 703 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 704 | if (intr_status & irq_mask) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 705 | denali->irq_status &= ~irq_mask; |
| 706 | spin_unlock_irq(&denali->irq_lock); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 707 | /* our interrupt was detected */ |
| 708 | break; |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 709 | } else { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 710 | /* these are not the interrupts you are looking for - |
| 711 | * need to wait again */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 712 | spin_unlock_irq(&denali->irq_lock); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 713 | retry = true; |
| 714 | } |
| 715 | } while (comp_res != 0); |
| 716 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 717 | if (comp_res == 0) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 718 | /* timeout */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 719 | printk(KERN_ERR "timeout occurred, status = 0x%x, mask = 0x%x\n", |
| 720 | intr_status, irq_mask); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 721 | |
| 722 | intr_status = 0; |
| 723 | } |
| 724 | return intr_status; |
| 725 | } |
| 726 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 727 | /* This helper function setups the registers for ECC and whether or not |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 728 | * the spare area will be transferred. */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 729 | static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 730 | bool transfer_spare) |
| 731 | { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 732 | int ecc_en_flag = 0, transfer_spare_flag = 0; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 733 | |
| 734 | /* set ECC, transfer spare bits if needed */ |
| 735 | ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0; |
| 736 | transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0; |
| 737 | |
| 738 | /* Enable spare area/ECC per user's request. */ |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 739 | iowrite32(ecc_en_flag, denali->flash_reg + ECC_ENABLE); |
| 740 | iowrite32(transfer_spare_flag, |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 741 | denali->flash_reg + TRANSFER_SPARE_REG); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 744 | /* sends a pipeline command operation to the controller. See the Denali NAND |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 745 | * controller's user guide for more information (section 4.2.3.6). |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 746 | */ |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 747 | static int denali_send_pipeline_cmd(struct denali_nand_info *denali, |
| 748 | bool ecc_en, |
| 749 | bool transfer_spare, |
| 750 | int access_type, |
| 751 | int op) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 752 | { |
| 753 | int status = PASS; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 754 | uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 755 | irq_mask = 0; |
| 756 | |
Chuanxiao Dong | a99d179 | 2010-07-27 11:32:21 +0800 | [diff] [blame] | 757 | if (op == DENALI_READ) |
| 758 | irq_mask = INTR_STATUS0__LOAD_COMP; |
| 759 | else if (op == DENALI_WRITE) |
| 760 | irq_mask = 0; |
| 761 | else |
| 762 | BUG(); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 763 | |
| 764 | setup_ecc_for_xfer(denali, ecc_en, transfer_spare); |
| 765 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 766 | /* clear interrupts */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 767 | clear_interrupts(denali); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 768 | |
| 769 | addr = BANK(denali->flash_bank) | denali->page; |
| 770 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 771 | if (op == DENALI_WRITE && access_type != SPARE_ACCESS) { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 772 | cmd = MODE_01 | addr; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 773 | iowrite32(cmd, denali->flash_mem); |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 774 | } else if (op == DENALI_WRITE && access_type == SPARE_ACCESS) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 775 | /* read spare area */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 776 | cmd = MODE_10 | addr; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 777 | index_addr(denali, (uint32_t)cmd, access_type); |
| 778 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 779 | cmd = MODE_01 | addr; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 780 | iowrite32(cmd, denali->flash_mem); |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 781 | } else if (op == DENALI_READ) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 782 | /* setup page read request for access type */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 783 | cmd = MODE_10 | addr; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 784 | index_addr(denali, (uint32_t)cmd, access_type); |
| 785 | |
| 786 | /* page 33 of the NAND controller spec indicates we should not |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 787 | use the pipeline commands in Spare area only mode. So we |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 788 | don't. |
| 789 | */ |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 790 | if (access_type == SPARE_ACCESS) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 791 | cmd = MODE_01 | addr; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 792 | iowrite32(cmd, denali->flash_mem); |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 793 | } else { |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 794 | index_addr(denali, (uint32_t)cmd, |
| 795 | 0x2000 | op | page_count); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 796 | |
| 797 | /* wait for command to be accepted |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 798 | * can always use status0 bit as the |
| 799 | * mask is identical for each |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 800 | * bank. */ |
| 801 | irq_status = wait_for_irq(denali, irq_mask); |
| 802 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 803 | if (irq_status == 0) { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 804 | dev_err(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 805 | "cmd, page, addr on timeout " |
| 806 | "(0x%x, 0x%x, 0x%x)\n", |
| 807 | cmd, denali->page, addr); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 808 | status = FAIL; |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 809 | } else { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 810 | cmd = MODE_01 | addr; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 811 | iowrite32(cmd, denali->flash_mem); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | } |
| 815 | return status; |
| 816 | } |
| 817 | |
| 818 | /* helper function that simply writes a buffer to the flash */ |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 819 | static int write_data_to_flash_mem(struct denali_nand_info *denali, |
| 820 | const uint8_t *buf, |
| 821 | int len) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 822 | { |
| 823 | uint32_t i = 0, *buf32; |
| 824 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 825 | /* verify that the len is a multiple of 4. see comment in |
| 826 | * read_data_from_flash_mem() */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 827 | BUG_ON((len % 4) != 0); |
| 828 | |
| 829 | /* write the data to the flash memory */ |
| 830 | buf32 = (uint32_t *)buf; |
| 831 | for (i = 0; i < len / 4; i++) |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 832 | iowrite32(*buf32++, denali->flash_mem + 0x10); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 833 | return i*4; /* intent is to return the number of bytes read */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /* helper function that simply reads a buffer from the flash */ |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 837 | static int read_data_from_flash_mem(struct denali_nand_info *denali, |
| 838 | uint8_t *buf, |
| 839 | int len) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 840 | { |
| 841 | uint32_t i = 0, *buf32; |
| 842 | |
| 843 | /* we assume that len will be a multiple of 4, if not |
| 844 | * it would be nice to know about it ASAP rather than |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 845 | * have random failures... |
| 846 | * This assumption is based on the fact that this |
| 847 | * function is designed to be used to read flash pages, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 848 | * which are typically multiples of 4... |
| 849 | */ |
| 850 | |
| 851 | BUG_ON((len % 4) != 0); |
| 852 | |
| 853 | /* transfer the data from the flash */ |
| 854 | buf32 = (uint32_t *)buf; |
| 855 | for (i = 0; i < len / 4; i++) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 856 | *buf32++ = ioread32(denali->flash_mem + 0x10); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 857 | return i*4; /* intent is to return the number of bytes read */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* writes OOB data to the device */ |
| 861 | static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) |
| 862 | { |
| 863 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
| 864 | uint32_t irq_status = 0; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 865 | uint32_t irq_mask = INTR_STATUS0__PROGRAM_COMP | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 866 | INTR_STATUS0__PROGRAM_FAIL; |
| 867 | int status = 0; |
| 868 | |
| 869 | denali->page = page; |
| 870 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 871 | if (denali_send_pipeline_cmd(denali, false, false, SPARE_ACCESS, |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 872 | DENALI_WRITE) == PASS) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 873 | write_data_to_flash_mem(denali, buf, mtd->oobsize); |
| 874 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 875 | /* wait for operation to complete */ |
| 876 | irq_status = wait_for_irq(denali, irq_mask); |
| 877 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 878 | if (irq_status == 0) { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 879 | dev_err(denali->dev, "OOB write failed\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 880 | status = -EIO; |
| 881 | } |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 882 | } else { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 883 | dev_err(denali->dev, "unable to send pipeline command\n"); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 884 | status = -EIO; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 885 | } |
| 886 | return status; |
| 887 | } |
| 888 | |
| 889 | /* reads OOB data from the device */ |
| 890 | static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) |
| 891 | { |
| 892 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 893 | uint32_t irq_mask = INTR_STATUS0__LOAD_COMP, |
| 894 | irq_status = 0, addr = 0x0, cmd = 0x0; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 895 | |
| 896 | denali->page = page; |
| 897 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 898 | if (denali_send_pipeline_cmd(denali, false, true, SPARE_ACCESS, |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 899 | DENALI_READ) == PASS) { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 900 | read_data_from_flash_mem(denali, buf, mtd->oobsize); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 901 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 902 | /* wait for command to be accepted |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 903 | * can always use status0 bit as the mask is identical for each |
| 904 | * bank. */ |
| 905 | irq_status = wait_for_irq(denali, irq_mask); |
| 906 | |
| 907 | if (irq_status == 0) |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 908 | dev_err(denali->dev, "page on OOB timeout %d\n", |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 909 | denali->page); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 910 | |
| 911 | /* We set the device back to MAIN_ACCESS here as I observed |
| 912 | * instability with the controller if you do a block erase |
| 913 | * and the last transaction was a SPARE_ACCESS. Block erase |
| 914 | * is reliable (according to the MTD test infrastructure) |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 915 | * if you are in MAIN_ACCESS. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 916 | */ |
| 917 | addr = BANK(denali->flash_bank) | denali->page; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 918 | cmd = MODE_10 | addr; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 919 | index_addr(denali, (uint32_t)cmd, MAIN_ACCESS); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 923 | /* this function examines buffers to see if they contain data that |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 924 | * indicate that the buffer is part of an erased region of flash. |
| 925 | */ |
| 926 | bool is_erased(uint8_t *buf, int len) |
| 927 | { |
| 928 | int i = 0; |
| 929 | for (i = 0; i < len; i++) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 930 | if (buf[i] != 0xFF) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 931 | return false; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 932 | return true; |
| 933 | } |
| 934 | #define ECC_SECTOR_SIZE 512 |
| 935 | |
| 936 | #define ECC_SECTOR(x) (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12) |
| 937 | #define ECC_BYTE(x) (((x) & ECC_ERROR_ADDRESS__OFFSET)) |
| 938 | #define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK) |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 939 | #define ECC_ERROR_CORRECTABLE(x) (!((x) & ERR_CORRECTION_INFO__ERROR_TYPE)) |
| 940 | #define ECC_ERR_DEVICE(x) (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 941 | #define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO) |
| 942 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 943 | static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 944 | uint32_t irq_status) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 945 | { |
| 946 | bool check_erased_page = false; |
| 947 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 948 | if (irq_status & INTR_STATUS0__ECC_ERR) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 949 | /* read the ECC errors. we'll ignore them for now */ |
| 950 | uint32_t err_address = 0, err_correction_info = 0; |
| 951 | uint32_t err_byte = 0, err_sector = 0, err_device = 0; |
| 952 | uint32_t err_correction_value = 0; |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 953 | denali_set_intr_modes(denali, false); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 954 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 955 | do { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 956 | err_address = ioread32(denali->flash_reg + |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 957 | ECC_ERROR_ADDRESS); |
| 958 | err_sector = ECC_SECTOR(err_address); |
| 959 | err_byte = ECC_BYTE(err_address); |
| 960 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 961 | err_correction_info = ioread32(denali->flash_reg + |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 962 | ERR_CORRECTION_INFO); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 963 | err_correction_value = |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 964 | ECC_CORRECTION_VALUE(err_correction_info); |
| 965 | err_device = ECC_ERR_DEVICE(err_correction_info); |
| 966 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 967 | if (ECC_ERROR_CORRECTABLE(err_correction_info)) { |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 968 | /* If err_byte is larger than ECC_SECTOR_SIZE, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 969 | * means error happened in OOB, so we ignore |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 970 | * it. It's no need for us to correct it |
| 971 | * err_device is represented the NAND error |
| 972 | * bits are happened in if there are more |
| 973 | * than one NAND connected. |
| 974 | * */ |
| 975 | if (err_byte < ECC_SECTOR_SIZE) { |
| 976 | int offset; |
| 977 | offset = (err_sector * |
| 978 | ECC_SECTOR_SIZE + |
| 979 | err_byte) * |
| 980 | denali->devnum + |
| 981 | err_device; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 982 | /* correct the ECC error */ |
| 983 | buf[offset] ^= err_correction_value; |
| 984 | denali->mtd.ecc_stats.corrected++; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 985 | } |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 986 | } else { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 987 | /* if the error is not correctable, need to |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 988 | * look at the page to see if it is an erased |
| 989 | * page. if so, then it's not a real ECC error |
| 990 | * */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 991 | check_erased_page = true; |
| 992 | } |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 993 | } while (!ECC_LAST_ERR(err_correction_info)); |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 994 | /* Once handle all ecc errors, controller will triger |
| 995 | * a ECC_TRANSACTION_DONE interrupt, so here just wait |
| 996 | * for a while for this interrupt |
| 997 | * */ |
| 998 | while (!(read_interrupt_status(denali) & |
| 999 | INTR_STATUS0__ECC_TRANSACTION_DONE)) |
| 1000 | cpu_relax(); |
| 1001 | clear_interrupts(denali); |
| 1002 | denali_set_intr_modes(denali, true); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1003 | } |
| 1004 | return check_erased_page; |
| 1005 | } |
| 1006 | |
| 1007 | /* programs the controller to either enable/disable DMA transfers */ |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1008 | static void denali_enable_dma(struct denali_nand_info *denali, bool en) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1009 | { |
| 1010 | uint32_t reg_val = 0x0; |
| 1011 | |
Chuanxiao Dong | a99d179 | 2010-07-27 11:32:21 +0800 | [diff] [blame] | 1012 | if (en) |
| 1013 | reg_val = DMA_ENABLE__FLAG; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1014 | |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 1015 | iowrite32(reg_val, denali->flash_reg + DMA_ENABLE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1016 | ioread32(denali->flash_reg + DMA_ENABLE); |
| 1017 | } |
| 1018 | |
| 1019 | /* setups the HW to perform the data DMA */ |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1020 | static void denali_setup_dma(struct denali_nand_info *denali, int op) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1021 | { |
| 1022 | uint32_t mode = 0x0; |
| 1023 | const int page_count = 1; |
| 1024 | dma_addr_t addr = denali->buf.dma_buf; |
| 1025 | |
| 1026 | mode = MODE_10 | BANK(denali->flash_bank); |
| 1027 | |
| 1028 | /* DMA is a four step process */ |
| 1029 | |
| 1030 | /* 1. setup transfer type and # of pages */ |
| 1031 | index_addr(denali, mode | denali->page, 0x2000 | op | page_count); |
| 1032 | |
| 1033 | /* 2. set memory high address bits 23:8 */ |
| 1034 | index_addr(denali, mode | ((uint16_t)(addr >> 16) << 8), 0x2200); |
| 1035 | |
| 1036 | /* 3. set memory low address bits 23:8 */ |
| 1037 | index_addr(denali, mode | ((uint16_t)addr << 8), 0x2300); |
| 1038 | |
| 1039 | /* 4. interrupt when complete, burst len = 64 bytes*/ |
| 1040 | index_addr(denali, mode | 0x14000, 0x2400); |
| 1041 | } |
| 1042 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1043 | /* writes a page. user specifies type, and this function handles the |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 1044 | * configuration details. */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1045 | static void write_page(struct mtd_info *mtd, struct nand_chip *chip, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1046 | const uint8_t *buf, bool raw_xfer) |
| 1047 | { |
| 1048 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1049 | |
| 1050 | dma_addr_t addr = denali->buf.dma_buf; |
| 1051 | size_t size = denali->mtd.writesize + denali->mtd.oobsize; |
| 1052 | |
| 1053 | uint32_t irq_status = 0; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1054 | uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1055 | INTR_STATUS0__PROGRAM_FAIL; |
| 1056 | |
| 1057 | /* if it is a raw xfer, we want to disable ecc, and send |
| 1058 | * the spare area. |
| 1059 | * !raw_xfer - enable ecc |
| 1060 | * raw_xfer - transfer spare |
| 1061 | */ |
| 1062 | setup_ecc_for_xfer(denali, !raw_xfer, raw_xfer); |
| 1063 | |
| 1064 | /* copy buffer into DMA buffer */ |
| 1065 | memcpy(denali->buf.buf, buf, mtd->writesize); |
| 1066 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1067 | if (raw_xfer) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1068 | /* transfer the data to the spare area */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1069 | memcpy(denali->buf.buf + mtd->writesize, |
| 1070 | chip->oob_poi, |
| 1071 | mtd->oobsize); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1074 | dma_sync_single_for_device(denali->dev, addr, size, DMA_TO_DEVICE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1075 | |
| 1076 | clear_interrupts(denali); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1077 | denali_enable_dma(denali, true); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1078 | |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1079 | denali_setup_dma(denali, DENALI_WRITE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1080 | |
| 1081 | /* wait for operation to complete */ |
| 1082 | irq_status = wait_for_irq(denali, irq_mask); |
| 1083 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1084 | if (irq_status == 0) { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1085 | dev_err(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1086 | "timeout on write_page (type = %d)\n", |
| 1087 | raw_xfer); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1088 | denali->status = |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 1089 | (irq_status & INTR_STATUS0__PROGRAM_FAIL) ? |
| 1090 | NAND_STATUS_FAIL : PASS; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1093 | denali_enable_dma(denali, false); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1094 | dma_sync_single_for_cpu(denali->dev, addr, size, DMA_TO_DEVICE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /* NAND core entry points */ |
| 1098 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1099 | /* this is the callback that the NAND core calls to write a page. Since |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 1100 | * writing a page with ECC or without is similar, all the work is done |
| 1101 | * by write_page above. |
| 1102 | * */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1103 | static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1104 | const uint8_t *buf) |
| 1105 | { |
| 1106 | /* for regular page writes, we let HW handle all the ECC |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1107 | * data written to the device. */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1108 | write_page(mtd, chip, buf, false); |
| 1109 | } |
| 1110 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1111 | /* This is the callback that the NAND core calls to write a page without ECC. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1112 | * raw access is similar to ECC page writes, so all the work is done in the |
Chuanxiao Dong | b292c34 | 2010-08-11 17:46:00 +0800 | [diff] [blame] | 1113 | * write_page() function above. |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1114 | */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1115 | static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1116 | const uint8_t *buf) |
| 1117 | { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1118 | /* for raw page writes, we want to disable ECC and simply write |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1119 | whatever data is in the buffer. */ |
| 1120 | write_page(mtd, chip, buf, true); |
| 1121 | } |
| 1122 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1123 | static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1124 | int page) |
| 1125 | { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1126 | return write_oob_data(mtd, chip->oob_poi, page); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1129 | static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1130 | int page, int sndcmd) |
| 1131 | { |
| 1132 | read_oob_data(mtd, chip->oob_poi, page); |
| 1133 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1134 | return 0; /* notify NAND core to send command to |
| 1135 | NAND device. */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, |
| 1139 | uint8_t *buf, int page) |
| 1140 | { |
| 1141 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1142 | |
| 1143 | dma_addr_t addr = denali->buf.dma_buf; |
| 1144 | size_t size = denali->mtd.writesize + denali->mtd.oobsize; |
| 1145 | |
| 1146 | uint32_t irq_status = 0; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1147 | uint32_t irq_mask = INTR_STATUS0__ECC_TRANSACTION_DONE | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1148 | INTR_STATUS0__ECC_ERR; |
| 1149 | bool check_erased_page = false; |
| 1150 | |
Chuanxiao Dong | 7d8a26f | 2010-08-11 18:19:23 +0800 | [diff] [blame] | 1151 | if (page != denali->page) { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1152 | dev_err(denali->dev, "IN %s: page %d is not" |
Chuanxiao Dong | 7d8a26f | 2010-08-11 18:19:23 +0800 | [diff] [blame] | 1153 | " equal to denali->page %d, investigate!!", |
| 1154 | __func__, page, denali->page); |
| 1155 | BUG(); |
| 1156 | } |
| 1157 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1158 | setup_ecc_for_xfer(denali, true, false); |
| 1159 | |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1160 | denali_enable_dma(denali, true); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1161 | dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1162 | |
| 1163 | clear_interrupts(denali); |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1164 | denali_setup_dma(denali, DENALI_READ); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1165 | |
| 1166 | /* wait for operation to complete */ |
| 1167 | irq_status = wait_for_irq(denali, irq_mask); |
| 1168 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1169 | dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1170 | |
| 1171 | memcpy(buf, denali->buf.buf, mtd->writesize); |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1172 | |
Chuanxiao Dong | 8ae61eb | 2010-08-10 00:07:01 +0800 | [diff] [blame] | 1173 | check_erased_page = handle_ecc(denali, buf, irq_status); |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1174 | denali_enable_dma(denali, false); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1175 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1176 | if (check_erased_page) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1177 | read_oob_data(&denali->mtd, chip->oob_poi, denali->page); |
| 1178 | |
| 1179 | /* check ECC failures that may have occurred on erased pages */ |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1180 | if (check_erased_page) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1181 | if (!is_erased(buf, denali->mtd.writesize)) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1182 | denali->mtd.ecc_stats.failed++; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1183 | if (!is_erased(buf, denali->mtd.oobsize)) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1184 | denali->mtd.ecc_stats.failed++; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1185 | } |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1186 | } |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, |
| 1191 | uint8_t *buf, int page) |
| 1192 | { |
| 1193 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1194 | |
| 1195 | dma_addr_t addr = denali->buf.dma_buf; |
| 1196 | size_t size = denali->mtd.writesize + denali->mtd.oobsize; |
| 1197 | |
| 1198 | uint32_t irq_status = 0; |
| 1199 | uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP; |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1200 | |
Chuanxiao Dong | 7d8a26f | 2010-08-11 18:19:23 +0800 | [diff] [blame] | 1201 | if (page != denali->page) { |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1202 | dev_err(denali->dev, "IN %s: page %d is not" |
Chuanxiao Dong | 7d8a26f | 2010-08-11 18:19:23 +0800 | [diff] [blame] | 1203 | " equal to denali->page %d, investigate!!", |
| 1204 | __func__, page, denali->page); |
| 1205 | BUG(); |
| 1206 | } |
| 1207 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1208 | setup_ecc_for_xfer(denali, false, true); |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1209 | denali_enable_dma(denali, true); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1210 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1211 | dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1212 | |
| 1213 | clear_interrupts(denali); |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1214 | denali_setup_dma(denali, DENALI_READ); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1215 | |
| 1216 | /* wait for operation to complete */ |
| 1217 | irq_status = wait_for_irq(denali, irq_mask); |
| 1218 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1219 | dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1220 | |
David Woodhouse | aadff49 | 2010-05-13 16:12:43 +0100 | [diff] [blame] | 1221 | denali_enable_dma(denali, false); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1222 | |
| 1223 | memcpy(buf, denali->buf.buf, mtd->writesize); |
| 1224 | memcpy(chip->oob_poi, denali->buf.buf + mtd->writesize, mtd->oobsize); |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | static uint8_t denali_read_byte(struct mtd_info *mtd) |
| 1230 | { |
| 1231 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
| 1232 | uint8_t result = 0xff; |
| 1233 | |
| 1234 | if (denali->buf.head < denali->buf.tail) |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1235 | result = denali->buf.buf[denali->buf.head++]; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1236 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1237 | return result; |
| 1238 | } |
| 1239 | |
| 1240 | static void denali_select_chip(struct mtd_info *mtd, int chip) |
| 1241 | { |
| 1242 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1243 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1244 | spin_lock_irq(&denali->irq_lock); |
| 1245 | denali->flash_bank = chip; |
| 1246 | spin_unlock_irq(&denali->irq_lock); |
| 1247 | } |
| 1248 | |
| 1249 | static int denali_waitfunc(struct mtd_info *mtd, struct nand_chip *chip) |
| 1250 | { |
| 1251 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
| 1252 | int status = denali->status; |
| 1253 | denali->status = 0; |
| 1254 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1255 | return status; |
| 1256 | } |
| 1257 | |
| 1258 | static void denali_erase(struct mtd_info *mtd, int page) |
| 1259 | { |
| 1260 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
| 1261 | |
| 1262 | uint32_t cmd = 0x0, irq_status = 0; |
| 1263 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1264 | /* clear interrupts */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1265 | clear_interrupts(denali); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1266 | |
| 1267 | /* setup page read request for access type */ |
| 1268 | cmd = MODE_10 | BANK(denali->flash_bank) | page; |
| 1269 | index_addr(denali, (uint32_t)cmd, 0x1); |
| 1270 | |
| 1271 | /* wait for erase to complete or failure to occur */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1272 | irq_status = wait_for_irq(denali, INTR_STATUS0__ERASE_COMP | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1273 | INTR_STATUS0__ERASE_FAIL); |
| 1274 | |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 1275 | denali->status = (irq_status & INTR_STATUS0__ERASE_FAIL) ? |
| 1276 | NAND_STATUS_FAIL : PASS; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1279 | static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1280 | int page) |
| 1281 | { |
| 1282 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 1283 | uint32_t addr, id; |
| 1284 | int i; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1285 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1286 | switch (cmd) { |
Chuanxiao Dong | a99d179 | 2010-07-27 11:32:21 +0800 | [diff] [blame] | 1287 | case NAND_CMD_PAGEPROG: |
| 1288 | break; |
| 1289 | case NAND_CMD_STATUS: |
| 1290 | read_status(denali); |
| 1291 | break; |
| 1292 | case NAND_CMD_READID: |
Florian Fainelli | 42af8b5 | 2010-08-30 18:32:20 +0200 | [diff] [blame] | 1293 | case NAND_CMD_PARAM: |
Chuanxiao Dong | a99d179 | 2010-07-27 11:32:21 +0800 | [diff] [blame] | 1294 | reset_buf(denali); |
Chuanxiao Dong | ef41e1b | 2010-08-06 00:48:49 +0800 | [diff] [blame] | 1295 | /*sometimes ManufactureId read from register is not right |
| 1296 | * e.g. some of Micron MT29F32G08QAA MLC NAND chips |
| 1297 | * So here we send READID cmd to NAND insteand |
| 1298 | * */ |
| 1299 | addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); |
| 1300 | index_addr(denali, (uint32_t)addr | 0, 0x90); |
| 1301 | index_addr(denali, (uint32_t)addr | 1, 0); |
| 1302 | for (i = 0; i < 5; i++) { |
| 1303 | index_addr_read_data(denali, |
| 1304 | (uint32_t)addr | 2, |
| 1305 | &id); |
| 1306 | write_byte_to_buf(denali, id); |
Chuanxiao Dong | a99d179 | 2010-07-27 11:32:21 +0800 | [diff] [blame] | 1307 | } |
| 1308 | break; |
| 1309 | case NAND_CMD_READ0: |
| 1310 | case NAND_CMD_SEQIN: |
| 1311 | denali->page = page; |
| 1312 | break; |
| 1313 | case NAND_CMD_RESET: |
| 1314 | reset_bank(denali); |
| 1315 | break; |
| 1316 | case NAND_CMD_READOOB: |
| 1317 | /* TODO: Read OOB data */ |
| 1318 | break; |
| 1319 | default: |
| 1320 | printk(KERN_ERR ": unsupported command" |
| 1321 | " received 0x%x\n", cmd); |
| 1322 | break; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | /* stubs for ECC functions not used by the NAND core */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1327 | static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1328 | uint8_t *ecc_code) |
| 1329 | { |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1330 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1331 | dev_err(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1332 | "denali_ecc_calculate called unexpectedly\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1333 | BUG(); |
| 1334 | return -EIO; |
| 1335 | } |
| 1336 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1337 | static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1338 | uint8_t *read_ecc, uint8_t *calc_ecc) |
| 1339 | { |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1340 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1341 | dev_err(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1342 | "denali_ecc_correct called unexpectedly\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1343 | BUG(); |
| 1344 | return -EIO; |
| 1345 | } |
| 1346 | |
| 1347 | static void denali_ecc_hwctl(struct mtd_info *mtd, int mode) |
| 1348 | { |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1349 | struct denali_nand_info *denali = mtd_to_denali(mtd); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1350 | dev_err(denali->dev, |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1351 | "denali_ecc_hwctl called unexpectedly\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1352 | BUG(); |
| 1353 | } |
| 1354 | /* end NAND core entry points */ |
| 1355 | |
| 1356 | /* Initialization code to bring the device up to a known good state */ |
| 1357 | static void denali_hw_init(struct denali_nand_info *denali) |
| 1358 | { |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1359 | /* tell driver how many bit controller will skip before |
| 1360 | * writing ECC code in OOB, this register may be already |
| 1361 | * set by firmware. So we read this value out. |
| 1362 | * if this value is 0, just let it be. |
| 1363 | * */ |
| 1364 | denali->bbtskipbytes = ioread32(denali->flash_reg + |
| 1365 | SPARE_AREA_SKIP_BYTES); |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 1366 | denali_nand_reset(denali); |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 1367 | iowrite32(0x0F, denali->flash_reg + RB_PIN_ENABLED); |
| 1368 | iowrite32(CHIP_EN_DONT_CARE__FLAG, |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 1369 | denali->flash_reg + CHIP_ENABLE_DONT_CARE); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1370 | |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 1371 | iowrite32(0xffff, denali->flash_reg + SPARE_AREA_MARKER); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1372 | |
| 1373 | /* Should set value for these registers when init */ |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 1374 | iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES); |
| 1375 | iowrite32(1, denali->flash_reg + ECC_ENABLE); |
Chuanxiao Dong | 5eab6aaa | 2010-08-12 10:07:18 +0800 | [diff] [blame] | 1376 | denali_nand_timing_set(denali); |
| 1377 | denali_irq_init(denali); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1378 | } |
| 1379 | |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1380 | /* Althogh controller spec said SLC ECC is forceb to be 4bit, |
| 1381 | * but denali controller in MRST only support 15bit and 8bit ECC |
| 1382 | * correction |
| 1383 | * */ |
| 1384 | #define ECC_8BITS 14 |
| 1385 | static struct nand_ecclayout nand_8bit_oob = { |
| 1386 | .eccbytes = 14, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1387 | }; |
| 1388 | |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1389 | #define ECC_15BITS 26 |
| 1390 | static struct nand_ecclayout nand_15bit_oob = { |
| 1391 | .eccbytes = 26, |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1392 | }; |
| 1393 | |
| 1394 | static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; |
| 1395 | static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; |
| 1396 | |
| 1397 | static struct nand_bbt_descr bbt_main_descr = { |
| 1398 | .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
| 1399 | | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, |
| 1400 | .offs = 8, |
| 1401 | .len = 4, |
| 1402 | .veroffs = 12, |
| 1403 | .maxblocks = 4, |
| 1404 | .pattern = bbt_pattern, |
| 1405 | }; |
| 1406 | |
| 1407 | static struct nand_bbt_descr bbt_mirror_descr = { |
| 1408 | .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
| 1409 | | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, |
| 1410 | .offs = 8, |
| 1411 | .len = 4, |
| 1412 | .veroffs = 12, |
| 1413 | .maxblocks = 4, |
| 1414 | .pattern = mirror_pattern, |
| 1415 | }; |
| 1416 | |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 1417 | /* initialize driver data structures */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1418 | void denali_drv_init(struct denali_nand_info *denali) |
| 1419 | { |
| 1420 | denali->idx = 0; |
| 1421 | |
| 1422 | /* setup interrupt handler */ |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1423 | /* the completion object will be used to notify |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1424 | * the callee that the interrupt is done */ |
| 1425 | init_completion(&denali->complete); |
| 1426 | |
| 1427 | /* the spinlock will be used to synchronize the ISR |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1428 | * with any element that might be access shared |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1429 | * data (interrupt status) */ |
| 1430 | spin_lock_init(&denali->irq_lock); |
| 1431 | |
| 1432 | /* indicate that MTD has not selected a valid bank yet */ |
| 1433 | denali->flash_bank = CHIP_SELECT_INVALID; |
| 1434 | |
| 1435 | /* initialize our irq_status variable to indicate no interrupts */ |
| 1436 | denali->irq_status = 0; |
| 1437 | } |
| 1438 | |
| 1439 | /* driver entry point */ |
| 1440 | static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 1441 | { |
| 1442 | int ret = -ENODEV; |
| 1443 | resource_size_t csr_base, mem_base; |
| 1444 | unsigned long csr_len, mem_len; |
| 1445 | struct denali_nand_info *denali; |
| 1446 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1447 | denali = kzalloc(sizeof(*denali), GFP_KERNEL); |
| 1448 | if (!denali) |
| 1449 | return -ENOMEM; |
| 1450 | |
| 1451 | ret = pci_enable_device(dev); |
| 1452 | if (ret) { |
| 1453 | printk(KERN_ERR "Spectra: pci_enable_device failed.\n"); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1454 | goto failed_alloc_memery; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | if (id->driver_data == INTEL_CE4100) { |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1458 | /* Due to a silicon limitation, we can only support |
| 1459 | * ONFI timing mode 1 and below. |
| 1460 | */ |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1461 | if (onfi_timing_mode < -1 || onfi_timing_mode > 1) { |
Chuanxiao Dong | bdca6da | 2010-07-27 11:28:09 +0800 | [diff] [blame] | 1462 | printk(KERN_ERR "Intel CE4100 only supports" |
| 1463 | " ONFI timing mode 1 or below\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1464 | ret = -EINVAL; |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1465 | goto failed_enable_dev; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1466 | } |
| 1467 | denali->platform = INTEL_CE4100; |
| 1468 | mem_base = pci_resource_start(dev, 0); |
| 1469 | mem_len = pci_resource_len(dev, 1); |
| 1470 | csr_base = pci_resource_start(dev, 1); |
| 1471 | csr_len = pci_resource_len(dev, 1); |
| 1472 | } else { |
| 1473 | denali->platform = INTEL_MRST; |
| 1474 | csr_base = pci_resource_start(dev, 0); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1475 | csr_len = pci_resource_len(dev, 0); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1476 | mem_base = pci_resource_start(dev, 1); |
| 1477 | mem_len = pci_resource_len(dev, 1); |
| 1478 | if (!mem_len) { |
| 1479 | mem_base = csr_base + csr_len; |
| 1480 | mem_len = csr_len; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | /* Is 32-bit DMA supported? */ |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1485 | ret = dma_set_mask(&dev->dev, DMA_BIT_MASK(32)); |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1486 | if (ret) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1487 | printk(KERN_ERR "Spectra: no usable DMA configuration\n"); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1488 | goto failed_enable_dev; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1489 | } |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1490 | denali->buf.dma_buf = dma_map_single(&dev->dev, denali->buf.buf, |
| 1491 | DENALI_BUF_SIZE, |
| 1492 | DMA_BIDIRECTIONAL); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1493 | |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1494 | if (dma_mapping_error(&dev->dev, denali->buf.dma_buf)) { |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1495 | dev_err(&dev->dev, "Spectra: failed to map DMA buffer\n"); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1496 | goto failed_enable_dev; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | pci_set_master(dev); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1500 | denali->dev = &dev->dev; |
Chuanxiao Dong | 5eab6aaa | 2010-08-12 10:07:18 +0800 | [diff] [blame] | 1501 | denali->mtd.dev.parent = &dev->dev; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1502 | |
| 1503 | ret = pci_request_regions(dev, DENALI_NAND_NAME); |
| 1504 | if (ret) { |
| 1505 | printk(KERN_ERR "Spectra: Unable to request memory regions\n"); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1506 | goto failed_dma_map; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | denali->flash_reg = ioremap_nocache(csr_base, csr_len); |
| 1510 | if (!denali->flash_reg) { |
| 1511 | printk(KERN_ERR "Spectra: Unable to remap memory region\n"); |
| 1512 | ret = -ENOMEM; |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1513 | goto failed_req_regions; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1514 | } |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1515 | |
| 1516 | denali->flash_mem = ioremap_nocache(mem_base, mem_len); |
| 1517 | if (!denali->flash_mem) { |
| 1518 | printk(KERN_ERR "Spectra: ioremap_nocache failed!"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1519 | ret = -ENOMEM; |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1520 | goto failed_remap_reg; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1521 | } |
| 1522 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1523 | denali_hw_init(denali); |
| 1524 | denali_drv_init(denali); |
| 1525 | |
Chuanxiao Dong | 5eab6aaa | 2010-08-12 10:07:18 +0800 | [diff] [blame] | 1526 | /* denali_isr register is done after all the hardware |
| 1527 | * initilization is finished*/ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1528 | if (request_irq(dev->irq, denali_isr, IRQF_SHARED, |
| 1529 | DENALI_NAND_NAME, denali)) { |
| 1530 | printk(KERN_ERR "Spectra: Unable to allocate IRQ\n"); |
| 1531 | ret = -ENODEV; |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1532 | goto failed_remap_mem; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /* now that our ISR is registered, we can enable interrupts */ |
Chuanxiao Dong | eda936e | 2010-07-27 14:17:37 +0800 | [diff] [blame] | 1536 | denali_set_intr_modes(denali, true); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1537 | |
| 1538 | pci_set_drvdata(dev, denali); |
| 1539 | |
Chuanxiao Dong | 5eab6aaa | 2010-08-12 10:07:18 +0800 | [diff] [blame] | 1540 | denali->mtd.name = "denali-nand"; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1541 | denali->mtd.owner = THIS_MODULE; |
| 1542 | denali->mtd.priv = &denali->nand; |
| 1543 | |
| 1544 | /* register the driver with the NAND core subsystem */ |
| 1545 | denali->nand.select_chip = denali_select_chip; |
| 1546 | denali->nand.cmdfunc = denali_cmdfunc; |
| 1547 | denali->nand.read_byte = denali_read_byte; |
| 1548 | denali->nand.waitfunc = denali_waitfunc; |
| 1549 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1550 | /* scan for NAND devices attached to the controller |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1551 | * this is the first stage in a two step process to register |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1552 | * with the nand subsystem */ |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1553 | if (nand_scan_ident(&denali->mtd, LLD_MAX_FLASH_BANKS, NULL)) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1554 | ret = -ENXIO; |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1555 | goto failed_req_irq; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1556 | } |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1557 | |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 1558 | /* MTD supported page sizes vary by kernel. We validate our |
| 1559 | * kernel supports the device here. |
| 1560 | */ |
| 1561 | if (denali->mtd.writesize > NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE) { |
| 1562 | ret = -ENODEV; |
| 1563 | printk(KERN_ERR "Spectra: device size not supported by this " |
| 1564 | "version of MTD."); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1565 | goto failed_req_irq; |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 1566 | } |
| 1567 | |
Chuanxiao Dong | 08b9ab9 | 2010-08-06 18:19:09 +0800 | [diff] [blame] | 1568 | /* support for multi nand |
| 1569 | * MTD known nothing about multi nand, |
| 1570 | * so we should tell it the real pagesize |
| 1571 | * and anything necessery |
| 1572 | */ |
| 1573 | denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED); |
| 1574 | denali->nand.chipsize <<= (denali->devnum - 1); |
| 1575 | denali->nand.page_shift += (denali->devnum - 1); |
| 1576 | denali->nand.pagemask = (denali->nand.chipsize >> |
| 1577 | denali->nand.page_shift) - 1; |
| 1578 | denali->nand.bbt_erase_shift += (denali->devnum - 1); |
| 1579 | denali->nand.phys_erase_shift = denali->nand.bbt_erase_shift; |
| 1580 | denali->nand.chip_shift += (denali->devnum - 1); |
| 1581 | denali->mtd.writesize <<= (denali->devnum - 1); |
| 1582 | denali->mtd.oobsize <<= (denali->devnum - 1); |
| 1583 | denali->mtd.erasesize <<= (denali->devnum - 1); |
| 1584 | denali->mtd.size = denali->nand.numchips * denali->nand.chipsize; |
| 1585 | denali->bbtskipbytes *= denali->devnum; |
| 1586 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1587 | /* second stage of the NAND scan |
| 1588 | * this stage requires information regarding ECC and |
| 1589 | * bad block management. */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1590 | |
| 1591 | /* Bad block management */ |
| 1592 | denali->nand.bbt_td = &bbt_main_descr; |
| 1593 | denali->nand.bbt_md = &bbt_mirror_descr; |
| 1594 | |
| 1595 | /* skip the scan for now until we have OOB read and write support */ |
| 1596 | denali->nand.options |= NAND_USE_FLASH_BBT | NAND_SKIP_BBTSCAN; |
| 1597 | denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME; |
| 1598 | |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1599 | /* Denali Controller only support 15bit and 8bit ECC in MRST, |
| 1600 | * so just let controller do 15bit ECC for MLC and 8bit ECC for |
| 1601 | * SLC if possible. |
| 1602 | * */ |
| 1603 | if (denali->nand.cellinfo & 0xc && |
| 1604 | (denali->mtd.oobsize > (denali->bbtskipbytes + |
| 1605 | ECC_15BITS * (denali->mtd.writesize / |
| 1606 | ECC_SECTOR_SIZE)))) { |
| 1607 | /* if MLC OOB size is large enough, use 15bit ECC*/ |
| 1608 | denali->nand.ecc.layout = &nand_15bit_oob; |
| 1609 | denali->nand.ecc.bytes = ECC_15BITS; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 1610 | iowrite32(15, denali->flash_reg + ECC_CORRECTION); |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1611 | } else if (denali->mtd.oobsize < (denali->bbtskipbytes + |
| 1612 | ECC_8BITS * (denali->mtd.writesize / |
| 1613 | ECC_SECTOR_SIZE))) { |
| 1614 | printk(KERN_ERR "Your NAND chip OOB is not large enough to" |
| 1615 | " contain 8bit ECC correction codes"); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1616 | goto failed_req_irq; |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1617 | } else { |
| 1618 | denali->nand.ecc.layout = &nand_8bit_oob; |
| 1619 | denali->nand.ecc.bytes = ECC_8BITS; |
Chuanxiao Dong | 24c3fa3 | 2010-08-09 23:59:23 +0800 | [diff] [blame] | 1620 | iowrite32(8, denali->flash_reg + ECC_CORRECTION); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1621 | } |
| 1622 | |
Chuanxiao Dong | 08b9ab9 | 2010-08-06 18:19:09 +0800 | [diff] [blame] | 1623 | denali->nand.ecc.bytes *= denali->devnum; |
Chuanxiao Dong | db9a321 | 2010-08-06 18:02:03 +0800 | [diff] [blame] | 1624 | denali->nand.ecc.layout->eccbytes *= |
| 1625 | denali->mtd.writesize / ECC_SECTOR_SIZE; |
| 1626 | denali->nand.ecc.layout->oobfree[0].offset = |
| 1627 | denali->bbtskipbytes + denali->nand.ecc.layout->eccbytes; |
| 1628 | denali->nand.ecc.layout->oobfree[0].length = |
| 1629 | denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes - |
| 1630 | denali->bbtskipbytes; |
| 1631 | |
Chuanxiao.Dong | 6640652 | 2010-08-06 18:48:21 +0800 | [diff] [blame] | 1632 | /* Let driver know the total blocks number and |
| 1633 | * how many blocks contained by each nand chip. |
| 1634 | * blksperchip will help driver to know how many |
| 1635 | * blocks is taken by FW. |
| 1636 | * */ |
| 1637 | denali->totalblks = denali->mtd.size >> |
| 1638 | denali->nand.phys_erase_shift; |
| 1639 | denali->blksperchip = denali->totalblks / denali->nand.numchips; |
| 1640 | |
Chuanxiao | 5bac3ac | 2010-08-05 23:06:04 +0800 | [diff] [blame] | 1641 | /* These functions are required by the NAND core framework, otherwise, |
| 1642 | * the NAND core will assert. However, we don't need them, so we'll stub |
| 1643 | * them out. */ |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1644 | denali->nand.ecc.calculate = denali_ecc_calculate; |
| 1645 | denali->nand.ecc.correct = denali_ecc_correct; |
| 1646 | denali->nand.ecc.hwctl = denali_ecc_hwctl; |
| 1647 | |
| 1648 | /* override the default read operations */ |
Chuanxiao Dong | 08b9ab9 | 2010-08-06 18:19:09 +0800 | [diff] [blame] | 1649 | denali->nand.ecc.size = ECC_SECTOR_SIZE * denali->devnum; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1650 | denali->nand.ecc.read_page = denali_read_page; |
| 1651 | denali->nand.ecc.read_page_raw = denali_read_page_raw; |
| 1652 | denali->nand.ecc.write_page = denali_write_page; |
| 1653 | denali->nand.ecc.write_page_raw = denali_write_page_raw; |
| 1654 | denali->nand.ecc.read_oob = denali_read_oob; |
| 1655 | denali->nand.ecc.write_oob = denali_write_oob; |
| 1656 | denali->nand.erase_cmd = denali_erase; |
| 1657 | |
Chuanxiao Dong | 345b1d3 | 2010-07-27 10:41:53 +0800 | [diff] [blame] | 1658 | if (nand_scan_tail(&denali->mtd)) { |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1659 | ret = -ENXIO; |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1660 | goto failed_req_irq; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | ret = add_mtd_device(&denali->mtd); |
| 1664 | if (ret) { |
Chuanxiao Dong | 7cfffac | 2010-08-10 00:16:51 +0800 | [diff] [blame] | 1665 | dev_err(&dev->dev, "Spectra: Failed to register MTD: %d\n", |
| 1666 | ret); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1667 | goto failed_req_irq; |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1668 | } |
| 1669 | return 0; |
| 1670 | |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1671 | failed_req_irq: |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1672 | denali_irq_cleanup(dev->irq, denali); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1673 | failed_remap_mem: |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1674 | iounmap(denali->flash_mem); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1675 | failed_remap_reg: |
| 1676 | iounmap(denali->flash_reg); |
| 1677 | failed_req_regions: |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1678 | pci_release_regions(dev); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1679 | failed_dma_map: |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1680 | dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE, |
| 1681 | DMA_BIDIRECTIONAL); |
Chuanxiao Dong | 5c0eb90 | 2010-08-09 18:37:00 +0800 | [diff] [blame] | 1682 | failed_enable_dev: |
| 1683 | pci_disable_device(dev); |
| 1684 | failed_alloc_memery: |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1685 | kfree(denali); |
| 1686 | return ret; |
| 1687 | } |
| 1688 | |
| 1689 | /* driver exit point */ |
| 1690 | static void denali_pci_remove(struct pci_dev *dev) |
| 1691 | { |
| 1692 | struct denali_nand_info *denali = pci_get_drvdata(dev); |
| 1693 | |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1694 | nand_release(&denali->mtd); |
| 1695 | del_mtd_device(&denali->mtd); |
| 1696 | |
| 1697 | denali_irq_cleanup(dev->irq, denali); |
| 1698 | |
| 1699 | iounmap(denali->flash_reg); |
| 1700 | iounmap(denali->flash_mem); |
| 1701 | pci_release_regions(dev); |
| 1702 | pci_disable_device(dev); |
Jamie Iles | 8445794 | 2011-05-06 15:28:55 +0100 | [diff] [blame^] | 1703 | dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE, |
| 1704 | DMA_BIDIRECTIONAL); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1705 | pci_set_drvdata(dev, NULL); |
| 1706 | kfree(denali); |
| 1707 | } |
| 1708 | |
| 1709 | MODULE_DEVICE_TABLE(pci, denali_pci_ids); |
| 1710 | |
| 1711 | static struct pci_driver denali_pci_driver = { |
| 1712 | .name = DENALI_NAND_NAME, |
| 1713 | .id_table = denali_pci_ids, |
| 1714 | .probe = denali_pci_probe, |
| 1715 | .remove = denali_pci_remove, |
| 1716 | }; |
| 1717 | |
| 1718 | static int __devinit denali_init(void) |
| 1719 | { |
Michal Marek | 9b5705a2 | 2011-04-05 16:59:03 +0200 | [diff] [blame] | 1720 | printk(KERN_INFO "Spectra MTD driver\n"); |
Jason Roberts | ce08259 | 2010-05-13 15:57:33 +0100 | [diff] [blame] | 1721 | return pci_register_driver(&denali_pci_driver); |
| 1722 | } |
| 1723 | |
| 1724 | /* Free memory */ |
| 1725 | static void __devexit denali_exit(void) |
| 1726 | { |
| 1727 | pci_unregister_driver(&denali_pci_driver); |
| 1728 | } |
| 1729 | |
| 1730 | module_init(denali_init); |
| 1731 | module_exit(denali_exit); |