blob: c54b5303a5f182ccec397e1d8c6790ea02457c3d [file] [log] [blame]
Kevin Chiufb796032021-03-22 19:34:30 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <ec/google/chromeec/ec.h>
4#include <baseboard/variants.h>
5#include <variant/sku.h>
6#include <string.h>
7#include <drivers/i2c/hid/chip.h>
8
9extern struct chip_operations drivers_i2c_generic_ops;
10extern struct chip_operations drivers_i2c_da7219_ops;
11
12void variant_devtree_update(void)
13{
14 uint32_t sku = google_chromeec_get_sku_id();
15 struct device *mmio_dev = NULL, *child = NULL;
16 struct device *alc_dev = NULL, *da7219_dev = NULL;
17
18 while (1) {
19 mmio_dev = dev_find_path(mmio_dev, DEVICE_PATH_MMIO);
20 if (mmio_dev == NULL)
21 break;
22 if (mmio_dev->path.mmio.addr == 0xfedc2000)
23 break;
24 }
25
26 if (mmio_dev == NULL)
27 return;
28
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020029 while ((child = dev_bus_each_child(mmio_dev->downstream, child)) != NULL) {
Kevin Chiufb796032021-03-22 19:34:30 +080030 if (child->path.type != DEVICE_PATH_I2C)
31 continue;
32 if (child->path.i2c.device != 0x1a)
33 continue;
34 if (child->chip_ops == &drivers_i2c_generic_ops) {
35 struct drivers_i2c_generic_config *config = child->chip_info;
36 if (!strcmp(config->hid, "10EC5682"))
37 alc_dev = child;
38 } else if (child->chip_ops == &drivers_i2c_da7219_ops) {
39 da7219_dev = child;
40 }
41 }
42
43 switch (sku) {
44 default:
45 /* da7219 only */
46 if (da7219_dev)
47 da7219_dev->enabled = 1;
48 if (alc_dev)
49 alc_dev->enabled = 0;
50 break;
51 case SKU_BARLA_ALC5682_44:
52 case SKU_BARLA_ALC5682_45:
53 case SKU_BARLA_ALC5682_46:
54 case SKU_BARLA_ALC5682_47:
55 /* alc5682 only */
56 if (da7219_dev)
57 da7219_dev->enabled = 0;
58 if (alc_dev)
59 alc_dev->enabled = 1;
60 break;
61 }
62}