Re: [PATCH 4/5] gpio: Add support for LMP92001 GPIO

2017-08-07 Thread Linus Walleij
On Tue, Aug 1, 2017 at 11:15 AM,   wrote:

> From: Abhisit Sangjan 

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

> +#include 

#include 

ONLY please.

> +#include 
> +#include 
> +#include 
> +#include 

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

Add this:
#include 

(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 (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


Re: [PATCH 4/5] gpio: Add support for LMP92001 GPIO

2017-08-07 Thread Linus Walleij
On Tue, Aug 1, 2017 at 11:15 AM,   wrote:

> From: Abhisit Sangjan 

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

> +#include 

#include 

ONLY please.

> +#include 
> +#include 
> +#include 
> +#include 

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

Add this:
#include 

(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 (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