Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 1 | /* |
| 2 | * omap-pm-noop.c - OMAP power management interface - dummy version |
| 3 | * |
| 4 | * This code implements the OMAP power management interface to |
| 5 | * drivers, CPUIdle, CPUFreq, and DSP Bridge. It is strictly for |
| 6 | * debug/demonstration use, as it does nothing but printk() whenever a |
| 7 | * function is called (when DEBUG is defined, below) |
| 8 | * |
| 9 | * Copyright (C) 2008-2009 Texas Instruments, Inc. |
| 10 | * Copyright (C) 2008-2009 Nokia Corporation |
| 11 | * Paul Walmsley |
| 12 | * |
| 13 | * Interface developed by (in alphabetical order): |
| 14 | * Karthik Dasu, Tony Lindgren, Rajendra Nayak, Sakari Poussa, Veeramanikandan |
| 15 | * Raju, Anand Sawant, Igor Stoppa, Paul Walmsley, Richard Woodruff |
| 16 | */ |
| 17 | |
| 18 | #undef DEBUG |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/cpufreq.h> |
| 22 | #include <linux/device.h> |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 24 | |
Tony Lindgren | 6e740f9 | 2012-10-29 15:20:45 -0700 | [diff] [blame] | 25 | #include "omap_device.h" |
| 26 | #include "omap-pm.h" |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 27 | |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 28 | static bool off_mode_enabled; |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 29 | static int dummy_context_loss_counter; |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 30 | |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 31 | /* |
| 32 | * Device-driver-originated constraints (via board-*.c files) |
| 33 | */ |
| 34 | |
Paul Walmsley | 564889c | 2010-07-26 16:34:34 -0600 | [diff] [blame] | 35 | int omap_pm_set_max_mpu_wakeup_lat(struct device *dev, long t) |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 36 | { |
| 37 | if (!dev || t < -1) { |
Paul Walmsley | 564889c | 2010-07-26 16:34:34 -0600 | [diff] [blame] | 38 | WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__); |
| 39 | return -EINVAL; |
Peter Senna Tschudin | 59c2795 | 2012-09-18 18:36:13 +0200 | [diff] [blame] | 40 | } |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 41 | |
| 42 | if (t == -1) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 43 | pr_debug("OMAP PM: remove max MPU wakeup latency constraint: dev %s\n", |
| 44 | dev_name(dev)); |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 45 | else |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 46 | pr_debug("OMAP PM: add max MPU wakeup latency constraint: dev %s, t = %ld usec\n", |
| 47 | dev_name(dev), t); |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * For current Linux, this needs to map the MPU to a |
| 51 | * powerdomain, then go through the list of current max lat |
| 52 | * constraints on the MPU and find the smallest. If |
| 53 | * the latency constraint has changed, the code should |
| 54 | * recompute the state to enter for the next powerdomain |
| 55 | * state. |
| 56 | * |
| 57 | * TI CDP code can call constraint_set here. |
| 58 | */ |
Paul Walmsley | 564889c | 2010-07-26 16:34:34 -0600 | [diff] [blame] | 59 | |
| 60 | return 0; |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 61 | } |
| 62 | |
Paul Walmsley | 564889c | 2010-07-26 16:34:34 -0600 | [diff] [blame] | 63 | int omap_pm_set_min_bus_tput(struct device *dev, u8 agent_id, unsigned long r) |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 64 | { |
| 65 | if (!dev || (agent_id != OCP_INITIATOR_AGENT && |
| 66 | agent_id != OCP_TARGET_AGENT)) { |
Paul Walmsley | 564889c | 2010-07-26 16:34:34 -0600 | [diff] [blame] | 67 | WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__); |
| 68 | return -EINVAL; |
Peter Senna Tschudin | 59c2795 | 2012-09-18 18:36:13 +0200 | [diff] [blame] | 69 | } |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 70 | |
| 71 | if (r == 0) |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 72 | pr_debug("OMAP PM: remove min bus tput constraint: dev %s for agent_id %d\n", |
| 73 | dev_name(dev), agent_id); |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 74 | else |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 75 | pr_debug("OMAP PM: add min bus tput constraint: dev %s for agent_id %d: rate %ld KiB\n", |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 76 | dev_name(dev), agent_id, r); |
| 77 | |
| 78 | /* |
| 79 | * This code should model the interconnect and compute the |
| 80 | * required clock frequency, convert that to a VDD2 OPP ID, then |
| 81 | * set the VDD2 OPP appropriately. |
| 82 | * |
| 83 | * TI CDP code can call constraint_set here on the VDD2 OPP. |
| 84 | */ |
Paul Walmsley | 564889c | 2010-07-26 16:34:34 -0600 | [diff] [blame] | 85 | |
| 86 | return 0; |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 87 | } |
| 88 | |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 89 | /* |
| 90 | * DSP Bridge-specific constraints |
| 91 | */ |
| 92 | |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 93 | |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 94 | /** |
| 95 | * omap_pm_enable_off_mode - notify OMAP PM that off-mode is enabled |
| 96 | * |
| 97 | * Intended for use only by OMAP PM core code to notify this layer |
| 98 | * that off mode has been enabled. |
| 99 | */ |
| 100 | void omap_pm_enable_off_mode(void) |
| 101 | { |
| 102 | off_mode_enabled = true; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * omap_pm_disable_off_mode - notify OMAP PM that off-mode is disabled |
| 107 | * |
| 108 | * Intended for use only by OMAP PM core code to notify this layer |
| 109 | * that off mode has been disabled. |
| 110 | */ |
| 111 | void omap_pm_disable_off_mode(void) |
| 112 | { |
| 113 | off_mode_enabled = false; |
| 114 | } |
| 115 | |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 116 | /* |
| 117 | * Device context loss tracking |
| 118 | */ |
| 119 | |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 120 | #ifdef CONFIG_ARCH_OMAP2PLUS |
| 121 | |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 122 | int omap_pm_get_dev_context_loss_count(struct device *dev) |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 123 | { |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 124 | struct platform_device *pdev = to_platform_device(dev); |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 125 | int count; |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 126 | |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 127 | if (WARN_ON(!dev)) |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 128 | return -ENODEV; |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 129 | |
Kevin Hilman | 3ec2dec | 2012-02-15 11:47:45 -0800 | [diff] [blame] | 130 | if (dev->pm_domain == &omap_device_pm_domain) { |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 131 | count = omap_device_get_context_loss_count(pdev); |
| 132 | } else { |
| 133 | WARN_ONCE(off_mode_enabled, "omap_pm: using dummy context loss counter; device %s should be converted to omap_device", |
| 134 | dev_name(dev)); |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 135 | |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 136 | count = dummy_context_loss_counter; |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 137 | |
| 138 | if (off_mode_enabled) { |
| 139 | count++; |
| 140 | /* |
| 141 | * Context loss count has to be a non-negative value. |
| 142 | * Clear the sign bit to get a value range from 0 to |
| 143 | * INT_MAX. |
| 144 | */ |
| 145 | count &= INT_MAX; |
| 146 | dummy_context_loss_counter = count; |
| 147 | } |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 150 | pr_debug("OMAP PM: context loss count for dev %s = %d\n", |
| 151 | dev_name(dev), count); |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 152 | |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 153 | return count; |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 154 | } |
| 155 | |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 156 | #else |
| 157 | |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 158 | int omap_pm_get_dev_context_loss_count(struct device *dev) |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 159 | { |
| 160 | return dummy_context_loss_counter; |
| 161 | } |
| 162 | |
| 163 | #endif |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 164 | |
| 165 | /* Should be called before clk framework init */ |
Kevin Hilman | 53da4ce | 2010-12-09 09:13:48 -0600 | [diff] [blame] | 166 | int __init omap_pm_if_early_init(void) |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 167 | { |
Paul Walmsley | c0407a9 | 2009-09-03 20:14:01 +0300 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | /* Must be called after clock framework is initialized */ |
| 172 | int __init omap_pm_if_init(void) |
| 173 | { |
| 174 | return 0; |
| 175 | } |