linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Reid <preid@electromag.com.au>
To: Song Qiang <songqiang1304521@gmail.com>
Cc: Jonathan Cameron <jonathan.cameron@huawei.com>,
	jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, robh+dt@kernel.org, mark.rutland@arm.com,
	rtresidd@electromag.com.au, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: magnetometer: Add driver support for PNI RM3100
Date: Thu, 27 Sep 2018 09:57:24 +0800	[thread overview]
Message-ID: <ef710cc6-4a2a-ce9d-3e4c-502aea7fcf27@electromag.com.au> (raw)
In-Reply-To: <20180926080752.GA12183@Eros>

On 26/09/2018 4:09 PM, Song Qiang wrote:
> On Wed, Sep 26, 2018 at 10:30:34AM +0800, Phil Reid wrote:
>> On 26/09/2018 9:49 AM, Song Qiang wrote:
>>> On Tue, Sep 25, 2018 at 10:36:54PM +0800, Phil Reid wrote:
>>>> On 25/09/2018 9:30 PM, Jonathan Cameron wrote:
>>>>>> +static irqreturn_t rm3100_trigger_handler(int irq, void *p)
>>>>>> +{
>>>>>> +	struct iio_poll_func *pf = p;
>>>>>> +	struct iio_dev *indio_dev = pf->indio_dev;
>>>>>> +	struct rm3100_data *data = iio_priv(indio_dev);
>>>>>> +	struct regmap *regmap = data->regmap;
>>>>>> +	u8 buffer[9];
>>>>>> +	int ret;
>>>>>> +	int i;
>>>>>> +
>>>>>> +	mutex_lock(&data->lock);
>>>>>> +	ret = rm3100_wait_measurement(data);
>>>>>> +	if (ret < 0) {
>>>>>> +		mutex_unlock(&data->lock);
>>>>>> +		goto done;
>>>>>> +	}
>>>>>> +
>>>>>> +	ret = regmap_bulk_read(regmap, RM3100_REG_MX2, buffer, sizeof(buffer));
>>>>>> +	mutex_unlock(&data->lock);
>>>>>> +	if (ret < 0)
>>>>>> +		goto done;
>>>>>> +
>>>>>> +	/* Convert XXXYYYZZZxxx to XXXxYYYxZZZx. x for padding. */
>>>>>> +	for (i = 0; i < 3; i++)
>>>>>> +		memcpy(data->buffer + i * 4, buffer + i * 3, 3);
>>>>> Firstly X doesn't need copying.
>>>>> Secondly the copy of Y actually overwrites the value of Z
>>>>> XXXYYYZZZxxx
>>>>> XXXxYYYZZxxx
>>>>> XXXxYYYxYZZx
>>>>>
>>>>> I think...
>>>>>
>>>>>> +
>>>>>> +	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
>>>>>> +			iio_get_time_ns(indio_dev));
>>>>
>>>> memcpy target is a different buffer so should be ok.
>>>>
>>>> But that raises the question of does it need to be?
>>>> 'buffer' could be 12 bytes long and just shuffle Z then Y.
>>>> Do the unused bytes need to be zeroed? or does libiio mask them anyway?
>>>>
>>>>
>>>>
>>>> -- 
>>>> Regards
>>>> Phil Reid
>>>
>>> Hi Phil,
>>>
>>> This is interesting, last patch I submitted uses three transactions and
>>> shuffles X, Y and Z respectively. You said it should be better to use one
>>> transactions, I thought it makes point, and one transaction may reduce
>>> IO pressure of the i2c bus. :)
>>> And that's not necessary for unused bytes to be zero. I'm not familiar
>>> with libiio, actually just been studying it, can't say anything about
>>> it.
>>>
>>> yours,
>>> Song Qiang
>>>
>>>
>> G'day Song,
>>
>> yes the one transaction suggestion was to reduce pressure on the bus.
>> I think also with 3 calls you can up up with other devices taking over
>> the i2c / spi bus in between.
>>
>> We've got a devkit for this part, but haven't got to wiring it up to our system as yet.
>> We're looking at using the i2c interface which could push things at max samplerate, so yes I'm
>> keen to see bus pressure reduced as much as possible.
>>
>> I was thinking something like the following:
>>
>> u8 buffer[12];
>> regmap_bulk_read(regmap, RM3100_REG_MX2, buffer, 9);
>>
>> buffer[10] = buffer[8]; // or memcpy or some other fancy shuffle code.
>> buffer[9]  = buffer[7];
>> buffer[8]  = buffer[6];
>>
>> buffer[6]  = buffer[5];
>> buffer[5]  = buffer[4];
>> buffer[4]  = buffer[3];
>>
>> iio_push_to_buffers_with_timestamp(indio_dev, buffer, iio_get_time_ns(indio_dev));
>>
>> but I'm unsure if this would be needed:
>> buffer[7] = 0
>> buffer[3] = 0
>>
>> What you've got does the job I think.
>>
>> I haven't dug into the datasheet in great detail, and my iio knownledge is limited.
>> Are you sure the RM3100_CHANNEL scantype endianness is IIO_LE.
>> rm3100_read_mag looks to be doing big endian conversion and the datasheet agrees with that.
>>
>>
>> -- 
>> Regards
>> Phil Reid
>>
> 
> Hi Phil,
> 
> You're absolutely right!
> This should be big endian, I think I probably just want something there
> when I was writing this code, planned to change it later, but apparently
> I've forgotten it...
> 
> AFAIK, filling places we do not need with 0 is not needed, we just
> extract valid data from valid bit field(24 here).
> 
> Both one transaction and three transactions way have their point, but
> this is a OS, probably the spiltted one is better, I need some real
> thinking about this...
The one transaction is better.
Reduces i2c traffic by 6 bytes and ensure the measurements are tightly
coupled in time for the 3 axis.

> 
> I could have use the same buffer to read from the sensor and send it to
> userspace like this:
> 
> int i = 0;
> ret = regmap_bulk_read(regmap, RM3100_REG_MX2, 9);
> if(ret)
> 	...
> /* Convert XXXYYYZZZxxx to XXXxYYYxZZZx. */
> for (i = 0; i < 2; i++)
> 	memcpy(buffer + (2 - i) * 4, buffer + (2 - i) * 3), 3);
> 
> This code snippet will use the same buffer, actually that's what I was
> using the first time. Jonathan must thinks so, from what he commented,
> he assumed I was using the same buffer, also what you want.
> But I changed this due to Peter's comment, maybe not a big deal, he
> suggests to use sizeof(buffer), this makes me use an additional size 9
> buffer. I thought this doesn't matter too much, just some additional
> space from the stack, but now I think maybe less memory using would be
> better...
> After all, this length 9 seems like never shouldn't be changed...

yes that does the job.


-- 
Regards
Phil Reid



  reply	other threads:[~2018-09-27  1:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-25  3:17 [PATCH 1/2] iio: magnetometer: Add DT support for PNI RM3100 Song Qiang
2018-09-25  3:17 ` [PATCH 2/2] iio: magnetometer: Add driver " Song Qiang
2018-09-25 13:30   ` Jonathan Cameron
2018-09-25 14:36     ` Phil Reid
2018-09-26  1:49       ` Song Qiang
2018-09-26  2:30         ` Phil Reid
2018-09-26  8:09           ` Song Qiang
2018-09-27  1:57             ` Phil Reid [this message]
2018-09-29 11:37             ` Jonathan Cameron
2018-09-26  1:33     ` Song Qiang
2018-09-29 11:45       ` Jonathan Cameron
2018-09-25 17:50   ` Himanshu Jha
2018-09-26  2:24     ` Song Qiang
2018-09-25 13:05 ` [PATCH 1/2] iio: magnetometer: Add DT " Jonathan Cameron
2018-10-02 14:38 ` [PATCH v3 0/3] Add support for PNI RM3100 magnetometer Song Qiang
2018-10-02 14:38   ` [PATCH v3 1/3] dt-bindings: Add PNI to the vendor prefixes Song Qiang
2018-10-02 14:38   ` [PATCH v3 2/3] dt-bindings: Add PNI RM3100 device tree binding Song Qiang
2018-10-07 15:18     ` Jonathan Cameron
2018-10-07 15:20       ` Jonathan Cameron
2018-10-02 14:38   ` [PATCH v3 3/3] iio: magnetometer: Add driver support for PNI RM3100 Song Qiang
2018-10-03  1:42     ` Phil Reid
2018-10-07 15:07       ` Jonathan Cameron
2018-10-07 15:44     ` Jonathan Cameron
2018-10-11  4:35       ` Song Qiang
2018-10-13  9:24         ` Jonathan Cameron
2018-10-12  7:35   ` [PATCH v4 0/3] Add support for PNI RM3100 magnetometer Song Qiang
2018-10-12  7:35     ` [PATCH v4 1/3] dt-bindings: Add PNI to the vendor prefixes Song Qiang
2018-10-12 11:36       ` Rob Herring
2018-10-12  7:35     ` [PATCH v4 2/3] iio: magnetometer: Add DT support for PNI RM3100 Song Qiang
2018-10-12 11:37       ` Rob Herring
2018-10-12  7:35     ` [PATCH v4 3/3] iio: magnetometer: Add driver " Song Qiang
2018-10-12  8:36       ` Song Qiang
2018-10-12 12:53         ` Himanshu Jha
2018-10-17  8:00           ` Song Qiang
2018-10-21 14:08             ` Jonathan Cameron
2018-10-13 10:19       ` Jonathan Cameron
2018-10-18  8:24         ` Song Qiang
2018-10-21 14:14           ` Jonathan Cameron
2018-11-02  7:55             ` Song Qiang
2018-11-02  9:24               ` Jonathan Cameron
2018-11-05  0:39                 ` Song Qiang

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=ef710cc6-4a2a-ce9d-3e4c-502aea7fcf27@electromag.com.au \
    --to=preid@electromag.com.au \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=jonathan.cameron@huawei.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --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=rtresidd@electromag.com.au \
    --cc=songqiang1304521@gmail.com \
    /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).