Skip to content

Commit

Permalink
Merge tag 'pwm/for-6.8-rc1' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/git/thierry.reding/linux-pwm

Pull pwm updates from Thierry Reding:
 "This contains a bunch of cleanups and simplifications across the
  board, as well as a number of small fixes.

  Perhaps the most notable change here is the addition of an API that
  allows PWMs to be used in atomic contexts, which is useful when time-
  critical operations are involved, such as using a PWM to generate IR
  signals.

  Finally, I have decided to step down as PWM subsystem maintainer. Due
  to other responsibilities I have lately not been able to find the time
  that the subsystem deserves and Uwe, who has been helping out a lot
  for the past few years and has many things planned for the future, has
  kindly volunteered to take over. I have no doubt that he will be a
  suitable replacement"

* tag 'pwm/for-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (44 commits)
  MAINTAINERS: pwm: Thierry steps down, Uwe takes over
  pwm: linux/pwm.h: fix Excess kernel-doc description warning
  pwm: Add pwm_apply_state() compatibility stub
  pwm: cros-ec: Drop documentation for dropped struct member
  pwm: Drop two unused API functions
  pwm: lpc18xx-sct: Don't modify the cached period of other PWM outputs
  pwm: meson: Simplify using dev_err_probe()
  pwm: stmpe: Silence duplicate error messages
  pwm: Reduce number of pointer dereferences in pwm_device_request()
  pwm: crc: Use consistent variable naming for driver data
  pwm: omap-dmtimer: Drop locking
  dt-bindings: pwm: ti,pwm-omap-dmtimer: Update binding for yaml
  media: pwm-ir-tx: Trigger edges from hrtimer interrupt context
  pwm: bcm2835: Allow PWM driver to be used in atomic context
  pwm: Make it possible to apply PWM changes in atomic context
  pwm: renesas: Remove unused include
  pwm: Replace ENOTSUPP with EOPNOTSUPP
  pwm: Rename pwm_apply_state() to pwm_apply_might_sleep()
  pwm: Stop referencing pwm->chip
  pwm: Update kernel doc for struct pwm_chip
  ...
  • Loading branch information
torvalds committed Jan 12, 2024
2 parents fef018d + 7afc0e7 commit 42bff4d
Show file tree
Hide file tree
Showing 53 changed files with 517 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ title: MediaTek DISP_PWM Controller

maintainers:
- Jitao Shi <[email protected]>
- Xinlei Lee <[email protected]>

allOf:
- $ref: pwm.yaml#
Expand Down
22 changes: 0 additions & 22 deletions Documentation/devicetree/bindings/pwm/pwm-omap-dmtimer.txt

This file was deleted.

59 changes: 59 additions & 0 deletions Documentation/devicetree/bindings/pwm/ti,omap-dmtimer-pwm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/pwm/ti,omap-dmtimer-pwm.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: TI dual mode timer PWM controller

maintainers:
- Tony Lindgren <[email protected]>

description:
TI dual mode timer instances have an IO pin for PWM capability

allOf:
- $ref: pwm.yaml#

properties:
compatible:
const: ti,omap-dmtimer-pwm

"#pwm-cells":
const: 3

ti,timers:
description: Timer instance phandle for the PWM
$ref: /schemas/types.yaml#/definitions/phandle

ti,prescaler:
description: |
Legacy clock prescaler for timer. The timer counter is prescaled
with 2^n where n is the prescaler.
$ref: /schemas/types.yaml#/definitions/uint32
enum: [ 0, 1, 2, 3, 4, 5, 6, 7 ]
deprecated: true

ti,clock-source:
description: |
Legacy clock for timer, please use assigned-clocks instead.
0x00 - high-frequency system clock (timer_sys_ck)
0x01 - 32-kHz always-on clock (timer_32k_ck)
0x02 - external clock (timer_ext_ck, OMAP2 only)
$ref: /schemas/types.yaml#/definitions/uint32
enum: [ 0, 1, 2 ]
deprecated: true

required:
- compatible
- ti,timers

unevaluatedProperties: false

examples:
- |
pwm9: pwm {
compatible = "ti,omap-dmtimer-pwm";
ti,timers = <&timer9>;
#pwm-cells = <3>;
};
17 changes: 13 additions & 4 deletions Documentation/driver-api/pwm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ the getter, devm_pwm_get() and devm_fwnode_pwm_get(), also exist.

After being requested, a PWM has to be configured using::

int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state);
int pwm_apply_might_sleep(struct pwm_device *pwm, struct pwm_state *state);

This API controls both the PWM period/duty_cycle config and the
enable/disable state.

PWM devices can be used from atomic context, if the PWM does not sleep. You
can check if this the case with::

bool pwm_might_sleep(struct pwm_device *pwm);

If false, the PWM can also be configured from atomic context with::

int pwm_apply_atomic(struct pwm_device *pwm, struct pwm_state *state);

As a consumer, don't rely on the output's state for a disabled PWM. If it's
easily possible, drivers are supposed to emit the inactive state, but some
drivers cannot. If you rely on getting the inactive state, use .duty_cycle=0,
Expand All @@ -57,13 +66,13 @@ If supported by the driver, the signal can be optimized, for example to improve
EMI by phase shifting the individual channels of a chip.

The pwm_config(), pwm_enable() and pwm_disable() functions are just wrappers
around pwm_apply_state() and should not be used if the user wants to change
around pwm_apply_might_sleep() and should not be used if the user wants to change
several parameter at once. For example, if you see pwm_config() and
pwm_{enable,disable}() calls in the same function, this probably means you
should switch to pwm_apply_state().
should switch to pwm_apply_might_sleep().

The PWM user API also allows one to query the PWM state that was passed to the
last invocation of pwm_apply_state() using pwm_get_state(). Note this is
last invocation of pwm_apply_might_sleep() using pwm_get_state(). Note this is
different to what the driver has actually implemented if the request cannot be
satisfied exactly with the hardware in use. There is currently no way for
consumers to get the actually implemented settings.
Expand Down
7 changes: 3 additions & 4 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -17645,12 +17645,11 @@ F: Documentation/devicetree/bindings/leds/irled/pwm-ir-tx.yaml
F: drivers/media/rc/pwm-ir-tx.c

PWM SUBSYSTEM
M: Thierry Reding <[email protected]>
R: Uwe Kleine-König <[email protected]>
M: Uwe Kleine-König <[email protected]>
L: [email protected]
S: Maintained
Q: https://patchwork.ozlabs.org/project/linux-pwm/list/
T: git git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git
T: git https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git
F: Documentation/devicetree/bindings/gpio/gpio-mvebu.yaml
F: Documentation/devicetree/bindings/pwm/
F: Documentation/driver-api/pwm.rst
Expand All @@ -17660,7 +17659,7 @@ F: drivers/video/backlight/pwm_bl.c
F: include/dt-bindings/pwm/
F: include/linux/pwm.h
F: include/linux/pwm_backlight.h
K: pwm_(config|apply_state|ops)
K: pwm_(config|apply_might_sleep|apply_atomic|ops)

PXA GPIO DRIVER
M: Robert Jarzmik <[email protected]>
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/i915/display/intel_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static void ext_pwm_set_backlight(const struct drm_connector_state *conn_state,
struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel;

pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100);
pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state);
pwm_apply_might_sleep(panel->backlight.pwm, &panel->backlight.pwm_state);
}

static void
Expand Down Expand Up @@ -428,7 +428,7 @@ static void ext_pwm_disable_backlight(const struct drm_connector_state *old_conn
intel_backlight_set_pwm_level(old_conn_state, level);

panel->backlight.pwm_state.enabled = false;
pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state);
pwm_apply_might_sleep(panel->backlight.pwm, &panel->backlight.pwm_state);
}

void intel_backlight_disable(const struct drm_connector_state *old_conn_state)
Expand Down Expand Up @@ -750,7 +750,7 @@ static void ext_pwm_enable_backlight(const struct intel_crtc_state *crtc_state,

pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100);
panel->backlight.pwm_state.enabled = true;
pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state);
pwm_apply_might_sleep(panel->backlight.pwm, &panel->backlight.pwm_state);
}

static void __intel_backlight_enable(const struct intel_crtc_state *crtc_state,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/solomon/ssd130x.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static int ssd130x_pwm_enable(struct ssd130x_device *ssd130x)

pwm_init_state(ssd130x->pwm, &pwmstate);
pwm_set_relative_duty_cycle(&pwmstate, 50, 100);
pwm_apply_state(ssd130x->pwm, &pwmstate);
pwm_apply_might_sleep(ssd130x->pwm, &pwmstate);

/* Enable the PWM */
pwm_enable(ssd130x->pwm);
Expand Down
8 changes: 4 additions & 4 deletions drivers/hwmon/pwm-fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int pwm_fan_power_on(struct pwm_fan_ctx *ctx)
}

state->enabled = true;
ret = pwm_apply_state(ctx->pwm, state);
ret = pwm_apply_might_sleep(ctx->pwm, state);
if (ret) {
dev_err(ctx->dev, "failed to enable PWM\n");
goto disable_regulator;
Expand Down Expand Up @@ -181,7 +181,7 @@ static int pwm_fan_power_off(struct pwm_fan_ctx *ctx)

state->enabled = false;
state->duty_cycle = 0;
ret = pwm_apply_state(ctx->pwm, state);
ret = pwm_apply_might_sleep(ctx->pwm, state);
if (ret) {
dev_err(ctx->dev, "failed to disable PWM\n");
return ret;
Expand All @@ -207,7 +207,7 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)

period = state->period;
state->duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);
ret = pwm_apply_state(ctx->pwm, state);
ret = pwm_apply_might_sleep(ctx->pwm, state);
if (ret)
return ret;
ret = pwm_fan_power_on(ctx);
Expand Down Expand Up @@ -278,7 +278,7 @@ static int pwm_fan_update_enable(struct pwm_fan_ctx *ctx, long val)
state,
&enable_regulator);

pwm_apply_state(ctx->pwm, state);
pwm_apply_might_sleep(ctx->pwm, state);
pwm_fan_switch_power(ctx, enable_regulator);
pwm_fan_update_state(ctx, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/input/misc/da7280.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static int da7280_haptic_set_pwm(struct da7280_haptic *haptics, bool enabled)
state.duty_cycle = period_mag_multi;
}

error = pwm_apply_state(haptics->pwm_dev, &state);
error = pwm_apply_might_sleep(haptics->pwm_dev, &state);
if (error)
dev_err(haptics->dev, "Failed to apply pwm state: %d\n", error);

Expand Down Expand Up @@ -1175,7 +1175,7 @@ static int da7280_probe(struct i2c_client *client)
/* Sync up PWM state and ensure it is off. */
pwm_init_state(haptics->pwm_dev, &state);
state.enabled = false;
error = pwm_apply_state(haptics->pwm_dev, &state);
error = pwm_apply_might_sleep(haptics->pwm_dev, &state);
if (error) {
dev_err(dev, "Failed to apply PWM state: %d\n", error);
return error;
Expand Down
4 changes: 2 additions & 2 deletions drivers/input/misc/pwm-beeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period)
state.period = period;
pwm_set_relative_duty_cycle(&state, 50, 100);

error = pwm_apply_state(beeper->pwm, &state);
error = pwm_apply_might_sleep(beeper->pwm, &state);
if (error)
return error;

Expand Down Expand Up @@ -138,7 +138,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
/* Sync up PWM state and ensure it is off. */
pwm_init_state(beeper->pwm, &state);
state.enabled = false;
error = pwm_apply_state(beeper->pwm, &state);
error = pwm_apply_might_sleep(beeper->pwm, &state);
if (error) {
dev_err(dev, "failed to apply initial PWM state: %d\n",
error);
Expand Down
8 changes: 4 additions & 4 deletions drivers/input/misc/pwm-vibra.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
pwm_set_relative_duty_cycle(&state, vibrator->level, 0xffff);
state.enabled = true;

err = pwm_apply_state(vibrator->pwm, &state);
err = pwm_apply_might_sleep(vibrator->pwm, &state);
if (err) {
dev_err(pdev, "failed to apply pwm state: %d\n", err);
return err;
Expand All @@ -67,7 +67,7 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
state.duty_cycle = vibrator->direction_duty_cycle;
state.enabled = true;

err = pwm_apply_state(vibrator->pwm_dir, &state);
err = pwm_apply_might_sleep(vibrator->pwm_dir, &state);
if (err) {
dev_err(pdev, "failed to apply dir-pwm state: %d\n", err);
pwm_disable(vibrator->pwm);
Expand Down Expand Up @@ -160,7 +160,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
/* Sync up PWM state and ensure it is off. */
pwm_init_state(vibrator->pwm, &state);
state.enabled = false;
err = pwm_apply_state(vibrator->pwm, &state);
err = pwm_apply_might_sleep(vibrator->pwm, &state);
if (err) {
dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n",
err);
Expand All @@ -174,7 +174,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
/* Sync up PWM state and ensure it is off. */
pwm_init_state(vibrator->pwm_dir, &state);
state.enabled = false;
err = pwm_apply_state(vibrator->pwm_dir, &state);
err = pwm_apply_might_sleep(vibrator->pwm_dir, &state);
if (err) {
dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n",
err);
Expand Down
2 changes: 1 addition & 1 deletion drivers/leds/leds-pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int led_pwm_set(struct led_classdev *led_cdev,

led_dat->pwmstate.duty_cycle = duty;
led_dat->pwmstate.enabled = true;
return pwm_apply_state(led_dat->pwm, &led_dat->pwmstate);
return pwm_apply_might_sleep(led_dat->pwm, &led_dat->pwmstate);
}

__attribute__((nonnull))
Expand Down
4 changes: 2 additions & 2 deletions drivers/leds/rgb/leds-pwm-multicolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static int led_pwm_mc_set(struct led_classdev *cdev,

priv->leds[i].state.duty_cycle = duty;
priv->leds[i].state.enabled = duty > 0;
ret = pwm_apply_state(priv->leds[i].pwm,
&priv->leds[i].state);
ret = pwm_apply_might_sleep(priv->leds[i].pwm,
&priv->leds[i].state);
if (ret)
break;
}
Expand Down
Loading

0 comments on commit 42bff4d

Please sign in to comment.