diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-06-06 02:14:12 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-06-06 02:14:12 +0300 |
commit | 07c4dd3435aa387d3b58f4e941dc516513f14507 (patch) | |
tree | 26ebc60562ba573ec499f850c53ffd48f2bfdf72 /drivers/usb/mtu3 | |
parent | f60342fac9fae20ada2cd5faadbc2a1337cae03f (diff) | |
parent | c2ef60fea2dc7f903450926aee1f9c282ea529ca (diff) | |
download | linux-07c4dd3435aa387d3b58f4e941dc516513f14507.tar.xz |
Merge tag 'usb-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB and PHY updates from Greg KH:
"Here is the big USB pull request for 4.18-rc1.
Lots of stuff here, the highlights are:
- phy driver updates and new additions
- usual set of xhci driver updates
- normal set of musb updates
- gadget driver updates and new controllers
- typec work, it's getting closer to getting fully out of the staging
portion of the tree.
- lots of minor cleanups and bugfixes.
All of these have been in linux-next for a while with no reported
issues"
* tag 'usb-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (263 commits)
Revert "xhci: Reset Renesas uPD72020x USB controller for 32-bit DMA issue"
xhci: Add quirk to zero 64bit registers on Renesas PCIe controllers
xhci: Allow more than 32 quirks
usb: xhci: force all memory allocations to node
selftests: add test for USB over IP driver
USB: typec: fsusb302: no need to check return value of debugfs_create_dir()
USB: gadget: udc: s3c2410_udc: no need to check return value of debugfs_create functions
USB: gadget: udc: renesas_usb3: no need to check return value of debugfs_create functions
USB: gadget: udc: pxa27x_udc: no need to check return value of debugfs_create functions
USB: gadget: udc: gr_udc: no need to check return value of debugfs_create functions
USB: gadget: udc: bcm63xx_udc: no need to check return value of debugfs_create functions
USB: udc: atmel_usba_udc: no need to check return value of debugfs_create functions
USB: dwc3: no need to check return value of debugfs_create functions
USB: dwc2: no need to check return value of debugfs_create functions
USB: core: no need to check return value of debugfs_create functions
USB: chipidea: no need to check return value of debugfs_create functions
USB: ehci-hcd: no need to check return value of debugfs_create functions
USB: fhci-hcd: no need to check return value of debugfs_create functions
USB: fotg210-hcd: no need to check return value of debugfs_create functions
USB: imx21-hcd: no need to check return value of debugfs_create functions
...
Diffstat (limited to 'drivers/usb/mtu3')
-rw-r--r-- | drivers/usb/mtu3/Kconfig | 3 | ||||
-rw-r--r-- | drivers/usb/mtu3/mtu3.h | 15 | ||||
-rw-r--r-- | drivers/usb/mtu3/mtu3_core.c | 26 | ||||
-rw-r--r-- | drivers/usb/mtu3/mtu3_dr.c | 73 | ||||
-rw-r--r-- | drivers/usb/mtu3/mtu3_gadget.c | 9 | ||||
-rw-r--r-- | drivers/usb/mtu3/mtu3_gadget_ep0.c | 12 | ||||
-rw-r--r-- | drivers/usb/mtu3/mtu3_plat.c | 6 |
7 files changed, 89 insertions, 55 deletions
diff --git a/drivers/usb/mtu3/Kconfig b/drivers/usb/mtu3/Kconfig index 25cd61947bee..40bbf1f53337 100644 --- a/drivers/usb/mtu3/Kconfig +++ b/drivers/usb/mtu3/Kconfig @@ -2,7 +2,7 @@ config USB_MTU3 tristate "MediaTek USB3 Dual Role controller" - depends on EXTCON && (USB || USB_GADGET) && HAS_DMA + depends on USB || USB_GADGET depends on ARCH_MEDIATEK || COMPILE_TEST select USB_XHCI_MTK if USB_SUPPORT && USB_XHCI_HCD help @@ -40,6 +40,7 @@ config USB_MTU3_GADGET config USB_MTU3_DUAL_ROLE bool "Dual Role mode" depends on ((USB=y || USB=USB_MTU3) && (USB_GADGET=y || USB_GADGET=USB_MTU3)) + depends on (EXTCON=y || EXTCON=USB_MTU3) help This is the default mode of working of MTU3 controller where both host and gadget features are enabled. diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index 2cd00a24afd9..87823ac0d120 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -196,10 +196,12 @@ struct mtu3_gpd_ring { * @vbus: vbus 5V used by host mode * @edev: external connector used to detect vbus and iddig changes * @vbus_nb: notifier for vbus detection -* @vbus_nb: notifier for iddig(idpin) detection -* @extcon_reg_dwork: delay work for extcon notifier register, waiting for -* xHCI driver initialization, it's necessary for system bootup -* as device. +* @vbus_work : work of vbus detection notifier, used to avoid sleep in +* notifier callback which is atomic context +* @vbus_event : event of vbus detecion notifier +* @id_nb : notifier for iddig(idpin) detection +* @id_work : work of iddig detection notifier +* @id_event : event of iddig detecion notifier * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not * @manual_drd_enabled: it's true when supports dual-role device by debugfs * to switch host/device modes depending on user input. @@ -208,8 +210,11 @@ struct otg_switch_mtk { struct regulator *vbus; struct extcon_dev *edev; struct notifier_block vbus_nb; + struct work_struct vbus_work; + unsigned long vbus_event; struct notifier_block id_nb; - struct delayed_work extcon_reg_dwork; + struct work_struct id_work; + unsigned long id_event; bool is_u3_drd; bool manual_drd_enabled; }; diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index b1b99a8f6a7a..eecfd0671362 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -176,7 +176,7 @@ static void mtu3_intr_enable(struct mtu3 *mtu) mtu3_writel(mbase, U3D_LV1IESR, value); /* Enable U2 common USB interrupts */ - value = SUSPEND_INTR | RESUME_INTR | RESET_INTR; + value = SUSPEND_INTR | RESUME_INTR | RESET_INTR | LPM_RESUME_INTR; mtu3_writel(mbase, U3D_COMMON_USB_INTR_ENABLE, value); if (mtu->is_u3_ip) { @@ -195,6 +195,16 @@ static void mtu3_intr_enable(struct mtu3 *mtu) mtu3_writel(mbase, U3D_DEV_LINK_INTR_ENABLE, SSUSB_DEV_SPEED_CHG_INTR); } +/* reset: u2 - data toggle, u3 - SeqN, flow control status etc */ +static void mtu3_ep_reset(struct mtu3_ep *mep) +{ + struct mtu3 *mtu = mep->mtu; + u32 rst_bit = EP_RST(mep->is_in, mep->epnum); + + mtu3_setbits(mtu->mac_base, U3D_EP_RST, rst_bit); + mtu3_clrbits(mtu->mac_base, U3D_EP_RST, rst_bit); +} + /* set/clear the stall and toggle bits for non-ep0 */ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set) { @@ -220,8 +230,7 @@ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set) } if (!set) { - mtu3_setbits(mbase, U3D_EP_RST, EP_RST(mep->is_in, epnum)); - mtu3_clrbits(mbase, U3D_EP_RST, EP_RST(mep->is_in, epnum)); + mtu3_ep_reset(mep); mep->flags &= ~MTU3_EP_STALL; } else { mep->flags |= MTU3_EP_STALL; @@ -400,6 +409,7 @@ void mtu3_deconfig_ep(struct mtu3 *mtu, struct mtu3_ep *mep) mtu3_setbits(mbase, U3D_QIECR0, QMU_RX_DONE_INT(epnum)); } + mtu3_ep_reset(mep); ep_fifo_free(mep); dev_dbg(mtu->dev, "%s: %s\n", __func__, mep->name); @@ -658,8 +668,10 @@ static irqreturn_t mtu3_u3_ltssm_isr(struct mtu3 *mtu) if (ltssm & (HOT_RST_INTR | WARM_RST_INTR)) mtu3_gadget_reset(mtu); - if (ltssm & VBUS_FALL_INTR) + if (ltssm & VBUS_FALL_INTR) { mtu3_ss_func_set(mtu, false); + mtu3_gadget_reset(mtu); + } if (ltssm & VBUS_RISE_INTR) mtu3_ss_func_set(mtu, true); @@ -692,6 +704,12 @@ static irqreturn_t mtu3_u2_common_isr(struct mtu3 *mtu) if (u2comm & RESET_INTR) mtu3_gadget_reset(mtu); + if (u2comm & LPM_RESUME_INTR) { + if (!(mtu3_readl(mbase, U3D_POWER_MANAGEMENT) & LPM_HRWE)) + mtu3_setbits(mbase, U3D_USB20_MISC_CONTROL, + LPM_U3_ACK_EN); + } + return IRQ_HANDLED; } diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index db7562d99b95..ac60e9c8564e 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -174,16 +174,40 @@ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx, } } -static int ssusb_id_notifier(struct notifier_block *nb, - unsigned long event, void *ptr) +static void ssusb_id_work(struct work_struct *work) { struct otg_switch_mtk *otg_sx = - container_of(nb, struct otg_switch_mtk, id_nb); + container_of(work, struct otg_switch_mtk, id_work); - if (event) + if (otg_sx->id_event) ssusb_set_mailbox(otg_sx, MTU3_ID_GROUND); else ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); +} + +static void ssusb_vbus_work(struct work_struct *work) +{ + struct otg_switch_mtk *otg_sx = + container_of(work, struct otg_switch_mtk, vbus_work); + + if (otg_sx->vbus_event) + ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID); + else + ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF); +} + +/* + * @ssusb_id_notifier is called in atomic context, but @ssusb_set_mailbox + * may sleep, so use work queue here + */ +static int ssusb_id_notifier(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct otg_switch_mtk *otg_sx = + container_of(nb, struct otg_switch_mtk, id_nb); + + otg_sx->id_event = event; + schedule_work(&otg_sx->id_work); return NOTIFY_DONE; } @@ -194,10 +218,8 @@ static int ssusb_vbus_notifier(struct notifier_block *nb, struct otg_switch_mtk *otg_sx = container_of(nb, struct otg_switch_mtk, vbus_nb); - if (event) - ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID); - else - ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF); + otg_sx->vbus_event = event; + schedule_work(&otg_sx->vbus_work); return NOTIFY_DONE; } @@ -238,15 +260,6 @@ static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) return 0; } -static void extcon_register_dwork(struct work_struct *work) -{ - struct delayed_work *dwork = to_delayed_work(work); - struct otg_switch_mtk *otg_sx = - container_of(dwork, struct otg_switch_mtk, extcon_reg_dwork); - - ssusb_extcon_register(otg_sx); -} - /* * We provide an interface via debugfs to switch between host and device modes * depending on user input. @@ -365,10 +378,6 @@ static void ssusb_debugfs_init(struct ssusb_mtk *ssusb) struct dentry *root; root = debugfs_create_dir(dev_name(ssusb->dev), usb_debug_root); - if (!root) { - dev_err(ssusb->dev, "create debugfs root failed\n"); - return; - } ssusb->dbgfs_root = root; debugfs_create_file("mode", 0644, root, ssusb, &ssusb_mode_fops); @@ -407,18 +416,13 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb) { struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; - if (otg_sx->manual_drd_enabled) { + INIT_WORK(&otg_sx->id_work, ssusb_id_work); + INIT_WORK(&otg_sx->vbus_work, ssusb_vbus_work); + + if (otg_sx->manual_drd_enabled) ssusb_debugfs_init(ssusb); - } else { - INIT_DELAYED_WORK(&otg_sx->extcon_reg_dwork, - extcon_register_dwork); - - /* - * It is enough to delay 1s for waiting for - * host initialization - */ - schedule_delayed_work(&otg_sx->extcon_reg_dwork, HZ); - } + else + ssusb_extcon_register(otg_sx); return 0; } @@ -429,6 +433,7 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb) if (otg_sx->manual_drd_enabled) ssusb_debugfs_exit(ssusb); - else - cancel_delayed_work(&otg_sx->extcon_reg_dwork); + + cancel_work_sync(&otg_sx->id_work); + cancel_work_sync(&otg_sx->vbus_work); } diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c index f05f10f5c171..5c60a8c5a0b5 100644 --- a/drivers/usb/mtu3/mtu3_gadget.c +++ b/drivers/usb/mtu3/mtu3_gadget.c @@ -660,14 +660,10 @@ int mtu3_gadget_setup(struct mtu3 *mtu) mtu3_gadget_init_eps(mtu); ret = usb_add_gadget_udc(mtu->dev, &mtu->g); - if (ret) { + if (ret) dev_err(mtu->dev, "failed to register udc\n"); - return ret; - } - usb_gadget_set_state(&mtu->g, USB_STATE_NOTATTACHED); - - return 0; + return ret; } void mtu3_gadget_cleanup(struct mtu3 *mtu) @@ -723,4 +719,5 @@ void mtu3_gadget_reset(struct mtu3 *mtu) mtu->u1_enable = 0; mtu->u2_enable = 0; mtu->delayed_status = false; + mtu->test_mode = false; } diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c b/drivers/usb/mtu3/mtu3_gadget_ep0.c index ebdcf7a38c29..25216e79cd6e 100644 --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c @@ -7,6 +7,7 @@ * Author: Chunfeng.Yun <chunfeng.yun@mediatek.com> */ +#include <linux/iopoll.h> #include <linux/usb/composite.h> #include "mtu3.h" @@ -263,6 +264,7 @@ static int handle_test_mode(struct mtu3 *mtu, struct usb_ctrlrequest *setup) { void __iomem *mbase = mtu->mac_base; int handled = 1; + u32 value; switch (le16_to_cpu(setup->wIndex) >> 8) { case TEST_J: @@ -292,6 +294,14 @@ static int handle_test_mode(struct mtu3 *mtu, struct usb_ctrlrequest *setup) if (mtu->test_mode_nr == TEST_PACKET_MODE) ep0_load_test_packet(mtu); + /* send status before entering test mode. */ + value = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS; + mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND); + + /* wait for ACK status sent by host */ + readl_poll_timeout_atomic(mbase + U3D_EP0CSR, value, + !(value & EP0_DATAEND), 100, 5000); + mtu3_writel(mbase, U3D_USB2_TEST_MODE, mtu->test_mode_nr); mtu->ep0_state = MU3D_EP0_STATE_SETUP; @@ -546,7 +556,7 @@ static void ep0_tx_state(struct mtu3 *mtu) struct usb_request *req; u32 csr; u8 *src; - u8 count; + u32 count; u32 maxp; dev_dbg(mtu->dev, "%s\n", __func__); diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 628d5ce356ca..46551f6d16fd 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -447,8 +447,7 @@ static int mtu3_remove(struct platform_device *pdev) */ static int __maybe_unused mtu3_suspend(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct ssusb_mtk *ssusb = platform_get_drvdata(pdev); + struct ssusb_mtk *ssusb = dev_get_drvdata(dev); dev_dbg(dev, "%s\n", __func__); @@ -466,8 +465,7 @@ static int __maybe_unused mtu3_suspend(struct device *dev) static int __maybe_unused mtu3_resume(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct ssusb_mtk *ssusb = platform_get_drvdata(pdev); + struct ssusb_mtk *ssusb = dev_get_drvdata(dev); int ret; dev_dbg(dev, "%s\n", __func__); |