ppchameleonevb.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. kfree(ppchameleon_mtd);
  252. goto nand_evb_init;
  253. }
  254. #ifndef USE_READY_BUSY_PIN
  255. /* Adjust delay if necessary */
  256. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  257. this->chip_delay = NAND_SMALL_DELAY_US;
  258. #endif
  259. #ifdef CONFIG_MTD_PARTITIONS
  260. ppchameleon_mtd->name = "ppchameleon-nand";
  261. mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0);
  262. if (mtd_parts_nb > 0)
  263. part_type = "command line";
  264. else
  265. mtd_parts_nb = 0;
  266. #endif
  267. if (mtd_parts_nb == 0) {
  268. if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
  269. mtd_parts = partition_info_me;
  270. else
  271. mtd_parts = partition_info_hi;
  272. mtd_parts_nb = NUM_PARTITIONS;
  273. part_type = "static";
  274. }
  275. /* Register the partitions */
  276. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  277. add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb);
  278. nand_evb_init:
  279. /****************************
  280. * EVB NAND (always present) *
  281. ****************************/
  282. /* Allocate memory for MTD device structure and private data */
  283. ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  284. if (!ppchameleonevb_mtd) {
  285. printk("Unable to allocate PPChameleonEVB NAND MTD device structure.\n");
  286. return -ENOMEM;
  287. }
  288. /* map physical address */
  289. ppchameleonevb_fio_base = ioremap(ppchameleonevb_fio_pbase, SZ_4M);
  290. if (!ppchameleonevb_fio_base) {
  291. printk("ioremap PPChameleonEVB NAND flash failed\n");
  292. kfree(ppchameleonevb_mtd);
  293. return -EIO;
  294. }
  295. /* Get pointer to private data */
  296. this = (struct nand_chip *)(&ppchameleonevb_mtd[1]);
  297. /* Initialize structures */
  298. memset(ppchameleonevb_mtd, 0, sizeof(struct mtd_info));
  299. memset(this, 0, sizeof(struct nand_chip));
  300. /* Link the private data with the MTD structure */
  301. ppchameleonevb_mtd->priv = this;
  302. /* Initialize GPIOs */
  303. /* Pin mapping for NAND chip */
  304. /*
  305. CE GPIO_14
  306. CLE GPIO_15
  307. ALE GPIO_16
  308. R/B GPIO_31
  309. */
  310. /* output select */
  311. out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xFFFFFFF0);
  312. out_be32((volatile unsigned *)GPIO0_OSRL, in_be32((volatile unsigned *)GPIO0_OSRL) & 0x3FFFFFFF);
  313. /* three-state select */
  314. out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFFFFFFF0);
  315. out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0x3FFFFFFF);
  316. /* enable output driver */
  317. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN |
  318. NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN);
  319. #ifdef USE_READY_BUSY_PIN
  320. /* three-state select */
  321. out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0xFFFFFFFC);
  322. /* high-impedecence */
  323. out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_EVB_RB_GPIO_PIN));
  324. /* input select */
  325. out_be32((volatile unsigned *)GPIO0_ISR1L,
  326. (in_be32((volatile unsigned *)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001);
  327. #endif
  328. /* insert callbacks */
  329. this->IO_ADDR_R = ppchameleonevb_fio_base;
  330. this->IO_ADDR_W = ppchameleonevb_fio_base;
  331. this->cmd_ctrl = ppchameleonevb_hwcontrol;
  332. #ifdef USE_READY_BUSY_PIN
  333. this->dev_ready = ppchameleonevb_device_ready;
  334. #endif
  335. this->chip_delay = NAND_SMALL_DELAY_US;
  336. /* ECC mode */
  337. this->ecc.mode = NAND_ECC_SOFT;
  338. /* Scan to find existence of the device */
  339. if (nand_scan(ppchameleonevb_mtd, 1)) {
  340. iounmap((void *)ppchameleonevb_fio_base);
  341. kfree(ppchameleonevb_mtd);
  342. return -ENXIO;
  343. }
  344. #ifdef CONFIG_MTD_PARTITIONS
  345. ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
  346. mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
  347. if (mtd_parts_nb > 0)
  348. part_type = "command line";
  349. else
  350. mtd_parts_nb = 0;
  351. #endif
  352. if (mtd_parts_nb == 0) {
  353. mtd_parts = partition_info_evb;
  354. mtd_parts_nb = NUM_PARTITIONS;
  355. part_type = "static";
  356. }
  357. /* Register the partitions */
  358. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  359. add_mtd_partitions(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb);
  360. /* Return happy */
  361. return 0;
  362. }
  363. module_init(ppchameleonevb_init);
  364. /*
  365. * Clean up routine
  366. */
  367. static void __exit ppchameleonevb_cleanup(void)
  368. {
  369. struct nand_chip *this;
  370. /* Release resources, unregister device(s) */
  371. nand_release(ppchameleon_mtd);
  372. nand_release(ppchameleonevb_mtd);
  373. /* Release iomaps */
  374. this = (struct nand_chip *) &ppchameleon_mtd[1];
  375. iounmap((void *) this->IO_ADDR_R;
  376. this = (struct nand_chip *) &ppchameleonevb_mtd[1];
  377. iounmap((void *) this->IO_ADDR_R;
  378. /* Free the MTD device structure */
  379. kfree (ppchameleon_mtd);
  380. kfree (ppchameleonevb_mtd);
  381. }
  382. module_exit(ppchameleonevb_cleanup);
  383. MODULE_LICENSE("GPL");
  384. MODULE_AUTHOR("DAVE Srl <support-ppchameleon@dave-tech.it>");
  385. MODULE_DESCRIPTION("MTD map driver for DAVE Srl PPChameleonEVB board");