ppchameleonevb.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. /* 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,
  213. in_be32((volatile unsigned *)GPIO0_TCR) | NAND_nCE_GPIO_PIN | NAND_CLE_GPIO_PIN | NAND_ALE_GPIO_PIN);
  214. #ifdef USE_READY_BUSY_PIN
  215. /* three-state select */
  216. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFF3FFFFF);
  217. /* high-impedecence */
  218. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_RB_GPIO_PIN));
  219. /* input select */
  220. out_be32((volatile unsigned *)GPIO0_ISR1H,
  221. (in_be32((volatile unsigned *)GPIO0_ISR1H) & 0xFF3FFFFF) | 0x00400000);
  222. #endif
  223. /* insert callbacks */
  224. this->IO_ADDR_R = ppchameleon_fio_base;
  225. this->IO_ADDR_W = ppchameleon_fio_base;
  226. this->hwcontrol = ppchameleon_hwcontrol;
  227. #ifdef USE_READY_BUSY_PIN
  228. this->dev_ready = ppchameleon_device_ready;
  229. #endif
  230. this->chip_delay = NAND_BIG_DELAY_US;
  231. /* ECC mode */
  232. this->eccmode = NAND_ECC_SOFT;
  233. /* Scan to find existence of the device (it could not be mounted) */
  234. if (nand_scan(ppchameleon_mtd, 1)) {
  235. iounmap((void *)ppchameleon_fio_base);
  236. kfree(ppchameleon_mtd);
  237. goto nand_evb_init;
  238. }
  239. #ifndef USE_READY_BUSY_PIN
  240. /* Adjust delay if necessary */
  241. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  242. this->chip_delay = NAND_SMALL_DELAY_US;
  243. #endif
  244. #ifdef CONFIG_MTD_PARTITIONS
  245. ppchameleon_mtd->name = "ppchameleon-nand";
  246. mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0);
  247. if (mtd_parts_nb > 0)
  248. part_type = "command line";
  249. else
  250. mtd_parts_nb = 0;
  251. #endif
  252. if (mtd_parts_nb == 0) {
  253. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  254. mtd_parts = partition_info_me;
  255. else
  256. mtd_parts = partition_info_hi;
  257. mtd_parts_nb = NUM_PARTITIONS;
  258. part_type = "static";
  259. }
  260. /* Register the partitions */
  261. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  262. add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb);
  263. nand_evb_init:
  264. /****************************
  265. * EVB NAND (always present) *
  266. ****************************/
  267. /* Allocate memory for MTD device structure and private data */
  268. ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + 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(ppchameleonevb_mtd, 0, sizeof(struct mtd_info));
  284. memset(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,
  311. (in_be32((volatile unsigned *)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001);
  312. #endif
  313. /* insert callbacks */
  314. this->IO_ADDR_R = ppchameleonevb_fio_base;
  315. this->IO_ADDR_W = ppchameleonevb_fio_base;
  316. this->hwcontrol = ppchameleonevb_hwcontrol;
  317. #ifdef USE_READY_BUSY_PIN
  318. this->dev_ready = ppchameleonevb_device_ready;
  319. #endif
  320. this->chip_delay = NAND_SMALL_DELAY_US;
  321. /* ECC mode */
  322. this->eccmode = NAND_ECC_SOFT;
  323. /* Scan to find existence of the device */
  324. if (nand_scan(ppchameleonevb_mtd, 1)) {
  325. iounmap((void *)ppchameleonevb_fio_base);
  326. kfree(ppchameleonevb_mtd);
  327. return -ENXIO;
  328. }
  329. #ifdef CONFIG_MTD_PARTITIONS
  330. ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
  331. mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
  332. if (mtd_parts_nb > 0)
  333. part_type = "command line";
  334. else
  335. mtd_parts_nb = 0;
  336. #endif
  337. if (mtd_parts_nb == 0) {
  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");