forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/usb/phy/phy-mv-usb.c
....@@ -8,6 +8,7 @@
88 #include <linux/module.h>
99 #include <linux/kernel.h>
1010 #include <linux/io.h>
11
+#include <linux/iopoll.h>
1112 #include <linux/uaccess.h>
1213 #include <linux/device.h>
1314 #include <linux/proc_fs.h>
....@@ -135,8 +136,8 @@
135136
136137 static int mv_otg_reset(struct mv_otg *mvotg)
137138 {
138
- unsigned int loops;
139139 u32 tmp;
140
+ int ret;
140141
141142 /* Stop the controller */
142143 tmp = readl(&mvotg->op_regs->usbcmd);
....@@ -146,15 +147,12 @@
146147 /* Reset the controller to get default values */
147148 writel(USBCMD_CTRL_RESET, &mvotg->op_regs->usbcmd);
148149
149
- loops = 500;
150
- while (readl(&mvotg->op_regs->usbcmd) & USBCMD_CTRL_RESET) {
151
- if (loops == 0) {
152
- dev_err(&mvotg->pdev->dev,
153
- "Wait for RESET completed TIMEOUT\n");
154
- return -ETIMEDOUT;
155
- }
156
- loops--;
157
- udelay(20);
150
+ ret = readl_poll_timeout_atomic(&mvotg->op_regs->usbcmd, tmp,
151
+ (tmp & USBCMD_CTRL_RESET), 10, 10000);
152
+ if (ret < 0) {
153
+ dev_err(&mvotg->pdev->dev,
154
+ "Wait for RESET completed TIMEOUT\n");
155
+ return ret;
158156 }
159157
160158 writel(0x0, &mvotg->op_regs->usbintr);
....@@ -334,7 +332,7 @@
334332 switch (old_state) {
335333 case OTG_STATE_UNDEFINED:
336334 mvotg->phy.otg->state = OTG_STATE_B_IDLE;
337
- /* FALL THROUGH */
335
+ fallthrough;
338336 case OTG_STATE_B_IDLE:
339337 if (otg_ctrl->id == 0)
340338 mvotg->phy.otg->state = OTG_STATE_A_IDLE;
....@@ -401,7 +399,6 @@
401399 static void mv_otg_work(struct work_struct *work)
402400 {
403401 struct mv_otg *mvotg;
404
- struct usb_phy *phy;
405402 struct usb_otg *otg;
406403 int old_state;
407404
....@@ -409,7 +406,6 @@
409406
410407 run:
411408 /* work queue is single thread, or we need spin_lock to protect */
412
- phy = &mvotg->phy;
413409 otg = mvotg->phy.otg;
414410 old_state = otg->state;
415411
....@@ -643,11 +639,14 @@
643639 .attrs = inputs_attrs,
644640 };
645641
642
+static const struct attribute_group *mv_otg_groups[] = {
643
+ &inputs_attr_group,
644
+ NULL,
645
+};
646
+
646647 static int mv_otg_remove(struct platform_device *pdev)
647648 {
648649 struct mv_otg *mvotg = platform_get_drvdata(pdev);
649
-
650
- sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group);
651650
652651 if (mvotg->qwork) {
653652 flush_workqueue(mvotg->qwork);
....@@ -811,13 +810,6 @@
811810 goto err_disable_clk;
812811 }
813812
814
- retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group);
815
- if (retval < 0) {
816
- dev_dbg(&pdev->dev,
817
- "Can't register sysfs attr group: %d\n", retval);
818
- goto err_remove_phy;
819
- }
820
-
821813 spin_lock_init(&mvotg->wq_lock);
822814 if (spin_trylock(&mvotg->wq_lock)) {
823815 mv_otg_run_state_machine(mvotg, 2 * HZ);
....@@ -830,8 +822,6 @@
830822
831823 return 0;
832824
833
-err_remove_phy:
834
- usb_remove_phy(&mvotg->phy);
835825 err_disable_clk:
836826 mv_otg_disable_internal(mvotg);
837827 err_destroy_workqueue:
....@@ -885,6 +875,7 @@
885875 .remove = mv_otg_remove,
886876 .driver = {
887877 .name = driver_name,
878
+ .dev_groups = mv_otg_groups,
888879 },
889880 #ifdef CONFIG_PM
890881 .suspend = mv_otg_suspend,