All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andreas Klinger <ak@it-klinger.de>
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	linux-iio@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org,
	mark.rutland@arm.com, linux-i2c@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] iio: srf08: add sensor type srf10
Date: Sat, 12 Aug 2017 12:50:55 +0100	[thread overview]
Message-ID: <20170812125055.0415eaad@archlinux> (raw)
In-Reply-To: <20170802232356.GA15234@arbeit>

On Thu, 3 Aug 2017 01:23:56 +0200
Andreas Klinger <ak@it-klinger.de> wrote:

> Ultrasonic sensor srf10 is quite similar to srf08 and now also supported by
> the driver as device tree compatible string.
> 
> The most significiant difference is a different range and values of
> register gain (in the driver it's call sensitivity). Therefore the array of
> was extended.
> 
> Signed-off-by: Andreas Klinger <ak@it-klinger.de>
Minor issue inline.  Otherwise looks fine.

Jonathan
> ---
>  drivers/iio/proximity/srf08.c | 59 +++++++++++++++++++++++++++++++++++--------
>  1 file changed, 48 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
> index 49316cbf7c60..350b5b0eb64e 100644
> --- a/drivers/iio/proximity/srf08.c
> +++ b/drivers/iio/proximity/srf08.c
> @@ -30,14 +30,23 @@
>  
>  #define SRF08_CMD_RANGING_CM	0x51	/* Ranging Mode - Result in cm */
>  
> -#define SRF08_DEFAULT_GAIN	1025	/* default analogue value of Gain */
> +//#define SRF08_DEFAULT_GAIN	1025	/* default analogue value of Gain */
checkpatch.pl would have picked up on this.  Don't leave random dead code
in here...
>  #define SRF08_DEFAULT_RANGE	6020	/* default value of Range in mm */
>  
> +#define SRF08_MAX_SENSITIVITY	32	/* number of Gain Register values */
> +
> +enum srf08_sensor_type {
> +	SRF08,
> +	SRF10,
> +	SRF_MAX_TYPE
> +};
> +
>  struct srf08_data {
>  	struct i2c_client	*client;
>  	int			sensitivity;		/* Gain */
>  	int			range_mm;		/* max. Range in mm */
>  	struct mutex		lock;
> +	enum srf08_sensor_type	sensor_type;		/* Sensor-Type */
>  };
>  
>  /*
> @@ -47,11 +56,29 @@ struct srf08_data {
>   * But with ADC's this term is already used differently and that's why it
>   * is called "Sensitivity" here.
>   */
> -static const int srf08_sensitivity[] = {
> +static const int srf08_sensitivity[SRF_MAX_TYPE][SRF08_MAX_SENSITIVITY] = {
> +	/* SRF08 */
> +	{
>  	 94,  97, 100, 103, 107, 110, 114, 118,
>  	123, 128, 133, 139, 145, 152, 159, 168,
>  	177, 187, 199, 212, 227, 245, 265, 288,
> -	317, 352, 395, 450, 524, 626, 777, 1025 };
> +	317, 352, 395, 450, 524, 626, 777, 1025
> +	},
> +	/* SRF10 */
> +	{
> +	 40,  40,  50,  60,  70,  80, 100, 120,
> +	140, 200, 250, 300, 350, 400, 500, 600,
> +	700,   0,   0,   0,   0,   0,   0,   0,
> +	  0,   0,   0,   0,   0,   0,   0,   0,
> +	},
> +};
> +
> +static const int srf08_default_sensitivity[SRF_MAX_TYPE] = {
> +	/* SRF08 */
> +	1025,
> +	/* SRF10 */
> +	700,
> +};
>  
>  static int srf08_read_ranging(struct srf08_data *data)
>  {
> @@ -225,9 +252,13 @@ static ssize_t srf08_show_sensitivity_available(struct device *dev,
>  				struct device_attribute *attr, char *buf)
>  {
>  	int i, len = 0;
> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +	struct srf08_data *data = iio_priv(indio_dev);
>  
> -	for (i = 0; i < ARRAY_SIZE(srf08_sensitivity); i++)
> -		len += sprintf(buf + len, "%d ", srf08_sensitivity[i]);
> +	for (i = 0; i < SRF08_MAX_SENSITIVITY; i++)
> +		if (srf08_sensitivity[data->sensor_type][i])
> +			len += sprintf(buf + len, "%d ",
> +				srf08_sensitivity[data->sensor_type][i]);
>  
>  	len += sprintf(buf + len, "\n");
>  
> @@ -256,13 +287,16 @@ static ssize_t srf08_write_sensitivity(struct srf08_data *data,
>  	int ret, i;
>  	u8 regval;
>  
> -	for (i = 0; i < ARRAY_SIZE(srf08_sensitivity); i++)
> -		if (val == srf08_sensitivity[i]) {
> +	if (!val)
> +		return -EINVAL;
> +
> +	for (i = 0; i < SRF08_MAX_SENSITIVITY; i++)
> +		if (val == srf08_sensitivity[data->sensor_type][i]) {
>  			regval = i;
>  			break;
>  		}
>  
> -	if (i >= ARRAY_SIZE(srf08_sensitivity))
> +	if (i >= SRF08_MAX_SENSITIVITY)
>  		return -EINVAL;
>  
>  	mutex_lock(&data->lock);
> @@ -352,8 +386,9 @@ static int srf08_probe(struct i2c_client *client,
>  	data = iio_priv(indio_dev);
>  	i2c_set_clientdata(client, indio_dev);
>  	data->client = client;
> +	data->sensor_type = (enum srf08_sensor_type)id->driver_data;
>  
> -	indio_dev->name = "srf08";
> +	indio_dev->name = id->name;
>  	indio_dev->dev.parent = &client->dev;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->info = &srf08_info;
> @@ -371,7 +406,8 @@ static int srf08_probe(struct i2c_client *client,
>  	if (ret < 0)
>  		return ret;
>  
> -	ret = srf08_write_sensitivity(data, SRF08_DEFAULT_GAIN);
> +	ret = srf08_write_sensitivity(data,
> +			srf08_default_sensitivity[id->driver_data]);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -379,7 +415,8 @@ static int srf08_probe(struct i2c_client *client,
>  }
>  
>  static const struct i2c_device_id srf08_id[] = {
> -	{ "srf08", 0 },
> +	{ "srf08", SRF08 },
> +	{ "srf10", SRF10 },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, srf08_id);

      reply	other threads:[~2017-08-12 11:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 23:23 [PATCH 2/7] iio: srf08: add sensor type srf10 Andreas Klinger
2017-08-12 11:50 ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170812125055.0415eaad@archlinux \
    --to=jic23@kernel.org \
    --cc=ak@it-klinger.de \
    --cc=devicetree@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.