From: Jonathan Cameron <jic23@cam.ac.uk>
To: Barry Song <21cnbao@gmail.com>
Cc: "Song, Barry" <Barry.Song@analog.com>,
linux-iio@vger.kernel.org,
uclinux-dist-devel@blackfin.uclinux.org,
manuel.stahl@iis.fraunhofer.de, jic23@hermes.cam.ac.uk
Subject: Re: [Uclinux-dist-devel] IIO ring buffer
Date: Thu, 08 Jul 2010 16:04:00 +0100 [thread overview]
Message-ID: <4C35E8E0.8050905@cam.ac.uk> (raw)
In-Reply-To: <AANLkTinTdyiv6c6lho50SpgDAJwCcUZ1jN5nQaT8oR_-@mail.gmail.com>
<snip>
>>>> The rest of your factoring out obviously requires the shared driver
>>>> state structure. This all makes sense if we think that is a desirable
>>>> thing to do.
>>>>> +int iio_probe_common_trigger(struct iio_dev *indio_dev)
>>>>> +{
>>>>> + int ret;
>>>>> + struct iio_state *st = indio_dev->dev_data;
>>>>> +
>>>>> + st->trig = iio_allocate_trigger();
>>>>> + st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
>>>>> + if (!st->trig->name) {
>>>>> + ret = -ENOMEM;
>>>>> + goto error_free_trig;
>>>>> + }
>>>>> + snprintf((char *)st->trig->name,
>>>>> + IIO_TRIGGER_NAME_LENGTH,
>>>>> + "iio-dev%d", indio_dev->id);
>>>>> + st->trig->dev.parent = st->parent_dev;
>>>>> + st->trig->owner = THIS_MODULE;
>>>>> + st->trig->private_data = st;
>>>>> + st->trig->set_trigger_state = &iio_common_trigger_set_state;
>>>>> + st->trig->try_reenable = &iio_common_trigger_try_reen;
>>>>> + st->trig->control_attrs = &iio_trigger_attr_group;
>>>>> + ret = iio_trigger_register(st->trig);
>>>>> +
>>>>> + /* select default trigger */
>>>>> + indio_dev->trig = st->trig;
>>>>> + if (ret)
>>>>> + goto error_free_trig_name;
>>>>> +
>>>>> + return 0;
>>>>> +
>>>>> +error_free_trig_name:
>>>>> + kfree(st->trig->name);
>>>>> +error_free_trig:
>>>>> + iio_free_trigger(st->trig);
>>>>> +
>>>>> + return ret;
>>>>> +}
>>>>> +EXPORT_SYMBOL(iio_probe_common_trigger);
>>>>> +
>>>>
>>>>
>>>>> +void iio_remove_common_trigger(struct iio_dev *indio_dev)
>>>>> +{
>>>>> + struct iio_state *state = indio_dev->dev_data;
>>>>> +
>>>>> + iio_trigger_unregister(state->trig);
>>>>> + kfree(state->trig->name);
>>>>> + iio_free_trigger(state->trig);
>>>>> +}
>>>>> +EXPORT_SYMBOL(iio_remove_common_trigger);
>>>>
>>>> snipped rest as it is obvious boiler pate.
>
> For this, how about we let bottom driver to implement
> set_trigger_state(), try_reenable(), and control_attrs of trigger, but
> probe() and remove() can be common like this:
>
> drivers/staging/iio/ring_sw.h
>
> struct iio_sw_ring_helper_state {
> struct work_struct work_trigger_to_ring;
> struct iio_dev *indio_dev;
I'm not sure this wants to be in this struct. The trigger and ring are intended
to be (more or less) completely separable. If we do this, then we immediately
cannot use this code with devices not supplying a trigger, or those that are supplying
several different ones.
Again, you have highlighted an area with a lot of shared code, but perhaps some
care is needed to maximise the gain without restricting the generality of the code.
> + struct iio_trigger *trig;
> int (*get_ring_element)(struct iio_sw_ring_helper_state *st, u8 *buf);
> s64 last_timestamp;
> };
>
> drivers/staging/iio/ring_sw.c
>
> +int iio_sw_probe_trigger(struct iio_dev *indio_dev, char *name,
> struct attribute_group *attr_group)
> +{
> + int ret;
> + struct iio_sw_ring_helper_state *st = (struct
> iio_sw_ring_helper_state *)indio_dev->dev_data;
>
Perhaps we can give iio_allocate_trigger some parameters
and effectively move much of this shared functionality in there?
The tricky bit is the name, as it has different conventions for
the triggers that are not coming from devices (e.g. gpio)...
> + st->trig = iio_allocate_trigger();
Aside: a kasprintf call can clean this next bit up.
> + st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
> + if (!st->trig->name) {
> + ret = -ENOMEM;
> + goto error_free_trig;
> + }
> + snprintf((char *)st->trig->name,
> + IIO_TRIGGER_NAME_LENGTH,
> + "%s%d", name, indio_dev->id);
> + st->trig->dev.parent = st->parent_dev;
> + st->trig->owner = THIS_MODULE;
The owner bit just went wrong if we do this as it is no longer the
device driver module.
> + st->trig->private_data = st;
> + st->trig->control_attrs = attr_group;
> + ret = iio_trigger_register(st->trig);
>
> + indio_dev->trig = st->trig;
> + if (ret)
> + goto error_free_trig_name;
>
> + return 0;
>
> +error_free_trig_name:
> kfree(st->trig->name);
> +error_free_trig:
> + iio_free_trigger(st->trig);
>
> + return ret;
> +}
> +EXPORT_SYMBOL(iio_sw_probe_trigger);
>
> +void iio_sw_remove_trigger(struct iio_dev *indio_dev)
> +{
> + struct iio_state *state = indio_dev->dev_data;
> +
> + iio_trigger_unregister(state->trig);
> + kfree(state->trig->name);
> + iio_free_trigger(state->trig);
> +}
> +EXPORT_SYMBOL(iio_sw_remove_trigger);
>
> name and attribute_group can be params for iio_sw_probe_trigger()
> since functions depend on them. But set_trigger_state(),
> try_reenable() can be given chip-special entries in bottom driver
> after iio_sw_probe_trigger() returns successfully.
>
Can we hold off on doing anything major in here for now. I'd like
to see a few more drivers doing event handling as well as triggers
as they quite often interact to a degree and may well complicate
things
with unifying the trigger code. (not sure yet!)
<snip>
Thanks for looking at all the other patches. I'll send those
off to Greg shortly.
Jonathan
prev parent reply other threads:[~2010-07-08 15:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <0F1B54C89D5F954D8535DB252AF412FA05A222FC@chinexm1.ad.analog.com>
2010-02-22 11:16 ` IIO ring buffer Jonathan Cameron
2010-02-23 4:11 ` Song, Barry
2010-02-23 11:44 ` Jonathan Cameron
2010-02-24 6:42 ` Song, Barry
2010-02-24 6:48 ` [Uclinux-dist-devel] " Song, Barry
2010-02-24 14:10 ` Jonathan Cameron
2010-03-02 9:57 ` Barry Song
2010-03-02 10:45 ` J.I. Cameron
2010-03-03 3:26 ` Barry Song
2010-03-03 5:59 ` [Uclinux-dist-devel] " Zhang, Sonic
2010-03-04 12:33 ` Jonathan Cameron
2010-03-08 3:41 ` Barry Song
2010-03-08 11:23 ` Jonathan Cameron
2010-06-02 8:01 ` [Uclinux-dist-devel] " Barry Song
2010-06-02 13:21 ` Jonathan Cameron
2010-06-10 4:48 ` Barry Song
2010-06-10 4:51 ` Barry Song
2010-06-10 13:48 ` Jonathan Cameron
2010-06-11 3:19 ` Barry Song
2010-06-11 10:22 ` Jonathan Cameron
2010-06-12 2:26 ` Barry Song
2010-06-12 17:35 ` Jonathan Cameron
2010-06-21 9:21 ` Barry Song
2010-06-25 14:11 ` Jonathan Cameron
2010-06-25 17:18 ` Jonathan Cameron
2010-06-28 7:59 ` Barry Song
2010-06-28 10:26 ` Jonathan Cameron
2010-06-30 7:51 ` Barry Song
2010-06-30 14:30 ` Jonathan Cameron
2010-07-08 10:38 ` Barry Song
2010-07-08 15:04 ` Jonathan Cameron [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=4C35E8E0.8050905@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=21cnbao@gmail.com \
--cc=Barry.Song@analog.com \
--cc=jic23@hermes.cam.ac.uk \
--cc=linux-iio@vger.kernel.org \
--cc=manuel.stahl@iis.fraunhofer.de \
--cc=uclinux-dist-devel@blackfin.uclinux.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