From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3E8AE7737B for ; Sat, 30 Sep 2023 17:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:Subject:From: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3bMCTNW1Bm4ll1XM1OeLF/gyL6Wvig3oryyypS+GNu0=; b=lZ3oODkMeMOgsx AgMNiXVqF4hFhPfwxCQVhYmoeA/sqwz1itW7etAcu3c1lvjXimjZljspmkXRTvnCTXY4YTqe7fTyq t+TkkoyU1WKdO4M2ynVC7cWeaCojUFPjsZcvRRgd/nuAWTq8wTUGTP+0j8N6Us3aFhvtCYEVe7zFq am8aLbX3IbNWZGld2ZRhRMH2QNrepVrqVXJMQAVU+1fqvxV1c/DbHUXZmeUPAy+vHKR7+9+iWShQ9 n14JjaoZhJMOF1q5GWLyoBwaEVc4yiogdK5m+4u37So9NkGAJAVIO3dNqu+ALB7rkPrQm15HEV8kN CBE1MpX9yIGCPjWcu/MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmdbn-009uar-33; Sat, 30 Sep 2023 17:18:27 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qmdbk-009uZR-20 for linux-arm-kernel@lists.infradead.org; Sat, 30 Sep 2023 17:18:26 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-504427aae4fso2119294e87.1 for ; Sat, 30 Sep 2023 10:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696094298; x=1696699098; darn=lists.infradead.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=VXfdPVhXPJrGGZ4SN+RAQ5z0z6qtec7h5xg/0e9zUX4=; b=iSUNVYrUxeSh7rHAJJe6Jb7UMWGVWfb5a2aw50anNsUOPDZKwiRuQHHAumfVbmrUmx Vr3o3h7BPl3OvYZbzlTUn5/t/MSvAqxrMMYnQvSWW606+k1kJpV2LqyBEemHNKRABjK+ dmxRTBUvwydEZGkwfCBFDDsfkAhpA50xHQcSfjaQU1Ve74SgwSY10XjTYpBeSNWXVYbe pnncwBkA9Z9D2HnzKeN075n44GGmLclG75AZyLlcIaf6afEr68iluG+rutog1S+NBkjW rjt1sF2Ndm4jlbNh4ruCPe+htYDboqoXIA9b0hu2Rnk9AEv/ttNQ2ZSo1r8n+XcRC5hS dtHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696094298; x=1696699098; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VXfdPVhXPJrGGZ4SN+RAQ5z0z6qtec7h5xg/0e9zUX4=; b=a7X8GXsI+7wbVv2MLduo/w1Go7ksmp8TZpu/ESCgcOupKOOL6ga6O8TUu6QVuCLeto LFhtdKqDuFbgl2DTXjOBk0Qg6syJpFIlzDyvc7okc72LRoRYUYn8ng4Q43wUQye46VxQ Cmi0xwveJWuQOaT1iMotdjYN9KgvbZEt/n9H94fGTA+gAQ2+k890C9/w0S+ZUBRMUFq1 Sif8rjPA9z7/jgjxff13vKqZZTEvr6hXaRUoFn8kvq0g5+yh5Hg1bD8ePOYytLX4fotM 4MvAw+lT4+ESgTo5S5HGS8loM7B9F13Gvm6WLiBcUvl/CA+dpH0Hb8/LVuViJccsenns 11Lw== X-Gm-Message-State: AOJu0YzFlg4hifAb050rBFGv2DU8C5SmvY+CCx0uDTnHx1R7ULa3gGcX q22JT+G+eKs3s8warcm778A5Ew== X-Google-Smtp-Source: AGHT+IFWLkpDIo4Dku+cy+qiAqnOoVI4CaVT5rs6kOyCwZ9kX/+NFB+D68536r0XlqGG5i74rTiNGw== X-Received: by 2002:a05:6512:2242:b0:503:1ca2:7673 with SMTP id i2-20020a056512224200b005031ca27673mr5828809lfu.14.1696094298169; Sat, 30 Sep 2023 10:18:18 -0700 (PDT) Received: from [192.168.246.189] (85-76-150-213-nat.elisa-mobile.fi. [85.76.150.213]) by smtp.gmail.com with ESMTPSA id ep30-20020a056512485e00b00500cede2786sm3985491lfb.65.2023.09.30.10.18.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Sep 2023 10:18:17 -0700 (PDT) Message-ID: <412492d1-fcc9-481c-9d28-b208a644ba1d@linaro.org> Date: Sat, 30 Sep 2023 20:18:13 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Dmitry Baryshkov Subject: Re: [PATCH 2/8] phy: qcom: Introduce Super-Speed USB UNIPHY driver To: Praveenkumar I , agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, vkoul@kernel.org, kishon@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, gregkh@linuxfoundation.org, catalin.marinas@arm.com, will@kernel.org, p.zabel@pengutronix.de, geert+renesas@glider.be, arnd@arndb.de, neil.armstrong@linaro.org, nfraprado@collabora.com, u-kumar1@ti.com, peng.fan@nxp.com, quic_wcheng@quicinc.com, quic_varada@quicinc.com, linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: quic_kathirav@quicinc.com, quic_nsekar@quicinc.com, quic_srichara@quicinc.com References: <20230929084209.3033093-1-quic_ipkumar@quicinc.com> <20230929084209.3033093-3-quic_ipkumar@quicinc.com> Content-Language: en-GB In-Reply-To: <20230929084209.3033093-3-quic_ipkumar@quicinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230930_101824_663804_7B9F2700 X-CRM114-Status: GOOD ( 39.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 29/09/2023 11:42, Praveenkumar I wrote: > Adds Qualcomm 22ull Super-Speed USB UNIPHY driver support which > is present in Qualcomm IPQ5332 SoC. This PHY is interfaced with > SNPS DWC3 USB and SNPS DWC PCIe. Either one of the interface > can use the it and selection is done via mux present in TCSR > register. This driver selects the PHY for DWC3 USB and handles > the reset, clocks and regulator. > > Signed-off-by: Praveenkumar I > --- > drivers/phy/qualcomm/Kconfig | 11 + > drivers/phy/qualcomm/Makefile | 1 + > drivers/phy/qualcomm/phy-qcom-uniphy-usb.c | 322 +++++++++++++++++++++ > 3 files changed, 334 insertions(+) > create mode 100644 drivers/phy/qualcomm/phy-qcom-uniphy-usb.c > > diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig > index d891058b7c39..7257c8455c53 100644 > --- a/drivers/phy/qualcomm/Kconfig > +++ b/drivers/phy/qualcomm/Kconfig > @@ -154,6 +154,17 @@ config PHY_QCOM_M31_USB > management. This driver is required even for peripheral only or > host only mode configurations. > > +config PHY_QCOM_UNIPHY_USB > + tristate "Qualcomm USB Super-Speed UNIPHY driver" Can we please have more specific driver name? As I wrote earlier, there are two other (different) kinds of Qualcomm UNI PHY devices: - DSI / HDMI UNIPHY on apq8064 / msm8974 / msm8960 (?) - USB QMP UNI PHY drivers Adding a driver called UNIPHY, which is not related to those two kinds sounds pretty confusing to me. > + depends on USB && (ARCH_QCOM || COMPILE_TEST) > + select GENERIC_PHY > + help > + Enable this to support the Qualcomm USB Super-Speed UNIPHY transceiver > + with DWC3 USB core. It handles PHY initialization, clock > + management required after resetting the hardware and power > + management. This driver is required even for peripheral only or > + host only mode configurations. > + > config PHY_QCOM_USB_HS > tristate "Qualcomm USB HS PHY module" > depends on USB_ULPI_BUS > diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile > index ffd609ac6233..c3e0112a7a70 100644 > --- a/drivers/phy/qualcomm/Makefile > +++ b/drivers/phy/qualcomm/Makefile > @@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_QCOM_QMP_USB_LEGACY) += phy-qcom-qmp-usb-legacy.o > obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o > obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2) += phy-qcom-snps-eusb2.o > obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER) += phy-qcom-eusb2-repeater.o > +obj-$(CONFIG_PHY_QCOM_UNIPHY_USB) += phy-qcom-uniphy-usb.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_28NM) += phy-qcom-usb-hs-28nm.o > diff --git a/drivers/phy/qualcomm/phy-qcom-uniphy-usb.c b/drivers/phy/qualcomm/phy-qcom-uniphy-usb.c > new file mode 100644 > index 000000000000..fdfc9c225995 > --- /dev/null > +++ b/drivers/phy/qualcomm/phy-qcom-uniphy-usb.c So, is it a USB PHY or UNI PHY (where I would expect that it handles USB and PCIe?) > @@ -0,0 +1,322 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define PCIE_USB_COMBO_PHY_CFG_MISC1 0x214 > +#define PCIE_USB_COMBO_PHY_CFG_RX_AFE_2 0x7C4 > +#define PCIE_USB_COMBO_PHY_CFG_RX_DLF_DEMUX_2 0x7E8 > + > +/* TCSR_USB_MUX_SEL regiter bits */ > +#define TCSR_USB_MUX_SEL BIT(0) > + > +struct phy_init_tbl { > + unsigned int offset; > + unsigned int val; > +}; > + > +#define PHY_INIT_CFG(o, v) \ > + { \ > + .offset = o, \ > + .val = v, \ > + } > + > +static const struct phy_init_tbl ipq5332_usb_uniphy_init_tbl[] = { > + PHY_INIT_CFG(PCIE_USB_COMBO_PHY_CFG_RX_AFE_2, 0x1076), > + PHY_INIT_CFG(PCIE_USB_COMBO_PHY_CFG_RX_DLF_DEMUX_2, 0x3142), > + PHY_INIT_CFG(PCIE_USB_COMBO_PHY_CFG_MISC1, 0x3), > +}; We already have this issue in QMP drivers. Could you please move data definitions to come after all struct definitions? > + > +struct uniphy_cfg { > + const struct phy_init_tbl *init_seq; > + int num_init_seq; > +}; > + > +struct uniphy_usb { > + struct device *dev; > + const struct uniphy_cfg *cfg; > + struct phy *phy; > + void __iomem *base; > + struct clk_bulk_data *clks; > + unsigned int num_clks; > + struct reset_control *reset; > + struct regulator *vreg; > + struct clk_fixed_rate pipe_clk_fixed; > + struct regmap *tcsr; > + unsigned int usb_mux_offset; > +}; > + > +static const struct uniphy_cfg ipq5332_usb_uniphy_cfg = { > + .init_seq = ipq5332_usb_uniphy_init_tbl, > + .num_init_seq = ARRAY_SIZE(ipq5332_usb_uniphy_init_tbl), > +}; > + > +static int uniphy_usb_mux_enable(struct uniphy_usb *uniphy, bool enable) > +{ > + struct device *dev = uniphy->dev; > + unsigned int val; > + int ret; > + > + if (!uniphy->tcsr) > + return -EINVAL; > + > + ret = regmap_read(uniphy->tcsr, uniphy->usb_mux_offset, &val); > + if (ret) { > + dev_err(dev, "Mux read failed: %d\n", ret); > + return ret; > + } > + > + val = enable ? (val | TCSR_USB_MUX_SEL) : (val & ~TCSR_USB_MUX_SEL); > + ret = regmap_write(uniphy->tcsr, uniphy->usb_mux_offset, val); regmap_update_bits() > + if (ret) { > + dev_err(dev, "Mux write failed: %d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int uniphy_usb_init(struct phy *phy) > +{ > + struct uniphy_usb *uniphy = phy_get_drvdata(phy); > + const struct uniphy_cfg *cfg = uniphy->cfg; > + const struct phy_init_tbl *tbl = cfg->init_seq; > + void __iomem *base = uniphy->base; > + struct device *dev = uniphy->dev; > + int i, ret; > + > + ret = regulator_enable(uniphy->vreg); > + if (ret) { > + dev_err(dev, "failed to enable regulator, %d\n", ret); > + return ret; > + } > + > + /* Perform phy reset */ > + reset_control_assert(uniphy->reset); > + usleep_range(1, 5); > + reset_control_deassert(uniphy->reset); Error checkig, please. > + > + ret = uniphy_usb_mux_enable(uniphy, true); > + if (ret < 0) > + goto err_assert_reset; > + > + ret = clk_bulk_prepare_enable(uniphy->num_clks, uniphy->clks); > + if (ret) { > + dev_err(dev, "failed to enable clocks: %d\n", ret); > + goto err_assert_reset; > + } > + > + /* phy autoload delay */ > + usleep_range(35, 40); > + > + for (i = 0; i < cfg->num_init_seq; i++) > + writel(tbl[i].val, base + tbl[i].offset); > + > + return 0; > + > +err_assert_reset: > + /* Assert phy reset */ > + reset_control_assert(uniphy->reset); > + > + return ret; > +} > + > +static int uniphy_usb_shutdown(struct phy *phy) > +{ > + struct uniphy_usb *uniphy = phy_get_drvdata(phy); > + > + clk_bulk_disable_unprepare(uniphy->num_clks, uniphy->clks); > + > + uniphy_usb_mux_enable(uniphy, false); > + > + /* Assert phy reset */ > + reset_control_assert(uniphy->reset); > + > + regulator_disable(uniphy->vreg); > + > + return 0; > +} > + > +static const struct phy_ops uniphy_usb_ops = { > + .power_on = uniphy_usb_init, > + .power_off = uniphy_usb_shutdown, > + .owner = THIS_MODULE, > +}; > + > +static int qcom_uniphy_usb_mux_init(struct uniphy_usb *uniphy) Inline this function please. > +{ > + struct device *dev = uniphy->dev; > + int ret; > + > + uniphy->tcsr = syscon_regmap_lookup_by_phandle_args(dev->of_node, "qcom,phy-usb-mux-sel", > + 1, &uniphy->usb_mux_offset); > + if (IS_ERR(uniphy->tcsr)) { > + ret = PTR_ERR(uniphy->tcsr); > + uniphy->tcsr = NULL; > + return ret; > + } > + > + return 0; > +} > + > +static int qcom_uniphy_usb_clk_init(struct uniphy_usb *uniphy) Inline > +{ > + struct device *dev = uniphy->dev; > + int ret; > + > + ret = devm_clk_bulk_get_all(dev, &uniphy->clks); > + if (ret < 0) > + return ret; > + > + uniphy->num_clks = ret; > + > + return 0; > +} > + > +static void phy_clk_release_provider(void *res) > +{ > + of_clk_del_provider(res); > +} > + > +/* > + * Register a fixed rate pipe clock. > + * > + * The _pipe_clksrc generated by PHY goes to the GCC that gate > + * controls it. The _pipe_clk coming out of the GCC is requested > + * by the PHY driver for its operations. > + * We register the _pipe_clksrc here. The gcc driver takes care > + * of assigning this _pipe_clksrc as parent to _pipe_clk. > + * Below picture shows this relationship. > + * > + * +---------------+ > + * | PHY block |<<---------------------------------------+ > + * | | | > + * | +-------+ | +-----+ | > + * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+ > + * clk | +-------+ | +-----+ > + * +---------------+ > + */ > +static int phy_pipe_clk_register(struct uniphy_usb *uniphy, struct device_node *np) > +{ > + struct clk_fixed_rate *fixed = &uniphy->pipe_clk_fixed; > + struct device *dev = uniphy->dev; > + struct clk_init_data init = { }; > + int ret; > + > + ret = of_property_read_string(np, "clock-output-names", &init.name); > + if (ret) { > + dev_err(dev, "%pOFn: No clock-output-names\n", np); > + return ret; > + } > + > + init.ops = &clk_fixed_rate_ops; > + > + fixed->fixed_rate = 250000000; > + fixed->hw.init = &init; > + > + ret = devm_clk_hw_register(dev, &fixed->hw); devm_clk_hw_register_fixed_rate() > + if (ret) > + return ret; > + > + ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw); > + if (ret) > + return ret; > + > + return devm_add_action_or_reset(dev, phy_clk_release_provider, np); devm_of_clk_add_hw_provider(). > +} > + > +static int qcom_uniphy_usb_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct phy_provider *phy_provider; > + struct uniphy_usb *uniphy; > + struct device_node *np; > + int ret; > + > + uniphy = devm_kzalloc(dev, sizeof(*uniphy), GFP_KERNEL); > + if (!uniphy) > + return -ENOMEM; > + > + uniphy->dev = dev; > + > + uniphy->cfg = of_device_get_match_data(dev); > + if (!uniphy->cfg) > + return -EINVAL; > + > + uniphy->base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(uniphy->base)) > + return PTR_ERR(uniphy->base); > + > + ret = qcom_uniphy_usb_clk_init(uniphy); > + if (ret) > + return dev_err_probe(dev, ret, "failed to get clock\n"); > + > + ret = qcom_uniphy_usb_mux_init(uniphy); > + if (ret) > + return dev_err_probe(dev, ret, "failed to get USB mux\n"); > + > + uniphy->reset = devm_reset_control_get_exclusive_by_index(dev, 0); > + if (IS_ERR(uniphy->reset)) > + return dev_err_probe(dev, PTR_ERR(uniphy->reset), "failed to get reset\n"); > + > + uniphy->vreg = devm_regulator_get_exclusive(dev, "vdd"); Why do you need the exclusive control here? > + if (IS_ERR(uniphy->vreg)) > + return dev_err_probe(dev, PTR_ERR(uniphy->phy), "failed to get vreg\n"); > + > + np = of_node_get(dev->of_node); No need to get/put it, just use dev->of_node directly. > + ret = phy_pipe_clk_register(uniphy, np); > + if (ret) { > + dev_err_probe(dev, ret, "failed to register pipe clk\n"); > + goto err; > + } > + > + uniphy->phy = devm_phy_create(dev, NULL, &uniphy_usb_ops); > + if (IS_ERR(uniphy->phy)) { > + ret = PTR_ERR(uniphy->phy); > + dev_err_probe(dev, ret, "failed to create PHY\n"); > + goto err; > + } > + > + phy_set_drvdata(uniphy->phy, uniphy); > + > + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); > + > + ret = PTR_ERR_OR_ZERO(phy_provider); > + > +err: > + of_node_put(np); > + return ret; > +} > + > +static const struct of_device_id qcom_uniphy_usb_of_match[] = { > + { .compatible = "qcom,ipq5332-usb-uniphy", .data = &ipq5332_usb_uniphy_cfg}, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, qcom_uniphy_usb_of_match); > + > +static struct platform_driver qcom_uniphy_usb_driver = { > + .probe = qcom_uniphy_usb_probe, > + .driver = { > + .of_match_table = qcom_uniphy_usb_of_match, > + .name = "qcom,uniphy-usb", > + } > +}; > +module_platform_driver(qcom_uniphy_usb_driver); > + > +MODULE_DESCRIPTION("Qualcomm Super-Speed USB UNIPHY driver"); > +MODULE_LICENSE("GPL"); -- With best wishes Dmitry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel