ipq806x: Add support for IPQ806x chip family
[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 diff --git a/Documentation/devicetree/bindings/ata/ahci-platform.txt b/Documentation/devicetree/bindings/ata/ahci-platform.txt
16 index 3ced07d..1ac807f 100644
17 --- a/Documentation/devicetree/bindings/ata/ahci-platform.txt
18 +++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt
19 @@ -11,6 +11,7 @@ Required properties:
20  Optional properties:
21  - dma-coherent      : Present if dma operations are coherent
22  - clocks            : a list of phandle + clock specifier pairs
23 +- target-supply     : regulator for SATA target power
24  
25  Example:
26          sata@ffe08000 {
27 diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
28 index c12862b..bf8100c 100644
29 --- a/drivers/ata/ahci.h
30 +++ b/drivers/ata/ahci.h
31 @@ -37,6 +37,7 @@
32  
33  #include <linux/clk.h>
34  #include <linux/libata.h>
35 +#include <linux/regulator/consumer.h>
36  
37  /* Enclosure Management Control */
38  #define EM_CTRL_MSG_TYPE              0x000f0000
39 @@ -323,6 +324,7 @@ struct ahci_host_priv {
40         u32                     em_buf_sz;      /* EM buffer size in byte */
41         u32                     em_msg_type;    /* EM message type */
42         struct clk              *clks[AHCI_MAX_CLKS]; /* Optional */
43 +       struct regulator        *target_pwr;    /* Optional */
44         void                    *plat_data;     /* Other platform data */
45         /*
46          * Optional ahci_start_engine override, if not set this gets set to the
47 diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
48 index 2342a42..8f18ebe 100644
49 --- a/drivers/ata/ahci_platform.c
50 +++ b/drivers/ata/ahci_platform.c
51 @@ -186,6 +186,14 @@ static int ahci_probe(struct platform_device *pdev)
52                 return -ENOMEM;
53         }
54  
55 +       hpriv->target_pwr = devm_regulator_get_optional(dev, "target");
56 +       if (IS_ERR(hpriv->target_pwr)) {
57 +               rc = PTR_ERR(hpriv->target_pwr);
58 +               if (rc == -EPROBE_DEFER)
59 +                       return -EPROBE_DEFER;
60 +               hpriv->target_pwr = NULL;
61 +       }
62 +
63         for (i = 0; i < AHCI_MAX_CLKS; i++) {
64                 /*
65                  * For now we must use clk_get(dev, NULL) for the first clock,
66 @@ -207,9 +215,15 @@ static int ahci_probe(struct platform_device *pdev)
67                 hpriv->clks[i] = clk;
68         }
69  
70 +       if (hpriv->target_pwr) {
71 +               rc = regulator_enable(hpriv->target_pwr);
72 +               if (rc)
73 +                       goto free_clk;
74 +       }
75 +
76         rc = ahci_enable_clks(dev, hpriv);
77         if (rc)
78 -               goto free_clk;
79 +               goto disable_regulator;
80  
81         /*
82          * Some platforms might need to prepare for mmio region access,
83 @@ -292,6 +306,9 @@ pdata_exit:
84                 pdata->exit(dev);
85  disable_unprepare_clk:
86         ahci_disable_clks(hpriv);
87 +disable_regulator:
88 +       if (hpriv->target_pwr)
89 +               regulator_disable(hpriv->target_pwr);
90  free_clk:
91         ahci_put_clks(hpriv);
92         return rc;
93 @@ -308,6 +325,9 @@ static void ahci_host_stop(struct ata_host *host)
94  
95         ahci_disable_clks(hpriv);
96         ahci_put_clks(hpriv);
97 +
98 +       if (hpriv->target_pwr)
99 +               regulator_disable(hpriv->target_pwr);
100  }
101  
102  #ifdef CONFIG_PM_SLEEP
103 @@ -344,6 +364,9 @@ static int ahci_suspend(struct device *dev)
104  
105         ahci_disable_clks(hpriv);
106  
107 +       if (hpriv->target_pwr)
108 +               regulator_disable(hpriv->target_pwr);
109 +
110         return 0;
111  }
112  
113 @@ -354,9 +377,15 @@ static int ahci_resume(struct device *dev)
114         struct ahci_host_priv *hpriv = host->private_data;
115         int rc;
116  
117 +       if (hpriv->target_pwr) {
118 +               rc = regulator_enable(hpriv->target_pwr);
119 +               if (rc)
120 +                       return rc;
121 +       }
122 +
123         rc = ahci_enable_clks(dev, hpriv);
124         if (rc)
125 -               return rc;
126 +               goto disable_regulator;
127  
128         if (pdata && pdata->resume) {
129                 rc = pdata->resume(dev);
130 @@ -378,6 +407,9 @@ static int ahci_resume(struct device *dev)
131  
132  disable_unprepare_clk:
133         ahci_disable_clks(hpriv);
134 +disable_regulator:
135 +       if (hpriv->target_pwr)
136 +               regulator_disable(hpriv->target_pwr);
137  
138         return rc;
139  }
140 -- 
141 1.7.10.4
142