physmap_of_gemini.c 3.2 KB

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