linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Gregory Bean <gbean@codeaurora.org>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Joe Perches <joe@perches.com>,
	"David S. Miller" <davem@davemloft.net>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Randy Dunlap <randy.dunlap@oracle.com>,
	Michael Hennerich <michael.hennerich@analog.com>,
	Mike Frysinger <vapier@gentoo.org>,
	David Brown <davidb@codeaurora.org>,
	Daniel Walker <dwalker@codeaurora.org>,
	Bryan Huntsman <bryanh@codeaurora.org>
Subject: Re: [PATCH 1/2 v2] gpio: msm7200a: Add gpiolib support for MSM chips.
Date: Tue, 15 Jun 2010 13:01:31 -0700	[thread overview]
Message-ID: <20100615130131.bf20833a.akpm@linux-foundation.org> (raw)
In-Reply-To: <1276301969-31385-2-git-send-email-gbean@codeaurora.org>

On Fri, 11 Jun 2010 17:19:28 -0700
Gregory Bean <gbean@codeaurora.org> wrote:

> Add support for uniprocessor MSM chips whose TLMM/GPIO design
> is the same as the MSM7200A.
> This includes, but is not necessarily limited to, the:
> MSM7200A, MSM7x25, MSM7x27, MSM7x30, QSD8x50, QSD8x50A
> 
>
> ...
>
> +static inline unsigned bit(unsigned offset)
> +{
> +	BUG_ON(offset >= sizeof(unsigned) * 8);
> +	return 1U << offset;
> +}

Could use bitops.h's BIT(), but it hardly matters.

> +/*
> + * This function assumes that msm_gpio_dev::lock is held.
> + */
> +static inline void set_gpio_bit(unsigned n, void __iomem *reg)
> +{
> +	writel(readl(reg) | bit(n), reg);
> +}
> +
> +/*
> + * This function assumes that msm_gpio_dev::lock is held.
> + */
> +static inline void clr_gpio_bit(unsigned n, void __iomem *reg)
> +{
> +	writel(readl(reg) & ~bit(n), reg);
> +}
> +
> +/*
> + * This function assumes that msm_gpio_dev::lock is held.
> + */
> +static inline void
> +msm_gpio_write(struct msm_gpio_dev *dev, unsigned n, unsigned on)
> +{
> +	if (on)
> +		set_gpio_bit(n, dev->regs.out);
> +	else
> +		clr_gpio_bit(n, dev->regs.out);
> +}

Recent gcc's often uninline things whcih were marked inline.  Doesn't
matter much.

>
> ...
>
> +static int gpio_chip_get(struct gpio_chip *chip, unsigned offset)
> +{
> +	struct msm_gpio_dev *msm_gpio = TO_MSM_GPIO_DEV(chip);
> +	unsigned long irq_flags;
> +	int ret;
> +
> +	spin_lock_irqsave(&msm_gpio->lock, irq_flags);
> +	ret = readl(msm_gpio->regs.in) & bit(offset) ? 1 : 0;
> +	spin_unlock_irqrestore(&msm_gpio->lock, irq_flags);
> +
> +	return ret;
> +}

The locking here is actually unneeded, I expect.

> +static void gpio_chip_set(struct gpio_chip *chip, unsigned offset, int value)
> +{
> +	struct msm_gpio_dev *msm_gpio = TO_MSM_GPIO_DEV(chip);
> +	unsigned long irq_flags;
> +
> +	spin_lock_irqsave(&msm_gpio->lock, irq_flags);
> +	msm_gpio_write(msm_gpio, offset, value);
> +	spin_unlock_irqrestore(&msm_gpio->lock, irq_flags);
> +}
> +
> +static int msm_gpio_probe(struct platform_device *dev)
> +{
> +	struct msm_gpio_dev *msm_gpio;
> +	struct msm7200a_gpio_platform_data *pdata =
> +		(struct msm7200a_gpio_platform_data *)dev->dev.platform_data;

The the typecast of a void* is unneeded and undesirable because it
defeats typechecking.

> +	int ret;
> +
> +	if (!pdata)
> +		return -EINVAL;
> +
> +	msm_gpio = kzalloc(sizeof(struct msm_gpio_dev), GFP_KERNEL);
> +	if (!msm_gpio)
> +		return -ENOMEM;
> +
> +	spin_lock_init(&msm_gpio->lock);
> +	platform_set_drvdata(dev, msm_gpio);
> +	memcpy(&msm_gpio->regs,
> +	       &pdata->regs,
> +	       sizeof(struct msm7200a_gpio_regs));
> +
> +	msm_gpio->gpio_chip.label            = dev->name;
> +	msm_gpio->gpio_chip.base             = pdata->gpio_base;
> +	msm_gpio->gpio_chip.ngpio            = pdata->ngpio;
> +	msm_gpio->gpio_chip.direction_input  = gpio_chip_direction_input;
> +	msm_gpio->gpio_chip.direction_output = gpio_chip_direction_output;
> +	msm_gpio->gpio_chip.get              = gpio_chip_get;
> +	msm_gpio->gpio_chip.set              = gpio_chip_set;
> +
> +	ret = gpiochip_add(&msm_gpio->gpio_chip);
> +	if (ret < 0)
> +		goto err_post_malloc;
> +
> +	return ret;
> +err_post_malloc:
> +	kfree(msm_gpio);

Maybe undo platform_set_drvdata() here?

> +	return ret;
> +}
> +
>
> ...
>


  reply	other threads:[~2010-06-15 20:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-12  0:19 [PATCH 0/2 v2] gpio: msm7200a: Add gpiolib support for MSM chips Gregory Bean
2010-06-12  0:19 ` [PATCH 1/2 " Gregory Bean
2010-06-15 20:01   ` Andrew Morton [this message]
2010-06-12  0:19 ` [PATCH 2/2 v2] gpio: msm7200a: Add irq support to msm-gpiolib Gregory Bean
2010-06-15 20:12   ` Andrew Morton

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=20100615130131.bf20833a.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=bryanh@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=davidb@codeaurora.org \
    --cc=dwalker@codeaurora.org \
    --cc=gbean@codeaurora.org \
    --cc=joe@perches.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=randy.dunlap@oracle.com \
    --cc=sameo@linux.intel.com \
    --cc=vapier@gentoo.org \
    /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).