/** * 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 lis3l02dq_state *st = iio_dev_get_devdata(indio_dev); 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 writen * @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 lis3l02dq_state *st = iio_dev_get_devdata(indio_dev); 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 lis3l02dq_state *st = iio_dev_get_devdata(indio_dev); struct spi_transfer xfers[] = { { .tx_buf = st->tx, .bits_per_word = 8, .len = 2, .cs_change = 1, }, { .tx_buf = st->tx + 2,
} len = iio_scan_mask_count_to_right(dev_info, el->number); if (len < 0) { ret = len; goto error_free_data; } len = sprintf(buf, "ring %d\n", data[len]); error_free_data: kfree(data); error_ret: return ret ? ret : len; } static const u8 read_all_tx_array[] = { LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_X_L_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_X_H_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Y_L_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Y_H_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Z_L_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Z_H_ADDR), 0, }; static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) { struct spi_transfer *xfers; struct spi_message msg; int ret, i, j = 0; xfers = kzalloc((st->indio_dev->scan_count) * 2 * sizeof(*xfers), GFP_KERNEL);