diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-01-14 16:03:49 -0500 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-01-14 16:03:49 -0500 |
commit | d529de2994880d345d7588f92d5a426f63089ba3 (patch) | |
tree | 038d6dc09e2e767280c2a061e2ff997bba43742d /drivers/i2c/i2c-core.c | |
parent | 5219bf884b6e2b54e734ca1799b6f0014bb2b4b7 (diff) |
i2c: Factor out runtime suspend checks from PM operations
When devices use dev_pm_ops the I2C API is implementing standard functionality
for integration with runtime PM and for checking for the presence of a per
device op. The PM core provides pm_generic_ functions implementing this
behaviour - use them to reduce coupling with future PM updates.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 68 |
1 files changed, 20 insertions, 48 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index b916675605b..0f9dc7dc15f 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 |