From patchwork Tue Oct 20 08:57:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7444001 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F3CFBBEEA4 for ; Tue, 20 Oct 2015 09:00:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5FCF420576 for ; Tue, 20 Oct 2015 09:00:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1C9A20570 for ; Tue, 20 Oct 2015 09:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752028AbbJTI7x (ORCPT ); Tue, 20 Oct 2015 04:59:53 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:60482 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750991AbbJTI6U (ORCPT ); Tue, 20 Oct 2015 04:58:20 -0400 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie2.idc.renesas.com with ESMTP; 20 Oct 2015 17:58:19 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 4054153E70; Tue, 20 Oct 2015 17:58:19 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 209EF480A3; Tue, 20 Oct 2015 17:58:19 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 1038A480A5; Tue, 20 Oct 2015 17:58:19 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac4.idc.renesas.com with ESMTP id TAF15749; Tue, 20 Oct 2015 17:58:19 +0900 X-IronPort-AV: E=Sophos;i="5.17,706,1437404400"; d="scan'";a="196853621" Received: from mail-pu1apc01lp0018.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.18]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 20 Oct 2015 17:58:17 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost (211.11.155.144) by SIXPR06MB0923.apcprd06.prod.outlook.com (10.162.173.158) with Microsoft SMTP Server (TLS) id 15.1.300.14; Tue, 20 Oct 2015 08:58:15 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v5 3/4] phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection Date: Tue, 20 Oct 2015 17:57:50 +0900 Message-ID: <1445331471-5028-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 In-Reply-To: <1445331471-5028-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1445331471-5028-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: HK2PR02CA0003.apcprd02.prod.outlook.com (25.163.104.141) To SIXPR06MB0923.apcprd06.prod.outlook.com (25.162.173.158) X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0923; 2:ELv2OuX2Uc7SGieImkCQ+4p+F40Z8EXHrUj33EL5KjAvrSTkfo17z9ScNnaYJ5XmNT75NCUNdw1OH6jMVXcMv9Ac6YXL6st9IW8tIRmK2AtRXnFupWT2MN8PvjYd6NWDWUP4mtSBxPgl9B/87eKLGokCWMTIADlRKtic6iVj52s=; 3:yX4xr3H0QKFL5HZYjOgJkF1Q+yHEmAAR1gYv+2ICAy0BtbywnjNQMSK6WBzCkOzMz449E/BTmifGOQx7UOFEl6m/4WHggemajY8W/grUvRsngPmmG8W3cLhdatGbTZ+SbxXCxZDoWUQ+lX23z22pcA==; 25:Zo5rNpFXQJruflYoRWnjVvDsSdk6oPskj32ebkzfDCq35AoF6mTpHDBMlj/JPx+P1WOszYb1LSVmt8rMsbwmPZNxYj/53v5Qb2S3UklLaXfybb4itPxQCYabOXjQScPgrLfXxqhZqU9OqUs5g3MDtYBMDFmxV9tDyipDE2IH5GxX9SGqAn+VCYfR4IudmL6GeovUChqIaLUBeqWkCgZ18jmwmqPC/Drnv61COS8WP94QCcTLe/Dfv7qqWuQWICyT3QF792F6F55c5p/Nm3e2Jw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB0923; X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0923; 20:8qFPfy27635/ECBNbC5fT5CJ1z5Yx4bSOLN4TipYSIWuWLTqfUzEBsY1ivgzrBllFemov1HRtlRhisC2kVrIyt1OAXmmpLgSfVb+Rw0pUgR2LD9XDltNlR/dhPTpyty6gsducYQaPFM1mM1MWG7KZVNHBsEdbuYdy62gpPkmhrUGgjrTZDxyrik89klOVR1bCwh2imy3xzMdCa0ANkesWGBqAZUByROiMxTChk25YG3soF48xhT+8iuH+FwNkfB+iooLHBbtxMva61VYSuhm8q/7LHSlRiMR0UZq8PkyWTXcIehLe+zB6JBb5nQbtafqhxv6RcKhzS12lYvi3b0rr8hrvWwPhNtL3AsNdF5Dc10mtHzo/cJbpPf60RQOcOIorG+F9aN0sszkbxTgBSRA8MRpHF+D9YNGHnAFp1Y6V78pCYh57QAClVFuQ80LwRcYf8RQALRl/xUXHUoUsBrGL39FimEVqG41z0GS9mCXAJ2zPMuEgyfmH6AxjZV5sO4c; 4:5VPeznmREzReCDQd8PyT7vJYjVkCR0n9rZqtLkPsmLsDyvSQa2it873myHCtjlNyq/5K0zK1ksI6j4hb5uMyzs0ybdqkAL8luC9bUA3yH/75+YwO1CXHbPKS7hf5bTBbVvDRbw0Uii6xIA9FOkSnnbjvjHr2MDrUXyc8Q9Y/KNVv0K/sxOn6eV/dhrVDlflnuP+yzGsx88UMFskqNfYRy4dL7SYqLL8+pIsAhVVfAajFStq1qqVlrVaOHdAL3HpqGirsbjAdu/vd+qWR3OuV3765zBoN3UPsYbnjahYvWylP+9BUjfm7X7KDJJEoihb87irpvoXMbJnMOAWqNakQrEDomjUh8s4yfxUnHHE37Eo= 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)(520078)(8121501046)(3002001); SRVR:SIXPR06MB0923; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB0923; X-Forefront-PRVS: 073515755F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(6069001)(199003)(189002)(42186005)(229853001)(50226001)(33646002)(46102003)(77096005)(189998001)(19580405001)(5001960100002)(2950100001)(48376002)(5004730100002)(50466002)(5007970100001)(122386002)(40100003)(87976001)(106356001)(47776003)(101416001)(42382002)(105586002)(81156007)(50986999)(107886002)(64706001)(575784001)(76176999)(19580395003)(230783001)(5001770100001)(5001920100001)(36756003)(97736004)(78352002)(5003940100001)(5008740100001)(76506005)(92566002)(66066001)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB0923; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:0; MX:0; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SIXPR06MB0923; 23:WARPJOep+x+Fl3jYIW/MVH2M1f17TSUD5fHj/8SwC?= =?us-ascii?Q?1gvWq38g5yXyUdeRIK5pss5kYewWjNLzkSjGIjzYfNnKwgpOTYF04LPtaKwK?= =?us-ascii?Q?hPXDabIW5/00314zKjBv6sVUAX+4wklcJmvFtP7JHgZZbRTSkHZTQcXTtkRM?= =?us-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nFp657D951pmPE2MG+ZecO?= =?us-ascii?Q?m1DLz18tgKD1mOkudfOodJNDHvp+xrLQSbkvVKaJ1Oz1aL9LVW54uxwzw4Yx?= =?us-ascii?Q?cUbSnD2I1Q+qk4evlkCGrr2qRvGGZ1hEqtlUi0ihjLWYofYVY43tqBvMZ+Sl?= =?us-ascii?Q?Ij0PWWyA9wbql+o8Sk3ld4rqyZUh0WHRnh+YE9PF68S+2VVcytxvQTe37GO/?= =?us-ascii?Q?t8Fq6dm1o048tUq4BI=3D?= X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0923; 5:mP+VaXK7FcrjcUfVKIDvktuNlVLClhHisLf2tyThHTPfpWgwrJh05QKpgY02NO1lPYjjpUiOG6ovTr7XPMyvuT7dPVQxpZHG5HeLknIBk/7kpl5pZt5BsisS5tzsz1WBFDMJY5495P3tlQ8hy/Z1aA==; 24:XVACSjF/fINqIWRM7MqOipggoFNSIM/1gcUrpwgmQ6bFarYwmVscFyGBggeZzhm+8Fk44QqHLqN1KyYGsCWQ5cI4kGjt24juqLXZa03ragk=; 20:uflwBlioo15OUOGPgXWvJ+wQT9K3rJgxfFIHMKmP0fgROorRh3nt8i7yGk/1Il30y5QxK+GHErGl8isrrwacyQOSp2l+aYy19u6/StDSPcmPdm8wqaNjz2H+NjyRNPOAewvQcKna+BtItXNqZNETaa62vaTqSEXyCJJW9lfgr9o= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2015 08:58:15.8860 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0923 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-5.7 required=5.0 tests=AXB_X_OUTLOOKPROT_ENVSDR, BAYES_00,RCVD_IN_DNSWL_HI,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 affa0f7..2390e4e 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 cf91f9f..3c6805c 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 @@ -25,14 +26,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 */ @@ -48,6 +53,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) @@ -174,6 +185,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val = readl(usb2_base + USB2_VBCTRL); writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL); + writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); + val = readl(usb2_base + USB2_OBINTEN); + writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); val = readl(usb2_base + USB2_ADPCTRL); writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); val = readl(usb2_base + USB2_LINECTRL1); @@ -270,6 +284,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_vdbg(&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" }, { } @@ -302,9 +333,19 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) /* To avoid error message by devm_ioremap_resource() */ if (res) { + int irq; + channel->hsusb.base = devm_ioremap_resource(dev, res); if (IS_ERR(channel->hsusb.base)) channel->hsusb.base = NULL; + /* call request_irq for OTG */ + irq = platform_get_irq(pdev, 0); + if (irq >= 0) + irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, + IRQF_SHARED, dev_name(dev), + channel); + if (irq < 0) + dev_err(dev, "No irq handler (%d)\n", irq); } /* devm_phy_create() will call pm_runtime_enable(dev); */