In ti_j721e_ufs_probe there is a call to clk_get_rate but the code after that attempts to detect an error from that call incorrectly uses IS_ERR_VALUE. Instead the test should just be for regular error codes. The call returns an unsigned long so that needs to be cast to a signed type first of all. This issue was found by Smatch. Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org> Reviewed-by: Anshul Dalal <anshuld@ti.com> Link: https://patch.msgid.link/20251007-ufs_ti-v2-1-501f575b6947@linaro.org Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
74 lines
1.5 KiB
C
74 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
|
|
*/
|
|
|
|
#include <asm/io.h>
|
|
#include <clk.h>
|
|
#include <dm.h>
|
|
#include <dm/device_compat.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/err.h>
|
|
|
|
#define UFS_SS_CTRL 0x4
|
|
#define UFS_SS_RST_N_PCS BIT(0)
|
|
#define UFS_SS_CLK_26MHZ BIT(4)
|
|
|
|
static int ti_j721e_ufs_probe(struct udevice *dev)
|
|
{
|
|
void __iomem *base;
|
|
unsigned long clock;
|
|
struct clk clk;
|
|
u32 reg = 0;
|
|
int ret;
|
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
|
if (ret) {
|
|
dev_err(dev, "failed to get M-PHY clock\n");
|
|
return ret;
|
|
}
|
|
|
|
clock = clk_get_rate(&clk);
|
|
if ((long)clock <= 0) {
|
|
dev_err(dev, "failed to get rate\n");
|
|
return clock ? clock : -EIO;
|
|
}
|
|
|
|
base = dev_remap_addr_index(dev, 0);
|
|
|
|
if (clock == 26000000)
|
|
reg |= UFS_SS_CLK_26MHZ;
|
|
/* Take UFS slave device out of reset */
|
|
reg |= UFS_SS_RST_N_PCS;
|
|
writel(reg, base + UFS_SS_CTRL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ti_j721e_ufs_remove(struct udevice *dev)
|
|
{
|
|
void __iomem *base = dev_remap_addr_index(dev, 0);
|
|
u32 reg = readl(base + UFS_SS_CTRL);
|
|
|
|
reg &= ~UFS_SS_RST_N_PCS;
|
|
writel(reg, base + UFS_SS_CTRL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct udevice_id ti_j721e_ufs_ids[] = {
|
|
{
|
|
.compatible = "ti,j721e-ufs",
|
|
},
|
|
{},
|
|
};
|
|
|
|
U_BOOT_DRIVER(ti_j721e_ufs) = {
|
|
.name = "ti-j721e-ufs",
|
|
.id = UCLASS_MISC,
|
|
.of_match = ti_j721e_ufs_ids,
|
|
.probe = ti_j721e_ufs_probe,
|
|
.remove = ti_j721e_ufs_remove,
|
|
.flags = DM_FLAG_OS_PREPARE,
|
|
};
|