From nobody Mon Feb 9 04:12:30 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 51FE88627D for ; Wed, 19 Jun 2024 10:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718791939; cv=none; b=R2y01utSuSLVWcGxasg0z40pR6b7yrmmfhzw+7r2PNIceSH9bn8WCk5SapgiEq2cOO7UqNMrE+haPsUqq+1vxq0RS3ytHt/WCtTZxKdZz8/p1EIm9zf8DM4K5FuERtHLHLgg9phblS+NEwkgRkfkMxpdA7wC2pQarJeFUJIaFWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718791939; c=relaxed/simple; bh=I3iLNPbAvcDPk6Nw1QUlh23HxzYQPmXbPfOcTvZTTEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qe/mpWMq2DPGE+cmP5vdfWHW/5HATSRJ5mO1ryZSajOeoUcJm96/d4B+JZKN81YAxe6AHNxp9lqsFJMefx1CbxbnKZwaX33ShBov5u9h2S+iVM5PDwecMyQ1yW3drSDYvf+BLfLAZQnIwSDiKF7sucE/JdN/nQwlFsSx/Gdh4d8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=r/e4f2nR; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="r/e4f2nR" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52bc29c79fdso8532982e87.1 for ; Wed, 19 Jun 2024 03:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718791935; x=1719396735; 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=Oy65aQubSD4tbmjRxefZecoIq4GXZIdFH64RPRpuevk=; b=r/e4f2nRL/TLpK7+y71IbGd0fozip5whzjgE0EUL/WYPx7edHPslGtRN2K7fW2DtzS 6R50gqT/WMaCkQhNeiO0z4uu+EErpVgAEOsLAFzOfNmIAyqj7+cE6h2yfpnFSmqjH3F6 dyurt451EOHx0oKZX+Fzvv3SKaxQV2Xjk65EFqN0UR+dP6+5VE2iLLTrJjFfcdit22nK +hnw2cBZrTSyHftlliviRtqJ1N3T4EBkq5VcLwdw8PE/WSZCatOGWSAJQhDbX3I5DJuY CYDJodMTtvNiLKZyqg+yDBrE02tAKuDHj2W3ZvU8cgxz/eUniRTpldVz9wZLAFOL21F0 j0mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718791935; x=1719396735; 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=Oy65aQubSD4tbmjRxefZecoIq4GXZIdFH64RPRpuevk=; b=eKfIcYgQVWze10Q2vnS993OGKRpoVJIxjspE3vTPVNkpc6MZQKyFTb0HwW1YJaUdnf YkO9BQkqIknw9xtL+qQBPgwzObR6liRN1a76uPe1JOFqvxNgwe4p6y+kcw678wtuC7wk SiuyCw/ycPeJahMGeYuZazOVxPaEqbTjJk/YZmGFZVNUC27EJ2deX7TmVSZUBt5zggSy K+o1scrir5DSnngI69PbbEmkdDuVMhEM0OE2/HDzy1Af0XhvjuJmNdy61shrY6748KI/ +1r67kgqwDzw08XvV0LNb7xWCGCmfyNgVVYXCvSRZLdh4lvnrQr4n/0BvLlTNZjzK0T1 xIZg== X-Forwarded-Encrypted: i=1; AJvYcCXX7yu2nmY3YYwGq3qcvi/Fgg6wi9IK4auZljj1A212gkfIYQ/IBHd6AKfzA3NebFW6b8hleJMQzv2Xxfd2OAq2ktnWOg+Z4TLd3tW0 X-Gm-Message-State: AOJu0YzLBFIvS8iQvywC08OgyKn18fqk/uGTRdUFKkBItvN44bGmvZ3I IJ/yp/kl1bZZoKiCTs5eF6upiE/OA0UpXeiFUtEs2mEdQOQ/VgGfuG1ZQQHD0W8= X-Google-Smtp-Source: AGHT+IElXV90COGxqoASkehEGVkVUJcHtIY55Qg2BOMAPU5KAnXGT3gOKzusHP31PljuwUXHfU62qQ== X-Received: by 2002:a05:6512:448:b0:52c:80fb:ee76 with SMTP id 2adb3069b0e04-52ccaa594ecmr1527652e87.58.1718791934559; Wed, 19 Jun 2024 03:12:14 -0700 (PDT) Received: from localhost (p509153eb.dip0.t-ipconnect.de. [80.145.83.235]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42286fe9184sm255060585e9.13.2024.06.19.03.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 03:12:14 -0700 (PDT) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Fabrice Gasnier , William Breathitt Gray , Lee Jones , Maxime Coquelin , Alexandre Torgue Cc: linux-pwm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thorsten Scherer Subject: [PATCH v2 5/5] pwm-stm32: Make use of parametrised register definitions Date: Wed, 19 Jun 2024 12:11:46 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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" X-Developer-Signature: v=1; a=openpgp-sha256; l=3795; i=u.kleine-koenig@baylibre.com; h=from:subject:message-id; bh=I3iLNPbAvcDPk6Nw1QUlh23HxzYQPmXbPfOcTvZTTEE=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBmcq7q8zY1OOIGZ/eP/4KeEUhCpX1HQd4lcfMiE qgoW7JMHLiJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZnKu6gAKCRCPgPtYfRL+ Toq4B/43LSGZu83nHMjrJj4MVPM4vtZms21eY4jgIjU0Gvcs7NtU61MHYKGY3AQOsxCPCNc9EvE t9VLqpH3lK2V4Haw2olqbsodrKWM508IzC24LQtqaqS8f1FqyzXuKaocLu4LYI2GsxUSURmkZh9 wRXRlhUikcxngpax3XlBNCaZ5ciBR68PmvbY+C2R7MgF6K4LkKRFYLr9PvvT9Gizpxp3hfYTAvP k1TXOVJaY2Tjv7E5t+9Advu+4qK49FdWMUpbx+/GfU21s6WTNwPLWCw7Rd14FtsQ/G8ymng3Vux Ga/FXD/DKAYkCorgEQiWt4mZDuWDWL/lOX6/6dpm/p8Lg+zi X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 Content-Transfer-Encoding: quoted-printable There is no semantic change, but it is a nicer on the eyes of a reader, because TIM_CCR1 + 4 * ch encodes internal register knowledge, while TIM_CCRx(ch + 1) keeps that information completely in the header defining the registers. While I expected this to not result in any changes in the binary, gcc 13 (as provided by Debian in the gcc-13-arm-linux-gnueabihf 13.2.0-12cross1 package) compiles the new version with an allmodconfig to more compact code: $ source/scripts/bloat-o-meter drivers/pwm/pwm-stm32.o-pre drivers/pwm/pwm= -stm32.o add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-488 (-488) Function old new delta stm32_pwm_get_state 968 936 -32 stm32_pwm_apply_locked 1920 1464 -456 Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/pwm/pwm-stm32.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index a2f231d13a9f..49a76514b83e 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -360,7 +360,7 @@ static int stm32_pwm_config(struct stm32_pwm *priv, uns= igned int ch, dty =3D mul_u64_u64_div_u64(duty_ns, clk_get_rate(priv->clk), (u64)NSEC_PER_SEC * (prescaler + 1)); =20 - regmap_write(priv->regmap, TIM_CCR1 + 4 * ch, dty); + regmap_write(priv->regmap, TIM_CCRx(ch + 1), dty); =20 /* Configure output mode */ shift =3D (ch & 0x1) * CCMR_CHANNEL_SHIFT; @@ -382,9 +382,9 @@ static int stm32_pwm_set_polarity(struct stm32_pwm *pri= v, unsigned int ch, { u32 mask; =20 - mask =3D TIM_CCER_CC1P << (ch * 4); + mask =3D TIM_CCER_CCxP(ch + 1); if (priv->have_complementary_output) - mask |=3D TIM_CCER_CC1NP << (ch * 4); + mask |=3D TIM_CCER_CCxNP(ch + 1); =20 regmap_update_bits(priv->regmap, TIM_CCER, mask, polarity =3D=3D PWM_POLARITY_NORMAL ? 0 : mask); @@ -402,9 +402,9 @@ static int stm32_pwm_enable(struct stm32_pwm *priv, uns= igned int ch) return ret; =20 /* Enable channel */ - mask =3D TIM_CCER_CC1E << (ch * 4); + mask =3D TIM_CCER_CCxE(ch + 1); if (priv->have_complementary_output) - mask |=3D TIM_CCER_CC1NE << (ch * 4); + mask |=3D TIM_CCER_CCxNE(ch); =20 regmap_set_bits(priv->regmap, TIM_CCER, mask); =20 @@ -422,9 +422,9 @@ static void stm32_pwm_disable(struct stm32_pwm *priv, u= nsigned int ch) u32 mask; =20 /* Disable channel */ - mask =3D TIM_CCER_CC1E << (ch * 4); + mask =3D TIM_CCER_CCxE(ch + 1); if (priv->have_complementary_output) - mask |=3D TIM_CCER_CC1NE << (ch * 4); + mask |=3D TIM_CCER_CCxNE(ch + 1); =20 regmap_clear_bits(priv->regmap, TIM_CCER, mask); =20 @@ -493,8 +493,8 @@ static int stm32_pwm_get_state(struct pwm_chip *chip, if (ret) goto out; =20 - state->enabled =3D ccer & (TIM_CCER_CC1E << (ch * 4)); - state->polarity =3D (ccer & (TIM_CCER_CC1P << (ch * 4))) ? + state->enabled =3D ccer & TIM_CCER_CCxE(ch + 1); + state->polarity =3D (ccer & TIM_CCER_CCxP(ch + 1)) ? PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL; ret =3D regmap_read(priv->regmap, TIM_PSC, &psc); if (ret) @@ -502,7 +502,7 @@ static int stm32_pwm_get_state(struct pwm_chip *chip, ret =3D regmap_read(priv->regmap, TIM_ARR, &arr); if (ret) goto out; - ret =3D regmap_read(priv->regmap, TIM_CCR1 + 4 * ch, &ccr); + ret =3D regmap_read(priv->regmap, TIM_CCRx(ch + 1), &ccr); if (ret) goto out; =20 @@ -702,7 +702,7 @@ static int stm32_pwm_suspend(struct device *dev) ccer =3D active_channels(priv); =20 for (i =3D 0; i < chip->npwm; i++) { - mask =3D TIM_CCER_CC1E << (i * 4); + mask =3D TIM_CCER_CCxE(i + 1); if (ccer & mask) { dev_err(dev, "PWM %u still in use by consumer %s\n", i, chip->pwms[i].label); --=20 2.43.0