ppchameleonevb.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. #ifdef CONFIG_MTD_PARTITIONS
  69. /*
  70. * Define static partitions for flash devices
  71. */
  72. static struct mtd_partition partition_info_hi[] = {
  73. { .name = "PPChameleon HI Nand Flash",
  74. .offset = 0,
  75. .size = 128 * 1024 * 1024
  76. }
  77. };
  78. static struct mtd_partition partition_info_me[] = {
  79. { .name = "PPChameleon ME Nand Flash",
  80. .offset = 0,
  81. .size = 32 * 1024 * 1024
  82. }
  83. };
  84. static struct mtd_partition partition_info_evb[] = {
  85. { .name = "PPChameleonEVB Nand Flash",
  86. .offset = 0,
  87. .size = 32 * 1024 * 1024
  88. }
  89. };
  90. #define NUM_PARTITIONS 1
  91. extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id);
  92. #endif
  93. /*
  94. * hardware specific access to control-lines
  95. */
  96. static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd,
  97. unsigned int ctrl)
  98. {
  99. struct nand_chip *chip = mtd->priv;
  100. if (ctrl & NAND_CTRL_CHANGE) {
  101. #error Missing headerfiles. No way to fix this. -tglx
  102. switch (cmd) {
  103. case NAND_CTL_SETCLE:
  104. MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND0_PADDR);
  105. break;
  106. case NAND_CTL_CLRCLE:
  107. MACRO_NAND_CTL_CLRCLE((unsigned long)CFG_NAND0_PADDR);
  108. break;
  109. case NAND_CTL_SETALE:
  110. MACRO_NAND_CTL_SETALE((unsigned long)CFG_NAND0_PADDR);
  111. break;
  112. case NAND_CTL_CLRALE:
  113. MACRO_NAND_CTL_CLRALE((unsigned long)CFG_NAND0_PADDR);
  114. break;
  115. case NAND_CTL_SETNCE:
  116. MACRO_NAND_ENABLE_CE((unsigned long)CFG_NAND0_PADDR);
  117. break;
  118. case NAND_CTL_CLRNCE:
  119. MACRO_NAND_DISABLE_CE((unsigned long)CFG_NAND0_PADDR);
  120. break;
  121. }
  122. }
  123. if (cmd != NAND_CMD_NONE)
  124. writeb(cmd, chip->IO_ADDR_W);
  125. }
  126. static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd,
  127. unsigned int ctrl)
  128. {
  129. struct nand_chip *chip = mtd->priv;
  130. if (ctrl & NAND_CTRL_CHANGE) {
  131. #error Missing headerfiles. No way to fix this. -tglx
  132. switch (cmd) {
  133. case NAND_CTL_SETCLE:
  134. MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND1_PADDR);
  135. break;
  136. case NAND_CTL_CLRCLE:
  137. MACRO_NAND_CTL_CLRCLE((unsigned long)CFG_NAND1_PADDR);
  138. break;
  139. case NAND_CTL_SETALE:
  140. MACRO_NAND_CTL_SETALE((unsigned long)CFG_NAND1_PADDR);
  141. break;
  142. case NAND_CTL_CLRALE:
  143. MACRO_NAND_CTL_CLRALE((unsigned long)CFG_NAND1_PADDR);
  144. break;
  145. case NAND_CTL_SETNCE:
  146. MACRO_NAND_ENABLE_CE((unsigned long)CFG_NAND1_PADDR);
  147. break;
  148. case NAND_CTL_CLRNCE:
  149. MACRO_NAND_DISABLE_CE((unsigned long)CFG_NAND1_PADDR);
  150. break;
  151. }
  152. }
  153. if (cmd != NAND_CMD_NONE)
  154. writeb(cmd, chip->IO_ADDR_W);
  155. }
  156. #ifdef USE_READY_BUSY_PIN
  157. /*
  158. * read device ready pin
  159. */
  160. static int ppchameleon_device_ready(struct mtd_info *minfo)
  161. {
  162. if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_RB_GPIO_PIN)
  163. return 1;
  164. return 0;
  165. }
  166. static int ppchameleonevb_device_ready(struct mtd_info *minfo)
  167. {
  168. if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_EVB_RB_GPIO_PIN)
  169. return 1;
  170. return 0;
  171. }
  172. #endif
  173. #ifdef CONFIG_MTD_PARTITIONS
  174. const char *part_probes[] = { "cmdlinepart", NULL };
  175. const char *part_probes_evb[] = { "cmdlinepart", NULL };
  176. #endif
  177. /*
  178. * Main initialization routine
  179. */
  180. static int __init ppchameleonevb_init(void)
  181. {
  182. struct nand_chip *this;
  183. const char *part_type = 0;
  184. int mtd_parts_nb = 0;
  185. struct mtd_partition *mtd_parts = 0;
  186. void __iomem *ppchameleon_fio_base;
  187. void __iomem *ppchameleonevb_fio_base;
  188. /*********************************
  189. * Processor module NAND (if any) *
  190. *********************************/
  191. /* Allocate memory for MTD device structure and private data */
  192. ppchameleon_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  193. if (!ppchameleon_mtd) {
  194. printk("Unable to allocate PPChameleon NAND MTD device structure.\n");
  195. return -ENOMEM;
  196. }
  197. /* map physical address */
  198. ppchameleon_fio_base = ioremap(ppchameleon_fio_pbase, SZ_4M);
  199. if (!ppchameleon_fio_base) {
  200. printk("ioremap PPChameleon NAND flash failed\n");
  201. kfree(ppchameleon_mtd);
  202. return -EIO;
  203. }
  204. /* Get pointer to private data */
  205. this = (struct nand_chip *)(&ppchameleon_mtd[1]);
  206. /* Initialize structures */
  207. memset(ppchameleon_mtd, 0, sizeof(struct mtd_info));
  208. memset(this, 0, sizeof(struct nand_chip));
  209. /* Link the private data with the MTD structure */
  210. ppchameleon_mtd->priv = this;
  211. ppchameleon_mtd->owner = THIS_MODULE;
  212. /* Initialize GPIOs */
  213. /* Pin mapping for NAND chip */
  214. /*
  215. CE GPIO_01
  216. CLE GPIO_02
  217. ALE GPIO_03
  218. R/B GPIO_04
  219. */
  220. /* output select */
  221. out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xC0FFFFFF);
  222. /* three-state select */
  223. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xC0FFFFFF);
  224. /* enable output driver */
  225. out_be32((volatile unsigned *)GPIO0_TCR,
  226. in_be32((volatile unsigned *)GPIO0_TCR) | NAND_nCE_GPIO_PIN | NAND_CLE_GPIO_PIN | NAND_ALE_GPIO_PIN);
  227. #ifdef USE_READY_BUSY_PIN
  228. /* three-state select */
  229. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFF3FFFFF);
  230. /* high-impedecence */
  231. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_RB_GPIO_PIN));
  232. /* input select */
  233. out_be32((volatile unsigned *)GPIO0_ISR1H,
  234. (in_be32((volatile unsigned *)GPIO0_ISR1H) & 0xFF3FFFFF) | 0x00400000);
  235. #endif
  236. /* insert callbacks */
  237. this->IO_ADDR_R = ppchameleon_fio_base;
  238. this->IO_ADDR_W = ppchameleon_fio_base;
  239. this->cmd_ctrl = ppchameleon_hwcontrol;
  240. #ifdef USE_READY_BUSY_PIN
  241. this->dev_ready = ppchameleon_device_ready;
  242. #endif
  243. this->chip_delay = NAND_BIG_DELAY_US;
  244. /* ECC mode */
  245. this->ecc.mode = NAND_ECC_SOFT;
  246. /* Scan to find existence of the device (it could not be mounted) */
  247. if (nand_scan(ppchameleon_mtd, 1)) {
  248. iounmap((void *)ppchameleon_fio_base);
  249. ppchameleon_fio_base = NULL;
  250. kfree(ppchameleon_mtd);
  251. goto nand_evb_init;
  252. }
  253. #ifndef USE_READY_BUSY_PIN
  254. /* Adjust delay if necessary */
  255. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  256. this->chip_delay = NAND_SMALL_DELAY_US;
  257. #endif
  258. #ifdef CONFIG_MTD_PARTITIONS
  259. ppchameleon_mtd->name = "ppchameleon-nand";
  260. mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0);
  261. if (mtd_parts_nb > 0)
  262. part_type = "command line";
  263. else
  264. mtd_parts_nb = 0;
  265. #endif
  266. if (mtd_parts_nb == 0) {
  267. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  268. mtd_parts = partition_info_me;
  269. else
  270. mtd_parts = partition_info_hi;
  271. mtd_parts_nb = NUM_PARTITIONS;
  272. part_type = "static";
  273. }
  274. /* Register the partitions */
  275. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  276. add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb);
  277. nand_evb_init:
  278. /****************************
  279. * EVB NAND (always present) *
  280. ****************************/
  281. /* Allocate memory for MTD device structure and private data */
  282. ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  283. if (!ppchameleonevb_mtd) {
  284. printk("Unable to allocate PPChameleonEVB NAND MTD device structure.\n");
  285. if (ppchameleon_fio_base)
  286. iounmap(ppchameleon_fio_base);
  287. return -ENOMEM;
  288. }
  289. /* map physical address */
  290. ppchameleonevb_fio_base = ioremap(ppchameleonevb_fio_pbase, SZ_4M);
  291. if (!ppchameleonevb_fio_base) {
  292. printk("ioremap PPChameleonEVB NAND flash failed\n");
  293. kfree(ppchameleonevb_mtd);
  294. if (ppchameleon_fio_base)
  295. iounmap(ppchameleon_fio_base);
  296. return -EIO;
  297. }
  298. /* Get pointer to private data */
  299. this = (struct nand_chip *)(&ppchameleonevb_mtd[1]);
  300. /* Initialize structures */
  301. memset(ppchameleonevb_mtd, 0, sizeof(struct mtd_info));
  302. memset(this, 0, sizeof(struct nand_chip));
  303. /* Link the private data with the MTD structure */
  304. ppchameleonevb_mtd->priv = this;
  305. /* Initialize GPIOs */
  306. /* Pin mapping for NAND chip */
  307. /*
  308. CE GPIO_14
  309. CLE GPIO_15
  310. ALE GPIO_16
  311. R/B GPIO_31
  312. */
  313. /* output select */
  314. out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xFFFFFFF0);
  315. out_be32((volatile unsigned *)GPIO0_OSRL, in_be32((volatile unsigned *)GPIO0_OSRL) & 0x3FFFFFFF);
  316. /* three-state select */
  317. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFFFFFFF0);
  318. out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0x3FFFFFFF);
  319. /* enable output driver */
  320. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN |
  321. NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN);
  322. #ifdef USE_READY_BUSY_PIN
  323. /* three-state select */
  324. out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0xFFFFFFFC);
  325. /* high-impedecence */
  326. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_EVB_RB_GPIO_PIN));
  327. /* input select */
  328. out_be32((volatile unsigned *)GPIO0_ISR1L,
  329. (in_be32((volatile unsigned *)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001);
  330. #endif
  331. /* insert callbacks */
  332. this->IO_ADDR_R = ppchameleonevb_fio_base;
  333. this->IO_ADDR_W = ppchameleonevb_fio_base;
  334. this->cmd_ctrl = ppchameleonevb_hwcontrol;
  335. #ifdef USE_READY_BUSY_PIN
  336. this->dev_ready = ppchameleonevb_device_ready;
  337. #endif
  338. this->chip_delay = NAND_SMALL_DELAY_US;
  339. /* ECC mode */
  340. this->ecc.mode = NAND_ECC_SOFT;
  341. /* Scan to find existence of the device */
  342. if (nand_scan(ppchameleonevb_mtd, 1)) {
  343. iounmap((void *)ppchameleonevb_fio_base);
  344. kfree(ppchameleonevb_mtd);
  345. if (ppchameleon_fio_base)
  346. iounmap(ppchameleon_fio_base);
  347. return -ENXIO;
  348. }
  349. #ifdef CONFIG_MTD_PARTITIONS
  350. ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
  351. mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
  352. if (mtd_parts_nb > 0)
  353. part_type = "command line";
  354. else
  355. mtd_parts_nb = 0;
  356. #endif
  357. if (mtd_parts_nb == 0) {
  358. mtd_parts = partition_info_evb;
  359. mtd_parts_nb = NUM_PARTITIONS;
  360. part_type = "static";
  361. }
  362. /* Register the partitions */
  363. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  364. add_mtd_partitions(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb);
  365. /* Return happy */
  366. return 0;
  367. }
  368. module_init(ppchameleonevb_init);
  369. /*
  370. * Clean up routine
  371. */
  372. static void __exit ppchameleonevb_cleanup(void)
  373. {
  374. struct nand_chip *this;
  375. /* Release resources, unregister device(s) */
  376. nand_release(ppchameleon_mtd);
  377. nand_release(ppchameleonevb_mtd);
  378. /* Release iomaps */
  379. this = (struct nand_chip *) &ppchameleon_mtd[1];
  380. iounmap((void *) this->IO_ADDR_R);
  381. this = (struct nand_chip *) &ppchameleonevb_mtd[1];
  382. iounmap((void *) this->IO_ADDR_R);
  383. /* Free the MTD device structure */
  384. kfree (ppchameleon_mtd);
  385. kfree (ppchameleonevb_mtd);
  386. }
  387. module_exit(ppchameleonevb_cleanup);
  388. MODULE_LICENSE("GPL");
  389. MODULE_AUTHOR("DAVE Srl <support-ppchameleon@dave-tech.it>");
  390. MODULE_DESCRIPTION("MTD map driver for DAVE Srl PPChameleonEVB board");