From: Jonathan Cameron <jic23@kernel.org>
To: Simon Wood <simon@mungewell.org>, linux-input@vger.kernel.org
Cc: Frank Praznik <frank.praznik@oh.rr.com>, linux-iio@vger.kernel.org
Subject: Re: [RFC_v2 2/4] HID: hid-sony: Add IIO buffer support for SixAxis Controller
Date: Sun, 05 Jul 2015 14:53:44 +0100 [thread overview]
Message-ID: <559936E8.6040608@kernel.org> (raw)
In-Reply-To: <1435105830-2297-3-git-send-email-simon@mungewell.org>
On 24/06/15 01:30, Simon Wood wrote:
> ---
> drivers/hid/hid-sony.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 47 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
> index c4686e3..b7a7f0d 100644
> --- a/drivers/hid/hid-sony.c
> +++ b/drivers/hid/hid-sony.c
> @@ -37,6 +37,11 @@
> #include <linux/idr.h>
> #include <linux/input/mt.h>
> #include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
This sysfs one shouldn't have become a dependency as part of adding buffered support...
> +#include <linux/iio/buffer.h>
> +#include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/triggered_buffer.h>
> +#include <linux/interrupt.h>
>
> #include "hid-ids.h"
>
> @@ -852,6 +857,7 @@ enum sony_iio_axis {
>
> struct sony_iio {
> struct sony_sc *sc;
> + u8 buff[16]; /* 3x 16-bit + padding + timestamp */
Make it u16 buff[8] to cut down on the casts below.
> #endif
> };
>
> @@ -861,6 +867,7 @@ static __u8 *sixaxis_fixup(struct hid_device *hdev, __u8 *rdesc,
> *rsize = sizeof(sixaxis_rdesc);
> return sixaxis_rdesc;
> }
> +
Some stray white space cleanups in here that should be in a separate patch.
> static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
> unsigned int *rsize)
> {
> @@ -1841,12 +1848,20 @@ static int sony_iio_read_raw(struct iio_dev *indio_dev,
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
> BIT(IIO_CHAN_INFO_OFFSET), \
> .address = AXIS_ACC_##_axis, \
> + .scan_index = AXIS_ACC_##_axis, \
> + .scan_type = { \
> + .sign = 's', \
> + .realbits = 16, \
> + .storagebits = 16, \
> + .shift = 0, \
Don't bother specifying shift=0 as it's the default.
> + }, \
> }
>
> static const struct iio_chan_spec sony_sixaxis_channels[] = {
> SONY_ACC_CHANNEL(X),
> SONY_ACC_CHANNEL(Y),
> SONY_ACC_CHANNEL(Z),
> + IIO_CHAN_SOFT_TIMESTAMP(3),
> };
>
> static const struct iio_info sony_iio_info = {
> @@ -1854,6 +1869,25 @@ static const struct iio_info sony_iio_info = {
> .driver_module = THIS_MODULE,
> };
>
> +static irqreturn_t sony_iio_trigger_handler(int irq, void *p)
> +{
> + struct iio_poll_func *pf = p;
> + struct iio_dev *indio_dev = pf->indio_dev;
> + struct sony_iio *data = iio_priv(indio_dev);
> + int64_t time_ns = iio_get_time_ns();
> + int bit, i = 0;
> +
> + for_each_set_bit(bit, indio_dev->active_scan_mask,
> + indio_dev->masklength) {
> + ((u16 *)data->buff)[i++] = data->sc->last_data[bit];
> + }
> +
> + iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns);
Put the iio_get_time_ns call directly in rather than bothering with the local
variable.
> + iio_trigger_notify_done(indio_dev->trig);
> +
> + return IRQ_HANDLED;
> +}
> +
> static int sony_iio_probe(struct sony_sc *sc)
> {
> struct hid_device *hdev = sc->hdev;
> @@ -1871,18 +1905,27 @@ static int sony_iio_probe(struct sony_sc *sc)
>
> indio_dev->dev.parent = &hdev->dev;
> indio_dev->name = dev_name(&hdev->dev);
> - indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED;
> indio_dev->info = &sony_iio_info;
> indio_dev->channels = sony_sixaxis_channels;
> - indio_dev->num_channels = 3;
> + indio_dev->num_channels = ARRAY_SIZE(sony_sixaxis_channels);
> +
> + ret = iio_triggered_buffer_setup(indio_dev, NULL,
> + sony_iio_trigger_handler, NULL);
> + if (ret < 0) {
> + dev_err(&hdev->dev, "unable to setup iio triggered buffer\n");
> + goto err;
> + }
>
> ret = iio_device_register(indio_dev);
> if (ret < 0) {
> hid_err(hdev, "Unable to register iio device\n");
> - goto err;
> + goto err_buffer_cleanup;
> }
> return 0;
>
> +err_buffer_cleanup:
> + iio_triggered_buffer_cleanup(indio_dev);
> err:
> kfree(indio_dev);
> sc->indio_dev = NULL;
> @@ -1895,6 +1938,7 @@ static void sony_iio_remove(struct sony_sc *sc)
> return;
>
> iio_device_unregister(sc->indio_dev);
> + iio_triggered_buffer_cleanup(sc->indio_dev);
> kfree(sc->indio_dev);
> sc->indio_dev = NULL;
> }
>
next prev parent reply other threads:[~2015-07-05 13:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-24 0:30 [RFC_v2 0/4] HID: hid-sony: Add IIO Suport for Motion Controllers Simon Wood
2015-06-24 0:30 ` [RFC_v2 1/4] HID: hid-sony: Add basic IIO support for SixAxis Controller Simon Wood
2015-06-24 9:13 ` Antonio Ospite
2015-06-24 14:29 ` Daniel Baluta
2015-06-24 15:20 ` simon
2015-07-05 13:49 ` Jonathan Cameron
2015-06-24 0:30 ` [RFC_v2 2/4] HID: hid-sony: Add IIO buffer " Simon Wood
2015-07-05 13:53 ` Jonathan Cameron [this message]
2015-06-24 0:30 ` [RFC_v2 3/4] HID: hid-sony: Add IIO trigger " Simon Wood
2015-07-05 13:58 ` Jonathan Cameron
2015-06-24 0:30 ` [RFC_v2 4/4] HID: hid-sony: Add IIO support for DualShock4 Controller Simon Wood
2015-07-05 14:01 ` Jonathan Cameron
2015-06-24 9:06 ` [RFC_v2 0/4] HID: hid-sony: Add IIO Suport for Motion Controllers Antonio Ospite
2015-06-24 15:14 ` simon
2015-07-23 16:53 ` Bastien Nocera
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=559936E8.6040608@kernel.org \
--to=jic23@kernel.org \
--cc=frank.praznik@oh.rr.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=simon@mungewell.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;
as well as URLs for NNTP newsgroup(s).