if (num_outbytes)
memcpy(outbytes, rsp.buf, num_outbytes);
return 0;
}
/** * mma9551_read_config_byte() - read 1 configuration byte * @client: I2C client * @app_id: Application ID * @reg: Application register * @val: Pointer to store value read * * Read one configuration byte 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_byte(struct i2c_client *client, u8 app_id,
u16 reg, u8 *val)
{ return mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
reg, NULL, 0, val, 1);
}
EXPORT_SYMBOL_NS(mma9551_read_config_byte, "IIO_MMA9551");
/** * mma9551_write_config_byte() - write 1 configuration byte * @client: I2C client * @app_id: Application ID * @reg: Application register * @val: Value to write * * Write one configuration byte 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_byte(struct i2c_client *client, u8 app_id,
u16 reg, u8 val)
{ return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg,
&val, 1, NULL, 0);
}
EXPORT_SYMBOL_NS(mma9551_write_config_byte, "IIO_MMA9551");
/** * mma9551_read_status_byte() - read 1 status byte * @client: I2C client * @app_id: Application ID * @reg: Application register * @val: Pointer to store value read * * Read one status byte 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_status_byte(struct i2c_client *client, u8 app_id,
u16 reg, u8 *val)
{ return mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
reg, NULL, 0, val, 1);
}
EXPORT_SYMBOL_NS(mma9551_read_status_byte, "IIO_MMA9551");
/** * 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); if (ret < 0) return ret;
/** * 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);
/** * mma9551_read_status_word() - read 1 status word * @client: I2C client * @app_id: Application ID * @reg: Application register * @val: Pointer to store value read * * Read one status 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_status_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_STATUS,
reg, NULL, 0, (u8 *)&v, 2); if (ret < 0) return ret;
/** * 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 words) * @buf: 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;
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
/** * 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 words) * @buf: 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;
__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
/** * 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 words) * @buf: 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;
__be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2];
/** * mma9551_update_config_bits() - update bits in register * @client: I2C client * @app_id: Application ID * @reg: Application register * @mask: Mask for the bits to update * @val: Value of the bits to update * * Update bits in the given register using a bit mask. * * 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_update_config_bits(struct i2c_client *client, u8 app_id,
u16 reg, u8 mask, u8 val)
{ int ret;
u8 tmp, orig;
ret = mma9551_read_config_byte(client, app_id, reg, &orig); if (ret < 0) return ret;
/** * mma9551_gpio_config() - configure gpio * @client: I2C client * @pin: GPIO pin to configure * @app_id: Application ID * @bitnum: Bit number of status register being assigned to the GPIO pin. * @polarity: The polarity parameter is described in section 6.2.2, page 66, * of the Software Reference Manual. Basically, polarity=0 means * the interrupt line has the same value as the selected bit, * while polarity=1 means the line is inverted. * * Assign a bit from an application’s status register to a specific GPIO pin. * * 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_gpio_config(struct i2c_client *client, enum mma9551_gpio_pin pin,
u8 app_id, u8 bitnum, int polarity)
{
u8 reg, pol_mask, pol_val; int ret;
/** * mma9551_read_version() - read device version information * @client: I2C client * * Read version information and print device id and firmware version. * * 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_version(struct i2c_client *client)
{ struct mma9551_version_info info; int ret;
ret = mma9551_transfer(client, MMA9551_APPID_VERSION, 0x00, 0x00,
NULL, 0, (u8 *)&info, sizeof(info)); if (ret < 0) return ret;
dev_info(&client->dev, "device ID 0x%x, firmware version %02x.%02x\n",
be32_to_cpu(info.device_id), info.fw_version[0],
info.fw_version[1]);
/** * mma9551_set_device_state() - sets HW power mode * @client: I2C client * @enable: Use true to power on device, false to cause the device * to enter sleep. * * Set power on/off for device using the Sleep/Wake Application. * When enable is true, power on chip and enable doze mode. * When enable is false, enter sleep mode (device remains in the * lowest-power mode). * * 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_set_device_state(struct i2c_client *client, bool enable)
{ return mma9551_update_config_bits(client, MMA9551_APPID_SLEEP_WAKE,
MMA9551_SLEEP_CFG,
MMA9551_SLEEP_CFG_SNCEN |
MMA9551_SLEEP_CFG_FLEEN |
MMA9551_SLEEP_CFG_SCHEN,
enable ? MMA9551_SLEEP_CFG_SCHEN |
MMA9551_SLEEP_CFG_FLEEN :
MMA9551_SLEEP_CFG_SNCEN);
}
EXPORT_SYMBOL_NS(mma9551_set_device_state, "IIO_MMA9551");
/** * mma9551_set_power_state() - sets runtime PM state * @client: I2C client * @on: Use true to power on device, false to power off * * Resume or suspend the device using Runtime PM. * The device will suspend after the autosuspend delay. * * Returns: 0 on success, negative value on failure.
*/ int mma9551_set_power_state(struct i2c_client *client, bool on)
{ #ifdef CONFIG_PM int ret;
if (on)
ret = pm_runtime_resume_and_get(&client->dev); else {
pm_runtime_mark_last_busy(&client->dev);
ret = pm_runtime_put_autosuspend(&client->dev);
}
if (ret < 0) {
dev_err(&client->dev, "failed to change power state to %d\n", on);
/** * mma9551_sleep() - sleep * @freq: Application frequency * * Firmware applications run at a certain frequency on the * device. Sleep for one application cycle to make sure the * application had time to run once and initialize set values.
*/ void mma9551_sleep(int freq)
{ int sleep_val = 1000 / freq;
/** * mma9551_read_accel_chan() - read accelerometer channel * @client: I2C client * @chan: IIO channel * @val: Pointer to the accelerometer value read * @val2: Unused * * Read accelerometer value for the specified channel. * * 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: IIO_VAL_INT on success, negative value on failure.
*/ int mma9551_read_accel_chan(struct i2c_client *client, conststruct iio_chan_spec *chan, int *val, int *val2)
{
u16 reg_addr;
s16 raw_accel; int ret;
switch (chan->channel2) { case IIO_MOD_X:
reg_addr = MMA9551_AFE_X_ACCEL_REG; break; case IIO_MOD_Y:
reg_addr = MMA9551_AFE_Y_ACCEL_REG; break; case IIO_MOD_Z:
reg_addr = MMA9551_AFE_Z_ACCEL_REG; break; default: return -EINVAL;
}
ret = mma9551_set_power_state(client, true); if (ret < 0) return ret;
ret = mma9551_read_status_word(client, MMA9551_APPID_AFE,
reg_addr, &raw_accel); if (ret < 0) goto out_poweroff;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.