From patchwork Tue Oct 20 08:57:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7443971 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 AA71DBEEA4 for ; Tue, 20 Oct 2015 09:00:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A4E3D206A7 for ; Tue, 20 Oct 2015 09:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CBE1206DF for ; Tue, 20 Oct 2015 09:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750910AbbJTI76 (ORCPT ); Tue, 20 Oct 2015 04:59:58 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:10969 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750904AbbJTI6P (ORCPT ); Tue, 20 Oct 2015 04:58:15 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 20 Oct 2015 17:58:13 +0900 Received: from relmlac1.idc.renesas.com (relmlac1.idc.renesas.com [10.200.69.21]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 5FAFF6135B; Tue, 20 Oct 2015 17:58:13 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id 3C72F8002E; Tue, 20 Oct 2015 17:58:13 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id 355A78002D; Tue, 20 Oct 2015 17:58:13 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac1.idc.renesas.com with ESMTP id TAA19584; Tue, 20 Oct 2015 17:58:13 +0900 X-IronPort-AV: E=Sophos;i="5.17,706,1437404400"; d="scan'";a="198065200" Received: from mail-sg2apc01lp0239.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.239]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 20 Oct 2015 17:58:11 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost (211.11.155.144) by SG2PR06MB0920.apcprd06.prod.outlook.com (10.162.204.153) with Microsoft SMTP Server (TLS) id 15.1.300.14; Tue, 20 Oct 2015 08:58:10 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v5 2/4] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel Date: Tue, 20 Oct 2015 17:57:49 +0900 Message-ID: <1445331471-5028-3-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: HK2PR02CA0020.apcprd02.prod.outlook.com (25.163.104.158) To SG2PR06MB0920.apcprd06.prod.outlook.com (25.162.204.153) X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0920; 2:aqk0azUISCRXurkwR0C47bbqQhuBF/roAECGUe8iey5DImmfdNpCqah+kmbE9bFMk6J5HUl+7Aj/MXeZluBO10Gtk2hwc50I06o4sp85K9OFPrH1iSh2CWNu81PgG2grmp8cxpoXcJCv6wdV94tEuaC4WOCHvqtnfPdQlc90fqk=; 3:349mfWAYotFBm6cAh2T1XmJTy5WgL9R3vlLnuTosj3g/TCNmbXRUikUmD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6xW29rRygXV2gIOhXU3I1LTKgky3IbbqwVSiB4rxgYshNaEchTck5hLXHBYD4hhiytTs+CxCCg+zZYPM1OfAJA7eC6fnjkw9cMMPdkGWNzKnMWd26OB1jw3ivM4zYULgLVjfLnD7fLdEH3NXxuA5XkrFZIjSp+LSo5EtRDNbM/5gxlJ/rWJ6mdtOIlncdHVx3YQqGcexK4xVuYD3RDOvpv2D/kHSJ8NY7oLodLNCuIMrO0DCpxG2PVeivj/sqUdxb6I= 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:SG2PR06MB0920; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB0920; X-Forefront-PRVS: 073515755F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(6069001)(189002)(199003)(97736004)(122386002)(107886002)(33646002)(5001770100001)(50986999)(77096005)(48376002)(76506005)(229853001)(36756003)(575784001)(78352002)(46102003)(42186005)(5001960100002)(105586002)(47776003)(81156007)(5003940100001)(189998001)(19580405001)(66066001)(64706001)(106356001)(5008740100001)(230783001)(42382002)(87976001)(76176999)(40100003)(19580395003)(101416001)(5004730100002)(50226001)(5007970100001)(92566002)(2950100001)(50466002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB0920; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:0; A:0; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SG2PR06MB0920; 23:MaqWHVIxSg7Xa/DxMUKdPg8Fvd/77T6pfLtaEKItw?= =?us-ascii?Q?Yo9cwnFSUesnfumlF51yT2pP+/ScHHR8m3u0x44MvytqjT4nMlos2/J2BnlC?= =?us-ascii?Q?ezIuInC39Hud8Yk3ll3+G7fjb7zLAYFVYB9xUQuamvqnNtbECfhwDI8llrmb?= =?us-ascii?Q?GS+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39nLRVU?= =?us-ascii?Q?gt7enNqrB/dHeZ0jOCSEAJIVnG+HIbNnNiL6vtoc8a2+nkkRNiAPAfU+sZ+X?= =?us-ascii?Q?uisMQg56P9ZhjJkfoG+PFEON1WEXKvsBHZdqkcVK1gjz1BbzqsOExbzJ9TK9?= =?us-ascii?Q?N77RU2unfaPoWZ2GP4OAbzRK7yl+H/BB4oB?= X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0920; 5:wqJYqrXmaffMPUL0nTkYjzIFe4pubtS3kgj6aR2+Lxm+Tvf/QMj6CMtNtVBP801GcGrH6JTA6k0jUA9MPb/IKS8gZtxMyPoOV5Ro+Uefnl9wInrbMP1mCAzzedZy4oMCW9HNf4OHIjUjJ1hXrfJ+ng==; 24:g4rMfZ9FaWZ44SpeiBrwsGdhzbkWLrMN9ZiMupd+JEOIpayz3qKBDwRE66zd39bXv28HbWdPchxLp8d0JTMo0moA8JyqGt5zAR7dzLHttts=; 20:PH9pP22aUR03uWPDixkD1k2k9tZXYeMche4U+kZFpvjFJ5VYWWDOgZekV7WbWIUfRXeHF9DSZxxDV6QLCi0N1bkE8B7Zqp52ItBFciWsNnobOuPpoLzc7xfjh4GFwsH/Ok8XGlbbF/r2wfEnVC2mWP62kp8v5HFq1lphUE8usRk= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2015 08:58:10.2464 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB0920 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=ham 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 To use the channel 0 of R-Car gen3 as periperal mode, This patch changes the mode to OTG instead of HOST. Then, this driver needs to set some registers to enable host mode and detects ID pin and VBUS pin at phy_init() timing. For now, the channel 0 can be used as host mode only. Signed-off-by: Yoshihiro Shimoda --- drivers/phy/phy-rcar-gen3-usb2.c | 124 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c index 9d9cf26..cf91f9f 100644 --- a/drivers/phy/phy-rcar-gen3-usb2.c +++ b/drivers/phy/phy-rcar-gen3-usb2.c @@ -24,6 +24,10 @@ #define USB2_USBCTR 0x00c #define USB2_SPD_RSM_TIMSET 0x10c #define USB2_OC_TIMSET 0x110 +#define USB2_COMMCTRL 0x600 +#define USB2_VBCTRL 0x60c +#define USB2_LINECTRL1 0x610 +#define USB2_ADPCTRL 0x630 /* INT_ENABLE */ #define USB2_INT_ENABLE_USBH_INTB_EN BIT(2) @@ -41,6 +45,24 @@ /* OC_TIMSET */ #define USB2_OC_TIMSET_INIT 0x000209ab +/* COMMCTRL */ +#define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */ + +/* VBCTRL */ +#define USB2_VBCTRL_DRVVBUSSEL BIT(8) + +/* LINECTRL1 */ +#define USB2_LINECTRL1_DPRPD_EN BIT(19) +#define USB2_LINECTRL1_DP_RPD BIT(18) +#define USB2_LINECTRL1_DMRPD_EN BIT(17) +#define USB2_LINECTRL1_DM_RPD BIT(16) + +/* ADPCTRL */ +#define USB2_ADPCTRL_OTGSESSVLD BIT(20) +#define USB2_ADPCTRL_IDDIG BIT(19) +#define USB2_ADPCTRL_IDPULLUP BIT(5) /* 1 = ID sampling is enabled */ +#define USB2_ADPCTRL_DRVVBUS BIT(4) + /******* HSUSB registers (original offset is +0x100) *******/ #define HSUSB_LPSTS 0x02 #define HSUSB_UGCTRL2 0x84 @@ -66,6 +88,102 @@ struct rcar_gen3_chan { struct phy *phy; }; +static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host) +{ + void __iomem *usb2_base = ch->usb2.base; + u32 val = readl(usb2_base + USB2_COMMCTRL); + + dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, host); + if (host) + val &= ~USB2_COMMCTRL_OTG_PERI; + else + val |= USB2_COMMCTRL_OTG_PERI; + writel(val, usb2_base + USB2_COMMCTRL); +} + +static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm) +{ + void __iomem *usb2_base = ch->usb2.base; + u32 val = readl(usb2_base + USB2_LINECTRL1); + + dev_vdbg(&ch->phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm); + val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD); + if (dp) + val |= USB2_LINECTRL1_DP_RPD; + if (dm) + val |= USB2_LINECTRL1_DM_RPD; + writel(val, usb2_base + USB2_LINECTRL1); +} + +static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus) +{ + void __iomem *usb2_base = ch->usb2.base; + u32 val = readl(usb2_base + USB2_ADPCTRL); + + dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, vbus); + if (vbus) + val |= USB2_ADPCTRL_DRVVBUS; + else + val &= ~USB2_ADPCTRL_DRVVBUS; + writel(val, usb2_base + USB2_ADPCTRL); +} + +static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch) +{ + rcar_gen3_set_linectrl(ch, 1, 1); + rcar_gen3_set_host_mode(ch, 1); + rcar_gen3_enable_vbus_ctrl(ch, 1); +} + +static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch) +{ + rcar_gen3_set_linectrl(ch, 0, 1); + rcar_gen3_set_host_mode(ch, 0); + rcar_gen3_enable_vbus_ctrl(ch, 0); +} + +static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch) +{ + return !!(readl(ch->usb2.base + USB2_ADPCTRL) & + USB2_ADPCTRL_OTGSESSVLD); +} + +static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch) +{ + return !!(readl(ch->usb2.base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG); +} + +static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch) +{ + bool is_host = true; + + /* B-device? */ + if (rcar_gen3_check_id(ch) && rcar_gen3_check_vbus(ch)) + is_host = false; + + if (is_host) + rcar_gen3_init_for_host(ch); + else + rcar_gen3_init_for_peri(ch); +} + +static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) +{ + void __iomem *usb2_base = ch->usb2.base; + u32 val; + + val = readl(usb2_base + USB2_VBCTRL); + writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL); + val = readl(usb2_base + USB2_ADPCTRL); + writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); + val = readl(usb2_base + USB2_LINECTRL1); + rcar_gen3_set_linectrl(ch, 0, 0); + writel(val | USB2_LINECTRL1_DPRPD_EN | USB2_LINECTRL1_DMRPD_EN, + usb2_base + USB2_LINECTRL1); + + rcar_gen3_device_recognition(ch); +} + static int rcar_gen3_phy_usb2_init(struct phy *p) { struct rcar_gen3_chan *channel = phy_get_drvdata(p); @@ -80,11 +198,13 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) /* Initialize HSUSB part */ if (hsusb_base) { - /* TODO: support "OTG" mode */ val = readl(hsusb_base + HSUSB_UGCTRL2); val = (val & ~HSUSB_UGCTRL2_USB0SEL) | - HSUSB_UGCTRL2_USB0SEL_HOST; + HSUSB_UGCTRL2_USB0SEL_OTG; writel(val & HSUSB_UGCTRL2_MASK, hsusb_base + HSUSB_UGCTRL2); + + /* Initialize otg part */ + rcar_gen3_init_otg(channel); } return 0;