From patchwork Tue Oct 13 10:22:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7382861 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 A20DCBEEA4 for ; Tue, 13 Oct 2015 10:23:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96184207D7 for ; Tue, 13 Oct 2015 10:23:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0AC36207C2 for ; Tue, 13 Oct 2015 10:23:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752772AbbJMKW7 (ORCPT ); Tue, 13 Oct 2015 06:22:59 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:30551 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932069AbbJMKWZ (ORCPT ); Tue, 13 Oct 2015 06:22:25 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 13 Oct 2015 19:22:24 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 4AEC553CA4; Tue, 13 Oct 2015 19:22:24 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 42A352806E; Tue, 13 Oct 2015 19:22:24 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id 3C5472806D; Tue, 13 Oct 2015 19:22:24 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac2.idc.renesas.com with ESMTP id VAE17104; Tue, 13 Oct 2015 19:22:24 +0900 X-IronPort-AV: E=Sophos;i="5.17,677,1437404400"; d="scan'";a="197502670" Received: from mail-sg2apc01lp0244.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.244]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 13 Oct 2015 19:22:22 +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:20 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v4 2/3] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel Date: Tue, 13 Oct 2015 19:22:05 +0900 Message-ID: <1444731726-5328-3-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: HKXPR02CA0026.apcprd02.prod.outlook.com (25.161.48.11) To HK2PR06MB0913.apcprd06.prod.outlook.com (25.162.246.28) X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0913; 2:iVLllPrceDMQjxh9asgfwMPojIbb8x7gigAcsutqyRnptMP0rwML5tfbnrS2JME5qEdOaEOLgq8Yps8x8w4bgaa8cPtQt3PgjvWTqnHjx5BoCM7q1WY0rJ1Ryooftqd+mcXVgXbEPr00pNpZV2CEvcR7i7XIa7ZgtgTpeGprRUY=; 3:Phl29QBmIoR3F9nmPgSQpxEomsZp+acZGKyBeq62IJRpB9d4qsV4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Vv9gSRtsXFgY4IjL3wD1/kjNm99ZEvXE31QBiMrpoqFXn8VEAghNQRnuxkH6ZC24mMk1sE7dAOkuRwFqH+7Jv/3z5yHrxTE7aG9cCaCNVCDfPeU/oiwue/faHTehysgA27VcCKLUObzRTW3/AYJd2/UtHFYyMgaGy1CA47O1M24A1SmissZnvzRiQSE3SkXWR72A5e81ComWsFsZYLlnvnGkIeis/Yi/qEbjEhNtszHzldyD5iGrw7I6QXa9BLcmpK+iQ= 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)(575784001)(46102003)(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:NhOA3McDELM6V9IfYdlykrm53cIKHp5yrLq7GjbVx?= =?us-ascii?Q?lxtKRdP39pJAUZuPqXQ2jdGPPfrL4SNx5yy0aZbYrejUlGGSY94As7bt19qF?= =?us-ascii?Q?uKpm5rZcoJhRsqu46+zoEdU4/2wn9drvKL4pw2ttdFll7H+P0sGm2BuF/WDJ?= =?us-ascii?Q?UhQDQ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x?= =?us-ascii?Q?zu+0hkH/g6lr8HhCiZJsxSMbD7l5NxEZ/k6qTK33w2HjYaMmDWAXB3UcyjYq?= =?us-ascii?Q?Kr8xbZTPJpB0PDOxcOliTJSqYefShMi5U+3aj7FgQTsMShfgwkXRf36ONUw7?= =?us-ascii?Q?o1dC3JgX7DOCmDe+rQIgqZunOG5tmuIKOio?= X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0913; 5:db/qe2Jpp268NCkyW5gmBrV4mbfOhjRaze+1dKq8qlHalEFNMZaFIvoSyPa2fV+bMBu+chFAlhknvFVUOc4i1wCBARYNSOZDcM+vlQFXGEtxNVyLoAv3RBd43lL5WTgojVsmCqyNNn5OySQz4a54Ww==; 24:KX7duhKp7+FPPxAdPDj1YqkRnEhcydGPF02WaF1CIY5zOoCGeuFoyTA/9acUdIqdK+4/kSnD2hZ/ft/4gDIgMesNteK5CFsqWgwZyqfL5Ys=; 20:upcky58i6FIIINQZg2uUZcqyqM75OUzV7jQ6Unmr2ykIaYxKgFbQpVBwZrDMmDQXGUBY3203627Un14OJ5bdXvgerSUuPRlqkSRwA5BYqv0wHJKqimB32JWf9Idm3tHOZZIsDG68mhp0FfFaeOdnBc396Ht3t6BhHeMkVBhFl0w= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2015 10:22:20.9741 (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 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 | 126 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 2 deletions(-) diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c index d90dfcf..03d7079 100644 --- a/drivers/phy/phy-rcar-gen3-usb2.c +++ b/drivers/phy/phy-rcar-gen3-usb2.c @@ -25,6 +25,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) @@ -42,6 +46,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 @@ -68,6 +90,104 @@ struct rcar_gen3_chan { spinlock_t lock; }; +static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host) +{ + void __iomem *usb2_base = ch->usb2.base; + u32 tmp = readl(usb2_base + USB2_COMMCTRL); + + dev_dbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, tmp, host); + if (host) + tmp &= ~USB2_COMMCTRL_OTG_PERI; + else + tmp |= USB2_COMMCTRL_OTG_PERI; + writel(tmp, 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 tmp = readl(usb2_base + USB2_LINECTRL1); + + dev_dbg(&ch->phy->dev, "%s: %08x, %d, %d\n", __func__, tmp, dp, dm); + tmp &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD); + if (dp) + tmp |= USB2_LINECTRL1_DP_RPD; + if (dm) + tmp |= USB2_LINECTRL1_DM_RPD; + writel(tmp, 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 tmp = readl(usb2_base + USB2_ADPCTRL); + + dev_dbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, tmp, vbus); + if (vbus) + tmp |= USB2_ADPCTRL_DRVVBUS; + else + tmp &= ~USB2_ADPCTRL_DRVVBUS; + writel(tmp, 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; + + if (rcar_gen3_check_id(ch)) { + /* B-device? */ + if (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 tmp; + + tmp = readl(usb2_base + USB2_VBCTRL); + writel(tmp | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL); + tmp = readl(usb2_base + USB2_ADPCTRL); + writel(tmp | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); + tmp = readl(usb2_base + USB2_LINECTRL1); + rcar_gen3_set_linectrl(ch, 0, 0); + writel(tmp | 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); @@ -85,11 +205,13 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) /* Initialize HSUSB part */ if (hsusb_base) { - /* TODO: support "OTG" mode */ tmp = readl(hsusb_base + HSUSB_UGCTRL2); tmp = (tmp & ~HSUSB_UGCTRL2_USB0SEL) | - HSUSB_UGCTRL2_USB0SEL_HOST; + HSUSB_UGCTRL2_USB0SEL_OTG; writel(tmp & HSUSB_UGCTRL2_MASK, hsusb_base + HSUSB_UGCTRL2); + + /* Initialize otg part */ + rcar_gen3_init_otg(channel); } spin_unlock_irqrestore(&channel->lock, flags);