Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e952799 authored by Jean Delvare's avatar Jean Delvare Committed by Mark M. Hoffman
Browse files

hwmon: (adm1025) Various cleanups



* Whitespace cleanups
* Constify scaling constants
* Fold long lines
* Drop redundant initializations to 0
* Rename new_client to just client
* Use sysfs_create_group()
* Drop a useless comment

Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent bb081300
Loading
Loading
Loading
Loading
+36 −44
Original line number Original line Diff line number Diff line
@@ -93,7 +93,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
 * The ADM1025 uses signed 8-bit values for temperatures.
 * 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_FROM_REG(reg,scale)	(((reg) * (scale) + 96) / 192)
#define IN_TO_REG(val,scale)	((val) <= 0 ? 0 : \
#define IN_TO_REG(val,scale)	((val) <= 0 ? 0 : \
@@ -293,7 +293,8 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
set_temp(1);
set_temp(1);
set_temp(2);
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);
	struct adm1025_data *data = adm1025_update_device(dev);
	return sprintf(buf, "%u\n", data->alarms);
	return sprintf(buf, "%u\n", data->alarms);
@@ -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(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
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);
	struct adm1025_data *data = adm1025_update_device(dev);
	return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
	return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
}
}
static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
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);
	struct adm1025_data *data = dev_get_drvdata(dev);
	return sprintf(buf, "%u\n", data->vrm);
	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 i2c_client *client = to_i2c_client(dev);
	struct adm1025_data *data = i2c_get_clientdata(client);
	struct adm1025_data *data = i2c_get_clientdata(client);
@@ -389,7 +393,7 @@ static const struct attribute_group adm1025_group = {
	.attrs = adm1025_attributes,
	.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_input.dev_attr.attr,
	&sensor_dev_attr_in4_min.dev_attr.attr,
	&sensor_dev_attr_in4_min.dev_attr.attr,
	&sensor_dev_attr_in4_max.dev_attr.attr,
	&sensor_dev_attr_in4_max.dev_attr.attr,
@@ -397,8 +401,8 @@ static struct attribute *adm1025_attributes_opt[] = {
	NULL
	NULL
};
};


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


/*
/*
@@ -407,7 +411,7 @@ static const struct attribute_group adm1025_group_opt = {
 */
 */
static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
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;
	struct adm1025_data *data;
	int err = 0;
	int err = 0;
	const char *name = "";
	const char *name = "";
@@ -421,14 +425,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
		goto exit;
		goto exit;
	}
	}


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


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


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


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


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


	/* Tell the I2C layer a new client has arrived */
	/* 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;
		goto exit_free;


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


	/* Register sysfs hooks */
	/* 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;
		goto exit_detach;


	/* Pin 11 is either in4 (+12V) or VID4 */
	/* Pin 11 is either in4 (+12V) or VID4 */
	if (!(config & 0x20)) {
	if (!(config & 0x20)) {
		if ((err = device_create_file(&new_client->dev,
		if ((err = sysfs_create_group(&client->dev.kobj,
					&sensor_dev_attr_in4_input.dev_attr))
					      &adm1025_group_in4)))
		 || (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)))
			goto exit_remove;
			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)) {
	if (IS_ERR(data->hwmon_dev)) {
		err = PTR_ERR(data->hwmon_dev);
		err = PTR_ERR(data->hwmon_dev);
		goto exit_remove;
		goto exit_remove;
@@ -526,10 +518,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
	return 0;
	return 0;


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


	hwmon_device_unregister(data->hwmon_dev);
	hwmon_device_unregister(data->hwmon_dev);
	sysfs_remove_group(&client->dev.kobj, &adm1025_group);
	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)))
	if ((err = i2c_detach_client(client)))
		return err;
		return err;