Source
x
static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
// SPDX-License-Identifier: GPL-2.0-only
/*
* An hwmon driver for the Analog Devices AD7416/17/18
* Copyright (C) 2006-07 Tower Technologies
*
* Author: Alessandro Zummo <a.zummo@towertech.it>
*
* Based on lm75.c
* Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl>
*/
enum chips { ad7416, ad7417, ad7418 };
/* AD7418 registers */
static const u8 AD7418_REG_TEMP[] = { AD7418_REG_TEMP_IN,
AD7418_REG_TEMP_HYST,
AD7418_REG_TEMP_OS };
struct ad7418_data {
struct i2c_client *client;
enum chips type;
struct mutex lock;
int adc_max; /* number of ADC channels */
char valid;
unsigned long last_updated; /* In jiffies */
s16 temp[3]; /* Register values */
u16 in[4];
};
static int ad7418_update_device(struct device *dev)
{
struct ad7418_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
s32 val;
mutex_lock(&data->lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) {
u8 cfg;
int i, ch;
/* read config register and clear channel bits */
val = i2c_smbus_read_byte_data(client, AD7418_REG_CONF);
if (val < 0)
goto abort;
cfg = val;
cfg &= 0x1F;
val = i2c_smbus_write_byte_data(client, AD7418_REG_CONF,
cfg | AD7418_CH_TEMP);
if (val < 0)
goto abort;
udelay(30);
for (i = 0; i < 3; i++) {
val = i2c_smbus_read_word_swapped(client,
AD7418_REG_TEMP[i]);
if (val < 0)
goto abort;
data->temp[i] = val;
}
for (i = 0, ch = 4; i < data->adc_max; i++, ch--) {