i.MX drivers change for 6.16:

- A series from Peng Fan to dump full 128-bits UID for i.MX8MP
 -----BEGIN PGP SIGNATURE-----
 
 iQFIBAABCgAyFiEEFmJXigPl4LoGSz08UFdYWoewfM4FAmghimgUHHNoYXduZ3Vv
 QGtlcm5lbC5vcmcACgkQUFdYWoewfM5aJggAlDCcQsA4z24IPWb8FRKWb4r48sSv
 4Jpn1lkr42rIkGO/VwuBuPRbRWCz+zBulT9YDfLanSNUj5BCjhfHg+EUCjoy/KWz
 pdXNeRCQyQs9M4n0X6tyyRtNDhp/z9e7K5ZironWcJ8zKIvhtFqbzjh6fywne1Gl
 zc8rcrdgh44FsvRjrOudv1fQo7aVcURDnFAZMKT6m6VYtMa7dwb2zm+UETxvrOH/
 6GQst0q6bqG+SLljTjVGplUG0cV5gWvsAbO2ilTTq56bSXGaKNeZPJa2kNq5XCsA
 cb/OEJMBsVcM7YgpKr/Vl3/uqIamCKdMCt8QofZkj7muUVJrp6QxDsiafg==
 =J+MT
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEiK/NIGsWEZVxh/FrYKtH/8kJUicFAmgh5pYACgkQYKtH/8kJ
 UieatA/9E6Gz84sqWnBLshOI9FlyTLYL3emk/yOo9YwUr2lQHg4inPce7eMBE3k3
 4pEcHh8pZK8G/on8TthK+UgVZfBA6UD9HYdIQ78fpkbaZsED30zWZDF99f13lGuq
 L7zj329q1YkNgYP3Un9LFHM51jmXJS1R2DKmEvXymQgOUasGOzAuFVCjeeX3zra6
 IJc56KYjR2DdIcKiRzL1pt8FcOQag2K6AZOMjXEFAqTv/hiNvg371Rkdb2tl0RY4
 GQa+z13gcnVXwYOyruXXvxW1+pdWY9bOLWNnHTPMZ7dKhSDtOsffZMz9HlOcopXB
 IrRpVu5x9o+e/lwvjmJFME0io9Yos6qhxW7i9XfsvpY4pak58YAYMBF+ni+heWJ8
 Z/i+3NQOoWQ+cpeuB89xz+txvKNF16DUPeMjU6Rk5sEcG8A98dj3ZsoyfQiqfuym
 LacgWVawX0CrubgzKFLS36V+M5p5jv/922WmCSnQqjYLKMM4zNVC3ZXIttAaj6Qy
 N0D3Tg0CLVqr8gA9yYdvBWki4lL6k23vUpjCU4DAc8lCXPqtNglIXkMj9aAkpI8O
 dG5LYp2C9PYKtrGc8Y43muh33YQ/Eb6EvRxeKIolo7t6y48LPowa8vu3T+xMGrQp
 415nJCDIwr/1+wuASzCEv87FcbJUIecYvbKJhYWFMD4fyxJYllw=
 =yyBZ
 -----END PGP SIGNATURE-----

Merge tag 'imx-drivers-6.16' of https://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux into soc/drivers

i.MX drivers change for 6.16:

- A series from Peng Fan to dump full 128-bits UID for i.MX8MP

* tag 'imx-drivers-6.16' of https://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux:
  soc: imx8m: Dump higher 64bits UID
  soc: imx8m: Introduce soc_uid hook
  soc: imx8m: Cleanup with adding imx8m_soc_[un]prepare

Link: https://lore.kernel.org/r/20250512103858.50501-1-shawnguo@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2025-05-12 14:16:15 +02:00
commit b892924264
1 changed files with 115 additions and 76 deletions

View File

@ -24,13 +24,21 @@
#define OCOTP_UID_HIGH 0x420
#define IMX8MP_OCOTP_UID_OFFSET 0x10
#define IMX8MP_OCOTP_UID_HIGH 0xE00
/* Same as ANADIG_DIGPROG_IMX7D */
#define ANADIG_DIGPROG_IMX8MM 0x800
struct imx8_soc_data {
char *name;
int (*soc_revision)(u32 *socrev, u64 *socuid);
const char *ocotp_compatible;
int (*soc_revision)(struct platform_device *pdev, u32 *socrev);
int (*soc_uid)(struct platform_device *pdev, u64 *socuid);
};
struct imx8_soc_drvdata {
void __iomem *ocotp_base;
struct clk *clk;
};
#ifdef CONFIG_HAVE_ARM_SMCCC
@ -49,30 +57,24 @@ static u32 imx8mq_soc_revision_from_atf(void)
static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
#endif
static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
static int imx8m_soc_uid(struct platform_device *pdev, u64 *socuid)
{
struct device_node *np __free(device_node) =
of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
void __iomem *ocotp_base;
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
void __iomem *ocotp_base = drvdata->ocotp_base;
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
*socuid <<= 32;
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
return 0;
}
static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev)
{
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
void __iomem *ocotp_base = drvdata->ocotp_base;
u32 magic;
u32 rev;
struct clk *clk;
int ret;
if (!np)
return -EINVAL;
ocotp_base = of_iomap(np, 0);
if (!ocotp_base)
return -EINVAL;
clk = of_clk_get_by_name(np, NULL);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
goto err_clk;
}
clk_prepare_enable(clk);
/*
* SOC revision on older imx8mq is not available in fuses so query
@ -85,61 +87,28 @@ static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
rev = REV_B1;
}
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
*socuid <<= 32;
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
*socrev = rev;
clk_disable_unprepare(clk);
clk_put(clk);
iounmap(ocotp_base);
return 0;
}
static int imx8mp_soc_uid(struct platform_device *pdev, u64 *socuid)
{
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
void __iomem *ocotp_base = drvdata->ocotp_base;
socuid[0] = readl_relaxed(ocotp_base + OCOTP_UID_HIGH + IMX8MP_OCOTP_UID_OFFSET);
socuid[0] <<= 32;
socuid[0] |= readl_relaxed(ocotp_base + OCOTP_UID_LOW + IMX8MP_OCOTP_UID_OFFSET);
socuid[1] = readl_relaxed(ocotp_base + IMX8MP_OCOTP_UID_HIGH + 0x10);
socuid[1] <<= 32;
socuid[1] |= readl_relaxed(ocotp_base + IMX8MP_OCOTP_UID_HIGH);
return 0;
err_clk:
iounmap(ocotp_base);
return ret;
}
static int imx8mm_soc_uid(u64 *socuid)
{
struct device_node *np __free(device_node) =
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
void __iomem *ocotp_base;
struct clk *clk;
int ret = 0;
u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
IMX8MP_OCOTP_UID_OFFSET : 0;
if (!np)
return -EINVAL;
ocotp_base = of_iomap(np, 0);
if (!ocotp_base)
return -EINVAL;
clk = of_clk_get_by_name(np, NULL);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
goto err_clk;
}
clk_prepare_enable(clk);
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH + offset);
*socuid <<= 32;
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW + offset);
clk_disable_unprepare(clk);
clk_put(clk);
err_clk:
iounmap(ocotp_base);
return ret;
}
static int imx8mm_soc_revision(u32 *socrev, u64 *socuid)
static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev)
{
struct device_node *np __free(device_node) =
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
@ -156,27 +125,71 @@ static int imx8mm_soc_revision(u32 *socrev, u64 *socuid)
iounmap(anatop_base);
return imx8mm_soc_uid(socuid);
return 0;
}
static int imx8m_soc_prepare(struct platform_device *pdev, const char *ocotp_compatible)
{
struct device_node *np __free(device_node) =
of_find_compatible_node(NULL, NULL, ocotp_compatible);
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
int ret = 0;
if (!np)
return -EINVAL;
drvdata->ocotp_base = of_iomap(np, 0);
if (!drvdata->ocotp_base)
return -EINVAL;
drvdata->clk = of_clk_get_by_name(np, NULL);
if (IS_ERR(drvdata->clk)) {
ret = PTR_ERR(drvdata->clk);
goto err_clk;
}
return clk_prepare_enable(drvdata->clk);
err_clk:
iounmap(drvdata->ocotp_base);
return ret;
}
static void imx8m_soc_unprepare(struct platform_device *pdev)
{
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
clk_disable_unprepare(drvdata->clk);
clk_put(drvdata->clk);
iounmap(drvdata->ocotp_base);
}
static const struct imx8_soc_data imx8mq_soc_data = {
.name = "i.MX8MQ",
.ocotp_compatible = "fsl,imx8mq-ocotp",
.soc_revision = imx8mq_soc_revision,
.soc_uid = imx8m_soc_uid,
};
static const struct imx8_soc_data imx8mm_soc_data = {
.name = "i.MX8MM",
.ocotp_compatible = "fsl,imx8mm-ocotp",
.soc_revision = imx8mm_soc_revision,
.soc_uid = imx8m_soc_uid,
};
static const struct imx8_soc_data imx8mn_soc_data = {
.name = "i.MX8MN",
.ocotp_compatible = "fsl,imx8mm-ocotp",
.soc_revision = imx8mm_soc_revision,
.soc_uid = imx8m_soc_uid,
};
static const struct imx8_soc_data imx8mp_soc_data = {
.name = "i.MX8MP",
.ocotp_compatible = "fsl,imx8mm-ocotp",
.soc_revision = imx8mm_soc_revision,
.soc_uid = imx8mp_soc_uid,
};
static __maybe_unused const struct of_device_id imx8_soc_match[] = {
@ -207,17 +220,24 @@ static int imx8m_soc_probe(struct platform_device *pdev)
struct soc_device_attribute *soc_dev_attr;
struct platform_device *cpufreq_dev;
const struct imx8_soc_data *data;
struct imx8_soc_drvdata *drvdata;
struct device *dev = &pdev->dev;
const struct of_device_id *id;
struct soc_device *soc_dev;
u32 soc_rev = 0;
u64 soc_uid = 0;
u64 soc_uid[2] = {0, 0};
int ret;
soc_dev_attr = devm_kzalloc(dev, sizeof(*soc_dev_attr), GFP_KERNEL);
if (!soc_dev_attr)
return -ENOMEM;
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata)
return -ENOMEM;
platform_set_drvdata(pdev, drvdata);
soc_dev_attr->family = "Freescale i.MX";
ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
@ -231,18 +251,37 @@ static int imx8m_soc_probe(struct platform_device *pdev)
data = id->data;
if (data) {
soc_dev_attr->soc_id = data->name;
ret = imx8m_soc_prepare(pdev, data->ocotp_compatible);
if (ret)
return ret;
if (data->soc_revision) {
ret = data->soc_revision(&soc_rev, &soc_uid);
if (ret)
ret = data->soc_revision(pdev, &soc_rev);
if (ret) {
imx8m_soc_unprepare(pdev);
return ret;
}
}
if (data->soc_uid) {
ret = data->soc_uid(pdev, soc_uid);
if (ret) {
imx8m_soc_unprepare(pdev);
return ret;
}
}
imx8m_soc_unprepare(pdev);
}
soc_dev_attr->revision = imx8_revision(dev, soc_rev);
if (!soc_dev_attr->revision)
return -ENOMEM;
soc_dev_attr->serial_number = devm_kasprintf(dev, GFP_KERNEL, "%016llX", soc_uid);
if (soc_uid[1])
soc_dev_attr->serial_number = devm_kasprintf(dev, GFP_KERNEL, "%016llX%016llX",
soc_uid[1], soc_uid[0]);
else
soc_dev_attr->serial_number = devm_kasprintf(dev, GFP_KERNEL, "%016llX",
soc_uid[0]);
if (!soc_dev_attr->serial_number)
return -ENOMEM;