From patchwork Mon Nov 19 11:08:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 151480 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2521159ljp; Mon, 19 Nov 2018 03:09:03 -0800 (PST) X-Google-Smtp-Source: AJdET5fvCcDQ7k7vPoqtgM1O6x6tZ6xPKuSkgojP6Stx9aAsAoZkNBXkYjvdWbEozgS3pt16ioIx X-Received: by 2002:a63:151f:: with SMTP id v31mr19412107pgl.34.1542625743445; Mon, 19 Nov 2018 03:09:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542625743; cv=none; d=google.com; s=arc-20160816; b=VL6SQg7O37a32mX2hz/jdcKaZG2n5CtVXU24amFj3RcEFRedVfe1Ea6+MCMHzi+L3x AC3fqEN6GggSJFSS4lhZUyKHJq3ymlUV1J0DVCu38057rxjdjEdgnQbHbTrG5ePqNx/M xTVxQQun+q5y7BK/NBsbWoYKUt/qgrIMhgD6osj3tj3y9cd/fYVYLcWqrGNJsVV7zLRN uBEaFjnEB82UWvkatElmJcLgmtBmfVzaJmFh/z4t54uf+MXBo3PoOekqiVJOsB5wgXiy u6O108ovp9frk2XFtUFlUsHLk6glOg8sDT80wWMVaKWjHB6ia7gyxkxhTlMJj/A8ZJBs Tx1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wBYo41bp2nljZaRVn1LYU/0Y2JzxwRkpjYo0a4rKUbs=; b=zKw5zNceJDjIplPcBQgX0OjjEF7T9f1vsWRvg4EceDuewEr1Ld4HJTk1vvohbUrber DgPwM4wEdhB7cg6EGOlnEa1MVyaegfG27PBRuY8B6W/hgEcJKgiwX5uCVIj1wFlJ9IHt hJnVuvR1yI0kAJhj6i+Kc2BUcUxxUtt71j7YoGVXSN0BGcBAna07qwrb9FSFkaK9YtaM tKQ0z4MkdesXs/CguWNAagvt0Dj346Nnaz5IRMvhLRONwLsr2/RqbURxbcIuMMOdAVeG cXiQLyWxEEdiKdRwTLi1W3Lu1yl1/3mM+dWpo5vjhqQrOsxaRlQOVaWaRfNRRU++jTkL 0q+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xe7FI8fn; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63si9617722pfg.194.2018.11.19.03.09.03; Mon, 19 Nov 2018 03:09:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xe7FI8fn; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728514AbeKSVcM (ORCPT + 15 others); Mon, 19 Nov 2018 16:32:12 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41739 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728562AbeKSVcM (ORCPT ); Mon, 19 Nov 2018 16:32:12 -0500 Received: by mail-pg1-f195.google.com with SMTP id 70so13696025pgh.8 for ; Mon, 19 Nov 2018 03:08:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wBYo41bp2nljZaRVn1LYU/0Y2JzxwRkpjYo0a4rKUbs=; b=Xe7FI8fnfdjJi6AyzyVrSeVaOgCfijPl4/408aCn36qij4chSK2idYDy60NwZlDVWp HnnqETsoX9qEhBXJjcGukVG4vzBmNQfS35U2lZMtRcj3c0y18wb6I5aV4/XO0YZ1/Z8V wn85MY/Z8D/PezemAV4W73Bi0BUQEaM2stnoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wBYo41bp2nljZaRVn1LYU/0Y2JzxwRkpjYo0a4rKUbs=; b=Apq0dfUlt9M22Fkcz/8lXtgg6OCIMWyTFSP7MH6eXlJ20H5kA3u5to1U3PNbdlWF/6 zAzsDqxyUZdiJxQztq2t0xBHj2+9nxQ+DkTrnD7xHOvBpWphk89Vf47sGniHhb3ct2Ll 1wNxS9i6OStmTAJmZY5WZjNldpGCpFXBwXLnooriLFBJgsLsdNcPwXIPoIv1lX4ISGEp UEW9t0y1CKtBOqB5bD8ONiKD1Zst7KxBNghyqY4MO3L2ffQTFHC7ujWxPSkk2Fhy23Tx SwdNEISvUipchvFWSkLRcLmjP1fumCCnNTZfyp5yHYvPf9coxUFr/yWZV71PyQhkqO36 uD5g== X-Gm-Message-State: AGRZ1gLvP64GlesIQL2BZGRbsxDGn2RUT4kjVUsTJXlSsWuoHbSytZA5 NO44f5+0IVi1Cxf4k57AmEBixg== X-Received: by 2002:a62:5146:: with SMTP id f67-v6mr22705390pfb.238.1542625734302; Mon, 19 Nov 2018 03:08:54 -0800 (PST) Received: from localhost.localdomain (61-216-91-114.HINET-IP.hinet.net. [61.216.91.114]) by smtp.gmail.com with ESMTPSA id q25sm43906934pgb.2.2018.11.19.03.08.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Nov 2018 03:08:53 -0800 (PST) From: Shawn Guo To: Kishon Vijay Abraham I Cc: Rob Herring , Sriharsha Allenki , Anu Ramanathan , Bjorn Andersson , Vinod Koul , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v4 1/2] dt-bindings: phy: Add Qualcomm Synopsys High-Speed USB PHY binding Date: Mon, 19 Nov 2018 19:08:11 +0800 Message-Id: <20181119110812.15825-2-shawn.guo@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181119110812.15825-1-shawn.guo@linaro.org> References: <20181119110812.15825-1-shawn.guo@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Sriharsha Allenki It adds bindings for Synopsys 28nm femto phy controller that supports LS/FS/HS usb connectivity on Qualcomm chipsets. Signed-off-by: Sriharsha Allenki Signed-off-by: Anu Ramanathan Signed-off-by: Bjorn Andersson Signed-off-by: Shawn Guo --- .../phy/qcom,snps-28nm-usb-hs-phy.txt | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-28nm-usb-hs-phy.txt -- 2.18.0 Reviewed-by: Rob Herring diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-28nm-usb-hs-phy.txt b/Documentation/devicetree/bindings/phy/qcom,snps-28nm-usb-hs-phy.txt new file mode 100644 index 000000000000..301987e716fd --- /dev/null +++ b/Documentation/devicetree/bindings/phy/qcom,snps-28nm-usb-hs-phy.txt @@ -0,0 +1,87 @@ +Qualcomm Synopsys 28nm Femto phy controller +=========================================== + +Synopsys 28nm femto phy controller supports LS/FS/HS usb connectivity on +Qualcomm chipsets. + +Required properties: + +- compatible: + Value type: + Definition: Should contain "qcom,qcs404-usb-hsphy". + +- reg: + Value type: + Definition: USB PHY base address and length of the register map. + +- #phy-cells: + Value type: + Definition: Should be 0. See phy/phy-bindings.txt for details. + +- clocks: + Value type: + Definition: See clock-bindings.txt section "consumers". List of + three clock specifiers for reference, phy core and + sleep clocks. + +- clock-names: + Value type: + Definition: Names of the clocks in 1-1 correspondence with the "clocks" + property. Must contain "ref", "phy" and "sleep". + +- resets: + Value type: + Definition: See reset.txt section "consumers". PHY reset specifiers + for phy core and POR resets. + +- reset-names: + Value type: + Definition: Names of the resets in 1-1 correspondence with the "resets" + property. Must contain "phy" and "por". + +- vdd-supply: + Value type: + Definition: phandle to the regulator VDD supply node. + +- vdda1p8-supply: + Value type: + Definition: phandle to the regulator 1.8V supply node. + +- vdda3p3-supply: + Value type: + Definition: phandle to the regulator 3.3V supply node. + +- qcom,vdd-voltage-level: + Value type: + Definition: This is a list of three integer values where + each value corresponding to voltage corner in uV. + +Optional child nodes: + +- The link to the USB connector should be modeled using the OF graph bindings + specified in bindings/graph.txt. + +Example: + + phy@7a000 { + compatible = "qcom,qcs404-usb-hsphy"; + reg = <0x7a000 0x200>; + #phy-cells = <0>; + clocks = <&rpmcc RPM_SMD_LN_BB_CLK>, + <&gcc GCC_USB_HS_PHY_CFG_AHB_CLK>, + <&gcc GCC_USB2A_PHY_SLEEP_CLK>; + clock-names = "ref", "phy", "sleep"; + resets = <&gcc GCC_USB_HS_PHY_CFG_AHB_BCR>, + <&gcc GCC_USB2A_PHY_BCR>; + reset-names = "phy", "por"; + vdd-supply = <&vreg_l4_1p2>; + vdda1p8-supply = <&vreg_l5_1p8>; + vdda3p3-supply = <&vreg_l12_3p3>; + qcom,vdd-voltage-level = <0 1144000 1200000>; + + port { + ep_usb_phy: endpoint { + remote-endpoint = <&ep_usb_con>; + }; + }; + }; From patchwork Mon Nov 19 11:08:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 151481 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2521590ljp; Mon, 19 Nov 2018 03:09:26 -0800 (PST) X-Google-Smtp-Source: AJdET5e85tfQpbbeAEPT0ns+sjO+g0F7Jab78CuCDXeXrjHtk+i2M8wWOkFlLkk6ghoElEW5gB2i X-Received: by 2002:a62:4497:: with SMTP id m23-v6mr22437554pfi.189.1542625766810; Mon, 19 Nov 2018 03:09:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542625766; cv=none; d=google.com; s=arc-20160816; b=01mBKhh6cX8gJRG3cuEX4ndGliblC8EVBnEZbkw5zVAbH5j7Tw1ykaHuDfLTndZB4a ssLQ5n8Md4hbs++0WJyjBChWJuzzLkp+XVAncrth3aTRvbcdos7clZy208dA/nwh3V86 YuE81yy845ryhq/1365YKbeuRr+KSouHI2Gd57JSrhGotoFJK4HZPoPZWJgQzOCesKIC vfns8ejcQbuyhqWsmENBCg5HXvDfz5f/pcQn/pV8UGcHsqbQLV1mEafmAZL4vGYzLd8T rvMWyutHRO8vkqonSPuWV4u2ts2TZZY6h8SeD9F+3c3d18BYqtS+HpNv9wlEE73M2pa1 EJ3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=NaYQMXoe79exCmcvEQJdqIUwRax8RIAZ/jbwdh7NZeQ=; b=vXLBrVnh5btT12x68AjkbS9U94nuHIA0cPIvQ305Cbv9Eu9NYngqQZA9spKmTZqM8P bCz8DjeIevmZwPQc07Z4P7sRFNNs+FR7ekdfa7oFuHGw5fScRYYTbITltpwCkjb31K03 8kjoJyjYZWN/owrR5V+PHHXiywHtDrsPJ3r76DW2rm48hxpMAmVwsINHZj5FF8s+9Els ElOTSGIikDJtaQxLSk7g6Oh8q7ti8vSB4QcGQ7uRTMYGvjvnXcGuG4gHWltW4qzBWHhA /zpIV2zN8TCViPDVqzr4koB8qMZIfaiq2xjNldNpzN5lBd3nX+boJwe9L+p7gKZzZZVc +IPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LkLuTKhZ; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63si9617722pfg.194.2018.11.19.03.09.26; Mon, 19 Nov 2018 03:09:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LkLuTKhZ; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728563AbeKSVcR (ORCPT + 15 others); Mon, 19 Nov 2018 16:32:17 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36576 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728585AbeKSVcR (ORCPT ); Mon, 19 Nov 2018 16:32:17 -0500 Received: by mail-pg1-f195.google.com with SMTP id n2so6521568pgm.3 for ; Mon, 19 Nov 2018 03:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NaYQMXoe79exCmcvEQJdqIUwRax8RIAZ/jbwdh7NZeQ=; b=LkLuTKhZodcDV2M7yTOxhknHmoCycVUxA/oLHCMs6UEF8BagMkshhHAn1+MWAammbk NSbVXc++EAnx4hHYqxB6t2GG2N/OWulE1k52CllV3jlBSFN24JGZbNgwpsPZr6qglbIt eTrcQ5eZssGKYq7Rsx+ILG+absReJMzF6GhAI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NaYQMXoe79exCmcvEQJdqIUwRax8RIAZ/jbwdh7NZeQ=; b=keL+VjYaBKNPh7pPKadGrFRr50m0LrBCYVOw7CUkU6JUGmzK0Yc59RVZAhP0+IHlp8 KuzfxrkK4am26Mbbwx6LtUFibUMDqKv3qCRCEkN6pn4Of/lVDXiAHboLb6OBF5TXeOFd 7wGmv13k+Q20AEYk2n0qpMvokr4ov0mkHN5hhpxLj1mjl3mq0BEOJMw2ITKEtg0O7ot8 gkWhnjZrkZ5A//dQwfpdVPywTNrOeT6VGG3eQhanV2Jq2tABinc/RgV619fTDJN9L/ae pT1KQGp1WPA+n47pr8Xda82zRBT9tLHG5R2rRoiLP2SmwME61esg5iOK3pp25xeNeIZe ONjg== X-Gm-Message-State: AA+aEWawFnmaYgTMzjqCm1mVpwtHVZPU6FwSH9p2WoRqRmZ/n0Y1xr6M vpcVDRGP1eq6AjmPhK7dLWlT1g== X-Received: by 2002:a65:534b:: with SMTP id w11mr10371772pgr.125.1542625739171; Mon, 19 Nov 2018 03:08:59 -0800 (PST) Received: from localhost.localdomain (61-216-91-114.HINET-IP.hinet.net. [61.216.91.114]) by smtp.gmail.com with ESMTPSA id q25sm43906934pgb.2.2018.11.19.03.08.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Nov 2018 03:08:57 -0800 (PST) From: Shawn Guo To: Kishon Vijay Abraham I Cc: Rob Herring , Sriharsha Allenki , Anu Ramanathan , Bjorn Andersson , Vinod Koul , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v4 2/2] phy: qualcomm: Add Synopsys High-Speed USB PHY driver Date: Mon, 19 Nov 2018 19:08:12 +0800 Message-Id: <20181119110812.15825-3-shawn.guo@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181119110812.15825-1-shawn.guo@linaro.org> References: <20181119110812.15825-1-shawn.guo@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org It adds Synopsys 28nm Femto High-Speed USB PHY driver support, which is usually paired with Synopsys DWC3 USB controllers on Qualcomm SoCs. Signed-off-by: Shawn Guo --- drivers/phy/qualcomm/Kconfig | 10 + drivers/phy/qualcomm/Makefile | 1 + .../phy/qualcomm/phy-qcom-usb-hs-snsp-28nm.c | 535 ++++++++++++++++++ 3 files changed, 546 insertions(+) create mode 100644 drivers/phy/qualcomm/phy-qcom-usb-hs-snsp-28nm.c -- 2.18.0 diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig index 32f7d34eb784..c7b5ee82895d 100644 --- a/drivers/phy/qualcomm/Kconfig +++ b/drivers/phy/qualcomm/Kconfig @@ -82,3 +82,13 @@ config PHY_QCOM_USB_HSIC select GENERIC_PHY help Support for the USB HSIC ULPI compliant PHY on QCOM chipsets. + +config PHY_QCOM_USB_HS_SNPS_28NM + tristate "Qualcomm Synopsys 28nm USB HS PHY driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on EXTCON || !EXTCON # if EXTCON=m, this cannot be built-in + select GENERIC_PHY + help + Enable this to support the Synopsys 28nm Femto USB PHY on Qualcomm + chips. This driver supports the high-speed PHY which is usually + paired with either the ChipIdea or Synopsys DWC3 USB IPs on MSM SOCs. diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile index c56efd3af205..dc238d95b18c 100644 --- a/drivers/phy/qualcomm/Makefile +++ b/drivers/phy/qualcomm/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_PHY_QCOM_UFS_14NM) += phy-qcom-ufs-qmp-14nm.o obj-$(CONFIG_PHY_QCOM_UFS_20NM) += phy-qcom-ufs-qmp-20nm.o obj-$(CONFIG_PHY_QCOM_USB_HS) += phy-qcom-usb-hs.o obj-$(CONFIG_PHY_QCOM_USB_HSIC) += phy-qcom-usb-hsic.o +obj-$(CONFIG_PHY_QCOM_USB_HS_SNPS_28NM) += phy-qcom-usb-hs-snsp-28nm.o diff --git a/drivers/phy/qualcomm/phy-qcom-usb-hs-snsp-28nm.c b/drivers/phy/qualcomm/phy-qcom-usb-hs-snsp-28nm.c new file mode 100644 index 000000000000..ee52bb6df6da --- /dev/null +++ b/drivers/phy/qualcomm/phy-qcom-usb-hs-snsp-28nm.c @@ -0,0 +1,535 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2009-2018, Linux Foundation. All rights reserved. + * Copyright (c) 2018, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* PHY register and bit definitions */ +#define PHY_CTRL_COMMON0 0x078 +#define SIDDQ BIT(2) +#define PHY_IRQ_CMD 0x0d0 +#define PHY_INTR_MASK0 0x0d4 +#define PHY_INTR_CLEAR0 0x0dc +#define DPDM_MASK 0x1e +#define DP_1_0 BIT(4) +#define DP_0_1 BIT(3) +#define DM_1_0 BIT(2) +#define DM_0_1 BIT(1) + +enum hsphy_voltage { + VOL_NONE, + VOL_MIN, + VOL_MAX, + VOL_NUM, +}; + +enum hsphy_vreg { + VDD, + VDDA_1P8, + VDDA_3P3, + VREG_NUM, +}; + +struct hsphy_init_seq { + int offset; + int val; + int delay; +}; + +struct hsphy_data { + const struct hsphy_init_seq *init_seq; + unsigned int init_seq_num; +}; + +struct hsphy_priv { + void __iomem *base; + struct clk_bulk_data *clks; + int num_clks; + struct reset_control *phy_reset; + struct reset_control *por_reset; + struct regulator_bulk_data vregs[VREG_NUM]; + unsigned int voltages[VREG_NUM][VOL_NUM]; + const struct hsphy_data *data; + bool cable_connected; + struct extcon_dev *vbus_edev; + struct notifier_block vbus_notify; + enum phy_mode mode; +}; + +static int qcom_snps_hsphy_config_regulators(struct hsphy_priv *priv, int high) +{ + int old_uV[VREG_NUM]; + int min, ret, i; + + min = high ? 1 : 0; /* low or none? */ + + for (i = 0; i < VREG_NUM; i++) { + old_uV[i] = regulator_get_voltage(priv->vregs[i].consumer); + ret = regulator_set_voltage(priv->vregs[i].consumer, + priv->voltages[i][min], + priv->voltages[i][VOL_MAX]); + if (ret) + goto roll_back; + } + + return 0; + +roll_back: + for (; i >= 0; i--) + regulator_set_voltage(priv->vregs[i].consumer, + old_uV[i], old_uV[i]); + return ret; +} + +static int qcom_snps_hsphy_enable_regulators(struct hsphy_priv *priv) +{ + int ret; + + ret = qcom_snps_hsphy_config_regulators(priv, 1); + if (ret) + return ret; + + ret = regulator_set_load(priv->vregs[VDDA_1P8].consumer, 19000); + if (ret < 0) + goto unconfig_regulators; + + ret = regulator_set_load(priv->vregs[VDDA_3P3].consumer, 16000); + if (ret < 0) + goto unset_1p8_load; + + ret = regulator_bulk_enable(VREG_NUM, priv->vregs); + if (ret) + goto unset_3p3_load; + + return 0; + +unset_3p3_load: + regulator_set_load(priv->vregs[VDDA_3P3].consumer, 0); +unset_1p8_load: + regulator_set_load(priv->vregs[VDDA_1P8].consumer, 0); +unconfig_regulators: + qcom_snps_hsphy_config_regulators(priv, 0); + return ret; +} + +static void qcom_snps_hsphy_disable_regulators(struct hsphy_priv *priv) +{ + regulator_bulk_disable(VREG_NUM, priv->vregs); + regulator_set_load(priv->vregs[VDDA_1P8].consumer, 0); + regulator_set_load(priv->vregs[VDDA_3P3].consumer, 0); + qcom_snps_hsphy_config_regulators(priv, 0); +} + +static int qcom_snps_hsphy_set_mode(struct phy *phy, enum phy_mode mode) +{ + struct hsphy_priv *priv = phy_get_drvdata(phy); + + priv->mode = mode; + + return 0; +} + +static void qcom_snps_hsphy_enable_hv_interrupts(struct hsphy_priv *priv) +{ + u32 val; + + /* Clear any existing interrupts before enabling the interrupts */ + val = readb(priv->base + PHY_INTR_CLEAR0); + val |= DPDM_MASK; + writeb(val, priv->base + PHY_INTR_CLEAR0); + + writeb(0x0, priv->base + PHY_IRQ_CMD); + usleep_range(200, 220); + writeb(0x1, priv->base + PHY_IRQ_CMD); + + /* Make sure the interrupts are cleared */ + usleep_range(200, 220); + + val = readb(priv->base + PHY_INTR_MASK0); + switch (priv->mode) { + case PHY_MODE_USB_HOST_HS: + case PHY_MODE_USB_HOST_FS: + case PHY_MODE_USB_DEVICE_HS: + case PHY_MODE_USB_DEVICE_FS: + val |= DP_1_0 | DM_0_1; + break; + case PHY_MODE_USB_HOST_LS: + case PHY_MODE_USB_DEVICE_LS: + val |= DP_0_1 | DM_1_0; + break; + default: + /* No device connected */ + val |= DP_0_1 | DM_0_1; + break; + } + writeb(val, priv->base + PHY_INTR_MASK0); +} + +static void qcom_snps_hsphy_disable_hv_interrupts(struct hsphy_priv *priv) +{ + u32 val; + + val = readb(priv->base + PHY_INTR_MASK0); + val &= ~DPDM_MASK; + writeb(val, priv->base + PHY_INTR_MASK0); + + /* Clear any pending interrupts */ + val = readb(priv->base + PHY_INTR_CLEAR0); + val |= DPDM_MASK; + writeb(val, priv->base + PHY_INTR_CLEAR0); + + writeb(0x0, priv->base + PHY_IRQ_CMD); + usleep_range(200, 220); + + writeb(0x1, priv->base + PHY_IRQ_CMD); + usleep_range(200, 220); +} + +static void qcom_snps_hsphy_enter_retention(struct hsphy_priv *priv) +{ + u32 val; + + val = readb(priv->base + PHY_CTRL_COMMON0); + val |= SIDDQ; + writeb(val, priv->base + PHY_CTRL_COMMON0); +} + +static void qcom_snps_hsphy_exit_retention(struct hsphy_priv *priv) +{ + u32 val; + + val = readb(priv->base + PHY_CTRL_COMMON0); + val &= ~SIDDQ; + writeb(val, priv->base + PHY_CTRL_COMMON0); +} + +static int qcom_snps_hsphy_vbus_notifier(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct hsphy_priv *priv = container_of(nb, struct hsphy_priv, + vbus_notify); + priv->cable_connected = !!event; + return 0; +} + +static int qcom_snps_hsphy_power_on(struct phy *phy) +{ + struct hsphy_priv *priv = phy_get_drvdata(phy); + int ret; + + if (priv->cable_connected) { + ret = clk_bulk_prepare_enable(priv->num_clks, priv->clks); + if (ret) + return ret; + qcom_snps_hsphy_disable_hv_interrupts(priv); + } else { + ret = qcom_snps_hsphy_enable_regulators(priv); + if (ret) + return ret; + ret = clk_bulk_prepare_enable(priv->num_clks, priv->clks); + if (ret) + return ret; + qcom_snps_hsphy_exit_retention(priv); + } + + return 0; +} + +static int qcom_snps_hsphy_power_off(struct phy *phy) +{ + struct hsphy_priv *priv = phy_get_drvdata(phy); + + if (priv->cable_connected) { + qcom_snps_hsphy_enable_hv_interrupts(priv); + clk_bulk_disable_unprepare(priv->num_clks, priv->clks); + } else { + qcom_snps_hsphy_enter_retention(priv); + clk_bulk_disable_unprepare(priv->num_clks, priv->clks); + qcom_snps_hsphy_disable_regulators(priv); + } + + return 0; +} + +static int qcom_snps_hsphy_reset(struct hsphy_priv *priv) +{ + int ret; + + ret = reset_control_assert(priv->phy_reset); + if (ret) + return ret; + + usleep_range(10, 15); + + ret = reset_control_deassert(priv->phy_reset); + if (ret) + return ret; + + usleep_range(80, 100); + + return 0; +} + +static void qcom_snps_hsphy_init_sequence(struct hsphy_priv *priv) +{ + const struct hsphy_data *data = priv->data; + const struct hsphy_init_seq *seq; + int i; + + /* Device match data is optional. */ + if (!data) + return; + + seq = data->init_seq; + + for (i = 0; i < data->init_seq_num; i++, seq++) { + writeb(seq->val, priv->base + seq->offset); + if (seq->delay) + usleep_range(seq->delay, seq->delay + 10); + } + + /* Ensure that the above parameter overrides is successful. */ + mb(); +} + +static int qcom_snps_hsphy_por_reset(struct hsphy_priv *priv) +{ + int ret; + + ret = reset_control_assert(priv->por_reset); + if (ret) + return ret; + + /* + * The Femto PHY is POR reset in the following scenarios. + * + * 1. After overriding the parameter registers. + * 2. Low power mode exit from PHY retention. + * + * Ensure that SIDDQ is cleared before bringing the PHY + * out of reset. + */ + qcom_snps_hsphy_exit_retention(priv); + + /* + * As per databook, 10 usec delay is required between + * PHY POR assert and de-assert. + */ + usleep_range(10, 20); + ret = reset_control_deassert(priv->por_reset); + if (ret) + return ret; + + /* + * As per databook, it takes 75 usec for PHY to stabilize + * after the reset. + */ + usleep_range(80, 100); + + /* Ensure that RESET operation is completed. */ + mb(); + + return 0; +} + +static int qcom_snps_hsphy_init(struct phy *phy) +{ + struct hsphy_priv *priv = phy_get_drvdata(phy); + int state; + int ret; + + ret = qcom_snps_hsphy_reset(priv); + if (ret) + return ret; + + qcom_snps_hsphy_init_sequence(priv); + + ret = qcom_snps_hsphy_por_reset(priv); + if (ret) + return ret; + + /* Setup initial state */ + if (priv->vbus_edev) { + state = extcon_get_state(priv->vbus_edev, EXTCON_USB); + ret = qcom_snps_hsphy_vbus_notifier(&priv->vbus_notify, state, + priv->vbus_edev); + if (ret) + return ret; + } + + return 0; +} + +static const struct phy_ops qcom_snps_hsphy_ops = { + .init = qcom_snps_hsphy_init, + .power_on = qcom_snps_hsphy_power_on, + .power_off = qcom_snps_hsphy_power_off, + .set_mode = qcom_snps_hsphy_set_mode, + .owner = THIS_MODULE, +}; + +static const char * const qcom_snps_hsphy_clks[] = { + "ref", + "phy", + "sleep", +}; + +static int qcom_snps_hsphy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *extcon_node; + struct phy_provider *provider; + struct hsphy_priv *priv; + struct resource *res; + struct phy *phy; + int ret; + int i; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + priv->base = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + priv->num_clks = ARRAY_SIZE(qcom_snps_hsphy_clks); + priv->clks = devm_kcalloc(dev, priv->num_clks, sizeof(*priv->clks), + GFP_KERNEL); + if (!priv->clks) + return -ENOMEM; + + for (i = 0; i < priv->num_clks; i++) + priv->clks[i].id = qcom_snps_hsphy_clks[i]; + + ret = devm_clk_bulk_get(dev, priv->num_clks, priv->clks); + if (ret) + return ret; + + priv->phy_reset = devm_reset_control_get(dev, "phy"); + if (IS_ERR(priv->phy_reset)) + return PTR_ERR(priv->phy_reset); + + priv->por_reset = devm_reset_control_get(dev, "por"); + if (IS_ERR(priv->por_reset)) + return PTR_ERR(priv->por_reset); + + priv->vregs[VDD].supply = "vdd"; + priv->vregs[VDDA_1P8].supply = "vdda1p8"; + priv->vregs[VDDA_3P3].supply = "vdda3p3"; + + ret = devm_regulator_bulk_get(dev, VREG_NUM, priv->vregs); + if (ret) + return ret; + + priv->voltages[VDDA_1P8][VOL_NONE] = 0; + priv->voltages[VDDA_1P8][VOL_MIN] = 1800000; + priv->voltages[VDDA_1P8][VOL_MAX] = 1800000; + + priv->voltages[VDDA_3P3][VOL_NONE] = 0; + priv->voltages[VDDA_3P3][VOL_MIN] = 3050000; + priv->voltages[VDDA_3P3][VOL_MAX] = 3300000; + + ret = of_property_read_u32_array(dev->of_node, "qcom,vdd-voltage-level", + priv->voltages[VDD], VOL_NUM); + if (ret) { + dev_err(dev, "failed to read qcom,vdd-voltage-level\n"); + return ret; + } + + extcon_node = of_graph_get_remote_node(dev->of_node, -1, -1); + if (extcon_node) { + priv->vbus_edev = extcon_find_edev_by_node(extcon_node); + if (IS_ERR(priv->vbus_edev)) { + if (PTR_ERR(priv->vbus_edev) != -ENODEV) { + of_node_put(extcon_node); + return PTR_ERR(priv->vbus_edev); + } + priv->vbus_edev = NULL; + } + } + of_node_put(extcon_node); + + if (priv->vbus_edev) { + priv->vbus_notify.notifier_call = qcom_snps_hsphy_vbus_notifier; + ret = devm_extcon_register_notifier(dev, priv->vbus_edev, + EXTCON_USB, + &priv->vbus_notify); + if (ret) + return ret; + } + + /* Get device match data */ + priv->data = device_get_match_data(dev); + + phy = devm_phy_create(dev, dev->of_node, &qcom_snps_hsphy_ops); + if (IS_ERR(phy)) + return PTR_ERR(phy); + + phy_set_drvdata(phy, priv); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + return PTR_ERR_OR_ZERO(provider); +} + +/* + * The macro is used to define an initialization sequence. Each tuple + * is meant to program 'value' into phy register at 'offset' with 'delay' + * in us followed. + */ +#define HSPHY_INIT_CFG(o, v, d) { .offset = o, .val = v, .delay = d, } + +static const struct hsphy_init_seq init_seq_qcs404[] = { + HSPHY_INIT_CFG(0xc0, 0x01, 0), + HSPHY_INIT_CFG(0xe8, 0x0d, 0), + HSPHY_INIT_CFG(0x74, 0x12, 0), + HSPHY_INIT_CFG(0x98, 0x63, 0), + HSPHY_INIT_CFG(0x9c, 0x03, 0), + HSPHY_INIT_CFG(0xa0, 0x1d, 0), + HSPHY_INIT_CFG(0xa4, 0x03, 0), + HSPHY_INIT_CFG(0x8c, 0x23, 0), + HSPHY_INIT_CFG(0x78, 0x08, 0), + HSPHY_INIT_CFG(0x7c, 0xdc, 0), + HSPHY_INIT_CFG(0x90, 0xe0, 20), + HSPHY_INIT_CFG(0x74, 0x10, 0), + HSPHY_INIT_CFG(0x90, 0x60, 0), +}; + +static const struct hsphy_data hsphy_data_qcs404 = { + .init_seq = init_seq_qcs404, + .init_seq_num = ARRAY_SIZE(init_seq_qcs404), +}; + +static const struct of_device_id qcom_snps_hsphy_match[] = { + { .compatible = "qcom,qcs404-usb-hsphy", .data = &hsphy_data_qcs404, }, + { }, +}; +MODULE_DEVICE_TABLE(of, qcom_snps_hsphy_match); + +static struct platform_driver qcom_snps_hsphy_driver = { + .probe = qcom_snps_hsphy_probe, + .driver = { + .name = "qcom-usb-snps-hsphy", + .of_match_table = qcom_snps_hsphy_match, + }, +}; +module_platform_driver(qcom_snps_hsphy_driver); + +MODULE_DESCRIPTION("Qualcomm Synopsys 28nm USB High-Speed PHY driver"); +MODULE_LICENSE("GPL v2");