ppchameleonevb.c 12 KB

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