blob: 795d96ef9b8a2eb3127942e9a6ec33be6d201a10 [file] [log] [blame]
Angel Pons8a7d7862020-04-05 13:21:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Shelley Chen243dc392017-03-15 15:25:48 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
David Wu80496f02018-09-14 21:30:39 +08004#include <baseboard/variants.h>
Kyösti Mälkkibe7692a2021-11-03 17:54:14 +02005#include <bootmode.h>
Shelley Chen8c81c6a2017-06-29 14:58:59 -07006#include <chip.h>
Elyes HAOUAS187655c2019-10-30 09:06:43 +01007#include <console/console.h>
Furquan Shaikhfb9f3202019-10-23 09:52:32 -07008#include <delay.h>
Shelley Chen243dc392017-03-15 15:25:48 -07009#include <device/device.h>
10#include <ec/ec.h>
Shelley Chenbdfc5f52017-09-28 10:26:26 -070011#include <ec/google/chromeec/ec.h>
12#include <gpio.h>
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +053013#include <intelblocks/power_limit.h>
Shelley Chena35ad0e2017-11-21 15:47:12 -080014#include <smbios.h>
Shelley Chendb287aa2017-06-09 12:56:08 -070015#include <soc/pci_devs.h>
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +080016#include <soc/nhlt.h>
Elyes Haouasbdd03c22024-05-27 11:20:07 +020017#include <stdio.h>
Furquan Shaikhfb9f3202019-10-23 09:52:32 -070018#include <timer.h>
Shelley Chen243dc392017-03-15 15:25:48 -070019
Furquan Shaikhfb9f3202019-10-23 09:52:32 -070020#include <variant/gpio.h>
21
Shelley Chen4fef7812018-01-16 13:20:04 -080022#define FIZZ_SKU_ID_I7_U42 0x4
23#define FIZZ_SKU_ID_I5_U42 0x5
24#define FIZZ_SKU_ID_I3_U42 0x6
25#define FIZZ_SKU_ID_I7_U22 0x3
26#define FIZZ_SKU_ID_I5_U22 0x2
27#define FIZZ_SKU_ID_I3_U22 0x1
28#define FIZZ_SKU_ID_CEL_U22 0x0
29#define FIZZ_PL2_U42 44
30#define FIZZ_PL2_U22 29
31#define FIZZ_PSYSPL2_U22 65
32#define FIZZ_PSYSPL2_U42 90
Shelley Chenc12dff92018-01-31 15:57:43 -080033#define FIZZ_MAX_TIME_WINDOW 6
34#define FIZZ_MIN_DUTYCYCLE 4
Shelley Chenbdfc5f52017-09-28 10:26:26 -070035/*
36 * For type-C chargers, set PL2 to 90% of max power to account for
37 * cable loss and FET Rdson loss in the path from the source.
38 */
Shelley Chene87d3cd2018-01-26 12:50:54 -080039#define SET_PSYSPL2(w) (9 * (w) / 10)
Shelley Chenbdfc5f52017-09-28 10:26:26 -070040
Daisuke Nojiri05927762018-02-01 07:46:02 -080041static uint8_t read_sku_id_from_gpio(void)
Daisuke Nojiria0ab7642017-11-28 14:15:51 -080042{
Daisuke Nojiria0ab7642017-11-28 14:15:51 -080043 const gpio_t sku_id_gpios[] = {
44 GPIO_SKU_ID0,
45 GPIO_SKU_ID1,
46 GPIO_SKU_ID2,
47 GPIO_SKU_ID3,
48 };
Daisuke Nojiri05927762018-02-01 07:46:02 -080049 return gpio_base2_value(sku_id_gpios, ARRAY_SIZE(sku_id_gpios));
50}
51
52static uint8_t board_sku_id(void)
53{
54 static int sku_id = -1;
55
56 if (sku_id < 0) {
57 uint32_t id;
58 if (google_chromeec_cbi_get_sku_id(&id))
59 /* TODO: Once transition completes, raise error instead
60 of returning gpio value which could be unintended. */
61 /* Reading from EC may succeed next time but we do not
62 want to return different values. So, we cache the
63 value read from GPIOs. */
64 id = read_sku_id_from_gpio();
65 sku_id = id;
66 }
67
68 return sku_id;
Daisuke Nojiria0ab7642017-11-28 14:15:51 -080069}
70
Shelley Chen8c81c6a2017-06-29 14:58:59 -070071/*
Shelley Chen750ec942018-01-08 18:24:03 -080072 * mainboard_set_power_limits
Shelley Chen8c81c6a2017-06-29 14:58:59 -070073 *
Shelley Chen750ec942018-01-08 18:24:03 -080074 * Set Pl2 and SysPl2 values based on detected charger.
Shelley Chen4fef7812018-01-16 13:20:04 -080075 * If detected barrel jack, use values below based on SKU.
Shelley Chenc12dff92018-01-31 15:57:43 -080076 * definitions:
77 * x = no value entered. Use default value in parenthesis.
78 * will set 0 to anything that shouldn't be set.
79 * n = max value of power adapter.
80 * +-------------+-----+---------+-----------+-------+
81 * | sku_id | PL2 | PsysPL2 | PsysPL3 | PL4 |
82 * +-------------+-----+---------+-----------+-------+
83 * | i7 U42 | 44 | 81 | x(.85PL4) | x(71) |
84 * | i5 U42 | 44 | 81 | x(.85PL4) | x(71) |
85 * | i3 U42 | 44 | 81 | x(.85PL4) | x(71) |
86 * | i7 U22 | 29 | 58 | x(.85PL4) | x(43) |
87 * | i5 U22 | 29 | 58 | x(.85PL4) | x(43) |
88 * | i3 U22 | 29 | 58 | x(.85PL4) | x(43) |
89 * | celeron U22 | 29 | 58 | x(.85PL4) | x(43) |
90 * +-------------+-----+---------+-----------+-------+
Shelley Chene87d3cd2018-01-26 12:50:54 -080091 * For USB C charger:
Shelley Chenc12dff92018-01-31 15:57:43 -080092 * +-------------+-----+---------+---------+-------+
93 * | Max Power(W)| PL2 | PsysPL2 | PsysPL3 | PL4 |
94 * +-------------+-----+---------+---------+-------+
95 * | 60 (U42) | 44 | 54 | 54 | 54 |
96 * | 60 (U22) | 29 | 54 | 54 | x(43) |
97 * | n (U42) | 44 | .9n | .9n | .9n |
98 * | n (U22) | 29 | .9n | .9n | x(43) |
99 * +-------------+-----+---------+---------+-------+
Shelley Chen8c81c6a2017-06-29 14:58:59 -0700100 */
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +0530101static void mainboard_set_power_limits(struct soc_power_limits_config *conf)
Shelley Chen8c81c6a2017-06-29 14:58:59 -0700102{
Shelley Chenbdfc5f52017-09-28 10:26:26 -0700103 enum usb_chg_type type;
104 u32 watts;
Gaggery Tsai52f18df2020-03-25 11:34:25 -0700105 u16 volts_mv, current_ma;
Shelley Chen750ec942018-01-08 18:24:03 -0800106 u32 pl2, psyspl2;
Gaggery Tsai52f18df2020-03-25 11:34:25 -0700107 int rv = google_chromeec_get_usb_pd_power_info(&type, &current_ma, &volts_mv);
Shelley Chen4fef7812018-01-16 13:20:04 -0800108 uint8_t sku = board_sku_id();
109 const uint32_t u42_mask = (1 << FIZZ_SKU_ID_I7_U42) |
110 (1 << FIZZ_SKU_ID_I5_U42) |
111 (1 << FIZZ_SKU_ID_I3_U42);
Shelley Chenbdfc5f52017-09-28 10:26:26 -0700112
Shelley Chene87d3cd2018-01-26 12:50:54 -0800113 /* PL2 value is sku-based, no matter what charger we are using */
114 pl2 = FIZZ_PL2_U22;
115 if ((1 << sku) & u42_mask)
116 pl2 = FIZZ_PL2_U42;
Shelley Chenc12dff92018-01-31 15:57:43 -0800117 conf->tdp_psyspl3 = conf->tdp_pl4 = 0;
Shelley Chene87d3cd2018-01-26 12:50:54 -0800118
Shelley Chenbdfc5f52017-09-28 10:26:26 -0700119 /* If we can't get charger info or not PD charger, assume barrel jack */
120 if (rv != 0 || type != USB_CHG_TYPE_PD) {
Shelley Chene87d3cd2018-01-26 12:50:54 -0800121 /* using the barrel jack, get PsysPL2 based on sku id */
Shelley Chen4fef7812018-01-16 13:20:04 -0800122 psyspl2 = FIZZ_PSYSPL2_U22;
123 /* Running a U42 SKU */
Shelley Chene87d3cd2018-01-26 12:50:54 -0800124 if ((1 << sku) & u42_mask)
Shelley Chen4fef7812018-01-16 13:20:04 -0800125 psyspl2 = FIZZ_PSYSPL2_U42;
Shelley Chen750ec942018-01-08 18:24:03 -0800126 } else {
Shelley Chenc12dff92018-01-31 15:57:43 -0800127 /* Detected TypeC. Base on max value of adapter */
Gaggery Tsai52f18df2020-03-25 11:34:25 -0700128 watts = ((u32)volts_mv * current_ma) / 1000000;
Shelley Chen750ec942018-01-08 18:24:03 -0800129 psyspl2 = watts;
Shelley Chenc12dff92018-01-31 15:57:43 -0800130 conf->tdp_psyspl3 = SET_PSYSPL2(psyspl2);
131 /* set max possible time window */
132 conf->tdp_psyspl3_time = FIZZ_MAX_TIME_WINDOW;
133 /* set minimum duty cycle */
134 conf->tdp_psyspl3_dutycycle = FIZZ_MIN_DUTYCYCLE;
135 if ((1 << sku) & u42_mask)
136 conf->tdp_pl4 = SET_PSYSPL2(psyspl2);
Shelley Chen750ec942018-01-08 18:24:03 -0800137 }
Shelley Chenbdfc5f52017-09-28 10:26:26 -0700138
Shelley Chenc12dff92018-01-31 15:57:43 -0800139 conf->tdp_pl2_override = pl2;
Shelley Chene87d3cd2018-01-26 12:50:54 -0800140 /* set psyspl2 to 90% of max adapter power */
Shelley Chenc12dff92018-01-31 15:57:43 -0800141 conf->tdp_psyspl2 = SET_PSYSPL2(psyspl2);
Shelley Chen8c81c6a2017-06-29 14:58:59 -0700142}
143
Daisuke Nojiri05927762018-02-01 07:46:02 -0800144static uint8_t read_oem_id_from_gpio(void)
Shelley Chena35ad0e2017-11-21 15:47:12 -0800145{
Shelley Chena35ad0e2017-11-21 15:47:12 -0800146 const gpio_t oem_id_gpios[] = {
147 GPIO_OEM_ID1,
148 GPIO_OEM_ID2,
149 GPIO_OEM_ID3,
150 };
Daisuke Nojiri05927762018-02-01 07:46:02 -0800151 return gpio_base2_value(oem_id_gpios, ARRAY_SIZE(oem_id_gpios));
152}
153
154static uint8_t board_oem_id(void)
155{
156 static int oem_id = -1;
157
158 if (oem_id < 0) {
159 uint32_t id;
160 if (google_chromeec_cbi_get_oem_id(&id))
161 /* TODO: Once transition completes, raise error instead
162 of returning gpio value which could be unintended. */
163 /* Reading from EC may succeed next time but we do not
164 want to return different values. So, we cache the
165 value read from GPIOs. */
166 id = read_oem_id_from_gpio();
167 oem_id = id;
168 }
169
170 return oem_id;
Shelley Chena35ad0e2017-11-21 15:47:12 -0800171}
172
Nico Huberebd8a4f2017-11-01 09:49:16 +0100173const char *smbios_system_sku(void)
Shelley Chena35ad0e2017-11-21 15:47:12 -0800174{
Jeff Chase71090c62020-02-24 18:43:23 -0500175 static char sku_str[7]; /* sku{0..255} */
Shelley Chena35ad0e2017-11-21 15:47:12 -0800176
177 snprintf(sku_str, sizeof(sku_str), "sku%d", board_oem_id());
178
179 return sku_str;
180}
181
Matt DeVillier13eb2372018-06-09 01:31:00 -0500182const char *fizz_oem_name[] = {
183 "Kench",
184 "Teemo",
185 "Sion",
186 "Wukong",
187 "Wukong",
188 "Wukong",
189 "Teemo",
Matt DeVilliere912bb92023-11-03 13:39:50 -0500190 "Karma",
Matt DeVillier13eb2372018-06-09 01:31:00 -0500191 "Jax",
Matt DeVilliere912bb92023-11-03 13:39:50 -0500192 "Endeavour",
Matt DeVillier13eb2372018-06-09 01:31:00 -0500193 "Excelsior"
194};
195
196const char *smbios_mainboard_product_name(void)
197{
198 return fizz_oem_name[board_oem_id()];
199}
200
Elyes HAOUASd129d432018-05-04 20:23:33 +0200201static void mainboard_init(struct device *dev)
Shelley Chen243dc392017-03-15 15:25:48 -0700202{
203 mainboard_ec_init();
204}
205
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +0800206static unsigned long mainboard_write_acpi_tables(
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700207 const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +0800208{
David Wu80496f02018-09-14 21:30:39 +0800209 const char *oem_id = NULL;
210 const char *oem_table_id = NULL;
211 uint32_t oem_revision = 0;
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +0800212 uintptr_t start_addr;
213 uintptr_t end_addr;
214 struct nhlt *nhlt;
215
216 start_addr = current;
217
218 nhlt = nhlt_init();
219 if (!nhlt)
220 return start_addr;
221
David Wu80496f02018-09-14 21:30:39 +0800222 variant_nhlt_init(nhlt);
223 variant_nhlt_oem_overrides(&oem_id, &oem_table_id, &oem_revision);
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +0800224
225 end_addr = nhlt_soc_serialize_oem_overrides(nhlt, start_addr,
David Wu80496f02018-09-14 21:30:39 +0800226 oem_id, oem_table_id, oem_revision);
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +0800227
228 if (end_addr != start_addr)
229 acpi_add_table(rsdp, (void *)start_addr);
230
231 return end_addr;
232}
233
Elyes HAOUASd129d432018-05-04 20:23:33 +0200234static void mainboard_enable(struct device *dev)
Shelley Chen243dc392017-03-15 15:25:48 -0700235{
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +0530236 struct soc_power_limits_config *soc_conf;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300237 config_t *conf = config_of_soc();
Shelley Chen8c81c6a2017-06-29 14:58:59 -0700238
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +0530239 soc_conf = &conf->power_limits_config;
240 mainboard_set_power_limits(soc_conf);
Shelley Chendb287aa2017-06-09 12:56:08 -0700241
Shelley Chen243dc392017-03-15 15:25:48 -0700242 dev->ops->init = mainboard_init;
Kevin Cheng2a6f4ae2017-06-06 10:37:59 +0800243 dev->ops->write_acpi_tables = mainboard_write_acpi_tables;
Shelley Chen243dc392017-03-15 15:25:48 -0700244}
245
Furquan Shaikhfb9f3202019-10-23 09:52:32 -0700246#define GPIO_HDMI_HPD GPP_E13
247#define GPIO_DP_HPD GPP_E14
248
249/* TODO: This can be moved to common directory */
250static void wait_for_hpd(gpio_t gpio, long timeout)
251{
252 struct stopwatch sw;
253
254 printk(BIOS_INFO, "Waiting for HPD\n");
255 gpio_input(gpio);
256
257 stopwatch_init_msecs_expire(&sw, timeout);
258 while (!gpio_get(gpio)) {
259 if (stopwatch_expired(&sw)) {
260 printk(BIOS_WARNING,
261 "HPD not ready after %ldms. Abort.\n", timeout);
262 return;
263 }
264 mdelay(200);
265 }
Rob Barnesd522f382022-09-12 06:31:47 -0600266 printk(BIOS_INFO, "HPD ready after %lld ms\n",
Furquan Shaikhfb9f3202019-10-23 09:52:32 -0700267 stopwatch_duration_msecs(&sw));
268}
269
Jeff Chasead1a8352020-06-04 17:24:59 -0400270void __weak variant_chip_display_init(void)
Furquan Shaikhfb9f3202019-10-23 09:52:32 -0700271{
Furquan Shaikhfb9f3202019-10-23 09:52:32 -0700272 static const long display_timeout_ms = 3000;
273
274 /* This is reconfigured back to whatever FSP-S expects by
275 gpio_configure_pads. */
276 gpio_input(GPIO_HDMI_HPD);
277 if (display_init_required() && !gpio_get(GPIO_HDMI_HPD)) {
278 /* This has to be done before FSP-S runs. */
279 if (google_chromeec_wait_for_displayport(display_timeout_ms))
280 wait_for_hpd(GPIO_DP_HPD, display_timeout_ms);
281 }
Jeff Chasead1a8352020-06-04 17:24:59 -0400282}
283
284static void mainboard_chip_init(void *chip_info)
285{
286 const struct pad_config *pads;
287 size_t num;
288
289 variant_chip_display_init();
Furquan Shaikhfb9f3202019-10-23 09:52:32 -0700290
291 pads = variant_gpio_table(&num);
292 gpio_configure_pads(pads, num);
293}
294
Shelley Chen243dc392017-03-15 15:25:48 -0700295struct chip_operations mainboard_ops = {
Furquan Shaikhfb9f3202019-10-23 09:52:32 -0700296 .init = mainboard_chip_init,
Shelley Chen243dc392017-03-15 15:25:48 -0700297 .enable_dev = mainboard_enable,
298};