coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
nuvoton.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 {
32 }
33 
34 static void merlin_init(struct device *dev)
35 {
36  if (!dev->enabled)
37  return;
38 
39  /*
40  * The address/data IO port pair for the Nuvoton EC are configurable
41  * through the EC domain and are fixed by the EC's firmware blob. If
42  * the value(s) passed through the "dev" structure don't match the
43  * expected values then output severe warnings.
44  */
45  if (dev->path.pnp.port != NUVOTON_FIXED_ADDR) {
46  printk(BIOS_ERR, "NUVOTON: Incorrect ports defined in devicetree.cb.\n");
47  printk(BIOS_ERR, "NUVOTON: Serious operational issues will arise.\n");
48  return;
49  }
50 
51  const uint16_t chip_id = ec_get_chip_id(dev->path.pnp.port);
52 
53  if (chip_id != NUVOTON_CHIPID_VAL) {
54  printk(BIOS_ERR, "NUVOTON: Expected chip ID 0x%04x, but got 0x%04x instead.\n",
55  NUVOTON_CHIPID_VAL, chip_id);
56  return;
57  }
58 
60 
61  /*
62  * Restore settings from CMOS into EC RAM:
63  *
64  * kbl_timeout
65  * fn_ctrl_swap
66  * max_charge
67  * fan_mode
68  * fn_lock_state
69  * trackpad_state
70  * kbl_brightness
71  * kbl_state
72  */
73 
74  /*
75  * Keyboard Backlight Timeout
76  *
77  * Setting: kbl_timeout
78  *
79  * Values: 30 Seconds, 1 Minute, 3 Minutes, 5 Minutes, Never
80  * Default: 30 Seconds
81  *
82  */
83  const uint8_t kbl_timeout[] = {
84  SEC_30,
85  MIN_1,
86  MIN_3,
87  MIN_5,
88  NEVER
89  };
90 
92  get_ec_value_from_option("kbl_timeout",
93  0,
94  kbl_timeout,
95  ARRAY_SIZE(kbl_timeout)));
96 
97  /*
98  * Fn Ctrl Reverse
99  *
100  * Setting: fn_ctrl_swap
101  *
102  * Values: Enabled, Disabled
103  * Default: Disabled
104  *
105  */
106  const uint8_t fn_ctrl_swap[] = {
107  FN_CTRL,
108  CTRL_FN
109  };
110 
112  get_ec_value_from_option("fn_ctrl_swap",
113  1,
114  fn_ctrl_swap,
115  ARRAY_SIZE(fn_ctrl_swap)));
116 
117  /*
118  * Maximum Charge Level
119  *
120  * Setting: max_charge
121  *
122  * Values: 60%, 80%, 100%
123  * Default: 100%
124  *
125  */
126  const uint8_t max_charge[] = {
127  CHARGE_100,
128  CHARGE_80,
129  CHARGE_60
130  };
131 
132  if (CONFIG(EC_STARLABS_MAX_CHARGE))
134  get_ec_value_from_option("max_charge",
135  0,
136  max_charge,
137  ARRAY_SIZE(max_charge)));
138 
139  /*
140  * Fan Mode
141  *
142  * Setting: fan_mode
143  *
144  * Values: Quiet, Normal, Aggressive
145  * Default: Normal
146  *
147  */
148  const uint8_t fan_mode[] = {
149  FAN_NORMAL,
151  FAN_QUIET
152  };
153 
154  if (CONFIG(EC_STARLABS_FAN))
156  get_ec_value_from_option("fan_mode",
157  0,
158  fan_mode,
159  ARRAY_SIZE(fan_mode)));
160 
161  /*
162  * Function Lock
163  *
164  * Setting: fn_lock_state
165  *
166  * Values: Locked, Unlocked
167  * Default: Locked
168  *
169  */
170  const uint8_t fn_lock_state[] = {
171  UNLOCKED,
172  LOCKED
173  };
174 
176  get_ec_value_from_option("fn_lock_state",
177  1,
178  fn_lock_state,
179  ARRAY_SIZE(fn_lock_state)));
180 
181  /*
182  * Trackpad State
183  *
184  * Setting: trackpad_state
185  *
186  * Values: Enabled, Disabled
187  * Default: Enabled
188  *
189  */
190  const uint8_t trackpad_state[] = {
193  };
194 
196  get_ec_value_from_option("trackpad_state",
197  0,
198  trackpad_state,
199  ARRAY_SIZE(trackpad_state)));
200 
201  /*
202  * Keyboard Backlight Brightness
203  *
204  * Setting: kbl_brightness
205  *
206  * Values: Off, Low, High / Off, On
207  * Default: Low
208  *
209  */
210  const uint8_t kbl_brightness[] = {
211  KBL_ON,
212  KBL_OFF,
213  KBL_LOW,
214  KBL_HIGH
215  };
216 
217  if (CONFIG(EC_STARLABS_KBL_LEVELS))
219  get_ec_value_from_option("kbl_brightness",
220  2,
221  kbl_brightness,
222  ARRAY_SIZE(kbl_brightness)));
223  else
225  get_ec_value_from_option("kbl_brightness",
226  0,
227  kbl_brightness,
228  ARRAY_SIZE(kbl_brightness)));
229 
230  /*
231  * Keyboard Backlight State
232  *
233  * Setting: kbl_state
234  *
235  * Values: Off, On
236  * Default: On
237  *
238  */
239  const uint8_t kbl_state[] = {
240  KBL_DISABLED,
242  };
243 
245  get_ec_value_from_option("kbl_state",
246  1,
247  kbl_state,
248  ARRAY_SIZE(kbl_state)));
249 }
250 
251 static struct device_operations ops = {
252  .init = merlin_init,
253  .read_resources = noop_read_resources,
254  .set_resources = noop_set_resources,
255 };
256 
257 static struct pnp_info pnp_dev_info[] = {
258  /* System Wake-Up Control (SWUC) */
259  { NULL, NUVOTON_MSWC, PNP_IO0 | PNP_IRQ0, 0xfff0, },
260  /* KBC / Mouse Interface */
261  { NULL, NUVOTON_KBCM, PNP_IRQ0, },
262  /* KBC / Keyboard Interface */
263  { NULL, NUVOTON_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
264  /* Shared Memory / Flash Interface (SMFI) */
265  { NULL, NUVOTON_SHM, PNP_IO0 | PNP_IRQ0, 0xfff0, },
266  /* Power Management I/F Channel 1 (PMC1) */
267  { NULL, NUVOTON_PM1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
268  /* Power Management I/F Channel 2 (PMC2) */
269  { NULL, NUVOTON_PM2, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IRQ0, 0x07fc,
270  0x07fc, 0xfff0, },
271  /* Power Management I/F Channel 3 (PMC3) */
272  { NULL, NUVOTON_PM3, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
273  /* Extended Shared Memory (ESHM) */
274  { NULL, NUVOTON_ESHM },
275  /* Power Management I/F Channel 4 (PMC4) */
276  { NULL, NUVOTON_PM4, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
277 };
278 
279 static void enable_dev(struct device *dev)
280 {
282 }
283 
285  CHIP_NAME("NUVOTON EC")
286  .enable_dev = enable_dev
287 };
#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 NUVOTON_PM3
Definition: ec.h:41
#define CTRL_FN
Definition: ec.h:67
#define CHARGE_80
Definition: ec.h:71
#define KBL_ENABLED
Definition: ec.h:95
#define NUVOTON_MSWC
Definition: ec.h:35
#define TRACKPAD_ENABLED
Definition: ec.h:84
#define NUVOTON_CHIPID
Definition: ec.h:48
#define MIN_3
Definition: ec.h:61
#define NUVOTON_PM4
Definition: ec.h:43
#define SEC_30
Definition: ec.h:59
#define KBL_OFF
Definition: ec.h:89
#define KBL_LOW
Definition: ec.h:90
#define NUVOTON_KBCK
Definition: ec.h:37
#define MIN_1
Definition: ec.h:60
#define ECRAM_MINOR_VERSION
Definition: ec.h:52
#define NUVOTON_PM2
Definition: ec.h:40
#define TRACKPAD_DISABLED
Definition: ec.h:85
#define NUVOTON_KBCM
Definition: ec.h:36
#define NUVOTON_SHM
Definition: ec.h:38
#define KBL_ON
Definition: ec.h:88
#define FAN_NORMAL
Definition: ec.h:75
#define CHARGE_100
Definition: ec.h:70
#define FN_CTRL
Definition: ec.h:66
#define NEVER
Definition: ec.h:63
#define NUVOTON_FIXED_ADDR
Definition: ec.h:15
#define KBL_HIGH
Definition: ec.h:91
#define CHARGE_60
Definition: ec.h:72
#define ECRAM_MAJOR_VERSION
Definition: ec.h:51
#define FAN_QUIET
Definition: ec.h:77
#define NUVOTON_PM1
Definition: ec.h:39
#define MIN_5
Definition: ec.h:62
#define KBL_DISABLED
Definition: ec.h:94
#define NUVOTON_ESHM
Definition: ec.h:42
#define UNLOCKED
Definition: ec.h:80
#define FAN_AGGRESSIVE
Definition: ec.h:76
fan_mode
Definition: fan_control.h:30
#define NUVOTON_CHIPID_VAL
Definition: ecdefs.h:14
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
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
static uint16_t ec_get_chip_id(unsigned int port)
Definition: nuvoton.c:29
static void enable_dev(struct device *dev)
Definition: nuvoton.c:279
static struct device_operations ops
Definition: nuvoton.c:251
uint16_t ec_get_version(void)
Definition: nuvoton.c:13
static void merlin_init(struct device *dev)
Definition: nuvoton.c:34
static struct pnp_info pnp_dev_info[]
Definition: nuvoton.c:257
struct chip_operations ec_starlabs_merlin_ops
Definition: nuvoton.c:284
static uint8_t get_ec_value_from_option(const char *name, unsigned int fallback, const uint8_t *lut, size_t lut_size)
Definition: nuvoton.c:18
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
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