On Wed, Nov 2, 2016 at 9:37 AM, Richard Vidal-Dorsch <richard.dorsch@xxxxxxxxx> wrote: > Signed-off-by: Richard Vidal-Dorsch <richard.dorsch@xxxxxxxxx> > +#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 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html