linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Richard Vidal-Dorsch <richard.dorsch@gmail.com>
Cc: Alexandre Courbot <gnurou@gmail.com>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Wolfram Sang <wsa@the-dreams.de>,
	Lee Jones <lee.jones@linaro.org>,
	Jingoo Han <jingoohan1@gmail.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Wim Van Sebroeck <wim@iguana.be>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	linux-hwmon@vger.kernel.org,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	"linux-fbdev@vger.kernel.org" <linux-fbdev@vger.kernel.org>,
	linux-watchdog@vger.kernel.org,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>,
	jo.sunga@advantech.com, weilun.huang@advantech.com,
	andrew.chou@advantech.com
Subject: Re: [PATCH v4 2/6] Add Advantech iManager GPIO driver
Date: Sat, 5 Nov 2016 09:29:29 +0100	[thread overview]
Message-ID: <CACRpkdZfegDfpV-qK8FkvRnCWZQT8R3CkB_t7r+pyNhQ3_hHpA@mail.gmail.com> (raw)
In-Reply-To: <20161102083751.6335-3-richard.dorsch@gmail.com>

On Wed, Nov 2, 2016 at 9:37 AM, Richard Vidal-Dorsch
<richard.dorsch@gmail.com> wrote:

> Signed-off-by: Richard Vidal-Dorsch <richard.dorsch@gmail.com>

> +#include <linux/device.h>
> +#include <linux/gpio.h>

#include <linux/gpio/driver.h>
should be enough.

> +#include <linux/init.h>
> +#include <linux/mfd/imanager.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +
> +#define EC_GPIOF_DIR_OUT       BIT(6)
> +#define EC_GPIOF_DIR_IN                BIT(7)
> +
> +struct imanager_gpio_data {
> +       struct imanager_device_data *imgr;
> +       struct gpio_chip chip;
> +};

Maybe some kerneldoc for this. Not necessary though since its sort of
self-explanatory.

> +static int imanager_gpio_direction_in(struct gpio_chip *chip, uint offset)
> +{
> +       struct imanager_gpio_data *data = gpiochip_get_data(chip);
> +       struct imanager_device_data *imgr = data->imgr;
> +       struct imanager_device_attribute *attr = imgr->ec.gpio.attr[offset];
> +
> +       mutex_lock(&imgr->lock);
> +       imanager_write8(&imgr->ec, EC_CMD_GPIO_DIR_WR, attr->did,
> +                       EC_GPIOF_DIR_IN);
> +       mutex_unlock(&imgr->lock);

It kind of looks like it would be smarter if the imanager_write8() was
taking and releasing the lock so you don't have to do it everywhere.

> +static int imanager_gpio_get_direction(struct gpio_chip *chip, uint offset)
> +{
> +       struct imanager_gpio_data *data = gpiochip_get_data(chip);
> +       struct imanager_device_data *imgr = data->imgr;
> +       struct imanager_device_attribute *attr = imgr->ec.gpio.attr[offset];
> +       int ret;
> +
> +       mutex_lock(&imgr->lock);
> +       ret = imanager_read8(&imgr->ec, EC_CMD_GPIO_DIR_RD, attr->did);
> +       mutex_unlock(&imgr->lock);
> +
> +       return ret & EC_GPIOF_DIR_IN ? GPIOF_DIR_IN : GPIOF_DIR_OUT;

Don't use GPIOF* flags, those are for consumers. Just return 0/1.

> +static int imanager_gpio_get(struct gpio_chip *chip, uint offset)
> +{
> +       struct imanager_gpio_data *data = gpiochip_get_data(chip);
> +       struct imanager_device_data *imgr = data->imgr;
> +       struct imanager_device_attribute *attr = imgr->ec.gpio.attr[offset];
> +       int ret;
> +
> +       mutex_lock(&imgr->lock);
> +       ret = imanager_read8(&imgr->ec, EC_CMD_HWP_RD, attr->did);
> +       mutex_unlock(&imgr->lock);
> +
> +       return ret;
> +}

Can the read function return an error code? In that case it should be checked
everywhere.

Also be sure to clamp ret like this:

return !!ret;

Apart from this it looks good.

Yours,
Linus Walleij

  reply	other threads:[~2016-11-05  8:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02  8:37 [PATCH v4 0/6] Advantech iManager EC driver set Richard Vidal-Dorsch
2016-11-02  8:37 ` [PATCH v4 1/6] Add Advantech iManager MFD core driver Richard Vidal-Dorsch
2016-11-03  8:41   ` Lee Jones
2016-11-02  8:37 ` [PATCH v4 2/6] Add Advantech iManager GPIO driver Richard Vidal-Dorsch
2016-11-05  8:29   ` Linus Walleij [this message]
2016-11-02  8:37 ` [PATCH v4 3/6] Add Advantech iManager HWmon driver Richard Vidal-Dorsch
2016-11-02  8:37 ` [PATCH v4 4/6] Add Advantech iManager I2C driver Richard Vidal-Dorsch
2016-11-02  8:37 ` [PATCH v4 5/6] Add Advantech iManager Backlight driver Richard Vidal-Dorsch
2016-11-02  8:37 ` [PATCH v4 6/6] Add Advantech iManager Watchdog driver Richard Vidal-Dorsch

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=CACRpkdZfegDfpV-qK8FkvRnCWZQT8R3CkB_t7r+pyNhQ3_hHpA@mail.gmail.com \
    --to=linus.walleij@linaro.org \
    --cc=andrew.chou@advantech.com \
    --cc=gnurou@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=jingoohan1@gmail.com \
    --cc=jo.sunga@advantech.com \
    --cc=k.kozlowski@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=richard.dorsch@gmail.com \
    --cc=tomi.valkeinen@ti.com \
    --cc=weilun.huang@advantech.com \
    --cc=wim@iguana.be \
    --cc=wsa@the-dreams.de \
    /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).