coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
hid.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpigen_dsm.h>
4 #include <acpi/acpi_device.h>
5 #include <assert.h>
6 #include <device/device.h>
7 #include <string.h>
8 #include "chip.h"
9 #include <gpio.h>
10 #include <console/console.h>
11 
12 #if CONFIG(HAVE_ACPI_TABLES)
13 static void i2c_hid_fill_dsm(const struct device *dev)
14 {
16  struct dsm_i2c_hid_config dsm_config = {
17  .hid_desc_reg_offset = config->hid_desc_reg_offset,
18  };
19 
20  acpigen_write_dsm_i2c_hid(&dsm_config);
21 }
22 
23 static void i2c_hid_fill_ssdt_generator(const struct device *dev)
24 {
26  config->generic.cid = I2C_HID_CID;
27  i2c_generic_fill_ssdt(dev, &i2c_hid_fill_dsm, &config->generic);
28 }
29 
30 static const char *i2c_hid_acpi_name(const struct device *dev)
31 {
32  static char name[5];
34  if (config->generic.name)
35  return config->generic.name;
36 
37  snprintf(name, sizeof(name), "H%03.3X", dev->path.i2c.device);
38  name[4] = '\0';
39  return name;
40 }
41 #endif
42 
43 static struct device_operations i2c_hid_ops = {
45  .set_resources = noop_set_resources,
46 #if CONFIG(HAVE_ACPI_TABLES)
47  .acpi_name = i2c_hid_acpi_name,
48  .acpi_fill_ssdt = i2c_hid_fill_ssdt_generator,
49 #endif
50 };
51 
52 static void i2c_hid_enable(struct device *dev)
53 {
55 
56  if (!config)
57  return;
58 
59  /* Check if device is present by reading GPIO */
60  if (config->generic.device_present_gpio) {
61  int present = gpio_get(config->generic.device_present_gpio);
62  present ^= config->generic.device_present_gpio_invert;
63 
64  printk(BIOS_INFO, "%s is %spresent\n",
65  dev->chip_ops->name, present ? "" : "not ");
66 
67  if (!present) {
68  dev->enabled = 0;
69  return;
70  }
71  }
72 
73  /*
74  * Ensure that I2C HID devices use level triggered interrupts as per ACPI
75  * I2C HID requirement. Check interrupt and GPIO interrupt.
76  */
77  if ((!config->generic.irq_gpio.pin_count &&
78  config->generic.irq.mode != ACPI_IRQ_LEVEL_TRIGGERED) ||
79  (config->generic.irq_gpio.pin_count &&
80  config->generic.irq_gpio.irq.mode != ACPI_IRQ_LEVEL_TRIGGERED)) {
81  printk(BIOS_ERR, "%s IRQ is not level triggered.\n", config->generic.hid);
82  BUG();
83  }
84 
85  dev->ops = &i2c_hid_ops;
86 
87  if (config && config->generic.desc) {
88  dev->name = config->generic.desc;
89  }
90 }
91 
93  CHIP_NAME("I2C HID Device")
94  .enable_dev = i2c_hid_enable
95 };
@ ACPI_IRQ_LEVEL_TRIGGERED
Definition: acpi_device.h:69
void acpigen_write_dsm_i2c_hid(struct dsm_i2c_hid_config *config)
Definition: acpigen_dsm.c:43
const char * name
Definition: mmu.c:92
#define BUG()
Definition: assert.h:65
#define printk(level,...)
Definition: stdlib.h:16
void i2c_generic_fill_ssdt(const struct device *dev, void(*callback)(const struct device *dev), struct drivers_i2c_generic_config *config)
#define I2C_HID_CID
Definition: chip.h:8
static struct device_operations i2c_hid_ops
Definition: hid.c:43
static void i2c_hid_enable(struct device *dev)
Definition: hid.c:52
struct chip_operations drivers_i2c_hid_ops
Definition: hid.c:92
#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
int gpio_get(gpio_t gpio)
Definition: gpio.c:166
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
enum board_config config
Definition: memory.c:448
const char * name
Definition: device.h:29
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct i2c_path i2c
Definition: path.h:118
Definition: device.h:107
struct chip_operations * chip_ops
Definition: device.h:144
const char * name
Definition: device.h:145
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int enabled
Definition: device.h:122
uint8_t hid_desc_reg_offset
Definition: acpigen_dsm.h:9
unsigned int device
Definition: path.h:63
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35