From: Krzysztof Kozlowski <krzk@kernel.org>
To: Shawn Lin <shawn.lin@rock-chips.com>,
Rob Herring <robh+dt@kernel.org>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Heiko Stuebner <heiko@sntech.de>,
Alim Akhtar <alim.akhtar@samsung.com>,
Avri Altman <avri.altman@wdc.com>,
Bart Van Assche <bvanassche@acm.org>,
YiFeng Zhao <zyf@rock-chips.com>, Liang Chen <cl@rock-chips.com>,
linux-scsi@vger.kernel.org, linux-rockchip@lists.infradead.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v1 3/3] scsi: ufs: rockchip: init support for UFS
Date: Tue, 6 Aug 2024 10:43:56 +0200 [thread overview]
Message-ID: <ea136482-16bc-4e67-8370-de72ee0c034e@kernel.org> (raw)
In-Reply-To: <1722928800-137042-4-git-send-email-shawn.lin@rock-chips.com>
On 06/08/2024 09:20, Shawn Lin wrote:
> RK3576 contains a UFS controller, add init support fot it.
>
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
>
> ---
> +
> +static int ufs_rockchip_common_init(struct ufs_hba *hba)
> +{
> + struct device *dev = hba->dev;
> + struct platform_device *pdev = to_platform_device(dev);
> + struct ufs_rockchip_host *host;
> + int err = 0;
> +
> + host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
> + if (!host)
> + return -ENOMEM;
> +
> + /* system control register for hci */
> + host->ufs_sys_ctrl = devm_platform_ioremap_resource_byname(pdev, "hci_grf");
> + if (IS_ERR(host->ufs_sys_ctrl)) {
> + dev_err(dev, "cannot ioremap for hci system control register\n");
> + return PTR_ERR(host->ufs_sys_ctrl);
> + }
> +
> + /* system control register for mphy */
> + host->ufs_phy_ctrl = devm_platform_ioremap_resource_byname(pdev, "mphy_grf");
> + if (IS_ERR(host->ufs_phy_ctrl)) {
> + dev_err(dev, "cannot ioremap for mphy system control register\n");
> + return PTR_ERR(host->ufs_phy_ctrl);
> + }
> +
> + /* mphy base register */
> + host->mphy_base = devm_platform_ioremap_resource_byname(pdev, "mphy");
> + if (IS_ERR(host->mphy_base)) {
> + dev_err(dev, "cannot ioremap for mphy base register\n");
> + return PTR_ERR(host->mphy_base);
> + }
> +
> + host->rst = devm_reset_control_array_get_exclusive(dev);
> + if (IS_ERR(host->rst)) {
> + dev_err(dev, "failed to get reset control\n");
> + return PTR_ERR(host->rst);
return dev_err_probe, assuming this is a probe path?
> + }
> +
> + reset_control_assert(host->rst);
> + udelay(1);
> + reset_control_deassert(host->rst);
> +
> + host->ref_out_clk = devm_clk_get(dev, "ref_out");
> + if (IS_ERR(host->ref_out_clk)) {
> + dev_err(dev, "ciu-drive not available\n");
> + return PTR_ERR(host->ref_out_clk);
Ditto
> + }
> + err = clk_prepare_enable(host->ref_out_clk);
> + if (err) {
> + dev_err(dev, "failed to enable ref out clock %d\n", err);
> + return err;
> + }
> +
> + host->rst_gpio = devm_gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);
Hm? Test your DTS and bindings.
> + if (IS_ERR(host->rst_gpio)) {
> + dev_err(&pdev->dev, "invalid reset-gpios property in node\n");
Post your DTS so we can review it. Post also results of dtbs_check...
> + err = PTR_ERR(host->rst_gpio);
dev_err_probe
> + goto out;
> + }
> + udelay(20);
> + gpiod_set_value_cansleep(host->rst_gpio, 1);
> +
> + host->clks[0].id = "core";
> + host->clks[1].id = "pclk";
> + host->clks[2].id = "pclk_mphy";
> + err = devm_clk_bulk_get_optional(dev, UFS_MAX_CLKS, host->clks);
> + if (err) {
> + dev_err(dev, "failed to get clocks %d\n", err);
> + goto out;
> + }
> +
> + err = clk_bulk_prepare_enable(UFS_MAX_CLKS, host->clks);
> + if (err) {
> + dev_err(dev, "failed to enable clocks %d\n", err);
> + goto out;
> + }
> +
> + if (device_property_read_u32(dev, "ufs-phy-config-mode",
No, stop adding undocumented properties.
> + &host->phy_config_mode))
> + host->phy_config_mode = 0;
> +
> + pm_runtime_set_active(&pdev->dev);
> +
> + host->hba = hba;
> + ufs_rockchip_set_pm_lvl(hba);
> +
> + ufshcd_set_variant(hba, host);
> +
> + return 0;
> +out:
> + clk_disable_unprepare(host->ref_out_clk);
> + return err;
> +}
> +
> +static int ufs_rockchip_rk3576_init(struct ufs_hba *hba)
> +{
> + int ret = 0;
> + struct device *dev = hba->dev;
> +
> + hba->quirks = UFSHCI_QUIRK_BROKEN_HCE | UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING;
> +
> + /* Enable BKOPS when suspend */
> + hba->caps |= UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
> + /* Enable putting device into deep sleep */
> + hba->caps |= UFSHCD_CAP_DEEPSLEEP;
> + /* Enable devfreq of UFS */
> + hba->caps |= UFSHCD_CAP_CLK_SCALING;
> + /* Enable WriteBooster */
> + hba->caps |= UFSHCD_CAP_WB_EN;
> +
> + ret = ufs_rockchip_common_init(hba);
> + if (ret) {
> + dev_err(dev, "ufs common init fail\n");
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static int ufs_rockchip_device_reset(struct ufs_hba *hba)
> +{
> + struct ufs_rockchip_host *host = ufshcd_get_variant(hba);
> +
> + if (!host->rst_gpio)
> + return -EOPNOTSUPP;
> +
> + gpiod_set_value_cansleep(host->rst_gpio, 0);
> + udelay(20);
> +
> + gpiod_set_value_cansleep(host->rst_gpio, 1);
> + udelay(20);
> +
> + return 0;
> +}
> +
> +static const struct ufs_hba_variant_ops ufs_hba_rk3576_vops = {
> + .name = "rk3576",
> + .init = ufs_rockchip_rk3576_init,
> + .device_reset = ufs_rockchip_device_reset,
> + .hce_enable_notify = ufs_rockchip_hce_enable_notify,
> + .phy_initialization = ufs_rockchip_rk3576_phy_init,
> +};
> +
> +static const struct of_device_id ufs_rockchip_of_match[] = {
> + { .compatible = "rockchip,rk3576-ufs", .data = &ufs_hba_rk3576_vops},
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, ufs_rockchip_of_match);
> +
> +static int ufs_rockchip_probe(struct platform_device *pdev)
> +{
> + int err;
> + struct device *dev = &pdev->dev;
> + const struct ufs_hba_variant_ops *vops;
> +
> + vops = device_get_match_data(dev);
> + err = ufshcd_pltfrm_init(pdev, vops);
> + if (err)
> + dev_err(dev, "ufshcd_pltfrm_init() failed %d\n", err);
> +
> + return err;
> +}
> +
> +static void ufs_rockchip_remove(struct platform_device *pdev)
> +{
> + struct ufs_hba *hba = platform_get_drvdata(pdev);
> + struct ufs_rockchip_host *host = ufshcd_get_variant(hba);
> +
> + pm_runtime_forbid(&pdev->dev);
> + pm_runtime_get_noresume(&pdev->dev);
> + ufshcd_remove(hba);
> + ufshcd_dealloc_host(hba);
> + clk_disable_unprepare(host->ref_out_clk);
> +}
> +
> +static int ufs_rockchip_restore_link(struct ufs_hba *hba, bool is_store)
> +{
> + struct ufs_rockchip_host *host = ufshcd_get_variant(hba);
> + int err, retry = 3;
> +
> + if (is_store) {
> + host->ie = ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
> + host->ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER);
> + return 0;
> + }
> +
> + /* Enable controller */
> + err = ufshcd_hba_enable(hba);
> + if (err)
> + return err;
> +
> + /* Link startup and wait for DP */
> + do {
> + err = ufshcd_dme_link_startup(hba);
> + if (!err && ufshcd_is_device_present(hba)) {
> + dev_dbg_ratelimited(hba->dev, "rockchip link startup successfully.\n");
> + break;
> + }
> + } while (retry--);
> +
> + if (retry < 0) {
> + dev_err(hba->dev, "rockchip link startup failed.\n");
> + return -ENXIO;
> + }
> +
> + /* Restore negotiated power mode */
> + err = ufshcd_config_pwr_mode(hba, &(hba->pwr_info));
> + if (err)
> + dev_err(hba->dev, "Failed to restore power mode, err = %d\n", err);
> +
> + /* Restore task and transfer list */
> + ufshcd_writel(hba, 0xffffffff, REG_INTERRUPT_STATUS);
> + ufshcd_make_hba_operational(hba);
> +
> + /* Restore lost regs */
> + ufshcd_writel(hba, host->ie, REG_INTERRUPT_ENABLE);
> + ufshcd_writel(hba, host->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER);
> + ufshcd_writel(hba, 0x1, REG_UTP_TRANSFER_REQ_LIST_RUN_STOP);
> + ufshcd_writel(hba, 0x1, REG_UTP_TASK_REQ_LIST_RUN_STOP);
> +
> + return err;
> +}
> +
> +static int ufs_rockchip_runtime_suspend(struct device *dev)
> +{
> + struct ufs_hba *hba = dev_get_drvdata(dev);
> + struct ufs_rockchip_host *host = ufshcd_get_variant(hba);
> +
> + clk_disable_unprepare(host->ref_out_clk);
> + return ufs_rockchip_restore_link(hba, true);
> +}
> +
> +static int ufs_rockchip_runtime_resume(struct device *dev)
> +{
> + struct ufs_hba *hba = dev_get_drvdata(dev);
> + struct ufs_rockchip_host *host = ufshcd_get_variant(hba);
> + int err;
> +
> + err = clk_prepare_enable(host->ref_out_clk);
> + if (err) {
> + dev_err(hba->dev, "failed to enable ref out clock %d\n", err);
> + return err;
> + }
> +
> + reset_control_assert(host->rst);
> + udelay(1);
> + reset_control_deassert(host->rst);
> +
> + return ufs_rockchip_restore_link(hba, false);
> +}
> +
> +static int ufs_rockchip_suspend(struct device *dev)
> +{
> + struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> + if (pm_runtime_suspended(hba->dev))
> + return 0;
> +
> + ufs_rockchip_restore_link(hba, true);
> +
> + return 0;
> +}
> +
> +static int ufs_rockchip_resume(struct device *dev)
> +{
> + struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> + if (pm_runtime_suspended(hba->dev))
> + return 0;
> +
> + /* Reset device if possible */
> + ufs_rockchip_device_reset(hba);
> + ufs_rockchip_restore_link(hba, false);
> +
> + return 0;
> +}
> +
> +static const struct dev_pm_ops ufs_rockchip_pm_ops = {
> + SET_SYSTEM_SLEEP_PM_OPS(ufs_rockchip_suspend, ufs_rockchip_resume)
> + SET_RUNTIME_PM_OPS(ufs_rockchip_runtime_suspend, ufs_rockchip_runtime_resume, NULL)
> + .prepare = ufshcd_suspend_prepare,
> + .complete = ufshcd_resume_complete,
> +};
> +
> +static struct platform_driver ufs_rockchip_pltform = {
> + .probe = ufs_rockchip_probe,
> + .remove = ufs_rockchip_remove,
> + .driver = {
> + .name = "ufshcd-rockchip",
> + .pm = &ufs_rockchip_pm_ops,
> + .of_match_table = of_match_ptr(ufs_rockchip_of_match),
Drop of_match_ptr, you have here warnings.
Best regards,
Krzysztof
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
prev parent reply other threads:[~2024-08-06 8:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 7:19 [PATCH v1 0/3] Init support for RK3576 UFS controller Shawn Lin
2024-08-06 7:19 ` [PATCH v1 1/3] scsi: ufs: core: Export ufshcd_dme_link_startup() helper Shawn Lin
2024-08-06 7:19 ` [PATCH v1 2/3] dt-bindings: ufs: Document Rockchip UFS host controller Shawn Lin
2024-08-06 8:46 ` Krzysztof Kozlowski
2024-08-06 10:18 ` Rob Herring (Arm)
2024-08-06 7:20 ` [PATCH v1 3/3] scsi: ufs: rockchip: init support for UFS Shawn Lin
2024-08-06 8:43 ` Krzysztof Kozlowski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea136482-16bc-4e67-8370-de72ee0c034e@kernel.org \
--to=krzk@kernel.org \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@wdc.com \
--cc=bvanassche@acm.org \
--cc=cl@rock-chips.com \
--cc=devicetree@vger.kernel.org \
--cc=heiko@sntech.de \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=robh+dt@kernel.org \
--cc=shawn.lin@rock-chips.com \
--cc=zyf@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox