From patchwork Thu Jan 9 13:12:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13932510 X-Patchwork-Delegate: viresh.linux@gmail.com Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F0C2217F4A; Thu, 9 Jan 2025 13:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736428423; cv=none; b=j1Y6uf7Un03HaadtbNeT+u3rKAqgWzvhkLOWWXu9OLKvAqHajA+SZ8QFaDgBydQP9fAGwktwLo+dT4bCq4JRsOCM8IBHFBvUE/doZyV8HwIhl2pbg6a9Qt3W+MWNDnbXvHFTDEjtqP28owSWmFs/0QTmwCrE+JyxKe4ISwppWSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736428423; c=relaxed/simple; bh=X9fEQu1U/DATwj8d7JTI0Sb2r249lhohoCdKtFyFSMA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IrqAkbshZrS0P+jCBGCfDpeH6CI0yTr81fZsMStF1KqfzEUmf1OKO/FIOA8lDWigGPWAz3H6ioQhrbmREUyFgyMc+70ALLhfwbgW8VU35BHl8Tu9n8gWeQIgV6rkrLqGExOFz9dH2gW9Pxskdg/U9aQBPHGcHBV7KGjiordRmVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PIi58Qwo; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PIi58Qwo" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-436637e8c8dso10296855e9.1; Thu, 09 Jan 2025 05:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736428420; x=1737033220; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=uRM5j6Ot4ZAazzuIZoxOMebBYpgaQOV63uO0HmRhKhU=; b=PIi58QwonuQdsfZmlzhWdhv9Lez5/UqfVOKk6JGHAQFRpYhXkVgrD6IV4R+Sarv5A4 uyCjElQ3GwbdacV+P8Zc2mCDLtDHiNBLlhWEj+6DhWJH9Gqy1xZ9b2cnSLkF/9mjFmFq yJ0TFLhi+QbFVnzJzEwj5WE+Fu/W182oAkktTzf1/J7RpFQWoFlT7NoQsuzIZhXnXZh/ hBJO8JooxvOD+djejf2w5WD9yTAmlOb87QjNmhUAo8uDPBYWhe2eKwBBXvQiO/SDo8+3 YJ/kA1cV9s2kdlOu1tDr5gtc+/tXL1U8yt+AMkKttvIs13gRuZfkJpZza7bxgmNq3vJn 5Wew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736428420; x=1737033220; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uRM5j6Ot4ZAazzuIZoxOMebBYpgaQOV63uO0HmRhKhU=; b=t6MA3RqpAAWfIDgEU0Mcl4g0bB9tCtJ1YEBbW+Rcg6jNkH05oodO5yh50YGiNYAww6 XQzld8/RBg94IQ1U149DQUDxya4Lb5O/qCGHJNecsI4y8YpPeVvnJJkuknv/2HU3QW3j JJdcr609GbBg0RvzX9Dr+ERXbkU7x4tGc7O08CydD/mrlG6RhDLDYIUFlzNQKlsglLlK fgrbg7psExO6895cTTpnZabUl2XrkNNsLbHusoXMPeMNM/Z3tEy+jVh/CTrRWiGO8+xh 3U+XHcCLQlZsG1UbBQ6/0nnvkynHuuXiC8h48ihuBZeXKQKNkjxIvMupL0WWHqyLM39H 9obw== X-Forwarded-Encrypted: i=1; AJvYcCVHYY09JP2A5Hz/MV/e/wkrTN666cKqGPvxmG9xAZMvO1vJpB3AS/1uDdQ3IWE3oErEsqjrK0ChnoI=@vger.kernel.org, AJvYcCXn5Cf6ekys+L0v4rzmopYPJcCb8IyPpGCQUWiaVxAYqEWrcyBHnM2uJPzAGSi+zil+69ve5igDsRK7SKc=@vger.kernel.org X-Gm-Message-State: AOJu0YxfMTpQFZCscXpVHCGasKm+HB6Pmm2iMxFUPMavpk1w6JF8JCOf NpSHY8UY41ZCqAzb3+/7PKM8iNGVF5sz1a7wN5tap7HOrld+h89w+8QWXg== X-Gm-Gg: ASbGncud5j6e+95gmhkr/Ij7u0KHF4Pl4q1daZ/dNyS3s5RcgZHqIKInRwC940mLXRh 8go1EwwP91hQ6qp8veMD6d7vQPnImNwwqf3z4Hp+mFANUidCF6eOEeNDB3wEmoel9H5OaeUtt5T TIzAqi4MsR/l3MzM5GIic2lQbIh3vIoWIuq6Mq+YKRGDksjv1+cvN7bwZUR2JQlaObKm9by6MS3 uh50XuRf/3e6IUFKgd2YZJcncGzaB5AF268UUx9H79q90MDn5k9U97vwzKPr75PHZtrx6MOnoy2 AfOzwP3+UDRb/CNAq7S6GZZTz4YFH08JPS9LrGpx/g== X-Google-Smtp-Source: AGHT+IGYsdHXDWGW+Q3wxecp7JvcILTEtygYfayS/lnRgUKCfBKAXrNMj5q72OGDlEgPzx8re1XYdQ== X-Received: by 2002:a05:600c:5112:b0:434:a386:6cf with SMTP id 5b1f17b1804b1-436e267f77amr60316635e9.2.1736428419286; Thu, 09 Jan 2025 05:13:39 -0800 (PST) Received: from localhost.localdomain (host-95-246-253-26.retail.telecomitalia.it. [95.246.253.26]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-38a8e385026sm1812286f8f.42.2025.01.09.05.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 05:13:38 -0800 (PST) From: Christian Marangi To: "Rafael J. Wysocki" , Viresh Kumar , Ulf Hansson , Matthias Brugger , AngeloGioacchino Del Regno , Christian Marangi , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, upstream@airoha.com Subject: [PATCH v10 1/2] pmdomain: airoha: Add Airoha CPU PM Domain support Date: Thu, 9 Jan 2025 14:12:57 +0100 Message-ID: <20250109131313.32317-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add Airoha CPU PM Domain support to control frequency and power of CPU present on Airoha EN7581 SoC. Frequency and power can be controlled with the use of the SMC command by passing the performance state. The driver also expose a read-only clock that expose the current CPU frequency with SMC command. Signed-off-by: Christian Marangi --- Changes v10: - Depends on HAVE_ARM_SMCCC Changes v9: - Fix compile error targetting wrong branch (remove_new change) Changes v8: - Add this patch - Use SMC invoke instead of 1.2 drivers/pmdomain/mediatek/Kconfig | 12 ++ drivers/pmdomain/mediatek/Makefile | 1 + .../pmdomain/mediatek/airoha-cpu-pmdomain.c | 144 ++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c diff --git a/drivers/pmdomain/mediatek/Kconfig b/drivers/pmdomain/mediatek/Kconfig index 21305c4f17fe..0e34a517ab7d 100644 --- a/drivers/pmdomain/mediatek/Kconfig +++ b/drivers/pmdomain/mediatek/Kconfig @@ -26,4 +26,16 @@ config MTK_SCPSYS_PM_DOMAINS Control Processor System (SCPSYS) has several power management related tasks in the system. +config AIROHA_CPU_PM_DOMAIN + tristate "Airoha CPU power domain" + default ARCH_AIROHA + depends on HAVE_ARM_SMCCC + depends on PM + select PM_GENERIC_DOMAINS + help + Say y here to enable CPU power domain support for Airoha SoC. + + CPU frequency and power is controlled by ATF with SMC command to + set performance states. + endmenu diff --git a/drivers/pmdomain/mediatek/Makefile b/drivers/pmdomain/mediatek/Makefile index 8cde09e654b3..0f6edce9239b 100644 --- a/drivers/pmdomain/mediatek/Makefile +++ b/drivers/pmdomain/mediatek/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o obj-$(CONFIG_MTK_SCPSYS_PM_DOMAINS) += mtk-pm-domains.o +obj-$(CONFIG_AIROHA_CPU_PM_DOMAIN) += airoha-cpu-pmdomain.o diff --git a/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c b/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c new file mode 100644 index 000000000000..0fd88d2f9ac2 --- /dev/null +++ b/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include + +#define AIROHA_SIP_AVS_HANDLE 0x82000301 +#define AIROHA_AVS_OP_BASE 0xddddddd0 +#define AIROHA_AVS_OP_MASK GENMASK(1, 0) +#define AIROHA_AVS_OP_FREQ_DYN_ADJ (AIROHA_AVS_OP_BASE | \ + FIELD_PREP(AIROHA_AVS_OP_MASK, 0x1)) +#define AIROHA_AVS_OP_GET_FREQ (AIROHA_AVS_OP_BASE | \ + FIELD_PREP(AIROHA_AVS_OP_MASK, 0x2)) + +struct airoha_cpu_pmdomain_priv { + struct clk_hw hw; + struct generic_pm_domain pd; +}; + +static long airoha_cpu_pmdomain_clk_round(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + return rate; +} + +static unsigned long airoha_cpu_pmdomain_clk_get(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_invoke(AIROHA_SIP_AVS_HANDLE, AIROHA_AVS_OP_GET_FREQ, + 0, 0, 0, 0, 0, 0, &res); + + /* SMCCC returns freq in MHz */ + return (int)(res.a0 * 1000 * 1000); +} + +/* Airoha CPU clk SMCC is always enabled */ +static int airoha_cpu_pmdomain_clk_is_enabled(struct clk_hw *hw) +{ + return true; +} + +static const struct clk_ops airoha_cpu_pmdomain_clk_ops = { + .recalc_rate = airoha_cpu_pmdomain_clk_get, + .is_enabled = airoha_cpu_pmdomain_clk_is_enabled, + .round_rate = airoha_cpu_pmdomain_clk_round, +}; + +static int airoha_cpu_pmdomain_set_performance_state(struct generic_pm_domain *domain, + unsigned int state) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_invoke(AIROHA_SIP_AVS_HANDLE, AIROHA_AVS_OP_FREQ_DYN_ADJ, + 0, state, 0, 0, 0, 0, &res); + + /* SMC signal correct apply by unsetting BIT 0 */ + return res.a0 & BIT(0) ? -EINVAL : 0; +} + +static int airoha_cpu_pmdomain_probe(struct platform_device *pdev) +{ + struct airoha_cpu_pmdomain_priv *priv; + struct device *dev = &pdev->dev; + const struct clk_init_data init = { + .name = "cpu", + .ops = &airoha_cpu_pmdomain_clk_ops, + /* Clock with no set_rate, can't cache */ + .flags = CLK_GET_RATE_NOCACHE, + }; + struct generic_pm_domain *pd; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + /* Init and register a get-only clk for Cpufreq */ + priv->hw.init = &init; + ret = devm_clk_hw_register(dev, &priv->hw); + if (ret) + return ret; + + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, + &priv->hw); + if (ret) + return ret; + + /* Init and register a PD for CPU */ + pd = &priv->pd; + pd->name = "cpu_pd"; + pd->flags = GENPD_FLAG_ALWAYS_ON; + pd->set_performance_state = airoha_cpu_pmdomain_set_performance_state; + + ret = pm_genpd_init(pd, NULL, false); + if (ret) + return ret; + + ret = of_genpd_add_provider_simple(dev->of_node, pd); + if (ret) + goto err_add_provider; + + platform_set_drvdata(pdev, priv); + + return 0; + +err_add_provider: + pm_genpd_remove(pd); + + return ret; +} + +static void airoha_cpu_pmdomain_remove(struct platform_device *pdev) +{ + struct airoha_cpu_pmdomain_priv *priv = platform_get_drvdata(pdev); + + of_genpd_del_provider(pdev->dev.of_node); + pm_genpd_remove(&priv->pd); +} + +static const struct of_device_id airoha_cpu_pmdomain_of_match[] = { + { .compatible = "airoha,en7581-cpufreq" }, + { }, +}; +MODULE_DEVICE_TABLE(of, airoha_cpu_pmdomain_of_match); + +static struct platform_driver airoha_cpu_pmdomain_driver = { + .probe = airoha_cpu_pmdomain_probe, + .remove = airoha_cpu_pmdomain_remove, + .driver = { + .name = "airoha-cpu-pmdomain", + .of_match_table = airoha_cpu_pmdomain_of_match, + }, +}; +module_platform_driver(airoha_cpu_pmdomain_driver); + +MODULE_AUTHOR("Christian Marangi "); +MODULE_DESCRIPTION("CPU PM domain driver for Airoha SoCs"); +MODULE_LICENSE("GPL"); From patchwork Thu Jan 9 13:12:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13932511 X-Patchwork-Delegate: viresh.linux@gmail.com Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B05BA2E; Thu, 9 Jan 2025 13:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736428424; cv=none; b=WhB1kLTO49+ZFlR+yPe4DS0O3hUwrmXNcFk3+/UQpashSqiYpSvEDcxtnbgXZ+jdypIZNvXBXGzdyQnD5ctPTgExUyt9PFNxhwdPtuawgGrFaNLhoRjz7RshWn6Rqp94+WgzbNxvppYE6qVnwItiCfyARRGh16GN41wPJU8YmG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736428424; c=relaxed/simple; bh=cY0IdA4avr/XmHZshF+96+n3p60epuelvtE/f+Gg9Qw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fGObIWn/GEvzzQV/mpypycRdtczH5vBBP/7rl6+g0xui0eofROcq7dzEcqlZqtwE1qg721LkdAKR3HmkGt79QrR6rXHlZMIhQQK8SSnV3dH1wDN3TWys3pWzdK/DuaTAYhajVGXziwnK/lDXRPPGLp8qS9dng/vTMtJSW0VyYgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UiidcQdH; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UiidcQdH" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-385f07cd1a4so593993f8f.1; Thu, 09 Jan 2025 05:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736428421; x=1737033221; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jkN0Zbqriw5PzthPVlNgEaF6B8Bg927+i+ccWjtK+W4=; b=UiidcQdHhVL4m3Z3oJZUuqL+XRQowdqbYMa7/2vJJpgA04WhrrLLDeGuoOGkKwhLFY DWn1dv2s3r0lYNGIDdSxIL4JGkPV+gWbDmeL0bRESkHT6O0a7prG2bm013KhWyo6t7e/ QwfBj8hQN9tvDbBbZuCNvwsgCo5BwootY+/b3LWA0mxi7ZHbPxUE5tvFeiVDCriCAtU9 Xa9wJiQq1dX977TlcEpBVP/fdyRJ8R4s0NME7r2X1JDXy8Ff6/ifcED8KBV6XHyUrbec kWgPnFDDUgEteqIl+KHbmsAjqw9lVmqAmMGefvLU0Yem/nWkDn9+Ma5db1t7oy63CCwf 9slw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736428421; x=1737033221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jkN0Zbqriw5PzthPVlNgEaF6B8Bg927+i+ccWjtK+W4=; b=PZm8mNCFUKUfcB/UWWHoVLKt/OPuhxcgumnaGP79e2GzWsN1ib/TvAj343dmD77ump BEu/iZJcJ3SUmGfeXBfu6YmLvSGxmm+Gj3AXDR8nmRgXfo1mH89m5yDxs+QnPvzFDBUs rQAoF39cBwC9HTrjjkIzji85+0a2yxAjMXt3a5lXlU1o0Jpflo2Wz1U675qc2AkyF6qn Fz1RWflXGZ7gC82TFFfvCib7Q1luUdO2ESS1vMC/H8DUVbATTNH4VLBgwHvA4tlf4XWt o/x6gBqLJpGZQACl3eYjpCqgfNFlTvyz0Nm4BOMaA8rTv52qO06OaWGczy0BuVMrC+2C r7LQ== X-Forwarded-Encrypted: i=1; AJvYcCVd8UxZvkorf2i6stDCbksRQf/Ne+INQ0fp1h289L0wJMlWPHbW6NSNXuMbb9EcYY7dfk2Va3bENW3NkJ0=@vger.kernel.org, AJvYcCXi0i7ol7+rfL2prwx61thLyLpE60jpW8IYkDGSA3H/A2FPHqtDaRZwoL5w0oPg7NwmzgNdYmTxZSk=@vger.kernel.org X-Gm-Message-State: AOJu0Yyl96FY5w6zgx/u/Xr7sFWL+hXs4M+y2ztvXAt0GNGj6SKEEE/9 4A56TVTD6Ape46cfXAyUnlEtuC0TxJ5kqJ+vGqHH3lsGvvs+QdPJ X-Gm-Gg: ASbGncvEfPIbR9Qcnfl0o4PuQJ3jp6Mib9Oe1M6d20k1nAqXBDDSxrjnzhYA7r+aO6x ZdLYqbwCG4+O8R58dwMPnkyHmEhFu+3TjLL+n6G2WgXg/7sfok/QojfcELZQjtWSRG0T9XuYZ3A lt8ywkMd0Arf5IqEb5uJ/f34e6cC9/aLZg2M+p8U2XZrotnKtGTIfqh6JidxXgBY2i5j8WXl45Q jYFRXFu8x0WX3kSmroWc2EtgVOiO/wBf/7lYgPj0TvZVoOnAv80bygqdtoZDDtGpC5seKbrPs+R gpTaTWJgGpucx7/fHqurRZXkzD+1v2KentLY5tTKTw== X-Google-Smtp-Source: AGHT+IG5cCytUXF99jwAAoz8fgNKe08AHoWKQCCBRKl1wIMKmBm470WFU6Boe0ZshyUraZJN3IFmMw== X-Received: by 2002:a5d:47c9:0:b0:385:f470:c2c6 with SMTP id ffacd0b85a97d-38a872fad4fmr5657737f8f.11.1736428420644; Thu, 09 Jan 2025 05:13:40 -0800 (PST) Received: from localhost.localdomain (host-95-246-253-26.retail.telecomitalia.it. [95.246.253.26]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-38a8e385026sm1812286f8f.42.2025.01.09.05.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 05:13:40 -0800 (PST) From: Christian Marangi To: "Rafael J. Wysocki" , Viresh Kumar , Ulf Hansson , Matthias Brugger , AngeloGioacchino Del Regno , Christian Marangi , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, upstream@airoha.com Subject: [PATCH v10 2/2] cpufreq: airoha: Add EN7581 CPUFreq SMCCC driver Date: Thu, 9 Jan 2025 14:12:58 +0100 Message-ID: <20250109131313.32317-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250109131313.32317-1-ansuelsmth@gmail.com> References: <20250109131313.32317-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add simple CPU Freq driver for Airoha EN7581 SoC that control CPU frequency scaling with SMC APIs and register a generic "cpufreq-dt" device. All CPU share the same frequency and can't be controlled independently. CPU frequency is controlled by the attached PM domain. Add SoC compatible to cpufreq-dt-plat block list as a dedicated cpufreq driver is needed with OPP v2 nodes declared in DTS. Signed-off-by: Christian Marangi --- Changes v9: - Fix compile error targetting wrong branch (remove_new change and new PM OPs) Changes v8: - Split in dedicated PM domain driver Changes v7: - No changes Changes v6: - Improve Kconfig depends logic - Select PM (PM_GENERIC_DOMAINS depends on it) - Drop (int) cast for Changes v5: - Rename cpu_pd to perf for power domain name - Use remove instead of remove_new Changes v4: - Rework to clk-only + PM set_performance_state implementation Changes v3: - Adapt to new cpufreq-dt APIs - Register cpufreq-dt instead of custom freq driver Changes v2: - Fix kernel bot error with missing slab.h and bitfield.h header - Limit COMPILE_TEST to ARM64 due to smcc 1.2 drivers/cpufreq/Kconfig.arm | 8 ++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/airoha-cpufreq.c | 152 +++++++++++++++++++++++++++ drivers/cpufreq/cpufreq-dt-platdev.c | 2 + 4 files changed, 163 insertions(+) create mode 100644 drivers/cpufreq/airoha-cpufreq.c diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm index 5f7e13e60c80..704e84d00639 100644 --- a/drivers/cpufreq/Kconfig.arm +++ b/drivers/cpufreq/Kconfig.arm @@ -15,6 +15,14 @@ config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM To compile this driver as a module, choose M here: the module will be called sun50i-cpufreq-nvmem. +config ARM_AIROHA_SOC_CPUFREQ + tristate "Airoha EN7581 SoC CPUFreq support" + depends on ARCH_AIROHA || COMPILE_TEST + select PM_OPP + default ARCH_AIROHA + help + This adds the CPUFreq driver for Airoha EN7581 SoCs. + config ARM_APPLE_SOC_CPUFREQ tristate "Apple Silicon SoC CPUFreq support" depends on ARCH_APPLE || (COMPILE_TEST && 64BIT) diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index d35a28dd9463..890fff99f37d 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_X86_AMD_FREQ_SENSITIVITY) += amd_freq_sensitivity.o ################################################################################## # ARM SoC drivers +obj-$(CONFIG_ARM_AIROHA_SOC_CPUFREQ) += airoha-cpufreq.o obj-$(CONFIG_ARM_APPLE_SOC_CPUFREQ) += apple-soc-cpufreq.o obj-$(CONFIG_ARM_ARMADA_37XX_CPUFREQ) += armada-37xx-cpufreq.o obj-$(CONFIG_ARM_ARMADA_8K_CPUFREQ) += armada-8k-cpufreq.o diff --git a/drivers/cpufreq/airoha-cpufreq.c b/drivers/cpufreq/airoha-cpufreq.c new file mode 100644 index 000000000000..4fe39eadd163 --- /dev/null +++ b/drivers/cpufreq/airoha-cpufreq.c @@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include + +#include "cpufreq-dt.h" + +struct airoha_cpufreq_priv { + int opp_token; + struct dev_pm_domain_list *pd_list; + struct platform_device *cpufreq_dt; +}; + +static struct platform_device *cpufreq_pdev; + +/* NOP function to disable OPP from setting clock */ +static int airoha_cpufreq_config_clks_nop(struct device *dev, + struct opp_table *opp_table, + struct dev_pm_opp *opp, + void *data, bool scaling_down) +{ + return 0; +} + +static const char * const airoha_cpufreq_clk_names[] = { "cpu", NULL }; +static const char * const airoha_cpufreq_pd_names[] = { "perf" }; + +static int airoha_cpufreq_probe(struct platform_device *pdev) +{ + const struct dev_pm_domain_attach_data attach_data = { + .pd_names = airoha_cpufreq_pd_names, + .num_pd_names = ARRAY_SIZE(airoha_cpufreq_pd_names), + .pd_flags = PD_FLAG_DEV_LINK_ON | PD_FLAG_REQUIRED_OPP, + }; + struct dev_pm_opp_config config = { + .clk_names = airoha_cpufreq_clk_names, + .config_clks = airoha_cpufreq_config_clks_nop, + }; + struct platform_device *cpufreq_dt; + struct airoha_cpufreq_priv *priv; + struct device *dev = &pdev->dev; + struct device *cpu_dev; + int ret; + + /* CPUs refer to the same OPP table */ + cpu_dev = get_cpu_device(0); + if (!cpu_dev) + return -ENODEV; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + /* Set OPP table conf with NOP config_clks */ + priv->opp_token = dev_pm_opp_set_config(cpu_dev, &config); + if (priv->opp_token < 0) + return dev_err_probe(dev, priv->opp_token, "Failed to set OPP config\n"); + + /* Attach PM for OPP */ + ret = dev_pm_domain_attach_list(cpu_dev, &attach_data, + &priv->pd_list); + if (ret) + goto clear_opp_config; + + cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0); + ret = PTR_ERR_OR_ZERO(cpufreq_dt); + if (ret) { + dev_err(dev, "failed to create cpufreq-dt device: %d\n", ret); + goto detach_pm; + } + + priv->cpufreq_dt = cpufreq_dt; + platform_set_drvdata(pdev, priv); + + return 0; + +detach_pm: + dev_pm_domain_detach_list(priv->pd_list); +clear_opp_config: + dev_pm_opp_clear_config(priv->opp_token); + + return ret; +} + +static void airoha_cpufreq_remove(struct platform_device *pdev) +{ + struct airoha_cpufreq_priv *priv = platform_get_drvdata(pdev); + + platform_device_unregister(priv->cpufreq_dt); + + dev_pm_domain_detach_list(priv->pd_list); + + dev_pm_opp_clear_config(priv->opp_token); +} + +static struct platform_driver airoha_cpufreq_driver = { + .probe = airoha_cpufreq_probe, + .remove = airoha_cpufreq_remove, + .driver = { + .name = "airoha-cpufreq", + }, +}; + +static const struct of_device_id airoha_cpufreq_match_list[] __initconst = { + { .compatible = "airoha,en7581" }, + {}, +}; +MODULE_DEVICE_TABLE(of, airoha_cpufreq_match_list); + +static int __init airoha_cpufreq_init(void) +{ + struct device_node *np = of_find_node_by_path("/"); + const struct of_device_id *match; + int ret; + + if (!np) + return -ENODEV; + + match = of_match_node(airoha_cpufreq_match_list, np); + of_node_put(np); + if (!match) + return -ENODEV; + + ret = platform_driver_register(&airoha_cpufreq_driver); + if (unlikely(ret < 0)) + return ret; + + cpufreq_pdev = platform_device_register_data(NULL, "airoha-cpufreq", + -1, match, sizeof(*match)); + ret = PTR_ERR_OR_ZERO(cpufreq_pdev); + if (ret) + platform_driver_unregister(&airoha_cpufreq_driver); + + return ret; +} +module_init(airoha_cpufreq_init); + +static void __exit airoha_cpufreq_exit(void) +{ + platform_device_unregister(cpufreq_pdev); + platform_driver_unregister(&airoha_cpufreq_driver); +} +module_exit(airoha_cpufreq_exit); + +MODULE_AUTHOR("Christian Marangi "); +MODULE_DESCRIPTION("CPUfreq driver for Airoha SoCs"); +MODULE_LICENSE("GPL"); diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c b/drivers/cpufreq/cpufreq-dt-platdev.c index 9c198bd4f7e9..2aa00769cf09 100644 --- a/drivers/cpufreq/cpufreq-dt-platdev.c +++ b/drivers/cpufreq/cpufreq-dt-platdev.c @@ -103,6 +103,8 @@ static const struct of_device_id allowlist[] __initconst = { * platforms using "operating-points-v2" property. */ static const struct of_device_id blocklist[] __initconst = { + { .compatible = "airoha,en7581", }, + { .compatible = "allwinner,sun50i-a100" }, { .compatible = "allwinner,sun50i-h6", }, { .compatible = "allwinner,sun50i-h616", },