From nobody Fri Dec 19 18:47:55 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7851244678; Mon, 23 Jun 2025 12:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680105; cv=none; b=SLB42GrVj3t4Ct2A2YQFGz6LmedLWtLB61udhm2x9yQRJD5P7l+txDIVNqOw+nq5b6Xv/nvTWN8M4VrsY7JgolCdh+ISKWz6BzKu9wPVvxAJSOtwG4FeoooaoPvlkywusVCaf8I4vQPGoi7SJGE1+6qgvazyszYvsWwNVXylgvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680105; c=relaxed/simple; bh=gbtG8/FPSoapFfBK9PFojeL8xN0vfOSrk+SUI+ArA44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aUGb44/krlOQb0BVVThnhXd7TRyDRNXUn+rrzQ2RyGj/WGFH/Z/DnJFWp71yEyrxRhDfoBxVix94uvZE/dAE+stWQSAMD6+x+2hyfjHmVa7PgBnXP2FyPrsJiFCnNfiXmR+IXCnO5LxSuItnBl3GvhTOSdswBroV6URkCIVYam4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=DbtqbiGr; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="DbtqbiGr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1750680102; bh=gbtG8/FPSoapFfBK9PFojeL8xN0vfOSrk+SUI+ArA44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DbtqbiGrPGc0dZ9y8hjZ9cDu/guznwGPO+PpujFkXw7zinQ6dMIHoghLtlg1UXGMF IOQ0GqcE8mQel7ATHIV8MkDGoaSaEGAyAgpmwCJRJTy+4M/1If5hMnwvwjQhUQwetp QcvPygO/MET03byT5A8W5EYeKrfsHC+2ISSGdt22gDS0rv3fjNcRmVytUDpHG+UzsK pGtoNVI+0zpG1T0ogrDRwUwmb846qGsEpC7T8rKGPJZInEpt/D9YVFaeUkSp2ay2r0 YkYZqPmoG44xH/5HV0dO+GczA64eEp/utF9asBLjrYHttUSk+u9WyEX0gvJztd6H2S VoIqSiRPwoabQ== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id 5C46617E0EC0; Mon, 23 Jun 2025 14:01:41 +0200 (CEST) From: AngeloGioacchino Del Regno To: robh@kernel.org Cc: krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, sudeep.holla@arm.com, cristian.marussi@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, arm-scmi@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol Date: Mon, 23 Jun 2025 14:01:35 +0200 Message-ID: <20250623120136.109311-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250623120136.109311-1-angelogioacchino.delregno@collabora.com> References: <20250623120136.109311-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the MediaTek TinySYS SCMI Extension protocol as found on a number of SoCs, including MT6895 and MT8196. This includes controls and power state notifications for the GPU, CPU Memory latency Manager (cm_mgr), SLBC, SSPM and others. Signed-off-by: AngeloGioacchino Del Regno --- .../firmware/mediatek,mt6895-scmi.yaml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/mediatek,mt6= 895-scmi.yaml diff --git a/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scm= i.yaml b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.ya= ml new file mode 100644 index 000000000000..98a5b81983b1 --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2025 Collabora Ltd +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/mediatek,mt6895-scmi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek System Control and Management Interface(SCMI) Vendor Proto= cols Extension + +maintainers: + - AngeloGioacchino Del Regno + +properties: + protocol@80: + $ref: '/schemas/firmware/arm,scmi.yaml#/$defs/protocol-node' + unevaluatedProperties: false + + properties: + reg: + const: 0x80 + +additionalProperties: true --=20 2.49.0 From nobody Fri Dec 19 18:47:55 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C04AC24A066; Mon, 23 Jun 2025 12:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680107; cv=none; b=uqK/NsjPp8LmtVzKYB1puorVEq3wxorS7bhMVC8PS8ZGdJgu+3auwrtsGz2ll4WiErFi1lUqKqVFZ0oilwaAQ+hTtF60ok71rxBbG7ffSSl/eWDIqR3B9SUmzRX3uMS1nVAYZ2sQzlawd8MpRiWL+9pS50uqJHRE410qv+YO8L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680107; c=relaxed/simple; bh=bdUIv+Bi0JKFaMkv/B0ZJnFgDGfpNHDxCyP1lPlsIyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y4qV0C6UYbWh6Aaac77kT8sFusePB7BvP3u6upYdLiS9G/mhX1jJsLGC8fgTFrovB3PY8fSEe8y3Fz/GPrsHivhjKxsuOeP1icu653WD/IlSZ5g/JtjIa6a7GYfWIQDHbO0V//t+OBJ2oQjLy+oa25lGZd6WgUyqfeQYOkweotg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=W2Ox3+9h; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="W2Ox3+9h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1750680103; bh=bdUIv+Bi0JKFaMkv/B0ZJnFgDGfpNHDxCyP1lPlsIyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W2Ox3+9hw+zvS0lVzsElHJKlKH6Z+uPRTcHdyKlW4TKn9Vf/MS7hW+D2s9e9QCJud 3m6QG8LHw5EFWlRFsvDey+2HHFjHvo+rv6ESuemAzUCTLvL0+KWjUtuulVkBk6kATj wOr4oTUcfHRF/nYj0Lzu0WSaKrr620P+nAccI8125+1uciDQess3vIBJgAIRZSUMdK tByBqJ8VIJUdVKojcqpginxCEoDs7eFstg2+u9CzhgHHkaeLppUW+VLdCwli7AAhLr /HH8V2K6NX6yuZdP50Fr/V2Yv/xPhM6MAA7TN3n8FG198fiIwElHMeXyzc7Gvnw+rK GiwPNgrAshbvA== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id 4604817E1560; Mon, 23 Jun 2025 14:01:42 +0200 (CEST) From: AngeloGioacchino Del Regno To: robh@kernel.org Cc: krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, sudeep.holla@arm.com, cristian.marussi@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, arm-scmi@vger.kernel.org, kernel@collabora.com Subject: [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support Date: Mon, 23 Jun 2025 14:01:36 +0200 Message-ID: <20250623120136.109311-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250623120136.109311-1-angelogioacchino.delregno@collabora.com> References: <20250623120136.109311-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a driver for the SCMI protocol extensions for MediaTek TinySYS. This is used to communicate with various remote processors in some MediaTek SoCs, which mainly handle power management related tasks. Signed-off-by: AngeloGioacchino Del Regno --- drivers/firmware/arm_scmi/Kconfig | 1 + drivers/firmware/arm_scmi/Makefile | 1 + .../arm_scmi/vendors/mediatek/Kconfig | 16 + .../arm_scmi/vendors/mediatek/Makefile | 2 + .../arm_scmi/vendors/mediatek/mtk-tinysys.c | 344 ++++++++++++++++++ include/linux/scmi_mtk_protocol.h | 62 ++++ 6 files changed, 426 insertions(+) create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Kconfig create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Makefile create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c create mode 100644 include/linux/scmi_mtk_protocol.h diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/= Kconfig index e3fb36825978..baadf4f7fef6 100644 --- a/drivers/firmware/arm_scmi/Kconfig +++ b/drivers/firmware/arm_scmi/Kconfig @@ -84,6 +84,7 @@ config ARM_SCMI_QUIRKS =20 source "drivers/firmware/arm_scmi/transports/Kconfig" source "drivers/firmware/arm_scmi/vendors/imx/Kconfig" +source "drivers/firmware/arm_scmi/vendors/mediatek/Kconfig" =20 endif #ARM_SCMI_PROTOCOL =20 diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi= /Makefile index 780cd62b2f78..d1b4ec16b8bc 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -13,6 +13,7 @@ scmi-module-objs :=3D $(scmi-driver-y) $(scmi-protocols-y= ) $(scmi-transport-y) =20 obj-$(CONFIG_ARM_SCMI_PROTOCOL) +=3D transports/ obj-$(CONFIG_ARM_SCMI_PROTOCOL) +=3D vendors/imx/ +obj-$(CONFIG_ARM_SCMI_PROTOCOL) +=3D vendors/mediatek/ =20 obj-$(CONFIG_ARM_SCMI_PROTOCOL) +=3D scmi-core.o obj-$(CONFIG_ARM_SCMI_PROTOCOL) +=3D scmi-module.o diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig b/drivers/f= irmware/arm_scmi/vendors/mediatek/Kconfig new file mode 100644 index 000000000000..8facdcd3819f --- /dev/null +++ b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +menu "ARM SCMI MediaTek Vendor Protocols" + +config MTK_SCMI_TINYSYS + tristate "MediaTek SCMI TinySYS Extension" + depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) + default y if ARCH_MEDIATEK + help + This enables communication with the MediaTek TinySYS MCU + to control the power status of various SoC sub-devices + other than passing other messages for initialization. + + To compile this driver as a module, choose M here: the + module will be called mtk-tinysys. + +endmenu diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Makefile b/drivers/= firmware/arm_scmi/vendors/mediatek/Makefile new file mode 100644 index 000000000000..dc1ff63c3b69 --- /dev/null +++ b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MTK_SCMI_TINYSYS) +=3D mtk-tinysys.o diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c b/dri= vers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c new file mode 100644 index 000000000000..baeb36493952 --- /dev/null +++ b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c @@ -0,0 +1,344 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System Control and Management Interface (SCMI) MediaTek TinySYS Protocol + * + * Copyright (c) 2021 MediaTek Inc. + * Copyright (c) 2025 Collabora Ltd + * AngeloGioacchino Del Regno + */ + +#define pr_fmt(fmt) "SCMI Notifications TinySYS - " fmt + +#include +#include +#include +#include +#include +#include +#include + +#include "../../protocols.h" +#include "../../notify.h" + +#define SCMI_MTK_CMD_SSPM_QUERY_ALIVE 0xdead + +enum scmi_mtk_tinysys_protocol_cmd { + MTK_TINYSYS_COMMON_SET =3D 0x3, + MTK_TINYSYS_COMMON_GET =3D 0x4, + MTK_TINYSYS_POWER_STATE_NOTIFY =3D 0x5, + MTK_TINYSYS_SLBC_CTRL =3D 0x6, +}; + +struct scmi_mtk_tinysys_common_get_payld { + __le32 rsvd; + __le32 param[SCMI_MTK_MSG_COMMON_REPLY_BYTES]; +}; + +struct scmi_mtk_tinysys_common_set_payld { + __le32 rsvd; + __le32 ctrl_id; + __le32 param[SCMI_MTK_MSG_COMMON_PARAM_BYTES]; +}; + +struct scmi_mtk_tinysys_slbc_payld { + __le32 rsvd; + __le32 cmd; + __le32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES]; +}; + +struct scmi_mtk_tinysys_pwrst_notify { + __le32 rsvd; + __le32 fid; + __le32 enable; +}; + +struct scmi_mtk_tinysys_notify_payld { + __le32 fid; + __le32 param[SCMI_MTK_MSG_NOTIF_ST_BYTES]; +}; + +struct scmi_mtk_tinysys_protocol_attributes { + __le32 attributes; +}; + +struct scmi_mtk_tinysys_info { + int num_domains; +}; + +static int scmi_mtk_tinysys_attributes_get(const struct scmi_protocol_hand= le *ph, + struct scmi_mtk_tinysys_info *tinfo) +{ + struct scmi_mtk_tinysys_protocol_attributes *attr; + struct scmi_xfer *t; + int ret; + + ret =3D ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, sizeof(*attr)= , &t); + if (ret) + return ret; + + attr =3D t->rx.buf; + + ret =3D ph->xops->do_xfer(ph, t); + if (!ret) { + attr->attributes =3D get_unaligned_le32(t->rx.buf); + tinfo->num_domains =3D attr->attributes; + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_mtk_tinysys_get_num_sources(const struct scmi_protocol_han= dle *ph) +{ + struct scmi_mtk_tinysys_info *tinfo =3D ph->get_priv(ph); + + if (!tinfo) + return -EINVAL; + + return tinfo->num_domains; +} + +static int scmi_mtk_tinysys_set_notify_enabled(const struct scmi_protocol_= handle *ph, + u8 evt_id, u32 src_id, bool enable) +{ + struct scmi_mtk_tinysys_pwrst_notify *pwrst_notify; + struct scmi_xfer *t; + int ret; + + /* There's only one possible event for now */ + if (evt_id !=3D 0) + return -EINVAL; + + ret =3D ph->xops->xfer_get_init(ph, MTK_TINYSYS_POWER_STATE_NOTIFY, + sizeof(*pwrst_notify), 0, &t); + if (ret) + return ret; + + pwrst_notify =3D t->tx.buf; + pwrst_notify->fid =3D src_id; + pwrst_notify->enable =3D cpu_to_le32(enable); + + ret =3D ph->xops->do_xfer(ph, t); + ph->xops->xfer_put(ph, t); + return ret; +} + +static void *scmi_mtk_tinysys_fill_custom_report(const struct scmi_protoco= l_handle *ph, + u8 evt_id, ktime_t timestamp, + const void *payld, size_t payld_sz, + void *report, u32 *src_id) +{ + const struct scmi_mtk_tinysys_notify_payld *p =3D payld; + struct scmi_mtk_tinysys_notif_report *r =3D report; + int i; + + if (sizeof(*p) !=3D payld_sz) + return NULL; + + if (evt_id =3D=3D SCMI_EVENT_MTK_TINYSYS_NOTIFIER) { + r->timestamp =3D timestamp; + r->fid =3D le32_to_cpu(p->fid); + for (i =3D 0; i < SCMI_MTK_MSG_NOTIF_ST_BYTES; i++) + r->status[i] =3D le32_to_cpu(p->param[i]); + if (src_id) + *src_id =3D p->fid; + } else { + WARN_ON_ONCE(1); + return NULL; + } + + return r; +} + +static const struct scmi_event scmi_mtk_tinysys_events[] =3D { + { + .id =3D SCMI_EVENT_MTK_TINYSYS_NOTIFIER, + .max_payld_sz =3D sizeof(struct scmi_mtk_tinysys_notify_payld), + .max_report_sz =3D sizeof(struct scmi_mtk_tinysys_notif_report), + }, +}; + +static int scmi_mtk_tinysys_common_get(const struct scmi_protocol_handle *= ph, + u32 ctrl_id, u32 cmd, + struct scmi_mtk_tinysys_status *retval) +{ + struct scmi_mtk_tinysys_common_get_payld *p; + struct scmi_xfer *t; + int ret; + + ret =3D ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_GET, + sizeof(*p), sizeof(*retval), &t); + if (ret) + return ret; + + p =3D t->tx.buf; + p->param[0] =3D ctrl_id; + p->param[1] =3D cmd; + + ret =3D ph->xops->do_xfer(ph, t); + if (!ret) { + if (t->rx.len =3D=3D sizeof(*retval)) + memcpy(retval, t->rx.buf, sizeof(*retval)); + else + ret =3D -EINVAL; + } + + ph->xops->xfer_put(ph, t); + return ret; +} + +static int scmi_mtk_tinysys_common_set(const struct scmi_protocol_handle *= ph, + u32 ctrl_id, const u32 *params, + const u8 num_params) +{ + struct scmi_mtk_tinysys_common_set_payld *p; + struct scmi_xfer *t; + int i, ret; + + if (!params || num_params > SCMI_MTK_MSG_COMMON_PARAM_BYTES) + return -EINVAL; + + ret =3D ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_SET, sizeof(*p), 0= , &t); + if (ret) + return ret; + + p =3D t->tx.buf; + p->ctrl_id =3D cpu_to_le32(ctrl_id); + for (i =3D 0; i < num_params; i++) + p->param[i] =3D cpu_to_le32(params[i]); + + ret =3D ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + return ret; +} + +static int scmi_mtk_tinysys_cm_mgr_set(const struct scmi_protocol_handle *= ph, + u32 ctrl_id, u32 cmd, u32 arg) +{ + const u32 params[2] =3D { cmd, arg }; + + return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2); +} + +static int scmi_mtk_tinysys_gpu_pwr_set(const struct scmi_protocol_handle = *ph, + u32 ctrl_id, u8 pwr_indication, bool enable) +{ + const u32 params[2] =3D { pwr_indication, enable }; + + return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2); +} + +static int scmi_mtk_tinysys_slbc_req(const struct scmi_protocol_handle *ph, + const struct scmi_mtk_tinysys_slbc *req, + struct scmi_mtk_tinysys_slbc *retval) +{ + struct scmi_mtk_tinysys_slbc_payld *p; + struct scmi_xfer *t; + int i, ret; + + ret =3D ph->xops->xfer_get_init(ph, MTK_TINYSYS_SLBC_CTRL, + sizeof(*p), sizeof(*p), &t); + if (ret) + return ret; + + p =3D t->tx.buf; + p->cmd =3D cpu_to_le32(req->cmd); + for (i =3D 0; i < SCMI_MTK_MSG_SLBC_PARAM_BYTES; i++) + p->arg[i] =3D cpu_to_le32(req->arg[i]); + + ret =3D ph->xops->do_xfer(ph, t); + if (!ret && retval) { + if (t->rx.len =3D=3D sizeof(*retval)) + memcpy(retval, t->rx.buf, sizeof(*retval)); + else + ret =3D -EINVAL; + } + + ph->xops->xfer_put(ph, t); + return ret; +} + +static int scmi_mtk_tinysys_sspm_mem_set(const struct scmi_protocol_handle= *ph, + u32 ctrl_id, u32 pa, u32 mem_sz) +{ + const u32 params[2] =3D { pa, mem_sz }; + + if (mem_sz < SZ_1M) + return -EINVAL; + + return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2); +} + +static bool scmi_mtk_tinysys_sspm_is_alive(const struct scmi_protocol_hand= le *ph, + u32 ctrl_id) +{ + const u32 param =3D SCMI_MTK_CMD_SSPM_QUERY_ALIVE; + int ret; + + ret =3D scmi_mtk_tinysys_common_set(ph, ctrl_id, ¶m, 1); + + return ret ? false : true; +} + +static const struct scmi_mtk_tinysys_proto_ops mtk_tinysys_proto_ops =3D { + .common_get =3D scmi_mtk_tinysys_common_get, + .cm_mgr_set =3D scmi_mtk_tinysys_cm_mgr_set, + .gpu_pwr_set =3D scmi_mtk_tinysys_gpu_pwr_set, + .slbc_req =3D scmi_mtk_tinysys_slbc_req, + .sspm_is_alive =3D scmi_mtk_tinysys_sspm_is_alive, + .sspm_mem_set =3D scmi_mtk_tinysys_sspm_mem_set, +}; + +static const struct scmi_event_ops scmi_mtk_tinysys_event_ops =3D { + .get_num_sources =3D scmi_mtk_tinysys_get_num_sources, + .set_notify_enabled =3D scmi_mtk_tinysys_set_notify_enabled, + .fill_custom_report =3D scmi_mtk_tinysys_fill_custom_report, +}; + +static const struct scmi_protocol_events scmi_mtk_tinysys_protocol_events = =3D { + .queue_sz =3D 4 * SCMI_PROTO_QUEUE_SZ, + .ops =3D &scmi_mtk_tinysys_event_ops, + .evts =3D scmi_mtk_tinysys_events, + .num_events =3D ARRAY_SIZE(scmi_mtk_tinysys_events), +}; + +static int scmi_mtk_tinysys_protocol_init(const struct scmi_protocol_handl= e *ph) +{ + struct scmi_mtk_tinysys_info *tinfo; + u32 version; + int ret; + + ret =3D ph->xops->version_get(ph, &version); + if (ret) + return ret; + + dev_info(ph->dev, "MediaTek TinySYS Protocol Version %d.%d\n", + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); + + tinfo =3D devm_kzalloc(ph->dev, sizeof(*tinfo), GFP_KERNEL); + if (!tinfo) + return -ENOMEM; + + ret =3D scmi_mtk_tinysys_attributes_get(ph, tinfo); + if (ret) + return ret; + + return ph->set_priv(ph, tinfo, version); +} + +static const struct scmi_protocol scmi_mtk_tinysys =3D { + .id =3D SCMI_PROTOCOL_MTK_TINYSYS, + .owner =3D THIS_MODULE, + .instance_init =3D &scmi_mtk_tinysys_protocol_init, + .ops =3D &mtk_tinysys_proto_ops, + .events =3D &scmi_mtk_tinysys_protocol_events, + .vendor_id =3D SCMI_MTK_VENDOR, +}; +module_scmi_protocol(scmi_mtk_tinysys); + +MODULE_AUTHOR("AngeloGioacchino Del Regno "); +MODULE_ALIAS("scmi-protocol-" __stringify(SCMI_PROTOCOL_MTK_TINYSYS) "-" S= CMI_MTK_VENDOR); +MODULE_DESCRIPTION("MediaTek SCMI TinySYS driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/scmi_mtk_protocol.h b/include/linux/scmi_mtk_pro= tocol.h new file mode 100644 index 000000000000..51ad0cb4b72d --- /dev/null +++ b/include/linux/scmi_mtk_protocol.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * SCMI Message Protocol driver MediaTek extension header + * + * Copyright (c) 2021 MediaTek Inc. + * Copyright (c) 2025 Collabora Ltd + * AngeloGioacchino Del Regno + */ + +#ifndef _LINUX_SCMI_MTK_PROTOCOL_H +#define _LINUX_SCMI_MTK_PROTOCOL_H + +#include +#include +#include +#include + +#define SCMI_PROTOCOL_MTK_TINYSYS 0x80 +#define SCMI_MTK_VENDOR "MediaTek" + +#define SCMI_MTK_MSG_COMMON_PARAM_BYTES 5 +#define SCMI_MTK_MSG_COMMON_REPLY_BYTES 2 +#define SCMI_MTK_MSG_NOTIF_ST_BYTES 4 +#define SCMI_MTK_MSG_SLBC_PARAM_BYTES 4 + +struct scmi_mtk_tinysys_status { + u32 rsvd; + u32 reply[SCMI_MTK_MSG_COMMON_REPLY_BYTES]; +}; + +struct scmi_mtk_tinysys_slbc { + u32 cmd; + u32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES]; +}; + +struct scmi_mtk_tinysys_proto_ops { + int (*common_get)(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 cmd, + struct scmi_mtk_tinysys_status *retval); + int (*cm_mgr_set)(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 cmd, u32 arg); + int (*gpu_pwr_set)(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u8 pwr_indication, bool enable); + int (*slbc_req)(const struct scmi_protocol_handle *ph, + const struct scmi_mtk_tinysys_slbc *req, + struct scmi_mtk_tinysys_slbc *retval); + bool (*sspm_is_alive)(const struct scmi_protocol_handle *ph, + u32 ctrl_id); + int (*sspm_mem_set)(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 pa, u32 mem_sz); +}; + +enum scmi_mtk_tinysys_notification_events { + SCMI_EVENT_MTK_TINYSYS_NOTIFIER =3D 0x0, +}; + +struct scmi_mtk_tinysys_notif_report { + ktime_t timestamp; + unsigned int fid; + unsigned int status[SCMI_MTK_MSG_NOTIF_ST_BYTES]; +}; +#endif --=20 2.49.0