Commit 88fa4de4 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:magnetometer:hmc5843: allocate device state with iio_dev.

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent afc2ff0a
...@@ -131,7 +131,6 @@ static const unsigned short normal_i2c[] = { HMC5843_I2C_ADDRESS, ...@@ -131,7 +131,6 @@ static const unsigned short normal_i2c[] = { HMC5843_I2C_ADDRESS,
/* Each client has this additional data */ /* Each client has this additional data */
struct hmc5843_data { struct hmc5843_data {
struct iio_dev *indio_dev;
struct mutex lock; struct mutex lock;
u8 rate; u8 rate;
u8 meas_conf; u8 meas_conf;
...@@ -159,7 +158,7 @@ static ssize_t hmc5843_read_measurement(struct device *dev, ...@@ -159,7 +158,7 @@ static ssize_t hmc5843_read_measurement(struct device *dev,
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
s16 coordinate_val; s16 coordinate_val;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
s32 result; s32 result;
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -202,7 +201,7 @@ static ssize_t hmc5843_show_operating_mode(struct device *dev, ...@@ -202,7 +201,7 @@ static ssize_t hmc5843_show_operating_mode(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
return sprintf(buf, "%d\n", data->operating_mode); return sprintf(buf, "%d\n", data->operating_mode);
} }
...@@ -213,7 +212,7 @@ static ssize_t hmc5843_set_operating_mode(struct device *dev, ...@@ -213,7 +212,7 @@ static ssize_t hmc5843_set_operating_mode(struct device *dev,
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
unsigned long operating_mode = 0; unsigned long operating_mode = 0;
s32 status; s32 status;
...@@ -278,7 +277,7 @@ static ssize_t hmc5843_show_measurement_configuration(struct device *dev, ...@@ -278,7 +277,7 @@ static ssize_t hmc5843_show_measurement_configuration(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
return sprintf(buf, "%d\n", data->meas_conf); return sprintf(buf, "%d\n", data->meas_conf);
} }
...@@ -350,7 +349,7 @@ static ssize_t set_sampling_frequency(struct device *dev, ...@@ -350,7 +349,7 @@ static ssize_t set_sampling_frequency(struct device *dev,
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
unsigned long rate = 0; unsigned long rate = 0;
if (strncmp(buf, "0.5" , 3) == 0) if (strncmp(buf, "0.5" , 3) == 0)
...@@ -422,7 +421,7 @@ static ssize_t show_range(struct device *dev, ...@@ -422,7 +421,7 @@ static ssize_t show_range(struct device *dev,
{ {
u8 range; u8 range;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
range = data->range; range = data->range;
return sprintf(buf, "%d\n", regval_to_input_field_mg[range]); return sprintf(buf, "%d\n", regval_to_input_field_mg[range]);
...@@ -436,7 +435,7 @@ static ssize_t set_range(struct device *dev, ...@@ -436,7 +435,7 @@ static ssize_t set_range(struct device *dev,
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
unsigned long range = 0; unsigned long range = 0;
int error; int error;
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -473,7 +472,7 @@ static ssize_t show_scale(struct device *dev, ...@@ -473,7 +472,7 @@ static ssize_t show_scale(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct hmc5843_data *data = indio_dev->dev_data; struct hmc5843_data *data = iio_priv(indio_dev);
return strlen(strcpy(buf, regval_to_scale[data->range])); return strlen(strcpy(buf, regval_to_scale[data->range]));
} }
static IIO_DEVICE_ATTR(magn_scale, static IIO_DEVICE_ATTR(magn_scale,
...@@ -538,53 +537,46 @@ static int hmc5843_probe(struct i2c_client *client, ...@@ -538,53 +537,46 @@ static int hmc5843_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct hmc5843_data *data; struct hmc5843_data *data;
struct iio_dev *indio_dev;
int err = 0; int err = 0;
data = kzalloc(sizeof(struct hmc5843_data), GFP_KERNEL); indio_dev = iio_allocate_device(sizeof(*data));
if (!data) { if (indio_dev == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
data = iio_priv(indio_dev);
/* default settings at probe */ /* default settings at probe */
data->meas_conf = CONF_NORMAL; data->meas_conf = CONF_NORMAL;
data->range = RANGE_1_0; data->range = RANGE_1_0;
data->operating_mode = MODE_CONVERSION_CONTINUOUS; data->operating_mode = MODE_CONVERSION_CONTINUOUS;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, indio_dev);
/* Initialize the HMC5843 chip */ /* Initialize the HMC5843 chip */
hmc5843_init_client(client); hmc5843_init_client(client);
data->indio_dev = iio_allocate_device(0); indio_dev->info = &hmc5843_info;
if (!data->indio_dev) { indio_dev->dev.parent = &client->dev;
err = -ENOMEM; indio_dev->modes = INDIO_DIRECT_MODE;
goto exit_free1; err = iio_device_register(indio_dev);
}
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) if (err)
goto exit_free2; goto exit_free2;
return 0; return 0;
exit_free2: exit_free2:
iio_free_device(data->indio_dev); iio_free_device(indio_dev);
exit_free1:
kfree(data);
exit: exit:
return err; return err;
} }
static int hmc5843_remove(struct i2c_client *client) static int hmc5843_remove(struct i2c_client *client)
{ {
struct hmc5843_data *data = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
/* sleep mode to save power */ /* sleep mode to save power */
hmc5843_configure(client, MODE_SLEEP); hmc5843_configure(client, MODE_SLEEP);
iio_device_unregister(data->indio_dev); iio_device_unregister(indio_dev);
kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
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