devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Matt Ranostay <mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	marex-ynQEQJNshbs@public.gmane.org,
	matt-agtwNxEcTQJWk0Htik3J/w@public.gmane.org,
	pantelis.antoniou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 2/2] iio: proximity: add support for PulsedLight LIDAR
Date: Sun, 2 Aug 2015 19:23:33 +0100	[thread overview]
Message-ID: <55BE6025.5030001@kernel.org> (raw)
In-Reply-To: <55BDE5F8.9090201-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>

On 02/08/15 10:42, Lars-Peter Clausen wrote:
> On 08/01/2015 05:58 AM, Matt Ranostay wrote:
> [...]
>> +
>> +struct lidar_data {
>> +	struct mutex lock;
>> +	struct iio_dev *indio_dev;
>> +	struct i2c_client *client;
>> +
>> +	/* config */
>> +	int calib_bias;
>> +
>> +	u16 buffer[5]; /* 2 byte distance + 8 byte timestamp */
> 
> Needs to be in its own cacheline to avoid issues if the I2C controller is
> using DMA.
Would do if spi, but in the case of i2c I thought all bus drivers were
obliged to deal with this rather than leaving it to the client drivers?

Has this changed?

> 
> 	u16 buffer[5] ____cacheline_aligned;
> 
>> +};
> [...]
>> +static inline int lidar_read_byte(struct lidar_data *data, int reg)
> 
> I'd drop the inline. The compiler is smart enough to figure out whether it
> makes sense to inline it or not.
> 
>> +{
>> +	struct i2c_client *client = data->client;
>> +	int ret;
>> +
>> +	ret = i2c_smbus_write_byte(client, reg);
>> +	if (ret < 0) {
>> +		dev_err(&client->dev, "cannot write addr value");
>> +		return ret;
>> +	}
>> +
>> +	ret = i2c_smbus_read_byte(client);
>> +	if (ret < 0) {
>> +		dev_err(&client->dev, "cannot read data value");
>> +		return ret;
>> +	}
> 
> Instead of using a write_byte/read_byte combination rather use
> i2c_smbus_read_byte_data(). I think that will do the same, but in one atomic
> operation.
> 
>> +
>> +	return ret;
>> +}
> [...]
>> +static int lidar_read_measurement(struct lidar_data *data, u16 *reg)
>> +{
>> +	int ret;
>> +	int val;
>> +
>> +	ret = lidar_read_byte(data, LIDAR_REG_DATA_HBYTE);
>> +	if (ret < 0)
>> +		return ret;
>> +	val = ret << 8;
>> +
>> +	ret = lidar_read_byte(data, LIDAR_REG_DATA_LBYTE);
>> +	if (ret < 0)
>> +		return ret;
>> +	val |= ret;
>> +
>> +	/* correct any possible overflow or underflow */
>> +	val += data->calib_bias / 10000;
> 
> Typically calib bias is only meant for a offset correction that is done in
> hardware rather than in software. What's the usecase for doing it in
> kernelspace rather than in userspace?
> 
>> +	if (val < 0)
>> +		val = 0;
>> +
>> +	if (val > LIDAR_REG_DATA_MAX)
>> +		val = LIDAR_REG_DATA_MAX;
>> +
>> +	*reg = val;
>> +
>> +	return 0;
>> +}
> [...]
>> +static int lidar_read_raw(struct iio_dev *indio_dev,
>> +			  struct iio_chan_spec const *chan,
>> +			  int *val, int *val2, long mask)
>> +{
>> +	struct lidar_data *data = iio_priv(indio_dev);
>> +	int ret = -EINVAL;
>> +
>> +	if (iio_buffer_enabled(indio_dev) && mask == IIO_CHAN_INFO_RAW)
>> +		return -EBUSY;
>> +
>> +	mutex_lock(&data->lock);
>> +
>> +	switch (mask) {
>> +	case IIO_CHAN_INFO_RAW: {
>> +		u16 reg;
>> +
>> +		ret = lidar_get_measurement(data, &reg);
>> +		if (!ret) {
>> +			*val = reg / 100;
>> +			*val2 = (reg % 100) * 10000;
>> +			ret = IIO_VAL_INT_PLUS_MICRO;
> 
> The raw attribute is supposed to return the raw value as a IIO_VAL_INT. A
> scale attribute should be used to indicate the conversion factor to get the
> proper unit.
> 
>> +		}
>> +		break;
>> +	}
>> +	case IIO_CHAN_INFO_CALIBBIAS:
>> +		*val = 0;
>> +		*val2 = data->calib_bias;
>> +		ret = IIO_VAL_INT_PLUS_MICRO;
>> +		break;
>> +	}
>> +
>> +	mutex_unlock(&data->lock);
>> +
>> +	return ret;
>> +}
> [...]
>> +static struct iio_info lidar_info = {
> 
> const
> 
>> +	.driver_module = THIS_MODULE,
>> +	.read_raw = lidar_read_raw,
>> +	.write_raw = lidar_write_raw,
>> +};
> [...]
>> +static struct i2c_driver lidar_driver = {
>> +	.driver = {
>> +		.name	= LIDAR_DRV_NAME,
>> +		.owner	= THIS_MODULE,
> 
> You added a DT vendor prefix, but there is no of match table for the driver.
> 
>> +	},
>> +	.probe		= lidar_probe,
>> +	.remove		= lidar_remove,
>> +	.id_table	= lidar_id,
>> +};
>> +module_i2c_driver(lidar_driver);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

  parent reply	other threads:[~2015-08-02 18:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-01  3:58 [PATCH 0/2] iio: proximity: add PulsedLight LIDAR sensor support Matt Ranostay
     [not found] ` <1438401484-22101-1-git-send-email-mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-08-01  3:58   ` [PATCH 1/2] devicetree: add PulsedLight vendor prefix Matt Ranostay
2015-08-01  3:58   ` [PATCH 2/2] iio: proximity: add support for PulsedLight LIDAR Matt Ranostay
     [not found]     ` <1438401484-22101-3-git-send-email-mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-08-01  8:39       ` Vladimir Barinov
     [not found]         ` <55BC85AF.1030608-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
2015-08-01 21:17           ` Jonathan Cameron
     [not found]             ` <791628AC-C26A-4D88-8A5B-54B2E4EED75B-tko9wxEg+fIOOJlXag/Snyp2UmYkHbXO@public.gmane.org>
2015-08-01 22:22               ` Matt Ranostay
     [not found]                 ` <CAKzfze9D6NYgJoT-271GUj1ei-PwUfHwJ38w8uMcgPoQz6yyUQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-02  7:36                   ` Vladimir Barinov
2015-08-02 18:18                   ` Jonathan Cameron
2015-08-02  9:42       ` Lars-Peter Clausen
     [not found]         ` <55BDE5F8.9090201-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-08-02 18:23           ` Jonathan Cameron [this message]
     [not found]             ` <55BE6025.5030001-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-08-02 18:39               ` Lars-Peter Clausen
     [not found]                 ` <55BE63F2.5080204-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-08-02 19:52                   ` Jonathan Cameron
2015-08-02 21:28           ` Matt Ranostay
     [not found]             ` <CAKzfze_ZNeSBo_hKn4ju1uNM4iyaFrvGo89Dv_80DK3Tfb24yg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-03  8:00               ` Lars-Peter Clausen
     [not found]                 ` <55BF1F9D.30207-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-08-03  8:19                   ` Matt Ranostay
2015-08-02  9:45       ` Lars-Peter Clausen
  -- strict thread matches above, loose matches on Subject: below --
2015-08-12  6:01 [PATCH v5 0/2] iio: proximity: add PulsedLight LIDAR sensor support Matt Ranostay
     [not found] ` <1439359276-19028-1-git-send-email-mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-08-12  6:01   ` [PATCH 2/2] iio: proximity: add support for PulsedLight LIDAR Matt Ranostay
     [not found]     ` <1439359276-19028-3-git-send-email-mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-08-16  8:24       ` Jonathan Cameron
     [not found]         ` <55D048A9.8060109-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-08-18  2:33           ` Matt Ranostay

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=55BE6025.5030001@kernel.org \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=marex-ynQEQJNshbs@public.gmane.org \
    --cc=matt-agtwNxEcTQJWk0Htik3J/w@public.gmane.org \
    --cc=mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=pantelis.antoniou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).