diff options
author | Greg Kroah-Hartman | 2015-08-12 21:43:41 +0200 |
---|---|---|
committer | Greg Kroah-Hartman | 2015-08-12 21:43:41 +0200 |
commit | 1c46ae0af6df0bbde66c5e868563be57f18a27b4 (patch) | |
tree | b5dbe61f8d05f9c67aff0080ea87945342d58c7d /drivers/iio/accel/stk8312.c | |
parent | staging: ozwpan: Remove from tree (diff) | |
parent | iio: event: Remove negative error code from iio_event_poll (diff) | |
download | kernel-qcow2-linux-1c46ae0af6df0bbde66c5e868563be57f18a27b4.tar.gz kernel-qcow2-linux-1c46ae0af6df0bbde66c5e868563be57f18a27b4.tar.xz kernel-qcow2-linux-1c46ae0af6df0bbde66c5e868563be57f18a27b4.zip |
Merge tag 'iio-for-4.3b-2' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
Second set of new device support, features and cleanup for the 4.3 cycle.
Take 2 also includes a fix set that was too late for the 4.2 cycle.
As we had a lot of tools and docs work in this set, I have broken those
out into their own categories in this description.
Fixes from the pull request '4th set of IIO fixes for the 4.2 cycle'.
* Poll functions for both event chardev and the buffer one were returning
negative error codes (via a positive value).
* A recent change to lsiio adding some error handling that was wrong and
stopped the tool working.
* bmg160 was missing some dependencies in Kconfig
* berlin2-adc had a misshandled register (wrote a value rather than a bitmap)
New device support
* TI opt3001 light sensor
* TXC PA12 ALS and proximity sensor.
* mcp3301 ADC support (in mcp320x driver)
* ST lsm303agr accelerometer and magnetometer drivers (plus some st-sensors
common support to allow different WHOAMI register addresses, devices with
fixed scale and allow interrupt equiped magnetometers).
* ADIS16305, ADIS16367, ADIS16445IMUs (in the adis16400 driver)
* ADIS16266 gyro (in the adis16260 driver)
* ADIS16137 gyro (in the adis16136 driver)
New functionality
* mmc35240 DT bindings.
* Inverse unit conversion macros to aid handing of values written to sysfs
attributes.
Core cleanup
* Forward declaration of struct iio_trigger to avoid a compile warning.
Driver cleanup / fixes
* mxs-lradc
- Clarify which parts are supported.
- Fix spelling erorrs.
- Missing/extra includes
- reorder includes
- add datasheet name listings for all usable channels (to allow them
to be bound by name from consumer drivers)
* acpi-als - add some function prefixes as per general iio style.
* bmc150_magn - replace a magic value with the existing define.
* vf610 - determine possible sample frequencies taking into account the
electrical characteristics (defining a minimum sample time)
* dht11
- whitespace
- additional docs
- avoid mulitple assignments in one line
- Use the new funciton ktime_get_resolution_ns to cleanup a nasty trick
previously used for timing.
* Fix all drivers that consider 0 a valid IRQ for historical reasons.
* Export I2C module alias info where previously missing (to allow autoprobing)
* Export OF module alias info where previously missing.
* mmc35240 - switch some variables into arrays to improve readability.
* mlx90614 - define some magic numbers for readability.
* bmc150_magn
- expand area locked by a mutex to cover all the use of the
data->buffer.
- use descriptive naming for a mask instead of a magic value.
* berin2-adc
- pass up an error code rather that a generic error
- constify the iio_chan_spec
- some other little tidy ups.
* stk8312
- fix a dependency on triggered buffers in kconfig
- add a check for invalid attribute values
- improve error handling by returning error codes where possible and
return immediately where relevant
- rework macro defs to use GENMASK etc
- change some variable types to reduce unnecessary casting
- clean up code style
- drop a local buffer copy for bulk reads and use the one in data->buffer
instead.
* adis16400 - the adis16448 gyroscope scale was wrong.
* adis16480 - some more wrong scales for various parts.
* adis16300 - has an undocumented product id and serial number registers so
use them.
* iio_simple_dummy - fix some wrong code indentation.
* bmc150-accel - use the chip ID to detect the chip present rather than
verifying the expected part was there. This was in response to a wrong
ACPI entry on the WinBook TW100.
* mma8452
- fix _get_hp_filter_index
- drop a double include
- pass up an error code rather than rewriting it
- range check input values to attribute writes
- register defs tidy up using GENMASK and reordering them to be easier to
follow.
- various coding style cleanups
- put the Kconfig entry in the write place (alphabetically).
Tools related
* Tools cleanup - drop an explicity NULL comparison, some unnecessary braces,
use the ARRAY_SIZE macro, send error messages to stderr instead of dropping
them in the middle of normal output.
* Fix tools to allow that scale and offset attributes are optional.
* More tools fixes including allowing true 32bit data (previously an overflow
prevented more than 31bits)
* Drop a stray header guard that ended up in a c file.
* Make calc_digits static as it isn't exported or in the header.
* Set ci_array pointer to NULL after free as a protection against non safe
usage of the tools core code. Also convert a double pointer to a single
one as the extra level of indirection was unnecessary.
Docs
* DocBook introduction by Daniel Baluta. Glad we are beginning to
draw together some more introductory docs to suplement the various
tools / examples.
* Drop bytes_per_datum sysfs attribute docs as it no longer exists.
* A whole load of missing / fixing of kernel-doc for the core of IIO.
* Document the trigger name sysfs attribute in the ABI docs.
* Minor typos in the ABI docs related to power down modes.
Diffstat (limited to 'drivers/iio/accel/stk8312.c')
-rw-r--r-- | drivers/iio/accel/stk8312.c | 107 |
1 files changed, 61 insertions, 46 deletions
diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c index c2bd1444d6da..c764af284c94 100644 --- a/drivers/iio/accel/stk8312.c +++ b/drivers/iio/accel/stk8312.c @@ -37,16 +37,16 @@ #define STK8312_REG_OTPDATA 0x3E #define STK8312_REG_OTPCTRL 0x3F -#define STK8312_MODE_ACTIVE 0x01 +#define STK8312_MODE_ACTIVE BIT(0) #define STK8312_MODE_STANDBY 0x00 -#define STK8312_DREADY_BIT 0x10 -#define STK8312_INT_MODE 0xC0 -#define STK8312_RNG_MASK 0xC0 -#define STK8312_SR_MASK 0x07 -#define STK8312_SR_400HZ_IDX 0 +#define STK8312_MODE_INT_AH_PP 0xC0 /* active-high, push-pull */ +#define STK8312_DREADY_BIT BIT(4) +#define STK8312_RNG_6G 1 #define STK8312_RNG_SHIFT 6 -#define STK8312_READ_RETRIES 16 -#define STK8312_ALL_CHANNEL_MASK 7 +#define STK8312_RNG_MASK GENMASK(7, 6) +#define STK8312_SR_MASK GENMASK(2, 0) +#define STK8312_SR_400HZ_IDX 0 +#define STK8312_ALL_CHANNEL_MASK GENMASK(2, 0) #define STK8312_ALL_CHANNEL_SIZE 3 #define STK8312_DRIVER_NAME "stk8312" @@ -69,8 +69,8 @@ static const int stk8312_scale_table[][2] = { }; static const struct { - u16 val; - u32 val2; + int val; + int val2; } stk8312_samp_freq_table[] = { {400, 0}, {200, 0}, {100, 0}, {50, 0}, {25, 0}, {12, 500000}, {6, 250000}, {3, 125000} @@ -103,7 +103,7 @@ static const struct iio_chan_spec stk8312_channels[] = { struct stk8312_data { struct i2c_client *client; struct mutex lock; - int range; + u8 range; u8 sample_rate_idx; u8 mode; struct iio_trigger *dready_trig; @@ -144,22 +144,25 @@ static int stk8312_otp_init(struct stk8312_data *data) if (ret < 0) goto exit_err; count--; - } while (!(ret & 0x80) && count > 0); + } while (!(ret & BIT(7)) && count > 0); - if (count == 0) + if (count == 0) { + ret = -ETIMEDOUT; goto exit_err; + } ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPDATA); + if (ret == 0) + ret = -EINVAL; if (ret < 0) goto exit_err; - ret = i2c_smbus_write_byte_data(data->client, - STK8312_REG_AFECTRL, ret); + ret = i2c_smbus_write_byte_data(data->client, STK8312_REG_AFECTRL, ret); if (ret < 0) goto exit_err; msleep(150); - return ret; + return 0; exit_err: dev_err(&client->dev, "failed to initialize sensor\n"); @@ -203,8 +206,11 @@ static int stk8312_set_interrupts(struct stk8312_data *data, u8 int_mask) return ret; ret = i2c_smbus_write_byte_data(client, STK8312_REG_INTSU, int_mask); - if (ret < 0) + if (ret < 0) { dev_err(&client->dev, "failed to set interrupts\n"); + stk8312_set_mode(data, mode); + return ret; + } return stk8312_set_mode(data, mode); } @@ -228,7 +234,7 @@ static int stk8312_data_rdy_trigger_set_state(struct iio_trigger *trig, data->dready_trigger_on = state; - return ret; + return 0; } static const struct iio_trigger_ops stk8312_trigger_ops = { @@ -236,7 +242,7 @@ static const struct iio_trigger_ops stk8312_trigger_ops = { .owner = THIS_MODULE, }; -static int stk8312_set_sample_rate(struct stk8312_data *data, int rate) +static int stk8312_set_sample_rate(struct stk8312_data *data, u8 rate) { int ret; u8 masked_reg; @@ -253,20 +259,24 @@ static int stk8312_set_sample_rate(struct stk8312_data *data, int rate) return ret; ret = i2c_smbus_read_byte_data(client, STK8312_REG_SR); - if (ret < 0) { - dev_err(&client->dev, "failed to set sampling rate\n"); - return ret; - } + if (ret < 0) + goto err_activate; masked_reg = (ret & (~STK8312_SR_MASK)) | rate; ret = i2c_smbus_write_byte_data(client, STK8312_REG_SR, masked_reg); if (ret < 0) - dev_err(&client->dev, "failed to set sampling rate\n"); - else - data->sample_rate_idx = rate; + goto err_activate; + + data->sample_rate_idx = rate; return stk8312_set_mode(data, mode); + +err_activate: + dev_err(&client->dev, "failed to set sampling rate\n"); + stk8312_set_mode(data, mode); + + return ret; } static int stk8312_set_range(struct stk8312_data *data, u8 range) @@ -288,21 +298,25 @@ static int stk8312_set_range(struct stk8312_data *data, u8 range) return ret; ret = i2c_smbus_read_byte_data(client, STK8312_REG_STH); - if (ret < 0) { - dev_err(&client->dev, "failed to change sensor range\n"); - return ret; - } + if (ret < 0) + goto err_activate; masked_reg = ret & (~STK8312_RNG_MASK); masked_reg |= range << STK8312_RNG_SHIFT; ret = i2c_smbus_write_byte_data(client, STK8312_REG_STH, masked_reg); if (ret < 0) - dev_err(&client->dev, "failed to change sensor range\n"); - else - data->range = range; + goto err_activate; + + data->range = range; return stk8312_set_mode(data, mode); + +err_activate: + dev_err(&client->dev, "failed to change sensor range\n"); + stk8312_set_mode(data, mode); + + return ret; } static int stk8312_read_accel(struct stk8312_data *data, u8 address) @@ -335,18 +349,21 @@ static int stk8312_read_raw(struct iio_dev *indio_dev, ret = stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); if (ret < 0) { mutex_unlock(&data->lock); - return -EINVAL; + return ret; } ret = stk8312_read_accel(data, chan->address); if (ret < 0) { stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); mutex_unlock(&data->lock); - return -EINVAL; + return ret; } *val = sign_extend32(ret, 7); - stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); + ret = stk8312_set_mode(data, + data->mode & (~STK8312_MODE_ACTIVE)); mutex_unlock(&data->lock); + if (ret < 0) + return ret; return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = stk8312_scale_table[data->range - 1][0]; @@ -418,7 +435,6 @@ static irqreturn_t stk8312_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct stk8312_data *data = iio_priv(indio_dev); int bit, ret, i = 0; - u8 buffer[STK8312_ALL_CHANNEL_SIZE]; mutex_lock(&data->lock); /* @@ -429,18 +445,15 @@ static irqreturn_t stk8312_trigger_handler(int irq, void *p) ret = i2c_smbus_read_i2c_block_data(data->client, STK8312_REG_XOUT, STK8312_ALL_CHANNEL_SIZE, - buffer); + data->buffer); if (ret < STK8312_ALL_CHANNEL_SIZE) { dev_err(&data->client->dev, "register read failed\n"); mutex_unlock(&data->lock); goto err; } - data->buffer[0] = buffer[0]; - data->buffer[1] = buffer[1]; - data->buffer[2] = buffer[2]; } else { for_each_set_bit(bit, indio_dev->active_scan_mask, - indio_dev->masklength) { + indio_dev->masklength) { ret = stk8312_read_accel(data, bit); if (ret < 0) { mutex_unlock(&data->lock); @@ -547,11 +560,12 @@ static int stk8312_probe(struct i2c_client *client, return ret; } data->sample_rate_idx = STK8312_SR_400HZ_IDX; - ret = stk8312_set_range(data, 1); + ret = stk8312_set_range(data, STK8312_RNG_6G); if (ret < 0) return ret; - ret = stk8312_set_mode(data, STK8312_INT_MODE | STK8312_MODE_ACTIVE); + ret = stk8312_set_mode(data, + STK8312_MODE_INT_AH_PP | STK8312_MODE_ACTIVE); if (ret < 0) return ret; @@ -606,7 +620,7 @@ static int stk8312_probe(struct i2c_client *client, goto err_buffer_cleanup; } - return ret; + return 0; err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); @@ -662,6 +676,7 @@ static const struct i2c_device_id stk8312_i2c_id[] = { {"STK8312", 0}, {} }; +MODULE_DEVICE_TABLE(i2c, stk8312_i2c_id); static const struct acpi_device_id stk8312_acpi_id[] = { {"STK8312", 0}, @@ -672,7 +687,7 @@ MODULE_DEVICE_TABLE(acpi, stk8312_acpi_id); static struct i2c_driver stk8312_driver = { .driver = { - .name = "stk8312", + .name = STK8312_DRIVER_NAME, .pm = STK8312_PM_OPS, .acpi_match_table = ACPI_PTR(stk8312_acpi_id), }, |