ppchameleonevb.c 13 KB

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