1 // SPDX-License-Identifier: GPL-2.0+
3 * cdns-platform.c - Platform driver for Cadence UFSHCI device
5 * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com
12 #include <dm/device_compat.h>
13 #include <linux/bitops.h>
14 #include <linux/err.h>
15 #include <linux/time.h>
19 #define CDNS_UFS_REG_HCLKDIV 0xFC
20 #define CDNS_UFS_REG_PHY_XCFGD1 0x113C
22 static int cdns_ufs_link_startup_notify(struct ufs_hba *hba,
23 enum ufs_notify_change_status status)
25 hba->quirks |= UFSHCD_QUIRK_BROKEN_LCC;
28 return ufshcd_dme_set(hba,
29 UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE),
38 static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba)
41 unsigned long core_clk_rate = 0;
45 ret = clk_get_by_name(hba->dev, "core_clk", &clk);
47 dev_err(hba->dev, "failed to get core_clk clock\n");
51 core_clk_rate = clk_get_rate(&clk);
52 if (IS_ERR_VALUE(core_clk_rate)) {
53 dev_err(hba->dev, "%s: unable to find core_clk rate\n",
58 core_clk_div = core_clk_rate / USEC_PER_SEC;
59 ufshcd_writel(hba, core_clk_div, CDNS_UFS_REG_HCLKDIV);
64 static int cdns_ufs_hce_enable_notify(struct ufs_hba *hba,
65 enum ufs_notify_change_status status)
69 return cdns_ufs_set_hclkdiv(hba);
77 static int cdns_ufs_init(struct ufs_hba *hba)
81 /* Increase RX_Advanced_Min_ActivateTime_Capability */
82 data = ufshcd_readl(hba, CDNS_UFS_REG_PHY_XCFGD1);
84 ufshcd_writel(hba, data, CDNS_UFS_REG_PHY_XCFGD1);
89 static struct ufs_hba_ops cdns_pltfm_hba_ops = {
90 .init = cdns_ufs_init,
91 .hce_enable_notify = cdns_ufs_hce_enable_notify,
92 .link_startup_notify = cdns_ufs_link_startup_notify,
95 static int cdns_ufs_pltfm_probe(struct udevice *dev)
97 int err = ufshcd_probe(dev, &cdns_pltfm_hba_ops);
99 dev_err(dev, "ufshcd_probe() failed %d\n", err);
104 static int cdns_ufs_pltfm_bind(struct udevice *dev)
106 struct udevice *scsi_dev;
108 return ufs_scsi_bind(dev, &scsi_dev);
111 static const struct udevice_id cdns_ufs_pltfm_ids[] = {
113 .compatible = "cdns,ufshc-m31-16nm",
118 U_BOOT_DRIVER(cdns_ufs_pltfm) = {
119 .name = "cdns-ufs-pltfm",
121 .of_match = cdns_ufs_pltfm_ids,
122 .probe = cdns_ufs_pltfm_probe,
123 .bind = cdns_ufs_pltfm_bind,