dev-flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 BCM3368_CPU_ID:
  66. case BCM6358_CPU_ID:
  67. val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
  68. if (val & STRAPBUS_6358_BOOT_SEL_PARALLEL)
  69. return BCM63XX_FLASH_TYPE_PARALLEL;
  70. else
  71. return BCM63XX_FLASH_TYPE_SERIAL;
  72. case BCM6362_CPU_ID:
  73. val = bcm_misc_readl(MISC_STRAPBUS_6362_REG);
  74. if (val & STRAPBUS_6362_BOOT_SEL_SERIAL)
  75. return BCM63XX_FLASH_TYPE_SERIAL;
  76. else
  77. return BCM63XX_FLASH_TYPE_NAND;
  78. case BCM6368_CPU_ID:
  79. val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
  80. switch (val & STRAPBUS_6368_BOOT_SEL_MASK) {
  81. case STRAPBUS_6368_BOOT_SEL_NAND:
  82. return BCM63XX_FLASH_TYPE_NAND;
  83. case STRAPBUS_6368_BOOT_SEL_SERIAL:
  84. return BCM63XX_FLASH_TYPE_SERIAL;
  85. case STRAPBUS_6368_BOOT_SEL_PARALLEL:
  86. return BCM63XX_FLASH_TYPE_PARALLEL;
  87. }
  88. default:
  89. return -EINVAL;
  90. }
  91. }
  92. int __init bcm63xx_flash_register(void)
  93. {
  94. int flash_type;
  95. u32 val;
  96. flash_type = bcm63xx_detect_flash_type();
  97. switch (flash_type) {
  98. case BCM63XX_FLASH_TYPE_PARALLEL:
  99. /* read base address of boot chip select (0) */
  100. val = bcm_mpi_readl(MPI_CSBASE_REG(0));
  101. val &= MPI_CSBASE_BASE_MASK;
  102. mtd_resources[0].start = val;
  103. mtd_resources[0].end = 0x1FFFFFFF;
  104. return platform_device_register(&mtd_dev);
  105. case BCM63XX_FLASH_TYPE_SERIAL:
  106. pr_warn("unsupported serial flash detected\n");
  107. return -ENODEV;
  108. case BCM63XX_FLASH_TYPE_NAND:
  109. pr_warn("unsupported NAND flash detected\n");
  110. return -ENODEV;
  111. default:
  112. pr_err("flash detection failed for BCM%x: %d\n",
  113. bcm63xx_get_cpu_id(), flash_type);
  114. return -ENODEV;
  115. }
  116. }