2020-10-30 13:18:27 +00:00
|
|
|
From 3c9d8f6c03a2cda1849ec3c84f82ec030d1f49ef Mon Sep 17 00:00:00 2001
|
|
|
|
From: Robert Marko <robert.marko@sartura.hr>
|
|
|
|
Date: Sun, 3 May 2020 22:18:22 +0200
|
|
|
|
Subject: [PATCH] phy: add driver for Qualcomm IPQ40xx USB PHY
|
2020-01-14 16:15:57 +00:00
|
|
|
|
2020-10-30 13:18:27 +00:00
|
|
|
Add a driver to setup the USB PHY-s on Qualcom m IPQ40xx series SoCs.
|
|
|
|
The driver sets up HS and SS phys.
|
2020-01-14 16:15:57 +00:00
|
|
|
|
|
|
|
Signed-off-by: John Crispin <john@phrozen.org>
|
2020-10-30 13:18:27 +00:00
|
|
|
Signed-off-by: Robert Marko <robert.marko@sartura.hr>
|
|
|
|
Cc: Luka Perkov <luka.perkov@sartura.hr>
|
|
|
|
Link: https://lore.kernel.org/r/20200503201823.531757-1-robert.marko@sartura.hr
|
|
|
|
Signed-off-by: Vinod Koul <vkoul@kernel.org>
|
2020-01-14 16:15:57 +00:00
|
|
|
---
|
2020-10-30 13:18:27 +00:00
|
|
|
drivers/phy/qualcomm/Kconfig | 7 +
|
2020-01-14 16:15:57 +00:00
|
|
|
drivers/phy/qualcomm/Makefile | 1 +
|
2020-10-30 13:18:27 +00:00
|
|
|
drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c | 148 ++++++++++++++++++++
|
|
|
|
3 files changed, 156 insertions(+)
|
2020-01-14 16:15:57 +00:00
|
|
|
create mode 100644 drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
|
|
|
|
|
|
|
|
--- a/drivers/phy/qualcomm/Kconfig
|
|
|
|
+++ b/drivers/phy/qualcomm/Kconfig
|
2020-02-28 20:15:48 +00:00
|
|
|
@@ -18,6 +18,13 @@ config PHY_QCOM_APQ8064_SATA
|
2020-01-14 16:15:57 +00:00
|
|
|
depends on OF
|
|
|
|
select GENERIC_PHY
|
|
|
|
|
|
|
|
+config PHY_QCOM_IPQ4019_USB
|
2020-10-30 13:18:27 +00:00
|
|
|
+ tristate "Qualcomm IPQ4019 USB PHY driver"
|
|
|
|
+ depends on OF && (ARCH_QCOM || COMPILE_TEST)
|
2020-01-14 16:15:57 +00:00
|
|
|
+ select GENERIC_PHY
|
|
|
|
+ help
|
2020-10-30 13:18:27 +00:00
|
|
|
+ Support for the USB PHY-s on Qualcomm IPQ40xx SoC-s.
|
2020-01-14 16:15:57 +00:00
|
|
|
+
|
|
|
|
config PHY_QCOM_IPQ806X_SATA
|
|
|
|
tristate "Qualcomm IPQ806x SATA SerDes/PHY driver"
|
|
|
|
depends on ARCH_QCOM
|
2020-10-30 13:18:27 +00:00
|
|
|
--- a/drivers/phy/qualcomm/Makefile
|
|
|
|
+++ b/drivers/phy/qualcomm/Makefile
|
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
obj-$(CONFIG_PHY_ATH79_USB) += phy-ath79-usb.o
|
|
|
|
obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o
|
|
|
|
+obj-$(CONFIG_PHY_QCOM_IPQ4019_USB) += phy-qcom-ipq4019-usb.o
|
|
|
|
obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
|
|
|
|
obj-$(CONFIG_PHY_QCOM_PCIE2) += phy-qcom-pcie2.o
|
|
|
|
obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o
|
2020-01-14 16:15:57 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
|
2020-10-30 13:18:27 +00:00
|
|
|
@@ -0,0 +1,148 @@
|
|
|
|
+// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-01-14 16:15:57 +00:00
|
|
|
+/*
|
|
|
|
+ * Copyright (C) 2018 John Crispin <john@phrozen.org>
|
|
|
|
+ *
|
|
|
|
+ * Based on code from
|
|
|
|
+ * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <linux/delay.h>
|
|
|
|
+#include <linux/err.h>
|
|
|
|
+#include <linux/io.h>
|
|
|
|
+#include <linux/kernel.h>
|
|
|
|
+#include <linux/module.h>
|
|
|
|
+#include <linux/mutex.h>
|
|
|
|
+#include <linux/of_platform.h>
|
2020-10-30 13:18:27 +00:00
|
|
|
+#include <linux/of_device.h>
|
2020-01-14 16:15:57 +00:00
|
|
|
+#include <linux/phy/phy.h>
|
|
|
|
+#include <linux/platform_device.h>
|
|
|
|
+#include <linux/reset.h>
|
|
|
|
+
|
|
|
|
+struct ipq4019_usb_phy {
|
|
|
|
+ struct device *dev;
|
|
|
|
+ struct phy *phy;
|
|
|
|
+ void __iomem *base;
|
|
|
|
+ struct reset_control *por_rst;
|
|
|
|
+ struct reset_control *srif_rst;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int ipq4019_ss_phy_power_off(struct phy *_phy)
|
|
|
|
+{
|
|
|
|
+ struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
|
|
|
|
+
|
|
|
|
+ reset_control_assert(phy->por_rst);
|
|
|
|
+ msleep(10);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int ipq4019_ss_phy_power_on(struct phy *_phy)
|
|
|
|
+{
|
|
|
|
+ struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
|
|
|
|
+
|
|
|
|
+ ipq4019_ss_phy_power_off(_phy);
|
|
|
|
+
|
|
|
|
+ reset_control_deassert(phy->por_rst);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static struct phy_ops ipq4019_usb_ss_phy_ops = {
|
|
|
|
+ .power_on = ipq4019_ss_phy_power_on,
|
|
|
|
+ .power_off = ipq4019_ss_phy_power_off,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int ipq4019_hs_phy_power_off(struct phy *_phy)
|
|
|
|
+{
|
|
|
|
+ struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
|
|
|
|
+
|
|
|
|
+ reset_control_assert(phy->por_rst);
|
|
|
|
+ msleep(10);
|
|
|
|
+
|
|
|
|
+ reset_control_assert(phy->srif_rst);
|
|
|
|
+ msleep(10);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int ipq4019_hs_phy_power_on(struct phy *_phy)
|
|
|
|
+{
|
|
|
|
+ struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
|
|
|
|
+
|
|
|
|
+ ipq4019_hs_phy_power_off(_phy);
|
|
|
|
+
|
|
|
|
+ reset_control_deassert(phy->srif_rst);
|
|
|
|
+ msleep(10);
|
|
|
|
+
|
|
|
|
+ reset_control_deassert(phy->por_rst);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static struct phy_ops ipq4019_usb_hs_phy_ops = {
|
|
|
|
+ .power_on = ipq4019_hs_phy_power_on,
|
|
|
|
+ .power_off = ipq4019_hs_phy_power_off,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static const struct of_device_id ipq4019_usb_phy_of_match[] = {
|
|
|
|
+ { .compatible = "qcom,usb-hs-ipq4019-phy", .data = &ipq4019_usb_hs_phy_ops},
|
|
|
|
+ { .compatible = "qcom,usb-ss-ipq4019-phy", .data = &ipq4019_usb_ss_phy_ops},
|
|
|
|
+ { },
|
|
|
|
+};
|
|
|
|
+MODULE_DEVICE_TABLE(of, ipq4019_usb_phy_of_match);
|
|
|
|
+
|
|
|
|
+static int ipq4019_usb_phy_probe(struct platform_device *pdev)
|
|
|
|
+{
|
|
|
|
+ struct device *dev = &pdev->dev;
|
|
|
|
+ struct resource *res;
|
|
|
|
+ struct phy_provider *phy_provider;
|
|
|
|
+ struct ipq4019_usb_phy *phy;
|
|
|
|
+
|
|
|
|
+ phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
|
|
|
|
+ if (!phy)
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+
|
|
|
|
+ phy->dev = &pdev->dev;
|
|
|
|
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
+ phy->base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
+ if (IS_ERR(phy->base)) {
|
|
|
|
+ dev_err(dev, "failed to remap register memory\n");
|
|
|
|
+ return PTR_ERR(phy->base);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ phy->por_rst = devm_reset_control_get(phy->dev, "por_rst");
|
|
|
|
+ if (IS_ERR(phy->por_rst)) {
|
|
|
|
+ if (PTR_ERR(phy->por_rst) != -EPROBE_DEFER)
|
|
|
|
+ dev_err(dev, "POR reset is missing\n");
|
|
|
|
+ return PTR_ERR(phy->por_rst);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ phy->srif_rst = devm_reset_control_get_optional(phy->dev, "srif_rst");
|
|
|
|
+ if (IS_ERR(phy->srif_rst))
|
|
|
|
+ return PTR_ERR(phy->srif_rst);
|
|
|
|
+
|
2020-10-30 13:18:27 +00:00
|
|
|
+ phy->phy = devm_phy_create(dev, NULL, of_device_get_match_data(dev));
|
2020-01-14 16:15:57 +00:00
|
|
|
+ if (IS_ERR(phy->phy)) {
|
|
|
|
+ dev_err(dev, "failed to create PHY\n");
|
|
|
|
+ return PTR_ERR(phy->phy);
|
|
|
|
+ }
|
|
|
|
+ phy_set_drvdata(phy->phy, phy);
|
|
|
|
+
|
|
|
|
+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
|
|
|
+
|
|
|
|
+ return PTR_ERR_OR_ZERO(phy_provider);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static struct platform_driver ipq4019_usb_phy_driver = {
|
|
|
|
+ .probe = ipq4019_usb_phy_probe,
|
|
|
|
+ .driver = {
|
|
|
|
+ .of_match_table = ipq4019_usb_phy_of_match,
|
|
|
|
+ .name = "ipq4019-usb-phy",
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+module_platform_driver(ipq4019_usb_phy_driver);
|
|
|
|
+
|
|
|
|
+MODULE_DESCRIPTION("QCOM/IPQ4019 USB phy driver");
|
|
|
|
+MODULE_AUTHOR("John Crispin <john@phrozen.org>");
|
|
|
|
+MODULE_LICENSE("GPL v2");
|