public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Cercueil <paul@crapouillou.net>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Artur Rojek <contact@artur-rojek.eu>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	linux-input <linux-input@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v7 7/7] input: joystick: Add ADC attached joystick driver.
Date: Tue, 19 May 2020 23:02:54 +0200	[thread overview]
Message-ID: <USJLAQ.SNMLIAX3CX1J2@crapouillou.net> (raw)
In-Reply-To: <CAHp75VcChHOrxrqBM==-_SaTL4vSojKmRWvkNn-CHLH99pcAuQ@mail.gmail.com>

Hi Andy,

Le mar. 19 mai 2020 à 23:43, Andy Shevchenko 
<andy.shevchenko@gmail.com> a écrit :
> On Sun, May 17, 2020 at 10:49 PM Artur Rojek <contact@artur-rojek.eu> 
> wrote:
>> 
>>  Add a driver for joystick devices connected to ADC controllers
>>  supporting the Industrial I/O subsystem.
> 
> ...
> 
>>  +static int adc_joystick_handle(const void *data, void *private)
>>  +{
>>  +       struct adc_joystick *joy = private;
>>  +       enum iio_endian endianness;
>>  +       int bytes, msb, val, i;
>>  +       bool sign;
>>  +
>>  +       bytes = joy->chans[0].channel->scan_type.storagebits >> 3;
>>  +
>>  +       for (i = 0; i < joy->num_chans; ++i) {
>>  +               endianness = 
>> joy->chans[i].channel->scan_type.endianness;
>>  +               msb = joy->chans[i].channel->scan_type.realbits - 1;
> 
>>  +               sign = 
>> (tolower(joy->chans[i].channel->scan_type.sign) == 's');
> 
> Do we need tolower()?

I'll answer this one:

The sign can be uppercase to specify that the value is sign-extended in 
all the storage bits.

-Paul

>>  +
>>  +               switch (bytes) {
>>  +               case 1:
>>  +                       val = ((const u8 *)data)[i];
>>  +                       break;
>>  +               case 2:
>>  +                       if (endianness == IIO_BE)
> 
>>  +                               val = be16_to_cpu(((const u16 
>> *)data)[i]);
> 
> Yeah, you have to provide bitwise types to satisfy sparse.
> Maybe using *_to_cpup() will cure this.
> 
>>  +                       else if (endianness == IIO_LE)
>>  +                               val = le16_to_cpu(((const u16 
>> *)data)[i]);
>>  +                       else /* IIO_CPU */
>>  +                               val = ((const u16 *)data)[i];
>>  +                       break;
>>  +               default:
>>  +                       return -EINVAL;
>>  +               }
>>  +
>>  +               val >>= joy->chans[i].channel->scan_type.shift;
>>  +               if (sign)
>>  +                       val = sign_extend32(val, msb);
>>  +               else
>>  +                       val &= GENMASK(msb, 0);
>>  +               input_report_abs(joy->input, joy->axes[i].code, 
>> val);
>>  +       }
>>  +
>>  +       input_sync(joy->input);
>>  +
>>  +       return 0;
>>  +}
> 
> ...
> 
>>  +       /* Count how many channels we got. NULL terminated. */
>>  +       while (joy->chans[joy->num_chans].indio_dev)
>>  +               joy->num_chans++;
> 
> I don't see how useful this is. Why not simple do below...
> 
>>  +       bits = joy->chans[0].channel->scan_type.storagebits;
>>  +       if (!bits || (bits > 16)) {
>>  +               dev_err(dev, "Unsupported channel storage size");
>>  +               return -EINVAL;
>>  +       }
>>  +       for (i = 1; i < joy->num_chans; ++i)
>>  +               if (joy->chans[i].channel->scan_type.storagebits != 
>> bits) {
>>  +                       dev_err(dev, "Channels must have equal 
>> storage size");
>>  +                       return -EINVAL;
>>  +               }
> 
> ...something like
> 
>   for (i = 0; joy->chans[i].indio_dev; i++) {
>     bits = joy->chans[i].channel->scan_type.storagebits;
>     if (bits ...) {
>       ...error handling...
>     }
>     if (bits != joy->chans[0].channel->scan_type.storagebits) {
>       ...second level of error handling...
>     }
>  }
> 
> ...
> 
>>  +static const struct of_device_id adc_joystick_of_match[] = {
>>  +       { .compatible = "adc-joystick", },
> 
>>  +       { },
> 
> No need comma.
> 
>>  +};
> 
> --
> With Best Regards,
> Andy Shevchenko



  reply	other threads:[~2020-05-19 21:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 19:48 [PATCH v7 1/7] dt-bindings: iio/adc: Convert ingenic-adc docs to YAML Artur Rojek
2020-05-17 19:48 ` [PATCH v7 2/7] IIO: Ingenic JZ47xx: Error check clk_enable calls Artur Rojek
2020-05-19 18:15   ` Jonathan Cameron
2020-05-17 19:49 ` [PATCH v7 3/7] IIO: Ingenic JZ47xx: Add xlate cb to retrieve correct channel idx Artur Rojek
2020-05-17 19:49 ` [PATCH v7 4/7] dt-bindings: iio/adc: Add touchscreen idx for JZ47xx SoC ADC Artur Rojek
2020-05-17 19:49 ` [PATCH v7 5/7] IIO: Ingenic JZ47xx: Add touchscreen mode Artur Rojek
2020-05-17 19:49 ` [PATCH v7 6/7] dt-bindings: input: Add docs for ADC driven joystick Artur Rojek
2020-05-18 14:22   ` Rob Herring
2020-05-17 19:49 ` [PATCH v7 7/7] input: joystick: Add ADC attached joystick driver Artur Rojek
2020-05-17 23:19   ` kbuild test robot
2020-05-19 18:25   ` Jonathan Cameron
2020-05-19 20:43   ` Andy Shevchenko
2020-05-19 21:02     ` Paul Cercueil [this message]
2020-05-26 21:34 ` [PATCH v7 1/7] dt-bindings: iio/adc: Convert ingenic-adc docs to YAML Rob Herring

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=USJLAQ.SNMLIAX3CX1J2@crapouillou.net \
    --to=paul@crapouillou.net \
    --cc=andy.shevchenko@gmail.com \
    --cc=contact@artur-rojek.eu \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@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