diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2010-05-22 02:36:56 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-05-22 02:36:56 -0400 |
commit | cf9b59e9d3e008591d1f54830f570982bb307a0d (patch) | |
tree | 113478ce8fd8c832ba726ffdf59b82cb46356476 /drivers/i2c/i2c-core.c | |
parent | 44504b2bebf8b5823c59484e73096a7d6574471d (diff) | |
parent | f4b87dee923342505e1ddba8d34ce9de33e75050 (diff) |
Merge remote branch 'origin' into secretlab/next-devicetree
Merging in current state of Linus' tree to deal with merge conflicts and
build failures in vio.c after merge.
Conflicts:
drivers/i2c/busses/i2c-cpm.c
drivers/i2c/busses/i2c-mpc.c
drivers/net/gianfar.c
Also fixed up one line in arch/powerpc/kernel/vio.c to use the
correct node pointer.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 319 |
1 files changed, 182 insertions, 137 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 4099b2b8c392..e0f833cca3f1 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -40,12 +40,11 @@ | |||
40 | #include "i2c-core.h" | 40 | #include "i2c-core.h" |
41 | 41 | ||
42 | 42 | ||
43 | /* core_lock protects i2c_adapter_idr, userspace_devices, and guarantees | 43 | /* core_lock protects i2c_adapter_idr, and guarantees |
44 | that device detection, deletion of detected devices, and attach_adapter | 44 | that device detection, deletion of detected devices, and attach_adapter |
45 | and detach_adapter calls are serialized */ | 45 | and detach_adapter calls are serialized */ |
46 | static DEFINE_MUTEX(core_lock); | 46 | static DEFINE_MUTEX(core_lock); |
47 | static DEFINE_IDR(i2c_adapter_idr); | 47 | static DEFINE_IDR(i2c_adapter_idr); |
48 | static LIST_HEAD(userspace_devices); | ||
49 | 48 | ||
50 | static struct device_type i2c_client_type; | 49 | static struct device_type i2c_client_type; |
51 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr); | 50 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr); |
@@ -117,8 +116,10 @@ static int i2c_device_probe(struct device *dev) | |||
117 | dev_dbg(dev, "probe\n"); | 116 | dev_dbg(dev, "probe\n"); |
118 | 117 | ||
119 | status = driver->probe(client, i2c_match_id(driver->id_table, client)); | 118 | status = driver->probe(client, i2c_match_id(driver->id_table, client)); |
120 | if (status) | 119 | if (status) { |
121 | client->driver = NULL; | 120 | client->driver = NULL; |
121 | i2c_set_clientdata(client, NULL); | ||
122 | } | ||
122 | return status; | 123 | return status; |
123 | } | 124 | } |
124 | 125 | ||
@@ -139,8 +140,10 @@ static int i2c_device_remove(struct device *dev) | |||
139 | dev->driver = NULL; | 140 | dev->driver = NULL; |
140 | status = 0; | 141 | status = 0; |
141 | } | 142 | } |
142 | if (status == 0) | 143 | if (status == 0) { |
143 | client->driver = NULL; | 144 | client->driver = NULL; |
145 | i2c_set_clientdata(client, NULL); | ||
146 | } | ||
144 | return status; | 147 | return status; |
145 | } | 148 | } |
146 | 149 | ||
@@ -156,106 +159,130 @@ static void i2c_device_shutdown(struct device *dev) | |||
156 | driver->shutdown(client); | 159 | driver->shutdown(client); |
157 | } | 160 | } |
158 | 161 | ||
159 | #ifdef CONFIG_SUSPEND | 162 | #ifdef CONFIG_PM_SLEEP |
160 | static int i2c_device_pm_suspend(struct device *dev) | 163 | static int i2c_legacy_suspend(struct device *dev, pm_message_t mesg) |
161 | { | 164 | { |
162 | const struct dev_pm_ops *pm; | 165 | struct i2c_client *client = i2c_verify_client(dev); |
166 | struct i2c_driver *driver; | ||
163 | 167 | ||
164 | if (!dev->driver) | 168 | if (!client || !dev->driver) |
165 | return 0; | 169 | return 0; |
166 | pm = dev->driver->pm; | 170 | driver = to_i2c_driver(dev->driver); |
167 | if (!pm || !pm->suspend) | 171 | if (!driver->suspend) |
168 | return 0; | 172 | return 0; |
169 | return pm->suspend(dev); | 173 | return driver->suspend(client, mesg); |
170 | } | 174 | } |
171 | 175 | ||
172 | static int i2c_device_pm_resume(struct device *dev) | 176 | static int i2c_legacy_resume(struct device *dev) |
173 | { | 177 | { |
174 | const struct dev_pm_ops *pm; | 178 | struct i2c_client *client = i2c_verify_client(dev); |
179 | struct i2c_driver *driver; | ||
175 | 180 | ||
176 | if (!dev->driver) | 181 | if (!client || !dev->driver) |
177 | return 0; | 182 | return 0; |
178 | pm = dev->driver->pm; | 183 | driver = to_i2c_driver(dev->driver); |
179 | if (!pm || !pm->resume) | 184 | if (!driver->resume) |
180 | return 0; | 185 | return 0; |
181 | return pm->resume(dev); | 186 | return driver->resume(client); |
182 | } | 187 | } |
183 | #else | ||
184 | #define i2c_device_pm_suspend NULL | ||
185 | #define i2c_device_pm_resume NULL | ||
186 | #endif | ||
187 | 188 | ||
188 | #ifdef CONFIG_PM_RUNTIME | 189 | static int i2c_device_pm_suspend(struct device *dev) |
189 | static int i2c_device_runtime_suspend(struct device *dev) | ||
190 | { | 190 | { |
191 | const struct dev_pm_ops *pm; | 191 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
192 | 192 | ||
193 | if (!dev->driver) | 193 | if (pm_runtime_suspended(dev)) |
194 | return 0; | ||
195 | pm = dev->driver->pm; | ||
196 | if (!pm || !pm->runtime_suspend) | ||
197 | return 0; | 194 | return 0; |
198 | return pm->runtime_suspend(dev); | ||
199 | } | ||
200 | 195 | ||
201 | static int i2c_device_runtime_resume(struct device *dev) | 196 | if (pm) |
202 | { | 197 | return pm->suspend ? pm->suspend(dev) : 0; |
203 | const struct dev_pm_ops *pm; | ||
204 | 198 | ||
205 | if (!dev->driver) | 199 | return i2c_legacy_suspend(dev, PMSG_SUSPEND); |
206 | return 0; | ||
207 | pm = dev->driver->pm; | ||
208 | if (!pm || !pm->runtime_resume) | ||
209 | return 0; | ||
210 | return pm->runtime_resume(dev); | ||
211 | } | 200 | } |
212 | 201 | ||
213 | static int i2c_device_runtime_idle(struct device *dev) | 202 | static int i2c_device_pm_resume(struct device *dev) |
214 | { | 203 | { |
215 | const struct dev_pm_ops *pm = NULL; | 204 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
216 | int ret; | 205 | int ret; |
217 | 206 | ||
218 | if (dev->driver) | 207 | if (pm) |
219 | pm = dev->driver->pm; | 208 | ret = pm->resume ? pm->resume(dev) : 0; |
220 | if (pm && pm->runtime_idle) { | 209 | else |
221 | ret = pm->runtime_idle(dev); | 210 | ret = i2c_legacy_resume(dev); |
222 | if (ret) | 211 | |
223 | return ret; | 212 | if (!ret) { |
213 | pm_runtime_disable(dev); | ||
214 | pm_runtime_set_active(dev); | ||
215 | pm_runtime_enable(dev); | ||
224 | } | 216 | } |
225 | 217 | ||
226 | return pm_runtime_suspend(dev); | 218 | return ret; |
227 | } | 219 | } |
228 | #else | ||
229 | #define i2c_device_runtime_suspend NULL | ||
230 | #define i2c_device_runtime_resume NULL | ||
231 | #define i2c_device_runtime_idle NULL | ||
232 | #endif | ||
233 | 220 | ||
234 | static int i2c_device_suspend(struct device *dev, pm_message_t mesg) | 221 | static int i2c_device_pm_freeze(struct device *dev) |
235 | { | 222 | { |
236 | struct i2c_client *client = i2c_verify_client(dev); | 223 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
237 | struct i2c_driver *driver; | ||
238 | 224 | ||
239 | if (!client || !dev->driver) | 225 | if (pm_runtime_suspended(dev)) |
240 | return 0; | 226 | return 0; |
241 | driver = to_i2c_driver(dev->driver); | 227 | |
242 | if (!driver->suspend) | 228 | if (pm) |
243 | return 0; | 229 | return pm->freeze ? pm->freeze(dev) : 0; |
244 | return driver->suspend(client, mesg); | 230 | |
231 | return i2c_legacy_suspend(dev, PMSG_FREEZE); | ||
245 | } | 232 | } |
246 | 233 | ||
247 | static int i2c_device_resume(struct device *dev) | 234 | static int i2c_device_pm_thaw(struct device *dev) |
248 | { | 235 | { |
249 | struct i2c_client *client = i2c_verify_client(dev); | 236 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
250 | struct i2c_driver *driver; | ||
251 | 237 | ||
252 | if (!client || !dev->driver) | 238 | if (pm_runtime_suspended(dev)) |
253 | return 0; | 239 | return 0; |
254 | driver = to_i2c_driver(dev->driver); | 240 | |
255 | if (!driver->resume) | 241 | if (pm) |
242 | return pm->thaw ? pm->thaw(dev) : 0; | ||
243 | |||
244 | return i2c_legacy_resume(dev); | ||
245 | } | ||
246 | |||
247 | static int i2c_device_pm_poweroff(struct device *dev) | ||
248 | { | ||
249 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
250 | |||
251 | if (pm_runtime_suspended(dev)) | ||
256 | return 0; | 252 | return 0; |
257 | return driver->resume(client); | 253 | |
254 | if (pm) | ||
255 | return pm->poweroff ? pm->poweroff(dev) : 0; | ||
256 | |||
257 | return i2c_legacy_suspend(dev, PMSG_HIBERNATE); | ||
258 | } | ||
259 | |||
260 | static int i2c_device_pm_restore(struct device *dev) | ||
261 | { | ||
262 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
263 | int ret; | ||
264 | |||
265 | if (pm) | ||
266 | ret = pm->restore ? pm->restore(dev) : 0; | ||
267 | else | ||
268 | ret = i2c_legacy_resume(dev); | ||
269 | |||
270 | if (!ret) { | ||
271 | pm_runtime_disable(dev); | ||
272 | pm_runtime_set_active(dev); | ||
273 | pm_runtime_enable(dev); | ||
274 | } | ||
275 | |||
276 | return ret; | ||
258 | } | 277 | } |
278 | #else /* !CONFIG_PM_SLEEP */ | ||
279 | #define i2c_device_pm_suspend NULL | ||
280 | #define i2c_device_pm_resume NULL | ||
281 | #define i2c_device_pm_freeze NULL | ||
282 | #define i2c_device_pm_thaw NULL | ||
283 | #define i2c_device_pm_poweroff NULL | ||
284 | #define i2c_device_pm_restore NULL | ||
285 | #endif /* !CONFIG_PM_SLEEP */ | ||
259 | 286 | ||
260 | static void i2c_client_dev_release(struct device *dev) | 287 | static void i2c_client_dev_release(struct device *dev) |
261 | { | 288 | { |
@@ -298,9 +325,15 @@ static const struct attribute_group *i2c_dev_attr_groups[] = { | |||
298 | static const struct dev_pm_ops i2c_device_pm_ops = { | 325 | static const struct dev_pm_ops i2c_device_pm_ops = { |
299 | .suspend = i2c_device_pm_suspend, | 326 | .suspend = i2c_device_pm_suspend, |
300 | .resume = i2c_device_pm_resume, | 327 | .resume = i2c_device_pm_resume, |
301 | .runtime_suspend = i2c_device_runtime_suspend, | 328 | .freeze = i2c_device_pm_freeze, |
302 | .runtime_resume = i2c_device_runtime_resume, | 329 | .thaw = i2c_device_pm_thaw, |
303 | .runtime_idle = i2c_device_runtime_idle, | 330 | .poweroff = i2c_device_pm_poweroff, |
331 | .restore = i2c_device_pm_restore, | ||
332 | SET_RUNTIME_PM_OPS( | ||
333 | pm_generic_runtime_suspend, | ||
334 | pm_generic_runtime_resume, | ||
335 | pm_generic_runtime_idle | ||
336 | ) | ||
304 | }; | 337 | }; |
305 | 338 | ||
306 | struct bus_type i2c_bus_type = { | 339 | struct bus_type i2c_bus_type = { |
@@ -309,8 +342,6 @@ struct bus_type i2c_bus_type = { | |||
309 | .probe = i2c_device_probe, | 342 | .probe = i2c_device_probe, |
310 | .remove = i2c_device_remove, | 343 | .remove = i2c_device_remove, |
311 | .shutdown = i2c_device_shutdown, | 344 | .shutdown = i2c_device_shutdown, |
312 | .suspend = i2c_device_suspend, | ||
313 | .resume = i2c_device_resume, | ||
314 | .pm = &i2c_device_pm_ops, | 345 | .pm = &i2c_device_pm_ops, |
315 | }; | 346 | }; |
316 | EXPORT_SYMBOL_GPL(i2c_bus_type); | 347 | EXPORT_SYMBOL_GPL(i2c_bus_type); |
@@ -541,9 +572,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | |||
541 | return -EEXIST; | 572 | return -EEXIST; |
542 | 573 | ||
543 | /* Keep track of the added device */ | 574 | /* Keep track of the added device */ |
544 | mutex_lock(&core_lock); | 575 | i2c_lock_adapter(adap); |
545 | list_add_tail(&client->detected, &userspace_devices); | 576 | list_add_tail(&client->detected, &adap->userspace_clients); |
546 | mutex_unlock(&core_lock); | 577 | i2c_unlock_adapter(adap); |
547 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", | 578 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", |
548 | info.type, info.addr); | 579 | info.type, info.addr); |
549 | 580 | ||
@@ -582,9 +613,10 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
582 | 613 | ||
583 | /* Make sure the device was added through sysfs */ | 614 | /* Make sure the device was added through sysfs */ |
584 | res = -ENOENT; | 615 | res = -ENOENT; |
585 | mutex_lock(&core_lock); | 616 | i2c_lock_adapter(adap); |
586 | list_for_each_entry_safe(client, next, &userspace_devices, detected) { | 617 | list_for_each_entry_safe(client, next, &adap->userspace_clients, |
587 | if (client->addr == addr && client->adapter == adap) { | 618 | detected) { |
619 | if (client->addr == addr) { | ||
588 | dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", | 620 | dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", |
589 | "delete_device", client->name, client->addr); | 621 | "delete_device", client->name, client->addr); |
590 | 622 | ||
@@ -594,7 +626,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
594 | break; | 626 | break; |
595 | } | 627 | } |
596 | } | 628 | } |
597 | mutex_unlock(&core_lock); | 629 | i2c_unlock_adapter(adap); |
598 | 630 | ||
599 | if (res < 0) | 631 | if (res < 0) |
600 | dev_err(dev, "%s: Can't find device in list\n", | 632 | dev_err(dev, "%s: Can't find device in list\n", |
@@ -676,6 +708,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
676 | } | 708 | } |
677 | 709 | ||
678 | rt_mutex_init(&adap->bus_lock); | 710 | rt_mutex_init(&adap->bus_lock); |
711 | INIT_LIST_HEAD(&adap->userspace_clients); | ||
679 | 712 | ||
680 | /* Set default timeout to 1 second if not already set */ | 713 | /* Set default timeout to 1 second if not already set */ |
681 | if (adap->timeout == 0) | 714 | if (adap->timeout == 0) |
@@ -878,14 +911,15 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
878 | return res; | 911 | return res; |
879 | 912 | ||
880 | /* Remove devices instantiated from sysfs */ | 913 | /* Remove devices instantiated from sysfs */ |
881 | list_for_each_entry_safe(client, next, &userspace_devices, detected) { | 914 | i2c_lock_adapter(adap); |
882 | if (client->adapter == adap) { | 915 | list_for_each_entry_safe(client, next, &adap->userspace_clients, |
883 | dev_dbg(&adap->dev, "Removing %s at 0x%x\n", | 916 | detected) { |
884 | client->name, client->addr); | 917 | dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, |
885 | list_del(&client->detected); | 918 | client->addr); |
886 | i2c_unregister_device(client); | 919 | list_del(&client->detected); |
887 | } | 920 | i2c_unregister_device(client); |
888 | } | 921 | } |
922 | i2c_unlock_adapter(adap); | ||
889 | 923 | ||
890 | /* Detach any active clients. This can't fail, thus we do not | 924 | /* Detach any active clients. This can't fail, thus we do not |
891 | checking the returned value. */ | 925 | checking the returned value. */ |
@@ -1190,10 +1224,10 @@ EXPORT_SYMBOL(i2c_transfer); | |||
1190 | * | 1224 | * |
1191 | * Returns negative errno, or else the number of bytes written. | 1225 | * Returns negative errno, or else the number of bytes written. |
1192 | */ | 1226 | */ |
1193 | int i2c_master_send(struct i2c_client *client,const char *buf ,int count) | 1227 | int i2c_master_send(struct i2c_client *client, const char *buf, int count) |
1194 | { | 1228 | { |
1195 | int ret; | 1229 | int ret; |
1196 | struct i2c_adapter *adap=client->adapter; | 1230 | struct i2c_adapter *adap = client->adapter; |
1197 | struct i2c_msg msg; | 1231 | struct i2c_msg msg; |
1198 | 1232 | ||
1199 | msg.addr = client->addr; | 1233 | msg.addr = client->addr; |
@@ -1217,9 +1251,9 @@ EXPORT_SYMBOL(i2c_master_send); | |||
1217 | * | 1251 | * |
1218 | * Returns negative errno, or else the number of bytes read. | 1252 | * Returns negative errno, or else the number of bytes read. |
1219 | */ | 1253 | */ |
1220 | int i2c_master_recv(struct i2c_client *client, char *buf ,int count) | 1254 | int i2c_master_recv(struct i2c_client *client, char *buf, int count) |
1221 | { | 1255 | { |
1222 | struct i2c_adapter *adap=client->adapter; | 1256 | struct i2c_adapter *adap = client->adapter; |
1223 | struct i2c_msg msg; | 1257 | struct i2c_msg msg; |
1224 | int ret; | 1258 | int ret; |
1225 | 1259 | ||
@@ -1263,12 +1297,23 @@ static int i2c_detect_address(struct i2c_client *temp_client, | |||
1263 | return 0; | 1297 | return 0; |
1264 | 1298 | ||
1265 | /* Make sure there is something at this address */ | 1299 | /* Make sure there is something at this address */ |
1266 | if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0) | 1300 | if (addr == 0x73 && (adapter->class & I2C_CLASS_HWMON)) { |
1267 | return 0; | 1301 | /* Special probe for FSC hwmon chips */ |
1302 | union i2c_smbus_data dummy; | ||
1268 | 1303 | ||
1269 | /* Prevent 24RF08 corruption */ | 1304 | if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_READ, 0, |
1270 | if ((addr & ~0x0f) == 0x50) | 1305 | I2C_SMBUS_BYTE_DATA, &dummy) < 0) |
1271 | i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL); | 1306 | return 0; |
1307 | } else { | ||
1308 | if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0, | ||
1309 | I2C_SMBUS_QUICK, NULL) < 0) | ||
1310 | return 0; | ||
1311 | |||
1312 | /* Prevent 24RF08 corruption */ | ||
1313 | if ((addr & ~0x0f) == 0x50) | ||
1314 | i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0, | ||
1315 | I2C_SMBUS_QUICK, NULL); | ||
1316 | } | ||
1272 | 1317 | ||
1273 | /* Finally call the custom detection function */ | 1318 | /* Finally call the custom detection function */ |
1274 | memset(&info, 0, sizeof(struct i2c_board_info)); | 1319 | memset(&info, 0, sizeof(struct i2c_board_info)); |
@@ -1410,7 +1455,7 @@ i2c_new_probed_device(struct i2c_adapter *adap, | |||
1410 | } | 1455 | } |
1411 | EXPORT_SYMBOL_GPL(i2c_new_probed_device); | 1456 | EXPORT_SYMBOL_GPL(i2c_new_probed_device); |
1412 | 1457 | ||
1413 | struct i2c_adapter* i2c_get_adapter(int id) | 1458 | struct i2c_adapter *i2c_get_adapter(int id) |
1414 | { | 1459 | { |
1415 | struct i2c_adapter *adapter; | 1460 | struct i2c_adapter *adapter; |
1416 | 1461 | ||
@@ -1437,7 +1482,7 @@ static u8 crc8(u16 data) | |||
1437 | { | 1482 | { |
1438 | int i; | 1483 | int i; |
1439 | 1484 | ||
1440 | for(i = 0; i < 8; i++) { | 1485 | for (i = 0; i < 8; i++) { |
1441 | if (data & 0x8000) | 1486 | if (data & 0x8000) |
1442 | data = data ^ POLY; | 1487 | data = data ^ POLY; |
1443 | data = data << 1; | 1488 | data = data << 1; |
@@ -1450,7 +1495,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) | |||
1450 | { | 1495 | { |
1451 | int i; | 1496 | int i; |
1452 | 1497 | ||
1453 | for(i = 0; i < count; i++) | 1498 | for (i = 0; i < count; i++) |
1454 | crc = crc8((crc ^ p[i]) << 8); | 1499 | crc = crc8((crc ^ p[i]) << 8); |
1455 | return crc; | 1500 | return crc; |
1456 | } | 1501 | } |
@@ -1520,7 +1565,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte); | |||
1520 | */ | 1565 | */ |
1521 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) | 1566 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) |
1522 | { | 1567 | { |
1523 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1568 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1524 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | 1569 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); |
1525 | } | 1570 | } |
1526 | EXPORT_SYMBOL(i2c_smbus_write_byte); | 1571 | EXPORT_SYMBOL(i2c_smbus_write_byte); |
@@ -1558,9 +1603,9 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) | |||
1558 | { | 1603 | { |
1559 | union i2c_smbus_data data; | 1604 | union i2c_smbus_data data; |
1560 | data.byte = value; | 1605 | data.byte = value; |
1561 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1606 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1562 | I2C_SMBUS_WRITE,command, | 1607 | I2C_SMBUS_WRITE, command, |
1563 | I2C_SMBUS_BYTE_DATA,&data); | 1608 | I2C_SMBUS_BYTE_DATA, &data); |
1564 | } | 1609 | } |
1565 | EXPORT_SYMBOL(i2c_smbus_write_byte_data); | 1610 | EXPORT_SYMBOL(i2c_smbus_write_byte_data); |
1566 | 1611 | ||
@@ -1597,9 +1642,9 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | |||
1597 | { | 1642 | { |
1598 | union i2c_smbus_data data; | 1643 | union i2c_smbus_data data; |
1599 | data.word = value; | 1644 | data.word = value; |
1600 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1645 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1601 | I2C_SMBUS_WRITE,command, | 1646 | I2C_SMBUS_WRITE, command, |
1602 | I2C_SMBUS_WORD_DATA,&data); | 1647 | I2C_SMBUS_WORD_DATA, &data); |
1603 | } | 1648 | } |
1604 | EXPORT_SYMBOL(i2c_smbus_write_word_data); | 1649 | EXPORT_SYMBOL(i2c_smbus_write_word_data); |
1605 | 1650 | ||
@@ -1676,9 +1721,9 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | |||
1676 | length = I2C_SMBUS_BLOCK_MAX; | 1721 | length = I2C_SMBUS_BLOCK_MAX; |
1677 | data.block[0] = length; | 1722 | data.block[0] = length; |
1678 | memcpy(&data.block[1], values, length); | 1723 | memcpy(&data.block[1], values, length); |
1679 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1724 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1680 | I2C_SMBUS_WRITE,command, | 1725 | I2C_SMBUS_WRITE, command, |
1681 | I2C_SMBUS_BLOCK_DATA,&data); | 1726 | I2C_SMBUS_BLOCK_DATA, &data); |
1682 | } | 1727 | } |
1683 | EXPORT_SYMBOL(i2c_smbus_write_block_data); | 1728 | EXPORT_SYMBOL(i2c_smbus_write_block_data); |
1684 | 1729 | ||
@@ -1720,10 +1765,10 @@ EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); | |||
1720 | 1765 | ||
1721 | /* Simulate a SMBus command using the i2c protocol | 1766 | /* Simulate a SMBus command using the i2c protocol |
1722 | No checking of parameters is done! */ | 1767 | No checking of parameters is done! */ |
1723 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | 1768 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, |
1724 | unsigned short flags, | 1769 | unsigned short flags, |
1725 | char read_write, u8 command, int size, | 1770 | char read_write, u8 command, int size, |
1726 | union i2c_smbus_data * data) | 1771 | union i2c_smbus_data *data) |
1727 | { | 1772 | { |
1728 | /* So we need to generate a series of msgs. In the case of writing, we | 1773 | /* So we need to generate a series of msgs. In the case of writing, we |
1729 | need to use only one message; when reading, we need two. We initialize | 1774 | need to use only one message; when reading, we need two. We initialize |
@@ -1731,7 +1776,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1731 | simpler. */ | 1776 | simpler. */ |
1732 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; | 1777 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; |
1733 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; | 1778 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; |
1734 | int num = read_write == I2C_SMBUS_READ?2:1; | 1779 | int num = read_write == I2C_SMBUS_READ ? 2 : 1; |
1735 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, | 1780 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, |
1736 | { addr, flags | I2C_M_RD, 0, msgbuf1 } | 1781 | { addr, flags | I2C_M_RD, 0, msgbuf1 } |
1737 | }; | 1782 | }; |
@@ -1740,7 +1785,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1740 | int status; | 1785 | int status; |
1741 | 1786 | ||
1742 | msgbuf0[0] = command; | 1787 | msgbuf0[0] = command; |
1743 | switch(size) { | 1788 | switch (size) { |
1744 | case I2C_SMBUS_QUICK: | 1789 | case I2C_SMBUS_QUICK: |
1745 | msg[0].len = 0; | 1790 | msg[0].len = 0; |
1746 | /* Special case: The read/write field is used as data */ | 1791 | /* Special case: The read/write field is used as data */ |
@@ -1767,7 +1812,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1767 | if (read_write == I2C_SMBUS_READ) | 1812 | if (read_write == I2C_SMBUS_READ) |
1768 | msg[1].len = 2; | 1813 | msg[1].len = 2; |
1769 | else { | 1814 | else { |
1770 | msg[0].len=3; | 1815 | msg[0].len = 3; |
1771 | msgbuf0[1] = data->word & 0xff; | 1816 | msgbuf0[1] = data->word & 0xff; |
1772 | msgbuf0[2] = data->word >> 8; | 1817 | msgbuf0[2] = data->word >> 8; |
1773 | } | 1818 | } |
@@ -1860,26 +1905,26 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1860 | } | 1905 | } |
1861 | 1906 | ||
1862 | if (read_write == I2C_SMBUS_READ) | 1907 | if (read_write == I2C_SMBUS_READ) |
1863 | switch(size) { | 1908 | switch (size) { |
1864 | case I2C_SMBUS_BYTE: | 1909 | case I2C_SMBUS_BYTE: |
1865 | data->byte = msgbuf0[0]; | 1910 | data->byte = msgbuf0[0]; |
1866 | break; | 1911 | break; |
1867 | case I2C_SMBUS_BYTE_DATA: | 1912 | case I2C_SMBUS_BYTE_DATA: |
1868 | data->byte = msgbuf1[0]; | 1913 | data->byte = msgbuf1[0]; |
1869 | break; | 1914 | break; |
1870 | case I2C_SMBUS_WORD_DATA: | 1915 | case I2C_SMBUS_WORD_DATA: |
1871 | case I2C_SMBUS_PROC_CALL: | 1916 | case I2C_SMBUS_PROC_CALL: |
1872 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); | 1917 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); |
1873 | break; | 1918 | break; |
1874 | case I2C_SMBUS_I2C_BLOCK_DATA: | 1919 | case I2C_SMBUS_I2C_BLOCK_DATA: |
1875 | for (i = 0; i < data->block[0]; i++) | 1920 | for (i = 0; i < data->block[0]; i++) |
1876 | data->block[i+1] = msgbuf1[i]; | 1921 | data->block[i+1] = msgbuf1[i]; |
1877 | break; | 1922 | break; |
1878 | case I2C_SMBUS_BLOCK_DATA: | 1923 | case I2C_SMBUS_BLOCK_DATA: |
1879 | case I2C_SMBUS_BLOCK_PROC_CALL: | 1924 | case I2C_SMBUS_BLOCK_PROC_CALL: |
1880 | for (i = 0; i < msgbuf1[0] + 1; i++) | 1925 | for (i = 0; i < msgbuf1[0] + 1; i++) |
1881 | data->block[i] = msgbuf1[i]; | 1926 | data->block[i] = msgbuf1[i]; |
1882 | break; | 1927 | break; |
1883 | } | 1928 | } |
1884 | return 0; | 1929 | return 0; |
1885 | } | 1930 | } |
@@ -1924,7 +1969,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
1924 | } | 1969 | } |
1925 | rt_mutex_unlock(&adapter->bus_lock); | 1970 | rt_mutex_unlock(&adapter->bus_lock); |
1926 | } else | 1971 | } else |
1927 | res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, | 1972 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, |
1928 | command, protocol, data); | 1973 | command, protocol, data); |
1929 | 1974 | ||
1930 | return res; | 1975 | return res; |