0017-sf-add-init-function.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From aa9d5d64ca6441cb24e22dc3c1f707da62da2887 Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <[email protected]>
  3. Date: Tue, 6 Nov 2012 19:35:17 +0100
  4. Subject: sf: add init function
  5. Signed-off-by: Daniel Schwierzeck <[email protected]>
  6. --- a/drivers/mtd/spi/spi_flash.c
  7. +++ b/drivers/mtd/spi/spi_flash.c
  8. @@ -482,3 +482,36 @@ void spi_flash_free(struct spi_flash *fl
  9. spi_flash_free_spl(flash);
  10. free(flash);
  11. }
  12. +
  13. +#ifdef CONFIG_SPI_FLASH_MTD
  14. +static int spi_flash_mtd_register(void)
  15. +{
  16. + struct spi_flash *flash;
  17. + int err;
  18. +
  19. + flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
  20. + CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
  21. + if (!flash)
  22. + return -1;
  23. +
  24. + err = spi_flash_mtd_init(flash);
  25. + if (err)
  26. + spi_flash_free(flash);
  27. +
  28. + return err;
  29. +}
  30. +#else
  31. +static int spi_flash_mtd_register(void)
  32. +{
  33. + return 0;
  34. +}
  35. +#endif
  36. +
  37. +int spi_flash_init(void)
  38. +{
  39. + int err;
  40. +
  41. + err = spi_flash_mtd_register();
  42. +
  43. + return err;
  44. +}
  45. --- a/include/spi_flash.h
  46. +++ b/include/spi_flash.h
  47. @@ -51,6 +51,8 @@ struct spi_flash {
  48. #endif
  49. };
  50. +int spi_flash_init(void);
  51. +
  52. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  53. unsigned int max_hz, unsigned int spi_mode);
  54. void spi_flash_free(struct spi_flash *flash);