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 <linux/err.h>
16 #define USEC_PER_SEC 1000000L
18 #define CDNS_UFS_REG_HCLKDIV 0xFC
19 #define CDNS_UFS_REG_PHY_XCFGD1 0x113C
21 static int cdns_ufs_link_startup_notify(struct ufs_hba *hba,
22 enum ufs_notify_change_status status)
24 hba->quirks |= UFSHCD_QUIRK_BROKEN_LCC;
27 return ufshcd_dme_set(hba,
28 UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE),
37 static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba)
40 unsigned long core_clk_rate = 0;
44 ret = clk_get_by_name(hba->dev, "core_clk", &clk);
46 dev_err(hba->dev, "failed to get core_clk clock\n");
50 core_clk_rate = clk_get_rate(&clk);
51 if (IS_ERR_VALUE(core_clk_rate)) {
52 dev_err(hba->dev, "%s: unable to find core_clk rate\n",
57 core_clk_div = core_clk_rate / USEC_PER_SEC;
58 ufshcd_writel(hba, core_clk_div, CDNS_UFS_REG_HCLKDIV);
63 static int cdns_ufs_hce_enable_notify(struct ufs_hba *hba,
64 enum ufs_notify_change_status status)
68 return cdns_ufs_set_hclkdiv(hba);
76 static int cdns_ufs_init(struct ufs_hba *hba)
80 /* Increase RX_Advanced_Min_ActivateTime_Capability */
81 data = ufshcd_readl(hba, CDNS_UFS_REG_PHY_XCFGD1);
83 ufshcd_writel(hba, data, CDNS_UFS_REG_PHY_XCFGD1);
88 static struct ufs_hba_ops cdns_pltfm_hba_ops = {
89 .init = cdns_ufs_init,
90 .hce_enable_notify = cdns_ufs_hce_enable_notify,
91 .link_startup_notify = cdns_ufs_link_startup_notify,
94 static int cdns_ufs_pltfm_probe(struct udevice *dev)
96 int err = ufshcd_probe(dev, &cdns_pltfm_hba_ops);
98 dev_err(dev, "ufshcd_probe() failed %d\n", err);
103 static int cdns_ufs_pltfm_bind(struct udevice *dev)
105 struct udevice *scsi_dev;
107 return ufs_scsi_bind(dev, &scsi_dev);
110 static const struct udevice_id cdns_ufs_pltfm_ids[] = {
112 .compatible = "cdns,ufshc-m31-16nm",
117 U_BOOT_DRIVER(cdns_ufs_pltfm) = {
118 .name = "cdns-ufs-pltfm",
120 .of_match = cdns_ufs_pltfm_ids,
121 .probe = cdns_ufs_pltfm_probe,
122 .bind = cdns_ufs_pltfm_bind,