summaryrefslogtreecommitdiff
path: root/include/throttle_ap.h
blob: 015d89d5ba08ab83133109bb2ebd30af856f9ec2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Copyright 2012 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Common interface to throttle the AP */

#ifndef __CROS_EC_THROTTLE_AP_H
#define __CROS_EC_THROTTLE_AP_H

#define PROCHOT_IN_DEBOUNCE_US (100 * MSEC)

/**
 * Level of throttling desired.
 */
enum throttle_level {
	THROTTLE_OFF = 0,
	THROTTLE_ON,
};

/**
 * Types of throttling desired. These are independent.
 */
enum throttle_type {
	THROTTLE_SOFT = 0, /* for example, host events */
	THROTTLE_HARD, /* for example, PROCHOT */
	NUM_THROTTLE_TYPES
};

/**
 * Possible sources for CPU throttling requests.
 */
enum throttle_sources {
	THROTTLE_SRC_THERMAL = 0,
	THROTTLE_SRC_BAT_DISCHG_CURRENT,
	THROTTLE_SRC_BAT_VOLTAGE,
	THROTTLE_SRC_AC,
};

/**
 * PROCHOT detection GPIOs.  PROCHOT in assumed to be active high unless
 * CONFIG_CPU_PROCHOT_ACTIVE_LOW is enabled.
 * C10 input polarity is explicitly specified in the struct below.
 */
struct prochot_cfg {
	enum gpio_signal gpio_prochot_in;
	void (*callback)(bool asserted, void *data);
	void *callback_data;
#ifdef CONFIG_CPU_PROCHOT_GATE_ON_C10
	enum gpio_signal gpio_c10_in;
	bool c10_active_high;
#endif
};

/**
 * Enable/disable CPU throttling.
 *
 * This is a virtual "OR" operation. Any caller can enable CPU throttling of
 * any type, but all callers must agree in order to disable that type.
 *
 * @param level         Level of throttling desired
 * @param type          Type of throttling desired
 * @param source        Which task is requesting throttling
 */
#if defined(CONFIG_THROTTLE_AP) ||                           \
	defined(CONFIG_THROTTLE_AP_ON_BAT_DISCHG_CURRENT) || \
	defined(CONFIG_THROTTLE_AP_ON_BAT_VOLTAGE)

void throttle_ap(enum throttle_level level, enum throttle_type type,
		 enum throttle_sources source);

/**
 * Configure the GPIOs used to monitor the PROCHOT signal.
 *
 * @param cfg	GPIO configuration for the PROCHOT and optional C10
 *		signals.
 */
void throttle_ap_config_prochot(const struct prochot_cfg *cfg);

/**
 * Interrupt handler to monitor PROCHOT input to the EC. The PROCHOT signal
 * can be asserted by the AP or by other devices on the board, such as chargers
 * and voltage regulators.
 *
 * The board initialization is responsible for enabling the interrupt.
 *
 * @param signal    GPIO signal connected to PROCHOT input. The polarity of this
 *                  signal is active high unless CONFIG_CPU_PROCHOT_ACTIVE_LOW
 *                  is defined.
 */
void throttle_ap_prochot_input_interrupt(enum gpio_signal signal);

/**
 * Interrupt handler to monitor the C10 input to the EC. The C10 signal
 * can be asserted by the AP when entering an idle state. This interrupt
 * is configured for the edge indicating C10 is de-asserting (GPIO_INT_RISING
 * if the signal is active low, GPIO_INT_FALLING for an active high signal).
 *
 * The board initialization is responsible for enabling the interrupt.
 *
 * @param signal    GPIO signal connected to C10 input.
 */
void throttle_ap_c10_input_interrupt(enum gpio_signal signal);

#else
static inline void throttle_ap(enum throttle_level level,
			       enum throttle_type type,
			       enum throttle_sources source)
{
}
#endif

void throttle_gpu(enum throttle_level level, enum throttle_type type,
		  enum throttle_sources source);

#endif /* __CROS_EC_THROTTLE_AP_H */