Esempio n. 1
0
static int hmc5843_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
{
	struct hmc5843_data *data;
	int err = 0;

	data = kzalloc(sizeof(struct hmc5843_data), GFP_KERNEL);
	if (!data) {
		err = -ENOMEM;
		goto exit;
	}

	/* default settings at probe */

	data->meas_conf = CONF_NORMAL;
	data->range = RANGE_1_0;
	data->operating_mode = MODE_CONVERSION_CONTINUOUS;

	i2c_set_clientdata(client, data);

	/* Initialize the HMC5843 chip */
	hmc5843_init_client(client);

	data->indio_dev = iio_allocate_device(0);
	if (!data->indio_dev) {
		err = -ENOMEM;
		goto exit_free1;
	}
	data->indio_dev->info = &hmc5843_info;
	data->indio_dev->dev.parent = &client->dev;
	data->indio_dev->dev_data = (void *)(data);
	data->indio_dev->modes = INDIO_DIRECT_MODE;
	err = iio_device_register(data->indio_dev);
	if (err)
		goto exit_free2;
	return 0;
exit_free2:
	iio_free_device(data->indio_dev);
exit_free1:
	kfree(data);
exit:
	return err;
}
Esempio n. 2
0
static int hmc5843_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
{
	struct hmc5843_data *data;
	struct iio_dev *indio_dev;
	int err = 0;

	indio_dev = iio_allocate_device(sizeof(*data));
	if (indio_dev == NULL) {
		err = -ENOMEM;
		goto exit;
	}
	data = iio_priv(indio_dev);
	/* default settings at probe */

	data->meas_conf = CONF_NORMAL;
	data->range = RANGE_1_0;
	data->operating_mode = MODE_CONVERSION_CONTINUOUS;

	i2c_set_clientdata(client, indio_dev);

	/* Initialize the HMC5843 chip */
	hmc5843_init_client(client);

	indio_dev->info = &hmc5843_info;
	indio_dev->name = id->name;
	indio_dev->channels = hmc5843_channels;
	indio_dev->num_channels = ARRAY_SIZE(hmc5843_channels);
	indio_dev->dev.parent = &client->dev;
	indio_dev->modes = INDIO_DIRECT_MODE;
	err = iio_device_register(indio_dev);
	if (err)
		goto exit_free2;
	return 0;
exit_free2:
	iio_free_device(indio_dev);
exit:
	return err;
}
Esempio n. 3
0
static int hmc5843_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
{
	struct hmc5843_data *data;
	struct iio_dev *indio_dev;
	int err = 0;

	indio_dev = iio_device_alloc(sizeof(*data));
	if (indio_dev == NULL) {
		err = -ENOMEM;
		goto exit;
	}

	/* default settings at probe */
	data = iio_priv(indio_dev);
	data->meas_conf = HMC5843_MEAS_CONF_NORMAL;
	data->range = HMC5843_RANGE_GAIN_DEFAULT;
	data->operating_mode = HMC5843_MODE_CONVERSION_CONTINUOUS;

	i2c_set_clientdata(client, indio_dev);
	hmc5843_init_client(client, id);

	indio_dev->info = &hmc5843_info;
	indio_dev->name = id->name;
	indio_dev->dev.parent = &client->dev;
	indio_dev->modes = INDIO_DIRECT_MODE;

	err = iio_device_register(indio_dev);
	if (err)
		goto exit_free2;

	return 0;

exit_free2:
	iio_device_free(indio_dev);
exit:
	return err;
}