From: Marek Vasut <marex@denx.de>
To: "Lars-Peter Clausen" <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Jonathan Cameron <jic23@kernel.org>, Wolfgang Denk <wd@denx.de>,
Juergen Beisert <jbe@pengutronix.de>
Subject: Re: [PATCH] IIO: Add basic MXS LRADC driver
Date: Thu, 19 Jul 2012 16:23:14 +0200 [thread overview]
Message-ID: <201207191623.14492.marex@denx.de> (raw)
In-Reply-To: <4FF55149.2080801@metafoo.de>
Dear Lars-Peter Clausen,
Sorry for my late reply, got busy with other crazy stuff.
[...]
> >> Is there any reason not to use the mxs_lradc struct directly has the iio
> >> data?
> >
> > I explained it below in the patch. I hope we'll eventually support the
> > delay triggers, which will need 4 separate IIO devices. And this is
> > where this structure will be augmented by other components.
>
> Ok I saw the comment, but it wasn't obvious to me that delay channels will
> require multiple IIO devices. Might make sense to state this explicitly.
Fixed.
> >>> [...]
> >>>
> >>> +
> >>> +/*
> >>> + * Channel management
> >>> + *
> >>> + * This involves crazy mapping between 8 virtual channels the CTRL4
> >>> register + * can harbor and 16 channels total this hardware supports.
> >>> + */
> >>
> >> I suppose this means only a maximum 8 channels can be active at a time.
> >> I've recently posted a patch which makes it easy to implement such a
> >> restriction. http://www.spinics.net/lists/linux-iio/msg05936.html and
> >> http://www.spinics.net/lists/linux-iio/msg05935.html for an example
> >> validate callback implementation. In your case you'd check for
> >> bitmap_weight(...) <= 8. Those patches are not yet in IIO though.
> >
> > This is good. When do you expect this to hit linux-next possibly? Or at
> > least linux-iio?
>
> soon, hopefully.
So I checked this, not sure how it'll help me though.
> > [..]
> >
> >>> +static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
> >>> + const struct iio_chan_spec *chan,
> >>> + int *val, int *val2, long m)
> >>> +{
> >>> + struct mxs_lradc_data *data = iio_priv(iio_dev);
> >>> + struct mxs_lradc *lradc = data->lradc;
> >>> + int ret, slot;
> >>> +
> >>> + if (m != 0)
> >>
> >> I'd use the symbolic constant here IIO_CHAN_INFO_RAW
> >>
> >>> + return -EINVAL;
> >>> +
> >>> + /* Map channel. */
> >>> + slot = mxs_lradc_map_channel(lradc, chan->channel,
> >>> LRADC_CHAN_FLAG_RAW); + if (slot < 0)
> >>> + return slot;
> >>> +
> >>> + /* Start sampling. */
> >>> + mxs_lradc_run_slots(lradc, 1 << slot);
> >>> +
> >>> + /* Wait for completion on the channel, 1 second max. */
> >>> + lradc->wq_done[slot] = false;
> >>> + ret = wait_event_interruptible_timeout(lradc->wq_data_avail[slot],
> >>> + lradc->wq_done[slot],
> >>> + msecs_to_jiffies(1000));
> >>> + if (!ret) {
>
> Just noticed this, wait_event_interruptible_timeout can return an error
> value, e.g. if it has been interrupted.
Fixed
> >>> + ret = -ETIMEDOUT;
> >>> + goto err;
> >>> + }
> >>> +
> >>
> >> How well will this work if the device is currrently in buffered mode?
> >> Maybe it's better do disablow it by checking iio_buffer_enabled and
> >> return -EBUSY if it returns true;
> >
> > I believe this should work perfectly OK, why won't it ? I tried to avoid
> > such artificial limitation.
>
> I suppose it is fine, but not knowing the hardware, what does
> mxs_lradc_run_slots do exactly?
Execute the sampling on the mapped slots.
> > [...]
> >
> >>> +static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool
> >>> state) +{
> >>> + struct iio_dev *iio = trig->private_data;
> >>> + struct mxs_lradc_data *data = iio_priv(iio);
> >>> + struct mxs_lradc *lradc = data->lradc;
> >>> + struct iio_buffer *buffer = iio->buffer;
> >>> + int slot, bit, ret = 0;
> >>> + uint8_t map = 0;
> >>> + unsigned long chans = 0;
> >>> +
> >>> + if (!state)
> >>> + goto exit;
> >>> +
> >>> + lradc->buffer = kmalloc(iio->scan_bytes, GFP_KERNEL);
> >>> + if (!lradc->buffer)
> >>> + return -ENOMEM;
> >>> +
> >>> + for_each_set_bit(bit, buffer->scan_mask, LRADC_MAX_TOTAL_CHANS) {
> >>> + slot = mxs_lradc_map_channel(lradc, bit, LRADC_CHAN_FLAG_BUF);
> >>> +
> >>> + if (slot < 0) {
> >>> + ret = -EINVAL;
> >>> + goto exit;
> >>> + }
> >>> + map |= 1 << slot;
> >>> + chans |= 1 << bit;
> >>> + }
> >>
> >> I think this should go into the buffer preenable and postdisable
> >> callbacks.
> >
> > How much of it, only the slot mapping or the allocation too ?
>
> Yeah I guess it is a bit tricky in this case. A good rule of thumb is to
> ask yourself whether the driver will (hypothetically) still work if
> another trigger is used. So the buffer allocation should certainly be
> handled by the buffer code, either the prenable or the update_scan_mode
> callback. The channel mapping part is not so obvious, but I'd put it in
> the
> preenable/postdisable callbacks as well.
Lemme try.
Best regards,
Marek Vasut
WARNING: multiple messages have this Message-ID (diff)
From: marex@denx.de (Marek Vasut)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] IIO: Add basic MXS LRADC driver
Date: Thu, 19 Jul 2012 16:23:14 +0200 [thread overview]
Message-ID: <201207191623.14492.marex@denx.de> (raw)
In-Reply-To: <4FF55149.2080801@metafoo.de>
Dear Lars-Peter Clausen,
Sorry for my late reply, got busy with other crazy stuff.
[...]
> >> Is there any reason not to use the mxs_lradc struct directly has the iio
> >> data?
> >
> > I explained it below in the patch. I hope we'll eventually support the
> > delay triggers, which will need 4 separate IIO devices. And this is
> > where this structure will be augmented by other components.
>
> Ok I saw the comment, but it wasn't obvious to me that delay channels will
> require multiple IIO devices. Might make sense to state this explicitly.
Fixed.
> >>> [...]
> >>>
> >>> +
> >>> +/*
> >>> + * Channel management
> >>> + *
> >>> + * This involves crazy mapping between 8 virtual channels the CTRL4
> >>> register + * can harbor and 16 channels total this hardware supports.
> >>> + */
> >>
> >> I suppose this means only a maximum 8 channels can be active at a time.
> >> I've recently posted a patch which makes it easy to implement such a
> >> restriction. http://www.spinics.net/lists/linux-iio/msg05936.html and
> >> http://www.spinics.net/lists/linux-iio/msg05935.html for an example
> >> validate callback implementation. In your case you'd check for
> >> bitmap_weight(...) <= 8. Those patches are not yet in IIO though.
> >
> > This is good. When do you expect this to hit linux-next possibly? Or at
> > least linux-iio?
>
> soon, hopefully.
So I checked this, not sure how it'll help me though.
> > [..]
> >
> >>> +static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
> >>> + const struct iio_chan_spec *chan,
> >>> + int *val, int *val2, long m)
> >>> +{
> >>> + struct mxs_lradc_data *data = iio_priv(iio_dev);
> >>> + struct mxs_lradc *lradc = data->lradc;
> >>> + int ret, slot;
> >>> +
> >>> + if (m != 0)
> >>
> >> I'd use the symbolic constant here IIO_CHAN_INFO_RAW
> >>
> >>> + return -EINVAL;
> >>> +
> >>> + /* Map channel. */
> >>> + slot = mxs_lradc_map_channel(lradc, chan->channel,
> >>> LRADC_CHAN_FLAG_RAW); + if (slot < 0)
> >>> + return slot;
> >>> +
> >>> + /* Start sampling. */
> >>> + mxs_lradc_run_slots(lradc, 1 << slot);
> >>> +
> >>> + /* Wait for completion on the channel, 1 second max. */
> >>> + lradc->wq_done[slot] = false;
> >>> + ret = wait_event_interruptible_timeout(lradc->wq_data_avail[slot],
> >>> + lradc->wq_done[slot],
> >>> + msecs_to_jiffies(1000));
> >>> + if (!ret) {
>
> Just noticed this, wait_event_interruptible_timeout can return an error
> value, e.g. if it has been interrupted.
Fixed
> >>> + ret = -ETIMEDOUT;
> >>> + goto err;
> >>> + }
> >>> +
> >>
> >> How well will this work if the device is currrently in buffered mode?
> >> Maybe it's better do disablow it by checking iio_buffer_enabled and
> >> return -EBUSY if it returns true;
> >
> > I believe this should work perfectly OK, why won't it ? I tried to avoid
> > such artificial limitation.
>
> I suppose it is fine, but not knowing the hardware, what does
> mxs_lradc_run_slots do exactly?
Execute the sampling on the mapped slots.
> > [...]
> >
> >>> +static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool
> >>> state) +{
> >>> + struct iio_dev *iio = trig->private_data;
> >>> + struct mxs_lradc_data *data = iio_priv(iio);
> >>> + struct mxs_lradc *lradc = data->lradc;
> >>> + struct iio_buffer *buffer = iio->buffer;
> >>> + int slot, bit, ret = 0;
> >>> + uint8_t map = 0;
> >>> + unsigned long chans = 0;
> >>> +
> >>> + if (!state)
> >>> + goto exit;
> >>> +
> >>> + lradc->buffer = kmalloc(iio->scan_bytes, GFP_KERNEL);
> >>> + if (!lradc->buffer)
> >>> + return -ENOMEM;
> >>> +
> >>> + for_each_set_bit(bit, buffer->scan_mask, LRADC_MAX_TOTAL_CHANS) {
> >>> + slot = mxs_lradc_map_channel(lradc, bit, LRADC_CHAN_FLAG_BUF);
> >>> +
> >>> + if (slot < 0) {
> >>> + ret = -EINVAL;
> >>> + goto exit;
> >>> + }
> >>> + map |= 1 << slot;
> >>> + chans |= 1 << bit;
> >>> + }
> >>
> >> I think this should go into the buffer preenable and postdisable
> >> callbacks.
> >
> > How much of it, only the slot mapping or the allocation too ?
>
> Yeah I guess it is a bit tricky in this case. A good rule of thumb is to
> ask yourself whether the driver will (hypothetically) still work if
> another trigger is used. So the buffer allocation should certainly be
> handled by the buffer code, either the prenable or the update_scan_mode
> callback. The channel mapping part is not so obvious, but I'd put it in
> the
> preenable/postdisable callbacks as well.
Lemme try.
Best regards,
Marek Vasut
next prev parent reply other threads:[~2012-07-19 14:23 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-04 2:15 [PATCH] IIO: Add basic MXS LRADC driver Marek Vasut
2012-07-04 2:15 ` Marek Vasut
2012-07-04 4:30 ` Wolfgang Denk
2012-07-04 4:30 ` Wolfgang Denk
2012-07-04 8:35 ` Lars-Peter Clausen
2012-07-04 8:35 ` Lars-Peter Clausen
2012-07-04 23:48 ` Marek Vasut
2012-07-04 23:48 ` Marek Vasut
2012-07-05 8:33 ` Lars-Peter Clausen
2012-07-05 8:33 ` Lars-Peter Clausen
2012-07-05 19:53 ` Marek Vasut
2012-07-05 19:53 ` Marek Vasut
2012-07-19 14:23 ` Marek Vasut [this message]
2012-07-19 14:23 ` Marek Vasut
2012-07-19 14:33 ` Lars-Peter Clausen
2012-07-19 14:33 ` Lars-Peter Clausen
2012-07-19 15:15 ` Marek Vasut
2012-07-19 15:15 ` Marek Vasut
2012-07-19 19:26 ` Marek Vasut
2012-07-19 19:26 ` Marek Vasut
2012-07-20 2:18 ` Marek Vasut
2012-07-20 2:18 ` Marek Vasut
2012-07-20 8:39 ` Robert Schwebel
2012-07-20 8:39 ` Robert Schwebel
2012-07-20 11:32 ` Marek Vasut
2012-07-20 11:32 ` Marek Vasut
2012-07-20 14:09 ` Lars-Peter Clausen
2012-07-20 14:09 ` Lars-Peter Clausen
2012-07-22 19:48 ` Jonathan Cameron
2012-07-20 14:11 ` Lars-Peter Clausen
2012-07-20 14:11 ` Lars-Peter Clausen
2012-07-20 15:12 ` Marek Vasut
2012-07-20 15:12 ` Marek Vasut
2012-07-09 9:19 ` Juergen Beisert
2012-07-09 9:19 ` Juergen Beisert
2012-07-09 9:52 ` Lars-Peter Clausen
2012-07-09 9:52 ` Lars-Peter Clausen
2012-07-09 10:03 ` Marek Vasut
2012-07-09 10:03 ` Marek Vasut
2012-07-10 9:20 ` Juergen Beisert
2012-07-10 9:20 ` Juergen Beisert
2012-07-10 9:26 ` Marek Vasut
2012-07-10 9:26 ` Marek Vasut
2012-07-10 9:49 ` Juergen Beisert
2012-07-10 9:49 ` Juergen Beisert
2012-07-10 10:08 ` Marek Vasut
2012-07-10 10:08 ` Marek Vasut
2012-07-10 10:26 ` Juergen Beisert
2012-07-10 10:26 ` Juergen Beisert
2012-07-10 10:35 ` Lars-Peter Clausen
2012-07-10 10:35 ` Lars-Peter Clausen
2012-07-10 10:41 ` Juergen Beisert
2012-07-10 10:41 ` Juergen Beisert
2012-07-10 10:45 ` Marek Vasut
2012-07-10 10:45 ` Marek Vasut
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=201207191623.14492.marex@denx.de \
--to=marex@denx.de \
--cc=jbe@pengutronix.de \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=wd@denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.