linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: mma8450: Add chip id check in probe
@ 2022-02-22  4:35 haibo.chen
  0 siblings, 0 replies; only message in thread
From: haibo.chen @ 2022-02-22  4:35 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: haibo.chen, linux-imx, linux-input

From: Haibo Chen <haibo.chen@nxp.com>

Add chip ID check in probe function. Add this to avoid the
continuously polling error log when this device is not connect
on the i2c bus.

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/input/misc/mma8450.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 1b5a5e19230a..c9f7e2ee7c91 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -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)
 {
@@ -150,7 +152,23 @@ static int mma8450_probe(struct i2c_client *c,
 			 const struct i2c_device_id *id)
 {
 	struct input_dev *input;
-	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;
+	}
 
 	input = devm_input_allocate_device(&c->dev);
 	if (!input)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-22  6:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-22  4:35 [PATCH] input: mma8450: Add chip id check in probe haibo.chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).