blob: 4ead077ea4e72c18854b34051c667131e7a5083e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Paul Walmsleyc0407a92009-09-03 20:14:01 +03002/*
3 * omap-pm-noop.c - OMAP power management interface - dummy version
4 *
5 * This code implements the OMAP power management interface to
6 * drivers, CPUIdle, CPUFreq, and DSP Bridge. It is strictly for
7 * debug/demonstration use, as it does nothing but printk() whenever a
8 * function is called (when DEBUG is defined, below)
9 *
10 * Copyright (C) 2008-2009 Texas Instruments, Inc.
11 * Copyright (C) 2008-2009 Nokia Corporation
12 * Paul Walmsley
13 *
14 * Interface developed by (in alphabetical order):
15 * Karthik Dasu, Tony Lindgren, Rajendra Nayak, Sakari Poussa, Veeramanikandan
16 * Raju, Anand Sawant, Igor Stoppa, Paul Walmsley, Richard Woodruff
17 */
18
19#undef DEBUG
20
21#include <linux/init.h>
22#include <linux/cpufreq.h>
23#include <linux/device.h>
Kevin Hilmanc80705a2010-12-21 21:31:55 -070024#include <linux/platform_device.h>
Paul Walmsleyc0407a92009-09-03 20:14:01 +030025
Tony Lindgren6e740f92012-10-29 15:20:45 -070026#include "omap_device.h"
27#include "omap-pm.h"
Paul Walmsleyc0407a92009-09-03 20:14:01 +030028
Kevin Hilman6081dc32010-12-21 21:31:55 -070029static bool off_mode_enabled;
Tomi Valkeinenfc013872011-06-09 16:56:23 +030030static int dummy_context_loss_counter;
Kevin Hilman6081dc32010-12-21 21:31:55 -070031
Paul Walmsleyc0407a92009-09-03 20:14:01 +030032/*
33 * Device-driver-originated constraints (via board-*.c files)
34 */
35
Paul Walmsley564889c2010-07-26 16:34:34 -060036int omap_pm_set_max_mpu_wakeup_lat(struct device *dev, long t)
Paul Walmsleyc0407a92009-09-03 20:14:01 +030037{
38 if (!dev || t < -1) {
Paul Walmsley564889c2010-07-26 16:34:34 -060039 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
40 return -EINVAL;
Peter Senna Tschudin59c27952012-09-18 18:36:13 +020041 }
Paul Walmsleyc0407a92009-09-03 20:14:01 +030042
43 if (t == -1)
Paul Walmsley7852ec02012-07-26 00:54:26 -060044 pr_debug("OMAP PM: remove max MPU wakeup latency constraint: dev %s\n",
45 dev_name(dev));
Paul Walmsleyc0407a92009-09-03 20:14:01 +030046 else
Paul Walmsley7852ec02012-07-26 00:54:26 -060047 pr_debug("OMAP PM: add max MPU wakeup latency constraint: dev %s, t = %ld usec\n",
48 dev_name(dev), t);
Paul Walmsleyc0407a92009-09-03 20:14:01 +030049
50 /*
51 * For current Linux, this needs to map the MPU to a
52 * powerdomain, then go through the list of current max lat
53 * constraints on the MPU and find the smallest. If
54 * the latency constraint has changed, the code should
55 * recompute the state to enter for the next powerdomain
56 * state.
57 *
58 * TI CDP code can call constraint_set here.
59 */
Paul Walmsley564889c2010-07-26 16:34:34 -060060
61 return 0;
Paul Walmsleyc0407a92009-09-03 20:14:01 +030062}
63
Paul Walmsley564889c2010-07-26 16:34:34 -060064int omap_pm_set_min_bus_tput(struct device *dev, u8 agent_id, unsigned long r)
Paul Walmsleyc0407a92009-09-03 20:14:01 +030065{
66 if (!dev || (agent_id != OCP_INITIATOR_AGENT &&
67 agent_id != OCP_TARGET_AGENT)) {
Paul Walmsley564889c2010-07-26 16:34:34 -060068 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
69 return -EINVAL;
Peter Senna Tschudin59c27952012-09-18 18:36:13 +020070 }
Paul Walmsleyc0407a92009-09-03 20:14:01 +030071
72 if (r == 0)
Paul Walmsley7852ec02012-07-26 00:54:26 -060073 pr_debug("OMAP PM: remove min bus tput constraint: dev %s for agent_id %d\n",
74 dev_name(dev), agent_id);
Paul Walmsleyc0407a92009-09-03 20:14:01 +030075 else
Paul Walmsley7852ec02012-07-26 00:54:26 -060076 pr_debug("OMAP PM: add min bus tput constraint: dev %s for agent_id %d: rate %ld KiB\n",
Paul Walmsleyc0407a92009-09-03 20:14:01 +030077 dev_name(dev), agent_id, r);
78
79 /*
80 * This code should model the interconnect and compute the
81 * required clock frequency, convert that to a VDD2 OPP ID, then
82 * set the VDD2 OPP appropriately.
83 *
84 * TI CDP code can call constraint_set here on the VDD2 OPP.
85 */
Paul Walmsley564889c2010-07-26 16:34:34 -060086
87 return 0;
Paul Walmsleyc0407a92009-09-03 20:14:01 +030088}
89
Paul Walmsleyc0407a92009-09-03 20:14:01 +030090/*
91 * DSP Bridge-specific constraints
92 */
93
Paul Walmsleyc0407a92009-09-03 20:14:01 +030094
Kevin Hilman6081dc32010-12-21 21:31:55 -070095/**
96 * omap_pm_enable_off_mode - notify OMAP PM that off-mode is enabled
97 *
98 * Intended for use only by OMAP PM core code to notify this layer
99 * that off mode has been enabled.
100 */
101void omap_pm_enable_off_mode(void)
102{
103 off_mode_enabled = true;
104}
105
106/**
107 * omap_pm_disable_off_mode - notify OMAP PM that off-mode is disabled
108 *
109 * Intended for use only by OMAP PM core code to notify this layer
110 * that off mode has been disabled.
111 */
112void omap_pm_disable_off_mode(void)
113{
114 off_mode_enabled = false;
115}
116
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300117/*
118 * Device context loss tracking
119 */
120
Kevin Hilman6081dc32010-12-21 21:31:55 -0700121#ifdef CONFIG_ARCH_OMAP2PLUS
122
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300123int omap_pm_get_dev_context_loss_count(struct device *dev)
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300124{
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700125 struct platform_device *pdev = to_platform_device(dev);
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300126 int count;
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300127
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700128 if (WARN_ON(!dev))
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300129 return -ENODEV;
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300130
Kevin Hilman3ec2dec2012-02-15 11:47:45 -0800131 if (dev->pm_domain == &omap_device_pm_domain) {
Kevin Hilman6081dc32010-12-21 21:31:55 -0700132 count = omap_device_get_context_loss_count(pdev);
133 } else {
134 WARN_ONCE(off_mode_enabled, "omap_pm: using dummy context loss counter; device %s should be converted to omap_device",
135 dev_name(dev));
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300136
Kevin Hilman6081dc32010-12-21 21:31:55 -0700137 count = dummy_context_loss_counter;
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300138
139 if (off_mode_enabled) {
140 count++;
141 /*
142 * Context loss count has to be a non-negative value.
143 * Clear the sign bit to get a value range from 0 to
144 * INT_MAX.
145 */
146 count &= INT_MAX;
147 dummy_context_loss_counter = count;
148 }
Kevin Hilman6081dc32010-12-21 21:31:55 -0700149 }
150
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700151 pr_debug("OMAP PM: context loss count for dev %s = %d\n",
152 dev_name(dev), count);
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300153
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700154 return count;
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300155}
156
Kevin Hilman6081dc32010-12-21 21:31:55 -0700157#else
158
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300159int omap_pm_get_dev_context_loss_count(struct device *dev)
Kevin Hilman6081dc32010-12-21 21:31:55 -0700160{
161 return dummy_context_loss_counter;
162}
163
164#endif
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300165
166/* Should be called before clk framework init */
Kevin Hilman53da4ce2010-12-09 09:13:48 -0600167int __init omap_pm_if_early_init(void)
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300168{
Paul Walmsleyc0407a92009-09-03 20:14:01 +0300169 return 0;
170}
171
172/* Must be called after clock framework is initialized */
173int __init omap_pm_if_init(void)
174{
175 return 0;
176}