From patchwork Fri Dec 6 21:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 848000 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 9754B213E73; Fri, 6 Dec 2024 21:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733519789; cv=none; b=qodJOUi3aQShORIXv9LJsc/z8gHdQiankfOqt0EOLwLQlO960ywiOBR0hMFTEyhD6F8uMS02dPfKeJ6w2YRdDpgBY1e5S15a0PVjX4+XyFSwCoL3SfguvWR1eP3HLdERB7bsPCr3JAoxj80IVC6qXaBG3iLg/9ADxAansgORuSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733519789; c=relaxed/simple; bh=zOmh9qAGwU6c3133KkRN8o4kWKNoEwXt1SHwu/dxEBc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NWvQvSX/cJWodJXnGNt6Nly6BRlvOZrukg8rlnhjP7uKPIybUaP+ax7aruZ57NJ+gtgmv7KjeWE0FjnbGDP93do2jQLsnsEq4iMWerO23AQqlU1Mwxy9K6pGTUF9Niecn8EBLxKSqUhbfDO8xsPL5YiPRq4m3C9Ap2OnzX+rxCQ= 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=cLozwkjv; arc=none smtp.client-ip=209.85.128.53 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="cLozwkjv" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-434ab114753so17105805e9.0; Fri, 06 Dec 2024 13:16:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733519786; x=1734124586; 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=nRW+iOVyps5/7zvlNQKW1GtyxDHbc6Ru5QmYKpc6JyI=; b=cLozwkjvvDJ0fO7v9FQP3904H3OH2IC8QJys1MabluRDMnD0LkJTdJqVvoKRvaeyY3 69I1P98b3MXEqmwqULcxVaUaRwzTXeLGAZhkk4XxZqJrPphXIQITXF5e+KDt1LG/WBaw crV/tX1jGlMkLw5j3n6We4Ympcq0Qm5wuivSOnJJSeYZueMD9CSwUlz/68iAqlt3MKWF Kf4EaXOncgleq/XhU4diArk5XWNamrqR48KH3w3GdaaZIFd/jHgrbMVv0KvTSqn0pyTb 8ER9PHN2lmrXJaeJwgt9dLcSftC7qxCgLQdrbO0pX4DMGo3OCmqlXD9J6hSbqyzZStQi C6Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733519786; x=1734124586; 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=nRW+iOVyps5/7zvlNQKW1GtyxDHbc6Ru5QmYKpc6JyI=; b=UIp8sp+g7ldfc89B4pwMK5s5eXicKEYU4zqKzpcoRnI5kl40sMPceMNvtR8K+BHpcN rSbIucdMqn7FKkM5938jQEwHGWqsFplsTABWK0aRo3+Ff4eeN3eOc6kDuP5j3IJRYEpN +aEXSrFUVKLyF0BXo/ddjZc2mkjWxKtbQQqJae9xOQOaHV9JPGMeP3PZyZFOKTnzHfgn pjxxV0OgPnnQFMjiRUaKDtbk20T0wanAYE2xD1KlgCJJUWV234csGhRUS2dvKCqCvIhO oTzsMqaN98vW/o7YazGdzjcsCtvHdu6nkYsH48QJKW+T3sNJREjMbL2JjQMJGIElZtm5 PGzg== X-Forwarded-Encrypted: i=1; AJvYcCVSOjYOUdFTOw5NwtVgjBa3RJNQasuMCG2nqfKUzZAXG2kI9svMC7URLusnyFBdDL6G0hwTIHjxL58I@vger.kernel.org, AJvYcCWo/gWOPSniUPSlsQZW68q+pgAxpxX94OdzcMb6r/DDHFV05JknkhpE3yWemXsj2tEapC5ldJRDL7k=@vger.kernel.org, AJvYcCXZZsrqjzwvW2e2u84CwjOi8zMfQC26f6F/Ogt6/gzoRPqw0eDaJ3soIdAfus1/R/qLohcHwW0A3BLJDbKl@vger.kernel.org X-Gm-Message-State: AOJu0YxWu75om19ma4IQVpqs2zrYhFvQJ++VtKG3FzzE3ex6C4eHNW4z a41RQz3KJO9IhPJuQaTnqq7Gd5JJH+bhIcJ5X0rUJS3l25znVhXx X-Gm-Gg: ASbGncvkpyRM7I96YX+acBYIMCBimRpb5NqHkCcT09XBKphzzu8cIvobGI2ztVECFw1 jZKKyw1xCw/+6b+kNNpertBP60aAr+wz5YVwqYifVnhWGtZeH67AaMNwBdEBMlwsMyj+V6Ld7N2 8wStEW97y0FwHY/lXwvf9SefDudSeUqNmGcBSYbQIG6YnmwwxjDlnglC3iaVmO21a4T+XwB0FdG U7vxednMR69AtxRONgB18mXN4HftOeaYofhB1dOH5UGwtPbuVFrKQRPZBTrCdoWe7BhOcvrXHBU zOUPzZ+XZwN0D0oCotc= X-Google-Smtp-Source: AGHT+IEIKgSj99gQZ0yfIujLV4jW/0ASuy6eVEaAycAy7rwgJQxjyx7hj/onKqQL6rPYk6CO5v+K8g== X-Received: by 2002:a5d:5f8c:0:b0:385:e1eb:a7af with SMTP id ffacd0b85a97d-3862b3e7bd7mr2996674f8f.48.1733519785502; Fri, 06 Dec 2024 13:16:25 -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-434d526b375sm105978835e9.9.2024.12.06.13.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 13:16:24 -0800 (PST) From: Christian Marangi To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, upstream@airoha.com Cc: Ulf Hansson Subject: [PATCH v7 1/2] dt-bindings: cpufreq: Document support for Airoha EN7581 CPUFreq Date: Fri, 6 Dec 2024 22:11:24 +0100 Message-ID: <20241206211145.2823-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 On newer Airoha SoC, CPU Frequency is scaled indirectly with SMC commands to ATF. A virtual clock is exposed. This virtual clock is a get-only clock and is used to expose the current global CPU clock. The frequency info comes by the output of the SMC command that reports the clock in MHz. The SMC sets the CPU clock by providing an index, this is modelled as performance states in a power domain. CPUs can't be individually scaled as the CPU frequency is shared across all CPUs and is global. Signed-off-by: Christian Marangi Reviewed-by: Ulf Hansson Reviewed-by: Rob Herring (Arm) --- Changes v7: - Add more info to the description for usage of clock and performance-domain - Drop redundant nodes from example Changes v6: - No changes Changes v5: - Add Reviewed-by tag - Fix OPP node name error - Rename cpufreq node name to power-domain - Rename CPU node power domain name to perf - Add model and compatible to example Changes v4: - Add this patch .../cpufreq/airoha,en7581-cpufreq.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/cpufreq/airoha,en7581-cpufreq.yaml diff --git a/Documentation/devicetree/bindings/cpufreq/airoha,en7581-cpufreq.yaml b/Documentation/devicetree/bindings/cpufreq/airoha,en7581-cpufreq.yaml new file mode 100644 index 000000000000..7d4510b3219c --- /dev/null +++ b/Documentation/devicetree/bindings/cpufreq/airoha,en7581-cpufreq.yaml @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/cpufreq/airoha,en7581-cpufreq.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha EN7581 CPUFreq + +maintainers: + - Christian Marangi + +description: | + On newer Airoha SoC, CPU Frequency is scaled indirectly with SMC commands + to ATF. + + A virtual clock is exposed. This virtual clock is a get-only clock and + is used to expose the current global CPU clock. The frequency info comes + by the output of the SMC command that reports the clock in MHz. + + The SMC sets the CPU clock by providing an index, this is modelled as + performance states in a power domain. + + CPUs can't be individually scaled as the CPU frequency is shared across + all CPUs and is global. + +properties: + compatible: + const: airoha,en7581-cpufreq + + '#clock-cells': + const: 0 + + '#power-domain-cells': + const: 0 + + operating-points-v2: true + +required: + - compatible + - '#clock-cells' + - '#power-domain-cells' + - operating-points-v2 + +additionalProperties: false + +examples: + - | + performance-domain { + compatible = "airoha,en7581-cpufreq"; + + operating-points-v2 = <&cpu_smcc_opp_table>; + + #power-domain-cells = <0>; + #clock-cells = <0>; + }; From patchwork Fri Dec 6 21:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 848655 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 E8553213E76; Fri, 6 Dec 2024 21:16:28 +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=1733519791; cv=none; b=hbERyXMKr3G268dxXZKAVw4eKs2WvRoFHsvTT2m0xG848yvz7OMqWR7ktopRt7JrYDUHqhXCtOfx2ltyzfB5eyvvqyWtD9v7PyoVferQv3YCHHkFlqgnPhF2qS/aKm7A/nwwwA8bDS/XRbc+UkzmZgkU0iUj9mvE2UimgIdpyHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733519791; c=relaxed/simple; bh=9PVfdKsPXyNDi0Mvxj1Gxdbz/ENj+JiukpaSylX3siU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mk6WFCmKHBW92ipwRYG35eUI6xo/EmaOLLlVKl9wix2XtiWlnEBiKTRSM9dg0XAHy9wtXpfl0lIWQrTgNRFMw+6ue4QLMoKc1PdO9q/6Fzow7ohghIsMuUiLECssVVzgYoDezLRWTHXydcUGfZrbm16wV0nEsuVSUSa/lPxRy4A= 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=cCoQRExH; 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="cCoQRExH" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-434a766b475so24433295e9.1; Fri, 06 Dec 2024 13:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733519787; x=1734124587; 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=rQ774mXwgVeiYfbHPouQ8yLYPlEdURfb4mguZt/P8ag=; b=cCoQRExHykXqZ7i4uAB3mDablk+AqBCJTX5uM4gTJGVZlcWrI33G92H2M9QfPJz1un y90f1io4S8yHzUdq/i4rLy5QUy1gv5PyPWW3j8283zWDl86g/hlE1GkZdbVurF9KbymU CHUVFuy1wCx5rwo9bgD/z7AT0vNqPToR5Han3yVuFuoJ+qtO8nAL509nCAix5xlxsCJK 4h9bn6AREGLbhM6K+hDZWMedPKbzPDyoRusQFWM+qu1W8QtedKePsfqFOuM23A1iPjgq CG4288mPw5yMdc9AiFeTqal4yt45CSCm2BxPYHQrvCSLpncnFXeHlSg0UdgnzsebGGJ/ hvkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733519787; x=1734124587; 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=rQ774mXwgVeiYfbHPouQ8yLYPlEdURfb4mguZt/P8ag=; b=w0UNW4ZG1XSBzyKI3VNPi7mwK9IH+tpzwtwHET2Oj344C8TzOdunABL/AO4qqkieXH ojOS4EkjL5AlZNp/jC+gfIQmoekoi9/UjpDxVLZH36pxZKI/VaYTjuXxJXhuDyy3+ldp qp5lssBkmO6a6P7ZzxpU6CSPG7w4A9OSbrRQM8jUtL3OpQURc5tUL8Qqrib7GNkVVAjb RhuiCuJKW0UJkwwrBdmduuI1gFN59XjOOr09NdymwBXiGwrBQfebpJ6bMEpGKix7DnDa MDY8S0DXpAu6nnu8rCYafXPcwPh4rAqazyA3Rg9DhKtpcoDoAV++2/J/8d2uQwQJKBdT sLgQ== X-Forwarded-Encrypted: i=1; AJvYcCW6OYh7Cf8azC56FQqsjQm2p20iAP+HMzk+mm9ya+StBzk5L4puPQ3p6T2yZNcRtEKDi9m+KvToa20cHOpS@vger.kernel.org, AJvYcCWO1RshynjJN9+kKnMENt9XFQyos83JFWxiUVoRFT5yxBN58GUJqzkg8B0xvt3bY+uN9IPmDlF7qRc=@vger.kernel.org, AJvYcCWVhxSJB8kzrmzNX8P5m3EnprJ6ItfcViPE2T/ogf0ER2Kk2Ad6U0GmicF2eEv8Nnyirfe9WQ6Fkqlf@vger.kernel.org X-Gm-Message-State: AOJu0YxrheGqn3NlXRnBZf8HQ21HDBBt03u66BgBggEv/j6pzI9zqM82 prjfj/qrzpwLEE25cO0OZY1hypkEeWvSQwsBsjbZiAtp5LO9T5Gu X-Gm-Gg: ASbGncssPSEubCuhRuaiRBstBWUkNdSsnJ1f0zC8P+Xytr+KKUHGkYuLAdOTiTIEgpq m2s5lPS33sb36kK/nbMGI9tMM2qzSrh+IqxsE68iWMcG1K4zSOKT75txQjvSsi1ke6RBX/z0nIm wj9HnimnQ/ptREya8T8VZCJdt9sOgiADKl5YZUlGt19kCe5/W1ZRQFJ8VMztKCF8dCB4vDFIwHm 3HDrowAil1HL+Wn0pByZ66IwY4F3HdEj69mqNbh0m3VQBsIK+EKyPwCYsv9Ku9K0lcu2V8Qc+vs LKIWQfJqNtO5kBZ+FC4= X-Google-Smtp-Source: AGHT+IGdWphX24+lrmbxiZVvOlYYxPMx6dojKKbztDpyZcVKiSkKOm0bgTD4AsFnJ5uzz8hAmPtZaA== X-Received: by 2002:a05:600c:a41:b0:42c:b52b:4335 with SMTP id 5b1f17b1804b1-434ddeb43e6mr46736215e9.10.1733519786866; Fri, 06 Dec 2024 13:16:26 -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-434d526b375sm105978835e9.9.2024.12.06.13.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 13:16:26 -0800 (PST) From: Christian Marangi To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, upstream@airoha.com Subject: [PATCH v7 2/2] cpufreq: airoha: Add EN7581 CPUFreq SMCCC driver Date: Fri, 6 Dec 2024 22:11:25 +0100 Message-ID: <20241206211145.2823-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241206211145.2823-1-ansuelsmth@gmail.com> References: <20241206211145.2823-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. CPUFreq driver registers a get-only clock to get the current global CPU frequency from SMC and a Power Domain to configure the performance state for each OPP to apply the requested frequency from cpufreq-dt. This is needed as SMC use index instead of raw frequency. 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 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 | 10 ++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/airoha-cpufreq.c | 222 +++++++++++++++++++++++++++ drivers/cpufreq/cpufreq-dt-platdev.c | 2 + 4 files changed, 235 insertions(+) create mode 100644 drivers/cpufreq/airoha-cpufreq.c diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm index 5f7e13e60c80..8494faac58ae 100644 --- a/drivers/cpufreq/Kconfig.arm +++ b/drivers/cpufreq/Kconfig.arm @@ -15,6 +15,16 @@ 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 ARM64 && (ARCH_AIROHA || COMPILE_TEST) + select PM + select PM_OPP + select PM_GENERIC_DOMAINS + 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..29738f61f401 --- /dev/null +++ b/drivers/cpufreq/airoha-cpufreq.c @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#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_priv { + struct clk_hw hw; + struct generic_pm_domain pd; + + int opp_token; + struct dev_pm_domain_list *pd_list; + struct platform_device *cpufreq_dt; +}; + +static long airoha_cpufreq_clk_round(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + return rate; +} + +static unsigned long airoha_cpufreq_clk_get(struct clk_hw *hw, + unsigned long parent_rate) +{ + 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); + + /* SMCCC returns freq in MHz */ + return res.a0 * 1000 * 1000; +} + +/* Airoha CPU clk SMCC is always enabled */ +static int airoha_cpufreq_clk_is_enabled(struct clk_hw *hw) +{ + return true; +} + +static const struct clk_ops airoha_cpufreq_clk_ops = { + .recalc_rate = airoha_cpufreq_clk_get, + .is_enabled = airoha_cpufreq_clk_is_enabled, + .round_rate = airoha_cpufreq_clk_round, +}; + +static const char * const airoha_cpufreq_clk_names[] = { "cpu", NULL }; + +/* 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_pd_names[] = { "perf" }; + +static int airoha_cpufreq_set_performance_state(struct generic_pm_domain *domain, + unsigned int state) +{ + const struct arm_smccc_1_2_regs args = { + .a0 = AIROHA_SIP_AVS_HANDLE, + .a1 = AIROHA_AVS_OP_FREQ_DYN_ADJ, + .a3 = state, + }; + 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 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; + const struct clk_init_data init = { + .name = "cpu", + .ops = &airoha_cpufreq_clk_ops, + /* Clock with no set_rate, can't cache */ + .flags = CLK_GET_RATE_NOCACHE, + }; + struct generic_pm_domain *pd; + 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; + + /* 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 Cpufreq */ + pd = &priv->pd; + pd->name = "cpu_pd"; + pd->flags = GENPD_FLAG_ALWAYS_ON; + pd->set_performance_state = airoha_cpufreq_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; + + /* Set OPP table conf with NOP config_clks */ + priv->opp_token = dev_pm_opp_set_config(cpu_dev, &config); + if (priv->opp_token < 0) { + ret = priv->opp_token; + dev_err(dev, "Failed to set OPP config\n"); + goto err_set_config; + } + + /* Attach PM for OPP */ + ret = dev_pm_domain_attach_list(cpu_dev, &attach_data, + &priv->pd_list); + if (ret) + goto err_attach_pm; + + 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 err_register_cpufreq; + } + + priv->cpufreq_dt = cpufreq_dt; + platform_set_drvdata(pdev, priv); + + return 0; + +err_register_cpufreq: + dev_pm_domain_detach_list(priv->pd_list); +err_attach_pm: + dev_pm_opp_clear_config(priv->opp_token); +err_set_config: + of_genpd_del_provider(dev->of_node); +err_add_provider: + pm_genpd_remove(pd); + + 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); + + of_genpd_del_provider(pdev->dev.of_node); + pm_genpd_remove(&priv->pd); +} + +static const struct of_device_id airoha_cpufreq_of_match[] = { + { .compatible = "airoha,en7581-cpufreq" }, + { }, +}; +MODULE_DEVICE_TABLE(of, airoha_cpufreq_of_match); + +static struct platform_driver airoha_cpufreq_driver = { + .probe = airoha_cpufreq_probe, + .remove = airoha_cpufreq_remove, + .driver = { + .name = "airoha-cpufreq", + .of_match_table = airoha_cpufreq_of_match, + }, +}; +module_platform_driver(airoha_cpufreq_driver); + +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", },