Skip to content

Commit 6981050

Browse files
MrVanShawn Guo
authored andcommitted
soc: imx8m: Introduce soc_uid hook
Cleanup code by introducing soc_uid hook, i.MX8MQ/M/N could reuse one function imx8m_soc_uid, i.MX8MP could have its own one. With this patch, it will easy to add 128bits UID support for i.MX8MP. Signed-off-by: Peng Fan <[email protected]> Reviewed-by: Marco Felsch <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent 390c010 commit 6981050

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

drivers/soc/imx/soc-imx8m.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
struct imx8_soc_data {
3232
char *name;
3333
const char *ocotp_compatible;
34-
int (*soc_revision)(struct platform_device *pdev, u32 *socrev, u64 *socuid);
34+
int (*soc_revision)(struct platform_device *pdev, u32 *socrev);
35+
int (*soc_uid)(struct platform_device *pdev, u64 *socuid);
3536
};
3637

3738
struct imx8_soc_drvdata {
@@ -55,7 +56,19 @@ static u32 imx8mq_soc_revision_from_atf(void)
5556
static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
5657
#endif
5758

58-
static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *socuid)
59+
static int imx8m_soc_uid(struct platform_device *pdev, u64 *socuid)
60+
{
61+
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
62+
void __iomem *ocotp_base = drvdata->ocotp_base;
63+
64+
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
65+
*socuid <<= 32;
66+
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
67+
68+
return 0;
69+
}
70+
71+
static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev)
5972
{
6073
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
6174
void __iomem *ocotp_base = drvdata->ocotp_base;
@@ -73,30 +86,24 @@ static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *s
7386
rev = REV_B1;
7487
}
7588

76-
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
77-
*socuid <<= 32;
78-
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
79-
8089
*socrev = rev;
8190

8291
return 0;
8392
}
8493

85-
static int imx8mm_soc_uid(struct platform_device *pdev, u64 *socuid)
94+
static int imx8mp_soc_uid(struct platform_device *pdev, u64 *socuid)
8695
{
8796
struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
8897
void __iomem *ocotp_base = drvdata->ocotp_base;
89-
u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
90-
IMX8MP_OCOTP_UID_OFFSET : 0;
9198

92-
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH + offset);
99+
*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH + IMX8MP_OCOTP_UID_OFFSET);
93100
*socuid <<= 32;
94-
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW + offset);
101+
*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW + IMX8MP_OCOTP_UID_OFFSET);
95102

96103
return 0;
97104
}
98105

99-
static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *socuid)
106+
static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev)
100107
{
101108
struct device_node *np __free(device_node) =
102109
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
@@ -113,7 +120,7 @@ static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *s
113120

114121
iounmap(anatop_base);
115122

116-
return imx8mm_soc_uid(pdev, socuid);
123+
return 0;
117124
}
118125

119126
static int imx8m_soc_prepare(struct platform_device *pdev, const char *ocotp_compatible)
@@ -156,24 +163,28 @@ static const struct imx8_soc_data imx8mq_soc_data = {
156163
.name = "i.MX8MQ",
157164
.ocotp_compatible = "fsl,imx8mq-ocotp",
158165
.soc_revision = imx8mq_soc_revision,
166+
.soc_uid = imx8m_soc_uid,
159167
};
160168

161169
static const struct imx8_soc_data imx8mm_soc_data = {
162170
.name = "i.MX8MM",
163171
.ocotp_compatible = "fsl,imx8mm-ocotp",
164172
.soc_revision = imx8mm_soc_revision,
173+
.soc_uid = imx8m_soc_uid,
165174
};
166175

167176
static const struct imx8_soc_data imx8mn_soc_data = {
168177
.name = "i.MX8MN",
169178
.ocotp_compatible = "fsl,imx8mm-ocotp",
170179
.soc_revision = imx8mm_soc_revision,
180+
.soc_uid = imx8m_soc_uid,
171181
};
172182

173183
static const struct imx8_soc_data imx8mp_soc_data = {
174184
.name = "i.MX8MP",
175185
.ocotp_compatible = "fsl,imx8mm-ocotp",
176186
.soc_revision = imx8mm_soc_revision,
187+
.soc_uid = imx8mp_soc_uid,
177188
};
178189

179190
static __maybe_unused const struct of_device_id imx8_soc_match[] = {
@@ -240,7 +251,14 @@ static int imx8m_soc_probe(struct platform_device *pdev)
240251
return ret;
241252

242253
if (data->soc_revision) {
243-
ret = data->soc_revision(pdev, &soc_rev, &soc_uid);
254+
ret = data->soc_revision(pdev, &soc_rev);
255+
if (ret) {
256+
imx8m_soc_unprepare(pdev);
257+
return ret;
258+
}
259+
}
260+
if (data->soc_uid) {
261+
ret = data->soc_uid(pdev, &soc_uid);
244262
if (ret) {
245263
imx8m_soc_unprepare(pdev);
246264
return ret;

0 commit comments

Comments
 (0)