dev-flash.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 BCM6338_CPU_ID:
  55. case BCM6345_CPU_ID:
  56. case BCM6348_CPU_ID:
  57. /* no way to auto detect so assume parallel */
  58. return BCM63XX_FLASH_TYPE_PARALLEL;
  59. case BCM6358_CPU_ID:
  60. val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
  61. if (val & STRAPBUS_6358_BOOT_SEL_PARALLEL)
  62. return BCM63XX_FLASH_TYPE_PARALLEL;
  63. else
  64. return BCM63XX_FLASH_TYPE_SERIAL;
  65. case BCM6368_CPU_ID:
  66. val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
  67. switch (val & STRAPBUS_6368_BOOT_SEL_MASK) {
  68. case STRAPBUS_6368_BOOT_SEL_NAND:
  69. return BCM63XX_FLASH_TYPE_NAND;
  70. case STRAPBUS_6368_BOOT_SEL_SERIAL:
  71. return BCM63XX_FLASH_TYPE_SERIAL;
  72. case STRAPBUS_6368_BOOT_SEL_PARALLEL:
  73. return BCM63XX_FLASH_TYPE_PARALLEL;
  74. }
  75. default:
  76. return -EINVAL;
  77. }
  78. }
  79. int __init bcm63xx_flash_register(void)
  80. {
  81. int flash_type;
  82. u32 val;
  83. flash_type = bcm63xx_detect_flash_type();
  84. switch (flash_type) {
  85. case BCM63XX_FLASH_TYPE_PARALLEL:
  86. /* read base address of boot chip select (0) */
  87. val = bcm_mpi_readl(MPI_CSBASE_REG(0));
  88. val &= MPI_CSBASE_BASE_MASK;
  89. mtd_resources[0].start = val;
  90. mtd_resources[0].end = 0x1FFFFFFF;
  91. return platform_device_register(&mtd_dev);
  92. case BCM63XX_FLASH_TYPE_SERIAL:
  93. pr_warn("unsupported serial flash detected\n");
  94. return -ENODEV;
  95. case BCM63XX_FLASH_TYPE_NAND:
  96. pr_warn("unsupported NAND flash detected\n");
  97. return -ENODEV;
  98. default:
  99. pr_err("flash detection failed for BCM%x: %d\n",
  100. bcm63xx_get_cpu_id(), flash_type);
  101. return -ENODEV;
  102. }
  103. }