Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5308114rwr; Mon, 24 Apr 2023 02:01:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bhvNpaDkEfu5NN6M22laggjXQUVbE9xq19r9oGzWYJOFhgaeNetXu9noDIXhUxZJ5X7/dO X-Received: by 2002:a05:6a21:6d98:b0:ec:60b9:c724 with SMTP id wl24-20020a056a216d9800b000ec60b9c724mr17195160pzb.33.1682326866774; Mon, 24 Apr 2023 02:01:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682326866; cv=none; d=google.com; s=arc-20160816; b=uXIBDAeDA+fwmvrcD7eEh0s7phQU13Ejqp4VdYLrw0XkFD+qHZoRX9PyCta257DB2L KTbGBy/CCwMteg73WXJFtUFzwVu8SwvKwuar9Q2T6plMGwRmLYhPya3Oy7u0jnVx6lZ5 DHBovsrKeL4BLdVOLSnKiiPklsDq5a9pZj4VMoN4s04Q0Zb3/0jWm+SfcCk5EPBKAOe7 wDJyEoTnrCiSxfJJH69c+Cx0uTnj6vv3w9HykuDinUfTGZ7Wpnd2IedPLBKFUWF04y+C oYfwJXlqrG3E+y7X2p/NDMsGi+0NNsdWIsqlX3rrG4l+BoIuxp8cAAo0iOYFIIzfCnzk nPsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=gm9rrknk4prDHmKxRidxVjDMLwXkYp7oX6Kv4FS8Gqc=; b=tSlWmsAiWz+G//u6PnG2v8ShlKat27CTX6C1LuK7VImkEAewgCeXi6jrQbuP6MvitO DhmBuy1jDGqUdvit43XyPg5OZ9aCJodmed8lO4Cm5fgHFi7LD1KxSl02PVStJn39yvfh U6p6912wzHbTg4UeSNIqGNfv8dGMQRbxG1kFdYuso2WSmTQ37LZxkkYaxZURb3EBsdza hwwS6uZgyYt1/BKfQg8RJaAEKNQCpuDVMB+kw17NQu9jLJnQtfys9p3F+Sjdt1dW3I1T Oju+eEVzyZGP08Q5dxdS/77sXM+AuCS8A4VMPrRa/UQOv/42gO1fFOXn16xu6zegFh1S +MHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jdIvp0la; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a631f44000000b0051398cda533si7243393pgm.388.2023.04.24.02.00.47; Mon, 24 Apr 2023 02:01:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jdIvp0la; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbjDXIq5 (ORCPT + 99 others); Mon, 24 Apr 2023 04:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231429AbjDXIq4 (ORCPT ); Mon, 24 Apr 2023 04:46:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24175E53; Mon, 24 Apr 2023 01:46:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A349A61F1F; Mon, 24 Apr 2023 08:46:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6286C433D2; Mon, 24 Apr 2023 08:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682326014; bh=BxzHUQB3Z0bZMqtecVzotggbecUSmBmH1hXxG3knd7g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=jdIvp0lahDwhD5Of5iNaBzJV93J9CmLiSKsfK1wx/EDaULMmI0evPDb9JQTkiL1XP 5jKKP4/Y2ucVSWsWg++viia79FEnxT553ndleAu9A1vuaz/a3zdIVk/gE7V0fLHIDh 4QX6Komzpjypwyt6yjSDtiHh5biBVitIbcP9muVRxCl/M/+7+Bq2gRVCq00GmwAVUM RUWT7VCJkA1H9gt4I1sPvYBFI+2YQhN8VS/iHBYVmYX7RRkcpvWyj83CTagRAHyv6u 03EsgB/Z3j3cPPy2b089AdlQ1B0t0GArQ22uIg47zwYiKSrpnp6K6ssjUUrMlJlhRf s170M+b+8IO5g== Message-ID: Date: Mon, 24 Apr 2023 11:46:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v5 3/7] phy: starfive: Add JH7110 USB 2.0 PHY driver Content-Language: en-US To: Minda Chen , Emil Renner Berthing , Conor Dooley , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Pawel Laszczak , Greg Kroah-Hartman , Peter Chen , Philipp Zabel Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, linux-usb@vger.kernel.org, linux-riscv@lists.infradead.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Mason Huo References: <20230420110052.3182-1-minda.chen@starfivetech.com> <20230420110052.3182-4-minda.chen@starfivetech.com> From: Roger Quadros In-Reply-To: <20230420110052.3182-4-minda.chen@starfivetech.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Minda, On 20/04/2023 14:00, Minda Chen wrote: > Add Starfive JH7110 SoC USB 2.0 PHY driver support. > USB 2.0 PHY default connect to Cadence USB controller. > > Signed-off-by: Minda Chen > --- > MAINTAINERS | 6 + > drivers/phy/starfive/Kconfig | 11 ++ > drivers/phy/starfive/Makefile | 1 + > drivers/phy/starfive/phy-jh7110-usb.c | 162 ++++++++++++++++++++++++++ > 4 files changed, 180 insertions(+) > create mode 100644 drivers/phy/starfive/phy-jh7110-usb.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index 1aef5ba46d71..c09ea66dcd5a 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -19968,6 +19968,12 @@ M: William Qiu > S: Supported > F: Documentation/devicetree/bindings/soc/starfive/starfive,jh7110-syscon.yaml > > +STARFIVE JH71X0 USB PHY DRIVER > +M: Minda Chen > +S: Supported > +F: Documentation/devicetree/bindings/phy/starfive,jh7110-usb-phy.yaml > +F: drivers/phy/starfive/phy-jh7110-usb.c > + > STATIC BRANCH/CALL > M: Peter Zijlstra > M: Josh Poimboeuf > diff --git a/drivers/phy/starfive/Kconfig b/drivers/phy/starfive/Kconfig > index f989b8ff8bcb..2c013c390dee 100644 > --- a/drivers/phy/starfive/Kconfig > +++ b/drivers/phy/starfive/Kconfig > @@ -11,3 +11,14 @@ config PHY_STARFIVE_DPHY_RX > Choose this option if you have a StarFive D-PHY in your > system. If M is selected, the module will be called > phy-starfive-dphy-rx. > + > +config PHY_STARFIVE_JH7110_USB > + tristate "Starfive JH7110 USB 2.0 PHY support" > + depends on USB_SUPPORT > + select GENERIC_PHY > + select USB_PHY > + help > + Enable this to support the StarFive USB 2.0 PHY, > + used with the Cadence USB controller. > + If M is selected, the module will be called > + phy-jh7110-usb.ko. > diff --git a/drivers/phy/starfive/Makefile b/drivers/phy/starfive/Makefile > index 7ec576cb30ae..176443852f4d 100644 > --- a/drivers/phy/starfive/Makefile > +++ b/drivers/phy/starfive/Makefile > @@ -1,2 +1,3 @@ > # SPDX-License-Identifier: GPL-2.0 > obj-$(CONFIG_PHY_STARFIVE_DPHY_RX) += phy-starfive-dphy-rx.o > +obj-$(CONFIG_PHY_STARFIVE_JH7110_USB) += phy-jh7110-usb.o > diff --git a/drivers/phy/starfive/phy-jh7110-usb.c b/drivers/phy/starfive/phy-jh7110-usb.c > new file mode 100644 > index 000000000000..4a12df0692cd > --- /dev/null > +++ b/drivers/phy/starfive/phy-jh7110-usb.c > @@ -0,0 +1,162 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * StarFive JH7110 USB 2.0 PHY driver > + * > + * Copyright (C) 2023 StarFive Technology Co., Ltd. > + * Author: Minda Chen > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define USB_125M_CLK_RATE 125000000 > +#define USB_LS_KEEPALIVE_OFF 0x4 > +#define USB_LS_KEEPALIVE_ENABLE BIT(4) > + > +struct jh7110_usb2_phy { > + struct phy *phy; > + void __iomem *regs; > + struct clk *usb_125m_clk; > + struct clk *app_125m; > + enum phy_mode mode; > +}; > + > +static void jh7110_usb2_mode_set(struct jh7110_usb2_phy *phy) > +{ > + unsigned int val; > + > + if (phy->mode != PHY_MODE_USB_HOST) { > + /* Enable the LS speed keep-alive signal */ > + val = readl(phy->regs + USB_LS_KEEPALIVE_OFF); > + val |= USB_LS_KEEPALIVE_ENABLE; > + writel(val, phy->regs + USB_LS_KEEPALIVE_OFF); > + } > +} > + > +static int jh7110_usb2_phy_set_mode(struct phy *_phy, > + enum phy_mode mode, int submode) > +{ > + struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy); > + > + switch (mode) { > + case PHY_MODE_USB_HOST: > + case PHY_MODE_USB_DEVICE: > + case PHY_MODE_USB_OTG: > + break; > + default: > + return -EINVAL; > + } > + > + if (mode != phy->mode) { > + dev_info(&_phy->dev, "Changing phy to %d\n", mode); dev_dbg() please? > + phy->mode = mode; > + jh7110_usb2_mode_set(phy); > + } > + > + return 0; > +} > + > +static int jh7110_usb2_phy_init(struct phy *_phy) > +{ > + struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy); > + int ret; > + > + ret = clk_set_rate(phy->usb_125m_clk, USB_125M_CLK_RATE); > + if (ret) > + return ret; > + > + ret = clk_prepare_enable(phy->app_125m); > + if (ret) > + return ret; > + > + return 0; > +} > + > +static int jh7110_usb2_phy_exit(struct phy *_phy) > +{ > + struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy); > + > + clk_disable_unprepare(phy->app_125m); > + > + return 0; > +} > + > +static const struct phy_ops jh7110_usb2_phy_ops = { > + .init = jh7110_usb2_phy_init, > + .exit = jh7110_usb2_phy_exit, > + .set_mode = jh7110_usb2_phy_set_mode, > + .owner = THIS_MODULE, > +}; > + > +static int jh7110_usb_phy_probe(struct platform_device *pdev) > +{ > + struct jh7110_usb2_phy *phy; > + struct device *dev = &pdev->dev; > + struct phy_provider *phy_provider; > + > + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); > + if (!phy) > + return -ENOMEM; > + > + phy->usb_125m_clk = devm_clk_get(dev, "125m"); > + if (IS_ERR(phy->usb_125m_clk)) > + return dev_err_probe(dev, PTR_ERR(phy->usb_125m_clk), > + "Failed to get 125m clock\n"); > + > + phy->app_125m = devm_clk_get(dev, "app_125m"); > + if (IS_ERR(phy->app_125m)) > + return dev_err_probe(dev, PTR_ERR(phy->app_125m), > + "Failed to get app 125m clock\n"); > + > + phy->regs = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(phy->regs)) > + return dev_err_probe(dev, PTR_ERR(phy->regs), > + "Failed to map phy base\n"); > + > + phy->phy = devm_phy_create(dev, NULL, &jh7110_usb2_phy_ops); > + if (IS_ERR(phy->phy)) > + return dev_err_probe(dev, PTR_ERR(phy->phy), > + "Failed to create phy\n"); > + > + platform_set_drvdata(pdev, 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 int jh7110_usb_phy_remove(struct platform_device *pdev) > +{ > + struct jh7110_usb2_phy *phy = platform_get_drvdata(pdev); > + > + clk_disable_unprepare(phy->app_125m); Why do you need to do clk_disable here? You didn't enable it in probe. > + platform_set_drvdata(pdev, NULL); > + > + return 0; > +} > + > +static const struct of_device_id jh7110_usb_phy_of_match[] = { > + { .compatible = "starfive,jh7110-usb-phy" }, > + { /* sentinel */ }, > +}; > +MODULE_DEVICE_TABLE(of, jh7110_usb_phy_of_match); > + > +static struct platform_driver jh7110_usb_phy_driver = { > + .probe = jh7110_usb_phy_probe, > + .remove = jh7110_usb_phy_remove, > + .driver = { > + .of_match_table = jh7110_usb_phy_of_match, > + .name = "jh7110-usb-phy", > + } > +}; > +module_platform_driver(jh7110_usb_phy_driver); > + > +MODULE_DESCRIPTION("StarFive JH7110 USB 2.0 PHY driver"); > +MODULE_AUTHOR("Minda Chen "); > +MODULE_LICENSE("GPL"); cheers, -roger