]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/soc/amlogic/meson-gx-socinfo.c
2 * Copyright (c) 2017 BayLibre, SAS
3 * Author: Neil Armstrong <narmstrong@baylibre.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/of_address.h>
11 #include <linux/of_platform.h>
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
14 #include <linux/sys_soc.h>
15 #include <linux/bitfield.h>
16 #include <linux/regmap.h>
17 #include <linux/mfd/syscon.h>
19 #define AO_SEC_SD_CFG8 0xe0
20 #define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8
22 #define SOCINFO_MAJOR GENMASK(31, 24)
23 #define SOCINFO_MINOR GENMASK(23, 16)
24 #define SOCINFO_PACK GENMASK(15, 8)
25 #define SOCINFO_MISC GENMASK(7, 0)
27 static const struct meson_gx_soc_id
{
38 static const struct meson_gx_package_id
{
40 unsigned int major_id
;
44 { "S905M", 0x1f, 0x20 },
46 { "S905X", 0x21, 0x80 },
47 { "S905L", 0x21, 0xc0 },
48 { "S905M2", 0x21, 0xe0 },
52 static inline unsigned int socinfo_to_major(u32 socinfo
)
54 return FIELD_GET(SOCINFO_MAJOR
, socinfo
);
57 static inline unsigned int socinfo_to_minor(u32 socinfo
)
59 return FIELD_GET(SOCINFO_MINOR
, socinfo
);
62 static inline unsigned int socinfo_to_pack(u32 socinfo
)
64 return FIELD_GET(SOCINFO_PACK
, socinfo
);
67 static inline unsigned int socinfo_to_misc(u32 socinfo
)
69 return FIELD_GET(SOCINFO_MISC
, socinfo
);
72 static const char *socinfo_to_package_id(u32 socinfo
)
74 unsigned int pack
= socinfo_to_pack(socinfo
) & 0xf0;
75 unsigned int major
= socinfo_to_major(socinfo
);
78 for (i
= 0 ; i
< ARRAY_SIZE(soc_packages
) ; ++i
) {
79 if (soc_packages
[i
].major_id
== major
&&
80 soc_packages
[i
].pack_id
== pack
)
81 return soc_packages
[i
].name
;
87 static const char *socinfo_to_soc_id(u32 socinfo
)
89 unsigned int id
= socinfo_to_major(socinfo
);
92 for (i
= 0 ; i
< ARRAY_SIZE(soc_ids
) ; ++i
) {
93 if (soc_ids
[i
].id
== id
)
94 return soc_ids
[i
].name
;
100 int __init
meson_gx_socinfo_init(void)
102 struct soc_device_attribute
*soc_dev_attr
;
103 struct soc_device
*soc_dev
;
104 struct device_node
*np
;
105 struct regmap
*regmap
;
106 unsigned int socinfo
;
110 /* look up for chipid node */
111 np
= of_find_compatible_node(NULL
, NULL
, "amlogic,meson-gx-ao-secure");
115 /* check if interface is enabled */
116 if (!of_device_is_available(np
))
119 /* check if chip-id is available */
120 if (!of_property_read_bool(np
, "amlogic,has-chip-id"))
123 /* node should be a syscon */
124 regmap
= syscon_node_to_regmap(np
);
126 if (IS_ERR(regmap
)) {
127 pr_err("%s: failed to get regmap\n", __func__
);
131 ret
= regmap_read(regmap
, AO_SEC_SOCINFO_OFFSET
, &socinfo
);
136 pr_err("%s: invalid chipid value\n", __func__
);
140 soc_dev_attr
= kzalloc(sizeof(*soc_dev_attr
), GFP_KERNEL
);
144 soc_dev_attr
->family
= "Amlogic Meson";
146 np
= of_find_node_by_path("/");
147 of_property_read_string(np
, "model", &soc_dev_attr
->machine
);
150 soc_dev_attr
->revision
= kasprintf(GFP_KERNEL
, "%x:%x - %x:%x",
151 socinfo_to_major(socinfo
),
152 socinfo_to_minor(socinfo
),
153 socinfo_to_pack(socinfo
),
154 socinfo_to_misc(socinfo
));
155 soc_dev_attr
->soc_id
= kasprintf(GFP_KERNEL
, "%s (%s)",
156 socinfo_to_soc_id(socinfo
),
157 socinfo_to_package_id(socinfo
));
159 soc_dev
= soc_device_register(soc_dev_attr
);
160 if (IS_ERR(soc_dev
)) {
161 kfree(soc_dev_attr
->revision
);
162 kfree_const(soc_dev_attr
->soc_id
);
164 return PTR_ERR(soc_dev
);
166 dev
= soc_device_to_device(soc_dev
);
168 dev_info(dev
, "Amlogic Meson %s Revision %x:%x (%x:%x) Detected\n",
169 soc_dev_attr
->soc_id
,
170 socinfo_to_major(socinfo
),
171 socinfo_to_minor(socinfo
),
172 socinfo_to_pack(socinfo
),
173 socinfo_to_misc(socinfo
));
177 device_initcall(meson_gx_socinfo_init
);