coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
chromeos.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <bootmode.h>
4 #include <boot/coreboot_tables.h>
5 #include <device/pci_ops.h>
6 #include <device/device.h>
9 #include <types.h>
10 #include <vendorcode/google/chromeos/chromeos.h>
11 #include "onboard.h"
12 
13 #include "ec.h"
14 #include <ec/smsc/mec1308/ec.h>
15 
16 void fill_lb_gpios(struct lb_gpios *gpios)
17 {
18  struct lb_gpio chromeos_gpios[] = {
19  /* Recovery: GPIO42 = CHP3_REC_MODE# */
21  "presence"},
22 
23  {100, ACTIVE_HIGH, get_lid_switch(), "lid"},
24 
25  /* Power Button */
26  {101, ACTIVE_LOW, get_power_switch(), "power"},
27 
28  /* Did we load the VGA Option ROM? */
29  /* -1 indicates that this is a pseudo GPIO */
30  {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
31  };
32  lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
33 }
34 
36 {
37  return get_gpio(GPIO_SPI_WP);
38 }
39 
41 {
42  return !get_gpio(GPIO_REC_MODE);
43 }
44 
45 int get_lid_switch(void)
46 {
47  return ec_read(0x83) & 1;
48 }
49 
51 {
52  const pci_devfn_t dev = PCI_DEV(0, 0x1f, 0);
53  u16 gen_pmcon_1 = pci_s_read_config32(dev, GEN_PMCON_1);
54  return (gen_pmcon_1 >> 9) & 1;
55 }
56 
57 static const struct cros_gpio cros_gpios[] = {
58  CROS_GPIO_REC_AL(GPIO_REC_MODE, CROS_GPIO_DEVICE_NAME),
59  CROS_GPIO_WP_AH(GPIO_SPI_WP, CROS_GPIO_DEVICE_NAME),
60 };
61 
void fill_lb_gpios(struct lb_gpios *gpios)
Definition: chromeos.c:9
int get_write_protect_state(void)
Only used if CONFIG(CHROMEOS) is set.
Definition: chromeos.c:15
int gfx_get_init_done(void)
Definition: bootmode.c:10
#define ARRAY_SIZE(a)
Definition: helpers.h:12
u8 ec_read(u8 addr)
Definition: ec.c:107
DECLARE_CROS_GPIOS(cros_gpios)
int get_recovery_mode_switch(void)
HACK: Use Fn-Key as recovery mode switch.
Definition: chromeos.c:29
#define GPIO_SPI_WP
Definition: onboard.h:23
#define GPIO_REC_MODE
Definition: onboard.h:20
int get_lid_switch(void)
Definition: chromeos.c:37
#define ACTIVE_HIGH
Definition: chromeos.c:18
#define ACTIVE_LOW
Definition: chromeos.c:17
int get_gpio(int community_base, int pad0_offset)
Definition: gpio_support.c:148
void lb_add_gpios(struct lb_gpios *gpios, const struct lb_gpio *gpio_table, size_t count)
static __always_inline uint32_t pci_s_read_config32(pci_devfn_t dev, uint16_t reg)
Definition: pci_io_cfg.h:92
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
int get_power_switch(void)
Definition: chromeos.c:50
static const struct cros_gpio cros_gpios[]
Definition: chromeos.c:57
#define CROS_GPIO_DEVICE_NAME
Definition: gpio.h:14
#define GEN_PMCON_1
Definition: lpc.h:56
uint16_t u16
Definition: stdint.h:48