summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2019-08-24 11:37:07 -0400
committerThierry Reding <thierry.reding@gmail.com>2019-09-20 21:25:10 -0400
commit71523d1812aca61e32e742e87ec064e3d8c615e1 (patch)
tree20491f0323c9b71d0628741824c4dcf992e22363
parentc9675829ba4b0e95c613f6d6d83d2b5cb9c5371c (diff)
pwm: Ensure pwm_apply_state() doesn't modify the state argument
It is surprising for a PWM consumer when the variable holding the requested state is modified by pwm_apply_state(). Consider for example a driver doing: #define PERIOD 5000000 #define DUTY_LITTLE 10 ... struct pwm_state state = { .period = PERIOD, .duty_cycle = DUTY_LITTLE, .polarity = PWM_POLARITY_NORMAL, .enabled = true, }; pwm_apply_state(mypwm, &state); ... state.duty_cycle = PERIOD / 2; pwm_apply_state(mypwm, &state); For sure the second call to pwm_apply_state() should still have state.period = PERIOD and not something the hardware driver chose for a reason that doesn't necessarily apply to the second call. So declare the state argument as a pointer to a const type and adapt all drivers' .apply callbacks. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r--drivers/gpio/gpio-mvebu.c2
-rw-r--r--drivers/pwm/core.c6
-rw-r--r--drivers/pwm/pwm-atmel-hlcdc.c2
-rw-r--r--drivers/pwm/pwm-atmel.c2
-rw-r--r--drivers/pwm/pwm-bcm-iproc.c2
-rw-r--r--drivers/pwm/pwm-cros-ec.c2
-rw-r--r--drivers/pwm/pwm-fsl-ftm.c4
-rw-r--r--drivers/pwm/pwm-hibvt.c2
-rw-r--r--drivers/pwm/pwm-imx-tpm.c4
-rw-r--r--drivers/pwm/pwm-imx27.c2
-rw-r--r--drivers/pwm/pwm-jz4740.c2
-rw-r--r--drivers/pwm/pwm-lpss.c2
-rw-r--r--drivers/pwm/pwm-meson.c4
-rw-r--r--drivers/pwm/pwm-rcar.c2
-rw-r--r--drivers/pwm/pwm-rockchip.c4
-rw-r--r--drivers/pwm/pwm-sifive.c2
-rw-r--r--drivers/pwm/pwm-sprd.c2
-rw-r--r--drivers/pwm/pwm-stm32-lp.c2
-rw-r--r--drivers/pwm/pwm-stm32.c4
-rw-r--r--drivers/pwm/pwm-sun4i.c4
-rw-r--r--drivers/pwm/pwm-zx.c2
-rw-r--r--include/linux/pwm.h4
22 files changed, 30 insertions, 32 deletions
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 869d47f89599..6c0687694341 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -694,7 +694,7 @@ static void mvebu_pwm_get_state(struct pwm_chip *chip,
694} 694}
695 695
696static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 696static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
697 struct pwm_state *state) 697 const struct pwm_state *state)
698{ 698{
699 struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip); 699 struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
700 struct mvebu_gpio_chip *mvchip = mvpwm->mvchip; 700 struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 449ba161877d..6ad51aa60c03 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -448,11 +448,9 @@ EXPORT_SYMBOL_GPL(pwm_free);
448/** 448/**
449 * pwm_apply_state() - atomically apply a new state to a PWM device 449 * pwm_apply_state() - atomically apply a new state to a PWM device
450 * @pwm: PWM device 450 * @pwm: PWM device
451 * @state: new state to apply. This can be adjusted by the PWM driver 451 * @state: new state to apply
452 * if the requested config is not achievable, for example,
453 * ->duty_cycle and ->period might be approximated.
454 */ 452 */
455int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) 453int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
456{ 454{
457 struct pwm_chip *chip; 455 struct pwm_chip *chip;
458 int err; 456 int err;
diff --git a/drivers/pwm/pwm-atmel-hlcdc.c b/drivers/pwm/pwm-atmel-hlcdc.c
index d13a83f430ac..dcbc0489dfd4 100644
--- a/drivers/pwm/pwm-atmel-hlcdc.c
+++ b/drivers/pwm/pwm-atmel-hlcdc.c
@@ -39,7 +39,7 @@ static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip)
39} 39}
40 40
41static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm, 41static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
42 struct pwm_state *state) 42 const struct pwm_state *state)
43{ 43{
44 struct atmel_hlcdc_pwm *chip = to_atmel_hlcdc_pwm(c); 44 struct atmel_hlcdc_pwm *chip = to_atmel_hlcdc_pwm(c);
45 struct atmel_hlcdc *hlcdc = chip->hlcdc; 45 struct atmel_hlcdc *hlcdc = chip->hlcdc;
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index e5e1eaf372fa..53bc7b9b3581 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -209,7 +209,7 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm,
209} 209}
210 210
211static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 211static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
212 struct pwm_state *state) 212 const struct pwm_state *state)
213{ 213{
214 struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 214 struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
215 struct pwm_state cstate; 215 struct pwm_state cstate;
diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
index d961a8207b1c..56c38cfae92c 100644
--- a/drivers/pwm/pwm-bcm-iproc.c
+++ b/drivers/pwm/pwm-bcm-iproc.c
@@ -115,7 +115,7 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
115} 115}
116 116
117static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm, 117static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
118 struct pwm_state *state) 118 const struct pwm_state *state)
119{ 119{
120 unsigned long prescale = IPROC_PWM_PRESCALE_MIN; 120 unsigned long prescale = IPROC_PWM_PRESCALE_MIN;
121 struct iproc_pwmc *ip = to_iproc_pwmc(chip); 121 struct iproc_pwmc *ip = to_iproc_pwmc(chip);
diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
index 98f6ac6cf6ab..db5faa79c33f 100644
--- a/drivers/pwm/pwm-cros-ec.c
+++ b/drivers/pwm/pwm-cros-ec.c
@@ -93,7 +93,7 @@ static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index)
93} 93}
94 94
95static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 95static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
96 struct pwm_state *state) 96 const struct pwm_state *state)
97{ 97{
98 struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip); 98 struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip);
99 int duty_cycle; 99 int duty_cycle;
diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c
index 3c9738617ceb..59272a920479 100644
--- a/drivers/pwm/pwm-fsl-ftm.c
+++ b/drivers/pwm/pwm-fsl-ftm.c
@@ -227,7 +227,7 @@ static bool fsl_pwm_is_other_pwm_enabled(struct fsl_pwm_chip *fpc,
227 227
228static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc, 228static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc,
229 struct pwm_device *pwm, 229 struct pwm_device *pwm,
230 struct pwm_state *newstate) 230 const struct pwm_state *newstate)
231{ 231{
232 unsigned int duty; 232 unsigned int duty;
233 u32 reg_polarity; 233 u32 reg_polarity;
@@ -298,7 +298,7 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc,
298} 298}
299 299
300static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 300static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
301 struct pwm_state *newstate) 301 const struct pwm_state *newstate)
302{ 302{
303 struct fsl_pwm_chip *fpc = to_fsl_chip(chip); 303 struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
304 struct pwm_state *oldstate = &pwm->state; 304 struct pwm_state *oldstate = &pwm->state;
diff --git a/drivers/pwm/pwm-hibvt.c b/drivers/pwm/pwm-hibvt.c
index 753bd58111e4..ad205fdad372 100644
--- a/drivers/pwm/pwm-hibvt.c
+++ b/drivers/pwm/pwm-hibvt.c
@@ -149,7 +149,7 @@ static void hibvt_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
149} 149}
150 150
151static int hibvt_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 151static int hibvt_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
152 struct pwm_state *state) 152 const struct pwm_state *state)
153{ 153{
154 struct hibvt_pwm_chip *hi_pwm_chip = to_hibvt_pwm_chip(chip); 154 struct hibvt_pwm_chip *hi_pwm_chip = to_hibvt_pwm_chip(chip);
155 155
diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
index e8385c1cf342..9145f6160649 100644
--- a/drivers/pwm/pwm-imx-tpm.c
+++ b/drivers/pwm/pwm-imx-tpm.c
@@ -89,7 +89,7 @@ to_imx_tpm_pwm_chip(struct pwm_chip *chip)
89static int pwm_imx_tpm_round_state(struct pwm_chip *chip, 89static int pwm_imx_tpm_round_state(struct pwm_chip *chip,
90 struct imx_tpm_pwm_param *p, 90 struct imx_tpm_pwm_param *p,
91 struct pwm_state *real_state, 91 struct pwm_state *real_state,
92 struct pwm_state *state) 92 const struct pwm_state *state)
93{ 93{
94 struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip); 94 struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
95 u32 rate, prescale, period_count, clock_unit; 95 u32 rate, prescale, period_count, clock_unit;
@@ -289,7 +289,7 @@ static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip,
289 289
290static int pwm_imx_tpm_apply(struct pwm_chip *chip, 290static int pwm_imx_tpm_apply(struct pwm_chip *chip,
291 struct pwm_device *pwm, 291 struct pwm_device *pwm,
292 struct pwm_state *state) 292 const struct pwm_state *state)
293{ 293{
294 struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip); 294 struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
295 struct imx_tpm_pwm_param param; 295 struct imx_tpm_pwm_param param;
diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c
index 91c23cbbc167..ae11d8577f18 100644
--- a/drivers/pwm/pwm-imx27.c
+++ b/drivers/pwm/pwm-imx27.c
@@ -209,7 +209,7 @@ static void pwm_imx27_wait_fifo_slot(struct pwm_chip *chip,
209} 209}
210 210
211static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, 211static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
212 struct pwm_state *state) 212 const struct pwm_state *state)
213{ 213{
214 unsigned long period_cycles, duty_cycles, prescale; 214 unsigned long period_cycles, duty_cycles, prescale;
215 struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip); 215 struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip);
diff --git a/drivers/pwm/pwm-jz4740.c b/drivers/pwm/pwm-jz4740.c
index 9d444d012f92..9d78cc21cb12 100644
--- a/drivers/pwm/pwm-jz4740.c
+++ b/drivers/pwm/pwm-jz4740.c
@@ -88,7 +88,7 @@ static void jz4740_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
88} 88}
89 89
90static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 90static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
91 struct pwm_state *state) 91 const struct pwm_state *state)
92{ 92{
93 struct jz4740_pwm_chip *jz4740 = to_jz4740(pwm->chip); 93 struct jz4740_pwm_chip *jz4740 = to_jz4740(pwm->chip);
94 unsigned long long tmp; 94 unsigned long long tmp;
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
index 4098a4601691..75bbfe5f3bc2 100644
--- a/drivers/pwm/pwm-lpss.c
+++ b/drivers/pwm/pwm-lpss.c
@@ -122,7 +122,7 @@ static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond)
122} 122}
123 123
124static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, 124static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
125 struct pwm_state *state) 125 const struct pwm_state *state)
126{ 126{
127 struct pwm_lpss_chip *lpwm = to_lpwm(chip); 127 struct pwm_lpss_chip *lpwm = to_lpwm(chip);
128 int ret; 128 int ret;
diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 3cbff5cbb789..6245bbdb6e6c 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -159,7 +159,7 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
159} 159}
160 160
161static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, 161static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
162 struct pwm_state *state) 162 const struct pwm_state *state)
163{ 163{
164 struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); 164 struct meson_pwm_channel *channel = pwm_get_chip_data(pwm);
165 unsigned int duty, period, pre_div, cnt, duty_cnt; 165 unsigned int duty, period, pre_div, cnt, duty_cnt;
@@ -265,7 +265,7 @@ static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm)
265} 265}
266 266
267static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 267static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
268 struct pwm_state *state) 268 const struct pwm_state *state)
269{ 269{
270 struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); 270 struct meson_pwm_channel *channel = pwm_get_chip_data(pwm);
271 struct meson_pwm *meson = to_meson_pwm(chip); 271 struct meson_pwm *meson = to_meson_pwm(chip);
diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c
index c8cd43f91efc..852eb2347954 100644
--- a/drivers/pwm/pwm-rcar.c
+++ b/drivers/pwm/pwm-rcar.c
@@ -158,7 +158,7 @@ static void rcar_pwm_disable(struct rcar_pwm_chip *rp)
158} 158}
159 159
160static int rcar_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 160static int rcar_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
161 struct pwm_state *state) 161 const struct pwm_state *state)
162{ 162{
163 struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); 163 struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip);
164 struct pwm_state cur_state; 164 struct pwm_state cur_state;
diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c
index 83c7627868d8..73352e6fbccb 100644
--- a/drivers/pwm/pwm-rockchip.c
+++ b/drivers/pwm/pwm-rockchip.c
@@ -99,7 +99,7 @@ static void rockchip_pwm_get_state(struct pwm_chip *chip,
99} 99}
100 100
101static void rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 101static void rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
102 struct pwm_state *state) 102 const struct pwm_state *state)
103{ 103{
104 struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); 104 struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
105 unsigned long period, duty; 105 unsigned long period, duty;
@@ -183,7 +183,7 @@ static int rockchip_pwm_enable(struct pwm_chip *chip,
183} 183}
184 184
185static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 185static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
186 struct pwm_state *state) 186 const struct pwm_state *state)
187{ 187{
188 struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); 188 struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
189 struct pwm_state curstate; 189 struct pwm_state curstate;
diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
index bb4f02ce4f94..cc63f9baa481 100644
--- a/drivers/pwm/pwm-sifive.c
+++ b/drivers/pwm/pwm-sifive.c
@@ -147,7 +147,7 @@ static int pwm_sifive_enable(struct pwm_chip *chip, bool enable)
147} 147}
148 148
149static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, 149static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
150 struct pwm_state *state) 150 const struct pwm_state *state)
151{ 151{
152 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); 152 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip);
153 struct pwm_state cur_state; 153 struct pwm_state cur_state;
diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
index 68c2d9f0411b..be2394227423 100644
--- a/drivers/pwm/pwm-sprd.c
+++ b/drivers/pwm/pwm-sprd.c
@@ -156,7 +156,7 @@ static int sprd_pwm_config(struct sprd_pwm_chip *spc, struct pwm_device *pwm,
156} 156}
157 157
158static int sprd_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 158static int sprd_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
159 struct pwm_state *state) 159 const struct pwm_state *state)
160{ 160{
161 struct sprd_pwm_chip *spc = 161 struct sprd_pwm_chip *spc =
162 container_of(chip, struct sprd_pwm_chip, chip); 162 container_of(chip, struct sprd_pwm_chip, chip);
diff --git a/drivers/pwm/pwm-stm32-lp.c b/drivers/pwm/pwm-stm32-lp.c
index 2211a642066d..21cb260dc2c0 100644
--- a/drivers/pwm/pwm-stm32-lp.c
+++ b/drivers/pwm/pwm-stm32-lp.c
@@ -32,7 +32,7 @@ static inline struct stm32_pwm_lp *to_stm32_pwm_lp(struct pwm_chip *chip)
32#define STM32_LPTIM_MAX_PRESCALER 128 32#define STM32_LPTIM_MAX_PRESCALER 128
33 33
34static int stm32_pwm_lp_apply(struct pwm_chip *chip, struct pwm_device *pwm, 34static int stm32_pwm_lp_apply(struct pwm_chip *chip, struct pwm_device *pwm,
35 struct pwm_state *state) 35 const struct pwm_state *state)
36{ 36{
37 struct stm32_pwm_lp *priv = to_stm32_pwm_lp(chip); 37 struct stm32_pwm_lp *priv = to_stm32_pwm_lp(chip);
38 unsigned long long prd, div, dty; 38 unsigned long long prd, div, dty;
diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
index 740e2dec8313..359b08596d9e 100644
--- a/drivers/pwm/pwm-stm32.c
+++ b/drivers/pwm/pwm-stm32.c
@@ -440,7 +440,7 @@ static void stm32_pwm_disable(struct stm32_pwm *priv, int ch)
440} 440}
441 441
442static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 442static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
443 struct pwm_state *state) 443 const struct pwm_state *state)
444{ 444{
445 bool enabled; 445 bool enabled;
446 struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 446 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
@@ -468,7 +468,7 @@ static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
468} 468}
469 469
470static int stm32_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *pwm, 470static int stm32_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *pwm,
471 struct pwm_state *state) 471 const struct pwm_state *state)
472{ 472{
473 struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 473 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
474 int ret; 474 int ret;
diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index 39007a7c0d83..6f5840a1a82d 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -145,7 +145,7 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip,
145} 145}
146 146
147static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4i_pwm, 147static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4i_pwm,
148 struct pwm_state *state, 148 const struct pwm_state *state,
149 u32 *dty, u32 *prd, unsigned int *prsclr) 149 u32 *dty, u32 *prd, unsigned int *prsclr)
150{ 150{
151 u64 clk_rate, div = 0; 151 u64 clk_rate, div = 0;
@@ -196,7 +196,7 @@ static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4i_pwm,
196} 196}
197 197
198static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 198static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
199 struct pwm_state *state) 199 const struct pwm_state *state)
200{ 200{
201 struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 201 struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip);
202 struct pwm_state cstate; 202 struct pwm_state cstate;
diff --git a/drivers/pwm/pwm-zx.c b/drivers/pwm/pwm-zx.c
index e24f4be35316..e2c21cc34a96 100644
--- a/drivers/pwm/pwm-zx.c
+++ b/drivers/pwm/pwm-zx.c
@@ -148,7 +148,7 @@ static int zx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
148} 148}
149 149
150static int zx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 150static int zx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
151 struct pwm_state *state) 151 const struct pwm_state *state)
152{ 152{
153 struct zx_pwm_chip *zpc = to_zx_pwm_chip(chip); 153 struct zx_pwm_chip *zpc = to_zx_pwm_chip(chip);
154 struct pwm_state cstate; 154 struct pwm_state cstate;
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 24632a7a7d11..b2c9c460947d 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -262,7 +262,7 @@ struct pwm_ops {
262 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm, 262 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
263 struct pwm_capture *result, unsigned long timeout); 263 struct pwm_capture *result, unsigned long timeout);
264 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, 264 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
265 struct pwm_state *state); 265 const struct pwm_state *state);
266 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, 266 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
267 struct pwm_state *state); 267 struct pwm_state *state);
268 struct module *owner; 268 struct module *owner;
@@ -316,7 +316,7 @@ struct pwm_capture {
316/* PWM user APIs */ 316/* PWM user APIs */
317struct pwm_device *pwm_request(int pwm_id, const char *label); 317struct pwm_device *pwm_request(int pwm_id, const char *label);
318void pwm_free(struct pwm_device *pwm); 318void pwm_free(struct pwm_device *pwm);
319int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state); 319int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state);
320int pwm_adjust_config(struct pwm_device *pwm); 320int pwm_adjust_config(struct pwm_device *pwm);
321 321
322/** 322/**