board-flash.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * board-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/cpu.h>
  19. #include <plat/gpmc.h>
  20. #include <plat/nand.h>
  21. #include <plat/onenand.h>
  22. #include <plat/tc.h>
  23. #include "common.h"
  24. #include "board-flash.h"
  25. #define REG_FPGA_REV 0x10
  26. #define REG_FPGA_DIP_SWITCH_INPUT2 0x60
  27. #define MAX_SUPPORTED_GPMC_CONFIG 3
  28. #define DEBUG_BASE 0x08000000 /* debug board */
  29. /* various memory sizes */
  30. #define FLASH_SIZE_SDPV1 SZ_64M /* NOR flash (64 Meg aligned) */
  31. #define FLASH_SIZE_SDPV2 SZ_128M /* NOR flash (256 Meg aligned) */
  32. static struct physmap_flash_data board_nor_data = {
  33. .width = 2,
  34. };
  35. static struct resource board_nor_resource = {
  36. .flags = IORESOURCE_MEM,
  37. };
  38. static struct platform_device board_nor_device = {
  39. .name = "physmap-flash",
  40. .id = 0,
  41. .dev = {
  42. .platform_data = &board_nor_data,
  43. },
  44. .num_resources = 1,
  45. .resource = &board_nor_resource,
  46. };
  47. static void
  48. __init board_nor_init(struct mtd_partition *nor_parts, u8 nr_parts, u8 cs)
  49. {
  50. int err;
  51. board_nor_data.parts = nor_parts;
  52. board_nor_data.nr_parts = nr_parts;
  53. /* Configure start address and size of NOR device */
  54. if (omap_rev() >= OMAP3430_REV_ES1_0) {
  55. err = gpmc_cs_request(cs, FLASH_SIZE_SDPV2 - 1,
  56. (unsigned long *)&board_nor_resource.start);
  57. board_nor_resource.end = board_nor_resource.start
  58. + FLASH_SIZE_SDPV2 - 1;
  59. } else {
  60. err = gpmc_cs_request(cs, FLASH_SIZE_SDPV1 - 1,
  61. (unsigned long *)&board_nor_resource.start);
  62. board_nor_resource.end = board_nor_resource.start
  63. + FLASH_SIZE_SDPV1 - 1;
  64. }
  65. if (err < 0) {
  66. pr_err("NOR: Can't request GPMC CS\n");
  67. return;
  68. }
  69. if (platform_device_register(&board_nor_device) < 0)
  70. pr_err("Unable to register NOR device\n");
  71. }
  72. #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
  73. defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
  74. static struct omap_onenand_platform_data board_onenand_data = {
  75. .dma_channel = -1, /* disable DMA in OMAP OneNAND driver */
  76. };
  77. void
  78. __init board_onenand_init(struct mtd_partition *onenand_parts,
  79. u8 nr_parts, u8 cs)
  80. {
  81. board_onenand_data.cs = cs;
  82. board_onenand_data.parts = onenand_parts;
  83. board_onenand_data.nr_parts = nr_parts;
  84. gpmc_onenand_init(&board_onenand_data);
  85. }
  86. #endif /* CONFIG_MTD_ONENAND_OMAP2 || CONFIG_MTD_ONENAND_OMAP2_MODULE */
  87. #if defined(CONFIG_MTD_NAND_OMAP2) || \
  88. defined(CONFIG_MTD_NAND_OMAP2_MODULE)
  89. /* Note that all values in this struct are in nanoseconds */
  90. static struct gpmc_timings nand_timings = {
  91. .sync_clk = 0,
  92. .cs_on = 0,
  93. .cs_rd_off = 36,
  94. .cs_wr_off = 36,
  95. .adv_on = 6,
  96. .adv_rd_off = 24,
  97. .adv_wr_off = 36,
  98. .we_off = 30,
  99. .oe_off = 48,
  100. .access = 54,
  101. .rd_cycle = 72,
  102. .wr_cycle = 72,
  103. .wr_access = 30,
  104. .wr_data_mux_bus = 0,
  105. };
  106. static struct omap_nand_platform_data board_nand_data = {
  107. .gpmc_t = &nand_timings,
  108. };
  109. void
  110. __init board_nand_init(struct mtd_partition *nand_parts,
  111. u8 nr_parts, u8 cs, int nand_type)
  112. {
  113. board_nand_data.cs = cs;
  114. board_nand_data.parts = nand_parts;
  115. board_nand_data.nr_parts = nr_parts;
  116. board_nand_data.devsize = nand_type;
  117. board_nand_data.ecc_opt = OMAP_ECC_HAMMING_CODE_DEFAULT;
  118. gpmc_nand_init(&board_nand_data);
  119. }
  120. #endif /* CONFIG_MTD_NAND_OMAP2 || CONFIG_MTD_NAND_OMAP2_MODULE */
  121. /**
  122. * get_gpmc0_type - Reads the FPGA DIP_SWITCH_INPUT_REGISTER2 to get
  123. * the various cs values.
  124. */
  125. static u8 get_gpmc0_type(void)
  126. {
  127. u8 cs = 0;
  128. void __iomem *fpga_map_addr;
  129. fpga_map_addr = ioremap(DEBUG_BASE, 4096);
  130. if (!fpga_map_addr)
  131. return -ENOMEM;
  132. if (!(__raw_readw(fpga_map_addr + REG_FPGA_REV)))
  133. /* we dont have an DEBUG FPGA??? */
  134. /* Depend on #defines!! default to strata boot return param */
  135. goto unmap;
  136. /* S8-DIP-OFF = 1, S8-DIP-ON = 0 */
  137. cs = __raw_readw(fpga_map_addr + REG_FPGA_DIP_SWITCH_INPUT2) & 0xf;
  138. /* ES2.0 SDP's onwards 4 dip switches are provided for CS */
  139. if (omap_rev() >= OMAP3430_REV_ES1_0)
  140. /* change (S8-1:4=DS-2:0) to (S8-4:1=DS-2:0) */
  141. cs = ((cs & 8) >> 3) | ((cs & 4) >> 1) |
  142. ((cs & 2) << 1) | ((cs & 1) << 3);
  143. else
  144. /* change (S8-1:3=DS-2:0) to (S8-3:1=DS-2:0) */
  145. cs = ((cs & 4) >> 2) | (cs & 2) | ((cs & 1) << 2);
  146. unmap:
  147. iounmap(fpga_map_addr);
  148. return cs;
  149. }
  150. /**
  151. * board_flash_init - Identify devices connected to GPMC and register.
  152. *
  153. * @return - void.
  154. */
  155. void __init board_flash_init(struct flash_partitions partition_info[],
  156. char chip_sel_board[][GPMC_CS_NUM], int nand_type)
  157. {
  158. u8 cs = 0;
  159. u8 norcs = GPMC_CS_NUM + 1;
  160. u8 nandcs = GPMC_CS_NUM + 1;
  161. u8 onenandcs = GPMC_CS_NUM + 1;
  162. u8 idx;
  163. unsigned char *config_sel = NULL;
  164. /* REVISIT: Is this return correct idx for 2430 SDP?
  165. * for which cs configuration matches for 2430 SDP?
  166. */
  167. idx = get_gpmc0_type();
  168. if (idx >= MAX_SUPPORTED_GPMC_CONFIG) {
  169. pr_err("%s: Invalid chip select: %d\n", __func__, cs);
  170. return;
  171. }
  172. config_sel = (unsigned char *)(chip_sel_board[idx]);
  173. while (cs < GPMC_CS_NUM) {
  174. switch (config_sel[cs]) {
  175. case PDC_NOR:
  176. if (norcs > GPMC_CS_NUM)
  177. norcs = cs;
  178. break;
  179. case PDC_NAND:
  180. if (nandcs > GPMC_CS_NUM)
  181. nandcs = cs;
  182. break;
  183. case PDC_ONENAND:
  184. if (onenandcs > GPMC_CS_NUM)
  185. onenandcs = cs;
  186. break;
  187. };
  188. cs++;
  189. }
  190. if (norcs > GPMC_CS_NUM)
  191. pr_err("NOR: Unable to find configuration in GPMC\n");
  192. else
  193. board_nor_init(partition_info[0].parts,
  194. partition_info[0].nr_parts, norcs);
  195. if (onenandcs > GPMC_CS_NUM)
  196. pr_err("OneNAND: Unable to find configuration in GPMC\n");
  197. else
  198. board_onenand_init(partition_info[1].parts,
  199. partition_info[1].nr_parts, onenandcs);
  200. if (nandcs > GPMC_CS_NUM)
  201. pr_err("NAND: Unable to find configuration in GPMC\n");
  202. else
  203. board_nand_init(partition_info[2].parts,
  204. partition_info[2].nr_parts, nandcs, nand_type);
  205. }