0004-sf-add-slim-probe-funtions-for-SPL.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From da11da943487e2f724f25d409bcaa1f099637c0b Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  3. Date: Sun, 13 Oct 2013 14:56:45 +0200
  4. Subject: sf: add slim probe funtions for SPL
  5. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  6. --- a/drivers/mtd/spi/sf_probe.c
  7. +++ b/drivers/mtd/spi/sf_probe.c
  8. @@ -365,3 +365,58 @@ void spi_flash_free(struct spi_flash *fl
  9. spi_free_slave(flash->spi);
  10. free(flash);
  11. }
  12. +
  13. +#ifdef CONFIG_SPI_SPL_SIMPLE
  14. +int spl_spi_flash_probe(struct spi_flash *flash)
  15. +{
  16. + struct spi_slave *spi;
  17. + u8 idcode[5];
  18. + int ret;
  19. +
  20. + /* Setup spi_slave */
  21. + spi = spi_setup_slave(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS,
  22. + CONFIG_SPL_SPI_MAX_HZ, CONFIG_SPL_SPI_MODE);
  23. + if (!spi) {
  24. + debug("SF: Failed to set up slave\n");
  25. + return -1;
  26. + }
  27. +
  28. + /* Claim spi bus */
  29. + ret = spi_claim_bus(spi);
  30. + if (ret) {
  31. + debug("SF: Failed to claim SPI bus: %d\n", ret);
  32. + goto err_claim_bus;
  33. + }
  34. +
  35. + /* Read the ID codes */
  36. + ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
  37. + if (ret) {
  38. + debug("SF: Failed to get idcodes\n");
  39. + goto err_read_id;
  40. + }
  41. +
  42. + /* Validate params from spi_flash_params table */
  43. + flash->spi = spi;
  44. + ret = spi_flash_validate_params(flash, idcode);
  45. + if (ret)
  46. + goto err_read_id;
  47. +
  48. + /* Release spi bus */
  49. + spi_release_bus(spi);
  50. +
  51. + return 0;
  52. +
  53. +err_read_id:
  54. + spi_release_bus(spi);
  55. +err_claim_bus:
  56. + spi_free_slave(spi);
  57. + flash->spi = NULL;
  58. +
  59. + return ret;
  60. +}
  61. +
  62. +void spl_spi_flash_free(struct spi_flash *flash)
  63. +{
  64. + spi_free_slave(flash->spi);
  65. +}
  66. +#endif
  67. --- a/include/spi_flash.h
  68. +++ b/include/spi_flash.h
  69. @@ -69,6 +69,9 @@ struct spi_flash *spi_flash_probe(unsign
  70. unsigned int max_hz, unsigned int spi_mode);
  71. void spi_flash_free(struct spi_flash *flash);
  72. +int spl_spi_flash_probe(struct spi_flash *flash);
  73. +void spl_spi_flash_free(struct spi_flash *flash);
  74. +
  75. static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
  76. size_t len, void *buf)
  77. {