aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c121
1 files changed, 57 insertions, 64 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6b4cc567645..045ba6efea4 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
209static int i2c_device_pm_resume(struct device *dev) 205static 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
222static int i2c_device_pm_freeze(struct device *dev) 215static 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
236static int i2c_device_pm_thaw(struct device *dev) 225static 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
250static int i2c_device_pm_poweroff(struct device *dev) 235static 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
264static int i2c_device_pm_restore(struct device *dev) 245static 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
@@ -565,9 +537,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
565 client->dev.parent = &client->adapter->dev; 537 client->dev.parent = &client->adapter->dev;
566 client->dev.bus = &i2c_bus_type; 538 client->dev.bus = &i2c_bus_type;
567 client->dev.type = &i2c_client_type; 539 client->dev.type = &i2c_client_type;
568#ifdef CONFIG_OF
569 client->dev.of_node = info->of_node; 540 client->dev.of_node = info->of_node;
570#endif
571 541
572 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), 542 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
573 client->addr); 543 client->addr);
@@ -1021,6 +991,14 @@ static int i2c_do_del_adapter(struct i2c_driver *driver,
1021static int __unregister_client(struct device *dev, void *dummy) 991static int __unregister_client(struct device *dev, void *dummy)
1022{ 992{
1023 struct i2c_client *client = i2c_verify_client(dev); 993 struct i2c_client *client = i2c_verify_client(dev);
994 if (client && strcmp(client->name, "dummy"))
995 i2c_unregister_device(client);
996 return 0;
997}
998
999static int __unregister_dummy(struct device *dev, void *dummy)
1000{
1001 struct i2c_client *client = i2c_verify_client(dev);
1024 if (client) 1002 if (client)
1025 i2c_unregister_device(client); 1003 i2c_unregister_device(client);
1026 return 0; 1004 return 0;
@@ -1075,8 +1053,12 @@ int i2c_del_adapter(struct i2c_adapter *adap)
1075 mutex_unlock(&adap->userspace_clients_lock); 1053 mutex_unlock(&adap->userspace_clients_lock);
1076 1054
1077 /* Detach any active clients. This can't fail, thus we do not 1055 /* Detach any active clients. This can't fail, thus we do not
1078 checking the returned value. */ 1056 * check the returned value. This is a two-pass process, because
1057 * we can't remove the dummy devices during the first pass: they
1058 * could have been instantiated by real devices wishing to clean
1059 * them up properly, so we give them a chance to do that first. */
1079 res = device_for_each_child(&adap->dev, NULL, __unregister_client); 1060 res = device_for_each_child(&adap->dev, NULL, __unregister_client);
1061 res = device_for_each_child(&adap->dev, NULL, __unregister_dummy);
1080 1062
1081#ifdef CONFIG_I2C_COMPAT 1063#ifdef CONFIG_I2C_COMPAT
1082 class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, 1064 class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
@@ -1140,6 +1122,14 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
1140 if (res) 1122 if (res)
1141 return res; 1123 return res;
1142 1124
1125 /* Drivers should switch to dev_pm_ops instead. */
1126 if (driver->suspend)
1127 pr_warn("i2c-core: driver [%s] using legacy suspend method\n",
1128 driver->driver.name);
1129 if (driver->resume)
1130 pr_warn("i2c-core: driver [%s] using legacy resume method\n",
1131 driver->driver.name);
1132
1143 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); 1133 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
1144 1134
1145 INIT_LIST_HEAD(&driver->clients); 1135 INIT_LIST_HEAD(&driver->clients);
@@ -1362,7 +1352,7 @@ EXPORT_SYMBOL(i2c_transfer);
1362 * 1352 *
1363 * Returns negative errno, or else the number of bytes written. 1353 * Returns negative errno, or else the number of bytes written.
1364 */ 1354 */
1365int i2c_master_send(struct i2c_client *client, const char *buf, int count) 1355int i2c_master_send(const struct i2c_client *client, const char *buf, int count)
1366{ 1356{
1367 int ret; 1357 int ret;
1368 struct i2c_adapter *adap = client->adapter; 1358 struct i2c_adapter *adap = client->adapter;
@@ -1389,7 +1379,7 @@ EXPORT_SYMBOL(i2c_master_send);
1389 * 1379 *
1390 * Returns negative errno, or else the number of bytes read. 1380 * Returns negative errno, or else the number of bytes read.
1391 */ 1381 */
1392int i2c_master_recv(struct i2c_client *client, char *buf, int count) 1382int i2c_master_recv(const struct i2c_client *client, char *buf, int count)
1393{ 1383{
1394 struct i2c_adapter *adap = client->adapter; 1384 struct i2c_adapter *adap = client->adapter;
1395 struct i2c_msg msg; 1385 struct i2c_msg msg;
@@ -1679,7 +1669,7 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
1679 * This executes the SMBus "receive byte" protocol, returning negative errno 1669 * This executes the SMBus "receive byte" protocol, returning negative errno
1680 * else the byte received from the device. 1670 * else the byte received from the device.
1681 */ 1671 */
1682s32 i2c_smbus_read_byte(struct i2c_client *client) 1672s32 i2c_smbus_read_byte(const struct i2c_client *client)
1683{ 1673{
1684 union i2c_smbus_data data; 1674 union i2c_smbus_data data;
1685 int status; 1675 int status;
@@ -1699,7 +1689,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte);
1699 * This executes the SMBus "send byte" protocol, returning negative errno 1689 * This executes the SMBus "send byte" protocol, returning negative errno
1700 * else zero on success. 1690 * else zero on success.
1701 */ 1691 */
1702s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1692s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)
1703{ 1693{
1704 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, 1694 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1705 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); 1695 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
@@ -1714,7 +1704,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte);
1714 * This executes the SMBus "read byte" protocol, returning negative errno 1704 * This executes the SMBus "read byte" protocol, returning negative errno
1715 * else a data byte received from the device. 1705 * else a data byte received from the device.
1716 */ 1706 */
1717s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 1707s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
1718{ 1708{
1719 union i2c_smbus_data data; 1709 union i2c_smbus_data data;
1720 int status; 1710 int status;
@@ -1735,7 +1725,8 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1735 * This executes the SMBus "write byte" protocol, returning negative errno 1725 * This executes the SMBus "write byte" protocol, returning negative errno
1736 * else zero on success. 1726 * else zero on success.
1737 */ 1727 */
1738s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 1728s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command,
1729 u8 value)
1739{ 1730{
1740 union i2c_smbus_data data; 1731 union i2c_smbus_data data;
1741 data.byte = value; 1732 data.byte = value;
@@ -1753,7 +1744,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1753 * This executes the SMBus "read word" protocol, returning negative errno 1744 * This executes the SMBus "read word" protocol, returning negative errno
1754 * else a 16-bit unsigned "word" received from the device. 1745 * else a 16-bit unsigned "word" received from the device.
1755 */ 1746 */
1756s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) 1747s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command)
1757{ 1748{
1758 union i2c_smbus_data data; 1749 union i2c_smbus_data data;
1759 int status; 1750 int status;
@@ -1774,7 +1765,8 @@ EXPORT_SYMBOL(i2c_smbus_read_word_data);
1774 * This executes the SMBus "write word" protocol, returning negative errno 1765 * This executes the SMBus "write word" protocol, returning negative errno
1775 * else zero on success. 1766 * else zero on success.
1776 */ 1767 */
1777s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 1768s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command,
1769 u16 value)
1778{ 1770{
1779 union i2c_smbus_data data; 1771 union i2c_smbus_data data;
1780 data.word = value; 1772 data.word = value;
@@ -1793,7 +1785,8 @@ EXPORT_SYMBOL(i2c_smbus_write_word_data);
1793 * This executes the SMBus "process call" protocol, returning negative errno 1785 * This executes the SMBus "process call" protocol, returning negative errno
1794 * else a 16-bit unsigned "word" received from the device. 1786 * else a 16-bit unsigned "word" received from the device.
1795 */ 1787 */
1796s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value) 1788s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command,
1789 u16 value)
1797{ 1790{
1798 union i2c_smbus_data data; 1791 union i2c_smbus_data data;
1799 int status; 1792 int status;
@@ -1821,7 +1814,7 @@ EXPORT_SYMBOL(i2c_smbus_process_call);
1821 * support this; its emulation through I2C messaging relies on a specific 1814 * support this; its emulation through I2C messaging relies on a specific
1822 * mechanism (I2C_M_RECV_LEN) which may not be implemented. 1815 * mechanism (I2C_M_RECV_LEN) which may not be implemented.
1823 */ 1816 */
1824s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, 1817s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command,
1825 u8 *values) 1818 u8 *values)
1826{ 1819{
1827 union i2c_smbus_data data; 1820 union i2c_smbus_data data;
@@ -1848,7 +1841,7 @@ EXPORT_SYMBOL(i2c_smbus_read_block_data);
1848 * This executes the SMBus "block write" protocol, returning negative errno 1841 * This executes the SMBus "block write" protocol, returning negative errno
1849 * else zero on success. 1842 * else zero on success.
1850 */ 1843 */
1851s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 1844s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command,
1852 u8 length, const u8 *values) 1845 u8 length, const u8 *values)
1853{ 1846{
1854 union i2c_smbus_data data; 1847 union i2c_smbus_data data;
@@ -1864,7 +1857,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1864EXPORT_SYMBOL(i2c_smbus_write_block_data); 1857EXPORT_SYMBOL(i2c_smbus_write_block_data);
1865 1858
1866/* Returns the number of read bytes */ 1859/* Returns the number of read bytes */
1867s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, 1860s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command,
1868 u8 length, u8 *values) 1861 u8 length, u8 *values)
1869{ 1862{
1870 union i2c_smbus_data data; 1863 union i2c_smbus_data data;
@@ -1884,7 +1877,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command,
1884} 1877}
1885EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); 1878EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1886 1879
1887s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, 1880s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command,
1888 u8 length, const u8 *values) 1881 u8 length, const u8 *values)
1889{ 1882{
1890 union i2c_smbus_data data; 1883 union i2c_smbus_data data;