/**
 * adis16220_spi_write_reg_8() - write single byte to a register
 * @indio_dev: iio device associated with child of actual device
 * @reg_address: the address of the register to be written
 * @val: the value to write
 **/
static int adis16220_spi_write_reg_8(struct iio_dev *indio_dev,
		u8 reg_address,
		u8 val)
{
	int ret;
	struct adis16220_state *st = iio_priv(indio_dev);

	mutex_lock(&st->buf_lock);
	st->tx[0] = ADIS16220_WRITE_REG(reg_address);
	st->tx[1] = val;

	ret = spi_write(st->us, st->tx, 2);
	mutex_unlock(&st->buf_lock);

	return ret;
}
Beispiel #2
0
            .tx_buf = st->tx,
            .bits_per_word = 8,
            .len = 2,
            .cs_change = 1,
            .delay_usecs = 25,
        }, {
            .tx_buf = st->tx + 2,
            .bits_per_word = 8,
            .len = 2,
            .cs_change = 1,
            .delay_usecs = 25,
        },
    };

    mutex_lock(&st->buf_lock);
    st->tx[0] = ADIS16220_WRITE_REG(lower_reg_address);
    st->tx[1] = value & 0xFF;
    st->tx[2] = ADIS16220_WRITE_REG(lower_reg_address + 1);
    st->tx[3] = (value >> 8) & 0xFF;

    spi_message_init(&msg);
    spi_message_add_tail(&xfers[0], &msg);
    spi_message_add_tail(&xfers[1], &msg);
    ret = spi_sync(st->us, &msg);
    mutex_unlock(&st->buf_lock);

    return ret;
}

/**
 * adis16220_spi_read_reg_16() - read 2 bytes from a 16-bit register