iio: accel: Add support for Freescale MMA7660FC
PATCH v2 1/1 iio: accel: Add support for Freescale MMA7660FC
Minimal implementation of an IIO driver for the Freescale MMA7660FC 3-axis accelerometer. Datasheet:
http://www.freescale.com.cn/files/sensors/doc/data_sheet/MMA7660FC.pdf
Includes:
- ACPI support;
- read_raw for x,y,z axes;
- reading and setting the scale (range) parameter.
- power management
--- drivers/iio/accel/Kconfig | 10 ++ drivers/iio/accel/Makefile | 2 + drivers/iio/accel/mma7660.c | 275 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 drivers/iio/accel/mma7660.c
drivers/iio/accel/Kconfig +10 -0
@@ -54,6 +54,16 @@ config HID_SENSOR_ACCEL_3D To compile this driver as a module, choose M here: the module will be called hid-sensor-accel-3d. +config MMA7660 + tristate "Freescale MMA7660FC 3-Axis Accelerometer Driver" + depends on I2C + help + Say yes here to get support for the Freescale MMA7660FC 3-Axis + accelerometer. + + Choosing M will build the driver as a module. If so, the module + will be called mma7660. + config IIO_ST_ACCEL_3AXIS tristate "STMicroelectronics accelerometers 3-Axis Driver" depends on (I2C || SPI_MASTER) && SYSFS
drivers/iio/accel/Makefile +2 -0
@@ -15,6 +15,8 @@ obj-$(CONFIG_MMA7455) += mma7455_core.o obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o obj-$(CONFIG_MMA7455_SPI) += mma7455_spi.o +obj-$(CONFIG_MMA7660) += mma7660.o + obj-$(CONFIG_MMA8452) += mma8452.o obj-$(CONFIG_MMA9551_CORE) += mma9551_core.o
drivers/iio/accel/mma7660.c new file +275 -0
275 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 3 lines · Constantin Musca
Minimal implementation of an IIO driver for the Freescale MMA7660FC 3-axis accelerometer. Datasheet:
http://www.freescale.com.cn/files/sensors/doc/data_sheet/MMA7660FC.pdf
comments below
Quoted 75 lines
Includes:
- ACPI support;
-read_rawfor x,y,z axes;
- reading and setting the scale (range) parameter.
- power managementSigned-off-by Constantin Musca <[email protected]>--- drivers/iio/accel/Kconfig | 10 ++ drivers/iio/accel/Makefile | 2 + drivers/iio/accel/mma7660.c | 275 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 drivers/iio/accel/mma7660.cdrivers/iio/accel/Kconfig +10
-0@@ -54,6 +54,16 @@ config HID_SENSOR_ACCEL_3D To compile this driver as a module, choose M here: the module will be called hid-sensor-accel-3d. +config MMA7660 + tristate "Freescale MMA7660FC 3-Axis Accelerometer Driver" + depends on I2C + help + Say yes here to get support for the Freescale MMA7660FC 3-Axis + accelerometer. + + Choosing M will build the driver as a module. If so, the module + will be called mma7660. + config IIO_ST_ACCEL_3AXIS tristate "STMicroelectronics accelerometers 3-Axis Driver" depends on (I2C || SPI_MASTER) && SYSFSdrivers/iio/accel/Makefile +2
-0@@ -15,6 +15,8 @@ obj-$(CONFIG_MMA7455) += mma7455_core.o obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o obj-$(CONFIG_MMA7455_SPI) += mma7455_spi.o +obj-$(CONFIG_MMA7660) += mma7660.o + obj-$(CONFIG_MMA8452) += mma8452.o obj-$(CONFIG_MMA9551_CORE) += mma9551_core.odrivers/iio/accel/mma7660.c new file +21
-0@@ -0,0 +1,275 @@ +/** +* Freescale MMA7660FC 3-Axis Accelerometer +* +* Copyright (c) 2016, Intel Corporation. +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* IIO driver for Freescale MMA7660FC; 7-bit I2C address: 0x4c. +*/ + +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> + +#define MMA7660_DRIVER_NAME "mma7660" + +#define MMA7660_REG_XOUT 0x00
drivers/iio/accel/mma7660.c line 31
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+#define MMA7660_REG_YOUT 0x01 +#define MMA7660_REG_ZOUT 0x02 +#define MMA7660_REG_OUT_BIT_ALERT BIT(6) + +#define MMA7660_REG_MODE 0x07 +#define MMA7660_REG_MODE_BIT_MODE BIT(0) +#define MMA7660_REG_MODE_BIT_TON BIT(2) + +#define MMA7660_MODE_STANDBY 0 +#define MMA7660_MODE_ACTIVE 1
those two could be an enum?
drivers/iio/accel/mma7660.c line 40
Quoted 9 lines
drivers/iio/accel/mma7660.c new file +9
-0+ +#define MMA7660_I2C_READ_RETRIES 5 + +/* +* The accelerometer has one measurement range: +* +* -1.5g - +1.5g (6-bit, signed) +* +* scale1 = (1.5 + 1.5) * 9.81 / (2^6 - 1) = 0.467142857
why named scale1?
Quoted 15 lines
drivers/iio/accel/mma7660.c new file +15
-0+*/ + +#define MMA7660_SCALE_AVAIL "0.467142857" + +const int mma7660_nscale =467142857 ; + +#define MMA7660_CHANNEL (reg, axis) { \ + .type = IIO_ACCEL, \ + .address = reg, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +} +
drivers/iio/accel/mma7660.c line 65
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+static const struct iio_chan_spec mma7660_channels[] = { +MMA7660_CHANNEL (MMA7660_REG_XOUT ,X ), +MMA7660_CHANNEL (MMA7660_REG_YOUT ,Y ), +MMA7660_CHANNEL (MMA7660_REG_ZOUT ,Z ), +}; + +struct mma7660_data { +struct i2c_client *client; +struct mutex lock; +u8 mode;
use enum here
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+}; + +static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL); + +static struct attribute *mma7660_attributes[] = { + &iio_const_attr_in_accel_scale_available.dev_attr.attr, +NULL , +}; + +static const struct attribute_group mma7660_attribute_group = {
drivers/iio/accel/mma7660.c line 85
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+ .attrs = mma7660_attributes +}; + +static int mma7660_set_mode (struct mma7660_data *data,u8 mode) +{ +int ret; +struct i2c_client *client = data->client; + +if (mode >1 ) +return -EINVAL ;
check can probably be dropped
drivers/iio/accel/mma7660.c line 92
Quoted 7 lines
drivers/iio/accel/mma7660.c new file +7
-0+ +if (mode == data->mode) +return 0 ; + + ret =i2c_smbus_read_byte_data (client,MMA7660_REG_MODE ); +if (ret <0 ) { +dev_err (&client->dev,"failed to change sensor mode\n" );
to read
Quoted 18 lines
drivers/iio/accel/mma7660.c new file +18
-0+return ret; + } + +if (mode ==MMA7660_MODE_ACTIVE ) { + ret &= ~MMA7660_REG_MODE_BIT_TON ; + ret |=MMA7660_REG_MODE_BIT_MODE ; + }else { + ret &= ~MMA7660_REG_MODE_BIT_TON ; + ret &= ~MMA7660_REG_MODE_BIT_MODE ; + } + + ret =i2c_smbus_write_byte_data (client,MMA7660_REG_MODE , ret); +if (ret <0 ) { +dev_err (&client->dev,"failed to change sensor mode\n" ); +return ret; + } + + data->mode = mode;
drivers/iio/accel/mma7660.c line 120
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+return ret; +} + +static int mma7660_read_accel (struct mma7660_data *data,u8 address) +{ +int ret, retries =MMA7660_I2C_READ_RETRIES ; +struct i2c_client *client = data->client; + +if (address >2 ) +return -EINVAL ;
check needed?
drivers/iio/accel/mma7660.c line 128
Quoted 8 lines
drivers/iio/accel/mma7660.c new file +8
-0+ +do { + ret =i2c_smbus_read_byte_data (client, address); +if (ret <0 ) { +dev_err (&client->dev,"register read failed\n" ); +return ret; + } + }while (--retries >0 && ret &MMA7660_REG_OUT_BIT_ALERT );
if READ_RETRIES were 1, this would always fail, no matter what OUT_BIT_ALERT is
Quoted 8 lines
drivers/iio/accel/mma7660.c new file +8
-0+ +if (retries ==0 ) { +dev_err (&client->dev,"all register read retries failed" ); +return -ETIMEDOUT ; + } + +return ret; +}
drivers/iio/accel/mma7660.c line 146
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+ +static int mma7660_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct mma7660_data *data =iio_priv (indio_dev); +int ret; + +if (chan->type !=IIO_ACCEL ) +return -EINVAL ;
check needed?
drivers/iio/accel/mma7660.c line 159
Quoted 13 lines
drivers/iio/accel/mma7660.c new file +13
-0+ +switch (mask) { +case IIO_CHAN_INFO_RAW : +mutex_lock (&data->lock); + ret =mma7660_read_accel (data, chan->address); +mutex_unlock (&data->lock); +if (ret <0 ) +return ret; + *val =sign_extend32 (ret,5 ); +return IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : + *val =0 ; + *val2 = mma7660_nscale;
nscale is NANO, not MICRO?
Quoted 12 lines
drivers/iio/accel/mma7660.c new file +12
-0+return IIO_VAL_INT_PLUS_MICRO ; +default : +return -EINVAL ; + } + +return -EINVAL ; +} + +static const struct iio_info mma7660_info = { + .driver_module =THIS_MODULE , + .read_raw = mma7660_read_raw, + .attrs = &mma7660_attribute_group,
drivers/iio/accel/mma7660.c line 181
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+}; + +static int mma7660_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +int ret; +struct iio_dev *indio_dev; +struct mma7660_data *data; + + indio_dev =iio_device_alloc (sizeof (*data));
devm_
drivers/iio/accel/mma7660.c line 191
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+if (!indio_dev) { +dev_err (&client->dev,"iio allocation failed!\n" ); +return -ENOMEM ; + } + + data =iio_priv (indio_dev); + data->client = client; +i2c_set_clientdata (client, indio_dev); +mutex_init (&data->lock); + data->mode =-1 ;
MODE_STANDBY probably
Quoted 48 lines
drivers/iio/accel/mma7660.c new file +48
-0+ + indio_dev->dev.parent = &client->dev; + indio_dev->info = &mma7660_info; + indio_dev->name =MMA7660_DRIVER_NAME ; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->channels = mma7660_channels; + indio_dev->num_channels =ARRAY_SIZE (mma7660_channels); + + ret =mma7660_set_mode (data,MMA7660_MODE_ACTIVE ); +if (ret <0 ) +return ret; + + ret =iio_device_register (indio_dev); +if (ret <0 ) { +dev_err (&client->dev,"device_register failed\n" ); +mma7660_set_mode (data,MMA7660_MODE_STANDBY ); + } + +return ret; +} + +static int mma7660_remove (struct i2c_client *client) +{ +struct iio_dev *indio_dev =i2c_get_clientdata (client); + +iio_device_unregister (indio_dev); + +return mma7660_set_mode (iio_priv (indio_dev),MMA7660_MODE_STANDBY ); +} + +#ifdef CONFIG_PM_SLEEP +static int mma7660_suspend (struct device *dev) +{ +struct mma7660_data *data; + + data =iio_priv (i2c_get_clientdata (to_i2c_client (dev))); + +return mma7660_set_mode (data,MMA7660_MODE_STANDBY ); +} + +static int mma7660_resume (struct device *dev) +{ +struct mma7660_data *data; + + data =iio_priv (i2c_get_clientdata (to_i2c_client (dev))); + +return mma7660_set_mode (data,MMA7660_MODE_ACTIVE ); +}
drivers/iio/accel/mma7660.c line 249
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+ +static SIMPLE_DEV_PM_OPS(mma7660_pm_ops, mma7660_suspend, mma7660_resume); + +#define MMA7660_PM_OPS (&mma7660_pm_ops) +#else +#define MMA7660_PM_OPS NULL +#endif + +static const struct i2c_device_id mma7660_i2c_id[] = { + {"MMA7660" ,0 },
really uppercase?
Quoted 27 lines
drivers/iio/accel/mma7660.c new file +26
-0+ {} +}; + +static const struct acpi_device_id mma7660_acpi_id[] = { + {"MMA7660" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (acpi, mma7660_acpi_id); + +static struct i2c_driver mma7660_driver = { + .driver = { + .name ="mma7660" , + .pm =MMA7660_PM_OPS , + .acpi_match_table =ACPI_PTR (mma7660_acpi_id), + }, + .probe = mma7660_probe, + .remove = mma7660_remove, + .id_table = mma7660_i2c_id, +}; + +module_i2c_driver (mma7660_driver); + +MODULE_AUTHOR ("Constantin Musca <[email protected]>" ); +MODULE_DESCRIPTION ("Freescale MMA7660FC 3-Axis Accelerometer driver" ); +MODULE_LICENSE ("GPL v2" );
Signature · 2 lines
Peter Meerwald-Stadler +43-664-2444418 (mobile)
Thanks. Please see patch v3.
Constantin
Quoted 362 lines · Peter Meerwald-Stadler
Quoted 3 lines · Constantin Musca
Minimal implementation of an IIO driver for the Freescale MMA7660FC 3-axis accelerometer. Datasheet:
http://www.freescale.com.cn/files/sensors/doc/data_sheet/MMA7660FC.pdfcomments below
Quoted 75 lines
Includes:
- ACPI support;
-read_rawfor x,y,z axes;
- reading and setting the scale (range) parameter.
- power managementSigned-off-by Constantin Musca <[email protected]>--- drivers/iio/accel/Kconfig | 10 ++ drivers/iio/accel/Makefile | 2 + drivers/iio/accel/mma7660.c | 275 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+)create mode 100644
drivers/iio/accel/mma7660.cdrivers/iio/accel/Kconfig +10
-0@@ -54,6 +54,16 @@ config HID_SENSOR_ACCEL_3D To compile this driver as a module, choose M here: the module will be called hid-sensor-accel-3d. +config MMA7660 + tristate "Freescale MMA7660FC 3-Axis Accelerometer Driver" + depends on I2C + help + Say yes here to get support for the Freescale MMA7660FC 3-Axis + accelerometer. + + Choosing M will build the driver as a module. If so, the module + will be called mma7660. + config IIO_ST_ACCEL_3AXIS tristate "STMicroelectronics accelerometers 3-Axis Driver" depends on (I2C || SPI_MASTER) && SYSFSdrivers/iio/accel/Makefile +2
-0@@ -15,6 +15,8 @@ obj-$(CONFIG_MMA7455) += mma7455_core.o obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o obj-$(CONFIG_MMA7455_SPI) += mma7455_spi.o +obj-$(CONFIG_MMA7660) += mma7660.o + obj-$(CONFIG_MMA8452) += mma8452.o obj-$(CONFIG_MMA9551_CORE) += mma9551_core.odrivers/iio/accel/mma7660.c new file +21
-0@@ -0,0 +1,275 @@ +/** +* Freescale MMA7660FC 3-Axis Accelerometer +* +* Copyright (c) 2016, Intel Corporation. +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* IIO driver for Freescale MMA7660FC; 7-bit I2C address: 0x4c. +*/ + +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> + +#define MMA7660_DRIVER_NAME "mma7660" + +#define MMA7660_REG_XOUT 0x00drivers/iio/accel/mma7660.c line 31
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+#define MMA7660_REG_YOUT 0x01 +#define MMA7660_REG_ZOUT 0x02 +#define MMA7660_REG_OUT_BIT_ALERT BIT(6) + +#define MMA7660_REG_MODE 0x07 +#define MMA7660_REG_MODE_BIT_MODE BIT(0) +#define MMA7660_REG_MODE_BIT_TON BIT(2) + +#define MMA7660_MODE_STANDBY 0 +#define MMA7660_MODE_ACTIVE 1those two could be an enum?
drivers/iio/accel/mma7660.c line 40
Quoted 9 lines
drivers/iio/accel/mma7660.c new file +9
-0+ +#define MMA7660_I2C_READ_RETRIES 5 + +/* +* The accelerometer has one measurement range: +* +* -1.5g - +1.5g (6-bit, signed) +* +* scale1 = (1.5 + 1.5) * 9.81 / (2^6 - 1) = 0.467142857 why named scale1?
Quoted 15 lines
drivers/iio/accel/mma7660.c new file +15
-0+*/ + +#define MMA7660_SCALE_AVAIL "0.467142857" + +const int mma7660_nscale =467142857 ; + +#define MMA7660_CHANNEL (reg, axis) { \ + .type = IIO_ACCEL, \ + .address = reg, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +} +drivers/iio/accel/mma7660.c line 65
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+static const struct iio_chan_spec mma7660_channels[] = { +MMA7660_CHANNEL (MMA7660_REG_XOUT ,X ), +MMA7660_CHANNEL (MMA7660_REG_YOUT ,Y ), +MMA7660_CHANNEL (MMA7660_REG_ZOUT ,Z ), +}; + +struct mma7660_data { +struct i2c_client *client; +struct mutex lock; +u8 mode;use enum here
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+}; + +static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL); + +static struct attribute *mma7660_attributes[] = { + &iio_const_attr_in_accel_scale_available.dev_attr.attr, +NULL , +}; + +static const struct attribute_group mma7660_attribute_group = {drivers/iio/accel/mma7660.c line 85
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+ .attrs = mma7660_attributes +}; + +static int mma7660_set_mode (struct mma7660_data *data,u8 mode) +{ +int ret; +struct i2c_client *client = data->client; + +if (mode >1 ) +return -EINVAL ;check can probably be dropped
drivers/iio/accel/mma7660.c line 92
Quoted 7 lines
drivers/iio/accel/mma7660.c new file +7
-0+ +if (mode == data->mode) +return 0 ; + + ret =i2c_smbus_read_byte_data (client,MMA7660_REG_MODE ); +if (ret <0 ) { +dev_err (&client->dev,"failed to change sensor mode\n" );to read
Quoted 18 lines
drivers/iio/accel/mma7660.c new file +18
-0+return ret; + } + +if (mode ==MMA7660_MODE_ACTIVE ) { + ret &= ~MMA7660_REG_MODE_BIT_TON ; + ret |=MMA7660_REG_MODE_BIT_MODE ; + }else { + ret &= ~MMA7660_REG_MODE_BIT_TON ; + ret &= ~MMA7660_REG_MODE_BIT_MODE ; + } + + ret =i2c_smbus_write_byte_data (client,MMA7660_REG_MODE , ret); +if (ret <0 ) { +dev_err (&client->dev,"failed to change sensor mode\n" ); +return ret; + } + + data->mode = mode;drivers/iio/accel/mma7660.c line 120
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+return ret; +} + +static int mma7660_read_accel (struct mma7660_data *data,u8 address) +{ +int ret, retries =MMA7660_I2C_READ_RETRIES ; +struct i2c_client *client = data->client; + +if (address >2 ) +return -EINVAL ;check needed?
drivers/iio/accel/mma7660.c line 128
Quoted 8 lines
drivers/iio/accel/mma7660.c new file +8
-0+ +do { + ret =i2c_smbus_read_byte_data (client, address); +if (ret <0 ) { +dev_err (&client->dev,"register read failed\n" ); +return ret; + } + }while (--retries >0 && ret &MMA7660_REG_OUT_BIT_ALERT );if
READ_RETRIESwere 1, this would always fail, no matter whatOUT_BIT_ALERTisQuoted 8 lines
drivers/iio/accel/mma7660.c new file +8
-0+ +if (retries ==0 ) { +dev_err (&client->dev,"all register read retries failed" ); +return -ETIMEDOUT ; + } + +return ret; +}drivers/iio/accel/mma7660.c line 146
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+ +static int mma7660_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct mma7660_data *data =iio_priv (indio_dev); +int ret; + +if (chan->type !=IIO_ACCEL ) +return -EINVAL ;check needed?
drivers/iio/accel/mma7660.c line 159
Quoted 13 lines
drivers/iio/accel/mma7660.c new file +13
-0+ +switch (mask) { +case IIO_CHAN_INFO_RAW : +mutex_lock (&data->lock); + ret =mma7660_read_accel (data, chan->address); +mutex_unlock (&data->lock); +if (ret <0 ) +return ret; + *val =sign_extend32 (ret,5 ); +return IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : + *val =0 ; + *val2 = mma7660_nscale;nscale is NANO, not MICRO?
Quoted 12 lines
drivers/iio/accel/mma7660.c new file +12
-0+return IIO_VAL_INT_PLUS_MICRO ; +default : +return -EINVAL ; + } + +return -EINVAL ; +} + +static const struct iio_info mma7660_info = { + .driver_module =THIS_MODULE , + .read_raw = mma7660_read_raw, + .attrs = &mma7660_attribute_group,drivers/iio/accel/mma7660.c line 181
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+}; + +static int mma7660_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +int ret; +struct iio_dev *indio_dev; +struct mma7660_data *data; + + indio_dev =iio_device_alloc (sizeof (*data));
devm_drivers/iio/accel/mma7660.c line 191
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+if (!indio_dev) { +dev_err (&client->dev,"iio allocation failed!\n" ); +return -ENOMEM ; + } + + data =iio_priv (indio_dev); + data->client = client; +i2c_set_clientdata (client, indio_dev); +mutex_init (&data->lock); + data->mode =-1 ;
MODE_STANDBYprobablyQuoted 48 lines
drivers/iio/accel/mma7660.c new file +48
-0+ + indio_dev->dev.parent = &client->dev; + indio_dev->info = &mma7660_info; + indio_dev->name =MMA7660_DRIVER_NAME ; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->channels = mma7660_channels; + indio_dev->num_channels =ARRAY_SIZE (mma7660_channels); + + ret =mma7660_set_mode (data,MMA7660_MODE_ACTIVE ); +if (ret <0 ) +return ret; + + ret =iio_device_register (indio_dev); +if (ret <0 ) { +dev_err (&client->dev,"device_register failed\n" ); +mma7660_set_mode (data,MMA7660_MODE_STANDBY ); + } + +return ret; +} + +static int mma7660_remove (struct i2c_client *client) +{ +struct iio_dev *indio_dev =i2c_get_clientdata (client); + +iio_device_unregister (indio_dev); + +return mma7660_set_mode (iio_priv (indio_dev),MMA7660_MODE_STANDBY ); +} + +#ifdef CONFIG_PM_SLEEP +static int mma7660_suspend (struct device *dev) +{ +struct mma7660_data *data; + + data =iio_priv (i2c_get_clientdata (to_i2c_client (dev))); + +return mma7660_set_mode (data,MMA7660_MODE_STANDBY ); +} + +static int mma7660_resume (struct device *dev) +{ +struct mma7660_data *data; + + data =iio_priv (i2c_get_clientdata (to_i2c_client (dev))); + +return mma7660_set_mode (data,MMA7660_MODE_ACTIVE ); +}drivers/iio/accel/mma7660.c line 249
Quoted 10 lines
drivers/iio/accel/mma7660.c new file +10
-0+ +static SIMPLE_DEV_PM_OPS(mma7660_pm_ops, mma7660_suspend, mma7660_resume); + +#define MMA7660_PM_OPS (&mma7660_pm_ops) +#else +#define MMA7660_PM_OPS NULL +#endif + +static const struct i2c_device_id mma7660_i2c_id[] = { + {"MMA7660" ,0 },really uppercase?
Quoted 27 lines
drivers/iio/accel/mma7660.c new file +26
-0+ {} +}; + +static const struct acpi_device_id mma7660_acpi_id[] = { + {"MMA7660" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (acpi, mma7660_acpi_id); + +static struct i2c_driver mma7660_driver = { + .driver = { + .name ="mma7660" , + .pm =MMA7660_PM_OPS , + .acpi_match_table =ACPI_PTR (mma7660_acpi_id), + }, + .probe = mma7660_probe, + .remove = mma7660_remove, + .id_table = mma7660_i2c_id, +}; + +module_i2c_driver (mma7660_driver); + +MODULE_AUTHOR ("Constantin Musca <[email protected]>" ); +MODULE_DESCRIPTION ("Freescale MMA7660FC 3-Axis Accelerometer driver" ); +MODULE_LICENSE ("GPL v2" );