Skip to content

Commit 1863f21

Browse files
Luwei Zhoudtor
authored andcommitted
Input: mma8450 - add chip ID check in probe
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 <[email protected]> Signed-off-by: Fugang Duan <[email protected]> Signed-off-by: Vipul Kumar <[email protected]> Signed-off-by: Dong Aisheng <[email protected]> Signed-off-by: Frank Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 55b7530 commit 1863f21

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

drivers/input/misc/mma8450.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#define MMA8450_CTRL_REG1 0x38
4040
#define MMA8450_CTRL_REG2 0x39
41+
#define MMA8450_ID 0xc6
42+
#define MMA8450_WHO_AM_I 0x0f
4143

4244
static int mma8450_read(struct i2c_client *c, unsigned int off)
4345
{
@@ -148,8 +150,20 @@ static void mma8450_close(struct input_dev *input)
148150
*/
149151
static int mma8450_probe(struct i2c_client *c)
150152
{
153+
struct i2c_adapter *adapter = c->adapter;
151154
struct input_dev *input;
152-
int err;
155+
int err, client_id;
156+
157+
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE |
158+
I2C_FUNC_SMBUS_BYTE_DATA))
159+
return dev_err_probe(&c->dev, -EINVAL,
160+
"I2C adapter doesn't support SMBUS BYTE");
161+
162+
client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
163+
if (client_id != MMA8450_ID)
164+
return dev_err_probe(&c->dev, -EINVAL,
165+
"unexpected chip ID 0x%x (vs 0x%x)\n",
166+
client_id, MMA8450_ID);
153167

154168
input = devm_input_allocate_device(&c->dev);
155169
if (!input)

0 commit comments

Comments
 (0)