]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: mma8450 - add chip ID check in probe
authorLuwei Zhou <b45643@freescale.com>
Mon, 16 Dec 2024 18:28:51 +0000 (10:28 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 17 Dec 2024 19:11:46 +0000 (11:11 -0800)
Prevent continuous polling error logs by adding a chip ID check in the
probe  function. This ensures the driver only proceeds when the mma8450 is
present, avoiding issues in scenarios like missing add-on cards.

Signed-off-by: Luwei Zhou <b45643@freescale.com>
Signed-off-by: Fugang Duan <B38611@freescale.com>
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20241216173205.211058-1-Frank.Li@nxp.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/mma8450.c

index 08412239b8e693e8fbe36f3c4b57a5f3f652073d..0c661140fb88d9892a0dd54116b269eb1af2f3cf 100644 (file)
@@ -38,6 +38,8 @@
 
 #define MMA8450_CTRL_REG1      0x38
 #define MMA8450_CTRL_REG2      0x39
+#define MMA8450_ID             0xc6
+#define MMA8450_WHO_AM_I       0x0f
 
 static int mma8450_read(struct i2c_client *c, unsigned int off)
 {
@@ -148,8 +150,20 @@ static void mma8450_close(struct input_dev *input)
  */
 static int mma8450_probe(struct i2c_client *c)
 {
+       struct i2c_adapter *adapter = c->adapter;
        struct input_dev *input;
-       int err;
+       int err, client_id;
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE |
+                                               I2C_FUNC_SMBUS_BYTE_DATA))
+               return dev_err_probe(&c->dev, -EINVAL,
+                                    "I2C adapter doesn't support SMBUS BYTE");
+
+       client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
+       if (client_id != MMA8450_ID)
+               return dev_err_probe(&c->dev, -EINVAL,
+                                    "unexpected chip ID 0x%x (vs 0x%x)\n",
+                                    client_id, MMA8450_ID);
 
        input = devm_input_allocate_device(&c->dev);
        if (!input)