linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Bart Tanghe <bart.tanghe@thomasmore.be>, thierry.reding@gmail.com
Cc: matt.porter@linaro.org, linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH v6]pwm: add BCM2835 PWM driver
Date: Tue, 07 Oct 2014 16:14:41 +0200	[thread overview]
Message-ID: <5433F551.7090507@pengutronix.de> (raw)
In-Reply-To: <1412690665-15416-1-git-send-email-bart.tanghe@thomasmore.be>

[-- Attachment #1: Type: text/plain, Size: 3128 bytes --]

On 10/07/2014 04:04 PM, Bart Tanghe wrote:
> Add pwm driver for Broadcom BCM2835 processor (Raspberry Pi)

> --- /dev/null
> +++ b/drivers/pwm/pwm-bcm2835.c
> @@ -0,0 +1,201 @@
> +/*
> + * Copyright 2014 Bart Tanghe <bart.tanghe@thomasmore.be>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/pwm.h>
> +
> +#define DUTY		0x14
> +#define PERIOD		0x10
> +#define CHANNEL	0x10
> +
> +#define PWM_ENABLE	(1 << 0)
> +#define PWM_POLARITY	(1 << 4)
> +
> +#define PWM_CONTROL_MASK	0xff
> +#define PWM_MODE		0x80		/* set timer in pwm mode */
> +#define DEFAULT		0xff		/* set timer in default mode */
> +#define PWM_CONTROL_STRIDE	8
> +#define MIN_PERIOD		108		/* 9.2Mhz max pwm clock */
> +
> +struct bcm2835_pwm {
> +	struct pwm_chip chip;
> +	struct device *dev;
> +	int channel;
> +	unsigned long scaler;
> +	void __iomem *base;
> +	struct clk *clk;
> +};
> +
> +static inline struct bcm2835_pwm  *to_bcm2835_pwm(struct pwm_chip *chip)
                                   ^^
nitpick: on space is enough

> +{
> +	return container_of(chip, struct bcm2835_pwm, chip);
> +}
> +

[...]

> +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 = devm_clk_get(&pdev->dev, NULL);
> +	if (IS_ERR(clk)) {
> +		dev_err(&pdev->dev, "no clock found: %ld\n", PTR_ERR(clk));
> +		return PTR_ERR(clk);
> +	}
> +
> +	pwm->clk = clk;
> +	ret = clk_prepare_enable(pwm->clk);
> +	if (ret) {
> +		clk_disable_unprepare(pwm->clk);

If enabling of the clock fails, don't disable it.

> +		return ret;
> +	}
> +
> +	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);

Here you should disable the clock instead.

> +
> +	pwm->chip.dev = &pdev->dev;
> +	pwm->chip.ops = &bcm2835_pwm_ops;
> +	pwm->chip.npwm = 2;
> +
> +	platform_set_drvdata(pdev, pwm);
> +
> +	ret = pwmchip_add(&pwm->chip);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
> +		return ret;

and here....or better introduce a disable_clock jump-label at end of
this function.

> +	}
> +	return 0;
> +}

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   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2014-10-07 14:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 14:04 [PATCH v6]pwm: add BCM2835 PWM driver Bart Tanghe
2014-10-07 14:14 ` Marc Kleine-Budde [this message]
2014-10-07 15:35 ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5433F551.7090507@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=bart.tanghe@thomasmore.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=matt.porter@linaro.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).