mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Shen Jianping (ME-SE/EAD2)" <Jianping.Shen@de.bosch.com>
To: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	"lars@metafoo.de" <lars@metafoo.de>,
	"robh@kernel.org" <robh@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"dima.fedrau@gmail.com" <dima.fedrau@gmail.com>,
	"marcelo.schmitt1@gmail.com" <marcelo.schmitt1@gmail.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Lorenz Christian (ME-SE/EAD2)" <Christian.Lorenz3@de.bosch.com>,
	"Frauendorf Ulrike (ME/PJ-SW3)" <Ulrike.Frauendorf@de.bosch.com>,
	"Dolde Kai (ME-SE/PAE-A3)" <Kai.Dolde@de.bosch.com>
Subject: RE: [PATCH v8 2/2] iio: imu: smi240: add driver
Date: Thu, 17 Oct 2024 07:46:48 +0000	[thread overview]
Message-ID: <DB9PR10MB4730F796051995DDAFD03DBFCD472@DB9PR10MB4730.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20241010174259.00003742@Huawei.com>


>> >It should still need to place the two bytes of that 16 bit value in the correct order to send to hardware.  That may be handled via a 32 bit word length on SPI though.
>>
>>
>> This is the most confusing part.  During the request preparation, we focus on the bit order not the byte order. We need to bring the 16 bit value in the correct bit order, to the correct bit position in the 32 bit request. This is automatically guarantied using FIELD_PREP. FIELD_PREP shifts the data 15-0 to request 18-3. We shall never manually change the byte order of the 16 bit value. The byte order (of the whole request) becomes important when we send it over spi, which will be explained later.
>>
>>
>> >> In the SMI240, the register address is 8 bit and each register is 16 bit. We do not have any register value, which is bigger than 16 bit and need to be stored in multiple registers.  Therefore the device does not need endian. Neither big endian nor Little Endian.  To access the register, it is important to prepare the request frame according to the specification.
>> >>
>> >> A request is 32 bit
>> >>
>> >> 	ID	ADR	W	CAP	*	WDATA	CRC
>> >> 	31-30	29-22	21	20	19	18-3		2-0
>> >>
>> >> ID: device id (if more than 1 device)
>> >> ADR: reg address
>> >> W: write/read
>> >> CAP: capture mode on/off
>> >> *: reserved
>> >> WDATA : reg value bit 15-0
>> >> CRC: check sum
>> >>
>> >> To prepare the request properly, the bit order is here critical. We need to put each part in its bit position. The request is created as a local u32, with help of FIELD_PREP, we put the value of each part to its bit position. FIELD_PREP will take care of the cpu endian and always put the value to the correct bit position. Before we send the request via SPI, a cpu endian to big endian conversion is required.
>> >
>> >So there are two possibilities here.  Either the byte order is just reversed for the device in which case fine as you describe or perhaps the SPI transfers should be using a 32 bit word?  You'd do that by overriding the bits_per_word in the individual SPI transfers.
>> >
>> >
>> >> Since the spi bus transfers data using big endian. When we get the response from spi, the response is big endian and need to be converted in cpu endian.  Any other manually endian conversion is not required.
>> >
>> >The SPI bus itself has no real concept of endian as such. It just sends bits in the order it is fed them.  The device may require a particular ordering of course if we assume it makes sense to break the transfers up into byte size chnunks.
>>
>>
>> Yes, the device expect that the 32 bit request will be sent from MSBit to LSBit. Which means the ID shall be sent firstly, followed by ADR, W, CAP, *, WDATA, CRC.  If we consider the 32 bit as 4 bytes , then the MSB need to sent firstly, and followed by the LSBs. From this perspective we can say that the SMI240 SPI protocol requires big endian. On the host side the request is a local u32 (4 bytes). To make sure that the MSB will be sent firstly we need to convert the request to big endian before sending it over spi.
>
>Understood.  Try a 32 bit word size for the spi transfers. I think that should make everything work without any need to make it big endian.
>
We tried to use 32 bit word size for the spi transfers. Nevertheless not all the spi libraries supports 32 bit word. A number of spi library just support 8bit. Therefore we will firstly provide a 8bit spi transfer in next version. 

Best Regards
Jianping Shen

      reply	other threads:[~2024-10-17  7:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23 12:40 [PATCH v8 0/2] iio: imu: smi240: add bosch smi240 driver Jianping.Shen
2024-09-23 12:40 ` [PATCH v8 1/2] dt-bindings: iio: imu: smi240: add Bosch smi240 Jianping.Shen
2024-09-23 12:40 ` [PATCH v8 2/2] iio: imu: smi240: add driver Jianping.Shen
2024-09-28 17:11   ` Jonathan Cameron
2024-10-01 18:42     ` Jonathan Cameron
2024-10-03 21:44     ` Shen Jianping (ME-SE/EAD2)
2024-10-06 11:10       ` Jonathan Cameron
2024-10-10 15:02         ` Shen Jianping (ME-SE/EAD2)
2024-10-10 16:42           ` Jonathan Cameron
2024-10-17  7:46             ` Shen Jianping (ME-SE/EAD2) [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=DB9PR10MB4730F796051995DDAFD03DBFCD472@DB9PR10MB4730.EURPRD10.PROD.OUTLOOK.COM \
    --to=jianping.shen@de.bosch.com \
    --cc=Christian.Lorenz3@de.bosch.com \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=Kai.Dolde@de.bosch.com \
    --cc=Ulrike.Frauendorf@de.bosch.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dima.fedrau@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=robh@kernel.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

all inboxes | Powered by JetHome®