On 12/02/2022 17:23, Nikita Travkin wrote: > Some systems have clocks exposed to external devices. If the clock > controller supports duty-cycle configuration, such clocks can be used as > pwm outputs. In fact PWM and CLK subsystems are interfaced with in a > similar way and an "opposite" driver already exists (clk-pwm). Add a > driver that would enable pwm devices to be used via clk subsystem. > > Signed-off-by: Nikita Travkin <nikita@xxxxxxx> > -- > (...) > + > +static int pwm_clk_probe(struct platform_device *pdev) > +{ > + struct pwm_clk_chip *chip; > + int ret; > + > + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); > + if (!chip) > + return -ENOMEM; > + > + chip->clk = devm_clk_get(&pdev->dev, NULL); > + if (IS_ERR(chip->clk)) > + return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk), > + "Failed to get clock\n"); > + > + chip->chip.dev = &pdev->dev; > + chip->chip.ops = &pwm_clk_ops; > + chip->chip.npwm = 1; > + > + ret = clk_prepare(chip->clk); > + if (ret < 0) > + return dev_err_probe(&pdev->dev, ret, "Failed to prepare clock\n"); > + > + ret = pwmchip_add(&chip->chip); > + if (ret < 0) > + return dev_err_probe(&pdev->dev, ret, "Failed to add pwm chip\n"); You need to cleanup - unprepare the clock. > + > + platform_set_drvdata(pdev, chip); > + return 0; > +} > + Best regards, Krzysztof