static void lis3l02dq_trigger_bh_to_ring(struct work_struct *work_s) { struct iio_sw_ring_helper_state *h = container_of(work_s, struct iio_sw_ring_helper_state, work_trigger_to_ring); struct lis3l02dq_state *st = lis3l02dq_h_to_s(h); st->inter = 0; iio_sw_trigger_bh_to_ring(work_s); }
/** * lis3l02dq_data_rdy_trig_poll() the event handler for the data rdy trig **/ static int lis3l02dq_data_rdy_trig_poll(struct iio_dev *indio_dev, int index, s64 timestamp, int no_test) { struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); struct lis3l02dq_state *st = lis3l02dq_h_to_s(h); iio_trigger_poll(st->trig, timestamp); return IRQ_HANDLED; }
/** * lis3l02dq_poll_func_th() top half interrupt handler called by trigger * @private_data: iio_dev **/ static void lis3l02dq_poll_func_th(struct iio_dev *indio_dev, s64 time) { struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); struct lis3l02dq_state *st = lis3l02dq_h_to_s(h); /* in this case we need to slightly extend the helper function */ iio_sw_poll_func_th(indio_dev, time); /* Indicate that this interrupt is being handled */ /* Technically this is trigger related, but without this * handler running there is currently now way for the interrupt * to clear. */ st->inter = 1; }
static int lis3l02dq_get_ring_element(struct iio_sw_ring_helper_state *h, u8 *buf) { int ret, i; u8 *rx_array ; s16 *data = (s16 *)buf; rx_array = kzalloc(4 * (h->indio_dev->ring->scan_count), GFP_KERNEL); if (rx_array == NULL) return -ENOMEM; ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array); if (ret < 0) return ret; for (i = 0; i < h->indio_dev->ring->scan_count; i++) data[i] = combine_8_to_16(rx_array[i*4+1], rx_array[i*4+3]); kfree(rx_array); return i*sizeof(data[0]); }
/** * lis3l02dq_spi_read_reg_8() - read single byte from a single register * @dev: device asosciated with child of actual device (iio_dev or iio_trig) * @reg_address: the address of the register to be read * @val: pass back the resulting value **/ int lis3l02dq_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) { int ret; struct spi_message msg; struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); struct lis3l02dq_state *st = lis3l02dq_h_to_s(h); struct spi_transfer xfer = { .tx_buf = st->tx, .rx_buf = st->rx, .bits_per_word = 8, .len = 2, .cs_change = 1, }; mutex_lock(&st->buf_lock); st->tx[0] = LIS3L02DQ_READ_REG(reg_address); st->tx[1] = 0; spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(st->us, &msg); *val = st->rx[1]; mutex_unlock(&st->buf_lock); return ret; } /** * lis3l02dq_spi_write_reg_8() - write single byte to a register * @dev: device associated with child of actual device (iio_dev or iio_trig) * @reg_address: the address of the register to be written * @val: the value to write **/ int lis3l02dq_spi_write_reg_8(struct device *dev, u8 reg_address, u8 *val) { int ret; struct spi_message msg; struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); struct lis3l02dq_state *st = lis3l02dq_h_to_s(h); struct spi_transfer xfer = { .tx_buf = st->tx, .bits_per_word = 8, .len = 2, .cs_change = 1, }; mutex_lock(&st->buf_lock); st->tx[0] = LIS3L02DQ_WRITE_REG(reg_address); st->tx[1] = *val; spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(st->us, &msg); mutex_unlock(&st->buf_lock); return ret; } /** * lisl302dq_spi_write_reg_s16() - write 2 bytes to a pair of registers * @dev: device associated with child of actual device (iio_dev or iio_trig) * @reg_address: the address of the lower of the two registers. Second register * is assumed to have address one greater. * @val: value to be written **/ static int lis3l02dq_spi_write_reg_s16(struct device *dev, u8 lower_reg_address, s16 value) { int ret; struct spi_message msg; struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); struct lis3l02dq_state *st = lis3l02dq_h_to_s(h); struct spi_transfer xfers[] = { { .tx_buf = st->tx, .bits_per_word = 8, .len = 2, .cs_change = 1, }, { .tx_buf = st->tx + 2,