summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-04-15 07:35:57 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2024-04-16 12:10:05 +0200
commitc5ae8eb5ef72385556c0665cf9fe0247219d83f6 (patch)
tree31608e727a343018c72face2cab8bc5eb22681df
parent29e00152bb73fcc59a6313f45649a12afd0c79c7 (diff)
downloadbarebox-c5ae8eb5ef72.tar.gz
barebox-c5ae8eb5ef72.tar.xz
PWM: align struct pwm_state member names with Linux
This introduces no functional change, but removes some churn of porting Linux drivers by aligning the naming of the frequently used struct pwm_state. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240415053600.370622-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/pwm.c32
-rw-r--r--drivers/led/led-pwm.c8
-rw-r--r--drivers/pwm/core.c32
-rw-r--r--drivers/pwm/pwm-atmel.c14
-rw-r--r--drivers/pwm/pwm-imx.c10
-rw-r--r--drivers/pwm/pwm-mxs.c12
-rw-r--r--drivers/pwm/pwm-stm32.c8
-rw-r--r--drivers/pwm/pxa_pwm.c12
-rw-r--r--drivers/sound/pwm-beeper.c6
-rw-r--r--include/pwm.h18
10 files changed, 76 insertions, 76 deletions
diff --git a/commands/pwm.c b/commands/pwm.c
index 5d41fa8ff4..b86f865d55 100644
--- a/commands/pwm.c
+++ b/commands/pwm.c
@@ -15,10 +15,10 @@
static bool is_equal_state(struct pwm_state *state1, struct pwm_state *state2)
{
- return (state1->period_ns == state2->period_ns)
- && (state1->duty_ns == state2->duty_ns)
+ return (state1->period == state2->period)
+ && (state1->duty_cycle == state2->duty_cycle)
&& (state1->polarity == state2->polarity)
- && (state1->p_enable == state2->p_enable);
+ && (state1->enabled == state2->enabled);
}
static int do_pwm_cmd(int argc, char *argv[])
@@ -109,12 +109,12 @@ static int do_pwm_cmd(int argc, char *argv[])
/* argc will be at least 3 with a valid devname */
if (verbose || (argc <= 3)) {
printf("pwm params for '%s':\n", devname);
- printf(" period : %u (ns)\n", state.period_ns);
- printf(" duty : %u (ns)\n", state.duty_ns);
- printf(" enabled : %d\n", state.p_enable);
+ printf(" period : %u (ns)\n", state.period);
+ printf(" duty : %u (ns)\n", state.duty_cycle);
+ printf(" enabled : %d\n", state.enabled);
printf(" polarity : %s\n", state.polarity == 0 ? "Normal" : "Inverted");
- if (state.period_ns)
- printf(" freq : %lu (Hz)\n", HZ_FROM_NANOSECONDS(state.period_ns));
+ if (state.period)
+ printf(" freq : %lu (Hz)\n", HZ_FROM_NANOSECONDS(state.period));
else
printf(" freq : -\n");
@@ -122,7 +122,7 @@ static int do_pwm_cmd(int argc, char *argv[])
return 0;
}
- if ((state.period_ns == 0) && (freq < 0) && (period < 0)) {
+ if ((state.period == 0) && (freq < 0) && (period < 0)) {
printf(" need to know some timing info: freq or period\n");
pwm_free(pwm);
return COMMAND_ERROR;
@@ -135,24 +135,24 @@ static int do_pwm_cmd(int argc, char *argv[])
/* period */
if (freq > 0) {
- state.p_enable = true;
- state.period_ns = HZ_TO_NANOSECONDS(freq);
+ state.enabled = true;
+ state.period = HZ_TO_NANOSECONDS(freq);
if (use_default_width && (width < 0)) {
width = 50;
}
} else if (period > 0) {
- state.p_enable = true;
- state.period_ns = period;
+ state.enabled = true;
+ state.period = period;
}
/* duty */
if (width >= 0) {
pwm_set_relative_duty_cycle(&state, width, 100);
} else if (duty >= 0) {
- state.duty_ns = duty;
+ state.duty_cycle = duty;
}
- if (state.duty_ns > state.period_ns) {
+ if (state.duty_cycle > state.period) {
printf(" duty_ns must not be greater than period_ns\n");
}
@@ -167,7 +167,7 @@ static int do_pwm_cmd(int argc, char *argv[])
* output (eg if duty => 0) and stopping in one command
*/
if (stop > 0) {
- state.p_enable = false;
+ state.enabled = false;
error = pwm_apply_state(pwm, &state);
if (error < 0)
printf(" error while stopping: %d\n", error);
diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 2ffb72e692..6f4abf97c8 100644
--- a/drivers/led/led-pwm.c
+++ b/drivers/led/led-pwm.c
@@ -27,14 +27,14 @@ static void led_pwm_set(struct led *led, unsigned int brightness)
pwm_get_state(pwmled->pwm, &state);
- duty = state.period_ns * brightness;
+ duty = state.period * brightness;
do_div(duty, max);
if (pwmled->active_low)
- duty = state.period_ns - duty;
+ duty = state.period - duty;
- state.p_enable = true;
- state.duty_ns = duty;
+ state.enabled = true;
+ state.duty_cycle = duty;
pwm_apply_state(pwmled->pwm, &state);
}
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 706c4515e9..7e090cc144 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -76,7 +76,7 @@ static int set_enable(struct param_d *p, void *priv)
{
struct pwm_device *pwm = priv;
- if (pwm->params.p_enable)
+ if (pwm->params.enabled)
pwm_enable(pwm);
else
pwm_disable(pwm);
@@ -118,17 +118,17 @@ int pwmchip_add(struct pwm_chip *chip)
list_add_tail(&pwm->node, &pwm_list);
p = dev_add_param_uint32(&pwm->dev, "duty_ns", apply_params,
- NULL, &pwm->params.duty_ns, "%u", pwm);
+ NULL, &pwm->params.duty_cycle, "%u", pwm);
if (IS_ERR(p))
return PTR_ERR(p);
p = dev_add_param_uint32(&pwm->dev, "period_ns", apply_params,
- NULL, &pwm->params.period_ns, "%u", pwm);
+ NULL, &pwm->params.period, "%u", pwm);
if (IS_ERR(p))
return PTR_ERR(p);
p = dev_add_param_bool(&pwm->dev, "enable", set_enable,
- NULL, &pwm->params.p_enable, pwm);
+ NULL, &pwm->params.enabled, pwm);
if (IS_ERR(p))
return PTR_ERR(p);
@@ -309,9 +309,9 @@ void pwm_init_state(const struct pwm_device *pwm,
/* Then fill it with the reference config */
pwm_get_args(pwm, &args);
- state->period_ns = args.period_ns;
+ state->period = args.period_ns;
state->polarity = args.polarity;
- state->duty_ns = 0;
+ state->duty_cycle = 0;
}
EXPORT_SYMBOL_GPL(pwm_init_state);
@@ -320,10 +320,10 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
struct pwm_chip *chip = pwm->chip;
int ret = -EINVAL;
- if (state->period_ns == 0)
+ if (state->period == 0)
goto err;
- if (state->duty_ns > state->period_ns)
+ if (state->duty_cycle > state->period)
goto err;
ret = chip->ops->apply(chip, pwm, state);
@@ -346,18 +346,18 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
return -EINVAL;
pwm_get_state(pwm, &state);
- if (state.duty_ns == duty_ns && state.period_ns == period_ns)
+ if (state.duty_cycle == duty_ns && state.period == period_ns)
return 0;
- state.duty_ns = duty_ns;
- state.period_ns = period_ns;
+ state.duty_cycle = duty_ns;
+ state.period = period_ns;
return pwm_apply_state(pwm, &state);
}
EXPORT_SYMBOL_GPL(pwm_config);
unsigned int pwm_get_period(struct pwm_device *pwm)
{
- return pwm->chip->state.period_ns;
+ return pwm->chip->state.period;
}
/*
@@ -368,10 +368,10 @@ int pwm_enable(struct pwm_device *pwm)
struct pwm_state state;
pwm_get_state(pwm, &state);
- if (state.p_enable)
+ if (state.enabled)
return 0;
- state.p_enable = true;
+ state.enabled = true;
return pwm_apply_state(pwm, &state);
}
EXPORT_SYMBOL_GPL(pwm_enable);
@@ -384,10 +384,10 @@ void pwm_disable(struct pwm_device *pwm)
struct pwm_state state;
pwm_get_state(pwm, &state);
- if (!state.p_enable)
+ if (!state.enabled)
return;
- state.p_enable = false;
+ state.enabled = false;
pwm_apply_state(pwm, &state);
}
EXPORT_SYMBOL_GPL(pwm_disable);
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 331a6e9712..851676c0dd 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -194,7 +194,7 @@ static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip,
unsigned long *cprd, u32 *pres)
{
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
- unsigned long long cycles = state->period_ns;
+ unsigned long long cycles = state->period;
int shift;
/* Calculate the period cycles and prescale value */
@@ -227,7 +227,7 @@ static void atmel_pwm_calculate_cdty(const struct pwm_state *state,
unsigned long clkrate, unsigned long cprd,
u32 pres, unsigned long *cdty)
{
- unsigned long long cycles = state->duty_ns;
+ unsigned long long cycles = state->duty_cycle;
cycles *= clkrate;
do_div(cycles, NSEC_PER_SEC);
@@ -298,12 +298,12 @@ static int atmel_pwm_apply(struct pwm_chip *chip,
cstate = chip->state;
- if (state->p_enable) {
+ if (state->enabled) {
unsigned long clkrate = clk_get_rate(atmel_pwm->clk);
- if (cstate.p_enable &&
+ if (cstate.enabled &&
cstate.polarity == state->polarity &&
- cstate.period_ns == state->period_ns) {
+ cstate.period == state->period) {
u32 cmr = atmel_pwm_ch_readl(atmel_pwm, chip->id, PWM_CMR);
cprd = atmel_pwm_ch_readl(atmel_pwm, chip->id,
@@ -325,7 +325,7 @@ static int atmel_pwm_apply(struct pwm_chip *chip,
atmel_pwm_calculate_cdty(state, clkrate, cprd, pres, &cdty);
- if (cstate.p_enable) {
+ if (cstate.enabled) {
atmel_pwm_disable(chip, false);
} else {
ret = clk_enable(atmel_pwm->clk);
@@ -345,7 +345,7 @@ static int atmel_pwm_apply(struct pwm_chip *chip,
atmel_pwm_ch_writel(atmel_pwm, chip->id, PWM_CMR, val);
atmel_pwm_set_cprd_cdty(chip, cprd, cdty);
atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << chip->id);
- } else if (cstate.p_enable) {
+ } else if (cstate.enabled) {
atmel_pwm_disable(chip, true);
}
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index f5e3cbcd7c..2a75400593 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -162,7 +162,7 @@ static int imx_pwm_config_v2(struct pwm_chip *chip,
writel(cr, imx->mmio_base + MX3_PWMCR);
- if (!chip->state.p_enable)
+ if (!chip->state.enabled)
imx_pwm_clk_disable_v2(imx);
return 0;
@@ -199,18 +199,18 @@ static int imx_pwm_apply(struct pwm_chip *chip,
bool enabled;
int ret;
- enabled = chip->state.p_enable;
+ enabled = chip->state.enabled;
- if (enabled && !state->p_enable) {
+ if (enabled && !state->enabled) {
imx->set_enable(chip, false);
return 0;
}
- ret = imx->config(chip, state->duty_ns, state->period_ns);
+ ret = imx->config(chip, state->duty_cycle, state->period);
if (ret)
return ret;
- if (!enabled && state->p_enable)
+ if (!enabled && state->enabled)
imx->set_enable(chip, true);
return 0;
diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
index 18279bf287..3e3efade68 100644
--- a/drivers/pwm/pwm-mxs.c
+++ b/drivers/pwm/pwm-mxs.c
@@ -55,9 +55,9 @@ static int mxs_pwm_apply(struct pwm_chip *chip,
unsigned long long c;
bool enabled;
- enabled = chip->state.p_enable;
+ enabled = chip->state.enabled;
- if (enabled && !state->p_enable) {
+ if (enabled && !state->enabled) {
writel(1 << mxs->chip.id, mxs->mxs->base + PWM_CTRL + CLR);
return 0;
}
@@ -65,7 +65,7 @@ static int mxs_pwm_apply(struct pwm_chip *chip,
rate = clk_get_rate(mxs->mxs->clk);
while (1) {
c = rate / cdiv[div];
- c = c * state->period_ns;
+ c = c * state->period;
do_div(c, 1000000000);
if (c < PERIOD_PERIOD_MAX)
break;
@@ -75,8 +75,8 @@ static int mxs_pwm_apply(struct pwm_chip *chip,
}
period_cycles = c;
- c *= state->duty_ns;
- do_div(c, state->period_ns);
+ c *= state->duty_cycle;
+ do_div(c, state->period);
duty_cycles = c;
writel(duty_cycles << 16,
@@ -85,7 +85,7 @@ static int mxs_pwm_apply(struct pwm_chip *chip,
PERIOD_INACTIVE_LOW | PERIOD_CDIV(div),
mxs->mxs->base + PWM_PERIOD0 + mxs->chip.id * 0x20);
- if (!enabled && state->p_enable)
+ if (!enabled && state->enabled)
writel(1 << mxs->chip.id, mxs->mxs->base + PWM_CTRL + SET);
return 0;
diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
index 218a270c02..16f80381c2 100644
--- a/drivers/pwm/pwm-stm32.c
+++ b/drivers/pwm/pwm-stm32.c
@@ -206,9 +206,9 @@ static int stm32_pwm_apply(struct pwm_chip *chip,
struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
int ret;
- enabled = chip->state.p_enable;
+ enabled = chip->state.enabled;
- if (enabled && !state->p_enable) {
+ if (enabled && !state->enabled) {
stm32_pwm_disable(priv, chip->id);
return 0;
}
@@ -217,11 +217,11 @@ static int stm32_pwm_apply(struct pwm_chip *chip,
stm32_pwm_set_polarity(priv, chip->id, state->polarity);
ret = stm32_pwm_config(priv, chip->id,
- state->duty_ns, state->period_ns);
+ state->duty_cycle, state->period);
if (ret)
return ret;
- if (!enabled && state->p_enable)
+ if (!enabled && state->enabled)
ret = stm32_pwm_enable(priv, chip->id);
return ret;
diff --git a/drivers/pwm/pxa_pwm.c b/drivers/pwm/pxa_pwm.c
index 09f36c92dd..42ccb37b9a 100644
--- a/drivers/pwm/pxa_pwm.c
+++ b/drivers/pwm/pxa_pwm.c
@@ -86,15 +86,15 @@ static int pxa_pwm_apply(struct pwm_chip *chip,
struct pxa_pwm_chip *pxa_pwm = to_pxa_pwm_chip(chip);
bool enabled;
- enabled = chip->state.p_enable;
+ enabled = chip->state.enabled;
- if (enabled && !state->p_enable) {
+ if (enabled && !state->enabled) {
pxa_pwm_disable(pxa_pwm);
return 0;
}
c = pxa_get_pwmclk();
- c = c * state->period_ns;
+ c = c * state->period;
do_div(c, 1000000000);
period_cycles = c;
@@ -106,10 +106,10 @@ static int pxa_pwm_apply(struct pwm_chip *chip,
if (prescale > 63)
return -EINVAL;
- if (state->duty_ns == state->period_ns)
+ if (state->duty_cycle == state->period)
dc = PWMDCR_FD;
else
- dc = (pv + 1) * state->duty_ns / state->period_ns;
+ dc = (pv + 1) * state->duty_cycle / state->period;
/* NOTE: the clock to PWM has to be enabled first
* before writing to the registers
@@ -118,7 +118,7 @@ static int pxa_pwm_apply(struct pwm_chip *chip,
writel(dc, pxa_pwm->iobase + PWMDCR);
writel(pv, pxa_pwm->iobase + PWMPCR);
- if (!enabled && state->p_enable) {
+ if (!enabled && state->enabled) {
pxa_pwm_enable(pxa_pwm);
return 0;
}
diff --git a/drivers/sound/pwm-beeper.c b/drivers/sound/pwm-beeper.c
index 21e57d4b07..94b27359c1 100644
--- a/drivers/sound/pwm-beeper.c
+++ b/drivers/sound/pwm-beeper.c
@@ -31,8 +31,8 @@ static int pwm_beeper_beep(struct sound_card *card, unsigned freq, unsigned dura
pwm_get_state(beeper->pwm, &state);
- state.p_enable = true;
- state.period_ns = HZ_TO_NANOSECONDS(freq);
+ state.enabled = true;
+ state.period = HZ_TO_NANOSECONDS(freq);
pwm_set_relative_duty_cycle(&state, 50, 100);
error = pwm_apply_state(beeper->pwm, &state);
@@ -66,7 +66,7 @@ static int pwm_beeper_probe(struct device *dev)
/* Sync up PWM state and ensure it is off. */
pwm_init_state(beeper->pwm, &state);
- state.p_enable = false;
+ state.enabled = false;
error = pwm_apply_state(beeper->pwm, &state);
if (error) {
dev_err(dev, "failed to apply initial PWM state: %d\n",
diff --git a/include/pwm.h b/include/pwm.h
index 876a242289..e8b0f2c962 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -12,16 +12,16 @@ struct device;
/*
* struct pwm_state - state of a PWM channel
- * @period_ns: PWM period (in nanoseconds)
- * @duty_ns: PWM duty cycle (in nanoseconds)
+ * @period: PWM period (in nanoseconds)
+ * @duty_cycle: PWM duty cycle (in nanoseconds)
* @polarity: PWM polarity
- * @p_enable: PWM enabled status
+ * @enabled: PWM enabled status
*/
struct pwm_state {
- unsigned int period_ns;
- unsigned int duty_ns;
+ unsigned int period;
+ unsigned int duty_cycle;
unsigned int polarity;
- unsigned int p_enable;
+ unsigned int enabled;
};
void pwm_print(void);
@@ -91,9 +91,9 @@ pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
if (!scale || duty_cycle > scale)
return -EINVAL;
- state->duty_ns = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle *
- state->period_ns,
- scale);
+ state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle *
+ state->period,
+ scale);
return 0;
}