Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752437AbdDJUEI (ORCPT ); Mon, 10 Apr 2017 16:04:08 -0400 Received: from mail-io0-f181.google.com ([209.85.223.181]:33622 "EHLO mail-io0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752040AbdDJUEG (ORCPT ); Mon, 10 Apr 2017 16:04:06 -0400 MIME-Version: 1.0 In-Reply-To: <1491397671-14675-2-git-send-email-michael.hennerich@analog.com> References: <1491397671-14675-1-git-send-email-michael.hennerich@analog.com> <1491397671-14675-2-git-send-email-michael.hennerich@analog.com> From: Linus Walleij Date: Mon, 10 Apr 2017 22:04:04 +0200 Message-ID: Subject: Re: [PATCH v4 2/2] i2c: mux: ltc4306: LTC4306 and LTC4305 I2C multiplexer/switch To: Michael Hennerich Cc: Wolfram Sang , Peter Rosin , Rob Herring , Mark Rutland , "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-gpio@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2841 Lines: 90 On Wed, Apr 5, 2017 at 3:07 PM, wrote: > From: Michael Hennerich > > This patch adds support for the Analog Devices / Linear Technology > LTC4306 and LTC4305 4/2 Channel I2C Bus Multiplexer/Switches. > The LTC4306 optionally provides two general purpose input/output pins > (GPIOs) that can be configured as logic inputs, opendrain outputs or > push-pull outputs via the generic GPIOLIB framework. > > Signed-off-by: Michael Hennerich Okay! > +#include > +#include > +#include > +#include Why are you including all these? Normally a GPIO driver should just include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +static int ltc4306_gpio_get(struct gpio_chip *chip, unsigned int offset) > +{ > + struct ltc4306 *data = gpiochip_get_data(chip); > + unsigned int val; > + int ret; > + > + ret = regmap_read(data->regmap, LTC_REG_CONFIG, &val); > + if (ret < 0) > + return ret; > + > + return (val & BIT(1 - offset)); Do this: return !!(val & BIT(1 - offset)); So you clamp the return value to [0,1] > +static int ltc4306_gpio_set_config(struct gpio_chip *chip, > + unsigned int offset, unsigned long config) > +{ > + struct ltc4306 *data = gpiochip_get_data(chip); > + unsigned int val; > + > + switch (pinconf_to_config_param(config)) { > + case PIN_CONFIG_DRIVE_OPEN_DRAIN: > + val = 0; > + break; > + case PIN_CONFIG_DRIVE_PUSH_PULL: > + val = BIT(4 - offset); > + break; > + default: > + return -ENOTSUPP; > + } > + > + return regmap_update_bits(data->regmap, LTC_REG_MODE, > + BIT(4 - offset), val); > +} Nice! > + data->gpiochip.label = dev_name(dev); > + data->gpiochip.base = -1; > + data->gpiochip.ngpio = data->chip->num_gpios; > + data->gpiochip.parent = dev; > + data->gpiochip.can_sleep = true; > + data->gpiochip.direction_input = ltc4306_gpio_direction_input; > + data->gpiochip.direction_output = ltc4306_gpio_direction_output; > + data->gpiochip.get = ltc4306_gpio_get; > + data->gpiochip.set = ltc4306_gpio_set; > + data->gpiochip.set_config = ltc4306_gpio_set_config; > + data->gpiochip.owner = THIS_MODULE; Please implement .get_direction(). This is very helpful to userspace, have you tested to use tools/gpio/* from the kernel? Like lsgpio? Yours, Linus Walleij