diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-07-17 13:24:56 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-17 13:24:56 -0400 |
commit | c43c1be0f7e0ac3d2fe1d4a5b37041c4c4463af1 (patch) | |
tree | 618b5e8ac458258acc981e0aeeac6f232f14aaf8 /drivers/i2c/chips | |
parent | e22146e610bb7aed63282148740ab1d1b91e1d90 (diff) | |
parent | a3cf859321486f69506326146ab3e2fd15c05c3f (diff) |
Merge branch 'linus' into x86/urgent
Diffstat (limited to 'drivers/i2c/chips')
-rw-r--r-- | drivers/i2c/chips/eeprom.c | 92 | ||||
-rw-r--r-- | drivers/i2c/chips/max6875.c | 120 | ||||
-rw-r--r-- | drivers/i2c/chips/pca9539.c | 109 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8574.c | 108 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8575.c | 96 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8591.c | 94 |
6 files changed, 248 insertions, 371 deletions
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c index 373ea8d8fe8f..2c27193aeaa0 100644 --- a/drivers/i2c/chips/eeprom.c +++ b/drivers/i2c/chips/eeprom.c | |||
@@ -47,7 +47,6 @@ enum eeprom_nature { | |||
47 | 47 | ||
48 | /* Each client has this additional data */ | 48 | /* Each client has this additional data */ |
49 | struct eeprom_data { | 49 | struct eeprom_data { |
50 | struct i2c_client client; | ||
51 | struct mutex update_lock; | 50 | struct mutex update_lock; |
52 | u8 valid; /* bitfield, bit!=0 if slice is valid */ | 51 | u8 valid; /* bitfield, bit!=0 if slice is valid */ |
53 | unsigned long last_updated[8]; /* In jiffies, 8 slices */ | 52 | unsigned long last_updated[8]; /* In jiffies, 8 slices */ |
@@ -56,19 +55,6 @@ struct eeprom_data { | |||
56 | }; | 55 | }; |
57 | 56 | ||
58 | 57 | ||
59 | static int eeprom_attach_adapter(struct i2c_adapter *adapter); | ||
60 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind); | ||
61 | static int eeprom_detach_client(struct i2c_client *client); | ||
62 | |||
63 | /* This is the driver that will be inserted */ | ||
64 | static struct i2c_driver eeprom_driver = { | ||
65 | .driver = { | ||
66 | .name = "eeprom", | ||
67 | }, | ||
68 | .attach_adapter = eeprom_attach_adapter, | ||
69 | .detach_client = eeprom_detach_client, | ||
70 | }; | ||
71 | |||
72 | static void eeprom_update_client(struct i2c_client *client, u8 slice) | 58 | static void eeprom_update_client(struct i2c_client *client, u8 slice) |
73 | { | 59 | { |
74 | struct eeprom_data *data = i2c_get_clientdata(client); | 60 | struct eeprom_data *data = i2c_get_clientdata(client); |
@@ -148,25 +134,17 @@ static struct bin_attribute eeprom_attr = { | |||
148 | .read = eeprom_read, | 134 | .read = eeprom_read, |
149 | }; | 135 | }; |
150 | 136 | ||
151 | static int eeprom_attach_adapter(struct i2c_adapter *adapter) | 137 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
152 | { | 138 | static int eeprom_detect(struct i2c_client *client, int kind, |
153 | if (!(adapter->class & (I2C_CLASS_DDC | I2C_CLASS_SPD))) | 139 | struct i2c_board_info *info) |
154 | return 0; | ||
155 | return i2c_probe(adapter, &addr_data, eeprom_detect); | ||
156 | } | ||
157 | |||
158 | /* This function is called by i2c_probe */ | ||
159 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | ||
160 | { | 140 | { |
161 | struct i2c_client *client; | 141 | struct i2c_adapter *adapter = client->adapter; |
162 | struct eeprom_data *data; | ||
163 | int err = 0; | ||
164 | 142 | ||
165 | /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all | 143 | /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all |
166 | addresses 0x50-0x57, but we only care about 0x50. So decline | 144 | addresses 0x50-0x57, but we only care about 0x50. So decline |
167 | attaching to addresses >= 0x51 on DDC buses */ | 145 | attaching to addresses >= 0x51 on DDC buses */ |
168 | if (!(adapter->class & I2C_CLASS_SPD) && address >= 0x51) | 146 | if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51) |
169 | goto exit; | 147 | return -ENODEV; |
170 | 148 | ||
171 | /* There are four ways we can read the EEPROM data: | 149 | /* There are four ways we can read the EEPROM data: |
172 | (1) I2C block reads (faster, but unsupported by most adapters) | 150 | (1) I2C block reads (faster, but unsupported by most adapters) |
@@ -177,32 +155,33 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | |||
177 | because all known adapters support one of the first two. */ | 155 | because all known adapters support one of the first two. */ |
178 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) | 156 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) |
179 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) | 157 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) |
180 | goto exit; | 158 | return -ENODEV; |
159 | |||
160 | strlcpy(info->type, "eeprom", I2C_NAME_SIZE); | ||
161 | |||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static int eeprom_probe(struct i2c_client *client, | ||
166 | const struct i2c_device_id *id) | ||
167 | { | ||
168 | struct i2c_adapter *adapter = client->adapter; | ||
169 | struct eeprom_data *data; | ||
170 | int err; | ||
181 | 171 | ||
182 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { | 172 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { |
183 | err = -ENOMEM; | 173 | err = -ENOMEM; |
184 | goto exit; | 174 | goto exit; |
185 | } | 175 | } |
186 | 176 | ||
187 | client = &data->client; | ||
188 | memset(data->data, 0xff, EEPROM_SIZE); | 177 | memset(data->data, 0xff, EEPROM_SIZE); |
189 | i2c_set_clientdata(client, data); | 178 | i2c_set_clientdata(client, data); |
190 | client->addr = address; | ||
191 | client->adapter = adapter; | ||
192 | client->driver = &eeprom_driver; | ||
193 | |||
194 | /* Fill in the remaining client fields */ | ||
195 | strlcpy(client->name, "eeprom", I2C_NAME_SIZE); | ||
196 | mutex_init(&data->update_lock); | 179 | mutex_init(&data->update_lock); |
197 | data->nature = UNKNOWN; | 180 | data->nature = UNKNOWN; |
198 | 181 | ||
199 | /* Tell the I2C layer a new client has arrived */ | ||
200 | if ((err = i2c_attach_client(client))) | ||
201 | goto exit_kfree; | ||
202 | |||
203 | /* Detect the Vaio nature of EEPROMs. | 182 | /* Detect the Vaio nature of EEPROMs. |
204 | We use the "PCG-" or "VGN-" prefix as the signature. */ | 183 | We use the "PCG-" or "VGN-" prefix as the signature. */ |
205 | if (address == 0x57 | 184 | if (client->addr == 0x57 |
206 | && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { | 185 | && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { |
207 | char name[4]; | 186 | char name[4]; |
208 | 187 | ||
@@ -221,33 +200,42 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | |||
221 | /* create the sysfs eeprom file */ | 200 | /* create the sysfs eeprom file */ |
222 | err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); | 201 | err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); |
223 | if (err) | 202 | if (err) |
224 | goto exit_detach; | 203 | goto exit_kfree; |
225 | 204 | ||
226 | return 0; | 205 | return 0; |
227 | 206 | ||
228 | exit_detach: | ||
229 | i2c_detach_client(client); | ||
230 | exit_kfree: | 207 | exit_kfree: |
231 | kfree(data); | 208 | kfree(data); |
232 | exit: | 209 | exit: |
233 | return err; | 210 | return err; |
234 | } | 211 | } |
235 | 212 | ||
236 | static int eeprom_detach_client(struct i2c_client *client) | 213 | static int eeprom_remove(struct i2c_client *client) |
237 | { | 214 | { |
238 | int err; | ||
239 | |||
240 | sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); | 215 | sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); |
241 | |||
242 | err = i2c_detach_client(client); | ||
243 | if (err) | ||
244 | return err; | ||
245 | |||
246 | kfree(i2c_get_clientdata(client)); | 216 | kfree(i2c_get_clientdata(client)); |
247 | 217 | ||
248 | return 0; | 218 | return 0; |
249 | } | 219 | } |
250 | 220 | ||
221 | static const struct i2c_device_id eeprom_id[] = { | ||
222 | { "eeprom", 0 }, | ||
223 | { } | ||
224 | }; | ||
225 | |||
226 | static struct i2c_driver eeprom_driver = { | ||
227 | .driver = { | ||
228 | .name = "eeprom", | ||
229 | }, | ||
230 | .probe = eeprom_probe, | ||
231 | .remove = eeprom_remove, | ||
232 | .id_table = eeprom_id, | ||
233 | |||
234 | .class = I2C_CLASS_DDC | I2C_CLASS_SPD, | ||
235 | .detect = eeprom_detect, | ||
236 | .address_data = &addr_data, | ||
237 | }; | ||
238 | |||
251 | static int __init eeprom_init(void) | 239 | static int __init eeprom_init(void) |
252 | { | 240 | { |
253 | return i2c_add_driver(&eeprom_driver); | 241 | return i2c_add_driver(&eeprom_driver); |
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c index 5a0285d8b6f9..033d9d81ec8a 100644 --- a/drivers/i2c/chips/max6875.c +++ b/drivers/i2c/chips/max6875.c | |||
@@ -53,7 +53,7 @@ I2C_CLIENT_INSMOD_1(max6875); | |||
53 | 53 | ||
54 | /* Each client has this additional data */ | 54 | /* Each client has this additional data */ |
55 | struct max6875_data { | 55 | struct max6875_data { |
56 | struct i2c_client client; | 56 | struct i2c_client *fake_client; |
57 | struct mutex update_lock; | 57 | struct mutex update_lock; |
58 | 58 | ||
59 | u32 valid; | 59 | u32 valid; |
@@ -61,19 +61,6 @@ struct max6875_data { | |||
61 | unsigned long last_updated[USER_EEPROM_SLICES]; | 61 | unsigned long last_updated[USER_EEPROM_SLICES]; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | static int max6875_attach_adapter(struct i2c_adapter *adapter); | ||
65 | static int max6875_detect(struct i2c_adapter *adapter, int address, int kind); | ||
66 | static int max6875_detach_client(struct i2c_client *client); | ||
67 | |||
68 | /* This is the driver that will be inserted */ | ||
69 | static struct i2c_driver max6875_driver = { | ||
70 | .driver = { | ||
71 | .name = "max6875", | ||
72 | }, | ||
73 | .attach_adapter = max6875_attach_adapter, | ||
74 | .detach_client = max6875_detach_client, | ||
75 | }; | ||
76 | |||
77 | static void max6875_update_slice(struct i2c_client *client, int slice) | 64 | static void max6875_update_slice(struct i2c_client *client, int slice) |
78 | { | 65 | { |
79 | struct max6875_data *data = i2c_get_clientdata(client); | 66 | struct max6875_data *data = i2c_get_clientdata(client); |
@@ -159,96 +146,87 @@ static struct bin_attribute user_eeprom_attr = { | |||
159 | .read = max6875_read, | 146 | .read = max6875_read, |
160 | }; | 147 | }; |
161 | 148 | ||
162 | static int max6875_attach_adapter(struct i2c_adapter *adapter) | 149 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
150 | static int max6875_detect(struct i2c_client *client, int kind, | ||
151 | struct i2c_board_info *info) | ||
163 | { | 152 | { |
164 | return i2c_probe(adapter, &addr_data, max6875_detect); | 153 | struct i2c_adapter *adapter = client->adapter; |
165 | } | ||
166 | |||
167 | /* This function is called by i2c_probe */ | ||
168 | static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) | ||
169 | { | ||
170 | struct i2c_client *real_client; | ||
171 | struct i2c_client *fake_client; | ||
172 | struct max6875_data *data; | ||
173 | int err; | ||
174 | 154 | ||
175 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA | 155 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
176 | | I2C_FUNC_SMBUS_READ_BYTE)) | 156 | | I2C_FUNC_SMBUS_READ_BYTE)) |
177 | return 0; | 157 | return -ENODEV; |
178 | 158 | ||
179 | /* Only check even addresses */ | 159 | /* Only check even addresses */ |
180 | if (address & 1) | 160 | if (client->addr & 1) |
181 | return 0; | 161 | return -ENODEV; |
162 | |||
163 | strlcpy(info->type, "max6875", I2C_NAME_SIZE); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int max6875_probe(struct i2c_client *client, | ||
169 | const struct i2c_device_id *id) | ||
170 | { | ||
171 | struct max6875_data *data; | ||
172 | int err; | ||
182 | 173 | ||
183 | if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) | 174 | if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) |
184 | return -ENOMEM; | 175 | return -ENOMEM; |
185 | 176 | ||
186 | /* A fake client is created on the odd address */ | 177 | /* A fake client is created on the odd address */ |
187 | if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) { | 178 | data->fake_client = i2c_new_dummy(client->adapter, client->addr + 1); |
179 | if (!data->fake_client) { | ||
188 | err = -ENOMEM; | 180 | err = -ENOMEM; |
189 | goto exit_kfree1; | 181 | goto exit_kfree; |
190 | } | 182 | } |
191 | 183 | ||
192 | /* Init real i2c_client */ | 184 | /* Init real i2c_client */ |
193 | real_client = &data->client; | 185 | i2c_set_clientdata(client, data); |
194 | i2c_set_clientdata(real_client, data); | ||
195 | real_client->addr = address; | ||
196 | real_client->adapter = adapter; | ||
197 | real_client->driver = &max6875_driver; | ||
198 | strlcpy(real_client->name, "max6875", I2C_NAME_SIZE); | ||
199 | mutex_init(&data->update_lock); | 186 | mutex_init(&data->update_lock); |
200 | 187 | ||
201 | /* Init fake client data */ | 188 | err = sysfs_create_bin_file(&client->dev.kobj, &user_eeprom_attr); |
202 | i2c_set_clientdata(fake_client, NULL); | ||
203 | fake_client->addr = address | 1; | ||
204 | fake_client->adapter = adapter; | ||
205 | fake_client->driver = &max6875_driver; | ||
206 | strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE); | ||
207 | |||
208 | if ((err = i2c_attach_client(real_client)) != 0) | ||
209 | goto exit_kfree2; | ||
210 | |||
211 | if ((err = i2c_attach_client(fake_client)) != 0) | ||
212 | goto exit_detach1; | ||
213 | |||
214 | err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); | ||
215 | if (err) | 189 | if (err) |
216 | goto exit_detach2; | 190 | goto exit_remove_fake; |
217 | 191 | ||
218 | return 0; | 192 | return 0; |
219 | 193 | ||
220 | exit_detach2: | 194 | exit_remove_fake: |
221 | i2c_detach_client(fake_client); | 195 | i2c_unregister_device(data->fake_client); |
222 | exit_detach1: | 196 | exit_kfree: |
223 | i2c_detach_client(real_client); | ||
224 | exit_kfree2: | ||
225 | kfree(fake_client); | ||
226 | exit_kfree1: | ||
227 | kfree(data); | 197 | kfree(data); |
228 | return err; | 198 | return err; |
229 | } | 199 | } |
230 | 200 | ||
231 | /* Will be called for both the real client and the fake client */ | 201 | static int max6875_remove(struct i2c_client *client) |
232 | static int max6875_detach_client(struct i2c_client *client) | ||
233 | { | 202 | { |
234 | int err; | ||
235 | struct max6875_data *data = i2c_get_clientdata(client); | 203 | struct max6875_data *data = i2c_get_clientdata(client); |
236 | 204 | ||
237 | /* data is NULL for the fake client */ | 205 | i2c_unregister_device(data->fake_client); |
238 | if (data) | ||
239 | sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr); | ||
240 | 206 | ||
241 | err = i2c_detach_client(client); | 207 | sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr); |
242 | if (err) | 208 | kfree(data); |
243 | return err; | ||
244 | 209 | ||
245 | if (data) /* real client */ | ||
246 | kfree(data); | ||
247 | else /* fake client */ | ||
248 | kfree(client); | ||
249 | return 0; | 210 | return 0; |
250 | } | 211 | } |
251 | 212 | ||
213 | static const struct i2c_device_id max6875_id[] = { | ||
214 | { "max6875", 0 }, | ||
215 | { } | ||
216 | }; | ||
217 | |||
218 | static struct i2c_driver max6875_driver = { | ||
219 | .driver = { | ||
220 | .name = "max6875", | ||
221 | }, | ||
222 | .probe = max6875_probe, | ||
223 | .remove = max6875_remove, | ||
224 | .id_table = max6875_id, | ||
225 | |||
226 | .detect = max6875_detect, | ||
227 | .address_data = &addr_data, | ||
228 | }; | ||
229 | |||
252 | static int __init max6875_init(void) | 230 | static int __init max6875_init(void) |
253 | { | 231 | { |
254 | return i2c_add_driver(&max6875_driver); | 232 | return i2c_add_driver(&max6875_driver); |
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c index 58ab7f26be26..270de4e56a81 100644 --- a/drivers/i2c/chips/pca9539.c +++ b/drivers/i2c/chips/pca9539.c | |||
@@ -14,8 +14,8 @@ | |||
14 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
15 | #include <linux/hwmon-sysfs.h> | 15 | #include <linux/hwmon-sysfs.h> |
16 | 16 | ||
17 | /* Addresses to scan */ | 17 | /* Addresses to scan: none, device is not autodetected */ |
18 | static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; | 18 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
19 | 19 | ||
20 | /* Insmod parameters */ | 20 | /* Insmod parameters */ |
21 | I2C_CLIENT_INSMOD_1(pca9539); | 21 | I2C_CLIENT_INSMOD_1(pca9539); |
@@ -32,23 +32,6 @@ enum pca9539_cmd | |||
32 | PCA9539_DIRECTION_1 = 7, | 32 | PCA9539_DIRECTION_1 = 7, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | static int pca9539_attach_adapter(struct i2c_adapter *adapter); | ||
36 | static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind); | ||
37 | static int pca9539_detach_client(struct i2c_client *client); | ||
38 | |||
39 | /* This is the driver that will be inserted */ | ||
40 | static struct i2c_driver pca9539_driver = { | ||
41 | .driver = { | ||
42 | .name = "pca9539", | ||
43 | }, | ||
44 | .attach_adapter = pca9539_attach_adapter, | ||
45 | .detach_client = pca9539_detach_client, | ||
46 | }; | ||
47 | |||
48 | struct pca9539_data { | ||
49 | struct i2c_client client; | ||
50 | }; | ||
51 | |||
52 | /* following are the sysfs callback functions */ | 35 | /* following are the sysfs callback functions */ |
53 | static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, | 36 | static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, |
54 | char *buf) | 37 | char *buf) |
@@ -105,77 +88,51 @@ static struct attribute_group pca9539_defattr_group = { | |||
105 | .attrs = pca9539_attributes, | 88 | .attrs = pca9539_attributes, |
106 | }; | 89 | }; |
107 | 90 | ||
108 | static int pca9539_attach_adapter(struct i2c_adapter *adapter) | 91 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
92 | static int pca9539_detect(struct i2c_client *client, int kind, | ||
93 | struct i2c_board_info *info) | ||
109 | { | 94 | { |
110 | return i2c_probe(adapter, &addr_data, pca9539_detect); | 95 | struct i2c_adapter *adapter = client->adapter; |
111 | } | ||
112 | |||
113 | /* This function is called by i2c_probe */ | ||
114 | static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) | ||
115 | { | ||
116 | struct i2c_client *client; | ||
117 | struct pca9539_data *data; | ||
118 | int err = 0; | ||
119 | 96 | ||
120 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 97 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
121 | goto exit; | 98 | return -ENODEV; |
122 | |||
123 | /* OK. For now, we presume we have a valid client. We now create the | ||
124 | client structure, even though we cannot fill it completely yet. */ | ||
125 | if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) { | ||
126 | err = -ENOMEM; | ||
127 | goto exit; | ||
128 | } | ||
129 | |||
130 | client = &data->client; | ||
131 | i2c_set_clientdata(client, data); | ||
132 | client->addr = address; | ||
133 | client->adapter = adapter; | ||
134 | client->driver = &pca9539_driver; | ||
135 | |||
136 | if (kind < 0) { | ||
137 | /* Detection: the pca9539 only has 8 registers (0-7). | ||
138 | A read of 7 should succeed, but a read of 8 should fail. */ | ||
139 | if ((i2c_smbus_read_byte_data(client, 7) < 0) || | ||
140 | (i2c_smbus_read_byte_data(client, 8) >= 0)) | ||
141 | goto exit_kfree; | ||
142 | } | ||
143 | |||
144 | strlcpy(client->name, "pca9539", I2C_NAME_SIZE); | ||
145 | |||
146 | /* Tell the I2C layer a new client has arrived */ | ||
147 | if ((err = i2c_attach_client(client))) | ||
148 | goto exit_kfree; | ||
149 | 99 | ||
150 | /* Register sysfs hooks */ | 100 | strlcpy(info->type, "pca9539", I2C_NAME_SIZE); |
151 | err = sysfs_create_group(&client->dev.kobj, | ||
152 | &pca9539_defattr_group); | ||
153 | if (err) | ||
154 | goto exit_detach; | ||
155 | 101 | ||
156 | return 0; | 102 | return 0; |
157 | |||
158 | exit_detach: | ||
159 | i2c_detach_client(client); | ||
160 | exit_kfree: | ||
161 | kfree(data); | ||
162 | exit: | ||
163 | return err; | ||
164 | } | 103 | } |
165 | 104 | ||
166 | static int pca9539_detach_client(struct i2c_client *client) | 105 | static int pca9539_probe(struct i2c_client *client, |
106 | const struct i2c_device_id *id) | ||
167 | { | 107 | { |
168 | int err; | 108 | /* Register sysfs hooks */ |
109 | return sysfs_create_group(&client->dev.kobj, | ||
110 | &pca9539_defattr_group); | ||
111 | } | ||
169 | 112 | ||
113 | static int pca9539_remove(struct i2c_client *client) | ||
114 | { | ||
170 | sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); | 115 | sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); |
171 | |||
172 | if ((err = i2c_detach_client(client))) | ||
173 | return err; | ||
174 | |||
175 | kfree(i2c_get_clientdata(client)); | ||
176 | return 0; | 116 | return 0; |
177 | } | 117 | } |
178 | 118 | ||
119 | static const struct i2c_device_id pca9539_id[] = { | ||
120 | { "pca9539", 0 }, | ||
121 | { } | ||
122 | }; | ||
123 | |||
124 | static struct i2c_driver pca9539_driver = { | ||
125 | .driver = { | ||
126 | .name = "pca9539", | ||
127 | }, | ||
128 | .probe = pca9539_probe, | ||
129 | .remove = pca9539_remove, | ||
130 | .id_table = pca9539_id, | ||
131 | |||
132 | .detect = pca9539_detect, | ||
133 | .address_data = &addr_data, | ||
134 | }; | ||
135 | |||
179 | static int __init pca9539_init(void) | 136 | static int __init pca9539_init(void) |
180 | { | 137 | { |
181 | return i2c_add_driver(&pca9539_driver); | 138 | return i2c_add_driver(&pca9539_driver); |
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c index 1b3db2b3ada9..6ec309894c88 100644 --- a/drivers/i2c/chips/pcf8574.c +++ b/drivers/i2c/chips/pcf8574.c | |||
@@ -38,37 +38,19 @@ | |||
38 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
39 | #include <linux/i2c.h> | 39 | #include <linux/i2c.h> |
40 | 40 | ||
41 | /* Addresses to scan */ | 41 | /* Addresses to scan: none, device can't be detected */ |
42 | static const unsigned short normal_i2c[] = { | 42 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
43 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | ||
44 | 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, | ||
45 | I2C_CLIENT_END | ||
46 | }; | ||
47 | 43 | ||
48 | /* Insmod parameters */ | 44 | /* Insmod parameters */ |
49 | I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); | 45 | I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); |
50 | 46 | ||
51 | /* Each client has this additional data */ | 47 | /* Each client has this additional data */ |
52 | struct pcf8574_data { | 48 | struct pcf8574_data { |
53 | struct i2c_client client; | ||
54 | |||
55 | int write; /* Remember last written value */ | 49 | int write; /* Remember last written value */ |
56 | }; | 50 | }; |
57 | 51 | ||
58 | static int pcf8574_attach_adapter(struct i2c_adapter *adapter); | ||
59 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind); | ||
60 | static int pcf8574_detach_client(struct i2c_client *client); | ||
61 | static void pcf8574_init_client(struct i2c_client *client); | 52 | static void pcf8574_init_client(struct i2c_client *client); |
62 | 53 | ||
63 | /* This is the driver that will be inserted */ | ||
64 | static struct i2c_driver pcf8574_driver = { | ||
65 | .driver = { | ||
66 | .name = "pcf8574", | ||
67 | }, | ||
68 | .attach_adapter = pcf8574_attach_adapter, | ||
69 | .detach_client = pcf8574_detach_client, | ||
70 | }; | ||
71 | |||
72 | /* following are the sysfs callback functions */ | 54 | /* following are the sysfs callback functions */ |
73 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) | 55 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) |
74 | { | 56 | { |
@@ -119,41 +101,22 @@ static const struct attribute_group pcf8574_attr_group = { | |||
119 | * Real code | 101 | * Real code |
120 | */ | 102 | */ |
121 | 103 | ||
122 | static int pcf8574_attach_adapter(struct i2c_adapter *adapter) | 104 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
123 | { | 105 | static int pcf8574_detect(struct i2c_client *client, int kind, |
124 | return i2c_probe(adapter, &addr_data, pcf8574_detect); | 106 | struct i2c_board_info *info) |
125 | } | ||
126 | |||
127 | /* This function is called by i2c_probe */ | ||
128 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | ||
129 | { | 107 | { |
130 | struct i2c_client *client; | 108 | struct i2c_adapter *adapter = client->adapter; |
131 | struct pcf8574_data *data; | 109 | const char *client_name; |
132 | int err = 0; | ||
133 | const char *client_name = ""; | ||
134 | 110 | ||
135 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | 111 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
136 | goto exit; | 112 | return -ENODEV; |
137 | |||
138 | /* OK. For now, we presume we have a valid client. We now create the | ||
139 | client structure, even though we cannot fill it completely yet. */ | ||
140 | if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) { | ||
141 | err = -ENOMEM; | ||
142 | goto exit; | ||
143 | } | ||
144 | |||
145 | client = &data->client; | ||
146 | i2c_set_clientdata(client, data); | ||
147 | client->addr = address; | ||
148 | client->adapter = adapter; | ||
149 | client->driver = &pcf8574_driver; | ||
150 | 113 | ||
151 | /* Now, we would do the remaining detection. But the PCF8574 is plainly | 114 | /* Now, we would do the remaining detection. But the PCF8574 is plainly |
152 | impossible to detect! Stupid chip. */ | 115 | impossible to detect! Stupid chip. */ |
153 | 116 | ||
154 | /* Determine the chip type */ | 117 | /* Determine the chip type */ |
155 | if (kind <= 0) { | 118 | if (kind <= 0) { |
156 | if (address >= 0x38 && address <= 0x3f) | 119 | if (client->addr >= 0x38 && client->addr <= 0x3f) |
157 | kind = pcf8574a; | 120 | kind = pcf8574a; |
158 | else | 121 | else |
159 | kind = pcf8574; | 122 | kind = pcf8574; |
@@ -163,40 +126,43 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | |||
163 | client_name = "pcf8574a"; | 126 | client_name = "pcf8574a"; |
164 | else | 127 | else |
165 | client_name = "pcf8574"; | 128 | client_name = "pcf8574"; |
129 | strlcpy(info->type, client_name, I2C_NAME_SIZE); | ||
166 | 130 | ||
167 | /* Fill in the remaining client fields and put it into the global list */ | 131 | return 0; |
168 | strlcpy(client->name, client_name, I2C_NAME_SIZE); | 132 | } |
133 | |||
134 | static int pcf8574_probe(struct i2c_client *client, | ||
135 | const struct i2c_device_id *id) | ||
136 | { | ||
137 | struct pcf8574_data *data; | ||
138 | int err; | ||
139 | |||
140 | data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL); | ||
141 | if (!data) { | ||
142 | err = -ENOMEM; | ||
143 | goto exit; | ||
144 | } | ||
145 | |||
146 | i2c_set_clientdata(client, data); | ||
169 | 147 | ||
170 | /* Tell the I2C layer a new client has arrived */ | ||
171 | if ((err = i2c_attach_client(client))) | ||
172 | goto exit_free; | ||
173 | |||
174 | /* Initialize the PCF8574 chip */ | 148 | /* Initialize the PCF8574 chip */ |
175 | pcf8574_init_client(client); | 149 | pcf8574_init_client(client); |
176 | 150 | ||
177 | /* Register sysfs hooks */ | 151 | /* Register sysfs hooks */ |
178 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); | 152 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); |
179 | if (err) | 153 | if (err) |
180 | goto exit_detach; | 154 | goto exit_free; |
181 | return 0; | 155 | return 0; |
182 | 156 | ||
183 | exit_detach: | ||
184 | i2c_detach_client(client); | ||
185 | exit_free: | 157 | exit_free: |
186 | kfree(data); | 158 | kfree(data); |
187 | exit: | 159 | exit: |
188 | return err; | 160 | return err; |
189 | } | 161 | } |
190 | 162 | ||
191 | static int pcf8574_detach_client(struct i2c_client *client) | 163 | static int pcf8574_remove(struct i2c_client *client) |
192 | { | 164 | { |
193 | int err; | ||
194 | |||
195 | sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); | 165 | sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); |
196 | |||
197 | if ((err = i2c_detach_client(client))) | ||
198 | return err; | ||
199 | |||
200 | kfree(i2c_get_clientdata(client)); | 166 | kfree(i2c_get_clientdata(client)); |
201 | return 0; | 167 | return 0; |
202 | } | 168 | } |
@@ -208,6 +174,24 @@ static void pcf8574_init_client(struct i2c_client *client) | |||
208 | data->write = -EAGAIN; | 174 | data->write = -EAGAIN; |
209 | } | 175 | } |
210 | 176 | ||
177 | static const struct i2c_device_id pcf8574_id[] = { | ||
178 | { "pcf8574", 0 }, | ||
179 | { "pcf8574a", 0 }, | ||
180 | { } | ||
181 | }; | ||
182 | |||
183 | static struct i2c_driver pcf8574_driver = { | ||
184 | .driver = { | ||
185 | .name = "pcf8574", | ||
186 | }, | ||
187 | .probe = pcf8574_probe, | ||
188 | .remove = pcf8574_remove, | ||
189 | .id_table = pcf8574_id, | ||
190 | |||
191 | .detect = pcf8574_detect, | ||
192 | .address_data = &addr_data, | ||
193 | }; | ||
194 | |||
211 | static int __init pcf8574_init(void) | 195 | static int __init pcf8574_init(void) |
212 | { | 196 | { |
213 | return i2c_add_driver(&pcf8574_driver); | 197 | return i2c_add_driver(&pcf8574_driver); |
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c index 3ea08ac0bfa3..07fd7cb3c57d 100644 --- a/drivers/i2c/chips/pcf8575.c +++ b/drivers/i2c/chips/pcf8575.c | |||
@@ -32,11 +32,8 @@ | |||
32 | #include <linux/slab.h> /* kzalloc() */ | 32 | #include <linux/slab.h> /* kzalloc() */ |
33 | #include <linux/sysfs.h> /* sysfs_create_group() */ | 33 | #include <linux/sysfs.h> /* sysfs_create_group() */ |
34 | 34 | ||
35 | /* Addresses to scan */ | 35 | /* Addresses to scan: none, device can't be detected */ |
36 | static const unsigned short normal_i2c[] = { | 36 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
37 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | ||
38 | I2C_CLIENT_END | ||
39 | }; | ||
40 | 37 | ||
41 | /* Insmod parameters */ | 38 | /* Insmod parameters */ |
42 | I2C_CLIENT_INSMOD; | 39 | I2C_CLIENT_INSMOD; |
@@ -44,24 +41,9 @@ I2C_CLIENT_INSMOD; | |||
44 | 41 | ||
45 | /* Each client has this additional data */ | 42 | /* Each client has this additional data */ |
46 | struct pcf8575_data { | 43 | struct pcf8575_data { |
47 | struct i2c_client client; | ||
48 | int write; /* last written value, or error code */ | 44 | int write; /* last written value, or error code */ |
49 | }; | 45 | }; |
50 | 46 | ||
51 | static int pcf8575_attach_adapter(struct i2c_adapter *adapter); | ||
52 | static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind); | ||
53 | static int pcf8575_detach_client(struct i2c_client *client); | ||
54 | |||
55 | /* This is the driver that will be inserted */ | ||
56 | static struct i2c_driver pcf8575_driver = { | ||
57 | .driver = { | ||
58 | .owner = THIS_MODULE, | ||
59 | .name = "pcf8575", | ||
60 | }, | ||
61 | .attach_adapter = pcf8575_attach_adapter, | ||
62 | .detach_client = pcf8575_detach_client, | ||
63 | }; | ||
64 | |||
65 | /* following are the sysfs callback functions */ | 47 | /* following are the sysfs callback functions */ |
66 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, | 48 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, |
67 | char *buf) | 49 | char *buf) |
@@ -126,75 +108,77 @@ static const struct attribute_group pcf8575_attr_group = { | |||
126 | * Real code | 108 | * Real code |
127 | */ | 109 | */ |
128 | 110 | ||
129 | static int pcf8575_attach_adapter(struct i2c_adapter *adapter) | 111 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
112 | static int pcf8575_detect(struct i2c_client *client, int kind, | ||
113 | struct i2c_board_info *info) | ||
130 | { | 114 | { |
131 | return i2c_probe(adapter, &addr_data, pcf8575_detect); | 115 | struct i2c_adapter *adapter = client->adapter; |
116 | |||
117 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) | ||
118 | return -ENODEV; | ||
119 | |||
120 | /* This is the place to detect whether the chip at the specified | ||
121 | address really is a PCF8575 chip. However, there is no method known | ||
122 | to detect whether an I2C chip is a PCF8575 or any other I2C chip. */ | ||
123 | |||
124 | strlcpy(info->type, "pcf8575", I2C_NAME_SIZE); | ||
125 | |||
126 | return 0; | ||
132 | } | 127 | } |
133 | 128 | ||
134 | /* This function is called by i2c_probe */ | 129 | static int pcf8575_probe(struct i2c_client *client, |
135 | static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind) | 130 | const struct i2c_device_id *id) |
136 | { | 131 | { |
137 | struct i2c_client *client; | ||
138 | struct pcf8575_data *data; | 132 | struct pcf8575_data *data; |
139 | int err = 0; | 133 | int err; |
140 | |||
141 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) | ||
142 | goto exit; | ||
143 | 134 | ||
144 | /* OK. For now, we presume we have a valid client. We now create the | ||
145 | client structure, even though we cannot fill it completely yet. */ | ||
146 | data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); | 135 | data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); |
147 | if (!data) { | 136 | if (!data) { |
148 | err = -ENOMEM; | 137 | err = -ENOMEM; |
149 | goto exit; | 138 | goto exit; |
150 | } | 139 | } |
151 | 140 | ||
152 | client = &data->client; | ||
153 | i2c_set_clientdata(client, data); | 141 | i2c_set_clientdata(client, data); |
154 | client->addr = address; | ||
155 | client->adapter = adapter; | ||
156 | client->driver = &pcf8575_driver; | ||
157 | strlcpy(client->name, "pcf8575", I2C_NAME_SIZE); | ||
158 | data->write = -EAGAIN; | 142 | data->write = -EAGAIN; |
159 | 143 | ||
160 | /* This is the place to detect whether the chip at the specified | ||
161 | address really is a PCF8575 chip. However, there is no method known | ||
162 | to detect whether an I2C chip is a PCF8575 or any other I2C chip. */ | ||
163 | |||
164 | /* Tell the I2C layer a new client has arrived */ | ||
165 | err = i2c_attach_client(client); | ||
166 | if (err) | ||
167 | goto exit_free; | ||
168 | |||
169 | /* Register sysfs hooks */ | 144 | /* Register sysfs hooks */ |
170 | err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); | 145 | err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); |
171 | if (err) | 146 | if (err) |
172 | goto exit_detach; | 147 | goto exit_free; |
173 | 148 | ||
174 | return 0; | 149 | return 0; |
175 | 150 | ||
176 | exit_detach: | ||
177 | i2c_detach_client(client); | ||
178 | exit_free: | 151 | exit_free: |
179 | kfree(data); | 152 | kfree(data); |
180 | exit: | 153 | exit: |
181 | return err; | 154 | return err; |
182 | } | 155 | } |
183 | 156 | ||
184 | static int pcf8575_detach_client(struct i2c_client *client) | 157 | static int pcf8575_remove(struct i2c_client *client) |
185 | { | 158 | { |
186 | int err; | ||
187 | |||
188 | sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); | 159 | sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); |
189 | |||
190 | err = i2c_detach_client(client); | ||
191 | if (err) | ||
192 | return err; | ||
193 | |||
194 | kfree(i2c_get_clientdata(client)); | 160 | kfree(i2c_get_clientdata(client)); |
195 | return 0; | 161 | return 0; |
196 | } | 162 | } |
197 | 163 | ||
164 | static const struct i2c_device_id pcf8575_id[] = { | ||
165 | { "pcf8575", 0 }, | ||
166 | { } | ||
167 | }; | ||
168 | |||
169 | static struct i2c_driver pcf8575_driver = { | ||
170 | .driver = { | ||
171 | .owner = THIS_MODULE, | ||
172 | .name = "pcf8575", | ||
173 | }, | ||
174 | .probe = pcf8575_probe, | ||
175 | .remove = pcf8575_remove, | ||
176 | .id_table = pcf8575_id, | ||
177 | |||
178 | .detect = pcf8575_detect, | ||
179 | .address_data = &addr_data, | ||
180 | }; | ||
181 | |||
198 | static int __init pcf8575_init(void) | 182 | static int __init pcf8575_init(void) |
199 | { | 183 | { |
200 | return i2c_add_driver(&pcf8575_driver); | 184 | return i2c_add_driver(&pcf8575_driver); |
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c index db735379f22f..16ce3e193776 100644 --- a/drivers/i2c/chips/pcf8591.c +++ b/drivers/i2c/chips/pcf8591.c | |||
@@ -72,28 +72,15 @@ MODULE_PARM_DESC(input_mode, | |||
72 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) | 72 | #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) |
73 | 73 | ||
74 | struct pcf8591_data { | 74 | struct pcf8591_data { |
75 | struct i2c_client client; | ||
76 | struct mutex update_lock; | 75 | struct mutex update_lock; |
77 | 76 | ||
78 | u8 control; | 77 | u8 control; |
79 | u8 aout; | 78 | u8 aout; |
80 | }; | 79 | }; |
81 | 80 | ||
82 | static int pcf8591_attach_adapter(struct i2c_adapter *adapter); | ||
83 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind); | ||
84 | static int pcf8591_detach_client(struct i2c_client *client); | ||
85 | static void pcf8591_init_client(struct i2c_client *client); | 81 | static void pcf8591_init_client(struct i2c_client *client); |
86 | static int pcf8591_read_channel(struct device *dev, int channel); | 82 | static int pcf8591_read_channel(struct device *dev, int channel); |
87 | 83 | ||
88 | /* This is the driver that will be inserted */ | ||
89 | static struct i2c_driver pcf8591_driver = { | ||
90 | .driver = { | ||
91 | .name = "pcf8591", | ||
92 | }, | ||
93 | .attach_adapter = pcf8591_attach_adapter, | ||
94 | .detach_client = pcf8591_detach_client, | ||
95 | }; | ||
96 | |||
97 | /* following are the sysfs callback functions */ | 84 | /* following are the sysfs callback functions */ |
98 | #define show_in_channel(channel) \ | 85 | #define show_in_channel(channel) \ |
99 | static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ | 86 | static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
@@ -180,58 +167,46 @@ static const struct attribute_group pcf8591_attr_group_opt = { | |||
180 | /* | 167 | /* |
181 | * Real code | 168 | * Real code |
182 | */ | 169 | */ |
183 | static int pcf8591_attach_adapter(struct i2c_adapter *adapter) | ||
184 | { | ||
185 | return i2c_probe(adapter, &addr_data, pcf8591_detect); | ||
186 | } | ||
187 | 170 | ||
188 | /* This function is called by i2c_probe */ | 171 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
189 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | 172 | static int pcf8591_detect(struct i2c_client *client, int kind, |
173 | struct i2c_board_info *info) | ||
190 | { | 174 | { |
191 | struct i2c_client *client; | 175 | struct i2c_adapter *adapter = client->adapter; |
192 | struct pcf8591_data *data; | ||
193 | int err = 0; | ||
194 | 176 | ||
195 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | 177 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE |
196 | | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | 178 | | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
197 | goto exit; | 179 | return -ENODEV; |
180 | |||
181 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | ||
182 | impossible to detect! Stupid chip. */ | ||
183 | |||
184 | strlcpy(info->type, "pcf8591", I2C_NAME_SIZE); | ||
185 | |||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | static int pcf8591_probe(struct i2c_client *client, | ||
190 | const struct i2c_device_id *id) | ||
191 | { | ||
192 | struct pcf8591_data *data; | ||
193 | int err; | ||
198 | 194 | ||
199 | /* OK. For now, we presume we have a valid client. We now create the | ||
200 | client structure, even though we cannot fill it completely yet. */ | ||
201 | if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { | 195 | if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { |
202 | err = -ENOMEM; | 196 | err = -ENOMEM; |
203 | goto exit; | 197 | goto exit; |
204 | } | 198 | } |
205 | 199 | ||
206 | client = &data->client; | ||
207 | i2c_set_clientdata(client, data); | 200 | i2c_set_clientdata(client, data); |
208 | client->addr = address; | ||
209 | client->adapter = adapter; | ||
210 | client->driver = &pcf8591_driver; | ||
211 | |||
212 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | ||
213 | impossible to detect! Stupid chip. */ | ||
214 | |||
215 | /* Determine the chip type - only one kind supported! */ | ||
216 | if (kind <= 0) | ||
217 | kind = pcf8591; | ||
218 | |||
219 | /* Fill in the remaining client fields and put it into the global | ||
220 | list */ | ||
221 | strlcpy(client->name, "pcf8591", I2C_NAME_SIZE); | ||
222 | mutex_init(&data->update_lock); | 201 | mutex_init(&data->update_lock); |
223 | 202 | ||
224 | /* Tell the I2C layer a new client has arrived */ | ||
225 | if ((err = i2c_attach_client(client))) | ||
226 | goto exit_kfree; | ||
227 | |||
228 | /* Initialize the PCF8591 chip */ | 203 | /* Initialize the PCF8591 chip */ |
229 | pcf8591_init_client(client); | 204 | pcf8591_init_client(client); |
230 | 205 | ||
231 | /* Register sysfs hooks */ | 206 | /* Register sysfs hooks */ |
232 | err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); | 207 | err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); |
233 | if (err) | 208 | if (err) |
234 | goto exit_detach; | 209 | goto exit_kfree; |
235 | 210 | ||
236 | /* Register input2 if not in "two differential inputs" mode */ | 211 | /* Register input2 if not in "two differential inputs" mode */ |
237 | if (input_mode != 3) { | 212 | if (input_mode != 3) { |
@@ -252,24 +227,16 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | |||
252 | exit_sysfs_remove: | 227 | exit_sysfs_remove: |
253 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); | 228 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
254 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); | 229 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
255 | exit_detach: | ||
256 | i2c_detach_client(client); | ||
257 | exit_kfree: | 230 | exit_kfree: |
258 | kfree(data); | 231 | kfree(data); |
259 | exit: | 232 | exit: |
260 | return err; | 233 | return err; |
261 | } | 234 | } |
262 | 235 | ||
263 | static int pcf8591_detach_client(struct i2c_client *client) | 236 | static int pcf8591_remove(struct i2c_client *client) |
264 | { | 237 | { |
265 | int err; | ||
266 | |||
267 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); | 238 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
268 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); | 239 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
269 | |||
270 | if ((err = i2c_detach_client(client))) | ||
271 | return err; | ||
272 | |||
273 | kfree(i2c_get_clientdata(client)); | 240 | kfree(i2c_get_clientdata(client)); |
274 | return 0; | 241 | return 0; |
275 | } | 242 | } |
@@ -316,6 +283,25 @@ static int pcf8591_read_channel(struct device *dev, int channel) | |||
316 | return (10 * value); | 283 | return (10 * value); |
317 | } | 284 | } |
318 | 285 | ||
286 | static const struct i2c_device_id pcf8591_id[] = { | ||
287 | { "pcf8591", 0 }, | ||
288 | { } | ||
289 | }; | ||
290 | MODULE_DEVICE_TABLE(i2c, pcf8591_id); | ||
291 | |||
292 | static struct i2c_driver pcf8591_driver = { | ||
293 | .driver = { | ||
294 | .name = "pcf8591", | ||
295 | }, | ||
296 | .probe = pcf8591_probe, | ||
297 | .remove = pcf8591_remove, | ||
298 | .id_table = pcf8591_id, | ||
299 | |||
300 | .class = I2C_CLASS_HWMON, /* Nearest choice */ | ||
301 | .detect = pcf8591_detect, | ||
302 | .address_data = &addr_data, | ||
303 | }; | ||
304 | |||
319 | static int __init pcf8591_init(void) | 305 | static int __init pcf8591_init(void) |
320 | { | 306 | { |
321 | if (input_mode < 0 || input_mode > 3) { | 307 | if (input_mode < 0 || input_mode > 3) { |