Skip to content

Commit 6c452cf

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: Make .get_state() callback return an error code
.get_state() might fail in some cases. To make it possible that a driver signals such a failure change the prototype of .get_state() to return an error code. This patch was created using coccinelle and the following semantic patch: @p1@ identifier getstatefunc; identifier driver; @@ struct pwm_ops driver = { ..., .get_state = getstatefunc ,... }; @p2@ identifier p1.getstatefunc; identifier chip, pwm, state; @@ -void +int getstatefunc(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { ... - return; + return 0; ... } plus the actual change of the prototype in include/linux/pwm.h (plus some manual fixing of indentions and empty lines). So for now all drivers return success unconditionally. They are adapted in the following patches to make the changes easier reviewable. Reviewed-by: Heiko Stuebner <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> Reviewed-by: Nobuhiro Iwamatsu <[email protected]> Reviewed-by: Andre Przywara <[email protected]> Reviewed-by: Dave Stevenson <[email protected]> Acked-by: Douglas Anderson <[email protected]> Acked-by: Jernej Skrabec <[email protected]> Acked-by: Pavel Machek <[email protected]> Acked-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 958f030 commit 6c452cf

29 files changed

+146
-89
lines changed

drivers/gpio/gpio-mvebu.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,10 @@ static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
657657
spin_unlock_irqrestore(&mvpwm->lock, flags);
658658
}
659659

660-
static void mvebu_pwm_get_state(struct pwm_chip *chip,
661-
struct pwm_device *pwm,
662-
struct pwm_state *state) {
660+
static int mvebu_pwm_get_state(struct pwm_chip *chip,
661+
struct pwm_device *pwm,
662+
struct pwm_state *state)
663+
{
663664

664665
struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
665666
struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
@@ -693,6 +694,8 @@ static void mvebu_pwm_get_state(struct pwm_chip *chip,
693694
state->enabled = false;
694695

695696
spin_unlock_irqrestore(&mvpwm->lock, flags);
697+
698+
return 0;
696699
}
697700

698701
static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

drivers/gpu/drm/bridge/ti-sn65dsi86.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,8 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
15001500
return ret;
15011501
}
15021502

1503-
static void ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
1504-
struct pwm_state *state)
1503+
static int ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
1504+
struct pwm_state *state)
15051505
{
15061506
struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip);
15071507
unsigned int pwm_en_inv;
@@ -1512,19 +1512,19 @@ static void ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
15121512

15131513
ret = regmap_read(pdata->regmap, SN_PWM_EN_INV_REG, &pwm_en_inv);
15141514
if (ret)
1515-
return;
1515+
return 0;
15161516

15171517
ret = ti_sn65dsi86_read_u16(pdata, SN_BACKLIGHT_SCALE_REG, &scale);
15181518
if (ret)
1519-
return;
1519+
return 0;
15201520

15211521
ret = ti_sn65dsi86_read_u16(pdata, SN_BACKLIGHT_REG, &backlight);
15221522
if (ret)
1523-
return;
1523+
return 0;
15241524

15251525
ret = regmap_read(pdata->regmap, SN_PWM_PRE_DIV_REG, &pre_div);
15261526
if (ret)
1527-
return;
1527+
return 0;
15281528

15291529
state->enabled = FIELD_GET(SN_PWM_EN_MASK, pwm_en_inv);
15301530
if (FIELD_GET(SN_PWM_INV_MASK, pwm_en_inv))
@@ -1539,6 +1539,8 @@ static void ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
15391539

15401540
if (state->duty_cycle > state->period)
15411541
state->duty_cycle = state->period;
1542+
1543+
return 0;
15421544
}
15431545

15441546
static const struct pwm_ops ti_sn_pwm_ops = {

drivers/leds/rgb/leds-qcom-lpg.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ static int lpg_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
968968
return ret;
969969
}
970970

971-
static void lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
972-
struct pwm_state *state)
971+
static int lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
972+
struct pwm_state *state)
973973
{
974974
struct lpg *lpg = container_of(chip, struct lpg, pwm);
975975
struct lpg_channel *chan = &lpg->channels[pwm->hwpwm];
@@ -982,20 +982,20 @@ static void lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
982982

983983
ret = regmap_read(lpg->map, chan->base + LPG_SIZE_CLK_REG, &val);
984984
if (ret)
985-
return;
985+
return 0;
986986

987987
refclk = lpg_clk_rates[val & PWM_CLK_SELECT_MASK];
988988
if (refclk) {
989989
ret = regmap_read(lpg->map, chan->base + LPG_PREDIV_CLK_REG, &val);
990990
if (ret)
991-
return;
991+
return 0;
992992

993993
pre_div = lpg_pre_divs[FIELD_GET(PWM_FREQ_PRE_DIV_MASK, val)];
994994
m = FIELD_GET(PWM_FREQ_EXP_MASK, val);
995995

996996
ret = regmap_bulk_read(lpg->map, chan->base + PWM_VALUE_REG, &pwm_value, sizeof(pwm_value));
997997
if (ret)
998-
return;
998+
return 0;
999999

10001000
state->period = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * LPG_RESOLUTION * pre_div * (1 << m), refclk);
10011001
state->duty_cycle = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * pwm_value * pre_div * (1 << m), refclk);
@@ -1006,13 +1006,15 @@ static void lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
10061006

10071007
ret = regmap_read(lpg->map, chan->base + PWM_ENABLE_CONTROL_REG, &val);
10081008
if (ret)
1009-
return;
1009+
return 0;
10101010

10111011
state->enabled = FIELD_GET(LPG_ENABLE_CONTROL_OUTPUT, val);
10121012
state->polarity = PWM_POLARITY_NORMAL;
10131013

10141014
if (state->duty_cycle > state->period)
10151015
state->duty_cycle = state->period;
1016+
1017+
return 0;
10161018
}
10171019

10181020
static const struct pwm_ops lpg_pwm_ops = {

drivers/pwm/pwm-atmel.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
356356
return 0;
357357
}
358358

359-
static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
360-
struct pwm_state *state)
359+
static int atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
360+
struct pwm_state *state)
361361
{
362362
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
363363
u32 sr, cmr;
@@ -396,6 +396,8 @@ static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
396396
state->polarity = PWM_POLARITY_INVERSED;
397397
else
398398
state->polarity = PWM_POLARITY_NORMAL;
399+
400+
return 0;
399401
}
400402

401403
static const struct pwm_ops atmel_pwm_ops = {

drivers/pwm/pwm-bcm-iproc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static void iproc_pwmc_disable(struct iproc_pwmc *ip, unsigned int channel)
6868
ndelay(400);
6969
}
7070

71-
static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
72-
struct pwm_state *state)
71+
static int iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
72+
struct pwm_state *state)
7373
{
7474
struct iproc_pwmc *ip = to_iproc_pwmc(chip);
7575
u64 tmp, multi, rate;
@@ -91,7 +91,7 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
9191
if (rate == 0) {
9292
state->period = 0;
9393
state->duty_cycle = 0;
94-
return;
94+
return 0;
9595
}
9696

9797
value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
@@ -107,6 +107,8 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
107107
value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
108108
tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
109109
state->duty_cycle = div64_u64(tmp, rate);
110+
111+
return 0;
110112
}
111113

112114
static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,

drivers/pwm/pwm-crc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
121121
return 0;
122122
}
123123

124-
static void crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
125-
struct pwm_state *state)
124+
static int crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
125+
struct pwm_state *state)
126126
{
127127
struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip);
128128
struct device *dev = crc_pwm->chip.dev;
@@ -132,13 +132,13 @@ static void crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
132132
error = regmap_read(crc_pwm->regmap, PWM0_CLK_DIV, &clk_div_reg);
133133
if (error) {
134134
dev_err(dev, "Error reading PWM0_CLK_DIV %d\n", error);
135-
return;
135+
return 0;
136136
}
137137

138138
error = regmap_read(crc_pwm->regmap, PWM0_DUTY_CYCLE, &duty_cycle_reg);
139139
if (error) {
140140
dev_err(dev, "Error reading PWM0_DUTY_CYCLE %d\n", error);
141-
return;
141+
return 0;
142142
}
143143

144144
clk_div = (clk_div_reg & ~PWM_OUTPUT_ENABLE) + 1;
@@ -149,6 +149,8 @@ static void crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
149149
DIV_ROUND_UP_ULL(duty_cycle_reg * state->period, PWM_MAX_LEVEL);
150150
state->polarity = PWM_POLARITY_NORMAL;
151151
state->enabled = !!(clk_div_reg & PWM_OUTPUT_ENABLE);
152+
153+
return 0;
152154
}
153155

154156
static const struct pwm_ops crc_pwm_ops = {

drivers/pwm/pwm-cros-ec.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
183183
return 0;
184184
}
185185

186-
static void cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
187-
struct pwm_state *state)
186+
static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
187+
struct pwm_state *state)
188188
{
189189
struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip);
190190
struct cros_ec_pwm *channel = pwm_get_chip_data(pwm);
@@ -193,7 +193,7 @@ static void cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
193193
ret = cros_ec_pwm_get_duty(ec_pwm, pwm->hwpwm);
194194
if (ret < 0) {
195195
dev_err(chip->dev, "error getting initial duty: %d\n", ret);
196-
return;
196+
return 0;
197197
}
198198

199199
state->enabled = (ret > 0);
@@ -212,6 +212,8 @@ static void cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
212212
state->duty_cycle = channel->duty_cycle;
213213
else
214214
state->duty_cycle = ret;
215+
216+
return 0;
215217
}
216218

217219
static struct pwm_device *

drivers/pwm/pwm-dwc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ static int dwc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
163163
return 0;
164164
}
165165

166-
static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
167-
struct pwm_state *state)
166+
static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
167+
struct pwm_state *state)
168168
{
169169
struct dwc_pwm *dwc = to_dwc_pwm(chip);
170170
u64 duty, period;
@@ -188,6 +188,8 @@ static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
188188
state->polarity = PWM_POLARITY_INVERSED;
189189

190190
pm_runtime_put_sync(chip->dev);
191+
192+
return 0;
191193
}
192194

193195
static const struct pwm_ops dwc_pwm_ops = {

drivers/pwm/pwm-hibvt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ static void hibvt_pwm_set_polarity(struct pwm_chip *chip,
128128
PWM_POLARITY_MASK, (0x0 << PWM_POLARITY_SHIFT));
129129
}
130130

131-
static void hibvt_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
132-
struct pwm_state *state)
131+
static int hibvt_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
132+
struct pwm_state *state)
133133
{
134134
struct hibvt_pwm_chip *hi_pwm_chip = to_hibvt_pwm_chip(chip);
135135
void __iomem *base;
@@ -146,6 +146,8 @@ static void hibvt_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
146146

147147
value = readl(base + PWM_CTRL_ADDR(pwm->hwpwm));
148148
state->enabled = (PWM_ENABLE_MASK & value);
149+
150+
return 0;
149151
}
150152

151153
static int hibvt_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

drivers/pwm/pwm-imx-tpm.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ static int pwm_imx_tpm_round_state(struct pwm_chip *chip,
132132
return 0;
133133
}
134134

135-
static void pwm_imx_tpm_get_state(struct pwm_chip *chip,
136-
struct pwm_device *pwm,
137-
struct pwm_state *state)
135+
static int pwm_imx_tpm_get_state(struct pwm_chip *chip,
136+
struct pwm_device *pwm,
137+
struct pwm_state *state)
138138
{
139139
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
140140
u32 rate, val, prescale;
@@ -164,6 +164,8 @@ static void pwm_imx_tpm_get_state(struct pwm_chip *chip,
164164

165165
/* get channel status */
166166
state->enabled = FIELD_GET(PWM_IMX_TPM_CnSC_ELS, val) ? true : false;
167+
168+
return 0;
167169
}
168170

169171
/* this function is supposed to be called with mutex hold */

0 commit comments

Comments
 (0)