192-ahci-platform-changes.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. From a52ae09871d171d6771b4bef2d4c56dd435e740f Mon Sep 17 00:00:00 2001
  2. From: Roger Quadros <[email protected]>
  3. Date: Mon, 20 Jan 2014 16:32:33 +0200
  4. Subject: [PATCH] ata: ahci_platform: Add DT compatible for Synopsis DWC AHCI
  5. controller
  6. Add compatible string "snps,dwc-ahci", which should be used
  7. for Synopsis Designware SATA cores. e.g. on TI OMAP5 and DRA7 platforms.
  8. Signed-off-by: Roger Quadros <[email protected]>
  9. Reviewed-by: Bartlomiej Zolnierkiewicz <[email protected]>
  10. Signed-off-by: Hans de Goede <[email protected]>
  11. ---
  12. drivers/ata/ahci_platform.c | 1 +
  13. 1 file changed, 1 insertion(+)
  14. --- a/drivers/ata/ahci_platform.c
  15. +++ b/drivers/ata/ahci_platform.c
  16. @@ -23,6 +23,8 @@
  17. #include <linux/platform_device.h>
  18. #include <linux/libata.h>
  19. #include <linux/ahci_platform.h>
  20. +#include <linux/phy/phy.h>
  21. +#include <linux/pm_runtime.h>
  22. #include "ahci.h"
  23. static void ahci_host_stop(struct ata_host *host);
  24. @@ -147,6 +149,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_
  25. * the following order:
  26. * 1) Regulator
  27. * 2) Clocks (through ahci_platform_enable_clks)
  28. + * 3) Phy
  29. *
  30. * If resource enabling fails at any point the previous enabled
  31. * resources are disabled in reverse order.
  32. @@ -171,8 +174,23 @@ int ahci_platform_enable_resources(struc
  33. if (rc)
  34. goto disable_regulator;
  35. + if (hpriv->phy) {
  36. + rc = phy_init(hpriv->phy);
  37. + if (rc)
  38. + goto disable_clks;
  39. +
  40. + rc = phy_power_on(hpriv->phy);
  41. + if (rc) {
  42. + phy_exit(hpriv->phy);
  43. + goto disable_clks;
  44. + }
  45. + }
  46. +
  47. return 0;
  48. +disable_clks:
  49. + ahci_platform_disable_clks(hpriv);
  50. +
  51. disable_regulator:
  52. if (hpriv->target_pwr)
  53. regulator_disable(hpriv->target_pwr);
  54. @@ -186,14 +204,20 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_r
  55. *
  56. * This function disables all ahci_platform managed resources in
  57. * the following order:
  58. - * 1) Clocks (through ahci_platform_disable_clks)
  59. - * 2) Regulator
  60. + * 1) Phy
  61. + * 2) Clocks (through ahci_platform_disable_clks)
  62. + * 3) Regulator
  63. *
  64. * LOCKING:
  65. * None.
  66. */
  67. void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
  68. {
  69. + if (hpriv->phy) {
  70. + phy_power_off(hpriv->phy);
  71. + phy_exit(hpriv->phy);
  72. + }
  73. +
  74. ahci_platform_disable_clks(hpriv);
  75. if (hpriv->target_pwr)
  76. @@ -206,6 +230,11 @@ static void ahci_platform_put_resources(
  77. struct ahci_host_priv *hpriv = res;
  78. int c;
  79. + if (hpriv->got_runtime_pm) {
  80. + pm_runtime_put_sync(dev);
  81. + pm_runtime_disable(dev);
  82. + }
  83. +
  84. for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)
  85. clk_put(hpriv->clks[c]);
  86. }
  87. @@ -222,6 +251,7 @@ static void ahci_platform_put_resources(
  88. * 2) regulator for controlling the targets power (optional)
  89. * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
  90. * or for non devicetree enabled platforms a single clock
  91. + * 4) phy (optional)
  92. *
  93. * LOCKING:
  94. * None.
  95. @@ -283,6 +313,29 @@ struct ahci_host_priv *ahci_platform_get
  96. hpriv->clks[i] = clk;
  97. }
  98. + hpriv->phy = devm_phy_get(dev, "sata-phy");
  99. + if (IS_ERR(hpriv->phy)) {
  100. + rc = PTR_ERR(hpriv->phy);
  101. + switch (rc) {
  102. + case -ENODEV:
  103. + case -ENOSYS:
  104. + /* continue normally */
  105. + hpriv->phy = NULL;
  106. + break;
  107. +
  108. + case -EPROBE_DEFER:
  109. + goto err_out;
  110. +
  111. + default:
  112. + dev_err(dev, "couldn't get sata-phy\n");
  113. + goto err_out;
  114. + }
  115. + }
  116. +
  117. + pm_runtime_enable(dev);
  118. + pm_runtime_get_sync(dev);
  119. + hpriv->got_runtime_pm = true;
  120. +
  121. devres_remove_group(dev, NULL);
  122. return hpriv;
  123. @@ -592,6 +645,11 @@ int ahci_platform_resume(struct device *
  124. if (rc)
  125. goto disable_resources;
  126. + /* We resumed so update PM runtime state */
  127. + pm_runtime_disable(dev);
  128. + pm_runtime_set_active(dev);
  129. + pm_runtime_enable(dev);
  130. +
  131. return 0;
  132. disable_resources:
  133. @@ -609,6 +667,7 @@ static const struct of_device_id ahci_of
  134. { .compatible = "snps,spear-ahci", },
  135. { .compatible = "snps,exynos5440-ahci", },
  136. { .compatible = "ibm,476gtr-ahci", },
  137. + { .compatible = "snps,dwc-ahci", },
  138. {},
  139. };
  140. MODULE_DEVICE_TABLE(of, ahci_of_match);
  141. --- a/drivers/ata/ahci.h
  142. +++ b/drivers/ata/ahci.h
  143. @@ -37,6 +37,7 @@
  144. #include <linux/clk.h>
  145. #include <linux/libata.h>
  146. +#include <linux/phy/phy.h>
  147. #include <linux/regulator/consumer.h>
  148. /* Enclosure Management Control */
  149. @@ -324,8 +325,10 @@ struct ahci_host_priv {
  150. u32 em_loc; /* enclosure management location */
  151. u32 em_buf_sz; /* EM buffer size in byte */
  152. u32 em_msg_type; /* EM message type */
  153. + bool got_runtime_pm; /* Did we do pm_runtime_get? */
  154. struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
  155. struct regulator *target_pwr; /* Optional */
  156. + struct phy *phy; /* If platform uses phy */
  157. void *plat_data; /* Other platform data */
  158. /*
  159. * Optional ahci_start_engine override, if not set this gets set to the
  160. --- a/drivers/ata/ahci_sunxi.c
  161. +++ b/drivers/ata/ahci_sunxi.c
  162. @@ -90,7 +90,7 @@ static int ahci_sunxi_phy_init(struct de
  163. /* This magic is from the original code */
  164. writel(0, reg_base + AHCI_RWCR);
  165. - mdelay(5);
  166. + msleep(5);
  167. sunxi_setbits(reg_base + AHCI_PHYCS1R, BIT(19));
  168. sunxi_clrsetbits(reg_base + AHCI_PHYCS0R,
  169. @@ -105,7 +105,7 @@ static int ahci_sunxi_phy_init(struct de
  170. (0x7 << 20), (0x3 << 20));
  171. sunxi_clrsetbits(reg_base + AHCI_PHYCS2R,
  172. (0x1f << 5), (0x19 << 5));
  173. - mdelay(5);
  174. + msleep(5);
  175. sunxi_setbits(reg_base + AHCI_PHYCS0R, (0x1 << 19));
  176. @@ -137,7 +137,7 @@ static int ahci_sunxi_phy_init(struct de
  177. udelay(1);
  178. } while (1);
  179. - mdelay(15);
  180. + msleep(15);
  181. writel(0x7, reg_base + AHCI_RWCR);