From patchwork Wed Jun 29 18:16:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9205993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D416360752 for ; Wed, 29 Jun 2016 18:19:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C78E1284B8 for ; Wed, 29 Jun 2016 18:19:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA4B028673; Wed, 29 Jun 2016 18:19:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2BAC4284B8 for ; Wed, 29 Jun 2016 18:19:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIK40-0000yi-9z; Wed, 29 Jun 2016 18:18:16 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIK2u-0007sU-AS for linux-arm-kernel@lists.infradead.org; Wed, 29 Jun 2016 18:17:10 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FA3481F03; Wed, 29 Jun 2016 18:16:51 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-6-127.ams2.redhat.com [10.36.6.127]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5TIGgar017179; Wed, 29 Jun 2016 14:16:47 -0400 From: Hans de Goede To: Bin Liu , Greg Kroah-Hartman Subject: [PATCH v5 resend] usb: musb: sunxi: Simplify dr_mode handling Date: Wed, 29 Jun 2016 20:16:40 +0200 Message-Id: <1467224200-7565-2-git-send-email-hdegoede@redhat.com> In-Reply-To: <1467224200-7565-1-git-send-email-hdegoede@redhat.com> References: <1467224200-7565-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 29 Jun 2016 18:16:51 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160629_111708_641249_208D96BA X-CRM114-Status: GOOD ( 14.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-usb@vger.kernel.org, Chen-Yu Tsai , Hans de Goede , linux-sunxi@googlegroups.com, Maxime Ripard , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP phy-sun4i-usb now has proper dr_mode handling, it always registers an extcon, and sends a notify with the mode (even when in peripheral- / host-only mode) at least once. So we can simply the sunxi musb glue by always registering its extcon notifier and relying on sunxi_musb_work() to enable vbus when in host-only mode. This also enables host- and peripheral-only mode with vbus monitoring. Tested-by: Maxime Ripard Signed-off-by: Hans de Goede Acked-by: Bin Liu --- Changes in v2: -No changes Changes in v3: -No changes Changes in v4: -Add Maxime's Tested-by -Add Bin Liu's Acked-by Changes in v5: -No changes --- drivers/usb/musb/sunxi.c | 68 ++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c index 7650051..a17eb2a 100644 --- a/drivers/usb/musb/sunxi.c +++ b/drivers/usb/musb/sunxi.c @@ -256,12 +256,10 @@ static int sunxi_musb_init(struct musb *musb) writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0); /* Register notifier before calling phy_init() */ - if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) { - ret = extcon_register_notifier(glue->extcon, EXTCON_USB_HOST, - &glue->host_nb); - if (ret) - goto error_reset_assert; - } + ret = extcon_register_notifier(glue->extcon, EXTCON_USB_HOST, + &glue->host_nb); + if (ret) + goto error_reset_assert; ret = phy_init(glue->phy); if (ret) @@ -275,9 +273,8 @@ static int sunxi_musb_init(struct musb *musb) return 0; error_unregister_notifier: - if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) - extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST, - &glue->host_nb); + extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST, + &glue->host_nb); error_reset_assert: if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) reset_control_assert(glue->rst); @@ -301,9 +298,8 @@ static int sunxi_musb_exit(struct musb *musb) phy_exit(glue->phy); - if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) - extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST, - &glue->host_nb); + extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST, + &glue->host_nb); if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) reset_control_assert(glue->rst); @@ -315,25 +311,6 @@ static int sunxi_musb_exit(struct musb *musb) return 0; } -static int sunxi_set_mode(struct musb *musb, u8 mode) -{ - struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent); - int ret; - - if (mode == MUSB_HOST) { - ret = phy_power_on(glue->phy); - if (ret) - return ret; - - set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags); - /* Stop musb work from turning vbus off again */ - set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags); - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; - } - - return 0; -} - static void sunxi_musb_enable(struct musb *musb) { struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent); @@ -582,7 +559,6 @@ static const struct musb_platform_ops sunxi_musb_ops = { .exit = sunxi_musb_exit, .enable = sunxi_musb_enable, .disable = sunxi_musb_disable, - .set_mode = sunxi_set_mode, .fifo_offset = sunxi_musb_fifo_offset, .ep_offset = sunxi_musb_ep_offset, .busctl_offset = sunxi_musb_busctl_offset, @@ -638,10 +614,6 @@ static int sunxi_musb_probe(struct platform_device *pdev) return -EINVAL; } - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); - if (!glue) - return -ENOMEM; - memset(&pdata, 0, sizeof(pdata)); switch (usb_get_dr_mode(&pdev->dev)) { #if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_HOST @@ -649,15 +621,13 @@ static int sunxi_musb_probe(struct platform_device *pdev) pdata.mode = MUSB_PORT_MODE_HOST; break; #endif +#if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_GADGET + case USB_DR_MODE_PERIPHERAL: + pdata.mode = MUSB_PORT_MODE_GADGET; + break; +#endif #ifdef CONFIG_USB_MUSB_DUAL_ROLE case USB_DR_MODE_OTG: - glue->extcon = extcon_get_edev_by_phandle(&pdev->dev, 0); - if (IS_ERR(glue->extcon)) { - if (PTR_ERR(glue->extcon) == -EPROBE_DEFER) - return -EPROBE_DEFER; - dev_err(&pdev->dev, "Invalid or missing extcon\n"); - return PTR_ERR(glue->extcon); - } pdata.mode = MUSB_PORT_MODE_DUAL_ROLE; break; #endif @@ -668,6 +638,10 @@ static int sunxi_musb_probe(struct platform_device *pdev) pdata.platform_ops = &sunxi_musb_ops; pdata.config = &sunxi_musb_hdrc_config; + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + if (!glue) + return -ENOMEM; + glue->dev = &pdev->dev; INIT_WORK(&glue->work, sunxi_musb_work); glue->host_nb.notifier_call = sunxi_musb_host_notifier; @@ -701,6 +675,14 @@ static int sunxi_musb_probe(struct platform_device *pdev) } } + glue->extcon = extcon_get_edev_by_phandle(&pdev->dev, 0); + if (IS_ERR(glue->extcon)) { + if (PTR_ERR(glue->extcon) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "Invalid or missing extcon\n"); + return PTR_ERR(glue->extcon); + } + glue->phy = devm_phy_get(&pdev->dev, "usb"); if (IS_ERR(glue->phy)) { if (PTR_ERR(glue->phy) == -EPROBE_DEFER)