physmap_of_gemini.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Cortina Systems Gemini OF physmap add-on
  4. * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
  5. *
  6. * This SoC has an elaborate flash control register, so we need to
  7. * detect and set it up when booting on this platform.
  8. */
  9. #include <linux/export.h>
  10. #include <linux/of.h>
  11. #include <linux/of_device.h>
  12. #include <linux/mtd/map.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/regmap.h>
  15. #include <linux/bitops.h>
  16. #include "physmap_of_gemini.h"
  17. /*
  18. * The Flash-relevant parts of the global status register
  19. * These would also be relevant for a NAND driver.
  20. */
  21. #define GLOBAL_STATUS 0x04
  22. #define FLASH_TYPE_MASK (0x3 << 24)
  23. #define FLASH_TYPE_NAND_2K (0x3 << 24)
  24. #define FLASH_TYPE_NAND_512 (0x2 << 24)
  25. #define FLASH_TYPE_PARALLEL (0x1 << 24)
  26. #define FLASH_TYPE_SERIAL (0x0 << 24)
  27. /* if parallel */
  28. #define FLASH_WIDTH_16BIT (1 << 23) /* else 8 bit */
  29. /* if serial */
  30. #define FLASH_ATMEL (1 << 23) /* else STM */
  31. #define FLASH_SIZE_MASK (0x3 << 21)
  32. #define NAND_256M (0x3 << 21) /* and more */
  33. #define NAND_128M (0x2 << 21)
  34. #define NAND_64M (0x1 << 21)
  35. #define NAND_32M (0x0 << 21)
  36. #define ATMEL_16M (0x3 << 21) /* and more */
  37. #define ATMEL_8M (0x2 << 21)
  38. #define ATMEL_4M_2M (0x1 << 21)
  39. #define ATMEL_1M (0x0 << 21) /* and less */
  40. #define STM_32M (1 << 22) /* and more */
  41. #define STM_16M (0 << 22) /* and less */
  42. #define FLASH_PARALLEL_HIGH_PIN_CNT (1 << 20) /* else low pin cnt */
  43. static const struct of_device_id syscon_match[] = {
  44. { .compatible = "cortina,gemini-syscon" },
  45. { },
  46. };
  47. int of_flash_probe_gemini(struct platform_device *pdev,
  48. struct device_node *np,
  49. struct map_info *map)
  50. {
  51. struct regmap *rmap;
  52. struct device *dev = &pdev->dev;
  53. u32 val;
  54. int ret;
  55. /* Multiplatform guard */
  56. if (!of_device_is_compatible(np, "cortina,gemini-flash"))
  57. return 0;
  58. rmap = syscon_regmap_lookup_by_phandle(np, "syscon");
  59. if (IS_ERR(rmap)) {
  60. dev_err(dev, "no syscon\n");
  61. return PTR_ERR(rmap);
  62. }
  63. ret = regmap_read(rmap, GLOBAL_STATUS, &val);
  64. if (ret) {
  65. dev_err(dev, "failed to read global status register\n");
  66. return -ENODEV;
  67. }
  68. dev_dbg(dev, "global status reg: %08x\n", val);
  69. /*
  70. * It would be contradictory if a physmap flash was NOT parallel.
  71. */
  72. if ((val & FLASH_TYPE_MASK) != FLASH_TYPE_PARALLEL) {
  73. dev_err(dev, "flash is not parallel\n");
  74. return -ENODEV;
  75. }
  76. /*
  77. * Complain if DT data and hardware definition is different.
  78. */
  79. if (val & FLASH_WIDTH_16BIT) {
  80. if (map->bankwidth != 2)
  81. dev_warn(dev, "flash hardware say flash is 16 bit wide but DT says it is %d bits wide\n",
  82. map->bankwidth * 8);
  83. } else {
  84. if (map->bankwidth != 1)
  85. dev_warn(dev, "flash hardware say flash is 8 bit wide but DT says it is %d bits wide\n",
  86. map->bankwidth * 8);
  87. }
  88. dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n");
  89. return 0;
  90. }