struct adt75_chip_info {
struct i2c_client *client;
- struct iio_dev *indio_dev;
u8 config;
};
* adt75 register access by I2C
*/
-static int adt75_i2c_read(struct adt75_chip_info *chip, u8 reg, u8 *data)
+static int adt75_i2c_read(struct iio_dev *dev_info, u8 reg, u8 *data)
{
+ struct adt75_chip_info *chip = iio_priv(dev_info);
struct i2c_client *client = chip->client;
int ret = 0, len;
return ret;
}
-static int adt75_i2c_write(struct adt75_chip_info *chip, u8 reg, u8 data)
+static int adt75_i2c_write(struct iio_dev *dev_info, u8 reg, u8 data)
{
+ struct adt75_chip_info *chip = iio_priv(dev_info);
struct i2c_client *client = chip->client;
int ret = 0;
struct device_attribute *attr,
char *buf)
{
- struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_get_drvdata(dev));
if (chip->config & ADT75_PD)
return sprintf(buf, "power-save\n");
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
int ret;
u8 config;
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
if (!strcmp(buf, "full"))
config |= ADT75_PD;
- ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
+ ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config);
if (ret)
return -EIO;
struct device_attribute *attr,
char *buf)
{
- struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_get_drvdata(dev));
return sprintf(buf, "%d\n", !!(chip->config & ADT75_ONESHOT));
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
unsigned long data = 0;
int ret;
u8 config;
return -EINVAL;
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
if (data)
config |= ADT75_ONESHOT;
- ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
+ ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config);
if (ret)
return -EIO;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
u16 data;
char sign = ' ';
int ret;
return -EIO;
}
- ret = adt75_i2c_read(chip, ADT75_TEMPERATURE, (u8 *)&data);
+ ret = adt75_i2c_read(dev_info, ADT75_TEMPERATURE, (u8 *)&data);
if (ret)
return -EIO;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
int ret;
/* retrive ALART status */
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
int ret;
u8 config;
/* retrive ALART status */
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
if (strcmp(buf, "comparator") != 0)
config |= ADT75_OS_INT;
- ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
+ ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config);
if (ret)
return -EIO;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
int ret;
/* retrive ALART status */
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
unsigned long data = 0;
int ret;
u8 config;
return -EINVAL;
/* retrive ALART status */
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
if (data)
config |= ADT75_SMBUS_ALART;
- ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
+ ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config);
if (ret)
return -EIO;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
int ret;
/* retrive ALART status */
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
+ struct adt75_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
u8 config;
return -EINVAL;
/* retrive ALART status */
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config);
if (ret)
return -EIO;
config = chip->config & ~ADT75_FAULT_QUEUE_MASK;
config |= (data << ADT75_FAULT_QUEUE_OFFSET);
- ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
+ ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config);
if (ret)
return -EIO;
{
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
u16 data;
char sign = ' ';
int ret;
- ret = adt75_i2c_read(chip, this_attr->address, (u8 *)&data);
+ ret = adt75_i2c_read(dev_info, this_attr->address, (u8 *)&data);
if (ret)
return -EIO;
{
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct adt75_chip_info *chip = dev_info->dev_data;
long tmp1, tmp2;
u16 data;
char *pos;
data <<= ADT75_VALUE_OFFSET;
data = swab16(data);
- ret = adt75_i2c_write(chip, this_attr->address, (u8)data);
+ ret = adt75_i2c_write(dev_info, this_attr->address, (u8)data);
if (ret)
return -EIO;
const struct i2c_device_id *id)
{
struct adt75_chip_info *chip;
+ struct iio_dev *indio_dev;
int ret = 0;
- chip = kzalloc(sizeof(struct adt75_chip_info), GFP_KERNEL);
-
- if (chip == NULL)
- return -ENOMEM;
+ indio_dev = iio_allocate_device(sizeof(*chip));
+ if (indio_dev == NULL) {
+ ret = -ENOMEM;
+ goto error_ret;
+ }
+ chip = iio_priv(indio_dev);
/* this is only used for device removal purposes */
- i2c_set_clientdata(client, chip);
+ i2c_set_clientdata(client, indio_dev);
chip->client = client;
- chip->indio_dev = iio_allocate_device(0);
- if (chip->indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_free_chip;
- }
-
- chip->indio_dev->name = id->name;
- chip->indio_dev->dev.parent = &client->dev;
- chip->indio_dev->info = &adt75_info;
- chip->indio_dev->dev_data = (void *)chip;
- chip->indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->name = id->name;
+ indio_dev->dev.parent = &client->dev;
+ indio_dev->info = &adt75_info;
+ indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(chip->indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
NULL,
&adt75_event_handler,
IRQF_TRIGGER_LOW,
- chip->indio_dev->name,
- chip->indio_dev);
+ indio_dev->name,
+ indio_dev);
if (ret)
goto error_unreg_dev;
- ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
+ ret = adt75_i2c_read(indio_dev, ADT75_CONFIG, &chip->config);
if (ret) {
ret = -EIO;
goto error_unreg_irq;
/* set irq polarity low level */
chip->config &= ~ADT75_OS_POLARITY;
- ret = adt75_i2c_write(chip, ADT75_CONFIG, chip->config);
+ ret = adt75_i2c_write(indio_dev, ADT75_CONFIG, chip->config);
if (ret) {
ret = -EIO;
goto error_unreg_irq;
}
dev_info(&client->dev, "%s temperature sensor registered.\n",
- chip->indio_dev->name);
+ indio_dev->name);
return 0;
error_unreg_irq:
- free_irq(client->irq, chip->indio_dev);
+ free_irq(client->irq, indio_dev);
error_unreg_dev:
- iio_device_unregister(chip->indio_dev);
+ iio_device_unregister(indio_dev);
error_free_dev:
- iio_free_device(chip->indio_dev);
-error_free_chip:
- kfree(chip);
-
+ iio_free_device(indio_dev);
+error_ret:
return ret;
}
static int __devexit adt75_remove(struct i2c_client *client)
{
- struct adt75_chip_info *chip = i2c_get_clientdata(client);
- struct iio_dev *indio_dev = chip->indio_dev;
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
if (client->irq)
- free_irq(client->irq, chip->indio_dev);
+ free_irq(client->irq, indio_dev);
iio_device_unregister(indio_dev);
- iio_free_device(chip->indio_dev);
- kfree(chip);
+ iio_free_device(indio_dev);
return 0;
}