Skip to content

Commit 2100082

Browse files
committed
Merge tag 'imx-drivers-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux into arm/drivers
i.MX driver changes for 5.3: - Add i.MX SCU based SoC bus driver for i.MX8QXP SoC support, which talks to SCU firmware for getting SoC ID and revision. - Update soc-imx8 bus driver to read imx8mm soc revision from anatop. - Add i.MX8MN SoC bus support into soc-imx8 driver. - Various small improvements on soc-imx8 bus driver. * tag 'imx-drivers-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux: soc: imx: Add i.MX8MN SoC driver support soc: imx8: Use existing of_root directly soc: imx8: Fix potential kernel dump in error path soc: imx: soc-imx8: Correct return value of error handle soc: imx: soc-imx8: Avoid unnecessary of_node_put() in error handling soc: imx: Add SCU SoC info driver support soc: imx: Read imx8mm soc revision from anatop Signed-off-by: Olof Johansson <[email protected]>
2 parents 0aa447e + db10496 commit 2100082

File tree

4 files changed

+204
-13
lines changed

4 files changed

+204
-13
lines changed

drivers/soc/imx/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ config IMX_GPCV2_PM_DOMAINS
88
select PM_GENERIC_DOMAINS
99
default y if SOC_IMX7D
1010

11+
config IMX_SCU_SOC
12+
bool "i.MX System Controller Unit SoC info support"
13+
depends on IMX_SCU
14+
select SOC_BUS
15+
help
16+
If you say yes here you get support for the NXP i.MX System
17+
Controller Unit SoC info module, it will provide the SoC info
18+
like SoC family, ID and revision etc.
19+
1120
endmenu

drivers/soc/imx/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
33
obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o
44
obj-$(CONFIG_ARCH_MXC) += soc-imx8.o
5+
obj-$(CONFIG_IMX_SCU_SOC) += soc-imx-scu.o

drivers/soc/imx/soc-imx-scu.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright 2019 NXP.
4+
*/
5+
6+
#include <dt-bindings/firmware/imx/rsrc.h>
7+
#include <linux/firmware/imx/sci.h>
8+
#include <linux/slab.h>
9+
#include <linux/sys_soc.h>
10+
#include <linux/platform_device.h>
11+
#include <linux/of.h>
12+
13+
#define IMX_SCU_SOC_DRIVER_NAME "imx-scu-soc"
14+
15+
static struct imx_sc_ipc *soc_ipc_handle;
16+
17+
struct imx_sc_msg_misc_get_soc_id {
18+
struct imx_sc_rpc_msg hdr;
19+
union {
20+
struct {
21+
u32 control;
22+
u16 resource;
23+
} __packed req;
24+
struct {
25+
u32 id;
26+
} resp;
27+
} data;
28+
} __packed;
29+
30+
static int imx_scu_soc_id(void)
31+
{
32+
struct imx_sc_msg_misc_get_soc_id msg;
33+
struct imx_sc_rpc_msg *hdr = &msg.hdr;
34+
int ret;
35+
36+
hdr->ver = IMX_SC_RPC_VERSION;
37+
hdr->svc = IMX_SC_RPC_SVC_MISC;
38+
hdr->func = IMX_SC_MISC_FUNC_GET_CONTROL;
39+
hdr->size = 3;
40+
41+
msg.data.req.control = IMX_SC_C_ID;
42+
msg.data.req.resource = IMX_SC_R_SYSTEM;
43+
44+
ret = imx_scu_call_rpc(soc_ipc_handle, &msg, true);
45+
if (ret) {
46+
pr_err("%s: get soc info failed, ret %d\n", __func__, ret);
47+
return ret;
48+
}
49+
50+
return msg.data.resp.id;
51+
}
52+
53+
static int imx_scu_soc_probe(struct platform_device *pdev)
54+
{
55+
struct soc_device_attribute *soc_dev_attr;
56+
struct soc_device *soc_dev;
57+
int id, ret;
58+
u32 val;
59+
60+
ret = imx_scu_get_handle(&soc_ipc_handle);
61+
if (ret)
62+
return ret;
63+
64+
soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
65+
GFP_KERNEL);
66+
if (!soc_dev_attr)
67+
return -ENOMEM;
68+
69+
soc_dev_attr->family = "Freescale i.MX";
70+
71+
ret = of_property_read_string(of_root,
72+
"model",
73+
&soc_dev_attr->machine);
74+
if (ret)
75+
return ret;
76+
77+
id = imx_scu_soc_id();
78+
if (id < 0)
79+
return -EINVAL;
80+
81+
/* format soc_id value passed from SCU firmware */
82+
val = id & 0x1f;
83+
soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%x", val);
84+
if (!soc_dev_attr->soc_id)
85+
return -ENOMEM;
86+
87+
/* format revision value passed from SCU firmware */
88+
val = (id >> 5) & 0xf;
89+
val = (((val >> 2) + 1) << 4) | (val & 0x3);
90+
soc_dev_attr->revision = kasprintf(GFP_KERNEL,
91+
"%d.%d",
92+
(val >> 4) & 0xf,
93+
val & 0xf);
94+
if (!soc_dev_attr->revision) {
95+
ret = -ENOMEM;
96+
goto free_soc_id;
97+
}
98+
99+
soc_dev = soc_device_register(soc_dev_attr);
100+
if (IS_ERR(soc_dev)) {
101+
ret = PTR_ERR(soc_dev);
102+
goto free_revision;
103+
}
104+
105+
return 0;
106+
107+
free_revision:
108+
kfree(soc_dev_attr->revision);
109+
free_soc_id:
110+
kfree(soc_dev_attr->soc_id);
111+
return ret;
112+
}
113+
114+
static struct platform_driver imx_scu_soc_driver = {
115+
.driver = {
116+
.name = IMX_SCU_SOC_DRIVER_NAME,
117+
},
118+
.probe = imx_scu_soc_probe,
119+
};
120+
121+
static int __init imx_scu_soc_init(void)
122+
{
123+
struct platform_device *pdev;
124+
struct device_node *np;
125+
int ret;
126+
127+
np = of_find_compatible_node(NULL, NULL, "fsl,imx-scu");
128+
if (!np)
129+
return -ENODEV;
130+
131+
of_node_put(np);
132+
133+
ret = platform_driver_register(&imx_scu_soc_driver);
134+
if (ret)
135+
return ret;
136+
137+
pdev = platform_device_register_simple(IMX_SCU_SOC_DRIVER_NAME,
138+
-1, NULL, 0);
139+
if (IS_ERR(pdev))
140+
platform_driver_unregister(&imx_scu_soc_driver);
141+
142+
return PTR_ERR_OR_ZERO(pdev);
143+
}
144+
device_initcall(imx_scu_soc_init);

drivers/soc/imx/soc-imx8.c

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#define IMX8MQ_SW_INFO_B1 0x40
1717
#define IMX8MQ_SW_MAGIC_B1 0xff0055aa
1818

19+
/* Same as ANADIG_DIGPROG_IMX7D */
20+
#define ANADIG_DIGPROG_IMX8MM 0x800
21+
1922
struct imx8_soc_data {
2023
char *name;
2124
u32 (*soc_revision)(void);
@@ -46,13 +49,45 @@ static u32 __init imx8mq_soc_revision(void)
4649
return rev;
4750
}
4851

52+
static u32 __init imx8mm_soc_revision(void)
53+
{
54+
struct device_node *np;
55+
void __iomem *anatop_base;
56+
u32 rev;
57+
58+
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
59+
if (!np)
60+
return 0;
61+
62+
anatop_base = of_iomap(np, 0);
63+
WARN_ON(!anatop_base);
64+
65+
rev = readl_relaxed(anatop_base + ANADIG_DIGPROG_IMX8MM);
66+
67+
iounmap(anatop_base);
68+
of_node_put(np);
69+
return rev;
70+
}
71+
4972
static const struct imx8_soc_data imx8mq_soc_data = {
5073
.name = "i.MX8MQ",
5174
.soc_revision = imx8mq_soc_revision,
5275
};
5376

77+
static const struct imx8_soc_data imx8mm_soc_data = {
78+
.name = "i.MX8MM",
79+
.soc_revision = imx8mm_soc_revision,
80+
};
81+
82+
static const struct imx8_soc_data imx8mn_soc_data = {
83+
.name = "i.MX8MN",
84+
.soc_revision = imx8mm_soc_revision,
85+
};
86+
5487
static const struct of_device_id imx8_soc_match[] = {
5588
{ .compatible = "fsl,imx8mq", .data = &imx8mq_soc_data, },
89+
{ .compatible = "fsl,imx8mm", .data = &imx8mm_soc_data, },
90+
{ .compatible = "fsl,imx8mn", .data = &imx8mn_soc_data, },
5691
{ }
5792
};
5893

@@ -65,28 +100,26 @@ static int __init imx8_soc_init(void)
65100
{
66101
struct soc_device_attribute *soc_dev_attr;
67102
struct soc_device *soc_dev;
68-
struct device_node *root;
69103
const struct of_device_id *id;
70104
u32 soc_rev = 0;
71105
const struct imx8_soc_data *data;
72106
int ret;
73107

74108
soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
75109
if (!soc_dev_attr)
76-
return -ENODEV;
110+
return -ENOMEM;
77111

78112
soc_dev_attr->family = "Freescale i.MX";
79113

80-
root = of_find_node_by_path("/");
81-
ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
114+
ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
82115
if (ret)
83116
goto free_soc;
84117

85-
id = of_match_node(imx8_soc_match, root);
86-
if (!id)
118+
id = of_match_node(imx8_soc_match, of_root);
119+
if (!id) {
120+
ret = -ENODEV;
87121
goto free_soc;
88-
89-
of_node_put(root);
122+
}
90123

91124
data = id->data;
92125
if (data) {
@@ -96,20 +129,24 @@ static int __init imx8_soc_init(void)
96129
}
97130

98131
soc_dev_attr->revision = imx8_revision(soc_rev);
99-
if (!soc_dev_attr->revision)
132+
if (!soc_dev_attr->revision) {
133+
ret = -ENOMEM;
100134
goto free_soc;
135+
}
101136

102137
soc_dev = soc_device_register(soc_dev_attr);
103-
if (IS_ERR(soc_dev))
138+
if (IS_ERR(soc_dev)) {
139+
ret = PTR_ERR(soc_dev);
104140
goto free_rev;
141+
}
105142

106143
return 0;
107144

108145
free_rev:
109-
kfree(soc_dev_attr->revision);
146+
if (strcmp(soc_dev_attr->revision, "unknown"))
147+
kfree(soc_dev_attr->revision);
110148
free_soc:
111149
kfree(soc_dev_attr);
112-
of_node_put(root);
113-
return -ENODEV;
150+
return ret;
114151
}
115152
device_initcall(imx8_soc_init);

0 commit comments

Comments
 (0)