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
13 #include <dm/device_compat.h>
14 #include <linux/bitops.h>
15 #include <linux/err.h>
19 #define USEC_PER_SEC 1000000L
21 #define CDNS_UFS_REG_HCLKDIV 0xFC
22 #define CDNS_UFS_REG_PHY_XCFGD1 0x113C
24 static int cdns_ufs_link_startup_notify(struct ufs_hba *hba,
25 enum ufs_notify_change_status status)
27 hba->quirks |= UFSHCD_QUIRK_BROKEN_LCC;
30 return ufshcd_dme_set(hba,
31 UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE),
40 static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba)
43 unsigned long core_clk_rate = 0;
47 ret = clk_get_by_name(hba->dev, "core_clk", &clk);
49 dev_err(hba->dev, "failed to get core_clk clock\n");
53 core_clk_rate = clk_get_rate(&clk);
54 if (IS_ERR_VALUE(core_clk_rate)) {
55 dev_err(hba->dev, "%s: unable to find core_clk rate\n",
60 core_clk_div = core_clk_rate / USEC_PER_SEC;
61 ufshcd_writel(hba, core_clk_div, CDNS_UFS_REG_HCLKDIV);
66 static int cdns_ufs_hce_enable_notify(struct ufs_hba *hba,
67 enum ufs_notify_change_status status)
71 return cdns_ufs_set_hclkdiv(hba);
79 static int cdns_ufs_init(struct ufs_hba *hba)
83 /* Increase RX_Advanced_Min_ActivateTime_Capability */
84 data = ufshcd_readl(hba, CDNS_UFS_REG_PHY_XCFGD1);
86 ufshcd_writel(hba, data, CDNS_UFS_REG_PHY_XCFGD1);
91 static struct ufs_hba_ops cdns_pltfm_hba_ops = {
92 .init = cdns_ufs_init,
93 .hce_enable_notify = cdns_ufs_hce_enable_notify,
94 .link_startup_notify = cdns_ufs_link_startup_notify,
97 static int cdns_ufs_pltfm_probe(struct udevice *dev)
99 int err = ufshcd_probe(dev, &cdns_pltfm_hba_ops);
101 dev_err(dev, "ufshcd_probe() failed %d\n", err);
106 static int cdns_ufs_pltfm_bind(struct udevice *dev)
108 struct udevice *scsi_dev;
110 return ufs_scsi_bind(dev, &scsi_dev);
113 static const struct udevice_id cdns_ufs_pltfm_ids[] = {
115 .compatible = "cdns,ufshc-m31-16nm",
120 U_BOOT_DRIVER(cdns_ufs_pltfm) = {
121 .name = "cdns-ufs-pltfm",
123 .of_match = cdns_ufs_pltfm_ids,
124 .probe = cdns_ufs_pltfm_probe,
125 .bind = cdns_ufs_pltfm_bind,