coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
audio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
5 #include <baseboard/variants.h>
6 #include <variant/sku.h>
7 #include <string.h>
8 #include <drivers/i2c/hid/chip.h>
9 
10 #define RT58_I2C_ADDRESS 0x1a
11 
14 
16 {
17  struct device *mmio_dev = NULL, *child = NULL;
18  struct device *alc_dev = NULL, *da7219_dev = NULL;
19 
20  do {
21  mmio_dev = dev_find_path(mmio_dev, DEVICE_PATH_MMIO);
22  if (!mmio_dev) {
23  printk(BIOS_INFO, "Checking audio codec\n");
24  return;
25  }
26  } while (mmio_dev->path.mmio.addr != APU_I2C0_BASE);
27 
28  while ((child = dev_bus_each_child(mmio_dev->link_list, child)) != NULL) {
29  if (child->path.type != DEVICE_PATH_I2C)
30  continue;
31  if (child->path.i2c.device != RT58_I2C_ADDRESS)
32  continue;
33  if (child->chip_ops == &drivers_i2c_generic_ops) {
34  struct drivers_i2c_generic_config *config = child->chip_info;
35  if (!strcmp(config->hid, "10EC5682"))
36  alc_dev = child;
37  } else if (child->chip_ops == &drivers_i2c_da7219_ops) {
38  da7219_dev = child;
39  }
40  }
41 
42  switch (google_chromeec_get_sku_id()) {
45  /* alc5682 only */
46  if (da7219_dev)
47  da7219_dev->enabled = 0;
48  if (alc_dev)
49  alc_dev->enabled = 1;
50  break;
51  default:
52  /* da7219 only */
53  if (da7219_dev)
54  da7219_dev->enabled = 1;
55  if (alc_dev)
56  alc_dev->enabled = 0;
57  break;
58  }
59 }
#define APU_I2C0_BASE
Definition: iomap.h:14
#define RT58_I2C_ADDRESS
Definition: audio.c:10
struct chip_operations drivers_i2c_da7219_ops
Definition: da7219.c:112
void variant_devtree_update(void)
Definition: audio.c:15
struct chip_operations drivers_i2c_generic_ops
Definition: generic.c:217
#define printk(level,...)
Definition: stdlib.h:16
DEVTREE_CONST struct device * dev_find_path(DEVTREE_CONST struct device *prev_match, enum device_path_type path_type)
Given a Device Path Type, find the device structure.
Definition: device_const.c:53
DEVTREE_CONST struct device * dev_bus_each_child(const struct bus *parent, DEVTREE_CONST struct device *prev_child)
Given a device and previous match iterate through all the children.
Definition: device_const.c:353
uint32_t google_chromeec_get_sku_id(void)
Definition: ec.c:934
@ SKU_TREEYA_ALC5682_AF
Definition: sku.h:7
@ SKU_TREEYA_ALC5682_AE
Definition: sku.h:6
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
enum board_config config
Definition: memory.c:448
@ DEVICE_PATH_I2C
Definition: path.h:11
@ DEVICE_PATH_MMIO
Definition: path.h:21
#define NULL
Definition: stddef.h:19
int strcmp(const char *s1, const char *s2)
Definition: string.c:103
struct mmio_path mmio
Definition: path.h:128
Definition: device.h:107
struct device_path path
Definition: device.h:115
DEVTREE_CONST struct bus * link_list
Definition: device.h:139
unsigned int enabled
Definition: device.h:122
uintptr_t addr
Definition: path.h:106