]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00277864 input: mma8450: Add chip id check in probe
authorLuwei Zhou <b45643@freescale.com>
Tue, 3 Sep 2013 09:32:55 +0000 (17:32 +0800)
committerNitin Garg <nitin.garg@freescale.com>
Fri, 16 Jan 2015 03:17:31 +0000 (21:17 -0600)
Add chip ID check in probe function. The mma8450 is
on the E-INK daughter board. When the daughter board
is not pluged, there would be polling error log
continuously. Add the check to avoid this.

Signed-off-by: Luwei Zhou <b45643@freescale.com>
(cherry picked from commit e9f2c4cf673dee1527925f30a9f3fd137d9799ad)

drivers/input/misc/mma8450.c

index 59d4dcddf6de0cf4d1c5384c977a36c319d66389..7744d23cc584033aa8ea7a76e10bb37a0c1d9fc5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  Driver for Freescale's 3-Axis Accelerometer MMA8450
  *
- *  Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *  Copyright (C) 2011-2014 Freescale Semiconductor, Inc. All Rights Reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -51,6 +51,8 @@
 
 #define MMA8450_CTRL_REG1      0x38
 #define MMA8450_CTRL_REG2      0x39
+#define MMA8450_ID             0xC6
+#define MMA8450_WHO_AM_I       0x0F
 
 /* mma8450 status */
 struct mma8450 {
@@ -172,7 +174,25 @@ static int mma8450_probe(struct i2c_client *c,
 {
        struct input_polled_dev *idev;
        struct mma8450 *m;
-       int err;
+       int err, client_id;
+       struct i2c_adapter *adapter = NULL;
+
+       adapter = to_i2c_adapter(c->dev.parent);
+       err = i2c_check_functionality(adapter,
+                                        I2C_FUNC_SMBUS_BYTE |
+                                        I2C_FUNC_SMBUS_BYTE_DATA);
+       if (!err)
+               goto err_out;
+
+       client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
+
+       if (MMA8450_ID != client_id) {
+               dev_err(&c->dev,
+                       "read chip ID 0x%x is not equal to 0x%x!\n", client_id,
+                       MMA8450_ID);
+               err = -EINVAL;
+               goto err_out;
+       }
 
        m = kzalloc(sizeof(struct mma8450), GFP_KERNEL);
        idev = input_allocate_polled_device();
@@ -211,6 +231,7 @@ static int mma8450_probe(struct i2c_client *c,
 err_free_mem:
        input_free_polled_device(idev);
        kfree(m);
+err_out:
        return err;
 }