platform-flash.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright 2011, Netlogic Microsystems.
  3. * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
  4. *
  5. * This file is licensed under the terms of the GNU General Public
  6. * License version 2. This program is licensed "as is" without any
  7. * warranty of any kind, whether express or implied.
  8. */
  9. #include <linux/device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/delay.h>
  15. #include <linux/ioport.h>
  16. #include <linux/resource.h>
  17. #include <linux/spi/flash.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/physmap.h>
  20. #include <linux/mtd/platnand.h>
  21. #include <asm/netlogic/haldefs.h>
  22. #include <asm/netlogic/xlr/iomap.h>
  23. #include <asm/netlogic/xlr/flash.h>
  24. #include <asm/netlogic/xlr/bridge.h>
  25. #include <asm/netlogic/xlr/gpio.h>
  26. #include <asm/netlogic/xlr/xlr.h>
  27. /*
  28. * Default NOR partition layout
  29. */
  30. static struct mtd_partition xlr_nor_parts[] = {
  31. {
  32. .name = "User FS",
  33. .offset = 0x800000,
  34. .size = MTDPART_SIZ_FULL,
  35. }
  36. };
  37. /*
  38. * Default NAND partition layout
  39. */
  40. static struct mtd_partition xlr_nand_parts[] = {
  41. {
  42. .name = "Root Filesystem",
  43. .offset = 64 * 64 * 2048,
  44. .size = 432 * 64 * 2048,
  45. },
  46. {
  47. .name = "Home Filesystem",
  48. .offset = MTDPART_OFS_APPEND,
  49. .size = MTDPART_SIZ_FULL,
  50. },
  51. };
  52. /* Use PHYSMAP flash for NOR */
  53. struct physmap_flash_data xlr_nor_data = {
  54. .width = 2,
  55. .parts = xlr_nor_parts,
  56. .nr_parts = ARRAY_SIZE(xlr_nor_parts),
  57. };
  58. static struct resource xlr_nor_res[] = {
  59. {
  60. .flags = IORESOURCE_MEM,
  61. },
  62. };
  63. static struct platform_device xlr_nor_dev = {
  64. .name = "physmap-flash",
  65. .dev = {
  66. .platform_data = &xlr_nor_data,
  67. },
  68. .num_resources = ARRAY_SIZE(xlr_nor_res),
  69. .resource = xlr_nor_res,
  70. };
  71. /*
  72. * Use "gen_nand" driver for NAND flash
  73. *
  74. * There seems to be no way to store a private pointer containing
  75. * platform specific info in gen_nand drivier. We will use a global
  76. * struct for now, since we currently have only one NAND chip per board.
  77. */
  78. struct xlr_nand_flash_priv {
  79. int cs;
  80. uint64_t flash_mmio;
  81. };
  82. static struct xlr_nand_flash_priv nand_priv;
  83. static void xlr_nand_ctrl(struct nand_chip *chip, int cmd,
  84. unsigned int ctrl)
  85. {
  86. if (ctrl & NAND_CLE)
  87. nlm_write_reg(nand_priv.flash_mmio,
  88. FLASH_NAND_CLE(nand_priv.cs), cmd);
  89. else if (ctrl & NAND_ALE)
  90. nlm_write_reg(nand_priv.flash_mmio,
  91. FLASH_NAND_ALE(nand_priv.cs), cmd);
  92. }
  93. struct platform_nand_data xlr_nand_data = {
  94. .chip = {
  95. .nr_chips = 1,
  96. .nr_partitions = ARRAY_SIZE(xlr_nand_parts),
  97. .chip_delay = 50,
  98. .partitions = xlr_nand_parts,
  99. },
  100. .ctrl = {
  101. .cmd_ctrl = xlr_nand_ctrl,
  102. },
  103. };
  104. static struct resource xlr_nand_res[] = {
  105. {
  106. .flags = IORESOURCE_MEM,
  107. },
  108. };
  109. static struct platform_device xlr_nand_dev = {
  110. .name = "gen_nand",
  111. .id = -1,
  112. .num_resources = ARRAY_SIZE(xlr_nand_res),
  113. .resource = xlr_nand_res,
  114. .dev = {
  115. .platform_data = &xlr_nand_data,
  116. }
  117. };
  118. /*
  119. * XLR/XLS supports upto 8 devices on its FLASH interface. The value in
  120. * FLASH_BAR (on the MEM/IO bridge) gives the base for mapping all the
  121. * flash devices.
  122. * Under this, each flash device has an offset and size given by the
  123. * CSBASE_ADDR and CSBASE_MASK registers for the device.
  124. *
  125. * The CSBASE_ registers are expected to be setup by the bootloader.
  126. */
  127. static void setup_flash_resource(uint64_t flash_mmio,
  128. uint64_t flash_map_base, int cs, struct resource *res)
  129. {
  130. u32 base, mask;
  131. base = nlm_read_reg(flash_mmio, FLASH_CSBASE_ADDR(cs));
  132. mask = nlm_read_reg(flash_mmio, FLASH_CSADDR_MASK(cs));
  133. res->start = flash_map_base + ((unsigned long)base << 16);
  134. res->end = res->start + (mask + 1) * 64 * 1024;
  135. }
  136. static int __init xlr_flash_init(void)
  137. {
  138. uint64_t gpio_mmio, flash_mmio, flash_map_base;
  139. u32 gpio_resetcfg, flash_bar;
  140. int cs, boot_nand, boot_nor;
  141. /* Flash address bits 39:24 is in bridge flash BAR */
  142. flash_bar = nlm_read_reg(nlm_io_base, BRIDGE_FLASH_BAR);
  143. flash_map_base = (flash_bar & 0xffff0000) << 8;
  144. gpio_mmio = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
  145. flash_mmio = nlm_mmio_base(NETLOGIC_IO_FLASH_OFFSET);
  146. /* Get the chip reset config */
  147. gpio_resetcfg = nlm_read_reg(gpio_mmio, GPIO_PWRON_RESET_CFG_REG);
  148. /* Check for boot flash type */
  149. boot_nor = boot_nand = 0;
  150. if (nlm_chip_is_xls()) {
  151. /* On XLS, check boot from NAND bit (GPIO reset reg bit 16) */
  152. if (gpio_resetcfg & (1 << 16))
  153. boot_nand = 1;
  154. /* check boot from PCMCIA, (GPIO reset reg bit 15 */
  155. if ((gpio_resetcfg & (1 << 15)) == 0)
  156. boot_nor = 1; /* not set, booted from NOR */
  157. } else { /* XLR */
  158. /* check boot from PCMCIA (bit 16 in GPIO reset on XLR) */
  159. if ((gpio_resetcfg & (1 << 16)) == 0)
  160. boot_nor = 1; /* not set, booted from NOR */
  161. }
  162. /* boot flash at chip select 0 */
  163. cs = 0;
  164. if (boot_nand) {
  165. nand_priv.cs = cs;
  166. nand_priv.flash_mmio = flash_mmio;
  167. setup_flash_resource(flash_mmio, flash_map_base, cs,
  168. xlr_nand_res);
  169. /* Initialize NAND flash at CS 0 */
  170. nlm_write_reg(flash_mmio, FLASH_CSDEV_PARM(cs),
  171. FLASH_NAND_CSDEV_PARAM);
  172. nlm_write_reg(flash_mmio, FLASH_CSTIME_PARMA(cs),
  173. FLASH_NAND_CSTIME_PARAMA);
  174. nlm_write_reg(flash_mmio, FLASH_CSTIME_PARMB(cs),
  175. FLASH_NAND_CSTIME_PARAMB);
  176. pr_info("ChipSelect %d: NAND Flash %pR\n", cs, xlr_nand_res);
  177. return platform_device_register(&xlr_nand_dev);
  178. }
  179. if (boot_nor) {
  180. setup_flash_resource(flash_mmio, flash_map_base, cs,
  181. xlr_nor_res);
  182. pr_info("ChipSelect %d: NOR Flash %pR\n", cs, xlr_nor_res);
  183. return platform_device_register(&xlr_nor_dev);
  184. }
  185. return 0;
  186. }
  187. arch_initcall(xlr_flash_init);