]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
soc: mediatek: mtk-socinfo: Restructure SoC attribute information
authorFei Shao <fshao@chromium.org>
Thu, 19 Dec 2024 11:33:50 +0000 (19:33 +0800)
committerAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Tue, 18 Feb 2025 09:28:55 +0000 (10:28 +0100)
So far, the MediaTek socinfo driver populates the SoC information as
follows:
  - family:  "MediaTek"
  - machine: "<marketing_name> (<soc_name>)"
      e.g.,  "Kompanio 1380 (MT8195)"
  - soc_id:  <null>

This approach has some drawbacks:
1.  "soc_id" can be used for showing the SoC name (e.g. "MT8195"), while
    it's currently unused.
2.  The newer socinfo API automatically populates the "machine"
    attribute with the model name from board DTS if unspecified, which
    we may want to preserve if possible.
3.  "machine" combines the marketing name and SoC name, making it
    trickier to parse. Ideally, the marketing name and SoC name should
    be in separate attributes so userspace to utilize them as needed.
4.  There's no guarantee that the marketing name will be announced along
    with the SoC name. If either is undetermined, the current design
    will result in a malformed "machine" output. This is observed on
    some newer MediaTek platforms, where the marketing name is still
    undetermined but the SoC information needs to be settled for device
    registration and validation before launch.

To address these points, this commit proposes a new theme to display the
SoC information:
  - family:  "MediaTek <marketing_name>"
      e.g.,  "MediaTek Kompanio 1380"
  - machine: "<dt_model_name>" (auto-populated)
      e.g.,  "Acer Tomato (rev1) board"
  - soc_id:  "<soc_name>"
      e.g.,  "MT8195"

Moreover, if the marketing name is not provided, the driver displays
"MediaTek" in the "family" attribute instead, consistent with the
previous behavior.

Restructure the way driver populates the SoC information as described
above.

Note that Mediatek-based Chromebooks are the primary consumers of this
socinfo driver, and Google has prepared corresponding userspace changes
to comply with this update, so the impact to userspace is controlled.

Signed-off-by: Fei Shao <fshao@chromium.org>
Link: https://lore.kernel.org/r/20241219113411.3999355-1-fshao@chromium.org
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
drivers/soc/mediatek/mtk-socinfo.c

index 123b12cd25432b5db3033fddbff1dcd6f57ed8b1..b9dbc90d781401028f0aa90dcb3b378c1253c253 100644 (file)
@@ -62,17 +62,24 @@ static struct socinfo_data socinfo_data_table[] = {
 static int mtk_socinfo_create_socinfo_node(struct mtk_socinfo *mtk_socinfop)
 {
        struct soc_device_attribute *attrs;
-       static char machine[30] = {0};
+       struct socinfo_data *data = mtk_socinfop->socinfo_data;
        static const char *soc_manufacturer = "MediaTek";
 
        attrs = devm_kzalloc(mtk_socinfop->dev, sizeof(*attrs), GFP_KERNEL);
        if (!attrs)
                return -ENOMEM;
 
-       snprintf(machine, sizeof(machine), "%s (%s)", mtk_socinfop->socinfo_data->marketing_name,
-               mtk_socinfop->socinfo_data->soc_name);
-       attrs->family = soc_manufacturer;
-       attrs->machine = machine;
+       if (data->marketing_name != NULL && data->marketing_name[0] != '\0')
+               attrs->family = devm_kasprintf(mtk_socinfop->dev, GFP_KERNEL, "MediaTek %s",
+                                              data->marketing_name);
+       else
+               attrs->family = soc_manufacturer;
+
+       attrs->soc_id = data->soc_name;
+       /*
+        * The "machine" field will be populated automatically with the model
+        * name from board DTS (if available).
+        **/
 
        mtk_socinfop->soc_dev = soc_device_register(attrs);
        if (IS_ERR(mtk_socinfop->soc_dev))