MLK-11467 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@nxp.com>
Mon, 19 Mar 2018 19:48:18 +0000 (14:48 -0500)
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>
Signed-off-by: Fugang Duan <B38611@freescale.com>
(cherry picked from commit e9f2c4cf673dee1527925f30a9f3fd137d9799ad)

drivers/input/misc/mma8450.c

index 19c7357..a0cb7fb 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-2015 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,24 @@ 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)
+               return err;
+
+       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);
+               return -EINVAL;
+       }
 
        m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL);
        if (!m)