1 // SPDX-License-Identifier: GPL-2.0+
3 * cdns-platform.c - Platform driver for Cadence UFSHCI device
5 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
12 #include <dm/device_compat.h>
13 #include <linux/bitops.h>
14 #include <linux/err.h>
18 #define USEC_PER_SEC 1000000L
20 #define CDNS_UFS_REG_HCLKDIV 0xFC
21 #define CDNS_UFS_REG_PHY_XCFGD1 0x113C
23 static int cdns_ufs_link_startup_notify(struct ufs_hba *hba,
24 enum ufs_notify_change_status status)
26 hba->quirks |= UFSHCD_QUIRK_BROKEN_LCC;
29 return ufshcd_dme_set(hba,
30 UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE),
39 static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba)
42 unsigned long core_clk_rate = 0;
46 ret = clk_get_by_name(hba->dev, "core_clk", &clk);
48 dev_err(hba->dev, "failed to get core_clk clock\n");
52 core_clk_rate = clk_get_rate(&clk);
53 if (IS_ERR_VALUE(core_clk_rate)) {
54 dev_err(hba->dev, "%s: unable to find core_clk rate\n",
59 core_clk_div = core_clk_rate / USEC_PER_SEC;
60 ufshcd_writel(hba, core_clk_div, CDNS_UFS_REG_HCLKDIV);
65 static int cdns_ufs_hce_enable_notify(struct ufs_hba *hba,
66 enum ufs_notify_change_status status)
70 return cdns_ufs_set_hclkdiv(hba);
78 static int cdns_ufs_init(struct ufs_hba *hba)
82 /* Increase RX_Advanced_Min_ActivateTime_Capability */
83 data = ufshcd_readl(hba, CDNS_UFS_REG_PHY_XCFGD1);
85 ufshcd_writel(hba, data, CDNS_UFS_REG_PHY_XCFGD1);
90 static struct ufs_hba_ops cdns_pltfm_hba_ops = {
91 .init = cdns_ufs_init,
92 .hce_enable_notify = cdns_ufs_hce_enable_notify,
93 .link_startup_notify = cdns_ufs_link_startup_notify,
96 static int cdns_ufs_pltfm_probe(struct udevice *dev)
98 int err = ufshcd_probe(dev, &cdns_pltfm_hba_ops);
100 dev_err(dev, "ufshcd_probe() failed %d\n", err);
105 static int cdns_ufs_pltfm_bind(struct udevice *dev)
107 struct udevice *scsi_dev;
109 return ufs_scsi_bind(dev, &scsi_dev);
112 static const struct udevice_id cdns_ufs_pltfm_ids[] = {
114 .compatible = "cdns,ufshc-m31-16nm",
119 U_BOOT_DRIVER(cdns_ufs_pltfm) = {
120 .name = "cdns-ufs-pltfm",
122 .of_match = cdns_ufs_pltfm_ids,
123 .probe = cdns_ufs_pltfm_probe,
124 .bind = cdns_ufs_pltfm_bind,