From patchwork Mon Nov 25 15:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13885058 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 2771E14287; Mon, 25 Nov 2024 15:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732546955; cv=none; b=A41PlLzY6ay3gOUGWtbubTL53OtFfAn6l0i974KypB46GIL0UkZgQ8GCrmUyqlGEaZyKgKunRp97o279vmyne4txxKc4WnRNgo3FrYY4QkIeliVHwfCUPaIXG4gW1mw/DOHHhgqA4sWX5e/ao3xsRldkFAl1O1AGyz/z4ADAul0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732546955; c=relaxed/simple; bh=MnjGRpx8FxBhjgl32LYRi0TvQy40xQWy1JdDnv+E7gM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WC3BTycRprygLwx/PUhPc06p51648qbwQSN8OtxtToei1Q0VlZ4Mt7qN5rb7/MfphmzVaNkB6z4+hnTROrVH0/jRRWL4kr9MMNtAK7Jly0Xdxhj0Mvm+tR4744i3PJIDLtgwGd5xrLjlvL/c17lAeiHXFd8XaafVNkC1fy6d+dM= 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=bjh4HEUD; arc=none smtp.client-ip=209.85.128.54 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="bjh4HEUD" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4349fb56260so8780735e9.3; Mon, 25 Nov 2024 07:02:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732546952; x=1733151752; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fBjnAAKOnPVEcbgfRGCTKD0kvAkCekOYy37Z9H/L7YI=; b=bjh4HEUDd871JccR1tWyvRHLUtQX4zxKgofJe4lzcTial9Gc5WMKaBjAHiykVIBCop EfbHz1kzeeM10MyOl4nos1mrV/UW1QZtm0cK7T73RDBdpZRiywc5PmaisEPhHTnFUyPQ 7Z7bzbCH8MQ5sWNQf8F76pwNNfszb18bdcBjm7ccJxaI8iunzRp509noOSbdJcg4NrS6 UDo8WHvQ5Z6WfXlQWz6pCSuYuhbmPExpi9q25lUoskxvvSLXdRAq2Yh4JgGPlEmaRS7q qWgnugxps6NDT1RfvG28TKK8vkiF0Njjv583v7y5VCmmt+kxf+oWIScN3PXTUGpKY7ty CynA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732546952; x=1733151752; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fBjnAAKOnPVEcbgfRGCTKD0kvAkCekOYy37Z9H/L7YI=; b=VczxU863yOV8uEB48RdIPWefsI/K2SzgCigf+ZP/w0Pic6NCx/v4yDI1QWeVnLnnuO xH4sGgww/FcJkVO/zx6K6CXIuFwCFYYLkZYCxy9hZrklDSvSW9hNzPHThLZHw1DWPH/b iX2CGe6PYWebyl/fLSQbCNAGtr6se2CIgpT2pHYJ3JtOjMwkch5GinRvDf4jFGycQNb0 WgCaK5RfiKsRFrqNSEVdUzZfJwMKz0Dlbahns89uPSiqSbMsj31gNXO+d+6hBImZw5Oo YyMfbj4E6PGBDmHAroeS0MyWzs8QkBj1Zno2DgAmlNk8LI9MV1OAtjAkMrM7CtQN+zMV 3eNQ== X-Forwarded-Encrypted: i=1; AJvYcCVbpf0D0UV1O1DsZgg/Kd94dCVZhltw2Lp3GHnMxrFpoUW6EMjdJQhNldl6lBoewXBZgg2tVWEmgmY269U=@vger.kernel.org, AJvYcCVqd8QWYKTcu02qowq2ehW+OjTkSxrro5OoLY8ebDQ7yz4I8vEvhMFY4ooBmdZsxi7yhXqOCtXz7DI=@vger.kernel.org X-Gm-Message-State: AOJu0YwPWAJHrwuty7PGpE8JGrEk1crDwyga6w8DiOhqSb9A6fHIG5V3 wv/JiN7RriLpkl3P8GrfypthYwEGZZEPeGrDf5UzSYnRNhIWjdyrQQbwpg== X-Gm-Gg: ASbGncvw+J2WN4l7OipowETFZ/FBiSuN55Uhv7pgz5ZA/+gCuxaHix5KLYY58j/kw7W Nq9XMCsH+RhWE3zJLrnubu76JTBWKvPfm5yvT7G8wcmaD5tCZs5g1mwgJvcPX/RVvzXl7LMZ5nw pcDNRSd/FejxKhXHzT/bMFejkUhpnOqpTEKwqFQuEnUD94MnTpty3dlaRMXqcjoeLPrMstKgct8 Gn3H2Dp4gYBXdwkMuZ7VoJS5h4pOw7I2j3GX+AfRfMzbvN7pj5BvbKw+AmOff5uRShQAGKl/Jth 8zj53B1OTBMu+mcbtoU= X-Google-Smtp-Source: AGHT+IHNMhgxW0JgKvldg61TQqerCb2ctxjxGgb6t69VPnLsTzlEJ1BY8OeRiqp2gBNdF7DIDao/bQ== X-Received: by 2002:a05:6000:1449:b0:378:89d8:8242 with SMTP id ffacd0b85a97d-38260b763c5mr12134930f8f.26.1732546950282; Mon, 25 Nov 2024 07:02:30 -0800 (PST) Received: from localhost.localdomain (93-34-91-161.ip49.fastwebnet.it. [93.34.91.161]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43494a0ad65sm77776405e9.26.2024.11.25.07.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 07:02:29 -0800 (PST) From: Christian Marangi To: "Rafael J. Wysocki" , Viresh Kumar , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, upstream@airoha.com Cc: Christian Marangi Subject: [PATCH v3 1/2] cpufreq: dt: permit defining custom .get and .target_index Date: Mon, 25 Nov 2024 16:01:11 +0100 Message-ID: <20241125150200.714-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 Some modern device might have CPU frequency control totally detached from the system and entirely handled by ATF or Secure World. Such device also tune the CPU frequency indirectly with special call, like SMCCC calls. In such condition, creating a special clock for the task might introduce lots of unneeded overhead to permit usage of the generic "cpufreq-dt" driver. To handle this scenario, expand the "cpufreq-dt" driver to also permit defining custom .get and .target_index function. This is already supported for the .suspend, .resume and the .get_intermediate OPs. With this, custom CPU Freq driver can now define custom .get and .target_index and directly make SMCCC calls to tune the CPU frequency while keeping full support of all the property and initialization of "cpufreq-dt". It's also needed to introduce a bool to permit skipping CPU clock parsing (no_cpu_clk). This bool is applied only if a custom .get is defined and is needed to handle case when the CPU node doesn't have a clock defined as it's entirely handled indirectly and not exposed to the system. This permits full init of cpufreq-dt with custom .get() and .target_index(). Signed-off-by: Christian Marangi --- Changes v3: - Add this patch drivers/cpufreq/cpufreq-dt.c | 19 +++++++++++++++++-- drivers/cpufreq/cpufreq-dt.h | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 983443396f8f..ecbac6502b57 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -31,6 +31,7 @@ struct private_data { struct device *cpu_dev; struct cpufreq_frequency_table *freq_table; bool have_static_opps; + bool no_cpu_clk; int opp_token; }; @@ -90,7 +91,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) { struct private_data *priv; struct device *cpu_dev; - struct clk *cpu_clk; + struct clk *cpu_clk = NULL; unsigned int transition_latency; int ret; @@ -101,7 +102,13 @@ static int cpufreq_init(struct cpufreq_policy *policy) } cpu_dev = priv->cpu_dev; - cpu_clk = clk_get(cpu_dev, NULL); + /* + * CPU might have special clock handling (example handled by ATF with + * SMCCC calls). If instructed, skip checking for a CPU clock as it's + * handled by custom .get. + */ + if (!priv->no_cpu_clk) + cpu_clk = clk_get(cpu_dev, NULL); if (IS_ERR(cpu_clk)) { ret = PTR_ERR(cpu_clk); dev_err(cpu_dev, "%s: failed to get clk: %d\n", __func__, ret); @@ -175,6 +182,7 @@ static struct cpufreq_driver dt_cpufreq_driver = { static int dt_cpufreq_early_init(struct device *dev, int cpu) { + struct cpufreq_dt_platform_data *data = dev_get_platdata(dev); struct private_data *priv; struct device *cpu_dev; bool fallback = false; @@ -198,6 +206,9 @@ static int dt_cpufreq_early_init(struct device *dev, int cpu) cpumask_set_cpu(cpu, priv->cpus); priv->cpu_dev = cpu_dev; + /* Permit CPU with no clock, if custom .get is defined */ + if (data->get) + priv->no_cpu_clk = data->no_cpu_clk; /* * OPP layer will be taking care of regulators now, but it needs to know @@ -313,6 +324,10 @@ static int dt_cpufreq_probe(struct platform_device *pdev) if (data->have_governor_per_policy) dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY; + if (data->get) + dt_cpufreq_driver.get = data->get; + if (data->target_index) + dt_cpufreq_driver.target_index = data->target_index; dt_cpufreq_driver.resume = data->resume; if (data->suspend) dt_cpufreq_driver.suspend = data->suspend; diff --git a/drivers/cpufreq/cpufreq-dt.h b/drivers/cpufreq/cpufreq-dt.h index 28c8af7ec5ef..ba0385d75bdb 100644 --- a/drivers/cpufreq/cpufreq-dt.h +++ b/drivers/cpufreq/cpufreq-dt.h @@ -13,7 +13,11 @@ struct cpufreq_policy; struct cpufreq_dt_platform_data { bool have_governor_per_policy; + bool no_cpu_clk; + unsigned int (*get)(unsigned int cpu); + int (*target_index)(struct cpufreq_policy *policy, + unsigned int index); unsigned int (*get_intermediate)(struct cpufreq_policy *policy, unsigned int index); int (*target_intermediate)(struct cpufreq_policy *policy, From patchwork Mon Nov 25 15:01:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13885059 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 38B8C1B0F06; Mon, 25 Nov 2024 15:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732546970; cv=none; b=D+LYgygdcDokJDmvzNz4SzkTTLfZwis/zqmMq8fH31X1e2F4BjKLCdPwrB8Y34lURMPzz8W/bQeAhLQiXbrvCav4D2nJRl4g8O+Pfnd3FFjlplCtoRQ/yIN2YDkJYsheIY6CRM8OwNPfnB3GfkykuR1PzWvtGAxXKcE/dTIMsYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732546970; c=relaxed/simple; bh=+LM1rK7vah20uAIPBx8x5WKF8QEsH0r7kgg/8Vz0UYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AeftSjdxbYbKP/07E1h084W+ZFuppB3KKbaFy+n5oqagjxCxDHRnteIRgUCqb9suj9ni0IM4BsP47AfYhRbf2sD1Oi40LUhnyufzegplCjR6agrrxXjrz5bWvVaCMhVPNfH/QUE+XePFw1csSpWALPFNb2Xyf1LCufuOfDO6NCI= 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=CBF6mGkS; arc=none smtp.client-ip=209.85.128.47 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="CBF6mGkS" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4314f38d274so57547205e9.1; Mon, 25 Nov 2024 07:02:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732546966; x=1733151766; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YacDjwA3Pzwa/6jHmzMbauERh855QymnQOy/p7bYdAY=; b=CBF6mGkS+9JrTTzdvDE2XTwR8PKV9/9dU90jM1KF7TVL/ujyIR7I1FB//vXPjY4D6Q AGIXqsdt/NmfYJkmYISgSZkc2nrsM2T7zt349COm7SLStC19cHIzDsbQ9Uzd88/Z+RTs 6870BkFUIlwBMWIO1U6nUutmxMcaNvLi1lVFxs5XmGQaYIO24plfw5W9RCy8t7C73SWg 9Q5gX3Ht0n+kH9bAu9jsq+MEqQW2efZqREl7iV7pdEwRBRtx0XY1FlkeB8fETR3y04SH y+h3k9+FXsBjztXQMF14sjPNw/es5qwbS8+GQNiX4qhL08XjRWblIlLLE85GCyin35Ee cFcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732546966; x=1733151766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YacDjwA3Pzwa/6jHmzMbauERh855QymnQOy/p7bYdAY=; b=e8Itjuakw10kns/EO3BhHr9jrbtZ6Lj9knvyJSd3cnDdEvbW4ZglTvxHvOVqbvkzPr gQtnaYsKWHysa0Et/HhrDSURga2jkM2/UeFuyVs5dNkAL8VhUxExj09QSKFY4h0m19Ea AWNztkWLgiMgQUGJ76O0rQn5HaxX5vGvVEmKgXDAKl/GY5jUFvm4z/iFyG5Wn9OEZOBd TQO3MLMLW+brWsriDR5DxnfmYTHHjJSTmYaave0AjsST9THPDiPDVGQFZolaxa9aYXrB nwxDUG7CBuMUwD4hFHZTMd/yxgC5QCqXIX2zw4pMj9TGsg36aNpt+J89T625zlcppDQX BMbQ== X-Forwarded-Encrypted: i=1; AJvYcCUYU3SVuCCzyp0LzrNhkkBjjKfJ8Iyz2wT6XSqxf49R3N5drRI5qhnOfz0wY8hdNZS/nDyv2XRpvFTOEWQ=@vger.kernel.org, AJvYcCWGR5pLvx8s8VriSmwakZ1VptJBUDt4MW9dCALygxNHTuKTUjdxHZmAO7Hvfo1PUOoxFLGM0/2IDKg=@vger.kernel.org X-Gm-Message-State: AOJu0YywaVYLija7JMZMad7cmG3USVRXoGo/z4bNFgsFzgVgr6tilgLp zONbva5+FvU9mEUWFI76DU24QM5jDtJYkfPlOjU+0IrzmpR8UZaU X-Gm-Gg: ASbGnctFcJpYLeH+uDg1liPMwwpSwAIUXKtJlSMEmiT/xjF7fkYh/+tC3W7k2NripiC TnUahY2VG1knRRW9rakhICuaCiw6NUH8GrCYL8+KYHxF/hAtZHK4/itk3RQTNVbkXlXe1TwAdNG 2Wjys3Y6uBYXSawmL14HYm9/vGx5U2fRqCv+WjC0rcV8hF+mJCpk4eLfzoYda690aCf7GxhPfB7 QLeRvm3qECn9AmwHvOmhoycBkYM6knv8iySLEA/Y8yS71Z+XXZcF4foWyoOeyb03ePVz5AlIEML jWu7VcovzqGiwpal/xE= X-Google-Smtp-Source: AGHT+IGAW0t2ZrdBcqdUgNKM+2F6avTAZtGexAj6xXX8ALGw523Q2ou+1d0XnbHJldgeYgGhv/UGzQ== X-Received: by 2002:a05:600c:5250:b0:431:5465:8072 with SMTP id 5b1f17b1804b1-433ce4ae351mr156896005e9.31.1732546951164; Mon, 25 Nov 2024 07:02:31 -0800 (PST) Received: from localhost.localdomain (93-34-91-161.ip49.fastwebnet.it. [93.34.91.161]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43494a0ad65sm77776405e9.26.2024.11.25.07.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 07:02:30 -0800 (PST) From: Christian Marangi To: "Rafael J. Wysocki" , Viresh Kumar , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, upstream@airoha.com Cc: Christian Marangi Subject: [PATCH v3 2/2] cpufreq: airoha: Add EN7581 Cpufreq SMC driver Date: Mon, 25 Nov 2024 16:01:12 +0100 Message-ID: <20241125150200.714-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241125150200.714-1-ansuelsmth@gmail.com> References: <20241125150200.714-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. Current shared CPU frequency is returned by the related SMC command. 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 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 | 103 +++++++++++++++++++++++++++ drivers/cpufreq/cpufreq-dt-platdev.c | 2 + 4 files changed, 114 insertions(+) create mode 100644 drivers/cpufreq/airoha-cpufreq.c diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm index 5f7e13e60c80..338fc54276f2 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 && ARM64) + 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 0f184031dd12..8e5a37a95d36 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile @@ -52,6 +52,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..52d863a7363a --- /dev/null +++ b/drivers/cpufreq/airoha-cpufreq.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#include "cpufreq-dt.h" + +#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_cpufreq_state { + struct platform_device *cpufreq_dt; +}; + +static struct airoha_cpufreq_state *airoha_cpufreq_state; + +static unsigned int airoha_cpufreq_get(unsigned int cpu) +{ + const struct arm_smccc_1_2_regs args = { + .a0 = AIROHA_SIP_AVS_HANDLE, + .a1 = AIROHA_AVS_OP_GET_FREQ, + }; + struct arm_smccc_1_2_regs res; + + arm_smccc_1_2_smc(&args, &res); + + return (int)(res.a0 * 1000); +} + +static int airoha_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index) +{ + const struct arm_smccc_1_2_regs args = { + .a0 = AIROHA_SIP_AVS_HANDLE, + .a1 = AIROHA_AVS_OP_FREQ_DYN_ADJ, + .a3 = index, + }; + struct arm_smccc_1_2_regs res; + + arm_smccc_1_2_smc(&args, &res); + + /* SMC signal correct apply by unsetting BIT 0 */ + return res.a0 & BIT(0) ? -EINVAL : 0; +} + +static int __init airoha_cpufreq_driver_init(void) +{ + struct cpufreq_dt_platform_data pdata = { }; + struct platform_device *cpufreq_dt; + struct device *cpu_dev; + int ret; + + if (!of_machine_is_compatible("airoha,en7581")) + return -ENODEV; + + cpu_dev = get_cpu_device(0); + if (!cpu_dev) { + dev_err(cpu_dev, "Cannot get CPU\n"); + return -ENODEV; + } + + airoha_cpufreq_state = kzalloc(sizeof(*airoha_cpufreq_state), GFP_KERNEL); + if (!airoha_cpufreq_state) + return -ENOMEM; + + pdata.no_cpu_clk = true; + pdata.target_index = airoha_cpufreq_set_target; + pdata.get = airoha_cpufreq_get; + + cpufreq_dt = platform_device_register_data(NULL, "cpufreq-dt", -1, &pdata, + sizeof(pdata)); + ret = PTR_ERR_OR_ZERO(cpufreq_dt); + if (ret) { + dev_err(cpu_dev, + "failed to create cpufreq-dt device: %d\n", ret); + kfree(airoha_cpufreq_state); + return ret; + } + + airoha_cpufreq_state->cpufreq_dt = cpufreq_dt; + + return 0; +} +late_initcall(airoha_cpufreq_driver_init); + +static void __exit airoha_cpufreq_driver_remove(void) +{ + platform_device_unregister(airoha_cpufreq_state->cpufreq_dt); + kfree(airoha_cpufreq_state); +} +module_exit(airoha_cpufreq_driver_remove); + +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 18942bfe9c95..5ecd8234bfac 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-h6", }, { .compatible = "allwinner,sun50i-h616", }, { .compatible = "allwinner,sun50i-h618", },