git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv2] lis3lv02d: support both one- and two-byte sensors

From
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Date
Feb 10, 2009, 23:51 UTC
Message-ID
<cb7bb73a0902101551o30dde0aesaeba399f1ab732af@mail.gmail.com>
In-Reply-To
<499211D0.3090705@tremplin-utc.net>
On Wed, Feb 11, 2009 at 12:46 AM, Éric Piel <Eric.Piel@tremplin-utc.net> wrote:
Show 24 quoted lines
> Giuseppe Bilotta schreef:
>>
>> Sensors responding with 0x3B to WHO_AM_I only have one data register per
>> direction, thus returning a signed byte from the position which is
>> occupied by the MSB in sensors responding with 0x3A.
>>
>> We support both kind of sensors by checking for the sensor type on init
>> and defining appropriate data-access routines and sensor limits (for the
>> joystick) depending on what we find.
>>
>> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
>> ---
>>
>> This is the other version of the patch, and it changes access to use the
>> base address from the 8-bit, so the 16-bit routine is changed to access
>> the PREVIOUS byte for the LSB.
>>
>> Choose whichever of the patches is deemed more correct 8-)
>>
>> Note that both patches are based off Linus tree, so I don't know how
>> they cope with Pavel's "don't touch too much on init" one. I'll try to
>> work out a patch on top of that too.
>
> Yes, great, and this one looks even better than v1 :-)
And don't forget about the v3 for -mm ;-)
Show 17 quoted lines
> However I'm not sure about the conversion between s8 and s16:
>
>> +static s16 lis3lv02d_read_8(acpi_handle handle, int reg)
>> +{
>> +       u8 lo;
>> +       adev.read(handle, reg, &lo);
>> +       return *((s8*)(&lo));
>> +}
>
> Does it really extend the sign to 16 bits? I would have written it this way:
> +static s16 lis3lv02d_read_8(acpi_handle handle, int reg)
> +{
> +       s8 lo;
> +       adev.read(handle, reg, &lo);
> +       return (s16)lo;
> +}
> Doesn't it work better?

Well, the previous one works, but I admit it's horribly convoluted. I'll double check with this one and resubmit (I'll only resubmit the one based on Pavel's "don't touch anything on init" probably though, hope it's ok)

-- 
Giuseppe "Oblomov" Bilotta
Previous: Éric PielNext: Éric Piel
Message 3 of 4 in “[PATCHv2] lis3lv02d: support both one- and two-byte sensors”
  1. Giuseppe BilottaFeb 10, 2009
  2. Éric PielFeb 10, 2009
  3. Giuseppe BilottaFeb 10, 2009
  4. Éric PielFeb 10, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.