Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 95724
b: refs/heads/master
c: 1852448
h: refs/heads/master
v: v3
  • Loading branch information
Mark M. Hoffman committed Apr 27, 2008
1 parent baadd37 commit a65fd6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5d822e9bd9d866672984c6a6b613f0c11ca2543b
refs/heads/master: 1852448652fd526d56099256dadc4ef32cb1b10e
45 changes: 23 additions & 22 deletions trunk/drivers/hwmon/adt7473.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,18 +422,14 @@ static ssize_t show_volt(struct device *dev, struct device_attribute *devattr,
* number in the range -128 to 127, or as an unsigned number that must
* be offset by 64.
*/
static int decode_temp(struct adt7473_data *data, u8 raw)
static int decode_temp(u8 twos_complement, u8 raw)
{
if (data->temp_twos_complement)
return (s8)raw;
return raw - 64;
return twos_complement ? (s8)raw : raw - 64;
}

static u8 encode_temp(struct adt7473_data *data, int cooked)
static u8 encode_temp(u8 twos_complement, int cooked)
{
if (data->temp_twos_complement)
return (cooked & 0xFF);
return cooked + 64;
return twos_complement ? cooked & 0xFF : cooked + 64;
}

static ssize_t show_temp_min(struct device *dev,
Expand All @@ -442,8 +438,9 @@ static ssize_t show_temp_min(struct device *dev,
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adt7473_data *data = adt7473_update_device(dev);
return sprintf(buf, "%d\n",
1000 * decode_temp(data, data->temp_min[attr->index]));
return sprintf(buf, "%d\n", 1000 * decode_temp(
data->temp_twos_complement,
data->temp_min[attr->index]));
}

static ssize_t set_temp_min(struct device *dev,
Expand All @@ -455,7 +452,7 @@ static ssize_t set_temp_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7473_data *data = i2c_get_clientdata(client);
int temp = simple_strtol(buf, NULL, 10) / 1000;
temp = encode_temp(data, temp);
temp = encode_temp(data->temp_twos_complement, temp);

mutex_lock(&data->lock);
data->temp_min[attr->index] = temp;
Expand All @@ -472,8 +469,9 @@ static ssize_t show_temp_max(struct device *dev,
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adt7473_data *data = adt7473_update_device(dev);
return sprintf(buf, "%d\n",
1000 * decode_temp(data, data->temp_max[attr->index]));
return sprintf(buf, "%d\n", 1000 * decode_temp(
data->temp_twos_complement,
data->temp_max[attr->index]));
}

static ssize_t set_temp_max(struct device *dev,
Expand All @@ -485,7 +483,7 @@ static ssize_t set_temp_max(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7473_data *data = i2c_get_clientdata(client);
int temp = simple_strtol(buf, NULL, 10) / 1000;
temp = encode_temp(data, temp);
temp = encode_temp(data->temp_twos_complement, temp);

mutex_lock(&data->lock);
data->temp_max[attr->index] = temp;
Expand All @@ -501,8 +499,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adt7473_data *data = adt7473_update_device(dev);
return sprintf(buf, "%d\n",
1000 * decode_temp(data, data->temp[attr->index]));
return sprintf(buf, "%d\n", 1000 * decode_temp(
data->temp_twos_complement,
data->temp[attr->index]));
}

static ssize_t show_fan_min(struct device *dev,
Expand Down Expand Up @@ -671,8 +670,9 @@ static ssize_t show_temp_tmax(struct device *dev,
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adt7473_data *data = adt7473_update_device(dev);
return sprintf(buf, "%d\n",
1000 * decode_temp(data, data->temp_tmax[attr->index]));
return sprintf(buf, "%d\n", 1000 * decode_temp(
data->temp_twos_complement,
data->temp_tmax[attr->index]));
}

static ssize_t set_temp_tmax(struct device *dev,
Expand All @@ -684,7 +684,7 @@ static ssize_t set_temp_tmax(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7473_data *data = i2c_get_clientdata(client);
int temp = simple_strtol(buf, NULL, 10) / 1000;
temp = encode_temp(data, temp);
temp = encode_temp(data->temp_twos_complement, temp);

mutex_lock(&data->lock);
data->temp_tmax[attr->index] = temp;
Expand All @@ -701,8 +701,9 @@ static ssize_t show_temp_tmin(struct device *dev,
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adt7473_data *data = adt7473_update_device(dev);
return sprintf(buf, "%d\n",
1000 * decode_temp(data, data->temp_tmin[attr->index]));
return sprintf(buf, "%d\n", 1000 * decode_temp(
data->temp_twos_complement,
data->temp_tmin[attr->index]));
}

static ssize_t set_temp_tmin(struct device *dev,
Expand All @@ -714,7 +715,7 @@ static ssize_t set_temp_tmin(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7473_data *data = i2c_get_clientdata(client);
int temp = simple_strtol(buf, NULL, 10) / 1000;
temp = encode_temp(data, temp);
temp = encode_temp(data->temp_twos_complement, temp);

mutex_lock(&data->lock);
data->temp_tmin[attr->index] = temp;
Expand Down

0 comments on commit a65fd6e

Please sign in to comment.