coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ec.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pnp.h>
6 #include <ec/acpi/ec.h>
7 #include <option.h>
8 
9 #include "ec.h"
10 #include "chip.h"
11 
12 typedef struct ec_kontron_it8516e_config config_t;
13 
14 enum { /* EC commands */
26 };
27 
28 /**
29  * Sets the type of the external temperature sensor used
30  *
31  * @param type Type of sensor to set
32  */
33 static void it8516e_set_systemp_type(const u8 type)
34 {
36  return;
38 }
39 
40 /**
41  * Sets the operating mode of a fan
42  *
43  * @param idx Selects the fan; 0: CPU, 1: System
44  * @param mode Mode to set
45  */
46 static void it8516e_set_fan_mode(const u8 idx, const u8 mode)
47 {
49  return;
50  if (send_ec_data(idx))
51  return;
52  send_ec_data(mode);
53 }
54 
55 /**
56  * Sets the PWM rate of a fan in IT8516E_MODE_PWM
57  *
58  * @param idx Selects the fan; 0: CPU, 1: System
59  * @param pwm PWM rate measured in 255ths
60  */
61 static void it8516e_set_fan_pwm(const u8 idx, const u8 pwm)
62 {
64  return;
65  if (send_ec_data(idx))
66  return;
67  send_ec_data(pwm);
68 }
69 
70 /**
71  * Sets the target speed in RPM for a fan in IT8516E_MODE_SPEED
72  *
73  * @param idx Selects the fan; 0: CPU, 1: System
74  * @param speed Speed in RPM
75  */
76 static void it8516e_set_fan_speed(const u8 idx, const u16 speed)
77 {
79  return;
80  if (send_ec_data(idx))
81  return;
82  if (send_ec_data(speed & 0xff))
83  return;
84  send_ec_data(speed >> 8);
85 }
86 
87 /**
88  * Sets the target temperature for a fan in IT8516E_MODE_THERMAL
89  *
90  * @param idx Selects the fan; 0: CPU, 1: System
91  * @param temp Temperature in 64ths degree C
92  */
93 static void it8516e_set_fan_temperature(const u8 idx, const u16 temp)
94 {
96  return;
97  if (send_ec_data(idx))
98  return;
99  if (send_ec_data(temp & 0xff))
100  return;
101  send_ec_data(temp >> 8);
102 }
103 
104 /**
105  * Sets the minimum and maximum PWM rate of a fan in IT8516E_MODE_THERMAL
106  *
107  * @param idx Selects the fan; 0: CPU, 1: System
108  * @param min Minimum PWM rate in %
109  * @param max Maximum PWM rate in %
110  */
111 static void it8516e_set_fan_limits(const u8 idx, const u8 min, const u8 max)
112 {
114  return;
115  if (send_ec_data(idx))
116  return;
117  if (send_ec_data(min))
118  return;
119  send_ec_data(max);
120 }
121 
123  const u8 fan_idx)
124 {
125  static char fanX_mode[] = "fanX_mode";
126  static char fanX_target[] = "fanX_target";
127  static char fanX_min[] = "fanX_min";
128  static char fanX_max[] = "fanX_max";
129 
130  u8 fan_mode = config->default_fan_mode[fan_idx];
131  u16 fan_target = config->default_fan_target[fan_idx];
132  u8 fan_min = config->default_fan_min[fan_idx];
133  u8 fan_max = config->default_fan_max[fan_idx];
134 
135  fanX_mode[3] = '1' + fan_idx;
136  fan_mode = get_uint_option(fanX_mode, fan_mode);
137  if (!fan_mode)
139  it8516e_set_fan_mode(fan_idx, fan_mode);
140 
141  fanX_target[3] = '1' + fan_idx;
142  fan_target = get_uint_option(fanX_target, fan_target);
143  switch (fan_mode) {
144  case IT8516E_MODE_AUTO:
146  "Setting it8516e fan%d "
147  "control to auto.\n",
148  fan_idx + 1);
149  break;
150  case IT8516E_MODE_PWM:
152  "Setting it8516e fan%d "
153  "control to %d%% PWM.\n",
154  fan_idx + 1, fan_target);
155  if (fan_target > 100) /* Constrain to 100% */
156  fan_target = 100;
157  it8516e_set_fan_pwm(fan_idx, (fan_target * 255) / 100);
158  break;
159  case IT8516E_MODE_SPEED:
161  "Setting it8516e fan%d "
162  "control to %d RPMs.\n",
163  fan_idx + 1, fan_target);
164  it8516e_set_fan_speed(fan_idx, fan_target);
165  break;
168  "Setting it8516e fan%d control to %d C.\n",
169  fan_idx + 1, fan_target);
170  if (fan_target > 1024) /* Constrain to 1K */
171  fan_target = 1024;
172  it8516e_set_fan_temperature(fan_idx, fan_target * 64);
173 
174  fanX_min[3] = '1' + fan_idx;
175  fanX_max[3] = '1' + fan_idx;
176  fan_min = get_uint_option(fanX_min, fan_min);
177  fan_max = get_uint_option(fanX_max, fan_max);
178 
179  if (!fan_max || fan_max > 100) /* Constrain fan_max to 100% */
180  fan_max = 100;
181  if (fan_min >= 100) /* Constrain fan_min to 99% */
182  fan_min = 99;
183  if (fan_max <= fan_min) /* If fan_min is the higher of the two,
184  it's safer for the hardware to keep
185  its value. Therefore, update fan_max. */
186  fan_max = fan_min + 1;
187 
189  "Setting it8516e fan%d limits to %d%% - %d%% PWM.\n",
190  fan_idx + 1, fan_min, fan_max);
191  it8516e_set_fan_limits(fan_idx, fan_min, fan_max);
192  break;
193  }
194 }
195 
196 static void it8516e_pm2_init(struct device *dev)
197 {
198  const config_t *const config = dev->chip_info;
199 
200  /* TODO: Set frequency / divider? */
201 
204 
205  u8 systemp_type = get_uint_option("systemp_type", config->default_systemp);
206  if (systemp_type >= IT8516E_SYSTEMP_LASTPLUSONE)
207  systemp_type = IT8516E_SYSTEMP_NONE;
208  it8516e_set_systemp_type(systemp_type);
209 
212 }
213 
214 static struct device_operations it8516e_pm2_ops = {
216  .set_resources = pnp_set_resources,
217  .enable_resources = pnp_enable_resources,
218  .enable = pnp_enable,
219  .init = it8516e_pm2_init
220 };
221 
222 static struct pnp_info it8516e_dev_infos[] = {
223  { NULL, IT8516E_LDN_UART1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
224  { NULL, IT8516E_LDN_UART2, PNP_IO0 | PNP_IRQ0, 0x07f8, },
225  { NULL, IT8516E_LDN_SWUC, PNP_IO0 | PNP_IRQ0, 0xffe0, },
227  { NULL, IT8516E_LDN_KBD, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
228  { NULL, IT8516E_LDN_SMFI, PNP_IO0 | PNP_IRQ0, 0xfff0, },
229  { NULL, IT8516E_LDN_BRAM, PNP_IO0 | PNP_IO1, 0xfffe, 0xfffe, },
230  { NULL, IT8516E_LDN_PM1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
231  { &it8516e_pm2_ops, IT8516E_LDN_PM2, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
232  { NULL, IT8516E_LDN_PM3, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
233 };
234 
235 static void it8516e_enable(struct device *dev)
236 {
239 }
240 
242  CHIP_NAME("Kontron (Fintec/ITE) IT8516E EC")
243  .enable_dev = it8516e_enable
244 };
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
struct resource * find_resource(const struct device *dev, unsigned int index)
Return an existing resource structure for a given index.
Definition: device_util.c:394
int send_ec_command(u8 command)
Definition: ec.c:13
void ec_set_ports(u16 cmd_reg, u16 data_reg)
Definition: ec.c:143
int send_ec_data(u8 data)
Definition: ec.c:35
static void it8516e_set_fan_from_options(const config_t *const config, const u8 fan_idx)
Definition: ec.c:122
static struct pnp_info it8516e_dev_infos[]
Definition: ec.c:222
static void it8516e_set_fan_temperature(const u8 idx, const u16 temp)
Sets the target temperature for a fan in IT8516E_MODE_THERMAL.
Definition: ec.c:93
static void it8516e_pm2_init(struct device *dev)
Definition: ec.c:196
static void it8516e_set_fan_speed(const u8 idx, const u16 speed)
Sets the target speed in RPM for a fan in IT8516E_MODE_SPEED.
Definition: ec.c:76
static void it8516e_set_systemp_type(const u8 type)
Sets the type of the external temperature sensor used.
Definition: ec.c:33
static void it8516e_enable(struct device *dev)
Definition: ec.c:235
static void it8516e_set_fan_pwm(const u8 idx, const u8 pwm)
Sets the PWM rate of a fan in IT8516E_MODE_PWM.
Definition: ec.c:61
@ IT8516E_CMD_SET_FAN_TEMP
Definition: ec.c:24
@ IT8516E_CMD_SET_FAN_MODE
Definition: ec.c:18
@ IT8516E_CMD_SET_FAN_PWM
Definition: ec.c:20
@ IT8516E_CMD_GET_FAN_TEMP
Definition: ec.c:23
@ IT8516E_CMD_GET_FAN_PWM
Definition: ec.c:19
@ IT8516E_CMD_SET_SYSTEMP_TYPE
Definition: ec.c:15
@ IT8516E_CMD_GET_SYSTEMP_TYPE
Definition: ec.c:16
@ IT8516E_CMD_SET_FAN_LIMITS
Definition: ec.c:25
@ IT8516E_CMD_GET_FAN_MODE
Definition: ec.c:17
@ IT8516E_CMD_GET_FAN_SPEED
Definition: ec.c:21
@ IT8516E_CMD_SET_FAN_SPEED
Definition: ec.c:22
const struct chip_operations ec_kontron_it8516e_ops
Definition: ec.c:241
static void it8516e_set_fan_mode(const u8 idx, const u8 mode)
Sets the operating mode of a fan.
Definition: ec.c:46
static struct device_operations it8516e_pm2_ops
Definition: ec.c:214
static void it8516e_set_fan_limits(const u8 idx, const u8 min, const u8 max)
Sets the minimum and maximum PWM rate of a fan in IT8516E_MODE_THERMAL.
Definition: ec.c:111
@ IT8516E_LDN_SWUC
Definition: ec.h:9
@ IT8516E_LDN_PM3
Definition: ec.h:16
@ IT8516E_LDN_PM2
Definition: ec.h:15
@ IT8516E_LDN_UART2
Definition: ec.h:8
@ IT8516E_LDN_SMFI
Definition: ec.h:12
@ IT8516E_LDN_UART1
Definition: ec.h:7
@ IT8516E_LDN_PM1
Definition: ec.h:14
@ IT8516E_LDN_MOUSE
Definition: ec.h:10
@ IT8516E_LDN_BRAM
Definition: ec.h:13
@ IT8516E_LDN_KBD
Definition: ec.h:11
@ IT8516E_MODE_THERMAL
Definition: ec.h:23
@ IT8516E_MODE_SPEED
Definition: ec.h:22
@ IT8516E_MODE_AUTO
Definition: ec.h:20
@ IT8516E_MODE_PWM
Definition: ec.h:21
@ IT8516E_SYSTEMP_NONE
Definition: ec.h:27
@ IT8516E_SYSTEMP_LASTPLUSONE
Definition: ec.h:34
fan_mode
Definition: fan_control.h:30
#define CHIP_NAME(X)
Definition: device.h:32
unsigned int type
Definition: edid.c:57
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
enum board_config config
Definition: memory.c:448
unsigned int get_uint_option(const char *name, const unsigned int fallback)
Definition: option.c:116
#define PNP_IO1
Definition: pnp.h:43
#define PNP_IO0
Definition: pnp.h:42
#define PNP_IRQ0
Definition: pnp.h:47
#define PNP_IDX_IO0
Definition: pnp_def.h:5
#define PNP_IDX_IO1
Definition: pnp_def.h:6
void pnp_enable(struct device *dev)
Definition: pnp_device.c:181
void pnp_read_resources(struct device *dev)
Definition: pnp_device.c:114
void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, unsigned int functions, struct pnp_info *info)
Definition: pnp_device.c:371
struct device_operations pnp_ops
Definition: pnp_device.c:199
void pnp_set_resources(struct device *dev)
Definition: pnp_device.c:157
void pnp_enable_resources(struct device *dev)
Definition: pnp_device.c:173
uintptr_t base
Definition: uart.c:17
#define NULL
Definition: stddef.h:19
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164
Definition: pnp.h:37