kernel: update 3.14 to 3.14.18
[openwrt/openwrt.git] / target / linux / ipq806x / patches / 0111-ahci-platform-Add-support-for-an-optional-regulator-.patch
1 From 967f4a7821a3356d9d3c8b641537cd6d5eb15439 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sat, 22 Feb 2014 16:53:32 +0100
4 Subject: [PATCH 111/182] ahci-platform: Add support for an optional regulator
5 for sata-target power
6
7 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
8 Signed-off-by: Tejun Heo <tj@kernel.org>
9 ---
10 .../devicetree/bindings/ata/ahci-platform.txt | 1 +
11 drivers/ata/ahci.h | 2 ++
12 drivers/ata/ahci_platform.c | 36 ++++++++++++++++++--
13 3 files changed, 37 insertions(+), 2 deletions(-)
14
15 --- a/Documentation/devicetree/bindings/ata/ahci-platform.txt
16 +++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt
17 @@ -11,6 +11,7 @@ Required properties:
18 Optional properties:
19 - dma-coherent : Present if dma operations are coherent
20 - clocks : a list of phandle + clock specifier pairs
21 +- target-supply : regulator for SATA target power
22
23 Example:
24 sata@ffe08000 {
25 --- a/drivers/ata/ahci.h
26 +++ b/drivers/ata/ahci.h
27 @@ -37,6 +37,7 @@
28
29 #include <linux/clk.h>
30 #include <linux/libata.h>
31 +#include <linux/regulator/consumer.h>
32
33 /* Enclosure Management Control */
34 #define EM_CTRL_MSG_TYPE 0x000f0000
35 @@ -324,6 +325,7 @@ struct ahci_host_priv {
36 u32 em_buf_sz; /* EM buffer size in byte */
37 u32 em_msg_type; /* EM message type */
38 struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
39 + struct regulator *target_pwr; /* Optional */
40 void *plat_data; /* Other platform data */
41 /*
42 * Optional ahci_start_engine override, if not set this gets set to the
43 --- a/drivers/ata/ahci_platform.c
44 +++ b/drivers/ata/ahci_platform.c
45 @@ -186,6 +186,14 @@ static int ahci_probe(struct platform_de
46 return -ENOMEM;
47 }
48
49 + hpriv->target_pwr = devm_regulator_get_optional(dev, "target");
50 + if (IS_ERR(hpriv->target_pwr)) {
51 + rc = PTR_ERR(hpriv->target_pwr);
52 + if (rc == -EPROBE_DEFER)
53 + return -EPROBE_DEFER;
54 + hpriv->target_pwr = NULL;
55 + }
56 +
57 for (i = 0; i < AHCI_MAX_CLKS; i++) {
58 /*
59 * For now we must use clk_get(dev, NULL) for the first clock,
60 @@ -207,9 +215,15 @@ static int ahci_probe(struct platform_de
61 hpriv->clks[i] = clk;
62 }
63
64 + if (hpriv->target_pwr) {
65 + rc = regulator_enable(hpriv->target_pwr);
66 + if (rc)
67 + goto free_clk;
68 + }
69 +
70 rc = ahci_enable_clks(dev, hpriv);
71 if (rc)
72 - goto free_clk;
73 + goto disable_regulator;
74
75 /*
76 * Some platforms might need to prepare for mmio region access,
77 @@ -292,6 +306,9 @@ pdata_exit:
78 pdata->exit(dev);
79 disable_unprepare_clk:
80 ahci_disable_clks(hpriv);
81 +disable_regulator:
82 + if (hpriv->target_pwr)
83 + regulator_disable(hpriv->target_pwr);
84 free_clk:
85 ahci_put_clks(hpriv);
86 return rc;
87 @@ -308,6 +325,9 @@ static void ahci_host_stop(struct ata_ho
88
89 ahci_disable_clks(hpriv);
90 ahci_put_clks(hpriv);
91 +
92 + if (hpriv->target_pwr)
93 + regulator_disable(hpriv->target_pwr);
94 }
95
96 #ifdef CONFIG_PM_SLEEP
97 @@ -344,6 +364,9 @@ static int ahci_suspend(struct device *d
98
99 ahci_disable_clks(hpriv);
100
101 + if (hpriv->target_pwr)
102 + regulator_disable(hpriv->target_pwr);
103 +
104 return 0;
105 }
106
107 @@ -354,9 +377,15 @@ static int ahci_resume(struct device *de
108 struct ahci_host_priv *hpriv = host->private_data;
109 int rc;
110
111 + if (hpriv->target_pwr) {
112 + rc = regulator_enable(hpriv->target_pwr);
113 + if (rc)
114 + return rc;
115 + }
116 +
117 rc = ahci_enable_clks(dev, hpriv);
118 if (rc)
119 - return rc;
120 + goto disable_regulator;
121
122 if (pdata && pdata->resume) {
123 rc = pdata->resume(dev);
124 @@ -378,6 +407,9 @@ static int ahci_resume(struct device *de
125
126 disable_unprepare_clk:
127 ahci_disable_clks(hpriv);
128 +disable_regulator:
129 + if (hpriv->target_pwr)
130 + regulator_disable(hpriv->target_pwr);
131
132 return rc;
133 }