Skip to content

Commit 2c87f7a

Browse files
committed
Merge tag 'pwm/for-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "The ZTE ZX platform is being removed, so the PWM driver is no longer needed and removed as well. Other than that this contains a small set of fixes and cleanups across a couple of drivers" * tag 'pwm/for-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: pwm: lpc18xx-sct: remove unneeded semicolon pwm: iqs620a: Correct a stale state variable pwm: iqs620a: Fix overflow and optimize calculations pwm: rockchip: Enable clock before calling clk_get_rate() pwm: rockchip: Eliminate potential race condition when probing pwm: rockchip: Replace "bus clk" with "PWM clk" pwm: rockchip: rockchip_pwm_probe(): Remove superfluous clk_unprepare() pwm: rockchip: Enable APB clock during register access while probing pwm: Remove ZTE ZX driver
2 parents ffc1759 + 9a9dd7e commit 2c87f7a

File tree

7 files changed

+65
-374
lines changed

7 files changed

+65
-374
lines changed

Documentation/devicetree/bindings/pwm/pwm-zx.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

drivers/pwm/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,4 @@ config PWM_VT8500
611611
To compile this driver as a module, choose M here: the module
612612
will be called pwm-vt8500.
613613

614-
config PWM_ZX
615-
tristate "ZTE ZX PWM support"
616-
depends on ARCH_ZX || COMPILE_TEST
617-
depends on HAS_IOMEM
618-
help
619-
Generic PWM framework driver for ZTE ZX family SoCs.
620-
621-
To compile this driver as a module, choose M here: the module
622-
will be called pwm-zx.
623-
624614
endif

drivers/pwm/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o
5757
obj-$(CONFIG_PWM_TWL) += pwm-twl.o
5858
obj-$(CONFIG_PWM_TWL_LED) += pwm-twl-led.o
5959
obj-$(CONFIG_PWM_VT8500) += pwm-vt8500.o
60-
obj-$(CONFIG_PWM_ZX) += pwm-zx.o

drivers/pwm/pwm-iqs620a.c

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,34 @@ struct iqs620_pwm_private {
3737
struct pwm_chip chip;
3838
struct notifier_block notifier;
3939
struct mutex lock;
40-
bool out_en;
41-
u8 duty_val;
40+
unsigned int duty_scale;
4241
};
4342

43+
static int iqs620_pwm_init(struct iqs620_pwm_private *iqs620_pwm,
44+
unsigned int duty_scale)
45+
{
46+
struct iqs62x_core *iqs62x = iqs620_pwm->iqs62x;
47+
int ret;
48+
49+
if (!duty_scale)
50+
return regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
51+
IQS620_PWR_SETTINGS_PWM_OUT, 0);
52+
53+
ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE,
54+
duty_scale - 1);
55+
if (ret)
56+
return ret;
57+
58+
return regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
59+
IQS620_PWR_SETTINGS_PWM_OUT, 0xff);
60+
}
61+
4462
static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
4563
const struct pwm_state *state)
4664
{
4765
struct iqs620_pwm_private *iqs620_pwm;
48-
struct iqs62x_core *iqs62x;
49-
u64 duty_scale;
66+
unsigned int duty_cycle;
67+
unsigned int duty_scale;
5068
int ret;
5169

5270
if (state->polarity != PWM_POLARITY_NORMAL)
@@ -56,7 +74,6 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
5674
return -EINVAL;
5775

5876
iqs620_pwm = container_of(chip, struct iqs620_pwm_private, chip);
59-
iqs62x = iqs620_pwm->iqs62x;
6077

6178
/*
6279
* The duty cycle generated by the device is calculated as follows:
@@ -70,38 +87,18 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
7087
* For lower duty cycles (e.g. 0), the PWM output is simply disabled to
7188
* allow an external pull-down resistor to hold the GPIO3/LTX pin low.
7289
*/
73-
duty_scale = div_u64(state->duty_cycle * 256, IQS620_PWM_PERIOD_NS);
74-
75-
mutex_lock(&iqs620_pwm->lock);
76-
77-
if (!state->enabled || !duty_scale) {
78-
ret = regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
79-
IQS620_PWR_SETTINGS_PWM_OUT, 0);
80-
if (ret)
81-
goto err_mutex;
82-
}
90+
duty_cycle = min_t(u64, state->duty_cycle, IQS620_PWM_PERIOD_NS);
91+
duty_scale = duty_cycle * 256 / IQS620_PWM_PERIOD_NS;
8392

84-
if (duty_scale) {
85-
u8 duty_val = min_t(u64, duty_scale - 1, 0xff);
93+
if (!state->enabled)
94+
duty_scale = 0;
8695

87-
ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE,
88-
duty_val);
89-
if (ret)
90-
goto err_mutex;
91-
92-
iqs620_pwm->duty_val = duty_val;
93-
}
94-
95-
if (state->enabled && duty_scale) {
96-
ret = regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
97-
IQS620_PWR_SETTINGS_PWM_OUT, 0xff);
98-
if (ret)
99-
goto err_mutex;
100-
}
96+
mutex_lock(&iqs620_pwm->lock);
10197

102-
iqs620_pwm->out_en = state->enabled;
98+
ret = iqs620_pwm_init(iqs620_pwm, duty_scale);
99+
if (!ret)
100+
iqs620_pwm->duty_scale = duty_scale;
103101

104-
err_mutex:
105102
mutex_unlock(&iqs620_pwm->lock);
106103

107104
return ret;
@@ -119,12 +116,11 @@ static void iqs620_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
119116
/*
120117
* Since the device cannot generate a 0% duty cycle, requests to do so
121118
* cause subsequent calls to iqs620_pwm_get_state to report the output
122-
* as disabled with duty cycle equal to that which was in use prior to
123-
* the request. This is not ideal, but is the best compromise based on
119+
* as disabled. This is not ideal, but is the best compromise based on
124120
* the capabilities of the device.
125121
*/
126-
state->enabled = iqs620_pwm->out_en;
127-
state->duty_cycle = DIV_ROUND_UP((iqs620_pwm->duty_val + 1) *
122+
state->enabled = iqs620_pwm->duty_scale > 0;
123+
state->duty_cycle = DIV_ROUND_UP(iqs620_pwm->duty_scale *
128124
IQS620_PWM_PERIOD_NS, 256);
129125

130126
mutex_unlock(&iqs620_pwm->lock);
@@ -136,15 +132,13 @@ static int iqs620_pwm_notifier(struct notifier_block *notifier,
136132
unsigned long event_flags, void *context)
137133
{
138134
struct iqs620_pwm_private *iqs620_pwm;
139-
struct iqs62x_core *iqs62x;
140135
int ret;
141136

142137
if (!(event_flags & BIT(IQS62X_EVENT_SYS_RESET)))
143138
return NOTIFY_DONE;
144139

145140
iqs620_pwm = container_of(notifier, struct iqs620_pwm_private,
146141
notifier);
147-
iqs62x = iqs620_pwm->iqs62x;
148142

149143
mutex_lock(&iqs620_pwm->lock);
150144

@@ -153,16 +147,8 @@ static int iqs620_pwm_notifier(struct notifier_block *notifier,
153147
* of a device reset, so nothing else is printed here unless there is
154148
* an additional failure.
155149
*/
156-
ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE,
157-
iqs620_pwm->duty_val);
158-
if (ret)
159-
goto err_mutex;
150+
ret = iqs620_pwm_init(iqs620_pwm, iqs620_pwm->duty_scale);
160151

161-
ret = regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
162-
IQS620_PWR_SETTINGS_PWM_OUT,
163-
iqs620_pwm->out_en ? 0xff : 0);
164-
165-
err_mutex:
166152
mutex_unlock(&iqs620_pwm->lock);
167153

168154
if (ret) {
@@ -209,12 +195,14 @@ static int iqs620_pwm_probe(struct platform_device *pdev)
209195
ret = regmap_read(iqs62x->regmap, IQS620_PWR_SETTINGS, &val);
210196
if (ret)
211197
return ret;
212-
iqs620_pwm->out_en = val & IQS620_PWR_SETTINGS_PWM_OUT;
213198

214-
ret = regmap_read(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE, &val);
215-
if (ret)
216-
return ret;
217-
iqs620_pwm->duty_val = val;
199+
if (val & IQS620_PWR_SETTINGS_PWM_OUT) {
200+
ret = regmap_read(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE, &val);
201+
if (ret)
202+
return ret;
203+
204+
iqs620_pwm->duty_scale = val + 1;
205+
}
218206

219207
iqs620_pwm->chip.dev = &pdev->dev;
220208
iqs620_pwm->chip.ops = &iqs620_pwm_ops;

drivers/pwm/pwm-lpc18xx-sct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
289289
dev_err(lpc18xx_pwm->dev,
290290
"maximum number of simultaneous channels reached\n");
291291
return -EBUSY;
292-
};
292+
}
293293

294294
set_bit(event, &lpc18xx_pwm->event_map);
295295
lpc18xx_data->duty_event = event;

drivers/pwm/pwm-rockchip.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ static void rockchip_pwm_get_state(struct pwm_chip *chip,
7272
if (ret)
7373
return;
7474

75+
ret = clk_enable(pc->clk);
76+
if (ret)
77+
return;
78+
7579
clk_rate = clk_get_rate(pc->clk);
7680

7781
tmp = readl_relaxed(pc->base + pc->data->regs.period);
@@ -90,6 +94,7 @@ static void rockchip_pwm_get_state(struct pwm_chip *chip,
9094
else
9195
state->polarity = PWM_POLARITY_NORMAL;
9296

97+
clk_disable(pc->clk);
9398
clk_disable(pc->pclk);
9499
}
95100

@@ -189,6 +194,10 @@ static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
189194
if (ret)
190195
return ret;
191196

197+
ret = clk_enable(pc->clk);
198+
if (ret)
199+
return ret;
200+
192201
pwm_get_state(pwm, &curstate);
193202
enabled = curstate.enabled;
194203

@@ -208,6 +217,7 @@ static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
208217
}
209218

210219
out:
220+
clk_disable(pc->clk);
211221
clk_disable(pc->pclk);
212222

213223
return ret;
@@ -288,6 +298,7 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
288298
const struct of_device_id *id;
289299
struct rockchip_pwm_chip *pc;
290300
u32 enable_conf, ctrl;
301+
bool enabled;
291302
int ret, count;
292303

293304
id = of_match_device(rockchip_pwm_dt_ids, &pdev->dev);
@@ -307,7 +318,7 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
307318
pc->clk = devm_clk_get(&pdev->dev, NULL);
308319
if (IS_ERR(pc->clk))
309320
return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk),
310-
"Can't get bus clk\n");
321+
"Can't get PWM clk\n");
311322
}
312323

313324
count = of_count_phandle_with_args(pdev->dev.of_node,
@@ -326,13 +337,13 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
326337

327338
ret = clk_prepare_enable(pc->clk);
328339
if (ret) {
329-
dev_err(&pdev->dev, "Can't prepare enable bus clk: %d\n", ret);
340+
dev_err(&pdev->dev, "Can't prepare enable PWM clk: %d\n", ret);
330341
return ret;
331342
}
332343

333-
ret = clk_prepare(pc->pclk);
344+
ret = clk_prepare_enable(pc->pclk);
334345
if (ret) {
335-
dev_err(&pdev->dev, "Can't prepare APB clk: %d\n", ret);
346+
dev_err(&pdev->dev, "Can't prepare enable APB clk: %d\n", ret);
336347
goto err_clk;
337348
}
338349

@@ -349,23 +360,26 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
349360
pc->chip.of_pwm_n_cells = 3;
350361
}
351362

363+
enable_conf = pc->data->enable_conf;
364+
ctrl = readl_relaxed(pc->base + pc->data->regs.ctrl);
365+
enabled = (ctrl & enable_conf) == enable_conf;
366+
352367
ret = pwmchip_add(&pc->chip);
353368
if (ret < 0) {
354-
clk_unprepare(pc->clk);
355369
dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
356370
goto err_pclk;
357371
}
358372

359373
/* Keep the PWM clk enabled if the PWM appears to be up and running. */
360-
enable_conf = pc->data->enable_conf;
361-
ctrl = readl_relaxed(pc->base + pc->data->regs.ctrl);
362-
if ((ctrl & enable_conf) != enable_conf)
374+
if (!enabled)
363375
clk_disable(pc->clk);
364376

377+
clk_disable(pc->pclk);
378+
365379
return 0;
366380

367381
err_pclk:
368-
clk_unprepare(pc->pclk);
382+
clk_disable_unprepare(pc->pclk);
369383
err_clk:
370384
clk_disable_unprepare(pc->clk);
371385

0 commit comments

Comments
 (0)