Skip to content

Commit 8d844b3

Browse files
committed
Merge tag 'pwm/for-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "Various cleanups and fixes across the board" * tag 'pwm/for-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (31 commits) pwm: lpc32xx: Remove handling of PWM channels pwm: atmel: Simplify using devm functions dt-bindings: pwm: brcm,kona-pwm: convert to YAML pwm: stmpe: Handle errors when disabling the signal pwm: stm32: Simplify using devm_pwmchip_add() pwm: stm32: Don't modify HW state in .remove() callback pwm: Fix order of freeing resources in pwmchip_remove() pwm: ntxec: Use device_set_of_node_from_dev() pwm: ntxec: Drop a write-only variable from driver data pwm: pxa: Don't reimplement of_device_get_match_data() pwm: lpc18xx-sct: Simplify using devm_clk_get_enabled() pwm: atmel-tcb: Don't track polarity in driver data pwm: atmel-tcb: Unroll atmel_tcb_pwm_set_polarity() into only caller pwm: atmel-tcb: Put per-channel data into driver data pwm: atmel-tcb: Fix resource freeing in error path and remove pwm: atmel-tcb: Harmonize resource allocation order pwm: Drop unused #include <linux/radix-tree.h> pwm: rz-mtu3: Fix build warning 'num_channel_ios' not described pwm: Remove outdated documentation for pwmchip_remove() pwm: atmel: Enable clk when pwm already enabled in bootloader ...
2 parents ff6e6de + 4aae44f commit 8d844b3

40 files changed

+281
-290
lines changed

Documentation/devicetree/bindings/pwm/brcm,kona-pwm.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/pwm/brcm,kona-pwm.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Broadcom Kona family PWM controller
8+
9+
description:
10+
This controller has 6 channels.
11+
12+
maintainers:
13+
- Florian Fainelli <f.fainelli@gmail.com>
14+
15+
allOf:
16+
- $ref: pwm.yaml#
17+
18+
properties:
19+
compatible:
20+
items:
21+
- enum:
22+
- brcm,bcm11351-pwm
23+
- const: brcm,kona-pwm
24+
25+
reg:
26+
maxItems: 1
27+
28+
clocks:
29+
maxItems: 1
30+
31+
'#pwm-cells':
32+
const: 3
33+
34+
required:
35+
- compatible
36+
- reg
37+
- clocks
38+
39+
unevaluatedProperties: false
40+
41+
examples:
42+
- |
43+
#include <dt-bindings/clock/bcm281xx.h>
44+
45+
pwm@3e01a000 {
46+
compatible = "brcm,bcm11351-pwm", "brcm,kona-pwm";
47+
reg = <0x3e01a000 0xcc>;
48+
clocks = <&slave_ccu BCM281XX_SLAVE_CCU_PWM>;
49+
#pwm-cells = <3>;
50+
};
51+
...

drivers/pwm/core.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include <linux/acpi.h>
1010
#include <linux/module.h>
11+
#include <linux/of.h>
1112
#include <linux/pwm.h>
12-
#include <linux/radix-tree.h>
1313
#include <linux/list.h>
1414
#include <linux/mutex.h>
1515
#include <linux/err.h>
@@ -127,28 +127,28 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
127127
}
128128

129129
struct pwm_device *
130-
of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
130+
of_pwm_xlate_with_flags(struct pwm_chip *chip, const struct of_phandle_args *args)
131131
{
132132
struct pwm_device *pwm;
133133

134-
if (pc->of_pwm_n_cells < 2)
134+
if (chip->of_pwm_n_cells < 2)
135135
return ERR_PTR(-EINVAL);
136136

137137
/* flags in the third cell are optional */
138138
if (args->args_count < 2)
139139
return ERR_PTR(-EINVAL);
140140

141-
if (args->args[0] >= pc->npwm)
141+
if (args->args[0] >= chip->npwm)
142142
return ERR_PTR(-EINVAL);
143143

144-
pwm = pwm_request_from_chip(pc, args->args[0], NULL);
144+
pwm = pwm_request_from_chip(chip, args->args[0], NULL);
145145
if (IS_ERR(pwm))
146146
return pwm;
147147

148148
pwm->args.period = args->args[1];
149149
pwm->args.polarity = PWM_POLARITY_NORMAL;
150150

151-
if (pc->of_pwm_n_cells >= 3) {
151+
if (chip->of_pwm_n_cells >= 3) {
152152
if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
153153
pwm->args.polarity = PWM_POLARITY_INVERSED;
154154
}
@@ -158,18 +158,18 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
158158
EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
159159

160160
struct pwm_device *
161-
of_pwm_single_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
161+
of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
162162
{
163163
struct pwm_device *pwm;
164164

165-
if (pc->of_pwm_n_cells < 1)
165+
if (chip->of_pwm_n_cells < 1)
166166
return ERR_PTR(-EINVAL);
167167

168168
/* validate that one cell is specified, optionally with flags */
169169
if (args->args_count != 1 && args->args_count != 2)
170170
return ERR_PTR(-EINVAL);
171171

172-
pwm = pwm_request_from_chip(pc, 0, NULL);
172+
pwm = pwm_request_from_chip(chip, 0, NULL);
173173
if (IS_ERR(pwm))
174174
return pwm;
175175

@@ -312,22 +312,19 @@ EXPORT_SYMBOL_GPL(pwmchip_add);
312312
* pwmchip_remove() - remove a PWM chip
313313
* @chip: the PWM chip to remove
314314
*
315-
* Removes a PWM chip. This function may return busy if the PWM chip provides
316-
* a PWM device that is still requested.
317-
*
318-
* Returns: 0 on success or a negative error code on failure.
315+
* Removes a PWM chip.
319316
*/
320317
void pwmchip_remove(struct pwm_chip *chip)
321318
{
322319
pwmchip_sysfs_unexport(chip);
323320

321+
if (IS_ENABLED(CONFIG_OF))
322+
of_pwmchip_remove(chip);
323+
324324
mutex_lock(&pwm_lock);
325325

326326
list_del_init(&chip->list);
327327

328-
if (IS_ENABLED(CONFIG_OF))
329-
of_pwmchip_remove(chip);
330-
331328
free_pwms(chip);
332329

333330
mutex_unlock(&pwm_lock);
@@ -692,7 +689,7 @@ static struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np,
692689
struct pwm_device *pwm = NULL;
693690
struct of_phandle_args args;
694691
struct device_link *dl;
695-
struct pwm_chip *pc;
692+
struct pwm_chip *chip;
696693
int index = 0;
697694
int err;
698695

@@ -709,16 +706,16 @@ static struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np,
709706
return ERR_PTR(err);
710707
}
711708

712-
pc = fwnode_to_pwmchip(of_fwnode_handle(args.np));
713-
if (IS_ERR(pc)) {
714-
if (PTR_ERR(pc) != -EPROBE_DEFER)
709+
chip = fwnode_to_pwmchip(of_fwnode_handle(args.np));
710+
if (IS_ERR(chip)) {
711+
if (PTR_ERR(chip) != -EPROBE_DEFER)
715712
pr_err("%s(): PWM chip not found\n", __func__);
716713

717-
pwm = ERR_CAST(pc);
714+
pwm = ERR_CAST(chip);
718715
goto put;
719716
}
720717

721-
pwm = pc->of_xlate(pc, &args);
718+
pwm = chip->of_xlate(chip, &args);
722719
if (IS_ERR(pwm))
723720
goto put;
724721

drivers/pwm/pwm-apple.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* - When APPLE_PWM_CTRL is set to 0, the output is constant low
1313
*/
1414

15+
#include <linux/mod_devicetable.h>
1516
#include <linux/module.h>
1617
#include <linux/platform_device.h>
1718
#include <linux/pwm.h>

drivers/pwm/pwm-atmel-hlcdc.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/delay.h>
1111
#include <linux/mfd/atmel-hlcdc.h>
1212
#include <linux/module.h>
13+
#include <linux/of.h>
1314
#include <linux/platform_device.h>
1415
#include <linux/pwm.h>
1516
#include <linux/regmap.h>
@@ -38,11 +39,11 @@ static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip)
3839
return container_of(chip, struct atmel_hlcdc_pwm, chip);
3940
}
4041

41-
static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
42+
static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
4243
const struct pwm_state *state)
4344
{
44-
struct atmel_hlcdc_pwm *chip = to_atmel_hlcdc_pwm(c);
45-
struct atmel_hlcdc *hlcdc = chip->hlcdc;
45+
struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
46+
struct atmel_hlcdc *hlcdc = atmel->hlcdc;
4647
unsigned int status;
4748
int ret;
4849

@@ -54,7 +55,7 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
5455
u32 pwmcfg;
5556
int pres;
5657

57-
if (!chip->errata || !chip->errata->slow_clk_erratum) {
58+
if (!atmel->errata || !atmel->errata->slow_clk_erratum) {
5859
clk_freq = clk_get_rate(new_clk);
5960
if (!clk_freq)
6061
return -EINVAL;
@@ -64,7 +65,7 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
6465
}
6566

6667
/* Errata: cannot use slow clk on some IP revisions */
67-
if ((chip->errata && chip->errata->slow_clk_erratum) ||
68+
if ((atmel->errata && atmel->errata->slow_clk_erratum) ||
6869
clk_period_ns > state->period) {
6970
new_clk = hlcdc->sys_clk;
7071
clk_freq = clk_get_rate(new_clk);
@@ -77,8 +78,8 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
7778

7879
for (pres = 0; pres <= ATMEL_HLCDC_PWMPS_MAX; pres++) {
7980
/* Errata: cannot divide by 1 on some IP revisions */
80-
if (!pres && chip->errata &&
81-
chip->errata->div1_clk_erratum)
81+
if (!pres && atmel->errata &&
82+
atmel->errata->div1_clk_erratum)
8283
continue;
8384

8485
if ((clk_period_ns << pres) >= state->period)
@@ -90,16 +91,16 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
9091

9192
pwmcfg = ATMEL_HLCDC_PWMPS(pres);
9293

93-
if (new_clk != chip->cur_clk) {
94+
if (new_clk != atmel->cur_clk) {
9495
u32 gencfg = 0;
9596
int ret;
9697

9798
ret = clk_prepare_enable(new_clk);
9899
if (ret)
99100
return ret;
100101

101-
clk_disable_unprepare(chip->cur_clk);
102-
chip->cur_clk = new_clk;
102+
clk_disable_unprepare(atmel->cur_clk);
103+
atmel->cur_clk = new_clk;
103104

104105
if (new_clk == hlcdc->sys_clk)
105106
gencfg = ATMEL_HLCDC_CLKPWMSEL;
@@ -160,8 +161,8 @@ static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
160161
if (ret)
161162
return ret;
162163

163-
clk_disable_unprepare(chip->cur_clk);
164-
chip->cur_clk = NULL;
164+
clk_disable_unprepare(atmel->cur_clk);
165+
atmel->cur_clk = NULL;
165166
}
166167

167168
return 0;
@@ -183,31 +184,32 @@ static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_sama5d3_errata = {
183184
#ifdef CONFIG_PM_SLEEP
184185
static int atmel_hlcdc_pwm_suspend(struct device *dev)
185186
{
186-
struct atmel_hlcdc_pwm *chip = dev_get_drvdata(dev);
187+
struct atmel_hlcdc_pwm *atmel = dev_get_drvdata(dev);
187188

188189
/* Keep the periph clock enabled if the PWM is still running. */
189-
if (pwm_is_enabled(&chip->chip.pwms[0]))
190-
clk_disable_unprepare(chip->hlcdc->periph_clk);
190+
if (pwm_is_enabled(&atmel->chip.pwms[0]))
191+
clk_disable_unprepare(atmel->hlcdc->periph_clk);
191192

192193
return 0;
193194
}
194195

195196
static int atmel_hlcdc_pwm_resume(struct device *dev)
196197
{
197-
struct atmel_hlcdc_pwm *chip = dev_get_drvdata(dev);
198+
struct atmel_hlcdc_pwm *atmel = dev_get_drvdata(dev);
198199
struct pwm_state state;
199200
int ret;
200201

201-
pwm_get_state(&chip->chip.pwms[0], &state);
202+
pwm_get_state(&atmel->chip.pwms[0], &state);
202203

203204
/* Re-enable the periph clock it was stopped during suspend. */
204205
if (!state.enabled) {
205-
ret = clk_prepare_enable(chip->hlcdc->periph_clk);
206+
ret = clk_prepare_enable(atmel->hlcdc->periph_clk);
206207
if (ret)
207208
return ret;
208209
}
209210

210-
return atmel_hlcdc_pwm_apply(&chip->chip, &chip->chip.pwms[0], &state);
211+
return atmel_hlcdc_pwm_apply(&atmel->chip, &atmel->chip.pwms[0],
212+
&state);
211213
}
212214
#endif
213215

@@ -244,14 +246,14 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
244246
{
245247
const struct of_device_id *match;
246248
struct device *dev = &pdev->dev;
247-
struct atmel_hlcdc_pwm *chip;
249+
struct atmel_hlcdc_pwm *atmel;
248250
struct atmel_hlcdc *hlcdc;
249251
int ret;
250252

251253
hlcdc = dev_get_drvdata(dev->parent);
252254

253-
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
254-
if (!chip)
255+
atmel = devm_kzalloc(dev, sizeof(*atmel), GFP_KERNEL);
256+
if (!atmel)
255257
return -ENOMEM;
256258

257259
ret = clk_prepare_enable(hlcdc->periph_clk);
@@ -260,31 +262,31 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
260262

261263
match = of_match_node(atmel_hlcdc_dt_ids, dev->parent->of_node);
262264
if (match)
263-
chip->errata = match->data;
265+
atmel->errata = match->data;
264266

265-
chip->hlcdc = hlcdc;
266-
chip->chip.ops = &atmel_hlcdc_pwm_ops;
267-
chip->chip.dev = dev;
268-
chip->chip.npwm = 1;
267+
atmel->hlcdc = hlcdc;
268+
atmel->chip.ops = &atmel_hlcdc_pwm_ops;
269+
atmel->chip.dev = dev;
270+
atmel->chip.npwm = 1;
269271

270-
ret = pwmchip_add(&chip->chip);
272+
ret = pwmchip_add(&atmel->chip);
271273
if (ret) {
272274
clk_disable_unprepare(hlcdc->periph_clk);
273275
return ret;
274276
}
275277

276-
platform_set_drvdata(pdev, chip);
278+
platform_set_drvdata(pdev, atmel);
277279

278280
return 0;
279281
}
280282

281283
static void atmel_hlcdc_pwm_remove(struct platform_device *pdev)
282284
{
283-
struct atmel_hlcdc_pwm *chip = platform_get_drvdata(pdev);
285+
struct atmel_hlcdc_pwm *atmel = platform_get_drvdata(pdev);
284286

285-
pwmchip_remove(&chip->chip);
287+
pwmchip_remove(&atmel->chip);
286288

287-
clk_disable_unprepare(chip->hlcdc->periph_clk);
289+
clk_disable_unprepare(atmel->hlcdc->periph_clk);
288290
}
289291

290292
static const struct of_device_id atmel_hlcdc_pwm_dt_ids[] = {

0 commit comments

Comments
 (0)