.. | .. |
---|
8 | 8 | #include <linux/module.h> |
---|
9 | 9 | #include <linux/kernel.h> |
---|
10 | 10 | #include <linux/io.h> |
---|
| 11 | +#include <linux/iopoll.h> |
---|
11 | 12 | #include <linux/uaccess.h> |
---|
12 | 13 | #include <linux/device.h> |
---|
13 | 14 | #include <linux/proc_fs.h> |
---|
.. | .. |
---|
135 | 136 | |
---|
136 | 137 | static int mv_otg_reset(struct mv_otg *mvotg) |
---|
137 | 138 | { |
---|
138 | | - unsigned int loops; |
---|
139 | 139 | u32 tmp; |
---|
| 140 | + int ret; |
---|
140 | 141 | |
---|
141 | 142 | /* Stop the controller */ |
---|
142 | 143 | tmp = readl(&mvotg->op_regs->usbcmd); |
---|
.. | .. |
---|
146 | 147 | /* Reset the controller to get default values */ |
---|
147 | 148 | writel(USBCMD_CTRL_RESET, &mvotg->op_regs->usbcmd); |
---|
148 | 149 | |
---|
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; |
---|
158 | 156 | } |
---|
159 | 157 | |
---|
160 | 158 | writel(0x0, &mvotg->op_regs->usbintr); |
---|
.. | .. |
---|
334 | 332 | switch (old_state) { |
---|
335 | 333 | case OTG_STATE_UNDEFINED: |
---|
336 | 334 | mvotg->phy.otg->state = OTG_STATE_B_IDLE; |
---|
337 | | - /* FALL THROUGH */ |
---|
| 335 | + fallthrough; |
---|
338 | 336 | case OTG_STATE_B_IDLE: |
---|
339 | 337 | if (otg_ctrl->id == 0) |
---|
340 | 338 | mvotg->phy.otg->state = OTG_STATE_A_IDLE; |
---|
.. | .. |
---|
401 | 399 | static void mv_otg_work(struct work_struct *work) |
---|
402 | 400 | { |
---|
403 | 401 | struct mv_otg *mvotg; |
---|
404 | | - struct usb_phy *phy; |
---|
405 | 402 | struct usb_otg *otg; |
---|
406 | 403 | int old_state; |
---|
407 | 404 | |
---|
.. | .. |
---|
409 | 406 | |
---|
410 | 407 | run: |
---|
411 | 408 | /* work queue is single thread, or we need spin_lock to protect */ |
---|
412 | | - phy = &mvotg->phy; |
---|
413 | 409 | otg = mvotg->phy.otg; |
---|
414 | 410 | old_state = otg->state; |
---|
415 | 411 | |
---|
.. | .. |
---|
643 | 639 | .attrs = inputs_attrs, |
---|
644 | 640 | }; |
---|
645 | 641 | |
---|
| 642 | +static const struct attribute_group *mv_otg_groups[] = { |
---|
| 643 | + &inputs_attr_group, |
---|
| 644 | + NULL, |
---|
| 645 | +}; |
---|
| 646 | + |
---|
646 | 647 | static int mv_otg_remove(struct platform_device *pdev) |
---|
647 | 648 | { |
---|
648 | 649 | struct mv_otg *mvotg = platform_get_drvdata(pdev); |
---|
649 | | - |
---|
650 | | - sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group); |
---|
651 | 650 | |
---|
652 | 651 | if (mvotg->qwork) { |
---|
653 | 652 | flush_workqueue(mvotg->qwork); |
---|
.. | .. |
---|
811 | 810 | goto err_disable_clk; |
---|
812 | 811 | } |
---|
813 | 812 | |
---|
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 | | - |
---|
821 | 813 | spin_lock_init(&mvotg->wq_lock); |
---|
822 | 814 | if (spin_trylock(&mvotg->wq_lock)) { |
---|
823 | 815 | mv_otg_run_state_machine(mvotg, 2 * HZ); |
---|
.. | .. |
---|
830 | 822 | |
---|
831 | 823 | return 0; |
---|
832 | 824 | |
---|
833 | | -err_remove_phy: |
---|
834 | | - usb_remove_phy(&mvotg->phy); |
---|
835 | 825 | err_disable_clk: |
---|
836 | 826 | mv_otg_disable_internal(mvotg); |
---|
837 | 827 | err_destroy_workqueue: |
---|
.. | .. |
---|
885 | 875 | .remove = mv_otg_remove, |
---|
886 | 876 | .driver = { |
---|
887 | 877 | .name = driver_name, |
---|
| 878 | + .dev_groups = mv_otg_groups, |
---|
888 | 879 | }, |
---|
889 | 880 | #ifdef CONFIG_PM |
---|
890 | 881 | .suspend = mv_otg_suspend, |
---|