From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.171.202.116 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795179473; b=ZMuhPl8QtkuF6JbEbBYaQ2536taVl2Glmax1A4PO0bdcst+bLhY1g7YIsBoyM/dFXycj WLZsxyAfBXRznggZSl2/qL7+SKHS+ukHIXBlpVtNMZzxaCrIF+c8mlNILIRnllL1Vgia7 USE7KxZiY42PjNCA3YIKGkmU/mFholciAdO+8+fc82DYW4XnqzI5F4QC+MZyODcup/4SO AD5q3/ft3rg01yKSghwGR5lsoiu63K9BqVUN3yhf8ZWB5k6arrYFqNTtYmUOCr5WM6EuJ agjTStntPmT4v5BAl50teE/xsUv45ZTlEdgNxnzc1qgtsGMMeBZHtLgMR91u+2lRgng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795179473; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=ZyG1HJB9CouJ88jrHvgbdE74CmzL9EWfbpLK4lLbZB8=; b=mSEGxYEmQHNRVF0O6zpI/uVtrO6h8l5OmEAbsr4zaiFrR24DXcNplk/p48ro4qI2OFuD xItzygd8Ss5o71fCR8F50YCDEF/Pj1TaJb7v0v8HNnkriEDiuyFRdKjOmIEjVvplplIPz tXtRxHoPfqT6A27OxLuk8Jy4Qc2mmB5M7Wu5EDNqOoNm8NzfClT4hvBGuMTImtYZgZUBY dZAqantqbyHdOrUgglMeuWZH8PTcoHdib+jDndOKwrazfPxpO9dozE3js7Uljfhhjvd+F MQ3DojmVauxYKTUTrDhVdlIgWURRByPXBxTMNvoFdtlwdZJlRkXxwbfnZuOwQEnKPZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=CIwpj3XN; arc=none smtp.remote-ip=185.171.202.116 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2C2560A260A for ; Fri, 20 Nov 2026 12:57:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A2C2560A260A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=CIwpj3XN Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 25E67C6221C; Fri, 20 Nov 2026 12:57:57 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7388A601B9; Fri, 20 Nov 2026 12:57:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 54E9211BC01AF; Fri, 20 Nov 2026 13:57:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1795179470; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ZyG1HJB9CouJ88jrHvgbdE74CmzL9EWfbpLK4lLbZB8=; b=CIwpj3XNGPVEq7IVMCfxfiYb0wfXVtbYAk7LTFhg1uGiNPczfzmjyDddimswPr9U/wH4ss Fs5+f/3LdbyXLDkfXHRw6gmUoLa4neaHD2mwVcKgxIYERAvILbd6o8PI+wWc84Ghjax9Y0 Le2FGDnbNK+riJ1rvzW7nhgBpRCfz1JYV1Bb0FdVqlgI9rLy9FT2XNrvxUM31iQ66aPYyl ZimLXdN708HBxTTuuyY+KIlHXDekR7R2xUX2wVdxfMto0C5rmh8Y8aEBAjZMoREU7XHadz f6eNDNc+MPs0ablm2dQmMffOI8MkCdQweByyM+IZC0/BX++R9fdEWRb7d0BOgQ== From: Paul Cercueil To: "Rafael J . Wysocki" , Len Brown , Russell King Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Thomas Petazzoni , Paul Cercueil Subject: [PATCH v4 2/2] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Date: Fri, 20 Nov 2026 13:57:22 +0100 Message-ID: <20261120125722.209609-3-paul.cercueil@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120125722.209609-1-paul.cercueil@bootlin.com> References: <20261120125722.209609-1-paul.cercueil@bootlin.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 ACPI 6.5 introduced a clock input resource descriptor, which allows to specify in the ACPI tables what clocks are connected to a given device. This patch adds support for the most basic clock resource, which is the one that represents a fixed clock. The new code will then create a clk_hw for each fixed clock resource, which is then made available to the device drivers, that can obtain it through a regular call to clk_get(NULL). Signed-off-by: Paul Cercueil --- v4: Change clock names to "acpi-clkX", because ACPI devices names can be up to 17 characters long, and our clock name must be 16 characters max. v3: No change v2: - Use the calculated clock name in devm_clk_hw_register_fixed_rate() instead of the device name - Make sure clkres->scale is <= 2. The field is 2 bits but the value clkres->scale == 3 is not defined in the spec. - Compute the fraction numerator using 64-bit math, to make sure it won't overflow on 32-bit systems. - Initialize clocks only when the device_type matches ACPI_BUS_TYPE_DEVICE. - Use a shorter name for clocks as the hard limit is 16 characters including the terminator. --- drivers/acpi/acpi_platform.c | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 80ea7121744d..4e8824cc042d 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -10,17 +10,27 @@ #include #include +#include +#include #include #include #include +#include #include +#include #include #include #include #include +#include #include "internal.h" +struct acpi_clk_data { + struct device *dev; + unsigned int idx; +}; + /* Exclude devices that have no _CRS resources provided */ #define ACPI_ALLOW_WO_RESOURCES BIT(0) @@ -130,6 +140,57 @@ static unsigned int acpi_platform_resource_count(struct acpi_resource *ares, voi return AE_CTRL_TERMINATE; } +static int acpi_add_fixed_clock(struct acpi_resource *res, void *d) +{ + static const unsigned long clk_scale[] = { 1, HZ_PER_KHZ, HZ_PER_MHZ }; + struct acpi_resource_clock_input *clkres; + struct acpi_clk_data *data = d; + struct device *dev = data->dev; + struct clk_hw *clk; + unsigned long rate; + char name[64]; + int err; + + if (res->type == ACPI_RESOURCE_TYPE_CLOCK_INPUT) { + clkres = &res->data.clock_input; + + if (clkres->mode) { + dev_warn(dev, "Only fixed rate clocks supported for now.\n"); + return 1; /* keep going */ + } + + if (clkres->frequency_divisor == 0 || clkres->scale > 2) + return -EINVAL; + + rate = DIV_ROUND_UP_ULL((u64)clkres->frequency_numerator * clk_scale[clkres->scale], + clkres->frequency_divisor); + + snprintf(name, sizeof(name), "acpi-clk%u", data->idx++); + + clk = devm_clk_hw_register_fixed_rate(dev, name, NULL, 0, rate); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + err = devm_clk_hw_register_clkdev(dev, clk, name, dev_name(dev)); + if (err) + return err; + } + + return 1; +} + +static void acpi_platform_init_clocks(struct acpi_device *adev) +{ + struct device *dev = &adev->dev; + struct acpi_clk_data data = { .dev = dev }; + LIST_HEAD(list); + int ret; + + ret = acpi_dev_get_resources(adev, &list, acpi_add_fixed_clock, &data); + if (ret < 0) + dev_err(dev, "Failed to add clock resources: %d\n", ret); +} + /** * acpi_create_platform_device - Create platform device for ACPI device node * @adev: ACPI device node to create a platform device for. @@ -196,6 +257,9 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, } acpi_dev_free_resource_list(&resource_list); } + + if (IS_ENABLED(CONFIG_COMMON_CLK)) + acpi_platform_init_clocks(adev); } memset(&pdevinfo, 0, sizeof(pdevinfo)); -- 2.47.3