Commit 9d5ad0c3 authored by Peter Meerwald's avatar Peter Meerwald Committed by Jonathan Cameron
Browse files

staging:iio:hmc5843: Check initialization and chip identifier


Signed-off-by: default avatarPeter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent f3f75519
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment