eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/pxa3xx_nand.c |
| 3 | * |
| 4 | * Copyright © 2005 Intel Corporation |
| 5 | * Copyright © 2006 Marvell International Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
Ezequiel Garcia | de484a3 | 2013-11-07 12:17:10 -0300 | [diff] [blame] | 10 | * |
| 11 | * See Documentation/mtd/nand/pxa3xx-nand.txt for more details. |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 12 | */ |
| 13 | |
Haojian Zhuang | a88bdbb | 2009-09-11 19:33:58 +0800 | [diff] [blame] | 14 | #include <linux/kernel.h> |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/dma-mapping.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/mtd/mtd.h> |
| 22 | #include <linux/mtd/nand.h> |
| 23 | #include <linux/mtd/partitions.h> |
David Woodhouse | a1c06ee | 2008-04-22 20:39:43 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
| 25 | #include <linux/irq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 27 | #include <linux/of.h> |
| 28 | #include <linux/of_device.h> |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 29 | |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 30 | #if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP) |
| 31 | #define ARCH_HAS_DMA |
| 32 | #endif |
| 33 | |
| 34 | #ifdef ARCH_HAS_DMA |
Eric Miao | afb5b5c | 2008-12-01 11:43:08 +0800 | [diff] [blame] | 35 | #include <mach/dma.h> |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 36 | #endif |
| 37 | |
Arnd Bergmann | 293b2da | 2012-08-24 15:16:48 +0200 | [diff] [blame] | 38 | #include <linux/platform_data/mtd-nand-pxa3xx.h> |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 39 | |
| 40 | #define CHIP_DELAY_TIMEOUT (2 * HZ/10) |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 41 | #define NAND_STOP_DELAY (2 * HZ/50) |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 42 | #define PAGE_CHUNK_SIZE (2048) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 43 | |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 44 | /* |
| 45 | * Define a buffer size for the initial command that detects the flash device: |
| 46 | * STATUS, READID and PARAM. The largest of these is the PARAM command, |
| 47 | * needing 256 bytes. |
| 48 | */ |
| 49 | #define INIT_BUFFER_SIZE 256 |
| 50 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 51 | /* registers and bit definitions */ |
| 52 | #define NDCR (0x00) /* Control register */ |
| 53 | #define NDTR0CS0 (0x04) /* Timing Parameter 0 for CS0 */ |
| 54 | #define NDTR1CS0 (0x0C) /* Timing Parameter 1 for CS0 */ |
| 55 | #define NDSR (0x14) /* Status Register */ |
| 56 | #define NDPCR (0x18) /* Page Count Register */ |
| 57 | #define NDBDR0 (0x1C) /* Bad Block Register 0 */ |
| 58 | #define NDBDR1 (0x20) /* Bad Block Register 1 */ |
| 59 | #define NDDB (0x40) /* Data Buffer */ |
| 60 | #define NDCB0 (0x48) /* Command Buffer0 */ |
| 61 | #define NDCB1 (0x4C) /* Command Buffer1 */ |
| 62 | #define NDCB2 (0x50) /* Command Buffer2 */ |
| 63 | |
| 64 | #define NDCR_SPARE_EN (0x1 << 31) |
| 65 | #define NDCR_ECC_EN (0x1 << 30) |
| 66 | #define NDCR_DMA_EN (0x1 << 29) |
| 67 | #define NDCR_ND_RUN (0x1 << 28) |
| 68 | #define NDCR_DWIDTH_C (0x1 << 27) |
| 69 | #define NDCR_DWIDTH_M (0x1 << 26) |
| 70 | #define NDCR_PAGE_SZ (0x1 << 24) |
| 71 | #define NDCR_NCSX (0x1 << 23) |
| 72 | #define NDCR_ND_MODE (0x3 << 21) |
| 73 | #define NDCR_NAND_MODE (0x0) |
| 74 | #define NDCR_CLR_PG_CNT (0x1 << 20) |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 75 | #define NDCR_STOP_ON_UNCOR (0x1 << 19) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 76 | #define NDCR_RD_ID_CNT_MASK (0x7 << 16) |
| 77 | #define NDCR_RD_ID_CNT(x) (((x) << 16) & NDCR_RD_ID_CNT_MASK) |
| 78 | |
| 79 | #define NDCR_RA_START (0x1 << 15) |
| 80 | #define NDCR_PG_PER_BLK (0x1 << 14) |
| 81 | #define NDCR_ND_ARB_EN (0x1 << 12) |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 82 | #define NDCR_INT_MASK (0xFFF) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 83 | |
| 84 | #define NDSR_MASK (0xfff) |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 85 | #define NDSR_RDY (0x1 << 12) |
| 86 | #define NDSR_FLASH_RDY (0x1 << 11) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 87 | #define NDSR_CS0_PAGED (0x1 << 10) |
| 88 | #define NDSR_CS1_PAGED (0x1 << 9) |
| 89 | #define NDSR_CS0_CMDD (0x1 << 8) |
| 90 | #define NDSR_CS1_CMDD (0x1 << 7) |
| 91 | #define NDSR_CS0_BBD (0x1 << 6) |
| 92 | #define NDSR_CS1_BBD (0x1 << 5) |
| 93 | #define NDSR_DBERR (0x1 << 4) |
| 94 | #define NDSR_SBERR (0x1 << 3) |
| 95 | #define NDSR_WRDREQ (0x1 << 2) |
| 96 | #define NDSR_RDDREQ (0x1 << 1) |
| 97 | #define NDSR_WRCMDREQ (0x1) |
| 98 | |
Ezequiel Garcia | 41a6343 | 2013-08-12 14:14:51 -0300 | [diff] [blame] | 99 | #define NDCB0_LEN_OVRD (0x1 << 28) |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 100 | #define NDCB0_ST_ROW_EN (0x1 << 26) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 101 | #define NDCB0_AUTO_RS (0x1 << 25) |
| 102 | #define NDCB0_CSEL (0x1 << 24) |
| 103 | #define NDCB0_CMD_TYPE_MASK (0x7 << 21) |
| 104 | #define NDCB0_CMD_TYPE(x) (((x) << 21) & NDCB0_CMD_TYPE_MASK) |
| 105 | #define NDCB0_NC (0x1 << 20) |
| 106 | #define NDCB0_DBC (0x1 << 19) |
| 107 | #define NDCB0_ADDR_CYC_MASK (0x7 << 16) |
| 108 | #define NDCB0_ADDR_CYC(x) (((x) << 16) & NDCB0_ADDR_CYC_MASK) |
| 109 | #define NDCB0_CMD2_MASK (0xff << 8) |
| 110 | #define NDCB0_CMD1_MASK (0xff) |
| 111 | #define NDCB0_ADDR_CYC_SHIFT (16) |
| 112 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 113 | /* macros for registers read/write */ |
| 114 | #define nand_writel(info, off, val) \ |
| 115 | __raw_writel((val), (info)->mmio_base + (off)) |
| 116 | |
| 117 | #define nand_readl(info, off) \ |
| 118 | __raw_readl((info)->mmio_base + (off)) |
| 119 | |
| 120 | /* error code and state */ |
| 121 | enum { |
| 122 | ERR_NONE = 0, |
| 123 | ERR_DMABUSERR = -1, |
| 124 | ERR_SENDCMD = -2, |
| 125 | ERR_DBERR = -3, |
| 126 | ERR_BBERR = -4, |
Yeasah Pell | 223cf6c | 2009-07-01 18:11:35 +0300 | [diff] [blame] | 127 | ERR_SBERR = -5, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | enum { |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 131 | STATE_IDLE = 0, |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 132 | STATE_PREPARED, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 133 | STATE_CMD_HANDLE, |
| 134 | STATE_DMA_READING, |
| 135 | STATE_DMA_WRITING, |
| 136 | STATE_DMA_DONE, |
| 137 | STATE_PIO_READING, |
| 138 | STATE_PIO_WRITING, |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 139 | STATE_CMD_DONE, |
| 140 | STATE_READY, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 141 | }; |
| 142 | |
Ezequiel Garcia | c0f3b86 | 2013-08-10 16:34:52 -0300 | [diff] [blame] | 143 | enum pxa3xx_nand_variant { |
| 144 | PXA3XX_NAND_VARIANT_PXA, |
| 145 | PXA3XX_NAND_VARIANT_ARMADA370, |
| 146 | }; |
| 147 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 148 | struct pxa3xx_nand_host { |
| 149 | struct nand_chip chip; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 150 | struct mtd_info *mtd; |
| 151 | void *info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 152 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 153 | /* page size of attached chip */ |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 154 | int use_ecc; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 155 | int cs; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 156 | |
| 157 | /* calculated from pxa3xx_nand_flash data */ |
| 158 | unsigned int col_addr_cycles; |
| 159 | unsigned int row_addr_cycles; |
| 160 | size_t read_id_bytes; |
| 161 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | struct pxa3xx_nand_info { |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 165 | struct nand_hw_control controller; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 166 | struct platform_device *pdev; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 167 | |
| 168 | struct clk *clk; |
| 169 | void __iomem *mmio_base; |
Haojian Zhuang | 8638fac | 2009-09-10 14:11:44 +0800 | [diff] [blame] | 170 | unsigned long mmio_phys; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 171 | struct completion cmd_complete; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 172 | |
| 173 | unsigned int buf_start; |
| 174 | unsigned int buf_count; |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 175 | unsigned int buf_size; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 176 | |
| 177 | /* DMA information */ |
| 178 | int drcmr_dat; |
| 179 | int drcmr_cmd; |
| 180 | |
| 181 | unsigned char *data_buff; |
Lei Wen | 18c81b1 | 2010-08-17 17:25:57 +0800 | [diff] [blame] | 182 | unsigned char *oob_buff; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 183 | dma_addr_t data_buff_phys; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 184 | int data_dma_ch; |
| 185 | struct pxa_dma_desc *data_desc; |
| 186 | dma_addr_t data_desc_addr; |
| 187 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 188 | struct pxa3xx_nand_host *host[NUM_CHIP_SELECT]; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 189 | unsigned int state; |
| 190 | |
Ezequiel Garcia | c0f3b86 | 2013-08-10 16:34:52 -0300 | [diff] [blame] | 191 | /* |
| 192 | * This driver supports NFCv1 (as found in PXA SoC) |
| 193 | * and NFCv2 (as found in Armada 370/XP SoC). |
| 194 | */ |
| 195 | enum pxa3xx_nand_variant variant; |
| 196 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 197 | int cs; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 198 | int use_ecc; /* use HW ECC ? */ |
| 199 | int use_dma; /* use DMA ? */ |
Ezequiel Garcia | 5bb653e | 2013-08-12 14:14:49 -0300 | [diff] [blame] | 200 | int use_spare; /* use spare ? */ |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 201 | int is_ready; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 202 | |
Ezequiel Garcia | 2128b08 | 2013-11-07 12:17:16 -0300 | [diff] [blame] | 203 | unsigned int fifo_size; /* max. data size in the FIFO */ |
| 204 | unsigned int data_size; /* data to be read from FIFO */ |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 205 | unsigned int oob_size; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 206 | int retcode; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 207 | |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 208 | /* cached register value */ |
| 209 | uint32_t reg_ndcr; |
| 210 | uint32_t ndtr0cs0; |
| 211 | uint32_t ndtr1cs0; |
| 212 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 213 | /* generated NDCBx register values */ |
| 214 | uint32_t ndcb0; |
| 215 | uint32_t ndcb1; |
| 216 | uint32_t ndcb2; |
Ezequiel Garcia | 3a1a344 | 2013-08-12 14:14:50 -0300 | [diff] [blame] | 217 | uint32_t ndcb3; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 218 | }; |
| 219 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 220 | static bool use_dma = 1; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 221 | module_param(use_dma, bool, 0444); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 222 | MODULE_PARM_DESC(use_dma, "enable DMA for data transferring to/from NAND HW"); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 223 | |
Lei Wen | c1f8247 | 2010-08-17 13:50:23 +0800 | [diff] [blame] | 224 | static struct pxa3xx_nand_timing timing[] = { |
Lei Wen | 227a886 | 2010-08-18 18:00:03 +0800 | [diff] [blame] | 225 | { 40, 80, 60, 100, 80, 100, 90000, 400, 40, }, |
| 226 | { 10, 0, 20, 40, 30, 40, 11123, 110, 10, }, |
| 227 | { 10, 25, 15, 25, 15, 30, 25000, 60, 10, }, |
| 228 | { 10, 35, 15, 25, 15, 25, 25000, 60, 10, }, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 229 | }; |
| 230 | |
Lei Wen | c1f8247 | 2010-08-17 13:50:23 +0800 | [diff] [blame] | 231 | static struct pxa3xx_nand_flash builtin_flash_types[] = { |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 232 | { "DEFAULT FLASH", 0, 0, 2048, 8, 8, 0, &timing[0] }, |
| 233 | { "64MiB 16-bit", 0x46ec, 32, 512, 16, 16, 4096, &timing[1] }, |
| 234 | { "256MiB 8-bit", 0xdaec, 64, 2048, 8, 8, 2048, &timing[1] }, |
| 235 | { "4GiB 8-bit", 0xd7ec, 128, 4096, 8, 8, 8192, &timing[1] }, |
| 236 | { "128MiB 8-bit", 0xa12c, 64, 2048, 8, 8, 1024, &timing[2] }, |
| 237 | { "128MiB 16-bit", 0xb12c, 64, 2048, 16, 16, 1024, &timing[2] }, |
| 238 | { "512MiB 8-bit", 0xdc2c, 64, 2048, 8, 8, 4096, &timing[2] }, |
| 239 | { "512MiB 16-bit", 0xcc2c, 64, 2048, 16, 16, 4096, &timing[2] }, |
| 240 | { "256MiB 16-bit", 0xba20, 64, 2048, 16, 16, 2048, &timing[3] }, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 241 | }; |
| 242 | |
Lei Wen | 227a886 | 2010-08-18 18:00:03 +0800 | [diff] [blame] | 243 | /* Define a default flash type setting serve as flash detecting only */ |
| 244 | #define DEFAULT_FLASH_TYPE (&builtin_flash_types[0]) |
| 245 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 246 | #define NDTR0_tCH(c) (min((c), 7) << 19) |
| 247 | #define NDTR0_tCS(c) (min((c), 7) << 16) |
| 248 | #define NDTR0_tWH(c) (min((c), 7) << 11) |
| 249 | #define NDTR0_tWP(c) (min((c), 7) << 8) |
| 250 | #define NDTR0_tRH(c) (min((c), 7) << 3) |
| 251 | #define NDTR0_tRP(c) (min((c), 7) << 0) |
| 252 | |
| 253 | #define NDTR1_tR(c) (min((c), 65535) << 16) |
| 254 | #define NDTR1_tWHR(c) (min((c), 15) << 4) |
| 255 | #define NDTR1_tAR(c) (min((c), 15) << 0) |
| 256 | |
| 257 | /* convert nano-seconds to nand flash controller clock cycles */ |
Axel Lin | 93b352f | 2010-08-16 16:09:09 +0800 | [diff] [blame] | 258 | #define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 259 | |
Ezequiel Garcia | c7e9c7e | 2013-11-07 12:17:14 -0300 | [diff] [blame] | 260 | static struct of_device_id pxa3xx_nand_dt_ids[] = { |
| 261 | { |
| 262 | .compatible = "marvell,pxa3xx-nand", |
| 263 | .data = (void *)PXA3XX_NAND_VARIANT_PXA, |
| 264 | }, |
| 265 | {} |
| 266 | }; |
| 267 | MODULE_DEVICE_TABLE(of, pxa3xx_nand_dt_ids); |
| 268 | |
| 269 | static enum pxa3xx_nand_variant |
| 270 | pxa3xx_nand_get_variant(struct platform_device *pdev) |
| 271 | { |
| 272 | const struct of_device_id *of_id = |
| 273 | of_match_device(pxa3xx_nand_dt_ids, &pdev->dev); |
| 274 | if (!of_id) |
| 275 | return PXA3XX_NAND_VARIANT_PXA; |
| 276 | return (enum pxa3xx_nand_variant)of_id->data; |
| 277 | } |
| 278 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 279 | static void pxa3xx_nand_set_timing(struct pxa3xx_nand_host *host, |
Enrico Scholz | 7dad482 | 2008-08-29 12:59:50 +0200 | [diff] [blame] | 280 | const struct pxa3xx_nand_timing *t) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 281 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 282 | struct pxa3xx_nand_info *info = host->info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 283 | unsigned long nand_clk = clk_get_rate(info->clk); |
| 284 | uint32_t ndtr0, ndtr1; |
| 285 | |
| 286 | ndtr0 = NDTR0_tCH(ns2cycle(t->tCH, nand_clk)) | |
| 287 | NDTR0_tCS(ns2cycle(t->tCS, nand_clk)) | |
| 288 | NDTR0_tWH(ns2cycle(t->tWH, nand_clk)) | |
| 289 | NDTR0_tWP(ns2cycle(t->tWP, nand_clk)) | |
| 290 | NDTR0_tRH(ns2cycle(t->tRH, nand_clk)) | |
| 291 | NDTR0_tRP(ns2cycle(t->tRP, nand_clk)); |
| 292 | |
| 293 | ndtr1 = NDTR1_tR(ns2cycle(t->tR, nand_clk)) | |
| 294 | NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) | |
| 295 | NDTR1_tAR(ns2cycle(t->tAR, nand_clk)); |
| 296 | |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 297 | info->ndtr0cs0 = ndtr0; |
| 298 | info->ndtr1cs0 = ndtr1; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 299 | nand_writel(info, NDTR0CS0, ndtr0); |
| 300 | nand_writel(info, NDTR1CS0, ndtr1); |
| 301 | } |
| 302 | |
Ezequiel Garcia | 6a3e486 | 2013-11-07 12:17:18 -0300 | [diff] [blame^] | 303 | /* |
| 304 | * Set the data and OOB size, depending on the selected |
| 305 | * spare and ECC configuration. |
| 306 | * Only applicable to READ0, READOOB and PAGEPROG commands. |
| 307 | */ |
Lei Wen | 18c81b1 | 2010-08-17 17:25:57 +0800 | [diff] [blame] | 308 | static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 309 | { |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 310 | int oob_enable = info->reg_ndcr & NDCR_SPARE_EN; |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 311 | |
Ezequiel Garcia | 2128b08 | 2013-11-07 12:17:16 -0300 | [diff] [blame] | 312 | info->data_size = info->fifo_size; |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 313 | if (!oob_enable) { |
| 314 | info->oob_size = 0; |
| 315 | return; |
| 316 | } |
| 317 | |
Ezequiel Garcia | 2128b08 | 2013-11-07 12:17:16 -0300 | [diff] [blame] | 318 | switch (info->fifo_size) { |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 319 | case 2048: |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 320 | info->oob_size = (info->use_ecc) ? 40 : 64; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 321 | break; |
| 322 | case 512: |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 323 | info->oob_size = (info->use_ecc) ? 8 : 16; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 324 | break; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 325 | } |
Lei Wen | 18c81b1 | 2010-08-17 17:25:57 +0800 | [diff] [blame] | 326 | } |
| 327 | |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 328 | /** |
| 329 | * NOTE: it is a must to set ND_RUN firstly, then write |
| 330 | * command buffer, otherwise, it does not work. |
| 331 | * We enable all the interrupt at the same time, and |
| 332 | * let pxa3xx_nand_irq to handle all logic. |
| 333 | */ |
| 334 | static void pxa3xx_nand_start(struct pxa3xx_nand_info *info) |
| 335 | { |
| 336 | uint32_t ndcr; |
| 337 | |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 338 | ndcr = info->reg_ndcr; |
Ezequiel Garcia | cd9d118 | 2013-08-12 14:14:48 -0300 | [diff] [blame] | 339 | |
| 340 | if (info->use_ecc) |
| 341 | ndcr |= NDCR_ECC_EN; |
| 342 | else |
| 343 | ndcr &= ~NDCR_ECC_EN; |
| 344 | |
| 345 | if (info->use_dma) |
| 346 | ndcr |= NDCR_DMA_EN; |
| 347 | else |
| 348 | ndcr &= ~NDCR_DMA_EN; |
| 349 | |
Ezequiel Garcia | 5bb653e | 2013-08-12 14:14:49 -0300 | [diff] [blame] | 350 | if (info->use_spare) |
| 351 | ndcr |= NDCR_SPARE_EN; |
| 352 | else |
| 353 | ndcr &= ~NDCR_SPARE_EN; |
| 354 | |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 355 | ndcr |= NDCR_ND_RUN; |
| 356 | |
| 357 | /* clear status bits and run */ |
| 358 | nand_writel(info, NDCR, 0); |
| 359 | nand_writel(info, NDSR, NDSR_MASK); |
| 360 | nand_writel(info, NDCR, ndcr); |
| 361 | } |
| 362 | |
| 363 | static void pxa3xx_nand_stop(struct pxa3xx_nand_info *info) |
| 364 | { |
| 365 | uint32_t ndcr; |
| 366 | int timeout = NAND_STOP_DELAY; |
| 367 | |
| 368 | /* wait RUN bit in NDCR become 0 */ |
| 369 | ndcr = nand_readl(info, NDCR); |
| 370 | while ((ndcr & NDCR_ND_RUN) && (timeout-- > 0)) { |
| 371 | ndcr = nand_readl(info, NDCR); |
| 372 | udelay(1); |
| 373 | } |
| 374 | |
| 375 | if (timeout <= 0) { |
| 376 | ndcr &= ~NDCR_ND_RUN; |
| 377 | nand_writel(info, NDCR, ndcr); |
| 378 | } |
| 379 | /* clear status bits */ |
| 380 | nand_writel(info, NDSR, NDSR_MASK); |
| 381 | } |
| 382 | |
Ezequiel Garcia | 57ff88f | 2013-08-12 14:14:57 -0300 | [diff] [blame] | 383 | static void __maybe_unused |
| 384 | enable_int(struct pxa3xx_nand_info *info, uint32_t int_mask) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 385 | { |
| 386 | uint32_t ndcr; |
| 387 | |
| 388 | ndcr = nand_readl(info, NDCR); |
| 389 | nand_writel(info, NDCR, ndcr & ~int_mask); |
| 390 | } |
| 391 | |
| 392 | static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask) |
| 393 | { |
| 394 | uint32_t ndcr; |
| 395 | |
| 396 | ndcr = nand_readl(info, NDCR); |
| 397 | nand_writel(info, NDCR, ndcr | int_mask); |
| 398 | } |
| 399 | |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 400 | static void handle_data_pio(struct pxa3xx_nand_info *info) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 401 | { |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 402 | switch (info->state) { |
| 403 | case STATE_PIO_WRITING: |
| 404 | __raw_writesl(info->mmio_base + NDDB, info->data_buff, |
Haojian Zhuang | a88bdbb | 2009-09-11 19:33:58 +0800 | [diff] [blame] | 405 | DIV_ROUND_UP(info->data_size, 4)); |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 406 | if (info->oob_size > 0) |
| 407 | __raw_writesl(info->mmio_base + NDDB, info->oob_buff, |
| 408 | DIV_ROUND_UP(info->oob_size, 4)); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 409 | break; |
| 410 | case STATE_PIO_READING: |
| 411 | __raw_readsl(info->mmio_base + NDDB, info->data_buff, |
Haojian Zhuang | a88bdbb | 2009-09-11 19:33:58 +0800 | [diff] [blame] | 412 | DIV_ROUND_UP(info->data_size, 4)); |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 413 | if (info->oob_size > 0) |
| 414 | __raw_readsl(info->mmio_base + NDDB, info->oob_buff, |
| 415 | DIV_ROUND_UP(info->oob_size, 4)); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 416 | break; |
| 417 | default: |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 418 | dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 419 | info->state); |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 420 | BUG(); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 421 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 422 | } |
| 423 | |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 424 | #ifdef ARCH_HAS_DMA |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 425 | static void start_data_dma(struct pxa3xx_nand_info *info) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 426 | { |
| 427 | struct pxa_dma_desc *desc = info->data_desc; |
Lei Wen | 9d8b104 | 2010-08-17 14:09:30 +0800 | [diff] [blame] | 428 | int dma_len = ALIGN(info->data_size + info->oob_size, 32); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 429 | |
| 430 | desc->ddadr = DDADR_STOP; |
| 431 | desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len; |
| 432 | |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 433 | switch (info->state) { |
| 434 | case STATE_DMA_WRITING: |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 435 | desc->dsadr = info->data_buff_phys; |
Haojian Zhuang | 8638fac | 2009-09-10 14:11:44 +0800 | [diff] [blame] | 436 | desc->dtadr = info->mmio_phys + NDDB; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 437 | desc->dcmd |= DCMD_INCSRCADDR | DCMD_FLOWTRG; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 438 | break; |
| 439 | case STATE_DMA_READING: |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 440 | desc->dtadr = info->data_buff_phys; |
Haojian Zhuang | 8638fac | 2009-09-10 14:11:44 +0800 | [diff] [blame] | 441 | desc->dsadr = info->mmio_phys + NDDB; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 442 | desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 443 | break; |
| 444 | default: |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 445 | dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__, |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 446 | info->state); |
| 447 | BUG(); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | DRCMR(info->drcmr_dat) = DRCMR_MAPVLD | info->data_dma_ch; |
| 451 | DDADR(info->data_dma_ch) = info->data_desc_addr; |
| 452 | DCSR(info->data_dma_ch) |= DCSR_RUN; |
| 453 | } |
| 454 | |
| 455 | static void pxa3xx_nand_data_dma_irq(int channel, void *data) |
| 456 | { |
| 457 | struct pxa3xx_nand_info *info = data; |
| 458 | uint32_t dcsr; |
| 459 | |
| 460 | dcsr = DCSR(channel); |
| 461 | DCSR(channel) = dcsr; |
| 462 | |
| 463 | if (dcsr & DCSR_BUSERR) { |
| 464 | info->retcode = ERR_DMABUSERR; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 465 | } |
| 466 | |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 467 | info->state = STATE_DMA_DONE; |
| 468 | enable_int(info, NDCR_INT_MASK); |
| 469 | nand_writel(info, NDSR, NDSR_WRDREQ | NDSR_RDDREQ); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 470 | } |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 471 | #else |
| 472 | static void start_data_dma(struct pxa3xx_nand_info *info) |
| 473 | {} |
| 474 | #endif |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 475 | |
| 476 | static irqreturn_t pxa3xx_nand_irq(int irq, void *devid) |
| 477 | { |
| 478 | struct pxa3xx_nand_info *info = devid; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 479 | unsigned int status, is_completed = 0; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 480 | unsigned int ready, cmd_done; |
| 481 | |
| 482 | if (info->cs == 0) { |
| 483 | ready = NDSR_FLASH_RDY; |
| 484 | cmd_done = NDSR_CS0_CMDD; |
| 485 | } else { |
| 486 | ready = NDSR_RDY; |
| 487 | cmd_done = NDSR_CS1_CMDD; |
| 488 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 489 | |
| 490 | status = nand_readl(info, NDSR); |
| 491 | |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 492 | if (status & NDSR_DBERR) |
| 493 | info->retcode = ERR_DBERR; |
| 494 | if (status & NDSR_SBERR) |
| 495 | info->retcode = ERR_SBERR; |
| 496 | if (status & (NDSR_RDDREQ | NDSR_WRDREQ)) { |
| 497 | /* whether use dma to transfer data */ |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 498 | if (info->use_dma) { |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 499 | disable_int(info, NDCR_INT_MASK); |
| 500 | info->state = (status & NDSR_RDDREQ) ? |
| 501 | STATE_DMA_READING : STATE_DMA_WRITING; |
| 502 | start_data_dma(info); |
| 503 | goto NORMAL_IRQ_EXIT; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 504 | } else { |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 505 | info->state = (status & NDSR_RDDREQ) ? |
| 506 | STATE_PIO_READING : STATE_PIO_WRITING; |
| 507 | handle_data_pio(info); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 508 | } |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 509 | } |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 510 | if (status & cmd_done) { |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 511 | info->state = STATE_CMD_DONE; |
| 512 | is_completed = 1; |
| 513 | } |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 514 | if (status & ready) { |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 515 | info->is_ready = 1; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 516 | info->state = STATE_READY; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 517 | } |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 518 | |
| 519 | if (status & NDSR_WRCMDREQ) { |
| 520 | nand_writel(info, NDSR, NDSR_WRCMDREQ); |
| 521 | status &= ~NDSR_WRCMDREQ; |
| 522 | info->state = STATE_CMD_HANDLE; |
Ezequiel Garcia | 3a1a344 | 2013-08-12 14:14:50 -0300 | [diff] [blame] | 523 | |
| 524 | /* |
| 525 | * Command buffer registers NDCB{0-2} (and optionally NDCB3) |
| 526 | * must be loaded by writing directly either 12 or 16 |
| 527 | * bytes directly to NDCB0, four bytes at a time. |
| 528 | * |
| 529 | * Direct write access to NDCB1, NDCB2 and NDCB3 is ignored |
| 530 | * but each NDCBx register can be read. |
| 531 | */ |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 532 | nand_writel(info, NDCB0, info->ndcb0); |
| 533 | nand_writel(info, NDCB0, info->ndcb1); |
| 534 | nand_writel(info, NDCB0, info->ndcb2); |
Ezequiel Garcia | 3a1a344 | 2013-08-12 14:14:50 -0300 | [diff] [blame] | 535 | |
| 536 | /* NDCB3 register is available in NFCv2 (Armada 370/XP SoC) */ |
| 537 | if (info->variant == PXA3XX_NAND_VARIANT_ARMADA370) |
| 538 | nand_writel(info, NDCB0, info->ndcb3); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 539 | } |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 540 | |
| 541 | /* clear NDSR to let the controller exit the IRQ */ |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 542 | nand_writel(info, NDSR, status); |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 543 | if (is_completed) |
| 544 | complete(&info->cmd_complete); |
| 545 | NORMAL_IRQ_EXIT: |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 546 | return IRQ_HANDLED; |
| 547 | } |
| 548 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 549 | static inline int is_buf_blank(uint8_t *buf, size_t len) |
| 550 | { |
| 551 | for (; len > 0; len--) |
| 552 | if (*buf++ != 0xff) |
| 553 | return 0; |
| 554 | return 1; |
| 555 | } |
| 556 | |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 557 | static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, |
| 558 | uint16_t column, int page_addr) |
| 559 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 560 | int addr_cycle, exec_cmd; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 561 | struct pxa3xx_nand_host *host; |
| 562 | struct mtd_info *mtd; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 563 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 564 | host = info->host[info->cs]; |
| 565 | mtd = host->mtd; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 566 | addr_cycle = 0; |
| 567 | exec_cmd = 1; |
| 568 | |
| 569 | /* reset data and oob column point to handle data */ |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 570 | info->buf_start = 0; |
| 571 | info->buf_count = 0; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 572 | info->oob_size = 0; |
| 573 | info->use_ecc = 0; |
Ezequiel Garcia | 5bb653e | 2013-08-12 14:14:49 -0300 | [diff] [blame] | 574 | info->use_spare = 1; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 575 | info->is_ready = 0; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 576 | info->retcode = ERR_NONE; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 577 | if (info->cs != 0) |
| 578 | info->ndcb0 = NDCB0_CSEL; |
| 579 | else |
| 580 | info->ndcb0 = 0; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 581 | |
| 582 | switch (command) { |
| 583 | case NAND_CMD_READ0: |
| 584 | case NAND_CMD_PAGEPROG: |
| 585 | info->use_ecc = 1; |
| 586 | case NAND_CMD_READOOB: |
| 587 | pxa3xx_set_datasize(info); |
| 588 | break; |
Ezequiel Garcia | 41a6343 | 2013-08-12 14:14:51 -0300 | [diff] [blame] | 589 | case NAND_CMD_PARAM: |
| 590 | info->use_spare = 0; |
| 591 | break; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 592 | case NAND_CMD_SEQIN: |
| 593 | exec_cmd = 0; |
| 594 | break; |
| 595 | default: |
| 596 | info->ndcb1 = 0; |
| 597 | info->ndcb2 = 0; |
Ezequiel Garcia | 3a1a344 | 2013-08-12 14:14:50 -0300 | [diff] [blame] | 598 | info->ndcb3 = 0; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 599 | break; |
| 600 | } |
| 601 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 602 | addr_cycle = NDCB0_ADDR_CYC(host->row_addr_cycles |
| 603 | + host->col_addr_cycles); |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 604 | |
| 605 | switch (command) { |
| 606 | case NAND_CMD_READOOB: |
| 607 | case NAND_CMD_READ0: |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 608 | info->buf_start = column; |
| 609 | info->ndcb0 |= NDCB0_CMD_TYPE(0) |
| 610 | | addr_cycle |
| 611 | | NAND_CMD_READ0; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 612 | |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 613 | if (command == NAND_CMD_READOOB) |
| 614 | info->buf_start += mtd->writesize; |
| 615 | |
| 616 | /* Second command setting for large pages */ |
Ezequiel Garcia | 0a3f3a1 | 2013-11-07 12:17:17 -0300 | [diff] [blame] | 617 | if (mtd->writesize >= PAGE_CHUNK_SIZE) |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 618 | info->ndcb0 |= NDCB0_DBC | (NAND_CMD_READSTART << 8); |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 619 | |
| 620 | case NAND_CMD_SEQIN: |
| 621 | /* small page addr setting */ |
Ezequiel Garcia | 0a3f3a1 | 2013-11-07 12:17:17 -0300 | [diff] [blame] | 622 | if (unlikely(mtd->writesize < PAGE_CHUNK_SIZE)) { |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 623 | info->ndcb1 = ((page_addr & 0xFFFFFF) << 8) |
| 624 | | (column & 0xFF); |
| 625 | |
| 626 | info->ndcb2 = 0; |
| 627 | } else { |
| 628 | info->ndcb1 = ((page_addr & 0xFFFF) << 16) |
| 629 | | (column & 0xFFFF); |
| 630 | |
| 631 | if (page_addr & 0xFF0000) |
| 632 | info->ndcb2 = (page_addr & 0xFF0000) >> 16; |
| 633 | else |
| 634 | info->ndcb2 = 0; |
| 635 | } |
| 636 | |
| 637 | info->buf_count = mtd->writesize + mtd->oobsize; |
| 638 | memset(info->data_buff, 0xFF, info->buf_count); |
| 639 | |
| 640 | break; |
| 641 | |
| 642 | case NAND_CMD_PAGEPROG: |
| 643 | if (is_buf_blank(info->data_buff, |
| 644 | (mtd->writesize + mtd->oobsize))) { |
| 645 | exec_cmd = 0; |
| 646 | break; |
| 647 | } |
| 648 | |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 649 | info->ndcb0 |= NDCB0_CMD_TYPE(0x1) |
| 650 | | NDCB0_AUTO_RS |
| 651 | | NDCB0_ST_ROW_EN |
| 652 | | NDCB0_DBC |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 653 | | (NAND_CMD_PAGEPROG << 8) |
| 654 | | NAND_CMD_SEQIN |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 655 | | addr_cycle; |
| 656 | break; |
| 657 | |
Ezequiel Garcia | ce0268f | 2013-05-14 08:15:25 -0300 | [diff] [blame] | 658 | case NAND_CMD_PARAM: |
Ezequiel Garcia | ce0268f | 2013-05-14 08:15:25 -0300 | [diff] [blame] | 659 | info->buf_count = 256; |
| 660 | info->ndcb0 |= NDCB0_CMD_TYPE(0) |
| 661 | | NDCB0_ADDR_CYC(1) |
Ezequiel Garcia | 41a6343 | 2013-08-12 14:14:51 -0300 | [diff] [blame] | 662 | | NDCB0_LEN_OVRD |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 663 | | command; |
Ezequiel Garcia | ce0268f | 2013-05-14 08:15:25 -0300 | [diff] [blame] | 664 | info->ndcb1 = (column & 0xFF); |
Ezequiel Garcia | 41a6343 | 2013-08-12 14:14:51 -0300 | [diff] [blame] | 665 | info->ndcb3 = 256; |
Ezequiel Garcia | ce0268f | 2013-05-14 08:15:25 -0300 | [diff] [blame] | 666 | info->data_size = 256; |
| 667 | break; |
| 668 | |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 669 | case NAND_CMD_READID: |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 670 | info->buf_count = host->read_id_bytes; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 671 | info->ndcb0 |= NDCB0_CMD_TYPE(3) |
| 672 | | NDCB0_ADDR_CYC(1) |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 673 | | command; |
Ezequiel Garcia | d14231f | 2013-05-14 08:15:24 -0300 | [diff] [blame] | 674 | info->ndcb1 = (column & 0xFF); |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 675 | |
| 676 | info->data_size = 8; |
| 677 | break; |
| 678 | case NAND_CMD_STATUS: |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 679 | info->buf_count = 1; |
| 680 | info->ndcb0 |= NDCB0_CMD_TYPE(4) |
| 681 | | NDCB0_ADDR_CYC(1) |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 682 | | command; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 683 | |
| 684 | info->data_size = 8; |
| 685 | break; |
| 686 | |
| 687 | case NAND_CMD_ERASE1: |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 688 | info->ndcb0 |= NDCB0_CMD_TYPE(2) |
| 689 | | NDCB0_AUTO_RS |
| 690 | | NDCB0_ADDR_CYC(3) |
| 691 | | NDCB0_DBC |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 692 | | (NAND_CMD_ERASE2 << 8) |
| 693 | | NAND_CMD_ERASE1; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 694 | info->ndcb1 = page_addr; |
| 695 | info->ndcb2 = 0; |
| 696 | |
| 697 | break; |
| 698 | case NAND_CMD_RESET: |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 699 | info->ndcb0 |= NDCB0_CMD_TYPE(5) |
Ezequiel Garcia | ec82135 | 2013-08-12 14:14:54 -0300 | [diff] [blame] | 700 | | command; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 701 | |
| 702 | break; |
| 703 | |
| 704 | case NAND_CMD_ERASE2: |
| 705 | exec_cmd = 0; |
| 706 | break; |
| 707 | |
| 708 | default: |
| 709 | exec_cmd = 0; |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 710 | dev_err(&info->pdev->dev, "non-supported command %x\n", |
| 711 | command); |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 712 | break; |
| 713 | } |
| 714 | |
| 715 | return exec_cmd; |
| 716 | } |
| 717 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 718 | static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, |
David Woodhouse | a1c06ee | 2008-04-22 20:39:43 +0100 | [diff] [blame] | 719 | int column, int page_addr) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 720 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 721 | struct pxa3xx_nand_host *host = mtd->priv; |
| 722 | struct pxa3xx_nand_info *info = host->info_data; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 723 | int ret, exec_cmd; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 724 | |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 725 | /* |
| 726 | * if this is a x16 device ,then convert the input |
| 727 | * "byte" address into a "word" address appropriate |
| 728 | * for indexing a word-oriented device |
| 729 | */ |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 730 | if (info->reg_ndcr & NDCR_DWIDTH_M) |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 731 | column /= 2; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 732 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 733 | /* |
| 734 | * There may be different NAND chip hooked to |
| 735 | * different chip select, so check whether |
| 736 | * chip select has been changed, if yes, reset the timing |
| 737 | */ |
| 738 | if (info->cs != host->cs) { |
| 739 | info->cs = host->cs; |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 740 | nand_writel(info, NDTR0CS0, info->ndtr0cs0); |
| 741 | nand_writel(info, NDTR1CS0, info->ndtr1cs0); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 744 | info->state = STATE_PREPARED; |
Lei Wen | 4eb2da8 | 2011-02-28 10:32:13 +0800 | [diff] [blame] | 745 | exec_cmd = prepare_command_pool(info, command, column, page_addr); |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 746 | if (exec_cmd) { |
| 747 | init_completion(&info->cmd_complete); |
| 748 | pxa3xx_nand_start(info); |
| 749 | |
| 750 | ret = wait_for_completion_timeout(&info->cmd_complete, |
| 751 | CHIP_DELAY_TIMEOUT); |
| 752 | if (!ret) { |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 753 | dev_err(&info->pdev->dev, "Wait time out!!!\n"); |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 754 | /* Stop State Machine for next command cycle */ |
| 755 | pxa3xx_nand_stop(info); |
| 756 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 757 | } |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 758 | info->state = STATE_IDLE; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 759 | } |
| 760 | |
Josh Wu | fdbad98d | 2012-06-25 18:07:45 +0800 | [diff] [blame] | 761 | static int pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd, |
Brian Norris | 1fbb938 | 2012-05-02 10:14:55 -0700 | [diff] [blame] | 762 | struct nand_chip *chip, const uint8_t *buf, int oob_required) |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 763 | { |
| 764 | chip->write_buf(mtd, buf, mtd->writesize); |
| 765 | chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); |
Josh Wu | fdbad98d | 2012-06-25 18:07:45 +0800 | [diff] [blame] | 766 | |
| 767 | return 0; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, |
Brian Norris | 1fbb938 | 2012-05-02 10:14:55 -0700 | [diff] [blame] | 771 | struct nand_chip *chip, uint8_t *buf, int oob_required, |
| 772 | int page) |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 773 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 774 | struct pxa3xx_nand_host *host = mtd->priv; |
| 775 | struct pxa3xx_nand_info *info = host->info_data; |
Ezequiel Garcia | 4e86fd2 | 2013-11-07 12:17:13 -0300 | [diff] [blame] | 776 | int max_bitflips = 0; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 777 | |
| 778 | chip->read_buf(mtd, buf, mtd->writesize); |
| 779 | chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); |
| 780 | |
| 781 | if (info->retcode == ERR_SBERR) { |
| 782 | switch (info->use_ecc) { |
| 783 | case 1: |
Ezequiel Garcia | 4e86fd2 | 2013-11-07 12:17:13 -0300 | [diff] [blame] | 784 | max_bitflips = 1; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 785 | mtd->ecc_stats.corrected++; |
| 786 | break; |
| 787 | case 0: |
| 788 | default: |
| 789 | break; |
| 790 | } |
| 791 | } else if (info->retcode == ERR_DBERR) { |
| 792 | /* |
| 793 | * for blank page (all 0xff), HW will calculate its ECC as |
| 794 | * 0, which is different from the ECC information within |
| 795 | * OOB, ignore such double bit errors |
| 796 | */ |
| 797 | if (is_buf_blank(buf, mtd->writesize)) |
Daniel Mack | 543e32d | 2011-06-07 03:01:07 -0700 | [diff] [blame] | 798 | info->retcode = ERR_NONE; |
| 799 | else |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 800 | mtd->ecc_stats.failed++; |
| 801 | } |
| 802 | |
Ezequiel Garcia | 4e86fd2 | 2013-11-07 12:17:13 -0300 | [diff] [blame] | 803 | return max_bitflips; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 804 | } |
| 805 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 806 | static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd) |
| 807 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 808 | struct pxa3xx_nand_host *host = mtd->priv; |
| 809 | struct pxa3xx_nand_info *info = host->info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 810 | char retval = 0xFF; |
| 811 | |
| 812 | if (info->buf_start < info->buf_count) |
| 813 | /* Has just send a new command? */ |
| 814 | retval = info->data_buff[info->buf_start++]; |
| 815 | |
| 816 | return retval; |
| 817 | } |
| 818 | |
| 819 | static u16 pxa3xx_nand_read_word(struct mtd_info *mtd) |
| 820 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 821 | struct pxa3xx_nand_host *host = mtd->priv; |
| 822 | struct pxa3xx_nand_info *info = host->info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 823 | u16 retval = 0xFFFF; |
| 824 | |
| 825 | if (!(info->buf_start & 0x01) && info->buf_start < info->buf_count) { |
| 826 | retval = *((u16 *)(info->data_buff+info->buf_start)); |
| 827 | info->buf_start += 2; |
| 828 | } |
| 829 | return retval; |
| 830 | } |
| 831 | |
| 832 | static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) |
| 833 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 834 | struct pxa3xx_nand_host *host = mtd->priv; |
| 835 | struct pxa3xx_nand_info *info = host->info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 836 | int real_len = min_t(size_t, len, info->buf_count - info->buf_start); |
| 837 | |
| 838 | memcpy(buf, info->data_buff + info->buf_start, real_len); |
| 839 | info->buf_start += real_len; |
| 840 | } |
| 841 | |
| 842 | static void pxa3xx_nand_write_buf(struct mtd_info *mtd, |
| 843 | const uint8_t *buf, int len) |
| 844 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 845 | struct pxa3xx_nand_host *host = mtd->priv; |
| 846 | struct pxa3xx_nand_info *info = host->info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 847 | int real_len = min_t(size_t, len, info->buf_count - info->buf_start); |
| 848 | |
| 849 | memcpy(info->data_buff + info->buf_start, buf, real_len); |
| 850 | info->buf_start += real_len; |
| 851 | } |
| 852 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 853 | static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip) |
| 854 | { |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) |
| 859 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 860 | struct pxa3xx_nand_host *host = mtd->priv; |
| 861 | struct pxa3xx_nand_info *info = host->info_data; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 862 | |
| 863 | /* pxa3xx_nand_send_command has waited for command complete */ |
| 864 | if (this->state == FL_WRITING || this->state == FL_ERASING) { |
| 865 | if (info->retcode == ERR_NONE) |
| 866 | return 0; |
| 867 | else { |
| 868 | /* |
| 869 | * any error make it return 0x01 which will tell |
| 870 | * the caller the erase and write fail |
| 871 | */ |
| 872 | return 0x01; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 879 | static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, |
Enrico Scholz | c8c17c8 | 2008-08-29 12:59:51 +0200 | [diff] [blame] | 880 | const struct pxa3xx_nand_flash *f) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 881 | { |
| 882 | struct platform_device *pdev = info->pdev; |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 883 | struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 884 | struct pxa3xx_nand_host *host = info->host[info->cs]; |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 885 | uint32_t ndcr = 0x0; /* enable all interrupts */ |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 886 | |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 887 | if (f->page_size != 2048 && f->page_size != 512) { |
| 888 | dev_err(&pdev->dev, "Current only support 2048 and 512 size\n"); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 889 | return -EINVAL; |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 890 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 891 | |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 892 | if (f->flash_width != 16 && f->flash_width != 8) { |
| 893 | dev_err(&pdev->dev, "Only support 8bit and 16 bit!\n"); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 894 | return -EINVAL; |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 895 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 896 | |
| 897 | /* calculate flash information */ |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 898 | host->read_id_bytes = (f->page_size == 2048) ? 4 : 2; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 899 | |
| 900 | /* calculate addressing information */ |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 901 | host->col_addr_cycles = (f->page_size == 2048) ? 2 : 1; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 902 | |
| 903 | if (f->num_blocks * f->page_per_block > 65536) |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 904 | host->row_addr_cycles = 3; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 905 | else |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 906 | host->row_addr_cycles = 2; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 907 | |
| 908 | ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 909 | ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 910 | ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0; |
| 911 | ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0; |
| 912 | ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0; |
| 913 | ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0; |
| 914 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 915 | ndcr |= NDCR_RD_ID_CNT(host->read_id_bytes); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 916 | ndcr |= NDCR_SPARE_EN; /* enable spare by default */ |
| 917 | |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 918 | info->reg_ndcr = ndcr; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 919 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 920 | pxa3xx_nand_set_timing(host, f->timing); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 921 | return 0; |
| 922 | } |
| 923 | |
Mike Rapoport | f271049 | 2009-02-17 13:54:47 +0200 | [diff] [blame] | 924 | static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) |
| 925 | { |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 926 | /* |
| 927 | * We set 0 by hard coding here, for we don't support keep_config |
| 928 | * when there is more than one chip attached to the controller |
| 929 | */ |
| 930 | struct pxa3xx_nand_host *host = info->host[0]; |
Mike Rapoport | f271049 | 2009-02-17 13:54:47 +0200 | [diff] [blame] | 931 | uint32_t ndcr = nand_readl(info, NDCR); |
Mike Rapoport | f271049 | 2009-02-17 13:54:47 +0200 | [diff] [blame] | 932 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 933 | if (ndcr & NDCR_PAGE_SZ) { |
Ezequiel Garcia | 2128b08 | 2013-11-07 12:17:16 -0300 | [diff] [blame] | 934 | /* Controller's FIFO size */ |
| 935 | info->fifo_size = 2048; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 936 | host->read_id_bytes = 4; |
| 937 | } else { |
Ezequiel Garcia | 2128b08 | 2013-11-07 12:17:16 -0300 | [diff] [blame] | 938 | info->fifo_size = 512; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 939 | host->read_id_bytes = 2; |
| 940 | } |
| 941 | |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 942 | info->reg_ndcr = ndcr & ~NDCR_INT_MASK; |
| 943 | info->ndtr0cs0 = nand_readl(info, NDTR0CS0); |
| 944 | info->ndtr1cs0 = nand_readl(info, NDTR1CS0); |
Mike Rapoport | f271049 | 2009-02-17 13:54:47 +0200 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 948 | #ifdef ARCH_HAS_DMA |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 949 | static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) |
| 950 | { |
| 951 | struct platform_device *pdev = info->pdev; |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 952 | int data_desc_offset = info->buf_size - sizeof(struct pxa_dma_desc); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 953 | |
| 954 | if (use_dma == 0) { |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 955 | info->data_buff = kmalloc(info->buf_size, GFP_KERNEL); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 956 | if (info->data_buff == NULL) |
| 957 | return -ENOMEM; |
| 958 | return 0; |
| 959 | } |
| 960 | |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 961 | info->data_buff = dma_alloc_coherent(&pdev->dev, info->buf_size, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 962 | &info->data_buff_phys, GFP_KERNEL); |
| 963 | if (info->data_buff == NULL) { |
| 964 | dev_err(&pdev->dev, "failed to allocate dma buffer\n"); |
| 965 | return -ENOMEM; |
| 966 | } |
| 967 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 968 | info->data_desc = (void *)info->data_buff + data_desc_offset; |
| 969 | info->data_desc_addr = info->data_buff_phys + data_desc_offset; |
| 970 | |
| 971 | info->data_dma_ch = pxa_request_dma("nand-data", DMA_PRIO_LOW, |
| 972 | pxa3xx_nand_data_dma_irq, info); |
| 973 | if (info->data_dma_ch < 0) { |
| 974 | dev_err(&pdev->dev, "failed to request data dma\n"); |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 975 | dma_free_coherent(&pdev->dev, info->buf_size, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 976 | info->data_buff, info->data_buff_phys); |
| 977 | return info->data_dma_ch; |
| 978 | } |
| 979 | |
Ezequiel Garcia | 95b2656 | 2013-10-04 15:30:37 -0300 | [diff] [blame] | 980 | /* |
| 981 | * Now that DMA buffers are allocated we turn on |
| 982 | * DMA proper for I/O operations. |
| 983 | */ |
| 984 | info->use_dma = 1; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 985 | return 0; |
| 986 | } |
| 987 | |
Ezequiel Garcia | 498b614 | 2013-04-17 13:38:14 -0300 | [diff] [blame] | 988 | static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info) |
| 989 | { |
| 990 | struct platform_device *pdev = info->pdev; |
Ezequiel Garcia | 15b540c | 2013-12-10 09:57:15 -0300 | [diff] [blame] | 991 | if (info->use_dma) { |
Ezequiel Garcia | 498b614 | 2013-04-17 13:38:14 -0300 | [diff] [blame] | 992 | pxa_free_dma(info->data_dma_ch); |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 993 | dma_free_coherent(&pdev->dev, info->buf_size, |
Ezequiel Garcia | 498b614 | 2013-04-17 13:38:14 -0300 | [diff] [blame] | 994 | info->data_buff, info->data_buff_phys); |
| 995 | } else { |
| 996 | kfree(info->data_buff); |
| 997 | } |
| 998 | } |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 999 | #else |
| 1000 | static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) |
| 1001 | { |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 1002 | info->data_buff = kmalloc(info->buf_size, GFP_KERNEL); |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 1003 | if (info->data_buff == NULL) |
| 1004 | return -ENOMEM; |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info) |
| 1009 | { |
| 1010 | kfree(info->data_buff); |
| 1011 | } |
| 1012 | #endif |
Ezequiel Garcia | 498b614 | 2013-04-17 13:38:14 -0300 | [diff] [blame] | 1013 | |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1014 | static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1015 | { |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1016 | struct mtd_info *mtd; |
Ezequiel Garcia | 2d79ab1 | 2013-11-07 12:17:15 -0300 | [diff] [blame] | 1017 | struct nand_chip *chip; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1018 | int ret; |
Ezequiel Garcia | 2d79ab1 | 2013-11-07 12:17:15 -0300 | [diff] [blame] | 1019 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1020 | mtd = info->host[info->cs]->mtd; |
Ezequiel Garcia | 2d79ab1 | 2013-11-07 12:17:15 -0300 | [diff] [blame] | 1021 | chip = mtd->priv; |
| 1022 | |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1023 | /* use the common timing to make a try */ |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1024 | ret = pxa3xx_nand_config_flash(info, &builtin_flash_types[0]); |
| 1025 | if (ret) |
| 1026 | return ret; |
| 1027 | |
Ezequiel Garcia | 2d79ab1 | 2013-11-07 12:17:15 -0300 | [diff] [blame] | 1028 | chip->cmdfunc(mtd, NAND_CMD_RESET, 0, 0); |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1029 | if (info->is_ready) |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1030 | return 0; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1031 | |
| 1032 | return -ENODEV; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1033 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1034 | |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1035 | static int pxa3xx_nand_scan(struct mtd_info *mtd) |
| 1036 | { |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1037 | struct pxa3xx_nand_host *host = mtd->priv; |
| 1038 | struct pxa3xx_nand_info *info = host->info_data; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1039 | struct platform_device *pdev = info->pdev; |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 1040 | struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Lei Wen | 0fab028 | 2011-06-07 03:01:06 -0700 | [diff] [blame] | 1041 | struct nand_flash_dev pxa3xx_flash_ids[2], *def = NULL; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1042 | const struct pxa3xx_nand_flash *f = NULL; |
| 1043 | struct nand_chip *chip = mtd->priv; |
| 1044 | uint32_t id = -1; |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1045 | uint64_t chipsize; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1046 | int i, ret, num; |
| 1047 | |
| 1048 | if (pdata->keep_config && !pxa3xx_nand_detect_config(info)) |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1049 | goto KEEP_CONFIG; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1050 | |
| 1051 | ret = pxa3xx_nand_sensing(info); |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1052 | if (ret) { |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1053 | dev_info(&info->pdev->dev, "There is no chip on cs %d!\n", |
| 1054 | info->cs); |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1055 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1056 | return ret; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | chip->cmdfunc(mtd, NAND_CMD_READID, 0, 0); |
| 1060 | id = *((uint16_t *)(info->data_buff)); |
| 1061 | if (id != 0) |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 1062 | dev_info(&info->pdev->dev, "Detect a flash id %x\n", id); |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1063 | else { |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 1064 | dev_warn(&info->pdev->dev, |
| 1065 | "Read out ID 0, potential timing set wrong!!\n"); |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1066 | |
| 1067 | return -EINVAL; |
| 1068 | } |
| 1069 | |
| 1070 | num = ARRAY_SIZE(builtin_flash_types) + pdata->num_flash - 1; |
| 1071 | for (i = 0; i < num; i++) { |
| 1072 | if (i < pdata->num_flash) |
| 1073 | f = pdata->flash + i; |
| 1074 | else |
| 1075 | f = &builtin_flash_types[i - pdata->num_flash + 1]; |
| 1076 | |
| 1077 | /* find the chip in default list */ |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1078 | if (f->chip_id == id) |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1079 | break; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1082 | if (i >= (ARRAY_SIZE(builtin_flash_types) + pdata->num_flash - 1)) { |
Lei Wen | da675b4 | 2011-07-14 20:44:31 -0700 | [diff] [blame] | 1083 | dev_err(&info->pdev->dev, "ERROR!! flash not defined!!!\n"); |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1084 | |
| 1085 | return -EINVAL; |
| 1086 | } |
| 1087 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1088 | ret = pxa3xx_nand_config_flash(info, f); |
| 1089 | if (ret) { |
| 1090 | dev_err(&info->pdev->dev, "ERROR! Configure failed\n"); |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1094 | pxa3xx_flash_ids[0].name = f->name; |
Artem Bityutskiy | 68aa352de | 2013-03-04 16:05:00 +0200 | [diff] [blame] | 1095 | pxa3xx_flash_ids[0].dev_id = (f->chip_id >> 8) & 0xffff; |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1096 | pxa3xx_flash_ids[0].pagesize = f->page_size; |
| 1097 | chipsize = (uint64_t)f->num_blocks * f->page_per_block * f->page_size; |
| 1098 | pxa3xx_flash_ids[0].chipsize = chipsize >> 20; |
| 1099 | pxa3xx_flash_ids[0].erasesize = f->page_size * f->page_per_block; |
| 1100 | if (f->flash_width == 16) |
| 1101 | pxa3xx_flash_ids[0].options = NAND_BUSWIDTH_16; |
Lei Wen | 0fab028 | 2011-06-07 03:01:06 -0700 | [diff] [blame] | 1102 | pxa3xx_flash_ids[1].name = NULL; |
| 1103 | def = pxa3xx_flash_ids; |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1104 | KEEP_CONFIG: |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1105 | chip->ecc.mode = NAND_ECC_HW; |
Ezequiel Garcia | 0a3f3a1 | 2013-11-07 12:17:17 -0300 | [diff] [blame] | 1106 | chip->ecc.size = info->fifo_size; |
Mike Dunn | 6a918ba | 2012-03-11 14:21:11 -0700 | [diff] [blame] | 1107 | chip->ecc.strength = 1; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1108 | |
Ezequiel Garcia | 48cf7ef | 2013-08-12 14:14:55 -0300 | [diff] [blame] | 1109 | if (info->reg_ndcr & NDCR_DWIDTH_M) |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1110 | chip->options |= NAND_BUSWIDTH_16; |
| 1111 | |
Lei Wen | 0fab028 | 2011-06-07 03:01:06 -0700 | [diff] [blame] | 1112 | if (nand_scan_ident(mtd, 1, def)) |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1113 | return -ENODEV; |
| 1114 | /* calculate addressing information */ |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1115 | if (mtd->writesize >= 2048) |
| 1116 | host->col_addr_cycles = 2; |
| 1117 | else |
| 1118 | host->col_addr_cycles = 1; |
| 1119 | |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 1120 | /* release the initial buffer */ |
| 1121 | kfree(info->data_buff); |
| 1122 | |
| 1123 | /* allocate the real data + oob buffer */ |
| 1124 | info->buf_size = mtd->writesize + mtd->oobsize; |
| 1125 | ret = pxa3xx_nand_init_buff(info); |
| 1126 | if (ret) |
| 1127 | return ret; |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1128 | info->oob_buff = info->data_buff + mtd->writesize; |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 1129 | |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1130 | if ((mtd->size >> chip->page_shift) > 65536) |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1131 | host->row_addr_cycles = 3; |
Lei Wen | 4332c11 | 2011-03-03 11:27:01 +0800 | [diff] [blame] | 1132 | else |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1133 | host->row_addr_cycles = 2; |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1134 | return nand_scan_tail(mtd); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1135 | } |
| 1136 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1137 | static int alloc_nand_resource(struct platform_device *pdev) |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1138 | { |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1139 | struct pxa3xx_nand_platform_data *pdata; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1140 | struct pxa3xx_nand_info *info; |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1141 | struct pxa3xx_nand_host *host; |
Haojian Zhuang | 6e308f8 | 2012-08-20 13:40:31 +0800 | [diff] [blame] | 1142 | struct nand_chip *chip = NULL; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1143 | struct mtd_info *mtd; |
| 1144 | struct resource *r; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1145 | int ret, irq, cs; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1146 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 1147 | pdata = dev_get_platdata(&pdev->dev); |
Ezequiel Garcia | 4c073cd | 2013-04-17 13:38:09 -0300 | [diff] [blame] | 1148 | info = devm_kzalloc(&pdev->dev, sizeof(*info) + (sizeof(*mtd) + |
| 1149 | sizeof(*host)) * pdata->num_cs, GFP_KERNEL); |
| 1150 | if (!info) |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1151 | return -ENOMEM; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1152 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1153 | info->pdev = pdev; |
Ezequiel Garcia | c7e9c7e | 2013-11-07 12:17:14 -0300 | [diff] [blame] | 1154 | info->variant = pxa3xx_nand_get_variant(pdev); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1155 | for (cs = 0; cs < pdata->num_cs; cs++) { |
| 1156 | mtd = (struct mtd_info *)((unsigned int)&info[1] + |
| 1157 | (sizeof(*mtd) + sizeof(*host)) * cs); |
| 1158 | chip = (struct nand_chip *)(&mtd[1]); |
| 1159 | host = (struct pxa3xx_nand_host *)chip; |
| 1160 | info->host[cs] = host; |
| 1161 | host->mtd = mtd; |
| 1162 | host->cs = cs; |
| 1163 | host->info_data = info; |
| 1164 | mtd->priv = host; |
| 1165 | mtd->owner = THIS_MODULE; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1166 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1167 | chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; |
| 1168 | chip->ecc.write_page = pxa3xx_nand_write_page_hwecc; |
| 1169 | chip->controller = &info->controller; |
| 1170 | chip->waitfunc = pxa3xx_nand_waitfunc; |
| 1171 | chip->select_chip = pxa3xx_nand_select_chip; |
| 1172 | chip->cmdfunc = pxa3xx_nand_cmdfunc; |
| 1173 | chip->read_word = pxa3xx_nand_read_word; |
| 1174 | chip->read_byte = pxa3xx_nand_read_byte; |
| 1175 | chip->read_buf = pxa3xx_nand_read_buf; |
| 1176 | chip->write_buf = pxa3xx_nand_write_buf; |
Ezequiel Garcia | 664c7f5 | 2013-11-07 12:17:12 -0300 | [diff] [blame] | 1177 | chip->options |= NAND_NO_SUBPAGE_WRITE; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1178 | } |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1179 | |
| 1180 | spin_lock_init(&chip->controller->lock); |
| 1181 | init_waitqueue_head(&chip->controller->wq); |
Ezequiel Garcia | 9ca7944 | 2013-04-17 13:38:11 -0300 | [diff] [blame] | 1182 | info->clk = devm_clk_get(&pdev->dev, NULL); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1183 | if (IS_ERR(info->clk)) { |
| 1184 | dev_err(&pdev->dev, "failed to get nand clock\n"); |
Ezequiel Garcia | 4c073cd | 2013-04-17 13:38:09 -0300 | [diff] [blame] | 1185 | return PTR_ERR(info->clk); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1186 | } |
Ezequiel Garcia | 1f8eaff | 2013-04-17 13:38:13 -0300 | [diff] [blame] | 1187 | ret = clk_prepare_enable(info->clk); |
| 1188 | if (ret < 0) |
| 1189 | return ret; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1190 | |
Ezequiel Garcia | 6b45c1e | 2013-08-12 14:14:58 -0300 | [diff] [blame] | 1191 | if (use_dma) { |
| 1192 | /* |
| 1193 | * This is a dirty hack to make this driver work from |
| 1194 | * devicetree bindings. It can be removed once we have |
| 1195 | * a prober DMA controller framework for DT. |
| 1196 | */ |
| 1197 | if (pdev->dev.of_node && |
| 1198 | of_machine_is_compatible("marvell,pxa3xx")) { |
| 1199 | info->drcmr_dat = 97; |
| 1200 | info->drcmr_cmd = 99; |
| 1201 | } else { |
| 1202 | r = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 1203 | if (r == NULL) { |
| 1204 | dev_err(&pdev->dev, |
| 1205 | "no resource defined for data DMA\n"); |
| 1206 | ret = -ENXIO; |
| 1207 | goto fail_disable_clk; |
| 1208 | } |
| 1209 | info->drcmr_dat = r->start; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1210 | |
Ezequiel Garcia | 6b45c1e | 2013-08-12 14:14:58 -0300 | [diff] [blame] | 1211 | r = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 1212 | if (r == NULL) { |
| 1213 | dev_err(&pdev->dev, |
| 1214 | "no resource defined for cmd DMA\n"); |
| 1215 | ret = -ENXIO; |
| 1216 | goto fail_disable_clk; |
| 1217 | } |
| 1218 | info->drcmr_cmd = r->start; |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1219 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1220 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1221 | |
| 1222 | irq = platform_get_irq(pdev, 0); |
| 1223 | if (irq < 0) { |
| 1224 | dev_err(&pdev->dev, "no IRQ resource defined\n"); |
| 1225 | ret = -ENXIO; |
Ezequiel Garcia | 9ca7944 | 2013-04-17 13:38:11 -0300 | [diff] [blame] | 1226 | goto fail_disable_clk; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Ezequiel Garcia | 0ddd846 | 2013-04-17 13:38:10 -0300 | [diff] [blame] | 1230 | info->mmio_base = devm_ioremap_resource(&pdev->dev, r); |
| 1231 | if (IS_ERR(info->mmio_base)) { |
| 1232 | ret = PTR_ERR(info->mmio_base); |
Ezequiel Garcia | 9ca7944 | 2013-04-17 13:38:11 -0300 | [diff] [blame] | 1233 | goto fail_disable_clk; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1234 | } |
Haojian Zhuang | 8638fac | 2009-09-10 14:11:44 +0800 | [diff] [blame] | 1235 | info->mmio_phys = r->start; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1236 | |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 1237 | /* Allocate a buffer to allow flash detection */ |
| 1238 | info->buf_size = INIT_BUFFER_SIZE; |
| 1239 | info->data_buff = kmalloc(info->buf_size, GFP_KERNEL); |
| 1240 | if (info->data_buff == NULL) { |
| 1241 | ret = -ENOMEM; |
Ezequiel Garcia | 9ca7944 | 2013-04-17 13:38:11 -0300 | [diff] [blame] | 1242 | goto fail_disable_clk; |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 1243 | } |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1244 | |
Haojian Zhuang | 346e125 | 2009-09-10 14:27:23 +0800 | [diff] [blame] | 1245 | /* initialize all interrupts to be disabled */ |
| 1246 | disable_int(info, NDSR_MASK); |
| 1247 | |
Michael Opdenacker | b1eb234 | 2013-10-13 08:21:32 +0200 | [diff] [blame] | 1248 | ret = request_irq(irq, pxa3xx_nand_irq, 0, pdev->name, info); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1249 | if (ret < 0) { |
| 1250 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
| 1251 | goto fail_free_buf; |
| 1252 | } |
| 1253 | |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1254 | platform_set_drvdata(pdev, info); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1255 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1256 | return 0; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1257 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1258 | fail_free_buf: |
Lei Wen | 401e67e | 2011-02-28 10:32:14 +0800 | [diff] [blame] | 1259 | free_irq(irq, info); |
Ezequiel Garcia | 62e8b85 | 2013-10-04 15:30:38 -0300 | [diff] [blame] | 1260 | kfree(info->data_buff); |
Ezequiel Garcia | 9ca7944 | 2013-04-17 13:38:11 -0300 | [diff] [blame] | 1261 | fail_disable_clk: |
Ezequiel Garcia | fb32061 | 2013-04-17 13:38:12 -0300 | [diff] [blame] | 1262 | clk_disable_unprepare(info->clk); |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1263 | return ret; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | static int pxa3xx_nand_remove(struct platform_device *pdev) |
| 1267 | { |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1268 | struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1269 | struct pxa3xx_nand_platform_data *pdata; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1270 | int irq, cs; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1271 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1272 | if (!info) |
| 1273 | return 0; |
| 1274 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 1275 | pdata = dev_get_platdata(&pdev->dev); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1276 | |
Haojian Zhuang | dbf5986 | 2009-09-10 14:22:55 +0800 | [diff] [blame] | 1277 | irq = platform_get_irq(pdev, 0); |
| 1278 | if (irq >= 0) |
| 1279 | free_irq(irq, info); |
Ezequiel Garcia | 498b614 | 2013-04-17 13:38:14 -0300 | [diff] [blame] | 1280 | pxa3xx_nand_free_buff(info); |
Mike Rapoport | 82a72d1 | 2009-02-17 13:54:46 +0200 | [diff] [blame] | 1281 | |
Ezequiel Garcia | fb32061 | 2013-04-17 13:38:12 -0300 | [diff] [blame] | 1282 | clk_disable_unprepare(info->clk); |
Mike Rapoport | 82a72d1 | 2009-02-17 13:54:46 +0200 | [diff] [blame] | 1283 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1284 | for (cs = 0; cs < pdata->num_cs; cs++) |
| 1285 | nand_release(info->host[cs]->mtd); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1286 | return 0; |
| 1287 | } |
| 1288 | |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1289 | static int pxa3xx_nand_probe_dt(struct platform_device *pdev) |
| 1290 | { |
| 1291 | struct pxa3xx_nand_platform_data *pdata; |
| 1292 | struct device_node *np = pdev->dev.of_node; |
| 1293 | const struct of_device_id *of_id = |
| 1294 | of_match_device(pxa3xx_nand_dt_ids, &pdev->dev); |
| 1295 | |
| 1296 | if (!of_id) |
| 1297 | return 0; |
| 1298 | |
| 1299 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1300 | if (!pdata) |
| 1301 | return -ENOMEM; |
| 1302 | |
| 1303 | if (of_get_property(np, "marvell,nand-enable-arbiter", NULL)) |
| 1304 | pdata->enable_arbiter = 1; |
| 1305 | if (of_get_property(np, "marvell,nand-keep-config", NULL)) |
| 1306 | pdata->keep_config = 1; |
| 1307 | of_property_read_u32(np, "num-cs", &pdata->num_cs); |
| 1308 | |
| 1309 | pdev->dev.platform_data = pdata; |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1313 | |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1314 | static int pxa3xx_nand_probe(struct platform_device *pdev) |
| 1315 | { |
| 1316 | struct pxa3xx_nand_platform_data *pdata; |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1317 | struct mtd_part_parser_data ppdata = {}; |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1318 | struct pxa3xx_nand_info *info; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1319 | int ret, cs, probe_success; |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1320 | |
Ezequiel Garcia | f4db2e3 | 2013-08-12 14:14:56 -0300 | [diff] [blame] | 1321 | #ifndef ARCH_HAS_DMA |
| 1322 | if (use_dma) { |
| 1323 | use_dma = 0; |
| 1324 | dev_warn(&pdev->dev, |
| 1325 | "This platform can't do DMA on this device\n"); |
| 1326 | } |
| 1327 | #endif |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1328 | ret = pxa3xx_nand_probe_dt(pdev); |
| 1329 | if (ret) |
| 1330 | return ret; |
| 1331 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 1332 | pdata = dev_get_platdata(&pdev->dev); |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1333 | if (!pdata) { |
| 1334 | dev_err(&pdev->dev, "no platform data defined\n"); |
| 1335 | return -ENODEV; |
| 1336 | } |
| 1337 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1338 | ret = alloc_nand_resource(pdev); |
| 1339 | if (ret) { |
| 1340 | dev_err(&pdev->dev, "alloc nand resource failed\n"); |
| 1341 | return ret; |
| 1342 | } |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1343 | |
Lei Wen | d456882 | 2011-07-14 20:44:32 -0700 | [diff] [blame] | 1344 | info = platform_get_drvdata(pdev); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1345 | probe_success = 0; |
| 1346 | for (cs = 0; cs < pdata->num_cs; cs++) { |
Ezequiel Garcia | b7655bc | 2013-08-12 14:14:52 -0300 | [diff] [blame] | 1347 | struct mtd_info *mtd = info->host[cs]->mtd; |
Ezequiel Garcia | f455578 | 2013-08-12 14:14:53 -0300 | [diff] [blame] | 1348 | |
Ezequiel Garcia | 18a84e9 | 2013-10-19 18:19:25 -0300 | [diff] [blame] | 1349 | /* |
| 1350 | * The mtd name matches the one used in 'mtdparts' kernel |
| 1351 | * parameter. This name cannot be changed or otherwise |
| 1352 | * user's mtd partitions configuration would get broken. |
| 1353 | */ |
| 1354 | mtd->name = "pxa3xx_nand-0"; |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1355 | info->cs = cs; |
Ezequiel Garcia | b7655bc | 2013-08-12 14:14:52 -0300 | [diff] [blame] | 1356 | ret = pxa3xx_nand_scan(mtd); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1357 | if (ret) { |
| 1358 | dev_warn(&pdev->dev, "failed to scan nand at cs %d\n", |
| 1359 | cs); |
| 1360 | continue; |
| 1361 | } |
| 1362 | |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1363 | ppdata.of_node = pdev->dev.of_node; |
Ezequiel Garcia | b7655bc | 2013-08-12 14:14:52 -0300 | [diff] [blame] | 1364 | ret = mtd_device_parse_register(mtd, NULL, |
Daniel Mack | 1e7ba63 | 2012-07-22 19:51:02 +0200 | [diff] [blame] | 1365 | &ppdata, pdata->parts[cs], |
Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 1366 | pdata->nr_parts[cs]); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1367 | if (!ret) |
| 1368 | probe_success = 1; |
| 1369 | } |
| 1370 | |
| 1371 | if (!probe_success) { |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1372 | pxa3xx_nand_remove(pdev); |
| 1373 | return -ENODEV; |
| 1374 | } |
| 1375 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1376 | return 0; |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1377 | } |
| 1378 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1379 | #ifdef CONFIG_PM |
| 1380 | static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state) |
| 1381 | { |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1382 | struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1383 | struct pxa3xx_nand_platform_data *pdata; |
| 1384 | struct mtd_info *mtd; |
| 1385 | int cs; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1386 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 1387 | pdata = dev_get_platdata(&pdev->dev); |
Lei Wen | f8155a4 | 2011-02-28 10:32:11 +0800 | [diff] [blame] | 1388 | if (info->state) { |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1389 | dev_err(&pdev->dev, "driver busy, state = %d\n", info->state); |
| 1390 | return -EAGAIN; |
| 1391 | } |
| 1392 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1393 | for (cs = 0; cs < pdata->num_cs; cs++) { |
| 1394 | mtd = info->host[cs]->mtd; |
Artem Bityutskiy | 3fe4bae | 2011-12-23 19:25:16 +0200 | [diff] [blame] | 1395 | mtd_suspend(mtd); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | static int pxa3xx_nand_resume(struct platform_device *pdev) |
| 1402 | { |
Lei Wen | e353a20 | 2011-03-03 11:08:30 +0800 | [diff] [blame] | 1403 | struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1404 | struct pxa3xx_nand_platform_data *pdata; |
| 1405 | struct mtd_info *mtd; |
| 1406 | int cs; |
Lei Wen | 051fc41 | 2011-07-14 20:44:30 -0700 | [diff] [blame] | 1407 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 1408 | pdata = dev_get_platdata(&pdev->dev); |
Lei Wen | 051fc41 | 2011-07-14 20:44:30 -0700 | [diff] [blame] | 1409 | /* We don't want to handle interrupt without calling mtd routine */ |
| 1410 | disable_int(info, NDCR_INT_MASK); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1411 | |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1412 | /* |
| 1413 | * Directly set the chip select to a invalid value, |
| 1414 | * then the driver would reset the timing according |
| 1415 | * to current chip select at the beginning of cmdfunc |
| 1416 | */ |
| 1417 | info->cs = 0xff; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1418 | |
Lei Wen | 051fc41 | 2011-07-14 20:44:30 -0700 | [diff] [blame] | 1419 | /* |
| 1420 | * As the spec says, the NDSR would be updated to 0x1800 when |
| 1421 | * doing the nand_clk disable/enable. |
| 1422 | * To prevent it damaging state machine of the driver, clear |
| 1423 | * all status before resume |
| 1424 | */ |
| 1425 | nand_writel(info, NDSR, NDSR_MASK); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1426 | for (cs = 0; cs < pdata->num_cs; cs++) { |
| 1427 | mtd = info->host[cs]->mtd; |
Artem Bityutskiy | ead995f | 2011-12-23 19:31:25 +0200 | [diff] [blame] | 1428 | mtd_resume(mtd); |
Lei Wen | f3c8cfc | 2011-07-14 20:44:33 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Lei Wen | 18c81b1 | 2010-08-17 17:25:57 +0800 | [diff] [blame] | 1431 | return 0; |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1432 | } |
| 1433 | #else |
| 1434 | #define pxa3xx_nand_suspend NULL |
| 1435 | #define pxa3xx_nand_resume NULL |
| 1436 | #endif |
| 1437 | |
| 1438 | static struct platform_driver pxa3xx_nand_driver = { |
| 1439 | .driver = { |
| 1440 | .name = "pxa3xx-nand", |
Sachin Kamat | 5576bc7 | 2013-09-30 15:10:24 +0530 | [diff] [blame] | 1441 | .of_match_table = pxa3xx_nand_dt_ids, |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1442 | }, |
| 1443 | .probe = pxa3xx_nand_probe, |
| 1444 | .remove = pxa3xx_nand_remove, |
| 1445 | .suspend = pxa3xx_nand_suspend, |
| 1446 | .resume = pxa3xx_nand_resume, |
| 1447 | }; |
| 1448 | |
Axel Lin | f99640d | 2011-11-27 20:45:03 +0800 | [diff] [blame] | 1449 | module_platform_driver(pxa3xx_nand_driver); |
eric miao | fe69af0 | 2008-02-14 15:48:23 +0800 | [diff] [blame] | 1450 | |
| 1451 | MODULE_LICENSE("GPL"); |
| 1452 | MODULE_DESCRIPTION("PXA3xx NAND controller driver"); |