diff options
Diffstat (limited to 'drivers/mtd/nand/pxa3xx_nand.c')
-rw-r--r-- | drivers/mtd/nand/pxa3xx_nand.c | 348 |
1 files changed, 94 insertions, 254 deletions
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 4d01cda68844..17f8518cc5eb 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c | |||
@@ -117,7 +117,7 @@ struct pxa3xx_nand_info { | |||
117 | struct nand_chip nand_chip; | 117 | struct nand_chip nand_chip; |
118 | 118 | ||
119 | struct platform_device *pdev; | 119 | struct platform_device *pdev; |
120 | const struct pxa3xx_nand_flash *flash_info; | 120 | struct pxa3xx_nand_cmdset *cmdset; |
121 | 121 | ||
122 | struct clk *clk; | 122 | struct clk *clk; |
123 | void __iomem *mmio_base; | 123 | void __iomem *mmio_base; |
@@ -131,6 +131,7 @@ struct pxa3xx_nand_info { | |||
131 | int drcmr_cmd; | 131 | int drcmr_cmd; |
132 | 132 | ||
133 | unsigned char *data_buff; | 133 | unsigned char *data_buff; |
134 | unsigned char *oob_buff; | ||
134 | dma_addr_t data_buff_phys; | 135 | dma_addr_t data_buff_phys; |
135 | size_t data_buff_size; | 136 | size_t data_buff_size; |
136 | int data_dma_ch; | 137 | int data_dma_ch; |
@@ -149,7 +150,8 @@ struct pxa3xx_nand_info { | |||
149 | int use_ecc; /* use HW ECC ? */ | 150 | int use_ecc; /* use HW ECC ? */ |
150 | int use_dma; /* use DMA ? */ | 151 | int use_dma; /* use DMA ? */ |
151 | 152 | ||
152 | size_t data_size; /* data size in FIFO */ | 153 | unsigned int page_size; /* page size of attached chip */ |
154 | unsigned int data_size; /* data size in FIFO */ | ||
153 | int retcode; | 155 | int retcode; |
154 | struct completion cmd_complete; | 156 | struct completion cmd_complete; |
155 | 157 | ||
@@ -158,6 +160,10 @@ struct pxa3xx_nand_info { | |||
158 | uint32_t ndcb1; | 160 | uint32_t ndcb1; |
159 | uint32_t ndcb2; | 161 | uint32_t ndcb2; |
160 | 162 | ||
163 | /* timing calcuted from setting */ | ||
164 | uint32_t ndtr0cs0; | ||
165 | uint32_t ndtr1cs0; | ||
166 | |||
161 | /* calculated from pxa3xx_nand_flash data */ | 167 | /* calculated from pxa3xx_nand_flash data */ |
162 | size_t oob_size; | 168 | size_t oob_size; |
163 | size_t read_id_bytes; | 169 | size_t read_id_bytes; |
@@ -174,23 +180,7 @@ MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW"); | |||
174 | * Default NAND flash controller configuration setup by the | 180 | * Default NAND flash controller configuration setup by the |
175 | * bootloader. This configuration is used only when pdata->keep_config is set | 181 | * bootloader. This configuration is used only when pdata->keep_config is set |
176 | */ | 182 | */ |
177 | static struct pxa3xx_nand_timing default_timing; | 183 | static struct pxa3xx_nand_cmdset default_cmdset = { |
178 | static struct pxa3xx_nand_flash default_flash; | ||
179 | |||
180 | static struct pxa3xx_nand_cmdset smallpage_cmdset = { | ||
181 | .read1 = 0x0000, | ||
182 | .read2 = 0x0050, | ||
183 | .program = 0x1080, | ||
184 | .read_status = 0x0070, | ||
185 | .read_id = 0x0090, | ||
186 | .erase = 0xD060, | ||
187 | .reset = 0x00FF, | ||
188 | .lock = 0x002A, | ||
189 | .unlock = 0x2423, | ||
190 | .lock_status = 0x007A, | ||
191 | }; | ||
192 | |||
193 | static struct pxa3xx_nand_cmdset largepage_cmdset = { | ||
194 | .read1 = 0x3000, | 184 | .read1 = 0x3000, |
195 | .read2 = 0x0050, | 185 | .read2 = 0x0050, |
196 | .program = 0x1080, | 186 | .program = 0x1080, |
@@ -203,142 +193,27 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = { | |||
203 | .lock_status = 0x007A, | 193 | .lock_status = 0x007A, |
204 | }; | 194 | }; |
205 | 195 | ||
206 | #ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN | 196 | static struct pxa3xx_nand_timing timing[] = { |
207 | static struct pxa3xx_nand_timing samsung512MbX16_timing = { | 197 | { 40, 80, 60, 100, 80, 100, 90000, 400, 40, }, |
208 | .tCH = 10, | 198 | { 10, 0, 20, 40, 30, 40, 11123, 110, 10, }, |
209 | .tCS = 0, | 199 | { 10, 25, 15, 25, 15, 30, 25000, 60, 10, }, |
210 | .tWH = 20, | 200 | { 10, 35, 15, 25, 15, 25, 25000, 60, 10, }, |
211 | .tWP = 40, | ||
212 | .tRH = 30, | ||
213 | .tRP = 40, | ||
214 | .tR = 11123, | ||
215 | .tWHR = 110, | ||
216 | .tAR = 10, | ||
217 | }; | ||
218 | |||
219 | static struct pxa3xx_nand_flash samsung512MbX16 = { | ||
220 | .timing = &samsung512MbX16_timing, | ||
221 | .cmdset = &smallpage_cmdset, | ||
222 | .page_per_block = 32, | ||
223 | .page_size = 512, | ||
224 | .flash_width = 16, | ||
225 | .dfc_width = 16, | ||
226 | .num_blocks = 4096, | ||
227 | .chip_id = 0x46ec, | ||
228 | }; | ||
229 | |||
230 | static struct pxa3xx_nand_flash samsung2GbX8 = { | ||
231 | .timing = &samsung512MbX16_timing, | ||
232 | .cmdset = &smallpage_cmdset, | ||
233 | .page_per_block = 64, | ||
234 | .page_size = 2048, | ||
235 | .flash_width = 8, | ||
236 | .dfc_width = 8, | ||
237 | .num_blocks = 2048, | ||
238 | .chip_id = 0xdaec, | ||
239 | }; | 201 | }; |
240 | 202 | ||
241 | static struct pxa3xx_nand_flash samsung32GbX8 = { | 203 | static struct pxa3xx_nand_flash builtin_flash_types[] = { |
242 | .timing = &samsung512MbX16_timing, | 204 | { 0, 0, 2048, 8, 8, 0, &default_cmdset, &timing[0] }, |
243 | .cmdset = &smallpage_cmdset, | 205 | { 0x46ec, 32, 512, 16, 16, 4096, &default_cmdset, &timing[1] }, |
244 | .page_per_block = 128, | 206 | { 0xdaec, 64, 2048, 8, 8, 2048, &default_cmdset, &timing[1] }, |
245 | .page_size = 4096, | 207 | { 0xd7ec, 128, 4096, 8, 8, 8192, &default_cmdset, &timing[1] }, |
246 | .flash_width = 8, | 208 | { 0xa12c, 64, 2048, 8, 8, 1024, &default_cmdset, &timing[2] }, |
247 | .dfc_width = 8, | 209 | { 0xb12c, 64, 2048, 16, 16, 1024, &default_cmdset, &timing[2] }, |
248 | .num_blocks = 8192, | 210 | { 0xdc2c, 64, 2048, 8, 8, 4096, &default_cmdset, &timing[2] }, |
249 | .chip_id = 0xd7ec, | 211 | { 0xcc2c, 64, 2048, 16, 16, 4096, &default_cmdset, &timing[2] }, |
212 | { 0xba20, 64, 2048, 16, 16, 2048, &default_cmdset, &timing[3] }, | ||
250 | }; | 213 | }; |
251 | 214 | ||
252 | static struct pxa3xx_nand_timing micron_timing = { | 215 | /* Define a default flash type setting serve as flash detecting only */ |
253 | .tCH = 10, | 216 | #define DEFAULT_FLASH_TYPE (&builtin_flash_types[0]) |
254 | .tCS = 25, | ||
255 | .tWH = 15, | ||
256 | .tWP = 25, | ||
257 | .tRH = 15, | ||
258 | .tRP = 30, | ||
259 | .tR = 25000, | ||
260 | .tWHR = 60, | ||
261 | .tAR = 10, | ||
262 | }; | ||
263 | |||
264 | static struct pxa3xx_nand_flash micron1GbX8 = { | ||
265 | .timing = µn_timing, | ||
266 | .cmdset = &largepage_cmdset, | ||
267 | .page_per_block = 64, | ||
268 | .page_size = 2048, | ||
269 | .flash_width = 8, | ||
270 | .dfc_width = 8, | ||
271 | .num_blocks = 1024, | ||
272 | .chip_id = 0xa12c, | ||
273 | }; | ||
274 | |||
275 | static struct pxa3xx_nand_flash micron1GbX16 = { | ||
276 | .timing = µn_timing, | ||
277 | .cmdset = &largepage_cmdset, | ||
278 | .page_per_block = 64, | ||
279 | .page_size = 2048, | ||
280 | .flash_width = 16, | ||
281 | .dfc_width = 16, | ||
282 | .num_blocks = 1024, | ||
283 | .chip_id = 0xb12c, | ||
284 | }; | ||
285 | |||
286 | static struct pxa3xx_nand_flash micron4GbX8 = { | ||
287 | .timing = µn_timing, | ||
288 | .cmdset = &largepage_cmdset, | ||
289 | .page_per_block = 64, | ||
290 | .page_size = 2048, | ||
291 | .flash_width = 8, | ||
292 | .dfc_width = 8, | ||
293 | .num_blocks = 4096, | ||
294 | .chip_id = 0xdc2c, | ||
295 | }; | ||
296 | |||
297 | static struct pxa3xx_nand_flash micron4GbX16 = { | ||
298 | .timing = µn_timing, | ||
299 | .cmdset = &largepage_cmdset, | ||
300 | .page_per_block = 64, | ||
301 | .page_size = 2048, | ||
302 | .flash_width = 16, | ||
303 | .dfc_width = 16, | ||
304 | .num_blocks = 4096, | ||
305 | .chip_id = 0xcc2c, | ||
306 | }; | ||
307 | |||
308 | static struct pxa3xx_nand_timing stm2GbX16_timing = { | ||
309 | .tCH = 10, | ||
310 | .tCS = 35, | ||
311 | .tWH = 15, | ||
312 | .tWP = 25, | ||
313 | .tRH = 15, | ||
314 | .tRP = 25, | ||
315 | .tR = 25000, | ||
316 | .tWHR = 60, | ||
317 | .tAR = 10, | ||
318 | }; | ||
319 | |||
320 | static struct pxa3xx_nand_flash stm2GbX16 = { | ||
321 | .timing = &stm2GbX16_timing, | ||
322 | .cmdset = &largepage_cmdset, | ||
323 | .page_per_block = 64, | ||
324 | .page_size = 2048, | ||
325 | .flash_width = 16, | ||
326 | .dfc_width = 16, | ||
327 | .num_blocks = 2048, | ||
328 | .chip_id = 0xba20, | ||
329 | }; | ||
330 | |||
331 | static struct pxa3xx_nand_flash *builtin_flash_types[] = { | ||
332 | &samsung512MbX16, | ||
333 | &samsung2GbX8, | ||
334 | &samsung32GbX8, | ||
335 | µn1GbX8, | ||
336 | µn1GbX16, | ||
337 | µn4GbX8, | ||
338 | µn4GbX16, | ||
339 | &stm2GbX16, | ||
340 | }; | ||
341 | #endif /* CONFIG_MTD_NAND_PXA3xx_BUILTIN */ | ||
342 | 217 | ||
343 | #define NDTR0_tCH(c) (min((c), 7) << 19) | 218 | #define NDTR0_tCH(c) (min((c), 7) << 19) |
344 | #define NDTR0_tCS(c) (min((c), 7) << 16) | 219 | #define NDTR0_tCS(c) (min((c), 7) << 16) |
@@ -351,23 +226,9 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = { | |||
351 | #define NDTR1_tWHR(c) (min((c), 15) << 4) | 226 | #define NDTR1_tWHR(c) (min((c), 15) << 4) |
352 | #define NDTR1_tAR(c) (min((c), 15) << 0) | 227 | #define NDTR1_tAR(c) (min((c), 15) << 0) |
353 | 228 | ||
354 | #define tCH_NDTR0(r) (((r) >> 19) & 0x7) | ||
355 | #define tCS_NDTR0(r) (((r) >> 16) & 0x7) | ||
356 | #define tWH_NDTR0(r) (((r) >> 11) & 0x7) | ||
357 | #define tWP_NDTR0(r) (((r) >> 8) & 0x7) | ||
358 | #define tRH_NDTR0(r) (((r) >> 3) & 0x7) | ||
359 | #define tRP_NDTR0(r) (((r) >> 0) & 0x7) | ||
360 | |||
361 | #define tR_NDTR1(r) (((r) >> 16) & 0xffff) | ||
362 | #define tWHR_NDTR1(r) (((r) >> 4) & 0xf) | ||
363 | #define tAR_NDTR1(r) (((r) >> 0) & 0xf) | ||
364 | |||
365 | /* convert nano-seconds to nand flash controller clock cycles */ | 229 | /* convert nano-seconds to nand flash controller clock cycles */ |
366 | #define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000) | 230 | #define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000) |
367 | 231 | ||
368 | /* convert nand flash controller clock cycles to nano-seconds */ | ||
369 | #define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000)) | ||
370 | |||
371 | static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, | 232 | static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, |
372 | const struct pxa3xx_nand_timing *t) | 233 | const struct pxa3xx_nand_timing *t) |
373 | { | 234 | { |
@@ -385,6 +246,8 @@ static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, | |||
385 | NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) | | 246 | NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) | |
386 | NDTR1_tAR(ns2cycle(t->tAR, nand_clk)); | 247 | NDTR1_tAR(ns2cycle(t->tAR, nand_clk)); |
387 | 248 | ||
249 | info->ndtr0cs0 = ndtr0; | ||
250 | info->ndtr1cs0 = ndtr1; | ||
388 | nand_writel(info, NDTR0CS0, ndtr0); | 251 | nand_writel(info, NDTR0CS0, ndtr0); |
389 | nand_writel(info, NDTR1CS0, ndtr1); | 252 | nand_writel(info, NDTR1CS0, ndtr1); |
390 | } | 253 | } |
@@ -408,23 +271,31 @@ static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event) | |||
408 | return -ETIMEDOUT; | 271 | return -ETIMEDOUT; |
409 | } | 272 | } |
410 | 273 | ||
411 | static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info, | 274 | static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info) |
412 | uint16_t cmd, int column, int page_addr) | ||
413 | { | 275 | { |
414 | const struct pxa3xx_nand_flash *f = info->flash_info; | 276 | int oob_enable = info->reg_ndcr & NDCR_SPARE_EN; |
415 | const struct pxa3xx_nand_cmdset *cmdset = f->cmdset; | ||
416 | 277 | ||
417 | /* calculate data size */ | 278 | info->data_size = info->page_size; |
418 | switch (f->page_size) { | 279 | if (!oob_enable) { |
280 | info->oob_size = 0; | ||
281 | return; | ||
282 | } | ||
283 | |||
284 | switch (info->page_size) { | ||
419 | case 2048: | 285 | case 2048: |
420 | info->data_size = (info->use_ecc) ? 2088 : 2112; | 286 | info->oob_size = (info->use_ecc) ? 40 : 64; |
421 | break; | 287 | break; |
422 | case 512: | 288 | case 512: |
423 | info->data_size = (info->use_ecc) ? 520 : 528; | 289 | info->oob_size = (info->use_ecc) ? 8 : 16; |
424 | break; | 290 | break; |
425 | default: | ||
426 | return -EINVAL; | ||
427 | } | 291 | } |
292 | } | ||
293 | |||
294 | static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info, | ||
295 | uint16_t cmd, int column, int page_addr) | ||
296 | { | ||
297 | const struct pxa3xx_nand_cmdset *cmdset = info->cmdset; | ||
298 | pxa3xx_set_datasize(info); | ||
428 | 299 | ||
429 | /* generate values for NDCBx registers */ | 300 | /* generate values for NDCBx registers */ |
430 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); | 301 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); |
@@ -463,12 +334,13 @@ static int prepare_erase_cmd(struct pxa3xx_nand_info *info, | |||
463 | 334 | ||
464 | static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) | 335 | static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) |
465 | { | 336 | { |
466 | const struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset; | 337 | const struct pxa3xx_nand_cmdset *cmdset = info->cmdset; |
467 | 338 | ||
468 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); | 339 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); |
469 | info->ndcb1 = 0; | 340 | info->ndcb1 = 0; |
470 | info->ndcb2 = 0; | 341 | info->ndcb2 = 0; |
471 | 342 | ||
343 | info->oob_size = 0; | ||
472 | if (cmd == cmdset->read_id) { | 344 | if (cmd == cmdset->read_id) { |
473 | info->ndcb0 |= NDCB0_CMD_TYPE(3); | 345 | info->ndcb0 |= NDCB0_CMD_TYPE(3); |
474 | info->data_size = 8; | 346 | info->data_size = 8; |
@@ -537,6 +409,9 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) | |||
537 | case STATE_PIO_WRITING: | 409 | case STATE_PIO_WRITING: |
538 | __raw_writesl(info->mmio_base + NDDB, info->data_buff, | 410 | __raw_writesl(info->mmio_base + NDDB, info->data_buff, |
539 | DIV_ROUND_UP(info->data_size, 4)); | 411 | DIV_ROUND_UP(info->data_size, 4)); |
412 | if (info->oob_size > 0) | ||
413 | __raw_writesl(info->mmio_base + NDDB, info->oob_buff, | ||
414 | DIV_ROUND_UP(info->oob_size, 4)); | ||
540 | 415 | ||
541 | enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD); | 416 | enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD); |
542 | 417 | ||
@@ -549,6 +424,9 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) | |||
549 | case STATE_PIO_READING: | 424 | case STATE_PIO_READING: |
550 | __raw_readsl(info->mmio_base + NDDB, info->data_buff, | 425 | __raw_readsl(info->mmio_base + NDDB, info->data_buff, |
551 | DIV_ROUND_UP(info->data_size, 4)); | 426 | DIV_ROUND_UP(info->data_size, 4)); |
427 | if (info->oob_size > 0) | ||
428 | __raw_readsl(info->mmio_base + NDDB, info->oob_buff, | ||
429 | DIV_ROUND_UP(info->oob_size, 4)); | ||
552 | break; | 430 | break; |
553 | default: | 431 | default: |
554 | printk(KERN_ERR "%s: invalid state %d\n", __func__, | 432 | printk(KERN_ERR "%s: invalid state %d\n", __func__, |
@@ -563,7 +441,7 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) | |||
563 | static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out) | 441 | static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out) |
564 | { | 442 | { |
565 | struct pxa_dma_desc *desc = info->data_desc; | 443 | struct pxa_dma_desc *desc = info->data_desc; |
566 | int dma_len = ALIGN(info->data_size, 32); | 444 | int dma_len = ALIGN(info->data_size + info->oob_size, 32); |
567 | 445 | ||
568 | desc->ddadr = DDADR_STOP; | 446 | desc->ddadr = DDADR_STOP; |
569 | desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len; | 447 | desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len; |
@@ -700,8 +578,7 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, | |||
700 | int column, int page_addr) | 578 | int column, int page_addr) |
701 | { | 579 | { |
702 | struct pxa3xx_nand_info *info = mtd->priv; | 580 | struct pxa3xx_nand_info *info = mtd->priv; |
703 | const struct pxa3xx_nand_flash *flash_info = info->flash_info; | 581 | const struct pxa3xx_nand_cmdset *cmdset = info->cmdset; |
704 | const struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset; | ||
705 | int ret; | 582 | int ret; |
706 | 583 | ||
707 | info->use_dma = (use_dma) ? 1 : 0; | 584 | info->use_dma = (use_dma) ? 1 : 0; |
@@ -925,8 +802,7 @@ static int pxa3xx_nand_ecc_correct(struct mtd_info *mtd, | |||
925 | 802 | ||
926 | static int __readid(struct pxa3xx_nand_info *info, uint32_t *id) | 803 | static int __readid(struct pxa3xx_nand_info *info, uint32_t *id) |
927 | { | 804 | { |
928 | const struct pxa3xx_nand_flash *f = info->flash_info; | 805 | const struct pxa3xx_nand_cmdset *cmdset = info->cmdset; |
929 | const struct pxa3xx_nand_cmdset *cmdset = f->cmdset; | ||
930 | uint32_t ndcr; | 806 | uint32_t ndcr; |
931 | uint8_t id_buff[8]; | 807 | uint8_t id_buff[8]; |
932 | 808 | ||
@@ -968,7 +844,9 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, | |||
968 | return -EINVAL; | 844 | return -EINVAL; |
969 | 845 | ||
970 | /* calculate flash information */ | 846 | /* calculate flash information */ |
971 | info->oob_size = (f->page_size == 2048) ? 64 : 16; | 847 | info->cmdset = f->cmdset; |
848 | info->page_size = f->page_size; | ||
849 | info->oob_buff = info->data_buff + f->page_size; | ||
972 | info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; | 850 | info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; |
973 | 851 | ||
974 | /* calculate addressing information */ | 852 | /* calculate addressing information */ |
@@ -992,49 +870,20 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, | |||
992 | info->reg_ndcr = ndcr; | 870 | info->reg_ndcr = ndcr; |
993 | 871 | ||
994 | pxa3xx_nand_set_timing(info, f->timing); | 872 | pxa3xx_nand_set_timing(info, f->timing); |
995 | info->flash_info = f; | ||
996 | return 0; | 873 | return 0; |
997 | } | 874 | } |
998 | 875 | ||
999 | static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info, | ||
1000 | struct pxa3xx_nand_timing *t) | ||
1001 | { | ||
1002 | unsigned long nand_clk = clk_get_rate(info->clk); | ||
1003 | uint32_t ndtr0 = nand_readl(info, NDTR0CS0); | ||
1004 | uint32_t ndtr1 = nand_readl(info, NDTR1CS0); | ||
1005 | |||
1006 | t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk); | ||
1007 | t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk); | ||
1008 | t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk); | ||
1009 | t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk); | ||
1010 | t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk); | ||
1011 | t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk); | ||
1012 | |||
1013 | t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk); | ||
1014 | t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk); | ||
1015 | t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk); | ||
1016 | } | ||
1017 | |||
1018 | static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) | 876 | static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) |
1019 | { | 877 | { |
1020 | uint32_t ndcr = nand_readl(info, NDCR); | 878 | uint32_t ndcr = nand_readl(info, NDCR); |
1021 | struct nand_flash_dev *type = NULL; | 879 | struct nand_flash_dev *type = NULL; |
1022 | uint32_t id = -1; | 880 | uint32_t id = -1, page_per_block, num_blocks; |
1023 | int i; | 881 | int i; |
1024 | 882 | ||
1025 | default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32; | 883 | page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32; |
1026 | default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512; | 884 | info->page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512; |
1027 | default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8; | ||
1028 | default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8; | ||
1029 | |||
1030 | if (default_flash.page_size == 2048) | ||
1031 | default_flash.cmdset = &largepage_cmdset; | ||
1032 | else | ||
1033 | default_flash.cmdset = &smallpage_cmdset; | ||
1034 | |||
1035 | /* set info fields needed to __readid */ | 885 | /* set info fields needed to __readid */ |
1036 | info->flash_info = &default_flash; | 886 | info->read_id_bytes = (info->page_size == 2048) ? 4 : 2; |
1037 | info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2; | ||
1038 | info->reg_ndcr = ndcr; | 887 | info->reg_ndcr = ndcr; |
1039 | 888 | ||
1040 | if (__readid(info, &id)) | 889 | if (__readid(info, &id)) |
@@ -1053,21 +902,20 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) | |||
1053 | return -ENODEV; | 902 | return -ENODEV; |
1054 | 903 | ||
1055 | /* fill the missing flash information */ | 904 | /* fill the missing flash information */ |
1056 | i = __ffs(default_flash.page_per_block * default_flash.page_size); | 905 | i = __ffs(page_per_block * info->page_size); |
1057 | default_flash.num_blocks = type->chipsize << (20 - i); | 906 | num_blocks = type->chipsize << (20 - i); |
1058 | |||
1059 | info->oob_size = (default_flash.page_size == 2048) ? 64 : 16; | ||
1060 | 907 | ||
1061 | /* calculate addressing information */ | 908 | /* calculate addressing information */ |
1062 | info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1; | 909 | info->col_addr_cycles = (info->page_size == 2048) ? 2 : 1; |
1063 | 910 | ||
1064 | if (default_flash.num_blocks * default_flash.page_per_block > 65536) | 911 | if (num_blocks * page_per_block > 65536) |
1065 | info->row_addr_cycles = 3; | 912 | info->row_addr_cycles = 3; |
1066 | else | 913 | else |
1067 | info->row_addr_cycles = 2; | 914 | info->row_addr_cycles = 2; |
1068 | 915 | ||
1069 | pxa3xx_nand_detect_timing(info, &default_timing); | 916 | info->ndtr0cs0 = nand_readl(info, NDTR0CS0); |
1070 | default_flash.timing = &default_timing; | 917 | info->ndtr1cs0 = nand_readl(info, NDTR1CS0); |
918 | info->cmdset = &default_cmdset; | ||
1071 | 919 | ||
1072 | return 0; | 920 | return 0; |
1073 | } | 921 | } |
@@ -1083,38 +931,29 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info, | |||
1083 | if (pxa3xx_nand_detect_config(info) == 0) | 931 | if (pxa3xx_nand_detect_config(info) == 0) |
1084 | return 0; | 932 | return 0; |
1085 | 933 | ||
1086 | for (i = 0; i<pdata->num_flash; ++i) { | 934 | /* we use default timing to detect id */ |
1087 | f = pdata->flash + i; | 935 | f = DEFAULT_FLASH_TYPE; |
1088 | 936 | pxa3xx_nand_config_flash(info, f); | |
1089 | if (pxa3xx_nand_config_flash(info, f)) | 937 | if (__readid(info, &id)) |
1090 | continue; | 938 | goto fail_detect; |
1091 | 939 | ||
1092 | if (__readid(info, &id)) | 940 | for (i=0; i<ARRAY_SIZE(builtin_flash_types) + pdata->num_flash - 1; i++) { |
1093 | continue; | 941 | /* we first choose the flash definition from platfrom */ |
1094 | 942 | if (i < pdata->num_flash) | |
1095 | if (id == f->chip_id) | 943 | f = pdata->flash + i; |
1096 | return 0; | 944 | else |
1097 | } | 945 | f = &builtin_flash_types[i - pdata->num_flash + 1]; |
1098 | 946 | if (f->chip_id == id) { | |
1099 | #ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN | 947 | dev_info(&info->pdev->dev, "detect chip id: 0x%x\n", id); |
1100 | for (i = 0; i < ARRAY_SIZE(builtin_flash_types); i++) { | 948 | pxa3xx_nand_config_flash(info, f); |
1101 | |||
1102 | f = builtin_flash_types[i]; | ||
1103 | |||
1104 | if (pxa3xx_nand_config_flash(info, f)) | ||
1105 | continue; | ||
1106 | |||
1107 | if (__readid(info, &id)) | ||
1108 | continue; | ||
1109 | |||
1110 | if (id == f->chip_id) | ||
1111 | return 0; | 949 | return 0; |
950 | } | ||
1112 | } | 951 | } |
1113 | #endif | ||
1114 | 952 | ||
1115 | dev_warn(&info->pdev->dev, | 953 | dev_warn(&info->pdev->dev, |
1116 | "failed to detect configured nand flash; found %04x instead of\n", | 954 | "failed to detect configured nand flash; found %04x instead of\n", |
1117 | id); | 955 | id); |
956 | fail_detect: | ||
1118 | return -ENODEV; | 957 | return -ENODEV; |
1119 | } | 958 | } |
1120 | 959 | ||
@@ -1177,10 +1016,9 @@ static struct nand_ecclayout hw_largepage_ecclayout = { | |||
1177 | static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, | 1016 | static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, |
1178 | struct pxa3xx_nand_info *info) | 1017 | struct pxa3xx_nand_info *info) |
1179 | { | 1018 | { |
1180 | const struct pxa3xx_nand_flash *f = info->flash_info; | ||
1181 | struct nand_chip *this = &info->nand_chip; | 1019 | struct nand_chip *this = &info->nand_chip; |
1182 | 1020 | ||
1183 | this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0; | 1021 | this->options = (info->reg_ndcr & NDCR_DWIDTH_C) ? NAND_BUSWIDTH_16: 0; |
1184 | 1022 | ||
1185 | this->waitfunc = pxa3xx_nand_waitfunc; | 1023 | this->waitfunc = pxa3xx_nand_waitfunc; |
1186 | this->select_chip = pxa3xx_nand_select_chip; | 1024 | this->select_chip = pxa3xx_nand_select_chip; |
@@ -1196,9 +1034,9 @@ static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, | |||
1196 | this->ecc.hwctl = pxa3xx_nand_ecc_hwctl; | 1034 | this->ecc.hwctl = pxa3xx_nand_ecc_hwctl; |
1197 | this->ecc.calculate = pxa3xx_nand_ecc_calculate; | 1035 | this->ecc.calculate = pxa3xx_nand_ecc_calculate; |
1198 | this->ecc.correct = pxa3xx_nand_ecc_correct; | 1036 | this->ecc.correct = pxa3xx_nand_ecc_correct; |
1199 | this->ecc.size = f->page_size; | 1037 | this->ecc.size = info->page_size; |
1200 | 1038 | ||
1201 | if (f->page_size == 2048) | 1039 | if (info->page_size == 2048) |
1202 | this->ecc.layout = &hw_largepage_ecclayout; | 1040 | this->ecc.layout = &hw_largepage_ecclayout; |
1203 | else | 1041 | else |
1204 | this->ecc.layout = &hw_smallpage_ecclayout; | 1042 | this->ecc.layout = &hw_smallpage_ecclayout; |
@@ -1411,9 +1249,11 @@ static int pxa3xx_nand_resume(struct platform_device *pdev) | |||
1411 | struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev); | 1249 | struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev); |
1412 | struct pxa3xx_nand_info *info = mtd->priv; | 1250 | struct pxa3xx_nand_info *info = mtd->priv; |
1413 | 1251 | ||
1252 | nand_writel(info, NDTR0CS0, info->ndtr0cs0); | ||
1253 | nand_writel(info, NDTR1CS0, info->ndtr1cs0); | ||
1414 | clk_enable(info->clk); | 1254 | clk_enable(info->clk); |
1415 | 1255 | ||
1416 | return pxa3xx_nand_config_flash(info, info->flash_info); | 1256 | return 0; |
1417 | } | 1257 | } |
1418 | #else | 1258 | #else |
1419 | #define pxa3xx_nand_suspend NULL | 1259 | #define pxa3xx_nand_suspend NULL |