linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: s.abhisit@gmail.com
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [PATCH 4/5] gpio: Add support for LMP92001 GPIO
Date: Mon, 7 Aug 2017 11:15:18 +0200	[thread overview]
Message-ID: <CACRpkdZgWM6OJzoKhE2O5FATgkDwrRvuCSQZ2=szObTrF_c7RQ@mail.gmail.com> (raw)
In-Reply-To: <1501578947-4692-1-git-send-email-s.abhisit@gmail.com>

On Tue, Aug 1, 2017 at 11:15 AM,  <s.abhisit@gmail.com> wrote:

> From: Abhisit Sangjan <s.abhisit@gmail.com>

That is a bit terse commit message for an entire new driver.
Elaborate some please.

> +#include <linux/gpio.h>

#include <linux/gpio/driver.h>

ONLY please.

> +#include <linux/platform_device.h>
> +#include <linux/seq_file.h>
> +#include <linux/mfd/core.h>
> +#include <linux/version.h>

Why? Supporting old kernels? We don't do that upstream.

Add this:
#include <linux/bitops.h>

(See below)

> +static inline struct lmp92001_gpio *to_lmp92001_gpio(struct gpio_chip *chip)
> +{
> +        return container_of(chip, struct lmp92001_gpio, gpio_chip);
> +}

Do not use this. Use the new devm_gpiochip_add_data() and pass a state container
as you data pointer.

> +
> +static int lmp92001_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
> +{
> +        struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip);

Then use this:
struct lmp92001_gpio *lmp92001_gpio = gpiochip_get_data(chip);

> +        return (val >> offset) & 1;

Do this:

return !!(val &BIT(offset));

> +static int lmp92001_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
> +{
> +        struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip);
> +        struct lmp92001 *lmp92001 =  lmp92001_gpio->lmp92001;
> +
> +        return regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, 1 << offset,
> +                        1 << offset);

return regmap_update_bits(lmp92001->regmap, LMP92001_CGPO,
BIT(offset), BIT(offset));

But seriously: why do you need to mask the bit even?

return regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, 0, BIT(offset));

should work shouldn't it?

Use the bitops BIT() and state container gpiochip_get_data() and resend
and I will look at more details.

Yours,
Linus Walleij

      reply	other threads:[~2017-08-07  9:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01  9:15 [PATCH 4/5] gpio: Add support for LMP92001 GPIO s.abhisit
2017-08-07  9:15 ` Linus Walleij [this message]

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='CACRpkdZgWM6OJzoKhE2O5FATgkDwrRvuCSQZ2=szObTrF_c7RQ@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.abhisit@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).