Thread (9 messages) 9 messages, 3 authors, 2016-11-05

Re: [PATCH v4 2/6] Add Advantech iManager GPIO driver

From: Linus Walleij <hidden>
Date: 2016-11-05 08:29:34
Also in: linux-gpio, linux-hwmon, linux-i2c, linux-watchdog, lkml

On Wed, Nov 2, 2016 at 9:37 AM, Richard Vidal-Dorsch
[off-list ref] wrote:
Signed-off-by: Richard Vidal-Dorsch <redacted>
+#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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help