Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 84503
b: refs/heads/master
c: 4e95279
h: refs/heads/master
i:
  84501: 84686b7
  84499: a478d32
  84495: 31575a3
v: v3
  • Loading branch information
Jean Delvare authored and Mark M. Hoffman committed Feb 8, 2008
1 parent 3017c3e commit a5de1fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 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: bb081300326335594c273107fcd4e5bdad765ae7
refs/heads/master: 4e9527998f8673b1e3bb6f9645b9700e7973581e
80 changes: 36 additions & 44 deletions trunk/drivers/hwmon/adm1025.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
*/

#define ADM1025_REG_MAN_ID 0x3E
#define ADM1025_REG_CHIP_ID 0x3F
#define ADM1025_REG_CHIP_ID 0x3F
#define ADM1025_REG_CONFIG 0x40
#define ADM1025_REG_STATUS1 0x41
#define ADM1025_REG_STATUS2 0x42
Expand All @@ -93,7 +93,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
* The ADM1025 uses signed 8-bit values for temperatures.
*/

static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };

#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
Expand Down Expand Up @@ -293,7 +293,8 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
set_temp(1);
set_temp(2);

static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t
show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
{
struct adm1025_data *data = adm1025_update_device(dev);
return sprintf(buf, "%u\n", data->alarms);
Expand All @@ -317,19 +318,22 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);

static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t
show_vid(struct device *dev, struct device_attribute *attr, char *buf)
{
struct adm1025_data *data = adm1025_update_device(dev);
return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
}
static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);

static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t
show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
{
struct adm1025_data *data = dev_get_drvdata(dev);
return sprintf(buf, "%u\n", data->vrm);
}
static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1025_data *data = i2c_get_clientdata(client);
Expand Down Expand Up @@ -389,16 +393,16 @@ static const struct attribute_group adm1025_group = {
.attrs = adm1025_attributes,
};

static struct attribute *adm1025_attributes_opt[] = {
static struct attribute *adm1025_attributes_in4[] = {
&sensor_dev_attr_in4_input.dev_attr.attr,
&sensor_dev_attr_in4_min.dev_attr.attr,
&sensor_dev_attr_in4_max.dev_attr.attr,
&sensor_dev_attr_in4_alarm.dev_attr.attr,
NULL
};

static const struct attribute_group adm1025_group_opt = {
.attrs = adm1025_attributes_opt,
static const struct attribute_group adm1025_group_in4 = {
.attrs = adm1025_attributes_in4,
};

/*
Expand All @@ -407,7 +411,7 @@ static const struct attribute_group adm1025_group_opt = {
*/
static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
{
struct i2c_client *new_client;
struct i2c_client *client;
struct adm1025_data *data;
int err = 0;
const char *name = "";
Expand All @@ -421,14 +425,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
goto exit;
}

/* The common I2C client data is placed right before the
ADM1025-specific data. */
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1025_driver;
new_client->flags = 0;
client = &data->client;
i2c_set_clientdata(client, data);
client->addr = address;
client->adapter = adapter;
client->driver = &adm1025_driver;

/*
* Now we do the remaining detection. A negative kind means that
Expand All @@ -440,12 +441,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
* requested, so both the detection and the identification steps
* are skipped.
*/
config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG);
config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
if (kind < 0) { /* detection */
if ((config & 0x80) != 0x00
|| (i2c_smbus_read_byte_data(new_client,
|| (i2c_smbus_read_byte_data(client,
ADM1025_REG_STATUS1) & 0xC0) != 0x00
|| (i2c_smbus_read_byte_data(new_client,
|| (i2c_smbus_read_byte_data(client,
ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
dev_dbg(&adapter->dev,
"ADM1025 detection failed at 0x%02x.\n",
Expand All @@ -457,11 +458,9 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
if (kind <= 0) { /* identification */
u8 man_id, chip_id;

man_id = i2c_smbus_read_byte_data(new_client,
ADM1025_REG_MAN_ID);
chip_id = i2c_smbus_read_byte_data(new_client,
ADM1025_REG_CHIP_ID);

man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);

if (man_id == 0x41) { /* Analog Devices */
if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
kind = adm1025;
Expand Down Expand Up @@ -489,35 +488,28 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
}

/* We can fill in the remaining client fields */
strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0;
strlcpy(client->name, name, I2C_NAME_SIZE);
mutex_init(&data->update_lock);

/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
if ((err = i2c_attach_client(client)))
goto exit_free;

/* Initialize the ADM1025 chip */
adm1025_init_client(new_client);
adm1025_init_client(client);

/* Register sysfs hooks */
if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group)))
if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group)))
goto exit_detach;

/* Pin 11 is either in4 (+12V) or VID4 */
if (!(config & 0x20)) {
if ((err = device_create_file(&new_client->dev,
&sensor_dev_attr_in4_input.dev_attr))
|| (err = device_create_file(&new_client->dev,
&sensor_dev_attr_in4_min.dev_attr))
|| (err = device_create_file(&new_client->dev,
&sensor_dev_attr_in4_max.dev_attr))
|| (err = device_create_file(&new_client->dev,
&sensor_dev_attr_in4_alarm.dev_attr)))
if ((err = sysfs_create_group(&client->dev.kobj,
&adm1025_group_in4)))
goto exit_remove;
}

data->hwmon_dev = hwmon_device_register(&new_client->dev);
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
goto exit_remove;
Expand All @@ -526,10 +518,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
return 0;

exit_remove:
sysfs_remove_group(&new_client->dev.kobj, &adm1025_group);
sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt);
sysfs_remove_group(&client->dev.kobj, &adm1025_group);
sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
exit_detach:
i2c_detach_client(new_client);
i2c_detach_client(client);
exit_free:
kfree(data);
exit:
Expand Down Expand Up @@ -585,7 +577,7 @@ static int adm1025_detach_client(struct i2c_client *client)

hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &adm1025_group);
sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt);
sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);

if ((err = i2c_detach_client(client)))
return err;
Expand Down

0 comments on commit a5de1fd

Please sign in to comment.