diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-08 23:13:14 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-08 23:13:14 -0500 |
commit | 19c055738b571c920c6e313fa31ac8c5ef4ce5a1 (patch) | |
tree | 5f39869ef0210b420f761a2b458e0449112b9a74 | |
parent | dde86f41f4cb13015288abcff4706993c007f65d (diff) | |
parent | e3eae85773ebd2165d19ca8661cca3b9c60b2ba1 (diff) |
Merge tag 'for_3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy into char-misc-next
Kishon writes:
Pull request for PHY subsystem contains few fixes in PHY-CORE mostly
w.r.t PM and reference counting and also a new PHY driver used by SATA
in Marvell SoC.
-rw-r--r-- | drivers/phy/Kconfig | 6 | ||||
-rw-r--r-- | drivers/phy/Makefile | 1 | ||||
-rw-r--r-- | drivers/phy/phy-core.c | 44 | ||||
-rw-r--r-- | drivers/phy/phy-mvebu-sata.c | 137 |
4 files changed, 175 insertions, 13 deletions
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 330ef2d06567..d0611b84d7f7 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig | |||
@@ -21,6 +21,12 @@ config PHY_EXYNOS_MIPI_VIDEO | |||
21 | Support for MIPI CSI-2 and MIPI DSI DPHY found on Samsung S5P | 21 | Support for MIPI CSI-2 and MIPI DSI DPHY found on Samsung S5P |
22 | and EXYNOS SoCs. | 22 | and EXYNOS SoCs. |
23 | 23 | ||
24 | config PHY_MVEBU_SATA | ||
25 | def_bool y | ||
26 | depends on ARCH_KIRKWOOD || ARCH_DOVE | ||
27 | depends on OF | ||
28 | select GENERIC_PHY | ||
29 | |||
24 | config OMAP_USB2 | 30 | config OMAP_USB2 |
25 | tristate "OMAP USB2 PHY Driver" | 31 | tristate "OMAP USB2 PHY Driver" |
26 | depends on ARCH_OMAP2PLUS | 32 | depends on ARCH_OMAP2PLUS |
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index d0caae9cfb83..4e4adc96f753 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile | |||
@@ -5,5 +5,6 @@ | |||
5 | obj-$(CONFIG_GENERIC_PHY) += phy-core.o | 5 | obj-$(CONFIG_GENERIC_PHY) += phy-core.o |
6 | obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o | 6 | obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o |
7 | obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o | 7 | obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o |
8 | obj-$(CONFIG_PHY_MVEBU_SATA) += phy-mvebu-sata.o | ||
8 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o | 9 | obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o |
9 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o | 10 | obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o |
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 58e0e9739028..645c867c1257 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c | |||
@@ -94,19 +94,31 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node) | |||
94 | 94 | ||
95 | int phy_pm_runtime_get(struct phy *phy) | 95 | int phy_pm_runtime_get(struct phy *phy) |
96 | { | 96 | { |
97 | int ret; | ||
98 | |||
97 | if (!pm_runtime_enabled(&phy->dev)) | 99 | if (!pm_runtime_enabled(&phy->dev)) |
98 | return -ENOTSUPP; | 100 | return -ENOTSUPP; |
99 | 101 | ||
100 | return pm_runtime_get(&phy->dev); | 102 | ret = pm_runtime_get(&phy->dev); |
103 | if (ret < 0 && ret != -EINPROGRESS) | ||
104 | pm_runtime_put_noidle(&phy->dev); | ||
105 | |||
106 | return ret; | ||
101 | } | 107 | } |
102 | EXPORT_SYMBOL_GPL(phy_pm_runtime_get); | 108 | EXPORT_SYMBOL_GPL(phy_pm_runtime_get); |
103 | 109 | ||
104 | int phy_pm_runtime_get_sync(struct phy *phy) | 110 | int phy_pm_runtime_get_sync(struct phy *phy) |
105 | { | 111 | { |
112 | int ret; | ||
113 | |||
106 | if (!pm_runtime_enabled(&phy->dev)) | 114 | if (!pm_runtime_enabled(&phy->dev)) |
107 | return -ENOTSUPP; | 115 | return -ENOTSUPP; |
108 | 116 | ||
109 | return pm_runtime_get_sync(&phy->dev); | 117 | ret = pm_runtime_get_sync(&phy->dev); |
118 | if (ret < 0) | ||
119 | pm_runtime_put_sync(&phy->dev); | ||
120 | |||
121 | return ret; | ||
110 | } | 122 | } |
111 | EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync); | 123 | EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync); |
112 | 124 | ||
@@ -155,13 +167,14 @@ int phy_init(struct phy *phy) | |||
155 | return ret; | 167 | return ret; |
156 | 168 | ||
157 | mutex_lock(&phy->mutex); | 169 | mutex_lock(&phy->mutex); |
158 | if (phy->init_count++ == 0 && phy->ops->init) { | 170 | if (phy->init_count == 0 && phy->ops->init) { |
159 | ret = phy->ops->init(phy); | 171 | ret = phy->ops->init(phy); |
160 | if (ret < 0) { | 172 | if (ret < 0) { |
161 | dev_err(&phy->dev, "phy init failed --> %d\n", ret); | 173 | dev_err(&phy->dev, "phy init failed --> %d\n", ret); |
162 | goto out; | 174 | goto out; |
163 | } | 175 | } |
164 | } | 176 | } |
177 | ++phy->init_count; | ||
165 | 178 | ||
166 | out: | 179 | out: |
167 | mutex_unlock(&phy->mutex); | 180 | mutex_unlock(&phy->mutex); |
@@ -179,13 +192,14 @@ int phy_exit(struct phy *phy) | |||
179 | return ret; | 192 | return ret; |
180 | 193 | ||
181 | mutex_lock(&phy->mutex); | 194 | mutex_lock(&phy->mutex); |
182 | if (--phy->init_count == 0 && phy->ops->exit) { | 195 | if (phy->init_count == 1 && phy->ops->exit) { |
183 | ret = phy->ops->exit(phy); | 196 | ret = phy->ops->exit(phy); |
184 | if (ret < 0) { | 197 | if (ret < 0) { |
185 | dev_err(&phy->dev, "phy exit failed --> %d\n", ret); | 198 | dev_err(&phy->dev, "phy exit failed --> %d\n", ret); |
186 | goto out; | 199 | goto out; |
187 | } | 200 | } |
188 | } | 201 | } |
202 | --phy->init_count; | ||
189 | 203 | ||
190 | out: | 204 | out: |
191 | mutex_unlock(&phy->mutex); | 205 | mutex_unlock(&phy->mutex); |
@@ -196,23 +210,27 @@ EXPORT_SYMBOL_GPL(phy_exit); | |||
196 | 210 | ||
197 | int phy_power_on(struct phy *phy) | 211 | int phy_power_on(struct phy *phy) |
198 | { | 212 | { |
199 | int ret = -ENOTSUPP; | 213 | int ret; |
200 | 214 | ||
201 | ret = phy_pm_runtime_get_sync(phy); | 215 | ret = phy_pm_runtime_get_sync(phy); |
202 | if (ret < 0 && ret != -ENOTSUPP) | 216 | if (ret < 0 && ret != -ENOTSUPP) |
203 | return ret; | 217 | return ret; |
204 | 218 | ||
205 | mutex_lock(&phy->mutex); | 219 | mutex_lock(&phy->mutex); |
206 | if (phy->power_count++ == 0 && phy->ops->power_on) { | 220 | if (phy->power_count == 0 && phy->ops->power_on) { |
207 | ret = phy->ops->power_on(phy); | 221 | ret = phy->ops->power_on(phy); |
208 | if (ret < 0) { | 222 | if (ret < 0) { |
209 | dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); | 223 | dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); |
210 | goto out; | 224 | goto out; |
211 | } | 225 | } |
212 | } | 226 | } |
227 | ++phy->power_count; | ||
228 | mutex_unlock(&phy->mutex); | ||
229 | return 0; | ||
213 | 230 | ||
214 | out: | 231 | out: |
215 | mutex_unlock(&phy->mutex); | 232 | mutex_unlock(&phy->mutex); |
233 | phy_pm_runtime_put_sync(phy); | ||
216 | 234 | ||
217 | return ret; | 235 | return ret; |
218 | } | 236 | } |
@@ -220,22 +238,22 @@ EXPORT_SYMBOL_GPL(phy_power_on); | |||
220 | 238 | ||
221 | int phy_power_off(struct phy *phy) | 239 | int phy_power_off(struct phy *phy) |
222 | { | 240 | { |
223 | int ret = -ENOTSUPP; | 241 | int ret; |
224 | 242 | ||
225 | mutex_lock(&phy->mutex); | 243 | mutex_lock(&phy->mutex); |
226 | if (--phy->power_count == 0 && phy->ops->power_off) { | 244 | if (phy->power_count == 1 && phy->ops->power_off) { |
227 | ret = phy->ops->power_off(phy); | 245 | ret = phy->ops->power_off(phy); |
228 | if (ret < 0) { | 246 | if (ret < 0) { |
229 | dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); | 247 | dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); |
230 | goto out; | 248 | mutex_unlock(&phy->mutex); |
249 | return ret; | ||
231 | } | 250 | } |
232 | } | 251 | } |
233 | 252 | --phy->power_count; | |
234 | out: | ||
235 | mutex_unlock(&phy->mutex); | 253 | mutex_unlock(&phy->mutex); |
236 | phy_pm_runtime_put(phy); | 254 | phy_pm_runtime_put(phy); |
237 | 255 | ||
238 | return ret; | 256 | return 0; |
239 | } | 257 | } |
240 | EXPORT_SYMBOL_GPL(phy_power_off); | 258 | EXPORT_SYMBOL_GPL(phy_power_off); |
241 | 259 | ||
@@ -360,7 +378,7 @@ EXPORT_SYMBOL_GPL(of_phy_simple_xlate); | |||
360 | struct phy *phy_get(struct device *dev, const char *string) | 378 | struct phy *phy_get(struct device *dev, const char *string) |
361 | { | 379 | { |
362 | int index = 0; | 380 | int index = 0; |
363 | struct phy *phy = NULL; | 381 | struct phy *phy; |
364 | 382 | ||
365 | if (string == NULL) { | 383 | if (string == NULL) { |
366 | dev_WARN(dev, "missing string\n"); | 384 | dev_WARN(dev, "missing string\n"); |
diff --git a/drivers/phy/phy-mvebu-sata.c b/drivers/phy/phy-mvebu-sata.c new file mode 100644 index 000000000000..d43786f62437 --- /dev/null +++ b/drivers/phy/phy-mvebu-sata.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | * phy-mvebu-sata.c: SATA Phy driver for the Marvell mvebu SoCs. | ||
3 | * | ||
4 | * Copyright (C) 2013 Andrew Lunn <andrew@lunn.ch> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/clk.h> | ||
15 | #include <linux/phy/phy.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | |||
19 | struct priv { | ||
20 | struct clk *clk; | ||
21 | void __iomem *base; | ||
22 | }; | ||
23 | |||
24 | #define SATA_PHY_MODE_2 0x0330 | ||
25 | #define MODE_2_FORCE_PU_TX BIT(0) | ||
26 | #define MODE_2_FORCE_PU_RX BIT(1) | ||
27 | #define MODE_2_PU_PLL BIT(2) | ||
28 | #define MODE_2_PU_IVREF BIT(3) | ||
29 | #define SATA_IF_CTRL 0x0050 | ||
30 | #define CTRL_PHY_SHUTDOWN BIT(9) | ||
31 | |||
32 | static int phy_mvebu_sata_power_on(struct phy *phy) | ||
33 | { | ||
34 | struct priv *priv = phy_get_drvdata(phy); | ||
35 | u32 reg; | ||
36 | |||
37 | clk_prepare_enable(priv->clk); | ||
38 | |||
39 | /* Enable PLL and IVREF */ | ||
40 | reg = readl(priv->base + SATA_PHY_MODE_2); | ||
41 | reg |= (MODE_2_FORCE_PU_TX | MODE_2_FORCE_PU_RX | | ||
42 | MODE_2_PU_PLL | MODE_2_PU_IVREF); | ||
43 | writel(reg , priv->base + SATA_PHY_MODE_2); | ||
44 | |||
45 | /* Enable PHY */ | ||
46 | reg = readl(priv->base + SATA_IF_CTRL); | ||
47 | reg &= ~CTRL_PHY_SHUTDOWN; | ||
48 | writel(reg, priv->base + SATA_IF_CTRL); | ||
49 | |||
50 | clk_disable_unprepare(priv->clk); | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static int phy_mvebu_sata_power_off(struct phy *phy) | ||
56 | { | ||
57 | struct priv *priv = phy_get_drvdata(phy); | ||
58 | u32 reg; | ||
59 | |||
60 | clk_prepare_enable(priv->clk); | ||
61 | |||
62 | /* Disable PLL and IVREF */ | ||
63 | reg = readl(priv->base + SATA_PHY_MODE_2); | ||
64 | reg &= ~(MODE_2_FORCE_PU_TX | MODE_2_FORCE_PU_RX | | ||
65 | MODE_2_PU_PLL | MODE_2_PU_IVREF); | ||
66 | writel(reg, priv->base + SATA_PHY_MODE_2); | ||
67 | |||
68 | /* Disable PHY */ | ||
69 | reg = readl(priv->base + SATA_IF_CTRL); | ||
70 | reg |= CTRL_PHY_SHUTDOWN; | ||
71 | writel(reg, priv->base + SATA_IF_CTRL); | ||
72 | |||
73 | clk_disable_unprepare(priv->clk); | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static struct phy_ops phy_mvebu_sata_ops = { | ||
79 | .power_on = phy_mvebu_sata_power_on, | ||
80 | .power_off = phy_mvebu_sata_power_off, | ||
81 | .owner = THIS_MODULE, | ||
82 | }; | ||
83 | |||
84 | static int phy_mvebu_sata_probe(struct platform_device *pdev) | ||
85 | { | ||
86 | struct phy_provider *phy_provider; | ||
87 | struct resource *res; | ||
88 | struct priv *priv; | ||
89 | struct phy *phy; | ||
90 | |||
91 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
92 | |||
93 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
94 | priv->base = devm_ioremap_resource(&pdev->dev, res); | ||
95 | if (IS_ERR(priv->base)) | ||
96 | return PTR_ERR(priv->base); | ||
97 | |||
98 | priv->clk = devm_clk_get(&pdev->dev, "sata"); | ||
99 | if (IS_ERR(priv->clk)) | ||
100 | return PTR_ERR(priv->clk); | ||
101 | |||
102 | phy_provider = devm_of_phy_provider_register(&pdev->dev, | ||
103 | of_phy_simple_xlate); | ||
104 | if (IS_ERR(phy_provider)) | ||
105 | return PTR_ERR(phy_provider); | ||
106 | |||
107 | phy = devm_phy_create(&pdev->dev, &phy_mvebu_sata_ops, NULL); | ||
108 | if (IS_ERR(phy)) | ||
109 | return PTR_ERR(phy); | ||
110 | |||
111 | phy_set_drvdata(phy, priv); | ||
112 | |||
113 | /* The boot loader may of left it on. Turn it off. */ | ||
114 | phy_mvebu_sata_power_off(phy); | ||
115 | |||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static const struct of_device_id phy_mvebu_sata_of_match[] = { | ||
120 | { .compatible = "marvell,mvebu-sata-phy" }, | ||
121 | { }, | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(of, phy_mvebu_sata_of_match); | ||
124 | |||
125 | static struct platform_driver phy_mvebu_sata_driver = { | ||
126 | .probe = phy_mvebu_sata_probe, | ||
127 | .driver = { | ||
128 | .name = "phy-mvebu-sata", | ||
129 | .owner = THIS_MODULE, | ||
130 | .of_match_table = phy_mvebu_sata_of_match, | ||
131 | } | ||
132 | }; | ||
133 | module_platform_driver(phy_mvebu_sata_driver); | ||
134 | |||
135 | MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>"); | ||
136 | MODULE_DESCRIPTION("Marvell MVEBU SATA PHY driver"); | ||
137 | MODULE_LICENSE("GPL v2"); | ||