hwmon: lis3dh: Add support of the ST LSM303DLHC accelerometer
authorZhifeng Wang <zhifeng.wang@intel.com>
Wed, 15 Feb 2012 03:03:17 +0000 (11:03 +0800)
committerbuildbot <buildbot@intel.com>
Thu, 16 Feb 2012 01:56:59 +0000 (17:56 -0800)
BZ: 22035

Modify the ST LIS3DH accelerometer driver code to support the new type
accelerometer ST LSM303DLHC.

Basically, the ST LSM303DLHC is a combination of the LIS3DH accelerometer
and a magnetometer. So very few code changes are necessary.

Change-Id: I858870fbf48336db0ad7b14ed0f43478ec76b777
Signed-off-by: Zhifeng Wang <zhifeng.wang@intel.com>
Reviewed-on: http://android.intel.com:8080/22091
Reviewed-by: Liu, Hong <hong.liu@intel.com>
Reviewed-by: Du, Alek <alek.du@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
arch/x86/platform/intel-mid/board-blackbay.c
drivers/hwmon/lis3dh_acc.c
include/linux/input/lis3dh.h

index 0249104..06784a0 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/module.h>
 #include <linux/notifier.h>
 #include <linux/intel_mid_pm.h>
+#include <linux/input/lis3dh.h>
 #include <linux/usb/penwell_otg.h>
 #include <linux/hsi/hsi.h>
 #include <linux/hsi/intel_mid_hsi.h>
@@ -185,6 +186,24 @@ static void *mpu3050_platform_data(void *info)
        return NULL;
 }
 
+static void *lsm303dlhc_accel_platform_data(void *info)
+{
+       static struct lis3dh_acc_platform_data accel;
+
+       accel.poll_interval = 200;
+       accel.negate_x = 1;
+       accel.negate_y = 0;
+       accel.negate_z = 0;
+       accel.axis_map_x = 0;
+       accel.axis_map_y = 1;
+       accel.axis_map_z = 2;
+       accel.gpio_int1 = get_gpio_by_name("accel_int");
+       accel.gpio_int2 = get_gpio_by_name("accel_2");
+       accel.model = MODEL_LSM303DLHC;
+
+       return &accel;
+}
+
 static void *ektf2136_spi_platform_data(void *info)
 {
        static int dummy;
@@ -1602,6 +1621,8 @@ struct devs_id __initconst device_ids[] = {
        {"ov8830", SFI_DEV_TYPE_I2C, 0, &ov8830_platform_data_init},
        {"synaptics_3202", SFI_DEV_TYPE_I2C, 0, &s3202_platform_data_init},
 
+       {"lsm303dl", SFI_DEV_TYPE_I2C, 0, &lsm303dlhc_accel_platform_data},
+
        {},
 };
 
index 41cdad6..cc05413 100644 (file)
@@ -255,15 +255,18 @@ static int lis3dh_acc_hw_init(struct lis3dh_acc_data *acc)
 
        dev_dbg(&acc->client->dev, "hw init start\n");
 
-       err = lis3dh_acc_i2c_read(acc, WHO_AM_I, buf, 1);
-       if (err < 0) {
-               dev_warn(&acc->client->dev, "Error reading WHO_AM_I: is device "
-                       "available/working?\n");
-               goto err_firstread;
-       } else {
-               acc->hw_working = 1;
+       /* LSM303DLHC doesn't have WHO_AM_I register */
+       if (acc->pdata->model != MODEL_LSM303DLHC) {
+               err = lis3dh_acc_i2c_read(acc, WHO_AM_I, buf, 1);
+               if (err < 0) {
+                       dev_warn(&acc->client->dev, "Error reading WHO_AM_I: "
+                                       "is device available/working?\n");
+                       goto err_firstread;
+               }
        }
 
+       acc->hw_working = 1;
+
        buf[0] = acc->resume_state[RES_CTRL_REG1];
        err = lis3dh_acc_i2c_write(acc, CTRL_REG1, buf, 1);
        if (err < 0)
@@ -1262,7 +1265,7 @@ static const struct dev_pm_ops lis3dh_acc_pm_ops = {
 };
 
 static const struct i2c_device_id lis3dh_acc_id[]
-               = { { LIS3DH_ACC_DEV_NAME, 0 }, { }, };
+               = { { LIS3DH_ACC_DEV_NAME, 0 }, { "lsm303dl", 0 }, { }, };
 
 MODULE_DEVICE_TABLE(i2c, lis3dh_acc_id);
 
index 2b5e368..49a7498 100644 (file)
@@ -68,6 +68,11 @@ Revision 1-0-7 26/11/2010
 #define LIS3DH_ACC_G_8G                0x20
 #define LIS3DH_ACC_G_16G               0x30
 
+/* supported accelerometer model */
+enum acc_model {
+       MODEL_LIS3DH,
+       MODEL_LSM303DLHC
+};
 
 #ifdef __KERNEL__
 struct lis3dh_acc_platform_data {
@@ -94,6 +99,8 @@ struct lis3dh_acc_platform_data {
         */
        int gpio_int1;
        int gpio_int2;
+
+       enum acc_model model;
 };
 #endif /* __KERNEL__ */