iio: add driver for Freescale MMA9553
Add support for Freescale MMA9553L Intelligent Pedometer Platform. The following functionalities are supported: - step counter (counts the number of steps using a HW register) - step detector (generates an iio event at every step the user takes) - activity recognition (rest, walking, jogging, running) - speed - calories - distance To get accurate pedometer results, the user's height, weight and gender need to be configured. The specifications can be downloaded from: http://www.freescale.com/files/sensors/doc/ref_manual/MMA955xLSWRM.pdf http://www.freescale.com/files/sensors/doc/ref_manual/MMA9553LSWRM.pdf Signed-off-by: Irina Tirdea <irina.tirdea@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
81110933a9
commit
40cb761306
|
@ -343,7 +343,30 @@ Description:
|
|||
production inaccuracies). If shared across all channels,
|
||||
<type>_calibscale is used.
|
||||
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_steps_calibheight
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_activity_calibgender
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_energy_calibgender
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_distance_calibgender
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_velocity_calibgender
|
||||
KernelVersion: 3.20
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
Gender of the user (e.g.: male, female) used by some pedometers
|
||||
to compute the stride length, distance, speed and activity
|
||||
type.
|
||||
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_activity_calibgender_available
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_energy_calibgender_available
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_distance_calibgender_available
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_velocity_calibgender_available
|
||||
KernelVersion: 3.20
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
Lists all available gender values (e.g.: male, female).
|
||||
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_activity_calibheight
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_energy_calibheight
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_distance_calibheight
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_velocity_calibheight
|
||||
KernelVersion: 3.19
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
|
@ -818,6 +841,14 @@ What: /sys/.../events/in_tempY_roc_falling_period
|
|||
What: /sys/.../events/in_accel_x&y&z_mag_falling_period
|
||||
What: /sys/.../events/in_intensity0_thresh_period
|
||||
What: /sys/.../events/in_proximity0_thresh_period
|
||||
What: /sys/.../events/in_activity_still_thresh_rising_period
|
||||
What: /sys/.../events/in_activity_still_thresh_falling_period
|
||||
What: /sys/.../events/in_activity_walking_thresh_rising_period
|
||||
What: /sys/.../events/in_activity_walking_thresh_falling_period
|
||||
What: /sys/.../events/in_activity_jogging_thresh_rising_period
|
||||
What: /sys/.../events/in_activity_jogging_thresh_falling_period
|
||||
What: /sys/.../events/in_activity_running_thresh_rising_period
|
||||
What: /sys/.../events/in_activity_running_thresh_falling_period
|
||||
KernelVersion: 2.6.37
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
|
@ -1142,6 +1173,12 @@ Description:
|
|||
This attribute is used to get/set the integration time in
|
||||
seconds.
|
||||
|
||||
What: /sys/.../iio:deviceX/in_velocity_sqrt(x^2+y^2+z^2)_integration_time
|
||||
KernelVersion: 3.20
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
Number of seconds in which to compute speed.
|
||||
|
||||
What: /sys/bus/iio/devices/iio:deviceX/in_rot_quaternion_raw
|
||||
KernelVersion: 3.15
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
|
@ -1170,13 +1207,17 @@ Description:
|
|||
present, output should be considered as processed with the
|
||||
unit in milliamps.
|
||||
|
||||
What: /sys/.../iio:deviceX/in_energy_en
|
||||
What: /sys/.../iio:deviceX/in_distance_en
|
||||
What: /sys/.../iio:deviceX/in_velocity_sqrt(x^2+y^2+z^2)_en
|
||||
What: /sys/.../iio:deviceX/in_steps_en
|
||||
KernelVersion: 3.19
|
||||
Contact: linux-iio@vger.kernel.org
|
||||
Description:
|
||||
Activates the step counter. After activation, the number of steps
|
||||
taken by the user will be counted in hardware and exported through
|
||||
in_steps_input.
|
||||
Activates a device feature that runs in firmware/hardware.
|
||||
E.g. for steps: the pedometer saves power while not used;
|
||||
when activated, it will count the steps taken by the user in
|
||||
firmware and export them through in_steps_input.
|
||||
|
||||
What: /sys/.../iio:deviceX/in_steps_input
|
||||
KernelVersion: 3.19
|
||||
|
|
|
@ -126,4 +126,14 @@ config MMA9551
|
|||
To compile this driver as a module, choose M here: the module
|
||||
will be called mma9551.
|
||||
|
||||
config MMA9553
|
||||
tristate "Freescale MMA9553L Intelligent Pedometer Platform Driver"
|
||||
depends on I2C
|
||||
select MMA9551_CORE
|
||||
help
|
||||
Say yes here to build support for the Freescale MMA9553L
|
||||
Intelligent Pedometer Platform Driver.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called mma9553.
|
||||
endmenu
|
||||
|
|
|
@ -12,6 +12,7 @@ obj-$(CONFIG_MMA8452) += mma8452.o
|
|||
|
||||
obj-$(CONFIG_MMA9551_CORE) += mma9551_core.o
|
||||
obj-$(CONFIG_MMA9551) += mma9551.o
|
||||
obj-$(CONFIG_MMA9553) += mma9553.o
|
||||
|
||||
obj-$(CONFIG_IIO_SSP_SENSORS_COMMONS) += ssp_accel_sensor.o
|
||||
|
||||
|
|
|
@ -53,6 +53,11 @@
|
|||
#define MMA9551_AFE_Y_ACCEL_REG 0x02
|
||||
#define MMA9551_AFE_Z_ACCEL_REG 0x04
|
||||
|
||||
/* Reset/Suspend/Clear application */
|
||||
#define MMA9551_RSC_RESET 0x00
|
||||
#define MMA9551_RSC_OFFSET(mask) (3 - (ffs(mask) - 1) / 8)
|
||||
#define MMA9551_RSC_VAL(mask) (mask >> (((ffs(mask) - 1) / 8) * 8))
|
||||
|
||||
/*
|
||||
* A response is composed of:
|
||||
* - control registers: MB0-3
|
||||
|
@ -274,6 +279,64 @@ int mma9551_read_status_byte(struct i2c_client *client, u8 app_id,
|
|||
}
|
||||
EXPORT_SYMBOL(mma9551_read_status_byte);
|
||||
|
||||
/**
|
||||
* mma9551_read_config_word() - read 1 config word
|
||||
* @client: I2C client
|
||||
* @app_id: Application ID
|
||||
* @reg: Application register
|
||||
* @val: Pointer to store value read
|
||||
*
|
||||
* Read one configuration word from the device using MMA955xL command format.
|
||||
* Commands to the MMA955xL platform consist of a write followed by one or
|
||||
* more reads.
|
||||
*
|
||||
* Locking note: This function must be called with the device lock held.
|
||||
* Locking is not handled inside the function. Callers should ensure they
|
||||
* serialize access to the HW.
|
||||
*
|
||||
* Returns: 0 on success, negative value on failure.
|
||||
*/
|
||||
int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u16 *val)
|
||||
{
|
||||
int ret;
|
||||
__be16 v;
|
||||
|
||||
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
|
||||
reg, NULL, 0, (u8 *)&v, 2);
|
||||
*val = be16_to_cpu(v);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mma9551_read_config_word);
|
||||
|
||||
/**
|
||||
* mma9551_write_config_word() - write 1 config word
|
||||
* @client: I2C client
|
||||
* @app_id: Application ID
|
||||
* @reg: Application register
|
||||
* @val: Value to write
|
||||
*
|
||||
* Write one configuration word from the device using MMA955xL command format.
|
||||
* Commands to the MMA955xL platform consist of a write followed by one or
|
||||
* more reads.
|
||||
*
|
||||
* Locking note: This function must be called with the device lock held.
|
||||
* Locking is not handled inside the function. Callers should ensure they
|
||||
* serialize access to the HW.
|
||||
*
|
||||
* Returns: 0 on success, negative value on failure.
|
||||
*/
|
||||
int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u16 val)
|
||||
{
|
||||
__be16 v = cpu_to_be16(val);
|
||||
|
||||
return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg,
|
||||
(u8 *) &v, 2, NULL, 0);
|
||||
}
|
||||
EXPORT_SYMBOL(mma9551_write_config_word);
|
||||
|
||||
/**
|
||||
* mma9551_read_status_word() - read 1 status word
|
||||
* @client: I2C client
|
||||
|
@ -305,6 +368,107 @@ int mma9551_read_status_word(struct i2c_client *client, u8 app_id,
|
|||
}
|
||||
EXPORT_SYMBOL(mma9551_read_status_word);
|
||||
|
||||
/**
|
||||
* mma9551_read_config_words() - read multiple config words
|
||||
* @client: I2C client
|
||||
* @app_id: Application ID
|
||||
* @reg: Application register
|
||||
* @len: Length of array to read in bytes
|
||||
* @val: Array of words to read
|
||||
*
|
||||
* Read multiple configuration registers (word-sized registers).
|
||||
*
|
||||
* Locking note: This function must be called with the device lock held.
|
||||
* Locking is not handled inside the function. Callers should ensure they
|
||||
* serialize access to the HW.
|
||||
*
|
||||
* Returns: 0 on success, negative value on failure.
|
||||
*/
|
||||
int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 len, u16 *buf)
|
||||
{
|
||||
int ret, i;
|
||||
int len_words = len / sizeof(u16);
|
||||
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS];
|
||||
|
||||
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
|
||||
reg, NULL, 0, (u8 *) be_buf, len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < len_words; i++)
|
||||
buf[i] = be16_to_cpu(be_buf[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mma9551_read_config_words);
|
||||
|
||||
/**
|
||||
* mma9551_read_status_words() - read multiple status words
|
||||
* @client: I2C client
|
||||
* @app_id: Application ID
|
||||
* @reg: Application register
|
||||
* @len: Length of array to read in bytes
|
||||
* @val: Array of words to read
|
||||
*
|
||||
* Read multiple status registers (word-sized registers).
|
||||
*
|
||||
* Locking note: This function must be called with the device lock held.
|
||||
* Locking is not handled inside the function. Callers should ensure they
|
||||
* serialize access to the HW.
|
||||
*
|
||||
* Returns: 0 on success, negative value on failure.
|
||||
*/
|
||||
int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 len, u16 *buf)
|
||||
{
|
||||
int ret, i;
|
||||
int len_words = len / sizeof(u16);
|
||||
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS];
|
||||
|
||||
ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
|
||||
reg, NULL, 0, (u8 *) be_buf, len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < len_words; i++)
|
||||
buf[i] = be16_to_cpu(be_buf[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mma9551_read_status_words);
|
||||
|
||||
/**
|
||||
* mma9551_write_config_words() - write multiple config words
|
||||
* @client: I2C client
|
||||
* @app_id: Application ID
|
||||
* @reg: Application register
|
||||
* @len: Length of array to write in bytes
|
||||
* @val: Array of words to write
|
||||
*
|
||||
* Write multiple configuration registers (word-sized registers).
|
||||
*
|
||||
* Locking note: This function must be called with the device lock held.
|
||||
* Locking is not handled inside the function. Callers should ensure they
|
||||
* serialize access to the HW.
|
||||
*
|
||||
* Returns: 0 on success, negative value on failure.
|
||||
*/
|
||||
int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 len, u16 *buf)
|
||||
{
|
||||
int i;
|
||||
int len_words = len / sizeof(u16);
|
||||
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS];
|
||||
|
||||
for (i = 0; i < len_words; i++)
|
||||
be_buf[i] = cpu_to_be16(buf[i]);
|
||||
|
||||
return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG,
|
||||
reg, (u8 *) be_buf, len, NULL, 0);
|
||||
}
|
||||
EXPORT_SYMBOL(mma9551_write_config_words);
|
||||
|
||||
/**
|
||||
* mma9551_update_config_bits() - update bits in register
|
||||
* @client: I2C client
|
||||
|
@ -609,6 +773,25 @@ int mma9551_read_accel_scale(int *val, int *val2)
|
|||
}
|
||||
EXPORT_SYMBOL(mma9551_read_accel_scale);
|
||||
|
||||
/**
|
||||
* mma9551_app_reset() - reset application
|
||||
* @client: I2C client
|
||||
* @app_mask: Application to reset
|
||||
*
|
||||
* Reset the given application (using the Reset/Suspend/Clear
|
||||
* Control Application)
|
||||
*
|
||||
* Returns: 0 on success, negative value on failure.
|
||||
*/
|
||||
int mma9551_app_reset(struct i2c_client *client, u32 app_mask)
|
||||
{
|
||||
return mma9551_write_config_byte(client, MMA9551_APPID_RCS,
|
||||
MMA9551_RSC_RESET +
|
||||
MMA9551_RSC_OFFSET(app_mask),
|
||||
MMA9551_RSC_VAL(app_mask));
|
||||
}
|
||||
EXPORT_SYMBOL(mma9551_app_reset);
|
||||
|
||||
MODULE_AUTHOR("Irina Tirdea <irina.tirdea@intel.com>");
|
||||
MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
|
|
@ -21,9 +21,13 @@
|
|||
#define MMA9551_APPID_AFE 0x06
|
||||
#define MMA9551_APPID_TILT 0x0B
|
||||
#define MMA9551_APPID_SLEEP_WAKE 0x12
|
||||
#define MMA9551_APPID_RESET 0x17
|
||||
#define MMA9551_APPID_PEDOMETER 0x15
|
||||
#define MMA9551_APPID_RCS 0x17
|
||||
#define MMA9551_APPID_NONE 0xff
|
||||
|
||||
/* Reset/Suspend/Clear application app masks */
|
||||
#define MMA9551_RSC_PED BIT(21)
|
||||
|
||||
#define MMA9551_AUTO_SUSPEND_DELAY_MS 2000
|
||||
|
||||
enum mma9551_gpio_pin {
|
||||
|
@ -48,8 +52,18 @@ int mma9551_write_config_byte(struct i2c_client *client, u8 app_id,
|
|||
u16 reg, u8 val);
|
||||
int mma9551_read_status_byte(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 *val);
|
||||
int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u16 *val);
|
||||
int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u16 val);
|
||||
int mma9551_read_status_word(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u16 *val);
|
||||
int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 len, u16 *buf);
|
||||
int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 len, u16 *buf);
|
||||
int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 len, u16 *buf);
|
||||
int mma9551_update_config_bits(struct i2c_client *client, u8 app_id,
|
||||
u16 reg, u8 mask, u8 val);
|
||||
int mma9551_gpio_config(struct i2c_client *client, enum mma9551_gpio_pin pin,
|
||||
|
@ -62,5 +76,6 @@ int mma9551_read_accel_chan(struct i2c_client *client,
|
|||
const struct iio_chan_spec *chan,
|
||||
int *val, int *val2);
|
||||
int mma9551_read_accel_scale(int *val, int *val2);
|
||||
int mma9551_app_reset(struct i2c_client *client, u32 app_mask);
|
||||
|
||||
#endif /* _MMA9551_CORE_H_ */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue