ppchameleonevb.c 12 KB

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