From patchwork Tue Oct 13 10:22:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7382821 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BFC189F1D5 for ; Tue, 13 Oct 2015 10:22:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB09A207C2 for ; Tue, 13 Oct 2015 10:22:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A57F62084C for ; Tue, 13 Oct 2015 10:22:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932086AbbJMKWe (ORCPT ); Tue, 13 Oct 2015 06:22:34 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:32743 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932211AbbJMKWa (ORCPT ); Tue, 13 Oct 2015 06:22:30 -0400 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie3.idc.renesas.com with ESMTP; 13 Oct 2015 19:22:28 +0900 Received: from relmlac1.idc.renesas.com (relmlac1.idc.renesas.com [10.200.69.21]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 083E8511FE; Tue, 13 Oct 2015 19:22:29 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id 019538002E; Tue, 13 Oct 2015 19:22:28 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id F01788002D; Tue, 13 Oct 2015 19:22:28 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac1.idc.renesas.com with ESMTP id VAF20954; Tue, 13 Oct 2015 19:22:28 +0900 X-IronPort-AV: E=Sophos;i="5.17,677,1437404400"; d="scan'";a="196294003" Received: from mail-sg2apc01lp0243.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.243]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 13 Oct 2015 19:22:27 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost (211.11.155.144) by HK2PR06MB0913.apcprd06.prod.outlook.com (10.162.246.28) with Microsoft SMTP Server (TLS) id 15.1.293.16; Tue, 13 Oct 2015 10:22:25 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v4 3/3] phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection Date: Tue, 13 Oct 2015 19:22:06 +0900 Message-ID: <1444731726-5328-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 In-Reply-To: <1444731726-5328-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1444731726-5328-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: HKXPR02CA0044.apcprd02.prod.outlook.com (25.161.48.29) To HK2PR06MB0913.apcprd06.prod.outlook.com (25.162.246.28) X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0913; 2:1OMGSGdZ+vmSFaXoSnbExMnpMKxiIVfS3pZaqM5c3uH9Uwup+wBpC/Yx2PxwG0feBCHRAcjqtTrBkC6nPf+PZKy8aGEV/1OF3BQHs2FKjtIYEEe0M0zY0EprTpCNRKxARGicklMnueGS1wqi+t6oEnfzfp/+LGcAyE0PC277Tpk=; 3:hCLMP8HTW20IvGfJvYkTkV9ZVNqREL+CWvtK2FQRKSrEYwCLS4Uw6K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A3EYF5vto+QTs3HlahAytDIE6vFyObetWKtEp5J1+JsT6I/U09O7DDYQm1YrXK0voBhbPMfzgUCyzNWf7qCMERRCMLZSXEvYdiyHWDuUrW9w+jZdDqqJRuFrqXUgmeKIERB0ua2k8soPjarLSJ42Ua+DbE2AafSD+qyRZfcHgIyxiHn+vz8Jjh9o+z5DTQeVyN1FLy8MBo6PzecpEohVwwMR60PKRCeygOgCjgOsKdfHCKB6M5A0HefiYYRrUIEPUdvt9J2I0/RysEwvbqC9PgMW4jhT28= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85106069007906); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(3002001); SRVR:HK2PR06MB0913; BCL:0; PCL:0; RULEID:; SRVR:HK2PR06MB0913; X-Forefront-PRVS: 07283408BE X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(6069001)(199003)(189002)(78352002)(33646002)(77096005)(2950100001)(5001770100001)(229853001)(66066001)(87976001)(92566002)(81156007)(5001960100002)(106356001)(105586002)(5004730100002)(97736004)(47776003)(107886002)(50226001)(76176999)(48376002)(64706001)(189998001)(36756003)(5007970100001)(76506005)(50466002)(19580395003)(230783001)(40100003)(50986999)(19580405001)(5008740100001)(122386002)(42382002)(101416001)(5003940100001)(42186005)(46102003)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:HK2PR06MB0913; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:0; MX:0; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HK2PR06MB0913; 23:b6x9c6yh1HNiSvHTlTp5k2ygjsVoHTMsnGs5NeNK8?= =?us-ascii?Q?G2aWU1iQbDGHNehy6HusRLm80Pv7xl8einNHITUwyZhqqR0zGLm6bqfKSCeG?= =?us-ascii?Q?eq9KMT9qtaHHrmMWiPGVAUMG/E0KtXK5IMqr/AMscit7fA31TH2sBN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fAi4jiZosI8czm5YM+4O1rBMBsPnJZRMdVrZuwVQ?= =?us-ascii?Q?b6hriv78jlWBh3RBjk94ET8W/0hHSo2OvkqeTcSE1injVrBGIGZn7T3S8otK?= =?us-ascii?Q?bbEUemc5eHA1yHXldDNHTwn2sxwRVEEQWU/j+GYqi0SSeNEdxI03fMeGOQGP?= =?us-ascii?Q?qKAPSDUwH+sPRs=3D?= X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0913; 5:FCXaW48JgwV3gsDKV5j36QYsoFpYwhB8wFipcSBPZCIW0NohJgXogO6kFuZGgLJgBvG+0Fgou294V8lF6elDqfjVoLo5cYKSCgjUN1SxWtAc1w+CFUBUEMv3rCHOw/4YEtqiyff9sol19NLZVL6FZg==; 24:4z9hKynxFwbif+pjS1QHAfYG9PFQPnG4WsxMnAdtw5hYl1LnFpR8xtEiop373GtEMTafmR/7/HaJGvCYoDifjDgqhY/aBMzF18YDKC4BWEM=; 20:wS1Up+kSLh9Yo8e7VftoIZNwnuV0/25KcNhO9oxFT/jDzlAlTZxDc6ZqHbK2NI8+B6mDR1vVHg7gQmlmg63FC0ApehbH7lpJjz+GguimuEK+PLtySl8/SMMhrDXhCQGJzaaW6SRXGRR0Qy3fd9n2kC1ulQkoFruvVKBo+PvbHDU= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2015 10:22:25.4273 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2PR06MB0913 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-4.6 required=5.0 tests=AXB_X_OUTLOOKPROT_ENVSDR, BAYES_00,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for runtime ID/VBUS pin detection if the channel 0 of R-Car gen3 is used. So, we are able to use the channel as both host and peripheral. Signed-off-by: Yoshihiro Shimoda --- .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 2 + drivers/phy/phy-rcar-gen3-usb2.c | 43 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt index 589f5c0..b30a98a 100644 --- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt @@ -18,6 +18,7 @@ properties. This is because HSUSB has registers to select USB 2.0 host or peripheral at that channel: - reg: offset and length of the partial HSUSB register block. - reg-names: must be "hsusb". +- interrupts: interrupt specifier for the PHY. Example (R-Car H3): @@ -25,6 +26,7 @@ Example (R-Car H3): compatible = "renesas,usb2-phy-r8a7795"; reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>; reg-names = "usb2_host", "hsusb"; + interrupts = ; clocks = <&mstp7_clks R8A7795_CLK_EHCI0>, <&mstp7_clks R8A7795_CLK_HSUSB>; }; diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c index 03d7079..40d0005 100644 --- a/drivers/phy/phy-rcar-gen3-usb2.c +++ b/drivers/phy/phy-rcar-gen3-usb2.c @@ -12,6 +12,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -26,14 +27,18 @@ #define USB2_SPD_RSM_TIMSET 0x10c #define USB2_OC_TIMSET 0x110 #define USB2_COMMCTRL 0x600 +#define USB2_OBINTSTA 0x604 +#define USB2_OBINTEN 0x608 #define USB2_VBCTRL 0x60c #define USB2_LINECTRL1 0x610 #define USB2_ADPCTRL 0x630 /* INT_ENABLE */ +#define USB2_INT_ENABLE_UCOM_INTEN BIT(3) #define USB2_INT_ENABLE_USBH_INTB_EN BIT(2) #define USB2_INT_ENABLE_USBH_INTA_EN BIT(1) -#define USB2_INT_ENABLE_INIT (USB2_INT_ENABLE_USBH_INTB_EN | \ +#define USB2_INT_ENABLE_INIT (USB2_INT_ENABLE_UCOM_INTEN | \ + USB2_INT_ENABLE_USBH_INTB_EN | \ USB2_INT_ENABLE_USBH_INTA_EN) /* USBCTR */ @@ -49,6 +54,12 @@ /* COMMCTRL */ #define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */ +/* OBINTSTA and OBINTEN */ +#define USB2_OBINT_SESSVLDCHG BIT(12) +#define USB2_OBINT_IDDIGCHG BIT(11) +#define USB2_OBINT_BITS (USB2_OBINT_SESSVLDCHG | \ + USB2_OBINT_IDDIGCHG) + /* VBCTRL */ #define USB2_VBCTRL_DRVVBUSSEL BIT(8) @@ -178,6 +189,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) tmp = readl(usb2_base + USB2_VBCTRL); writel(tmp | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL); + writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); + tmp = readl(usb2_base + USB2_OBINTEN); + writel(tmp | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); tmp = readl(usb2_base + USB2_ADPCTRL); writel(tmp | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); tmp = readl(usb2_base + USB2_LINECTRL1); @@ -289,6 +303,23 @@ static struct phy_ops rcar_gen3_phy_usb2_ops = { .owner = THIS_MODULE, }; +static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) +{ + struct rcar_gen3_chan *ch = _ch; + void __iomem *usb2_base = ch->usb2.base; + u32 status = readl(usb2_base + USB2_OBINTSTA); + irqreturn_t ret = IRQ_NONE; + + if (status & USB2_OBINT_BITS) { + dev_dbg(&ch->phy->dev, "%s: %08x\n", __func__, status); + writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); + rcar_gen3_device_recognition(ch); + ret = IRQ_HANDLED; + } + + return ret; +} + static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = { { .compatible = "renesas,usb2-phy-r8a7795" }, { } @@ -323,9 +354,19 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) /* To avoid error message by devm_ioremap_resource() */ if (res) { + int ret, irq; + channel->hsusb.base = devm_ioremap_resource(dev, res); if (IS_ERR(channel->hsusb.base)) channel->hsusb.base = NULL; + /* call request_irq for OTG */ + ret = irq = platform_get_irq(pdev, 0); + if (irq >= 0) + ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, + IRQF_SHARED, dev_name(dev), + channel); + if (ret < 0) + dev_err(dev, "No irq handler (%d)\n", ret); } /* devm_phy_create() will call pm_runtime_enable(dev); */