board-sdp-flash.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * board-sdp-flash.c
  3. * Modified from mach-omap2/board-3430sdp-flash.c
  4. *
  5. * Copyright (C) 2009 Nokia Corporation
  6. * Copyright (C) 2009 Texas Instruments
  7. *
  8. * Vimal Singh <vimalsingh@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/physmap.h>
  17. #include <linux/io.h>
  18. #include <plat/gpmc.h>
  19. #include <plat/nand.h>
  20. #include <plat/onenand.h>
  21. #include <plat/tc.h>
  22. #include <mach/board-sdp.h>
  23. #define REG_FPGA_REV 0x10
  24. #define REG_FPGA_DIP_SWITCH_INPUT2 0x60
  25. #define MAX_SUPPORTED_GPMC_CONFIG 3
  26. #define DEBUG_BASE 0x08000000 /* debug board */
  27. #define PDC_NOR 1
  28. #define PDC_NAND 2
  29. #define PDC_ONENAND 3
  30. #define DBG_MPDB 4
  31. /* various memory sizes */
  32. #define FLASH_SIZE_SDPV1 SZ_64M /* NOR flash (64 Meg aligned) */
  33. #define FLASH_SIZE_SDPV2 SZ_128M /* NOR flash (256 Meg aligned) */
  34. /*
  35. * SDP3430 V2 Board CS organization
  36. * Different from SDP3430 V1. Now 4 switches used to specify CS
  37. *
  38. * See also the Switch S8 settings in the comments.
  39. *
  40. * REVISIT: Add support for 2430 SDP
  41. */
  42. static const unsigned char chip_sel_sdp[][GPMC_CS_NUM] = {
  43. {PDC_NOR, PDC_NAND, PDC_ONENAND, DBG_MPDB, 0, 0, 0, 0}, /* S8:1111 */
  44. {PDC_ONENAND, PDC_NAND, PDC_NOR, DBG_MPDB, 0, 0, 0, 0}, /* S8:1110 */
  45. {PDC_NAND, PDC_ONENAND, PDC_NOR, DBG_MPDB, 0, 0, 0, 0}, /* S8:1101 */
  46. };
  47. static struct physmap_flash_data sdp_nor_data = {
  48. .width = 2,
  49. };
  50. static struct resource sdp_nor_resource = {
  51. .flags = IORESOURCE_MEM,
  52. };
  53. static struct platform_device sdp_nor_device = {
  54. .name = "physmap-flash",
  55. .id = 0,
  56. .dev = {
  57. .platform_data = &sdp_nor_data,
  58. },
  59. .num_resources = 1,
  60. .resource = &sdp_nor_resource,
  61. };
  62. static void
  63. __init board_nor_init(struct flash_partitions sdp_nor_parts, u8 cs)
  64. {
  65. int err;
  66. sdp_nor_data.parts = sdp_nor_parts.parts;
  67. sdp_nor_data.nr_parts = sdp_nor_parts.nr_parts;
  68. /* Configure start address and size of NOR device */
  69. if (omap_rev() >= OMAP3430_REV_ES1_0) {
  70. err = gpmc_cs_request(cs, FLASH_SIZE_SDPV2 - 1,
  71. (unsigned long *)&sdp_nor_resource.start);
  72. sdp_nor_resource.end = sdp_nor_resource.start
  73. + FLASH_SIZE_SDPV2 - 1;
  74. } else {
  75. err = gpmc_cs_request(cs, FLASH_SIZE_SDPV1 - 1,
  76. (unsigned long *)&sdp_nor_resource.start);
  77. sdp_nor_resource.end = sdp_nor_resource.start
  78. + FLASH_SIZE_SDPV1 - 1;
  79. }
  80. if (err < 0) {
  81. printk(KERN_ERR "NOR: Can't request GPMC CS\n");
  82. return;
  83. }
  84. if (platform_device_register(&sdp_nor_device) < 0)
  85. printk(KERN_ERR "Unable to register NOR device\n");
  86. }
  87. #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
  88. defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
  89. static struct omap_onenand_platform_data board_onenand_data = {
  90. .dma_channel = -1, /* disable DMA in OMAP OneNAND driver */
  91. };
  92. static void
  93. __init board_onenand_init(struct flash_partitions sdp_onenand_parts, u8 cs)
  94. {
  95. board_onenand_data.cs = cs;
  96. board_onenand_data.parts = sdp_onenand_parts.parts;
  97. board_onenand_data.nr_parts = sdp_onenand_parts.nr_parts;
  98. gpmc_onenand_init(&board_onenand_data);
  99. }
  100. #else
  101. static void
  102. __init board_onenand_init(struct flash_partitions sdp_onenand_parts, u8 cs)
  103. {
  104. }
  105. #endif /* CONFIG_MTD_ONENAND_OMAP2 || CONFIG_MTD_ONENAND_OMAP2_MODULE */
  106. #if defined(CONFIG_MTD_NAND_OMAP2) || \
  107. defined(CONFIG_MTD_NAND_OMAP2_MODULE)
  108. /* Note that all values in this struct are in nanoseconds */
  109. static struct gpmc_timings nand_timings = {
  110. .sync_clk = 0,
  111. .cs_on = 0,
  112. .cs_rd_off = 36,
  113. .cs_wr_off = 36,
  114. .adv_on = 6,
  115. .adv_rd_off = 24,
  116. .adv_wr_off = 36,
  117. .we_off = 30,
  118. .oe_off = 48,
  119. .access = 54,
  120. .rd_cycle = 72,
  121. .wr_cycle = 72,
  122. .wr_access = 30,
  123. .wr_data_mux_bus = 0,
  124. };
  125. static struct omap_nand_platform_data sdp_nand_data = {
  126. .nand_setup = NULL,
  127. .gpmc_t = &nand_timings,
  128. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  129. .dev_ready = NULL,
  130. .devsize = 0, /* '0' for 8-bit, '1' for 16-bit device */
  131. };
  132. static void
  133. __init board_nand_init(struct flash_partitions sdp_nand_parts, u8 cs)
  134. {
  135. sdp_nand_data.cs = cs;
  136. sdp_nand_data.parts = sdp_nand_parts.parts;
  137. sdp_nand_data.nr_parts = sdp_nand_parts.nr_parts;
  138. sdp_nand_data.gpmc_cs_baseaddr = (void *)(OMAP34XX_GPMC_VIRT +
  139. GPMC_CS0_BASE +
  140. cs * GPMC_CS_SIZE);
  141. sdp_nand_data.gpmc_baseaddr = (void *) (OMAP34XX_GPMC_VIRT);
  142. gpmc_nand_init(&sdp_nand_data);
  143. }
  144. #else
  145. static void
  146. __init board_nand_init(struct flash_partitions sdp_nand_parts, u8 cs)
  147. {
  148. }
  149. #endif /* CONFIG_MTD_NAND_OMAP2 || CONFIG_MTD_NAND_OMAP2_MODULE */
  150. /**
  151. * get_gpmc0_type - Reads the FPGA DIP_SWITCH_INPUT_REGISTER2 to get
  152. * the various cs values.
  153. */
  154. static u8 get_gpmc0_type(void)
  155. {
  156. u8 cs = 0;
  157. void __iomem *fpga_map_addr;
  158. fpga_map_addr = ioremap(DEBUG_BASE, 4096);
  159. if (!fpga_map_addr)
  160. return -ENOMEM;
  161. if (!(__raw_readw(fpga_map_addr + REG_FPGA_REV)))
  162. /* we dont have an DEBUG FPGA??? */
  163. /* Depend on #defines!! default to strata boot return param */
  164. goto unmap;
  165. /* S8-DIP-OFF = 1, S8-DIP-ON = 0 */
  166. cs = __raw_readw(fpga_map_addr + REG_FPGA_DIP_SWITCH_INPUT2) & 0xf;
  167. /* ES2.0 SDP's onwards 4 dip switches are provided for CS */
  168. if (omap_rev() >= OMAP3430_REV_ES1_0)
  169. /* change (S8-1:4=DS-2:0) to (S8-4:1=DS-2:0) */
  170. cs = ((cs & 8) >> 3) | ((cs & 4) >> 1) |
  171. ((cs & 2) << 1) | ((cs & 1) << 3);
  172. else
  173. /* change (S8-1:3=DS-2:0) to (S8-3:1=DS-2:0) */
  174. cs = ((cs & 4) >> 2) | (cs & 2) | ((cs & 1) << 2);
  175. unmap:
  176. iounmap(fpga_map_addr);
  177. return cs;
  178. }
  179. /**
  180. * sdp3430_flash_init - Identify devices connected to GPMC and register.
  181. *
  182. * @return - void.
  183. */
  184. void __init sdp_flash_init(struct flash_partitions sdp_partition_info[])
  185. {
  186. u8 cs = 0;
  187. u8 norcs = GPMC_CS_NUM + 1;
  188. u8 nandcs = GPMC_CS_NUM + 1;
  189. u8 onenandcs = GPMC_CS_NUM + 1;
  190. u8 idx;
  191. unsigned char *config_sel = NULL;
  192. /* REVISIT: Is this return correct idx for 2430 SDP?
  193. * for which cs configuration matches for 2430 SDP?
  194. */
  195. idx = get_gpmc0_type();
  196. if (idx >= MAX_SUPPORTED_GPMC_CONFIG) {
  197. printk(KERN_ERR "%s: Invalid chip select: %d\n", __func__, cs);
  198. return;
  199. }
  200. config_sel = (unsigned char *)(chip_sel_sdp[idx]);
  201. while (cs < GPMC_CS_NUM) {
  202. switch (config_sel[cs]) {
  203. case PDC_NOR:
  204. if (norcs > GPMC_CS_NUM)
  205. norcs = cs;
  206. break;
  207. case PDC_NAND:
  208. if (nandcs > GPMC_CS_NUM)
  209. nandcs = cs;
  210. break;
  211. case PDC_ONENAND:
  212. if (onenandcs > GPMC_CS_NUM)
  213. onenandcs = cs;
  214. break;
  215. };
  216. cs++;
  217. }
  218. if (norcs > GPMC_CS_NUM)
  219. printk(KERN_INFO "NOR: Unable to find configuration "
  220. "in GPMC\n");
  221. else
  222. board_nor_init(sdp_partition_info[0], norcs);
  223. if (onenandcs > GPMC_CS_NUM)
  224. printk(KERN_INFO "OneNAND: Unable to find configuration "
  225. "in GPMC\n");
  226. else
  227. board_onenand_init(sdp_partition_info[1], onenandcs);
  228. if (nandcs > GPMC_CS_NUM)
  229. printk(KERN_INFO "NAND: Unable to find configuration "
  230. "in GPMC\n");
  231. else
  232. board_nand_init(sdp_partition_info[2], nandcs);
  233. }