hwmon: (fscher) Convert to a new-style i2c driver
The new-style fscher driver implements the optional detect() callback to cover the use cases of the legacy driver. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Reinhard Nissl <rnissl@gmx.de>
This commit is contained in:
parent
935ada8c44
commit
c2df1591df
1 changed files with 42 additions and 51 deletions
|
@ -106,9 +106,11 @@ I2C_CLIENT_INSMOD_1(fscher);
|
||||||
* Functions declaration
|
* Functions declaration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int fscher_attach_adapter(struct i2c_adapter *adapter);
|
static int fscher_probe(struct i2c_client *client,
|
||||||
static int fscher_detect(struct i2c_adapter *adapter, int address, int kind);
|
const struct i2c_device_id *id);
|
||||||
static int fscher_detach_client(struct i2c_client *client);
|
static int fscher_detect(struct i2c_client *client, int kind,
|
||||||
|
struct i2c_board_info *info);
|
||||||
|
static int fscher_remove(struct i2c_client *client);
|
||||||
static struct fscher_data *fscher_update_device(struct device *dev);
|
static struct fscher_data *fscher_update_device(struct device *dev);
|
||||||
static void fscher_init_client(struct i2c_client *client);
|
static void fscher_init_client(struct i2c_client *client);
|
||||||
|
|
||||||
|
@ -119,12 +121,21 @@ static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value);
|
||||||
* Driver data (common to all clients)
|
* Driver data (common to all clients)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static const struct i2c_device_id fscher_id[] = {
|
||||||
|
{ "fscher", fscher },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
static struct i2c_driver fscher_driver = {
|
static struct i2c_driver fscher_driver = {
|
||||||
|
.class = I2C_CLASS_HWMON,
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "fscher",
|
.name = "fscher",
|
||||||
},
|
},
|
||||||
.attach_adapter = fscher_attach_adapter,
|
.probe = fscher_probe,
|
||||||
.detach_client = fscher_detach_client,
|
.remove = fscher_remove,
|
||||||
|
.id_table = fscher_id,
|
||||||
|
.detect = fscher_detect,
|
||||||
|
.address_data = &addr_data,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -132,7 +143,6 @@ static struct i2c_driver fscher_driver = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct fscher_data {
|
struct fscher_data {
|
||||||
struct i2c_client client;
|
|
||||||
struct device *hwmon_dev;
|
struct device *hwmon_dev;
|
||||||
struct mutex update_lock;
|
struct mutex update_lock;
|
||||||
char valid; /* zero until following fields are valid */
|
char valid; /* zero until following fields are valid */
|
||||||
|
@ -283,38 +293,14 @@ static const struct attribute_group fscher_group = {
|
||||||
* Real code
|
* Real code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int fscher_attach_adapter(struct i2c_adapter *adapter)
|
/* Return 0 if detection is successful, -ENODEV otherwise */
|
||||||
|
static int fscher_detect(struct i2c_client *new_client, int kind,
|
||||||
|
struct i2c_board_info *info)
|
||||||
{
|
{
|
||||||
if (!(adapter->class & I2C_CLASS_HWMON))
|
struct i2c_adapter *adapter = new_client->adapter;
|
||||||
return 0;
|
|
||||||
return i2c_probe(adapter, &addr_data, fscher_detect);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
|
|
||||||
{
|
|
||||||
struct i2c_client *new_client;
|
|
||||||
struct fscher_data *data;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||||
goto exit;
|
return -ENODEV;
|
||||||
|
|
||||||
/* OK. For now, we presume we have a valid client. We now create the
|
|
||||||
* client structure, even though we cannot fill it completely yet.
|
|
||||||
* But it allows us to access i2c_smbus_read_byte_data. */
|
|
||||||
if (!(data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The common I2C client data is placed right before the
|
|
||||||
* Hermes-specific data. */
|
|
||||||
new_client = &data->client;
|
|
||||||
i2c_set_clientdata(new_client, data);
|
|
||||||
new_client->addr = address;
|
|
||||||
new_client->adapter = adapter;
|
|
||||||
new_client->driver = &fscher_driver;
|
|
||||||
new_client->flags = 0;
|
|
||||||
|
|
||||||
/* Do the remaining detection unless force or force_fscher parameter */
|
/* Do the remaining detection unless force or force_fscher parameter */
|
||||||
if (kind < 0) {
|
if (kind < 0) {
|
||||||
|
@ -324,24 +310,35 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
|
||||||
FSCHER_REG_IDENT_1) != 0x45) /* 'E' */
|
FSCHER_REG_IDENT_1) != 0x45) /* 'E' */
|
||||||
|| (i2c_smbus_read_byte_data(new_client,
|
|| (i2c_smbus_read_byte_data(new_client,
|
||||||
FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */
|
FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */
|
||||||
goto exit_free;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in the remaining client fields and put it into the
|
strlcpy(info->type, "fscher", I2C_NAME_SIZE);
|
||||||
* global list */
|
|
||||||
strlcpy(new_client->name, "fscher", I2C_NAME_SIZE);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fscher_probe(struct i2c_client *new_client,
|
||||||
|
const struct i2c_device_id *id)
|
||||||
|
{
|
||||||
|
struct fscher_data *data;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL);
|
||||||
|
if (!data) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_set_clientdata(new_client, data);
|
||||||
data->valid = 0;
|
data->valid = 0;
|
||||||
mutex_init(&data->update_lock);
|
mutex_init(&data->update_lock);
|
||||||
|
|
||||||
/* Tell the I2C layer a new client has arrived */
|
|
||||||
if ((err = i2c_attach_client(new_client)))
|
|
||||||
goto exit_free;
|
|
||||||
|
|
||||||
fscher_init_client(new_client);
|
fscher_init_client(new_client);
|
||||||
|
|
||||||
/* Register sysfs hooks */
|
/* Register sysfs hooks */
|
||||||
if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
|
if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
|
||||||
goto exit_detach;
|
goto exit_free;
|
||||||
|
|
||||||
data->hwmon_dev = hwmon_device_register(&new_client->dev);
|
data->hwmon_dev = hwmon_device_register(&new_client->dev);
|
||||||
if (IS_ERR(data->hwmon_dev)) {
|
if (IS_ERR(data->hwmon_dev)) {
|
||||||
|
@ -353,25 +350,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
|
||||||
|
|
||||||
exit_remove_files:
|
exit_remove_files:
|
||||||
sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
|
sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
|
||||||
exit_detach:
|
|
||||||
i2c_detach_client(new_client);
|
|
||||||
exit_free:
|
exit_free:
|
||||||
kfree(data);
|
kfree(data);
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fscher_detach_client(struct i2c_client *client)
|
static int fscher_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
struct fscher_data *data = i2c_get_clientdata(client);
|
struct fscher_data *data = i2c_get_clientdata(client);
|
||||||
int err;
|
|
||||||
|
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
hwmon_device_unregister(data->hwmon_dev);
|
||||||
sysfs_remove_group(&client->dev.kobj, &fscher_group);
|
sysfs_remove_group(&client->dev.kobj, &fscher_group);
|
||||||
|
|
||||||
if ((err = i2c_detach_client(client)))
|
|
||||||
return err;
|
|
||||||
|
|
||||||
kfree(data);
|
kfree(data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue