board-flash.c 5.9 KB

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