[resend rfc v4]pwm: add BCM2835 PWM driver
Marc Kleine-Budde
mkl at pengutronix.de
Mon Sep 29 08:21:27 PDT 2014
On 09/29/2014 04:40 PM, Bart Tanghe wrote:
> +static int bcm2835_pwm_probe(struct platform_device *pdev)
> +{
> + struct bcm2835_pwm *pwm;
> + int ret;
> + struct resource *r;
> + struct clk *clk;
> +
> + pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
> + if (!pwm)
> + return -ENOMEM;
> +
> + pwm->dev = &pdev->dev;
> +
> + clk = clk_get(&pdev->dev, NULL);
Better use devm_, as you don't free the clock in case of an error and
during remove()
> + if (IS_ERR(clk)) {
> + dev_err(&pdev->dev, "no clock found: %ld\n", PTR_ERR(clk));
> + return PTR_ERR(clk);
> + }
> +
> + pwm->clk = clk;
> + clk_prepare_enable(pwm->clk);
Please check the return value of clk_prepare_enable()
> + pwm->scaler = NSEC_PER_SEC / clk_get_rate(clk);
> +
> + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + pwm->base = devm_ioremap_resource(&pdev->dev, r);
> + if (IS_ERR(pwm->base))
> + return PTR_ERR(pwm->base);
> +
> + pwm->chip.dev = &pdev->dev;
> + pwm->chip.ops = &bcm2835_pwm_ops;
> + pwm->chip.npwm = 2;
> +
> + ret = pwmchip_add(&pwm->chip);
> + if (ret < 0) {
> + dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
> + return -1;
Please propagate the error vlaue:
return ret;
> + }
> + platform_set_drvdata(pdev, pwm);
Better do this before pwmchip_add()
> + return 0;
> +}
> +
> +static int bcm2835_pwm_remove(struct platform_device *pdev)
> +{
> + struct bcm2835_pwm *pc = platform_get_drvdata(pdev);
> + clk_disable_unprepare(pc->clk);
> + return pwmchip_remove(&pc->chip);
> +}
> +
> +static const struct of_device_id bcm2835_pwm_of_match[] = {
> + { .compatible = "brcm,bcm2835-pwm", },
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, bcm2835_pwm_of_match);
> +
> +static struct platform_driver bcm2835_pwm_driver = {
> + .driver = {
> + .name = "bcm2835-pwm",
> + .of_match_table = bcm2835_pwm_of_match,
> + },
> + .probe = bcm2835_pwm_probe,
> + .remove = bcm2835_pwm_remove,
> +};
> +module_platform_driver(bcm2835_pwm_driver);
> +
> +MODULE_AUTHOR("Bart Tanghe <bart.tanghe at thomasmore.be");
> +MODULE_DESCRIPTION("Broadcom BCM2835 PWM driver");
> +MODULE_LICENSE("GPL v2");
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-rpi-kernel/attachments/20140929/f443a4a2/attachment.sig>
More information about the linux-rpi-kernel
mailing list