From nobody Tue Nov 26 00:58:48 2024 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.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 551D31E7657 for ; Wed, 23 Oct 2024 20:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729717162; cv=none; b=bL8ScJm/ydnf2CsegMw70qXpK5rjn3jPlhgE+OpJsyLhFq5kGR30OUbgHIdY2Y0lC6o7dtarueLoHD54rUcXJWkbwDbrRciw7Q00d3Rpq9FVY0pA6OvUvKUsaRFOGFVEwQ+Om+5fNuEHEjvYqcS/blXc5zFcj5sLG+fGvE8rEss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729717162; c=relaxed/simple; bh=SlCysBgz0D/4+AADJGuHeqX6/WY754v+eDo0HNvP8C4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ifibcRYBqmy9ecxkoxpXdi0B0s/Au2iDhA3lMt/B6TylZB+WpcS7eZ4gXIJZwVmOo7XLLvJZN/m6pa+wtj+kgX5dZZG2Vzy+xUvPUwm3TjGgI/DIbHGq0BusBAFwEBfUpJbq/XM9c1fOVC/FUvukDFPADEnbcrbJy8F3Uhc8E+E= 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=QFhtkj+X; arc=none smtp.client-ip=209.85.210.47 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="QFhtkj+X" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-71850708dc9so182369a34.0 for ; Wed, 23 Oct 2024 13:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729717159; x=1730321959; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8TxSe+My0zxdEn+4gVzAIjVmZG39HxjUCg8p7C0cMnI=; b=QFhtkj+XE0Gjpjnt27RxaEKUTNJeOSO8aweYhrtcy91DlH8n+4JJhQZmNvAZX9oeDP LYpBr+laTTWn/vyjYZc7T3a72llddv5t3RrGHrouFWuPX2U1pbnTsHg3Wg0oHqEaHpHN LosEeO16As6uDIb1YzhM8Ngc1zWWULHSv7PdaaixCUSrjUtcReerInLdVoZl0artcc4A Z6UxrgINOTcMaOCG8VhekcKxOBYxv9W30gZeasqfhOTuNznlkdiYROzlVWpRgfAADtY1 Yw98PITB3WtaYkH7YKr3HAhSRWBvqcyulKsbJMjfHHnExkwbofEpfSWPDi9S7RmN2baQ 3YRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729717159; x=1730321959; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8TxSe+My0zxdEn+4gVzAIjVmZG39HxjUCg8p7C0cMnI=; b=XrktKM7QVvJ9vUEHzd2VmD+i82WO66TlXyCDJdJBYdOiv7bx7UP75y8JCRAiBXFuAW F9u6eWEylqxpe/zZ2hZS2wwbv1706eQejETSIolrqB/v6Z3+RaKo8L1HbbSbQ+JjTbwU 2GbT+Mlpt8jxnN2dJcSkttipb+qEzaRq4ZqnEFxKyw6NsRacHlaRdueOg7vSWlquLC79 am3uRoEhUwancUh0DF7yo/oc0ckWY0hR+HXO1sCr1PJH410NajGZeaIkD8GwPQ6jrPg2 L9SXJZK+Y9OHbWOVeMo8011pC+UY6OIWbTNB86ZwUdevIKGwOaQWHjnFVVTTh1N8NYYk h0ZQ== X-Forwarded-Encrypted: i=1; AJvYcCU5C+Po1RvN8xEyt6uWI5NoDqpRrmAIMT/ZBgUKocyehW4CaehHXnmnC4Q+wP5Pjk5CrOmjX/HpU0bEXOk=@vger.kernel.org X-Gm-Message-State: AOJu0Ywc/qdrv1h7MjbS4IpcWtA0Xq5rnDSdbKOE55gSnAh+aJPqdhaN 3LyXKuenMSnOX9xWOAzBfKKoYp5RTHbfYPnhs+U2QGutWqCmsYTg7FigNajudteSglzcIUyRKOH C X-Google-Smtp-Source: AGHT+IHLXaj2jzh6xyZqcUUi3HAROcbZJkyHzk/8HYjkhquqvm+FQrkdOY7a4q7lSibR/k9/2Gq7iA== X-Received: by 2002:a05:6830:4981:b0:718:12af:7f01 with SMTP id 46e09a7af769-7184b2e6a7fmr5254614a34.13.1729717159246; Wed, 23 Oct 2024 13:59:19 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2c157sm52730eaf.44.2024.10.23.13.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 13:59:17 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 15:59:08 -0500 Subject: [PATCH RFC v4 01/15] pwm: core: export pwm_get_state_hw() 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: quoted-printable Message-Id: <20241023-dlech-mainline-spi-engine-offload-2-v4-1-f8125b99f5a1@baylibre.com> References: <20241023-dlech-mainline-spi-engine-offload-2-v4-0-f8125b99f5a1@baylibre.com> In-Reply-To: <20241023-dlech-mainline-spi-engine-offload-2-v4-0-f8125b99f5a1@baylibre.com> To: Mark Brown , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?utf-8?q?Nuno_S=C3=A1?= , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Michael Hennerich , Lars-Peter Clausen , David Jander , Martin Sperl , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-pwm@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Export the pwm_get_state_hw() function. This is useful in cases where we want to know what the hardware is actually doing, rather than what what we requested it should do. Signed-off-by: David Lechner --- v4 changes: new patch in v4 And FYI for Uwe and Jonathan, there are a couple of other series introducing PWM conversion triggers that could make use of this so that the sampling_frequency attribute can return the actual rate rather than the requested rate. Already applied: https://lore.kernel.org/linux-iio/20241015-ad7606_add_iio_backend_support-v= 5-4-654faf1ae08c@baylibre.com/ Under review: https://lore.kernel.org/linux-iio/aea7f92b-3d12-4ced-b1c8-90bcf1d992d3@bayl= ibre.com/T/#m1377d5acd7e996acd1f59038bdd09f0742d3ac35 --- drivers/pwm/core.c | 55 +++++++++++++++++++++++++++++++++++++------------= ---- include/linux/pwm.h | 1 + 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 634be56e204b..a214d0165d09 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -718,7 +718,7 @@ int pwm_apply_atomic(struct pwm_device *pwm, const stru= ct pwm_state *state) } EXPORT_SYMBOL_GPL(pwm_apply_atomic); =20 -static int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *stat= e) +static int __pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *st= ate) { struct pwm_chip *chip =3D pwm->chip; const struct pwm_ops *ops =3D chip->ops; @@ -730,29 +730,50 @@ static int pwm_get_state_hw(struct pwm_device *pwm, s= truct pwm_state *state) =20 BUG_ON(WFHWSIZE < ops->sizeof_wfhw); =20 - scoped_guard(pwmchip, chip) { - - ret =3D __pwm_read_waveform(chip, pwm, &wfhw); - if (ret) - return ret; + ret =3D __pwm_read_waveform(chip, pwm, &wfhw); + if (ret) + return ret; =20 - ret =3D __pwm_round_waveform_fromhw(chip, pwm, &wfhw, &wf); - if (ret) - return ret; - } + ret =3D __pwm_round_waveform_fromhw(chip, pwm, &wfhw, &wf); + if (ret) + return ret; =20 pwm_wf2state(&wf, state); =20 } else if (ops->get_state) { - scoped_guard(pwmchip, chip) - ret =3D ops->get_state(chip, pwm, state); - + ret =3D ops->get_state(chip, pwm, state); trace_pwm_get(pwm, state, ret); } =20 return ret; } =20 +/** + * pwm_get_state_hw() - get the current PWM state from hardware + * @pwm: PWM device + * @state: state to fill with the current PWM state + * + * Similar to pwm_get_state() but reads the current PWM state from hardware + * instead of the requested state. + * + * Returns: 0 on success or a negative error code on failure. + * Context: May sleep. + */ +int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *state) +{ + struct pwm_chip *chip =3D pwm->chip; + + might_sleep(); + + guard(pwmchip)(chip); + + if (!chip->operational) + return -ENODEV; + + return __pwm_get_state_hw(pwm, state); +} +EXPORT_SYMBOL_GPL(pwm_get_state_hw); + /** * pwm_adjust_config() - adjust the current PWM config to the PWM arguments * @pwm: PWM device @@ -906,9 +927,11 @@ static int pwm_device_request(struct pwm_device *pwm, = const char *label) */ struct pwm_state state =3D { 0, }; =20 - err =3D pwm_get_state_hw(pwm, &state); - if (!err) - pwm->state =3D state; + scoped_guard(pwmchip, chip) { + err =3D __pwm_get_state_hw(pwm, &state); + if (!err) + pwm->state =3D state; + } =20 if (IS_ENABLED(CONFIG_PWM_DEBUG)) pwm->last =3D pwm->state; diff --git a/include/linux/pwm.h b/include/linux/pwm.h index f1cb1e5b0a36..5bcbcf2911c3 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -370,6 +370,7 @@ int pwm_get_waveform_might_sleep(struct pwm_device *pwm= , struct pwm_waveform *wf int pwm_set_waveform_might_sleep(struct pwm_device *pwm, const struct pwm_= waveform *wf, bool exact); int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *= state); int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state= ); +int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *state); int pwm_adjust_config(struct pwm_device *pwm); =20 /** --=20 2.43.0