diff options
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 10be7b5fbe97..3202a86f420e 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/hardirq.h> | 34 | #include <linux/hardirq.h> |
35 | #include <linux/irqflags.h> | 35 | #include <linux/irqflags.h> |
36 | #include <linux/rwsem.h> | 36 | #include <linux/rwsem.h> |
37 | #include <linux/pm_runtime.h> | ||
37 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
38 | 39 | ||
39 | #include "i2c-core.h" | 40 | #include "i2c-core.h" |
@@ -184,6 +185,52 @@ static int i2c_device_pm_resume(struct device *dev) | |||
184 | #define i2c_device_pm_resume NULL | 185 | #define i2c_device_pm_resume NULL |
185 | #endif | 186 | #endif |
186 | 187 | ||
188 | #ifdef CONFIG_PM_RUNTIME | ||
189 | static int i2c_device_runtime_suspend(struct device *dev) | ||
190 | { | ||
191 | const struct dev_pm_ops *pm; | ||
192 | |||
193 | if (!dev->driver) | ||
194 | return 0; | ||
195 | pm = dev->driver->pm; | ||
196 | if (!pm || !pm->runtime_suspend) | ||
197 | return 0; | ||
198 | return pm->runtime_suspend(dev); | ||
199 | } | ||
200 | |||
201 | static int i2c_device_runtime_resume(struct device *dev) | ||
202 | { | ||
203 | const struct dev_pm_ops *pm; | ||
204 | |||
205 | if (!dev->driver) | ||
206 | return 0; | ||
207 | pm = dev->driver->pm; | ||
208 | if (!pm || !pm->runtime_resume) | ||
209 | return 0; | ||
210 | return pm->runtime_resume(dev); | ||
211 | } | ||
212 | |||
213 | static int i2c_device_runtime_idle(struct device *dev) | ||
214 | { | ||
215 | const struct dev_pm_ops *pm = NULL; | ||
216 | int ret; | ||
217 | |||
218 | if (dev->driver) | ||
219 | pm = dev->driver->pm; | ||
220 | if (pm && pm->runtime_idle) { | ||
221 | ret = pm->runtime_idle(dev); | ||
222 | if (ret) | ||
223 | return ret; | ||
224 | } | ||
225 | |||
226 | return pm_runtime_suspend(dev); | ||
227 | } | ||
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 | |||
187 | static int i2c_device_suspend(struct device *dev, pm_message_t mesg) | 234 | static int i2c_device_suspend(struct device *dev, pm_message_t mesg) |
188 | { | 235 | { |
189 | struct i2c_client *client = i2c_verify_client(dev); | 236 | struct i2c_client *client = i2c_verify_client(dev); |
@@ -251,6 +298,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = { | |||
251 | static const struct dev_pm_ops i2c_device_pm_ops = { | 298 | static const struct dev_pm_ops i2c_device_pm_ops = { |
252 | .suspend = i2c_device_pm_suspend, | 299 | .suspend = i2c_device_pm_suspend, |
253 | .resume = i2c_device_pm_resume, | 300 | .resume = i2c_device_pm_resume, |
301 | .runtime_suspend = i2c_device_runtime_suspend, | ||
302 | .runtime_resume = i2c_device_runtime_resume, | ||
303 | .runtime_idle = i2c_device_runtime_idle, | ||
254 | }; | 304 | }; |
255 | 305 | ||
256 | struct bus_type i2c_bus_type = { | 306 | struct bus_type i2c_bus_type = { |
@@ -1133,7 +1183,7 @@ EXPORT_SYMBOL(i2c_transfer); | |||
1133 | * i2c_master_send - issue a single I2C message in master transmit mode | 1183 | * i2c_master_send - issue a single I2C message in master transmit mode |
1134 | * @client: Handle to slave device | 1184 | * @client: Handle to slave device |
1135 | * @buf: Data that will be written to the slave | 1185 | * @buf: Data that will be written to the slave |
1136 | * @count: How many bytes to write | 1186 | * @count: How many bytes to write, must be less than 64k since msg.len is u16 |
1137 | * | 1187 | * |
1138 | * Returns negative errno, or else the number of bytes written. | 1188 | * Returns negative errno, or else the number of bytes written. |
1139 | */ | 1189 | */ |
@@ -1160,7 +1210,7 @@ EXPORT_SYMBOL(i2c_master_send); | |||
1160 | * i2c_master_recv - issue a single I2C message in master receive mode | 1210 | * i2c_master_recv - issue a single I2C message in master receive mode |
1161 | * @client: Handle to slave device | 1211 | * @client: Handle to slave device |
1162 | * @buf: Where to store data read from slave | 1212 | * @buf: Where to store data read from slave |
1163 | * @count: How many bytes to read | 1213 | * @count: How many bytes to read, must be less than 64k since msg.len is u16 |
1164 | * | 1214 | * |
1165 | * Returns negative errno, or else the number of bytes read. | 1215 | * Returns negative errno, or else the number of bytes read. |
1166 | */ | 1216 | */ |