soc: mediatek: mtk-socinfo: Restructure SoC attribute information

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>
This commit is contained in:
Fei Shao 2024-12-19 19:33:50 +08:00 committed by AngeloGioacchino Del Regno
parent 2014c95afe
commit da77c2d3d0
No known key found for this signature in database
GPG Key ID: 9A3604CFAD978478

View 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);
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->machine = machine;
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))