Changes in 4.9.293 HID: introduce hid_is_using_ll_driver HID: add hid_is_usb() function to make it simpler for USB detection HID: add USB_HID dependancy to hid-prodikeys HID: add USB_HID dependancy to hid-chicony HID: add USB_HID dependancy on some USB HID drivers HID: wacom: fix problems when device is not a valid USB device HID: check for valid USB device for many HID drivers can: sja1000: fix use after free in ems_pcmcia_add_card() nfc: fix potential NULL pointer deref in nfc_genl_dump_ses_done IB/hfi1: Correct guard on eager buffer deallocation mm: bdi: initialize bdi_min_ratio when bdi is unregistered ALSA: ctl: Fix copy of updated id with element read/write ALSA: pcm: oss: Fix negative period/buffer sizes ALSA: pcm: oss: Limit the period size to 16MB ALSA: pcm: oss: Handle missing errors in snd_pcm_oss_change_params*() tracefs: Have new files inherit the ownership of their parent can: pch_can: pch_can_rx_normal: fix use after free libata: add horkage for ASMedia 1092 wait: add wake_up_pollfree() binder: use wake_up_pollfree() signalfd: use wake_up_pollfree() tracefs: Set all files to the same group ownership as the mount option block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2) net: cdc_ncm: Allow for dwNtbOutMaxSize to be unset or zero net: altera: set a couple error code in probe() net: fec: only clear interrupt of handling queue in fec_enet_rx_queue() net, neigh: clear whole pneigh_entry at alloc time net/qla3xxx: fix an error code in ql_adapter_up() USB: gadget: detect too-big endpoint 0 requests USB: gadget: zero allocate endpoint 0 buffers usb: core: config: fix validation of wMaxPacketValue entries usb: core: config: using bit mask instead of individual bits iio: stk3310: Don't return error code in interrupt handler iio: mma8452: Fix trigger reference couting iio: ltr501: Don't return error code in trigger handler iio: kxsd9: Don't return error code in trigger handler iio: itg3200: Call iio_trigger_notify_done() on error iio: accel: kxcjk-1013: Fix possible memory leak in probe and remove irqchip/armada-370-xp: Fix return value of armada_370_xp_msi_alloc() irqchip/armada-370-xp: Fix support for Multi-MSI interrupts irqchip/irq-gic-v3-its.c: Force synchronisation when issuing INVALL irqchip: nvic: Fix offset for Interrupt Priority Offsets Linux 4.9.293 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I4f94616f8a0fc5c2fa5b41d49108d7c853d5796a
161 lines
3.7 KiB
C
161 lines
3.7 KiB
C
/*
|
|
* itg3200_buffer.c -- support InvenSense ITG3200
|
|
* Digital 3-Axis Gyroscope driver
|
|
*
|
|
* Copyright (c) 2011 Christian Strobel <christian.strobel@iis.fraunhofer.de>
|
|
* Copyright (c) 2011 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
|
|
* Copyright (c) 2012 Thorsten Nowak <thorsten.nowak@iis.fraunhofer.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/slab.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/iio/iio.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/iio/gyro/itg3200.h>
|
|
|
|
|
|
static int itg3200_read_all_channels(struct i2c_client *i2c, __be16 *buf)
|
|
{
|
|
u8 tx = 0x80 | ITG3200_REG_TEMP_OUT_H;
|
|
struct i2c_msg msg[2] = {
|
|
{
|
|
.addr = i2c->addr,
|
|
.flags = i2c->flags,
|
|
.len = 1,
|
|
.buf = &tx,
|
|
},
|
|
{
|
|
.addr = i2c->addr,
|
|
.flags = i2c->flags | I2C_M_RD,
|
|
.len = ITG3200_SCAN_ELEMENTS * sizeof(s16),
|
|
.buf = (char *)&buf,
|
|
},
|
|
};
|
|
|
|
return i2c_transfer(i2c->adapter, msg, 2);
|
|
}
|
|
|
|
static irqreturn_t itg3200_trigger_handler(int irq, void *p)
|
|
{
|
|
struct iio_poll_func *pf = p;
|
|
struct iio_dev *indio_dev = pf->indio_dev;
|
|
struct itg3200 *st = iio_priv(indio_dev);
|
|
/*
|
|
* Ensure correct alignment and padding including for the
|
|
* timestamp that may be inserted.
|
|
*/
|
|
struct {
|
|
__be16 buf[ITG3200_SCAN_ELEMENTS];
|
|
s64 ts __aligned(8);
|
|
} scan;
|
|
|
|
int ret = itg3200_read_all_channels(st->i2c, scan.buf);
|
|
if (ret < 0)
|
|
goto error_ret;
|
|
|
|
iio_push_to_buffers_with_timestamp(indio_dev, &scan, pf->timestamp);
|
|
|
|
error_ret:
|
|
iio_trigger_notify_done(indio_dev->trig);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
int itg3200_buffer_configure(struct iio_dev *indio_dev)
|
|
{
|
|
return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
|
|
itg3200_trigger_handler, NULL);
|
|
}
|
|
|
|
void itg3200_buffer_unconfigure(struct iio_dev *indio_dev)
|
|
{
|
|
iio_triggered_buffer_cleanup(indio_dev);
|
|
}
|
|
|
|
|
|
static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig,
|
|
bool state)
|
|
{
|
|
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
|
|
int ret;
|
|
u8 msc;
|
|
|
|
ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_IRQ_CONFIG, &msc);
|
|
if (ret)
|
|
goto error_ret;
|
|
|
|
if (state)
|
|
msc |= ITG3200_IRQ_DATA_RDY_ENABLE;
|
|
else
|
|
msc &= ~ITG3200_IRQ_DATA_RDY_ENABLE;
|
|
|
|
ret = itg3200_write_reg_8(indio_dev, ITG3200_REG_IRQ_CONFIG, msc);
|
|
if (ret)
|
|
goto error_ret;
|
|
|
|
error_ret:
|
|
return ret;
|
|
|
|
}
|
|
|
|
static const struct iio_trigger_ops itg3200_trigger_ops = {
|
|
.owner = THIS_MODULE,
|
|
.set_trigger_state = &itg3200_data_rdy_trigger_set_state,
|
|
};
|
|
|
|
int itg3200_probe_trigger(struct iio_dev *indio_dev)
|
|
{
|
|
int ret;
|
|
struct itg3200 *st = iio_priv(indio_dev);
|
|
|
|
st->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
|
|
indio_dev->id);
|
|
if (!st->trig)
|
|
return -ENOMEM;
|
|
|
|
ret = request_irq(st->i2c->irq,
|
|
&iio_trigger_generic_data_rdy_poll,
|
|
IRQF_TRIGGER_RISING,
|
|
"itg3200_data_rdy",
|
|
st->trig);
|
|
if (ret)
|
|
goto error_free_trig;
|
|
|
|
|
|
st->trig->dev.parent = &st->i2c->dev;
|
|
st->trig->ops = &itg3200_trigger_ops;
|
|
iio_trigger_set_drvdata(st->trig, indio_dev);
|
|
ret = iio_trigger_register(st->trig);
|
|
if (ret)
|
|
goto error_free_irq;
|
|
|
|
/* select default trigger */
|
|
indio_dev->trig = iio_trigger_get(st->trig);
|
|
|
|
return 0;
|
|
|
|
error_free_irq:
|
|
free_irq(st->i2c->irq, st->trig);
|
|
error_free_trig:
|
|
iio_trigger_free(st->trig);
|
|
return ret;
|
|
}
|
|
|
|
void itg3200_remove_trigger(struct iio_dev *indio_dev)
|
|
{
|
|
struct itg3200 *st = iio_priv(indio_dev);
|
|
|
|
iio_trigger_unregister(st->trig);
|
|
free_irq(st->i2c->irq, st->trig);
|
|
iio_trigger_free(st->trig);
|
|
}
|