blob: 996ea1f2b2f9ef333073a426f7d71eb6f5d6a108 [file] [log] [blame]
Aaron Durbine7f47802018-07-25 09:12:10 -06001/*
2 * This file is part of the coreboot project.
3 *
Patrick Georgi5b2a2d02018-09-26 20:46:04 +02004 * Copyright 2018 Google LLC
Aaron Durbine7f47802018-07-25 09:12:10 -06005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi_device.h>
17#include <baseboard/variants.h>
18#include <boardid.h>
19#include <device/device.h>
20#include <drivers/i2c/generic/chip.h>
21#include <drivers/i2c/hid/chip.h>
22#include <soc/gpio.h>
23#include <soc/pci_devs.h>
24#include <string.h>
Peichao Wangcfab6f62018-09-19 10:55:12 +080025#include <ec/google/chromeec/ec.h>
26
27#define SKU_UNKNOWN 0xFFFFFFFF
Aaron Durbine7f47802018-07-25 09:12:10 -060028
29extern struct chip_operations drivers_i2c_generic_ops;
30extern struct chip_operations drivers_i2c_hid_ops;
31
32void variant_update_devtree(struct device *dev)
33{
34 uint32_t bid;
Peichao Wangcfab6f62018-09-19 10:55:12 +080035 uint32_t sku_id = SKU_UNKNOWN;
Aaron Durbine7f47802018-07-25 09:12:10 -060036 struct device *touchscreen_i2c_host;
37 struct device *child;
38 const struct bus *children_bus;
39 static const struct acpi_gpio new_enable_gpio =
40 ACPI_GPIO_OUTPUT_ACTIVE_HIGH(GPIO_146);
41
42 bid = board_id();
43
44 /* Nothing to update. */
45 if (bid == UNDEFINED_STRAPPING_ID || bid < 1)
46 return;
47
48 touchscreen_i2c_host = dev_find_slot(0, PCH_DEVFN_I2C7);
49
50 if (touchscreen_i2c_host == NULL)
51 return;
52
Peichao Wangcfab6f62018-09-19 10:55:12 +080053 /* According to the sku id decide whether update touch
54 * screen device information:
55 * 1. sku id is 1 then dev->enabled = 0.
56 */
57 google_chromeec_cbi_get_sku_id(&sku_id);
58 if (sku_id == 1) {
59 touchscreen_i2c_host->enabled = 0;
60 return;
61 }
62
Aaron Durbine7f47802018-07-25 09:12:10 -060063 children_bus = touchscreen_i2c_host->link_list;
64 child = NULL;
65
66 /* Find all children on bus to update touchscreen enable gpio. */
67 while ((child = dev_bus_each_child(children_bus, child)) != NULL) {
68 struct drivers_i2c_generic_config *cfg;
69
70 /* No configration to change. */
71 if (child->chip_info == NULL)
72 continue;
73
74 if (child->chip_ops == &drivers_i2c_generic_ops)
75 cfg = child->chip_info;
76 else if (child->chip_ops == &drivers_i2c_hid_ops) {
77 struct drivers_i2c_hid_config *hid_cfg;
78 hid_cfg = child->chip_info;
79 cfg = &hid_cfg->generic;
80 } else
81 continue;
82
83 /* Update the enable gpio. */
84 memcpy(&cfg->enable_gpio, &new_enable_gpio,
85 sizeof(new_enable_gpio));
86 }
87}