dev-flash.c 3.0 KB

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