Exemplo n.º 1
0
static int ade7759_spi_read_reg_8(struct device *dev,
		u8 reg_address,
		u8 *val)
{
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
	struct ade7759_state *st = iio_priv(indio_dev);
	int ret;

	ret = spi_w8r8(st->us, ADE7759_READ_REG(reg_address));
	if (ret < 0) {
		dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
				reg_address);
		return ret;
	}
	*val = ret;

	return 0;
}
Exemplo n.º 2
0
static int ade7759_spi_read_reg_16(struct device *dev,
                                   u8 reg_address,
                                   u16 *val)
{
    struct iio_dev *indio_dev = dev_get_drvdata(dev);
    struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
    int ret;

    ret = spi_w8r16(st->us, ADE7759_READ_REG(reg_address));
    if (ret < 0) {
        dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
                reg_address);
        return ret;
    }

    *val = ret;
    *val = be16_to_cpup(val);

    return 0;
}
Exemplo n.º 3
0
		u64 *val)
{
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
	struct ade7759_state *st = iio_priv(indio_dev);
	int ret;
	struct spi_transfer xfers[] = {
		{
			.tx_buf = st->tx,
			.rx_buf = st->rx,
			.bits_per_word = 8,
			.len = 6,
		},
	};

	mutex_lock(&st->buf_lock);
	st->tx[0] = ADE7759_READ_REG(reg_address);
	memset(&st->tx[1], 0 , 5);

	ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
	if (ret) {
		dev_err(&st->us->dev, "problem when reading 40 bit register 0x%02X",
				reg_address);
		goto error_ret;
	}
	*val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
		(st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];

error_ret:
	mutex_unlock(&st->buf_lock);
	return ret;
}