Santosh Shilimkar | fc20ffe | 2013-07-14 17:17:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * PM domain driver for Keystone2 devices |
| 3 | * |
| 4 | * Copyright 2013 Texas Instruments, Inc. |
| 5 | * Santosh Shilimkar <santosh.shillimkar@ti.com> |
| 6 | * |
| 7 | * Based on Kevins work on DAVINCI SOCs |
| 8 | * Kevin Hilman <khilman@linaro.org> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms and conditions of the GNU General Public License, |
| 12 | * version 2, as published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/pm_runtime.h> |
| 17 | #include <linux/pm_clock.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/clk-provider.h> |
Kevin Hilman | 8620d2c | 2013-10-14 10:30:11 -0700 | [diff] [blame] | 20 | #include <linux/of.h> |
Santosh Shilimkar | fc20ffe | 2013-07-14 17:17:39 -0400 | [diff] [blame] | 21 | |
Rafael J. Wysocki | bf7c544 | 2014-12-13 00:42:49 +0100 | [diff] [blame] | 22 | #ifdef CONFIG_PM |
Santosh Shilimkar | fc20ffe | 2013-07-14 17:17:39 -0400 | [diff] [blame] | 23 | static int keystone_pm_runtime_suspend(struct device *dev) |
| 24 | { |
| 25 | int ret; |
| 26 | |
| 27 | dev_dbg(dev, "%s\n", __func__); |
| 28 | |
| 29 | ret = pm_generic_runtime_suspend(dev); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | ret = pm_clk_suspend(dev); |
| 34 | if (ret) { |
| 35 | pm_generic_runtime_resume(dev); |
| 36 | return ret; |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int keystone_pm_runtime_resume(struct device *dev) |
| 43 | { |
| 44 | dev_dbg(dev, "%s\n", __func__); |
| 45 | |
| 46 | pm_clk_resume(dev); |
| 47 | |
| 48 | return pm_generic_runtime_resume(dev); |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | static struct dev_pm_domain keystone_pm_domain = { |
| 53 | .ops = { |
| 54 | SET_RUNTIME_PM_OPS(keystone_pm_runtime_suspend, |
| 55 | keystone_pm_runtime_resume, NULL) |
| 56 | USE_PLATFORM_PM_SLEEP_OPS |
| 57 | }, |
| 58 | }; |
| 59 | |
| 60 | static struct pm_clk_notifier_block platform_domain_notifier = { |
| 61 | .pm_domain = &keystone_pm_domain, |
| 62 | }; |
| 63 | |
Kevin Hilman | 8620d2c | 2013-10-14 10:30:11 -0700 | [diff] [blame] | 64 | static struct of_device_id of_keystone_table[] = { |
| 65 | {.compatible = "ti,keystone"}, |
| 66 | { /* end of list */ }, |
| 67 | }; |
| 68 | |
Santosh Shilimkar | fc20ffe | 2013-07-14 17:17:39 -0400 | [diff] [blame] | 69 | int __init keystone_pm_runtime_init(void) |
| 70 | { |
Kevin Hilman | 8620d2c | 2013-10-14 10:30:11 -0700 | [diff] [blame] | 71 | struct device_node *np; |
| 72 | |
| 73 | np = of_find_matching_node(NULL, of_keystone_table); |
| 74 | if (!np) |
| 75 | return 0; |
| 76 | |
Santosh Shilimkar | fc20ffe | 2013-07-14 17:17:39 -0400 | [diff] [blame] | 77 | pm_clk_add_notifier(&platform_bus_type, &platform_domain_notifier); |
| 78 | |
| 79 | return 0; |
| 80 | } |