diff options
author | Luwei Zhou <b45643@freescale.com> | 2013-09-03 17:32:55 +0800 |
---|---|---|
committer | Luwei Zhou <b45643@freescale.com> | 2013-09-06 17:05:50 +0800 |
commit | afade76618b6c362f1d09cde579c7afc49f1d76a (patch) | |
tree | 5339e283460265add67a09f613bdce9e03ab6e5d /drivers | |
parent | 1a1037a552bbbd244de67a99a9c112af973ef4be (diff) |
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 <b45643@freescale.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/misc/mma8450.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c index f3309696d053..9d3868211fc2 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-2013 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(); @@ -209,6 +229,7 @@ static int mma8450_probe(struct i2c_client *c, err_free_mem: input_free_polled_device(idev); kfree(m); +err_out: return err; } |