ppchameleonevb.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /*
  2. * drivers/mtd/nand/ppchameleonevb.c
  3. *
  4. * Copyright (C) 2003 DAVE Srl (info@wawnet.biz)
  5. *
  6. * Derived from drivers/mtd/nand/edb7312.c
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Overview:
  14. * This is a device driver for the NAND flash devices found on the
  15. * PPChameleon/PPChameleonEVB system.
  16. * PPChameleon options (autodetected):
  17. * - BA model: no NAND
  18. * - ME model: 32MB (Samsung K9F5608U0B)
  19. * - HI model: 128MB (Samsung K9F1G08UOM)
  20. * PPChameleonEVB options:
  21. * - 32MB (Samsung K9F5608U0B)
  22. */
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/mtd/nand.h>
  28. #include <linux/mtd/partitions.h>
  29. #include <asm/io.h>
  30. #include <platforms/PPChameleonEVB.h>
  31. #undef USE_READY_BUSY_PIN
  32. #define USE_READY_BUSY_PIN
  33. /* see datasheets (tR) */
  34. #define NAND_BIG_DELAY_US 25
  35. #define NAND_SMALL_DELAY_US 10
  36. /* handy sizes */
  37. #define SZ_4M 0x00400000
  38. #define NAND_SMALL_SIZE 0x02000000
  39. #define NAND_MTD_NAME "ppchameleon-nand"
  40. #define NAND_EVB_MTD_NAME "ppchameleonevb-nand"
  41. /* GPIO pins used to drive NAND chip mounted on processor module */
  42. #define NAND_nCE_GPIO_PIN (0x80000000 >> 1)
  43. #define NAND_CLE_GPIO_PIN (0x80000000 >> 2)
  44. #define NAND_ALE_GPIO_PIN (0x80000000 >> 3)
  45. #define NAND_RB_GPIO_PIN (0x80000000 >> 4)
  46. /* GPIO pins used to drive NAND chip mounted on EVB */
  47. #define NAND_EVB_nCE_GPIO_PIN (0x80000000 >> 14)
  48. #define NAND_EVB_CLE_GPIO_PIN (0x80000000 >> 15)
  49. #define NAND_EVB_ALE_GPIO_PIN (0x80000000 >> 16)
  50. #define NAND_EVB_RB_GPIO_PIN (0x80000000 >> 31)
  51. /*
  52. * MTD structure for PPChameleonEVB board
  53. */
  54. static struct mtd_info *ppchameleon_mtd = NULL;
  55. static struct mtd_info *ppchameleonevb_mtd = NULL;
  56. /*
  57. * Module stuff
  58. */
  59. static unsigned long ppchameleon_fio_pbase = CFG_NAND0_PADDR;
  60. static unsigned long ppchameleonevb_fio_pbase = CFG_NAND1_PADDR;
  61. #ifdef MODULE
  62. module_param(ppchameleon_fio_pbase, ulong, 0);
  63. module_param(ppchameleonevb_fio_pbase, ulong, 0);
  64. #else
  65. __setup("ppchameleon_fio_pbase=", ppchameleon_fio_pbase);
  66. __setup("ppchameleonevb_fio_pbase=", ppchameleonevb_fio_pbase);
  67. #endif
  68. /*
  69. * Define static partitions for flash devices
  70. */
  71. static struct mtd_partition partition_info_hi[] = {
  72. { .name = "PPChameleon HI Nand Flash",
  73. .offset = 0,
  74. .size = 128 * 1024 * 1024
  75. }
  76. };
  77. static struct mtd_partition partition_info_me[] = {
  78. { .name = "PPChameleon ME Nand Flash",
  79. .offset = 0,
  80. .size = 32 * 1024 * 1024
  81. }
  82. };
  83. static struct mtd_partition partition_info_evb[] = {
  84. { .name = "PPChameleonEVB Nand Flash",
  85. .offset = 0,
  86. .size = 32 * 1024 * 1024
  87. }
  88. };
  89. #define NUM_PARTITIONS 1
  90. extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id);
  91. /*
  92. * hardware specific access to control-lines
  93. */
  94. static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd,
  95. unsigned int ctrl)
  96. {
  97. struct nand_chip *chip = mtd->priv;
  98. if (ctrl & NAND_CTRL_CHANGE) {
  99. #error Missing headerfiles. No way to fix this. -tglx
  100. switch (cmd) {
  101. case NAND_CTL_SETCLE:
  102. MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND0_PADDR);
  103. break;
  104. case NAND_CTL_CLRCLE:
  105. MACRO_NAND_CTL_CLRCLE((unsigned long)CFG_NAND0_PADDR);
  106. break;
  107. case NAND_CTL_SETALE:
  108. MACRO_NAND_CTL_SETALE((unsigned long)CFG_NAND0_PADDR);
  109. break;
  110. case NAND_CTL_CLRALE:
  111. MACRO_NAND_CTL_CLRALE((unsigned long)CFG_NAND0_PADDR);
  112. break;
  113. case NAND_CTL_SETNCE:
  114. MACRO_NAND_ENABLE_CE((unsigned long)CFG_NAND0_PADDR);
  115. break;
  116. case NAND_CTL_CLRNCE:
  117. MACRO_NAND_DISABLE_CE((unsigned long)CFG_NAND0_PADDR);
  118. break;
  119. }
  120. }
  121. if (cmd != NAND_CMD_NONE)
  122. writeb(cmd, chip->IO_ADDR_W);
  123. }
  124. static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd,
  125. unsigned int ctrl)
  126. {
  127. struct nand_chip *chip = mtd->priv;
  128. if (ctrl & NAND_CTRL_CHANGE) {
  129. #error Missing headerfiles. No way to fix this. -tglx
  130. switch (cmd) {
  131. case NAND_CTL_SETCLE:
  132. MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND1_PADDR);
  133. break;
  134. case NAND_CTL_CLRCLE:
  135. MACRO_NAND_CTL_CLRCLE((unsigned long)CFG_NAND1_PADDR);
  136. break;
  137. case NAND_CTL_SETALE:
  138. MACRO_NAND_CTL_SETALE((unsigned long)CFG_NAND1_PADDR);
  139. break;
  140. case NAND_CTL_CLRALE:
  141. MACRO_NAND_CTL_CLRALE((unsigned long)CFG_NAND1_PADDR);
  142. break;
  143. case NAND_CTL_SETNCE:
  144. MACRO_NAND_ENABLE_CE((unsigned long)CFG_NAND1_PADDR);
  145. break;
  146. case NAND_CTL_CLRNCE:
  147. MACRO_NAND_DISABLE_CE((unsigned long)CFG_NAND1_PADDR);
  148. break;
  149. }
  150. }
  151. if (cmd != NAND_CMD_NONE)
  152. writeb(cmd, chip->IO_ADDR_W);
  153. }
  154. #ifdef USE_READY_BUSY_PIN
  155. /*
  156. * read device ready pin
  157. */
  158. static int ppchameleon_device_ready(struct mtd_info *minfo)
  159. {
  160. if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_RB_GPIO_PIN)
  161. return 1;
  162. return 0;
  163. }
  164. static int ppchameleonevb_device_ready(struct mtd_info *minfo)
  165. {
  166. if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_EVB_RB_GPIO_PIN)
  167. return 1;
  168. return 0;
  169. }
  170. #endif
  171. const char *part_probes[] = { "cmdlinepart", NULL };
  172. const char *part_probes_evb[] = { "cmdlinepart", NULL };
  173. /*
  174. * Main initialization routine
  175. */
  176. static int __init ppchameleonevb_init(void)
  177. {
  178. struct nand_chip *this;
  179. const char *part_type = 0;
  180. int mtd_parts_nb = 0;
  181. struct mtd_partition *mtd_parts = 0;
  182. void __iomem *ppchameleon_fio_base;
  183. void __iomem *ppchameleonevb_fio_base;
  184. /*********************************
  185. * Processor module NAND (if any) *
  186. *********************************/
  187. /* Allocate memory for MTD device structure and private data */
  188. ppchameleon_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  189. if (!ppchameleon_mtd) {
  190. printk("Unable to allocate PPChameleon NAND MTD device structure.\n");
  191. return -ENOMEM;
  192. }
  193. /* map physical address */
  194. ppchameleon_fio_base = ioremap(ppchameleon_fio_pbase, SZ_4M);
  195. if (!ppchameleon_fio_base) {
  196. printk("ioremap PPChameleon NAND flash failed\n");
  197. kfree(ppchameleon_mtd);
  198. return -EIO;
  199. }
  200. /* Get pointer to private data */
  201. this = (struct nand_chip *)(&ppchameleon_mtd[1]);
  202. /* Initialize structures */
  203. memset(ppchameleon_mtd, 0, sizeof(struct mtd_info));
  204. memset(this, 0, sizeof(struct nand_chip));
  205. /* Link the private data with the MTD structure */
  206. ppchameleon_mtd->priv = this;
  207. ppchameleon_mtd->owner = THIS_MODULE;
  208. /* Initialize GPIOs */
  209. /* Pin mapping for NAND chip */
  210. /*
  211. CE GPIO_01
  212. CLE GPIO_02
  213. ALE GPIO_03
  214. R/B GPIO_04
  215. */
  216. /* output select */
  217. out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xC0FFFFFF);
  218. /* three-state select */
  219. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xC0FFFFFF);
  220. /* enable output driver */
  221. out_be32((volatile unsigned *)GPIO0_TCR,
  222. in_be32((volatile unsigned *)GPIO0_TCR) | NAND_nCE_GPIO_PIN | NAND_CLE_GPIO_PIN | NAND_ALE_GPIO_PIN);
  223. #ifdef USE_READY_BUSY_PIN
  224. /* three-state select */
  225. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFF3FFFFF);
  226. /* high-impedecence */
  227. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_RB_GPIO_PIN));
  228. /* input select */
  229. out_be32((volatile unsigned *)GPIO0_ISR1H,
  230. (in_be32((volatile unsigned *)GPIO0_ISR1H) & 0xFF3FFFFF) | 0x00400000);
  231. #endif
  232. /* insert callbacks */
  233. this->IO_ADDR_R = ppchameleon_fio_base;
  234. this->IO_ADDR_W = ppchameleon_fio_base;
  235. this->cmd_ctrl = ppchameleon_hwcontrol;
  236. #ifdef USE_READY_BUSY_PIN
  237. this->dev_ready = ppchameleon_device_ready;
  238. #endif
  239. this->chip_delay = NAND_BIG_DELAY_US;
  240. /* ECC mode */
  241. this->ecc.mode = NAND_ECC_SOFT;
  242. /* Scan to find existence of the device (it could not be mounted) */
  243. if (nand_scan(ppchameleon_mtd, 1)) {
  244. iounmap((void *)ppchameleon_fio_base);
  245. ppchameleon_fio_base = NULL;
  246. kfree(ppchameleon_mtd);
  247. goto nand_evb_init;
  248. }
  249. #ifndef USE_READY_BUSY_PIN
  250. /* Adjust delay if necessary */
  251. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  252. this->chip_delay = NAND_SMALL_DELAY_US;
  253. #endif
  254. ppchameleon_mtd->name = "ppchameleon-nand";
  255. mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0);
  256. if (mtd_parts_nb > 0)
  257. part_type = "command line";
  258. else
  259. mtd_parts_nb = 0;
  260. if (mtd_parts_nb == 0) {
  261. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  262. mtd_parts = partition_info_me;
  263. else
  264. mtd_parts = partition_info_hi;
  265. mtd_parts_nb = NUM_PARTITIONS;
  266. part_type = "static";
  267. }
  268. /* Register the partitions */
  269. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  270. mtd_device_register(ppchameleon_mtd, mtd_parts, mtd_parts_nb);
  271. nand_evb_init:
  272. /****************************
  273. * EVB NAND (always present) *
  274. ****************************/
  275. /* Allocate memory for MTD device structure and private data */
  276. ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  277. if (!ppchameleonevb_mtd) {
  278. printk("Unable to allocate PPChameleonEVB NAND MTD device structure.\n");
  279. if (ppchameleon_fio_base)
  280. iounmap(ppchameleon_fio_base);
  281. return -ENOMEM;
  282. }
  283. /* map physical address */
  284. ppchameleonevb_fio_base = ioremap(ppchameleonevb_fio_pbase, SZ_4M);
  285. if (!ppchameleonevb_fio_base) {
  286. printk("ioremap PPChameleonEVB NAND flash failed\n");
  287. kfree(ppchameleonevb_mtd);
  288. if (ppchameleon_fio_base)
  289. iounmap(ppchameleon_fio_base);
  290. return -EIO;
  291. }
  292. /* Get pointer to private data */
  293. this = (struct nand_chip *)(&ppchameleonevb_mtd[1]);
  294. /* Initialize structures */
  295. memset(ppchameleonevb_mtd, 0, sizeof(struct mtd_info));
  296. memset(this, 0, sizeof(struct nand_chip));
  297. /* Link the private data with the MTD structure */
  298. ppchameleonevb_mtd->priv = this;
  299. /* Initialize GPIOs */
  300. /* Pin mapping for NAND chip */
  301. /*
  302. CE GPIO_14
  303. CLE GPIO_15
  304. ALE GPIO_16
  305. R/B GPIO_31
  306. */
  307. /* output select */
  308. out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xFFFFFFF0);
  309. out_be32((volatile unsigned *)GPIO0_OSRL, in_be32((volatile unsigned *)GPIO0_OSRL) & 0x3FFFFFFF);
  310. /* three-state select */
  311. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFFFFFFF0);
  312. out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0x3FFFFFFF);
  313. /* enable output driver */
  314. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN |
  315. NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN);
  316. #ifdef USE_READY_BUSY_PIN
  317. /* three-state select */
  318. out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0xFFFFFFFC);
  319. /* high-impedecence */
  320. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_EVB_RB_GPIO_PIN));
  321. /* input select */
  322. out_be32((volatile unsigned *)GPIO0_ISR1L,
  323. (in_be32((volatile unsigned *)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001);
  324. #endif
  325. /* insert callbacks */
  326. this->IO_ADDR_R = ppchameleonevb_fio_base;
  327. this->IO_ADDR_W = ppchameleonevb_fio_base;
  328. this->cmd_ctrl = ppchameleonevb_hwcontrol;
  329. #ifdef USE_READY_BUSY_PIN
  330. this->dev_ready = ppchameleonevb_device_ready;
  331. #endif
  332. this->chip_delay = NAND_SMALL_DELAY_US;
  333. /* ECC mode */
  334. this->ecc.mode = NAND_ECC_SOFT;
  335. /* Scan to find existence of the device */
  336. if (nand_scan(ppchameleonevb_mtd, 1)) {
  337. iounmap((void *)ppchameleonevb_fio_base);
  338. kfree(ppchameleonevb_mtd);
  339. if (ppchameleon_fio_base)
  340. iounmap(ppchameleon_fio_base);
  341. return -ENXIO;
  342. }
  343. ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
  344. mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
  345. if (mtd_parts_nb > 0)
  346. part_type = "command line";
  347. else
  348. mtd_parts_nb = 0;
  349. if (mtd_parts_nb == 0) {
  350. mtd_parts = partition_info_evb;
  351. mtd_parts_nb = NUM_PARTITIONS;
  352. part_type = "static";
  353. }
  354. /* Register the partitions */
  355. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  356. mtd_device_register(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb);
  357. /* Return happy */
  358. return 0;
  359. }
  360. module_init(ppchameleonevb_init);
  361. /*
  362. * Clean up routine
  363. */
  364. static void __exit ppchameleonevb_cleanup(void)
  365. {
  366. struct nand_chip *this;
  367. /* Release resources, unregister device(s) */
  368. nand_release(ppchameleon_mtd);
  369. nand_release(ppchameleonevb_mtd);
  370. /* Release iomaps */
  371. this = (struct nand_chip *) &ppchameleon_mtd[1];
  372. iounmap((void *) this->IO_ADDR_R);
  373. this = (struct nand_chip *) &ppchameleonevb_mtd[1];
  374. iounmap((void *) this->IO_ADDR_R);
  375. /* Free the MTD device structure */
  376. kfree (ppchameleon_mtd);
  377. kfree (ppchameleonevb_mtd);
  378. }
  379. module_exit(ppchameleonevb_cleanup);
  380. MODULE_LICENSE("GPL");
  381. MODULE_AUTHOR("DAVE Srl <support-ppchameleon@dave-tech.it>");
  382. MODULE_DESCRIPTION("MTD map driver for DAVE Srl PPChameleonEVB board");