From patchwork Wed May 15 22:20:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABl_PORTAY?= X-Patchwork-Id: 10945395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72F391398 for ; Wed, 15 May 2019 22:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6161E28823 for ; Wed, 15 May 2019 22:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F8F328A80; Wed, 15 May 2019 22:21:28 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA4B428823 for ; Wed, 15 May 2019 22:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=OQB8vRW4l6n3Agl/TtXHK4ZMJL3X/makIY9ZXakr9mM=; b=Brh2lQWCNbtfry bLdacHsweRsrqvidGCF+LAYrA0TiKo14hhMTZVmqOt8N+H0+WMHbduxPE5ApmIFVrsIET1Y8oO4Nd dOClR66eVMpTlFihvDYpMtLhZesa9u44/ThvgvT74QZ7idqNjQcXnTzgcNjJWLGO8k6oVWCMs/zad 1nTeU5v1F4TIdrDLglG3LrC2nJREWgmOtGXEK5pN1ODLFGLOX0nLynyke/0NH1nwmnq2xU3x5bHOU JTgN5aOsMbmXcJRSttfEuKi1Yt4r8W/07v6lZN9BAxcYJ/quKW1HI5VaGU7YmPQWsQUrz4AdkC1Pd /3SqRDfKbvRm9pUGyPoQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hR2H5-0006Ju-G5; Wed, 15 May 2019 22:21:23 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hR2Gw-0006De-65; Wed, 15 May 2019 22:21:16 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: gportay) with ESMTPSA id 523AA283E7A From: =?utf-8?q?Ga=C3=ABl_PORTAY?= To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Subject: [PATCH v2] phy: rockchip-inno-usb2: allow to force the B-Device Session Valid bit. Date: Wed, 15 May 2019 18:20:50 -0400 Message-Id: <20190515222050.15075-1-gael.portay@collabora.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190515_152114_490175_08944E2D X-CRM114-Status: GOOD ( 18.02 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Enric Balletbo i Serra , kernel@collabora.com, Heiko Stuebner , =?utf-8?q?Ga=C3=ABl?= =?utf-8?q?_PORTAY?= , Kishon Vijay Abraham I Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Enric Balletbo i Serra The OTG disconnection event is generated after the presence/absence of an ID connection, but some platforms don't have the ID pin connected, so the event is not generated. In such case, for detecting the disconnection event, we can get the cable state from an extcon driver. We need, though, to force to set the B-Device Session Valid bit on the PHY to have the device respond to the setup address. Otherwise, the following error is shown: usb 2-2: Device not responding to setup address. usb 2-2: device not accepting address 14, error -71 usb usb2-port2: unable to enumerate USB device The patch tells the PHY to force the B-Device Session Valid bit when the OTG role is device and clear that bit if the OTG role is host, when an extcon is available. Signed-off-by: Enric Balletbo i Serra Signed-off-by: Gaël PORTAY --- Hi all, The main purpose of this patch is have the Type-C port on the Samsung Chromebook Plus work as a device or in OTG mode. That patch was originally a part of that patchset[1]; all other patches was merged recently in master. The patch was tested on a Samsung Chromebook Plus by configuring one port to work as device, configure a cdc ethernet gadget and communicate via ethernet gadget my workstation with the chromebook through a usb-a to type-c cable. Best regards, Gaël [1]: https://lkml.org/lkml/2018/8/15/141 Changes since v1: - [PATCH 3/4] Remove introduction of dt property "rockchip,force-bvalid" and replace cable state using extcon instead (if set). drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index ba07121c3eff..5e9d50b5ae16 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -125,6 +125,7 @@ struct rockchip_chg_det_reg { * @bvalid_det_en: vbus valid rise detection enable register. * @bvalid_det_st: vbus valid rise detection status register. * @bvalid_det_clr: vbus valid rise detection clear register. + * @bvalid_session: force B-device session valid register. * @ls_det_en: linestate detection enable register. * @ls_det_st: linestate detection state register. * @ls_det_clr: linestate detection clear register. @@ -138,6 +139,7 @@ struct rockchip_usb2phy_port_cfg { struct usb2phy_reg bvalid_det_en; struct usb2phy_reg bvalid_det_st; struct usb2phy_reg bvalid_det_clr; + struct usb2phy_reg bvalid_session; struct usb2phy_reg ls_det_en; struct usb2phy_reg ls_det_st; struct usb2phy_reg ls_det_clr; @@ -169,6 +171,7 @@ struct rockchip_usb2phy_cfg { * @port_id: flag for otg port or host port. * @suspended: phy suspended flag. * @vbus_attached: otg device vbus status. + * @force_bvalid: force the control of the B-device session valid bit. * @bvalid_irq: IRQ number assigned for vbus valid rise detection. * @ls_irq: IRQ number assigned for linestate detection. * @otg_mux_irq: IRQ number which multiplex otg-id/otg-bvalid/linestate @@ -187,6 +190,7 @@ struct rockchip_usb2phy_port { unsigned int port_id; bool suspended; bool vbus_attached; + bool force_bvalid; int bvalid_irq; int ls_irq; int otg_mux_irq; @@ -553,6 +557,13 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) switch (rport->state) { case OTG_STATE_UNDEFINED: rport->state = OTG_STATE_B_IDLE; + if (rport->force_bvalid) { + property_enable(rphy->grf, + &rport->port_cfg->bvalid_session, + true); + dev_dbg(&rport->phy->dev, + "set the B-Device Session Valid\n"); + } if (!vbus_attach) rockchip_usb2phy_power_off(rport->phy); /* fall through */ @@ -560,6 +571,14 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) > 0) { dev_dbg(&rport->phy->dev, "usb otg host connect\n"); rport->state = OTG_STATE_A_HOST; + /* When leaving device mode force end the session */ + if (rport->force_bvalid) { + property_enable(rphy->grf, + &rport->port_cfg->bvalid_session, + false); + dev_dbg(&rport->phy->dev, + "clear the B-Device Session Valid\n"); + } rockchip_usb2phy_power_on(rport->phy); return; } else if (vbus_attach) { @@ -634,6 +653,14 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) == 0) { dev_dbg(&rport->phy->dev, "usb otg host disconnect\n"); rport->state = OTG_STATE_B_IDLE; + /* When leaving host mode force start the session */ + if (rport->force_bvalid) { + property_enable(rphy->grf, + &rport->port_cfg->bvalid_session, + true); + dev_dbg(&rport->phy->dev, + "set the B-Device Session Valid\n"); + } rockchip_usb2phy_power_off(rport->phy); } break; @@ -1016,6 +1043,28 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, INIT_DELAYED_WORK(&rport->chg_work, rockchip_chg_detect_work); INIT_DELAYED_WORK(&rport->otg_sm_work, rockchip_usb2phy_otg_sm_work); + /* + * Some platforms doesn't have the ID pin connected to the phy, hence + * the OTD ID event is not generated, but in some cases we can get the + * cable state from an extcon driver. In such case we can force to set + * the B-Device Session Valid bit on the PHY to have the device working + * as a OTG. + */ + if (rphy->edev) { + /* + * Check if bvalid_session register is set in the structure + * rockchip_usb2phy_cfg for this SoC. + */ + if (rport->port_cfg->bvalid_session.offset == 0x0) { + rport->force_bvalid = false; + dev_err(rphy->dev, + "cannot force B-device session, the register is not set for that SoC\n"); + } else { + rport->force_bvalid = true; + dev_info(rphy->dev, "force B-device session enabled\n"); + } + } + /* * Some SoCs use one interrupt with otg-id/otg-bvalid/linestate * interrupts muxed together, so probe the otg-mux interrupt first, @@ -1338,6 +1387,7 @@ static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = { .bvalid_det_en = { 0xe3c0, 3, 3, 0, 1 }, .bvalid_det_st = { 0xe3e0, 3, 3, 0, 1 }, .bvalid_det_clr = { 0xe3d0, 3, 3, 0, 1 }, + .bvalid_session = { 0x4498, 4, 4, 0, 1 }, .utmi_avalid = { 0xe2ac, 7, 7, 0, 1 }, .utmi_bvalid = { 0xe2ac, 12, 12, 0, 1 }, }, @@ -1373,6 +1423,7 @@ static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = { .bvalid_det_en = { 0xe3c0, 8, 8, 0, 1 }, .bvalid_det_st = { 0xe3e0, 8, 8, 0, 1 }, .bvalid_det_clr = { 0xe3d0, 8, 8, 0, 1 }, + .bvalid_session = { 0x4518, 4, 4, 0, 1 }, .utmi_avalid = { 0xe2ac, 10, 10, 0, 1 }, .utmi_bvalid = { 0xe2ac, 16, 16, 0, 1 }, },