Skip to content

Commit

Permalink
pwm: Rename pwm_apply_state() to pwm_apply_might_sleep()
Browse files Browse the repository at this point in the history
In order to introduce a pwm api which can be used from atomic context,
we will need two functions for applying pwm changes:

	int pwm_apply_might_sleep(struct pwm *, struct pwm_state *);
	int pwm_apply_atomic(struct pwm *, struct pwm_state *);

This commit just deals with renaming pwm_apply_state(), a following
commit will introduce the pwm_apply_atomic() function.

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> # for input
Acked-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Sean Young authored and Thierry Reding committed Dec 20, 2023
1 parent 80943bb commit c748a6d
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 68 deletions.
8 changes: 4 additions & 4 deletions Documentation/driver-api/pwm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ 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.
Expand All @@ -57,13 +57,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
2 changes: 1 addition & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -17576,7 +17576,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|ops)

PXA GPIO DRIVER
M: Robert Jarzmik <robert.jarzmik@free.fr>
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 @@ -274,7 +274,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 @@ -427,7 +427,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 @@ -749,7 +749,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
4 changes: 2 additions & 2 deletions drivers/media/rc/pwm-ir-tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf,

for (i = 0; i < count; i++) {
state.enabled = !(i % 2);
pwm_apply_state(pwm, &state);
pwm_apply_might_sleep(pwm, &state);

edge = ktime_add_us(edge, txbuf[i]);
delta = ktime_us_delta(edge, ktime_get());
Expand All @@ -77,7 +77,7 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf,
}

state.enabled = false;
pwm_apply_state(pwm, &state);
pwm_apply_might_sleep(pwm, &state);

return count;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/platform/x86/lenovo-yogabook.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static int yogabook_pdev_set_kbd_backlight(struct yogabook_data *data, u8 level)
.enabled = level,
};

pwm_apply_state(data->kbd_bl_pwm, &state);
pwm_apply_might_sleep(data->kbd_bl_pwm, &state);
gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0);
return 0;
}
Expand Down
18 changes: 9 additions & 9 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
}
EXPORT_SYMBOL_GPL(pwm_request_from_chip);

static void pwm_apply_state_debug(struct pwm_device *pwm,
const struct pwm_state *state)
static void pwm_apply_debug(struct pwm_device *pwm,
const struct pwm_state *state)
{
struct pwm_state *last = &pwm->last;
struct pwm_chip *chip = pwm->chip;
Expand Down Expand Up @@ -433,19 +433,19 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
}

/**
* pwm_apply_state() - atomically apply a new state to a PWM device
* pwm_apply_might_sleep() - atomically apply a new state to a PWM device
* @pwm: PWM device
* @state: new state to apply
*/
int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state)
{
struct pwm_chip *chip;
int err;

/*
* Some lowlevel driver's implementations of .apply() make use of
* mutexes, also with some drivers only returning when the new
* configuration is active calling pwm_apply_state() from atomic context
* configuration is active calling pwm_apply_might_sleep() from atomic context
* is a bad idea. So make it explicit that calling this function might
* sleep.
*/
Expand Down Expand Up @@ -475,11 +475,11 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
* only do this after pwm->state was applied as some
* implementations of .get_state depend on this
*/
pwm_apply_state_debug(pwm, state);
pwm_apply_debug(pwm, state);

return 0;
}
EXPORT_SYMBOL_GPL(pwm_apply_state);
EXPORT_SYMBOL_GPL(pwm_apply_might_sleep);

/**
* pwm_capture() - capture and report a PWM signal
Expand Down Expand Up @@ -537,7 +537,7 @@ int pwm_adjust_config(struct pwm_device *pwm)
state.period = pargs.period;
state.polarity = pargs.polarity;

return pwm_apply_state(pwm, &state);
return pwm_apply_might_sleep(pwm, &state);
}

/*
Expand All @@ -560,7 +560,7 @@ int pwm_adjust_config(struct pwm_device *pwm)
state.duty_cycle = state.period - state.duty_cycle;
}

return pwm_apply_state(pwm, &state);
return pwm_apply_might_sleep(pwm, &state);
}
EXPORT_SYMBOL_GPL(pwm_adjust_config);

Expand Down
2 changes: 1 addition & 1 deletion drivers/pwm/pwm-twl-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static int twl4030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm,
* We cannot skip calling ->config even if state->period ==
* pwm->state.period && state->duty_cycle == pwm->state.duty_cycle
* because we might have exited early in the last call to
* pwm_apply_state because of !state->enabled and so the two values in
* pwm_apply_might_sleep because of !state->enabled and so the two values in
* pwm->state might not be configured in hardware.
*/
ret = twl4030_pwmled_config(chip, pwm,
Expand Down
2 changes: 1 addition & 1 deletion drivers/pwm/pwm-vt8500.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static int vt8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
* We cannot skip calling ->config even if state->period ==
* pwm->state.period && state->duty_cycle == pwm->state.duty_cycle
* because we might have exited early in the last call to
* pwm_apply_state because of !state->enabled and so the two values in
* pwm_apply_might_sleep because of !state->enabled and so the two values in
* pwm->state might not be configured in hardware.
*/
err = vt8500_pwm_config(chip, pwm, state->duty_cycle, state->period);
Expand Down
10 changes: 5 additions & 5 deletions drivers/pwm/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static ssize_t period_store(struct device *child,
mutex_lock(&export->lock);
pwm_get_state(pwm, &state);
state.period = val;
ret = pwm_apply_state(pwm, &state);
ret = pwm_apply_might_sleep(pwm, &state);
mutex_unlock(&export->lock);

return ret ? : size;
Expand Down Expand Up @@ -97,7 +97,7 @@ static ssize_t duty_cycle_store(struct device *child,
mutex_lock(&export->lock);
pwm_get_state(pwm, &state);
state.duty_cycle = val;
ret = pwm_apply_state(pwm, &state);
ret = pwm_apply_might_sleep(pwm, &state);
mutex_unlock(&export->lock);

return ret ? : size;
Expand Down Expand Up @@ -144,7 +144,7 @@ static ssize_t enable_store(struct device *child,
goto unlock;
}

ret = pwm_apply_state(pwm, &state);
ret = pwm_apply_might_sleep(pwm, &state);

unlock:
mutex_unlock(&export->lock);
Expand Down Expand Up @@ -194,7 +194,7 @@ static ssize_t polarity_store(struct device *child,
mutex_lock(&export->lock);
pwm_get_state(pwm, &state);
state.polarity = polarity;
ret = pwm_apply_state(pwm, &state);
ret = pwm_apply_might_sleep(pwm, &state);
mutex_unlock(&export->lock);

return ret ? : size;
Expand Down Expand Up @@ -401,7 +401,7 @@ static int pwm_class_apply_state(struct pwm_export *export,
struct pwm_device *pwm,
struct pwm_state *state)
{
int ret = pwm_apply_state(pwm, state);
int ret = pwm_apply_might_sleep(pwm, state);

/* release lock taken in pwm_class_get_state */
mutex_unlock(&export->lock);
Expand Down
4 changes: 2 additions & 2 deletions drivers/regulator/pwm-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
pwm_set_relative_duty_cycle(&pstate,
drvdata->duty_cycle_table[selector].dutycycle, 100);

ret = pwm_apply_state(drvdata->pwm, &pstate);
ret = pwm_apply_might_sleep(drvdata->pwm, &pstate);
if (ret) {
dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
return ret;
Expand Down Expand Up @@ -216,7 +216,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,

pwm_set_relative_duty_cycle(&pstate, dutycycle, duty_unit);

ret = pwm_apply_state(drvdata->pwm, &pstate);
ret = pwm_apply_might_sleep(drvdata->pwm, &pstate);
if (ret) {
dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/backlight/lm3630a_bl.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static int lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max)

pchip->pwmd_state.enabled = pchip->pwmd_state.duty_cycle ? true : false;

return pwm_apply_state(pchip->pwmd, &pchip->pwmd_state);
return pwm_apply_might_sleep(pchip->pwmd, &pchip->pwmd_state);
}

/* update and get brightness */
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/backlight/lp855x_bl.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static int lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
state.duty_cycle = div_u64(br * state.period, max_br);
state.enabled = state.duty_cycle;

return pwm_apply_state(lp->pwm, &state);
return pwm_apply_might_sleep(lp->pwm, &state);
}

static int lp855x_bl_update_status(struct backlight_device *bl)
Expand Down
Loading

0 comments on commit c748a6d

Please sign in to comment.