You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

755 lines
20 KiB

  1. /*
  2. * Copyright (C) 2009 by Dean Glazeski
  3. * dnglaze@gmail.com
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the
  17. * Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include <target/arm.h>
  24. #include <helper/log.h>
  25. #include "imp.h"
  26. #include "arm_io.h"
  27. #define AT91C_PIOx_SODR (0x30) /**< Offset to PIO SODR. */
  28. #define AT91C_PIOx_CODR (0x34) /**< Offset to PIO CODR. */
  29. #define AT91C_PIOx_PDSR (0x3C) /**< Offset to PIO PDSR. */
  30. #define AT91C_ECCx_CR (0x00) /**< Offset to ECC CR. */
  31. #define AT91C_ECCx_SR (0x08) /**< Offset to ECC SR. */
  32. #define AT91C_ECCx_PR (0x0C) /**< Offset to ECC PR. */
  33. #define AT91C_ECCx_NPR (0x10) /**< Offset to ECC NPR. */
  34. /**
  35. * Representation of a pin on an AT91SAM9 chip.
  36. */
  37. struct at91sam9_pin {
  38. /** Target this pin is on. */
  39. struct target *target;
  40. /** Address of the PIO controller. */
  41. uint32_t pioc;
  42. /** Pin number. */
  43. uint32_t num;
  44. };
  45. /**
  46. * Private data for the controller that is stored in the NAND device structure.
  47. */
  48. struct at91sam9_nand {
  49. /** Target the NAND is attached to. */
  50. struct target *target;
  51. /** Address of the ECC controller for NAND. */
  52. uint32_t ecc;
  53. /** Address data is written to. */
  54. uint32_t data;
  55. /** Address commands are written to. */
  56. uint32_t cmd;
  57. /** Address addresses are written to. */
  58. uint32_t addr;
  59. /** I/O structure for hosted reads/writes. */
  60. struct arm_nand_data io;
  61. /** Pin representing the ready/~busy line. */
  62. struct at91sam9_pin busy;
  63. /** Pin representing the chip enable. */
  64. struct at91sam9_pin ce;
  65. };
  66. /**
  67. * Checks if the target is halted and prints an error message if it isn't.
  68. *
  69. * @param target Target to be checked.
  70. * @param label String label for where function is called from.
  71. * @return True if the target is halted.
  72. */
  73. static int at91sam9_halted(struct target *target, const char *label)
  74. {
  75. if (target->state == TARGET_HALTED)
  76. return true;
  77. LOG_ERROR("Target must be halted to use NAND controller (%s)", label);
  78. return false;
  79. }
  80. /**
  81. * Initialize the AT91SAM9 NAND controller.
  82. *
  83. * @param nand NAND device the controller is attached to.
  84. * @return Success or failure of initialization.
  85. */
  86. static int at91sam9_init(struct nand_device *nand)
  87. {
  88. struct at91sam9_nand *info = nand->controller_priv;
  89. struct target *target = info->target;
  90. if (!at91sam9_halted(target, "init")) {
  91. return ERROR_NAND_OPERATION_FAILED;
  92. }
  93. return ERROR_OK;
  94. }
  95. /**
  96. * Enable NAND device attached to a controller.
  97. *
  98. * @param info NAND controller information for controlling NAND device.
  99. * @return Success or failure of the enabling.
  100. */
  101. static int at91sam9_enable(struct at91sam9_nand *info)
  102. {
  103. struct target *target = info->target;
  104. return target_write_u32(target, info->ce.pioc + AT91C_PIOx_CODR, 1 << info->ce.num);
  105. }
  106. /**
  107. * Disable NAND device attached to a controller.
  108. *
  109. * @param info NAND controller information for controlling NAND device.
  110. * @return Success or failure of the disabling.
  111. */
  112. static int at91sam9_disable(struct at91sam9_nand *info)
  113. {
  114. struct target *target = info->target;
  115. return target_write_u32(target, info->ce.pioc + AT91C_PIOx_SODR, 1 << info->ce.num);
  116. }
  117. /**
  118. * Send a command to the NAND device.
  119. *
  120. * @param nand NAND device to write the command to.
  121. * @param command Command to be written.
  122. * @return Success or failure of writing the command.
  123. */
  124. static int at91sam9_command(struct nand_device *nand, uint8_t command)
  125. {
  126. struct at91sam9_nand *info = nand->controller_priv;
  127. struct target *target = info->target;
  128. if (!at91sam9_halted(target, "command")) {
  129. return ERROR_NAND_OPERATION_FAILED;
  130. }
  131. at91sam9_enable(info);
  132. return target_write_u8(target, info->cmd, command);
  133. }
  134. /**
  135. * Reset the AT91SAM9 NAND controller.
  136. *
  137. * @param nand NAND device to be reset.
  138. * @return Success or failure of reset.
  139. */
  140. static int at91sam9_reset(struct nand_device *nand)
  141. {
  142. struct at91sam9_nand *info = nand->controller_priv;
  143. if (!at91sam9_halted(info->target, "reset")) {
  144. return ERROR_NAND_OPERATION_FAILED;
  145. }
  146. return at91sam9_disable(info);
  147. }
  148. /**
  149. * Send an address to the NAND device attached to an AT91SAM9 NAND controller.
  150. *
  151. * @param nand NAND device to send the address to.
  152. * @param address Address to be sent.
  153. * @return Success or failure of sending the address.
  154. */
  155. static int at91sam9_address(struct nand_device *nand, uint8_t address)
  156. {
  157. struct at91sam9_nand *info = nand->controller_priv;
  158. struct target *target = info->target;
  159. if (!at91sam9_halted(info->target, "address")) {
  160. return ERROR_NAND_OPERATION_FAILED;
  161. }
  162. return target_write_u8(target, info->addr, address);
  163. }
  164. /**
  165. * Read data directly from the NAND device attached to an AT91SAM9 NAND
  166. * controller.
  167. *
  168. * @param nand NAND device to read from.
  169. * @param data Pointer to where the data should be put.
  170. * @return Success or failure of reading the data.
  171. */
  172. static int at91sam9_read_data(struct nand_device *nand, void *data)
  173. {
  174. struct at91sam9_nand *info = nand->controller_priv;
  175. struct target *target = info->target;
  176. if (!at91sam9_halted(info->target, "read data")) {
  177. return ERROR_NAND_OPERATION_FAILED;
  178. }
  179. return target_read_u8(target, info->data, data);
  180. }
  181. /**
  182. * Write data directly to the NAND device attached to an AT91SAM9 NAND
  183. * controller.
  184. *
  185. * @param nand NAND device to be written to.
  186. * @param data Data to be written.
  187. * @return Success or failure of the data write.
  188. */
  189. static int at91sam9_write_data(struct nand_device *nand, uint16_t data)
  190. {
  191. struct at91sam9_nand *info = nand->controller_priv;
  192. struct target *target = info->target;
  193. if (!at91sam9_halted(target, "write data")) {
  194. return ERROR_NAND_OPERATION_FAILED;
  195. }
  196. return target_write_u8(target, info->data, data);
  197. }
  198. /**
  199. * Determine if the NAND device is ready by looking at the ready/~busy pin.
  200. *
  201. * @param nand NAND device to check.
  202. * @param timeout Time in milliseconds to wait for NAND to be ready.
  203. * @return True if the NAND is ready in the timeout period.
  204. */
  205. static int at91sam9_nand_ready(struct nand_device *nand, int timeout)
  206. {
  207. struct at91sam9_nand *info = nand->controller_priv;
  208. struct target *target = info->target;
  209. uint32_t status;
  210. if (!at91sam9_halted(target, "nand ready")) {
  211. return 0;
  212. }
  213. do {
  214. target_read_u32(target, info->busy.pioc + AT91C_PIOx_PDSR, &status);
  215. if (status & (1 << info->busy.num)) {
  216. return 1;
  217. }
  218. alive_sleep(1);
  219. } while (timeout-- > 0);
  220. return 0;
  221. }
  222. /**
  223. * Read a block of data from the NAND device attached to an AT91SAM9. This
  224. * utilizes the ARM hosted NAND read function.
  225. *
  226. * @param nand NAND device to read from.
  227. * @param data Pointer to where the read data should be placed.
  228. * @param size Size of the data being read.
  229. * @return Success or failure of the hosted read.
  230. */
  231. static int at91sam9_read_block_data(struct nand_device *nand, uint8_t *data, int size)
  232. {
  233. struct at91sam9_nand *info = nand->controller_priv;
  234. struct arm_nand_data *io = &info->io;
  235. int status;
  236. if (!at91sam9_halted(info->target, "read block")) {
  237. return ERROR_NAND_OPERATION_FAILED;
  238. }
  239. io->chunk_size = nand->page_size;
  240. status = arm_nandread(io, data, size);
  241. return status;
  242. }
  243. /**
  244. * Write a block of data to a NAND device attached to an AT91SAM9. This uses
  245. * the ARM hosted write function to write the data.
  246. *
  247. * @param nand NAND device to write to.
  248. * @param data Data to be written to device.
  249. * @param size Size of the data being written.
  250. * @return Success or failure of the hosted write.
  251. */
  252. static int at91sam9_write_block_data(struct nand_device *nand, uint8_t *data, int size)
  253. {
  254. struct at91sam9_nand *info = nand->controller_priv;
  255. struct arm_nand_data *io = &info->io;
  256. int status;
  257. if (!at91sam9_halted(info->target, "write block")) {
  258. return ERROR_NAND_OPERATION_FAILED;
  259. }
  260. io->chunk_size = nand->page_size;
  261. status = arm_nandwrite(io, data, size);
  262. return status;
  263. }
  264. /**
  265. * Initialize the ECC controller on the AT91SAM9.
  266. *
  267. * @param target Target to configure ECC on.
  268. * @param info NAND controller information for where the ECC is.
  269. * @return Success or failure of initialization.
  270. */
  271. static int at91sam9_ecc_init(struct target *target, struct at91sam9_nand *info)
  272. {
  273. if (!info->ecc) {
  274. LOG_ERROR("ECC controller address must be set when not reading raw NAND data");
  275. return ERROR_NAND_OPERATION_FAILED;
  276. }
  277. // reset ECC parity registers
  278. return target_write_u32(target, info->ecc + AT91C_ECCx_CR, 1);
  279. }
  280. /**
  281. * Initialize an area for the OOB based on whether a user is requesting the OOB
  282. * data. This determines the size of the OOB and allocates the space in case
  283. * the user has not requested the OOB data.
  284. *
  285. * @param nand NAND device we are creating an OOB for.
  286. * @param oob Pointer to the user supplied OOB area.
  287. * @param size Size of the OOB.
  288. * @return Pointer to an area to store OOB data.
  289. */
  290. static uint8_t * at91sam9_oob_init(struct nand_device *nand, uint8_t *oob, uint32_t *size)
  291. {
  292. if (!oob) {
  293. // user doesn't want OOB, allocate it
  294. if (nand->page_size == 512) {
  295. *size = 16;
  296. } else if (nand->page_size == 2048) {
  297. *size = 64;
  298. }
  299. oob = malloc(*size);
  300. if (!oob) {
  301. LOG_ERROR("Unable to allocate space for OOB");
  302. }
  303. memset(oob, 0xFF, *size);
  304. }
  305. return oob;
  306. }
  307. /**
  308. * Reads a page from an AT91SAM9 NAND controller and verifies using 1-bit ECC
  309. * controller on chip. This makes an attempt to correct any errors that are
  310. * encountered while reading the page of data.
  311. *
  312. * @param nand NAND device to read from
  313. * @param page Page to be read.
  314. * @param data Pointer to where data should be read to.
  315. * @param data_size Size of the data to be read.
  316. * @param oob Pointer to where OOB data should be read to.
  317. * @param oob_size Size of the OOB data to be read.
  318. * @return Success or failure of reading the NAND page.
  319. */
  320. static int at91sam9_read_page(struct nand_device *nand, uint32_t page,
  321. uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
  322. {
  323. int retval;
  324. struct at91sam9_nand *info = nand->controller_priv;
  325. struct target *target = info->target;
  326. uint8_t *oob_data;
  327. uint32_t status;
  328. retval = at91sam9_ecc_init(target, info);
  329. if (ERROR_OK != retval) {
  330. return retval;
  331. }
  332. retval = nand_page_command(nand, page, NAND_CMD_READ0, !data);
  333. if (ERROR_OK != retval) {
  334. return retval;
  335. }
  336. if (data) {
  337. retval = nand_read_data_page(nand, data, data_size);
  338. if (ERROR_OK != retval) {
  339. return retval;
  340. }
  341. }
  342. oob_data = at91sam9_oob_init(nand, oob, &oob_size);
  343. retval = nand_read_data_page(nand, oob_data, oob_size);
  344. if (ERROR_OK == retval && data) {
  345. target_read_u32(target, info->ecc + AT91C_ECCx_SR, &status);
  346. if (status & 1) {
  347. LOG_ERROR("Error detected!");
  348. if (status & 4) {
  349. LOG_ERROR("Multiple errors encountered; unrecoverable!");
  350. } else {
  351. // attempt recovery
  352. uint32_t parity;
  353. target_read_u32(target,
  354. info->ecc + AT91C_ECCx_PR,
  355. &parity);
  356. uint32_t word = (parity & 0x0000FFF0) >> 4;
  357. uint32_t bit = parity & 0x0F;
  358. data[word] ^= (0x1) << bit;
  359. LOG_INFO("Data word %d, bit %d corrected.",
  360. (unsigned) word,
  361. (unsigned) bit);
  362. }
  363. }
  364. if (status & 2) {
  365. // we could write back correct ECC data
  366. LOG_ERROR("Error in ECC bytes detected");
  367. }
  368. }
  369. if (!oob) {
  370. // if it wasn't asked for, free it
  371. free(oob_data);
  372. }
  373. return retval;
  374. }
  375. /**
  376. * Write a page of data including 1-bit ECC information to a NAND device
  377. * attached to an AT91SAM9 controller. If there is OOB data to be written,
  378. * this will ignore the computed ECC from the ECC controller.
  379. *
  380. * @param nand NAND device to write to.
  381. * @param page Page to write.
  382. * @param data Pointer to data being written.
  383. * @param data_size Size of the data being written.
  384. * @param oob Pointer to OOB data being written.
  385. * @param oob_size Size of the OOB data.
  386. * @return Success or failure of the page write.
  387. */
  388. static int at91sam9_write_page(struct nand_device *nand, uint32_t page,
  389. uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
  390. {
  391. struct at91sam9_nand *info = nand->controller_priv;
  392. struct target *target = info->target;
  393. int retval;
  394. uint8_t *oob_data = oob;
  395. uint32_t parity, nparity;
  396. retval = at91sam9_ecc_init(target, info);
  397. if (ERROR_OK != retval) {
  398. return retval;
  399. }
  400. retval = nand_page_command(nand, page, NAND_CMD_SEQIN, !data);
  401. if (ERROR_OK != retval) {
  402. return retval;
  403. }
  404. if (data) {
  405. retval = nand_write_data_page(nand, data, data_size);
  406. if (ERROR_OK != retval) {
  407. LOG_ERROR("Unable to write data to NAND device");
  408. return retval;
  409. }
  410. }
  411. oob_data = at91sam9_oob_init(nand, oob, &oob_size);
  412. if (!oob) {
  413. // no OOB given, so read in the ECC parity from the ECC controller
  414. target_read_u32(target, info->ecc + AT91C_ECCx_PR, &parity);
  415. target_read_u32(target, info->ecc + AT91C_ECCx_NPR, &nparity);
  416. oob_data[0] = (uint8_t) parity;
  417. oob_data[1] = (uint8_t) (parity >> 8);
  418. oob_data[2] = (uint8_t) nparity;
  419. oob_data[3] = (uint8_t) (nparity >> 8);
  420. }
  421. retval = nand_write_data_page(nand, oob_data, oob_size);
  422. if (!oob) {
  423. free(oob_data);
  424. }
  425. if (ERROR_OK != retval) {
  426. LOG_ERROR("Unable to write OOB data to NAND");
  427. return retval;
  428. }
  429. retval = nand_write_finish(nand);
  430. return retval;
  431. }
  432. /**
  433. * Handle the initial NAND device command for AT91SAM9 controllers. This
  434. * initializes much of the controller information struct to be ready for future
  435. * reads and writes.
  436. */
  437. NAND_DEVICE_COMMAND_HANDLER(at91sam9_nand_device_command)
  438. {
  439. struct target *target = NULL;
  440. unsigned long chip = 0, ecc = 0;
  441. struct at91sam9_nand *info = NULL;
  442. LOG_DEBUG("AT91SAM9 NAND Device Command\n");
  443. if (CMD_ARGC < 3 || CMD_ARGC > 4) {
  444. LOG_ERROR("parameters: %s target chip_addr", CMD_ARGV[0]);
  445. return ERROR_NAND_OPERATION_FAILED;
  446. }
  447. target = get_target(CMD_ARGV[1]);
  448. if (!target) {
  449. LOG_ERROR("invalid target: %s", CMD_ARGV[1]);
  450. return ERROR_NAND_OPERATION_FAILED;
  451. }
  452. COMMAND_PARSE_NUMBER(ulong, CMD_ARGV[2], chip);
  453. if (chip == 0) {
  454. LOG_ERROR("invalid NAND chip address: %s", CMD_ARGV[2]);
  455. return ERROR_NAND_OPERATION_FAILED;
  456. }
  457. if (CMD_ARGC == 4) {
  458. COMMAND_PARSE_NUMBER(ulong, CMD_ARGV[3], ecc);
  459. if (ecc == 0) {
  460. LOG_ERROR("invalid ECC controller address: %s", CMD_ARGV[3]);
  461. return ERROR_NAND_OPERATION_FAILED;
  462. }
  463. }
  464. info = calloc(1, sizeof(*info));
  465. if (!info) {
  466. LOG_ERROR("unable to allocate space for controller private data");
  467. return ERROR_NAND_OPERATION_FAILED;
  468. }
  469. info->target = target;
  470. info->data = chip;
  471. info->cmd = chip | (1 << 22);
  472. info->addr = chip | (1 << 21);
  473. info->ecc = ecc;
  474. nand->controller_priv = info;
  475. info->io.target = target;
  476. info->io.data = info->data;
  477. info->io.op = ARM_NAND_NONE;
  478. return ERROR_OK;
  479. }
  480. /**
  481. * Handle the AT91SAM9 CLE command for specifying the address line to use for
  482. * writing commands to a NAND device.
  483. */
  484. COMMAND_HANDLER(handle_at91sam9_cle_command)
  485. {
  486. struct nand_device *nand = NULL;
  487. struct at91sam9_nand *info = NULL;
  488. unsigned num, address_line;
  489. if (CMD_ARGC != 2) {
  490. command_print(CMD_CTX, "incorrect number of arguments for 'at91sam9 cle' command");
  491. return ERROR_OK;
  492. }
  493. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num);
  494. nand = get_nand_device_by_num(num);
  495. if (!nand) {
  496. command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]);
  497. return ERROR_OK;
  498. }
  499. info = nand->controller_priv;
  500. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], address_line);
  501. info->cmd = info->data | (1 << address_line);
  502. return ERROR_OK;
  503. }
  504. /**
  505. * Handle the AT91SAM9 ALE command for specifying the address line to use for
  506. * writing addresses to the NAND device.
  507. */
  508. COMMAND_HANDLER(handle_at91sam9_ale_command)
  509. {
  510. struct nand_device *nand = NULL;
  511. struct at91sam9_nand *info = NULL;
  512. unsigned num, address_line;
  513. if (CMD_ARGC != 2) {
  514. return ERROR_COMMAND_SYNTAX_ERROR;
  515. }
  516. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num);
  517. nand = get_nand_device_by_num(num);
  518. if (!nand) {
  519. command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]);
  520. return ERROR_COMMAND_ARGUMENT_INVALID;
  521. }
  522. info = nand->controller_priv;
  523. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], address_line);
  524. info->addr = info->data | (1 << address_line);
  525. return ERROR_OK;
  526. }
  527. /**
  528. * Handle the AT91SAM9 RDY/~BUSY command for specifying the pin that watches the
  529. * RDY/~BUSY line from the NAND device.
  530. */
  531. COMMAND_HANDLER(handle_at91sam9_rdy_busy_command)
  532. {
  533. struct nand_device *nand = NULL;
  534. struct at91sam9_nand *info = NULL;
  535. unsigned num, base_pioc, pin_num;
  536. if (CMD_ARGC != 3) {
  537. return ERROR_COMMAND_SYNTAX_ERROR;
  538. }
  539. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num);
  540. nand = get_nand_device_by_num(num);
  541. if (!nand) {
  542. command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]);
  543. return ERROR_COMMAND_ARGUMENT_INVALID;
  544. }
  545. info = nand->controller_priv;
  546. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], base_pioc);
  547. info->busy.pioc = base_pioc;
  548. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], pin_num);
  549. info->busy.num = pin_num;
  550. return ERROR_OK;
  551. }
  552. /**
  553. * Handle the AT91SAM9 CE command for specifying the pin that is used to enable
  554. * or disable the NAND device.
  555. */
  556. COMMAND_HANDLER(handle_at91sam9_ce_command)
  557. {
  558. struct nand_device *nand = NULL;
  559. struct at91sam9_nand *info = NULL;
  560. unsigned num, base_pioc, pin_num;
  561. if (CMD_ARGC != 3) {
  562. return ERROR_COMMAND_SYNTAX_ERROR;
  563. }
  564. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num);
  565. nand = get_nand_device_by_num(num);
  566. if (!nand) {
  567. command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]);
  568. return ERROR_COMMAND_ARGUMENT_INVALID;
  569. }
  570. info = nand->controller_priv;
  571. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], base_pioc);
  572. info->ce.pioc = base_pioc;
  573. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], pin_num);
  574. info->ce.num = pin_num;
  575. return ERROR_OK;
  576. }
  577. static const struct command_registration at91sam9_sub_command_handlers[] = {
  578. {
  579. .name = "cle",
  580. .handler = handle_at91sam9_cle_command,
  581. .mode = COMMAND_CONFIG,
  582. .help = "set command latch enable address line (default is 22)",
  583. .usage = "<device_id> <address_line>",
  584. },
  585. {
  586. .name = "ale",
  587. .handler = handle_at91sam9_ale_command,
  588. .mode = COMMAND_CONFIG,
  589. .help = "set address latch enable address line (default is 21)",
  590. .usage = "<device_id> <address_line>",
  591. },
  592. {
  593. .name = "rdy_busy",
  594. .handler = handle_at91sam9_rdy_busy_command,
  595. .mode = COMMAND_CONFIG,
  596. .help = "set the input pin connected to RDY/~BUSY signal (no default)",
  597. .usage = "<device_id> <base_pioc> <pin_num>",
  598. },
  599. {
  600. .name = "ce",
  601. .handler = handle_at91sam9_ce_command,
  602. .mode = COMMAND_CONFIG,
  603. .help = "set the output pin connected to chip enable signal (no default)",
  604. .usage = "<device_id> <base_pioc> <pin_num>",
  605. },
  606. COMMAND_REGISTRATION_DONE
  607. };
  608. static const struct command_registration at91sam9_command_handler[] = {
  609. {
  610. .name = "at91sam9",
  611. .mode = COMMAND_ANY,
  612. .help = "AT91SAM9 NAND flash controller commands",
  613. .chain = at91sam9_sub_command_handlers,
  614. },
  615. COMMAND_REGISTRATION_DONE
  616. };
  617. /**
  618. * Structure representing the AT91SAM9 NAND controller.
  619. */
  620. struct nand_flash_controller at91sam9_nand_controller = {
  621. .name = "at91sam9",
  622. .nand_device_command = at91sam9_nand_device_command,
  623. .commands = at91sam9_command_handler,
  624. .init = at91sam9_init,
  625. .command = at91sam9_command,
  626. .reset = at91sam9_reset,
  627. .address = at91sam9_address,
  628. .read_data = at91sam9_read_data,
  629. .write_data = at91sam9_write_data,
  630. .nand_ready = at91sam9_nand_ready,
  631. .read_block_data = at91sam9_read_block_data,
  632. .write_block_data = at91sam9_write_block_data,
  633. .read_page = at91sam9_read_page,
  634. .write_page = at91sam9_write_page,
  635. };