Commit 2f37d65a authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'staging-4.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging

Pull staging driver updates from Greg KH:
 "Here is the big staging driver updates for 4.3-rc1.

  Lots of things all over the place, almost all of them trivial fixups
  and changes.  The usual IIO updates and new drivers and we have added
  the MOST driver subsystem which is getting cleaned up in the tree.
  The ozwpan driver is finally being deleted as it is obviously
  abandoned and no one cares about it.

  Full details are in the shortlog, and all of these have been in
  linux-next with no reported issues"

* tag 'staging-4.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (912 commits)
  staging/lustre/o2iblnd: remove references to ib_reg_phsy_mr()
  staging: wilc1000: fix build warning with setup_timer()
  staging: wilc1000: remove DECLARE_WILC_BUFFER()
  staging: wilc1000: remove void function return statements that are not useful
  staging: wilc1000: coreconfigurator.c: fix kmalloc error check
  staging: wilc1000: coreconfigurator.c: use kmalloc instead of WILC_MALLOC
  staging: wilc1000: remove unused codes of gps8ConfigPacket
  staging: wilc1000: remove unnecessary void pointer cast
  staging: wilc1000: remove WILC_NEW and WILC_NEW_EX
  staging: wilc1000: use kmalloc instead of WILC_NEW
  staging: wilc1000: Process WARN, INFO options of debug levels from user
  staging: wilc1000: remove unneeded tstrWILC_MsgQueueAttrs typedef
  staging: wilc1000: delete wilc_osconfig.h
  staging: wilc1000: delete wilc_log.h
  staging: wilc1000: delete wilc_timer.h
  staging: wilc1000: remove WILC_TimerStart()
  staging: wilc1000: remove WILC_TimerCreate()
  staging: wilc1000: remove WILC_TimerDestroy()
  staging: wilc1000: remove WILC_TimerStop()
  staging: wilc1000: remove tstrWILC_TimerAttrs typedef
  ...
parents 1af115d6 415bcb5c
...@@ -413,6 +413,11 @@ Description: ...@@ -413,6 +413,11 @@ Description:
to compute the calories burnt by the user. to compute the calories burnt by the user.
What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale_available What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale_available
What: /sys/.../iio:deviceX/in_anglvel_scale_available
What: /sys/.../iio:deviceX/in_magn_scale_available
What: /sys/.../iio:deviceX/in_illuminance_scale_available
What: /sys/.../iio:deviceX/in_intensity_scale_available
What: /sys/.../iio:deviceX/in_proximity_scale_available
What: /sys/.../iio:deviceX/in_voltageX_scale_available What: /sys/.../iio:deviceX/in_voltageX_scale_available
What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available
What: /sys/.../iio:deviceX/out_voltageX_scale_available What: /sys/.../iio:deviceX/out_voltageX_scale_available
...@@ -488,7 +493,7 @@ Contact: linux-iio@vger.kernel.org ...@@ -488,7 +493,7 @@ Contact: linux-iio@vger.kernel.org
Description: Description:
Specifies the output powerdown mode. Specifies the output powerdown mode.
DAC output stage is disconnected from the amplifier and DAC output stage is disconnected from the amplifier and
1kohm_to_gnd: connected to ground via an 1kOhm resistor, 1kohm_to_gnd: connected to ground via an 1kOhm resistor,
6kohm_to_gnd: connected to ground via a 6kOhm resistor, 6kohm_to_gnd: connected to ground via a 6kOhm resistor,
20kohm_to_gnd: connected to ground via a 20kOhm resistor, 20kohm_to_gnd: connected to ground via a 20kOhm resistor,
100kohm_to_gnd: connected to ground via an 100kOhm resistor, 100kohm_to_gnd: connected to ground via an 100kOhm resistor,
...@@ -498,9 +503,9 @@ Description: ...@@ -498,9 +503,9 @@ Description:
outX_powerdown_mode_available. If Y is not present the outX_powerdown_mode_available. If Y is not present the
mode is shared across all outputs. mode is shared across all outputs.
What: /sys/.../iio:deviceX/out_votlageY_powerdown_mode_available What: /sys/.../iio:deviceX/out_voltageY_powerdown_mode_available
What: /sys/.../iio:deviceX/out_voltage_powerdown_mode_available What: /sys/.../iio:deviceX/out_voltage_powerdown_mode_available
What: /sys/.../iio:deviceX/out_altvotlageY_powerdown_mode_available What: /sys/.../iio:deviceX/out_altvoltageY_powerdown_mode_available
What: /sys/.../iio:deviceX/out_altvoltage_powerdown_mode_available What: /sys/.../iio:deviceX/out_altvoltage_powerdown_mode_available
KernelVersion: 2.6.38 KernelVersion: 2.6.38
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
...@@ -1035,13 +1040,6 @@ Contact: linux-iio@vger.kernel.org ...@@ -1035,13 +1040,6 @@ Contact: linux-iio@vger.kernel.org
Description: Description:
Number of scans contained by the buffer. Number of scans contained by the buffer.
What: /sys/bus/iio/devices/iio:deviceX/buffer/bytes_per_datum
KernelVersion: 2.6.37
Contact: linux-iio@vger.kernel.org
Description:
Bytes per scan. Due to alignment fun, the scan may be larger
than implied directly by the scan_element parameters.
What: /sys/bus/iio/devices/iio:deviceX/buffer/enable What: /sys/bus/iio/devices/iio:deviceX/buffer/enable
KernelVersion: 2.6.35 KernelVersion: 2.6.35
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
......
...@@ -9,3 +9,12 @@ Description: ...@@ -9,3 +9,12 @@ Description:
automated testing or in situations, where other trigger methods automated testing or in situations, where other trigger methods
are not applicable. For example no RTC or spare GPIOs. are not applicable. For example no RTC or spare GPIOs.
X is the IIO index of the trigger. X is the IIO index of the trigger.
What: /sys/bus/iio/devices/triggerX/name
KernelVersion: 2.6.39
Contact: linux-iio@vger.kernel.org
Description:
The name attribute holds a description string for the current
trigger. In order to associate the trigger with an IIO device
one should write this name string to
/sys/bus/iio/devices/iio:deviceY/trigger/current_trigger.
...@@ -15,7 +15,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \ ...@@ -15,7 +15,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
80211.xml debugobjects.xml sh.xml regulator.xml \ 80211.xml debugobjects.xml sh.xml regulator.xml \
alsa-driver-api.xml writing-an-alsa-driver.xml \ alsa-driver-api.xml writing-an-alsa-driver.xml \
tracepoint.xml drm.xml media_api.xml w1.xml \ tracepoint.xml drm.xml media_api.xml w1.xml \
writing_musb_glue_layer.xml crypto-API.xml writing_musb_glue_layer.xml crypto-API.xml iio.xml
include Documentation/DocBook/media/Makefile include Documentation/DocBook/media/Makefile
......
This diff is collapsed.
...@@ -18,6 +18,7 @@ Required properties: ...@@ -18,6 +18,7 @@ Required properties:
"mcp3202" "mcp3202"
"mcp3204" "mcp3204"
"mcp3208" "mcp3208"
"mcp3301"
Examples: Examples:
......
...@@ -17,6 +17,11 @@ Recommended properties: ...@@ -17,6 +17,11 @@ Recommended properties:
- Frequency in normal mode (ADLPC=0, ADHSC=0) - Frequency in normal mode (ADLPC=0, ADHSC=0)
- Frequency in high-speed mode (ADLPC=0, ADHSC=1) - Frequency in high-speed mode (ADLPC=0, ADHSC=1)
- Frequency in low-power mode (ADLPC=1, ADHSC=0) - Frequency in low-power mode (ADLPC=1, ADHSC=0)
- min-sample-time: Minimum sampling time in nanoseconds. This value has
to be chosen according to the conversion mode and the connected analog
source resistance (R_as) and capacitance (C_as). Refer the datasheet's
operating requirements. A safe default across a wide range of R_as and
C_as as well as conversion modes is 1000ns.
Example: Example:
adc0: adc@4003b000 { adc0: adc@4003b000 {
......
* MEMSIC MMC35240 magnetometer sensor
Required properties:
- compatible : should be "memsic,mmc35240"
- reg : the I2C address of the magnetometer
Example:
mmc35240@30 {
compatible = "memsic,mmc35240";
reg = <0x30>;
};
...@@ -35,6 +35,7 @@ Accelerometers: ...@@ -35,6 +35,7 @@ Accelerometers:
- st,lsm303dl-accel - st,lsm303dl-accel
- st,lsm303dlm-accel - st,lsm303dlm-accel
- st,lsm330-accel - st,lsm330-accel
- st,lsm303agr-accel
Gyroscopes: Gyroscopes:
- st,l3g4200d-gyro - st,l3g4200d-gyro
...@@ -46,6 +47,7 @@ Gyroscopes: ...@@ -46,6 +47,7 @@ Gyroscopes:
- st,lsm330-gyro - st,lsm330-gyro
Magnetometers: Magnetometers:
- st,lsm303agr-magn
- st,lsm303dlh-magn - st,lsm303dlh-magn
- st,lsm303dlhc-magn - st,lsm303dlhc-magn
- st,lsm303dlm-magn - st,lsm303dlm-magn
......
* Freescale i.MX28 LRADC device driver * Freescale MXS LRADC device driver
Required properties: Required properties:
- compatible: Should be "fsl,imx23-lradc" for i.MX23 SoC and "fsl,imx28-lradc" - compatible: Should be "fsl,imx23-lradc" for i.MX23 SoC and "fsl,imx28-lradc"
......
What is sm712fb?
=================
This is a graphics framebuffer driver for Silicon Motion SM712 based processors.
How to use it?
==============
Switching modes is done using the video=sm712fb:... boot parameter.
If you want, for example, enable a resolution of 1280x1024x24bpp you should
pass to the kernel this command line: "video=sm712fb:0x31B".
You should not compile-in vesafb.
Currently supported video modes are:
[Graphic modes]
bpp | 640x480 800x600 1024x768 1280x1024
----+--------------------------------------------
8 | 0x301 0x303 0x305 0x307
16 | 0x311 0x314 0x317 0x31A
24 | 0x312 0x315 0x318 0x31B
Missing Features
================
(alias TODO list)
* 2D acceleratrion
* dual-head support
...@@ -9348,6 +9348,15 @@ S: Maintained ...@@ -9348,6 +9348,15 @@ S: Maintained
F: drivers/media/i2c/ov2659.c F: drivers/media/i2c/ov2659.c
F: include/media/ov2659.h F: include/media/ov2659.h
SILICON MOTION SM712 FRAME BUFFER DRIVER
M: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
M: Teddy Wang <teddy.wang@siliconmotion.com>
M: Sudip Mukherjee <sudip@vectorindia.org>
L: linux-fbdev@vger.kernel.org
S: Maintained
F: drivers/video/fbdev/sm712*
F: Documentation/fb/sm712fb.txt
SIS 190 ETHERNET DRIVER SIS 190 ETHERNET DRIVER
M: Francois Romieu <romieu@fr.zoreil.com> M: Francois Romieu <romieu@fr.zoreil.com>
L: netdev@vger.kernel.org L: netdev@vger.kernel.org
...@@ -9745,11 +9754,6 @@ W: http://wiki.laptop.org/go/DCON ...@@ -9745,11 +9754,6 @@ W: http://wiki.laptop.org/go/DCON
S: Maintained S: Maintained
F: drivers/staging/olpc_dcon/ F: drivers/staging/olpc_dcon/
STAGING - OZMO DEVICES USB OVER WIFI DRIVER
M: Shigekatsu Tateno <shigekatsu.tateno@atmel.com>
S: Maintained
F: drivers/staging/ozwpan/
STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER
M: Willy Tarreau <willy@meta-x.org> M: Willy Tarreau <willy@meta-x.org>
S: Odd Fixes S: Odd Fixes
...@@ -9768,14 +9772,6 @@ L: linux-wireless@vger.kernel.org ...@@ -9768,14 +9772,6 @@ L: linux-wireless@vger.kernel.org
S: Maintained S: Maintained
F: drivers/staging/rtl8723au/ F: drivers/staging/rtl8723au/
STAGING - SILICON MOTION SM7XX FRAME BUFFER DRIVER
M: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
M: Teddy Wang <teddy.wang@siliconmotion.com>
M: Sudip Mukherjee <sudip@vectorindia.org>
L: linux-fbdev@vger.kernel.org
S: Maintained
F: drivers/staging/sm7xxfb/
STAGING - SILICON MOTION SM750 FRAME BUFFER DRIVER STAGING - SILICON MOTION SM750 FRAME BUFFER DRIVER
M: Sudip Mukherjee <sudipm.mukherjee@gmail.com> M: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
M: Teddy Wang <teddy.wang@siliconmotion.com> M: Teddy Wang <teddy.wang@siliconmotion.com>
......
...@@ -86,18 +86,6 @@ config KXSD9 ...@@ -86,18 +86,6 @@ config KXSD9
To compile this driver as a module, choose M here: the module To compile this driver as a module, choose M here: the module
will be called kxsd9. will be called kxsd9.
config MMA8452
tristate "Freescale MMA8452Q Accelerometer Driver"
depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
help
Say yes here to build support for the Freescale MMA8452Q 3-axis
accelerometer.
To compile this driver as a module, choose M here: the module
will be called mma8452.
config KXCJK1013 config KXCJK1013
tristate "Kionix 3-Axis Accelerometer Driver" tristate "Kionix 3-Axis Accelerometer Driver"
depends on I2C depends on I2C
...@@ -111,6 +99,18 @@ config KXCJK1013 ...@@ -111,6 +99,18 @@ config KXCJK1013
To compile this driver as a module, choose M here: the module will To compile this driver as a module, choose M here: the module will
be called kxcjk-1013. be called kxcjk-1013.
config MMA8452
tristate "Freescale MMA8452Q Accelerometer Driver"
depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
help
Say yes here to build support for the Freescale MMA8452Q 3-axis
accelerometer.
To compile this driver as a module, choose M here: the module
will be called mma8452.
config MMA9551_CORE config MMA9551_CORE
tristate tristate
...@@ -140,6 +140,8 @@ config MMA9553 ...@@ -140,6 +140,8 @@ config MMA9553
config STK8312 config STK8312
tristate "Sensortek STK8312 3-Axis Accelerometer Driver" tristate "Sensortek STK8312 3-Axis Accelerometer Driver"
depends on I2C depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
help help
Say yes here to get support for the Sensortek STK8312 3-axis Say yes here to get support for the Sensortek STK8312 3-axis
accelerometer. accelerometer.
......
...@@ -846,7 +846,6 @@ MODULE_DEVICE_TABLE(i2c, bma180_ids); ...@@ -846,7 +846,6 @@ MODULE_DEVICE_TABLE(i2c, bma180_ids);
static struct i2c_driver bma180_driver = { static struct i2c_driver bma180_driver = {
.driver = { .driver = {
.name = "bma180", .name = "bma180",
.owner = THIS_MODULE,
.pm = BMA180_PM_OPS, .pm = BMA180_PM_OPS,
}, },
.probe = bma180_probe, .probe = bma180_probe,
......
...@@ -151,6 +151,7 @@ struct bmc150_scale_info { ...@@ -151,6 +151,7 @@ struct bmc150_scale_info {
}; };
struct bmc150_accel_chip_info { struct bmc150_accel_chip_info {
const char *name;
u8 chip_id; u8 chip_id;
const struct iio_chan_spec *channels; const struct iio_chan_spec *channels;
int num_channels; int num_channels;
...@@ -241,7 +242,6 @@ static const struct { ...@@ -241,7 +242,6 @@ static const struct {
{500000, BMC150_ACCEL_SLEEP_500_MS}, {500000, BMC150_ACCEL_SLEEP_500_MS},
{1000000, BMC150_ACCEL_SLEEP_1_SEC} }; {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
static int bmc150_accel_set_mode(struct bmc150_accel_data *data, static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
enum bmc150_power_modes mode, enum bmc150_power_modes mode,
int dur_us) int dur_us)
...@@ -259,8 +259,9 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data, ...@@ -259,8 +259,9 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
dur_val = dur_val =
bmc150_accel_sleep_value_table[i].reg_value; bmc150_accel_sleep_value_table[i].reg_value;
} }
} else } else {
dur_val = 0; dur_val = 0;
}
if (dur_val < 0) if (dur_val < 0)
return -EINVAL; return -EINVAL;
...@@ -288,7 +289,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val, ...@@ -288,7 +289,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) { for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
if (bmc150_accel_samp_freq_table[i].val == val && if (bmc150_accel_samp_freq_table[i].val == val &&
bmc150_accel_samp_freq_table[i].val2 == val2) { bmc150_accel_samp_freq_table[i].val2 == val2) {
ret = i2c_smbus_write_byte_data( ret = i2c_smbus_write_byte_data(
data->client, data->client,
BMC150_ACCEL_REG_PMU_BW, BMC150_ACCEL_REG_PMU_BW,
...@@ -345,65 +346,6 @@ static int bmc150_accel_any_motion_setup(struct bmc150_accel_trigger *t, ...@@ -345,65 +346,6 @@ static int bmc150_accel_any_motion_setup(struct bmc150_accel_trigger *t,
return 0; return 0;
} }
static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
{
int ret;
ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
if (ret < 0) {
dev_err(&data->client->dev,
"Error: Reading chip id\n");
return ret;
}
dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
if (ret != data->chip_info->chip_id) {
dev_err(&data->client->dev, "Invalid chip %x\n", ret);
return -ENODEV;
}
ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
if (ret < 0)
return ret;
/* Set Bandwidth */
ret = bmc150_accel_set_bw(data, BMC150_ACCEL_DEF_BW, 0);
if (ret < 0)
return ret;
/* Set Default Range */
ret = i2c_smbus_write_byte_data(data->client,
BMC150_ACCEL_REG_PMU_RANGE,
BMC150_ACCEL_DEF_RANGE_4G);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_pmu_range\n");
return ret;
}
data->range = BMC150_ACCEL_DEF_RANGE_4G;
/* Set default slope duration and thresholds */
data->slope_thres = BMC150_ACCEL_DEF_SLOPE_THRESHOLD;
data->slope_dur = BMC150_ACCEL_DEF_SLOPE_DURATION;
ret = bmc150_accel_update_slope(data);
if (ret < 0)
return ret;
/* Set default as latched interrupts */
ret = i2c_smbus_write_byte_data(data->client,
BMC150_ACCEL_REG_INT_RST_LATCH,
BMC150_ACCEL_INT_MODE_LATCH_INT |
BMC150_ACCEL_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_int_rst_latch\n");
return ret;
}
return 0;
}
static int bmc150_accel_get_bw(struct bmc150_accel_data *data, int *val, static int bmc150_accel_get_bw(struct bmc150_accel_data *data, int *val,
int *val2) int *val2)
{ {
...@@ -437,12 +379,13 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on) ...@@ -437,12 +379,13 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
{ {
int ret; int ret;
if (on) if (on) {
ret = pm_runtime_get_sync(&data->client->dev); ret = pm_runtime_get_sync(&data->client->dev);
else { } else {
pm_runtime_mark_last_busy(&data->client->dev); pm_runtime_mark_last_busy(&data->client->dev);
ret = pm_runtime_put_autosuspend(&data->client->dev); ret = pm_runtime_put_autosuspend(&data->client->dev);
} }
if (ret < 0) { if (ret < 0) {
dev_err(&data->client->dev, dev_err(&data->client->dev,
"Failed: bmc150_accel_set_power_state for %d\n", on); "Failed: bmc150_accel_set_power_state for %d\n", on);
...@@ -514,13 +457,13 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i, ...@@ -514,13 +457,13 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
} }
/* /*
* We will expect the enable and disable to do operation in * We will expect the enable and disable to do operation in reverse
* in reverse order. This will happen here anyway as our * order. This will happen here anyway, as our resume operation uses
* resume operation uses sync mode runtime pm calls, the * sync mode runtime pm calls. The suspend operation will be delayed
* suspend operation will be delayed by autosuspend delay * by autosuspend delay.
* So the disable operation will still happen in reverse of * So the disable operation will still happen in reverse order of
* enable operation. When runtime pm is disabled the mode * enable operation. When runtime pm is disabled the mode is always on,
* is always on so sequence doesn't matter * so sequence doesn't matter.
*/ */
ret = bmc150_accel_set_power_state(data, state); ret = bmc150_accel_set_power_state(data, state);
if (ret < 0) if (ret < 0)
...@@ -574,7 +517,6 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i, ...@@ -574,7 +517,6 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
return ret; return ret;
} }
static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val) static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
{ {
int ret, i; int ret, i;
...@@ -674,8 +616,9 @@ static int bmc150_accel_read_raw(struct iio_dev *indio_dev, ...@@ -674,8 +616,9 @@ static int bmc150_accel_read_raw(struct iio_dev *indio_dev,
if (chan->type == IIO_TEMP) { if (chan->type == IIO_TEMP) {
*val = BMC150_ACCEL_TEMP_CENTER_VAL; *val = BMC150_ACCEL_TEMP_CENTER_VAL;
return IIO_VAL_INT; return IIO_VAL_INT;
} else } else {
return -EINVAL; return -EINVAL;
}
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = 0; *val = 0;
switch (chan->type) { switch (chan->type) {
...@@ -776,7 +719,7 @@ static int bmc150_accel_write_event(struct iio_dev *indio_dev, ...@@ -776,7 +719,7 @@ static int bmc150_accel_write_event(struct iio_dev *indio_dev,
switch (info) { switch (info) {
case IIO_EV_INFO_VALUE: case IIO_EV_INFO_VALUE:
data->slope_thres = val & 0xFF; data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK;
break; break;
case IIO_EV_INFO_PERIOD: case IIO_EV_INFO_PERIOD:
data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK; data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK;
...@@ -793,7 +736,6 @@ static int bmc150_accel_read_event_config(struct iio_dev *indio_dev, ...@@ -793,7 +736,6 @@ static int bmc150_accel_read_event_config(struct iio_dev *indio_dev,
enum iio_event_type type, enum iio_event_type type,
enum iio_event_direction dir) enum iio_event_direction dir)
{ {
struct bmc150_accel_data *data = iio_priv(indio_dev); struct bmc150_accel_data *data = iio_priv(indio_dev);
return data->ev_enable_state; return data->ev_enable_state;
...@@ -827,7 +769,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev, ...@@ -827,7 +769,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
} }
static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev, static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev,
struct iio_trigger *trig) struct iio_trigger *trig)
{ {
struct bmc150_accel_data *data = iio_priv(indio_dev); struct bmc150_accel_data *data = iio_priv(indio_dev);
int i; int i;
...@@ -963,6 +905,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev, ...@@ -963,6 +905,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3]; u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
int64_t tstamp; int64_t tstamp;
uint64_t sample_period; uint64_t sample_period;
ret = i2c_smbus_read_byte_data(data->client, ret = i2c_smbus_read_byte_data(data->client,
BMC150_ACCEL_REG_FIFO_STATUS); BMC150_ACCEL_REG_FIFO_STATUS);
if (ret < 0) { if (ret < 0) {
...@@ -1120,6 +1063,7 @@ enum { ...@@ -1120,6 +1063,7 @@ enum {
static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
[bmc150] = { [bmc150] = {
.name = "BMC150A",
.chip_id = 0xFA, .chip_id = 0xFA,
.channels = bmc150_accel_channels, .channels = bmc150_accel_channels,
.num_channels = ARRAY_SIZE(bmc150_accel_channels), .num_channels = ARRAY_SIZE(bmc150_accel_channels),
...@@ -1129,6 +1073,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { ...@@ -1129,6 +1073,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
{76590, BMC150_ACCEL_DEF_RANGE_16G} }, {76590, BMC150_ACCEL_DEF_RANGE_16G} },
}, },
[bmi055] = { [bmi055] = {
.name = "BMI055A",
.chip_id = 0xFA, .chip_id = 0xFA,
.channels = bmc150_accel_channels, .channels = bmc150_accel_channels,
.num_channels = ARRAY_SIZE(bmc150_accel_channels), .num_channels = ARRAY_SIZE(bmc150_accel_channels),
...@@ -1138,6 +1083,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { ...@@ -1138,6 +1083,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
{76590, BMC150_ACCEL_DEF_RANGE_16G} }, {76590, BMC150_ACCEL_DEF_RANGE_16G} },
}, },
[bma255] = { [bma255] = {
.name = "BMA0255",
.chip_id = 0xFA, .chip_id = 0xFA,
.channels = bmc150_accel_channels, .channels = bmc150_accel_channels,
.num_channels = ARRAY_SIZE(bmc150_accel_channels), .num_channels = ARRAY_SIZE(bmc150_accel_channels),
...@@ -1147,6 +1093,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { ...@@ -1147,6 +1093,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
{76590, BMC150_ACCEL_DEF_RANGE_16G} }, {76590, BMC150_ACCEL_DEF_RANGE_16G} },
}, },
[bma250e] = { [bma250e] = {
.name = "BMA250E",
.chip_id = 0xF9, .chip_id = 0xF9,
.channels = bma250e_accel_channels, .channels = bma250e_accel_channels,
.num_channels = ARRAY_SIZE(bma250e_accel_channels), .num_channels = ARRAY_SIZE(bma250e_accel_channels),
...@@ -1156,6 +1103,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { ...@@ -1156,6 +1103,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
{306457, BMC150_ACCEL_DEF_RANGE_16G} }, {306457, BMC150_ACCEL_DEF_RANGE_16G} },
}, },
[bma222e] = { [bma222e] = {
.name = "BMA222E",
.chip_id = 0xF8, .chip_id = 0xF8,
.channels = bma222e_accel_channels, .channels = bma222e_accel_channels,
.num_channels = ARRAY_SIZE(bma222e_accel_channels), .num_channels = ARRAY_SIZE(bma222e_accel_channels),
...@@ -1165,6 +1113,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { ...@@ -1165,6 +1113,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
{1225831, BMC150_ACCEL_DEF_RANGE_16G} }, {1225831, BMC150_ACCEL_DEF_RANGE_16G} },
}, },
[bma280] = { [bma280] = {
.name = "BMA0280",
.chip_id = 0xFB, .chip_id = 0xFB,
.channels = bma280_accel_channels, .channels = bma280_accel_channels,
.num_channels = ARRAY_SIZE(bma280_accel_channels), .num_channels = ARRAY_SIZE(bma280_accel_channels),
...@@ -1255,7 +1204,7 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig) ...@@ -1255,7 +1204,7 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
} }
static int bmc150_accel_trigger_set_state(struct iio_trigger *trig, static int bmc150_accel_trigger_set_state(struct iio_trigger *trig,
bool state) bool state)
{ {
struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig); struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
struct bmc150_accel_data *data = t->data; struct bmc150_accel_data *data = t->data;
...@@ -1314,26 +1263,32 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev) ...@@ -1314,26 +1263,32 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
dir = IIO_EV_DIR_RISING; dir = IIO_EV_DIR_RISING;
if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X) if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, iio_push_event(indio_dev,
0, IIO_MOD_EVENT_CODE(IIO_ACCEL,
IIO_MOD_X, 0,
IIO_EV_TYPE_ROC, IIO_MOD_X,
dir), IIO_EV_TYPE_ROC,
data->timestamp); dir),
data->timestamp);
if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y) if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, iio_push_event(indio_dev,
0, IIO_MOD_EVENT_CODE(IIO_ACCEL,
IIO_MOD_Y, 0,
IIO_EV_TYPE_ROC, IIO_MOD_Y,
dir), IIO_EV_TYPE_ROC,
data->timestamp); dir),
data->timestamp);
if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z) if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, iio_push_event(indio_dev,
0, IIO_MOD_EVENT_CODE(IIO_ACCEL,
IIO_MOD_Z, 0,
IIO_EV_TYPE_ROC, IIO_MOD_Z,
dir), IIO_EV_TYPE_ROC,
data->timestamp); dir),
data->timestamp);
return ret; return ret;
} }
...@@ -1365,7 +1320,9 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private) ...@@ -1365,7 +1320,9 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
BMC150_ACCEL_INT_MODE_LATCH_INT | BMC150_ACCEL_INT_MODE_LATCH_INT |
BMC150_ACCEL_INT_MODE_LATCH_RESET); BMC150_ACCEL_INT_MODE_LATCH_RESET);
if (ret) if (ret)
dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n"); dev_err(&data->client->dev,
"Error writing reg_int_rst_latch\n");
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} else { } else {
ret = IRQ_NONE; ret = IRQ_NONE;
...@@ -1403,22 +1360,8 @@ static irqreturn_t bmc150_accel_irq_handler(int irq, void *private) ...@@ -1403,22 +1360,8 @@ static irqreturn_t bmc150_accel_irq_handler(int irq, void *private)
return IRQ_NONE; return IRQ_NONE;
} }
static const char *bmc150_accel_match_acpi_device(struct device *dev, int *data)
{
const struct acpi_device_id *id;
id = acpi_match_device(dev->driver->acpi_match_table, dev);
if (!id)
return NULL;
*data = (int) id->driver_data;
return dev_name(dev);
}
static int bmc150_accel_gpio_probe(struct i2c_client *client, static int bmc150_accel_gpio_probe(struct i2c_client *client,
struct bmc150_accel_data *data) struct bmc150_accel_data *data)
{ {
struct device *dev; struct device *dev;
struct gpio_desc *gpio; struct gpio_desc *gpio;
...@@ -1611,6 +1554,70 @@ static const struct iio_buffer_setup_ops bmc150_accel_buffer_ops = { ...@@ -1611,6 +1554,70 @@ static const struct iio_buffer_setup_ops bmc150_accel_buffer_ops = {
.postdisable = bmc150_accel_buffer_postdisable, .postdisable = bmc150_accel_buffer_postdisable,
}; };
static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
{
int ret, i;
ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
if (ret < 0) {
dev_err(&data->client->dev, "Error: Reading chip id\n");
return ret;
}
dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
for (i = 0; i < ARRAY_SIZE(bmc150_accel_chip_info_tbl); i++) {
if (bmc150_accel_chip_info_tbl[i].chip_id == ret) {
data->chip_info = &bmc150_accel_chip_info_tbl[i];
break;
}
}
if (!data->chip_info) {
dev_err(&data->client->dev, "Unsupported chip %x\n", ret);
return -ENODEV;
}
ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
if (ret < 0)
return ret;
/* Set Bandwidth */
ret = bmc150_accel_set_bw(data, BMC150_ACCEL_DEF_BW, 0);
if (ret < 0)
return ret;
/* Set Default Range */
ret = i2c_smbus_write_byte_data(data->client,
BMC150_ACCEL_REG_PMU_RANGE,
BMC150_ACCEL_DEF_RANGE_4G);
if (ret < 0) {
dev_err(&data->client->dev, "Error writing reg_pmu_range\n");
return ret;
}
data->range = BMC150_ACCEL_DEF_RANGE_4G;
/* Set default slope duration and thresholds */
data->slope_thres = BMC150_ACCEL_DEF_SLOPE_THRESHOLD;
data->slope_dur = BMC150_ACCEL_DEF_SLOPE_DURATION;
ret = bmc150_accel_update_slope(data);
if (ret < 0)
return ret;
/* Set default as latched interrupts */
ret = i2c_smbus_write_byte_data(data->client,
BMC150_ACCEL_REG_INT_RST_LATCH,
BMC150_ACCEL_INT_MODE_LATCH_INT |
BMC150_ACCEL_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_int_rst_latch\n");
return ret;
}
return 0;
}
static int bmc150_accel_probe(struct i2c_client *client, static int bmc150_accel_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -1618,7 +1625,6 @@ static int bmc150_accel_probe(struct i2c_client *client, ...@@ -1618,7 +1625,6 @@ static int bmc150_accel_probe(struct i2c_client *client,
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret; int ret;
const char *name = NULL; const char *name = NULL;
int chip_id = 0;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev) if (!indio_dev)
...@@ -1628,15 +1634,8 @@ static int bmc150_accel_probe(struct i2c_client *client, ...@@ -1628,15 +1634,8 @@ static int bmc150_accel_probe(struct i2c_client *client,
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);
data->client = client; data->client = client;
if (id) { if (id)
name = id->name; name = id->name;
chip_id = id->driver_data;
}
if (ACPI_HANDLE(&client->dev))
name = bmc150_accel_match_acpi_device(&client->dev, &chip_id);
data->chip_info = &bmc150_accel_chip_info_tbl[chip_id];
ret = bmc150_accel_chip_init(data); ret = bmc150_accel_chip_init(data);
if (ret < 0) if (ret < 0)
...@@ -1647,7 +1646,7 @@ static int bmc150_accel_probe(struct i2c_client *client, ...@@ -1647,7 +1646,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
indio_dev->dev.parent = &client->dev; indio_dev->dev.parent = &client->dev;
indio_dev->channels = data->chip_info->channels; indio_dev->channels = data->chip_info->channels;
indio_dev->num_channels = data->chip_info->num_channels; indio_dev->num_channels = data->chip_info->num_channels;
indio_dev->name = name; indio_dev->name = name ? name : data->chip_info->name;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &bmc150_accel_info; indio_dev->info = &bmc150_accel_info;
...@@ -1663,7 +1662,7 @@ static int bmc150_accel_probe(struct i2c_client *client, ...@@ -1663,7 +1662,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
if (client->irq < 0) if (client->irq < 0)
client->irq = bmc150_accel_gpio_probe(client, data); client->irq = bmc150_accel_gpio_probe(client, data);
if (client->irq >= 0) { if (client->irq > 0) {
ret = devm_request_threaded_irq( ret = devm_request_threaded_irq(
&client->dev, client->irq, &client->dev, client->irq,
bmc150_accel_irq_handler, bmc150_accel_irq_handler,
......
...@@ -658,10 +658,8 @@ static int kxcjk1013_set_scale(struct kxcjk1013_data *data, int val) ...@@ -658,10 +658,8 @@ static int kxcjk1013_set_scale(struct kxcjk1013_data *data, int val)
int ret, i; int ret, i;
enum kxcjk1013_mode store_mode; enum kxcjk1013_mode store_mode;
for (i = 0; i < ARRAY_SIZE(KXCJK1013_scale_table); ++i) { for (i = 0; i < ARRAY_SIZE(KXCJK1013_scale_table); ++i) {
if (KXCJK1013_scale_table[i].scale == val) { if (KXCJK1013_scale_table[i].scale == val) {
ret = kxcjk1013_get_mode(data, &store_mode); ret = kxcjk1013_get_mode(data, &store_mode);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -820,7 +818,6 @@ static int kxcjk1013_read_event_config(struct iio_dev *indio_dev, ...@@ -820,7 +818,6 @@ static int kxcjk1013_read_event_config(struct iio_dev *indio_dev,
enum iio_event_type type, enum iio_event_type type,
enum iio_event_direction dir) enum iio_event_direction dir)
{ {
struct kxcjk1013_data *data = iio_priv(indio_dev); struct kxcjk1013_data *data = iio_priv(indio_dev);
return data->ev_enable_state; return data->ev_enable_state;
...@@ -1243,7 +1240,7 @@ static int kxcjk1013_probe(struct i2c_client *client, ...@@ -1243,7 +1240,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
if (client->irq < 0) if (client->irq < 0)
client->irq = kxcjk1013_gpio_probe(client, data); client->irq = kxcjk1013_gpio_probe(client, data);
if (client->irq >= 0) { if (client->irq > 0) {
ret = devm_request_threaded_irq(&client->dev, client->irq, ret = devm_request_threaded_irq(&client->dev, client->irq,
kxcjk1013_data_rdy_trig_poll, kxcjk1013_data_rdy_trig_poll,
kxcjk1013_event_handler, kxcjk1013_event_handler,
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/buffer.h> #include <linux/iio/buffer.h>
#include <linux/iio/trigger.h> #include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h> #include <linux/iio/trigger_consumer.h>
...@@ -24,54 +23,51 @@ ...@@ -24,54 +23,51 @@
#include <linux/iio/events.h> #include <linux/iio/events.h>
#include <linux/delay.h> #include <linux/delay.h>
#define MMA8452_STATUS 0x00 #define MMA8452_STATUS 0x00
#define MMA8452_OUT_X 0x01 /* MSB first, 12-bit */ #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0))
#define MMA8452_OUT_Y 0x03 #define MMA8452_OUT_X 0x01 /* MSB first, 12-bit */
#define MMA8452_OUT_Z 0x05 #define MMA8452_OUT_Y 0x03
#define MMA8452_INT_SRC 0x0c #define MMA8452_OUT_Z 0x05
#define MMA8452_WHO_AM_I 0x0d #define MMA8452_INT_SRC 0x0c
#define MMA8452_DATA_CFG 0x0e #define MMA8452_WHO_AM_I 0x0d
#define MMA8452_HP_FILTER_CUTOFF 0x0f #define MMA8452_DATA_CFG 0x0e
#define MMA8452_HP_FILTER_CUTOFF_SEL_MASK (BIT(0) | BIT(1)) #define MMA8452_DATA_CFG_FS_MASK GENMASK(1, 0)
#define MMA8452_TRANSIENT_CFG 0x1d #define MMA8452_DATA_CFG_FS_2G 0
#define MMA8452_TRANSIENT_CFG_ELE BIT(4) #define MMA8452_DATA_CFG_FS_4G 1
#define MMA8452_TRANSIENT_CFG_CHAN(chan) BIT(chan + 1) #define MMA8452_DATA_CFG_FS_8G 2
#define MMA8452_TRANSIENT_CFG_HPF_BYP BIT(0) #define MMA8452_DATA_CFG_HPF_MASK BIT(4)
#define MMA8452_TRANSIENT_SRC 0x1e #define MMA8452_HP_FILTER_CUTOFF 0x0f
#define MMA8452_TRANSIENT_SRC_XTRANSE BIT(1) #define MMA8452_HP_FILTER_CUTOFF_SEL_MASK GENMASK(1, 0)
#define MMA8452_TRANSIENT_SRC_YTRANSE BIT(3) #define MMA8452_TRANSIENT_CFG 0x1d
#define MMA8452_TRANSIENT_SRC_ZTRANSE BIT(5) #define MMA8452_TRANSIENT_CFG_HPF_BYP BIT(0)
#define MMA8452_TRANSIENT_THS 0x1f #define MMA8452_TRANSIENT_CFG_CHAN(chan) BIT(chan + 1)
#define MMA8452_TRANSIENT_THS_MASK 0x7f #define MMA8452_TRANSIENT_CFG_ELE BIT(4)
#define MMA8452_TRANSIENT_COUNT 0x20 #define MMA8452_TRANSIENT_SRC 0x1e
#define MMA8452_OFF_X 0x2f #define MMA8452_TRANSIENT_SRC_XTRANSE BIT(1)
#define MMA8452_OFF_Y 0x30 #define MMA8452_TRANSIENT_SRC_YTRANSE BIT(3)
#define MMA8452_OFF_Z 0x31 #define MMA8452_TRANSIENT_SRC_ZTRANSE BIT(5)
#define MMA8452_CTRL_REG1 0x2a #define MMA8452_TRANSIENT_THS 0x1f
#define MMA8452_CTRL_REG2 0x2b #define MMA8452_TRANSIENT_THS_MASK GENMASK(6, 0)
#define MMA8452_CTRL_REG2_RST BIT(6) #define MMA8452_TRANSIENT_COUNT 0x20
#define MMA8452_CTRL_REG4 0x2d #define MMA8452_CTRL_REG1 0x2a
#define MMA8452_CTRL_REG5 0x2e #define MMA8452_CTRL_ACTIVE BIT(0)
#define MMA8452_CTRL_DR_MASK GENMASK(5, 3)
#define MMA8452_MAX_REG 0x31 #define MMA8452_CTRL_DR_SHIFT 3
#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */
#define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) #define MMA8452_CTRL_REG2 0x2b
#define MMA8452_CTRL_REG2_RST BIT(6)
#define MMA8452_CTRL_DR_MASK (BIT(5) | BIT(4) | BIT(3)) #define MMA8452_CTRL_REG4 0x2d
#define MMA8452_CTRL_DR_SHIFT 3 #define MMA8452_CTRL_REG5 0x2e
#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */ #define MMA8452_OFF_X 0x2f
#define MMA8452_CTRL_ACTIVE BIT(0) #define MMA8452_OFF_Y 0x30
#define MMA8452_OFF_Z 0x31
#define MMA8452_DATA_CFG_FS_MASK (BIT(1) | BIT(0))
#define MMA8452_DATA_CFG_FS_2G 0 #define MMA8452_MAX_REG 0x31
#define MMA8452_DATA_CFG_FS_4G 1
#define MMA8452_DATA_CFG_FS_8G 2 #define MMA8452_INT_DRDY BIT(0)
#define MMA8452_DATA_CFG_HPF_MASK BIT(4) #define MMA8452_INT_TRANS BIT(5)
#define MMA8452_INT_DRDY BIT(0) #define MMA8452_DEVICE_ID 0x2a
#define MMA8452_INT_TRANS BIT(5)
#define MMA8452_DEVICE_ID 0x2a
struct mma8452_data { struct mma8452_data {
struct i2c_client *client; struct i2c_client *client;
...@@ -91,30 +87,34 @@ static int mma8452_drdy(struct mma8452_data *data) ...@@ -91,30 +87,34 @@ static int mma8452_drdy(struct mma8452_data *data)
return ret; return ret;
if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY) if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
return 0; return 0;
msleep(20); msleep(20);
} }
dev_err(&data->client->dev, "data not ready\n"); dev_err(&data->client->dev, "data not ready\n");
return -EIO; return -EIO;
} }
static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
{ {
int ret = mma8452_drdy(data); int ret = mma8452_drdy(data);
if (ret < 0) if (ret < 0)
return ret; return ret;
return i2c_smbus_read_i2c_block_data(data->client,
MMA8452_OUT_X, 3 * sizeof(__be16), (u8 *) buf); return i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
3 * sizeof(__be16), (u8 *)buf);
} }
static ssize_t mma8452_show_int_plus_micros(char *buf, static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],
const int (*vals)[2], int n) int n)
{ {
size_t len = 0; size_t len = 0;
while (n-- > 0) while (n-- > 0)
len += scnprintf(buf + len, PAGE_SIZE - len, len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ",
"%d.%06d ", vals[n][0], vals[n][1]); vals[n][0], vals[n][1]);
/* replace trailing space by newline */ /* replace trailing space by newline */
buf[len - 1] = '\n'; buf[len - 1] = '\n';
...@@ -123,7 +123,7 @@ static ssize_t mma8452_show_int_plus_micros(char *buf, ...@@ -123,7 +123,7 @@ static ssize_t mma8452_show_int_plus_micros(char *buf,
} }
static int mma8452_get_int_plus_micros_index(const int (*vals)[2], int n, static int mma8452_get_int_plus_micros_index(const int (*vals)[2], int n,
int val, int val2) int val, int val2)
{ {
while (n-- > 0) while (n-- > 0)
if (val == vals[n][0] && val2 == vals[n][1]) if (val == vals[n][0] && val2 == vals[n][1])
...@@ -147,7 +147,7 @@ static const int mma8452_samp_freq[8][2] = { ...@@ -147,7 +147,7 @@ static const int mma8452_samp_freq[8][2] = {
* Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048 * Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048
* The userspace interface uses m/s^2 and we declare micro units * The userspace interface uses m/s^2 and we declare micro units
* So scale factor is given by: * So scale factor is given by:
* g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 * g * N * 1000000 / 2048 for N = 2, 4, 8 and g = 9.80665
*/ */
static const int mma8452_scales[3][2] = { static const int mma8452_scales[3][2] = {
{0, 9577}, {0, 19154}, {0, 38307} {0, 9577}, {0, 19154}, {0, 38307}
...@@ -178,17 +178,19 @@ static const int mma8452_hp_filter_cutoff[8][4][2] = { ...@@ -178,17 +178,19 @@ static const int mma8452_hp_filter_cutoff[8][4][2] = {
}; };
static ssize_t mma8452_show_samp_freq_avail(struct device *dev, static ssize_t mma8452_show_samp_freq_avail(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr,
char *buf)
{ {
return mma8452_show_int_plus_micros(buf, mma8452_samp_freq, return mma8452_show_int_plus_micros(buf, mma8452_samp_freq,
ARRAY_SIZE(mma8452_samp_freq)); ARRAY_SIZE(mma8452_samp_freq));
} }
static ssize_t mma8452_show_scale_avail(struct device *dev, static ssize_t mma8452_show_scale_avail(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr,
char *buf)
{ {
return mma8452_show_int_plus_micros(buf, mma8452_scales, return mma8452_show_int_plus_micros(buf, mma8452_scales,
ARRAY_SIZE(mma8452_scales)); ARRAY_SIZE(mma8452_scales));
} }
static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev, static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev,
...@@ -205,22 +207,23 @@ static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev, ...@@ -205,22 +207,23 @@ static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev,
static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail); static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail);
static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO, static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO,
mma8452_show_scale_avail, NULL, 0); mma8452_show_scale_avail, NULL, 0);
static IIO_DEVICE_ATTR(in_accel_filter_high_pass_3db_frequency_available, static IIO_DEVICE_ATTR(in_accel_filter_high_pass_3db_frequency_available,
S_IRUGO, mma8452_show_hp_cutoff_avail, NULL, 0); S_IRUGO, mma8452_show_hp_cutoff_avail, NULL, 0);
static int mma8452_get_samp_freq_index(struct mma8452_data *data, static int mma8452_get_samp_freq_index(struct mma8452_data *data,
int val, int val2) int val, int val2)
{ {
return mma8452_get_int_plus_micros_index(mma8452_samp_freq, return mma8452_get_int_plus_micros_index(mma8452_samp_freq,
ARRAY_SIZE(mma8452_samp_freq), val, val2); ARRAY_SIZE(mma8452_samp_freq),
val, val2);
} }
static int mma8452_get_scale_index(struct mma8452_data *data, static int mma8452_get_scale_index(struct mma8452_data *data, int val, int val2)
int val, int val2)
{ {
return mma8452_get_int_plus_micros_index(mma8452_scales, return mma8452_get_int_plus_micros_index(mma8452_scales,
ARRAY_SIZE(mma8452_scales), val, val2); ARRAY_SIZE(mma8452_scales),
val, val2);
} }
static int mma8452_get_hp_filter_index(struct mma8452_data *data, static int mma8452_get_hp_filter_index(struct mma8452_data *data,
...@@ -229,7 +232,7 @@ static int mma8452_get_hp_filter_index(struct mma8452_data *data, ...@@ -229,7 +232,7 @@ static int mma8452_get_hp_filter_index(struct mma8452_data *data,
int i = mma8452_get_odr_index(data); int i = mma8452_get_odr_index(data);
return mma8452_get_int_plus_micros_index(mma8452_hp_filter_cutoff[i], return mma8452_get_int_plus_micros_index(mma8452_hp_filter_cutoff[i],
ARRAY_SIZE(mma8452_scales[0]), val, val2); ARRAY_SIZE(mma8452_hp_filter_cutoff[0]), val, val2);
} }
static int mma8452_read_hp_filter(struct mma8452_data *data, int *hz, int *uHz) static int mma8452_read_hp_filter(struct mma8452_data *data, int *hz, int *uHz)
...@@ -266,25 +269,31 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, ...@@ -266,25 +269,31 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = sign_extend32(
be16_to_cpu(buffer[chan->scan_index]) >> 4, 11); *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]) >> 4,
11);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK; i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK;
*val = mma8452_scales[i][0]; *val = mma8452_scales[i][0];
*val2 = mma8452_scales[i][1]; *val2 = mma8452_scales[i][1];
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
i = mma8452_get_odr_index(data); i = mma8452_get_odr_index(data);
*val = mma8452_samp_freq[i][0]; *val = mma8452_samp_freq[i][0];
*val2 = mma8452_samp_freq[i][1]; *val2 = mma8452_samp_freq[i][1];
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
ret = i2c_smbus_read_byte_data(data->client, MMA8452_OFF_X + ret = i2c_smbus_read_byte_data(data->client,
chan->scan_index); MMA8452_OFF_X + chan->scan_index);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = sign_extend32(ret, 7); *val = sign_extend32(ret, 7);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
if (data->data_cfg & MMA8452_DATA_CFG_HPF_MASK) { if (data->data_cfg & MMA8452_DATA_CFG_HPF_MASK) {
...@@ -295,21 +304,23 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, ...@@ -295,21 +304,23 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
} }
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
} }
return -EINVAL; return -EINVAL;
} }
static int mma8452_standby(struct mma8452_data *data) static int mma8452_standby(struct mma8452_data *data)
{ {
return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
data->ctrl_reg1 & ~MMA8452_CTRL_ACTIVE); data->ctrl_reg1 & ~MMA8452_CTRL_ACTIVE);
} }
static int mma8452_active(struct mma8452_data *data) static int mma8452_active(struct mma8452_data *data)
{ {
return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
} }
static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val) static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
...@@ -334,6 +345,7 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val) ...@@ -334,6 +345,7 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
ret = 0; ret = 0;
fail: fail:
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
return ret; return ret;
} }
...@@ -344,12 +356,13 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, ...@@ -344,12 +356,13 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data,
i = mma8452_get_hp_filter_index(data, val, val2); i = mma8452_get_hp_filter_index(data, val, val2);
if (i < 0) if (i < 0)
return -EINVAL; return i;
reg = i2c_smbus_read_byte_data(data->client, reg = i2c_smbus_read_byte_data(data->client,
MMA8452_HP_FILTER_CUTOFF); MMA8452_HP_FILTER_CUTOFF);
if (reg < 0) if (reg < 0)
return reg; return reg;
reg &= ~MMA8452_HP_FILTER_CUTOFF_SEL_MASK; reg &= ~MMA8452_HP_FILTER_CUTOFF_SEL_MASK;
reg |= i; reg |= i;
...@@ -370,25 +383,30 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, ...@@ -370,25 +383,30 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
i = mma8452_get_samp_freq_index(data, val, val2); i = mma8452_get_samp_freq_index(data, val, val2);
if (i < 0) if (i < 0)
return -EINVAL; return i;
data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
return mma8452_change_config(data, MMA8452_CTRL_REG1, return mma8452_change_config(data, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
i = mma8452_get_scale_index(data, val, val2); i = mma8452_get_scale_index(data, val, val2);
if (i < 0) if (i < 0)
return -EINVAL; return i;
data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK; data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK;
data->data_cfg |= i; data->data_cfg |= i;
return mma8452_change_config(data, MMA8452_DATA_CFG, return mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
if (val < -128 || val > 127) if (val < -128 || val > 127)
return -EINVAL; return -EINVAL;
return mma8452_change_config(data, MMA8452_OFF_X +
chan->scan_index, val); return mma8452_change_config(data,
MMA8452_OFF_X + chan->scan_index,
val);
case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
if (val == 0 && val2 == 0) { if (val == 0 && val2 == 0) {
...@@ -399,8 +417,9 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, ...@@ -399,8 +417,9 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return mma8452_change_config(data, MMA8452_DATA_CFG, return mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
default: default:
return -EINVAL; return -EINVAL;
...@@ -425,6 +444,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, ...@@ -425,6 +444,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
return ret; return ret;
*val = ret & MMA8452_TRANSIENT_THS_MASK; *val = ret & MMA8452_TRANSIENT_THS_MASK;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_EV_INFO_PERIOD: case IIO_EV_INFO_PERIOD:
...@@ -437,6 +457,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, ...@@ -437,6 +457,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
mma8452_get_odr_index(data)]; mma8452_get_odr_index(data)];
*val = us / USEC_PER_SEC; *val = us / USEC_PER_SEC;
*val2 = us % USEC_PER_SEC; *val2 = us % USEC_PER_SEC;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
...@@ -453,6 +474,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, ...@@ -453,6 +474,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
default: default:
...@@ -472,19 +494,22 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev, ...@@ -472,19 +494,22 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
switch (info) { switch (info) {
case IIO_EV_INFO_VALUE: case IIO_EV_INFO_VALUE:
return mma8452_change_config(data, MMA8452_TRANSIENT_THS, if (val < 0 || val > MMA8452_TRANSIENT_THS_MASK)
val & MMA8452_TRANSIENT_THS_MASK); return -EINVAL;
return mma8452_change_config(data, MMA8452_TRANSIENT_THS, val);
case IIO_EV_INFO_PERIOD: case IIO_EV_INFO_PERIOD:
steps = (val * USEC_PER_SEC + val2) / steps = (val * USEC_PER_SEC + val2) /
mma8452_transient_time_step_us[ mma8452_transient_time_step_us[
mma8452_get_odr_index(data)]; mma8452_get_odr_index(data)];
if (steps > 0xff) if (steps < 0 || steps > 0xff)
return -EINVAL; return -EINVAL;
return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT, return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT,
steps); steps);
case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
reg = i2c_smbus_read_byte_data(data->client, reg = i2c_smbus_read_byte_data(data->client,
MMA8452_TRANSIENT_CFG); MMA8452_TRANSIENT_CFG);
...@@ -499,6 +524,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev, ...@@ -499,6 +524,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg); return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg);
default: default:
...@@ -608,15 +634,16 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p) ...@@ -608,15 +634,16 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p)
u8 buffer[16]; /* 3 16-bit channels + padding + ts */ u8 buffer[16]; /* 3 16-bit channels + padding + ts */
int ret; int ret;
ret = mma8452_read(data, (__be16 *) buffer); ret = mma8452_read(data, (__be16 *)buffer);
if (ret < 0) if (ret < 0)
goto done; goto done;
iio_push_to_buffers_with_timestamp(indio_dev, buffer, iio_push_to_buffers_with_timestamp(indio_dev, buffer,
iio_get_time_ns()); iio_get_time_ns());
done: done:
iio_trigger_notify_done(indio_dev->trig); iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -674,10 +701,10 @@ static struct attribute_group mma8452_event_attribute_group = { ...@@ -674,10 +701,10 @@ static struct attribute_group mma8452_event_attribute_group = {
.modified = 1, \ .modified = 1, \
.channel2 = IIO_MOD_##axis, \ .channel2 = IIO_MOD_##axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_CALIBBIAS), \ BIT(IIO_CHAN_INFO_CALIBBIAS), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SCALE) | \
BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \
.scan_index = idx, \ .scan_index = idx, \
.scan_type = { \ .scan_type = { \
.sign = 's', \ .sign = 's', \
...@@ -780,6 +807,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev) ...@@ -780,6 +807,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
return ret; return ret;
indio_dev->trig = trig; indio_dev->trig = trig;
return 0; return 0;
} }
...@@ -849,7 +877,7 @@ static int mma8452_probe(struct i2c_client *client, ...@@ -849,7 +877,7 @@ static int mma8452_probe(struct i2c_client *client,
data->data_cfg = MMA8452_DATA_CFG_FS_2G; data->data_cfg = MMA8452_DATA_CFG_FS_2G;
ret = i2c_smbus_write_byte_data(client, MMA8452_DATA_CFG, ret = i2c_smbus_write_byte_data(client, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -891,14 +919,14 @@ static int mma8452_probe(struct i2c_client *client, ...@@ -891,14 +919,14 @@ static int mma8452_probe(struct i2c_client *client,
} }
data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
(MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT); (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
if (ret < 0) if (ret < 0)
goto trigger_cleanup; goto trigger_cleanup;
ret = iio_triggered_buffer_setup(indio_dev, NULL, ret = iio_triggered_buffer_setup(indio_dev, NULL,
mma8452_trigger_handler, NULL); mma8452_trigger_handler, NULL);
if (ret < 0) if (ret < 0)
goto trigger_cleanup; goto trigger_cleanup;
...@@ -968,6 +996,7 @@ static const struct of_device_id mma8452_dt_ids[] = { ...@@ -968,6 +996,7 @@ static const struct of_device_id mma8452_dt_ids[] = {
{ .compatible = "fsl,mma8452" }, { .compatible = "fsl,mma8452" },
{ } { }
}; };
MODULE_DEVICE_TABLE(of, mma8452_dt_ids);
static struct i2c_driver mma8452_driver = { static struct i2c_driver mma8452_driver = {
.driver = { .driver = {
......
...@@ -297,7 +297,7 @@ EXPORT_SYMBOL(mma9551_read_status_byte); ...@@ -297,7 +297,7 @@ EXPORT_SYMBOL(mma9551_read_status_byte);
* Returns: 0 on success, negative value on failure. * Returns: 0 on success, negative value on failure.
*/ */
int mma9551_read_config_word(struct i2c_client *client, u8 app_id, int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
u16 reg, u16 *val) u16 reg, u16 *val)
{ {
int ret; int ret;
__be16 v; __be16 v;
...@@ -328,12 +328,12 @@ EXPORT_SYMBOL(mma9551_read_config_word); ...@@ -328,12 +328,12 @@ EXPORT_SYMBOL(mma9551_read_config_word);
* Returns: 0 on success, negative value on failure. * Returns: 0 on success, negative value on failure.
*/ */
int mma9551_write_config_word(struct i2c_client *client, u8 app_id, int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
u16 reg, u16 val) u16 reg, u16 val)
{ {
__be16 v = cpu_to_be16(val); __be16 v = cpu_to_be16(val);
return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg, return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg,
(u8 *) &v, 2, NULL, 0); (u8 *)&v, 2, NULL, 0);
} }
EXPORT_SYMBOL(mma9551_write_config_word); EXPORT_SYMBOL(mma9551_write_config_word);
...@@ -373,7 +373,7 @@ EXPORT_SYMBOL(mma9551_read_status_word); ...@@ -373,7 +373,7 @@ EXPORT_SYMBOL(mma9551_read_status_word);
* @client: I2C client * @client: I2C client
* @app_id: Application ID * @app_id: Application ID
* @reg: Application register * @reg: Application register
* @len: Length of array to read in bytes * @len: Length of array to read (in words)
* @buf: Array of words to read * @buf: Array of words to read
* *
* Read multiple configuration registers (word-sized registers). * Read multiple configuration registers (word-sized registers).
...@@ -385,23 +385,22 @@ EXPORT_SYMBOL(mma9551_read_status_word); ...@@ -385,23 +385,22 @@ EXPORT_SYMBOL(mma9551_read_status_word);
* Returns: 0 on success, negative value on failure. * Returns: 0 on success, negative value on failure.
*/ */
int mma9551_read_config_words(struct i2c_client *client, u8 app_id, int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf) u16 reg, u8 len, u16 *buf)
{ {
int ret, i; int ret, i;
int len_words = len / sizeof(u16);
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
if (len_words > ARRAY_SIZE(be_buf)) { if (len > ARRAY_SIZE(be_buf)) {
dev_err(&client->dev, "Invalid buffer size %d\n", len); dev_err(&client->dev, "Invalid buffer size %d\n", len);
return -EINVAL; return -EINVAL;
} }
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
reg, NULL, 0, (u8 *) be_buf, len); reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16));
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 0; i < len_words; i++) for (i = 0; i < len; i++)
buf[i] = be16_to_cpu(be_buf[i]); buf[i] = be16_to_cpu(be_buf[i]);
return 0; return 0;
...@@ -413,7 +412,7 @@ EXPORT_SYMBOL(mma9551_read_config_words); ...@@ -413,7 +412,7 @@ EXPORT_SYMBOL(mma9551_read_config_words);
* @client: I2C client * @client: I2C client
* @app_id: Application ID * @app_id: Application ID
* @reg: Application register * @reg: Application register
* @len: Length of array to read in bytes * @len: Length of array to read (in words)
* @buf: Array of words to read * @buf: Array of words to read
* *
* Read multiple status registers (word-sized registers). * Read multiple status registers (word-sized registers).
...@@ -428,20 +427,19 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id, ...@@ -428,20 +427,19 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf) u16 reg, u8 len, u16 *buf)
{ {
int ret, i; int ret, i;
int len_words = len / sizeof(u16);
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
if (len_words > ARRAY_SIZE(be_buf)) { if (len > ARRAY_SIZE(be_buf)) {
dev_err(&client->dev, "Invalid buffer size %d\n", len); dev_err(&client->dev, "Invalid buffer size %d\n", len);
return -EINVAL; return -EINVAL;
} }
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
reg, NULL, 0, (u8 *) be_buf, len); reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16));
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 0; i < len_words; i++) for (i = 0; i < len; i++)
buf[i] = be16_to_cpu(be_buf[i]); buf[i] = be16_to_cpu(be_buf[i]);
return 0; return 0;
...@@ -453,7 +451,7 @@ EXPORT_SYMBOL(mma9551_read_status_words); ...@@ -453,7 +451,7 @@ EXPORT_SYMBOL(mma9551_read_status_words);
* @client: I2C client * @client: I2C client
* @app_id: Application ID * @app_id: Application ID
* @reg: Application register * @reg: Application register
* @len: Length of array to write in bytes * @len: Length of array to write (in words)
* @buf: Array of words to write * @buf: Array of words to write
* *
* Write multiple configuration registers (word-sized registers). * Write multiple configuration registers (word-sized registers).
...@@ -468,19 +466,18 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id, ...@@ -468,19 +466,18 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf) u16 reg, u8 len, u16 *buf)
{ {
int i; int i;
int len_words = len / sizeof(u16);
__be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2]; __be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2];
if (len_words > ARRAY_SIZE(be_buf)) { if (len > ARRAY_SIZE(be_buf)) {
dev_err(&client->dev, "Invalid buffer size %d\n", len); dev_err(&client->dev, "Invalid buffer size %d\n", len);
return -EINVAL; return -EINVAL;
} }
for (i = 0; i < len_words; i++) for (i = 0; i < len; i++)
be_buf[i] = cpu_to_be16(buf[i]); be_buf[i] = cpu_to_be16(buf[i]);
return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG,
reg, (u8 *) be_buf, len, NULL, 0); reg, (u8 *)be_buf, len * sizeof(u16), NULL, 0);
} }
EXPORT_SYMBOL(mma9551_write_config_words); EXPORT_SYMBOL(mma9551_write_config_words);
......
...@@ -53,13 +53,13 @@ int mma9551_write_config_byte(struct i2c_client *client, u8 app_id, ...@@ -53,13 +53,13 @@ int mma9551_write_config_byte(struct i2c_client *client, u8 app_id,
int mma9551_read_status_byte(struct i2c_client *client, u8 app_id, int mma9551_read_status_byte(struct i2c_client *client, u8 app_id,
u16 reg, u8 *val); u16 reg, u8 *val);
int mma9551_read_config_word(struct i2c_client *client, u8 app_id, int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
u16 reg, u16 *val); u16 reg, u16 *val);
int mma9551_write_config_word(struct i2c_client *client, u8 app_id, int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
u16 reg, u16 val); u16 reg, u16 val);
int mma9551_read_status_word(struct i2c_client *client, u8 app_id, int mma9551_read_status_word(struct i2c_client *client, u8 app_id,
u16 reg, u16 *val); u16 reg, u16 *val);
int mma9551_read_config_words(struct i2c_client *client, u8 app_id, int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf); u16 reg, u8 len, u16 *buf);
int mma9551_read_status_words(struct i2c_client *client, u8 app_id, int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
u16 reg, u8 len, u16 *buf); u16 reg, u8 len, u16 *buf);
int mma9551_write_config_words(struct i2c_client *client, u8 app_id, int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
......
...@@ -182,6 +182,10 @@ struct mma9553_conf_regs { ...@@ -182,6 +182,10 @@ struct mma9553_conf_regs {
struct mma9553_data { struct mma9553_data {
struct i2c_client *client; struct i2c_client *client;
/*
* 1. Serialize access to HW (requested by mma9551_core API).
* 2. Serialize sequences that power on/off the device and access HW.
*/
struct mutex mutex; struct mutex mutex;
struct mma9553_conf_regs conf; struct mma9553_conf_regs conf;
struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE]; struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE];
...@@ -322,7 +326,8 @@ static int mma9553_read_activity_stepcnt(struct mma9553_data *data, ...@@ -322,7 +326,8 @@ static int mma9553_read_activity_stepcnt(struct mma9553_data *data,
int ret; int ret;
ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
MMA9553_REG_STATUS, sizeof(u32), buf); MMA9553_REG_STATUS, ARRAY_SIZE(buf),
buf);
if (ret < 0) { if (ret < 0) {
dev_err(&data->client->dev, dev_err(&data->client->dev,
"error reading status and stepcnt\n"); "error reading status and stepcnt\n");
...@@ -342,10 +347,10 @@ static int mma9553_conf_gpio(struct mma9553_data *data) ...@@ -342,10 +347,10 @@ static int mma9553_conf_gpio(struct mma9553_data *data)
struct mma9553_event *ev_step_detect; struct mma9553_event *ev_step_detect;
bool activity_enabled; bool activity_enabled;
activity_enabled = activity_enabled = mma9553_is_any_event_enabled(data, true,
mma9553_is_any_event_enabled(data, true, IIO_ACTIVITY); IIO_ACTIVITY);
ev_step_detect = ev_step_detect = mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD,
mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, IIO_EV_DIR_NONE); IIO_EV_DIR_NONE);
/* /*
* If both step detector and activity are enabled, use the MRGFL bit. * If both step detector and activity are enabled, use the MRGFL bit.
...@@ -371,9 +376,8 @@ static int mma9553_conf_gpio(struct mma9553_data *data) ...@@ -371,9 +376,8 @@ static int mma9553_conf_gpio(struct mma9553_data *data)
return ret; return ret;
} }
ret = mma9551_gpio_config(data->client, ret = mma9551_gpio_config(data->client, MMA9553_DEFAULT_GPIO_PIN, appid,
MMA9553_DEFAULT_GPIO_PIN, bitnum, MMA9553_DEFAULT_GPIO_POLARITY);
appid, bitnum, MMA9553_DEFAULT_GPIO_POLARITY);
if (ret < 0) if (ret < 0)
return ret; return ret;
data->gpio_bitnum = bitnum; data->gpio_bitnum = bitnum;
...@@ -394,17 +398,16 @@ static int mma9553_init(struct mma9553_data *data) ...@@ -394,17 +398,16 @@ static int mma9553_init(struct mma9553_data *data)
* a device identification command to differentiate the MMA9553L * a device identification command to differentiate the MMA9553L
* from the MMA9550L. * from the MMA9550L.
*/ */
ret = ret = mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER,
mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER, MMA9553_REG_CONF_SLEEPMIN,
MMA9553_REG_CONF_SLEEPMIN, sizeof(data->conf) / sizeof(u16),
sizeof(data->conf), (u16 *) &data->conf); (u16 *)&data->conf);
if (ret < 0) { if (ret < 0) {
dev_err(&data->client->dev, dev_err(&data->client->dev,
"failed to read configuration registers\n"); "failed to read configuration registers\n");
return ret; return ret;
} }
/* Reset GPIO */ /* Reset GPIO */
data->gpio_bitnum = MMA9553_MAX_BITNUM; data->gpio_bitnum = MMA9553_MAX_BITNUM;
ret = mma9553_conf_gpio(data); ret = mma9553_conf_gpio(data);
...@@ -419,18 +422,18 @@ static int mma9553_init(struct mma9553_data *data) ...@@ -419,18 +422,18 @@ static int mma9553_init(struct mma9553_data *data)
data->conf.sleepmin = MMA9553_DEFAULT_SLEEPMIN; data->conf.sleepmin = MMA9553_DEFAULT_SLEEPMIN;
data->conf.sleepmax = MMA9553_DEFAULT_SLEEPMAX; data->conf.sleepmax = MMA9553_DEFAULT_SLEEPMAX;
data->conf.sleepthd = MMA9553_DEFAULT_SLEEPTHD; data->conf.sleepthd = MMA9553_DEFAULT_SLEEPTHD;
data->conf.config = data->conf.config = mma9553_set_bits(data->conf.config, 1,
mma9553_set_bits(data->conf.config, 1, MMA9553_MASK_CONF_CONFIG); MMA9553_MASK_CONF_CONFIG);
/* /*
* Clear the activity debounce counter when the activity level changes, * Clear the activity debounce counter when the activity level changes,
* so that the confidence level applies for any activity level. * so that the confidence level applies for any activity level.
*/ */
data->conf.config = mma9553_set_bits(data->conf.config, 1, data->conf.config = mma9553_set_bits(data->conf.config, 1,
MMA9553_MASK_CONF_ACT_DBCNTM); MMA9553_MASK_CONF_ACT_DBCNTM);
ret = ret = mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER,
mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER, MMA9553_REG_CONF_SLEEPMIN,
MMA9553_REG_CONF_SLEEPMIN, sizeof(data->conf) / sizeof(u16),
sizeof(data->conf), (u16 *) &data->conf); (u16 *)&data->conf);
if (ret < 0) { if (ret < 0) {
dev_err(&data->client->dev, dev_err(&data->client->dev,
"failed to write configuration registers\n"); "failed to write configuration registers\n");
...@@ -567,7 +570,7 @@ static int mma9553_read_raw(struct iio_dev *indio_dev, ...@@ -567,7 +570,7 @@ static int mma9553_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBHEIGHT: case IIO_CHAN_INFO_CALIBHEIGHT:
tmp = mma9553_get_bits(data->conf.height_weight, tmp = mma9553_get_bits(data->conf.height_weight,
MMA9553_MASK_CONF_HEIGHT); MMA9553_MASK_CONF_HEIGHT);
*val = tmp / 100; /* cm to m */ *val = tmp / 100; /* cm to m */
*val2 = (tmp % 100) * 10000; *val2 = (tmp % 100) * 10000;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
...@@ -719,7 +722,6 @@ static int mma9553_read_event_config(struct iio_dev *indio_dev, ...@@ -719,7 +722,6 @@ static int mma9553_read_event_config(struct iio_dev *indio_dev,
enum iio_event_type type, enum iio_event_type type,
enum iio_event_direction dir) enum iio_event_direction dir)
{ {
struct mma9553_data *data = iio_priv(indio_dev); struct mma9553_data *data = iio_priv(indio_dev);
struct mma9553_event *event; struct mma9553_event *event;
...@@ -1026,22 +1028,22 @@ static irqreturn_t mma9553_event_handler(int irq, void *private) ...@@ -1026,22 +1028,22 @@ static irqreturn_t mma9553_event_handler(int irq, void *private)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
ev_prev_activity = ev_prev_activity = mma9553_get_event(data, IIO_ACTIVITY,
mma9553_get_event(data, IIO_ACTIVITY, mma9553_activity_to_mod(
mma9553_activity_to_mod(data->activity), data->activity),
IIO_EV_DIR_FALLING); IIO_EV_DIR_FALLING);
ev_activity = ev_activity = mma9553_get_event(data, IIO_ACTIVITY,
mma9553_get_event(data, IIO_ACTIVITY, mma9553_activity_to_mod(activity),
mma9553_activity_to_mod(activity), IIO_EV_DIR_RISING);
IIO_EV_DIR_RISING); ev_step_detect = mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD,
ev_step_detect = IIO_EV_DIR_NONE);
mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, IIO_EV_DIR_NONE);
if (ev_step_detect->enabled && (stepcnt != data->stepcnt)) { if (ev_step_detect->enabled && (stepcnt != data->stepcnt)) {
data->stepcnt = stepcnt; data->stepcnt = stepcnt;
iio_push_event(indio_dev, iio_push_event(indio_dev,
IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
IIO_EV_DIR_NONE, IIO_EV_TYPE_CHANGE, 0, 0, 0), IIO_EV_DIR_NONE,
IIO_EV_TYPE_CHANGE, 0, 0, 0),
data->timestamp); data->timestamp);
} }
...@@ -1051,17 +1053,19 @@ static irqreturn_t mma9553_event_handler(int irq, void *private) ...@@ -1051,17 +1053,19 @@ static irqreturn_t mma9553_event_handler(int irq, void *private)
if (ev_prev_activity && ev_prev_activity->enabled) if (ev_prev_activity && ev_prev_activity->enabled)
iio_push_event(indio_dev, iio_push_event(indio_dev,
IIO_EVENT_CODE(IIO_ACTIVITY, 0, IIO_EVENT_CODE(IIO_ACTIVITY, 0,
ev_prev_activity->info->mod, ev_prev_activity->info->mod,
IIO_EV_DIR_FALLING, IIO_EV_DIR_FALLING,
IIO_EV_TYPE_THRESH, 0, 0, 0), IIO_EV_TYPE_THRESH, 0, 0,
0),
data->timestamp); data->timestamp);
if (ev_activity && ev_activity->enabled) if (ev_activity && ev_activity->enabled)
iio_push_event(indio_dev, iio_push_event(indio_dev,
IIO_EVENT_CODE(IIO_ACTIVITY, 0, IIO_EVENT_CODE(IIO_ACTIVITY, 0,
ev_activity->info->mod, ev_activity->info->mod,
IIO_EV_DIR_RISING, IIO_EV_DIR_RISING,
IIO_EV_TYPE_THRESH, 0, 0, 0), IIO_EV_TYPE_THRESH, 0, 0,
0),
data->timestamp); data->timestamp);
} }
mutex_unlock(&data->mutex); mutex_unlock(&data->mutex);
...@@ -1145,7 +1149,7 @@ static int mma9553_probe(struct i2c_client *client, ...@@ -1145,7 +1149,7 @@ static int mma9553_probe(struct i2c_client *client,
if (client->irq < 0) if (client->irq < 0)
client->irq = mma9553_gpio_probe(client); client->irq = mma9553_gpio_probe(client);
if (client->irq >= 0) { if (client->irq > 0) {
ret = devm_request_threaded_irq(&client->dev, client->irq, ret = devm_request_threaded_irq(&client->dev, client->irq,
mma9553_irq_handler, mma9553_irq_handler,
mma9553_event_handler, mma9553_event_handler,
...@@ -1156,7 +1160,6 @@ static int mma9553_probe(struct i2c_client *client, ...@@ -1156,7 +1160,6 @@ static int mma9553_probe(struct i2c_client *client,
client->irq); client->irq);
goto out_poweroff; goto out_poweroff;
} }
} }
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel" #define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel"
#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel" #define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel"
#define LSM330_ACCEL_DEV_NAME "lsm330_accel" #define LSM330_ACCEL_DEV_NAME "lsm330_accel"
#define LSM303AGR_ACCEL_DEV_NAME "lsm303agr_accel"
/** /**
* struct st_sensors_platform_data - default accel platform data * struct st_sensors_platform_data - default accel platform data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment