hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/usb/mtu3/mtu3_plat.c
....@@ -16,6 +16,7 @@
1616
1717 #include "mtu3.h"
1818 #include "mtu3_dr.h"
19
+#include "mtu3_debug.h"
1920
2021 /* u2-port0 should be powered on and enabled; */
2122 int ssusb_check_clocks(struct ssusb_mtk *ssusb, u32 ex_clks)
....@@ -200,19 +201,14 @@
200201 mtu3_setbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL0, SSUSB_IP_SW_RST);
201202 udelay(1);
202203 mtu3_clrbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL0, SSUSB_IP_SW_RST);
203
-}
204204
205
-/* ignore the error if the clock does not exist */
206
-static struct clk *get_optional_clk(struct device *dev, const char *id)
207
-{
208
- struct clk *opt_clk;
209
-
210
- opt_clk = devm_clk_get(dev, id);
211
- /* ignore error number except EPROBE_DEFER */
212
- if (IS_ERR(opt_clk) && (PTR_ERR(opt_clk) != -EPROBE_DEFER))
213
- opt_clk = NULL;
214
-
215
- return opt_clk;
205
+ /*
206
+ * device ip may be powered on in firmware/BROM stage before entering
207
+ * kernel stage;
208
+ * power down device ip, otherwise ip-sleep will fail when working as
209
+ * host only mode
210
+ */
211
+ mtu3_setbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN);
216212 }
217213
218214 static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb)
....@@ -220,12 +216,10 @@
220216 struct device_node *node = pdev->dev.of_node;
221217 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
222218 struct device *dev = &pdev->dev;
223
- struct regulator *vbus;
224
- struct resource *res;
225219 int i;
226220 int ret;
227221
228
- ssusb->vusb33 = devm_regulator_get(&pdev->dev, "vusb33");
222
+ ssusb->vusb33 = devm_regulator_get(dev, "vusb33");
229223 if (IS_ERR(ssusb->vusb33)) {
230224 dev_err(dev, "failed to get vusb33\n");
231225 return PTR_ERR(ssusb->vusb33);
....@@ -237,15 +231,15 @@
237231 return PTR_ERR(ssusb->sys_clk);
238232 }
239233
240
- ssusb->ref_clk = get_optional_clk(dev, "ref_ck");
234
+ ssusb->ref_clk = devm_clk_get_optional(dev, "ref_ck");
241235 if (IS_ERR(ssusb->ref_clk))
242236 return PTR_ERR(ssusb->ref_clk);
243237
244
- ssusb->mcu_clk = get_optional_clk(dev, "mcu_ck");
238
+ ssusb->mcu_clk = devm_clk_get_optional(dev, "mcu_ck");
245239 if (IS_ERR(ssusb->mcu_clk))
246240 return PTR_ERR(ssusb->mcu_clk);
247241
248
- ssusb->dma_clk = get_optional_clk(dev, "dma_ck");
242
+ ssusb->dma_clk = devm_clk_get_optional(dev, "dma_ck");
249243 if (IS_ERR(ssusb->dma_clk))
250244 return PTR_ERR(ssusb->dma_clk);
251245
....@@ -268,8 +262,7 @@
268262 }
269263 }
270264
271
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ippc");
272
- ssusb->ippc_base = devm_ioremap_resource(dev, res);
265
+ ssusb->ippc_base = devm_platform_ioremap_resource_byname(pdev, "ippc");
273266 if (IS_ERR(ssusb->ippc_base))
274267 return PTR_ERR(ssusb->ippc_base);
275268
....@@ -278,7 +271,7 @@
278271 ssusb->dr_mode = USB_DR_MODE_OTG;
279272
280273 if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL)
281
- return 0;
274
+ goto out;
282275
283276 /* if host role is supported */
284277 ret = ssusb_wakeup_of_property_parse(ssusb, node);
....@@ -291,22 +284,22 @@
291284 of_property_read_u32(node, "mediatek,u3p-dis-msk",
292285 &ssusb->u3p_dis_msk);
293286
294
- vbus = devm_regulator_get(&pdev->dev, "vbus");
295
- if (IS_ERR(vbus)) {
287
+ otg_sx->vbus = devm_regulator_get(dev, "vbus");
288
+ if (IS_ERR(otg_sx->vbus)) {
296289 dev_err(dev, "failed to get vbus\n");
297
- return PTR_ERR(vbus);
290
+ return PTR_ERR(otg_sx->vbus);
298291 }
299
- otg_sx->vbus = vbus;
300292
301293 if (ssusb->dr_mode == USB_DR_MODE_HOST)
302
- return 0;
294
+ goto out;
303295
304296 /* if dual-role mode is supported */
305297 otg_sx->is_u3_drd = of_property_read_bool(node, "mediatek,usb3-drd");
306298 otg_sx->manual_drd_enabled =
307299 of_property_read_bool(node, "enable-manual-drd");
300
+ otg_sx->role_sw_used = of_property_read_bool(node, "usb-role-switch");
308301
309
- if (of_property_read_bool(node, "extcon")) {
302
+ if (!otg_sx->role_sw_used && of_property_read_bool(node, "extcon")) {
310303 otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0);
311304 if (IS_ERR(otg_sx->edev)) {
312305 dev_err(ssusb->dev, "couldn't get extcon device\n");
....@@ -314,6 +307,7 @@
314307 }
315308 }
316309
310
+out:
317311 dev_info(dev, "dr_mode: %d, is_u3_dr: %d, u3p_dis_msk: %x, drd: %s\n",
318312 ssusb->dr_mode, otg_sx->is_u3_drd, ssusb->u3p_dis_msk,
319313 otg_sx->manual_drd_enabled ? "manual" : "auto");
....@@ -345,6 +339,8 @@
345339 ret = get_ssusb_rscs(pdev, ssusb);
346340 if (ret)
347341 return ret;
342
+
343
+ ssusb_debugfs_create_root(ssusb);
348344
349345 /* enable power domain */
350346 pm_runtime_enable(dev);
....@@ -393,7 +389,11 @@
393389 goto gadget_exit;
394390 }
395391
396
- ssusb_otg_switch_init(ssusb);
392
+ ret = ssusb_otg_switch_init(ssusb);
393
+ if (ret) {
394
+ dev_err(dev, "failed to initialize switch\n");
395
+ goto host_exit;
396
+ }
397397 break;
398398 default:
399399 dev_err(dev, "unsupported mode: %d\n", ssusb->dr_mode);
....@@ -403,6 +403,8 @@
403403
404404 return 0;
405405
406
+host_exit:
407
+ ssusb_host_exit(ssusb);
406408 gadget_exit:
407409 ssusb_gadget_exit(ssusb);
408410 comm_exit:
....@@ -410,6 +412,7 @@
410412 comm_init_err:
411413 pm_runtime_put_sync(dev);
412414 pm_runtime_disable(dev);
415
+ ssusb_debugfs_remove_root(ssusb);
413416
414417 return ret;
415418 }
....@@ -437,6 +440,7 @@
437440 ssusb_rscs_exit(ssusb);
438441 pm_runtime_put_sync(&pdev->dev);
439442 pm_runtime_disable(&pdev->dev);
443
+ ssusb_debugfs_remove_root(ssusb);
440444
441445 return 0;
442446 }