Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1515522
| From | Linus Walleij <linus.walleij@linaro.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v4 2/6] Add Advantech iManager GPIO driver |
| Date | 2016-11-05 09:40 +0100 |
| Message-ID | <sA4G5-5zz-3@gated-at.bofh.it> (permalink) |
| References | <syZfr-3TD-3@gated-at.bofh.it> <syZp7-3X5-15@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v4 0/6] Advantech iManager EC driver set Richard Vidal-Dorsch <richard.dorsch@gmail.com> - 2016-11-02 09:40 +0100
[PATCH v4 6/6] Add Advantech iManager Watchdog driver Richard Vidal-Dorsch <richard.dorsch@gmail.com> - 2016-11-02 09:40 +0100
[PATCH v4 5/6] Add Advantech iManager Backlight driver Richard Vidal-Dorsch <richard.dorsch@gmail.com> - 2016-11-02 09:50 +0100
[PATCH v4 2/6] Add Advantech iManager GPIO driver Richard Vidal-Dorsch <richard.dorsch@gmail.com> - 2016-11-02 09:50 +0100
Re: [PATCH v4 2/6] Add Advantech iManager GPIO driver Linus Walleij <linus.walleij@linaro.org> - 2016-11-05 09:40 +0100
[PATCH v4 4/6] Add Advantech iManager I2C driver Richard Vidal-Dorsch <richard.dorsch@gmail.com> - 2016-11-02 09:50 +0100
Re: [PATCH v4 1/6] Add Advantech iManager MFD core driver Lee Jones <lee.jones@linaro.org> - 2016-11-03 09:40 +0100
csiph-web