Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1815078lqm; Fri, 3 May 2024 07:21:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW52A3hyjJnVptUH1dhAgUWmAE/dQzenVn4pn+ynXCmnb/JqiZXnCBXCLb8+f1pwbWTewAUIQhSOR44aFpifVWj87THSP+lyadkhtqz8A== X-Google-Smtp-Source: AGHT+IEcO0y/4zYpgK05bIVPM6ar64mRvQyOd7OAgVEpWDvCoxMqdVXVNBS6wjn0AcSWfZVPf0j1 X-Received: by 2002:ac8:5a83:0:b0:43a:f1c7:4491 with SMTP id c3-20020ac85a83000000b0043af1c74491mr2867200qtc.61.1714746105356; Fri, 03 May 2024 07:21:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714746105; cv=pass; d=google.com; s=arc-20160816; b=Y5ilGi9AnUvKfwNWqOfAJwXwd1Q7ANP4RHoSwh9DKfzn3ChEjyuB88EqQ/IpU4cNFT NPpxgSJklCh4xQBZQTi2sm/GqnXTxE7x1eZCGX70zdVQcopRDBJsrv0cwzMPo/MFDiGZ 7Q+b95mROpkAiqbDmLPjo/CAlM1bkwyFtKIP7aDuf99lk4CB5UYkNX4lF3DCmdpc7KuN AN+G0ShXY157bun0oHt0lUfqhtyI0V7nbkZCyMpPPmXQJs7ITl8kdH+WRWuHSbXDGVA/ 642iCWNJeywUIHerXur7Hfiuw8+HlvszXD39521q5EsosBiwqXhNlwWPWBRi/u8k3FMm fXzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=0CmhYS38FoiHM21EItP7+1kMUZLrboLBpS562xGjpdM=; fh=FM+ryhC3zZYH/pBRXfFNqQ7rqZR5mg7STLNv34C2ANM=; b=avDbwf2p2dW9AVAaVSRFYqxI93hGgT+eS/e6eOQLvJDyHoS1s2BLO2D2IQdoXlR+Dd +ZOd2OEp4s/F9PR+qKOWj1hjE4w2cnwhPauSCP0n8LNDS8ECkxt6Ljs1eQP/3SQ/SmB2 BPaqBAyswDTw4jUkF2PGZUkdqj9X1NixrGlukPPOyZWQF/aMfrJl886KlVYszD0UVoKx kpfocYYaEJNwq+E+V6h3+3xm1XHzD1k+3AGJecg3oDqcPZSCRkgj9FHGfai9Jwv9tct6 vgBddZn7OQC9l2A970AHx7ZZ58PV08XBDWMipSipS28n8mevqg5r/qEvGP3aAAGeqqQc YRmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="TlYeUop/"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-167757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d4-20020ac85ac4000000b0043aab3d8a94si3532387qtd.415.2024.05.03.07.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 07:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="TlYeUop/"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-167757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F302A1C21682 for ; Fri, 3 May 2024 14:21:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0663E15532C; Fri, 3 May 2024 14:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="TlYeUop/" Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 6A986154BF1; Fri, 3 May 2024 14:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714746080; cv=none; b=dMyBqOT8ZMVxnzwfEgZDwoA4o6pEqpkuJ1ma369cGPmwCV73nWy7VTD1+W/kiauT+RNvkrbMHtFM7yc1jMfZssL7ua0v+tAs5ITERndJlj2agZEF3Taf0TH533w+85eyiptztZXyMbqMevaxgpSlz2jhuMacKmXtqMD3mb39ysE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714746080; c=relaxed/simple; bh=aPqTKe7d4WbI7QD4yTnf4tncjyKh5eeTinicI+o4iQE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FdLbTrb7cxxRFIQ/zzWwMRDnuNSwCumwzBDCSyMjXVeIjZG5q+A7Z2rZdv3V3eafxlhjkhWMJ/GpfJSOz10N0F3F0yL4/pW32kqtsUl3W0H1wQkQwNOWykDlxjkG5AUBcQ4DeQdAc8H8QzFOe8PNziNc6STeLvqS9LmWaVcj8jI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=TlYeUop/; arc=none smtp.client-ip=217.70.183.196 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 Received: by mail.gandi.net (Postfix) with ESMTPSA id D0FF8E000C; Fri, 3 May 2024 14:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1714746075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0CmhYS38FoiHM21EItP7+1kMUZLrboLBpS562xGjpdM=; b=TlYeUop/D26Wwi25qpQ4yhYXwqSEuNsVANHZGKT4my4vGC7jDA3sCFFedSehCrcJnhnSpl bz3aF90uTvhMFH3GBN3sbBUY4d7A5Xm62JTi9+DofOiHzBrpVIaSaNx7X8DVWfRSOabAqU yBzRncqpduNrxM//Sdj1O7JO3J4XKlRlVyN/KN6yEQa1E3YbJILU7zG05fgaRXjG61iliB 9LuBOASlsDnBcyJDEeAZGV/60ZxlmDukgQkG2tUhI3NLKddPMI/SyEqGVJGWUUgnNGO7If uDCIB7D/7B95zc98oGdjCAqtbZwAbfh2AgafUZiOeewl4qrM5xvsFvFeOKzYOA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 03 May 2024 16:20:52 +0200 Subject: [PATCH v2 07/11] clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240503-mbly-olb-v2-7-95ce5a1e18fe@bootlin.com> References: <20240503-mbly-olb-v2-0-95ce5a1e18fe@bootlin.com> In-Reply-To: <20240503-mbly-olb-v2-0-95ce5a1e18fe@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Turquette , Stephen Boyd , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , "Rafael J. Wysocki" , Lee Jones , Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, Vladimir Kondratiev , Gregory CLEMENT , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.13.0 X-GND-Sasl: theo.lebrun@bootlin.com Add CLK_DIVIDER_EVEN_INTEGERS flag to support divisor of 2, 4, 6, etc. The same divisor can be done using a table, which would be big and wasteful for a clock dividor of width 8 (256 entries). Require increasing flags size from u8 to u16 because CLK_DIVIDER_EVEN_INTEGERS is the eighth flag. Signed-off-by: Théo Lebrun --- drivers/clk/clk-divider.c | 12 +++++++++--- include/linux/clk-provider.h | 11 +++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index a2c2b5203b0a..b6654c5c36d2 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -72,6 +72,8 @@ static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width, return clk_div_mask(width); if (flags & CLK_DIVIDER_POWER_OF_TWO) return 1 << clk_div_mask(width); + if (flags & CLK_DIVIDER_EVEN_INTEGERS) + return 2 * (clk_div_mask(width) + 1); if (table) return _get_table_maxdiv(table, width); return clk_div_mask(width) + 1; @@ -97,6 +99,8 @@ static unsigned int _get_div(const struct clk_div_table *table, return 1 << val; if (flags & CLK_DIVIDER_MAX_AT_ZERO) return val ? val : clk_div_mask(width) + 1; + if (flags & CLK_DIVIDER_EVEN_INTEGERS) + return 2 * (val + 1); if (table) return _get_table_div(table, val); return val + 1; @@ -122,6 +126,8 @@ static unsigned int _get_val(const struct clk_div_table *table, return __ffs(div); if (flags & CLK_DIVIDER_MAX_AT_ZERO) return (div == clk_div_mask(width) + 1) ? 0 : div; + if (flags & CLK_DIVIDER_EVEN_INTEGERS) + return (div >> 1) - 1; if (table) return _get_table_val(table, div); return div - 1; @@ -538,7 +544,7 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev, struct device_node *np, const char *name, const char *parent_name, const struct clk_hw *parent_hw, const struct clk_parent_data *parent_data, unsigned long flags, - void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, + void __iomem *reg, u8 shift, u8 width, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { struct clk_divider *div; @@ -610,7 +616,7 @@ EXPORT_SYMBOL_GPL(__clk_hw_register_divider); struct clk *clk_register_divider_table(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 shift, u8 width, - u8 clk_divider_flags, const struct clk_div_table *table, + u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { struct clk_hw *hw; @@ -664,7 +670,7 @@ struct clk_hw *__devm_clk_hw_register_divider(struct device *dev, struct device_node *np, const char *name, const char *parent_name, const struct clk_hw *parent_hw, const struct clk_parent_data *parent_data, unsigned long flags, - void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, + void __iomem *reg, u8 shift, u8 width, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { struct clk_hw **ptr, *hw; diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 4a537260f655..cb348e502e41 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -675,13 +675,15 @@ struct clk_div_table { * CLK_DIVIDER_BIG_ENDIAN - By default little endian register accesses are used * for the divider register. Setting this flag makes the register accesses * big endian. + * CLK_DIVIDER_EVEN_INTEGERS - clock divisor is 2, 4, 6, 8, 10, etc. + * Formula is 2 * (value read from hardware + 1). */ struct clk_divider { struct clk_hw hw; void __iomem *reg; u8 shift; u8 width; - u8 flags; + u16 flags; const struct clk_div_table *table; spinlock_t *lock; }; @@ -697,6 +699,7 @@ struct clk_divider { #define CLK_DIVIDER_READ_ONLY BIT(5) #define CLK_DIVIDER_MAX_AT_ZERO BIT(6) #define CLK_DIVIDER_BIG_ENDIAN BIT(7) +#define CLK_DIVIDER_EVEN_INTEGERS BIT(8) extern const struct clk_ops clk_divider_ops; extern const struct clk_ops clk_divider_ro_ops; @@ -726,18 +729,18 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev, struct device_node *np, const char *name, const char *parent_name, const struct clk_hw *parent_hw, const struct clk_parent_data *parent_data, unsigned long flags, - void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, + void __iomem *reg, u8 shift, u8 width, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock); struct clk_hw *__devm_clk_hw_register_divider(struct device *dev, struct device_node *np, const char *name, const char *parent_name, const struct clk_hw *parent_hw, const struct clk_parent_data *parent_data, unsigned long flags, - void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, + void __iomem *reg, u8 shift, u8 width, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock); struct clk *clk_register_divider_table(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 shift, u8 width, - u8 clk_divider_flags, const struct clk_div_table *table, + u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock); /** * clk_register_divider - register a divider clock with the clock framework -- 2.45.0