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

Commit b12e484e authored by Axel Lin's avatar Axel Lin Committed by Guenter Roeck
Browse files

hwmon: (adm1029) Avoid forward declarations



Reorder functions to avoid forward declarations.

Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 337076f9
Loading
Loading
Loading
Loading
+78 −93
Original line number Original line Diff line number Diff line
@@ -105,40 +105,6 @@ static const u8 ADM1029_REG_FAN_DIV[] = {
	ADM1029_REG_FAN2_CONFIG,
	ADM1029_REG_FAN2_CONFIG,
};
};


/*
 * Functions declaration
 */

static int adm1029_probe(struct i2c_client *client,
			 const struct i2c_device_id *id);
static int adm1029_detect(struct i2c_client *client,
			  struct i2c_board_info *info);
static int adm1029_remove(struct i2c_client *client);
static struct adm1029_data *adm1029_update_device(struct device *dev);
static int adm1029_init_client(struct i2c_client *client);

/*
 * Driver data (common to all clients)
 */

static const struct i2c_device_id adm1029_id[] = {
	{ "adm1029", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, adm1029_id);

static struct i2c_driver adm1029_driver = {
	.class		= I2C_CLASS_HWMON,
	.driver = {
		.name = "adm1029",
	},
	.probe		= adm1029_probe,
	.remove		= adm1029_remove,
	.id_table	= adm1029_id,
	.detect		= adm1029_detect,
	.address_list	= normal_i2c,
};

/*
/*
 * Client data (each client gets its own)
 * Client data (each client gets its own)
 */
 */
@@ -155,6 +121,50 @@ struct adm1029_data {
	u8 fan_div[ARRAY_SIZE(ADM1029_REG_FAN_DIV)];
	u8 fan_div[ARRAY_SIZE(ADM1029_REG_FAN_DIV)];
};
};


/*
 * function that update the status of the chips (temperature for example)
 */
static struct adm1029_data *adm1029_update_device(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct adm1029_data *data = i2c_get_clientdata(client);

	mutex_lock(&data->update_lock);
	/*
	 * Use the "cache" Luke, don't recheck values
	 * if there are already checked not a long time later
	 */
	if (time_after(jiffies, data->last_updated + HZ * 2)
	 || !data->valid) {
		int nr;

		dev_dbg(&client->dev, "Updating adm1029 data\n");

		for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_TEMP); nr++) {
			data->temp[nr] =
			    i2c_smbus_read_byte_data(client,
						     ADM1029_REG_TEMP[nr]);
		}
		for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN); nr++) {
			data->fan[nr] =
			    i2c_smbus_read_byte_data(client,
						     ADM1029_REG_FAN[nr]);
		}
		for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) {
			data->fan_div[nr] =
			    i2c_smbus_read_byte_data(client,
						     ADM1029_REG_FAN_DIV[nr]);
		}

		data->last_updated = jiffies;
		data->valid = 1;
	}

	mutex_unlock(&data->update_lock);

	return data;
}

/*
/*
 * Sysfs stuff
 * Sysfs stuff
 */
 */
@@ -340,6 +350,24 @@ static int adm1029_detect(struct i2c_client *client,
	return 0;
	return 0;
}
}


static int adm1029_init_client(struct i2c_client *client)
{
	u8 config;

	config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
	if ((config & 0x10) == 0) {
		i2c_smbus_write_byte_data(client, ADM1029_REG_CONFIG,
					  config | 0x10);
	}
	/* recheck config */
	config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
	if ((config & 0x10) == 0) {
		dev_err(&client->dev, "Initialization failed!\n");
		return 0;
	}
	return 1;
}

static int adm1029_probe(struct i2c_client *client,
static int adm1029_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
			 const struct i2c_device_id *id)
{
{
@@ -379,23 +407,6 @@ static int adm1029_probe(struct i2c_client *client,
	return err;
	return err;
}
}


static int adm1029_init_client(struct i2c_client *client)
{
	u8 config;
	config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
	if ((config & 0x10) == 0) {
		i2c_smbus_write_byte_data(client, ADM1029_REG_CONFIG,
					  config | 0x10);
	}
	/* recheck config */
	config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
	if ((config & 0x10) == 0) {
		dev_err(&client->dev, "Initialization failed!\n");
		return 0;
	}
	return 1;
}

static int adm1029_remove(struct i2c_client *client)
static int adm1029_remove(struct i2c_client *client)
{
{
	struct adm1029_data *data = i2c_get_clientdata(client);
	struct adm1029_data *data = i2c_get_clientdata(client);
@@ -406,49 +417,23 @@ static int adm1029_remove(struct i2c_client *client)
	return 0;
	return 0;
}
}


/*
static const struct i2c_device_id adm1029_id[] = {
 * function that update the status of the chips (temperature for example)
	{ "adm1029", 0 },
 */
	{ }
static struct adm1029_data *adm1029_update_device(struct device *dev)
};
{
MODULE_DEVICE_TABLE(i2c, adm1029_id);
	struct i2c_client *client = to_i2c_client(dev);
	struct adm1029_data *data = i2c_get_clientdata(client);

	mutex_lock(&data->update_lock);
	/*
	 * Use the "cache" Luke, don't recheck values
	 * if there are already checked not a long time later
	 */
	if (time_after(jiffies, data->last_updated + HZ * 2)
	 || !data->valid) {
		int nr;

		dev_dbg(&client->dev, "Updating adm1029 data\n");

		for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_TEMP); nr++) {
			data->temp[nr] =
			    i2c_smbus_read_byte_data(client,
						     ADM1029_REG_TEMP[nr]);
		}
		for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN); nr++) {
			data->fan[nr] =
			    i2c_smbus_read_byte_data(client,
						     ADM1029_REG_FAN[nr]);
		}
		for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) {
			data->fan_div[nr] =
			    i2c_smbus_read_byte_data(client,
						     ADM1029_REG_FAN_DIV[nr]);
		}

		data->last_updated = jiffies;
		data->valid = 1;
	}

	mutex_unlock(&data->update_lock);


	return data;
static struct i2c_driver adm1029_driver = {
}
	.class		= I2C_CLASS_HWMON,
	.driver = {
		.name = "adm1029",
	},
	.probe		= adm1029_probe,
	.remove		= adm1029_remove,
	.id_table	= adm1029_id,
	.detect		= adm1029_detect,
	.address_list	= normal_i2c,
};


module_i2c_driver(adm1029_driver);
module_i2c_driver(adm1029_driver);