Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354216
b: refs/heads/master
c: 9ab82f0
h: refs/heads/master
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Jan 26, 2013
1 parent 800c45a commit d3f1d79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c21ab7005140bdc5898907f73a5d73a86ea60a5d
refs/heads/master: 9ab82f071125e340a052570df90813b11574f8d4
61 changes: 25 additions & 36 deletions trunk/drivers/staging/iio/gyro/adis16080_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,32 @@ struct adis16080_state {
u8 buf[2] ____cacheline_aligned;
};

static int adis16080_spi_write(struct iio_dev *indio_dev,
u16 val)
static int adis16080_read_sample(struct iio_dev *indio_dev,
u16 addr, int *val)
{
int ret;
struct adis16080_state *st = iio_priv(indio_dev);

mutex_lock(&st->buf_lock);
st->buf[0] = val >> 8;
st->buf[1] = val;

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

return ret;
}

static int adis16080_spi_read(struct iio_dev *indio_dev,
u16 *val)
{
struct spi_message m;
int ret;
struct adis16080_state *st = iio_priv(indio_dev);
struct spi_transfer t[] = {
{
.tx_buf = &st->buf,
.len = 2,
.cs_change = 1,
}, {
.rx_buf = &st->buf,
.len = 2,
},
};

mutex_lock(&st->buf_lock);
st->buf[0] = addr >> 8;
st->buf[1] = addr;

ret = spi_read(st->us, st->buf, 2);
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);

ret = spi_sync(st->us, &m);
if (ret == 0)
*val = sign_extend32(((st->buf[0] & 0xF) << 8) | st->buf[1], 11);
mutex_unlock(&st->buf_lock);
Expand All @@ -81,28 +81,17 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
int *val2,
long mask)
{
int ret = -EINVAL;
u16 ut = 0;
/* Take the iio_dev status lock */
int ret;

mutex_lock(&indio_dev->mlock);
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = adis16080_spi_write(indio_dev,
chan->address |
ADIS16080_DIN_WRITE);
if (ret < 0)
break;
ret = adis16080_spi_read(indio_dev, &ut);
if (ret < 0)
break;
*val = ut;
ret = IIO_VAL_INT;
break;
mutex_lock(&indio_dev->mlock);
ret = adis16080_read_sample(indio_dev, chan->address, val);
mutex_unlock(&indio_dev->mlock);
return ret ? ret : IIO_VAL_INT;
}
mutex_unlock(&indio_dev->mlock);

return ret;
return -EINVAL;
}

static const struct iio_chan_spec adis16080_channels[] = {
Expand Down

0 comments on commit d3f1d79

Please sign in to comment.