diff options
author | Ivan T. Ivanov <iivanov@mm-sol.com> | 2014-04-28 09:34:06 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-04-30 12:28:04 -0400 |
commit | 37cfdaf782590e277d9352626dba4496734e0375 (patch) | |
tree | 02efa8b6f2a7b42b48ad1816eeedc0208655d7db | |
parent | 0d092fdb8c7a1b874d5c1b56f14d97b62df13186 (diff) |
usb: phy: msm: Move global regulators variables to driver state
Eliminating global variables allows driver to handle multiple
device instances.
Signed-off-by: Ivan T. Ivanov <iivanov@mm-sol.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/phy/phy-msm-usb.c | 82 | ||||
-rw-r--r-- | include/linux/usb/msm_hsusb.h | 3 |
2 files changed, 42 insertions, 43 deletions
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 5b37b81f2ef6..878f67d29ed5 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c | |||
@@ -58,47 +58,43 @@ | |||
58 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ | 58 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ |
59 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ | 59 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
60 | 60 | ||
61 | static struct regulator *hsusb_3p3; | ||
62 | static struct regulator *hsusb_1p8; | ||
63 | static struct regulator *hsusb_vddcx; | ||
64 | |||
65 | static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) | 61 | static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) |
66 | { | 62 | { |
67 | int ret = 0; | 63 | int ret = 0; |
68 | 64 | ||
69 | if (init) { | 65 | if (init) { |
70 | hsusb_vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX"); | 66 | motg->vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX"); |
71 | if (IS_ERR(hsusb_vddcx)) { | 67 | if (IS_ERR(motg->vddcx)) { |
72 | dev_err(motg->phy.dev, "unable to get hsusb vddcx\n"); | 68 | dev_err(motg->phy.dev, "unable to get hsusb vddcx\n"); |
73 | return PTR_ERR(hsusb_vddcx); | 69 | return PTR_ERR(motg->vddcx); |
74 | } | 70 | } |
75 | 71 | ||
76 | ret = regulator_set_voltage(hsusb_vddcx, | 72 | ret = regulator_set_voltage(motg->vddcx, |
77 | USB_PHY_VDD_DIG_VOL_MIN, | 73 | USB_PHY_VDD_DIG_VOL_MIN, |
78 | USB_PHY_VDD_DIG_VOL_MAX); | 74 | USB_PHY_VDD_DIG_VOL_MAX); |
79 | if (ret) { | 75 | if (ret) { |
80 | dev_err(motg->phy.dev, "unable to set the voltage " | 76 | dev_err(motg->phy.dev, "unable to set the voltage " |
81 | "for hsusb vddcx\n"); | 77 | "for hsusb vddcx\n"); |
82 | regulator_put(hsusb_vddcx); | 78 | regulator_put(motg->vddcx); |
83 | return ret; | 79 | return ret; |
84 | } | 80 | } |
85 | 81 | ||
86 | ret = regulator_enable(hsusb_vddcx); | 82 | ret = regulator_enable(motg->vddcx); |
87 | if (ret) { | 83 | if (ret) { |
88 | dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); | 84 | dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); |
89 | regulator_put(hsusb_vddcx); | 85 | regulator_put(motg->vddcx); |
90 | } | 86 | } |
91 | } else { | 87 | } else { |
92 | ret = regulator_set_voltage(hsusb_vddcx, 0, | 88 | ret = regulator_set_voltage(motg->vddcx, 0, |
93 | USB_PHY_VDD_DIG_VOL_MAX); | 89 | USB_PHY_VDD_DIG_VOL_MAX); |
94 | if (ret) | 90 | if (ret) |
95 | dev_err(motg->phy.dev, "unable to set the voltage " | 91 | dev_err(motg->phy.dev, "unable to set the voltage " |
96 | "for hsusb vddcx\n"); | 92 | "for hsusb vddcx\n"); |
97 | ret = regulator_disable(hsusb_vddcx); | 93 | ret = regulator_disable(motg->vddcx); |
98 | if (ret) | 94 | if (ret) |
99 | dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n"); | 95 | dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n"); |
100 | 96 | ||
101 | regulator_put(hsusb_vddcx); | 97 | regulator_put(motg->vddcx); |
102 | } | 98 | } |
103 | 99 | ||
104 | return ret; | 100 | return ret; |
@@ -109,38 +105,38 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) | |||
109 | int rc = 0; | 105 | int rc = 0; |
110 | 106 | ||
111 | if (init) { | 107 | if (init) { |
112 | hsusb_3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3"); | 108 | motg->v3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3"); |
113 | if (IS_ERR(hsusb_3p3)) { | 109 | if (IS_ERR(motg->v3p3)) { |
114 | dev_err(motg->phy.dev, "unable to get hsusb 3p3\n"); | 110 | dev_err(motg->phy.dev, "unable to get hsusb 3p3\n"); |
115 | return PTR_ERR(hsusb_3p3); | 111 | return PTR_ERR(motg->v3p3); |
116 | } | 112 | } |
117 | 113 | ||
118 | rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN, | 114 | rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN, |
119 | USB_PHY_3P3_VOL_MAX); | 115 | USB_PHY_3P3_VOL_MAX); |
120 | if (rc) { | 116 | if (rc) { |
121 | dev_err(motg->phy.dev, "unable to set voltage level " | 117 | dev_err(motg->phy.dev, "unable to set voltage level " |
122 | "for hsusb 3p3\n"); | 118 | "for hsusb 3p3\n"); |
123 | goto put_3p3; | 119 | goto put_3p3; |
124 | } | 120 | } |
125 | rc = regulator_enable(hsusb_3p3); | 121 | rc = regulator_enable(motg->v3p3); |
126 | if (rc) { | 122 | if (rc) { |
127 | dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n"); | 123 | dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n"); |
128 | goto put_3p3; | 124 | goto put_3p3; |
129 | } | 125 | } |
130 | hsusb_1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8"); | 126 | motg->v1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8"); |
131 | if (IS_ERR(hsusb_1p8)) { | 127 | if (IS_ERR(motg->v1p8)) { |
132 | dev_err(motg->phy.dev, "unable to get hsusb 1p8\n"); | 128 | dev_err(motg->phy.dev, "unable to get hsusb 1p8\n"); |
133 | rc = PTR_ERR(hsusb_1p8); | 129 | rc = PTR_ERR(motg->v1p8); |
134 | goto disable_3p3; | 130 | goto disable_3p3; |
135 | } | 131 | } |
136 | rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN, | 132 | rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN, |
137 | USB_PHY_1P8_VOL_MAX); | 133 | USB_PHY_1P8_VOL_MAX); |
138 | if (rc) { | 134 | if (rc) { |
139 | dev_err(motg->phy.dev, "unable to set voltage level " | 135 | dev_err(motg->phy.dev, "unable to set voltage level " |
140 | "for hsusb 1p8\n"); | 136 | "for hsusb 1p8\n"); |
141 | goto put_1p8; | 137 | goto put_1p8; |
142 | } | 138 | } |
143 | rc = regulator_enable(hsusb_1p8); | 139 | rc = regulator_enable(motg->v1p8); |
144 | if (rc) { | 140 | if (rc) { |
145 | dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n"); | 141 | dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n"); |
146 | goto put_1p8; | 142 | goto put_1p8; |
@@ -149,54 +145,54 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) | |||
149 | return 0; | 145 | return 0; |
150 | } | 146 | } |
151 | 147 | ||
152 | regulator_disable(hsusb_1p8); | 148 | regulator_disable(motg->v1p8); |
153 | put_1p8: | 149 | put_1p8: |
154 | regulator_put(hsusb_1p8); | 150 | regulator_put(motg->v1p8); |
155 | disable_3p3: | 151 | disable_3p3: |
156 | regulator_disable(hsusb_3p3); | 152 | regulator_disable(motg->v3p3); |
157 | put_3p3: | 153 | put_3p3: |
158 | regulator_put(hsusb_3p3); | 154 | regulator_put(motg->v3p3); |
159 | return rc; | 155 | return rc; |
160 | } | 156 | } |
161 | 157 | ||
162 | static int msm_hsusb_ldo_set_mode(int on) | 158 | static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, int on) |
163 | { | 159 | { |
164 | int ret = 0; | 160 | int ret = 0; |
165 | 161 | ||
166 | if (!hsusb_1p8 || IS_ERR(hsusb_1p8)) { | 162 | if (!motg->v1p8 || IS_ERR(motg->v1p8)) { |
167 | pr_err("%s: HSUSB_1p8 is not initialized\n", __func__); | 163 | pr_err("%s: HSUSB_1p8 is not initialized\n", __func__); |
168 | return -ENODEV; | 164 | return -ENODEV; |
169 | } | 165 | } |
170 | 166 | ||
171 | if (!hsusb_3p3 || IS_ERR(hsusb_3p3)) { | 167 | if (!motg->v3p3 || IS_ERR(motg->v3p3)) { |
172 | pr_err("%s: HSUSB_3p3 is not initialized\n", __func__); | 168 | pr_err("%s: HSUSB_3p3 is not initialized\n", __func__); |
173 | return -ENODEV; | 169 | return -ENODEV; |
174 | } | 170 | } |
175 | 171 | ||
176 | if (on) { | 172 | if (on) { |
177 | ret = regulator_set_optimum_mode(hsusb_1p8, | 173 | ret = regulator_set_optimum_mode(motg->v1p8, |
178 | USB_PHY_1P8_HPM_LOAD); | 174 | USB_PHY_1P8_HPM_LOAD); |
179 | if (ret < 0) { | 175 | if (ret < 0) { |
180 | pr_err("%s: Unable to set HPM of the regulator " | 176 | pr_err("%s: Unable to set HPM of the regulator " |
181 | "HSUSB_1p8\n", __func__); | 177 | "HSUSB_1p8\n", __func__); |
182 | return ret; | 178 | return ret; |
183 | } | 179 | } |
184 | ret = regulator_set_optimum_mode(hsusb_3p3, | 180 | ret = regulator_set_optimum_mode(motg->v3p3, |
185 | USB_PHY_3P3_HPM_LOAD); | 181 | USB_PHY_3P3_HPM_LOAD); |
186 | if (ret < 0) { | 182 | if (ret < 0) { |
187 | pr_err("%s: Unable to set HPM of the regulator " | 183 | pr_err("%s: Unable to set HPM of the regulator " |
188 | "HSUSB_3p3\n", __func__); | 184 | "HSUSB_3p3\n", __func__); |
189 | regulator_set_optimum_mode(hsusb_1p8, | 185 | regulator_set_optimum_mode(motg->v1p8, |
190 | USB_PHY_1P8_LPM_LOAD); | 186 | USB_PHY_1P8_LPM_LOAD); |
191 | return ret; | 187 | return ret; |
192 | } | 188 | } |
193 | } else { | 189 | } else { |
194 | ret = regulator_set_optimum_mode(hsusb_1p8, | 190 | ret = regulator_set_optimum_mode(motg->v1p8, |
195 | USB_PHY_1P8_LPM_LOAD); | 191 | USB_PHY_1P8_LPM_LOAD); |
196 | if (ret < 0) | 192 | if (ret < 0) |
197 | pr_err("%s: Unable to set LPM of the regulator " | 193 | pr_err("%s: Unable to set LPM of the regulator " |
198 | "HSUSB_1p8\n", __func__); | 194 | "HSUSB_1p8\n", __func__); |
199 | ret = regulator_set_optimum_mode(hsusb_3p3, | 195 | ret = regulator_set_optimum_mode(motg->v3p3, |
200 | USB_PHY_3P3_LPM_LOAD); | 196 | USB_PHY_3P3_LPM_LOAD); |
201 | if (ret < 0) | 197 | if (ret < 0) |
202 | pr_err("%s: Unable to set LPM of the regulator " | 198 | pr_err("%s: Unable to set LPM of the regulator " |
@@ -417,7 +413,7 @@ static int msm_otg_reset(struct usb_phy *phy) | |||
417 | #ifdef CONFIG_PM | 413 | #ifdef CONFIG_PM |
418 | 414 | ||
419 | #define USB_PHY_SUSP_DIG_VOL 500000 | 415 | #define USB_PHY_SUSP_DIG_VOL 500000 |
420 | static int msm_hsusb_config_vddcx(int high) | 416 | static int msm_hsusb_config_vddcx(struct msm_otg *motg, int high) |
421 | { | 417 | { |
422 | int max_vol = USB_PHY_VDD_DIG_VOL_MAX; | 418 | int max_vol = USB_PHY_VDD_DIG_VOL_MAX; |
423 | int min_vol; | 419 | int min_vol; |
@@ -428,7 +424,7 @@ static int msm_hsusb_config_vddcx(int high) | |||
428 | else | 424 | else |
429 | min_vol = USB_PHY_SUSP_DIG_VOL; | 425 | min_vol = USB_PHY_SUSP_DIG_VOL; |
430 | 426 | ||
431 | ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol); | 427 | ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol); |
432 | if (ret) { | 428 | if (ret) { |
433 | pr_err("%s: unable to set the voltage for regulator " | 429 | pr_err("%s: unable to set the voltage for regulator " |
434 | "HSUSB_VDDCX\n", __func__); | 430 | "HSUSB_VDDCX\n", __func__); |
@@ -518,8 +514,8 @@ static int msm_otg_suspend(struct msm_otg *motg) | |||
518 | 514 | ||
519 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && | 515 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
520 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { | 516 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
521 | msm_hsusb_ldo_set_mode(0); | 517 | msm_hsusb_ldo_set_mode(motg, 0); |
522 | msm_hsusb_config_vddcx(0); | 518 | msm_hsusb_config_vddcx(motg, 0); |
523 | } | 519 | } |
524 | 520 | ||
525 | if (device_may_wakeup(phy->dev)) | 521 | if (device_may_wakeup(phy->dev)) |
@@ -555,8 +551,8 @@ static int msm_otg_resume(struct msm_otg *motg) | |||
555 | 551 | ||
556 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && | 552 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
557 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { | 553 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
558 | msm_hsusb_ldo_set_mode(1); | 554 | msm_hsusb_ldo_set_mode(motg, 1); |
559 | msm_hsusb_config_vddcx(1); | 555 | msm_hsusb_config_vddcx(motg, 1); |
560 | writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL); | 556 | writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL); |
561 | } | 557 | } |
562 | 558 | ||
@@ -1521,7 +1517,7 @@ static int __init msm_otg_probe(struct platform_device *pdev) | |||
1521 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); | 1517 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
1522 | goto vddcx_exit; | 1518 | goto vddcx_exit; |
1523 | } | 1519 | } |
1524 | ret = msm_hsusb_ldo_set_mode(1); | 1520 | ret = msm_hsusb_ldo_set_mode(motg, 1); |
1525 | if (ret) { | 1521 | if (ret) { |
1526 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); | 1522 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
1527 | goto ldo_exit; | 1523 | goto ldo_exit; |
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h index 32754835a39b..8705b0164684 100644 --- a/include/linux/usb/msm_hsusb.h +++ b/include/linux/usb/msm_hsusb.h | |||
@@ -183,6 +183,9 @@ struct msm_otg { | |||
183 | enum usb_chg_state chg_state; | 183 | enum usb_chg_state chg_state; |
184 | enum usb_chg_type chg_type; | 184 | enum usb_chg_type chg_type; |
185 | u8 dcd_retries; | 185 | u8 dcd_retries; |
186 | struct regulator *v3p3; | ||
187 | struct regulator *v1p8; | ||
188 | struct regulator *vddcx; | ||
186 | }; | 189 | }; |
187 | 190 | ||
188 | #endif | 191 | #endif |