coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ite.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 #include <pc80/keyboard.h>
9 
10 #include "ec.h"
11 #include "ecdefs.h"
12 
14 {
16 }
17 
19  unsigned int fallback,
20  const uint8_t *lut,
21  size_t lut_size)
22 {
23  unsigned int index = get_uint_option(name, fallback);
24  if (index >= lut_size)
25  index = fallback;
26  return lut[index];
27 }
28 
29 static uint16_t ec_get_chip_id(unsigned int port)
30 {
31  return (pnp_read_index(port, ITE_CHIPID1) << 8) |
33 }
34 
35 static void merlin_init(struct device *dev)
36 {
37  if (!dev->enabled)
38  return;
39 
40  /*
41  * The address/data IO port pair for the ite EC are configurable
42  * through the EC domain and are fixed by the EC's firmware blob. If
43  * the value(s) passed through the "dev" structure don't match the
44  * expected values then output severe warnings.
45  */
46  if (dev->path.pnp.port != ITE_FIXED_ADDR) {
47  printk(BIOS_ERR, "ITE: Incorrect ports defined in devicetree.cb.\n");
48  printk(BIOS_ERR, "ITE: Serious operational issues will arise.\n");
49  return;
50  }
51 
52  const uint16_t chip_id = ec_get_chip_id(dev->path.pnp.port);
53 
54  if (chip_id != ITE_CHIPID_VAL) {
55  printk(BIOS_ERR, "ITE: Expected chip ID 0x%04x, but got 0x%04x instead.\n",
56  ITE_CHIPID_VAL, chip_id);
57  return;
58  }
59 
61 
62  /*
63  * Restore settings from CMOS into EC RAM:
64  *
65  * kbl_timeout
66  * fn_ctrl_swap
67  * max_charge
68  * fan_mode
69  * fn_lock_state
70  * trackpad_state
71  * kbl_brightness
72  * kbl_state
73  */
74 
75  /*
76  * Keyboard Backlight Timeout
77  *
78  * Setting: kbl_timeout
79  *
80  * Values: 30 Seconds, 1 Minute, 3 Minutes, 5 Minutes, Never
81  * Default: 30 Seconds
82  *
83  */
84  const uint8_t kbl_timeout[] = {
85  SEC_30,
86  MIN_1,
87  MIN_3,
88  MIN_5,
89  NEVER
90  };
91 
93  get_ec_value_from_option("kbl_timeout",
94  0,
95  kbl_timeout,
96  ARRAY_SIZE(kbl_timeout)));
97 
98  /*
99  * Fn Ctrl Reverse
100  *
101  * Setting: fn_ctrl_swap
102  *
103  * Values: Enabled, Disabled
104  * Default: Disabled
105  *
106  */
107  const uint8_t fn_ctrl_swap[] = {
108  FN_CTRL,
109  CTRL_FN
110  };
111 
113  get_ec_value_from_option("fn_ctrl_swap",
114  1,
115  fn_ctrl_swap,
116  ARRAY_SIZE(fn_ctrl_swap)));
117 
118  /*
119  * Maximum Charge Level
120  *
121  * Setting: max_charge
122  *
123  * Values: 60%, 80%, 100%
124  * Default: 100%
125  *
126  */
127  const uint8_t max_charge[] = {
128  CHARGE_100,
129  CHARGE_80,
130  CHARGE_60
131  };
132 
133  if (CONFIG(EC_STARLABS_MAX_CHARGE))
135  get_ec_value_from_option("max_charge",
136  0,
137  max_charge,
138  ARRAY_SIZE(max_charge)));
139 
140  /*
141  * Fan Mode
142  *
143  * Setting: fan_mode
144  *
145  * Values: Quiet, Normal, Aggressive
146  * Default: Normal
147  *
148  */
149  const uint8_t fan_mode[] = {
150  FAN_NORMAL,
152  FAN_QUIET
153  };
154 
155  if (CONFIG(EC_STARLABS_FAN))
157  get_ec_value_from_option("fan_mode",
158  0,
159  fan_mode,
160  ARRAY_SIZE(fan_mode)));
161 
162  /*
163  * Function Lock
164  *
165  * Setting: fn_lock_state
166  *
167  * Values: Locked, Unlocked
168  * Default: Locked
169  *
170  */
171  const uint8_t fn_lock_state[] = {
172  UNLOCKED,
173  LOCKED
174  };
175 
177  get_ec_value_from_option("fn_lock_state",
178  1,
179  fn_lock_state,
180  ARRAY_SIZE(fn_lock_state)));
181 
182  /*
183  * Trackpad State
184  *
185  * Setting: trackpad_state
186  *
187  * Values: Enabled, Disabled
188  * Default: Enabled
189  *
190  */
191  const uint8_t trackpad_state[] = {
194  };
195 
197  get_ec_value_from_option("trackpad_state",
198  0,
199  trackpad_state,
200  ARRAY_SIZE(trackpad_state)));
201 
202  /*
203  * Keyboard Backlight Brightness
204  *
205  * Setting: kbl_brightness
206  *
207  * Values: Off, Low, High / Off, On
208  * Default: Low
209  *
210  */
211  const uint8_t kbl_brightness[] = {
212  KBL_ON,
213  KBL_OFF,
214  KBL_LOW,
215  KBL_HIGH
216  };
217 
218  if (CONFIG(EC_STARLABS_KBL_LEVELS))
220  get_ec_value_from_option("kbl_brightness",
221  2,
222  kbl_brightness,
223  ARRAY_SIZE(kbl_brightness)));
224  else
226  get_ec_value_from_option("kbl_brightness",
227  0,
228  kbl_brightness,
229  ARRAY_SIZE(kbl_brightness)));
230 
231  /*
232  * Keyboard Backlight State
233  *
234  * Setting: kbl_state
235  *
236  * Values: Off, On
237  * Default: On
238  *
239  */
240  const uint8_t kbl_state[] = {
241  KBL_DISABLED,
243  };
244 
246  get_ec_value_from_option("kbl_state",
247  1,
248  kbl_state,
249  ARRAY_SIZE(kbl_state)));
250 }
251 
252 static struct device_operations ops = {
253  .init = merlin_init,
254  .read_resources = noop_read_resources,
255  .set_resources = noop_set_resources,
256 };
257 
258 static struct pnp_info pnp_dev_info[] = {
259  /* Serial Port 1 (UART1) */
260  { NULL, ITE_SP1, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
261  /* Serial Port 2 (UART2) */
262  { NULL, ITE_SP2, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
263  /* System Wake-Up Control (SWUC) */
264  { NULL, ITE_SWUC, PNP_IO0 | PNP_IRQ0, 0xfff0, },
265  /* KBC / Mouse Interface */
266  { NULL, ITE_SWUC, PNP_IRQ0, },
267  /* KBC / Keyboard Interface */
268  { NULL, ITE_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
269  /* Consumer IR (CIR) */
270  { NULL, ITE_IR, PNP_IO0 | PNP_IRQ0, 0xfff8, },
271  /* Shared Memory / Flash Interface (SMFI) */
272  { NULL, ITE_SMFI, PNP_IO0 | PNP_IRQ0, 0xfff0, },
273  /* RTC-like Timer (RCTC) */
275  0xfffe, 0xfffe, 0xfffe, 0xfffe, },
276  /* Power Management I/F Channel 1 (PMC1) */
277  { NULL, ITE_PMC1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
278  /* Power Management I/F Channel 2 (PMC2) */
279  { NULL, ITE_PMC2, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IRQ0, 0x07fc,
280  0x07fc, 0xfff0, },
281  /* Serial Peripheral Interface (SSPI) */
282  { NULL, ITE_SSPI, PNP_IO0 | PNP_IRQ0, 0xfff8, },
283  /* Platform Environment Control Interface (PECI) */
284  { NULL, ITE_PECI, PNP_IRQ0, 0xfff8, },
285  /* Power Management I/F Channel 3 (PMC3) */
286  { NULL, ITE_PMC3, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
287  /* Power Management I/F Channel 4 (PMC4) */
288  { NULL, ITE_PMC4, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
289  /* Power Management I/F Channel 5 (PMC5) */
290  { NULL, ITE_PMC5, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
291 };
292 
293 static void enable_dev(struct device *dev)
294 {
296 }
297 
299  CHIP_NAME("ITE EC")
300  .enable_dev = enable_dev
301 };
#define ITE_CHIPID_VAL
Definition: ecdefs.h:14
#define ECRAM_KBL_TIMEOUT
Definition: ecdefs.h:20
#define ECRAM_TRACKPAD_STATE
Definition: ecdefs.h:17
#define ECRAM_FN_LOCK_STATE
Definition: ecdefs.h:21
#define ECRAM_KBL_STATE
Definition: ecdefs.h:18
#define ECRAM_KBL_BRIGHTNESS
Definition: ecdefs.h:19
#define ECRAM_MAX_CHARGE
Definition: ecdefs.h:23
#define ECRAM_FN_CTRL_REVERSE
Definition: ecdefs.h:22
#define ECRAM_FAN_MODE
Definition: ecdefs.h:24
const char * name
Definition: mmu.c:92
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
u8 ec_read(u8 addr)
Definition: ec.c:107
int ec_write(u8 addr, u8 data)
Definition: ec.c:115
#define LOCKED
Definition: ec.h:81
#define CTRL_FN
Definition: ec.h:67
#define ITE_RTCT
Definition: ec.h:25
#define ITE_PECI
Definition: ec.h:29
#define ITE_PMC1
Definition: ec.h:26
#define CHARGE_80
Definition: ec.h:71
#define ITE_CHIPID1
Definition: ec.h:46
#define KBL_ENABLED
Definition: ec.h:95
#define TRACKPAD_ENABLED
Definition: ec.h:84
#define ITE_PMC2
Definition: ec.h:27
#define ITE_SMFI
Definition: ec.h:24
#define MIN_3
Definition: ec.h:61
#define SEC_30
Definition: ec.h:59
#define KBL_OFF
Definition: ec.h:89
#define KBL_LOW
Definition: ec.h:90
#define ITE_PMC5
Definition: ec.h:32
#define ITE_CHIPID2
Definition: ec.h:47
#define MIN_1
Definition: ec.h:60
#define ECRAM_MINOR_VERSION
Definition: ec.h:52
#define ITE_SP1
Definition: ec.h:18
#define TRACKPAD_DISABLED
Definition: ec.h:85
#define KBL_ON
Definition: ec.h:88
#define FAN_NORMAL
Definition: ec.h:75
#define CHARGE_100
Definition: ec.h:70
#define ITE_PMC3
Definition: ec.h:30
#define ITE_FIXED_ADDR
Definition: ec.h:14
#define FN_CTRL
Definition: ec.h:66
#define NEVER
Definition: ec.h:63
#define ITE_IR
Definition: ec.h:23
#define ITE_KBCK
Definition: ec.h:22
#define KBL_HIGH
Definition: ec.h:91
#define CHARGE_60
Definition: ec.h:72
#define ITE_SSPI
Definition: ec.h:28
#define ECRAM_MAJOR_VERSION
Definition: ec.h:51
#define FAN_QUIET
Definition: ec.h:77
#define MIN_5
Definition: ec.h:62
#define KBL_DISABLED
Definition: ec.h:94
#define ITE_SWUC
Definition: ec.h:20
#define UNLOCKED
Definition: ec.h:80
#define FAN_AGGRESSIVE
Definition: ec.h:76
#define ITE_PMC4
Definition: ec.h:31
#define ITE_SP2
Definition: ec.h:19
fan_mode
Definition: fan_control.h:30
port
Definition: i915.h:29
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
static uint16_t ec_get_chip_id(unsigned int port)
Definition: ite.c:29
static void enable_dev(struct device *dev)
Definition: ite.c:293
static struct device_operations ops
Definition: ite.c:252
uint16_t ec_get_version(void)
Definition: ite.c:13
static void merlin_init(struct device *dev)
Definition: ite.c:35
static struct pnp_info pnp_dev_info[]
Definition: ite.c:258
struct chip_operations ec_starlabs_merlin_ops
Definition: ite.c:298
static uint8_t get_ec_value_from_option(const char *name, unsigned int fallback, const uint8_t *lut, size_t lut_size)
Definition: ite.c:18
uint8_t pc_keyboard_init(uint8_t probe_aux)
Definition: keyboard.c:229
#define NO_AUX_DEVICE
Definition: keyboard.h:6
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
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_IO2
Definition: pnp.h:44
#define PNP_IO0
Definition: pnp.h:42
#define PNP_IRQ0
Definition: pnp.h:47
#define PNP_IO3
Definition: pnp.h:45
static u8 pnp_read_index(u16 port, u8 reg)
Definition: pnp.h: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
#define NULL
Definition: stddef.h:19
unsigned short uint16_t
Definition: stdint.h:11
unsigned char uint8_t
Definition: stdint.h:8
void(* init)(struct device *dev)
Definition: device.h:42
struct pnp_path pnp
Definition: path.h:117
Definition: device.h:107
struct device_path path
Definition: device.h:115
unsigned int enabled
Definition: device.h:122
Definition: pnp.h:37
unsigned int port
Definition: path.h:58