Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751425AbcCVRFG (ORCPT ); Tue, 22 Mar 2016 13:05:06 -0400 Received: from smtpo.poczta.interia.pl ([217.74.65.208]:49511 "EHLO smtpo.poczta.interia.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005AbcCVRE5 (ORCPT ); Tue, 22 Mar 2016 13:04:57 -0400 X-Interia-R: Interia X-Interia-R-IP: 188.121.17.172 X-Interia-R-Helo: Date: Tue, 22 Mar 2016 18:05:39 +0100 From: Slawomir Stepien To: Joachim Eastwood Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v4] iio: potentiometer: add driver for Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Message-ID: <20160322170538.GB871@x220> References: <20160322154455.GA871@x220> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Interia-Antivirus: OK Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3594 Lines: 122 On Mar 22, 2016 17:10, Joachim Eastwood wrote: > Hi Slawomir, > > On 22 March 2016 at 16:44, Slawomir Stepien wrote: > > The following functionalities are supported: > > - write, read from volatile memory > > > > Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf > > > > Signed-off-by: Slawomir Stepien > > --- > > > +#include > > +#include > > +#include > > + > > +#include > > Give that you use that you have a some OF stuff in your driver you > should also include . Same goes for . > I am sure this builds fine without those includes, but you should > explicitly include stuff that you use. Oh yes that's true. > While you're at it you could also put the includes in alphabetic order. OK > > +static int mcp4131_read_raw(struct iio_dev *indio_dev, > > + struct iio_chan_spec const *chan, > > + int *val, int *val2, long mask) > > +{ > > + int err; > > + struct mcp4131_data *data = iio_priv(indio_dev); > > + int address = chan->channel; > > + > > + switch (mask) { > > + case IIO_CHAN_INFO_RAW: > > + mutex_lock(&data->lock); > > + > > + data->buf[0] = (address << MCP4131_WIPER_SHIFT) | MCP4131_READ; > > + data->buf[1] = 0; > > + > > + err = mcp4131_read(data->spi, data->buf, 2); > > + if (err) { > > + mutex_unlock(&data->lock); > > + return err; > > + } > > + > > + /* Error, bad address/command combination */ > > + if (!MCP4131_CMDERR(data->buf)) > > + return -EIO; > > Missing mutex unlock here. Oh ;) I'll fix that. > > + > > + *val = MCP4131_RAW(data->buf); > > + mutex_unlock(&data->lock); > > + > > + return IIO_VAL_INT; > > + > > + case IIO_CHAN_INFO_SCALE: > > + *val = 1000 * data->cfg->kohms; > > + *val2 = data->cfg->max_pos; > > + return IIO_VAL_FRACTIONAL; > > + } > > + > > + return -EINVAL; > > +} > > + > > +static int mcp4131_write_raw(struct iio_dev *indio_dev, > > + struct iio_chan_spec const *chan, > > + int val, int val2, long mask) > > +{ > > + int err; > > + struct mcp4131_data *data = iio_priv(indio_dev); > > + int address = chan->channel << MCP4131_WIPER_SHIFT; > > + > > + switch (mask) { > > + case IIO_CHAN_INFO_RAW: > > + if (val > data->cfg->max_pos || val < 0) > > + return -EINVAL; > > + break; > > + > > + default: > > + return -EINVAL; > > + } > > + > > + mutex_lock(&data->lock); > > + > > + data->buf[0] = address << MCP4131_WIPER_SHIFT; > > + data->buf[0] |= MCP4131_WRITE | (val >> 8); > > + data->buf[1] = val & 0xFF; /* 8 bits here */ > > + > > + err = spi_write(data->spi, data->buf, 2); > > + if (err) { > > + mutex_unlock(&data->lock); > > + return err; > > + } > > + mutex_unlock(&data->lock); > > + > > + return 0; > > This last part could be written as: > err = spi_write(data->spi, data->buf, 2); > mutex_unlock(&data->lock); > > return err; OK > Other than the things I noted driver looks good to me. > > > regards, > Joachim Eastwood -- Slawomir Stepien