From 04ec0383183390e09f033337779c56f0742cca2b Mon Sep 17 00:00:00 2001 From: Luwei Zhou Date: Tue, 3 Sep 2013 17:32:55 +0800 Subject: [PATCH] ENGR00277864 input: mma8450: Add chip id check in probe 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 (cherry picked from commit e9f2c4cf673dee1527925f30a9f3fd137d9799ad) --- drivers/input/misc/mma8450.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c index 59d4dcddf6de..7744d23cc584 100644 --- a/drivers/input/misc/mma8450.c +++ b/drivers/input/misc/mma8450.c @@ -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; } -- 2.39.5