Andrew McRae | b438dab | 2020-04-15 16:10:58 +1000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
| 3 | |
| 4 | #include <baseboard/variants.h> |
| 5 | #include <chip.h> |
| 6 | #include <delay.h> |
| 7 | #include <device/device.h> |
| 8 | #include <ec/google/chromeec/ec.h> |
| 9 | #include <gpio.h> |
| 10 | #include <timer.h> |
| 11 | |
| 12 | #define GPIO_HDMI_HPD GPP_E13 |
| 13 | #define GPIO_DP_HPD GPP_E14 |
| 14 | |
| 15 | /* TODO: This can be moved to common directory */ |
| 16 | static void wait_for_hpd(gpio_t gpio, long timeout) |
| 17 | { |
| 18 | struct stopwatch sw; |
| 19 | |
| 20 | printk(BIOS_INFO, "Waiting for HPD\n"); |
| 21 | stopwatch_init_msecs_expire(&sw, timeout); |
| 22 | while (!gpio_get(gpio)) { |
| 23 | if (stopwatch_expired(&sw)) { |
| 24 | printk(BIOS_WARNING, |
| 25 | "HPD not ready after %ldms. Abort.\n", timeout); |
| 26 | return; |
| 27 | } |
| 28 | mdelay(200); |
| 29 | } |
| 30 | printk(BIOS_INFO, "HPD ready after %lu ms\n", |
| 31 | stopwatch_duration_msecs(&sw)); |
| 32 | } |
| 33 | |
| 34 | void variant_ramstage_init(void) |
| 35 | { |
| 36 | static const long display_timeout_ms = 3000; |
| 37 | |
| 38 | /* This is reconfigured back to whatever FSP-S expects by |
| 39 | gpio_configure_pads. */ |
| 40 | gpio_input(GPIO_HDMI_HPD); |
| 41 | gpio_input(GPIO_DP_HPD); |
| 42 | if (display_init_required() |
| 43 | && !gpio_get(GPIO_HDMI_HPD) |
| 44 | && !gpio_get(GPIO_DP_HPD)) { |
| 45 | /* This has to be done before FSP-S runs. */ |
| 46 | if (google_chromeec_wait_for_displayport(display_timeout_ms)) |
| 47 | wait_for_hpd(GPIO_DP_HPD, display_timeout_ms); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * For type-C chargers, set PL2 to 90% of max power to account for |
| 53 | * cable loss and FET Rdson loss in the path from the source. |
| 54 | */ |
| 55 | #define SET_PSYSPL2(w) (9 * (w) / 10) |
| 56 | |
| 57 | #define PUFF_PL2 (35) |
| 58 | |
| 59 | #define PUFF_PSYSPL2 (58) |
| 60 | |
| 61 | #define PUFF_MAX_TIME_WINDOW 6 |
| 62 | #define PUFF_MIN_DUTYCYCLE 4 |
| 63 | |
| 64 | /* |
| 65 | * mainboard_set_power_limits |
| 66 | * |
| 67 | * Set Pl2 and SysPl2 values based on detected charger. |
| 68 | * Values are defined below but we use U22 value for all SKUs for now. |
| 69 | * definitions: |
| 70 | * x = no value entered. Use default value in parenthesis. |
| 71 | * will set 0 to anything that shouldn't be set. |
| 72 | * n = max value of power adapter. |
| 73 | * +-------------+-----+---------+-----------+-------+ |
| 74 | * | sku_id | PL2 | PsysPL2 | PsysPL3 | PL4 | |
| 75 | * +-------------+-----+---------+-----------+-------+ |
| 76 | * | i7 U42 | 51 | 81 | x(.85PL4) | x(82) | |
| 77 | * | celeron U22 | 35 | 58 | x(.85PL4) | x(51) | |
| 78 | * +-------------+-----+---------+-----------+-------+ |
| 79 | * For USB C charger: |
| 80 | * +-------------+-----+---------+---------+-------+ |
| 81 | * | Max Power(W)| PL2 | PsysPL2 | PsysPL3 | PL4 | |
| 82 | * +-------------+-----+---------+---------+-------+ |
| 83 | * | 60 (U42) | 44 | 54 | 54 | 54 | |
| 84 | * | 60 (U22) | 29 | 54 | 54 | x(43) | |
| 85 | * | n (U42) | 44 | .9n | .9n | .9n | |
| 86 | * | n (U22) | 29 | .9n | .9n | x(43) | |
| 87 | * +-------------+-----+---------+---------+-------+ |
| 88 | */ |
| 89 | static void mainboard_set_power_limits(config_t *conf) |
| 90 | { |
| 91 | enum usb_chg_type type; |
| 92 | u32 watts; |
| 93 | u32 psyspl2 = PUFF_PSYSPL2; // default barrel jack value for U22 |
| 94 | int rv = google_chromeec_get_usb_pd_power_info(&type, &watts); |
| 95 | |
| 96 | /* use SoC default value for PsysPL3 and PL4 unless we're on USB-PD*/ |
| 97 | conf->tdp_psyspl3 = 0; |
| 98 | conf->tdp_pl4 = 0; |
| 99 | |
| 100 | if (rv == 0 && type == USB_CHG_TYPE_PD) { |
| 101 | /* Detected USB-PD. Base on max value of adapter */ |
| 102 | psyspl2 = watts; |
| 103 | conf->tdp_psyspl3 = SET_PSYSPL2(psyspl2); |
| 104 | /* set max possible time window */ |
| 105 | conf->tdp_psyspl3_time = PUFF_MAX_TIME_WINDOW; |
| 106 | /* set minimum duty cycle */ |
| 107 | conf->tdp_psyspl3_dutycycle = PUFF_MIN_DUTYCYCLE; |
| 108 | conf->tdp_pl4 = SET_PSYSPL2(psyspl2); |
| 109 | } |
| 110 | |
| 111 | conf->tdp_pl2_override = PUFF_PL2; |
| 112 | /* set psyspl2 to 90% of max adapter power */ |
| 113 | conf->tdp_psyspl2 = SET_PSYSPL2(psyspl2); |
| 114 | } |
| 115 | |
| 116 | void variant_mainboard_enable(struct device *dev) |
| 117 | { |
| 118 | config_t *conf = config_of_soc(); |
| 119 | mainboard_set_power_limits(conf); |
| 120 | } |