ppchameleonevb.c 12 KB

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