1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
9 #include <dm/device_compat.h>
10 #include <linux/bitops.h>
11 #include <linux/err.h>
13 #define UFS_SS_CTRL 0x4
14 #define UFS_SS_RST_N_PCS BIT(0)
15 #define UFS_SS_CLK_26MHZ BIT(4)
17 static int ti_j721e_ufs_probe(struct udevice *dev)
25 ret = clk_get_by_index(dev, 0, &clk);
27 dev_err(dev, "failed to get M-PHY clock\n");
31 clock = clk_get_rate(&clk);
32 if (IS_ERR_VALUE(clock)) {
33 dev_err(dev, "failed to get rate\n");
37 base = dev_remap_addr_index(dev, 0);
39 if (clock == 26000000)
40 reg |= UFS_SS_CLK_26MHZ;
41 /* Take UFS slave device out of reset */
42 reg |= UFS_SS_RST_N_PCS;
43 writel(reg, base + UFS_SS_CTRL);
48 static int ti_j721e_ufs_remove(struct udevice *dev)
50 void __iomem *base = dev_remap_addr_index(dev, 0);
51 u32 reg = readl(base + UFS_SS_CTRL);
53 reg &= ~UFS_SS_RST_N_PCS;
54 writel(reg, base + UFS_SS_CTRL);
59 static const struct udevice_id ti_j721e_ufs_ids[] = {
61 .compatible = "ti,j721e-ufs",
66 U_BOOT_DRIVER(ti_j721e_ufs) = {
67 .name = "ti-j721e-ufs",
69 .of_match = ti_j721e_ufs_ids,
70 .probe = ti_j721e_ufs_probe,
71 .remove = ti_j721e_ufs_remove,
72 .flags = DM_FLAG_OS_PREPARE,