From patchwork Mon Nov 30 01:44:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7719951 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 295F29F30B for ; Mon, 30 Nov 2015 01:46:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AB7B203A0 for ; Mon, 30 Nov 2015 01:46:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A93820573 for ; Mon, 30 Nov 2015 01:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751935AbbK3Bpv (ORCPT ); Sun, 29 Nov 2015 20:45:51 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:45672 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752419AbbK3Bov (ORCPT ); Sun, 29 Nov 2015 20:44:51 -0500 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie2.idc.renesas.com with ESMTP; 30 Nov 2015 10:44:49 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 9459D3EEE8; Mon, 30 Nov 2015 10:44:49 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id 7D6621806F; Mon, 30 Nov 2015 10:44:49 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id 703931800A; Mon, 30 Nov 2015 10:44:49 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac3.idc.renesas.com with ESMTP id LAL28183; Mon, 30 Nov 2015 10:44:49 +0900 X-IronPort-AV: E=Sophos;i="5.20,361,1444662000"; d="scan'";a="199508215" Received: from mail-pu1apc01lp0015.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.15]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 30 Nov 2015 10:44:47 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost (211.11.155.144) by SIXPR06MB0924.apcprd06.prod.outlook.com (10.162.180.29) with Microsoft SMTP Server (TLS) id 15.1.331.20; Mon, 30 Nov 2015 01:44:46 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v6 2/4] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel Date: Mon, 30 Nov 2015 10:44:31 +0900 Message-ID: <1448847873-7072-3-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 In-Reply-To: <1448847873-7072-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1448847873-7072-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: HKXPR03CA0059.apcprd03.prod.outlook.com (10.141.129.49) To SIXPR06MB0924.apcprd06.prod.outlook.com (25.162.180.29) X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0924; 2:TWX+vCCA+HocsVIailcdSue83E532y3YNENTNSwchkDbuQ7hxCkjESazGaa5PANkbm8SdiX/2ilhnfw3Wk9Fp/38go3EKsZYUaCMccWP5fv5aPki3+4lufaQSi4TlMGI+uTfIBfwGUU/Kr/dNP2TpQ==; 3:7k20JlEWWlReNCVEwVPpj9cH7D5QP6TJNDhSEtzrkwxFXCTDz8ABCyvAv8MwZBLzjiCrwLLNzWatc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VgKcMVKB+JGmQc5yqh/YuiaoCXFaTKBkWlxO2ghQGj9TGZzOiCbZXAslD8Vd6zZMfxytaKMtwGEzEKuTEiVBQ6FbXKugbuHMUzXFSildrH1n1bgHKzuKpu+OsFenzCGDb5od4BKdNjFGxdYPppd9vZdYOPAlVahPlCL88ck1DOMBgQpCDSHdXRTahYNX1gk3byAa5B00VFWycENAThCGthIV6fCANJ1yrYkiNfbY6gDpQ0852GsFqUDZb7G3P9ActaxdvtYTsiLh0HT+lubTSrKj ivi/8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85106069007906); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(10201501046)(3002001); SRVR:SIXPR06MB0924; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB0924; X-Forefront-PRVS: 0776C39A48 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(979002)(6069001)(6009001)(189002)(199003)(47776003)(76176999)(586003)(5001960100002)(575784001)(92566002)(40100003)(76506005)(77096005)(81156007)(50986999)(189998001)(229853001)(42382002)(3846002)(6116002)(5003940100001)(122386002)(33646002)(97736004)(107886002)(5001770100001)(105586002)(106356001)(5004730100002)(48376002)(101416001)(42186005)(66066001)(78352003)(50466002)(19580395003)(50226001)(87976001)(230783001)(2950100001)(19580405001)(1096002)(4001430100002)(5008740100001)(36756003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB0924; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:0; A:0; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SIXPR06MB0924; 23:UctRMMBgX00BdqseUodnbtIbb2ONguaP41yKpwxui?= =?us-ascii?Q?Yq8j27MtFOkl6oXlFw8kZnEpNcq9t4NIGA1JkT+T+nRhW1o/namyvHxUoskC?= =?us-ascii?Q?iGUHGnD9Uq748O8z4c4eGB1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-ascii?Q?X3Kka74gM4AfQtTbXFjG2OPu56wE+zqyfmw4JeKVDMbxojmP9e3FjJdVjpTj?= =?us-ascii?Q?TKkDZkoY5uMblW75rvcrmoHOrPGgz9pzaLvplMxXZUWs5QJK7m7fCpNUCxV/?= =?us-ascii?Q?qW6Rh1cK/UnPdosI+/nnLflOcl/EpG9zPXvXuOZ+qlK8zd+KBYTfByL9T9Dn?= =?us-ascii?Q?eHiBxB1iRiF9OCziMRwYyaWBd8R9e9b0gYXMM9hNvzL3QxX9ScBR2CPv1l4B?= =?us-ascii?Q?bYLntV7Qfzf6/IUGoOwp7zLehrWun9lwxYRSjn1tp+PdJNj3tJSkXUoV7cZ6?= =?us-ascii?B?dz09?= X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0924; 5:t3cHe5I0Mp36yE7YQd3gVF1iCqc/70I/zwH+R5N1hCWQEH/9lQ7NGnbrieepOmI/Jo1+nb7Cr9l0S5IjPtWDbSG+wK726egi10QjWau1Mg6vFnBgsjQy4K0LXUHoKBZVx80a/tlBb/PPAlZWmtbAIg==; 24:5mZxvrLLK72dhfCm+3xznwdb9SbDWnGtLKipB9D5zwA+hbSU3B6lapGgb/LQqcgEQp3YVW/NSJmiun0v+uJYSjVUkFtIrKxydNkk5jVWibo=; 20:ooO+bb2gGKla3ek7uAlkw2uYRXVjEBkKQrYZHgAM87wX3ZCMiZ7olWW+cZ2ivkRHgFzxXHpwRM22iUI3+GVX7JNf384Xfr4Uv8FYn0YC58z94+gKL8YG53MZOAf0iOvBoW8N42Ld5b2e/OcM1NJlGv5WQfI4wHxLn4UW7zQ8OVw= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2015 01:44:46.8993 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0924 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.0 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 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 2696152..2b5d890 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;