mtd-spi-nor.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-02-25 GuEe-GUI the first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include "dev_spi_flash_sfud.h"
  13. extern rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name);
  14. static rt_err_t spi_nor_flash_probe(struct rt_spi_device *spi_dev)
  15. {
  16. rt_spi_flash_device_t flash;
  17. const char *dev_name = rt_dm_dev_get_name(&spi_dev->parent);
  18. const char *vendor = spi_dev->id ? spi_dev->id->name : "spi-nor";
  19. rt_spidev_device_init(spi_dev, dev_name);
  20. if (!(flash = rt_sfud_flash_probe(vendor, dev_name)))
  21. {
  22. /* Maybe is not support by SFUD now, user could access it later */
  23. return -RT_ENOSYS;
  24. }
  25. rt_dm_dev_set_name_auto(&flash->flash_device, "nor");
  26. return RT_EOK;
  27. }
  28. static const struct rt_spi_device_id spi_nor_flash_ids[] =
  29. {
  30. /*
  31. * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
  32. * hack around the fact that the SPI core does not provide uevent
  33. * matching for .ofw_ids
  34. */
  35. { "spi-nor" },
  36. /*
  37. * Entries not used in DTs that should be safe to drop after replacing
  38. * them with "spi-nor" in platform data.
  39. */
  40. { "s25sl064a" }, { "w25x16" }, { "m25p10" }, { "m25px64" },
  41. /*
  42. * Entries that were used in DTs without "jedec,spi-nor" fallback and
  43. * should be kept for backward compatibility.
  44. */
  45. { "at25df321a" }, { "at25df641" }, { "at26df081a" },
  46. { "mx25l4005a" }, { "mx25l1606e" }, { "mx25l6405d" }, { "mx25l12805d" },
  47. { "mx25l25635e" }, { "mx66l51235l" },
  48. { "n25q064" }, { "n25q128a11" }, { "n25q128a13" }, { "n25q512a" },
  49. { "s25fl256s1" }, { "s25fl512s" }, { "s25sl12801" }, { "s25fl008k" },
  50. { "s25fl064k" },
  51. { "sst25vf040b" }, { "sst25vf016b" }, { "sst25vf032b" }, { "sst25wf040" },
  52. { "m25p40" }, { "m25p80" }, { "m25p16" }, { "m25p32" },
  53. { "m25p64" }, { "m25p128" },
  54. { "w25x80" }, { "w25x32" }, { "w25q32" }, { "w25q32dw" },
  55. { "w25q80bl" }, { "w25q128" }, { "w25q256" },
  56. /* Flashes that can't be detected using JEDEC */
  57. { "m25p05-nonjedec" }, { "m25p10-nonjedec" }, { "m25p20-nonjedec" },
  58. { "m25p40-nonjedec" }, { "m25p80-nonjedec" }, { "m25p16-nonjedec" },
  59. { "m25p32-nonjedec" }, { "m25p64-nonjedec" }, { "m25p128-nonjedec" },
  60. /* Everspin MRAMs (non-JEDEC) */
  61. { "mr25h128" }, /* 128 Kib, 40 MHz */
  62. { "mr25h256" }, /* 256 Kib, 40 MHz */
  63. { "mr25h10" }, /* 1 Mib, 40 MHz */
  64. { "mr25h40" }, /* 4 Mib, 40 MHz */
  65. { /* sentinel */ },
  66. };
  67. static const struct rt_ofw_node_id spi_nor_flash_ofw_ids[] =
  68. {
  69. /*
  70. * Generic compatibility for SPI NOR that can be identified by the
  71. * JEDEC READ ID opcode (0x9F). Use this, if possible.
  72. */
  73. { .compatible = "jedec,spi-nor" },
  74. { /* sentinel */ }
  75. };
  76. static struct rt_spi_driver spi_nor_flash_driver =
  77. {
  78. .ids = spi_nor_flash_ids,
  79. .ofw_ids = spi_nor_flash_ofw_ids,
  80. .probe = spi_nor_flash_probe,
  81. };
  82. RT_SPI_DRIVER_EXPORT(spi_nor_flash_driver);