diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-03-19 02:38:50 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-03-19 02:38:50 -0400 |
commit | 97eb3f24352ec6632c2127b35d8087d2a809a9b9 (patch) | |
tree | 722948059bbd325bbca232269490124231df80d4 /drivers/i2c/i2c-core.c | |
parent | 439581ec07fa9cf3f519dd461a2cf41cfd3adcb4 (diff) | |
parent | def179c271ac9b5020deca798470521f14d11edd (diff) |
Merge branch 'next' into for-linus
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 131 |
1 files changed, 69 insertions, 62 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index d231f683f576..f0bd5bcdf563 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -196,88 +196,60 @@ static int i2c_device_pm_suspend(struct device *dev) | |||
196 | { | 196 | { |
197 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 197 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
198 | 198 | ||
199 | if (pm) { | 199 | if (pm) |
200 | if (pm_runtime_suspended(dev)) | 200 | return pm_generic_suspend(dev); |
201 | return 0; | 201 | else |
202 | else | 202 | return i2c_legacy_suspend(dev, PMSG_SUSPEND); |
203 | return pm->suspend ? pm->suspend(dev) : 0; | ||
204 | } | ||
205 | |||
206 | return i2c_legacy_suspend(dev, PMSG_SUSPEND); | ||
207 | } | 203 | } |
208 | 204 | ||
209 | static int i2c_device_pm_resume(struct device *dev) | 205 | static int i2c_device_pm_resume(struct device *dev) |
210 | { | 206 | { |
211 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 207 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
212 | int ret; | ||
213 | 208 | ||
214 | if (pm) | 209 | if (pm) |
215 | ret = pm->resume ? pm->resume(dev) : 0; | 210 | return pm_generic_resume(dev); |
216 | else | 211 | else |
217 | ret = i2c_legacy_resume(dev); | 212 | return i2c_legacy_resume(dev); |
218 | |||
219 | return ret; | ||
220 | } | 213 | } |
221 | 214 | ||
222 | static int i2c_device_pm_freeze(struct device *dev) | 215 | static int i2c_device_pm_freeze(struct device *dev) |
223 | { | 216 | { |
224 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 217 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
225 | 218 | ||
226 | if (pm) { | 219 | if (pm) |
227 | if (pm_runtime_suspended(dev)) | 220 | return pm_generic_freeze(dev); |
228 | return 0; | 221 | else |
229 | else | 222 | return i2c_legacy_suspend(dev, PMSG_FREEZE); |
230 | return pm->freeze ? pm->freeze(dev) : 0; | ||
231 | } | ||
232 | |||
233 | return i2c_legacy_suspend(dev, PMSG_FREEZE); | ||
234 | } | 223 | } |
235 | 224 | ||
236 | static int i2c_device_pm_thaw(struct device *dev) | 225 | static int i2c_device_pm_thaw(struct device *dev) |
237 | { | 226 | { |
238 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 227 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
239 | 228 | ||
240 | if (pm) { | 229 | if (pm) |
241 | if (pm_runtime_suspended(dev)) | 230 | return pm_generic_thaw(dev); |
242 | return 0; | 231 | else |
243 | else | 232 | return i2c_legacy_resume(dev); |
244 | return pm->thaw ? pm->thaw(dev) : 0; | ||
245 | } | ||
246 | |||
247 | return i2c_legacy_resume(dev); | ||
248 | } | 233 | } |
249 | 234 | ||
250 | static int i2c_device_pm_poweroff(struct device *dev) | 235 | static int i2c_device_pm_poweroff(struct device *dev) |
251 | { | 236 | { |
252 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 237 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
253 | 238 | ||
254 | if (pm) { | 239 | if (pm) |
255 | if (pm_runtime_suspended(dev)) | 240 | return pm_generic_poweroff(dev); |
256 | return 0; | 241 | else |
257 | else | 242 | return i2c_legacy_suspend(dev, PMSG_HIBERNATE); |
258 | return pm->poweroff ? pm->poweroff(dev) : 0; | ||
259 | } | ||
260 | |||
261 | return i2c_legacy_suspend(dev, PMSG_HIBERNATE); | ||
262 | } | 243 | } |
263 | 244 | ||
264 | static int i2c_device_pm_restore(struct device *dev) | 245 | static int i2c_device_pm_restore(struct device *dev) |
265 | { | 246 | { |
266 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | 247 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
267 | int ret; | ||
268 | 248 | ||
269 | if (pm) | 249 | if (pm) |
270 | ret = pm->restore ? pm->restore(dev) : 0; | 250 | return pm_generic_restore(dev); |
271 | else | 251 | else |
272 | ret = i2c_legacy_resume(dev); | 252 | return i2c_legacy_resume(dev); |
273 | |||
274 | if (!ret) { | ||
275 | pm_runtime_disable(dev); | ||
276 | pm_runtime_set_active(dev); | ||
277 | pm_runtime_enable(dev); | ||
278 | } | ||
279 | |||
280 | return ret; | ||
281 | } | 253 | } |
282 | #else /* !CONFIG_PM_SLEEP */ | 254 | #else /* !CONFIG_PM_SLEEP */ |
283 | #define i2c_device_pm_suspend NULL | 255 | #define i2c_device_pm_suspend NULL |
@@ -848,6 +820,18 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
848 | goto out_list; | 820 | goto out_list; |
849 | } | 821 | } |
850 | 822 | ||
823 | /* Sanity checks */ | ||
824 | if (unlikely(adap->name[0] == '\0')) { | ||
825 | pr_err("i2c-core: Attempt to register an adapter with " | ||
826 | "no name!\n"); | ||
827 | return -EINVAL; | ||
828 | } | ||
829 | if (unlikely(!adap->algo)) { | ||
830 | pr_err("i2c-core: Attempt to register adapter '%s' with " | ||
831 | "no algo!\n", adap->name); | ||
832 | return -EINVAL; | ||
833 | } | ||
834 | |||
851 | rt_mutex_init(&adap->bus_lock); | 835 | rt_mutex_init(&adap->bus_lock); |
852 | mutex_init(&adap->userspace_clients_lock); | 836 | mutex_init(&adap->userspace_clients_lock); |
853 | INIT_LIST_HEAD(&adap->userspace_clients); | 837 | INIT_LIST_HEAD(&adap->userspace_clients); |
@@ -1009,6 +993,14 @@ static int i2c_do_del_adapter(struct i2c_driver *driver, | |||
1009 | static int __unregister_client(struct device *dev, void *dummy) | 993 | static int __unregister_client(struct device *dev, void *dummy) |
1010 | { | 994 | { |
1011 | struct i2c_client *client = i2c_verify_client(dev); | 995 | struct i2c_client *client = i2c_verify_client(dev); |
996 | if (client && strcmp(client->name, "dummy")) | ||
997 | i2c_unregister_device(client); | ||
998 | return 0; | ||
999 | } | ||
1000 | |||
1001 | static int __unregister_dummy(struct device *dev, void *dummy) | ||
1002 | { | ||
1003 | struct i2c_client *client = i2c_verify_client(dev); | ||
1012 | if (client) | 1004 | if (client) |
1013 | i2c_unregister_device(client); | 1005 | i2c_unregister_device(client); |
1014 | return 0; | 1006 | return 0; |
@@ -1063,8 +1055,12 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
1063 | mutex_unlock(&adap->userspace_clients_lock); | 1055 | mutex_unlock(&adap->userspace_clients_lock); |
1064 | 1056 | ||
1065 | /* Detach any active clients. This can't fail, thus we do not | 1057 | /* Detach any active clients. This can't fail, thus we do not |
1066 | checking the returned value. */ | 1058 | * check the returned value. This is a two-pass process, because |
1059 | * we can't remove the dummy devices during the first pass: they | ||
1060 | * could have been instantiated by real devices wishing to clean | ||
1061 | * them up properly, so we give them a chance to do that first. */ | ||
1067 | res = device_for_each_child(&adap->dev, NULL, __unregister_client); | 1062 | res = device_for_each_child(&adap->dev, NULL, __unregister_client); |
1063 | res = device_for_each_child(&adap->dev, NULL, __unregister_dummy); | ||
1068 | 1064 | ||
1069 | #ifdef CONFIG_I2C_COMPAT | 1065 | #ifdef CONFIG_I2C_COMPAT |
1070 | class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, | 1066 | class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, |
@@ -1128,6 +1124,14 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
1128 | if (res) | 1124 | if (res) |
1129 | return res; | 1125 | return res; |
1130 | 1126 | ||
1127 | /* Drivers should switch to dev_pm_ops instead. */ | ||
1128 | if (driver->suspend) | ||
1129 | pr_warn("i2c-core: driver [%s] using legacy suspend method\n", | ||
1130 | driver->driver.name); | ||
1131 | if (driver->resume) | ||
1132 | pr_warn("i2c-core: driver [%s] using legacy resume method\n", | ||
1133 | driver->driver.name); | ||
1134 | |||
1131 | pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); | 1135 | pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); |
1132 | 1136 | ||
1133 | INIT_LIST_HEAD(&driver->clients); | 1137 | INIT_LIST_HEAD(&driver->clients); |
@@ -1350,7 +1354,7 @@ EXPORT_SYMBOL(i2c_transfer); | |||
1350 | * | 1354 | * |
1351 | * Returns negative errno, or else the number of bytes written. | 1355 | * Returns negative errno, or else the number of bytes written. |
1352 | */ | 1356 | */ |
1353 | int i2c_master_send(struct i2c_client *client, const char *buf, int count) | 1357 | int i2c_master_send(const struct i2c_client *client, const char *buf, int count) |
1354 | { | 1358 | { |
1355 | int ret; | 1359 | int ret; |
1356 | struct i2c_adapter *adap = client->adapter; | 1360 | struct i2c_adapter *adap = client->adapter; |
@@ -1377,7 +1381,7 @@ EXPORT_SYMBOL(i2c_master_send); | |||
1377 | * | 1381 | * |
1378 | * Returns negative errno, or else the number of bytes read. | 1382 | * Returns negative errno, or else the number of bytes read. |
1379 | */ | 1383 | */ |
1380 | int i2c_master_recv(struct i2c_client *client, char *buf, int count) | 1384 | int i2c_master_recv(const struct i2c_client *client, char *buf, int count) |
1381 | { | 1385 | { |
1382 | struct i2c_adapter *adap = client->adapter; | 1386 | struct i2c_adapter *adap = client->adapter; |
1383 | struct i2c_msg msg; | 1387 | struct i2c_msg msg; |
@@ -1667,7 +1671,7 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg) | |||
1667 | * This executes the SMBus "receive byte" protocol, returning negative errno | 1671 | * This executes the SMBus "receive byte" protocol, returning negative errno |
1668 | * else the byte received from the device. | 1672 | * else the byte received from the device. |
1669 | */ | 1673 | */ |
1670 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 1674 | s32 i2c_smbus_read_byte(const struct i2c_client *client) |
1671 | { | 1675 | { |
1672 | union i2c_smbus_data data; | 1676 | union i2c_smbus_data data; |
1673 | int status; | 1677 | int status; |
@@ -1687,7 +1691,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte); | |||
1687 | * This executes the SMBus "send byte" protocol, returning negative errno | 1691 | * This executes the SMBus "send byte" protocol, returning negative errno |
1688 | * else zero on success. | 1692 | * else zero on success. |
1689 | */ | 1693 | */ |
1690 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) | 1694 | s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value) |
1691 | { | 1695 | { |
1692 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, | 1696 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1693 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | 1697 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); |
@@ -1702,7 +1706,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte); | |||
1702 | * This executes the SMBus "read byte" protocol, returning negative errno | 1706 | * This executes the SMBus "read byte" protocol, returning negative errno |
1703 | * else a data byte received from the device. | 1707 | * else a data byte received from the device. |
1704 | */ | 1708 | */ |
1705 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) | 1709 | s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command) |
1706 | { | 1710 | { |
1707 | union i2c_smbus_data data; | 1711 | union i2c_smbus_data data; |
1708 | int status; | 1712 | int status; |
@@ -1723,7 +1727,8 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data); | |||
1723 | * This executes the SMBus "write byte" protocol, returning negative errno | 1727 | * This executes the SMBus "write byte" protocol, returning negative errno |
1724 | * else zero on success. | 1728 | * else zero on success. |
1725 | */ | 1729 | */ |
1726 | s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) | 1730 | s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command, |
1731 | u8 value) | ||
1727 | { | 1732 | { |
1728 | union i2c_smbus_data data; | 1733 | union i2c_smbus_data data; |
1729 | data.byte = value; | 1734 | data.byte = value; |
@@ -1741,7 +1746,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte_data); | |||
1741 | * This executes the SMBus "read word" protocol, returning negative errno | 1746 | * This executes the SMBus "read word" protocol, returning negative errno |
1742 | * else a 16-bit unsigned "word" received from the device. | 1747 | * else a 16-bit unsigned "word" received from the device. |
1743 | */ | 1748 | */ |
1744 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) | 1749 | s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command) |
1745 | { | 1750 | { |
1746 | union i2c_smbus_data data; | 1751 | union i2c_smbus_data data; |
1747 | int status; | 1752 | int status; |
@@ -1762,7 +1767,8 @@ EXPORT_SYMBOL(i2c_smbus_read_word_data); | |||
1762 | * This executes the SMBus "write word" protocol, returning negative errno | 1767 | * This executes the SMBus "write word" protocol, returning negative errno |
1763 | * else zero on success. | 1768 | * else zero on success. |
1764 | */ | 1769 | */ |
1765 | s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | 1770 | s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, |
1771 | u16 value) | ||
1766 | { | 1772 | { |
1767 | union i2c_smbus_data data; | 1773 | union i2c_smbus_data data; |
1768 | data.word = value; | 1774 | data.word = value; |
@@ -1781,7 +1787,8 @@ EXPORT_SYMBOL(i2c_smbus_write_word_data); | |||
1781 | * This executes the SMBus "process call" protocol, returning negative errno | 1787 | * This executes the SMBus "process call" protocol, returning negative errno |
1782 | * else a 16-bit unsigned "word" received from the device. | 1788 | * else a 16-bit unsigned "word" received from the device. |
1783 | */ | 1789 | */ |
1784 | s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value) | 1790 | s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command, |
1791 | u16 value) | ||
1785 | { | 1792 | { |
1786 | union i2c_smbus_data data; | 1793 | union i2c_smbus_data data; |
1787 | int status; | 1794 | int status; |
@@ -1809,7 +1816,7 @@ EXPORT_SYMBOL(i2c_smbus_process_call); | |||
1809 | * support this; its emulation through I2C messaging relies on a specific | 1816 | * support this; its emulation through I2C messaging relies on a specific |
1810 | * mechanism (I2C_M_RECV_LEN) which may not be implemented. | 1817 | * mechanism (I2C_M_RECV_LEN) which may not be implemented. |
1811 | */ | 1818 | */ |
1812 | s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, | 1819 | s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command, |
1813 | u8 *values) | 1820 | u8 *values) |
1814 | { | 1821 | { |
1815 | union i2c_smbus_data data; | 1822 | union i2c_smbus_data data; |
@@ -1836,7 +1843,7 @@ EXPORT_SYMBOL(i2c_smbus_read_block_data); | |||
1836 | * This executes the SMBus "block write" protocol, returning negative errno | 1843 | * This executes the SMBus "block write" protocol, returning negative errno |
1837 | * else zero on success. | 1844 | * else zero on success. |
1838 | */ | 1845 | */ |
1839 | s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | 1846 | s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command, |
1840 | u8 length, const u8 *values) | 1847 | u8 length, const u8 *values) |
1841 | { | 1848 | { |
1842 | union i2c_smbus_data data; | 1849 | union i2c_smbus_data data; |
@@ -1852,7 +1859,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | |||
1852 | EXPORT_SYMBOL(i2c_smbus_write_block_data); | 1859 | EXPORT_SYMBOL(i2c_smbus_write_block_data); |
1853 | 1860 | ||
1854 | /* Returns the number of read bytes */ | 1861 | /* Returns the number of read bytes */ |
1855 | s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, | 1862 | s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command, |
1856 | u8 length, u8 *values) | 1863 | u8 length, u8 *values) |
1857 | { | 1864 | { |
1858 | union i2c_smbus_data data; | 1865 | union i2c_smbus_data data; |
@@ -1872,7 +1879,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, | |||
1872 | } | 1879 | } |
1873 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); | 1880 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); |
1874 | 1881 | ||
1875 | s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | 1882 | s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command, |
1876 | u8 length, const u8 *values) | 1883 | u8 length, const u8 *values) |
1877 | { | 1884 | { |
1878 | union i2c_smbus_data data; | 1885 | union i2c_smbus_data data; |