diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-07-16 13:30:10 -0400 |
---|---|---|
committer | Jean Delvare <khali@mahadeva.delvare> | 2008-07-16 13:30:10 -0400 |
commit | 7347cb388e5aecffc4920bd5ea6a61e4a4690bae (patch) | |
tree | cd1cca34f2f93f41506940d3ed3ec47fc35d3fc8 /drivers/hwmon | |
parent | 7fae8283109e155467bc1c622178d3a475cdbddf (diff) |
hwmon: (ads7828) Convert to a new-style i2c driver
The new-style ads7828 driver implements the optional detect() callback
to cover the use cases of the legacy driver.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/ads7828.c | 89 |
1 files changed, 38 insertions, 51 deletions
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 5c8b6e0ff47c..5c39b4af1b23 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -64,7 +64,6 @@ static unsigned int ads7828_lsb_resol; /* resolution of the ADC sample lsb */ | |||
64 | 64 | ||
65 | /* Each client has this additional data */ | 65 | /* Each client has this additional data */ |
66 | struct ads7828_data { | 66 | struct ads7828_data { |
67 | struct i2c_client client; | ||
68 | struct device *hwmon_dev; | 67 | struct device *hwmon_dev; |
69 | struct mutex update_lock; /* mutex protect updates */ | 68 | struct mutex update_lock; /* mutex protect updates */ |
70 | char valid; /* !=0 if following fields are valid */ | 69 | char valid; /* !=0 if following fields are valid */ |
@@ -73,7 +72,10 @@ struct ads7828_data { | |||
73 | }; | 72 | }; |
74 | 73 | ||
75 | /* Function declaration - necessary due to function dependencies */ | 74 | /* Function declaration - necessary due to function dependencies */ |
76 | static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind); | 75 | static int ads7828_detect(struct i2c_client *client, int kind, |
76 | struct i2c_board_info *info); | ||
77 | static int ads7828_probe(struct i2c_client *client, | ||
78 | const struct i2c_device_id *id); | ||
77 | 79 | ||
78 | /* The ADS7828 returns the 12-bit sample in two bytes, | 80 | /* The ADS7828 returns the 12-bit sample in two bytes, |
79 | these are read as a word then byte-swapped */ | 81 | these are read as a word then byte-swapped */ |
@@ -156,58 +158,43 @@ static const struct attribute_group ads7828_group = { | |||
156 | .attrs = ads7828_attributes, | 158 | .attrs = ads7828_attributes, |
157 | }; | 159 | }; |
158 | 160 | ||
159 | static int ads7828_attach_adapter(struct i2c_adapter *adapter) | 161 | static int ads7828_remove(struct i2c_client *client) |
160 | { | ||
161 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
162 | return 0; | ||
163 | return i2c_probe(adapter, &addr_data, ads7828_detect); | ||
164 | } | ||
165 | |||
166 | static int ads7828_detach_client(struct i2c_client *client) | ||
167 | { | 162 | { |
168 | struct ads7828_data *data = i2c_get_clientdata(client); | 163 | struct ads7828_data *data = i2c_get_clientdata(client); |
169 | hwmon_device_unregister(data->hwmon_dev); | 164 | hwmon_device_unregister(data->hwmon_dev); |
170 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | 165 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); |
171 | i2c_detach_client(client); | ||
172 | kfree(i2c_get_clientdata(client)); | 166 | kfree(i2c_get_clientdata(client)); |
173 | return 0; | 167 | return 0; |
174 | } | 168 | } |
175 | 169 | ||
170 | static const struct i2c_device_id ads7828_id[] = { | ||
171 | { "ads7828", ads7828 }, | ||
172 | { } | ||
173 | }; | ||
174 | MODULE_DEVICE_TABLE(i2c, ads7828_id); | ||
175 | |||
176 | /* This is the driver that will be inserted */ | 176 | /* This is the driver that will be inserted */ |
177 | static struct i2c_driver ads7828_driver = { | 177 | static struct i2c_driver ads7828_driver = { |
178 | .class = I2C_CLASS_HWMON, | ||
178 | .driver = { | 179 | .driver = { |
179 | .name = "ads7828", | 180 | .name = "ads7828", |
180 | }, | 181 | }, |
181 | .attach_adapter = ads7828_attach_adapter, | 182 | .probe = ads7828_probe, |
182 | .detach_client = ads7828_detach_client, | 183 | .remove = ads7828_remove, |
184 | .id_table = ads7828_id, | ||
185 | .detect = ads7828_detect, | ||
186 | .address_data = &addr_data, | ||
183 | }; | 187 | }; |
184 | 188 | ||
185 | /* This function is called by i2c_probe */ | 189 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
186 | static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | 190 | static int ads7828_detect(struct i2c_client *client, int kind, |
191 | struct i2c_board_info *info) | ||
187 | { | 192 | { |
188 | struct i2c_client *client; | 193 | struct i2c_adapter *adapter = client->adapter; |
189 | struct ads7828_data *data; | ||
190 | int err = 0; | ||
191 | const char *name = ""; | ||
192 | 194 | ||
193 | /* Check we have a valid client */ | 195 | /* Check we have a valid client */ |
194 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) | 196 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) |
195 | goto exit; | 197 | return -ENODEV; |
196 | |||
197 | /* OK. For now, we presume we have a valid client. We now create the | ||
198 | client structure, even though we cannot fill it completely yet. | ||
199 | But it allows us to access ads7828_read_value. */ | ||
200 | data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL); | ||
201 | if (!data) { | ||
202 | err = -ENOMEM; | ||
203 | goto exit; | ||
204 | } | ||
205 | |||
206 | client = &data->client; | ||
207 | i2c_set_clientdata(client, data); | ||
208 | client->addr = address; | ||
209 | client->adapter = adapter; | ||
210 | client->driver = &ads7828_driver; | ||
211 | 198 | ||
212 | /* Now, we do the remaining detection. There is no identification | 199 | /* Now, we do the remaining detection. There is no identification |
213 | dedicated register so attempt to sanity check using knowledge of | 200 | dedicated register so attempt to sanity check using knowledge of |
@@ -225,32 +212,34 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | |||
225 | printk(KERN_DEBUG | 212 | printk(KERN_DEBUG |
226 | "%s : Doesn't look like an ads7828 device\n", | 213 | "%s : Doesn't look like an ads7828 device\n", |
227 | __func__); | 214 | __func__); |
228 | goto exit_free; | 215 | return -ENODEV; |
229 | } | 216 | } |
230 | } | 217 | } |
231 | } | 218 | } |
219 | strlcpy(info->type, "ads7828", I2C_NAME_SIZE); | ||
232 | 220 | ||
233 | /* Determine the chip type - only one kind supported! */ | 221 | return 0; |
234 | if (kind <= 0) | 222 | } |
235 | kind = ads7828; | ||
236 | 223 | ||
237 | if (kind == ads7828) | 224 | static int ads7828_probe(struct i2c_client *client, |
238 | name = "ads7828"; | 225 | const struct i2c_device_id *id) |
226 | { | ||
227 | struct ads7828_data *data; | ||
228 | int err; | ||
239 | 229 | ||
240 | /* Fill in the remaining client fields, put it into the global list */ | 230 | data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL); |
241 | strlcpy(client->name, name, I2C_NAME_SIZE); | 231 | if (!data) { |
232 | err = -ENOMEM; | ||
233 | goto exit; | ||
234 | } | ||
242 | 235 | ||
236 | i2c_set_clientdata(client, data); | ||
243 | mutex_init(&data->update_lock); | 237 | mutex_init(&data->update_lock); |
244 | 238 | ||
245 | /* Tell the I2C layer a new client has arrived */ | ||
246 | err = i2c_attach_client(client); | ||
247 | if (err) | ||
248 | goto exit_free; | ||
249 | |||
250 | /* Register sysfs hooks */ | 239 | /* Register sysfs hooks */ |
251 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); | 240 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); |
252 | if (err) | 241 | if (err) |
253 | goto exit_detach; | 242 | goto exit_free; |
254 | 243 | ||
255 | data->hwmon_dev = hwmon_device_register(&client->dev); | 244 | data->hwmon_dev = hwmon_device_register(&client->dev); |
256 | if (IS_ERR(data->hwmon_dev)) { | 245 | if (IS_ERR(data->hwmon_dev)) { |
@@ -262,8 +251,6 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind) | |||
262 | 251 | ||
263 | exit_remove: | 252 | exit_remove: |
264 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | 253 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); |
265 | exit_detach: | ||
266 | i2c_detach_client(client); | ||
267 | exit_free: | 254 | exit_free: |
268 | kfree(data); | 255 | kfree(data); |
269 | exit: | 256 | exit: |