005-spi-ath79-avoid-multiple-initialization-of-the-SPI-c.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From d731c08cf1d264fd6113b9a97790c5a3a86ea520 Mon Sep 17 00:00:00 2001
  2. From: Gabor Juhos <[email protected]>
  3. Date: Thu, 27 Dec 2012 10:42:28 +0100
  4. Subject: [PATCH] spi/ath79: avoid multiple initialization of the SPI
  5. controller
  6. commit c4a31f43005512b366e8bfc346e7f14c1a7a1ba7 upstream.
  7. Currently we are initializing the SPI controller in
  8. the chip select line function, and that function is
  9. called once for each SPI device on the bus. If a
  10. board has multiple SPI devices, the controller will
  11. be initialized multiple times.
  12. Introduce ath79_spi_{en,dis}able helper functions,
  13. and call those from probe/response in order to avoid
  14. the mutliple initialization of the controller.
  15. Signed-off-by: Gabor Juhos <[email protected]>
  16. Signed-off-by: Grant Likely <[email protected]>
  17. ---
  18. drivers/spi/spi-ath79.c | 41 ++++++++++++++++++++++++-----------------
  19. 1 file changed, 24 insertions(+), 17 deletions(-)
  20. --- a/drivers/spi/spi-ath79.c
  21. +++ b/drivers/spi/spi-ath79.c
  22. @@ -96,16 +96,8 @@ static void ath79_spi_chipselect(struct
  23. }
  24. -static int ath79_spi_setup_cs(struct spi_device *spi)
  25. +static void ath79_spi_enable(struct ath79_spi *sp)
  26. {
  27. - struct ath79_spi *sp = ath79_spidev_to_sp(spi);
  28. - struct ath79_spi_controller_data *cdata;
  29. - int status;
  30. -
  31. - cdata = spi->controller_data;
  32. - if (spi->chip_select && !cdata)
  33. - return -EINVAL;
  34. -
  35. /* enable GPIO mode */
  36. ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO);
  37. @@ -115,6 +107,24 @@ static int ath79_spi_setup_cs(struct spi
  38. /* TODO: setup speed? */
  39. ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43);
  40. +}
  41. +
  42. +static void ath79_spi_disable(struct ath79_spi *sp)
  43. +{
  44. + /* restore CTRL register */
  45. + ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl);
  46. + /* disable GPIO mode */
  47. + ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
  48. +}
  49. +
  50. +static int ath79_spi_setup_cs(struct spi_device *spi)
  51. +{
  52. + struct ath79_spi_controller_data *cdata;
  53. + int status;
  54. +
  55. + cdata = spi->controller_data;
  56. + if (spi->chip_select && !cdata)
  57. + return -EINVAL;
  58. status = 0;
  59. if (spi->chip_select) {
  60. @@ -135,17 +145,10 @@ static int ath79_spi_setup_cs(struct spi
  61. static void ath79_spi_cleanup_cs(struct spi_device *spi)
  62. {
  63. - struct ath79_spi *sp = ath79_spidev_to_sp(spi);
  64. -
  65. if (spi->chip_select) {
  66. struct ath79_spi_controller_data *cdata = spi->controller_data;
  67. gpio_free(cdata->gpio);
  68. }
  69. -
  70. - /* restore CTRL register */
  71. - ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl);
  72. - /* disable GPIO mode */
  73. - ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
  74. }
  75. static int ath79_spi_setup(struct spi_device *spi)
  76. @@ -268,12 +271,15 @@ static int ath79_spi_probe(struct platfo
  77. dev_dbg(&pdev->dev, "register read/write delay is %u nsecs\n",
  78. sp->rrw_delay);
  79. + ath79_spi_enable(sp);
  80. ret = spi_bitbang_start(&sp->bitbang);
  81. if (ret)
  82. - goto err_clk_disable;
  83. + goto err_disable;
  84. return 0;
  85. +err_disable:
  86. + ath79_spi_disable(sp);
  87. err_clk_disable:
  88. clk_disable(sp->clk);
  89. err_clk_put:
  90. @@ -292,6 +298,7 @@ static int ath79_spi_remove(struct platf
  91. struct ath79_spi *sp = platform_get_drvdata(pdev);
  92. spi_bitbang_stop(&sp->bitbang);
  93. + ath79_spi_disable(sp);
  94. clk_disable(sp->clk);
  95. clk_put(sp->clk);
  96. iounmap(sp->base);