summaryrefslogtreecommitdiff
path: root/zephyr/projects/corsola/src/krabby
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/projects/corsola/src/krabby')
-rw-r--r--zephyr/projects/corsola/src/krabby/battery.c46
-rw-r--r--zephyr/projects/corsola/src/krabby/charger_workaround.c70
-rw-r--r--zephyr/projects/corsola/src/krabby/hooks.c24
-rw-r--r--zephyr/projects/corsola/src/krabby/i2c.c6
-rw-r--r--zephyr/projects/corsola/src/krabby/led.c147
-rw-r--r--zephyr/projects/corsola/src/krabby/sensor_magikarp.c41
-rw-r--r--zephyr/projects/corsola/src/krabby/sensor_tentacruel.c41
-rw-r--r--zephyr/projects/corsola/src/krabby/temp_tentacruel.c126
-rw-r--r--zephyr/projects/corsola/src/krabby/usb_pd_policy.c2
-rw-r--r--zephyr/projects/corsola/src/krabby/usbc_config.c52
-rw-r--r--zephyr/projects/corsola/src/krabby/usbc_config_tentacruel.c223
11 files changed, 508 insertions, 270 deletions
diff --git a/zephyr/projects/corsola/src/krabby/battery.c b/zephyr/projects/corsola/src/krabby/battery.c
deleted file mode 100644
index 0c0efc8200..0000000000
--- a/zephyr/projects/corsola/src/krabby/battery.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "battery.h"
-#include "battery_fuel_gauge.h"
-#include "battery_smart.h"
-#include "charge_manager.h"
-#include "chipset.h"
-#include "hooks.h"
-#include "system.h"
-#include "usb_pd.h"
-
-const struct board_batt_params board_battery_info[] = {
- [BATTERY_C235] = {
- .fuel_gauge = {
- .manuf_name = "AS3GWRc3KA",
- .device_name = "C235-41",
- .ship_mode = {
- .reg_addr = 0x0,
- .reg_data = { 0x10, 0x10 },
- },
- .fet = {
- .reg_addr = 0x99,
- .reg_mask = 0x0c,
- .disconnect_val = 0x0c,
- }
- },
- .batt_info = {
- .voltage_max = 8800,
- .voltage_normal = 7700,
- .voltage_min = 6000,
- .precharge_current = 256,
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 60,
- .discharging_min_c = 0,
- .discharging_max_c = 60,
- },
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
-
-const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_C235;
diff --git a/zephyr/projects/corsola/src/krabby/charger_workaround.c b/zephyr/projects/corsola/src/krabby/charger_workaround.c
index 373917db56..dda91fccb5 100644
--- a/zephyr/projects/corsola/src/krabby/charger_workaround.c
+++ b/zephyr/projects/corsola/src/krabby/charger_workaround.c
@@ -1,22 +1,30 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include <zephyr/sys/util.h>
+
#include "charger.h"
#include "driver/charger/rt9490.h"
#include "hooks.h"
#include "i2c.h"
#include "system.h"
+/*
+ * This workaround and the board id checks only apply to krabby and early
+ * tentacruel devices.
+ * Newer project should have all of these fixed.
+ */
+BUILD_ASSERT(IS_ENABLED(CONFIG_BOARD_KRABBY) ||
+ IS_ENABLED(CONFIG_BOARD_TENTACRUEL) || IS_ENABLED(CONFIG_TEST));
+
static void enter_hidden_mode(void)
{
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
- chg_chips[CHARGER_SOLO].i2c_addr_flags,
- 0xF1, 0x69);
+ chg_chips[CHARGER_SOLO].i2c_addr_flags, 0xF1, 0x69);
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
- chg_chips[CHARGER_SOLO].i2c_addr_flags,
- 0xF2, 0x96);
+ chg_chips[CHARGER_SOLO].i2c_addr_flags, 0xF2, 0x96);
}
/* b/194967754#comment5: work around for IBUS ADC unstable issue */
@@ -28,48 +36,33 @@ static void ibus_adc_workaround(void)
i2c_update8(chg_chips[CHARGER_SOLO].i2c_port,
chg_chips[CHARGER_SOLO].i2c_addr_flags,
- RT9490_REG_ADC_CHANNEL0,
- RT9490_VSYS_ADC_DIS,
- MASK_SET);
+ RT9490_REG_ADC_CHANNEL0, RT9490_VSYS_ADC_DIS, MASK_SET);
enter_hidden_mode();
/* undocumented registers... */
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
- chg_chips[CHARGER_SOLO].i2c_addr_flags,
- 0x52, 0xC4);
+ chg_chips[CHARGER_SOLO].i2c_addr_flags, 0x52, 0xC4);
i2c_update8(chg_chips[CHARGER_SOLO].i2c_port,
chg_chips[CHARGER_SOLO].i2c_addr_flags,
- RT9490_REG_ADC_CHANNEL0,
- RT9490_VSYS_ADC_DIS,
- MASK_CLR);
+ RT9490_REG_ADC_CHANNEL0, RT9490_VSYS_ADC_DIS, MASK_CLR);
}
/* b/214880220#comment44: lock i2c at 400khz */
static void i2c_speed_workaround(void)
{
- /*
- * This workaround can be applied to all version of RT9490 in our cases
- * no need to identify chip version.
- */
+ if (system_get_board_version() >= 3) {
+ return;
+ }
+
enter_hidden_mode();
/* Set to Auto mode, default run at 400kHz */
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
- chg_chips[CHARGER_SOLO].i2c_addr_flags,
- 0x71, 0x22);
+ chg_chips[CHARGER_SOLO].i2c_addr_flags, 0x71, 0x22);
/* Manually select for 400kHz, valid only when 0x71[7] == 1 */
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
- chg_chips[CHARGER_SOLO].i2c_addr_flags,
- 0xF7, 0x14);
-}
-
-static void pwm_freq_workaround(void)
-{
- /* Reduce SW freq from 1.5MHz to 1MHz
- * for 10% higher current rating b/215294785
- */
- rt9490_enable_pwm_1mhz(CHARGER_SOLO, true);
+ chg_chips[CHARGER_SOLO].i2c_addr_flags, 0xF7, 0x14);
}
static void eoc_deglitch_workaround(void)
@@ -81,16 +74,27 @@ static void eoc_deglitch_workaround(void)
/* set end-of-charge deglitch time to 2ms */
i2c_update8(chg_chips[CHARGER_SOLO].i2c_port,
chg_chips[CHARGER_SOLO].i2c_addr_flags,
- RT9490_REG_ADD_CTRL0,
- RT9490_TD_EOC,
- MASK_CLR);
+ RT9490_REG_ADD_CTRL0, RT9490_TD_EOC, MASK_CLR);
+}
+
+static void disable_safety_timer(void)
+{
+ if (system_get_board_version() >= 2) {
+ return;
+ }
+ /* Disable charge timer */
+ i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
+ chg_chips[CHARGER_SOLO].i2c_addr_flags,
+ RT9490_REG_SAFETY_TMR_CTRL,
+ RT9490_EN_TRICHG_TMR | RT9490_EN_PRECHG_TMR |
+ RT9490_EN_FASTCHG_TMR);
}
static void board_rt9490_workaround(void)
{
ibus_adc_workaround();
i2c_speed_workaround();
- pwm_freq_workaround();
eoc_deglitch_workaround();
+ disable_safety_timer();
}
DECLARE_HOOK(HOOK_INIT, board_rt9490_workaround, HOOK_PRIO_DEFAULT);
diff --git a/zephyr/projects/corsola/src/krabby/hooks.c b/zephyr/projects/corsola/src/krabby/hooks.c
index 9fae7c8bb5..1eb4f600f2 100644
--- a/zephyr/projects/corsola/src/krabby/hooks.c
+++ b/zephyr/projects/corsola/src/krabby/hooks.c
@@ -1,10 +1,11 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <zephyr/init.h>
#include <zephyr/drivers/gpio.h>
+#include <zephyr/drivers/pinctrl.h>
#include <ap_power/ap_power.h>
#include "charger.h"
@@ -13,22 +14,21 @@
#include "gpio.h"
#include "hooks.h"
+#define I2C3_NODE DT_NODELABEL(i2c3)
+PINCTRL_DT_DEFINE(I2C3_NODE);
+
static void board_i2c3_ctrl(bool enable)
{
- if (DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(DT_NODELABEL(i2c3),
- scl_gpios, 0)) == DEVICE_DT_GET(DT_NODELABEL(gpiof))) {
- /*
- * TODO(b/226296649):
- * Use pinctrl APIs to enable/disable an interface.
- */
- struct gctrl_it8xxx2_regs *const gctrl_base =
- (struct gctrl_it8xxx2_regs *)
- DT_REG_ADDR(DT_NODELABEL(gctrl));
+ if (DEVICE_DT_GET(
+ DT_GPIO_CTLR_BY_IDX(DT_NODELABEL(i2c3), scl_gpios, 0)) ==
+ DEVICE_DT_GET(DT_NODELABEL(gpiof))) {
+ const struct pinctrl_dev_config *pcfg =
+ PINCTRL_DT_DEV_CONFIG_GET(I2C3_NODE);
if (enable) {
- gctrl_base->GCTRL_PMER3 |= IT8XXX2_GCTRL_SMB3PSEL;
+ pinctrl_apply_state(pcfg, PINCTRL_STATE_DEFAULT);
} else {
- gctrl_base->GCTRL_PMER3 &= ~IT8XXX2_GCTRL_SMB3PSEL;
+ pinctrl_apply_state(pcfg, PINCTRL_STATE_SLEEP);
}
}
}
diff --git a/zephyr/projects/corsola/src/krabby/i2c.c b/zephyr/projects/corsola/src/krabby/i2c.c
index 3b5108e115..a83af77dbd 100644
--- a/zephyr/projects/corsola/src/krabby/i2c.c
+++ b/zephyr/projects/corsola/src/krabby/i2c.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -12,6 +12,8 @@
int board_allow_i2c_passthru(const struct i2c_cmd_desc_t *cmd_desc)
{
return (i2c_get_device_for_port(cmd_desc->port) ==
- i2c_get_device_for_port(I2C_PORT_VIRTUAL_BATTERY));
+ i2c_get_device_for_port(I2C_PORT_VIRTUAL_BATTERY) ||
+ i2c_get_device_for_port(cmd_desc->port) ==
+ i2c_get_device_for_port(I2C_PORT_EEPROM));
}
#endif
diff --git a/zephyr/projects/corsola/src/krabby/led.c b/zephyr/projects/corsola/src/krabby/led.c
deleted file mode 100644
index c001615402..0000000000
--- a/zephyr/projects/corsola/src/krabby/led.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <zephyr/drivers/pwm.h>
-#include <zephyr/logging/log.h>
-
-#include "board_led.h"
-#include "common.h"
-#include "led_common.h"
-#include "led_onoff_states.h"
-#include "util.h"
-
-LOG_MODULE_REGISTER(board_led, LOG_LEVEL_ERR);
-
-/*If we need pwm output in ITE chip power saving mode, then we should set
- * frequency <= 324Hz.
- */
-#define BOARD_LED_PWM_PERIOD_NS BOARD_LED_HZ_TO_PERIOD_NS(324)
-
-static const struct board_led_pwm_dt_channel board_led_power_white =
- BOARD_LED_PWM_DT_CHANNEL_INITIALIZER(DT_NODELABEL(led_power_white));
-static const struct board_led_pwm_dt_channel board_led_battery_amber =
- BOARD_LED_PWM_DT_CHANNEL_INITIALIZER(DT_NODELABEL(led_battery_amber));
-static const struct board_led_pwm_dt_channel board_led_battery_white =
- BOARD_LED_PWM_DT_CHANNEL_INITIALIZER(DT_NODELABEL(led_battery_white));
-
-__override const int led_charge_lvl_1 = 5;
-__override const int led_charge_lvl_2 = 95;
-
-__override struct led_descriptor
- led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = {
- [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} },
- [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} },
- [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
- [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} },
- [STATE_DISCHARGE_S0_BAT_LOW] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC},
- {LED_OFF, 3 * LED_ONE_SEC} },
- [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} },
- [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} },
- [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC},
- {LED_OFF, 1 * LED_ONE_SEC} },
- [STATE_FACTORY_TEST] = {{EC_LED_COLOR_WHITE, 2 * LED_ONE_SEC},
- {EC_LED_COLOR_AMBER, 2 * LED_ONE_SEC} },
-};
-
-__override const struct led_descriptor
- led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES] = {
- [PWR_LED_STATE_ON] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
- [PWR_LED_STATE_SUSPEND_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC},
- {LED_OFF, 3 * LED_ONE_SEC} },
- [PWR_LED_STATE_SUSPEND_NO_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC},
- {LED_OFF, 3 * LED_ONE_SEC} },
- [PWR_LED_STATE_OFF] = {{LED_OFF, LED_INDEFINITE} },
-};
-
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_BATTERY_LED,
- EC_LED_ID_POWER_LED,
-};
-
-const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-
-static void board_led_pwm_set_duty(const struct board_led_pwm_dt_channel *ch,
- int percent)
-{
- uint32_t pulse_ns;
- int rv;
-
- if (!device_is_ready(ch->dev)) {
- LOG_ERR("PWM device %s not ready", ch->dev->name);
- return;
- }
-
- pulse_ns = DIV_ROUND_NEAREST(BOARD_LED_PWM_PERIOD_NS * percent, 100);
-
- LOG_DBG("Board LED PWM %s set percent (%d), pulse %d",
- ch->dev->name, percent, pulse_ns);
-
- rv = pwm_set(ch->dev, ch->channel, BOARD_LED_PWM_PERIOD_NS, pulse_ns,
- ch->flags);
- if (rv) {
- LOG_ERR("pwm_set() failed %s (%d)", ch->dev->name, rv);
- }
-}
-
-__override void led_set_color_battery(enum ec_led_colors color)
-{
- switch (color) {
- case EC_LED_COLOR_AMBER:
- board_led_pwm_set_duty(&board_led_battery_amber, 100);
- board_led_pwm_set_duty(&board_led_battery_white, 0);
- break;
- case EC_LED_COLOR_WHITE:
- board_led_pwm_set_duty(&board_led_battery_amber, 0);
- board_led_pwm_set_duty(&board_led_battery_white, 100);
- break;
- default:
- board_led_pwm_set_duty(&board_led_battery_amber, 0);
- board_led_pwm_set_duty(&board_led_battery_white, 0);
- break;
- }
-}
-
-__override void led_set_color_power(enum ec_led_colors color)
-{
- switch (color) {
- case EC_LED_COLOR_WHITE:
- board_led_pwm_set_duty(&board_led_power_white, 100);
- break;
- default:
- board_led_pwm_set_duty(&board_led_power_white, 0);
- break;
- }
-}
-
-void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
-{
- if (led_id == EC_LED_ID_BATTERY_LED) {
- brightness_range[EC_LED_COLOR_AMBER] = 1;
- brightness_range[EC_LED_COLOR_WHITE] = 1;
- } else if (led_id == EC_LED_ID_POWER_LED) {
- brightness_range[EC_LED_COLOR_WHITE] = 1;
- }
-}
-
-int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
-{
- if (led_id == EC_LED_ID_BATTERY_LED) {
- if (brightness[EC_LED_COLOR_AMBER] != 0) {
- led_set_color_battery(EC_LED_COLOR_AMBER);
- } else if (brightness[EC_LED_COLOR_WHITE] != 0) {
- led_set_color_battery(EC_LED_COLOR_WHITE);
- } else {
- led_set_color_battery(LED_OFF);
- }
- } else if (led_id == EC_LED_ID_POWER_LED) {
- if (brightness[EC_LED_COLOR_WHITE] != 0) {
- led_set_color_power(EC_LED_COLOR_WHITE);
- } else {
- led_set_color_power(LED_OFF);
- }
- }
-
- return EC_SUCCESS;
-}
diff --git a/zephyr/projects/corsola/src/krabby/sensor_magikarp.c b/zephyr/projects/corsola/src/krabby/sensor_magikarp.c
new file mode 100644
index 0000000000..269bc26fae
--- /dev/null
+++ b/zephyr/projects/corsola/src/krabby/sensor_magikarp.c
@@ -0,0 +1,41 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "accelgyro.h"
+#include "cros_cbi.h"
+#include "driver/accelgyro_bmi323.h"
+#include "driver/accelgyro_icm42607.h"
+#include "hooks.h"
+#include "motionsense_sensors.h"
+
+void motion_interrupt(enum gpio_signal signal)
+{
+ uint32_t val;
+
+ cros_cbi_get_fw_config(FW_BASE_GYRO, &val);
+ if (val == FW_BASE_ICM42607) {
+ icm42607_interrupt(signal);
+ } else if (val == FW_BASE_BMI323) {
+ bmi3xx_interrupt(signal);
+ }
+}
+
+static void motionsense_init(void)
+{
+ uint32_t val;
+
+ cros_cbi_get_fw_config(FW_BASE_GYRO, &val);
+ if (val == FW_BASE_ICM42607) {
+ ccprints("BASE ACCEL is ICM42607");
+ } else if (val == FW_BASE_BMI323) {
+ MOTIONSENSE_ENABLE_ALTERNATE(alt_base_accel);
+ MOTIONSENSE_ENABLE_ALTERNATE(alt_base_gyro);
+ ccprints("BASE ACCEL IS BMI323");
+ } else {
+ ccprints("no motionsense");
+ }
+}
+DECLARE_HOOK(HOOK_INIT, motionsense_init, HOOK_PRIO_DEFAULT);
diff --git a/zephyr/projects/corsola/src/krabby/sensor_tentacruel.c b/zephyr/projects/corsola/src/krabby/sensor_tentacruel.c
new file mode 100644
index 0000000000..269bc26fae
--- /dev/null
+++ b/zephyr/projects/corsola/src/krabby/sensor_tentacruel.c
@@ -0,0 +1,41 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "accelgyro.h"
+#include "cros_cbi.h"
+#include "driver/accelgyro_bmi323.h"
+#include "driver/accelgyro_icm42607.h"
+#include "hooks.h"
+#include "motionsense_sensors.h"
+
+void motion_interrupt(enum gpio_signal signal)
+{
+ uint32_t val;
+
+ cros_cbi_get_fw_config(FW_BASE_GYRO, &val);
+ if (val == FW_BASE_ICM42607) {
+ icm42607_interrupt(signal);
+ } else if (val == FW_BASE_BMI323) {
+ bmi3xx_interrupt(signal);
+ }
+}
+
+static void motionsense_init(void)
+{
+ uint32_t val;
+
+ cros_cbi_get_fw_config(FW_BASE_GYRO, &val);
+ if (val == FW_BASE_ICM42607) {
+ ccprints("BASE ACCEL is ICM42607");
+ } else if (val == FW_BASE_BMI323) {
+ MOTIONSENSE_ENABLE_ALTERNATE(alt_base_accel);
+ MOTIONSENSE_ENABLE_ALTERNATE(alt_base_gyro);
+ ccprints("BASE ACCEL IS BMI323");
+ } else {
+ ccprints("no motionsense");
+ }
+}
+DECLARE_HOOK(HOOK_INIT, motionsense_init, HOOK_PRIO_DEFAULT);
diff --git a/zephyr/projects/corsola/src/krabby/temp_tentacruel.c b/zephyr/projects/corsola/src/krabby/temp_tentacruel.c
new file mode 100644
index 0000000000..53a8312be6
--- /dev/null
+++ b/zephyr/projects/corsola/src/krabby/temp_tentacruel.c
@@ -0,0 +1,126 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "charger.h"
+#include "charge_state.h"
+#include "common.h"
+#include "config.h"
+#include "console.h"
+#include "driver/charger/rt9490.h"
+#include "hooks.h"
+#include "temp_sensor/temp_sensor.h"
+#include "thermal.h"
+#include "util.h"
+
+#define NUM_CURRENT_LEVELS ARRAY_SIZE(current_table)
+#define TEMP_THRESHOLD 55
+#define TEMP_BUFF_SIZE 60
+#define KEEP_TIME 5
+
+/* calculate current average temperature */
+static int average_tempature(void)
+{
+ static int temp_history_buffer[TEMP_BUFF_SIZE];
+ static int buff_ptr;
+ static int temp_sum;
+ static int past_temp;
+ static int avg_temp;
+ int cur_temp, t;
+
+ temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL(temp_charger)), &t);
+ cur_temp = K_TO_C(t);
+ past_temp = temp_history_buffer[buff_ptr];
+ temp_history_buffer[buff_ptr] = cur_temp;
+ temp_sum = temp_sum + temp_history_buffer[buff_ptr] - past_temp;
+ buff_ptr++;
+ if (buff_ptr >= TEMP_BUFF_SIZE) {
+ buff_ptr = 0;
+ }
+ /* Calculate per minute temperature.
+ * It's expected low temperature when the first 60 seconds.
+ */
+ avg_temp = temp_sum / TEMP_BUFF_SIZE;
+ return avg_temp;
+}
+
+static int current_level;
+
+/* Limit charging current table : 3600/3000/2400/1800
+ * note this should be in descending order.
+ */
+static uint16_t current_table[] = {
+ 3600,
+ 3000,
+ 2400,
+ 1800,
+};
+
+/* Called by hook task every hook second (1 sec) */
+static void current_update(void)
+{
+ int temp;
+ static uint8_t uptime;
+ static uint8_t dntime;
+
+ temp = average_tempature();
+ if (charge_get_state() == PWR_STATE_DISCHARGE) {
+ current_level = 0;
+ uptime = 0;
+ dntime = 0;
+ return;
+ }
+ if (temp >= TEMP_THRESHOLD) {
+ dntime = 0;
+ if (uptime < KEEP_TIME) {
+ uptime++;
+ } else {
+ uptime = 0;
+ current_level++;
+ }
+ } else if (current_level != 0 && temp < TEMP_THRESHOLD) {
+ uptime = 0;
+ if (dntime < KEEP_TIME) {
+ dntime++;
+ } else {
+ dntime = 0;
+ current_level--;
+ }
+ } else {
+ uptime = 0;
+ dntime = 0;
+ }
+ if (current_level > NUM_CURRENT_LEVELS) {
+ current_level = NUM_CURRENT_LEVELS;
+ }
+}
+DECLARE_HOOK(HOOK_SECOND, current_update, HOOK_PRIO_DEFAULT);
+
+int charger_profile_override(struct charge_state_data *curr)
+{
+ /*
+ * Precharge must be executed when communication is failed on
+ * dead battery.
+ */
+ if (!(curr->batt.flags & BATT_FLAG_RESPONSIVE))
+ return 0;
+ if (current_level != 0) {
+ if (curr->requested_current > current_table[current_level - 1])
+ curr->requested_current =
+ current_table[current_level - 1];
+ }
+ return 0;
+}
+
+enum ec_status charger_profile_override_get_param(uint32_t param,
+ uint32_t *value)
+{
+ return EC_RES_INVALID_PARAM;
+}
+
+enum ec_status charger_profile_override_set_param(uint32_t param,
+ uint32_t value)
+{
+ return EC_RES_INVALID_PARAM;
+}
diff --git a/zephyr/projects/corsola/src/krabby/usb_pd_policy.c b/zephyr/projects/corsola/src/krabby/usb_pd_policy.c
index 5f9ae83a19..8f2a2c3515 100644
--- a/zephyr/projects/corsola/src/krabby/usb_pd_policy.c
+++ b/zephyr/projects/corsola/src/krabby/usb_pd_policy.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/zephyr/projects/corsola/src/krabby/usbc_config.c b/zephyr/projects/corsola/src/krabby/usbc_config.c
index 73ecd2f7bd..01686119cc 100644
--- a/zephyr/projects/corsola/src/krabby/usbc_config.c
+++ b/zephyr/projects/corsola/src/krabby/usbc_config.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,25 +23,15 @@
#include "variant_db_detection.h"
-#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
void c0_bc12_interrupt(enum gpio_signal signal)
{
rt1739_interrupt(0);
}
-static void board_sub_bc12_init(void)
-{
- if (corsola_get_db_type() == CORSOLA_DB_HDMI) {
- /* If this is not a Type-C subboard, disable the task. */
- task_disable_task(TASK_ID_USB_CHG_P1);
- }
-}
-/* Must be done after I2C and subboard */
-DECLARE_HOOK(HOOK_INIT, board_sub_bc12_init, HOOK_PRIO_POST_I2C);
-
static void board_usbc_init(void)
{
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c0_ppc_bc12));
@@ -58,12 +48,12 @@ void ppc_interrupt(enum gpio_signal signal)
int ppc_get_alert_status(int port)
{
if (port == 0) {
- return gpio_pin_get_dt(
- GPIO_DT_FROM_NODELABEL(usb_c0_ppc_bc12_int_odl)) == 0;
+ return gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(
+ usb_c0_ppc_bc12_int_odl)) == 0;
}
if (port == 1 && corsola_get_db_type() == CORSOLA_DB_TYPEC) {
- return gpio_pin_get_dt(
- GPIO_DT_FROM_ALIAS(gpio_usb_c1_ppc_int_odl)) == 0;
+ return gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(
+ gpio_usb_c1_ppc_int_odl)) == 0;
}
return 0;
@@ -73,15 +63,19 @@ const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port)
{
const static struct cc_para_t
cc_parameter[CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT] = {
- {
- .rising_time = IT83XX_TX_PRE_DRIVING_TIME_1_UNIT,
- .falling_time = IT83XX_TX_PRE_DRIVING_TIME_2_UNIT,
- },
- {
- .rising_time = IT83XX_TX_PRE_DRIVING_TIME_1_UNIT,
- .falling_time = IT83XX_TX_PRE_DRIVING_TIME_2_UNIT,
- },
- };
+ {
+ .rising_time =
+ IT83XX_TX_PRE_DRIVING_TIME_1_UNIT,
+ .falling_time =
+ IT83XX_TX_PRE_DRIVING_TIME_2_UNIT,
+ },
+ {
+ .rising_time =
+ IT83XX_TX_PRE_DRIVING_TIME_1_UNIT,
+ .falling_time =
+ IT83XX_TX_PRE_DRIVING_TIME_2_UNIT,
+ },
+ };
return &cc_parameter[port];
}
@@ -169,10 +163,10 @@ int board_set_active_charge_port(int port)
enum adc_channel board_get_vbus_adc(int port)
{
if (port == 0) {
- return ADC_VBUS_C0;
+ return ADC_VBUS_C0;
}
if (port == 1) {
- return ADC_VBUS_C1;
+ return ADC_VBUS_C1;
}
CPRINTSUSB("Unknown vbus adc port id: %d", port);
return ADC_VBUS_C0;
diff --git a/zephyr/projects/corsola/src/krabby/usbc_config_tentacruel.c b/zephyr/projects/corsola/src/krabby/usbc_config_tentacruel.c
new file mode 100644
index 0000000000..691a28d50f
--- /dev/null
+++ b/zephyr/projects/corsola/src/krabby/usbc_config_tentacruel.c
@@ -0,0 +1,223 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Tentacruel board-specific USB-C configuration */
+
+#include "adc.h"
+#include "baseboard_usbc_config.h"
+#include "bc12/pi3usb9201_public.h"
+#include "charge_manager.h"
+#include "charger.h"
+#include "console.h"
+#include "cros_board_info.h"
+#include "driver/charger/rt9490.h"
+#include "driver/ppc/rt1739.h"
+#include "driver/tcpm/it83xx_pd.h"
+#include "driver/usb_mux/ps8743.h"
+#include "gpio/gpio_int.h"
+#include "hooks.h"
+#include "ppc/syv682x_public.h"
+#include "usb_mux/it5205_public.h"
+#include "usbc_ppc.h"
+#include "usbc/ppc.h"
+
+#include "variant_db_detection.h"
+#include <zephyr/logging/log.h>
+
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+
+LOG_MODULE_REGISTER(alt_dev_replacement);
+
+#define BOARD_VERSION_UNKNOWN 0xffffffff
+
+/* Check board version to decide which ppc/bc12 is used. */
+static bool board_has_syv_ppc(void)
+{
+ static uint32_t board_version = BOARD_VERSION_UNKNOWN;
+
+ if (board_version == BOARD_VERSION_UNKNOWN) {
+ if (cbi_get_board_version(&board_version) != EC_SUCCESS) {
+ LOG_ERR("Failed to get board version.");
+ board_version = 0;
+ }
+ }
+
+ return (board_version >= 3);
+}
+
+static void check_alternate_devices(void)
+{
+ /* Configure the PPC driver */
+ if (board_has_syv_ppc())
+ /* Arg is the USB port number */
+ PPC_ENABLE_ALTERNATE(0);
+}
+DECLARE_HOOK(HOOK_INIT, check_alternate_devices, HOOK_PRIO_DEFAULT);
+
+void bc12_interrupt(enum gpio_signal signal)
+{
+ usb_charger_task_set_event(0, USB_CHG_EVENT_BC12);
+}
+
+static void board_usbc_init(void)
+{
+ if (board_has_syv_ppc()) {
+ /* Enable PPC interrupts. */
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(int_usb_c0_ppc));
+
+ /* Enable BC1.2 interrupts. */
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(int_usb_c0_bc12));
+ } else {
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(int_usb_c0_ppc));
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_usbc_init, HOOK_PRIO_POST_DEFAULT);
+
+void ppc_interrupt(enum gpio_signal signal)
+{
+ if (signal == GPIO_SIGNAL(DT_NODELABEL(usb_c0_ppc_int_odl))) {
+ if (board_has_syv_ppc()) {
+ syv682x_interrupt(0);
+ } else {
+ rt1739_interrupt(0);
+ }
+ }
+ if (signal == GPIO_SIGNAL(DT_ALIAS(gpio_usb_c1_ppc_int_odl))) {
+ syv682x_interrupt(1);
+ }
+}
+
+int ppc_get_alert_status(int port)
+{
+ if (port == 0) {
+ return gpio_pin_get_dt(
+ GPIO_DT_FROM_NODELABEL(usb_c0_ppc_int_odl)) == 0;
+ }
+ if (port == 1 && corsola_get_db_type() == CORSOLA_DB_TYPEC) {
+ return gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(
+ gpio_usb_c1_ppc_int_odl)) == 0;
+ }
+
+ return 0;
+}
+
+const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port)
+{
+ const static struct cc_para_t
+ cc_parameter[CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT] = {
+ {
+ .rising_time =
+ IT83XX_TX_PRE_DRIVING_TIME_1_UNIT,
+ .falling_time =
+ IT83XX_TX_PRE_DRIVING_TIME_2_UNIT,
+ },
+ {
+ .rising_time =
+ IT83XX_TX_PRE_DRIVING_TIME_1_UNIT,
+ .falling_time =
+ IT83XX_TX_PRE_DRIVING_TIME_2_UNIT,
+ },
+ };
+
+ return &cc_parameter[port];
+}
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* TODO: check correct operation for Corsola */
+}
+
+uint16_t tcpc_get_alert_status(void)
+{
+ /*
+ * C0 & C1: TCPC is embedded in the EC and processes interrupts in the
+ * chip code (it83xx/intc.c)
+ */
+ return 0;
+}
+
+void board_reset_pd_mcu(void)
+{
+ /*
+ * C0 & C1: TCPC is embedded in the EC and processes interrupts in the
+ * chip code (it83xx/intc.c)
+ */
+}
+
+int board_set_active_charge_port(int port)
+{
+ int i;
+ int is_valid_port = (port >= 0 && port < board_get_usb_pd_port_count());
+
+ if (!is_valid_port && port != CHARGE_PORT_NONE) {
+ return EC_ERROR_INVAL;
+ }
+
+ if (port == CHARGE_PORT_NONE) {
+ CPRINTS("Disabling all charger ports");
+
+ /* Disable all ports. */
+ for (i = 0; i < ppc_cnt; i++) {
+ /*
+ * Do not return early if one fails otherwise we can
+ * get into a boot loop assertion failure.
+ */
+ if (ppc_vbus_sink_enable(i, 0)) {
+ CPRINTS("Disabling C%d as sink failed.", i);
+ }
+ }
+
+ return EC_SUCCESS;
+ }
+
+ /* Check if the port is sourcing VBUS. */
+ if (ppc_is_sourcing_vbus(port)) {
+ CPRINTS("Skip enable C%d", port);
+ return EC_ERROR_INVAL;
+ }
+
+ CPRINTS("New charge port: C%d", port);
+
+ /*
+ * Turn off the other ports' sink path FETs, before enabling the
+ * requested charge port.
+ */
+ for (i = 0; i < ppc_cnt; i++) {
+ if (i == port) {
+ continue;
+ }
+
+ if (ppc_vbus_sink_enable(i, 0)) {
+ CPRINTS("C%d: sink path disable failed.", i);
+ }
+ }
+
+ /* Enable requested charge port. */
+ if (ppc_vbus_sink_enable(port, 1)) {
+ CPRINTS("C%d: sink path enable failed.", port);
+ return EC_ERROR_UNKNOWN;
+ }
+
+ return EC_SUCCESS;
+}
+
+#ifdef CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT
+enum adc_channel board_get_vbus_adc(int port)
+{
+ if (port == 0) {
+ return ADC_VBUS_C0;
+ }
+ if (port == 1) {
+ return ADC_VBUS_C1;
+ }
+ CPRINTSUSB("Unknown vbus adc port id: %d", port);
+ return ADC_VBUS_C0;
+}
+#endif /* CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT */