Skip to content

Commit 96f9458

Browse files
alcharkkrzk
authored andcommitted
soc: Add VIA/WonderMedia SoC identification driver
Add a small SOC bus driver to parse the chip ID and revision made available on VIA/WonderMedia SoCs via their system configuration controller's SCC_ID register. This is intended to select appropriate sets of on-chip device quirks at runtime, as it has been found that even within the same SoC version there can be register-incompatible differences, such as with the SDMMC controller on WM8505 rev. A0-A1 vs. rev. A2. The list of SoC versions is compiled from various vendor source dumps and not all of them have corresponding mainline driver support. Some of them also have been seen with varying on-chip markings while sharing the same hardware chip ID's (as is the case with e.g. WM8850 vs. WM8950). In such cases the selection of names to use here among those seen in various source dumps and chip markings was arbitrary. Suggested by Krzysztof at [1] - thanks a lot! [1] https://lore.kernel.org/all/[email protected]/ Signed-off-by: Alexey Charkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]>
1 parent 04e394d commit 96f9458

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed

drivers/soc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ source "drivers/soc/tegra/Kconfig"
2828
source "drivers/soc/ti/Kconfig"
2929
source "drivers/soc/ux500/Kconfig"
3030
source "drivers/soc/versatile/Kconfig"
31+
source "drivers/soc/vt8500/Kconfig"
3132
source "drivers/soc/xilinx/Kconfig"
3233

3334
endmenu

drivers/soc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ obj-$(CONFIG_ARCH_TEGRA) += tegra/
3434
obj-y += ti/
3535
obj-$(CONFIG_ARCH_U8500) += ux500/
3636
obj-y += versatile/
37+
obj-y += vt8500/
3738
obj-y += xilinx/

drivers/soc/vt8500/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
if ARCH_VT8500 || COMPILE_TEST
4+
5+
menu "VIA/WonderMedia SoC drivers"
6+
7+
config WMT_SOCINFO
8+
bool "VIA/WonderMedia SoC Information driver"
9+
default ARCH_VT8500
10+
select SOC_BUS
11+
help
12+
Say yes to support decoding of VIA/WonderMedia system configuration
13+
register information. This currently includes just the chip ID register
14+
which helps identify the exact hardware revision of the SoC the kernel
15+
is running on (to know if any revision-specific quirks are required)
16+
17+
endmenu
18+
19+
endif

drivers/soc/vt8500/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
obj-$(CONFIG_WMT_SOCINFO) += wmt-socinfo.o

drivers/soc/vt8500/wmt-socinfo.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright 2025 Alexey Charkov <[email protected]>
4+
* Based on aspeed-socinfo.c
5+
*/
6+
7+
#include <linux/dev_printk.h>
8+
#include <linux/device.h>
9+
#include <linux/io.h>
10+
#include <linux/of.h>
11+
#include <linux/platform_device.h>
12+
#include <linux/sys_soc.h>
13+
14+
static const struct {
15+
const char *name;
16+
const u32 id;
17+
} chip_id_table[] = {
18+
/* VIA */
19+
{ "VT8420", 0x3300 },
20+
{ "VT8430", 0x3357 },
21+
{ "VT8500", 0x3400 },
22+
23+
/* WonderMedia */
24+
{ "WM8425", 0x3429 },
25+
{ "WM8435", 0x3437 },
26+
{ "WM8440", 0x3451 },
27+
{ "WM8505", 0x3426 },
28+
{ "WM8650", 0x3465 },
29+
{ "WM8750", 0x3445 },
30+
{ "WM8850", 0x3481 },
31+
{ "WM8880", 0x3498 },
32+
};
33+
34+
static const char *sccid_to_name(u32 sccid)
35+
{
36+
u32 id = sccid >> 16;
37+
unsigned int i;
38+
39+
for (i = 0 ; i < ARRAY_SIZE(chip_id_table) ; ++i) {
40+
if (chip_id_table[i].id == id)
41+
return chip_id_table[i].name;
42+
}
43+
44+
return "Unknown";
45+
}
46+
47+
static int wmt_socinfo_probe(struct platform_device *pdev)
48+
{
49+
struct device_node *np = pdev->dev.of_node;
50+
struct soc_device_attribute *attrs;
51+
struct soc_device *soc_dev;
52+
char letter, digit;
53+
void __iomem *reg;
54+
u32 sccid;
55+
56+
reg = devm_of_iomap(&pdev->dev, np, 0, NULL);
57+
if (IS_ERR(reg))
58+
return PTR_ERR(reg);
59+
60+
sccid = readl(reg);
61+
62+
attrs = devm_kzalloc(&pdev->dev, sizeof(*attrs), GFP_KERNEL);
63+
if (!attrs)
64+
return -ENOMEM;
65+
66+
/*
67+
* Machine: VIA APC Rock
68+
* Family: WM8850
69+
* Revision: A2
70+
* SoC ID: raw silicon revision id (34810103 in hexadecimal)
71+
*/
72+
73+
attrs->family = sccid_to_name(sccid);
74+
75+
letter = (sccid >> 8) & 0xf;
76+
letter = (letter - 1) + 'A';
77+
digit = sccid & 0xff;
78+
digit = (digit - 1) + '0';
79+
attrs->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL,
80+
"%c%c", letter, digit);
81+
82+
attrs->soc_id = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%08x", sccid);
83+
84+
if (!attrs->revision || !attrs->soc_id)
85+
return -ENOMEM;
86+
87+
soc_dev = soc_device_register(attrs);
88+
if (IS_ERR(soc_dev))
89+
return PTR_ERR(soc_dev);
90+
91+
dev_info(&pdev->dev,
92+
"VIA/WonderMedia %s rev %s (%s)\n",
93+
attrs->family,
94+
attrs->revision,
95+
attrs->soc_id);
96+
97+
platform_set_drvdata(pdev, soc_dev);
98+
return 0;
99+
}
100+
101+
static void wmt_socinfo_remove(struct platform_device *pdev)
102+
{
103+
struct soc_device *soc_dev = platform_get_drvdata(pdev);
104+
105+
soc_device_unregister(soc_dev);
106+
}
107+
108+
static const struct of_device_id wmt_socinfo_ids[] = {
109+
{ .compatible = "via,vt8500-scc-id" },
110+
{ /* Sentinel */ },
111+
};
112+
113+
static struct platform_driver wmt_socinfo = {
114+
.probe = wmt_socinfo_probe,
115+
.remove = wmt_socinfo_remove,
116+
.driver = {
117+
.name = "wmt-socinfo",
118+
.of_match_table = wmt_socinfo_ids,
119+
},
120+
};
121+
module_platform_driver(wmt_socinfo);
122+
123+
MODULE_AUTHOR("Alexey Charkov <[email protected]>");
124+
MODULE_DESCRIPTION("VIA/WonderMedia socinfo driver");
125+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)