From patchwork Mon May 29 10:42:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 9753077 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5548E60249 for ; Mon, 29 May 2017 10:45:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AD572846B for ; Mon, 29 May 2017 10:45:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C0842847D; Mon, 29 May 2017 10:45:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EC9728474 for ; Mon, 29 May 2017 10:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750996AbdE2KpA (ORCPT ); Mon, 29 May 2017 06:45:00 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:21162 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750925AbdE2Ko6 (ORCPT ); Mon, 29 May 2017 06:44:58 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie3.idc.renesas.com with ESMTP; 29 May 2017 19:44:56 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 3951566DA8; Mon, 29 May 2017 19:44:56 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.38,413,1491231600"; d="scan'208";a="245533551" Received: from mail-hk2apc01lp0208.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.208]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 29 May 2017 19:44:55 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6tcSkgmEDpgX4ux+64/Yjp5kBXh4GwqOxEFdVLPBrlc=; b=I/FJVG0FrxFmwx5YuMkgyJc6C+TkFstr39hdamZexPYWJFwY7iSScarqQvlSabAML8FQZGUr1vfaFgk0Co4X6KJD4O9UcHVr/HlpbOKLpyzxDeHnhadJ0W2dZtkkTbXW0urruIzX3j90KCiw9EqmQqJS9EWn2FfGhkVAKfiCiAo= Authentication-Results: ti.com; dkim=none (message not signed) header.d=none; ti.com; dmarc=none action=none header.from=renesas.com; Received: from localhost.localdomain (211.11.155.144) by SIXPR06MB0986.apcprd06.prod.outlook.com (2a01:111:e400:51e9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Mon, 29 May 2017 10:44:52 +0000 From: Yoshihiro Shimoda To: , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v3] phy: rcar-gen3-usb3: add support for R-Car Gen3 USB 3.0 PHY Date: Mon, 29 May 2017 19:42:15 +0900 Message-ID: <1496054535-29826-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: KL1PR0201CA0037.apcprd02.prod.outlook.com (2603:1096:800::47) To SIXPR06MB0986.apcprd06.prod.outlook.com (2a01:111:e400:51e9::27) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SIXPR06MB0986: X-MS-Office365-Filtering-Correlation-Id: f938472f-b09d-4600-5c36-08d4a67fbd86 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:SIXPR06MB0986; X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0986; 3:22E2U9sEVO0pBhHpUdWPLtrkma3aFEXDsJ+5It8YBNSu3Ieu8Hfst5k9vqm3pgUtKK+cw8TZufIWAaWuJY0r11YqWcoQlrdj7S15zEERyZPWfqQlQCBcdymQ9kMwzsmTmarZVUWVaWRmO3yIgZ1O+09WdkOT3sLRoIcoZbGFC8wkHE5GRL0OtsIYawPjjFJogCuYsEKTbYUqOXf4bTE8Sck+eJsLhvFFXXVoLn9EPFPgeSiKU9dWQt+Hzj4dINNb1cA1wcUZZVSXU2bj21xyjXSYP1AqPoq4C/j5uwQltS8VHK8+HfVMNtCNjCVK/WSkwLOJ/xOPlSnzr/MXZKNSbQFRTAHxUXMGSdZpAqI5SFM=; 25:oCjD90clRYYkcFYTHmrU9dkyjwoySYTc7K/hF+nfQmg17nwMyzpXeV0OefwJHo/ooCK9fET4LMwDp6X0c0GkqqZDFPy1v7TOH4OhPfcEUdCJYeK0X7U6AmCAlhzQPuDK24XAHK5XuKOwZqurevHv7SxgumH15DcSDd152gdP4AZA6IEb6Gdm4X9LmSol7FgJI3xqji4Ex9Yo9X7vmknYFQ8JKrg8NeNQRLwiCVZM3r5EXk8yY4SpHlvucVhD1GUnVZZVFon2o+Q8PaHYN3gD4Ai/8hdWLlMGtYpjGUNXi8xpLhlUDogUtPrASggBryCTDC/QHvU36Pa/BCb9nPC/yqLAr2W+s9Mpcr1MdXlp/dyM40A3mdjmEWHeEPJAKRVxx8orpO30ffGKleu1wUpynlq0KFHHLUVzTJhvSZ3Nu+X9gybrejiYxYXqcdwwcp+M2q0BNon4ly2futVr98MzZE1aWv7DREgzsMYXAiQGHaA= X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0986; 31:qjIxkCLITQfDYVQ4hdm00hSqXJN5eRqrhI5106B+Q9uZGPAZUJNnAv3cwAjHbY9UInenloTsmbzJ7EtZngEJnYoLAvweEy8IWceuL8H9a9LMGZ07W779ZVohwBbE6vMQGTNLcasnDUAX/Yv+yaQjXc+48taTgk/FRZ8yYOjILHVskBUdwmiz+vih4xk33Kw3qM9alK3Lrxt3tKjr9y4yIhDmQHq9i7goP1/UaFT7kKU=; 20:y85RRGuwwR/5Kr7t0bKlAEgKJYeBasuu1xgwxiveJXIi7SUn+dg36EPDqYm93drlNypT5SaZaiublMOgZmttDxAFQ8nqauMsRUyKCFtaRcv3E+/roEURj6N2u0QmYgp9dQjH0D9GDwQ0WOd6F8MAAv/Lf77dKXVMfE/jjLUpidck42+tAtCli77Y5lFTyBSOHuyiDe3qjDUF/idTTNrr8qEJ1Vjk/cdX8VFtv+/DWHkwm2wZoygb1LZ3Eeg2rOsnffLJTGbadZZDYo+uq997Yjg6eQ784ah6GYOPpMNwp9fprxfoOaLG+V15ZHqTpRXiWZCPtzJunN8cOlsfXT5imuE/9vF6I6sbVWfVhfau086rtTOVfnQyfIUqq8Z513W6gUSX95bo6VJcEG+Hw7g9CcFXLiYLbD+Mb3cQE7dBrfFSqotikSHJrpFoxCVzbjVUtwMHzw3GCaBcuDjn7NIgEHq37DWd1l7p6YX7dmOGiJ6bOmDSW5jFP2jxiMka2V3+ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123558100)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061750153)(20161123560025)(20161123562025)(6072148); SRVR:SIXPR06MB0986; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB0986; X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0986; 4:JbP18pMt2LjoW+DMlJ7DckUMJYgpMrljrZ9CbsfyLbqc9j9BPHX30ZBTZljCs4HeaSQrHVyqyCelUybNY4VQzr7BwLB+7nuPa7ensooz+bCFHEa1OiVc5uHs12NAOU3NTy34wzME75ItoR1cx01CeaPu+7vDBiCqoODFymDKpQrX4hcBXx+dTimc/qf/NnLX6JUq+x8X2IgkfgJMWS939eojHikQpUHcntgGeG1hqeCPc/OIKbsCdkNczCHD1E1iIE9MbfeQW+A7E0Tt70CkTDg+JYaxRyVcOMsaZq3BJIMW9a3+vJ6WcZ/nd1RTMRTCZ2E1P5EwbJSbsy5CO9L6mDyvBMDy8cBgp5q88AsIjLDUDygKyq3I4KHbRADcOKxlb6a/AV3zlQFirdyqMik0PWJFDWFHkczMo/luXKa/v4ue4t4Jz+Foqj+vlNk0xEHhZK2Su9aula6JdsSs2frqFlFgRU4fZ0g99jKqqQ19YFVw4s1hSzM//7ImS2RamU2tnOqpxFvs4+f8KeAKq83NiT0RYe6vv9Gmaji307LJwvfcsAgaoIzIZX5EAf9+GjBwLV6S4QR5SxhFEbnqBt2wNXXImamMADkqjcRwfBK9VGbUeGSEHSvLIRjW+CNE+KUHL8vIyGCnoDPyqHq/AklV77EOUb6VBZNj7L1UANqRqPkRKTEpWhBHerSsjagzf26KvZJVtdewDbCDaxwZtzON4UxcNxdHqda9hxWWiJcON1S2D8jESnaNI56SYTE0gCUJfOA3t8rdLED9HvTQGY4jbWbODCeJZQ3BiJekv/ua7OEhj+X6tfFKJetvZwuLn0U7XtpQT3cfoNdiKHO6IU8UZQ== X-Forefront-PRVS: 0322B4EDE1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(39450400003)(39840400002)(39860400002)(39400400002)(39410400002)(39850400002)(966005)(54906002)(6486002)(189998001)(6512007)(42882006)(6666003)(6306002)(498600001)(6506006)(38730400002)(107886003)(53936002)(3846002)(6116002)(36756003)(33646002)(7736002)(42186005)(305945005)(81166006)(8676002)(50986999)(48376002)(5003940100001)(4326008)(50226002)(50466002)(78352004)(47776003)(25786009)(5660300001)(66066001)(2906002)(230783001)(2004002)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB0986; H:localhost.localdomain; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SIXPR06MB0986; 23:6tv70OMRBISbZAkwFk5F+5KC6xMwj9iO7ELNjXB4h?= =?us-ascii?Q?9Ysaaqg93/lMGK7YH5K1ZZooq5p6pnH/sCYOrBZi2IkCEdet7eZkf77lk2j/?= =?us-ascii?Q?iewZIHEyILHwcO88p1da2+6rDtndrfKTFr6QNDCjJNWIOuIW/CoVqv+F4ZPH?= =?us-ascii?Q?WoNDQ933deSwg3l8Mcme2p9zv+GeyELhq74gs8ebAceuukYn+57NA3a2YhHC?= =?us-ascii?Q?3YS6FoObsr4jOP2rUtpLAJ6JdLkF2ZOoPNlgKdh+OZ+bTUJqHrhOu2m9F7Xs?= =?us-ascii?Q?z8F8GimNp+Q0nW9pqrD5Pmn75IPqHOhp+/Dt6ARP/CsufuLPT5zOl8jc4PlB?= =?us-ascii?Q?LRMO0lTu9ZLUeJkTvJjgjh/oa728EuzM7kMQLvzpjfN3EVAJgMRMQUmMt2UV?= =?us-ascii?Q?hJQrrzyUpI1OhIn+aFOwmLFxxMrI5BXnwPanSvgSaRBBGzyCfgFJAuiTOiCI?= =?us-ascii?Q?x74IBbXumZxMPRvne8zW9cJz9AQQABepdvx5DiJZ59wS3zV00fkg18CBQqNR?= =?us-ascii?Q?iXBlhdWhcdhZgi/seZmRWwcggpddRrbUg8+YipOkrdfvcmbFl1Tug0fqGHqd?= =?us-ascii?Q?PiJ+PyQoOqPM3ThuJDVPeq0E3hD2VDAdkC7sTKKCmEz7RFJPvzf0F4ZdHWqc?= =?us-ascii?Q?etXDFjWc+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S-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2017 10:44:52.8714 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0986 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The USB 3.0 PHY modules of R-Car Gen3 SoCs have: - Spread spectrum clock (ssc). - Using USB 2.0 EXTAL clock instead of USB 3.0 clock. - Enabling VBUS detection for usb3.0 peripheral. So, this driver supports these features. Signed-off-by: Yoshihiro Shimoda --- This patch is based on the latest linux-phy.git / next branch and "[PATCH v5 3/3] phy: Group vendor specific phy drivers" patch. I discussed with Geert-san about this driver on the ML: https://patchwork.kernel.org/patch/9731759/ Changes from v2: - Revise the device tree doc. - Improve initialization method in rcar_gen3_phy_usb3_init(). - remove some values from rcar_gen3_phy_usb3_match_table. Changes from v1: - Changes from dev_info to dev_vdbg in rcar_gen3_phy_usb3_init(). .../devicetree/bindings/phy/rcar-gen3-phy-usb3.txt | 46 +++++ MAINTAINERS | 4 +- drivers/phy/renesas/Kconfig | 7 + drivers/phy/renesas/Makefile | 1 + drivers/phy/renesas/phy-rcar-gen3-usb3.c | 226 +++++++++++++++++++++ 5 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb3.txt create mode 100644 drivers/phy/renesas/phy-rcar-gen3-usb3.c diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb3.txt b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb3.txt new file mode 100644 index 0000000..f94cea4 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb3.txt @@ -0,0 +1,46 @@ +* Renesas R-Car generation 3 USB 3.0 PHY + +This file provides information on what the device node for the R-Car generation +3 USB 3.0 PHY contains. +If you want to enable spread spectrum clock (ssc), you should use USB_EXTAL +instead of USB3_CLK. However, if you don't want to these features, you don't +need this driver. + +Required properties: +- compatible: "renesas,r8a7795-usb3-phy" if the device is a part of an R8A7795 + SoC. + "renesas,r8a7796-usb3-phy" if the device is a part of an R8A7796 + SoC. + "renesas,rcar-gen3-usb3-phy" for a generic R-Car Gen3 compatible + device. + + When compatible with the generic version, nodes must list the + SoC-specific version corresponding to the platform first + followed by the generic version. + +- reg: offset and length of the USB 3.0 PHY register block. +- clocks: A list of phandles and clock-specifier pairs. +- clock-names: Name of the clocks. + - The funcional clock must be "usb3-if". + - The usb3's external clock must be "usb3s_clk". + - The usb2's external clock must be "usb_extal". If you want to use the ssc, + the clock-frequency must not be 0. +- #phy-cells: see phy-bindings.txt in the same directory, must be <0>. + +Optional properties: +- renesas,ssc-range: Enable/disable spread spectrum clock (ssc) by using + the following values as u32: + - 0 (or the property doesn't exist): disable the ssc + - 4980: enable the ssc as -4980 ppm + - 4492: enable the ssc as -4492 ppm + - 4003: enable the ssc as -4003 ppm + +Example (R-Car H3): + + usb-phy@e65ee000 { + compatible = "renesas,r8a7795-usb3-phy", + "renesas,rcar-gen3-usb3-phy"; + reg = <0 0xe65ee000 0 0x90>; + clocks = <&cpg CPG_MOD 328>, <&usb3s0_clk>, <&usb_extal>; + clock-names = "usb3-if", "usb3s_clk", "usb_extal"; + }; diff --git a/MAINTAINERS b/MAINTAINERS index a47d3da..d711d53 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10829,11 +10829,11 @@ L: linux-iio@vger.kernel.org S: Supported F: drivers/iio/adc/rcar_gyro_adc.c -RENESAS USB2 PHY DRIVER +RENESAS USB PHY DRIVER M: Yoshihiro Shimoda L: linux-renesas-soc@vger.kernel.org S: Maintained -F: drivers/phy/renesas/phy-rcar-gen3-usb2.c +F: drivers/phy/renesas/phy-rcar-gen3-usb*.c RESET CONTROLLER FRAMEWORK M: Philipp Zabel diff --git a/drivers/phy/renesas/Kconfig b/drivers/phy/renesas/Kconfig index 432e271..4377064 100644 --- a/drivers/phy/renesas/Kconfig +++ b/drivers/phy/renesas/Kconfig @@ -15,3 +15,10 @@ config PHY_RCAR_GEN3_USB2 select GENERIC_PHY help Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs. + +config PHY_RCAR_GEN3_USB3 + tristate "Renesas R-Car generation 3 USB 3.0 PHY driver" + depends on ARCH_RENESAS + select GENERIC_PHY + help + Support for USB 3.0 PHY found on Renesas R-Car generation 3 SoCs. diff --git a/drivers/phy/renesas/Makefile b/drivers/phy/renesas/Makefile index 695241a..8b60259 100644 --- a/drivers/phy/renesas/Makefile +++ b/drivers/phy/renesas/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o obj-$(CONFIG_PHY_RCAR_GEN3_USB2) += phy-rcar-gen3-usb2.o +obj-$(CONFIG_PHY_RCAR_GEN3_USB3) += phy-rcar-gen3-usb3.o diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb3.c b/drivers/phy/renesas/phy-rcar-gen3-usb3.c new file mode 100644 index 0000000..88c83c9 --- /dev/null +++ b/drivers/phy/renesas/phy-rcar-gen3-usb3.c @@ -0,0 +1,226 @@ +/* + * Renesas R-Car Gen3 for USB3.0 PHY driver + * + * Copyright (C) 2017 Renesas Electronics Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define USB30_CLKSET0 0x034 +#define USB30_CLKSET1 0x036 +#define USB30_SSC_SET 0x038 +#define USB30_PHY_ENABLE 0x060 +#define USB30_VBUS_EN 0x064 + +/* USB30_CLKSET0 */ +#define CLKSET0_PRIVATE 0x05c0 +#define CLKSET0_USB30_FSEL_USB_EXTAL 0x0002 + +/* USB30_CLKSET1 */ +#define CLKSET1_USB30_PLL_MULTI_SHIFT 6 +#define CLKSET1_USB30_PLL_MULTI_USB_EXTAL (0x64 << \ + CLKSET1_USB30_PLL_MULTI_SHIFT) +#define CLKSET1_PHYRESET BIT(4) /* 1: reset */ +#define CLKSET1_REF_CLKDIV BIT(3) /* 1: USB_EXTAL */ +#define CLKSET1_PRIVATE_2_1 BIT(1) /* Write B'01 */ +#define CLKSET1_REF_CLK_SEL BIT(0) /* 1: USB3S0_CLK_P */ + +/* USB30_SSC_SET */ +#define SSC_SET_SSC_EN BIT(12) +#define SSC_SET_RANGE_SHIFT 9 +#define SSC_SET_RANGE_4980 (0x0 << SSC_SET_RANGE_SHIFT) +#define SSC_SET_RANGE_4492 (0x1 << SSC_SET_RANGE_SHIFT) +#define SSC_SET_RANGE_4003 (0x2 << SSC_SET_RANGE_SHIFT) + +/* USB30_PHY_ENABLE */ +#define PHY_ENABLE_RESET_EN BIT(4) + +/* USB30_VBUS_EN */ +#define VBUS_EN_VBUS_EN BIT(1) + +struct rcar_gen3_usb3 { + void __iomem *base; + struct phy *phy; + u32 ssc_range; + bool usb3s_clk; + bool usb_extal; +}; + +static void write_clkset1_for_usb_extal(struct rcar_gen3_usb3 *r, bool reset) +{ + u16 val = CLKSET1_USB30_PLL_MULTI_USB_EXTAL | + CLKSET1_REF_CLKDIV | CLKSET1_PRIVATE_2_1; + + if (reset) + val |= CLKSET1_PHYRESET; + + writew(val, r->base + USB30_CLKSET1); +} + +static void rcar_gen3_phy_usb3_enable_ssc(struct rcar_gen3_usb3 *r) +{ + u16 val = SSC_SET_SSC_EN; + + switch (r->ssc_range) { + case 4980: + val |= SSC_SET_RANGE_4980; + break; + case 4492: + val |= SSC_SET_RANGE_4492; + break; + case 4003: + val |= SSC_SET_RANGE_4003; + break; + default: + dev_err(&r->phy->dev, "%s: unsupported range (%x)\n", __func__, + r->ssc_range); + return; + } + + writew(val, r->base + USB30_SSC_SET); +} + +static void rcar_gen3_phy_usb3_select_usb_extal(struct rcar_gen3_usb3 *r) +{ + write_clkset1_for_usb_extal(r, false); + if (r->ssc_range) + rcar_gen3_phy_usb3_enable_ssc(r); + writew(CLKSET0_PRIVATE | CLKSET0_USB30_FSEL_USB_EXTAL, + r->base + USB30_CLKSET0); + writew(PHY_ENABLE_RESET_EN, r->base + USB30_PHY_ENABLE); + write_clkset1_for_usb_extal(r, true); + usleep_range(10, 20); + write_clkset1_for_usb_extal(r, false); +} + +static int rcar_gen3_phy_usb3_init(struct phy *p) +{ + struct rcar_gen3_usb3 *r = phy_get_drvdata(p); + + dev_vdbg(&r->phy->dev, "%s: enter (%d, %d, %d)\n", __func__, + r->usb3s_clk, r->usb_extal, r->ssc_range); + + if (!r->usb3s_clk && r->usb_extal) + rcar_gen3_phy_usb3_select_usb_extal(r); + + /* Enables VBUS detection anyway */ + writew(VBUS_EN_VBUS_EN, r->base + USB30_VBUS_EN); + + return 0; +} + +static const struct phy_ops rcar_gen3_phy_usb3_ops = { + .init = rcar_gen3_phy_usb3_init, + .owner = THIS_MODULE, +}; + +static const struct of_device_id rcar_gen3_phy_usb3_match_table[] = { + { .compatible = "renesas,rcar-gen3-usb3-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb3_match_table); + +static int rcar_gen3_phy_usb3_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct rcar_gen3_usb3 *r; + struct phy_provider *provider; + struct resource *res; + int ret = 0; + struct clk *clk; + + if (!dev->of_node) { + dev_err(dev, "This driver needs device tree\n"); + return -EINVAL; + } + + r = devm_kzalloc(dev, sizeof(*r), GFP_KERNEL); + if (!r) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + r->base = devm_ioremap_resource(dev, res); + if (IS_ERR(r->base)) + return PTR_ERR(r->base); + + clk = devm_clk_get(dev, "usb3s_clk"); + if (!IS_ERR(clk) && !clk_prepare_enable(clk)) { + r->usb3s_clk = !!clk_get_rate(clk); + clk_disable_unprepare(clk); + } + clk = devm_clk_get(dev, "usb_extal"); + if (!IS_ERR(clk) && !clk_prepare_enable(clk)) { + r->usb_extal = !!clk_get_rate(clk); + clk_disable_unprepare(clk); + } + + if (!r->usb3s_clk && !r->usb_extal) { + dev_err(dev, "This driver needs usb3s_clk and/or usb_extal\n"); + ret = -EINVAL; + goto error; + } + + /* + * devm_phy_create() will call pm_runtime_enable(&phy->dev); + * And then, phy-core will manage runtime pm for this device. + */ + pm_runtime_enable(dev); + + r->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb3_ops); + if (IS_ERR(r->phy)) { + dev_err(dev, "Failed to create USB3 PHY\n"); + ret = PTR_ERR(r->phy); + goto error; + } + + of_property_read_u32(dev->of_node, "renesas,ssc-range", &r->ssc_range); + + platform_set_drvdata(pdev, r); + phy_set_drvdata(r->phy, r); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + if (IS_ERR(provider)) { + dev_err(dev, "Failed to register PHY provider\n"); + ret = PTR_ERR(provider); + goto error; + } + + return 0; + +error: + pm_runtime_disable(dev); + + return ret; +} + +static int rcar_gen3_phy_usb3_remove(struct platform_device *pdev) +{ + pm_runtime_disable(&pdev->dev); + + return 0; +}; + +static struct platform_driver rcar_gen3_phy_usb3_driver = { + .driver = { + .name = "phy_rcar_gen3_usb3", + .of_match_table = rcar_gen3_phy_usb3_match_table, + }, + .probe = rcar_gen3_phy_usb3_probe, + .remove = rcar_gen3_phy_usb3_remove, +}; +module_platform_driver(rcar_gen3_phy_usb3_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Renesas R-Car Gen3 USB 3.0 PHY"); +MODULE_AUTHOR("Yoshihiro Shimoda ");