linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Matt Ranostay <matt.ranostay@konsulko.com>
Cc: linux-input <linux-input@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Rishi Gupta <gupt21@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH] HID: mcp2221: add ADC/DAC support via iio subsystem
Date: Sun, 31 Jul 2022 21:10:32 +0200	[thread overview]
Message-ID: <CAHp75VcOAbrZ2yciwH6teYs5L0vYnE4z==SQ6ejye63+_v9v+g@mail.gmail.com> (raw)
In-Reply-To: <20220729154723.99947-1-matt.ranostay@konsulko.com>

On Fri, Jul 29, 2022 at 5:49 PM Matt Ranostay
<matt.ranostay@konsulko.com> wrote:
>
> Add support for 3x 10-bit ADC and 1x DAC channels registered via
> the iio subsystem.
>
> To prevent breakage and unexpected dependencies this support only is
> only built if CONFIG_IIO is enabled, and is only weakly referenced by
> 'imply IIO' within the respective Kconfig.
>
> Additionally the iio device only gets registered if at least one channel
> is enabled in the power-on configuration read from SRAM.

I tried to leave the comments not clashed with Jonathan's ones below.

...

> Cc: Rishi Gupta <gupt21@gmail.com>
> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Use --cc in the parameters to `git format-patch` or move them after
the cutter '---' line below, so they won't pollute the Git commit
message.

...

> -       depends on GPIOLIB
> +       select GPIOLIB

I'm not sure why.

...

>  #include <linux/hidraw.h>
>  #include <linux/i2c.h>
>  #include <linux/gpio/driver.h>

+ blank line.

> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>

+ blank line.

>  #include "hid-ids.h"

> +#if IS_REACHABLE(CONFIG_IIO)
> +       struct iio_chan_spec iio_channels[3];
> +       struct iio_dev *indio_dev;
> +       u16 adc_values[3];
> +       u8 dac_value;
> +#endif
> +};

...

> +#if IS_REACHABLE(CONFIG_IIO)
> +                       if (mcp->indio_dev)
> +                               memcpy(&mcp->adc_values, &data[50], 6);

sizeof()

> +#endif

...

> +               // Confirm value is within 10-bit range
> +               if (*val > GENMASK(9, 0))

  if (*val >= BIT(10))

 will make comment useless

> +                       return -EINVAL;
> +       }

...

> +       if (val < 0 || val > GENMASK(4, 0))

In a similar way, val >= BIT(5).

> +               return -EINVAL;

...

> +       memset(mcp->txbuf, 0, 12);

sizeof() ?

...

> +       ret = mcp_send_data_req_status(mcp, mcp->txbuf, 12);

Ditto,

> +       hid_hw_power(mcp->hdev, PM_HINT_NORMAL);

Even in an error case?

> +       if (ret) {
> +               mutex_unlock(&mcp->lock);
> +               return -EINVAL;
> +       }

...

> +#if IS_REACHABLE(CONFIG_IIO)
> +       if (mcp->indio_dev)

Do you need this check?

> +               iio_device_unregister(mcp->indio_dev);
> +#endif

...

Overall what I really do not like is that ugly ifdeffery. Can we avoid
adding it?

-- 
With Best Regards,
Andy Shevchenko

  parent reply	other threads:[~2022-07-31 19:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29 15:47 [PATCH] HID: mcp2221: add ADC/DAC support via iio subsystem Matt Ranostay
2022-07-31 11:57 ` Jonathan Cameron
2022-08-01  4:04   ` Matt Ranostay
2022-07-31 19:10 ` Andy Shevchenko [this message]
2022-08-01  4:19   ` Matt Ranostay
2022-08-01  9:08     ` Andy Shevchenko
2022-08-06 16:29       ` Jonathan Cameron
2022-08-06 21:48         ` Andy Shevchenko

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='CAHp75VcOAbrZ2yciwH6teYs5L0vYnE4z==SQ6ejye63+_v9v+g@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=gupt21@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=matt.ranostay@konsulko.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).