dev-flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Broadcom BCM63xx flash registration
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  9. * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
  10. * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/mtd/physmap.h>
  18. #include <bcm63xx_cpu.h>
  19. #include <bcm63xx_dev_flash.h>
  20. #include <bcm63xx_regs.h>
  21. #include <bcm63xx_io.h>
  22. static struct mtd_partition mtd_partitions[] = {
  23. {
  24. .name = "cfe",
  25. .offset = 0x0,
  26. .size = 0x40000,
  27. }
  28. };
  29. static const char *bcm63xx_part_types[] = { "bcm63xxpart", NULL };
  30. static struct physmap_flash_data flash_data = {
  31. .width = 2,
  32. .parts = mtd_partitions,
  33. .part_probe_types = bcm63xx_part_types,
  34. };
  35. static struct resource mtd_resources[] = {
  36. {
  37. .start = 0, /* filled at runtime */
  38. .end = 0, /* filled at runtime */
  39. .flags = IORESOURCE_MEM,
  40. }
  41. };
  42. static struct platform_device mtd_dev = {
  43. .name = "physmap-flash",
  44. .resource = mtd_resources,
  45. .num_resources = ARRAY_SIZE(mtd_resources),
  46. .dev = {
  47. .platform_data = &flash_data,
  48. },
  49. };
  50. static int __init bcm63xx_detect_flash_type(void)
  51. {
  52. u32 val;
  53. switch (bcm63xx_get_cpu_id()) {
  54. case BCM6328_CPU_ID:
  55. val = bcm_misc_readl(MISC_STRAPBUS_6328_REG);
  56. if (val & STRAPBUS_6328_BOOT_SEL_SERIAL)
  57. return BCM63XX_FLASH_TYPE_SERIAL;
  58. else
  59. return BCM63XX_FLASH_TYPE_NAND;
  60. case BCM6338_CPU_ID:
  61. case BCM6345_CPU_ID:
  62. case BCM6348_CPU_ID:
  63. /* no way to auto detect so assume parallel */
  64. return BCM63XX_FLASH_TYPE_PARALLEL;
  65. case BCM6358_CPU_ID:
  66. val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
  67. if (val & STRAPBUS_6358_BOOT_SEL_PARALLEL)
  68. return BCM63XX_FLASH_TYPE_PARALLEL;
  69. else
  70. return BCM63XX_FLASH_TYPE_SERIAL;
  71. case BCM6362_CPU_ID:
  72. val = bcm_misc_readl(MISC_STRAPBUS_6362_REG);
  73. if (val & STRAPBUS_6362_BOOT_SEL_SERIAL)
  74. return BCM63XX_FLASH_TYPE_SERIAL;
  75. else
  76. return BCM63XX_FLASH_TYPE_NAND;
  77. case BCM6368_CPU_ID:
  78. val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
  79. switch (val & STRAPBUS_6368_BOOT_SEL_MASK) {
  80. case STRAPBUS_6368_BOOT_SEL_NAND:
  81. return BCM63XX_FLASH_TYPE_NAND;
  82. case STRAPBUS_6368_BOOT_SEL_SERIAL:
  83. return BCM63XX_FLASH_TYPE_SERIAL;
  84. case STRAPBUS_6368_BOOT_SEL_PARALLEL:
  85. return BCM63XX_FLASH_TYPE_PARALLEL;
  86. }
  87. default:
  88. return -EINVAL;
  89. }
  90. }
  91. int __init bcm63xx_flash_register(void)
  92. {
  93. int flash_type;
  94. u32 val;
  95. flash_type = bcm63xx_detect_flash_type();
  96. switch (flash_type) {
  97. case BCM63XX_FLASH_TYPE_PARALLEL:
  98. /* read base address of boot chip select (0) */
  99. val = bcm_mpi_readl(MPI_CSBASE_REG(0));
  100. val &= MPI_CSBASE_BASE_MASK;
  101. mtd_resources[0].start = val;
  102. mtd_resources[0].end = 0x1FFFFFFF;
  103. return platform_device_register(&mtd_dev);
  104. case BCM63XX_FLASH_TYPE_SERIAL:
  105. pr_warn("unsupported serial flash detected\n");
  106. return -ENODEV;
  107. case BCM63XX_FLASH_TYPE_NAND:
  108. pr_warn("unsupported NAND flash detected\n");
  109. return -ENODEV;
  110. default:
  111. pr_err("flash detection failed for BCM%x: %d\n",
  112. bcm63xx_get_cpu_id(), flash_type);
  113. return -ENODEV;
  114. }
  115. }