Skip to content

Commit 8a2ba6f

Browse files
committed
Merge tag 'pwm/for-6.16-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux
Pull pwm fixes from Uwe Kleine-König: "axi-pwmgen: Fix handling of external clock The pwm-axi-pwmgen device is backed by an FPGA and can be synthesized in different ways. Relevant here is that it can use one or two external clock signals. These fix clock handling for the two clocks case" * tag 'pwm/for-6.16-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux: pwm: axi-pwmgen: fix missing separate external clock dt-bindings: pwm: adi,axi-pwmgen: Fix clocks
2 parents 6d88542 + a8841dc commit 8a2ba6f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

Documentation/devicetree/bindings/pwm/adi,axi-pwmgen.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ properties:
3030
const: 3
3131

3232
clocks:
33-
maxItems: 1
33+
minItems: 1
34+
maxItems: 2
35+
36+
clock-names:
37+
minItems: 1
38+
items:
39+
- const: axi
40+
- const: ext
3441

3542
required:
3643
- reg
3744
- clocks
45+
- clock-names
3846

3947
unevaluatedProperties: false
4048

@@ -43,6 +51,7 @@ examples:
4351
pwm@44b00000 {
4452
compatible = "adi,axi-pwmgen-2.00.a";
4553
reg = <0x44b00000 0x1000>;
46-
clocks = <&spi_clk>;
54+
clocks = <&fpga_clk>, <&spi_clk>;
55+
clock-names = "axi", "ext";
4756
#pwm-cells = <3>;
4857
};

drivers/pwm/pwm-axi-pwmgen.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int axi_pwmgen_probe(struct platform_device *pdev)
257257
struct regmap *regmap;
258258
struct pwm_chip *chip;
259259
struct axi_pwmgen_ddata *ddata;
260-
struct clk *clk;
260+
struct clk *axi_clk, *clk;
261261
void __iomem *io_base;
262262
int ret;
263263

@@ -280,9 +280,26 @@ static int axi_pwmgen_probe(struct platform_device *pdev)
280280
ddata = pwmchip_get_drvdata(chip);
281281
ddata->regmap = regmap;
282282

283-
clk = devm_clk_get_enabled(dev, NULL);
283+
/*
284+
* Using NULL here instead of "axi" for backwards compatibility. There
285+
* are some dtbs that don't give clock-names and have the "ext" clock
286+
* as the one and only clock (due to mistake in the original bindings).
287+
*/
288+
axi_clk = devm_clk_get_enabled(dev, NULL);
289+
if (IS_ERR(axi_clk))
290+
return dev_err_probe(dev, PTR_ERR(axi_clk), "failed to get axi clock\n");
291+
292+
clk = devm_clk_get_optional_enabled(dev, "ext");
284293
if (IS_ERR(clk))
285-
return dev_err_probe(dev, PTR_ERR(clk), "failed to get clock\n");
294+
return dev_err_probe(dev, PTR_ERR(clk), "failed to get ext clock\n");
295+
296+
/*
297+
* If there is no "ext" clock, it means the HDL was compiled with
298+
* ASYNC_CLK_EN=0. In this case, the AXI clock is also used for the
299+
* PWM output clock.
300+
*/
301+
if (!clk)
302+
clk = axi_clk;
286303

287304
ret = devm_clk_rate_exclusive_get(dev, clk);
288305
if (ret)

0 commit comments

Comments
 (0)