board-flash.c 6.1 KB

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