OpenOCD
lpc32xx.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2007 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2011 Bjarne Steinsbo <bsteinsbo@gmail.com> *
8  * Copyright (C) 2010 richard vegh <vegh.ricsi@gmail.com> *
9  * Copyright (C) 2010 Oyvind Harboe <oyvind.harboe@zylin.com> *
10  * *
11  * Based on a combination of the lpc3180 driver and code from *
12  * uboot-2009.03-lpc32xx by Kevin Wells. *
13  * Any bugs are mine. --BSt *
14  ***************************************************************************/
15 
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 
20 #include "imp.h"
21 #include "lpc32xx.h"
22 #include <target/target.h>
23 
24 static int lpc32xx_reset(struct nand_device *nand);
25 static int lpc32xx_controller_ready(struct nand_device *nand, int timeout);
26 static int lpc32xx_tc_ready(struct nand_device *nand, int timeout);
27 
28 /* These are offset with the working area in IRAM when using DMA to
29  * read/write data to the SLC controller.
30  * - DMA descriptors will be put at start of working area,
31  * - Hardware generated ECC will be stored at ECC_OFFS
32  * - OOB will be read/written from/to SPARE_OFFS
33  * - Actual page data will be read from/to DATA_OFFS
34  * There are unused holes between the used areas.
35  */
36 #define ECC_OFFS 0x120
37 #define SPARE_OFFS 0x140
38 #define DATA_OFFS 0x200
39 
40 static const int sp_ooblayout[] = {
41  10, 11, 12, 13, 14, 15
42 };
43 static const int lp_ooblayout[] = {
44  40, 41, 42, 43, 44, 45,
45  46, 47, 48, 49, 50, 51,
46  52, 53, 54, 55, 56, 57,
47  58, 59, 60, 61, 62, 63
48 };
49 
50 struct dmac_ll {
51  volatile uint32_t dma_src;
52  volatile uint32_t dma_dest;
53  volatile uint32_t next_lli;
54  volatile uint32_t next_ctrl;
55 };
56 
57 static struct dmac_ll dmalist[(2048/256) * 2 + 1];
58 
59 /* nand device lpc32xx <target#> <oscillator_frequency>
60  */
61 NAND_DEVICE_COMMAND_HANDLER(lpc32xx_nand_device_command)
62 {
63  if (CMD_ARGC < 3)
65 
66  uint32_t osc_freq;
67  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], osc_freq);
68 
69  struct lpc32xx_nand_controller *lpc32xx_info;
70  lpc32xx_info = malloc(sizeof(struct lpc32xx_nand_controller));
71  nand->controller_priv = lpc32xx_info;
72 
73  lpc32xx_info->osc_freq = osc_freq;
74 
75  if ((lpc32xx_info->osc_freq < 1000) || (lpc32xx_info->osc_freq > 20000))
76  LOG_WARNING("LPC32xx oscillator frequency should be between "
77  "1000 and 20000 kHz, was %i",
78  lpc32xx_info->osc_freq);
79 
81  lpc32xx_info->sw_write_protection = 0;
82  lpc32xx_info->sw_wp_lower_bound = 0x0;
83  lpc32xx_info->sw_wp_upper_bound = 0x0;
84 
85  return ERROR_OK;
86 }
87 
88 static int lpc32xx_pll(int fclkin, uint32_t pll_ctrl)
89 {
90  int bypass = (pll_ctrl & 0x8000) >> 15;
91  int direct = (pll_ctrl & 0x4000) >> 14;
92  int feedback = (pll_ctrl & 0x2000) >> 13;
93  int p = (1 << ((pll_ctrl & 0x1800) >> 11) * 2);
94  int n = ((pll_ctrl & 0x0600) >> 9) + 1;
95  int m = ((pll_ctrl & 0x01fe) >> 1) + 1;
96  int lock = (pll_ctrl & 0x1);
97 
98  if (!lock)
99  LOG_WARNING("PLL is not locked");
100 
101  if (!bypass && direct) /* direct mode */
102  return (m * fclkin) / n;
103 
104  if (bypass && !direct) /* bypass mode */
105  return fclkin / (2 * p);
106 
107  if (bypass & direct) /* direct bypass mode */
108  return fclkin;
109 
110  if (feedback) /* integer mode */
111  return m * (fclkin / n);
112  else /* non-integer mode */
113  return (m / (2 * p)) * (fclkin / n);
114 }
115 
116 static float lpc32xx_cycle_time(struct nand_device *nand)
117 {
118  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
119  struct target *target = nand->target;
120  uint32_t sysclk_ctrl, pwr_ctrl, hclkdiv_ctrl, hclkpll_ctrl;
121  int sysclk;
122  int hclk;
123  int hclk_pll;
124  int retval;
125 
126  /* calculate timings */
127 
128  /* determine current SYSCLK (13'MHz or main oscillator) */
129  retval = target_read_u32(target, 0x40004050, &sysclk_ctrl);
130  if (retval != ERROR_OK) {
131  LOG_ERROR("could not read SYSCLK_CTRL");
133  }
134 
135  if ((sysclk_ctrl & 1) == 0)
136  sysclk = lpc32xx_info->osc_freq;
137  else
138  sysclk = 13000;
139 
140  /* determine selected HCLK source */
141  retval = target_read_u32(target, 0x40004044, &pwr_ctrl);
142  if (retval != ERROR_OK) {
143  LOG_ERROR("could not read HCLK_CTRL");
145  }
146 
147  if ((pwr_ctrl & (1 << 2)) == 0) /* DIRECT RUN mode */
148  hclk = sysclk;
149  else {
150  retval = target_read_u32(target, 0x40004058, &hclkpll_ctrl);
151  if (retval != ERROR_OK) {
152  LOG_ERROR("could not read HCLKPLL_CTRL");
154  }
155  hclk_pll = lpc32xx_pll(sysclk, hclkpll_ctrl);
156 
157  retval = target_read_u32(target, 0x40004040, &hclkdiv_ctrl);
158  if (retval != ERROR_OK) {
159  LOG_ERROR("could not read CLKDIV_CTRL");
161  }
162 
163  if (pwr_ctrl & (1 << 10)) /* ARM_CLK and HCLK use PERIPH_CLK */
164  hclk = hclk_pll / (((hclkdiv_ctrl & 0x7c) >> 2) + 1);
165  else /* HCLK uses HCLK_PLL */
166  hclk = hclk_pll / (1 << (hclkdiv_ctrl & 0x3));
167  }
168 
169  LOG_DEBUG("LPC32xx HCLK currently clocked at %i kHz", hclk);
170 
171  return (1.0 / hclk) * 1000000.0;
172 }
173 
174 static int lpc32xx_init(struct nand_device *nand)
175 {
176  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
177  struct target *target = nand->target;
178  int bus_width = nand->bus_width ? nand->bus_width : 8;
179  int address_cycles = nand->address_cycles ? nand->address_cycles : 3;
180  int page_size = nand->page_size ? nand->page_size : 512;
181  int retval;
182 
183  if (target->state != TARGET_HALTED) {
184  LOG_ERROR("target must be halted to use LPC32xx "
185  "NAND flash controller");
187  }
188 
189  /* sanitize arguments */
190  if (bus_width != 8) {
191  LOG_ERROR("LPC32xx doesn't support %i", bus_width);
193  }
194 
195  /* inform calling code about selected bus width */
196  nand->bus_width = bus_width;
197 
198  if ((address_cycles < 3) || (address_cycles > 5)) {
199  LOG_ERROR("LPC32xx driver doesn't support %i address cycles", address_cycles);
201  }
202 
203  if ((page_size != 512) && (page_size != 2048)) {
204  LOG_ERROR("LPC32xx doesn't support page size %i", page_size);
206  }
207 
208  /* select MLC controller if none is currently selected */
209  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
210  LOG_DEBUG("no LPC32xx NAND flash controller selected, "
211  "using default 'slc'");
213  }
214 
215  if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
216  uint32_t mlc_icr_value = 0x0;
217  float cycle;
218  int twp, twh, trp, treh, trhz, trbwb, tcea;
219 
220  /* FLASHCLK_CTRL = 0x22 (enable clk for MLC) */
221  retval = target_write_u32(target, 0x400040c8, 0x22);
222  if (retval != ERROR_OK) {
223  LOG_ERROR("could not set FLASHCLK_CTRL");
225  }
226 
227  /* MLC_CEH = 0x0 (Force nCE assert) */
228  retval = target_write_u32(target, 0x200b804c, 0x0);
229  if (retval != ERROR_OK) {
230  LOG_ERROR("could not set MLC_CEH");
232  }
233 
234  /* MLC_LOCK = 0xa25e (unlock protected registers) */
235  retval = target_write_u32(target, 0x200b8044, 0xa25e);
236  if (retval != ERROR_OK) {
237  LOG_ERROR("could not set MLC_LOCK");
239  }
240 
241  /* MLC_ICR = configuration */
242  if (lpc32xx_info->sw_write_protection)
243  mlc_icr_value |= 0x8;
244  if (page_size == 2048)
245  mlc_icr_value |= 0x4;
246  if (address_cycles == 4)
247  mlc_icr_value |= 0x2;
248  if (bus_width == 16)
249  mlc_icr_value |= 0x1;
250  retval = target_write_u32(target, 0x200b8030, mlc_icr_value);
251  if (retval != ERROR_OK) {
252  LOG_ERROR("could not set MLC_ICR");
254  }
255 
256  /* calculate NAND controller timings */
257  cycle = lpc32xx_cycle_time(nand);
258 
259  twp = ((40 / cycle) + 1);
260  twh = ((20 / cycle) + 1);
261  trp = ((30 / cycle) + 1);
262  treh = ((15 / cycle) + 1);
263  trhz = ((30 / cycle) + 1);
264  trbwb = ((100 / cycle) + 1);
265  tcea = ((45 / cycle) + 1);
266 
267  /* MLC_LOCK = 0xa25e (unlock protected registers) */
268  retval = target_write_u32(target, 0x200b8044, 0xa25e);
269  if (retval != ERROR_OK) {
270  LOG_ERROR("could not set MLC_LOCK");
272  }
273 
274  /* MLC_TIME_REG */
275  retval = target_write_u32(target, 0x200b8034,
276  (twp & 0xf)
277  | ((twh & 0xf) << 4)
278  | ((trp & 0xf) << 8)
279  | ((treh & 0xf) << 12)
280  | ((trhz & 0x7) << 16)
281  | ((trbwb & 0x1f) << 19)
282  | ((tcea & 0x3) << 24));
283  if (retval != ERROR_OK) {
284  LOG_ERROR("could not set MLC_TIME_REG");
286  }
287 
288  retval = lpc32xx_reset(nand);
289  if (retval != ERROR_OK)
291  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
292  float cycle;
293  int r_setup, r_hold, r_width, r_rdy;
294  int w_setup, w_hold, w_width, w_rdy;
295 
296  /* FLASHCLK_CTRL = 0x05 (enable clk for SLC) */
297  retval = target_write_u32(target, 0x400040c8, 0x05);
298  if (retval != ERROR_OK) {
299  LOG_ERROR("could not set FLASHCLK_CTRL");
301  }
302 
303  /* after reset set other registers of SLC,
304  * so reset calling is here at the beginning
305  */
306  retval = lpc32xx_reset(nand);
307  if (retval != ERROR_OK)
309 
310  /* SLC_CFG =
311  Force nCE assert,
312  DMA ECC enabled,
313  ECC enabled,
314  DMA burst enabled,
315  DMA read from SLC,
316  WIDTH = bus_width)
317  */
318  retval = target_write_u32(target, 0x20020014,
319  0x3e | ((bus_width == 16) ? 1 : 0));
320  if (retval != ERROR_OK) {
321  LOG_ERROR("could not set SLC_CFG");
323  }
324 
325  /* SLC_IEN = 3 (INT_RDY_EN = 1) ,(INT_TC_STAT = 1) */
326  retval = target_write_u32(target, 0x20020020, 0x03);
327  if (retval != ERROR_OK) {
328  LOG_ERROR("could not set SLC_IEN");
330  }
331 
332  /* DMA configuration */
333 
334  /* DMACLK_CTRL = 0x01 (enable clock for DMA controller) */
335  retval = target_write_u32(target, 0x400040e8, 0x01);
336  if (retval != ERROR_OK) {
337  LOG_ERROR("could not set DMACLK_CTRL");
339  }
340 
341  /* DMACConfig = DMA enabled*/
342  retval = target_write_u32(target, 0x31000030, 0x01);
343  if (retval != ERROR_OK) {
344  LOG_ERROR("could not set DMACConfig");
346  }
347 
348  /* calculate NAND controller timings */
349  cycle = lpc32xx_cycle_time(nand);
350 
351  r_setup = w_setup = 0;
352  r_hold = w_hold = 10 / cycle;
353  r_width = 30 / cycle;
354  w_width = 40 / cycle;
355  r_rdy = w_rdy = 100 / cycle;
356 
357  /* SLC_TAC: SLC timing arcs register */
358  retval = target_write_u32(target, 0x2002002c,
359  (r_setup & 0xf)
360  | ((r_hold & 0xf) << 4)
361  | ((r_width & 0xf) << 8)
362  | ((r_rdy & 0xf) << 12)
363  | ((w_setup & 0xf) << 16)
364  | ((w_hold & 0xf) << 20)
365  | ((w_width & 0xf) << 24)
366  | ((w_rdy & 0xf) << 28));
367  if (retval != ERROR_OK) {
368  LOG_ERROR("could not set SLC_TAC");
370  }
371  }
372 
373  return ERROR_OK;
374 }
375 
376 static int lpc32xx_reset(struct nand_device *nand)
377 {
378  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
379  struct target *target = nand->target;
380  int retval;
381 
382  if (target->state != TARGET_HALTED) {
383  LOG_ERROR("target must be halted to use "
384  "LPC32xx NAND flash controller");
386  }
387 
388  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
389  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
391  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
392  /* MLC_CMD = 0xff (reset controller and NAND device) */
393  retval = target_write_u32(target, 0x200b8000, 0xff);
394  if (retval != ERROR_OK) {
395  LOG_ERROR("could not set MLC_CMD");
397  }
398 
399  if (!lpc32xx_controller_ready(nand, 100)) {
400  LOG_ERROR("LPC32xx MLC NAND controller timed out "
401  "after reset");
403  }
404  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
405  /* SLC_CTRL = 0x6 (ECC_CLEAR, SW_RESET) */
406  retval = target_write_u32(target, 0x20020010, 0x6);
407  if (retval != ERROR_OK) {
408  LOG_ERROR("could not set SLC_CTRL");
410  }
411 
412  if (!lpc32xx_controller_ready(nand, 100)) {
413  LOG_ERROR("LPC32xx SLC NAND controller timed out "
414  "after reset");
416  }
417  }
418 
419  return ERROR_OK;
420 }
421 
422 static int lpc32xx_command(struct nand_device *nand, uint8_t command)
423 {
424  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
425  struct target *target = nand->target;
426  int retval;
427 
428  if (target->state != TARGET_HALTED) {
429  LOG_ERROR("target must be halted to use "
430  "LPC32xx NAND flash controller");
432  }
433 
434  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
435  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
437  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
438  /* MLC_CMD = command */
439  retval = target_write_u32(target, 0x200b8000, command);
440  if (retval != ERROR_OK) {
441  LOG_ERROR("could not set MLC_CMD");
443  }
444  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
445  /* SLC_CMD = command */
446  retval = target_write_u32(target, 0x20020008, command);
447  if (retval != ERROR_OK) {
448  LOG_ERROR("could not set SLC_CMD");
450  }
451  }
452 
453  return ERROR_OK;
454 }
455 
456 static int lpc32xx_address(struct nand_device *nand, uint8_t address)
457 {
458  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
459  struct target *target = nand->target;
460  int retval;
461 
462  if (target->state != TARGET_HALTED) {
463  LOG_ERROR("target must be halted to use "
464  "LPC32xx NAND flash controller");
466  }
467 
468  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
469  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
471  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
472  /* MLC_ADDR = address */
473  retval = target_write_u32(target, 0x200b8004, address);
474  if (retval != ERROR_OK) {
475  LOG_ERROR("could not set MLC_ADDR");
477  }
478  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
479  /* SLC_ADDR = address */
480  retval = target_write_u32(target, 0x20020004, address);
481  if (retval != ERROR_OK) {
482  LOG_ERROR("could not set SLC_ADDR");
484  }
485  }
486 
487  return ERROR_OK;
488 }
489 
490 static int lpc32xx_write_data(struct nand_device *nand, uint16_t data)
491 {
492  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
493  struct target *target = nand->target;
494  int retval;
495 
496  if (target->state != TARGET_HALTED) {
497  LOG_ERROR("target must be halted to use "
498  "LPC32xx NAND flash controller");
500  }
501 
502  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
503  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
505  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
506  /* MLC_DATA = data */
507  retval = target_write_u32(target, 0x200b0000, data);
508  if (retval != ERROR_OK) {
509  LOG_ERROR("could not set MLC_DATA");
511  }
512  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
513  /* SLC_DATA = data */
514  retval = target_write_u32(target, 0x20020000, data);
515  if (retval != ERROR_OK) {
516  LOG_ERROR("could not set SLC_DATA");
518  }
519  }
520 
521  return ERROR_OK;
522 }
523 
524 static int lpc32xx_read_data(struct nand_device *nand, void *data)
525 {
526  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
527  struct target *target = nand->target;
528  int retval;
529 
530  if (target->state != TARGET_HALTED) {
531  LOG_ERROR("target must be halted to use LPC32xx "
532  "NAND flash controller");
534  }
535 
536  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
537  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
539  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
540  /* data = MLC_DATA, use sized access */
541  if (nand->bus_width == 8) {
542  uint8_t *data8 = data;
543  retval = target_read_u8(target, 0x200b0000, data8);
544  } else {
545  LOG_ERROR("BUG: bus_width neither 8 nor 16 bit");
547  }
548  if (retval != ERROR_OK) {
549  LOG_ERROR("could not read MLC_DATA");
551  }
552  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
553  uint32_t data32;
554 
555  /* data = SLC_DATA, must use 32-bit access */
556  retval = target_read_u32(target, 0x20020000, &data32);
557  if (retval != ERROR_OK) {
558  LOG_ERROR("could not read SLC_DATA");
560  }
561 
562  if (nand->bus_width == 8) {
563  uint8_t *data8 = data;
564  *data8 = data32 & 0xff;
565  } else {
566  LOG_ERROR("BUG: bus_width neither 8 nor 16 bit");
568  }
569  }
570 
571  return ERROR_OK;
572 }
573 
574 static int lpc32xx_write_page_mlc(struct nand_device *nand, uint32_t page,
575  uint8_t *data, uint32_t data_size,
576  uint8_t *oob, uint32_t oob_size)
577 {
578  struct target *target = nand->target;
579  int retval;
580  uint8_t status;
581  static uint8_t page_buffer[512];
582  static uint8_t oob_buffer[6];
583  int quarter, num_quarters;
584 
585  /* MLC_CMD = sequential input */
586  retval = target_write_u32(target, 0x200b8000, NAND_CMD_SEQIN);
587  if (retval != ERROR_OK) {
588  LOG_ERROR("could not set MLC_CMD");
590  }
591 
592  if (nand->page_size == 512) {
593  /* MLC_ADDR = 0x0 (one column cycle) */
594  retval = target_write_u32(target, 0x200b8004, 0x0);
595  if (retval != ERROR_OK) {
596  LOG_ERROR("could not set MLC_ADDR");
598  }
599 
600  /* MLC_ADDR = row */
601  retval = target_write_u32(target, 0x200b8004, page & 0xff);
602  if (retval != ERROR_OK) {
603  LOG_ERROR("could not set MLC_ADDR");
605  }
606  retval = target_write_u32(target, 0x200b8004,
607  (page >> 8) & 0xff);
608  if (retval != ERROR_OK) {
609  LOG_ERROR("could not set MLC_ADDR");
611  }
612 
613  if (nand->address_cycles == 4) {
614  retval = target_write_u32(target, 0x200b8004,
615  (page >> 16) & 0xff);
616  if (retval != ERROR_OK) {
617  LOG_ERROR("could not set MLC_ADDR");
619  }
620  }
621  } else {
622  /* MLC_ADDR = 0x0 (two column cycles) */
623  retval = target_write_u32(target, 0x200b8004, 0x0);
624  if (retval != ERROR_OK) {
625  LOG_ERROR("could not set MLC_ADDR");
627  }
628  retval = target_write_u32(target, 0x200b8004, 0x0);
629  if (retval != ERROR_OK) {
630  LOG_ERROR("could not set MLC_ADDR");
632  }
633 
634  /* MLC_ADDR = row */
635  retval = target_write_u32(target, 0x200b8004, page & 0xff);
636  if (retval != ERROR_OK) {
637  LOG_ERROR("could not set MLC_ADDR");
639  }
640  retval = target_write_u32(target, 0x200b8004,
641  (page >> 8) & 0xff);
642  if (retval != ERROR_OK) {
643  LOG_ERROR("could not set MLC_ADDR");
645  }
646  }
647 
648  /* when using the MLC controller, we have to treat a large page device
649  * as being made out of four quarters, each the size of a small page
650  * device
651  */
652  num_quarters = (nand->page_size == 2048) ? 4 : 1;
653 
654  for (quarter = 0; quarter < num_quarters; quarter++) {
655  int thisrun_data_size = (data_size > 512) ? 512 : data_size;
656  int thisrun_oob_size = (oob_size > 6) ? 6 : oob_size;
657 
658  memset(page_buffer, 0xff, 512);
659  if (data) {
660  memcpy(page_buffer, data, thisrun_data_size);
661  data_size -= thisrun_data_size;
662  data += thisrun_data_size;
663  }
664 
665  memset(oob_buffer, 0xff, 6);
666  if (oob) {
667  memcpy(oob_buffer, oob, thisrun_oob_size);
668  oob_size -= thisrun_oob_size;
669  oob += thisrun_oob_size;
670  }
671 
672  /* write MLC_ECC_ENC_REG to start encode cycle */
673  retval = target_write_u32(target, 0x200b8008, 0x0);
674  if (retval != ERROR_OK) {
675  LOG_ERROR("could not set MLC_ECC_ENC_REG");
677  }
678 
679  retval = target_write_memory(target, 0x200a8000,
680  4, 128, page_buffer);
681  if (retval != ERROR_OK) {
682  LOG_ERROR("could not set MLC_BUF (data)");
684  }
685  retval = target_write_memory(target, 0x200a8000,
686  1, 6, oob_buffer);
687  if (retval != ERROR_OK) {
688  LOG_ERROR("could not set MLC_BUF (oob)");
690  }
691 
692  /* write MLC_ECC_AUTO_ENC_REG to start auto encode */
693  retval = target_write_u32(target, 0x200b8010, 0x0);
694  if (retval != ERROR_OK) {
695  LOG_ERROR("could not set MLC_ECC_AUTO_ENC_REG");
697  }
698 
699  if (!lpc32xx_controller_ready(nand, 1000)) {
700  LOG_ERROR("timeout while waiting for "
701  "completion of auto encode cycle");
703  }
704  }
705 
706  /* MLC_CMD = auto program command */
707  retval = target_write_u32(target, 0x200b8000, NAND_CMD_PAGEPROG);
708  if (retval != ERROR_OK) {
709  LOG_ERROR("could not set MLC_CMD");
711  }
712 
713  retval = nand_read_status(nand, &status);
714  if (retval != ERROR_OK) {
715  LOG_ERROR("couldn't read status");
717  }
718 
719  if (status & NAND_STATUS_FAIL) {
720  LOG_ERROR("write operation didn't pass, status: 0x%2.2x",
721  status);
723  }
724 
725  return ERROR_OK;
726 }
727 
728 /* SLC controller in !raw mode will use target cpu to read/write nand from/to
729  * target internal memory. The transfer to/from flash is done by DMA. This
730  * function sets up the dma linked list in host memory for later transfer to
731  * target.
732  */
733 static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size,
734  int do_read)
735 {
736  uint32_t i, dmasrc, ctrl, ecc_ctrl, oob_ctrl, dmadst;
737 
738  /* DMACCxControl =
739  TransferSize =64,
740  Source burst size =16,
741  Destination burst size = 16,
742  Source transfer width = 32 bit,
743  Destination transfer width = 32 bit,
744  Source AHB master select = M0,
745  Destination AHB master select = M0,
746  Source increment = 0, // set later
747  Destination increment = 0, // set later
748  Terminal count interrupt enable bit = 0 // set on last
749  */ /*
750  * Write Operation Sequence for Small Block NAND
751  * ----------------------------------------------------------
752  * 1. X'fer 256 bytes of data from Memory to Flash.
753  * 2. Copy generated ECC data from Register to Spare Area
754  * 3. X'fer next 256 bytes of data from Memory to Flash.
755  * 4. Copy generated ECC data from Register to Spare Area.
756  * 5. X'fer 16 bytes of Spare area from Memory to Flash.
757  * Read Operation Sequence for Small Block NAND
758  * ----------------------------------------------------------
759  * 1. X'fer 256 bytes of data from Flash to Memory.
760  * 2. Copy generated ECC data from Register to ECC calc Buffer.
761  * 3. X'fer next 256 bytes of data from Flash to Memory.
762  * 4. Copy generated ECC data from Register to ECC calc Buffer.
763  * 5. X'fer 16 bytes of Spare area from Flash to Memory.
764  * Write Operation Sequence for Large Block NAND
765  * ----------------------------------------------------------
766  * 1. Steps(1-4) of Write Operations repeated for four times
767  * which generates 16 DMA descriptors to X'fer 2048 bytes of
768  * data & 32 bytes of ECC data.
769  * 2. X'fer 64 bytes of Spare area from Memory to Flash.
770  * Read Operation Sequence for Large Block NAND
771  * ----------------------------------------------------------
772  * 1. Steps(1-4) of Read Operations repeated for four times
773  * which generates 16 DMA descriptors to X'fer 2048 bytes of
774  * data & 32 bytes of ECC data.
775  * 2. X'fer 64 bytes of Spare area from Flash to Memory.
776  */
777 
778  ctrl = (0x40 | 3 << 12 | 3 << 15 | 2 << 18 | 2 << 21 | 0 << 24
779  | 0 << 25 | 0 << 26 | 0 << 27 | 0 << 31);
780 
781  /* DMACCxControl =
782  TransferSize =1,
783  Source burst size =4,
784  Destination burst size = 4,
785  Source transfer width = 32 bit,
786  Destination transfer width = 32 bit,
787  Source AHB master select = M0,
788  Destination AHB master select = M0,
789  Source increment = 0,
790  Destination increment = 1,
791  Terminal count interrupt enable bit = 0
792  */
793  ecc_ctrl = 0x01 | 1 << 12 | 1 << 15 | 2 << 18 | 2 << 21 | 0 << 24
794  | 0 << 25 | 0 << 26 | 1 << 27 | 0 << 31;
795 
796  /* DMACCxControl =
797  TransferSize =16 for lp or 4 for sp,
798  Source burst size =16,
799  Destination burst size = 16,
800  Source transfer width = 32 bit,
801  Destination transfer width = 32 bit,
802  Source AHB master select = M0,
803  Destination AHB master select = M0,
804  Source increment = 0, // set later
805  Destination increment = 0, // set later
806  Terminal count interrupt enable bit = 1 // set on last
807  */
808  oob_ctrl = (page_size == 2048 ? 0x10 : 0x04)
809  | 3 << 12 | 3 << 15 | 2 << 18 | 2 << 21 | 0 << 24
810  | 0 << 25 | 0 << 26 | 0 << 27 | 1 << 31;
811  if (do_read) {
812  ctrl |= 1 << 27;/* Destination increment = 1 */
813  oob_ctrl |= 1 << 27; /* Destination increment = 1 */
814  dmasrc = 0x20020038; /* SLC_DMA_DATA */
815  dmadst = target_mem_base + DATA_OFFS;
816  } else {
817  ctrl |= 1 << 26;/* Source increment = 1 */
818  oob_ctrl |= 1 << 26; /* Source increment = 1 */
819  dmasrc = target_mem_base + DATA_OFFS;
820  dmadst = 0x20020038; /* SLC_DMA_DATA */
821  }
822  /*
823  * Write Operation Sequence for Small Block NAND
824  * ----------------------------------------------------------
825  * 1. X'fer 256 bytes of data from Memory to Flash.
826  * 2. Copy generated ECC data from Register to Spare Area
827  * 3. X'fer next 256 bytes of data from Memory to Flash.
828  * 4. Copy generated ECC data from Register to Spare Area.
829  * 5. X'fer 16 bytes of Spare area from Memory to Flash.
830  * Read Operation Sequence for Small Block NAND
831  * ----------------------------------------------------------
832  * 1. X'fer 256 bytes of data from Flash to Memory.
833  * 2. Copy generated ECC data from Register to ECC calc Buffer.
834  * 3. X'fer next 256 bytes of data from Flash to Memory.
835  * 4. Copy generated ECC data from Register to ECC calc Buffer.
836  * 5. X'fer 16 bytes of Spare area from Flash to Memory.
837  * Write Operation Sequence for Large Block NAND
838  * ----------------------------------------------------------
839  * 1. Steps(1-4) of Write Operations repeated for four times
840  * which generates 16 DMA descriptors to X'fer 2048 bytes of
841  * data & 32 bytes of ECC data.
842  * 2. X'fer 64 bytes of Spare area from Memory to Flash.
843  * Read Operation Sequence for Large Block NAND
844  * ----------------------------------------------------------
845  * 1. Steps(1-4) of Read Operations repeated for four times
846  * which generates 16 DMA descriptors to X'fer 2048 bytes of
847  * data & 32 bytes of ECC data.
848  * 2. X'fer 64 bytes of Spare area from Flash to Memory.
849  */
850  for (i = 0; i < page_size/0x100; i++) {
851  dmalist[i*2].dma_src = (do_read ? dmasrc : (dmasrc + i * 256));
852  dmalist[i*2].dma_dest = (do_read ? (dmadst + i * 256) : dmadst);
853  dmalist[i*2].next_lli =
854  target_mem_base + (i*2 + 1) * sizeof(struct dmac_ll);
855  dmalist[i*2].next_ctrl = ctrl;
856 
857  dmalist[(i*2) + 1].dma_src = 0x20020034;/* SLC_ECC */
858  dmalist[(i*2) + 1].dma_dest =
859  target_mem_base + ECC_OFFS + i * 4;
860  dmalist[(i*2) + 1].next_lli =
861  target_mem_base + (i*2 + 2) * sizeof(struct dmac_ll);
862  dmalist[(i*2) + 1].next_ctrl = ecc_ctrl;
863 
864  }
865  if (do_read)
866  dmadst = target_mem_base + SPARE_OFFS;
867  else {
868  dmasrc = target_mem_base + SPARE_OFFS;
869  dmalist[(i*2) - 1].next_lli = 0;/* last link = null on write */
870  dmalist[(i*2) - 1].next_ctrl |= (1 << 31); /* Set TC enable */
871  }
872  dmalist[i*2].dma_src = dmasrc;
873  dmalist[i*2].dma_dest = dmadst;
874  dmalist[i*2].next_lli = 0;
875  dmalist[i*2].next_ctrl = oob_ctrl;
876 
877  return i * 2 + 1; /* Number of descriptors */
878 }
879 
880 static int lpc32xx_start_slc_dma(struct nand_device *nand, uint32_t count,
881  int do_wait)
882 {
883  struct target *target = nand->target;
884  int retval;
885 
886  /* DMACIntTCClear = ch0 */
887  retval = target_write_u32(target, 0x31000008, 1);
888  if (retval != ERROR_OK) {
889  LOG_ERROR("Could not set DMACIntTCClear");
890  return retval;
891  }
892 
893  /* DMACIntErrClear = ch0 */
894  retval = target_write_u32(target, 0x31000010, 1);
895  if (retval != ERROR_OK) {
896  LOG_ERROR("Could not set DMACIntErrClear");
897  return retval;
898  }
899 
900  /* DMACCxConfig=
901  E=1,
902  SrcPeripheral = 1 (SLC),
903  DestPeripheral = 1 (SLC),
904  FlowCntrl = 2 (Pher -> Mem, DMA),
905  IE = 0,
906  ITC = 0,
907  L= 0,
908  H=0
909  */
910  retval = target_write_u32(target, 0x31000110,
911  1 | 1<<1 | 1<<6 | 2<<11 | 0<<14
912  | 0<<15 | 0<<16 | 0<<18);
913  if (retval != ERROR_OK) {
914  LOG_ERROR("Could not set DMACC0Config");
915  return retval;
916  }
917 
918  /* SLC_CTRL = 3 (START DMA), ECC_CLEAR */
919  retval = target_write_u32(target, 0x20020010, 0x3);
920  if (retval != ERROR_OK) {
921  LOG_ERROR("Could not set SLC_CTRL");
922  return retval;
923  }
924 
925  /* SLC_ICR = 2, INT_TC_CLR, clear pending TC*/
926  retval = target_write_u32(target, 0x20020028, 2);
927  if (retval != ERROR_OK) {
928  LOG_ERROR("Could not set SLC_ICR");
929  return retval;
930  }
931 
932  /* SLC_TC */
933  retval = target_write_u32(target, 0x20020030, count);
934  if (retval != ERROR_OK) {
935  LOG_ERROR("lpc32xx_start_slc_dma: Could not set SLC_TC");
936  return retval;
937  }
938 
939  /* Wait finish */
940  if (do_wait && !lpc32xx_tc_ready(nand, 100)) {
941  LOG_ERROR("timeout while waiting for completion of DMA");
943  }
944 
945  return retval;
946 }
947 
948 static int lpc32xx_dma_ready(struct nand_device *nand, int timeout)
949 {
950  struct target *target = nand->target;
951 
952  LOG_DEBUG("lpc32xx_dma_ready count start=%d", timeout);
953 
954  do {
955  uint32_t tc_stat;
956  uint32_t err_stat;
957  int retval;
958 
959  /* Read DMACRawIntTCStat */
960  retval = target_read_u32(target, 0x31000014, &tc_stat);
961  if (retval != ERROR_OK) {
962  LOG_ERROR("Could not read DMACRawIntTCStat");
963  return 0;
964  }
965  /* Read DMACRawIntErrStat */
966  retval = target_read_u32(target, 0x31000018, &err_stat);
967  if (retval != ERROR_OK) {
968  LOG_ERROR("Could not read DMACRawIntErrStat");
969  return 0;
970  }
971  if ((tc_stat | err_stat) & 1) {
972  LOG_DEBUG("lpc32xx_dma_ready count=%d",
973  timeout);
974  if (err_stat & 1) {
975  LOG_ERROR("lpc32xx_dma_ready "
976  "DMA error, aborted");
977  return 0;
978  } else
979  return 1;
980  }
981 
982  alive_sleep(1);
983  } while (timeout-- > 0);
984 
985  return 0;
986 }
987 
988 static uint32_t slc_ecc_copy_to_buffer(uint8_t *spare,
989  const uint32_t *ecc, int count)
990 {
991  int i;
992  for (i = 0; i < (count * 3); i += 3) {
993  uint32_t ce = ecc[i/3];
994  ce = ~(ce << 2) & 0xFFFFFF;
995  spare[i+2] = (uint8_t)(ce & 0xFF); ce >>= 8;
996  spare[i+1] = (uint8_t)(ce & 0xFF); ce >>= 8;
997  spare[i] = (uint8_t)(ce & 0xFF);
998  }
999  return 0;
1000 }
1001 
1002 static void lpc32xx_dump_oob(uint8_t *oob, uint32_t oob_size)
1003 {
1004  int addr = 0;
1005  while (oob_size > 0) {
1006  LOG_DEBUG("%02x: %02x %02x %02x %02x %02x %02x %02x %02x", addr,
1007  oob[0], oob[1], oob[2], oob[3],
1008  oob[4], oob[5], oob[6], oob[7]);
1009  oob += 8;
1010  addr += 8;
1011  oob_size -= 8;
1012  }
1013 }
1014 
1015 static int lpc32xx_write_page_slc(struct nand_device *nand,
1016  struct working_area *pworking_area,
1017  uint32_t page, uint8_t *data,
1018  uint32_t data_size, uint8_t *oob,
1019  uint32_t oob_size)
1020 {
1021  struct target *target = nand->target;
1022  int retval;
1023  uint32_t target_mem_base;
1024 
1025  LOG_DEBUG("SLC write page %" PRIx32 " data=%d, oob=%d, "
1026  "data_size=%" PRIu32 ", oob_size=%" PRIu32,
1027  page, !!data, !!oob, data_size, oob_size);
1028 
1029  target_mem_base = pworking_area->address;
1030  /*
1031  * Skip writing page which has all 0xFF data as this will
1032  * generate 0x0 value.
1033  */
1034  if (data && !oob) {
1035  uint32_t i, all_ff = 1;
1036  for (i = 0; i < data_size; i++)
1037  if (data[i] != 0xFF) {
1038  all_ff = 0;
1039  break;
1040  }
1041  if (all_ff)
1042  return ERROR_OK;
1043  }
1044  /* Make the dma descriptors in local memory */
1045  int nll = lpc32xx_make_dma_list(target_mem_base, nand->page_size, 0);
1046  /* Write them to target.
1047  XXX: Assumes host and target have same byte sex.
1048  */
1049  retval = target_write_memory(target, target_mem_base, 4,
1050  nll * sizeof(struct dmac_ll) / 4,
1051  (uint8_t *)dmalist);
1052  if (retval != ERROR_OK) {
1053  LOG_ERROR("Could not write DMA descriptors to IRAM");
1054  return retval;
1055  }
1056 
1057  retval = nand_page_command(nand, page, NAND_CMD_SEQIN, !data);
1058  if (retval != ERROR_OK) {
1059  LOG_ERROR("NAND_CMD_SEQIN failed");
1060  return retval;
1061  }
1062 
1063  /* SLC_CFG =
1064  Force nCE assert,
1065  DMA ECC enabled,
1066  ECC enabled,
1067  DMA burst enabled,
1068  DMA write to SLC,
1069  WIDTH = bus_width
1070  */
1071  retval = target_write_u32(target, 0x20020014, 0x3c);
1072  if (retval != ERROR_OK) {
1073  LOG_ERROR("Could not set SLC_CFG");
1074  return retval;
1075  }
1076  if (data) {
1077  /* Write data to target */
1078  static uint8_t fdata[2048];
1079  memset(fdata, 0xFF, nand->page_size);
1080  memcpy(fdata, data, data_size);
1081  retval = target_write_memory(target,
1082  target_mem_base + DATA_OFFS,
1083  4, nand->page_size/4, fdata);
1084  if (retval != ERROR_OK) {
1085  LOG_ERROR("Could not write data to IRAM");
1086  return retval;
1087  }
1088 
1089  /* Write first descriptor to DMA controller */
1090  retval = target_write_memory(target, 0x31000100, 4,
1091  sizeof(struct dmac_ll) / 4,
1092  (uint8_t *)dmalist);
1093  if (retval != ERROR_OK) {
1094  LOG_ERROR("Could not write DMA descriptor to DMAC");
1095  return retval;
1096  }
1097 
1098  /* Start xfer of data from iram to flash using DMA */
1099  int tot_size = nand->page_size;
1100  tot_size += tot_size == 2048 ? 64 : 16;
1101  retval = lpc32xx_start_slc_dma(nand, tot_size, 0);
1102  if (retval != ERROR_OK) {
1103  LOG_ERROR("DMA failed");
1104  return retval;
1105  }
1106 
1107  /* Wait for DMA to finish. SLC is not finished at this stage */
1108  if (!lpc32xx_dma_ready(nand, 100)) {
1109  LOG_ERROR("Data DMA failed during write");
1111  }
1112  } /* data xfer */
1113 
1114  /* Copy OOB to iram */
1115  static uint8_t foob[64];
1116  int foob_size = nand->page_size == 2048 ? 64 : 16;
1117  memset(foob, 0xFF, foob_size);
1118  if (oob) /* Raw mode */
1119  memcpy(foob, oob, oob_size);
1120  else {
1121  /* Get HW generated ECC, made while writing data */
1122  int ecc_count = nand->page_size == 2048 ? 8 : 2;
1123  static uint32_t hw_ecc[8];
1124  retval = target_read_memory(target, target_mem_base + ECC_OFFS,
1125  4, ecc_count, (uint8_t *)hw_ecc);
1126  if (retval != ERROR_OK) {
1127  LOG_ERROR("Reading hw generated ECC from IRAM failed");
1128  return retval;
1129  }
1130  /* Copy to oob, at correct offsets */
1131  static uint8_t ecc[24];
1132  slc_ecc_copy_to_buffer(ecc, hw_ecc, ecc_count);
1133  const int *layout = nand->page_size == 2048 ? lp_ooblayout : sp_ooblayout;
1134  int i;
1135  for (i = 0; i < ecc_count * 3; i++)
1136  foob[layout[i]] = ecc[i];
1137  lpc32xx_dump_oob(foob, foob_size);
1138  }
1139  retval = target_write_memory(target, target_mem_base + SPARE_OFFS, 4,
1140  foob_size / 4, foob);
1141  if (retval != ERROR_OK) {
1142  LOG_ERROR("Writing OOB to IRAM failed");
1143  return retval;
1144  }
1145 
1146  /* Write OOB descriptor to DMA controller */
1147  retval = target_write_memory(target, 0x31000100, 4,
1148  sizeof(struct dmac_ll) / 4,
1149  (uint8_t *)(&dmalist[nll-1]));
1150  if (retval != ERROR_OK) {
1151  LOG_ERROR("Could not write OOB DMA descriptor to DMAC");
1152  return retval;
1153  }
1154  if (data) {
1155  /* Only restart DMA with last descriptor,
1156  * don't setup SLC again */
1157 
1158  /* DMACIntTCClear = ch0 */
1159  retval = target_write_u32(target, 0x31000008, 1);
1160  if (retval != ERROR_OK) {
1161  LOG_ERROR("Could not set DMACIntTCClear");
1162  return retval;
1163  }
1164  /* DMACCxConfig=
1165  * E=1,
1166  * SrcPeripheral = 1 (SLC),
1167  * DestPeripheral = 1 (SLC),
1168  * FlowCntrl = 2 (Pher -> Mem, DMA),
1169  * IE = 0,
1170  * ITC = 0,
1171  * L= 0,
1172  * H=0
1173  */
1174  retval = target_write_u32(target, 0x31000110,
1175  1 | 1<<1 | 1<<6 | 2<<11 | 0<<14
1176  | 0<<15 | 0<<16 | 0<<18);
1177  if (retval != ERROR_OK) {
1178  LOG_ERROR("Could not set DMACC0Config");
1179  return retval;
1180  }
1181  /* Wait finish */
1182  if (!lpc32xx_tc_ready(nand, 100)) {
1183  LOG_ERROR("timeout while waiting for "
1184  "completion of DMA");
1186  }
1187  } else {
1188  /* Start xfer of data from iram to flash using DMA */
1189  retval = lpc32xx_start_slc_dma(nand, foob_size, 1);
1190  if (retval != ERROR_OK) {
1191  LOG_ERROR("DMA OOB failed");
1192  return retval;
1193  }
1194  }
1195 
1196  /* Let NAND start actual writing */
1197  retval = nand_write_finish(nand);
1198  if (retval != ERROR_OK) {
1199  LOG_ERROR("nand_write_finish failed");
1200  return retval;
1201  }
1202 
1203  return ERROR_OK;
1204 }
1205 
1206 static int lpc32xx_write_page(struct nand_device *nand, uint32_t page,
1207  uint8_t *data, uint32_t data_size,
1208  uint8_t *oob, uint32_t oob_size)
1209 {
1210  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
1211  struct target *target = nand->target;
1212  int retval = ERROR_OK;
1213 
1214  if (target->state != TARGET_HALTED) {
1215  LOG_ERROR("target must be halted to use LPC32xx "
1216  "NAND flash controller");
1218  }
1219 
1220  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
1221  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
1223  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
1224  if (!data && oob) {
1225  LOG_ERROR("LPC32xx MLC controller can't write "
1226  "OOB data only");
1228  }
1229 
1230  if (oob && (oob_size > 24)) {
1231  LOG_ERROR("LPC32xx MLC controller can't write more "
1232  "than 6 bytes for each quarter's OOB data");
1234  }
1235 
1236  if (data_size > (uint32_t)nand->page_size) {
1237  LOG_ERROR("data size exceeds page size");
1239  }
1240 
1241  retval = lpc32xx_write_page_mlc(nand, page, data, data_size,
1242  oob, oob_size);
1243  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
1244  struct working_area *pworking_area;
1245  if (!data && oob) {
1246  /*
1247  * if oob only mode is active original method is used
1248  * as SLC controller hangs during DMA interworking. (?)
1249  * Anyway the code supports the oob only mode below.
1250  */
1251  return nand_write_page_raw(nand, page, data,
1252  data_size, oob, oob_size);
1253  }
1255  nand->page_size + DATA_OFFS,
1256  &pworking_area);
1257  if (retval != ERROR_OK) {
1258  LOG_ERROR("Can't allocate working area in "
1259  "LPC internal RAM");
1261  }
1262  retval = lpc32xx_write_page_slc(nand, pworking_area, page,
1263  data, data_size, oob, oob_size);
1264  target_free_working_area(target, pworking_area);
1265  }
1266 
1267  return retval;
1268 }
1269 
1270 static int lpc32xx_read_page_mlc(struct nand_device *nand, uint32_t page,
1271  uint8_t *data, uint32_t data_size,
1272  uint8_t *oob, uint32_t oob_size)
1273 {
1274  struct target *target = nand->target;
1275  static uint8_t page_buffer[2048];
1276  static uint8_t oob_buffer[64];
1277  uint32_t page_bytes_done = 0;
1278  uint32_t oob_bytes_done = 0;
1279  uint32_t mlc_isr;
1280  int retval;
1281 
1282  if (!data && oob) {
1283  /* MLC_CMD = Read OOB
1284  * we can use the READOOB command on both small and large page
1285  * devices, as the controller translates the 0x50 command to
1286  * a 0x0 with appropriate positioning of the serial buffer
1287  * read pointer
1288  */
1289  retval = target_write_u32(target, 0x200b8000, NAND_CMD_READOOB);
1290  } else {
1291  /* MLC_CMD = Read0 */
1292  retval = target_write_u32(target, 0x200b8000, NAND_CMD_READ0);
1293  }
1294  if (retval != ERROR_OK) {
1295  LOG_ERROR("could not set MLC_CMD");
1297  }
1298  if (nand->page_size == 512) {
1299  /* small page device
1300  * MLC_ADDR = 0x0 (one column cycle) */
1301  retval = target_write_u32(target, 0x200b8004, 0x0);
1302  if (retval != ERROR_OK) {
1303  LOG_ERROR("could not set MLC_ADDR");
1305  }
1306 
1307  /* MLC_ADDR = row */
1308  retval = target_write_u32(target, 0x200b8004, page & 0xff);
1309  if (retval != ERROR_OK) {
1310  LOG_ERROR("could not set MLC_ADDR");
1312  }
1313  retval = target_write_u32(target, 0x200b8004,
1314  (page >> 8) & 0xff);
1315  if (retval != ERROR_OK) {
1316  LOG_ERROR("could not set MLC_ADDR");
1318  }
1319 
1320  if (nand->address_cycles == 4) {
1321  retval = target_write_u32(target, 0x200b8004,
1322  (page >> 16) & 0xff);
1323  if (retval != ERROR_OK) {
1324  LOG_ERROR("could not set MLC_ADDR");
1326  }
1327  }
1328  } else {
1329  /* large page device
1330  * MLC_ADDR = 0x0 (two column cycles) */
1331  retval = target_write_u32(target, 0x200b8004, 0x0);
1332  if (retval != ERROR_OK) {
1333  LOG_ERROR("could not set MLC_ADDR");
1335  }
1336  retval = target_write_u32(target, 0x200b8004, 0x0);
1337  if (retval != ERROR_OK) {
1338  LOG_ERROR("could not set MLC_ADDR");
1340  }
1341 
1342  /* MLC_ADDR = row */
1343  retval = target_write_u32(target, 0x200b8004, page & 0xff);
1344  if (retval != ERROR_OK) {
1345  LOG_ERROR("could not set MLC_ADDR");
1347  }
1348  retval = target_write_u32(target, 0x200b8004,
1349  (page >> 8) & 0xff);
1350  if (retval != ERROR_OK) {
1351  LOG_ERROR("could not set MLC_ADDR");
1353  }
1354 
1355  /* MLC_CMD = Read Start */
1356  retval = target_write_u32(target, 0x200b8000,
1358  if (retval != ERROR_OK) {
1359  LOG_ERROR("could not set MLC_CMD");
1361  }
1362  }
1363 
1364  while (page_bytes_done < (uint32_t)nand->page_size) {
1365  /* MLC_ECC_AUTO_DEC_REG = dummy */
1366  retval = target_write_u32(target, 0x200b8014, 0xaa55aa55);
1367  if (retval != ERROR_OK) {
1368  LOG_ERROR("could not set MLC_ECC_AUTO_DEC_REG");
1370  }
1371 
1372  if (!lpc32xx_controller_ready(nand, 1000)) {
1373  LOG_ERROR("timeout while waiting for "
1374  "completion of auto decode cycle");
1376  }
1377 
1378  retval = target_read_u32(target, 0x200b8048, &mlc_isr);
1379  if (retval != ERROR_OK) {
1380  LOG_ERROR("could not read MLC_ISR");
1382  }
1383 
1384  if (mlc_isr & 0x8) {
1385  if (mlc_isr & 0x40) {
1386  LOG_ERROR("uncorrectable error detected: 0x%2.2" PRIx32, mlc_isr);
1388  }
1389 
1390  LOG_WARNING("%i symbol error detected and corrected",
1391  ((int)(((mlc_isr & 0x30) >> 4) + 1)));
1392  }
1393 
1394  if (data) {
1395  retval = target_read_memory(target, 0x200a8000, 4, 128,
1396  page_buffer + page_bytes_done);
1397  if (retval != ERROR_OK) {
1398  LOG_ERROR("could not read MLC_BUF (data)");
1400  }
1401  }
1402 
1403  if (oob) {
1404  retval = target_read_memory(target, 0x200a8000, 4, 4,
1405  oob_buffer + oob_bytes_done);
1406  if (retval != ERROR_OK) {
1407  LOG_ERROR("could not read MLC_BUF (oob)");
1409  }
1410  }
1411 
1412  page_bytes_done += 512;
1413  oob_bytes_done += 16;
1414  }
1415 
1416  if (data)
1417  memcpy(data, page_buffer, data_size);
1418 
1419  if (oob)
1420  memcpy(oob, oob_buffer, oob_size);
1421 
1422  return ERROR_OK;
1423 }
1424 
1425 static int lpc32xx_read_page_slc(struct nand_device *nand,
1426  struct working_area *pworking_area,
1427  uint32_t page, uint8_t *data,
1428  uint32_t data_size, uint8_t *oob,
1429  uint32_t oob_size)
1430 {
1431  struct target *target = nand->target;
1432  int retval;
1433  uint32_t target_mem_base;
1434 
1435  LOG_DEBUG("SLC read page %" PRIx32 " data=%" PRIu32 ", oob=%" PRIu32,
1436  page, data_size, oob_size);
1437 
1438  target_mem_base = pworking_area->address;
1439 
1440  /* Make the dma descriptors in local memory */
1441  int nll = lpc32xx_make_dma_list(target_mem_base, nand->page_size, 1);
1442  /* Write them to target.
1443  XXX: Assumes host and target have same byte sex.
1444  */
1445  retval = target_write_memory(target, target_mem_base, 4,
1446  nll * sizeof(struct dmac_ll) / 4,
1447  (uint8_t *)dmalist);
1448  if (retval != ERROR_OK) {
1449  LOG_ERROR("Could not write DMA descriptors to IRAM");
1450  return retval;
1451  }
1452 
1453  retval = nand_page_command(nand, page, NAND_CMD_READ0, 0);
1454  if (retval != ERROR_OK) {
1455  LOG_ERROR("lpc32xx_read_page_slc: NAND_CMD_READ0 failed");
1456  return retval;
1457  }
1458 
1459  /* SLC_CFG =
1460  Force nCE assert,
1461  DMA ECC enabled,
1462  ECC enabled,
1463  DMA burst enabled,
1464  DMA read from SLC,
1465  WIDTH = bus_width
1466  */
1467  retval = target_write_u32(target, 0x20020014, 0x3e);
1468  if (retval != ERROR_OK) {
1469  LOG_ERROR("lpc32xx_read_page_slc: Could not set SLC_CFG");
1470  return retval;
1471  }
1472 
1473  /* Write first descriptor to DMA controller */
1474  retval = target_write_memory(target, 0x31000100, 4,
1475  sizeof(struct dmac_ll) / 4, (uint8_t *)dmalist);
1476  if (retval != ERROR_OK) {
1477  LOG_ERROR("Could not write DMA descriptor to DMAC");
1478  return retval;
1479  }
1480 
1481  /* Start xfer of data from flash to iram using DMA */
1482  int tot_size = nand->page_size;
1483  tot_size += nand->page_size == 2048 ? 64 : 16;
1484  retval = lpc32xx_start_slc_dma(nand, tot_size, 1);
1485  if (retval != ERROR_OK) {
1486  LOG_ERROR("lpc32xx_read_page_slc: DMA read failed");
1487  return retval;
1488  }
1489 
1490  /* Copy data from iram */
1491  if (data) {
1492  retval = target_read_memory(target, target_mem_base + DATA_OFFS,
1493  4, data_size/4, data);
1494  if (retval != ERROR_OK) {
1495  LOG_ERROR("Could not read data from IRAM");
1496  return retval;
1497  }
1498  }
1499  if (oob) {
1500  /* No error correction, just return data as read from flash */
1501  retval = target_read_memory(target,
1502  target_mem_base + SPARE_OFFS, 4,
1503  oob_size/4, oob);
1504  if (retval != ERROR_OK) {
1505  LOG_ERROR("Could not read OOB from IRAM");
1506  return retval;
1507  }
1508  return ERROR_OK;
1509  }
1510 
1511  /* Copy OOB from flash, stored in IRAM */
1512  static uint8_t foob[64];
1513  retval = target_read_memory(target, target_mem_base + SPARE_OFFS,
1514  4, nand->page_size == 2048 ? 16 : 4, foob);
1515  lpc32xx_dump_oob(foob, nand->page_size == 2048 ? 64 : 16);
1516  if (retval != ERROR_OK) {
1517  LOG_ERROR("Could not read OOB from IRAM");
1518  return retval;
1519  }
1520  /* Copy ECC from HW, generated while reading */
1521  int ecc_count = nand->page_size == 2048 ? 8 : 2;
1522  static uint32_t hw_ecc[8]; /* max size */
1523  retval = target_read_memory(target, target_mem_base + ECC_OFFS, 4,
1524  ecc_count, (uint8_t *)hw_ecc);
1525  if (retval != ERROR_OK) {
1526  LOG_ERROR("Could not read hw generated ECC from IRAM");
1527  return retval;
1528  }
1529  static uint8_t ecc[24];
1530  slc_ecc_copy_to_buffer(ecc, hw_ecc, ecc_count);
1531  /* Copy ECC from flash using correct layout */
1532  static uint8_t fecc[24];/* max size */
1533  const int *layout = nand->page_size == 2048 ? lp_ooblayout : sp_ooblayout;
1534  int i;
1535  for (i = 0; i < ecc_count * 3; i++)
1536  fecc[i] = foob[layout[i]];
1537  /* Compare ECC and possibly correct data */
1538  for (i = 0; i < ecc_count; i++) {
1539  retval = nand_correct_data(nand, data + 256*i, &fecc[i * 3],
1540  &ecc[i * 3]);
1541  if (retval > 0)
1542  LOG_WARNING("error detected and corrected: %" PRIu32 "/%d",
1543  page, i);
1544  if (retval < 0)
1545  break;
1546  }
1547  if (i == ecc_count)
1548  retval = ERROR_OK;
1549  else {
1550  LOG_ERROR("uncorrectable error detected: %" PRIu32 "/%d", page, i);
1551  retval = ERROR_NAND_OPERATION_FAILED;
1552  }
1553  return retval;
1554 }
1555 
1556 static int lpc32xx_read_page(struct nand_device *nand, uint32_t page,
1557  uint8_t *data, uint32_t data_size,
1558  uint8_t *oob, uint32_t oob_size)
1559 {
1560  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
1561  struct target *target = nand->target;
1562  int retval = ERROR_OK;
1563 
1564  if (target->state != TARGET_HALTED) {
1565  LOG_ERROR("target must be halted to use LPC32xx "
1566  "NAND flash controller");
1568  }
1569 
1570  if (lpc32xx_info->selected_controller == LPC32XX_NO_CONTROLLER) {
1571  LOG_ERROR("BUG: no LPC32xx NAND flash controller selected");
1573  } else if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
1574  if (data_size > (uint32_t)nand->page_size) {
1575  LOG_ERROR("data size exceeds page size");
1577  }
1578  retval = lpc32xx_read_page_mlc(nand, page, data, data_size,
1579  oob, oob_size);
1580  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
1581  struct working_area *pworking_area;
1582 
1584  nand->page_size + 0x200,
1585  &pworking_area);
1586  if (retval != ERROR_OK) {
1587  LOG_ERROR("Can't allocate working area in "
1588  "LPC internal RAM");
1590  }
1591  retval = lpc32xx_read_page_slc(nand, pworking_area, page,
1592  data, data_size, oob, oob_size);
1593  target_free_working_area(target, pworking_area);
1594  }
1595 
1596  return retval;
1597 }
1598 
1599 static int lpc32xx_controller_ready(struct nand_device *nand, int timeout)
1600 {
1601  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
1602  struct target *target = nand->target;
1603  int retval;
1604 
1605  if (target->state != TARGET_HALTED) {
1606  LOG_ERROR("target must be halted to use LPC32xx "
1607  "NAND flash controller");
1609  }
1610 
1611  LOG_DEBUG("lpc32xx_controller_ready count start=%d", timeout);
1612 
1613  do {
1614  if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
1615  uint8_t status;
1616 
1617  /* Read MLC_ISR, wait for controller to become ready */
1618  retval = target_read_u8(target, 0x200b8048, &status);
1619  if (retval != ERROR_OK) {
1620  LOG_ERROR("could not set MLC_STAT");
1622  }
1623 
1624  if (status & 2) {
1625  LOG_DEBUG("lpc32xx_controller_ready count=%d",
1626  timeout);
1627  return 1;
1628  }
1629  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
1630  uint32_t status;
1631 
1632  /* Read SLC_STAT and check READY bit */
1633  retval = target_read_u32(target, 0x20020018, &status);
1634  if (retval != ERROR_OK) {
1635  LOG_ERROR("could not set SLC_STAT");
1637  }
1638 
1639  if (status & 1) {
1640  LOG_DEBUG("lpc32xx_controller_ready count=%d",
1641  timeout);
1642  return 1;
1643  }
1644  }
1645 
1646  alive_sleep(1);
1647  } while (timeout-- > 0);
1648 
1649  return 0;
1650 }
1651 
1652 static int lpc32xx_nand_ready(struct nand_device *nand, int timeout)
1653 {
1654  struct lpc32xx_nand_controller *lpc32xx_info = nand->controller_priv;
1655  struct target *target = nand->target;
1656  int retval;
1657 
1658  if (target->state != TARGET_HALTED) {
1659  LOG_ERROR("target must be halted to use LPC32xx "
1660  "NAND flash controller");
1662  }
1663 
1664  LOG_DEBUG("lpc32xx_nand_ready count start=%d", timeout);
1665 
1666  do {
1667  if (lpc32xx_info->selected_controller == LPC32XX_MLC_CONTROLLER) {
1668  uint8_t status = 0x0;
1669 
1670  /* Read MLC_ISR, wait for NAND flash device to
1671  * become ready */
1672  retval = target_read_u8(target, 0x200b8048, &status);
1673  if (retval != ERROR_OK) {
1674  LOG_ERROR("could not read MLC_ISR");
1676  }
1677 
1678  if (status & 1) {
1679  LOG_DEBUG("lpc32xx_nand_ready count end=%d",
1680  timeout);
1681  return 1;
1682  }
1683  } else if (lpc32xx_info->selected_controller == LPC32XX_SLC_CONTROLLER) {
1684  uint32_t status = 0x0;
1685 
1686  /* Read SLC_STAT and check READY bit */
1687  retval = target_read_u32(target, 0x20020018, &status);
1688  if (retval != ERROR_OK) {
1689  LOG_ERROR("could not read SLC_STAT");
1691  }
1692 
1693  if (status & 1) {
1694  LOG_DEBUG("lpc32xx_nand_ready count end=%d",
1695  timeout);
1696  return 1;
1697  }
1698  }
1699 
1700  alive_sleep(1);
1701  } while (timeout-- > 0);
1702 
1703  return 0;
1704 }
1705 
1706 static int lpc32xx_tc_ready(struct nand_device *nand, int timeout)
1707 {
1708  struct target *target = nand->target;
1709 
1710  LOG_DEBUG("lpc32xx_tc_ready count start=%d", timeout);
1711 
1712  do {
1713  uint32_t status = 0x0;
1714  int retval;
1715  /* Read SLC_INT_STAT and check INT_TC_STAT bit */
1716  retval = target_read_u32(target, 0x2002001c, &status);
1717  if (retval != ERROR_OK) {
1718  LOG_ERROR("Could not read SLC_INT_STAT");
1719  return 0;
1720  }
1721  if (status & 2) {
1722  LOG_DEBUG("lpc32xx_tc_ready count=%d", timeout);
1723  return 1;
1724  }
1725 
1726  alive_sleep(1);
1727  } while (timeout-- > 0);
1728 
1729  return 0;
1730 }
1731 
1732 COMMAND_HANDLER(handle_lpc32xx_select_command)
1733 {
1734  struct lpc32xx_nand_controller *lpc32xx_info = NULL;
1735  char *selected[] = {
1736  "no", "mlc", "slc"
1737  };
1738 
1739  if ((CMD_ARGC < 1) || (CMD_ARGC > 3))
1741 
1742  unsigned int num;
1743  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num);
1744  struct nand_device *nand = get_nand_device_by_num(num);
1745  if (!nand) {
1746  command_print(CMD, "nand device '#%s' is out of bounds",
1747  CMD_ARGV[0]);
1748  return ERROR_OK;
1749  }
1750 
1751  lpc32xx_info = nand->controller_priv;
1752 
1753  if (CMD_ARGC >= 2) {
1754  if (strcmp(CMD_ARGV[1], "mlc") == 0) {
1755  lpc32xx_info->selected_controller =
1757  } else if (strcmp(CMD_ARGV[1], "slc") == 0) {
1758  lpc32xx_info->selected_controller =
1760  } else
1762  }
1763 
1764  command_print(CMD, "%s controller selected",
1765  selected[lpc32xx_info->selected_controller]);
1766 
1767  return ERROR_OK;
1768 }
1769 
1770 static const struct command_registration lpc32xx_exec_command_handlers[] = {
1771  {
1772  .name = "select",
1773  .handler = handle_lpc32xx_select_command,
1774  .mode = COMMAND_EXEC,
1775  .help = "select MLC or SLC controller (default is MLC)",
1776  .usage = "bank_id ['mlc'|'slc' ]",
1777  },
1779 };
1780 static const struct command_registration lpc32xx_command_handler[] = {
1781  {
1782  .name = "lpc32xx",
1783  .mode = COMMAND_ANY,
1784  .help = "LPC32xx NAND flash controller commands",
1785  .usage = "",
1787  },
1789 };
1790 
1792  .name = "lpc32xx",
1793  .commands = lpc32xx_command_handler,
1794  .nand_device_command = lpc32xx_nand_device_command,
1795  .init = lpc32xx_init,
1796  .reset = lpc32xx_reset,
1797  .command = lpc32xx_command,
1798  .address = lpc32xx_address,
1799  .write_data = lpc32xx_write_data,
1800  .read_data = lpc32xx_read_data,
1801  .write_page = lpc32xx_write_page,
1802  .read_page = lpc32xx_read_page,
1803  .nand_ready = lpc32xx_nand_ready,
1804 };
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:389
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:146
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:161
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:405
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:156
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:445
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
ecc
Definition: davinci.c:22
uint32_t page_size
Page size.
Definition: dw-spi-helper.h:3
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
#define ERROR_FLASH_OPERATION_FAILED
Definition: flash/common.h:30
int nand_read_status(struct nand_device *nand, uint8_t *status)
int nand_write_finish(struct nand_device *nand)
int nand_write_page_raw(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
struct nand_device * get_nand_device_by_num(int num)
int nand_page_command(struct nand_device *nand, uint32_t page, uint8_t cmd, bool oob_only)
void alive_sleep(uint64_t ms)
Definition: log.c:478
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
#define DATA_OFFS
Definition: lpc32xx.c:38
static int lpc32xx_tc_ready(struct nand_device *nand, int timeout)
Definition: lpc32xx.c:1706
static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size, int do_read)
Definition: lpc32xx.c:733
static int lpc32xx_pll(int fclkin, uint32_t pll_ctrl)
Definition: lpc32xx.c:88
static int lpc32xx_write_page_slc(struct nand_device *nand, struct working_area *pworking_area, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:1015
static const struct command_registration lpc32xx_command_handler[]
Definition: lpc32xx.c:1780
#define ECC_OFFS
Definition: lpc32xx.c:36
static int lpc32xx_write_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:1206
static int lpc32xx_read_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:1556
static const int sp_ooblayout[]
Definition: lpc32xx.c:40
static int lpc32xx_controller_ready(struct nand_device *nand, int timeout)
Definition: lpc32xx.c:1599
static int lpc32xx_address(struct nand_device *nand, uint8_t address)
Definition: lpc32xx.c:456
static const int lp_ooblayout[]
Definition: lpc32xx.c:43
static int lpc32xx_read_data(struct nand_device *nand, void *data)
Definition: lpc32xx.c:524
static float lpc32xx_cycle_time(struct nand_device *nand)
Definition: lpc32xx.c:116
static int lpc32xx_init(struct nand_device *nand)
Definition: lpc32xx.c:174
static int lpc32xx_read_page_mlc(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:1270
static int lpc32xx_start_slc_dma(struct nand_device *nand, uint32_t count, int do_wait)
Definition: lpc32xx.c:880
static const struct command_registration lpc32xx_exec_command_handlers[]
Definition: lpc32xx.c:1770
static int lpc32xx_write_data(struct nand_device *nand, uint16_t data)
Definition: lpc32xx.c:490
static int lpc32xx_reset(struct nand_device *nand)
Definition: lpc32xx.c:376
static struct dmac_ll dmalist[(2048/256) *2+1]
Definition: lpc32xx.c:57
COMMAND_HANDLER(handle_lpc32xx_select_command)
Definition: lpc32xx.c:1732
static void lpc32xx_dump_oob(uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:1002
static int lpc32xx_write_page_mlc(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:574
static int lpc32xx_dma_ready(struct nand_device *nand, int timeout)
Definition: lpc32xx.c:948
static int lpc32xx_nand_ready(struct nand_device *nand, int timeout)
Definition: lpc32xx.c:1652
static uint32_t slc_ecc_copy_to_buffer(uint8_t *spare, const uint32_t *ecc, int count)
Definition: lpc32xx.c:988
#define SPARE_OFFS
Definition: lpc32xx.c:37
NAND_DEVICE_COMMAND_HANDLER(lpc32xx_nand_device_command)
Definition: lpc32xx.c:61
static int lpc32xx_read_page_slc(struct nand_device *nand, struct working_area *pworking_area, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Definition: lpc32xx.c:1425
static int lpc32xx_command(struct nand_device *nand, uint8_t command)
Definition: lpc32xx.c:422
@ LPC32XX_MLC_CONTROLLER
Definition: lpc32xx.h:13
@ LPC32XX_SLC_CONTROLLER
Definition: lpc32xx.h:14
@ LPC32XX_NO_CONTROLLER
Definition: lpc32xx.h:12
#define ERROR_NAND_OPERATION_TIMEOUT
Definition: nand/core.h:218
#define ERROR_NAND_OPERATION_FAILED
Definition: nand/core.h:217
int nand_correct_data(struct nand_device *nand, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
nand_correct_data - Detect and correct a 1 bit error for 256 byte block
Definition: ecc.c:113
@ NAND_CMD_SEQIN
Definition: nand/core.h:148
@ NAND_CMD_READSTART
Definition: nand/core.h:155
@ NAND_CMD_READOOB
Definition: nand/core.h:144
@ NAND_CMD_READ0
Definition: nand/core.h:140
@ NAND_CMD_PAGEPROG
Definition: nand/core.h:143
@ NAND_STATUS_FAIL
Definition: nand/core.h:162
#define ERROR_NAND_OPERATION_NOT_SUPPORTED
Definition: nand/core.h:219
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
struct rtt_control ctrl
Control block.
Definition: rtt/rtt.c:25
const char * name
Definition: command.h:239
volatile uint32_t next_lli
Definition: lpc32xx.c:53
volatile uint32_t dma_dest
Definition: lpc32xx.c:52
volatile uint32_t dma_src
Definition: lpc32xx.c:51
volatile uint32_t next_ctrl
Definition: lpc32xx.c:54
uint32_t sw_wp_upper_bound
Definition: lpc32xx.h:22
uint32_t sw_wp_lower_bound
Definition: lpc32xx.h:21
enum lpc32xx_selected_controller selected_controller
Definition: lpc32xx.h:19
void * controller_priv
Definition: nand/core.h:51
int page_size
Definition: nand/core.h:56
int address_cycles
Definition: nand/core.h:55
int bus_width
Definition: nand/core.h:54
struct target * target
Definition: nand/core.h:49
Interface for NAND flash controllers.
Definition: nand/driver.h:23
Definition: target.h:119
enum target_state state
Definition: target.h:167
Definition: psoc6.c:83
target_addr_t address
Definition: target.h:89
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
Definition: target.c:2601
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
Definition: target.c:1288
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2090
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2635
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
Definition: target.c:2148
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2561
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
Definition: target.c:1260
@ TARGET_HALTED
Definition: target.h:58
#define NULL
Definition: usb.h:16
uint8_t status[4]
Definition: vdebug.c:17
uint8_t count[4]
Definition: vdebug.c:22