summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Meerwald <pmeerw@pmeerw.net>2013-10-16 22:19:00 (GMT)
committerJonathan Cameron <jic23@kernel.org>2013-10-17 22:52:16 (GMT)
commit9d5ad0c3e7b853544476f3fbe264515aae0f6106 (patch)
tree2cbfa77f7a6067ea7b9f222b35c88c78bf131a86
parentf3f755197b0436f212d11c5bb960e8ff3a784747 (diff)
downloadlinux-fsl-qoriq-9d5ad0c3e7b853544476f3fbe264515aae0f6106.tar.xz
staging:iio:hmc5843: Check initialization and chip identifier
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/staging/iio/magnetometer/hmc5843.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c
index c819b8e..7e688dd 100644
--- a/drivers/staging/iio/magnetometer/hmc5843.c
+++ b/drivers/staging/iio/magnetometer/hmc5843.c
@@ -33,6 +33,7 @@
#define HMC5843_MODE_REG 0x02
#define HMC5843_DATA_OUT_MSB_REGS 0x03
#define HMC5843_STATUS_REG 0x09
+#define HMC5843_ID_REG 0x0a
enum hmc5843_ids {
HMC5843_ID,
@@ -497,12 +498,30 @@ static const struct hmc5843_chip_info hmc5843_chip_info_tbl[] = {
},
};
-static void hmc5843_init(struct hmc5843_data *data)
+static int hmc5843_init(struct hmc5843_data *data)
{
- hmc5843_set_meas_conf(data, HMC5843_MEAS_CONF_NORMAL);
- hmc5843_set_samp_freq(data, HMC5843_RATE_DEFAULT);
- hmc5843_set_range_gain(data, HMC5843_RANGE_GAIN_DEFAULT);
- hmc5843_set_mode(data, HMC5843_MODE_CONVERSION_CONTINUOUS);
+ int ret;
+ u8 id[3];
+
+ ret = i2c_smbus_read_i2c_block_data(data->client, HMC5843_ID_REG,
+ sizeof(id), id);
+ if (ret < 0)
+ return ret;
+ if (id[0] != 'H' || id[1] != '4' || id[2] != '3') {
+ dev_err(&data->client->dev, "no HMC5843/5883/5883L sensor\n");
+ return -ENODEV;
+ }
+
+ ret = hmc5843_set_meas_conf(data, HMC5843_MEAS_CONF_NORMAL);
+ if (ret < 0)
+ return ret;
+ ret = hmc5843_set_samp_freq(data, HMC5843_RATE_DEFAULT);
+ if (ret < 0)
+ return ret;
+ ret = hmc5843_set_range_gain(data, HMC5843_RANGE_GAIN_DEFAULT);
+ if (ret < 0)
+ return ret;
+ return hmc5843_set_mode(data, HMC5843_MODE_CONVERSION_CONTINUOUS);
}
static const struct iio_info hmc5843_info = {
@@ -541,7 +560,9 @@ static int hmc5843_probe(struct i2c_client *client,
indio_dev->num_channels = 4;
indio_dev->available_scan_masks = hmc5843_scan_masks;
- hmc5843_init(data);
+ ret = hmc5843_init(data);
+ if (ret < 0)
+ return ret;
ret = iio_triggered_buffer_setup(indio_dev, NULL,
hmc5843_trigger_handler, NULL);