From: Simon Wood <simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> To: linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Frank Praznik <frank.praznik-oKii7tqusJgAvxtiuMwx3w@public.gmane.org>, linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Simon Wood <simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> Subject: [RFC_v2 3/4] HID: hid-sony: Add IIO trigger support for SixAxis Controller Date: Tue, 23 Jun 2015 18:30:29 -0600 [thread overview] Message-ID: <1435105830-2297-4-git-send-email-simon@mungewell.org> (raw) In-Reply-To: <1435105830-2297-1-git-send-email-simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> --- drivers/hid/hid-sony.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index b7a7f0d..ce0526d 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -39,9 +39,11 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/trigger.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> #include <linux/interrupt.h> +#include <linux/irq_work.h> #include "hid-ids.h" @@ -855,9 +857,14 @@ enum sony_iio_axis { AXIS_ACC_Z, }; +static void sony_iio_trigger_work(struct irq_work *work); + struct sony_iio { struct sony_sc *sc; + struct iio_trigger *trig; + u8 buff[16]; /* 3x 16-bit + padding + timestamp */ + struct irq_work work; #endif }; @@ -1076,6 +1083,13 @@ static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, sc->last_data[AXIS_ACC_X] = (rd[42] << 8) + rd[41]; sc->last_data[AXIS_ACC_Y] = (rd[44] << 8) + rd[43]; sc->last_data[AXIS_ACC_Z] = (rd[46] << 8) + rd[45]; + + if (sc->indio_dev) { + struct sony_iio *data; + + data = iio_priv(sc->indio_dev); + sony_iio_trigger_work(&data->work); + } #endif sixaxis_parse_report(sc, rd, size); } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && @@ -1869,6 +1883,28 @@ static const struct iio_info sony_iio_info = { .driver_module = THIS_MODULE, }; +static void sony_iio_trigger_work(struct irq_work *work) +{ + struct sony_iio *data = container_of(work, struct sony_iio, work); + + iio_trigger_poll(data->trig); +} + +static ssize_t sony_iio_trigger_poll(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct iio_trigger *trig = to_iio_trigger(dev); + struct sony_iio *data = iio_trigger_get_drvdata(trig); + + irq_work_queue(&data->work); + + return count; +} + +static const struct iio_trigger_ops sony_iio_trigger_ops = { + .owner = THIS_MODULE, +}; + static irqreturn_t sony_iio_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -1910,11 +1946,29 @@ static int sony_iio_probe(struct sony_sc *sc) indio_dev->channels = sony_sixaxis_channels; indio_dev->num_channels = ARRAY_SIZE(sony_sixaxis_channels); + data->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, + indio_dev->id); + if (!data->trig) { + ret = -ENOMEM; + goto err; + } + + data->trig->dev.parent = &hdev->dev; + data->trig->ops = &sony_iio_trigger_ops; + iio_trigger_set_drvdata(data->trig, indio_dev); + indio_dev->trig = iio_trigger_get(data->trig); + + init_irq_work(&data->work, sony_iio_trigger_work); + + ret = iio_trigger_register(data->trig); + if (ret) + goto err_trigger_free; + 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; + goto err_trigger_unregister; } ret = iio_device_register(indio_dev); @@ -1926,6 +1980,11 @@ static int sony_iio_probe(struct sony_sc *sc) err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); +err_trigger_unregister: + if (data->trig) + iio_trigger_unregister(data->trig); +err_trigger_free: + iio_trigger_free(data->trig); err: kfree(indio_dev); sc->indio_dev = NULL; @@ -1934,11 +1993,19 @@ err: static void sony_iio_remove(struct sony_sc *sc) { + struct sony_iio *data; + if (!sc->indio_dev) return; - iio_device_unregister(sc->indio_dev); + data = iio_priv(sc->indio_dev); + iio_triggered_buffer_cleanup(sc->indio_dev); + if (data->trig) + iio_trigger_unregister(data->trig); + iio_trigger_free(data->trig); + iio_device_unregister(sc->indio_dev); + kfree(sc->indio_dev); sc->indio_dev = NULL; } -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: Simon Wood <simon@mungewell.org> To: linux-input@vger.kernel.org Cc: Frank Praznik <frank.praznik@oh.rr.com>, linux-iio@vger.kernel.org, Simon Wood <simon@mungewell.org> Subject: [RFC_v2 3/4] HID: hid-sony: Add IIO trigger support for SixAxis Controller Date: Tue, 23 Jun 2015 18:30:29 -0600 [thread overview] Message-ID: <1435105830-2297-4-git-send-email-simon@mungewell.org> (raw) In-Reply-To: <1435105830-2297-1-git-send-email-simon@mungewell.org> --- drivers/hid/hid-sony.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index b7a7f0d..ce0526d 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -39,9 +39,11 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/trigger.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> #include <linux/interrupt.h> +#include <linux/irq_work.h> #include "hid-ids.h" @@ -855,9 +857,14 @@ enum sony_iio_axis { AXIS_ACC_Z, }; +static void sony_iio_trigger_work(struct irq_work *work); + struct sony_iio { struct sony_sc *sc; + struct iio_trigger *trig; + u8 buff[16]; /* 3x 16-bit + padding + timestamp */ + struct irq_work work; #endif }; @@ -1076,6 +1083,13 @@ static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, sc->last_data[AXIS_ACC_X] = (rd[42] << 8) + rd[41]; sc->last_data[AXIS_ACC_Y] = (rd[44] << 8) + rd[43]; sc->last_data[AXIS_ACC_Z] = (rd[46] << 8) + rd[45]; + + if (sc->indio_dev) { + struct sony_iio *data; + + data = iio_priv(sc->indio_dev); + sony_iio_trigger_work(&data->work); + } #endif sixaxis_parse_report(sc, rd, size); } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && @@ -1869,6 +1883,28 @@ static const struct iio_info sony_iio_info = { .driver_module = THIS_MODULE, }; +static void sony_iio_trigger_work(struct irq_work *work) +{ + struct sony_iio *data = container_of(work, struct sony_iio, work); + + iio_trigger_poll(data->trig); +} + +static ssize_t sony_iio_trigger_poll(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct iio_trigger *trig = to_iio_trigger(dev); + struct sony_iio *data = iio_trigger_get_drvdata(trig); + + irq_work_queue(&data->work); + + return count; +} + +static const struct iio_trigger_ops sony_iio_trigger_ops = { + .owner = THIS_MODULE, +}; + static irqreturn_t sony_iio_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -1910,11 +1946,29 @@ static int sony_iio_probe(struct sony_sc *sc) indio_dev->channels = sony_sixaxis_channels; indio_dev->num_channels = ARRAY_SIZE(sony_sixaxis_channels); + data->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, + indio_dev->id); + if (!data->trig) { + ret = -ENOMEM; + goto err; + } + + data->trig->dev.parent = &hdev->dev; + data->trig->ops = &sony_iio_trigger_ops; + iio_trigger_set_drvdata(data->trig, indio_dev); + indio_dev->trig = iio_trigger_get(data->trig); + + init_irq_work(&data->work, sony_iio_trigger_work); + + ret = iio_trigger_register(data->trig); + if (ret) + goto err_trigger_free; + 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; + goto err_trigger_unregister; } ret = iio_device_register(indio_dev); @@ -1926,6 +1980,11 @@ static int sony_iio_probe(struct sony_sc *sc) err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); +err_trigger_unregister: + if (data->trig) + iio_trigger_unregister(data->trig); +err_trigger_free: + iio_trigger_free(data->trig); err: kfree(indio_dev); sc->indio_dev = NULL; @@ -1934,11 +1993,19 @@ err: static void sony_iio_remove(struct sony_sc *sc) { + struct sony_iio *data; + if (!sc->indio_dev) return; - iio_device_unregister(sc->indio_dev); + data = iio_priv(sc->indio_dev); + iio_triggered_buffer_cleanup(sc->indio_dev); + if (data->trig) + iio_trigger_unregister(data->trig); + iio_trigger_free(data->trig); + iio_device_unregister(sc->indio_dev); + kfree(sc->indio_dev); sc->indio_dev = NULL; } -- 2.1.4
next prev parent reply other threads:[~2015-06-24 0:30 UTC|newest] Thread overview: 26+ 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 ` Simon Wood 2015-06-24 0:30 ` [RFC_v2 4/4] HID: hid-sony: Add IIO support for DualShock4 Controller Simon Wood [not found] ` <1435105830-2297-5-git-send-email-simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> 2015-07-05 14:01 ` Jonathan Cameron 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 [not found] ` <20150624110608.65a31e2a52bb2752352605db-qKGr9MkilAE@public.gmane.org> 2015-06-24 15:14 ` simon-wM4F9T/ekXmXDw4h08c5KA 2015-06-24 15:14 ` simon [not found] ` <1435105830-2297-1-git-send-email-simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> 2015-06-24 0:30 ` [RFC_v2 1/4] HID: hid-sony: Add basic IIO support for SixAxis Controller Simon Wood 2015-06-24 0:30 ` Simon Wood [not found] ` <1435105830-2297-2-git-send-email-simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> 2015-06-24 9:13 ` Antonio Ospite 2015-06-24 9:13 ` Antonio Ospite 2015-06-24 14:29 ` Daniel Baluta [not found] ` <20150624111343.9cbff925b0f25865fc6e5cd8-qKGr9MkilAE@public.gmane.org> 2015-06-24 15:20 ` simon-wM4F9T/ekXmXDw4h08c5KA 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-06-24 0:30 ` Simon Wood [not found] ` <1435105830-2297-3-git-send-email-simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> 2015-07-05 13:53 ` Jonathan Cameron 2015-07-05 13:53 ` Jonathan Cameron 2015-06-24 0:30 ` Simon Wood [this message] 2015-06-24 0:30 ` [RFC_v2 3/4] HID: hid-sony: Add IIO trigger " Simon Wood [not found] ` <1435105830-2297-4-git-send-email-simon-wM4F9T/ekXmXDw4h08c5KA@public.gmane.org> 2015-07-05 13:58 ` Jonathan Cameron 2015-07-05 13:58 ` Jonathan Cameron 2015-07-23 16:53 ` [RFC_v2 0/4] HID: hid-sony: Add IIO Suport for Motion Controllers Bastien Nocera 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=1435105830-2297-4-git-send-email-simon@mungewell.org \ --to=simon-wm4f9t/ekxmxdw4h08c5ka@public.gmane.org \ --cc=frank.praznik-oKii7tqusJgAvxtiuMwx3w@public.gmane.org \ --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.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: linkBe 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.