Skip to content

Commit

Permalink
Merge tag 'iio-for-3.9d' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/jic23/iio into staging-next

Jonathan writes:

"4th set of IIO new drivers cleanups and fixes for the 3.9 cycle
+ a new spi helper function.

1) Introduce spi_sync_transfer and use it within IIO.  Originally
   it was envisioned that this nice little boilerplate replacement
   would go through the spi tree, but Grant Likely stated he'd
   prefer we take it through IIO as the example usecases were all
   in IIO (and are also in this pull request).  Note that given
   their may have been some unresolved elements related to the
   coccinelle element of the patch, that has been stripped out
   and will doubtlessly follow at a later date (along with
   lots of other patches for drivers elsewhere in the tree).

2) New Invensense MPU6050 driver.  This is stripped down to pretty
   much the basics from the original submission with the intent
   to build up all the fancy bits in an incremental (and hence
   reviewable fashion). It's been through a good few revisions
   so nice to finally merge this.

3) Change to iio_channel_get api to simplify device tree based
   mappings.  The actual mappings are currently under review.

4) Build fixes for !CONFIG_IIO_TRIGGER in the st_sensors driver.
   This one snuck past during review and testing but got picked
   up by Randy Dunlap in a randconfig build.

5) Some max1363 cleanups and enhancements.

6) Some comment fixes to make them coherent and comprehensible.

7) Trivial build warning fix in mxs-lradc"
  • Loading branch information
Greg Kroah-Hartman committed Feb 11, 2013
2 parents 5305d74 + 09a642b commit ad463ac
Show file tree
Hide file tree
Showing 53 changed files with 1,646 additions and 246 deletions.
13 changes: 13 additions & 0 deletions Documentation/ABI/testing/sysfs-bus-iio-mpu6050
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
What: /sys/bus/iio/devices/iio:deviceX/in_gyro_matrix
What: /sys/bus/iio/devices/iio:deviceX/in_accel_matrix
What: /sys/bus/iio/devices/iio:deviceX/in_magn_matrix
KernelVersion: 3.4.0
Contact: linux-iio@vger.kernel.org
Description:
This is mounting matrix for motion sensors. Mounting matrix
is a 3x3 unitary matrix. A typical mounting matrix would look like
[0, 1, 0; 1, 0, 0; 0, 0, -1]. Using this information, it would be
easy to tell the relative positions among sensors as well as their
positions relative to the board that holds these sensors. Identity matrix
[1, 0, 0; 0, 1, 0; 0, 0, 1] means sensor chip and device are perfectly
aligned with each other. All axes are exactly the same.
3 changes: 1 addition & 2 deletions drivers/extcon/extcon-adc-jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ static int adc_jack_probe(struct platform_device *pdev)
;
data->num_conditions = i;

data->chan = iio_channel_get(dev_name(&pdev->dev),
pdata->consumer_channel);
data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);
if (IS_ERR(data->chan)) {
err = PTR_ERR(data->chan);
goto out;
Expand Down
6 changes: 1 addition & 5 deletions drivers/iio/accel/kxsd9.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro)

static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
{
struct spi_message msg;
int ret;
struct kxsd9_state *st = iio_priv(indio_dev);
struct spi_transfer xfers[] = {
Expand All @@ -112,10 +111,7 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)

mutex_lock(&st->buf_lock);
st->tx[0] = KXSD9_READ(address);
spi_message_init(&msg);
spi_message_add_tail(&xfers[0], &msg);
spi_message_add_tail(&xfers[1], &msg);
ret = spi_sync(st->us, &msg);
ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
if (ret)
return ret;
return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
Expand Down
9 changes: 7 additions & 2 deletions drivers/iio/accel/st_accel_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <linux/irq.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/trigger.h>
#include <linux/iio/buffer.h>

#include <linux/iio/common/st_sensors.h>
Expand Down Expand Up @@ -419,10 +419,15 @@ static const struct iio_info accel_info = {
.write_raw = &st_accel_write_raw,
};

#ifdef CONFIG_IIO_TRIGGER
static const struct iio_trigger_ops st_accel_trigger_ops = {
.owner = THIS_MODULE,
.set_trigger_state = ST_ACCEL_TRIGGER_SET_STATE,
};
#define ST_ACCEL_TRIGGER_OPS (&st_accel_trigger_ops)
#else
#define ST_ACCEL_TRIGGER_OPS NULL
#endif

int st_accel_common_probe(struct iio_dev *indio_dev)
{
Expand Down Expand Up @@ -455,7 +460,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
goto st_accel_common_probe_error;

err = st_sensors_allocate_trigger(indio_dev,
&st_accel_trigger_ops);
ST_ACCEL_TRIGGER_OPS);
if (err < 0)
goto st_accel_probe_trigger_error;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/iio/accel/st_accel_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger.h>

#include <linux/iio/common/st_sensors.h>
#include <linux/iio/common/st_sensors_i2c.h>
Expand Down
1 change: 0 additions & 1 deletion drivers/iio/accel/st_accel_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <linux/slab.h>
#include <linux/spi/spi.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger.h>

#include <linux/iio/common/st_sensors.h>
#include <linux/iio/common/st_sensors_spi.h>
Expand Down
81 changes: 49 additions & 32 deletions drivers/iio/adc/max1363.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ struct max1363_chip_info {
* @mask_low: bitmask for enabled low thresholds
* @thresh_high: high threshold values
* @thresh_low: low threshold values
* @vref: Reference voltage regulator
* @vref_uv: Actual (external or internal) reference voltage
*/
struct max1363_state {
struct i2c_client *client;
Expand All @@ -182,6 +184,8 @@ struct max1363_state {
/* 4x unipolar first then the fours bipolar ones */
s16 thresh_high[8];
s16 thresh_low[8];
struct regulator *vref;
u32 vref_uv;
};

#define MAX1363_MODE_SINGLE(_num, _mask) { \
Expand Down Expand Up @@ -393,23 +397,19 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
{
struct max1363_state *st = iio_priv(indio_dev);
int ret;
unsigned long scale_uv;

switch (m) {
case IIO_CHAN_INFO_RAW:
ret = max1363_read_single_chan(indio_dev, chan, val, m);
if (ret < 0)
return ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
if ((1 << (st->chip_info->bits + 1)) >
st->chip_info->int_vref_mv) {
*val = 0;
*val2 = 500000;
return IIO_VAL_INT_PLUS_MICRO;
} else {
*val = (st->chip_info->int_vref_mv)
>> st->chip_info->bits;
return IIO_VAL_INT;
}
scale_uv = st->vref_uv >> st->chip_info->bits;
*val = scale_uv / 1000;
*val2 = (scale_uv % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
Expand Down Expand Up @@ -1390,12 +1390,16 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = {

static int max1363_initial_setup(struct max1363_state *st)
{
st->setupbyte = MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD
| MAX1363_SETUP_POWER_UP_INT_REF
| MAX1363_SETUP_INT_CLOCK
st->setupbyte = MAX1363_SETUP_INT_CLOCK
| MAX1363_SETUP_UNIPOLAR
| MAX1363_SETUP_NORESET;

if (st->vref)
st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF;
else
st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF
| MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT;

/* Set scan mode writes the config anyway so wait until then */
st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte);
st->current_mode = &max1363_mode_table[st->chip_info->default_mode];
Expand All @@ -1410,8 +1414,9 @@ static int max1363_alloc_scan_masks(struct iio_dev *indio_dev)
unsigned long *masks;
int i;

masks = kzalloc(BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*sizeof(long)*
(st->chip_info->num_modes + 1), GFP_KERNEL);
masks = devm_kzalloc(&indio_dev->dev,
BITS_TO_LONGS(MAX1363_MAX_CHANNELS) * sizeof(long) *
(st->chip_info->num_modes + 1), GFP_KERNEL);
if (!masks)
return -ENOMEM;

Expand Down Expand Up @@ -1490,6 +1495,7 @@ static int max1363_probe(struct i2c_client *client,
int ret;
struct max1363_state *st;
struct iio_dev *indio_dev;
struct regulator *vref;

indio_dev = iio_device_alloc(sizeof(struct max1363_state));
if (indio_dev == NULL) {
Expand All @@ -1504,22 +1510,39 @@ static int max1363_probe(struct i2c_client *client,

st = iio_priv(indio_dev);

st->reg = regulator_get(&client->dev, "vcc");
st->reg = devm_regulator_get(&client->dev, "vcc");
if (IS_ERR(st->reg)) {
ret = PTR_ERR(st->reg);
goto error_unregister_map;
}

ret = regulator_enable(st->reg);
if (ret)
goto error_put_reg;
goto error_unregister_map;

/* this is only used for device removal purposes */
i2c_set_clientdata(client, indio_dev);

st->chip_info = &max1363_chip_info_tbl[id->driver_data];
st->client = client;

st->vref_uv = st->chip_info->int_vref_mv * 1000;
vref = devm_regulator_get(&client->dev, "vref");
if (!IS_ERR(vref)) {
int vref_uv;

ret = regulator_enable(vref);
if (ret)
goto error_disable_reg;
st->vref = vref;
vref_uv = regulator_get_voltage(vref);
if (vref_uv <= 0) {
ret = -EINVAL;
goto error_disable_reg;
}
st->vref_uv = vref_uv;
}

ret = max1363_alloc_scan_masks(indio_dev);
if (ret)
goto error_disable_reg;
Expand All @@ -1533,15 +1556,15 @@ static int max1363_probe(struct i2c_client *client,
indio_dev->modes = INDIO_DIRECT_MODE;
ret = max1363_initial_setup(st);
if (ret < 0)
goto error_free_available_scan_masks;
goto error_disable_reg;

ret = iio_triggered_buffer_setup(indio_dev, NULL,
&max1363_trigger_handler, &max1363_buffered_setup_ops);
if (ret)
goto error_free_available_scan_masks;
goto error_disable_reg;

if (client->irq) {
ret = request_threaded_irq(st->client->irq,
ret = devm_request_threaded_irq(&client->dev, st->client->irq,
NULL,
&max1363_event_handler,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Expand All @@ -1554,20 +1577,16 @@ static int max1363_probe(struct i2c_client *client,

ret = iio_device_register(indio_dev);
if (ret < 0)
goto error_free_irq;
goto error_uninit_buffer;

return 0;
error_free_irq:
if (client->irq)
free_irq(st->client->irq, indio_dev);

error_uninit_buffer:
iio_triggered_buffer_cleanup(indio_dev);
error_free_available_scan_masks:
kfree(indio_dev->available_scan_masks);
error_disable_reg:
if (st->vref)
regulator_disable(st->vref);
regulator_disable(st->reg);
error_put_reg:
regulator_put(st->reg);
error_unregister_map:
iio_map_array_unregister(indio_dev);
error_free_device:
Expand All @@ -1582,12 +1601,10 @@ static int max1363_remove(struct i2c_client *client)
struct max1363_state *st = iio_priv(indio_dev);

iio_device_unregister(indio_dev);
if (client->irq)
free_irq(st->client->irq, indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
kfree(indio_dev->available_scan_masks);
if (st->vref)
regulator_disable(st->vref);
regulator_disable(st->reg);
regulator_put(st->reg);
iio_map_array_unregister(indio_dev);
iio_device_free(indio_dev);

Expand Down
7 changes: 1 addition & 6 deletions drivers/iio/dac/ad5360.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
unsigned int addr)
{
struct ad5360_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret;
struct spi_transfer t[] = {
{
Expand All @@ -226,18 +225,14 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
},
};

spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);

mutex_lock(&indio_dev->mlock);

st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
AD5360_ADDR(AD5360_REG_SF_READBACK) |
AD5360_READBACK_TYPE(type) |
AD5360_READBACK_ADDR(addr));

ret = spi_sync(st->spi, &m);
ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff;

Expand Down
7 changes: 1 addition & 6 deletions drivers/iio/dac/ad5421.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
{
struct ad5421_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret;
struct spi_transfer t[] = {
{
Expand All @@ -140,15 +139,11 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
},
};

spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);

mutex_lock(&indio_dev->mlock);

st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));

ret = spi_sync(st->spi, &m);
ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff;

Expand Down
6 changes: 1 addition & 5 deletions drivers/iio/dac/ad5504.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ static int ad5504_spi_read(struct spi_device *spi, u8 addr)
.rx_buf = &val,
.len = 2,
};
struct spi_message m;

spi_message_init(&m);
spi_message_add_tail(&t, &m);
ret = spi_sync(spi, &m);
ret = spi_sync_transfer(spi, &t, 1);

if (ret < 0)
return ret;
Expand Down
7 changes: 1 addition & 6 deletions drivers/iio/dac/ad5686.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,13 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
.len = 3,
},
};
struct spi_message m;
int ret;

spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);

st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) |
AD5686_ADDR(addr));
st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP));

ret = spi_sync(st->spi, &m);
ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret < 0)
return ret;

Expand Down
7 changes: 1 addition & 6 deletions drivers/iio/dac/ad5755.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel,
static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
{
struct ad5755_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret;
struct spi_transfer t[] = {
{
Expand All @@ -167,16 +166,12 @@ static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
},
};

spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);

mutex_lock(&indio_dev->mlock);

st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16));
st->data[1].d32 = cpu_to_be32(AD5755_NOOP);

ret = spi_sync(st->spi, &m);
ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff;

Expand Down
Loading

0 comments on commit ad463ac

Please sign in to comment.