From patchwork Wed May 24 12:04:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 9745889 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 7031D601C2 for ; Wed, 24 May 2017 12:07:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F6DC28966 for ; Wed, 24 May 2017 12:07:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53CB728968; Wed, 24 May 2017 12:07:07 +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=unavailable 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 92D7028966 for ; Wed, 24 May 2017 12:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764418AbdEXMGw (ORCPT ); Wed, 24 May 2017 08:06:52 -0400 Received: from relmlor1.renesas.com ([210.160.252.171]:50500 "EHLO relmlie4.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S936165AbdEXMGp (ORCPT ); Wed, 24 May 2017 08:06:45 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie4.idc.renesas.com with ESMTP; 24 May 2017 21:06:43 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 0C5B26D245; Wed, 24 May 2017 21:06:43 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.38,386,1491231600"; d="scan'208";a="244060572" Received: from mail-sg2apc01lp0246.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.246]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 24 May 2017 21:06:41 +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=kJ6plKU7RUu2EB6ij4UsJuS0mdjBwlyG2+QeF0N2Fwo=; b=VYfSguqYCZHJ375QwJhjinWB4MY/DykHYP8gIHpNkPCpD04NHoWsLf2c6jQvLOPYf0bpn08PmDLhVOWw4wjXuN9QmO4RN6mNGRqcl0iEMbNVAmWPDnkgiLZx+gGG7AeKBjspYzR/XiwBl7wK11IBnshRZwbGsueAlmJdTRhK3Fc= 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 HK2PR06MB0980.apcprd06.prod.outlook.com (2a01:111:e400:589d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Wed, 24 May 2017 12:06:39 +0000 From: Yoshihiro Shimoda To: , , CC: , , , Yoshihiro Shimoda Subject: [PATCH] phy: rcar-gen3-usb3: add support for R-Car Gen3 USB 3.0 PHY Date: Wed, 24 May 2017 21:04:03 +0900 Message-ID: <1495627443-28057-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: SG2PR04CA0074.apcprd04.prod.outlook.com (2a01:111:e400:7803::42) To HK2PR06MB0980.apcprd06.prod.outlook.com (2a01:111:e400:589d::26) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK2PR06MB0980: X-MS-Office365-Filtering-Correlation-Id: 0d06590a-4d67-4c76-dea6-08d4a29d55ee X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:HK2PR06MB0980; X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0980; 3:uu1C109wAo/BnK2NxDGrZYXI5k9Y44U0MTRsB7yzyAiMb9ZLQeqbf2T5rC3QiGwhISxU00mGjIzSyj73G0aWvUUTNfEr3IzSoKXkVplfBbjUZGkqJRXAzMgKZouQ87eKeEM3KEkVTlt75XCeaQI3Fa8KjdNsrd+Q+rCb1ajuN5cmK7d8BpF8ridde1i64c0epU75nRjjFFGWKnctRDqVB4Y3wBwHAiP+wbIEm15QqHMkm7X6dm91Uz8m+ULN/8lV3k3We81pGuNIPeGtbRKiQTHeozjH+biXWj2Mn/IdRcOSNy/YuKmqViTsNLWpMMZEI9JHg19qsJIwlBguIjHRvEnxvKvmsnJIGkiZoR5fMII=; 25:cKyr12no0sNgzzHe40P4ME43g0jmwxBHGoxaYuX4wury3FlF5B5UyEVIvyrg71QV5g+yF4pgHyOKyPnLZe8Y3AU+QGClWy1pCumh9qLGyleuoCTCFgsd7X4G7HTx0MTIvoaXIci34UjWIAB//u7tlxNfZi6bSWT6X5A3CKjvU09ffTWPS39eLujWOK098QSCdG1kboWt0OkFSIUAwMTEO4lT2hucOPqmV6ehxjhYSUrpz6CME2m+qYAhHGBA6uipGSBXd8xUgYTinpovP9Gvr1m37D8MtN+EhlZH3Wrr5YXZrWxVOaKZvRqsW5Lp9kPt9Y9BcQJrWc0OBsFKjrd2olGxuAIec7NPFOPWqC9U5eCqQbYejbUQjpMELJhaQV6HlXbOEQZnWAKDYXUyj1vXi9gGueYrgH4Mx1zKoKV3yie82S+AKh+Nt52iPXWTEqQpWIjHsuBX/OSp7Gx8NyksowTf93W9zbYPQbgjDhS3XsU= X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0980; 31:Q5Wd2BQr5V9BhpY2DOwJUKGnlpEZgWd0mB2qx7Z9rT/60p0FqI6krmbAn0dqtmPFciFzsbJcGLMx7gVF5k3rM336m7iFlpkAMHPE8t5kXL1KyGyTmpOrCzmQmTJMvuDMv35u2eeu6P0N9HVMFl8WxSGYP94oq10oY58co01b5NJMWscrCdOHv7iVsqeVzBtac6GokF4hYRlxrWB+nmT00LjrOnN+pkaoGdertCQj2AI=; 20:vLHACSVWB2WTmSHY2x4AL9aTB6QO/sTEhHqRxRv7yHlZjRhvzq/qRmZyHIN9iqNF/up8zC7v0WxJBXGczMvF2Lj44Si600hwysxmsgSFQz7UmtxfW+SE76Wt/m7wZiVX4kYzGJEY6oelYhSMvpR+qllJ9ZWU2j8KAUcefcktI5YMCdmMCqhKexmIh7AwiEr8c7fYZ6bVNvlRZk+lttYXKkaYLDBaXgcIjOWZMgrsDM838F1iYDa1ePuJoY/eHJj60LgUshhqgWdhkW1wy/Dnykw87HMjs3wdH+HkrV+IkZHnm0NFlHkspoKuTeA8EgdHdN+0ISSg5gYAOB9GdO104lJilRr0k2xDqcQRDtqyoCGR/kHr6FYgyWZFUH2CO6/HnOZ/THR6bCujtVBDxrwoAlAiUAo/HfGdMpH/tcnp7ay30RVQUULzADwbgbeAhHm8Fse8s2QpT2/aZQDCxbzJ10v92i5j4BvH/SZ7ddV7ACiuYDIALV4Sj7g60lFfiDXp 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)(8121501046)(5005006)(93006095)(10201501046)(3002001)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061750153)(20161123558100)(20161123562025)(20161123564025)(20161123555025)(20161123560025)(6072148); SRVR:HK2PR06MB0980; BCL:0; PCL:0; RULEID:; SRVR:HK2PR06MB0980; X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0980; 4:Wxpmbcb5QpU7L4IS6WwgFgyyzIOn7nRYlxp1xqP0FsG5+21PkddbIM94d3hjamWPrRf58pLJTX8BTsJxl8qHpT4WqzEGEqohis+i2rS8dehH/n5pL2fg6S6vbdq7pKwVer+2trN3rixjst/mFPKVllis2E1FW0+l2xe5YYxZGzGRkbIc9WO0J9lLOKlu3bujze5g4ZuGDCtVtl+dWTXhyQw5fmIDCCdFdh6sWDEaLI6sZ59NNGNSCsbuDYzJC86uocqd+h2+9nwCyfj9RH2uOlRUcbxZ07Kfk+tgKjzWAtv76ClA9gDSvk2JKgS5EH4ZYbUju+TsBawSxofuZTwXBawOhETOMbuTHV17ahEEv6XS3Qs82nbLdcR/WBsFsbAN62rIulUtV9CGEFlvGETTu4trUyfYfD1Yf9Gof+OqaqotywwufOT9WMStworR5fwxVNNu9rLCkiF6MzPWZ/H3w47dVTbc8Y4JR1G0+VWxdZTTNRU+B3WmciuFhv2dthNkWxaYIfypl4io/DCSnGmZ04CSDI5aFq8dnuBgyPHo8Dpky11pgeb8PbV/MFCGjaqEF5t7s+YiXv4fAeelCv4dNymRcWTCa8OeDhFPpKC1v2rYXvqqW8RuX8reoYdelCFgZZMt3rv8dUNaSV+KXOVA9xCEyrIxYHDeKrOYcgY8kEEg8S39rL97fIzRY3cvLVbZb0RD8iNRfMy3eFZJtMK6iXzLMTJ31jzBKEDtrrJriqSKnB7+2/eNR8V4ViwhBVI6wIECeq/v0LREE3yPHXRBNugoO/QYpl6vOd/7N+Ma1fX0vjZZzj00rApBYrt3AfuQ X-Forefront-PRVS: 031763BCAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(39450400003)(39840400002)(39860400002)(39410400002)(39400400002)(39850400002)(6506006)(6306002)(81166006)(107886003)(38730400002)(498600001)(78352004)(50226002)(966005)(6512007)(53936002)(4326008)(54906002)(189998001)(42882006)(6486002)(6666003)(25786009)(8676002)(3846002)(6116002)(230783001)(5660300001)(33646002)(7736002)(42186005)(50466002)(5003940100001)(305945005)(48376002)(36756003)(2906002)(47776003)(50986999)(66066001)(2004002)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:HK2PR06MB0980; H:localhost.localdomain; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HK2PR06MB0980; 23:8qF+4/syhVaS8CgSNAG1Vgx4YiJKuqCnQWYq+xyqT?= =?us-ascii?Q?xRhKs1tHlGaK37XziLd4Lm6WDXGxEusrSQOVxwpTXg/bTyUmz3xzRDLfg+x/?= =?us-ascii?Q?yk6IY1jtcRQQ/L0KRO1RIQavxHya1psvXUNJocV+qF2Y4t8wQeCqgXMIhJCb?= =?us-ascii?Q?bLY/0qIXD8K3Zh0HhZduBheVouHncX8sleKP9SRBMTeqKR3lspdl0FiRNO0D?= =?us-ascii?Q?EuzYkcUkJPORuk71W5z+A1fgB0EbMWchMTt9LvbGNjmTPyMihl92a4BZp/8x?= =?us-ascii?Q?aaVh16w5DFm/kq+aZaGrovjCLkERq9GONaATbcmw/6Z4m6CT+Zar6s3Y/49b?= =?us-ascii?Q?kWNDEzSWNgVLCNpOmU1MXXM94/uafEdiHkKRtplWwQDKSTXFGIwdO8Kd5MJA?= =?us-ascii?Q?RCw6uVc0FN3c2ZoMuQVF9NUDNgYcO31cvQBQpHAQPuFxQuX9uJdPQX9mSvzL?= =?us-ascii?Q?RnlG54n76gEWy4LsM4TE05RNY5NB7rMVaWWKQvxPh/kzxZaa0LX7DiSMZoGu?= =?us-ascii?Q?MnUw9Er4QGdON6rujedAp+8pZRoP1oa1mnHycc7vsHA9noO0tFT4v0fCKUXO?= =?us-ascii?Q?wIvSgbdkuhDCBLPK0wwtBIi9cu6iV2ullX97UpBBwPOl3spA157biRarFRtK?= =?us-ascii?Q?88UabLkFj0sGAbTh3H/aZB64WPFW9HYglOL+Mo4TgHur13+MZmEA5V8CGoX0?= =?us-ascii?Q?aWdlyGA1jApEuUemhSsFbAFgzpmd858iuKsOo9X5pzFV0PKKLaD1ojSOUagn?= =?us-ascii?Q?y3aaU1B9GElOo8aIN02JEPWRirsspjyQ2ntePlUJoMmqI22E9z+SzZvv1Ctv?= =?us-ascii?Q?kH2TxNZ+K8UFqdePlM2UOQyXE3ujsvbFa/y78q4euLhcDAxUUw701qEnBLzq?= =?us-ascii?Q?oCtbaARVGy2xnxZ7/CJuhpKFJOgQzvdz2HsudN/AIW/RPuauoJjNLI2NuPgz?= =?us-ascii?Q?J9ARBCDgZYqaXkjRi/TPxuUgHfpMIimcVvJDIM9w0JuIjyZxHxRn62Ajd4lY?= =?us-ascii?Q?wONlabp1jOkNsPIPc+vq5Auq2jekNcg162rz3/0efARnDJ6oCYYUfSPmsf9g?= =?us-ascii?Q?1biJ80KhZouTsDDzW1ykNHbTlJdxOoiD/UdovHnT4sepDVAd6KMaB/6kr2Mx?= =?us-ascii?Q?f5YvJJ64J9iPwoon0VvbapxfJhO57XH?= X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0980; 6:2cGONrQoMRHnQUWC/DnJZRzUCdNEPbvEHNxlIgqMOLbsRbr2TfEzgvuQgc3dL41IcQ7vgGfM4s7h5MqMB8xZO61SnXs/zm8buMb6y//2Z0svyeQmzBVlTVLX5XH34UYuIEN0aLLSnnxnN9cUmgvsmpE1tpmGzen1Dj84faC91Ai2PmiOXfyg8JMdxCPMxifiTAeZCV8RnGOnG03tQyZ7h+HvJ1/W+N2iHqvUG5RhzJJjQwo9V8vxu13oSZVCQqIBss7qFwUrbcosj74M2ag1uHQDS+uSQCElcd7wPzR+oNdwYsu+gfDLYx4BdjzJLJf/MB+Y7D7YGtBpYss+ihZcMxrqnYIT6kGd31FJ+2hLN+E2VEepnMJM+tNnPJjAtxA0UH9KFI3MuL+18938Z/9DacsjBy4FyAoEa17hCcmbPjwE6Tu9RiJsz/Ux8fIzQu9f44E7TnwR30qY7/GKfGrF1opzf23VPN8yK562VsqdSdbL55+VBy8+nK/XAUFHaWRkERNJLWUpLUBLOGbXF4IHY99W/iN3Pox90EeRa/lt4gTZvP02l7mIlMENlLyVymMy; 5:BCREdZLv97a8FW2eVeH1D8ynwupUknWhSCvzDrpjTFvc0JcDSzW8csZX1hWPXa5st5NzwQFxyzLhlveUY3m0bEGO3bgapraV9ah7l6o3hJxhdQZwH68nZB1pE947almUBVhbR4tW1zKf78RvTOdiEQ==; 24:+eVeLZI64+rwpUW+A1ELjZaeCL+LpslPSwQL61NfNzKZjn+Q/qwPaVZqsLs8ID33TmeQX6kL2CHECWvBxLINqn6/lrnhsREfnpq00/kB/vM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0980; 7:YtUv4cN33zjM6L9a21Z64WnLb6DosFxuQrLYvGX0jMPaGpY5ArRU7/dcdx+SwKNyApKfNxSE9rmzSv3pbpkYw0+rmh2cUMGFhJCaEWx7aVD3BnEbwXroxT6uXAp6KE/zDcPQffPuBVU6ROm83DerUa5Tuzz2btDoDLh5BQ66rFgv6juPBErZ5MrJvmUXmS3Eq/bkNfz4kxATsCoE/1xYa7SdkJ5Hi6JOjMqowabmmQYG2fGAH/Nl2eQ4KXye8iLtMW8GydL6fw2gmCBox5FmzrSyrKm7WuJmBZcw0PMpbUE+HsmWgSOj1yjciPAa93NPKsuqKA25Jq5Jtzgt7YFgLg==; 20:yiZ6dSb9L65yU/k9avepOWcZfLjAzCPbghKQ4+hdTcOTblxG3SX1Tq+Y/KWabgbSiX3EbFa3cc9BqXQ9c6Jm4kOfLd3T9YbK3XvZxGwekexsUSmuTMfiThSBOLQ5iZrkGe4PR8e+RSYZuDmXlTknvvPuAtsmvWS+hVe6xMEUwkc= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2017 12:06:39.0896 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2PR06MB0980 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/ .../devicetree/bindings/phy/rcar-gen3-phy-usb3.txt | 47 +++++ MAINTAINERS | 4 +- drivers/phy/renesas/Kconfig | 7 + drivers/phy/renesas/Makefile | 1 + drivers/phy/renesas/phy-rcar-gen3-usb3.c | 207 +++++++++++++++++++++ 5 files changed, 264 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..e58ba6b --- /dev/null +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb3.txt @@ -0,0 +1,47 @@ +* 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". If you want to use the ssc, + the clock-frequency must be 0. + - The usb2's external clock must be "usb_extal". If you want to use the ssc, + the clock-frequenvy 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..6238417 --- /dev/null +++ b/drivers/phy/renesas/phy-rcar-gen3-usb3.c @@ -0,0 +1,207 @@ +/* + * 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 + +#define USB30_CLKSET0 0x034 +#define USB30_CLKSET1 0x036 +#define USB30_SSC_SET 0x038 +#define USB30_VBUS_EN 0x064 + +#define CLKSET0_RESERVED 0x05c0 +#define CLKSET0_USB_EXTAL (CLKSET0_RESERVED | 0x0002) + +#define CLKSET1_PLL_MULTI_SHIFT 6 +#define CLKSET1_PLL_MULTI_USB_EXTAL (0x64 << CLKSET1_PLL_MULTI_SHIFT) +#define CLKSET1_REF_CLKDIV_USB_EXTAL BIT(3) +#define CLKSET1_RESERVED_1 BIT(1) +#define CLKSET1_REF_CLK_SEL_USB_EXTAL 0 +#define CLKSET1_USB_EXTAL (CLKSET1_PLL_MULTI_USB_EXTAL | \ + CLKSET1_REF_CLKDIV_USB_EXTAL | \ + CLKSET1_RESERVED_1 | \ + CLKSET1_REF_CLK_SEL_USB_EXTAL) + +#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) + +#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 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) +{ + writew(CLKSET0_USB_EXTAL, r->base + USB30_CLKSET0); + writew(CLKSET1_USB_EXTAL, r->base + USB30_CLKSET1); +} + +static int rcar_gen3_phy_usb3_init(struct phy *p) +{ + struct rcar_gen3_usb3 *r = phy_get_drvdata(p); + + dev_info(&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); + /* SSC can be enabled when usb_extal is used */ + if (r->ssc_range) + rcar_gen3_phy_usb3_enable_ssc(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,r8a7795-usb3-phy" }, + { .compatible = "renesas,r8a7796-usb3-phy" }, + { .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 ");