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