[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACRpkdZfegDfpV-qK8FkvRnCWZQT8R3CkB_t7r+pyNhQ3_hHpA@mail.gmail.com>
Date: Sat, 5 Nov 2016 09:29:29 +0100
From: Linus Walleij <linus.walleij@...aro.org>
To: Richard Vidal-Dorsch <richard.dorsch@...il.com>
Cc: Alexandre Courbot <gnurou@...il.com>,
Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>,
Wolfram Sang <wsa@...-dreams.de>,
Lee Jones <lee.jones@...aro.org>,
Jingoo Han <jingoohan1@...il.com>,
Tomi Valkeinen <tomi.valkeinen@...com>,
Wim Van Sebroeck <wim@...ana.be>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-gpio@...r.kernel.org" <linux-gpio@...r.kernel.org>,
linux-hwmon@...r.kernel.org,
"linux-i2c@...r.kernel.org" <linux-i2c@...r.kernel.org>,
"linux-fbdev@...r.kernel.org" <linux-fbdev@...r.kernel.org>,
linux-watchdog@...r.kernel.org,
Krzysztof Kozlowski <k.kozlowski@...sung.com>,
jo.sunga@...antech.com, weilun.huang@...antech.com,
andrew.chou@...antech.com
Subject: Re: [PATCH v4 2/6] Add Advantech iManager GPIO driver
On Wed, Nov 2, 2016 at 9:37 AM, Richard Vidal-Dorsch
<richard.dorsch@...il.com> wrote:
> Signed-off-by: Richard Vidal-Dorsch <richard.dorsch@...il.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
Powered by blists - more mailing lists