summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/accel_cal.c18
-rw-r--r--common/acpi.c62
-rw-r--r--common/adc.c8
-rw-r--r--common/als.c16
-rw-r--r--common/ap_hang_detect.c21
-rw-r--r--common/audio_codec.c19
-rw-r--r--common/audio_codec_dmic.c14
-rw-r--r--common/audio_codec_i2s_rx.c8
-rw-r--r--common/audio_codec_wov.c19
-rw-r--r--common/backlight_lid.c8
-rw-r--r--common/base32.c29
-rw-r--r--common/base_state.c11
-rw-r--r--common/battery.c91
-rw-r--r--common/battery_fuel_gauge.c32
-rw-r--r--common/battery_v1.c21
-rw-r--r--common/battery_v2.c35
-rw-r--r--common/blink.c6
-rw-r--r--common/bluetooth_le.c41
-rw-r--r--common/body_detection.c41
-rw-r--r--common/btle_hci_controller.c324
-rw-r--r--common/btle_ll.c153
-rw-r--r--common/build.mk9
-rw-r--r--common/button.c58
-rw-r--r--common/capsense.c15
-rw-r--r--common/cbi.c73
-rw-r--r--common/cbi_eeprom.c12
-rw-r--r--common/cbi_gpio.c8
-rw-r--r--common/cec.c16
-rw-r--r--common/charge_manager.c362
-rw-r--r--common/charge_ramp.c6
-rw-r--r--common/charge_ramp_sw.c69
-rw-r--r--common/charge_state_v2.c554
-rw-r--r--common/chargen.c17
-rw-r--r--common/charger.c97
-rw-r--r--common/charger_profile_override.c27
-rw-r--r--common/chargesplash.c4
-rw-r--r--common/chipset.c44
-rw-r--r--common/clz.c2
-rw-r--r--common/console.c76
-rw-r--r--common/console_output.c25
-rw-r--r--common/crc.c2
-rw-r--r--common/crc8.c2
-rw-r--r--common/ctz.c6
-rw-r--r--common/device_event.c6
-rw-r--r--common/device_state.c14
-rw-r--r--common/dps.c142
-rw-r--r--common/dptf.c27
-rw-r--r--common/ec.libsharedobjs.ld2
-rw-r--r--common/ec_ec_comm_client.c71
-rw-r--r--common/ec_ec_comm_server.c70
-rw-r--r--common/ec_features.c70
-rw-r--r--common/espi.c5
-rw-r--r--common/event_log.c30
-rw-r--r--common/extpower_common.c2
-rw-r--r--common/extpower_gpio.c5
-rw-r--r--common/fan.c96
-rw-r--r--common/firmware_image.S2
-rw-r--r--common/firmware_image.lds.S2
-rw-r--r--common/flash.c205
-rw-r--r--common/fmap.c112
-rw-r--r--common/fpsensor/build.mk2
-rw-r--r--common/fpsensor/fpsensor.c144
-rw-r--r--common/fpsensor/fpsensor_crypto.c40
-rw-r--r--common/fpsensor/fpsensor_detect_strings.c2
-rw-r--r--common/fpsensor/fpsensor_private.h6
-rw-r--r--common/fpsensor/fpsensor_state.c46
-rw-r--r--common/gesture.c52
-rw-r--r--common/gpio.c19
-rw-r--r--common/gpio_commands.c53
-rw-r--r--common/gyro_cal.c2
-rw-r--r--common/gyro_still_det.c2
-rw-r--r--common/hooks.c69
-rw-r--r--common/host_command.c128
-rw-r--r--common/host_command_controller.c41
-rw-r--r--common/host_command_pd.c16
-rw-r--r--common/host_event_commands.c110
-rw-r--r--common/hotword_dsp_api.c2
-rw-r--r--common/i2c_bitbang.c24
-rw-r--r--common/i2c_controller.c516
-rw-r--r--common/i2c_hid_touchpad.c524
-rw-r--r--common/i2c_peripheral.c5
-rw-r--r--common/i2c_trace.c68
-rw-r--r--common/i2c_wedge.c37
-rw-r--r--common/inductive_charging.c2
-rw-r--r--common/init_rom.c2
-rw-r--r--common/ioexpander.c37
-rw-r--r--common/ioexpander_commands.c19
-rw-r--r--common/irq_locking.c2
-rw-r--r--common/kasa.c2
-rw-r--r--common/keyboard_8042.c327
-rw-r--r--common/keyboard_8042_sharedlib.c166
-rw-r--r--common/keyboard_backlight.c39
-rw-r--r--common/keyboard_mkbp.c37
-rw-r--r--common/keyboard_scan.c226
-rw-r--r--common/keyboard_test.c17
-rw-r--r--common/keyboard_vivaldi.c58
-rw-r--r--common/lb_common.c75
-rw-r--r--common/led_common.c6
-rw-r--r--common/led_onoff_states.c50
-rw-r--r--common/led_policy_std.c36
-rw-r--r--common/led_pwm.c11
-rw-r--r--common/lid_angle.c17
-rw-r--r--common/lid_switch.c35
-rw-r--r--common/lightbar.c321
-rw-r--r--common/mag_cal.c52
-rw-r--r--common/main.c30
-rw-r--r--common/mat33.c9
-rw-r--r--common/mat44.c2
-rw-r--r--common/math_util.c110
-rw-r--r--common/memory_commands.c45
-rw-r--r--common/mkbp_event.c62
-rw-r--r--common/mkbp_fifo.c14
-rw-r--r--common/mkbp_info.c6
-rw-r--r--common/mkbp_input_devices.c21
-rw-r--r--common/mock/README.md2
-rw-r--r--common/mock/adc_mock.c2
-rw-r--r--common/mock/battery_mock.c13
-rw-r--r--common/mock/build.mk3
-rw-r--r--common/mock/charge_manager_mock.c4
-rw-r--r--common/mock/dp_alt_mode_mock.c6
-rw-r--r--common/mock/fp_sensor_mock.c7
-rw-r--r--common/mock/fpsensor_crypto_mock.c63
-rw-r--r--common/mock/fpsensor_detect_mock.c2
-rw-r--r--common/mock/fpsensor_state_mock.c35
-rw-r--r--common/mock/mkbp_events_mock.c2
-rw-r--r--common/mock/rollback_mock.c9
-rw-r--r--common/mock/tcpc_mock.c9
-rw-r--r--common/mock/tcpci_i2c_mock.c327
-rw-r--r--common/mock/tcpm_mock.c8
-rw-r--r--common/mock/timer_mock.c2
-rw-r--r--common/mock/usb_mux_mock.c2
-rw-r--r--common/mock/usb_pd_dpm_mock.c18
-rw-r--r--common/mock/usb_pe_sm_mock.c10
-rw-r--r--common/mock/usb_prl_mock.c50
-rw-r--r--common/mock/usb_tc_sm_mock.c43
-rw-r--r--common/motion_lid.c90
-rw-r--r--common/motion_orientation.c13
-rw-r--r--common/motion_sense.c358
-rw-r--r--common/motion_sense_fifo.c122
-rw-r--r--common/newton_fit.c8
-rw-r--r--common/ocpc.c138
-rw-r--r--common/onewire.c30
-rw-r--r--common/online_calibration.c5
-rw-r--r--common/panic_output.c70
-rw-r--r--common/pd_log.c15
-rw-r--r--common/peci.c29
-rw-r--r--common/peripheral.c5
-rw-r--r--common/peripheral_charger.c48
-rw-r--r--common/port80.c42
-rw-r--r--common/power_button.c65
-rw-r--r--common/power_button_x86.c45
-rw-r--r--common/printf.c383
-rw-r--r--common/pstore_commands.c14
-rw-r--r--common/pwm.c19
-rw-r--r--common/pwm_kblight.c2
-rw-r--r--common/queue.c86
-rw-r--r--common/queue_policies.c8
-rw-r--r--common/regulator.c8
-rw-r--r--common/rgb_keyboard.c57
-rw-r--r--common/rollback.c55
-rw-r--r--common/rollback_private.h2
-rw-r--r--common/rsa.c56
-rw-r--r--common/rtc.c14
-rw-r--r--common/rwsig.c46
-rw-r--r--[l---------]common/sha256.c297
-rw-r--r--common/shared_mem.c7
-rw-r--r--common/shmalloc.c33
-rw-r--r--common/spi_commands.c14
-rw-r--r--common/spi_flash.c103
-rw-r--r--common/spi_flash_reg.c33
-rw-r--r--common/spi_nor.c249
-rw-r--r--common/stillness_detector.c22
-rw-r--r--common/switch.c17
-rw-r--r--common/system.c212
-rw-r--r--common/tablet_mode.c35
-rw-r--r--common/temp_sensor.c13
-rw-r--r--common/test_util.c34
-rw-r--r--common/thermal.c25
-rw-r--r--common/throttle_ap.c28
-rw-r--r--common/timer.c46
-rw-r--r--common/typec_control.c8
-rw-r--r--common/uart_buffering.c33
-rw-r--r--common/uart_hostcmd.c2
-rw-r--r--common/uart_printf.c2
-rw-r--r--common/update_fw.c67
-rw-r--r--common/uptime.c10
-rw-r--r--common/usb_charger.c37
-rw-r--r--common/usb_common.c149
-rw-r--r--common/usb_console_stream.c26
-rw-r--r--common/usb_host_command.c62
-rw-r--r--common/usb_i2c.c61
-rw-r--r--common/usb_pd_alt_mode_dfp.c548
-rw-r--r--common/usb_pd_alt_mode_ufp.c2
-rw-r--r--common/usb_pd_console_cmd.c85
-rw-r--r--common/usb_pd_dual_role.c76
-rw-r--r--common/usb_pd_flags.c4
-rw-r--r--common/usb_pd_host_cmd.c167
-rw-r--r--common/usb_pd_pdo.c2
-rw-r--r--common/usb_pd_policy.c512
-rw-r--r--common/usb_pd_protocol.c1235
-rw-r--r--common/usb_pd_tcpc.c280
-rw-r--r--common/usb_port_power_dumb.c29
-rw-r--r--common/usb_port_power_smart.c39
-rw-r--r--common/usb_update.c116
-rw-r--r--common/usbc/build.mk2
-rw-r--r--common/usbc/dp_alt_mode.c74
-rw-r--r--common/usbc/tbt_alt_mode.c398
-rw-r--r--common/usbc/usb_mode.c144
-rw-r--r--common/usbc/usb_pd_console.c75
-rw-r--r--common/usbc/usb_pd_dp_ufp.c54
-rw-r--r--common/usbc/usb_pd_dpm.c344
-rw-r--r--common/usbc/usb_pd_host.c45
-rw-r--r--common/usbc/usb_pd_timer.c133
-rw-r--r--common/usbc/usb_pe_ctvpd_sm.c57
-rw-r--r--common/usbc/usb_pe_drp_sm.c1040
-rw-r--r--common/usbc/usb_pe_private.h84
-rw-r--r--common/usbc/usb_prl_sm.c285
-rw-r--r--common/usbc/usb_retimer_fw_update.c188
-rw-r--r--common/usbc/usb_sm.c30
-rw-r--r--common/usbc/usb_tc_ctvpd_sm.c68
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c398
-rw-r--r--common/usbc/usb_tc_vpd_sm.c21
-rw-r--r--common/usbc/usbc_pd_policy.c10
-rw-r--r--common/usbc/usbc_task.c7
-rw-r--r--common/usbc_intr_task.c24
-rw-r--r--common/usbc_ocp.c43
-rw-r--r--common/usbc_ppc.c26
-rw-r--r--common/util.c90
-rw-r--r--common/util_stdlib.c332
-rw-r--r--common/vboot/common.c10
-rw-r--r--common/vboot/efs2.c58
-rw-r--r--common/vboot/vb21_lib.c17
-rw-r--r--common/vboot/vboot.c42
-rw-r--r--common/vboot_hash.c84
-rw-r--r--common/vec3.c7
-rw-r--r--common/version.c6
-rw-r--r--common/virtual_battery.c46
-rw-r--r--common/vstore.c8
-rw-r--r--common/webusb_desc.c2
-rw-r--r--common/wireless.c19
240 files changed, 8944 insertions, 9563 deletions
diff --git a/common/accel_cal.c b/common/accel_cal.c
index 533a14fbc4..0fe9fe7656 100644
--- a/common/accel_cal.c
+++ b/common/accel_cal.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,17 +23,17 @@ void accel_cal_reset(struct accel_cal *cal)
static inline int compute_temp_gate(const struct accel_cal *cal, fp_t temp)
{
- int gate = (int) fp_div(fp_mul(temp - CONFIG_ACCEL_CAL_MIN_TEMP,
- INT_TO_FP(cal->num_temp_windows)),
- TEMP_RANGE);
+ int gate = (int)fp_div(fp_mul(temp - CONFIG_ACCEL_CAL_MIN_TEMP,
+ INT_TO_FP(cal->num_temp_windows)),
+ TEMP_RANGE);
- return gate < cal->num_temp_windows
- ? gate : (cal->num_temp_windows - 1);
+ return gate < cal->num_temp_windows ? gate :
+ (cal->num_temp_windows - 1);
}
-test_mockable bool accel_cal_accumulate(
- struct accel_cal *cal, uint32_t timestamp, fp_t x, fp_t y, fp_t z,
- fp_t temp)
+test_mockable bool accel_cal_accumulate(struct accel_cal *cal,
+ uint32_t timestamp, fp_t x, fp_t y,
+ fp_t z, fp_t temp)
{
struct accel_cal_algo *algo;
diff --git a/common/acpi.c b/common/acpi.c
index c234347019..86217ab1ba 100644
--- a/common/acpi.c
+++ b/common/acpi.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -15,6 +15,7 @@
#include "host_command.h"
#include "keyboard_backlight.h"
#include "lpc.h"
+#include "printf.h"
#include "pwm.h"
#include "timer.h"
#include "tablet_mode.h"
@@ -24,8 +25,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_LPC, outstr)
-#define CPRINTF(format, args...) cprintf(CC_LPC, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_LPC, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_LPC, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_LPC, format, ##args)
/* Last received ACPI command */
static uint8_t acpi_cmd;
@@ -37,8 +38,8 @@ static int acpi_data_count;
static uint8_t acpi_mem_test;
#ifdef CONFIG_DPTF
-static int dptf_temp_sensor_id; /* last sensor ID written */
-static int dptf_temp_threshold; /* last threshold written */
+static int dptf_temp_sensor_id; /* last sensor ID written */
+static int dptf_temp_threshold; /* last threshold written */
/*
* Current DPTF profile number.
@@ -62,9 +63,9 @@ static int current_dptf_profile = DPTF_PROFILE_DEFAULT;
#define ACPI_READ_CACHE_FLUSHED (EC_ACPI_MEM_MAPPED_BEGIN - 1)
/* Calculate size of valid cache based upon end of memmap data. */
-#define ACPI_VALID_CACHE_SIZE(addr) (MIN( \
- EC_ACPI_MEM_MAPPED_SIZE + EC_ACPI_MEM_MAPPED_BEGIN - (addr), \
- ACPI_READ_CACHE_SIZE))
+#define ACPI_VALID_CACHE_SIZE(addr) \
+ (MIN(EC_ACPI_MEM_MAPPED_SIZE + EC_ACPI_MEM_MAPPED_BEGIN - (addr), \
+ ACPI_READ_CACHE_SIZE))
/*
* In burst mode, read the requested memmap data and the data immediately
@@ -140,24 +141,20 @@ static int acpi_read(uint8_t addr)
/* Check for out-of-range read. */
if (addr < EC_ACPI_MEM_MAPPED_BEGIN ||
addr >= EC_ACPI_MEM_MAPPED_BEGIN + EC_ACPI_MEM_MAPPED_SIZE) {
- CPRINTS("ACPI read 0x%02x (ignored)",
- acpi_addr);
+ CPRINTS("ACPI read 0x%02x (ignored)", acpi_addr);
return 0xff;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif /* __clang__ */
-
/* Read from cache if enabled (burst mode). */
if (acpi_read_cache.enabled) {
/* Fetch to cache on miss. */
if (acpi_read_cache.start_addr == ACPI_READ_CACHE_FLUSHED ||
acpi_read_cache.start_addr > addr ||
- addr - acpi_read_cache.start_addr >=
- ACPI_READ_CACHE_SIZE) {
- memcpy(acpi_read_cache.data,
- memmap_addr,
+ addr - acpi_read_cache.start_addr >= ACPI_READ_CACHE_SIZE) {
+ memcpy(acpi_read_cache.data, memmap_addr,
ACPI_VALID_CACHE_SIZE(addr));
acpi_read_cache.start_addr = addr;
}
@@ -177,7 +174,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
{
int data = 0;
int retval = 0;
- int result = 0xff; /* value for bogus read */
+ int result = 0xff; /* value for bogus read */
/* Read command/data; this clears the FRMH status bit. */
if (is_cmd) {
@@ -241,7 +238,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
#ifdef CONFIG_DPTF
result |= (acpi_dptf_get_profile_num() &
EC_ACPI_MEM_DDPN_MASK)
- << EC_ACPI_MEM_DDPN_SHIFT;
+ << EC_ACPI_MEM_DDPN_SHIFT;
#endif
break;
@@ -260,7 +257,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
result = val >> (8 * off);
break;
- }
+ }
case EC_ACPI_MEM_DEVICE_FEATURES4:
case EC_ACPI_MEM_DEVICE_FEATURES5:
case EC_ACPI_MEM_DEVICE_FEATURES6:
@@ -270,7 +267,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
result = val >> (8 * off);
break;
- }
+ }
#ifdef CONFIG_USB_PORT_POWER_DUMB
case EC_ACPI_MEM_USB_PORT_POWER: {
@@ -289,7 +286,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
result |= 1 << i;
}
break;
- }
+ }
#endif
#ifdef CONFIG_USBC_RETIMER_FW_UPDATE
case EC_ACPI_MEM_USB_RETIMER_FW_UPDATE:
@@ -318,17 +315,19 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
break;
#endif
#ifdef CONFIG_KEYBOARD_BACKLIGHT
- case EC_ACPI_MEM_KEYBOARD_BACKLIGHT:
+ case EC_ACPI_MEM_KEYBOARD_BACKLIGHT: {
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
/*
* Debug output with CR not newline, because the host
* does a lot of keyboard backlights and it scrolls the
* debug console.
*/
- CPRINTF("\r[%pT ACPI kblight %d]",
- PRINTF_TIMESTAMP_NOW, data);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("\r[%s ACPI kblight %d]", ts_str, data);
kblight_set(data);
kblight_enable(data > 0);
break;
+ }
#endif
#ifdef CONFIG_FANS
case EC_ACPI_MEM_FAN_DUTY:
@@ -342,13 +341,12 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
case EC_ACPI_MEM_TEMP_THRESHOLD:
dptf_temp_threshold = data + EC_TEMP_SENSOR_OFFSET;
break;
- case EC_ACPI_MEM_TEMP_COMMIT:
- {
+ case EC_ACPI_MEM_TEMP_COMMIT: {
int idx = data & EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK;
int enable = data & EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK;
dptf_set_temp_threshold(dptf_temp_sensor_id,
- dptf_temp_threshold,
- idx, enable);
+ dptf_temp_threshold, idx,
+ enable);
break;
}
#endif
@@ -380,8 +378,9 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
if (mode_field & 1)
mode = USB_CHARGE_MODE_ENABLED;
- if (usb_charge_set_mode(i, mode,
- USB_ALLOW_SUSPEND_CHARGE)) {
+ if (usb_charge_set_mode(
+ i, mode,
+ USB_ALLOW_SUSPEND_CHARGE)) {
CPRINTS("ERROR: could not set charge "
"mode of USB port p%d to %d",
i, mode);
@@ -389,7 +388,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
mode_field >>= 1;
}
break;
- }
+ }
#endif
#ifdef CONFIG_USBC_RETIMER_FW_UPDATE
case EC_ACPI_MEM_USB_RETIMER_FW_UPDATE:
@@ -427,7 +426,8 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
* Disable from deferred function in case burst mode is enabled
* for an extremely long time (ex. kernel bug / crash).
*/
- hook_call_deferred(&acpi_disable_burst_deferred_data, 1*SECOND);
+ hook_call_deferred(&acpi_disable_burst_deferred_data,
+ 1 * SECOND);
/* ACPI 5.0-12.3.3: Burst ACK */
*resultptr = 0x90;
diff --git a/common/adc.c b/common/adc.c
index c9e3a36e57..89e0b1f645 100644
--- a/common/adc.c
+++ b/common/adc.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -41,7 +41,7 @@ static int print_one_adc(int channel)
return EC_SUCCESS;
}
-static int command_adc(int argc, char **argv)
+static int command_adc(int argc, const char **argv)
{
int i, ret;
@@ -61,9 +61,7 @@ static int command_adc(int argc, char **argv)
return EC_SUCCESS;
}
}
-DECLARE_CONSOLE_COMMAND(adc, command_adc,
- "[name]",
- "Print ADC channel(s)");
+DECLARE_CONSOLE_COMMAND(adc, command_adc, "[name]", "Print ADC channel(s)");
static enum ec_status hc_adc_read(struct host_cmd_handler_args *args)
{
diff --git a/common/als.c b/common/als.c
index 2e9c7ba96c..832ed382f3 100644
--- a/common/als.c
+++ b/common/als.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,9 +19,8 @@
#include "util.h"
#define CPUTS(outstr) cputs(CC_ALS, outstr)
-#define CPRINTS(format, args...) cprints(CC_ALS, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_ALS, format, ## args)
-
+#define CPRINTS(format, args...) cprints(CC_ALS, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_ALS, format, ##args)
#define ALS_POLL_PERIOD SECOND
@@ -90,8 +89,7 @@ static void als_task_init(void)
* Enable ALS task in S0 only and may need to re-enable
* when sysjumped.
*/
- if (system_jumped_late() &&
- chipset_in_state(CHIPSET_STATE_ON))
+ if (system_jumped_late() && chipset_in_state(CHIPSET_STATE_ON))
als_task_enable();
}
@@ -103,7 +101,7 @@ DECLARE_HOOK(HOOK_INIT, als_task_init, HOOK_PRIO_ALS_INIT);
/* Console commands */
#ifdef CONFIG_CMD_ALS
-static int command_als(int argc, char **argv)
+static int command_als(int argc, const char **argv)
{
int i, rv, val;
@@ -121,7 +119,5 @@ static int command_als(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(als, command_als,
- NULL,
- "Print ALS values");
+DECLARE_CONSOLE_COMMAND(als, command_als, NULL, "Print ALS values");
#endif
diff --git a/common/ap_hang_detect.c b/common/ap_hang_detect.c
index 0c9e7a186d..6e3d7177a7 100644
--- a/common/ap_hang_detect.c
+++ b/common/ap_hang_detect.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -18,12 +18,12 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CHIPSET, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ##args)
static struct ec_params_hang_detect hdparams;
-static int active; /* Is hang detect timer active / counting? */
-static int timeout_will_reboot; /* Will the deferred call reboot the AP? */
+static int active; /* Is hang detect timer active / counting? */
+static int timeout_will_reboot; /* Will the deferred call reboot the AP? */
/**
* Handle the hang detect timer expiring.
@@ -56,7 +56,8 @@ static void hang_detect_deferred(void)
timeout_will_reboot = 1;
hook_call_deferred(&hang_detect_deferred_data,
(hdparams.warm_reboot_timeout_msec -
- hdparams.host_event_timeout_msec) * MSEC);
+ hdparams.host_event_timeout_msec) *
+ MSEC);
} else {
/* Not rebooting, so go back to idle */
active = 0;
@@ -196,19 +197,18 @@ hang_detect_host_command(struct host_cmd_handler_args *args)
*/
if (hdparams.warm_reboot_timeout_msec &&
hdparams.warm_reboot_timeout_msec <=
- hdparams.host_event_timeout_msec)
+ hdparams.host_event_timeout_msec)
hdparams.host_event_timeout_msec = 0;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HANG_DETECT,
- hang_detect_host_command,
+DECLARE_HOST_COMMAND(EC_CMD_HANG_DETECT, hang_detect_host_command,
EC_VER_MASK(0));
/*****************************************************************************/
/* Console command */
-static int command_hang_detect(int argc, char **argv)
+static int command_hang_detect(int argc, const char **argv)
{
ccprintf("flags: 0x%x\n", hdparams.flags);
@@ -233,6 +233,5 @@ static int command_hang_detect(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(hangdet, command_hang_detect,
- NULL,
+DECLARE_CONSOLE_COMMAND(hangdet, command_hang_detect, NULL,
"Print hang detect state");
diff --git a/common/audio_codec.c b/common/audio_codec.c
index 3f7203ad15..aba1453ce3 100644
--- a/common/audio_codec.c
+++ b/common/audio_codec.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,15 +9,14 @@
#include "host_command.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ##args)
-static const uint32_t capabilities =
- 0
+static const uint32_t capabilities = 0
#ifdef CONFIG_AUDIO_CODEC_CAP_WOV_AUDIO_SHM
- | BIT(EC_CODEC_CAP_WOV_AUDIO_SHM)
+ | BIT(EC_CODEC_CAP_WOV_AUDIO_SHM)
#endif
#ifdef CONFIG_AUDIO_CODEC_CAP_WOV_LANG_SHM
- | BIT(EC_CODEC_CAP_WOV_LANG_SHM)
+ | BIT(EC_CODEC_CAP_WOV_LANG_SHM)
#endif
;
@@ -122,8 +121,8 @@ int audio_codec_capable(uint8_t cap)
return capabilities & BIT(cap);
}
-int audio_codec_register_shm(uint8_t shm_id, uint8_t cap,
- uintptr_t *addr, uint32_t len, uint8_t type)
+int audio_codec_register_shm(uint8_t shm_id, uint8_t cap, uintptr_t *addr,
+ uint32_t len, uint8_t type)
{
if (shm_id >= EC_CODEC_SHM_ID_LAST)
return EC_ERROR_INVAL;
@@ -140,8 +139,8 @@ int audio_codec_register_shm(uint8_t shm_id, uint8_t cap,
return EC_SUCCESS;
}
-__attribute__((weak))
-int audio_codec_memmap_ap_to_ec(uintptr_t ap_addr, uintptr_t *ec_addr)
+__attribute__((weak)) int audio_codec_memmap_ap_to_ec(uintptr_t ap_addr,
+ uintptr_t *ec_addr)
{
return EC_ERROR_UNIMPLEMENTED;
}
diff --git a/common/audio_codec_dmic.c b/common/audio_codec_dmic.c
index c4f0b07a46..d85245791d 100644
--- a/common/audio_codec_dmic.c
+++ b/common/audio_codec_dmic.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,7 +8,7 @@
#include "console.h"
#include "host_command.h"
-#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ##args)
static enum ec_status dmic_get_max_gain(struct host_cmd_handler_args *args)
{
@@ -25,9 +25,9 @@ static enum ec_status dmic_set_gain_idx(struct host_cmd_handler_args *args)
{
const struct ec_param_ec_codec_dmic *p = args->params;
- if (audio_codec_dmic_set_gain_idx(
- p->set_gain_idx_param.channel,
- p->set_gain_idx_param.gain) != EC_SUCCESS)
+ if (audio_codec_dmic_set_gain_idx(p->set_gain_idx_param.channel,
+ p->set_gain_idx_param.gain) !=
+ EC_SUCCESS)
return EC_RES_ERROR;
return EC_RES_SUCCESS;
@@ -38,8 +38,8 @@ static enum ec_status dmic_get_gain_idx(struct host_cmd_handler_args *args)
const struct ec_param_ec_codec_dmic *p = args->params;
struct ec_response_ec_codec_dmic_get_gain_idx *r = args->response;
- if (audio_codec_dmic_get_gain_idx(
- p->get_gain_idx_param.channel, &r->gain) != EC_SUCCESS)
+ if (audio_codec_dmic_get_gain_idx(p->get_gain_idx_param.channel,
+ &r->gain) != EC_SUCCESS)
return EC_RES_ERROR;
args->response_size = sizeof(*r);
diff --git a/common/audio_codec_i2s_rx.c b/common/audio_codec_i2s_rx.c
index aeae19bdca..ac6aa8ecce 100644
--- a/common/audio_codec_i2s_rx.c
+++ b/common/audio_codec_i2s_rx.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,7 +8,7 @@
#include "console.h"
#include "host_command.h"
-#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ##args)
static uint8_t i2s_rx_enabled;
@@ -128,5 +128,5 @@ static enum ec_status i2s_rx_host_command(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
}
-DECLARE_HOST_COMMAND(EC_CMD_EC_CODEC_I2S_RX,
- i2s_rx_host_command, EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_EC_CODEC_I2S_RX, i2s_rx_host_command,
+ EC_VER_MASK(0));
diff --git a/common/audio_codec_wov.c b/common/audio_codec_wov.c
index f84e45f342..7c7b43acae 100644
--- a/common/audio_codec_wov.c
+++ b/common/audio_codec_wov.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,7 +13,7 @@
#include "task.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_AUDIO_CODEC, format, ##args)
/*
* To shorten the variable names, or the following code is likely to greater
@@ -99,7 +99,7 @@ static enum ec_status wov_set_lang_shm(struct host_cmd_handler_args *args)
{
const struct ec_param_ec_codec_wov *p = args->params;
const struct ec_param_ec_codec_wov_set_lang_shm *pp =
- &p->set_lang_shm_param;
+ &p->set_lang_shm_param;
if (pp->total_len > LANG_BUF_LEN)
return EC_RES_INVALID_PARAM;
@@ -135,11 +135,11 @@ static enum ec_status wov_set_lang(struct host_cmd_handler_args *args)
return EC_RES_BUSY;
if (!pp->offset)
- memset((uint8_t *)audio_codec_wov_lang_buf_addr,
- 0, LANG_BUF_LEN);
+ memset((uint8_t *)audio_codec_wov_lang_buf_addr, 0,
+ LANG_BUF_LEN);
- memcpy((uint8_t *)audio_codec_wov_lang_buf_addr + pp->offset,
- pp->buf, pp->len);
+ memcpy((uint8_t *)audio_codec_wov_lang_buf_addr + pp->offset, pp->buf,
+ pp->len);
if (pp->offset + pp->len == pp->total_len) {
if (check_lang_buf((uint8_t *)audio_codec_wov_lang_buf_addr,
@@ -176,7 +176,7 @@ static enum ec_status wov_enable(struct host_cmd_handler_args *args)
if (!speech_lib_loaded) {
if (!GoogleHotwordDspInit(
- (void *)audio_codec_wov_lang_buf_addr))
+ (void *)audio_codec_wov_lang_buf_addr))
return EC_RES_ERROR;
speech_lib_loaded = 1;
} else {
@@ -359,7 +359,6 @@ void audio_codec_wov_task(void *arg)
continue;
}
-
/* Clear the buffer if full. */
if (is_buf_full()) {
audio_buf_wp = audio_buf_rp;
@@ -415,7 +414,7 @@ void audio_codec_wov_task(void *arg)
* case, sample is S16_LE. Thus, n / 2.
*/
if (!hotword_detected &&
- GoogleHotwordDspProcess(p, n / 2, &r)) {
+ GoogleHotwordDspProcess(p, n / 2, &r)) {
CPRINTS("hotword detected");
mutex_lock(&lock);
diff --git a/common/backlight_lid.c b/common/backlight_lid.c
index f0dd3b2e24..f8fd8d637f 100644
--- a/common/backlight_lid.c
+++ b/common/backlight_lid.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,7 +11,6 @@
#include "host_command.h"
#include "lid_switch.h"
-
/**
* Activate/Deactivate the backlight GPIO pin considering active high or low.
*/
@@ -32,7 +31,7 @@ static void update_backlight(void)
#ifdef CONFIG_BACKLIGHT_REQ_GPIO
/* Enable the backlight if lid is open AND requested by AP */
enable_backlight(lid_is_open() &&
- gpio_get_level(CONFIG_BACKLIGHT_REQ_GPIO));
+ gpio_get_level(CONFIG_BACKLIGHT_REQ_GPIO));
#else
/*
* Enable backlight if lid is open; this is AND'd with the request from
@@ -79,5 +78,4 @@ switch_command_enable_backlight(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_SWITCH_ENABLE_BKLIGHT,
- switch_command_enable_backlight,
- EC_VER_MASK(0));
+ switch_command_enable_backlight, EC_VER_MASK(0));
diff --git a/common/base32.c b/common/base32.c
index a6be8409b1..fc3fe3c8ae 100644
--- a/common/base32.c
+++ b/common/base32.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,15 +9,13 @@
#include "base32.h"
#include "util.h"
-static const unsigned char crc5_table1[] = {
- 0x00, 0x0E, 0x1C, 0x12, 0x11, 0x1F, 0x0D, 0x03,
- 0x0B, 0x05, 0x17, 0x19, 0x1A, 0x14, 0x06, 0x08
-};
+static const unsigned char crc5_table1[] = { 0x00, 0x0E, 0x1C, 0x12, 0x11, 0x1F,
+ 0x0D, 0x03, 0x0B, 0x05, 0x17, 0x19,
+ 0x1A, 0x14, 0x06, 0x08 };
-static const unsigned char crc5_table0[] = {
- 0x00, 0x16, 0x05, 0x13, 0x0A, 0x1C, 0x0F, 0x19,
- 0x14, 0x02, 0x11, 0x07, 0x1E, 0x08, 0x1B, 0x0D
-};
+static const unsigned char crc5_table0[] = { 0x00, 0x16, 0x05, 0x13, 0x0A, 0x1C,
+ 0x0F, 0x19, 0x14, 0x02, 0x11, 0x07,
+ 0x1E, 0x08, 0x1B, 0x0D };
uint8_t crc5_sym(uint8_t sym, uint8_t previous_crc)
{
@@ -46,9 +44,8 @@ static int decode_sym(int sym)
return -1;
}
-int base32_encode(char *dest, int destlen_chars,
- const void *srcbits, int srclen_bits,
- int add_crc_every)
+int base32_encode(char *dest, int destlen_chars, const void *srcbits,
+ int srclen_bits, int add_crc_every)
{
const uint8_t *src = srcbits;
int destlen_needed;
@@ -59,14 +56,14 @@ int base32_encode(char *dest, int destlen_chars,
*dest = 0;
/* Make sure destination is big enough */
- destlen_needed = (srclen_bits + 4) / 5; /* Symbols before adding CRC */
+ destlen_needed = (srclen_bits + 4) / 5; /* Symbols before adding CRC */
if (add_crc_every) {
/* Must be an exact number of groups to add CRC */
if (destlen_needed % add_crc_every)
return EC_ERROR_INVAL;
destlen_needed += destlen_needed / add_crc_every;
}
- destlen_needed++; /* For terminating null */
+ destlen_needed++; /* For terminating null */
if (destlen_chars < destlen_needed)
return EC_ERROR_INVAL;
@@ -124,7 +121,7 @@ int base32_decode(uint8_t *dest, int destlen_bits, const char *src,
sym = decode_sym(*src);
if (sym < 0)
- return -1; /* Bad input symbol */
+ return -1; /* Bad input symbol */
/* Check CRC if needed */
if (crc_after_every) {
@@ -155,7 +152,7 @@ int base32_decode(uint8_t *dest, int destlen_bits, const char *src,
dbits = 8 - (out_bits & 7);
b = MIN(dbits, sbits);
if (dbits == 8)
- dest[out_bits / 8] = 0; /* Starting a new byte */
+ dest[out_bits / 8] = 0; /* Starting a new byte */
dest[out_bits / 8] |= (sym << (dbits - b)) >> (sbits - b);
out_bits += b;
sbits -= b;
diff --git a/common/base_state.c b/common/base_state.c
index 543329fe29..f90a5e7ce5 100644
--- a/common/base_state.c
+++ b/common/base_state.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,7 +8,7 @@
#include "host_command.h"
#include "hooks.h"
-#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ##args)
#ifdef CONFIG_BASE_ATTACHED_SWITCH
/* 1: base attached, 0: otherwise */
@@ -33,7 +33,7 @@ void base_set_state(int state)
}
#endif
-static int command_setbasestate(int argc, char **argv)
+static int command_setbasestate(int argc, const char **argv)
{
if (argc != 2)
return EC_ERROR_PARAM_COUNT;
@@ -47,10 +47,9 @@ static int command_setbasestate(int argc, char **argv)
return EC_ERROR_PARAM1;
return EC_SUCCESS;
-
}
-DECLARE_CONSOLE_COMMAND(basestate, command_setbasestate,
- "[attach | detach | reset]",
+DECLARE_CONSOLE_COMMAND(
+ basestate, command_setbasestate, "[attach | detach | reset]",
"Manually force base state to attached, detached or reset.");
static enum ec_status hostcmd_setbasestate(struct host_cmd_handler_args *args)
diff --git a/common/battery.c b/common/battery.c
index 01478d5b52..00c9540a1f 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -6,6 +6,7 @@
*/
#include "battery.h"
+#include "battery_fuel_gauge.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "common.h"
@@ -21,8 +22,8 @@
#include "util.h"
#include "watchdog.h"
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
#define CUTOFFPRINTS(info) CPRINTS("%s %s", "Battery cut off", info)
/* See config.h for details */
@@ -77,9 +78,14 @@ static int check_print_error(int rv)
static void print_battery_status(void)
{
- static const char * const st[] = {"EMPTY", "FULL", "DCHG", "INIT",};
- static const char * const al[] = {"RT", "RC", "--", "TD",
- "OT", "--", "TC", "OC"};
+ static const char *const st[] = {
+ "EMPTY",
+ "FULL",
+ "DCHG",
+ "INIT",
+ };
+ static const char *const al[] = { "RT", "RC", "--", "TD",
+ "OT", "--", "TC", "OC" };
int value, i;
@@ -92,12 +98,12 @@ static void print_battery_status(void)
/* bits 4-7 are status */
for (i = 0; i < 4; i++)
- if (value & (1 << (i+4)))
+ if (value & (1 << (i + 4)))
ccprintf(" %s", st[i]);
/* bits 15-8 are alarms */
for (i = 0; i < 8; i++)
- if (value & (1 << (i+8)))
+ if (value & (1 << (i + 8)))
ccprintf(" %s", al[i]);
ccprintf("\n");
@@ -138,10 +144,8 @@ static void print_battery_params(void)
ccprintf("%08x\n", batt->flags);
print_item_name("Temp:");
- ccprintf("0x%04x = %.1d K (%.1d C)\n",
- batt->temperature,
- batt->temperature,
- batt->temperature - 2731);
+ ccprintf("0x%04x = %.1d K (%.1d C)\n", batt->temperature,
+ batt->temperature, batt->temperature - 2731);
print_item_name("V:");
ccprintf("0x%04x = %d mV\n", batt->voltage, batt->voltage);
@@ -167,7 +171,7 @@ static void print_battery_params(void)
batt->flags & BATT_FLAG_WANT_CHARGE ? "" : "Not ");
print_item_name("Charge:");
- ccprintf("%d %%\n", batt->state_of_charge);
+ ccprintf("%d %%\n", batt->state_of_charge);
if (IS_ENABLED(CONFIG_CHARGER)) {
int value;
@@ -214,10 +218,10 @@ static void print_battery_info(void)
print_item_name("Time-full:");
if (check_print_error(battery_time_to_full(&value))) {
if (value == 65535) {
- hour = 0;
+ hour = 0;
minute = 0;
} else {
- hour = value / 60;
+ hour = value / 60;
minute = value % 60;
}
ccprintf("%dh:%d\n", hour, minute);
@@ -226,10 +230,10 @@ static void print_battery_info(void)
print_item_name(" Empty:");
if (check_print_error(battery_time_to_empty(&value))) {
if (value == 65535) {
- hour = 0;
+ hour = 0;
minute = 0;
} else {
- hour = value / 60;
+ hour = value / 60;
minute = value % 60;
}
ccprintf("%dh:%d\n", hour, minute);
@@ -240,6 +244,15 @@ static void print_battery_info(void)
print_item_name("shutdown_soc:");
ccprintf("%d %%\n", batt_host_shutdown_pct);
+
+#ifdef CONFIG_BATTERY_FUEL_GAUGE
+ value = battery_is_charge_fet_disabled();
+ /* reverse the flag if no error */
+ if (value != -1)
+ value = !value;
+ print_item_name("C-FET:");
+ ccprintf("%d\n", value);
+#endif
}
void print_battery_debug(void)
@@ -250,7 +263,7 @@ void print_battery_debug(void)
print_battery_info();
}
-static int command_battery(int argc, char **argv)
+static int command_battery(int argc, const char **argv)
{
int repeat = 1;
int loop;
@@ -289,8 +302,7 @@ static int command_battery(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(battery, command_battery,
- "<repeat_count> <sleep_ms>",
+DECLARE_CONSOLE_COMMAND(battery, command_battery, "<repeat_count> <sleep_ms>",
"Print battery info");
#ifdef CONFIG_BATTERY_CUT_OFF
@@ -349,7 +361,7 @@ static enum ec_status battery_command_cutoff(struct host_cmd_handler_args *args)
return rv;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cutoff,
- EC_VER_MASK(0) | EC_VER_MASK(1));
+ EC_VER_MASK(0) | EC_VER_MASK(1));
static void check_pending_cutoff(void)
{
@@ -362,7 +374,7 @@ static void check_pending_cutoff(void)
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, check_pending_cutoff, HOOK_PRIO_LAST);
-static int command_cutoff(int argc, char **argv)
+static int command_cutoff(int argc, const char **argv)
{
int rv;
@@ -384,15 +396,14 @@ static int command_cutoff(int argc, char **argv)
return EC_ERROR_UNKNOWN;
}
-DECLARE_CONSOLE_COMMAND(cutoff, command_cutoff,
- "[at-shutdown]",
- "Cut off the battery output");
+DECLARE_CONSOLE_COMMAND(cutoff, command_cutoff, "[at-shutdown]",
+ "Cut off the battery output");
#else
int battery_is_cut_off(void)
{
- return 0; /* Always return NOT cut off */
+ return 0; /* Always return NOT cut off */
}
-#endif /* CONFIG_BATTERY_CUT_OFF */
+#endif /* CONFIG_BATTERY_CUT_OFF */
#ifdef CONFIG_BATTERY_VENDOR_PARAM
__overridable int battery_get_vendor_param(uint32_t param, uint32_t *value)
@@ -427,7 +438,7 @@ __overridable int battery_set_vendor_param(uint32_t param, uint32_t value)
return EC_ERROR_UNIMPLEMENTED;
}
-static int console_command_battery_vendor_param(int argc, char **argv)
+static int console_command_battery_vendor_param(int argc, const char **argv)
{
uint32_t param;
uint32_t value;
@@ -488,11 +499,9 @@ host_command_battery_vendor_param(struct host_cmd_handler_args *args)
return rv;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_VENDOR_PARAM,
- host_command_battery_vendor_param,
- EC_VER_MASK(0));
+ host_command_battery_vendor_param, EC_VER_MASK(0));
#endif /* CONFIG_BATTERY_VENDOR_PARAM */
-
void battery_compensate_params(struct batt_params *batt)
{
int numer, denom;
@@ -500,7 +509,7 @@ void battery_compensate_params(struct batt_params *batt)
int full = batt->full_capacity;
if ((batt->flags & BATT_FLAG_BAD_FULL_CAPACITY) ||
- (batt->flags & BATT_FLAG_BAD_REMAINING_CAPACITY))
+ (batt->flags & BATT_FLAG_BAD_REMAINING_CAPACITY))
return;
if (*remain <= 0 || full <= 0)
@@ -589,20 +598,21 @@ __overridable enum battery_disconnect_state battery_get_disconnect_state(void)
#ifdef CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV
#if CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV < 5000 || \
- CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV >= PD_MAX_VOLTAGE_MV
- #error "Voltage limit must be between 5000 and PD_MAX_VOLTAGE_MV"
+ CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV >= PD_MAX_VOLTAGE_MV
+#error "Voltage limit must be between 5000 and PD_MAX_VOLTAGE_MV"
#endif
#if !((defined(CONFIG_USB_PD_TCPMV1) && defined(CONFIG_USB_PD_DUAL_ROLE)) || \
- (defined(CONFIG_USB_PD_TCPMV2) && defined(CONFIG_USB_PE_SM)))
- #error "Voltage reducing requires TCPM with Policy Engine"
+ (defined(CONFIG_USB_PD_TCPMV2) && defined(CONFIG_USB_PE_SM)))
+#error "Voltage reducing requires TCPM with Policy Engine"
#endif
/*
* Returns true if input voltage should be reduced (chipset is in S5/G3) and
* battery is full, otherwise returns false
*/
-static bool board_wants_reduced_input_voltage(void) {
+static bool board_wants_reduced_input_voltage(void)
+{
struct batt_params batt;
/* Chipset not in S5/G3, so we don't want to reduce voltage */
@@ -638,7 +648,7 @@ static void reduce_input_voltage_when_full(void)
CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV) {
saved_input_voltage = max_pd_voltage_mv;
max_pd_voltage_mv =
- CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV;
+ CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV;
}
} else if (saved_input_voltage != -1) {
/*
@@ -656,8 +666,7 @@ static void reduce_input_voltage_when_full(void)
if (pd_get_max_voltage() != max_pd_voltage_mv)
pd_set_external_voltage_limit(port, max_pd_voltage_mv);
}
-DECLARE_HOOK(HOOK_AC_CHANGE, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_AC_CHANGE, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, reduce_input_voltage_when_full,
HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, reduce_input_voltage_when_full,
@@ -677,7 +686,7 @@ void battery_validate_params(struct batt_params *batt)
*/
if (batt->temperature > CELSIUS_TO_DECI_KELVIN(5660)) {
CPRINTS("ignoring ridiculous batt.temp of %dC",
- DECI_KELVIN_TO_CELSIUS(batt->temperature));
+ DECI_KELVIN_TO_CELSIUS(batt->temperature));
batt->flags |= BATT_FLAG_BAD_TEMPERATURE;
}
diff --git a/common/battery_fuel_gauge.c b/common/battery_fuel_gauge.c
index 900798a9fd..0382abca26 100644
--- a/common/battery_fuel_gauge.c
+++ b/common/battery_fuel_gauge.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -12,7 +12,7 @@
#include "i2c.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
/*
* Authenticate the battery connected.
@@ -26,8 +26,8 @@ static bool authenticate_battery_type(int index, char *manuf_name)
{
char device_name[32];
- const struct fuel_gauge_info * const fuel_gauge =
- &board_battery_info[index].fuel_gauge;
+ const struct fuel_gauge_info *const fuel_gauge =
+ &board_battery_info[index].fuel_gauge;
int len = 0;
/* check for valid index */
@@ -40,17 +40,14 @@ static bool authenticate_battery_type(int index, char *manuf_name)
/* device name is specified in table */
if (fuel_gauge->device_name != NULL) {
-
/* Get the device name */
- if (battery_device_name(device_name,
- sizeof(device_name)))
+ if (battery_device_name(device_name, sizeof(device_name)))
return false;
len = strlen(fuel_gauge->device_name);
/* device name mismatch */
- if (strncasecmp(device_name, fuel_gauge->device_name,
- len))
+ if (strncasecmp(device_name, fuel_gauge->device_name, len))
return false;
}
@@ -70,7 +67,7 @@ static int battery_get_fixed_battery_type(void)
{
if (fixed_battery_type == BATTERY_TYPE_UNINITIALIZED) {
CPRINTS("Warning: Battery type is not Initialized! "
- "Setting to default battery type.\n");
+ "Setting to default battery type.\n");
fixed_battery_type = DEFAULT_BATTERY_TYPE;
}
@@ -144,7 +141,8 @@ static inline const struct board_batt_params *get_batt_params(void)
int type = get_battery_type();
return &board_battery_info[type == BATTERY_TYPE_COUNT ?
- board_get_default_battery_type() : type];
+ board_get_default_battery_type() :
+ type];
}
const struct battery_info *battery_get_info(void)
@@ -202,10 +200,10 @@ int board_cut_off_battery(void)
if (board_battery_info[type].fuel_gauge.ship_mode.wb_support)
rv = cut_off_battery_block_write(
- &board_battery_info[type].fuel_gauge.ship_mode);
+ &board_battery_info[type].fuel_gauge.ship_mode);
else
rv = cut_off_battery_sb_write(
- &board_battery_info[type].fuel_gauge.ship_mode);
+ &board_battery_info[type].fuel_gauge.ship_mode);
return rv ? EC_RES_ERROR : EC_RES_SUCCESS;
}
@@ -308,8 +306,7 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
if ((reg & board_battery_info[type].fuel_gauge.fet.reg_mask) ==
board_battery_info[type].fuel_gauge.fet.disconnect_val) {
CPRINTS("Batt disconnected: reg 0x%04x mask 0x%04x disc 0x%04x",
- reg,
- board_battery_info[type].fuel_gauge.fet.reg_mask,
+ reg, board_battery_info[type].fuel_gauge.fet.reg_mask,
board_battery_info[type].fuel_gauge.fet.disconnect_val);
return BATTERY_DISCONNECTED;
}
@@ -326,8 +323,9 @@ int battery_imbalance_mv(void)
* If battery type is unknown, we cannot safely access non-standard
* registers.
*/
- return (type == BATTERY_TYPE_COUNT) ? 0 :
- board_battery_info[type].fuel_gauge.imbalance_mv();
+ return (type == BATTERY_TYPE_COUNT) ?
+ 0 :
+ board_battery_info[type].fuel_gauge.imbalance_mv();
}
int battery_default_imbalance_mv(void)
diff --git a/common/battery_v1.c b/common/battery_v1.c
index d6fc42affb..2c81d6b446 100644
--- a/common/battery_v1.c
+++ b/common/battery_v1.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.
*
@@ -15,8 +15,8 @@
#include "printf.h"
#include "util.h"
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
/* Returns zero if every item was updated. */
int update_static_battery_info(void)
@@ -34,8 +34,11 @@ int update_static_battery_info(void)
batt_str = (char *)host_get_memmap(EC_MEMMAP_BATT_SERIAL);
memset(batt_str, 0, EC_MEMMAP_TEXT_MAX);
rv = battery_serial_number(&batt_serial);
- if (!rv)
- snprintf(batt_str, EC_MEMMAP_TEXT_MAX, "%04X", batt_serial);
+ if (!rv) {
+ if (snprintf(batt_str, EC_MEMMAP_TEXT_MAX, "%04X",
+ batt_serial) <= 0)
+ rv |= EC_ERROR_UNKNOWN;
+ }
/* Design Capacity of Full */
rv |= battery_design_capacity(
@@ -136,7 +139,8 @@ void update_dynamic_battery_info(void)
* Don't report zero charge, as that has special meaning
* to Chrome OS powerd.
*/
- if (curr->batt.remaining_capacity == 0 && !curr->batt_is_charging)
+ if (curr->batt.remaining_capacity == 0 &&
+ !curr->batt_is_charging)
*memmap_cap = 1;
else
*memmap_cap = curr->batt.remaining_capacity;
@@ -151,12 +155,11 @@ void update_dynamic_battery_info(void)
}
if (curr->batt.is_present == BP_YES &&
- !(curr->batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- curr->batt.state_of_charge <= BATTERY_LEVEL_CRITICAL)
+ battery_is_below_threshold(BATT_THRESHOLD_TYPE_SHUTDOWN, false))
tmp |= EC_BATT_FLAG_LEVEL_CRITICAL;
tmp |= curr->batt_is_charging ? EC_BATT_FLAG_CHARGING :
- EC_BATT_FLAG_DISCHARGING;
+ EC_BATT_FLAG_DISCHARGING;
/* Tell the AP to re-read battery status if charge state changes */
if (*memmap_flags != tmp)
diff --git a/common/battery_v2.c b/common/battery_v2.c
index 27ae0285ac..57ae07196b 100644
--- a/common/battery_v2.c
+++ b/common/battery_v2.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.
*
@@ -15,8 +15,8 @@
#include "printf.h"
#include "util.h"
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
/*
* Store battery information in these 2 structures. Main (lid) battery is always
@@ -135,8 +135,7 @@ host_command_battery_get_static(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_BATTERY_GET_STATIC,
- host_command_battery_get_static,
+DECLARE_HOST_COMMAND(EC_CMD_BATTERY_GET_STATIC, host_command_battery_get_static,
EC_VER_MASK(0) | EC_VER_MASK(1));
static enum ec_status
@@ -154,8 +153,7 @@ host_command_battery_get_dynamic(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_GET_DYNAMIC,
- host_command_battery_get_dynamic,
- EC_VER_MASK(0));
+ host_command_battery_get_dynamic, EC_VER_MASK(0));
#endif /* CONFIG_HOSTCMD_BATTERY_V2 */
void battery_memmap_refresh(enum battery_index index)
@@ -222,8 +220,9 @@ int update_static_battery_info(void)
/* Smart battery serial number is 16 bits */
rv = battery_serial_number(&batt_serial);
if (!rv)
- snprintf(bs->serial_ext, sizeof(bs->serial_ext),
- "%04X", batt_serial);
+ if (snprintf(bs->serial_ext, sizeof(bs->serial_ext), "%04X",
+ batt_serial) <= 0)
+ rv |= EC_ERROR_UNKNOWN;
/* Design Capacity of Full */
ret = battery_design_capacity(&val);
@@ -344,29 +343,31 @@ void update_dynamic_battery_info(void)
* to Chrome OS powerd.
*/
if (curr->batt.remaining_capacity == 0 &&
- !curr->batt_is_charging)
+ !curr->batt_is_charging)
bd->remaining_capacity = 1;
else
bd->remaining_capacity = curr->batt.remaining_capacity;
}
if (!(curr->batt.flags & BATT_FLAG_BAD_FULL_CAPACITY) &&
- (curr->batt.full_capacity <=
- (bd->full_capacity - LFCC_EVENT_THRESH) ||
- curr->batt.full_capacity >=
- (bd->full_capacity + LFCC_EVENT_THRESH))) {
+ (curr->batt.full_capacity <=
+ (bd->full_capacity - LFCC_EVENT_THRESH) ||
+ curr->batt.full_capacity >=
+ (bd->full_capacity + LFCC_EVENT_THRESH))) {
bd->full_capacity = curr->batt.full_capacity;
/* Poke the AP if the full_capacity changes. */
send_batt_info_event++;
}
if (curr->batt.is_present == BP_YES &&
- !(curr->batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- curr->batt.state_of_charge <= BATTERY_LEVEL_CRITICAL)
+ battery_is_below_threshold(BATT_THRESHOLD_TYPE_SHUTDOWN, false))
tmp |= EC_BATT_FLAG_LEVEL_CRITICAL;
tmp |= curr->batt_is_charging ? EC_BATT_FLAG_CHARGING :
- EC_BATT_FLAG_DISCHARGING;
+ EC_BATT_FLAG_DISCHARGING;
+
+ if (battery_is_cut_off())
+ tmp |= EC_BATT_FLAG_CUT_OFF;
/* Tell the AP to re-read battery status if charge state changes */
if (bd->flags != tmp)
diff --git a/common/blink.c b/common/blink.c
index ed16146f5a..dcd6f0bdaa 100644
--- a/common/blink.c
+++ b/common/blink.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,12 +10,12 @@
#include "hooks.h"
#ifndef CONFIG_BLINK_LEDS
- #error The macro CONFIG_BLINK_LEDS must be specified to use BLINK.
+#error The macro CONFIG_BLINK_LEDS must be specified to use BLINK.
#endif
static const enum gpio_signal leds[] = { CONFIG_BLINK_LEDS };
-BUILD_ASSERT(ARRAY_SIZE(leds) <= sizeof(int)*8, "Too many LEDs to drive.");
+BUILD_ASSERT(ARRAY_SIZE(leds) <= sizeof(int) * 8, "Too many LEDs to drive.");
BUILD_ASSERT(ARRAY_SIZE(leds) > 0, "Must have at least one LED to blink.");
static void blink(void)
diff --git a/common/bluetooth_le.c b/common/bluetooth_le.c
index c148ef8285..3108553a8b 100644
--- a/common/bluetooth_le.c
+++ b/common/bluetooth_le.c
@@ -1,13 +1,14 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "builtin/assert.h"
#include "bluetooth_le.h"
#include "util.h"
#include "console.h"
-#define CPRINTF(format, args...) cprintf(CC_BLUETOOTH_LE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_BLUETOOTH_LE, format, ##args)
/*
* Convert from BLE Channel to frequency
@@ -15,11 +16,11 @@
* Bluetooth 4.1 Vol 6 pg 36 4.1 Table 1.1
*/
-#define CHAN_0_MHZ 2404
-#define CHAN_11_MHZ 2428
-#define CHAN_37_MHZ 2402
-#define CHAN_38_MHZ 2426
-#define CHAN_39_MHZ 2480
+#define CHAN_0_MHZ 2404
+#define CHAN_11_MHZ 2428
+#define CHAN_37_MHZ 2402
+#define CHAN_38_MHZ 2426
+#define CHAN_39_MHZ 2480
int chan2freq(int channel)
{
@@ -72,11 +73,11 @@ uint8_t get_next_data_channel(struct remapping_table *rt)
/* Check if the channel is mapped */
if (rt->map[rt->last_unmapped_channel / 8] &
- (1 << (rt->last_unmapped_channel % 8)))
+ (1 << (rt->last_unmapped_channel % 8)))
return rt->last_unmapped_channel;
else
- return rt->remapping_index
- [rt->last_unmapped_channel % rt->num_used_channels];
+ return rt->remapping_index[rt->last_unmapped_channel %
+ rt->num_used_channels];
}
/* BLE 4.1 Vol 3 Part C 11 */
@@ -85,27 +86,27 @@ uint8_t get_next_data_channel(struct remapping_table *rt)
uint8_t *pack_adv(uint8_t *dest, int length, int type, const uint8_t *data)
{
/* Add the structure length */
- dest[0] = (uint8_t)length+1;
+ dest[0] = (uint8_t)length + 1;
/* Add the structure type */
dest[1] = (uint8_t)type;
/* Add the data */
memcpy(&dest[2], data, length);
/* Return a pointer to the next structure */
- return &dest[2+length];
+ return &dest[2 + length];
}
uint8_t *pack_adv_int(uint8_t *dest, int length, int type, int data)
{
/* Add the structure length */
- dest[0] = (uint8_t)length+1;
+ dest[0] = (uint8_t)length + 1;
/* Add the structure type */
dest[1] = (uint8_t)type;
/* Add the data */
memcpy(&dest[2], &data, length);
/* Return a pointer to the next structure */
- return &dest[2+length];
+ return &dest[2 + length];
}
uint8_t *pack_adv_addr(uint8_t *dest, uint64_t addr)
@@ -139,7 +140,7 @@ static void mem_dump(uint8_t *mem, int len)
for (i = 0; i < len; i++) {
value = mem[i];
if (i % 8 == 0)
- CPRINTF("\n%pP: %02x", &mem[i], value);
+ CPRINTF("\n%p: %02x", &mem[i], value);
else
CPRINTF(" %02x", value);
}
@@ -160,19 +161,19 @@ void dump_ble_packet(struct ble_pdu *ble_p)
int curr_offs;
if (ble_p->header_type_adv) {
- CPRINTF("BLE packet @ %pP: type %d, len %d, %s %s\n",
- ble_p, ble_p->header.adv.type, ble_p->header.adv.length,
+ CPRINTF("BLE packet @ %p: type %d, len %d, %s %s\n", ble_p,
+ ble_p->header.adv.type, ble_p->header.adv.length,
(ble_p->header.adv.txaddr ? " TXADDR" : ""),
(ble_p->header.adv.rxaddr ? " RXADDR" : ""));
curr_offs = 0;
if (ble_p->header.adv.type ==
- BLE_ADV_HEADER_PDU_TYPE_SCAN_REQ) {
+ BLE_ADV_HEADER_PDU_TYPE_SCAN_REQ) {
dump_ble_addr(ble_p->payload, "ScanA");
curr_offs += BLUETOOTH_ADDR_OCTETS;
} else if (ble_p->header.adv.type ==
- BLE_ADV_HEADER_PDU_TYPE_CONNECT_REQ) {
+ BLE_ADV_HEADER_PDU_TYPE_CONNECT_REQ) {
dump_ble_addr(ble_p->payload, "InitA");
curr_offs += BLUETOOTH_ADDR_OCTETS;
}
@@ -187,7 +188,7 @@ void dump_ble_packet(struct ble_pdu *ble_p)
mem_dump(ble_p->payload + curr_offs,
ble_p->header.adv.length - curr_offs);
} else { /* Data PDUs */
- CPRINTF("BLE data packet @%pP: LLID %d,"
+ CPRINTF("BLE data packet @%p: LLID %d,"
" nesn %d, sn %d, md %d, length %d\n",
ble_p, ble_p->header.data.llid, ble_p->header.data.nesn,
ble_p->header.data.sn, ble_p->header.data.md,
diff --git a/common/body_detection.c b/common/body_detection.c
index 4fbc88e852..848c4f08c1 100644
--- a/common/body_detection.c
+++ b/common/body_detection.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,8 +14,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_ACCEL, outstr)
-#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ##args)
static struct motion_sensor_t *body_sensor =
&motion_sensors[CONFIG_BODY_DETECTION_SENSOR];
@@ -31,10 +31,9 @@ static bool history_initialized;
static bool body_detect_enable;
STATIC_IF(CONFIG_ACCEL_SPOOF_MODE) bool spoof_enable;
-static struct body_detect_motion_data
-{
+static struct body_detect_motion_data {
int history[CONFIG_BODY_DETECTION_MAX_WINDOW_SIZE]; /* acceleration */
- int sum; /* sum(history) */
+ int sum; /* sum(history) */
uint64_t n2_variance; /* n^2 * var(history) */
} data[2]; /* motion data for X-axis and Y-axis */
@@ -59,8 +58,8 @@ static void update_motion_data(struct body_detect_motion_data *x, int x_n)
const int sum_diff = x_n - x_0;
const int new_sum = x->sum + sum_diff;
- x->n2_variance += sum_diff *
- ((int64_t)n * (x_n + x_0) - new_sum - x->sum);
+ x->n2_variance +=
+ sum_diff * ((int64_t)n * (x_n + x_0) - new_sum - x->sum);
x->sum = new_sum;
x->history[history_idx] = x_n;
}
@@ -76,8 +75,8 @@ static void update_motion_variance(void)
/* return Var(X) + Var(Y) */
static uint64_t get_motion_variance(void)
{
- return (data[X].n2_variance + data[Y].n2_variance)
- / window_size / window_size;
+ return (data[X].n2_variance + data[Y].n2_variance) / window_size /
+ window_size;
}
static int calculate_motion_confidence(uint64_t var)
@@ -87,7 +86,7 @@ static int calculate_motion_confidence(uint64_t var)
if (var > var_threshold_scaled + confidence_delta_scaled)
return 100;
return 100 * (var - var_threshold_scaled + confidence_delta_scaled) /
- (2 * confidence_delta_scaled);
+ (2 * confidence_delta_scaled);
}
/* Change the motion state and commit the change to AP. */
@@ -105,7 +104,7 @@ void body_detect_change_state(enum body_detect_states state, bool spoof)
.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID,
};
motion_sense_fifo_stage_data(&vector, NULL, 0,
- __hw_clock_source_read());
+ __hw_clock_source_read());
motion_sense_fifo_commit_data();
}
/* change the motion state */
@@ -160,15 +159,15 @@ static void determine_threshold_scale(int range, int resolution, int rms_noise)
* CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR / 100.
*/
const int var_noise = POW2((uint64_t)rms_noise) *
- CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR * POW2(98)
- / 100 / POW2(10000);
+ CONFIG_BODY_DETECTION_VAR_NOISE_FACTOR *
+ POW2(98) / 100 / POW2(10000);
- var_threshold_scaled = (uint64_t)
- (CONFIG_BODY_DETECTION_VAR_THRESHOLD + var_noise) *
- multiplier / divisor;
- confidence_delta_scaled = (uint64_t)
- CONFIG_BODY_DETECTION_CONFIDENCE_DELTA *
+ var_threshold_scaled =
+ (uint64_t)(CONFIG_BODY_DETECTION_VAR_THRESHOLD + var_noise) *
multiplier / divisor;
+ confidence_delta_scaled =
+ (uint64_t)CONFIG_BODY_DETECTION_CONFIDENCE_DELTA * multiplier /
+ divisor;
}
void body_detect_reset(void)
@@ -185,8 +184,8 @@ void body_detect_reset(void)
if (odr == 0)
return;
determine_window_size(odr);
- determine_threshold_scale(body_sensor->current_range,
- resolution, rms_noise);
+ determine_threshold_scale(body_sensor->current_range, resolution,
+ rms_noise);
/* initialize motion data and state */
memset(data, 0, sizeof(data));
history_idx = 0;
diff --git a/common/btle_hci_controller.c b/common/btle_hci_controller.c
index cc5b872b19..a4dcadaccf 100644
--- a/common/btle_hci_controller.c
+++ b/common/btle_hci_controller.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,8 +11,8 @@
#ifdef CONFIG_BLUETOOTH_HCI_DEBUG
#define CPUTS(outstr) cputs(CC_BLUETOOTH_HCI, outstr)
-#define CPRINTS(format, args...) cprints(CC_BLUETOOTH_HCI, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_BLUETOOTH_HCI, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_BLUETOOTH_HCI, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_BLUETOOTH_HCI, format, ##args)
#else /* CONFIG_BLUETOOTH_HCI_DEBUG */
@@ -27,7 +27,7 @@ static uint64_t hci_le_event_mask;
#define MAX_MESSAGE 24
-#define STATUS (return_params[0])
+#define STATUS (return_params[0])
#define RPARAMS (&(return_params[1]))
void hci_cmd(uint8_t *hciCmdbuf)
@@ -56,215 +56,184 @@ void hci_cmd(uint8_t *hciCmdbuf)
}
switch (hdr->opcode) {
- case CMD_MAKE_OPCODE(HCI_OGF_Controller_and_Baseband,
- HCI_CMD_Reset):
+ case CMD_MAKE_OPCODE(HCI_OGF_Controller_and_Baseband, HCI_CMD_Reset):
STATUS = ll_reset();
- break;
+ break;
case CMD_MAKE_OPCODE(HCI_OGF_Controller_and_Baseband,
- HCI_CMD_Set_Event_Mask):
+ HCI_CMD_Set_Event_Mask):
if (hdr->paramLen != sizeof(hci_event_mask))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = HCI_SUCCESS;
memcpy(&hci_event_mask, params, sizeof(hci_event_mask));
- break;
+ break;
case CMD_MAKE_OPCODE(HCI_OGF_Controller_and_Baseband,
- HCI_CMD_Read_Transmit_Power_Level):
- case CMD_MAKE_OPCODE(HCI_OGF_Informational,
- HCI_CMD_Read_Local_Supported_Features):
+ HCI_CMD_Read_Transmit_Power_Level):
case CMD_MAKE_OPCODE(HCI_OGF_Informational,
- HCI_CMD_Read_Local_Supported_Commands):
+ HCI_CMD_Read_Local_Supported_Features):
case CMD_MAKE_OPCODE(HCI_OGF_Informational,
- HCI_CMD_Read_Local_Version_Information):
+ HCI_CMD_Read_Local_Supported_Commands):
case CMD_MAKE_OPCODE(HCI_OGF_Informational,
- HCI_CMD_Read_BD_ADDR):
+ HCI_CMD_Read_Local_Version_Information):
+ case CMD_MAKE_OPCODE(HCI_OGF_Informational, HCI_CMD_Read_BD_ADDR):
case CMD_MAKE_OPCODE(HCI_OGF_Link_Control,
- HCI_CMD_Read_Remote_Version_Information):
- case CMD_MAKE_OPCODE(HCI_OGF_Status,
- HCI_CMD_Read_RSSI):
+ HCI_CMD_Read_Remote_Version_Information):
+ case CMD_MAKE_OPCODE(HCI_OGF_Status, HCI_CMD_Read_RSSI):
event = 0;
- break;
+ break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Event_Mask):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Event_Mask):
if (hdr->paramLen != sizeof(hci_le_event_mask))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = HCI_SUCCESS;
memcpy(&hci_le_event_mask, params, sizeof(hci_le_event_mask));
- break;
+ break;
/* LE Information */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Buffer_Size):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Read_Buffer_Size):
if (hdr->paramLen != 0)
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_read_buffer_size(RPARAMS);
rparam_count = sizeof(struct hciCmplLeReadBufferSize);
- break;
+ break;
case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Local_Supported_Features):
+ HCI_CMD_LE_Read_Local_Supported_Features):
if (hdr->paramLen != 0)
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_read_local_supported_features(RPARAMS);
rparam_count =
sizeof(struct hciCmplLeReadLocalSupportedFeatures);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Supported_States):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Read_Supported_States):
if (hdr->paramLen != 0)
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_read_supported_states(RPARAMS);
rparam_count = sizeof(struct hciCmplLeReadSupportedStates);
- break;
+ break;
case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Host_Channel_Classification):
+ HCI_CMD_LE_Set_Host_Channel_Classification):
if (hdr->paramLen !=
sizeof(struct hciLeSetHostChannelClassification))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_set_host_channel_classification(params);
- break;
+ break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Random_Address):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Random_Address):
if (hdr->paramLen != sizeof(struct hciLeSetRandomAddress))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_set_random_address(params);
- break;
+ break;
/* Advertising */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Advertise_Enable):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Advertise_Enable):
STATUS = ll_set_advertising_enable(params);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Advertising_Data):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Advertising_Data):
STATUS = ll_set_adv_data(params);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Adv_Params):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Adv_Params):
if (hdr->paramLen != sizeof(struct hciLeSetAdvParams))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_set_advertising_params(params);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Adv_Channel_TX_Power):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Read_Adv_Channel_TX_Power):
STATUS = ll_read_tx_power();
rparam_count = sizeof(struct hciCmplLeReadAdvChannelTxPower);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Scan_Response_Data):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Scan_Response_Data):
STATUS = ll_set_scan_response_data(params);
- break;
+ break;
/* Connections */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Remote_Used_Features):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Read_Remote_Used_Features):
if (hdr->paramLen != sizeof(struct hciLeReadRemoteUsedFeatures))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_read_remote_used_features(params);
event = HCI_EVT_Command_Status;
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_Link_Control,
- HCI_CMD_Disconnect):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Connection_Update):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Create_Connection):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Create_Connection_Cancel):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Channel_Map):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_Link_Control, HCI_CMD_Disconnect):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Connection_Update):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Create_Connection):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Create_Connection_Cancel):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Read_Channel_Map):
event = 0;
- break;
+ break;
/* Encryption */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Encrypt):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_LTK_Request_Reply):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_LTK_Request_Negative_Reply):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Rand):
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Start_Encryption):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Encrypt):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_LTK_Request_Reply):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_LTK_Request_Negative_Reply):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Rand):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Start_Encryption):
event = 0;
- break;
+ break;
/* Scanning */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Scan_Enable):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Scan_Enable):
if (hdr->paramLen != sizeof(struct hciLeSetScanEnable))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_set_scan_enable(params);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Scan_Parameters):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Scan_Parameters):
if (hdr->paramLen != sizeof(struct hciLeSetScanParams))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_set_scan_params(params);
- break;
+ break;
/* Allow List */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Clear_Allow_List):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Clear_Allow_List):
if (hdr->paramLen != 0)
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_clear_allow_list();
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Read_Allow_List_Size):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Read_Allow_List_Size):
if (hdr->paramLen != 0)
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_read_allow_list_size(RPARAMS);
rparam_count = sizeof(struct hciCmplLeReadAllowListSize);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Add_Device_To_Allow_List):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Add_Device_To_Allow_List):
if (hdr->paramLen != sizeof(struct hciLeAddDeviceToAllowList))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_add_device_to_allow_list(params);
- break;
+ break;
case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Remove_Device_From_Allow_List):
+ HCI_CMD_LE_Remove_Device_From_Allow_List):
if (hdr->paramLen !=
- sizeof(struct hciLeRemoveDeviceFromAllowList))
+ sizeof(struct hciLeRemoveDeviceFromAllowList))
STATUS = HCI_ERR_Invalid_HCI_Command_Parameters;
else
STATUS = ll_remove_device_from_allow_list(params);
- break;
+ break;
/* RFPHY Testing Support */
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Receiver_Test):
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Receiver_Test):
STATUS = ll_receiver_test(params);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Transmitter_Test):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Transmitter_Test):
STATUS = ll_transmitter_test(params);
- break;
- case CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Test_End):
+ break;
+ case CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Test_End):
STATUS = ll_test_end(RPARAMS);
rparam_count = sizeof(struct hciCmplLeTestEnd);
- break;
+ break;
default:
STATUS = HCI_ERR_Unknown_HCI_Command;
- break;
+ break;
}
hci_event(event, rparam_count, return_params);
@@ -275,12 +244,11 @@ void hci_acl_to_host(uint8_t *data, uint16_t hdr, uint16_t len)
int i;
/* Enqueue hdr, len, len bytes of data */
- CPRINTF("Sending %d bytes of data from handle %d with PB=%x.\n",
- len, hdr & ACL_HDR_MASK_CONN_ID,
- hdr & ACL_HDR_MASK_PB);
- for (i = 0; i < len; i++)
- CPRINTF("0x%x, ", data[i]);
- CPRINTF("\n");
+ CPRINTF("Sending %d bytes of data from handle %d with PB=%x.\n", len,
+ hdr & ACL_HDR_MASK_CONN_ID, hdr & ACL_HDR_MASK_PB);
+ for (i = 0; i < len; i++)
+ CPRINTF("0x%x, ", data[i]);
+ CPRINTF("\n");
}
void hci_acl_from_host(uint8_t *hciAclbuf)
@@ -290,12 +258,11 @@ void hci_acl_from_host(uint8_t *hciAclbuf)
int i;
/* Send the data to the link layer */
- CPRINTF("Sending %d bytes of data to handle %d with PB=%x.\n",
- hdr->len, hdr->hdr & ACL_HDR_MASK_CONN_ID,
- hdr->hdr & ACL_HDR_MASK_PB);
- for (i = 0; i < hdr->len; i++)
- CPRINTF("0x%x, ", data[i]);
- CPRINTF("\n");
+ CPRINTF("Sending %d bytes of data to handle %d with PB=%x.\n", hdr->len,
+ hdr->hdr & ACL_HDR_MASK_CONN_ID, hdr->hdr & ACL_HDR_MASK_PB);
+ for (i = 0; i < hdr->len; i++)
+ CPRINTF("0x%x, ", data[i]);
+ CPRINTF("\n");
}
/*
@@ -335,52 +302,50 @@ void hci_event(uint8_t event_code, uint8_t len, uint8_t *params)
* hcitool lcmd 0x2008 18 0x42410906 0x03454443 0x203c119 0x3030501 0x1812
* hcitool cmd 8 8 6 9 41 42 43 44 45 3 19 c1 3 2 1 5 3 3 12 18
*/
-uint8_t adv0[19] = {0x07, 0x09, 'A', 'B', 'C', 'D', 'E', 'F', /* Name */
- 0x03, 0x19, 0xc1, 0x03, /* Keyboard */
- 0x02, 0x01, 0x05, /* Flags */
- 0x03, 0x03, 0x12, 0x18}; /* UUID */
+uint8_t adv0[19] = { 0x07, 0x09, 'A', 'B', 'C', 'D', 'E', 'F', /* Name */
+ 0x03, 0x19, 0xc1, 0x03, /* Keyboard */
+ 0x02, 0x01, 0x05, /* Flags */
+ 0x03, 0x03, 0x12, 0x18 }; /* UUID */
-uint8_t adv1[18] = {0x06, 0x09, 'A', 'B', 'C', 'D', 'E', /* Name */
- 0x02, 0x01, 0x05, /* Flags */
- 0x03, 0x19, 0xc1, 0x03, /* Keyboard */
- 0x03, 0x03, 0x12, 0x18}; /* UUID */
+uint8_t adv1[18] = { 0x06, 0x09, 'A', 'B', 'C', 'D', 'E', /* Name */
+ 0x02, 0x01, 0x05, /* Flags */
+ 0x03, 0x19, 0xc1, 0x03, /* Keyboard */
+ 0x03, 0x03, 0x12, 0x18 }; /* UUID */
-uint8_t *adverts[] = {adv0, adv1};
-uint8_t adv_lengths[] = {sizeof(adv0), sizeof(adv1)};
+uint8_t *adverts[] = { adv0, adv1 };
+uint8_t adv_lengths[] = { sizeof(adv0), sizeof(adv1) };
-uint8_t scan0[4] = {0x03, 0x08, 'A', 'B'}; /* Short Name */
+uint8_t scan0[4] = { 0x03, 0x08, 'A', 'B' }; /* Short Name */
-uint8_t scan1[] = {}; /* Empty */
+uint8_t scan1[] = {}; /* Empty */
-uint8_t *scans[] = {scan0, scan1};
-uint8_t scan_lengths[] = {sizeof(scan0), sizeof(scan1)};
+uint8_t *scans[] = { scan0, scan1 };
+uint8_t scan_lengths[] = { sizeof(scan0), sizeof(scan1) };
/*
* LE_Set_Adv_Params
* hcitool lcmd 0x2006 15 0x010000f0 0xb0010100 0xb4b3b2b1 0x0007c5
* hcitool cmd 8 6 f0 0 0 1 0 1 1 b0 b1 b2 b3 b4 c5 7 0
*/
-uint8_t adv_param0[15] = {
- 0xf0, 0x00, /* IntervalMin */
- 0x00, 0x01, /* IntervalMax */
- 0x00, /* Adv Type */
- 0x01, /* Use Random Addr */
- 0x01, /* Direct Random */
- 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc5, /* Direct Addr */
- 0x07, /* Channel Map */
- 0x00}; /* Filter Policy */
-
-uint8_t adv_param1[15] = {
- 0xf0, 0x00, /* IntervalMin */
- 0x00, 0x01, /* IntervalMax */
- 0x02, /* Adv Type */
- 0x01, /* Use Random Addr */
- 0x01, /* Direct Random */
- 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc5, /* Direct Addr */
- 0x07, /* Channel Map */
- 0x00}; /* Filter Policy */
-
-uint8_t *adv_params[] = {adv_param0, adv_param1};
+uint8_t adv_param0[15] = { 0xf0, 0x00, /* IntervalMin */
+ 0x00, 0x01, /* IntervalMax */
+ 0x00, /* Adv Type */
+ 0x01, /* Use Random Addr */
+ 0x01, /* Direct Random */
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc5, /* Direct Addr */
+ 0x07, /* Channel Map */
+ 0x00 }; /* Filter Policy */
+
+uint8_t adv_param1[15] = { 0xf0, 0x00, /* IntervalMin */
+ 0x00, 0x01, /* IntervalMax */
+ 0x02, /* Adv Type */
+ 0x01, /* Use Random Addr */
+ 0x01, /* Direct Random */
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc5, /* Direct Addr */
+ 0x07, /* Channel Map */
+ 0x00 }; /* Filter Policy */
+
+uint8_t *adv_params[] = { adv_param0, adv_param1 };
/*
* LE Information
@@ -466,7 +431,7 @@ static uint8_t hci_buf[200];
#define MAX_BLE_HCI_PARAMS 8
static uint32_t param[MAX_BLE_HCI_PARAMS];
-static int command_ble_hci_cmd(int argc, char **argv)
+static int command_ble_hci_cmd(int argc, const char **argv)
{
static struct hciCmdHdr header;
int length, opcode, i;
@@ -489,7 +454,7 @@ static int command_ble_hci_cmd(int argc, char **argv)
}
for (i = 3; i < argc; i++) {
- param[i-3] = strtoi(argv[i], &e, 0);
+ param[i - 3] = strtoi(argv[i], &e, 0);
if (*e)
return EC_ERROR_PARAM3 + i;
}
@@ -498,12 +463,11 @@ static int command_ble_hci_cmd(int argc, char **argv)
header.paramLen = length;
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
- memcpy(hci_buf + sizeof(struct hciCmdHdr),
- param, length);
+ memcpy(hci_buf + sizeof(struct hciCmdHdr), param, length);
hci_cmd(hci_buf);
- CPRINTS("hci cmd @%pP", hci_buf);
+ CPRINTS("hci cmd @%p", hci_buf);
return EC_SUCCESS;
}
@@ -511,7 +475,7 @@ DECLARE_CONSOLE_COMMAND(ble_hci_cmd, command_ble_hci_cmd,
"opcode len uint32 uint32 uint32... (little endian)",
"Send an hci command of length len");
-static int command_hcitool(int argc, char **argv)
+static int command_hcitool(int argc, const char **argv)
{
static struct hciCmdHdr header;
int i, ogf, ocf;
@@ -521,7 +485,7 @@ static int command_hcitool(int argc, char **argv)
return EC_ERROR_PARAM_COUNT;
if (argv[1][0] == 'l') /* strcmp lcmd */
- return command_ble_hci_cmd(argc-1, &argv[1]);
+ return command_ble_hci_cmd(argc - 1, &argv[1]);
ogf = strtoi(argv[2], &e, 16);
if (*e)
@@ -532,7 +496,7 @@ static int command_hcitool(int argc, char **argv)
return EC_ERROR_PARAM3;
header.opcode = CMD_MAKE_OPCODE(ogf, ocf);
- header.paramLen = argc-4;
+ header.paramLen = argc - 4;
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
for (i = 4; i < argc; i++) {
@@ -543,15 +507,16 @@ static int command_hcitool(int argc, char **argv)
hci_cmd(hci_buf);
- CPRINTS("hci cmd @%pP", hci_buf);
+ CPRINTS("hci cmd @%p", hci_buf);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(hcitool, command_hcitool,
- "cmd ogf ocf b0 b1 b2 b3... or lcmd opcode len uint32.. (little endian)",
- "Send an hci command of length len");
+DECLARE_CONSOLE_COMMAND(
+ hcitool, command_hcitool,
+ "cmd ogf ocf b0 b1 b2 b3... or lcmd opcode len uint32.. (little endian)",
+ "Send an hci command of length len");
-static int command_ble_hci_acl(int argc, char **argv)
+static int command_ble_hci_acl(int argc, const char **argv)
{
static struct hciAclHdr header;
int length, hdr, i;
@@ -574,7 +539,7 @@ static int command_ble_hci_acl(int argc, char **argv)
}
for (i = 3; i < argc; i++) {
- param[i-3] = strtoi(argv[i], &e, 0);
+ param[i - 3] = strtoi(argv[i], &e, 0);
if (*e)
return EC_ERROR_PARAM3 + i;
}
@@ -583,12 +548,11 @@ static int command_ble_hci_acl(int argc, char **argv)
header.len = length;
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
- memcpy(hci_buf + sizeof(struct hciCmdHdr),
- param, length);
+ memcpy(hci_buf + sizeof(struct hciCmdHdr), param, length);
hci_cmd(hci_buf);
- CPRINTS("hci acl @%pP", hci_buf);
+ CPRINTS("hci acl @%p", hci_buf);
return EC_SUCCESS;
}
@@ -596,7 +560,7 @@ DECLARE_CONSOLE_COMMAND(ble_hci_acl, command_ble_hci_acl,
"hdr len uint32 uint32 uint32... (little endian)",
"Send hci acl data of length len");
-static int command_ble_hci_adv(int argc, char **argv)
+static int command_ble_hci_adv(int argc, const char **argv)
{
static struct hciCmdHdr header;
int adv, p = 0, scan_rsp = 0;
@@ -625,33 +589,33 @@ static int command_ble_hci_adv(int argc, char **argv)
header.paramLen = sizeof(struct hciLeSetAdvParams);
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
- memcpy(hci_buf + sizeof(struct hciCmdHdr),
- adv_params[p], header.paramLen);
+ memcpy(hci_buf + sizeof(struct hciCmdHdr), adv_params[p],
+ header.paramLen);
hci_cmd(hci_buf);
- header.opcode = CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Advertising_Data);
+ header.opcode =
+ CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Advertising_Data);
header.paramLen = adv_lengths[adv];
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
- memcpy(hci_buf + sizeof(struct hciCmdHdr),
- adverts[adv], header.paramLen);
+ memcpy(hci_buf + sizeof(struct hciCmdHdr), adverts[adv],
+ header.paramLen);
hci_cmd(hci_buf);
- header.opcode = CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Scan_Response_Data);
+ header.opcode =
+ CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Scan_Response_Data);
header.paramLen = scan_lengths[scan_rsp];
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
- memcpy(hci_buf + sizeof(struct hciCmdHdr),
- scans[scan_rsp], header.paramLen);
+ memcpy(hci_buf + sizeof(struct hciCmdHdr), scans[scan_rsp],
+ header.paramLen);
hci_cmd(hci_buf);
- header.opcode = CMD_MAKE_OPCODE(HCI_OGF_LE,
- HCI_CMD_LE_Set_Advertise_Enable);
+ header.opcode =
+ CMD_MAKE_OPCODE(HCI_OGF_LE, HCI_CMD_LE_Set_Advertise_Enable);
header.paramLen = sizeof(struct hciLeSetAdvEnable);
memcpy(hci_buf, &header, sizeof(struct hciCmdHdr));
diff --git a/common/btle_ll.c b/common/btle_ll.c
index d57eb3bfd3..71ca108565 100644
--- a/common/btle_ll.c
+++ b/common/btle_ll.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,8 +16,8 @@
#ifdef CONFIG_BLUETOOTH_LL_DEBUG
#define CPUTS(outstr) cputs(CC_BLUETOOTH_LL, outstr)
-#define CPRINTS(format, args...) cprints(CC_BLUETOOTH_LL, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_BLUETOOTH_LL, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_BLUETOOTH_LL, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_BLUETOOTH_LL, format, ##args)
#else /* CONFIG_BLUETOOTH_LL_DEBUG */
@@ -57,7 +57,7 @@ uint8_t is_first_data_packet;
static uint64_t ll_random_address = 0xC5BADBADBAD1; /* Uninitialized */
static uint64_t ll_public_address = 0xC5BADBADBADF; /* Uninitialized */
-static uint8_t ll_channel_map[5] = {0xff, 0xff, 0xff, 0xff, 0x1f};
+static uint8_t ll_channel_map[5] = { 0xff, 0xff, 0xff, 0xff, 0x1f };
static uint8_t ll_filter_duplicates;
@@ -161,8 +161,8 @@ static uint8_t ll_state_change_request(enum ll_state_t next_state)
{
/* Initialize the radio if it hasn't been initialized */
if (ll_state == UNINITIALIZED) {
- if (ble_radio_init(BLE_ADV_ACCESS_ADDRESS, BLE_ADV_CRCINIT)
- != EC_SUCCESS)
+ if (ble_radio_init(BLE_ADV_ACCESS_ADDRESS, BLE_ADV_CRCINIT) !=
+ EC_SUCCESS)
return HCI_ERR_Hardware_Failure;
ll_state = STANDBY;
}
@@ -236,50 +236,50 @@ uint8_t initialize_connection(void)
num_consecutive_failures = 0;
/* Copy data into the appropriate portions of memory */
- memcpy((uint8_t *)&(conn_params.init_a),
- payload_start, CONNECT_REQ_INITA_LEN);
+ memcpy((uint8_t *)&(conn_params.init_a), payload_start,
+ CONNECT_REQ_INITA_LEN);
cur_offset += CONNECT_REQ_INITA_LEN;
- memcpy((uint8_t *)&(conn_params.adv_a),
- payload_start+cur_offset, CONNECT_REQ_ADVA_LEN);
+ memcpy((uint8_t *)&(conn_params.adv_a), payload_start + cur_offset,
+ CONNECT_REQ_ADVA_LEN);
cur_offset += CONNECT_REQ_ADVA_LEN;
- memcpy(&(conn_params.access_addr),
- payload_start+cur_offset, CONNECT_REQ_ACCESS_ADDR_LEN);
+ memcpy(&(conn_params.access_addr), payload_start + cur_offset,
+ CONNECT_REQ_ACCESS_ADDR_LEN);
cur_offset += CONNECT_REQ_ACCESS_ADDR_LEN;
conn_params.crc_init_val = 0;
- memcpy(&(conn_params.crc_init_val),
- payload_start+cur_offset, CONNECT_REQ_CRC_INIT_VAL_LEN);
+ memcpy(&(conn_params.crc_init_val), payload_start + cur_offset,
+ CONNECT_REQ_CRC_INIT_VAL_LEN);
cur_offset += CONNECT_REQ_CRC_INIT_VAL_LEN;
- memcpy(&(conn_params.win_size),
- payload_start+cur_offset, CONNECT_REQ_WIN_SIZE_LEN);
+ memcpy(&(conn_params.win_size), payload_start + cur_offset,
+ CONNECT_REQ_WIN_SIZE_LEN);
cur_offset += CONNECT_REQ_WIN_SIZE_LEN;
- memcpy(&(conn_params.win_offset),
- payload_start+cur_offset, CONNECT_REQ_WIN_OFFSET_LEN);
+ memcpy(&(conn_params.win_offset), payload_start + cur_offset,
+ CONNECT_REQ_WIN_OFFSET_LEN);
cur_offset += CONNECT_REQ_WIN_OFFSET_LEN;
- memcpy(&(conn_params.interval),
- payload_start+cur_offset, CONNECT_REQ_INTERVAL_LEN);
+ memcpy(&(conn_params.interval), payload_start + cur_offset,
+ CONNECT_REQ_INTERVAL_LEN);
cur_offset += CONNECT_REQ_INTERVAL_LEN;
- memcpy(&(conn_params.latency),
- payload_start+cur_offset, CONNECT_REQ_LATENCY_LEN);
+ memcpy(&(conn_params.latency), payload_start + cur_offset,
+ CONNECT_REQ_LATENCY_LEN);
cur_offset += CONNECT_REQ_LATENCY_LEN;
- memcpy(&(conn_params.timeout),
- payload_start+cur_offset, CONNECT_REQ_TIMEOUT_LEN);
+ memcpy(&(conn_params.timeout), payload_start + cur_offset,
+ CONNECT_REQ_TIMEOUT_LEN);
cur_offset += CONNECT_REQ_TIMEOUT_LEN;
conn_params.channel_map = 0;
- memcpy(&(conn_params.channel_map),
- payload_start+cur_offset, CONNECT_REQ_CHANNEL_MAP_LEN);
+ memcpy(&(conn_params.channel_map), payload_start + cur_offset,
+ CONNECT_REQ_CHANNEL_MAP_LEN);
cur_offset += CONNECT_REQ_CHANNEL_MAP_LEN;
- memcpy(&final_octet, payload_start+cur_offset,
- CONNECT_REQ_HOP_INCREMENT_AND_SCA_LEN);
+ memcpy(&final_octet, payload_start + cur_offset,
+ CONNECT_REQ_HOP_INCREMENT_AND_SCA_LEN);
/* last 5 bits of final_octet: */
conn_params.hop_increment = final_octet & 0x1f;
@@ -288,9 +288,9 @@ uint8_t initialize_connection(void)
/* Set up channel mapping table */
for (i = 0; i < 5; ++i)
- remap_arr[i] = *(((uint8_t *)&(conn_params.channel_map))+i);
+ remap_arr[i] = *(((uint8_t *)&(conn_params.channel_map)) + i);
fill_remapping_table(&remap_table, remap_arr,
- conn_params.hop_increment);
+ conn_params.hop_increment);
/* Calculate transmission window parameters */
conn_params.transmitWindowSize = conn_params.win_size * 1250;
@@ -332,7 +332,7 @@ uint8_t ll_read_allow_list_size(uint8_t *return_params)
uint8_t ll_add_device_to_allow_list(uint8_t *params)
{
if (ble_radio_add_device_to_allow_list(&params[1], params[0]) ==
- EC_SUCCESS)
+ EC_SUCCESS)
return HCI_SUCCESS;
else
return HCI_ERR_Host_Rejected_Due_To_Limited_Resources;
@@ -341,7 +341,7 @@ uint8_t ll_add_device_to_allow_list(uint8_t *params)
uint8_t ll_remove_device_from_allow_list(uint8_t *params)
{
if (ble_radio_remove_device_from_allow_list(&params[1], params[0]) ==
- EC_SUCCESS)
+ EC_SUCCESS)
return HCI_SUCCESS;
else
return HCI_ERR_Hardware_Failure;
@@ -449,27 +449,28 @@ uint8_t ll_set_advertising_params(uint8_t *params)
case BLE_ADV_HEADER_PDU_TYPE_ADV_NONCONN_IND:
case BLE_ADV_HEADER_PDU_TYPE_ADV_SCAN_IND:
if (ll_adv_params.advIntervalMin <
- (100000 / LL_ADV_INTERVAL_UNIT_US)) /* 100ms */
+ (100000 / LL_ADV_INTERVAL_UNIT_US)) /* 100ms */
return HCI_ERR_Invalid_HCI_Command_Parameters;
/* Fall through */
case BLE_ADV_HEADER_PDU_TYPE_ADV_IND:
if (ll_adv_params.advIntervalMin > ll_adv_params.advIntervalMax)
return HCI_ERR_Invalid_HCI_Command_Parameters;
if (ll_adv_params.advIntervalMin <
- (20000 / LL_ADV_INTERVAL_UNIT_US) || /* 20ms */
+ (20000 / LL_ADV_INTERVAL_UNIT_US) || /* 20ms */
ll_adv_params.advIntervalMax >
- (10240000 / LL_ADV_INTERVAL_UNIT_US)) /* 10.24s */
+ (10240000 / LL_ADV_INTERVAL_UNIT_US)) /* 10.24s */
return HCI_ERR_Invalid_HCI_Command_Parameters;
ll_adv_interval_us = (((ll_adv_params.advIntervalMin +
- ll_adv_params.advIntervalMax) / 2) *
- LL_ADV_INTERVAL_UNIT_US);
+ ll_adv_params.advIntervalMax) /
+ 2) *
+ LL_ADV_INTERVAL_UNIT_US);
/* Don't time out */
ll_adv_timeout_us = -1;
- break;
+ break;
case BLE_ADV_HEADER_PDU_TYPE_ADV_DIRECT_IND:
ll_adv_interval_us = LL_ADV_DIRECT_INTERVAL_US;
ll_adv_timeout_us = LL_ADV_DIRECT_TIMEOUT_US;
- break;
+ break;
default:
return HCI_ERR_Invalid_HCI_Command_Parameters;
}
@@ -563,25 +564,25 @@ int ble_ll_adv(int chan)
case BLE_ADV_HEADER_PDU_TYPE_SCAN_REQ:
/* Scan requests are only allowed for ADV_IND and SCAN_IND */
if ((ll_adv_pdu.header.adv.type !=
- BLE_ADV_HEADER_PDU_TYPE_ADV_IND &&
+ BLE_ADV_HEADER_PDU_TYPE_ADV_IND &&
ll_adv_pdu.header.adv.type !=
- BLE_ADV_HEADER_PDU_TYPE_ADV_SCAN_IND) ||
- /* The advertising address needs to match */
+ BLE_ADV_HEADER_PDU_TYPE_ADV_SCAN_IND) ||
+ /* The advertising address needs to match */
(memcmp(&ll_rcv_packet.payload[BLUETOOTH_ADDR_OCTETS],
&ll_adv_pdu.payload[0], BLUETOOTH_ADDR_OCTETS))) {
/* Don't send the scan response */
radio_disable();
return rv;
}
- break;
+ break;
case BLE_ADV_HEADER_PDU_TYPE_CONNECT_REQ:
/* Don't send a scan response */
radio_disable();
/* Connecting is only allowed for ADV_IND and ADV_DIRECT_IND */
if (ll_adv_pdu.header.adv.type !=
- BLE_ADV_HEADER_PDU_TYPE_ADV_IND &&
+ BLE_ADV_HEADER_PDU_TYPE_ADV_IND &&
ll_adv_pdu.header.adv.type !=
- BLE_ADV_HEADER_PDU_TYPE_ADV_DIRECT_IND)
+ BLE_ADV_HEADER_PDU_TYPE_ADV_DIRECT_IND)
return rv;
/* The advertising address needs to match */
if (memcmp(&ll_rcv_packet.payload[BLUETOOTH_ADDR_OCTETS],
@@ -589,9 +590,9 @@ int ble_ll_adv(int chan)
return rv;
/* The InitAddr address needs to match for ADV_DIRECT_IND */
if (ll_adv_pdu.header.adv.type ==
- BLE_ADV_HEADER_PDU_TYPE_ADV_DIRECT_IND &&
- memcmp(&ll_adv_pdu.payload[BLUETOOTH_ADDR_OCTETS],
- &ll_rcv_packet.payload[0], BLUETOOTH_ADDR_OCTETS))
+ BLE_ADV_HEADER_PDU_TYPE_ADV_DIRECT_IND &&
+ memcmp(&ll_adv_pdu.payload[BLUETOOTH_ADDR_OCTETS],
+ &ll_rcv_packet.payload[0], BLUETOOTH_ADDR_OCTETS))
return rv;
/* Mark time that connect was received */
@@ -604,11 +605,11 @@ int ble_ll_adv(int chan)
ll_state = CONNECTION;
return rv;
- break;
+ break;
default: /* Unhandled response packet */
radio_disable();
return rv;
- break;
+ break;
}
CPRINTF("ADV %u Response %u %u\n", tx_end, rsp_end, tx_rsp_end);
@@ -632,7 +633,6 @@ int ble_ll_adv_event(void)
return rv;
}
-
void print_connection_state(void)
{
CPRINTF("vvvvvvvvvvvvvvvvvvvCONNECTION STATEvvvvvvvvvvvvvvvvvvv\n");
@@ -663,12 +663,12 @@ int connected_communicate(void)
if (num_consecutive_failures > 0) {
ble_radio_init(conn_params.access_addr,
- conn_params.crc_init_val);
+ conn_params.crc_init_val);
NRF51_RADIO_FREQUENCY =
NRF51_RADIO_FREQUENCY_VAL(chan2freq(comm_channel));
NRF51_RADIO_DATAWHITEIV = comm_channel;
- listen_time = last_receive_time + conn_params.connInterval
- - get_time().val + conn_params.transmitWindowSize;
+ listen_time = last_receive_time + conn_params.connInterval -
+ get_time().val + conn_params.transmitWindowSize;
/*
* This listens for 1.25 times the expected amount
@@ -680,12 +680,12 @@ int connected_communicate(void)
* slightly longer than expected in the case that
* there was a timing disagreement.
*/
- rv = ble_rx(&ll_rcv_packet,
- listen_time + (listen_time >> 2), 0);
+ rv = ble_rx(&ll_rcv_packet, listen_time + (listen_time >> 2),
+ 0);
} else {
if (!is_first_data_packet) {
- sleep_time = receive_time +
- conn_params.connInterval - get_time().val;
+ sleep_time = receive_time + conn_params.connInterval -
+ get_time().val;
/*
* The time slept is 31/32 (96.875%) of the calculated
* required sleep time because the code to receive
@@ -695,8 +695,8 @@ int connected_communicate(void)
} else {
last_receive_time = time_of_connect_req;
sleep_time = TRANSMIT_WINDOW_OFFSET_CONSTANT +
- conn_params.transmitWindowOffset +
- time_of_connect_req - get_time().val;
+ conn_params.transmitWindowOffset +
+ time_of_connect_req - get_time().val;
if (sleep_time >= 0) {
/*
* Radio is on for longer than needed for first
@@ -709,7 +709,7 @@ int connected_communicate(void)
}
ble_radio_init(conn_params.access_addr,
- conn_params.crc_init_val);
+ conn_params.crc_init_val);
NRF51_RADIO_FREQUENCY =
NRF51_RADIO_FREQUENCY_VAL(chan2freq(comm_channel));
NRF51_RADIO_DATAWHITEIV = comm_channel;
@@ -722,14 +722,13 @@ int connected_communicate(void)
* how early the window opens in microseconds.
*/
if (!is_first_data_packet)
- offset = last_receive_time + conn_params.connInterval
- - get_time().val;
+ offset = last_receive_time + conn_params.connInterval -
+ get_time().val;
else
offset = 0;
rv = ble_rx(&ll_rcv_packet,
- offset + conn_params.transmitWindowSize,
- 0);
+ offset + conn_params.transmitWindowSize, 0);
}
/*
@@ -766,9 +765,9 @@ void bluetooth_ll_task(void)
case ADVERTISING:
if (deadline.val == 0) {
- CPRINTS("ADV @%pP", &ll_adv_pdu);
+ CPRINTS("ADV @%p", &ll_adv_pdu);
deadline.val = get_time().val +
- (uint32_t)ll_adv_timeout_us;
+ (uint32_t)ll_adv_timeout_us;
ll_adv_events = 0;
}
@@ -786,7 +785,7 @@ void bluetooth_ll_task(void)
ll_state = STANDBY;
break;
}
- break;
+ break;
case STANDBY:
deadline.val = 0;
CPRINTS("Standby %d events", ll_adv_events);
@@ -795,20 +794,20 @@ void bluetooth_ll_task(void)
task_wait_event(-1);
connection_initialized = 0;
errors_recovered = 0;
- break;
+ break;
case TEST_RX:
if (ble_test_rx() == HCI_SUCCESS)
ll_test_packets++;
/* Packets come every 625us, sleep to save power */
usleep(300);
- break;
+ break;
case TEST_TX:
start = get_time().le.lo;
ble_test_tx();
ll_test_packets++;
end = get_time().le.lo;
- usleep(625 - 82 - (end-start)); /* 625us */
- break;
+ usleep(625 - 82 - (end - start)); /* 625us */
+ break;
case UNINITIALIZED:
ble_radio_init(BLE_ADV_ACCESS_ADDRESS, BLE_ADV_CRCINIT);
ll_adv_events = 0;
@@ -816,7 +815,7 @@ void bluetooth_ll_task(void)
connection_initialized = 0;
packet_tb_sent = &tx_packet_1;
set_empty_data_packet(&tx_packet_1);
- break;
+ break;
case CONNECTION:
if (!connection_initialized) {
if (initialize_connection() != HCI_SUCCESS) {
@@ -835,8 +834,7 @@ void bluetooth_ll_task(void)
} else {
num_consecutive_failures++;
if ((get_time().val - last_rx_time) >
- conn_params.connSupervisionTimeout) {
-
+ conn_params.connSupervisionTimeout) {
ll_state = STANDBY;
CPRINTF("EXITING CONNECTION STATE "
"DUE TO TIMEOUT.\n");
@@ -847,10 +845,11 @@ void bluetooth_ll_task(void)
if (ll_state == STANDBY) {
CPRINTF("Exiting connection state/Entering "
"Standby state after %d connections "
- "events\n", ll_conn_events);
+ "events\n",
+ ll_conn_events);
print_connection_state();
}
- break;
+ break;
default:
CPRINTS("Unhandled State ll_state = %d", ll_state);
ll_state = UNINITIALIZED;
diff --git a/common/build.mk b/common/build.mk
index 6473d53291..f784d57732 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -1,5 +1,5 @@
# -*- makefile -*-
-# Copyright 2014 The Chromium OS Authors. All rights reserved.
+# Copyright 2014 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
@@ -9,7 +9,7 @@
# Note that this variable includes the trailing "/"
_common_dir:=$(dir $(lastword $(MAKEFILE_LIST)))
-common-y=util.o util_stdlib.o
+common-y=util.o
common-y+=version.o printf.o queue.o queue_policies.o irq_locking.o
common-$(CONFIG_ACCELGYRO_BMI160)+=math_util.o
@@ -66,7 +66,10 @@ common-$(CONFIG_CHARGE_RAMP_SW)+=charge_ramp.o charge_ramp_sw.o
common-$(CONFIG_CHARGESPLASH)+=chargesplash.o
common-$(CONFIG_CHIP_INIT_ROM_REGION)+=init_rom.o
common-$(CONFIG_CMD_CHARGEN) += chargen.o
-common-$(CONFIG_CHARGER)+=charger.o charge_state_v2.o
+common-$(CONFIG_CHARGER)+=charger.o
+ifneq ($(CONFIG_CHARGER),)
+common-$(CONFIG_BATTERY)+=charge_state_v2.o
+endif
common-$(CONFIG_CHARGER_PROFILE_OVERRIDE_COMMON)+=charger_profile_override.o
common-$(CONFIG_CMD_I2CWEDGE)+=i2c_wedge.o
common-$(CONFIG_COMMON_GPIO)+=gpio.o gpio_commands.o
diff --git a/common/button.c b/common/button.c
index 145cd9db74..53745adaef 100644
--- a/common/button.c
+++ b/common/button.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -24,7 +24,7 @@
#include "watchdog.h"
/* Console output macro */
-#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ##args)
struct button_state_t {
uint64_t debounce_time;
@@ -75,12 +75,12 @@ static int raw_button_pressed(const struct button_config *button)
int simulated_value = 0;
if (!(button->flags & BUTTON_FLAG_DISABLED)) {
if (IS_ENABLED(CONFIG_ADC_BUTTONS) &&
- button_is_adc_detected(button->gpio)) {
- physical_value =
- adc_to_physical_value(button->gpio);
+ button_is_adc_detected(button->gpio)) {
+ physical_value = adc_to_physical_value(button->gpio);
} else {
- physical_value = (!!gpio_get_level(button->gpio) ==
- !!(button->flags & BUTTON_FLAG_ACTIVE_HIGH));
+ physical_value =
+ (!!gpio_get_level(button->gpio) ==
+ !!(button->flags & BUTTON_FLAG_ACTIVE_HIGH));
}
#ifdef CONFIG_SIMULATED_BUTTON
simulated_value = simulated_button_pressed(button);
@@ -193,7 +193,7 @@ static int is_recovery_boot(void)
if (system_jumped_to_this_image())
return 0;
if (!(system_get_reset_flags() &
- (EC_RESET_FLAG_RESET_PIN | EC_RESET_FLAG_POWER_ON)))
+ (EC_RESET_FLAG_RESET_PIN | EC_RESET_FLAG_POWER_ON)))
return 0;
if (!is_recovery_button_pressed())
return 0;
@@ -202,7 +202,7 @@ static int is_recovery_boot(void)
#endif /* CONFIG_BUTTON_TRIGGERED_RECOVERY */
static void button_reset(enum button button_type,
- const struct button_config *button)
+ const struct button_config *button)
{
state[button_type].debounced_pressed = raw_button_pressed(button);
state[button_type].debounce_time = 0;
@@ -260,7 +260,6 @@ int button_disable_gpio(enum button button_type)
}
#endif
-
/*
* Handle debounced button changing state.
*/
@@ -308,15 +307,14 @@ static void button_change_deferred(void)
hook_call_deferred(
&debug_mode_handle_data, 0);
#endif
- CPRINTS("Button '%s' was %s",
- buttons[i].name, new_pressed ?
- "pressed" : "released");
+ CPRINTS("Button '%s' was %s", buttons[i].name,
+ new_pressed ? "pressed" : "released");
if (IS_ENABLED(CONFIG_MKBP_INPUT_DEVICES)) {
mkbp_button_update(buttons[i].type,
- new_pressed);
+ new_pressed);
} else if (IS_ENABLED(HAS_TASK_KEYPROTO)) {
keyboard_update_button(buttons[i].type,
- new_pressed);
+ new_pressed);
}
}
@@ -327,10 +325,11 @@ static void button_change_deferred(void)
* Make sure the next deferred call happens on or before
* each button needs it.
*/
- soonest_debounce_time = (soonest_debounce_time == 0) ?
- state[i].debounce_time :
- MIN(soonest_debounce_time,
- state[i].debounce_time);
+ soonest_debounce_time =
+ (soonest_debounce_time == 0) ?
+ state[i].debounce_time :
+ MIN(soonest_debounce_time,
+ state[i].debounce_time);
}
}
@@ -418,12 +417,12 @@ static void simulate_button(uint32_t button_mask, int press_ms)
/* Defer the button release for specified duration */
hook_call_deferred(&simulate_button_release_deferred_data,
- press_ms * MSEC);
+ press_ms * MSEC);
}
#endif /* #ifdef CONFIG_SIMULATED_BUTTON */
#ifdef CONFIG_CMD_BUTTON
-static int console_command_button(int argc, char **argv)
+static int console_command_button(int argc, const char **argv)
{
int press_ms = 50;
char *e;
@@ -465,8 +464,7 @@ static int console_command_button(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(button, console_command_button,
- "vup|vdown|rec msec",
+DECLARE_CONSOLE_COMMAND(button, console_command_button, "vup|vdown|rec msec",
"Simulate button press");
#endif /* CONFIG_CMD_BUTTON */
@@ -494,7 +492,6 @@ DECLARE_HOST_COMMAND(EC_CMD_BUTTON, host_command_button, EC_VER_MASK(0));
#endif /* CONFIG_HOSTCMD_BUTTON */
-
#ifdef CONFIG_EMULATED_SYSRQ
#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON
@@ -546,10 +543,10 @@ enum debug_state {
STATE_WARM_RESET_EXEC,
};
-#define DEBUG_BTN_POWER BIT(0)
-#define DEBUG_BTN_VOL_UP BIT(1)
-#define DEBUG_BTN_VOL_DN BIT(2)
-#define DEBUG_TIMEOUT (10 * SECOND)
+#define DEBUG_BTN_POWER BIT(0)
+#define DEBUG_BTN_VOL_UP BIT(1)
+#define DEBUG_BTN_VOL_DN BIT(2)
+#define DEBUG_TIMEOUT (10 * SECOND)
static enum debug_state curr_debug_state = STATE_DEBUG_NONE;
static enum debug_state next_debug_state = STATE_DEBUG_NONE;
@@ -721,8 +718,9 @@ static void debug_mode_handle(void)
* Schedule a deferred call in case timeout hasn't
* occurred yet.
*/
- hook_call_deferred(&debug_mode_handle_data,
- (debug_state_deadline.val - now.val));
+ hook_call_deferred(
+ &debug_mode_handle_data,
+ (debug_state_deadline.val - now.val));
}
break;
diff --git a/common/capsense.c b/common/capsense.c
index b2413ac61f..2c2bbd6db5 100644
--- a/common/capsense.c
+++ b/common/capsense.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,11 +9,12 @@
#include "hooks.h"
#include "i2c.h"
#include "keyboard_protocol.h"
+#include "printf.h"
#include "timer.h"
/* Console output macro */
-#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
#define CAPSENSE_I2C_ADDR 0x08
#define CAPSENSE_MASK_BITS 8
@@ -24,8 +25,7 @@ static int capsense_read_bitmask(void)
int rv;
uint8_t val = 0;
- rv = i2c_xfer(I2C_PORT_CAPSENSE, CAPSENSE_I2C_ADDR,
- 0, 0, &val, 1);
+ rv = i2c_xfer(I2C_PORT_CAPSENSE, CAPSENSE_I2C_ADDR, 0, 0, &val, 1);
if (rv)
CPRINTS("%s failed: error %d", __func__, rv);
@@ -49,11 +49,12 @@ static void capsense_change_deferred(void)
static uint8_t cur_val;
uint8_t new_val;
int i, n, c;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
new_val = capsense_read_bitmask();
if (new_val != cur_val) {
- CPRINTF("[%pT capsense 0x%02x: ",
- PRINTF_TIMESTAMP_NOW, new_val);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s capsense 0x%02x: ", ts_str, new_val);
for (i = 0; i < CAPSENSE_MASK_BITS; i++) {
/* See what changed */
n = (new_val >> i) & 0x01;
diff --git a/common/cbi.c b/common/cbi.c
index e18f15e5a9..26125c902e 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -31,8 +31,8 @@ uint8_t cbi_crc8(const struct cbi_header *h)
h->total_size - sizeof(h->magic) - sizeof(h->crc));
}
-uint8_t *cbi_set_data(uint8_t *p, enum cbi_data_tag tag,
- const void *buf, int size)
+uint8_t *cbi_set_data(uint8_t *p, enum cbi_data_tag tag, const void *buf,
+ int size)
{
struct cbi_data *d = (struct cbi_data *)p;
@@ -77,11 +77,11 @@ struct cbi_data *cbi_find_tag(const void *buf, enum cbi_data_tag tag)
*/
#ifndef HOST_TOOLS_BUILD
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ##args)
static int cache_status = CBI_CACHE_STATUS_INVALID;
static uint8_t cbi[CBI_IMAGE_SIZE];
-static struct cbi_header * const head = (struct cbi_header *)cbi;
+static struct cbi_header *const head = (struct cbi_header *)cbi;
int cbi_create(void)
{
@@ -133,21 +133,21 @@ static int do_cbi_read(void)
* buffer has practical limitation.
*/
if (head->total_size < sizeof(*head) ||
- head->total_size > CBI_IMAGE_SIZE) {
+ head->total_size > CBI_IMAGE_SIZE) {
CPRINTS("Bad size: %d", head->total_size);
return EC_ERROR_OVERFLOW;
}
/* Read the data */
if (cbi_config.drv->load(sizeof(*head), head->data,
- head->total_size - sizeof(*head))) {
+ head->total_size - sizeof(*head))) {
CPRINTS("Failed to read body");
return EC_ERROR_INVAL;
}
/* Check CRC. This supports new fields unknown to this parser. */
if (cbi_config.storage_type != CBI_STORAGE_TYPE_GPIO &&
- cbi_crc8(head) != head->crc) {
+ cbi_crc8(head) != head->crc) {
CPRINTS("Bad CRC");
return EC_ERROR_INVAL;
}
@@ -175,8 +175,8 @@ static int cbi_read(void)
return rv;
}
-__attribute__((weak))
-int cbi_board_override(enum cbi_data_tag tag, uint8_t *buf, uint8_t *size)
+__attribute__((weak)) int cbi_board_override(enum cbi_data_tag tag,
+ uint8_t *buf, uint8_t *size)
{
return EC_SUCCESS;
}
@@ -294,8 +294,7 @@ int cbi_get_ssfc(uint32_t *ssfc)
{
uint8_t size = sizeof(*ssfc);
- return cbi_get_board_info(CBI_TAG_SSFC, (uint8_t *)ssfc,
- &size);
+ return cbi_get_board_info(CBI_TAG_SSFC, (uint8_t *)ssfc, &size);
}
int cbi_get_pcb_supplier(uint32_t *pcb_supplier)
@@ -303,7 +302,7 @@ int cbi_get_pcb_supplier(uint32_t *pcb_supplier)
uint8_t size = sizeof(*pcb_supplier);
return cbi_get_board_info(CBI_TAG_PCB_SUPPLIER, (uint8_t *)pcb_supplier,
- &size);
+ &size);
}
int cbi_get_rework_id(uint64_t *id)
@@ -312,6 +311,14 @@ int cbi_get_rework_id(uint64_t *id)
return cbi_get_board_info(CBI_TAG_REWORK_ID, (uint8_t *)id, &size);
}
+int cbi_get_factory_calibration_data(uint32_t *calibration_data)
+{
+ uint8_t size = sizeof(*calibration_data);
+
+ return cbi_get_board_info(CBI_TAG_FACTORY_CALIBRATION_DATA,
+ (uint8_t *)calibration_data, &size);
+}
+
static enum ec_status hc_cbi_get(struct host_cmd_handler_args *args)
{
const struct __ec_align4 ec_params_get_cbi *p = args->params;
@@ -326,19 +333,16 @@ static enum ec_status hc_cbi_get(struct host_cmd_handler_args *args)
args->response_size = size;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_CROS_BOARD_INFO,
- hc_cbi_get,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_GET_CROS_BOARD_INFO, hc_cbi_get, EC_VER_MASK(0));
-static enum ec_status common_cbi_set(const struct __ec_align4
- ec_params_set_cbi * p)
+static enum ec_status
+common_cbi_set(const struct __ec_align4 ec_params_set_cbi *p)
{
/*
* If we ultimately cannot write to the flash, then fail early unless
* we are explicitly trying to write to the in-memory CBI only
*/
- if (cbi_config.drv->is_protected() &&
- !(p->flag & CBI_SET_NO_SYNC)) {
+ if (cbi_config.drv->is_protected() && !(p->flag & CBI_SET_NO_SYNC)) {
CPRINTS("Failed to write due to WP");
return EC_RES_ACCESS_DENIED;
}
@@ -386,7 +390,7 @@ static enum ec_status common_cbi_set(const struct __ec_align4
static enum ec_status hc_cbi_set(struct host_cmd_handler_args *args)
{
- const struct __ec_align4 ec_params_set_cbi * p = args->params;
+ const struct __ec_align4 ec_params_set_cbi *p = args->params;
/* Given data size exceeds the packet size. */
if (args->params_size < sizeof(*p) + p->size)
@@ -394,12 +398,10 @@ static enum ec_status hc_cbi_set(struct host_cmd_handler_args *args)
return common_cbi_set(p);
}
-DECLARE_HOST_COMMAND(EC_CMD_SET_CROS_BOARD_INFO,
- hc_cbi_set,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_SET_CROS_BOARD_INFO, hc_cbi_set, EC_VER_MASK(0));
#ifdef CONFIG_CMD_CBI
-static void print_tag(const char * const tag, int rv, const uint32_t *val)
+static void print_tag(const char *const tag, int rv, const uint32_t *val)
{
ccprintf("%s", tag);
if (rv == EC_SUCCESS && val)
@@ -408,7 +410,7 @@ static void print_tag(const char * const tag, int rv, const uint32_t *val)
ccprintf(": (Error %d)\n", rv);
}
-static void print_uint64_tag(const char * const tag, int rv,
+static void print_uint64_tag(const char *const tag, int rv,
const uint64_t *lval)
{
ccprintf("%s", tag);
@@ -429,7 +431,8 @@ static void dump_cbi(void)
cbi_read();
if (cbi_get_cache_status() != CBI_CACHE_STATUS_SYNCED) {
- ccprintf("Cannot Read CBI (Error %d)\n", cbi_get_cache_status());
+ ccprintf("Cannot Read CBI (Error %d)\n",
+ cbi_get_cache_status());
return;
}
@@ -450,12 +453,12 @@ static void dump_cbi(void)
* Space for the set command (does not include data space) plus maximum
* possible console input
*/
-static uint8_t buf[sizeof(struct ec_params_set_cbi) + \
- CONFIG_CONSOLE_INPUT_LINE_SIZE];
+static uint8_t
+ buf[sizeof(struct ec_params_set_cbi) + CONFIG_CONSOLE_INPUT_LINE_SIZE];
-static int cc_cbi(int argc, char **argv)
+static int cc_cbi(int argc, const char **argv)
{
- struct __ec_align4 ec_params_set_cbi * setter =
+ struct __ec_align4 ec_params_set_cbi *setter =
(struct __ec_align4 ec_params_set_cbi *)buf;
int last_arg;
char *e;
@@ -494,8 +497,9 @@ static int cc_cbi(int argc, char **argv)
if (setter->size < 1) {
ccprintf("Set size too small\n");
return EC_ERROR_PARAM4;
- } else if ((setter->size > 8) || (setter->size > 4 &&
- setter->tag != CBI_TAG_REWORK_ID)) {
+ } else if ((setter->size > 8) ||
+ (setter->size > 4 &&
+ setter->tag != CBI_TAG_REWORK_ID)) {
ccprintf("Set size too large\n");
return EC_ERROR_PARAM4;
}
@@ -542,7 +546,8 @@ static int cc_cbi(int argc, char **argv)
return EC_ERROR_UNKNOWN;
}
-DECLARE_CONSOLE_COMMAND(cbi, cc_cbi, "[set <tag> <value> <size> | "
+DECLARE_CONSOLE_COMMAND(cbi, cc_cbi,
+ "[set <tag> <value> <size> | "
"remove <tag>] [init | skip_write]",
"Print or change Cros Board Info from flash");
#endif /* CONFIG_CMD_CBI */
diff --git a/common/cbi_eeprom.c b/common/cbi_eeprom.c
index ef20fdc7e2..da7d85f21b 100644
--- a/common/cbi_eeprom.c
+++ b/common/cbi_eeprom.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.
*/
@@ -14,20 +14,20 @@
#include "util.h"
#include "write_protect.h"
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ##args)
/*
* We allow EEPROMs with page size of 8 or 16. Use 8 to be the most compatible.
* This causes a little more overhead for writes, but we are not writing to the
* EEPROM outside of the factory process.
*/
-#define EEPROM_PAGE_WRITE_SIZE 8
-#define EEPROM_PAGE_WRITE_MS 5
+#define EEPROM_PAGE_WRITE_SIZE 8
+#define EEPROM_PAGE_WRITE_MS 5
static int eeprom_read(uint8_t offset, uint8_t *data, int len)
{
- return i2c_read_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM_FLAGS,
- offset, data, len);
+ return i2c_read_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM_FLAGS, offset,
+ data, len);
}
static int eeprom_is_write_protected(void)
diff --git a/common/cbi_gpio.c b/common/cbi_gpio.c
index 7b9fb25ebb..09e1dd3a18 100644
--- a/common/cbi_gpio.c
+++ b/common/cbi_gpio.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.
*/
@@ -11,7 +11,7 @@
#include "system.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, "CBI " format, ##args)
static int cbi_gpio_read(uint8_t offset, uint8_t *data, int len)
{
@@ -39,8 +39,8 @@ static int cbi_gpio_read(uint8_t offset, uint8_t *data, int len)
}
sku_id = system_get_sku_id();
- rv = cbi_set_board_info(CBI_TAG_SKU_ID,
- (uint8_t *)&sku_id, sizeof(int));
+ rv = cbi_set_board_info(CBI_TAG_SKU_ID, (uint8_t *)&sku_id,
+ sizeof(int));
if (rv) {
CPRINTS("Failed (%d) to set SKU_ID tag", rv);
err++;
diff --git a/common/cec.c b/common/cec.c
index 1bc3273c1d..4b15fc1799 100644
--- a/common/cec.c
+++ b/common/cec.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,8 +7,8 @@
#include "console.h"
#include "task.h"
-#define CPRINTF(format, args...) cprintf(CC_CEC, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_CEC, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CEC, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_CEC, format, ##args)
/*
* Mutex for the read-offset of the rx queue. Needed since the
@@ -75,7 +75,7 @@ int cec_rx_queue_push(struct cec_rx_queue *queue, const uint8_t *msg,
queue->buf[offset] = 0;
offset = (offset + 1) % CEC_RX_BUFFER_SIZE;
- for (i = 0 ; i < msg_len; i++) {
+ for (i = 0; i < msg_len; i++) {
if (offset == queue->read_offset) {
/* Buffer full */
return EC_ERROR_OVERFLOW;
@@ -101,8 +101,7 @@ int cec_rx_queue_push(struct cec_rx_queue *queue, const uint8_t *msg,
return EC_SUCCESS;
}
-int cec_rx_queue_pop(struct cec_rx_queue *queue, uint8_t *msg,
- uint8_t *msg_len)
+int cec_rx_queue_pop(struct cec_rx_queue *queue, uint8_t *msg, uint8_t *msg_len)
{
int i;
@@ -126,9 +125,8 @@ int cec_rx_queue_pop(struct cec_rx_queue *queue, uint8_t *msg,
queue->read_offset = (queue->read_offset + 1) % CEC_RX_BUFFER_SIZE;
for (i = 0; i < *msg_len; i++) {
msg[i] = queue->buf[queue->read_offset];
- queue->read_offset = (queue->read_offset + 1) %
- CEC_RX_BUFFER_SIZE;
-
+ queue->read_offset =
+ (queue->read_offset + 1) % CEC_RX_BUFFER_SIZE;
}
mutex_unlock(&rx_queue_readoffset_mutex);
diff --git a/common/charge_manager.c b/common/charge_manager.c
index f8a08b7fa8..3e8b937e53 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
#include "adc.h"
#include "atomic.h"
#include "battery.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charge_ramp.h"
#include "charge_state_v2.h"
@@ -30,13 +31,13 @@
#error Mock defined HAS_MOCK_CHARGE_MANAGER
#endif
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
#define POWER(charge_port) ((charge_port.current) * (charge_port.voltage))
/* Timeout for delayed override power swap, allow for 500ms extra */
-#define POWER_SWAP_TIMEOUT (PD_T_SRC_RECOVER_MAX + PD_T_SRC_TURN_ON + \
- PD_T_SAFE_0V + 500 * MSEC)
+#define POWER_SWAP_TIMEOUT \
+ (PD_T_SRC_RECOVER_MAX + PD_T_SRC_TURN_ON + PD_T_SAFE_0V + 500 * MSEC)
/*
* Default charge supplier priority
@@ -70,15 +71,13 @@ __overridable const int supplier_priority[] = {
[CHARGE_SUPPLIER_OTHER] = 4,
[CHARGE_SUPPLIER_VBUS] = 4,
#endif
-#ifdef CONFIG_WIRELESS_CHARGER_P9221_R7
- [CHARGE_SUPPLIER_WPC_BPP] = 5,
- [CHARGE_SUPPLIER_WPC_EPP] = 5,
- [CHARGE_SUPPLIER_WPC_GPP] = 5,
-#endif
};
BUILD_ASSERT(ARRAY_SIZE(supplier_priority) == CHARGE_SUPPLIER_COUNT);
+const char *charge_supplier_name[] = { CHARGE_SUPPLIER_NAME };
+BUILD_ASSERT(ARRAY_SIZE(charge_supplier_name) == CHARGE_SUPPLIER_COUNT);
+
/* Keep track of available charge for each charge port. */
static struct charge_port_info available_charge[CHARGE_SUPPLIER_COUNT]
[CHARGE_PORT_COUNT];
@@ -150,7 +149,7 @@ enum charge_manager_change_type {
CHANGE_DUALROLE,
};
-static int is_pd_port(int port)
+int is_pd_port(int port)
{
return port >= 0 && port < board_get_usb_pd_port_count();
}
@@ -204,9 +203,8 @@ static int is_connected(int port)
*/
static int charge_manager_spoof_dualrole_capability(void)
{
- return (system_get_image_copy() == EC_IMAGE_RO &&
- system_is_locked()) || !left_safe_mode;
-
+ return (system_get_image_copy() == EC_IMAGE_RO && system_is_locked()) ||
+ !left_safe_mode;
}
#endif /* !CONFIG_CHARGE_MANAGER_DRP_CHARGING */
@@ -257,9 +255,9 @@ static int charge_manager_is_seeded(void)
if (!is_valid_port(j))
continue;
if (available_charge[i][j].current ==
- CHARGE_CURRENT_UNINITIALIZED ||
+ CHARGE_CURRENT_UNINITIALIZED ||
available_charge[i][j].voltage ==
- CHARGE_VOLTAGE_UNINITIALIZED)
+ CHARGE_VOLTAGE_UNINITIALIZED)
return 0;
}
}
@@ -340,8 +338,8 @@ static enum charge_supplier get_current_supplier(int port)
return supplier;
}
-static enum usb_power_roles get_current_power_role(int port,
- enum charge_supplier supplier)
+static enum usb_power_roles
+get_current_power_role(int port, enum charge_supplier supplier)
{
enum usb_power_roles role;
if (charge_port == port)
@@ -397,30 +395,38 @@ static int get_vbus_voltage(int port, enum usb_power_roles current_role)
int charge_manager_get_vbus_voltage(int port)
{
- return get_vbus_voltage(port, get_current_power_role(port,
- get_current_supplier(port)));
+ return get_vbus_voltage(
+ port, get_current_power_role(port, get_current_supplier(port)));
}
#ifdef CONFIG_CMD_VBUS
-static int command_vbus(int argc, char **argv)
+static int command_vbus(int argc, const char **argv)
{
/* port = -1 to print all the ports */
int port = -1;
+ int vbus, vsys;
if (argc == 2)
port = atoi(argv[1]);
- for (int i = 0; i < board_get_usb_pd_port_count(); i++) {
- if (port < 0 || i == port)
- ccprintf("VBUS C%d = %d mV\n", i,
- charge_manager_get_vbus_voltage(i));
+ ccprintf(" VBUS VSYS\n");
+ for (int i = 0; i < CHARGE_PORT_COUNT; i++) {
+ if (port < 0 || i == port) {
+ vbus = charge_manager_get_vbus_voltage(i);
+ if (charger_get_vsys_voltage(i, &vsys))
+ vsys = -1;
+ ccprintf(" P%d %6dmV ", i, vbus);
+ if (vsys >= 0)
+ ccprintf("%6dmV\n", vsys);
+ else
+ ccprintf("(unknown)\n");
+ }
}
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(vbus, command_vbus,
- "[port]",
- "VBUS of the given port");
+DECLARE_CONSOLE_COMMAND(vbus, command_vbus, "[port]",
+ "Print VBUS & VSYS of the given port");
#endif
/**
@@ -429,8 +435,9 @@ DECLARE_CONSOLE_COMMAND(vbus, command_vbus,
* @param port Charge port.
* @param r USB PD power info to be updated.
*/
-static void charge_manager_fill_power_info(int port,
- struct ec_response_usb_pd_power_info *r)
+static void
+charge_manager_fill_power_info(int port,
+ struct ec_response_usb_pd_power_info *r)
{
enum charge_supplier sup = get_current_supplier(port);
@@ -461,6 +468,8 @@ static void charge_manager_fill_power_info(int port,
}
} else {
int use_ramp_current;
+ uint32_t max_mv, max_ma, pdo, unused;
+
switch (sup) {
case CHARGE_SUPPLIER_PD:
r->type = USB_CHG_TYPE_PD;
@@ -486,30 +495,32 @@ static void charge_manager_fill_power_info(int port,
r->type = USB_CHG_TYPE_VBUS;
break;
#endif
-#ifdef CONFIG_WIRELESS_CHARGER_P9221_R7
- /*
- * Todo:need kernel add wpc device node in power_supply
- * before that use USB_CHG_TYPE_PROPRIETARY to present WPC.
- */
- case CHARGE_SUPPLIER_WPC_BPP:
- case CHARGE_SUPPLIER_WPC_EPP:
- case CHARGE_SUPPLIER_WPC_GPP:
- r->type = USB_CHG_TYPE_PROPRIETARY;
- break;
-#endif
#if CONFIG_DEDICATED_CHARGE_PORT_COUNT > 0
case CHARGE_SUPPLIER_DEDICATED:
r->type = USB_CHG_TYPE_DEDICATED;
break;
#endif
default:
-#ifdef CONFIG_WIRELESS_CHARGER_P9221_R7
- r->type = USB_CHG_TYPE_VBUS;
-#else
r->type = USB_CHG_TYPE_OTHER;
-#endif
}
- r->meas.voltage_max = available_charge[sup][port].voltage;
+
+ if (IS_ENABLED(CONFIG_USB_PD_DPS) && dps_is_enabled() &&
+ sup == CHARGE_SUPPLIER_PD) {
+ /*
+ * Returns the maximum power the system can request when
+ * DPS enabled. This is to prevent the system think it's
+ * using a low power charger.
+ */
+ pd_find_pdo_index(pd_get_src_cap_cnt(port),
+ pd_get_src_caps(port),
+ pd_get_max_voltage(), &pdo);
+ pd_extract_pdo_power(pdo, &max_ma, &max_mv, &unused);
+ } else {
+ max_mv = available_charge[sup][port].voltage;
+ max_ma = available_charge[sup][port].current;
+ }
+
+ r->meas.voltage_max = max_mv;
/*
* Report unknown charger CHARGE_DETECT_DELAY after supplier
@@ -523,15 +534,15 @@ static void charge_manager_fill_power_info(int port,
* lose power again).
*/
#ifdef CONFIG_BATTERY
- if (get_time().val < registration_time[port].val +
- CHARGE_DETECT_DELAY)
+ if (get_time().val <
+ registration_time[port].val + CHARGE_DETECT_DELAY)
r->type = USB_CHG_TYPE_UNKNOWN;
#endif
#if defined(HAS_TASK_CHG_RAMP) || defined(CONFIG_CHARGE_RAMP_HW)
/* Read ramped current if active charging port */
- use_ramp_current =
- (charge_port == port) && chg_ramp_allowed(port, sup);
+ use_ramp_current = (charge_port == port) &&
+ chg_ramp_allowed(port, sup);
#else
use_ramp_current = 0;
#endif
@@ -548,17 +559,15 @@ static void charge_manager_fill_power_info(int port,
* If ramp is not allowed, max current is just the
* available charge current.
*/
- r->meas.current_max = chg_ramp_is_stable() ?
- r->meas.current_lim : chg_ramp_max(port, sup,
- available_charge[sup][port].current);
+ r->meas.current_max =
+ chg_ramp_is_stable() ?
+ r->meas.current_lim :
+ chg_ramp_max(port, sup, max_ma);
- r->max_power =
- r->meas.current_max * r->meas.voltage_max;
} else {
- r->meas.current_max = r->meas.current_lim =
- available_charge[sup][port].current;
- r->max_power = POWER(available_charge[sup][port]);
+ r->meas.current_max = r->meas.current_lim = max_ma;
}
+ r->max_power = r->meas.current_max * r->meas.voltage_max;
r->meas.voltage_now = get_vbus_voltage(port, r->role);
}
@@ -588,8 +597,8 @@ void charge_manager_save_log(int port)
(pinfo.dualrole ? CHARGE_FLAGS_DUAL_ROLE : 0);
pd_log_event(PD_EVENT_MCU_CHARGE,
- PD_LOG_PORT_SIZE(port, sizeof(pinfo.meas)),
- flags, &pinfo.meas);
+ PD_LOG_PORT_SIZE(port, sizeof(pinfo.meas)), flags,
+ &pinfo.meas);
}
#endif /* CONFIG_USB_PD_LOGGING */
@@ -650,7 +659,6 @@ static void charge_manager_get_best_charge_port(int *new_port,
/* Skip port selection on OVERRIDE_DONT_CHARGE. */
if (override_port != OVERRIDE_DONT_CHARGE) {
-
/*
* Charge supplier selection logic:
* 1. Prefer DPS charge port.
@@ -680,8 +688,7 @@ static void charge_manager_get_best_charge_port(int *new_port,
* charge on another override port.
*/
if (override_port != OVERRIDE_OFF &&
- override_port == port &&
- override_port != j)
+ override_port == port && override_port != j)
continue;
#ifndef CONFIG_CHARGE_MANAGER_DRP_CHARGING
@@ -706,31 +713,36 @@ static void charge_manager_get_best_charge_port(int *new_port,
supplier = i;
port = j;
break;
- /* Select if no supplier chosen yet. */
+ /* Select if no supplier chosen yet. */
} else if (supplier == CHARGE_SUPPLIER_NONE ||
- /* ..or if supplier priority is higher. */
- supplier_priority[i] <
- supplier_priority[supplier] ||
- /* ..or if this is our override port. */
- (j == override_port &&
- port != override_port) ||
- /* ..or if priority is tied and.. */
- (supplier_priority[i] ==
- supplier_priority[supplier] &&
- /* candidate port can supply more power or.. */
- (candidate_port_power > best_port_power ||
- /*
- * candidate port is the active port and can
- * supply the same amount of power.
- */
- (candidate_port_power == best_port_power &&
- charge_port == j)))) {
+ /* ..or if supplier priority is
+ higher. */
+ supplier_priority[i] <
+ supplier_priority[supplier] ||
+ /* ..or if this is our override port.
+ */
+ (j == override_port &&
+ port != override_port) ||
+ /* ..or if priority is tied and.. */
+ (supplier_priority[i] ==
+ supplier_priority[supplier] &&
+ /* candidate port can supply more
+ power or.. */
+ (candidate_port_power >
+ best_port_power ||
+ /*
+ * candidate port is the active
+ * port and can supply the same
+ * amount of power.
+ */
+ (candidate_port_power ==
+ best_port_power &&
+ charge_port == j)))) {
supplier = i;
port = j;
best_port_power = candidate_port_power;
}
}
-
}
#ifdef CONFIG_BATTERY
@@ -738,8 +750,7 @@ static void charge_manager_get_best_charge_port(int *new_port,
* if no battery present then retain same charge port
* and charge supplier to avoid the port switching
*/
- if (charge_port != CHARGE_SUPPLIER_NONE &&
- charge_port != port &&
+ if (charge_port != CHARGE_SUPPLIER_NONE && charge_port != port &&
(battery_is_present() == BP_NO ||
(battery_is_present() == BP_YES &&
battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL))) {
@@ -782,9 +793,8 @@ static void charge_manager_refresh(void)
* the port, for example, if the port has become a charge
* source.
*/
- if (active_charge_port_initialized &&
- new_port == charge_port &&
- new_supplier == charge_supplier)
+ if (active_charge_port_initialized && new_port == charge_port &&
+ new_supplier == charge_supplier)
break;
/*
@@ -844,8 +854,8 @@ static void charge_manager_refresh(void)
/* Enforce port charge ceiling. */
ceil = charge_manager_get_ceil(new_port);
if (left_safe_mode && ceil != CHARGE_CEIL_NONE)
- new_charge_current = MIN(ceil,
- new_charge_current_uncapped);
+ new_charge_current =
+ MIN(ceil, new_charge_current_uncapped);
else
new_charge_current = new_charge_current_uncapped;
@@ -866,19 +876,19 @@ static void charge_manager_refresh(void)
if (new_port != charge_port || new_charge_current != charge_current ||
new_supplier != charge_supplier) {
#ifdef HAS_TASK_CHG_RAMP
- chg_ramp_charge_supplier_change(
- new_port, new_supplier, new_charge_current,
- registration_time[new_port],
- new_charge_voltage);
+ chg_ramp_charge_supplier_change(new_port, new_supplier,
+ new_charge_current,
+ registration_time[new_port],
+ new_charge_voltage);
#else
#ifdef CONFIG_CHARGE_RAMP_HW
/* Enable or disable charge ramp */
charger_set_hw_ramp(chg_ramp_allowed(new_port, new_supplier));
#endif
board_set_charge_limit(new_port, new_supplier,
- new_charge_current,
- new_charge_current_uncapped,
- new_charge_voltage);
+ new_charge_current,
+ new_charge_current_uncapped,
+ new_charge_voltage);
#endif /* HAS_TASK_CHG_RAMP */
power_changed = 1;
@@ -946,9 +956,9 @@ static void charge_manager_refresh(void)
if (is_pd_port(updated_new_port)) {
/* Check if we can get requested voltage/current */
if ((IS_ENABLED(CONFIG_USB_PD_TCPMV1) &&
- IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE)) ||
+ IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE)) ||
(IS_ENABLED(CONFIG_USB_PD_TCPMV2) &&
- IS_ENABLED(CONFIG_USB_PE_SM))) {
+ IS_ENABLED(CONFIG_USB_PE_SM))) {
uint32_t pdo;
uint32_t max_voltage;
uint32_t max_current;
@@ -959,9 +969,9 @@ static void charge_manager_refresh(void)
* than requested. If yes, send new power request
*/
if (pd_get_requested_voltage(updated_new_port) !=
- charge_voltage ||
+ charge_voltage ||
pd_get_requested_current(updated_new_port) !=
- charge_current_uncapped)
+ charge_current_uncapped)
new_req = true;
if (IS_ENABLED(CONFIG_USB_PD_DPS) && dps_is_enabled()) {
@@ -996,9 +1006,11 @@ static void charge_manager_refresh(void)
if (is_pd_port(updated_old_port))
pd_set_new_power_request(updated_old_port);
- if (power_changed)
+ if (power_changed) {
+ hook_notify(HOOK_POWER_SUPPLY_CHANGE);
/* notify host of power info change */
pd_send_host_event(PD_EVENT_POWER_CHANGE);
+ }
}
DECLARE_DEFERRED(charge_manager_refresh);
@@ -1031,8 +1043,7 @@ DECLARE_DEFERRED(charger_detect_debounced);
* @param charge Charge port current / voltage.
*/
static void charge_manager_make_change(enum charge_manager_change_type change,
- int supplier,
- int port,
+ int supplier, int port,
const struct charge_port_info *charge)
{
int i;
@@ -1048,9 +1059,8 @@ static void charge_manager_make_change(enum charge_manager_change_type change,
case CHANGE_CHARGE:
/* Ignore changes where charge is identical */
if (available_charge[supplier][port].current ==
- charge->current &&
- available_charge[supplier][port].voltage ==
- charge->voltage)
+ charge->current &&
+ available_charge[supplier][port].voltage == charge->voltage)
return;
if (charge->current > 0 &&
available_charge[supplier][port].current == 0)
@@ -1084,12 +1094,13 @@ static void charge_manager_make_change(enum charge_manager_change_type change,
}
/* Remove override when a charger is plugged */
- if (clear_override && override_port != port
+ if (clear_override &&
+ override_port != port
#ifndef CONFIG_CHARGE_MANAGER_DRP_CHARGING
/* only remove override when it's a dedicated charger */
&& dualrole_capability[port] == CAP_DEDICATED
#endif
- ) {
+ ) {
override_port = OVERRIDE_OFF;
if (delayed_override_port != OVERRIDE_OFF) {
delayed_override_port = OVERRIDE_OFF;
@@ -1117,7 +1128,7 @@ static void charge_manager_make_change(enum charge_manager_change_type change,
/*
* If we have a charge on our delayed override port within
* the deadline, make it our override port.
- */
+ */
if (port == delayed_override_port && charge->current > 0 &&
is_sink(delayed_override_port) &&
get_time().val < delayed_override_deadline.val) {
@@ -1202,11 +1213,10 @@ void typec_set_input_current_limit(int port, typec_current_t max_ma,
NULL);
}
-void charge_manager_update_charge(int supplier,
- int port,
+void charge_manager_update_charge(int supplier, int port,
const struct charge_port_info *charge)
{
- struct charge_port_info zero = {0};
+ struct charge_port_info zero = { 0 };
if (!charge)
charge = &zero;
charge_manager_make_change(CHANGE_CHARGE, supplier, port, charge);
@@ -1230,6 +1240,21 @@ void charge_manager_leave_safe_mode(void)
if (left_safe_mode)
return;
+ /*
+ * Sometimes the fuel gauge will report that it has
+ * sufficient state of charge and remaining capacity,
+ * but in actuality it doesn't. When the EC sees that
+ * information, it trusts it and leaves charge manager
+ * safe mode. Doing so will allow CHARGE_PORT_NONE to
+ * be selected, thereby cutting off the input FETs.
+ * When the battery cannot provide the charge it claims,
+ * the system loses power, shuts down, and the battery
+ * is not charged even though the charger is plugged in.
+ * By waiting 500ms, we can avoid the selection of
+ * CHARGE_PORT_NONE around init time and not cut off the
+ * input FETs.
+ */
+ msleep(500);
CPRINTS("%s()", __func__);
cflush();
left_safe_mode = 1;
@@ -1288,8 +1313,8 @@ int charge_manager_set_override(int port)
if (override_port != port) {
override_port = port;
if (charge_manager_is_seeded())
- hook_call_deferred(
- &charge_manager_refresh_data, 0);
+ hook_call_deferred(&charge_manager_refresh_data,
+ 0);
}
}
/*
@@ -1297,13 +1322,13 @@ int charge_manager_set_override(int port)
* power swap and set the delayed override for swap completion.
*/
else if (!is_sink(port) && dualrole_capability[port] == CAP_DUALROLE) {
- delayed_override_deadline.val = get_time().val +
- POWER_SWAP_TIMEOUT;
+ delayed_override_deadline.val =
+ get_time().val + POWER_SWAP_TIMEOUT;
delayed_override_port = port;
hook_call_deferred(&charge_override_timeout_data,
POWER_SWAP_TIMEOUT);
pd_request_power_swap(port);
- /* Can't charge from requested port -- return error. */
+ /* Can't charge from requested port -- return error. */
} else
retval = EC_ERROR_INVAL;
@@ -1361,7 +1386,7 @@ int charge_manager_get_power_limit_uw(void)
/* Bitmap of ports used as power source */
static volatile uint32_t source_port_bitmap;
-BUILD_ASSERT(sizeof(source_port_bitmap)*8 >= CONFIG_USB_PD_PORT_MAX_COUNT);
+BUILD_ASSERT(sizeof(source_port_bitmap) * 8 >= CONFIG_USB_PD_PORT_MAX_COUNT);
static inline int has_other_active_source(int port)
{
@@ -1392,7 +1417,7 @@ static int can_supply_max_current(int port)
if (p == port)
continue;
if (source_port_rp[p] ==
- CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
+ CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
return 0;
}
return 1;
@@ -1418,8 +1443,8 @@ void charge_manager_source_port(int port, int enable)
/* Set port limit according to policy */
for (p = 0; p < board_get_usb_pd_port_count(); p++) {
rp = can_supply_max_current(p) ?
- CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT :
- CONFIG_USB_PD_PULLUP;
+ CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT :
+ CONFIG_USB_PD_PULLUP;
source_port_rp[p] = rp;
#ifdef CONFIG_USB_PD_LOGGING
@@ -1471,8 +1496,7 @@ static enum ec_status hc_pd_power_info(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_POWER_INFO,
- hc_pd_power_info,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_POWER_INFO, hc_pd_power_info,
EC_VER_MASK(0));
static enum ec_status hc_charge_port_count(struct host_cmd_handler_args *args)
@@ -1484,8 +1508,7 @@ static enum ec_status hc_charge_port_count(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_CHARGE_PORT_COUNT,
- hc_charge_port_count,
+DECLARE_HOST_COMMAND(EC_CMD_CHARGE_PORT_COUNT, hc_charge_port_count,
EC_VER_MASK(0));
static enum ec_status
@@ -1499,15 +1522,15 @@ hc_charge_port_override(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
return charge_manager_set_override(override_port) == EC_SUCCESS ?
- EC_RES_SUCCESS : EC_RES_ERROR;
+ EC_RES_SUCCESS :
+ EC_RES_ERROR;
}
-DECLARE_HOST_COMMAND(EC_CMD_PD_CHARGE_PORT_OVERRIDE,
- hc_charge_port_override,
+DECLARE_HOST_COMMAND(EC_CMD_PD_CHARGE_PORT_OVERRIDE, hc_charge_port_override,
EC_VER_MASK(0));
#if CONFIG_DEDICATED_CHARGE_PORT_COUNT > 0
-static enum ec_status hc_override_dedicated_charger_limit(
- struct host_cmd_handler_args *args)
+static enum ec_status
+hc_override_dedicated_charger_limit(struct host_cmd_handler_args *args)
{
const struct ec_params_dedicated_charger_limit *p = args->params;
struct charge_port_info ci = {
@@ -1528,11 +1551,10 @@ static enum ec_status hc_override_dedicated_charger_limit(
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT,
- hc_override_dedicated_charger_limit,
- EC_VER_MASK(0));
+ hc_override_dedicated_charger_limit, EC_VER_MASK(0));
#endif
-static int command_charge_port_override(int argc, char **argv)
+static int command_charge_port_override(int argc, const char **argv)
{
int port = OVERRIDE_OFF;
int ret = EC_SUCCESS;
@@ -1546,12 +1568,12 @@ static int command_charge_port_override(int argc, char **argv)
ret = charge_manager_set_override(port);
}
- ccprintf("Override: %d\n", (argc >= 2 && ret == EC_SUCCESS) ?
- port : override_port);
+ ccprintf("Override: %d\n",
+ (argc >= 2 && ret == EC_SUCCESS) ? port : override_port);
return ret;
}
-DECLARE_CONSOLE_COMMAND(chgoverride, command_charge_port_override,
- "[port | -1 | -2]",
+DECLARE_CONSOLE_COMMAND(
+ chgoverride, command_charge_port_override, "[port | -1 | -2]",
"Force charging from a given port (-1 = off, -2 = disable charging)");
#ifdef CONFIG_CHARGE_MANAGER_EXTERNAL_POWER_LIMIT
@@ -1588,16 +1610,14 @@ hc_external_power_limit(struct host_cmd_handler_args *args)
{
const struct ec_params_external_power_limit_v1 *p = args->params;
- charge_manager_set_external_power_limit(p->current_lim,
- p->voltage_lim);
+ charge_manager_set_external_power_limit(p->current_lim, p->voltage_lim);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_EXTERNAL_POWER_LIMIT,
- hc_external_power_limit,
+DECLARE_HOST_COMMAND(EC_CMD_EXTERNAL_POWER_LIMIT, hc_external_power_limit,
EC_VER_MASK(1));
-static int command_external_power_limit(int argc, char **argv)
+static int command_external_power_limit(int argc, const char **argv)
{
int max_current;
int max_voltage;
@@ -1623,41 +1643,63 @@ static int command_external_power_limit(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(chglim, command_external_power_limit,
- "[max_current (mA)] [max_voltage (mV)]",
- "Set max charger current / voltage");
+ "[max_current (mA)] [max_voltage (mV)]",
+ "Set max charger current / voltage");
#endif /* CONFIG_CHARGE_MANAGER_EXTERNAL_POWER_LIMIT */
#ifdef CONFIG_CMD_CHARGE_SUPPLIER_INFO
-static int charge_supplier_info(int argc, char **argv)
+static int charge_supplier_info(int argc, const char **argv)
{
- ccprintf("port=%d, type=%d, cur=%dmA, vtg=%dmV, lsm=%d\n",
- charge_manager_get_active_charge_port(),
- charge_supplier,
- charge_current,
- charge_voltage,
- left_safe_mode);
-
+ int p, s;
+ int port_printed;
+
+ ccprintf("\n");
+ ccprintf("Port --Supplier-- Prio -Available Power-\n");
+ for (p = 0; p < CHARGE_PORT_COUNT; p++) {
+ port_printed = 0;
+ for (s = 0; s < CHARGE_SUPPLIER_COUNT; s++) {
+ if (available_charge[s][p].current == 0 &&
+ available_charge[s][p].voltage == 0)
+ continue;
+ if (charge_manager_get_active_charge_port() == p &&
+ charge_manager_get_supplier() == s)
+ ccprintf("*");
+ else
+ ccprintf(" ");
+ if (!port_printed) {
+ ccprintf("P%d ", p);
+ port_printed = 1;
+ } else {
+ ccprintf(" ");
+ }
+ ccprintf("%-10s %4d %5dmA %5dmV\n",
+ charge_supplier_name[s], supplier_priority[s],
+ available_charge[s][p].current,
+ available_charge[s][p].voltage);
+ }
+ }
+ ccprintf("\n");
+ ccprintf(" %s safe mode\n", left_safe_mode ? "Left" : "In");
+ ccprintf(" Override port = P%d\n", charge_manager_get_override());
+ ccprintf("\n");
return 0;
}
-DECLARE_CONSOLE_COMMAND(chgsup, charge_supplier_info,
- NULL, "print chg supplier info");
+DECLARE_CONSOLE_COMMAND(chgsup, charge_supplier_info, NULL,
+ "print chg supplier info");
#endif
-__overridable
-int board_charge_port_is_sink(int port)
+__overridable int board_charge_port_is_sink(int port)
{
return 1;
}
-__overridable
-int board_charge_port_is_connected(int port)
+__overridable int board_charge_port_is_connected(int port)
{
return 1;
}
-__overridable
-void board_fill_source_power_info(int port,
- struct ec_response_usb_pd_power_info *r)
+__overridable void
+board_fill_source_power_info(int port, struct ec_response_usb_pd_power_info *r)
{
r->meas.voltage_now = 0;
r->meas.voltage_max = 0;
diff --git a/common/charge_ramp.c b/common/charge_ramp.c
index 32e0d21ddb..2c84087e21 100644
--- a/common/charge_ramp.c
+++ b/common/charge_ramp.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -41,7 +41,7 @@ test_mockable int chg_ramp_allowed(int port, int supplier)
case CHARGE_SUPPLIER_PD:
case CHARGE_SUPPLIER_TYPEC:
return 0;
- /* default: fall through */
+ /* default: fall through */
}
/* Otherwise ask the BC1.2 detect module */
@@ -59,7 +59,7 @@ test_mockable int chg_ramp_max(int port, int supplier, int sup_curr)
* we may brownout the systems they are connected to.
*/
return sup_curr;
- /* default: fall through */
+ /* default: fall through */
}
/* Otherwise ask the BC1.2 detect module */
diff --git a/common/charge_ramp_sw.c b/common/charge_ramp_sw.c
index bfd6db057b..4c09a94a8d 100644
--- a/common/charge_ramp_sw.c
+++ b/common/charge_ramp_sw.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,30 +16,30 @@
#include "usb_pd.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
/* Number of times to ramp current searching for limit before stable charging */
-#define RAMP_COUNT 3
+#define RAMP_COUNT 3
/* Maximum allowable time charger can be unplugged to be considered an OCP */
#define OC_RECOVER_MAX_TIME (SECOND)
/* Delay for running state machine when board is not consuming full current */
-#define CURRENT_DRAW_DELAY (5*SECOND)
+#define CURRENT_DRAW_DELAY (5 * SECOND)
/* Current ramp increment */
-#define RAMP_CURR_INCR_MA 64
-#define RAMP_CURR_DELAY (500*MSEC)
-#define RAMP_CURR_START_MA 500
+#define RAMP_CURR_INCR_MA 64
+#define RAMP_CURR_DELAY (500 * MSEC)
+#define RAMP_CURR_START_MA 500
/* How much to backoff the input current limit when limit has been found */
-#define RAMP_ICL_BACKOFF (2*RAMP_CURR_INCR_MA)
+#define RAMP_ICL_BACKOFF (2 * RAMP_CURR_INCR_MA)
/* Interval at which VBUS voltage is monitored in stable state */
#define STABLE_VBUS_MONITOR_INTERVAL (SECOND)
/* Time to delay for stablizing the charging current */
-#define STABLIZE_DELAY (5*SECOND)
+#define STABLIZE_DELAY (5 * SECOND)
enum chg_ramp_state {
CHG_RAMP_DISCONNECTED,
@@ -78,14 +78,13 @@ static int max_icl;
static int min_icl;
void chg_ramp_charge_supplier_change(int port, int supplier, int current,
- timestamp_t registration_time, int voltage)
+ timestamp_t registration_time, int voltage)
{
/*
* If the last active port was a valid port and the port
* has changed, then this may have been an over-current.
*/
- if (active_port != CHARGE_PORT_NONE &&
- port != active_port) {
+ if (active_port != CHARGE_PORT_NONE && port != active_port) {
if (oc_info_idx[active_port] == RAMP_COUNT - 1)
oc_info_idx[active_port] = 0;
else
@@ -111,7 +110,8 @@ void chg_ramp_charge_supplier_change(int port, int supplier, int current,
reg_time = registration_time;
if (ramp_st != CHG_RAMP_STABILIZE) {
ramp_st = (active_port == CHARGE_PORT_NONE) ?
- CHG_RAMP_DISCONNECTED : CHG_RAMP_CHARGE_DETECT_DELAY;
+ CHG_RAMP_DISCONNECTED :
+ CHG_RAMP_CHARGE_DETECT_DELAY;
CPRINTS("Ramp reset: st%d", ramp_st);
task_wake(TASK_ID_CHG_RAMP);
}
@@ -153,7 +153,7 @@ void chg_ramp_task(void *u)
int last_active_port = CHARGE_PORT_NONE;
enum chg_ramp_state ramp_st_prev = CHG_RAMP_DISCONNECTED,
- ramp_st_new = CHG_RAMP_DISCONNECTED;
+ ramp_st_new = CHG_RAMP_DISCONNECTED;
int active_icl_new;
/* Clear last OCP supplier to guarantee we ramp on first connect */
@@ -190,15 +190,15 @@ void chg_ramp_task(void *u)
last_active_port = active_port;
if (reg_time.val <
ACTIVE_OC_INFO.ts.val +
- OC_RECOVER_MAX_TIME) {
+ OC_RECOVER_MAX_TIME) {
ACTIVE_OC_INFO.oc_detected = 1;
} else {
for (i = 0; i < RAMP_COUNT; ++i)
- oc_info[active_port][i].
- oc_detected = 0;
+ oc_info[active_port][i]
+ .oc_detected = 0;
}
- detect_end_time_us = get_time().val +
- CHARGE_DETECT_DELAY;
+ detect_end_time_us =
+ get_time().val + CHARGE_DETECT_DELAY;
task_wait_time = CHARGE_DETECT_DELAY;
break;
}
@@ -246,8 +246,8 @@ void chg_ramp_task(void *u)
if (i == RAMP_COUNT) {
/* Found OC threshold! */
- active_icl_new = ACTIVE_OC_INFO.icl -
- RAMP_ICL_BACKOFF;
+ active_icl_new =
+ ACTIVE_OC_INFO.icl - RAMP_ICL_BACKOFF;
ramp_st_new = CHG_RAMP_STABLE;
} else {
/*
@@ -272,8 +272,8 @@ void chg_ramp_task(void *u)
if (board_is_vbus_too_low(active_port,
CHG_RAMP_VBUS_RAMPING)) {
CPRINTS("VBUS low");
- active_icl_new = MAX(min_icl, active_icl -
- RAMP_ICL_BACKOFF);
+ active_icl_new = MAX(
+ min_icl, active_icl - RAMP_ICL_BACKOFF);
ramp_st_new = CHG_RAMP_STABILIZE;
task_wait_time = STABLIZE_DELAY;
stablize_port = active_port;
@@ -300,8 +300,8 @@ void chg_ramp_task(void *u)
}
ramp_st_new = active_port == CHARGE_PORT_NONE ?
- CHG_RAMP_DISCONNECTED :
- CHG_RAMP_CHARGE_DETECT_DELAY;
+ CHG_RAMP_DISCONNECTED :
+ CHG_RAMP_CHARGE_DETECT_DELAY;
break;
case CHG_RAMP_STABLE:
/* Maintain input current limit */
@@ -320,7 +320,7 @@ void chg_ramp_task(void *u)
CHG_RAMP_VBUS_STABLE)) {
CPRINTS("VBUS low; Re-ramp");
max_icl = MAX(min_icl,
- max_icl - RAMP_ICL_BACKOFF);
+ max_icl - RAMP_ICL_BACKOFF);
active_icl_new = min_icl;
ramp_st_new = CHG_RAMP_RAMP;
}
@@ -334,9 +334,9 @@ void chg_ramp_task(void *u)
/* Skip setting limit if status is stable twice in a row */
if (ramp_st_prev != CHG_RAMP_STABLE ||
- ramp_st != CHG_RAMP_STABLE) {
- CPRINTS("Ramp p%d st%d %dmA %dmA",
- active_port, ramp_st, min_icl, active_icl);
+ ramp_st != CHG_RAMP_STABLE) {
+ CPRINTS("Ramp p%d st%d %dmA %dmA", active_port, ramp_st,
+ min_icl, active_icl);
/* Set the input current limit */
lim = chg_ramp_get_current_limit();
board_set_charge_limit(active_port, active_sup, lim,
@@ -356,13 +356,13 @@ void chg_ramp_task(void *u)
}
#ifdef CONFIG_CMD_CHGRAMP
-static int command_chgramp(int argc, char **argv)
+static int command_chgramp(int argc, const char **argv)
{
int i;
int port;
- ccprintf("Chg Ramp:\nState: %d\nMin ICL: %d\nActive ICL: %d\n",
- ramp_st, min_icl, active_icl);
+ ccprintf("Chg Ramp:\nState: %d\nMin ICL: %d\nActive ICL: %d\n", ramp_st,
+ min_icl, active_icl);
for (port = 0; port < board_get_usb_pd_port_count(); port++) {
ccprintf("Port %d:\n", port);
@@ -377,7 +377,6 @@ static int command_chgramp(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(chgramp, command_chgramp,
- "",
- "Dump charge ramp state info");
+DECLARE_CONSOLE_COMMAND(chgramp, command_chgramp, "",
+ "Dump charge ramp state info");
#endif
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index f3dc811eef..728606ef8a 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -7,6 +7,7 @@
#include "battery.h"
#include "battery_smart.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charger_profile_override.h"
#include "charge_state.h"
@@ -35,8 +36,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
/* Extra debugging prints when allocating power between lid and base. */
#undef CHARGE_ALLOCATE_EXTRA_DEBUG
@@ -87,8 +88,8 @@ static int prev_ac, prev_charge, prev_full, prev_disp_charge;
static enum battery_present prev_bp;
static int is_full; /* battery not accepting current */
static enum ec_charge_control_mode chg_ctl_mode;
-static int manual_voltage; /* Manual voltage override (-1 = no override) */
-static int manual_current; /* Manual current override (-1 = no override) */
+static int manual_voltage; /* Manual voltage override (-1 = no override) */
+static int manual_current; /* Manual current override (-1 = no override) */
static unsigned int user_current_limit = -1U;
test_export_static timestamp_t shutdown_target_time;
static bool is_charging_progress_displayed;
@@ -155,18 +156,10 @@ static int battery_was_removed;
static int problems_exist;
static int debugging;
-
-static const char * const prob_text[] = {
- "static update",
- "set voltage",
- "set current",
- "set mode",
- "set input current",
- "post init",
- "chg params",
- "batt params",
- "custom profile",
- "cfg secondary chg"
+static const char *const prob_text[] = {
+ "static update", "set voltage", "set current", "set mode",
+ "set input current", "post init", "chg params", "batt params",
+ "custom profile", "cfg secondary chg"
};
BUILD_ASSERT(ARRAY_SIZE(prob_text) == NUM_PROBLEM_TYPES);
@@ -184,7 +177,7 @@ void charge_problem(enum problem_type p, int v)
t_now = get_time();
t_diff.val = t_now.val - last_prob_time[p].val;
CPRINTS("charge problem: %s, 0x%x -> 0x%x after %.6" PRId64 "s",
- prob_text[p], last_prob_val[p], v, t_diff.val);
+ prob_text[p], last_prob_val[p], v, t_diff.val);
last_prob_val[p] = v;
last_prob_time[p] = t_now;
}
@@ -304,11 +297,12 @@ static const struct dual_battery_policy db_policy = {
};
/* Add at most "value" to power_var, subtracting from total_power budget. */
-#define CHG_ALLOCATE(power_var, total_power, value) do { \
- int val_capped = MIN(value, total_power); \
- (power_var) += val_capped; \
- (total_power) -= val_capped; \
-} while (0)
+#define CHG_ALLOCATE(power_var, total_power, value) \
+ do { \
+ int val_capped = MIN(value, total_power); \
+ (power_var) += val_capped; \
+ (total_power) -= val_capped; \
+ } while (0)
/* Update base battery information */
static void update_base_battery_info(void)
@@ -346,9 +340,9 @@ static void update_base_battery_info(void)
/* Newly connected battery, or change in capacity. */
if (old_flags & EC_BATT_FLAG_INVALID_DATA ||
- ((old_flags & EC_BATT_FLAG_BATT_PRESENT) !=
- (bd->flags & EC_BATT_FLAG_BATT_PRESENT)) ||
- old_full_capacity != bd->full_capacity)
+ ((old_flags & EC_BATT_FLAG_BATT_PRESENT) !=
+ (bd->flags & EC_BATT_FLAG_BATT_PRESENT)) ||
+ old_full_capacity != bd->full_capacity)
host_set_single_event(EC_HOST_EVENT_BATTERY);
if (flags_changed)
@@ -359,8 +353,8 @@ static void update_base_battery_info(void)
BATT_FLAG_BAD_REMAINING_CAPACITY))
charge_base = -1;
else if (bd->full_capacity > 0)
- charge_base = 100 * bd->remaining_capacity
- / bd->full_capacity;
+ charge_base = 100 * bd->remaining_capacity /
+ bd->full_capacity;
else
charge_base = 0;
}
@@ -380,8 +374,8 @@ static int set_base_current(int current_base, int allow_charge_base)
const int otg_voltage = db_policy.otg_voltage;
int ret;
- ret = ec_ec_client_base_charge_control(current_base,
- otg_voltage, allow_charge_base);
+ ret = ec_ec_client_base_charge_control(current_base, otg_voltage,
+ allow_charge_base);
if (ret) {
/* Ignore errors until the base is responsive. */
if (base_responsive)
@@ -418,9 +412,9 @@ static void set_base_lid_current(int current_base, int allow_charge_base,
if (prev_current_base != current_base ||
prev_allow_charge_base != allow_charge_base ||
prev_current_lid != current_lid) {
- CPRINTS("Base/Lid: %d%s/%d%s mA",
- current_base, allow_charge_base ? "+" : "",
- current_lid, allow_charge_lid ? "+" : "");
+ CPRINTS("Base/Lid: %d%s/%d%s mA", current_base,
+ allow_charge_base ? "+" : "", current_lid,
+ allow_charge_lid ? "+" : "");
}
/*
@@ -452,12 +446,12 @@ static void set_base_lid_current(int current_base, int allow_charge_base,
return;
if (allow_charge_lid)
ret = charge_request(curr.requested_voltage,
- curr.requested_current);
+ curr.requested_current);
else
ret = charge_request(0, 0);
} else {
- ret = charge_set_output_current_limit(CHARGER_SOLO,
- -current_lid, otg_voltage);
+ ret = charge_set_output_current_limit(
+ CHARGER_SOLO, -current_lid, otg_voltage);
}
if (ret)
@@ -536,7 +530,6 @@ static void charge_allocate_input_current_limit(void)
const struct ec_response_battery_dynamic_info *const base_bd =
&battery_dynamic[BATT_IDX_BASE];
-
if (!base_connected) {
set_base_lid_current(0, 0, curr.desired_input_current, 1);
prev_base_battery_power = -1;
@@ -553,7 +546,8 @@ static void charge_allocate_input_current_limit(void)
* but the value is currently wrong, especially during transitions.
*/
if (total_power <= 0) {
- int base_critical = charge_base >= 0 &&
+ int base_critical =
+ charge_base >= 0 &&
charge_base < db_policy.max_charge_base_batt_to_batt;
/* Discharging */
@@ -567,14 +561,14 @@ static void charge_allocate_input_current_limit(void)
if (manual_noac_current_base > 0) {
base_current = -manual_noac_current_base;
- lid_current =
- add_margin(manual_noac_current_base,
- db_policy.margin_otg_current);
+ lid_current = add_margin(
+ manual_noac_current_base,
+ db_policy.margin_otg_current);
} else {
lid_current = manual_noac_current_base;
- base_current =
- add_margin(-manual_noac_current_base,
- db_policy.margin_otg_current);
+ base_current = add_margin(
+ -manual_noac_current_base,
+ db_policy.margin_otg_current);
}
set_base_lid_current(base_current, 0, lid_current, 0);
@@ -605,18 +599,20 @@ static void charge_allocate_input_current_limit(void)
* touchpad events.
*/
if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
- !base_critical) {
+ !base_critical) {
set_base_lid_current(0, 0, 0, 0);
return;
}
if (charge_base > db_policy.min_charge_base_otg) {
int lid_current = db_policy.max_base_to_lid_current;
- int base_current = add_margin(lid_current,
- db_policy.margin_otg_current);
+ int base_current = add_margin(
+ lid_current, db_policy.margin_otg_current);
/* Draw current from base to lid */
- set_base_lid_current(-base_current, 0, lid_current,
- charge_lid < db_policy.max_charge_lid_batt_to_batt);
+ set_base_lid_current(
+ -base_current, 0, lid_current,
+ charge_lid <
+ db_policy.max_charge_lid_batt_to_batt);
} else {
/*
* Base battery is too low, apply power to it, and allow
@@ -635,8 +631,8 @@ static void charge_allocate_input_current_limit(void)
int base_current =
(db_policy.min_base_system_power * 1000) /
db_policy.otg_voltage;
- int lid_current = add_margin(base_current,
- db_policy.margin_otg_current);
+ int lid_current = add_margin(
+ base_current, db_policy.margin_otg_current);
set_base_lid_current(base_current, base_critical,
-lid_current, 0);
@@ -664,8 +660,8 @@ static void charge_allocate_input_current_limit(void)
lid_system_power = charger_get_system_power() / 1000;
/* Smooth system power, as it is very spiky */
- lid_system_power = smooth_value(prev_lid_system_power,
- lid_system_power, db_policy.lid_system_power_smooth);
+ lid_system_power = smooth_value(prev_lid_system_power, lid_system_power,
+ db_policy.lid_system_power_smooth);
prev_lid_system_power = lid_system_power;
/*
@@ -677,15 +673,15 @@ static void charge_allocate_input_current_limit(void)
*/
/* Estimate lid battery power. */
if (!(curr.batt.flags &
- (BATT_FLAG_BAD_VOLTAGE | BATT_FLAG_BAD_CURRENT)))
- lid_battery_power = curr.batt.current *
- curr.batt.voltage / 1000;
+ (BATT_FLAG_BAD_VOLTAGE | BATT_FLAG_BAD_CURRENT)))
+ lid_battery_power =
+ curr.batt.current * curr.batt.voltage / 1000;
if (lid_battery_power < prev_lid_battery_power)
- lid_battery_power = smooth_value(prev_lid_battery_power,
- lid_battery_power, db_policy.battery_power_smooth);
+ lid_battery_power =
+ smooth_value(prev_lid_battery_power, lid_battery_power,
+ db_policy.battery_power_smooth);
if (!(curr.batt.flags &
- (BATT_FLAG_BAD_DESIRED_VOLTAGE |
- BATT_FLAG_BAD_DESIRED_CURRENT)))
+ (BATT_FLAG_BAD_DESIRED_VOLTAGE | BATT_FLAG_BAD_DESIRED_CURRENT)))
lid_battery_power_max = curr.batt.desired_current *
curr.batt.desired_voltage / 1000;
@@ -699,19 +695,20 @@ static void charge_allocate_input_current_limit(void)
base_bd->desired_voltage / 1000;
}
if (base_battery_power < prev_base_battery_power)
- base_battery_power = smooth_value(prev_base_battery_power,
- base_battery_power, db_policy.battery_power_smooth);
+ base_battery_power = smooth_value(
+ prev_base_battery_power, base_battery_power,
+ db_policy.battery_power_smooth);
base_battery_power = MIN(base_battery_power, base_battery_power_max);
if (debugging) {
CPRINTF("%s:\n", __func__);
CPRINTF("total power: %d\n", total_power);
- CPRINTF("base battery power: %d (%d)\n",
- base_battery_power, base_battery_power_max);
+ CPRINTF("base battery power: %d (%d)\n", base_battery_power,
+ base_battery_power_max);
CPRINTF("lid system power: %d\n", lid_system_power);
CPRINTF("lid battery power: %d\n", lid_battery_power);
- CPRINTF("percent base/lid: %d%% %d%%\n",
- charge_base, charge_lid);
+ CPRINTF("percent base/lid: %d%% %d%%\n", charge_base,
+ charge_lid);
}
prev_lid_battery_power = lid_battery_power;
@@ -720,30 +717,31 @@ static void charge_allocate_input_current_limit(void)
if (total_power > 0) { /* Charging */
/* Allocate system power */
CHG_ALLOCATE(power_base, total_power,
- db_policy.min_base_system_power);
+ db_policy.min_base_system_power);
CHG_ALLOCATE(power_lid, total_power, lid_system_power);
/* Allocate lid, then base battery power */
- lid_battery_power = add_margin(lid_battery_power,
- db_policy.margin_lid_battery_power);
+ lid_battery_power = add_margin(
+ lid_battery_power, db_policy.margin_lid_battery_power);
CHG_ALLOCATE(power_lid, total_power, lid_battery_power);
- base_battery_power = add_margin(base_battery_power,
- db_policy.margin_base_battery_power);
+ base_battery_power =
+ add_margin(base_battery_power,
+ db_policy.margin_base_battery_power);
CHG_ALLOCATE(power_base, total_power, base_battery_power);
/* Give everything else to the lid. */
CHG_ALLOCATE(power_lid, total_power, total_power);
if (debugging)
- CPRINTF("power: base %d mW / lid %d mW\n",
- power_base, power_lid);
+ CPRINTF("power: base %d mW / lid %d mW\n", power_base,
+ power_lid);
current_base = 1000 * power_base / curr.input_voltage;
current_lid = 1000 * power_lid / curr.input_voltage;
if (current_base > db_policy.max_lid_to_base_current) {
- current_lid += (current_base
- - db_policy.max_lid_to_base_current);
+ current_lid += (current_base -
+ db_policy.max_lid_to_base_current);
current_base = db_policy.max_lid_to_base_current;
}
@@ -760,12 +758,13 @@ static void charge_allocate_input_current_limit(void)
}
#endif /* CONFIG_EC_EC_COMM_BATTERY_CLIENT */
-static const char * const state_list[] = {
- "idle", "discharge", "charge", "precharge"
-};
+static const char *const state_list[] = { "idle", "discharge", "charge",
+ "precharge" };
BUILD_ASSERT(ARRAY_SIZE(state_list) == NUM_STATES_V2);
-static const char * const batt_pres[] = {
- "NO", "YES", "NOT_SURE",
+static const char *const batt_pres[] = {
+ "NO",
+ "YES",
+ "NOT_SURE",
};
const char *mode_text[] = EC_CHARGE_MODE_TEXT;
@@ -774,9 +773,9 @@ BUILD_ASSERT(ARRAY_SIZE(mode_text) == CHARGE_CONTROL_COUNT);
static void dump_charge_state(void)
{
#define DUMP(FLD, FMT) ccprintf(#FLD " = " FMT "\n", curr.FLD)
-#define DUMP_CHG(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.chg. FLD)
-#define DUMP_BATT(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.batt. FLD)
-#define DUMP_OCPC(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.ocpc. FLD)
+#define DUMP_CHG(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.chg.FLD)
+#define DUMP_BATT(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.batt.FLD)
+#define DUMP_OCPC(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.ocpc.FLD)
enum ec_charge_control_mode cmode = get_chg_ctrl_mode();
@@ -846,8 +845,8 @@ static void dump_charge_state(void)
ccprintf("battery_was_removed = %d\n", battery_was_removed);
ccprintf("debug output = %s\n", debugging ? "on" : "off");
ccprintf("Battery sustainer = %s (%d%% ~ %d%%)\n",
- battery_sustainer_enabled() ? "on" : "off",
- sustain_soc.lower, sustain_soc.upper);
+ battery_sustainer_enabled() ? "on" : "off", sustain_soc.lower,
+ sustain_soc.upper);
#undef DUMP
}
@@ -901,14 +900,13 @@ static void show_charging_progress(void)
dsoc = charge_get_display_charge();
if (rv)
CPRINTS("Battery %d%% (Display %d.%d %%) / ??h:?? %s%s",
- curr.batt.state_of_charge,
- dsoc / 10, dsoc % 10,
+ curr.batt.state_of_charge, dsoc / 10, dsoc % 10,
to_full ? "to full" : "to empty",
is_full ? ", not accepting current" : "");
else
CPRINTS("Battery %d%% (Display %d.%d %%) / %dh:%d %s%s",
- curr.batt.state_of_charge,
- dsoc / 10, dsoc % 10, minutes / 60, minutes % 60,
+ curr.batt.state_of_charge, dsoc / 10, dsoc % 10,
+ minutes / 60, minutes % 60,
to_full ? "to full" : "to empty",
is_full ? ", not accepting current" : "");
@@ -948,6 +946,11 @@ test_mockable int calc_is_full(void)
return ret;
}
+__overridable int board_should_charger_bypass(void)
+{
+ return false;
+}
+
/*
* Ask the charger for some voltage and current. If either value is 0,
* charging is disabled; otherwise it's enabled. Negative values are ignored.
@@ -956,6 +959,7 @@ static int charge_request(int voltage, int current)
{
int r1 = EC_SUCCESS, r2 = EC_SUCCESS, r3 = EC_SUCCESS, r4 = EC_SUCCESS;
static int prev_volt, prev_curr;
+ bool should_bypass;
if (!voltage || !current) {
#ifdef CONFIG_CHARGER_NARROW_VDC
@@ -983,6 +987,17 @@ static int charge_request(int voltage, int current)
}
/*
+ * Enable bypass mode if applicable. Transition from Bypass to Bypass +
+ * CHRG or backward is done after this call (by set_current & set_mode)
+ * thus not done here. Similarly, when bypass is disabled, transitioning
+ * from nvdc + chrg will be done separately.
+ */
+ should_bypass = board_should_charger_bypass();
+ if ((should_bypass && !(curr.chg.status & CHARGER_BYPASS_MODE)) ||
+ (!should_bypass && (curr.chg.status & CHARGER_BYPASS_MODE)))
+ charger_enable_bypass_mode(0, should_bypass);
+
+ /*
* Set current before voltage so that if we are just starting
* to charge, we allow some time (i2c delay) for charging circuit to
* start at a voltage just above battery voltage before jumping
@@ -1019,9 +1034,9 @@ static int charge_request(int voltage, int current)
*/
if (curr.ocpc.active_chg_chip == CHARGER_SECONDARY) {
if ((current >= 0) || (voltage >= 0))
- r3 = ocpc_config_secondary_charger(&curr.desired_input_current,
- &curr.ocpc,
- voltage, current);
+ r3 = ocpc_config_secondary_charger(
+ &curr.desired_input_current, &curr.ocpc,
+ voltage, current);
if (r3 != EC_SUCCESS)
charge_problem(PR_CFG_SEC_CHG, r3);
}
@@ -1140,9 +1155,8 @@ static inline int battery_too_low(void)
curr.batt.voltage <= batt_info->voltage_min));
}
-__attribute__((weak))
-enum critical_shutdown board_critical_shutdown_check(
- struct charge_state_data *curr)
+__attribute__((weak)) enum critical_shutdown
+board_critical_shutdown_check(struct charge_state_data *curr)
{
#ifdef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF
return CRITICAL_SHUTDOWN_CUTOFF;
@@ -1173,21 +1187,21 @@ static int is_battery_critical(void)
}
if (battery_too_low() && !curr.batt_is_charging) {
- CPRINTS("Low battery: %d%%, %dmV",
- curr.batt.state_of_charge, curr.batt.voltage);
+ CPRINTS("Low battery: %d%%, %dmV", curr.batt.state_of_charge,
+ curr.batt.voltage);
return 1;
}
return 0;
}
- /*
- * If the battery is at extremely low charge (and discharging) or extremely
- * high temperature, the EC will notify the AP and start a timer. If the
- * critical condition is not corrected before the timeout expires, the EC
- * will shut down the AP (if the AP is not already off) and then optionally
- * hibernate or cut off battery.
- */
+/*
+ * If the battery is at extremely low charge (and discharging) or extremely
+ * high temperature, the EC will notify the AP and start a timer. If the
+ * critical condition is not corrected before the timeout expires, the EC
+ * will shut down the AP (if the AP is not already off) and then optionally
+ * hibernate or cut off battery.
+ */
static int shutdown_on_critical_battery(void)
{
if (!is_battery_critical()) {
@@ -1199,8 +1213,8 @@ static int shutdown_on_critical_battery(void)
if (!shutdown_target_time.val) {
/* Start count down timer */
CPRINTS("Start shutdown due to critical battery");
- shutdown_target_time.val = get_time().val
- + CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US;
+ shutdown_target_time.val =
+ get_time().val + CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US;
#ifdef CONFIG_HOSTCMD_EVENTS
if (!chipset_in_state(CHIPSET_STATE_ANY_OFF))
host_set_single_event(EC_HOST_EVENT_BATTERY_SHUTDOWN);
@@ -1245,14 +1259,36 @@ static int shutdown_on_critical_battery(void)
}
} else {
/* Timeout waiting for AP to shut down, so kill it */
- CPRINTS(
- "charge force shutdown due to critical battery");
+ CPRINTS("charge force shutdown due to critical battery");
chipset_force_shutdown(CHIPSET_SHUTDOWN_BATTERY_CRIT);
}
return 1;
}
+int battery_is_below_threshold(enum batt_threshold_type type, bool transitioned)
+{
+ int threshold;
+
+ /* We can't tell what the current charge is. Assume it's okay. */
+ if (curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)
+ return 0;
+
+ switch (type) {
+ case BATT_THRESHOLD_TYPE_LOW:
+ threshold = BATTERY_LEVEL_LOW;
+ break;
+ case BATT_THRESHOLD_TYPE_SHUTDOWN:
+ threshold = CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE;
+ break;
+ default:
+ return 0;
+ }
+
+ return curr.batt.state_of_charge <= threshold &&
+ (!transitioned || prev_charge > threshold);
+}
+
/*
* Send host events as the battery charge drops below certain thresholds.
* We handle forced shutdown and other actions elsewhere; this is just for the
@@ -1261,17 +1297,11 @@ static int shutdown_on_critical_battery(void)
*/
static void notify_host_of_low_battery_charge(void)
{
- /* We can't tell what the current charge is. Assume it's okay. */
- if (curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)
- return;
-
#ifdef CONFIG_HOSTCMD_EVENTS
- if (curr.batt.state_of_charge <= BATTERY_LEVEL_LOW &&
- prev_charge > BATTERY_LEVEL_LOW)
+ if (battery_is_below_threshold(BATT_THRESHOLD_TYPE_LOW, true))
host_set_single_event(EC_HOST_EVENT_BATTERY_LOW);
- if (curr.batt.state_of_charge <= BATTERY_LEVEL_CRITICAL &&
- prev_charge > BATTERY_LEVEL_CRITICAL)
+ if (battery_is_below_threshold(BATT_THRESHOLD_TYPE_SHUTDOWN, true))
host_set_single_event(EC_HOST_EVENT_BATTERY_CRITICAL);
#endif
}
@@ -1295,16 +1325,16 @@ static void notify_host_of_low_battery_voltage(void)
THROTTLE_SRC_BAT_VOLTAGE);
uvp_throttle_start_time = get_time();
} else if (uvp_throttle_start_time.val &&
- (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH +
- BAT_UVP_HYSTERESIS)) {
+ (curr.batt.voltage <
+ BAT_LOW_VOLTAGE_THRESH + BAT_UVP_HYSTERESIS)) {
/*
* Reset the timer when we are not sure if VBAT can stay
* above BAT_LOW_VOLTAGE_THRESH after we stop throttling.
*/
uvp_throttle_start_time = get_time();
} else if (uvp_throttle_start_time.val &&
- (get_time().val > uvp_throttle_start_time.val +
- BAT_UVP_TIMEOUT_US)) {
+ (get_time().val >
+ uvp_throttle_start_time.val + BAT_UVP_TIMEOUT_US)) {
throttle_ap(THROTTLE_OFF, THROTTLE_SOFT,
THROTTLE_SRC_BAT_VOLTAGE);
uvp_throttle_start_time.val = 0;
@@ -1328,8 +1358,8 @@ static void notify_host_of_over_current(struct batt_params *batt)
throttle_ap(THROTTLE_ON, THROTTLE_SOFT,
THROTTLE_SRC_BAT_DISCHG_CURRENT);
} else if (ocp_throttle_start_time.val &&
- (get_time().val > ocp_throttle_start_time.val +
- BAT_OCP_TIMEOUT_US)) {
+ (get_time().val >
+ ocp_throttle_start_time.val + BAT_OCP_TIMEOUT_US)) {
/*
* Clear the timer and notify AP to stop throttling if
* we haven't seen over current for BAT_OCP_TIMEOUT_US.
@@ -1361,8 +1391,8 @@ static int battery_outside_charging_temperature(void)
if (curr.batt.flags & BATT_FLAG_BAD_TEMPERATURE)
return 0;
- if((curr.batt.desired_voltage == 0) &&
- (curr.batt.desired_current == 0)){
+ if ((curr.batt.desired_voltage == 0) &&
+ (curr.batt.desired_current == 0)) {
max_c = batt_info->start_charging_max_c;
min_c = batt_info->start_charging_min_c;
} else {
@@ -1370,9 +1400,7 @@ static int battery_outside_charging_temperature(void)
min_c = batt_info->charging_min_c;
}
-
- if ((batt_temp_c >= max_c) ||
- (batt_temp_c <= min_c)) {
+ if ((batt_temp_c >= max_c) || (batt_temp_c <= min_c)) {
return 1;
}
return 0;
@@ -1385,8 +1413,8 @@ static void sustain_battery_soc(void)
int rv;
/* If either AC or battery is not present, nothing to do. */
- if (!curr.ac || curr.batt.is_present != BP_YES
- || !battery_sustainer_enabled())
+ if (!curr.ac || curr.batt.is_present != BP_YES ||
+ !battery_sustainer_enabled())
return;
soc = charge_get_display_charge() / 10;
@@ -1402,7 +1430,8 @@ static void sustain_battery_soc(void)
/* Going up */
if (sustain_soc.upper < soc)
mode = sustain_soc.upper == sustain_soc.lower ?
- CHARGE_CONTROL_IDLE : CHARGE_CONTROL_DISCHARGE;
+ CHARGE_CONTROL_IDLE :
+ CHARGE_CONTROL_DISCHARGE;
break;
case CHARGE_CONTROL_IDLE:
/* Discharging naturally */
@@ -1422,8 +1451,8 @@ static void sustain_battery_soc(void)
return;
rv = set_chg_ctrl_mode(mode);
- CPRINTS("%s: %s control mode to %s",
- __func__, rv == EC_SUCCESS ? "Switched" : "Failed to switch",
+ CPRINTS("%s: %s control mode to %s", __func__,
+ rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[mode]);
}
@@ -1454,6 +1483,7 @@ static void charge_wakeup(void)
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, charge_wakeup, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_AC_CHANGE, charge_wakeup, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_POWER_SUPPLY_CHANGE, charge_wakeup, HOOK_PRIO_DEFAULT);
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
/* Reset the base on S5->S0 transition. */
@@ -1465,20 +1495,19 @@ static void bat_low_voltage_throttle_reset(void)
{
uvp_throttle_start_time.val = 0;
}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
- bat_low_voltage_throttle_reset,
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, bat_low_voltage_throttle_reset,
HOOK_PRIO_DEFAULT);
#endif
static int get_desired_input_current(enum battery_present batt_present,
- const struct charger_info * const info)
+ const struct charger_info *const info)
{
if (batt_present == BP_YES || system_is_locked() || base_connected) {
#ifdef CONFIG_CHARGE_MANAGER
int ilim = charge_manager_get_charger_current();
return ilim == CHARGE_CURRENT_UNINITIALIZED ?
- CHARGE_CURRENT_UNINITIALIZED :
- MAX(CONFIG_CHARGER_INPUT_CURRENT, ilim);
+ CHARGE_CURRENT_UNINITIALIZED :
+ MAX(CONFIG_CHARGER_INPUT_CURRENT, ilim);
#else
return CONFIG_CHARGER_INPUT_CURRENT;
#endif
@@ -1498,9 +1527,9 @@ static void wakeup_battery(int *need_static)
set_charge_state(ST_IDLE);
curr.requested_voltage = 0;
curr.requested_current = 0;
- } else if (curr.state == ST_PRECHARGE
- && (get_time().val > precharge_start_time.val +
- PRECHARGE_TIMEOUT_US)) {
+ } else if (curr.state == ST_PRECHARGE &&
+ (get_time().val >
+ precharge_start_time.val + PRECHARGE_TIMEOUT_US)) {
/* We've tried long enough, give up */
CPRINTS("battery seems to be dead");
battery_seems_dead = 1;
@@ -1531,9 +1560,10 @@ static void deep_charge_battery(int *need_static)
/* Deep charge time out , do nothing */
curr.requested_voltage = 0;
curr.requested_current = 0;
- } else if (curr.state == ST_PRECHARGE
- && (get_time().val > precharge_start_time.val +
- CONFIG_BATTERY_LOW_VOLTAGE_TIMEOUT)) {
+ } else if (curr.state == ST_PRECHARGE &&
+ (get_time().val >
+ precharge_start_time.val +
+ CONFIG_BATTERY_LOW_VOLTAGE_TIMEOUT)) {
/* We've tried long enough, give up */
CPRINTS("Precharge for low voltage timed out");
set_charge_state(ST_IDLE);
@@ -1552,13 +1582,11 @@ static void deep_charge_battery(int *need_static)
}
}
-
static void revive_battery(int *need_static)
{
- if (IS_ENABLED(CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD)
- && curr.requested_voltage == 0
- && curr.requested_current == 0
- && curr.batt.state_of_charge == 0) {
+ if (IS_ENABLED(CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD) &&
+ curr.requested_voltage == 0 && curr.requested_current == 0 &&
+ curr.batt.state_of_charge == 0) {
/*
* Battery is dead, give precharge current
* TODO (crosbug.com/p/29467): remove this workaround
@@ -1566,10 +1594,9 @@ static void revive_battery(int *need_static)
*/
curr.requested_voltage = batt_info->voltage_max;
curr.requested_current = batt_info->precharge_current;
- } else if (IS_ENABLED(CONFIG_BATTERY_REVIVE_DISCONNECT)
- && curr.requested_voltage == 0
- && curr.requested_current == 0
- && battery_seems_disconnected) {
+ } else if (IS_ENABLED(CONFIG_BATTERY_REVIVE_DISCONNECT) &&
+ curr.requested_voltage == 0 && curr.requested_current == 0 &&
+ battery_seems_disconnected) {
/*
* Battery is in disconnect state. Apply a
* current to kick it out of this state.
@@ -1577,8 +1604,8 @@ static void revive_battery(int *need_static)
CPRINTS("found battery in disconnect state");
curr.requested_voltage = batt_info->voltage_max;
curr.requested_current = batt_info->precharge_current;
- } else if (curr.state == ST_PRECHARGE
- || battery_seems_dead || battery_was_removed) {
+ } else if (curr.state == ST_PRECHARGE || battery_seems_dead ||
+ battery_was_removed) {
CPRINTS("battery woke up");
/* Update the battery-specific values */
batt_info = battery_get_info();
@@ -1594,7 +1621,7 @@ void charger_task(void *u)
int sleep_usec;
int battery_critical;
int need_static = 1;
- const struct charger_info * const info = charger_get_info();
+ const struct charger_info *const info = charger_get_info();
int prev_plt_and_desired_mw;
int chgnum = 0;
@@ -1622,8 +1649,8 @@ void charger_task(void *u)
* as needed.
*/
prev_bp = BP_NOT_INIT;
- curr.desired_input_current = get_desired_input_current(
- curr.batt.is_present, info);
+ curr.desired_input_current =
+ get_desired_input_current(curr.batt.is_present, info);
if (IS_ENABLED(CONFIG_USB_PD_PREFER_MV)) {
/* init battery desired power */
@@ -1640,7 +1667,6 @@ void charger_task(void *u)
battery_level_shutdown = board_set_battery_level_shutdown();
while (1) {
-
/* Let's see what's going on... */
curr.ts = get_time();
sleep_usec = 0;
@@ -1657,8 +1683,8 @@ void charger_task(void *u)
curr.ac = 0;
/* System is off: if AC gets connected, reset the base. */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF) &&
- !prev_ac && curr.ac)
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !prev_ac &&
+ curr.ac)
board_base_reset();
#endif
if (curr.ac != prev_ac) {
@@ -1679,7 +1705,7 @@ void charger_task(void *u)
if (rv != EC_SUCCESS) {
charge_problem(PR_POST_INIT, rv);
} else if (curr.desired_input_current !=
- CHARGE_CURRENT_UNINITIALIZED) {
+ CHARGE_CURRENT_UNINITIALIZED) {
rv = charger_set_input_current_limit(
chgnum,
curr.desired_input_current);
@@ -1727,8 +1753,8 @@ void charger_task(void *u)
get_desired_input_current(prev_bp, info);
if (curr.desired_input_current !=
CHARGE_CURRENT_UNINITIALIZED)
- charger_set_input_current_limit(chgnum,
- curr.desired_input_current);
+ charger_set_input_current_limit(
+ chgnum, curr.desired_input_current);
hook_notify(HOOK_BATTERY_SOC_CHANGE);
}
@@ -1749,7 +1775,7 @@ void charger_task(void *u)
* applying power to a battery we can't talk to.
*/
if (curr.batt.flags & (BATT_FLAG_BAD_DESIRED_VOLTAGE |
- BATT_FLAG_BAD_DESIRED_CURRENT)) {
+ BATT_FLAG_BAD_DESIRED_CURRENT)) {
curr.requested_voltage = 0;
curr.requested_current = 0;
} else {
@@ -1805,9 +1831,9 @@ void charger_task(void *u)
goto wait_for_it;
}
- if (IS_ENABLED(CONFIG_BATTERY_LOW_VOLTAGE_PROTECTION)
- && !(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE)
- && (curr.batt.voltage <= batt_info->voltage_min)) {
+ if (IS_ENABLED(CONFIG_BATTERY_LOW_VOLTAGE_PROTECTION) &&
+ !(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE) &&
+ (curr.batt.voltage <= batt_info->voltage_min)) {
deep_charge_battery(&need_static);
goto wait_for_it;
}
@@ -1819,23 +1845,23 @@ void charger_task(void *u)
* the battery disconnect state is one of the items used
* to decide whether or not to leave safe mode.
*/
- battery_seems_disconnected =
- battery_get_disconnect_state() == BATTERY_DISCONNECTED;
+ battery_seems_disconnected = battery_get_disconnect_state() ==
+ BATTERY_DISCONNECTED;
revive_battery(&need_static);
set_charge_state(ST_CHARGE);
-wait_for_it:
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
- && get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL) {
+ wait_for_it:
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL) {
sleep_usec = charger_profile_override(&curr);
if (sleep_usec < 0)
charge_problem(PR_CUSTOM, sleep_usec);
}
- if (IS_ENABLED(CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS)
- && battery_outside_charging_temperature()) {
+ if (IS_ENABLED(CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS) &&
+ battery_outside_charging_temperature()) {
curr.requested_current = 0;
curr.requested_voltage = 0;
curr.batt.flags &= ~BATT_FLAG_WANT_CHARGE;
@@ -1845,23 +1871,8 @@ wait_for_it:
#ifdef CONFIG_CHARGE_MANAGER
if (curr.batt.state_of_charge >=
- CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
+ CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
!battery_seems_disconnected) {
- /*
- * Sometimes the fuel gauge will report that it has
- * sufficient state of charge and remaining capacity,
- * but in actuality it doesn't. When the EC sees that
- * information, it trusts it and leaves charge manager
- * safe mode. Doing so will allow CHARGE_PORT_NONE to
- * be selected, thereby cutting off the input FETs.
- * When the battery cannot provide the charge it claims,
- * the system loses power, shuts down, and the battery
- * is not charged even though the charger is plugged in.
- * By waiting 500ms, we can avoid the selection of
- * CHARGE_PORT_NONE around init time and not cut off the
- * input FETs.
- */
- msleep(500);
charge_manager_leave_safe_mode();
}
#endif
@@ -1882,12 +1893,11 @@ wait_for_it:
sustain_battery_soc();
if ((!(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- curr.batt.state_of_charge != prev_charge) ||
+ curr.batt.state_of_charge != prev_charge) ||
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
(charge_base != prev_charge_base) ||
#endif
- (is_full != prev_full) ||
- (curr.state != prev_state) ||
+ (is_full != prev_full) || (curr.state != prev_state) ||
(charge_get_display_charge() != prev_disp_charge)) {
show_charging_progress();
prev_charge = curr.batt.state_of_charge;
@@ -1968,9 +1978,8 @@ wait_for_it:
sleep_usec = CHARGE_POLL_PERIOD_SHORT;
else if (sleep_usec <= 0) {
/* default values depend on the state */
- if (!curr.ac &&
- (curr.state == ST_IDLE ||
- curr.state == ST_DISCHARGE)) {
+ if (!curr.ac && (curr.state == ST_IDLE ||
+ curr.state == ST_DISCHARGE)) {
#ifdef CONFIG_CHARGER_OTG
int output_current = curr.output_current;
#else
@@ -1980,9 +1989,10 @@ wait_for_it:
* If AP is off and we do not provide power, we
* can sleep a long time.
*/
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF |
- CHIPSET_STATE_ANY_SUSPEND)
- && output_current == 0)
+ if (chipset_in_state(
+ CHIPSET_STATE_ANY_OFF |
+ CHIPSET_STATE_ANY_SUSPEND) &&
+ output_current == 0)
sleep_usec =
CHARGE_POLL_PERIOD_VERY_LONG;
else
@@ -2062,15 +2072,14 @@ wait_for_it:
}
}
-
/*****************************************************************************/
/* Exported functions */
int charge_want_shutdown(void)
{
return (curr.state == ST_DISCHARGE) &&
- !(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- (curr.batt.state_of_charge < battery_level_shutdown);
+ !(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
+ (curr.batt.state_of_charge < battery_level_shutdown);
}
int charge_prevent_power_on(int power_button_pressed)
@@ -2103,14 +2112,14 @@ int charge_prevent_power_on(int power_button_pressed)
if (current_batt_params->is_present != BP_YES ||
#ifdef CONFIG_BATTERY_MEASURE_IMBALANCE
(current_batt_params->flags & BATT_FLAG_IMBALANCED_CELL &&
- current_batt_params->state_of_charge <
- CONFIG_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON) ||
+ current_batt_params->state_of_charge <
+ CONFIG_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON) ||
#endif
#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED ||
#endif
current_batt_params->state_of_charge <
- CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
+ CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
prevent_power_on = 1;
#if defined(CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON) && \
@@ -2123,13 +2132,14 @@ int charge_prevent_power_on(int power_button_pressed)
#if defined(CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT) && \
defined(CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC)
else if (charge_manager_get_power_limit_uw() >=
- CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT * 1000
+ CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT *
+ 1000
#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
- && battery_get_disconnect_state() ==
- BATTERY_NOT_DISCONNECTED
+ && battery_get_disconnect_state() ==
+ BATTERY_NOT_DISCONNECTED
#endif
- && (current_batt_params->state_of_charge >=
- CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC))
+ && (current_batt_params->state_of_charge >=
+ CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC))
prevent_power_on = 0;
#endif
}
@@ -2140,18 +2150,18 @@ int charge_prevent_power_on(int power_button_pressed)
* except when auto-power-on at EC startup and the battery
* is physically present.
*/
- prevent_power_on &= (system_is_locked() || (automatic_power_on
+ prevent_power_on &=
+ (system_is_locked() || (automatic_power_on
#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM
- && battery_hw_present() == BP_YES
+ && battery_hw_present() == BP_YES
#endif
- ));
+ ));
#endif /* CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON */
#ifdef CONFIG_CHARGE_MANAGER
/* Always prevent power on until charge current is initialized */
- if (extpower_is_present() &&
- (charge_manager_get_charger_current() ==
- CHARGE_CURRENT_UNINITIALIZED))
+ if (extpower_is_present() && (charge_manager_get_charger_current() ==
+ CHARGE_CURRENT_UNINITIALIZED))
prevent_power_on = 1;
#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM
/*
@@ -2161,19 +2171,19 @@ int charge_prevent_power_on(int power_button_pressed)
if (extpower_is_present() && battery_hw_present() == BP_NO
#ifdef CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON
&& charge_manager_get_power_limit_uw() <
- CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON * 1000
+ CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON * 1000
#endif /* CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON */
- )
+ )
prevent_power_on = 1;
#endif /* CONFIG_BATTERY_HW_PRESENT_CUSTOM */
#endif /* CONFIG_CHARGE_MANAGER */
- /*
- * Prevent power on if there is no battery nor ac power. This
- * happens when the servo is powering the EC to flash it. Only include
- * this logic for boards in initial bring up phase since this won't
- * happen for released boards.
- */
+ /*
+ * Prevent power on if there is no battery nor ac power. This
+ * happens when the servo is powering the EC to flash it. Only
+ * include this logic for boards in initial bring up phase since
+ * this won't happen for released boards.
+ */
#ifdef CONFIG_SYSTEM_UNLOCKED
if (!current_batt_params->is_present && !curr.ac)
prevent_power_on = 1;
@@ -2197,11 +2207,19 @@ static int battery_near_full(void)
enum charge_state charge_get_state(void)
{
+ uint32_t chflags;
+
switch (curr.state) {
case ST_IDLE:
+ chflags = charge_get_flags();
+
if (battery_seems_dead || curr.batt.is_present == BP_NO)
return PWR_STATE_ERROR;
- return PWR_STATE_IDLE;
+
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ return PWR_STATE_FORCED_IDLE;
+ else
+ return PWR_STATE_IDLE;
case ST_DISCHARGE:
#ifdef CONFIG_PWR_STATE_DISCHARGE_FULL
if (battery_near_full())
@@ -2219,8 +2237,13 @@ enum charge_state charge_get_state(void)
else
return PWR_STATE_CHARGE;
case ST_PRECHARGE:
+ chflags = charge_get_flags();
+
/* we're in battery discovery mode */
- return PWR_STATE_IDLE;
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ return PWR_STATE_FORCED_IDLE;
+ else
+ return PWR_STATE_IDLE;
default:
/* Anything else can be considered an error for LED purposes */
return PWR_STATE_ERROR;
@@ -2317,8 +2340,7 @@ int charge_set_input_current_limit(int ma, int mv)
* browning out due to insufficient input current.
*/
if (curr.batt.is_present != BP_YES && !system_is_locked() &&
- !base_connected) {
-
+ !base_connected) {
int prev_input = 0;
charger_get_input_current_limit(chgnum, &prev_input);
@@ -2333,8 +2355,8 @@ int charge_set_input_current_limit(int ma, int mv)
* input system power.
*/
- if (mv > 0 && mv * curr.desired_input_current >
- PD_MAX_POWER_MW * 1000)
+ if (mv > 0 &&
+ mv * curr.desired_input_current > PD_MAX_POWER_MW * 1000)
ma = (PD_MAX_POWER_MW * 1000) / mv;
/*
* If the active charger has already been initialized to at
@@ -2346,11 +2368,11 @@ int charge_set_input_current_limit(int ma, int mv)
if (prev_input >= ma)
return EC_SUCCESS;
#endif
- /*
- * If the current needs lowered due to PD max power
- * considerations, or needs raised for the selected active
- * charger chip, fall through to set.
- */
+ /*
+ * If the current needs lowered due to PD max power
+ * considerations, or needs raised for the selected
+ * active charger chip, fall through to set.
+ */
#endif /* CONFIG_USB_POWER_DELIVERY */
}
@@ -2468,8 +2490,8 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
if (p->cmd == EC_CHARGE_CONTROL_CMD_SET) {
if (p->mode == CHARGE_CONTROL_NORMAL) {
rv = battery_sustainer_set(
- p->sustain_soc.lower,
- p->sustain_soc.upper);
+ p->sustain_soc.lower,
+ p->sustain_soc.upper);
if (rv == EC_RES_UNAVAILABLE)
return EC_RES_UNAVAILABLE;
if (rv)
@@ -2565,7 +2587,6 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
chgnum = in->chgnum;
switch (in->cmd) {
-
case CHARGE_STATE_CMD_GET_STATE:
out->get_state.ac = curr.ac;
out->get_state.chg_voltage = curr.chg.voltage;
@@ -2577,18 +2598,18 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
case CHARGE_STATE_CMD_GET_PARAM:
val = 0;
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
- && in->get_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN
- && in->get_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ in->get_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN &&
+ in->get_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
/* custom profile params */
- rv = charger_profile_override_get_param(
+ rv = charger_profile_override_get_param(
in->get_param.param, &val);
- } else if (IS_ENABLED(CONFIG_CHARGE_STATE_DEBUG)
- && in->get_param.param >= CS_PARAM_DEBUG_MIN
- && in->get_param.param <= CS_PARAM_DEBUG_MAX) {
+ } else if (IS_ENABLED(CONFIG_CHARGE_STATE_DEBUG) &&
+ in->get_param.param >= CS_PARAM_DEBUG_MIN &&
+ in->get_param.param <= CS_PARAM_DEBUG_MAX) {
/* debug params */
- rv = charge_get_charge_state_debug(
- in->get_param.param, &val);
+ rv = charge_get_charge_state_debug(in->get_param.param,
+ &val);
} else {
/* standard params */
switch (in->get_param.param) {
@@ -2615,10 +2636,11 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
*/
if ((curr.batt.is_present != BP_YES ||
curr.batt.state_of_charge <
- CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT)
- && charge_manager_get_power_limit_uw() <
- CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW
- * 1000 && system_is_locked())
+ CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT) &&
+ charge_manager_get_power_limit_uw() <
+ CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW *
+ 1000 &&
+ system_is_locked())
val = 1;
else
#endif
@@ -2639,11 +2661,11 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
return EC_RES_ACCESS_DENIED;
val = in->set_param.value;
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
- && in->set_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN
- && in->set_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ in->set_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN &&
+ in->set_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
/* custom profile params */
- rv = charger_profile_override_set_param(
+ rv = charger_profile_override_set_param(
in->set_param.param, val);
} else {
switch (in->set_param.param) {
@@ -2669,7 +2691,6 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
break;
default:
rv = EC_RES_INVALID_PARAM;
-
}
}
break;
@@ -2690,7 +2711,7 @@ DECLARE_HOST_COMMAND(EC_CMD_CHARGE_STATE, charge_command_charge_state,
#ifdef CONFIG_CMD_PWR_AVG
-static int command_pwr_avg(int argc, char **argv)
+static int command_pwr_avg(int argc, const char **argv)
{
int avg_mv;
int avg_ma;
@@ -2705,18 +2726,16 @@ static int command_pwr_avg(int argc, char **argv)
avg_ma = battery_get_avg_current();
avg_mw = avg_mv * avg_ma / 1000;
- ccprintf("mv = %d\nma = %d\nmw = %d\n",
- avg_mv, avg_ma, avg_mw);
+ ccprintf("mv = %d\nma = %d\nmw = %d\n", avg_mv, avg_ma, avg_mw);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(pwr_avg, command_pwr_avg,
- NULL,
+DECLARE_CONSOLE_COMMAND(pwr_avg, command_pwr_avg, NULL,
"Get 1 min power average");
#endif /* CONFIG_CMD_PWR_AVG */
-static int command_chgstate(int argc, char **argv)
+static int command_chgstate(int argc, const char **argv)
{
int rv;
int val;
@@ -2729,7 +2748,7 @@ static int command_chgstate(int argc, char **argv)
if (!parse_bool(argv[2], &val))
return EC_ERROR_PARAM2;
rv = set_chg_ctrl_mode(val ? CHARGE_CONTROL_IDLE :
- CHARGE_CONTROL_NORMAL);
+ CHARGE_CONTROL_NORMAL);
if (rv)
return rv;
} else if (!strcasecmp(argv[1], "discharge")) {
@@ -2738,7 +2757,7 @@ static int command_chgstate(int argc, char **argv)
if (!parse_bool(argv[2], &val))
return EC_ERROR_PARAM2;
rv = set_chg_ctrl_mode(val ? CHARGE_CONTROL_DISCHARGE :
- CHARGE_CONTROL_NORMAL);
+ CHARGE_CONTROL_NORMAL);
if (rv)
return rv;
} else if (!strcasecmp(argv[1], "debug")) {
@@ -2774,7 +2793,7 @@ DECLARE_CONSOLE_COMMAND(chgstate, command_chgstate,
"Get/set charge state machine status");
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
-static int command_chgdualdebug(int argc, char **argv)
+static int command_chgdualdebug(int argc, const char **argv)
{
int val;
char *e;
@@ -2812,9 +2831,8 @@ static int command_chgdualdebug(int argc, char **argv)
return EC_ERROR_PARAM1;
}
} else {
- ccprintf("Base/Lid: %d%s/%d mA\n",
- prev_current_base, prev_allow_charge_base ? "+" : "",
- prev_current_lid);
+ ccprintf("Base/Lid: %d%s/%d mA\n", prev_current_base,
+ prev_allow_charge_base ? "+" : "", prev_current_lid);
}
return EC_SUCCESS;
diff --git a/common/chargen.c b/common/chargen.c
index 1a57e7f539..cfbf8bb2ca 100644
--- a/common/chargen.c
+++ b/common/chargen.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -17,8 +17,8 @@
* Microseconds time to drain entire UART_TX console buffer at 115200 b/s, 10
* bits per character.
*/
-#define BUFFER_DRAIN_TIME_US (1000000UL * 10 * CONFIG_UART_TX_BUF_SIZE \
- / CONFIG_UART_BAUD_RATE)
+#define BUFFER_DRAIN_TIME_US \
+ (1000000UL * 10 * CONFIG_UART_TX_BUF_SIZE / CONFIG_UART_BAUD_RATE)
/*
* Generate a stream of characters on the UART (and USB) console.
@@ -37,7 +37,7 @@
*
* Hitting 'x' on the keyboard stops the generator.
*/
-static int command_chargen(int argc, char **argv)
+static int command_chargen(int argc, const char **argv)
{
int wrap_value = 0;
int wrap_counter = 0;
@@ -80,7 +80,7 @@ static int command_chargen(int argc, char **argv)
* Let's let other tasks run for a bit while buffer is
* being drained a little.
*/
- usleep(BUFFER_DRAIN_TIME_US/10);
+ usleep(BUFFER_DRAIN_TIME_US / 10);
current_time = get_time();
@@ -110,7 +110,7 @@ static int command_chargen(int argc, char **argv)
c = '0';
else if (c == ('Z' + 1))
c = 'a';
- else if (c == ('9' + 1))
+ else if (c == ('9' + 1))
c = 'A';
}
@@ -128,6 +128,5 @@ DECLARE_SAFE_CONSOLE_COMMAND(chargen, command_chargen,
#endif
"Generate a constant stream of characters on the "
"UART console,\nrepeating every 'seq_length' "
- "characters, up to 'num_chars' total."
- );
-#endif /* !SECTION_IS_RO */
+ "characters, up to 'num_chars' total.");
+#endif /* !SECTION_IS_RO */
diff --git a/common/charger.c b/common/charger.c
index 8dae2e71e8..c19dd85832 100644
--- a/common/charger.c
+++ b/common/charger.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -18,7 +18,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
/* DPTF current limit, -1 = none */
static int dptf_limit_ma = -1;
@@ -71,7 +71,7 @@ int charger_closest_voltage(int voltage)
int charger_closest_current(int current)
{
- const struct charger_info * const info = charger_get_info();
+ const struct charger_info *const info = charger_get_info();
/* Apply DPTF limit if necessary */
if (dptf_limit_ma >= 0 && current > dptf_limit_ma)
@@ -146,7 +146,7 @@ void print_charger_debug(int chgnum)
/* option */
print_item_name("Option:");
if (check_print_error(charger_get_option(&d)))
- ccprintf("%pb (0x%04x)\n", BINARY_VALUE(d, 16), d);
+ ccprintf("(0x%04x)\n", d);
/* manufacturer id */
print_item_name("Man id:");
@@ -184,7 +184,7 @@ void print_charger_debug(int chgnum)
ccputs("disabled\n");
}
-static int command_charger(int argc, char **argv)
+static int command_charger(int argc, const char **argv)
{
int d;
char *e;
@@ -210,41 +210,43 @@ static int command_charger(int argc, char **argv)
return EC_SUCCESS;
}
- if (strcasecmp(argv[1+idx_provided], "input") == 0) {
- d = strtoi(argv[2+idx_provided], &e, 0);
+ if (strcasecmp(argv[1 + idx_provided], "input") == 0) {
+ d = strtoi(argv[2 + idx_provided], &e, 0);
if (*e)
- return EC_ERROR_PARAM2+idx_provided;
+ return EC_ERROR_PARAM2 + idx_provided;
return charger_set_input_current_limit(chgnum, d);
- } else if (strcasecmp(argv[1+idx_provided], "current") == 0) {
- d = strtoi(argv[2+idx_provided], &e, 0);
+ } else if (IS_ENABLED(CONFIG_BATTERY) &&
+ strcasecmp(argv[1 + idx_provided], "current") == 0) {
+ d = strtoi(argv[2 + idx_provided], &e, 0);
if (*e)
- return EC_ERROR_PARAM2+idx_provided;
+ return EC_ERROR_PARAM2 + idx_provided;
chgstate_set_manual_current(d);
return charger_set_current(chgnum, d);
- } else if (strcasecmp(argv[1+idx_provided], "voltage") == 0) {
- d = strtoi(argv[2+idx_provided], &e, 0);
+ } else if (IS_ENABLED(CONFIG_BATTERY) &&
+ strcasecmp(argv[1 + idx_provided], "voltage") == 0) {
+ d = strtoi(argv[2 + idx_provided], &e, 0);
if (*e)
- return EC_ERROR_PARAM2+idx_provided;
+ return EC_ERROR_PARAM2 + idx_provided;
chgstate_set_manual_voltage(d);
return charger_set_voltage(chgnum, d);
- } else if (strcasecmp(argv[1+idx_provided], "dptf") == 0) {
- d = strtoi(argv[2+idx_provided], &e, 0);
+ } else if (strcasecmp(argv[1 + idx_provided], "dptf") == 0) {
+ d = strtoi(argv[2 + idx_provided], &e, 0);
if (*e)
- return EC_ERROR_PARAM2+idx_provided;
+ return EC_ERROR_PARAM2 + idx_provided;
dptf_limit_ma = d;
return EC_SUCCESS;
- } else if (strcasecmp(argv[1+idx_provided], "dump") == 0) {
+ } else if (strcasecmp(argv[1 + idx_provided], "dump") == 0) {
if (!IS_ENABLED(CONFIG_CMD_CHARGER_DUMP) ||
- !chg_chips[chgnum].drv->dump_registers) {
+ !chg_chips[chgnum].drv->dump_registers) {
ccprintf("dump not supported\n");
- return EC_ERROR_PARAM1+idx_provided;
+ return EC_ERROR_PARAM1 + idx_provided;
}
ccprintf("Dump %s registers\n",
- chg_chips[chgnum].drv->get_info(chgnum)->name);
+ chg_chips[chgnum].drv->get_info(chgnum)->name);
chg_chips[chgnum].drv->dump_registers(chgnum);
return EC_SUCCESS;
} else {
- return EC_ERROR_PARAM1+idx_provided;
+ return EC_ERROR_PARAM1 + idx_provided;
}
}
@@ -500,7 +502,7 @@ enum ec_error_list charger_enable_bypass_mode(int chgnum, int enable)
return chg_chips[chgnum].drv->enable_bypass_mode(chgnum, enable);
}
-enum ec_error_list charger_get_vbus_voltage(int port, int *voltage)
+static int charger_get_valid_chgnum(int port)
{
int chgnum = 0;
@@ -510,15 +512,38 @@ enum ec_error_list charger_get_vbus_voltage(int port, int *voltage)
if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
- return 0;
+ return -1;
}
+ return chgnum;
+}
+
+enum ec_error_list charger_get_vbus_voltage(int port, int *voltage)
+{
+ int chgnum = charger_get_valid_chgnum(port);
+
+ if (chgnum < 0)
+ return EC_ERROR_INVAL;
+
if (!chg_chips[chgnum].drv->get_vbus_voltage)
return EC_ERROR_UNIMPLEMENTED;
return chg_chips[chgnum].drv->get_vbus_voltage(chgnum, port, voltage);
}
+enum ec_error_list charger_get_vsys_voltage(int port, int *voltage)
+{
+ int chgnum = charger_get_valid_chgnum(port);
+
+ if (chgnum < 0)
+ return EC_ERROR_INVAL;
+
+ if (!chg_chips[chgnum].drv->get_vsys_voltage)
+ return EC_ERROR_UNIMPLEMENTED;
+
+ return chg_chips[chgnum].drv->get_vsys_voltage(chgnum, port, voltage);
+}
+
enum ec_error_list charger_set_input_current_limit(int chgnum,
int input_current)
{
@@ -644,12 +669,16 @@ enum ec_error_list charger_set_hw_ramp(int enable)
if (enable) {
/* Check if this is the active chg chip. */
if (chgnum == charge_get_active_chg_chip())
- rv = chg_chips[chgnum].drv->set_hw_ramp(chgnum, 1);
- /* This is not the active chg chip, disable hw_ramp. */
+ rv = chg_chips[chgnum].drv->set_hw_ramp(
+ chgnum, 1);
+ /* This is not the active chg chip, disable
+ * hw_ramp. */
else
- rv = chg_chips[chgnum].drv->set_hw_ramp(chgnum, 0);
+ rv = chg_chips[chgnum].drv->set_hw_ramp(
+ chgnum, 0);
} else
- rv = chg_chips[chgnum].drv->set_hw_ramp(chgnum, 0);
+ rv = chg_chips[chgnum].drv->set_hw_ramp(chgnum,
+ 0);
}
}
@@ -705,8 +734,7 @@ int chg_ramp_get_current_limit(void)
enum ec_error_list charger_set_vsys_compensation(int chgnum,
struct ocpc_data *ocpc,
- int current_ma,
- int voltage_mv)
+ int current_ma, int voltage_mv)
{
if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
@@ -726,7 +754,7 @@ enum ec_error_list charger_set_vsys_compensation(int chgnum,
enum ec_error_list charger_is_icl_reached(int chgnum, bool *reached)
{
- if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -750,3 +778,10 @@ enum ec_error_list charger_enable_linear_charge(int chgnum, bool enable)
return EC_ERROR_UNIMPLEMENTED;
}
+
+#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
+inline int charger_get_min_bat_pct_for_power_on(void)
+{
+ return CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON;
+}
+#endif
diff --git a/common/charger_profile_override.c b/common/charger_profile_override.c
index 2b691b9a5a..00aaa2b5bd 100644
--- a/common/charger_profile_override.c
+++ b/common/charger_profile_override.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -20,17 +20,17 @@ static int test_vtg_mV = -1;
static int fast_charging_allowed = 1;
-int charger_profile_override_common(struct charge_state_data *curr,
- const struct fast_charge_params *fast_chg_params,
- const struct fast_charge_profile **prev_chg_prof_info,
- int batt_vtg_max)
+int charger_profile_override_common(
+ struct charge_state_data *curr,
+ const struct fast_charge_params *fast_chg_params,
+ const struct fast_charge_profile **prev_chg_prof_info, int batt_vtg_max)
{
int i, voltage_range;
/* temp in 0.1 deg C */
int temp_c = curr->batt.temperature - 2731;
int temp_ranges = fast_chg_params->total_temp_ranges;
const struct fast_charge_profile *chg_profile_info =
- fast_chg_params->chg_profile_info;
+ fast_chg_params->chg_profile_info;
#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
if (fast_charge_test_on && test_vtg_mV != -1) {
@@ -78,9 +78,9 @@ int charger_profile_override_common(struct charge_state_data *curr,
if (!(curr->batt.flags & BATT_FLAG_BAD_VOLTAGE)) {
for (i = 0; i < CONFIG_CHARGER_PROFILE_VOLTAGE_RANGES - 1;
- i++) {
+ i++) {
if (curr->batt.voltage <
- fast_chg_params->voltage_mV[i]) {
+ fast_chg_params->voltage_mV[i]) {
voltage_range = i;
break;
}
@@ -98,13 +98,13 @@ int charger_profile_override_common(struct charge_state_data *curr,
* Okay, impose our custom will:
*/
curr->requested_current =
- (*prev_chg_prof_info)->current_mA[voltage_range];
+ (*prev_chg_prof_info)->current_mA[voltage_range];
curr->requested_voltage = curr->requested_current ? batt_vtg_max : 0;
#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
if (fast_charge_test_on)
ccprintf("Fast charge profile i=%dmA, v=%dmV\n",
- curr->requested_current, curr->requested_voltage);
+ curr->requested_current, curr->requested_voltage);
#endif
return 0;
@@ -134,7 +134,7 @@ enum ec_status charger_profile_override_set_param(uint32_t param,
}
#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE
-static int command_fastcharge(int argc, char **argv)
+static int command_fastcharge(int argc, const char **argv)
{
if (argc > 1 && !parse_bool(argv[1], &fast_charging_allowed))
return EC_ERROR_PARAM1;
@@ -143,8 +143,7 @@ static int command_fastcharge(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
- "[on|off]",
+DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge, "[on|off]",
"Get or set fast charging profile");
#endif
@@ -153,7 +152,7 @@ DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
* fast charging profile is selected.
*/
#ifdef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE_TEST
-static int command_fastcharge_test(int argc, char **argv)
+static int command_fastcharge_test(int argc, const char **argv)
{
char *e;
int test_on;
diff --git a/common/chargesplash.c b/common/chargesplash.c
index 88bc6a63f1..17da9a5c8c 100644
--- a/common/chargesplash.c
+++ b/common/chargesplash.c
@@ -1,4 +1,4 @@
-/* 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.
*/
@@ -171,7 +171,7 @@ static void handle_chipset_shutdown(void)
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, handle_chipset_shutdown, HOOK_PRIO_DEFAULT);
-static int command_chargesplash(int argc, char **argv)
+static int command_chargesplash(int argc, const char **argv)
{
if (argc != 2) {
return EC_ERROR_PARAM_COUNT;
diff --git a/common/chipset.c b/common/chipset.c
index 61478f184a..55964e4ba9 100644
--- a/common/chipset.c
+++ b/common/chipset.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -18,30 +18,27 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CHIPSET, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ##args)
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_POWER_AP
-static int command_apreset(int argc, char **argv)
+static int command_apreset(int argc, const char **argv)
{
/* Force the chipset to reset */
ccprintf("Issuing AP reset...\n");
chipset_reset(CHIPSET_RESET_CONSOLE_CMD);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(apreset, command_apreset,
- NULL,
- "Issue AP reset");
+DECLARE_CONSOLE_COMMAND(apreset, command_apreset, NULL, "Issue AP reset");
-static int command_apshutdown(int argc, char **argv)
+static int command_apshutdown(int argc, const char **argv)
{
chipset_force_shutdown(CHIPSET_SHUTDOWN_CONSOLE_CMD);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(apshutdown, command_apshutdown,
- NULL,
+DECLARE_CONSOLE_COMMAND(apshutdown, command_apshutdown, NULL,
"Force AP shutdown");
#endif
@@ -53,9 +50,7 @@ static enum ec_status host_command_apreset(struct host_cmd_handler_args *args)
chipset_reset(CHIPSET_RESET_HOST_CMD);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_AP_RESET,
- host_command_apreset,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_AP_RESET, host_command_apreset, EC_VER_MASK(0));
#endif
@@ -64,8 +59,7 @@ K_MUTEX_DEFINE(reset_log_mutex);
static int next_reset_log __preserved_logs(next_reset_log);
static uint32_t ap_resets_since_ec_boot;
/* keep reset_logs size a power of 2 */
-static struct ap_reset_log_entry
- reset_logs[4] __preserved_logs(reset_logs);
+static struct ap_reset_log_entry reset_logs[4] __preserved_logs(reset_logs);
static int reset_log_checksum __preserved_logs(reset_log_checksum);
/* Calculate reset log checksum */
@@ -113,11 +107,10 @@ get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
mutex_lock(&reset_log_mutex);
*resets_since_ec_boot = ap_resets_since_ec_boot;
- for (i = 0;
- i != ARRAY_SIZE(reset_logs) && i != num_reset_log_entries;
+ for (i = 0; i != ARRAY_SIZE(reset_logs) && i != num_reset_log_entries;
++i) {
log_address = (next_reset_log + i) &
- (ARRAY_SIZE(reset_logs) - 1);
+ (ARRAY_SIZE(reset_logs) - 1);
reset_log_entries[i] = reset_logs[log_address];
}
mutex_unlock(&reset_log_mutex);
@@ -125,4 +118,19 @@ get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
return EC_SUCCESS;
}
-#endif /* !CONFIG_AP_RESET_LOG */
+enum chipset_shutdown_reason chipset_get_shutdown_reason(void)
+{
+ enum chipset_shutdown_reason reason = CHIPSET_RESET_UNKNOWN;
+
+ mutex_lock(&reset_log_mutex);
+ if (ap_resets_since_ec_boot != 0) {
+ int i = (next_reset_log == 0) ? ARRAY_SIZE(reset_logs) - 1 :
+ next_reset_log - 1;
+ reason = reset_logs[i].reset_cause;
+ }
+ mutex_unlock(&reset_log_mutex);
+
+ return reason;
+}
+
+#endif /* !CONFIG_AP_RESET_LOG */
diff --git a/common/clz.c b/common/clz.c
index b0b58e76a0..178c44d345 100644
--- a/common/clz.c
+++ b/common/clz.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 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/common/console.c b/common/console.c
index dc0d2655c0..9e7d6ad036 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -52,14 +52,14 @@ static int last_rx_was_cr;
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
/* State of input escape code */
static enum {
- ESC_OUTSIDE, /* Not in escape code */
- ESC_START, /* Got ESC */
- ESC_BAD, /* Bad escape sequence */
- ESC_BRACKET, /* Got ESC [ */
+ ESC_OUTSIDE, /* Not in escape code */
+ ESC_START, /* Got ESC */
+ ESC_BAD, /* Bad escape sequence */
+ ESC_BRACKET, /* Got ESC [ */
ESC_BRACKET_1, /* Got ESC [ 1 */
ESC_BRACKET_3, /* Got ESC [ 3 */
ESC_BRACKET_4, /* Got ESC [ 4 */
- ESC_O, /* Got ESC O */
+ ESC_O, /* Got ESC O */
} esc_state;
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
@@ -85,7 +85,7 @@ enum extended_key_code {
* @return EC_SUCCESS. If more than MAX_ARGS_PER_COMMAND words are found,
* discards the excess and returns EC_ERROR_OVERFLOW.
*/
-static int split_words(char *input, int *argc, char **argv)
+static int split_words(char *input, int *argc, const char **argv)
{
char *c;
int in_word = 0;
@@ -129,7 +129,7 @@ static int split_words(char *input, int *argc, char **argv)
*
* @return A pointer to the command structure, or NULL if no match found.
*/
-static const struct console_command *find_command(char *name)
+static const struct console_command *find_command(const char *name)
{
const struct console_command *cmd, *match = NULL;
int match_length = strlen(name);
@@ -151,18 +151,10 @@ static const struct console_command *find_command(char *name)
return match;
}
-
static const char *const errmsgs[] = {
- "OK",
- "Unknown error",
- "Unimplemented",
- "Overflow",
- "Timeout",
- "Invalid argument",
- "Busy",
- "Access Denied",
- "Not Powered",
- "Not Calibrated",
+ "OK", "Unknown error", "Unimplemented", "Overflow",
+ "Timeout", "Invalid argument", "Busy", "Access Denied",
+ "Not Powered", "Not Calibrated",
};
/**
@@ -175,7 +167,7 @@ static const char *const errmsgs[] = {
static int handle_command(char *input)
{
const struct console_command *cmd;
- char *argv[MAX_ARGS_PER_COMMAND];
+ const char *argv[MAX_ARGS_PER_COMMAND];
int argc = 0;
int rv;
#ifdef CONFIG_EXPERIMENTAL_CONSOLE
@@ -205,10 +197,10 @@ static int handle_command(char *input)
i = input[1] == '&' ? 2 : 1;
/* Next, there should be 4 hex digits: XXYY + '&' */
- if (i+5 > input_len)
+ if (i + 5 > input_len)
goto command_has_error;
/* Replace the '&' with null so we can call strtoi(). */
- input[i+4] = 0;
+ input[i + 4] = 0;
j = strtoi(input + i, &e, 16);
if (*e)
goto command_has_error;
@@ -218,10 +210,10 @@ static int handle_command(char *input)
i += 5;
/* Lastly, verify the CRC8 of the command. */
- if (i+command_len > input_len)
+ if (i + command_len > input_len)
goto command_has_error;
if (packed_crc8 != cros_crc8(&input[i], command_len)) {
-command_has_error:
+ command_has_error:
/* Send back the error string. */
ccprintf("&&EE\n");
return EC_ERROR_UNKNOWN;
@@ -248,7 +240,7 @@ command_has_error:
rv = EC_ERROR_ACCESS_DENIED;
else
#endif
- rv = cmd->handler(argc, argv);
+ rv = cmd->handler(argc, argv);
if (rv == EC_SUCCESS)
return rv;
@@ -372,7 +364,7 @@ static void save_history(void)
static void handle_backspace(void)
{
if (!input_pos)
- return; /* Already at beginning of line */
+ return; /* Already at beginning of line */
/* Move cursor back */
console_putc('\b');
@@ -380,8 +372,7 @@ static void handle_backspace(void)
/* Print and move anything following the cursor position */
if (input_pos != input_len) {
ccputs(input_buf + input_pos);
- memmove(input_buf + input_pos - 1,
- input_buf + input_pos,
+ memmove(input_buf + input_pos - 1, input_buf + input_pos,
input_len - input_pos + 1);
} else {
input_buf[input_len - 1] = '\0';
@@ -511,7 +502,7 @@ static void console_handle_char(int c)
#ifndef CONFIG_EXPERIMENTAL_CONSOLE
case KEY_DEL:
if (input_pos == input_len)
- break; /* Already at end */
+ break; /* Already at end */
move_cursor_right();
@@ -544,8 +535,8 @@ static void console_handle_char(int c)
/* Save command in history buffer */
if (input_len) {
save_history();
- history_next = (history_next + 1) %
- CONFIG_CONSOLE_HISTORY;
+ history_next =
+ (history_next + 1) % CONFIG_CONSOLE_HISTORY;
history_pos = history_next;
}
#endif
@@ -692,7 +683,7 @@ void console_task(void *u)
console_handle_char(c);
}
- task_wait_event(-1); /* Wait for more input */
+ task_wait_event(-1); /* Wait for more input */
}
}
@@ -700,10 +691,10 @@ void console_task(void *u)
/* Console commands */
/* Command handler - prints help. */
-static int command_help(int argc, char **argv)
+static int command_help(int argc, const char **argv)
{
const int ncmds = __cmds_end - __cmds;
- const int cols = 5; /* printing in five columns */
+ const int cols = 5; /* printing in five columns */
const int rows = (ncmds + cols - 1) / cols;
int i, j;
@@ -715,16 +706,15 @@ static int command_help(int argc, char **argv)
#ifdef CONFIG_CONSOLE_COMMAND_FLAGS
ccputs("Command Flags Description\n");
for (i = 0; i < ncmds; i++) {
- ccprintf(" %-14s %x %s\n",
- __cmds[i].name, __cmds[i].flags,
- __cmds[i].help);
+ ccprintf(" %-14s %x %s\n", __cmds[i].name,
+ __cmds[i].flags, __cmds[i].help);
cflush();
}
#else
ccputs("Known commands:\n");
for (i = 0; i < ncmds; i++) {
- ccprintf(" %-15s%s\n",
- __cmds[i].name, __cmds[i].help);
+ ccprintf(" %-15s%s\n", __cmds[i].name,
+ __cmds[i].help);
cflush();
}
#endif
@@ -771,12 +761,11 @@ static int command_help(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(help, command_help,
- "[ list | <name> ]",
+DECLARE_SAFE_CONSOLE_COMMAND(help, command_help, "[ list | <name> ]",
"Print command help");
#ifdef CONFIG_CONSOLE_HISTORY
-static int command_history(int argc, char **argv)
+static int command_history(int argc, const char **argv)
{
int i;
@@ -788,7 +777,6 @@ static int command_history(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(history, command_history,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(history, command_history, NULL,
"Print console history");
#endif
diff --git a/common/console_output.c b/common/console_output.c
index 33b1466181..24bdb5aa3a 100644
--- a/common/console_output.c
+++ b/common/console_output.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
/* Console output module for Chrome EC */
#include "console.h"
+#include "printf.h"
#include "uart.h"
#include "usb_console.h"
#include "util.h"
@@ -27,14 +28,14 @@ static uint32_t channel_mask_saved = CC_DEFAULT;
* might also become more important if we have >32 channels - for example, if
* we decide to replace enum console_channel with enum module_id.
*/
-static const char * const channel_names[] = {
- #define CONSOLE_CHANNEL(enumeration, string) string,
- #include "console_channel.inc"
- #undef CONSOLE_CHANNEL
+static const char *const channel_names[] = {
+#define CONSOLE_CHANNEL(enumeration, string) string,
+#include "console_channel.inc"
+#undef CONSOLE_CHANNEL
};
BUILD_ASSERT(ARRAY_SIZE(channel_names) == CC_CHANNEL_COUNT);
/* ensure that we are not silently masking additional channels */
-BUILD_ASSERT(CC_CHANNEL_COUNT <= 8*sizeof(uint32_t));
+BUILD_ASSERT(CC_CHANNEL_COUNT <= 8 * sizeof(uint32_t));
static int console_channel_name_to_index(const char *name)
{
@@ -114,12 +115,14 @@ int cprints(enum console_channel channel, const char *format, ...)
{
int r, rv;
va_list args;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
/* Filter out inactive channels */
if (console_channel_is_disabled(channel))
return EC_SUCCESS;
- rv = cprintf(channel, "[%pT ", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ rv = cprintf(channel, "[%s ", ts_str);
va_start(args, format);
r = uart_vprintf(format, args);
@@ -148,7 +151,7 @@ void cflush(void)
#ifdef CONFIG_CONSOLE_CHANNEL
/* Set active channels */
-static int command_ch(int argc, char **argv)
+static int command_ch(int argc, const char **argv)
{
int i;
char *e;
@@ -178,15 +181,13 @@ static int command_ch(int argc, char **argv)
/* Print the list of channels */
ccputs(" # Mask E Channel\n");
for (i = 0; i < CC_CHANNEL_COUNT; i++) {
- ccprintf("%2d %08x %c %s\n",
- i, CC_MASK(i),
+ ccprintf("%2d %08x %c %s\n", i, CC_MASK(i),
(channel_mask & CC_MASK(i)) ? '*' : ' ',
channel_names[i]);
cflush();
}
return EC_SUCCESS;
};
-DECLARE_SAFE_CONSOLE_COMMAND(chan, command_ch,
- "[ save | restore | <mask> ]",
+DECLARE_SAFE_CONSOLE_COMMAND(chan, command_ch, "[ save | restore | <mask> ]",
"Save, restore, get or set console channel mask");
#endif /* CONFIG_CONSOLE_CHANNEL */
diff --git a/common/crc.c b/common/crc.c
index 8b45150b67..a53cf91d47 100644
--- a/common/crc.c
+++ b/common/crc.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 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/common/crc8.c b/common/crc8.c
index 8098fa74eb..0aba3e80a3 100644
--- a/common/crc8.c
+++ b/common/crc8.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 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/common/ctz.c b/common/ctz.c
index bb6f69624e..ad144225f0 100644
--- a/common/ctz.c
+++ b/common/ctz.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -20,8 +20,8 @@
int __keep __ctzsi2(int x)
{
static const uint8_t MulDeBruijnBitPos[32] = {
- 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
- 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
+ 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+ 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
return MulDeBruijnBitPos[((uint32_t)((x & -x) * 0x077CB531U)) >> 27];
}
diff --git a/common/device_event.c b/common/device_event.c
index 748a98ae8f..b9e1bafc69 100644
--- a/common/device_event.c
+++ b/common/device_event.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -15,7 +15,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_EVENTS, outstr)
-#define CPRINTS(format, args...) cprints(CC_EVENTS, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_EVENTS, format, ##args)
static atomic_t device_current_events;
static atomic_t device_enabled_events;
@@ -87,7 +87,7 @@ void device_enable_event(enum ec_device_event event)
/* Console commands */
#ifdef CONFIG_CMD_DEVICE_EVENT
-static int command_device_event(int argc, char **argv)
+static int command_device_event(int argc, const char **argv)
{
/* Handle sub-commands */
if (argc == 3) {
diff --git a/common/device_state.c b/common/device_state.c
index 0ba94d6115..1739a9beb2 100644
--- a/common/device_state.c
+++ b/common/device_state.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,7 +7,7 @@
#include "device_state.h"
#include "hooks.h"
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
/**
* Return text description for a state
@@ -17,8 +17,9 @@
*/
static const char *state_desc(enum device_state state)
{
- return state == DEVICE_STATE_ON ? "on" :
- state == DEVICE_STATE_OFF ? "off" : "unknown";
+ return state == DEVICE_STATE_ON ? "on" :
+ state == DEVICE_STATE_OFF ? "off" :
+ "unknown";
}
enum device_state device_get_state(enum device_type device)
@@ -65,7 +66,7 @@ static void check_device_state(void)
}
DECLARE_HOOK(HOOK_SECOND, check_device_state, HOOK_PRIO_DEFAULT);
-static int command_devices(int argc, char **argv)
+static int command_devices(int argc, const char **argv)
{
const struct device_config *dc = device_states;
int i;
@@ -78,6 +79,5 @@ static int command_devices(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(devices, command_devices,
- "",
+DECLARE_SAFE_CONSOLE_COMMAND(devices, command_devices, "",
"Get the device states");
diff --git a/common/dps.c b/common/dps.c
index 3af25e6280..13f551a95d 100644
--- a/common/dps.c
+++ b/common/dps.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.
*
@@ -7,15 +7,14 @@
#include <stdint.h>
-#include "adc.h"
#include "dps.h"
#include "atomic.h"
#include "battery.h"
+#include "common.h"
#include "console.h"
#include "charger.h"
#include "charge_manager.h"
#include "charge_state.h"
-#include "charge_state_v2.h"
#include "ec_commands.h"
#include "math_util.h"
#include "task.h"
@@ -23,8 +22,6 @@
#include "usb_common.h"
#include "usb_pd.h"
#include "util.h"
-#include "usb_pe_sm.h"
-
#define K_MORE_PWR 96
#define K_LESS_PWR 93
@@ -33,17 +30,16 @@
#define T_REQUEST_STABLE_TIME (10 * SECOND)
#define T_NEXT_CHECK_TIME (5 * SECOND)
-#define DPS_FLAG_DISABLED BIT(0)
-#define DPS_FLAG_NO_SRCCAP BIT(1)
-#define DPS_FLAG_WAITING BIT(2)
-#define DPS_FLAG_SAMPLED BIT(3)
-#define DPS_FLAG_NEED_MORE_PWR BIT(4)
+#define DPS_FLAG_DISABLED BIT(0)
+#define DPS_FLAG_NO_SRCCAP BIT(1)
+#define DPS_FLAG_WAITING BIT(2)
+#define DPS_FLAG_SAMPLED BIT(3)
+#define DPS_FLAG_NEED_MORE_PWR BIT(4)
-#define DPS_FLAG_STOP_EVENTS (DPS_FLAG_DISABLED | \
- DPS_FLAG_NO_SRCCAP)
-#define DPS_FLAG_ALL GENMASK(31, 0)
+#define DPS_FLAG_STOP_EVENTS (DPS_FLAG_DISABLED | DPS_FLAG_NO_SRCCAP)
+#define DPS_FLAG_ALL GENMASK(31, 0)
-#define MAX_MOVING_AVG_WINDOW 5
+#define MAX_MOVING_AVG_WINDOW 5
BUILD_ASSERT(K_MORE_PWR > K_LESS_PWR && 100 >= K_MORE_PWR && 100 >= K_LESS_PWR);
@@ -71,6 +67,11 @@ __overridable struct dps_config_t dps_config = {
.is_more_efficient = NULL,
};
+__test_only struct dps_config_t *dps_get_config(void)
+{
+ return &dps_config;
+}
+
int dps_get_dynamic_voltage(void)
{
return dynamic_mv;
@@ -86,14 +87,15 @@ bool dps_is_enabled(void)
return is_enabled;
}
-static void dps_enable(bool en)
+test_export_static void dps_enable(bool en)
{
bool prev_en = is_enabled;
is_enabled = en;
- if (is_enabled && !prev_en)
+ if (is_enabled && !prev_en) {
task_wake(TASK_ID_DPS);
+ }
if (!is_enabled) {
/* issue a new PD request for a default voltage */
@@ -126,22 +128,24 @@ static void dps_reset(void)
/*
* DPS initialization.
*/
-static void dps_init(void)
+test_export_static int dps_init(void)
{
+ int rc = EC_SUCCESS;
+
dps_reset();
if (dps_config.k_window > MAX_MOVING_AVG_WINDOW) {
- dps_config.k_window = MAX_MOVING_AVG_WINDOW;
CPRINTS("ERR:WIN");
+ rc = EC_ERROR_INVALID_CONFIG;
}
- if (dps_config.k_less_pwr > 100 ||
- dps_config.k_more_pwr > 100 ||
+ if (dps_config.k_less_pwr > 100 || dps_config.k_more_pwr > 100 ||
dps_config.k_more_pwr <= dps_config.k_less_pwr) {
- dps_config.k_less_pwr = K_LESS_PWR;
- dps_config.k_more_pwr = K_MORE_PWR;
CPRINTS("ERR:COEF");
+ rc = EC_ERROR_INVALID_CONFIG;
}
+
+ return rc;
}
static bool is_near_limit(int val, int limit)
@@ -197,6 +201,26 @@ static int get_desired_input_power(int *vbus, int *input_current)
return (*vbus) * (*input_current) / 1000;
}
+static int get_battery_target_voltage(int *target_mv)
+{
+ int charger_id = charge_get_active_chg_chip();
+ int error = charger_get_voltage(charger_id, target_mv);
+
+ if (!error) {
+ return EC_SUCCESS;
+ }
+ if (error != EC_ERROR_UNIMPLEMENTED) {
+ CPRINTS("Failed to get voltage for charge port %d: %d",
+ charger_id, error);
+ return error;
+ }
+ /*
+ * Fall back to battery design voltage if charger output voltage
+ * is not available.
+ */
+ return battery_design_voltage(target_mv);
+}
+
/*
* Get the most efficient PDO voltage for the battery of the charging port
*
@@ -224,7 +248,7 @@ int get_efficient_voltage(void)
if (!input_pwr)
return 0;
- if (battery_design_voltage(&batt_mv))
+ if (get_battery_target_voltage(&batt_mv))
return 0;
batt_pwr = batt->current * batt->voltage / 1000;
@@ -258,16 +282,16 @@ struct pdo_candidate {
};
#define UPDATE_CANDIDATE(new_port, new_mv, new_mw) \
- do { \
- cand->port = new_port; \
- cand->mv = new_mv; \
- cand->mw = new_mw; \
+ do { \
+ cand->port = new_port; \
+ cand->mv = new_mv; \
+ cand->mw = new_mw; \
} while (0)
-#define CLEAR_AND_RETURN() \
- do { \
+#define CLEAR_AND_RETURN() \
+ do { \
moving_avg_count = 0; \
- return false; \
+ return false; \
} while (0)
/*
@@ -276,7 +300,7 @@ struct pdo_candidate {
* @param struct pdo_candidate: The candidate PDO. (Return value)
* @return true if a new power request, or false otherwise.
*/
-static bool has_new_power_request(struct pdo_candidate *cand)
+__maybe_unused static bool has_new_power_request(struct pdo_candidate *cand)
{
int vbus, input_curr, input_pwr;
int input_pwr_avg = 0, input_curr_avg = 0;
@@ -305,7 +329,7 @@ static bool has_new_power_request(struct pdo_candidate *cand)
if (!req_mv)
CLEAR_AND_RETURN();
- if (battery_design_voltage(&batt_mv))
+ if (get_battery_target_voltage(&batt_mv))
CLEAR_AND_RETURN();
/* if last sample is not the same as the current one, reset counting. */
@@ -360,7 +384,7 @@ static bool has_new_power_request(struct pdo_candidate *cand)
input_curr, input_pwr_avg, input_curr_avg);
for (int i = 0; i < board_get_usb_pd_port_count(); ++i) {
- const uint32_t * const src_caps = pd_get_src_caps(i);
+ const uint32_t *const src_caps = pd_get_src_caps(i);
/* If the port is not SNK, skip evaluating this port. */
if (pd_get_power_role(i) != PD_ROLE_SINK)
@@ -380,7 +404,7 @@ static bool has_new_power_request(struct pdo_candidate *cand)
if (mv > max_mv)
continue;
- mw = ma * mv / 1000;
+ mw = MIN(ma, PD_MAX_CURRENT_MA) * mv / 1000;
efficient = is_more_efficient(mv, cand->mv, batt_mv,
batt_pwr, input_pwr_avg);
@@ -419,7 +443,6 @@ static bool has_new_power_request(struct pdo_candidate *cand)
}
}
-
/*
* if the candidate is the same as the current one, pick
* the one at active charge port.
@@ -436,7 +459,7 @@ static bool has_new_power_request(struct pdo_candidate *cand)
return (cand->mv != req_mv);
}
-static bool has_srccap(void)
+__maybe_unused static bool has_srccap(void)
{
for (int i = 0; i < board_get_usb_pd_port_count(); ++i) {
if (pd_is_connected(i) &&
@@ -454,14 +477,20 @@ void dps_update_stabilized_time(int port)
void dps_task(void *u)
{
- struct pdo_candidate last_cand = {CHARGE_PORT_NONE, 0, 0};
+ struct pdo_candidate last_cand = { CHARGE_PORT_NONE, 0, 0 };
int sample_count = 0;
+ int rv;
+
+ rv = dps_init();
+ if (rv) {
+ CPRINTS("ERR:INIT%d", rv);
+ return;
+ }
- dps_init();
update_timeout(dps_config.t_check);
while (1) {
- struct pdo_candidate curr_cand = {CHARGE_PORT_NONE, 0, 0};
+ struct pdo_candidate curr_cand = { CHARGE_PORT_NONE, 0, 0 };
timestamp_t now;
now = get_time();
@@ -505,8 +534,7 @@ void dps_task(void *u)
if (sample_count == dps_config.k_sample) {
dynamic_mv = curr_cand.mv;
dps_port = curr_cand.port;
- pd_dpm_request(dps_port,
- DPM_REQUEST_NEW_POWER_LEVEL);
+ pd_dpm_request(dps_port, DPM_REQUEST_NEW_POWER_LEVEL);
sample_count = 0;
flag &= ~(DPS_FLAG_SAMPLED | DPS_FLAG_NEED_MORE_PWR);
}
@@ -519,7 +547,7 @@ void dps_task(void *u)
}
}
-static int command_dps(int argc, char **argv)
+static int command_dps(int argc, const char **argv)
{
int port = charge_manager_get_active_charge_port();
int input_pwr, vbus, input_curr;
@@ -545,7 +573,7 @@ static int command_dps(int argc, char **argv)
return EC_SUCCESS;
}
- battery_design_voltage(&batt_mv);
+ get_battery_target_voltage(&batt_mv);
input_pwr = get_desired_input_power(&vbus, &input_curr);
if (!(flag & DPS_FLAG_NO_SRCCAP)) {
last_mv = pd_get_requested_voltage(port);
@@ -557,10 +585,8 @@ static int command_dps(int argc, char **argv)
"Efficient: %dmV\n"
"Batt: %dmv\n"
"PDMaxMV: %dmV\n",
- port, last_mv, last_ma,
- vbus, input_curr, input_pwr,
- get_efficient_voltage(),
- batt_mv,
+ port, last_mv, last_ma, vbus, input_curr, input_pwr,
+ get_efficient_voltage(), batt_mv,
pd_get_max_voltage());
return EC_SUCCESS;
}
@@ -657,6 +683,24 @@ static enum ec_status hc_usb_pd_dps_control(struct host_cmd_handler_args *args)
dps_enable(p->enable);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_DPS_CONTROL,
- hc_usb_pd_dps_control,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_DPS_CONTROL, hc_usb_pd_dps_control,
EC_VER_MASK(0));
+
+#ifdef TEST_BUILD
+__test_only bool dps_is_fake_enabled(void)
+{
+ return fake_enabled;
+}
+__test_only int dps_get_fake_mv(void)
+{
+ return fake_mv;
+}
+__test_only int dps_get_fake_ma(void)
+{
+ return fake_ma;
+}
+__test_only int *dps_get_debug_level(void)
+{
+ return &debug_level;
+}
+#endif /* TEST_BUILD */
diff --git a/common/dptf.c b/common/dptf.c
index 28ccff34f2..003ac9f32c 100644
--- a/common/dptf.c
+++ b/common/dptf.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,14 +19,14 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_DPTF, outstr)
-#define CPRINTS(format, args...) cprints(CC_DPTF, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_DPTF, format, ##args)
/*****************************************************************************/
/* DPTF temperature thresholds */
static struct {
- int temp; /* degrees K, negative for disabled */
- cond_t over; /* watch for crossings */
+ int temp; /* degrees K, negative for disabled */
+ cond_t over; /* watch for crossings */
} dptf_threshold[TEMP_SENSOR_COUNT][DPTF_THRESHOLDS_PER_SENSOR];
_STATIC_ASSERT(TEMP_SENSOR_COUNT > 0,
"CONFIG_PLATFORM_EC_DPTF enabled, but no temp sensors");
@@ -40,7 +40,6 @@ static void dptf_init(void)
dptf_threshold[id][t].temp = -1;
cond_init(&dptf_threshold[id][t].over, 0);
}
-
}
DECLARE_HOOK(HOOK_INIT, dptf_init, HOOK_PRIO_DEFAULT);
@@ -72,9 +71,8 @@ static int dptf_check_temp_threshold(int sensor_id, int temp)
}
for (i = 0; i < DPTF_THRESHOLDS_PER_SENSOR; i++) {
-
max = dptf_threshold[sensor_id][i].temp;
- if (max < 0) /* disabled? */
+ if (max < 0) /* disabled? */
continue;
if (temp >= max)
@@ -83,14 +81,12 @@ static int dptf_check_temp_threshold(int sensor_id, int temp)
cond_set_false(&dptf_threshold[sensor_id][i].over);
if (cond_went_true(&dptf_threshold[sensor_id][i].over)) {
- CPRINTS("DPTF over threshold [%d][%d",
- sensor_id, i);
+ CPRINTS("DPTF over threshold [%d][%d", sensor_id, i);
atomic_or(&dptf_seen, BIT(sensor_id));
tripped = 1;
}
if (cond_went_false(&dptf_threshold[sensor_id][i].over)) {
- CPRINTS("DPTF under threshold [%d][%d",
- sensor_id, i);
+ CPRINTS("DPTF under threshold [%d][%d", sensor_id, i);
atomic_or(&dptf_seen, BIT(sensor_id));
tripped = 1;
}
@@ -101,8 +97,8 @@ static int dptf_check_temp_threshold(int sensor_id, int temp)
void dptf_set_temp_threshold(int sensor_id, int temp, int idx, int enable)
{
- CPRINTS("DPTF sensor %d, threshold %d C, index %d, %sabled",
- sensor_id, K_TO_C(temp), idx, enable ? "en" : "dis");
+ CPRINTS("DPTF sensor %d, threshold %d C, index %d, %sabled", sensor_id,
+ K_TO_C(temp), idx, enable ? "en" : "dis");
if ((sensor_id >= TEMP_SENSOR_COUNT) ||
(idx >= DPTF_THRESHOLDS_PER_SENSOR)) {
@@ -178,7 +174,7 @@ DECLARE_HOOK(HOOK_SECOND, thermal_control_dptf, HOOK_PRIO_TEMP_SENSOR_DONE);
/*****************************************************************************/
/* Console commands */
-static int command_dptftemp(int argc, char **argv)
+static int command_dptftemp(int argc, const char **argv)
{
int id, t;
int temp, trig;
@@ -201,6 +197,5 @@ static int command_dptftemp(int argc, char **argv)
ccprintf("AP seen mask: 0x%08x\n", (int)dptf_seen);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(dptftemp, command_dptftemp,
- NULL,
+DECLARE_CONSOLE_COMMAND(dptftemp, command_dptftemp, NULL,
"Print DPTF thermal parameters (degrees Kelvin)");
diff --git a/common/ec.libsharedobjs.ld b/common/ec.libsharedobjs.ld
index adf5081640..57b67daecc 100644
--- a/common/ec.libsharedobjs.ld
+++ b/common/ec.libsharedobjs.ld
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 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/common/ec_ec_comm_client.c b/common/ec_ec_comm_client.c
index b2f2387976..193d121343 100644
--- a/common/ec_ec_comm_client.c
+++ b/common/ec_ec_comm_client.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -16,7 +16,7 @@
#include "util.h"
/* Console output macros */
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
/*
* TODO(b:65697962): The packed structures below do not play well if we force EC
@@ -97,9 +97,8 @@ struct {
* - EC_ERROR_INVAL when the received header is invalid.
* - EC_ERROR_UNKNOWN on other error.
*/
-static int write_command(uint16_t command,
- uint8_t *data, int req_len, int resp_len,
- int timeout_us)
+static int write_command(uint16_t command, uint8_t *data, int req_len,
+ int resp_len, int timeout_us)
{
/* Sequence number. */
static uint8_t cur_seq;
@@ -111,11 +110,10 @@ static int write_command(uint16_t command,
int tx_length =
sizeof(*request_header) + ((req_len > 0) ? (req_len + 1) : 0);
- struct ec_host_response4 *response_header =
- (void *)&data[tx_length];
+ struct ec_host_response4 *response_header = (void *)&data[tx_length];
/* RX length is TX length + response from server. */
- int rx_length = tx_length +
- sizeof(*request_header) + ((resp_len > 0) ? (resp_len + 1) : 0);
+ int rx_length = tx_length + sizeof(*request_header) +
+ ((resp_len > 0) ? (resp_len + 1) : 0);
/*
* Make sure there is a gap between each command, so that the server
@@ -124,7 +122,7 @@ static int write_command(uint16_t command,
* TODO(b:65697962): We can be much smarter than this, and record the
* last transaction time instead of just sleeping blindly.
*/
- usleep(10*MSEC);
+ usleep(10 * MSEC);
#ifdef DEBUG_EC_COMM_STATS
if ((comm_stats.total % 128) == 0) {
@@ -136,26 +134,27 @@ static int write_command(uint16_t command,
#endif
cur_seq = (cur_seq + 1) &
- (EC_PACKET4_0_SEQ_NUM_MASK >> EC_PACKET4_0_SEQ_NUM_SHIFT);
+ (EC_PACKET4_0_SEQ_NUM_MASK >> EC_PACKET4_0_SEQ_NUM_SHIFT);
memset(request_header, 0, sizeof(*request_header));
/* fields0: leave seq_dup and is_response as 0. */
request_header->fields0 =
EC_EC_HOSTCMD_VERSION | /* version */
- (cur_seq << EC_PACKET4_0_SEQ_NUM_SHIFT); /* seq_num */
+ (cur_seq << EC_PACKET4_0_SEQ_NUM_SHIFT); /* seq_num
+ */
/* fields1: leave command_version as 0. */
if (req_len > 0)
request_header->fields1 |= EC_PACKET4_1_DATA_CRC_PRESENT_MASK;
request_header->command = command;
request_header->data_len = req_len;
- request_header->header_crc =
- cros_crc8((uint8_t *)request_header, sizeof(*request_header)-1);
+ request_header->header_crc = cros_crc8((uint8_t *)request_header,
+ sizeof(*request_header) - 1);
if (req_len > 0)
data[sizeof(*request_header) + req_len] =
cros_crc8(&data[sizeof(*request_header)], req_len);
- ret = uart_alt_pad_write_read((void *)data, tx_length,
- (void *)data, rx_length, timeout_us);
+ ret = uart_alt_pad_write_read((void *)data, tx_length, (void *)data,
+ rx_length, timeout_us);
INCR_COMM_STATS(total);
@@ -187,20 +186,19 @@ static int write_command(uint16_t command,
hascrc = response_header->fields1 & EC_PACKET4_1_DATA_CRC_PRESENT_MASK;
response_seq = (response_header->fields0 & EC_PACKET4_0_SEQ_NUM_MASK) >>
- EC_PACKET4_0_SEQ_NUM_SHIFT;
+ EC_PACKET4_0_SEQ_NUM_SHIFT;
/*
* Validate received header.
* Note that we _require_ data crc to be present if there is data to be
* read back, else we would not know how many bytes to read exactly.
*/
- if ((response_header->fields0 & EC_PACKET4_0_STRUCT_VERSION_MASK)
- != EC_EC_HOSTCMD_VERSION ||
- !(response_header->fields0 &
- EC_PACKET4_0_IS_RESPONSE_MASK) ||
- response_seq != cur_seq ||
- (response_header->data_len > 0 && !hascrc) ||
- response_header->data_len != resp_len) {
+ if ((response_header->fields0 & EC_PACKET4_0_STRUCT_VERSION_MASK) !=
+ EC_EC_HOSTCMD_VERSION ||
+ !(response_header->fields0 & EC_PACKET4_0_IS_RESPONSE_MASK) ||
+ response_seq != cur_seq ||
+ (response_header->data_len > 0 && !hascrc) ||
+ response_header->data_len != resp_len) {
INCR_COMM_STATS(errinval);
return EC_ERROR_INVAL;
}
@@ -259,9 +257,9 @@ int ec_ec_client_base_get_dynamic_info(void)
data.req.param.index = 0;
- ret = write_command(EC_CMD_BATTERY_GET_DYNAMIC,
- (void *)&data, sizeof(data.req.param),
- sizeof(data.resp.info), 15 * MSEC);
+ ret = write_command(EC_CMD_BATTERY_GET_DYNAMIC, (void *)&data,
+ sizeof(data.req.param), sizeof(data.resp.info),
+ 15 * MSEC);
ret = handle_error(__func__, ret, data.resp.head.result);
if (ret != EC_RES_SUCCESS)
return ret;
@@ -277,7 +275,7 @@ int ec_ec_client_base_get_dynamic_info(void)
#endif
memcpy(&battery_dynamic[BATT_IDX_BASE], &data.resp.info,
- sizeof(battery_dynamic[BATT_IDX_BASE]));
+ sizeof(battery_dynamic[BATT_IDX_BASE]));
return EC_RES_SUCCESS;
}
@@ -301,9 +299,9 @@ int ec_ec_client_base_get_static_info(void)
data.req.param.index = 0;
- ret = write_command(EC_CMD_BATTERY_GET_STATIC,
- (void *)&data, sizeof(data.req.param),
- sizeof(data.resp.info), 15 * MSEC);
+ ret = write_command(EC_CMD_BATTERY_GET_STATIC, (void *)&data,
+ sizeof(data.req.param), sizeof(data.resp.info),
+ 15 * MSEC);
ret = handle_error(__func__, ret, data.resp.head.result);
if (ret != EC_RES_SUCCESS)
return ret;
@@ -330,8 +328,7 @@ int ec_ec_client_base_get_static_info(void)
return EC_RES_SUCCESS;
}
-int ec_ec_client_base_charge_control(int max_current,
- int otg_voltage,
+int ec_ec_client_base_charge_control(int max_current, int otg_voltage,
int allow_charging)
{
int ret;
@@ -350,8 +347,8 @@ int ec_ec_client_base_charge_control(int max_current,
data.req.ctrl.max_current = max_current;
data.req.ctrl.otg_voltage = otg_voltage;
- ret = write_command(EC_CMD_CHARGER_CONTROL,
- (void *)&data, sizeof(data.req.ctrl), 0, 30 * MSEC);
+ ret = write_command(EC_CMD_CHARGER_CONTROL, (void *)&data,
+ sizeof(data.req.ctrl), 0, 30 * MSEC);
return handle_error(__func__, ret, data.resp.head.result);
}
@@ -372,8 +369,8 @@ int ec_ec_client_hibernate(void)
data.req.param.cmd = EC_REBOOT_HIBERNATE;
data.req.param.flags = 0;
- ret = write_command(EC_CMD_REBOOT_EC,
- (void *)&data, sizeof(data.req.param), 0, 30 * MSEC);
+ ret = write_command(EC_CMD_REBOOT_EC, (void *)&data,
+ sizeof(data.req.param), 0, 30 * MSEC);
return handle_error(__func__, ret, data.resp.head.result);
}
diff --git a/common/ec_ec_comm_server.c b/common/ec_ec_comm_server.c
index 23b5fee139..6f37004513 100644
--- a/common/ec_ec_comm_server.c
+++ b/common/ec_ec_comm_server.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -21,8 +21,8 @@
#include "task.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ##args)
/* Print extra debugging information */
#undef EXTRA_DEBUG
@@ -37,11 +37,10 @@ static int charging_allowed;
#define LARGEST_PARAMS_SIZE 8
BUILD_ASSERT(LARGEST_PARAMS_SIZE >=
- sizeof(struct ec_params_battery_static_info));
+ sizeof(struct ec_params_battery_static_info));
BUILD_ASSERT(LARGEST_PARAMS_SIZE >=
- sizeof(struct ec_params_battery_dynamic_info));
-BUILD_ASSERT(LARGEST_PARAMS_SIZE >=
- sizeof(struct ec_params_charger_control));
+ sizeof(struct ec_params_battery_dynamic_info));
+BUILD_ASSERT(LARGEST_PARAMS_SIZE >= sizeof(struct ec_params_charger_control));
#define COMMAND_BUFFER_PARAMS_SIZE (LARGEST_PARAMS_SIZE + 1)
@@ -51,7 +50,6 @@ BUILD_ASSERT(LARGEST_PARAMS_SIZE >=
*/
#define COMMAND_TIMEOUT_US (5 * MSEC)
-
void ec_ec_comm_server_written(struct consumer const *consumer, size_t count)
{
task_wake(TASK_ID_ECCOMM);
@@ -67,7 +65,7 @@ static void discard_queue(void)
{
do {
queue_advance_head(&ec_ec_comm_server_input,
- queue_count(&ec_ec_comm_server_input));
+ queue_count(&ec_ec_comm_server_input));
usleep(1 * MSEC);
} while (queue_count(&ec_ec_comm_server_input) > 0);
}
@@ -78,19 +76,17 @@ static void write_response(uint16_t res, int seq, const void *data, int len)
struct ec_host_response4 header;
uint8_t crc;
- header.fields0 =
- 4 | /* version */
- EC_PACKET4_0_IS_RESPONSE_MASK | /* is_response */
- (seq << EC_PACKET4_0_SEQ_NUM_SHIFT); /* seq_num */
+ header.fields0 = 4 | /* version */
+ EC_PACKET4_0_IS_RESPONSE_MASK | /* is_response */
+ (seq << EC_PACKET4_0_SEQ_NUM_SHIFT); /* seq_num */
/* Set data_crc_present if there is data */
header.fields1 = (len > 0) ? EC_PACKET4_1_DATA_CRC_PRESENT_MASK : 0;
header.result = res;
header.data_len = len;
header.reserved = 0;
- header.header_crc =
- cros_crc8((uint8_t *)&header, sizeof(header)-1);
- QUEUE_ADD_UNITS(&ec_ec_comm_server_output,
- (uint8_t *)&header, sizeof(header));
+ header.header_crc = cros_crc8((uint8_t *)&header, sizeof(header) - 1);
+ QUEUE_ADD_UNITS(&ec_ec_comm_server_output, (uint8_t *)&header,
+ sizeof(header));
if (len > 0) {
QUEUE_ADD_UNITS(&ec_ec_comm_server_output, data, len);
@@ -123,9 +119,8 @@ static int read_data(void *buffer, size_t len, uint32_t start)
return EC_SUCCESS;
}
-static void handle_cmd_reboot_ec(
- const struct ec_params_reboot_ec *params,
- int data_len, int seq)
+static void handle_cmd_reboot_ec(const struct ec_params_reboot_ec *params,
+ int data_len, int seq)
{
int ret = EC_RES_SUCCESS;
@@ -150,9 +145,9 @@ out:
}
#ifdef CONFIG_EC_EC_COMM_BATTERY
-static void handle_cmd_charger_control(
- const struct ec_params_charger_control *params,
- int data_len, int seq)
+static void
+handle_cmd_charger_control(const struct ec_params_charger_control *params,
+ int data_len, int seq)
{
int ret = EC_RES_SUCCESS;
int prev_charging_allowed = charging_allowed;
@@ -169,7 +164,7 @@ static void handle_cmd_charger_control(
charging_allowed = params->allow_charging;
} else {
if (-params->max_current > MAX_OTG_CURRENT_MA ||
- params->otg_voltage > MAX_OTG_VOLTAGE_MV) {
+ params->otg_voltage > MAX_OTG_VOLTAGE_MV) {
ret = EC_RES_INVALID_PARAM;
goto out;
}
@@ -233,8 +228,8 @@ void ec_ec_comm_server_task(void *u)
#ifdef EXTRA_DEBUG
CPRINTS("%s f0=%02x f1=%02x cmd=%02x, length=%d", __func__,
- header.fields0, header.fields1,
- header.command, header.data_len);
+ header.fields0, header.fields1, header.command,
+ header.data_len);
#endif
/* Ignore response (we wrote that ourselves) */
@@ -266,7 +261,7 @@ void ec_ec_comm_server_task(void *u)
}
seq = (header.fields0 & EC_PACKET4_0_SEQ_NUM_MASK) >>
- EC_PACKET4_0_SEQ_NUM_SHIFT;
+ EC_PACKET4_0_SEQ_NUM_SHIFT;
cmdver = header.fields1 & EC_PACKET4_1_COMMAND_VERSION_MASK;
@@ -277,7 +272,7 @@ void ec_ec_comm_server_task(void *u)
}
/* Check data CRC */
- if (hascrc && params[len-1] != cros_crc8(params, len-1)) {
+ if (hascrc && params[len - 1] != cros_crc8(params, len - 1)) {
CPRINTS("%s data crc error", __func__);
write_response(EC_RES_INVALID_CHECKSUM, seq, NULL, 0);
goto discard;
@@ -295,31 +290,30 @@ void ec_ec_comm_server_task(void *u)
case EC_CMD_BATTERY_GET_STATIC:
/* Note that we ignore the battery index parameter. */
write_response(EC_RES_SUCCESS, seq,
- &battery_static[BATT_IDX_MAIN],
- sizeof(battery_static[BATT_IDX_MAIN]));
+ &battery_static[BATT_IDX_MAIN],
+ sizeof(battery_static[BATT_IDX_MAIN]));
break;
case EC_CMD_BATTERY_GET_DYNAMIC:
/* Note that we ignore the battery index parameter. */
write_response(EC_RES_SUCCESS, seq,
- &battery_dynamic[BATT_IDX_MAIN],
- sizeof(battery_dynamic[BATT_IDX_MAIN]));
+ &battery_dynamic[BATT_IDX_MAIN],
+ sizeof(battery_dynamic[BATT_IDX_MAIN]));
break;
case EC_CMD_CHARGER_CONTROL:
handle_cmd_charger_control((void *)params,
- header.data_len, seq);
+ header.data_len, seq);
break;
#endif
case EC_CMD_REBOOT_EC:
- handle_cmd_reboot_ec((void *)params,
- header.data_len, seq);
+ handle_cmd_reboot_ec((void *)params, header.data_len,
+ seq);
break;
default:
- write_response(EC_RES_INVALID_COMMAND, seq,
- NULL, 0);
+ write_response(EC_RES_INVALID_COMMAND, seq, NULL, 0);
}
continue;
-discard:
+ discard:
/*
* Some error occurred: discard all data in the queue.
*/
diff --git a/common/ec_features.c b/common/ec_features.c
index 2147c1b48a..a45204b7a1 100644
--- a/common/ec_features.c
+++ b/common/ec_features.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -15,97 +15,97 @@ uint32_t get_feature_flags0(void)
{
uint32_t result = 0
#ifdef CONFIG_FW_LIMITED_IMAGE
- | EC_FEATURE_MASK_0(EC_FEATURE_LIMITED)
+ | EC_FEATURE_MASK_0(EC_FEATURE_LIMITED)
#endif
#ifdef CONFIG_FLASH_CROS
- | EC_FEATURE_MASK_0(EC_FEATURE_FLASH)
+ | EC_FEATURE_MASK_0(EC_FEATURE_FLASH)
#endif
#ifdef CONFIG_FANS
- | EC_FEATURE_MASK_0(EC_FEATURE_PWM_FAN)
+ | EC_FEATURE_MASK_0(EC_FEATURE_PWM_FAN)
#endif
#ifdef CONFIG_KEYBOARD_BACKLIGHT
- | EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB)
+ | EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB)
#endif
#ifdef HAS_TASK_LIGHTBAR
- | EC_FEATURE_MASK_0(EC_FEATURE_LIGHTBAR)
+ | EC_FEATURE_MASK_0(EC_FEATURE_LIGHTBAR)
#endif
#ifdef CONFIG_LED_COMMON
- | EC_FEATURE_MASK_0(EC_FEATURE_LED)
+ | EC_FEATURE_MASK_0(EC_FEATURE_LED)
#endif
#ifdef HAS_TASK_MOTIONSENSE
- | EC_FEATURE_MASK_0(EC_FEATURE_MOTION_SENSE)
+ | EC_FEATURE_MASK_0(EC_FEATURE_MOTION_SENSE)
#endif
#ifdef HAS_TASK_KEYSCAN
- | EC_FEATURE_MASK_0(EC_FEATURE_KEYB)
+ | EC_FEATURE_MASK_0(EC_FEATURE_KEYB)
#endif
#ifdef CONFIG_PSTORE
- | EC_FEATURE_MASK_0(EC_FEATURE_PSTORE)
+ | EC_FEATURE_MASK_0(EC_FEATURE_PSTORE)
#endif
#ifdef CONFIG_HOSTCMD_X86
- | EC_FEATURE_MASK_0(EC_FEATURE_PORT80)
+ | EC_FEATURE_MASK_0(EC_FEATURE_PORT80)
#endif
#ifdef CONFIG_TEMP_SENSOR
- | EC_FEATURE_MASK_0(EC_FEATURE_THERMAL)
+ | EC_FEATURE_MASK_0(EC_FEATURE_THERMAL)
#endif
#if (defined CONFIG_BACKLIGHT_LID) || (defined CONFIG_BACKLIGHT_REQ_GPIO)
- | EC_FEATURE_MASK_0(EC_FEATURE_BKLIGHT_SWITCH)
+ | EC_FEATURE_MASK_0(EC_FEATURE_BKLIGHT_SWITCH)
#endif
#ifdef CONFIG_WIRELESS
- | EC_FEATURE_MASK_0(EC_FEATURE_WIFI_SWITCH)
+ | EC_FEATURE_MASK_0(EC_FEATURE_WIFI_SWITCH)
#endif
#ifdef CONFIG_HOSTCMD_EVENTS
- | EC_FEATURE_MASK_0(EC_FEATURE_HOST_EVENTS)
+ | EC_FEATURE_MASK_0(EC_FEATURE_HOST_EVENTS)
#endif
#ifdef CONFIG_COMMON_GPIO
- | EC_FEATURE_MASK_0(EC_FEATURE_GPIO)
+ | EC_FEATURE_MASK_0(EC_FEATURE_GPIO)
#endif
#ifdef CONFIG_I2C_CONTROLLER
- | EC_FEATURE_MASK_0(EC_FEATURE_I2C)
+ | EC_FEATURE_MASK_0(EC_FEATURE_I2C)
#endif
#ifdef CONFIG_CHARGER
- | EC_FEATURE_MASK_0(EC_FEATURE_CHARGER)
+ | EC_FEATURE_MASK_0(EC_FEATURE_CHARGER)
#endif
#if (defined CONFIG_BATTERY)
- | EC_FEATURE_MASK_0(EC_FEATURE_BATTERY)
+ | EC_FEATURE_MASK_0(EC_FEATURE_BATTERY)
#endif
#ifdef CONFIG_BATTERY_SMART
- | EC_FEATURE_MASK_0(EC_FEATURE_SMART_BATTERY)
+ | EC_FEATURE_MASK_0(EC_FEATURE_SMART_BATTERY)
#endif
#ifdef CONFIG_AP_HANG_DETECT
- | EC_FEATURE_MASK_0(EC_FEATURE_HANG_DETECT)
+ | EC_FEATURE_MASK_0(EC_FEATURE_HANG_DETECT)
#endif
#if 0
| EC_FEATURE_MASK_0(EC_FEATURE_PMU) /* Obsolete */
#endif
#ifdef CONFIG_HOSTCMD_PD
- | EC_FEATURE_MASK_0(EC_FEATURE_SUB_MCU)
+ | EC_FEATURE_MASK_0(EC_FEATURE_SUB_MCU)
#endif
#ifdef CONFIG_CHARGE_MANAGER
- | EC_FEATURE_MASK_0(EC_FEATURE_USB_PD)
+ | EC_FEATURE_MASK_0(EC_FEATURE_USB_PD)
#endif
#ifdef CONFIG_ACCEL_FIFO
- | EC_FEATURE_MASK_0(EC_FEATURE_MOTION_SENSE_FIFO)
+ | EC_FEATURE_MASK_0(EC_FEATURE_MOTION_SENSE_FIFO)
#endif
#ifdef CONFIG_VSTORE
- | EC_FEATURE_MASK_0(EC_FEATURE_VSTORE)
+ | EC_FEATURE_MASK_0(EC_FEATURE_VSTORE)
#endif
#ifdef CONFIG_USB_MUX_VIRTUAL
- | EC_FEATURE_MASK_0(EC_FEATURE_USBC_SS_MUX_VIRTUAL)
+ | EC_FEATURE_MASK_0(EC_FEATURE_USBC_SS_MUX_VIRTUAL)
#endif
#ifdef CONFIG_HOSTCMD_RTC
- | EC_FEATURE_MASK_0(EC_FEATURE_RTC)
+ | EC_FEATURE_MASK_0(EC_FEATURE_RTC)
#endif
#ifdef CONFIG_SPI_FP_PORT
- | EC_FEATURE_MASK_0(EC_FEATURE_FINGERPRINT)
+ | EC_FEATURE_MASK_0(EC_FEATURE_FINGERPRINT)
#endif
#ifdef HAS_TASK_CENTROIDING
- | EC_FEATURE_MASK_0(EC_FEATURE_TOUCHPAD)
+ | EC_FEATURE_MASK_0(EC_FEATURE_TOUCHPAD)
#endif
#if defined(HAS_TASK_RWSIG) || defined(HAS_TASK_RWSIG_RO)
- | EC_FEATURE_MASK_0(EC_FEATURE_RWSIG)
+ | EC_FEATURE_MASK_0(EC_FEATURE_RWSIG)
#endif
#ifdef CONFIG_DEVICE_EVENT
- | EC_FEATURE_MASK_0(EC_FEATURE_DEVICE_EVENT)
+ | EC_FEATURE_MASK_0(EC_FEATURE_DEVICE_EVENT)
#endif
;
return board_override_feature_flags0(result);
@@ -113,7 +113,8 @@ uint32_t get_feature_flags0(void)
uint32_t get_feature_flags1(void)
{
- uint32_t result = EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS)
+ uint32_t result =
+ EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS)
#ifdef CONFIG_HOST_EVENT64
| EC_FEATURE_MASK_1(EC_FEATURE_HOST_EVENT64)
#endif
@@ -150,6 +151,9 @@ uint32_t get_feature_flags1(void)
#ifdef CONFIG_POWER_S4_RESIDENCY
| EC_FEATURE_MASK_1(EC_FEATURE_S4_RESIDENCY)
#endif
+#ifdef CONFIG_USB_MUX_AP_CONTROL
+ | EC_FEATURE_MASK_1(EC_FEATURE_TYPEC_AP_MUX_SET)
+#endif
;
return board_override_feature_flags1(result);
}
@@ -164,7 +168,7 @@ __overridable uint32_t board_override_feature_flags1(uint32_t flags1)
return flags1;
}
-static int cc_feat(int argc, char **argv)
+static int cc_feat(int argc, const char **argv)
{
ccprintf(" 0-31: 0x%08x\n", get_feature_flags0());
ccprintf("32-63: 0x%08x\n", get_feature_flags1());
diff --git a/common/espi.c b/common/espi.c
index 0a747d3bda..dfb1f90749 100644
--- a/common/espi.c
+++ b/common/espi.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -12,7 +12,6 @@
#include "timer.h"
#include "util.h"
-
const char *espi_vw_names[] = {
"VW_SLP_S3_L",
"VW_SLP_S4_L",
@@ -41,7 +40,6 @@ const char *espi_vw_names[] = {
};
BUILD_ASSERT(ARRAY_SIZE(espi_vw_names) == VW_SIGNAL_COUNT);
-
const char *espi_vw_get_wire_name(enum espi_vw_signal signal)
{
if (espi_signal_is_vw(signal))
@@ -50,7 +48,6 @@ const char *espi_vw_get_wire_name(enum espi_vw_signal signal)
return NULL;
}
-
int espi_signal_is_vw(int signal)
{
return ((signal >= VW_SIGNAL_START) && (signal < VW_SIGNAL_END));
diff --git a/common/event_log.c b/common/event_log.c
index dc2c4ec2d7..f748b3d9a7 100644
--- a/common/event_log.c
+++ b/common/event_log.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,8 +13,8 @@
/* Event log FIFO */
#define UNIT_SIZE sizeof(struct event_log_entry)
-#define UNIT_COUNT (CONFIG_EVENT_LOG_SIZE/UNIT_SIZE)
-#define UNIT_COUNT_MASK (UNIT_COUNT - 1)
+#define UNIT_COUNT (CONFIG_EVENT_LOG_SIZE / UNIT_SIZE)
+#define UNIT_COUNT_MASK (UNIT_COUNT - 1)
static struct event_log_entry log_events[UNIT_COUNT];
BUILD_ASSERT(POWER_OF_TWO(UNIT_COUNT));
@@ -42,10 +42,10 @@ static size_t log_tail;
static size_t log_tail_next;
/* Size of one FIFO entry */
-#define ENTRY_SIZE(payload_sz) (1+DIV_ROUND_UP((payload_sz), UNIT_SIZE))
+#define ENTRY_SIZE(payload_sz) (1 + DIV_ROUND_UP((payload_sz), UNIT_SIZE))
-void log_add_event(uint8_t type, uint8_t size, uint16_t data,
- void *payload, uint32_t timestamp)
+void log_add_event(uint8_t type, uint8_t size, uint16_t data, void *payload,
+ uint32_t timestamp)
{
struct event_log_entry *r;
size_t payload_size = EVENT_LOG_SIZE(size);
@@ -78,13 +78,13 @@ void log_add_event(uint8_t type, uint8_t size, uint16_t data,
r->size = size;
r->data = data;
/* copy the payload into the FIFO */
- first = MIN(total_size - 1, (UNIT_COUNT -
- (current_tail & UNIT_COUNT_MASK)) - 1);
+ first = MIN(total_size - 1,
+ (UNIT_COUNT - (current_tail & UNIT_COUNT_MASK)) - 1);
if (first)
memcpy(r->payload, payload, first * UNIT_SIZE);
if (first < total_size - 1)
memcpy(log_events, ((uint8_t *)payload) + first * UNIT_SIZE,
- (total_size - first) * UNIT_SIZE);
+ (total_size - first) * UNIT_SIZE);
/* mark the entry available in the queue if nobody is behind us */
if (current_tail == log_tail)
log_tail = log_tail_next;
@@ -112,7 +112,7 @@ retry:
first = MIN(total_size, UNIT_COUNT - (current_head & UNIT_COUNT_MASK));
memcpy(r, entry, first * UNIT_SIZE);
if (first < total_size)
- memcpy(r + first, log_events, (total_size-first) * UNIT_SIZE);
+ memcpy(r + first, log_events, (total_size - first) * UNIT_SIZE);
/* --- critical section : remove the entry from the queue --- */
lock_key = irq_lock();
@@ -134,10 +134,10 @@ retry:
/*
* Display TPM event logs.
*/
-static int command_dlog(int argc, char **argv)
+static int command_dlog(int argc, const char **argv)
{
size_t log_cur;
- const uint8_t * const log_events_end =
+ const uint8_t *const log_events_end =
(uint8_t *)&log_events[UNIT_COUNT];
if (argc > 1) {
@@ -164,7 +164,7 @@ static int command_dlog(int argc, char **argv)
log_cur += ENTRY_SIZE(payload_bytes);
ccprintf("%10d %4d 0x%04X %4d ", r->timestamp, r->type,
- r->data, payload_bytes);
+ r->data, payload_bytes);
/* display payload if exists */
payload = r->payload;
@@ -179,8 +179,6 @@ static int command_dlog(int argc, char **argv)
}
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(dlog,
- command_dlog,
- "[clear]",
+DECLARE_CONSOLE_COMMAND(dlog, command_dlog, "[clear]",
"Display/clear TPM event logs");
#endif
diff --git a/common/extpower_common.c b/common/extpower_common.c
index 9021b77626..9f0947a529 100644
--- a/common/extpower_common.c
+++ b/common/extpower_common.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/extpower_gpio.c b/common/extpower_gpio.c
index 4cdcb834f8..8b41ec2075 100644
--- a/common/extpower_gpio.c
+++ b/common/extpower_gpio.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -31,7 +31,6 @@ static void extpower_deferred(void)
debounced_extpower_presence = extpower_presence;
extpower_handle_update(extpower_presence);
-
}
DECLARE_DEFERRED(extpower_deferred);
@@ -39,7 +38,7 @@ void extpower_interrupt(enum gpio_signal signal)
{
/* Trigger deferred notification of external power change */
hook_call_deferred(&extpower_deferred_data,
- CONFIG_EXTPOWER_DEBOUNCE_MS * MSEC);
+ CONFIG_EXTPOWER_DEBOUNCE_MS * MSEC);
}
static void extpower_init(void)
diff --git a/common/fan.c b/common/fan.c
index 636bec04f9..ddc15a4288 100644
--- a/common/fan.c
+++ b/common/fan.c
@@ -1,11 +1,11 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Basic Chrome OS fan control */
-#include "assert.h"
+#include "builtin/assert.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -56,7 +56,7 @@ void fan_set_count(int count)
* Convert the percentage to a target RPM. We can't simply scale all
* the way down to zero because most fans won't turn that slowly, so
* we'll map [1,100] => [FAN_MIN,FAN_MAX], and [0] => "off".
-*/
+ */
int fan_percent_to_rpm(int fan, int pct)
{
int rpm, max, min;
@@ -71,7 +71,7 @@ int fan_percent_to_rpm(int fan, int pct)
return rpm;
}
-#endif /* CONFIG_FAN_RPM_CUSTOM */
+#endif /* CONFIG_FAN_RPM_CUSTOM */
/* The thermal task will only call this function with pct in [0,100]. */
test_mockable void fan_set_percent_needed(int fan, int pct)
@@ -94,8 +94,7 @@ test_mockable void fan_set_percent_needed(int fan, int pct)
/* If we want to turn and the fans are currently significantly below
* the minimum turning speed, we should turn at least as fast as the
* necessary start speed instead. */
- if (new_rpm &&
- actual_rpm < fans[fan].rpm->rpm_min * 9 / 10 &&
+ if (new_rpm && actual_rpm < fans[fan].rpm->rpm_min * 9 / 10 &&
new_rpm < fans[fan].rpm->rpm_start)
new_rpm = fans[fan].rpm->rpm_start;
@@ -137,7 +136,7 @@ static void set_duty_cycle(int fan, int percent)
/*****************************************************************************/
/* Console commands */
-static int cc_fanauto(int argc, char **argv)
+static int cc_fanauto(int argc, const char **argv)
{
char *e;
int fan = 0;
@@ -157,8 +156,7 @@ static int cc_fanauto(int argc, char **argv)
set_thermal_control_enabled(fan, 1);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(fanauto, cc_fanauto,
- "{fan}",
+DECLARE_CONSOLE_COMMAND(fanauto, cc_fanauto, "{fan}",
"Enable thermal fan control");
/* Return 0 for off, 1 for on, -1 for unknown */
@@ -176,28 +174,27 @@ static int is_powered(int fan)
return is_pgood;
}
-static int cc_faninfo(int argc, char **argv)
+static int cc_faninfo(int argc, const char **argv)
{
- static const char * const human_status[] = {
- "not spinning", "changing", "locked", "frustrated"
- };
+ static const char *const human_status[] = { "not spinning", "changing",
+ "locked", "frustrated" };
int tmp, is_pgood;
int fan;
char leader[20] = "";
for (fan = 0; fan < fan_count; fan++) {
if (fan_count > 1)
- snprintf(leader, sizeof(leader), "Fan %d ", fan);
+ if (snprintf(leader, sizeof(leader), "Fan %d ", fan) <
+ 0)
+ leader[0] = '\0';
if (fan)
ccprintf("\n");
ccprintf("%sActual: %4d rpm\n", leader,
fan_get_rpm_actual(FAN_CH(fan)));
ccprintf("%sTarget: %4d rpm\n", leader,
fan_get_rpm_target(FAN_CH(fan)));
- ccprintf("%sDuty: %d%%\n", leader,
- fan_get_duty(FAN_CH(fan)));
+ ccprintf("%sDuty: %d%%\n", leader, fan_get_duty(FAN_CH(fan)));
tmp = fan_get_status(FAN_CH(fan));
- ccprintf("%sStatus: %d (%s)\n", leader,
- tmp, human_status[tmp]);
+ ccprintf("%sStatus: %d (%s)\n", leader, tmp, human_status[tmp]);
ccprintf("%sMode: %s\n", leader,
fan_get_rpm_mode(FAN_CH(fan)) ? "rpm" : "duty");
ccprintf("%sAuto: %s\n", leader,
@@ -212,11 +209,9 @@ static int cc_faninfo(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(faninfo, cc_faninfo,
- NULL,
- "Print fan info");
+DECLARE_CONSOLE_COMMAND(faninfo, cc_faninfo, NULL, "Print fan info");
-static int cc_fanset(int argc, char **argv)
+static int cc_fanset(int argc, const char **argv)
{
const char *rpm_str;
int rpm;
@@ -247,7 +242,7 @@ static int cc_fanset(int argc, char **argv)
}
rpm = strtoi(rpm_str, &e, 0);
- if (*e == '%') { /* Wait, that's a percentage */
+ if (*e == '%') { /* Wait, that's a percentage */
ccprintf("Fan rpm given as %d%%\n", rpm);
if (rpm < 0)
rpm = 0;
@@ -273,11 +268,10 @@ static int cc_fanset(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(fanset, cc_fanset,
- "[fan] (rpm | pct%)",
+DECLARE_CONSOLE_COMMAND(fanset, cc_fanset, "[fan] (rpm | pct%)",
"Set fan speed");
-static int cc_fanduty(int argc, char **argv)
+static int cc_fanduty(int argc, const char **argv)
{
const char *percent_str;
int percent = 0;
@@ -316,8 +310,7 @@ static int cc_fanduty(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(fanduty, cc_fanduty,
- "[fan] percent",
+DECLARE_CONSOLE_COMMAND(fanduty, cc_fanduty, "[fan] percent",
"Set fan duty cycle");
/*****************************************************************************/
@@ -326,7 +319,7 @@ DECLARE_CONSOLE_COMMAND(fanduty, cc_fanduty,
/* 0-100% if in duty mode. -1 if not */
int dptf_get_fan_duty_target(void)
{
- int fan = 0; /* TODO(crosbug.com/p/23803) */
+ int fan = 0; /* TODO(crosbug.com/p/23803) */
if (fan_count == 0)
return -1;
@@ -370,8 +363,7 @@ hc_pwm_get_fan_target_rpm(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_FAN_TARGET_RPM,
- hc_pwm_get_fan_target_rpm,
+DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_FAN_TARGET_RPM, hc_pwm_get_fan_target_rpm,
EC_VER_MASK(0));
static enum ec_status
@@ -399,7 +391,7 @@ hc_pwm_set_fan_target_rpm(struct host_cmd_handler_args *args)
return EC_RES_ERROR;
/* enable the fan if rpm is non-zero */
- set_enabled(fan, (p_v1->rpm > 0) ? 1 :0);
+ set_enabled(fan, (p_v1->rpm > 0) ? 1 : 0);
set_thermal_control_enabled(fan, 0);
fan_set_rpm_mode(FAN_CH(fan), 1);
@@ -407,8 +399,7 @@ hc_pwm_set_fan_target_rpm(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM,
- hc_pwm_set_fan_target_rpm,
+DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM, hc_pwm_set_fan_target_rpm,
EC_VER_MASK(0) | EC_VER_MASK(1));
static enum ec_status hc_pwm_set_fan_duty(struct host_cmd_handler_args *args)
@@ -432,8 +423,7 @@ static enum ec_status hc_pwm_set_fan_duty(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY,
- hc_pwm_set_fan_duty,
+DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY, hc_pwm_set_fan_duty,
EC_VER_MASK(0) | EC_VER_MASK(1));
static enum ec_status
@@ -457,10 +447,8 @@ hc_thermal_auto_fan_ctrl(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_THERMAL_AUTO_FAN_CTRL,
- hc_thermal_auto_fan_ctrl,
- EC_VER_MASK(0)|EC_VER_MASK(1));
-
+DECLARE_HOST_COMMAND(EC_CMD_THERMAL_AUTO_FAN_CTRL, hc_thermal_auto_fan_ctrl,
+ EC_VER_MASK(0) | EC_VER_MASK(1));
/*****************************************************************************/
/* Hooks */
@@ -471,18 +459,18 @@ DECLARE_HOST_COMMAND(EC_CMD_THERMAL_AUTO_FAN_CTRL,
*/
BUILD_ASSERT(CONFIG_FANS <= EC_FAN_SPEED_ENTRIES);
-#define PWMFAN_SYSJUMP_TAG 0x5046 /* "PF" */
+#define PWMFAN_SYSJUMP_TAG 0x5046 /* "PF" */
#define PWM_HOOK_VERSION 1
/* Saved PWM state across sysjumps */
struct pwm_fan_state {
/* TODO(crosbug.com/p/23530): Still treating all fans as one. */
uint16_t rpm;
- uint8_t flag; /* FAN_STATE_FLAG_* */
+ uint8_t flag; /* FAN_STATE_FLAG_* */
};
/* For struct pwm_fan_state.flag */
-#define FAN_STATE_FLAG_ENABLED BIT(0)
-#define FAN_STATE_FLAG_THERMAL BIT(1)
+#define FAN_STATE_FLAG_ENABLED BIT(0)
+#define FAN_STATE_FLAG_THERMAL BIT(1)
static void pwm_fan_init(void)
{
@@ -500,8 +488,8 @@ static void pwm_fan_init(void)
fan_channel_setup(FAN_CH(fan), fans[fan].conf->flags);
/* Restore previous state. */
- prev = (const struct pwm_fan_state *)
- system_get_jump_tag(PWMFAN_SYSJUMP_TAG, &version, &size);
+ prev = (const struct pwm_fan_state *)system_get_jump_tag(
+ PWMFAN_SYSJUMP_TAG, &version, &size);
if (prev && version == PWM_HOOK_VERSION && size == sizeof(*prev)) {
memcpy(&state, prev, sizeof(state));
} else {
@@ -513,7 +501,7 @@ static void pwm_fan_init(void)
state.flag & FAN_STATE_FLAG_ENABLED);
fan_set_rpm_target(FAN_CH(fan), state.rpm);
set_thermal_control_enabled(
- fan, state.flag & FAN_STATE_FLAG_THERMAL);
+ fan, state.flag & FAN_STATE_FLAG_THERMAL);
}
/* Initialize memory-mapped data */
@@ -553,7 +541,7 @@ DECLARE_HOOK(HOOK_SECOND, pwm_fan_second, HOOK_PRIO_DEFAULT);
static void pwm_fan_preserve_state(void)
{
- struct pwm_fan_state state = {0};
+ struct pwm_fan_state state = { 0 };
int fan = 0;
if (fan_count == 0)
@@ -566,8 +554,8 @@ static void pwm_fan_preserve_state(void)
state.flag |= FAN_STATE_FLAG_THERMAL;
state.rpm = fan_get_rpm_target(FAN_CH(fan));
- system_add_jump_tag(PWMFAN_SYSJUMP_TAG, PWM_HOOK_VERSION,
- sizeof(state), &state);
+ system_add_jump_tag(PWMFAN_SYSJUMP_TAG, PWM_HOOK_VERSION, sizeof(state),
+ &state);
}
DECLARE_HOOK(HOOK_SYSJUMP, pwm_fan_preserve_state, HOOK_PRIO_DEFAULT);
@@ -578,9 +566,11 @@ static void pwm_fan_control(int enable)
/* TODO(crosbug.com/p/23530): Still treating all fans as one. */
for (fan = 0; fan < fan_count; fan++) {
set_thermal_control_enabled(fan, enable);
- fan_set_rpm_target(FAN_CH(fan), enable ?
- fan_percent_to_rpm(FAN_CH(fan), CONFIG_FAN_INIT_SPEED) :
- 0);
+ fan_set_rpm_target(
+ FAN_CH(fan),
+ enable ? fan_percent_to_rpm(FAN_CH(fan),
+ CONFIG_FAN_INIT_SPEED) :
+ 0);
set_enabled(fan, enable);
}
}
diff --git a/common/firmware_image.S b/common/firmware_image.S
index 193719608f..cc9034b89d 100644
--- a/common/firmware_image.S
+++ b/common/firmware_image.S
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 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/common/firmware_image.lds.S b/common/firmware_image.lds.S
index 04249367b8..5bcd6efb5f 100644
--- a/common/firmware_image.lds.S
+++ b/common/firmware_image.lds.S
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 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/common/flash.c b/common/flash.c
index 055064d029..0a027fd312 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -1,10 +1,11 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Flash memory module for Chrome EC - common functions */
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "cros_board_info.h"
@@ -42,14 +43,14 @@
/* Persistent protection state - emulates a SPI status register for flashrom */
/* NOTE: It's not expected that RO and RW will support
* differing PSTATE versions. */
-#define PERSIST_STATE_VERSION 3 /* Expected persist_state.version */
+#define PERSIST_STATE_VERSION 3 /* Expected persist_state.version */
/* Flags for persist_state.flags */
/* Protect persist state and RO firmware at boot */
#define PERSIST_FLAG_PROTECT_RO 0x02
-#define PSTATE_VALID_FLAGS BIT(0)
-#define PSTATE_VALID_SERIALNO BIT(1)
-#define PSTATE_VALID_MAC_ADDR BIT(2)
+#define PSTATE_VALID_FLAGS BIT(0)
+#define PSTATE_VALID_SERIALNO BIT(1)
+#define PSTATE_VALID_MAC_ADDR BIT(2)
/*
* Error correction code operates on blocks equal to CONFIG_FLASH_WRITE_SIZE
@@ -59,10 +60,10 @@
* size of the structure to ensure that it is also a multiple of the alignment.
*/
struct persist_state {
- uint8_t version; /* Version of this struct */
- uint8_t flags; /* Lock flags (PERSIST_FLAG_*) */
- uint8_t valid_fields; /* Flags for valid data. */
- uint8_t reserved; /* Reserved; set 0 */
+ uint8_t version; /* Version of this struct */
+ uint8_t flags; /* Lock flags (PERSIST_FLAG_*) */
+ uint8_t valid_fields; /* Flags for valid data. */
+ uint8_t reserved; /* Reserved; set 0 */
#ifdef CONFIG_SERIALNO_LEN
uint8_t serialno[CONFIG_SERIALNO_LEN]; /* Serial number. */
#endif /* CONFIG_SERIALNO_LEN */
@@ -91,11 +92,11 @@ BUILD_ASSERT(sizeof(struct persist_state) <= CONFIG_FW_PSTATE_SIZE);
* lock the flash at boot.
*/
#if (CONFIG_FLASH_ERASED_VALUE32 == -1U)
-#define PSTATE_MAGIC_UNLOCKED 0x4f4e5057 /* "WPNO" */
-#define PSTATE_MAGIC_LOCKED 0x00000000 /* "" */
+#define PSTATE_MAGIC_UNLOCKED 0x4f4e5057 /* "WPNO" */
+#define PSTATE_MAGIC_LOCKED 0x00000000 /* "" */
#elif (CONFIG_FLASH_ERASED_VALUE32 == 0)
-#define PSTATE_MAGIC_UNLOCKED 0x4f4e5057 /* "WPNO" */
-#define PSTATE_MAGIC_LOCKED 0x5f5f5057 /* "WP__" */
+#define PSTATE_MAGIC_UNLOCKED 0x4f4e5057 /* "WPNO" */
+#define PSTATE_MAGIC_LOCKED 0x5f5f5057 /* "WP__" */
#else
/* What kind of wacky flash doesn't erase all bits to 1 or 0? */
#error "PSTATE needs magic values for this flash architecture."
@@ -171,8 +172,8 @@ int crec_flash_bank_index(int offset)
return bank_offset;
for (i = 0; i < ARRAY_SIZE(flash_bank_array); i++) {
- int all_sector_size = flash_bank_array[i].count <<
- flash_bank_array[i].size_exp;
+ int all_sector_size = flash_bank_array[i].count
+ << flash_bank_array[i].size_exp;
if (offset >= all_sector_size) {
offset -= all_sector_size;
bank_offset += flash_bank_array[i].count;
@@ -217,16 +218,15 @@ int crec_flash_bank_start_offset(int bank)
return offset;
}
-#endif /* CONFIG_FLASH_MULTIPLE_REGION */
+#endif /* CONFIG_FLASH_MULTIPLE_REGION */
static int flash_range_ok(int offset, int size_req, int align)
{
- if (offset < 0 || size_req < 0 ||
- offset > CONFIG_FLASH_SIZE_BYTES ||
+ if (offset < 0 || size_req < 0 || offset > CONFIG_FLASH_SIZE_BYTES ||
size_req > CONFIG_FLASH_SIZE_BYTES ||
offset + size_req > CONFIG_FLASH_SIZE_BYTES ||
(offset | size_req) & (align - 1))
- return 0; /* Invalid range */
+ return 0; /* Invalid range */
return 1;
}
@@ -251,7 +251,7 @@ static const char *flash_physical_dataptr(int offset)
int crec_flash_dataptr(int offset, int size_req, int align, const char **ptrp)
{
if (!flash_range_ok(offset, size_req, align))
- return -1; /* Invalid range */
+ return -1; /* Invalid range */
if (ptrp)
*ptrp = flash_physical_dataptr(offset);
@@ -268,8 +268,8 @@ int crec_flash_dataptr(int offset, int size_req, int align, const char **ptrp)
static uint32_t flash_read_pstate(void)
{
const struct persist_state *pstate =
- (const struct persist_state *)
- flash_physical_dataptr(CONFIG_FW_PSTATE_OFF);
+ (const struct persist_state *)flash_physical_dataptr(
+ CONFIG_FW_PSTATE_OFF);
if ((pstate->version == PERSIST_STATE_VERSION) &&
(pstate->valid_fields & PSTATE_VALID_FLAGS) &&
@@ -314,8 +314,6 @@ static int flash_write_pstate_data(struct persist_state *newpstate)
(const char *)newpstate);
}
-
-
/**
* Validate and Init persistent state datastructure.
*
@@ -342,8 +340,8 @@ static int flash_write_pstate(uint32_t flags)
{
struct persist_state newpstate;
const struct persist_state *pstate =
- (const struct persist_state *)
- flash_physical_dataptr(CONFIG_FW_PSTATE_OFF);
+ (const struct persist_state *)flash_physical_dataptr(
+ CONFIG_FW_PSTATE_OFF);
/* Only check the flags we write to pstate */
flags &= EC_FLASH_PROTECT_RO_AT_BOOT;
@@ -372,8 +370,8 @@ static int flash_write_pstate(uint32_t flags)
const char *crec_flash_read_pstate_serial(void)
{
const struct persist_state *pstate =
- (const struct persist_state *)
- flash_physical_dataptr(CONFIG_FW_PSTATE_OFF);
+ (const struct persist_state *)flash_physical_dataptr(
+ CONFIG_FW_PSTATE_OFF);
if ((pstate->version == PERSIST_STATE_VERSION) &&
(pstate->valid_fields & PSTATE_VALID_SERIALNO)) {
@@ -394,8 +392,8 @@ int crec_flash_write_pstate_serial(const char *serialno)
int length;
struct persist_state newpstate;
const struct persist_state *pstate =
- (const struct persist_state *)
- flash_physical_dataptr(CONFIG_FW_PSTATE_OFF);
+ (const struct persist_state *)flash_physical_dataptr(
+ CONFIG_FW_PSTATE_OFF);
/* Check that this is OK */
if (!serialno)
@@ -432,8 +430,8 @@ int crec_flash_write_pstate_serial(const char *serialno)
const char *crec_flash_read_pstate_mac_addr(void)
{
const struct persist_state *pstate =
- (const struct persist_state *)
- flash_physical_dataptr(CONFIG_FW_PSTATE_OFF);
+ (const struct persist_state *)flash_physical_dataptr(
+ CONFIG_FW_PSTATE_OFF);
if ((pstate->version == PERSIST_STATE_VERSION) &&
(pstate->valid_fields & PSTATE_VALID_MAC_ADDR)) {
@@ -454,8 +452,8 @@ int crec_flash_write_pstate_mac_addr(const char *mac_addr)
int length;
struct persist_state newpstate;
const struct persist_state *pstate =
- (const struct persist_state *)
- flash_physical_dataptr(CONFIG_FW_PSTATE_OFF);
+ (const struct persist_state *)flash_physical_dataptr(
+ CONFIG_FW_PSTATE_OFF);
/* Check that this is OK, data is valid and fits in the region. */
if (!mac_addr) {
@@ -559,10 +557,9 @@ static int flash_write_pstate(uint32_t flags)
* Write a new pstate. We can overwrite the existing value, because
* we're only moving bits from the erased state to the unerased state.
*/
- return crec_flash_physical_write(get_pstate_addr() -
- CONFIG_PROGRAM_MEMORY_BASE,
- sizeof(new_pstate),
- (const char *)&new_pstate);
+ return crec_flash_physical_write(
+ get_pstate_addr() - CONFIG_PROGRAM_MEMORY_BASE,
+ sizeof(new_pstate), (const char *)&new_pstate);
}
#endif /* !CONFIG_FLASH_PSTATE_BANK */
@@ -575,7 +572,7 @@ int crec_flash_is_erased(uint32_t offset, int size)
#ifdef CONFIG_MAPPED_STORAGE
/* Use pointer directly to flash */
if (crec_flash_dataptr(offset, size, sizeof(uint32_t),
- (const char **)&ptr) < 0)
+ (const char **)&ptr) < 0)
return 0;
crec_flash_lock_mapped_storage(1);
@@ -583,7 +580,7 @@ int crec_flash_is_erased(uint32_t offset, int size)
if (*ptr != CONFIG_FLASH_ERASED_VALUE32) {
crec_flash_lock_mapped_storage(0);
return 0;
- }
+ }
crec_flash_lock_mapped_storage(0);
#else
@@ -604,7 +601,6 @@ int crec_flash_is_erased(uint32_t offset, int size)
for (bsize /= sizeof(uint32_t); bsize > 0; bsize--, ptr++)
if (*ptr != CONFIG_FLASH_ERASED_VALUE32)
return 0;
-
}
#endif
@@ -657,11 +653,11 @@ static void flash_abort_or_invalidate_hash(int offset, int size)
* jump to RW after the timeout.
*/
if ((offset >= CONFIG_RW_MEM_OFF &&
- offset < (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)) ||
+ offset < (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)) ||
((offset + size) > CONFIG_RW_MEM_OFF &&
- (offset + size) <= (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)) ||
+ (offset + size) <= (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)) ||
(offset < CONFIG_RW_MEM_OFF &&
- (offset + size) > (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)))
+ (offset + size) > (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)))
rwsig_abort();
#endif
}
@@ -669,7 +665,7 @@ static void flash_abort_or_invalidate_hash(int offset, int size)
int crec_flash_write(int offset, int size, const char *data)
{
if (!flash_range_ok(offset, size, CONFIG_FLASH_WRITE_SIZE))
- return EC_ERROR_INVAL; /* Invalid range */
+ return EC_ERROR_INVAL; /* Invalid range */
flash_abort_or_invalidate_hash(offset, size);
@@ -680,7 +676,7 @@ int crec_flash_erase(int offset, int size)
{
#ifndef CONFIG_FLASH_MULTIPLE_REGION
if (!flash_range_ok(offset, size, CONFIG_FLASH_ERASE_SIZE))
- return EC_ERROR_INVAL; /* Invalid range */
+ return EC_ERROR_INVAL; /* Invalid range */
#endif
flash_abort_or_invalidate_hash(offset, size);
@@ -736,7 +732,7 @@ uint32_t crec_flash_get_protect(void)
uint32_t flags = 0;
int i;
/* Region protection status */
- int not_protected[FLASH_REGION_COUNT] = {0};
+ int not_protected[FLASH_REGION_COUNT] = { 0 };
#ifdef CONFIG_ROLLBACK
/* Flags that must be set to set ALL_NOW flag. */
const uint32_t all_flags = EC_FLASH_PROTECT_RO_NOW |
@@ -759,11 +755,11 @@ uint32_t crec_flash_get_protect(void)
/* Scan flash protection */
for (i = 0; i < PHYSICAL_BANKS; i++) {
int is_ro = (i >= WP_BANK_OFFSET &&
- i < WP_BANK_OFFSET + WP_BANK_COUNT);
+ i < WP_BANK_OFFSET + WP_BANK_COUNT);
enum flash_region region = is_ro ? FLASH_REGION_RO :
- FLASH_REGION_RW;
+ FLASH_REGION_RW;
int bank_flag = is_ro ? EC_FLASH_PROTECT_RO_NOW :
- EC_FLASH_PROTECT_RW_NOW;
+ EC_FLASH_PROTECT_RW_NOW;
#ifdef CONFIG_ROLLBACK
if (i >= ROLLBACK_BANK_OFFSET &&
@@ -824,10 +820,11 @@ int crec_flash_set_protect(uint32_t mask, uint32_t flags)
{
int retval = EC_SUCCESS;
int rv;
- int old_flags_at_boot = crec_flash_get_protect() &
+ int old_flags_at_boot =
+ crec_flash_get_protect() &
(EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RW_AT_BOOT |
- EC_FLASH_PROTECT_ROLLBACK_AT_BOOT |
- EC_FLASH_PROTECT_ALL_AT_BOOT);
+ EC_FLASH_PROTECT_ROLLBACK_AT_BOOT |
+ EC_FLASH_PROTECT_ALL_AT_BOOT);
int new_flags_at_boot = old_flags_at_boot;
/* Sanitize input flags */
@@ -908,8 +905,8 @@ int crec_flash_set_protect(uint32_t mask, uint32_t flags)
* All subsequent flags only work if write protect is enabled (that is,
* hardware WP flag) *and* RO is protected at boot (software WP flag).
*/
- if ((~crec_flash_get_protect()) & (EC_FLASH_PROTECT_GPIO_ASSERTED |
- EC_FLASH_PROTECT_RO_AT_BOOT))
+ if ((~crec_flash_get_protect()) &
+ (EC_FLASH_PROTECT_GPIO_ASSERTED | EC_FLASH_PROTECT_RO_AT_BOOT))
return retval;
/*
@@ -948,8 +945,7 @@ int crec_flash_set_protect(uint32_t mask, uint32_t flags)
* we're now protecting the RO region with SW WP.
*/
if (IS_ENABLED(CONFIG_EEPROM_CBI_WP) &&
- (EC_FLASH_PROTECT_GPIO_ASSERTED &
- crec_flash_get_protect()))
+ (EC_FLASH_PROTECT_GPIO_ASSERTED & crec_flash_get_protect()))
cbi_latch_eeprom_wp();
}
@@ -982,7 +978,7 @@ DECLARE_DEFERRED(flash_erase_deferred);
/* Console commands */
#ifdef CONFIG_CMD_FLASHINFO
-static int command_flash_info(int argc, char **argv)
+static int command_flash_info(int argc, const char **argv)
{
int i, flags;
@@ -992,8 +988,7 @@ static int command_flash_info(int argc, char **argv)
#ifdef CONFIG_FLASH_MULTIPLE_REGION
ccprintf("Regions:\n");
for (i = 0; i < ARRAY_SIZE(flash_bank_array); i++) {
- ccprintf(" %d region%s:\n",
- flash_bank_array[i].count,
+ ccprintf(" %d region%s:\n", flash_bank_array[i].count,
(flash_bank_array[i].count == 1 ? "" : "s"));
ccprintf(" Erase: %4d B (to %d-bits)\n",
1 << flash_bank_array[i].erase_size_exp,
@@ -1049,13 +1044,12 @@ static int command_flash_info(int argc, char **argv)
ccputs("\n");
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(flashinfo, command_flash_info,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(flashinfo, command_flash_info, NULL,
"Print flash info");
#endif /* CONFIG_CMD_FLASHINFO */
#ifdef CONFIG_CMD_FLASH
-static int command_flash_erase(int argc, char **argv)
+static int command_flash_erase(int argc, const char **argv)
{
int offset = -1;
int size = -1;
@@ -1071,11 +1065,10 @@ static int command_flash_erase(int argc, char **argv)
ccprintf("Erasing %d bytes at 0x%x...\n", size, offset);
return crec_flash_erase(offset, size);
}
-DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase,
- "offset size",
+DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase, "offset size",
"Erase flash");
-static int command_flash_write(int argc, char **argv)
+static int command_flash_write(int argc, const char **argv)
{
int offset = -1;
int size = -1;
@@ -1112,11 +1105,10 @@ static int command_flash_write(int argc, char **argv)
return rv;
}
-DECLARE_CONSOLE_COMMAND(flashwrite, command_flash_write,
- "offset size",
+DECLARE_CONSOLE_COMMAND(flashwrite, command_flash_write, "offset size",
"Write pattern to flash");
-static int command_flash_read(int argc, char **argv)
+static int command_flash_read(int argc, const char **argv)
{
int offset = -1;
int size = 256;
@@ -1160,13 +1152,12 @@ static int command_flash_read(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(flashread, command_flash_read,
- "offset [size]",
+DECLARE_CONSOLE_COMMAND(flashread, command_flash_read, "offset [size]",
"Read flash");
#endif
#ifdef CONFIG_CMD_FLASH_WP
-static int command_flash_wp(int argc, char **argv)
+static int command_flash_wp(int argc, const char **argv)
{
int val;
@@ -1203,7 +1194,7 @@ static int command_flash_wp(int argc, char **argv)
/* Do this last, since anything starting with 'n' means "no" */
if (parse_bool(argv[1], &val))
return crec_flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT,
- val ? -1 : 0);
+ val ? -1 : 0);
return EC_ERROR_PARAM1;
}
@@ -1215,7 +1206,8 @@ DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp,
#ifdef CONFIG_ROLLBACK
" | rb | norb"
#endif
- , "Modify flash write protect");
+ ,
+ "Modify flash write protect");
#endif /* CONFIG_CMD_FLASH_WP */
/*****************************************************************************/
@@ -1231,8 +1223,8 @@ DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp,
* region belonging to the EC. TODO(crbug.com/529365): Handle fmap_base
* correctly in flashrom, dump_fmap, etc. and remove EC_FLASH_REGION_START.
*/
-#define EC_FLASH_REGION_START MIN(CONFIG_EC_PROTECTED_STORAGE_OFF, \
- CONFIG_EC_WRITABLE_STORAGE_OFF)
+#define EC_FLASH_REGION_START \
+ MIN(CONFIG_EC_PROTECTED_STORAGE_OFF, CONFIG_EC_WRITABLE_STORAGE_OFF)
static enum ec_status flash_command_get_info(struct host_cmd_handler_args *args)
{
@@ -1263,8 +1255,8 @@ static enum ec_status flash_command_get_info(struct host_cmd_handler_args *args)
* Compute the ideal amount of data for the host to send us,
* based on the maximum response size and the ideal write size.
*/
- ideal_size = (args->response_max -
- sizeof(struct ec_params_flash_write)) &
+ ideal_size =
+ (args->response_max - sizeof(struct ec_params_flash_write)) &
~(CONFIG_FLASH_WRITE_IDEAL_SIZE - 1);
/*
* If we can't get at least one ideal block, then just want
@@ -1272,9 +1264,8 @@ static enum ec_status flash_command_get_info(struct host_cmd_handler_args *args)
*/
if (!ideal_size)
ideal_size = (args->response_max -
- sizeof(struct ec_params_flash_write)) &
- ~(CONFIG_FLASH_WRITE_SIZE - 1);
-
+ sizeof(struct ec_params_flash_write)) &
+ ~(CONFIG_FLASH_WRITE_SIZE - 1);
if (args->version >= 2) {
args->response_size = sizeof(struct ec_response_flash_info_2);
@@ -1319,16 +1310,14 @@ static enum ec_status flash_command_get_info(struct host_cmd_handler_args *args)
#endif
}
return EC_RES_SUCCESS;
-#endif /* CONFIG_FLASH_MULTIPLE_REGION */
+#endif /* CONFIG_FLASH_MULTIPLE_REGION */
}
#ifdef CONFIG_FLASH_MULTIPLE_REGION
#define FLASH_INFO_VER EC_VER_MASK(2)
#else
#define FLASH_INFO_VER (EC_VER_MASK(0) | EC_VER_MASK(1) | EC_VER_MASK(2))
#endif
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_INFO,
- flash_command_get_info, FLASH_INFO_VER);
-
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_INFO, flash_command_get_info, FLASH_INFO_VER);
static enum ec_status flash_command_read(struct host_cmd_handler_args *args)
{
@@ -1345,9 +1334,7 @@ static enum ec_status flash_command_read(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_READ,
- flash_command_read,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_READ, flash_command_read, EC_VER_MASK(0));
/**
* Flash write command
@@ -1376,8 +1363,7 @@ static enum ec_status flash_command_write(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_WRITE,
- flash_command_write,
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_WRITE, flash_command_write,
EC_VER_MASK(0) | EC_VER_MASK(EC_VER_FLASH_WRITE));
#ifndef CONFIG_FLASH_MULTIPLE_REGION
@@ -1453,13 +1439,12 @@ static enum ec_status flash_command_erase(struct host_cmd_handler_args *args)
return rc;
}
-
DECLARE_HOST_COMMAND(EC_CMD_FLASH_ERASE, flash_command_erase,
- EC_VER_MASK(0)
+ EC_VER_MASK(0)
#ifdef CONFIG_FLASH_DEFERRED_ERASE
- | EC_VER_MASK(1)
+ | EC_VER_MASK(1)
#endif
- );
+);
static enum ec_status flash_command_protect(struct host_cmd_handler_args *args)
{
@@ -1484,12 +1469,11 @@ static enum ec_status flash_command_protect(struct host_cmd_handler_args *args)
r->flags = crec_flash_get_protect();
/* Indicate which flags are valid on this platform */
- r->valid_flags =
- EC_FLASH_PROTECT_GPIO_ASSERTED |
- EC_FLASH_PROTECT_ERROR_STUCK |
- EC_FLASH_PROTECT_ERROR_INCONSISTENT |
- EC_FLASH_PROTECT_ERROR_UNKNOWN |
- crec_flash_physical_get_valid_flags();
+ r->valid_flags = EC_FLASH_PROTECT_GPIO_ASSERTED |
+ EC_FLASH_PROTECT_ERROR_STUCK |
+ EC_FLASH_PROTECT_ERROR_INCONSISTENT |
+ EC_FLASH_PROTECT_ERROR_UNKNOWN |
+ crec_flash_physical_get_valid_flags();
r->writable_flags = crec_flash_physical_get_writable_flags(r->flags);
args->response_size = sizeof(*r);
@@ -1502,8 +1486,7 @@ static enum ec_status flash_command_protect(struct host_cmd_handler_args *args)
* temporary workaround for a problem in the cros_ec driver. Drop
* EC_VER_MASK(0) once cros_ec driver can send the correct version.
*/
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_PROTECT,
- flash_command_protect,
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_PROTECT, flash_command_protect,
EC_VER_MASK(0) | EC_VER_MASK(1));
static enum ec_status
@@ -1515,23 +1498,21 @@ flash_command_region_info(struct host_cmd_handler_args *args)
switch (p->region) {
case EC_FLASH_REGION_RO:
r->offset = CONFIG_EC_PROTECTED_STORAGE_OFF +
- CONFIG_RO_STORAGE_OFF -
- EC_FLASH_REGION_START;
+ CONFIG_RO_STORAGE_OFF - EC_FLASH_REGION_START;
r->size = EC_FLASH_REGION_RO_SIZE;
break;
case EC_FLASH_REGION_ACTIVE:
r->offset = flash_get_rw_offset(system_get_active_copy()) -
- EC_FLASH_REGION_START;
+ EC_FLASH_REGION_START;
r->size = CONFIG_EC_WRITABLE_STORAGE_SIZE;
break;
case EC_FLASH_REGION_WP_RO:
- r->offset = CONFIG_WP_STORAGE_OFF -
- EC_FLASH_REGION_START;
+ r->offset = CONFIG_WP_STORAGE_OFF - EC_FLASH_REGION_START;
r->size = CONFIG_WP_STORAGE_SIZE;
break;
case EC_FLASH_REGION_UPDATE:
r->offset = flash_get_rw_offset(system_get_update_copy()) -
- EC_FLASH_REGION_START;
+ EC_FLASH_REGION_START;
r->size = CONFIG_EC_WRITABLE_STORAGE_SIZE;
break;
default:
@@ -1541,11 +1522,9 @@ flash_command_region_info(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_REGION_INFO,
- flash_command_region_info,
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_REGION_INFO, flash_command_region_info,
EC_VER_MASK(EC_VER_FLASH_REGION_INFO));
-
#ifdef CONFIG_FLASH_SELECT_REQUIRED
static enum ec_status flash_command_select(struct host_cmd_handler_args *args)
@@ -1554,8 +1533,6 @@ static enum ec_status flash_command_select(struct host_cmd_handler_args *args)
return crec_board_flash_select(p->select);
}
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_SELECT,
- flash_command_select,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_SELECT, flash_command_select, EC_VER_MASK(0));
#endif /* CONFIG_FLASH_SELECT_REQUIRED */
diff --git a/common/fmap.c b/common/fmap.c
index 6bae9c7f85..469fac0ceb 100644
--- a/common/fmap.c
+++ b/common/fmap.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 The Chromium OS Authors. All rights reserved.
+ * Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,7 +13,8 @@
/*
* FMAP structs.
- * See https://chromium.googlesource.com/chromiumos/third_party/flashmap/+/HEAD/lib/fmap.h
+ * See
+ * https://chromium.googlesource.com/chromiumos/third_party/flashmap/+/HEAD/lib/fmap.h
*/
#define FMAP_NAMELEN 32
#define FMAP_SIGNATURE "__FMAP__"
@@ -25,8 +26,8 @@
* For address containing CONFIG_PROGRAM_MEMORY_BASE (symbols in *.RO.lds.S and
* variable), this computes the offset to the start of the image on flash.
*/
-#define RELATIVE_RO(addr) ((addr) - CONFIG_PROGRAM_MEMORY_BASE - \
- CONFIG_RO_MEM_OFF)
+#define RELATIVE_RO(addr) \
+ ((addr)-CONFIG_PROGRAM_MEMORY_BASE - CONFIG_RO_MEM_OFF)
/*
* All internal EC code assumes that offsets are provided relative to
@@ -45,23 +46,23 @@
#endif
struct fmap_header {
- char fmap_signature[FMAP_SIGNATURE_SIZE];
- uint8_t fmap_ver_major;
- uint8_t fmap_ver_minor;
- uint64_t fmap_base;
- uint32_t fmap_size;
- char fmap_name[FMAP_NAMELEN];
- uint16_t fmap_nareas;
+ char fmap_signature[FMAP_SIGNATURE_SIZE];
+ uint8_t fmap_ver_major;
+ uint8_t fmap_ver_minor;
+ uint64_t fmap_base;
+ uint32_t fmap_size;
+ char fmap_name[FMAP_NAMELEN];
+ uint16_t fmap_nareas;
} __packed;
-#define FMAP_AREA_STATIC BIT(0) /* can be checksummed */
-#define FMAP_AREA_COMPRESSED BIT(1) /* may be compressed */
-#define FMAP_AREA_RO BIT(2) /* writes may fail */
+#define FMAP_AREA_STATIC BIT(0) /* can be checksummed */
+#define FMAP_AREA_COMPRESSED BIT(1) /* may be compressed */
+#define FMAP_AREA_RO BIT(2) /* writes may fail */
struct fmap_area_header {
uint32_t area_offset;
uint32_t area_size;
- char area_name[FMAP_NAMELEN];
+ char area_name[FMAP_NAMELEN];
uint16_t area_flags;
} __packed;
@@ -77,19 +78,18 @@ struct fmap_area_header {
#define NUM_EC_FMAP_AREAS_ROLLBACK 0
#endif
#ifdef CONFIG_RW_B
-# ifdef CONFIG_RWSIG_TYPE_RWSIG
-# define NUM_EC_FMAP_AREAS_RW_B 2
-# else
-# define NUM_EC_FMAP_AREAS_RW_B 1
-# endif
+#ifdef CONFIG_RWSIG_TYPE_RWSIG
+#define NUM_EC_FMAP_AREAS_RW_B 2
+#else
+#define NUM_EC_FMAP_AREAS_RW_B 1
+#endif
#else
-#define NUM_EC_FMAP_AREAS_RW_B 0
+#define NUM_EC_FMAP_AREAS_RW_B 0
#endif
-#define NUM_EC_FMAP_AREAS (7 + \
- NUM_EC_FMAP_AREAS_RWSIG + \
- NUM_EC_FMAP_AREAS_ROLLBACK + \
- NUM_EC_FMAP_AREAS_RW_B)
+#define NUM_EC_FMAP_AREAS \
+ (7 + NUM_EC_FMAP_AREAS_RWSIG + NUM_EC_FMAP_AREAS_ROLLBACK + \
+ NUM_EC_FMAP_AREAS_RW_B)
const struct _ec_fmap {
struct fmap_header header;
@@ -97,7 +97,7 @@ const struct _ec_fmap {
} ec_fmap __keep __attribute__((section(".google"))) = {
/* Header */
{
- .fmap_signature = {'_', '_', 'F', 'M', 'A', 'P', '_', '_'},
+ .fmap_signature = { '_', '_', 'F', 'M', 'A', 'P', '_', '_' },
.fmap_ver_major = FMAP_VER_MAJOR,
.fmap_ver_minor = FMAP_VER_MINOR,
.fmap_base = CONFIG_PROGRAM_MEMORY_BASE,
@@ -108,7 +108,7 @@ const struct _ec_fmap {
},
{
- /* RO Firmware */
+ /* RO Firmware */
{
/*
* Range of RO firmware to be updated. EC_RO
@@ -120,7 +120,7 @@ const struct _ec_fmap {
*/
.area_name = "EC_RO",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
- FMAP_REGION_START,
+ FMAP_REGION_START,
.area_size = CONFIG_RO_SIZE + CONFIG_RO_STORAGE_OFF,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -128,7 +128,8 @@ const struct _ec_fmap {
/* (Optional) RO firmware code. */
.area_name = "FR_MAIN",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RO_STORAGE_OFF,
+ FMAP_REGION_START +
+ CONFIG_RO_STORAGE_OFF,
.area_size = CONFIG_RO_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -138,10 +139,11 @@ const struct _ec_fmap {
* ASCII, and padded with \0.
*/
.area_name = "RO_FRID",
- .area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
+ .area_offset =
+ CONFIG_EC_PROTECTED_STORAGE_OFF -
FMAP_REGION_START + CONFIG_RO_STORAGE_OFF +
RELATIVE_RO((uint32_t)__image_data_offset) +
- offsetof(struct image_data, version),
+ offsetof(struct image_data, version),
.area_size = sizeof(current_image_data.version),
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -150,8 +152,9 @@ const struct _ec_fmap {
{
.area_name = "FMAP",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RO_STORAGE_OFF +
- RELATIVE_RO((uint32_t)&ec_fmap),
+ FMAP_REGION_START +
+ CONFIG_RO_STORAGE_OFF +
+ RELATIVE_RO((uint32_t)&ec_fmap),
.area_size = sizeof(ec_fmap),
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -162,8 +165,7 @@ const struct _ec_fmap {
* EC_RO and aligned to hardware specification.
*/
.area_name = "WP_RO",
- .area_offset = CONFIG_WP_STORAGE_OFF -
- FMAP_REGION_START,
+ .area_offset = CONFIG_WP_STORAGE_OFF - FMAP_REGION_START,
.area_size = CONFIG_WP_STORAGE_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -172,8 +174,9 @@ const struct _ec_fmap {
/* RO public key address, for RW verification */
.area_name = "KEY_RO",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RO_PUBKEY_ADDR -
- CONFIG_PROGRAM_MEMORY_BASE,
+ FMAP_REGION_START +
+ CONFIG_RO_PUBKEY_ADDR -
+ CONFIG_PROGRAM_MEMORY_BASE,
.area_size = CONFIG_RO_PUBKEY_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -181,10 +184,11 @@ const struct _ec_fmap {
/* RW Firmware */
{
- /* The range of RW firmware to be auto-updated. */
+ /* The range of RW firmware to be auto-updated. */
.area_name = "EC_RW",
.area_offset = CONFIG_EC_WRITABLE_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RW_STORAGE_OFF,
+ FMAP_REGION_START +
+ CONFIG_RW_STORAGE_OFF,
.area_size = CONFIG_RW_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -197,10 +201,11 @@ const struct _ec_fmap {
* accommodate image asymmetry.
*/
.area_name = "RW_FWID",
- .area_offset = CONFIG_EC_WRITABLE_STORAGE_OFF -
+ .area_offset =
+ CONFIG_EC_WRITABLE_STORAGE_OFF -
FMAP_REGION_START + CONFIG_RW_STORAGE_OFF +
RELATIVE_RO((uint32_t)__image_data_offset) +
- offsetof(struct image_data, version),
+ offsetof(struct image_data, version),
.area_size = sizeof(current_image_data.version),
.area_flags = FMAP_AREA_STATIC,
},
@@ -213,22 +218,22 @@ const struct _ec_fmap {
* accommodate image asymmetry.
*/
.area_name = "RW_RBVER",
- .area_offset = CONFIG_EC_WRITABLE_STORAGE_OFF -
+ .area_offset =
+ CONFIG_EC_WRITABLE_STORAGE_OFF -
FMAP_REGION_START + CONFIG_RW_STORAGE_OFF +
RELATIVE_RO((uint32_t)__image_data_offset) +
offsetof(struct image_data, rollback_version),
- .area_size = sizeof(
- current_image_data.rollback_version),
+ .area_size = sizeof(current_image_data.rollback_version),
.area_flags = FMAP_AREA_STATIC,
},
#endif
#ifdef CONFIG_RWSIG_TYPE_RWSIG
{
- /* RW image signature */
+ /* RW image signature */
.area_name = "SIG_RW",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RW_SIG_ADDR -
- CONFIG_PROGRAM_MEMORY_BASE,
+ FMAP_REGION_START + CONFIG_RW_SIG_ADDR -
+ CONFIG_PROGRAM_MEMORY_BASE,
.area_size = CONFIG_RW_SIG_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -236,21 +241,22 @@ const struct _ec_fmap {
#ifdef CONFIG_RW_B
/* RW Firmware */
{
- /* The range of RW firmware to be auto-updated. */
+ /* The range of RW firmware to be auto-updated. */
.area_name = "EC_RW_B",
.area_offset = CONFIG_EC_WRITABLE_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RW_STORAGE_OFF +
- CONFIG_RW_SIZE,
+ FMAP_REGION_START +
+ CONFIG_RW_STORAGE_OFF + CONFIG_RW_SIZE,
.area_size = CONFIG_RW_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
#ifdef CONFIG_RWSIG_TYPE_RWSIG
{
- /* RW_B image signature */
+ /* RW_B image signature */
.area_name = "SIG_RW_B",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
- FMAP_REGION_START + CONFIG_RW_B_SIG_ADDR -
- CONFIG_PROGRAM_MEMORY_BASE,
+ FMAP_REGION_START +
+ CONFIG_RW_B_SIG_ADDR -
+ CONFIG_PROGRAM_MEMORY_BASE,
.area_size = CONFIG_RW_SIG_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
diff --git a/common/fpsensor/build.mk b/common/fpsensor/build.mk
index b2bb248efc..2b476bfa51 100644
--- a/common/fpsensor/build.mk
+++ b/common/fpsensor/build.mk
@@ -1,4 +1,4 @@
-# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Copyright 2019 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/common/fpsensor/fpsensor.c b/common/fpsensor/fpsensor.c
index 12904c0b39..bd09ed5c3a 100644
--- a/common/fpsensor/fpsensor.c
+++ b/common/fpsensor/fpsensor.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -42,14 +42,14 @@ static timestamp_t encryption_deadline;
#define FP_SENSOR_IMAGE_OFFSET 0
#endif
-#define FP_MODE_ANY_CAPTURE (FP_MODE_CAPTURE | FP_MODE_ENROLL_IMAGE | \
- FP_MODE_MATCH)
-#define FP_MODE_ANY_DETECT_FINGER (FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
- FP_MODE_ANY_CAPTURE)
-#define FP_MODE_ANY_WAIT_IRQ (FP_MODE_FINGER_DOWN | FP_MODE_ANY_CAPTURE)
+#define FP_MODE_ANY_CAPTURE \
+ (FP_MODE_CAPTURE | FP_MODE_ENROLL_IMAGE | FP_MODE_MATCH)
+#define FP_MODE_ANY_DETECT_FINGER \
+ (FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | FP_MODE_ANY_CAPTURE)
+#define FP_MODE_ANY_WAIT_IRQ (FP_MODE_FINGER_DOWN | FP_MODE_ANY_CAPTURE)
/* Delay between 2 s of the sensor to detect finger removal */
-#define FINGER_POLLING_DELAY (100*MSEC)
+#define FINGER_POLLING_DELAY (100 * MSEC)
/* Timing statistics. */
static uint32_t capture_time_us;
@@ -76,8 +76,8 @@ static inline int is_raw_capture(uint32_t mode)
{
int capture_type = FP_CAPTURE_TYPE(mode);
- return (capture_type == FP_CAPTURE_VENDOR_FORMAT
- || capture_type == FP_CAPTURE_QUALITY_TEST);
+ return (capture_type == FP_CAPTURE_VENDOR_FORMAT ||
+ capture_type == FP_CAPTURE_QUALITY_TEST);
}
__maybe_unused static bool fp_match_success(int match_result)
@@ -92,10 +92,10 @@ static inline int is_test_capture(uint32_t mode)
{
int capture_type = FP_CAPTURE_TYPE(mode);
- return (mode & FP_MODE_CAPTURE)
- && (capture_type == FP_CAPTURE_PATTERN0
- || capture_type == FP_CAPTURE_PATTERN1
- || capture_type == FP_CAPTURE_RESET_TEST);
+ return (mode & FP_MODE_CAPTURE) &&
+ (capture_type == FP_CAPTURE_PATTERN0 ||
+ capture_type == FP_CAPTURE_PATTERN1 ||
+ capture_type == FP_CAPTURE_RESET_TEST);
}
/*
@@ -119,8 +119,8 @@ static uint32_t fp_process_enroll(void)
res = fp_finger_enroll(fp_buffer, &percent);
CPRINTS("[%d]Enroll =>%d (%d%%)", templ_valid, res, percent);
if (res < 0)
- return EC_MKBP_FP_ENROLL
- | EC_MKBP_FP_ERRCODE(EC_MKBP_FP_ERR_ENROLL_INTERNAL);
+ return EC_MKBP_FP_ENROLL |
+ EC_MKBP_FP_ERRCODE(EC_MKBP_FP_ERR_ENROLL_INTERNAL);
templ_dirty |= BIT(templ_valid);
if (percent == 100) {
res = fp_enrollment_finish(fp_template[templ_valid]);
@@ -128,15 +128,15 @@ static uint32_t fp_process_enroll(void)
res = EC_MKBP_FP_ERR_ENROLL_INTERNAL;
} else {
template_newly_enrolled = templ_valid;
- fp_enable_positive_match_secret(templ_valid,
- &positive_match_secret_state);
+ fp_enable_positive_match_secret(
+ templ_valid, &positive_match_secret_state);
templ_valid++;
}
sensor_mode &= ~FP_MODE_ENROLL_SESSION;
enroll_session &= ~FP_MODE_ENROLL_SESSION;
}
- return EC_MKBP_FP_ENROLL | EC_MKBP_FP_ERRCODE(res)
- | (percent << EC_MKBP_FP_ENROLL_PROGRESS_OFFSET);
+ return EC_MKBP_FP_ENROLL | EC_MKBP_FP_ERRCODE(res) |
+ (percent << EC_MKBP_FP_ENROLL_PROGRESS_OFFSET);
}
static uint32_t fp_process_match(void)
@@ -161,8 +161,8 @@ static uint32_t fp_process_match(void)
* with EC_MKBP_FP_ERR_MATCH_NO_INTERNAL.
*/
if (fgr >= 0 && fgr < FP_MAX_FINGER_COUNT) {
- fp_enable_positive_match_secret(fgr,
- &positive_match_secret_state);
+ fp_enable_positive_match_secret(
+ fgr, &positive_match_secret_state);
} else {
res = EC_MKBP_FP_ERR_MATCH_NO_INTERNAL;
}
@@ -187,8 +187,9 @@ static uint32_t fp_process_match(void)
timestamps_invalid |= FPSTATS_MATCHING_INV;
matching_time_us = time_since32(t0);
- return EC_MKBP_FP_MATCH | EC_MKBP_FP_ERRCODE(res)
- | ((fgr << EC_MKBP_FP_MATCH_IDX_OFFSET) & EC_MKBP_FP_MATCH_IDX_MASK);
+ return EC_MKBP_FP_MATCH | EC_MKBP_FP_ERRCODE(res) |
+ ((fgr << EC_MKBP_FP_MATCH_IDX_OFFSET) &
+ EC_MKBP_FP_MATCH_IDX_MASK);
}
static void fp_process_finger(void)
@@ -260,12 +261,12 @@ void fp_task(void)
} else {
fp_enrollment_finish(NULL);
}
- enroll_session =
- sensor_mode & FP_MODE_ENROLL_SESSION;
+ enroll_session = sensor_mode &
+ FP_MODE_ENROLL_SESSION;
}
if (is_test_capture(mode)) {
- fp_sensor_acquire_image_with_mode(fp_buffer,
- FP_CAPTURE_TYPE(mode));
+ fp_sensor_acquire_image_with_mode(
+ fp_buffer, FP_CAPTURE_TYPE(mode));
sensor_mode &= ~FP_MODE_CAPTURE;
send_mkbp_event(EC_MKBP_FP_IMAGE_READY);
continue;
@@ -343,13 +344,14 @@ static enum ec_status fp_command_passthru(struct host_cmd_handler_args *args)
if (system_is_locked())
return EC_RES_ACCESS_DENIED;
- if (params->len > args->params_size +
- offsetof(struct ec_params_fp_passthru, data) ||
+ if (params->len >
+ args->params_size +
+ offsetof(struct ec_params_fp_passthru, data) ||
params->len > args->response_max)
return EC_RES_INVALID_PARAM;
- rc = spi_transaction_async(&spi_devices[0], params->data,
- params->len, out, SPI_READBACK_ALL);
+ rc = spi_transaction_async(&spi_devices[0], params->data, params->len,
+ out, SPI_READBACK_ALL);
if (params->flags & EC_FP_FLAG_NOT_COMPLETE)
rc |= spi_transaction_wait(&spi_devices[0]);
else
@@ -381,8 +383,9 @@ static enum ec_status fp_command_info(struct host_cmd_handler_args *args)
r->template_version = FP_TEMPLATE_FORMAT_VERSION;
/* V1 is identical to V0 with more information appended */
- args->response_size = args->version ? sizeof(*r) :
- sizeof(struct ec_response_fp_info_v0);
+ args->response_size = args->version ?
+ sizeof(*r) :
+ sizeof(struct ec_response_fp_info_v0);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_FP_INFO, fp_command_info,
@@ -472,23 +475,27 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args)
*/
enc_info = (void *)fp_enc_buffer;
enc_info->struct_version = FP_TEMPLATE_FORMAT_VERSION;
- init_trng();
- rand_bytes(enc_info->nonce, FP_CONTEXT_NONCE_BYTES);
- rand_bytes(enc_info->encryption_salt,
- FP_CONTEXT_ENCRYPTION_SALT_BYTES);
- exit_trng();
+ trng_init();
+ trng_rand_bytes(enc_info->nonce, FP_CONTEXT_NONCE_BYTES);
+ trng_rand_bytes(enc_info->encryption_salt,
+ FP_CONTEXT_ENCRYPTION_SALT_BYTES);
+ trng_exit();
- if (fgr == template_newly_enrolled) {
+ /*
+ * TODO(http://b/244781166): Use consistent types so cast is
+ * not needed.
+ */
+ if (fgr == (uint32_t)template_newly_enrolled) {
/*
* Newly enrolled templates need new positive match
* salt, new positive match secret and new validation
* value.
*/
template_newly_enrolled = FP_NO_SUCH_TEMPLATE;
- init_trng();
- rand_bytes(fp_positive_match_salt[fgr],
- FP_POSITIVE_MATCH_SALT_BYTES);
- exit_trng();
+ trng_init();
+ trng_rand_bytes(fp_positive_match_salt[fgr],
+ FP_POSITIVE_MATCH_SALT_BYTES);
+ trng_exit();
}
ret = derive_encryption_key(key, enc_info->encryption_salt);
@@ -508,8 +515,7 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args)
/* Encrypt the secret blob in-place. */
ret = aes_gcm_encrypt(key, SBP_ENC_KEY_LEN, encrypted_template,
- encrypted_template,
- encrypted_blob_size,
+ encrypted_template, encrypted_blob_size,
enc_info->nonce, FP_CONTEXT_NONCE_BYTES,
enc_info->tag, FP_CONTEXT_TAG_BYTES);
always_memset(key, 0, sizeof(key));
@@ -550,12 +556,11 @@ DECLARE_HOST_COMMAND(EC_CMD_FP_STATS, fp_command_stats, EC_VER_MASK(0));
static bool template_needs_validation_value(
struct ec_fp_template_encryption_metadata *enc_info)
{
- return enc_info->struct_version == 3
- && FP_TEMPLATE_FORMAT_VERSION == 4;
+ return enc_info->struct_version == 3 && FP_TEMPLATE_FORMAT_VERSION == 4;
}
-static int validate_template_format(
- struct ec_fp_template_encryption_metadata *enc_info)
+static int
+validate_template_format(struct ec_fp_template_encryption_metadata *enc_info)
{
if (template_needs_validation_value(enc_info))
/* The host requested migration to v4. */
@@ -619,9 +624,8 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args)
if (enc_info->struct_version <= 3) {
encrypted_blob_size = sizeof(fp_template[0]);
} else {
- encrypted_blob_size =
- sizeof(fp_template[0]) +
- sizeof(fp_positive_match_salt[0]);
+ encrypted_blob_size = sizeof(fp_template[0]) +
+ sizeof(fp_positive_match_salt[0]);
}
ret = derive_encryption_key(key, enc_info->encryption_salt);
@@ -632,8 +636,7 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args)
/* Decrypt the secret blob in-place. */
ret = aes_gcm_decrypt(key, SBP_ENC_KEY_LEN, encrypted_template,
- encrypted_template,
- encrypted_blob_size,
+ encrypted_template, encrypted_blob_size,
enc_info->nonce, FP_CONTEXT_NONCE_BYTES,
enc_info->tag, FP_CONTEXT_TAG_BYTES);
always_memset(key, 0, sizeof(key));
@@ -647,10 +650,10 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args)
sizeof(fp_template[0]));
if (template_needs_validation_value(enc_info)) {
CPRINTS("fgr%d: Generating positive match salt.", idx);
- init_trng();
- rand_bytes(positive_match_salt,
- FP_POSITIVE_MATCH_SALT_BYTES);
- exit_trng();
+ trng_init();
+ trng_rand_bytes(positive_match_salt,
+ FP_POSITIVE_MATCH_SALT_BYTES);
+ trng_exit();
}
if (bytes_are_trivial(positive_match_salt,
sizeof(fp_positive_match_salt[0]))) {
@@ -703,7 +706,8 @@ DECLARE_HOST_COMMAND(EC_CMD_FP_TEMPLATE, fp_command_template, EC_VER_MASK(0));
* Add the following to your ${HOME}/.screenrc:
*
* zmodem catch
- * zmodem recvcmd '!!! bash -c "ascii-xfr -rdv /tmp/finger.pgm && display /tmp/finger.pgm"'
+ * zmodem recvcmd '!!! bash -c "ascii-xfr -rdv /tmp/finger.pgm && display
+ * /tmp/finger.pgm"'
*
* From *outside the chroot*, use screen to connect to UART console:
*
@@ -761,7 +765,7 @@ static enum ec_error_list fp_console_action(uint32_t mode)
return EC_ERROR_TIMEOUT;
}
-static int command_fpcapture(int argc, char **argv)
+static int command_fpcapture(int argc, const char **argv)
{
int capture_type = FP_CAPTURE_SIMPLE_IMAGE;
uint32_t mode;
@@ -781,8 +785,8 @@ static int command_fpcapture(int argc, char **argv)
if (*e || capture_type < 0)
return EC_ERROR_PARAM1;
}
- mode = FP_MODE_CAPTURE | ((capture_type << FP_MODE_CAPTURE_TYPE_SHIFT)
- & FP_MODE_CAPTURE_TYPE_MASK);
+ mode = FP_MODE_CAPTURE | ((capture_type << FP_MODE_CAPTURE_TYPE_SHIFT) &
+ FP_MODE_CAPTURE_TYPE_MASK);
rc = fp_console_action(mode);
if (rc == EC_SUCCESS)
@@ -794,13 +798,13 @@ DECLARE_CONSOLE_COMMAND_FLAGS(fpcapture, command_fpcapture, NULL,
"Capture fingerprint in PGM format",
CMD_FLAG_RESTRICTED);
-static int command_fpenroll(int argc, char **argv)
+static int command_fpenroll(int argc, const char **argv)
{
enum ec_error_list rc;
int percent = 0;
uint32_t event;
- static const char * const enroll_str[] = {"OK", "Low Quality",
- "Immobile", "Low Coverage"};
+ static const char *const enroll_str[] = { "OK", "Low Quality",
+ "Immobile", "Low Coverage" };
/*
* TODO(b/142944002): Remove this redundant check for system_is_locked
@@ -832,11 +836,9 @@ static int command_fpenroll(int argc, char **argv)
return rc;
}
DECLARE_CONSOLE_COMMAND_FLAGS(fpenroll, command_fpenroll, NULL,
- "Enroll a new fingerprint",
- CMD_FLAG_RESTRICTED);
-
+ "Enroll a new fingerprint", CMD_FLAG_RESTRICTED);
-static int command_fpmatch(int argc, char **argv)
+static int command_fpmatch(int argc, const char **argv)
{
enum ec_error_list rc = fp_console_action(FP_MODE_MATCH);
uint32_t event = atomic_clear(&fp_events);
@@ -854,7 +856,7 @@ static int command_fpmatch(int argc, char **argv)
DECLARE_CONSOLE_COMMAND(fpmatch, command_fpmatch, NULL,
"Run match algorithm against finger");
-static int command_fpclear(int argc, char **argv)
+static int command_fpclear(int argc, const char **argv)
{
/*
* We intentionally run this on the fp_task so that we use the
@@ -872,7 +874,7 @@ static int command_fpclear(int argc, char **argv)
DECLARE_CONSOLE_COMMAND(fpclear, command_fpclear, NULL,
"Clear fingerprint sensor context");
-static int command_fpmaintenance(int argc, char **argv)
+static int command_fpmaintenance(int argc, const char **argv)
{
#ifdef HAVE_FP_PRIVATE_DRIVER
return fp_maintenance();
diff --git a/common/fpsensor/fpsensor_crypto.c b/common/fpsensor/fpsensor_crypto.c
index 73d7aca681..257042197e 100644
--- a/common/fpsensor/fpsensor_crypto.c
+++ b/common/fpsensor/fpsensor_crypto.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -17,7 +17,7 @@
#error "fpsensor requires AES, AES_GCM and ROLLBACK_SECRET_SIZE"
#endif
-static int get_ikm(uint8_t *ikm)
+test_export_static int get_ikm(uint8_t *ikm)
{
int ret;
@@ -44,6 +44,14 @@ static int get_ikm(uint8_t *ikm)
return EC_SUCCESS;
}
+test_mockable void compute_hmac_sha256(uint8_t *output, const uint8_t *key,
+ const int key_len,
+ const uint8_t *message,
+ const int message_len)
+{
+ hmac_SHA256(output, key, key_len, message, message_len);
+}
+
static void hkdf_extract(uint8_t *prk, const uint8_t *salt, size_t salt_size,
const uint8_t *ikm, size_t ikm_size)
{
@@ -51,12 +59,12 @@ static void hkdf_extract(uint8_t *prk, const uint8_t *salt, size_t salt_size,
* Derive a key with the "extract" step of HKDF
* https://tools.ietf.org/html/rfc5869#section-2.2
*/
- hmac_SHA256(prk, salt, salt_size, ikm, ikm_size);
+ compute_hmac_sha256(prk, salt, salt_size, ikm, ikm_size);
}
static int hkdf_expand_one_step(uint8_t *out_key, size_t out_key_size,
- uint8_t *prk, size_t prk_size,
- uint8_t *info, size_t info_size)
+ uint8_t *prk, size_t prk_size, uint8_t *info,
+ size_t info_size)
{
uint8_t key_buf[SHA256_DIGEST_SIZE];
uint8_t message_buf[SHA256_DIGEST_SIZE + 1];
@@ -75,7 +83,7 @@ static int hkdf_expand_one_step(uint8_t *out_key, size_t out_key_size,
memcpy(message_buf, info, info_size);
/* 1 step, set the counter byte to 1. */
message_buf[info_size] = 0x01;
- hmac_SHA256(key_buf, prk, prk_size, message_buf, info_size + 1);
+ compute_hmac_sha256(key_buf, prk, prk_size, message_buf, info_size + 1);
memcpy(out_key, key_buf, out_key_size);
always_memset(key_buf, 0, sizeof(key_buf));
@@ -83,8 +91,8 @@ static int hkdf_expand_one_step(uint8_t *out_key, size_t out_key_size,
return EC_SUCCESS;
}
-int hkdf_expand(uint8_t *out_key, size_t L, const uint8_t *prk,
- size_t prk_size, const uint8_t *info, size_t info_size)
+int hkdf_expand(uint8_t *out_key, size_t L, const uint8_t *prk, size_t prk_size,
+ const uint8_t *info, size_t info_size)
{
/*
* "Expand" step of HKDF.
@@ -123,8 +131,8 @@ int hkdf_expand(uint8_t *out_key, size_t L, const uint8_t *prk,
memcpy(info_buffer, T, T_len);
memcpy(info_buffer + T_len, info, info_size);
info_buffer[T_len + info_size] = count;
- hmac_SHA256(T_buffer, prk, prk_size, info_buffer,
- T_len + info_size + sizeof(count));
+ compute_hmac_sha256(T_buffer, prk, prk_size, info_buffer,
+ T_len + info_size + sizeof(count));
memcpy(out_key, T_buffer, block_size);
T += T_len;
@@ -216,11 +224,9 @@ int derive_encryption_key(uint8_t *out_key, const uint8_t *salt)
return ret;
}
-int aes_gcm_encrypt(const uint8_t *key, int key_size,
- const uint8_t *plaintext,
- uint8_t *ciphertext, int text_size,
- const uint8_t *nonce, int nonce_size,
- uint8_t *tag, int tag_size)
+int aes_gcm_encrypt(const uint8_t *key, int key_size, const uint8_t *plaintext,
+ uint8_t *ciphertext, int text_size, const uint8_t *nonce,
+ int nonce_size, uint8_t *tag, int tag_size)
{
int res;
AES_KEY aes_key;
@@ -251,8 +257,8 @@ int aes_gcm_encrypt(const uint8_t *key, int key_size,
int aes_gcm_decrypt(const uint8_t *key, int key_size, uint8_t *plaintext,
const uint8_t *ciphertext, int text_size,
- const uint8_t *nonce, int nonce_size,
- const uint8_t *tag, int tag_size)
+ const uint8_t *nonce, int nonce_size, const uint8_t *tag,
+ int tag_size)
{
int res;
AES_KEY aes_key;
diff --git a/common/fpsensor/fpsensor_detect_strings.c b/common/fpsensor/fpsensor_detect_strings.c
index 352dc90ee5..af08219ced 100644
--- a/common/fpsensor/fpsensor_detect_strings.c
+++ b/common/fpsensor/fpsensor_detect_strings.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/fpsensor/fpsensor_private.h b/common/fpsensor/fpsensor_private.h
index a42049dece..919c523273 100644
--- a/common/fpsensor/fpsensor_private.h
+++ b/common/fpsensor/fpsensor_private.h
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,8 +10,8 @@
#include <stdint.h>
-#define CPRINTF(format, args...) cprintf(CC_FP, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_FP, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_FP, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_FP, format, ##args)
int validate_fp_buffer_offset(uint32_t buffer_size, uint32_t offset,
uint32_t size);
diff --git a/common/fpsensor/fpsensor_state.c b/common/fpsensor/fpsensor_state.c
index bd907e2c00..8153df9883 100644
--- a/common/fpsensor/fpsensor_state.c
+++ b/common/fpsensor/fpsensor_state.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,25 +19,25 @@
/* Last acquired frame (aligned as it is used by arbitrary binary libraries) */
uint8_t fp_buffer[FP_SENSOR_IMAGE_SIZE] FP_FRAME_SECTION __aligned(4);
/* Fingers templates for the current user */
-uint8_t fp_template[FP_MAX_FINGER_COUNT][FP_ALGORITHM_TEMPLATE_SIZE]
- FP_TEMPLATE_SECTION;
+uint8_t fp_template[FP_MAX_FINGER_COUNT]
+ [FP_ALGORITHM_TEMPLATE_SIZE] FP_TEMPLATE_SECTION;
/* Encryption/decryption buffer */
/* TODO: On-the-fly encryption/decryption without a dedicated buffer */
/*
* Store the encryption metadata at the beginning of the buffer containing the
* ciphered data.
*/
-uint8_t fp_enc_buffer[FP_ALGORITHM_ENCRYPTED_TEMPLATE_SIZE]
- FP_TEMPLATE_SECTION;
+uint8_t fp_enc_buffer[FP_ALGORITHM_ENCRYPTED_TEMPLATE_SIZE] FP_TEMPLATE_SECTION;
/* Salt used in derivation of positive match secret. */
-uint8_t fp_positive_match_salt
- [FP_MAX_FINGER_COUNT][FP_POSITIVE_MATCH_SALT_BYTES];
+uint8_t fp_positive_match_salt[FP_MAX_FINGER_COUNT]
+ [FP_POSITIVE_MATCH_SALT_BYTES];
-struct positive_match_secret_state positive_match_secret_state = {
- .template_matched = FP_NO_SUCH_TEMPLATE,
- .readable = false,
- .deadline.val = 0,
-};
+struct positive_match_secret_state
+ positive_match_secret_state = { .template_matched = FP_NO_SUCH_TEMPLATE,
+ .readable = false,
+ .deadline = {
+ .val = 0,
+ } };
/* Index of the last enrolled but not retrieved template. */
int8_t template_newly_enrolled = FP_NO_SUCH_TEMPLATE;
@@ -178,7 +178,7 @@ static int validate_fp_mode(const uint32_t mode)
return EC_SUCCESS;
}
-int fp_set_sensor_mode(uint32_t mode, uint32_t *mode_output)
+enum ec_status fp_set_sensor_mode(uint32_t mode, uint32_t *mode_output)
{
int ret;
@@ -205,7 +205,7 @@ static enum ec_status fp_command_mode(struct host_cmd_handler_args *args)
const struct ec_params_fp_mode *p = args->params;
struct ec_response_fp_mode *r = args->response;
- int ret = fp_set_sensor_mode(p->mode, &r->mode);
+ enum ec_status ret = fp_set_sensor_mode(p->mode, &r->mode);
if (ret == EC_RES_SUCCESS)
args->response_size = sizeof(*r);
@@ -262,23 +262,22 @@ int fp_enable_positive_match_secret(uint32_t fgr,
return EC_SUCCESS;
}
-void fp_disable_positive_match_secret(
- struct positive_match_secret_state *state)
+void fp_disable_positive_match_secret(struct positive_match_secret_state *state)
{
state->template_matched = FP_NO_SUCH_TEMPLATE;
state->readable = false;
state->deadline.val = 0;
}
-static enum ec_status fp_command_read_match_secret(
- struct host_cmd_handler_args *args)
+static enum ec_status
+fp_command_read_match_secret(struct host_cmd_handler_args *args)
{
const struct ec_params_fp_read_match_secret *params = args->params;
struct ec_response_fp_read_match_secret *response = args->response;
int8_t fgr = params->fgr;
timestamp_t now = get_time();
- struct positive_match_secret_state state_copy
- = positive_match_secret_state;
+ struct positive_match_secret_state state_copy =
+ positive_match_secret_state;
fp_disable_positive_match_secret(&positive_match_secret_state);
@@ -293,13 +292,14 @@ static enum ec_status fp_command_read_match_secret(
}
if (fgr != state_copy.template_matched || !state_copy.readable) {
CPRINTS("Positive match secret for finger %d is not meant to "
- "be read now.", fgr);
+ "be read now.",
+ fgr);
return EC_RES_ACCESS_DENIED;
}
if (derive_positive_match_secret(response->positive_match_secret,
- fp_positive_match_salt[fgr])
- != EC_SUCCESS) {
+ fp_positive_match_salt[fgr]) !=
+ EC_SUCCESS) {
CPRINTS("Failed to derive positive match secret for finger %d",
fgr);
/* Keep the template and encryption salt. */
diff --git a/common/gesture.c b/common/gesture.c
index 0ccd358d54..99d054783d 100644
--- a/common/gesture.c
+++ b/common/gesture.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,9 +19,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_GESTURE, outstr)
-#define CPRINTS(format, args...) cprints(CC_GESTURE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_GESTURE, format, ## args)
-
+#define CPRINTS(format, args...) cprints(CC_GESTURE, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_GESTURE, format, ##args)
/*
* Double tap detection parameters
@@ -34,16 +33,16 @@
* which to check for relatively calm periods. In between the two impulses
* there is a minimum and maximum interstice time allowed.
*/
-#define OUTER_WINDOW \
+#define OUTER_WINDOW \
(CONFIG_GESTURE_TAP_OUTER_WINDOW_T / \
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
-#define INNER_WINDOW \
+#define INNER_WINDOW \
(CONFIG_GESTURE_TAP_INNER_WINDOW_T / \
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
-#define MIN_INTERSTICE \
+#define MIN_INTERSTICE \
(CONFIG_GESTURE_TAP_MIN_INTERSTICE_T / \
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
-#define MAX_INTERSTICE \
+#define MAX_INTERSTICE \
(CONFIG_GESTURE_TAP_MAX_INTERSTICE_T / \
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
#define MAX_WINDOW OUTER_WINDOW
@@ -67,10 +66,10 @@ enum tap_states {
/* Tap sensor to use */
static struct motion_sensor_t *sensor =
-&motion_sensors[CONFIG_GESTURE_TAP_SENSOR];
+ &motion_sensors[CONFIG_GESTURE_TAP_SENSOR];
/* Tap state information */
-static int history_z[MAX_WINDOW]; /* Changes in Z */
+static int history_z[MAX_WINDOW]; /* Changes in Z */
static int history_xy[MAX_WINDOW]; /* Changes in X and Y */
static int state, history_idx;
static int history_initialized, history_init_index;
@@ -166,7 +165,7 @@ static int gesture_tap_for_battery(void)
(OUTER_WINDOW - INNER_WINDOW);
delta_z_inner = sum_z_inner * 1000 / INNER_WINDOW;
delta_xy_outer = (sum_xy_outer - sum_xy_inner) * 1000 /
- (OUTER_WINDOW - INNER_WINDOW);
+ (OUTER_WINDOW - INNER_WINDOW);
delta_xy_inner = sum_xy_inner * 1000 / INNER_WINDOW;
state_cnt++;
@@ -253,13 +252,11 @@ static int gesture_tap_for_battery(void)
}
/* On state transitions, print debug info */
- if (tap_debug &&
- (state != state_p ||
- (state_cnt % 10000 == 9999))) {
+ if (tap_debug && (state != state_p || (state_cnt % 10000 == 9999))) {
/* make sure we don't divide by 0 */
if (delta_z_outer == 0 || delta_xy_inner == 0)
- CPRINTS("tap st %d->%d, error div by 0",
- state_p, state);
+ CPRINTS("tap st %d->%d, error div by 0", state_p,
+ state);
else
CPRINTS("tap st %d->%d, st_cnt %-3d "
"Z_in:Z_out %-3d, Z_in:XY_in %-3d "
@@ -267,10 +264,8 @@ static int gesture_tap_for_battery(void)
"dZ_out %-8.3d",
state_p, state, state_cnt,
delta_z_inner / delta_z_outer,
- delta_z_inner / delta_xy_inner,
- delta_z_inner,
- delta_z_inner_max,
- delta_z_outer);
+ delta_z_inner / delta_xy_inner, delta_z_inner,
+ delta_z_inner_max, delta_z_outer);
}
return ret;
@@ -281,8 +276,7 @@ static void gesture_chipset_resume(void)
/* disable tap detection */
tap_detection = 0;
}
-DECLARE_HOOK(HOOK_CHIPSET_RESUME, gesture_chipset_resume,
- GESTURE_HOOK_PRIO);
+DECLARE_HOOK(HOOK_CHIPSET_RESUME, gesture_chipset_resume, GESTURE_HOOK_PRIO);
static void gesture_chipset_suspend(void)
{
@@ -295,8 +289,7 @@ static void gesture_chipset_suspend(void)
state = TAP_IDLE;
tap_detection = 1;
}
-DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, gesture_chipset_suspend,
- GESTURE_HOOK_PRIO);
+DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, gesture_chipset_suspend, GESTURE_HOOK_PRIO);
void gesture_calc(uint32_t *event)
{
@@ -306,17 +299,17 @@ void gesture_calc(uint32_t *event)
if (gesture_tap_for_battery())
*event |= TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
- MOTIONSENSE_ACTIVITY_DOUBLE_TAP);
+ MOTIONSENSE_ACTIVITY_DOUBLE_TAP);
}
/*****************************************************************************/
/* Console commands */
-static int command_tap_info(int argc, char **argv)
+static int command_tap_info(int argc, const char **argv)
{
int val;
- ccprintf("tap: %s\n", (tap_detection && !lid_is_open()) ?
- "on" : "off");
+ ccprintf("tap: %s\n",
+ (tap_detection && !lid_is_open()) ? "on" : "off");
if (argc > 1) {
if (!parse_bool(argv[1], &val))
@@ -329,6 +322,5 @@ static int command_tap_info(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(tapinfo, command_tap_info,
- "debug on/off",
+DECLARE_CONSOLE_COMMAND(tapinfo, command_tap_info, "debug on/off",
"Print tap information");
diff --git a/common/gpio.c b/common/gpio.c
index 9fa8512e27..2e76116e4c 100644
--- a/common/gpio.c
+++ b/common/gpio.c
@@ -1,10 +1,11 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* GPIO common functionality for Chrome EC */
+#include "builtin/assert.h"
#include "common.h"
#include "gpio.h"
#include "ioexpander.h"
@@ -34,9 +35,9 @@ struct gpio_alt_func {
* Construct the gpio_alt_funcs array. This array is used by gpio_config_module
* to enable and disable GPIO alternate functions on a module by module basis.
*/
-#define ALTERNATE(pinmask, function, module, flagz) \
- {GPIO_##pinmask, .func = (function), .module_id = (module), \
- .flags = (flagz)},
+#define ALTERNATE(pinmask, function, module, flagz) \
+ { GPIO_##pinmask, .func = (function), .module_id = (module), \
+ .flags = (flagz) },
static __const_data const struct gpio_alt_func gpio_alt_funcs[] = {
#include "gpio.wrap"
@@ -74,9 +75,9 @@ static int gpio_config_pins(enum module_id id, uint32_t port, uint32_t pin_mask,
gpio_set_flags_by_mask(
af->port, (af->mask & pin_mask),
enable ? af->flags : GPIO_INPUT);
- gpio_set_alternate_function(af->port,
- (af->mask & pin_mask),
- enable ? af->func : GPIO_ALT_FUNC_NONE);
+ gpio_set_alternate_function(
+ af->port, (af->mask & pin_mask),
+ enable ? af->func : GPIO_ALT_FUNC_NONE);
rv = EC_SUCCESS;
/* We're done here if we were just setting one port. */
if (port != GPIO_CONFIG_ALL_PORTS)
@@ -222,8 +223,8 @@ int gpio_or_ioex_get_level(int signal, int *value)
int signal_is_gpio(int signal)
{
- return ((signal >= GPIO_SIGNAL_START)
- && (signal < GPIO_SIGNAL_START + GPIO_COUNT));
+ return ((signal >= GPIO_SIGNAL_START) &&
+ (signal < GPIO_SIGNAL_START + GPIO_COUNT));
}
__attribute__((weak)) void gpio_set_wakepin(enum gpio_signal signal,
diff --git a/common/gpio_commands.c b/common/gpio_commands.c
index b044524797..d6257ea61d 100644
--- a/common/gpio_commands.c
+++ b/common/gpio_commands.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -67,8 +67,13 @@ static enum ec_error_list set(const char *name, int value)
if (!gpio_is_implemented(signal))
return EC_ERROR_INVAL;
- if (!(gpio_get_default_flags(signal) & GPIO_OUTPUT))
- return EC_ERROR_INVAL;
+ if (IS_ENABLED(CONFIG_GPIO_GET_EXTENDED)) {
+ if (!(gpio_get_flags(signal) & GPIO_OUTPUT))
+ return EC_ERROR_INVAL;
+ } else {
+ if (!(gpio_get_default_flags(signal) & GPIO_OUTPUT))
+ return EC_ERROR_INVAL;
+ }
gpio_set_level(signal, value);
@@ -78,23 +83,18 @@ static enum ec_error_list set(const char *name, int value)
/* Console commands */
struct gpio_flag_description {
- const int bitfield;
- const char* name;
+ const int bitfield;
+ const char *name;
};
__maybe_unused static const struct gpio_flag_description gpio_descriptions[] = {
- {GPIO_INPUT, "I"},
- {GPIO_OUTPUT, "O"},
- {GPIO_LOW, "L"},
- {GPIO_HIGH, "H"},
- {GPIO_OPEN_DRAIN, "ODR"},
- {GPIO_PULL_UP, "PU"},
- {GPIO_PULL_DOWN, "PD"},
- {GPIO_SEL_1P8V, "1P8"},
+ { GPIO_INPUT, "I" }, { GPIO_OUTPUT, "O" },
+ { GPIO_LOW, "L" }, { GPIO_HIGH, "H" },
+ { GPIO_OPEN_DRAIN, "ODR" }, { GPIO_PULL_UP, "PU" },
+ { GPIO_PULL_DOWN, "PD" }, { GPIO_SEL_1P8V, "1P8" },
#ifndef CONFIG_ZEPHYR
- {GPIO_ANALOG, "A"},
- {GPIO_ALTERNATE, "ALT"},
- {GPIO_LOCKED, "LCK"}
+ { GPIO_ANALOG, "A" }, { GPIO_ALTERNATE, "ALT" },
+ { GPIO_LOCKED, "LCK" }
#endif
};
@@ -103,12 +103,13 @@ static void print_gpio_info(int gpio)
int changed, v, i;
if (!gpio_is_implemented(gpio))
- return; /* Skip unsupported signals */
+ return; /* Skip unsupported signals */
v = gpio_get_level(gpio);
changed = last_val_changed(gpio, v);
- /* Split the printf call into multiple calls to reduce the stack usage. */
+ /* Split the printf call into multiple calls to reduce the stack usage.
+ */
ccprintf(" %d%c ", v, (changed ? '*' : ' '));
if (IS_ENABLED(CONFIG_CMD_GPIO_EXTENDED)) {
@@ -126,7 +127,7 @@ static void print_gpio_info(int gpio)
cflush();
}
-static int command_gpio_get(int argc, char **argv)
+static int command_gpio_get(int argc, const char **argv)
{
int i;
@@ -143,18 +144,17 @@ static int command_gpio_get(int argc, char **argv)
/* Otherwise print them all */
for (i = 0; i < GPIO_COUNT; i++) {
if (!gpio_is_implemented(i))
- continue; /* Skip unsupported signals */
+ continue; /* Skip unsupported signals */
print_gpio_info(i);
}
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(gpioget, command_gpio_get,
- "[name]",
+DECLARE_SAFE_CONSOLE_COMMAND(gpioget, command_gpio_get, "[name]",
"Read GPIO value(s)");
-static int command_gpio_set(int argc, char **argv)
+static int command_gpio_set(int argc, const char **argv)
{
#ifdef CONFIG_CMD_GPIO_EXTENDED
int gpio;
@@ -217,9 +217,7 @@ DECLARE_CONSOLE_COMMAND_FLAGS(gpioset, command_gpio_set,
#else
"name <0 | 1>",
#endif
- "Set a GPIO",
- CMD_FLAG_RESTRICTED
-);
+ "Set a GPIO", CMD_FLAG_RESTRICTED);
/*****************************************************************************/
/* Host commands */
@@ -262,7 +260,7 @@ static enum ec_status gpio_command_get(struct host_cmd_handler_args *args)
i = p_v1->get_info.index;
len = strlen(gpio_get_name(i));
- memcpy(r_v1->get_info.name, gpio_get_name(i), len+1);
+ memcpy(r_v1->get_info.name, gpio_get_name(i), len + 1);
r_v1->get_info.val = gpio_get_level(i);
r_v1->get_info.flags = gpio_get_default_flags(i);
args->response_size = sizeof(r_v1->get_info);
@@ -272,7 +270,6 @@ static enum ec_status gpio_command_get(struct host_cmd_handler_args *args)
}
return EC_RES_SUCCESS;
-
}
DECLARE_HOST_COMMAND(EC_CMD_GPIO_GET, gpio_command_get,
EC_VER_MASK(0) | EC_VER_MASK(1));
diff --git a/common/gyro_cal.c b/common/gyro_cal.c
index 572e401b18..8996b85757 100644
--- a/common/gyro_cal.c
+++ b/common/gyro_cal.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/gyro_still_det.c b/common/gyro_still_det.c
index 4574e22e5f..303b73b15f 100644
--- a/common/gyro_still_det.c
+++ b/common/gyro_still_det.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/hooks.c b/common/hooks.c
index 061586c4cb..3bd9689d64 100644
--- a/common/hooks.c
+++ b/common/hooks.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,7 +14,7 @@
#ifdef CONFIG_HOOK_DEBUG
#define CPUTS(outstr) cputs(CC_HOOK, outstr)
-#define CPRINTS(format, args...) cprints(CC_HOOK, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_HOOK, format, ##args)
#else
#define CPUTS(outstr)
#define CPRINTS(format, args...)
@@ -32,37 +32,38 @@ struct hook_ptrs {
* order as enum hook_type.
*/
static const struct hook_ptrs hook_list[] = {
- {__hooks_init, __hooks_init_end},
- {__hooks_pre_freq_change, __hooks_pre_freq_change_end},
- {__hooks_freq_change, __hooks_freq_change_end},
- {__hooks_sysjump, __hooks_sysjump_end},
- {__hooks_chipset_pre_init, __hooks_chipset_pre_init_end},
- {__hooks_chipset_startup, __hooks_chipset_startup_end},
- {__hooks_chipset_resume, __hooks_chipset_resume_end},
- {__hooks_chipset_suspend, __hooks_chipset_suspend_end},
+ { __hooks_init, __hooks_init_end },
+ { __hooks_pre_freq_change, __hooks_pre_freq_change_end },
+ { __hooks_freq_change, __hooks_freq_change_end },
+ { __hooks_sysjump, __hooks_sysjump_end },
+ { __hooks_chipset_pre_init, __hooks_chipset_pre_init_end },
+ { __hooks_chipset_startup, __hooks_chipset_startup_end },
+ { __hooks_chipset_resume, __hooks_chipset_resume_end },
+ { __hooks_chipset_suspend, __hooks_chipset_suspend_end },
#ifdef CONFIG_CHIPSET_RESUME_INIT_HOOK
- {__hooks_chipset_resume_init, __hooks_chipset_resume_init_end},
- {__hooks_chipset_suspend_complete,
- __hooks_chipset_suspend_complete_end},
+ { __hooks_chipset_resume_init, __hooks_chipset_resume_init_end },
+ { __hooks_chipset_suspend_complete,
+ __hooks_chipset_suspend_complete_end },
#endif
- {__hooks_chipset_shutdown, __hooks_chipset_shutdown_end},
- {__hooks_chipset_shutdown_complete,
- __hooks_chipset_shutdown_complete_end},
- {__hooks_chipset_hard_off, __hooks_chipset_hard_off_end},
- {__hooks_chipset_reset, __hooks_chipset_reset_end},
- {__hooks_ac_change, __hooks_ac_change_end},
- {__hooks_lid_change, __hooks_lid_change_end},
- {__hooks_tablet_mode_change, __hooks_tablet_mode_change_end},
- {__hooks_base_attached_change, __hooks_base_attached_change_end},
- {__hooks_pwrbtn_change, __hooks_pwrbtn_change_end},
- {__hooks_battery_soc_change, __hooks_battery_soc_change_end},
+ { __hooks_chipset_shutdown, __hooks_chipset_shutdown_end },
+ { __hooks_chipset_shutdown_complete,
+ __hooks_chipset_shutdown_complete_end },
+ { __hooks_chipset_hard_off, __hooks_chipset_hard_off_end },
+ { __hooks_chipset_reset, __hooks_chipset_reset_end },
+ { __hooks_ac_change, __hooks_ac_change_end },
+ { __hooks_lid_change, __hooks_lid_change_end },
+ { __hooks_tablet_mode_change, __hooks_tablet_mode_change_end },
+ { __hooks_base_attached_change, __hooks_base_attached_change_end },
+ { __hooks_pwrbtn_change, __hooks_pwrbtn_change_end },
+ { __hooks_battery_soc_change, __hooks_battery_soc_change_end },
#ifdef CONFIG_USB_SUSPEND
- {__hooks_usb_change, __hooks_usb_change_end},
+ { __hooks_usb_change, __hooks_usb_change_end },
#endif
- {__hooks_tick, __hooks_tick_end},
- {__hooks_second, __hooks_second_end},
- {__hooks_usb_pd_disconnect, __hooks_usb_pd_disconnect_end},
- {__hooks_usb_pd_connect, __hooks_usb_pd_connect_end},
+ { __hooks_tick, __hooks_tick_end },
+ { __hooks_second, __hooks_second_end },
+ { __hooks_usb_pd_disconnect, __hooks_usb_pd_disconnect_end },
+ { __hooks_usb_pd_connect, __hooks_usb_pd_connect_end },
+ { __hooks_power_supply_change, __hooks_power_supply_change_end },
};
/* Times for deferrable functions */
@@ -149,7 +150,7 @@ int hook_call_deferred(const struct deferred_data *data, int us)
int i = data - __deferred_funcs;
if (data < __deferred_funcs || data >= __deferred_funcs_end)
- return EC_ERROR_INVAL; /* Routine not registered */
+ return EC_ERROR_INVAL; /* Routine not registered */
if (us == -1) {
/* Cancel */
@@ -195,7 +196,7 @@ void hook_task(void *u)
*/
__deferred_until[i] = 0;
interrupt_enable();
- CPRINTS("hook call deferred 0x%pP",
+ CPRINTS("hook call deferred 0x%p",
__deferred_funcs[i].routine);
__deferred_funcs[i].routine();
interrupt_disable();
@@ -264,7 +265,7 @@ static void print_hook_delay(uint32_t interval, uint32_t delay, uint32_t avg)
ccprintf(" Average: %7d us (%d%%)\n\n", avg, percent_avg);
}
-static int command_stats(int argc, char **argv)
+static int command_stats(int argc, const char **argv)
{
int i;
@@ -283,7 +284,5 @@ static int command_stats(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(hookstats, command_stats,
- NULL,
- "Print stats of hooks");
+DECLARE_CONSOLE_COMMAND(hookstats, command_stats, NULL, "Print stats of hooks");
#endif
diff --git a/common/host_command.c b/common/host_command.c
index e05475ce48..89a835a1aa 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,12 +6,14 @@
/* Host command module for Chrome EC */
#include "ap_hang_detect.h"
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "ec_commands.h"
#include "host_command.h"
#include "link_defs.h"
#include "lpc.h"
+#include "printf.h"
#include "shared_mem.h"
#include "system.h"
#include "task.h"
@@ -20,8 +22,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_HOSTCMD, outstr)
-#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ##args)
#define TASK_EVENT_CMD_PENDING TASK_EVENT_CUSTOM_BIT(0)
@@ -42,18 +44,19 @@ static uint8_t host_memmap[EC_MEMMAP_SIZE] __aligned(4);
#endif
static enum {
- HCDEBUG_OFF, /* No host command debug output */
- HCDEBUG_NORMAL, /* Normal output mode; skips repeated commands */
- HCDEBUG_EVERY, /* Print every command */
- HCDEBUG_PARAMS, /* ... and print params for request/response */
+ HCDEBUG_OFF, /* No host command debug output */
+ HCDEBUG_NORMAL, /* Normal output mode; skips repeated commands */
+ HCDEBUG_EVERY, /* Print every command */
+ HCDEBUG_PARAMS, /* ... and print params for request/response */
/* Number of host command debug modes */
HCDEBUG_MODES
} hcdebug = CONFIG_HOSTCMD_DEBUG_MODE;
#ifdef CONFIG_CMD_HCDEBUG
-static const char * const hcdebug_mode_names[HCDEBUG_MODES] = {
- "off", "normal", "every", "params"};
+static const char *const hcdebug_mode_names[HCDEBUG_MODES] = { "off", "normal",
+ "every",
+ "params" };
#endif
#ifdef CONFIG_HOST_COMMAND_STATUS
@@ -343,8 +346,8 @@ void host_packet_receive(struct host_packet *pkt)
args0.version = r->command_version;
args0.params_size = r->data_len;
args0.response = (struct ec_host_response *)(pkt->response) + 1;
- args0.response_max = pkt->response_max -
- sizeof(struct ec_host_response);
+ args0.response_max =
+ pkt->response_max - sizeof(struct ec_host_response);
args0.response_size = 0;
args0.result = EC_RES_SUCCESS;
@@ -440,7 +443,7 @@ void host_command_task(void *u)
/* Process it */
if ((evt & TASK_EVENT_CMD_PENDING) && pending_args) {
pending_args->result =
- host_command_process(pending_args);
+ host_command_process(pending_args);
host_send_response(pending_args);
}
@@ -473,8 +476,7 @@ host_command_proto_version(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION,
- host_command_proto_version,
+DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION, host_command_proto_version,
EC_VER_MASK(0));
static enum ec_status host_command_hello(struct host_cmd_handler_args *args)
@@ -488,9 +490,7 @@ static enum ec_status host_command_hello(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HELLO,
- host_command_hello,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_HELLO, host_command_hello, EC_VER_MASK(0));
static enum ec_status host_command_read_test(struct host_cmd_handler_args *args)
{
@@ -511,9 +511,7 @@ static enum ec_status host_command_read_test(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_READ_TEST,
- host_command_read_test,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_READ_TEST, host_command_read_test, EC_VER_MASK(0));
#ifndef CONFIG_HOSTCMD_X86
/*
@@ -543,8 +541,7 @@ host_command_read_memmap(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_READ_MEMMAP,
- host_command_read_memmap,
+DECLARE_HOST_COMMAND(EC_CMD_READ_MEMMAP, host_command_read_memmap,
EC_VER_MASK(0));
#endif
@@ -555,9 +552,9 @@ host_command_get_cmd_versions(struct host_cmd_handler_args *args)
const struct ec_params_get_cmd_versions_v1 *p_v1 = args->params;
struct ec_response_get_cmd_versions *r = args->response;
- const struct host_command *cmd =
- (args->version == 1) ? find_host_command(p_v1->cmd) :
- find_host_command(p->cmd);
+ const struct host_command *cmd = (args->version == 1) ?
+ find_host_command(p_v1->cmd) :
+ find_host_command(p->cmd);
if (!cmd)
return EC_RES_INVALID_PARAM;
@@ -568,8 +565,7 @@ host_command_get_cmd_versions(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_CMD_VERSIONS,
- host_command_get_cmd_versions,
+DECLARE_HOST_COMMAND(EC_CMD_GET_CMD_VERSIONS, host_command_get_cmd_versions,
EC_VER_MASK(0) | EC_VER_MASK(1));
static int host_command_is_suppressed(uint16_t cmd)
@@ -594,11 +590,13 @@ static void dump_host_command_suppressed(int force)
{
#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
int i;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
if (!force && !timestamp_expired(suppressed_cmd_deadline, NULL))
return;
- CPRINTF("[%pT HC Suppressed:", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s HC Suppressed:", ts_str);
for (i = 0; i < ARRAY_SIZE(hc_suppressed_cmd); i++) {
CPRINTF(" 0x%x=%d", hc_suppressed_cmd[i], hc_suppressed_cnt[i]);
hc_suppressed_cnt[i] = 0;
@@ -614,10 +612,9 @@ static void dump_host_command_suppressed_(void)
{
dump_host_command_suppressed(1);
}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
- dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_SYSJUMP,
- dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, dump_host_command_suppressed_,
+ HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_SYSJUMP, dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
#else
}
#endif /* CONFIG_SUPPRESSED_HOST_COMMANDS */
@@ -659,11 +656,14 @@ static void host_command_debug_request(struct host_cmd_handler_args *args)
hc_prev_cmd = args->command;
}
- if (hcdebug >= HCDEBUG_PARAMS && args->params_size)
- CPRINTS("HC 0x%04x.%d:%ph", args->command,
- args->version,
- HEX_BUF(args->params, args->params_size));
- else
+ if (hcdebug >= HCDEBUG_PARAMS && args->params_size) {
+ char str_buf[hex_str_buf_size(args->params_size)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(args->params, args->params_size));
+ CPRINTS("HC 0x%04x.%d:%s", args->command, args->version,
+ str_buf);
+ } else
CPRINTS("HC 0x%04x", args->command);
}
@@ -693,9 +693,9 @@ uint16_t host_command_process(struct host_cmd_handler_args *args)
if (args->command >= EC_CMD_PASSTHRU_OFFSET(1) &&
args->command <= EC_CMD_PASSTHRU_MAX(1)) {
rv = pd_host_command(args->command - EC_CMD_PASSTHRU_OFFSET(1),
- args->version,
- args->params, args->params_size,
- args->response, args->response_max);
+ args->version, args->params,
+ args->params_size, args->response,
+ args->response_max);
if (rv >= 0) {
/* Success; store actual response size */
args->response_size = rv;
@@ -719,9 +719,14 @@ uint16_t host_command_process(struct host_cmd_handler_args *args)
if (rv != EC_RES_SUCCESS)
CPRINTS("HC 0x%04x err %d", args->command, rv);
- if (hcdebug >= HCDEBUG_PARAMS && args->response_size)
- CPRINTS("HC resp:%ph",
- HEX_BUF(args->response, args->response_size));
+ if (hcdebug >= HCDEBUG_PARAMS && args->response_size) {
+ char str_buf[hex_str_buf_size(args->response_size)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(args->response,
+ args->response_size));
+ CPRINTS("HC resp:%s", str_buf);
+ }
return rv;
}
@@ -739,8 +744,7 @@ host_command_get_comms_status(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_COMMS_STATUS,
- host_command_get_comms_status,
+DECLARE_HOST_COMMAND(EC_CMD_GET_COMMS_STATUS, host_command_get_comms_status,
EC_VER_MASK(0));
/* Resend the last saved response */
@@ -756,8 +760,7 @@ host_command_resend_response(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_RESEND_RESPONSE,
- host_command_resend_response,
+DECLARE_HOST_COMMAND(EC_CMD_RESEND_RESPONSE, host_command_resend_response,
EC_VER_MASK(0));
#endif /* CONFIG_HOST_COMMAND_STATUS */
@@ -775,8 +778,7 @@ host_command_test_protocol(struct host_cmd_handler_args *args)
return p->ec_result;
}
-DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL,
- host_command_test_protocol,
+DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL, host_command_test_protocol,
EC_VER_MASK(0));
/* Returns supported features. */
@@ -791,16 +793,14 @@ host_command_get_features(struct host_cmd_handler_args *args)
r->flags[1] = get_feature_flags1();
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_FEATURES,
- host_command_get_features,
+DECLARE_HOST_COMMAND(EC_CMD_GET_FEATURES, host_command_get_features,
EC_VER_MASK(0));
-
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_HOSTCMD
-static int parse_byte(char *b, uint8_t *out)
+static int parse_byte(const char *b, uint8_t *out)
{
int i;
*out = 0;
@@ -819,7 +819,7 @@ static int parse_byte(char *b, uint8_t *out)
return EC_SUCCESS;
}
-static int parse_params(char *s, uint8_t *params)
+static int parse_params(const char *s, uint8_t *params)
{
int len = 0;
@@ -833,7 +833,7 @@ static int parse_params(char *s, uint8_t *params)
return len;
}
-static int command_host_command(int argc, char **argv)
+static int command_host_command(int argc, const char **argv)
{
struct host_cmd_handler_args args;
char *cmd_params;
@@ -888,23 +888,27 @@ static int command_host_command(int argc, char **argv)
if (res != EC_RES_SUCCESS)
ccprintf("Command returned %d\n", res);
- else if (args.response_size)
- ccprintf("Response: %ph\n",
- HEX_BUF(cmd_params, args.response_size));
- else
+ else if (args.response_size) {
+ char str_buf[hex_str_buf_size(args.response_size)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(cmd_params, args.response_size));
+ ccprintf("Response: %s\n", str_buf);
+ } else
ccprintf("Command succeeded; no response.\n");
shared_mem_release(cmd_params);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(hostcmd, command_host_command,
- "cmd ver param",
+DECLARE_CONSOLE_COMMAND(hostcmd, command_host_command, "cmd ver param",
"Fake host command");
#endif /* CONFIG_CMD_HOSTCMD */
#ifdef CONFIG_CMD_HCDEBUG
-static int command_hcdebug(int argc, char **argv)
+static int command_hcdebug(int argc, const char **argv)
{
+ if (argc >= 3)
+ return EC_ERROR_PARAM_COUNT;
if (argc > 1) {
int i;
diff --git a/common/host_command_controller.c b/common/host_command_controller.c
index eb35622ab3..83d4ce0c86 100644
--- a/common/host_command_controller.c
+++ b/common/host_command_controller.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,8 +16,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_HOSTCMD, outstr)
-#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ##args)
/* Number of attempts for each PD host command */
#define PD_HOST_COMMAND_ATTEMPTS 3
@@ -81,8 +81,7 @@ static int pd_host_command_internal(int command, int version,
*/
i2c_lock(I2C_PORT_PD_MCU, 1);
i2c_set_timeout(I2C_PORT_PD_MCU, PD_HOST_COMMAND_TIMEOUT_US);
- ret = i2c_xfer_unlocked(I2C_PORT_PD_MCU,
- CONFIG_USB_PD_I2C_ADDR_FLAGS,
+ ret = i2c_xfer_unlocked(I2C_PORT_PD_MCU, CONFIG_USB_PD_I2C_ADDR_FLAGS,
&req_buf[0], outsize + sizeof(rq) + 1,
&resp_buf[0], 2, I2C_XFER_START);
i2c_set_timeout(I2C_PORT_PD_MCU, 0);
@@ -96,20 +95,17 @@ static int pd_host_command_internal(int command, int version,
if (resp_len > (insize + sizeof(rs))) {
/* Do a read to generate stop condition */
- i2c_xfer_unlocked(I2C_PORT_PD_MCU,
- CONFIG_USB_PD_I2C_ADDR_FLAGS,
+ i2c_xfer_unlocked(I2C_PORT_PD_MCU, CONFIG_USB_PD_I2C_ADDR_FLAGS,
0, 0, &resp_buf[2], 1, I2C_XFER_STOP);
i2c_lock(I2C_PORT_PD_MCU, 0);
- CPRINTS("response size is too large %d > %d",
- resp_len, insize + sizeof(rs));
+ CPRINTS("response size is too large %d > %d", resp_len,
+ insize + sizeof(rs));
return -EC_RES_RESPONSE_TOO_BIG;
}
/* Receive remaining data */
- ret = i2c_xfer_unlocked(I2C_PORT_PD_MCU,
- CONFIG_USB_PD_I2C_ADDR_FLAGS,
- 0, 0,
- &resp_buf[2], resp_len, I2C_XFER_STOP);
+ ret = i2c_xfer_unlocked(I2C_PORT_PD_MCU, CONFIG_USB_PD_I2C_ADDR_FLAGS,
+ 0, 0, &resp_buf[2], resp_len, I2C_XFER_STOP);
i2c_lock(I2C_PORT_PD_MCU, 0);
if (ret) {
CPRINTS("i2c transaction 2 failed: %d", ret);
@@ -152,10 +148,9 @@ static int pd_host_command_internal(int command, int version,
sum += *d;
}
-
if ((uint8_t)sum) {
- CPRINTS("command 0x%04x bad checksum returned: %d",
- command, sum);
+ CPRINTS("command 0x%04x bad checksum returned: %d", command,
+ sum);
return -EC_RES_INVALID_CHECKSUM;
}
@@ -163,8 +158,7 @@ static int pd_host_command_internal(int command, int version,
return resp_len;
}
-int pd_host_command(int command, int version,
- const void *outdata, int outsize,
+int pd_host_command(int command, int version, const void *outdata, int outsize,
void *indata, int insize)
{
int rv;
@@ -183,13 +177,13 @@ int pd_host_command(int command, int version,
/* If host command error due to i2c bus error, try again. */
if (rv != -EC_RES_BUS_ERROR)
break;
- task_wait_event(50*MSEC);
+ task_wait_event(50 * MSEC);
}
return rv;
}
-static int command_pd_mcu(int argc, char **argv)
+static int command_pd_mcu(int argc, const char **argv)
{
char *e;
static char outbuf[128];
@@ -212,11 +206,11 @@ static int command_pd_mcu(int argc, char **argv)
tmp = strtoi(argv[i], &e, 0);
if (*e)
return EC_ERROR_PARAM3;
- outbuf[i-3] = tmp;
+ outbuf[i - 3] = tmp;
}
ret = pd_host_command(command, version, &outbuf, argc - 3, &inbuf,
- sizeof(inbuf));
+ sizeof(inbuf));
ccprintf("Host command 0x%02x, returned %d\n", command, ret);
for (i = 0; i < ret; i++)
@@ -224,6 +218,5 @@ static int command_pd_mcu(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(pdcmd, command_pd_mcu,
- "cmd ver [params]",
+DECLARE_CONSOLE_COMMAND(pdcmd, command_pd_mcu, "cmd ver [params]",
"Send PD host command");
diff --git a/common/host_command_pd.c b/common/host_command_pd.c
index 7d82249d21..23e2710695 100644
--- a/common/host_command_pd.c
+++ b/common/host_command_pd.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -20,10 +20,10 @@
#include "usb_pd_tcpm.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_PD_HOST_CMD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_PD_HOST_CMD, format, ##args)
-#define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM_BIT(0)
-#define TASK_EVENT_HIBERNATING TASK_EVENT_CUSTOM_BIT(1)
+#define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM_BIT(0)
+#define TASK_EVENT_HIBERNATING TASK_EVENT_CUSTOM_BIT(1)
/* Define local option for if we are a TCPM with an off chip TCPC */
#if defined(CONFIG_USB_POWER_DELIVERY) && !defined(CONFIG_USB_PD_TCPM_STUB)
@@ -61,7 +61,7 @@ void host_command_pd_request_hibernate(void)
#ifdef CONFIG_HOSTCMD_PD
static int pd_send_host_command(struct ec_params_pd_status *ec_status,
- struct ec_response_pd_status *pd_status)
+ struct ec_response_pd_status *pd_status)
{
return pd_host_command(EC_CMD_PD_EXCHANGE_STATUS,
EC_VER_PD_EXCHANGE_STATUS, ec_status,
@@ -126,8 +126,8 @@ static void pd_check_chg_status(struct ec_response_pd_status *pd_status)
#endif
/* Set input current limit */
- rv = charge_set_input_current_limit(MAX(pd_status->curr_lim_ma,
- CONFIG_CHARGER_INPUT_CURRENT), 0);
+ rv = charge_set_input_current_limit(
+ MAX(pd_status->curr_lim_ma, CONFIG_CHARGER_INPUT_CURRENT), 0);
if (rv < 0)
CPRINTS("Failed to set input curr limit from PD MCU");
}
@@ -201,7 +201,7 @@ static void pd_exchange_status(uint32_t ec_state)
if (!first_exchange)
/* Delay to prevent task starvation */
- usleep(5*MSEC);
+ usleep(5 * MSEC);
first_exchange = 0;
} while (pd_get_alert());
#endif /* USB_TCPM_WITH_OFF_CHIP_TCPC */
diff --git a/common/host_event_commands.c b/common/host_event_commands.c
index 177e7cb877..58bca7073e 100644
--- a/common/host_event_commands.c
+++ b/common/host_event_commands.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,13 +19,13 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_EVENTS, outstr)
-#define CPRINTS(format, args...) cprints(CC_EVENTS, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_EVENTS, format, ##args)
/*
* This is used to avoid 64-bit shifts which might require a new library
* function.
*/
-#define HOST_EVENT_32BIT_MASK(x) (1UL << ((x) - 1))
+#define HOST_EVENT_32BIT_MASK(x) (1UL << ((x)-1))
static void host_event_set_bit(host_event_t *ev, uint8_t bit)
{
uint32_t *ptr = (uint32_t *)ev;
@@ -49,7 +49,7 @@ static void host_event_set_bit(host_event_t *ev, uint8_t bit)
#ifdef CONFIG_HOSTCMD_X86
-#define LPC_SYSJUMP_TAG 0x4c50 /* "LP" */
+#define LPC_SYSJUMP_TAG 0x4c50 /* "LP" */
#define LPC_SYSJUMP_OLD_VERSION 1
#define LPC_SYSJUMP_VERSION 2
@@ -72,14 +72,14 @@ static void host_event_set_bit(host_event_t *ev, uint8_t bit)
* - EC_HOST_EVENT_MKBP
*
*/
-#define LPC_HOST_EVENT_ALWAYS_REPORT_DEFAULT_MASK \
- (EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY) | \
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN) | \
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_BATTERY_SHUTDOWN) | \
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_HANG_REBOOT) | \
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_PANIC) | \
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_FASTBOOT) | \
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_MKBP) | \
+#define LPC_HOST_EVENT_ALWAYS_REPORT_DEFAULT_MASK \
+ (EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY) | \
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN) | \
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_BATTERY_SHUTDOWN) | \
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_HANG_REBOOT) | \
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_PANIC) | \
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_FASTBOOT) | \
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_MKBP) | \
EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT))
static host_event_t lpc_host_events;
@@ -114,7 +114,7 @@ static host_event_t lpc_get_all_host_event_masks(void)
return or_mask;
}
-static void lpc_set_host_event_state(host_event_t events)
+test_export_static void lpc_set_host_event_state(host_event_t events)
{
if (events == lpc_host_events)
return;
@@ -136,7 +136,7 @@ host_event_t lpc_get_host_events(void)
int lpc_get_next_host_event(void)
{
host_event_t ev;
- int evt_idx = __builtin_ffs(lpc_host_events);
+ int evt_idx = __builtin_ffs(lpc_host_events);
#ifdef CONFIG_HOST_EVENT64
if (evt_idx == 0) {
@@ -175,7 +175,7 @@ static int lpc_post_sysjump_restore_mask(void)
int size, version;
prev_mask = (const host_event_t *)system_get_jump_tag(LPC_SYSJUMP_TAG,
- &version, &size);
+ &version, &size);
if (!prev_mask || size != sizeof(lpc_host_event_mask) ||
(version != LPC_SYSJUMP_VERSION &&
version != LPC_SYSJUMP_OLD_VERSION))
@@ -332,7 +332,7 @@ void host_set_events(host_event_t mask)
HOST_EVENT_CPRINTS("event set", mask);
if (!IS_ENABLED(CONFIG_ZTEST) &&
- (mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)))
+ (mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)))
system_enter_manual_recovery();
host_events_atomic_or(&events, mask);
@@ -347,8 +347,8 @@ void host_set_events(host_event_t mask)
#error "Config error: MKBP must not be on top of host event"
#endif
host_events_send_mkbp_event(events);
-#endif /* CONFIG_MKBP_EVENT */
-#endif /* !CONFIG_HOSTCMD_X86 */
+#endif /* CONFIG_MKBP_EVENT */
+#endif /* !CONFIG_HOSTCMD_X86 */
}
void host_set_single_event(enum host_event_code event)
@@ -391,7 +391,7 @@ void host_clear_events(host_event_t mask)
#ifdef CONFIG_MKBP_EVENT
host_events_send_mkbp_event(events);
#endif
-#endif /* !CONFIG_HOSTCMD_X86 */
+#endif /* !CONFIG_HOSTCMD_X86 */
}
#ifndef CONFIG_HOSTCMD_X86
@@ -459,7 +459,7 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, clear_events_copy_b, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
/* Console commands */
-static int command_host_event(int argc, char **argv)
+static int command_host_event(int argc, const char **argv)
{
/* Handle sub-commands */
if (argc == 3) {
@@ -494,19 +494,21 @@ static int command_host_event(int argc, char **argv)
HOST_EVENT_CCPRINTF("Events-B: ", events_copy_b);
#ifdef CONFIG_HOSTCMD_X86
HOST_EVENT_CCPRINTF("SMI mask: ",
- lpc_get_host_event_mask(LPC_HOST_EVENT_SMI));
+ lpc_get_host_event_mask(LPC_HOST_EVENT_SMI));
HOST_EVENT_CCPRINTF("SCI mask: ",
- lpc_get_host_event_mask(LPC_HOST_EVENT_SCI));
+ lpc_get_host_event_mask(LPC_HOST_EVENT_SCI));
HOST_EVENT_CCPRINTF("Wake mask: ",
- lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE));
- HOST_EVENT_CCPRINTF("Always report mask: ",
- lpc_get_host_event_mask(LPC_HOST_EVENT_ALWAYS_REPORT));
+ lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE));
+ HOST_EVENT_CCPRINTF(
+ "Always report mask: ",
+ lpc_get_host_event_mask(LPC_HOST_EVENT_ALWAYS_REPORT));
#endif
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(hostevent, command_host_event,
- "[set | clear | clearb | smi | sci | wake | always_report] [mask]",
- "Print / set host event state");
+DECLARE_CONSOLE_COMMAND(
+ hostevent, command_host_event,
+ "[set | clear | clearb | smi | sci | wake | always_report] [mask]",
+ "Print / set host event state");
/*****************************************************************************/
/* Host commands */
@@ -523,8 +525,7 @@ host_event_get_smi_mask(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SMI_MASK,
- host_event_get_smi_mask,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SMI_MASK, host_event_get_smi_mask,
EC_VER_MASK(0));
static enum ec_status
@@ -537,8 +538,7 @@ host_event_get_sci_mask(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SCI_MASK,
- host_event_get_sci_mask,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SCI_MASK, host_event_get_sci_mask,
EC_VER_MASK(0));
static enum ec_status
@@ -551,8 +551,7 @@ host_event_get_wake_mask(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_WAKE_MASK,
- host_event_get_wake_mask,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_WAKE_MASK, host_event_get_wake_mask,
EC_VER_MASK(0));
static enum ec_status
@@ -563,8 +562,7 @@ host_event_set_smi_mask(struct host_cmd_handler_args *args)
lpc_set_host_event_mask(LPC_HOST_EVENT_SMI, p->mask);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SMI_MASK,
- host_event_set_smi_mask,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SMI_MASK, host_event_set_smi_mask,
EC_VER_MASK(0));
static enum ec_status
@@ -575,8 +573,7 @@ host_event_set_sci_mask(struct host_cmd_handler_args *args)
lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, p->mask);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SCI_MASK,
- host_event_set_sci_mask,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SCI_MASK, host_event_set_sci_mask,
EC_VER_MASK(0));
static enum ec_status
@@ -588,8 +585,7 @@ host_event_set_wake_mask(struct host_cmd_handler_args *args)
active_wm_set_by_host = !!p->mask;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_WAKE_MASK,
- host_event_set_wake_mask,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_WAKE_MASK, host_event_set_wake_mask,
EC_VER_MASK(0));
uint8_t lpc_is_active_wm_set_by_host(void)
@@ -597,7 +593,7 @@ uint8_t lpc_is_active_wm_set_by_host(void)
return active_wm_set_by_host;
}
-#endif /* CONFIG_HOSTCMD_X86 */
+#endif /* CONFIG_HOSTCMD_X86 */
static enum ec_status host_event_get_b(struct host_cmd_handler_args *args)
{
@@ -608,9 +604,7 @@ static enum ec_status host_event_get_b(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_B,
- host_event_get_b,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_B, host_event_get_b, EC_VER_MASK(0));
static enum ec_status host_event_clear(struct host_cmd_handler_args *args)
{
@@ -619,9 +613,7 @@ static enum ec_status host_event_clear(struct host_cmd_handler_args *args)
host_clear_events(p->mask);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR,
- host_event_clear,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR, host_event_clear, EC_VER_MASK(0));
static enum ec_status host_event_clear_b(struct host_cmd_handler_args *args)
{
@@ -630,8 +622,7 @@ static enum ec_status host_event_clear_b(struct host_cmd_handler_args *args)
host_clear_events_b(p->mask);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR_B,
- host_event_clear_b,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR_B, host_event_clear_b,
EC_VER_MASK(0));
static enum ec_status host_event_action_get(struct host_cmd_handler_args *args)
@@ -658,8 +649,8 @@ static enum ec_status host_event_action_get(struct host_cmd_handler_args *args)
r->value = lpc_get_host_event_mask(LPC_HOST_EVENT_SMI);
break;
case EC_HOST_EVENT_ALWAYS_REPORT_MASK:
- r->value = lpc_get_host_event_mask
- (LPC_HOST_EVENT_ALWAYS_REPORT);
+ r->value =
+ lpc_get_host_event_mask(LPC_HOST_EVENT_ALWAYS_REPORT);
break;
case EC_HOST_EVENT_ACTIVE_WAKE_MASK:
r->value = lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE);
@@ -704,7 +695,7 @@ static enum ec_status host_event_action_set(struct host_cmd_handler_args *args)
break;
case EC_HOST_EVENT_ALWAYS_REPORT_MASK:
lpc_set_host_event_mask(LPC_HOST_EVENT_ALWAYS_REPORT,
- mask_value);
+ mask_value);
break;
case EC_HOST_EVENT_ACTIVE_WAKE_MASK:
active_wm_set_by_host = !!mask_value;
@@ -783,12 +774,11 @@ host_command_host_event(struct host_cmd_handler_args *args)
}
}
-DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT,
- host_command_host_event,
+DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT, host_command_host_event,
EC_VER_MASK(0));
-#define LAZY_WAKE_MASK_SYSJUMP_TAG 0x4C4D /* LM - Lazy Mask*/
-#define LAZY_WAKE_MASK_HOOK_VERSION 1
+#define LAZY_WAKE_MASK_SYSJUMP_TAG 0x4C4D /* LM - Lazy Mask*/
+#define LAZY_WAKE_MASK_HOOK_VERSION 1
#ifdef CONFIG_HOSTCMD_X86
int get_lazy_wake_mask(enum power_state state, host_event_t *mask)
@@ -818,8 +808,7 @@ int get_lazy_wake_mask(enum power_state state, host_event_t *mask)
static void preserve_lazy_wm(void)
{
system_add_jump_tag(LAZY_WAKE_MASK_SYSJUMP_TAG,
- LAZY_WAKE_MASK_HOOK_VERSION,
- sizeof(lazy_wm),
+ LAZY_WAKE_MASK_HOOK_VERSION, sizeof(lazy_wm),
&lazy_wm);
}
DECLARE_HOOK(HOOK_SYSJUMP, preserve_lazy_wm, HOOK_PRIO_DEFAULT);
@@ -829,9 +818,8 @@ static void restore_lazy_wm(void)
const struct lazy_wake_masks *wm_state;
int version, size;
- wm_state = (const struct lazy_wake_masks *)
- system_get_jump_tag(LAZY_WAKE_MASK_SYSJUMP_TAG,
- &version, &size);
+ wm_state = (const struct lazy_wake_masks *)system_get_jump_tag(
+ LAZY_WAKE_MASK_SYSJUMP_TAG, &version, &size);
if (wm_state && (version == LAZY_WAKE_MASK_HOOK_VERSION) &&
(size == sizeof(lazy_wm))) {
diff --git a/common/hotword_dsp_api.c b/common/hotword_dsp_api.c
index dc53cd0055..24291df8c0 100644
--- a/common/hotword_dsp_api.c
+++ b/common/hotword_dsp_api.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Copyright 2019 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/common/i2c_bitbang.c b/common/i2c_bitbang.c
index 99868b2dc6..01d4f5f31e 100644
--- a/common/i2c_bitbang.c
+++ b/common/i2c_bitbang.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,7 +11,7 @@
#include "util.h"
#define CPUTS(str) cputs(CC_I2C, str)
-#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ##args)
static int started;
@@ -22,8 +22,8 @@ static void i2c_delay(void)
}
/* Number of attempts to unwedge each pin. */
-#define UNWEDGE_SCL_ATTEMPTS 10
-#define UNWEDGE_SDA_ATTEMPTS 3
+#define UNWEDGE_SCL_ATTEMPTS 10
+#define UNWEDGE_SDA_ATTEMPTS 3
static void i2c_bitbang_unwedge(const struct i2c_port_t *i2c_port)
{
@@ -84,7 +84,7 @@ static void i2c_bitbang_unwedge(const struct i2c_port_t *i2c_port)
/* Check if the bus is unwedged. */
if (gpio_get_level(i2c_port->sda) &&
- gpio_get_level(i2c_port->scl))
+ gpio_get_level(i2c_port->scl))
break;
}
@@ -263,7 +263,7 @@ static int i2c_write_byte(const struct i2c_port_t *i2c_port, uint8_t byte)
}
static int i2c_read_byte(const struct i2c_port_t *i2c_port, uint8_t *byte,
- int nack)
+ int nack)
{
int i;
@@ -281,9 +281,8 @@ static int i2c_read_byte(const struct i2c_port_t *i2c_port, uint8_t *byte,
}
static int i2c_bitbang_xfer(const struct i2c_port_t *i2c_port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+ const uint16_t addr_flags, const uint8_t *out,
+ int out_size, uint8_t *in, int in_size, int flags)
{
uint16_t addr_8bit = addr_flags << 1, err = EC_SUCCESS;
int i = 0;
@@ -320,7 +319,8 @@ static int i2c_bitbang_xfer(const struct i2c_port_t *i2c_port,
for (i = 0; i < in_size; i++) {
err = i2c_read_byte(i2c_port, &in[i],
- (flags & I2C_XFER_STOP) && (i == in_size - 1));
+ (flags & I2C_XFER_STOP) &&
+ (i == in_size - 1));
if (err)
goto exit;
}
@@ -353,9 +353,7 @@ __overridable void board_pre_task_i2c_peripheral_init(void)
{
}
-const struct i2c_drv bitbang_drv = {
- .xfer = &i2c_bitbang_xfer
-};
+const struct i2c_drv bitbang_drv = { .xfer = &i2c_bitbang_xfer };
#ifdef TEST_BUILD
int bitbang_start_cond(const struct i2c_port_t *i2c_port)
diff --git a/common/i2c_controller.c b/common/i2c_controller.c
index 7a0550a93e..146d582c0d 100644
--- a/common/i2c_controller.c
+++ b/common/i2c_controller.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
/* I2C cross-platform code for Chrome EC */
#include "battery.h"
+#include "builtin/assert.h"
#include "clock.h"
#include "charge_state.h"
#include "console.h"
@@ -15,6 +16,7 @@
#include "i2c.h"
#include "i2c_bitbang.h"
#include "i2c_private.h"
+#include "printf.h"
#include "system.h"
#include "task.h"
#include "usb_pd.h"
@@ -29,15 +31,15 @@
#endif /* CONFIG_ZEPHYR */
/* Delay for bitbanging i2c corresponds roughly to 100kHz. */
-#define I2C_BITBANG_DELAY_US 5
+#define I2C_BITBANG_DELAY_US 5
/* Number of attempts to unwedge each pin. */
-#define UNWEDGE_SCL_ATTEMPTS 10
-#define UNWEDGE_SDA_ATTEMPTS 3
+#define UNWEDGE_SCL_ATTEMPTS 10
+#define UNWEDGE_SDA_ATTEMPTS 3
#define CPUTS(outstr) cputs(CC_I2C, outstr)
-#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_I2C, format, ##args)
/* Only chips with multi-port controllers will define I2C_CONTROLLER_COUNT */
#ifndef I2C_CONTROLLER_COUNT
@@ -48,14 +50,7 @@
#define I2C_BITBANG_PORT_COUNT 0
#endif
-#ifdef CONFIG_ZEPHYR
-/* I2C_PORT_COUNT is bigger than the real count of used I2C devices, so
- * use a special define for that to save RAM.
- */
-static mutex_t port_mutex[I2C_DEVICE_COUNT + I2C_BITBANG_PORT_COUNT];
-#else
static mutex_t port_mutex[I2C_CONTROLLER_COUNT + I2C_BITBANG_PORT_COUNT];
-#endif /* CONFIG_ZEPHYR */
/* A bitmap of the controllers which are currently servicing a request. */
static volatile uint32_t i2c_port_active_list;
@@ -81,7 +76,8 @@ SYS_INIT(init_port_mutex, POST_KERNEL, 50);
* will incorrectly return true. However, callers which failed to statically
* lock the port will fail quickly.
*/
-static int i2c_port_is_locked(int port)
+STATIC_IF_NOT(CONFIG_ZTEST)
+int i2c_port_is_locked(int port)
{
#ifdef CONFIG_I2C_MULTI_PORT_CONTROLLER
/* Test the controller, not the port */
@@ -91,16 +87,6 @@ static int i2c_port_is_locked(int port)
if (port < 0)
return 0;
- if (IS_ENABLED(CONFIG_ZEPHYR)) {
- /*
- * For Zephyr: to convert an i2c port enum value to a port
- * number in mutex_lock(), this number should be soc's i2c port
- * where the i2 device is connected to.
- */
- if (i2c_get_physical_port(port) >= 0)
- port = i2c_get_physical_port(port);
- }
-
return (i2c_port_active_list >> port) & 1;
}
@@ -134,10 +120,11 @@ const struct i2c_port_t *get_i2c_port(const int port)
return NULL;
}
-__maybe_unused static int chip_i2c_xfer_with_notify(
- const int port, const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+__maybe_unused static int chip_i2c_xfer_with_notify(const int port,
+ const uint16_t addr_flags,
+ const uint8_t *out,
+ int out_size, uint8_t *in,
+ int in_size, int flags)
{
int ret;
uint16_t no_pec_af = addr_flags;
@@ -157,18 +144,18 @@ __maybe_unused static int chip_i2c_xfer_with_notify(
no_pec_af &= ~I2C_FLAG_PEC;
if (i2c_port->drv)
- ret = i2c_port->drv->xfer(i2c_port, no_pec_af,
- out, out_size, in, in_size, flags);
+ ret = i2c_port->drv->xfer(i2c_port, no_pec_af, out, out_size,
+ in, in_size, flags);
else
- ret = chip_i2c_xfer(port, no_pec_af,
- out, out_size, in, in_size, flags);
+ ret = chip_i2c_xfer(port, no_pec_af, out, out_size, in, in_size,
+ flags);
if (IS_ENABLED(CONFIG_I2C_XFER_BOARD_CALLBACK))
i2c_end_xfer_notify(port, addr_flags);
if (IS_ENABLED(CONFIG_I2C_DEBUG)) {
- i2c_trace_notify(port, addr_flags, out, out_size,
- in, in_size, ret);
+ i2c_trace_notify(port, addr_flags, out, out_size, in, in_size,
+ ret);
}
return ret;
@@ -179,16 +166,15 @@ __maybe_unused static int chip_i2c_xfer_with_notify(
* Internal function that splits transfer into multiple chip_i2c_xfer() calls
* if in_size or out_size exceeds CONFIG_I2C_CHIP_MAX_TRANSFER_SIZE.
*/
-static int i2c_xfer_no_retry(const int port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+static int i2c_xfer_no_retry(const int port, const uint16_t addr_flags,
+ const uint8_t *out, int out_size, uint8_t *in,
+ int in_size, int flags)
{
int offset;
- for (offset = 0; offset < out_size; ) {
+ for (offset = 0; offset < out_size;) {
int chunk_size = MIN(out_size - offset,
- CONFIG_I2C_CHIP_MAX_TRANSFER_SIZE);
+ CONFIG_I2C_CHIP_MAX_TRANSFER_SIZE);
int out_flags = 0;
if (offset == 0)
@@ -197,13 +183,13 @@ static int i2c_xfer_no_retry(const int port,
out_flags |= flags & I2C_XFER_STOP;
RETURN_ERROR(chip_i2c_xfer_with_notify(port, addr_flags,
- out + offset, chunk_size, NULL, 0,
- out_flags));
+ out + offset, chunk_size,
+ NULL, 0, out_flags));
offset += chunk_size;
}
- for (offset = 0; offset < in_size; ) {
+ for (offset = 0; offset < in_size;) {
int chunk_size = MIN(in_size - offset,
- CONFIG_I2C_CHIP_MAX_TRANSFER_SIZE);
+ CONFIG_I2C_CHIP_MAX_TRANSFER_SIZE);
int in_flags = 0;
if (offset == 0)
@@ -211,18 +197,18 @@ static int i2c_xfer_no_retry(const int port,
if (offset + chunk_size == in_size)
in_flags |= flags & I2C_XFER_STOP;
- RETURN_ERROR(chip_i2c_xfer_with_notify(port, addr_flags,
- NULL, 0, in + offset, chunk_size, in_flags));
+ RETURN_ERROR(chip_i2c_xfer_with_notify(port, addr_flags, NULL,
+ 0, in + offset,
+ chunk_size, in_flags));
offset += chunk_size;
}
return EC_SUCCESS;
}
#endif /* CONFIG_I2C_XFER_LARGE_TRANSFER */
-int i2c_xfer_unlocked(const int port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+int i2c_xfer_unlocked(const int port, const uint16_t addr_flags,
+ const uint8_t *out, int out_size, uint8_t *in,
+ int in_size, int flags)
{
int i;
int ret = EC_SUCCESS;
@@ -275,14 +261,14 @@ int i2c_xfer_unlocked(const int port,
/* Big endian flag is used in wrappers for this call */
if (no_pec_af & ~(I2C_ADDR_MASK | I2C_FLAG_BIG_ENDIAN))
ccprintf("Ignoring flags from i2c addr_flags: %04x",
- no_pec_af);
+ no_pec_af);
- ret = i2c_transfer(i2c_get_device_for_port(port), msg,
- num_msgs, I2C_STRIP_FLAGS(no_pec_af));
+ ret = i2c_transfer(i2c_get_device_for_port(port), msg, num_msgs,
+ I2C_STRIP_FLAGS(no_pec_af));
if (IS_ENABLED(CONFIG_I2C_DEBUG)) {
- i2c_trace_notify(port, addr_flags, out, out_size,
- in, in_size, ret);
+ i2c_trace_notify(port, addr_flags, out, out_size, in,
+ in_size, ret);
}
switch (ret) {
@@ -294,13 +280,11 @@ int i2c_xfer_unlocked(const int port,
return EC_ERROR_UNKNOWN;
}
#elif defined(CONFIG_I2C_XFER_LARGE_TRANSFER)
- ret = i2c_xfer_no_retry(port, no_pec_af,
- out, out_size, in,
- in_size, flags);
+ ret = i2c_xfer_no_retry(port, no_pec_af, out, out_size, in,
+ in_size, flags);
#else
- ret = chip_i2c_xfer_with_notify(port, no_pec_af,
- out, out_size,
- in, in_size, flags);
+ ret = chip_i2c_xfer_with_notify(port, no_pec_af, out, out_size,
+ in, in_size, flags);
#endif /* CONFIG_I2C_XFER_LARGE_TRANSFER */
if (ret != EC_ERROR_BUSY)
break;
@@ -308,16 +292,13 @@ int i2c_xfer_unlocked(const int port,
return ret;
}
-int i2c_xfer(const int port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size)
+int i2c_xfer(const int port, const uint16_t addr_flags, const uint8_t *out,
+ int out_size, uint8_t *in, int in_size)
{
int rv;
i2c_lock(port, 1);
- rv = i2c_xfer_unlocked(port, addr_flags,
- out, out_size, in, in_size,
+ rv = i2c_xfer_unlocked(port, addr_flags, out, out_size, in, in_size,
I2C_XFER_SINGLE);
i2c_lock(port, 0);
@@ -330,16 +311,6 @@ void i2c_lock(int port, int lock)
/* Lock the controller, not the port */
port = i2c_port_to_controller(port);
#endif
- if (IS_ENABLED(CONFIG_ZEPHYR)) {
- /*
- * For Zephyr: to convert an i2c port enum value to a port
- * number in mutex_lock(), this number should be soc's i2c port
- * where the i2 device is connected to.
- */
- if (i2c_get_physical_port(port) >= 0)
- port = i2c_get_physical_port(port);
- }
-
if (port < 0 || port >= ARRAY_SIZE(port_mutex))
return;
@@ -390,13 +361,13 @@ static int platform_ec_i2c_read(const int port, const uint16_t addr_flags,
int i, rv;
/* addr_8bit = 7 bit addr_flags + 1 bit r/w */
uint8_t addr_8bit = I2C_STRIP_FLAGS(addr_flags) << 1;
- uint8_t out[3] = {addr_8bit, reg, addr_8bit | 1};
+ uint8_t out[3] = { addr_8bit, reg, addr_8bit | 1 };
uint8_t pec_local = 0, pec_remote;
i2c_lock(port, 1);
for (i = 0; i <= CONFIG_I2C_NACK_RETRY_COUNT; i++) {
- rv = i2c_xfer_unlocked(port, addr_flags, &reg, 1,
- in, in_size, I2C_XFER_START);
+ rv = i2c_xfer_unlocked(port, addr_flags, &reg, 1, in,
+ in_size, I2C_XFER_START);
if (rv)
continue;
@@ -421,8 +392,7 @@ static int platform_ec_i2c_read(const int port, const uint16_t addr_flags,
}
/* i2c_writeN with optional error checking */
-static int platform_ec_i2c_write(const int port,
- const uint16_t addr_flags,
+static int platform_ec_i2c_write(const int port, const uint16_t addr_flags,
const uint8_t *out, int out_size)
{
if (!IS_ENABLED(CONFIG_SMBUS_PEC) && I2C_USE_PEC(addr_flags))
@@ -438,15 +408,13 @@ static int platform_ec_i2c_write(const int port,
i2c_lock(port, 1);
for (i = 0; i <= CONFIG_I2C_NACK_RETRY_COUNT; i++) {
- rv = i2c_xfer_unlocked(port, addr_flags,
- out, out_size, NULL, 0,
- I2C_XFER_START);
+ rv = i2c_xfer_unlocked(port, addr_flags, out, out_size,
+ NULL, 0, I2C_XFER_START);
if (rv)
continue;
- rv = i2c_xfer_unlocked(port, addr_flags,
- &pec, 1, NULL, 0,
- I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked(port, addr_flags, &pec, 1, NULL,
+ 0, I2C_XFER_STOP);
if (!rv)
break;
}
@@ -458,17 +426,14 @@ static int platform_ec_i2c_write(const int port,
return i2c_xfer(port, addr_flags, out, out_size, NULL, 0);
}
-int i2c_read32(const int port,
- const uint16_t addr_flags,
- int offset, int *data)
+int i2c_read32(const int port, const uint16_t addr_flags, int offset, int *data)
{
int rv;
uint8_t reg, buf[sizeof(uint32_t)];
reg = offset & 0xff;
/* I2C read 32-bit word: transmit 8-bit offset, and read 32bits */
- rv = platform_ec_i2c_read(port, addr_flags, reg, buf,
- sizeof(uint32_t));
+ rv = platform_ec_i2c_read(port, addr_flags, reg, buf, sizeof(uint32_t));
if (rv)
return rv;
@@ -483,9 +448,7 @@ int i2c_read32(const int port,
return EC_SUCCESS;
}
-int i2c_write32(const int port,
- const uint16_t addr_flags,
- int offset, int data)
+int i2c_write32(const int port, const uint16_t addr_flags, int offset, int data)
{
uint8_t buf[1 + sizeof(uint32_t)];
@@ -507,17 +470,14 @@ int i2c_write32(const int port,
sizeof(uint32_t) + 1);
}
-int i2c_read16(const int port,
- const uint16_t addr_flags,
- int offset, int *data)
+int i2c_read16(const int port, const uint16_t addr_flags, int offset, int *data)
{
int rv;
uint8_t reg, buf[sizeof(uint16_t)];
reg = offset & 0xff;
/* I2C read 16-bit word: transmit 8-bit offset, and read 16bits */
- rv = platform_ec_i2c_read(port, addr_flags, reg, buf,
- sizeof(uint16_t));
+ rv = platform_ec_i2c_read(port, addr_flags, reg, buf, sizeof(uint16_t));
if (rv)
return rv;
@@ -530,9 +490,7 @@ int i2c_read16(const int port,
return EC_SUCCESS;
}
-int i2c_write16(const int port,
- const uint16_t addr_flags,
- int offset, int data)
+int i2c_write16(const int port, const uint16_t addr_flags, int offset, int data)
{
uint8_t buf[1 + sizeof(uint16_t)];
@@ -550,9 +508,7 @@ int i2c_write16(const int port,
1 + sizeof(uint16_t));
}
-int i2c_read8(const int port,
- const uint16_t addr_flags,
- int offset, int *data)
+int i2c_read8(const int port, const uint16_t addr_flags, int offset, int *data)
{
int rv;
uint8_t reg = offset;
@@ -560,17 +516,14 @@ int i2c_read8(const int port,
reg = offset;
- rv = platform_ec_i2c_read(port, addr_flags, reg, &buf,
- sizeof(uint8_t));
+ rv = platform_ec_i2c_read(port, addr_flags, reg, &buf, sizeof(uint8_t));
if (!rv)
*data = buf;
return rv;
}
-int i2c_write8(const int port,
- const uint16_t addr_flags,
- int offset, int data)
+int i2c_write8(const int port, const uint16_t addr_flags, int offset, int data)
{
uint8_t buf[2];
@@ -580,11 +533,8 @@ int i2c_write8(const int port,
return platform_ec_i2c_write(port, addr_flags, buf, sizeof(buf));
}
-int i2c_update8(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint8_t mask,
- const enum mask_update_action action)
+int i2c_update8(const int port, const uint16_t addr_flags, const int offset,
+ const uint8_t mask, const enum mask_update_action action)
{
int rv;
int read_val;
@@ -594,8 +544,8 @@ int i2c_update8(const int port,
if (rv)
return rv;
- write_val = (action == MASK_SET) ? (read_val | mask)
- : (read_val & ~mask);
+ write_val = (action == MASK_SET) ? (read_val | mask) :
+ (read_val & ~mask);
if (IS_ENABLED(CONFIG_I2C_UPDATE_IF_CHANGED) && write_val == read_val)
return EC_SUCCESS;
@@ -603,11 +553,8 @@ int i2c_update8(const int port,
return i2c_write8(port, addr_flags, offset, write_val);
}
-int i2c_update16(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint16_t mask,
- const enum mask_update_action action)
+int i2c_update16(const int port, const uint16_t addr_flags, const int offset,
+ const uint16_t mask, const enum mask_update_action action)
{
int rv;
int read_val;
@@ -617,8 +564,8 @@ int i2c_update16(const int port,
if (rv)
return rv;
- write_val = (action == MASK_SET) ? (read_val | mask)
- : (read_val & ~mask);
+ write_val = (action == MASK_SET) ? (read_val | mask) :
+ (read_val & ~mask);
if (IS_ENABLED(CONFIG_I2C_UPDATE_IF_CHANGED) && write_val == read_val)
return EC_SUCCESS;
@@ -626,10 +573,8 @@ int i2c_update16(const int port,
return i2c_write16(port, addr_flags, offset, write_val);
}
-int i2c_field_update8(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint8_t field_mask,
+int i2c_field_update8(const int port, const uint16_t addr_flags,
+ const int offset, const uint8_t field_mask,
const uint8_t set_value)
{
int rv;
@@ -648,10 +593,8 @@ int i2c_field_update8(const int port,
return i2c_write8(port, addr_flags, offset, write_val);
}
-int i2c_field_update16(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint16_t field_mask,
+int i2c_field_update16(const int port, const uint16_t addr_flags,
+ const int offset, const uint16_t field_mask,
const uint16_t set_value)
{
int rv;
@@ -670,8 +613,7 @@ int i2c_field_update16(const int port,
return i2c_write16(port, addr_flags, offset, write_val);
}
-int i2c_read_offset16(const int port,
- const uint16_t addr_flags,
+int i2c_read_offset16(const int port, const uint16_t addr_flags,
uint16_t offset, int *data, int len)
{
int rv;
@@ -701,8 +643,7 @@ int i2c_read_offset16(const int port,
return EC_SUCCESS;
}
-int i2c_write_offset16(const int port,
- const uint16_t addr_flags,
+int i2c_write_offset16(const int port, const uint16_t addr_flags,
uint16_t offset, int data, int len)
{
uint8_t buf[2 + sizeof(uint16_t)];
@@ -728,8 +669,7 @@ int i2c_write_offset16(const int port,
return i2c_xfer(port, addr_flags, buf, 2 + len, NULL, 0);
}
-int i2c_read_offset16_block(const int port,
- const uint16_t addr_flags,
+int i2c_read_offset16_block(const int port, const uint16_t addr_flags,
uint16_t offset, uint8_t *data, int len)
{
uint8_t addr[sizeof(uint16_t)];
@@ -740,8 +680,7 @@ int i2c_read_offset16_block(const int port,
return i2c_xfer(port, addr_flags, addr, 2, data, len);
}
-int i2c_write_offset16_block(const int port,
- const uint16_t addr_flags,
+int i2c_write_offset16_block(const int port, const uint16_t addr_flags,
uint16_t offset, const uint8_t *data, int len)
{
int rv;
@@ -758,16 +697,15 @@ int i2c_write_offset16_block(const int port,
rv = i2c_xfer_unlocked(port, addr_flags, addr, 2, NULL, 0,
I2C_XFER_START);
if (!rv)
- rv = i2c_xfer_unlocked(port, addr_flags,
- data, len, NULL, 0, I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked(port, addr_flags, data, len, NULL, 0,
+ I2C_XFER_STOP);
i2c_lock(port, 0);
return rv;
}
-int i2c_read_sized_block(const int port,
- const uint16_t addr_flags,
- int offset, uint8_t *data, int max_len, int *read_len)
+int i2c_read_sized_block(const int port, const uint16_t addr_flags, int offset,
+ uint8_t *data, int max_len, int *read_len)
{
int i, rv;
uint8_t reg, block_length;
@@ -788,9 +726,8 @@ int i2c_read_sized_block(const int port,
* Send device reg space offset, and read back block length.
* Keep this session open without a stop.
*/
- rv = i2c_xfer_unlocked(port, addr_flags,
- &reg, 1, &block_length, 1,
- I2C_XFER_START);
+ rv = i2c_xfer_unlocked(port, addr_flags, &reg, 1, &block_length,
+ 1, I2C_XFER_START);
if (rv)
continue;
@@ -799,15 +736,13 @@ int i2c_read_sized_block(const int port,
else
data_length = block_length;
- if (IS_ENABLED(CONFIG_SMBUS_PEC) &&
- I2C_USE_PEC(addr_flags)) {
- uint8_t addr_8bit =
- I2C_STRIP_FLAGS(addr_flags) << 1;
- uint8_t out[3] = {addr_8bit, reg, addr_8bit | 1};
+ if (IS_ENABLED(CONFIG_SMBUS_PEC) && I2C_USE_PEC(addr_flags)) {
+ uint8_t addr_8bit = I2C_STRIP_FLAGS(addr_flags) << 1;
+ uint8_t out[3] = { addr_8bit, reg, addr_8bit | 1 };
uint8_t pec, pec_remote;
- rv = i2c_xfer_unlocked(port, addr_flags,
- 0, 0, data, data_length, 0);
+ rv = i2c_xfer_unlocked(port, addr_flags, 0, 0, data,
+ data_length, 0);
if (rv)
continue;
@@ -820,8 +755,8 @@ int i2c_read_sized_block(const int port,
while (block_length) {
uint8_t byte;
- rv = i2c_xfer_unlocked(port, addr_flags,
- NULL, 0, &byte, 1, 0);
+ rv = i2c_xfer_unlocked(port, addr_flags, NULL,
+ 0, &byte, 1, 0);
if (rv)
break;
pec = cros_crc8_arg(&byte, 1, pec);
@@ -838,9 +773,8 @@ int i2c_read_sized_block(const int port,
if (pec != pec_remote)
rv = EC_ERROR_CRC;
} else {
- rv = i2c_xfer_unlocked(port, addr_flags,
- 0, 0, data, data_length,
- I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked(port, addr_flags, 0, 0, data,
+ data_length, I2C_XFER_STOP);
if (rv)
continue;
}
@@ -854,9 +788,8 @@ int i2c_read_sized_block(const int port,
return rv;
}
-int i2c_read_string(const int port,
- const uint16_t addr_flags,
- int offset, uint8_t *data, int len)
+int i2c_read_string(const int port, const uint16_t addr_flags, int offset,
+ uint8_t *data, int len)
{
int read_len = 0;
int rv = 0;
@@ -865,7 +798,7 @@ int i2c_read_string(const int port,
return EC_ERROR_INVAL;
rv = i2c_read_sized_block(port, addr_flags, offset, data, len - 1,
- &read_len);
+ &read_len);
data[read_len] = 0;
return rv;
}
@@ -880,9 +813,8 @@ int i2c_read_block(const int port, const uint16_t addr_flags, int offset,
return rv;
}
-int i2c_write_block(const int port,
- const uint16_t addr_flags,
- int offset, const uint8_t *data, int len)
+int i2c_write_block(const int port, const uint16_t addr_flags, int offset,
+ const uint8_t *data, int len)
{
int i, rv;
uint8_t reg_address = offset, pec = 0;
@@ -903,27 +835,25 @@ int i2c_write_block(const int port,
*/
i2c_lock(port, 1);
for (i = 0; i <= CONFIG_I2C_NACK_RETRY_COUNT; i++) {
- rv = i2c_xfer_unlocked(port, addr_flags,
- &reg_address, 1, NULL, 0,
- I2C_XFER_START);
+ rv = i2c_xfer_unlocked(port, addr_flags, &reg_address, 1, NULL,
+ 0, I2C_XFER_START);
if (rv)
continue;
if (I2C_USE_PEC(addr_flags)) {
- rv = i2c_xfer_unlocked(port, addr_flags,
- data, len, NULL, 0, 0);
+ rv = i2c_xfer_unlocked(port, addr_flags, data, len,
+ NULL, 0, 0);
if (rv)
continue;
- rv = i2c_xfer_unlocked(port, addr_flags,
- &pec, sizeof(uint8_t), NULL, 0,
+ rv = i2c_xfer_unlocked(port, addr_flags, &pec,
+ sizeof(uint8_t), NULL, 0,
I2C_XFER_STOP);
if (rv)
continue;
} else {
- rv = i2c_xfer_unlocked(port, addr_flags,
- data, len, NULL, 0,
- I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked(port, addr_flags, data, len,
+ NULL, 0, I2C_XFER_STOP);
if (rv)
continue;
}
@@ -1022,7 +952,6 @@ int i2c_raw_mode(int port, int enable)
return ret_sda == EC_SUCCESS ? ret_scl : ret_sda;
}
-
/*
* Unwedge the i2c bus for the given port.
*
@@ -1083,7 +1012,8 @@ int i2c_unwedge(int port)
* clock low and there is nothing we can do.
*/
CPRINTS("I2C%d unwedge failed, "
- "SCL is held low", port);
+ "SCL is held low",
+ port);
ret = EC_ERROR_UNKNOWN;
goto unwedge_done;
}
@@ -1202,8 +1132,8 @@ enum i2c_freq i2c_get_freq(int port)
/* Host commands */
#ifdef CONFIG_I2C_DEBUG_PASSTHRU
-#define PTHRUPRINTS(format, args...) CPRINTS("I2C_PTHRU " format, ## args)
-#define PTHRUPRINTF(format, args...) CPRINTF(format, ## args)
+#define PTHRUPRINTS(format, args...) CPRINTS("I2C_PTHRU " format, ##args)
+#define PTHRUPRINTF(format, args...) CPRINTF(format, ##args)
#else
#define PTHRUPRINTS(format, args...)
#define PTHRUPRINTF(format, args...)
@@ -1241,7 +1171,7 @@ static int check_i2c_params(const struct host_cmd_handler_args *args)
}
#ifdef CONFIG_I2C_PASSTHRU_RESTRICTED
- out = (uint8_t *) args->params + size;
+ out = (uint8_t *)args->params + size;
#endif
/* Loop and process messages */;
@@ -1252,8 +1182,7 @@ static int check_i2c_params(const struct host_cmd_handler_args *args)
PTHRUPRINTS("port=%d, %s, addr=0x%x(7-bit), len=%d",
params->port,
addr_flags & EC_I2C_FLAG_READ ? "read" : "write",
- addr_flags & EC_I2C_ADDR_MASK,
- msg->len);
+ addr_flags & EC_I2C_ADDR_MASK, msg->len);
if (addr_flags & EC_I2C_FLAG_READ) {
read_len += msg->len;
@@ -1270,8 +1199,7 @@ static int check_i2c_params(const struct host_cmd_handler_args *args)
.addr_flags = addr_flags,
.cmd = cmd_id,
};
- if (!board_allow_i2c_passthru(
- &cmd_desc))
+ if (!board_allow_i2c_passthru(&cmd_desc))
return EC_RES_ACCESS_DENIED;
}
#endif
@@ -1279,7 +1207,7 @@ static int check_i2c_params(const struct host_cmd_handler_args *args)
/* Check there is room for the data */
if (args->response_max <
- sizeof(struct ec_response_i2c_passthru) + read_len) {
+ sizeof(struct ec_response_i2c_passthru) + read_len) {
PTHRUPRINTS("overflow1");
return EC_RES_INVALID_PARAM;
}
@@ -1316,8 +1244,7 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
*/
((struct ec_params_i2c_passthru *)(args->params))->port =
i2c_get_port_from_remote_port(
- ((struct ec_params_i2c_passthru *)(args->params))
- ->port);
+ ((struct ec_params_i2c_passthru *)(args->params))->port);
#endif
const struct ec_params_i2c_passthru *params = args->params;
const struct ec_params_i2c_passthru_msg *msg;
@@ -1349,8 +1276,8 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
return EC_RES_ACCESS_DENIED;
for (i = 0; i < params->num_msgs; i++) {
- if (!i2c_port->passthru_allowed(i2c_port,
- params->msg[i].addr_flags))
+ if (!i2c_port->passthru_allowed(
+ i2c_port, params->msg[i].addr_flags))
return EC_RES_ACCESS_DENIED;
}
}
@@ -1358,12 +1285,11 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
/* Loop and process messages */
resp->i2c_status = 0;
out = (uint8_t *)args->params + sizeof(*params) +
- params->num_msgs * sizeof(*msg);
+ params->num_msgs * sizeof(*msg);
in_len = 0;
for (resp->num_msgs = 0, msg = params->msg;
- resp->num_msgs < params->num_msgs;
- resp->num_msgs++, msg++) {
+ resp->num_msgs < params->num_msgs; resp->num_msgs++, msg++) {
int xferflags = I2C_XFER_START;
int read_len = 0, write_len = 0;
int rv = 1;
@@ -1371,7 +1297,6 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
/* Have to remove the EC flags from the address flags */
uint16_t addr_flags = msg->addr_flags & EC_I2C_ADDR_MASK;
-
if (msg->addr_flags & EC_I2C_FLAG_READ)
read_len = msg->len;
else
@@ -1385,15 +1310,14 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
if (is_i2c_port_virtual_battery(params->port) &&
addr_flags == VIRTUAL_BATTERY_ADDR_FLAGS) {
if (virtual_battery_handler(resp, in_len, &rv,
- xferflags, read_len,
- write_len, out))
+ xferflags, read_len,
+ write_len, out))
break;
}
#endif
/* Transfer next message */
PTHRUPRINTS("xfer port=%x addr=0x%x rlen=%d flags=0x%x",
- params->port, addr_flags,
- read_len, xferflags);
+ params->port, addr_flags, read_len, xferflags);
if (write_len) {
PTHRUPRINTF(" out:");
for (i = 0; i < write_len; i++)
@@ -1403,11 +1327,9 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
if (rv) {
if (!port_is_locked)
i2c_lock(params->port, (port_is_locked = 1));
- rv = i2c_xfer_unlocked(params->port,
- addr_flags,
- out, write_len,
- &resp->data[in_len], read_len,
- xferflags);
+ rv = i2c_xfer_unlocked(params->port, addr_flags, out,
+ write_len, &resp->data[in_len],
+ read_len, xferflags);
}
if (rv) {
@@ -1436,6 +1358,11 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_I2C_PASSTHRU, i2c_command_passthru, EC_VER_MASK(0));
+__test_only void i2c_passthru_protect_reset(void)
+{
+ memset(port_protected, 0, sizeof(port_protected));
+}
+
static void i2c_passthru_protect_port(uint32_t port)
{
if (port < ARRAY_SIZE(port_protected))
@@ -1476,8 +1403,7 @@ i2c_command_passthru_protect(struct host_cmd_handler_args *args)
*/
((struct ec_params_i2c_passthru_protect *)(args->params))
->port = i2c_get_port_from_remote_port(
- ((struct ec_params_i2c_passthru_protect *)(args->params))
- ->port);
+ ((struct ec_params_i2c_passthru_protect *)(args->params))->port);
#endif
const struct ec_params_i2c_passthru_protect *params = args->params;
struct ec_response_i2c_passthru_protect *resp = args->response;
@@ -1495,7 +1421,7 @@ i2c_command_passthru_protect(struct host_cmd_handler_args *args)
*/
if (params->subcmd == EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS) {
if (IS_ENABLED(CONFIG_USB_POWER_DELIVERY) &&
- !IS_ENABLED(CONFIG_USB_PD_TCPM_STUB))
+ !IS_ENABLED(CONFIG_USB_PD_TCPM_STUB))
i2c_passthru_protect_tcpc_ports();
return EC_RES_SUCCESS;
}
@@ -1508,8 +1434,8 @@ i2c_command_passthru_protect(struct host_cmd_handler_args *args)
if (params->subcmd == EC_CMD_I2C_PASSTHRU_PROTECT_STATUS) {
if (args->response_max < sizeof(*resp)) {
PTHRUPRINTS("protect no response, "
- "response_max=%d, need at least %d",
- args->response_max, sizeof(*resp));
+ "response_max=%d, need at least %d",
+ args->response_max, sizeof(*resp));
return EC_RES_INVALID_PARAM;
}
@@ -1528,8 +1454,7 @@ DECLARE_HOST_COMMAND(EC_CMD_I2C_PASSTHRU_PROTECT, i2c_command_passthru_protect,
#ifdef CONFIG_HOSTCMD_I2C_CONTROL
-static enum ec_status
-i2c_command_control(struct host_cmd_handler_args *args)
+static enum ec_status i2c_command_control(struct host_cmd_handler_args *args)
{
#ifdef CONFIG_ZEPHYR
/* For Zephyr, convert the received remote port number to a port number
@@ -1537,8 +1462,7 @@ i2c_command_control(struct host_cmd_handler_args *args)
*/
((struct ec_params_i2c_control *)(args->params))->port =
i2c_get_port_from_remote_port(
- ((struct ec_params_i2c_control *)(args->params))
- ->port);
+ ((struct ec_params_i2c_control *)(args->params))->port);
#endif
const struct ec_params_i2c_control *params = args->params;
struct ec_response_i2c_control *resp = args->response;
@@ -1559,7 +1483,7 @@ i2c_command_control(struct host_cmd_handler_args *args)
old_i2c_freq = i2c_get_freq(cfg->port);
khz = i2c_freq_to_khz(old_i2c_freq);
old_i2c_speed_khz = (khz != 0) ? khz :
- EC_I2C_CONTROL_SPEED_UNKNOWN;
+ EC_I2C_CONTROL_SPEED_UNKNOWN;
break;
case EC_I2C_CONTROL_SET_SPEED:
@@ -1576,9 +1500,7 @@ i2c_command_control(struct host_cmd_handler_args *args)
return EC_RES_ERROR;
CPRINTS("I2C%d speed changed from %d kHz to %d kHz",
- params->port,
- old_i2c_speed_khz,
- new_i2c_speed_khz);
+ params->port, old_i2c_speed_khz, new_i2c_speed_khz);
break;
default:
@@ -1591,8 +1513,7 @@ i2c_command_control(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_I2C_CONTROL, i2c_command_control,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_I2C_CONTROL, i2c_command_control, EC_VER_MASK(0));
#endif /* CONFIG_HOSTCMD_I2C_CONTROL */
@@ -1600,7 +1521,7 @@ DECLARE_HOST_COMMAND(EC_CMD_I2C_CONTROL, i2c_command_control,
/* Console commands */
#ifdef CONFIG_CMD_I2C_PROTECT
-static int command_i2cprotect(int argc, char **argv)
+static int command_i2cprotect(int argc, const char **argv)
{
if (argc == 1) {
int i, port;
@@ -1608,7 +1529,8 @@ static int command_i2cprotect(int argc, char **argv)
for (i = 0; i < i2c_ports_used; i++) {
port = i2c_ports[i].port;
ccprintf("Port %d: %s\n", port,
- port_protected[port] ? "Protected" : "Unprotected");
+ port_protected[port] ? "Protected" :
+ "Unprotected");
}
} else if (argc == 2) {
int port;
@@ -1620,7 +1542,7 @@ static int command_i2cprotect(int argc, char **argv)
if (!get_i2c_port(port)) {
ccprintf("i2c passthru protect invalid port %d\n",
- port);
+ port);
return EC_RES_INVALID_PARAM;
}
@@ -1631,8 +1553,7 @@ static int command_i2cprotect(int argc, char **argv)
return EC_RES_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(i2cprotect, command_i2cprotect,
- "[port]",
+DECLARE_CONSOLE_COMMAND(i2cprotect, command_i2cprotect, "[port]",
"Protect I2C bus");
#endif
@@ -1662,12 +1583,12 @@ static void scan_bus(int port, const char *desc)
*/
for (addr_flags = I2C_FIRST_VALID_ADDR;
addr_flags <= I2C_LAST_VALID_ADDR; ++addr_flags) {
- watchdog_reload(); /* Otherwise a full scan trips watchdog */
+ watchdog_reload(); /* Otherwise a full scan trips watchdog */
ccputs(".");
/* Do a single read */
- if (!i2c_xfer_unlocked(port, addr_flags,
- NULL, 0, &tmp, 1, I2C_XFER_SINGLE))
+ if (!i2c_xfer_unlocked(port, addr_flags, NULL, 0, &tmp, 1,
+ I2C_XFER_SINGLE))
ccprintf("\n 0x%02x", addr_flags);
}
@@ -1676,7 +1597,7 @@ scan_bus_exit:
ccputs("\n");
}
-static int command_scan(int argc, char **argv)
+static int command_scan(int argc, const char **argv)
{
int port;
char *e;
@@ -1694,7 +1615,6 @@ static int command_scan(int argc, char **argv)
return EC_SUCCESS;
}
-
port = strtoi(argv[1], &e, 0);
if (*e)
return EC_ERROR_PARAM2;
@@ -1707,13 +1627,12 @@ static int command_scan(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(i2cscan, command_scan,
- "i2cscan [port]",
+DECLARE_CONSOLE_COMMAND(i2cscan, command_scan, "i2cscan [port]",
"Scan I2C ports for devices");
#endif
#ifdef CONFIG_CMD_I2C_XFER
-static int command_i2cxfer(int argc, char **argv)
+static int command_i2cxfer(int argc, const char **argv)
{
int port;
uint16_t addr_flags;
@@ -1750,22 +1669,18 @@ static int command_i2cxfer(int argc, char **argv)
if (strcasecmp(argv[1], "r") == 0) {
/* 8-bit read */
if (offset_size == 2)
- rv = i2c_read_offset16(port, addr_flags,
- offset, &v, 1);
+ rv = i2c_read_offset16(port, addr_flags, offset, &v, 1);
else
- rv = i2c_read8(port, addr_flags,
- offset, &v);
+ rv = i2c_read8(port, addr_flags, offset, &v);
if (!rv)
ccprintf("0x%02x [%d]\n", v, v);
} else if (strcasecmp(argv[1], "r16") == 0) {
/* 16-bit read */
if (offset_size == 2)
- rv = i2c_read_offset16(port, addr_flags,
- offset, &v, 2);
+ rv = i2c_read_offset16(port, addr_flags, offset, &v, 2);
else
- rv = i2c_read16(port, addr_flags,
- offset, &v);
+ rv = i2c_read16(port, addr_flags, offset, &v);
if (!rv)
ccprintf("0x%04x [%d]\n", v, v);
@@ -1774,33 +1689,33 @@ static int command_i2cxfer(int argc, char **argv)
if (argc < 6 || v < 0 || v > sizeof(data))
return EC_ERROR_PARAM5;
- rv = i2c_xfer(port, addr_flags,
- (uint8_t *)&offset, 1, data, v);
+ rv = i2c_xfer(port, addr_flags, (uint8_t *)&offset, 1, data, v);
- if (!rv)
- ccprintf("Data: %ph\n", HEX_BUF(data, v));
+ if (!rv) {
+ char str_buf[hex_str_buf_size(v)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(data, v));
+ ccprintf("Data: %s\n", str_buf);
+ }
} else if (strcasecmp(argv[1], "w") == 0) {
/* 8-bit write */
if (argc < 6)
return EC_ERROR_PARAM5;
if (offset_size == 2)
- rv = i2c_write_offset16(port, addr_flags,
- offset, v, 1);
+ rv = i2c_write_offset16(port, addr_flags, offset, v, 1);
else
- rv = i2c_write8(port, addr_flags,
- offset, v);
+ rv = i2c_write8(port, addr_flags, offset, v);
} else if (strcasecmp(argv[1], "w16") == 0) {
/* 16-bit write */
if (argc < 6)
return EC_ERROR_PARAM5;
if (offset_size == 2)
- rv = i2c_write_offset16(port, addr_flags,
- offset, v, 2);
+ rv = i2c_write_offset16(port, addr_flags, offset, v, 2);
else
- rv = i2c_write16(port, addr_flags,
- offset, v);
+ rv = i2c_write16(port, addr_flags, offset, v);
#ifdef CONFIG_CMD_I2C_XFER_RAW
} else if (strcasecmp(argv[1], "raw") == 0) {
/* <port> <addr_flags> <read_count> [write_bytes..] */
@@ -1836,11 +1751,8 @@ static int command_i2cxfer(int argc, char **argv)
xferflags |= I2C_XFER_STOP;
ccprintf("Writing %d bytes\n", write_count);
i2c_lock(port, 1);
- rv = i2c_xfer_unlocked(port,
- addr_flags,
- data, write_count,
- NULL, 0,
- xferflags);
+ rv = i2c_xfer_unlocked(port, addr_flags, data,
+ write_count, NULL, 0, xferflags);
if (rv || read_count == 0) {
i2c_lock(port, 0);
return rv;
@@ -1850,15 +1762,17 @@ static int command_i2cxfer(int argc, char **argv)
ccprintf("Reading %d bytes\n", read_count);
if (write_count == 0)
i2c_lock(port, 1);
- rv = i2c_xfer_unlocked(port,
- addr_flags,
- NULL, 0,
- data, read_count,
+ rv = i2c_xfer_unlocked(port, addr_flags, NULL, 0, data,
+ read_count,
I2C_XFER_START | I2C_XFER_STOP);
i2c_lock(port, 0);
- if (!rv)
- ccprintf("Data: %ph\n",
- HEX_BUF(data, read_count));
+ if (!rv) {
+ char str_buf[hex_str_buf_size(read_count)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(data, read_count));
+ ccprintf("Data: %s\n", str_buf);
+ }
}
#endif /* CONFIG_CMD_I2C_XFER_RAW */
} else {
@@ -1878,7 +1792,7 @@ DECLARE_CONSOLE_COMMAND(i2cxfer, command_i2cxfer,
#ifdef CONFIG_CMD_I2C_SPEED
-static const char * const i2c_freq_str[] = {
+static const char *const i2c_freq_str[] = {
[I2C_FREQ_1000KHZ] = "1000 kHz",
[I2C_FREQ_400KHZ] = "400 kHz",
[I2C_FREQ_100KHZ] = "100 kHz",
@@ -1887,7 +1801,7 @@ static const char * const i2c_freq_str[] = {
BUILD_ASSERT(ARRAY_SIZE(i2c_freq_str) == I2C_FREQ_COUNT + 1);
-static int command_i2c_speed(int argc, char **argv)
+static int command_i2c_speed(int argc, const char **argv)
{
int port;
char *e;
@@ -1936,16 +1850,14 @@ static int command_i2c_speed(int argc, char **argv)
if (new_freq != I2C_FREQ_COUNT)
ccprintf("Port %d speed changed from %s to %s\n", port,
- i2c_freq_str[freq],
- i2c_freq_str[new_freq]);
+ i2c_freq_str[freq], i2c_freq_str[new_freq]);
else
ccprintf("Port %d speed is %s\n", port, i2c_freq_str[freq]);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(i2cspeed, command_i2c_speed,
- "port [speed in kHz]",
+DECLARE_CONSOLE_COMMAND(i2cspeed, command_i2c_speed, "port [speed in kHz]",
"Get or set I2C port speed");
#endif /* CONFIG_CMD_I2C_SPEED */
@@ -1955,23 +1867,20 @@ static void i2c_test_status(struct i2c_test_results *i2c_test, int test_dev)
{
ccprintf("test_dev=%2d, ", test_dev);
ccprintf("r=%5d, rs=%5d, rf=%5d, ",
- i2c_test->read_success + i2c_test->read_fail,
- i2c_test->read_success,
- i2c_test->read_fail);
+ i2c_test->read_success + i2c_test->read_fail,
+ i2c_test->read_success, i2c_test->read_fail);
ccprintf("w=%5d, ws=%5d, wf=%5d\n",
- i2c_test->write_success + i2c_test->write_fail,
- i2c_test->write_success,
- i2c_test->write_fail);
+ i2c_test->write_success + i2c_test->write_fail,
+ i2c_test->write_success, i2c_test->write_fail);
i2c_test->read_success = 0;
i2c_test->read_fail = 0;
- i2c_test->write_success = 0,
- i2c_test->write_fail = 0;
+ i2c_test->write_success = 0, i2c_test->write_fail = 0;
}
#define I2C_STRESS_TEST_DATA_VERIFY_RETRY_COUNT 3
-static int command_i2ctest(int argc, char **argv)
+static int command_i2ctest(int argc, const char **argv)
{
char *e;
int i, j, rv;
@@ -2025,10 +1934,11 @@ static int command_i2ctest(int argc, char **argv)
if (rand & 0x1) {
/* read */
rv = i2c_s_test->i2c_read ?
- i2c_s_test->i2c_read(port, addr_flags,
- reg_s_info->read_reg, &data) :
- i2c_s_test->i2c_read_dev(
- reg_s_info->read_reg, &data);
+ i2c_s_test->i2c_read(port, addr_flags,
+ reg_s_info->read_reg,
+ &data) :
+ i2c_s_test->i2c_read_dev(
+ reg_s_info->read_reg, &data);
if (rv || data != reg_s_info->read_val)
test_s_results->read_fail++;
else
@@ -2042,10 +1952,11 @@ static int command_i2ctest(int argc, char **argv)
/* Read the write register */
rv = i2c_s_test->i2c_read ?
- i2c_s_test->i2c_read(port, addr_flags,
- reg_s_info->read_reg, &data) :
- i2c_s_test->i2c_read_dev(
- reg_s_info->read_reg, &data);
+ i2c_s_test->i2c_read(port, addr_flags,
+ reg_s_info->read_reg,
+ &data) :
+ i2c_s_test->i2c_read_dev(
+ reg_s_info->read_reg, &data);
if (rv) {
/* Skip writing invalid data */
test_s_results->read_fail++;
@@ -2057,11 +1968,13 @@ static int command_i2ctest(int argc, char **argv)
do {
/* Write same value back */
rv = i2c_s_test->i2c_write ?
- i2c_s_test->i2c_write(port,
- addr_flags,
- reg_s_info->write_reg, data) :
- i2c_s_test->i2c_write_dev(
- reg_s_info->write_reg, data);
+ i2c_s_test->i2c_write(
+ port, addr_flags,
+ reg_s_info->write_reg,
+ data) :
+ i2c_s_test->i2c_write_dev(
+ reg_s_info->write_reg,
+ data);
i++;
if (rv) {
/* Skip reading as write failed */
@@ -2072,11 +1985,13 @@ static int command_i2ctest(int argc, char **argv)
/* Read back to verify the data */
rv = i2c_s_test->i2c_read ?
- i2c_s_test->i2c_read(port,
- addr_flags,
- reg_s_info->read_reg, &data_verify) :
- i2c_s_test->i2c_read_dev(
- reg_s_info->read_reg, &data_verify);
+ i2c_s_test->i2c_read(
+ port, addr_flags,
+ reg_s_info->read_reg,
+ &data_verify) :
+ i2c_s_test->i2c_read_dev(
+ reg_s_info->read_reg,
+ &data_verify);
i++;
if (rv) {
/* Read failed try next time */
@@ -2111,7 +2026,6 @@ static int command_i2ctest(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(i2ctest, command_i2ctest,
- "i2ctest count|udelay|dev",
+DECLARE_CONSOLE_COMMAND(i2ctest, command_i2ctest, "i2ctest count|udelay|dev",
"I2C stress test");
#endif /* CONFIG_CMD_I2C_STRESS_TEST */
diff --git a/common/i2c_hid_touchpad.c b/common/i2c_hid_touchpad.c
index 29122f83d6..02261d8fa4 100644
--- a/common/i2c_hid_touchpad.c
+++ b/common/i2c_hid_touchpad.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,23 +10,23 @@
#include "util.h"
/* 2 bytes for length + 1 byte for report ID */
-#define I2C_HID_HEADER_SIZE 3
+#define I2C_HID_HEADER_SIZE 3
/* Report ID */
-#define REPORT_ID_TOUCH 0x01
-#define REPORT_ID_MOUSE 0x02
-#define REPORT_ID_DEVICE_CAPS 0x0A
-#define REPORT_ID_DEVICE_CERT 0x0B
-#define REPORT_ID_INPUT_MODE 0x0C
-#define REPORT_ID_REPORTING 0x0D
+#define REPORT_ID_TOUCH 0x01
+#define REPORT_ID_MOUSE 0x02
+#define REPORT_ID_DEVICE_CAPS 0x0A
+#define REPORT_ID_DEVICE_CERT 0x0B
+#define REPORT_ID_INPUT_MODE 0x0C
+#define REPORT_ID_REPORTING 0x0D
-#define INPUT_MODE_MOUSE 0x00
-#define INPUT_MODE_TOUCH 0x03
+#define INPUT_MODE_MOUSE 0x00
+#define INPUT_MODE_TOUCH 0x03
/* VID/PID/FW version */
-#if !defined(I2C_HID_TOUCHPAD_VENDOR_ID) || \
- !defined(I2C_HID_TOUCHPAD_PRODUCT_ID) || \
- !defined(I2C_HID_TOUCHPAD_FW_VERSION)
+#if !defined(I2C_HID_TOUCHPAD_VENDOR_ID) || \
+ !defined(I2C_HID_TOUCHPAD_PRODUCT_ID) || \
+ !defined(I2C_HID_TOUCHPAD_FW_VERSION)
#error "Must define touchpad VID/PID/FW version"
#endif
/*
@@ -34,10 +34,9 @@
*
* Physical dimensions are in the unit of mms.
*/
-#if !defined(I2C_HID_TOUCHPAD_MAX_X) || \
- !defined(I2C_HID_TOUCHPAD_MAX_Y) || \
- !defined(I2C_HID_TOUCHPAD_MAX_PHYSICAL_X) || \
- !defined(I2C_HID_TOUCHPAD_MAX_PHYSICAL_Y)
+#if !defined(I2C_HID_TOUCHPAD_MAX_X) || !defined(I2C_HID_TOUCHPAD_MAX_Y) || \
+ !defined(I2C_HID_TOUCHPAD_MAX_PHYSICAL_X) || \
+ !defined(I2C_HID_TOUCHPAD_MAX_PHYSICAL_Y)
#error "Must define finger maximum X/Y and physical dimensions"
#endif
/*
@@ -49,9 +48,9 @@
* different data ranges. It is therefore recommended for the user to check the
* device's spec and set these values manually.
*/
-#if !defined(I2C_HID_TOUCHPAD_MAX_WIDTH) || \
- !defined(I2C_HID_TOUCHPAD_MAX_HEIGHT) || \
- !defined(I2C_HID_TOUCHPAD_MAX_PRESSURE)
+#if !defined(I2C_HID_TOUCHPAD_MAX_WIDTH) || \
+ !defined(I2C_HID_TOUCHPAD_MAX_HEIGHT) || \
+ !defined(I2C_HID_TOUCHPAD_MAX_PRESSURE)
#error "Must define finger maximum width/height/pressure"
#endif
/*
@@ -67,42 +66,37 @@
* This is a bit similar to the mouse CPI and is used by mouse reports only.
*/
#if !defined(I2C_HID_TOUCHPAD_MOUSE_SCALE_X) || \
- !defined(I2C_HID_TOUCHPAD_MOUSE_SCALE_Y)
+ !defined(I2C_HID_TOUCHPAD_MOUSE_SCALE_Y)
#error "Must define mouse horizontal/vertical scaling factors"
#endif
/* Helper bit-op macros */
-#define N_BITS(n) \
-( \
- (n) < (1 << 1) ? 1 : \
- (n) < (1 << 2) ? 2 : \
- (n) < (1 << 3) ? 3 : \
- (n) < (1 << 4) ? 4 : \
- (n) < (1 << 5) ? 5 : \
- (n) < (1 << 6) ? 6 : \
- (n) < (1 << 7) ? 7 : \
- (n) < (1 << 8) ? 8 : \
- (n) < (1 << 9) ? 9 : \
- (n) < (1 << 10) ? 10 : \
- (n) < (1 << 11) ? 11 : \
- (n) < (1 << 12) ? 12 : \
- (n) < (1 << 13) ? 13 : \
- (n) < (1 << 14) ? 14 : \
- (n) < (1 << 15) ? 15 : \
- 16 \
-)
+#define N_BITS(n) \
+ ((n) < (1 << 1) ? 1 : \
+ (n) < (1 << 2) ? 2 : \
+ (n) < (1 << 3) ? 3 : \
+ (n) < (1 << 4) ? 4 : \
+ (n) < (1 << 5) ? 5 : \
+ (n) < (1 << 6) ? 6 : \
+ (n) < (1 << 7) ? 7 : \
+ (n) < (1 << 8) ? 8 : \
+ (n) < (1 << 9) ? 9 : \
+ (n) < (1 << 10) ? 10 : \
+ (n) < (1 << 11) ? 11 : \
+ (n) < (1 << 12) ? 12 : \
+ (n) < (1 << 13) ? 13 : \
+ (n) < (1 << 14) ? 14 : \
+ (n) < (1 << 15) ? 15 : \
+ 16)
/* We would need to pad some bits at the end of each finger struct to match
* the allocation unit's boundary so the array indexing may work correctly.
*/
-#define N_VAR_BITS \
-( \
- N_BITS(I2C_HID_TOUCHPAD_MAX_X) + \
- N_BITS(I2C_HID_TOUCHPAD_MAX_Y) + \
- N_BITS(I2C_HID_TOUCHPAD_MAX_WIDTH) + \
- N_BITS(I2C_HID_TOUCHPAD_MAX_HEIGHT) + \
- N_BITS(I2C_HID_TOUCHPAD_MAX_PRESSURE) + \
- N_BITS(I2C_HID_TOUCHPAD_MAX_ORIENTATION) \
-)
+#define N_VAR_BITS \
+ (N_BITS(I2C_HID_TOUCHPAD_MAX_X) + N_BITS(I2C_HID_TOUCHPAD_MAX_Y) + \
+ N_BITS(I2C_HID_TOUCHPAD_MAX_WIDTH) + \
+ N_BITS(I2C_HID_TOUCHPAD_MAX_HEIGHT) + \
+ N_BITS(I2C_HID_TOUCHPAD_MAX_PRESSURE) + \
+ N_BITS(I2C_HID_TOUCHPAD_MAX_ORIENTATION))
#define N_PADDING_BITS ((DIV_ROUND_UP(N_VAR_BITS, 8) * 8) - N_VAR_BITS)
#define N_BITS_ORIENTATION \
(N_BITS(I2C_HID_TOUCHPAD_MAX_ORIENTATION) + N_PADDING_BITS)
@@ -121,45 +115,45 @@ struct finger {
* identify unintended contacts or palms but is up to the OS
* explanation.
*/
- uint8_t confidence:1;
+ uint8_t confidence : 1;
/*
* Whether a finger is touching the surface (leaving/left finger gets
* 0).
*/
- uint8_t tip:1;
+ uint8_t tip : 1;
/*
* Whether a finger is within the sensor range. For example, hovering
* fingers would have tip=0 and inrange=1.
*/
- uint8_t inrange:1;
+ uint8_t inrange : 1;
/*
* Contact id. This is like slot numbers in Linux MT-B.
*/
- uint8_t id:5;
- uint16_t x:N_BITS(I2C_HID_TOUCHPAD_MAX_X);
- uint16_t y:N_BITS(I2C_HID_TOUCHPAD_MAX_Y);
- uint16_t width:N_BITS(I2C_HID_TOUCHPAD_MAX_WIDTH);
- uint16_t height:N_BITS(I2C_HID_TOUCHPAD_MAX_HEIGHT);
- uint16_t pressure:N_BITS(I2C_HID_TOUCHPAD_MAX_PRESSURE);
- uint16_t orientation:N_BITS_ORIENTATION;
+ uint8_t id : 5;
+ uint16_t x : N_BITS(I2C_HID_TOUCHPAD_MAX_X);
+ uint16_t y : N_BITS(I2C_HID_TOUCHPAD_MAX_Y);
+ uint16_t width : N_BITS(I2C_HID_TOUCHPAD_MAX_WIDTH);
+ uint16_t height : N_BITS(I2C_HID_TOUCHPAD_MAX_HEIGHT);
+ uint16_t pressure : N_BITS(I2C_HID_TOUCHPAD_MAX_PRESSURE);
+ uint16_t orientation : N_BITS_ORIENTATION;
} __packed;
struct touch_report {
- uint8_t button:1;
- uint8_t count:7;
+ uint8_t button : 1;
+ uint8_t count : 7;
uint16_t timestamp;
struct finger finger[I2C_HID_TOUCHPAD_MAX_FINGERS];
} __packed;
struct mouse_report {
- uint8_t button1:1;
+ uint8_t button1 : 1;
/* Windows expects at least two button usages in a mouse report. Many
* touchpads on the Chromebook are a single clickable surface, so
* button2 isn't used. That said, we may later report a button2 event if
* necessary.
*/
- uint8_t button2:1;
- uint8_t unused:6;
+ uint8_t button2 : 1;
+ uint8_t unused : 6;
int8_t x;
int8_t y;
} __packed;
@@ -173,231 +167,215 @@ struct mouse_report {
*/
static const uint8_t report_desc[] = {
/* Mouse Collection */
- 0x05, 0x01, /* Usage Page (Generic Desktop) */
- 0x09, 0x02, /* Usage (Mouse) */
- 0xA1, 0x01, /* Collection (Application) */
- 0x85, REPORT_ID_MOUSE, /* Report ID (Mouse) */
- 0x09, 0x01, /* Usage (Pointer) */
- 0xA1, 0x00, /* Collection (Physical) */
- 0x05, 0x09, /* Usage Page (Button) */
- 0x19, 0x01, /* Usage Minimum (Button 1) */
- 0x29, 0x02, /* Usage Maximum (Button 2) */
- 0x15, 0x00, /* Logical Minimum (0) */
- 0x25, 0x01, /* Logical Maximum (1) */
- 0x75, 0x01, /* Report Size (1) */
- 0x95, 0x02, /* Report Count (2) */
- 0x81, 0x02, /* Input (Data,Var,Abs) */
- 0x95, 0x06, /* Report Count (6) */
- 0x81, 0x03, /* Input (Cnst,Var,Abs) */
- 0x05, 0x01, /* Usage Page (Generic Desktop) */
- 0x09, 0x30, /* Usage (X) */
- 0x09, 0x31, /* Usage (Y) */
- 0x15, 0x81, /* Logical Minimum (-127) */
- 0x25, 0x7F, /* Logical Maximum (127) */
- 0x75, 0x08, /* Report Size (8) */
- 0x95, 0x02, /* Report Count (2) */
- 0x81, 0x06, /* Input (Data,Var,Rel) */
- 0xC0, /* End Collection */
- 0xC0, /* End Collection */
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
+ 0x09, 0x02, /* Usage (Mouse) */
+ 0xA1, 0x01, /* Collection (Application) */
+ 0x85, REPORT_ID_MOUSE, /* Report ID (Mouse) */
+ 0x09, 0x01, /* Usage (Pointer) */
+ 0xA1, 0x00, /* Collection (Physical) */
+ 0x05, 0x09, /* Usage Page (Button) */
+ 0x19, 0x01, /* Usage Minimum (Button 1) */
+ 0x29, 0x02, /* Usage Maximum (Button 2) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x25, 0x01, /* Logical Maximum (1) */
+ 0x75, 0x01, /* Report Size (1) */
+ 0x95, 0x02, /* Report Count (2) */
+ 0x81, 0x02, /* Input (Data,Var,Abs) */
+ 0x95, 0x06, /* Report Count (6) */
+ 0x81, 0x03, /* Input (Cnst,Var,Abs) */
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
+ 0x09, 0x30, /* Usage (X) */
+ 0x09, 0x31, /* Usage (Y) */
+ 0x15, 0x81, /* Logical Minimum (-127) */
+ 0x25, 0x7F, /* Logical Maximum (127) */
+ 0x75, 0x08, /* Report Size (8) */
+ 0x95, 0x02, /* Report Count (2) */
+ 0x81, 0x06, /* Input (Data,Var,Rel) */
+ 0xC0, /* End Collection */
+ 0xC0, /* End Collection */
/* Touchpad Collection */
- 0x05, 0x0D, /* Usage Page (Digitizer) */
- 0x09, 0x05, /* Usage (Touch Pad) */
- 0xA1, 0x01, /* Collection (Application) */
- 0x85, REPORT_ID_TOUCH, /* Report ID (Touch) */
+ 0x05, 0x0D, /* Usage Page (Digitizer) */
+ 0x09, 0x05, /* Usage (Touch Pad) */
+ 0xA1, 0x01, /* Collection (Application) */
+ 0x85, REPORT_ID_TOUCH, /* Report ID (Touch) */
/* Button */
- 0x05, 0x09, /* Usage Page (Button) */
- 0x19, 0x01, /* Usage Minimum (0x01) */
- 0x29, 0x01, /* Usage Maximum (0x01) */
- 0x15, 0x00, /* Logical Minimum (0) */
- 0x25, 0x01, /* Logical Maximum (1) */
- 0x75, 0x01, /* Report Size (1) */
- 0x95, 0x01, /* Report Count (1) */
- 0x81, 0x02, /* Input (Data,Var,Abs) */
+ 0x05, 0x09, /* Usage Page (Button) */
+ 0x19, 0x01, /* Usage Minimum (0x01) */
+ 0x29, 0x01, /* Usage Maximum (0x01) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x25, 0x01, /* Logical Maximum (1) */
+ 0x75, 0x01, /* Report Size (1) */
+ 0x95, 0x01, /* Report Count (1) */
+ 0x81, 0x02, /* Input (Data,Var,Abs) */
/* Contact count */
- 0x05, 0x0D, /* Usage Page (Digitizer) */
- 0x09, 0x54, /* Usage (Contact count) */
- 0x25, I2C_HID_TOUCHPAD_MAX_FINGERS, /* Logical Max. (MAX_FINGERS) */
- 0x75, 0x07, /* Report Size (7) */
- 0x95, 0x01, /* Report Count (1) */
- 0x81, 0x02, /* Input (Data,Var,Abs) */
+ 0x05, 0x0D, /* Usage Page (Digitizer) */
+ 0x09, 0x54, /* Usage (Contact count) */
+ 0x25, I2C_HID_TOUCHPAD_MAX_FINGERS, /* Logical Max. (MAX_FINGERS) */
+ 0x75, 0x07, /* Report Size (7) */
+ 0x95, 0x01, /* Report Count (1) */
+ 0x81, 0x02, /* Input (Data,Var,Abs) */
/* Scan time */
- 0x55, 0x0C, /* Unit Exponent (-4) */
- 0x66, 0x01, 0x10, /* Unit (Seconds) */
- 0x47, 0xFF, 0xFF, 0x00, 0x00, /* Physical Maximum (65535) */
- 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535) */
- 0x75, 0x10, /* Report Size (16) */
- 0x95, 0x01, /* Report Count (1) */
- 0x05, 0x0D, /* Usage Page (Digitizers) */
- 0x09, 0x56, /* Usage (Scan Time) */
- 0x81, 0x02, /* Input (Data,Var,Abs) */
-
-#define FINGER(FINGER_NUMBER) \
- /* Finger FINGER_NUMBER */ \
- 0x05, 0x0D, /* Usage Page (Digitizer) */ \
- 0x09, 0x22, /* Usage (Finger) */ \
- 0xA1, 0x02, /* Collection (Logical) */ \
- 0x09, 0x47, /* Usage (Confidence) */ \
- 0x09, 0x42, /* Usage (Tip Switch) */ \
- 0x09, 0x32, /* Usage (In Range) */ \
- 0x15, 0x00, /* Logical Minimum (0) */ \
- 0x25, 0x01, /* Logical Maximum (1) */ \
- 0x75, 0x01, /* Report Size (1) */ \
- 0x95, 0x03, /* Report Count (3) */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x09, 0x51, /* Usage (Contact identifier) */ \
- 0x25, 0x1F, /* Logical Maximum (31) */ \
- 0x75, 0x05, /* Report Size (5) */ \
- 0x95, 0x01, /* Report Count (1) */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x05, 0x01, /* Usage Page (Generic Desktop) */ \
- 0x09, 0x30, /* Usage (X) */ \
- 0x55, 0x0E, /* Unit Exponent (-2) */ \
- 0x65, 0x11, /* Unit (SI Linear, Length: cm) */ \
- 0x35, 0x00, /* Physical Minimum (0) */ \
- 0x46, I2C_HID_TOUCHPAD_MAX_PHYSICAL_X&0xff, \
- I2C_HID_TOUCHPAD_MAX_PHYSICAL_X>>8, \
- /* Physical Maximum */ \
- 0x26, I2C_HID_TOUCHPAD_MAX_X&0xff, I2C_HID_TOUCHPAD_MAX_X>>8, \
- /* Logical Maximum */ \
- 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_X), \
- /* Report Size */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x09, 0x31, /* Usage (Y) */ \
- 0x46, I2C_HID_TOUCHPAD_MAX_PHYSICAL_Y&0xff, \
- I2C_HID_TOUCHPAD_MAX_PHYSICAL_Y>>8, \
- /* Physical Maximum */ \
- 0x26, I2C_HID_TOUCHPAD_MAX_Y&0xff, I2C_HID_TOUCHPAD_MAX_Y>>8, \
- /* Logical Maximum */ \
- 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_Y), \
- /* Report Size */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x05, 0x0D, /* Usage Page (Digitizer) */ \
- 0x09, 0x48, /* Usage (Width) */ \
- 0x26, I2C_HID_TOUCHPAD_MAX_WIDTH&0xff, I2C_HID_TOUCHPAD_MAX_WIDTH>>8, \
- /* Logical Maximum */ \
- 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_WIDTH), \
- /* Report Size */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x09, 0x49, /* Usage (Height) */ \
- 0x26, I2C_HID_TOUCHPAD_MAX_HEIGHT&0xff, I2C_HID_TOUCHPAD_MAX_HEIGHT>>8,\
- /* Logical Maximum */ \
- 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_HEIGHT), \
- /* Report Size */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x09, 0x30, /* Usage (Tip pressure) */ \
- 0x26, I2C_HID_TOUCHPAD_MAX_PRESSURE&0xff, \
- I2C_HID_TOUCHPAD_MAX_PRESSURE>>8, \
- /* Logical Maximum */ \
- 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_PRESSURE), \
- /* Report Size */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0x09, 0x3f, /* Usage (Azimuth Orientation) */ \
- 0x16, 0x00, 0x00, /* Logical Minimum (0) */ \
- 0x26, I2C_HID_TOUCHPAD_MAX_ORIENTATION&0xff, \
- I2C_HID_TOUCHPAD_MAX_ORIENTATION>>8, \
- /* Logical Maximum */ \
- 0x75, N_BITS_ORIENTATION, /* Report Size */ \
- 0x81, 0x02, /* Input (Data,Var,Abs) */ \
- 0xC0, /* End Collection */
-
- FINGER(1)
- FINGER(2)
- FINGER(3)
- FINGER(4)
- FINGER(5)
+ 0x55, 0x0C, /* Unit Exponent (-4) */
+ 0x66, 0x01, 0x10, /* Unit (Seconds) */
+ 0x47, 0xFF, 0xFF, 0x00, 0x00, /* Physical Maximum (65535) */
+ 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535) */
+ 0x75, 0x10, /* Report Size (16) */
+ 0x95, 0x01, /* Report Count (1) */
+ 0x05, 0x0D, /* Usage Page (Digitizers) */
+ 0x09, 0x56, /* Usage (Scan Time) */
+ 0x81, 0x02, /* Input (Data,Var,Abs) */
+
+#define FINGER(FINGER_NUMBER) \
+ /* Finger FINGER_NUMBER */ \
+ 0x05, 0x0D, /* Usage Page (Digitizer) */ \
+ 0x09, 0x22, /* Usage (Finger) */ \
+ 0xA1, 0x02, /* Collection (Logical) */ \
+ 0x09, 0x47, /* Usage (Confidence) */ \
+ 0x09, 0x42, /* Usage (Tip Switch) */ \
+ 0x09, 0x32, /* Usage (In Range) */ \
+ 0x15, 0x00, /* Logical Minimum (0) */ \
+ 0x25, 0x01, /* Logical Maximum (1) */ \
+ 0x75, 0x01, /* Report Size (1) */ \
+ 0x95, 0x03, /* Report Count (3) */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x09, 0x51, /* Usage (Contact identifier) */ \
+ 0x25, 0x1F, /* Logical Maximum (31) */ \
+ 0x75, 0x05, /* Report Size (5) */ \
+ 0x95, 0x01, /* Report Count (1) */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */ \
+ 0x09, 0x30, /* Usage (X) */ \
+ 0x55, 0x0E, /* Unit Exponent (-2) */ \
+ 0x65, 0x11, /* Unit (SI Linear, Length: cm) */ \
+ 0x35, 0x00, /* Physical Minimum (0) */ \
+ 0x46, I2C_HID_TOUCHPAD_MAX_PHYSICAL_X & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_PHYSICAL_X >> 8, /* Physical Maximum \
+ */ \
+ 0x26, I2C_HID_TOUCHPAD_MAX_X & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_X >> 8, /* Logical Maximum */ \
+ 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_X), /* Report Size */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x09, 0x31, /* Usage (Y) */ \
+ 0x46, I2C_HID_TOUCHPAD_MAX_PHYSICAL_Y & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_PHYSICAL_Y >> 8, /* Physical Maximum \
+ */ \
+ 0x26, I2C_HID_TOUCHPAD_MAX_Y & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_Y >> 8, /* Logical Maximum */ \
+ 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_Y), /* Report Size */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x05, 0x0D, /* Usage Page (Digitizer) */ \
+ 0x09, 0x48, /* Usage (Width) */ \
+ 0x26, I2C_HID_TOUCHPAD_MAX_WIDTH & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_WIDTH >> 8, /* Logical Maximum */ \
+ 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_WIDTH), /* Report Size \
+ */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x09, 0x49, /* Usage (Height) */ \
+ 0x26, I2C_HID_TOUCHPAD_MAX_HEIGHT & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_HEIGHT >> 8, /* Logical Maximum */ \
+ 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_HEIGHT), /* Report Size \
+ */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x09, 0x30, /* Usage (Tip pressure) */ \
+ 0x26, I2C_HID_TOUCHPAD_MAX_PRESSURE & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_PRESSURE >> 8, /* Logical Maximum */ \
+ 0x75, N_BITS(I2C_HID_TOUCHPAD_MAX_PRESSURE), /* Report \
+ Size */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0x09, 0x3f, /* Usage (Azimuth Orientation) */ \
+ 0x16, 0x00, 0x00, /* Logical Minimum (0) */ \
+ 0x26, I2C_HID_TOUCHPAD_MAX_ORIENTATION & 0xff, \
+ I2C_HID_TOUCHPAD_MAX_ORIENTATION >> 8, /* Logical Maximum \
+ */ \
+ 0x75, N_BITS_ORIENTATION, /* Report Size */ \
+ 0x81, 0x02, /* Input (Data,Var,Abs) */ \
+ 0xC0, /* End Collection */
+
+ FINGER(1) FINGER(2) FINGER(3) FINGER(4) FINGER(5)
#undef FINGER
- 0x05, 0x0D, /* Usage Page (Digitizer) */
- 0x85, REPORT_ID_DEVICE_CAPS, /* Report ID (Device Capabilities) */
- 0x09, 0x55, /* Usage (Contact Count Maximum) */
- 0x09, 0x59, /* Usage (Pad Type) */
- 0x75, 0x08, /* Report Size (8) */
- 0x95, 0x02, /* Report Count (2) */
- 0x25, 0x0F, /* Logical Maximum (15) */
- 0xB1, 0x02, /* Feature (Data,Var,Abs) */
- 0x06, 0x00, 0xFF, /* Usage Page (Vendor Defined) */
- 0x85, REPORT_ID_DEVICE_CERT, /* Report ID (Device Certification) */
- 0x09, 0xC5, /* Usage (Vendor Usage 0xC5) */
- 0x15, 0x00, /* Logical Minimum (0) */
- 0x26, 0xFF, 0x00, /* Logical Maximum (255) */
- 0x75, 0x08, /* Report Size (8) */
- 0x96, 0x00, 0x01, /* Report Count (256) */
- 0xB1, 0x02, /* Feature (Data,Var,Abs) */
- 0xC0, /* End Collection */
+ 0x05,
+ 0x0D, /* Usage Page (Digitizer) */
+ 0x85, REPORT_ID_DEVICE_CAPS, /* Report ID (Device Capabilities) */
+ 0x09, 0x55, /* Usage (Contact Count Maximum) */
+ 0x09, 0x59, /* Usage (Pad Type) */
+ 0x75, 0x08, /* Report Size (8) */
+ 0x95, 0x02, /* Report Count (2) */
+ 0x25, 0x0F, /* Logical Maximum (15) */
+ 0xB1, 0x02, /* Feature (Data,Var,Abs) */
+ 0x06, 0x00, 0xFF, /* Usage Page (Vendor Defined) */
+ 0x85, REPORT_ID_DEVICE_CERT, /* Report ID (Device Certification) */
+ 0x09, 0xC5, /* Usage (Vendor Usage 0xC5) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x26, 0xFF, 0x00, /* Logical Maximum (255) */
+ 0x75, 0x08, /* Report Size (8) */
+ 0x96, 0x00, 0x01, /* Report Count (256) */
+ 0xB1, 0x02, /* Feature (Data,Var,Abs) */
+ 0xC0, /* End Collection */
/* Configuration Collection */
- 0x05, 0x0D, /* Usage Page (Digitizer) */
- 0x09, 0x0E, /* Usage (Configuration) */
- 0xA1, 0x01, /* Collection (Application) */
- 0x85, REPORT_ID_INPUT_MODE, /* Report ID (Input Mode) */
- 0x09, 0x22, /* Usage (Finger) */
- 0xA1, 0x02, /* Collection (Logical) */
- 0x09, 0x52, /* Usage (Input Mode) */
- 0x15, 0x00, /* Logical Minimum (0) */
- 0x25, 0x0F, /* Logical Maximum (15) */
- 0x75, 0x08, /* Report Size (8) */
- 0x95, 0x01, /* Report Count (1) */
- 0xB1, 0x02, /* Feature (Data,Var,Abs) */
- 0xC0, /* End Collection */
- 0x09, 0x22, /* Usage (Finger) */
- 0xA1, 0x00, /* Collection (Physical) */
- 0x85, REPORT_ID_REPORTING, /* Report ID (Selective Reporting)*/
- 0x09, 0x57, /* Usage (Surface Switch) */
- 0x09, 0x58, /* Usage (Button Switch) */
- 0x75, 0x04, /* Report Size (4) */
- 0x95, 0x02, /* Report Count (2) */
- 0x25, 0x01, /* Logical Maximum (1) */
- 0xB1, 0x02, /* Feature (Data,Var,Abs) */
- 0xC0, /* End Collection */
- 0xC0, /* End Collection */
+ 0x05, 0x0D, /* Usage Page (Digitizer) */
+ 0x09, 0x0E, /* Usage (Configuration) */
+ 0xA1, 0x01, /* Collection (Application) */
+ 0x85, REPORT_ID_INPUT_MODE, /* Report ID (Input Mode) */
+ 0x09, 0x22, /* Usage (Finger) */
+ 0xA1, 0x02, /* Collection (Logical) */
+ 0x09, 0x52, /* Usage (Input Mode) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x25, 0x0F, /* Logical Maximum (15) */
+ 0x75, 0x08, /* Report Size (8) */
+ 0x95, 0x01, /* Report Count (1) */
+ 0xB1, 0x02, /* Feature (Data,Var,Abs) */
+ 0xC0, /* End Collection */
+ 0x09, 0x22, /* Usage (Finger) */
+ 0xA1, 0x00, /* Collection (Physical) */
+ 0x85, REPORT_ID_REPORTING, /* Report ID (Selective Reporting)*/
+ 0x09, 0x57, /* Usage (Surface Switch) */
+ 0x09, 0x58, /* Usage (Button Switch) */
+ 0x75, 0x04, /* Report Size (4) */
+ 0x95, 0x02, /* Report Count (2) */
+ 0x25, 0x01, /* Logical Maximum (1) */
+ 0xB1, 0x02, /* Feature (Data,Var,Abs) */
+ 0xC0, /* End Collection */
+ 0xC0, /* End Collection */
};
static const uint8_t device_caps[] = {
- I2C_HID_TOUCHPAD_MAX_FINGERS, /* Contact Count Maximum */
- 0x00, /* Pad Type: Depressible click-pad */
+ I2C_HID_TOUCHPAD_MAX_FINGERS, /* Contact Count Maximum */
+ 0x00, /* Pad Type: Depressible click-pad */
};
/* A 256-byte default blob for the 'device certification status' feature report
* expected by Windows.
*/
static const uint8_t device_cert[] = {
- 0xFC, 0x28, 0xFE, 0x84, 0x40, 0xCB, 0x9A, 0x87,
- 0x0D, 0xBE, 0x57, 0x3C, 0xB6, 0x70, 0x09, 0x88,
- 0x07, 0x97, 0x2D, 0x2B, 0xE3, 0x38, 0x34, 0xB6,
- 0x6C, 0xED, 0xB0, 0xF7, 0xE5, 0x9C, 0xF6, 0xC2,
- 0x2E, 0x84, 0x1B, 0xE8, 0xB4, 0x51, 0x78, 0x43,
- 0x1F, 0x28, 0x4B, 0x7C, 0x2D, 0x53, 0xAF, 0xFC,
- 0x47, 0x70, 0x1B, 0x59, 0x6F, 0x74, 0x43, 0xC4,
- 0xF3, 0x47, 0x18, 0x53, 0x1A, 0xA2, 0xA1, 0x71,
- 0xC7, 0x95, 0x0E, 0x31, 0x55, 0x21, 0xD3, 0xB5,
- 0x1E, 0xE9, 0x0C, 0xBA, 0xEC, 0xB8, 0x89, 0x19,
- 0x3E, 0xB3, 0xAF, 0x75, 0x81, 0x9D, 0x53, 0xB9,
- 0x41, 0x57, 0xF4, 0x6D, 0x39, 0x25, 0x29, 0x7C,
- 0x87, 0xD9, 0xB4, 0x98, 0x45, 0x7D, 0xA7, 0x26,
- 0x9C, 0x65, 0x3B, 0x85, 0x68, 0x89, 0xD7, 0x3B,
- 0xBD, 0xFF, 0x14, 0x67, 0xF2, 0x2B, 0xF0, 0x2A,
- 0x41, 0x54, 0xF0, 0xFD, 0x2C, 0x66, 0x7C, 0xF8,
- 0xC0, 0x8F, 0x33, 0x13, 0x03, 0xF1, 0xD3, 0xC1,
- 0x0B, 0x89, 0xD9, 0x1B, 0x62, 0xCD, 0x51, 0xB7,
- 0x80, 0xB8, 0xAF, 0x3A, 0x10, 0xC1, 0x8A, 0x5B,
- 0xE8, 0x8A, 0x56, 0xF0, 0x8C, 0xAA, 0xFA, 0x35,
- 0xE9, 0x42, 0xC4, 0xD8, 0x55, 0xC3, 0x38, 0xCC,
- 0x2B, 0x53, 0x5C, 0x69, 0x52, 0xD5, 0xC8, 0x73,
- 0x02, 0x38, 0x7C, 0x73, 0xB6, 0x41, 0xE7, 0xFF,
- 0x05, 0xD8, 0x2B, 0x79, 0x9A, 0xE2, 0x34, 0x60,
- 0x8F, 0xA3, 0x32, 0x1F, 0x09, 0x78, 0x62, 0xBC,
- 0x80, 0xE3, 0x0F, 0xBD, 0x65, 0x20, 0x08, 0x13,
- 0xC1, 0xE2, 0xEE, 0x53, 0x2D, 0x86, 0x7E, 0xA7,
- 0x5A, 0xC5, 0xD3, 0x7D, 0x98, 0xBE, 0x31, 0x48,
- 0x1F, 0xFB, 0xDA, 0xAF, 0xA2, 0xA8, 0x6A, 0x89,
- 0xD6, 0xBF, 0xF2, 0xD3, 0x32, 0x2A, 0x9A, 0xE4,
- 0xCF, 0x17, 0xB7, 0xB8, 0xF4, 0xE1, 0x33, 0x08,
- 0x24, 0x8B, 0xC4, 0x43, 0xA5, 0xE5, 0x24, 0xC2,
+ 0xFC, 0x28, 0xFE, 0x84, 0x40, 0xCB, 0x9A, 0x87, 0x0D, 0xBE, 0x57, 0x3C,
+ 0xB6, 0x70, 0x09, 0x88, 0x07, 0x97, 0x2D, 0x2B, 0xE3, 0x38, 0x34, 0xB6,
+ 0x6C, 0xED, 0xB0, 0xF7, 0xE5, 0x9C, 0xF6, 0xC2, 0x2E, 0x84, 0x1B, 0xE8,
+ 0xB4, 0x51, 0x78, 0x43, 0x1F, 0x28, 0x4B, 0x7C, 0x2D, 0x53, 0xAF, 0xFC,
+ 0x47, 0x70, 0x1B, 0x59, 0x6F, 0x74, 0x43, 0xC4, 0xF3, 0x47, 0x18, 0x53,
+ 0x1A, 0xA2, 0xA1, 0x71, 0xC7, 0x95, 0x0E, 0x31, 0x55, 0x21, 0xD3, 0xB5,
+ 0x1E, 0xE9, 0x0C, 0xBA, 0xEC, 0xB8, 0x89, 0x19, 0x3E, 0xB3, 0xAF, 0x75,
+ 0x81, 0x9D, 0x53, 0xB9, 0x41, 0x57, 0xF4, 0x6D, 0x39, 0x25, 0x29, 0x7C,
+ 0x87, 0xD9, 0xB4, 0x98, 0x45, 0x7D, 0xA7, 0x26, 0x9C, 0x65, 0x3B, 0x85,
+ 0x68, 0x89, 0xD7, 0x3B, 0xBD, 0xFF, 0x14, 0x67, 0xF2, 0x2B, 0xF0, 0x2A,
+ 0x41, 0x54, 0xF0, 0xFD, 0x2C, 0x66, 0x7C, 0xF8, 0xC0, 0x8F, 0x33, 0x13,
+ 0x03, 0xF1, 0xD3, 0xC1, 0x0B, 0x89, 0xD9, 0x1B, 0x62, 0xCD, 0x51, 0xB7,
+ 0x80, 0xB8, 0xAF, 0x3A, 0x10, 0xC1, 0x8A, 0x5B, 0xE8, 0x8A, 0x56, 0xF0,
+ 0x8C, 0xAA, 0xFA, 0x35, 0xE9, 0x42, 0xC4, 0xD8, 0x55, 0xC3, 0x38, 0xCC,
+ 0x2B, 0x53, 0x5C, 0x69, 0x52, 0xD5, 0xC8, 0x73, 0x02, 0x38, 0x7C, 0x73,
+ 0xB6, 0x41, 0xE7, 0xFF, 0x05, 0xD8, 0x2B, 0x79, 0x9A, 0xE2, 0x34, 0x60,
+ 0x8F, 0xA3, 0x32, 0x1F, 0x09, 0x78, 0x62, 0xBC, 0x80, 0xE3, 0x0F, 0xBD,
+ 0x65, 0x20, 0x08, 0x13, 0xC1, 0xE2, 0xEE, 0x53, 0x2D, 0x86, 0x7E, 0xA7,
+ 0x5A, 0xC5, 0xD3, 0x7D, 0x98, 0xBE, 0x31, 0x48, 0x1F, 0xFB, 0xDA, 0xAF,
+ 0xA2, 0xA8, 0x6A, 0x89, 0xD6, 0xBF, 0xF2, 0xD3, 0x32, 0x2A, 0x9A, 0xE4,
+ 0xCF, 0x17, 0xB7, 0xB8, 0xF4, 0xE1, 0x33, 0x08, 0x24, 0x8B, 0xC4, 0x43,
+ 0xA5, 0xE5, 0x24, 0xC2,
};
#define MAX_SIZEOF(a, b) (sizeof(a) > sizeof(b) ? sizeof(a) : sizeof(b))
@@ -431,7 +409,7 @@ static bool pending_probe;
static bool pending_reset;
/* Reports (double buffered) */
-#define MAX_REPORT_CNT 2
+#define MAX_REPORT_CNT 2
static struct touch_report touch_reports[MAX_REPORT_CNT];
static struct mouse_report mouse_reports[MAX_REPORT_CNT];
@@ -448,8 +426,8 @@ static uint8_t input_mode;
* |reporting.button_switch|, respectively.
*/
struct selective_reporting {
- uint8_t surface_switch:4;
- uint8_t button_switch:4;
+ uint8_t surface_switch : 4;
+ uint8_t button_switch : 4;
} __packed;
static struct selective_reporting reporting;
@@ -568,7 +546,7 @@ int i2c_hid_touchpad_process(unsigned int len, uint8_t *buffer,
break;
case I2C_HID_COMMAND_REGISTER:
*cmd = i2c_hid_touchpad_command_process(len, buffer,
- send_response, data);
+ send_response, data);
break;
default:
/* Unknown register has been received. */
@@ -697,9 +675,9 @@ void i2c_hid_compile_report(struct touchpad_event *event)
touch->finger[i].pressure = event->finger[i].pressure;
if (event->finger[i].is_palm)
touch->finger[i].pressure =
- I2C_HID_TOUCHPAD_MAX_PRESSURE;
+ I2C_HID_TOUCHPAD_MAX_PRESSURE;
touch->finger[i].orientation =
- event->finger[i].orientation;
+ event->finger[i].orientation;
contact_num++;
} else if (touch_old->finger[i].tip) {
/*
diff --git a/common/i2c_peripheral.c b/common/i2c_peripheral.c
index ebc7167f8d..3aa1951b91 100644
--- a/common/i2c_peripheral.c
+++ b/common/i2c_peripheral.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -29,6 +29,5 @@ static enum ec_status i2c_get_protocol_info(struct host_cmd_handler_args *args)
return EC_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO,
- i2c_get_protocol_info,
+DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, i2c_get_protocol_info,
EC_VER_MASK(0));
diff --git a/common/i2c_trace.c b/common/i2c_trace.c
index af65d85210..c7207698b7 100644
--- a/common/i2c_trace.c
+++ b/common/i2c_trace.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,8 +11,8 @@
#include "util.h"
#define CPUTS(outstr) cputs(CC_I2C, outstr)
-#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_I2C, format, ##args)
struct i2c_trace_range {
bool enabled;
@@ -23,18 +23,17 @@ struct i2c_trace_range {
static struct i2c_trace_range trace_entries[8];
-void i2c_trace_notify(int port, uint16_t addr_flags,
- const uint8_t *out_data, size_t out_size,
- const uint8_t *in_data, size_t in_size, int ret)
+void i2c_trace_notify(int port, uint16_t addr_flags, const uint8_t *out_data,
+ size_t out_size, const uint8_t *in_data, size_t in_size,
+ int ret)
{
size_t i;
uint16_t addr = I2C_STRIP_FLAGS(addr_flags);
for (i = 0; i < ARRAY_SIZE(trace_entries); i++)
- if (trace_entries[i].enabled
- && trace_entries[i].port == port
- && trace_entries[i].addr_lo <= addr
- && trace_entries[i].addr_hi >= addr)
+ if (trace_entries[i].enabled && trace_entries[i].port == port &&
+ trace_entries[i].addr_lo <= addr &&
+ trace_entries[i].addr_hi >= addr)
goto trace_enabled;
return;
@@ -66,19 +65,16 @@ static int command_i2ctrace_list(void)
for (i = 0; i < ARRAY_SIZE(trace_entries); i++) {
if (trace_entries[i].enabled) {
i2c_port = get_i2c_port(trace_entries[i].port);
- ccprintf("%-2zd %d %-8s 0x%X",
- i,
- trace_entries[i].port,
+ ccprintf("%-2zd %d %-8s 0x%X", i, trace_entries[i].port,
#ifndef CONFIG_ZEPHYR
i2c_port->name,
#else
"",
#endif /* CONFIG_ZEPHYR */
trace_entries[i].addr_lo);
- if (trace_entries[i].addr_hi
- != trace_entries[i].addr_lo)
- ccprintf(" to 0x%X",
- trace_entries[i].addr_hi);
+ if (trace_entries[i].addr_hi !=
+ trace_entries[i].addr_lo)
+ ccprintf(" to 0x%X", trace_entries[i].addr_hi);
ccprintf("\n");
}
}
@@ -95,8 +91,7 @@ static int command_i2ctrace_disable(size_t id)
return EC_SUCCESS;
}
-static int command_i2ctrace_enable(int port, int addr_lo,
- int addr_hi)
+static int command_i2ctrace_enable(int port, int addr_lo, int addr_hi)
{
struct i2c_trace_range *t;
struct i2c_trace_range *new_entry = NULL;
@@ -111,41 +106,34 @@ static int command_i2ctrace_enable(int port, int addr_lo,
* Scan thru existing entries to see if there is one we can
* extend instead of making a new entry
*/
- for (t = trace_entries;
- t < trace_entries + ARRAY_SIZE(trace_entries);
+ for (t = trace_entries; t < trace_entries + ARRAY_SIZE(trace_entries);
t++) {
if (t->enabled && t->port == port) {
/* Subset of existing range, do nothing */
- if (t->addr_lo <= addr_lo &&
- t->addr_hi >= addr_hi)
+ if (t->addr_lo <= addr_lo && t->addr_hi >= addr_hi)
return EC_SUCCESS;
/* Extends exising range on both directions, replace */
- if (t->addr_lo >= addr_lo &&
- t->addr_hi <= addr_hi) {
+ if (t->addr_lo >= addr_lo && t->addr_hi <= addr_hi) {
t->enabled = 0;
- return command_i2ctrace_enable(
- port, addr_lo, addr_hi);
+ return command_i2ctrace_enable(port, addr_lo,
+ addr_hi);
}
/* Extends existing range below */
if (t->addr_lo - 1 <= addr_hi &&
t->addr_hi >= addr_hi) {
t->enabled = 0;
- return command_i2ctrace_enable(
- port,
- addr_lo,
- t->addr_hi);
+ return command_i2ctrace_enable(port, addr_lo,
+ t->addr_hi);
}
/* Extends existing range above */
if (t->addr_lo <= addr_lo &&
t->addr_hi + 1 >= addr_lo) {
t->enabled = 0;
- return command_i2ctrace_enable(
- port,
- t->addr_lo,
- addr_hi);
+ return command_i2ctrace_enable(port, t->addr_lo,
+ addr_hi);
}
} else if (!t->enabled && !new_entry) {
new_entry = t;
@@ -165,8 +153,7 @@ static int command_i2ctrace_enable(int port, int addr_lo,
return EC_ERROR_MEMORY_ALLOCATION;
}
-
-static int command_i2ctrace(int argc, char **argv)
+static int command_i2ctrace(int argc, const char **argv)
{
int id_or_port;
int address_low;
@@ -204,14 +191,13 @@ static int command_i2ctrace(int argc, char **argv)
return EC_ERROR_PARAM_COUNT;
}
- return command_i2ctrace_enable(
- id_or_port, address_low, address_high);
+ return command_i2ctrace_enable(id_or_port, address_low,
+ address_high);
}
return EC_ERROR_PARAM1;
}
-DECLARE_CONSOLE_COMMAND(i2ctrace,
- command_i2ctrace,
+DECLARE_CONSOLE_COMMAND(i2ctrace, command_i2ctrace,
"[list | disable <id> | enable <port> <address> | "
"enable <port> <address-low> <address-high>]",
"Trace I2C transactions");
diff --git a/common/i2c_wedge.c b/common/i2c_wedge.c
index fc0a5132b7..ff8c5d494f 100644
--- a/common/i2c_wedge.c
+++ b/common/i2c_wedge.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -199,8 +199,7 @@ static void i2c_bang_xfer(int addr, int reg)
ccprintf(" read byte: %d\n", byte);
}
-static void i2c_bang_wedge_write(int addr, int byte, int bit_count,
- int reboot)
+static void i2c_bang_wedge_write(int addr, int byte, int bit_count, int reboot)
{
int i;
@@ -219,8 +218,7 @@ static void i2c_bang_wedge_write(int addr, int byte, int bit_count,
system_reset(0);
}
-static void i2c_bang_wedge_read(int addr, int reg, int bit_count,
- int reboot)
+static void i2c_bang_wedge_read(int addr, int reg, int bit_count, int reboot)
{
int i;
@@ -244,11 +242,11 @@ static void i2c_bang_wedge_read(int addr, int reg, int bit_count,
system_reset(0);
}
-#define WEDGE_WRITE 1
-#define WEDGE_READ 2
-#define WEDGE_REBOOT 4
+#define WEDGE_WRITE 1
+#define WEDGE_READ 2
+#define WEDGE_REBOOT 4
-static int command_i2c_wedge(int argc, char **argv)
+static int command_i2c_wedge(int argc, const char **argv)
{
int addr, reg, wedge_flag = 0, wedge_bit_count = -1;
char *e;
@@ -256,17 +254,17 @@ static int command_i2c_wedge(int argc, char **argv)
/* Verify that the I2C_PORT_HOST has SDA and SCL pins defined. */
if (get_sda_from_i2c_port(I2C_PORT_HOST, &tmp) != EC_SUCCESS ||
- get_scl_from_i2c_port(I2C_PORT_HOST, &tmp) != EC_SUCCESS) {
+ get_scl_from_i2c_port(I2C_PORT_HOST, &tmp) != EC_SUCCESS) {
ccprintf("Cannot wedge bus because no SCL and SDA pins are"
- "defined for this port. Check i2c_ports[].\n");
+ "defined for this port. Check i2c_ports[].\n");
return EC_SUCCESS;
}
if (argc < 3) {
ccputs("Usage: i2cwedge addr out_byte "
- "[wedge_flag [wedge_bit_count]]\n");
+ "[wedge_flag [wedge_bit_count]]\n");
ccputs(" wedge_flag - (1: wedge out; 2: wedge in;"
- " 5: wedge out+reboot; 6: wedge in+reboot)]\n");
+ " 5: wedge out+reboot; 6: wedge in+reboot)]\n");
ccputs(" wedge_bit_count - 0 to 8\n");
return EC_ERROR_UNKNOWN;
}
@@ -302,12 +300,12 @@ static int command_i2c_wedge(int argc, char **argv)
if (wedge_bit_count < 0)
wedge_bit_count = 8;
i2c_bang_wedge_write(addr, reg, wedge_bit_count,
- (wedge_flag & WEDGE_REBOOT));
+ (wedge_flag & WEDGE_REBOOT));
} else if (wedge_flag & WEDGE_READ) {
if (wedge_bit_count < 0)
wedge_bit_count = 2;
i2c_bang_wedge_read(addr, reg, wedge_bit_count,
- (wedge_flag & WEDGE_REBOOT));
+ (wedge_flag & WEDGE_REBOOT));
} else {
i2c_bang_xfer(addr, reg);
}
@@ -326,15 +324,14 @@ static int command_i2c_wedge(int argc, char **argv)
}
DECLARE_CONSOLE_COMMAND(i2cwedge, command_i2c_wedge,
"i2cwedge addr out_byte "
- "[wedge_flag [wedge_bit_count]]",
+ "[wedge_flag [wedge_bit_count]]",
"Wedge host I2C bus");
-static int command_i2c_unwedge(int argc, char **argv)
+static int command_i2c_unwedge(int argc, const char **argv)
{
i2c_unwedge(I2C_PORT_HOST);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(i2cunwedge, command_i2c_unwedge,
- "",
- "Unwedge host I2C bus");
+DECLARE_CONSOLE_COMMAND(i2cunwedge, command_i2c_unwedge, "",
+ "Unwedge host I2C bus");
diff --git a/common/inductive_charging.c b/common/inductive_charging.c
index 793f535afe..9700e37dcc 100644
--- a/common/inductive_charging.c
+++ b/common/inductive_charging.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 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/common/init_rom.c b/common/init_rom.c
index 2cee57f922..102c3a00ae 100644
--- a/common/init_rom.c
+++ b/common/init_rom.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/ioexpander.c b/common/ioexpander.c
index 2bed1039f4..0a08f37c46 100644
--- a/common/ioexpander.c
+++ b/common/ioexpander.c
@@ -1,18 +1,19 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* IO Expander Controller Common Code */
+#include "builtin/assert.h"
#include "gpio.h"
#include "hooks.h"
#include "ioexpander.h"
#include "system.h"
#include "util.h"
-#define CPRINTF(format, args...) cprintf(CC_GPIO, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_GPIO, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_GPIO, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_GPIO, format, ##args)
int signal_is_ioex(int signal)
{
@@ -68,7 +69,7 @@ int ioex_enable_interrupt(enum ioex_signal signal)
rv = ioex_is_valid_interrupt_signal(signal);
if (rv != EC_SUCCESS)
- return rv;
+ return rv;
drv = ioex_config[g->ioex].drv;
return drv->enable_interrupt(g->ioex, g->port, g->mask, 1);
@@ -82,7 +83,7 @@ int ioex_disable_interrupt(enum ioex_signal signal)
rv = ioex_is_valid_interrupt_signal(signal);
if (rv != EC_SUCCESS)
- return rv;
+ return rv;
drv = ioex_config[g->ioex].drv;
return drv->enable_interrupt(g->ioex, g->port, g->mask, 0);
@@ -107,8 +108,8 @@ int ioex_get_flags(enum ioex_signal signal, int *flags)
if (g == NULL)
return EC_ERROR_BUSY;
- return ioex_config[g->ioex].drv->get_flags_by_mask(g->ioex,
- g->port, g->mask, flags);
+ return ioex_config[g->ioex].drv->get_flags_by_mask(g->ioex, g->port,
+ g->mask, flags);
}
int ioex_set_flags(enum ioex_signal signal, int flags)
@@ -118,8 +119,8 @@ int ioex_set_flags(enum ioex_signal signal, int flags)
if (g == NULL)
return EC_ERROR_BUSY;
- return ioex_config[g->ioex].drv->set_flags_by_mask(g->ioex,
- g->port, g->mask, flags);
+ return ioex_config[g->ioex].drv->set_flags_by_mask(g->ioex, g->port,
+ g->mask, flags);
}
int ioex_get_level(enum ioex_signal signal, int *val)
@@ -129,8 +130,8 @@ int ioex_get_level(enum ioex_signal signal, int *val)
if (g == NULL)
return EC_ERROR_BUSY;
- return ioex_config[g->ioex].drv->get_level(g->ioex, g->port,
- g->mask, val);
+ return ioex_config[g->ioex].drv->get_level(g->ioex, g->port, g->mask,
+ val);
}
int ioex_set_level(enum ioex_signal signal, int value)
@@ -140,8 +141,8 @@ int ioex_set_level(enum ioex_signal signal, int value)
if (g == NULL)
return EC_ERROR_BUSY;
- return ioex_config[g->ioex].drv->set_level(g->ioex, g->port,
- g->mask, value);
+ return ioex_config[g->ioex].drv->set_level(g->ioex, g->port, g->mask,
+ value);
}
#ifdef CONFIG_IO_EXPANDER_SUPPORT_GET_PORT
@@ -198,7 +199,7 @@ int ioex_restore_gpio_state(int ioex, const int *state, int state_len)
}
rv = drv->set_flags_by_mask(g->ioex, g->port, g->mask,
- state[state_offset++]);
+ state[state_offset++]);
if (rv) {
CPRINTS("%s failed to set flags rv=%d", __func__, rv);
return rv;
@@ -233,8 +234,8 @@ int ioex_init(int ioex)
if (system_jumped_late())
flags &= ~(GPIO_LOW | GPIO_HIGH);
- drv->set_flags_by_mask(g->ioex, g->port,
- g->mask, flags);
+ drv->set_flags_by_mask(g->ioex, g->port, g->mask,
+ flags);
}
}
@@ -253,8 +254,8 @@ static void ioex_init_default(void)
* If the IO Expander has been initialized or if the default
* initialization is disabled, skip initializing.
*/
- if (ioex_config[i].flags & (IOEX_FLAGS_INITIALIZED |
- IOEX_FLAGS_DEFAULT_INIT_DISABLED))
+ if (ioex_config[i].flags &
+ (IOEX_FLAGS_INITIALIZED | IOEX_FLAGS_DEFAULT_INIT_DISABLED))
continue;
ioex_init(i);
diff --git a/common/ioexpander_commands.c b/common/ioexpander_commands.c
index a09337ea88..38ab82565a 100644
--- a/common/ioexpander_commands.c
+++ b/common/ioexpander_commands.c
@@ -1,7 +1,9 @@
-/* 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 "builtin/assert.h"
#include "console.h"
#include "gpio.h"
#include "ioexpander.h"
@@ -69,14 +71,13 @@ static void print_ioex_info(enum ioex_signal signal)
changed = last_val_changed(signal, val);
- ccprintf(" %d%c %s%s%s%s%s%s\n", val,
- (changed ? '*' : ' '),
+ ccprintf(" %d%c %s%s%s%s%s%s\n", val, (changed ? '*' : ' '),
(flags & GPIO_INPUT ? "I " : ""),
(flags & GPIO_OUTPUT ? "O " : ""),
(flags & GPIO_LOW ? "L " : ""),
(flags & GPIO_HIGH ? "H " : ""),
(flags & GPIO_OPEN_DRAIN ? "ODR " : ""),
- ioex_get_name(signal));
+ ioex_get_name(signal));
/* Flush console to avoid truncating output */
cflush();
@@ -99,7 +100,7 @@ static enum ec_error_list ioex_set(const char *name, int value)
return ioex_set_level(signal, value);
}
-static int command_ioex_set(int argc, char **argv)
+static int command_ioex_set(int argc, const char **argv)
{
char *e;
int v;
@@ -116,11 +117,10 @@ static int command_ioex_set(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(ioexset, command_ioex_set,
- "name <0 | 1>",
+DECLARE_CONSOLE_COMMAND(ioexset, command_ioex_set, "name <0 | 1>",
"Set level of a IO expander pin");
-static int command_ioex_get(int argc, char **argv)
+static int command_ioex_get(int argc, const char **argv)
{
enum ioex_signal signal;
@@ -140,6 +140,5 @@ static int command_ioex_get(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(ioexget, command_ioex_get,
- "[name]",
+DECLARE_SAFE_CONSOLE_COMMAND(ioexget, command_ioex_get, "[name]",
"Read level of IO expander pin(s)");
diff --git a/common/irq_locking.c b/common/irq_locking.c
index 3606b7aa15..1146145c5e 100644
--- a/common/irq_locking.c
+++ b/common/irq_locking.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/kasa.c b/common/kasa.c
index 79c75ad55b..6b974dc574 100644
--- a/common/kasa.c
+++ b/common/kasa.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/keyboard_8042.c b/common/keyboard_8042.c
index 755b26f360..e0371ddd5c 100644
--- a/common/keyboard_8042.c
+++ b/common/keyboard_8042.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -6,6 +6,7 @@
*/
#include "button.h"
+#include "builtin/assert.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -13,6 +14,7 @@
#include "hooks.h"
#include "host_command.h"
#include "i8042_protocol.h"
+#include "atkbd_protocol.h"
#include "keyboard_8042_sharedlib.h"
#include "keyboard_config.h"
#include "keyboard_protocol.h"
@@ -28,11 +30,11 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_KEYBOARD, outstr)
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
#ifdef CONFIG_KEYBOARD_DEBUG
#define CPUTS5(outstr) cputs(CC_KEYBOARD, outstr)
-#define CPRINTS5(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS5(format, args...) cprints(CC_KEYBOARD, format, ##args)
#else
#define CPUTS5(outstr)
#define CPRINTS5(format, args...)
@@ -44,23 +46,23 @@
* #define CMD_KEYBOARD_LOG IS_ENABLED(CONFIG_MALLOC)
*/
#ifdef CONFIG_MALLOC
-#define CMD_KEYBOARD_LOG 1
+#define CMD_KEYBOARD_LOG 1
#else
-#define CMD_KEYBOARD_LOG 0
+#define CMD_KEYBOARD_LOG 0
#endif
static enum {
- STATE_NORMAL = 0,
- STATE_SCANCODE,
- STATE_SETLEDS,
- STATE_EX_SETLEDS_1, /* Expect 2-byte parameter */
- STATE_EX_SETLEDS_2,
- STATE_WRITE_CMD_BYTE,
- STATE_WRITE_OUTPUT_PORT,
- STATE_ECHO_MOUSE,
- STATE_SETREP,
- STATE_SEND_TO_MOUSE,
-} data_port_state = STATE_NORMAL;
+ STATE_ATKBD_CMD = 0,
+ STATE_ATKBD_SCANCODE,
+ STATE_ATKBD_SETLEDS,
+ STATE_ATKBD_EX_SETLEDS_1, /* Expect 2-byte parameter */
+ STATE_ATKBD_EX_SETLEDS_2,
+ STATE_8042_WRITE_CMD_BYTE,
+ STATE_8042_WRITE_OUTPUT_PORT,
+ STATE_8042_ECHO_MOUSE,
+ STATE_ATKBD_SETREP,
+ STATE_8042_SEND_TO_MOUSE,
+} data_port_state = STATE_ATKBD_CMD;
enum scancode_set_list {
SCANCODE_GET_SET = 0,
@@ -123,9 +125,9 @@ static int i8042_keyboard_irq_enabled;
static int i8042_aux_irq_enabled;
/* i8042 global settings */
-static int keyboard_enabled; /* default the keyboard is disabled. */
-static int aux_chan_enabled; /* default the mouse is disabled. */
-static int keystroke_enabled; /* output keystrokes */
+static int keyboard_enabled; /* default the keyboard is disabled. */
+static int aux_chan_enabled; /* default the mouse is disabled. */
+static int keystroke_enabled; /* output keystrokes */
static uint8_t resend_command[MAX_SCAN_CODE_LEN];
static uint8_t resend_command_len;
static uint8_t controller_ram_address;
@@ -157,11 +159,11 @@ static enum scancode_set_list scancode_set = SCANCODE_SET_2;
static uint8_t typematic_value_from_host;
static int typematic_first_delay;
static int typematic_inter_delay;
-static int typematic_len; /* length of typematic_scan_code */
+static int typematic_len; /* length of typematic_scan_code */
static uint8_t typematic_scan_code[MAX_SCAN_CODE_LEN];
static timestamp_t typematic_deadline;
-#define KB_SYSJUMP_TAG 0x4b42 /* "KB" */
+#define KB_SYSJUMP_TAG 0x4b42 /* "KB" */
#define KB_HOOK_VERSION 2
/* the previous keyboard state before reboot_ec. */
struct kb_state {
@@ -174,7 +176,7 @@ struct kb_state {
/* Keyboard event log */
/* Log the traffic between EC and host -- for debug only */
-#define MAX_KBLOG 512 /* Max events in keyboard log */
+#define MAX_KBLOG 512 /* Max events in keyboard log */
struct kblog_t {
/*
@@ -202,8 +204,8 @@ struct kblog_t {
uint8_t byte;
};
-static struct kblog_t *kblog_buf; /* Log buffer; NULL if not logging */
-static int kblog_len; /* Current log length */
+static struct kblog_t *kblog_buf; /* Log buffer; NULL if not logging */
+static int kblog_len; /* Current log length */
/**
* Add event to keyboard log.
@@ -266,8 +268,8 @@ static void aux_enable_irq(int enable)
* @param to_host Data to send
* @param chan Channel to send data on
*/
-static void i8042_send_to_host(int len, const uint8_t *bytes,
- uint8_t chan)
+static void i8042_send_to_host(int len, const uint8_t *bytes, uint8_t chan,
+ int is_typematic)
{
int i;
struct data_byte data;
@@ -275,15 +277,20 @@ static void i8042_send_to_host(int len, const uint8_t *bytes,
/* Enqueue output data if there's space */
mutex_lock(&to_host_mutex);
- for (i = 0; i < len; i++)
- kblog_put(chan == CHAN_AUX ? 'a' : 's', bytes[i]);
-
- if (queue_space(&to_host) >= len) {
- kblog_put('t', to_host.state->tail);
- for (i = 0; i < len; i++) {
- data.chan = chan;
- data.byte = bytes[i];
- queue_add_unit(&to_host, &data);
+ if (is_typematic && !typematic_len) {
+ for (i = 0; i < len; i++)
+ kblog_put('r', bytes[i]);
+ } else {
+ for (i = 0; i < len; i++)
+ kblog_put(chan == CHAN_AUX ? 'a' : 's', bytes[i]);
+
+ if (queue_space(&to_host) >= len) {
+ kblog_put('t', to_host.state->tail);
+ for (i = 0; i < len; i++) {
+ data.chan = chan;
+ data.byte = bytes[i];
+ queue_add_unit(&to_host, &data);
+ }
}
}
mutex_unlock(&to_host_mutex);
@@ -364,8 +371,8 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col,
#ifdef CONFIG_KEYBOARD_SCANCODE_CALLBACK
{
- enum ec_error_list r = keyboard_scancode_callback(
- &make_code, pressed);
+ enum ec_error_list r =
+ keyboard_scancode_callback(&make_code, pressed);
if (r != EC_SUCCESS)
return r;
}
@@ -392,10 +399,10 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col,
static void set_typematic_delays(uint8_t data)
{
typematic_value_from_host = data;
- typematic_first_delay = MSEC *
- (((typematic_value_from_host & 0x60) >> 5) + 1) * 250;
- typematic_inter_delay = SECOND *
- (1 << ((typematic_value_from_host & 0x18) >> 3)) *
+ typematic_first_delay =
+ MSEC * (((typematic_value_from_host & 0x60) >> 5) + 1) * 250;
+ typematic_inter_delay =
+ SECOND * (1 << ((typematic_value_from_host & 0x18) >> 3)) *
((typematic_value_from_host & 0x7) + 8) / 240;
}
@@ -442,7 +449,8 @@ void keyboard_state_changed(int row, int col, int is_pressed)
if (mylabel & KEYCAP_LONG_LABEL_BIT)
CPRINTS("KB (%d,%d)=%d %s", row, col, is_pressed,
- get_keycap_long_label(mylabel & KEYCAP_LONG_LABEL_INDEX_BITMASK));
+ get_keycap_long_label(mylabel &
+ KEYCAP_LONG_LABEL_INDEX_BITMASK));
else
CPRINTS("KB (%d,%d)=%d %c", row, col, is_pressed, mylabel);
#endif
@@ -452,7 +460,7 @@ void keyboard_state_changed(int row, int col, int is_pressed)
if (ret == EC_SUCCESS) {
ASSERT(len > 0);
if (keystroke_enabled)
- i8042_send_to_host(len, scan_code, CHAN_KBD);
+ i8042_send_to_host(len, scan_code, CHAN_KBD, 0);
}
if (is_pressed) {
@@ -516,8 +524,8 @@ static void update_ctl_ram(uint8_t addr, uint8_t data)
orig = controller_ram[addr];
controller_ram[addr] = data;
- CPRINTS5("KB set CTR_RAM(0x%02x)=0x%02x (old:0x%02x)",
- addr, data, orig);
+ CPRINTS5("KB set CTR_RAM(0x%02x)=0x%02x (old:0x%02x)", addr, data,
+ orig);
if (addr == 0x00) {
/* Keyboard enable/disable */
@@ -555,19 +563,19 @@ static int handle_mouse_data(uint8_t data, uint8_t *output, int *count)
int out_len = 0;
switch (data_port_state) {
- case STATE_ECHO_MOUSE:
- CPRINTS5("STATE_ECHO_MOUSE: 0x%02x", data);
+ case STATE_8042_ECHO_MOUSE:
+ CPRINTS5("STATE_8042_ECHO_MOUSE: 0x%02x", data);
output[out_len++] = data;
- data_port_state = STATE_NORMAL;
+ data_port_state = STATE_ATKBD_CMD;
break;
- case STATE_SEND_TO_MOUSE:
- CPRINTS5("STATE_SEND_TO_MOUSE: 0x%02x", data);
+ case STATE_8042_SEND_TO_MOUSE:
+ CPRINTS5("STATE_8042_SEND_TO_MOUSE: 0x%02x", data);
send_aux_data_to_device(data);
- data_port_state = STATE_NORMAL;
+ data_port_state = STATE_ATKBD_CMD;
break;
- default: /* STATE_NORMAL */
+ default: /* STATE_ATKBD_CMD */
return 0;
}
@@ -590,120 +598,119 @@ static int handle_keyboard_data(uint8_t data, uint8_t *output)
int i;
switch (data_port_state) {
- case STATE_SCANCODE:
- CPRINTS5("KB eaten by STATE_SCANCODE: 0x%02x", data);
+ case STATE_ATKBD_SCANCODE:
+ CPRINTS5("KB eaten by STATE_ATKBD_SCANCODE: 0x%02x", data);
if (data == SCANCODE_GET_SET) {
- output[out_len++] = I8042_RET_ACK;
+ output[out_len++] = ATKBD_RET_ACK;
output[out_len++] = scancode_set;
} else {
scancode_set = data;
CPRINTS("KB scancode set to %d", scancode_set);
- output[out_len++] = I8042_RET_ACK;
+ output[out_len++] = ATKBD_RET_ACK;
}
- data_port_state = STATE_NORMAL;
+ data_port_state = STATE_ATKBD_CMD;
break;
- case STATE_SETLEDS:
- CPRINTS5("KB eaten by STATE_SETLEDS");
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_NORMAL;
+ case STATE_ATKBD_SETLEDS:
+ CPRINTS5("KB eaten by STATE_ATKBD_SETLEDS");
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_CMD;
break;
- case STATE_EX_SETLEDS_1:
- CPRINTS5("KB eaten by STATE_EX_SETLEDS_1");
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_EX_SETLEDS_2;
+ case STATE_ATKBD_EX_SETLEDS_1:
+ CPRINTS5("KB eaten by STATE_ATKBD_EX_SETLEDS_1");
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_EX_SETLEDS_2;
break;
- case STATE_EX_SETLEDS_2:
- CPRINTS5("KB eaten by STATE_EX_SETLEDS_2");
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_NORMAL;
+ case STATE_ATKBD_EX_SETLEDS_2:
+ CPRINTS5("KB eaten by STATE_ATKBD_EX_SETLEDS_2");
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_CMD;
break;
- case STATE_WRITE_CMD_BYTE:
- CPRINTS5("KB eaten by STATE_WRITE_CMD_BYTE: 0x%02x",
- data);
+ case STATE_8042_WRITE_CMD_BYTE:
+ CPRINTS5("KB eaten by STATE_8042_WRITE_CMD_BYTE: 0x%02x", data);
update_ctl_ram(controller_ram_address, data);
- data_port_state = STATE_NORMAL;
+ data_port_state = STATE_ATKBD_CMD;
break;
- case STATE_WRITE_OUTPUT_PORT:
- CPRINTS5("KB eaten by STATE_WRITE_OUTPUT_PORT: 0x%02x",
+ case STATE_8042_WRITE_OUTPUT_PORT:
+ CPRINTS5("KB eaten by STATE_8042_WRITE_OUTPUT_PORT: 0x%02x",
data);
A20_status = (data & BIT(1)) ? 1 : 0;
- data_port_state = STATE_NORMAL;
+ data_port_state = STATE_ATKBD_CMD;
break;
- case STATE_SETREP:
- CPRINTS5("KB eaten by STATE_SETREP: 0x%02x", data);
+ case STATE_ATKBD_SETREP:
+ CPRINTS5("KB eaten by STATE_ATKBD_SETREP: 0x%02x", data);
set_typematic_delays(data);
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_NORMAL;
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_CMD;
break;
- default: /* STATE_NORMAL */
+ default: /* STATE_ATKBD_CMD */
switch (data) {
- case I8042_CMD_GSCANSET: /* also I8042_CMD_SSCANSET */
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_SCANCODE;
+ case ATKBD_CMD_GSCANSET: /* also ATKBD_CMD_SSCANSET */
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_SCANCODE;
break;
- case I8042_CMD_SETLEDS:
+ case ATKBD_CMD_SETLEDS:
/* Chrome OS doesn't have keyboard LEDs, so ignore */
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_SETLEDS;
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_SETLEDS;
break;
- case I8042_CMD_EX_SETLEDS:
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_EX_SETLEDS_1;
+ case ATKBD_CMD_EX_SETLEDS:
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_EX_SETLEDS_1;
break;
- case I8042_CMD_DIAG_ECHO:
- output[out_len++] = I8042_RET_ACK;
- output[out_len++] = I8042_CMD_DIAG_ECHO;
+ case ATKBD_CMD_DIAG_ECHO:
+ output[out_len++] = ATKBD_RET_ACK;
+ output[out_len++] = ATKBD_RET_ECHO;
break;
- case I8042_CMD_GETID: /* fall-thru */
- case I8042_CMD_OK_GETID:
- output[out_len++] = I8042_RET_ACK;
- output[out_len++] = 0xab; /* Regular keyboards */
+ case ATKBD_CMD_GETID: /* fall-thru */
+ case ATKBD_CMD_OK_GETID:
+ output[out_len++] = ATKBD_RET_ACK;
+ output[out_len++] = 0xab; /* Regular keyboards */
output[out_len++] = 0x83;
break;
- case I8042_CMD_SETREP:
- output[out_len++] = I8042_RET_ACK;
- data_port_state = STATE_SETREP;
+ case ATKBD_CMD_SETREP:
+ output[out_len++] = ATKBD_RET_ACK;
+ data_port_state = STATE_ATKBD_SETREP;
break;
- case I8042_CMD_ENABLE:
- output[out_len++] = I8042_RET_ACK;
+ case ATKBD_CMD_ENABLE:
+ output[out_len++] = ATKBD_RET_ACK;
keystroke_enable(1);
keyboard_clear_buffer();
break;
- case I8042_CMD_RESET_DIS:
- output[out_len++] = I8042_RET_ACK;
+ case ATKBD_CMD_RESET_DIS:
+ output[out_len++] = ATKBD_RET_ACK;
keystroke_enable(0);
reset_rate_and_delay();
keyboard_clear_buffer();
break;
- case I8042_CMD_RESET_DEF:
- output[out_len++] = I8042_RET_ACK;
+ case ATKBD_CMD_RESET_DEF:
+ output[out_len++] = ATKBD_RET_ACK;
reset_rate_and_delay();
keyboard_clear_buffer();
break;
- case I8042_CMD_RESET:
+ case ATKBD_CMD_RESET:
reset_rate_and_delay();
keyboard_clear_buffer();
- output[out_len++] = I8042_RET_ACK;
+ output[out_len++] = ATKBD_RET_ACK;
break;
- case I8042_CMD_RESEND:
+ case ATKBD_CMD_RESEND:
save_for_resend = 0;
for (i = 0; i < resend_command_len; ++i)
output[out_len++] = resend_command[i];
@@ -714,12 +721,12 @@ static int handle_keyboard_data(uint8_t data, uint8_t *output)
/* U-boot hack. Just ignore; don't reply. */
break;
- case I8042_CMD_SETALL_MB: /* fall-thru */
- case I8042_CMD_SETALL_MBR:
- case I8042_CMD_EX_ENABLE:
+ case ATKBD_CMD_SETALL_MB: /* fall-thru */
+ case ATKBD_CMD_SETALL_MBR:
+ case ATKBD_CMD_EX_ENABLE:
default:
- output[out_len++] = I8042_RET_NAK;
- CPRINTS("KB Unsupported i8042 data 0x%02x",
+ output[out_len++] = ATKBD_RET_RESEND;
+ CPRINTS("KB Unsupported AT keyboard command 0x%02x",
data);
break;
}
@@ -763,14 +770,14 @@ static int handle_keyboard_command(uint8_t command, uint8_t *output)
break;
case I8042_WRITE_CMD_BYTE:
- data_port_state = STATE_WRITE_CMD_BYTE;
+ data_port_state = STATE_8042_WRITE_CMD_BYTE;
controller_ram_address = command - 0x60;
break;
case I8042_DIS_KB:
update_ctl_ram(0, read_ctl_ram(0) | I8042_KBD_DIS);
reset_rate_and_delay();
- typematic_len = 0; /* stop typematic */
+ typematic_len = 0; /* stop typematic */
keyboard_clear_buffer();
break;
@@ -784,16 +791,16 @@ static int handle_keyboard_command(uint8_t command, uint8_t *output)
output[out_len++] =
(lpc_keyboard_input_pending() ? BIT(5) : 0) |
(lpc_keyboard_has_char() ? BIT(4) : 0) |
- (A20_status ? BIT(1) : 0) |
- 1; /* Main processor in normal mode */
+ (A20_status ? BIT(1) : 0) | 1; /* Main processor in
+ normal mode */
break;
case I8042_WRITE_OUTPUT_PORT:
- data_port_state = STATE_WRITE_OUTPUT_PORT;
+ data_port_state = STATE_8042_WRITE_OUTPUT_PORT;
break;
case I8042_RESET_SELF_TEST:
- output[out_len++] = 0x55; /* Self test success */
+ output[out_len++] = 0x55; /* Self test success */
break;
case I8042_TEST_KB_PORT:
@@ -809,15 +816,15 @@ static int handle_keyboard_command(uint8_t command, uint8_t *output)
break;
case I8042_TEST_MOUSE:
- output[out_len++] = 0; /* No error detected */
+ output[out_len++] = 0; /* No error detected */
break;
case I8042_ECHO_MOUSE:
- data_port_state = STATE_ECHO_MOUSE;
+ data_port_state = STATE_8042_ECHO_MOUSE;
break;
case I8042_SEND_TO_MOUSE:
- data_port_state = STATE_SEND_TO_MOUSE;
+ data_port_state = STATE_8042_SEND_TO_MOUSE;
break;
case I8042_SYSTEM_RESET:
@@ -830,7 +837,7 @@ static int handle_keyboard_command(uint8_t command, uint8_t *output)
output[out_len++] = read_ctl_ram(command - 0x20);
} else if (command >= I8042_WRITE_CTL_RAM &&
command <= I8042_WRITE_CTL_RAM_END) {
- data_port_state = STATE_WRITE_CMD_BYTE;
+ data_port_state = STATE_8042_WRITE_CMD_BYTE;
controller_ram_address = command - 0x60;
} else if (command == I8042_DISABLE_A20) {
A20_status = 0;
@@ -848,7 +855,7 @@ static int handle_keyboard_command(uint8_t command, uint8_t *output)
reset_rate_and_delay();
keyboard_clear_buffer();
output[out_len++] = I8042_RET_NAK;
- data_port_state = STATE_NORMAL;
+ data_port_state = STATE_ATKBD_CMD;
}
break;
}
@@ -877,7 +884,7 @@ static void i8042_handle_from_host(void)
ret_len = handle_keyboard_data(h.byte, output);
}
- i8042_send_to_host(ret_len, output, chan);
+ i8042_send_to_host(ret_len, output, chan, 0);
}
}
@@ -905,9 +912,9 @@ void keyboard_protocol_task(void *u)
if (keystroke_enabled)
i8042_send_to_host(typematic_len,
typematic_scan_code,
- CHAN_KBD);
- typematic_deadline.val = t.val +
- typematic_inter_delay;
+ CHAN_KBD, 1);
+ typematic_deadline.val =
+ t.val + typematic_inter_delay;
wait = typematic_inter_delay;
} else {
/* Wait for remaining interval */
@@ -970,13 +977,13 @@ static void send_aux_data_to_host_deferred(void)
uint8_t data;
if (IS_ENABLED(CONFIG_DEVICE_EVENT) &&
- chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
+ chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
device_set_single_event(EC_DEVICE_EVENT_TRACKPAD);
while (!queue_is_empty(&aux_to_host_queue)) {
queue_remove_unit(&aux_to_host_queue, &data);
if (aux_chan_enabled && IS_ENABLED(CONFIG_8042_AUX))
- i8042_send_to_host(1, &data, CHAN_AUX);
+ i8042_send_to_host(1, &data, CHAN_AUX, 0);
else
CPRINTS("AUX Callback ignored");
}
@@ -1034,7 +1041,7 @@ test_mockable void keyboard_update_button(enum keyboard_button_type button,
if (keystroke_enabled) {
CPRINTS5("KB UPDATE BTN");
- i8042_send_to_host(len, scan_code, CHAN_KBD);
+ i8042_send_to_host(len, scan_code, CHAN_KBD, 0);
task_wake(TASK_ID_KEYPROTO);
}
}
@@ -1042,7 +1049,7 @@ test_mockable void keyboard_update_button(enum keyboard_button_type button,
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_KEYBOARD
-static int command_typematic(int argc, char **argv)
+static int command_typematic(int argc, const char **argv)
{
int i;
@@ -1064,13 +1071,13 @@ static int command_typematic(int argc, char **argv)
return EC_SUCCESS;
}
-static int command_codeset(int argc, char **argv)
+static int command_codeset(int argc, const char **argv)
{
if (argc == 2) {
int set = strtoi(argv[1], NULL, 0);
switch (set) {
- case SCANCODE_SET_1: /* fall-thru */
- case SCANCODE_SET_2: /* fall-thru */
+ case SCANCODE_SET_1: /* fall-thru */
+ case SCANCODE_SET_2: /* fall-thru */
scancode_set = set;
break;
default:
@@ -1083,7 +1090,7 @@ static int command_codeset(int argc, char **argv)
return EC_SUCCESS;
}
-static int command_controller_ram(int argc, char **argv)
+static int command_controller_ram(int argc, const char **argv)
{
int index;
@@ -1101,7 +1108,7 @@ static int command_controller_ram(int argc, char **argv)
return EC_SUCCESS;
}
-static int command_keyboard_log(int argc, char **argv)
+static int command_keyboard_log(int argc, const char **argv)
{
int i;
@@ -1109,8 +1116,8 @@ static int command_keyboard_log(int argc, char **argv)
if (argc == 1) {
ccprintf("KBC log (len=%d):\n", kblog_len);
for (i = 0; kblog_buf && i < kblog_len; ++i) {
- ccprintf("%c.%02x ",
- kblog_buf[i].type, kblog_buf[i].byte);
+ ccprintf("%c.%02x ", kblog_buf[i].type,
+ kblog_buf[i].byte);
if ((i & 15) == 15) {
ccputs("\n");
cflush();
@@ -1126,9 +1133,9 @@ static int command_keyboard_log(int argc, char **argv)
if (i) {
if (!kblog_buf) {
- int rv = SHARED_MEM_ACQUIRE_CHECK(
- sizeof(*kblog_buf) * MAX_KBLOG,
- (char **)&kblog_buf);
+ int rv = SHARED_MEM_ACQUIRE_CHECK(sizeof(*kblog_buf) *
+ MAX_KBLOG,
+ (char **)&kblog_buf);
if (rv != EC_SUCCESS)
kblog_buf = NULL;
kblog_len = 0;
@@ -1144,7 +1151,7 @@ static int command_keyboard_log(int argc, char **argv)
return EC_SUCCESS;
}
-static int command_keyboard(int argc, char **argv)
+static int command_keyboard(int argc, const char **argv)
{
int ena;
@@ -1159,7 +1166,7 @@ static int command_keyboard(int argc, char **argv)
return EC_SUCCESS;
}
-static int command_8042_internal(int argc, char **argv)
+static int command_8042_internal(int argc, const char **argv)
{
int i;
@@ -1204,24 +1211,19 @@ static int command_8042_internal(int argc, char **argv)
/* Zephyr only provides these as subcommands*/
#ifndef CONFIG_ZEPHYR
-DECLARE_CONSOLE_COMMAND(typematic, command_typematic,
- "[first] [inter]",
+DECLARE_CONSOLE_COMMAND(typematic, command_typematic, "[first] [inter]",
"Get/set typematic delays");
-DECLARE_CONSOLE_COMMAND(codeset, command_codeset,
- "[set]",
+DECLARE_CONSOLE_COMMAND(codeset, command_codeset, "[set]",
"Get/set keyboard codeset");
-DECLARE_CONSOLE_COMMAND(ctrlram, command_controller_ram,
- "index [value]",
+DECLARE_CONSOLE_COMMAND(ctrlram, command_controller_ram, "index [value]",
"Get/set keyboard controller RAM");
-DECLARE_CONSOLE_COMMAND(kblog, command_keyboard_log,
- "[on | off]",
+DECLARE_CONSOLE_COMMAND(kblog, command_keyboard_log, "[on | off]",
"Print or toggle keyboard event log");
-DECLARE_CONSOLE_COMMAND(kbd, command_keyboard,
- "[on | off]",
+DECLARE_CONSOLE_COMMAND(kbd, command_keyboard, "[on | off]",
"Print or toggle keyboard info");
#endif
-static int command_8042(int argc, char **argv)
+static int command_8042(int argc, const char **argv)
{
if (argc >= 2) {
if (!strcasecmp(argv[1], "internal"))
@@ -1239,16 +1241,16 @@ static int command_8042(int argc, char **argv)
else
return EC_ERROR_PARAM1;
} else {
- char *ctlram_argv[] = {"ctrlram", "0"};
+ const char *ctlram_argv[] = { "ctrlram", "0" };
ccprintf("\n- Typematic:\n");
command_typematic(argc, argv);
ccprintf("\n- Codeset:\n");
command_codeset(argc, argv);
ccprintf("\n- Control RAM:\n");
- command_controller_ram(
- sizeof(ctlram_argv) / sizeof(ctlram_argv[0]),
- ctlram_argv);
+ command_controller_ram(sizeof(ctlram_argv) /
+ sizeof(ctlram_argv[0]),
+ ctlram_argv);
if (CMD_KEYBOARD_LOG) {
ccprintf("\n- Keyboard log:\n");
command_keyboard_log(argc, argv);
@@ -1268,7 +1270,6 @@ DECLARE_CONSOLE_COMMAND(8042, command_8042,
"Print 8042 state in one place");
#endif
-
/*****************************************************************************/
/* Hooks */
@@ -1290,8 +1291,8 @@ static void keyboard_preserve_state(void)
state.ctlram = controller_ram[0];
state.keystroke_enabled = keystroke_enabled;
- system_add_jump_tag(KB_SYSJUMP_TAG, KB_HOOK_VERSION,
- sizeof(state), &state);
+ system_add_jump_tag(KB_SYSJUMP_TAG, KB_HOOK_VERSION, sizeof(state),
+ &state);
}
DECLARE_HOOK(HOOK_SYSJUMP, keyboard_preserve_state, HOOK_PRIO_DEFAULT);
diff --git a/common/keyboard_8042_sharedlib.c b/common/keyboard_8042_sharedlib.c
index a2ed5c4445..3e98c977b7 100644
--- a/common/keyboard_8042_sharedlib.c
+++ b/common/keyboard_8042_sharedlib.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -7,6 +7,7 @@
#include <stddef.h>
+#include "builtin/assert.h"
#include "button.h"
#include "keyboard_8042_sharedlib.h"
#include "keyboard_config.h"
@@ -17,25 +18,25 @@
#ifndef CONFIG_KEYBOARD_CUSTOMIZATION
/* The standard Chrome OS keyboard matrix table in scan code set 2. */
static uint16_t scancode_set2[KEYBOARD_COLS_MAX][KEYBOARD_ROWS] = {
- {0x0000, 0x0000, 0x0014, 0xe01f, 0xe014, 0xe007, 0x0000, 0x0000},
- {0xe01f, 0x0076, 0x000d, 0x000e, 0x001c, 0x001a, 0x0016, 0x0015},
- {0x0005, 0x000c, 0x0004, 0x0006, 0x0023, 0x0021, 0x0026, 0x0024},
- {0x0032, 0x0034, 0x002c, 0x002e, 0x002b, 0x002a, 0x0025, 0x002d},
- {0x0009, 0x0083, 0x000b, 0x0003, 0x001b, 0x0022, 0x001e, 0x001d},
- {0x0051, 0x0000, 0x005b, 0x0000, 0x0042, 0x0041, 0x003e, 0x0043},
- {0x0031, 0x0033, 0x0035, 0x0036, 0x003b, 0x003a, 0x003d, 0x003c},
- {0x0000, 0x0000, 0x0061, 0x0000, 0x0000, 0x0012, 0x0000, 0x0059},
- {0x0055, 0x0052, 0x0054, 0x004e, 0x004c, 0x004a, 0x0045, 0x004d},
- {0x0000, 0x0001, 0x000a, 0x002f, 0x004b, 0x0049, 0x0046, 0x0044},
- {0xe011, 0x0000, 0x006a, 0x0000, 0x005d, 0x0000, 0x0011, 0x0000},
+ { 0x0000, 0x0000, 0x0014, 0xe01f, 0xe014, 0xe007, 0x0000, 0x0000 },
+ { 0xe01f, 0x0076, 0x000d, 0x000e, 0x001c, 0x001a, 0x0016, 0x0015 },
+ { 0x0005, 0x000c, 0x0004, 0x0006, 0x0023, 0x0021, 0x0026, 0x0024 },
+ { 0x0032, 0x0034, 0x002c, 0x002e, 0x002b, 0x002a, 0x0025, 0x002d },
+ { 0x0009, 0x0083, 0x000b, 0x0003, 0x001b, 0x0022, 0x001e, 0x001d },
+ { 0x0051, 0x0000, 0x005b, 0x0000, 0x0042, 0x0041, 0x003e, 0x0043 },
+ { 0x0031, 0x0033, 0x0035, 0x0036, 0x003b, 0x003a, 0x003d, 0x003c },
+ { 0x0000, 0x0000, 0x0061, 0x0000, 0x0000, 0x0012, 0x0000, 0x0059 },
+ { 0x0055, 0x0052, 0x0054, 0x004e, 0x004c, 0x004a, 0x0045, 0x004d },
+ { 0x0000, 0x0001, 0x000a, 0x002f, 0x004b, 0x0049, 0x0046, 0x0044 },
+ { 0xe011, 0x0000, 0x006a, 0x0000, 0x005d, 0x0000, 0x0011, 0x0000 },
#ifndef CONFIG_KEYBOARD_KEYPAD
- {0x0000, 0x0066, 0x0000, 0x005d, 0x005a, 0x0029, 0xe072, 0xe075},
- {0x0000, 0x0064, 0x0000, 0x0067, 0x0000, 0x0000, 0xe074, 0xe06b},
+ { 0x0000, 0x0066, 0x0000, 0x005d, 0x005a, 0x0029, 0xe072, 0xe075 },
+ { 0x0000, 0x0064, 0x0000, 0x0067, 0x0000, 0x0000, 0xe074, 0xe06b },
#else
- {0x0000, 0x0066, 0xe071, 0x005d, 0x005a, 0x0029, 0xe072, 0xe075},
- {0xe06c, 0x0064, 0xe07d, 0x0067, 0xe069, 0xe07a, 0xe074, 0xe06b},
- {0xe04a, 0x007c, 0x007b, 0x0074, 0x0071, 0x0073, 0x006b, 0x0070},
- {0x006c, 0x0075, 0x007d, 0x0079, 0x007a, 0x0072, 0x0069, 0xe05a},
+ { 0x0000, 0x0066, 0xe071, 0x005d, 0x005a, 0x0029, 0xe072, 0xe075 },
+ { 0xe06c, 0x0064, 0xe07d, 0x0067, 0xe069, 0xe07a, 0xe074, 0xe06b },
+ { 0xe04a, 0x007c, 0x007b, 0x0074, 0x0071, 0x0073, 0x006b, 0x0070 },
+ { 0x006c, 0x0075, 0x007d, 0x0079, 0x007a, 0x0072, 0x0069, 0xe05a },
#endif
};
@@ -68,37 +69,32 @@ void set_scancode_set2(uint8_t row, uint8_t col, uint16_t val)
* see scancode_translate_set2_to_1 below).
*/
SHAREDLIB(const uint8_t scancode_translate_table[128] = {
- 0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
- 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
- 0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a,
- 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
- 0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c,
- 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
- 0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e,
- 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
- 0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60,
- 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
- 0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e,
- 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
- 0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b,
- 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
- 0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45,
- 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
-});
-
+ 0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58, 0x64, 0x44,
+ 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59, 0x65, 0x38, 0x2a, 0x70,
+ 0x1d, 0x10, 0x02, 0x5a, 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11,
+ 0x03, 0x5b, 0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c,
+ 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d, 0x69, 0x31,
+ 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e, 0x6a, 0x72, 0x32, 0x24,
+ 0x16, 0x08, 0x09, 0x5f, 0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b,
+ 0x0a, 0x60, 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
+ 0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e, 0x3a, 0x36,
+ 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76, 0x55, 0x56, 0x77, 0x78,
+ 0x79, 0x7a, 0x0e, 0x7b, 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e,
+ 0x7f, 0x6f, 0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45,
+ 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
+ });
#ifdef CONFIG_KEYBOARD_DEBUG
-SHAREDLIB(const
-static char * const keycap_long_label[KLLI_MAX & KEYCAP_LONG_LABEL_INDEX_BITMASK] = {
- "UNKNOWN", "F1", "F2", "F3",
- "F4", "F5", "F6", "F7",
- "F8", "F9", "F10", "F11",
- "F12", "F13", "F14", "F15",
- "L-ALT", "R-ALT", "L-CTR", "R-CTR",
- "L-SHT", "R-SHT", "ENTER", "SPACE",
- "B-SPC", "TAB", "SEARC", "LEFT",
- "RIGHT", "DOWN", "UP", "ESC",
-});
+SHAREDLIB(
+ const static char *const
+ keycap_long_label[KLLI_MAX & KEYCAP_LONG_LABEL_INDEX_BITMASK] = {
+ "UNKNOWN", "F1", "F2", "F3", "F4", "F5",
+ "F6", "F7", "F8", "F9", "F10", "F11",
+ "F12", "F13", "F14", "F15", "L-ALT", "R-ALT",
+ "L-CTR", "R-CTR", "L-SHT", "R-SHT", "ENTER", "SPACE",
+ "B-SPC", "TAB", "SEARC", "LEFT", "RIGHT", "DOWN",
+ "UP", "ESC",
+ });
const char *get_keycap_long_label(uint8_t idx)
{
@@ -109,38 +105,30 @@ const char *get_keycap_long_label(uint8_t idx)
#ifndef CONFIG_KEYBOARD_CUSTOMIZATION
static char keycap_label[KEYBOARD_COLS_MAX][KEYBOARD_ROWS] = {
- {KLLI_UNKNO, KLLI_UNKNO, KLLI_L_CTR, KLLI_SEARC,
- KLLI_R_CTR, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO},
- {KLLI_F11, KLLI_ESC, KLLI_TAB, '~',
- 'a', 'z', '1', 'q'},
- {KLLI_F1, KLLI_F4, KLLI_F3, KLLI_F2,
- 'd', 'c', '3', 'e'},
- {'b', 'g', 't', '5',
- 'f', 'v', '4', 'r'},
- {KLLI_F10, KLLI_F7, KLLI_F6, KLLI_F5,
- 's', 'x', '2', 'w'},
- {KLLI_UNKNO, KLLI_F12, ']', KLLI_F13,
- 'k', ',', '8', 'i'},
- {'n', 'h', 'y', '6',
- 'j', 'm', '7', 'u'},
- {KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
- KLLI_UNKNO, KLLI_L_SHT, KLLI_UNKNO, KLLI_R_SHT},
- {'=', '\'', '[', '-',
- ';', '/', '0', 'p'},
- {KLLI_F14, KLLI_F9, KLLI_F8, KLLI_UNKNO,
- '|', '.', '9', 'o'},
- {KLLI_R_ALT, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
- KLLI_UNKNO, KLLI_UNKNO, KLLI_L_ALT, KLLI_UNKNO},
- {KLLI_F15, KLLI_B_SPC, KLLI_UNKNO, '\\',
- KLLI_ENTER, KLLI_SPACE, KLLI_DOWN, KLLI_UP},
- {KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
- KLLI_UNKNO, KLLI_UNKNO, KLLI_RIGHT, KLLI_LEFT},
+ { KLLI_UNKNO, KLLI_UNKNO, KLLI_L_CTR, KLLI_SEARC, KLLI_R_CTR,
+ KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO },
+ { KLLI_F11, KLLI_ESC, KLLI_TAB, '~', 'a', 'z', '1', 'q' },
+ { KLLI_F1, KLLI_F4, KLLI_F3, KLLI_F2, 'd', 'c', '3', 'e' },
+ { 'b', 'g', 't', '5', 'f', 'v', '4', 'r' },
+ { KLLI_F10, KLLI_F7, KLLI_F6, KLLI_F5, 's', 'x', '2', 'w' },
+ { KLLI_UNKNO, KLLI_F12, ']', KLLI_F13, 'k', ',', '8', 'i' },
+ { 'n', 'h', 'y', '6', 'j', 'm', '7', 'u' },
+ { KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
+ KLLI_L_SHT, KLLI_UNKNO, KLLI_R_SHT },
+ { '=', '\'', '[', '-', ';', '/', '0', 'p' },
+ { KLLI_F14, KLLI_F9, KLLI_F8, KLLI_UNKNO, '|', '.', '9', 'o' },
+ { KLLI_R_ALT, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
+ KLLI_UNKNO, KLLI_L_ALT, KLLI_UNKNO },
+ { KLLI_F15, KLLI_B_SPC, KLLI_UNKNO, '\\', KLLI_ENTER, KLLI_SPACE,
+ KLLI_DOWN, KLLI_UP },
+ { KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
+ KLLI_UNKNO, KLLI_RIGHT, KLLI_LEFT },
#ifdef CONFIG_KEYBOARD_KEYPAD
/* TODO: Populate these */
- {KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
- KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO},
- {KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
- KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO},
+ { KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
+ KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO },
+ { KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO,
+ KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO },
#endif
};
@@ -174,16 +162,16 @@ uint8_t scancode_translate_set2_to_1(uint8_t code)
* Must be in the same order as defined in keyboard_button_type.
*/
SHAREDLIB(const struct button_8042_t buttons_8042[] = {
- {SCANCODE_POWER, 0},
- {SCANCODE_VOLUME_DOWN, 1},
- {SCANCODE_VOLUME_UP, 1},
- {SCANCODE_1, 1},
- {SCANCODE_2, 1},
- {SCANCODE_3, 1},
- {SCANCODE_4, 1},
- {SCANCODE_5, 1},
- {SCANCODE_6, 1},
- {SCANCODE_7, 1},
- {SCANCODE_8, 1},
-});
+ { SCANCODE_POWER, 0 },
+ { SCANCODE_VOLUME_DOWN, 1 },
+ { SCANCODE_VOLUME_UP, 1 },
+ { SCANCODE_1, 1 },
+ { SCANCODE_2, 1 },
+ { SCANCODE_3, 1 },
+ { SCANCODE_4, 1 },
+ { SCANCODE_5, 1 },
+ { SCANCODE_6, 1 },
+ { SCANCODE_7, 1 },
+ { SCANCODE_8, 1 },
+ });
BUILD_ASSERT(ARRAY_SIZE(buttons_8042) == KEYBOARD_BUTTON_COUNT);
diff --git a/common/keyboard_backlight.c b/common/keyboard_backlight.c
index 62da361d73..fde20de7ef 100644
--- a/common/keyboard_backlight.c
+++ b/common/keyboard_backlight.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -15,16 +15,20 @@
#include "timer.h"
#include "util.h"
-#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
static struct kblight_conf kblight;
static int current_percent;
static uint8_t current_enable;
-__overridable void board_kblight_init(void) {}
+__overridable void board_kblight_init(void)
+{
+}
-__overridable void board_kblight_shutdown(void) {}
+__overridable void board_kblight_shutdown(void)
+{
+}
static int kblight_init(void)
{
@@ -89,7 +93,6 @@ int kblight_get_enabled(void)
return -1;
}
-
int kblight_register(const struct kblight_drv *drv)
{
kblight.drv = drv;
@@ -137,7 +140,7 @@ static void kblight_resume(void)
}
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, kblight_resume, HOOK_PRIO_DEFAULT);
-#endif /* CONFIG_AP_POWER_CONTROL */
+#endif /* CONFIG_AP_POWER_CONTROL */
#ifdef CONFIG_LID_SWITCH
static void kblight_lid_change(void)
@@ -150,7 +153,7 @@ DECLARE_HOOK(HOOK_LID_CHANGE, kblight_lid_change, HOOK_PRIO_DEFAULT);
/*
* Console and host commands
*/
-static int cc_kblight(int argc, char **argv)
+static int cc_kblight(int argc, const char **argv)
{
if (argc >= 2) {
char *e;
@@ -162,12 +165,11 @@ static int cc_kblight(int argc, char **argv)
if (kblight_enable(i > 0))
return EC_ERROR_PARAM1;
}
- ccprintf("Keyboard backlight: %d%% enabled: %d\n",
- kblight_get(), kblight_get_enabled());
+ ccprintf("Keyboard backlight: %d%% enabled: %d\n", kblight_get(),
+ kblight_get_enabled());
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(kblight, cc_kblight,
- "percent",
+DECLARE_CONSOLE_COMMAND(kblight, cc_kblight, "percent",
"Get/set keyboard backlight");
static enum ec_status
@@ -182,8 +184,7 @@ hc_get_keyboard_backlight(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT,
- hc_get_keyboard_backlight,
- EC_VER_MASK(0));
+ hc_get_keyboard_backlight, EC_VER_MASK(0));
static enum ec_status
hc_set_keyboard_backlight(struct host_cmd_handler_args *args)
@@ -197,5 +198,11 @@ hc_set_keyboard_backlight(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT,
- hc_set_keyboard_backlight,
- EC_VER_MASK(0));
+ hc_set_keyboard_backlight, EC_VER_MASK(0));
+
+#ifdef TEST_BUILD
+uint8_t kblight_get_current_enable(void)
+{
+ return current_enable;
+}
+#endif /* TEST_BUILD */
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c
index 51c17a5cee..fa003c31a2 100644
--- a/common/keyboard_mkbp.c
+++ b/common/keyboard_mkbp.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -21,7 +21,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_KEYBOARD, outstr)
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
/* Changes to col,row here need to also be reflected in kernel.
* drivers/input/mkbp.c ... see KEY_BATTERY.
@@ -36,9 +36,9 @@
/* Config for mkbp protocol; does not include fields from scan config */
struct ec_mkbp_protocol_config {
- uint32_t valid_mask; /* valid fields */
- uint8_t flags; /* some flags (enum mkbp_config_flags) */
- uint8_t valid_flags; /* which flags are valid */
+ uint32_t valid_mask; /* valid fields */
+ uint8_t flags; /* some flags (enum mkbp_config_flags) */
+ uint8_t valid_flags; /* which flags are valid */
/* maximum depth to allow for fifo (0 = no keyscan output) */
uint8_t fifo_max_depth;
@@ -46,9 +46,10 @@ struct ec_mkbp_protocol_config {
static struct ec_mkbp_protocol_config config = {
.valid_mask = EC_MKBP_VALID_SCAN_PERIOD | EC_MKBP_VALID_POLL_TIMEOUT |
- EC_MKBP_VALID_MIN_POST_SCAN_DELAY |
- EC_MKBP_VALID_OUTPUT_SETTLE | EC_MKBP_VALID_DEBOUNCE_DOWN |
- EC_MKBP_VALID_DEBOUNCE_UP | EC_MKBP_VALID_FIFO_MAX_DEPTH,
+ EC_MKBP_VALID_MIN_POST_SCAN_DELAY |
+ EC_MKBP_VALID_OUTPUT_SETTLE |
+ EC_MKBP_VALID_DEBOUNCE_DOWN | EC_MKBP_VALID_DEBOUNCE_UP |
+ EC_MKBP_VALID_FIFO_MAX_DEPTH,
.valid_flags = EC_MKBP_FLAGS_ENABLE,
.flags = EC_MKBP_FLAGS_ENABLE,
.fifo_max_depth = FIFO_DEPTH,
@@ -81,7 +82,8 @@ static int keyboard_get_next_event(uint8_t *out)
DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_KEY_MATRIX, keyboard_get_next_event);
void clear_typematic_key(void)
-{ }
+{
+}
static void set_keyscan_config(const struct ec_mkbp_config *src,
struct ec_mkbp_protocol_config *dst,
@@ -119,11 +121,11 @@ static void set_keyscan_config(const struct ec_mkbp_config *src,
* fall out of the task_wait_event() in keyboard_scan_task().
*/
if ((new_flags & EC_MKBP_FLAGS_ENABLE) &&
- !(dst->flags & EC_MKBP_FLAGS_ENABLE))
+ !(dst->flags & EC_MKBP_FLAGS_ENABLE))
task_wake(TASK_ID_KEYSCAN);
}
-static void get_keyscan_config(struct ec_mkbp_config *dst)
+test_export_static void get_keyscan_config(struct ec_mkbp_config *dst)
{
const struct keyboard_scan_config *ksc = keyboard_scan_get_config();
@@ -151,15 +153,14 @@ static void get_keyscan_config(struct ec_mkbp_config *dst)
* over to dst->flags
*/
static void keyscan_copy_config(const struct ec_mkbp_config *src,
- struct ec_mkbp_protocol_config *dst,
- uint32_t valid_mask, uint8_t valid_flags)
+ struct ec_mkbp_protocol_config *dst,
+ uint32_t valid_mask, uint8_t valid_flags)
{
uint8_t new_flags;
if (valid_mask & EC_MKBP_VALID_FIFO_MAX_DEPTH) {
/* Validity check for fifo depth */
- dst->fifo_max_depth = MIN(src->fifo_max_depth,
- FIFO_DEPTH);
+ dst->fifo_max_depth = MIN(src->fifo_max_depth, FIFO_DEPTH);
}
new_flags = dst->flags & ~valid_flags;
@@ -182,8 +183,7 @@ host_command_mkbp_set_config(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_MKBP_SET_CONFIG,
- host_command_mkbp_set_config,
+DECLARE_HOST_COMMAND(EC_CMD_MKBP_SET_CONFIG, host_command_mkbp_set_config,
EC_VER_MASK(0));
static enum ec_status
@@ -206,6 +206,5 @@ host_command_mkbp_get_config(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_MKBP_GET_CONFIG,
- host_command_mkbp_get_config,
+DECLARE_HOST_COMMAND(EC_CMD_MKBP_GET_CONFIG, host_command_mkbp_get_config,
EC_VER_MASK(0));
diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c
index 26ffde96dc..6c3756170b 100644
--- a/common/keyboard_scan.c
+++ b/common/keyboard_scan.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,6 +19,7 @@
#include "keyboard_scan.h"
#include "keyboard_test.h"
#include "lid_switch.h"
+#include "printf.h"
#include "switch.h"
#include "system.h"
#include "tablet_mode.h"
@@ -27,23 +28,27 @@
#include "usb_api.h"
#include "util.h"
+#ifdef CONFIG_KEYBOARD_MULTIPLE
+#include "keyboard_customization.h"
+#endif
+
/* Console output macros */
#define CPUTS(outstr) cputs(CC_KEYSCAN, outstr)
-#define CPRINTF(format, args...) cprintf(CC_KEYSCAN, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_KEYSCAN, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_KEYSCAN, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_KEYSCAN, format, ##args)
#ifdef CONFIG_KEYBOARD_DEBUG
#define CPUTS5(outstr) cputs(CC_KEYSCAN, outstr)
-#define CPRINTS5(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS5(format, args...) cprints(CC_KEYBOARD, format, ##args)
#else
#define CPUTS5(outstr)
#define CPRINTS5(format, args...)
#endif
-#define SCAN_TIME_COUNT 32 /* Number of last scan times to track */
+#define SCAN_TIME_COUNT 32 /* Number of last scan times to track */
/* If we're waiting for a scan to happen, we'll give it this long */
-#define SCAN_TASK_TIMEOUT_US (100 * MSEC)
+#define SCAN_TASK_TIMEOUT_US (100 * MSEC)
#ifndef CONFIG_KEYBOARD_POST_SCAN_CLOCKS
/*
@@ -78,18 +83,20 @@ __overridable struct keyboard_scan_config keyscan_config = {
},
};
-/* Boot key list. Must be in same order as enum boot_key. */
-struct boot_key_entry {
- uint8_t col;
- uint8_t row;
-};
-
#ifdef CONFIG_KEYBOARD_BOOT_KEYS
+#ifndef CONFIG_KEYBOARD_MULTIPLE
static const struct boot_key_entry boot_key_list[] = {
- {KEYBOARD_COL_ESC, KEYBOARD_ROW_ESC}, /* Esc */
- {KEYBOARD_COL_DOWN, KEYBOARD_ROW_DOWN}, /* Down-arrow */
- {KEYBOARD_COL_LEFT_SHIFT, KEYBOARD_ROW_LEFT_SHIFT}, /* Left-Shift */
+ { KEYBOARD_COL_ESC, KEYBOARD_ROW_ESC }, /* Esc */
+ { KEYBOARD_COL_DOWN, KEYBOARD_ROW_DOWN }, /* Down-arrow */
+ { KEYBOARD_COL_LEFT_SHIFT, KEYBOARD_ROW_LEFT_SHIFT }, /* Left-Shift */
};
+#else
+struct boot_key_entry boot_key_list[] = {
+ { KEYBOARD_COL_ESC, KEYBOARD_ROW_ESC }, /* Esc */
+ { KEYBOARD_COL_DOWN, KEYBOARD_ROW_DOWN }, /* Down-arrow */
+ { KEYBOARD_COL_LEFT_SHIFT, KEYBOARD_ROW_LEFT_SHIFT }, /* Left-Shift */
+};
+#endif
static uint32_t boot_key_value = BOOT_KEY_NONE;
#endif
@@ -131,7 +138,7 @@ static volatile int kbd_polls;
/* If true, we'll force a keyboard poll */
static volatile int force_poll;
-static int keyboard_scan_is_enabled(void)
+test_export_static int keyboard_scan_is_enabled(void)
{
/* NOTE: this is just an instantaneous glimpse of the variable. */
return !disable_scanning_mask;
@@ -160,8 +167,10 @@ void keyboard_scan_enable(int enable, enum kb_scan_disable_masks mask)
static void print_state(const uint8_t *state, const char *msg)
{
int c;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
- CPRINTF("[%pT KB %s:", PRINTF_TIMESTAMP_NOW, msg);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s KB %s:", ts_str, msg);
for (c = 0; c < keyboard_cols; c++) {
if (state[c])
CPRINTF(" %02x", state[c]);
@@ -208,7 +217,7 @@ static int keyboard_read_adc_rows(void)
/* Read each adc channel to build row byte */
for (int i = 0; i < KEYBOARD_ROWS; i++) {
if (adc_read_channel(ADC_KSI_00 + i) >
- keyscan_config.ksi_threshold_mv)
+ keyscan_config.ksi_threshold_mv)
kb_row |= (1 << i);
}
@@ -226,14 +235,20 @@ static int keyboard_read_adc_rows(void)
*/
static void keyboard_read_refresh_key(uint8_t *state)
{
+#ifndef CONFIG_KEYBOARD_MULTIPLE
if (!gpio_get_level(GPIO_RFR_KEY_L))
state[KEYBOARD_COL_REFRESH] |= BIT(KEYBOARD_ROW_REFRESH);
else
state[KEYBOARD_COL_REFRESH] &= ~BIT(KEYBOARD_ROW_REFRESH);
+#else
+ if (!gpio_get_level(GPIO_RFR_KEY_L))
+ state[key_typ.col_refresh] |= BIT(key_typ.row_refresh);
+ else
+ state[key_typ.col_refresh] &= ~BIT(key_typ.row_refresh);
+#endif
}
#endif
-
/**
* Simulate a keypress.
*
@@ -246,7 +261,7 @@ static void simulate_key(int row, int col, int pressed)
int old_polls;
if ((simulated_key[col] & BIT(row)) == ((pressed ? 1 : 0) << row))
- return; /* No change */
+ return; /* No change */
simulated_key[col] ^= BIT(row);
@@ -266,8 +281,8 @@ static void simulate_key(int row, int col, int pressed)
* That means it needs to have run and for enough time.
*/
ensure_keyboard_scanned(old_polls);
- usleep(pressed ?
- keyscan_config.debounce_down_us : keyscan_config.debounce_up_us);
+ usleep(pressed ? keyscan_config.debounce_down_us :
+ keyscan_config.debounce_up_us);
ensure_keyboard_scanned(kbd_polls);
}
@@ -279,10 +294,11 @@ static void simulate_key(int row, int col, int pressed)
*
* @param state Destination for new state (must be KEYBOARD_COLS_MAX
* long).
+ * @param at_boot True if we are reading the boot key state.
*
* @return 1 if at least one key is pressed, else zero.
*/
-static int read_matrix(uint8_t *state)
+static int read_matrix(uint8_t *state, bool at_boot)
{
int c;
int pressed = 0;
@@ -317,6 +333,31 @@ static int read_matrix(uint8_t *state)
state[c] = keyscan_seq_get_scan(c, state[c]);
}
+#ifdef KEYBOARD_MASK_PWRBTN
+ /*
+ * 2. Boot key workaround.
+ *
+ * Check if KSI2 or KSI3 is asserted for all columns due to power
+ * button hold, and ignore it if so.
+ */
+ if (at_boot) {
+ for (c = 0; c < keyboard_cols; c++) {
+ if (!(state[c] & KEYBOARD_MASK_PWRBTN))
+ break;
+ }
+
+ if (c == keyboard_cols) {
+ for (c = 0; c < keyboard_cols; c++)
+ state[c] &= ~KEYBOARD_MASK_PWRBTN;
+#ifndef CONFIG_KEYBOARD_MULTIPLE
+ state[KEYBOARD_COL_REFRESH] |= KEYBOARD_MASK_PWRBTN;
+#else
+ state[key_typ.col_refresh] |= KEYBOARD_MASK_PWRBTN;
+#endif
+ }
+ }
+#endif
+
#ifdef CONFIG_KEYBOARD_SCAN_ADC
/* Account for the refresh key */
keyboard_read_refresh_key(state);
@@ -326,7 +367,7 @@ static int read_matrix(uint8_t *state)
* this check isn't required
*/
#else
- /* 2. Detect transitional ghost */
+ /* 3. Detect transitional ghost */
for (c = 0; c < keyboard_cols; c++) {
int c2;
@@ -351,7 +392,7 @@ static int read_matrix(uint8_t *state)
}
#endif
- /* 3. Fix result */
+ /* 4. Fix result */
for (c = 0; c < keyboard_cols; c++) {
/* Add in simulated keypresses */
state[c] |= simulated_key[c];
@@ -365,7 +406,6 @@ static int read_matrix(uint8_t *state)
/* Mask off keys that don't exist on the actual keyboard */
state[c] &= keyscan_config.actual_key_mask[c];
-
}
keyboard_raw_drive_column(KEYBOARD_COLUMN_NONE);
@@ -437,9 +477,15 @@ static int check_runtime_keys(const uint8_t *state)
if (state[key_vol_up_col] != KEYBOARD_ROW_TO_MASK(key_vol_up_row))
return 0;
+#ifndef CONFIG_KEYBOARD_MULTIPLE
if (state[KEYBOARD_COL_RIGHT_ALT] != KEYBOARD_MASK_RIGHT_ALT &&
state[KEYBOARD_COL_LEFT_ALT] != KEYBOARD_MASK_LEFT_ALT)
return 0;
+#else
+ if (state[key_typ.col_right_alt] != KEYBOARD_MASK_RIGHT_ALT &&
+ state[key_typ.col_left_alt] != KEYBOARD_MASK_LEFT_ALT)
+ return 0;
+#endif
/*
* Count number of columns with keys pressed. We know two columns are
@@ -454,6 +500,7 @@ static int check_runtime_keys(const uint8_t *state)
if (num_press != 3)
return 0;
+#ifndef CONFIG_KEYBOARD_MULTIPLE
/* Check individual keys */
if (state[KEYBOARD_COL_KEY_R] == KEYBOARD_MASK_KEY_R) {
/* R = reboot */
@@ -467,6 +514,21 @@ static int check_runtime_keys(const uint8_t *state)
system_enter_hibernate(0, 0);
return 1;
}
+#else
+ /* Check individual keys */
+ if (state[key_typ.col_key_r] == KEYBOARD_MASK_KEY_R) {
+ /* R = reboot */
+ CPRINTS("KB warm reboot");
+ keyboard_clear_buffer();
+ chipset_reset(CHIPSET_RESET_KB_WARM_REBOOT);
+ return 1;
+ } else if (state[key_typ.col_key_h] == KEYBOARD_MASK_KEY_H) {
+ /* H = hibernate */
+ CPRINTS("KB hibernate");
+ system_enter_hibernate(0, 0);
+ return 1;
+ }
+#endif
return 0;
}
@@ -510,7 +572,7 @@ static int has_ghosting(const uint8_t *state)
}
/* Inform keyboard module if scanning is enabled */
-static void key_state_changed(int row, int col, uint8_t state)
+test_mockable_static void key_state_changed(int row, int col, uint8_t state)
{
if (!keyboard_scan_is_enabled())
return;
@@ -540,7 +602,7 @@ static int check_keys_changed(uint8_t *state)
scan_time[scan_time_index] = tnow;
/* Read the raw key state */
- any_pressed = read_matrix(new_state);
+ any_pressed = read_matrix(new_state, false);
if (!IS_ENABLED(CONFIG_KEYBOARD_SCAN_ADC)) {
/* Ignore if so many keys are pressed that we're ghosting. */
@@ -559,7 +621,7 @@ static int check_keys_changed(uint8_t *state)
if (tnow - scan_time[scan_edge_index[c][i]] <
(state[c] ? keyscan_config.debounce_down_us :
keyscan_config.debounce_up_us))
- continue; /* Not done debouncing */
+ continue; /* Not done debouncing */
debouncing[c] &= ~BIT(i);
if (!IS_ENABLED(CONFIG_KEYBOARD_STRICT_DEBOUNCE))
@@ -604,7 +666,6 @@ static int check_keys_changed(uint8_t *state)
}
if (any_change) {
-
#ifdef CONFIG_KEYBOARD_SUPPRESS_NOISE
/* Suppress keyboard noise */
keyboard_suppress_noise();
@@ -615,11 +676,14 @@ static int check_keys_changed(uint8_t *state)
#ifdef CONFIG_KEYBOARD_PRINT_SCAN_TIMES
/* Print delta times from now back to each previous scan */
- CPRINTF("[%pT kb deltaT", PRINTF_TIMESTAMP_NOW);
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
+
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s kb deltaT", ts_str);
for (i = 0; i < SCAN_TIME_COUNT; i++) {
- int tnew = scan_time[
- (SCAN_TIME_COUNT + scan_time_index - i) %
- SCAN_TIME_COUNT];
+ int tnew = scan_time[(SCAN_TIME_COUNT +
+ scan_time_index - i) %
+ SCAN_TIME_COUNT];
CPRINTF(" %d", tnow - tnew);
}
CPRINTF("]\n");
@@ -665,22 +729,11 @@ static uint32_t check_key_list(const uint8_t *state)
/* Make copy of current debounced state. */
memcpy(curr_state, state, sizeof(curr_state));
-#ifdef KEYBOARD_MASK_PWRBTN
- /*
- * Check if KSI2 or KSI3 is asserted for all columns due to power
- * button hold, and ignore it if so.
- */
- for (c = 0; c < keyboard_cols; c++)
- if ((keyscan_config.actual_key_mask[c] & KEYBOARD_MASK_PWRBTN)
- && !(curr_state[c] & KEYBOARD_MASK_PWRBTN))
- break;
-
- if (c == keyboard_cols)
- for (c = 0; c < keyboard_cols; c++)
- curr_state[c] &= ~KEYBOARD_MASK_PWRBTN;
-#endif
-
+#ifndef CONFIG_KEYBOARD_MULTIPLE
curr_state[KEYBOARD_COL_REFRESH] &= ~keyboard_mask_refresh;
+#else
+ curr_state[key_typ.col_refresh] &= ~keyboard_mask_refresh;
+#endif
/* Update mask with all boot keys that were pressed. */
k = boot_key_list;
@@ -715,7 +768,7 @@ static void read_adc_boot_keys(uint8_t *state)
udelay(keyscan_config.output_settle_us);
if (adc_read_channel(ADC_KSI_00 + r) >
- keyscan_config.ksi_threshold_mv)
+ keyscan_config.ksi_threshold_mv)
state[c] |= BIT(r);
}
@@ -745,10 +798,16 @@ static uint32_t check_boot_key(const uint8_t *state)
if (system_jumped_late())
return BOOT_KEY_NONE;
- /* If reset was not caused by reset pin, refresh must be held down */
+/* If reset was not caused by reset pin, refresh must be held down */
+#ifndef CONFIG_KEYBOARD_MULTIPLE
if (!(system_get_reset_flags() & EC_RESET_FLAG_RESET_PIN) &&
!(state[KEYBOARD_COL_REFRESH] & keyboard_mask_refresh))
return BOOT_KEY_NONE;
+#else
+ if (!(system_get_reset_flags() & EC_RESET_FLAG_RESET_PIN) &&
+ !(state[key_typ.col_refresh] & keyboard_mask_refresh))
+ return BOOT_KEY_NONE;
+#endif
return check_key_list(state);
}
@@ -757,7 +816,7 @@ static uint32_t check_boot_key(const uint8_t *state)
static void keyboard_freq_change(void)
{
post_scan_clock_us = (CONFIG_KEYBOARD_POST_SCAN_CLOCKS * 1000) /
- (clock_get_freq() / 1000);
+ (clock_get_freq() / 1000);
}
DECLARE_HOOK(HOOK_FREQ_CHANGE, keyboard_freq_change, HOOK_PRIO_DEFAULT);
@@ -793,8 +852,8 @@ void keyboard_scan_init(void)
}
/* Configure refresh key matrix */
- keyboard_mask_refresh = KEYBOARD_ROW_TO_MASK(
- board_keyboard_row_refresh());
+ keyboard_mask_refresh =
+ KEYBOARD_ROW_TO_MASK(board_keyboard_row_refresh());
if (!IS_ENABLED(CONFIG_KEYBOARD_SCAN_ADC))
/* Configure GPIO */
@@ -805,7 +864,7 @@ void keyboard_scan_init(void)
/* Initialize raw state */
#ifndef CONFIG_KEYBOARD_SCAN_ADC
- read_matrix(debounced_state);
+ read_matrix(debounced_state, true);
#else
read_adc_boot_keys(debounced_state);
#endif
@@ -875,7 +934,8 @@ void keyboard_scan_task(void *u)
if (local_disable_scanning != new_disable_scanning)
CPRINTS("KB disable_scanning_mask changed: "
- "0x%08x", new_disable_scanning);
+ "0x%08x",
+ new_disable_scanning);
if (!new_disable_scanning) {
/* Enabled now */
@@ -910,7 +970,7 @@ void keyboard_scan_task(void *u)
#else
if (!local_disable_scanning &&
(keyboard_read_adc_rows() || force_poll ||
- !gpio_get_level(GPIO_RFR_KEY_L)))
+ !gpio_get_level(GPIO_RFR_KEY_L)))
break;
#endif
else
@@ -931,15 +991,16 @@ void keyboard_scan_task(void *u)
/* Check for keys down */
if (check_keys_changed(debounced_state)) {
- poll_deadline.val = start.val
- + keyscan_config.poll_timeout_us;
+ poll_deadline.val =
+ start.val +
+ keyscan_config.poll_timeout_us;
} else if (timestamp_expired(poll_deadline, &start)) {
break;
}
/* Delay between scans */
wait_time = keyscan_config.scan_period_us -
- (get_time().val - start.val);
+ (get_time().val - start.val);
if (wait_time < keyscan_config.min_post_scan_delay_us)
wait_time =
@@ -1001,8 +1062,7 @@ mkbp_command_simulate_key(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_MKBP_SIMULATE_KEY,
- mkbp_command_simulate_key,
+DECLARE_HOST_COMMAND(EC_CMD_MKBP_SIMULATE_KEY, mkbp_command_simulate_key,
EC_VER_MASK(0));
#ifdef CONFIG_KEYBOARD_FACTORY_TEST
@@ -1020,17 +1080,15 @@ int keyboard_factory_test_scan(void)
/* Set all of KSO/KSI pins to internal pull-up and input */
for (i = 0; i < keyboard_factory_scan_pins_used; i++) {
-
if (keyboard_factory_scan_pins[i][0] < 0)
continue;
port = keyboard_factory_scan_pins[i][0];
id = keyboard_factory_scan_pins[i][1];
- gpio_set_alternate_function(port, 1 << id,
- GPIO_ALT_FUNC_NONE);
+ gpio_set_alternate_function(port, 1 << id, GPIO_ALT_FUNC_NONE);
gpio_set_flags_by_mask(port, 1 << id,
- GPIO_INPUT | GPIO_PULL_UP);
+ GPIO_INPUT | GPIO_PULL_UP);
}
/*
@@ -1038,7 +1096,6 @@ int keyboard_factory_test_scan(void)
* going to low level, it indicate the two pins are shorted.
*/
for (i = 0; i < keyboard_factory_scan_pins_used; i++) {
-
if (keyboard_factory_scan_pins[i][0] < 0)
continue;
@@ -1048,19 +1105,18 @@ int keyboard_factory_test_scan(void)
gpio_set_flags_by_mask(port, 1 << id, GPIO_OUT_LOW);
for (j = 0; j < keyboard_factory_scan_pins_used; j++) {
-
if (keyboard_factory_scan_pins[j][0] < 0 || i == j)
continue;
if (keyboard_raw_is_input_low(
- keyboard_factory_scan_pins[j][0],
- keyboard_factory_scan_pins[j][1])) {
+ keyboard_factory_scan_pins[j][0],
+ keyboard_factory_scan_pins[j][1])) {
shorted = i << 8 | j;
goto done;
}
}
gpio_set_flags_by_mask(port, 1 << id,
- GPIO_INPUT | GPIO_PULL_UP);
+ GPIO_INPUT | GPIO_PULL_UP);
}
done:
gpio_config_module(MODULE_KEYBOARD_SCAN, 1);
@@ -1088,8 +1144,7 @@ static enum ec_status keyboard_factory_test(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_KEYBOARD_FACTORY_TEST,
- keyboard_factory_test,
+DECLARE_HOST_COMMAND(EC_CMD_KEYBOARD_FACTORY_TEST, keyboard_factory_test,
EC_VER_MASK(0));
#endif
@@ -1116,7 +1171,7 @@ int keyboard_get_keyboard_id(void)
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_KEYBOARD
-static int command_ksstate(int argc, char **argv)
+static int command_ksstate(int argc, const char **argv)
{
if (argc > 1) {
if (!strcasecmp(argv[1], "force")) {
@@ -1130,17 +1185,15 @@ static int command_ksstate(int argc, char **argv)
print_state(debounced_state, "debounced ");
print_state(debouncing, "debouncing");
- ccprintf("Keyboard scan disable mask: 0x%08x\n",
- disable_scanning_mask);
+ ccprintf("Keyboard scan disable mask: 0x%08x\n", disable_scanning_mask);
ccprintf("Keyboard scan state printing %s\n",
print_state_changes ? "on" : "off");
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(ksstate, command_ksstate,
- "ksstate [on | off | force]",
+DECLARE_CONSOLE_COMMAND(ksstate, command_ksstate, "ksstate [on | off | force]",
"Show or toggle printing keyboard scan state");
-static int command_keyboard_press(int argc, char **argv)
+static int command_keyboard_press(int argc, const char **argv)
{
if (argc == 1) {
int i, j;
@@ -1181,7 +1234,18 @@ static int command_keyboard_press(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(kbpress, command_keyboard_press,
- "[col row [0 | 1]]",
+DECLARE_CONSOLE_COMMAND(kbpress, command_keyboard_press, "[col row [0 | 1]]",
"Simulate keypress");
#endif
+
+#ifdef TEST_BUILD
+__test_only int keyboard_scan_get_print_state_changes(void)
+{
+ return print_state_changes;
+}
+
+__test_only void keyboard_scan_set_print_state_changes(int val)
+{
+ print_state_changes = val;
+}
+#endif /* TEST_BUILD */
diff --git a/common/keyboard_test.c b/common/keyboard_test.c
index e7b1dfe501..eb6fc11bdd 100644
--- a/common/keyboard_test.c
+++ b/common/keyboard_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 The Chromium OS Authors. All rights reserved.
+ * Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,8 +13,8 @@
#include <util.h>
enum {
- KEYSCAN_MAX_LENGTH = 20,
- KEYSCAN_SEQ_START_DELAY_US = 10000,
+ KEYSCAN_MAX_LENGTH = 20,
+ KEYSCAN_SEQ_START_DELAY_US = 10000,
};
static uint8_t keyscan_seq_count;
@@ -151,8 +151,8 @@ static int keyscan_seq_collect(struct ec_params_keyscan_seq_ctrl *req,
resp->collect.num_items = end - start;
for (i = start, ksi = keyscan_items; i < end; i++, ksi++)
- resp->collect.item[i].flags = ksi->done ?
- EC_KEYSCAN_SEQ_FLAG_DONE : 0;
+ resp->collect.item[i].flags =
+ ksi->done ? EC_KEYSCAN_SEQ_FLAG_DONE : 0;
return sizeof(*resp) + resp->collect.num_items;
}
@@ -186,7 +186,8 @@ static enum ec_status keyscan_seq_ctrl(struct host_cmd_handler_args *args)
keyscan_seq_start();
break;
case EC_KEYSCAN_SEQ_COLLECT:
- args->response_size = keyscan_seq_collect(&req,
+ args->response_size = keyscan_seq_collect(
+ &req,
(struct ec_result_keyscan_seq_ctrl *)args->response);
break;
default:
@@ -196,6 +197,4 @@ static enum ec_status keyscan_seq_ctrl(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_KEYSCAN_SEQ_CTRL,
- keyscan_seq_ctrl,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_KEYSCAN_SEQ_CTRL, keyscan_seq_ctrl, EC_VER_MASK(0));
diff --git a/common/keyboard_vivaldi.c b/common/keyboard_vivaldi.c
index 1cab203857..11f5b708e6 100644
--- a/common/keyboard_vivaldi.c
+++ b/common/keyboard_vivaldi.c
@@ -1,10 +1,11 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Vivali Keyboard code for Chrome EC */
+#include "builtin/assert.h"
#include "keyboard_8042_sharedlib.h"
#include "keyboard_scan.h"
#include "ec_commands.h"
@@ -15,7 +16,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_KEYBOARD, outstr)
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
/*
* Row Column info for Top row keys T1 - T15. This has been sourced from
@@ -25,21 +26,21 @@ __overridable const struct key {
uint8_t row;
uint8_t col;
} vivaldi_keys[] = {
- {.row = 0, .col = 2}, /* T1 */
- {.row = 3, .col = 2}, /* T2 */
- {.row = 2, .col = 2}, /* T3 */
- {.row = 1, .col = 2}, /* T4 */
- {.row = 3, .col = 4}, /* T5 */
- {.row = 2, .col = 4}, /* T6 */
- {.row = 1, .col = 4}, /* T7 */
- {.row = 2, .col = 9}, /* T8 */
- {.row = 1, .col = 9}, /* T9 */
- {.row = 0, .col = 4}, /* T10 */
- {.row = 0, .col = 1}, /* T11 */
- {.row = 1, .col = 5}, /* T12 */
- {.row = 3, .col = 5}, /* T13 */
- {.row = 0, .col = 9}, /* T14 */
- {.row = 0, .col = 11}, /* T15 */
+ { .row = 0, .col = 2 }, /* T1 */
+ { .row = 3, .col = 2 }, /* T2 */
+ { .row = 2, .col = 2 }, /* T3 */
+ { .row = 1, .col = 2 }, /* T4 */
+ { .row = 3, .col = 4 }, /* T5 */
+ { .row = 2, .col = 4 }, /* T6 */
+ { .row = 1, .col = 4 }, /* T7 */
+ { .row = 2, .col = 9 }, /* T8 */
+ { .row = 1, .col = 9 }, /* T9 */
+ { .row = 0, .col = 4 }, /* T10 */
+ { .row = 0, .col = 1 }, /* T11 */
+ { .row = 1, .col = 5 }, /* T12 */
+ { .row = 3, .col = 5 }, /* T13 */
+ { .row = 0, .col = 9 }, /* T14 */
+ { .row = 0, .col = 11 }, /* T15 */
};
BUILD_ASSERT(ARRAY_SIZE(vivaldi_keys) == MAX_TOP_ROW_KEYS);
@@ -69,8 +70,8 @@ static const uint16_t action_scancodes[] = {
static const struct ec_response_keybd_config *vivaldi_keybd;
-static enum
-ec_status get_vivaldi_keybd_config(struct host_cmd_handler_args *args)
+static enum ec_status
+get_vivaldi_keybd_config(struct host_cmd_handler_args *args)
{
struct ec_response_keybd_config *resp = args->response;
@@ -90,8 +91,8 @@ DECLARE_HOST_COMMAND(EC_CMD_GET_KEYBD_CONFIG, get_vivaldi_keybd_config,
* Boards selecting CONFIG_KEYBOARD_CUSTOMIZATION are likely to not
* want vivaldi code messing with their customized keyboards.
*/
-__overridable
-const struct ec_response_keybd_config *board_vivaldi_keybd_config(void)
+__overridable const struct ec_response_keybd_config *
+board_vivaldi_keybd_config(void)
{
return NULL;
}
@@ -117,8 +118,8 @@ static const struct ec_response_keybd_config default_keybd = {
.capabilities = KEYBD_CAP_SCRNLOCK_KEY,
};
-__overridable
-const struct ec_response_keybd_config *board_vivaldi_keybd_config(void)
+__overridable const struct ec_response_keybd_config *
+board_vivaldi_keybd_config(void)
{
return &default_keybd;
}
@@ -149,7 +150,6 @@ static void vivaldi_init(void)
}
for (i = 0; i < ARRAY_SIZE(vivaldi_keys); i++) {
-
uint8_t row, col, *mask;
enum action_key key;
@@ -157,8 +157,8 @@ static void vivaldi_init(void)
col = vivaldi_keys[i].col;
if (col >= KEYBOARD_COLS_MAX || row >= KEYBOARD_ROWS) {
- CPRINTS("VIVALDI: Bad (row,col) for T-%u: (%u,%u)",
- i, row, col);
+ CPRINTS("VIVALDI: Bad (row,col) for T-%u: (%u,%u)", i,
+ row, col);
ASSERT(false);
}
@@ -171,18 +171,16 @@ static void vivaldi_init(void)
key = vivaldi_keybd->action_keys[i];
if (i < vivaldi_keybd->num_top_row_keys && key != TK_ABSENT) {
-
/* Enable the mask */
*mask |= BIT(row);
/* Populate the scancode */
set_scancode_set2(row, col, action_scancodes[key]);
- CPRINTS("VIVALDI key-%u (r-%u, c-%u) = scancode-%X",
- i, row, col, action_scancodes[key]);
+ CPRINTS("VIVALDI key-%u (r-%u, c-%u) = scancode-%X", i,
+ row, col, action_scancodes[key]);
if (key == TK_VOL_UP)
set_vol_up_key(row, col);
-
}
}
}
diff --git a/common/lb_common.c b/common/lb_common.c
index 019e0e254f..eca21bfb03 100644
--- a/common/lb_common.c
+++ b/common/lb_common.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -97,12 +97,13 @@
#include "ec_commands.h"
#include "i2c.h"
#include "lb_common.h"
+#include "printf.h"
#include "util.h"
/* Console output macros */
#define CPUTS(outstr) cputs(CC_LIGHTBAR, outstr)
-#define CPRINTF(format, args...) cprintf(CC_LIGHTBAR, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_LIGHTBAR, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_LIGHTBAR, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_LIGHTBAR, format, ##args)
/******************************************************************************/
/* How to talk to the controller */
@@ -120,9 +121,8 @@ static inline void controller_write(int ctrl_num, uint8_t reg, uint8_t val)
buf[0] = reg;
buf[1] = val;
ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr_flags);
- i2c_xfer_unlocked(I2C_PORT_LIGHTBAR, i2c_addr_flags[ctrl_num],
- buf, 2, 0, 0,
- I2C_XFER_SINGLE);
+ i2c_xfer_unlocked(I2C_PORT_LIGHTBAR, i2c_addr_flags[ctrl_num], buf, 2,
+ 0, 0, I2C_XFER_SINGLE);
}
static inline uint8_t controller_read(int ctrl_num, uint8_t reg)
@@ -132,7 +132,7 @@ static inline uint8_t controller_read(int ctrl_num, uint8_t reg)
ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr_flags);
rv = i2c_xfer_unlocked(I2C_PORT_LIGHTBAR, i2c_addr_flags[ctrl_num],
- &reg, 1, buf, 1, I2C_XFER_SINGLE);
+ &reg, 1, buf, 1, I2C_XFER_SINGLE);
return rv ? 0 : buf[0];
}
@@ -149,15 +149,15 @@ static inline uint8_t controller_read(int ctrl_num, uint8_t reg)
* I've lowered the other colors until they all appear approximately equal
* brightness when full on. That's still pretty bright and a lot of current
* drain on the battery, so we'll probably rarely go that high. */
-#define MAX_RED 0x5c
+#define MAX_RED 0x5c
#define MAX_GREEN 0x30
-#define MAX_BLUE 0x67
+#define MAX_BLUE 0x67
#endif
#ifdef BOARD_HOST
/* For testing only */
-#define MAX_RED 0xff
+#define MAX_RED 0xff
#define MAX_GREEN 0xff
-#define MAX_BLUE 0xff
+#define MAX_BLUE 0xff
#endif
/* How we'd like to see the driver chips initialized. The controllers have some
@@ -169,20 +169,20 @@ struct initdata_s {
};
static const struct initdata_s init_vals[] = {
- {0x04, 0x00}, /* no backlight function */
- {0x05, 0x3f}, /* xRGBRGB per chip */
- {0x0f, 0x01}, /* square law looks better */
- {0x10, 0x3f}, /* enable independent LEDs */
- {0x11, 0x00}, /* no auto cycling */
- {0x12, 0x00}, /* no auto cycling */
- {0x13, 0x00}, /* instant fade in/out */
- {0x14, 0x00}, /* not using LED 7 */
- {0x15, 0x00}, /* current for LED 6 (blue) */
- {0x16, 0x00}, /* current for LED 5 (red) */
- {0x17, 0x00}, /* current for LED 4 (green) */
- {0x18, 0x00}, /* current for LED 3 (blue) */
- {0x19, 0x00}, /* current for LED 2 (red) */
- {0x1a, 0x00}, /* current for LED 1 (green) */
+ { 0x04, 0x00 }, /* no backlight function */
+ { 0x05, 0x3f }, /* xRGBRGB per chip */
+ { 0x0f, 0x01 }, /* square law looks better */
+ { 0x10, 0x3f }, /* enable independent LEDs */
+ { 0x11, 0x00 }, /* no auto cycling */
+ { 0x12, 0x00 }, /* no auto cycling */
+ { 0x13, 0x00 }, /* instant fade in/out */
+ { 0x14, 0x00 }, /* not using LED 7 */
+ { 0x15, 0x00 }, /* current for LED 6 (blue) */
+ { 0x16, 0x00 }, /* current for LED 5 (red) */
+ { 0x17, 0x00 }, /* current for LED 4 (green) */
+ { 0x18, 0x00 }, /* current for LED 3 (blue) */
+ { 0x19, 0x00 }, /* current for LED 2 (red) */
+ { 0x1a, 0x00 }, /* current for LED 1 (green) */
};
/* Controller register lookup tables. */
@@ -198,7 +198,7 @@ static const uint8_t led_to_isc[] = { 0x15, 0x18, 0x15, 0x18 };
/* Scale 0-255 into max value */
static inline uint8_t scale_abs(int val, int max)
{
- return (val * max)/255;
+ return (val * max) / 255;
}
/* This is the overall brightness control. */
@@ -211,7 +211,7 @@ static uint8_t current[NUM_LEDS][3];
/* Scale 0-255 by brightness */
static inline uint8_t scale(int val, int max)
{
- return scale_abs((val * brightness)/255, max);
+ return scale_abs((val * brightness) / 255, max);
}
/* Helper function to set one LED color and remember it for later */
@@ -225,8 +225,8 @@ static void setrgb(int led, int red, int green, int blue)
bank = led_to_isc[led];
i2c_lock(I2C_PORT_LIGHTBAR, 1);
controller_write(ctrl, bank, scale(blue, MAX_BLUE));
- controller_write(ctrl, bank+1, scale(red, MAX_RED));
- controller_write(ctrl, bank+2, scale(green, MAX_GREEN));
+ controller_write(ctrl, bank + 1, scale(red, MAX_RED));
+ controller_write(ctrl, bank + 2, scale(green, MAX_GREEN));
i2c_lock(I2C_PORT_LIGHTBAR, 0);
}
@@ -275,8 +275,10 @@ uint8_t lb_get_brightness(void)
void lb_init(int use_lock)
{
int i;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
- CPRINTF("[%pT LB_init_vals ", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s LB_init_vals ", ts_str);
for (i = 0; i < ARRAY_SIZE(init_vals); i++) {
CPRINTF("%c", '0' + i % 10);
if (use_lock)
@@ -310,12 +312,10 @@ void lb_on(void)
i2c_lock(I2C_PORT_LIGHTBAR, 0);
}
-static const uint8_t dump_reglist[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a
-};
+static const uint8_t dump_reglist[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
+ 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
+ 0x16, 0x17, 0x18, 0x19, 0x1a };
/* Helper for host command to dump controller registers */
void lb_hc_cmd_dump(struct ec_response_lightbar *out)
@@ -323,8 +323,7 @@ void lb_hc_cmd_dump(struct ec_response_lightbar *out)
int i;
uint8_t reg;
- BUILD_ASSERT(ARRAY_SIZE(dump_reglist) ==
- ARRAY_SIZE(out->dump.vals));
+ BUILD_ASSERT(ARRAY_SIZE(dump_reglist) == ARRAY_SIZE(out->dump.vals));
for (i = 0; i < ARRAY_SIZE(dump_reglist); i++) {
reg = dump_reglist[i];
diff --git a/common/led_common.c b/common/led_common.c
index e890ad71bb..2c73ba95e6 100644
--- a/common/led_common.c
+++ b/common/led_common.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -91,8 +91,8 @@ static enum ec_status led_command_control(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_LED_CONTROL, led_command_control, EC_VER_MASK(1));
-__attribute__((weak))
-void led_control(enum ec_led_id led_id, enum ec_led_state state)
+__attribute__((weak)) void led_control(enum ec_led_id led_id,
+ enum ec_led_state state)
{
/*
* Default weak implementation that does not affect the state of
diff --git a/common/led_onoff_states.c b/common/led_onoff_states.c
index 48886e5de3..244257cf1d 100644
--- a/common/led_onoff_states.c
+++ b/common/led_onoff_states.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -17,14 +17,14 @@
#include "system.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_GPIO, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_GPIO, format, ##args)
/*
* In order to support the battery LED being optional (ex. for Chromeboxes),
* set up default battery table, setter, and variables.
*/
-__overridable struct led_descriptor
- led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES];
+__overridable struct led_descriptor led_bat_state_table[LED_NUM_STATES]
+ [LED_NUM_PHASES];
__overridable const int led_charge_lvl_1;
__overridable const int led_charge_lvl_2;
__overridable void led_set_color_battery(enum ec_led_colors color)
@@ -43,7 +43,7 @@ static int led_get_charge_percent(void)
static enum led_states led_get_state(void)
{
- int charge_lvl;
+ int charge_lvl;
enum led_states new_state = LED_NUM_STATES;
if (!IS_ENABLED(CONFIG_CHARGER))
@@ -58,11 +58,10 @@ static enum led_states led_get_state(void)
new_state = STATE_CHARGING_LVL_1;
else if (charge_lvl < led_charge_lvl_2)
new_state = STATE_CHARGING_LVL_2;
+ else if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ new_state = STATE_CHARGING_FULL_S5;
else
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
- new_state = STATE_CHARGING_FULL_S5;
- else
- new_state = STATE_CHARGING_FULL_CHARGE;
+ new_state = STATE_CHARGING_FULL_CHARGE;
break;
case PWR_STATE_DISCHARGE_FULL:
if (extpower_is_present()) {
@@ -77,7 +76,7 @@ static enum led_states led_get_state(void)
if (chipset_in_state(CHIPSET_STATE_ON)) {
#ifdef CONFIG_LED_ONOFF_STATES_BAT_LOW
if (led_get_charge_percent() <
- CONFIG_LED_ONOFF_STATES_BAT_LOW)
+ CONFIG_LED_ONOFF_STATES_BAT_LOW)
new_state = STATE_DISCHARGE_S0_BAT_LOW;
else
#endif
@@ -97,13 +96,14 @@ static enum led_states led_get_state(void)
new_state = STATE_CHARGING_FULL_CHARGE;
break;
case PWR_STATE_IDLE: /* External power connected in IDLE */
- if (charge_get_flags() & CHARGE_FLAG_FORCE_IDLE)
- new_state = STATE_FACTORY_TEST;
- else if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
new_state = STATE_DISCHARGE_S5;
else
new_state = STATE_DISCHARGE_S0;
break;
+ case PWR_STATE_FORCED_IDLE:
+ new_state = STATE_FACTORY_TEST;
+ break;
default:
/* Other states don't alter LED behavior */
break;
@@ -147,14 +147,14 @@ static void led_update_battery(void)
ticks = 0;
period = led_bat_state_table[led_state][LED_PHASE_0].time +
- led_bat_state_table[led_state][LED_PHASE_1].time;
-
+ led_bat_state_table[led_state][LED_PHASE_1].time;
}
/* If this state is undefined, turn the LED off */
if (period == 0) {
CPRINTS("Undefined LED behavior for battery state %d,"
- "turning off LED", led_state);
+ "turning off LED",
+ led_state);
led_set_color_battery(LED_OFF);
return;
}
@@ -163,8 +163,8 @@ static void led_update_battery(void)
* Determine which phase of the state table to use. The phase is
* determined if it falls within first phase time duration.
*/
- phase = ticks < led_bat_state_table[led_state][LED_PHASE_0].time ?
- 0 : 1;
+ phase = ticks < led_bat_state_table[led_state][LED_PHASE_0].time ? 0 :
+ 1;
ticks = (ticks + 1) % period;
/* Set the color for the given state and phase */
@@ -176,7 +176,7 @@ static void led_update_battery(void)
* table and setter
*/
__overridable const struct led_descriptor
- led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES];
+ led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES];
__overridable void led_set_color_power(enum ec_led_colors color)
{
}
@@ -226,14 +226,14 @@ static void led_update_power(void)
ticks = 0;
period = led_pwr_state_table[led_state][LED_PHASE_0].time +
- led_pwr_state_table[led_state][LED_PHASE_1].time;
-
+ led_pwr_state_table[led_state][LED_PHASE_1].time;
}
/* If this state is undefined, turn the LED off */
if (period == 0) {
CPRINTS("Undefined LED behavior for power state %d,"
- "turning off LED", led_state);
+ "turning off LED",
+ led_state);
led_set_color_power(LED_OFF);
return;
}
@@ -242,13 +242,12 @@ static void led_update_power(void)
* Determine which phase of the state table to use. The phase is
* determined if it falls within first phase time duration.
*/
- phase = ticks < led_pwr_state_table[led_state][LED_PHASE_0].time ?
- 0 : 1;
+ phase = ticks < led_pwr_state_table[led_state][LED_PHASE_0].time ? 0 :
+ 1;
ticks = (ticks + 1) % period;
/* Set the color for the given state and phase */
led_set_color_power(led_pwr_state_table[led_state][phase].color);
-
}
static void led_init(void)
@@ -260,7 +259,6 @@ static void led_init(void)
/* If power LED is enabled, set it to "off" to start with */
if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
led_set_color_power(LED_OFF);
-
}
DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT);
diff --git a/common/led_policy_std.c b/common/led_policy_std.c
index 65bf8cedbd..fe8570df87 100644
--- a/common/led_policy_std.c
+++ b/common/led_policy_std.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -31,8 +31,8 @@
#define POWER_LED_OFF 0
#endif
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_BATTERY_LED, EC_LED_ID_POWER_LED};
+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);
@@ -42,7 +42,7 @@ enum led_color {
LED_AMBER,
LED_GREEN,
LED_WHITE,
- LED_COLOR_COUNT /* Number of colors, not a color itself */
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
};
static int bat_led_set_color(enum led_color color)
@@ -108,15 +108,18 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
case EC_LED_ID_BATTERY_LED:
gpio_set_level(GPIO_BAT_LED_RED,
(brightness[EC_LED_COLOR_RED] != 0) ?
- BAT_LED_ON : BAT_LED_OFF);
+ BAT_LED_ON :
+ BAT_LED_OFF);
gpio_set_level(GPIO_BAT_LED_GREEN,
(brightness[EC_LED_COLOR_GREEN] != 0) ?
- BAT_LED_ON : BAT_LED_OFF);
+ BAT_LED_ON :
+ BAT_LED_OFF);
break;
case EC_LED_ID_POWER_LED:
gpio_set_level(GPIO_POWER_LED,
(brightness[EC_LED_COLOR_WHITE] != 0) ?
- POWER_LED_ON : POWER_LED_OFF);
+ POWER_LED_ON :
+ POWER_LED_OFF);
break;
default:
return EC_ERROR_UNKNOWN;
@@ -149,7 +152,6 @@ static void std_led_set_power(void)
static void std_led_set_battery(void)
{
static int battery_second;
- uint32_t chflags = charge_get_flags();
battery_second++;
@@ -163,11 +165,11 @@ static void std_led_set_battery(void)
break;
case PWR_STATE_DISCHARGE:
if (charge_get_percent() < 3)
- bat_led_set_color((battery_second & 1)
- ? LED_OFF : LED_AMBER);
+ bat_led_set_color((battery_second & 1) ? LED_OFF :
+ LED_AMBER);
else if (charge_get_percent() < 10)
- bat_led_set_color((battery_second & 3)
- ? LED_OFF : LED_AMBER);
+ bat_led_set_color((battery_second & 3) ? LED_OFF :
+ LED_AMBER);
else
bat_led_set_color(LED_OFF);
break;
@@ -178,11 +180,11 @@ static void std_led_set_battery(void)
bat_led_set_color(LED_GREEN);
break;
case PWR_STATE_IDLE: /* External power connected in IDLE. */
- if (chflags & CHARGE_FLAG_FORCE_IDLE)
- bat_led_set_color(
- (battery_second & 0x2) ? LED_GREEN : LED_AMBER);
- else
- bat_led_set_color(LED_GREEN);
+ bat_led_set_color(LED_GREEN);
+ break;
+ case PWR_STATE_FORCED_IDLE:
+ bat_led_set_color((battery_second & 0x2) ? LED_GREEN :
+ LED_AMBER);
break;
default:
/* Other states don't alter LED behavior */
diff --git a/common/led_pwm.c b/common/led_pwm.c
index 05fe21e82b..c088ba0b40 100644
--- a/common/led_pwm.c
+++ b/common/led_pwm.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -262,10 +262,10 @@ static void update_leds(void)
}
DECLARE_HOOK(HOOK_TICK, update_leds, HOOK_PRIO_DEFAULT);
-#endif/* CONFIG_LED_PWM_TASK_DISABLED */
+#endif /* CONFIG_LED_PWM_TASK_DISABLED */
#ifdef CONFIG_CMD_LEDTEST
-static int command_ledtest(int argc, char **argv)
+static int command_ledtest(int argc, const char **argv)
{
int enable;
int pwm_led_id;
@@ -280,9 +280,8 @@ static int command_ledtest(int argc, char **argv)
led_id = supported_led_ids[pwm_led_id];
if (argc == 2) {
- ccprintf("PWM LED %d: led_id=%d, auto_control=%d\n",
- pwm_led_id, led_id,
- led_auto_control_is_enabled(led_id) != 0);
+ ccprintf("PWM LED %d: led_id=%d, auto_control=%d\n", pwm_led_id,
+ led_id, led_auto_control_is_enabled(led_id) != 0);
return EC_SUCCESS;
}
if (!parse_bool(argv[2], &enable))
diff --git a/common/lid_angle.c b/common/lid_angle.c
index 8a3775b959..86b6884058 100644
--- a/common/lid_angle.c
+++ b/common/lid_angle.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,7 +19,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_LIDANGLE, outstr)
-#define CPRINTS(format, args...) cprints(CC_LIDANGLE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_LIDANGLE, format, ##args)
/*
* Define the number of previous lid angle measurements to keep for determining
@@ -50,7 +50,7 @@ static int wake_large_angle = 180;
static const int wake_small_angle = 13;
/* Define hysteresis value to add stability to the flags. */
-#define LID_ANGLE_HYSTERESIS_DEG 2
+#define LID_ANGLE_HYSTERESIS_DEG 2
/* Define max and min values for wake_large_angle. */
#define LID_ANGLE_MIN_LARGE_ANGLE 0
@@ -74,8 +74,8 @@ static int lid_in_range_to_enable_peripherals(int ang)
else if (wake_large_angle == LID_ANGLE_MAX_LARGE_ANGLE)
return 1;
- return (ang >= (wake_small_angle + LID_ANGLE_HYSTERESIS_DEG)) &&
- (ang <= (wake_large_angle - LID_ANGLE_HYSTERESIS_DEG));
+ return (ang >= (wake_small_angle + LID_ANGLE_HYSTERESIS_DEG)) &&
+ (ang <= (wake_large_angle - LID_ANGLE_HYSTERESIS_DEG));
}
/**
@@ -96,11 +96,10 @@ static int lid_in_range_to_ignore_peripherals(int ang)
else if (wake_large_angle == LID_ANGLE_MAX_LARGE_ANGLE)
return 0;
- return (ang <= (wake_small_angle - LID_ANGLE_HYSTERESIS_DEG)) ||
- (ang >= (wake_large_angle + LID_ANGLE_HYSTERESIS_DEG));
+ return (ang <= (wake_small_angle - LID_ANGLE_HYSTERESIS_DEG)) ||
+ (ang >= (wake_large_angle + LID_ANGLE_HYSTERESIS_DEG));
}
-
int lid_angle_get_wake_angle(void)
{
return wake_large_angle;
@@ -125,7 +124,7 @@ void lid_angle_update(int lid_ang)
/* Record most recent lid angle in circular buffer. */
lidangle_buffer[index] = lid_ang;
- index = (index == LID_ANGLE_BUFFER_SIZE-1) ? 0 : index+1;
+ index = (index == LID_ANGLE_BUFFER_SIZE - 1) ? 0 : index + 1;
/*
* Manage whether or not peripherals are enabled based on lid angle
diff --git a/common/lid_switch.c b/common/lid_switch.c
index 050bbd9512..f0231b1ee7 100644
--- a/common/lid_switch.c
+++ b/common/lid_switch.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,15 +16,15 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SWITCH, outstr)
-#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ##args)
/* if no X-macro is defined for LID switch GPIO, use GPIO_LID_OPEN as default */
#ifndef CONFIG_LID_SWITCH_GPIO_LIST
#define CONFIG_LID_SWITCH_GPIO_LIST LID_GPIO(GPIO_LID_OPEN)
#endif
-static int debounced_lid_open; /* Debounced lid state */
-static int forced_lid_open; /* Forced lid open */
+static int debounced_lid_open; /* Debounced lid state */
+static int forced_lid_open; /* Forced lid open */
/**
* Get raw lid switch state.
@@ -87,7 +87,7 @@ static void lid_init(void)
if (raw_lid_open())
debounced_lid_open = 1;
- /* Enable interrupts, now that we've initialized */
+ /* Enable interrupts, now that we've initialized */
#define LID_GPIO(gpio) gpio_enable_interrupt(gpio);
CONFIG_LID_SWITCH_GPIO_LIST
#undef LID_GPIO
@@ -133,33 +133,27 @@ void enable_lid_detect(bool enable)
}
}
-static int command_lidopen(int argc, char **argv)
+static int command_lidopen(int argc, const char **argv)
{
lid_switch_open();
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(lidopen, command_lidopen,
- NULL,
- "Simulate lid open");
+DECLARE_CONSOLE_COMMAND(lidopen, command_lidopen, NULL, "Simulate lid open");
-static int command_lidclose(int argc, char **argv)
+static int command_lidclose(int argc, const char **argv)
{
lid_switch_close();
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(lidclose, command_lidclose,
- NULL,
- "Simulate lid close");
+DECLARE_CONSOLE_COMMAND(lidclose, command_lidclose, NULL, "Simulate lid close");
-static int command_lidstate(int argc, char **argv)
+static int command_lidstate(int argc, const char **argv)
{
ccprintf("lid state: %s\n", debounced_lid_open ? "open" : "closed");
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(lidstate, command_lidstate,
- NULL,
- "Get state of lid");
+DECLARE_CONSOLE_COMMAND(lidstate, command_lidstate, NULL, "Get state of lid");
/**
* Host command to enable/disable lid opened.
@@ -167,14 +161,15 @@ DECLARE_CONSOLE_COMMAND(lidstate, command_lidstate,
static enum ec_status hc_force_lid_open(struct host_cmd_handler_args *args)
{
const struct ec_params_force_lid_open *p = args->params;
+ int old_state = forced_lid_open;
/* Override lid open if necessary */
forced_lid_open = p->enabled ? 1 : 0;
/* Make this take effect immediately; no debounce time */
- hook_call_deferred(&lid_change_deferred_data, 0);
+ if (forced_lid_open != old_state)
+ hook_call_deferred(&lid_change_deferred_data, 0);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_FORCE_LID_OPEN, hc_force_lid_open,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_FORCE_LID_OPEN, hc_force_lid_open, EC_VER_MASK(0));
diff --git a/common/lightbar.c b/common/lightbar.c
index f80287941d..8a6a874b34 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 The Chromium OS Authors. All rights reserved.
+ * Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -33,11 +33,11 @@
* optional features in the current version should be marked with flags.
*/
#define LIGHTBAR_IMPLEMENTATION_VERSION 1
-#define LIGHTBAR_IMPLEMENTATION_FLAGS 0
+#define LIGHTBAR_IMPLEMENTATION_FLAGS 0
/* Console output macros */
#define CPUTS(outstr) cputs(CC_LIGHTBAR, outstr)
-#define CPRINTS(format, args...) cprints(CC_LIGHTBAR, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_LIGHTBAR, format, ##args)
#define FP_SCALE 10000
@@ -61,10 +61,10 @@ static struct p_state {
int battery_is_power_on_prevented;
/* Pattern variables for state S0. */
- uint16_t w0; /* primary phase */
- uint8_t ramp; /* ramp-in for S3->S0 */
+ uint16_t w0; /* primary phase */
+ uint8_t ramp; /* ramp-in for S3->S0 */
- uint8_t _pad0; /* next item is __packed */
+ uint8_t _pad0; /* next item is __packed */
/* Tweakable parameters. */
union {
@@ -162,7 +162,7 @@ static const struct lightbar_params_v1 default_params = {
},
};
-#define LB_SYSJUMP_TAG 0x4c42 /* "LB" */
+#define LB_SYSJUMP_TAG 0x4c42 /* "LB" */
static void lightbar_preserve_state(void)
{
system_add_jump_tag(LB_SYSJUMP_TAG, 0, sizeof(st), &st);
@@ -177,10 +177,8 @@ static void lightbar_restore_state(void)
old_state = system_get_jump_tag(LB_SYSJUMP_TAG, 0, &size);
if (old_state && size == sizeof(st)) {
memcpy(&st, old_state, size);
- CPRINTS("LB state restored: %d %d - %d %d/%d",
- st.cur_seq, st.prev_seq,
- st.battery_is_charging,
- st.battery_percent,
+ CPRINTS("LB state restored: %d %d - %d %d/%d", st.cur_seq,
+ st.prev_seq, st.battery_is_charging, st.battery_percent,
st.battery_level);
} else {
st.cur_seq = st.prev_seq = LIGHTBAR_S5;
@@ -234,7 +232,7 @@ test_export_static int lux_level_to_google_color(const int lux)
}
/* See if we need to decrease brightness */
- for (i = google_color_id; i < lb_brightness_levels_count ; i++)
+ for (i = google_color_id; i < lb_brightness_levels_count; i++)
if (lux >= lb_brightness_levels[i].lux_down)
break;
if (i > google_color_id) {
@@ -242,7 +240,7 @@ test_export_static int lux_level_to_google_color(const int lux)
return 1;
}
/* See if we need to increase brightness */
- for (i = google_color_id; i > 0; i--)
+ for (i = google_color_id; i > 0; i--)
if (lux < lb_brightness_levels[i - 1].lux_up)
break;
if (i < google_color_id) {
@@ -276,8 +274,8 @@ static int get_battery_level(void)
/* Use some hysteresis to avoid flickering */
if (bl < st.battery_level ||
- (bl > st.battery_level
- && pct >= (st.p.battery_threshold[st.battery_level] + 1))) {
+ (bl > st.battery_level &&
+ pct >= (st.p.battery_threshold[st.battery_level] + 1))) {
st.battery_level = bl;
change = 1;
}
@@ -294,7 +292,7 @@ static int get_battery_level(void)
*/
if (pwm_get_enabled(PWM_CH_KBLIGHT)) {
pct = pwm_get_duty(PWM_CH_KBLIGHT);
- pct = (255 * pct) / 100; /* 00 - FF */
+ pct = (255 * pct) / 100; /* 00 - FF */
if (pct > st.p.bright_bl_on_max[st.battery_is_charging])
pct = st.p.bright_bl_on_max[st.battery_is_charging];
else if (pct < st.p.bright_bl_on_min[st.battery_is_charging])
@@ -350,8 +348,7 @@ void demo_is_charging(int ischarge)
return;
st.battery_is_charging = ischarge;
- CPRINTS("LB demo: battery_is_charging=%d",
- st.battery_is_charging);
+ CPRINTS("LB demo: battery_is_charging=%d", st.battery_is_charging);
}
/* Bright/Dim keys */
@@ -409,7 +406,7 @@ static inline int cycle_010(uint8_t i)
index = i & 0x3;
return _ramp_table[bucket] +
- ((_ramp_table[bucket + 1] - _ramp_table[bucket]) * index >> 2);
+ ((_ramp_table[bucket + 1] - _ramp_table[bucket]) * index >> 2);
}
/******************************************************************************/
@@ -421,12 +418,12 @@ static uint32_t pending_msg;
#define PENDING_MSG TASK_EVENT_CUSTOM_BIT(0)
/* Interruptible delay. */
-#define WAIT_OR_RET(A) \
- do { \
- uint32_t msg = task_wait_event(A); \
- uint32_t p_msg = pending_msg; \
- if (msg & PENDING_MSG && p_msg != st.cur_seq) \
- return p_msg; \
+#define WAIT_OR_RET(A) \
+ do { \
+ uint32_t msg = task_wait_event(A); \
+ uint32_t p_msg = pending_msg; \
+ if (msg & PENDING_MSG && p_msg != st.cur_seq) \
+ return p_msg; \
} while (0)
/******************************************************************************/
@@ -501,7 +498,7 @@ static uint32_t sequence_S3S0(void)
}
/* Initial conditions */
- st.w0 = -256; /* start cycle_npn() quietly */
+ st.w0 = -256; /* start cycle_npn() quietly */
st.ramp = 0;
/* Ready for S0 */
@@ -583,7 +580,7 @@ static uint32_t sequence_S0(void)
return 0;
}
-#else /* just simple google colors */
+#else /* just simple google colors */
static uint32_t sequence_S0(void)
{
@@ -711,7 +708,6 @@ static uint32_t sequence_S3(void)
return 0;
}
-
/* CPU is powering up. We generally boot fast enough that we don't have time
* to do anything interesting in the S3 state, but go straight on to S0. */
static uint32_t sequence_S5S3(void)
@@ -817,12 +813,10 @@ static uint32_t sequence_STOP(void)
do {
msg = task_wait_event(-1);
CPRINTS("LB %s() got pending_msg %d", __func__, pending_msg);
- } while (msg != PENDING_MSG || (
- pending_msg != LIGHTBAR_RUN &&
- pending_msg != LIGHTBAR_S0S3 &&
- pending_msg != LIGHTBAR_S3 &&
- pending_msg != LIGHTBAR_S3S5 &&
- pending_msg != LIGHTBAR_S5));
+ } while (msg != PENDING_MSG ||
+ (pending_msg != LIGHTBAR_RUN && pending_msg != LIGHTBAR_S0S3 &&
+ pending_msg != LIGHTBAR_S3 && pending_msg != LIGHTBAR_S3S5 &&
+ pending_msg != LIGHTBAR_S5));
return 0;
}
@@ -856,73 +850,47 @@ static const struct {
unsigned int delay;
} konami[] = {
- {1, 0xff, 0xff, 0x00, 0},
- {2, 0xff, 0xff, 0x00, 100000},
- {1, 0x00, 0x00, 0x00, 0},
- {2, 0x00, 0x00, 0x00, 100000},
-
- {1, 0xff, 0xff, 0x00, 0},
- {2, 0xff, 0xff, 0x00, 100000},
- {1, 0x00, 0x00, 0x00, 0},
- {2, 0x00, 0x00, 0x00, 100000},
-
- {0, 0x00, 0x00, 0xff, 0},
- {3, 0x00, 0x00, 0xff, 100000},
- {0, 0x00, 0x00, 0x00, 0},
- {3, 0x00, 0x00, 0x00, 100000},
-
- {0, 0x00, 0x00, 0xff, 0},
- {3, 0x00, 0x00, 0xff, 100000},
- {0, 0x00, 0x00, 0x00, 0},
- {3, 0x00, 0x00, 0x00, 100000},
-
- {0, 0xff, 0x00, 0x00, 0},
- {1, 0xff, 0x00, 0x00, 100000},
- {0, 0x00, 0x00, 0x00, 0},
- {1, 0x00, 0x00, 0x00, 100000},
-
- {2, 0x00, 0xff, 0x00, 0},
- {3, 0x00, 0xff, 0x00, 100000},
- {2, 0x00, 0x00, 0x00, 0},
- {3, 0x00, 0x00, 0x00, 100000},
-
- {0, 0xff, 0x00, 0x00, 0},
- {1, 0xff, 0x00, 0x00, 100000},
- {0, 0x00, 0x00, 0x00, 0},
- {1, 0x00, 0x00, 0x00, 100000},
-
- {2, 0x00, 0xff, 0x00, 0},
- {3, 0x00, 0xff, 0x00, 100000},
- {2, 0x00, 0x00, 0x00, 0},
- {3, 0x00, 0x00, 0x00, 100000},
-
- {0, 0x00, 0xff, 0xff, 0},
- {2, 0x00, 0xff, 0xff, 100000},
- {0, 0x00, 0x00, 0x00, 0},
- {2, 0x00, 0x00, 0x00, 150000},
-
- {1, 0xff, 0x00, 0xff, 0},
- {3, 0xff, 0x00, 0xff, 100000},
- {1, 0x00, 0x00, 0x00, 0},
- {3, 0x00, 0x00, 0x00, 250000},
-
- {4, 0xff, 0xff, 0xff, 100000},
- {4, 0x00, 0x00, 0x00, 100000},
-
- {4, 0xff, 0xff, 0xff, 100000},
- {4, 0x00, 0x00, 0x00, 100000},
-
- {4, 0xff, 0xff, 0xff, 100000},
- {4, 0x00, 0x00, 0x00, 100000},
-
- {4, 0xff, 0xff, 0xff, 100000},
- {4, 0x00, 0x00, 0x00, 100000},
-
- {4, 0xff, 0xff, 0xff, 100000},
- {4, 0x00, 0x00, 0x00, 100000},
-
- {4, 0xff, 0xff, 0xff, 100000},
- {4, 0x00, 0x00, 0x00, 100000},
+ { 1, 0xff, 0xff, 0x00, 0 }, { 2, 0xff, 0xff, 0x00, 100000 },
+ { 1, 0x00, 0x00, 0x00, 0 }, { 2, 0x00, 0x00, 0x00, 100000 },
+
+ { 1, 0xff, 0xff, 0x00, 0 }, { 2, 0xff, 0xff, 0x00, 100000 },
+ { 1, 0x00, 0x00, 0x00, 0 }, { 2, 0x00, 0x00, 0x00, 100000 },
+
+ { 0, 0x00, 0x00, 0xff, 0 }, { 3, 0x00, 0x00, 0xff, 100000 },
+ { 0, 0x00, 0x00, 0x00, 0 }, { 3, 0x00, 0x00, 0x00, 100000 },
+
+ { 0, 0x00, 0x00, 0xff, 0 }, { 3, 0x00, 0x00, 0xff, 100000 },
+ { 0, 0x00, 0x00, 0x00, 0 }, { 3, 0x00, 0x00, 0x00, 100000 },
+
+ { 0, 0xff, 0x00, 0x00, 0 }, { 1, 0xff, 0x00, 0x00, 100000 },
+ { 0, 0x00, 0x00, 0x00, 0 }, { 1, 0x00, 0x00, 0x00, 100000 },
+
+ { 2, 0x00, 0xff, 0x00, 0 }, { 3, 0x00, 0xff, 0x00, 100000 },
+ { 2, 0x00, 0x00, 0x00, 0 }, { 3, 0x00, 0x00, 0x00, 100000 },
+
+ { 0, 0xff, 0x00, 0x00, 0 }, { 1, 0xff, 0x00, 0x00, 100000 },
+ { 0, 0x00, 0x00, 0x00, 0 }, { 1, 0x00, 0x00, 0x00, 100000 },
+
+ { 2, 0x00, 0xff, 0x00, 0 }, { 3, 0x00, 0xff, 0x00, 100000 },
+ { 2, 0x00, 0x00, 0x00, 0 }, { 3, 0x00, 0x00, 0x00, 100000 },
+
+ { 0, 0x00, 0xff, 0xff, 0 }, { 2, 0x00, 0xff, 0xff, 100000 },
+ { 0, 0x00, 0x00, 0x00, 0 }, { 2, 0x00, 0x00, 0x00, 150000 },
+
+ { 1, 0xff, 0x00, 0xff, 0 }, { 3, 0xff, 0x00, 0xff, 100000 },
+ { 1, 0x00, 0x00, 0x00, 0 }, { 3, 0x00, 0x00, 0x00, 250000 },
+
+ { 4, 0xff, 0xff, 0xff, 100000 }, { 4, 0x00, 0x00, 0x00, 100000 },
+
+ { 4, 0xff, 0xff, 0xff, 100000 }, { 4, 0x00, 0x00, 0x00, 100000 },
+
+ { 4, 0xff, 0xff, 0xff, 100000 }, { 4, 0x00, 0x00, 0x00, 100000 },
+
+ { 4, 0xff, 0xff, 0xff, 100000 }, { 4, 0x00, 0x00, 0x00, 100000 },
+
+ { 4, 0xff, 0xff, 0xff, 100000 }, { 4, 0x00, 0x00, 0x00, 100000 },
+
+ { 4, 0xff, 0xff, 0xff, 100000 }, { 4, 0x00, 0x00, 0x00, 100000 },
};
static uint32_t sequence_KONAMI_inner(void)
@@ -930,8 +898,8 @@ static uint32_t sequence_KONAMI_inner(void)
int i;
for (i = 0; i < ARRAY_SIZE(konami); i++) {
- lb_set_rgb(konami[i].led,
- konami[i].r, konami[i].g, konami[i].b);
+ lb_set_rgb(konami[i].led, konami[i].r, konami[i].g,
+ konami[i].b);
if (konami[i].delay)
WAIT_OR_RET(konami[i].delay);
}
@@ -961,7 +929,7 @@ static int range(int val, int min, int ofs)
{
if (val <= min)
return 0;
- if (val >= min+ofs)
+ if (val >= min + ofs)
return FP_SCALE;
return (val - min) * FP_SCALE / ofs;
}
@@ -977,7 +945,7 @@ static uint32_t sequence_TAP_inner(int dir)
uint32_t elapsed_time = 0;
int i, l, ci, max_led;
int f_osc, f_mult;
- int gi, gr, gate[NUM_LEDS] = {0, 0, 0, 0};
+ int gi, gr, gate[NUM_LEDS] = { 0, 0, 0, 0 };
uint8_t w = 0;
#ifdef CONFIG_LIGHTBAR_TAP_DIM_LAST_SEGMENT
int f_min, f_delta, f_power;
@@ -1010,7 +978,6 @@ static uint32_t sequence_TAP_inner(int dir)
gate[gi - 1] = FP_SCALE;
for (i = 0; i < NUM_LEDS; i++) {
-
#ifdef CONFIG_LIGHTBAR_TAP_DIM_LAST_SEGMENT
if (max_led > i) {
f_mult = FP_SCALE;
@@ -1019,7 +986,8 @@ static uint32_t sequence_TAP_inner(int dir)
} else {
switch (base_color) {
case RED:
- f_power = range(st.battery_percent, 0,
+ f_power = range(
+ st.battery_percent, 0,
st.p.battery_threshold[0] - 1);
break;
case YELLOW:
@@ -1174,9 +1142,9 @@ static inline uint32_t decode_32(uint32_t *dest)
CPRINTS("pc 0x%02x near or out of bounds", pc);
return EC_RES_INVALID_PARAM;
}
- *dest = cur_prog.data[pc++] << 24;
+ *dest = cur_prog.data[pc++] << 24;
*dest |= cur_prog.data[pc++] << 16;
- *dest |= cur_prog.data[pc++] << 8;
+ *dest |= cur_prog.data[pc++] << 8;
*dest |= cur_prog.data[pc++];
return EC_SUCCESS;
}
@@ -1307,7 +1275,6 @@ static uint32_t lightbyte_SET_BRIGHTNESS(void)
*/
static uint32_t lightbyte_SET_COLOR_SINGLE(void)
{
-
uint8_t packed_loc, led, control, color, value;
int i;
if (decode_8(&packed_loc) != EC_SUCCESS)
@@ -1369,8 +1336,8 @@ static uint32_t lightbyte_GET_COLORS(void)
int i;
for (i = 0; i < NUM_LEDS; i++)
lb_get_rgb(i, &led_desc[i][LB_CONT_COLOR0][LB_COL_RED],
- &led_desc[i][LB_CONT_COLOR0][LB_COL_GREEN],
- &led_desc[i][LB_CONT_COLOR0][LB_COL_BLUE]);
+ &led_desc[i][LB_CONT_COLOR0][LB_COL_GREEN],
+ &led_desc[i][LB_CONT_COLOR0][LB_COL_BLUE]);
return EC_SUCCESS;
}
@@ -1481,15 +1448,21 @@ static uint32_t lightbyte_CYCLE(void)
for (w = 0;; w++) {
for (i = 0; i < NUM_LEDS; i++) {
- r = get_interp_value(i, LB_COL_RED,
- cycle_010((w & 0xff) +
- led_desc[i][LB_CONT_PHASE][LB_COL_RED]));
- g = get_interp_value(i, LB_COL_GREEN,
+ r = get_interp_value(
+ i, LB_COL_RED,
+ cycle_010(
+ (w & 0xff) +
+ led_desc[i][LB_CONT_PHASE][LB_COL_RED]));
+ g = get_interp_value(
+ i, LB_COL_GREEN,
cycle_010((w & 0xff) +
- led_desc[i][LB_CONT_PHASE][LB_COL_GREEN]));
- b = get_interp_value(i, LB_COL_BLUE,
+ led_desc[i][LB_CONT_PHASE]
+ [LB_COL_GREEN]));
+ b = get_interp_value(
+ i, LB_COL_BLUE,
cycle_010((w & 0xff) +
- led_desc[i][LB_CONT_PHASE][LB_COL_BLUE]));
+ led_desc[i][LB_CONT_PHASE]
+ [LB_COL_BLUE]));
lb_set_rgb(i, r, g, b);
}
WAIT_OR_RET(lb_ramp_delay);
@@ -1509,24 +1482,17 @@ static uint32_t lightbyte_HALT(void)
#define OP(NAME, BYTES, MNEMONIC) NAME,
#include "lightbar_opcode_list.h"
-enum lightbyte_opcode {
- LIGHTBAR_OPCODE_TABLE
- MAX_OPCODE
-};
+enum lightbyte_opcode { LIGHTBAR_OPCODE_TABLE MAX_OPCODE };
#undef OP
-#define OP(NAME, BYTES, MNEMONIC) lightbyte_ ## NAME,
+#define OP(NAME, BYTES, MNEMONIC) lightbyte_##NAME,
#include "lightbar_opcode_list.h"
-static uint32_t (*lightbyte_dispatch[])(void) = {
- LIGHTBAR_OPCODE_TABLE
-};
+static uint32_t (*lightbyte_dispatch[])(void) = { LIGHTBAR_OPCODE_TABLE };
#undef OP
#define OP(NAME, BYTES, MNEMONIC) MNEMONIC,
#include "lightbar_opcode_list.h"
-static const char * const lightbyte_names[] = {
- LIGHTBAR_OPCODE_TABLE
-};
+static const char *const lightbyte_names[] = { LIGHTBAR_OPCODE_TABLE };
#undef OP
static uint32_t sequence_PROGRAM(void)
@@ -1563,7 +1529,7 @@ static uint32_t sequence_PROGRAM(void)
return EC_RES_INVALID_PARAM;
} else {
CPRINTS("LB PROGRAM pc: 0x%02x, opcode 0x%02x -> %s",
- old_pc, next_inst, lightbyte_names[next_inst]);
+ old_pc, next_inst, lightbyte_names[next_inst]);
rc = lightbyte_dispatch[next_inst]();
if (rc) {
lb_set_brightness(saved_brightness);
@@ -1588,15 +1554,16 @@ static inline int is_normal_sequence(enum lightbar_sequence seq)
/* Link each sequence with a command to invoke it. */
struct lightbar_cmd_t {
- const char * const string;
+ const char *const string;
uint32_t (*sequence)(void);
};
-#define LBMSG(state) { #state, sequence_##state }
+#define LBMSG(state) \
+ { \
+#state, sequence_##state \
+ }
#include "lightbar_msg_list.h"
-static struct lightbar_cmd_t lightbar_cmds[] = {
- LIGHTBAR_MSG_LIST
-};
+static struct lightbar_cmd_t lightbar_cmds[] = { LIGHTBAR_MSG_LIST };
#undef LBMSG
void lightbar_task(void)
@@ -1608,9 +1575,9 @@ void lightbar_task(void)
lightbar_restore_state();
while (1) {
- CPRINTS("LB running cur_seq %d %s. prev_seq %d %s",
- st.cur_seq, lightbar_cmds[st.cur_seq].string,
- st.prev_seq, lightbar_cmds[st.prev_seq].string);
+ CPRINTS("LB running cur_seq %d %s. prev_seq %d %s", st.cur_seq,
+ lightbar_cmds[st.cur_seq].string, st.prev_seq,
+ lightbar_cmds[st.prev_seq].string);
next_seq = lightbar_cmds[st.cur_seq].sequence();
if (next_seq) {
CPRINTS("LB cur_seq %d %s returned pending msg %d %s",
@@ -1622,8 +1589,8 @@ void lightbar_task(void)
st.cur_seq = next_seq;
}
} else {
- CPRINTS("LB cur_seq %d %s returned value 0",
- st.cur_seq, lightbar_cmds[st.cur_seq].string);
+ CPRINTS("LB cur_seq %d %s returned value 0", st.cur_seq,
+ lightbar_cmds[st.cur_seq].string);
switch (st.cur_seq) {
case LIGHTBAR_S5S3:
st.cur_seq = LIGHTBAR_S3;
@@ -1733,16 +1700,12 @@ static enum ec_status lpc_cmd_lightbar(struct host_cmd_handler_args *args)
lb_hc_cmd_reg(in);
break;
case LIGHTBAR_CMD_SET_RGB:
- lb_set_rgb(in->set_rgb.led,
- in->set_rgb.red,
- in->set_rgb.green,
+ lb_set_rgb(in->set_rgb.led, in->set_rgb.red, in->set_rgb.green,
in->set_rgb.blue);
break;
case LIGHTBAR_CMD_GET_RGB:
- rv = lb_get_rgb(in->get_rgb.led,
- &out->get_rgb.red,
- &out->get_rgb.green,
- &out->get_rgb.blue);
+ rv = lb_get_rgb(in->get_rgb.led, &out->get_rgb.red,
+ &out->get_rgb.green, &out->get_rgb.blue);
if (rv == EC_RES_SUCCESS)
args->response_size = sizeof(out->get_rgb);
return rv;
@@ -1777,8 +1740,7 @@ static enum ec_status lpc_cmd_lightbar(struct host_cmd_handler_args *args)
break;
case LIGHTBAR_CMD_SET_PROGRAM:
CPRINTS("LB_set_program");
- memcpy(&next_prog,
- &in->set_program,
+ memcpy(&next_prog, &in->set_program,
sizeof(struct lightbar_program));
break;
case LIGHTBAR_CMD_VERSION:
@@ -1801,28 +1763,24 @@ static enum ec_status lpc_cmd_lightbar(struct host_cmd_handler_args *args)
break;
case LIGHTBAR_CMD_GET_PARAMS_V2_TIMING:
CPRINTS("LB_get_params_v2_timing");
- memcpy(&out->get_params_v2_timing,
- &st.p_v2.timing,
+ memcpy(&out->get_params_v2_timing, &st.p_v2.timing,
sizeof(st.p_v2.timing));
args->response_size = sizeof(out->get_params_v2_timing);
break;
case LIGHTBAR_CMD_SET_PARAMS_V2_TIMING:
CPRINTS("LB_set_params_v2_timing");
- memcpy(&st.p_v2.timing,
- &in->set_v2par_timing,
+ memcpy(&st.p_v2.timing, &in->set_v2par_timing,
sizeof(struct lightbar_params_v2_timing));
break;
case LIGHTBAR_CMD_GET_PARAMS_V2_TAP:
CPRINTS("LB_get_params_v2_tap");
- memcpy(&out->get_params_v2_tap,
- &st.p_v2.tap,
+ memcpy(&out->get_params_v2_tap, &st.p_v2.tap,
sizeof(struct lightbar_params_v2_tap));
args->response_size = sizeof(out->get_params_v2_tap);
break;
case LIGHTBAR_CMD_SET_PARAMS_V2_TAP:
CPRINTS("LB_set_params_v2_tap");
- memcpy(&st.p_v2.tap,
- &in->set_v2par_tap,
+ memcpy(&st.p_v2.tap, &in->set_v2par_tap,
sizeof(struct lightbar_params_v2_tap));
break;
case LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION:
@@ -1833,47 +1791,40 @@ static enum ec_status lpc_cmd_lightbar(struct host_cmd_handler_args *args)
break;
case LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION:
CPRINTS("LB_set_params_v2_oscillation");
- memcpy(&st.p_v2.osc,
- &in->set_v2par_osc,
+ memcpy(&st.p_v2.osc, &in->set_v2par_osc,
sizeof(struct lightbar_params_v2_oscillation));
break;
case LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS:
CPRINTS("LB_get_params_v2_brightness");
- memcpy(&out->get_params_v2_bright,
- &st.p_v2.bright,
+ memcpy(&out->get_params_v2_bright, &st.p_v2.bright,
sizeof(struct lightbar_params_v2_brightness));
args->response_size = sizeof(out->get_params_v2_bright);
break;
case LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS:
CPRINTS("LB_set_params_v2_brightness");
- memcpy(&st.p_v2.bright,
- &in->set_v2par_bright,
+ memcpy(&st.p_v2.bright, &in->set_v2par_bright,
sizeof(struct lightbar_params_v2_brightness));
break;
case LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS:
CPRINTS("LB_get_params_v2_thlds");
- memcpy(&out->get_params_v2_thlds,
- &st.p_v2.thlds,
+ memcpy(&out->get_params_v2_thlds, &st.p_v2.thlds,
sizeof(struct lightbar_params_v2_thresholds));
args->response_size = sizeof(out->get_params_v2_thlds);
break;
case LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS:
CPRINTS("LB_set_params_v2_thlds");
- memcpy(&st.p_v2.thlds,
- &in->set_v2par_thlds,
+ memcpy(&st.p_v2.thlds, &in->set_v2par_thlds,
sizeof(struct lightbar_params_v2_thresholds));
break;
case LIGHTBAR_CMD_GET_PARAMS_V2_COLORS:
CPRINTS("LB_get_params_v2_colors");
- memcpy(&out->get_params_v2_colors,
- &st.p_v2.colors,
+ memcpy(&out->get_params_v2_colors, &st.p_v2.colors,
sizeof(struct lightbar_params_v2_colors));
args->response_size = sizeof(out->get_params_v2_colors);
break;
case LIGHTBAR_CMD_SET_PARAMS_V2_COLORS:
CPRINTS("LB_set_params_v2_colors");
- memcpy(&st.p_v2.colors,
- &in->set_v2par_colors,
+ memcpy(&st.p_v2.colors, &in->set_v2par_colors,
sizeof(struct lightbar_params_v2_colors));
break;
default:
@@ -1884,9 +1835,7 @@ static enum ec_status lpc_cmd_lightbar(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_LIGHTBAR_CMD,
- lpc_cmd_lightbar,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_LIGHTBAR_CMD, lpc_cmd_lightbar, EC_VER_MASK(0));
/****************************************************************************/
/* EC console commands */
@@ -1902,10 +1851,12 @@ static int help(const char *cmd)
ccprintf(" %s init - load default vals\n", cmd);
ccprintf(" %s brightness [NUM] - set intensity (0-ff)\n", cmd);
ccprintf(" %s seq [NUM|SEQUENCE] - run given pattern"
- " (no arg for list)\n", cmd);
+ " (no arg for list)\n",
+ cmd);
ccprintf(" %s CTRL REG VAL - set LED controller regs\n", cmd);
ccprintf(" %s LED RED GREEN BLUE - set color manually"
- " (LED=%d for all)\n", cmd, NUM_LEDS);
+ " (LED=%d for all)\n",
+ cmd, NUM_LEDS);
ccprintf(" %s LED - get current LED color\n", cmd);
ccprintf(" %s demo [0|1] - turn demo mode on & off\n", cmd);
#ifdef LIGHTBAR_SIMULATION
@@ -1936,19 +1887,18 @@ static void show_msg_names(void)
lightbar_cmds[st.cur_seq].string);
}
-static int command_lightbar(int argc, char **argv)
+static int command_lightbar(int argc, const char **argv)
{
int i;
uint8_t num, led, r = 0, g = 0, b = 0;
struct ec_response_lightbar out;
char *e;
- if (argc == 1) { /* no args = dump 'em all */
+ if (argc == 1) { /* no args = dump 'em all */
lb_hc_cmd_dump(&out);
for (i = 0; i < ARRAY_SIZE(out.dump.vals); i++)
ccprintf(" %02x %02x %02x\n",
- out.dump.vals[i].reg,
- out.dump.vals[i].ic0,
+ out.dump.vals[i].reg, out.dump.vals[i].ic0,
out.dump.vals[i].ic1);
return EC_SUCCESS;
@@ -1987,8 +1937,7 @@ static int command_lightbar(int argc, char **argv)
if (!strcasecmp(argv[1], "demo")) {
if (argc > 2) {
- if (!strcasecmp(argv[2], "on") ||
- argv[2][0] == '1')
+ if (!strcasecmp(argv[2], "on") || argv[2][0] == '1')
demo_mode = 1;
else if (!strcasecmp(argv[2], "off") ||
argv[2][0] == '0')
@@ -2010,7 +1959,7 @@ static int command_lightbar(int argc, char **argv)
num = find_msg_by_name(argv[2]);
if (num >= LIGHTBAR_NUM_SEQUENCES)
return EC_ERROR_PARAM2;
- if (argc > 3) /* for testing TAP direction */
+ if (argc > 3) /* for testing TAP direction */
force_dir = strtoi(argv[3], 0, 0);
lightbar_sequence(num);
return EC_SUCCESS;
@@ -2056,13 +2005,11 @@ static int command_lightbar(int argc, char **argv)
return EC_SUCCESS;
}
-
#ifdef CONFIG_CONSOLE_CMDHELP
help(argv[0]);
#endif
return EC_ERROR_INVAL;
}
-DECLARE_CONSOLE_COMMAND(lightbar, command_lightbar,
- "[help | COMMAND [ARGS]]",
+DECLARE_CONSOLE_COMMAND(lightbar, command_lightbar, "[help | COMMAND [ARGS]]",
"Get/set lightbar state");
diff --git a/common/mag_cal.c b/common/mag_cal.c
index 13beb93af2..a9ce95798c 100644
--- a/common/mag_cal.c
+++ b/common/mag_cal.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,17 +14,17 @@
#include "util.h"
/* Data from sensor is in 16th of uT, 0.0625 uT/LSB */
-#define MAG_CAL_RAW_UT 16
+#define MAG_CAL_RAW_UT 16
-#define MAX_EIGEN_RATIO FLOAT_TO_FP(25.0f)
-#define MAX_EIGEN_MAG FLOAT_TO_FP(80.0f * MAG_CAL_RAW_UT)
-#define MIN_EIGEN_MAG FLOAT_TO_FP(10.0f * MAG_CAL_RAW_UT)
+#define MAX_EIGEN_RATIO FLOAT_TO_FP(25.0f)
+#define MAX_EIGEN_MAG FLOAT_TO_FP(80.0f * MAG_CAL_RAW_UT)
+#define MIN_EIGEN_MAG FLOAT_TO_FP(10.0f * MAG_CAL_RAW_UT)
-#define MAX_FIT_MAG MAX_EIGEN_MAG
-#define MIN_FIT_MAG MIN_EIGEN_MAG
+#define MAX_FIT_MAG MAX_EIGEN_MAG
+#define MIN_FIT_MAG MIN_EIGEN_MAG
-#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
-#define PRINTF_FLOAT(x) ((int)((x) * 100.0f))
+#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ##args)
+#define PRINTF_FLOAT(x) ((int)((x)*100.0f))
/**
* Compute the covariance element: (avg(ab) - avg(a)*avg(b))
@@ -51,34 +51,25 @@ static int moc_eigen_test(struct mag_cal_t *moc)
mat33_fp_t eigenvecs;
fp_t evmax, evmin, evmag;
fp_t inv = fp_div_dbz(FLOAT_TO_FP(1.0f),
- INT_TO_FP((int) moc->kasa_fit.nsamples));
+ INT_TO_FP((int)moc->kasa_fit.nsamples));
int eigen_pass;
/* covariance matrix */
- S[0][0] = covariance_element(moc->kasa_fit.acc_xx,
- moc->kasa_fit.acc_x,
- moc->kasa_fit.acc_x,
- inv);
+ S[0][0] = covariance_element(moc->kasa_fit.acc_xx, moc->kasa_fit.acc_x,
+ moc->kasa_fit.acc_x, inv);
S[0][1] = S[1][0] = covariance_element(moc->kasa_fit.acc_xy,
moc->kasa_fit.acc_x,
- moc->kasa_fit.acc_y,
- inv);
+ moc->kasa_fit.acc_y, inv);
S[0][2] = S[2][0] = covariance_element(moc->kasa_fit.acc_xz,
moc->kasa_fit.acc_x,
- moc->kasa_fit.acc_z,
- inv);
- S[1][1] = covariance_element(moc->kasa_fit.acc_yy,
- moc->kasa_fit.acc_y,
- moc->kasa_fit.acc_y,
- inv);
+ moc->kasa_fit.acc_z, inv);
+ S[1][1] = covariance_element(moc->kasa_fit.acc_yy, moc->kasa_fit.acc_y,
+ moc->kasa_fit.acc_y, inv);
S[1][2] = S[2][1] = covariance_element(moc->kasa_fit.acc_yz,
moc->kasa_fit.acc_y,
- moc->kasa_fit.acc_z,
- inv);
- S[2][2] = covariance_element(moc->kasa_fit.acc_zz,
- moc->kasa_fit.acc_z,
- moc->kasa_fit.acc_z,
- inv);
+ moc->kasa_fit.acc_z, inv);
+ S[2][2] = covariance_element(moc->kasa_fit.acc_zz, moc->kasa_fit.acc_z,
+ moc->kasa_fit.acc_z, inv);
mat33_fp_get_eigenbasis(S, eigenvals, eigenvecs);
@@ -90,9 +81,8 @@ static int moc_eigen_test(struct mag_cal_t *moc)
evmag = fp_sqrtf(eigenvals[X] + eigenvals[Y] + eigenvals[Z]);
- eigen_pass = (fp_mul(evmin, MAX_EIGEN_RATIO) > evmax)
- && (evmag > MIN_EIGEN_MAG)
- && (evmag < MAX_EIGEN_MAG);
+ eigen_pass = (fp_mul(evmin, MAX_EIGEN_RATIO) > evmax) &&
+ (evmag > MIN_EIGEN_MAG) && (evmag < MAX_EIGEN_MAG);
#if 0
CPRINTF("mag eigenvalues: (%.02d %.02d %.02d), ",
diff --git a/common/main.c b/common/main.c
index 93e68fb1ca..ef5aef8acf 100644
--- a/common/main.c
+++ b/common/main.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -29,6 +29,7 @@
#ifdef CONFIG_MPU
#include "mpu.h"
#endif
+#include "panic.h"
#include "rwsig.h"
#include "system.h"
#include "task.h"
@@ -40,8 +41,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SYSTEM, outstr)
-#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
test_mockable __keep int main(void)
{
@@ -182,12 +183,12 @@ test_mockable __keep int main(void)
if (IS_ENABLED(CONFIG_EEPROM_CBI_WP) && system_is_locked())
cbi_latch_eeprom_wp();
- /*
- * Keyboard scan init/Button init can set recovery events to
- * indicate to host entry into recovery mode. Before this is
- * done, LPC_HOST_EVENT_ALWAYS_REPORT mask needs to be initialized
- * correctly.
- */
+ /*
+ * Keyboard scan init/Button init can set recovery events to
+ * indicate to host entry into recovery mode. Before this is
+ * done, LPC_HOST_EVENT_ALWAYS_REPORT mask needs to be
+ * initialized correctly.
+ */
#ifdef CONFIG_HOSTCMD_X86
lpc_init_mask();
#endif
@@ -228,9 +229,9 @@ test_mockable __keep int main(void)
#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON | CONFIG_VOLUME_BUTTONS) */
/* Make sure recovery boot won't be paused. */
- if (IS_ENABLED(CONFIG_POWER_BUTTON_INIT_IDLE)
- && system_is_manual_recovery()
- && (system_get_reset_flags() & EC_RESET_FLAG_AP_IDLE)) {
+ if (IS_ENABLED(CONFIG_POWER_BUTTON_INIT_IDLE) &&
+ system_is_manual_recovery() &&
+ (system_get_reset_flags() & EC_RESET_FLAG_AP_IDLE)) {
CPRINTS("Clear AP_IDLE for recovery mode");
system_clear_reset_flags(EC_RESET_FLAG_AP_IDLE);
}
@@ -270,15 +271,14 @@ test_mockable __keep int main(void)
rwsig_jump_now();
}
}
-#endif /* !CONFIG_VBOOT_EFS && CONFIG_RWSIG && !HAS_TASK_RWSIG */
+#endif /* !CONFIG_VBOOT_EFS && CONFIG_RWSIG && !HAS_TASK_RWSIG */
/*
* Disable I2C raw mode for the ports which needed pre-task i2c
* transactions as the task is about to start and the I2C can resume
* to event based transactions.
*/
- if (IS_ENABLED(CONFIG_I2C_BITBANG) &&
- IS_ENABLED(CONFIG_I2C_CONTROLLER))
+ if (IS_ENABLED(CONFIG_I2C_BITBANG) && IS_ENABLED(CONFIG_I2C_CONTROLLER))
enable_i2c_raw_mode(false);
/*
diff --git a/common/mat33.c b/common/mat33.c
index 87e335db26..844fd0b8cc 100644
--- a/common/mat33.c
+++ b/common/mat33.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -59,8 +59,7 @@ void mat33_fp_swap_rows(mat33_fp_t A, const size_t i, const size_t j)
* The i-th eigenvalue corresponds to the eigenvector in the i-th _row_ of
* "eigenvecs".
*/
-void mat33_fp_get_eigenbasis(mat33_fp_t S, fpv3_t e_vals,
- mat33_fp_t e_vecs)
+void mat33_fp_get_eigenbasis(mat33_fp_t S, fpv3_t e_vals, mat33_fp_t e_vecs)
{
const size_t N = 3;
sizev3_t ind;
@@ -176,8 +175,8 @@ size_t mat33_fp_maxind(mat33_fp_t A, size_t k)
return m;
}
-void mat33_fp_rotate(mat33_fp_t A, fp_t c, fp_t s,
- size_t k, size_t l, size_t i, size_t j)
+void mat33_fp_rotate(mat33_fp_t A, fp_t c, fp_t s, size_t k, size_t l, size_t i,
+ size_t j)
{
fp_t tmp = fp_mul(c, A[k][l]) - fp_mul(s, A[i][j]);
A[i][j] = fp_mul(s, A[k][l]) + fp_mul(c, A[i][j]);
diff --git a/common/mat44.c b/common/mat44.c
index a4232bf8d4..d48ca4f596 100644
--- a/common/mat44.c
+++ b/common/mat44.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 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/common/math_util.c b/common/math_util.c
index ff305438eb..c0a279b825 100644
--- a/common/math_util.c
+++ b/common/math_util.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,18 +11,18 @@
#include "util.h"
/* For cosine lookup table, define the increment and the size of the table. */
-#define COSINE_LUT_INCR_DEG 5
-#define COSINE_LUT_SIZE ((180 / COSINE_LUT_INCR_DEG) + 1)
+#define COSINE_LUT_INCR_DEG 5
+#define COSINE_LUT_SIZE ((180 / COSINE_LUT_INCR_DEG) + 1)
/* Lookup table for the value of cosine from 0 degrees to 180 degrees. */
static const fp_t cos_lut[] = {
- FLOAT_TO_FP( 1.00000), FLOAT_TO_FP( 0.99619), FLOAT_TO_FP( 0.98481),
- FLOAT_TO_FP( 0.96593), FLOAT_TO_FP( 0.93969), FLOAT_TO_FP( 0.90631),
- FLOAT_TO_FP( 0.86603), FLOAT_TO_FP( 0.81915), FLOAT_TO_FP( 0.76604),
- FLOAT_TO_FP( 0.70711), FLOAT_TO_FP( 0.64279), FLOAT_TO_FP( 0.57358),
- FLOAT_TO_FP( 0.50000), FLOAT_TO_FP( 0.42262), FLOAT_TO_FP( 0.34202),
- FLOAT_TO_FP( 0.25882), FLOAT_TO_FP( 0.17365), FLOAT_TO_FP( 0.08716),
- FLOAT_TO_FP( 0.00000), FLOAT_TO_FP(-0.08716), FLOAT_TO_FP(-0.17365),
+ FLOAT_TO_FP(1.00000), FLOAT_TO_FP(0.99619), FLOAT_TO_FP(0.98481),
+ FLOAT_TO_FP(0.96593), FLOAT_TO_FP(0.93969), FLOAT_TO_FP(0.90631),
+ FLOAT_TO_FP(0.86603), FLOAT_TO_FP(0.81915), FLOAT_TO_FP(0.76604),
+ FLOAT_TO_FP(0.70711), FLOAT_TO_FP(0.64279), FLOAT_TO_FP(0.57358),
+ FLOAT_TO_FP(0.50000), FLOAT_TO_FP(0.42262), FLOAT_TO_FP(0.34202),
+ FLOAT_TO_FP(0.25882), FLOAT_TO_FP(0.17365), FLOAT_TO_FP(0.08716),
+ FLOAT_TO_FP(0.00000), FLOAT_TO_FP(-0.08716), FLOAT_TO_FP(-0.17365),
FLOAT_TO_FP(-0.25882), FLOAT_TO_FP(-0.34202), FLOAT_TO_FP(-0.42262),
FLOAT_TO_FP(-0.50000), FLOAT_TO_FP(-0.57358), FLOAT_TO_FP(-0.64279),
FLOAT_TO_FP(-0.70711), FLOAT_TO_FP(-0.76604), FLOAT_TO_FP(-0.81915),
@@ -32,7 +32,6 @@ static const fp_t cos_lut[] = {
};
BUILD_ASSERT(ARRAY_SIZE(cos_lut) == COSINE_LUT_SIZE);
-
fp_t arc_cos(fp_t x)
{
int i;
@@ -48,8 +47,8 @@ fp_t arc_cos(fp_t x)
* interpolate for precision.
*/
/* TODO(crosbug.com/p/25600): Optimize with binary search. */
- for (i = 0; i < COSINE_LUT_SIZE-1; i++) {
- if (x >= cos_lut[i+1]) {
+ for (i = 0; i < COSINE_LUT_SIZE - 1; i++) {
+ if (x >= cos_lut[i + 1]) {
const fp_t interp = fp_div(cos_lut[i] - x,
cos_lut[i] - cos_lut[i + 1]);
@@ -104,7 +103,7 @@ int int_sqrtf(fp_inter_t x)
* infrequently enough it doesn't matter.
*/
if (x <= 0)
- return 0; /* Yeah, for imaginary numbers too */
+ return 0; /* Yeah, for imaginary numbers too */
else if (x >= (fp_inter_t)rmax * rmax)
return rmax;
@@ -138,9 +137,8 @@ fp_t fp_sqrtf(fp_t x)
int vector_magnitude(const intv3_t v)
{
- fp_inter_t sum = (fp_inter_t)v[0] * v[0] +
- (fp_inter_t)v[1] * v[1] +
- (fp_inter_t)v[2] * v[2];
+ fp_inter_t sum = (fp_inter_t)v[0] * v[0] + (fp_inter_t)v[1] * v[1] +
+ (fp_inter_t)v[2] * v[2];
return int_sqrtf(sum);
}
@@ -155,8 +153,7 @@ void cross_product(const intv3_t v1, const intv3_t v2, intv3_t v)
fp_inter_t dot_product(const intv3_t v1, const intv3_t v2)
{
- return (fp_inter_t)v1[X] * v2[X] +
- (fp_inter_t)v1[Y] * v2[Y] +
+ return (fp_inter_t)v1[X] * v2[X] + (fp_inter_t)v1[Y] * v2[Y] +
(fp_inter_t)v1[Z] * v2[Z];
}
@@ -215,17 +212,13 @@ void rotate(const intv3_t v, const mat33_fp_t R, intv3_t res)
return;
}
-
/* Rotate */
- t[0] = (fp_inter_t)v[0] * R[0][0] +
- (fp_inter_t)v[1] * R[1][0] +
- (fp_inter_t)v[2] * R[2][0];
- t[1] = (fp_inter_t)v[0] * R[0][1] +
- (fp_inter_t)v[1] * R[1][1] +
- (fp_inter_t)v[2] * R[2][1];
- t[2] = (fp_inter_t)v[0] * R[0][2] +
- (fp_inter_t)v[1] * R[1][2] +
- (fp_inter_t)v[2] * R[2][2];
+ t[0] = (fp_inter_t)v[0] * R[0][0] + (fp_inter_t)v[1] * R[1][0] +
+ (fp_inter_t)v[2] * R[2][0];
+ t[1] = (fp_inter_t)v[0] * R[0][1] + (fp_inter_t)v[1] * R[1][1] +
+ (fp_inter_t)v[2] * R[2][1];
+ t[2] = (fp_inter_t)v[0] * R[0][2] + (fp_inter_t)v[1] * R[1][2] +
+ (fp_inter_t)v[2] * R[2][2];
/* Scale by fixed point shift when writing back to result */
res[0] = FP_TO_INT(t[0]);
@@ -244,38 +237,39 @@ void rotate_inv(const intv3_t v, const mat33_fp_t R, intv3_t res)
return;
}
- deter = fp_mul(R[0][0], (fp_mul(R[1][1], R[2][2]) -
- fp_mul(R[2][1], R[1][2]))) -
- fp_mul(R[0][1], (fp_mul(R[1][0], R[2][2]) -
- fp_mul(R[1][2], R[2][0]))) +
- fp_mul(R[0][2], (fp_mul(R[1][0], R[2][1]) -
- fp_mul(R[1][1], R[2][0])));
+ deter = fp_mul(R[0][0],
+ (fp_mul(R[1][1], R[2][2]) - fp_mul(R[2][1], R[1][2]))) -
+ fp_mul(R[0][1],
+ (fp_mul(R[1][0], R[2][2]) - fp_mul(R[1][2], R[2][0]))) +
+ fp_mul(R[0][2],
+ (fp_mul(R[1][0], R[2][1]) - fp_mul(R[1][1], R[2][0])));
/*
* invert the matrix: from
* http://stackoverflow.com/questions/983999/
* simple-3x3-matrix-inverse-code-c
*/
- t[0] = (fp_inter_t)v[0] * (fp_mul(R[1][1], R[2][2]) -
- fp_mul(R[2][1], R[1][2])) -
- (fp_inter_t)v[1] * (fp_mul(R[1][0], R[2][2]) -
- fp_mul(R[1][2], R[2][0])) +
- (fp_inter_t)v[2] * (fp_mul(R[1][0], R[2][1]) -
- fp_mul(R[2][0], R[1][1]));
-
- t[1] = (fp_inter_t)v[0] * (fp_mul(R[0][1], R[2][2]) -
- fp_mul(R[0][2], R[2][1])) * -1 +
- (fp_inter_t)v[1] * (fp_mul(R[0][0], R[2][2]) -
- fp_mul(R[0][2], R[2][0])) -
- (fp_inter_t)v[2] * (fp_mul(R[0][0], R[2][1]) -
- fp_mul(R[2][0], R[0][1]));
-
- t[2] = (fp_inter_t)v[0] * (fp_mul(R[0][1], R[1][2]) -
- fp_mul(R[0][2], R[1][1])) -
- (fp_inter_t)v[1] * (fp_mul(R[0][0], R[1][2]) -
- fp_mul(R[1][0], R[0][2])) +
- (fp_inter_t)v[2] * (fp_mul(R[0][0], R[1][1]) -
- fp_mul(R[1][0], R[0][1]));
+ t[0] = (fp_inter_t)v[0] *
+ (fp_mul(R[1][1], R[2][2]) - fp_mul(R[2][1], R[1][2])) -
+ (fp_inter_t)v[1] *
+ (fp_mul(R[1][0], R[2][2]) - fp_mul(R[1][2], R[2][0])) +
+ (fp_inter_t)v[2] *
+ (fp_mul(R[1][0], R[2][1]) - fp_mul(R[2][0], R[1][1]));
+
+ t[1] = (fp_inter_t)v[0] *
+ (fp_mul(R[0][1], R[2][2]) - fp_mul(R[0][2], R[2][1])) *
+ -1 +
+ (fp_inter_t)v[1] *
+ (fp_mul(R[0][0], R[2][2]) - fp_mul(R[0][2], R[2][0])) -
+ (fp_inter_t)v[2] *
+ (fp_mul(R[0][0], R[2][1]) - fp_mul(R[2][0], R[0][1]));
+
+ t[2] = (fp_inter_t)v[0] *
+ (fp_mul(R[0][1], R[1][2]) - fp_mul(R[0][2], R[1][1])) -
+ (fp_inter_t)v[1] *
+ (fp_mul(R[0][0], R[1][2]) - fp_mul(R[1][0], R[0][2])) +
+ (fp_inter_t)v[2] *
+ (fp_mul(R[0][0], R[1][1]) - fp_mul(R[1][0], R[0][1]));
/* Scale by fixed point shift when writing back to result */
res[0] = FP_TO_INT(fp_div(t[0], deter));
@@ -287,8 +281,8 @@ void rotate_inv(const intv3_t v, const mat33_fp_t R, intv3_t res)
int round_divide(int64_t dividend, int divisor)
{
return (dividend > 0) ^ (divisor > 0) ?
- (dividend - divisor / 2) / divisor :
- (dividend + divisor / 2) / divisor;
+ (dividend - divisor / 2) / divisor :
+ (dividend + divisor / 2) / divisor;
}
#if ULONG_MAX == 0xFFFFFFFFUL
@@ -303,7 +297,7 @@ uint64_t bitmask_uint64(int offset)
{
union mask64_t {
struct {
-#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
uint32_t lo;
uint32_t hi;
#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
diff --git a/common/memory_commands.c b/common/memory_commands.c
index 98c64d918b..cb53c4890a 100644
--- a/common/memory_commands.c
+++ b/common/memory_commands.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,7 +10,6 @@
#include "util.h"
#include "watchdog.h"
-
enum format {
FMT_WORD,
FMT_HALF,
@@ -56,7 +55,7 @@ static void show_val(uint32_t address, uint32_t index, enum format fmt)
cflush();
}
-static int command_mem_dump(int argc, char **argv)
+static int command_mem_dump(int argc, const char **argv)
{
uint32_t address, i, num = 1;
char *e;
@@ -106,15 +105,14 @@ static int command_mem_dump(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND_FLAGS
- (md, command_mem_dump,
- "[.b|.h|.s] addr [count]",
- "dump memory values, optionally specifying the format",
- CMD_FLAG_RESTRICTED);
+DECLARE_CONSOLE_COMMAND_FLAGS(
+ md, command_mem_dump, "[.b|.h|.s] addr [count]",
+ "dump memory values, optionally specifying the format",
+ CMD_FLAG_RESTRICTED);
#endif /* CONFIG_CMD_MD */
#ifdef CONFIG_CMD_RW
-static int command_read_word(int argc, char **argv)
+static int command_read_word(int argc, const char **argv)
{
volatile uint32_t *address;
uint32_t value;
@@ -149,16 +147,16 @@ static int command_read_word(int argc, char **argv)
if ((argc - argc_offs) < 3) {
switch (access_size) {
case 1:
- ccprintf("read 0x%pP = 0x%02x\n",
- address, *((uint8_t *)address));
+ ccprintf("read 0x%p = 0x%02x\n", address,
+ *((uint8_t *)address));
break;
case 2:
- ccprintf("read 0x%pP = 0x%04x\n",
- address, *((uint16_t *)address));
+ ccprintf("read 0x%p = 0x%04x\n", address,
+ *((uint16_t *)address));
break;
default:
- ccprintf("read 0x%pP = 0x%08x\n", address, *address);
+ ccprintf("read 0x%p = 0x%08x\n", address, *address);
break;
}
return EC_SUCCESS;
@@ -171,17 +169,17 @@ static int command_read_word(int argc, char **argv)
switch (access_size) {
case 1:
- ccprintf("write 0x%pP = 0x%02x\n", address, (uint8_t)value);
- cflush(); /* Flush before writing in case this crashes */
+ ccprintf("write 0x%p = 0x%02x\n", address, (uint8_t)value);
+ cflush(); /* Flush before writing in case this crashes */
*((uint8_t *)address) = (uint8_t)value;
break;
case 2:
- ccprintf("write 0x%pP = 0x%04x\n", address, (uint16_t)value);
+ ccprintf("write 0x%p = 0x%04x\n", address, (uint16_t)value);
cflush();
*((uint16_t *)address) = (uint16_t)value;
break;
default:
- ccprintf("write 0x%pP = 0x%02x\n", address, value);
+ ccprintf("write 0x%p = 0x%02x\n", address, value);
cflush();
*address = value;
break;
@@ -190,9 +188,8 @@ static int command_read_word(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND_FLAGS
- (rw, command_read_word,
- "[.b|.h] addr [value]",
- "Read or write a word in memory optionally specifying the size",
- CMD_FLAG_RESTRICTED);
-#endif /* CONFIG_CMD_RW */
+DECLARE_CONSOLE_COMMAND_FLAGS(
+ rw, command_read_word, "[.b|.h] addr [value]",
+ "Read or write a word in memory optionally specifying the size",
+ CMD_FLAG_RESTRICTED);
+#endif /* CONFIG_CMD_RW */
diff --git a/common/mkbp_event.c b/common/mkbp_event.c
index d67951c3b3..e602f81baf 100644
--- a/common/mkbp_event.c
+++ b/common/mkbp_event.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -18,8 +18,8 @@
#include "util.h"
#define CPUTS(outstr) cputs(CC_COMMAND, outstr)
-#define CPRINTS(format, args...) cprints(CC_COMMAND, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_COMMAND, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_COMMAND, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_COMMAND, format, ##args)
/*
* Tracks the current state of the MKBP interrupt send from the EC to the AP.
@@ -165,7 +165,7 @@ static int mkbp_set_host_active(int active, uint32_t *timestamp)
return mkbp_set_host_active_via_custom(active, timestamp);
#elif defined(CONFIG_MKBP_USE_HOST_EVENT)
return mkbp_set_host_active_via_event(active, timestamp);
-#elif defined(CONFIG_MKBP_USE_GPIO) ||\
+#elif defined(CONFIG_MKBP_USE_GPIO) || \
defined(CONFIG_MKBP_USE_GPIO_AND_HOST_EVENT)
return mkbp_set_host_active_via_gpio(active, timestamp);
#elif defined(CONFIG_MKBP_USE_HECI)
@@ -185,10 +185,9 @@ static inline int host_is_sleeping(void)
#ifdef CONFIG_POWER_TRACK_HOST_SLEEP_STATE
enum host_sleep_event sleep_state = power_get_host_sleep_state();
- is_sleeping |=
- (sleep_state == HOST_SLEEP_EVENT_S0IX_SUSPEND ||
- sleep_state == HOST_SLEEP_EVENT_S3_SUSPEND ||
- sleep_state == HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND);
+ is_sleeping |= (sleep_state == HOST_SLEEP_EVENT_S0IX_SUSPEND ||
+ sleep_state == HOST_SLEEP_EVENT_S3_SUSPEND ||
+ sleep_state == HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND);
#endif
return is_sleeping;
}
@@ -202,7 +201,7 @@ static inline int host_is_sleeping(void)
static void force_mkbp_if_events(void);
DECLARE_DEFERRED(force_mkbp_if_events);
-static void activate_mkbp_with_events(uint32_t events_to_add)
+test_export_static void activate_mkbp_with_events(uint32_t events_to_add)
{
int interrupt_id = -1;
int skip_interrupt = 0;
@@ -216,16 +215,16 @@ static void activate_mkbp_with_events(uint32_t events_to_add)
*/
if (events_to_add == BIT(EC_MKBP_EVENT_HOST_EVENT) ||
events_to_add == BIT(EC_MKBP_EVENT_HOST_EVENT64))
- skip_interrupt = host_is_sleeping() &&
- !(host_get_events() &
- mkbp_host_event_wake_mask);
+ skip_interrupt =
+ host_is_sleeping() &&
+ !(host_get_events() & mkbp_host_event_wake_mask);
#endif /* CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK */
#ifdef CONFIG_MKBP_EVENT_WAKEUP_MASK
/* Check to see if this MKBP event should wake the system. */
if (!skip_interrupt)
skip_interrupt = host_is_sleeping() &&
- !(events_to_add & mkbp_event_wake_mask);
+ !(events_to_add & mkbp_event_wake_mask);
#endif /* CONFIG_MKBP_EVENT_WAKEUP_MASK */
mutex_lock(&state.lock);
@@ -257,8 +256,8 @@ static void activate_mkbp_with_events(uint32_t events_to_add)
if (state.interrupt == INTERRUPT_INACTIVE_TO_ACTIVE &&
interrupt_id == state.interrupt_id) {
schedule_deferred = 1;
- state.interrupt = rv == EC_SUCCESS ? INTERRUPT_ACTIVE
- : INTERRUPT_INACTIVE;
+ state.interrupt = rv == EC_SUCCESS ? INTERRUPT_ACTIVE :
+ INTERRUPT_INACTIVE;
}
mutex_unlock(&state.lock);
@@ -308,8 +307,8 @@ static void force_mkbp_if_events(void)
* of events or we exceed number of attempts, so marking
* interrupt as INACTIVE doesn't affect failed_attempts counter.
* If we need to send interrupt once again
- * activate_mkbp_with_events() will set interrupt state to ACTIVE
- * before this function will be called.
+ * activate_mkbp_with_events() will set interrupt state to
+ * ACTIVE before this function will be called.
*/
if (++state.failed_attempts < 3) {
send_mkbp_interrupt = 1;
@@ -456,8 +455,7 @@ static enum ec_status mkbp_get_next_event(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_NEXT_EVENT,
- mkbp_get_next_event,
+DECLARE_HOST_COMMAND(EC_CMD_GET_NEXT_EVENT, mkbp_get_next_event,
EC_VER_MASK(0) | EC_VER_MASK(1) | EC_VER_MASK(2));
#ifdef CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK
@@ -473,12 +471,11 @@ mkbp_get_host_event_wake_mask(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_WAKE_MASK,
- mkbp_get_host_event_wake_mask,
- EC_VER_MASK(0));
+ mkbp_get_host_event_wake_mask, EC_VER_MASK(0));
#endif /* CONFIG_MKBP_USE_HOST_EVENT */
#endif /* CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK */
-#if defined(CONFIG_MKBP_EVENT_WAKEUP_MASK) || \
+#if defined(CONFIG_MKBP_EVENT_WAKEUP_MASK) || \
defined(CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK)
static enum ec_status hc_mkbp_wake_mask(struct host_cmd_handler_args *args)
{
@@ -517,8 +514,7 @@ static enum ec_status hc_mkbp_wake_mask(struct host_cmd_handler_args *args)
case EC_MKBP_HOST_EVENT_WAKE_MASK:
CPRINTF("MKBP hostevent mask updated to: 0x%08x "
"(was 0x%08x)\n",
- p->new_wake_mask,
- mkbp_host_event_wake_mask);
+ p->new_wake_mask, mkbp_host_event_wake_mask);
mkbp_host_event_wake_mask = p->new_wake_mask;
break;
#endif /* CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK */
@@ -543,11 +539,9 @@ static enum ec_status hc_mkbp_wake_mask(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_MKBP_WAKE_MASK,
- hc_mkbp_wake_mask,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_MKBP_WAKE_MASK, hc_mkbp_wake_mask, EC_VER_MASK(0));
-static int command_mkbp_wake_mask(int argc, char **argv)
+static int command_mkbp_wake_mask(int argc, const char **argv)
{
if (argc == 3) {
char *e;
@@ -582,3 +576,15 @@ DECLARE_CONSOLE_COMMAND(mkbpwakemask, command_mkbp_wake_mask,
"[event | hostevent] [new_mask]",
"Show or set MKBP event/hostevent wake mask");
#endif /* CONFIG_MKBP_(HOST)?EVENT_WAKEUP_MASK */
+
+#ifdef TEST_BUILD
+void mkbp_event_clear_all(void)
+{
+ mutex_lock(&state.lock);
+ state.events = 0;
+ mutex_unlock(&state.lock);
+
+ /* Reset the interrupt line */
+ mkbp_set_host_active(0, NULL);
+}
+#endif
diff --git a/common/mkbp_fifo.c b/common/mkbp_fifo.c
index c394d9fc77..dfcf87814e 100644
--- a/common/mkbp_fifo.c
+++ b/common/mkbp_fifo.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.
*
@@ -15,7 +15,7 @@
#include "util.h"
/* Console output macros */
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
/*
* Common FIFO depth. This needs to be big enough not to overflow if a
@@ -26,9 +26,9 @@
* which is non-trivial but not horrible.
*/
-static uint32_t fifo_start; /* first entry */
-static uint32_t fifo_end; /* last entry */
-static atomic_t fifo_entries; /* number of existing entries */
+static uint32_t fifo_start; /* first entry */
+static uint32_t fifo_end; /* last entry */
+static atomic_t fifo_entries; /* number of existing entries */
static uint8_t fifo_max_depth = FIFO_DEPTH;
static struct ec_response_get_next_event fifo[FIFO_DEPTH];
@@ -114,7 +114,6 @@ void mkbp_fifo_depth_update(uint8_t new_max_depth)
fifo_max_depth = new_max_depth;
}
-
void mkbp_fifo_clear_keyboard(void)
{
int i, new_fifo_entries = 0;
@@ -180,8 +179,7 @@ test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp)
mutex_lock(&fifo_add_mutex);
if (fifo_entries >= fifo_max_depth) {
mutex_unlock(&fifo_add_mutex);
- CPRINTS("MKBP common FIFO depth %d reached",
- fifo_max_depth);
+ CPRINTS("MKBP common FIFO depth %d reached", fifo_max_depth);
return EC_ERROR_OVERFLOW;
}
diff --git a/common/mkbp_info.c b/common/mkbp_info.c
index 52d26f407b..c195eda888 100644
--- a/common/mkbp_info.c
+++ b/common/mkbp_info.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.
*/
@@ -25,7 +25,7 @@ __overridable int mkbp_support_volume_buttons(void)
#endif
}
-static uint32_t get_supported_buttons(void)
+test_export_static uint32_t get_supported_buttons(void)
{
uint32_t val = 0;
@@ -44,7 +44,7 @@ static uint32_t get_supported_buttons(void)
return val;
}
-static uint32_t get_supported_switches(void)
+test_export_static uint32_t get_supported_switches(void)
{
uint32_t val = 0;
diff --git a/common/mkbp_input_devices.c b/common/mkbp_input_devices.c
index 7cba670eb1..6cc277ab98 100644
--- a/common/mkbp_input_devices.c
+++ b/common/mkbp_input_devices.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.
*/
@@ -20,7 +20,7 @@
#include "tablet_mode.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ##args)
/* Buttons and switch state. */
static uint32_t mkbp_button_state;
@@ -69,7 +69,7 @@ void mkbp_button_update(enum keyboard_button_type button, int is_pressed)
CPRINTS("mkbp buttons: %x", mkbp_button_state);
mkbp_fifo_add(EC_MKBP_EVENT_BUTTON,
- (const uint8_t *)&mkbp_button_state);
+ (const uint8_t *)&mkbp_button_state);
};
void mkbp_update_switches(uint32_t sw, int state)
@@ -86,10 +86,9 @@ void mkbp_update_switches(uint32_t sw, int state)
*/
if (mkbp_init_done)
mkbp_fifo_add(EC_MKBP_EVENT_SWITCH,
- (const uint8_t *)&mkbp_switch_state);
+ (const uint8_t *)&mkbp_switch_state);
}
-
/*****************************************************************************/
/* Hooks */
@@ -99,8 +98,7 @@ void mkbp_update_switches(uint32_t sw, int state)
*/
static void keyboard_power_button(void)
{
- mkbp_button_update(KEYBOARD_BUTTON_POWER,
- power_button_is_pressed());
+ mkbp_button_update(KEYBOARD_BUTTON_POWER, power_button_is_pressed());
}
DECLARE_HOOK(HOOK_POWER_BUTTON_CHANGE, keyboard_power_button,
HOOK_PRIO_DEFAULT);
@@ -142,7 +140,7 @@ static void mkbp_report_switch_on_init(void)
/* All switches initialized, report switch state to AP */
mkbp_init_done = true;
mkbp_fifo_add(EC_MKBP_EVENT_SWITCH,
- (const uint8_t *)&mkbp_switch_state);
+ (const uint8_t *)&mkbp_switch_state);
}
DECLARE_HOOK(HOOK_INIT, mkbp_report_switch_on_init, HOOK_PRIO_LAST);
@@ -188,7 +186,7 @@ uint8_t keyboard_cols = KEYBOARD_COLS_MAX;
static void simulate_key(int row, int col, int pressed)
{
if ((simulated_key[col] & BIT(row)) == ((pressed ? 1 : 0) << row))
- return; /* No change */
+ return; /* No change */
simulated_key[col] &= ~BIT(row);
if (pressed)
@@ -197,7 +195,7 @@ static void simulate_key(int row, int col, int pressed)
mkbp_fifo_add((uint8_t)EC_MKBP_EVENT_KEY_MATRIX, simulated_key);
}
-static int command_mkbp_keyboard_press(int argc, char **argv)
+static int command_mkbp_keyboard_press(int argc, const char **argv)
{
if (argc == 1) {
int i, j;
@@ -239,7 +237,6 @@ static int command_mkbp_keyboard_press(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(kbpress, command_mkbp_keyboard_press,
- "[col row [0 | 1]]",
- "Simulate keypress");
+ "[col row [0 | 1]]", "Simulate keypress");
#endif /* !defined(HAS_TASK_KEYSCAN) */
diff --git a/common/mock/README.md b/common/mock/README.md
index c7695531b6..62f53f5416 100644
--- a/common/mock/README.md
+++ b/common/mock/README.md
@@ -38,7 +38,7 @@ one.
Example `.mocklist`:
```c
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 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/common/mock/adc_mock.c b/common/mock/adc_mock.c
index 9727c560d3..35cf4aadb5 100644
--- a/common/mock/adc_mock.c
+++ b/common/mock/adc_mock.c
@@ -1,4 +1,4 @@
-/* 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.
*/
diff --git a/common/mock/battery_mock.c b/common/mock/battery_mock.c
index 63e94c660b..0d6b4fdb22 100644
--- a/common/mock/battery_mock.c
+++ b/common/mock/battery_mock.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.
*/
@@ -141,7 +141,7 @@ void set_battery_time_to_full(int new_value)
}
#define MAX_DEVICE_NAME_LENGTH 40
-static char battery_device_name_value[MAX_DEVICE_NAME_LENGTH+1] = "?";
+static char battery_device_name_value[MAX_DEVICE_NAME_LENGTH + 1] = "?";
int battery_device_name(char *dest, int size)
{
int i;
@@ -159,12 +159,13 @@ void set_battery_device_name(char *new_value)
for (i = 0; i < size && i < MAX_DEVICE_NAME_LENGTH; ++i)
battery_device_name_value[i] = new_value[i];
- for (; i < MAX_DEVICE_NAME_LENGTH+1; ++i)
+ for (; i < MAX_DEVICE_NAME_LENGTH + 1; ++i)
battery_device_name_value[i] = '\0';
}
#define MAX_DEVICE_CHEMISTRY_LENGTH 40
-static char battery_device_chemistry_value[MAX_DEVICE_CHEMISTRY_LENGTH+1] = "?";
+static char battery_device_chemistry_value[MAX_DEVICE_CHEMISTRY_LENGTH + 1] =
+ "?";
int battery_device_chemistry(char *dest, int size)
{
int i;
@@ -182,7 +183,7 @@ void set_battery_device_chemistry(char *new_value)
for (i = 0; i < size && i < MAX_DEVICE_CHEMISTRY_LENGTH; ++i)
battery_device_chemistry_value[i] = new_value[i];
- for (; i < MAX_DEVICE_CHEMISTRY_LENGTH+1; ++i)
+ for (; i < MAX_DEVICE_CHEMISTRY_LENGTH + 1; ++i)
battery_device_chemistry_value[i] = '\0';
}
@@ -194,7 +195,7 @@ static int battery_temperature_value = 20;
static int battery_voltage_value = 5000;
void battery_get_params(struct batt_params *batt)
{
- struct batt_params batt_new = {0};
+ struct batt_params batt_new = { 0 };
batt_new.temperature = battery_temperature_value;
batt_new.state_of_charge = battery_soc_value;
diff --git a/common/mock/build.mk b/common/mock/build.mk
index fd87f40990..a8b109429c 100644
--- a/common/mock/build.mk
+++ b/common/mock/build.mk
@@ -1,4 +1,4 @@
-# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Copyright 2019 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -8,6 +8,7 @@ mock-$(HAS_MOCK_ADC) += adc_mock.o
mock-$(HAS_MOCK_BATTERY) += battery_mock.o
mock-$(HAS_MOCK_CHARGE_MANAGER) += charge_manager_mock.o
mock-$(HAS_MOCK_FP_SENSOR) += fp_sensor_mock.o
+mock-$(HAS_MOCK_FPSENSOR_CRYPTO) += fpsensor_crypto_mock.o
mock-$(HAS_MOCK_FPSENSOR_DETECT) += fpsensor_detect_mock.o
mock-$(HAS_MOCK_FPSENSOR_STATE) += fpsensor_state_mock.o
mock-$(HAS_MOCK_MKBP_EVENTS) += mkbp_events_mock.o
diff --git a/common/mock/charge_manager_mock.c b/common/mock/charge_manager_mock.c
index 11661d2b2e..b27e7de241 100644
--- a/common/mock/charge_manager_mock.c
+++ b/common/mock/charge_manager_mock.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.
*/
@@ -47,4 +47,4 @@ void mock_charge_manager_set_vbus_voltage(int voltage_mv)
}
struct mock_ctrl_charge_manager mock_ctrl_charge_manager =
-MOCK_CTRL_DEFAULT_CHARGE_MANAGER;
+ MOCK_CTRL_DEFAULT_CHARGE_MANAGER;
diff --git a/common/mock/dp_alt_mode_mock.c b/common/mock/dp_alt_mode_mock.c
index 29f76bdb7a..e261415aaa 100644
--- a/common/mock/dp_alt_mode_mock.c
+++ b/common/mock/dp_alt_mode_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -18,8 +18,8 @@
#endif
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
diff --git a/common/mock/fp_sensor_mock.c b/common/mock/fp_sensor_mock.c
index 363f092ff1..4db25a821c 100644
--- a/common/mock/fp_sensor_mock.c
+++ b/common/mock/fp_sensor_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -59,9 +59,8 @@ int fp_sensor_acquire_image_with_mode(uint8_t *image_data, int mode)
return mock_ctrl_fp_sensor.fp_sensor_acquire_image_with_mode_return;
}
-int fp_finger_match(void *templ, uint32_t templ_count,
- uint8_t *image, int32_t *match_index,
- uint32_t *update_bitmap)
+int fp_finger_match(void *templ, uint32_t templ_count, uint8_t *image,
+ int32_t *match_index, uint32_t *update_bitmap)
{
return mock_ctrl_fp_sensor.fp_finger_match_return;
}
diff --git a/common/mock/fpsensor_crypto_mock.c b/common/mock/fpsensor_crypto_mock.c
new file mode 100644
index 0000000000..f2cc425c8f
--- /dev/null
+++ b/common/mock/fpsensor_crypto_mock.c
@@ -0,0 +1,63 @@
+/* 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.
+ */
+
+/**
+ * @file fpsensor_crypto_mock.c
+ * @brief Mock fpsensor_crypto library
+ */
+#include "sha256.h"
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "assert.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "ec_commands.h"
+#include "fpsensor_private.h"
+#include "mock/fpsensor_crypto_mock.h"
+
+#ifndef TEST_BUILD
+#error "Mocks should only be in the test build."
+#endif
+
+struct mock_ctrl_fpsensor_crypto mock_ctrl_fpsensor_crypto =
+ MOCK_CTRL_DEFAULT_FPSENSOR_CRYPTO;
+
+#define MESSAGE_ZERO_IDX 0
+#define MESSAGE_FF_IDX 1
+typedef uint8_t key_message_pair[FP_POSITIVE_MATCH_SECRET_BYTES];
+
+key_message_pair fake_fpsensor_crypto[] = {
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+};
+
+BUILD_ASSERT(sizeof(key_message_pair) == FP_POSITIVE_MATCH_SECRET_BYTES);
+
+/* Mock compute_hmac_sha256 for unit or fuzz tests. */
+void compute_hmac_sha256(uint8_t *output, const uint8_t *key, const int key_len,
+ const uint8_t *message, const int message_len)
+{
+ switch (mock_ctrl_fpsensor_crypto.output_type) {
+ case MOCK_CTRL_FPSENSOR_CRYPTO_SHA256_TYPE_REAL:
+ hmac_SHA256(output, key, key_len, message, message_len);
+ break;
+ case MOCK_CTRL_FPSENSOR_CRYPTO_SHA256_TYPE_ZEROS:
+ memcpy(output, fake_fpsensor_crypto[MESSAGE_ZERO_IDX],
+ FP_POSITIVE_MATCH_SECRET_BYTES);
+ break;
+ case MOCK_CTRL_FPSENSOR_CRYPTO_SHA256_TYPE_FF:
+ memcpy(output, fake_fpsensor_crypto[MESSAGE_FF_IDX],
+ FP_POSITIVE_MATCH_SECRET_BYTES);
+ break;
+ default:
+ assert(0);
+ break;
+ };
+}
diff --git a/common/mock/fpsensor_detect_mock.c b/common/mock/fpsensor_detect_mock.c
index 6e3ca839f1..50f27f92bf 100644
--- a/common/mock/fpsensor_detect_mock.c
+++ b/common/mock/fpsensor_detect_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/mock/fpsensor_state_mock.c b/common/mock/fpsensor_state_mock.c
index c3092fe860..cbeb29ae3c 100644
--- a/common/mock/fpsensor_state_mock.c
+++ b/common/mock/fpsensor_state_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,6 +7,7 @@
#include <string.h>
#include "common.h"
+#include "driver/fingerprint/fpsensor.h"
#include "ec_commands.h"
#include "test_util.h"
@@ -21,6 +22,38 @@ const uint8_t default_fake_tpm_seed[] = {
};
BUILD_ASSERT(sizeof(default_fake_tpm_seed) == FP_CONTEXT_TPM_BYTES);
+const uint8_t default_fake_fp_positive_match_salt
+ [FP_MAX_FINGER_COUNT][FP_POSITIVE_MATCH_SALT_BYTES] = {
+ { 0x04, 0x1f, 0x5a, 0xac, 0x5f, 0x79, 0x10, 0xaf, 0x04, 0x1d,
+ 0x46, 0x3a, 0x5f, 0x08, 0xee, 0xcb },
+ { 0x04, 0x1f, 0x5a, 0xac, 0x5f, 0x79, 0x10, 0xaf, 0x04, 0x1d,
+ 0x46, 0x3a, 0x5f, 0x08, 0xee, 0xcb },
+ { 0x04, 0x1f, 0x5a, 0xac, 0x5f, 0x79, 0x10, 0xaf, 0x04, 0x1d,
+ 0x46, 0x3a, 0x5f, 0x08, 0xee, 0xcb },
+ { 0x04, 0x1f, 0x5a, 0xac, 0x5f, 0x79, 0x10, 0xaf, 0x04, 0x1d,
+ 0x46, 0x3a, 0x5f, 0x08, 0xee, 0xcb },
+ { 0x04, 0x1f, 0x5a, 0xac, 0x5f, 0x79, 0x10, 0xaf, 0x04, 0x1d,
+ 0x46, 0x3a, 0x5f, 0x08, 0xee, 0xcb }
+ };
+BUILD_ASSERT(sizeof(default_fake_fp_positive_match_salt) ==
+ FP_MAX_FINGER_COUNT * FP_POSITIVE_MATCH_SALT_BYTES);
+
+const uint8_t trivial_fp_positive_match_salt
+ [FP_MAX_FINGER_COUNT][FP_POSITIVE_MATCH_SALT_BYTES] = {
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+ };
+BUILD_ASSERT(sizeof(trivial_fp_positive_match_salt) ==
+ FP_MAX_FINGER_COUNT * FP_POSITIVE_MATCH_SALT_BYTES);
+
int fpsensor_state_mock_set_tpm_seed(
const uint8_t tpm_seed[FP_CONTEXT_TPM_BYTES])
{
diff --git a/common/mock/mkbp_events_mock.c b/common/mock/mkbp_events_mock.c
index d42c06fdec..3f4d76b659 100644
--- a/common/mock/mkbp_events_mock.c
+++ b/common/mock/mkbp_events_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 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/common/mock/rollback_mock.c b/common/mock/rollback_mock.c
index 2b26d9d8d7..e68616df53 100644
--- a/common/mock/rollback_mock.c
+++ b/common/mock/rollback_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,10 +23,9 @@
struct mock_ctrl_rollback mock_ctrl_rollback = MOCK_CTRL_DEFAULT_ROLLBACK;
static const uint8_t fake_rollback_secret[] = {
- 0xcf, 0xe3, 0x23, 0x76, 0x35, 0x04, 0xc2, 0x0f,
- 0x0d, 0xb6, 0x02, 0xa9, 0x68, 0xba, 0x2a, 0x61,
- 0x86, 0x2a, 0x85, 0xd1, 0xca, 0x09, 0x54, 0x8a,
- 0x6b, 0xe2, 0xe3, 0x38, 0xde, 0x5d, 0x59, 0x14,
+ 0xcf, 0xe3, 0x23, 0x76, 0x35, 0x04, 0xc2, 0x0f, 0x0d, 0xb6, 0x02,
+ 0xa9, 0x68, 0xba, 0x2a, 0x61, 0x86, 0x2a, 0x85, 0xd1, 0xca, 0x09,
+ 0x54, 0x8a, 0x6b, 0xe2, 0xe3, 0x38, 0xde, 0x5d, 0x59, 0x14,
};
BUILD_ASSERT(sizeof(fake_rollback_secret) == CONFIG_ROLLBACK_SECRET_SIZE);
diff --git a/common/mock/tcpc_mock.c b/common/mock/tcpc_mock.c
index a9bb12b356..31dda7eba1 100644
--- a/common/mock/tcpc_mock.c
+++ b/common/mock/tcpc_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -125,8 +125,7 @@ static int mock_set_msg_header(int port, int power_role, int data_role)
return EC_SUCCESS;
ccprints("[TCPC] Setting TCPM-side header to %s %s",
- from_pd_power_role(power_role),
- from_pd_data_role(data_role));
+ from_pd_power_role(power_role), from_pd_data_role(data_role));
return EC_SUCCESS;
}
@@ -141,8 +140,8 @@ static int mock_get_message_raw(int port, uint32_t *payload, int *head)
return EC_SUCCESS;
}
-static int mock_transmit(int port, enum tcpci_msg_type type,
- uint16_t header, const uint32_t *data)
+static int mock_transmit(int port, enum tcpci_msg_type type, uint16_t header,
+ const uint32_t *data)
{
return EC_SUCCESS;
}
diff --git a/common/mock/tcpci_i2c_mock.c b/common/mock/tcpci_i2c_mock.c
index c9b9f71738..a0e59ecc44 100644
--- a/common/mock/tcpci_i2c_mock.c
+++ b/common/mock/tcpci_i2c_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -18,15 +18,19 @@
#define VERIFY_TIMEOUT (5 * SECOND)
struct tcpci_reg {
- uint8_t offset;
- uint8_t size;
- uint16_t value;
- const char *name;
+ uint8_t offset;
+ uint8_t size;
+ uint16_t value;
+ const char *name;
};
-#define TCPCI_REG(reg_name, reg_size) \
- [reg_name] = { .offset = (reg_name), .size = (reg_size), \
- .value = 0, .name = #reg_name, }
+#define TCPCI_REG(reg_name, reg_size) \
+ [reg_name] = { \
+ .offset = (reg_name), \
+ .size = (reg_size), \
+ .value = 0, \
+ .name = #reg_name, \
+ }
static struct tcpci_reg tcpci_regs[] = {
TCPCI_REG(TCPC_REG_VENDOR_ID, 2),
@@ -76,111 +80,109 @@ static int tx_retry_cnt = -1;
static uint8_t rx_buffer[BUFFER_SIZE];
static int rx_pos = -1;
-static const char * const ctrl_msg_name[] = {
- [0] = "C-RSVD_0",
- [PD_CTRL_GOOD_CRC] = "C-GOODCRC",
- [PD_CTRL_GOTO_MIN] = "C-GOTOMIN",
- [PD_CTRL_ACCEPT] = "C-ACCEPT",
- [PD_CTRL_REJECT] = "C-REJECT",
- [PD_CTRL_PING] = "C-PING",
- [PD_CTRL_PS_RDY] = "C-PSRDY",
- [PD_CTRL_GET_SOURCE_CAP] = "C-GET_SRC_CAP",
- [PD_CTRL_GET_SINK_CAP] = "C-GET_SNK_CAP",
- [PD_CTRL_DR_SWAP] = "C-DR_SWAP",
- [PD_CTRL_PR_SWAP] = "C-PR_SWAP",
- [PD_CTRL_VCONN_SWAP] = "C-VCONN_SW",
- [PD_CTRL_WAIT] = "C-WAIT",
- [PD_CTRL_SOFT_RESET] = "C-SOFT-RESET",
- [14] = "C-RSVD_14",
- [15] = "C-RSVD_15",
- [PD_CTRL_NOT_SUPPORTED] = "C-NOT_SUPPORTED",
- [PD_CTRL_GET_SOURCE_CAP_EXT] = "C-GET_SRC_CAP-EXT",
- [PD_CTRL_GET_STATUS] = "C-GET-STATUS",
- [PD_CTRL_FR_SWAP] = "C-FR_SWAP",
- [PD_CTRL_GET_PPS_STATUS] = "C-GET_PPS_STATUS",
- [PD_CTRL_GET_COUNTRY_CODES] = "C-GET_COUNTRY_CODES",
- [PD_CTRL_GET_SINK_CAP_EXT] = "C-GET_SINK_CAP_EXT",
- [PD_CTRL_GET_SOURCE_INFO] = "C-GET_SOURCE_INFO",
- [PD_CTRL_GET_REVISION] = "C-GET_REVISION",
+static const char *const ctrl_msg_name[] = {
+ [0] = "C-RSVD_0",
+ [PD_CTRL_GOOD_CRC] = "C-GOODCRC",
+ [PD_CTRL_GOTO_MIN] = "C-GOTOMIN",
+ [PD_CTRL_ACCEPT] = "C-ACCEPT",
+ [PD_CTRL_REJECT] = "C-REJECT",
+ [PD_CTRL_PING] = "C-PING",
+ [PD_CTRL_PS_RDY] = "C-PSRDY",
+ [PD_CTRL_GET_SOURCE_CAP] = "C-GET_SRC_CAP",
+ [PD_CTRL_GET_SINK_CAP] = "C-GET_SNK_CAP",
+ [PD_CTRL_DR_SWAP] = "C-DR_SWAP",
+ [PD_CTRL_PR_SWAP] = "C-PR_SWAP",
+ [PD_CTRL_VCONN_SWAP] = "C-VCONN_SW",
+ [PD_CTRL_WAIT] = "C-WAIT",
+ [PD_CTRL_SOFT_RESET] = "C-SOFT-RESET",
+ [14] = "C-RSVD_14",
+ [15] = "C-RSVD_15",
+ [PD_CTRL_NOT_SUPPORTED] = "C-NOT_SUPPORTED",
+ [PD_CTRL_GET_SOURCE_CAP_EXT] = "C-GET_SRC_CAP-EXT",
+ [PD_CTRL_GET_STATUS] = "C-GET-STATUS",
+ [PD_CTRL_FR_SWAP] = "C-FR_SWAP",
+ [PD_CTRL_GET_PPS_STATUS] = "C-GET_PPS_STATUS",
+ [PD_CTRL_GET_COUNTRY_CODES] = "C-GET_COUNTRY_CODES",
+ [PD_CTRL_GET_SINK_CAP_EXT] = "C-GET_SINK_CAP_EXT",
+ [PD_CTRL_GET_SOURCE_INFO] = "C-GET_SOURCE_INFO",
+ [PD_CTRL_GET_REVISION] = "C-GET_REVISION",
};
-static const char * const data_msg_name[] = {
- [0] = "D-RSVD_0",
- [PD_DATA_SOURCE_CAP] = "D-SRC_CAP",
- [PD_DATA_REQUEST] = "D-REQUEST",
- [PD_DATA_BIST] = "D-BIST",
- [PD_DATA_SINK_CAP] = "D-SNK_CAP",
+static const char *const data_msg_name[] = {
+ [0] = "D-RSVD_0",
+ [PD_DATA_SOURCE_CAP] = "D-SRC_CAP",
+ [PD_DATA_REQUEST] = "D-REQUEST",
+ [PD_DATA_BIST] = "D-BIST",
+ [PD_DATA_SINK_CAP] = "D-SNK_CAP",
/* 5-14 Reserved for REV 2.0 */
- [PD_DATA_BATTERY_STATUS] = "D-BATTERY_STATUS",
- [PD_DATA_ALERT] = "D-ALERT",
- [PD_DATA_GET_COUNTRY_INFO] = "D-GET_COUNTRY_CODES",
+ [PD_DATA_BATTERY_STATUS] = "D-BATTERY_STATUS",
+ [PD_DATA_ALERT] = "D-ALERT",
+ [PD_DATA_GET_COUNTRY_INFO] = "D-GET_COUNTRY_CODES",
/* 8-14 Reserved for REV 3.0 */
- [PD_DATA_ENTER_USB] = "D-ENTER_USB",
- [PD_DATA_EPR_REQUEST] = "D-EPR_REQUEST",
- [PD_DATA_EPR_MODE] = "D-EPR_MODE",
- [PD_DATA_SOURCE_INFO] = "D-EPR_SOURCE_INFO",
- [PD_DATA_REVISION] = "D-REVISION",
+ [PD_DATA_ENTER_USB] = "D-ENTER_USB",
+ [PD_DATA_EPR_REQUEST] = "D-EPR_REQUEST",
+ [PD_DATA_EPR_MODE] = "D-EPR_MODE",
+ [PD_DATA_SOURCE_INFO] = "D-EPR_SOURCE_INFO",
+ [PD_DATA_REVISION] = "D-REVISION",
/* 13-14 Reserved for REV 3.0 */
- [PD_DATA_VENDOR_DEF] = "D-VDM",
+ [PD_DATA_VENDOR_DEF] = "D-VDM",
};
-static const char * const ext_msg_name[] = {
- [0] = "X-RSVD_0",
- [PD_EXT_SOURCE_CAP] = "X-SRC_CAP",
- [PD_EXT_STATUS] = "X-STATUS",
- [PD_EXT_GET_BATTERY_CAP] = "X-GET_BATTERY_CAP",
- [PD_EXT_GET_BATTERY_STATUS] = "X-GET_BATTERY_STATUS",
- [PD_EXT_BATTERY_CAP] = "X-BATTERY_CAP",
- [PD_EXT_GET_MANUFACTURER_INFO] = "X-GET_MFR_INFO",
- [PD_EXT_MANUFACTURER_INFO] = "X-MFR_INFO",
- [PD_EXT_SECURITY_REQUEST] = "X-SECURITY_REQ",
- [PD_EXT_SECURITY_RESPONSE] = "X-SECURITY_RESP",
+static const char *const ext_msg_name[] = {
+ [0] = "X-RSVD_0",
+ [PD_EXT_SOURCE_CAP] = "X-SRC_CAP",
+ [PD_EXT_STATUS] = "X-STATUS",
+ [PD_EXT_GET_BATTERY_CAP] = "X-GET_BATTERY_CAP",
+ [PD_EXT_GET_BATTERY_STATUS] = "X-GET_BATTERY_STATUS",
+ [PD_EXT_BATTERY_CAP] = "X-BATTERY_CAP",
+ [PD_EXT_GET_MANUFACTURER_INFO] = "X-GET_MFR_INFO",
+ [PD_EXT_MANUFACTURER_INFO] = "X-MFR_INFO",
+ [PD_EXT_SECURITY_REQUEST] = "X-SECURITY_REQ",
+ [PD_EXT_SECURITY_RESPONSE] = "X-SECURITY_RESP",
[PD_EXT_FIRMWARE_UPDATE_REQUEST] = "X-FW_UP_REQ",
[PD_EXT_FIRMWARE_UPDATE_RESPONSE] = "X-FW_UP_RESP",
- [PD_EXT_PPS_STATUS] = "X-PPS_STATUS",
- [PD_EXT_COUNTRY_INFO] = "X-COUNTRY_INFO",
- [PD_EXT_COUNTRY_CODES] = "X-COUNTRY_CODES",
- [PD_EXT_SINK_CAP] = "X-SNK_CAP",
- [PD_EXT_CONTROL] = "X-CONTROL",
- [PD_EXT_EPR_SOURCE_CAP] = "X-EPR_SRC_CAP",
- [PD_EXT_EPR_SINK_CAP] = "X-EPR_SNK_CAP",
+ [PD_EXT_PPS_STATUS] = "X-PPS_STATUS",
+ [PD_EXT_COUNTRY_INFO] = "X-COUNTRY_INFO",
+ [PD_EXT_COUNTRY_CODES] = "X-COUNTRY_CODES",
+ [PD_EXT_SINK_CAP] = "X-SNK_CAP",
+ [PD_EXT_CONTROL] = "X-CONTROL",
+ [PD_EXT_EPR_SOURCE_CAP] = "X-EPR_SRC_CAP",
+ [PD_EXT_EPR_SINK_CAP] = "X-EPR_SNK_CAP",
};
-static const char * const rev_name[] = {
+static const char *const rev_name[] = {
[PD_REV10] = "1.0",
[PD_REV20] = "2.0",
[PD_REV30] = "3.0",
[3] = "RSVD",
};
-static const char * const drole_name[] = {
+static const char *const drole_name[] = {
[PD_ROLE_UFP] = "UFP",
[PD_ROLE_DFP] = "DFP",
};
-static const char * const prole_name[] = {
+static const char *const prole_name[] = {
[PD_ROLE_SINK] = "SNK",
[PD_ROLE_SOURCE] = "SRC",
};
static void print_header(const char *prefix, uint16_t header)
{
- int type = PD_HEADER_TYPE(header);
+ int type = PD_HEADER_TYPE(header);
int drole = PD_HEADER_DROLE(header);
- int rev = PD_HEADER_REV(header);
+ int rev = PD_HEADER_REV(header);
int prole = PD_HEADER_PROLE(header);
- int id = PD_HEADER_ID(header);
- int cnt = PD_HEADER_CNT(header);
- int ext = PD_HEADER_EXT(header);
- const char *name = ext ? ext_msg_name[type]
- : cnt
- ? data_msg_name[type]
- : ctrl_msg_name[type];
-
- ccprints("%s header=0x%x [%s %s %s %s id=%d cnt=%d ext=%d]",
- prefix, header,
- name, drole_name[drole], rev_name[rev], prole_name[prole],
- id, cnt, ext);
+ int id = PD_HEADER_ID(header);
+ int cnt = PD_HEADER_CNT(header);
+ int ext = PD_HEADER_EXT(header);
+ const char *name = ext ? ext_msg_name[type] :
+ cnt ? data_msg_name[type] :
+ ctrl_msg_name[type];
+
+ ccprints("%s header=0x%x [%s %s %s %s id=%d cnt=%d ext=%d]", prefix,
+ header, name, drole_name[drole], rev_name[rev],
+ prole_name[prole], id, cnt, ext);
}
static bool dead_battery(void)
@@ -193,11 +195,9 @@ static bool debug_accessory_indicator_supported(void)
return true;
}
-static int verify_transmit(enum tcpci_msg_type want_tx_type,
- int want_tx_retry,
+static int verify_transmit(enum tcpci_msg_type want_tx_type, int want_tx_retry,
enum pd_ctrl_msg_type want_ctrl_msg,
- enum pd_data_msg_type want_data_msg,
- int timeout)
+ enum pd_data_msg_type want_data_msg, int timeout)
{
uint64_t end_time = get_time().val + timeout;
@@ -215,10 +215,10 @@ static int verify_transmit(enum tcpci_msg_type want_tx_type,
tcpci_regs[TCPC_REG_TRANSMIT].value);
int tx_retry = TCPC_REG_TRANSMIT_RETRY(
tcpci_regs[TCPC_REG_TRANSMIT].value);
- uint16_t header = UINT16_FROM_BYTE_ARRAY_LE(
- tx_buffer, 1);
- int pd_type = PD_HEADER_TYPE(header);
- int pd_cnt = PD_HEADER_CNT(header);
+ uint16_t header =
+ UINT16_FROM_BYTE_ARRAY_LE(tx_buffer, 1);
+ int pd_type = PD_HEADER_TYPE(header);
+ int pd_cnt = PD_HEADER_CNT(header);
TEST_EQ(tx_type, want_tx_type, "%d");
if (want_tx_retry >= 0)
@@ -246,46 +246,34 @@ int verify_tcpci_transmit(enum tcpci_msg_type tx_type,
enum pd_ctrl_msg_type ctrl_msg,
enum pd_data_msg_type data_msg)
{
- return verify_transmit(tx_type, -1,
- ctrl_msg, data_msg,
- VERIFY_TIMEOUT);
+ return verify_transmit(tx_type, -1, ctrl_msg, data_msg, VERIFY_TIMEOUT);
}
int verify_tcpci_tx_timeout(enum tcpci_msg_type tx_type,
enum pd_ctrl_msg_type ctrl_msg,
- enum pd_data_msg_type data_msg,
- int timeout)
+ enum pd_data_msg_type data_msg, int timeout)
{
- return verify_transmit(tx_type, -1,
- ctrl_msg, data_msg,
- timeout);
+ return verify_transmit(tx_type, -1, ctrl_msg, data_msg, timeout);
}
int verify_tcpci_tx_retry_count(enum tcpci_msg_type tx_type,
enum pd_ctrl_msg_type ctrl_msg,
- enum pd_data_msg_type data_msg,
- int retry_count)
+ enum pd_data_msg_type data_msg, int retry_count)
{
- return verify_transmit(tx_type, retry_count,
- ctrl_msg, data_msg,
+ return verify_transmit(tx_type, retry_count, ctrl_msg, data_msg,
VERIFY_TIMEOUT);
}
int verify_tcpci_tx_with_data(enum tcpci_msg_type tx_type,
- enum pd_data_msg_type data_msg,
- uint8_t *data,
- int data_bytes,
- int *msg_len,
- int timeout)
+ enum pd_data_msg_type data_msg, uint8_t *data,
+ int data_bytes, int *msg_len, int timeout)
{
int rv;
if (timeout <= 0)
timeout = VERIFY_TIMEOUT;
- rv = verify_transmit(tx_type, -1,
- 0, data_msg,
- timeout);
+ rv = verify_transmit(tx_type, -1, 0, data_msg, timeout);
if (!rv) {
TEST_NE(data, NULL, "%p");
TEST_GE(data_bytes, tx_msg_cnt, "%d");
@@ -296,13 +284,9 @@ int verify_tcpci_tx_with_data(enum tcpci_msg_type tx_type,
return rv;
}
-int verify_tcpci_possible_tx(struct possible_tx possible[],
- int possible_cnt,
- int *found_index,
- uint8_t *data,
- int data_bytes,
- int *msg_len,
- int timeout)
+int verify_tcpci_possible_tx(struct possible_tx possible[], int possible_cnt,
+ int *found_index, uint8_t *data, int data_bytes,
+ int *msg_len, int timeout)
{
bool assert_on_timeout = true;
uint64_t end_time;
@@ -328,10 +312,10 @@ int verify_tcpci_possible_tx(struct possible_tx possible[],
int i;
int tx_type = TCPC_REG_TRANSMIT_TYPE(
tcpci_regs[TCPC_REG_TRANSMIT].value);
- uint16_t header = UINT16_FROM_BYTE_ARRAY_LE(
- tx_buffer, 1);
- int pd_type = PD_HEADER_TYPE(header);
- int pd_cnt = PD_HEADER_CNT(header);
+ uint16_t header =
+ UINT16_FROM_BYTE_ARRAY_LE(tx_buffer, 1);
+ int pd_type = PD_HEADER_TYPE(header);
+ int pd_cnt = PD_HEADER_CNT(header);
for (i = 0; i < possible_cnt; ++i) {
int want_tx_type = possible[i].tx_type;
@@ -352,8 +336,8 @@ int verify_tcpci_possible_tx(struct possible_tx possible[],
continue;
if (data != NULL) {
- TEST_GE(data_bytes,
- tx_msg_cnt, "%d");
+ TEST_GE(data_bytes, tx_msg_cnt,
+ "%d");
memcpy(data, tx_buffer,
tx_msg_cnt);
}
@@ -391,9 +375,9 @@ void mock_tcpci_receive(enum tcpci_msg_type sop, uint16_t header,
for (i = 4; i < rx_buffer[0]; i += 4) {
rx_buffer[i] = *payload & 0xFF;
- rx_buffer[i+1] = (*payload >> 8) & 0xFF;
- rx_buffer[i+2] = (*payload >> 16) & 0xFF;
- rx_buffer[i+3] = (*payload >> 24) & 0xFF;
+ rx_buffer[i + 1] = (*payload >> 8) & 0xFF;
+ rx_buffer[i + 2] = (*payload >> 16) & 0xFF;
+ rx_buffer[i + 3] = (*payload >> 24) & 0xFF;
payload++;
}
@@ -411,11 +395,11 @@ static void tcpci_reset_register_masks(void)
/*
* Using table 4-1 for default mask values
*/
- tcpci_regs[TCPC_REG_ALERT_MASK].value = 0x7FFF;
- tcpci_regs[TCPC_REG_POWER_STATUS_MASK].value = 0xFF;
- tcpci_regs[TCPC_REG_FAULT_STATUS_MASK].value = 0xFF;
- tcpci_regs[TCPC_REG_EXT_STATUS_MASK].value = 0x01;
- tcpci_regs[TCPC_REG_ALERT_EXTENDED_MASK].value = 0x07;
+ tcpci_regs[TCPC_REG_ALERT_MASK].value = 0x7FFF;
+ tcpci_regs[TCPC_REG_POWER_STATUS_MASK].value = 0xFF;
+ tcpci_regs[TCPC_REG_FAULT_STATUS_MASK].value = 0xFF;
+ tcpci_regs[TCPC_REG_EXT_STATUS_MASK].value = 0x01;
+ tcpci_regs[TCPC_REG_ALERT_EXTENDED_MASK].value = 0x07;
}
static void tcpci_reset_register_defaults(void)
@@ -427,69 +411,68 @@ static void tcpci_reset_register_defaults(void)
tcpci_regs[i].value = 0;
/* Type-C Release 1,3 */
- tcpci_regs[TCPC_REG_TC_REV].value = 0x0013;
+ tcpci_regs[TCPC_REG_TC_REV].value = 0x0013;
/* PD Revision 3.0 Version 1.2 */
- tcpci_regs[TCPC_REG_PD_REV].value = 0x3012;
+ tcpci_regs[TCPC_REG_PD_REV].value = 0x3012;
/* PD Interface Revision 2.0, Version 1.1 */
- tcpci_regs[TCPC_REG_PD_INT_REV].value = 0x2011;
+ tcpci_regs[TCPC_REG_PD_INT_REV].value = 0x2011;
tcpci_reset_register_masks();
tcpci_regs[TCPC_REG_CONFIG_STD_OUTPUT].value =
- TCPC_REG_CONFIG_STD_OUTPUT_AUDIO_CONN_N |
- TCPC_REG_CONFIG_STD_OUTPUT_DBG_ACC_CONN_N;
+ TCPC_REG_CONFIG_STD_OUTPUT_AUDIO_CONN_N |
+ TCPC_REG_CONFIG_STD_OUTPUT_DBG_ACC_CONN_N;
tcpci_regs[TCPC_REG_POWER_CTRL].value =
- TCPC_REG_POWER_CTRL_VOLT_ALARM_DIS |
- TCPC_REG_POWER_CTRL_VBUS_VOL_MONITOR_DIS;
+ TCPC_REG_POWER_CTRL_VOLT_ALARM_DIS |
+ TCPC_REG_POWER_CTRL_VBUS_VOL_MONITOR_DIS;
tcpci_regs[TCPC_REG_FAULT_STATUS].value =
- TCPC_REG_FAULT_STATUS_ALL_REGS_RESET;
+ TCPC_REG_FAULT_STATUS_ALL_REGS_RESET;
tcpci_regs[TCPC_REG_DEV_CAP_1].value =
- TCPC_REG_DEV_CAP_1_SOURCE_VBUS |
- TCPC_REG_DEV_CAP_1_SINK_VBUS |
- TCPC_REG_DEV_CAP_1_PWRROLE_SRC_SNK_DRP |
- TCPC_REG_DEV_CAP_1_SRC_RESISTOR_RP_3P0_1P5_DEF;
+ TCPC_REG_DEV_CAP_1_SOURCE_VBUS | TCPC_REG_DEV_CAP_1_SINK_VBUS |
+ TCPC_REG_DEV_CAP_1_PWRROLE_SRC_SNK_DRP |
+ TCPC_REG_DEV_CAP_1_SRC_RESISTOR_RP_3P0_1P5_DEF;
/*
* Using table 4-17 to get the default Role Control and
* Message Header Info register values.
*/
switch (mock_tcpci_get_reg(TCPC_REG_DEV_CAP_1) &
- TCPC_REG_DEV_CAP_1_PWRROLE_MASK) {
+ TCPC_REG_DEV_CAP_1_PWRROLE_MASK) {
case TCPC_REG_DEV_CAP_1_PWRROLE_SRC_OR_SNK:
case TCPC_REG_DEV_CAP_1_PWRROLE_SNK:
case TCPC_REG_DEV_CAP_1_PWRROLE_SNK_ACC:
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0A;
- tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x04;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0A;
+ tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x04;
break;
case TCPC_REG_DEV_CAP_1_PWRROLE_DRP:
if (dead_battery())
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0A;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0A;
else if (debug_accessory_indicator_supported())
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x4A;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x4A;
else
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0F;
- tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x04;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0F;
+ tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x04;
break;
case TCPC_REG_DEV_CAP_1_PWRROLE_SRC:
if (!dead_battery())
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x05;
- tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x0D;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x05;
+ tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x0D;
break;
case TCPC_REG_DEV_CAP_1_PWRROLE_SRC_SNK_DRP_ADPT_CBL:
case TCPC_REG_DEV_CAP_1_PWRROLE_SRC_SNK_DRP:
if (dead_battery())
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0A;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0A;
else if (debug_accessory_indicator_supported())
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x4A;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x4A;
else
- tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0F;
- tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x04;
+ tcpci_regs[TCPC_REG_ROLE_CTRL].value = 0x0F;
+ tcpci_regs[TCPC_REG_MSG_HDR_INFO].value = 0x04;
break;
}
}
@@ -505,7 +488,7 @@ void mock_tcpci_set_reg(int reg_offset, uint16_t value)
struct tcpci_reg *reg = tcpci_regs + reg_offset;
reg->value = value;
- ccprints("TCPCI mock set %s = 0x%x", reg->name, reg->value);
+ ccprints("TCPCI mock set %s = 0x%x", reg->name, reg->value);
}
void mock_tcpci_set_reg_bits(int reg_offset, uint16_t mask)
@@ -514,8 +497,8 @@ void mock_tcpci_set_reg_bits(int reg_offset, uint16_t mask)
uint16_t old_value = reg->value;
reg->value |= mask;
- ccprints("TCPCI mock set bits %s (mask=0x%x) = 0x%x -> 0x%x",
- reg->name, mask, old_value, reg->value);
+ ccprints("TCPCI mock set bits %s (mask=0x%x) = 0x%x -> 0x%x", reg->name,
+ mask, old_value, reg->value);
}
void mock_tcpci_clr_reg_bits(int reg_offset, uint16_t mask)
@@ -524,8 +507,8 @@ void mock_tcpci_clr_reg_bits(int reg_offset, uint16_t mask)
uint16_t old_value = reg->value;
reg->value &= ~mask;
- ccprints("TCPCI mock clr bits %s (mask=0x%x) = 0x%x -> 0x%x",
- reg->name, mask, old_value, reg->value);
+ ccprints("TCPCI mock clr bits %s (mask=0x%x) = 0x%x -> 0x%x", reg->name,
+ mask, old_value, reg->value);
}
uint16_t mock_tcpci_get_reg(int reg_offset)
@@ -533,9 +516,8 @@ uint16_t mock_tcpci_get_reg(int reg_offset)
return tcpci_regs[reg_offset].value;
}
-int tcpci_i2c_xfer(int port, uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+int tcpci_i2c_xfer(int port, uint16_t addr_flags, const uint8_t *out,
+ int out_size, uint8_t *in, int in_size, int flags)
{
struct tcpci_reg *reg;
@@ -554,10 +536,10 @@ int tcpci_i2c_xfer(int port, uint16_t addr_flags,
return EC_ERROR_UNKNOWN;
}
memcpy(in, rx_buffer + rx_pos, in_size);
- rx_pos += in_size;
+ rx_pos += in_size;
if (rx_pos == rx_buffer[0] + 1) {
- print_header("RX", UINT16_FROM_BYTE_ARRAY_LE(
- rx_buffer, 2));
+ print_header("RX",
+ UINT16_FROM_BYTE_ARRAY_LE(rx_buffer, 2));
rx_pos = -1;
}
return EC_SUCCESS;
@@ -576,8 +558,8 @@ int tcpci_i2c_xfer(int port, uint16_t addr_flags,
tx_pos += out_size;
tx_msg_cnt = tx_pos;
if (tx_pos > 0 && tx_pos == tx_buffer[0] + 1) {
- print_header("TX", UINT16_FROM_BYTE_ARRAY_LE(
- tx_buffer, 1));
+ print_header("TX",
+ UINT16_FROM_BYTE_ARRAY_LE(tx_buffer, 1));
tx_pos = -1;
tx_retry_cnt = -1;
}
@@ -638,8 +620,7 @@ int tcpci_i2c_xfer(int port, uint16_t addr_flags,
else if (reg->size == 2)
value = out[1] + (out[2] << 8);
ccprints("%s TCPCI write %s = 0x%x",
- task_get_name(task_get_current()),
- reg->name, value);
+ task_get_name(task_get_current()), reg->name, value);
if (reg->offset == TCPC_REG_ALERT)
reg->value &= ~value;
else
diff --git a/common/mock/tcpm_mock.c b/common/mock/tcpm_mock.c
index 2c212cf8c9..a54b31839b 100644
--- a/common/mock/tcpm_mock.c
+++ b/common/mock/tcpm_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -31,7 +31,7 @@ int tcpm_dequeue_message(int port, uint32_t *payload, int *header)
*header = mock_tcpm[port].mock_header;
memcpy(payload, mock_tcpm[port].mock_rx_chk_buf,
- sizeof(mock_tcpm[port].mock_rx_chk_buf));
+ sizeof(mock_tcpm[port].mock_rx_chk_buf));
return EC_SUCCESS;
}
@@ -51,7 +51,7 @@ void mock_tcpm_reset(void)
{
int port;
- for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port)
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port)
mock_tcpm[port].mock_has_pending_message = 0;
}
@@ -65,7 +65,7 @@ void mock_tcpm_rx_msg(int port, uint16_t header, int cnt, const uint32_t *data)
if (cnt > 0) {
int idx;
- for (idx = 0 ; (idx < cnt) && (idx < MOCK_CHK_BUF_SIZE) ; ++idx)
+ for (idx = 0; (idx < cnt) && (idx < MOCK_CHK_BUF_SIZE); ++idx)
mock_tcpm[port].mock_rx_chk_buf[idx] = data[idx];
}
mock_tcpm[port].mock_has_pending_message = 1;
diff --git a/common/mock/timer_mock.c b/common/mock/timer_mock.c
index dc83aa24d5..0504578412 100644
--- a/common/mock/timer_mock.c
+++ b/common/mock/timer_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 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/common/mock/usb_mux_mock.c b/common/mock/usb_mux_mock.c
index f2db5cf8bd..815cdf777c 100644
--- a/common/mock/usb_mux_mock.c
+++ b/common/mock/usb_mux_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 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/common/mock/usb_pd_dpm_mock.c b/common/mock/usb_pd_dpm_mock.c
index 005e0090a6..158c53c650 100644
--- a/common/mock/usb_pd_dpm_mock.c
+++ b/common/mock/usb_pd_dpm_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -36,12 +36,12 @@ void dpm_mode_exit_complete(int port)
}
void dpm_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
- uint32_t *vdm)
+ uint32_t *vdm)
{
}
void dpm_vdm_naked(int port, enum tcpci_msg_type type, uint16_t svid,
- uint8_t vdm_cmd)
+ uint8_t vdm_cmd)
{
}
@@ -73,6 +73,14 @@ void dpm_remove_source(int port)
{
}
+void dpm_bist_shared_mode_enter(int port)
+{
+}
+
+void dpm_bist_shared_mode_exit(int port)
+{
+}
+
int dpm_get_source_pdo(const uint32_t **src_pdo, const int port)
{
*src_pdo = pd_src_pdo;
@@ -83,3 +91,7 @@ int dpm_get_status_msg(int port, uint8_t *msg, uint32_t *len)
{
return EC_SUCCESS;
}
+
+void dpm_handle_alert(int port, uint32_t ado)
+{
+}
diff --git a/common/mock/usb_pe_sm_mock.c b/common/mock/usb_pe_sm_mock.c
index 8d1a25324b..24861a73f9 100644
--- a/common/mock/usb_pe_sm_mock.c
+++ b/common/mock/usb_pe_sm_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,7 +23,6 @@
struct mock_pe_port_t mock_pe_port[CONFIG_USB_PD_PORT_MAX_COUNT];
-
/**
* Resets all mock PE ports to initial values
*/
@@ -31,7 +30,7 @@ void mock_pe_port_reset(void)
{
int port;
- for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port) {
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port) {
mock_pe_port[port].mock_pe_error = -1;
/* These mock variable only get set to 1 by various functions,
* so initialize them to 0. Tests can verify they are still 0
@@ -93,7 +92,7 @@ bool pe_in_local_ams(int port)
return false;
}
-const uint32_t * const pd_get_src_caps(int port)
+const uint32_t *const pd_get_src_caps(int port)
{
return NULL;
}
@@ -108,7 +107,8 @@ void pd_set_src_caps(int port, int cnt, uint32_t *src_caps)
}
void pd_request_power_swap(int port)
-{}
+{
+}
int pd_get_rev(int port, enum tcpci_msg_type type)
{
diff --git a/common/mock/usb_prl_mock.c b/common/mock/usb_prl_mock.c
index d5f4781829..df61cfaf95 100644
--- a/common/mock/usb_prl_mock.c
+++ b/common/mock/usb_prl_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -45,14 +45,15 @@ void mock_prl_reset(void)
memset(mock_prl_port, 0, sizeof(mock_prl_port));
- for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port) {
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port) {
mock_prl_port[port].last_tx_type = TCPCI_MSG_INVALID;
mock_prl_port[port].error_tx_type = TCPCI_MSG_INVALID;
}
}
void prl_end_ams(int port)
-{}
+{
+}
void prl_execute_hard_reset(int port)
{
@@ -67,7 +68,8 @@ enum pd_rev_type prl_get_rev(int port, enum tcpci_msg_type partner)
}
void prl_hard_reset_complete(int port)
-{}
+{
+}
int prl_is_running(int port)
{
@@ -80,10 +82,11 @@ __overridable bool prl_is_busy(int port)
}
void prl_reset_soft(int port)
-{}
+{
+}
void prl_send_ctrl_msg(int port, enum tcpci_msg_type type,
- enum pd_ctrl_msg_type msg)
+ enum pd_ctrl_msg_type msg)
{
mock_prl_port[port].last_ctrl_msg = msg;
mock_prl_port[port].last_data_msg = 0;
@@ -91,7 +94,7 @@ void prl_send_ctrl_msg(int port, enum tcpci_msg_type type,
}
void prl_send_data_msg(int port, enum tcpci_msg_type type,
- enum pd_data_msg_type msg)
+ enum pd_data_msg_type msg)
{
mock_prl_port[port].last_data_msg = msg;
mock_prl_port[port].last_ctrl_msg = 0;
@@ -99,30 +102,28 @@ void prl_send_data_msg(int port, enum tcpci_msg_type type,
}
void prl_send_ext_data_msg(int port, enum tcpci_msg_type type,
- enum pd_ext_msg_type msg)
-{}
-
-void prl_set_rev(int port, enum tcpci_msg_type partner,
- enum pd_rev_type rev)
-{}
+ enum pd_ext_msg_type msg)
+{
+}
+void prl_set_rev(int port, enum tcpci_msg_type partner, enum pd_rev_type rev)
+{
+}
-int mock_prl_wait_for_tx_msg(int port,
- enum tcpci_msg_type tx_type,
+int mock_prl_wait_for_tx_msg(int port, enum tcpci_msg_type tx_type,
enum pd_ctrl_msg_type ctrl_msg,
- enum pd_data_msg_type data_msg,
- int timeout)
+ enum pd_data_msg_type data_msg, int timeout)
{
uint64_t end_time = get_time().val + timeout;
while (get_time().val < end_time) {
if (mock_prl_port[port].last_tx_type != TCPCI_MSG_INVALID) {
- TEST_EQ(mock_prl_port[port].last_tx_type,
- tx_type, "%d");
- TEST_EQ(mock_prl_port[port].last_ctrl_msg,
- ctrl_msg, "%d");
- TEST_EQ(mock_prl_port[port].last_data_msg,
- data_msg, "%d");
+ TEST_EQ(mock_prl_port[port].last_tx_type, tx_type,
+ "%d");
+ TEST_EQ(mock_prl_port[port].last_ctrl_msg, ctrl_msg,
+ "%d");
+ TEST_EQ(mock_prl_port[port].last_data_msg, data_msg,
+ "%d");
mock_prl_clear_last_sent_msg(port);
return EC_SUCCESS;
}
@@ -191,8 +192,7 @@ void prl_run(int port, int evt, int en)
}
if (mock_prl_port[port].error_tx_type != TCPCI_MSG_INVALID) {
ccprints("pe_error %d", mock_prl_port[port].error);
- pe_report_error(port,
- mock_prl_port[port].error,
+ pe_report_error(port, mock_prl_port[port].error,
mock_prl_port[port].error_tx_type);
mock_prl_port[port].error = 0;
mock_prl_port[port].error_tx_type = TCPCI_MSG_INVALID;
diff --git a/common/mock/usb_tc_sm_mock.c b/common/mock/usb_tc_sm_mock.c
index d55def12e2..5badc6eba6 100644
--- a/common/mock/usb_tc_sm_mock.c
+++ b/common/mock/usb_tc_sm_mock.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -26,7 +26,7 @@ void mock_tc_port_reset(void)
{
int port;
- for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port) {
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port) {
mock_tc_port[port].rev = PD_REV30;
mock_tc_port[port].pd_enable = 0;
mock_tc_port[port].msg_tx_id = 0;
@@ -93,7 +93,8 @@ int tc_check_vconn_swap(int port)
}
void tc_ctvpd_detected(int port)
-{}
+{
+}
int tc_is_vconn_src(int port)
{
@@ -106,31 +107,40 @@ void tc_hard_reset_request(int port)
}
void tc_partner_dr_data(int port, int en)
-{}
+{
+}
void tc_partner_dr_power(int port, int en)
-{}
+{
+}
void tc_partner_unconstrainedpower(int port, int en)
-{}
+{
+}
void tc_partner_usb_comm(int port, int en)
-{}
+{
+}
void tc_pd_connection(int port, int en)
-{}
+{
+}
void tc_pr_swap_complete(int port, bool success)
-{}
+{
+}
void tc_src_power_off(int port)
-{}
+{
+}
void tc_start_error_recovery(int port)
-{}
+{
+}
void tc_snk_power_off(int port)
-{}
+{
+}
void tc_request_power_swap(int port)
{
@@ -200,13 +210,16 @@ enum tcpc_cc_polarity pd_get_polarity(int port)
}
void pd_request_data_swap(int port)
-{}
+{
+}
void pd_request_vconn_swap_off(int port)
-{}
+{
+}
void pd_request_vconn_swap_on(int port)
-{}
+{
+}
bool pd_alt_mode_capable(int port)
{
diff --git a/common/motion_lid.c b/common/motion_lid.c
index 4e76bebb66..1a254e786d 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -26,8 +26,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_MOTION_LID, outstr)
-#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ##args)
#ifdef CONFIG_TABLET_MODE
/* Previous lid_angle. */
@@ -50,7 +50,7 @@ static int lid_angle_is_reliable;
static intv3_t smoothed_base, smoothed_lid;
/* 8.7 m/s^2 is the the maximum acceleration parallel to the hinge */
-#define SCALED_HINGE_VERTICAL_MAXIMUM \
+#define SCALED_HINGE_VERTICAL_MAXIMUM \
((int)((8.7f * MOTION_SCALING_FACTOR) / MOTION_ONE_G))
#define SCALED_HINGE_VERTICAL_SMOOTHING_START \
@@ -88,21 +88,21 @@ static intv3_t smoothed_base, smoothed_lid;
* frame before calculating lid angle).
*/
#ifdef CONFIG_ACCEL_STD_REF_FRAME_OLD
-static const intv3_t hinge_axis = { 0, 1, 0};
+static const intv3_t hinge_axis = { 0, 1, 0 };
#define HINGE_AXIS Y
#else
-static const intv3_t hinge_axis = { 1, 0, 0};
+static const intv3_t hinge_axis = { 1, 0, 0 };
#define HINGE_AXIS X
#endif
-static const struct motion_sensor_t * const accel_base =
+static const struct motion_sensor_t *const accel_base =
&motion_sensors[CONFIG_LID_ANGLE_SENSOR_BASE];
-static const struct motion_sensor_t * const accel_lid =
+static const struct motion_sensor_t *const accel_lid =
&motion_sensors[CONFIG_LID_ANGLE_SENSOR_LID];
STATIC_IF(CONFIG_TABLET_MODE) void motion_lid_set_tablet_mode(int reliable);
-STATIC_IF(CONFIG_TABLET_MODE) int lid_angle_set_tablet_mode_threshold(
- int angle, int hys);
+STATIC_IF(CONFIG_TABLET_MODE)
+int lid_angle_set_tablet_mode_threshold(int angle, int hys);
STATIC_IF(CONFIG_TABLET_MODE) fp_t tablet_zone_lid_angle;
STATIC_IF(CONFIG_TABLET_MODE) fp_t laptop_zone_lid_angle;
@@ -142,18 +142,16 @@ __attribute__((weak)) int board_is_lid_angle_tablet_mode(void)
* by using MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
*/
-#define DEFAULT_TABLET_MODE_ANGLE (180)
-#define DEFAULT_TABLET_MODE_HYS (20)
+#define DEFAULT_TABLET_MODE_ANGLE (180)
+#define DEFAULT_TABLET_MODE_HYS (20)
-#define TABLET_ZONE_ANGLE(a, h) ((a) + (h))
-#define LAPTOP_ZONE_ANGLE(a, h) ((a) - (h))
+#define TABLET_ZONE_ANGLE(a, h) ((a) + (h))
+#define LAPTOP_ZONE_ANGLE(a, h) ((a) - (h))
-static fp_t tablet_zone_lid_angle =
- FLOAT_TO_FP(TABLET_ZONE_ANGLE(DEFAULT_TABLET_MODE_ANGLE,
- DEFAULT_TABLET_MODE_HYS));
-static fp_t laptop_zone_lid_angle =
- FLOAT_TO_FP(LAPTOP_ZONE_ANGLE(DEFAULT_TABLET_MODE_ANGLE,
- DEFAULT_TABLET_MODE_HYS));
+static fp_t tablet_zone_lid_angle = FLOAT_TO_FP(
+ TABLET_ZONE_ANGLE(DEFAULT_TABLET_MODE_ANGLE, DEFAULT_TABLET_MODE_HYS));
+static fp_t laptop_zone_lid_angle = FLOAT_TO_FP(
+ LAPTOP_ZONE_ANGLE(DEFAULT_TABLET_MODE_ANGLE, DEFAULT_TABLET_MODE_HYS));
static int tablet_mode_lid_angle = DEFAULT_TABLET_MODE_ANGLE;
static int tablet_mode_hys_degree = DEFAULT_TABLET_MODE_HYS;
@@ -220,8 +218,8 @@ static int lid_angle_set_tablet_mode_threshold(int angle, int hys)
#define MOTION_LID_SET_DPTF_PROFILE
#endif
-STATIC_IF(MOTION_LID_SET_DPTF_PROFILE) void motion_lid_set_dptf_profile(
- int reliable);
+STATIC_IF(MOTION_LID_SET_DPTF_PROFILE)
+void motion_lid_set_dptf_profile(int reliable);
#ifdef MOTION_LID_SET_DPTF_PROFILE
/*
@@ -322,11 +320,11 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid,
* less than 1<<30.
*/
base_magnitude2 = scaled_base[X] * scaled_base[X] +
- scaled_base[Y] * scaled_base[Y] +
- scaled_base[Z] * scaled_base[Z];
+ scaled_base[Y] * scaled_base[Y] +
+ scaled_base[Z] * scaled_base[Z];
lid_magnitude2 = scaled_lid[X] * scaled_lid[X] +
- scaled_lid[Y] * scaled_lid[Y] +
- scaled_lid[Z] * scaled_lid[Z];
+ scaled_lid[Y] * scaled_lid[Y] +
+ scaled_lid[Z] * scaled_lid[Z];
/*
* Check to see if they differ than more than NOISY_MAGNITUDE_DEVIATION.
@@ -358,14 +356,16 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid,
goto end_calculate_lid_angle;
}
- largest_hinge_accel = MAX(ABS(scaled_base[HINGE_AXIS]),
- ABS(scaled_lid[HINGE_AXIS]));
+ largest_hinge_accel =
+ MAX(ABS(scaled_base[HINGE_AXIS]), ABS(scaled_lid[HINGE_AXIS]));
- smoothed_ratio = MAX(INT_TO_FP(0), MIN(INT_TO_FP(1),
- fp_div(INT_TO_FP(largest_hinge_accel -
- SCALED_HINGE_VERTICAL_SMOOTHING_START),
- INT_TO_FP(SCALED_HINGE_VERTICAL_MAXIMUM -
- SCALED_HINGE_VERTICAL_SMOOTHING_START))));
+ smoothed_ratio = MAX(
+ INT_TO_FP(0),
+ MIN(INT_TO_FP(1),
+ fp_div(INT_TO_FP(largest_hinge_accel -
+ SCALED_HINGE_VERTICAL_SMOOTHING_START),
+ INT_TO_FP(SCALED_HINGE_VERTICAL_MAXIMUM -
+ SCALED_HINGE_VERTICAL_SMOOTHING_START))));
/* Check hinge is not too vertical */
if (largest_hinge_accel > SCALED_HINGE_VERTICAL_MAXIMUM) {
@@ -417,8 +417,7 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid,
#ifdef CONFIG_TABLET_MODE
/* Ignore large angles when the lid is closed. */
- if (!lid_is_open() &&
- (lid_to_base_fp > SMALL_LID_ANGLE_RANGE)) {
+ if (!lid_is_open() && (lid_to_base_fp > SMALL_LID_ANGLE_RANGE)) {
reliable = 0;
goto end_calculate_lid_angle;
}
@@ -434,8 +433,7 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid,
* may wake us up. This is because we require at least 4 consecutive
* reliable readings over a threshold to disable key scanning.
*/
- if (lid_is_open() &&
- (lid_to_base_fp <= SMALL_LID_ANGLE_RANGE)) {
+ if (lid_is_open() && (lid_to_base_fp <= SMALL_LID_ANGLE_RANGE)) {
reliable = 0;
goto end_calculate_lid_angle;
}
@@ -451,10 +449,8 @@ static int calculate_lid_angle(const intv3_t base, const intv3_t lid,
* prove the small angle we see is correct so we take the angle
* as is.
*/
- if ((last_lid_angle_fp >=
- FLOAT_TO_FP(360) - DEBOUNCE_ANGLE_DELTA) &&
- (lid_to_base_fp <= DEBOUNCE_ANGLE_DELTA) &&
- (lid_is_open()))
+ if ((last_lid_angle_fp >= FLOAT_TO_FP(360) - DEBOUNCE_ANGLE_DELTA) &&
+ (lid_to_base_fp <= DEBOUNCE_ANGLE_DELTA) && (lid_is_open()))
last_lid_angle_fp = FLOAT_TO_FP(360) - lid_to_base_fp;
else
last_lid_angle_fp = lid_to_base_fp;
@@ -471,7 +467,7 @@ end_calculate_lid_angle:
if (IS_ENABLED(MOTION_LID_SET_DPTF_PROFILE))
motion_lid_set_dptf_profile(reliable);
-#else /* CONFIG_TABLET_MODE */
+#else /* CONFIG_TABLET_MODE */
end_calculate_lid_angle:
if (reliable)
*lid_angle = FP_TO_INT(lid_to_base_fp + FLOAT_TO_FP(0.5));
@@ -494,8 +490,7 @@ void motion_lid_calc(void)
{
/* Calculate angle of lid accel. */
lid_angle_is_reliable = calculate_lid_angle(
- accel_base->xyz, accel_lid->xyz,
- &lid_angle_deg);
+ accel_base->xyz, accel_lid->xyz, &lid_angle_deg);
if (IS_ENABLED(CONFIG_LID_ANGLE_UPDATE))
lid_angle_update(motion_lid_get_angle());
@@ -504,7 +499,6 @@ void motion_lid_calc(void)
/*****************************************************************************/
/* Host commands */
-
enum ec_status host_cmd_motion_lid(struct host_cmd_handler_args *args)
{
const struct ec_params_motion_sense *in = args->params;
@@ -519,7 +513,7 @@ enum ec_status host_cmd_motion_lid(struct host_cmd_handler_args *args)
*/
if (in->kb_wake_angle.data != EC_MOTION_SENSE_NO_VALUE)
lid_angle_set_wake_angle(
- in->kb_wake_angle.data);
+ in->kb_wake_angle.data);
out->kb_wake_angle.ret = lid_angle_get_wake_angle();
} else {
@@ -542,8 +536,8 @@ enum ec_status host_cmd_motion_lid(struct host_cmd_handler_args *args)
if (IS_ENABLED(CONFIG_TABLET_MODE)) {
int ret;
ret = lid_angle_set_tablet_mode_threshold(
- in->tablet_mode_threshold.lid_angle,
- in->tablet_mode_threshold.hys_degree);
+ in->tablet_mode_threshold.lid_angle,
+ in->tablet_mode_threshold.hys_degree);
if (ret != EC_RES_SUCCESS)
return ret;
diff --git a/common/motion_orientation.c b/common/motion_orientation.c
index 9a20ff8499..1c52fe847e 100644
--- a/common/motion_orientation.c
+++ b/common/motion_orientation.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -18,9 +18,9 @@ static const intv3_t orientation_modes[] = {
[MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE] = { 0, 1, 0 },
};
-enum motionsensor_orientation motion_orientation_remap(
- const struct motion_sensor_t *s,
- enum motionsensor_orientation orientation)
+enum motionsensor_orientation
+motion_orientation_remap(const struct motion_sensor_t *s,
+ enum motionsensor_orientation orientation)
{
enum motionsensor_orientation rotated_orientation;
const intv3_t *orientation_v;
@@ -31,7 +31,8 @@ enum motionsensor_orientation motion_orientation_remap(
orientation_v = &orientation_modes[orientation];
rotate(*orientation_v, *s->rot_standard_ref, rotated_orientation_v);
- rotated_orientation = ((2 * rotated_orientation_v[1] +
- rotated_orientation_v[0] + 4) % 5);
+ rotated_orientation =
+ ((2 * rotated_orientation_v[1] + rotated_orientation_v[0] + 4) %
+ 5);
return rotated_orientation;
}
diff --git a/common/motion_sense.c b/common/motion_sense.c
index f61b8dfdf1..f326259497 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,6 +8,7 @@
#include "accelgyro.h"
#include "atomic.h"
#include "body_detection.h"
+#include "builtin/assert.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -24,6 +25,7 @@
#include "motion_lid.h"
#include "motion_orientation.h"
#include "online_calibration.h"
+#include "printf.h"
#include "power.h"
#include "queue.h"
#include "tablet_mode.h"
@@ -33,9 +35,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_MOTION_SENSE, outstr)
-#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_MOTION_SENSE, format, ## args)
-
+#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_MOTION_SENSE, format, ##args)
/* Delay between FIFO interruption. */
static unsigned int ap_event_interval;
@@ -67,10 +68,10 @@ test_export_static enum chipset_state_mask sensor_active;
test_export_static int wait_us;
STATIC_IF(CONFIG_ACCEL_SPOOF_MODE) void print_spoof_mode_status(int id);
-STATIC_IF(CONFIG_GESTURE_DETECTION) void check_and_queue_gestures(
- uint32_t *event);
-STATIC_IF(CONFIG_MOTION_FILL_LPC_SENSE_DATA) void update_sense_data(
- uint8_t *lpc_status, int *psample_id);
+STATIC_IF(CONFIG_GESTURE_DETECTION)
+void check_and_queue_gestures(uint32_t *event);
+STATIC_IF(CONFIG_MOTION_FILL_LPC_SENSE_DATA)
+void update_sense_data(uint8_t *lpc_status, int *psample_id);
/* Flags to control whether to send an ODR change event for a sensor */
static atomic_t odr_event_required;
@@ -90,8 +91,8 @@ static int init_sensor_mutex(const struct device *dev)
SYS_INIT(init_sensor_mutex, POST_KERNEL, 50);
#endif /* CONFIG_ZEPHYR */
-static inline int motion_sensor_in_forced_mode(
- const struct motion_sensor_t *sensor)
+static inline int
+motion_sensor_in_forced_mode(const struct motion_sensor_t *sensor)
{
#ifdef CONFIG_ACCEL_FORCE_MODE_MASK
/* Sensor not in force mode, its irq_handler is getting data. */
@@ -105,8 +106,9 @@ static inline int motion_sensor_in_forced_mode(
}
/* Minimal amount of time since last collection before triggering a new one */
-static inline int motion_sensor_time_to_read(const timestamp_t *ts,
- const struct motion_sensor_t *sensor)
+static inline int
+motion_sensor_time_to_read(const timestamp_t *ts,
+ const struct motion_sensor_t *sensor)
{
if (sensor->collection_rate == 0)
return 0;
@@ -173,8 +175,8 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
sensor->name, odr, roundup, config_id,
BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr));
else
- CPRINTS("%c%d ODR %d rup %d cfg %d AP %d",
- sensor->name[0], sensor->type, odr, roundup, config_id,
+ CPRINTS("%c%d ODR %d rup %d cfg %d AP %d", sensor->name[0],
+ sensor->type, odr, roundup, config_id,
BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr));
mutex_lock(&g_sensor_mutex);
@@ -195,6 +197,10 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
sensor->collection_rate = odr > 0 ? SECOND * 1000 / odr : 0;
sensor->next_collection = ts.le.lo + sensor->collection_rate;
sensor->oversampling = 0;
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ motion_sense_set_data_period(sensor - motion_sensors,
+ sensor->collection_rate);
+ }
mutex_unlock(&g_sensor_mutex);
if (IS_ENABLED(CONFIG_BODY_DETECTION) &&
(sensor - motion_sensors == CONFIG_BODY_DETECTION_SENSOR))
@@ -203,9 +209,9 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
return 0;
}
-static int motion_sense_set_ec_rate_from_ap(
- const struct motion_sensor_t *sensor,
- unsigned int new_rate_us)
+static int
+motion_sense_set_ec_rate_from_ap(const struct motion_sensor_t *sensor,
+ unsigned int new_rate_us)
{
int odr_mhz = sensor->drv->get_data_rate(sensor);
@@ -238,7 +244,6 @@ end_set_ec_rate_from_ap:
return MAX(new_rate_us, motion_min_interval);
}
-
/*
* motion_sense_select_ec_rate
*
@@ -253,10 +258,9 @@ end_set_ec_rate_from_ap:
*
* return rate in us.
*/
-static int motion_sense_select_ec_rate(
- const struct motion_sensor_t *sensor,
- enum sensor_config config_id,
- int interrupt)
+static int motion_sense_select_ec_rate(const struct motion_sensor_t *sensor,
+ enum sensor_config config_id,
+ int interrupt)
{
if (interrupt == 0 && motion_sensor_in_forced_mode(sensor)) {
int rate_mhz = BASE_ODR(sensor->config[config_id].odr);
@@ -283,11 +287,11 @@ static int motion_sense_ec_rate(struct motion_sensor_t *sensor)
/* Check the AP setting first. */
if (sensor_active != SENSOR_ACTIVE_S5)
- ec_rate = motion_sense_select_ec_rate(
- sensor, SENSOR_CONFIG_AP, 0);
+ ec_rate = motion_sense_select_ec_rate(sensor, SENSOR_CONFIG_AP,
+ 0);
ec_rate_from_cfg = motion_sense_select_ec_rate(
- sensor, motion_sense_get_ec_config(), 0);
+ sensor, motion_sense_get_ec_config(), 0);
if (ec_rate_from_cfg != 0)
if (ec_rate == 0 || ec_rate_from_cfg < ec_rate)
@@ -315,7 +319,7 @@ static void motion_sense_set_motion_intervals(void)
continue;
sensor_ec_rate = motion_sense_select_ec_rate(
- sensor, SENSOR_CONFIG_AP, 1);
+ sensor, SENSOR_CONFIG_AP, 1);
if (ec_int_rate == 0 ||
(sensor_ec_rate && sensor_ec_rate < ec_int_rate))
ec_int_rate = sensor_ec_rate;
@@ -365,8 +369,8 @@ int sensor_init_done(struct motion_sensor_t *s)
!!(s->current_range & ROUND_UP_FLAG));
if (ret == EC_RES_SUCCESS) {
if (IS_ENABLED(CONFIG_CONSOLE_VERBOSE))
- CPRINTS("%s: MS Done Init type:0x%X range:%d",
- s->name, s->type, s->current_range);
+ CPRINTS("%s: MS Done Init type:0x%X range:%d", s->name,
+ s->type, s->current_range);
else
CPRINTS("%c%d InitDone r:%d", s->name[0], s->type,
s->current_range);
@@ -396,15 +400,14 @@ static void motion_sense_switch_sensor_rate(void)
* set.
*/
if (sensor->state == SENSOR_INITIALIZED) {
- sensor->drv->set_range(sensor,
- sensor->current_range,
- 1);
+ sensor->drv->set_range(
+ sensor, sensor->current_range, 1);
sensor_setup_mask |= BIT(i);
} else {
ret = motion_sense_init(sensor);
if (ret != EC_SUCCESS)
CPRINTS("%s: %d: init failed: %d",
- sensor->name, i, ret);
+ sensor->name, i, ret);
else
sensor_setup_mask |= BIT(i);
/*
@@ -468,19 +471,20 @@ static void motion_sense_switch_sensor_rate(void)
sensor = &motion_sensors[i];
if (sensor->state != SENSOR_INITIALIZED)
continue;
- sensor->drv->list_activities(sensor,
- &enabled, &disabled);
+ sensor->drv->list_activities(sensor, &enabled,
+ &disabled);
/* exclude double tap, it is used internally. */
enabled &= ~BIT(MOTIONSENSE_ACTIVITY_DOUBLE_TAP);
while (enabled) {
int activity = get_next_bit(&enabled);
- sensor->drv->manage_activity(
- sensor, activity, 0, NULL);
+ sensor->drv->manage_activity(sensor, activity,
+ 0, NULL);
}
/* Re-enable double tap in case AP disabled it */
- sensor->drv->manage_activity(sensor,
- MOTIONSENSE_ACTIVITY_DOUBLE_TAP, 1, NULL);
+ sensor->drv->manage_activity(
+ sensor, MOTIONSENSE_ACTIVITY_DOUBLE_TAP, 1,
+ NULL);
}
}
}
@@ -544,8 +548,7 @@ static void motion_sense_resume(void)
hook_call_deferred(&motion_sense_switch_sensor_rate_data,
CONFIG_MOTION_SENSE_RESUME_DELAY_US);
}
-DECLARE_HOOK(HOOK_CHIPSET_RESUME, motion_sense_resume,
- MOTION_SENSE_HOOK_PRIO);
+DECLARE_HOOK(HOOK_CHIPSET_RESUME, motion_sense_resume, MOTION_SENSE_HOOK_PRIO);
static void motion_sense_startup(void)
{
@@ -561,8 +564,7 @@ static void motion_sense_startup(void)
if (chipset_in_state(SENSOR_ACTIVE_S0))
motion_sense_resume();
}
-DECLARE_HOOK(HOOK_INIT, motion_sense_startup,
- MOTION_SENSE_HOOK_PRIO);
+DECLARE_HOOK(HOOK_INIT, motion_sense_startup, MOTION_SENSE_HOOK_PRIO);
/* Write to LPC status byte to represent that accelerometers are present. */
static inline void set_present(uint8_t *lpc_status)
@@ -620,15 +622,14 @@ static void update_sense_data(uint8_t *lpc_status, int *psample_id)
for (i = 0; i < EC_ALS_ENTRIES && i < ALS_COUNT; i++)
lpc_als[i] = ec_motion_sensor_clamp_u16(
- motion_als_sensors[i]->xyz[X]);
+ motion_als_sensors[i]->xyz[X]);
}
/*
* Increment sample id and clear busy bit to signal we finished
* updating data.
*/
- *psample_id = (*psample_id + 1) &
- EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
+ *psample_id = (*psample_id + 1) & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
*lpc_status = EC_MEMMAP_ACC_STATUS_PRESENCE_BIT | *psample_id;
}
#endif
@@ -650,7 +651,6 @@ static int motion_sense_read(struct motion_sensor_t *sensor)
return sensor->drv->read(sensor, sensor->raw_xyz);
}
-
static inline void increment_sensor_collection(struct motion_sensor_t *sensor,
const timestamp_t *ts)
{
@@ -708,8 +708,7 @@ void motion_sense_push_raw_xyz(struct motion_sensor_t *s)
}
}
-static int motion_sense_process(struct motion_sensor_t *sensor,
- uint32_t *event,
+static int motion_sense_process(struct motion_sensor_t *sensor, uint32_t *event,
const timestamp_t *ts)
{
int ret = EC_SUCCESS;
@@ -758,8 +757,8 @@ static int motion_sense_process(struct motion_sensor_t *sensor,
int flush_pending = atomic_clear(&sensor->flush_pending);
for (; flush_pending > 0; flush_pending--) {
- motion_sense_fifo_insert_async_event(
- sensor, ASYNC_EVENT_FLUSH);
+ motion_sense_fifo_insert_async_event(sensor,
+ ASYNC_EVENT_FLUSH);
}
}
@@ -768,8 +767,8 @@ static int motion_sense_process(struct motion_sensor_t *sensor,
motion_sense_set_data_rate(sensor);
motion_sense_set_motion_intervals();
if (IS_ENABLED(CONFIG_ACCEL_FIFO))
- motion_sense_fifo_insert_async_event(
- sensor, ASYNC_EVENT_ODR);
+ motion_sense_fifo_insert_async_event(sensor,
+ ASYNC_EVENT_ODR);
}
if (has_data_read) {
/* Run gesture recognition engine */
@@ -783,13 +782,12 @@ static int motion_sense_process(struct motion_sensor_t *sensor,
return ret;
}
-
#ifdef CONFIG_GESTURE_DETECTION
static void check_and_queue_gestures(uint32_t *event)
{
if (IS_ENABLED(CONFIG_GESTURE_SENSOR_DOUBLE_TAP) &&
(*event & TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
- MOTIONSENSE_ACTIVITY_DOUBLE_TAP))) {
+ MOTIONSENSE_ACTIVITY_DOUBLE_TAP))) {
if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION)) {
struct ec_response_motion_sensor_data vector;
@@ -799,14 +797,15 @@ static void check_and_queue_gestures(uint32_t *event)
* AP is ignoring double tap event, do no wake up and no
* automatic disable.
*/
- if (IS_ENABLED(CONFIG_GESTURE_SENSOR_DOUBLE_TAP_FOR_HOST))
+ if (IS_ENABLED(
+ CONFIG_GESTURE_SENSOR_DOUBLE_TAP_FOR_HOST))
vector.flags |= MOTIONSENSE_SENSOR_FLAG_WAKEUP;
vector.activity_data.activity =
- MOTIONSENSE_ACTIVITY_DOUBLE_TAP;
+ MOTIONSENSE_ACTIVITY_DOUBLE_TAP;
vector.activity_data.state = 1 /* triggered */;
vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
motion_sense_fifo_stage_data(&vector, NULL, 0,
- __hw_clock_source_read());
+ __hw_clock_source_read());
motion_sense_fifo_commit_data();
}
/* Call board specific function to process tap */
@@ -814,7 +813,7 @@ static void check_and_queue_gestures(uint32_t *event)
}
if (IS_ENABLED(CONFIG_GESTURE_SIGMO) &&
(*event & TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
- MOTIONSENSE_ACTIVITY_SIG_MOTION))) {
+ MOTIONSENSE_ACTIVITY_SIG_MOTION))) {
struct motion_sensor_t *activity_sensor;
if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION)) {
struct ec_response_motion_sensor_data vector;
@@ -823,19 +822,18 @@ static void check_and_queue_gestures(uint32_t *event)
vector.flags = MOTIONSENSE_SENSOR_FLAG_WAKEUP |
MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO;
vector.activity_data.activity =
- MOTIONSENSE_ACTIVITY_SIG_MOTION;
+ MOTIONSENSE_ACTIVITY_SIG_MOTION;
vector.activity_data.state = 1 /* triggered */;
vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
motion_sense_fifo_stage_data(&vector, NULL, 0,
- __hw_clock_source_read());
+ __hw_clock_source_read());
motion_sense_fifo_commit_data();
}
/* Disable further detection */
activity_sensor = &motion_sensors[CONFIG_GESTURE_SIGMO_SENSOR];
activity_sensor->drv->manage_activity(
- activity_sensor,
- MOTIONSENSE_ACTIVITY_SIG_MOTION,
- 0, NULL);
+ activity_sensor, MOTIONSENSE_ACTIVITY_SIG_MOTION, 0,
+ NULL);
}
if (IS_ENABLED(CONFIG_ORIENTATION_SENSOR)) {
const struct motion_sensor_t *sensor =
@@ -852,24 +850,22 @@ static void check_and_queue_gestures(uint32_t *event)
mutex_lock(sensor->mutex);
if (motion_orientation_changed(sensor) &&
- (*motion_orientation_ptr(sensor) !=
- MOTIONSENSE_ORIENTATION_UNKNOWN)) {
+ (*motion_orientation_ptr(sensor) !=
+ MOTIONSENSE_ORIENTATION_UNKNOWN)) {
motion_orientation_update(sensor);
vector.activity_data.state =
*motion_orientation_ptr(sensor);
- motion_sense_fifo_stage_data(&vector, NULL, 0,
- __hw_clock_source_read());
+ motion_sense_fifo_stage_data(
+ &vector, NULL, 0,
+ __hw_clock_source_read());
motion_sense_fifo_commit_data();
if (IS_ENABLED(CONFIG_DEBUG_ORIENTATION)) {
- static const char * const mode[] = {
- "Landscape",
- "Portrait",
- "Inv_Portrait",
- "Inv_Landscape",
+ static const char *const mode[] = {
+ "Landscape", "Portrait",
+ "Inv_Portrait", "Inv_Landscape",
"Unknown"
};
- CPRINTS(mode[
- vector.activity_data.state]);
+ CPRINTS(mode[vector.activity_data.state]);
}
}
mutex_unlock(sensor->mutex);
@@ -910,7 +906,6 @@ void motion_sense_task(void *u)
while (1) {
ts_begin_task = get_time();
for (i = 0; i < motion_sensor_count; ++i) {
-
sensor = &motion_sensors[i];
/* if the sensor is active in the current power state */
@@ -920,7 +915,7 @@ void motion_sense_task(void *u)
}
ret = motion_sense_process(sensor, &event,
- &ts_begin_task);
+ &ts_begin_task);
if (ret != EC_SUCCESS)
continue;
ready_status |= BIT(i);
@@ -944,13 +939,14 @@ void motion_sense_task(void *u)
}
}
if (IS_ENABLED(CONFIG_CMD_ACCEL_INFO) && (accel_disp)) {
- CPRINTF("[%pT event 0x%08x ",
- PRINTF_TIMESTAMP_NOW, event);
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
+
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s event 0x%08x ", ts_str, event);
for (i = 0; i < motion_sensor_count; ++i) {
sensor = &motion_sensors[i];
CPRINTF("%s=%-5d, %-5d, %-5d ", sensor->name,
- sensor->xyz[X],
- sensor->xyz[Y],
+ sensor->xyz[X], sensor->xyz[Y],
sensor->xyz[Z]);
}
if (IS_ENABLED(CONFIG_LID_ANGLE))
@@ -986,9 +982,9 @@ void motion_sense_task(void *u)
* will resume listening until it is suspended again.
*/
if ((IS_ENABLED(CONFIG_MKBP_EVENT) &&
- ((fifo_int_enabled &&
- sensor_active == SENSOR_ACTIVE_S0) ||
- motion_sense_fifo_wake_up_needed()))) {
+ ((fifo_int_enabled &&
+ sensor_active == SENSOR_ACTIVE_S0) ||
+ motion_sense_fifo_wake_up_needed()))) {
mkbp_send_event(EC_MKBP_EVENT_SENSOR_FIFO);
}
if (motion_sense_fifo_bypass_needed())
@@ -1003,7 +999,7 @@ void motion_sense_task(void *u)
struct motion_sensor_t *sensor = &motion_sensors[i];
if (!motion_sensor_in_forced_mode(sensor) ||
- sensor->collection_rate == 0)
+ sensor->collection_rate == 0)
continue;
time_diff = time_until(ts_end_task.le.lo,
@@ -1021,9 +1017,9 @@ void motion_sense_task(void *u)
if (wait_us >= 0 && wait_us < motion_min_interval) {
/*
- * Guarantee some minimum delay to allow other lower
- * priority tasks to run.
- */
+ * Guarantee some minimum delay to allow other lower
+ * priority tasks to run.
+ */
wait_us = motion_min_interval;
}
@@ -1035,8 +1031,7 @@ void motion_sense_task(void *u)
/* Host commands */
/* Function to map host sensor IDs to motion sensor. */
-static struct motion_sensor_t
- *host_sensor_id_to_real_sensor(int host_id)
+static struct motion_sensor_t *host_sensor_id_to_real_sensor(int host_id)
{
struct motion_sensor_t *sensor;
@@ -1052,8 +1047,7 @@ static struct motion_sensor_t
return NULL;
}
-static struct motion_sensor_t
- *host_sensor_id_to_motion_sensor(int host_id)
+static struct motion_sensor_t *host_sensor_id_to_motion_sensor(int host_id)
{
/* Return the info for the first sensor that support some gestures. */
if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION) &&
@@ -1081,7 +1075,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
out->dump.module_flags =
(*(host_get_memmap(EC_MEMMAP_ACC_STATUS)) &
EC_MEMMAP_ACC_STATUS_PRESENCE_BIT) ?
- MOTIONSENSE_MODULE_FLAG_ACTIVE : 0;
+ MOTIONSENSE_MODULE_FLAG_ACTIVE :
+ 0;
out->dump.sensor_count = ALL_MOTION_SENSORS;
args->response_size = sizeof(out->dump);
reported = MIN(ALL_MOTION_SENSORS, in->dump.max_sensor_count);
@@ -1099,13 +1094,14 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
}
}
mutex_unlock(&g_sensor_mutex);
- args->response_size += reported *
+ args->response_size +=
+ reported *
sizeof(struct ec_response_motion_sensor_data);
break;
case MOTIONSENSE_CMD_DATA:
sensor = host_sensor_id_to_real_sensor(
- in->sensor_odr.sensor_num);
+ in->sensor_odr.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
@@ -1120,7 +1116,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_INFO:
sensor = host_sensor_id_to_motion_sensor(
- in->sensor_odr.sensor_num);
+ in->sensor_odr.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
@@ -1139,7 +1135,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
if (args->version >= 3) {
out->info_3.min_frequency = sensor->min_frequency;
out->info_3.max_frequency = sensor->max_frequency;
- out->info_3.fifo_max_event_count = CONFIG_ACCEL_FIFO_SIZE;
+ out->info_3.fifo_max_event_count =
+ CONFIG_ACCEL_FIFO_SIZE;
args->response_size = sizeof(out->info_3);
}
if (args->version >= 4) {
@@ -1152,8 +1149,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
break;
case MOTIONSENSE_CMD_EC_RATE:
- sensor = host_sensor_id_to_real_sensor(
- in->ec_rate.sensor_num);
+ sensor = host_sensor_id_to_real_sensor(in->ec_rate.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
@@ -1181,7 +1177,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_SENSOR_ODR:
/* Verify sensor number is valid. */
sensor = host_sensor_id_to_real_sensor(
- in->sensor_odr.sensor_num);
+ in->sensor_odr.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
@@ -1210,7 +1206,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_SENSOR_RANGE:
/* Verify sensor number is valid. */
sensor = host_sensor_id_to_real_sensor(
- in->sensor_range.sensor_num);
+ in->sensor_range.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
/* Set new range if the data arg has a value. */
@@ -1218,10 +1214,9 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
if (!sensor->drv->set_range)
return EC_RES_INVALID_COMMAND;
- if (sensor->drv->set_range(sensor,
- in->sensor_range.data,
- in->sensor_range.roundup)
- != EC_SUCCESS) {
+ if (sensor->drv->set_range(
+ sensor, in->sensor_range.data,
+ in->sensor_range.roundup) != EC_SUCCESS) {
return EC_RES_INVALID_PARAM;
}
}
@@ -1233,7 +1228,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_SENSOR_OFFSET:
/* Verify sensor number is valid. */
sensor = host_sensor_id_to_real_sensor(
- in->sensor_offset.sensor_num);
+ in->sensor_offset.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
/* Set new range if the data arg has a value. */
@@ -1242,9 +1237,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
return EC_RES_INVALID_COMMAND;
in_offset = in->sensor_offset.offset;
- ret = sensor->drv->set_offset(sensor,
- in_offset,
- in->sensor_offset.temp);
+ ret = sensor->drv->set_offset(sensor, in_offset,
+ in->sensor_offset.temp);
if (ret != EC_SUCCESS)
return ret;
}
@@ -1264,7 +1258,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_SENSOR_SCALE:
/* Verify sensor number is valid. */
sensor = host_sensor_id_to_real_sensor(
- in->sensor_scale.sensor_num);
+ in->sensor_scale.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
/* Set new range if the data arg has a value. */
@@ -1273,8 +1267,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
return EC_RES_INVALID_COMMAND;
in_scale = in->sensor_scale.scale;
- ret = sensor->drv->set_scale(sensor,
- in_scale,
+ ret = sensor->drv->set_scale(sensor, in_scale,
in->sensor_scale.temp);
if (ret != EC_SUCCESS)
return ret;
@@ -1284,8 +1277,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
return EC_RES_INVALID_COMMAND;
out_scale = out->sensor_scale.scale;
- ret = sensor->drv->get_scale(sensor, out_scale,
- &out_temp);
+ ret = sensor->drv->get_scale(sensor, out_scale, &out_temp);
if (ret != EC_SUCCESS)
return ret;
@@ -1296,14 +1288,14 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_PERFORM_CALIB:
/* Verify sensor number is valid. */
sensor = host_sensor_id_to_real_sensor(
- in->perform_calib.sensor_num);
+ in->perform_calib.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
if (!sensor->drv->perform_calib)
return EC_RES_INVALID_COMMAND;
- ret = sensor->drv->perform_calib(
- sensor, in->perform_calib.enable);
+ ret = sensor->drv->perform_calib(sensor,
+ in->perform_calib.enable);
if (ret != EC_SUCCESS)
return ret;
@@ -1320,7 +1312,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
if (!IS_ENABLED(CONFIG_ACCEL_FIFO))
return EC_RES_INVALID_PARAM;
sensor = host_sensor_id_to_real_sensor(
- in->sensor_odr.sensor_num);
+ in->sensor_odr.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
@@ -1340,12 +1332,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
break;
}
motion_sense_fifo_get_info(&out->fifo_info, 1);
- for (i = 0; i < motion_sensor_count; i++) {
- out->fifo_info.lost[i] = motion_sensors[i].lost;
- motion_sensors[i].lost = 0;
- }
args->response_size = sizeof(out->fifo_info) +
- sizeof(uint16_t) * motion_sensor_count;
+ sizeof(uint16_t) * motion_sensor_count;
break;
case MOTIONSENSE_CMD_FIFO_READ:
@@ -1353,8 +1341,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
out->fifo_read.number_data = motion_sense_fifo_read(
args->response_max - sizeof(out->fifo_read),
- in->fifo_read.max_data_vector,
- out->fifo_read.data,
+ in->fifo_read.max_data_vector, out->fifo_read.data,
&(args->response_size));
args->response_size += sizeof(out->fifo_read);
break;
@@ -1384,9 +1371,9 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
out_calib_read = &out->online_calib_read;
args->response_size =
- online_calibration_read(sensor, out_calib_read)
- ? sizeof(struct ec_response_online_calibration_data)
- : 0;
+ online_calibration_read(sensor, out_calib_read) ?
+ sizeof(struct ec_response_online_calibration_data) :
+ 0;
break;
#ifdef CONFIG_GESTURE_HOST_DETECTION
case MOTIONSENSE_CMD_LIST_ACTIVITIES: {
@@ -1399,8 +1386,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
while (mask && ret == EC_RES_SUCCESS) {
i = get_next_bit(&mask);
sensor = &motion_sensors[i];
- ret = sensor->drv->list_activities(sensor,
- &enabled, &disabled);
+ ret = sensor->drv->list_activities(sensor, &enabled,
+ &disabled);
if (ret == EC_RES_SUCCESS) {
out->list_activities.enabled |= enabled;
out->list_activities.disabled |= disabled;
@@ -1408,11 +1395,11 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
}
if (IS_ENABLED(CONFIG_BODY_DETECTION)) {
if (body_detect_get_enable()) {
- out->list_activities.enabled |=
- BIT(MOTIONSENSE_ACTIVITY_BODY_DETECTION);
+ out->list_activities.enabled |= BIT(
+ MOTIONSENSE_ACTIVITY_BODY_DETECTION);
} else {
- out->list_activities.disabled |=
- BIT(MOTIONSENSE_ACTIVITY_BODY_DETECTION);
+ out->list_activities.disabled |= BIT(
+ MOTIONSENSE_ACTIVITY_BODY_DETECTION);
}
}
if (ret != EC_RES_SUCCESS)
@@ -1428,18 +1415,18 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
while (mask && ret == EC_RES_SUCCESS) {
i = get_next_bit(&mask);
sensor = &motion_sensors[i];
- sensor->drv->list_activities(sensor,
- &enabled, &disabled);
+ sensor->drv->list_activities(sensor, &enabled,
+ &disabled);
if ((1 << in->set_activity.activity) &
(enabled | disabled))
- ret = sensor->drv->manage_activity(sensor,
- in->set_activity.activity,
- in->set_activity.enable,
- &in->set_activity);
+ ret = sensor->drv->manage_activity(
+ sensor, in->set_activity.activity,
+ in->set_activity.enable,
+ &in->set_activity);
}
if (IS_ENABLED(CONFIG_BODY_DETECTION) &&
(in->set_activity.activity ==
- MOTIONSENSE_ACTIVITY_BODY_DETECTION))
+ MOTIONSENSE_ACTIVITY_BODY_DETECTION))
body_detect_set_enable(in->set_activity.enable);
if (ret != EC_RES_SUCCESS)
return ret;
@@ -1450,8 +1437,8 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
if (IS_ENABLED(CONFIG_BODY_DETECTION) &&
(in->get_activity.activity ==
MOTIONSENSE_ACTIVITY_BODY_DETECTION)) {
- out->get_activity.state = (uint8_t)
- body_detect_get_state();
+ out->get_activity.state =
+ (uint8_t)body_detect_get_state();
ret = EC_RES_SUCCESS;
} else {
ret = EC_RES_INVALID_PARAM;
@@ -1549,7 +1536,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_SPOOF_MODE_QUERY:
/* Querying the spoof status of the sensor. */
out->spoof.ret = !!(sensor->flags &
- MOTIONSENSE_FLAG_IN_SPOOF_MODE);
+ MOTIONSENSE_FLAG_IN_SPOOF_MODE);
args->response_size = sizeof(out->spoof);
break;
@@ -1570,7 +1557,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
default:
/* Call other users of the motion task */
if (IS_ENABLED(CONFIG_LID_ANGLE) &&
- (ret == EC_RES_INVALID_PARAM))
+ (ret == EC_RES_INVALID_PARAM))
ret = host_cmd_motion_lid(args);
return ret;
}
@@ -1580,12 +1567,12 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_MOTION_SENSE_CMD, host_cmd_motion_sense,
EC_VER_MASK(1) | EC_VER_MASK(2) | EC_VER_MASK(3) |
- EC_VER_MASK(4));
+ EC_VER_MASK(4));
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_ACCELS
-static int command_accelrange(int argc, char **argv)
+static int command_accelrange(int argc, const char **argv)
{
char *e;
int id, data, round = 1;
@@ -1618,9 +1605,8 @@ static int command_accelrange(int argc, char **argv)
* Write new range, if it returns invalid arg, then return
* a parameter error.
*/
- if (sensor->drv->set_range(sensor,
- data,
- round) == EC_ERROR_INVAL)
+ if (sensor->drv->set_range(sensor, data, round) ==
+ EC_ERROR_INVAL)
return EC_ERROR_PARAM2;
} else {
ccprintf("Sensor %d range: %d\n", id, sensor->current_range);
@@ -1628,11 +1614,10 @@ static int command_accelrange(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(accelrange, command_accelrange,
- "id [data [roundup]]",
- "Read or write accelerometer range");
+DECLARE_CONSOLE_COMMAND(accelrange, command_accelrange, "id [data [roundup]]",
+ "Read or write accelerometer range");
-static int command_accelresolution(int argc, char **argv)
+static int command_accelresolution(int argc, const char **argv)
{
char *e;
int id, data, round = 1;
@@ -1666,8 +1651,8 @@ static int command_accelresolution(int argc, char **argv)
* return a parameter error.
*/
if (sensor->drv->set_resolution &&
- sensor->drv->set_resolution(sensor, data, round)
- == EC_ERROR_INVAL)
+ sensor->drv->set_resolution(sensor, data, round) ==
+ EC_ERROR_INVAL)
return EC_ERROR_PARAM2;
} else {
ccprintf("Resolution for sensor %d: %d\n", id,
@@ -1677,10 +1662,10 @@ static int command_accelresolution(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(accelres, command_accelresolution,
- "id [data [roundup]]",
- "Read or write accelerometer resolution");
+ "id [data [roundup]]",
+ "Read or write accelerometer resolution");
-static int command_accel_data_rate(int argc, char **argv)
+static int command_accel_data_rate(int argc, const char **argv)
{
char *e;
int id, data, round = 1;
@@ -1717,8 +1702,8 @@ static int command_accel_data_rate(int argc, char **argv)
*/
config_id = motion_sense_get_ec_config();
sensor->config[SENSOR_CONFIG_AP].odr = 0;
- sensor->config[config_id].odr =
- data | (round ? ROUND_UP_FLAG : 0);
+ sensor->config[config_id].odr = data |
+ (round ? ROUND_UP_FLAG : 0);
atomic_or(&odr_event_required, 1 << (sensor - motion_sensors));
task_set_event(TASK_ID_MOTIONSENSE,
@@ -1734,10 +1719,10 @@ static int command_accel_data_rate(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(accelrate, command_accel_data_rate,
- "id [data [roundup]]",
- "Read or write accelerometer ODR");
+ "id [data [roundup]]",
+ "Read or write accelerometer ODR");
-static int command_accel_read_xyz(int argc, char **argv)
+static int command_accel_read_xyz(int argc, const char **argv)
{
char *e;
int id, n = 1, ret;
@@ -1761,22 +1746,21 @@ static int command_accel_read_xyz(int argc, char **argv)
while ((n-- > 0)) {
ret = sensor->drv->read(sensor, v);
if (ret == 0)
- ccprintf("Current data %d: %-5d %-5d %-5d\n",
- id, v[X], v[Y], v[Z]);
+ ccprintf("Current data %d: %-5d %-5d %-5d\n", id, v[X],
+ v[Y], v[Z]);
else
ccprintf("vector not ready\n");
- ccprintf("Last calib. data %d: %-5d %-5d %-5d\n",
- id, sensor->xyz[X], sensor->xyz[Y], sensor->xyz[Z]);
+ ccprintf("Last calib. data %d: %-5d %-5d %-5d\n", id,
+ sensor->xyz[X], sensor->xyz[Y], sensor->xyz[Z]);
task_wait_event(motion_min_interval);
}
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(accelread, command_accel_read_xyz,
- "id [n]",
- "Read sensor x/y/z");
+DECLARE_CONSOLE_COMMAND(accelread, command_accel_read_xyz, "id [n]",
+ "Read sensor x/y/z");
-static int command_accel_init(int argc, char **argv)
+static int command_accel_init(int argc, const char **argv)
{
char *e;
int id, ret;
@@ -1797,12 +1781,10 @@ static int command_accel_init(int argc, char **argv)
ccprintf("%s: state %d - %d\n", sensor->name, sensor->state, ret);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(accelinit, command_accel_init,
- "id",
- "Init sensor");
+DECLARE_CONSOLE_COMMAND(accelinit, command_accel_init, "id", "Init sensor");
#ifdef CONFIG_CMD_ACCEL_INFO
-static int command_display_accel_info(int argc, char **argv)
+static int command_display_accel_info(int argc, const char **argv)
{
int val, i, j;
@@ -1819,17 +1801,17 @@ static int command_display_accel_info(int argc, char **argv)
ccprintf("type: %d\n", motion_sensors[i].type);
ccprintf("location: %d\n", motion_sensors[i].location);
ccprintf("port: %d\n", motion_sensors[i].port);
- ccprintf("addr: %d\n", I2C_STRIP_FLAGS(motion_sensors[i]
- .i2c_spi_addr_flags));
+ ccprintf("addr: %d\n",
+ I2C_STRIP_FLAGS(motion_sensors[i].i2c_spi_addr_flags));
ccprintf("range: %d\n", motion_sensors[i].current_range);
ccprintf("min_freq: %d\n", motion_sensors[i].min_frequency);
ccprintf("max_freq: %d\n", motion_sensors[i].max_frequency);
ccprintf("config:\n");
for (j = 0; j < SENSOR_CONFIG_MAX; j++) {
ccprintf("%d - odr: %umHz, ec_rate: %uus\n", j,
- motion_sensors[i].config[j].odr &
- ~ROUND_UP_FLAG,
- motion_sensors[i].config[j].ec_rate);
+ motion_sensors[i].config[j].odr &
+ ~ROUND_UP_FLAG,
+ motion_sensors[i].config[j].ec_rate);
}
}
@@ -1843,9 +1825,8 @@ static int command_display_accel_info(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(accelinfo, command_display_accel_info,
- "on/off",
- "Print motion sensor info, lid angle calculations.");
+DECLARE_CONSOLE_COMMAND(accelinfo, command_display_accel_info, "on/off",
+ "Print motion sensor info, lid angle calculations.");
#endif /* CONFIG_CMD_ACCEL_INFO */
#endif /* CONFIG_CMD_ACCELS */
@@ -1854,15 +1835,16 @@ DECLARE_CONSOLE_COMMAND(accelinfo, command_display_accel_info,
static void print_spoof_mode_status(int id)
{
CPRINTS("Sensor %d spoof mode is %s. <%d, %d, %d>", id,
- (motion_sensors[id].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE)
- ? "enabled" : "disabled",
+ (motion_sensors[id].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) ?
+ "enabled" :
+ "disabled",
motion_sensors[id].spoof_xyz[X],
motion_sensors[id].spoof_xyz[Y],
motion_sensors[id].spoof_xyz[Z]);
}
#ifdef CONFIG_CMD_ACCELSPOOF
-static int command_accelspoof(int argc, char **argv)
+static int command_accelspoof(int argc, const char **argv)
{
char *e;
int id, enable, i;
@@ -1897,8 +1879,8 @@ static int command_accelspoof(int argc, char **argv)
*/
if (argc == 6) {
for (i = 0; i < 3; i++)
- s->spoof_xyz[i] = strtoi(argv[3 + i],
- &e, 0);
+ s->spoof_xyz[i] =
+ strtoi(argv[3 + i], &e, 0);
} else if (argc == 3) {
for (i = X; i <= Z; i++)
s->spoof_xyz[i] = s->raw_xyz[i];
diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c
index 5743d0fdcb..672b328420 100644
--- a/common/motion_sense_fifo.c
+++ b/common/motion_sense_fifo.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -15,7 +15,7 @@
#include "online_calibration.h"
#include "stdbool.h"
-#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ##args)
/**
* Staged metadata for the fifo queue.
@@ -50,6 +50,12 @@ static struct queue fifo = QUEUE_NULL(CONFIG_ACCEL_FIFO_SIZE,
struct ec_response_motion_sensor_data);
/** Count of the number of entries lost due to a small queue. */
static int fifo_lost;
+/*
+ * How many vector events are lost in the FIFO since last time
+ * FIFO info has been transmitted.
+ */
+static uint16_t fifo_sensor_lost[MAX_MOTION_SENSORS];
+
/** Metadata for the fifo, used for staging and spreading data. */
static struct fifo_staged fifo_staged;
@@ -60,6 +66,18 @@ static struct fifo_staged fifo_staged;
static struct timestamp_state next_timestamp[MAX_MOTION_SENSORS];
/**
+ * Expected data periods:
+ * copy of collection rate, updated when ODR changes.
+ */
+static uint32_t expected_data_periods[MAX_MOTION_SENSORS];
+
+/**
+ * Calculated data periods:
+ * can be different from collection rate when spreading.
+ */
+static uint32_t data_periods[MAX_MOTION_SENSORS];
+
+/**
* Bitmap telling which sensors have valid entries in the next_timestamp array.
*/
static uint32_t next_timestamp_initialized;
@@ -76,8 +94,8 @@ static int wake_up_needed;
* @param data The data entry to check.
* @return 1 if the entry is a timestamp, 0 otherwise.
*/
-static inline int is_timestamp(
- const struct ec_response_motion_sensor_data *data)
+static inline int
+is_timestamp(const struct ec_response_motion_sensor_data *data)
{
return data->flags & MOTIONSENSE_SENSOR_FLAG_TIMESTAMP;
}
@@ -102,8 +120,8 @@ static inline bool is_data(const struct ec_response_motion_sensor_data *data)
*/
static inline struct ec_response_motion_sensor_data *get_fifo_head(void)
{
- return ((struct ec_response_motion_sensor_data *) fifo.buffer) +
- (fifo.state->head & fifo.buffer_units_mask);
+ return ((struct ec_response_motion_sensor_data *)fifo.buffer) +
+ (fifo.state->head & fifo.buffer_units_mask);
}
/**
@@ -149,7 +167,7 @@ static void fifo_pop(void)
/* Increment lost counter if we have valid data. */
if (!is_timestamp(head))
- motion_sensors[head->sensor_num].lost++;
+ fifo_sensor_lost[head->sensor_num]++;
/*
* We're done if the initial count was non-zero and we only advanced the
@@ -228,11 +246,10 @@ static inline bool is_new_timestamp(uint8_t sensor_num)
* @param data The data to stage.
* @param sensor The sensor that generated the data
* @param valid_data The number of readable data entries in the data.
+ * sensor can be NULL (for activity sensors). valid_data must be 0 then.
*/
-static void fifo_stage_unit(
- struct ec_response_motion_sensor_data *data,
- struct motion_sensor_t *sensor,
- int valid_data)
+static void fifo_stage_unit(struct ec_response_motion_sensor_data *data,
+ struct motion_sensor_t *sensor, int valid_data)
{
struct queue_chunk chunk;
int i;
@@ -266,7 +283,7 @@ static void fifo_stage_unit(
if (removed) {
mutex_unlock(&g_sensor_mutex);
if (IS_ENABLED(CONFIG_ONLINE_CALIB) &&
- next_timestamp_initialized & BIT(data->sensor_num))
+ !is_new_timestamp(data->sensor_num))
online_calibration_process_data(
data, sensor,
next_timestamp[data->sensor_num].next);
@@ -279,7 +296,8 @@ static void fifo_stage_unit(
if (IS_ENABLED(CONFIG_TABLET_MODE))
data->flags |= (tablet_get_mode() ?
- MOTIONSENSE_SENSOR_FLAG_TABLET_MODE : 0);
+ MOTIONSENSE_SENSOR_FLAG_TABLET_MODE :
+ 0);
/*
* Get the next writable block in the fifo. We don't need to lock this
@@ -316,8 +334,7 @@ static void fifo_stage_unit(
* If the new per-sensor sample count is greater than 1, we'll need to
* spread.
*/
- if (IS_ENABLED(CONFIG_SENSOR_TIGHT_TIMESTAMPS) &&
- !is_timestamp(data) &&
+ if (IS_ENABLED(CONFIG_SENSOR_TIGHT_TIMESTAMPS) && !is_timestamp(data) &&
++fifo_staged.sample_count[data->sensor_num] > 1)
fifo_staged.requires_spreading = 1;
@@ -351,8 +368,9 @@ static void fifo_stage_timestamp(uint32_t timestamp, uint8_t sensor_num)
static inline struct ec_response_motion_sensor_data *
peek_fifo_staged(size_t offset)
{
- return (struct ec_response_motion_sensor_data *)
- queue_get_write_chunk(&fifo, offset).buffer;
+ return (struct ec_response_motion_sensor_data *)queue_get_write_chunk(
+ &fifo, offset)
+ .buffer;
}
void motion_sense_fifo_init(void)
@@ -389,9 +407,8 @@ void motion_sense_fifo_reset_needed_flags(void)
mutex_unlock(&g_sensor_mutex);
}
-void motion_sense_fifo_insert_async_event(
- struct motion_sensor_t *sensor,
- enum motion_sense_async_event event)
+void motion_sense_fifo_insert_async_event(struct motion_sensor_t *sensor,
+ enum motion_sense_async_event event)
{
struct ec_response_motion_sensor_data vector;
@@ -409,11 +426,9 @@ inline void motion_sense_fifo_add_timestamp(uint32_t timestamp)
motion_sense_fifo_commit_data();
}
-void motion_sense_fifo_stage_data(
- struct ec_response_motion_sensor_data *data,
- struct motion_sensor_t *sensor,
- int valid_data,
- uint32_t time)
+void motion_sense_fifo_stage_data(struct ec_response_motion_sensor_data *data,
+ struct motion_sensor_t *sensor,
+ int valid_data, uint32_t time)
{
if (IS_ENABLED(CONFIG_SENSOR_TIGHT_TIMESTAMPS)) {
/* First entry, save the time for spreading later. */
@@ -426,8 +441,6 @@ void motion_sense_fifo_stage_data(
void motion_sense_fifo_commit_data(void)
{
- /* Cached data periods, static to store off stack. */
- static uint32_t data_periods[MAX_MOTION_SENSORS];
struct ec_response_motion_sensor_data *data;
int i, window, sensor_num;
@@ -468,15 +481,15 @@ void motion_sense_fifo_commit_data(void)
if (!fifo_staged.sample_count[i])
continue;
- period = motion_sensors[i].collection_rate;
+ period = expected_data_periods[i];
/*
* Clamp the sample period to the MIN of collection_rate and the
* window length / (sample count - 1).
*/
if (window && fifo_staged.sample_count[i] > 1)
- period = MIN(
- period,
- window / (fifo_staged.sample_count[i] - 1));
+ period =
+ MIN(period,
+ window / (fifo_staged.sample_count[i] - 1));
data_periods[i] = period;
}
@@ -519,7 +532,7 @@ commit_data_end:
* sensor or the timestamp is after our computed next, skip
* ahead.
*/
- if (!(next_timestamp_initialized & BIT(sensor_num)) ||
+ if (is_new_timestamp(sensor_num) ||
time_after(data->timestamp,
next_timestamp[sensor_num].prev)) {
next_timestamp[sensor_num].next = data->timestamp;
@@ -531,9 +544,9 @@ commit_data_end:
next_timestamp[sensor_num].prev =
next_timestamp[sensor_num].next;
next_timestamp[sensor_num].next +=
- fifo_staged.requires_spreading
- ? data_periods[sensor_num]
- : motion_sensors[sensor_num].collection_rate;
+ fifo_staged.requires_spreading ?
+ data_periods[sensor_num] :
+ expected_data_periods[sensor_num];
/* Update online calibration if enabled. */
data = peek_fifo_staged(i);
@@ -549,30 +562,30 @@ commit_data_end:
/* Reset metadata for next staging cycle. */
memset(&fifo_staged, 0, sizeof(fifo_staged));
- /*
- * Reset the initialized bits. This will allow new timestamps to be
- * considered as the new "source of truth".
- */
- next_timestamp_initialized = 0;
-
mutex_unlock(&g_sensor_mutex);
}
void motion_sense_fifo_get_info(
- struct ec_response_motion_sense_fifo_info *fifo_info,
- int reset)
+ struct ec_response_motion_sense_fifo_info *fifo_info, int reset)
{
+ int i;
+
mutex_lock(&g_sensor_mutex);
fifo_info->size = fifo.buffer_units;
fifo_info->count = queue_count(&fifo);
fifo_info->total_lost = fifo_lost;
+ for (i = 0; i < MAX_MOTION_SENSORS; i++) {
+ fifo_info->lost[i] = fifo_sensor_lost[i];
+ }
mutex_unlock(&g_sensor_mutex);
#ifdef CONFIG_MKBP_EVENT
fifo_info->timestamp = mkbp_last_event_time;
#endif
- if (reset)
+ if (reset) {
fifo_lost = 0;
+ memset(fifo_sensor_lost, 0, sizeof(fifo_sensor_lost));
+ }
}
/* LCOV_EXCL_START - function cannot be tested due to limitations with mkbp */
@@ -615,10 +628,23 @@ int motion_sense_fifo_read(int capacity_bytes, int max_count, void *out,
void motion_sense_fifo_reset(void)
{
+ static uint8_t fifo_info_buffer
+ [sizeof(struct ec_response_motion_sense_fifo_info) +
+ sizeof(uint16_t) * MAX_MOTION_SENSORS];
+ struct ec_response_motion_sense_fifo_info *fifo_info =
+ (void *)fifo_info_buffer;
+
next_timestamp_initialized = 0;
memset(&fifo_staged, 0, sizeof(fifo_staged));
motion_sense_fifo_init();
queue_init(&fifo);
+ motion_sense_fifo_get_info(fifo_info, /*reset=*/true);
+}
+
+void motion_sense_set_data_period(int sensor_num, uint32_t data_period)
+{
+ expected_data_periods[sensor_num] = data_period;
+ next_timestamp_initialized &= ~BIT(sensor_num);
}
#ifdef CONFIG_CMD_ACCEL_FIFO
@@ -641,7 +667,8 @@ static int motion_sense_read_fifo(int argc, char **argv)
memcpy(&timestamp, v.data, sizeof(v.data));
ccprintf("Timestamp: 0x%016llx%s\n", timestamp,
(v.flags & MOTIONSENSE_SENSOR_FLAG_FLUSH ?
- " - Flush" : ""));
+ " - Flush" :
+ ""));
} else {
ccprintf("%d %d: %-5d %-5d %-5d\n", i, v.sensor_num,
v.data[X], v.data[Y], v.data[Z]);
@@ -650,7 +677,6 @@ static int motion_sense_read_fifo(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(fiforead, motion_sense_read_fifo,
- "id",
- "Read Fifo sensor");
+DECLARE_CONSOLE_COMMAND(fiforead, motion_sense_read_fifo, "id",
+ "Read Fifo sensor");
#endif /* defined(CONFIG_CMD_ACCEL_FIFO) */
diff --git a/common/newton_fit.c b/common/newton_fit.c
index ae81a45f07..5d217bc63d 100644
--- a/common/newton_fit.c
+++ b/common/newton_fit.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -32,7 +32,7 @@ static fp_t compute_error(struct newton_fit *fit, fpv3_t center)
_it = (struct newton_fit_orientation *)it.ptr;
e = FLOAT_TO_FP(1.0f) -
- distance_squared(_it->orientation, center);
+ distance_squared(_it->orientation, center);
error += fp_mul(e, e);
}
@@ -138,8 +138,8 @@ void newton_fit_compute(struct newton_fit *fit, fpv3_t bias, fp_t *radius)
if (queue_is_empty(fit->orientations))
return;
- inv_orient_count = fp_div(FLOAT_TO_FP(1.0f),
- queue_count(fit->orientations));
+ inv_orient_count =
+ fp_div(FLOAT_TO_FP(1.0f), queue_count(fit->orientations));
memcpy(new_bias, bias, sizeof(fpv3_t));
new_error = compute_error(fit, new_bias);
diff --git a/common/ocpc.c b/common/ocpc.c
index 89d9b9cf4f..c27cf4efe5 100644
--- a/common/ocpc.c
+++ b/common/ocpc.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -32,23 +32,22 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-#define CPRINT_VIZ(format, args...) \
-do { \
- if (viz_output) \
- cprintf(CC_CHARGER, format, ## args); \
-} while (0)
-#define CPRINTS_DBG(format, args...) \
-do { \
- if (debug_output) \
- cprints(CC_CHARGER, format, ## args); \
-} while (0)
-#define CPRINTF_DBG(format, args...) \
-do { \
- if (debug_output) \
- cprintf(CC_CHARGER, format, ## args); \
-} while (0)
-
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
+#define CPRINT_VIZ(format, args...) \
+ do { \
+ if (viz_output) \
+ cprintf(CC_CHARGER, format, ##args); \
+ } while (0)
+#define CPRINTS_DBG(format, args...) \
+ do { \
+ if (debug_output) \
+ cprints(CC_CHARGER, format, ##args); \
+ } while (0)
+#define CPRINTF_DBG(format, args...) \
+ do { \
+ if (debug_output) \
+ cprintf(CC_CHARGER, format, ##args); \
+ } while (0)
/* Code refactor will be needed if more than 2 charger chips are present */
BUILD_ASSERT(CHARGER_NUM == 2);
@@ -68,14 +67,14 @@ static int viz_output;
#define RSYS_IDX 2
static int resistance_tbl[NUM_RESISTANCE_SAMPLES][3] = {
/* Rsys+Rbatt Rbatt Rsys */
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
- {CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0},
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
+ { CONFIG_OCPC_DEF_RBATT_MOHMS, CONFIG_OCPC_DEF_RBATT_MOHMS, 0 },
};
static int resistance_tbl_idx;
static int mean_resistance[3];
@@ -125,8 +124,8 @@ static void calc_resistance_stats(struct ocpc_data *ocpc)
for (j = 0; j < NUM_RESISTANCE_SAMPLES; j++)
sum += POW2(resistance_tbl[j][i] - mean_resistance[i]);
- stddev_resistance[i] = fp_sqrtf(INT_TO_FP(sum /
- NUM_RESISTANCE_SAMPLES));
+ stddev_resistance[i] =
+ fp_sqrtf(INT_TO_FP(sum / NUM_RESISTANCE_SAMPLES));
stddev_resistance[i] = FP_TO_INT(stddev_resistance[i]);
/*
* Don't let our stddev collapse to 0 to continually consider
@@ -149,8 +148,7 @@ static bool is_within_range(struct ocpc_data *ocpc, int combined, int rbatt,
/* Discard measurements not within a 6 std. dev. window. */
if ((ocpc->chg_flags[act_chg] & OCPC_NO_ISYS_MEAS_CAP)) {
/* We only know the combined Rsys+Rbatt */
- valid = (combined > 0) &&
- (combined <= ub[COMBINED_IDX]) &&
+ valid = (combined > 0) && (combined <= ub[COMBINED_IDX]) &&
(combined >= lb[COMBINED_IDX]);
} else {
valid = (rsys <= ub[RSYS_IDX]) && (rsys >= lb[RSYS_IDX]) &&
@@ -201,12 +199,12 @@ enum ec_error_list ocpc_calc_resistances(struct ocpc_data *ocpc,
* out Rsys from Rbatt.
*/
combined = ((ocpc->vsys_aux_mv - battery->voltage) * 1000) /
- battery->current;
+ battery->current;
} else {
rsys = ((ocpc->vsys_aux_mv - ocpc->vsys_mv) * 1000) /
- ocpc->isys_ma;
+ ocpc->isys_ma;
rbatt = ((ocpc->vsys_mv - battery->voltage) * 1000) /
- battery->current;
+ battery->current;
combined = rsys + rbatt;
}
@@ -222,35 +220,36 @@ enum ec_error_list ocpc_calc_resistances(struct ocpc_data *ocpc,
resistance_tbl[resistance_tbl_idx][COMBINED_IDX] =
MAX(combined, CONFIG_OCPC_DEF_RBATT_MOHMS);
calc_resistance_stats(ocpc);
- resistance_tbl_idx = (resistance_tbl_idx + 1) %
- NUM_RESISTANCE_SAMPLES;
+ resistance_tbl_idx =
+ (resistance_tbl_idx + 1) % NUM_RESISTANCE_SAMPLES;
}
if (seeded) {
ocpc->combined_rsys_rbatt_mo =
- MAX(mean_resistance[COMBINED_IDX],
- CONFIG_OCPC_DEF_RBATT_MOHMS);
+ MAX(mean_resistance[COMBINED_IDX],
+ CONFIG_OCPC_DEF_RBATT_MOHMS);
if (!(ocpc->chg_flags[act_chg] & OCPC_NO_ISYS_MEAS_CAP)) {
ocpc->rsys_mo = mean_resistance[RSYS_IDX];
ocpc->rbatt_mo = MAX(mean_resistance[RBATT_IDX],
CONFIG_OCPC_DEF_RBATT_MOHMS);
- CPRINTS_DBG("Rsys: %dmOhm Rbatt: %dmOhm",
- ocpc->rsys_mo, ocpc->rbatt_mo);
+ CPRINTS_DBG("Rsys: %dmOhm Rbatt: %dmOhm", ocpc->rsys_mo,
+ ocpc->rbatt_mo);
}
CPRINTS_DBG("Rsys+Rbatt: %dmOhm", ocpc->combined_rsys_rbatt_mo);
} else {
seeded = ++initial_samples >= (2 * NUM_RESISTANCE_SAMPLES) ?
- true : false;
+ true :
+ false;
}
return EC_SUCCESS;
}
int ocpc_config_secondary_charger(int *desired_input_current,
- struct ocpc_data *ocpc,
- int voltage_mv, int current_ma)
+ struct ocpc_data *ocpc, int voltage_mv,
+ int current_ma)
{
int rv = EC_SUCCESS;
struct batt_params batt;
@@ -342,7 +341,6 @@ int ocpc_config_secondary_charger(int *desired_input_current,
iterations = 0;
}
-
/*
* We need to induce a current flow that matches the requested current
* by raising VSYS. Let's start by getting the latest data that we
@@ -353,7 +351,6 @@ int ocpc_config_secondary_charger(int *desired_input_current,
ocpc_get_adcs(ocpc);
charger_get_params(&charger);
-
/*
* If the system is in S5/G3, we can calculate the board and battery
* resistances.
@@ -378,9 +375,9 @@ int ocpc_config_secondary_charger(int *desired_input_current,
/* Set our current target accordingly. */
if (batt.desired_voltage) {
if (((batt.voltage < batt_info->voltage_min) ||
- ((batt.voltage < batt_info->voltage_normal) &&
- (current_ma >= 0) &&
- (current_ma <= batt_info->precharge_current))) &&
+ ((batt.voltage < batt_info->voltage_normal) &&
+ (current_ma >= 0) &&
+ (current_ma <= batt_info->precharge_current))) &&
(ph != PHASE_PRECHARGE)) {
/*
* If the charger IC doesn't support the linear charge
@@ -396,8 +393,7 @@ int ocpc_config_secondary_charger(int *desired_input_current,
}
} else if (batt.voltage < batt.desired_voltage) {
if ((ph == PHASE_PRECHARGE) &&
- (current_ma >
- batt_info->precharge_current)) {
+ (current_ma > batt_info->precharge_current)) {
/*
* Precharge phase is complete. Now set the
* target VSYS to the battery voltage to prevent
@@ -437,7 +433,6 @@ int ocpc_config_secondary_charger(int *desired_input_current,
ph = ph == PHASE_CC ? PHASE_CV_TRIP : PHASE_CV_COMPLETE;
if (ph == PHASE_CV_TRIP)
i_ma_CC_CV = batt.current;
-
}
}
@@ -486,8 +481,7 @@ int ocpc_config_secondary_charger(int *desired_input_current,
CPRINTS_DBG("min_vsys_target = %d", min_vsys_target);
/* Obtain the drive from our PID controller. */
- if ((ocpc->last_vsys != OCPC_UNINIT) &&
- (ph > PHASE_PRECHARGE)) {
+ if ((ocpc->last_vsys != OCPC_UNINIT) && (ph > PHASE_PRECHARGE)) {
drive = (k_p * error / k_p_div) +
(k_i * ocpc->integral / k_i_div) +
(k_d * derivative / k_d_div);
@@ -521,23 +515,25 @@ int ocpc_config_secondary_charger(int *desired_input_current,
* desired voltage.
*/
if (ph == PHASE_CV_TRIP) {
- vsys_target = batt.desired_voltage +
- ((i_ma_CC_CV *
- ocpc->combined_rsys_rbatt_mo) / 1000);
+ vsys_target =
+ batt.desired_voltage +
+ ((i_ma_CC_CV * ocpc->combined_rsys_rbatt_mo) / 1000);
CPRINTS_DBG("i_ma_CC_CV = %d", i_ma_CC_CV);
}
if (ph == PHASE_CV_COMPLETE)
- vsys_target = batt.desired_voltage +
- ((batt_info->precharge_current *
- ocpc->combined_rsys_rbatt_mo) / 1000);
+ vsys_target =
+ batt.desired_voltage + ((batt_info->precharge_current *
+ ocpc->combined_rsys_rbatt_mo) /
+ 1000);
/*
* Ensure VSYS is no higher than the specified maximum battery voltage
* plus the voltage drop across the system.
*/
- vsys_target = CLAMP(vsys_target, min_vsys_target,
- batt_info->voltage_max +
- (i_ma * ocpc->combined_rsys_rbatt_mo / 1000));
+ vsys_target =
+ CLAMP(vsys_target, min_vsys_target,
+ batt_info->voltage_max +
+ (i_ma * ocpc->combined_rsys_rbatt_mo / 1000));
/* If we're input current limited, we cannot increase VSYS any more. */
CPRINTS_DBG("OCPC: Inst. Input Current: %dmA (Limit: %dmA)",
@@ -550,7 +546,7 @@ int ocpc_config_secondary_charger(int *desired_input_current,
* 95% of the limit.
*/
if (ocpc->secondary_ibus_ma >=
- (*desired_input_current * 95 / 100))
+ (*desired_input_current * 95 / 100))
icl_reached = true;
}
@@ -635,9 +631,8 @@ void ocpc_get_adcs(struct ocpc_data *ocpc)
ocpc->isys_ma = val;
}
-__overridable void ocpc_get_pid_constants(int *kp, int *kp_div,
- int *ki, int *ki_div,
- int *kd, int *kd_div)
+__overridable void ocpc_get_pid_constants(int *kp, int *kp_div, int *ki,
+ int *ki_div, int *kd, int *kd_div)
{
}
@@ -647,8 +642,8 @@ static enum ec_error_list ocpc_precharge_enable(bool enable)
int rv = charger_enable_linear_charge(CHARGER_PRIMARY, enable);
if (rv)
- CPRINTS("OCPC: Failed to %sble linear charge!", enable ? "ena"
- : "dis");
+ CPRINTS("OCPC: Failed to %sble linear charge!",
+ enable ? "ena" : "dis");
return rv;
}
@@ -669,8 +664,9 @@ void ocpc_reset(struct ocpc_data *ocpc)
*/
if (ocpc->active_chg_chip > CHARGER_PRIMARY) {
voltage = (batt.voltage > 0 &&
- !(batt.flags & BATT_FLAG_BAD_VOLTAGE)) ?
- batt.voltage : battery_get_info()->voltage_normal;
+ !(batt.flags & BATT_FLAG_BAD_VOLTAGE)) ?
+ batt.voltage :
+ battery_get_info()->voltage_normal;
CPRINTS("OCPC: C%d Init VSYS to %dmV", ocpc->active_chg_chip,
voltage);
charger_set_voltage(ocpc->active_chg_chip, voltage);
@@ -702,7 +698,7 @@ void ocpc_init(struct ocpc_data *ocpc)
board_ocpc_init(ocpc);
}
-static int command_ocpcdebug(int argc, char **argv)
+static int command_ocpcdebug(int argc, const char **argv)
{
if (argc < 2)
return EC_ERROR_PARAM_COUNT;
@@ -732,7 +728,7 @@ DECLARE_SAFE_CONSOLE_COMMAND(ocpcdebug, command_ocpcdebug,
"Each segment is 5% of current target. All shows"
" both. Disable shows no debug output.");
-static int command_ocpcpid(int argc, char **argv)
+static int command_ocpcpid(int argc, const char **argv)
{
int *num, *denom;
diff --git a/common/onewire.c b/common/onewire.c
index cdb5837255..0b109bbdcd 100644
--- a/common/onewire.c
+++ b/common/onewire.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,16 +16,19 @@
* Note that these timing are actually _longer_ than legacy 1-wire standard
* speed because we're running the 1-wire bus at 3.3V instead of 5V.
*/
-#define T_RSTL 602 /* Reset low pulse; 600-960 us */
-#define T_MSP 72 /* Presence detect sample time; 70-75 us */
-#define T_RSTH (68 + 260 + 5 + 2) /* Reset high; tPDHmax + tPDLmax + tRECmin */
-#define T_SLOT 70 /* Timeslot; >67 us */
-#define T_W0L 63 /* Write 0 low; 62-120 us */
-#define T_W1L 7 /* Write 1 low; 5-15 us */
-#define T_RL 7 /* Read low; 5-15 us */
-#define T_MSR 9 /* Read sample time; <15 us. Must be at least 200 ns after
- * T_RL since that's how long the signal takes to be pulled
- * up on our board. */
+#define T_RSTL 602 /* Reset low pulse; 600-960 us */
+#define T_MSP 72 /* Presence detect sample time; 70-75 us */
+#define T_RSTH \
+ (68 + 260 + 5 + 2) /* Reset high; tPDHmax + tPDLmax + tRECmin \
+ */
+#define T_SLOT 70 /* Timeslot; >67 us */
+#define T_W0L 63 /* Write 0 low; 62-120 us */
+#define T_W1L 7 /* Write 1 low; 5-15 us */
+#define T_RL 7 /* Read low; 5-15 us */
+#define T_MSR \
+ 9 /* Read sample time; <15 us. Must be at least 200 ns after \
+ * T_RL since that's how long the signal takes to be pulled \
+ * up on our board. */
/**
* Output low on the bus for <usec> us, then switch back to open-drain input.
@@ -98,7 +101,6 @@ static void writebit(int bit)
interrupt_enable();
udelay(T_SLOT - T_W0L);
}
-
}
int onewire_reset(void)
@@ -133,7 +135,7 @@ int onewire_read(void)
int i;
for (i = 0; i < 8; i++)
- data |= readbit() << i; /* LSB first */
+ data |= readbit() << i; /* LSB first */
return data;
}
@@ -143,5 +145,5 @@ void onewire_write(int data)
int i;
for (i = 0; i < 8; i++)
- writebit((data >> i) & 0x01); /* LSB first */
+ writebit((data >> i) & 0x01); /* LSB first */
}
diff --git a/common/online_calibration.c b/common/online_calibration.c
index 6ff46f4714..2d79c6ae1d 100644
--- a/common/online_calibration.c
+++ b/common/online_calibration.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -202,8 +202,7 @@ void online_calibration_init(void)
void *type_specific_data = NULL;
s->online_calib_data->last_temperature = -1;
- type_specific_data =
- s->online_calib_data->type_specific_data;
+ type_specific_data = s->online_calib_data->type_specific_data;
if (!type_specific_data)
continue;
diff --git a/common/panic_output.c b/common/panic_output.c
index 45fd1f732a..e5a184be27 100644
--- a/common/panic_output.c
+++ b/common/panic_output.c
@@ -1,8 +1,9 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "cpu.h"
@@ -30,17 +31,13 @@ static struct panic_data zephyr_panic_data;
#define CONFIG_PANIC_DATA_BASE (&zephyr_panic_data)
#endif
/* Panic data goes at the end of RAM. */
-static struct panic_data * const pdata_ptr = PANIC_DATA_PTR;
+static struct panic_data *const pdata_ptr = PANIC_DATA_PTR;
/* Common SW Panic reasons strings */
-const char * const panic_sw_reasons[] = {
+const char *const panic_sw_reasons[] = {
#ifdef CONFIG_SOFTWARE_PANIC
- "PANIC_SW_DIV_ZERO",
- "PANIC_SW_STACK_OVERFLOW",
- "PANIC_SW_PD_CRASH",
- "PANIC_SW_ASSERT",
- "PANIC_SW_WATCHDOG",
- "PANIC_SW_RNG",
+ "PANIC_SW_DIV_ZERO", "PANIC_SW_STACK_OVERFLOW", "PANIC_SW_PD_CRASH",
+ "PANIC_SW_ASSERT", "PANIC_SW_WATCHDOG", "PANIC_SW_RNG",
"PANIC_SW_PMIC_FAULT",
#endif
};
@@ -52,8 +49,7 @@ const char * const panic_sw_reasons[] = {
*/
int panic_sw_reason_is_valid(uint32_t reason)
{
- return (IS_ENABLED(CONFIG_SOFTWARE_PANIC) &&
- reason >= PANIC_SW_BASE &&
+ return (IS_ENABLED(CONFIG_SOFTWARE_PANIC) && reason >= PANIC_SW_BASE &&
(reason - PANIC_SW_BASE) < ARRAY_SIZE(panic_sw_reasons));
}
@@ -125,7 +121,7 @@ void panic_reboot(void)
}
/* Complete the processing of a panic, after the initial message is shown */
-static noreturn void complete_panic(int linenum)
+test_mockable_static_noreturn void complete_panic(int linenum)
{
if (IS_ENABLED(CONFIG_SOFTWARE_PANIC))
software_panic(PANIC_SW_ASSERT, linenum);
@@ -143,8 +139,8 @@ void panic_assert_fail(const char *fname, int linenum)
void panic_assert_fail(const char *msg, const char *func, const char *fname,
int linenum)
{
- panic_printf("\nASSERTION FAILURE '%s' in %s() at %s:%d\n",
- msg, func, fname, linenum);
+ panic_printf("\nASSERTION FAILURE '%s' in %s() at %s:%d\n", msg, func,
+ fname, linenum);
complete_panic(linenum);
}
#endif
@@ -179,9 +175,8 @@ uintptr_t get_panic_data_start(void)
if (IS_ENABLED(CONFIG_BOARD_NATIVE_POSIX))
return (uintptr_t)pdata_ptr;
- return ((uintptr_t)CONFIG_PANIC_DATA_BASE
- + CONFIG_PANIC_DATA_SIZE
- - pdata_ptr->struct_size);
+ return ((uintptr_t)CONFIG_PANIC_DATA_BASE + CONFIG_PANIC_DATA_SIZE -
+ pdata_ptr->struct_size);
}
static uint32_t get_panic_data_size(void)
@@ -212,7 +207,7 @@ struct panic_data *get_panic_data_write(void)
* and magic is safe because it is always placed at the
* end of RAM.
*/
- struct panic_data * const pdata_ptr = PANIC_DATA_PTR;
+ struct panic_data *const pdata_ptr = PANIC_DATA_PTR;
const struct jump_data *jdata_ptr;
uintptr_t data_begin;
size_t move_size;
@@ -249,8 +244,8 @@ struct panic_data *get_panic_data_write(void)
* anything and can just return pdata_ptr (clear memory, set magic
* and struct_size first).
*/
- if (jdata_ptr->magic != JUMP_DATA_MAGIC ||
- jdata_ptr->version < 1 || jdata_ptr->version > 3) {
+ if (jdata_ptr->magic != JUMP_DATA_MAGIC || jdata_ptr->version < 1 ||
+ jdata_ptr->version > 3) {
memset(pdata_ptr, 0, CONFIG_PANIC_DATA_SIZE);
pdata_ptr->magic = PANIC_DATA_MAGIC;
pdata_ptr->struct_size = CONFIG_PANIC_DATA_SIZE;
@@ -273,7 +268,8 @@ struct panic_data *get_panic_data_write(void)
if (move_size != 0) {
/* Move jump_tags and jump_data */
- memmove((void *)(data_begin - delta), (void *)data_begin, move_size);
+ memmove((void *)(data_begin - delta), (void *)data_begin,
+ move_size);
}
/*
@@ -312,6 +308,10 @@ DECLARE_HOOK(HOOK_CHIPSET_RESET, panic_init, HOOK_PRIO_LAST);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winfinite-recursion"
#endif /* __clang__ */
+#if __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winfinite-recursion"
+#endif /* __GNUC__ >= 12 */
static void stack_overflow_recurse(int n)
{
ccprintf("+%d", n);
@@ -322,7 +322,7 @@ static void stack_overflow_recurse(int n)
*/
msleep(10);
- stack_overflow_recurse(n+1);
+ stack_overflow_recurse(n + 1);
/*
* Do work after the recursion, or else the compiler uses tail-chaining
@@ -330,6 +330,9 @@ static void stack_overflow_recurse(int n)
*/
ccprintf("-%d", n);
}
+#if __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif /* __GNUC__ >= 12 */
#ifdef __clang__
#pragma clang diagnostic pop
#endif /* __clang__ */
@@ -338,7 +341,7 @@ static void stack_overflow_recurse(int n)
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_CRASH
-static int command_crash(int argc, char **argv)
+static int command_crash(int argc, const char **argv)
{
if (argc < 2)
return EC_ERROR_PARAM1;
@@ -382,22 +385,23 @@ static int command_crash(int argc, char **argv)
return EC_ERROR_UNKNOWN;
}
DECLARE_CONSOLE_COMMAND(crash, command_crash,
- "[assert | divzero | udivzero"
+ "[assert | divzero | udivzero"
#ifdef CONFIG_CMD_STACKOVERFLOW
" | stack"
#endif
" | unaligned | watchdog | hang]",
- "Crash the system (for testing)");
+ "Crash the system (for testing)");
#endif /* CONFIG_CMD_CRASH */
-static int command_panicinfo(int argc, char **argv)
+static int command_panicinfo(int argc, const char **argv)
{
- struct panic_data * const pdata_ptr = panic_get_data();
+ struct panic_data *const pdata_ptr = panic_get_data();
if (pdata_ptr) {
ccprintf("Saved panic data:%s\n",
(pdata_ptr->flags & PANIC_DATA_FLAG_OLD_CONSOLE ?
- "" : " (NEW)"));
+ "" :
+ " (NEW)"));
panic_data_print(pdata_ptr);
@@ -405,12 +409,11 @@ static int command_panicinfo(int argc, char **argv)
pdata_ptr->flags |= PANIC_DATA_FLAG_OLD_CONSOLE;
} else {
ccprintf("No saved panic data available "
- "or panic data can't be safely interpreted.\n");
+ "or panic data can't be safely interpreted.\n");
}
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(panicinfo, command_panicinfo,
- NULL,
+DECLARE_CONSOLE_COMMAND(panicinfo, command_panicinfo, NULL,
"Print info from a previous panic");
/*****************************************************************************/
@@ -421,7 +424,7 @@ host_command_panic_info(struct host_cmd_handler_args *args)
{
uint32_t pdata_size = get_panic_data_size();
uintptr_t pdata_start = get_panic_data_start();
- struct panic_data * pdata;
+ struct panic_data *pdata;
if (pdata_start && pdata_size > 0) {
ASSERT(pdata_size <= args->response_max);
@@ -437,6 +440,5 @@ host_command_panic_info(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_PANIC_INFO,
- host_command_panic_info,
+DECLARE_HOST_COMMAND(EC_CMD_GET_PANIC_INFO, host_command_panic_info,
EC_VER_MASK(0));
diff --git a/common/pd_log.c b/common/pd_log.c
index 3708aad72e..477f8327eb 100644
--- a/common/pd_log.c
+++ b/common/pd_log.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -21,8 +21,7 @@ BUILD_ASSERT(PD_LOG_SIZE_MASK == EVENT_LOG_SIZE_MASK);
BUILD_ASSERT(PD_LOG_TIMESTAMP_SHIFT == EVENT_LOG_TIMESTAMP_SHIFT);
BUILD_ASSERT(PD_EVENT_NO_ENTRY == EVENT_LOG_NO_ENTRY);
-void pd_log_event(uint8_t type, uint8_t size_port,
- uint16_t data, void *payload)
+void pd_log_event(uint8_t type, uint8_t size_port, uint16_t data, void *payload)
{
uint32_t timestamp = get_time().val >> PD_LOG_TIMESTAMP_SHIFT;
@@ -48,8 +47,8 @@ void pd_log_recv_vdm(int port, int cnt, uint32_t *payload)
return;
if (r->type != PD_EVENT_NO_ENTRY) {
- timestamp = (get_time().val >> PD_LOG_TIMESTAMP_SHIFT)
- - r->timestamp;
+ timestamp = (get_time().val >> PD_LOG_TIMESTAMP_SHIFT) -
+ r->timestamp;
log_add_event(r->type, size_port, r->data, r->payload,
timestamp);
/* record that we have enqueued new content */
@@ -84,8 +83,7 @@ dequeue_retry:
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PD_GET_LOG_ENTRY,
- hc_pd_get_log_entry,
+DECLARE_HOST_COMMAND(EC_CMD_PD_GET_LOG_ENTRY, hc_pd_get_log_entry,
EC_VER_MASK(0));
static enum ec_status hc_pd_write_log_entry(struct host_cmd_handler_args *args)
@@ -117,8 +115,7 @@ static enum ec_status hc_pd_write_log_entry(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PD_WRITE_LOG_ENTRY,
- hc_pd_write_log_entry,
+DECLARE_HOST_COMMAND(EC_CMD_PD_WRITE_LOG_ENTRY, hc_pd_write_log_entry,
EC_VER_MASK(0));
#else /* !HAS_TASK_HOSTCMD */
/* we are a PD accessory, send back the events as a VDM (VDO_CMD_GET_LOG) */
diff --git a/common/peci.c b/common/peci.c
index e0f03c95dd..b124d6b67b 100644
--- a/common/peci.c
+++ b/common/peci.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,12 +8,13 @@
#include "chipset.h"
#include "console.h"
#include "peci.h"
+#include "printf.h"
#include "util.h"
static int peci_get_cpu_temp(int *cpu_temp)
{
int rv;
- uint8_t r_buf[PECI_GET_TEMP_READ_LENGTH] = {0};
+ uint8_t r_buf[PECI_GET_TEMP_READ_LENGTH] = { 0 };
struct peci_data peci = {
.cmd_code = PECI_CMD_GET_TEMP,
.addr = PECI_TARGET_ADDRESS,
@@ -72,10 +73,10 @@ int peci_temp_sensor_get_val(int idx, int *temp_ptr)
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_PECI
-static int peci_cmd(int argc, char **argv)
+static int peci_cmd(int argc, const char **argv)
{
- uint8_t r_buf[PECI_READ_DATA_FIFO_SIZE] = {0};
- uint8_t w_buf[PECI_WRITE_DATA_FIFO_SIZE] = {0};
+ uint8_t r_buf[PECI_READ_DATA_FIFO_SIZE] = { 0 };
+ uint8_t w_buf[PECI_WRITE_DATA_FIFO_SIZE] = { 0 };
struct peci_data peci = {
.w_buf = w_buf,
.r_buf = r_buf,
@@ -139,15 +140,20 @@ static int peci_cmd(int argc, char **argv)
if (peci_transaction(&peci)) {
ccprintf("PECI transaction error\n");
return EC_ERROR_UNKNOWN;
+ } else {
+ char str_buf[hex_str_buf_size(peci.r_len)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(r_buf, sizeof(str_buf)));
+ ccprintf("PECI read data: %s\n", str_buf);
+
+ return EC_SUCCESS;
}
- ccprintf("PECI read data: %ph\n", HEX_BUF(r_buf, peci.r_len));
- return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(peci, peci_cmd,
- "addr wlen rlen cmd timeout(us)",
+DECLARE_CONSOLE_COMMAND(peci, peci_cmd, "addr wlen rlen cmd timeout(us)",
"PECI command");
-static int command_peci_temp(int argc, char **argv)
+static int command_peci_temp(int argc, const char **argv)
{
int t;
@@ -159,7 +165,6 @@ static int command_peci_temp(int argc, char **argv)
ccprintf("CPU temp: %d K, %d C\n", t, K_TO_C(t));
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp,
- NULL,
+DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp, NULL,
"Print CPU temperature");
#endif /* CONFIG_CMD_PECI */
diff --git a/common/peripheral.c b/common/peripheral.c
index e70ec19347..557aa0ed6f 100644
--- a/common/peripheral.c
+++ b/common/peripheral.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -30,7 +30,8 @@ static enum ec_status hc_locate_chip(struct host_cmd_handler_args *args)
#endif /* CONFIG_CBI_EEPROM */
break;
case EC_CHIP_TYPE_TCPC:
-#if defined(CONFIG_USB_POWER_DELIVERY) && defined(CONFIG_USB_PD_PORT_MAX_COUNT) && !defined(CONFIG_USB_PD_TCPC)
+#if defined(CONFIG_USB_POWER_DELIVERY) && \
+ defined(CONFIG_USB_PD_PORT_MAX_COUNT) && !defined(CONFIG_USB_PD_TCPC)
if (params->index >= board_get_usb_pd_port_count())
return EC_RES_OVERFLOW;
resp->bus_type = tcpc_config[params->index].bus_type;
diff --git a/common/peripheral_charger.c b/common/peripheral_charger.c
index 024379fe58..5767315a78 100644
--- a/common/peripheral_charger.c
+++ b/common/peripheral_charger.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,7 +23,7 @@
/* Host event queue. Shared by all ports. */
static struct queue const host_events =
- QUEUE_NULL(PCHG_EVENT_QUEUE_SIZE, uint32_t);
+ QUEUE_NULL(PCHG_EVENT_QUEUE_SIZE, uint32_t);
struct mutex host_event_mtx;
static void pchg_queue_event(struct pchg *ctx, enum pchg_event event)
@@ -59,7 +59,7 @@ static void pchg_queue_host_event(struct pchg *ctx, uint32_t event)
static const char *_text_state(enum pchg_state state)
{
/* TODO: Use "S%d" for normal build. */
- static const char * const state_names[] = EC_PCHG_STATE_TEXT;
+ static const char *const state_names[] = EC_PCHG_STATE_TEXT;
BUILD_ASSERT(ARRAY_SIZE(state_names) == PCHG_STATE_COUNT);
if (state >= sizeof(state_names))
@@ -71,7 +71,7 @@ static const char *_text_state(enum pchg_state state)
static const char *_text_event(enum pchg_event event)
{
/* TODO: Use "S%d" for normal build. */
- static const char * const event_names[] = {
+ static const char *const event_names[] = {
[PCHG_EVENT_NONE] = "NONE",
[PCHG_EVENT_IRQ] = "IRQ",
[PCHG_EVENT_RESET] = "RESET",
@@ -118,7 +118,8 @@ static void _clear_port(struct pchg *ctx)
}
__overridable void board_pchg_power_on(int port, bool on)
-{}
+{
+}
static enum pchg_state pchg_reset(struct pchg *ctx)
{
@@ -504,7 +505,7 @@ static int pchg_run(struct pchg *ctx)
/* Don't wake up if the lid is closed. */
return 0;
return (ctx->event == PCHG_EVENT_DEVICE_DETECTED ||
- ctx->event == PCHG_EVENT_DEVICE_LOST);
+ ctx->event == PCHG_EVENT_DEVICE_LOST);
}
if (ctx->event == PCHG_EVENT_CHARGE_UPDATE)
@@ -538,25 +539,37 @@ void pchg_irq(enum gpio_signal signal)
}
}
-
static void pchg_startup(void)
{
struct pchg *ctx;
int p;
+ int active_pchg_count = 0;
+ int rv;
CPRINTS("%s", __func__);
queue_init(&host_events);
for (p = 0; p < pchg_count; p++) {
+ rv = EC_SUCCESS;
ctx = &pchgs[p];
_clear_port(ctx);
ctx->mode = PCHG_MODE_NORMAL;
+ gpio_disable_interrupt(ctx->cfg->irq_pin);
board_pchg_power_on(p, 1);
ctx->cfg->drv->reset(ctx);
- gpio_enable_interrupt(ctx->cfg->irq_pin);
+ if (ctx->cfg->drv->get_chip_info)
+ rv = ctx->cfg->drv->get_chip_info(ctx);
+ if (rv == EC_SUCCESS) {
+ gpio_enable_interrupt(ctx->cfg->irq_pin);
+ active_pchg_count++;
+ } else {
+ CPRINTS("ERR: Failed to probe P%d", p);
+ board_pchg_power_on(p, 0);
+ }
}
- task_wake(TASK_ID_PCHG);
+ if (active_pchg_count)
+ task_wake(TASK_ID_PCHG);
}
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, pchg_startup, HOOK_PRIO_DEFAULT);
@@ -630,8 +643,8 @@ static enum ec_status hc_pchg(struct host_cmd_handler_args *args)
ctx = &pchgs[port];
- if (ctx->state == PCHG_STATE_CONNECTED
- && ctx->battery_percent >= ctx->cfg->full_percent)
+ if (ctx->state == PCHG_STATE_CONNECTED &&
+ ctx->battery_percent >= ctx->cfg->full_percent)
r->state = PCHG_STATE_FULL;
else
r->state = ctx->state;
@@ -643,7 +656,8 @@ static enum ec_status hc_pchg(struct host_cmd_handler_args *args)
r->dropped_host_event_count = ctx->dropped_host_event_count;
args->response_size = args->version == 1 ?
- sizeof(struct ec_response_pchg) : sizeof(*r);
+ sizeof(struct ec_response_pchg) :
+ sizeof(*r);
return EC_RES_SUCCESS;
}
@@ -743,7 +757,7 @@ static enum ec_status hc_pchg_update(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_PCHG_UPDATE, hc_pchg_update, EC_VER_MASK(0));
-static int cc_pchg(int argc, char **argv)
+static int cc_pchg(int argc, const char **argv)
{
int port;
char *end;
@@ -758,11 +772,11 @@ static int cc_pchg(int argc, char **argv)
ctx = &pchgs[port];
if (argc == 2) {
- ccprintf("P%d STATE_%s EVENT_%s SOC=%d%%\n",
- port, _text_state(ctx->state), _text_event(ctx->event),
+ ccprintf("P%d STATE_%s EVENT_%s SOC=%d%%\n", port,
+ _text_state(ctx->state), _text_event(ctx->event),
ctx->battery_percent);
- ccprintf("error=0x%x dropped=%u fw_version=0x%x\n",
- ctx->error, ctx->dropped_event_count, ctx->fw_version);
+ ccprintf("error=0x%x dropped=%u fw_version=0x%x\n", ctx->error,
+ ctx->dropped_event_count, ctx->fw_version);
return EC_SUCCESS;
}
diff --git a/common/port80.c b/common/port80.c
index 231181cad8..abead59cd9 100644
--- a/common/port80.c
+++ b/common/port80.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,11 +11,12 @@
#include "hooks.h"
#include "host_command.h"
#include "port80.h"
+#include "printf.h"
#include "task.h"
#include "timer.h"
#include "util.h"
-#define CPRINTF(format, args...) cprintf(CC_PORT80, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_PORT80, format, ##args)
#ifdef CONFIG_PORT80_4_BYTE
typedef uint32_t port80_code_t;
@@ -23,7 +24,7 @@ typedef uint32_t port80_code_t;
typedef uint16_t port80_code_t;
#endif
static port80_code_t history[CONFIG_PORT80_HISTORY_LEN];
-static int writes; /* Number of port 80 writes so far */
+static int writes; /* Number of port 80 writes so far */
static uint16_t last_boot; /* Last code from previous boot */
static int scroll;
@@ -39,6 +40,8 @@ DECLARE_DEFERRED(port80_dump_buffer);
void port_80_write(int data)
{
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
+
/*
* By default print_in_int is disabled if:
* 1. CONFIG_BRINGUP is not defined
@@ -53,15 +56,20 @@ void port_80_write(int data)
* dump the current port80 buffer to EC console. This is to allow
* developers to help debug BIOS progress by tracing port80 messages.
*/
- if (print_in_int)
- CPRINTF("%c[%pT Port 80: 0x%02x]",
- scroll ? '\n' : '\r', PRINTF_TIMESTAMP_NOW, data);
+ if (print_in_int) {
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("%c[%s Port 80: 0x%02x]", scroll ? '\n' : '\r', ts_str,
+ data);
+ }
- hook_call_deferred(&port80_dump_buffer_data, 4 * SECOND);
+ if (!IS_ENABLED(CONFIG_PORT80_QUIET)) {
+ hook_call_deferred(&port80_dump_buffer_data, 4 * SECOND);
+ }
/* Save current port80 code if system is resetting */
if (data == PORT_80_EVENT_RESET && writes) {
- port80_code_t prev = history[(writes-1) % ARRAY_SIZE(history)];
+ port80_code_t prev =
+ history[(writes - 1) % ARRAY_SIZE(history)];
/*
* last_boot only reports 8-bit codes.
@@ -127,7 +135,7 @@ static void port80_dump_buffer(void)
/*****************************************************************************/
/* Console commands */
-static int command_port80(int argc, char **argv)
+static int command_port80(int argc, const char **argv)
{
/*
* 'port80 scroll' toggles whether port 80 output begins with a newline
@@ -154,8 +162,7 @@ static int command_port80(int argc, char **argv)
port80_dump_buffer();
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(port80, command_port80,
- "[scroll | intprint | flush]",
+DECLARE_CONSOLE_COMMAND(port80, command_port80, "[scroll | intprint | flush]",
"Print port80 writes or toggle port80 scrolling");
enum ec_status port80_last_boot(struct host_cmd_handler_args *args)
@@ -187,24 +194,23 @@ static enum ec_status port80_command_read(struct host_cmd_handler_args *args)
} else if (p->subcmd == EC_PORT80_READ_BUFFER) {
/* do not allow bad offset or size */
if (offset >= ARRAY_SIZE(history) || entries == 0 ||
- entries > args->response_max)
+ entries > args->response_max)
return EC_RES_INVALID_PARAM;
for (i = 0; i < entries; i++) {
- uint16_t e = history[(i + offset) %
- ARRAY_SIZE(history)];
+ uint16_t e =
+ history[(i + offset) % ARRAY_SIZE(history)];
rsp->data.codes[i] = e;
}
- args->response_size = entries*sizeof(uint16_t);
+ args->response_size = entries * sizeof(uint16_t);
return EC_RES_SUCCESS;
}
return EC_RES_INVALID_PARAM;
}
-DECLARE_HOST_COMMAND(EC_CMD_PORT80_READ,
- port80_command_read,
- EC_VER_MASK(0) | EC_VER_MASK(1));
+DECLARE_HOST_COMMAND(EC_CMD_PORT80_READ, port80_command_read,
+ EC_VER_MASK(0) | EC_VER_MASK(1));
static void port80_log_resume(void)
{
diff --git a/common/power_button.c b/common/power_button.c
index 20c468301c..36d7e510d2 100644
--- a/common/power_button.c
+++ b/common/power_button.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
/* Power button module for Chrome EC */
#include "button.h"
+#include "chipset.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
@@ -21,14 +22,14 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SWITCH, outstr)
-#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ##args)
/* By default the power button is active low */
#ifndef CONFIG_POWER_BUTTON_FLAGS
#define CONFIG_POWER_BUTTON_FLAGS 0
#endif
-static int debounced_power_pressed; /* Debounced power button state */
+static int debounced_power_pressed; /* Debounced power button state */
static int simulate_power_pressed;
static volatile int power_button_is_stable = 1;
@@ -41,8 +42,11 @@ static const struct button_config power_button = {
int power_button_signal_asserted(void)
{
- return !!(gpio_get_level(power_button.gpio)
- == (power_button.flags & BUTTON_FLAG_ACTIVE_HIGH) ? 1 : 0);
+ return !!(
+ gpio_get_level(power_button.gpio) ==
+ (power_button.flags & BUTTON_FLAG_ACTIVE_HIGH) ?
+ 1 :
+ 0);
}
/**
@@ -93,8 +97,8 @@ int power_button_wait_for_release(int timeout_us)
* the power button is debounced but not changed, or the power
* button has not been debounced.
*/
- task_wait_event(MIN(power_button.debounce_us,
- deadline.val - now.val));
+ task_wait_event(
+ MIN(power_button.debounce_us, deadline.val - now.val));
}
CPRINTS("%s released in time", power_button.name);
@@ -132,6 +136,10 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP, pb_chipset_startup, HOOK_PRIO_DEFAULT);
static void pb_chipset_shutdown(void)
{
+ /* Don't set AP_IDLE if shutting down due to power failure. */
+ if (chipset_get_shutdown_reason() == CHIPSET_SHUTDOWN_POWERFAIL)
+ return;
+
chip_save_reset_flags(chip_read_reset_flags() | EC_RESET_FLAG_AP_IDLE);
system_set_reset_flags(EC_RESET_FLAG_AP_IDLE);
CPRINTS("Saved AP_IDLE flag");
@@ -164,8 +172,8 @@ static void power_button_change_deferred(void)
debounced_power_pressed = new_pressed;
power_button_is_stable = 1;
- CPRINTS("%s %s",
- power_button.name, new_pressed ? "pressed" : "released");
+ CPRINTS("%s %s", power_button.name,
+ new_pressed ? "pressed" : "released");
/* Call hooks */
hook_notify(HOOK_POWER_BUTTON_CHANGE);
@@ -192,35 +200,38 @@ void power_button_interrupt(enum gpio_signal signal)
power_button.debounce_us);
}
-/*****************************************************************************/
-/* Console commands */
-
-static int command_powerbtn(int argc, char **argv)
+void power_button_simulate_press(unsigned int duration)
{
- int ms = 200; /* Press duration in ms */
- char *e;
-
- if (argc > 1) {
- ms = strtoi(argv[1], &e, 0);
- if (*e)
- return EC_ERROR_PARAM1;
- }
-
- ccprintf("Simulating %d ms %s press.\n", ms, power_button.name);
+ ccprintf("Simulating %d ms %s press.\n", duration, power_button.name);
simulate_power_pressed = 1;
power_button_is_stable = 0;
hook_call_deferred(&power_button_change_deferred_data, 0);
- if (ms > 0)
- msleep(ms);
+ if (duration > 0)
+ msleep(duration);
ccprintf("Simulating %s release.\n", power_button.name);
simulate_power_pressed = 0;
power_button_is_stable = 0;
hook_call_deferred(&power_button_change_deferred_data, 0);
+}
+
+/*****************************************************************************/
+/* Console commands */
+
+static int command_powerbtn(int argc, const char **argv)
+{
+ int ms = 200; /* Press duration in ms */
+ char *e;
+
+ if (argc > 1) {
+ ms = strtoi(argv[1], &e, 0);
+ if (*e || ms < 0)
+ return EC_ERROR_PARAM1;
+ }
+ power_button_simulate_press(ms);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn,
- "[msec]",
+DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn, "[msec]",
"Simulate power button press");
diff --git a/common/power_button_x86.c b/common/power_button_x86.c
index fd24f7a75b..efa51530e5 100644
--- a/common/power_button_x86.c
+++ b/common/power_button_x86.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,7 +23,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SWITCH, outstr)
-#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ##args)
/*
* x86 chipsets have a hardware timer on the power button input which causes
@@ -54,14 +54,14 @@
* to host v v
* @S0 make code break code
*/
-#define PWRBTN_DELAY_T0 (32 * MSEC) /* 32ms (PCH requires >16ms) */
-#define PWRBTN_DELAY_T1 (4 * SECOND - PWRBTN_DELAY_T0) /* 4 secs - t0 */
+#define PWRBTN_DELAY_T0 (32 * MSEC) /* 32ms (PCH requires >16ms) */
+#define PWRBTN_DELAY_T1 (4 * SECOND - PWRBTN_DELAY_T0) /* 4 secs - t0 */
/*
* Length of time to stretch initial power button press to give chipset a
* chance to wake up (~100ms) and react to the press (~16ms). Also used as
* pulse length for simulated power button presses when the system is off.
*/
-#define PWRBTN_INITIAL_US (200 * MSEC)
+#define PWRBTN_INITIAL_US (200 * MSEC)
enum power_button_state {
/* Button up; state machine idle */
@@ -92,18 +92,9 @@ enum power_button_state {
};
static enum power_button_state pwrbtn_state = PWRBTN_STATE_IDLE;
-static const char * const state_names[] = {
- "idle",
- "pressed",
- "t0",
- "t1",
- "held",
- "lid-open",
- "released",
- "eat-release",
- "init-on",
- "recovery",
- "was-off",
+static const char *const state_names[] = {
+ "idle", "pressed", "t0", "t1", "held", "lid-open",
+ "released", "eat-release", "init-on", "recovery", "was-off",
};
/*
@@ -139,7 +130,7 @@ static void set_pwrbtn_to_pch(int high, int init)
*/
#ifdef CONFIG_CHARGER
if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !high &&
- (charge_want_shutdown() || charge_prevent_power_on(!init))) {
+ (charge_want_shutdown() || charge_prevent_power_on(!init))) {
CPRINTS("PB PCH pwrbtn ignored due to battery level");
high = 1;
}
@@ -346,8 +337,8 @@ static void state_machine(uint64_t tnow)
if (!IS_ENABLED(CONFIG_CHARGER) || charge_prevent_power_on(0)) {
if (tnow >
- (tpb_task_start +
- CONFIG_POWER_BUTTON_INIT_TIMEOUT * SECOND)) {
+ (tpb_task_start +
+ CONFIG_POWER_BUTTON_INIT_TIMEOUT * SECOND)) {
pwrbtn_state = PWRBTN_STATE_IDLE;
break;
}
@@ -366,9 +357,9 @@ static void state_machine(uint64_t tnow)
#ifdef CONFIG_DELAY_DSW_PWROK_TO_PWRBTN
/* Check if power button is ready. If not, we'll come back. */
if (get_time().val - get_time_dsw_pwrok() <
- CONFIG_DSW_PWROK_TO_PWRBTN_US) {
+ CONFIG_DSW_PWROK_TO_PWRBTN_US) {
tnext_state = get_time_dsw_pwrok() +
- CONFIG_DSW_PWROK_TO_PWRBTN_US;
+ CONFIG_DSW_PWROK_TO_PWRBTN_US;
break;
}
#endif
@@ -444,7 +435,7 @@ void power_button_task(void *u)
* early.)
*/
CPRINTS("PB task %d = %s, wait %d", pwrbtn_state,
- state_names[pwrbtn_state], d);
+ state_names[pwrbtn_state], d);
task_wait_event(d);
}
}
@@ -533,7 +524,6 @@ static enum ec_status hc_config_powerbtn_x86(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_CONFIG_POWER_BUTTON, hc_config_powerbtn_x86,
EC_VER_MASK(0));
-
/*
* Currently, the only reason why we disable power button pulse is to allow
* detachable menu on AP to use power button for selection purpose without
@@ -554,8 +544,8 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, power_button_pulse_setting_reset,
DECLARE_HOOK(HOOK_CHIPSET_RESUME, power_button_pulse_setting_reset,
HOOK_PRIO_DEFAULT);
-#define POWER_BUTTON_SYSJUMP_TAG 0x5042 /* PB */
-#define POWER_BUTTON_HOOK_VERSION 1
+#define POWER_BUTTON_SYSJUMP_TAG 0x5042 /* PB */
+#define POWER_BUTTON_HOOK_VERSION 1
static void power_button_pulse_setting_restore_state(void)
{
@@ -574,8 +564,7 @@ DECLARE_HOOK(HOOK_INIT, power_button_pulse_setting_restore_state,
static void power_button_pulse_setting_preserve_state(void)
{
- system_add_jump_tag(POWER_BUTTON_SYSJUMP_TAG,
- POWER_BUTTON_HOOK_VERSION,
+ system_add_jump_tag(POWER_BUTTON_SYSJUMP_TAG, POWER_BUTTON_HOOK_VERSION,
sizeof(power_button_pulse_enabled),
&power_button_pulse_enabled);
}
diff --git a/common/printf.c b/common/printf.c
index e302708a9b..d2cc78f5aa 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -1,10 +1,11 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Printf-like functionality for Chrome EC */
+#include "builtin/assert.h"
#include "console.h"
#include "printf.h"
#include "timer.h"
@@ -12,24 +13,7 @@
static const char error_str[] = "ERROR";
-#define MAX_FORMAT 1024 /* Maximum chars in a single format field */
-
-#ifndef CONFIG_DEBUG_PRINTF
-static inline int divmod(uint64_t *n, int d)
-{
- return uint64divmod(n, d);
-}
-
-#else /* CONFIG_DEBUG_PRINTF */
-/* if we are optimizing for size, remove the 64-bit support */
-#define NO_UINT64_SUPPORT
-static inline int divmod(uint32_t *n, int d)
-{
- int r = *n % d;
- *n /= d;
- return r;
-}
-#endif
+#define MAX_FORMAT 1024 /* Maximum chars in a single format field */
/**
* Convert the lowest nibble of a number to hex
@@ -47,27 +31,118 @@ static int hexdigit(int c)
}
/* Flags for vfnprintf() flags */
-#define PF_LEFT BIT(0) /* Left-justify */
-#define PF_PADZERO BIT(1) /* Pad with 0's not spaces */
-#define PF_SIGN BIT(2) /* Add sign (+) for a positive number */
+#define PF_LEFT BIT(0) /* Left-justify */
+#define PF_PADZERO BIT(1) /* Pad with 0's not spaces */
+#define PF_SIGN BIT(2) /* Add sign (+) for a positive number */
+#define PF_64BIT BIT(3) /* Number is 64-bit */
+
+test_export_static char *uint64_to_str(char *buf, int buf_len, uint64_t val,
+ int precision, int base, bool uppercase)
+{
+ int i;
+ char *str;
+
+ if (buf_len <= 1)
+ return NULL;
+
+ if (base <= 1)
+ return NULL;
+
+ /*
+ * Convert integer to string, starting at end of
+ * buffer and working backwards.
+ */
+ str = buf + buf_len - 1;
+ *(str) = '\0';
+
+ /*
+ * Fixed-point precision must fit in our buffer.
+ * Leave space for "0." and the terminating null.
+ */
+ if (precision > buf_len - 3) {
+ precision = buf_len - 3;
+ if (precision < 0)
+ return NULL;
+ }
+
+ /*
+ * Handle digits to right of decimal for fixed point numbers.
+ */
+ for (i = 0; i < precision; i++)
+ *(--str) = '0' + uint64divmod(&val, 10);
+ if (precision >= 0)
+ *(--str) = '.';
+
+ if (!val)
+ *(--str) = '0';
+
+ while (val) {
+ int digit;
+
+ if (str <= buf)
+ return NULL;
+
+ digit = uint64divmod(&val, base);
+ if (digit < 10)
+ *(--str) = '0' + digit;
+ else if (uppercase)
+ *(--str) = 'A' + digit - 10;
+ else
+ *(--str) = 'a' + digit - 10;
+ }
+
+ return str;
+}
+
+int snprintf_timestamp_now(char *str, size_t size)
+{
+ return snprintf_timestamp(str, size, get_time().val);
+}
+
+int snprintf_timestamp(char *str, size_t size, uint64_t timestamp)
+{
+ int len;
+ int precision;
+ char *tmp_str;
+ char tmp_buf[PRINTF_TIMESTAMP_BUF_SIZE];
+ int base = 10;
-/* Deactivate the PF_64BIT flag is 64-bit support is disabled. */
-#ifdef NO_UINT64_SUPPORT
-#define PF_64BIT 0
-#else
-#define PF_64BIT BIT(3) /* Number is 64-bit */
-#endif
+ if (size == 0)
+ return -EC_ERROR_INVAL;
+
+ /* Ensure string has terminating '\0' in error cases. */
+ str[0] = '\0';
+
+ if (IS_ENABLED(CONFIG_CONSOLE_VERBOSE)) {
+ precision = 6;
+ } else {
+ precision = 3;
+ timestamp /= 1000;
+ }
+
+ tmp_str = uint64_to_str(tmp_buf, sizeof(tmp_buf), timestamp, precision,
+ base, false);
+ if (!tmp_str)
+ return -EC_ERROR_OVERFLOW;
+
+ len = strlen(tmp_str);
+ if (len + 1 > size)
+ return -EC_ERROR_OVERFLOW;
+
+ memcpy(str, tmp_str, len + 1);
+
+ return len;
+}
/*
* Print the buffer as a string of bytes in hex.
* Returns 0 on success or an error on failure.
*/
-static int print_hex_buffer(int (*addchar)(void *context, int c),
- void *context, const char *vstr, int precision,
- int pad_width, int flags)
+static int print_hex_buffer(int (*addchar)(void *context, int c), void *context,
+ const char *vstr, int precision, int pad_width,
+ int flags)
{
-
/*
* Divide pad_width instead of multiplying precision to avoid overflow
* error in the condition. The "/2" and "2*" can be optimized by
@@ -100,6 +175,54 @@ static int print_hex_buffer(int (*addchar)(void *context, int c),
return EC_SUCCESS;
}
+struct hex_char_context {
+ struct hex_buffer_params hex_buf_params;
+ char *str;
+ size_t size;
+};
+
+int add_hex_char(void *context, int c)
+{
+ struct hex_char_context *ctx = context;
+
+ if (ctx->size == 0)
+ return EC_ERROR_OVERFLOW;
+
+ *(ctx->str++) = c;
+ ctx->size--;
+
+ return EC_SUCCESS;
+}
+
+size_t hex_str_buf_size(size_t num_bytes)
+{
+ return 2 * num_bytes + 1;
+}
+
+int snprintf_hex_buffer(char *str, size_t size,
+ const struct hex_buffer_params *params)
+{
+ int rv;
+ struct hex_char_context context = {
+ .hex_buf_params = *params,
+ .str = str,
+ /*
+ * Reserve space for terminating '\0'.
+ */
+ .size = size - 1,
+ };
+
+ if (size == 0)
+ return -EC_ERROR_INVAL;
+
+ rv = print_hex_buffer(add_hex_char, &context, params->buffer,
+ params->size, 0, 0);
+
+ *context.str = '\0';
+
+ return (rv == EC_SUCCESS) ? (context.str - str) : -rv;
+}
+
int vfnprintf(int (*addchar)(void *context, int c), void *context,
const char *format, va_list args)
{
@@ -215,17 +338,15 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
} else {
int base = 10;
-#ifdef NO_UINT64_SUPPORT
- uint32_t v;
-#else
uint64_t v;
-#endif
- int ptrspec;
+
void *ptrval;
/*
* Handle length:
- * %l - DEPRECATED (see below)
+ * %l - supports 64-bit longs, 32-bit longs are
+ * supported with a config flag, see comment
+ * below for more details
* %ll - long long
* %z - size_t
*/
@@ -240,18 +361,23 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
}
/*
- * %l on 32-bit systems is deliberately
- * deprecated. It was originally used as
- * shorthand for 64-bit values. When
+ * The CONFIG_PRINTF_LONG_IS_32BITS flag is
+ * required to enable the %l flag on systems
+ * where it would signify a 32-bit value.
+ * Otherwise, %l on 32-bit systems is
+ * deliberately deprecated. %l was originally
+ * used as shorthand for 64-bit values. When
* compile-time printf format checking was
* enabled, it had to be cleaned up to be
* sizeof(long), which is 32 bits on today's
* ECs. This presents a mismatch which can be
* dangerous if a new-style printf call is
* cherry-picked into an old firmware branch.
- * See crbug.com/984041 for more context.
+ * For more context, see
+ * https://issuetracker.google.com/issues/172210614
*/
- if (!(flags & PF_64BIT)) {
+ if (!IS_ENABLED(CONFIG_PRINTF_LONG_IS_32BITS) &&
+ !(flags & PF_64BIT)) {
format = error_str;
continue;
}
@@ -264,74 +390,11 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
if (c == 'p') {
c = -1;
- ptrspec = *format++;
ptrval = va_arg(args, void *);
- /*
- * Avoid null pointer dereference for %ph and
- * %pb. %pT and %pP can accept null.
- */
- if (ptrval == NULL
- && ptrspec != 'T' && ptrspec != 'P')
- continue;
- /* %pT - print a timestamp. */
- if (ptrspec == 'T' &&
- !IS_ENABLED(NO_UINT64_SUPPORT) &&
- (!IS_ENABLED(CONFIG_ZEPHYR) ||
- IS_ENABLED(CONFIG_PLATFORM_EC_TIMER))) {
+ v = (unsigned long)ptrval;
+ base = 16;
+ if (sizeof(unsigned long) == sizeof(uint64_t))
flags |= PF_64BIT;
- if (ptrval == PRINTF_TIMESTAMP_NOW)
- v = get_time().val;
- else
- v = *(uint64_t *)ptrval;
-
- if (IS_ENABLED(
- CONFIG_CONSOLE_VERBOSE)) {
- precision = 6;
- } else {
- precision = 3;
- v /= 1000;
- }
-
- } else if (ptrspec == 'h') {
- /* %ph - Print a hex byte buffer. */
- struct hex_buffer_params *hexbuf =
- ptrval;
- int rc;
-
- rc = print_hex_buffer(addchar,
- context,
- hexbuf->buffer,
- hexbuf->size,
- 0,
- 0);
-
- if (rc != EC_SUCCESS)
- return rc;
-
- continue;
-
- } else if (ptrspec == 'P') {
- /* %pP - Print a raw pointer. */
- v = (unsigned long)ptrval;
- base = 16;
- if (sizeof(unsigned long) ==
- sizeof(uint64_t))
- flags |= PF_64BIT;
-
- } else if (ptrspec == 'b') {
- /* %pb - Print a binary integer */
- struct binary_print_params *binary =
- ptrval;
-
- v = binary->value;
- pad_width = binary->count;
- flags |= PF_PADZERO;
- base = 2;
-
- } else {
- return EC_ERROR_INVAL;
- }
-
} else if (flags & PF_64BIT) {
v = va_arg(args, uint64_t);
} else {
@@ -339,12 +402,9 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
}
switch (c) {
-#ifdef CONFIG_PRINTF_LEGACY_LI_FORMAT
+#ifdef CONFIG_PRINTF_LONG_IS_32BITS
case 'i':
- /* force 32-bit for compatibility */
- flags &= ~PF_64BIT;
- /* fall-through */
-#endif /* CONFIG_PRINTF_LEGACY_LI_FORMAT */
+#endif /* CONFIG_PRINTF_LONG_IS_32BITS */
case 'd':
if (flags & PF_64BIT) {
if ((int64_t)v < 0) {
@@ -381,41 +441,9 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
if (format == error_str)
continue; /* Bad format specifier */
- /*
- * Convert integer to string, starting at end of
- * buffer and working backwards.
- */
- vstr = intbuf + sizeof(intbuf) - 1;
- *(vstr) = '\0';
-
- /*
- * Fixed-point precision must fit in our buffer.
- * Leave space for "0." and the terminating null.
- */
- if (precision > (int)(sizeof(intbuf) - 3))
- precision = sizeof(intbuf) - 3;
-
- /*
- * Handle digits to right of decimal for fixed point
- * numbers.
- */
- for (vlen = 0; vlen < precision; vlen++)
- *(--vstr) = '0' + divmod(&v, 10);
- if (precision >= 0)
- *(--vstr) = '.';
-
- if (!v)
- *(--vstr) = '0';
-
- while (v) {
- int digit = divmod(&v, base);
- if (digit < 10)
- *(--vstr) = '0' + digit;
- else if (c == 'X')
- *(--vstr) = 'A' + digit - 10;
- else
- *(--vstr) = 'a' + digit - 10;
- }
+ vstr = uint64_to_str(intbuf, sizeof(intbuf), v,
+ precision, base, c == 'X');
+ ASSERT(vstr);
if (sign)
*(--vstr) = sign;
@@ -443,7 +471,6 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
vlen = strnlen(vstr, precision);
}
-
while (vlen < pad_width && !(flags & PF_LEFT)) {
if (addchar(context, flags & PF_PADZERO ? '0' : ' '))
return EC_ERROR_OVERFLOW;
@@ -462,59 +489,3 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
/* If we're still here, we consumed all output */
return EC_SUCCESS;
}
-
-/* Context for snprintf() */
-struct snprintf_context {
- char *str;
- int size;
-};
-
-/**
- * Add a character to the string context.
- *
- * @param context Context receiving character
- * @param c Character to add
- * @return 0 if character added, 1 if character dropped because no space.
- */
-static int snprintf_addchar(void *context, int c)
-{
- struct snprintf_context *ctx = (struct snprintf_context *)context;
-
- if (!ctx->size)
- return 1;
-
- *(ctx->str++) = c;
- ctx->size--;
- return 0;
-}
-
-int crec_snprintf(char *str, size_t size, const char *format, ...)
-{
- va_list args;
- int rv;
-
- va_start(args, format);
- rv = crec_vsnprintf(str, size, format, args);
- va_end(args);
-
- return rv;
-}
-
-int crec_vsnprintf(char *str, size_t size, const char *format, va_list args)
-{
- struct snprintf_context ctx;
- int rv;
-
- if (!str || !format || size <= 0)
- return -EC_ERROR_INVAL;
-
- ctx.str = str;
- ctx.size = size - 1; /* Reserve space for terminating '\0' */
-
- rv = vfnprintf(snprintf_addchar, &ctx, format, args);
-
- /* Terminate string */
- *ctx.str = '\0';
-
- return (rv == EC_SUCCESS) ? (ctx.str - str) : -rv;
-}
diff --git a/common/pstore_commands.c b/common/pstore_commands.c
index 469af6a054..89c996379c 100644
--- a/common/pstore_commands.c
+++ b/common/pstore_commands.c
@@ -1,10 +1,11 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Persistent storage commands for Chrome EC */
+#include "builtin/assert.h"
#include "common.h"
#include "eeprom.h"
#include "host_command.h"
@@ -23,8 +24,7 @@ pstore_command_get_info(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PSTORE_INFO,
- pstore_command_get_info,
+DECLARE_HOST_COMMAND(EC_CMD_PSTORE_INFO, pstore_command_get_info,
EC_VER_MASK(0));
static enum ec_status pstore_command_read(struct host_cmd_handler_args *args)
@@ -60,9 +60,7 @@ static enum ec_status pstore_command_read(struct host_cmd_handler_args *args)
args->response_size = p->size;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PSTORE_READ,
- pstore_command_read,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_PSTORE_READ, pstore_command_read, EC_VER_MASK(0));
static enum ec_status pstore_command_write(struct host_cmd_handler_args *args)
{
@@ -97,6 +95,4 @@ static enum ec_status pstore_command_write(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PSTORE_WRITE,
- pstore_command_write,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_PSTORE_WRITE, pstore_command_write, EC_VER_MASK(0));
diff --git a/common/pwm.c b/common/pwm.c
index a4edfdd5a5..9019a329b4 100644
--- a/common/pwm.c
+++ b/common/pwm.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,9 +13,8 @@
#ifdef CONFIG_PWM
-#define PWM_RAW_TO_PERCENT(v) \
- DIV_ROUND_NEAREST((uint32_t)(v) * 100, UINT16_MAX)
-#define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v) * UINT16_MAX / 100)
+#define PWM_RAW_TO_PERCENT(v) DIV_ROUND_NEAREST((uint32_t)(v)*100, UINT16_MAX)
+#define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v)*UINT16_MAX / 100)
/*
* Get target channel based on type / index host command parameters.
@@ -71,8 +70,7 @@ host_command_pwm_set_duty(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_DUTY,
- host_command_pwm_set_duty,
+DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_DUTY, host_command_pwm_set_duty,
EC_VER_MASK(0));
static enum ec_status
@@ -92,8 +90,7 @@ host_command_pwm_get_duty(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_DUTY,
- host_command_pwm_get_duty,
+DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_DUTY, host_command_pwm_get_duty,
EC_VER_MASK(0));
/**
@@ -112,13 +109,13 @@ static void print_channel(enum pwm_channel ch, int max_duty)
ccprintf(" %d: disabled\n", ch);
}
-static int cc_pwm_duty(int argc, char **argv)
+static int cc_pwm_duty(int argc, const char **argv)
{
int value = 0;
int max_duty = 100;
int ch;
char *e;
- char *raw;
+ const char *raw;
if (argc < 2) {
ccprintf("PWM channels:\n");
@@ -153,7 +150,7 @@ static int cc_pwm_duty(int argc, char **argv)
ccprintf("Setting channel %d to %d\n", ch, value);
pwm_enable(ch, 1);
(max_duty == 100) ? pwm_set_duty(ch, value) :
- pwm_set_raw_duty(ch, value);
+ pwm_set_raw_duty(ch, value);
}
}
diff --git a/common/pwm_kblight.c b/common/pwm_kblight.c
index 3389023ea3..5748bef700 100644
--- a/common/pwm_kblight.c
+++ b/common/pwm_kblight.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 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/common/queue.c b/common/queue.c
index 7b083233ad..ebe9d8b63d 100644
--- a/common/queue.c
+++ b/common/queue.c
@@ -1,21 +1,23 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Queue data structure implementation.
*/
+
+#include "builtin/assert.h"
#include "console.h"
#include "queue.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ##args)
static void queue_action_null(struct queue_policy const *policy, size_t count)
{
}
struct queue_policy const queue_policy_null = {
- .add = queue_action_null,
+ .add = queue_action_null,
.remove = queue_action_null,
};
@@ -74,17 +76,17 @@ struct queue_chunk queue_get_write_chunk(struct queue const *q, size_t offset)
{
size_t head = q->state->head & q->buffer_units_mask;
size_t tail = (q->state->tail + offset) & q->buffer_units_mask;
- size_t last = (tail < head) ? head : /* Wrapped */
- q->buffer_units; /* Normal | Empty */
+ size_t last = (tail < head) ? head : /* Wrapped */
+ q->buffer_units; /* Normal | Empty */
/* Make sure that the offset doesn't exceed free space. */
if (queue_space(q) <= offset)
- return ((struct queue_chunk) {
+ return ((struct queue_chunk){
.count = 0,
.buffer = NULL,
});
- return ((struct queue_chunk) {
+ return ((struct queue_chunk){
.count = last - tail,
.buffer = q->buffer + (tail * q->unit_bytes),
});
@@ -95,10 +97,10 @@ struct queue_chunk queue_get_read_chunk(struct queue const *q)
size_t head = q->state->head & q->buffer_units_mask;
size_t tail = q->state->tail & q->buffer_units_mask;
size_t last = (queue_is_empty(q) ? head : /* Empty */
- ((head < tail) ? tail : /* Normal */
- q->buffer_units)); /* Wrapped | Full */
+ ((head < tail) ? tail : /* Normal */
+ q->buffer_units)); /* Wrapped | Full */
- return ((struct queue_chunk) {
+ return ((struct queue_chunk){
.count = (last - head),
.buffer = q->buffer + (head * q->unit_bytes),
});
@@ -134,7 +136,7 @@ size_t queue_add_unit(struct queue const *q, const void *src)
return 0;
if (q->unit_bytes == 1)
- q->buffer[tail] = *((uint8_t *) src);
+ q->buffer[tail] = *((uint8_t *)src);
else
memcpy(q->buffer + tail * q->unit_bytes, src, q->unit_bytes);
@@ -146,46 +148,33 @@ size_t queue_add_units(struct queue const *q, const void *src, size_t count)
return queue_add_memcpy(q, src, count, memcpy);
}
-size_t queue_add_memcpy(struct queue const *q,
- const void *src,
- size_t count,
- void *(*memcpy)(void *dest,
- const void *src,
- size_t n))
+size_t queue_add_memcpy(struct queue const *q, const void *src, size_t count,
+ void *(*memcpy)(void *dest, const void *src, size_t n))
{
size_t transfer = MIN(count, queue_space(q));
- size_t tail = q->state->tail & q->buffer_units_mask;
- size_t first = MIN(transfer, q->buffer_units - tail);
+ size_t tail = q->state->tail & q->buffer_units_mask;
+ size_t first = MIN(transfer, q->buffer_units - tail);
- memcpy(q->buffer + tail * q->unit_bytes,
- src,
- first * q->unit_bytes);
+ memcpy(q->buffer + tail * q->unit_bytes, src, first * q->unit_bytes);
if (first < transfer)
memcpy(q->buffer,
- ((uint8_t const *) src) + first * q->unit_bytes,
+ ((uint8_t const *)src) + first * q->unit_bytes,
(transfer - first) * q->unit_bytes);
return queue_advance_tail(q, transfer);
}
-static void queue_read_safe(struct queue const *q,
- void *dest,
- size_t head,
- size_t transfer,
- void *(*memcpy)(void *dest,
- const void *src,
- size_t n))
+static void
+queue_read_safe(struct queue const *q, void *dest, size_t head, size_t transfer,
+ void *(*memcpy)(void *dest, const void *src, size_t n))
{
size_t first = MIN(transfer, q->buffer_units - head);
- memcpy(dest,
- q->buffer + head * q->unit_bytes,
- first * q->unit_bytes);
+ memcpy(dest, q->buffer + head * q->unit_bytes, first * q->unit_bytes);
if (first < transfer)
- memcpy(((uint8_t *) dest) + first * q->unit_bytes,
- q->buffer,
+ memcpy(((uint8_t *)dest) + first * q->unit_bytes, q->buffer,
(transfer - first) * q->unit_bytes);
}
@@ -197,7 +186,7 @@ size_t queue_remove_unit(struct queue const *q, void *dest)
return 0;
if (q->unit_bytes == 1)
- *((uint8_t *) dest) = q->buffer[head];
+ *((uint8_t *)dest) = q->buffer[head];
else
memcpy(dest, q->buffer + head * q->unit_bytes, q->unit_bytes);
@@ -209,39 +198,30 @@ size_t queue_remove_units(struct queue const *q, void *dest, size_t count)
return queue_remove_memcpy(q, dest, count, memcpy);
}
-size_t queue_remove_memcpy(struct queue const *q,
- void *dest,
- size_t count,
- void *(*memcpy)(void *dest,
- const void *src,
+size_t queue_remove_memcpy(struct queue const *q, void *dest, size_t count,
+ void *(*memcpy)(void *dest, const void *src,
size_t n))
{
size_t transfer = MIN(count, queue_count(q));
- size_t head = q->state->head & q->buffer_units_mask;
+ size_t head = q->state->head & q->buffer_units_mask;
queue_read_safe(q, dest, head, transfer, memcpy);
return queue_advance_head(q, transfer);
}
-size_t queue_peek_units(struct queue const *q,
- void *dest,
- size_t i,
+size_t queue_peek_units(struct queue const *q, void *dest, size_t i,
size_t count)
{
return queue_peek_memcpy(q, dest, i, count, memcpy);
}
-size_t queue_peek_memcpy(struct queue const *q,
- void *dest,
- size_t i,
+size_t queue_peek_memcpy(struct queue const *q, void *dest, size_t i,
size_t count,
- void *(*memcpy)(void *dest,
- const void *src,
- size_t n))
+ void *(*memcpy)(void *dest, const void *src, size_t n))
{
size_t available = queue_count(q);
- size_t transfer = MIN(count, available - i);
+ size_t transfer = MIN(count, available - i);
if (i < available) {
size_t head = (q->state->head + i) & q->buffer_units_mask;
@@ -258,7 +238,7 @@ void queue_begin(struct queue const *q, struct queue_iterator *it)
it->ptr = NULL;
else
it->ptr = q->buffer + (q->state->head & q->buffer_units_mask) *
- q->unit_bytes;
+ q->unit_bytes;
it->_state.offset = 0;
it->_state.head = q->state->head;
it->_state.tail = q->state->tail;
diff --git a/common/queue_policies.c b/common/queue_policies.c
index 090c837fae..6646d49cf4 100644
--- a/common/queue_policies.c
+++ b/common/queue_policies.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -29,14 +29,14 @@ void queue_remove_direct(struct queue_policy const *policy, size_t count)
struct producer const null_producer = {
.queue = NULL,
- .ops = &((struct producer_ops const) {
- .read = NULL,
+ .ops = &((struct producer_ops const){
+ .read = NULL,
}),
};
struct consumer const null_consumer = {
.queue = NULL,
- .ops = &((struct consumer_ops const) {
+ .ops = &((struct consumer_ops const){
.written = NULL,
}),
};
diff --git a/common/regulator.c b/common/regulator.c
index 54d9e87521..5b8da2adc8 100644
--- a/common/regulator.c
+++ b/common/regulator.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,8 +11,7 @@
#include "host_command.h"
#include "regulator.h"
-static enum ec_status
-hc_regulator_get_info(struct host_cmd_handler_args *args)
+static enum ec_status hc_regulator_get_info(struct host_cmd_handler_args *args)
{
const struct ec_params_regulator_get_info *p = args->params;
struct ec_response_regulator_get_info *r = args->response;
@@ -33,8 +32,7 @@ hc_regulator_get_info(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_REGULATOR_GET_INFO, hc_regulator_get_info,
EC_VER_MASK(0));
-static enum ec_status
-hc_regulator_enable(struct host_cmd_handler_args *args)
+static enum ec_status hc_regulator_enable(struct host_cmd_handler_args *args)
{
const struct ec_params_regulator_enable *p = args->params;
int rv;
diff --git a/common/rgb_keyboard.c b/common/rgb_keyboard.c
index 815e4a3435..5b5b6c6cf3 100644
--- a/common/rgb_keyboard.c
+++ b/common/rgb_keyboard.c
@@ -1,4 +1,4 @@
-/* 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.
*/
@@ -24,7 +24,7 @@
#define CPRINTS(fmt, args...) cprints(CC_RGBKBD, "RGBKBD: " fmt, ##args)
test_export_static enum ec_rgbkbd_demo demo =
-#if defined(CONFIG_RGBKBD_DEMO_FLOW)
+#if defined(CONFIG_RGBKBD_DEMO_FLOW)
EC_RGBKBD_DEMO_FLOW;
#elif defined(CONFIG_RGBKBD_DEMO_DOT)
EC_RGBKBD_DEMO_DOT;
@@ -35,15 +35,14 @@ test_export_static enum ec_rgbkbd_demo demo =
const int default_demo_interval_ms = 250;
test_export_static int demo_interval_ms = -1;
-test_export_static
-uint8_t rgbkbd_table[EC_RGBKBD_MAX_KEY_COUNT];
+test_export_static uint8_t rgbkbd_table[EC_RGBKBD_MAX_KEY_COUNT];
static enum rgbkbd_state rgbkbd_state;
const struct rgbkbd_init rgbkbd_init_default = {
.gcc = RGBKBD_MAX_GCC_LEVEL / 2,
.scale = { RGBKBD_MAX_SCALE, RGBKBD_MAX_SCALE, RGBKBD_MAX_SCALE },
- .color = { .r = 0xff, .g = 0xff, .b = 0xff }, /* white */
+ .color = { .r = 0xff, .g = 0xff, .b = 0xff }, /* white */
};
const struct rgbkbd_init *rgbkbd_init_setting = &rgbkbd_init_default;
@@ -88,8 +87,8 @@ static int set_color_single(struct rgb_s color, int x, int y)
rv = ctx->cfg->drv->set_color(ctx, offset, &ctx->buf[offset], 1);
CPRINTS("%set (%d,%d) to color=(%d,%d,%d) grid=%u offset=%u (%d)",
- rv ? "Failed to s" : "S",
- x, y, color.r, color.g, color.b, grid, offset, rv);
+ rv ? "Failed to s" : "S", x, y, color.r, color.g, color.b, grid,
+ offset, rv);
return rv;
}
@@ -214,14 +213,13 @@ static void rgbkbd_demo_run(enum ec_rgbkbd_demo id)
}
}
-test_export_static
-void rgbkbd_init_lookup_table(void)
+test_export_static void rgbkbd_init_lookup_table(void)
{
bool add = true;
int i, k = 0;
if (rgbkbd_map[0] != RGBKBD_DELM ||
- rgbkbd_map[rgbkbd_map_size - 1] != RGBKBD_DELM) {
+ rgbkbd_map[rgbkbd_map_size - 1] != RGBKBD_DELM) {
CPRINTS("Invalid Key-LED map");
return;
}
@@ -267,8 +265,8 @@ static int rgbkbd_set_global_brightness(uint8_t gcc)
e = ctx->cfg->drv->set_gcc(ctx, gcc);
if (e) {
- CPRINTS("Failed to set GCC to %u for grid=%d (%d)",
- gcc, grid, e);
+ CPRINTS("Failed to set GCC to %u for grid=%d (%d)", gcc,
+ grid, e);
rv = e;
continue;
}
@@ -356,8 +354,8 @@ static int rgbkbd_init(void)
e = ctx->cfg->drv->set_gcc(ctx, gcc);
if (e) {
- CPRINTS("Failed to set GCC to %u for grid=%d (%d)",
- gcc, i, e);
+ CPRINTS("Failed to set GCC to %u for grid=%d (%d)", gcc,
+ i, e);
rv = e;
continue;
}
@@ -423,8 +421,8 @@ static int rgbkbd_enable(int enable)
}
if (rv == EC_SUCCESS) {
- rgbkbd_state = enable ?
- RGBKBD_STATE_ENABLED : RGBKBD_STATE_DISABLED;
+ rgbkbd_state = enable ? RGBKBD_STATE_ENABLED :
+ RGBKBD_STATE_DISABLED;
}
/* Return EC_SUCCESS or the last error. */
@@ -518,8 +516,8 @@ static enum ec_status hc_rgbkbd_set_color(struct host_cmd_handler_args *args)
if (led.u8 == RGBKBD_DELM)
/* Reached end of the group. */
break;
- if (set_color_single(p->color[i],
- led.coord.x, led.coord.y))
+ if (set_color_single(p->color[i], led.coord.x,
+ led.coord.y))
return EC_RES_ERROR;
} while (led.u8 != RGBKBD_DELM);
}
@@ -532,8 +530,11 @@ DECLARE_HOST_COMMAND(EC_CMD_RGBKBD_SET_COLOR, hc_rgbkbd_set_color,
static enum ec_status hc_rgbkbd(struct host_cmd_handler_args *args)
{
const struct ec_params_rgbkbd *p = args->params;
+ struct ec_response_rgbkbd *r = args->response;
enum ec_status rv = EC_RES_SUCCESS;
+ args->response_size = sizeof(*r);
+
if (rgbkbd_late_init())
return EC_RES_ERROR;
@@ -550,6 +551,9 @@ static enum ec_status hc_rgbkbd(struct host_cmd_handler_args *args)
if (rgbkbd_set_scale(p->set_scale.scale, p->set_scale.key))
rv = EC_RES_ERROR;
break;
+ case EC_RGBKBD_SUBCMD_GET_CONFIG:
+ r->rgbkbd_type = rgbkbd_type;
+ break;
default:
rv = EC_RES_INVALID_PARAM;
break;
@@ -575,7 +579,7 @@ static int int_to_rgb(const char *code, struct rgb_s *rgb)
return EC_SUCCESS;
}
-test_export_static int cc_rgb(int argc, char **argv)
+test_export_static int cc_rgb(int argc, const char **argv)
{
char *end, *comma;
struct rgb_s rgb, scale;
@@ -606,19 +610,19 @@ test_export_static int cc_rgb(int argc, char **argv)
if (y < 0) {
/* Set all LEDs on column x. */
- ccprintf("Set column %d to 0x%02x%02x%02x\n",
- x, rgb.r, rgb.g, rgb.b);
+ ccprintf("Set column %d to 0x%02x%02x%02x\n", x, rgb.r,
+ rgb.g, rgb.b);
for (i = 0; i < rgbkbd_vsize; i++)
rv = set_color_single(rgb, x, i);
} else if (x < 0) {
/* Set all LEDs on row y. */
- ccprintf("Set row %d to 0x%02x%02x%02x\n",
- y, rgb.r, rgb.g, rgb.b);
+ ccprintf("Set row %d to 0x%02x%02x%02x\n", y, rgb.r,
+ rgb.g, rgb.b);
for (i = 0; i < rgbkbd_hsize; i++)
rv = set_color_single(rgb, i, y);
} else {
- ccprintf("Set (%d,%d) to 0x%02x%02x%02x\n",
- x, y, rgb.r, rgb.g, rgb.b);
+ ccprintf("Set (%d,%d) to 0x%02x%02x%02x\n", x, y, rgb.r,
+ rgb.g, rgb.b);
rv = set_color_single(rgb, x, y);
}
} else if (!strcasecmp(argv[1], "all")) {
@@ -680,6 +684,5 @@ DECLARE_CONSOLE_COMMAND(rgb, cc_rgb,
"4. rgb demo <id>\n"
"5. rgb reset/enable/disable/red\n"
"6. rgb scale <24-bit RGB scale>\n",
- "Control RGB keyboard"
- );
+ "Control RGB keyboard");
#endif
diff --git a/common/rollback.c b/common/rollback.c
index 984058c49a..7aaba72ebb 100644
--- a/common/rollback.c
+++ b/common/rollback.c
@@ -1,10 +1,11 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Rollback protection logic. */
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#ifdef CONFIG_LIBCRYPTOC
@@ -25,7 +26,7 @@
#include "util.h"
/* Console output macros */
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
/* Number of rollback regions */
#define ROLLBACK_REGIONS 2
@@ -188,12 +189,12 @@ failed:
#ifdef CONFIG_ROLLBACK_UPDATE
#ifdef CONFIG_ROLLBACK_SECRET_SIZE
-static int add_entropy(uint8_t *dst, const uint8_t *src,
- const uint8_t *add, unsigned int add_len)
+static int add_entropy(uint8_t *dst, const uint8_t *src, const uint8_t *add,
+ unsigned int add_len)
{
int ret = 0;
#ifdef CONFIG_SHA256
-BUILD_ASSERT(SHA256_DIGEST_SIZE == CONFIG_ROLLBACK_SECRET_SIZE);
+ BUILD_ASSERT(SHA256_DIGEST_SIZE == CONFIG_ROLLBACK_SECRET_SIZE);
struct sha256_ctx ctx;
uint8_t *hash;
#ifdef CONFIG_ROLLBACK_SECRET_LOCAL_ENTROPY_SIZE
@@ -240,16 +241,16 @@ failed:
*
* @return EC_SUCCESS on success, EC_ERROR_* on error.
*/
-static int rollback_update(int32_t next_min_version,
- const uint8_t *entropy, unsigned int length)
+static int rollback_update(int32_t next_min_version, const uint8_t *entropy,
+ unsigned int length)
{
/*
* When doing flash_write operation, the data needs to be in blocks
* of CONFIG_FLASH_WRITE_SIZE, pad rollback_data as required.
*/
uint8_t block[CONFIG_FLASH_WRITE_SIZE *
- DIV_ROUND_UP(sizeof(struct rollback_data),
- CONFIG_FLASH_WRITE_SIZE)];
+ DIV_ROUND_UP(sizeof(struct rollback_data),
+ CONFIG_FLASH_WRITE_SIZE)];
struct rollback_data *data = (struct rollback_data *)block;
BUILD_ASSERT(sizeof(block) >= sizeof(*data));
int erase_size, offset, region, ret;
@@ -260,7 +261,7 @@ static int rollback_update(int32_t next_min_version,
}
/* Initialize the rest of the block. */
- memset(&block[sizeof(*data)], 0xff, sizeof(block)-sizeof(*data));
+ memset(&block[sizeof(*data)], 0xff, sizeof(block) - sizeof(*data));
region = get_latest_rollback(data);
@@ -349,7 +350,7 @@ int rollback_add_entropy(const uint8_t *data, unsigned int len)
return rollback_update(-1, data, len);
}
-static int command_rollback_update(int argc, char **argv)
+static int command_rollback_update(int argc, const char **argv)
{
int32_t min_version;
char *e;
@@ -364,12 +365,11 @@ static int command_rollback_update(int argc, char **argv)
return rollback_update_version(min_version);
}
-DECLARE_CONSOLE_COMMAND(rollbackupdate, command_rollback_update,
- "min_version",
+DECLARE_CONSOLE_COMMAND(rollbackupdate, command_rollback_update, "min_version",
"Update rollback info");
#ifdef CONFIG_ROLLBACK_SECRET_SIZE
-static int command_rollback_add_entropy(int argc, char **argv)
+static int command_rollback_add_entropy(int argc, const char **argv)
{
int len;
@@ -380,8 +380,7 @@ static int command_rollback_add_entropy(int argc, char **argv)
return rollback_add_entropy(argv[1], len);
}
-DECLARE_CONSOLE_COMMAND(rollbackaddent, command_rollback_add_entropy,
- "data",
+DECLARE_CONSOLE_COMMAND(rollbackaddent, command_rollback_add_entropy, "data",
"Add entropy to rollback block");
#ifdef CONFIG_RNG
@@ -400,9 +399,9 @@ static void add_entropy_deferred(void)
if (add_entropy_action == ADD_ENTROPY_RESET_ASYNC)
repeat = ROLLBACK_REGIONS;
- init_trng();
+ trng_init();
do {
- rand_bytes(rand, sizeof(rand));
+ trng_rand_bytes(rand, sizeof(rand));
if (rollback_add_entropy(rand, sizeof(rand)) != EC_SUCCESS) {
add_entropy_rv = EC_RES_ERROR;
goto out;
@@ -411,7 +410,7 @@ static void add_entropy_deferred(void)
add_entropy_rv = EC_RES_SUCCESS;
out:
- exit_trng();
+ trng_exit();
}
DECLARE_DEFERRED(add_entropy_deferred);
@@ -438,14 +437,13 @@ hc_rollback_add_entropy(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
}
-DECLARE_HOST_COMMAND(EC_CMD_ADD_ENTROPY,
- hc_rollback_add_entropy,
+DECLARE_HOST_COMMAND(EC_CMD_ADD_ENTROPY, hc_rollback_add_entropy,
EC_VER_MASK(0));
#endif /* CONFIG_RNG */
#endif /* CONFIG_ROLLBACK_SECRET_SIZE */
#endif /* CONFIG_ROLLBACK_UPDATE */
-static int command_rollback_info(int argc, char **argv)
+static int command_rollback_info(int argc, const char **argv)
{
int ret = EC_ERROR_UNKNOWN;
int region, min_region;
@@ -467,14 +465,13 @@ static int command_rollback_info(int argc, char **argv)
if (ret)
goto failed;
- ccprintf("rollback %d: %08x %08x %08x",
- region, data.id, data.rollback_min_version,
- data.cookie);
+ ccprintf("rollback %d: %08x %08x %08x", region, data.id,
+ data.rollback_min_version, data.cookie);
#ifdef CONFIG_ROLLBACK_SECRET_SIZE
if (!system_is_locked()) {
/* If system is unlocked, show some of the secret. */
ccprintf(" [%02x..%02x]", data.secret[0],
- data.secret[CONFIG_ROLLBACK_SECRET_SIZE-1]);
+ data.secret[CONFIG_ROLLBACK_SECRET_SIZE - 1]);
}
#endif
if (min_region == region)
@@ -487,8 +484,7 @@ failed:
clear_rollback(&data);
return ret;
}
-DECLARE_SAFE_CONSOLE_COMMAND(rollbackinfo, command_rollback_info,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(rollbackinfo, command_rollback_info, NULL,
"Print rollback info");
static enum ec_status
@@ -515,6 +511,5 @@ failed:
clear_rollback(&data);
return ret;
}
-DECLARE_HOST_COMMAND(EC_CMD_ROLLBACK_INFO,
- host_command_rollback_info,
+DECLARE_HOST_COMMAND(EC_CMD_ROLLBACK_INFO, host_command_rollback_info,
EC_VER_MASK(0));
diff --git a/common/rollback_private.h b/common/rollback_private.h
index c757882f4f..1dbbd4f430 100644
--- a/common/rollback_private.h
+++ b/common/rollback_private.h
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 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/common/rsa.c b/common/rsa.c
index 10f0afa4b4..4df6fc136a 100644
--- a/common/rsa.c
+++ b/common/rsa.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -39,16 +39,14 @@ static int ge_mod(const struct rsa_public_key *key, const uint32_t *a)
if (a[i] > key->n[i])
return 1;
}
- return 1; /* equal */
+ return 1; /* equal */
}
/**
* Montgomery c[] += a * b[] / R % mod
*/
-static void mont_mul_add(const struct rsa_public_key *key,
- uint32_t *c,
- const uint32_t a,
- const uint32_t *b)
+static void mont_mul_add(const struct rsa_public_key *key, uint32_t *c,
+ const uint32_t a, const uint32_t *b)
{
uint64_t A = mula32(a, b[0], c[0]);
uint32_t d0 = (uint32_t)A * key->n0inv;
@@ -73,9 +71,8 @@ static void mont_mul_add(const struct rsa_public_key *key,
/**
* Montgomery c[] += 0 * b[] / R % mod
*/
-static void mont_mul_add_0(const struct rsa_public_key *key,
- uint32_t *c,
- const uint32_t *b)
+static void mont_mul_add_0(const struct rsa_public_key *key, uint32_t *c,
+ const uint32_t *b)
{
uint32_t d0 = c[0] * key->n0inv;
uint64_t B = mula32(d0, key->n[0], c[0]);
@@ -90,8 +87,7 @@ static void mont_mul_add_0(const struct rsa_public_key *key,
}
/* Montgomery c[] = a[] * 1 / R % key. */
-static void mont_mul_1(const struct rsa_public_key *key,
- uint32_t *c,
+static void mont_mul_1(const struct rsa_public_key *key, uint32_t *c,
const uint32_t *a)
{
int i;
@@ -108,10 +104,8 @@ static void mont_mul_1(const struct rsa_public_key *key,
/**
* Montgomery c[] = a[] * b[] / R % mod
*/
-static void mont_mul(const struct rsa_public_key *key,
- uint32_t *c,
- const uint32_t *a,
- const uint32_t *b)
+static void mont_mul(const struct rsa_public_key *key, uint32_t *c,
+ const uint32_t *a, const uint32_t *b)
{
uint32_t i;
for (i = 0; i < RSANUMWORDS; ++i)
@@ -136,21 +130,20 @@ static void mod_pow(const struct rsa_public_key *key, uint8_t *inout,
uint32_t *a = workbuf32;
uint32_t *a_r = a + RSANUMWORDS;
uint32_t *aa_r = a_r + RSANUMWORDS;
- uint32_t *aaa = aa_r; /* Re-use location. */
+ uint32_t *aaa = aa_r; /* Re-use location. */
int i;
/* Convert from big endian byte array to little endian word array. */
for (i = 0; i < RSANUMWORDS; ++i) {
- uint32_t tmp =
- (inout[((RSANUMWORDS - 1 - i) * 4) + 0] << 24) |
- (inout[((RSANUMWORDS - 1 - i) * 4) + 1] << 16) |
- (inout[((RSANUMWORDS - 1 - i) * 4) + 2] << 8) |
- (inout[((RSANUMWORDS - 1 - i) * 4) + 3] << 0);
+ uint32_t tmp = (inout[((RSANUMWORDS - 1 - i) * 4) + 0] << 24) |
+ (inout[((RSANUMWORDS - 1 - i) * 4) + 1] << 16) |
+ (inout[((RSANUMWORDS - 1 - i) * 4) + 2] << 8) |
+ (inout[((RSANUMWORDS - 1 - i) * 4) + 3] << 0);
a[i] = tmp;
}
/* TODO(drinkcat): This operation could be precomputed to save time. */
- mont_mul(key, a_r, a, key->rr); /* a_r = a * RR / R mod M */
+ mont_mul(key, a_r, a, key->rr); /* a_r = a * RR / R mod M */
#ifdef CONFIG_RSA_EXPONENT_3
mont_mul(key, aa_r, a_r, a_r);
mont_mul(key, a, aa_r, a_r);
@@ -159,9 +152,10 @@ static void mod_pow(const struct rsa_public_key *key, uint8_t *inout,
/* Exponent 65537 */
for (i = 0; i < 16; i += 2) {
mont_mul(key, aa_r, a_r, a_r); /* aa_r = a_r * a_r / R mod M */
- mont_mul(key, a_r, aa_r, aa_r);/* a_r = aa_r * aa_r / R mod M */
+ mont_mul(key, a_r, aa_r, aa_r); /* a_r = aa_r * aa_r / R mod M
+ */
}
- mont_mul(key, aaa, a_r, a); /* aaa = a_r * a / R mod M */
+ mont_mul(key, aaa, a_r, a); /* aaa = a_r * a / R mod M */
#endif
/* Make sure aaa < mod; aaa is at most 1x mod too large. */
@@ -173,8 +167,8 @@ static void mod_pow(const struct rsa_public_key *key, uint8_t *inout,
uint32_t tmp = aaa[i];
*inout++ = (uint8_t)(tmp >> 24);
*inout++ = (uint8_t)(tmp >> 16);
- *inout++ = (uint8_t)(tmp >> 8);
- *inout++ = (uint8_t)(tmp >> 0);
+ *inout++ = (uint8_t)(tmp >> 8);
+ *inout++ = (uint8_t)(tmp >> 0);
}
}
@@ -192,11 +186,9 @@ static void mod_pow(const struct rsa_public_key *key, uint8_t *inout,
*
* PS: octet string consisting of {Length(RSA Key) - Length(T) - 3} 0xFF
*/
-static const uint8_t sha256_tail[] = {
- 0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60,
- 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
- 0x05, 0x00, 0x04, 0x20
-};
+static const uint8_t sha256_tail[] = { 0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
+ 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04,
+ 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 };
#define PKCS_PAD_SIZE (RSANUMBYTES - SHA256_DIGEST_SIZE)
@@ -255,5 +247,5 @@ int rsa_verify(const struct rsa_public_key *key, const uint8_t *signature,
if (memcmp(buf + PKCS_PAD_SIZE, sha, SHA256_DIGEST_SIZE) != 0)
return 0;
- return 1; /* All checked out OK. */
+ return 1; /* All checked out OK. */
}
diff --git a/common/rtc.c b/common/rtc.c
index 670e86d707..e4292e9762 100644
--- a/common/rtc.c
+++ b/common/rtc.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,9 +8,8 @@
#include "rtc.h"
-static uint16_t days_since_year_start[12] = {
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
-};
+static uint16_t days_since_year_start[12] = { 0, 31, 59, 90, 120, 151,
+ 181, 212, 243, 273, 304, 334 };
/* Conversion between calendar date and seconds eclapsed since 1970-01-01 */
uint32_t date_to_sec(struct calendar_date time)
@@ -25,8 +24,8 @@ uint32_t date_to_sec(struct calendar_date time)
}
sec += (days_since_year_start[time.month - 1] +
- (IS_LEAP_YEAR(time.year) && time.month > 2) +
- (time.day - 1)) * SECS_PER_DAY;
+ (IS_LEAP_YEAR(time.year) && time.month > 2) + (time.day - 1)) *
+ SECS_PER_DAY;
/* add the accumulated time in seconds from 1970 to 2000 */
return sec + SECS_TILL_YEAR_2K;
@@ -55,7 +54,8 @@ struct calendar_date sec_to_date(uint32_t sec)
}
for (i = 1; i < 12; i++) {
if (days_since_year_start[i] +
- (IS_LEAP_YEAR(time.year) && (i >= 2)) >= day_tmp)
+ (IS_LEAP_YEAR(time.year) && (i >= 2)) >=
+ day_tmp)
break;
}
time.month = i;
diff --git a/common/rwsig.c b/common/rwsig.c
index 676c66d79b..1ea6d6923a 100644
--- a/common/rwsig.c
+++ b/common/rwsig.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -25,18 +25,17 @@
#include "vboot.h"
/* Console output macros */
-#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
#if !defined(CONFIG_MAPPED_STORAGE)
#error rwsig implementation assumes mem-mapped storage.
#endif
/* RW firmware reset vector */
-static uint32_t * const rw_rst =
+static uint32_t *const rw_rst =
(uint32_t *)(CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RW_MEM_OFF + 4);
-
void rwsig_jump_now(void)
{
/* Protect all flash before jumping to RW. */
@@ -74,8 +73,8 @@ void rwsig_jump_now(void)
* Check that memory between rwdata[start] and rwdata[len-1] is filled
* with ones. data, start and len must be aligned on 4-byte boundary.
*/
-static int check_padding(const uint8_t *data,
- unsigned int start, unsigned int len)
+static int check_padding(const uint8_t *data, unsigned int start,
+ unsigned int len)
{
unsigned int i;
const uint32_t *data32 = (const uint32_t *)data;
@@ -83,7 +82,7 @@ static int check_padding(const uint8_t *data,
if ((start % 4) != 0 || (len % 4) != 0)
return 0;
- for (i = start/4; i < len/4; i++) {
+ for (i = start / 4; i < len / 4; i++) {
if (data32[i] != 0xffffffff)
return 0;
}
@@ -99,8 +98,8 @@ int rwsig_check_signature(void)
const uint8_t *sig;
uint8_t *hash;
uint32_t *rsa_workbuf = NULL;
- const uint8_t *rwdata = (uint8_t *)CONFIG_PROGRAM_MEMORY_BASE
- + CONFIG_RW_MEM_OFF;
+ const uint8_t *rwdata =
+ (uint8_t *)CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RW_MEM_OFF;
int good = 0;
unsigned int rwlen;
@@ -125,8 +124,8 @@ int rwsig_check_signature(void)
if (rw_rollback_version < 0 || min_rollback_version < 0 ||
rw_rollback_version < min_rollback_version) {
- CPRINTS("Rollback error (%d < %d)",
- rw_rollback_version, min_rollback_version);
+ CPRINTS("Rollback error (%d < %d)", rw_rollback_version,
+ min_rollback_version);
goto out;
}
#endif
@@ -152,8 +151,8 @@ int rwsig_check_signature(void)
goto out;
}
- key = (const struct rsa_public_key *)
- ((const uint8_t *)vb21_key + vb21_key->key_offset);
+ key = (const struct rsa_public_key *)((const uint8_t *)vb21_key +
+ vb21_key->key_offset);
/*
* TODO(crbug.com/690773): We could verify other parameters such
@@ -179,7 +178,7 @@ int rwsig_check_signature(void)
* Check that unverified RW region is actually filled with ones.
*/
good = check_padding(rwdata, rwlen,
- CONFIG_RW_SIZE - CONFIG_RW_SIG_SIZE);
+ CONFIG_RW_SIZE - CONFIG_RW_SIG_SIZE);
if (!good) {
CPRINTS("Invalid padding.");
goto out;
@@ -207,11 +206,10 @@ int rwsig_check_signature(void)
*/
if (rw_rollback_version != min_rollback_version
#ifdef CONFIG_FLASH_PROTECT_RW
- && ((!system_is_locked() ||
- crec_flash_get_protect() &
- EC_FLASH_PROTECT_RW_NOW))
+ && ((!system_is_locked() ||
+ crec_flash_get_protect() & EC_FLASH_PROTECT_RW_NOW))
#endif
- ) {
+ ) {
/*
* This will fail if the rollback block is protected (RW image
* will unprotect that block later on).
@@ -219,8 +217,7 @@ int rwsig_check_signature(void)
int ret = rollback_update_version(rw_rollback_version);
if (ret == 0) {
- CPRINTS("Rollback updated to %d",
- rw_rollback_version);
+ CPRINTS("Rollback updated to %d", rw_rollback_version);
} else if (ret != EC_ERROR_ACCESS_DENIED) {
CPRINTS("Rollback update error %d", ret);
good = 0;
@@ -315,9 +312,7 @@ static enum ec_status rwsig_cmd_action(struct host_cmd_handler_args *args)
args->response_size = 0;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_RWSIG_ACTION,
- rwsig_cmd_action,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_RWSIG_ACTION, rwsig_cmd_action, EC_VER_MASK(0));
#else /* !HAS_TASK_RWSIG */
static enum ec_status rwsig_cmd_check_status(struct host_cmd_handler_args *args)
@@ -330,7 +325,6 @@ static enum ec_status rwsig_cmd_check_status(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_RWSIG_CHECK_STATUS,
- rwsig_cmd_check_status,
+DECLARE_HOST_COMMAND(EC_CMD_RWSIG_CHECK_STATUS, rwsig_cmd_check_status,
EC_VER_MASK(0));
#endif
diff --git a/common/sha256.c b/common/sha256.c
index 8c0778c3e6..2826f6c68d 120000..100644
--- a/common/sha256.c
+++ b/common/sha256.c
@@ -1 +1,296 @@
-../third_party/sha2//sha256.c \ No newline at end of file
+/* SHA-256 and SHA-512 implementation based on code by Oliver Gay
+ * <olivier.gay@a3.epfl.ch> under a BSD-style license. See below.
+ */
+
+/*
+ * FIPS 180-2 SHA-224/256/384/512 implementation
+ * Last update: 02/02/2007
+ * Issue date: 04/30/2005
+ *
+ * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "builtin/assert.h"
+#include "sha256.h"
+#include "util.h"
+
+#define SHFR(x, n) (x >> n)
+#define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
+#define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
+#define CH(x, y, z) ((x & y) ^ (~x & z))
+#define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
+
+#define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
+#define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
+#define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3))
+#define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10))
+
+#define UNPACK32(x, str) \
+ { \
+ *((str) + 3) = (uint8_t)((x)); \
+ *((str) + 2) = (uint8_t)((x) >> 8); \
+ *((str) + 1) = (uint8_t)((x) >> 16); \
+ *((str) + 0) = (uint8_t)((x) >> 24); \
+ }
+
+#define PACK32(str, x) \
+ { \
+ *(x) = ((uint32_t) * ((str) + 3)) | \
+ ((uint32_t) * ((str) + 2) << 8) | \
+ ((uint32_t) * ((str) + 1) << 16) | \
+ ((uint32_t) * ((str) + 0) << 24); \
+ }
+
+/* Macros used for loops unrolling */
+
+#define SHA256_SCR(i) \
+ { \
+ w[i] = SHA256_F4(w[i - 2]) + w[i - 7] + SHA256_F3(w[i - 15]) + \
+ w[i - 16]; \
+ }
+
+#define SHA256_EXP(a, b, c, d, e, f, g, h, j) \
+ { \
+ t1 = wv[h] + SHA256_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) + \
+ sha256_k[j] + w[j]; \
+ t2 = SHA256_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \
+ wv[d] += t1; \
+ wv[h] = t1 + t2; \
+ }
+
+static const uint32_t sha256_h0[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372,
+ 0xa54ff53a, 0x510e527f, 0x9b05688c,
+ 0x1f83d9ab, 0x5be0cd19 };
+
+static const uint32_t sha256_k[64] = {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+};
+
+void SHA256_init(struct sha256_ctx *ctx)
+{
+ int i;
+
+ for (i = 0; i < 8; i++)
+ ctx->h[i] = sha256_h0[i];
+
+ ctx->len = 0;
+ ctx->tot_len = 0;
+}
+
+static void SHA256_transform(struct sha256_ctx *ctx, const uint8_t *message,
+ unsigned int block_nb)
+{
+ /* Note: this function requires a considerable amount of stack */
+ uint32_t w[64];
+ uint32_t wv[8];
+ uint32_t t1, t2;
+ const unsigned char *sub_block;
+ int i, j;
+
+ for (i = 0; i < (int)block_nb; i++) {
+ sub_block = message + (i << 6);
+
+ for (j = 0; j < 16; j++)
+ PACK32(&sub_block[j << 2], &w[j]);
+
+#ifdef CONFIG_SHA256_UNROLLED
+ for (j = 16; j < 64; j += 8) {
+ SHA256_SCR(j);
+ SHA256_SCR(j + 1);
+ SHA256_SCR(j + 2);
+ SHA256_SCR(j + 3);
+ SHA256_SCR(j + 4);
+ SHA256_SCR(j + 5);
+ SHA256_SCR(j + 6);
+ SHA256_SCR(j + 7);
+ }
+#else
+ for (j = 16; j < 64; j++)
+ SHA256_SCR(j);
+#endif
+
+ for (j = 0; j < 8; j++)
+ wv[j] = ctx->h[j];
+
+#ifdef CONFIG_SHA256_UNROLLED
+ for (j = 0; j < 64; j += 8) {
+ SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, j);
+ SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, j + 1);
+ SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, j + 2);
+ SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, j + 3);
+ SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, j + 4);
+ SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, j + 5);
+ SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, j + 6);
+ SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, j + 7);
+ }
+#else
+ for (j = 0; j < 64; j++) {
+ t1 = wv[7] + SHA256_F2(wv[4]) +
+ CH(wv[4], wv[5], wv[6]) + sha256_k[j] + w[j];
+ t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]);
+ wv[7] = wv[6];
+ wv[6] = wv[5];
+ wv[5] = wv[4];
+ wv[4] = wv[3] + t1;
+ wv[3] = wv[2];
+ wv[2] = wv[1];
+ wv[1] = wv[0];
+ wv[0] = t1 + t2;
+ }
+#endif
+
+ for (j = 0; j < 8; j++)
+ ctx->h[j] += wv[j];
+ }
+}
+
+void SHA256_update(struct sha256_ctx *ctx, const uint8_t *data, uint32_t len)
+{
+ unsigned int block_nb;
+ unsigned int new_len, rem_len, tmp_len;
+ const uint8_t *shifted_data;
+
+ tmp_len = SHA256_BLOCK_SIZE - ctx->len;
+ rem_len = len < tmp_len ? len : tmp_len;
+
+ memcpy(&ctx->block[ctx->len], data, rem_len);
+
+ if (ctx->len + len < SHA256_BLOCK_SIZE) {
+ ctx->len += len;
+ return;
+ }
+
+ new_len = len - rem_len;
+ block_nb = new_len / SHA256_BLOCK_SIZE;
+
+ shifted_data = data + rem_len;
+
+ SHA256_transform(ctx, ctx->block, 1);
+ SHA256_transform(ctx, shifted_data, block_nb);
+
+ rem_len = new_len % SHA256_BLOCK_SIZE;
+
+ memcpy(ctx->block, &shifted_data[block_nb << 6], rem_len);
+
+ ctx->len = rem_len;
+ ctx->tot_len += (block_nb + 1) << 6;
+}
+
+/*
+ * Specialized SHA256_init + SHA256_update that takes the first data block of
+ * size SHA256_BLOCK_SIZE as input.
+ */
+static void SHA256_init_1b(struct sha256_ctx *ctx, const uint8_t *data)
+{
+ int i;
+
+ for (i = 0; i < 8; i++)
+ ctx->h[i] = sha256_h0[i];
+
+ SHA256_transform(ctx, data, 1);
+
+ ctx->len = 0;
+ ctx->tot_len = SHA256_BLOCK_SIZE;
+}
+
+uint8_t *SHA256_final(struct sha256_ctx *ctx)
+{
+ unsigned int block_nb;
+ unsigned int pm_len;
+ unsigned int len_b;
+ int i;
+
+ block_nb = (1 +
+ ((SHA256_BLOCK_SIZE - 9) < (ctx->len % SHA256_BLOCK_SIZE)));
+
+ len_b = (ctx->tot_len + ctx->len) << 3;
+ pm_len = block_nb << 6;
+
+ memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
+ ctx->block[ctx->len] = 0x80;
+ UNPACK32(len_b, ctx->block + pm_len - 4);
+
+ SHA256_transform(ctx, ctx->block, block_nb);
+
+ for (i = 0; i < 8; i++)
+ UNPACK32(ctx->h[i], &ctx->buf[i << 2]);
+
+ return ctx->buf;
+}
+
+static void hmac_SHA256_step(uint8_t *output, uint8_t mask, const uint8_t *key,
+ const int key_len, const uint8_t *data,
+ const int data_len)
+{
+ struct sha256_ctx ctx;
+ uint8_t *key_pad = ctx.block;
+ uint8_t *tmp;
+ int i;
+
+ /* key_pad = key (zero-padded) ^ mask */
+ memset(key_pad, mask, SHA256_BLOCK_SIZE);
+ for (i = 0; i < key_len; i++)
+ key_pad[i] ^= key[i];
+
+ /* tmp = hash(key_pad || message) */
+ SHA256_init_1b(&ctx, key_pad);
+ SHA256_update(&ctx, data, data_len);
+ tmp = SHA256_final(&ctx);
+ memcpy(output, tmp, SHA256_DIGEST_SIZE);
+}
+
+void hmac_SHA256(uint8_t *output, const uint8_t *key, const int key_len,
+ const uint8_t *message, const int message_len)
+{
+ /* This code does not support key_len > block_size. */
+ ASSERT(key_len <= SHA256_BLOCK_SIZE);
+
+ /*
+ * i_key_pad = key (zero-padded) ^ 0x36
+ * output = hash(i_key_pad || message)
+ * (Use output as temporary buffer)
+ */
+ hmac_SHA256_step(output, 0x36, key, key_len, message, message_len);
+
+ /*
+ * o_key_pad = key (zero-padded) ^ 0x5c
+ * output = hash(o_key_pad || output)
+ */
+ hmac_SHA256_step(output, 0x5c, key, key_len, output,
+ SHA256_DIGEST_SIZE);
+}
diff --git a/common/shared_mem.c b/common/shared_mem.c
index e435408d3b..db1ad0ca32 100644
--- a/common/shared_mem.c
+++ b/common/shared_mem.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -62,14 +62,13 @@ void shared_mem_release(void *ptr)
}
#ifdef CONFIG_CMD_SHMEM
-static int command_shmem(int argc, char **argv)
+static int command_shmem(int argc, const char **argv)
{
ccprintf("Size:%6d\n", shared_mem_size());
ccprintf("Used:%6d\n", buf_in_use);
ccprintf("Max: %6d\n", max_used);
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(shmem, command_shmem,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(shmem, command_shmem, NULL,
"Print shared memory stats");
#endif
diff --git a/common/shmalloc.c b/common/shmalloc.c
index b1705b52d1..6cbf213227 100644
--- a/common/shmalloc.c
+++ b/common/shmalloc.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -47,8 +47,8 @@ static void shared_mem_init(void)
free_buf_chain = (struct shm_buffer *)__shared_mem_buf;
free_buf_chain->next_buffer = NULL;
free_buf_chain->prev_buffer = NULL;
- free_buf_chain->buffer_size = system_usable_ram_end() -
- (uintptr_t)__shared_mem_buf;
+ free_buf_chain->buffer_size =
+ system_usable_ram_end() - (uintptr_t)__shared_mem_buf;
}
DECLARE_HOOK(HOOK_INIT, shared_mem_init, HOOK_PRIO_FIRST);
@@ -73,8 +73,7 @@ static void do_release(struct shm_buffer *ptr)
* Saninty check: verify that the buffer is in the allocated
* buffers chain.
*/
- for (pfb = allocced_buf_chain->next_buffer;
- pfb;
+ for (pfb = allocced_buf_chain->next_buffer; pfb;
pfb = pfb->next_buffer)
if (pfb == ptr)
break;
@@ -117,10 +116,9 @@ static void do_release(struct shm_buffer *ptr)
if (pfb == free_buf_chain) {
set_map_bit(BIT(1));
/* Merge the two buffers. */
- ptr->buffer_size = free_buf_chain->buffer_size +
- released_size;
- ptr->next_buffer =
- free_buf_chain->next_buffer;
+ ptr->buffer_size =
+ free_buf_chain->buffer_size + released_size;
+ ptr->next_buffer = free_buf_chain->next_buffer;
} else {
set_map_bit(BIT(2));
ptr->buffer_size = released_size;
@@ -163,8 +161,7 @@ static void do_release(struct shm_buffer *ptr)
if (top == pfb->next_buffer) {
/* Yes, it is. */
pfb->buffer_size += pfb->next_buffer->buffer_size;
- pfb->next_buffer =
- pfb->next_buffer->next_buffer;
+ pfb->next_buffer = pfb->next_buffer->next_buffer;
if (pfb->next_buffer) {
set_map_bit(BIT(5));
pfb->next_buffer->prev_buffer = pfb;
@@ -179,8 +176,8 @@ static void do_release(struct shm_buffer *ptr)
if (top == pfb->next_buffer) {
/* The new buffer is adjacent with the one right above it. */
set_map_bit(BIT(7));
- ptr->buffer_size = released_size +
- pfb->next_buffer->buffer_size;
+ ptr->buffer_size =
+ released_size + pfb->next_buffer->buffer_size;
ptr->next_buffer = pfb->next_buffer->next_buffer;
} else {
/* Just include the new free buffer into the chain. */
@@ -352,7 +349,7 @@ void shared_mem_release(void *ptr)
#ifdef CONFIG_CMD_SHMEM
-static int command_shmem(int argc, char **argv)
+static int command_shmem(int argc, const char **argv)
{
size_t allocated_size;
size_t free_size;
@@ -373,8 +370,7 @@ static int command_shmem(int argc, char **argv)
max_free = buf_room;
}
- for (buf = allocced_buf_chain; buf;
- buf = buf->next_buffer)
+ for (buf = allocced_buf_chain; buf; buf = buf->next_buffer)
allocated_size += buf->buffer_size;
mutex_unlock(&shmem_lock);
@@ -386,8 +382,7 @@ static int command_shmem(int argc, char **argv)
ccprintf("Max allocated: %6d\n", max_allocated_size);
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(shmem, command_shmem,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(shmem, command_shmem, NULL,
"Print shared memory stats");
-#endif /* CONFIG_CMD_SHMEM ^^^^^^^ defined */
+#endif /* CONFIG_CMD_SHMEM ^^^^^^^ defined */
diff --git a/common/spi_commands.c b/common/spi_commands.c
index 45c2f3ce70..9810039ede 100644
--- a/common/spi_commands.c
+++ b/common/spi_commands.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -8,11 +8,12 @@
#include "common.h"
#include "console.h"
+#include "printf.h"
#include "spi.h"
#include "timer.h"
#include "util.h"
-static int command_spixfer(int argc, char **argv)
+static int command_spixfer(int argc, const char **argv)
{
int dev_id;
uint8_t offset;
@@ -45,8 +46,13 @@ static int command_spixfer(int argc, char **argv)
rv = spi_transaction(&spi_devices[dev_id], &cmd, 1, data, v);
- if (!rv)
- ccprintf("Data: %ph\n", HEX_BUF(data, v));
+ if (!rv) {
+ char str_buf[hex_str_buf_size(v)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(data, v));
+ ccprintf("Data: %s\n", str_buf);
+ }
} else if (strcasecmp(argv[1], "w") == 0) {
/* 8-bit write */
diff --git a/common/spi_flash.c b/common/spi_flash.c
index e202e1e17d..8eaf3e8406 100644
--- a/common/spi_flash.c
+++ b/common/spi_flash.c
@@ -1,11 +1,12 @@
/*
- * Copyright 2014 The Chromium OS Authors. All rights reserved.
+ * Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* SPI flash driver for Chrome EC.
*/
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "host_command.h"
@@ -22,12 +23,12 @@
/*
* Time to sleep when chip is busy
*/
-#define SPI_FLASH_SLEEP_USEC 100
+#define SPI_FLASH_SLEEP_USEC 100
/*
* This is the max time for 32kb flash erase
*/
-#define SPI_FLASH_TIMEOUT_USEC (800*MSEC)
+#define SPI_FLASH_TIMEOUT_USEC (800 * MSEC)
/* Internal buffer used by SPI flash driver */
static uint8_t buf[SPI_FLASH_MAX_MESSAGE_SIZE];
@@ -109,13 +110,12 @@ uint8_t spi_flash_get_status2(void)
*/
int spi_flash_set_status(int reg1, int reg2)
{
- uint8_t cmd[3] = {SPI_FLASH_WRITE_SR, reg1, reg2};
+ uint8_t cmd[3] = { SPI_FLASH_WRITE_SR, reg1, reg2 };
int rv = EC_SUCCESS;
/* fail if both HW pin is asserted and SRP(s) is 1 */
if (spi_flash_check_wp() != SPI_WP_NONE &&
- (crec_flash_get_protect() &
- EC_FLASH_PROTECT_GPIO_ASSERTED) != 0)
+ (crec_flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) != 0)
return EC_ERROR_ACCESS_DENIED;
/* Enable writing to SPI flash */
@@ -123,7 +123,7 @@ int spi_flash_set_status(int reg1, int reg2)
if (rv)
return rv;
- /* Second status register not present */
+ /* Second status register not present */
#ifndef CONFIG_SPI_FLASH_HAS_SR2
reg2 = -1;
#endif
@@ -163,11 +163,8 @@ int spi_flash_read(uint8_t *buf_usr, unsigned int offset, unsigned int bytes)
cmd[2] = (spi_addr >> 8) & 0xFF;
cmd[3] = spi_addr & 0xFF;
read_size = MIN((bytes - i), SPI_FLASH_MAX_READ_SIZE);
- ret = spi_transaction(SPI_FLASH_DEVICE,
- cmd,
- 4,
- buf_usr + i,
- read_size);
+ ret = spi_transaction(SPI_FLASH_DEVICE, cmd, 4, buf_usr + i,
+ read_size);
if (ret != EC_SUCCESS)
break;
msleep(CONFIG_SPI_FLASH_READ_WAIT_MS);
@@ -276,7 +273,7 @@ int spi_flash_erase(unsigned int offset, unsigned int bytes)
* @return EC_SUCCESS, or non-zero if any error.
*/
int spi_flash_write(unsigned int offset, unsigned int bytes,
- const uint8_t *data)
+ const uint8_t *data)
{
int rv, write_size;
@@ -288,8 +285,10 @@ int spi_flash_write(unsigned int offset, unsigned int bytes,
while (bytes > 0) {
watchdog_reload();
/* Write length can not go beyond the end of the flash page */
- write_size = MIN(bytes, SPI_FLASH_MAX_WRITE_SIZE -
- (offset & (SPI_FLASH_MAX_WRITE_SIZE - 1)));
+ write_size =
+ MIN(bytes,
+ SPI_FLASH_MAX_WRITE_SIZE -
+ (offset & (SPI_FLASH_MAX_WRITE_SIZE - 1)));
/* Wait for previous operation to complete */
rv = spi_flash_wait();
@@ -310,8 +309,8 @@ int spi_flash_write(unsigned int offset, unsigned int bytes,
buf[2] = (offset) >> 8;
buf[3] = offset;
- rv = spi_transaction(SPI_FLASH_DEVICE,
- buf, 4 + write_size, NULL, 0);
+ rv = spi_transaction(SPI_FLASH_DEVICE, buf, 4 + write_size,
+ NULL, 0);
if (rv)
return rv;
@@ -345,7 +344,7 @@ int spi_flash_get_jedec_id(uint8_t *dest)
*/
int spi_flash_get_mfr_dev_id(uint8_t *dest)
{
- uint8_t cmd[4] = {SPI_FLASH_MFR_DEV_ID, 0, 0, 0};
+ uint8_t cmd[4] = { SPI_FLASH_MFR_DEV_ID, 0, 0, 0 };
return spi_transaction(SPI_FLASH_DEVICE, cmd, sizeof(cmd), dest, 2);
}
@@ -358,7 +357,7 @@ int spi_flash_get_mfr_dev_id(uint8_t *dest)
*/
int spi_flash_get_unique_id(uint8_t *dest)
{
- uint8_t cmd[5] = {SPI_FLASH_UNIQUE_ID, 0, 0, 0, 0};
+ uint8_t cmd[5] = { SPI_FLASH_UNIQUE_ID, 0, 0, 0, 0 };
return spi_transaction(SPI_FLASH_DEVICE, cmd, sizeof(cmd), dest, 8);
}
@@ -480,7 +479,7 @@ int spi_flash_set_protect(unsigned int offset, unsigned int bytes)
return spi_flash_set_status(sr1, sr2);
}
-static int command_spi_flashinfo(int argc, char **argv)
+static int command_spi_flashinfo(int argc, const char **argv)
{
uint8_t jedec[3];
uint8_t unique[8];
@@ -497,18 +496,17 @@ static int command_spi_flashinfo(int argc, char **argv)
spi_flash_get_jedec_id(jedec);
spi_flash_get_unique_id(unique);
- ccprintf("Manufacturer ID: %02x\nDevice ID: %02x %02x\n",
- jedec[0], jedec[1], jedec[2]);
+ ccprintf("Manufacturer ID: %02x\nDevice ID: %02x %02x\n", jedec[0],
+ jedec[1], jedec[2]);
ccprintf("Unique ID: %02x %02x %02x %02x %02x %02x %02x %02x\n",
- unique[0], unique[1], unique[2], unique[3],
- unique[4], unique[5], unique[6], unique[7]);
+ unique[0], unique[1], unique[2], unique[3], unique[4],
+ unique[5], unique[6], unique[7]);
ccprintf("Capacity: %4d kB\n", SPI_FLASH_SIZE(jedec[2]) / 1024);
return rv;
}
-DECLARE_CONSOLE_COMMAND(spi_flashinfo, command_spi_flashinfo,
- NULL,
- "Print SPI flash info");
+DECLARE_CONSOLE_COMMAND(spi_flashinfo, command_spi_flashinfo, NULL,
+ "Print SPI flash info");
#ifdef CONFIG_HOSTCMD_FLASH_SPI_INFO
static enum ec_status flash_command_spi_info(struct host_cmd_handler_args *args)
@@ -524,13 +522,12 @@ static enum ec_status flash_command_spi_info(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_FLASH_SPI_INFO,
- flash_command_spi_info,
+DECLARE_HOST_COMMAND(EC_CMD_FLASH_SPI_INFO, flash_command_spi_info,
EC_VER_MASK(0));
-#endif /* CONFIG_HOSTCMD_FLASH_SPI_INFO */
+#endif /* CONFIG_HOSTCMD_FLASH_SPI_INFO */
#ifdef CONFIG_CMD_SPI_FLASH
-static int command_spi_flasherase(int argc, char **argv)
+static int command_spi_flasherase(int argc, const char **argv)
{
int offset = -1;
int bytes = 4096;
@@ -549,10 +546,9 @@ static int command_spi_flasherase(int argc, char **argv)
return spi_flash_erase(offset, bytes);
}
DECLARE_CONSOLE_COMMAND(spi_flasherase, command_spi_flasherase,
- "offset [bytes]",
- "Erase flash");
+ "offset [bytes]", "Erase flash");
-static int command_spi_flashwrite(int argc, char **argv)
+static int command_spi_flashwrite(int argc, const char **argv)
{
int offset = -1;
int bytes = SPI_FLASH_MAX_WRITE_SIZE;
@@ -578,7 +574,8 @@ static int command_spi_flashwrite(int argc, char **argv)
while (bytes > 0) {
/* First write multiples of 256, then (bytes % 256) last */
write_len = ((bytes % SPI_FLASH_MAX_WRITE_SIZE) == bytes) ?
- bytes : SPI_FLASH_MAX_WRITE_SIZE;
+ bytes :
+ SPI_FLASH_MAX_WRITE_SIZE;
/* Perform write */
rv = spi_flash_write(offset, write_len, buf);
@@ -594,10 +591,9 @@ static int command_spi_flashwrite(int argc, char **argv)
return rv;
}
DECLARE_CONSOLE_COMMAND(spi_flashwrite, command_spi_flashwrite,
- "offset [bytes]",
- "Write pattern to flash");
+ "offset [bytes]", "Write pattern to flash");
-static int command_spi_flashread(int argc, char **argv)
+static int command_spi_flashread(int argc, const char **argv)
{
int i;
int offset = -1;
@@ -627,8 +623,8 @@ static int command_spi_flashread(int argc, char **argv)
/* First read (bytes % 256), then in multiples of 256 */
read_len = (bytes % SPI_FLASH_MAX_READ_SIZE) ?
- (bytes % SPI_FLASH_MAX_READ_SIZE) :
- SPI_FLASH_MAX_READ_SIZE;
+ (bytes % SPI_FLASH_MAX_READ_SIZE) :
+ SPI_FLASH_MAX_READ_SIZE;
rv = spi_flash_read(buf, offset, read_len);
if (rv)
@@ -651,11 +647,10 @@ static int command_spi_flashread(int argc, char **argv)
ASSERT(bytes == 0);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(spi_flashread, command_spi_flashread,
- "offset bytes",
- "Read flash");
+DECLARE_CONSOLE_COMMAND(spi_flashread, command_spi_flashread, "offset bytes",
+ "Read flash");
-static int command_spi_flashread_sr(int argc, char **argv)
+static int command_spi_flashread_sr(int argc, const char **argv)
{
spi_enable(SPI_FLASH_DEVICE, 1);
@@ -664,11 +659,10 @@ static int command_spi_flashread_sr(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(spi_flash_rsr, command_spi_flashread_sr,
- NULL,
- "Read status registers");
+DECLARE_CONSOLE_COMMAND(spi_flash_rsr, command_spi_flashread_sr, NULL,
+ "Read status registers");
-static int command_spi_flashwrite_sr(int argc, char **argv)
+static int command_spi_flashwrite_sr(int argc, const char **argv)
{
int val1 = 0;
int val2 = 0;
@@ -684,10 +678,9 @@ static int command_spi_flashwrite_sr(int argc, char **argv)
return spi_flash_set_status(val1, val2);
}
DECLARE_CONSOLE_COMMAND(spi_flash_wsr, command_spi_flashwrite_sr,
- "value1 value2",
- "Write to status registers");
+ "value1 value2", "Write to status registers");
-static int command_spi_flashprotect(int argc, char **argv)
+static int command_spi_flashprotect(int argc, const char **argv)
{
int val1 = 0;
int val2 = 0;
@@ -698,10 +691,10 @@ static int command_spi_flashprotect(int argc, char **argv)
spi_enable(SPI_FLASH_DEVICE, 1);
- ccprintf("Setting protection for 0x%06x to 0x%06x\n", val1, val1+val2);
+ ccprintf("Setting protection for 0x%06x to 0x%06x\n", val1,
+ val1 + val2);
return spi_flash_set_protect(val1, val2);
}
-DECLARE_CONSOLE_COMMAND(spi_flash_prot, command_spi_flashprotect,
- "offset len",
- "Set block protection");
+DECLARE_CONSOLE_COMMAND(spi_flash_prot, command_spi_flashprotect, "offset len",
+ "Set block protection");
#endif
diff --git a/common/spi_flash_reg.c b/common/spi_flash_reg.c
index ee8d31fa06..fa71ab5eb6 100644
--- a/common/spi_flash_reg.c
+++ b/common/spi_flash_reg.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -21,7 +21,7 @@ struct protect_range {
enum bit_state cmp;
enum bit_state sec;
enum bit_state tb;
- enum bit_state bp[3]; /* Ordered {BP2, BP1, BP0} */
+ enum bit_state bp[3]; /* Ordered {BP2, BP1, BP0} */
uint32_t protect_start;
uint32_t protect_len;
};
@@ -39,7 +39,7 @@ struct protect_range {
*/
#if defined(CONFIG_SPI_FLASH_W25X40) || defined(CONFIG_SPI_FLASH_GD25Q41B)
static const struct protect_range spi_flash_protect_ranges[] = {
- { IGN, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
+ { IGN, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
{ IGN, IGN, 1, { 0, 1, 1 }, 0, 0x40000 }, /* Lower 1/2 */
{ IGN, IGN, 1, { 0, 1, 0 }, 0, 0x20000 }, /* Lower 1/4 */
};
@@ -49,17 +49,17 @@ static const struct protect_range spi_flash_protect_ranges[] = {
/* For GD25LQ40, BP3 and BP4 have same meaning as TB and SEC */
static const struct protect_range spi_flash_protect_ranges[] = {
/* CMP = 0 */
- { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
- { 0, 0, 1, { 0, 1, 0 }, 0, 0x20000 }, /* Lower 1/4 */
- { 0, 0, 1, { 0, 1, 1 }, 0, 0x40000 }, /* Lower 1/2 */
+ { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
+ { 0, 0, 1, { 0, 1, 0 }, 0, 0x20000 }, /* Lower 1/4 */
+ { 0, 0, 1, { 0, 1, 1 }, 0, 0x40000 }, /* Lower 1/2 */
/* CMP = 1 */
- { 1, 0, 0, { 0, 1, 1 }, 0, 0x40000 }, /* Lower 1/2 */
- { 1, 0, IGN, { 1, IGN, IGN }, 0, 0 }, /* None (W25Q40EW only) */
+ { 1, 0, 0, { 0, 1, 1 }, 0, 0x40000 }, /* Lower 1/2 */
+ { 1, 0, IGN, { 1, IGN, IGN }, 0, 0 }, /* None (W25Q40EW only) */
};
#elif defined(CONFIG_SPI_FLASH_W25Q64)
static const struct protect_range spi_flash_protect_ranges[] = {
- { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
+ { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
{ 0, 0, 1, { 1, 1, 0 }, 0, 0x400000 }, /* Lower 1/2 */
{ 0, 0, 1, { 1, 0, 1 }, 0, 0x200000 }, /* Lower 1/4 */
};
@@ -67,7 +67,7 @@ static const struct protect_range spi_flash_protect_ranges[] = {
#elif defined(CONFIG_SPI_FLASH_W25Q80)
static const struct protect_range spi_flash_protect_ranges[] = {
/* CMP = 0 */
- { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
+ { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
{ 0, 0, 1, { 0, 1, 0 }, 0, 0x20000 }, /* Lower 1/8 */
{ 0, 0, 1, { 0, 1, 1 }, 0, 0x40000 }, /* Lower 1/4 */
{ 0, 0, 1, { 1, 0, 0 }, 0, 0x80000 }, /* Lower 1/2 */
@@ -75,7 +75,7 @@ static const struct protect_range spi_flash_protect_ranges[] = {
#elif defined(CONFIG_SPI_FLASH_W25Q128)
static const struct protect_range spi_flash_protect_ranges[] = {
/* CMP = 0 */
- { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
+ { 0, IGN, IGN, { 0, 0, 0 }, 0, 0 }, /* No protection */
{ 0, 0, 1, { 1, 0, 0 }, 0, 0x20000 }, /* Lower 1/8 */
{ 0, 0, 1, { 1, 0, 1 }, 0, 0x40000 }, /* Lower 1/4 */
{ 0, 0, 1, { 1, 1, 0 }, 0, 0x80000 }, /* Lower 1/2 */
@@ -107,8 +107,9 @@ int spi_flash_reg_to_protect(uint8_t sr1, uint8_t sr2, unsigned int *start,
cmp = (sr2 & SPI_FLASH_SR2_CMP) ? 1 : 0;
sec = (sr1 & SPI_FLASH_SR1_SEC) ? 1 : 0;
tb = (sr1 & SPI_FLASH_SR1_TB) ? 1 : 0;
- bp = (sr1 & (SPI_FLASH_SR1_BP2 | SPI_FLASH_SR1_BP1 | SPI_FLASH_SR1_BP0))
- >> 2;
+ bp = (sr1 &
+ (SPI_FLASH_SR1_BP2 | SPI_FLASH_SR1_BP1 | SPI_FLASH_SR1_BP0)) >>
+ 2;
/* Bad pointers or invalid data */
if (!start || !len || sr1 == 0xff || sr2 == 0xff)
@@ -174,12 +175,10 @@ int spi_flash_protect_to_reg(unsigned int start, unsigned int len, uint8_t *sr1,
sec = GET_BIT(range->sec);
tb = GET_BIT(range->tb);
bp = GET_BIT(range->bp[0]) << 2 |
- GET_BIT(range->bp[1]) << 1 |
- GET_BIT(range->bp[2]);
+ GET_BIT(range->bp[1]) << 1 | GET_BIT(range->bp[2]);
*sr1 = (sec ? SPI_FLASH_SR1_SEC : 0) |
- (tb ? SPI_FLASH_SR1_TB : 0) |
- (bp << 2);
+ (tb ? SPI_FLASH_SR1_TB : 0) | (bp << 2);
*sr2 = (cmp ? SPI_FLASH_SR2_CMP : 0);
return EC_SUCCESS;
}
diff --git a/common/spi_nor.c b/common/spi_nor.c
index 0a719d63b3..015cb7077c 100644
--- a/common/spi_nor.c
+++ b/common/spi_nor.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -18,7 +18,7 @@
#ifdef CONFIG_SPI_NOR_DEBUG
#define CPRINTS(dev, string, args...) \
- cprints(CC_SPI, "SPI NOR %s: " string, (dev)->name, ## args)
+ cprints(CC_SPI, "SPI NOR %s: " string, (dev)->name, ##args)
#else
#define CPRINTS(dev, string, args...)
#endif
@@ -74,8 +74,8 @@ static int spi_nor_write_enable(const struct spi_nor_device_t *spi_nor_device)
int rv = EC_SUCCESS;
/* Set the write enable latch. */
- rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller],
- &cmd, 1, NULL, 0);
+ rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller], &cmd,
+ 1, NULL, 0);
if (rv)
return rv;
@@ -84,7 +84,7 @@ static int spi_nor_write_enable(const struct spi_nor_device_t *spi_nor_device)
if (rv)
return rv;
if ((status_register_value & SPI_NOR_STATUS_REGISTER_WEL) == 0)
- return EC_ERROR_UNKNOWN; /* WEL not set but should be. */
+ return EC_ERROR_UNKNOWN; /* WEL not set but should be. */
return rv;
}
@@ -101,7 +101,7 @@ static int spi_nor_read_ear(const struct spi_nor_device_t *spi_nor_device,
uint8_t command = SPI_NOR_OPCODE_RDEAR;
return spi_transaction(&spi_devices[spi_nor_device->spi_controller],
- &command, sizeof(command), value, 1);
+ &command, sizeof(command), value, 1);
}
int spi_nor_write_ear(const struct spi_nor_device_t *spi_nor_device,
@@ -122,8 +122,8 @@ int spi_nor_write_ear(const struct spi_nor_device_t *spi_nor_device,
buf[0] = SPI_NOR_OPCODE_WREAR;
buf[1] = value;
- rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller],
- buf, sizeof(buf), NULL, 0);
+ rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller], buf,
+ sizeof(buf), NULL, 0);
if (rv) {
CPRINTS(spi_nor_device, "Failed to write EAR, rv=%d", rv);
goto err_free;
@@ -134,9 +134,9 @@ int spi_nor_write_ear(const struct spi_nor_device_t *spi_nor_device,
goto err_free;
if (ear != value) {
- CPRINTS(spi_nor_device,
- "Write EAR error: write=%d, read=%d", value, ear);
- rv = EC_ERROR_UNKNOWN; /* WEL not set but should be. */
+ CPRINTS(spi_nor_device, "Write EAR error: write=%d, read=%d",
+ value, ear);
+ rv = EC_ERROR_UNKNOWN; /* WEL not set but should be. */
goto err_free;
}
@@ -157,8 +157,7 @@ static int spi_nor_wait(const struct spi_nor_device_t *spi_nor_device)
rv = spi_nor_read_status(spi_nor_device, &status_register_value);
if (rv)
return rv;
- timeout.val =
- get_time().val + spi_nor_device->timeout_usec;
+ timeout.val = get_time().val + spi_nor_device->timeout_usec;
while (status_register_value & SPI_NOR_STATUS_REGISTER_WIP) {
/* Reload the watchdog before sleeping. */
watchdog_reload();
@@ -181,10 +180,9 @@ static int spi_nor_wait(const struct spi_nor_device_t *spi_nor_device)
/**
* Read the Manufacturer bank and ID out of the JEDEC ID.
*/
-static int spi_nor_read_jedec_mfn_id(
- const struct spi_nor_device_t *spi_nor_device,
- uint8_t *out_mfn_bank,
- uint8_t *out_mfn_id)
+static int
+spi_nor_read_jedec_mfn_id(const struct spi_nor_device_t *spi_nor_device,
+ uint8_t *out_mfn_bank, uint8_t *out_mfn_id)
{
int rv = EC_SUCCESS;
uint8_t jedec_id[SPI_NOR_JEDEC_ID_BANKS];
@@ -192,8 +190,8 @@ static int spi_nor_read_jedec_mfn_id(
uint8_t cmd = SPI_NOR_OPCODE_JEDEC_ID;
/* Read the standardized part of the JEDEC ID. */
- rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller],
- &cmd, 1, jedec_id, SPI_NOR_JEDEC_ID_BANKS);
+ rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller], &cmd,
+ 1, jedec_id, SPI_NOR_JEDEC_ID_BANKS);
if (rv)
return rv;
@@ -214,11 +212,11 @@ static int spi_nor_read_jedec_mfn_id(
/**
* Read a doubleword out of a SFDP table (DWs are 1-based like the SFDP spec).
*/
-static int spi_nor_read_sfdp_dword(
- const struct spi_nor_device_t *spi_nor_device,
- uint32_t table_offset,
- uint8_t table_double_word,
- uint32_t *out_dw) {
+static int
+spi_nor_read_sfdp_dword(const struct spi_nor_device_t *spi_nor_device,
+ uint32_t table_offset, uint8_t table_double_word,
+ uint32_t *out_dw)
+{
uint8_t sfdp_cmd[5];
/* Calculate the byte offset based on the double word. */
uint32_t sfdp_offset = table_offset + ((table_double_word - 1) * 4);
@@ -228,7 +226,7 @@ static int spi_nor_read_sfdp_dword(
sfdp_cmd[1] = (sfdp_offset & 0xFF0000) >> 16;
sfdp_cmd[2] = (sfdp_offset & 0xFF00) >> 8;
sfdp_cmd[3] = (sfdp_offset & 0xFF);
- sfdp_cmd[4] = 0; /* Required extra cycle. */
+ sfdp_cmd[4] = 0; /* Required extra cycle. */
return spi_transaction(&spi_devices[spi_nor_device->spi_controller],
sfdp_cmd, 5, (uint8_t *)out_dw, 4);
}
@@ -248,10 +246,10 @@ static int is_basic_flash_parameter_table(uint8_t sfdp_major_rev,
BASIC_FLASH_PARAMETER_TABLE_1_0_ID);
} else if (sfdp_major_rev == 1 && sfdp_minor_rev >= 5) {
return ((SFDP_GET_BITFIELD(SFDP_1_5_PARAMETER_HEADER_DW1_ID_LSB,
- parameter_header_dw1) ==
+ parameter_header_dw1) ==
BASIC_FLASH_PARAMETER_TABLE_1_5_ID_LSB) &&
(SFDP_GET_BITFIELD(SFDP_1_5_PARAMETER_HEADER_DW2_ID_MSB,
- parameter_header_dw2) ==
+ parameter_header_dw2) ==
BASIC_FLASH_PARAMETER_TABLE_1_5_ID_MSB));
}
@@ -262,13 +260,10 @@ static int is_basic_flash_parameter_table(uint8_t sfdp_major_rev,
* Helper function to locate the SFDP Basic SPI Flash NOR Parameter Table.
*/
static int locate_sfdp_basic_parameter_table(
- const struct spi_nor_device_t *spi_nor_device,
- uint8_t *out_sfdp_major_rev,
- uint8_t *out_sfdp_minor_rev,
- uint8_t *out_table_major_rev,
- uint8_t *out_table_minor_rev,
- uint32_t *out_table_offset,
- size_t *out_table_size)
+ const struct spi_nor_device_t *spi_nor_device,
+ uint8_t *out_sfdp_major_rev, uint8_t *out_sfdp_minor_rev,
+ uint8_t *out_table_major_rev, uint8_t *out_table_minor_rev,
+ uint32_t *out_table_offset, size_t *out_table_size)
{
int rv = EC_SUCCESS;
uint8_t number_parameter_headers;
@@ -296,8 +291,8 @@ static int locate_sfdp_basic_parameter_table(
SFDP_GET_BITFIELD(SFDP_HEADER_DW2_SFDP_MAJOR, dw2);
*out_sfdp_minor_rev =
SFDP_GET_BITFIELD(SFDP_HEADER_DW2_SFDP_MINOR, dw2);
- CPRINTS(spi_nor_device, "SFDP v%d.%d discovered",
- *out_sfdp_major_rev, *out_sfdp_minor_rev);
+ CPRINTS(spi_nor_device, "SFDP v%d.%d discovered", *out_sfdp_major_rev,
+ *out_sfdp_minor_rev);
/* NPH is 0-based, so add 1. */
number_parameter_headers =
@@ -315,17 +310,16 @@ static int locate_sfdp_basic_parameter_table(
number_parameter_headers--;
/* Read this parameter header's two dwords. */
- rv = spi_nor_read_sfdp_dword(
- spi_nor_device, table_offset, 1, &dw1);
- rv |= spi_nor_read_sfdp_dword(
- spi_nor_device, table_offset, 2, &dw2);
+ rv = spi_nor_read_sfdp_dword(spi_nor_device, table_offset, 1,
+ &dw1);
+ rv |= spi_nor_read_sfdp_dword(spi_nor_device, table_offset, 2,
+ &dw2);
if (rv)
return rv;
/* Ensure it's the basic flash parameter table. */
- if (!is_basic_flash_parameter_table(*out_sfdp_major_rev,
- *out_sfdp_minor_rev,
- dw1, dw2))
+ if (!is_basic_flash_parameter_table(
+ *out_sfdp_major_rev, *out_sfdp_minor_rev, dw1, dw2))
continue;
/* The parameter header major and minor versioning is still the
@@ -352,8 +346,10 @@ static int locate_sfdp_basic_parameter_table(
*out_table_offset = SFDP_GET_BITFIELD(
SFDP_1_0_PARAMETER_HEADER_DW2_PTP, dw2);
/* Convert the size from DW to Bytes. */
- *out_table_size = SFDP_GET_BITFIELD(
- SFDP_1_0_PARAMETER_HEADER_DW1_PTL, dw1) * 4;
+ *out_table_size =
+ SFDP_GET_BITFIELD(SFDP_1_0_PARAMETER_HEADER_DW1_PTL,
+ dw1) *
+ 4;
}
if (!table_found) {
@@ -376,8 +372,7 @@ static int spi_nor_device_discover_sfdp_page_size(
struct spi_nor_device_t *spi_nor_device,
uint8_t basic_parameter_table_major_version,
uint8_t basic_parameter_table_minor_version,
- uint32_t basic_parameter_table_offset,
- size_t *page_size)
+ uint32_t basic_parameter_table_offset, size_t *page_size)
{
int rv = EC_SUCCESS;
uint32_t dw;
@@ -397,12 +392,12 @@ static int spi_nor_device_discover_sfdp_page_size(
} else if (basic_parameter_table_major_version == 1 &&
basic_parameter_table_minor_version >= 5) {
/* Use the Basic Flash Parameter v1.5 page size reporting. */
- rv = spi_nor_read_sfdp_dword(spi_nor_device,
- basic_parameter_table_offset, 11, &dw);
+ rv = spi_nor_read_sfdp_dword(
+ spi_nor_device, basic_parameter_table_offset, 11, &dw);
if (rv)
return rv;
- *page_size =
- 1 << SFDP_GET_BITFIELD(BFPT_1_5_DW11_PAGE_SIZE, dw);
+ *page_size = 1
+ << SFDP_GET_BITFIELD(BFPT_1_5_DW11_PAGE_SIZE, dw);
}
return EC_SUCCESS;
@@ -413,11 +408,10 @@ static int spi_nor_device_discover_sfdp_page_size(
* NOR Parameter Table.
*/
static int spi_nor_device_discover_sfdp_capacity(
- struct spi_nor_device_t *spi_nor_device,
- uint8_t basic_parameter_table_major_version,
- uint8_t basic_parameter_table_minor_version,
- uint32_t basic_parameter_table_offset,
- uint32_t *capacity)
+ struct spi_nor_device_t *spi_nor_device,
+ uint8_t basic_parameter_table_major_version,
+ uint8_t basic_parameter_table_minor_version,
+ uint32_t basic_parameter_table_offset, uint32_t *capacity)
{
int rv = EC_SUCCESS;
uint32_t dw;
@@ -425,15 +419,16 @@ static int spi_nor_device_discover_sfdp_capacity(
/* First attempt to discover the device's capacity. */
if (basic_parameter_table_major_version == 1) {
/* Use the Basic Flash Parameter v1.0 capacity reporting. */
- rv = spi_nor_read_sfdp_dword(spi_nor_device,
- basic_parameter_table_offset, 2, &dw);
+ rv = spi_nor_read_sfdp_dword(
+ spi_nor_device, basic_parameter_table_offset, 2, &dw);
if (rv)
return rv;
if (SFDP_GET_BITFIELD(BFPT_1_0_DW2_GT_2_GIBIBITS, dw)) {
/* Ensure the capacity is less than 4GiB. */
- uint64_t tmp_capacity = 1 <<
- (SFDP_GET_BITFIELD(BFPT_1_0_DW2_N, dw) - 3);
+ uint64_t tmp_capacity =
+ 1
+ << (SFDP_GET_BITFIELD(BFPT_1_0_DW2_N, dw) - 3);
if (tmp_capacity > UINT32_MAX)
return EC_ERROR_OVERFLOW;
*capacity = tmp_capacity;
@@ -456,8 +451,7 @@ static int spi_nor_read_internal(const struct spi_nor_device_t *spi_nor_device,
* is larger than the maximum read size.
*/
while (size > 0) {
- size_t read_size =
- MIN(size, CONFIG_SPI_NOR_MAX_READ_SIZE);
+ size_t read_size = MIN(size, CONFIG_SPI_NOR_MAX_READ_SIZE);
size_t read_command_size;
/* Set up the read command in the TX buffer. */
@@ -468,7 +462,7 @@ static int spi_nor_read_internal(const struct spi_nor_device_t *spi_nor_device,
buf[3] = (offset & 0xFF00) >> 8;
buf[4] = (offset & 0xFF);
read_command_size = 5;
- } else { /* in 3 byte addressing mode */
+ } else { /* in 3 byte addressing mode */
buf[1] = (offset & 0xFF0000) >> 16;
buf[2] = (offset & 0xFF00) >> 8;
buf[3] = (offset & 0xFF);
@@ -476,8 +470,8 @@ static int spi_nor_read_internal(const struct spi_nor_device_t *spi_nor_device,
}
rv = spi_transaction(
- &spi_devices[spi_nor_device->spi_controller],
- buf, read_command_size, data, read_size);
+ &spi_devices[spi_nor_device->spi_controller], buf,
+ read_command_size, data, read_size);
if (rv)
return rv;
@@ -513,16 +507,12 @@ int spi_nor_init(void)
uint8_t table_major_rev, table_minor_rev;
uint32_t table_offset;
size_t table_size;
- struct spi_nor_device_t *spi_nor_device =
- &spi_nor_devices[i];
+ struct spi_nor_device_t *spi_nor_device = &spi_nor_devices[i];
- rv |= locate_sfdp_basic_parameter_table(spi_nor_device,
- &sfdp_major_rev,
- &sfdp_minor_rev,
- &table_major_rev,
- &table_minor_rev,
- &table_offset,
- &table_size);
+ rv |= locate_sfdp_basic_parameter_table(
+ spi_nor_device, &sfdp_major_rev, &sfdp_minor_rev,
+ &table_major_rev, &table_minor_rev, &table_offset,
+ &table_size);
/* If we failed to find a compatible SFDP Basic Flash Parameter
* table, use the default capacity, page size, and addressing
@@ -532,13 +522,11 @@ int spi_nor_init(void)
uint32_t capacity = 0;
rv |= spi_nor_device_discover_sfdp_page_size(
- spi_nor_device,
- table_major_rev, table_minor_rev, table_offset,
- &page_size);
+ spi_nor_device, table_major_rev,
+ table_minor_rev, table_offset, &page_size);
rv |= spi_nor_device_discover_sfdp_capacity(
- spi_nor_device,
- table_major_rev, table_minor_rev, table_offset,
- &capacity);
+ spi_nor_device, table_major_rev,
+ table_minor_rev, table_offset, &capacity);
if (rv == EC_SUCCESS) {
mutex_lock(&driver_mutex);
spi_nor_device->capacity = capacity;
@@ -595,8 +583,8 @@ int spi_nor_set_4b_mode(struct spi_nor_device_t *spi_nor_device,
/* Claim the driver mutex to modify the device state. */
mutex_lock(&driver_mutex);
- rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller],
- &cmd, 1, NULL, 0);
+ rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller], &cmd,
+ 1, NULL, 0);
if (rv == EC_SUCCESS) {
spi_nor_device->in_4b_addressing_mode =
enter_4b_addressing_mode;
@@ -619,7 +607,8 @@ int spi_nor_set_4b_mode(struct spi_nor_device_t *spi_nor_device,
* @return ec_error_list (non-zero on error and timeout).
*/
int spi_nor_read_jedec_id(const struct spi_nor_device_t *spi_nor_device,
- size_t size, uint8_t *data) {
+ size_t size, uint8_t *data)
+{
int rv;
uint8_t cmd = SPI_NOR_OPCODE_JEDEC_ID;
@@ -628,8 +617,8 @@ int spi_nor_read_jedec_id(const struct spi_nor_device_t *spi_nor_device,
/* Claim the driver mutex. */
mutex_lock(&driver_mutex);
/* Read the JEDEC ID. */
- rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller],
- &cmd, 1, data, size);
+ rv = spi_transaction(&spi_devices[spi_nor_device->spi_controller], &cmd,
+ 1, data, size);
/* Release the driver mutex. */
mutex_unlock(&driver_mutex);
@@ -645,8 +634,8 @@ int spi_nor_read_jedec_id(const struct spi_nor_device_t *spi_nor_device,
* @param data Destination buffer for data.
* @return ec_error_list (non-zero on error and timeout).
*/
-int spi_nor_read(const struct spi_nor_device_t *spi_nor_device,
- uint32_t offset, size_t size, uint8_t *data)
+int spi_nor_read(const struct spi_nor_device_t *spi_nor_device, uint32_t offset,
+ size_t size, uint8_t *data)
{
int rv;
@@ -708,8 +697,8 @@ int spi_nor_erase(const struct spi_nor_device_t *spi_nor_device,
read_offset = offset;
read_left = erase_size;
while (read_left) {
- read_size = MIN(read_left,
- CONFIG_SPI_NOR_MAX_READ_SIZE);
+ read_size =
+ MIN(read_left, CONFIG_SPI_NOR_MAX_READ_SIZE);
/* Since CONFIG_SPI_NOR_MAX_READ_SIZE & erase_size are
* both guaranteed to be multiples of 4.
*/
@@ -731,8 +720,8 @@ int spi_nor_erase(const struct spi_nor_device_t *spi_nor_device,
*/
verify_offset = 0;
while (verify_offset <= read_size - 4) {
- if (*(uint32_t *)(buffer + verify_offset)
- != 0xffffffff) {
+ if (*(uint32_t *)(buffer + verify_offset) !=
+ 0xffffffff) {
break;
}
verify_offset += 4;
@@ -767,7 +756,7 @@ int spi_nor_erase(const struct spi_nor_device_t *spi_nor_device,
buf[3] = (offset & 0xFF00) >> 8;
buf[4] = (offset & 0xFF);
erase_command_size = 5;
- } else { /* in 3 byte addressing mode */
+ } else { /* in 3 byte addressing mode */
buf[1] = (offset & 0xFF0000) >> 16;
buf[2] = (offset & 0xFF00) >> 8;
buf[3] = (offset & 0xFF);
@@ -775,8 +764,8 @@ int spi_nor_erase(const struct spi_nor_device_t *spi_nor_device,
}
rv = spi_transaction(
- &spi_devices[spi_nor_device->spi_controller],
- buf, erase_command_size, NULL, 0);
+ &spi_devices[spi_nor_device->spi_controller], buf,
+ erase_command_size, NULL, 0);
if (rv)
goto err_free;
@@ -814,8 +803,8 @@ int spi_nor_write(const struct spi_nor_device_t *spi_nor_device,
/* Ensure the device's page size fits in the driver's buffer, if not
* emulate a smaller page size based on the buffer size. */
- effective_page_size = MIN(spi_nor_device->page_size,
- CONFIG_SPI_NOR_MAX_WRITE_SIZE);
+ effective_page_size =
+ MIN(spi_nor_device->page_size, CONFIG_SPI_NOR_MAX_WRITE_SIZE);
/* Split the write into multiple writes if the size is too large. */
while (size > 0) {
@@ -843,7 +832,7 @@ int spi_nor_write(const struct spi_nor_device_t *spi_nor_device,
buf[3] = (offset & 0xFF00) >> 8;
buf[4] = (offset & 0xFF);
prefix_size = 5;
- } else { /* in 3 byte addressing mode */
+ } else { /* in 3 byte addressing mode */
buf[1] = (offset & 0xFF0000) >> 16;
buf[2] = (offset & 0xFF00) >> 8;
buf[3] = (offset & 0xFF);
@@ -853,8 +842,8 @@ int spi_nor_write(const struct spi_nor_device_t *spi_nor_device,
memmove(buf + prefix_size, data, write_size);
rv = spi_transaction(
- &spi_devices[spi_nor_device->spi_controller],
- buf, prefix_size + write_size, NULL, 0);
+ &spi_devices[spi_nor_device->spi_controller], buf,
+ prefix_size + write_size, NULL, 0);
if (rv)
goto err_free;
@@ -877,7 +866,7 @@ err_free:
/* Serial NOR Flash console commands. */
#ifdef CONFIG_CMD_SPI_NOR
-static int command_spi_nor_info(int argc, char **argv)
+static int command_spi_nor_info(int argc, const char **argv)
{
int rv = EC_SUCCESS;
@@ -908,14 +897,13 @@ static int command_spi_nor_info(int argc, char **argv)
ccprintf("\tName: %s\n", spi_nor_device->name);
ccprintf("\tSPI controller index: %d\n",
spi_nor_device->spi_controller);
- ccprintf("\tTimeout: %d uSec\n",
- spi_nor_device->timeout_usec);
+ ccprintf("\tTimeout: %d uSec\n", spi_nor_device->timeout_usec);
ccprintf("\tCapacity: %d KiB\n",
spi_nor_device->capacity >> 10),
- ccprintf("\tAddressing: %s addressing mode\n",
- spi_nor_device->in_4b_addressing_mode ? "4B" : "3B");
- ccprintf("\tPage Size: %d Bytes\n",
- spi_nor_device->page_size);
+ ccprintf("\tAddressing: %s addressing mode\n",
+ spi_nor_device->in_4b_addressing_mode ? "4B" :
+ "3B");
+ ccprintf("\tPage Size: %d Bytes\n", spi_nor_device->page_size);
/* Get JEDEC ID info. */
rv = spi_nor_read_jedec_mfn_id(spi_nor_device, &mfn_bank,
@@ -927,27 +915,26 @@ static int command_spi_nor_info(int argc, char **argv)
/* Get SFDP info. */
if (locate_sfdp_basic_parameter_table(
- spi_nor_device, &sfdp_major_rev, &sfdp_minor_rev,
- &table_major_rev, &table_minor_rev, &table_offset,
- &table_size) != EC_SUCCESS) {
+ spi_nor_device, &sfdp_major_rev, &sfdp_minor_rev,
+ &table_major_rev, &table_minor_rev, &table_offset,
+ &table_size) != EC_SUCCESS) {
ccputs("\tNo JEDEC SFDP support detected\n");
- continue; /* Go on to the next device. */
+ continue; /* Go on to the next device. */
}
ccprintf("\tSFDP v%d.%d\n", sfdp_major_rev, sfdp_minor_rev);
ccprintf("\tFlash Parameter Table v%d.%d (%dB @ 0x%x)\n",
- table_major_rev, table_minor_rev,
- table_size, table_offset);
+ table_major_rev, table_minor_rev, table_size,
+ table_offset);
}
return rv;
}
-DECLARE_CONSOLE_COMMAND(spinorinfo, command_spi_nor_info,
- "[device]",
+DECLARE_CONSOLE_COMMAND(spinorinfo, command_spi_nor_info, "[device]",
"Report Serial NOR Flash device information");
-#endif /* CONFIG_CMD_SPI_NOR */
+#endif /* CONFIG_CMD_SPI_NOR */
#ifdef CONFIG_CMD_SPI_NOR
-static int command_spi_nor_erase(int argc, char **argv)
+static int command_spi_nor_erase(int argc, const char **argv)
{
const struct spi_nor_device_t *spi_nor_device;
int spi_nor_device_index;
@@ -967,17 +954,16 @@ static int command_spi_nor_erase(int argc, char **argv)
if (rv)
return rv;
- ccprintf("Erasing %d bytes at 0x%x on %s...\n",
- size, offset, spi_nor_device->name);
+ ccprintf("Erasing %d bytes at 0x%x on %s...\n", size, offset,
+ spi_nor_device->name);
return spi_nor_erase(spi_nor_device, offset, size);
}
DECLARE_CONSOLE_COMMAND(spinorerase, command_spi_nor_erase,
- "device [offset] [size]",
- "Erase flash");
-#endif /* CONFIG_CMD_SPI_NOR */
+ "device [offset] [size]", "Erase flash");
+#endif /* CONFIG_CMD_SPI_NOR */
#ifdef CONFIG_CMD_SPI_NOR
-static int command_spi_nor_write(int argc, char **argv)
+static int command_spi_nor_write(int argc, const char **argv)
{
const struct spi_nor_device_t *spi_nor_device;
int spi_nor_device_index;
@@ -1013,8 +999,8 @@ static int command_spi_nor_write(int argc, char **argv)
for (i = 0; i < size; i++)
data[i] = i;
- ccprintf("Writing %d bytes to 0x%x on %s...\n",
- size, offset, spi_nor_device->name);
+ ccprintf("Writing %d bytes to 0x%x on %s...\n", size, offset,
+ spi_nor_device->name);
rv = spi_nor_write(spi_nor_device, offset, size, data);
/* Free the buffer */
@@ -1023,12 +1009,11 @@ static int command_spi_nor_write(int argc, char **argv)
return rv;
}
DECLARE_CONSOLE_COMMAND(spinorwrite, command_spi_nor_write,
- "device [offset] [size]",
- "Write pattern to flash");
-#endif /* CONFIG_CMD_SPI_NOR */
+ "device [offset] [size]", "Write pattern to flash");
+#endif /* CONFIG_CMD_SPI_NOR */
#ifdef CONFIG_CMD_SPI_NOR
-static int command_spi_nor_read(int argc, char **argv)
+static int command_spi_nor_read(int argc, const char **argv)
{
const struct spi_nor_device_t *spi_nor_device;
int spi_nor_device_index;
@@ -1061,8 +1046,7 @@ static int command_spi_nor_read(int argc, char **argv)
}
/* Read the data */
- ccprintf("Reading %d bytes from %s...",
- size, spi_nor_device->name);
+ ccprintf("Reading %d bytes from %s...", size, spi_nor_device->name);
if (spi_nor_read(spi_nor_device, offset, size, data)) {
rv = EC_ERROR_INVAL;
goto err_free;
@@ -1086,6 +1070,5 @@ err_free:
return rv;
}
DECLARE_CONSOLE_COMMAND(spinorread, command_spi_nor_read,
- "device [offset] [size]",
- "Read flash");
-#endif /* CONFIG_CMD_SPI_NOR */
+ "device [offset] [size]", "Read flash");
+#endif /* CONFIG_CMD_SPI_NOR */
diff --git a/common/stillness_detector.c b/common/stillness_detector.c
index c33472aa22..c43e19873e 100644
--- a/common/stillness_detector.c
+++ b/common/stillness_detector.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -23,8 +23,8 @@ static bool stillness_batch_complete(struct still_det *still_det,
uint32_t sample_time)
{
bool complete = false;
- uint32_t batch_window = time_until(still_det->window_start_time,
- sample_time);
+ uint32_t batch_window =
+ time_until(still_det->window_start_time, sample_time);
/* Checking if enough data is accumulated */
if (batch_window >= still_det->min_batch_window &&
@@ -51,8 +51,8 @@ static inline fp_t compute_variance(fp_t acc_squared, fp_t acc, fp_t inv)
return fp_mul((acc_squared - fp_mul(fp_sq(acc), inv)), inv);
}
-bool still_det_update(struct still_det *still_det, uint32_t sample_time,
- fp_t x, fp_t y, fp_t z)
+bool still_det_update(struct still_det *still_det, uint32_t sample_time, fp_t x,
+ fp_t y, fp_t z)
{
fp_t inv = FLOAT_TO_FP(0.0f), var_x, var_y, var_z;
bool complete = false;
@@ -88,12 +88,12 @@ bool still_det_update(struct still_det *still_det, uint32_t sample_time,
return complete;
}
/* Calculating the VAR = sum(x^2)/n - sum(x)^2/n^2 */
- var_x = compute_variance(
- still_det->acc_xx, still_det->acc_x, inv);
- var_y = compute_variance(
- still_det->acc_yy, still_det->acc_y, inv);
- var_z = compute_variance(
- still_det->acc_zz, still_det->acc_z, inv);
+ var_x = compute_variance(still_det->acc_xx, still_det->acc_x,
+ inv);
+ var_y = compute_variance(still_det->acc_yy, still_det->acc_y,
+ inv);
+ var_z = compute_variance(still_det->acc_zz, still_det->acc_z,
+ inv);
/* Checking if sensor is still */
if (var_x < still_det->var_threshold &&
var_y < still_det->var_threshold &&
diff --git a/common/switch.c b/common/switch.c
index 40a5ab217f..f2a3266ed0 100644
--- a/common/switch.c
+++ b/common/switch.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -19,7 +19,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SWITCH, outstr)
-#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ##args)
static uint8_t *memmap_switches;
@@ -99,18 +99,14 @@ void switch_interrupt(enum gpio_signal signal)
}
#ifdef CONFIG_CMD_MMAPINFO
-static int command_mmapinfo(int argc, char **argv)
+static int command_mmapinfo(int argc, const char **argv)
{
uint8_t *memmap_switches = host_get_memmap(EC_MEMMAP_SWITCHES);
uint8_t val = *memmap_switches;
int i;
const char *explanation[] = {
- "lid_open",
- "powerbtn",
- "wp_off",
- "kbd_rec",
- "gpio_rec",
- "fake_dev",
+ "lid_open", "powerbtn", "wp_off",
+ "kbd_rec", "gpio_rec", "fake_dev",
};
ccprintf("memmap switches = 0x%x\n", val);
for (i = 0; i < ARRAY_SIZE(explanation); i++)
@@ -119,7 +115,6 @@ static int command_mmapinfo(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(mmapinfo, command_mmapinfo,
- NULL,
+DECLARE_CONSOLE_COMMAND(mmapinfo, command_mmapinfo, NULL,
"Print memmap switch state");
#endif
diff --git a/common/system.c b/common/system.c
index 013452c21a..b4387f5257 100644
--- a/common/system.c
+++ b/common/system.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -41,17 +41,17 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SYSTEM, outstr)
-#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
/* Round up to a multiple of 4 */
#define ROUNDUP4(x) (((x) + 3) & ~3)
/* Data for an individual jump tag */
struct jump_tag {
- uint16_t tag; /* Tag ID */
- uint8_t data_size; /* Size of data which follows */
- uint8_t data_version; /* Data version */
+ uint16_t tag; /* Tag ID */
+ uint8_t data_size; /* Size of data which follows */
+ uint8_t data_version; /* Data version */
/* Followed by data_size bytes of data */
};
@@ -59,10 +59,10 @@ struct jump_tag {
/* Jump data (at end of RAM, or preceding panic data) */
static struct jump_data *jdata;
-static uint32_t reset_flags; /* EC_RESET_FLAG_* */
+static uint32_t reset_flags; /* EC_RESET_FLAG_* */
static int jumped_to_image;
-static int disable_jump; /* Disable ALL jumps if system is locked */
-static int force_locked; /* Force system locked even if WP isn't enabled */
+static int disable_jump; /* Disable ALL jumps if system is locked */
+static int force_locked; /* Force system locked even if WP isn't enabled */
static enum ec_reboot_cmd reboot_at_shutdown;
static enum sysinfo_flags system_info_flags;
@@ -83,8 +83,8 @@ static uint32_t ap_sku_id;
#ifdef CONFIG_HOSTCMD_AP_SET_SKUID
-#define AP_SKUID_SYSJUMP_TAG 0x4153 /* AS */
-#define AP_SKUID_HOOK_VERSION 1
+#define AP_SKUID_SYSJUMP_TAG 0x4153 /* AS */
+#define AP_SKUID_HOOK_VERSION 1
/**
* Preserve AP SKUID across a sysjump.
@@ -109,7 +109,7 @@ static void ap_sku_id_restore_state(void)
AP_SKUID_SYSJUMP_TAG, &version, &size);
if (prev_ap_sku_id && version == AP_SKUID_HOOK_VERSION &&
- size == sizeof(prev_ap_sku_id)) {
+ size == sizeof(prev_ap_sku_id)) {
memcpy(&ap_sku_id, prev_ap_sku_id, sizeof(ap_sku_id));
}
}
@@ -271,8 +271,8 @@ static void print_reset_flags(uint32_t flags)
{
int count = 0;
int i;
- static const char * const reset_flag_descs[] = {
- #include "reset_flag_desc.inc"
+ static const char *const reset_flag_descs[] = {
+#include "reset_flag_desc.inc"
};
if (!flags) {
@@ -311,9 +311,8 @@ void system_print_banner(void)
CPRINTS("UART initialized after sysjump");
else
CPUTS("\n--- UART initialized after reboot ---\n");
- CPRINTF("[Image: %s, %s]\n",
- system_get_image_copy_string(),
- system_get_build_info());
+ CPRINTF("[Image: %s, %s]\n", system_get_image_copy_string(),
+ system_get_build_info());
CPUTS("[Reset cause: ");
system_print_reset_flags();
CPUTS("]\n");
@@ -415,9 +414,8 @@ void system_disable_jump(void)
*/
ret = mpu_protect_data_ram();
if (ret == EC_SUCCESS) {
- CPRINTS("data RAM locked. Exclusion %pP-%pP",
- &__iram_text_start,
- &__iram_text_end);
+ CPRINTS("data RAM locked. Exclusion %p-%p",
+ &__iram_text_start, &__iram_text_end);
} else {
CPRINTS("Failed to lock data RAM (%d)", ret);
return;
@@ -441,11 +439,11 @@ void system_disable_jump(void)
*/
switch (system_get_image_copy()) {
case EC_IMAGE_RO:
- ret = mpu_lock_rw_flash();
+ ret = mpu_lock_rw_flash();
copy = EC_IMAGE_RW;
break;
case EC_IMAGE_RW:
- ret = mpu_lock_ro_flash();
+ ret = mpu_lock_ro_flash();
copy = EC_IMAGE_RO;
break;
default:
@@ -453,8 +451,7 @@ void system_disable_jump(void)
ret = !EC_SUCCESS;
}
if (ret == EC_SUCCESS) {
- CPRINTS("%s image locked",
- ec_image_to_string(copy));
+ CPRINTS("%s image locked", ec_image_to_string(copy));
} else {
CPRINTS("Failed to lock %s image (%d)",
ec_image_to_string(copy), ret);
@@ -477,8 +474,8 @@ test_mockable enum ec_image system_get_image_copy(void)
/* Return which region is used in program memory */
return system_get_shrspi_image_copy();
#else
- uintptr_t my_addr = (uintptr_t)system_get_image_copy -
- CONFIG_PROGRAM_MEMORY_BASE;
+ uintptr_t my_addr =
+ (uintptr_t)system_get_image_copy - CONFIG_PROGRAM_MEMORY_BASE;
if (my_addr >= CONFIG_RO_MEM_OFF &&
my_addr < (CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE))
@@ -541,9 +538,8 @@ const char *system_get_image_copy_string(void)
const char *ec_image_to_string(enum ec_image copy)
{
- static const char * const image_names[] = {
- "unknown", "RO", "RW", "RO_B", "RW_B"
- };
+ static const char *const image_names[] = { "unknown", "RO", "RW",
+ "RO_B", "RW_B" };
return image_names[copy < ARRAY_SIZE(image_names) ? copy : 0];
}
@@ -604,7 +600,7 @@ static void jump_to_image(uintptr_t init_addr)
jdata->magic = JUMP_DATA_MAGIC;
jdata->version = JUMP_DATA_VERSION;
jdata->reset_flags = reset_flags;
- jdata->jump_tag_total = 0; /* Reset tags */
+ jdata->jump_tag_total = 0; /* Reset tags */
jdata->struct_size = sizeof(struct jump_data);
/* Call other hooks; these may add tags */
@@ -619,7 +615,7 @@ static void jump_to_image(uintptr_t init_addr)
#endif /* CONFIG_DMA */
/* Jump to the reset vector */
- resetvec = (void(*)(void))init_addr;
+ resetvec = (void (*)(void))init_addr;
resetvec();
}
@@ -688,8 +684,8 @@ static int system_run_image_copy_with_flags(enum ec_image copy,
if (copy == EC_IMAGE_RO)
system_clear_reset_flags(EC_RESET_FLAG_EFS);
- CPRINTS("Jumping to image %s (0x%08x)",
- ec_image_to_string(copy), system_get_reset_flags());
+ CPRINTS("Jumping to image %s (0x%08x)", ec_image_to_string(copy),
+ system_get_reset_flags());
jump_to_image(init_addr);
@@ -715,9 +711,9 @@ enum ec_image system_get_active_copy(void)
enum ec_image system_get_update_copy(void)
{
-#ifdef CONFIG_VBOOT_EFS /* Not needed for EFS2, which is single-slot. */
- return system_get_active_copy() == EC_IMAGE_RW_A ?
- EC_IMAGE_RW_B : EC_IMAGE_RW_A;
+#ifdef CONFIG_VBOOT_EFS /* Not needed for EFS2, which is single-slot. */
+ return system_get_active_copy() == EC_IMAGE_RW_A ? EC_IMAGE_RW_B :
+ EC_IMAGE_RW_A;
#else
return EC_IMAGE_RW_A;
#endif
@@ -764,7 +760,7 @@ const struct image_data *system_get_image_data(enum ec_image copy)
* it's the same offset as in the current image. Find that offset.
*/
addr = ((uintptr_t)&current_image_data -
- get_program_memory_addr(active_copy));
+ get_program_memory_addr(active_copy));
/*
* Read the version information from the proper location
@@ -792,24 +788,23 @@ const struct image_data *system_get_image_data(enum ec_image copy)
return NULL;
}
-__attribute__((weak)) /* Weird chips may need their own implementations */
-const char *system_get_version(enum ec_image copy)
+__attribute__((weak)) /* Weird chips may need their own implementations */
+const char *
+system_get_version(enum ec_image copy)
{
const struct image_data *data = system_get_image_data(copy);
return data ? data->version : "";
}
-
const char *system_get_cros_fwid(enum ec_image copy)
{
const struct image_data *data;
if (IS_ENABLED(CONFIG_CROS_FWID_VERSION)) {
data = system_get_image_data(copy);
- if (data &&
- (data->cookie3 & CROS_EC_IMAGE_DATA_COOKIE3_MASK) ==
- CROS_EC_IMAGE_DATA_COOKIE3)
+ if (data && (data->cookie3 & CROS_EC_IMAGE_DATA_COOKIE3_MASK) ==
+ CROS_EC_IMAGE_DATA_COOKIE3)
return data->cros_fwid;
else
return CROS_FWID_MISSING_STR;
@@ -870,8 +865,9 @@ int system_get_board_version(void)
return board_get_version();
}
-__attribute__((weak)) /* Weird chips may need their own implementations */
-const char *system_get_build_info(void)
+__attribute__((weak)) /* Weird chips may need their own implementations */
+const char *
+system_get_build_info(void)
{
return build_info;
}
@@ -917,7 +913,7 @@ void system_common_pre_init(void)
* the new fields below.
*/
if (jdata->version == 1)
- delta = 0; /* No tags in v1, so no need for move */
+ delta = 0; /* No tags in v1, so no need for move */
else if (jdata->version == 2)
delta = sizeof(struct jump_data) - JUMP_DATA_SIZE_V2;
else
@@ -975,8 +971,8 @@ static int handle_pending_reboot(enum ec_reboot_cmd cmd)
case EC_REBOOT_CANCEL:
return EC_SUCCESS;
case EC_REBOOT_JUMP_RO:
- return system_run_image_copy_with_flags(EC_IMAGE_RO,
- EC_RESET_FLAG_STAY_IN_RO);
+ return system_run_image_copy_with_flags(
+ EC_IMAGE_RO, EC_RESET_FLAG_STAY_IN_RO);
case EC_REBOOT_JUMP_RW:
return system_run_image_copy(system_get_active_copy());
case EC_REBOOT_COLD:
@@ -1046,7 +1042,8 @@ static int handle_pending_reboot(enum ec_reboot_cmd cmd)
}
}
-void system_enter_hibernate(uint32_t seconds, uint32_t microseconds)
+test_mockable void system_enter_hibernate(uint32_t seconds,
+ uint32_t microseconds)
{
if (!IS_ENABLED(CONFIG_HIBERNATE))
return;
@@ -1059,8 +1056,8 @@ void system_enter_hibernate(uint32_t seconds, uint32_t microseconds)
* this is to prevent an action triggered by developers.
* See: b/192259035
*/
- if (IS_ENABLED(CONFIG_EXTPOWER) && IS_ENABLED(CONFIG_AP_POWER_CONTROL)
- && extpower_is_present()) {
+ if (IS_ENABLED(CONFIG_EXTPOWER) &&
+ IS_ENABLED(CONFIG_AP_POWER_CONTROL) && extpower_is_present()) {
CPRINTS("AC on, skip hibernate");
return;
}
@@ -1125,7 +1122,7 @@ static int sysinfo(struct ec_response_sysinfo *info)
return EC_SUCCESS;
}
-static int command_sysinfo(int argc, char **argv)
+static int command_sysinfo(int argc, const char **argv)
{
struct ec_response_sysinfo info;
int rv;
@@ -1160,8 +1157,7 @@ static int command_sysinfo(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(sysinfo, command_sysinfo,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(sysinfo, command_sysinfo, NULL,
"Print system info");
static enum ec_status host_command_sysinfo(struct host_cmd_handler_args *args)
@@ -1181,7 +1177,7 @@ DECLARE_HOST_COMMAND(EC_CMD_SYSINFO, host_command_sysinfo,
#endif
#ifdef CONFIG_CMD_SCRATCHPAD
-static int command_scratchpad(int argc, char **argv)
+static int command_scratchpad(int argc, const char **argv)
{
int rv = EC_SUCCESS;
uint32_t scratchpad_value;
@@ -1207,12 +1203,11 @@ static int command_scratchpad(int argc, char **argv)
ccprintf("Scratchpad: 0x%08x\n", scratchpad_value);
return rv;
}
-DECLARE_CONSOLE_COMMAND(scratchpad, command_scratchpad,
- "[val]",
+DECLARE_CONSOLE_COMMAND(scratchpad, command_scratchpad, "[val]",
"Get or set scratchpad value");
#endif /* CONFIG_CMD_SCRATCHPAD */
-__maybe_unused static int command_hibernate(int argc, char **argv)
+__maybe_unused static int command_hibernate(int argc, const char **argv)
{
int seconds = 0;
int microseconds = 0;
@@ -1238,8 +1233,7 @@ __maybe_unused static int command_hibernate(int argc, char **argv)
return EC_SUCCESS;
}
#ifdef CONFIG_HIBERNATE
-DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate,
- "[sec] [usec]",
+DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate, "[sec] [usec]",
"Hibernate the EC");
#endif /* CONFIG_HIBERNATE */
@@ -1284,7 +1278,7 @@ static void print_build_string(void)
ccprintf("\n");
}
-static int command_version(int argc, char **argv)
+static int command_version(int argc, const char **argv)
{
int board_version;
const char *fw_version;
@@ -1353,12 +1347,10 @@ static int command_version(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(version, command_version,
- NULL,
- "Print versions");
+DECLARE_SAFE_CONSOLE_COMMAND(version, command_version, NULL, "Print versions");
#ifdef CONFIG_CMD_SYSJUMP
-static int command_sysjump(int argc, char **argv)
+static int command_sysjump(int argc, const char **argv)
{
uint32_t addr;
char *e;
@@ -1368,8 +1360,8 @@ static int command_sysjump(int argc, char **argv)
/* Handle named images */
if (!strcasecmp(argv[1], "RO"))
- return system_run_image_copy_with_flags(EC_IMAGE_RO,
- EC_RESET_FLAG_STAY_IN_RO);
+ return system_run_image_copy_with_flags(
+ EC_IMAGE_RO, EC_RESET_FLAG_STAY_IN_RO);
else if (!strcasecmp(argv[1], "RW") || !strcasecmp(argv[1], "A"))
return system_run_image_copy(EC_IMAGE_RW);
else if (!strcasecmp(argv[1], "B")) {
@@ -1402,7 +1394,7 @@ DECLARE_CONSOLE_COMMAND(sysjump, command_sysjump,
"Jump to a system image or address");
#endif
-static int command_reboot(int argc, char **argv)
+static int command_reboot(int argc, const char **argv)
{
int flags = SYSTEM_RESET_MANUALLY_TRIGGERED;
int i;
@@ -1449,13 +1441,12 @@ DECLARE_CONSOLE_COMMAND(
"Reboot the EC");
#ifdef CONFIG_CMD_SYSLOCK
-static int command_system_lock(int argc, char **argv)
+static int command_system_lock(int argc, const char **argv)
{
force_locked = 1;
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(syslock, command_system_lock,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(syslock, command_system_lock, NULL,
"Lock the system, even if WP is disabled");
#endif
@@ -1464,7 +1455,7 @@ DECLARE_SAFE_CONSOLE_COMMAND(syslock, command_system_lock,
* Modify and print the sleep mask which controls access to deep sleep
* mode in the idle task.
*/
-static int command_sleepmask(int argc, char **argv)
+static int command_sleepmask(int argc, const char **argv)
{
#ifdef CONFIG_CMD_SLEEPMASK_SET
int v;
@@ -1496,7 +1487,7 @@ DECLARE_SAFE_CONSOLE_COMMAND(sleepmask, command_sleepmask,
#endif
#ifdef CONFIG_CMD_JUMPTAGS
-static int command_jumptags(int argc, char **argv)
+static int command_jumptags(int argc, const char **argv)
{
const struct jump_tag *t;
int used = 0;
@@ -1510,21 +1501,18 @@ static int command_jumptags(int argc, char **argv)
t = (const struct jump_tag *)(system_usable_ram_end() + used);
used += sizeof(struct jump_tag) + ROUNDUP4(t->data_size);
- ccprintf("%08x: 0x%04x %c%c.%d %3d\n",
- (uintptr_t)t,
- t->tag, t->tag >> 8, (uint8_t)t->tag,
- t->data_version, t->data_size);
+ ccprintf("%08x: 0x%04x %c%c.%d %3d\n", (uintptr_t)t, t->tag,
+ t->tag >> 8, (uint8_t)t->tag, t->data_version,
+ t->data_size);
}
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(jumptags, command_jumptags,
- NULL,
- "List jump tags");
+DECLARE_CONSOLE_COMMAND(jumptags, command_jumptags, NULL, "List jump tags");
#endif /* CONFIG_CMD_JUMPTAGS */
#ifdef CONFIG_EMULATED_SYSRQ
-static int command_sysrq(int argc, char **argv)
+static int command_sysrq(int argc, const char **argv)
{
char key = 'x';
@@ -1535,20 +1523,18 @@ static int command_sysrq(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(sysrq, command_sysrq,
- "[key]",
+DECLARE_CONSOLE_COMMAND(sysrq, command_sysrq, "[key]",
"Simulate sysrq press (default: x)");
#endif /* CONFIG_EMULATED_SYSRQ */
#ifdef CONFIG_CMD_RESET_FLAGS
-static int command_rflags(int argc, char **argv)
+static int command_rflags(int argc, const char **argv)
{
print_reset_flags(chip_read_reset_flags());
ccprintf("\n");
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(rflags, command_rflags,
- NULL,
+DECLARE_CONSOLE_COMMAND(rflags, command_rflags, NULL,
"Print reset flags saved in non-volatile memory");
#endif
@@ -1606,8 +1592,7 @@ host_command_get_version(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_VERSION,
- host_command_get_version,
+DECLARE_HOST_COMMAND(EC_CMD_GET_VERSION, host_command_get_version,
EC_VER_MASK(0) | EC_VER_MASK(1));
#ifdef CONFIG_HOSTCMD_SKUID
@@ -1621,8 +1606,7 @@ host_command_get_sku_id(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_SKU_ID,
- host_command_get_sku_id,
+DECLARE_HOST_COMMAND(EC_CMD_GET_SKU_ID, host_command_get_sku_id,
EC_VER_MASK(0));
#endif
@@ -1636,8 +1620,7 @@ host_command_set_sku_id(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_SET_SKU_ID,
- host_command_set_sku_id,
+DECLARE_HOST_COMMAND(EC_CMD_SET_SKU_ID, host_command_set_sku_id,
EC_VER_MASK(0));
#endif
@@ -1652,8 +1635,7 @@ host_command_get_keyboard_id(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_KEYBOARD_ID,
- host_command_get_keyboard_id,
+DECLARE_HOST_COMMAND(EC_CMD_GET_KEYBOARD_ID, host_command_get_keyboard_id,
EC_VER_MASK(0));
#endif
@@ -1665,8 +1647,7 @@ host_command_build_info(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_BUILD_INFO,
- host_command_build_info,
+DECLARE_HOST_COMMAND(EC_CMD_GET_BUILD_INFO, host_command_build_info,
EC_VER_MASK(0));
static enum ec_status
@@ -1682,8 +1663,7 @@ host_command_get_chip_info(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_CHIP_INFO,
- host_command_get_chip_info,
+DECLARE_HOST_COMMAND(EC_CMD_GET_CHIP_INFO, host_command_get_chip_info,
EC_VER_MASK(0));
static enum ec_status
@@ -1703,8 +1683,7 @@ host_command_get_board_version(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_BOARD_VERSION,
- host_command_get_board_version,
+DECLARE_HOST_COMMAND(EC_CMD_GET_BOARD_VERSION, host_command_get_board_version,
EC_VER_MASK(0));
static enum ec_status host_command_reboot(struct host_cmd_handler_args *args)
@@ -1738,10 +1717,8 @@ static enum ec_status host_command_reboot(struct host_cmd_handler_args *args)
}
#ifdef HAS_TASK_HOSTCMD
- if (p.cmd == EC_REBOOT_JUMP_RO ||
- p.cmd == EC_REBOOT_JUMP_RW ||
- p.cmd == EC_REBOOT_COLD ||
- p.cmd == EC_REBOOT_HIBERNATE ||
+ if (p.cmd == EC_REBOOT_JUMP_RO || p.cmd == EC_REBOOT_JUMP_RW ||
+ p.cmd == EC_REBOOT_COLD || p.cmd == EC_REBOOT_HIBERNATE ||
p.cmd == EC_REBOOT_COLD_AP_OFF) {
/* Clean busy bits on host for commands that won't return */
args->result = EC_RES_SUCCESS;
@@ -1761,21 +1738,18 @@ static enum ec_status host_command_reboot(struct host_cmd_handler_args *args)
return EC_RES_ERROR;
}
}
-DECLARE_HOST_COMMAND(EC_CMD_REBOOT_EC,
- host_command_reboot,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_REBOOT_EC, host_command_reboot, EC_VER_MASK(0));
int system_can_boot_ap(void)
{
int soc = -1;
int pow = -1;
-#if defined(CONFIG_BATTERY) && \
- defined(CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
+#if defined(CONFIG_BATTERY) && defined(CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
/* Require a minimum battery level to power on. If battery isn't
* present, battery_state_of_charge_abs returns false. */
if (battery_state_of_charge_abs(&soc) == EC_SUCCESS &&
- soc >= CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
+ soc >= CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
return 1;
#endif
@@ -1816,7 +1790,7 @@ __overridable int board_write_serial(const char *serialno)
else
return EC_ERROR_UNIMPLEMENTED;
}
-#endif /* CONFIG_SERIALNO_LEN */
+#endif /* CONFIG_SERIALNO_LEN */
#ifdef CONFIG_MAC_ADDR_LEN
/* By default, read MAC address from flash, can be overridden. */
@@ -1838,10 +1812,10 @@ __overridable int board_write_mac_addr(const char *mac_addr)
else
return EC_ERROR_UNIMPLEMENTED;
}
-#endif /* CONFIG_MAC_ADDR_LEN */
+#endif /* CONFIG_MAC_ADDR_LEN */
-__attribute__((weak))
-void clock_enable_module(enum module_id module, int enable)
+__attribute__((weak)) void clock_enable_module(enum module_id module,
+ int enable)
{
/*
* Default weak implementation - for chips that don't support this
@@ -1854,4 +1828,14 @@ __test_only void system_common_reset_state(void)
jdata = 0;
reset_flags = 0;
jumped_to_image = 0;
+ system_info_flags = 0;
+}
+
+__test_only enum ec_reboot_cmd system_common_get_reset_reboot_at_shutdown(void)
+{
+ int ret = reboot_at_shutdown;
+
+ reboot_at_shutdown = 0;
+
+ return ret;
}
diff --git a/common/tablet_mode.c b/common/tablet_mode.c
index d6780f34a2..576e80c0ef 100644
--- a/common/tablet_mode.c
+++ b/common/tablet_mode.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -13,8 +13,8 @@
#include "tablet_mode.h"
#include "timer.h"
-#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ##args)
/*
* Other code modules assume that notebook mode (i.e. tablet_mode = 0) at
@@ -58,7 +58,6 @@ static void notify_tablet_mode_change(void)
*/
if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS))
host_set_single_event(EC_HOST_EVENT_MODE_CHANGE);
-
}
void tablet_set_mode(int mode, uint32_t trigger)
@@ -105,9 +104,9 @@ void tablet_disable(void)
#endif
static void gmr_tablet_switch_interrupt_debounce(void)
{
- gmr_sensor_at_360 = IS_ENABLED(CONFIG_GMR_TABLET_MODE_CUSTOM)
- ? board_sensor_at_360()
- : !gpio_get_level(GPIO_TABLET_MODE_L);
+ gmr_sensor_at_360 = IS_ENABLED(CONFIG_GMR_TABLET_MODE_CUSTOM) ?
+ board_sensor_at_360() :
+ !gpio_get_level(GPIO_TABLET_MODE_L);
/*
* DPTF table is updated only when the board enters/exits completely
@@ -116,9 +115,9 @@ static void gmr_tablet_switch_interrupt_debounce(void)
* calculation and update DPTF table when lid angle > 300 degrees.
*/
if (IS_ENABLED(CONFIG_HOSTCMD_X86) && IS_ENABLED(CONFIG_DPTF)) {
- acpi_dptf_set_profile_num(gmr_sensor_at_360 ?
- DPTF_PROFILE_FLIPPED_360_MODE :
- DPTF_PROFILE_CLAMSHELL);
+ acpi_dptf_set_profile_num(
+ gmr_sensor_at_360 ? DPTF_PROFILE_FLIPPED_360_MODE :
+ DPTF_PROFILE_CLAMSHELL);
}
/*
* 1. Peripherals are disabled only when lid reaches 360 position (It's
@@ -142,7 +141,7 @@ static void gmr_tablet_switch_interrupt_debounce(void)
DECLARE_DEFERRED(gmr_tablet_switch_interrupt_debounce);
/* Debounce time for gmr sensor tablet mode interrupt */
-#define GMR_SENSOR_DEBOUNCE_US (30 * MSEC)
+#define GMR_SENSOR_DEBOUNCE_US (30 * MSEC)
void gmr_tablet_switch_isr(enum gpio_signal signal)
{
@@ -175,7 +174,7 @@ void gmr_tablet_switch_disable(void)
#endif
#ifdef CONFIG_TABLET_MODE
-static int command_settabletmode(int argc, char **argv)
+static int command_settabletmode(int argc, const char **argv)
{
static uint32_t tablet_mode_store;
@@ -206,7 +205,13 @@ static int command_settabletmode(int argc, char **argv)
notify_tablet_mode_change();
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(tabletmode, command_settabletmode,
- "[on | off | reset]",
- "Manually force tablet mode to on, off or reset.");
+DECLARE_CONSOLE_COMMAND(tabletmode, command_settabletmode, "[on | off | reset]",
+ "Manually force tablet mode to on, off or reset.");
#endif
+
+__test_only void tablet_reset(void)
+{
+ tablet_mode = 0;
+ tablet_mode_forced = false;
+ disabled = false;
+}
diff --git a/common/temp_sensor.c b/common/temp_sensor.c
index 66ba5298dc..f2a764c151 100644
--- a/common/temp_sensor.c
+++ b/common/temp_sensor.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -44,8 +44,7 @@ static void update_mapped_memory(void)
*/
if (i == EC_TEMP_SENSOR_ENTRIES)
mptr = host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B);
- else if (i >= EC_TEMP_SENSOR_ENTRIES +
- EC_TEMP_SENSOR_B_ENTRIES)
+ else if (i >= EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES)
break;
switch (temp_sensor_read(i, &t)) {
@@ -143,12 +142,11 @@ int print_temps(void)
/* Console commands */
#ifdef CONFIG_CMD_TEMP_SENSOR
-static int command_temps(int argc, char **argv)
+static int command_temps(int argc, const char **argv)
{
return print_temps();
}
-DECLARE_CONSOLE_COMMAND(temps, command_temps,
- NULL,
+DECLARE_CONSOLE_COMMAND(temps, command_temps, NULL,
"Print temp sensors and fan speed");
#endif
@@ -172,6 +170,5 @@ temp_sensor_command_get_info(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO,
- temp_sensor_command_get_info,
+DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO, temp_sensor_command_get_info,
EC_VER_MASK(0));
diff --git a/common/test_util.c b/common/test_util.c
index 37cc42000c..f15b99f302 100644
--- a/common/test_util.c
+++ b/common/test_util.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -29,23 +29,33 @@ struct test_util_tag {
int __test_error_count;
/* Weak reference function as an entry point for unit test */
-test_mockable void run_test(int argc, char **argv) { }
+test_mockable void run_test(int argc, const char **argv)
+{
+}
/* Default mock test init */
-test_mockable void test_init(void) { }
+test_mockable void test_init(void)
+{
+}
/* Default mock before test */
-test_mockable void before_test(void) { }
+test_mockable void before_test(void)
+{
+}
/* Default mock after test */
-test_mockable void after_test(void) { }
+test_mockable void after_test(void)
+{
+}
#ifdef TEST_COVERAGE
-extern void __gcov_flush(void);
+extern void __gcov_dump(void);
+extern void __gcov_reset(void);
void emulator_flush(void)
{
- __gcov_flush();
+ __gcov_dump();
+ __gcov_reset();
}
#else
void emulator_flush(void)
@@ -167,7 +177,7 @@ int test_send_host_command(int command, int version, const void *params,
return host_command_process(&args);
}
-#endif /* TASK_HAS_HOSTCMD */
+#endif /* TASK_HAS_HOSTCMD */
/* Linear congruential pseudo random number generator */
uint32_t prng(uint32_t seed)
@@ -188,8 +198,7 @@ static void restore_state(void)
tag = (const struct test_util_tag *)system_get_jump_tag(
TEST_UTIL_SYSJUMP_TAG, &version, &size);
- if (tag && version == TEST_UTIL_SYSJUMP_VERSION &&
- size == sizeof(*tag))
+ if (tag && version == TEST_UTIL_SYSJUMP_VERSION && size == sizeof(*tag))
__test_error_count = tag->error_count;
else
__test_error_count = 0;
@@ -205,13 +214,12 @@ static void preserve_state(void)
}
DECLARE_HOOK(HOOK_SYSJUMP, preserve_state, HOOK_PRIO_DEFAULT);
-static int command_run_test(int argc, char **argv)
+static int command_run_test(int argc, const char **argv)
{
run_test(argc, argv);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL);
+DECLARE_CONSOLE_COMMAND(runtest, command_run_test, NULL, NULL);
#ifndef CONFIG_ZEPHYR
void z_ztest_run_test_suite(const char *name, struct unit_test *suite)
diff --git a/common/thermal.c b/common/thermal.c
index 50bf3e27f1..975afed3d1 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -25,7 +25,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_THERMAL, outstr)
-#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ##args)
/*****************************************************************************/
/* EC-specific thermal controls */
@@ -93,7 +93,6 @@ static void thermal_control(void)
/* go through all the sensors */
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
-
/* read one */
rv = temp_sensor_read(i, &t);
@@ -242,30 +241,26 @@ DECLARE_HOOK(HOOK_SECOND, thermal_control, HOOK_PRIO_TEMP_SENSOR_DONE);
/*****************************************************************************/
/* Console commands */
-static int command_thermalget(int argc, char **argv)
+static int command_thermalget(int argc, const char **argv)
{
int i;
ccprintf("sensor warn high halt fan_off fan_max name\n");
for (i = 0; i < TEMP_SENSOR_COUNT; i++) {
ccprintf(" %2d %3d %3d %3d %3d %3d %s\n",
- i,
- thermal_params[i].temp_host[EC_TEMP_THRESH_WARN],
+ i, thermal_params[i].temp_host[EC_TEMP_THRESH_WARN],
thermal_params[i].temp_host[EC_TEMP_THRESH_HIGH],
thermal_params[i].temp_host[EC_TEMP_THRESH_HALT],
thermal_params[i].temp_fan_off,
- thermal_params[i].temp_fan_max,
- temp_sensors[i].name);
+ thermal_params[i].temp_fan_max, temp_sensors[i].name);
}
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(thermalget, command_thermalget,
- NULL,
+DECLARE_CONSOLE_COMMAND(thermalget, command_thermalget, NULL,
"Print thermal parameters (degrees Kelvin)");
-
-static int command_thermalset(int argc, char **argv)
+static int command_thermalset(int argc, const char **argv)
{
unsigned int n;
int i, val;
@@ -329,8 +324,7 @@ thermal_command_set_threshold(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_THERMAL_SET_THRESHOLD,
- thermal_command_set_threshold,
- EC_VER_MASK(1));
+ thermal_command_set_threshold, EC_VER_MASK(1));
static enum ec_status
thermal_command_get_threshold(struct host_cmd_handler_args *args)
@@ -346,5 +340,4 @@ thermal_command_get_threshold(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_THERMAL_GET_THRESHOLD,
- thermal_command_get_threshold,
- EC_VER_MASK(1));
+ thermal_command_get_threshold, EC_VER_MASK(1));
diff --git a/common/throttle_ap.c b/common/throttle_ap.c
index 33e004ba7b..39223f9829 100644
--- a/common/throttle_ap.c
+++ b/common/throttle_ap.c
@@ -1,10 +1,11 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Common chipset throttling code for Chrome EC */
+#include "builtin/assert.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -19,15 +20,15 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_THERMAL, outstr)
-#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ##args)
/*
* When C10 deasserts, PROCHOT may also change state when the corresponding
* power rail is turned back on. Recheck PROCHOT directly from the C10 exit
* using a shorter debounce than the PROCHOT interrupt.
*/
-#define PROCHOT_IN_DEBOUNCE_US (100 * MSEC)
-#define C10_IN_DEBOUNCE_US (10 * MSEC)
+#define PROCHOT_IN_DEBOUNCE_US (100 * MSEC)
+#define C10_IN_DEBOUNCE_US (10 * MSEC)
/*****************************************************************************/
/* This enforces the virtual OR of all throttling sources. */
@@ -36,8 +37,7 @@ static uint32_t throttle_request[NUM_THROTTLE_TYPES];
static int debounced_prochot_in;
static const struct prochot_cfg *prochot_cfg;
-void throttle_ap(enum throttle_level level,
- enum throttle_type type,
+void throttle_ap(enum throttle_level level, enum throttle_type type,
enum throttle_sources source)
{
uint32_t tmpval, bitmask;
@@ -55,7 +55,7 @@ void throttle_ap(enum throttle_level level,
break;
}
- tmpval = throttle_request[type]; /* save for printing */
+ tmpval = throttle_request[type]; /* save for printing */
switch (type) {
case THROTTLE_SOFT:
@@ -79,9 +79,8 @@ void throttle_ap(enum throttle_level level,
mutex_unlock(&throttle_mutex);
/* print outside the mutex */
- CPRINTS("set AP throttling type %d to %s (0x%08x)",
- type, tmpval ? "on" : "off", tmpval);
-
+ CPRINTS("set AP throttling type %d to %s (0x%08x)", type,
+ tmpval ? "on" : "off", tmpval);
}
void throttle_ap_config_prochot(const struct prochot_cfg *cfg)
@@ -128,7 +127,7 @@ static void prochot_input_deferred(void)
* asserting low is normal behavior and not a concern
* for PROCHOT# event. Ignore all PROCHOT changes while the AP is off
*/
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF | CHIPSET_STATE_ANY_SUSPEND))
return;
/*
@@ -163,7 +162,7 @@ void throttle_ap_prochot_input_interrupt(enum gpio_signal signal)
* any pulses that are too short.
*/
hook_call_deferred(&prochot_input_deferred_data,
- PROCHOT_IN_DEBOUNCE_US);
+ PROCHOT_IN_DEBOUNCE_US);
}
#ifdef CONFIG_CPU_PROCHOT_GATE_ON_C10
@@ -181,7 +180,7 @@ void throttle_ap_c10_input_interrupt(enum gpio_signal signal)
/*****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_APTHROTTLE
-static int command_apthrottle(int argc, char **argv)
+static int command_apthrottle(int argc, const char **argv)
{
int i;
uint32_t tmpval;
@@ -197,7 +196,6 @@ static int command_apthrottle(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(apthrottle, command_apthrottle,
- NULL,
+DECLARE_CONSOLE_COMMAND(apthrottle, command_apthrottle, NULL,
"Display the AP throttling state");
#endif
diff --git a/common/timer.c b/common/timer.c
index a8d02e7ece..eea773619b 100644
--- a/common/timer.c
+++ b/common/timer.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
/* Timer module for Chrome EC operating system */
#include "atomic.h"
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "hooks.h"
@@ -19,19 +20,19 @@
#ifdef CONFIG_ZEPHYR
#include <zephyr/kernel.h> /* For k_usleep() */
#else
-extern __error("k_usleep() should only be called from Zephyr code")
-int32_t k_usleep(int32_t);
+extern __error("k_usleep() should only be called from Zephyr code") int32_t
+ k_usleep(int32_t);
#endif /* CONFIG_ZEPHYR */
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
#else
#define CPRINTS(format, args...)
#define CPRINTF(format, args...)
#endif
-#define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */
+#define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */
/* High 32-bits of the 64-bit timestamp counter. */
STATIC_IF_NOT(CONFIG_HWTIMER_64BIT) volatile uint32_t clksrc_high;
@@ -82,7 +83,6 @@ void process_timers(int overflow)
/* read atomically the current state of timer running */
check_timer = running_t0 = timer_running;
while (check_timer) {
-
int tskid = __fls(check_timer);
/* timer has expired ? */
if (timer_deadline[tskid].val <= now.val)
@@ -95,7 +95,7 @@ void process_timers(int overflow)
check_timer &= ~BIT(tskid);
}
- /* if there is a new timer, let's retry */
+ /* if there is a new timer, let's retry */
} while (timer_running & ~running_t0);
if (next.le.hi == 0xffffffff) {
@@ -203,7 +203,7 @@ void usleep(unsigned us)
do {
evt |= task_wait_event(us);
} while (!(evt & TASK_EVENT_TIMER) &&
- ((__hw_clock_source_read() - t0) < us));
+ ((__hw_clock_source_read() - t0) < us));
/* Re-queue other events which happened in the meanwhile */
if (evt)
@@ -246,7 +246,7 @@ timestamp_t get_time(void)
clock_t clock(void)
{
/* __hw_clock_source_read() returns a microsecond resolution timer.*/
- return (clock_t) __hw_clock_source_read() / 1000;
+ return (clock_t)__hw_clock_source_read() / 1000;
}
void force_time(timestamp_t ts)
@@ -299,8 +299,7 @@ void __hw_clock_source_set(uint32_t ts)
void timer_print_info(void)
{
timestamp_t t = get_time();
- uint64_t deadline = (uint64_t)t.le.hi << 32 |
- __hw_clock_event_get();
+ uint64_t deadline = (uint64_t)t.le.hi << 32 | __hw_clock_event_get();
int tskid;
ccprintf("Time: 0x%016llx us, %11.6lld s\n"
@@ -354,7 +353,7 @@ static void timer_sysjump(void)
DECLARE_HOOK(HOOK_SYSJUMP, timer_sysjump, HOOK_PRIO_DEFAULT);
#ifdef CONFIG_CMD_WAITMS
-static int command_wait(int argc, char **argv)
+static int command_wait(int argc, const char **argv)
{
char *e;
int i;
@@ -366,6 +365,9 @@ static int command_wait(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM1;
+ if (i < 0)
+ return EC_ERROR_PARAM1;
+
/*
* Reload the watchdog so that issuing multiple small waitms commands
* quickly one after the other will not cause a reset.
@@ -384,8 +386,7 @@ static int command_wait(int argc, char **argv)
return EC_SUCCESS;
}
/* Typically a large delay (e.g. 3s) will cause a reset */
-DECLARE_CONSOLE_COMMAND(waitms, command_wait,
- "msec",
+DECLARE_CONSOLE_COMMAND(waitms, command_wait, "msec",
"Busy-wait for msec (large delays will reset)");
#endif
@@ -395,7 +396,7 @@ DECLARE_CONSOLE_COMMAND(waitms, command_wait,
* especially when going "backward" in time, because task deadlines are
* left un-adjusted.
*/
-static int command_force_time(int argc, char **argv)
+static int command_force_time(int argc, const char **argv)
{
char *e;
timestamp_t new;
@@ -416,32 +417,29 @@ static int command_force_time(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(forcetime, command_force_time,
- "hi lo",
+DECLARE_CONSOLE_COMMAND(forcetime, command_force_time, "hi lo",
"Force current time");
#endif
#ifdef CONFIG_CMD_GETTIME
-static int command_get_time(int argc, char **argv)
+static int command_get_time(int argc, const char **argv)
{
timestamp_t ts = get_time();
ccprintf("Time: 0x%016llx = %.6lld s\n", ts.val, ts.val);
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(gettime, command_get_time,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(gettime, command_get_time, NULL,
"Print current time");
#endif
#ifdef CONFIG_CMD_TIMERINFO
-static int command_timer_info(int argc, char **argv)
+static int command_timer_info(int argc, const char **argv)
{
timer_print_info();
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(timerinfo, command_timer_info,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(timerinfo, command_timer_info, NULL,
"Print timer info");
#endif
diff --git a/common/typec_control.c b/common/typec_control.c
index 1fea258389..94070d47df 100644
--- a/common/typec_control.c
+++ b/common/typec_control.c
@@ -1,4 +1,4 @@
-/* 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.
*/
@@ -28,7 +28,7 @@ void typec_set_sbu(int port, bool enable)
}
__overridable void typec_set_source_current_limit(int port,
- enum tcpc_rp_value rp)
+ enum tcpc_rp_value rp)
{
if (IS_ENABLED(CONFIG_USBC_PPC))
ppc_set_vbus_source_current_limit(port, rp);
@@ -45,8 +45,8 @@ void typec_set_vconn(int port, bool enable)
* the PD state machine detects a disconnection on the CC lines, we will
* reset our OC event counter.
*/
- if (IS_ENABLED(CONFIG_USBC_OCP) &&
- enable && usbc_ocp_is_port_latched_off(port))
+ if (IS_ENABLED(CONFIG_USBC_OCP) && enable &&
+ usbc_ocp_is_port_latched_off(port))
return;
/*
diff --git a/common/uart_buffering.c b/common/uart_buffering.c
index d993eab345..1aa6e9ef35 100644
--- a/common/uart_buffering.c
+++ b/common/uart_buffering.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -22,7 +22,7 @@
/* Macros to advance in the circular buffers */
#define TX_BUF_NEXT(i) (((i) + 1) & (CONFIG_UART_TX_BUF_SIZE - 1))
#define RX_BUF_NEXT(i) (((i) + 1) & (CONFIG_UART_RX_BUF_SIZE - 1))
-#define RX_BUF_PREV(i) (((i) - 1) & (CONFIG_UART_RX_BUF_SIZE - 1))
+#define RX_BUF_PREV(i) (((i)-1) & (CONFIG_UART_RX_BUF_SIZE - 1))
/* Macros to calculate difference of pointers in the circular buffers. */
#define TX_BUF_DIFF(i, j) (((i) - (j)) & (CONFIG_UART_TX_BUF_SIZE - 1))
@@ -37,12 +37,12 @@ BUILD_ASSERT((CONFIG_UART_RX_BUF_SIZE & (CONFIG_UART_RX_BUF_SIZE - 1)) == 0);
* of input has been detected by the normal tick task. There will be
* CONFIG_UART_RX_DMA_RECHECKS rechecks between this tick and the next tick.
*/
-#define RX_DMA_RECHECK_INTERVAL (HOOK_TICK_INTERVAL / \
- (CONFIG_UART_RX_DMA_RECHECKS + 1))
+#define RX_DMA_RECHECK_INTERVAL \
+ (HOOK_TICK_INTERVAL / (CONFIG_UART_RX_DMA_RECHECKS + 1))
/* Transmit and receive buffers */
-static volatile char tx_buf[CONFIG_UART_TX_BUF_SIZE]
- __uncached __preserved_logs(tx_buf);
+static volatile char tx_buf[CONFIG_UART_TX_BUF_SIZE] __uncached
+ __preserved_logs(tx_buf);
static volatile int tx_buf_head __preserved_logs(tx_buf_head);
static volatile int tx_buf_tail __preserved_logs(tx_buf_tail);
static volatile char rx_buf[CONFIG_UART_RX_BUF_SIZE] __uncached;
@@ -59,7 +59,6 @@ static int uart_buffer_calc_checksum(void)
return tx_buf_head ^ tx_buf_tail;
}
-
void uart_init_buffer(void)
{
if (tx_checksum != uart_buffer_calc_checksum() ||
@@ -81,8 +80,8 @@ int uart_tx_char_raw(void *context, int c)
int tx_buf_next, tx_buf_new_tail;
#if defined CONFIG_POLLING_UART
- (void) tx_buf_next;
- (void) tx_buf_new_tail;
+ (void)tx_buf_next;
+ (void)tx_buf_new_tail;
uart_write_char(c);
#else
@@ -137,7 +136,7 @@ void uart_process_output(void)
/* If a previous DMA transfer completed, free up the buffer it used */
if (tx_dma_in_progress) {
tx_buf_tail = (tx_buf_tail + tx_dma_in_progress) &
- (CONFIG_UART_TX_BUF_SIZE - 1);
+ (CONFIG_UART_TX_BUF_SIZE - 1);
tx_dma_in_progress = 0;
if (IS_ENABLED(CONFIG_PRESERVE_LOGS))
@@ -154,8 +153,9 @@ void uart_process_output(void)
* Get the largest contiguous block of output. If the transmit buffer
* wraps, only use the part before the wrap.
*/
- tx_dma_in_progress = (head > tx_buf_tail ? head :
- CONFIG_UART_TX_BUF_SIZE) - tx_buf_tail;
+ tx_dma_in_progress =
+ (head > tx_buf_tail ? head : CONFIG_UART_TX_BUF_SIZE) -
+ tx_buf_tail;
uart_tx_dma_start((char *)(tx_buf + tx_buf_tail), tx_dma_in_progress);
}
@@ -181,7 +181,7 @@ void uart_process_output(void)
#endif /* !CONFIG_UART_TX_DMA */
#ifdef CONFIG_UART_RX_DMA
-#ifdef CONFIG_UART_INPUT_FILTER /* TODO(crosbug.com/p/36745): */
+#ifdef CONFIG_UART_INPUT_FILTER /* TODO(crosbug.com/p/36745): */
#error "Filtering the UART input with DMA enabled is NOT SUPPORTED!"
#endif
@@ -245,7 +245,7 @@ void uart_process_input(void)
void uart_clear_input(void)
{
- int scratch __attribute__ ((unused));
+ int scratch __attribute__((unused));
while (uart_rx_available())
scratch = uart_read_char();
rx_buf_head = rx_buf_tail = 0;
@@ -347,9 +347,7 @@ enum ec_status uart_console_read_buffer_init(void)
return EC_RES_SUCCESS;
}
-int uart_console_read_buffer(uint8_t type,
- char *dest,
- uint16_t dest_size,
+int uart_console_read_buffer(uint8_t type, char *dest, uint16_t dest_size,
uint16_t *write_count)
{
int *tail;
@@ -371,7 +369,6 @@ int uart_console_read_buffer(uint8_t type,
/* Copy data to response */
while (*tail != tx_snapshot_head && *write_count < dest_size - 1) {
-
/*
* Copy only non-zero bytes, so that we don't copy unused
* bytes if the buffer hasn't completely rolled at boot.
diff --git a/common/uart_hostcmd.c b/common/uart_hostcmd.c
index 5cef2a8e24..7b4ff5b461 100644
--- a/common/uart_hostcmd.c
+++ b/common/uart_hostcmd.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/common/uart_printf.c b/common/uart_printf.c
index 198d076971..6f8ebb5cbc 100644
--- a/common/uart_printf.c
+++ b/common/uart_printf.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/common/update_fw.c b/common/update_fw.c
index 068758e7b0..85b805191c 100644
--- a/common/update_fw.c
+++ b/common/update_fw.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -25,13 +25,13 @@
#include "touchpad_fw_hash.h"
BUILD_ASSERT(sizeof(touchpad_fw_hashes) ==
- (CONFIG_TOUCHPAD_FW_CHUNKS * SHA256_DIGEST_SIZE));
+ (CONFIG_TOUCHPAD_FW_CHUNKS * SHA256_DIGEST_SIZE));
BUILD_ASSERT(sizeof(touchpad_fw_hashes[0]) == SHA256_DIGEST_SIZE);
BUILD_ASSERT(sizeof(touchpad_fw_full_hash) == SHA256_DIGEST_SIZE);
#endif
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USB, format, ##args)
/* Section to be updated (i.e. not the current section). */
struct {
@@ -47,9 +47,8 @@ struct {
static int is_touchpad_block(uint32_t block_offset, size_t body_size)
{
return (block_offset >= CONFIG_TOUCHPAD_VIRTUAL_OFF) &&
- (block_offset + body_size) <=
- (CONFIG_TOUCHPAD_VIRTUAL_OFF +
- CONFIG_TOUCHPAD_VIRTUAL_SIZE);
+ (block_offset + body_size) <= (CONFIG_TOUCHPAD_VIRTUAL_OFF +
+ CONFIG_TOUCHPAD_VIRTUAL_SIZE);
}
#endif
@@ -71,17 +70,15 @@ static uint8_t check_update_chunk(uint32_t block_offset, size_t body_size)
if (update_section.base_offset != update_section.top_offset &&
(block_offset >= update_section.base_offset) &&
((block_offset + body_size) <= update_section.top_offset)) {
-
base = update_section.base_offset;
- size = update_section.top_offset -
- update_section.base_offset;
+ size = update_section.top_offset - update_section.base_offset;
/*
* If this is the first chunk for this section, it needs to
* be erased.
*/
if (block_offset == base) {
if (crec_flash_physical_erase(base, size) !=
- EC_SUCCESS) {
+ EC_SUCCESS) {
CPRINTF("%s:%d erase failure of 0x%x..+0x%x\n",
__func__, __LINE__, base, size);
return UPDATE_ERASE_FAILURE;
@@ -96,14 +93,11 @@ static uint8_t check_update_chunk(uint32_t block_offset, size_t body_size)
return UPDATE_SUCCESS;
#endif
- CPRINTF("%s:%d %x, %d section base %x top %x\n",
- __func__, __LINE__,
- block_offset, body_size,
- update_section.base_offset,
+ CPRINTF("%s:%d %x, %d section base %x top %x\n", __func__, __LINE__,
+ block_offset, body_size, update_section.base_offset,
update_section.top_offset);
return UPDATE_BAD_ADDR;
-
}
int update_pdu_valid(struct update_command *cmd_body, size_t cmd_size)
@@ -120,8 +114,8 @@ static void new_chunk_written(uint32_t block_offset)
{
}
-static int contents_allowed(uint32_t block_offset,
- size_t body_size, void *update_data)
+static int contents_allowed(uint32_t block_offset, size_t body_size,
+ void *update_data)
{
#if defined(CONFIG_TOUCHPAD_VIRTUAL_OFF) && defined(CONFIG_TOUCHPAD_HASH_FW)
if (is_touchpad_block(block_offset, body_size)) {
@@ -132,9 +126,9 @@ static int contents_allowed(uint32_t block_offset,
int good = 0;
if (chunk >= CONFIG_TOUCHPAD_FW_CHUNKS ||
- (fw_offset % CONFIG_UPDATE_PDU_SIZE) != 0) {
- CPRINTF("%s: TP invalid offset %08x\n",
- __func__, fw_offset);
+ (fw_offset % CONFIG_UPDATE_PDU_SIZE) != 0) {
+ CPRINTF("%s: TP invalid offset %08x\n", __func__,
+ fw_offset);
return 0;
}
@@ -143,10 +137,10 @@ static int contents_allowed(uint32_t block_offset,
tmp = SHA256_final(&ctx);
good = !memcmp(tmp, touchpad_fw_hashes[chunk],
- SHA256_DIGEST_SIZE);
+ SHA256_DIGEST_SIZE);
- CPRINTF("%s: TP %08x %02x..%02x (%s)\n", __func__,
- fw_offset, tmp[0], tmp[31], good ? "GOOD" : "BAD");
+ CPRINTF("%s: TP %08x %02x..%02x (%s)\n", __func__, fw_offset,
+ tmp[0], tmp[31], good ? "GOOD" : "BAD");
return good;
}
@@ -194,7 +188,7 @@ void fw_update_start(struct first_response_pdu *rpdu)
rpdu->common.offset = htobe32(update_section.base_offset);
if (version)
memcpy(rpdu->common.version, version,
- sizeof(rpdu->common.version));
+ sizeof(rpdu->common.version));
#ifdef CONFIG_ROLLBACK
rpdu->common.min_rollback = htobe32(rollback_get_minimum_version());
@@ -216,13 +210,12 @@ void fw_update_start(struct first_response_pdu *rpdu)
#endif
}
-void fw_update_command_handler(void *body,
- size_t cmd_size,
+void fw_update_command_handler(void *body, size_t cmd_size,
size_t *response_size)
{
struct update_command *cmd_body = body;
void *update_data;
- uint8_t *error_code = body; /* Cache the address for code clarity. */
+ uint8_t *error_code = body; /* Cache the address for code clarity. */
size_t body_size;
uint32_t block_offset;
@@ -285,11 +278,11 @@ void fw_update_command_handler(void *body,
#ifdef CONFIG_TOUCHPAD_VIRTUAL_OFF
if (is_touchpad_block(block_offset, body_size)) {
if (touchpad_update_write(
- block_offset - CONFIG_TOUCHPAD_VIRTUAL_OFF,
- body_size, update_data) != EC_SUCCESS) {
+ block_offset - CONFIG_TOUCHPAD_VIRTUAL_OFF,
+ body_size, update_data) != EC_SUCCESS) {
*error_code = UPDATE_WRITE_FAILURE;
- CPRINTF("%s:%d update write error\n",
- __func__, __LINE__);
+ CPRINTF("%s:%d update write error\n", __func__,
+ __LINE__);
return;
}
@@ -301,8 +294,8 @@ void fw_update_command_handler(void *body,
#endif
CPRINTF("update: 0x%x\n", block_offset + CONFIG_PROGRAM_MEMORY_BASE);
- if (crec_flash_physical_write(block_offset, body_size, update_data)
- != EC_SUCCESS) {
+ if (crec_flash_physical_write(block_offset, body_size, update_data) !=
+ EC_SUCCESS) {
*error_code = UPDATE_WRITE_FAILURE;
CPRINTF("%s:%d update write error\n", __func__, __LINE__);
return;
@@ -311,12 +304,12 @@ void fw_update_command_handler(void *body,
new_chunk_written(block_offset);
/* Verify that data was written properly. */
- if (memcmp(update_data, (void *)
- (block_offset + CONFIG_PROGRAM_MEMORY_BASE),
+ if (memcmp(update_data,
+ (void *)(block_offset + CONFIG_PROGRAM_MEMORY_BASE),
body_size)) {
*error_code = UPDATE_VERIFY_ERROR;
- CPRINTF("%s:%d update verification error\n",
- __func__, __LINE__);
+ CPRINTF("%s:%d update verification error\n", __func__,
+ __LINE__);
return;
}
diff --git a/common/uptime.c b/common/uptime.c
index 3c3be3e55c..3b2c68fd34 100644
--- a/common/uptime.c
+++ b/common/uptime.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -32,14 +32,12 @@ host_command_get_uptime_info(struct host_cmd_handler_args *args)
r->ec_reset_flags = system_get_reset_flags();
memset(r->recent_ap_reset, 0, sizeof(r->recent_ap_reset));
- rc = get_ap_reset_stats(recent_ap_reset,
- ARRAY_SIZE(r->recent_ap_reset),
+ rc = get_ap_reset_stats(recent_ap_reset, ARRAY_SIZE(r->recent_ap_reset),
&ap_resets_since_ec_boot);
r->ap_resets_since_ec_boot = ap_resets_since_ec_boot;
args->response_size = sizeof(*r);
return rc == EC_SUCCESS ? EC_RES_SUCCESS : EC_RES_ERROR;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_UPTIME_INFO,
- host_command_get_uptime_info,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_GET_UPTIME_INFO, host_command_get_uptime_info,
+ EC_VER_MASK(0));
diff --git a/common/usb_charger.c b/common/usb_charger.c
index d0b6dd3ca1..60deade0ef 100644
--- a/common/usb_charger.c
+++ b/common/usb_charger.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 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,7 @@
* is necessary to update charge_manager with detected charger attributes.
*/
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charger.h"
#include "common.h"
@@ -48,7 +49,7 @@ BUILD_ASSERT(BIT(3) == TASK_EVENT_CUSTOM_BIT(3));
static void update_vbus_supplier(int port, int vbus_level)
{
- struct charge_port_info charge = {0};
+ struct charge_port_info charge = { 0 };
if (vbus_level && !usb_charger_port_is_sourcing_vbus(port)) {
charge.voltage = USB_CHARGER_VOLTAGE_MV;
@@ -104,7 +105,7 @@ void usb_charger_vbus_change(int port, int vbus_level)
#endif
if ((get_usb_pd_vbus_detect() == USB_PD_VBUS_DETECT_CHARGER) ||
- (get_usb_pd_vbus_detect() == USB_PD_VBUS_DETECT_PPC)) {
+ (get_usb_pd_vbus_detect() == USB_PD_VBUS_DETECT_PPC)) {
/* USB PD task */
task_wake(PD_PORT_TO_TASK_ID(port));
}
@@ -112,29 +113,14 @@ void usb_charger_vbus_change(int port, int vbus_level)
void usb_charger_reset_charge(int port)
{
- charge_manager_update_charge(CHARGE_SUPPLIER_PROPRIETARY,
- port, NULL);
- charge_manager_update_charge(CHARGE_SUPPLIER_BC12_CDP,
- port, NULL);
- charge_manager_update_charge(CHARGE_SUPPLIER_BC12_DCP,
- port, NULL);
- charge_manager_update_charge(CHARGE_SUPPLIER_BC12_SDP,
- port, NULL);
- charge_manager_update_charge(CHARGE_SUPPLIER_OTHER,
- port, NULL);
+ charge_manager_update_charge(CHARGE_SUPPLIER_PROPRIETARY, port, NULL);
+ charge_manager_update_charge(CHARGE_SUPPLIER_BC12_CDP, port, NULL);
+ charge_manager_update_charge(CHARGE_SUPPLIER_BC12_DCP, port, NULL);
+ charge_manager_update_charge(CHARGE_SUPPLIER_BC12_SDP, port, NULL);
+ charge_manager_update_charge(CHARGE_SUPPLIER_OTHER, port, NULL);
#if CONFIG_DEDICATED_CHARGE_PORT_COUNT > 0
- charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED,
- port, NULL);
+ charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED, port, NULL);
#endif
-#ifdef CONFIG_WIRELESS_CHARGER_P9221_R7
- charge_manager_update_charge(CHARGE_SUPPLIER_WPC_BPP,
- port, NULL);
- charge_manager_update_charge(CHARGE_SUPPLIER_WPC_EPP,
- port, NULL);
- charge_manager_update_charge(CHARGE_SUPPLIER_WPC_GPP,
- port, NULL);
-#endif
-
}
void usb_charger_task_set_event(int port, uint8_t event)
@@ -185,8 +171,7 @@ void usb_charger_task_shared(void *u)
}
port_evt = PORT_EVENT_UNPACK(
- port,
- atomic_get(&usb_charger_port_events));
+ port, atomic_get(&usb_charger_port_events));
atomic_and(&usb_charger_port_events,
~PORT_EVENT_PACK(port, port_evt));
diff --git a/common/usb_common.c b/common/usb_common.c
index 12316f5ca3..805bc5d551 100644
--- a/common/usb_common.c
+++ b/common/usb_common.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -36,8 +36,8 @@
#include "util.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
#else
#define CPRINTS(format, args...)
#define CPRINTF(format, args...)
@@ -78,7 +78,7 @@ int hex8tou32(char *str, uint32_t *val)
int remote_flashing(int argc, char **argv)
{
int port, cnt, cmd;
- uint32_t data[VDO_MAX_SIZE-1];
+ uint32_t data[VDO_MAX_SIZE - 1];
char *e;
static int flash_offset[CONFIG_USB_PD_PORT_MAX_COUNT];
@@ -111,12 +111,11 @@ int remote_flashing(int argc, char **argv)
argc -= 3;
for (i = 0; i < argc; i++)
- if (hex8tou32(argv[i+3], data + i))
+ if (hex8tou32(argv[i + 3], data + i))
return EC_ERROR_INVAL;
cmd = VDO_CMD_FLASH_WRITE;
cnt = argc;
- ccprintf("WRITE %d @%04x ...", argc * 4,
- flash_offset[port]);
+ ccprintf("WRITE %d @%04x ...", argc * 4, flash_offset[port]);
flash_offset[port] += argc * 4;
}
@@ -124,7 +123,7 @@ int remote_flashing(int argc, char **argv)
/* Wait until VDM is done */
while (pd[port].vdm_state > 0)
- task_wait_event(100*MSEC);
+ task_wait_event(100 * MSEC);
ccprintf("DONE %d\n", pd[port].vdm_state);
return EC_SUCCESS;
@@ -151,11 +150,10 @@ bool pd_firmware_upgrade_check_power_readiness(int port)
*/
battery_get_params(&batt);
if (batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE ||
- batt.state_of_charge <
- MIN_BATTERY_FOR_PD_UPGRADE_PERCENT) {
+ batt.state_of_charge < MIN_BATTERY_FOR_PD_UPGRADE_PERCENT) {
CPRINTS("C%d: Cannot suspend for upgrade, not "
- "enough battery (%d%%)!",
- port, batt.state_of_charge);
+ "enough battery (%d%%)!",
+ port, batt.state_of_charge);
return false;
}
} else {
@@ -181,8 +179,8 @@ int usb_get_battery_soc(void)
#endif
}
-#if defined(CONFIG_USB_PD_PREFER_MV) && defined(PD_PREFER_LOW_VOLTAGE) + \
- defined(PD_PREFER_HIGH_VOLTAGE) > 1
+#if defined(CONFIG_USB_PD_PREFER_MV) && \
+ defined(PD_PREFER_LOW_VOLTAGE) + defined(PD_PREFER_HIGH_VOLTAGE) > 1
#error "PD preferred voltage strategy should be mutually exclusive."
#endif
@@ -200,7 +198,8 @@ int usb_get_battery_soc(void)
*/
typec_current_t usb_get_typec_current_limit(enum tcpc_cc_polarity polarity,
- enum tcpc_cc_voltage_status cc1, enum tcpc_cc_voltage_status cc2)
+ enum tcpc_cc_voltage_status cc1,
+ enum tcpc_cc_voltage_status cc2)
{
typec_current_t charge = 0;
enum tcpc_cc_voltage_status cc;
@@ -236,7 +235,7 @@ typec_current_t usb_get_typec_current_limit(enum tcpc_cc_polarity polarity,
}
enum tcpc_cc_polarity get_snk_polarity(enum tcpc_cc_voltage_status cc1,
- enum tcpc_cc_voltage_status cc2)
+ enum tcpc_cc_voltage_status cc2)
{
/* The following assumes:
*
@@ -251,13 +250,13 @@ enum tcpc_cc_polarity get_snk_polarity(enum tcpc_cc_voltage_status cc1,
}
enum tcpc_cc_polarity get_src_polarity(enum tcpc_cc_voltage_status cc1,
- enum tcpc_cc_voltage_status cc2)
+ enum tcpc_cc_voltage_status cc2)
{
return (cc1 == TYPEC_CC_VOLT_RD) ? POLARITY_CC1 : POLARITY_CC2;
}
-enum pd_cc_states pd_get_cc_state(
- enum tcpc_cc_voltage_status cc1, enum tcpc_cc_voltage_status cc2)
+enum pd_cc_states pd_get_cc_state(enum tcpc_cc_voltage_status cc1,
+ enum tcpc_cc_voltage_status cc2)
{
/* Port partner is a SNK */
if (cc_is_snk_dbg_acc(cc1, cc2))
@@ -289,7 +288,7 @@ bool pd_is_debug_acc(int port)
enum pd_cc_states cc_state = pd_get_task_cc_state(port);
return cc_state == PD_CC_UFP_DEBUG_ACC ||
- cc_state == PD_CC_DFP_DEBUG_ACC;
+ cc_state == PD_CC_DFP_DEBUG_ACC;
}
__overridable int pd_board_check_request(uint32_t rdo, int pdo_cnt)
@@ -303,7 +302,7 @@ int pd_get_source_pdo(const uint32_t **src_pdo_p, const int port)
const uint32_t *src_pdo;
const int pdo_cnt = dpm_get_source_pdo(&src_pdo, port);
#elif defined(CONFIG_USB_PD_DYNAMIC_SRC_CAP) || \
- defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
+ defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
const uint32_t *src_pdo;
const int pdo_cnt = charge_manager_get_source_pdo(&src_pdo, port);
#else
@@ -346,8 +345,8 @@ int pd_check_requested_voltage(uint32_t rdo, const int port)
return EC_ERROR_INVAL; /* too much max current */
CPRINTF("Requested %d mV %d mA (for %d/%d mA)\n",
- ((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
- op_ma * 10, max_ma * 10);
+ ((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10, op_ma * 10,
+ max_ma * 10);
/* Accept the requested voltage */
return EC_SUCCESS;
@@ -382,16 +381,12 @@ int pd_get_retry_count(int port, enum tcpci_msg_type type)
}
enum pd_drp_next_states drp_auto_toggle_next_state(
- uint64_t *drp_sink_time,
- enum pd_power_role power_role,
- enum pd_dual_role_states drp_state,
- enum tcpc_cc_voltage_status cc1,
- enum tcpc_cc_voltage_status cc2,
- bool auto_toggle_supported)
+ uint64_t *drp_sink_time, enum pd_power_role power_role,
+ enum pd_dual_role_states drp_state, enum tcpc_cc_voltage_status cc1,
+ enum tcpc_cc_voltage_status cc2, bool auto_toggle_supported)
{
const bool hardware_debounced_unattached =
- ((drp_state == PD_DRP_TOGGLE_ON) &&
- auto_toggle_supported);
+ ((drp_state == PD_DRP_TOGGLE_ON) && auto_toggle_supported);
/* Set to appropriate port state */
if (cc_is_open(cc1, cc2)) {
@@ -425,13 +420,13 @@ enum pd_drp_next_states drp_auto_toggle_next_state(
return DRP_TC_DRP_AUTO_TOGGLE;
}
} else if ((cc_is_rp(cc1) || cc_is_rp(cc2)) &&
- drp_state != PD_DRP_FORCE_SOURCE) {
+ drp_state != PD_DRP_FORCE_SOURCE) {
/* SNK allowed unless ForceSRC */
if (hardware_debounced_unattached)
return DRP_TC_ATTACHED_WAIT_SNK;
return DRP_TC_UNATTACHED_SNK;
} else if (cc_is_at_least_one_rd(cc1, cc2) ||
- cc_is_audio_acc(cc1, cc2)) {
+ cc_is_audio_acc(cc1, cc2)) {
/*
* SRC allowed unless ForceSNK or Toggle Off
*
@@ -447,10 +442,10 @@ enum pd_drp_next_states drp_auto_toggle_next_state(
* ready for a new connection.
*/
if (drp_state == PD_DRP_TOGGLE_OFF ||
- drp_state == PD_DRP_FORCE_SINK) {
- if (get_time().val > *drp_sink_time + 200*MSEC)
+ drp_state == PD_DRP_FORCE_SINK) {
+ if (get_time().val > *drp_sink_time + 200 * MSEC)
*drp_sink_time = get_time().val;
- if (get_time().val < *drp_sink_time + 100*MSEC)
+ if (get_time().val < *drp_sink_time + 100 * MSEC)
return DRP_TC_UNATTACHED_SNK;
else
return DRP_TC_DRP_AUTO_TOGGLE;
@@ -502,8 +497,8 @@ mux_state_t get_mux_mode_to_set(int port)
* conditions which are checked below. The default function returns
* false, so only boards that override this check will be affected.
*/
- if (usb_ufp_check_usb3_enable(port) && pd_get_data_role(port)
- == PD_ROLE_UFP)
+ if (usb_ufp_check_usb3_enable(port) &&
+ pd_get_data_role(port) == PD_ROLE_UFP)
return USB_PD_MUX_USB_ENABLED;
/* If new data role isn't DFP & we only support DFP, also disconnect. */
@@ -544,21 +539,19 @@ void set_usb_mux_with_current_data_role(int port)
if (IS_ENABLED(CONFIG_USBC_SS_MUX)) {
mux_state_t mux_mode = get_mux_mode_to_set(port);
enum usb_switch usb_switch_mode =
- (mux_mode == USB_PD_MUX_NONE) ?
- USB_SWITCH_DISCONNECT : USB_SWITCH_CONNECT;
+ (mux_mode == USB_PD_MUX_NONE) ? USB_SWITCH_DISCONNECT :
+ USB_SWITCH_CONNECT;
usb_mux_set(port, mux_mode, usb_switch_mode,
- polarity_rm_dts(pd_get_polarity(port)));
+ polarity_rm_dts(pd_get_polarity(port)));
}
}
void usb_mux_set_safe_mode(int port)
{
if (IS_ENABLED(CONFIG_USBC_SS_MUX)) {
- usb_mux_set(port, IS_ENABLED(CONFIG_USB_MUX_VIRTUAL) ?
- USB_PD_MUX_SAFE_MODE : USB_PD_MUX_NONE,
- USB_SWITCH_CONNECT,
- polarity_rm_dts(pd_get_polarity(port)));
+ usb_mux_set(port, USB_PD_MUX_SAFE_MODE, USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
}
/* Isolate the SBU lines. */
@@ -617,8 +610,7 @@ __overridable int pd_board_checks(void)
return EC_SUCCESS;
}
-__overridable int pd_check_data_swap(int port,
- enum pd_data_role data_role)
+__overridable int pd_check_data_swap(int port, enum pd_data_role data_role)
{
/* Allow data swap if we are a UFP, otherwise don't allow. */
return (data_role == PD_ROLE_UFP) ? 1 : 0;
@@ -639,8 +631,7 @@ __overridable int pd_check_power_swap(int port)
return 0;
}
-__overridable void pd_execute_data_swap(int port,
- enum pd_data_role data_role)
+__overridable void pd_execute_data_swap(int port, enum pd_data_role data_role)
{
}
@@ -699,7 +690,7 @@ __overridable int pd_custom_vdm(int port, int cnt, uint32_t *payload,
case VDO_CMD_VERSION:
/* guarantee last byte of payload is null character */
*(payload + cnt - 1) = 0;
- CPRINTF("version: %s\n", (char *)(payload+1));
+ CPRINTF("version: %s\n", (char *)(payload + 1));
break;
case VDO_CMD_READ_INFO:
case VDO_CMD_SEND_INFO:
@@ -720,10 +711,8 @@ __overridable int pd_custom_vdm(int port, int cnt, uint32_t *payload,
pd_send_host_event(PD_EVENT_UPDATE_DEVICE);
CPRINTF("DevId:%d.%d SW:%d RW:%d\n",
- HW_DEV_ID_MAJ(dev_id),
- HW_DEV_ID_MIN(dev_id),
- VDO_INFO_SW_DBG_VER(payload[6]),
- is_rw);
+ HW_DEV_ID_MAJ(dev_id), HW_DEV_ID_MIN(dev_id),
+ VDO_INFO_SW_DBG_VER(payload[6]), is_rw);
} else if (cnt == 6) {
/* really old devices don't have last byte */
pd_dev_store_rw_hash(port, dev_id, payload + 1,
@@ -757,9 +746,9 @@ __overridable bool vboot_allow_usb_pd(void)
static void pd_usb_billboard_deferred(void)
{
if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE) &&
- !IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP) &&
- !IS_ENABLED(CONFIG_USB_PD_SIMPLE_DFP) &&
- IS_ENABLED(CONFIG_USB_BOS)) {
+ !IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP) &&
+ !IS_ENABLED(CONFIG_USB_PD_SIMPLE_DFP) &&
+ IS_ENABLED(CONFIG_USB_BOS)) {
/*
* TODO(tbroch)
* 1. Will we have multiple type-C port UFPs
@@ -859,10 +848,9 @@ __overridable int pd_snk_is_vbus_provided(int port)
__overridable bool pd_check_vbus_level(int port, enum vbus_level level)
{
if (IS_ENABLED(CONFIG_USB_PD_VBUS_DETECT_TCPC) &&
- (get_usb_pd_vbus_detect() == USB_PD_VBUS_DETECT_TCPC)) {
+ (get_usb_pd_vbus_detect() == USB_PD_VBUS_DETECT_TCPC)) {
return tcpm_check_vbus_level(port, level);
- }
- else if (level == VBUS_PRESENT)
+ } else if (level == VBUS_PRESENT)
return pd_snk_is_vbus_provided(port);
else
return !pd_snk_is_vbus_provided(port);
@@ -899,7 +887,7 @@ int pd_set_frs_enable(int port, int enable)
* Dump TCPC registers.
*/
void tcpc_dump_registers(int port, const struct tcpc_reg_dump_map *reg,
- int count)
+ int count)
{
int i, val;
@@ -907,21 +895,20 @@ void tcpc_dump_registers(int port, const struct tcpc_reg_dump_map *reg,
switch (reg->size) {
case 1:
tcpc_read(port, reg->addr, &val);
- ccprintf(" %-30s(0x%02x) = 0x%02x\n",
- reg->name, reg->addr, (uint8_t)val);
+ ccprintf(" %-30s(0x%02x) = 0x%02x\n", reg->name,
+ reg->addr, (uint8_t)val);
break;
case 2:
tcpc_read16(port, reg->addr, &val);
- ccprintf(" %-30s(0x%02x) = 0x%04x\n",
- reg->name, reg->addr, (uint16_t)val);
+ ccprintf(" %-30s(0x%02x) = 0x%04x\n", reg->name,
+ reg->addr, (uint16_t)val);
break;
}
cflush();
}
-
}
-static int command_tcpc_dump(int argc, char **argv)
+static int command_tcpc_dump(int argc, const char **argv)
{
int port;
@@ -995,7 +982,7 @@ void pd_srccaps_dump(int port)
if (range_flag)
ccprintf("-%dmV", min_mv);
ccprintf("/%dm%c", max_ma,
- pdo_mask == PDO_TYPE_BATTERY ? 'W' : 'A');
+ pdo_mask == PDO_TYPE_BATTERY ? 'W' : 'A');
if (pdo & PDO_FIXED_DUAL_ROLE)
ccprintf(" DRP");
@@ -1034,6 +1021,23 @@ int pd_send_alert_msg(int port, uint32_t ado)
{
#if defined(CONFIG_USB_PD_TCPMV2) && defined(CONFIG_USB_PE_SM) && \
!defined(CONFIG_USB_VPD) && !defined(CONFIG_USB_CTVPD)
+ struct rmdo partner_rmdo;
+
+ /*
+ * The Alert Data Object (ADO) definition changed between USB PD
+ * Revision 3.0 and 3.1. Clear reserved bits from the USB PD 3.0
+ * ADO before sending to a USB PD 3.0 partner and block the
+ * message if the ADO is empty.
+ */
+ partner_rmdo = pe_get_partner_rmdo(port);
+ if (partner_rmdo.major_rev == 0) {
+ ado &= ~(ADO_EXTENDED_ALERT_EVENT |
+ ADO_EXTENDED_ALERT_EVENT_TYPE);
+ }
+
+ if (!ado)
+ return EC_ERROR_INVAL;
+
if (pe_set_ado(port, ado) != EC_SUCCESS)
return EC_ERROR_BUSY;
@@ -1057,6 +1061,15 @@ void pd_send_host_event(int mask)
}
#endif /* defined(HAS_TASK_HOSTCMD) && !defined(TEST_BUILD) */
+#ifdef CONFIG_MKBP_EVENT
+static int dp_alt_mode_entry_get_next_event(uint8_t *data)
+{
+ return EC_SUCCESS;
+}
+DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_DP_ALT_MODE_ENTERED,
+ dp_alt_mode_entry_get_next_event);
+#endif /* CONFIG_MKBP_EVENT */
+
__overridable void pd_notify_dp_alt_mode_entry(int port)
{
if (IS_ENABLED(CONFIG_MKBP_EVENT)) {
diff --git a/common/usb_console_stream.c b/common/usb_console_stream.c
index 13dd7f8264..629e7ba1f8 100644
--- a/common/usb_console_stream.c
+++ b/common/usb_console_stream.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -25,13 +25,12 @@
/* Console output macro */
#define USB_CONSOLE_TIMEOUT_US (30 * MSEC)
-#define QUEUE_SIZE_USB_TX CONFIG_USB_CONSOLE_TX_BUF_SIZE
-#define QUEUE_SIZE_USB_RX USB_MAX_PACKET_SIZE
+#define QUEUE_SIZE_USB_TX CONFIG_USB_CONSOLE_TX_BUF_SIZE
+#define QUEUE_SIZE_USB_RX USB_MAX_PACKET_SIZE
static void usb_console_wr(struct queue_policy const *policy, size_t count);
static void uart_console_rd(struct queue_policy const *policy, size_t count);
-
static int last_tx_ok = 1;
/*
@@ -52,24 +51,19 @@ static int is_readonly = 1;
* usb-stream.c.
*/
static struct queue_policy const usb_console_policy = {
- .add = usb_console_wr,
+ .add = usb_console_wr,
.remove = uart_console_rd,
};
static struct queue const tx_q = QUEUE_NULL(QUEUE_SIZE_USB_TX, uint8_t);
-static struct queue const rx_q = QUEUE(QUEUE_SIZE_USB_RX, uint8_t,
- usb_console_policy);
+static struct queue const rx_q =
+ QUEUE(QUEUE_SIZE_USB_RX, uint8_t, usb_console_policy);
struct usb_stream_config const usb_console;
-USB_STREAM_CONFIG(usb_console,
- USB_IFACE_CONSOLE,
- USB_STR_CONSOLE_NAME,
- USB_EP_CONSOLE,
- USB_MAX_PACKET_SIZE,
- USB_MAX_PACKET_SIZE,
- rx_q,
- tx_q)
+USB_STREAM_CONFIG(usb_console, USB_IFACE_CONSOLE, USB_STR_CONSOLE_NAME,
+ USB_EP_CONSOLE, USB_MAX_PACKET_SIZE, USB_MAX_PACKET_SIZE,
+ rx_q, tx_q)
static void usb_console_wr(struct queue_policy const *policy, size_t count)
{
@@ -185,7 +179,7 @@ int usb_puts(const char *outstr)
if (!is_enabled)
return EC_SUCCESS;
- ret = usb_wait_console();
+ ret = usb_wait_console();
if (ret)
return ret;
diff --git a/common/usb_host_command.c b/common/usb_host_command.c
index ccae57dd43..83a6e24a7d 100644
--- a/common/usb_host_command.c
+++ b/common/usb_host_command.c
@@ -1,4 +1,4 @@
-/* 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.
*/
@@ -9,6 +9,7 @@
#include "ec_commands.h"
#include "queue_policies.h"
#include "host_command.h"
+#include "printf.h"
#include "system.h"
#include "usb_api.h"
#include "usb_hw.h"
@@ -16,13 +17,11 @@
#include "util.h"
#define CPUTS(outstr) cputs(CC_USB, outstr)
-#define CPRINTS(format, args...) cprints(CC_HOSTCMD, "USBHC: " format, ## args)
+#define CPRINTS(format, args...) cprints(CC_HOSTCMD, "USBHC: " format, ##args)
enum usbhc_state {
- /* Not enabled (initial state, and when chipset is off) */
- USBHC_STATE_DISABLED = 0,
- /* Ready to receive next request */
- USBHC_STATE_READY_TO_RX,
+ /* Initial State - Ready to receive next request */
+ USBHC_STATE_READY_TO_RX = 0,
/* Receiving request */
USBHC_STATE_RECEIVING,
/* Processing request */
@@ -38,26 +37,16 @@ struct producer const hostcmd_producer;
struct usb_stream_config const usbhc_stream;
/* RX (Host->EC) queue */
-static struct queue const usb_to_hostcmd = QUEUE_DIRECT(64,
- uint8_t,
- usbhc_stream.producer,
- hostcmd_consumer);
+static struct queue const usb_to_hostcmd =
+ QUEUE_DIRECT(64, uint8_t, usbhc_stream.producer, hostcmd_consumer);
/* TX (EC->Host) queue */
-static struct queue const hostcmd_to_usb = QUEUE_DIRECT(64,
- uint8_t,
- hostcmd_producer,
- usbhc_stream.consumer);
-
-USB_STREAM_CONFIG_FULL(usbhc_stream,
- USB_IFACE_HOSTCMD,
- USB_CLASS_VENDOR_SPEC,
- USB_SUBCLASS_GOOGLE_HOSTCMD,
- USB_PROTOCOL_GOOGLE_HOSTCMD,
- USB_STR_HOSTCMD_NAME,
- USB_EP_HOSTCMD,
- USB_MAX_PACKET_SIZE,
- USB_MAX_PACKET_SIZE,
- usb_to_hostcmd,
+static struct queue const hostcmd_to_usb =
+ QUEUE_DIRECT(64, uint8_t, hostcmd_producer, usbhc_stream.consumer);
+
+USB_STREAM_CONFIG_FULL(usbhc_stream, USB_IFACE_HOSTCMD, USB_CLASS_VENDOR_SPEC,
+ USB_SUBCLASS_GOOGLE_HOSTCMD, USB_PROTOCOL_GOOGLE_HOSTCMD,
+ USB_STR_HOSTCMD_NAME, USB_EP_HOSTCMD,
+ USB_MAX_PACKET_SIZE, USB_MAX_PACKET_SIZE, usb_to_hostcmd,
hostcmd_to_usb)
static uint8_t in_msg[USBHC_MAX_REQUEST_SIZE];
@@ -94,7 +83,7 @@ static void usbhc_read(struct producer const *producer, size_t count)
struct producer const hostcmd_producer = {
.queue = &hostcmd_to_usb,
- .ops = &((struct producer_ops const) {
+ .ops = &((struct producer_ops const){
.read = usbhc_read,
}),
};
@@ -171,8 +160,13 @@ static void usbhc_written(struct consumer const *consumer, size_t count)
block_index = 0;
/* Only version 3 is supported. Using in_msg as a courtesy. */
QUEUE_REMOVE_UNITS(consumer->queue, in_msg, count);
- if (IS_ENABLED(DEBUG))
- CPRINTS("%ph", HEX_BUF(in_msg, count));
+ if (IS_ENABLED(DEBUG)) {
+ char str_buf[hex_str_buf_size(count)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(in_msg, count));
+ CPRINTS("%s", str_buf);
+ }
if (in_msg[0] != EC_HOST_REQUEST_VERSION) {
CPRINTS("Unsupported version: %u", in_msg[0]);
return;
@@ -206,7 +200,6 @@ static void usbhc_written(struct consumer const *consumer, size_t count)
return;
case USBHC_STATE_PROCESSING:
case USBHC_STATE_SENDING:
- case USBHC_STATE_DISABLED:
/*
* Take no action and return though we may have resource to
* receive a new request. Host will get a buffer full error or
@@ -229,7 +222,7 @@ static void usbhc_written(struct consumer const *consumer, size_t count)
block_index += count;
if (block_index < expected_size)
- return; /* More to come. */
+ return; /* More to come. */
if (IS_ENABLED(DEBUG))
CPRINTS("Rx complete (%d bytes)", block_index);
@@ -247,13 +240,13 @@ static void usbhc_written(struct consumer const *consumer, size_t count)
struct consumer const hostcmd_consumer = {
.queue = &usb_to_hostcmd,
- .ops = &((struct consumer_ops const) {
+ .ops = &((struct consumer_ops const){
.written = usbhc_written,
}),
};
-static enum ec_status host_command_protocol_info(
- struct host_cmd_handler_args *args)
+static enum ec_status
+host_command_protocol_info(struct host_cmd_handler_args *args)
{
struct ec_response_get_protocol_info *r = args->response;
@@ -267,6 +260,5 @@ static enum ec_status host_command_protocol_info(
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO,
- host_command_protocol_info,
+DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, host_command_protocol_info,
EC_VER_MASK(0));
diff --git a/common/usb_i2c.c b/common/usb_i2c.c
index ace2e7139c..8482ec0967 100644
--- a/common/usb_i2c.c
+++ b/common/usb_i2c.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -20,27 +20,24 @@
#include "usb-stream.h"
#include "usb_i2c.h"
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ##args)
-#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
+USB_I2C_CONFIG(i2c, USB_IFACE_I2C, USB_STR_I2C_NAME, USB_EP_I2C)
-
-USB_I2C_CONFIG(i2c,
- USB_IFACE_I2C,
- USB_STR_I2C_NAME,
- USB_EP_I2C)
-
-static int (*cros_cmd_handler)(void *data_in,
- size_t in_size,
- void *data_out,
+static int (*cros_cmd_handler)(void *data_in, size_t in_size, void *data_out,
size_t out_size);
static int16_t usb_i2c_map_error(int error)
{
switch (error) {
- case EC_SUCCESS: return USB_I2C_SUCCESS;
- case EC_ERROR_TIMEOUT: return USB_I2C_TIMEOUT;
- case EC_ERROR_BUSY: return USB_I2C_BUSY;
- default: return USB_I2C_UNKNOWN_ERROR | (error & 0x7fff);
+ case EC_SUCCESS:
+ return USB_I2C_SUCCESS;
+ case EC_ERROR_TIMEOUT:
+ return USB_I2C_TIMEOUT;
+ case EC_ERROR_BUSY:
+ return USB_I2C_BUSY;
+ default:
+ return USB_I2C_UNKNOWN_ERROR | (error & 0x7fff);
}
}
@@ -52,7 +49,7 @@ static int16_t usb_i2c_map_error(int error)
static uint32_t usb_i2c_read_packet(struct usb_i2c_config const *config)
{
return QUEUE_REMOVE_UNITS(config->consumer.queue, config->buffer,
- queue_count(config->consumer.queue));
+ queue_count(config->consumer.queue));
}
static void usb_i2c_write_packet(struct usb_i2c_config const *config,
@@ -72,9 +69,8 @@ static uint8_t usb_i2c_executable(struct usb_i2c_config const *config)
* In order to support larger write payload, we need to peek
* the queue to see if we need to wait for more data.
*/
- if (queue_peek_units(config->consumer.queue,
- peek, 0, sizeof(peek))
- != sizeof(peek)) {
+ if (queue_peek_units(config->consumer.queue, peek, 0,
+ sizeof(peek)) != sizeof(peek)) {
/* Not enough data to calculate expected_size. */
return 0;
}
@@ -92,7 +88,6 @@ static uint8_t usb_i2c_executable(struct usb_i2c_config const *config)
expected_size += (((size_t)peek[0] & 0xf0) << 4) | peek[2];
}
-
if (queue_count(config->consumer.queue) >= expected_size) {
expected_size = 0;
return 1;
@@ -104,20 +99,20 @@ static uint8_t usb_i2c_executable(struct usb_i2c_config const *config)
static void usb_i2c_execute(struct usb_i2c_config const *config)
{
/* Payload is ready to execute. */
- uint32_t count = usb_i2c_read_packet(config);
- int portindex = (config->buffer[0] >> 0) & 0xf;
+ uint32_t count = usb_i2c_read_packet(config);
+ int portindex = (config->buffer[0] >> 0) & 0xf;
uint16_t addr_flags = (config->buffer[0] >> 8) & 0x7f;
- int write_count = ((config->buffer[0] << 4) & 0xf00) |
- ((config->buffer[1] >> 0) & 0xff);
- int read_count = (config->buffer[1] >> 8) & 0xff;
- int offset = 0; /* Offset for extended reading header. */
+ int write_count = ((config->buffer[0] << 4) & 0xf00) |
+ ((config->buffer[1] >> 0) & 0xff);
+ int read_count = (config->buffer[1] >> 8) & 0xff;
+ int offset = 0; /* Offset for extended reading header. */
config->buffer[0] = 0;
config->buffer[1] = 0;
if (read_count & 0x80) {
read_count = ((config->buffer[2] & 0xff) << 7) |
- (read_count & 0x7f);
+ (read_count & 0x7f);
offset = 2;
}
@@ -127,7 +122,7 @@ static void usb_i2c_execute(struct usb_i2c_config const *config)
if (!usb_i2c_board_is_enabled()) {
config->buffer[0] = USB_I2C_DISABLED;
} else if (write_count > CONFIG_USB_I2C_MAX_WRITE_COUNT ||
- write_count != (count - 4 - offset)) {
+ write_count != (count - 4 - offset)) {
config->buffer[0] = USB_I2C_WRITE_COUNT_INVALID;
} else if (read_count > CONFIG_USB_I2C_MAX_READ_COUNT) {
config->buffer[0] = USB_I2C_READ_COUNT_INVALID;
@@ -156,8 +151,7 @@ static void usb_i2c_execute(struct usb_i2c_config const *config)
*/
ret = i2c_xfer(i2c_ports[portindex].port, addr_flags,
(uint8_t *)(config->buffer + 2) + offset,
- write_count,
- (uint8_t *)(config->buffer + 2),
+ write_count, (uint8_t *)(config->buffer + 2),
read_count);
config->buffer[0] = usb_i2c_map_error(ret);
}
@@ -183,11 +177,8 @@ struct consumer_ops const usb_i2c_consumer_ops = {
.written = usb_i2c_written,
};
-int usb_i2c_register_cros_cmd_handler(int (*cmd_handler)
- (void *data_in,
- size_t in_size,
- void *data_out,
- size_t out_size))
+int usb_i2c_register_cros_cmd_handler(int (*cmd_handler)(
+ void *data_in, size_t in_size, void *data_out, size_t out_size))
{
if (cros_cmd_handler)
return -1;
diff --git a/common/usb_pd_alt_mode_dfp.c b/common/usb_pd_alt_mode_dfp.c
index 1de01f9c48..45a47ed9a5 100644
--- a/common/usb_pd_alt_mode_dfp.c
+++ b/common/usb_pd_alt_mode_dfp.c
@@ -1,10 +1,11 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Alternate Mode Downstream Facing Port (DFP) USB-PD module.
*/
+#include "builtin/assert.h"
#include "chipset.h"
#include "console.h"
#include "gpio.h"
@@ -23,8 +24,8 @@
#include "util.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
#else
#define CPRINTS(format, args...)
#define CPRINTF(format, args...)
@@ -51,8 +52,8 @@ uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
/* Console command multi-function preference set for a PD port. */
__maybe_unused bool dp_port_mf_allow[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- [0 ... CONFIG_USB_PD_PORT_MAX_COUNT - 1] = true};
-
+ [0 ... CONFIG_USB_PD_PORT_MAX_COUNT - 1] = true
+};
__overridable const struct svdm_response svdm_rsp = {
.identity = NULL,
@@ -60,8 +61,7 @@ __overridable const struct svdm_response svdm_rsp = {
.modes = NULL,
};
-static int pd_get_mode_idx(int port, enum tcpci_msg_type type,
- uint16_t svid)
+static int pd_get_mode_idx(int port, enum tcpci_msg_type type, uint16_t svid)
{
int amode_idx;
struct partner_active_modes *active =
@@ -75,8 +75,7 @@ static int pd_get_mode_idx(int port, enum tcpci_msg_type type,
return -1;
}
-static int pd_allocate_mode(int port, enum tcpci_msg_type type,
- uint16_t svid)
+static int pd_allocate_mode(int port, enum tcpci_msg_type type, uint16_t svid)
{
int i, j;
struct svdm_amode_data *modep;
@@ -122,21 +121,20 @@ static int pd_allocate_mode(int port, enum tcpci_msg_type type,
return -1;
}
-static int validate_mode_request(struct svdm_amode_data *modep,
- uint16_t svid, int opos)
+static int validate_mode_request(struct svdm_amode_data *modep, uint16_t svid,
+ int opos)
{
if (!modep->fx)
return 0;
if (svid != modep->fx->svid) {
- CPRINTF("ERR:svid r:0x%04x != c:0x%04x\n",
- svid, modep->fx->svid);
+ CPRINTF("ERR:svid r:0x%04x != c:0x%04x\n", svid,
+ modep->fx->svid);
return 0;
}
if (opos != modep->opos) {
- CPRINTF("ERR:opos r:%d != c:%d\n",
- opos, modep->opos);
+ CPRINTF("ERR:opos r:%d != c:%d\n", opos, modep->opos);
return 0;
}
@@ -199,7 +197,7 @@ int pd_dfp_dp_get_pin_mode(int port, uint32_t status)
if (IS_ENABLED(CONFIG_CMD_MFALLOW))
mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]) &&
- dp_port_mf_allow[port];
+ dp_port_mf_allow[port];
else
mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]);
@@ -229,8 +227,8 @@ int pd_dfp_dp_get_pin_mode(int port, uint32_t status)
return 1 << get_next_bit(&pin_caps);
}
-struct svdm_amode_data *pd_get_amode_data(int port,
- enum tcpci_msg_type type, uint16_t svid)
+struct svdm_amode_data *pd_get_amode_data(int port, enum tcpci_msg_type type,
+ uint16_t svid)
{
int idx = pd_get_mode_idx(port, type, svid);
struct partner_active_modes *active =
@@ -244,8 +242,8 @@ struct svdm_amode_data *pd_get_amode_data(int port,
* Enter default mode ( payload[0] == 0 ) or attempt to enter mode via svid &
* opos
*/
-uint32_t pd_dfp_enter_mode(int port, enum tcpci_msg_type type,
- uint16_t svid, int opos)
+uint32_t pd_dfp_enter_mode(int port, enum tcpci_msg_type type, uint16_t svid,
+ int opos)
{
int mode_idx = pd_allocate_mode(port, type, svid);
struct svdm_amode_data *modep;
@@ -285,7 +283,7 @@ uint32_t pd_dfp_enter_mode(int port, enum tcpci_msg_type type,
/* TODO(b/170372521) : Incorporate exit mode specific changes to DPM SM */
int pd_dfp_exit_mode(int port, enum tcpci_msg_type type, uint16_t svid,
- int opos)
+ int opos)
{
struct svdm_amode_data *modep;
struct partner_active_modes *active =
@@ -358,7 +356,7 @@ void dfp_consume_attention(int port, uint32_t *payload)
}
void dfp_consume_identity(int port, enum tcpci_msg_type type, int cnt,
- uint32_t *payload)
+ uint32_t *payload)
{
int ptype;
struct pd_discovery *disc;
@@ -372,8 +370,8 @@ void dfp_consume_identity(int port, enum tcpci_msg_type type, int cnt,
ptype = PD_IDH_PTYPE(payload[VDO_I(IDH)]);
disc = pd_get_am_discovery_and_notify_access(port, type);
- identity_size = MIN(sizeof(union disc_ident_ack),
- (cnt - 1) * sizeof(uint32_t));
+ identity_size =
+ MIN(sizeof(union disc_ident_ack), (cnt - 1) * sizeof(uint32_t));
/* Note: only store VDOs, not the VDM header */
memcpy(disc->identity.raw_value, payload + 1, identity_size);
@@ -383,14 +381,14 @@ void dfp_consume_identity(int port, enum tcpci_msg_type type, int cnt,
case IDH_PTYPE_AMA:
/* Leave vbus ON if the following macro is false */
if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) &&
- IS_ENABLED(CONFIG_USBC_VCONN_SWAP)) {
+ IS_ENABLED(CONFIG_USBC_VCONN_SWAP)) {
/* Adapter is requesting vconn, try to supply it */
if (PD_VDO_AMA_VCONN_REQ(payload[VDO_I(AMA)]))
pd_try_vconn_src(port);
/* Only disable vbus if vconn was requested */
if (PD_VDO_AMA_VCONN_REQ(payload[VDO_I(AMA)]) &&
- !PD_VDO_AMA_VBUS_REQ(payload[VDO_I(AMA)]))
+ !PD_VDO_AMA_VBUS_REQ(payload[VDO_I(AMA)]))
pd_power_supply_reset(port);
}
break;
@@ -401,14 +399,14 @@ void dfp_consume_identity(int port, enum tcpci_msg_type type, int cnt,
}
void dfp_consume_svids(int port, enum tcpci_msg_type type, int cnt,
- uint32_t *payload)
+ uint32_t *payload)
{
int i;
uint32_t *ptr = payload + 1;
int vdo = 1;
uint16_t svid0, svid1;
struct pd_discovery *disc =
- pd_get_am_discovery_and_notify_access(port, type);
+ pd_get_am_discovery_and_notify_access(port, type);
for (i = disc->svid_cnt; i < disc->svid_cnt + 12; i += 2) {
if (i >= SVID_DISCOVERY_MAX) {
@@ -447,13 +445,13 @@ void dfp_consume_svids(int port, enum tcpci_msg_type type, int cnt,
}
void dfp_consume_modes(int port, enum tcpci_msg_type type, int cnt,
- uint32_t *payload)
+ uint32_t *payload)
{
int svid_idx;
struct svid_mode_data *mode_discovery = NULL;
struct pd_discovery *disc =
- pd_get_am_discovery_and_notify_access(port, type);
- uint16_t response_svid = (uint16_t) PD_VDO_VID(payload[0]);
+ pd_get_am_discovery_and_notify_access(port, type);
+ uint16_t response_svid = (uint16_t)PD_VDO_VID(payload[0]);
for (svid_idx = 0; svid_idx < disc->svid_cnt; ++svid_idx) {
uint16_t svid = disc->svids[svid_idx].svid;
@@ -467,15 +465,15 @@ void dfp_consume_modes(int port, enum tcpci_msg_type type, int cnt,
const struct svid_mode_data *requested_mode_data =
pd_get_next_mode(port, type);
CPRINTF("C%d: Mode response for undiscovered SVID %x, but TCPM "
- "requested SVID %x\n",
- port, response_svid, requested_mode_data->svid);
+ "requested SVID %x\n",
+ port, response_svid, requested_mode_data->svid);
/*
* Although SVIDs discovery seemed like it succeeded before, the
* partner is now responding with undiscovered SVIDs. Discovery
* cannot reasonably continue under these circumstances.
*/
pd_set_modes_discovery(port, type, requested_mode_data->svid,
- PD_DISC_FAIL);
+ PD_DISC_FAIL);
return;
}
@@ -483,15 +481,15 @@ void dfp_consume_modes(int port, enum tcpci_msg_type type, int cnt,
if (mode_discovery->mode_cnt < 1) {
CPRINTF("ERR:NOMODE\n");
pd_set_modes_discovery(port, type, mode_discovery->svid,
- PD_DISC_FAIL);
+ PD_DISC_FAIL);
return;
}
memcpy(mode_discovery->mode_vdo, &payload[1],
- sizeof(uint32_t) * mode_discovery->mode_cnt);
+ sizeof(uint32_t) * mode_discovery->mode_cnt);
disc->svid_idx++;
pd_set_modes_discovery(port, type, mode_discovery->svid,
- PD_DISC_COMPLETE);
+ PD_DISC_COMPLETE);
}
int pd_alt_mode(int port, enum tcpci_msg_type type, uint16_t svid)
@@ -505,7 +503,7 @@ void pd_set_identity_discovery(int port, enum tcpci_msg_type type,
enum pd_discovery_state disc)
{
struct pd_discovery *pd =
- pd_get_am_discovery_and_notify_access(port, type);
+ pd_get_am_discovery_and_notify_access(port, type);
pd->identity_discovery = disc;
}
@@ -519,7 +517,7 @@ enum pd_discovery_state pd_get_identity_discovery(int port,
}
const union disc_ident_ack *pd_get_identity_response(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
if (type >= DISCOVERY_TYPE_COUNT)
return NULL;
@@ -529,39 +527,39 @@ const union disc_ident_ack *pd_get_identity_response(int port,
uint16_t pd_get_identity_vid(int port)
{
- const union disc_ident_ack *resp = pd_get_identity_response(port,
- TCPCI_MSG_SOP);
+ const union disc_ident_ack *resp =
+ pd_get_identity_response(port, TCPCI_MSG_SOP);
return resp->idh.usb_vendor_id;
}
uint16_t pd_get_identity_pid(int port)
{
- const union disc_ident_ack *resp = pd_get_identity_response(port,
- TCPCI_MSG_SOP);
+ const union disc_ident_ack *resp =
+ pd_get_identity_response(port, TCPCI_MSG_SOP);
return resp->product.product_id;
}
uint8_t pd_get_product_type(int port)
{
- const union disc_ident_ack *resp = pd_get_identity_response(port,
- TCPCI_MSG_SOP);
+ const union disc_ident_ack *resp =
+ pd_get_identity_response(port, TCPCI_MSG_SOP);
return resp->idh.product_type;
}
void pd_set_svids_discovery(int port, enum tcpci_msg_type type,
- enum pd_discovery_state disc)
+ enum pd_discovery_state disc)
{
struct pd_discovery *pd =
- pd_get_am_discovery_and_notify_access(port, type);
+ pd_get_am_discovery_and_notify_access(port, type);
pd->svids_discovery = disc;
}
enum pd_discovery_state pd_get_svids_discovery(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
const struct pd_discovery *disc = pd_get_am_discovery(port, type);
@@ -582,11 +580,11 @@ uint16_t pd_get_svid(int port, uint16_t svid_idx, enum tcpci_msg_type type)
return disc->svids[svid_idx].svid;
}
-void pd_set_modes_discovery(int port, enum tcpci_msg_type type,
- uint16_t svid, enum pd_discovery_state disc)
+void pd_set_modes_discovery(int port, enum tcpci_msg_type type, uint16_t svid,
+ enum pd_discovery_state disc)
{
struct pd_discovery *pd =
- pd_get_am_discovery_and_notify_access(port, type);
+ pd_get_am_discovery_and_notify_access(port, type);
int svid_idx;
for (svid_idx = 0; svid_idx < pd->svid_cnt; ++svid_idx) {
@@ -601,7 +599,7 @@ void pd_set_modes_discovery(int port, enum tcpci_msg_type type,
}
enum pd_discovery_state pd_get_modes_discovery(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
const struct svid_mode_data *mode_data = pd_get_next_mode(port, type);
@@ -615,8 +613,8 @@ enum pd_discovery_state pd_get_modes_discovery(int port,
return mode_data->discovery;
}
-int pd_get_mode_vdo_for_svid(int port, enum tcpci_msg_type type,
- uint16_t svid, uint32_t *vdo_out)
+int pd_get_mode_vdo_for_svid(int port, enum tcpci_msg_type type, uint16_t svid,
+ uint32_t *vdo_out)
{
int idx;
const struct pd_discovery *disc;
@@ -637,7 +635,7 @@ int pd_get_mode_vdo_for_svid(int port, enum tcpci_msg_type type,
}
const struct svid_mode_data *pd_get_next_mode(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
const struct pd_discovery *disc = pd_get_am_discovery(port, type);
const struct svid_mode_data *failed_mode_data = NULL;
@@ -672,7 +670,7 @@ const struct svid_mode_data *pd_get_next_mode(int port,
}
const uint32_t *pd_get_mode_vdo(int port, uint16_t svid_idx,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
const struct pd_discovery *disc = pd_get_am_discovery(port, type);
@@ -680,15 +678,15 @@ const uint32_t *pd_get_mode_vdo(int port, uint16_t svid_idx,
}
bool pd_is_mode_discovered_for_svid(int port, enum tcpci_msg_type type,
- uint16_t svid)
+ uint16_t svid)
{
const struct pd_discovery *disc = pd_get_am_discovery(port, type);
const struct svid_mode_data *mode_data;
for (mode_data = disc->svids; mode_data < disc->svids + disc->svid_cnt;
- ++mode_data) {
+ ++mode_data) {
if (mode_data->svid == svid &&
- mode_data->discovery == PD_DISC_COMPLETE)
+ mode_data->discovery == PD_DISC_COMPLETE)
return true;
}
@@ -726,69 +724,6 @@ bool is_vpd_ct_supported(int port)
return vpd.ct_support;
}
-uint8_t get_vpd_ct_gnd_impedance(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.gnd_impedance;
-}
-
-uint8_t get_vpd_ct_vbus_impedance(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.vbus_impedance;
-}
-
-uint8_t get_vpd_ct_current_support(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.ct_current_support;
-}
-
-uint8_t get_vpd_ct_max_vbus_voltage(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.max_vbus_voltage;
-}
-
-uint8_t get_vpd_ct_vdo_version(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.vdo_version;
-}
-
-uint8_t get_vpd_ct_firmware_verion(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.firmware_version;
-}
-
-uint8_t get_vpd_ct_hw_version(int port)
-{
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union vpd_vdo vpd = disc->identity.product_t1.vpd;
-
- return vpd.hw_version;
-}
-
/*
* ############################################################################
*
@@ -812,7 +747,7 @@ bool is_usb2_cable_support(int port)
return disc->identity.idh.product_type == IDH_PTYPE_PCABLE ||
pd_get_vdo_ver(port, TCPCI_MSG_SOP_PRIME) < VDM_VER20 ||
disc->identity.product_t2.a2_rev30.usb_20_support ==
- USB2_SUPPORTED;
+ USB2_SUPPORTED;
}
bool is_cable_speed_gen2_capable(int port)
@@ -823,13 +758,13 @@ bool is_cable_speed_gen2_capable(int port)
switch (pd_get_rev(port, TCPCI_MSG_SOP_PRIME)) {
case PD_REV20:
return disc->identity.product_t1.p_rev20.ss ==
- USB_R20_SS_U31_GEN1_GEN2;
+ USB_R20_SS_U31_GEN1_GEN2;
case PD_REV30:
return disc->identity.product_t1.p_rev30.ss ==
- USB_R30_SS_U32_U40_GEN2 ||
+ USB_R30_SS_U32_U40_GEN2 ||
disc->identity.product_t1.p_rev30.ss ==
- USB_R30_SS_U40_GEN3;
+ USB_R30_SS_U40_GEN3;
default:
return false;
}
@@ -844,310 +779,8 @@ bool is_active_cable_element_retimer(int port)
* Revision 2 Active cables do not have Active element support.
*/
return is_pd_rev3(port, TCPCI_MSG_SOP_PRIME) &&
- disc->identity.idh.product_type == IDH_PTYPE_ACABLE &&
- disc->identity.product_t2.a2_rev30.active_elem ==
- ACTIVE_RETIMER;
-}
-
-/*
- * ############################################################################
- *
- * Thunderbolt-Compatible functions
- *
- * ############################################################################
- */
-
-uint32_t pd_get_tbt_mode_vdo(int port, enum tcpci_msg_type type)
-{
- uint32_t tbt_mode_vdo[PDO_MODES];
-
- return pd_get_mode_vdo_for_svid(port, type, USB_VID_INTEL,
- tbt_mode_vdo) ? tbt_mode_vdo[0] : 0;
-}
-
-/* TODO (b/148528713): Need to enable Thunderbolt-compatible mode on TCPMv2 */
-void set_tbt_compat_mode_ready(int port)
-{
- if (IS_ENABLED(CONFIG_USBC_SS_MUX) &&
- IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)) {
- /* Connect the SBU and USB lines to the connector. */
- typec_set_sbu(port, true);
-
- /* Set usb mux to Thunderbolt-compatible mode */
- usb_mux_set(port, USB_PD_MUX_TBT_COMPAT_ENABLED,
- USB_SWITCH_CONNECT,
- polarity_rm_dts(pd_get_polarity(port)));
- }
-}
-
-/*
- * Ref: USB Type-C Cable and Connector Specification
- * Figure F-1 TBT3 Discovery Flow
- */
-static bool is_tbt_cable_superspeed(int port)
-{
- const struct pd_discovery *disc;
-
- if (!IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) ||
- !IS_ENABLED(CONFIG_USB_PD_DECODE_SOP))
- return false;
-
- disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
-
- /* Product type is Active cable, hence don't check for speed */
- if (disc->identity.idh.product_type == IDH_PTYPE_ACABLE)
- return true;
-
- if (disc->identity.idh.product_type != IDH_PTYPE_PCABLE)
- return false;
-
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- is_pd_rev3(port, TCPCI_MSG_SOP_PRIME))
- return disc->identity.product_t1.p_rev30.ss ==
- USB_R30_SS_U32_U40_GEN1 ||
- disc->identity.product_t1.p_rev30.ss ==
- USB_R30_SS_U32_U40_GEN2 ||
- disc->identity.product_t1.p_rev30.ss ==
- USB_R30_SS_U40_GEN3;
-
- return disc->identity.product_t1.p_rev20.ss ==
- USB_R20_SS_U31_GEN1 ||
- disc->identity.product_t1.p_rev20.ss ==
- USB_R20_SS_U31_GEN1_GEN2;
-}
-
-static enum tbt_compat_cable_speed usb_rev30_to_tbt_speed(enum usb_rev30_ss ss)
-{
- switch (ss) {
- case USB_R30_SS_U32_U40_GEN1:
- return TBT_SS_U31_GEN1;
- case USB_R30_SS_U32_U40_GEN2:
- return TBT_SS_U32_GEN1_GEN2;
- case USB_R30_SS_U40_GEN3:
- return TBT_SS_TBT_GEN3;
- default:
- return TBT_SS_U32_GEN1_GEN2;
- }
-}
-
-enum tbt_compat_cable_speed get_tbt_cable_speed(int port)
-{
- union tbt_mode_resp_cable cable_mode_resp;
- enum tbt_compat_cable_speed max_tbt_speed;
- enum tbt_compat_cable_speed cable_tbt_speed;
-
- if (!is_tbt_cable_superspeed(port))
- return TBT_SS_RES_0;
-
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
- max_tbt_speed = board_get_max_tbt_speed(port);
-
- /*
- * Ref: TBT4 PD Discovery Flow Application Notes Revision 0.9, Figure 2
- * For passive cable, if cable doesn't support USB_VID_INTEL, enter
- * Thunderbolt alternate mode with speed from USB Highest Speed field of
- * the Passive Cable VDO
- * For active cable, if the cable doesn't support USB_VID_INTEL, do not
- * enter Thunderbolt alternate mode.
- */
- if (!cable_mode_resp.raw_value) {
- const struct pd_discovery *disc;
-
- if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE)
- return TBT_SS_RES_0;
-
- disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- cable_tbt_speed =
- usb_rev30_to_tbt_speed(disc->identity.product_t1.p_rev30.ss);
- } else {
- cable_tbt_speed = cable_mode_resp.tbt_cable_speed;
- }
-
- return max_tbt_speed < cable_tbt_speed ?
- max_tbt_speed : cable_tbt_speed;
-}
-
-/* Note: Assumes that pins have already been set in safe state */
-int enter_tbt_compat_mode(int port, enum tcpci_msg_type sop,
- uint32_t *payload)
-{
- union tbt_dev_mode_enter_cmd enter_dev_mode = { .raw_value = 0 };
- union tbt_mode_resp_device dev_mode_resp;
- union tbt_mode_resp_cable cable_mode_resp;
- enum tcpci_msg_type enter_mode_sop =
- sop == TCPCI_MSG_SOP_PRIME_PRIME ?
- TCPCI_MSG_SOP_PRIME : sop;
-
- /* Table F-12 TBT3 Cable Enter Mode Command */
- /*
- * The port doesn't query Discover SOP'' to the cable so, the port
- * doesn't have opos for SOP''. Hence, send Enter Mode SOP'' with same
- * opos and revision as SOP'.
- */
- payload[0] = pd_dfp_enter_mode(port, enter_mode_sop, USB_VID_INTEL, 0) |
- VDO_CMDT(CMDT_INIT) |
- VDO_SVDM_VERS(pd_get_vdo_ver(port, enter_mode_sop));
-
- /* For TBT3 Cable Enter Mode Command, number of Objects is 1 */
- if ((sop == TCPCI_MSG_SOP_PRIME) ||
- (sop == TCPCI_MSG_SOP_PRIME_PRIME))
- return 1;
-
- dev_mode_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP);
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
- /* Table F-13 TBT3 Device Enter Mode Command */
- enter_dev_mode.vendor_spec_b1 = dev_mode_resp.vendor_spec_b1;
- enter_dev_mode.vendor_spec_b0 = dev_mode_resp.vendor_spec_b0;
- enter_dev_mode.intel_spec_b0 = dev_mode_resp.intel_spec_b0;
-
- if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE ||
- cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE)
- enter_dev_mode.cable = TBT_ENTER_ACTIVE_CABLE;
-
- enter_dev_mode.lsrx_comm = cable_mode_resp.lsrx_comm;
- enter_dev_mode.retimer_type = cable_mode_resp.retimer_type;
- enter_dev_mode.tbt_cable = cable_mode_resp.tbt_cable;
- enter_dev_mode.tbt_rounded = cable_mode_resp.tbt_rounded;
- enter_dev_mode.tbt_cable_speed = get_tbt_cable_speed(port);
- enter_dev_mode.tbt_alt_mode = TBT_ALTERNATE_MODE;
-
- payload[1] = enter_dev_mode.raw_value;
-
- /* For TBT3 Device Enter Mode Command, number of Objects are 2 */
- return 2;
-}
-
-enum tbt_compat_rounded_support get_tbt_rounded_support(int port)
-{
- union tbt_mode_resp_cable cable_mode_resp = {
- .raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME) };
-
- /* tbt_rounded_support is zero when uninitialized */
- return cable_mode_resp.tbt_rounded;
-}
-
-__overridable enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
-{
- return TBT_SS_TBT_GEN3;
-}
-/*
- * ############################################################################
- *
- * USB4 functions
- *
- * ############################################################################
- */
-
-/*
- * For Cable rev 3.0: USB4 cable speed is set according to speed supported by
- * the port and the response received from the cable, whichever is least.
- *
- * For Cable rev 2.0: If get_tbt_cable_speed() is less than
- * TBT_SS_U31_GEN1, return USB_R30_SS_U2_ONLY speed since the board
- * doesn't support superspeed else the USB4 cable speed is set according to
- * the cable response.
- */
-enum usb_rev30_ss get_usb4_cable_speed(int port)
-{
- enum tbt_compat_cable_speed tbt_speed = get_tbt_cable_speed(port);
- enum usb_rev30_ss max_usb4_speed;
-
-
- if (tbt_speed < TBT_SS_U31_GEN1)
- return USB_R30_SS_U2_ONLY;
-
- /*
- * Converting Thunderbolt-Compatible board speed to equivalent USB4
- * speed.
- */
- max_usb4_speed = tbt_speed == TBT_SS_TBT_GEN3 ?
- USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2;
-
- if ((get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE) &&
- is_pd_rev3(port, TCPCI_MSG_SOP_PRIME)) {
- const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- union active_cable_vdo1_rev30 a_rev30 =
- disc->identity.product_t1.a_rev30;
-
- if (a_rev30.vdo_ver >= VDO_VERSION_1_3) {
- return max_usb4_speed < a_rev30.ss ?
- max_usb4_speed : a_rev30.ss;
- }
- }
-
- return max_usb4_speed;
-}
-
-uint32_t get_enter_usb_msg_payload(int port)
-{
- /*
- * Ref: USB Power Delivery Specification Revision 3.0, Version 2.0
- * Table 6-47 Enter_USB Data Object
- */
- union enter_usb_data_obj eudo;
- const struct pd_discovery *disc;
- union tbt_mode_resp_cable cable_mode_resp;
-
- if (!IS_ENABLED(CONFIG_USB_PD_USB4))
- return 0;
-
- disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
- eudo.mode = USB_PD_40;
- eudo.usb4_drd_cap = IS_ENABLED(CONFIG_USB_PD_USB4_DRD);
- eudo.usb3_drd_cap = IS_ENABLED(CONFIG_USB_PD_USB32_DRD);
- eudo.cable_speed = get_usb4_cable_speed(port);
-
- if (disc->identity.idh.product_type == IDH_PTYPE_ACABLE) {
- if (is_pd_rev3(port, TCPCI_MSG_SOP_PRIME)) {
- enum retimer_active_element active_element =
- disc->identity.product_t2.a2_rev30.active_elem;
- eudo.cable_type = active_element == ACTIVE_RETIMER ?
- CABLE_TYPE_ACTIVE_RETIMER :
- CABLE_TYPE_ACTIVE_REDRIVER;
- } else {
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
- eudo.cable_type =
- cable_mode_resp.retimer_type == USB_RETIMER ?
- CABLE_TYPE_ACTIVE_RETIMER :
- CABLE_TYPE_ACTIVE_REDRIVER;
- }
- } else {
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
- eudo.cable_type =
- cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE ?
- CABLE_TYPE_ACTIVE_REDRIVER : CABLE_TYPE_PASSIVE;
- }
-
- switch (disc->identity.product_t1.p_rev20.vbus_cur) {
- case USB_VBUS_CUR_3A:
- eudo.cable_current = USB4_CABLE_CURRENT_3A;
- break;
- case USB_VBUS_CUR_5A:
- eudo.cable_current = USB4_CABLE_CURRENT_5A;
- break;
- default:
- eudo.cable_current = USB4_CABLE_CURRENT_INVALID;
- break;
- }
- eudo.pcie_supported = IS_ENABLED(CONFIG_USB_PD_PCIE_TUNNELING);
- eudo.dp_supported = IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP);
- eudo.tbt_supported = IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE);
- eudo.host_present = 1;
-
- return eudo.raw_value;
-}
-
-__overridable bool board_is_tbt_usb4_port(int port)
-{
- return true;
+ disc->identity.idh.product_type == IDH_PTYPE_ACABLE &&
+ disc->identity.product_t2.a2_rev30.active_elem == ACTIVE_RETIMER;
}
__overridable void svdm_safe_dp_mode(int port)
@@ -1179,17 +812,17 @@ __overridable int svdm_enter_dp_mode(int port, uint32_t mode_caps)
return -1;
#endif
- /*
- * TCPMv2: Enable logging of CCD line state CCD_MODE_ODL.
- * DisplayPort Alternate mode requires that the SBU lines are used for
- * AUX communication.
- * However, in Chromebooks SBU signals are repurposed as USB2 signals
- * for CCD. This functionality is accomplished by override fets whose
- * state is controlled by CCD_MODE_ODL.
- *
- * This condition helps in debugging unexpected AUX timeout issues by
- * indicating the state of the CCD override fets.
- */
+ /*
+ * TCPMv2: Enable logging of CCD line state CCD_MODE_ODL.
+ * DisplayPort Alternate mode requires that the SBU lines are
+ * used for AUX communication. However, in Chromebooks SBU
+ * signals are repurposed as USB2 signals for CCD. This
+ * functionality is accomplished by override fets whose state is
+ * controlled by CCD_MODE_ODL.
+ *
+ * This condition helps in debugging unexpected AUX timeout
+ * issues by indicating the state of the CCD override fets.
+ */
#ifdef GPIO_CCD_MODE_ODL
if (!gpio_get_level(GPIO_CCD_MODE_ODL))
CPRINTS("WARNING: Tried to EnterMode DP with [CCD on AUX/SBU]");
@@ -1216,8 +849,8 @@ __overridable int svdm_dp_status(int port, uint32_t *payload)
{
int opos = pd_alt_mode(port, TCPCI_MSG_SOP, USB_SID_DISPLAYPORT);
- payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
- CMD_DP_STATUS | VDO_OPOS(opos));
+ payload[0] =
+ VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_STATUS | VDO_OPOS(opos));
payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
0, /* HPD level ... not applicable */
0, /* exit DP? ... no */
@@ -1242,7 +875,7 @@ mux_state_t svdm_dp_get_mux_mode(int port)
if (IS_ENABLED(CONFIG_CMD_MFALLOW))
mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]) &&
- dp_port_mf_allow[port];
+ dp_port_mf_allow[port];
else
mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]);
@@ -1267,7 +900,7 @@ __overridable int svdm_dp_config(int port, uint32_t *payload)
if (IS_ENABLED(CONFIG_CMD_MFALLOW))
mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]) &&
- dp_port_mf_allow[port];
+ dp_port_mf_allow[port];
else
mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]);
@@ -1276,11 +909,11 @@ __overridable int svdm_dp_config(int port, uint32_t *payload)
CPRINTS("pin_mode: %x, mf: %d, mux: %d", pin_mode, mf_pref, mux_mode);
- payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
- CMD_DP_CONFIG | VDO_OPOS(opos));
- payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */
- 1, /* DPv1.3 signaling */
- 2); /* UFP connected */
+ payload[0] =
+ VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_CONFIG | VDO_OPOS(opos));
+ payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */
+ 1, /* DPv1.3 signaling */
+ 2); /* UFP connected */
return 2;
};
@@ -1304,7 +937,7 @@ __overridable void svdm_dp_post_config(int port)
typec_set_sbu(port, true);
usb_mux_set(port, mux_mode, USB_SWITCH_CONNECT,
- polarity_rm_dts(pd_get_polarity(port)));
+ polarity_rm_dts(pd_get_polarity(port)));
dp_flags[port] |= DP_FLAGS_DP_ON;
if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING))
@@ -1317,8 +950,8 @@ __overridable void svdm_dp_post_config(int port)
svdm_hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL;
#endif /* CONFIG_USB_PD_DP_HPD_GPIO */
- usb_mux_hpd_update(port, USB_PD_MUX_HPD_LVL |
- USB_PD_MUX_HPD_IRQ_DEASSERTED);
+ usb_mux_hpd_update(port,
+ USB_PD_MUX_HPD_LVL | USB_PD_MUX_HPD_IRQ_DEASSERTED);
#ifdef USB_PD_PORT_TCPC_MST
if (port == USB_PD_PORT_TCPC_MST)
@@ -1337,8 +970,7 @@ __overridable int svdm_dp_attention(int port, uint32_t *payload)
dp_status[port] = payload[1];
- if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
- (irq || lvl))
+ if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) && (irq || lvl))
/*
* Wake up the AP. IRQ or level high indicates a DP sink is now
* present.
@@ -1402,7 +1034,7 @@ __overridable void svdm_exit_dp_mode(int port)
svdm_set_hpd_gpio(port, 0);
#endif /* CONFIG_USB_PD_DP_HPD_GPIO */
usb_mux_hpd_update(port, USB_PD_MUX_HPD_LVL_DEASSERTED |
- USB_PD_MUX_HPD_IRQ_DEASSERTED);
+ USB_PD_MUX_HPD_IRQ_DEASSERTED);
#ifdef USB_PD_PORT_TCPC_MST
if (port == USB_PD_PORT_TCPC_MST)
baseboard_mst_enable_control(port, 0);
@@ -1502,7 +1134,7 @@ const struct svdm_amode_fx supported_modes[] = {
const int supported_modes_cnt = ARRAY_SIZE(supported_modes);
#ifdef CONFIG_CMD_MFALLOW
-static int command_mfallow(int argc, char **argv)
+static int command_mfallow(int argc, const char **argv)
{
char *e;
int port;
@@ -1526,5 +1158,5 @@ static int command_mfallow(int argc, char **argv)
}
DECLARE_CONSOLE_COMMAND(mfallow, command_mfallow, "port [true | false]",
- "Controls Multifunction choice during DP Altmode.");
+ "Controls Multifunction choice during DP Altmode.");
#endif
diff --git a/common/usb_pd_alt_mode_ufp.c b/common/usb_pd_alt_mode_ufp.c
index 3db60166d2..5585056b58 100644
--- a/common/usb_pd_alt_mode_ufp.c
+++ b/common/usb_pd_alt_mode_ufp.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/common/usb_pd_console_cmd.c b/common/usb_pd_console_cmd.c
index 3ad1944494..23f2a27b1e 100644
--- a/common/usb_pd_console_cmd.c
+++ b/common/usb_pd_console_cmd.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -23,24 +23,24 @@ static void dump_pe(int port)
const struct pd_discovery *disc =
pd_get_am_discovery(port, TCPCI_MSG_SOP);
- static const char * const idh_ptype_names[] = {
- "UNDEF", "Hub", "Periph", "PCable", "ACable", "AMA",
- "RSV6", "RSV7"};
- static const char * const tx_names[] = {"SOP", "SOP'", "SOP''"};
+ static const char *const idh_ptype_names[] = { "UNDEF", "Hub",
+ "Periph", "PCable",
+ "ACable", "AMA",
+ "RSV6", "RSV7" };
+ static const char *const tx_names[] = { "SOP", "SOP'", "SOP''" };
for (type = TCPCI_MSG_SOP; type < DISCOVERY_TYPE_COUNT; type++) {
resp = pd_get_identity_response(port, type);
if (pd_get_identity_discovery(port, type) != PD_DISC_COMPLETE) {
ccprintf("No %s identity discovered yet.\n",
- tx_names[type]);
+ tx_names[type]);
continue;
}
idh_ptype = resp->idh.product_type;
ccprintf("IDENT %s:\n", tx_names[type]);
ccprintf("\t[ID Header] %08x :: %s, VID:%04x\n",
- resp->raw_value[0],
- idh_ptype_names[idh_ptype],
+ resp->raw_value[0], idh_ptype_names[idh_ptype],
resp->idh.usb_vendor_id);
ccprintf("\t[Cert Stat] %08x\n", resp->cert.xid);
@@ -62,11 +62,11 @@ static void dump_pe(int port)
ccprintf("SVID[%d]: %04x MODES:", i, disc->svids[i].svid);
for (j = 0; j < disc->svids[j].mode_cnt; j++)
ccprintf(" [%d] %08x", j + 1,
- disc->svids[i].mode_vdo[j]);
+ disc->svids[i].mode_vdo[j]);
ccprintf("\n");
modep = pd_get_amode_data(port, TCPCI_MSG_SOP,
- disc->svids[i].svid);
+ disc->svids[i].svid);
if (modep) {
mode_caps = modep->data->mode_vdo[modep->opos - 1];
ccprintf("MODE[%d]: svid:%04x caps:%08x\n", modep->opos,
@@ -75,7 +75,7 @@ static void dump_pe(int port)
}
}
-static int command_pe(int argc, char **argv)
+static int command_pe(int argc, const char **argv)
{
int port;
char *e;
@@ -92,23 +92,21 @@ static int command_pe(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(pe, command_pe,
- "<port> dump",
- "USB PE");
+DECLARE_CONSOLE_COMMAND(pe, command_pe, "<port> dump", "USB PE");
#endif /* CONFIG_CMD_USB_PD_PE */
#ifdef CONFIG_CMD_USB_PD_CABLE
-static const char * const cable_type[] = {
+static const char *const cable_type[] = {
[IDH_PTYPE_PCABLE] = "Passive",
[IDH_PTYPE_ACABLE] = "Active",
};
-static const char * const cable_curr[] = {
+static const char *const cable_curr[] = {
[USB_VBUS_CUR_3A] = "3A",
[USB_VBUS_CUR_5A] = "5A",
};
-static int command_cable(int argc, char **argv)
+static int command_cable(int argc, const char **argv)
{
int port;
char *e;
@@ -127,8 +125,7 @@ static int command_cable(int argc, char **argv)
ptype = get_usb_pd_cable_type(port);
ccprintf("Cable Type: ");
- if (ptype != IDH_PTYPE_PCABLE &&
- ptype != IDH_PTYPE_ACABLE) {
+ if (ptype != IDH_PTYPE_PCABLE && ptype != IDH_PTYPE_ACABLE) {
ccprintf("Not Emark Cable\n");
return EC_SUCCESS;
}
@@ -137,8 +134,9 @@ static int command_cable(int argc, char **argv)
cable_rev = pd_get_rev(port, TCPCI_MSG_SOP_PRIME);
disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
+ IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) ?
+ pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME) :
+ 0;
/* Cable revision */
ccprintf("Cable Rev: %d.0\n", cable_rev + 1);
@@ -148,13 +146,15 @@ static int command_cable(int argc, char **argv)
* connector type (Bit 19:18) and current handling capability bit 6:5
*/
ccprintf("Connector Type: %d\n",
- disc->identity.product_t1.p_rev20.connector);
+ disc->identity.product_t1.p_rev20.connector);
if (disc->identity.product_t1.p_rev20.vbus_cur) {
ccprintf("Cable Current: %s\n",
- disc->identity.product_t1.p_rev20.vbus_cur >
- ARRAY_SIZE(cable_curr) ? "Invalid" :
- cable_curr[disc->identity.product_t1.p_rev20.vbus_cur]);
+ disc->identity.product_t1.p_rev20.vbus_cur >
+ ARRAY_SIZE(cable_curr) ?
+ "Invalid" :
+ cable_curr[disc->identity.product_t1.p_rev20
+ .vbus_cur]);
} else
ccprintf("Cable Current: Invalid\n");
@@ -164,7 +164,7 @@ static int command_cable(int argc, char **argv)
*/
if (ptype == IDH_PTYPE_PCABLE)
ccprintf("USB Superspeed Signaling support: %d\n",
- disc->identity.product_t1.p_rev20.ss);
+ disc->identity.product_t1.p_rev20.ss);
/*
* For Rev 3.0 active cables and Rev 2.0 active and passive cables,
@@ -172,7 +172,8 @@ static int command_cable(int argc, char **argv)
*/
if (ptype == IDH_PTYPE_ACABLE)
ccprintf("SOP'' Controller: %s present\n",
- disc->identity.product_t1.a_rev20.sop_p_p ? "" : "Not");
+ disc->identity.product_t1.a_rev20.sop_p_p ? "" :
+ "Not");
if (cable_rev == PD_REV30) {
/*
@@ -180,15 +181,16 @@ static int command_cable(int argc, char **argv)
* same bits 10:9.
*/
ccprintf("Max vbus voltage: %d\n",
- 20 + 10 * disc->identity.product_t1.p_rev30.vbus_max);
+ 20 + 10 * disc->identity.product_t1.p_rev30.vbus_max);
/* For Rev 3.0 Active cables */
if (ptype == IDH_PTYPE_ACABLE) {
ccprintf("SS signaling: USB_SS_GEN%u\n",
- disc->identity.product_t2.a2_rev30.usb_gen ?
- 2 : 1);
+ disc->identity.product_t2.a2_rev30.usb_gen ?
+ 2 :
+ 1);
ccprintf("Number of SS lanes supported: %u\n",
- disc->identity.product_t2.a2_rev30.usb_lanes);
+ disc->identity.product_t2.a2_rev30.usb_lanes);
}
}
@@ -196,28 +198,29 @@ static int command_cable(int argc, char **argv)
return EC_SUCCESS;
ccprintf("Rounded support: %s\n",
- cable_mode_resp.tbt_rounded ==
- TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED ? "Yes" : "No");
+ cable_mode_resp.tbt_rounded ==
+ TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED ?
+ "Yes" :
+ "No");
ccprintf("Optical cable: %s\n",
- cable_mode_resp.tbt_cable == TBT_CABLE_OPTICAL ? "Yes" : "No");
+ cable_mode_resp.tbt_cable == TBT_CABLE_OPTICAL ? "Yes" : "No");
ccprintf("Retimer support: %s\n",
- cable_mode_resp.retimer_type == USB_RETIMER ?
- "Yes" : "No");
+ cable_mode_resp.retimer_type == USB_RETIMER ? "Yes" : "No");
ccprintf("Link training: %s-directional\n",
- cable_mode_resp.lsrx_comm == BIDIR_LSRX_COMM ? "Bi" : "Uni");
+ cable_mode_resp.lsrx_comm == BIDIR_LSRX_COMM ? "Bi" : "Uni");
ccprintf("Thunderbolt cable type: %s\n",
- cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE ?
- "Active" : "Passive");
+ cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE ?
+ "Active" :
+ "Passive");
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(pdcable, command_cable,
- "<port>",
+DECLARE_CONSOLE_COMMAND(pdcable, command_cable, "<port>",
"Cable Characteristics");
#endif /* CONFIG_CMD_USB_PD_CABLE */
diff --git a/common/usb_pd_dual_role.c b/common/usb_pd_dual_role.c
index a748f8377b..6498e0853f 100644
--- a/common/usb_pd_dual_role.c
+++ b/common/usb_pd_dual_role.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -13,7 +13,7 @@
#include "usb_pd.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
/* The macro is used to prevent a DBZ exception while decoding PDOs. */
#define PROCESS_ZERO_DIVISOR(x) ((x) == 0 ? 1 : (x))
@@ -66,8 +66,8 @@ static bool pd_get_usb_comm_capable(int port)
* PD_MAX_VOLTAGE_MV and PD_OPERATING_POWER_MW. And in turn, does not
* use the following functions.
*/
-int pd_find_pdo_index(uint32_t src_cap_cnt, const uint32_t * const src_caps,
- int max_mv, uint32_t *selected_pdo)
+int pd_find_pdo_index(uint32_t src_cap_cnt, const uint32_t *const src_caps,
+ int max_mv, uint32_t *selected_pdo)
{
int i, uw, mv;
int ret = 0;
@@ -157,10 +157,10 @@ int pd_find_pdo_index(uint32_t src_cap_cnt, const uint32_t * const src_caps,
mv < cur_mv)
prefer_cur = 1;
}
- /*
- * pick the largest power if we don't see one staisfy
- * desired power
- */
+ /*
+ * pick the largest power if we don't see one
+ * staisfy desired power
+ */
} else if (cur_uw == 0 || uw > cur_uw) {
prefer_cur = 1;
}
@@ -225,7 +225,7 @@ void pd_extract_pdo_power(uint32_t pdo, uint32_t *ma, uint32_t *max_mv,
}
void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
- uint32_t *mv, int port)
+ uint32_t *mv, int port)
{
uint32_t pdo;
int pdo_index, flags = 0;
@@ -236,7 +236,7 @@ void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
int vpd_vbus_dcr;
int vpd_gnd_dcr;
uint32_t src_cap_cnt = pd_get_src_cap_cnt(port);
- const uint32_t * const src_caps = pd_get_src_caps(port);
+ const uint32_t *const src_caps = pd_get_src_caps(port);
int charging_allowed;
int max_request_allowed;
uint32_t max_request_mv = pd_get_max_voltage();
@@ -265,8 +265,7 @@ void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
max_request_allowed = 1;
if (IS_ENABLED(CONFIG_USB_PD_DPS) && dps_is_enabled())
- max_request_mv =
- MIN(max_request_mv, dps_get_dynamic_voltage());
+ max_request_mv = MIN(max_request_mv, dps_get_dynamic_voltage());
/*
* If currently charging on a different port, or we are not allowed to
@@ -275,7 +274,7 @@ void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
if (charging_allowed && max_request_allowed) {
/* find pdo index for max voltage we can request */
pdo_index = pd_find_pdo_index(src_cap_cnt, src_caps,
- max_request_mv, &pdo);
+ max_request_mv, &pdo);
} else {
/* src cap 0 should be vSafe5V */
pdo_index = 0;
@@ -319,28 +318,28 @@ void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
flags |= RDO_CAP_MISMATCH;
#ifdef CONFIG_USB_PD_GIVE_BACK
- /* Tell source we are give back capable. */
- flags |= RDO_GIVE_BACK;
+ /* Tell source we are give back capable. */
+ flags |= RDO_GIVE_BACK;
- /*
- * BATTERY PDO: Inform the source that the sink will reduce
- * power to this minimum level on receipt of a GotoMin Request.
- */
- max_or_min_mw = PD_MIN_POWER_MW;
+ /*
+ * BATTERY PDO: Inform the source that the sink will reduce
+ * power to this minimum level on receipt of a GotoMin Request.
+ */
+ max_or_min_mw = PD_MIN_POWER_MW;
- /*
- * FIXED or VARIABLE PDO: Inform the source that the sink will
- * reduce current to this minimum level on receipt of a GotoMin
- * Request.
- */
- max_or_min_ma = PD_MIN_CURRENT_MA;
+ /*
+ * FIXED or VARIABLE PDO: Inform the source that the sink will
+ * reduce current to this minimum level on receipt of a GotoMin
+ * Request.
+ */
+ max_or_min_ma = PD_MIN_CURRENT_MA;
#else
- /*
- * Can't give back, so set maximum current and power to
- * operating level.
- */
- max_or_min_ma = *ma;
- max_or_min_mw = uw / 1000;
+ /*
+ * Can't give back, so set maximum current and power to
+ * operating level.
+ */
+ max_or_min_ma = *ma;
+ max_or_min_mw = uw / 1000;
#endif
if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
@@ -381,8 +380,7 @@ void pd_process_source_cap(int port, int cnt, uint32_t *src_caps)
/* Get max power info that we could request */
pd_find_pdo_index(pd_get_src_cap_cnt(port),
- pd_get_src_caps(port),
- max_mv, &pdo);
+ pd_get_src_caps(port), max_mv, &pdo);
pd_extract_pdo_power(pdo, &ma, &mv, &unused);
/* Set max. limit, but apply 500mA ceiling */
@@ -397,8 +395,7 @@ bool pd_is_battery_capable(void)
bool capable;
/* Battery is present and at some minimum percentage. */
- capable = (usb_get_battery_soc() >=
- CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC);
+ capable = (usb_get_battery_soc() >= CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC);
#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
/*
@@ -406,9 +403,8 @@ bool pd_is_battery_capable(void)
* FET may not be enabled and so attempting being a SRC may cut off
* our only power source at the time.
*/
- capable &= (battery_get_disconnect_state() ==
- BATTERY_NOT_DISCONNECTED);
-#elif defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
+ capable &= (battery_get_disconnect_state() == BATTERY_NOT_DISCONNECTED);
+#elif defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
defined(CONFIG_BATTERY_PRESENT_GPIO)
/*
* When battery is cutoff in ship mode it may not be reliable to
@@ -443,7 +439,7 @@ bool pd_is_try_source_capable(void)
* therefore allow Try.Src if we're toggling.
*/
new_try_src = try_src && (charge_manager_get_supplier() ==
- CHARGE_SUPPLIER_DEDICATED);
+ CHARGE_SUPPLIER_DEDICATED);
#endif /* CONFIG_DEDICATED_CHARGE_PORT_COUNT */
return new_try_src;
diff --git a/common/usb_pd_flags.c b/common/usb_pd_flags.c
index 073637e05b..89225f7730 100644
--- a/common/usb_pd_flags.c
+++ b/common/usb_pd_flags.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.
*/
@@ -17,7 +17,7 @@ BUILD_ASSERT(sizeof(usb_pd_flags) == sizeof(uint32_t));
enum usb_pd_vbus_detect get_usb_pd_vbus_detect(void)
{
if (IS_ENABLED(CONFIG_USB_PD_RUNTIME_FLAGS))
- return (enum usb_pd_vbus_detect) usb_pd_flags.vbus_detect;
+ return (enum usb_pd_vbus_detect)usb_pd_flags.vbus_detect;
else if (IS_ENABLED(CONFIG_USB_PD_VBUS_DETECT_TCPC))
return (enum usb_pd_vbus_detect)USB_PD_VBUS_DETECT_TCPC;
else if (IS_ENABLED(CONFIG_USD_PD_VBUS_DETECT_GPIO))
diff --git a/common/usb_pd_host_cmd.c b/common/usb_pd_host_cmd.c
index 09a5697829..8d43571a3f 100644
--- a/common/usb_pd_host_cmd.c
+++ b/common/usb_pd_host_cmd.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -20,8 +20,8 @@
#include "usb_pd_tcpm.h"
#include "usb_pd.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else /* CONFIG_COMMON_RUNTIME */
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -38,9 +38,7 @@ static enum ec_status hc_pd_ports(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_PORTS,
- hc_pd_ports,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_PORTS, hc_pd_ports, EC_VER_MASK(0));
#ifdef CONFIG_HOSTCMD_RWHASHPD
static enum ec_status
@@ -71,8 +69,7 @@ hc_remote_rw_hash_entry(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_RW_HASH_ENTRY,
- hc_remote_rw_hash_entry,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_RW_HASH_ENTRY, hc_remote_rw_hash_entry,
EC_VER_MASK(0));
#endif /* CONFIG_HOSTCMD_RWHASHPD */
@@ -93,15 +90,14 @@ static enum ec_status hc_remote_pd_chip_info(struct host_cmd_handler_args *args)
* same layout for v0 data. (v1 just appends data)
*/
args->response_size =
- args->version ? sizeof(struct ec_response_pd_chip_info_v1)
- : sizeof(struct ec_response_pd_chip_info);
+ args->version ? sizeof(struct ec_response_pd_chip_info_v1) :
+ sizeof(struct ec_response_pd_chip_info);
memcpy(args->response, &info, args->response_size);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PD_CHIP_INFO,
- hc_remote_pd_chip_info,
+DECLARE_HOST_COMMAND(EC_CMD_PD_CHIP_INFO, hc_remote_pd_chip_info,
EC_VER_MASK(0) | EC_VER_MASK(1));
#endif /* CONFIG_EC_CMD_PD_CHIP_INFO && !CONFIG_USB_PD_TCPC */
@@ -110,8 +106,8 @@ static enum ec_status hc_remote_pd_set_amode(struct host_cmd_handler_args *args)
{
const struct ec_params_usb_pd_set_mode_request *p = args->params;
- if ((p->port >= board_get_usb_pd_port_count()) ||
- (!p->svid) || (!p->opos))
+ if ((p->port >= board_get_usb_pd_port_count()) || (!p->svid) ||
+ (!p->opos))
return EC_RES_INVALID_PARAM;
switch (p->cmd) {
@@ -126,16 +122,16 @@ static enum ec_status hc_remote_pd_set_amode(struct host_cmd_handler_args *args)
break;
case PD_ENTER_MODE:
if (pd_dfp_enter_mode(p->port, TCPCI_MSG_SOP, p->svid, p->opos))
- pd_send_vdm(p->port, p->svid, CMD_ENTER_MODE |
- VDO_OPOS(p->opos), NULL, 0);
+ pd_send_vdm(p->port, p->svid,
+ CMD_ENTER_MODE | VDO_OPOS(p->opos), NULL,
+ 0);
break;
default:
return EC_RES_INVALID_PARAM;
}
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_SET_AMODE,
- hc_remote_pd_set_amode,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_SET_AMODE, hc_remote_pd_set_amode,
EC_VER_MASK(0));
static enum ec_status hc_remote_pd_discovery(struct host_cmd_handler_args *args)
@@ -156,8 +152,7 @@ static enum ec_status hc_remote_pd_discovery(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_DISCOVERY,
- hc_remote_pd_discovery,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_DISCOVERY, hc_remote_pd_discovery,
EC_VER_MASK(0));
static enum ec_status hc_remote_pd_get_amode(struct host_cmd_handler_args *args)
@@ -180,7 +175,7 @@ static enum ec_status hc_remote_pd_get_amode(struct host_cmd_handler_args *args)
r->svid = pd_get_svid(p->port, p->svid_idx, TCPCI_MSG_SOP);
r->opos = 0;
memcpy(r->vdo, pd_get_mode_vdo(p->port, p->svid_idx, TCPCI_MSG_SOP),
- sizeof(uint32_t) * PDO_MODES);
+ sizeof(uint32_t) * PDO_MODES);
modep = pd_get_amode_data(p->port, TCPCI_MSG_SOP, r->svid);
if (modep)
@@ -189,8 +184,7 @@ static enum ec_status hc_remote_pd_get_amode(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_GET_AMODE,
- hc_remote_pd_get_amode,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_GET_AMODE, hc_remote_pd_get_amode,
EC_VER_MASK(0));
#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
@@ -215,23 +209,22 @@ static enum ec_status hc_remote_pd_dev_info(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_DEV_INFO,
- hc_remote_pd_dev_info,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_DEV_INFO, hc_remote_pd_dev_info,
EC_VER_MASK(0));
static const enum pd_dual_role_states dual_role_map[USB_PD_CTRL_ROLE_COUNT] = {
- [USB_PD_CTRL_ROLE_TOGGLE_ON] = PD_DRP_TOGGLE_ON,
- [USB_PD_CTRL_ROLE_TOGGLE_OFF] = PD_DRP_TOGGLE_OFF,
- [USB_PD_CTRL_ROLE_FORCE_SINK] = PD_DRP_FORCE_SINK,
+ [USB_PD_CTRL_ROLE_TOGGLE_ON] = PD_DRP_TOGGLE_ON,
+ [USB_PD_CTRL_ROLE_TOGGLE_OFF] = PD_DRP_TOGGLE_OFF,
+ [USB_PD_CTRL_ROLE_FORCE_SINK] = PD_DRP_FORCE_SINK,
[USB_PD_CTRL_ROLE_FORCE_SOURCE] = PD_DRP_FORCE_SOURCE,
- [USB_PD_CTRL_ROLE_FREEZE] = PD_DRP_FREEZE,
+ [USB_PD_CTRL_ROLE_FREEZE] = PD_DRP_FREEZE,
};
static const mux_state_t typec_mux_map[USB_PD_CTRL_MUX_COUNT] = {
[USB_PD_CTRL_MUX_NONE] = USB_PD_MUX_NONE,
- [USB_PD_CTRL_MUX_USB] = USB_PD_MUX_USB_ENABLED,
+ [USB_PD_CTRL_MUX_USB] = USB_PD_MUX_USB_ENABLED,
[USB_PD_CTRL_MUX_AUTO] = USB_PD_MUX_DP_ENABLED,
- [USB_PD_CTRL_MUX_DP] = USB_PD_MUX_DP_ENABLED,
+ [USB_PD_CTRL_MUX_DP] = USB_PD_MUX_DP_ENABLED,
[USB_PD_CTRL_MUX_DOCK] = USB_PD_MUX_DOCK,
};
@@ -248,7 +241,8 @@ static uint8_t get_pd_control_flags(int port)
union tbt_mode_resp_device device_resp;
uint8_t control_flags = 0;
- if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
+ if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP) ||
+ !IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE))
return 0;
cable_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
@@ -260,14 +254,18 @@ static uint8_t get_pd_control_flags(int port)
* For Passive cables, Active Cable Plug link training is set to 0
*/
control_flags |= (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE ||
- cable_resp.tbt_active_passive == TBT_CABLE_ACTIVE) ?
- USB_PD_CTRL_ACTIVE_CABLE : 0;
+ cable_resp.tbt_active_passive == TBT_CABLE_ACTIVE) ?
+ USB_PD_CTRL_ACTIVE_CABLE :
+ 0;
control_flags |= cable_resp.tbt_cable == TBT_CABLE_OPTICAL ?
- USB_PD_CTRL_OPTICAL_CABLE : 0;
+ USB_PD_CTRL_OPTICAL_CABLE :
+ 0;
control_flags |= device_resp.tbt_adapter == TBT_ADAPTER_TBT2_LEGACY ?
- USB_PD_CTRL_TBT_LEGACY_ADAPTER : 0;
+ USB_PD_CTRL_TBT_LEGACY_ADAPTER :
+ 0;
control_flags |= cable_resp.lsrx_comm == UNIDIR_LSRX_COMM ?
- USB_PD_CTRL_ACTIVE_LINK_UNIDIR : 0;
+ USB_PD_CTRL_ACTIVE_LINK_UNIDIR :
+ 0;
return control_flags;
}
@@ -275,19 +273,23 @@ static uint8_t get_pd_control_flags(int port)
static uint8_t pd_get_role_flags(int port)
{
return (pd_get_power_role(port) == PD_ROLE_SOURCE ?
- PD_CTRL_RESP_ROLE_POWER : 0) |
- (pd_get_data_role(port) == PD_ROLE_DFP ?
- PD_CTRL_RESP_ROLE_DATA : 0) |
- (pd_get_vconn_state(port) ?
- PD_CTRL_RESP_ROLE_VCONN : 0) |
- (pd_get_partner_dual_role_power(port) ?
- PD_CTRL_RESP_ROLE_DR_POWER : 0) |
- (pd_get_partner_data_swap_capable(port) ?
- PD_CTRL_RESP_ROLE_DR_DATA : 0) |
- (pd_get_partner_usb_comm_capable(port) ?
- PD_CTRL_RESP_ROLE_USB_COMM : 0) |
- (pd_get_partner_unconstr_power(port) ?
- PD_CTRL_RESP_ROLE_UNCONSTRAINED : 0);
+ PD_CTRL_RESP_ROLE_POWER :
+ 0) |
+ (pd_get_data_role(port) == PD_ROLE_DFP ? PD_CTRL_RESP_ROLE_DATA :
+ 0) |
+ (pd_get_vconn_state(port) ? PD_CTRL_RESP_ROLE_VCONN : 0) |
+ (pd_get_partner_dual_role_power(port) ?
+ PD_CTRL_RESP_ROLE_DR_POWER :
+ 0) |
+ (pd_get_partner_data_swap_capable(port) ?
+ PD_CTRL_RESP_ROLE_DR_DATA :
+ 0) |
+ (pd_get_partner_usb_comm_capable(port) ?
+ PD_CTRL_RESP_ROLE_USB_COMM :
+ 0) |
+ (pd_get_partner_unconstr_power(port) ?
+ PD_CTRL_RESP_ROLE_UNCONSTRAINED :
+ 0);
}
static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
@@ -313,11 +315,11 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
}
if (IS_ENABLED(CONFIG_USBC_SS_MUX) &&
- p->mux != USB_PD_CTRL_MUX_NO_CHANGE)
+ p->mux != USB_PD_CTRL_MUX_NO_CHANGE)
usb_mux_set(p->port, typec_mux_map[p->mux],
typec_mux_map[p->mux] == USB_PD_MUX_NONE ?
- USB_SWITCH_DISCONNECT :
- USB_SWITCH_CONNECT,
+ USB_SWITCH_DISCONNECT :
+ USB_SWITCH_CONNECT,
polarity_rm_dts(pd_get_polarity(p->port)));
if (p->swap == USB_PD_CTRL_SWAP_DATA) {
@@ -326,7 +328,7 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
if (p->swap == USB_PD_CTRL_SWAP_POWER)
pd_request_power_swap(p->port);
else if (IS_ENABLED(CONFIG_USBC_VCONN_SWAP) &&
- p->swap == USB_PD_CTRL_SWAP_VCONN)
+ p->swap == USB_PD_CTRL_SWAP_VCONN)
pd_request_vconn_swap(p->port);
}
@@ -340,17 +342,19 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
break;
case 1:
case 2:
- r_v2->enabled =
- (pd_comm_is_enabled(p->port) ?
- PD_CTRL_RESP_ENABLED_COMMS : 0) |
- (pd_is_connected(p->port) ?
- PD_CTRL_RESP_ENABLED_CONNECTED : 0) |
- (pd_capable(p->port) ?
- PD_CTRL_RESP_ENABLED_PD_CAPABLE : 0);
+ r_v2->enabled = (pd_comm_is_enabled(p->port) ?
+ PD_CTRL_RESP_ENABLED_COMMS :
+ 0) |
+ (pd_is_connected(p->port) ?
+ PD_CTRL_RESP_ENABLED_CONNECTED :
+ 0) |
+ (pd_capable(p->port) ?
+ PD_CTRL_RESP_ENABLED_PD_CAPABLE :
+ 0);
r_v2->role = pd_get_role_flags(p->port);
r_v2->polarity = pd_get_polarity(p->port);
- r_v2->cc_state = pd_get_task_cc_state(p->port);
+ r_v2->cc_state = pd_get_task_cc_state(p->port);
task_state_name = pd_get_task_state_name(p->port);
if (task_state_name)
strzcpy(r_v2->state, task_state_name,
@@ -361,8 +365,12 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
r_v2->control_flags = get_pd_control_flags(p->port);
if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
r_v2->dp_mode = get_dp_pin_mode(p->port);
- r_v2->cable_speed = get_tbt_cable_speed(p->port);
- r_v2->cable_gen = get_tbt_rounded_support(p->port);
+ if (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)) {
+ r_v2->cable_speed =
+ get_tbt_cable_speed(p->port);
+ r_v2->cable_gen =
+ get_tbt_rounded_support(p->port);
+ }
}
if (args->version == 1)
@@ -376,8 +384,7 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
}
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_CONTROL,
- hc_usb_pd_control,
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_CONTROL, hc_usb_pd_control,
EC_VER_MASK(0) | EC_VER_MASK(1) | EC_VER_MASK(2));
#endif /* CONFIG_COMMON_RUNTIME */
@@ -397,14 +404,14 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
#if defined(CONFIG_CHARGE_MANAGER) && defined(CONFIG_BATTERY) && \
- (defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
+ (defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
defined(CONFIG_BATTERY_PRESENT_GPIO))
/*
* Do not allow PD firmware update if no battery and this port
* is sinking power, because we will lose power.
*/
if (battery_is_present() != BP_YES &&
- charge_manager_get_active_charge_port() == port)
+ charge_manager_get_active_charge_port() == port)
return EC_RES_UNAVAILABLE;
#endif
@@ -437,7 +444,7 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
size = p->size / 4;
for (i = 0; i < size; i += VDO_MAX_SIZE - 1) {
pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_FLASH_WRITE,
- data + i, MIN(size - i, VDO_MAX_SIZE - 1));
+ data + i, MIN(size - i, VDO_MAX_SIZE - 1));
}
return EC_RES_SUCCESS;
@@ -447,12 +454,9 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
return rv;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_FW_UPDATE,
- hc_remote_flash,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_FW_UPDATE, hc_remote_flash, EC_VER_MASK(0));
#endif /* CONFIG_HOSTCMD_FLASHPD && CONFIG_USB_PD_TCPMV2 */
-
__overridable enum ec_pd_port_location board_get_pd_port_location(int port)
{
(void)port;
@@ -479,8 +483,7 @@ static enum ec_status hc_get_pd_port_caps(struct host_cmd_handler_args *args)
else
r->pd_try_power_role_cap = EC_PD_TRY_POWER_ROLE_NONE;
- if (IS_ENABLED(CONFIG_USB_VPD) ||
- IS_ENABLED(CONFIG_USB_CTVPD))
+ if (IS_ENABLED(CONFIG_USB_VPD) || IS_ENABLED(CONFIG_USB_CTVPD))
r->pd_data_role_cap = EC_PD_DATA_ROLE_UFP;
else
r->pd_data_role_cap = EC_PD_DATA_ROLE_DUAL;
@@ -492,14 +495,22 @@ static enum ec_status hc_get_pd_port_caps(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_GET_PD_PORT_CAPS,
- hc_get_pd_port_caps,
+DECLARE_HOST_COMMAND(EC_CMD_GET_PD_PORT_CAPS, hc_get_pd_port_caps,
EC_VER_MASK(0));
#ifdef CONFIG_HOSTCMD_PD_CONTROL
+static int pd_control_disabled[CONFIG_USB_PD_PORT_MAX_COUNT];
+
+/* Only allow port re-enable in unit tests */
+#ifdef TEST_BUILD
+void pd_control_port_enable(int port)
+{
+ pd_control_disabled[port] = 0;
+}
+#endif /* TEST_BUILD */
+
static enum ec_status pd_control(struct host_cmd_handler_args *args)
{
- static int pd_control_disabled[CONFIG_USB_PD_PORT_MAX_COUNT];
const struct ec_params_pd_control *cmd = args->params;
int enable = 0;
diff --git a/common/usb_pd_pdo.c b/common/usb_pd_pdo.c
index cfa355bf0e..3141af34a9 100644
--- a/common/usb_pd_pdo.c
+++ b/common/usb_pd_pdo.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/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 30aa936f28..c63cde6301 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -1,9 +1,10 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "atomic.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "common.h"
#include "console.h"
@@ -77,20 +78,11 @@ __overridable void pd_check_dr_role(int port, enum pd_data_role dr_role,
pd_request_data_swap(port);
}
-#ifdef CONFIG_MKBP_EVENT
-static int dp_alt_mode_entry_get_next_event(uint8_t *data)
-{
- return EC_SUCCESS;
-}
-DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_DP_ALT_MODE_ENTERED,
- dp_alt_mode_entry_get_next_event);
-#endif /* CONFIG_MKBP_EVENT */
-
/* Last received source cap */
static uint32_t pd_src_caps[CONFIG_USB_PD_PORT_MAX_COUNT][PDO_MAX_OBJECTS];
static uint8_t pd_src_cap_cnt[CONFIG_USB_PD_PORT_MAX_COUNT];
-const uint32_t * const pd_get_src_caps(int port)
+const uint32_t *const pd_get_src_caps(int port)
{
return pd_src_caps[port];
}
@@ -110,76 +102,6 @@ uint8_t pd_get_src_cap_cnt(int port)
return pd_src_cap_cnt[port];
}
-static struct pd_cable cable[CONFIG_USB_PD_PORT_MAX_COUNT];
-
-enum pd_rev_type get_usb_pd_cable_revision(int port)
-{
- return cable[port].rev;
-}
-
-bool consume_sop_prime_repeat_msg(int port, uint8_t msg_id)
-{
- if (cable[port].last_sop_p_msg_id != msg_id) {
- cable[port].last_sop_p_msg_id = msg_id;
- return false;
- }
- CPRINTF("C%d SOP Prime repeat msg_id %d\n", port, msg_id);
- return true;
-}
-
-bool consume_sop_prime_prime_repeat_msg(int port, uint8_t msg_id)
-{
- if (cable[port].last_sop_p_p_msg_id != msg_id) {
- cable[port].last_sop_p_p_msg_id = msg_id;
- return false;
- }
- CPRINTF("C%d SOP Prime Prime repeat msg_id %d\n", port, msg_id);
- return true;
-}
-
-__maybe_unused static uint8_t is_sop_prime_ready(int port)
-{
- /*
- * Ref: USB PD 3.0 sec 2.5.4: When an Explicit Contract is in place the
- * VCONN Source (either the DFP or the UFP) can communicate with the
- * Cable Plug(s) using SOP’/SOP’’ Packets
- *
- * Ref: USB PD 2.0 sec 2.4.4: When an Explicit Contract is in place the
- * DFP (either the Source or the Sink) can communicate with the
- * Cable Plug(s) using SOP’/SOP” Packets.
- * Sec 3.6.11 : Before communicating with a Cable Plug a Port Should
- * ensure that it is the Vconn Source
- */
- return (pd_get_vconn_state(port) &&
- (IS_ENABLED(CONFIG_USB_PD_REV30) ||
- (pd_get_data_role(port) == PD_ROLE_DFP)));
-}
-
-void reset_pd_cable(int port)
-{
- memset(&cable[port], 0, sizeof(cable[port]));
- cable[port].last_sop_p_msg_id = INVALID_MSG_ID_COUNTER;
- cable[port].last_sop_p_p_msg_id = INVALID_MSG_ID_COUNTER;
-}
-
-bool should_enter_usb4_mode(int port)
-{
- return IS_ENABLED(CONFIG_USB_PD_USB4) &&
- cable[port].flags & CABLE_FLAGS_ENTER_USB_MODE;
-}
-
-void enable_enter_usb4_mode(int port)
-{
- if (IS_ENABLED(CONFIG_USB_PD_USB4))
- cable[port].flags |= CABLE_FLAGS_ENTER_USB_MODE;
-}
-
-void disable_enter_usb4_mode(int port)
-{
- if (IS_ENABLED(CONFIG_USB_PD_USB4))
- cable[port].flags &= ~CABLE_FLAGS_ENTER_USB_MODE;
-}
-
#ifdef CONFIG_USB_PD_ALT_MODE
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
@@ -189,168 +111,6 @@ static struct pd_discovery discovery[CONFIG_USB_PD_PORT_MAX_COUNT]
static struct partner_active_modes partner_amodes[CONFIG_USB_PD_PORT_MAX_COUNT]
[AMODE_TYPE_COUNT];
-static bool is_vdo_present(int cnt, int index)
-{
- return cnt > index;
-}
-
-static bool is_modal(int port, int cnt, const uint32_t *payload)
-{
- return is_vdo_present(cnt, VDO_INDEX_IDH) &&
- PD_IDH_IS_MODAL(payload[VDO_INDEX_IDH]);
-}
-
-static bool is_tbt_compat_mode(int port, int cnt, const uint32_t *payload)
-{
- /*
- * Ref: USB Type-C cable and connector specification
- * F.2.5 TBT3 Device Discover Mode Responses
- */
- return is_vdo_present(cnt, VDO_INDEX_IDH) &&
- PD_VDO_RESP_MODE_INTEL_TBT(payload[VDO_INDEX_IDH]);
-}
-
-static bool cable_supports_tbt_speed(int port)
-{
- enum tbt_compat_cable_speed tbt_cable_speed = get_tbt_cable_speed(port);
-
- return (tbt_cable_speed == TBT_SS_TBT_GEN3 ||
- tbt_cable_speed == TBT_SS_U32_GEN1_GEN2);
-}
-
-static bool is_tbt_compat_enabled(int port)
-{
- return (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) &&
- (cable[port].flags & CABLE_FLAGS_TBT_COMPAT_ENABLE));
-}
-
-static void enable_tbt_compat_mode(int port)
-{
- if (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE))
- cable[port].flags |= CABLE_FLAGS_TBT_COMPAT_ENABLE;
-}
-
-static inline void disable_tbt_compat_mode(int port)
-{
- if (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE))
- cable[port].flags &= ~CABLE_FLAGS_TBT_COMPAT_ENABLE;
-}
-
-static inline void limit_tbt_cable_speed(int port)
-{
- /* Cable flags are cleared when cable reset is called */
- cable[port].flags |= CABLE_FLAGS_TBT_COMPAT_LIMIT_SPEED;
-}
-
-static inline bool is_limit_tbt_cable_speed(int port)
-{
- return !!(cable[port].flags & CABLE_FLAGS_TBT_COMPAT_LIMIT_SPEED);
-}
-
-static bool is_intel_svid(int port, enum tcpci_msg_type type)
-{
- int i;
-
- for (i = 0; i < discovery[port][type].svid_cnt; i++) {
- if (pd_get_svid(port, i, type) == USB_VID_INTEL)
- return true;
- }
-
- return false;
-}
-
-static inline bool is_usb4_mode_enabled(int port)
-{
- return (IS_ENABLED(CONFIG_USB_PD_USB4) &&
- (cable[port].flags & CABLE_FLAGS_USB4_CAPABLE));
-}
-
-static inline void enable_usb4_mode(int port)
-{
- if (IS_ENABLED(CONFIG_USB_PD_USB4))
- cable[port].flags |= CABLE_FLAGS_USB4_CAPABLE;
-}
-
-static inline void disable_usb4_mode(int port)
-{
- if (IS_ENABLED(CONFIG_USB_PD_USB4))
- cable[port].flags &= ~CABLE_FLAGS_USB4_CAPABLE;
-}
-
-/*
- * Ref: USB Type-C Cable and Connector Specification
- * Figure 5-1 USB4 Discovery and Entry Flow Model.
- *
- * Note: USB Type-C Cable and Connector Specification
- * doesn't include details for Revision 2 cables.
- *
- * Passive Cable
- * |
- * -----------------------------------
- * | |
- * Revision 2 Revision 3
- * USB Signalling USB Signalling
- * | |
- * ------------------ -------------------------
- * | | | | | | |
- * USB2.0 USB3.1 USB3.1 USB3.2 USB4 USB3.2 USB2
- * | Gen1 Gen1 Gen2 Gen2 Gen3 Gen1 |
- * | | | | | | Exit
- * -------- ------------ -------- USB4
- * | | | Discovery.
- * Exit Is DFP Gen3 Capable? Enter USB4
- * USB4 | with respective
- * Discovery. --- No ---|--- Yes --- cable speed.
- * | |
- * Enter USB4 with Is Cable TBT3
- * respective cable |
- * speed. --- No ---|--- Yes ---
- * | |
- * Enter USB4 with Enter USB4 with
- * TBT Gen2 passive TBT Gen3 passive
- * cable. cable.
- *
- */
-static bool is_cable_ready_to_enter_usb4(int port, int cnt)
-{
- /* TODO: USB4 enter mode for Active cables */
- struct pd_discovery *disc = &discovery[port][TCPCI_MSG_SOP_PRIME];
- if (IS_ENABLED(CONFIG_USB_PD_USB4) &&
- (get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE) &&
- is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE1)) {
- switch (cable[port].rev) {
- case PD_REV30:
- switch (disc->identity.product_t1.p_rev30.ss) {
- case USB_R30_SS_U40_GEN3:
- case USB_R30_SS_U32_U40_GEN1:
- return true;
- case USB_R30_SS_U32_U40_GEN2:
- /* Check if DFP is Gen 3 capable */
- if (IS_ENABLED(CONFIG_USB_PD_TBT_GEN3_CAPABLE))
- return false;
- return true;
- default:
- disable_usb4_mode(port);
- return false;
- }
- case PD_REV20:
- switch (disc->identity.product_t1.p_rev20.ss) {
- case USB_R20_SS_U31_GEN1_GEN2:
- /* Check if DFP is Gen 3 capable */
- if (IS_ENABLED(CONFIG_USB_PD_TBT_GEN3_CAPABLE))
- return false;
- return true;
- default:
- disable_usb4_mode(port);
- return false;
- }
- default:
- disable_usb4_mode(port);
- }
- }
- return false;
-}
-
void pd_dfp_discovery_init(int port)
{
memset(&discovery[port], 0, sizeof(struct pd_discovery));
@@ -361,26 +121,20 @@ void pd_dfp_mode_init(int port)
memset(&partner_amodes[port], 0, sizeof(partner_amodes[0]));
}
-static int dfp_discover_ident(uint32_t *payload)
-{
- payload[0] = VDO(USB_SID_PD, 1, CMD_DISCOVER_IDENT);
- return 1;
-}
-
static int dfp_discover_svids(uint32_t *payload)
{
payload[0] = VDO(USB_SID_PD, 1, CMD_DISCOVER_SVID);
return 1;
}
-struct pd_discovery *pd_get_am_discovery_and_notify_access(
- int port, enum tcpci_msg_type type)
+struct pd_discovery *
+pd_get_am_discovery_and_notify_access(int port, enum tcpci_msg_type type)
{
return (struct pd_discovery *)pd_get_am_discovery(port, type);
}
const struct pd_discovery *pd_get_am_discovery(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
return &discovery[port][type];
}
@@ -407,7 +161,7 @@ void pd_set_dfp_enter_mode_flag(int port, bool set)
static int dfp_discover_modes(int port, uint32_t *payload)
{
const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP);
+ pd_get_am_discovery(port, TCPCI_MSG_SOP);
uint16_t svid = disc->svids[disc->svid_idx].svid;
if (disc->svid_idx >= disc->svid_cnt)
@@ -418,23 +172,6 @@ static int dfp_discover_modes(int port, uint32_t *payload)
return 1;
}
-static bool is_usb4_vdo(int port, int cnt, uint32_t *payload)
-{
- enum idh_ptype ptype = PD_IDH_PTYPE(payload[VDO_I(IDH)]);
-
- if (IS_PD_IDH_UFP_PTYPE(ptype)) {
- /*
- * Ref: USB Type-C Cable and Connector Specification
- * Figure 5-1 USB4 Discovery and Entry Flow Model
- * Device USB4 VDO detection.
- */
- return IS_ENABLED(CONFIG_USB_PD_USB4) &&
- is_vdo_present(cnt, VDO_INDEX_PTYPE_UFP1_VDO) &&
- PD_PRODUCT_IS_USB4(payload[VDO_INDEX_PTYPE_UFP1_VDO]);
- }
- return false;
-}
-
static int process_am_discover_ident_sop(int port, int cnt, uint32_t head,
uint32_t *payload,
enum tcpci_msg_type *rtype)
@@ -443,63 +180,6 @@ static int process_am_discover_ident_sop(int port, int cnt, uint32_t head,
pd_dfp_mode_init(port);
dfp_consume_identity(port, TCPCI_MSG_SOP, cnt, payload);
- if (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP) && is_sop_prime_ready(port) &&
- board_is_tbt_usb4_port(port)) {
- /* Enable USB4 mode if USB4 VDO present and port partner
- * supports USB Rev 3.0.
- */
- if (is_usb4_vdo(port, cnt, payload) &&
- PD_HEADER_REV(head) == PD_REV30)
- enable_usb4_mode(port);
-
- /*
- * Enable Thunderbolt-compatible mode if the modal operation is
- * supported.
- */
- if (is_modal(port, cnt, payload))
- enable_tbt_compat_mode(port);
-
- if (is_modal(port, cnt, payload) ||
- is_usb4_vdo(port, cnt, payload)) {
- *rtype = TCPCI_MSG_SOP_PRIME;
- return dfp_discover_ident(payload);
- }
- }
-
- return dfp_discover_svids(payload);
-}
-
-static int process_am_discover_ident_sop_prime(int port, int cnt, uint32_t head,
- uint32_t *payload)
-{
- dfp_consume_identity(port, TCPCI_MSG_SOP_PRIME, cnt, payload);
- cable[port].rev = PD_HEADER_REV(head);
-
- /*
- * Enter USB4 mode if the cable supports USB4 operation and has USB4
- * VDO.
- */
- if (is_usb4_mode_enabled(port) &&
- is_cable_ready_to_enter_usb4(port, cnt)) {
- enable_enter_usb4_mode(port);
- usb_mux_set_safe_mode(port);
- /*
- * To change the mode of operation from USB4 the port needs to
- * be reconfigured.
- * Ref: USB Type-C Cable and Connectot Spec section 5.4.4.
- */
- disable_tbt_compat_mode(port);
- return 0;
- }
-
- /*
- * Disable Thunderbolt-compatible mode if the cable does not support
- * superspeed.
- */
- if (is_tbt_compat_enabled(port) &&
- get_tbt_cable_speed(port) < TBT_SS_U31_GEN1)
- disable_tbt_compat_mode(port);
-
return dfp_discover_svids(payload);
}
@@ -514,133 +194,8 @@ static int process_am_discover_svids(int port, int cnt, uint32_t *payload,
*/
dfp_consume_svids(port, sop, cnt, payload);
- /*
- * Ref: USB Type-C Cable and Connector Specification,
- * figure F-1: TBT3 Discovery Flow
- *
- * For USB4 mode if device or cable doesn't have Intel SVID,
- * disable Thunderbolt-Compatible mode directly enter USB4 mode
- * with USB3.2 Gen1/Gen2 speed.
- *
- * For Thunderbolt-compatible, check if 0x8087 is received for
- * Discover SVID SOP. If not, disable Thunderbolt-compatible mode
- *
- * If 0x8087 is not received for Discover SVID SOP' limit to TBT
- * passive Gen 2 cable.
- */
- if (is_tbt_compat_enabled(port)) {
- bool intel_svid = is_intel_svid(port, sop);
- if (!intel_svid) {
- if (is_usb4_mode_enabled(port)) {
- disable_tbt_compat_mode(port);
- cable[port].cable_mode_resp.tbt_cable_speed =
- TBT_SS_U32_GEN1_GEN2;
- enable_enter_usb4_mode(port);
- usb_mux_set_safe_mode(port);
- return 0;
- }
-
- if (sop == TCPCI_MSG_SOP_PRIME)
- limit_tbt_cable_speed(port);
- else
- disable_tbt_compat_mode(port);
- } else if (sop == TCPCI_MSG_SOP) {
- *rtype = TCPCI_MSG_SOP_PRIME;
- return dfp_discover_svids(payload);
- }
- }
-
return dfp_discover_modes(port, payload);
}
-
-static int process_tbt_compat_discover_modes(int port,
- enum tcpci_msg_type sop,
- uint32_t *payload,
- enum tcpci_msg_type *rtype)
-{
- int rsize;
-
- /* Initialize transmit type to SOP */
- *rtype = TCPCI_MSG_SOP;
-
- /*
- * For active cables, Enter mode: SOP', SOP'', SOP
- * Ref: USB Type-C Cable and Connector Specification, figure F-1: TBT3
- * Discovery Flow and Section F.2.7 TBT3 Cable Enter Mode Command.
- */
- if (sop == TCPCI_MSG_SOP_PRIME) {
- /* Store Discover Mode SOP' response */
- cable[port].cable_mode_resp.raw_value = payload[1];
-
- if (is_usb4_mode_enabled(port)) {
- /*
- * If Cable is not Thunderbolt Gen 3
- * capable or Thunderbolt Gen1_Gen2
- * capable, disable USB4 mode and
- * continue flow for
- * Thunderbolt-compatible mode
- */
- if (cable_supports_tbt_speed(port)) {
- enable_enter_usb4_mode(port);
- usb_mux_set_safe_mode(port);
- return 0;
- }
- disable_usb4_mode(port);
- }
-
- /*
- * Send TBT3 Cable Enter Mode (SOP') for active cables,
- * otherwise send TBT3 Device Enter Mode (SOP).
- */
- if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE)
- *rtype = TCPCI_MSG_SOP_PRIME;
-
- rsize = enter_tbt_compat_mode(port, *rtype, payload);
- } else {
- /* Store Discover Mode SOP response */
- cable[port].dev_mode_resp.raw_value = payload[1];
-
- if (is_limit_tbt_cable_speed(port)) {
- /*
- * Passive cable has Nacked for Discover SVID.
- * No need to do Discover modes of cable.
- * Enter into device Thunderbolt-compatible mode.
- */
- rsize = enter_tbt_compat_mode(port, *rtype, payload);
- } else {
- /* Discover modes for SOP' */
- discovery[port][TCPCI_MSG_SOP].svid_idx--;
- rsize = dfp_discover_modes(port, payload);
- *rtype = TCPCI_MSG_SOP_PRIME;
- }
- }
-
- return rsize;
-}
-
-static int obj_cnt_enter_tbt_compat_mode(int port, enum tcpci_msg_type sop,
- uint32_t *payload,
- enum tcpci_msg_type *rtype)
-{
- struct pd_discovery *disc = &discovery[port][TCPCI_MSG_SOP_PRIME];
-
- /* Enter mode SOP' for active cables */
- if (sop == TCPCI_MSG_SOP_PRIME) {
- /* Check if the cable has a SOP'' controller */
- if (disc->identity.product_t1.a_rev20.sop_p_p)
- *rtype = TCPCI_MSG_SOP_PRIME_PRIME;
- return enter_tbt_compat_mode(port, *rtype, payload);
- }
-
- /* Enter Mode SOP'' for active cables with SOP'' controller */
- if (sop == TCPCI_MSG_SOP_PRIME_PRIME)
- return enter_tbt_compat_mode(port, *rtype, payload);
-
- /* Update Mux state to Thunderbolt-compatible mode. */
- set_tbt_compat_mode_ready(port);
- /* No response once device (and cable) acks */
- return 0;
-}
#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
@@ -725,15 +280,9 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
switch (cmd) {
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
case CMD_DISCOVER_IDENT:
- /* Received a SOP' Discover Ident msg */
- if (sop == TCPCI_MSG_SOP_PRIME) {
- rsize = process_am_discover_ident_sop_prime(
- port, cnt, head, payload);
- /* Received a SOP Discover Ident Message */
- } else {
- rsize = process_am_discover_ident_sop(
- port, cnt, head, payload, rtype);
- }
+ /* Received a SOP Discover Ident Message */
+ rsize = process_am_discover_ident_sop(port, cnt, head,
+ payload, rtype);
break;
case CMD_DISCOVER_SVID:
rsize = process_am_discover_svids(port, cnt, payload,
@@ -741,22 +290,10 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
break;
case CMD_DISCOVER_MODES:
dfp_consume_modes(port, sop, cnt, payload);
- if (is_tbt_compat_enabled(port) &&
- is_tbt_compat_mode(port, cnt, payload)) {
- rsize = process_tbt_compat_discover_modes(
- port, sop, payload, rtype);
- break;
- }
rsize = dfp_discover_modes(port, payload);
/* enter the default mode for DFP */
if (!rsize) {
- /*
- * Disabling Thunderbolt-Compatible mode if
- * discover mode response doesn't include Intel
- * SVID.
- */
- disable_tbt_compat_mode(port);
payload[0] = pd_dfp_enter_mode(
port, TCPCI_MSG_SOP, 0, 0);
if (payload[0])
@@ -764,19 +301,12 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
}
break;
case CMD_ENTER_MODE:
- if (is_tbt_compat_enabled(port)) {
- rsize = obj_cnt_enter_tbt_compat_mode(
- port, sop, payload, rtype);
- /*
- * Continue with PD flow if
- * Thunderbolt-compatible mode is disabled.
- */
- } else if (!modep) {
+ if (!modep) {
rsize = 0;
} else {
if (!modep->opos)
pd_dfp_enter_mode(port, TCPCI_MSG_SOP,
- 0, 0);
+ 0, 0);
if (modep->opos) {
rsize = modep->fx->status(port,
@@ -805,7 +335,7 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
* config ack).
*/
if (svdm_dp_get_mux_mode(port) ==
- USB_PD_MUX_DP_ENABLED)
+ USB_PD_MUX_DP_ENABLED)
usb_mux_set_safe_mode(port);
rsize = modep->fx->config(port, payload);
} else {
@@ -856,15 +386,7 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload,
rsize = 0;
}
} else if (cmd_type == CMDT_RSP_NAK) {
- /* Passive cable Nacked for Discover SVID */
- if (cmd == CMD_DISCOVER_SVID && is_tbt_compat_enabled(port) &&
- sop == TCPCI_MSG_SOP_PRIME &&
- get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE) {
- limit_tbt_cable_speed(port);
- rsize = dfp_discover_modes(port, payload);
- } else {
- rsize = 0;
- }
+ rsize = 0;
#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
} else {
CPRINTF("ERR:CMDT:%d\n", cmd);
@@ -952,7 +474,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload)
flash_offset =
CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF;
crec_flash_physical_erase(CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_STORAGE_OFF,
+ CONFIG_RW_STORAGE_OFF,
CONFIG_RW_SIZE);
rw_flash_changed = 1;
break;
@@ -963,7 +485,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload)
CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF))
break;
crec_flash_physical_write(flash_offset, 4 * (cnt - 1),
- (const char *)(payload + 1));
+ (const char *)(payload + 1));
flash_offset += 4 * (cnt - 1);
rw_flash_changed = 1;
break;
@@ -976,7 +498,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload)
for (offset = FW_RW_END - RSANUMBYTES;
offset < FW_RW_END; offset += 4)
crec_flash_physical_write(offset, 4,
- (const char *)&zero);
+ (const char *)&zero);
}
break;
default:
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 3f0408eedf..80d3b400da 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,6 +7,7 @@
#include "battery.h"
#include "battery_smart.h"
#include "board.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "chipset.h"
@@ -38,27 +39,19 @@
#include "vboot.h"
/* Flags to clear on a disconnect */
-#define PD_FLAGS_RESET_ON_DISCONNECT_MASK (PD_FLAGS_PARTNER_DR_POWER | \
- PD_FLAGS_PARTNER_DR_DATA | \
- PD_FLAGS_CHECK_IDENTITY | \
- PD_FLAGS_SNK_CAP_RECVD | \
- PD_FLAGS_TCPC_DRP_TOGGLE | \
- PD_FLAGS_EXPLICIT_CONTRACT | \
- PD_FLAGS_PREVIOUS_PD_CONN | \
- PD_FLAGS_CHECK_PR_ROLE | \
- PD_FLAGS_CHECK_DR_ROLE | \
- PD_FLAGS_PARTNER_UNCONSTR | \
- PD_FLAGS_VCONN_ON | \
- PD_FLAGS_TRY_SRC | \
- PD_FLAGS_PARTNER_USB_COMM | \
- PD_FLAGS_UPDATE_SRC_CAPS | \
- PD_FLAGS_TS_DTS_PARTNER | \
- PD_FLAGS_SNK_WAITING_BATT | \
- PD_FLAGS_CHECK_VCONN_STATE)
+#define PD_FLAGS_RESET_ON_DISCONNECT_MASK \
+ (PD_FLAGS_PARTNER_DR_POWER | PD_FLAGS_PARTNER_DR_DATA | \
+ PD_FLAGS_CHECK_IDENTITY | PD_FLAGS_SNK_CAP_RECVD | \
+ PD_FLAGS_TCPC_DRP_TOGGLE | PD_FLAGS_EXPLICIT_CONTRACT | \
+ PD_FLAGS_PREVIOUS_PD_CONN | PD_FLAGS_CHECK_PR_ROLE | \
+ PD_FLAGS_CHECK_DR_ROLE | PD_FLAGS_PARTNER_UNCONSTR | \
+ PD_FLAGS_VCONN_ON | PD_FLAGS_TRY_SRC | PD_FLAGS_PARTNER_USB_COMM | \
+ PD_FLAGS_UPDATE_SRC_CAPS | PD_FLAGS_TS_DTS_PARTNER | \
+ PD_FLAGS_SNK_WAITING_BATT | PD_FLAGS_CHECK_VCONN_STATE)
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
static int tcpc_prints(const char *string, int port)
{
@@ -105,11 +98,11 @@ static const int debug_level;
#define DUAL_ROLE_IF_ELSE(port, sink_clause, src_clause) (src_clause)
#endif
-#define READY_RETURN_STATE(port) DUAL_ROLE_IF_ELSE(port, PD_STATE_SNK_READY, \
- PD_STATE_SRC_READY)
+#define READY_RETURN_STATE(port) \
+ DUAL_ROLE_IF_ELSE(port, PD_STATE_SNK_READY, PD_STATE_SRC_READY)
/* Type C supply voltage (mV) */
-#define TYPE_C_VOLTAGE 5000 /* mV */
+#define TYPE_C_VOLTAGE 5000 /* mV */
/* PD counter definitions */
#define PD_MESSAGE_ID_COUNT 7
@@ -153,8 +146,9 @@ enum vdm_states {
#ifdef CONFIG_USB_PD_DUAL_ROLE
/* Port dual-role state */
enum pd_dual_role_states drp_state[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- [0 ... (CONFIG_USB_PD_PORT_MAX_COUNT - 1)] =
- CONFIG_USB_PD_INITIAL_DRP_STATE};
+ [0 ...(CONFIG_USB_PD_PORT_MAX_COUNT - 1)] =
+ CONFIG_USB_PD_INITIAL_DRP_STATE
+};
/* Enable variable for Try.SRC states */
static bool pd_try_src_enable;
@@ -183,8 +177,7 @@ static bool pd_try_src_enable;
* Rev 1 (VDO 1.0) - return VDM_VER10
* Rev 2 (VDO 2.0) - return VDM_VER20
*/
-static const uint8_t vdo_ver[] = {
- VDM_VER10, VDM_VER10, VDM_VER20};
+static const uint8_t vdo_ver[] = { VDM_VER10, VDM_VER10, VDM_VER20 };
#define VDO_VER(v) vdo_ver[v]
#else
#define VDO_VER(v) VDM_VER10
@@ -277,7 +270,7 @@ static struct pd_protocol {
/* Attached ChromeOS device id, RW hash, and current RO / RW image */
uint16_t dev_id;
- uint32_t dev_rw_hash[PD_RW_HASH_SIZE/4];
+ uint32_t dev_rw_hash[PD_RW_HASH_SIZE / 4];
enum ec_image current_image;
#ifdef CONFIG_USB_PD_REV30
/* protocol revision */
@@ -298,24 +291,46 @@ static struct pd_protocol {
} pd[CONFIG_USB_PD_PORT_MAX_COUNT];
#ifdef CONFIG_USB_PD_TCPMV1_DEBUG
-static const char * const pd_state_names[] = {
- "DISABLED", "SUSPENDED",
- "SNK_DISCONNECTED", "SNK_DISCONNECTED_DEBOUNCE",
+static const char *const pd_state_names[] = {
+ "DISABLED",
+ "SUSPENDED",
+ "SNK_DISCONNECTED",
+ "SNK_DISCONNECTED_DEBOUNCE",
"SNK_HARD_RESET_RECOVER",
- "SNK_DISCOVERY", "SNK_REQUESTED", "SNK_TRANSITION", "SNK_READY",
- "SNK_SWAP_INIT", "SNK_SWAP_SNK_DISABLE",
- "SNK_SWAP_SRC_DISABLE", "SNK_SWAP_STANDBY", "SNK_SWAP_COMPLETE",
- "SRC_DISCONNECTED", "SRC_DISCONNECTED_DEBOUNCE",
- "SRC_HARD_RESET_RECOVER", "SRC_STARTUP",
- "SRC_DISCOVERY", "SRC_NEGOCIATE", "SRC_ACCEPTED", "SRC_POWERED",
- "SRC_TRANSITION", "SRC_READY", "SRC_GET_SNK_CAP", "DR_SWAP",
- "SRC_SWAP_INIT", "SRC_SWAP_SNK_DISABLE", "SRC_SWAP_SRC_DISABLE",
+ "SNK_DISCOVERY",
+ "SNK_REQUESTED",
+ "SNK_TRANSITION",
+ "SNK_READY",
+ "SNK_SWAP_INIT",
+ "SNK_SWAP_SNK_DISABLE",
+ "SNK_SWAP_SRC_DISABLE",
+ "SNK_SWAP_STANDBY",
+ "SNK_SWAP_COMPLETE",
+ "SRC_DISCONNECTED",
+ "SRC_DISCONNECTED_DEBOUNCE",
+ "SRC_HARD_RESET_RECOVER",
+ "SRC_STARTUP",
+ "SRC_DISCOVERY",
+ "SRC_NEGOCIATE",
+ "SRC_ACCEPTED",
+ "SRC_POWERED",
+ "SRC_TRANSITION",
+ "SRC_READY",
+ "SRC_GET_SNK_CAP",
+ "DR_SWAP",
+ "SRC_SWAP_INIT",
+ "SRC_SWAP_SNK_DISABLE",
+ "SRC_SWAP_SRC_DISABLE",
"SRC_SWAP_STANDBY",
- "VCONN_SWAP_SEND", "VCONN_SWAP_INIT", "VCONN_SWAP_READY",
- "SOFT_RESET", "HARD_RESET_SEND", "HARD_RESET_EXECUTE", "BIST_RX",
+ "VCONN_SWAP_SEND",
+ "VCONN_SWAP_INIT",
+ "VCONN_SWAP_READY",
+ "SOFT_RESET",
+ "HARD_RESET_SEND",
+ "HARD_RESET_EXECUTE",
+ "BIST_RX",
"BIST_TX",
"DRP_AUTO_TOGGLE",
- "ENTER_USB",
};
BUILD_ASSERT(ARRAY_SIZE(pd_state_names) == PD_STATE_COUNT);
#endif
@@ -336,11 +351,10 @@ bool pd_alt_mode_capable(int port)
* the port is not suspended.
*/
return pd_comm_is_enabled(port) &&
- !(pd[port].task_state == PD_STATE_SUSPENDED);
+ !(pd[port].task_state == PD_STATE_SUSPENDED);
}
-static inline void set_state_timeout(int port,
- uint64_t timeout,
+static inline void set_state_timeout(int port, uint64_t timeout,
enum pd_states timeout_state)
{
pd[port].timeout = timeout;
@@ -353,9 +367,6 @@ int pd_get_rev(int port, enum tcpci_msg_type type)
/* TCPMv1 Only stores PD revision for SOP and SOP' types */
ASSERT(type < NUM_SOP_STAR_TYPES - 1);
- if (type == TCPCI_MSG_SOP_PRIME)
- return get_usb_pd_cable_revision(port);
-
return pd[port].rev;
#else
return PD_REV20;
@@ -365,9 +376,6 @@ int pd_get_rev(int port, enum tcpci_msg_type type)
int pd_get_vdo_ver(int port, enum tcpci_msg_type type)
{
#ifdef CONFIG_USB_PD_REV30
- if (type == TCPCI_MSG_SOP_PRIME)
- return vdo_ver[get_usb_pd_cable_revision(port)];
-
return vdo_ver[pd[port].rev];
#else
return VDM_VER10;
@@ -385,13 +393,16 @@ int pd_is_connected(int port)
return 0;
#endif
- return DUAL_ROLE_IF_ELSE(port,
+ return DUAL_ROLE_IF_ELSE(
+ port,
/* sink */
pd[port].task_state != PD_STATE_SNK_DISCONNECTED &&
- pd[port].task_state != PD_STATE_SNK_DISCONNECTED_DEBOUNCE,
+ pd[port].task_state !=
+ PD_STATE_SNK_DISCONNECTED_DEBOUNCE,
/* source */
pd[port].task_state != PD_STATE_SRC_DISCONNECTED &&
- pd[port].task_state != PD_STATE_SRC_DISCONNECTED_DEBOUNCE);
+ pd[port].task_state !=
+ PD_STATE_SRC_DISCONNECTED_DEBOUNCE);
}
/* Return true if partner port is known to be PD capable. */
@@ -425,7 +436,6 @@ void pd_vbus_low(int port)
}
#endif
-
#ifdef CONFIG_USBC_VCONN
static void set_vconn(int port, int enable)
{
@@ -485,12 +495,12 @@ static void handle_device_access(int port)
pd[port].low_power_time = get_time().val + PD_LPM_DEBOUNCE_US;
if (pd[port].flags & PD_FLAGS_LPM_ENGAGED) {
tcpc_prints("Exit Low Power Mode", port);
- pd[port].flags &= ~(PD_FLAGS_LPM_ENGAGED |
- PD_FLAGS_LPM_REQUESTED);
+ pd[port].flags &=
+ ~(PD_FLAGS_LPM_ENGAGED | PD_FLAGS_LPM_REQUESTED);
pd[port].flags |= PD_FLAGS_LPM_EXIT;
- pd[port].low_power_exit_time = get_time().val
- + PD_LPM_EXIT_DEBOUNCE_US;
+ pd[port].low_power_exit_time =
+ get_time().val + PD_LPM_EXIT_DEBOUNCE_US;
/*
* Wake to ensure we make another pass through the main task
* loop after clearing the flags.
@@ -675,28 +685,18 @@ static bool consume_sop_repeat_message(int port, uint8_t msg_id)
* @param port USB PD TCPC port number
* @param msg_header Message Header containing the RX message ID
* @return True if the received message is a duplicate one, False otherwise.
- *
- * From USB PD version 1.3 section 6.7.1, the port which communicates
- * using SOP* Packets Shall maintain copies of the last MessageID for
- * each type of SOP* it uses.
*/
static bool consume_repeat_message(int port, uint32_t msg_header)
{
uint8_t msg_id = PD_HEADER_ID(msg_header);
- enum tcpci_msg_type sop = PD_HEADER_GET_SOP(msg_header);
/* If repeat message ignore, except softreset control request. */
if (PD_HEADER_TYPE(msg_header) == PD_CTRL_SOFT_RESET &&
PD_HEADER_CNT(msg_header) == 0) {
return false;
- } else if (sop == TCPCI_MSG_SOP_PRIME) {
- return consume_sop_prime_repeat_msg(port, msg_id);
- } else if (sop == TCPCI_MSG_SOP_PRIME_PRIME) {
- return consume_sop_prime_prime_repeat_msg(port, msg_id);
} else {
return consume_sop_repeat_message(port, msg_id);
}
-
}
/**
@@ -791,15 +791,13 @@ static inline void set_state(int port, enum pd_states next_state)
if (last_state != PD_STATE_SNK_DISCONNECTED_DEBOUNCE &&
last_state != PD_STATE_SRC_DISCONNECTED_DEBOUNCE) {
pd[port].flags &= ~PD_FLAGS_RESET_ON_DISCONNECT_MASK;
- reset_pd_cable(port);
}
/* Clear the input current limit */
pd_set_input_current_limit(port, 0, 0);
#ifdef CONFIG_CHARGE_MANAGER
typec_set_input_current_limit(port, 0, 0);
- charge_manager_set_ceil(port,
- CEIL_REQUESTOR_PD,
+ charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
CHARGE_CEIL_NONE);
#endif
#ifdef CONFIG_BC12_DETECT_DATA_ROLE_TRIGGER
@@ -868,7 +866,7 @@ static inline void set_state(int port, enum pd_states next_state)
/* Upon entering SRC_READY, it is safe for the sink to transmit */
if (next_state == PD_STATE_SRC_READY) {
if (pd[port].rev == PD_REV30 &&
- pd[port].flags & PD_FLAGS_EXPLICIT_CONTRACT)
+ pd[port].flags & PD_FLAGS_EXPLICIT_CONTRACT)
sink_can_xmit(port, SINK_TX_OK);
}
#endif
@@ -888,7 +886,7 @@ static inline void set_state(int port, enum pd_states next_state)
#ifdef CONFIG_USB_PD_TCPMV1_DEBUG
if (debug_level > 0)
CPRINTF("C%d st%d %s\n", port, next_state,
- pd_state_names[next_state]);
+ pd_state_names[next_state]);
else
#endif
CPRINTF("C%d st%d\n", port, next_state);
@@ -909,8 +907,8 @@ void pd_transmit_complete(int port, int status)
task_set_event(PD_PORT_TO_TASK_ID(port), PD_EVENT_TX);
}
-static int pd_transmit(int port, enum tcpci_msg_type type,
- uint16_t header, const uint32_t *data, enum ams_seq ams)
+static int pd_transmit(int port, enum tcpci_msg_type type, uint16_t header,
+ const uint32_t *data, enum ams_seq ams)
{
int evt;
int res;
@@ -922,9 +920,9 @@ static int pd_transmit(int port, enum tcpci_msg_type type,
if (!pd_comm_is_enabled(port))
return -1;
- /* Don't try to transmit anything until we have processed
- * all RX messages.
- */
+ /* Don't try to transmit anything until we have processed
+ * all RX messages.
+ */
if (tcpm_has_pending_message(port))
return -1;
@@ -951,7 +949,7 @@ static int pd_transmit(int port, enum tcpci_msg_type type,
* Note: a Sink can still send Hard Reset signaling at any time.
*/
if ((pd[port].rev == PD_REV30) && ams == AMS_START &&
- (pd[port].flags & PD_FLAGS_EXPLICIT_CONTRACT)) {
+ (pd[port].flags & PD_FLAGS_EXPLICIT_CONTRACT)) {
if (pd[port].power_role == PD_ROLE_SOURCE) {
/*
* Inform Sink that it can't transmit. If a sink
@@ -967,7 +965,7 @@ static int pd_transmit(int port, enum tcpci_msg_type type,
tcpm_get_cc(port, &cc1, &cc2);
if (cc1 == TYPEC_CC_VOLT_RP_1_5 ||
- cc2 == TYPEC_CC_VOLT_RP_1_5) {
+ cc2 == TYPEC_CC_VOLT_RP_1_5) {
/* Sink can't transmit now. */
/* Return failure, pd_task can retry later */
return -1;
@@ -1004,15 +1002,15 @@ static int send_control(int port, int type)
{
int bit_len;
uint16_t header = PD_HEADER(type, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id, 0,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ pd[port].data_role, pd[port].msg_id, 0,
+ pd_get_rev(port, TCPCI_MSG_SOP), 0);
/*
* For PD 3.0, collision avoidance logic needs to know if this message
* will begin a new Atomic Message Sequence (AMS)
*/
- enum ams_seq ams = ((1 << type) & PD_CTRL_AMS_START_MASK)
- ? AMS_START : AMS_RESPONSE;
-
+ enum ams_seq ams = ((1 << type) & PD_CTRL_AMS_START_MASK) ?
+ AMS_START :
+ AMS_RESPONSE;
bit_len = pd_transmit(port, TCPCI_MSG_SOP, header, NULL, ams);
if (debug_level >= 2)
@@ -1030,7 +1028,7 @@ static int send_source_cap(int port, enum ams_seq ams)
{
int bit_len;
#if defined(CONFIG_USB_PD_DYNAMIC_SRC_CAP) || \
- defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
+ defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
const uint32_t *src_pdo;
const int src_pdo_cnt = charge_manager_get_source_pdo(&src_pdo, port);
#else
@@ -1042,12 +1040,13 @@ static int send_source_cap(int port, enum ams_seq ams)
if (src_pdo_cnt == 0)
/* No source capabilities defined, sink only */
header = PD_HEADER(PD_CTRL_REJECT, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id, 0,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ pd[port].data_role, pd[port].msg_id, 0,
+ pd_get_rev(port, TCPCI_MSG_SOP), 0);
else
header = PD_HEADER(PD_DATA_SOURCE_CAP, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id, src_pdo_cnt,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ pd[port].data_role, pd[port].msg_id,
+ src_pdo_cnt, pd_get_rev(port, TCPCI_MSG_SOP),
+ 0);
bit_len = pd_transmit(port, TCPCI_MSG_SOP, header, src_pdo, ams);
if (debug_level >= 2)
@@ -1060,21 +1059,19 @@ static int send_source_cap(int port, enum ams_seq ams)
static int send_battery_cap(int port, uint32_t *payload)
{
int bit_len;
- uint16_t msg[6] = {0, 0, 0, 0, 0, 0};
- uint16_t header = PD_HEADER(PD_EXT_BATTERY_CAP,
- pd[port].power_role,
- pd[port].data_role,
- pd[port].msg_id,
+ uint16_t msg[6] = { 0, 0, 0, 0, 0, 0 };
+ uint16_t header = PD_HEADER(PD_EXT_BATTERY_CAP, pd[port].power_role,
+ pd[port].data_role, pd[port].msg_id,
3, /* Number of Data Objects */
- pd[port].rev,
- 1 /* This is an exteded message */
- );
+ pd[port].rev, 1 /* This is an exteded
+ message */
+ );
/* Set extended header */
msg[0] = PD_EXT_HEADER(0, /* Chunk Number */
0, /* Request Chunk */
- 9 /* Data Size in bytes */
- );
+ 9 /* Data Size in bytes */
+ );
/* Set VID */
msg[1] = USB_VID_GOOGLE;
@@ -1121,7 +1118,7 @@ static int send_battery_cap(int port, uint32_t *payload)
* 10th of a Wh = Wh * 10
*/
msg[3] = DIV_ROUND_NEAREST((c * v),
- 100000);
+ 100000);
}
if (battery_full_charge_capacity(&c) == 0) {
@@ -1130,7 +1127,7 @@ static int send_battery_cap(int port, uint32_t *payload)
* 10th of a Wh = Wh * 10
*/
msg[4] = DIV_ROUND_NEAREST((c * v),
- 100000);
+ 100000);
}
}
}
@@ -1143,18 +1140,16 @@ static int send_battery_cap(int port, uint32_t *payload)
return bit_len;
}
-static int send_battery_status(int port, uint32_t *payload)
+static int send_battery_status(int port, uint32_t *payload)
{
int bit_len;
uint32_t msg = 0;
- uint16_t header = PD_HEADER(PD_DATA_BATTERY_STATUS,
- pd[port].power_role,
- pd[port].data_role,
- pd[port].msg_id,
+ uint16_t header = PD_HEADER(PD_DATA_BATTERY_STATUS, pd[port].power_role,
+ pd[port].data_role, pd[port].msg_id,
1, /* Number of Data Objects */
- pd[port].rev,
- 0 /* This is NOT an extended message */
- );
+ pd[port].rev, 0 /* This is NOT an extended
+ message */
+ );
if (battery_is_present()) {
/*
@@ -1169,15 +1164,15 @@ static int send_battery_status(int port, uint32_t *payload)
uint32_t c;
if (battery_design_voltage(&v) != 0 ||
- battery_remaining_capacity(&c) != 0) {
+ battery_remaining_capacity(&c) != 0) {
msg |= BSDO_CAP(BSDO_CAP_UNKNOWN);
} else {
/*
* Wh = (c * v) / 1000000
* 10th of a Wh = Wh * 10
*/
- msg |= BSDO_CAP(DIV_ROUND_NEAREST((c * v),
- 100000));
+ msg |= BSDO_CAP(
+ DIV_ROUND_NEAREST((c * v), 100000));
}
/* Battery is present */
@@ -1217,8 +1212,9 @@ static void send_sink_cap(int port)
{
int bit_len;
uint16_t header = PD_HEADER(PD_DATA_SINK_CAP, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id, pd_snk_pdo_cnt,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ pd[port].data_role, pd[port].msg_id,
+ pd_snk_pdo_cnt,
+ pd_get_rev(port, TCPCI_MSG_SOP), 0);
bit_len = pd_transmit(port, TCPCI_MSG_SOP, header, pd_snk_pdo,
AMS_RESPONSE);
@@ -1230,8 +1226,8 @@ static int send_request(int port, uint32_t rdo)
{
int bit_len;
uint16_t header = PD_HEADER(PD_DATA_REQUEST, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id, 1,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ pd[port].data_role, pd[port].msg_id, 1,
+ pd_get_rev(port, TCPCI_MSG_SOP), 0);
/* Note: ams will need to be AMS_START if used for PPS keep alive */
bit_len = pd_transmit(port, TCPCI_MSG_SOP, header, &rdo, AMS_RESPONSE);
@@ -1250,8 +1246,8 @@ static int send_bist_cmd(int port)
uint32_t bdo = BDO(BDO_MODE_CARRIER2, 0);
int bit_len;
uint16_t header = PD_HEADER(PD_DATA_BIST, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id, 1,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ pd[port].data_role, pd[port].msg_id, 1,
+ pd_get_rev(port, TCPCI_MSG_SOP), 0);
bit_len = pd_transmit(port, TCPCI_MSG_SOP, header, &bdo, AMS_START);
CPRINTF("C%d BIST>%d\n", port, bit_len);
@@ -1261,19 +1257,18 @@ static int send_bist_cmd(int port)
#endif
static void queue_vdm(int port, uint32_t *header, const uint32_t *data,
- int data_cnt, enum tcpci_msg_type type)
+ int data_cnt, enum tcpci_msg_type type)
{
pd[port].vdo_count = data_cnt + 1;
pd[port].vdo_data[0] = header[0];
pd[port].xmit_type = type;
- memcpy(&pd[port].vdo_data[1], data,
- sizeof(uint32_t) * data_cnt);
+ memcpy(&pd[port].vdo_data[1], data, sizeof(uint32_t) * data_cnt);
/* Set ready, pd task will actually send */
pd[port].vdm_state = VDM_STATE_READY;
}
static void handle_vdm_request(int port, int cnt, uint32_t *payload,
- uint32_t head)
+ uint32_t head)
{
int rlen = 0;
uint32_t *rdata;
@@ -1282,11 +1277,11 @@ static void handle_vdm_request(int port, int cnt, uint32_t *payload,
if (pd[port].vdm_state == VDM_STATE_BUSY) {
/* If UFP responded busy retry after timeout */
if (PD_VDO_CMDT(payload[0]) == CMDT_RSP_BUSY) {
- pd[port].vdm_timeout.val = get_time().val +
- PD_T_VDM_BUSY;
+ pd[port].vdm_timeout.val =
+ get_time().val + PD_T_VDM_BUSY;
pd[port].vdm_state = VDM_STATE_WAIT_RSP_BUSY;
pd[port].vdo_retry = (payload[0] & ~VDO_CMDT_MASK) |
- CMDT_INIT;
+ CMDT_INIT;
return;
} else {
pd[port].vdm_state = VDM_STATE_DONE;
@@ -1310,8 +1305,8 @@ static void handle_vdm_request(int port, int cnt, uint32_t *payload,
}
if (debug_level >= 2)
- CPRINTF("C%d Unhandled VDM VID %04x CMD %04x\n",
- port, PD_VDO_VID(payload[0]), payload[0] & 0xFFFF);
+ CPRINTF("C%d Unhandled VDM VID %04x CMD %04x\n", port,
+ PD_VDO_VID(payload[0]), payload[0] & 0xFFFF);
}
bool pd_is_disconnected(int port)
@@ -1401,8 +1396,7 @@ void pd_execute_hard_reset(int port)
/* Clear the input current limit */
pd_set_input_current_limit(port, 0, 0);
#ifdef CONFIG_CHARGE_MANAGER
- charge_manager_set_ceil(port,
- CEIL_REQUESTOR_PD,
+ charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
CHARGE_CEIL_NONE);
#endif /* CONFIG_CHARGE_MANAGER */
@@ -1442,7 +1436,7 @@ static void execute_soft_reset(int port)
{
invalidate_last_message_id(port);
set_state(port, DUAL_ROLE_IF_ELSE(port, PD_STATE_SNK_DISCOVERY,
- PD_STATE_SRC_DISCOVERY));
+ PD_STATE_SRC_DISCOVERY));
CPRINTF("C%d Soft Rst\n", port);
}
@@ -1484,8 +1478,8 @@ static int pd_send_request_msg(int port, int always_send_request)
#endif
}
- CPRINTF("C%d Req [%d] %dmV %dmA", port, RDO_POS(rdo),
- supply_voltage, curr_limit);
+ CPRINTF("C%d Req [%d] %dmV %dmA", port, RDO_POS(rdo), supply_voltage,
+ curr_limit);
if (rdo & RDO_CAP_MISMATCH)
CPRINTF(" Mismatch");
CPRINTF("\n");
@@ -1543,8 +1537,7 @@ static void pd_update_pdo_flags(int port, int pdo_cnt, uint32_t *pdos)
* Get max power that the partner offers (not necessarily what
* this board will request)
*/
- pd_find_pdo_index(pdo_cnt, pdos, PD_REV3_MAX_VOLTAGE,
- &max_pdo);
+ pd_find_pdo_index(pdo_cnt, pdos, PD_REV3_MAX_VOLTAGE, &max_pdo);
pd_extract_pdo_power(max_pdo, &max_ma, &max_mv, &unused);
max_mw = max_ma * max_mv / 1000;
@@ -1557,8 +1550,7 @@ static void pd_update_pdo_flags(int port, int pdo_cnt, uint32_t *pdos)
}
}
-static void handle_data_request(int port, uint32_t head,
- uint32_t *payload)
+static void handle_data_request(int port, uint32_t head, uint32_t *payload)
{
int type = PD_HEADER_TYPE(head);
int cnt = PD_HEADER_CNT(head);
@@ -1566,14 +1558,12 @@ static void handle_data_request(int port, uint32_t head,
switch (type) {
#ifdef CONFIG_USB_PD_DUAL_ROLE
case PD_DATA_SOURCE_CAP:
- if ((pd[port].task_state == PD_STATE_SNK_DISCOVERY)
- || (pd[port].task_state == PD_STATE_SNK_TRANSITION)
- || (pd[port].task_state == PD_STATE_SNK_REQUESTED)
- || ((get_usb_pd_vbus_detect() ==
- USB_PD_VBUS_DETECT_NONE)
- && (pd[port].task_state ==
- PD_STATE_SNK_HARD_RESET_RECOVER))
- || (pd[port].task_state == PD_STATE_SNK_READY)) {
+ if ((pd[port].task_state == PD_STATE_SNK_DISCOVERY) ||
+ (pd[port].task_state == PD_STATE_SNK_TRANSITION) ||
+ (pd[port].task_state == PD_STATE_SNK_REQUESTED) ||
+ ((get_usb_pd_vbus_detect() == USB_PD_VBUS_DETECT_NONE) &&
+ (pd[port].task_state == PD_STATE_SNK_HARD_RESET_RECOVER)) ||
+ (pd[port].task_state == PD_STATE_SNK_READY)) {
#ifdef CONFIG_USB_PD_REV30
/*
* Only adjust sink rev if source rev is higher.
@@ -1630,18 +1620,20 @@ static void handle_data_request(int port, uint32_t head,
break;
case PD_DATA_BIST:
/* If not in READY state, then don't start BIST */
- if (DUAL_ROLE_IF_ELSE(port,
- pd[port].task_state == PD_STATE_SNK_READY,
- pd[port].task_state == PD_STATE_SRC_READY)) {
+ if (DUAL_ROLE_IF_ELSE(
+ port, pd[port].task_state == PD_STATE_SNK_READY,
+ pd[port].task_state == PD_STATE_SRC_READY)) {
/* currently only support sending bist carrier mode 2 */
if ((payload[0] >> 28) == 5) {
/* bist data object mode is 2 */
pd_transmit(port, TCPCI_MSG_TX_BIST_MODE_2, 0,
NULL, AMS_RESPONSE);
/* Set to appropriate port disconnected state */
- set_state(port, DUAL_ROLE_IF_ELSE(port,
- PD_STATE_SNK_DISCONNECTED,
- PD_STATE_SRC_DISCONNECTED));
+ set_state(port,
+ DUAL_ROLE_IF_ELSE(
+ port,
+ PD_STATE_SNK_DISCONNECTED,
+ PD_STATE_SRC_DISCONNECTED));
}
}
break;
@@ -1655,12 +1647,6 @@ static void handle_data_request(int port, uint32_t head,
#ifdef CONFIG_USB_PD_REV30
case PD_DATA_BATTERY_STATUS:
break;
- /* TODO : Add case PD_DATA_RESET for exiting USB4 */
-
- /*
- * TODO : Add case PD_DATA_ENTER_USB to accept or reject
- * Enter_USB request from port partner.
- */
#endif
case PD_DATA_VENDOR_DEF:
handle_vdm_request(port, cnt, payload, head);
@@ -1705,9 +1691,8 @@ void pd_try_vconn_src(int port)
void pd_request_data_swap(int port)
{
- if (DUAL_ROLE_IF_ELSE(port,
- pd[port].task_state == PD_STATE_SNK_READY,
- pd[port].task_state == PD_STATE_SRC_READY))
+ if (DUAL_ROLE_IF_ELSE(port, pd[port].task_state == PD_STATE_SNK_READY,
+ pd[port].task_state == PD_STATE_SRC_READY))
set_state(port, PD_STATE_DR_SWAP);
task_wake(PD_PORT_TO_TASK_ID(port));
}
@@ -1726,8 +1711,7 @@ static void pd_dr_swap(int port)
pd[port].flags |= PD_FLAGS_CHECK_IDENTITY;
}
-static void handle_ctrl_request(int port, uint32_t head,
- uint32_t *payload)
+static void handle_ctrl_request(int port, uint32_t head, uint32_t *payload)
{
int type = PD_HEADER_TYPE(head);
int res;
@@ -1768,7 +1752,7 @@ static void handle_ctrl_request(int port, uint32_t head,
* later time.
*/
pd_snk_give_back(port, &pd[port].curr_limit,
- &pd[port].supply_voltage);
+ &pd[port].supply_voltage);
set_state(port, PD_STATE_SNK_TRANSITION);
}
#endif
@@ -1813,37 +1797,21 @@ static void handle_ctrl_request(int port, uint32_t head,
*/
if (pd[port].task_state == PD_STATE_SNK_TRANSITION)
pd[port].ready_state_holdoff_timer =
- get_time().val + SNK_READY_HOLD_OFF_US
- + (get_time().le.lo & 0xf) * 12 * MSEC;
+ get_time().val + SNK_READY_HOLD_OFF_US +
+ (get_time().le.lo & 0xf) * 12 * MSEC;
set_state(port, PD_STATE_SNK_READY);
pd_set_input_current_limit(port, pd[port].curr_limit,
pd[port].supply_voltage);
#ifdef CONFIG_CHARGE_MANAGER
/* Set ceiling based on what's negotiated */
- charge_manager_set_ceil(port,
- CEIL_REQUESTOR_PD,
+ charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
pd[port].curr_limit);
#endif
}
break;
#endif
case PD_CTRL_REJECT:
- if (pd[port].task_state == PD_STATE_ENTER_USB) {
- if (!IS_ENABLED(CONFIG_USBC_SS_MUX))
- break;
-
- /*
- * Since Enter USB sets the mux state to SAFE mode,
- * resetting the mux state back to USB mode on
- * recieveing a NACK.
- */
- usb_mux_set(port, USB_PD_MUX_USB_ENABLED,
- USB_SWITCH_CONNECT, pd[port].polarity);
-
- set_state(port, READY_RETURN_STATE(port));
- break;
- }
case PD_CTRL_WAIT:
if (pd[port].task_state == PD_STATE_DR_SWAP) {
if (type == PD_CTRL_WAIT) /* try again ... */
@@ -1898,28 +1866,15 @@ static void handle_ctrl_request(int port, uint32_t head,
const int in_contract =
pd[port].flags &
PD_FLAGS_EXPLICIT_CONTRACT;
- set_state(port,
- in_contract ? PD_STATE_SNK_READY
- : PD_STATE_SNK_DISCOVERY);
+ set_state(port, in_contract ?
+ PD_STATE_SNK_READY :
+ PD_STATE_SNK_DISCOVERY);
}
}
#endif
break;
case PD_CTRL_ACCEPT:
- if (pd[port].task_state == PD_STATE_ENTER_USB) {
- if (!IS_ENABLED(CONFIG_USBC_SS_MUX))
- break;
-
- /* Connect the SBU and USB lines to the connector */
- if (IS_ENABLED(CONFIG_USBC_PPC_SBU))
- ppc_set_sbu(port, 1);
-
- /* Set usb mux to USB4 mode */
- usb_mux_set(port, USB_PD_MUX_USB4_ENABLED,
- USB_SWITCH_CONNECT, pd[port].polarity);
-
- set_state(port, READY_RETURN_STATE(port));
- } else if (pd[port].task_state == PD_STATE_SOFT_RESET) {
+ if (pd[port].task_state == PD_STATE_SOFT_RESET) {
/*
* For the case that we sent soft reset in SNK_DISCOVERY
* on startup due to VBUS never low, clear the flag.
@@ -1939,23 +1894,20 @@ static void handle_ctrl_request(int port, uint32_t head,
} else if (pd[port].task_state == PD_STATE_SRC_SWAP_INIT) {
/* explicit contract goes away for power swap */
pd[port].flags &= ~PD_FLAGS_EXPLICIT_CONTRACT;
- pd_update_saved_port_flags(port,
- PD_BBRMFLG_EXPLICIT_CONTRACT,
- 0);
+ pd_update_saved_port_flags(
+ port, PD_BBRMFLG_EXPLICIT_CONTRACT, 0);
set_state(port, PD_STATE_SRC_SWAP_SNK_DISABLE);
} else if (pd[port].task_state == PD_STATE_SNK_SWAP_INIT) {
/* explicit contract goes away for power swap */
pd[port].flags &= ~PD_FLAGS_EXPLICIT_CONTRACT;
- pd_update_saved_port_flags(port,
- PD_BBRMFLG_EXPLICIT_CONTRACT,
- 0);
+ pd_update_saved_port_flags(
+ port, PD_BBRMFLG_EXPLICIT_CONTRACT, 0);
set_state(port, PD_STATE_SNK_SWAP_SNK_DISABLE);
} else if (pd[port].task_state == PD_STATE_SNK_REQUESTED) {
/* explicit contract is now in place */
pd[port].flags |= PD_FLAGS_EXPLICIT_CONTRACT;
- pd_update_saved_port_flags(port,
- PD_BBRMFLG_EXPLICIT_CONTRACT,
- 1);
+ pd_update_saved_port_flags(
+ port, PD_BBRMFLG_EXPLICIT_CONTRACT, 1);
set_state(port, PD_STATE_SNK_TRANSITION);
#endif
}
@@ -1976,9 +1928,9 @@ static void handle_ctrl_request(int port, uint32_t head,
*/
pd[port].flags &= ~PD_FLAGS_CHECK_PR_ROLE;
set_state(port,
- DUAL_ROLE_IF_ELSE(port,
- PD_STATE_SNK_SWAP_SNK_DISABLE,
- PD_STATE_SRC_SWAP_SNK_DISABLE));
+ DUAL_ROLE_IF_ELSE(
+ port, PD_STATE_SNK_SWAP_SNK_DISABLE,
+ PD_STATE_SRC_SWAP_SNK_DISABLE));
} else {
send_control(port, PD_CTRL_REJECT);
}
@@ -1998,7 +1950,6 @@ static void handle_ctrl_request(int port, uint32_t head,
pd_dr_swap(port);
} else {
send_control(port, PD_CTRL_REJECT);
-
}
break;
case PD_CTRL_VCONN_SWAP:
@@ -2045,8 +1996,7 @@ static void handle_ext_request(int port, uint16_t head, uint32_t *payload)
}
#endif
-static void handle_request(int port, uint32_t head,
- uint32_t *payload)
+static void handle_request(int port, uint32_t head, uint32_t *payload)
{
int cnt = PD_HEADER_CNT(head);
int data_role = PD_HEADER_DROLE(head);
@@ -2091,8 +2041,7 @@ static void handle_request(int port, uint32_t head,
TYPEC_CC_RP));
}
set_state(port,
- DUAL_ROLE_IF_ELSE(port,
- PD_STATE_SNK_DISCONNECTED,
+ DUAL_ROLE_IF_ELSE(port, PD_STATE_SNK_DISCONNECTED,
PD_STATE_SRC_DISCONNECTED));
return;
}
@@ -2119,8 +2068,11 @@ void pd_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data,
}
/* set VDM header with VID & CMD */
- pd[port].vdo_data[0] = VDO(vid, ((vid & USB_SID_PD) == USB_SID_PD) ?
- 1 : (PD_VDO_CMD(cmd) <= CMD_ATTENTION), cmd);
+ pd[port].vdo_data[0] = VDO(vid,
+ ((vid & USB_SID_PD) == USB_SID_PD) ?
+ 1 :
+ (PD_VDO_CMD(cmd) <= CMD_ATTENTION),
+ cmd);
#ifdef CONFIG_USB_PD_REV30
pd[port].vdo_data[0] |= VDO_SVDM_VERS(vdo_ver[pd[port].rev]);
#endif
@@ -2150,7 +2102,7 @@ static uint64_t vdm_get_ready_timeout(uint32_t vdm_hdr)
/* its not a structured VDM command */
if (!PD_VDO_SVDM(vdm_hdr))
- return 500*MSEC;
+ return 500 * MSEC;
switch (PD_VDO_CMDT(vdm_hdr)) {
case CMDT_INIT:
@@ -2169,50 +2121,10 @@ static uint64_t vdm_get_ready_timeout(uint32_t vdm_hdr)
return timeout;
}
-static void exit_tbt_mode_sop_prime(int port)
-{
- /* Exit Thunderbolt-Compatible mode SOP' */
- uint16_t header;
- int opos;
-
- if (!IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE))
- return;
-
- opos = pd_alt_mode(port, TCPCI_MSG_SOP, USB_VID_INTEL);
- if (opos <= 0)
- return;
-
- CPRINTS("C%d Cable exiting TBT Compat mode", port);
- /*
- * Note: TCPMv2 contemplates separate discovery structures for each SOP
- * type. TCPMv1 only uses one discovery structure, so all accesses
- * specify TCPCI_MSG_SOP.
- */
- if (pd_dfp_exit_mode(port, TCPCI_MSG_SOP, USB_VID_INTEL, opos))
- usb_mux_set_safe_mode(port);
- else
- return;
-
- header = PD_HEADER(PD_DATA_VENDOR_DEF, pd[port].power_role,
- pd[port].data_role, pd[port].msg_id,
- (int)pd[port].vdo_count,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
-
- pd[port].vdo_data[0] = VDO(USB_VID_INTEL, 1,
- CMD_EXIT_MODE | VDO_OPOS(opos));
-
- pd_transmit(port, TCPCI_MSG_SOP_PRIME, header, pd[port].vdo_data,
- AMS_START);
-
- usb_mux_set(port, USB_PD_MUX_USB_ENABLED, USB_SWITCH_CONNECT,
- polarity_rm_dts(pd_get_polarity(port)));
-}
-
static void pd_vdm_send_state_machine(int port)
{
int res;
uint16_t header;
- enum tcpci_msg_type msg_type = pd[port].xmit_type;
switch (pd[port].vdm_state) {
case VDM_STATE_READY:
@@ -2229,82 +2141,20 @@ static void pd_vdm_send_state_machine(int port)
if (pdo_busy(port))
break;
- /*
- * To communicate with the cable plug, an explicit contract
- * should be established, VCONN should be enabled and data role
- * that can communicate with the cable plug should be in place.
- * For USB3.0, UFP/DFP can communicate whereas in case of
- * USB2.0 only DFP can talk to the cable plug.
- *
- * For communication between USB2.0 UFP and cable plug,
- * data role swap takes place during source and sink
- * negotiation and in case of failure, a soft reset is issued.
- */
- if ((msg_type == TCPCI_MSG_SOP_PRIME) ||
- (msg_type == TCPCI_MSG_SOP_PRIME_PRIME)) {
- /* Prepare SOP'/SOP'' header and send VDM */
- header = PD_HEADER(
- PD_DATA_VENDOR_DEF,
- PD_PLUG_FROM_DFP_UFP,
- 0,
- pd[port].msg_id,
- (int)pd[port].vdo_count,
- pd_get_rev(port, TCPCI_MSG_SOP),
- 0);
- res = pd_transmit(port, msg_type, header,
- pd[port].vdo_data, AMS_START);
- /*
- * In the case of SOP', if there is no response from
- * the cable, it's a non-emark cable and therefore the
- * pd flow should continue irrespective of cable
- * response, sending discover_identity so the pd flow
- * remains intact.
- *
- * In the case of SOP'', if there is no response from
- * the cable, exit Thunderbolt-Compatible mode
- * discovery, reset the mux state since, the mux will
- * be set to a safe state before entering
- * Thunderbolt-Compatible mode and enter the default
- * mode.
- */
- if (res < 0) {
- header = PD_HEADER(PD_DATA_VENDOR_DEF,
- pd[port].power_role,
- pd[port].data_role,
- pd[port].msg_id,
- (int)pd[port].vdo_count,
- pd_get_rev
- (port, TCPCI_MSG_SOP),
- 0);
-
- if ((msg_type == TCPCI_MSG_SOP_PRIME_PRIME) &&
- IS_ENABLED(CONFIG_USBC_SS_MUX)) {
- exit_tbt_mode_sop_prime(port);
- } else if (msg_type == TCPCI_MSG_SOP_PRIME) {
- pd[port].vdo_data[0] = VDO(USB_SID_PD,
- 1, CMD_DISCOVER_SVID);
- }
- res = pd_transmit(port, TCPCI_MSG_SOP, header,
- pd[port].vdo_data, AMS_START);
- reset_pd_cable(port);
- }
- } else {
- /* Prepare SOP header and send VDM */
- header = PD_HEADER(PD_DATA_VENDOR_DEF,
- pd[port].power_role,
- pd[port].data_role,
- pd[port].msg_id,
- (int)pd[port].vdo_count,
- pd_get_rev(port, TCPCI_MSG_SOP), 0);
- res = pd_transmit(port, TCPCI_MSG_SOP, header,
- pd[port].vdo_data, AMS_START);
- }
+ /* Prepare SOP header and send VDM */
+ header = PD_HEADER(PD_DATA_VENDOR_DEF, pd[port].power_role,
+ pd[port].data_role, pd[port].msg_id,
+ (int)pd[port].vdo_count,
+ pd_get_rev(port, TCPCI_MSG_SOP), 0);
+ res = pd_transmit(port, TCPCI_MSG_SOP, header,
+ pd[port].vdo_data, AMS_START);
if (res < 0) {
pd[port].vdm_state = VDM_STATE_ERR_SEND;
} else {
pd[port].vdm_state = VDM_STATE_BUSY;
- pd[port].vdm_timeout.val = get_time().val +
+ pd[port].vdm_timeout.val =
+ get_time().val +
vdm_get_ready_timeout(pd[port].vdo_data[0]);
}
break;
@@ -2366,15 +2216,14 @@ int pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash,
/* Search table for matching device / hash */
for (i = 0; i < RW_HASH_ENTRIES; i++)
if (dev_id == rw_hash_table[i].dev_id)
- return !memcmp(rw_hash,
- rw_hash_table[i].dev_rw_hash,
+ return !memcmp(rw_hash, rw_hash_table[i].dev_rw_hash,
PD_RW_HASH_SIZE);
#endif
return 0;
}
void pd_dev_get_rw_hash(int port, uint16_t *dev_id, uint8_t *rw_hash,
- uint32_t *current_image)
+ uint32_t *current_image)
{
*dev_id = pd[port].dev_id;
*current_image = pd[port].current_image;
@@ -2391,10 +2240,11 @@ __maybe_unused static void exit_supported_alt_mode(int port)
for (i = 0; i < supported_modes_cnt; i++) {
int opos = pd_alt_mode(port, TCPCI_MSG_SOP,
- supported_modes[i].svid);
+ supported_modes[i].svid);
- if (opos > 0 && pd_dfp_exit_mode(port, TCPCI_MSG_SOP,
- supported_modes[i].svid, opos)) {
+ if (opos > 0 &&
+ pd_dfp_exit_mode(port, TCPCI_MSG_SOP,
+ supported_modes[i].svid, opos)) {
CPRINTS("C%d Exiting ALT mode with SVID = 0x%x", port,
supported_modes[i].svid);
usb_mux_set_safe_mode(port);
@@ -2409,7 +2259,6 @@ __maybe_unused static void exit_supported_alt_mode(int port)
#ifdef CONFIG_POWER_COMMON
static void handle_new_power_state(int port)
{
-
if (chipset_in_or_transitioning_to_state(CHIPSET_STATE_ANY_OFF)) {
/*
* The SoC will negotiate the alternate mode again when
@@ -2473,8 +2322,8 @@ static void pd_update_snk_reset(void)
if (pd[i].task_state == PD_STATE_SNK_DISCOVERY) {
CPRINTS("C%d: Starting soft reset timer", i);
- set_state_timeout(i,
- get_time().val + PD_T_SINK_WAIT_CAP,
+ set_state_timeout(
+ i, get_time().val + PD_T_SINK_WAIT_CAP,
PD_STATE_SOFT_RESET);
}
}
@@ -2518,13 +2367,13 @@ void pd_set_dual_role(int port, enum pd_dual_role_states state)
static int pd_is_power_swapping(int port)
{
/* return true if in the act of swapping power roles */
- return pd[port].task_state == PD_STATE_SNK_SWAP_SNK_DISABLE ||
- pd[port].task_state == PD_STATE_SNK_SWAP_SRC_DISABLE ||
- pd[port].task_state == PD_STATE_SNK_SWAP_STANDBY ||
- pd[port].task_state == PD_STATE_SNK_SWAP_COMPLETE ||
- pd[port].task_state == PD_STATE_SRC_SWAP_SNK_DISABLE ||
- pd[port].task_state == PD_STATE_SRC_SWAP_SRC_DISABLE ||
- pd[port].task_state == PD_STATE_SRC_SWAP_STANDBY;
+ return pd[port].task_state == PD_STATE_SNK_SWAP_SNK_DISABLE ||
+ pd[port].task_state == PD_STATE_SNK_SWAP_SRC_DISABLE ||
+ pd[port].task_state == PD_STATE_SNK_SWAP_STANDBY ||
+ pd[port].task_state == PD_STATE_SNK_SWAP_COMPLETE ||
+ pd[port].task_state == PD_STATE_SRC_SWAP_SNK_DISABLE ||
+ pd[port].task_state == PD_STATE_SRC_SWAP_SRC_DISABLE ||
+ pd[port].task_state == PD_STATE_SRC_SWAP_STANDBY;
}
/* This must only be called from the PD task */
@@ -2536,9 +2385,9 @@ static void pd_update_dual_role_config(int port)
* source disconnected state).
*/
if (pd[port].power_role == PD_ROLE_SOURCE &&
- (drp_state[port] == PD_DRP_FORCE_SINK
- || (drp_state[port] == PD_DRP_TOGGLE_OFF
- && pd[port].task_state == PD_STATE_SRC_DISCONNECTED))) {
+ (drp_state[port] == PD_DRP_FORCE_SINK ||
+ (drp_state[port] == PD_DRP_TOGGLE_OFF &&
+ pd[port].task_state == PD_STATE_SRC_DISCONNECTED))) {
pd_set_power_role(port, PD_ROLE_SINK);
set_state(port, PD_STATE_SNK_DISCONNECTED);
tcpm_set_cc(port, TYPEC_CC_RD);
@@ -2695,8 +2544,7 @@ void pd_comm_enable(int port, int enable)
* any port in PD_SNK_DISCOVERY.
*/
if (enable && pd[port].task_state == PD_STATE_SNK_DISCOVERY)
- set_state_timeout(port,
- get_time().val + PD_T_SINK_WAIT_CAP,
+ set_state_timeout(port, get_time().val + PD_T_SINK_WAIT_CAP,
PD_STATE_HARD_RESET_SEND);
#endif
}
@@ -2794,57 +2642,12 @@ static int pd_restart_tcpc(int port)
}
#endif
-static void pd_send_enter_usb(int port, int *timeout)
-{
- uint32_t usb4_payload;
- uint16_t header;
- int res;
-
- /*
- * TODO: Enable Enter USB for cables (SOP').
- * This is needed for active cables
- */
- if (!IS_ENABLED(CONFIG_USBC_SS_MUX) ||
- !IS_ENABLED(CONFIG_USB_PD_USB4) ||
- !IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
- return;
-
- usb4_payload = get_enter_usb_msg_payload(port);
-
- header = PD_HEADER(PD_DATA_ENTER_USB,
- pd[port].power_role,
- pd[port].data_role,
- pd[port].msg_id,
- 1,
- PD_REV30,
- 0);
-
- res = pd_transmit(port, TCPCI_MSG_SOP, header, &usb4_payload,
- AMS_START);
- if (res < 0) {
- *timeout = 10*MSEC;
- /*
- * If failed to get goodCRC, send soft reset, otherwise ignore
- * failure.
- */
- set_state(port, res == -1 ?
- PD_STATE_SOFT_RESET :
- READY_RETURN_STATE(port));
- return;
- }
-
- /* Disable Enter USB4 mode prevent re-entry */
- disable_enter_usb4_mode(port);
-
- set_state(port, PD_STATE_ENTER_USB);
-}
-
void pd_task(void *u)
{
uint32_t head;
int port = TASK_ID_TO_PD_PORT(task_get_current());
uint32_t payload[7];
- int timeout = 10*MSEC;
+ int timeout = 10 * MSEC;
enum tcpc_cc_voltage_status cc1, cc2;
int res, incoming_packet = 0;
int hard_reset_count = 0;
@@ -2922,8 +2725,7 @@ void pd_task(void *u)
if (!res) {
struct ec_response_pd_chip_info_v1 info;
- if (tcpm_get_chip_info(port, 0, &info) ==
- EC_SUCCESS) {
+ if (tcpm_get_chip_info(port, 0, &info) == EC_SUCCESS) {
CPRINTS("TCPC p%d VID:0x%x PID:0x%x DID:0x%x "
"FWV:0x%" PRIx64,
port, info.vendor_id, info.product_id,
@@ -2943,8 +2745,8 @@ void pd_task(void *u)
* present. This flag is used to maintain a PD connection after a
* reset by sending a soft reset.
*/
- pd[port].flags |=
- pd_is_vbus_present(port) ? PD_FLAGS_VBUS_NEVER_LOW : 0;
+ pd[port].flags |= pd_is_vbus_present(port) ? PD_FLAGS_VBUS_NEVER_LOW :
+ 0;
#endif
/* Disable TCPC RX until connection is established */
@@ -2968,14 +2770,17 @@ void pd_task(void *u)
if ((saved_flgs & PD_BBRMFLG_POWER_ROLE) == PD_ROLE_SINK) {
pd_set_power_role(port,
(saved_flgs & PD_BBRMFLG_POWER_ROLE) ?
- PD_ROLE_SOURCE : PD_ROLE_SINK);
+ PD_ROLE_SOURCE :
+ PD_ROLE_SINK);
pd_set_data_role(port,
(saved_flgs & PD_BBRMFLG_DATA_ROLE) ?
- PD_ROLE_DFP : PD_ROLE_UFP);
+ PD_ROLE_DFP :
+ PD_ROLE_UFP);
#ifdef CONFIG_USBC_VCONN
pd_set_vconn_role(port,
(saved_flgs & PD_BBRMFLG_VCONN_ROLE) ?
- PD_ROLE_VCONN_ON : PD_ROLE_VCONN_OFF);
+ PD_ROLE_VCONN_ON :
+ PD_ROLE_VCONN_OFF);
#endif /* CONFIG_USBC_VCONN */
/*
@@ -2997,9 +2802,8 @@ void pd_task(void *u)
* earlier, so clear the contract flag and re-start as
* default role
*/
- pd_update_saved_port_flags(port,
- PD_BBRMFLG_EXPLICIT_CONTRACT, 0);
-
+ pd_update_saved_port_flags(
+ port, PD_BBRMFLG_EXPLICIT_CONTRACT, 0);
}
/*
* Set the TCPC reset event such that we can set our CC
@@ -3026,7 +2830,8 @@ void pd_task(void *u)
if (!(saved_flgs & PD_BBRMFLG_EXPLICIT_CONTRACT))
#endif /* CONFIG_USB_PD_DUAL_ROLE */
tcpm_set_cc(port, PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE ?
- TYPEC_CC_RP : TYPEC_CC_RD);
+ TYPEC_CC_RP :
+ TYPEC_CC_RD);
#ifdef CONFIG_USBC_PPC
/*
@@ -3126,7 +2931,8 @@ void pd_task(void *u)
* role.
*/
tcpm_set_cc(port, pd[port].power_role ?
- TYPEC_CC_RP : TYPEC_CC_RD);
+ TYPEC_CC_RP :
+ TYPEC_CC_RD);
/* Determine the polarity. */
tcpm_get_cc(port, &cc1, &cc2);
@@ -3136,7 +2942,7 @@ void pd_task(void *u)
} else if (cc_is_snk_dbg_acc(cc1, cc2)) {
pd[port].polarity =
board_get_src_dts_polarity(
- port);
+ port);
} else {
pd[port].polarity =
get_src_polarity(cc1, cc2);
@@ -3145,9 +2951,11 @@ void pd_task(void *u)
#endif /* CONFIG_USB_PD_DUAL_ROLE */
{
/* Ensure CC termination is default */
- tcpm_set_cc(port, PD_ROLE_DEFAULT(port) ==
- PD_ROLE_SOURCE ? TYPEC_CC_RP :
- TYPEC_CC_RD);
+ tcpm_set_cc(port,
+ PD_ROLE_DEFAULT(port) ==
+ PD_ROLE_SOURCE ?
+ TYPEC_CC_RP :
+ TYPEC_CC_RD);
}
/*
@@ -3157,14 +2965,18 @@ void pd_task(void *u)
* Otherwise, go to the default disconnected state
* and force renegotiation.
*/
- if (pd[port].vdm_state == VDM_STATE_DONE && (
+ if (pd[port].vdm_state == VDM_STATE_DONE &&
+ (
#ifdef CONFIG_USB_PD_DUAL_ROLE
- (PD_ROLE_DEFAULT(port) == PD_ROLE_SINK &&
- pd[port].task_state == PD_STATE_SNK_READY) ||
- (pd[port].task_state == PD_STATE_SOFT_RESET) ||
-#endif
- (PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE &&
- pd[port].task_state == PD_STATE_SRC_READY))) {
+ (PD_ROLE_DEFAULT(port) == PD_ROLE_SINK &&
+ pd[port].task_state ==
+ PD_STATE_SNK_READY) ||
+ (pd[port].task_state ==
+ PD_STATE_SOFT_RESET) ||
+#endif
+ (PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE &&
+ pd[port].task_state ==
+ PD_STATE_SRC_READY))) {
typec_set_polarity(port, pd[port].polarity);
tcpm_set_msg_header(port, pd[port].power_role,
pd[port].data_role);
@@ -3198,9 +3010,8 @@ void pd_task(void *u)
if (incoming_packet) {
/* Dequeue and consume duplicate message ID. */
if (tcpm_dequeue_message(port, payload, &head) ==
- EC_SUCCESS
- && !consume_repeat_message(port, head)
- )
+ EC_SUCCESS &&
+ !consume_repeat_message(port, head))
handle_request(port, head, payload);
/* Check if there are any more messages */
@@ -3214,13 +3025,13 @@ void pd_task(void *u)
/* if nothing to do, verify the state of the world in 500ms */
this_state = pd[port].task_state;
- timeout = 500*MSEC;
+ timeout = 500 * MSEC;
switch (this_state) {
case PD_STATE_DISABLED:
/* Nothing to do */
break;
case PD_STATE_SRC_DISCONNECTED:
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
pd_set_src_caps(port, 0, NULL);
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
/*
@@ -3242,10 +3053,9 @@ void pd_task(void *u)
*/
if (auto_toggle_supported &&
!(pd[port].flags & PD_FLAGS_TCPC_DRP_TOGGLE) &&
- !is_try_src(port) &&
- cc_is_open(cc1, cc2)) {
+ !is_try_src(port) && cc_is_open(cc1, cc2)) {
set_state(port, PD_STATE_DRP_AUTO_TOGGLE);
- timeout = 2*MSEC;
+ timeout = 2 * MSEC;
break;
}
#endif
@@ -3275,7 +3085,7 @@ void pd_task(void *u)
#endif
pd[port].cc_state = PD_CC_NONE;
set_state(port,
- PD_STATE_SRC_DISCONNECTED_DEBOUNCE);
+ PD_STATE_SRC_DISCONNECTED_DEBOUNCE);
break;
}
#if defined(CONFIG_USB_PD_DUAL_ROLE)
@@ -3331,7 +3141,7 @@ void pd_task(void *u)
#endif
break;
case PD_STATE_SRC_DISCONNECTED_DEBOUNCE:
- timeout = 20*MSEC;
+ timeout = 20 * MSEC;
tcpm_get_cc(port, &cc1, &cc2);
if (cc_is_snk_dbg_acc(cc1, cc2)) {
@@ -3346,7 +3156,7 @@ void pd_task(void *u)
} else {
/* No UFP */
set_state(port, PD_STATE_SRC_DISCONNECTED);
- timeout = 5*MSEC;
+ timeout = 5 * MSEC;
break;
}
@@ -3354,8 +3164,8 @@ void pd_task(void *u)
if (new_cc_state != pd[port].cc_state) {
pd[port].cc_debounce =
get_time().val +
- (is_try_src(port) ? PD_T_DEBOUNCE
- : PD_T_CC_DEBOUNCE);
+ (is_try_src(port) ? PD_T_DEBOUNCE :
+ PD_T_CC_DEBOUNCE);
pd[port].cc_state = new_cc_state;
break;
}
@@ -3455,7 +3265,7 @@ void pd_task(void *u)
pd[port].flags |= PD_FLAGS_CHECK_PR_ROLE |
PD_FLAGS_CHECK_DR_ROLE;
hard_reset_count = 0;
- timeout = 5*MSEC;
+ timeout = 5 * MSEC;
set_state(port, PD_STATE_SRC_STARTUP);
}
@@ -3467,7 +3277,7 @@ void pd_task(void *u)
case PD_STATE_SRC_HARD_RESET_RECOVER:
/* Do not continue until hard reset recovery time */
if (get_time().val < pd[port].src_recover) {
- timeout = 50*MSEC;
+ timeout = 50 * MSEC;
break;
}
@@ -3481,7 +3291,7 @@ void pd_task(void *u)
#endif
/* Enable VBUS */
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
if (pd_set_power_supply_ready(port)) {
set_state(port, PD_STATE_SRC_DISCONNECTED);
break;
@@ -3501,8 +3311,6 @@ void pd_task(void *u)
set_state(port, PD_STATE_SRC_STARTUP);
break;
case PD_STATE_SRC_STARTUP:
- /* Reset cable attributes and flags */
- reset_pd_cable(port);
/* Wait for power source to enable */
if (pd[port].last_state != pd[port].task_state) {
pd[port].flags |= PD_FLAGS_CHECK_IDENTITY;
@@ -3520,13 +3328,14 @@ void pd_task(void *u)
* on during debounce.
*/
get_time().val +
- PD_POWER_SUPPLY_TURN_ON_DELAY -
- (pd[port].last_state ==
- PD_STATE_SRC_DISCONNECTED_DEBOUNCE
- ? PD_T_CC_DEBOUNCE : 0),
+ PD_POWER_SUPPLY_TURN_ON_DELAY -
+ (pd[port].last_state ==
+ PD_STATE_SRC_DISCONNECTED_DEBOUNCE ?
+ PD_T_CC_DEBOUNCE :
+ 0),
#else
get_time().val +
- PD_POWER_SUPPLY_TURN_ON_DELAY,
+ PD_POWER_SUPPLY_TURN_ON_DELAY,
#endif
PD_STATE_SRC_DISCOVERY);
}
@@ -3541,25 +3350,25 @@ void pd_task(void *u)
* partner, then start NoResponseTimer.
*/
if (pd_capable(port))
- set_state_timeout(port,
+ set_state_timeout(
+ port,
get_time().val +
- PD_T_NO_RESPONSE,
+ PD_T_NO_RESPONSE,
hard_reset_count <
- PD_HARD_RESET_COUNT ?
- PD_STATE_HARD_RESET_SEND :
- PD_STATE_SRC_DISCONNECTED);
+ PD_HARD_RESET_COUNT ?
+ PD_STATE_HARD_RESET_SEND :
+ PD_STATE_SRC_DISCONNECTED);
}
/* Send source cap some minimum number of times */
- if (caps_count < PD_CAPS_COUNT &&
- next_src_cap <= now.val) {
+ if (caps_count < PD_CAPS_COUNT &&
+ next_src_cap <= now.val) {
/* Query capabilities of the other side */
res = send_source_cap(port, AMS_START);
/* packet was acked => PD capable device) */
if (res >= 0) {
- set_state(port,
- PD_STATE_SRC_NEGOCIATE);
- timeout = 10*MSEC;
+ set_state(port, PD_STATE_SRC_NEGOCIATE);
+ timeout = 10 * MSEC;
hard_reset_count = 0;
caps_count = 0;
/* Port partner is PD capable */
@@ -3567,8 +3376,8 @@ void pd_task(void *u)
PD_FLAGS_PREVIOUS_PD_CONN;
} else { /* failed, retry later */
timeout = PD_T_SEND_SOURCE_CAP;
- next_src_cap = now.val +
- PD_T_SEND_SOURCE_CAP;
+ next_src_cap =
+ now.val + PD_T_SEND_SOURCE_CAP;
caps_count++;
}
} else if (caps_count < PD_CAPS_COUNT) {
@@ -3580,17 +3389,16 @@ void pd_task(void *u)
if (pd[port].last_state != pd[port].task_state)
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
PD_STATE_HARD_RESET_SEND);
break;
case PD_STATE_SRC_ACCEPTED:
/* Accept sent, wait for enabling the new voltage */
if (pd[port].last_state != pd[port].task_state)
- set_state_timeout(
- port,
- get_time().val +
- PD_T_SINK_TRANSITION,
- PD_STATE_SRC_POWERED);
+ set_state_timeout(port,
+ get_time().val +
+ PD_T_SINK_TRANSITION,
+ PD_STATE_SRC_POWERED);
break;
case PD_STATE_SRC_POWERED:
/* Switch to the new requested voltage */
@@ -3600,7 +3408,7 @@ void pd_task(void *u)
set_state_timeout(
port,
get_time().val +
- PD_POWER_SUPPLY_TURN_ON_DELAY,
+ PD_POWER_SUPPLY_TURN_ON_DELAY,
PD_STATE_SRC_TRANSITION);
}
break;
@@ -3608,7 +3416,7 @@ void pd_task(void *u)
/* the voltage output is good, notify the source */
res = send_control(port, PD_CTRL_PS_RDY);
if (res >= 0) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
/*
* Give the sink some time to send any messages
@@ -3621,8 +3429,8 @@ void pd_task(void *u)
* SRC_READY state.
*/
pd[port].ready_state_holdoff_timer =
- get_time().val + SRC_READY_HOLD_OFF_US
- + (get_time().le.lo & 0xf) * 12 * MSEC;
+ get_time().val + SRC_READY_HOLD_OFF_US +
+ (get_time().le.lo & 0xf) * 12 * MSEC;
/* it's time to ping regularly the sink */
set_state(port, PD_STATE_SRC_READY);
@@ -3658,8 +3466,7 @@ void pd_task(void *u)
if (pd[port].flags & PD_FLAGS_UPDATE_SRC_CAPS) {
res = send_source_cap(port, AMS_START);
if (res >= 0) {
- set_state(port,
- PD_STATE_SRC_NEGOCIATE);
+ set_state(port, PD_STATE_SRC_NEGOCIATE);
pd[port].flags &=
~PD_FLAGS_UPDATE_SRC_CAPS;
}
@@ -3669,12 +3476,16 @@ void pd_task(void *u)
/* Send get sink cap if haven't received it yet */
if (!(pd[port].flags & PD_FLAGS_SNK_CAP_RECVD)) {
if (++snk_cap_count <= PD_SNK_CAP_RETRIES) {
- /* Get sink cap to know if dual-role device */
- send_control(port, PD_CTRL_GET_SINK_CAP);
- set_state(port, PD_STATE_SRC_GET_SINK_CAP);
+ /* Get sink cap to know if dual-role
+ * device */
+ send_control(port,
+ PD_CTRL_GET_SINK_CAP);
+ set_state(port,
+ PD_STATE_SRC_GET_SINK_CAP);
break;
} else if (debug_level >= 2 &&
- snk_cap_count == PD_SNK_CAP_RETRIES+1) {
+ snk_cap_count ==
+ PD_SNK_CAP_RETRIES + 1) {
CPRINTF("C%d ERR SNK_CAP\n", port);
}
}
@@ -3686,7 +3497,6 @@ void pd_task(void *u)
pd[port].flags &= ~PD_FLAGS_CHECK_PR_ROLE;
}
-
/* Check data role policy, which may trigger a swap */
if (pd[port].flags & PD_FLAGS_CHECK_DR_ROLE) {
pd_check_dr_role(port, pd[port].data_role,
@@ -3705,8 +3515,7 @@ void pd_task(void *u)
* initiate or receive a request an exchange
* of VCONN Source.
*/
- pd_try_execute_vconn_swap(port,
- pd[port].flags);
+ pd_try_execute_vconn_swap(port, pd[port].flags);
pd[port].flags &= ~PD_FLAGS_CHECK_VCONN_STATE;
break;
}
@@ -3722,15 +3531,6 @@ void pd_task(void *u)
break;
}
- /*
- * Enter_USB if port partner and cable are
- * USB4 compatible.
- */
- if (should_enter_usb4_mode(port)) {
- pd_send_enter_usb(port, &timeout);
- break;
- }
-
if (!(pd[port].flags & PD_FLAGS_PING_ENABLED))
break;
@@ -3747,28 +3547,30 @@ void pd_task(void *u)
if (pd[port].last_state != pd[port].task_state)
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
PD_STATE_SRC_READY);
break;
case PD_STATE_DR_SWAP:
if (pd[port].last_state != pd[port].task_state) {
res = send_control(port, PD_CTRL_DR_SWAP);
if (res < 0) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
/*
* If failed to get goodCRC, send
* soft reset, otherwise ignore
* failure.
*/
- set_state(port, res == -1 ?
- PD_STATE_SOFT_RESET :
- READY_RETURN_STATE(port));
+ set_state(port,
+ res == -1 ?
+ PD_STATE_SOFT_RESET :
+ READY_RETURN_STATE(
+ port));
break;
}
/* Wait for accept or reject */
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
READY_RETURN_STATE(port));
}
break;
@@ -3777,31 +3579,32 @@ void pd_task(void *u)
if (pd[port].last_state != pd[port].task_state) {
res = send_control(port, PD_CTRL_PR_SWAP);
if (res < 0) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
/*
* If failed to get goodCRC, send
* soft reset, otherwise ignore
* failure.
*/
- set_state(port, res == -1 ?
- PD_STATE_SOFT_RESET :
- PD_STATE_SRC_READY);
+ set_state(port,
+ res == -1 ?
+ PD_STATE_SOFT_RESET :
+ PD_STATE_SRC_READY);
break;
}
/* Wait for accept or reject */
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
PD_STATE_SRC_READY);
}
break;
case PD_STATE_SRC_SWAP_SNK_DISABLE:
/* Give time for sink to stop drawing current */
if (pd[port].last_state != pd[port].task_state)
- set_state_timeout(port,
- get_time().val +
- PD_T_SINK_TRANSITION,
- PD_STATE_SRC_SWAP_SRC_DISABLE);
+ set_state_timeout(
+ port,
+ get_time().val + PD_T_SINK_TRANSITION,
+ PD_STATE_SRC_SWAP_SRC_DISABLE);
break;
case PD_STATE_SRC_SWAP_SRC_DISABLE:
if (pd[port].last_state != pd[port].task_state) {
@@ -3824,10 +3627,11 @@ void pd_task(void *u)
/* Inform TCPC of power role update. */
pd_update_roles(port);
- set_state_timeout(port,
- get_time().val +
- PD_POWER_SUPPLY_TURN_OFF_DELAY,
- PD_STATE_SRC_SWAP_STANDBY);
+ set_state_timeout(
+ port,
+ get_time().val +
+ PD_POWER_SUPPLY_TURN_OFF_DELAY,
+ PD_STATE_SRC_SWAP_STANDBY);
}
break;
case PD_STATE_SRC_SWAP_STANDBY:
@@ -3836,7 +3640,7 @@ void pd_task(void *u)
/* Send PS_RDY */
res = send_control(port, PD_CTRL_PS_RDY);
if (res < 0) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
set_state(port,
PD_STATE_SRC_DISCONNECTED);
break;
@@ -3844,7 +3648,7 @@ void pd_task(void *u)
/* Wait for PS_RDY from new source */
set_state_timeout(port,
get_time().val +
- PD_T_PS_SOURCE_ON,
+ PD_T_PS_SOURCE_ON,
PD_STATE_SNK_DISCONNECTED);
}
break;
@@ -3895,8 +3699,8 @@ void pd_task(void *u)
/* Set the CC termination and state back to default */
tcpm_set_cc(port,
PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE ?
- TYPEC_CC_RP :
- TYPEC_CC_RD);
+ TYPEC_CC_RP :
+ TYPEC_CC_RD);
set_state(port, PD_DEFAULT_STATE(port));
tcpc_prints("resumed!", port);
#endif
@@ -3904,10 +3708,11 @@ void pd_task(void *u)
}
case PD_STATE_SNK_DISCONNECTED:
#ifdef CONFIG_USB_PD_LOW_POWER
- timeout = (drp_state[port] !=
- PD_DRP_TOGGLE_ON ? SECOND : 10*MSEC);
+ timeout = (drp_state[port] != PD_DRP_TOGGLE_ON ?
+ SECOND :
+ 10 * MSEC);
#else
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
#endif
pd_set_src_caps(port, 0, NULL);
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
@@ -3931,11 +3736,10 @@ void pd_task(void *u)
*/
if (auto_toggle_supported &&
!(pd[port].flags & PD_FLAGS_TCPC_DRP_TOGGLE) &&
- !is_try_src(port) &&
- cc_is_open(cc1, cc2) &&
- (drp_state[port] == PD_DRP_TOGGLE_ON)) {
+ !is_try_src(port) && cc_is_open(cc1, cc2) &&
+ (drp_state[port] == PD_DRP_TOGGLE_ON)) {
set_state(port, PD_STATE_DRP_AUTO_TOGGLE);
- timeout = 2*MSEC;
+ timeout = 2 * MSEC;
break;
}
#endif
@@ -3945,11 +3749,11 @@ void pd_task(void *u)
pd[port].cc_state = PD_CC_NONE;
hard_reset_count = 0;
new_cc_state = PD_CC_NONE;
- pd[port].cc_debounce = get_time().val +
- PD_T_CC_DEBOUNCE;
+ pd[port].cc_debounce =
+ get_time().val + PD_T_CC_DEBOUNCE;
set_state(port,
- PD_STATE_SNK_DISCONNECTED_DEBOUNCE);
- timeout = 10*MSEC;
+ PD_STATE_SNK_DISCONNECTED_DEBOUNCE);
+ timeout = 10 * MSEC;
break;
}
@@ -3983,7 +3787,7 @@ void pd_task(void *u)
#endif
/* Swap states quickly */
- timeout = 2*MSEC;
+ timeout = 2 * MSEC;
break;
}
@@ -3994,7 +3798,7 @@ void pd_task(void *u)
* CC status.
*/
pd[port].flags |= PD_FLAGS_LPM_REQUESTED;
-#endif/* CONFIG_USB_PD_TCPC_LOW_POWER */
+#endif /* CONFIG_USB_PD_TCPC_LOW_POWER */
break;
case PD_STATE_SNK_DISCONNECTED_DEBOUNCE:
@@ -4008,16 +3812,16 @@ void pd_task(void *u)
} else {
/* No connection any more */
set_state(port, PD_STATE_SNK_DISCONNECTED);
- timeout = 5*MSEC;
+ timeout = 5 * MSEC;
break;
}
- timeout = 20*MSEC;
+ timeout = 20 * MSEC;
/* Debounce the cc state */
if (new_cc_state != pd[port].cc_state) {
- pd[port].cc_debounce = get_time().val +
- PD_T_CC_DEBOUNCE;
+ pd[port].cc_debounce =
+ get_time().val + PD_T_CC_DEBOUNCE;
pd[port].cc_state = new_cc_state;
break;
}
@@ -4032,14 +3836,14 @@ void pd_task(void *u)
* If TRY_SRC is enabled, but not active,
* then force attempt to connect as source.
*/
- pd[port].try_src_marker = get_time().val
- + PD_T_DRP_TRY;
- pd[port].try_timeout = get_time().val
- + PD_T_TRY_TIMEOUT;
+ pd[port].try_src_marker =
+ get_time().val + PD_T_DRP_TRY;
+ pd[port].try_timeout =
+ get_time().val + PD_T_TRY_TIMEOUT;
/* Swap roles to source */
pd_set_power_role(port, PD_ROLE_SOURCE);
tcpm_set_cc(port, TYPEC_CC_RP);
- timeout = 2*MSEC;
+ timeout = 2 * MSEC;
set_state(port, PD_STATE_SRC_DISCONNECTED);
/* Set flag after the state change */
pd[port].flags |= PD_FLAGS_TRY_SRC;
@@ -4060,8 +3864,8 @@ void pd_task(void *u)
#if defined(CONFIG_CHARGE_MANAGER)
typec_curr = usb_get_typec_current_limit(
pd[port].polarity, cc1, cc2);
- typec_set_input_current_limit(
- port, typec_curr, TYPE_C_VOLTAGE);
+ typec_set_input_current_limit(port, typec_curr,
+ TYPE_C_VOLTAGE);
#endif
#ifdef CONFIG_USBC_PPC
@@ -4081,14 +3885,11 @@ void pd_task(void *u)
pd[port].flags |= PD_FLAGS_CHECK_PR_ROLE |
PD_FLAGS_CHECK_DR_ROLE |
PD_FLAGS_CHECK_IDENTITY;
- /* Reset cable attributes and flags */
- reset_pd_cable(port);
-
if (new_cc_state == PD_CC_DFP_DEBUG_ACC)
pd[port].flags |=
PD_FLAGS_TS_DTS_PARTNER;
set_state(port, PD_STATE_SNK_DISCOVERY);
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
hook_call_deferred(
&pd_usb_billboard_deferred_data,
PD_T_AME);
@@ -4099,47 +3900,49 @@ void pd_task(void *u)
pd[port].flags |= PD_FLAGS_CHECK_IDENTITY;
if (get_usb_pd_vbus_detect() ==
- USB_PD_VBUS_DETECT_NONE) {
+ USB_PD_VBUS_DETECT_NONE) {
/*
* Can't measure vbus state so this is the
* maximum recovery time for the source.
*/
if (pd[port].last_state != pd[port].task_state)
- set_state_timeout(port, get_time().val +
- PD_T_SAFE_0V +
- PD_T_SRC_RECOVER_MAX +
- PD_T_SRC_TURN_ON,
- PD_STATE_SNK_DISCONNECTED);
+ set_state_timeout(
+ port,
+ get_time().val + PD_T_SAFE_0V +
+ PD_T_SRC_RECOVER_MAX +
+ PD_T_SRC_TURN_ON,
+ PD_STATE_SNK_DISCONNECTED);
} else {
#ifndef CONFIG_USB_PD_VBUS_DETECT_NONE
/* Wait for VBUS to go low and then high*/
if (pd[port].last_state !=
- pd[port].task_state) {
+ pd[port].task_state) {
snk_hard_reset_vbus_off = 0;
- set_state_timeout(port,
- get_time().val +
- PD_T_SAFE_0V,
- hard_reset_count <
- PD_HARD_RESET_COUNT ?
- PD_STATE_HARD_RESET_SEND :
- PD_STATE_SNK_DISCOVERY);
+ set_state_timeout(
+ port,
+ get_time().val + PD_T_SAFE_0V,
+ hard_reset_count <
+ PD_HARD_RESET_COUNT ?
+ PD_STATE_HARD_RESET_SEND :
+ PD_STATE_SNK_DISCOVERY);
}
if (!pd_is_vbus_present(port) &&
!snk_hard_reset_vbus_off) {
/* VBUS has gone low, reset timeout */
snk_hard_reset_vbus_off = 1;
- set_state_timeout(port,
- get_time().val +
- PD_T_SRC_RECOVER_MAX +
- PD_T_SRC_TURN_ON,
- PD_STATE_SNK_DISCONNECTED);
+ set_state_timeout(
+ port,
+ get_time().val +
+ PD_T_SRC_RECOVER_MAX +
+ PD_T_SRC_TURN_ON,
+ PD_STATE_SNK_DISCONNECTED);
}
if (pd_is_vbus_present(port) &&
snk_hard_reset_vbus_off) {
/* VBUS went high again */
set_state(port, PD_STATE_SNK_DISCOVERY);
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
}
/*
@@ -4152,8 +3955,8 @@ void pd_task(void *u)
break;
case PD_STATE_SNK_DISCOVERY:
/* Wait for source cap expired only if we are enabled */
- if ((pd[port].last_state != pd[port].task_state)
- && pd_comm_is_enabled(port)) {
+ if ((pd[port].last_state != pd[port].task_state) &&
+ pd_comm_is_enabled(port)) {
#if defined(CONFIG_USB_PD_TCPM_TCPCI) || defined(CONFIG_USB_PD_TCPM_STUB)
/*
* If we come from hard reset recover state,
@@ -4176,58 +3979,64 @@ void pd_task(void *u)
*/
int batt_soc = usb_get_battery_soc();
- if (batt_soc < CONFIG_USB_PD_RESET_MIN_BATT_SOC ||
+ if (batt_soc <
+ CONFIG_USB_PD_RESET_MIN_BATT_SOC ||
battery_get_disconnect_state() !=
- BATTERY_NOT_DISCONNECTED)
+ BATTERY_NOT_DISCONNECTED)
pd[port].flags |=
- PD_FLAGS_SNK_WAITING_BATT;
+ PD_FLAGS_SNK_WAITING_BATT;
else
pd[port].flags &=
- ~PD_FLAGS_SNK_WAITING_BATT;
+ ~PD_FLAGS_SNK_WAITING_BATT;
#endif
if (pd[port].flags &
- PD_FLAGS_SNK_WAITING_BATT) {
+ PD_FLAGS_SNK_WAITING_BATT) {
#ifdef CONFIG_CHARGE_MANAGER
/*
* Configure this port as dedicated for
* now, so it won't be de-selected by
* the charge manager leaving safe mode.
*/
- charge_manager_update_dualrole(port,
- CAP_DEDICATED);
+ charge_manager_update_dualrole(
+ port, CAP_DEDICATED);
#endif
CPRINTS("C%d: Battery low. "
- "Hold reset timer", port);
- /*
- * If VBUS has never been low, and we timeout
- * waiting for source cap, try a soft reset
- * first, in case we were already in a stable
- * contract before this boot.
- */
+ "Hold reset timer",
+ port);
+ /*
+ * If VBUS has never been low, and we
+ * timeout waiting for source cap, try a
+ * soft reset first, in case we were
+ * already in a stable contract before
+ * this boot.
+ */
} else if (pd[port].flags &
- PD_FLAGS_VBUS_NEVER_LOW) {
- set_state_timeout(port,
- get_time().val +
- PD_T_SINK_WAIT_CAP,
- PD_STATE_SOFT_RESET);
- /*
- * If we haven't passed hard reset counter,
- * start SinkWaitCapTimer, otherwise start
- * NoResponseTimer.
- */
+ PD_FLAGS_VBUS_NEVER_LOW) {
+ set_state_timeout(
+ port,
+ get_time().val +
+ PD_T_SINK_WAIT_CAP,
+ PD_STATE_SOFT_RESET);
+ /*
+ * If we haven't passed hard reset
+ * counter, start SinkWaitCapTimer,
+ * otherwise start NoResponseTimer.
+ */
} else if (hard_reset_count <
- PD_HARD_RESET_COUNT) {
- set_state_timeout(port,
- get_time().val +
- PD_T_SINK_WAIT_CAP,
- PD_STATE_HARD_RESET_SEND);
+ PD_HARD_RESET_COUNT) {
+ set_state_timeout(
+ port,
+ get_time().val +
+ PD_T_SINK_WAIT_CAP,
+ PD_STATE_HARD_RESET_SEND);
} else if (pd_capable(port)) {
/* ErrorRecovery */
- set_state_timeout(port,
- get_time().val +
- PD_T_NO_RESPONSE,
- PD_STATE_SNK_DISCONNECTED);
+ set_state_timeout(
+ port,
+ get_time().val +
+ PD_T_NO_RESPONSE,
+ PD_STATE_SNK_DISCONNECTED);
}
#if defined(CONFIG_CHARGE_MANAGER)
/*
@@ -4247,17 +4056,17 @@ void pd_task(void *u)
/* Check if CC pull-up has changed */
tcpm_get_cc(port, &cc1, &cc2);
- if (typec_curr != usb_get_typec_current_limit(
- pd[port].polarity, cc1, cc2)) {
+ if (typec_curr !=
+ usb_get_typec_current_limit(pd[port].polarity, cc1,
+ cc2)) {
/* debounce signal by requiring two reads */
if (typec_curr_change) {
/* set new input current limit */
- typec_curr =
- usb_get_typec_current_limit(
- pd[port].polarity,
- cc1, cc2);
+ typec_curr = usb_get_typec_current_limit(
+ pd[port].polarity, cc1, cc2);
typec_set_input_current_limit(
- port, typec_curr, TYPE_C_VOLTAGE);
+ port, typec_curr,
+ TYPE_C_VOLTAGE);
} else {
/* delay for debounce */
timeout = PD_T_DEBOUNCE;
@@ -4275,7 +4084,7 @@ void pd_task(void *u)
hard_reset_count = 0;
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
PD_STATE_HARD_RESET_SEND);
}
break;
@@ -4284,11 +4093,11 @@ void pd_task(void *u)
if (pd[port].last_state != pd[port].task_state)
set_state_timeout(port,
get_time().val +
- PD_T_PS_TRANSITION,
+ PD_T_PS_TRANSITION,
PD_STATE_HARD_RESET_SEND);
break;
case PD_STATE_SNK_READY:
- timeout = 20*MSEC;
+ timeout = 20 * MSEC;
/*
* Don't send any traffic yet until our holdoff timer
@@ -4343,52 +4152,43 @@ void pd_task(void *u)
* initiate or receive a request an exchange
* of VCONN Source.
*/
- pd_try_execute_vconn_swap(port,
- pd[port].flags);
+ pd_try_execute_vconn_swap(port, pd[port].flags);
pd[port].flags &= ~PD_FLAGS_CHECK_VCONN_STATE;
break;
}
/* If DFP, send discovery SVDMs */
if (pd[port].data_role == PD_ROLE_DFP &&
- (pd[port].flags & PD_FLAGS_CHECK_IDENTITY)) {
+ (pd[port].flags & PD_FLAGS_CHECK_IDENTITY)) {
pd_send_vdm(port, USB_SID_PD,
CMD_DISCOVER_IDENT, NULL, 0);
pd[port].flags &= ~PD_FLAGS_CHECK_IDENTITY;
break;
}
- /*
- * Enter_USB if port partner and cable are
- * USB4 compatible.
- */
- if (should_enter_usb4_mode(port)) {
- pd_send_enter_usb(port, &timeout);
- break;
- }
-
/* Sent all messages, don't need to wake very often */
- timeout = 200*MSEC;
+ timeout = 200 * MSEC;
break;
case PD_STATE_SNK_SWAP_INIT:
if (pd[port].last_state != pd[port].task_state) {
res = send_control(port, PD_CTRL_PR_SWAP);
if (res < 0) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
/*
* If failed to get goodCRC, send
* soft reset, otherwise ignore
* failure.
*/
- set_state(port, res == -1 ?
- PD_STATE_SOFT_RESET :
- PD_STATE_SNK_READY);
+ set_state(port,
+ res == -1 ?
+ PD_STATE_SOFT_RESET :
+ PD_STATE_SNK_READY);
break;
}
/* Wait for accept or reject */
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
PD_STATE_SNK_READY);
}
break;
@@ -4397,19 +4197,18 @@ void pd_task(void *u)
pd_set_input_current_limit(port, 0, 0);
#ifdef CONFIG_CHARGE_MANAGER
typec_set_input_current_limit(port, 0, 0);
- charge_manager_set_ceil(port,
- CEIL_REQUESTOR_PD,
+ charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
CHARGE_CEIL_NONE);
#endif
set_state(port, PD_STATE_SNK_SWAP_SRC_DISABLE);
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
break;
case PD_STATE_SNK_SWAP_SRC_DISABLE:
/* Wait for PS_RDY */
if (pd[port].last_state != pd[port].task_state)
set_state_timeout(port,
get_time().val +
- PD_T_PS_SOURCE_OFF,
+ PD_T_PS_SOURCE_OFF,
PD_STATE_HARD_RESET_SEND);
break;
case PD_STATE_SNK_SWAP_STANDBY:
@@ -4419,7 +4218,7 @@ void pd_task(void *u)
if (pd_set_power_supply_ready(port)) {
/* Restore Rd */
tcpm_set_cc(port, TYPEC_CC_RD);
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
set_state(port,
PD_STATE_SNK_DISCONNECTED);
break;
@@ -4428,7 +4227,7 @@ void pd_task(void *u)
set_state_timeout(
port,
get_time().val +
- PD_POWER_SUPPLY_TURN_ON_DELAY,
+ PD_POWER_SUPPLY_TURN_ON_DELAY,
PD_STATE_SNK_SWAP_COMPLETE);
}
break;
@@ -4445,34 +4244,36 @@ void pd_task(void *u)
}
/* Don't send GET_SINK_CAP on swap */
- snk_cap_count = PD_SNK_CAP_RETRIES+1;
+ snk_cap_count = PD_SNK_CAP_RETRIES + 1;
caps_count = 0;
pd[port].msg_id = 0;
pd_set_power_role(port, PD_ROLE_SOURCE);
pd_update_roles(port);
set_state(port, PD_STATE_SRC_DISCOVERY);
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
break;
#ifdef CONFIG_USBC_VCONN_SWAP
case PD_STATE_VCONN_SWAP_SEND:
if (pd[port].last_state != pd[port].task_state) {
res = send_control(port, PD_CTRL_VCONN_SWAP);
if (res < 0) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
/*
* If failed to get goodCRC, send
* soft reset, otherwise ignore
* failure.
*/
- set_state(port, res == -1 ?
- PD_STATE_SOFT_RESET :
- READY_RETURN_STATE(port));
+ set_state(port,
+ res == -1 ?
+ PD_STATE_SOFT_RESET :
+ READY_RETURN_STATE(
+ port));
break;
}
/* Wait for accept or reject */
set_state_timeout(port,
get_time().val +
- PD_T_SENDER_RESPONSE,
+ PD_T_SENDER_RESPONSE,
READY_RETURN_STATE(port));
}
break;
@@ -4481,12 +4282,14 @@ void pd_task(void *u)
if (!(pd[port].flags & PD_FLAGS_VCONN_ON)) {
/* Turn VCONN on and wait for it */
set_vconn(port, 1);
- set_state_timeout(port,
+ set_state_timeout(
+ port,
get_time().val +
- CONFIG_USBC_VCONN_SWAP_DELAY_US,
+ CONFIG_USBC_VCONN_SWAP_DELAY_US,
PD_STATE_VCONN_SWAP_READY);
} else {
- set_state_timeout(port,
+ set_state_timeout(
+ port,
get_time().val +
PD_T_VCONN_SOURCE_ON,
READY_RETURN_STATE(port));
@@ -4498,29 +4301,30 @@ void pd_task(void *u)
if (!(pd[port].flags & PD_FLAGS_VCONN_ON)) {
/* VCONN is now on, send PS_RDY */
pd_set_vconn_role(port,
- PD_ROLE_VCONN_ON);
+ PD_ROLE_VCONN_ON);
res = send_control(port,
- PD_CTRL_PS_RDY);
+ PD_CTRL_PS_RDY);
if (res == -1) {
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
/*
* If failed to get goodCRC,
* send soft reset
*/
set_state(port,
- PD_STATE_SOFT_RESET);
+ PD_STATE_SOFT_RESET);
break;
}
set_state(port,
- READY_RETURN_STATE(port));
+ READY_RETURN_STATE(port));
} else {
/* Turn VCONN off and wait for it */
set_vconn(port, 0);
pd_set_vconn_role(port,
- PD_ROLE_VCONN_OFF);
- set_state_timeout(port,
+ PD_ROLE_VCONN_OFF);
+ set_state_timeout(
+ port,
get_time().val +
- CONFIG_USBC_VCONN_SWAP_DELAY_US,
+ CONFIG_USBC_VCONN_SWAP_DELAY_US,
READY_RETURN_STATE(port));
}
}
@@ -4538,14 +4342,14 @@ void pd_task(void *u)
if (res < 0) {
set_state(port,
PD_STATE_HARD_RESET_SEND);
- timeout = 5*MSEC;
+ timeout = 5 * MSEC;
break;
}
- set_state_timeout(
- port,
- get_time().val + PD_T_SENDER_RESPONSE,
- PD_STATE_HARD_RESET_SEND);
+ set_state_timeout(port,
+ get_time().val +
+ PD_T_SENDER_RESPONSE,
+ PD_STATE_HARD_RESET_SEND);
}
break;
case PD_STATE_HARD_RESET_SEND:
@@ -4577,7 +4381,7 @@ void pd_task(void *u)
break;
if (pd_transmit(port, TCPCI_MSG_TX_HARD_RESET, 0, NULL,
- AMS_START) < 0) {
+ AMS_START) < 0) {
/*
* likely a non-idle channel
* TCPCI r2.0 v1.0 4.4.15:
@@ -4614,7 +4418,8 @@ void pd_task(void *u)
*/
if (pd[port].power_role == PD_ROLE_SOURCE) {
set_state_timeout(port,
- get_time().val + PD_T_PS_HARD_RESET,
+ get_time().val +
+ PD_T_PS_HARD_RESET,
PD_STATE_HARD_RESET_EXECUTE);
} else {
set_state(port, PD_STATE_HARD_RESET_EXECUTE);
@@ -4633,32 +4438,31 @@ void pd_task(void *u)
/* reset our own state machine */
pd_execute_hard_reset(port);
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
break;
#ifdef CONFIG_COMMON_RUNTIME
case PD_STATE_BIST_RX:
send_bist_cmd(port);
/* Delay at least enough for partner to finish BIST */
- timeout = PD_T_BIST_RECEIVE + 20*MSEC;
+ timeout = PD_T_BIST_RECEIVE + 20 * MSEC;
/* Set to appropriate port disconnected state */
- set_state(port, DUAL_ROLE_IF_ELSE(port,
- PD_STATE_SNK_DISCONNECTED,
+ set_state(port, DUAL_ROLE_IF_ELSE(
+ port, PD_STATE_SNK_DISCONNECTED,
PD_STATE_SRC_DISCONNECTED));
break;
case PD_STATE_BIST_TX:
pd_transmit(port, TCPCI_MSG_TX_BIST_MODE_2, 0, NULL,
AMS_START);
/* Delay at least enough to finish sending BIST */
- timeout = PD_T_BIST_TRANSMIT + 20*MSEC;
+ timeout = PD_T_BIST_TRANSMIT + 20 * MSEC;
/* Set to appropriate port disconnected state */
- set_state(port, DUAL_ROLE_IF_ELSE(port,
- PD_STATE_SNK_DISCONNECTED,
+ set_state(port, DUAL_ROLE_IF_ELSE(
+ port, PD_STATE_SNK_DISCONNECTED,
PD_STATE_SRC_DISCONNECTED));
break;
#endif
#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
- case PD_STATE_DRP_AUTO_TOGGLE:
- {
+ case PD_STATE_DRP_AUTO_TOGGLE: {
enum pd_drp_next_states next_state;
assert(auto_toggle_supported);
@@ -4701,10 +4505,8 @@ void pd_task(void *u)
tcpm_get_cc(port, &cc1, &cc2);
next_state = drp_auto_toggle_next_state(
- &pd[port].drp_sink_time,
- pd[port].power_role,
- drp_state[port],
- cc1, cc2, false);
+ &pd[port].drp_sink_time, pd[port].power_role,
+ drp_state[port], cc1, cc2, false);
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
/*
@@ -4718,7 +4520,7 @@ void pd_task(void *u)
#endif
if (next_state == DRP_TC_DEFAULT) {
if (PD_DEFAULT_STATE(port) ==
- PD_STATE_SNK_DISCONNECTED)
+ PD_STATE_SNK_DISCONNECTED)
next_state = DRP_TC_UNATTACHED_SNK;
else
next_state = DRP_TC_UNATTACHED_SRC;
@@ -4737,7 +4539,7 @@ void pd_task(void *u)
tcpm_set_cc(port, TYPEC_CC_RD);
pd_set_power_role(port, PD_ROLE_SINK);
- timeout = 2*MSEC;
+ timeout = 2 * MSEC;
set_state(port, PD_STATE_SNK_DISCONNECTED);
} else if (next_state == DRP_TC_UNATTACHED_SRC) {
/*
@@ -4752,7 +4554,7 @@ void pd_task(void *u)
tcpm_set_cc(port, TYPEC_CC_RP);
pd_set_power_role(port, PD_ROLE_SOURCE);
- timeout = 2*MSEC;
+ timeout = 2 * MSEC;
set_state(port, PD_STATE_SRC_DISCONNECTED);
} else {
/*
@@ -4767,13 +4569,6 @@ void pd_task(void *u)
break;
}
#endif
- case PD_STATE_ENTER_USB:
- if (pd[port].last_state != pd[port].task_state) {
- set_state_timeout(port,
- get_time().val + PD_T_SENDER_RESPONSE,
- READY_RETURN_STATE(port));
- }
- break;
default:
break;
}
@@ -4789,7 +4584,8 @@ void pd_task(void *u)
if (now.val >= pd[port].timeout) {
set_state(port, pd[port].timeout_state);
/* On a state timeout, run next state soon */
- timeout = timeout < 10*MSEC ? timeout : 10*MSEC;
+ timeout = timeout < 10 * MSEC ? timeout :
+ 10 * MSEC;
} else if (pd[port].timeout - now.val < timeout) {
timeout = pd[port].timeout - now.val;
}
@@ -4836,7 +4632,7 @@ void pd_task(void *u)
if (cc1 == TYPEC_CC_VOLT_OPEN) {
set_state(port, PD_STATE_SRC_DISCONNECTED);
/* Debouncing */
- timeout = 10*MSEC;
+ timeout = 10 * MSEC;
#ifdef CONFIG_USB_PD_DUAL_ROLE
/*
* If Try.SRC is configured, then ATTACHED_SRC
@@ -4848,8 +4644,8 @@ void pd_task(void *u)
pd_set_power_role(port, PD_ROLE_SINK);
tcpm_set_cc(port, TYPEC_CC_RD);
/* Set timer for TryWait.SNK state */
- pd[port].try_src_marker = get_time().val
- + PD_T_DEBOUNCE;
+ pd[port].try_src_marker =
+ get_time().val + PD_T_DEBOUNCE;
/* Advance to TryWait.SNK state */
set_state(port,
PD_STATE_SNK_DISCONNECTED);
@@ -4874,7 +4670,7 @@ void pd_task(void *u)
/* Sink: detect disconnect by monitoring VBUS */
set_state(port, PD_STATE_SNK_DISCONNECTED);
/* set timeout small to reconnect fast */
- timeout = 5*MSEC;
+ timeout = 5 * MSEC;
}
#endif /* CONFIG_USB_PD_DUAL_ROLE */
}
@@ -4915,8 +4711,6 @@ static void pd_chipset_startup(void)
for (i = 0; i < board_get_usb_pd_port_count(); i++) {
pd_set_dual_role_no_wakeup(i, PD_DRP_TOGGLE_OFF);
pd[i].flags |= PD_FLAGS_CHECK_IDENTITY;
- /* Reset cable attributes and flags */
- reset_pd_cable(i);
task_set_event(PD_PORT_TO_TASK_ID(i),
PD_EVENT_POWER_STATE_CHANGE |
PD_EVENT_UPDATE_DUAL_ROLE);
@@ -5013,16 +4807,16 @@ void pd_send_hpd(int port, enum hpd_event hpd)
if (!opos)
return;
- data[0] = VDO_DP_STATUS((hpd == hpd_irq), /* IRQ_HPD */
- (hpd != hpd_low), /* HPD_HI|LOW */
- 0, /* request exit DP */
- 0, /* request exit USB */
- 0, /* MF pref */
- 1, /* enabled */
- 0, /* power low */
+ data[0] = VDO_DP_STATUS((hpd == hpd_irq), /* IRQ_HPD */
+ (hpd != hpd_low), /* HPD_HI|LOW */
+ 0, /* request exit DP */
+ 0, /* request exit USB */
+ 0, /* MF pref */
+ 1, /* enabled */
+ 0, /* power low */
0x2);
- pd_send_vdm(port, USB_SID_DISPLAYPORT,
- VDO_OPOS(opos) | CMD_ATTENTION, data, 1);
+ pd_send_vdm(port, USB_SID_DISPLAYPORT, VDO_OPOS(opos) | CMD_ATTENTION,
+ data, 1);
/* Wait until VDM is done. */
while (pd[0].vdm_state > 0)
task_wait_event(USB_PD_RX_TMOUT_US *
@@ -5037,15 +4831,15 @@ int pd_fetch_acc_log_entry(int port)
/* Cannot send a VDM now, the host should retry */
if (pd[port].vdm_state > 0)
return pd[port].vdm_state == VDM_STATE_BUSY ?
- EC_RES_BUSY : EC_RES_UNAVAILABLE;
+ EC_RES_BUSY :
+ EC_RES_UNAVAILABLE;
pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_GET_LOG, NULL, 0);
- timeout.val = get_time().val + 75*MSEC;
+ timeout.val = get_time().val + 75 * MSEC;
/* Wait until VDM is done */
- while ((pd[port].vdm_state > 0) &&
- (get_time().val < timeout.val))
- task_wait_event(10*MSEC);
+ while ((pd[port].vdm_state > 0) && (get_time().val < timeout.val))
+ task_wait_event(10 * MSEC);
if (pd[port].vdm_state > 0)
return EC_RES_TIMEOUT;
@@ -5096,7 +4890,7 @@ void pd_update_contract(int port)
#endif /* CONFIG_USB_PD_DUAL_ROLE */
-static int command_pd(int argc, char **argv)
+static int command_pd(int argc, const char **argv)
{
int port;
char *e;
@@ -5119,7 +4913,6 @@ static int command_pd(int argc, char **argv)
return EC_SUCCESS;
}
-
#ifdef CONFIG_CMD_PD
#ifdef CONFIG_CMD_PD_DEV_DUMP_INFO
else if (!strncasecmp(argv[1], "rwhashtable", 3)) {
@@ -5234,8 +5027,8 @@ static int command_pd(int argc, char **argv)
}
ccprintf("Pings %s\n",
- (pd[port].flags & PD_FLAGS_PING_ENABLED) ?
- "on" : "off");
+ (pd[port].flags & PD_FLAGS_PING_ENABLED) ? "on" :
+ "off");
} else if (!strncasecmp(argv[2], "vdm", 3)) {
if (argc < 4)
return EC_ERROR_PARAM_COUNT;
@@ -5250,11 +5043,11 @@ static int command_pd(int argc, char **argv)
pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_PING_ENABLE,
&enable, 1);
} else if (!strncasecmp(argv[3], "curr", 4)) {
- pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_CURRENT,
- NULL, 0);
+ pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_CURRENT, NULL,
+ 0);
} else if (!strncasecmp(argv[3], "vers", 4)) {
- pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_VERSION,
- NULL, 0);
+ pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_VERSION, NULL,
+ 0);
} else {
return EC_ERROR_PARAM_COUNT;
}
@@ -5293,8 +5086,7 @@ static int command_pd(int argc, char **argv)
else if (!strcasecmp(argv[3], "sink"))
pd_set_dual_role(port, PD_DRP_FORCE_SINK);
else if (!strcasecmp(argv[3], "source"))
- pd_set_dual_role(port,
- PD_DRP_FORCE_SOURCE);
+ pd_set_dual_role(port, PD_DRP_FORCE_SOURCE);
else
return EC_ERROR_PARAM4;
}
@@ -5302,17 +5094,17 @@ static int command_pd(int argc, char **argv)
#endif
} else
#endif
- if (!strncasecmp(argv[2], "state", 5)) {
+ if (!strncasecmp(argv[2], "state", 5)) {
ccprintf("Port C%d CC%d, %s - Role: %s-%s%s "
"State: %d(%s), Flags: 0x%04x\n",
- port, pd[port].polarity + 1,
- pd_comm_is_enabled(port) ? "Ena" : "Dis",
- pd[port].power_role == PD_ROLE_SOURCE ? "SRC" : "SNK",
- pd[port].data_role == PD_ROLE_DFP ? "DFP" : "UFP",
- (pd[port].flags & PD_FLAGS_VCONN_ON) ? "-VC" : "",
- pd[port].task_state,
- debug_level > 0 ? pd_get_task_state_name(port) : "",
- pd[port].flags);
+ port, pd[port].polarity + 1,
+ pd_comm_is_enabled(port) ? "Ena" : "Dis",
+ pd[port].power_role == PD_ROLE_SOURCE ? "SRC" : "SNK",
+ pd[port].data_role == PD_ROLE_DFP ? "DFP" : "UFP",
+ (pd[port].flags & PD_FLAGS_VCONN_ON) ? "-VC" : "",
+ pd[port].task_state,
+ debug_level > 0 ? pd_get_task_state_name(port) : "",
+ pd[port].flags);
} else {
return EC_ERROR_PARAM1;
}
@@ -5360,9 +5152,8 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
if (p->size + sizeof(*p) > args->params_size)
return EC_RES_INVALID_PARAM;
-#if defined(CONFIG_BATTERY) && \
- (defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
- defined(CONFIG_BATTERY_PRESENT_GPIO))
+#if defined(CONFIG_BATTERY) && (defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
+ defined(CONFIG_BATTERY_PRESENT_GPIO))
/*
* Do not allow PD firmware update if no battery and this port
* is sinking power, because we will lose power.
@@ -5400,7 +5191,7 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
case USB_PD_FW_ERASE_SIG:
pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_ERASE_SIG, NULL, 0);
- timeout.val = get_time().val + 500*MSEC;
+ timeout.val = get_time().val + 500 * MSEC;
break;
case USB_PD_FW_FLASH_WRITE:
@@ -5412,12 +5203,12 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
for (i = 0; i < size; i += VDO_MAX_SIZE - 1) {
pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_FLASH_WRITE,
data + i, MIN(size - i, VDO_MAX_SIZE - 1));
- timeout.val = get_time().val + 500*MSEC;
+ timeout.val = get_time().val + 500 * MSEC;
/* Wait until VDM is done */
while ((pd[port].vdm_state > 0) &&
(get_time().val < timeout.val))
- task_wait_event(10*MSEC);
+ task_wait_event(10 * MSEC);
if (pd[port].vdm_state > 0)
return EC_RES_TIMEOUT;
@@ -5431,7 +5222,7 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
/* Wait until VDM is done or timeout */
while ((pd[port].vdm_state > 0) && (get_time().val < timeout.val))
- task_wait_event(50*MSEC);
+ task_wait_event(50 * MSEC);
if ((pd[port].vdm_state > 0) ||
(pd[port].vdm_state == VDM_STATE_ERR_TMOUT))
@@ -5441,12 +5232,8 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
return rv;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_PD_FW_UPDATE,
- hc_remote_flash,
- EC_VER_MASK(0));
+DECLARE_HOST_COMMAND(EC_CMD_USB_PD_FW_UPDATE, hc_remote_flash, EC_VER_MASK(0));
#endif /* CONFIG_HOSTCMD_FLASHPD */
#endif /* HAS_TASK_HOSTCMD */
-
-
#endif /* CONFIG_COMMON_RUNTIME */
diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c
index 1aaee29abc..c8010a5005 100644
--- a/common/usb_pd_tcpc.c
+++ b/common/usb_pd_tcpc.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -24,8 +24,8 @@
#include "usb_pd_tcpm.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
/*
* Debug log level - higher number == more log
@@ -45,93 +45,93 @@ static const int debug_level;
#endif
/* Encode 5 bits using Biphase Mark Coding */
-#define BMC(x) ((x & 1 ? 0x001 : 0x3FF) \
- ^ (x & 2 ? 0x004 : 0x3FC) \
- ^ (x & 4 ? 0x010 : 0x3F0) \
- ^ (x & 8 ? 0x040 : 0x3C0) \
- ^ (x & 16 ? 0x100 : 0x300))
+#define BMC(x) \
+ ((x & 1 ? 0x001 : 0x3FF) ^ (x & 2 ? 0x004 : 0x3FC) ^ \
+ (x & 4 ? 0x010 : 0x3F0) ^ (x & 8 ? 0x040 : 0x3C0) ^ \
+ (x & 16 ? 0x100 : 0x300))
/* 4b/5b + Bimark Phase encoding */
static const uint16_t bmc4b5b[] = {
-/* 0 = 0000 */ BMC(0x1E) /* 11110 */,
-/* 1 = 0001 */ BMC(0x09) /* 01001 */,
-/* 2 = 0010 */ BMC(0x14) /* 10100 */,
-/* 3 = 0011 */ BMC(0x15) /* 10101 */,
-/* 4 = 0100 */ BMC(0x0A) /* 01010 */,
-/* 5 = 0101 */ BMC(0x0B) /* 01011 */,
-/* 6 = 0110 */ BMC(0x0E) /* 01110 */,
-/* 7 = 0111 */ BMC(0x0F) /* 01111 */,
-/* 8 = 1000 */ BMC(0x12) /* 10010 */,
-/* 9 = 1001 */ BMC(0x13) /* 10011 */,
-/* A = 1010 */ BMC(0x16) /* 10110 */,
-/* B = 1011 */ BMC(0x17) /* 10111 */,
-/* C = 1100 */ BMC(0x1A) /* 11010 */,
-/* D = 1101 */ BMC(0x1B) /* 11011 */,
-/* E = 1110 */ BMC(0x1C) /* 11100 */,
-/* F = 1111 */ BMC(0x1D) /* 11101 */,
-/* Sync-1 K-code 11000 Startsynch #1 */
-/* Sync-2 K-code 10001 Startsynch #2 */
-/* RST-1 K-code 00111 Hard Reset #1 */
-/* RST-2 K-code 11001 Hard Reset #2 */
-/* EOP K-code 01101 EOP End Of Packet */
-/* Reserved Error 00000 */
-/* Reserved Error 00001 */
-/* Reserved Error 00010 */
-/* Reserved Error 00011 */
-/* Reserved Error 00100 */
-/* Reserved Error 00101 */
-/* Reserved Error 00110 */
-/* Reserved Error 01000 */
-/* Reserved Error 01100 */
-/* Reserved Error 10000 */
-/* Reserved Error 11111 */
+ /* 0 = 0000 */ BMC(0x1E) /* 11110 */,
+ /* 1 = 0001 */ BMC(0x09) /* 01001 */,
+ /* 2 = 0010 */ BMC(0x14) /* 10100 */,
+ /* 3 = 0011 */ BMC(0x15) /* 10101 */,
+ /* 4 = 0100 */ BMC(0x0A) /* 01010 */,
+ /* 5 = 0101 */ BMC(0x0B) /* 01011 */,
+ /* 6 = 0110 */ BMC(0x0E) /* 01110 */,
+ /* 7 = 0111 */ BMC(0x0F) /* 01111 */,
+ /* 8 = 1000 */ BMC(0x12) /* 10010 */,
+ /* 9 = 1001 */ BMC(0x13) /* 10011 */,
+ /* A = 1010 */ BMC(0x16) /* 10110 */,
+ /* B = 1011 */ BMC(0x17) /* 10111 */,
+ /* C = 1100 */ BMC(0x1A) /* 11010 */,
+ /* D = 1101 */ BMC(0x1B) /* 11011 */,
+ /* E = 1110 */ BMC(0x1C) /* 11100 */,
+ /* F = 1111 */ BMC(0x1D) /* 11101 */,
+ /* Sync-1 K-code 11000 Startsynch #1 */
+ /* Sync-2 K-code 10001 Startsynch #2 */
+ /* RST-1 K-code 00111 Hard Reset #1 */
+ /* RST-2 K-code 11001 Hard Reset #2 */
+ /* EOP K-code 01101 EOP End Of Packet */
+ /* Reserved Error 00000 */
+ /* Reserved Error 00001 */
+ /* Reserved Error 00010 */
+ /* Reserved Error 00011 */
+ /* Reserved Error 00100 */
+ /* Reserved Error 00101 */
+ /* Reserved Error 00110 */
+ /* Reserved Error 01000 */
+ /* Reserved Error 01100 */
+ /* Reserved Error 10000 */
+ /* Reserved Error 11111 */
};
static const uint8_t dec4b5b[] = {
-/* Error */ 0x10 /* 00000 */,
-/* Error */ 0x10 /* 00001 */,
-/* Error */ 0x10 /* 00010 */,
-/* Error */ 0x10 /* 00011 */,
-/* Error */ 0x10 /* 00100 */,
-/* Error */ 0x10 /* 00101 */,
-/* Error */ 0x10 /* 00110 */,
-/* RST-1 */ 0x13 /* 00111 K-code: Hard Reset #1 */,
-/* Error */ 0x10 /* 01000 */,
-/* 1 = 0001 */ 0x01 /* 01001 */,
-/* 4 = 0100 */ 0x04 /* 01010 */,
-/* 5 = 0101 */ 0x05 /* 01011 */,
-/* Error */ 0x10 /* 01100 */,
-/* EOP */ 0x15 /* 01101 K-code: EOP End Of Packet */,
-/* 6 = 0110 */ 0x06 /* 01110 */,
-/* 7 = 0111 */ 0x07 /* 01111 */,
-/* Error */ 0x10 /* 10000 */,
-/* Sync-2 */ 0x12 /* 10001 K-code: Startsynch #2 */,
-/* 8 = 1000 */ 0x08 /* 10010 */,
-/* 9 = 1001 */ 0x09 /* 10011 */,
-/* 2 = 0010 */ 0x02 /* 10100 */,
-/* 3 = 0011 */ 0x03 /* 10101 */,
-/* A = 1010 */ 0x0A /* 10110 */,
-/* B = 1011 */ 0x0B /* 10111 */,
-/* Sync-1 */ 0x11 /* 11000 K-code: Startsynch #1 */,
-/* RST-2 */ 0x14 /* 11001 K-code: Hard Reset #2 */,
-/* C = 1100 */ 0x0C /* 11010 */,
-/* D = 1101 */ 0x0D /* 11011 */,
-/* E = 1110 */ 0x0E /* 11100 */,
-/* F = 1111 */ 0x0F /* 11101 */,
-/* 0 = 0000 */ 0x00 /* 11110 */,
-/* Error */ 0x10 /* 11111 */,
+ /* Error */ 0x10 /* 00000 */,
+ /* Error */ 0x10 /* 00001 */,
+ /* Error */ 0x10 /* 00010 */,
+ /* Error */ 0x10 /* 00011 */,
+ /* Error */ 0x10 /* 00100 */,
+ /* Error */ 0x10 /* 00101 */,
+ /* Error */ 0x10 /* 00110 */,
+ /* RST-1 */ 0x13 /* 00111 K-code: Hard Reset #1 */,
+ /* Error */ 0x10 /* 01000 */,
+ /* 1 = 0001 */ 0x01 /* 01001 */,
+ /* 4 = 0100 */ 0x04 /* 01010 */,
+ /* 5 = 0101 */ 0x05 /* 01011 */,
+ /* Error */ 0x10 /* 01100 */,
+ /* EOP */ 0x15 /* 01101 K-code: EOP End Of Packet */,
+ /* 6 = 0110 */ 0x06 /* 01110 */,
+ /* 7 = 0111 */ 0x07 /* 01111 */,
+ /* Error */ 0x10 /* 10000 */,
+ /* Sync-2 */ 0x12 /* 10001 K-code: Startsynch #2 */,
+ /* 8 = 1000 */ 0x08 /* 10010 */,
+ /* 9 = 1001 */ 0x09 /* 10011 */,
+ /* 2 = 0010 */ 0x02 /* 10100 */,
+ /* 3 = 0011 */ 0x03 /* 10101 */,
+ /* A = 1010 */ 0x0A /* 10110 */,
+ /* B = 1011 */ 0x0B /* 10111 */,
+ /* Sync-1 */ 0x11 /* 11000 K-code: Startsynch #1 */,
+ /* RST-2 */ 0x14 /* 11001 K-code: Hard Reset #2 */,
+ /* C = 1100 */ 0x0C /* 11010 */,
+ /* D = 1101 */ 0x0D /* 11011 */,
+ /* E = 1110 */ 0x0E /* 11100 */,
+ /* F = 1111 */ 0x0F /* 11101 */,
+ /* 0 = 0000 */ 0x00 /* 11110 */,
+ /* Error */ 0x10 /* 11111 */,
};
/* Start of Packet sequence : three Sync-1 K-codes, then one Sync-2 K-code */
-#define PD_SOP (PD_SYNC1 | (PD_SYNC1<<5) | (PD_SYNC1<<10) | (PD_SYNC2<<15))
-#define PD_SOP_PRIME (PD_SYNC1 | (PD_SYNC1<<5) | \
- (PD_SYNC3<<10) | (PD_SYNC3<<15))
-#define PD_SOP_PRIME_PRIME (PD_SYNC1 | (PD_SYNC3<<5) | \
- (PD_SYNC1<<10) | (PD_SYNC3<<15))
+#define PD_SOP \
+ (PD_SYNC1 | (PD_SYNC1 << 5) | (PD_SYNC1 << 10) | (PD_SYNC2 << 15))
+#define PD_SOP_PRIME \
+ (PD_SYNC1 | (PD_SYNC1 << 5) | (PD_SYNC3 << 10) | (PD_SYNC3 << 15))
+#define PD_SOP_PRIME_PRIME \
+ (PD_SYNC1 | (PD_SYNC3 << 5) | (PD_SYNC1 << 10) | (PD_SYNC3 << 15))
/* Hard Reset sequence : three RST-1 K-codes, then one RST-2 K-code */
-#define PD_HARD_RESET (PD_RST1 | (PD_RST1 << 5) |\
- (PD_RST1 << 10) | (PD_RST2 << 15))
+#define PD_HARD_RESET \
+ (PD_RST1 | (PD_RST1 << 5) | (PD_RST1 << 10) | (PD_RST2 << 15))
/*
* Polarity based on 'DFP Perspective' (see table USB Type-C Cable and Connector
@@ -159,11 +159,11 @@ static const uint8_t dec4b5b[] = {
#endif
#ifndef CC_RA
-#define CC_RA(port, cc, sel) (cc < PD_SRC_RD_THRESHOLD)
+#define CC_RA(port, cc, sel) (cc < PD_SRC_RD_THRESHOLD)
#endif
#define CC_RD(cc) ((cc >= PD_SRC_RD_THRESHOLD) && (cc < PD_SRC_VNC))
#ifndef CC_NC
-#define CC_NC(port, cc, sel) (cc >= PD_SRC_VNC)
+#define CC_NC(port, cc, sel) (cc >= PD_SRC_VNC)
#endif
/*
@@ -180,16 +180,16 @@ static const uint8_t dec4b5b[] = {
#define PD_SNK_VA PD_SNK_VA_MV
#endif
-#define CC_RP(cc) (cc >= PD_SNK_VA)
+#define CC_RP(cc) (cc >= PD_SNK_VA)
/*
* Type C power source charge current limits are identified by their cc
* voltage (set by selecting the proper Rd resistor). Any voltage below
* TYPE_C_SRC_500_THRESHOLD will not be identified as a type C charger.
*/
-#define TYPE_C_SRC_500_THRESHOLD PD_SRC_RD_THRESHOLD
-#define TYPE_C_SRC_1500_THRESHOLD 660 /* mV */
-#define TYPE_C_SRC_3000_THRESHOLD 1230 /* mV */
+#define TYPE_C_SRC_500_THRESHOLD PD_SRC_RD_THRESHOLD
+#define TYPE_C_SRC_1500_THRESHOLD 660 /* mV */
+#define TYPE_C_SRC_3000_THRESHOLD 1230 /* mV */
/* Convert TCPC Alert register to index into pd.alert[] */
#define ALERT_REG_TO_INDEX(reg) (reg - TCPC_REG_ALERT)
@@ -254,8 +254,8 @@ static struct pd_port_controller {
#endif
/* Last received */
- int rx_head[RX_BUFFER_SIZE+1];
- uint32_t rx_payload[RX_BUFFER_SIZE+1][7];
+ int rx_head[RX_BUFFER_SIZE + 1];
+ uint32_t rx_payload[RX_BUFFER_SIZE + 1][7];
int rx_buf_head, rx_buf_tail;
/* Next transmit */
@@ -309,7 +309,7 @@ int encode_word(int port, int off, uint32_t val32)
/* prepare a 4b/5b-encoded PD message to send */
int prepare_message(int port, uint16_t header, uint8_t cnt,
- const uint32_t *data)
+ const uint32_t *data)
{
int off, i;
/* 64-bit preamble */
@@ -387,8 +387,8 @@ static int send_validate_message(int port, uint16_t header,
uint8_t expected_msg_id = PD_HEADER_ID(header);
uint8_t cnt = PD_HEADER_CNT(header);
int retries = PD_HEADER_TYPE(header) == PD_DATA_SOURCE_CAP ?
- 0 :
- CONFIG_PD_RETRY_COUNT;
+ 0 :
+ CONFIG_PD_RETRY_COUNT;
/* retry 3 times if we are not getting a valid answer */
for (r = 0; r <= retries; r++) {
@@ -464,7 +464,7 @@ static int send_validate_message(int port, uint16_t header,
static void send_goodcrc(int port, int id)
{
uint16_t header = PD_HEADER(PD_CTRL_GOOD_CRC, pd[port].power_role,
- pd[port].data_role, id, 0, 0, 0);
+ pd[port].data_role, id, 0, 0, 0);
int bit_len = prepare_message(port, header, 0, NULL);
if (pd_start_tx(port, pd[port].polarity, bit_len) < 0)
@@ -536,7 +536,7 @@ static void bist_mode_2_tx(int port)
* build context buffer with 5 bytes, where the data is
* alternating 1's and 0's.
*/
- bit = pd_write_sym(port, 0, BMC(0x15));
+ bit = pd_write_sym(port, 0, BMC(0x15));
bit = pd_write_sym(port, bit, BMC(0x0a));
bit = pd_write_sym(port, bit, BMC(0x15));
bit = pd_write_sym(port, bit, BMC(0x0a));
@@ -566,10 +566,9 @@ static inline int decode_short(int port, int off, uint16_t *val16)
dec4b5b[(w >> 15) & 0x1f], dec4b5b[(w >> 10) & 0x1f],
dec4b5b[(w >> 5) & 0x1f], dec4b5b[(w >> 0) & 0x1f]);
#endif
- *val16 = dec4b5b[w & 0x1f] |
- (dec4b5b[(w >> 5) & 0x1f] << 4) |
- (dec4b5b[(w >> 10) & 0x1f] << 8) |
- (dec4b5b[(w >> 15) & 0x1f] << 12);
+ *val16 = dec4b5b[w & 0x1f] | (dec4b5b[(w >> 5) & 0x1f] << 4) |
+ (dec4b5b[(w >> 10) & 0x1f] << 8) |
+ (dec4b5b[(w >> 15) & 0x1f] << 12);
return end;
}
@@ -674,7 +673,7 @@ int pd_analyze_rx(int port, uint32_t *payload)
#else /* CONFIG_USB_VPD || CONFIG_USB_CTVPD */
#ifdef CONFIG_USB_PD_DECODE_SOP
if (val == PD_SOP || val == PD_SOP_PRIME ||
- val == PD_SOP_PRIME_PRIME)
+ val == PD_SOP_PRIME_PRIME)
break;
#else
if (val == PD_SOP) {
@@ -734,7 +733,7 @@ int pd_analyze_rx(int port, uint32_t *payload)
/* read payload data */
for (p = 0; p < cnt && bit > 0; p++) {
- bit = decode_word(port, bit, payload+p);
+ bit = decode_word(port, bit, payload + p);
crc32_hash32(payload[p]);
}
ccrc = crc32_result();
@@ -801,7 +800,7 @@ static int cc_voltage_to_status(int port, int cc_volt, int cc_sel)
return TYPEC_CC_VOLT_RA;
else
return TYPEC_CC_VOLT_RD;
- /* If we have a pull-down, then we are sink, check for Rp. */
+ /* If we have a pull-down, then we are sink, check for Rp. */
}
#ifdef CONFIG_USB_PD_DUAL_ROLE
else if (pd[port].cc_pull == TYPEC_CC_RD) {
@@ -843,9 +842,8 @@ int tcpc_run(int port, int evt)
/* incoming packet ? */
if (pd_rx_started(port) && pd[port].rx_enabled) {
/* Get message and place at RX buffer head */
- res = pd[port].rx_head[pd[port].rx_buf_head] =
- pd_analyze_rx(port,
- pd[port].rx_payload[pd[port].rx_buf_head]);
+ res = pd[port].rx_head[pd[port].rx_buf_head] = pd_analyze_rx(
+ port, pd[port].rx_payload[pd[port].rx_buf_head]);
pd_rx_complete(port);
/*
@@ -872,9 +870,8 @@ int tcpc_run(int port, int evt)
#else
case TCPCI_MSG_SOP:
#endif
- res = send_validate_message(port,
- pd[port].tx_head,
- pd[port].tx_data);
+ res = send_validate_message(port, pd[port].tx_head,
+ pd[port].tx_data);
break;
case TCPCI_MSG_TX_BIST_MODE_2:
bist_mode_2_tx(port);
@@ -929,11 +926,11 @@ int tcpc_run(int port, int evt)
*/
return (get_time().val >= pd[port].low_power_ts.val &&
pd[port].cc_pull == TYPEC_CC_RD &&
- cc_is_open(pd[port].cc_status[0], pd[port].cc_status[1]))
- ? 200 * MSEC
- : 10 * MSEC;
+ cc_is_open(pd[port].cc_status[0], pd[port].cc_status[1])) ?
+ 200 * MSEC :
+ 10 * MSEC;
#else
- return 10*MSEC;
+ return 10 * MSEC;
#endif
}
@@ -941,7 +938,7 @@ int tcpc_run(int port, int evt)
void pd_task(void *u)
{
int port = TASK_ID_TO_PD_PORT(task_get_current());
- int timeout = 10*MSEC;
+ int timeout = 10 * MSEC;
int evt;
/* initialize phy task */
@@ -1024,8 +1021,8 @@ int tcpc_set_cc(int port, int pull)
* because we only want to go into low power mode when we are not
* dual-role toggling.
*/
- pd[port].low_power_ts.val = get_time().val +
- 2*(PD_T_DRP_SRC + PD_T_DRP_SNK);
+ pd[port].low_power_ts.val =
+ get_time().val + 2 * (PD_T_DRP_SRC + PD_T_DRP_SNK);
#endif
/*
@@ -1047,7 +1044,7 @@ int tcpc_set_cc(int port, int pull)
}
int tcpc_get_cc(int port, enum tcpc_cc_voltage_status *cc1,
- enum tcpc_cc_voltage_status *cc2)
+ enum tcpc_cc_voltage_status *cc2)
{
*cc2 = pd[port].cc_status[1];
*cc1 = pd[port].cc_status[0];
@@ -1184,8 +1181,9 @@ void tcpc_init(int port)
/* Initialize physical layer */
pd_hw_init(port, PD_ROLE_DEFAULT(port));
- pd[port].cc_pull = PD_ROLE_DEFAULT(port) ==
- PD_ROLE_SOURCE ? TYPEC_CC_RP : TYPEC_CC_RD;
+ pd[port].cc_pull = PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE ?
+ TYPEC_CC_RP :
+ TYPEC_CC_RD;
#ifdef TCPC_LOW_POWER
/* Don't use low power immediately after boot */
pd[port].low_power_ts.val = get_time().val + SECOND;
@@ -1196,16 +1194,15 @@ void tcpc_init(int port)
/* make initial readings of CC voltages */
for (i = 0; i < 2; i++) {
- pd[port].cc_status[i] = cc_voltage_to_status(port,
- pd_adc_read(port, i),
- i);
+ pd[port].cc_status[i] =
+ cc_voltage_to_status(port, pd_adc_read(port, i), i);
}
#ifdef CONFIG_USB_PD_TCPC_TRACK_VBUS
#if CONFIG_USB_PD_PORT_MAX_COUNT >= 2
- tcpc_set_power_status(port, !gpio_get_level(port ?
- GPIO_USB_C1_VBUS_WAKE_L :
- GPIO_USB_C0_VBUS_WAKE_L));
+ tcpc_set_power_status(port,
+ !gpio_get_level(port ? GPIO_USB_C1_VBUS_WAKE_L :
+ GPIO_USB_C0_VBUS_WAKE_L));
#else
tcpc_set_power_status(port, !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
#endif /* CONFIG_USB_PD_PORT_MAX_COUNT >= 2 */
@@ -1223,7 +1220,7 @@ void tcpc_init(int port)
void pd_vbus_evt_p0(enum gpio_signal signal)
{
tcpc_set_power_status(TASK_ID_TO_PD_PORT(TASK_ID_PD_C0),
- !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
+ !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
task_wake(TASK_ID_PD_C0);
}
@@ -1234,7 +1231,7 @@ void pd_vbus_evt_p1(enum gpio_signal signal)
return;
tcpc_set_power_status(TASK_ID_TO_PD_PORT(TASK_ID_PD_C1),
- !gpio_get_level(GPIO_USB_C1_VBUS_WAKE_L));
+ !gpio_get_level(GPIO_USB_C1_VBUS_WAKE_L));
task_wake(TASK_ID_PD_C1);
}
#endif /* PD_PORT_COUNT >= 2 */
@@ -1277,8 +1274,8 @@ static void tcpc_i2c_write(int port, int reg, int len, uint8_t *payload)
tcpc_alert_mask_set(port, alert);
break;
case TCPC_REG_RX_DETECT:
- tcpc_set_rx_enable(port, payload[1] &
- TCPC_REG_RX_DETECT_SOP_HRST_MASK);
+ tcpc_set_rx_enable(
+ port, payload[1] & TCPC_REG_RX_DETECT_SOP_HRST_MASK);
break;
case TCPC_REG_POWER_STATUS_MASK:
tcpc_set_power_status_mask(port, payload[1]);
@@ -1308,12 +1305,11 @@ static int tcpc_i2c_read(int port, int reg, uint8_t *payload)
case TCPC_REG_CC_STATUS:
tcpc_get_cc(port, &cc1, &cc2);
payload[0] = TCPC_REG_CC_STATUS_SET(
- pd[port].cc_pull == TYPEC_CC_RD,
- pd[port].cc_status[0], pd[port].cc_status[1]);
+ pd[port].cc_pull == TYPEC_CC_RD, pd[port].cc_status[0],
+ pd[port].cc_status[1]);
return 1;
case TCPC_REG_ROLE_CTRL:
- payload[0] = TCPC_REG_ROLE_CTRL_SET(0, 0,
- pd[port].cc_pull,
+ payload[0] = TCPC_REG_ROLE_CTRL_SET(0, 0, pd[port].cc_pull,
pd[port].cc_pull);
return 1;
case TCPC_REG_TCPC_CTRL:
@@ -1325,7 +1321,8 @@ static int tcpc_i2c_read(int port, int reg, uint8_t *payload)
return 1;
case TCPC_REG_RX_DETECT:
payload[0] = pd[port].rx_enabled ?
- TCPC_REG_RX_DETECT_SOP_HRST_MASK : 0;
+ TCPC_REG_RX_DETECT_SOP_HRST_MASK :
+ 0;
return 1;
case TCPC_REG_ALERT:
tcpc_alert_status(port, &alert);
@@ -1337,13 +1334,14 @@ static int tcpc_i2c_read(int port, int reg, uint8_t *payload)
payload[1] = (pd[port].alert_mask >> 8) & 0xff;
return 2;
case TCPC_REG_RX_BYTE_CNT:
- payload[0] = 3 + 4 *
- PD_HEADER_CNT(pd[port].rx_head[pd[port].rx_buf_tail]);
+ payload[0] =
+ 3 + 4 * PD_HEADER_CNT(
+ pd[port].rx_head[pd[port].rx_buf_tail]);
return 1;
case TCPC_REG_RX_HDR:
payload[0] = pd[port].rx_head[pd[port].rx_buf_tail] & 0xff;
- payload[1] =
- (pd[port].rx_head[pd[port].rx_buf_tail] >> 8) & 0xff;
+ payload[1] = (pd[port].rx_head[pd[port].rx_buf_tail] >> 8) &
+ 0xff;
return 2;
case TCPC_REG_RX_DATA:
memcpy(payload, pd[port].rx_payload[pd[port].rx_buf_tail],
@@ -1408,7 +1406,7 @@ void tcpc_i2c_process(int read, int port, int len, uint8_t *payload,
#endif
#ifdef CONFIG_COMMON_RUNTIME
-static int command_tcpc(int argc, char **argv)
+static int command_tcpc(int argc, const char **argv)
{
int port;
char *e;
@@ -1452,12 +1450,12 @@ static int command_tcpc(int argc, char **argv)
} else if (!strncasecmp(argv[2], "state", 5)) {
ccprintf("Port C%d, %s - CC:%d, CC0:%d, CC1:%d\n"
"Alert: 0x%02x Mask: 0x%04x\n"
- "Power Status: 0x%02x Mask: 0x%02x\n", port,
- pd[port].rx_enabled ? "Ena" : "Dis",
- pd[port].cc_pull,
- pd[port].cc_status[0], pd[port].cc_status[1],
- pd[port].alert, pd[port].alert_mask,
- pd[port].power_status, pd[port].power_status_mask);
+ "Power Status: 0x%02x Mask: 0x%02x\n",
+ port, pd[port].rx_enabled ? "Ena" : "Dis",
+ pd[port].cc_pull, pd[port].cc_status[0],
+ pd[port].cc_status[1], pd[port].alert,
+ pd[port].alert_mask, pd[port].power_status,
+ pd[port].power_status_mask);
}
return EC_SUCCESS;
diff --git a/common/usb_port_power_dumb.c b/common/usb_port_power_dumb.c
index ea2d4eb668..10eca3ffb7 100644
--- a/common/usb_port_power_dumb.c
+++ b/common/usb_port_power_dumb.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,7 +16,7 @@
#include "util.h"
#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr)
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
static uint8_t charge_mode[USB_PORT_COUNT];
@@ -75,20 +75,19 @@ usb_port_command_set_mode(struct host_cmd_handler_args *args)
{
const struct ec_params_usb_charge_set_mode *p = args->params;
- if (usb_charge_set_mode(p->usb_port_id, p->mode,
- p->inhibit_charge) != EC_SUCCESS)
+ if (usb_charge_set_mode(p->usb_port_id, p->mode, p->inhibit_charge) !=
+ EC_SUCCESS)
return EC_RES_ERROR;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE,
- usb_port_command_set_mode,
+DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE, usb_port_command_set_mode,
EC_VER_MASK(0));
/*****************************************************************************/
/* Console commands */
-static int command_set_mode(int argc, char **argv)
+static int command_set_mode(int argc, const char **argv)
{
int port_id = -1;
int mode = -1;
@@ -108,18 +107,16 @@ static int command_set_mode(int argc, char **argv)
/* fallthrough */
case 1:
for (i = 0; i < USB_PORT_COUNT; i++)
- ccprintf("Port %d: %s\n",
- i, charge_mode[i] ? "on" : "off");
+ ccprintf("Port %d: %s\n", i,
+ charge_mode[i] ? "on" : "off");
return EC_SUCCESS;
}
return EC_ERROR_PARAM_COUNT;
}
-DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode,
- "[<port> <on | off>]",
+DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode, "[<port> <on | off>]",
"Set USB charge mode");
-
/*****************************************************************************/
/* Hooks */
@@ -135,10 +132,10 @@ static void usb_port_init(void)
const uint8_t *prev;
int version, size, i;
- prev = (const uint8_t *)system_get_jump_tag(USB_SYSJUMP_TAG,
- &version, &size);
+ prev = (const uint8_t *)system_get_jump_tag(USB_SYSJUMP_TAG, &version,
+ &size);
if (!prev || version != USB_HOOK_VERSION ||
- size != sizeof(charge_mode)) {
+ size != sizeof(charge_mode)) {
usb_port_all_ports_off();
return;
}
@@ -162,4 +159,4 @@ static void usb_port_shutdown(void)
usb_port_all_ports_off();
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, usb_port_shutdown, HOOK_PRIO_DEFAULT);
-#endif /* CONFIG_USB_PORT_POWER_DUMB_CUSTOM_HOOK */
+#endif /* CONFIG_USB_PORT_POWER_DUMB_CUSTOM_HOOK */
diff --git a/common/usb_port_power_smart.c b/common/usb_port_power_smart.c
index 3143bdf400..42fbc7dd64 100644
--- a/common/usb_port_power_smart.c
+++ b/common/usb_port_power_smart.c
@@ -1,10 +1,11 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* USB charging control module for Chrome EC */
+#include "builtin/assert.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -16,15 +17,15 @@
#include "util.h"
#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr)
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
#ifndef CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE
#define CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE USB_CHARGE_MODE_SDP2
#endif
struct charge_mode_t {
- uint8_t mode:7;
- uint8_t inhibit_charging_in_suspend:1;
+ uint8_t mode : 7;
+ uint8_t inhibit_charging_in_suspend : 1;
} __pack;
static struct charge_mode_t charge_mode[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT];
@@ -34,7 +35,9 @@ static struct charge_mode_t charge_mode[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT];
* If we only support CDP and SDP, the control signals are hard-wired so
* there's nothing to do. The only to do is set ILIM_SEL.
*/
-static void usb_charge_set_control_mode(int port_id, int mode) {}
+static void usb_charge_set_control_mode(int port_id, int mode)
+{
+}
#else /* !defined(CONFIG_USB_PORT_POWER_SMART_CDP_SDP_ONLY) */
static void usb_charge_set_control_mode(int port_id, int mode)
{
@@ -74,7 +77,7 @@ static void usb_charge_set_ilim(int port_id, int sel)
{
int ilim_sel;
-#if defined(CONFIG_USB_PORT_POWER_SMART_SIMPLE) || \
+#if defined(CONFIG_USB_PORT_POWER_SMART_SIMPLE) || \
defined(CONFIG_USB_PORT_POWER_SMART_INVERTED)
/* ILIM_SEL is inverted. */
sel = !sel;
@@ -142,7 +145,7 @@ int usb_charge_set_mode(int port_id, enum usb_charge_mode mode,
/*****************************************************************************/
/* Console commands */
-static int command_set_mode(int argc, char **argv)
+static int command_set_mode(int argc, const char **argv)
{
int port_id = -1;
int mode = -1, inhibit_charge = 0;
@@ -152,7 +155,7 @@ static int command_set_mode(int argc, char **argv)
if (argc == 1) {
for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++)
ccprintf("Port %d: %d,%d\n", i, charge_mode[i].mode,
- charge_mode[i].inhibit_charging_in_suspend);
+ charge_mode[i].inhibit_charging_in_suspend);
return EC_SUCCESS;
}
@@ -188,14 +191,13 @@ usb_charge_command_set_mode(struct host_cmd_handler_args *args)
{
const struct ec_params_usb_charge_set_mode *p = args->params;
- if (usb_charge_set_mode(p->usb_port_id, p->mode,
- p->inhibit_charge) != EC_SUCCESS)
+ if (usb_charge_set_mode(p->usb_port_id, p->mode, p->inhibit_charge) !=
+ EC_SUCCESS)
return EC_RES_ERROR;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE,
- usb_charge_command_set_mode,
+DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE, usb_charge_command_set_mode,
EC_VER_MASK(0));
/*****************************************************************************/
@@ -213,18 +215,18 @@ static void usb_charge_init(void)
const struct charge_mode_t *prev;
int version, size, i;
- prev = (const struct charge_mode_t *)system_get_jump_tag(USB_SYSJUMP_TAG,
- &version, &size);
+ prev = (const struct charge_mode_t *)system_get_jump_tag(
+ USB_SYSJUMP_TAG, &version, &size);
if (!prev || version != USB_HOOK_VERSION ||
- size != sizeof(charge_mode)) {
+ size != sizeof(charge_mode)) {
usb_charge_all_ports_ctrl(USB_CHARGE_MODE_DISABLED);
return;
}
for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++)
usb_charge_set_mode(i, prev[i].mode,
- prev[i].inhibit_charging_in_suspend);
+ prev[i].inhibit_charging_in_suspend);
}
DECLARE_HOOK(HOOK_INIT, usb_charge_init, HOOK_PRIO_DEFAULT);
@@ -234,9 +236,8 @@ static void usb_charge_resume(void)
/* Turn on USB ports on as we go into S0 from S3 or S5. */
for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++)
- usb_charge_set_mode(i,
- CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE,
- charge_mode[i].inhibit_charging_in_suspend);
+ usb_charge_set_mode(i, CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE,
+ charge_mode[i].inhibit_charging_in_suspend);
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, usb_charge_resume, HOOK_PRIO_DEFAULT);
diff --git a/common/usb_update.c b/common/usb_update.c
index 3b307ede9a..444a4d6949 100644
--- a/common/usb_update.c
+++ b/common/usb_update.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -20,8 +20,8 @@
#include "usb-stream.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USB, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_USB, format, ##args)
/*
* This file is an adaptation layer between the USB interface and the firmware
@@ -47,37 +47,27 @@
struct consumer const update_consumer;
struct usb_stream_config const usb_update;
-static struct queue const update_to_usb = QUEUE_DIRECT(64, uint8_t,
- null_producer,
- usb_update.consumer);
-static struct queue const usb_to_update = QUEUE_DIRECT(64, uint8_t,
- usb_update.producer,
- update_consumer);
-
-USB_STREAM_CONFIG_FULL(usb_update,
- USB_IFACE_UPDATE,
- USB_CLASS_VENDOR_SPEC,
- USB_SUBCLASS_GOOGLE_UPDATE,
- USB_PROTOCOL_GOOGLE_UPDATE,
- USB_STR_UPDATE_NAME,
- USB_EP_UPDATE,
- USB_MAX_PACKET_SIZE,
- USB_MAX_PACKET_SIZE,
- usb_to_update,
- update_to_usb)
+static struct queue const update_to_usb =
+ QUEUE_DIRECT(64, uint8_t, null_producer, usb_update.consumer);
+static struct queue const usb_to_update =
+ QUEUE_DIRECT(64, uint8_t, usb_update.producer, update_consumer);
+USB_STREAM_CONFIG_FULL(usb_update, USB_IFACE_UPDATE, USB_CLASS_VENDOR_SPEC,
+ USB_SUBCLASS_GOOGLE_UPDATE, USB_PROTOCOL_GOOGLE_UPDATE,
+ USB_STR_UPDATE_NAME, USB_EP_UPDATE, USB_MAX_PACKET_SIZE,
+ USB_MAX_PACKET_SIZE, usb_to_update, update_to_usb)
/* The receiver can be in one of the states below. */
enum rx_state {
- rx_idle, /* Nothing happened yet. */
- rx_inside_block, /* Assembling a block to pass to the programmer. */
- rx_outside_block, /* Waiting for the next block to start or for the
- reset command. */
+ rx_idle, /* Nothing happened yet. */
+ rx_inside_block, /* Assembling a block to pass to the programmer. */
+ rx_outside_block, /* Waiting for the next block to start or for the
+ reset command. */
};
enum rx_state rx_state_ = rx_idle;
-static uint8_t block_buffer[sizeof(struct update_command) +
- CONFIG_UPDATE_PDU_SIZE];
+static uint8_t
+ block_buffer[sizeof(struct update_command) + CONFIG_UPDATE_PDU_SIZE];
static uint32_t block_size;
static uint32_t block_index;
@@ -117,8 +107,8 @@ static int pair_challenge(struct pair_challenge *challenge)
* tmp2 = device_private
* = HMAC_SHA256(device_secret, "device-identity")
*/
- hmac_SHA256(tmp2, tmp, CONFIG_ROLLBACK_SECRET_SIZE,
- KEY_CONTEXT, sizeof(KEY_CONTEXT) - 1);
+ hmac_SHA256(tmp2, tmp, CONFIG_ROLLBACK_SECRET_SIZE, KEY_CONTEXT,
+ sizeof(KEY_CONTEXT) - 1);
/* tmp = device_public = x25519(device_private, x25519_base_point) */
X25519_public_from_private(tmp, tmp2);
@@ -128,10 +118,11 @@ static int pair_challenge(struct pair_challenge *challenge)
X25519(tmp, tmp2, challenge->host_public);
/* tmp2 = authenticator = HMAC_SHA256(shared_secret, nonce) */
- hmac_SHA256(tmp2, tmp, sizeof(tmp),
- challenge->nonce, sizeof(challenge->nonce));
+ hmac_SHA256(tmp2, tmp, sizeof(tmp), challenge->nonce,
+ sizeof(challenge->nonce));
QUEUE_ADD_UNITS(&update_to_usb, tmp2,
- member_size(struct pair_challenge_response, authenticator));
+ member_size(struct pair_challenge_response,
+ authenticator));
return 1;
}
#endif
@@ -198,7 +189,8 @@ static int try_vendor_command(struct consumer const *consumer, size_t count)
/* Looks like this is a vendor command, let's verify it. */
if (update_pdu_valid(&cmd_buffer->cmd,
- count - offsetof(struct update_frame_header, cmd))) {
+ count - offsetof(struct update_frame_header,
+ cmd))) {
enum update_extra_command subcommand;
uint8_t response;
size_t response_size = sizeof(response);
@@ -267,8 +259,8 @@ static int try_vendor_command(struct consumer const *consumer, size_t count)
break;
#ifdef CONFIG_ROLLBACK
case UPDATE_EXTRA_CMD_UNLOCK_ROLLBACK:
- crec_flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT
- , 0);
+ crec_flash_set_protect(
+ EC_FLASH_PROTECT_ROLLBACK_AT_BOOT, 0);
response = EC_RES_SUCCESS;
break;
#ifdef CONFIG_ROLLBACK_SECRET_SIZE
@@ -295,8 +287,8 @@ static int try_vendor_command(struct consumer const *consumer, size_t count)
}
/* pair_challenge takes care of answering */
- return pair_challenge((struct pair_challenge *)
- (buffer + header_size));
+ return pair_challenge((
+ struct pair_challenge *)(buffer + header_size));
}
#endif
#endif /* CONFIG_ROLLBACK_SECRET_SIZE */
@@ -322,11 +314,10 @@ static int try_vendor_command(struct consumer const *consumer, size_t count)
#ifdef CONFIG_TOUCHPAD_HASH_FW
memcpy(tp.allowed_fw_hash, touchpad_fw_full_hash,
- sizeof(tp.allowed_fw_hash));
+ sizeof(tp.allowed_fw_hash));
#endif
#endif /* CONFIG_TOUCHPAD_VIRTUAL_OFF */
- QUEUE_ADD_UNITS(&update_to_usb,
- &tp, response_size);
+ QUEUE_ADD_UNITS(&update_to_usb, &tp, response_size);
return 1;
}
case UPDATE_EXTRA_CMD_TOUCHPAD_DEBUG: {
@@ -338,7 +329,8 @@ static int try_vendor_command(struct consumer const *consumer, size_t count)
* with the payload data, and put the response in data.
*/
response = touchpad_debug(buffer + header_size,
- data_count, &data, &write_count);
+ data_count, &data,
+ &write_count);
/*
* On error, or if there is no data to write back, just
@@ -374,11 +366,10 @@ static int try_vendor_command(struct consumer const *consumer, size_t count)
}
response = uart_console_read_buffer(
- data[0],
- (char *)output,
- MIN(sizeof(output),
- queue_space(&update_to_usb)),
- &write_count);
+ data[0], (char *)output,
+ MIN(sizeof(output),
+ queue_space(&update_to_usb)),
+ &write_count);
if (response != EC_RES_SUCCESS || write_count == 0)
break;
@@ -406,7 +397,7 @@ static uint64_t prev_activity_timestamp;
* A flag indicating that at least one valid PDU containing flash update block
* has been received in the current transfer session.
*/
-static uint8_t data_was_transferred;
+static uint8_t data_was_transferred;
/* Reply with an error to remote side, reset state. */
static void send_error_reset(uint8_t resp_value)
@@ -459,10 +450,10 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
* digest = 0, and base = 0.
*/
if (!fetch_transfer_start(consumer, count, &u.upfr) ||
- be32toh(u.upfr.block_size) !=
- sizeof(struct update_frame_header) ||
- u.upfr.cmd.block_digest != 0 ||
- u.upfr.cmd.block_base != 0) {
+ be32toh(u.upfr.block_size) !=
+ sizeof(struct update_frame_header) ||
+ u.upfr.cmd.block_digest != 0 ||
+ u.upfr.cmd.block_base != 0) {
/*
* Something is wrong, this payload is not a valid
* update start PDU. Let'w indicate this by returning
@@ -474,14 +465,14 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
}
CPRINTS("FW update: starting...");
- fw_update_command_handler(&u.upfr.cmd, count -
- offsetof(struct update_frame_header,
- cmd),
- &resp_size);
+ fw_update_command_handler(
+ &u.upfr.cmd,
+ count - offsetof(struct update_frame_header, cmd),
+ &resp_size);
if (!u.startup_resp.return_value) {
- rx_state_ = rx_outside_block; /* We're in business. */
- data_was_transferred = 0; /* No data received yet. */
+ rx_state_ = rx_outside_block; /* We're in business. */
+ data_was_transferred = 0; /* No data received yet. */
}
/* Let the host know what updater had to say. */
@@ -509,8 +500,7 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
}
resp_value = 0;
- QUEUE_ADD_UNITS(&update_to_usb,
- &resp_value, 1);
+ QUEUE_ADD_UNITS(&update_to_usb, &resp_value, 1);
rx_state_ = rx_idle;
return;
}
@@ -528,7 +518,7 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
/* Let's allocate a large enough buffer. */
block_size = be32toh(upfr.block_size) -
- offsetof(struct update_frame_header, cmd);
+ offsetof(struct update_frame_header, cmd);
/*
* Only update start PDU is allowed to have a size 0 payload.
@@ -545,7 +535,7 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
* to the updater.
*/
block_index = sizeof(upfr) -
- offsetof(struct update_frame_header, cmd);
+ offsetof(struct update_frame_header, cmd);
memcpy(block_buffer, &upfr.cmd, block_index);
block_size -= block_index;
rx_state_ = rx_inside_block;
@@ -567,7 +557,7 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
send_error_reset(UPDATE_GEN_ERROR);
return;
}
- return; /* More to come. */
+ return; /* More to come. */
}
/*
@@ -588,7 +578,7 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
struct consumer const update_consumer = {
.queue = &usb_to_update,
- .ops = &((struct consumer_ops const) {
+ .ops = &((struct consumer_ops const){
.written = update_out_handler,
}),
};
diff --git a/common/usbc/build.mk b/common/usbc/build.mk
index 60e2347741..15c9f06001 100644
--- a/common/usbc/build.mk
+++ b/common/usbc/build.mk
@@ -1,4 +1,4 @@
-# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Copyright 2019 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/common/usbc/dp_alt_mode.c b/common/usbc/dp_alt_mode.c
index 5cf3c03ba8..0f2a42ec2a 100644
--- a/common/usbc/dp_alt_mode.c
+++ b/common/usbc/dp_alt_mode.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,8 +11,8 @@
#include <stdbool.h>
#include <stdint.h>
-#include "assert.h"
#include "atomic.h"
+#include "builtin/assert.h"
#include "console.h"
#include "usb_common.h"
#include "usb_dp_alt_mode.h"
@@ -20,8 +20,8 @@
#include "usb_pd_tcpm.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -47,24 +47,20 @@ static enum dp_states dp_state[CONFIG_USB_PD_PORT_MAX_COUNT];
* Default of 0 indicates no command expected.
*/
static const uint8_t state_vdm_cmd[DP_STATE_COUNT] = {
- [DP_START] = CMD_ENTER_MODE,
- [DP_ENTER_ACKED] = CMD_DP_STATUS,
- [DP_PREPARE_CONFIG] = CMD_DP_CONFIG,
- [DP_PREPARE_EXIT] = CMD_EXIT_MODE,
+ [DP_START] = CMD_ENTER_MODE, [DP_ENTER_ACKED] = CMD_DP_STATUS,
+ [DP_PREPARE_CONFIG] = CMD_DP_CONFIG, [DP_PREPARE_EXIT] = CMD_EXIT_MODE,
[DP_ENTER_RETRY] = CMD_ENTER_MODE,
};
/*
* Track if we're retrying due to an Enter Mode NAK
*/
-#define DP_FLAG_RETRY BIT(0)
+#define DP_FLAG_RETRY BIT(0)
static atomic_t dpm_dp_flags[CONFIG_USB_PD_PORT_MAX_COUNT];
-#define DP_SET_FLAG(port, flag) \
- atomic_or(&dpm_dp_flags[port], (flag))
-#define DP_CLR_FLAG(port, flag) \
- atomic_clear_bits(&dpm_dp_flags[port], (flag))
+#define DP_SET_FLAG(port, flag) atomic_or(&dpm_dp_flags[port], (flag))
+#define DP_CLR_FLAG(port, flag) atomic_clear_bits(&dpm_dp_flags[port], (flag))
#define DP_CHK_FLAG(port, flag) (dpm_dp_flags[port] & (flag))
bool dp_is_active(int port)
@@ -72,6 +68,11 @@ bool dp_is_active(int port)
return dp_state[port] == DP_ACTIVE || dp_state[port] == DP_PREPARE_EXIT;
}
+bool dp_is_idle(int port)
+{
+ return dp_state[port] == DP_INACTIVE || dp_state[port] == DP_START;
+}
+
void dp_init(int port)
{
dp_state[port] = DP_START;
@@ -80,8 +81,7 @@ void dp_init(int port)
bool dp_entry_is_done(int port)
{
- return dp_state[port] == DP_ACTIVE ||
- dp_state[port] == DP_INACTIVE;
+ return dp_state[port] == DP_ACTIVE || dp_state[port] == DP_INACTIVE;
}
static void dp_entry_failed(int port)
@@ -91,8 +91,8 @@ static void dp_entry_failed(int port)
dpm_dp_flags[port] = 0;
}
-static bool dp_response_valid(int port, enum tcpci_msg_type type,
- char *cmdt, int vdm_cmd)
+static bool dp_response_valid(int port, enum tcpci_msg_type type, char *cmdt,
+ int vdm_cmd)
{
enum dp_states st = dp_state[port];
@@ -103,7 +103,8 @@ static bool dp_response_valid(int port, enum tcpci_msg_type type,
if (type != TCPCI_MSG_SOP ||
(st != DP_INACTIVE && state_vdm_cmd[st] != vdm_cmd)) {
CPRINTS("C%d: Received unexpected DP VDM %s (cmd %d) from"
- " %s in state %d", port, cmdt, vdm_cmd,
+ " %s in state %d",
+ port, cmdt, vdm_cmd,
type == TCPCI_MSG_SOP ? "port partner" : "cable plug",
st);
dp_entry_failed(port);
@@ -120,17 +121,17 @@ static void dp_exit_to_usb_mode(int port)
set_usb_mux_with_current_data_role(port);
CPRINTS("C%d: Exited DP mode", port);
- /*
- * If the EC exits an alt mode autonomously, don't try to enter it again. If
- * the AP commands the EC to exit DP mode, it might command the EC to enter
- * again later, so leave the state machine ready for that possibility.
- */
- dp_state[port] = IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY)
- ? DP_START : DP_INACTIVE;
+ /*
+ * If the EC exits an alt mode autonomously, don't try to enter it
+ * again. If the AP commands the EC to exit DP mode, it might command
+ * the EC to enter again later, so leave the state machine ready for
+ * that possibility.
+ */
+ dp_state[port] = DP_INACTIVE;
}
void dp_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
- uint32_t *vdm)
+ uint32_t *vdm)
{
const struct svdm_amode_data *modep =
pd_get_amode_data(port, type, USB_SID_DISPLAYPORT);
@@ -180,8 +181,8 @@ void dp_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
break;
default:
/* Invalid or unexpected negotiation state */
- CPRINTF("%s called with invalid state %d\n",
- __func__, dp_state[port]);
+ CPRINTF("%s called with invalid state %d\n", __func__,
+ dp_state[port]);
dp_entry_failed(port);
break;
}
@@ -216,8 +217,8 @@ void dp_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd)
dp_exit_to_usb_mode(port);
break;
default:
- CPRINTS("C%d: NAK for cmd %d in state %d", port,
- vdm_cmd, dp_state[port]);
+ CPRINTS("C%d: NAK for cmd %d in state %d", port, vdm_cmd,
+ dp_state[port]);
dp_entry_failed(port);
break;
}
@@ -226,8 +227,8 @@ void dp_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd)
enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count,
uint32_t *vdm)
{
- const struct svdm_amode_data *modep = pd_get_amode_data(port,
- TCPCI_MSG_SOP, USB_SID_DISPLAYPORT);
+ const struct svdm_amode_data *modep =
+ pd_get_amode_data(port, TCPCI_MSG_SOP, USB_SID_DISPLAYPORT);
int vdo_count_ret;
if (*vdo_count < VDO_MAX_SIZE)
@@ -238,7 +239,7 @@ enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count,
case DP_ENTER_RETRY:
/* Enter the first supported mode for DisplayPort. */
vdm[0] = pd_dfp_enter_mode(port, TCPCI_MSG_SOP,
- USB_SID_DISPLAYPORT, 0);
+ USB_SID_DISPLAYPORT, 0);
if (vdm[0] == 0)
return MSG_SETUP_ERROR;
/* CMDT_INIT is 0, so this is a no-op */
@@ -311,8 +312,7 @@ enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count,
return MSG_SETUP_MUX_WAIT;
case DP_PREPARE_EXIT:
/* DPM should call setup only after safe state is set */
- vdm[0] = VDO(USB_SID_DISPLAYPORT,
- 1, /* structured */
+ vdm[0] = VDO(USB_SID_DISPLAYPORT, 1, /* structured */
CMD_EXIT_MODE);
vdm[0] |= VDO_OPOS(modep->opos);
@@ -326,8 +326,8 @@ enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count,
*/
return MSG_SETUP_ERROR;
default:
- CPRINTF("%s called with invalid state %d\n",
- __func__, dp_state[port]);
+ CPRINTF("%s called with invalid state %d\n", __func__,
+ dp_state[port]);
return MSG_SETUP_ERROR;
}
diff --git a/common/usbc/tbt_alt_mode.c b/common/usbc/tbt_alt_mode.c
index 5baf9d1a73..d1ad031fad 100644
--- a/common/usbc/tbt_alt_mode.c
+++ b/common/usbc/tbt_alt_mode.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,6 +14,7 @@
#include "compile_time_macros.h"
#include "console.h"
#include "tcpm/tcpm.h"
+#include "typec_control.h"
#include "usb_common.h"
#include "usb_mux.h"
#include "usb_pd.h"
@@ -57,8 +58,8 @@
*/
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -70,8 +71,8 @@
* with a partner. It may be fixed in b/159495742, in which case this
* logic is unneeded.
*/
-#define TBT_FLAG_RETRY_DONE BIT(0)
-#define TBT_FLAG_EXIT_DONE BIT(1)
+#define TBT_FLAG_RETRY_DONE BIT(0)
+#define TBT_FLAG_EXIT_DONE BIT(1)
#define TBT_FLAG_CABLE_ENTRY_DONE BIT(2)
static uint8_t tbt_flags[CONFIG_USB_PD_PORT_MAX_COUNT];
@@ -123,14 +124,12 @@ void tbt_init(int port)
bool tbt_is_active(int port)
{
- return tbt_state[port] != TBT_INACTIVE &&
- tbt_state[port] != TBT_START;
+ return tbt_state[port] != TBT_INACTIVE && tbt_state[port] != TBT_START;
}
bool tbt_entry_is_done(int port)
{
- return tbt_state[port] == TBT_ACTIVE ||
- tbt_state[port] == TBT_INACTIVE;
+ return tbt_state[port] == TBT_ACTIVE || tbt_state[port] == TBT_INACTIVE;
}
bool tbt_cable_entry_is_done(int port)
@@ -140,13 +139,15 @@ bool tbt_cable_entry_is_done(int port)
static void tbt_exit_done(int port)
{
- /*
- * If the EC exits an alt mode autonomously, don't try to enter it again. If
- * the AP commands the EC to exit DP mode, it might command the EC to enter
- * again later, so leave the state machine ready for that possibility.
- */
- tbt_state[port] = IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY)
- ? TBT_START : TBT_INACTIVE;
+ /*
+ * If the EC exits an alt mode autonomously, don't try to enter it
+ * again. If the AP commands the EC to exit DP mode, it might command
+ * the EC to enter again later, so leave the state machine ready for
+ * that possibility.
+ */
+ tbt_state[port] = IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY) ?
+ TBT_START :
+ TBT_INACTIVE;
TBT_CLR_FLAG(port, TBT_FLAG_RETRY_DONE);
TBT_CLR_FLAG(port, TBT_FLAG_CABLE_ENTRY_DONE);
@@ -159,10 +160,47 @@ static void tbt_exit_done(int port)
tbt_prints("alt mode protocol failed!", port);
}
-void tbt_exit_mode_request(int port)
+static bool tbt_is_lrd_active_cable(int port)
{
union tbt_mode_resp_cable cable_mode_resp;
+ cable_mode_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
+ if (get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE &&
+ cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE)
+ return true;
+
+ return false;
+}
+
+/* Check if this port requires SOP' mode entry and exit */
+static bool tbt_sop_prime_needed(int port)
+{
+ /*
+ * We require SOP' entry if cable is
+ * active cable, or
+ * an LRD cable (passive in DiscoverIdentity, active in TBT mode)
+ */
+ if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE ||
+ tbt_is_lrd_active_cable(port))
+ return true;
+ return false;
+}
+
+/* Check if this port requires SOP'' mode entry and exit */
+static bool tbt_sop_prime_prime_needed(int port)
+{
+ const struct pd_discovery *disc;
+
+ disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
+ if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE &&
+ disc->identity.product_t1.a_rev20.sop_p_p)
+ return true;
+ return false;
+}
+
+void tbt_exit_mode_request(int port)
+{
TBT_SET_FLAG(port, TBT_FLAG_RETRY_DONE);
TBT_CLR_FLAG(port, TBT_FLAG_EXIT_DONE);
/*
@@ -172,26 +210,24 @@ void tbt_exit_mode_request(int port)
* TODO (b/156749387): Remove once data reset feature is in place.
*/
if (tbt_state[port] == TBT_ENTER_SOP) {
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
/*
* For Linear re-driver cables, the port enters USB4 mode
* with Thunderbolt mode for SOP prime. Hence, on request to
* exit, only exit Thunderbolt mode SOP prime
*/
- tbt_state[port] =
- cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE ?
- TBT_EXIT_SOP_PRIME : TBT_EXIT_SOP_PRIME_PRIME;
+ tbt_state[port] = tbt_sop_prime_prime_needed(port) ?
+ TBT_EXIT_SOP_PRIME_PRIME :
+ TBT_EXIT_SOP_PRIME;
}
}
-static bool tbt_response_valid(int port, enum tcpci_msg_type type,
- char *cmdt, int vdm_cmd)
+static bool tbt_response_valid(int port, enum tcpci_msg_type type, char *cmdt,
+ int vdm_cmd)
{
enum tbt_states st = tbt_state[port];
union tbt_mode_resp_cable cable_mode_resp = {
- .raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME) };
+ .raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME)
+ };
/*
* Check for an unexpected response.
@@ -216,71 +252,50 @@ static void tbt_retry_enter_mode(int port)
TBT_SET_FLAG(port, TBT_FLAG_RETRY_DONE);
}
-/* Send Exit Mode to SOP''(if supported), or SOP' */
-static void tbt_active_cable_exit_mode(int port)
-{
- const struct pd_discovery *disc;
-
- disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
-
- if (disc->identity.product_t1.a_rev20.sop_p_p)
- tbt_state[port] = TBT_EXIT_SOP_PRIME_PRIME;
- else
- tbt_state[port] = TBT_EXIT_SOP_PRIME;
-}
-
bool tbt_cable_entry_required_for_usb4(int port)
{
const struct pd_discovery *disc_sop_prime;
- union tbt_mode_resp_cable cable_mode_resp;
- /* Request to enter Thunderbolt mode for the cable prior to entering
- * USB4 mode if -
- * 1. Thunderbolt Mode SOP' VDO active/passive bit (B25) is
- * TBT_CABLE_ACTIVE or
- * 2. It's an active cable with VDM version < 2.0 or
- * VDO version < 1.3
- */
if (tbt_cable_entry_is_done(port))
return false;
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
- if (cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE)
+ /*
+ * For some cables, the TCPM may need to enter TBT mode with the
+ * cable to support USB4 mode with the partner. Request to enter
+ * Thunderbolt mode for the cable prior to entering USB4 for
+ * the port partner if
+ * 1. The cable advertises itself as passive in its Identity VDO
+ * but active in its TBT mode VDO, or
+ * 2. The cable advertises itself as active, but its PD support
+ * is not new enough to support Enter_USB.
+ */
+ if (tbt_is_lrd_active_cable(port))
return true;
if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE) {
disc_sop_prime = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
if (pd_get_vdo_ver(port, TCPCI_MSG_SOP_PRIME) < VDM_VER20 ||
disc_sop_prime->identity.product_t1.a_rev30.vdo_ver <
- VDO_VERSION_1_3)
+ VDO_VERSION_1_3)
return true;
}
return false;
}
void intel_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
- uint32_t *vdm)
+ uint32_t *vdm)
{
- const struct pd_discovery *disc;
const uint8_t vdm_cmd = PD_VDO_CMD(vdm[0]);
int opos_sop, opos_sop_prime;
- union tbt_mode_resp_cable cable_mode_resp;
if (!tbt_response_valid(port, type, "ACK", vdm_cmd))
return;
- disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
-
switch (tbt_state[port]) {
case TBT_ENTER_SOP_PRIME:
tbt_prints("enter mode SOP'", port);
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
/* For LRD cables, Enter mode SOP' -> Enter mode SOP */
- if (disc->identity.product_t1.a_rev20.sop_p_p &&
- cable_mode_resp.tbt_active_passive != TBT_CABLE_ACTIVE) {
+ if (tbt_sop_prime_prime_needed(port)) {
tbt_state[port] = TBT_ENTER_SOP_PRIME_PRIME;
} else {
TBT_SET_FLAG(port, TBT_FLAG_CABLE_ENTRY_DONE);
@@ -308,8 +323,11 @@ void intel_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
if (opos_sop > 0)
pd_dfp_exit_mode(port, TCPCI_MSG_SOP, USB_VID_INTEL,
opos_sop);
- if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE) {
- tbt_active_cable_exit_mode(port);
+
+ if (tbt_sop_prime_prime_needed(port)) {
+ tbt_state[port] = TBT_EXIT_SOP_PRIME_PRIME;
+ } else if (tbt_sop_prime_needed(port)) {
+ tbt_state[port] = TBT_EXIT_SOP_PRIME;
} else {
set_usb_mux_with_current_data_role(port);
if (TBT_CHK_FLAG(port, TBT_FLAG_RETRY_DONE))
@@ -330,13 +348,12 @@ void intel_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
* Exit mode process is complete; go to inactive state.
*/
tbt_exit_done(port);
- opos_sop_prime =
- pd_alt_mode(port, TCPCI_MSG_SOP_PRIME,
- USB_VID_INTEL);
+ opos_sop_prime = pd_alt_mode(port, TCPCI_MSG_SOP_PRIME,
+ USB_VID_INTEL);
/* Clear Thunderbolt related signals */
pd_dfp_exit_mode(port, TCPCI_MSG_SOP_PRIME,
- USB_VID_INTEL, opos_sop_prime);
+ USB_VID_INTEL, opos_sop_prime);
set_usb_mux_with_current_data_role(port);
} else {
tbt_retry_enter_mode(port);
@@ -351,8 +368,8 @@ void intel_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
break;
default:
/* Invalid or unexpected negotiation state */
- CPRINTF("%s called with invalid state %d\n",
- __func__, tbt_state[port]);
+ CPRINTF("%s called with invalid state %d\n", __func__,
+ tbt_state[port]);
tbt_exit_done(port);
break;
}
@@ -378,9 +395,12 @@ void intel_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd)
case TBT_EXIT_SOP:
/* Exit SOP got NAK'ed */
tbt_prints("exit mode SOP failed", port);
- if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE)
- tbt_active_cable_exit_mode(port);
- else {
+
+ if (tbt_sop_prime_prime_needed(port)) {
+ tbt_state[port] = TBT_EXIT_SOP_PRIME_PRIME;
+ } else if (tbt_sop_prime_needed(port)) {
+ tbt_state[port] = TBT_EXIT_SOP_PRIME;
+ } else {
set_usb_mux_with_current_data_role(port);
if (TBT_CHK_FLAG(port, TBT_FLAG_RETRY_DONE))
/* Retried enter mode, still failed, give up */
@@ -406,8 +426,8 @@ void intel_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd)
}
break;
default:
- CPRINTS("C%d: NAK for cmd %d in state %d", port,
- vdm_cmd, tbt_state[port]);
+ CPRINTS("C%d: NAK for cmd %d in state %d", port, vdm_cmd,
+ tbt_state[port]);
tbt_exit_done(port);
break;
}
@@ -416,7 +436,7 @@ void intel_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd)
static bool tbt_mode_is_supported(int port, int vdo_count)
{
const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP);
+ pd_get_am_discovery(port, TCPCI_MSG_SOP);
if (!disc->identity.idh.modal_support)
return false;
@@ -430,8 +450,8 @@ static bool tbt_mode_is_supported(int port, int vdo_count)
* SVID USB_VID_INTEL to enter Thunderbolt alt mode
*/
if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE &&
- !pd_is_mode_discovered_for_svid(
- port, TCPCI_MSG_SOP_PRIME, USB_VID_INTEL))
+ !pd_is_mode_discovered_for_svid(port, TCPCI_MSG_SOP_PRIME,
+ USB_VID_INTEL))
return false;
return true;
@@ -443,7 +463,6 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count,
{
struct svdm_amode_data *modep;
int vdo_count_ret = 0;
- union tbt_mode_resp_cable cable_mode_resp;
*tx_type = TCPCI_MSG_SOP;
@@ -467,12 +486,8 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count,
*/
usb_mux_set_safe_mode(port);
- cable_mode_resp.raw_value =
- pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
-
/* Active cable and LRD cables send Enter Mode SOP' first */
- if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE ||
- cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE) {
+ if (tbt_sop_prime_needed(port)) {
tbt_state[port] = TBT_ENTER_SOP_PRIME;
} else {
/* Passive cable send Enter Mode SOP */
@@ -486,14 +501,12 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count,
*tx_type = TCPCI_MSG_SOP_PRIME;
break;
case TBT_ENTER_SOP_PRIME_PRIME:
- vdo_count_ret =
- enter_tbt_compat_mode(
- port, TCPCI_MSG_SOP_PRIME_PRIME, vdm);
+ vdo_count_ret = enter_tbt_compat_mode(
+ port, TCPCI_MSG_SOP_PRIME_PRIME, vdm);
*tx_type = TCPCI_MSG_SOP_PRIME_PRIME;
break;
case TBT_ENTER_SOP:
- vdo_count_ret =
- enter_tbt_compat_mode(port, TCPCI_MSG_SOP, vdm);
+ vdo_count_ret = enter_tbt_compat_mode(port, TCPCI_MSG_SOP, vdm);
break;
case TBT_ACTIVE:
/*
@@ -515,43 +528,38 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count,
return MSG_SETUP_MUX_WAIT;
case TBT_EXIT_SOP:
/* DPM will only call this after safe state set is done */
- modep = pd_get_amode_data(port,
- TCPCI_MSG_SOP, USB_VID_INTEL);
+ modep = pd_get_amode_data(port, TCPCI_MSG_SOP, USB_VID_INTEL);
if (!(modep && modep->opos))
return MSG_SETUP_ERROR;
vdm[0] = VDO(USB_VID_INTEL, 1, CMD_EXIT_MODE) |
- VDO_OPOS(modep->opos) |
- VDO_CMDT(CMDT_INIT) |
- VDO_SVDM_VERS(
- pd_get_vdo_ver(port, TCPCI_MSG_SOP));
+ VDO_OPOS(modep->opos) | VDO_CMDT(CMDT_INIT) |
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP));
vdo_count_ret = 1;
break;
case TBT_EXIT_SOP_PRIME_PRIME:
- modep = pd_get_amode_data(port,
- TCPCI_MSG_SOP_PRIME, USB_VID_INTEL);
+ modep = pd_get_amode_data(port, TCPCI_MSG_SOP_PRIME,
+ USB_VID_INTEL);
if (!(modep && modep->opos))
return MSG_SETUP_ERROR;
vdm[0] = VDO(USB_VID_INTEL, 1, CMD_EXIT_MODE) |
- VDO_OPOS(modep->opos) |
- VDO_CMDT(CMDT_INIT) |
- VDO_SVDM_VERS(pd_get_vdo_ver(port,
- TCPCI_MSG_SOP_PRIME_PRIME));
+ VDO_OPOS(modep->opos) | VDO_CMDT(CMDT_INIT) |
+ VDO_SVDM_VERS(pd_get_vdo_ver(
+ port, TCPCI_MSG_SOP_PRIME_PRIME));
vdo_count_ret = 1;
*tx_type = TCPCI_MSG_SOP_PRIME_PRIME;
break;
case TBT_EXIT_SOP_PRIME:
- modep = pd_get_amode_data(port,
- TCPCI_MSG_SOP_PRIME, USB_VID_INTEL);
+ modep = pd_get_amode_data(port, TCPCI_MSG_SOP_PRIME,
+ USB_VID_INTEL);
if (!(modep && modep->opos))
return MSG_SETUP_ERROR;
vdm[0] = VDO(USB_VID_INTEL, 1, CMD_EXIT_MODE) |
- VDO_OPOS(modep->opos) |
- VDO_CMDT(CMDT_INIT) |
- VDO_SVDM_VERS(pd_get_vdo_ver(port,
- TCPCI_MSG_SOP_PRIME));
+ VDO_OPOS(modep->opos) | VDO_CMDT(CMDT_INIT) |
+ VDO_SVDM_VERS(
+ pd_get_vdo_ver(port, TCPCI_MSG_SOP_PRIME));
vdo_count_ret = 1;
*tx_type = TCPCI_MSG_SOP_PRIME;
break;
@@ -559,8 +567,8 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count,
/* Thunderbolt mode is inactive */
return MSG_SETUP_UNSUPPORTED;
default:
- CPRINTF("%s called with invalid state %d\n",
- __func__, tbt_state[port]);
+ CPRINTF("%s called with invalid state %d\n", __func__,
+ tbt_state[port]);
return MSG_SETUP_ERROR;
}
@@ -571,3 +579,177 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count,
return MSG_SETUP_UNSUPPORTED;
}
+
+uint32_t pd_get_tbt_mode_vdo(int port, enum tcpci_msg_type type)
+{
+ uint32_t tbt_mode_vdo[PDO_MODES];
+
+ return pd_get_mode_vdo_for_svid(port, type, USB_VID_INTEL,
+ tbt_mode_vdo) ?
+ tbt_mode_vdo[0] :
+ 0;
+}
+
+void set_tbt_compat_mode_ready(int port)
+{
+ if (IS_ENABLED(CONFIG_USBC_SS_MUX) &&
+ IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)) {
+ /* Connect the SBU and USB lines to the connector. */
+ typec_set_sbu(port, true);
+
+ /* Set usb mux to Thunderbolt-compatible mode */
+ usb_mux_set(port, USB_PD_MUX_TBT_COMPAT_ENABLED,
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
+ }
+}
+
+/*
+ * Ref: USB Type-C Cable and Connector Specification
+ * Figure F-1 TBT3 Discovery Flow
+ */
+static bool is_tbt_cable_superspeed(int port)
+{
+ const struct pd_discovery *disc;
+
+ if (!IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) ||
+ !IS_ENABLED(CONFIG_USB_PD_DECODE_SOP))
+ return false;
+
+ disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
+
+ /* Product type is Active cable, hence don't check for speed */
+ if (disc->identity.idh.product_type == IDH_PTYPE_ACABLE)
+ return true;
+
+ if (disc->identity.idh.product_type != IDH_PTYPE_PCABLE)
+ return false;
+
+ if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
+ pd_get_rev(port, TCPCI_MSG_SOP_PRIME) == PD_REV30)
+ return disc->identity.product_t1.p_rev30.ss ==
+ USB_R30_SS_U32_U40_GEN1 ||
+ disc->identity.product_t1.p_rev30.ss ==
+ USB_R30_SS_U32_U40_GEN2 ||
+ disc->identity.product_t1.p_rev30.ss ==
+ USB_R30_SS_U40_GEN3;
+
+ return disc->identity.product_t1.p_rev20.ss == USB_R20_SS_U31_GEN1 ||
+ disc->identity.product_t1.p_rev20.ss == USB_R20_SS_U31_GEN1_GEN2;
+}
+
+static enum tbt_compat_cable_speed usb_rev30_to_tbt_speed(enum usb_rev30_ss ss)
+{
+ switch (ss) {
+ case USB_R30_SS_U32_U40_GEN1:
+ return TBT_SS_U31_GEN1;
+ case USB_R30_SS_U32_U40_GEN2:
+ return TBT_SS_U32_GEN1_GEN2;
+ case USB_R30_SS_U40_GEN3:
+ return TBT_SS_TBT_GEN3;
+ default:
+ return TBT_SS_U32_GEN1_GEN2;
+ }
+}
+
+enum tbt_compat_cable_speed get_tbt_cable_speed(int port)
+{
+ union tbt_mode_resp_cable cable_mode_resp;
+ enum tbt_compat_cable_speed max_tbt_speed;
+ enum tbt_compat_cable_speed cable_tbt_speed;
+
+ if (!is_tbt_cable_superspeed(port))
+ return TBT_SS_RES_0;
+
+ cable_mode_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
+ max_tbt_speed = board_get_max_tbt_speed(port);
+
+ /*
+ * Ref: TBT4 PD Discovery Flow Application Notes Revision 0.9, Figure 2
+ * For passive cable, if cable doesn't support USB_VID_INTEL, enter
+ * Thunderbolt alternate mode with speed from USB Highest Speed field of
+ * the Passive Cable VDO
+ * For active cable, if the cable doesn't support USB_VID_INTEL, do not
+ * enter Thunderbolt alternate mode.
+ */
+ if (!cable_mode_resp.raw_value) {
+ const struct pd_discovery *disc;
+
+ if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE)
+ return TBT_SS_RES_0;
+
+ disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
+ cable_tbt_speed = usb_rev30_to_tbt_speed(
+ disc->identity.product_t1.p_rev30.ss);
+ } else {
+ cable_tbt_speed = cable_mode_resp.tbt_cable_speed;
+ }
+
+ return max_tbt_speed < cable_tbt_speed ? max_tbt_speed :
+ cable_tbt_speed;
+}
+
+/* Note: Assumes that pins have already been set in safe state */
+int enter_tbt_compat_mode(int port, enum tcpci_msg_type sop, uint32_t *payload)
+{
+ union tbt_dev_mode_enter_cmd enter_dev_mode = { .raw_value = 0 };
+ union tbt_mode_resp_device dev_mode_resp;
+ union tbt_mode_resp_cable cable_mode_resp;
+ enum tcpci_msg_type enter_mode_sop =
+ sop == TCPCI_MSG_SOP_PRIME_PRIME ? TCPCI_MSG_SOP_PRIME : sop;
+
+ /* Table F-12 TBT3 Cable Enter Mode Command */
+ /*
+ * The port doesn't query Discover SOP'' to the cable so, the port
+ * doesn't have opos for SOP''. Hence, send Enter Mode SOP'' with same
+ * opos and revision as SOP'.
+ */
+ payload[0] = pd_dfp_enter_mode(port, enter_mode_sop, USB_VID_INTEL, 0) |
+ VDO_CMDT(CMDT_INIT) |
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, enter_mode_sop));
+
+ /* For TBT3 Cable Enter Mode Command, number of Objects is 1 */
+ if ((sop == TCPCI_MSG_SOP_PRIME) || (sop == TCPCI_MSG_SOP_PRIME_PRIME))
+ return 1;
+
+ dev_mode_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP);
+ cable_mode_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
+
+ /* Table F-13 TBT3 Device Enter Mode Command */
+ enter_dev_mode.vendor_spec_b1 = dev_mode_resp.vendor_spec_b1;
+ enter_dev_mode.vendor_spec_b0 = dev_mode_resp.vendor_spec_b0;
+ enter_dev_mode.intel_spec_b0 = dev_mode_resp.intel_spec_b0;
+
+ if (get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE ||
+ cable_mode_resp.tbt_active_passive == TBT_CABLE_ACTIVE)
+ enter_dev_mode.cable = TBT_ENTER_ACTIVE_CABLE;
+
+ enter_dev_mode.lsrx_comm = cable_mode_resp.lsrx_comm;
+ enter_dev_mode.retimer_type = cable_mode_resp.retimer_type;
+ enter_dev_mode.tbt_cable = cable_mode_resp.tbt_cable;
+ enter_dev_mode.tbt_rounded = cable_mode_resp.tbt_rounded;
+ enter_dev_mode.tbt_cable_speed = get_tbt_cable_speed(port);
+ enter_dev_mode.tbt_alt_mode = TBT_ALTERNATE_MODE;
+
+ payload[1] = enter_dev_mode.raw_value;
+
+ /* For TBT3 Device Enter Mode Command, number of Objects are 2 */
+ return 2;
+}
+
+enum tbt_compat_rounded_support get_tbt_rounded_support(int port)
+{
+ union tbt_mode_resp_cable cable_mode_resp = {
+ .raw_value = pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME)
+ };
+
+ /* tbt_rounded_support is zero when uninitialized */
+ return cable_mode_resp.tbt_rounded;
+}
+
+__overridable enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
+{
+ return TBT_SS_TBT_GEN3;
+}
diff --git a/common/usbc/usb_mode.c b/common/usbc/usb_mode.c
index e7c385c59c..8f4824e4e9 100644
--- a/common/usbc/usb_mode.c
+++ b/common/usbc/usb_mode.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -26,8 +26,8 @@
#include "usbc_ppc.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -117,7 +117,7 @@ static void usb4_debug_prints(int port, enum usb4_mode_status usb4_status)
bool enter_usb_entry_is_done(int port)
{
return usb4_state[port] == USB4_ACTIVE ||
- usb4_state[port] == USB4_INACTIVE;
+ usb4_state[port] == USB4_INACTIVE;
}
void usb4_exit_mode_request(int port)
@@ -153,7 +153,7 @@ static bool enter_usb_response_valid(int port, enum tcpci_msg_type type)
* Check for an unexpected response.
*/
if (get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE &&
- type != TCPCI_MSG_SOP) {
+ type != TCPCI_MSG_SOP) {
enter_usb_failed(port);
return false;
}
@@ -163,7 +163,7 @@ static bool enter_usb_response_valid(int port, enum tcpci_msg_type type)
bool enter_usb_port_partner_is_capable(int port)
{
const struct pd_discovery *disc =
- pd_get_am_discovery(port, TCPCI_MSG_SOP);
+ pd_get_am_discovery(port, TCPCI_MSG_SOP);
if (usb4_state[port] == USB4_INACTIVE)
return false;
@@ -185,7 +185,7 @@ bool enter_usb_cable_is_capable(int port)
if (pd_get_vdo_ver(port, TCPCI_MSG_SOP_PRIME) >= VDM_VER20 &&
disc_sop_prime->identity.product_t1.a_rev30.vdo_ver >=
- VDO_VERSION_1_3) {
+ VDO_VERSION_1_3) {
union active_cable_vdo2_rev30 a2_rev30 =
disc_sop_prime->identity.product_t2.a2_rev30;
/*
@@ -195,25 +195,25 @@ bool enter_usb_cable_is_capable(int port)
*/
if (a2_rev30.usb_40_support == USB4_NOT_SUPPORTED)
return false;
- /*
- * For VDM version < 2.0 or VDO version < 1.3, do not enter USB4
- * mode if the cable -
- * doesn't support modal operation or
- * doesn't support Intel SVID or
- * doesn't have rounded support.
- */
+ /*
+ * For VDM version < 2.0 or VDO version < 1.3, do not
+ * enter USB4 mode if the cable - doesn't support modal
+ * operation or doesn't support Intel SVID or doesn't
+ * have rounded support.
+ */
} else {
const struct pd_discovery *disc =
pd_get_am_discovery(port, TCPCI_MSG_SOP);
union tbt_mode_resp_cable cable_mode_resp = {
- .raw_value = pd_get_tbt_mode_vdo(port,
- TCPCI_MSG_SOP_PRIME) };
+ .raw_value = pd_get_tbt_mode_vdo(
+ port, TCPCI_MSG_SOP_PRIME)
+ };
if (!disc->identity.idh.modal_support ||
- !pd_is_mode_discovered_for_svid(port,
- TCPCI_MSG_SOP_PRIME, USB_VID_INTEL) ||
+ !pd_is_mode_discovered_for_svid(
+ port, TCPCI_MSG_SOP_PRIME, USB_VID_INTEL) ||
cable_mode_resp.tbt_rounded !=
- TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED)
+ TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED)
return false;
}
} else {
@@ -288,7 +288,7 @@ uint32_t enter_usb_setup_next_msg(int port, enum tcpci_msg_type *type)
if (pd_get_vdo_ver(port, TCPCI_MSG_SOP_PRIME) < VDM_VER20 ||
disc_sop_prime->identity.product_t1.a_rev30.vdo_ver <
- VDO_VERSION_1_3 ||
+ VDO_VERSION_1_3 ||
get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE) {
usb4_state[port] = USB4_ENTER_SOP;
} else {
@@ -312,3 +312,107 @@ uint32_t enter_usb_setup_next_msg(int port, enum tcpci_msg_type *type)
}
return get_enter_usb_msg_payload(port);
}
+
+/*
+ * For Cable rev 3.0: USB4 cable speed is set according to speed supported by
+ * the port and the response received from the cable, whichever is least.
+ *
+ * For Cable rev 2.0: If get_tbt_cable_speed() is less than
+ * TBT_SS_U31_GEN1, return USB_R30_SS_U2_ONLY speed since the board
+ * doesn't support superspeed else the USB4 cable speed is set according to
+ * the cable response.
+ */
+enum usb_rev30_ss get_usb4_cable_speed(int port)
+{
+ enum tbt_compat_cable_speed tbt_speed = get_tbt_cable_speed(port);
+ enum usb_rev30_ss max_usb4_speed;
+
+ if (tbt_speed < TBT_SS_U31_GEN1)
+ return USB_R30_SS_U2_ONLY;
+
+ /*
+ * Converting Thunderbolt-Compatible board speed to equivalent USB4
+ * speed.
+ */
+ max_usb4_speed = tbt_speed == TBT_SS_TBT_GEN3 ? USB_R30_SS_U40_GEN3 :
+ USB_R30_SS_U32_U40_GEN2;
+
+ if ((get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE) &&
+ pd_get_rev(port, TCPCI_MSG_SOP_PRIME) == PD_REV30) {
+ const struct pd_discovery *disc =
+ pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
+ union active_cable_vdo1_rev30 a_rev30 =
+ disc->identity.product_t1.a_rev30;
+
+ if (a_rev30.vdo_ver >= VDO_VERSION_1_3) {
+ return max_usb4_speed < a_rev30.ss ? max_usb4_speed :
+ a_rev30.ss;
+ }
+ }
+
+ return max_usb4_speed;
+}
+
+uint32_t get_enter_usb_msg_payload(int port)
+{
+ /*
+ * Ref: USB Power Delivery Specification Revision 3.0, Version 2.0
+ * Table 6-47 Enter_USB Data Object
+ */
+ union enter_usb_data_obj eudo;
+ const struct pd_discovery *disc;
+ union tbt_mode_resp_cable cable_mode_resp;
+
+ if (!IS_ENABLED(CONFIG_USB_PD_USB4))
+ return 0;
+
+ disc = pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME);
+ eudo.mode = USB_PD_40;
+ eudo.usb4_drd_cap = IS_ENABLED(CONFIG_USB_PD_USB4_DRD);
+ eudo.usb3_drd_cap = IS_ENABLED(CONFIG_USB_PD_USB32_DRD);
+ eudo.cable_speed = get_usb4_cable_speed(port);
+
+ if (disc->identity.idh.product_type == IDH_PTYPE_ACABLE) {
+ if (pd_get_rev(port, TCPCI_MSG_SOP_PRIME) == PD_REV30) {
+ enum retimer_active_element active_element =
+ disc->identity.product_t2.a2_rev30.active_elem;
+ eudo.cable_type = active_element == ACTIVE_RETIMER ?
+ CABLE_TYPE_ACTIVE_RETIMER :
+ CABLE_TYPE_ACTIVE_REDRIVER;
+ } else {
+ cable_mode_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
+
+ eudo.cable_type = cable_mode_resp.retimer_type ==
+ USB_RETIMER ?
+ CABLE_TYPE_ACTIVE_RETIMER :
+ CABLE_TYPE_ACTIVE_REDRIVER;
+ }
+ } else {
+ cable_mode_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPCI_MSG_SOP_PRIME);
+
+ eudo.cable_type = cable_mode_resp.tbt_active_passive ==
+ TBT_CABLE_ACTIVE ?
+ CABLE_TYPE_ACTIVE_REDRIVER :
+ CABLE_TYPE_PASSIVE;
+ }
+
+ switch (disc->identity.product_t1.p_rev20.vbus_cur) {
+ case USB_VBUS_CUR_3A:
+ eudo.cable_current = USB4_CABLE_CURRENT_3A;
+ break;
+ case USB_VBUS_CUR_5A:
+ eudo.cable_current = USB4_CABLE_CURRENT_5A;
+ break;
+ default:
+ eudo.cable_current = USB4_CABLE_CURRENT_INVALID;
+ break;
+ }
+ eudo.pcie_supported = IS_ENABLED(CONFIG_USB_PD_PCIE_TUNNELING);
+ eudo.dp_supported = IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP);
+ eudo.tbt_supported = IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE);
+ eudo.host_present = 1;
+
+ return eudo.raw_value;
+}
diff --git a/common/usbc/usb_pd_console.c b/common/usbc/usb_pd_console.c
index 6b1ea259eb..027a0d66c5 100644
--- a/common/usbc/usb_pd_console.c
+++ b/common/usbc/usb_pd_console.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,7 +16,8 @@
#ifndef TEST_USB_PD_CONSOLE
static
#endif
-int command_pd(int argc, char **argv)
+ int
+ command_pd(int argc, const char **argv)
{
int port;
char *e;
@@ -43,7 +44,7 @@ int command_pd(int argc, char **argv)
return EC_SUCCESS;
}
} else if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC) &&
- !strcasecmp(argv[1], "trysrc")) {
+ !strcasecmp(argv[1], "trysrc")) {
enum try_src_override_t ov = tc_get_try_src_override();
if (argc >= 3) {
@@ -111,7 +112,7 @@ int command_pd(int argc, char **argv)
else if (!strcasecmp(argv[3], "data"))
pd_dpm_request(port, DPM_REQUEST_DR_SWAP);
else if (IS_ENABLED(CONFIG_USBC_VCONN_SWAP) &&
- !strcasecmp(argv[3], "vconn"))
+ !strcasecmp(argv[3], "vconn"))
pd_dpm_request(port, DPM_REQUEST_VCONN_SWAP);
else
return EC_ERROR_PARAM3;
@@ -135,60 +136,66 @@ int command_pd(int argc, char **argv)
case PD_DRP_FORCE_SOURCE:
ccprintf("force source\n");
break;
- cflush();
+ cflush();
}
} else {
if (!strcasecmp(argv[3], "on"))
pd_set_dual_role(port,
- PD_DRP_TOGGLE_ON);
+ PD_DRP_TOGGLE_ON);
else if (!strcasecmp(argv[3], "off"))
pd_set_dual_role(port,
- PD_DRP_TOGGLE_OFF);
+ PD_DRP_TOGGLE_OFF);
else if (!strcasecmp(argv[3], "freeze"))
pd_set_dual_role(port, PD_DRP_FREEZE);
else if (!strcasecmp(argv[3], "sink"))
pd_set_dual_role(port,
- PD_DRP_FORCE_SINK);
+ PD_DRP_FORCE_SINK);
else if (!strcasecmp(argv[3], "source"))
pd_set_dual_role(port,
- PD_DRP_FORCE_SOURCE);
+ PD_DRP_FORCE_SOURCE);
else
return EC_ERROR_PARAM4;
}
return EC_SUCCESS;
+ } else if (!strcasecmp(argv[2], "suspend")) {
+ pd_comm_enable(port, 0);
+ pd_set_suspend(port, 1);
+ } else if (!strcasecmp(argv[2], "resume")) {
+ pd_comm_enable(port, 1);
+ pd_set_suspend(port, 0);
}
}
if (!strcasecmp(argv[2], "state")) {
cflush();
- ccprintf("Port C%d CC%d, %s - Role: %s-%s",
- port, pd_get_polarity(port) + 1,
- pd_comm_is_enabled(port) ? "Enable" : "Disable",
- pd_get_power_role(port) ==
- PD_ROLE_SOURCE ? "SRC" : "SNK",
- pd_get_data_role(port) == PD_ROLE_DFP ? "DFP" : "UFP");
+ ccprintf("Port C%d CC%d, %s - Role: %s-%s", port,
+ pd_get_polarity(port) + 1,
+ pd_comm_is_enabled(port) ? "Enable" : "Disable",
+ pd_get_power_role(port) == PD_ROLE_SOURCE ? "SRC" :
+ "SNK",
+ pd_get_data_role(port) == PD_ROLE_DFP ? "DFP" : "UFP");
if (IS_ENABLED(CONFIG_USBC_VCONN))
ccprintf("%s ", tc_is_vconn_src(port) ? "-VC" : "");
ccprintf("TC State: %s, Flags: 0x%04x",
- tc_get_current_state(port),
- tc_get_flags(port));
+ tc_get_current_state(port), tc_get_flags(port));
if (IS_ENABLED(CONFIG_USB_PE_SM))
ccprintf(" PE State: %s, Flags: 0x%04x\n",
- pe_get_current_state(port),
- pe_get_flags(port));
+ pe_get_current_state(port),
+ pe_get_flags(port));
else
ccprintf("\n");
cflush();
} else if (!strcasecmp(argv[2], "srccaps")) {
pd_srccaps_dump(port);
+ } else if (!strcasecmp(argv[2], "cc")) {
+ ccprintf("Port C%d CC%d\n", port, pd_get_task_cc_state(port));
}
- if (IS_ENABLED(CONFIG_CMD_PD_TIMER) &&
- !strcasecmp(argv[2], "timer")) {
+ if (IS_ENABLED(CONFIG_CMD_PD_TIMER) && !strcasecmp(argv[2], "timer")) {
pd_timer_dump(port);
}
@@ -196,22 +203,24 @@ int command_pd(int argc, char **argv)
}
#ifndef TEST_USB_PD_CONSOLE
DECLARE_CONSOLE_COMMAND(pd, command_pd,
- "version"
- "\ndump [0|1|2|3]"
+ "version"
+ "\ndump [0|1|2|3]"
#ifdef CONFIG_USB_PD_TRY_SRC
- "\ntrysrc [0|1|2]"
+ "\ntrysrc [0|1|2]"
#endif
- "\n\t<port> state"
- "\n\t<port> srccaps"
+ "\n\t<port> state"
+ "\n\t<port> srccaps"
+ "\n\t<port> cc"
#ifdef CONFIG_CMD_PD_TIMER
- "\n\t<port> timer"
+ "\n\t<port> timer"
#endif /* CONFIG_CMD_PD_TIMER */
#ifdef CONFIG_USB_PD_DUAL_ROLE
- "|tx|charger|dev"
- "\n\t<port> disable|enable|soft|hard"
- "\n\t<port> dualrole [on|off|freeze|sink|source]"
- "\n\t<port> swap [power|data|vconn]"
+ "|tx|charger|dev"
+ "\n\t<port> disable|enable|soft|hard"
+ "\n\t<port> suspend|resume"
+ "\n\t<port> dualrole [on|off|freeze|sink|source]"
+ "\n\t<port> swap [power|data|vconn]"
#endif /* CONFIG_USB_PD_DUAL_ROLE */
- ,
- "USB PD");
+ ,
+ "USB PD");
#endif
diff --git a/common/usbc/usb_pd_dp_ufp.c b/common/usbc/usb_pd_dp_ufp.c
index 0009b5c710..d88ee17aaf 100644
--- a/common/usbc/usb_pd_dp_ufp.c
+++ b/common/usbc/usb_pd_dp_ufp.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.
*/
@@ -15,9 +15,8 @@
#include "usb_pd.h"
#include "usb_pd_dp_ufp.h"
-
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
enum hpd_state {
LOW_WAIT,
@@ -105,17 +104,17 @@ static void hpd_to_dp_attention(void)
* the DP_STATUS VDO.
*/
svdm_header = VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP)) |
- VDO_OPOS(opos) | CMD_ATTENTION;
+ VDO_OPOS(opos) | CMD_ATTENTION;
vdm[0] = VDO(USB_SID_DISPLAYPORT, 1, svdm_header);
vdm[1] = VDO_DP_STATUS((evt == hpd_irq), /* IRQ_HPD */
- (evt != hpd_low), /* HPD_HI|LOW */
- 0, /* request exit DP */
- 0, /* request exit USB */
- dock_get_mf_preference(), /* MF pref */
- 1, /* enabled */
- 0, /* power low */
- 0x2);
+ (evt != hpd_low), /* HPD_HI|LOW */
+ 0, /* request exit DP */
+ 0, /* request exit USB */
+ dock_get_mf_preference(), /* MF pref */
+ 1, /* enabled */
+ 0, /* power low */
+ 0x2);
/* Send request to DPM to send an attention VDM */
pd_request_vdm_attention(port, vdm, ARRAY_SIZE(vdm));
@@ -154,10 +153,10 @@ static void hpd_queue_event(enum hpd_event evt)
* are kept in the queue.
*/
if (evt == hpd_irq) {
- if ((hpd.count >= HPD_QUEUE_DEPTH) || ((hpd.count >= 2) &&
- (hpd.queue[hpd.count - 2] == hpd_irq))) {
- CPRINTS("hpd: discard hpd: count - %d",
- hpd.count);
+ if ((hpd.count >= HPD_QUEUE_DEPTH) ||
+ ((hpd.count >= 2) &&
+ (hpd.queue[hpd.count - 2] == hpd_irq))) {
+ CPRINTS("hpd: discard hpd: count - %d", hpd.count);
return;
}
}
@@ -238,13 +237,13 @@ static void hpd_to_pd_converter(int level, uint64_t ts)
*/
if (!level) {
/* Still low, now wait for IRQ or LOW determination */
- hpd.timer = ts + (HPD_T_IRQ_MAX_PULSE -
- HPD_T_IRQ_MIN_PULSE);
+ hpd.timer = ts +
+ (HPD_T_IRQ_MAX_PULSE - HPD_T_IRQ_MIN_PULSE);
hpd.state = IRQ_CHECK;
} else {
uint64_t irq_ts = hpd.timer + HPD_T_IRQ_MAX_PULSE -
- HPD_T_IRQ_MIN_PULSE;
+ HPD_T_IRQ_MIN_PULSE;
/*
* If hpd is high now, this must have been an edge
* event, but still need to determine if the pulse width
@@ -271,7 +270,7 @@ static void hpd_to_pd_converter(int level, uint64_t ts)
if (ts <= hpd.timer) {
hpd_queue_event(hpd_irq);
}
- } else if (ts > hpd.timer) {
+ } else if (ts > hpd.timer) {
hpd.state = LOW_WAIT;
hpd_queue_event(hpd_low);
}
@@ -287,7 +286,7 @@ static void manage_hpd(void)
int level;
uint64_t ts = get_time().val;
uint32_t num_hpd_events = (hpd.edges.head - hpd.edges.tail) &
- EDGE_QUEUE_MASK;
+ EDGE_QUEUE_MASK;
/*
* HPD edges are detected via GPIO interrupts. The ISR routine adds edge
@@ -305,7 +304,7 @@ static void manage_hpd(void)
}
if (num_hpd_events) {
- while(num_hpd_events-- > 0) {
+ while (num_hpd_events-- > 0) {
int idx = hpd.edges.tail;
level = hpd.edges.buffer[idx].level;
@@ -331,9 +330,8 @@ static void manage_hpd(void)
* a DP_ATTENTION message if a DP_CONFIG message has been
* received and have passed the minimum spacing interval.
*/
- if (hpd.send_enable &&
- ((get_time().val - hpd.last_send_ts) >
- HPD_T_MIN_DP_ATTEN)) {
+ if (hpd.send_enable && ((get_time().val - hpd.last_send_ts) >
+ HPD_T_MIN_DP_ATTEN)) {
/* Generate DP_ATTENTION event pending in queue */
hpd_to_dp_attention();
} else {
@@ -352,7 +350,7 @@ static void manage_hpd(void)
* the minimum time spacing.
*/
callback_us = HPD_T_MIN_DP_ATTEN -
- (get_time().val - hpd.last_send_ts);
+ (get_time().val - hpd.last_send_ts);
if (callback_us <= 0 ||
callback_us > HPD_T_MIN_DP_ATTEN)
callback_us = HPD_T_MIN_DP_ATTEN;
@@ -403,7 +401,7 @@ void usb_pd_hpd_converter_enable(int enable)
hpd.state = LOW_WAIT;
hpd.count = 0;
hpd.timer = 0;
- hpd.last_send_ts = 0;
+ hpd.last_send_ts = 0;
hpd.send_enable = 0;
/* Reset hpd signal edges queue */
@@ -427,7 +425,7 @@ void usb_pd_hpd_converter_enable(int enable)
void usb_pd_hpd_edge_event(int signal)
{
- int next_head = (hpd.edges.head + 1) & EDGE_QUEUE_MASK;
+ int next_head = (hpd.edges.head + 1) & EDGE_QUEUE_MASK;
struct hpd_mark mark;
/* Get current timestamp and level */
diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c
index 159331171e..8141e92fd7 100644
--- a/common/usbc/usb_pd_dpm.c
+++ b/common/usbc/usb_pd_dpm.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,12 +8,15 @@
* Refer to USB PD 3.0 spec, version 2.0, sections 8.2 and 8.3
*/
+#include "builtin/assert.h"
#include "charge_state.h"
+#include "chipset.h"
#include "compile_time_macros.h"
#include "console.h"
#include "ec_commands.h"
#include "hooks.h"
#include "power.h"
+#include "power_button.h"
#include "system.h"
#include "task.h"
#include "tcpm/tcpm.h"
@@ -23,8 +26,9 @@
#include "usb_mux.h"
#include "usb_pd.h"
#include "usb_pd_dpm.h"
-#include "usb_pd_tcpm.h"
#include "usb_pd_pdo.h"
+#include "usb_pd_tcpm.h"
+#include "usb_pd_timer.h"
#include "usb_pe_sm.h"
#include "usb_tbt_alt_mode.h"
@@ -33,8 +37,8 @@
#endif
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -48,6 +52,7 @@ static struct {
uint32_t vdm_attention[DPM_ATTENION_MAX_VDO];
int vdm_cnt;
mutex_t vdm_attention_mutex;
+ enum dpm_pd_button_state pd_button_state;
} dpm[CONFIG_USB_PD_PORT_MAX_COUNT];
#define DPM_SET_FLAG(port, flag) atomic_or(&dpm[(port)].flags, (flag))
@@ -55,16 +60,18 @@ static struct {
#define DPM_CHK_FLAG(port, flag) (dpm[(port)].flags & (flag))
/* Flags for internal DPM state */
-#define DPM_FLAG_MODE_ENTRY_DONE BIT(0)
-#define DPM_FLAG_EXIT_REQUEST BIT(1)
-#define DPM_FLAG_ENTER_DP BIT(2)
-#define DPM_FLAG_ENTER_TBT BIT(3)
-#define DPM_FLAG_ENTER_USB4 BIT(4)
-#define DPM_FLAG_ENTER_ANY (DPM_FLAG_ENTER_DP | DPM_FLAG_ENTER_TBT \
- | DPM_FLAG_ENTER_USB4)
-#define DPM_FLAG_SEND_ATTENTION BIT(5)
+#define DPM_FLAG_MODE_ENTRY_DONE BIT(0)
+#define DPM_FLAG_EXIT_REQUEST BIT(1)
+#define DPM_FLAG_ENTER_DP BIT(2)
+#define DPM_FLAG_ENTER_TBT BIT(3)
+#define DPM_FLAG_ENTER_USB4 BIT(4)
+#define DPM_FLAG_ENTER_ANY \
+ (DPM_FLAG_ENTER_DP | DPM_FLAG_ENTER_TBT | DPM_FLAG_ENTER_USB4)
+#define DPM_FLAG_SEND_ATTENTION BIT(5)
#define DPM_FLAG_DATA_RESET_REQUESTED BIT(6)
-#define DPM_FLAG_DATA_RESET_DONE BIT(7)
+#define DPM_FLAG_DATA_RESET_DONE BIT(7)
+#define DPM_FLAG_PD_BUTTON_PRESSED BIT(8)
+#define DPM_FLAG_PD_BUTTON_RELEASED BIT(9)
#ifdef CONFIG_ZEPHYR
static int init_vdm_attention_mutex(const struct device *dev)
@@ -81,6 +88,11 @@ static int init_vdm_attention_mutex(const struct device *dev)
SYS_INIT(init_vdm_attention_mutex, POST_KERNEL, 50);
#endif /* CONFIG_ZEPHYR */
+__overridable bool board_is_tbt_usb4_port(int port)
+{
+ return true;
+}
+
enum ec_status pd_request_vdm_attention(int port, const uint32_t *data,
int vdo_count)
{
@@ -120,17 +132,22 @@ enum ec_status pd_request_enter_mode(int port, enum typec_mode mode)
return EC_RES_INVALID_PARAM;
/* Only one enter request may be active at a time. */
- if (DPM_CHK_FLAG(port, DPM_FLAG_ENTER_DP |
- DPM_FLAG_ENTER_TBT |
- DPM_FLAG_ENTER_USB4))
+ if (DPM_CHK_FLAG(port, DPM_FLAG_ENTER_DP | DPM_FLAG_ENTER_TBT |
+ DPM_FLAG_ENTER_USB4))
return EC_RES_BUSY;
switch (mode) {
case TYPEC_MODE_DP:
+ if (dp_is_idle(port))
+ dp_init(port);
DPM_SET_FLAG(port, DPM_FLAG_ENTER_DP);
break;
#ifdef CONFIG_USB_PD_TBT_COMPAT_MODE
case TYPEC_MODE_TBT:
+ /* TODO(b/235984702#comment21): Refactor alt mode modules
+ * to better support mode reentry. */
+ if (dp_is_idle(port))
+ dp_init(port);
DPM_SET_FLAG(port, DPM_FLAG_ENTER_TBT);
break;
#endif /* CONFIG_USB_PD_TBT_COMPAT_MODE */
@@ -153,19 +170,20 @@ enum ec_status pd_request_enter_mode(int port, enum typec_mode mode)
void dpm_init(int port)
{
dpm[port].flags = 0;
+ dpm[port].pd_button_state = DPM_PD_BUTTON_IDLE;
}
void dpm_mode_exit_complete(int port)
{
DPM_CLR_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE | DPM_FLAG_EXIT_REQUEST |
- DPM_FLAG_SEND_ATTENTION);
+ DPM_FLAG_SEND_ATTENTION);
}
static void dpm_set_mode_entry_done(int port)
{
DPM_SET_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE);
DPM_CLR_FLAG(port, DPM_FLAG_ENTER_DP | DPM_FLAG_ENTER_TBT |
- DPM_FLAG_ENTER_USB4);
+ DPM_FLAG_ENTER_USB4);
}
void dpm_set_mode_exit_request(int port)
@@ -210,7 +228,7 @@ static bool dpm_mode_entry_requested(int port, enum typec_mode mode)
}
void dpm_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
- uint32_t *vdm)
+ uint32_t *vdm)
{
const uint16_t svid = PD_VDO_VID(vdm[0]);
@@ -227,12 +245,12 @@ void dpm_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count,
}
default:
CPRINTS("C%d: Received unexpected VDM ACK for SVID %d", port,
- svid);
+ svid);
}
}
void dpm_vdm_naked(int port, enum tcpci_msg_type type, uint16_t svid,
- uint8_t vdm_cmd)
+ uint8_t vdm_cmd)
{
switch (svid) {
case USB_SID_DISPLAYPORT:
@@ -245,7 +263,7 @@ void dpm_vdm_naked(int port, enum tcpci_msg_type type, uint16_t svid,
}
default:
CPRINTS("C%d: Received unexpected VDM NAK for SVID %d", port,
- svid);
+ svid);
}
}
@@ -261,16 +279,15 @@ static void dpm_attempt_mode_entry(int port)
uint32_t vdm[VDO_MAX_SIZE];
enum tcpci_msg_type tx_type = TCPCI_MSG_SOP;
bool enter_mode_requested =
- IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY) ? false : true;
+ IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY) ? false : true;
enum dpm_msg_setup_status status = MSG_SETUP_UNSUPPORTED;
if (pd_get_data_role(port) != PD_ROLE_DFP) {
- if (DPM_CHK_FLAG(port, DPM_FLAG_ENTER_DP |
- DPM_FLAG_ENTER_TBT |
- DPM_FLAG_ENTER_USB4))
+ if (DPM_CHK_FLAG(port, DPM_FLAG_ENTER_DP | DPM_FLAG_ENTER_TBT |
+ DPM_FLAG_ENTER_USB4))
DPM_CLR_FLAG(port, DPM_FLAG_ENTER_DP |
- DPM_FLAG_ENTER_TBT |
- DPM_FLAG_ENTER_USB4);
+ DPM_FLAG_ENTER_TBT |
+ DPM_FLAG_ENTER_USB4);
/*
* TODO(b/168030639): Notify the AP that the enter mode request
* failed.
@@ -298,9 +315,9 @@ static void dpm_attempt_mode_entry(int port)
return;
if (dp_entry_is_done(port) ||
- (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) &&
- tbt_entry_is_done(port)) ||
- (IS_ENABLED(CONFIG_USB_PD_USB4) && enter_usb_entry_is_done(port))) {
+ (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) &&
+ tbt_entry_is_done(port)) ||
+ (IS_ENABLED(CONFIG_USB_PD_USB4) && enter_usb_entry_is_done(port))) {
dpm_set_mode_entry_done(port);
return;
}
@@ -314,24 +331,23 @@ static void dpm_attempt_mode_entry(int port)
return;
if (IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY) &&
- IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
- DPM_CHK_FLAG(port, DPM_FLAG_ENTER_ANY) &&
- !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_REQUESTED) &&
- !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_DONE)) {
+ IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
+ DPM_CHK_FLAG(port, DPM_FLAG_ENTER_ANY) &&
+ !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_REQUESTED) &&
+ !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_DONE)) {
pd_dpm_request(port, DPM_REQUEST_DATA_RESET);
DPM_SET_FLAG(port, DPM_FLAG_DATA_RESET_REQUESTED);
return;
}
if (IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY) &&
- IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
- !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_DONE)) {
+ IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
+ !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_DONE)) {
return;
}
/* Check if port, port partner and cable support USB4. */
- if (IS_ENABLED(CONFIG_USB_PD_USB4) &&
- board_is_tbt_usb4_port(port) &&
+ if (IS_ENABLED(CONFIG_USB_PD_USB4) && board_is_tbt_usb4_port(port) &&
enter_usb_port_partner_is_capable(port) &&
enter_usb_cable_is_capable(port) &&
dpm_mode_entry_requested(port, TYPEC_MODE_USB4)) {
@@ -351,14 +367,13 @@ static void dpm_attempt_mode_entry(int port)
/* If not, check if they support Thunderbolt alt mode. */
if (IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE) &&
- board_is_tbt_usb4_port(port) &&
- pd_is_mode_discovered_for_svid(port, TCPCI_MSG_SOP,
- USB_VID_INTEL) &&
- dpm_mode_entry_requested(port, TYPEC_MODE_TBT)) {
+ board_is_tbt_usb4_port(port) &&
+ pd_is_mode_discovered_for_svid(port, TCPCI_MSG_SOP,
+ USB_VID_INTEL) &&
+ dpm_mode_entry_requested(port, TYPEC_MODE_TBT)) {
enter_mode_requested = true;
vdo_count = ARRAY_SIZE(vdm);
- status = tbt_setup_next_vdm(port, &vdo_count, vdm,
- &tx_type);
+ status = tbt_setup_next_vdm(port, &vdo_count, vdm, &tx_type);
}
/* If not, check if they support DisplayPort alt mode. */
@@ -381,7 +396,7 @@ static void dpm_attempt_mode_entry(int port)
* just mark setup done and get out of here.
*/
if (status != MSG_SETUP_SUCCESS &&
- !DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE)) {
+ !DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE)) {
if (enter_mode_requested) {
/*
* TODO(b/168030639): Notify the AP that mode entry
@@ -427,9 +442,8 @@ static void dpm_attempt_mode_exit(int port)
* is not supported, exit active modes individually.
*/
if (IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG)) {
- if (!DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_REQUESTED)
- && !DPM_CHK_FLAG(port,
- DPM_FLAG_DATA_RESET_DONE)) {
+ if (!DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_REQUESTED) &&
+ !DPM_CHK_FLAG(port, DPM_FLAG_DATA_RESET_DONE)) {
pd_dpm_request(port, DPM_REQUEST_DATA_RESET);
DPM_SET_FLAG(port, DPM_FLAG_DATA_RESET_REQUESTED);
return;
@@ -495,6 +509,118 @@ static void dpm_send_attention_vdm(int port)
DPM_CLR_FLAG(port, DPM_FLAG_SEND_ATTENTION);
}
+void dpm_handle_alert(int port, uint32_t ado)
+{
+ if (ado & ADO_EXTENDED_ALERT_EVENT) {
+ /* Extended Alert */
+ if (pd_get_data_role(port) == PD_ROLE_DFP &&
+ (ADO_EXTENDED_ALERT_EVENT_TYPE & ado) ==
+ ADO_POWER_BUTTON_PRESS) {
+ DPM_SET_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED);
+ } else if (pd_get_data_role(port) == PD_ROLE_DFP &&
+ (ADO_EXTENDED_ALERT_EVENT_TYPE & ado) ==
+ ADO_POWER_BUTTON_RELEASE) {
+ DPM_SET_FLAG(port, DPM_FLAG_PD_BUTTON_RELEASED);
+ }
+ }
+}
+
+static void dpm_run_pd_button_sm(int port)
+{
+#ifdef CONFIG_AP_POWER_CONTROL
+ if (!IS_ENABLED(CONFIG_POWER_BUTTON_X86) &&
+ !IS_ENABLED(CONFIG_CHIPSET_SC7180) &&
+ !IS_ENABLED(CONFIG_CHIPSET_SC7280)) {
+ /* Insufficient chipset API support for USB PD power button. */
+ DPM_CLR_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED);
+ DPM_CLR_FLAG(port, DPM_FLAG_PD_BUTTON_RELEASED);
+ return;
+ }
+
+ /*
+ * Check for invalid flag combination. Alerts can only send a press or
+ * release event at once and only one flag should be set. If press and
+ * release flags are both set, we cannot know the order they were
+ * received. Clear the flags, disable the timer and return to an idle
+ * state.
+ */
+ if (DPM_CHK_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED) &&
+ DPM_CHK_FLAG(port, DPM_FLAG_PD_BUTTON_RELEASED)) {
+ DPM_CLR_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED |
+ DPM_FLAG_PD_BUTTON_RELEASED);
+ pd_timer_disable(port, DPM_TIMER_PD_BUTTON_SHORT_PRESS);
+ pd_timer_disable(port, DPM_TIMER_PD_BUTTON_LONG_PRESS);
+ dpm[port].pd_button_state = DPM_PD_BUTTON_IDLE;
+ return;
+ }
+
+ switch (dpm[port].pd_button_state) {
+ case DPM_PD_BUTTON_IDLE:
+ if (DPM_CHK_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED)) {
+ pd_timer_enable(port, DPM_TIMER_PD_BUTTON_SHORT_PRESS,
+ CONFIG_USB_PD_SHORT_PRESS_MAX_MS *
+ MSEC);
+ pd_timer_enable(port, DPM_TIMER_PD_BUTTON_LONG_PRESS,
+ CONFIG_USB_PD_LONG_PRESS_MAX_MS * MSEC);
+ dpm[port].pd_button_state = DPM_PD_BUTTON_PRESSED;
+ }
+ break;
+ case DPM_PD_BUTTON_PRESSED:
+ if (DPM_CHK_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED)) {
+ pd_timer_enable(port, DPM_TIMER_PD_BUTTON_SHORT_PRESS,
+ CONFIG_USB_PD_SHORT_PRESS_MAX_MS *
+ MSEC);
+ pd_timer_enable(port, DPM_TIMER_PD_BUTTON_LONG_PRESS,
+ CONFIG_USB_PD_LONG_PRESS_MAX_MS * MSEC);
+ } else if (pd_timer_is_expired(
+ port, DPM_TIMER_PD_BUTTON_LONG_PRESS)) {
+ pd_timer_disable(port, DPM_TIMER_PD_BUTTON_SHORT_PRESS);
+ pd_timer_disable(port, DPM_TIMER_PD_BUTTON_LONG_PRESS);
+ dpm[port].pd_button_state = DPM_PD_BUTTON_IDLE;
+ } else if (DPM_CHK_FLAG(port, DPM_FLAG_PD_BUTTON_RELEASED)) {
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
+ /*
+ * Wake chipset on any button press when the
+ * system is off.
+ */
+ chipset_power_on();
+ } else if (chipset_in_state(
+ CHIPSET_STATE_ANY_SUSPEND) ||
+ chipset_in_state(CHIPSET_STATE_ON)) {
+ if (pd_timer_is_expired(
+ port,
+ DPM_TIMER_PD_BUTTON_SHORT_PRESS)) {
+ /*
+ * Shutdown chipset on long USB PD power
+ * button press.
+ */
+ chipset_force_shutdown(
+ CHIPSET_SHUTDOWN_BUTTON);
+ } else {
+ /*
+ * Simulate a short power button press
+ * on short USB PD power button press.
+ * This will wake the system from
+ * suspend, or bring up the power UI
+ * when the system is on.
+ */
+ power_button_simulate_press(
+ USB_PD_SHORT_BUTTON_PRESS_MS);
+ }
+ }
+ pd_timer_disable(port, DPM_TIMER_PD_BUTTON_SHORT_PRESS);
+ pd_timer_disable(port, DPM_TIMER_PD_BUTTON_LONG_PRESS);
+ dpm[port].pd_button_state = DPM_PD_BUTTON_IDLE;
+ }
+ break;
+ }
+#endif /* CONFIG_AP_POWER_CONTROL */
+
+ /* After checking flags, clear them. */
+ DPM_CLR_FLAG(port, DPM_FLAG_PD_BUTTON_PRESSED);
+ DPM_CLR_FLAG(port, DPM_FLAG_PD_BUTTON_RELEASED);
+}
+
void dpm_run(int port)
{
if (pd_get_data_role(port) == PD_ROLE_DFP) {
@@ -503,6 +629,9 @@ void dpm_run(int port)
dpm_attempt_mode_exit(port);
else if (!DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE))
dpm_attempt_mode_entry(port);
+
+ /* Run USB PD Power button state machine */
+ dpm_run_pd_button_sm(port);
} else {
/* Run UFP related DPM requests */
if (DPM_CHK_FLAG(port, DPM_FLAG_SEND_ATTENTION))
@@ -523,7 +652,7 @@ void dpm_run(int port)
* Note: request bitmasks should be accessed atomically as other ports may alter
* them
*/
-static uint32_t max_current_claimed;
+static uint32_t max_current_claimed;
K_MUTEX_DEFINE(max_current_claimed_lock);
/* Ports with PD sink needing > 1.5 A */
@@ -533,7 +662,10 @@ static atomic_t source_frs_max_requested;
/* Ports with non-PD sinks, so current requirements are unknown */
static atomic_t non_pd_sink_max_requested;
-#define LOWEST_PORT(p) __builtin_ctz(p) /* Undefined behavior if p == 0 */
+/* BIST shared test mode */
+static bool bist_shared_mode_enabled;
+
+#define LOWEST_PORT(p) __builtin_ctz(p) /* Undefined behavior if p == 0 */
static int count_port_bits(uint32_t bitmask)
{
@@ -568,12 +700,19 @@ static void balance_source_ports(void)
if (deferred_waiting)
return;
+ /*
+ * Turn off all shared power logic while BIST shared test mode is active
+ * on the system.
+ */
+ if (bist_shared_mode_enabled)
+ return;
+
mutex_lock(&max_current_claimed_lock);
/* Remove any ports which no longer require 3.0 A */
- removed_ports = max_current_claimed & ~(sink_max_pdo_requested |
- source_frs_max_requested |
- non_pd_sink_max_requested);
+ removed_ports = max_current_claimed &
+ ~(sink_max_pdo_requested | source_frs_max_requested |
+ non_pd_sink_max_requested);
max_current_claimed &= ~removed_ports;
/* Allocate 3.0 A to new PD sink ports that need it */
@@ -582,7 +721,7 @@ static void balance_source_ports(void)
int new_max_port = LOWEST_PORT(new_ports);
if (count_port_bits(max_current_claimed) <
- CONFIG_USB_PD_3A_PORTS) {
+ CONFIG_USB_PD_3A_PORTS) {
max_current_claimed |= BIT(new_max_port);
typec_select_src_current_limit_rp(new_max_port,
TYPEC_RP_3A0);
@@ -590,7 +729,8 @@ static void balance_source_ports(void)
/* Always downgrade non-PD ports first */
int rem_non_pd = LOWEST_PORT(non_pd_sink_max_requested &
max_current_claimed);
- typec_select_src_current_limit_rp(rem_non_pd,
+ typec_select_src_current_limit_rp(
+ rem_non_pd,
typec_get_default_current_limit_rp(rem_non_pd));
max_current_claimed &= ~BIT(rem_non_pd);
@@ -602,7 +742,7 @@ static void balance_source_ports(void)
} else if (source_frs_max_requested & max_current_claimed) {
/* Downgrade lowest FRS port from 3.0 A slot */
int rem_frs = LOWEST_PORT(source_frs_max_requested &
- max_current_claimed);
+ max_current_claimed);
pd_dpm_request(rem_frs, DPM_REQUEST_FRS_DET_DISABLE);
max_current_claimed &= ~BIT(rem_frs);
@@ -624,14 +764,15 @@ static void balance_source_ports(void)
int new_frs_port = LOWEST_PORT(new_ports);
if (count_port_bits(max_current_claimed) <
- CONFIG_USB_PD_3A_PORTS) {
+ CONFIG_USB_PD_3A_PORTS) {
max_current_claimed |= BIT(new_frs_port);
pd_dpm_request(new_frs_port,
DPM_REQUEST_FRS_DET_ENABLE);
} else if (non_pd_sink_max_requested & max_current_claimed) {
int rem_non_pd = LOWEST_PORT(non_pd_sink_max_requested &
max_current_claimed);
- typec_select_src_current_limit_rp(rem_non_pd,
+ typec_select_src_current_limit_rp(
+ rem_non_pd,
typec_get_default_current_limit_rp(rem_non_pd));
max_current_claimed &= ~BIT(rem_non_pd);
@@ -653,7 +794,7 @@ static void balance_source_ports(void)
int new_max_port = LOWEST_PORT(new_ports);
if (count_port_bits(max_current_claimed) <
- CONFIG_USB_PD_3A_PORTS) {
+ CONFIG_USB_PD_3A_PORTS) {
max_current_claimed |= BIT(new_max_port);
typec_select_src_current_limit_rp(new_max_port,
TYPEC_RP_3A0);
@@ -741,7 +882,7 @@ void dpm_evaluate_request_rdo(int port, uint32_t rdo)
return;
op_ma = (rdo >> 10) & 0x3FF;
- if ((BIT(port) && sink_max_pdo_requested) && (op_ma <= 150)) {
+ if ((BIT(port) & sink_max_pdo_requested) && (op_ma <= 150)) {
/*
* sink_max_pdo_requested will be set when we get 5V/3A sink
* capability from port partner. If port partner only request
@@ -766,8 +907,8 @@ void dpm_remove_sink(int port)
atomic_clear_bits(&non_pd_sink_max_requested, BIT(port));
/* Restore selected default Rp on the port */
- typec_select_src_current_limit_rp(port,
- typec_get_default_current_limit_rp(port));
+ typec_select_src_current_limit_rp(
+ port, typec_get_default_current_limit_rp(port));
balance_source_ports();
}
@@ -788,16 +929,83 @@ void dpm_remove_source(int port)
balance_source_ports();
}
+void dpm_bist_shared_mode_enter(int port)
+{
+ /*
+ * From 6.4.3.3.1 BIST Shared Test Mode Entry:
+ *
+ * "When any Master Port in a shared capacity group receives a BIST
+ * Message with a BIST Shared Test Mode Entry BIST Data Object, while
+ * in the PE_SRC_Ready State, the UUT Shall enter a compliance test
+ * mode where the maximum source capability is always offered on every
+ * port, regardless of the availability of shared power i.e. all shared
+ * power management is disabled.
+ * . . .
+ * On entering this mode, the UUT Shall send a new Source_Capabilities
+ * Message from each Port in the shared capacity group within
+ * tBISTSharedTestMode. The Tester will not exceed the shared capacity
+ * during this mode."
+ */
+
+ /* Shared mode is unnecessary without at least one 3.0 A port */
+ if (CONFIG_USB_PD_3A_PORTS == 0)
+ return;
+
+ /* Enter mode only if this port had been in PE_SRC_Ready */
+ if (pd_get_power_role(port) != PD_ROLE_SOURCE)
+ return;
+
+ bist_shared_mode_enabled = true;
+
+ /* Trigger new source caps on all source ports */
+ for (int i = 0; i < board_get_usb_pd_port_count(); i++) {
+ if (pd_get_power_role(i) == PD_ROLE_SOURCE)
+ typec_select_src_current_limit_rp(i, TYPEC_RP_3A0);
+ }
+}
+
+void dpm_bist_shared_mode_exit(int port)
+{
+ /*
+ * From 6.4.3.3.2 BIST Shared Test Mode Exit:
+ *
+ * "Upon receipt of a BIST Message, with a BIST Shared Test Mode Exit
+ * BIST Data Object, the UUT Shall return a GoodCRC Message and Shall
+ * exit the BIST Shared Capacity Test Mode.
+ * . . .
+ * On exiting the mode, the UUT May send a new Source_Capabilities
+ * Message to each port in the shared capacity group or the UUT May
+ * perform ErrorRecovery on each port."
+ */
+
+ /* Shared mode is unnecessary without at least one 3.0 A port */
+ if (CONFIG_USB_PD_3A_PORTS == 0)
+ return;
+
+ /* Do nothing if Exit was received with no Entry */
+ if (!bist_shared_mode_enabled)
+ return;
+
+ bist_shared_mode_enabled = false;
+
+ /* Declare error recovery bankruptcy */
+ for (int i = 0; i < board_get_usb_pd_port_count(); i++) {
+ pd_set_error_recovery(i);
+ }
+}
+
/*
* Note: all ports receive the 1.5 A source offering until they are found to
* match a criteria on the 3.0 A priority list (ex. through sink capability
* probing), at which point they will be offered a new 3.0 A source capability.
+ *
+ * All ports must be offered our full capability while in BIST shared test mode.
*/
__overridable int dpm_get_source_pdo(const uint32_t **src_pdo, const int port)
{
/* Max PDO may not exist on boards which don't offer 3 A */
#if CONFIG_USB_PD_3A_PORTS > 0
- if (max_current_claimed & BIT(port)) {
+ if (max_current_claimed & BIT(port) || bist_shared_mode_enabled) {
*src_pdo = pd_src_pdo_max;
return pd_src_pdo_max_cnt;
}
@@ -812,7 +1020,7 @@ int dpm_get_source_current(const int port)
if (pd_get_power_role(port) == PD_ROLE_SINK)
return 0;
- if (max_current_claimed & BIT(port))
+ if (max_current_claimed & BIT(port) || bist_shared_mode_enabled)
return 3000;
else if (typec_get_default_current_limit_rp(port) == TYPEC_RP_1A5)
return 1500;
@@ -820,8 +1028,8 @@ int dpm_get_source_current(const int port)
return 500;
}
-__overridable enum pd_sdb_power_indicator board_get_pd_sdb_power_indicator(
-enum pd_sdb_power_state power_state)
+__overridable enum pd_sdb_power_indicator
+board_get_pd_sdb_power_indicator(enum pd_sdb_power_state power_state)
{
/*
* LED on for S0 and blinking for S0ix/S3.
@@ -856,7 +1064,7 @@ static uint8_t get_status_internal_temp(void)
else if (temp_c < 2)
temp_c = 1;
- return (uint8_t) temp_c;
+ return (uint8_t)temp_c;
#else
return 0;
#endif
diff --git a/common/usbc/usb_pd_host.c b/common/usbc/usb_pd_host.c
index d6bd61057f..5d22e8ecd3 100644
--- a/common/usbc/usb_pd_host.c
+++ b/common/usbc/usb_pd_host.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -15,8 +15,8 @@
#include "usb_pd_tcpm.h"
#include "util.h"
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
/* Retrieve all discovery results for the given port and transmit type */
static enum ec_status hc_typec_discovery(struct host_cmd_handler_args *args)
@@ -35,8 +35,8 @@ static enum ec_status hc_typec_discovery(struct host_cmd_handler_args *args)
if (p->partner_type > TYPEC_PARTNER_SOP_PRIME)
return EC_RES_INVALID_PARAM;
- type = p->partner_type == TYPEC_PARTNER_SOP ?
- TCPCI_MSG_SOP : TCPCI_MSG_SOP_PRIME;
+ type = p->partner_type == TYPEC_PARTNER_SOP ? TCPCI_MSG_SOP :
+ TCPCI_MSG_SOP_PRIME;
/*
* Clear out access mask so we can track if tasks have touched data
@@ -61,8 +61,9 @@ static enum ec_status hc_typec_discovery(struct host_cmd_handler_args *args)
if (pd_get_modes_discovery(p->port, type) == PD_DISC_COMPLETE) {
int svid_i;
- int max_resp_svids = (args->response_max - args->response_size)/
- sizeof(struct svid_mode_info);
+ int max_resp_svids =
+ (args->response_max - args->response_size) /
+ sizeof(struct svid_mode_info);
if (disc->svid_cnt > max_resp_svids) {
CPRINTS("Warn: SVIDS exceeded HC response");
@@ -74,7 +75,7 @@ static enum ec_status hc_typec_discovery(struct host_cmd_handler_args *args)
for (svid_i = 0; svid_i < r->svid_count; svid_i++) {
r->svids[svid_i].svid = disc->svids[svid_i].svid;
r->svids[svid_i].mode_count =
- disc->svids[svid_i].mode_cnt;
+ disc->svids[svid_i].mode_cnt;
memcpy(r->svids[svid_i].mode_vdo,
disc->svids[svid_i].mode_vdo,
sizeof(r->svids[svid_i].mode_vdo));
@@ -96,14 +97,12 @@ static enum ec_status hc_typec_discovery(struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_TYPEC_DISCOVERY,
- hc_typec_discovery,
+DECLARE_HOST_COMMAND(EC_CMD_TYPEC_DISCOVERY, hc_typec_discovery,
EC_VER_MASK(0));
/* Default to feature unavailable, with boards supporting it overriding */
__overridable enum ec_status
- board_set_tbt_ufp_reply(int port,
- enum typec_tbt_ufp_reply reply)
+board_set_tbt_ufp_reply(int port, enum typec_tbt_ufp_reply reply)
{
return EC_RES_UNAVAILABLE;
}
@@ -111,6 +110,7 @@ __overridable enum ec_status
static enum ec_status hc_typec_control(struct host_cmd_handler_args *args)
{
const struct ec_params_typec_control *p = args->params;
+ mux_state_t mode;
if (p->port >= board_get_usb_pd_port_count())
return EC_RES_INVALID_PARAM;
@@ -127,11 +127,13 @@ static enum ec_status hc_typec_control(struct host_cmd_handler_args *args)
case TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY:
return board_set_tbt_ufp_reply(p->port, p->tbt_ufp_reply);
case TYPEC_CONTROL_COMMAND_USB_MUX_SET:
+ /* The EC will fill in polarity, so filter flip out */
+ mode = p->mux_params.mux_flags & ~USB_PD_MUX_POLARITY_INVERTED;
+
if (!IS_ENABLED(CONFIG_USB_MUX_AP_CONTROL))
return EC_RES_INVALID_PARAM;
- /* TODO: Check if AP wants to set usb mode or polarity */
- usb_mux_set_single(p->port, p->mux_params.mux_index,
- p->mux_params.mux_flags,
+
+ usb_mux_set_single(p->port, p->mux_params.mux_index, mode,
USB_SWITCH_CONNECT,
polarity_rm_dts(pd_get_polarity(p->port)));
return EC_RES_SUCCESS;
@@ -139,7 +141,6 @@ static enum ec_status hc_typec_control(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
}
-
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_TYPEC_CONTROL, hc_typec_control, EC_VER_MASK(0));
@@ -177,13 +178,15 @@ static enum ec_status hc_typec_status(struct host_cmd_handler_args *args)
r->events = pd_get_events(p->port);
r->sop_revision = r->sop_connected ?
- PD_STATUS_REV_SET_MAJOR(pd_get_rev(p->port, TCPCI_MSG_SOP)) : 0;
+ PD_STATUS_REV_SET_MAJOR(
+ pd_get_rev(p->port, TCPCI_MSG_SOP)) :
+ 0;
r->sop_prime_revision =
pd_get_identity_discovery(p->port, TCPCI_MSG_SOP_PRIME) ==
- PD_DISC_COMPLETE ?
- PD_STATUS_REV_SET_MAJOR(pd_get_rev(p->port,
- TCPCI_MSG_SOP_PRIME))
- : 0;
+ PD_DISC_COMPLETE ?
+ PD_STATUS_REV_SET_MAJOR(
+ pd_get_rev(p->port, TCPCI_MSG_SOP_PRIME)) :
+ 0;
r->source_cap_count = pd_get_src_cap_cnt(p->port);
memcpy(r->source_cap_pdos, pd_get_src_caps(p->port),
diff --git a/common/usbc/usb_pd_timer.c b/common/usbc/usb_pd_timer.c
index a1859ac9e9..a6ec07125d 100644
--- a/common/usbc/usb_pd_timer.c
+++ b/common/usbc/usb_pd_timer.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.
*/
@@ -14,36 +14,35 @@
#include "usb_pd_timer.h"
#include "usb_tc_sm.h"
-#define MAX_PD_PORTS CONFIG_USB_PD_PORT_MAX_COUNT
-#define MAX_PD_TIMERS PD_TIMER_COUNT
+#define MAX_PD_PORTS CONFIG_USB_PD_PORT_MAX_COUNT
+#define MAX_PD_TIMERS PD_TIMER_COUNT
#define PD_TIMERS_ALL_MASK (UINT64_MAX >> (64 - PD_TIMER_COUNT))
-#define MAX_EXPIRE (0x7FFFFFFF)
-#define NO_TIMEOUT (-1)
-#define EXPIRE_NOW (0)
+#define MAX_EXPIRE (0x7FFFFFFF)
+#define NO_TIMEOUT (-1)
+#define EXPIRE_NOW (0)
#define PD_SET_ACTIVE(p, bit) \
- atomic_set_bit(timer_active, (p) * PD_TIMER_COUNT + (bit))
+ atomic_set_bit(timer_active, (p)*PD_TIMER_COUNT + (bit))
#define PD_CLR_ACTIVE(p, bit) \
- atomic_clear_bit(timer_active, (p) * PD_TIMER_COUNT + (bit))
+ atomic_clear_bit(timer_active, (p)*PD_TIMER_COUNT + (bit))
#define PD_CHK_ACTIVE(p, bit) \
- atomic_test_bit(timer_active, (p) * PD_TIMER_COUNT + (bit))
+ atomic_test_bit(timer_active, (p)*PD_TIMER_COUNT + (bit))
#define PD_SET_DISABLED(p, bit) \
- atomic_set_bit(timer_disabled, (p) * PD_TIMER_COUNT + (bit))
+ atomic_set_bit(timer_disabled, (p)*PD_TIMER_COUNT + (bit))
#define PD_CLR_DISABLED(p, bit) \
- atomic_clear_bit(timer_disabled, (p) * PD_TIMER_COUNT + (bit))
+ atomic_clear_bit(timer_disabled, (p)*PD_TIMER_COUNT + (bit))
#define PD_CHK_DISABLED(p, bit) \
- atomic_test_bit(timer_disabled, (p) * PD_TIMER_COUNT + (bit))
+ atomic_test_bit(timer_disabled, (p)*PD_TIMER_COUNT + (bit))
-test_mockable_static
-ATOMIC_DEFINE(timer_active, PD_TIMER_COUNT * MAX_PD_PORTS);
-test_mockable_static
-ATOMIC_DEFINE(timer_disabled, PD_TIMER_COUNT * MAX_PD_PORTS);
+test_mockable_static ATOMIC_DEFINE(timer_active, PD_TIMER_COUNT *MAX_PD_PORTS);
+test_mockable_static ATOMIC_DEFINE(timer_disabled,
+ PD_TIMER_COUNT *MAX_PD_PORTS);
static uint64_t timer_expires[MAX_PD_PORTS][PD_TIMER_COUNT];
/*
@@ -52,42 +51,43 @@ static uint64_t timer_expires[MAX_PD_PORTS][PD_TIMER_COUNT];
static int count[MAX_PD_PORTS];
static int max_count[MAX_PD_PORTS];
-__maybe_unused static __const_data const char * const pd_timer_names[] = {
- [PE_TIMER_BIST_CONT_MODE] = "PE-BIST_CONT_MODE",
+__maybe_unused static __const_data const char *const pd_timer_names[] = {
+ [DPM_TIMER_PD_BUTTON_LONG_PRESS] = "DPM-PD_BUTTON_LONG_PRESS",
+ [DPM_TIMER_PD_BUTTON_SHORT_PRESS] = "DPM-PD_BUTTON_SHORT_PRESS",
+ [PE_TIMER_BIST_CONT_MODE] = "PE-BIST_CONT_MODE",
[PE_TIMER_CHUNKING_NOT_SUPPORTED] = "PE-CHUNKING_NOT_SUPPORTED",
- [PE_TIMER_DISCOVER_IDENTITY] = "PE-DISCOVER_IDENTITY",
- [PE_TIMER_NO_RESPONSE] = "PE-NO_RESPONSE",
- [PE_TIMER_PR_SWAP_WAIT] = "PE-PR_SWAP_WAIT",
- [PE_TIMER_PS_HARD_RESET] = "PE-PS_HARD_RESET",
- [PE_TIMER_PS_SOURCE] = "PE-PS_SOURCE",
- [PE_TIMER_PS_TRANSITION] = "PE-PS_TRANSITION",
- [PE_TIMER_SENDER_RESPONSE] = "PE-SENDER_RESPONSE",
- [PE_TIMER_SINK_REQUEST] = "PE-SINK_REQUEST",
- [PE_TIMER_SOURCE_CAP] = "PE-SOURCE_CAP",
- [PE_TIMER_SRC_TRANSITION] = "PE-SRC_TRANSITION",
- [PE_TIMER_SWAP_SOURCE_START] = "PE-SWAP_SOURCE_START",
- [PE_TIMER_TIMEOUT] = "PE-TIMEOUT",
- [PE_TIMER_VCONN_ON] = "PE-VCONN_ON",
- [PE_TIMER_VDM_RESPONSE] = "PE-VDM_RESPONSE",
- [PE_TIMER_WAIT_AND_ADD_JITTER] = "PE-WAIT_AND_ADD_JITTER",
- [PE_TIMER_VCONN_DISCHARGE] = "PE-VCONN_DISCHARGE",
- [PE_TIMER_VCONN_REAPPLIED] = "PE-VCONN_REAPPLIED",
- [PE_TIMER_DATA_RESET_FAIL] = "PE-DATA_RESET_FAIL",
-
- [PR_TIMER_CHUNK_SENDER_REQUEST] = "PR-CHUNK_SENDER_REQUEST",
+ [PE_TIMER_DISCOVER_IDENTITY] = "PE-DISCOVER_IDENTITY",
+ [PE_TIMER_NO_RESPONSE] = "PE-NO_RESPONSE",
+ [PE_TIMER_PR_SWAP_WAIT] = "PE-PR_SWAP_WAIT",
+ [PE_TIMER_PS_HARD_RESET] = "PE-PS_HARD_RESET",
+ [PE_TIMER_PS_SOURCE] = "PE-PS_SOURCE",
+ [PE_TIMER_PS_TRANSITION] = "PE-PS_TRANSITION",
+ [PE_TIMER_SENDER_RESPONSE] = "PE-SENDER_RESPONSE",
+ [PE_TIMER_SINK_REQUEST] = "PE-SINK_REQUEST",
+ [PE_TIMER_SOURCE_CAP] = "PE-SOURCE_CAP",
+ [PE_TIMER_SRC_TRANSITION] = "PE-SRC_TRANSITION",
+ [PE_TIMER_SWAP_SOURCE_START] = "PE-SWAP_SOURCE_START",
+ [PE_TIMER_TIMEOUT] = "PE-TIMEOUT",
+ [PE_TIMER_VCONN_ON] = "PE-VCONN_ON",
+ [PE_TIMER_VDM_RESPONSE] = "PE-VDM_RESPONSE",
+ [PE_TIMER_WAIT_AND_ADD_JITTER] = "PE-WAIT_AND_ADD_JITTER",
+ [PE_TIMER_VCONN_DISCHARGE] = "PE-VCONN_DISCHARGE",
+ [PE_TIMER_VCONN_REAPPLIED] = "PE-VCONN_REAPPLIED",
+ [PE_TIMER_DATA_RESET_FAIL] = "PE-DATA_RESET_FAIL",
+
+ [PR_TIMER_CHUNK_SENDER_REQUEST] = "PR-CHUNK_SENDER_REQUEST",
[PR_TIMER_CHUNK_SENDER_RESPONSE] = "PR-CHUNK_SENDER_RESPONSE",
- [PR_TIMER_HARD_RESET_COMPLETE] = "PR-HARD_RESET_COMPLETE",
- [PR_TIMER_SINK_TX] = "PR-SINK_TX",
- [PR_TIMER_TCPC_TX_TIMEOUT] = "PR-TCPC_TX_TIMEOUT",
-
- [TC_TIMER_CC_DEBOUNCE] = "TC-CC_DEBOUNCE",
- [TC_TIMER_LOW_POWER_EXIT_TIME] = "TC-LOW_POWER_EXIT_TIME",
- [TC_TIMER_LOW_POWER_TIME] = "TC-LOW_POWER_TIME",
- [TC_TIMER_NEXT_ROLE_SWAP] = "TC-NEXT_ROLE_SWAP",
- [TC_TIMER_PD_DEBOUNCE] = "TC-PD_DEBOUNCE",
- [TC_TIMER_TIMEOUT] = "TC-TIMEOUT",
- [TC_TIMER_TRY_WAIT_DEBOUNCE] = "TC-TRY_WAIT_DEBOUNCE",
- [TC_TIMER_VBUS_DEBOUNCE] = "TC-VBUS_DEBOUNCE",
+ [PR_TIMER_HARD_RESET_COMPLETE] = "PR-HARD_RESET_COMPLETE",
+ [PR_TIMER_SINK_TX] = "PR-SINK_TX",
+ [PR_TIMER_TCPC_TX_TIMEOUT] = "PR-TCPC_TX_TIMEOUT",
+ [TC_TIMER_CC_DEBOUNCE] = "TC-CC_DEBOUNCE",
+ [TC_TIMER_LOW_POWER_EXIT_TIME] = "TC-LOW_POWER_EXIT_TIME",
+ [TC_TIMER_LOW_POWER_TIME] = "TC-LOW_POWER_TIME",
+ [TC_TIMER_NEXT_ROLE_SWAP] = "TC-NEXT_ROLE_SWAP",
+ [TC_TIMER_PD_DEBOUNCE] = "TC-PD_DEBOUNCE",
+ [TC_TIMER_TIMEOUT] = "TC-TIMEOUT",
+ [TC_TIMER_TRY_WAIT_DEBOUNCE] = "TC-TRY_WAIT_DEBOUNCE",
+ [TC_TIMER_VBUS_DEBOUNCE] = "TC-VBUS_DEBOUNCE",
};
/*****************************************************************************
@@ -171,17 +171,21 @@ void pd_timer_disable_range(int port, enum pd_timer_range range)
enum pd_task_timer timer;
switch (range) {
+ case DPM_TIMER_RANGE:
+ start = DPM_TIMER_START;
+ end = DPM_TIMER_END;
+ break;
case PE_TIMER_RANGE:
- start = PE_TIMER_START;
- end = PE_TIMER_END;
+ start = PE_TIMER_START;
+ end = PE_TIMER_END;
break;
case PR_TIMER_RANGE:
- start = PR_TIMER_START;
- end = PR_TIMER_END;
+ start = PR_TIMER_START;
+ end = PR_TIMER_END;
break;
case TC_TIMER_RANGE:
- start = TC_TIMER_START;
- end = TC_TIMER_END;
+ start = TC_TIMER_START;
+ end = TC_TIMER_END;
break;
default:
return;
@@ -253,8 +257,8 @@ test_mockable_static void pd_timer_dump(int port)
int timer;
uint64_t now = get_time().val;
- ccprints("Timers(%d): cur=%d max=%d",
- port, count[port], max_count[port]);
+ ccprints("Timers(%d): cur=%d max=%d", port, count[port],
+ max_count[port]);
for (timer = 0; timer < PD_TIMER_COUNT; ++timer) {
if (pd_timer_is_disabled(port, timer)) {
@@ -265,14 +269,13 @@ test_mockable_static void pd_timer_dump(int port)
if (now < timer_expires[port][timer])
delta = timer_expires[port][timer] - now;
- ccprints("[%2d] Active: %s (%d%s)",
- timer, pd_timer_names[timer], (uint32_t)delta,
- tc_event_loop_is_paused(port)
- ? "-PAUSED"
- : "");
+ ccprints("[%2d] Active: %s (%d%s)", timer,
+ pd_timer_names[timer], (uint32_t)delta,
+ tc_event_loop_is_paused(port) ? "-PAUSED" :
+ "");
} else {
- ccprints("[%2d] Inactive: %s",
- timer, pd_timer_names[timer]);
+ ccprints("[%2d] Inactive: %s", timer,
+ pd_timer_names[timer]);
}
}
}
diff --git a/common/usbc/usb_pe_ctvpd_sm.c b/common/usbc/usb_pe_ctvpd_sm.c
index 346a57a461..f3f3d8af9b 100644
--- a/common/usbc/usb_pe_ctvpd_sm.c
+++ b/common/usbc/usb_pe_ctvpd_sm.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -167,55 +167,48 @@ static void pe_request_run(const int port)
/* Prepare to send ACK */
/* VDM Header */
- payload[0] = VDO(
- USB_VID_GOOGLE,
- 1, /* Structured VDM */
- VDO_SVDM_VERS(1) |
- VDO_CMDT(CMDT_RSP_ACK) |
- CMD_DISCOVER_IDENT);
+ payload[0] = VDO(USB_VID_GOOGLE, 1, /* Structured VDM */
+ VDO_SVDM_VERS(1) | VDO_CMDT(CMDT_RSP_ACK) |
+ CMD_DISCOVER_IDENT);
/* ID Header VDO */
- payload[1] = VDO_IDH(
- 0, /* Not a USB Host */
- 1, /* Capable of being enumerated as USB Device */
- IDH_PTYPE_VPD,
- 0, /* Modal Operation Not Supported */
- USB_VID_GOOGLE);
+ payload[1] = VDO_IDH(0, /* Not a USB Host */
+ 1, /* Capable of being enumerated as USB
+ Device */
+ IDH_PTYPE_VPD, 0, /* Modal Operation Not
+ Supported */
+ USB_VID_GOOGLE);
/* Cert State VDO */
payload[2] = 0;
/* Product VDO */
- payload[3] = VDO_PRODUCT(
- CONFIG_USB_PID,
- USB_BCD_DEVICE);
+ payload[3] = VDO_PRODUCT(CONFIG_USB_PID, USB_BCD_DEVICE);
/* VPD VDO */
payload[4] = VDO_VPD(
- VPD_HW_VERSION,
- VPD_FW_VERSION,
- VPD_MAX_VBUS_20V,
- IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_CT_CURRENT
- : 0,
- IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_VBUS_IMP(
- VPD_VBUS_IMPEDANCE)
- : 0,
- IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_GND_IMP(
- VPD_GND_IMPEDANCE)
- : 0,
- IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_CTS_SUPPORTED
- : VPD_CTS_NOT_SUPPORTED);
+ VPD_HW_VERSION, VPD_FW_VERSION, VPD_MAX_VBUS_20V,
+ IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_CT_CURRENT : 0,
+ IS_ENABLED(CONFIG_USB_CTVPD) ?
+ VPD_VBUS_IMP(VPD_VBUS_IMPEDANCE) :
+ 0,
+ IS_ENABLED(CONFIG_USB_CTVPD) ?
+ VPD_GND_IMP(VPD_GND_IMPEDANCE) :
+ 0,
+ IS_ENABLED(CONFIG_USB_CTVPD) ? VPD_CTS_SUPPORTED :
+ VPD_CTS_NOT_SUPPORTED);
/* 20 bytes, 5 data objects */
tx_emsg[port].len = 20;
/* Set to highest revision supported by both ports. */
prl_set_rev(port, TCPCI_MSG_SOP_PRIME,
- (PD_HEADER_REV(header) > PD_REV30) ?
- PD_REV30 : PD_HEADER_REV(header));
+ (PD_HEADER_REV(header) > PD_REV30) ?
+ PD_REV30 :
+ PD_HEADER_REV(header));
/* Send the ACK */
prl_send_data_msg(port, TCPCI_MSG_SOP_PRIME,
- PD_DATA_VENDOR_DEF);
+ PD_DATA_VENDOR_DEF);
}
}
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index baa2c98ec8..1094e4180c 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
#include "atomic.h"
#include "battery.h"
#include "battery_smart.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "common.h"
@@ -15,6 +16,7 @@
#include "ec_commands.h"
#include "hooks.h"
#include "host_command.h"
+#include "power_button.h"
#include "stdbool.h"
#include "system.h"
#include "task.h"
@@ -47,41 +49,42 @@
*/
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
#endif
-#define CPRINTF_LX(x, format, args...) \
- do { \
- if (pe_debug_level >= x) \
- CPRINTF(format, ## args); \
+#define CPRINTF_LX(x, format, args...) \
+ do { \
+ if (pe_debug_level >= x) \
+ CPRINTF(format, ##args); \
} while (0)
-#define CPRINTF_L1(format, args...) CPRINTF_LX(1, format, ## args)
-#define CPRINTF_L2(format, args...) CPRINTF_LX(2, format, ## args)
-#define CPRINTF_L3(format, args...) CPRINTF_LX(3, format, ## args)
-
-#define CPRINTS_LX(x, format, args...) \
- do { \
- if (pe_debug_level >= x) \
- CPRINTS(format, ## args); \
+#define CPRINTF_L1(format, args...) CPRINTF_LX(1, format, ##args)
+#define CPRINTF_L2(format, args...) CPRINTF_LX(2, format, ##args)
+#define CPRINTF_L3(format, args...) CPRINTF_LX(3, format, ##args)
+
+#define CPRINTS_LX(x, format, args...) \
+ do { \
+ if (pe_debug_level >= x) \
+ CPRINTS(format, ##args); \
} while (0)
-#define CPRINTS_L1(format, args...) CPRINTS_LX(1, format, ## args)
-#define CPRINTS_L2(format, args...) CPRINTS_LX(2, format, ## args)
-#define CPRINTS_L3(format, args...) CPRINTS_LX(3, format, ## args)
-
-#define PE_SET_FN(port, _fn) atomic_or(ATOMIC_ELEM(pe[port].flags_a, (_fn)), \
- ATOMIC_MASK(_fn))
-#define PE_CLR_FN(port, _fn) atomic_clear_bits(ATOMIC_ELEM(pe[port].flags_a, \
- (_fn)), ATOMIC_MASK(_fn))
-#define PE_CHK_FN(port, _fn) (pe[port].flags_a[ATOMIC_ELEM(0, (_fn))] & \
- ATOMIC_MASK(_fn))
-
-#define PE_SET_FLAG(port, name) PE_SET_FN(port, (name ## _FN))
-#define PE_CLR_FLAG(port, name) PE_CLR_FN(port, (name ## _FN))
-#define PE_CHK_FLAG(port, name) PE_CHK_FN(port, (name ## _FN))
+#define CPRINTS_L1(format, args...) CPRINTS_LX(1, format, ##args)
+#define CPRINTS_L2(format, args...) CPRINTS_LX(2, format, ##args)
+#define CPRINTS_L3(format, args...) CPRINTS_LX(3, format, ##args)
+
+#define PE_SET_FN(port, _fn) \
+ atomic_or(ATOMIC_ELEM(pe[port].flags_a, (_fn)), ATOMIC_MASK(_fn))
+#define PE_CLR_FN(port, _fn) \
+ atomic_clear_bits(ATOMIC_ELEM(pe[port].flags_a, (_fn)), \
+ ATOMIC_MASK(_fn))
+#define PE_CHK_FN(port, _fn) \
+ (pe[port].flags_a[ATOMIC_ELEM(0, (_fn))] & ATOMIC_MASK(_fn))
+
+#define PE_SET_FLAG(port, name) PE_SET_FN(port, (name##_FN))
+#define PE_CLR_FLAG(port, name) PE_CLR_FN(port, (name##_FN))
+#define PE_CHK_FLAG(port, name) PE_CHK_FN(port, (name##_FN))
/*
* TODO(b/229655319): support more than 32 bits
@@ -99,10 +102,11 @@
#define PE_CHK_DPM_REQUEST(port, req) (pe[port].dpm_request & (req))
/* Message flags which should not persist on returning to ready state */
-#define PE_MASK_READY_CLR (BIT(PE_FLAGS_LOCALLY_INITIATED_AMS_FN) | \
- BIT(PE_FLAGS_MSG_DISCARDED_FN) | \
- BIT(PE_FLAGS_VDM_REQUEST_TIMEOUT_FN) | \
- BIT(PE_FLAGS_INTERRUPTIBLE_AMS_FN))
+#define PE_MASK_READY_CLR \
+ (BIT(PE_FLAGS_LOCALLY_INITIATED_AMS_FN) | \
+ BIT(PE_FLAGS_MSG_DISCARDED_FN) | \
+ BIT(PE_FLAGS_VDM_REQUEST_TIMEOUT_FN) | \
+ BIT(PE_FLAGS_INTERRUPTIBLE_AMS_FN))
/*
* Combination to check whether a reply to a message was received. Our message
@@ -113,8 +117,9 @@
* on the same run cycle. With chunking, received message will take an
* additional cycle to be flagged.
*/
-#define PE_CHK_REPLY(port) (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED) && \
- !PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED))
+#define PE_CHK_REPLY(port) \
+ (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED) && \
+ !PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED))
/* 6.7.3 Hard Reset Counter */
#define N_HARD_RESET_COUNT 2
@@ -136,20 +141,20 @@
* solely from VCONN. Limit the number of retries without a contract to
* ensure we attempt some cable discovery after a contract is in place.
*/
-#define N_DISCOVER_IDENTITY_PRECONTRACT_LIMIT 2
+#define N_DISCOVER_IDENTITY_PRECONTRACT_LIMIT 2
/*
* Once this limit of SOP' Discover Identity messages has been set, downgrade
* to PD 2.0 in case the cable is non-compliant about GoodCRC-ing higher
* revisions. This limit should be higher than the precontract limit.
*/
-#define N_DISCOVER_IDENTITY_PD3_0_LIMIT 4
+#define N_DISCOVER_IDENTITY_PD3_0_LIMIT 4
/*
* tDiscoverIdentity is only defined while an explicit contract is in place, so
* extend the interval between retries pre-contract.
*/
-#define PE_T_DISCOVER_IDENTITY_NO_CONTRACT (200*MSEC)
+#define PE_T_DISCOVER_IDENTITY_NO_CONTRACT (200 * MSEC)
/*
* Only VCONN source can communicate with the cable plug. Hence, try VCONN swap
@@ -278,6 +283,7 @@ enum usb_pe_state {
PE_GIVE_BATTERY_STATUS,
PE_GIVE_STATUS,
PE_SEND_ALERT,
+ PE_ALERT_RECEIVED,
PE_SRC_CHUNK_RECEIVED,
PE_SNK_CHUNK_RECEIVED,
PE_VCS_FORCE_VCONN,
@@ -316,15 +322,14 @@ static const struct usb_state pe_states[];
* If we can't print or the CONFIG_USB_PD_DEBUG_LEVEL is defined to be 0
* then the DEBUG LABELS will be removed from the build.
*/
-#if defined(CONFIG_COMMON_RUNTIME) && \
- (!defined(CONFIG_USB_PD_DEBUG_LEVEL) || \
- (CONFIG_USB_PD_DEBUG_LEVEL > 0))
+#if defined(CONFIG_COMMON_RUNTIME) && (!defined(CONFIG_USB_PD_DEBUG_LEVEL) || \
+ (CONFIG_USB_PD_DEBUG_LEVEL > 0))
#define USB_PD_DEBUG_LABELS
#endif
/* List of human readable state names for console debugging */
-__maybe_unused static __const_data const char * const pe_state_names[] = {
- /* Super States */
+__maybe_unused static __const_data const char *const pe_state_names[] = {
+/* Super States */
#ifdef CONFIG_USB_PD_REV30
[PE_PRS_FRS_SHARED] = "SS:PE_PRS_FRS_SHARED",
#endif
@@ -381,7 +386,7 @@ __maybe_unused static __const_data const char * const pe_state_names[] = {
#endif
[PE_VDM_IDENTITY_REQUEST_CBL] = "PE_VDM_Identity_Request_Cbl",
[PE_INIT_PORT_VDM_IDENTITY_REQUEST] =
- "PE_INIT_PORT_VDM_Identity_Request",
+ "PE_INIT_PORT_VDM_Identity_Request",
[PE_INIT_VDM_SVIDS_REQUEST] = "PE_INIT_VDM_SVIDs_Request",
[PE_INIT_VDM_MODES_REQUEST] = "PE_INIT_VDM_Modes_Request",
[PE_VDM_REQUEST_DPM] = "PE_VDM_Request_DPM",
@@ -389,12 +394,12 @@ __maybe_unused static __const_data const char * const pe_state_names[] = {
[PE_HANDLE_CUSTOM_VDM_REQUEST] = "PE_Handle_Custom_Vdm_Request",
[PE_WAIT_FOR_ERROR_RECOVERY] = "PE_Wait_For_Error_Recovery",
[PE_BIST_TX] = "PE_Bist_TX",
- [PE_DEU_SEND_ENTER_USB] = "PE_DEU_Send_Enter_USB",
+ [PE_DEU_SEND_ENTER_USB] = "PE_DEU_Send_Enter_USB",
[PE_DR_GET_SINK_CAP] = "PE_DR_Get_Sink_Cap",
[PE_DR_SNK_GIVE_SOURCE_CAP] = "PE_DR_SNK_Give_Source_Cap",
[PE_DR_SRC_GET_SOURCE_CAP] = "PE_DR_SRC_Get_Source_Cap",
- /* PD3.0 only states below here*/
+/* PD3.0 only states below here*/
#ifdef CONFIG_USB_PD_REV30
[PE_FRS_SNK_SRC_START_AMS] = "PE_FRS_SNK_SRC_Start_Ams",
[PE_GET_REVISION] = "PE_Get_Revision",
@@ -403,6 +408,7 @@ __maybe_unused static __const_data const char * const pe_state_names[] = {
[PE_GIVE_BATTERY_STATUS] = "PE_Give_Battery_Status",
[PE_GIVE_STATUS] = "PE_Give_Status",
[PE_SEND_ALERT] = "PE_Send_Alert",
+ [PE_ALERT_RECEIVED] = "PE_Alert_Received",
#else
[PE_SRC_CHUNK_RECEIVED] = "PE_SRC_Chunk_Received",
[PE_SNK_CHUNK_RECEIVED] = "PE_SNK_Chunk_Received",
@@ -416,7 +422,7 @@ __maybe_unused static __const_data const char * const pe_state_names[] = {
[PE_UDR_TURN_OFF_VCONN] = "PE_UDR_Turn_Off_VCONN",
[PE_UDR_SEND_PS_RDY] = "PE_UDR_Send_Ps_Rdy",
[PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE] =
- "PE_UDR_Wait_For_Data_Reset_Complete",
+ "PE_UDR_Wait_For_Data_Reset_Complete",
[PE_DDR_SEND_DATA_RESET] = "PE_DDR_Send_Data_Reset",
[PE_DDR_DATA_RESET_RECEIVED] = "PE_DDR_Data_Reset_Received",
[PE_DDR_WAIT_FOR_VCONN_OFF] = "PE_DDR_Wait_For_VCONN_Off",
@@ -451,6 +457,8 @@ GEN_NOT_SUPPORTED(PE_SNK_CHUNK_RECEIVED);
#define PE_SNK_CHUNK_RECEIVED PE_SNK_CHUNK_RECEIVED_NOT_SUPPORTED
GEN_NOT_SUPPORTED(PE_GET_REVISION);
#define PE_GET_REVISION PE_GET_REVISION_NOT_SUPPORTED
+GEN_NOT_SUPPORTED(PE_ALERT_RECEIVED);
+#define PE_ALERT_RECEIVED PE_ALERT_RECEIVED_NOT_SUPPORTED
#endif /* CONFIG_USB_PD_REV30 */
#if !defined(CONFIG_USBC_VCONN) || !defined(CONFIG_USB_PD_REV30)
@@ -529,12 +537,12 @@ static enum sm_local_state local_state[CONFIG_USB_PD_PORT_MAX_COUNT];
* what ever is needed to handle the Discard.
*/
enum pe_msg_check {
- PE_MSG_SEND_PENDING = BIT(0),
- PE_MSG_SENT = BIT(1),
- PE_MSG_DISCARDED = BIT(2),
+ PE_MSG_SEND_PENDING = BIT(0),
+ PE_MSG_SENT = BIT(1),
+ PE_MSG_DISCARDED = BIT(2),
- PE_MSG_SEND_COMPLETED = BIT(3) | PE_MSG_SENT,
- PE_MSG_DPM_DISCARDED = BIT(4) | PE_MSG_DISCARDED,
+ PE_MSG_SEND_COMPLETED = BIT(3) | PE_MSG_SENT,
+ PE_MSG_DPM_DISCARDED = BIT(4) | PE_MSG_DISCARDED,
};
static void pe_sender_response_msg_entry(const int port);
static enum pe_msg_check pe_sender_response_msg_run(const int port);
@@ -543,6 +551,8 @@ static void pe_sender_response_msg_exit(const int port);
/* Debug log level - higher number == more log */
#ifdef CONFIG_USB_PD_DEBUG_LEVEL
static const enum debug_level pe_debug_level = CONFIG_USB_PD_DEBUG_LEVEL;
+#elif defined(CONFIG_USB_PD_INITIAL_DEBUG_LEVEL)
+static enum debug_level pe_debug_level = CONFIG_USB_PD_INITIAL_DEBUG_LEVEL;
#else
static enum debug_level pe_debug_level = DEBUG_LEVEL_1;
#endif
@@ -654,7 +664,7 @@ static struct policy_engine {
/* Attached ChromeOS device id, RW hash, and current RO / RW image */
uint16_t dev_id;
- uint32_t dev_rw_hash[PD_RW_HASH_SIZE/4];
+ uint32_t dev_rw_hash[PD_RW_HASH_SIZE / 4];
enum ec_image current_image;
} pe[CONFIG_USB_PD_PORT_MAX_COUNT];
@@ -713,8 +723,8 @@ static inline void send_data_msg(int port, enum tcpci_msg_type type,
prl_send_data_msg(port, type, msg);
}
-static __maybe_unused inline void send_ext_data_msg(
- int port, enum tcpci_msg_type type, enum pd_ext_msg_type msg)
+static __maybe_unused inline void
+send_ext_data_msg(int port, enum tcpci_msg_type type, enum pd_ext_msg_type msg)
{
/* Clear any previous TX status before sending a new message */
PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE);
@@ -744,15 +754,15 @@ static void init_cable_rev(int port)
* also be PD 2.0
*/
if (prl_get_rev(port, TCPCI_MSG_SOP) == PD_REV20) {
- /*
- * If the cable supports PD 3.0, but the port partner supports PD 2.0,
- * redo the cable discover with PD 2.0
- */
+ /*
+ * If the cable supports PD 3.0, but the port partner supports
+ * PD 2.0, redo the cable discover with PD 2.0
+ */
if (prl_get_rev(port, TCPCI_MSG_SOP_PRIME) == PD_REV30 &&
pd_get_identity_discovery(port, TCPCI_MSG_SOP_PRIME) ==
- PD_DISC_COMPLETE) {
+ PD_DISC_COMPLETE) {
pd_set_identity_discovery(port, TCPCI_MSG_SOP_PRIME,
- PD_DISC_NEEDED);
+ PD_DISC_NEEDED);
}
set_cable_rev(port, PD_REV20);
}
@@ -850,8 +860,8 @@ void pe_run(int port, int evt, int en)
DPM_REQUEST_HARD_RESET_SEND);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
} else {
- pe_set_dpm_curr_request(port,
- DPM_REQUEST_HARD_RESET_SEND);
+ pe_set_dpm_curr_request(
+ port, DPM_REQUEST_HARD_RESET_SEND);
pe_set_hard_reset(port);
}
}
@@ -864,7 +874,7 @@ void pe_run(int port, int evt, int en)
* make sure to handle it immediately.
*/
if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- PE_CHK_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_SIGNALED)) {
+ PE_CHK_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_SIGNALED)) {
PE_CLR_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_SIGNALED);
set_state_pe(port, PE_FRS_SNK_SRC_START_AMS);
}
@@ -968,13 +978,13 @@ static void pe_set_frs_enable(int port, int enable)
pd_set_frs_enable(port, enable);
if (enable) {
- int curr_limit = *pd_get_snk_caps(port)
- & PDO_FIXED_FRS_CURR_MASK;
+ int curr_limit = *pd_get_snk_caps(port) &
+ PDO_FIXED_FRS_CURR_MASK;
- typec_select_src_current_limit_rp(port,
- curr_limit ==
- PDO_FIXED_FRS_CURR_3A0_AT_5V ?
- TYPEC_RP_3A0 : TYPEC_RP_1A5);
+ typec_select_src_current_limit_rp(
+ port, curr_limit == PDO_FIXED_FRS_CURR_3A0_AT_5V ?
+ TYPEC_RP_3A0 :
+ TYPEC_RP_1A5);
PE_SET_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
} else {
PE_CLR_FLAG(port, PE_FLAGS_FAST_ROLE_SWAP_ENABLED);
@@ -1026,7 +1036,7 @@ void pe_set_snk_caps(int port, int cnt, uint32_t *snk_caps)
memcpy(pe[port].snk_caps, snk_caps, sizeof(uint32_t) * cnt);
}
-const uint32_t * const pd_get_snk_caps(int port)
+const uint32_t *const pd_get_snk_caps(int port)
{
return pe[port].snk_caps;
}
@@ -1066,12 +1076,12 @@ static bool pe_can_send_sop_prime(int port)
if (PE_CHK_FLAG(port, PE_FLAGS_EXPLICIT_CONTRACT)) {
if (prl_get_rev(port, TCPCI_MSG_SOP) == PD_REV20)
return tc_is_vconn_src(port) &&
- pe[port].data_role == PD_ROLE_DFP;
+ pe[port].data_role == PD_ROLE_DFP;
else
return tc_is_vconn_src(port);
} else {
return tc_is_vconn_src(port) &&
- pe[port].power_role == PD_ROLE_SOURCE;
+ pe[port].power_role == PD_ROLE_SOURCE;
}
} else {
return false;
@@ -1146,9 +1156,9 @@ static bool pe_check_outgoing_discard(int port)
* Version 2.0 Specification.
*/
if (PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED) &&
- PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
enum tcpci_msg_type sop =
- PD_HEADER_GET_SOP(rx_emsg[port].header);
+ PD_HEADER_GET_SOP(rx_emsg[port].header);
PE_CLR_FLAG(port, PE_FLAGS_MSG_DISCARDED);
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
@@ -1190,28 +1200,26 @@ void pe_report_error(int port, enum pe_error e, enum tcpci_msg_type type)
* TODO(b/150774779): TCPMv2: Improve pe_error documentation
*/
if ((get_state_pe(port) == PE_SRC_SEND_CAPABILITIES ||
- get_state_pe(port) == PE_SRC_TRANSITION_SUPPLY ||
- get_state_pe(port) == PE_PRS_SNK_SRC_EVALUATE_SWAP ||
- get_state_pe(port) == PE_PRS_SNK_SRC_SOURCE_ON ||
- get_state_pe(port) == PE_PRS_SRC_SNK_WAIT_SOURCE_ON ||
- get_state_pe(port) == PE_SRC_DISABLED ||
- get_state_pe(port) == PE_SRC_DISCOVERY ||
- get_state_pe(port) == PE_VCS_CBL_SEND_SOFT_RESET ||
- get_state_pe(port) == PE_VDM_IDENTITY_REQUEST_CBL) ||
- (IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
- (get_state_pe(port) == PE_UDR_SEND_DATA_RESET ||
- get_state_pe(port) == PE_UDR_DATA_RESET_RECEIVED ||
- get_state_pe(port) == PE_UDR_TURN_OFF_VCONN ||
- get_state_pe(port) == PE_UDR_SEND_PS_RDY ||
- get_state_pe(port) ==
- PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE ||
- get_state_pe(port) == PE_DDR_SEND_DATA_RESET ||
- get_state_pe(port) == PE_DDR_DATA_RESET_RECEIVED ||
- get_state_pe(port) == PE_DDR_WAIT_FOR_VCONN_OFF ||
- get_state_pe(port) == PE_DDR_PERFORM_DATA_RESET)) ||
- (pe_in_frs_mode(port) &&
- get_state_pe(port) == PE_PRS_SNK_SRC_SEND_SWAP)
- ) {
+ get_state_pe(port) == PE_SRC_TRANSITION_SUPPLY ||
+ get_state_pe(port) == PE_PRS_SNK_SRC_EVALUATE_SWAP ||
+ get_state_pe(port) == PE_PRS_SNK_SRC_SOURCE_ON ||
+ get_state_pe(port) == PE_PRS_SRC_SNK_WAIT_SOURCE_ON ||
+ get_state_pe(port) == PE_SRC_DISABLED ||
+ get_state_pe(port) == PE_SRC_DISCOVERY ||
+ get_state_pe(port) == PE_VCS_CBL_SEND_SOFT_RESET ||
+ get_state_pe(port) == PE_VDM_IDENTITY_REQUEST_CBL) ||
+ (IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
+ (get_state_pe(port) == PE_UDR_SEND_DATA_RESET ||
+ get_state_pe(port) == PE_UDR_DATA_RESET_RECEIVED ||
+ get_state_pe(port) == PE_UDR_TURN_OFF_VCONN ||
+ get_state_pe(port) == PE_UDR_SEND_PS_RDY ||
+ get_state_pe(port) == PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE ||
+ get_state_pe(port) == PE_DDR_SEND_DATA_RESET ||
+ get_state_pe(port) == PE_DDR_DATA_RESET_RECEIVED ||
+ get_state_pe(port) == PE_DDR_WAIT_FOR_VCONN_OFF ||
+ get_state_pe(port) == PE_DDR_PERFORM_DATA_RESET)) ||
+ (pe_in_frs_mode(port) &&
+ get_state_pe(port) == PE_PRS_SNK_SRC_SEND_SWAP)) {
PE_SET_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
task_wake(PD_PORT_TO_TASK_ID(port));
return;
@@ -1234,10 +1242,10 @@ void pe_report_error(int port, enum pe_error e, enum tcpci_msg_type type)
*/
/* All error types besides transmit errors are Protocol Errors. */
if ((e != ERR_TCH_XMIT &&
- !PE_CHK_FLAG(port, PE_FLAGS_INTERRUPTIBLE_AMS))
- || e == ERR_TCH_XMIT
- || (!PE_CHK_FLAG(port, PE_FLAGS_EXPLICIT_CONTRACT) &&
- type == TCPCI_MSG_SOP)) {
+ !PE_CHK_FLAG(port, PE_FLAGS_INTERRUPTIBLE_AMS)) ||
+ e == ERR_TCH_XMIT ||
+ (!PE_CHK_FLAG(port, PE_FLAGS_EXPLICIT_CONTRACT) &&
+ type == TCPCI_MSG_SOP)) {
pe_send_soft_reset(port, type);
}
/*
@@ -1262,7 +1270,7 @@ void pe_got_soft_reset(int port)
}
__overridable bool pd_can_charge_from_device(int port, const int pdo_cnt,
- const uint32_t *pdos)
+ const uint32_t *pdos)
{
/*
* Don't attempt to charge from a device we have no SrcCaps from. Or, if
@@ -1292,9 +1300,7 @@ __overridable bool pd_can_charge_from_device(int port, const int pdo_cnt,
* Get max power that the partner offers (not necessarily what
* this board will request)
*/
- pd_find_pdo_index(pdo_cnt, pdos,
- PD_REV3_MAX_VOLTAGE,
- &max_pdo);
+ pd_find_pdo_index(pdo_cnt, pdos, PD_REV3_MAX_VOLTAGE, &max_pdo);
pd_extract_pdo_power(max_pdo, &max_ma, &max_mv, &unused);
max_mw = max_ma * max_mv / 1000;
@@ -1351,14 +1357,15 @@ void pe_message_sent(int port)
}
void pd_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data,
- int count)
+ int count)
{
/* Copy VDM Header */
pe[port].vdm_data[0] =
- VDO(vid, ((vid & USB_SID_PD) == USB_SID_PD) ? 1 :
- (PD_VDO_CMD(cmd) <= CMD_ATTENTION),
- VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP)) |
- cmd);
+ VDO(vid,
+ ((vid & USB_SID_PD) == USB_SID_PD) ?
+ 1 :
+ (PD_VDO_CMD(cmd) <= CMD_ATTENTION),
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP)) | cmd);
/*
* Copy VDOs after the VDM Header. Note that the count refers to VDO
@@ -1485,21 +1492,21 @@ static void pe_update_waiting_batt_flag(void)
* flag and perform Hard Reset.
*/
PE_CLR_FLAG(i, PE_FLAGS_SNK_WAITING_BATT);
- CPRINTS("C%d: Battery has enough charge (%d%%) " \
- "to withstand a hard reset", i, batt_soc);
+ CPRINTS("C%d: Battery has enough charge (%d%%) "
+ "to withstand a hard reset",
+ i, batt_soc);
pd_dpm_request(i, DPM_REQUEST_HARD_RESET_SEND);
}
}
}
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, pe_update_waiting_batt_flag,
- HOOK_PRIO_DEFAULT);
+ HOOK_PRIO_DEFAULT);
#endif
/*
* Private functions
*/
-static void pe_set_dpm_curr_request(const int port,
- const int request)
+static void pe_set_dpm_curr_request(const int port, const int request)
{
PE_CLR_DPM_REQUEST(port, request);
pe[port].dpm_curr_request = request;
@@ -1527,33 +1534,24 @@ test_export_static enum usb_pe_state get_state_pe(const int port)
*/
static bool common_src_snk_dpm_requests(int port)
{
- if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES) &&
- PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SEND_ALERT)) {
- pe_set_dpm_curr_request(port, DPM_REQUEST_SEND_ALERT);
- set_state_pe(port, PE_SEND_ALERT);
- return true;
- } else if (IS_ENABLED(CONFIG_USBC_VCONN) &&
- PE_CHK_DPM_REQUEST(port, DPM_REQUEST_VCONN_SWAP)) {
+ if (IS_ENABLED(CONFIG_USBC_VCONN) &&
+ PE_CHK_DPM_REQUEST(port, DPM_REQUEST_VCONN_SWAP)) {
pe_set_dpm_curr_request(port, DPM_REQUEST_VCONN_SWAP);
set_state_pe(port, PE_VCS_SEND_SWAP);
return true;
- } else if (PE_CHK_DPM_REQUEST(port,
- DPM_REQUEST_BIST_TX)) {
+ } else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_BIST_TX)) {
pe_set_dpm_curr_request(port, DPM_REQUEST_BIST_TX);
set_state_pe(port, PE_BIST_TX);
return true;
- } else if (PE_CHK_DPM_REQUEST(port,
- DPM_REQUEST_SNK_STARTUP)) {
+ } else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SNK_STARTUP)) {
pe_set_dpm_curr_request(port, DPM_REQUEST_SNK_STARTUP);
set_state_pe(port, PE_SNK_STARTUP);
return true;
- } else if (PE_CHK_DPM_REQUEST(port,
- DPM_REQUEST_SRC_STARTUP)) {
+ } else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SRC_STARTUP)) {
pe_set_dpm_curr_request(port, DPM_REQUEST_SRC_STARTUP);
set_state_pe(port, PE_SRC_STARTUP);
return true;
- } else if (PE_CHK_DPM_REQUEST(port,
- DPM_REQUEST_SOFT_RESET_SEND)) {
+ } else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SOFT_RESET_SEND)) {
pe_set_dpm_curr_request(port, DPM_REQUEST_SOFT_RESET_SEND);
/* Currently only support sending soft reset to SOP */
pe_send_soft_reset(port, TCPCI_MSG_SOP);
@@ -1593,14 +1591,13 @@ static bool common_src_snk_dpm_requests(int port)
dpm_set_mode_exit_request(port);
return true;
} else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_GET_SNK_CAPS)) {
- pe_set_dpm_curr_request(port,
- DPM_REQUEST_GET_SNK_CAPS);
+ pe_set_dpm_curr_request(port, DPM_REQUEST_GET_SNK_CAPS);
set_state_pe(port, PE_DR_GET_SINK_CAP);
return true;
} else if (PE_CHK_DPM_REQUEST(port,
DPM_REQUEST_SOP_PRIME_SOFT_RESET_SEND)) {
pe_set_dpm_curr_request(port,
- DPM_REQUEST_SOP_PRIME_SOFT_RESET_SEND);
+ DPM_REQUEST_SOP_PRIME_SOFT_RESET_SEND);
pe[port].tx_type = TCPCI_MSG_SOP_PRIME;
set_state_pe(port, PE_VCS_CBL_SEND_SOFT_RESET);
return true;
@@ -1617,8 +1614,9 @@ static bool common_src_snk_dpm_requests(int port)
set_state_pe(port, PE_DRS_SEND_SWAP);
return true;
} else if (IS_ENABLED(CONFIG_USB_PD_DATA_RESET_MSG) &&
- PE_CHK_DPM_REQUEST(port, DPM_REQUEST_DATA_RESET)) {
+ PE_CHK_DPM_REQUEST(port, DPM_REQUEST_DATA_RESET)) {
if (prl_get_rev(port, TCPCI_MSG_SOP) < PD_REV30) {
+ PE_CLR_DPM_REQUEST(port, DPM_REQUEST_DATA_RESET);
dpm_data_reset_complete(port);
return false;
}
@@ -1631,9 +1629,22 @@ static bool common_src_snk_dpm_requests(int port)
return true;
} else if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
PE_CHK_DPM_REQUEST(port, DPM_REQUEST_GET_REVISION)) {
+ if (prl_get_rev(port, TCPCI_MSG_SOP) < PD_REV30) {
+ PE_CLR_DPM_REQUEST(port, DPM_REQUEST_GET_REVISION);
+ return false;
+ }
pe_set_dpm_curr_request(port, DPM_REQUEST_GET_REVISION);
set_state_pe(port, PE_GET_REVISION);
return true;
+ } else if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES) &&
+ PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SEND_ALERT)) {
+ if (prl_get_rev(port, TCPCI_MSG_SOP) < PD_REV30) {
+ PE_CLR_DPM_REQUEST(port, DPM_REQUEST_SEND_ALERT);
+ return false;
+ }
+ pe_set_dpm_curr_request(port, DPM_REQUEST_SEND_ALERT);
+ set_state_pe(port, PE_SEND_ALERT);
+ return true;
}
return false;
@@ -1654,9 +1665,9 @@ static bool source_dpm_requests(int port)
* DPM_REQURST_FRS_DET_DISABLE
*/
PE_CLR_DPM_REQUEST(port, DPM_REQUEST_NEW_POWER_LEVEL |
- DPM_REQUEST_SOURCE_CAP |
- DPM_REQUEST_FRS_DET_ENABLE |
- DPM_REQUEST_FRS_DET_DISABLE);
+ DPM_REQUEST_SOURCE_CAP |
+ DPM_REQUEST_FRS_DET_ENABLE |
+ DPM_REQUEST_FRS_DET_DISABLE);
if (pe[port].dpm_request) {
uint32_t dpm_request = pe[port].dpm_request;
@@ -1668,8 +1679,7 @@ static bool source_dpm_requests(int port)
set_state_pe(port, PE_PRS_SRC_SNK_SEND_SWAP);
return true;
} else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_GOTO_MIN)) {
- pe_set_dpm_curr_request(port,
- DPM_REQUEST_GOTO_MIN);
+ pe_set_dpm_curr_request(port, DPM_REQUEST_GOTO_MIN);
set_state_pe(port, PE_SRC_TRANSITION_SUPPLY);
return true;
} else if (PE_CHK_DPM_REQUEST(port,
@@ -1679,21 +1689,18 @@ static bool source_dpm_requests(int port)
set_state_pe(port, PE_SRC_SEND_CAPABILITIES);
return true;
} else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_GET_SRC_CAPS)) {
- pe_set_dpm_curr_request(port,
- DPM_REQUEST_GET_SRC_CAPS);
+ pe_set_dpm_curr_request(port, DPM_REQUEST_GET_SRC_CAPS);
set_state_pe(port, PE_DR_SRC_GET_SOURCE_CAP);
return true;
} else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SEND_PING)) {
- pe_set_dpm_curr_request(port,
- DPM_REQUEST_SEND_PING);
+ pe_set_dpm_curr_request(port, DPM_REQUEST_SEND_PING);
set_state_pe(port, PE_SRC_PING);
return true;
} else if (common_src_snk_dpm_requests(port)) {
return true;
}
- CPRINTF("Unhandled DPM Request %x received\n",
- dpm_request);
+ CPRINTF("Unhandled DPM Request %x received\n", dpm_request);
PE_CLR_DPM_REQUEST(port, dpm_request);
PE_CLR_FLAG(port, PE_FLAGS_LOCALLY_INITIATED_AMS);
}
@@ -1714,8 +1721,8 @@ static bool sink_dpm_requests(int port)
* DPM_REQUEST_SEND_PING
*/
PE_CLR_DPM_REQUEST(port, DPM_REQUEST_GOTO_MIN |
- DPM_REQUEST_SRC_CAP_CHANGE |
- DPM_REQUEST_SEND_PING);
+ DPM_REQUEST_SRC_CAP_CHANGE |
+ DPM_REQUEST_SEND_PING);
if (pe[port].dpm_request) {
uint32_t dpm_request = pe[port].dpm_request;
@@ -1727,8 +1734,7 @@ static bool sink_dpm_requests(int port)
set_state_pe(port, PE_PRS_SNK_SRC_SEND_SWAP);
return true;
} else if (PE_CHK_DPM_REQUEST(port, DPM_REQUEST_SOURCE_CAP)) {
- pe_set_dpm_curr_request(port,
- DPM_REQUEST_SOURCE_CAP);
+ pe_set_dpm_curr_request(port, DPM_REQUEST_SOURCE_CAP);
set_state_pe(port, PE_SNK_GET_SOURCE_CAP);
return true;
} else if (PE_CHK_DPM_REQUEST(port,
@@ -1775,13 +1781,12 @@ static void print_current_state(const int port)
{
const char *mode = "";
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- pe_in_frs_mode(port))
+ if (IS_ENABLED(CONFIG_USB_PD_REV30) && pe_in_frs_mode(port))
mode = " FRS-MODE";
if (IS_ENABLED(USB_PD_DEBUG_LABELS))
CPRINTS_L1("C%d: %s%s", port,
- pe_state_names[get_state_pe(port)], mode);
+ pe_state_names[get_state_pe(port)], mode);
else
CPRINTS("C%d: pe-st%d", port, get_state_pe(port));
}
@@ -1817,20 +1822,20 @@ static void pe_send_request_msg(int port)
* might need adjusting.
*/
if ((get_usb_pd_cable_type(port) == IDH_PTYPE_VPD) &&
- is_vpd_ct_supported(port)) {
- union vpd_vdo vpd = pd_get_am_discovery(port,
- TCPCI_MSG_SOP_PRIME)->identity.product_t1.vpd;
+ is_vpd_ct_supported(port)) {
+ union vpd_vdo vpd =
+ pd_get_am_discovery(port, TCPCI_MSG_SOP_PRIME)
+ ->identity.product_t1.vpd;
/* The raw vpd_vdo is passed to pd_build_request */
vpd_vdo = vpd.raw_value;
}
/* Build and send request RDO */
- pd_build_request(vpd_vdo, &rdo, &curr_limit,
- &supply_voltage, port);
+ pd_build_request(vpd_vdo, &rdo, &curr_limit, &supply_voltage, port);
- CPRINTF("C%d: Req [%d] %dmV %dmA", port, RDO_POS(rdo),
- supply_voltage, curr_limit);
+ CPRINTF("C%d: Req [%d] %dmV %dmA", port, RDO_POS(rdo), supply_voltage,
+ curr_limit);
if (rdo & RDO_CAP_MISMATCH)
CPRINTF(" Mismatch");
CPRINTF("\n");
@@ -1931,18 +1936,35 @@ __maybe_unused static bool pe_attempt_port_discovery(int port)
return false;
/* Apply Port Discovery DR Swap Policy */
- if (port_discovery_dr_swap_policy(port, pe[port].data_role,
- PE_CHK_FLAG(port, PE_FLAGS_DR_SWAP_TO_DFP))) {
+ if (port_discovery_dr_swap_policy(
+ port, pe[port].data_role,
+ PE_CHK_FLAG(port, PE_FLAGS_DR_SWAP_TO_DFP))) {
PE_SET_FLAG(port, PE_FLAGS_LOCALLY_INITIATED_AMS);
PE_CLR_FLAG(port, PE_FLAGS_DR_SWAP_TO_DFP);
set_state_pe(port, PE_DRS_SEND_SWAP);
return true;
}
+ /*
+ * An edge case of DR Swap fail (port still UFP) and partner in PD 2.0.
+ * PD 2.0 allows only DFP to initiate Discover Identity, but partner may
+ * reject a DR Swap.
+ */
+ if (pe[port].data_role == PD_ROLE_UFP &&
+ prl_get_rev(port, TCPCI_MSG_SOP) == PD_REV20) {
+ pd_set_identity_discovery(port, TCPCI_MSG_SOP, PD_DISC_FAIL);
+ pd_set_identity_discovery(port, TCPCI_MSG_SOP_PRIME,
+ PD_DISC_FAIL);
+ pd_notify_event(port, PD_STATUS_EVENT_SOP_DISC_DONE);
+ pd_notify_event(port, PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
+ PE_SET_FLAG(port, PE_FLAGS_VDM_SETUP_DONE);
+ return false;
+ }
+
/* Apply Port Discovery VCONN Swap Policy */
if (IS_ENABLED(CONFIG_USBC_VCONN) &&
- port_discovery_vconn_swap_policy(port,
- PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_TO_ON))) {
+ port_discovery_vconn_swap_policy(
+ port, PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_TO_ON))) {
PE_SET_FLAG(port, PE_FLAGS_LOCALLY_INITIATED_AMS);
PE_CLR_FLAG(port, PE_FLAGS_VCONN_SWAP_TO_ON);
set_state_pe(port, PE_VCS_SEND_SWAP);
@@ -1961,36 +1983,35 @@ __maybe_unused static bool pe_attempt_port_discovery(int port)
*/
if (pd_timer_is_expired(port, PE_TIMER_DISCOVER_IDENTITY)) {
if (pd_get_identity_discovery(port, TCPCI_MSG_SOP_PRIME) ==
- PD_DISC_NEEDED) {
+ PD_DISC_NEEDED) {
pe[port].tx_type = TCPCI_MSG_SOP_PRIME;
set_state_pe(port, PE_VDM_IDENTITY_REQUEST_CBL);
return true;
} else if (pd_get_identity_discovery(port, TCPCI_MSG_SOP) ==
- PD_DISC_NEEDED &&
- pe_can_send_sop_vdm(port, CMD_DISCOVER_IDENT)) {
+ PD_DISC_NEEDED &&
+ pe_can_send_sop_vdm(port, CMD_DISCOVER_IDENT)) {
pe[port].tx_type = TCPCI_MSG_SOP;
- set_state_pe(port,
- PE_INIT_PORT_VDM_IDENTITY_REQUEST);
+ set_state_pe(port, PE_INIT_PORT_VDM_IDENTITY_REQUEST);
return true;
} else if (pd_get_svids_discovery(port, TCPCI_MSG_SOP) ==
- PD_DISC_NEEDED &&
- pe_can_send_sop_vdm(port, CMD_DISCOVER_SVID)) {
+ PD_DISC_NEEDED &&
+ pe_can_send_sop_vdm(port, CMD_DISCOVER_SVID)) {
pe[port].tx_type = TCPCI_MSG_SOP;
set_state_pe(port, PE_INIT_VDM_SVIDS_REQUEST);
return true;
} else if (pd_get_modes_discovery(port, TCPCI_MSG_SOP) ==
- PD_DISC_NEEDED &&
- pe_can_send_sop_vdm(port, CMD_DISCOVER_MODES)) {
+ PD_DISC_NEEDED &&
+ pe_can_send_sop_vdm(port, CMD_DISCOVER_MODES)) {
pe[port].tx_type = TCPCI_MSG_SOP;
set_state_pe(port, PE_INIT_VDM_MODES_REQUEST);
return true;
- } else if (pd_get_svids_discovery(port, TCPCI_MSG_SOP_PRIME)
- == PD_DISC_NEEDED) {
+ } else if (pd_get_svids_discovery(port, TCPCI_MSG_SOP_PRIME) ==
+ PD_DISC_NEEDED) {
pe[port].tx_type = TCPCI_MSG_SOP_PRIME;
set_state_pe(port, PE_INIT_VDM_SVIDS_REQUEST);
return true;
} else if (pd_get_modes_discovery(port, TCPCI_MSG_SOP_PRIME) ==
- PD_DISC_NEEDED) {
+ PD_DISC_NEEDED) {
pe[port].tx_type = TCPCI_MSG_SOP_PRIME;
set_state_pe(port, PE_INIT_VDM_MODES_REQUEST);
return true;
@@ -2000,8 +2021,8 @@ __maybe_unused static bool pe_attempt_port_discovery(int port)
return false;
}
-bool pd_setup_vdm_request(int port, enum tcpci_msg_type tx_type,
- uint32_t *vdm, uint32_t vdo_cnt)
+bool pd_setup_vdm_request(int port, enum tcpci_msg_type tx_type, uint32_t *vdm,
+ uint32_t vdo_cnt)
{
if (vdo_cnt < VDO_HDR_SIZE || vdo_cnt > VDO_MAX_SIZE)
return false;
@@ -2014,7 +2035,7 @@ bool pd_setup_vdm_request(int port, enum tcpci_msg_type tx_type,
}
int pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash,
- uint32_t current_image)
+ uint32_t current_image)
{
pe[port].dev_id = dev_id;
memcpy(pe[port].dev_rw_hash, rw_hash, PD_RW_HASH_SIZE);
@@ -2038,7 +2059,7 @@ int pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash,
}
void pd_dev_get_rw_hash(int port, uint16_t *dev_id, uint8_t *rw_hash,
- uint32_t *current_image)
+ uint32_t *current_image)
{
*dev_id = pe[port].dev_id;
*current_image = pe[port].current_image;
@@ -2079,7 +2100,7 @@ static void pe_update_wait_and_add_jitter_timer(int port)
pd_timer_is_disabled(port, PE_TIMER_WAIT_AND_ADD_JITTER)) {
pd_timer_enable(port, PE_TIMER_WAIT_AND_ADD_JITTER,
SRC_SNK_READY_HOLD_OFF_US +
- (get_time().le.lo & 0xf) * 23 * MSEC);
+ (get_time().le.lo & 0xf) * 23 * MSEC);
}
}
@@ -2263,8 +2284,7 @@ static void pe_src_startup_entry(int port)
/* Request partner sink caps if a feature requires them */
if (IS_ENABLED(CONFIG_USB_PD_HOST_CMD) ||
- CONFIG_USB_PD_3A_PORTS > 0 ||
- IS_ENABLED(CONFIG_USB_PD_FRS))
+ CONFIG_USB_PD_3A_PORTS > 0 || IS_ENABLED(CONFIG_USB_PD_FRS))
pd_dpm_request(port, DPM_REQUEST_GET_SNK_CAPS);
/*
@@ -2273,7 +2293,6 @@ static void pe_src_startup_entry(int port)
* revision 3.0
*/
pd_dpm_request(port, DPM_REQUEST_GET_REVISION);
-
}
}
@@ -2336,6 +2355,19 @@ static void pe_src_discovery_run(int port)
set_state_pe(port, PE_SRC_SEND_CAPABILITIES);
return;
} else if (!PE_CHK_FLAG(port, PE_FLAGS_PD_CONNECTION)) {
+ /*
+ * Cable identity may be discovered without a PD
+ * contract in place. If it has been discovered, notify
+ * the AP.
+ */
+ if (pd_get_identity_discovery(port,
+ TCPCI_MSG_SOP_PRIME) ==
+ PD_DISC_COMPLETE) {
+ pd_notify_event(
+ port,
+ PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
+ }
+
set_state_pe(port, PE_SRC_DISABLED);
return;
}
@@ -2347,11 +2379,11 @@ static void pe_src_discovery_run(int port)
* requests properly.
*/
if (pd_get_identity_discovery(port, TCPCI_MSG_SOP_PRIME) ==
- PD_DISC_NEEDED
- && pd_timer_is_expired(port, PE_TIMER_DISCOVER_IDENTITY)
- && pe_can_send_sop_prime(port)
- && (pe[port].discover_identity_counter <
- N_DISCOVER_IDENTITY_PRECONTRACT_LIMIT)) {
+ PD_DISC_NEEDED &&
+ pd_timer_is_expired(port, PE_TIMER_DISCOVER_IDENTITY) &&
+ pe_can_send_sop_prime(port) &&
+ (pe[port].discover_identity_counter <
+ N_DISCOVER_IDENTITY_PRECONTRACT_LIMIT)) {
pe[port].tx_type = TCPCI_MSG_SOP_PRIME;
set_state_pe(port, PE_VDM_IDENTITY_REQUEST_CBL);
return;
@@ -2441,15 +2473,14 @@ static void pe_src_send_capabilities_run(int port)
* Request Message Received?
*/
if (PD_HEADER_CNT(rx_emsg[port].header) > 0 &&
- PD_HEADER_TYPE(rx_emsg[port].header) ==
- PD_DATA_REQUEST) {
-
+ PD_HEADER_TYPE(rx_emsg[port].header) == PD_DATA_REQUEST) {
/*
* Set to highest revision supported by both
* ports.
*/
prl_set_rev(port, TCPCI_MSG_SOP,
- MIN(PD_REVISION, PD_HEADER_REV(rx_emsg[port].header)));
+ MIN(PD_REVISION,
+ PD_HEADER_REV(rx_emsg[port].header)));
init_cable_rev(port);
@@ -2620,7 +2651,7 @@ static void pe_src_transition_supply_run(int port)
if (!pe_is_explicit_contract(port)) {
PE_SET_FLAG(port, PE_FLAGS_FIRST_MSG);
pd_timer_disable(port,
- PE_TIMER_WAIT_AND_ADD_JITTER);
+ PE_TIMER_WAIT_AND_ADD_JITTER);
}
/* NOTE: Second pass through this code block */
@@ -2680,13 +2711,13 @@ static void extended_message_not_supported(int port, uint32_t *payload)
uint16_t ext_header = GET_EXT_HEADER(*payload);
if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- !IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES) &&
- PD_EXT_HEADER_CHUNKED(ext_header) &&
- PD_EXT_HEADER_DATA_SIZE(ext_header) >
- PD_MAX_EXTENDED_MSG_CHUNK_LEN) {
- set_state_pe(port,
- pe[port].power_role == PD_ROLE_SOURCE ?
- PE_SRC_CHUNK_RECEIVED : PE_SNK_CHUNK_RECEIVED);
+ !IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES) &&
+ PD_EXT_HEADER_CHUNKED(ext_header) &&
+ PD_EXT_HEADER_DATA_SIZE(ext_header) >
+ PD_MAX_EXTENDED_MSG_CHUNK_LEN) {
+ set_state_pe(port, pe[port].power_role == PD_ROLE_SOURCE ?
+ PE_SRC_CHUNK_RECEIVED :
+ PE_SNK_CHUNK_RECEIVED);
return;
}
@@ -2753,18 +2784,24 @@ static void pe_src_ready_run(int port)
break;
case PD_DATA_VENDOR_DEF:
if (PD_HEADER_TYPE(rx_emsg[port].header) ==
- PD_DATA_VENDOR_DEF) {
+ PD_DATA_VENDOR_DEF) {
if (PD_VDO_SVDM(*payload)) {
set_state_pe(port,
- PE_VDM_RESPONSE);
+ PE_VDM_RESPONSE);
} else
- set_state_pe(port,
- PE_HANDLE_CUSTOM_VDM_REQUEST);
+ set_state_pe(
+ port,
+ PE_HANDLE_CUSTOM_VDM_REQUEST);
}
return;
case PD_DATA_BIST:
set_state_pe(port, PE_BIST_TX);
return;
+#ifdef CONFIG_USB_PD_REV30
+ case PD_DATA_ALERT:
+ set_state_pe(port, PE_ALERT_RECEIVED);
+ return;
+#endif /* CONFIG_USB_PD_REV30 */
default:
set_state_pe(port, PE_SEND_NOT_SUPPORTED);
return;
@@ -2789,7 +2826,7 @@ static void pe_src_ready_run(int port)
break;
case PD_CTRL_PR_SWAP:
set_state_pe(port,
- PE_PRS_SRC_SNK_EVALUATE_SWAP);
+ PE_PRS_SRC_SNK_EVALUATE_SWAP);
return;
case PD_CTRL_DR_SWAP:
if (PE_CHK_FLAG(port,
@@ -2803,10 +2840,10 @@ static void pe_src_ready_run(int port)
case PD_CTRL_VCONN_SWAP:
if (IS_ENABLED(CONFIG_USBC_VCONN))
set_state_pe(port,
- PE_VCS_EVALUATE_SWAP);
+ PE_VCS_EVALUATE_SWAP);
else
set_state_pe(port,
- PE_SEND_NOT_SUPPORTED);
+ PE_SEND_NOT_SUPPORTED);
return;
/*
* USB PD 3.0 6.8.1:
@@ -2817,16 +2854,19 @@ static void pe_src_ready_run(int port)
case PD_CTRL_REJECT:
case PD_CTRL_WAIT:
case PD_CTRL_PS_RDY:
- pe_send_soft_reset(port,
- PD_HEADER_GET_SOP(rx_emsg[port].header));
+ pe_send_soft_reset(
+ port, PD_HEADER_GET_SOP(
+ rx_emsg[port].header));
return;
#ifdef CONFIG_USB_PD_DATA_RESET_MSG
case PD_CTRL_DATA_RESET:
if (pe[port].data_role == PD_ROLE_DFP)
- set_state_pe(port,
+ set_state_pe(
+ port,
PE_DDR_DATA_RESET_RECEIVED);
else
- set_state_pe(port,
+ set_state_pe(
+ port,
PE_UDR_DATA_RESET_RECEIVED);
return;
#endif /* CONFIG_USB_PD_DATA_RESET_MSG */
@@ -2835,10 +2875,11 @@ static void pe_src_ready_run(int port)
set_state_pe(port, PE_GIVE_STATUS);
return;
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
- /*
- * Receiving an unknown or unsupported message
- * shall be responded to with a not supported message.
- */
+ /*
+ * Receiving an unknown or unsupported message
+ * shall be responded to with a not supported
+ * message.
+ */
default:
set_state_pe(port, PE_SEND_NOT_SUPPORTED);
@@ -2868,7 +2909,6 @@ static void pe_src_ready_run(int port)
if (pd_timer_is_disabled(port, PE_TIMER_WAIT_AND_ADD_JITTER) ||
pd_timer_is_expired(port, PE_TIMER_WAIT_AND_ADD_JITTER)) {
-
PE_CLR_FLAG(port, PE_FLAGS_FIRST_MSG);
pd_timer_disable(port, PE_TIMER_WAIT_AND_ADD_JITTER);
@@ -2898,7 +2938,7 @@ static void pe_src_disabled_entry(int port)
print_current_state(port);
if ((get_usb_pd_cable_type(port) == IDH_PTYPE_VPD) &&
- is_vpd_ct_supported(port)) {
+ is_vpd_ct_supported(port)) {
/*
* Inform the Device Policy Manager that a Charge-Through VCONN
* Powered Device was detected.
@@ -2988,10 +3028,9 @@ static void pe_src_hard_reset_entry(int port)
pd_timer_enable(port, PE_TIMER_PS_HARD_RESET, PD_T_PS_HARD_RESET);
/* Clear error flags */
- PE_CLR_MASK(port,
- BIT(PE_FLAGS_VDM_REQUEST_NAKED_FN) |
- BIT(PE_FLAGS_PROTOCOL_ERROR_FN) |
- BIT(PE_FLAGS_VDM_REQUEST_BUSY_FN));
+ PE_CLR_MASK(port, BIT(PE_FLAGS_VDM_REQUEST_NAKED_FN) |
+ BIT(PE_FLAGS_PROTOCOL_ERROR_FN) |
+ BIT(PE_FLAGS_VDM_REQUEST_BUSY_FN));
}
static void pe_src_hard_reset_run(int port)
@@ -3158,9 +3197,8 @@ static void pe_snk_startup_entry(int port)
* Swap, then the Policy Engine Shall do the following:
* - Send a Get_Sink_Cap Message
*/
- if (IS_ENABLED(CONFIG_USB_PD_HOST_CMD) ||
- CONFIG_USB_PD_3A_PORTS > 0 ||
- IS_ENABLED(CONFIG_USB_PD_FRS))
+ if (IS_ENABLED(CONFIG_USB_PD_HOST_CMD) || CONFIG_USB_PD_3A_PORTS > 0 ||
+ IS_ENABLED(CONFIG_USB_PD_FRS))
pd_dpm_request(port, DPM_REQUEST_GET_SNK_CAPS);
/*
@@ -3169,7 +3207,6 @@ static void pe_snk_startup_entry(int port)
* revision 3.0
*/
pd_dpm_request(port, DPM_REQUEST_GET_REVISION);
-
}
static void pe_snk_startup_run(int port)
@@ -3264,7 +3301,7 @@ static void pe_snk_evaluate_capability_entry(int port)
/* Set to highest revision supported by both ports. */
prl_set_rev(port, TCPCI_MSG_SOP,
- MIN(PD_REVISION, PD_HEADER_REV(rx_emsg[port].header)));
+ MIN(PD_REVISION, PD_HEADER_REV(rx_emsg[port].header)));
init_cable_rev(port);
@@ -3385,7 +3422,7 @@ static void pe_snk_select_capability_run(int port)
* Reject or Wait Message Received
*/
else if (type == PD_CTRL_REJECT ||
- type == PD_CTRL_WAIT) {
+ type == PD_CTRL_WAIT) {
if (type == PD_CTRL_WAIT)
PE_SET_FLAG(port, PE_FLAGS_WAIT);
@@ -3403,7 +3440,8 @@ static void pe_snk_select_capability_run(int port)
* to PE_SNK_Wait_For_Capabilities
*/
else
- set_state_pe(port,
+ set_state_pe(
+ port,
PE_SNK_WAIT_FOR_CAPABILITIES);
return;
}
@@ -3464,8 +3502,7 @@ static void pe_snk_transition_sink_run(int port)
* PS_RDY message received
*/
if ((PD_HEADER_CNT(rx_emsg[port].header) == 0) &&
- (PD_HEADER_TYPE(rx_emsg[port].header) ==
- PD_CTRL_PS_RDY)) {
+ (PD_HEADER_TYPE(rx_emsg[port].header) == PD_CTRL_PS_RDY)) {
/*
* Set first message flag to trigger a wait and add
* jitter delay when operating in PD2.0 mode.
@@ -3488,8 +3525,8 @@ static void pe_snk_transition_sink_run(int port)
* already available
*/
if (pd_get_snk_cap_cnt(port) > 0)
- dpm_evaluate_sink_fixed_pdo(port,
- *pd_get_snk_caps(port));
+ dpm_evaluate_sink_fixed_pdo(
+ port, *pd_get_snk_caps(port));
set_state_pe(port, PE_SNK_READY);
} else {
@@ -3515,13 +3552,13 @@ static void pe_snk_transition_sink_run(int port)
static void pe_snk_transition_sink_exit(int port)
{
/* Transition Sink's power supply to the new power level */
- pd_set_input_current_limit(port,
- pe[port].curr_limit, pe[port].supply_voltage);
+ pd_set_input_current_limit(port, pe[port].curr_limit,
+ pe[port].supply_voltage);
if (IS_ENABLED(CONFIG_CHARGE_MANAGER))
/* Set ceiling based on what's negotiated */
- charge_manager_set_ceil(port,
- CEIL_REQUESTOR_PD, pe[port].curr_limit);
+ charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
+ pe[port].curr_limit);
pd_timer_disable(port, PE_TIMER_PS_TRANSITION);
@@ -3530,7 +3567,6 @@ static void pe_snk_transition_sink_exit(int port)
dps_update_stabilized_time(port);
}
-
/**
* PE_SNK_Ready State
*/
@@ -3551,8 +3587,7 @@ static void pe_snk_ready_entry(int port)
*/
if (PE_CHK_FLAG(port, PE_FLAGS_WAIT)) {
PE_CLR_FLAG(port, PE_FLAGS_WAIT);
- pd_timer_enable(port, PE_TIMER_SINK_REQUEST,
- PD_T_SINK_REQUEST);
+ pd_timer_enable(port, PE_TIMER_SINK_REQUEST, PD_T_SINK_REQUEST);
}
/*
@@ -3596,23 +3631,28 @@ static void pe_snk_ready_run(int port)
else if (cnt > 0) {
switch (type) {
case PD_DATA_SOURCE_CAP:
- set_state_pe(port,
- PE_SNK_EVALUATE_CAPABILITY);
+ set_state_pe(port, PE_SNK_EVALUATE_CAPABILITY);
break;
case PD_DATA_VENDOR_DEF:
if (PD_HEADER_TYPE(rx_emsg[port].header) ==
- PD_DATA_VENDOR_DEF) {
+ PD_DATA_VENDOR_DEF) {
if (PD_VDO_SVDM(*payload))
set_state_pe(port,
- PE_VDM_RESPONSE);
+ PE_VDM_RESPONSE);
else
- set_state_pe(port,
- PE_HANDLE_CUSTOM_VDM_REQUEST);
+ set_state_pe(
+ port,
+ PE_HANDLE_CUSTOM_VDM_REQUEST);
}
break;
case PD_DATA_BIST:
set_state_pe(port, PE_BIST_TX);
break;
+#ifdef CONFIG_USB_PD_REV30
+ case PD_DATA_ALERT:
+ set_state_pe(port, PE_ALERT_RECEIVED);
+ return;
+#endif /* CONFIG_USB_PD_REV30 */
default:
set_state_pe(port, PE_SEND_NOT_SUPPORTED);
}
@@ -3638,30 +3678,32 @@ static void pe_snk_ready_run(int port)
return;
case PD_CTRL_PR_SWAP:
set_state_pe(port,
- PE_PRS_SNK_SRC_EVALUATE_SWAP);
+ PE_PRS_SNK_SRC_EVALUATE_SWAP);
return;
case PD_CTRL_DR_SWAP:
if (PE_CHK_FLAG(port, PE_FLAGS_MODAL_OPERATION))
pe_set_hard_reset(port);
else
set_state_pe(port,
- PE_DRS_EVALUATE_SWAP);
+ PE_DRS_EVALUATE_SWAP);
return;
case PD_CTRL_VCONN_SWAP:
if (IS_ENABLED(CONFIG_USBC_VCONN))
set_state_pe(port,
- PE_VCS_EVALUATE_SWAP);
+ PE_VCS_EVALUATE_SWAP);
else
set_state_pe(port,
- PE_SEND_NOT_SUPPORTED);
+ PE_SEND_NOT_SUPPORTED);
return;
#ifdef CONFIG_USB_PD_DATA_RESET_MSG
case PD_CTRL_DATA_RESET:
if (pe[port].data_role == PD_ROLE_DFP)
- set_state_pe(port,
+ set_state_pe(
+ port,
PE_DDR_DATA_RESET_RECEIVED);
else
- set_state_pe(port,
+ set_state_pe(
+ port,
PE_UDR_DATA_RESET_RECEIVED);
return;
#endif /* CONFIG_USB_PD_DATA_RESET_MSG */
@@ -3682,8 +3724,9 @@ static void pe_snk_ready_run(int port)
case PD_CTRL_REJECT:
case PD_CTRL_WAIT:
case PD_CTRL_PS_RDY:
- pe_send_soft_reset(port,
- PD_HEADER_GET_SOP(rx_emsg[port].header));
+ pe_send_soft_reset(
+ port, PD_HEADER_GET_SOP(
+ rx_emsg[port].header));
return;
/*
* Receiving an unknown or unsupported message
@@ -3735,7 +3778,6 @@ static void pe_snk_ready_run(int port)
/* No DPM requests; attempt mode entry/exit if needed */
dpm_run(port);
-
}
}
@@ -3756,7 +3798,7 @@ static void pe_snk_hard_reset_entry(int port)
* Source is non-responsive.
*/
if (PE_CHK_FLAG(port, PE_FLAGS_SNK_WAIT_CAP_TIMEOUT) &&
- pe[port].hard_reset_counter > N_HARD_RESET_COUNT) {
+ pe[port].hard_reset_counter > N_HARD_RESET_COUNT) {
set_state_pe(port, PE_SRC_DISABLED);
return;
}
@@ -3776,13 +3818,13 @@ static void pe_snk_hard_reset_entry(int port)
if (IS_ENABLED(CONFIG_BATTERY) && (battery_is_present() == BP_NO) &&
IS_ENABLED(CONFIG_CHARGE_MANAGER) &&
((port == charge_manager_get_active_charge_port() ||
- (charge_manager_get_active_charge_port() == CHARGE_PORT_NONE))) &&
+ (charge_manager_get_active_charge_port() == CHARGE_PORT_NONE))) &&
system_get_reset_flags() & EC_RESET_FLAG_SYSJUMP) {
CPRINTS("C%d: Disabling port to avoid brown out, "
- "please reboot EC to enable port again", port);
+ "please reboot EC to enable port again",
+ port);
set_state_pe(port, PE_SRC_DISABLED);
return;
-
}
#ifdef CONFIG_USB_PD_RESET_MIN_BATT_SOC
@@ -3803,19 +3845,18 @@ static void pe_snk_hard_reset_entry(int port)
if (batt_soc < CONFIG_USB_PD_RESET_MIN_BATT_SOC ||
battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED) {
PE_SET_FLAG(port, PE_FLAGS_SNK_WAITING_BATT);
- CPRINTS("C%d: Battery low %d%%! Stay in disabled state " \
- "until battery level reaches %d%%", port, batt_soc,
- CONFIG_USB_PD_RESET_MIN_BATT_SOC);
+ CPRINTS("C%d: Battery low %d%%! Stay in disabled state "
+ "until battery level reaches %d%%",
+ port, batt_soc, CONFIG_USB_PD_RESET_MIN_BATT_SOC);
set_state_pe(port, PE_SRC_DISABLED);
return;
}
#endif
- PE_CLR_MASK(port,
- BIT(PE_FLAGS_SNK_WAIT_CAP_TIMEOUT_FN) |
- BIT(PE_FLAGS_VDM_REQUEST_NAKED_FN) |
- BIT(PE_FLAGS_PROTOCOL_ERROR_FN) |
- BIT(PE_FLAGS_VDM_REQUEST_BUSY_FN));
+ PE_CLR_MASK(port, BIT(PE_FLAGS_SNK_WAIT_CAP_TIMEOUT_FN) |
+ BIT(PE_FLAGS_VDM_REQUEST_NAKED_FN) |
+ BIT(PE_FLAGS_PROTOCOL_ERROR_FN) |
+ BIT(PE_FLAGS_VDM_REQUEST_BUSY_FN));
/* Request the generation of Hard Reset Signaling by the PHY Layer */
prl_execute_hard_reset(port);
@@ -3832,11 +3873,11 @@ static void pe_snk_hard_reset_entry(int port)
/* Transition Sink's power supply to the new power level */
pd_set_input_current_limit(port, pe[port].curr_limit,
- pe[port].supply_voltage);
+ pe[port].supply_voltage);
if (IS_ENABLED(CONFIG_CHARGE_MANAGER))
/* Set ceiling based on what's negotiated */
charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
- pe[port].curr_limit);
+ pe[port].curr_limit);
}
}
@@ -3943,8 +3984,8 @@ static void pe_send_soft_reset_run(int port)
* unexpected incoming message type
*/
/* Send Soft Reset message */
- send_ctrl_msg(port,
- pe[port].soft_reset_sop, PD_CTRL_SOFT_RESET);
+ send_ctrl_msg(port, pe[port].soft_reset_sop,
+ PD_CTRL_SOFT_RESET);
return;
}
@@ -3978,10 +4019,9 @@ static void pe_send_soft_reset_run(int port)
if ((ext == 0) && (cnt == 0) && (type == PD_CTRL_ACCEPT)) {
if (pe[port].power_role == PD_ROLE_SINK)
set_state_pe(port,
- PE_SNK_WAIT_FOR_CAPABILITIES);
+ PE_SNK_WAIT_FOR_CAPABILITIES);
else
- set_state_pe(port,
- PE_SRC_SEND_CAPABILITIES);
+ set_state_pe(port, PE_SRC_SEND_CAPABILITIES);
return;
}
}
@@ -3991,7 +4031,7 @@ static void pe_send_soft_reset_run(int port)
* Response Timer Timeout or Protocol Layer or Protocol Error
*/
if (pd_timer_is_expired(port, PE_TIMER_SENDER_RESPONSE) ||
- PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
+ PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
pe_set_hard_reset(port);
return;
@@ -4014,7 +4054,7 @@ static void pe_soft_reset_entry(int port)
send_ctrl_msg(port, TCPCI_MSG_SOP, PD_CTRL_ACCEPT);
}
-static void pe_soft_reset_run(int port)
+static void pe_soft_reset_run(int port)
{
if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE)) {
PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE);
@@ -4054,7 +4094,6 @@ static void pe_send_not_supported_run(int port)
if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE)) {
PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE);
pe_set_ready_state(port);
-
}
}
@@ -4176,32 +4215,28 @@ static void pe_give_battery_cap_entry(int port)
*/
msg[BCDB_FULL_CAP] = 0xffff;
-
if (IS_ENABLED(HAS_TASK_HOSTCMD) &&
*host_get_memmap(EC_MEMMAP_BATTERY_VERSION) != 0) {
int design_volt, design_cap, full_cap;
- design_volt = *(int *)host_get_memmap(
- EC_MEMMAP_BATT_DVLT);
- design_cap = *(int *)host_get_memmap(
- EC_MEMMAP_BATT_DCAP);
- full_cap = *(int *)host_get_memmap(
- EC_MEMMAP_BATT_LFCC);
+ design_volt =
+ *(int *)host_get_memmap(EC_MEMMAP_BATT_DVLT);
+ design_cap =
+ *(int *)host_get_memmap(EC_MEMMAP_BATT_DCAP);
+ full_cap = *(int *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
/*
* Wh = (c * v) / 1000000
* 10th of a Wh = Wh * 10
*/
msg[BCDB_DESIGN_CAP] = DIV_ROUND_NEAREST(
- (design_cap * design_volt),
- 100000);
+ (design_cap * design_volt), 100000);
/*
* Wh = (c * v) / 1000000
* 10th of a Wh = Wh * 10
*/
msg[BCDB_FULL_CAP] = DIV_ROUND_NEAREST(
- (design_cap * full_cap),
- 100000);
+ (design_cap * full_cap), 100000);
} else {
uint32_t v;
uint32_t c;
@@ -4213,24 +4248,19 @@ static void pe_give_battery_cap_entry(int port)
* 10th of a Wh = Wh * 10
*/
msg[BCDB_DESIGN_CAP] =
- DIV_ROUND_NEAREST(
- (c * v),
- 100000);
+ DIV_ROUND_NEAREST((c * v),
+ 100000);
}
- if (battery_full_charge_capacity(&c)
- == 0) {
+ if (battery_full_charge_capacity(&c) == 0) {
/*
* Wh = (c * v) / 1000000
* 10th of a Wh = Wh * 10
*/
- msg[BCDB_FULL_CAP] =
- DIV_ROUND_NEAREST(
- (c * v),
- 100000);
+ msg[BCDB_FULL_CAP] = DIV_ROUND_NEAREST(
+ (c * v), 100000);
}
}
-
}
/* Valid battery selected */
msg[BCDB_BATT_TYPE] = 0;
@@ -4286,24 +4316,23 @@ static void pe_give_battery_status_entry(int port)
if (IS_ENABLED(HAS_TASK_HOSTCMD) &&
*host_get_memmap(EC_MEMMAP_BATTERY_VERSION) != 0) {
v = *(int *)host_get_memmap(
- EC_MEMMAP_BATT_DVLT);
- c = *(int *)host_get_memmap(
- EC_MEMMAP_BATT_CAP);
+ EC_MEMMAP_BATT_DVLT);
+ c = *(int *)host_get_memmap(EC_MEMMAP_BATT_CAP);
/*
* Wh = (c * v) / 1000000
* 10th of a Wh = Wh * 10
*/
- *msg = BSDO_CAP(DIV_ROUND_NEAREST((c * v),
- 100000));
+ *msg = BSDO_CAP(
+ DIV_ROUND_NEAREST((c * v), 100000));
} else if (battery_design_voltage(&v) == 0 &&
battery_remaining_capacity(&c) == 0) {
/*
* Wh = (c * v) / 1000000
* 10th of a Wh = Wh * 10
*/
- *msg = BSDO_CAP(DIV_ROUND_NEAREST((c * v),
- 100000));
+ *msg = BSDO_CAP(
+ DIV_ROUND_NEAREST((c * v), 100000));
}
/* Battery is present */
@@ -4377,7 +4406,6 @@ static void pe_give_status_run(int port)
}
}
-
/**
* PE_SRC_Send_Source_Alert and
* PE_SNK_Send_Sink_Alert
@@ -4411,6 +4439,20 @@ static void pe_send_alert_run(int port)
pe_set_ready_state(port);
}
}
+
+/**
+ * PE_SNK_Source_Alert_Received and
+ * PE_SRC_Sink_Alert_Received
+ */
+static void pe_alert_received_entry(int port)
+{
+ uint32_t *ado = (uint32_t *)rx_emsg[port].buf;
+
+ print_current_state(port);
+ dpm_handle_alert(port, *ado);
+ pe_set_ready_state(port);
+}
+
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
/**
@@ -4539,8 +4581,8 @@ static void pe_drs_send_swap_run(int port)
set_state_pe(port, PE_DRS_CHANGE);
return;
} else if ((type == PD_CTRL_REJECT) ||
- (type == PD_CTRL_WAIT) ||
- (type == PD_CTRL_NOT_SUPPORTED)) {
+ (type == PD_CTRL_WAIT) ||
+ (type == PD_CTRL_NOT_SUPPORTED)) {
pe_set_ready_state(port);
return;
}
@@ -4742,8 +4784,7 @@ static void pe_prs_src_snk_wait_source_on_run(int port)
static void pe_prs_src_snk_wait_source_on_exit(int port)
{
pd_timer_disable(port, PE_TIMER_PS_SOURCE);
- tc_pr_swap_complete(port,
- PE_CHK_FLAG(port, PE_FLAGS_PR_SWAP_COMPLETE));
+ tc_pr_swap_complete(port, PE_CHK_FLAG(port, PE_FLAGS_PR_SWAP_COMPLETE));
}
/**
@@ -4794,7 +4835,7 @@ static void pe_prs_src_snk_send_swap_run(int port)
pe[port].src_snk_pr_swap_counter = 0;
tc_request_power_swap(port);
set_state_pe(port,
- PE_PRS_SRC_SNK_TRANSITION_TO_OFF);
+ PE_PRS_SRC_SNK_TRANSITION_TO_OFF);
} else if (type == PD_CTRL_REJECT) {
pe[port].src_snk_pr_swap_counter = 0;
set_state_pe(port, PE_SRC_READY);
@@ -4802,7 +4843,7 @@ static void pe_prs_src_snk_send_swap_run(int port)
if (pe[port].src_snk_pr_swap_counter <
N_SNK_SRC_PR_SWAP_COUNT) {
PE_SET_FLAG(port,
- PE_FLAGS_WAITING_PR_SWAP);
+ PE_FLAGS_WAITING_PR_SWAP);
pd_timer_enable(port,
PE_TIMER_PR_SWAP_WAIT,
PD_T_PR_SWAP_WAIT);
@@ -4902,8 +4943,7 @@ static void pe_prs_snk_src_transition_to_off_entry(int port)
{
print_current_state(port);
- if (!IS_ENABLED(CONFIG_USB_PD_REV30) ||
- !pe_in_frs_mode(port))
+ if (!IS_ENABLED(CONFIG_USB_PD_REV30) || !pe_in_frs_mode(port))
tc_snk_power_off(port);
pd_timer_enable(port, PE_TIMER_PS_SOURCE, PD_T_PS_SOURCE_OFF);
@@ -4970,8 +5010,7 @@ static void pe_prs_snk_src_assert_rp_run(int port)
{
/* Wait until TypeC is in the Attached.SRC state */
if (tc_is_attached_src(port)) {
- if (!IS_ENABLED(CONFIG_USB_PD_REV30) ||
- !pe_in_frs_mode(port)) {
+ if (!IS_ENABLED(CONFIG_USB_PD_REV30) || !pe_in_frs_mode(port)) {
/* Contract is invalid now */
pe_invalidate_explicit_contract(port);
}
@@ -5032,8 +5071,7 @@ static void pe_prs_snk_src_source_on_run(int port)
static void pe_prs_snk_src_source_on_exit(int port)
{
pd_timer_disable(port, PE_TIMER_PS_SOURCE);
- tc_pr_swap_complete(port,
- PE_CHK_FLAG(port, PE_FLAGS_PR_SWAP_COMPLETE));
+ tc_pr_swap_complete(port, PE_CHK_FLAG(port, PE_FLAGS_PR_SWAP_COMPLETE));
}
/**
@@ -5056,11 +5094,9 @@ static void pe_prs_snk_src_send_swap_entry(int port)
* Request the Protocol Layer to send a FR_Swap Message.
*/
if (IS_ENABLED(CONFIG_USB_PD_REV30)) {
- send_ctrl_msg(port,
- TCPCI_MSG_SOP,
- pe_in_frs_mode(port)
- ? PD_CTRL_FR_SWAP
- : PD_CTRL_PR_SWAP);
+ send_ctrl_msg(port, TCPCI_MSG_SOP,
+ pe_in_frs_mode(port) ? PD_CTRL_FR_SWAP :
+ PD_CTRL_PR_SWAP);
} else {
send_ctrl_msg(port, TCPCI_MSG_SOP, PD_CTRL_PR_SWAP);
}
@@ -5113,12 +5149,13 @@ static void pe_prs_snk_src_send_swap_run(int port)
set_state_pe(port,
PE_PRS_SNK_SRC_TRANSITION_TO_OFF);
} else if ((type == PD_CTRL_REJECT) ||
- (type == PD_CTRL_WAIT)) {
+ (type == PD_CTRL_WAIT)) {
if (IS_ENABLED(CONFIG_USB_PD_REV30))
- set_state_pe(port,
- pe_in_frs_mode(port)
- ? PE_WAIT_FOR_ERROR_RECOVERY
- : PE_SNK_READY);
+ set_state_pe(
+ port,
+ pe_in_frs_mode(port) ?
+ PE_WAIT_FOR_ERROR_RECOVERY :
+ PE_SNK_READY);
else
set_state_pe(port, PE_SNK_READY);
}
@@ -5133,10 +5170,9 @@ static void pe_prs_snk_src_send_swap_run(int port)
*/
if (pd_timer_is_expired(port, PE_TIMER_SENDER_RESPONSE)) {
if (IS_ENABLED(CONFIG_USB_PD_REV30))
- set_state_pe(port,
- pe_in_frs_mode(port)
- ? PE_WAIT_FOR_ERROR_RECOVERY
- : PE_SNK_READY);
+ set_state_pe(port, pe_in_frs_mode(port) ?
+ PE_WAIT_FOR_ERROR_RECOVERY :
+ PE_SNK_READY);
else
set_state_pe(port, PE_SNK_READY);
return;
@@ -5147,9 +5183,8 @@ static void pe_prs_snk_src_send_swap_run(int port)
* has not been received). A soft reset Shall Not be initiated in
* this case.
*/
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- pe_in_frs_mode(port) &&
- PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
+ if (IS_ENABLED(CONFIG_USB_PD_REV30) && pe_in_frs_mode(port) &&
+ PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
}
@@ -5269,6 +5304,18 @@ static void pe_bist_tx_entry(int port)
*/
if (tcpc_set_bist_test_mode(port, true) != EC_SUCCESS)
CPRINTS("C%d: Failed to enter BIST Test Mode", port);
+ } else if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
+ mode == BIST_SHARED_MODE_ENTER) {
+ /* Notify the DPM and return to ready */
+ dpm_bist_shared_mode_enter(port);
+ pe_set_ready_state(port);
+ return;
+ } else if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
+ mode == BIST_SHARED_MODE_EXIT) {
+ /* Notify the DPM and return to ready */
+ dpm_bist_shared_mode_exit(port);
+ pe_set_ready_state(port);
+ return;
} else {
/* Ignore unsupported BIST messages. */
pe_set_ready_state(port);
@@ -5415,10 +5462,10 @@ static enum vdm_response_result parse_vdm_response_common(int port)
cnt = PD_HEADER_CNT(rx_emsg[port].header);
ext = PD_HEADER_EXT(rx_emsg[port].header);
- if (sop == pe[port].tx_type && type == PD_DATA_VENDOR_DEF && cnt >= 1
- && ext == 0) {
+ if (sop == pe[port].tx_type && type == PD_DATA_VENDOR_DEF && cnt >= 1 &&
+ ext == 0) {
if (PD_VDO_CMDT(payload[0]) == CMDT_RSP_ACK &&
- cnt >= pe[port].vdm_ack_min_data_objects) {
+ cnt >= pe[port].vdm_ack_min_data_objects) {
/* Handle ACKs in state-specific code. */
return VDM_RESULT_ACK;
} else if (PD_VDO_CMDT(payload[0]) == CMDT_RSP_NAK) {
@@ -5430,7 +5477,7 @@ static enum vdm_response_result parse_vdm_response_common(int port)
* tVDMBusy
*/
CPRINTS("C%d: Partner BUSY, request will be retried",
- port);
+ port);
pd_timer_enable(port, PE_TIMER_DISCOVER_IDENTITY,
PD_T_VDM_BUSY);
@@ -5448,11 +5495,11 @@ static enum vdm_response_result parse_vdm_response_common(int port)
* Partner gave us an incorrect size or command; mark discovery
* as failed.
*/
- CPRINTS("C%d: Unexpected VDM response: 0x%04x 0x%04x",
- port, rx_emsg[port].header, payload[0]);
+ CPRINTS("C%d: Unexpected VDM response: 0x%04x 0x%04x", port,
+ rx_emsg[port].header, payload[0]);
return VDM_RESULT_NAK;
} else if (sop == pe[port].tx_type && ext == 0 && cnt == 0 &&
- type == PD_CTRL_NOT_SUPPORTED) {
+ type == PD_CTRL_NOT_SUPPORTED) {
/*
* A NAK would be more expected here, but Not Supported is still
* allowed with the same meaning.
@@ -5483,16 +5530,16 @@ static void pe_vdm_send_request_entry(int port)
if ((pe[port].tx_type == TCPCI_MSG_SOP_PRIME ||
pe[port].tx_type == TCPCI_MSG_SOP_PRIME_PRIME) &&
- !tc_is_vconn_src(port) && port_discovery_vconn_swap_policy(port,
- BIT(PE_FLAGS_VCONN_SWAP_TO_ON_FN))) {
+ !tc_is_vconn_src(port) &&
+ port_discovery_vconn_swap_policy(
+ port, BIT(PE_FLAGS_VCONN_SWAP_TO_ON_FN))) {
if (port_try_vconn_swap(port))
return;
}
/* All VDM sequences are Interruptible */
- PE_SET_MASK(port,
- BIT(PE_FLAGS_LOCALLY_INITIATED_AMS_FN) |
- BIT(PE_FLAGS_INTERRUPTIBLE_AMS_FN));
+ PE_SET_MASK(port, BIT(PE_FLAGS_LOCALLY_INITIATED_AMS_FN) |
+ BIT(PE_FLAGS_INTERRUPTIBLE_AMS_FN));
}
static void pe_vdm_send_request_run(int port)
@@ -5504,8 +5551,7 @@ static void pe_vdm_send_request_run(int port)
/* Start no response timer */
/* TODO(b/155890173): Support DPM-supplied timeout */
- pd_timer_enable(port, PE_TIMER_VDM_RESPONSE,
- PD_T_VDM_SNDR_RSP);
+ pd_timer_enable(port, PE_TIMER_VDM_RESPONSE, PD_T_VDM_SNDR_RSP);
}
if (PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
@@ -5523,8 +5569,7 @@ static void pe_vdm_send_request_run(int port)
*/
if (pd_timer_is_expired(port, PE_TIMER_VDM_RESPONSE)) {
CPRINTF("VDM %s Response Timeout\n",
- pe[port].tx_type == TCPCI_MSG_SOP ?
- "Port" : "Cable");
+ pe[port].tx_type == TCPCI_MSG_SOP ? "Port" : "Cable");
/*
* Flag timeout so child state can mark appropriate discovery
* item as failed.
@@ -5572,8 +5617,8 @@ static void pe_vdm_identity_request_cbl_entry(int port)
}
msg[0] = VDO(USB_SID_PD, 1,
- VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
- CMD_DISCOVER_IDENT);
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
+ CMD_DISCOVER_IDENT);
tx_emsg[port].len = sizeof(uint32_t);
send_data_msg(port, pe[port].tx_type, PD_DATA_VENDOR_DEF);
@@ -5590,7 +5635,7 @@ static void pe_vdm_identity_request_cbl_entry(int port)
static void pe_vdm_identity_request_cbl_run(int port)
{
/* Retrieve the message information */
- uint32_t *payload = (uint32_t *) rx_emsg[port].buf;
+ uint32_t *payload = (uint32_t *)rx_emsg[port].buf;
int sop = PD_HEADER_GET_SOP(rx_emsg[port].header);
uint8_t type = PD_HEADER_TYPE(rx_emsg[port].header);
uint8_t cnt = PD_HEADER_CNT(rx_emsg[port].header);
@@ -5623,9 +5668,8 @@ static void pe_vdm_identity_request_cbl_run(int port)
* state.
*/
if (get_last_state_pe(port) == PE_SRC_DISCOVERY &&
- (sop != pe[port].tx_type ||
- type != PD_DATA_VENDOR_DEF ||
- cnt == 0 || ext != 0)) {
+ (sop != pe[port].tx_type || type != PD_DATA_VENDOR_DEF ||
+ cnt == 0 || ext != 0)) {
/*
* Unexpected non-VDM received: Before an explicit
* contract, an unexpected message shall generate a soft
@@ -5689,10 +5733,9 @@ static void pe_vdm_identity_request_cbl_exit(int port)
* Not send any further SOP’/SOP’’ Messages.
*/
if (pe[port].discover_identity_counter >= N_DISCOVER_IDENTITY_COUNT)
- pd_set_identity_discovery(port, pe[port].tx_type,
- PD_DISC_FAIL);
+ pd_set_identity_discovery(port, pe[port].tx_type, PD_DISC_FAIL);
else if (pe[port].discover_identity_counter ==
- N_DISCOVER_IDENTITY_PD3_0_LIMIT)
+ N_DISCOVER_IDENTITY_PD3_0_LIMIT)
/*
* Downgrade to PD 2.0 if the partner hasn't replied before
* all retries are exhausted in case the cable is
@@ -5703,8 +5746,9 @@ static void pe_vdm_identity_request_cbl_exit(int port)
/*
* Set discover identity timer unless BUSY case already did so.
*/
- if (pd_get_identity_discovery(port, pe[port].tx_type) == PD_DISC_NEEDED
- && pd_timer_is_expired(port, PE_TIMER_DISCOVER_IDENTITY)) {
+ if (pd_get_identity_discovery(port, pe[port].tx_type) ==
+ PD_DISC_NEEDED &&
+ pd_timer_is_expired(port, PE_TIMER_DISCOVER_IDENTITY)) {
/*
* The tDiscoverIdentity timer is used during an explicit
* contract when discovering whether a cable is PD capable.
@@ -5714,17 +5758,18 @@ static void pe_vdm_identity_request_cbl_exit(int port)
* power the SOP' responder from VBUS instead of VCONN.
*/
pd_timer_enable(port, PE_TIMER_DISCOVER_IDENTITY,
- pe_is_explicit_contract(port)
- ? PD_T_DISCOVER_IDENTITY
- : PE_T_DISCOVER_IDENTITY_NO_CONTRACT);
+ pe_is_explicit_contract(port) ?
+ PD_T_DISCOVER_IDENTITY :
+ PE_T_DISCOVER_IDENTITY_NO_CONTRACT);
}
/* Do not attempt further discovery if identity discovery failed. */
if (pd_get_identity_discovery(port, pe[port].tx_type) == PD_DISC_FAIL) {
pd_set_svids_discovery(port, pe[port].tx_type, PD_DISC_FAIL);
- pd_notify_event(port, pe[port].tx_type == TCPCI_MSG_SOP ?
- PD_STATUS_EVENT_SOP_DISC_DONE :
- PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
+ pd_notify_event(port,
+ pe[port].tx_type == TCPCI_MSG_SOP ?
+ PD_STATUS_EVENT_SOP_DISC_DONE :
+ PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
}
}
@@ -5743,8 +5788,8 @@ static void pe_init_port_vdm_identity_request_entry(int port)
print_current_state(port);
msg[0] = VDO(USB_SID_PD, 1,
- VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
- CMD_DISCOVER_IDENT);
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
+ CMD_DISCOVER_IDENT);
tx_emsg[port].len = sizeof(uint32_t);
send_data_msg(port, pe[port].tx_type, PD_DATA_VENDOR_DEF);
@@ -5771,7 +5816,7 @@ static void pe_init_port_vdm_identity_request_run(int port)
break;
case VDM_RESULT_ACK: {
/* Retrieve the message information. */
- uint32_t *payload = (uint32_t *) rx_emsg[port].buf;
+ uint32_t *payload = (uint32_t *)rx_emsg[port].buf;
int sop = PD_HEADER_GET_SOP(rx_emsg[port].header);
uint8_t cnt = PD_HEADER_CNT(rx_emsg[port].header);
@@ -5779,7 +5824,7 @@ static void pe_init_port_vdm_identity_request_run(int port)
dfp_consume_identity(port, sop, cnt, payload);
break;
- }
+ }
case VDM_RESULT_NAK:
/* PE_INIT_PORT_VDM_IDENTITY_NAKed embedded here */
pd_set_identity_discovery(port, pe[port].tx_type, PD_DISC_FAIL);
@@ -5809,9 +5854,10 @@ static void pe_init_port_vdm_identity_request_exit(int port)
/* Do not attempt further discovery if identity discovery failed. */
if (pd_get_identity_discovery(port, pe[port].tx_type) == PD_DISC_FAIL) {
pd_set_svids_discovery(port, pe[port].tx_type, PD_DISC_FAIL);
- pd_notify_event(port, pe[port].tx_type == TCPCI_MSG_SOP ?
- PD_STATUS_EVENT_SOP_DISC_DONE :
- PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
+ pd_notify_event(port,
+ pe[port].tx_type == TCPCI_MSG_SOP ?
+ PD_STATUS_EVENT_SOP_DISC_DONE :
+ PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
}
}
@@ -5838,8 +5884,8 @@ static void pe_init_vdm_svids_request_entry(int port)
}
msg[0] = VDO(USB_SID_PD, 1,
- VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
- CMD_DISCOVER_SVID);
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
+ CMD_DISCOVER_SVID);
tx_emsg[port].len = sizeof(uint32_t);
send_data_msg(port, pe[port].tx_type, PD_DATA_VENDOR_DEF);
@@ -5866,14 +5912,14 @@ static void pe_init_vdm_svids_request_run(int port)
break;
case VDM_RESULT_ACK: {
/* Retrieve the message information. */
- uint32_t *payload = (uint32_t *) rx_emsg[port].buf;
+ uint32_t *payload = (uint32_t *)rx_emsg[port].buf;
int sop = PD_HEADER_GET_SOP(rx_emsg[port].header);
uint8_t cnt = PD_HEADER_CNT(rx_emsg[port].header);
/* PE_INIT_VDM_SVIDs_ACKed embedded here */
dfp_consume_svids(port, sop, cnt, payload);
break;
- }
+ }
case VDM_RESULT_NAK:
/* PE_INIT_VDM_SVIDs_NAKed embedded here */
pd_set_svids_discovery(port, pe[port].tx_type, PD_DISC_FAIL);
@@ -5902,9 +5948,10 @@ static void pe_init_vdm_svids_request_exit(int port)
/* If SVID discovery failed, discovery is done at this point */
if (pd_get_svids_discovery(port, pe[port].tx_type) == PD_DISC_FAIL)
- pd_notify_event(port, pe[port].tx_type == TCPCI_MSG_SOP ?
- PD_STATUS_EVENT_SOP_DISC_DONE :
- PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
+ pd_notify_event(port,
+ pe[port].tx_type == TCPCI_MSG_SOP ?
+ PD_STATUS_EVENT_SOP_DISC_DONE :
+ PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
}
/**
@@ -5935,14 +5982,14 @@ static void pe_init_vdm_modes_request_entry(int port)
* is still disabled, there's nothing left to try.
*/
pd_set_modes_discovery(port, pe[port].tx_type, svid,
- PD_DISC_FAIL);
+ PD_DISC_FAIL);
set_state_pe(port, get_last_state_pe(port));
return;
}
- msg[0] = VDO((uint16_t) svid, 1,
- VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
- CMD_DISCOVER_MODES);
+ msg[0] = VDO((uint16_t)svid, 1,
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, pe[port].tx_type)) |
+ CMD_DISCOVER_MODES);
tx_emsg[port].len = sizeof(uint32_t);
send_data_msg(port, pe[port].tx_type, PD_DATA_VENDOR_DEF);
@@ -5978,10 +6025,10 @@ static void pe_init_vdm_modes_request_run(int port)
break;
case VDM_RESULT_ACK: {
/* Retrieve the message information. */
- uint32_t *payload = (uint32_t *) rx_emsg[port].buf;
+ uint32_t *payload = (uint32_t *)rx_emsg[port].buf;
int sop = PD_HEADER_GET_SOP(rx_emsg[port].header);
uint8_t cnt = PD_HEADER_CNT(rx_emsg[port].header);
- uint16_t response_svid = (uint16_t) PD_VDO_VID(payload[0]);
+ uint16_t response_svid = (uint16_t)PD_VDO_VID(payload[0]);
/*
* Accept ACK if the request and response SVIDs are equal;
@@ -5995,12 +6042,12 @@ static void pe_init_vdm_modes_request_run(int port)
dfp_consume_modes(port, sop, cnt, payload);
break;
}
- }
+ }
/* Fall Through */
case VDM_RESULT_NAK:
/* PE_INIT_VDM_Modes_NAKed embedded here */
pd_set_modes_discovery(port, pe[port].tx_type, requested_svid,
- PD_DISC_FAIL);
+ PD_DISC_FAIL);
break;
}
@@ -6012,10 +6059,10 @@ static void pe_init_vdm_modes_request_exit(int port)
{
if (pd_get_modes_discovery(port, pe[port].tx_type) != PD_DISC_NEEDED)
/* Mode discovery done, notify the AP */
- pd_notify_event(port, pe[port].tx_type == TCPCI_MSG_SOP ?
- PD_STATUS_EVENT_SOP_DISC_DONE :
- PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
-
+ pd_notify_event(port,
+ pe[port].tx_type == TCPCI_MSG_SOP ?
+ PD_STATUS_EVENT_SOP_DISC_DONE :
+ PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
}
/**
@@ -6030,7 +6077,7 @@ static void pe_vdm_request_dpm_entry(int port)
if ((pe[port].tx_type == TCPCI_MSG_SOP_PRIME ||
pe[port].tx_type == TCPCI_MSG_SOP_PRIME_PRIME) &&
- !pe_can_send_sop_prime(port)) {
+ !pe_can_send_sop_prime(port)) {
/*
* The parent state already tried to enable SOP' traffic. If it
* is still disabled, there's nothing left to try.
@@ -6045,9 +6092,8 @@ static void pe_vdm_request_dpm_entry(int port)
/* Copy Vendor Data Objects (VDOs) into message buffer */
if (pe[port].vdm_cnt > 0) {
/* Copy data after header */
- memcpy(&tx_emsg[port].buf,
- (uint8_t *)pe[port].vdm_data,
- pe[port].vdm_cnt * 4);
+ memcpy(&tx_emsg[port].buf, (uint8_t *)pe[port].vdm_data,
+ pe[port].vdm_cnt * 4);
/* Update len with the number of VDO bytes */
tx_emsg[port].len = pe[port].vdm_cnt * 4;
}
@@ -6085,8 +6131,8 @@ static void pe_vdm_request_dpm_run(int port)
* transmit is complete.
*/
vdm_hdr = pe[port].vdm_data[0];
- if(PD_VDO_SVDM(vdm_hdr) &&
- (PD_VDO_CMD(vdm_hdr) == CMD_ATTENTION)) {
+ if (PD_VDO_SVDM(vdm_hdr) &&
+ (PD_VDO_CMD(vdm_hdr) == CMD_ATTENTION)) {
if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE)) {
PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE);
break;
@@ -6108,7 +6154,7 @@ static void pe_vdm_request_dpm_run(int port)
break;
case VDM_RESULT_ACK: {
/* Retrieve the message information. */
- uint32_t *payload = (uint32_t *) rx_emsg[port].buf;
+ uint32_t *payload = (uint32_t *)rx_emsg[port].buf;
int sop = PD_HEADER_GET_SOP(rx_emsg[port].header);
uint8_t cnt = PD_HEADER_CNT(rx_emsg[port].header);
uint16_t svid = PD_VDO_VID(payload[0]);
@@ -6121,11 +6167,11 @@ static void pe_vdm_request_dpm_run(int port)
dpm_vdm_acked(port, sop, cnt, payload);
if (sop == TCPCI_MSG_SOP && svid == USB_SID_DISPLAYPORT &&
- vdm_cmd == CMD_DP_CONFIG) {
+ vdm_cmd == CMD_DP_CONFIG) {
PE_SET_FLAG(port, PE_FLAGS_VDM_SETUP_DONE);
}
break;
- }
+ }
case VDM_RESULT_NAK:
/*
* PE initiator VDM-NAKed state for requested VDM, like
@@ -6139,8 +6185,8 @@ static void pe_vdm_request_dpm_run(int port)
* Extract the needed information from the sent VDM.
*/
dpm_vdm_naked(port, pe[port].tx_type,
- PD_VDO_VID(pe[port].vdm_data[0]),
- PD_VDO_CMD(pe[port].vdm_data[0]));
+ PD_VDO_VID(pe[port].vdm_data[0]),
+ PD_VDO_CMD(pe[port].vdm_data[0]));
break;
}
@@ -6150,6 +6196,24 @@ static void pe_vdm_request_dpm_run(int port)
static void pe_vdm_request_dpm_exit(int port)
{
+ if (PE_CHK_FLAG(port, PE_FLAGS_VDM_REQUEST_TIMEOUT)) {
+ PE_CLR_FLAG(port, PE_FLAGS_VDM_REQUEST_TIMEOUT);
+ PE_SET_FLAG(port, PE_FLAGS_VDM_SETUP_DONE);
+
+ /*
+ * Mark failure to respond as discovery failure.
+ *
+ * For PD 2.0 partners (6.10.3 Applicability of Structured VDM
+ * Commands Note 3):
+ *
+ * If Structured VDMs are not supported, a Structured VDM
+ * Command received by a DFP or UFP Shall be Ignored.
+ */
+ dpm_vdm_naked(port, pe[port].tx_type,
+ PD_VDO_VID(pe[port].vdm_data[0]),
+ PD_VDO_CMD(pe[port].vdm_data[0]));
+ }
+
/*
* Force Tx type to be reset before reentering a VDM state, unless the
* current VDM request will be resumed.
@@ -6323,11 +6387,9 @@ static void pe_vdm_response_run(int port)
if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE) ||
PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR) ||
PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
-
- PE_CLR_MASK(port,
- BIT(PE_FLAGS_TX_COMPLETE_FN) |
- BIT(PE_FLAGS_PROTOCOL_ERROR_FN) |
- BIT(PE_FLAGS_MSG_DISCARDED_FN));
+ PE_CLR_MASK(port, BIT(PE_FLAGS_TX_COMPLETE_FN) |
+ BIT(PE_FLAGS_PROTOCOL_ERROR_FN) |
+ BIT(PE_FLAGS_MSG_DISCARDED_FN));
pe_set_ready_state(port);
}
@@ -6360,7 +6422,7 @@ static void pe_enter_usb_entry(int port)
if ((pe[port].tx_type == TCPCI_MSG_SOP_PRIME ||
pe[port].tx_type == TCPCI_MSG_SOP_PRIME_PRIME) &&
- !tc_is_vconn_src(port)) {
+ !tc_is_vconn_src(port)) {
if (port_try_vconn_swap(port))
return;
}
@@ -6566,11 +6628,12 @@ static void pe_vcs_send_swap_run(int port)
*/
if (type == PD_CTRL_ACCEPT) {
if (tc_is_vconn_src(port)) {
- set_state_pe(port,
+ set_state_pe(
+ port,
PE_VCS_WAIT_FOR_VCONN_SWAP);
} else {
set_state_pe(port,
- PE_VCS_TURN_ON_VCONN_SWAP);
+ PE_VCS_TURN_ON_VCONN_SWAP);
}
return;
}
@@ -6593,7 +6656,7 @@ static void pe_vcs_send_swap_run(int port)
*/
if (type == PD_CTRL_NOT_SUPPORTED) {
if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- !tc_is_vconn_src(port))
+ !tc_is_vconn_src(port))
set_state_pe(port, PE_VCS_FORCE_VCONN);
else
pe_set_ready_state(port);
@@ -6675,8 +6738,8 @@ static void pe_vcs_wait_for_vconn_swap_run(int port)
* the incoming message.
*/
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
- pe_send_soft_reset(port,
- PD_HEADER_GET_SOP(rx_emsg[port].header));
+ pe_send_soft_reset(
+ port, PD_HEADER_GET_SOP(rx_emsg[port].header));
return;
}
}
@@ -6718,7 +6781,6 @@ static void pe_vcs_turn_on_vconn_swap_entry(int port)
static void pe_vcs_turn_on_vconn_swap_run(int port)
{
-
/*
* Transition to the PE_VCS_Send_Ps_Rdy state when:
* 1) The Port’s VCONN is on.
@@ -6778,7 +6840,7 @@ static void pe_vcs_send_ps_rdy_swap_entry(int port)
/* Check for any interruptions to this non-interruptible AMS */
if (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
enum tcpci_msg_type sop =
- PD_HEADER_GET_SOP(rx_emsg[port].header);
+ PD_HEADER_GET_SOP(rx_emsg[port].header);
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
@@ -6906,7 +6968,7 @@ static void pe_vcs_cbl_send_soft_reset_run(int port)
/* Got ACCEPT or REJECT from Cable Plug */
if ((msg_check & PE_MSG_SENT) &&
- PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
cable_soft_reset_complete = true;
@@ -7003,16 +7065,17 @@ static void pe_dr_get_sink_cap_run(int port)
if ((cnt > 0) && (type == PD_DATA_SINK_CAP)) {
uint32_t *payload =
(uint32_t *)rx_emsg[port].buf;
- uint8_t cap_cnt = rx_emsg[port].len /
- sizeof(uint32_t);
+ uint8_t cap_cnt =
+ rx_emsg[port].len / sizeof(uint32_t);
pe_set_snk_caps(port, cap_cnt, payload);
dpm_evaluate_sink_fixed_pdo(port, payload[0]);
pe_set_ready_state(port);
return;
- } else if (cnt == 0 && (type == PD_CTRL_REJECT ||
- type == PD_CTRL_NOT_SUPPORTED)) {
+ } else if (cnt == 0 &&
+ (type == PD_CTRL_REJECT ||
+ type == PD_CTRL_NOT_SUPPORTED)) {
pe_set_ready_state(port);
return;
}
@@ -7126,12 +7189,13 @@ static void pe_dr_src_get_source_cap_run(int port)
*/
if (IS_ENABLED(CONFIG_CHARGE_MANAGER) &&
pd_get_partner_dual_role_power(port))
- charge_manager_update_dualrole(port,
- CAP_DUALROLE);
+ charge_manager_update_dualrole(
+ port, CAP_DUALROLE);
set_state_pe(port, PE_SRC_READY);
- } else if ((cnt == 0) && (type == PD_CTRL_REJECT ||
- type == PD_CTRL_NOT_SUPPORTED)) {
+ } else if ((cnt == 0) &&
+ (type == PD_CTRL_REJECT ||
+ type == PD_CTRL_NOT_SUPPORTED)) {
pd_set_src_caps(port, -1, NULL);
set_state_pe(port, PE_SRC_READY);
} else {
@@ -7172,15 +7236,6 @@ __maybe_unused static void pe_get_revision_entry(int port)
{
print_current_state(port);
- /*
- * Only USB PD partners with major revision 3.0 could potentially
- * respond to Get_Revision.
- */
- if (prl_get_rev(port, TCPCI_MSG_SOP) != PD_REV30) {
- pe_set_ready_state(port);
- return;
- }
-
/* Send a Get_Revision message */
send_ctrl_msg(port, TCPCI_MSG_SOP, PD_CTRL_GET_REVISION);
pe_sender_response_msg_entry(port);
@@ -7193,14 +7248,11 @@ __maybe_unused static void pe_get_revision_run(int port)
int ext;
enum pe_msg_check msg_check;
- if (prl_get_rev(port, TCPCI_MSG_SOP) != PD_REV30)
- return;
-
/* Check the state of the message sent */
msg_check = pe_sender_response_msg_run(port);
if ((msg_check & PE_MSG_SENT) &&
- PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
type = PD_HEADER_TYPE(rx_emsg[port].header);
@@ -7210,7 +7262,7 @@ __maybe_unused static void pe_get_revision_run(int port)
if (ext == 0 && cnt == 1 && type == PD_DATA_REVISION) {
/* Revision returned by partner */
pe[port].partner_rmdo =
- *((struct rmdo *) rx_emsg[port].buf);
+ *((struct rmdo *)rx_emsg[port].buf);
} else if (type != PD_CTRL_NOT_SUPPORTED) {
/*
* If the partner response with a message other than
@@ -7235,14 +7287,10 @@ __maybe_unused static void pe_get_revision_run(int port)
if ((msg_check & PE_MSG_DISCARDED) ||
pd_timer_is_expired(port, PE_TIMER_SENDER_RESPONSE))
pe_set_ready_state(port);
-
}
__maybe_unused static void pe_get_revision_exit(int port)
{
- if (prl_get_rev(port, TCPCI_MSG_SOP) != PD_REV30)
- return;
-
pe_sender_response_msg_exit(port);
}
@@ -7284,17 +7332,17 @@ static void pe_udr_send_data_reset_run(int port)
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
if (PD_HEADER_GET_SOP(hdr) == TCPCI_MSG_SOP &&
- PD_HEADER_CNT(hdr) == 0 &&
- !PD_HEADER_EXT(hdr) &&
- PD_HEADER_TYPE(hdr) == PD_CTRL_ACCEPT) {
- set_state_pe(port, tc_is_vconn_src(port) ?
+ PD_HEADER_CNT(hdr) == 0 && !PD_HEADER_EXT(hdr) &&
+ PD_HEADER_TYPE(hdr) == PD_CTRL_ACCEPT) {
+ set_state_pe(
+ port,
+ tc_is_vconn_src(port) ?
PE_UDR_TURN_OFF_VCONN :
PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE);
return;
} else if (PD_HEADER_GET_SOP(hdr) == TCPCI_MSG_SOP &&
- PD_HEADER_CNT(hdr) == 0 &&
- !PD_HEADER_EXT(hdr) &&
- PD_HEADER_TYPE(hdr) == PD_CTRL_NOT_SUPPORTED) {
+ PD_HEADER_CNT(hdr) == 0 && !PD_HEADER_EXT(hdr) &&
+ PD_HEADER_TYPE(hdr) == PD_CTRL_NOT_SUPPORTED) {
/* Just pretend it worked. */
dpm_data_reset_complete(port);
pe_set_ready_state(port);
@@ -7306,7 +7354,7 @@ static void pe_udr_send_data_reset_run(int port)
}
if (pd_timer_is_expired(port, PE_TIMER_SENDER_RESPONSE) ||
- PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
+ PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
return;
@@ -7333,10 +7381,9 @@ static void pe_udr_data_reset_received_run(int port)
if (tc_is_vconn_src(port))
set_state_pe(port, PE_UDR_TURN_OFF_VCONN);
else
- set_state_pe(port,
- PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE);
+ set_state_pe(port, PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE);
} else if (PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR) ||
- PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
+ PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
PE_CLR_FLAG(port, PE_FLAGS_MSG_DISCARDED);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
@@ -7355,7 +7402,7 @@ static void pe_udr_turn_off_vconn_run(int port)
{
/* Wait until VCONN is fully discharged */
if (pd_timer_is_disabled(port, PE_TIMER_TIMEOUT) &&
- PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE)) {
+ PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE)) {
PE_CLR_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE);
pd_timer_enable(port, PE_TIMER_TIMEOUT,
CONFIG_USBC_VCONN_SWAP_DELAY_US);
@@ -7379,7 +7426,7 @@ static void pe_udr_send_ps_rdy_run(int port)
PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE);
set_state_pe(port, PE_UDR_WAIT_FOR_DATA_RESET_COMPLETE);
} else if (PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR) ||
- PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
+ PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
PE_CLR_FLAG(port, PE_FLAGS_MSG_DISCARDED);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
@@ -7461,9 +7508,8 @@ static void pe_ddr_send_data_reset_run(int port)
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
if (PD_HEADER_GET_SOP(hdr) == TCPCI_MSG_SOP &&
- PD_HEADER_CNT(hdr) == 0 &&
- !PD_HEADER_EXT(hdr) &&
- PD_HEADER_TYPE(hdr) == PD_CTRL_ACCEPT) {
+ PD_HEADER_CNT(hdr) == 0 && !PD_HEADER_EXT(hdr) &&
+ PD_HEADER_TYPE(hdr) == PD_CTRL_ACCEPT) {
/*
* Start DataResetFailTimer NOTE: This timer continues
* to run in every state until it is stopped or it times
@@ -7472,13 +7518,12 @@ static void pe_ddr_send_data_reset_run(int port)
pd_timer_enable(port, PE_TIMER_DATA_RESET_FAIL,
PD_T_DATA_RESET_FAIL);
set_state_pe(port, tc_is_vconn_src(port) ?
- PE_DDR_PERFORM_DATA_RESET :
- PE_DDR_WAIT_FOR_VCONN_OFF);
+ PE_DDR_PERFORM_DATA_RESET :
+ PE_DDR_WAIT_FOR_VCONN_OFF);
return;
} else if (PD_HEADER_GET_SOP(hdr) == TCPCI_MSG_SOP &&
- PD_HEADER_CNT(hdr) == 0 &&
- !PD_HEADER_EXT(hdr) &&
- PD_HEADER_TYPE(hdr) == PD_CTRL_NOT_SUPPORTED) {
+ PD_HEADER_CNT(hdr) == 0 && !PD_HEADER_EXT(hdr) &&
+ PD_HEADER_TYPE(hdr) == PD_CTRL_NOT_SUPPORTED) {
/* Just pretend it worked. */
dpm_data_reset_complete(port);
pe_set_ready_state(port);
@@ -7490,7 +7535,7 @@ static void pe_ddr_send_data_reset_run(int port)
}
if (pd_timer_is_expired(port, PE_TIMER_SENDER_RESPONSE) ||
- PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
+ PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
return;
@@ -7554,9 +7599,8 @@ static void pe_ddr_wait_for_vconn_off_run(int port)
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
if (PD_HEADER_GET_SOP(hdr) == TCPCI_MSG_SOP &&
- PD_HEADER_CNT(hdr) == 0 &&
- !PD_HEADER_EXT(hdr) &&
- PD_HEADER_TYPE(hdr) == PD_CTRL_PS_RDY) {
+ PD_HEADER_CNT(hdr) == 0 && !PD_HEADER_EXT(hdr) &&
+ PD_HEADER_TYPE(hdr) == PD_CTRL_PS_RDY) {
/* PS_RDY message received */
pd_timer_enable(port, PE_TIMER_VCONN_REAPPLIED,
PD_T_VCONN_REAPPLIED);
@@ -7569,7 +7613,7 @@ static void pe_ddr_wait_for_vconn_off_run(int port)
}
if (pd_timer_is_expired(port, PE_TIMER_VCONN_DISCHARGE) ||
- PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
+ PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
return;
@@ -7596,7 +7640,7 @@ static void pe_ddr_perform_data_reset_entry(int port)
* c) If operating in [USB4] drive the port’s SBTX to a logic low.
*/
usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_DISCONNECT,
- polarity_rm_dts(pd_get_polarity(port)));
+ polarity_rm_dts(pd_get_polarity(port)));
/* 2) Both the DFP and UFP Shall exit all Alternate Modes if any. */
if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
@@ -7635,18 +7679,18 @@ static void pe_ddr_perform_data_reset_run(int port)
* expires. At this point, the Data Reset process is complete.
*/
if (IS_ENABLED(CONFIG_USBC_VCONN) && !tc_is_vconn_src(port) &&
- PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE)) {
+ PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE)) {
PE_CLR_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE);
/* Wait until VCONN has discharged to start tVconnReapplied. */
pd_timer_enable(port, PE_TIMER_TIMEOUT,
- CONFIG_USBC_VCONN_SWAP_DELAY_US);
+ CONFIG_USBC_VCONN_SWAP_DELAY_US);
} else if (IS_ENABLED(CONFIG_USBC_VCONN) &&
- pd_timer_is_expired(port, PE_TIMER_TIMEOUT)) {
+ pd_timer_is_expired(port, PE_TIMER_TIMEOUT)) {
pd_timer_disable(port, PE_TIMER_TIMEOUT);
pd_timer_enable(port, PE_TIMER_VCONN_REAPPLIED,
PD_T_VCONN_REAPPLIED);
} else if (IS_ENABLED(CONFIG_USBC_VCONN) &&
- pd_timer_is_expired(port, PE_TIMER_VCONN_REAPPLIED)) {
+ pd_timer_is_expired(port, PE_TIMER_VCONN_REAPPLIED)) {
pd_request_vconn_swap_on(port);
pd_timer_disable(port, PE_TIMER_VCONN_REAPPLIED);
@@ -7664,15 +7708,21 @@ static void pe_ddr_perform_data_reset_run(int port)
* ambiguity and update this implementation.
*/
usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_DISCONNECT,
- polarity_rm_dts(pd_get_polarity(port)));
+ polarity_rm_dts(pd_get_polarity(port)));
} else if (IS_ENABLED(CONFIG_USBC_VCONN) &&
- PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE) &&
- tc_is_vconn_src(port)) {
+ PE_CHK_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE) &&
+ tc_is_vconn_src(port)) {
PE_CLR_FLAG(port, PE_FLAGS_VCONN_SWAP_COMPLETE);
PE_SET_FLAG(port, PE_FLAGS_DATA_RESET_COMPLETE);
} else if (PE_CHK_FLAG(port, PE_FLAGS_DATA_RESET_COMPLETE) &&
- !pd_timer_is_disabled(port, PE_TIMER_DATA_RESET_FAIL)) {
+ !pd_timer_is_disabled(port, PE_TIMER_DATA_RESET_FAIL)) {
pd_timer_disable(port, PE_TIMER_DATA_RESET_FAIL);
+ /*
+ * Because the cable power-cycled, reset the Tx (optional) and
+ * cached Rx (mandatory) message IDs.
+ */
+ prl_reset_msg_ids(port, TCPCI_MSG_SOP_PRIME);
+ prl_reset_msg_ids(port, TCPCI_MSG_SOP_PRIME_PRIME);
send_ctrl_msg(port, TCPCI_MSG_SOP, PD_CTRL_DATA_RESET_COMPLETE);
} else if (PE_CHK_FLAG(port, PE_FLAGS_DATA_RESET_COMPLETE)) {
/*
@@ -7689,7 +7739,7 @@ static void pe_ddr_perform_data_reset_run(int port)
}
return;
} else if (pd_timer_is_expired(port, PE_TIMER_DATA_RESET_FAIL) ||
- PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
+ PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) {
PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
set_state_pe(port, PE_WAIT_FOR_ERROR_RECOVERY);
return;
@@ -7709,11 +7759,12 @@ static void pe_ddr_perform_data_reset_exit(int port)
pd_timer_disable(port, PE_TIMER_VCONN_REAPPLIED);
pd_timer_disable(port, PE_TIMER_DATA_RESET_FAIL);
PE_CLR_FLAG(port, PE_FLAGS_DATA_RESET_COMPLETE);
+ pd_dpm_request(port, DPM_REQUEST_PORT_DISCOVERY);
dpm_data_reset_complete(port);
}
#endif /* CONFIG_USB_PD_DATA_RESET_MSG */
-const uint32_t * const pd_get_src_caps(int port)
+const uint32_t *const pd_get_src_caps(int port)
{
return pe[port].src_caps;
}
@@ -7746,7 +7797,6 @@ void pd_dfp_discovery_init(int port)
BIT(task_get_current()));
memset(pe[port].discovery, 0, sizeof(pe[port].discovery));
-
}
void pd_dfp_mode_init(int port)
@@ -7755,9 +7805,8 @@ void pd_dfp_mode_init(int port)
* Clear the VDM Setup Done and Modal Operation flags so we will
* have a fresh discovery
*/
- PE_CLR_MASK(port,
- BIT(PE_FLAGS_VDM_SETUP_DONE_FN) |
- BIT(PE_FLAGS_MODAL_OPERATION_FN));
+ PE_CLR_MASK(port, BIT(PE_FLAGS_VDM_SETUP_DONE_FN) |
+ BIT(PE_FLAGS_MODAL_OPERATION_FN));
memset(pe[port].partner_amodes, 0, sizeof(pe[port].partner_amodes));
@@ -7776,7 +7825,7 @@ void pd_dfp_mode_init(int port)
}
__maybe_unused void pd_discovery_access_clear(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
assert(0);
@@ -7785,7 +7834,7 @@ __maybe_unused void pd_discovery_access_clear(int port,
}
__maybe_unused bool pd_discovery_access_validate(int port,
- enum tcpci_msg_type type)
+ enum tcpci_msg_type type)
{
if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
assert(0);
@@ -7793,15 +7842,15 @@ __maybe_unused bool pd_discovery_access_validate(int port,
return !(task_access[port][type] & ~BIT(task_get_current()));
}
-__maybe_unused struct pd_discovery *pd_get_am_discovery_and_notify_access(
- int port, enum tcpci_msg_type type)
+__maybe_unused struct pd_discovery *
+pd_get_am_discovery_and_notify_access(int port, enum tcpci_msg_type type)
{
atomic_or(&task_access[port][type], BIT(task_get_current()));
return (struct pd_discovery *)pd_get_am_discovery(port, type);
}
-__maybe_unused const struct pd_discovery *pd_get_am_discovery(int port,
- enum tcpci_msg_type type)
+__maybe_unused const struct pd_discovery *
+pd_get_am_discovery(int port, enum tcpci_msg_type type)
{
if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
assert(0);
@@ -7810,8 +7859,8 @@ __maybe_unused const struct pd_discovery *pd_get_am_discovery(int port,
return &pe[port].discovery[type];
}
-__maybe_unused struct partner_active_modes *pd_get_partner_active_modes(
- int port, enum tcpci_msg_type type)
+__maybe_unused struct partner_active_modes *
+pd_get_partner_active_modes(int port, enum tcpci_msg_type type)
{
if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
assert(0);
@@ -7847,7 +7896,7 @@ uint32_t pe_get_flags(int port)
}
static __const_data const struct usb_state pe_states[] = {
- /* Super States */
+/* Super States */
#ifdef CONFIG_USB_PD_REV30
[PE_PRS_FRS_SHARED] = {
.entry = pe_prs_frs_shared_entry,
@@ -8179,6 +8228,9 @@ static __const_data const struct usb_state pe_states[] = {
.entry = pe_send_alert_entry,
.run = pe_send_alert_run,
},
+ [PE_ALERT_RECEIVED] = {
+ .entry = pe_alert_received_entry,
+ },
#else
[PE_SRC_CHUNK_RECEIVED] = {
.entry = pe_chunk_received_entry,
diff --git a/common/usbc/usb_pe_private.h b/common/usbc/usb_pe_private.h
index e68c4c2fcd..bfe534dcca 100644
--- a/common/usbc/usb_pe_private.h
+++ b/common/usbc/usb_pe_private.h
@@ -1,4 +1,4 @@
-/* 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.
*/
@@ -13,76 +13,84 @@
*/
enum {
-/* At least one successful PD communication packet received from port partner */
+ /* At least one successful PD communication packet received from port
+ partner */
PE_FLAGS_PD_CONNECTION_FN = 0,
-/* Accept message received from port partner */
+ /* Accept message received from port partner */
PE_FLAGS_ACCEPT_FN,
-/* Power Supply Ready message received from port partner */
+ /* Power Supply Ready message received from port partner */
PE_FLAGS_PS_READY_FN,
-/* Protocol Error was determined based on error recovery current state */
+ /* Protocol Error was determined based on error recovery current state
+ */
PE_FLAGS_PROTOCOL_ERROR_FN,
-/* Set if we are in Modal Operation */
+ /* Set if we are in Modal Operation */
PE_FLAGS_MODAL_OPERATION_FN,
-/* A message we requested to be sent has been transmitted */
+ /* A message we requested to be sent has been transmitted */
PE_FLAGS_TX_COMPLETE_FN,
-/* A message sent by a port partner has been received */
+ /* A message sent by a port partner has been received */
PE_FLAGS_MSG_RECEIVED_FN,
-/* A hard reset has been requested but has not been sent, not currently used */
+ /* A hard reset has been requested but has not been sent, not currently
+ used */
PE_FLAGS_HARD_RESET_PENDING_FN,
-/* Port partner sent a Wait message. Wait before we resend our message */
+ /* Port partner sent a Wait message. Wait before we resend our message
+ */
PE_FLAGS_WAIT_FN,
-/* An explicit contract is in place with our port partner */
+ /* An explicit contract is in place with our port partner */
PE_FLAGS_EXPLICIT_CONTRACT_FN,
-/* Waiting for Sink Capabailities timed out. Used for retry error handling */
+ /* Waiting for Sink Capabailities timed out. Used for retry error
+ handling */
PE_FLAGS_SNK_WAIT_CAP_TIMEOUT_FN,
-/* Power Supply voltage/current transition timed out */
+ /* Power Supply voltage/current transition timed out */
PE_FLAGS_PS_TRANSITION_TIMEOUT_FN,
-/* Flag to note current Atomic Message Sequence is interruptible */
+ /* Flag to note current Atomic Message Sequence is interruptible */
PE_FLAGS_INTERRUPTIBLE_AMS_FN,
-/* Flag to note Power Supply reset has completed */
+ /* Flag to note Power Supply reset has completed */
PE_FLAGS_PS_RESET_COMPLETE_FN,
-/* VCONN swap operation has completed */
+ /* VCONN swap operation has completed */
PE_FLAGS_VCONN_SWAP_COMPLETE_FN,
-/* Flag to note no more setup VDMs (discovery, etc.) should be sent */
+ /* Flag to note no more setup VDMs (discovery, etc.) should be sent */
PE_FLAGS_VDM_SETUP_DONE_FN,
-/* Flag to note PR Swap just completed for Startup entry */
+ /* Flag to note PR Swap just completed for Startup entry */
PE_FLAGS_PR_SWAP_COMPLETE_FN,
-/* Flag to note Port Discovery port partner replied with BUSY */
+ /* Flag to note Port Discovery port partner replied with BUSY */
PE_FLAGS_VDM_REQUEST_BUSY_FN,
-/* Flag to note Port Discovery port partner replied with NAK */
+ /* Flag to note Port Discovery port partner replied with NAK */
PE_FLAGS_VDM_REQUEST_NAKED_FN,
-/* Flag to note FRS/PRS context in shared state machine path */
+ /* Flag to note FRS/PRS context in shared state machine path */
PE_FLAGS_FAST_ROLE_SWAP_PATH_FN,
-/* Flag to note if FRS listening is enabled */
+ /* Flag to note if FRS listening is enabled */
PE_FLAGS_FAST_ROLE_SWAP_ENABLED_FN,
-/* Flag to note TCPC passed on FRS signal from port partner */
+ /* Flag to note TCPC passed on FRS signal from port partner */
PE_FLAGS_FAST_ROLE_SWAP_SIGNALED_FN,
-/* TODO: POLICY decision: Triggers a DR SWAP attempt from UFP to DFP */
+ /* TODO: POLICY decision: Triggers a DR SWAP attempt from UFP to DFP */
PE_FLAGS_DR_SWAP_TO_DFP_FN,
-/*
- * TODO: POLICY decision
- * Flag to trigger a message resend after receiving a WAIT from port partner
- */
+ /*
+ * TODO: POLICY decision
+ * Flag to trigger a message resend after receiving a WAIT from port
+ * partner
+ */
PE_FLAGS_WAITING_PR_SWAP_FN,
-/* FLAG is set when an AMS is initiated locally. ie. AP requested a PR_SWAP */
+ /* FLAG is set when an AMS is initiated locally. ie. AP requested a
+ PR_SWAP */
PE_FLAGS_LOCALLY_INITIATED_AMS_FN,
-/* Flag to note the first message sent in PE_SRC_READY and PE_SNK_READY */
+ /* Flag to note the first message sent in PE_SRC_READY and PE_SNK_READY
+ */
PE_FLAGS_FIRST_MSG_FN,
-/* Flag to continue a VDM request if it was interrupted */
+ /* Flag to continue a VDM request if it was interrupted */
PE_FLAGS_VDM_REQUEST_CONTINUE_FN,
-/* TODO: POLICY decision: Triggers a Vconn SWAP attempt to on */
+ /* TODO: POLICY decision: Triggers a Vconn SWAP attempt to on */
PE_FLAGS_VCONN_SWAP_TO_ON_FN,
-/* FLAG to track that VDM request to port partner timed out */
+ /* FLAG to track that VDM request to port partner timed out */
PE_FLAGS_VDM_REQUEST_TIMEOUT_FN,
-/* FLAG to note message was discarded due to incoming message */
+ /* FLAG to note message was discarded due to incoming message */
PE_FLAGS_MSG_DISCARDED_FN,
-/* FLAG to note that hard reset can't be performed due to battery low */
+ /* FLAG to note that hard reset can't be performed due to battery low */
PE_FLAGS_SNK_WAITING_BATT_FN,
-/* FLAG to note that a data reset is complete */
+ /* FLAG to note that a data reset is complete */
PE_FLAGS_DATA_RESET_COMPLETE_FN,
-/* Waiting for SRC to SNK settle time */
+ /* Waiting for SRC to SNK settle time */
PE_FLAGS_SRC_SNK_SETTLE_FN,
-/* Last element */
+ /* Last element */
PE_FLAGS_COUNT
};
diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c
index 805e6dfcd8..b1843da6eb 100644
--- a/common/usbc/usb_prl_sm.c
+++ b/common/usbc/usb_prl_sm.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
#include "battery.h"
#include "battery_smart.h"
#include "board.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "chipset.h"
@@ -33,8 +34,8 @@
#include "vpd_api.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -46,27 +47,25 @@
#undef DEBUG_PRINT_FLAG_NAMES
#ifdef DEBUG_PRINT_FLAG_NAMES
-__maybe_unused static void print_flag(const char *group,
- int set_or_clear,
+__maybe_unused static void print_flag(const char *group, int set_or_clear,
int flag);
-#define SET_FLAG(group, flags, flag) \
- do { \
- print_flag(group, 1, flag); \
- atomic_or(flags, (flag)); \
+#define SET_FLAG(group, flags, flag) \
+ do { \
+ print_flag(group, 1, flag); \
+ atomic_or(flags, (flag)); \
} while (0)
-#define CLR_FLAG(group, flags, flag) \
- do { \
- int before = *flags; \
- atomic_clear_bits(flags, (flag)); \
- if (*flags != before) \
- print_flag(group, 0, flag); \
+#define CLR_FLAG(group, flags, flag) \
+ do { \
+ int before = *flags; \
+ atomic_clear_bits(flags, (flag)); \
+ if (*flags != before) \
+ print_flag(group, 0, flag); \
} while (0)
#else
#define SET_FLAG(group, flags, flag) atomic_or(flags, (flag))
#define CLR_FLAG(group, flags, flag) atomic_clear_bits(flags, (flag))
#endif
-
#define RCH_SET_FLAG(port, flag) SET_FLAG("RCH", &rch[port].flags, (flag))
#define RCH_CLR_FLAG(port, flag) CLR_FLAG("RCH", &rch[port].flags, (flag))
#define RCH_CHK_FLAG(port, flag) (rch[port].flags & (flag))
@@ -98,34 +97,34 @@ __maybe_unused static void print_flag(const char *group,
* different meanings in each state machine.
*/
/* Flag to note message transmission completed */
-#define PRL_FLAGS_TX_COMPLETE BIT(0)
+#define PRL_FLAGS_TX_COMPLETE BIT(0)
/* Flag to note that PRL requested to set SINK_NG CC state */
-#define PRL_FLAGS_SINK_NG BIT(1)
+#define PRL_FLAGS_SINK_NG BIT(1)
/* Flag to note PRL waited for SINK_OK CC state before transmitting */
-#define PRL_FLAGS_WAIT_SINK_OK BIT(2)
+#define PRL_FLAGS_WAIT_SINK_OK BIT(2)
/* Flag to note transmission error occurred */
-#define PRL_FLAGS_TX_ERROR BIT(3)
+#define PRL_FLAGS_TX_ERROR BIT(3)
/* Flag to note PE triggered a hard reset */
-#define PRL_FLAGS_PE_HARD_RESET BIT(4)
+#define PRL_FLAGS_PE_HARD_RESET BIT(4)
/* Flag to note hard reset has completed */
-#define PRL_FLAGS_HARD_RESET_COMPLETE BIT(5)
+#define PRL_FLAGS_HARD_RESET_COMPLETE BIT(5)
/* Flag to note port partner sent a hard reset */
#define PRL_FLAGS_PORT_PARTNER_HARD_RESET BIT(6)
/*
* Flag to note a message transmission has been requested. It is only cleared
* when we send the message to the TCPC layer.
*/
-#define PRL_FLAGS_MSG_XMIT BIT(7)
+#define PRL_FLAGS_MSG_XMIT BIT(7)
/* Flag to note a message was received */
-#define PRL_FLAGS_MSG_RECEIVED BIT(8)
+#define PRL_FLAGS_MSG_RECEIVED BIT(8)
/* Flag to note aborting current TX message, not currently set */
-#define PRL_FLAGS_ABORT BIT(9)
+#define PRL_FLAGS_ABORT BIT(9)
/* Flag to note current TX message uses chunking */
-#define PRL_FLAGS_CHUNKING BIT(10)
+#define PRL_FLAGS_CHUNKING BIT(10)
struct bit_name {
- int value;
- const char *name;
+ int value;
+ const char *name;
};
static __const_data const struct bit_name flag_bit_names[] = {
@@ -136,17 +135,15 @@ static __const_data const struct bit_name flag_bit_names[] = {
{ PRL_FLAGS_PE_HARD_RESET, "PRL_FLAGS_PE_HARD_RESET" },
{ PRL_FLAGS_HARD_RESET_COMPLETE, "PRL_FLAGS_HARD_RESET_COMPLETE" },
{ PRL_FLAGS_PORT_PARTNER_HARD_RESET,
- "PRL_FLAGS_PORT_PARTNER_HARD_RESET" },
+ "PRL_FLAGS_PORT_PARTNER_HARD_RESET" },
{ PRL_FLAGS_MSG_XMIT, "PRL_FLAGS_MSG_XMIT" },
{ PRL_FLAGS_MSG_RECEIVED, "PRL_FLAGS_MSG_RECEIVED" },
{ PRL_FLAGS_ABORT, "PRL_FLAGS_ABORT" },
{ PRL_FLAGS_CHUNKING, "PRL_FLAGS_CHUNKING" },
};
-__maybe_unused static void print_bits(const char *group,
- const char *desc,
- int value,
- const struct bit_name *names,
+__maybe_unused static void print_bits(const char *group, const char *desc,
+ int value, const struct bit_name *names,
int names_size)
{
int i;
@@ -162,8 +159,7 @@ __maybe_unused static void print_bits(const char *group,
CPRINTF("\n");
}
-__maybe_unused static void print_flag(const char *group,
- int set_or_clear,
+__maybe_unused static void print_flag(const char *group, int set_or_clear,
int flag)
{
print_bits(group, set_or_clear ? "Set" : "Clr", flag, flag_bit_names,
@@ -189,6 +185,8 @@ __maybe_unused static void print_flag(const char *group,
*/
#ifdef CONFIG_USB_PD_DEBUG_LEVEL
static const enum debug_level prl_debug_level = CONFIG_USB_PD_DEBUG_LEVEL;
+#elif defined(CONFIG_USB_PD_INITIAL_DEBUG_LEVEL)
+static enum debug_level prl_debug_level = CONFIG_USB_PD_INITIAL_DEBUG_LEVEL;
#else
static enum debug_level prl_debug_level = DEBUG_LEVEL_1;
#endif
@@ -238,7 +236,7 @@ enum usb_tch_state {
TCH_REPORT_ERROR,
};
-static const char * const prl_tx_state_names[] = {
+static const char *const prl_tx_state_names[] = {
[PRL_TX_PHY_LAYER_RESET] = "PRL_TX_PHY_LAYER_RESET",
[PRL_TX_WAIT_FOR_MESSAGE_REQUEST] = "PRL_TX_WAIT_FOR_MESSAGE_REQUEST",
[PRL_TX_LAYER_RESET_FOR_TRANSMIT] = "PRL_TX_LAYER_RESET_FOR_TRANSMIT",
@@ -250,18 +248,18 @@ static const char * const prl_tx_state_names[] = {
[PRL_TX_DISCARD_MESSAGE] = "PRL_TX_DISCARD_MESSAGE",
};
-static const char * const prl_hr_state_names[] = {
+static const char *const prl_hr_state_names[] = {
[PRL_HR_WAIT_FOR_REQUEST] = "PRL_HR_WAIT_FOR_REQUEST",
[PRL_HR_RESET_LAYER] = "PRL_HR_RESET_LAYER",
- [PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE]
- = "PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE",
- [PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE]
- = "PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE",
+ [PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE] =
+ "PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE",
+ [PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE] =
+ "PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE",
};
-__maybe_unused static const char * const rch_state_names[] = {
- [RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER]
- = "RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER",
+__maybe_unused static const char *const rch_state_names[] = {
+ [RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER] =
+ "RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER",
[RCH_PASS_UP_MESSAGE] = "RCH_PASS_UP_MESSAGE",
[RCH_PROCESSING_EXTENDED_MESSAGE] = "RCH_PROCESSING_EXTENDED_MESSAGE",
[RCH_REQUESTING_CHUNK] = "RCH_REQUESTING_CHUNK",
@@ -269,11 +267,11 @@ __maybe_unused static const char * const rch_state_names[] = {
[RCH_REPORT_ERROR] = "RCH_REPORT_ERROR",
};
-__maybe_unused static const char * const tch_state_names[] = {
- [TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE]
- = "TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE",
- [TCH_WAIT_FOR_TRANSMISSION_COMPLETE]
- = "TCH_WAIT_FOR_TRANSMISSION_COMPLETE",
+__maybe_unused static const char *const tch_state_names[] = {
+ [TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE] =
+ "TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE",
+ [TCH_WAIT_FOR_TRANSMISSION_COMPLETE] =
+ "TCH_WAIT_FOR_TRANSMISSION_COMPLETE",
[TCH_CONSTRUCT_CHUNKED_MESSAGE] = "TCH_CONSTRUCT_CHUNKED_MESSAGE",
[TCH_SENDING_CHUNKED_MESSAGE] = "TCH_SENDING_CHUNKED_MESSAGE",
[TCH_WAIT_CHUNK_REQUEST] = "TCH_WAIT_CHUNK_REQUEST",
@@ -380,12 +378,12 @@ GEN_NOT_SUPPORTED(PRL_TX_SNK_START_AMS);
GEN_NOT_SUPPORTED(RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
#define RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER \
- RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER_NOT_SUPPORTED
+ RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER_NOT_SUPPORTED
GEN_NOT_SUPPORTED(RCH_PASS_UP_MESSAGE);
#define RCH_PASS_UP_MESSAGE RCH_PASS_UP_MESSAGE_NOT_SUPPORTED
GEN_NOT_SUPPORTED(RCH_PROCESSING_EXTENDED_MESSAGE);
#define RCH_PROCESSING_EXTENDED_MESSAGE \
- RCH_PROCESSING_EXTENDED_MESSAGE_NOT_SUPPORTED
+ RCH_PROCESSING_EXTENDED_MESSAGE_NOT_SUPPORTED
GEN_NOT_SUPPORTED(RCH_REQUESTING_CHUNK);
#define RCH_REQUESTING_CHUNK RCH_REQUESTING_CHUNK_NOT_SUPPORTED
GEN_NOT_SUPPORTED(RCH_WAITING_CHUNK);
@@ -395,13 +393,13 @@ GEN_NOT_SUPPORTED(RCH_REPORT_ERROR);
GEN_NOT_SUPPORTED(TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
#define TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE \
- TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE_NOT_SUPPORTED
+ TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE_NOT_SUPPORTED
GEN_NOT_SUPPORTED(TCH_WAIT_FOR_TRANSMISSION_COMPLETE);
#define TCH_WAIT_FOR_TRANSMISSION_COMPLETE \
- TCH_WAIT_FOR_TRANSMISSION_COMPLETE_NOT_SUPPORTED
+ TCH_WAIT_FOR_TRANSMISSION_COMPLETE_NOT_SUPPORTED
GEN_NOT_SUPPORTED(TCH_CONSTRUCT_CHUNKED_MESSAGE);
#define TCH_CONSTRUCT_CHUNKED_MESSAGE \
- TCH_CONSTRUCT_CHUNKED_MESSAGE_NOT_SUPPORTED
+ TCH_CONSTRUCT_CHUNKED_MESSAGE_NOT_SUPPORTED
GEN_NOT_SUPPORTED(TCH_SENDING_CHUNKED_MESSAGE);
#define TCH_SENDING_CHUNKED_MESSAGE TCH_SENDING_CHUNKED_MESSAGE_NOT_SUPPORTED
GEN_NOT_SUPPORTED(TCH_WAIT_CHUNK_REQUEST);
@@ -435,7 +433,7 @@ static void print_current_prl_tx_state(const int port)
{
if (prl_debug_level >= DEBUG_LEVEL_3)
CPRINTS("C%d: %s", port,
- prl_tx_state_names[prl_tx_get_state(port)]);
+ prl_tx_state_names[prl_tx_get_state(port)]);
}
/* Set the hard reset statemachine to a new state. */
@@ -456,7 +454,7 @@ static void print_current_prl_hr_state(const int port)
{
if (prl_debug_level >= DEBUG_LEVEL_3)
CPRINTS("C%d: %s", port,
- prl_hr_state_names[prl_hr_get_state(port)]);
+ prl_hr_state_names[prl_hr_get_state(port)]);
}
/* Set the chunked Rx statemachine to a new state. */
@@ -477,8 +475,7 @@ test_export_static enum usb_rch_state rch_get_state(const int port)
static void print_current_rch_state(const int port)
{
if (prl_debug_level >= DEBUG_LEVEL_3)
- CPRINTS("C%d: %s", port,
- rch_state_names[rch_get_state(port)]);
+ CPRINTS("C%d: %s", port, rch_state_names[rch_get_state(port)]);
}
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
@@ -503,12 +500,10 @@ test_export_static enum usb_tch_state tch_get_state(const int port)
static void print_current_tch_state(const int port)
{
if (prl_debug_level >= DEBUG_LEVEL_3)
- CPRINTS("C%d: %s", port,
- tch_state_names[tch_get_state(port)]);
+ CPRINTS("C%d: %s", port, tch_state_names[tch_get_state(port)]);
}
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
-
timestamp_t prl_get_tcpc_tx_success_ts(int port)
{
return tcpc_tx_success_ts[port];
@@ -578,10 +573,8 @@ static void prl_init(int port)
prl_hr[port].flags = 0;
- for (i = 0; i < NUM_SOP_STAR_TYPES; i++) {
- prl_rx[port].msg_id[i] = -1;
- prl_tx[port].msg_id_counter[i] = 0;
- }
+ for (i = 0; i < NUM_SOP_STAR_TYPES; i++)
+ prl_reset_msg_ids(port, i);
pd_timer_disable_range(port, PR_TIMER_RANGE);
@@ -605,9 +598,8 @@ bool prl_is_busy(int port)
{
#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES
return rch_get_state(port) !=
- RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER ||
- tch_get_state(port) !=
- TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE;
+ RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER ||
+ tch_get_state(port) != TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE;
#else
return false;
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
@@ -626,9 +618,8 @@ void prl_hard_reset_complete(int port)
task_wake(PD_PORT_TO_TASK_ID(port));
}
-void prl_send_ctrl_msg(int port,
- enum tcpci_msg_type type,
- enum pd_ctrl_msg_type msg)
+void prl_send_ctrl_msg(int port, enum tcpci_msg_type type,
+ enum pd_ctrl_msg_type msg)
{
pdmsg[port].xmit_type = type;
pdmsg[port].msg_type = msg;
@@ -646,9 +637,8 @@ void prl_send_ctrl_msg(int port,
task_wake(PD_PORT_TO_TASK_ID(port));
}
-void prl_send_data_msg(int port,
- enum tcpci_msg_type type,
- enum pd_data_msg_type msg)
+void prl_send_data_msg(int port, enum tcpci_msg_type type,
+ enum pd_data_msg_type msg)
{
pdmsg[port].xmit_type = type;
pdmsg[port].msg_type = msg;
@@ -666,9 +656,8 @@ void prl_send_data_msg(int port,
}
#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES
-void prl_send_ext_data_msg(int port,
- enum tcpci_msg_type type,
- enum pd_ext_msg_type msg)
+void prl_send_ext_data_msg(int port, enum tcpci_msg_type type,
+ enum pd_ext_msg_type msg)
{
pdmsg[port].xmit_type = type;
pdmsg[port].msg_type = msg;
@@ -736,11 +725,9 @@ void prl_run(int port, int evt, int en)
* reset.
*/
if (prl_hr_get_state(port) == PRL_HR_WAIT_FOR_REQUEST) {
-
/* Run Protocol Layer Message Reception */
prl_rx_wait_for_phy_message(port, evt);
-
if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) {
/*
* Run RX Chunked state machine after prl_rx.
@@ -772,8 +759,7 @@ void prl_run(int port, int evt, int en)
}
}
-void prl_set_rev(int port, enum tcpci_msg_type type,
- enum pd_rev_type rev)
+void prl_set_rev(int port, enum tcpci_msg_type type, enum pd_rev_type rev)
{
/* We only store revisions for SOP* types. */
ASSERT(type < NUM_SOP_STAR_TYPES);
@@ -789,6 +775,12 @@ enum pd_rev_type prl_get_rev(int port, enum tcpci_msg_type type)
return pdmsg[port].rev[type];
}
+void prl_reset_msg_ids(int port, enum tcpci_msg_type type)
+{
+ prl_tx[port].msg_id_counter[type] = 0;
+ prl_rx[port].msg_id[type] = -1;
+}
+
static void prl_copy_msg_to_buffer(int port)
{
/*
@@ -814,7 +806,7 @@ static void prl_copy_msg_to_buffer(int port)
/* Copy message to chunked buffer */
memset((uint8_t *)pdmsg[port].tx_chk_buf, 0, CHK_BUF_SIZE_BYTES);
memcpy((uint8_t *)pdmsg[port].tx_chk_buf, (uint8_t *)tx_emsg[port].buf,
- tx_emsg[port].len);
+ tx_emsg[port].len);
/*
* Pad length to 4-byte boundary and
* convert to number of 32-bit objects.
@@ -828,8 +820,8 @@ static void prl_copy_msg_to_buffer(int port)
static __maybe_unused int pdmsg_xmit_type_is_rev30(const int port)
{
if (IS_ENABLED(CONFIG_USB_PD_REV30))
- return ((pdmsg[port].xmit_type < NUM_SOP_STAR_TYPES)
- && (prl_get_rev(port, pdmsg[port].xmit_type) == PD_REV30));
+ return ((pdmsg[port].xmit_type < NUM_SOP_STAR_TYPES) &&
+ (prl_get_rev(port, pdmsg[port].xmit_type) == PD_REV30));
else
return 0;
}
@@ -846,8 +838,7 @@ static void prl_tx_phy_layer_reset_entry(const int port)
{
print_current_prl_tx_state(port);
- if (IS_ENABLED(CONFIG_USB_CTVPD)
- || IS_ENABLED(CONFIG_USB_VPD)) {
+ if (IS_ENABLED(CONFIG_USB_CTVPD) || IS_ENABLED(CONFIG_USB_VPD)) {
vpd_rx_enable(pd_is_connected(port));
} else {
/* Note: can't clear PHY messages due to TCPC architecture */
@@ -884,7 +875,7 @@ static void prl_tx_wait_for_message_request_run(const int port)
if (IS_ENABLED(CONFIG_USB_PD_REV30) && is_sop_rev30(port) &&
pe_in_local_ams(port)) {
if (PRL_TX_CHK_FLAG(port, PRL_FLAGS_SINK_NG |
- PRL_FLAGS_WAIT_SINK_OK)) {
+ PRL_FLAGS_WAIT_SINK_OK)) {
/*
* If we are already in an AMS then allow the
* multi-message AMS to continue, even if we
@@ -915,7 +906,7 @@ static void prl_tx_wait_for_message_request_run(const int port)
* Soft Reset Message Message pending
*/
if ((pdmsg[port].msg_type == PD_CTRL_SOFT_RESET) &&
- (tx_emsg[port].len == 0)) {
+ (tx_emsg[port].len == 0)) {
set_state_prl_tx(port, PRL_TX_LAYER_RESET_FOR_TRANSMIT);
}
/*
@@ -1031,16 +1022,14 @@ static void prl_tx_layer_reset_for_transmit_entry(const int port)
* From section 6.3.13 Soft Reset Message in the USB PD 3.0
* v2.0 spec, Soft_Reset Message Shall be targeted at a
* specific entity depending on the type of SOP* Packet used.
- */
- prl_tx[port].msg_id_counter[pdmsg[port].xmit_type] = 0;
-
- /*
+ *
+ *
* From section 6.11.2.3.2, the MessageID should be cleared
* from the PRL_Rx_Layer_Reset_for_Receive state. However, we
* don't implement a full state machine for PRL RX states so
* clear the MessageID here.
*/
- prl_rx[port].msg_id[pdmsg[port].xmit_type] = -1;
+ prl_reset_msg_ids(port, pdmsg[port].xmit_type);
}
}
@@ -1063,23 +1052,21 @@ static uint32_t get_sop_star_header(const int port)
#endif
/* SOP vs SOP'/SOP" headers are different. Replace fields as needed */
- return PD_HEADER(
- pdmsg[port].msg_type,
- is_sop_packet ?
- pd_get_power_role(port) : tc_get_cable_plug(port),
- is_sop_packet ?
- pd_get_data_role(port) : 0,
- prl_tx[port].msg_id_counter[pdmsg[port].xmit_type],
- pdmsg[port].data_objs,
- pdmsg[port].rev[pdmsg[port].xmit_type],
- ext);
+ return PD_HEADER(pdmsg[port].msg_type,
+ is_sop_packet ? pd_get_power_role(port) :
+ tc_get_cable_plug(port),
+ is_sop_packet ? pd_get_data_role(port) : 0,
+ prl_tx[port].msg_id_counter[pdmsg[port].xmit_type],
+ pdmsg[port].data_objs,
+ pdmsg[port].rev[pdmsg[port].xmit_type], ext);
}
static void prl_tx_construct_message(const int port)
{
/* The header is unused for hard reset, etc. */
const uint32_t header = pdmsg[port].xmit_type < NUM_SOP_STAR_TYPES ?
- get_sop_star_header(port) : 0;
+ get_sop_star_header(port) :
+ 0;
/* Save SOP* so the correct msg_id_counter can be incremented */
prl_tx[port].last_xmit_type = pdmsg[port].xmit_type;
@@ -1199,7 +1186,7 @@ static void prl_tx_src_pending_run(const int port)
* SinkTxTimer timeout
*/
if ((tx_emsg[port].len == 0) &&
- (pdmsg[port].msg_type == PD_CTRL_SOFT_RESET)) {
+ (pdmsg[port].msg_type == PD_CTRL_SOFT_RESET)) {
set_state_prl_tx(port, PRL_TX_LAYER_RESET_FOR_TRANSMIT);
}
/* Message pending (except Soft Reset) &
@@ -1259,7 +1246,7 @@ static void prl_tx_snk_pending_run(const int port)
* Rp = SinkTxOk
*/
if ((pdmsg[port].msg_type == PD_CTRL_SOFT_RESET) &&
- (tx_emsg[port].len == 0)) {
+ (tx_emsg[port].len == 0)) {
set_state_prl_tx(port, PRL_TX_LAYER_RESET_FOR_TRANSMIT);
}
/*
@@ -1305,7 +1292,7 @@ static void prl_hr_wait_for_request_entry(const int port)
static void prl_hr_wait_for_request_run(const int port)
{
if (PRL_HR_CHK_FLAG(port, PRL_FLAGS_PE_HARD_RESET |
- PRL_FLAGS_PORT_PARTNER_HARD_RESET))
+ PRL_FLAGS_PORT_PARTNER_HARD_RESET))
set_state_prl_hr(port, PRL_HR_RESET_LAYER);
}
@@ -1327,13 +1314,11 @@ static void prl_hr_reset_layer_entry(const int port)
/* Hard reset resets messageIDCounters for all TX types */
for (i = 0; i < NUM_SOP_STAR_TYPES; i++) {
- prl_rx[port].msg_id[i] = -1;
- prl_tx[port].msg_id_counter[i] = 0;
+ prl_reset_msg_ids(port, i);
}
/* Disable RX */
- if (IS_ENABLED(CONFIG_USB_CTVPD) ||
- IS_ENABLED(CONFIG_USB_VPD))
+ if (IS_ENABLED(CONFIG_USB_CTVPD) || IS_ENABLED(CONFIG_USB_VPD))
vpd_rx_enable(0);
else
tcpm_set_rx_enable(port, 0);
@@ -1396,8 +1381,7 @@ static void prl_hr_wait_for_phy_hard_reset_complete_entry(const int port)
print_current_prl_hr_state(port);
/* Start HardResetCompleteTimer */
- pd_timer_enable(port, PR_TIMER_HARD_RESET_COMPLETE,
- PD_T_PS_HARD_RESET);
+ pd_timer_enable(port, PR_TIMER_HARD_RESET_COMPLETE, PD_T_PS_HARD_RESET);
}
static void prl_hr_wait_for_phy_hard_reset_complete_run(const int port)
@@ -1455,11 +1439,11 @@ static void copy_chunk_to_ext(int port)
{
/* Calculate number of bytes */
pdmsg[port].num_bytes_received =
- (PD_HEADER_CNT(rx_emsg[port].header) * 4);
+ (PD_HEADER_CNT(rx_emsg[port].header) * 4);
/* Copy chunk into extended message */
memcpy((uint8_t *)rx_emsg[port].buf, (uint8_t *)pdmsg[port].rx_chk_buf,
- pdmsg[port].num_bytes_received);
+ pdmsg[port].num_bytes_received);
/* Set extended message length */
rx_emsg[port].len = pdmsg[port].num_bytes_received;
@@ -1491,10 +1475,10 @@ static void rch_wait_for_message_from_protocol_layer_run(const int port)
* Are we communicating with a PD3.0 device and is
* this an extended message?
*/
- if (pdmsg_xmit_type_is_rev30(port)
- && PD_HEADER_EXT(rx_emsg[port].header)) {
+ if (pdmsg_xmit_type_is_rev30(port) &&
+ PD_HEADER_EXT(rx_emsg[port].header)) {
uint16_t exhdr =
- GET_EXT_HEADER(*pdmsg[port].rx_chk_buf);
+ GET_EXT_HEADER(*pdmsg[port].rx_chk_buf);
uint8_t chunked = PD_EXT_HEADER_CHUNKED(exhdr);
/*
@@ -1502,7 +1486,7 @@ static void rch_wait_for_message_from_protocol_layer_run(const int port)
* (Chunking = 1 & Chunked = 1)
*/
if ((RCH_CHK_FLAG(port, PRL_FLAGS_CHUNKING)) &&
- chunked) {
+ chunked) {
/*
* RCH_Processing_Extended_Message first chunk
* entry processing embedded here
@@ -1524,7 +1508,7 @@ static void rch_wait_for_message_from_protocol_layer_run(const int port)
* (Chunking = 0 & Chunked = 0))
*/
else if (!RCH_CHK_FLAG(port, PRL_FLAGS_CHUNKING) &&
- !chunked) {
+ !chunked) {
/* Copy chunk to extended buffer */
copy_chunk_to_ext(port);
set_state_rch(port, RCH_PASS_UP_MESSAGE);
@@ -1602,8 +1586,8 @@ static void rch_processing_extended_message_run(const int port)
byte_num = PD_MAX_EXTENDED_MSG_CHUNK_LEN;
/* Make sure extended message buffer does not overflow */
- if (pdmsg[port].num_bytes_received +
- byte_num > EXTENDED_BUFFER_SIZE) {
+ if (pdmsg[port].num_bytes_received + byte_num >
+ EXTENDED_BUFFER_SIZE) {
rch[port].error = ERR_RCH_CHUNKED;
set_state_rch(port, RCH_REPORT_ERROR);
return;
@@ -1612,9 +1596,8 @@ static void rch_processing_extended_message_run(const int port)
/* Append data */
/* Add 2 to chk_buf to skip over extended message header */
memcpy(((uint8_t *)rx_emsg[port].buf +
- pdmsg[port].num_bytes_received),
- (uint8_t *)pdmsg[port].rx_chk_buf + 2,
- byte_num);
+ pdmsg[port].num_bytes_received),
+ (uint8_t *)pdmsg[port].rx_chk_buf + 2, byte_num);
/* increment chunk number expected */
pdmsg[port].chunk_number_expected++;
/* adjust num bytes received */
@@ -1623,7 +1606,7 @@ static void rch_processing_extended_message_run(const int port)
/* Was that the last chunk? */
if (pdmsg[port].num_bytes_received >= data_size) {
rx_emsg[port].len = pdmsg[port].num_bytes_received;
- /* Pass Message to Policy Engine */
+ /* Pass Message to Policy Engine */
set_state_rch(port, RCH_PASS_UP_MESSAGE);
}
/*
@@ -1652,11 +1635,11 @@ static void rch_requesting_chunk_entry(const int port)
* Send Chunk Request to Protocol Layer
* with chunk number = Chunk_Number_Expected
*/
- pdmsg[port].tx_chk_buf[0] = PD_EXT_HEADER(
- pdmsg[port].chunk_number_expected,
- 1, /* Request Chunk */
- 0 /* Data Size */
- );
+ pdmsg[port].tx_chk_buf[0] =
+ PD_EXT_HEADER(pdmsg[port].chunk_number_expected, 1, /* Request
+ Chunk */
+ 0 /* Data Size */
+ );
pdmsg[port].data_objs = 1;
pdmsg[port].ext = 1;
@@ -1827,16 +1810,15 @@ static void tch_wait_for_message_request_from_pe_run(const int port)
* Discard the Message
*/
if (rch_get_state(port) !=
- RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER) {
+ RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER) {
tch[port].error = ERR_TCH_XMIT;
set_state_tch(port, TCH_REPORT_ERROR);
} else {
/*
* Extended Message Request & Chunking
*/
- if (pdmsg_xmit_type_is_rev30(port)
- && pdmsg[port].ext
- && TCH_CHK_FLAG(port, PRL_FLAGS_CHUNKING)) {
+ if (pdmsg_xmit_type_is_rev30(port) && pdmsg[port].ext &&
+ TCH_CHK_FLAG(port, PRL_FLAGS_CHUNKING)) {
/*
* NOTE: TCH_Prepare_To_Send_Chunked_Message
* embedded here.
@@ -1855,7 +1837,8 @@ static void tch_wait_for_message_request_from_pe_run(const int port)
/* Pass Message to Protocol Layer */
PRL_TX_SET_FLAG(port, PRL_FLAGS_MSG_XMIT);
- set_state_tch(port,
+ set_state_tch(
+ port,
TCH_WAIT_FOR_TRANSMISSION_COMPLETE);
}
}
@@ -1900,7 +1883,7 @@ static void tch_wait_for_transmission_complete_run(const int port)
* the tx message was sent successfully.
*/
if (TCH_CHK_FLAG(port, PRL_FLAGS_MSG_RECEIVED) &&
- prl_tx[port].xmit_status != TCPC_TX_COMPLETE_SUCCESS) {
+ prl_tx[port].xmit_status != TCPC_TX_COMPLETE_SUCCESS) {
TCH_CLR_FLAG(port, PRL_FLAGS_MSG_RECEIVED);
set_state_tch(port, TCH_MESSAGE_RECEIVED);
return;
@@ -1937,8 +1920,9 @@ static void tch_construct_chunked_message_entry(const int port)
num = PD_MAX_EXTENDED_MSG_CHUNK_LEN;
/* Set the chunks extended header */
- *ext_hdr = PD_EXT_HEADER(pdmsg[port].chunk_number_to_send,
- 0, /* Chunk Request */
+ *ext_hdr = PD_EXT_HEADER(pdmsg[port].chunk_number_to_send, 0, /* Chunk
+ Request
+ */
tx_emsg[port].len);
/* Copy the message chunk into chk_buf */
@@ -2036,7 +2020,8 @@ static void tch_wait_chunk_request_run(const int port)
*/
if (PD_EXT_HEADER_CHUNK_NUM(exthdr) ==
pdmsg[port].chunk_number_to_send) {
- set_state_tch(port,
+ set_state_tch(
+ port,
TCH_CONSTRUCT_CHUNKED_MESSAGE);
}
/*
@@ -2111,8 +2096,6 @@ static void tch_message_sent_entry(const int port)
return;
}
-
-
set_state_tch(port, TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
}
@@ -2136,7 +2119,6 @@ static void tch_report_error_entry(const int port)
return;
}
-
set_state_tch(port, TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
}
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
@@ -2176,7 +2158,7 @@ static void prl_rx_wait_for_phy_message(const int port, int evt)
/* dump received packet content (only dump ping at debug level MAX) */
if ((prl_debug_level >= DEBUG_LEVEL_2 && type != PD_CTRL_PING) ||
- prl_debug_level >= DEBUG_LEVEL_3) {
+ prl_debug_level >= DEBUG_LEVEL_3) {
int p;
ccprintf("C%d: RECV %04x/%d ", port, header, cnt);
@@ -2189,8 +2171,7 @@ static void prl_rx_wait_for_phy_message(const int port, int evt)
* Ignore messages sent to the cable from our
* port partner if we aren't Vconn powered device.
*/
- if (!IS_ENABLED(CONFIG_USB_CTVPD) &&
- !IS_ENABLED(CONFIG_USB_VPD) &&
+ if (!IS_ENABLED(CONFIG_USB_CTVPD) && !IS_ENABLED(CONFIG_USB_VPD) &&
PD_HEADER_GET_SOP(header) != TCPCI_MSG_SOP &&
PD_HEADER_PROLE(header) == PD_PLUG_FROM_DFP_UFP)
return;
@@ -2214,19 +2195,17 @@ static void prl_rx_wait_for_phy_message(const int port, int evt)
/* Handle incoming soft reset as special case */
if (cnt == 0 && type == PD_CTRL_SOFT_RESET) {
- /* Clear MessageIdCounter */
- prl_tx[port].msg_id_counter[prl_rx[port].sop] = 0;
- /* Clear stored MessageID value */
- prl_rx[port].msg_id[prl_rx[port].sop] = -1;
+ /* Clear MessageIdCounter and stored MessageID value. */
+ prl_reset_msg_ids(port, prl_rx[port].sop);
/* Soft Reset occurred */
set_state_prl_tx(port, PRL_TX_PHY_LAYER_RESET);
if (IS_ENABLED(CONFIG_USB_PD_EXTENDED_MESSAGES)) {
set_state_rch(port,
- RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
+ RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
set_state_tch(port,
- TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
+ TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
}
/*
@@ -2286,7 +2265,7 @@ static void prl_rx_wait_for_phy_message(const int port, int evt)
* tch_wait_for_message_request_from_pe has been run
*/
else if (tch_get_state(port) !=
- TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE ||
+ TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE ||
TCH_CHK_FLAG(port, PRL_FLAGS_MSG_XMIT)) {
/* NOTE: RTR_TX_CHUNKS State embedded here. */
/*
diff --git a/common/usbc/usb_retimer_fw_update.c b/common/usbc/usb_retimer_fw_update.c
index 1c3023db9b..3f9b1b4c72 100644
--- a/common/usbc/usb_retimer_fw_update.c
+++ b/common/usbc/usb_retimer_fw_update.c
@@ -1,10 +1,12 @@
-/* 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 <stdbool.h>
#include <stdint.h>
+
+#include "builtin/assert.h"
#include "compile_time_macros.h"
#include "console.h"
#include "hooks.h"
@@ -14,14 +16,20 @@
#include "usb_tc_sm.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
#else
#define CPRINTS(format, args...)
#define CPRINTF(format, args...)
#endif
/*
+ * Update retimer firmware of no device attached (NDA) ports
+ *
+ * https://docs.kernel.org/admin-guide/thunderbolt.html#
+ * upgrading-on-board-retimer-nvm-when-there-is-no-cable-connected
+ *
+ * On EC side:
* Retimer firmware update is initiated by AP.
* The operations requested by AP are:
* 0 - USB_RETIMER_FW_UPDATE_QUERY_PORT
@@ -43,10 +51,52 @@
* If 4/5/6/7 is received, TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN is
* set, PD task should be in suspended mode and process it.
*
+ * On host side:
+ * 1. Put NDA ports into offline mode.
+ * This forces retimer to power on, and requests EC to suspend
+ * PD port, set USB mux to USB, Safe then TBT.
+ * 2. Scan for retimers
+ * 3. Update retimer NVM firmware.
+ * 4. Authenticate.
+ * 5. Wait 5 or more seconds for retimer to come back.
+ * 6. Put NDA ports into online mode -- the functional state.
+ * This requestes EC to disconnect(set USB mux to 0), resume PD port.
+ *
+ * Error recovery:
+ * As mentioned above, to put port online, host sends two requests to EC
+ * 1. Disconnect USB MUX: USB_RETIMER_FW_UPDATE_DISCONNECT
+ * if step 1 is successful, then
+ * 2. Resume PD port: USB_RETIMER_FW_UPDATE_RESUME_PD
+ *
+ * If step 1 fails, host will not send step 2. This means no
+ * resume request from host. PD port stays in suspended state.
+ * EC needs an error recovery to resume PD port by itself.
+ *
+ * Below is how error recovery works:
+ * PD port state is set to RETIMER_ONLINE_REQUESTED when receives
+ * "Disconnect USB MUX"; a deferred call is set up too. When EC resumes
+ * port upon host's request, port state will be set to RETIMER_ONLINE;
+ * or port state stays RETIMER_ONLINE_REQUESTED if host doesn't request.
+ * By the time the deferrred call is fired, it will check if any port is
+ * still in RETIMER_ONLINE_REQUESTED state. If true, EC will put the
+ * port online by itself. That is, retry disconnect and unconditionally
+ * resume the port.
*/
#define SUSPEND 1
-#define RESUME 0
+#define RESUME 0
+
+enum retimer_port_state {
+ RETIMER_ONLINE,
+ RETIMER_OFFLINE,
+ RETIMER_ONLINE_REQUESTED
+};
+
+/*
+ * Two seconds buffer is added on top of required 5 seconds;
+ * to cover the time to disconnect and resume.
+ */
+#define RETIMTER_ONLINE_DELAY (7 * SECOND)
/* Track current port AP requested to update retimer firmware */
static int cur_port;
@@ -54,7 +104,7 @@ static int last_op; /* Operation received from AP via ACPI_WRITE */
/* Operation result returned to ACPI_READ */
static int last_result;
/* Track port state: SUSPEND or RESUME */
-static int port_state[CONFIG_USB_PD_PORT_MAX_COUNT];
+static enum retimer_port_state port_state[CONFIG_USB_PD_PORT_MAX_COUNT];
int usb_retimer_fw_update_get_result(void)
{
@@ -87,12 +137,13 @@ int usb_retimer_fw_update_get_result(void)
return result;
}
-static void retimer_fw_update_set_port_state(int port, int state)
+static void retimer_fw_update_set_port_state(int port,
+ enum retimer_port_state state)
{
port_state[port] = state;
}
-static int retimer_fw_update_get_port_state(int port)
+static enum retimer_port_state retimer_fw_update_get_port_state(int port)
{
return port_state[port];
}
@@ -101,16 +152,16 @@ static int retimer_fw_update_get_port_state(int port)
* @brief Suspend or resume PD task and update the state of the port.
*
* @param port PD port
- * @param state
- * SUSPEND: suspend PD task for firmware update; and set state to SUSPEND
- * RESUME: resume PD task after firmware update is done; and set state
- * to RESUME.
+ * @param suspend
+ * SUSPEND: suspend PD task; set state to RETIMER_OFFLINE
+ * RESUME: resume PD task; set state to RETIMER_ONLINE.
*
*/
-static void retimer_fw_update_port_handler(int port, int state)
+static void retimer_fw_update_port_handler(int port, bool suspend)
{
- pd_set_suspend(port, state);
- retimer_fw_update_set_port_state(port, state);
+ pd_set_suspend(port, suspend);
+ retimer_fw_update_set_port_state(
+ port, suspend == SUSPEND ? RETIMER_OFFLINE : RETIMER_ONLINE);
}
static void deferred_pd_suspend(void)
@@ -124,14 +175,74 @@ static inline mux_state_t retimer_fw_update_usb_mux_get(int port)
return usb_mux_get(port) & USB_RETIMER_FW_UPDATE_MUX_MASK;
}
+/*
+ * Host will wait maximum 300ms for result; otherwise it's error.
+ * so the polling takes 300ms too.
+ */
+#define POLLING_CYCLE 15
+#define POLLING_TIME_MS 20
+
+static bool query_usb_mux_set_completed_timeout(int port)
+{
+ int i;
+
+ for (i = 0; i < POLLING_CYCLE; i++) {
+ if (!usb_mux_set_completed(port))
+ msleep(POLLING_TIME_MS);
+ else
+ return false;
+ }
+
+ return true;
+}
+
+static void retry_online(int port)
+{
+ usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_DISCONNECT,
+ pd_get_polarity(port));
+ /* Wait maximum 300 ms for USB mux to be set */
+ query_usb_mux_set_completed_timeout(port);
+ /* Resume the port unconditionally */
+ retimer_fw_update_port_handler(port, RESUME);
+}
+
+/*
+ * After NVM update, if AP skips step 5, not wait 5+ seconds for retimer
+ * to come back; then do step 6 immediately, requesting EC to put
+ * retimer online. Step 6 will fail; port is still offline afterwards.
+ *
+ * This deferred function monitors if any port has this problem and retry
+ * online one more time.
+ */
+static void retimer_check_online(void)
+{
+ int i;
+
+ for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
+ if (retimer_fw_update_get_port_state(i) ==
+ RETIMER_ONLINE_REQUESTED) {
+ /*
+ * Now the time has passed RETIMTER_ONLINE_DELAY;
+ * retry online.
+ * The port is suspended; if the port is not
+ * suspended, DISCONNECT request won't go through,
+ * we couldn't be here.
+ */
+ retry_online(i);
+ /* PD port is resumed */
+ }
+ }
+}
+DECLARE_DEFERRED(retimer_check_online);
+
/* Allow mux results to be filled in during HOOKS if needed */
static void last_result_mux_get(void);
DECLARE_DEFERRED(last_result_mux_get);
static void last_result_mux_get(void)
{
- if (!usb_mux_set_completed(cur_port)) {
- hook_call_deferred(&last_result_mux_get_data, 20 * MSEC);
+ if (query_usb_mux_set_completed_timeout(cur_port)) {
+ last_result = USB_RETIMER_FW_UPDATE_ERR;
return;
}
@@ -175,8 +286,8 @@ void usb_retimer_fw_update_process_op_cb(int port)
result_mux_get = true;
break;
case USB_RETIMER_FW_UPDATE_SET_USB:
- usb_mux_set(port, USB_PD_MUX_USB_ENABLED,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ usb_mux_set(port, USB_PD_MUX_USB_ENABLED, USB_SWITCH_CONNECT,
+ pd_get_polarity(port));
result_mux_get = true;
break;
case USB_RETIMER_FW_UPDATE_SET_SAFE:
@@ -185,13 +296,21 @@ void usb_retimer_fw_update_process_op_cb(int port)
break;
case USB_RETIMER_FW_UPDATE_SET_TBT:
usb_mux_set(port, USB_PD_MUX_TBT_COMPAT_ENABLED,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT, pd_get_polarity(port));
result_mux_get = true;
break;
case USB_RETIMER_FW_UPDATE_DISCONNECT:
- usb_mux_set(port, USB_PD_MUX_NONE,
- USB_SWITCH_DISCONNECT, pd_get_polarity(port));
+ usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_DISCONNECT,
+ pd_get_polarity(port));
result_mux_get = true;
+ /*
+ * Host decides to put retimer online; now disconnects USB MUX
+ * and sets port state to "RETIMER_ONLINE_REQUESTED".
+ */
+ retimer_fw_update_set_port_state(port,
+ RETIMER_ONLINE_REQUESTED);
+ hook_call_deferred(&retimer_check_online_data,
+ RETIMTER_ONLINE_DELAY);
break;
default:
break;
@@ -210,12 +329,32 @@ void usb_retimer_fw_update_process_op(int port, int op)
ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_MAX_COUNT);
/*
- * TODO(b/179220036): check not overlapping requests;
- * not change cur_port if retimer scan is in progress
+ * The order of requests from host are:
+ *
+ * Port 0 offline
+ * Port 0 rescan retimers
+ * Port 1 offline
+ * Port 1 rescan retimers
+ * ...
+ * Port 0 online
+ * Port 1 online
+ * ...
*/
last_op = op;
cur_port = port;
+ /*
+ * Host has requested to put this port back online, and haven't
+ * finished online process. During this period, don't accept any
+ * requests, except USB_RETIMER_FW_UPDATE_RESUME_PD.
+ */
+ if (port_state[port] == RETIMER_ONLINE_REQUESTED) {
+ if (op != USB_RETIMER_FW_UPDATE_RESUME_PD) {
+ last_result = USB_RETIMER_FW_UPDATE_ERR;
+ return;
+ }
+ }
+
switch (op) {
case USB_RETIMER_FW_UPDATE_QUERY_PORT:
break;
@@ -253,9 +392,10 @@ static void restore_port(void)
{
int port;
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++) {
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++) {
if (retimer_fw_update_get_port_state(port))
retimer_fw_update_port_handler(port, RESUME);
}
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, restore_port, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_CHIPSET_RESET, restore_port, HOOK_PRIO_DEFAULT);
diff --git a/common/usbc/usb_sm.c b/common/usbc/usb_sm.c
index 04b7193c0f..96b0b81e33 100644
--- a/common/usbc/usb_sm.c
+++ b/common/usbc/usb_sm.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -12,8 +12,8 @@
#include "util.h"
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USB, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USB, format, ##args)
#else /* CONFIG_COMMON_RUNTIME */
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
@@ -23,8 +23,8 @@
struct internal_ctx {
usb_state_ptr last_entered;
uint32_t running : 1;
- uint32_t enter : 1;
- uint32_t exit : 1;
+ uint32_t enter : 1;
+ uint32_t exit : 1;
};
BUILD_ASSERT(sizeof(struct internal_ctx) ==
member_size(struct sm_ctx, internal));
@@ -65,9 +65,9 @@ static usb_state_ptr shared_parent_state(usb_state_ptr a, usb_state_ptr b)
* functions.
*/
static void call_entry_functions(const int port,
- struct internal_ctx *const internal,
- const usb_state_ptr stop,
- const usb_state_ptr current)
+ struct internal_ctx *const internal,
+ const usb_state_ptr stop,
+ const usb_state_ptr current)
{
if (current == stop)
return;
@@ -92,7 +92,7 @@ static void call_entry_functions(const int port,
* during an exit function.
*/
static void call_exit_functions(const int port, const usb_state_ptr stop,
- const usb_state_ptr current)
+ const usb_state_ptr current)
{
if (current == stop)
return;
@@ -106,7 +106,7 @@ static void call_exit_functions(const int port, const usb_state_ptr stop,
void set_state(const int port, struct sm_ctx *const ctx,
const usb_state_ptr new_state)
{
- struct internal_ctx * const internal = (void *) ctx->internal;
+ struct internal_ctx *const internal = (void *)ctx->internal;
usb_state_ptr last_state;
usb_state_ptr shared_parent;
@@ -116,8 +116,8 @@ void set_state(const int port, struct sm_ctx *const ctx,
* intended state to transition into.
*/
if (internal->exit) {
- CPRINTF("C%d: Ignoring set state to 0x%pP within 0x%pP",
- port, new_state, ctx->current);
+ CPRINTF("C%d: Ignoring set state to 0x%p within 0x%p", port,
+ new_state, ctx->current);
return;
}
@@ -176,8 +176,8 @@ void set_state(const int port, struct sm_ctx *const ctx,
* functions.
*/
static void call_run_functions(const int port,
- const struct internal_ctx *const internal,
- const usb_state_ptr current)
+ const struct internal_ctx *const internal,
+ const usb_state_ptr current)
{
if (!current)
return;
@@ -194,7 +194,7 @@ static void call_run_functions(const int port,
void run_state(const int port, struct sm_ctx *const ctx)
{
- struct internal_ctx * const internal = (void *) ctx->internal;
+ struct internal_ctx *const internal = (void *)ctx->internal;
internal->running = true;
call_run_functions(port, internal, ctx->current);
diff --git a/common/usbc/usb_tc_ctvpd_sm.c b/common/usbc/usb_tc_ctvpd_sm.c
index 46550978ed..045cca55c4 100644
--- a/common/usbc/usb_tc_ctvpd_sm.c
+++ b/common/usbc/usb_tc_ctvpd_sm.c
@@ -1,8 +1,9 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "system.h"
@@ -16,18 +17,18 @@
/* USB Type-C CTVPD module */
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else /* CONFIG_COMMON_RUNTIME */
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
#endif
/* Type-C Layer Flags */
-#define TC_FLAGS_VCONN_ON BIT(0)
+#define TC_FLAGS_VCONN_ON BIT(0)
-#define SUPPORT_TIMER_RESET_INIT 0
-#define SUPPORT_TIMER_RESET_REQUEST 1
+#define SUPPORT_TIMER_RESET_INIT 0
+#define SUPPORT_TIMER_RESET_REQUEST 1
#define SUPPORT_TIMER_RESET_COMPLETE 2
/**
@@ -105,9 +106,8 @@ enum usb_tc_state {
/* Forward declare the full list of states. This is indexed by usb_tc_state */
static const struct usb_state tc_states[];
-
/* List of human readable state names for console debugging */
-__maybe_unused const char * const tc_state_names[] = {
+__maybe_unused const char *const tc_state_names[] = {
#ifdef CONFIG_COMMON_RUNTIME
[TC_DISABLED] = "Disabled",
[TC_UNATTACHED_SNK] = "Unattached.SNK",
@@ -257,9 +257,9 @@ test_mockable_static void print_current_state(const int port)
int pd_is_connected(int port)
{
return (get_state_tc(port) == TC_ATTACHED_SNK) ||
- (get_state_tc(port) == TC_ATTACHED_SRC) ||
- (get_state_tc(port) == TC_CT_ATTACHED_UNSUPPORTED) ||
- (get_state_tc(port) == TC_CT_ATTACHED_VPD);
+ (get_state_tc(port) == TC_ATTACHED_SRC) ||
+ (get_state_tc(port) == TC_CT_ATTACHED_UNSUPPORTED) ||
+ (get_state_tc(port) == TC_CT_ATTACHED_VPD);
}
bool pd_is_disconnected(int port)
@@ -398,7 +398,7 @@ static void tc_unattached_snk_run(const int port)
* 2) VBUS is detected
*/
if (vpd_is_ct_vbus_present() &&
- tc[port].cc_state == PD_CC_DFP_ATTACHED) {
+ tc[port].cc_state == PD_CC_DFP_ATTACHED) {
set_state_tc(port, TC_UNATTACHED_SRC);
return;
}
@@ -436,11 +436,11 @@ static void tc_attach_wait_snk_run(const int port)
if (tc[port].host_cc_state != host_new_cc_state) {
tc[port].host_cc_state = host_new_cc_state;
if (host_new_cc_state == PD_CC_DFP_ATTACHED)
- tc[port].host_cc_debounce = get_time().val +
- PD_T_CC_DEBOUNCE;
+ tc[port].host_cc_debounce =
+ get_time().val + PD_T_CC_DEBOUNCE;
else
- tc[port].host_cc_debounce = get_time().val +
- PD_T_PD_DEBOUNCE;
+ tc[port].host_cc_debounce =
+ get_time().val + PD_T_PD_DEBOUNCE;
return;
}
@@ -458,7 +458,7 @@ static void tc_attach_wait_snk_run(const int port)
* CC2 pins is SNK.Open for at least tPDDebounce.
*/
if (tc[port].host_cc_state == PD_CC_DFP_ATTACHED &&
- (vpd_is_vconn_present() || vpd_is_host_vbus_present()))
+ (vpd_is_vconn_present() || vpd_is_host_vbus_present()))
set_state_tc(port, TC_ATTACHED_SNK);
else if (tc[port].host_cc_state == PD_CC_NONE)
set_state_tc(port, TC_UNATTACHED_SNK);
@@ -551,7 +551,7 @@ static void tc_attached_snk_run(const int port)
/* Check the Support Timer */
if (get_time().val > tc[port].support_timer &&
- !tc[port].billboard_presented) {
+ !tc[port].billboard_presented) {
/*
* Present USB Billboard Device Class interface
* indicating that Charge-Through is not supported
@@ -654,7 +654,7 @@ static void tc_unattached_src_run(const int port)
* if Charge-Through VBUS is removed.
*/
if (!vpd_is_ct_vbus_present() ||
- get_time().val > tc[port].next_role_swap) {
+ get_time().val > tc[port].next_role_swap) {
set_state_tc(port, TC_UNATTACHED_SNK);
return;
}
@@ -719,7 +719,7 @@ static void tc_attach_wait_src_run(const int port)
* state is on the Host-side port’s CC pin for at least tCCDebounce.
*/
if (tc[port].host_cc_state == PD_CC_UFP_ATTACHED &&
- !vpd_is_host_vbus_present()) {
+ !vpd_is_host_vbus_present()) {
set_state_tc(port, TC_TRY_SNK);
return;
}
@@ -847,7 +847,7 @@ static void tc_try_snk_run(const int port)
* for tTryCCDebounce.
*/
if (tc[port].host_cc_state == PD_CC_DFP_ATTACHED &&
- (vpd_is_host_vbus_present() || vpd_is_vconn_present()))
+ (vpd_is_host_vbus_present() || vpd_is_vconn_present()))
set_state_tc(port, TC_ATTACHED_SNK);
else if (tc[port].host_cc_state == PD_CC_NONE)
set_state_tc(port, TC_TRY_WAIT_SRC);
@@ -887,7 +887,7 @@ static void tc_try_wait_src_run(const int port)
if (tc[port].host_cc_state != host_new_cc_state) {
tc[port].host_cc_state = host_new_cc_state;
tc[port].host_cc_debounce =
- get_time().val + PD_T_TRY_CC_DEBOUNCE;
+ get_time().val + PD_T_TRY_CC_DEBOUNCE;
return;
}
@@ -899,7 +899,7 @@ static void tc_try_wait_src_run(const int port)
* at least tTryCCDebounce.
*/
if (tc[port].host_cc_state == PD_CC_UFP_ATTACHED &&
- !vpd_is_host_vbus_present()) {
+ !vpd_is_host_vbus_present()) {
set_state_tc(port, TC_ATTACHED_SRC);
return;
}
@@ -988,7 +988,7 @@ static void tc_ct_try_snk_run(const int port)
* Charge-Through port.
*/
if (tc[port].cc_state == PD_CC_DFP_ATTACHED &&
- vpd_is_ct_vbus_present()) {
+ vpd_is_ct_vbus_present()) {
set_state_tc(port, TC_CT_ATTACHED_VPD);
return;
}
@@ -1001,8 +1001,7 @@ static void tc_ct_try_snk_run(const int port)
* for tDRPTryWait.
*/
if (tc[port].cc_state == PD_CC_NONE) {
- set_state_tc(port,
- TC_CT_ATTACHED_UNSUPPORTED);
+ set_state_tc(port, TC_CT_ATTACHED_UNSUPPORTED);
return;
}
}
@@ -1181,8 +1180,7 @@ static void tc_ct_unattached_unsupported_run(const int port)
* on both the CC1 and CC2 pins.
*/
if (cc_is_at_least_one_rd(cc1, cc2) || cc_is_audio_acc(cc1, cc2)) {
- set_state_tc(port,
- TC_CT_ATTACH_WAIT_UNSUPPORTED);
+ set_state_tc(port, TC_CT_ATTACH_WAIT_UNSUPPORTED);
return;
}
@@ -1343,7 +1341,7 @@ static void tc_ct_attached_vpd_entry(const int port)
* pins is connected through the cable
*/
vpd_ct_get_cc(&cc1, &cc2);
- tc[port].ct_cc = cc_is_rp(cc2) ? CT_CC2 : CT_CC1;
+ tc[port].ct_cc = cc_is_rp(cc2) ? CT_CC2 : CT_CC1;
/*
* 1. Remove or reduce any additional capacitance on the
@@ -1468,10 +1466,8 @@ static void tc_ct_attach_wait_vpd_run(const int port)
/* Debounce the cc state */
if (new_cc_state != tc[port].cc_state) {
tc[port].cc_state = new_cc_state;
- tc[port].cc_debounce = get_time().val +
- PD_T_CC_DEBOUNCE;
- tc[port].pd_debounce = get_time().val +
- PD_T_PD_DEBOUNCE;
+ tc[port].cc_debounce = get_time().val + PD_T_CC_DEBOUNCE;
+ tc[port].pd_debounce = get_time().val + PD_T_PD_DEBOUNCE;
return;
}
@@ -1482,7 +1478,7 @@ static void tc_ct_attach_wait_vpd_run(const int port)
* port’s CC1 and CC2 pins are SNK.Open for at least
* tPDDebounce.
*/
- if (tc[port].cc_state == PD_CC_NONE) {
+ if (tc[port].cc_state == PD_CC_NONE) {
set_state_tc(port, TC_CT_UNATTACHED_VPD);
return;
}
@@ -1496,8 +1492,8 @@ static void tc_ct_attach_wait_vpd_run(const int port)
* least tCCDebounce and VBUS on the Charge-Through port is
* detected.
*/
- if (tc[port].cc_state == PD_CC_DFP_ATTACHED &&
- vpd_is_ct_vbus_present()) {
+ if (tc[port].cc_state == PD_CC_DFP_ATTACHED &&
+ vpd_is_ct_vbus_present()) {
set_state_tc(port, TC_CT_ATTACHED_VPD);
return;
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 2da6b59f0a..e68b0139db 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -1,8 +1,9 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "common.h"
@@ -32,30 +33,30 @@
* See Figure 4-16 in Release 1.4 of USB Type-C Spec.
*/
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else /* CONFIG_COMMON_RUNTIME */
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
#endif
-#define CPRINTF_LX(x, format, args...) \
- do { \
- if (tc_debug_level >= x) \
- CPRINTF(format, ## args); \
+#define CPRINTF_LX(x, format, args...) \
+ do { \
+ if (tc_debug_level >= x) \
+ CPRINTF(format, ##args); \
} while (0)
-#define CPRINTF_L1(format, args...) CPRINTF_LX(1, format, ## args)
-#define CPRINTF_L2(format, args...) CPRINTF_LX(2, format, ## args)
-#define CPRINTF_L3(format, args...) CPRINTF_LX(3, format, ## args)
-
-#define CPRINTS_LX(x, format, args...) \
- do { \
- if (tc_debug_level >= x) \
- CPRINTS(format, ## args); \
+#define CPRINTF_L1(format, args...) CPRINTF_LX(1, format, ##args)
+#define CPRINTF_L2(format, args...) CPRINTF_LX(2, format, ##args)
+#define CPRINTF_L3(format, args...) CPRINTF_LX(3, format, ##args)
+
+#define CPRINTS_LX(x, format, args...) \
+ do { \
+ if (tc_debug_level >= x) \
+ CPRINTS(format, ##args); \
} while (0)
-#define CPRINTS_L1(format, args...) CPRINTS_LX(1, format, ## args)
-#define CPRINTS_L2(format, args...) CPRINTS_LX(2, format, ## args)
-#define CPRINTS_L3(format, args...) CPRINTS_LX(3, format, ## args)
+#define CPRINTS_L1(format, args...) CPRINTS_LX(1, format, ##args)
+#define CPRINTS_L2(format, args...) CPRINTS_LX(2, format, ##args)
+#define CPRINTS_L3(format, args...) CPRINTS_LX(3, format, ##args)
/*
* Define DEBUG_PRINT_FLAG_AND_EVENT_NAMES to print flag names when set and
@@ -83,57 +84,58 @@ void print_flag(int port, int set_or_clear, int flag);
/* Type-C Layer Flags */
/* Flag to note we are sourcing VCONN */
-#define TC_FLAGS_VCONN_ON BIT(0)
+#define TC_FLAGS_VCONN_ON BIT(0)
/* Flag to note port partner has Rp/Rp or Rd/Rd */
-#define TC_FLAGS_TS_DTS_PARTNER BIT(1)
+#define TC_FLAGS_TS_DTS_PARTNER BIT(1)
/* Flag to note VBus input has never been low */
-#define TC_FLAGS_VBUS_NEVER_LOW BIT(2)
+#define TC_FLAGS_VBUS_NEVER_LOW BIT(2)
/* Flag to note Low Power Mode transition is currently happening */
-#define TC_FLAGS_LPM_TRANSITION BIT(3)
+#define TC_FLAGS_LPM_TRANSITION BIT(3)
/* Flag to note Low Power Mode is currently on */
-#define TC_FLAGS_LPM_ENGAGED BIT(4)
+#define TC_FLAGS_LPM_ENGAGED BIT(4)
/* Flag to note CVTPD has been detected */
-#define TC_FLAGS_CTVPD_DETECTED BIT(5)
+#define TC_FLAGS_CTVPD_DETECTED BIT(5)
/* Flag to note request to swap to VCONN on */
-#define TC_FLAGS_REQUEST_VC_SWAP_ON BIT(6)
+#define TC_FLAGS_REQUEST_VC_SWAP_ON BIT(6)
/* Flag to note request to swap to VCONN off */
-#define TC_FLAGS_REQUEST_VC_SWAP_OFF BIT(7)
+#define TC_FLAGS_REQUEST_VC_SWAP_OFF BIT(7)
/* Flag to note request to swap VCONN is being rejected */
-#define TC_FLAGS_REJECT_VCONN_SWAP BIT(8)
+#define TC_FLAGS_REJECT_VCONN_SWAP BIT(8)
/* Flag to note request to power role swap */
-#define TC_FLAGS_REQUEST_PR_SWAP BIT(9)
+#define TC_FLAGS_REQUEST_PR_SWAP BIT(9)
/* Flag to note request to data role swap */
-#define TC_FLAGS_REQUEST_DR_SWAP BIT(10)
+#define TC_FLAGS_REQUEST_DR_SWAP BIT(10)
/* Flag to note request to power off sink */
-#define TC_FLAGS_POWER_OFF_SNK BIT(11)
+#define TC_FLAGS_POWER_OFF_SNK BIT(11)
/* Flag to note port partner is Power Delivery capable */
-#define TC_FLAGS_PARTNER_PD_CAPABLE BIT(12)
+#define TC_FLAGS_PARTNER_PD_CAPABLE BIT(12)
/* Flag to note hard reset has been requested */
-#define TC_FLAGS_HARD_RESET_REQUESTED BIT(13)
+#define TC_FLAGS_HARD_RESET_REQUESTED BIT(13)
/* Flag to note we are currently performing PR Swap */
-#define TC_FLAGS_PR_SWAP_IN_PROGRESS BIT(14)
+#define TC_FLAGS_PR_SWAP_IN_PROGRESS BIT(14)
/* Flag to note we should check for connection */
-#define TC_FLAGS_CHECK_CONNECTION BIT(15)
+#define TC_FLAGS_CHECK_CONNECTION BIT(15)
/* Flag to note request from pd_set_suspend to enter TC_DISABLED state */
-#define TC_FLAGS_REQUEST_SUSPEND BIT(16)
+#define TC_FLAGS_REQUEST_SUSPEND BIT(16)
/* Flag to note we are in TC_DISABLED state */
-#define TC_FLAGS_SUSPENDED BIT(17)
+#define TC_FLAGS_SUSPENDED BIT(17)
/* Flag to indicate the port current limit has changed */
-#define TC_FLAGS_UPDATE_CURRENT BIT(18)
+#define TC_FLAGS_UPDATE_CURRENT BIT(18)
/* Flag to indicate USB mux should be updated */
-#define TC_FLAGS_UPDATE_USB_MUX BIT(19)
+#define TC_FLAGS_UPDATE_USB_MUX BIT(19)
/* Flag for retimer firmware update */
-#define TC_FLAGS_USB_RETIMER_FW_UPDATE_RUN BIT(20)
+#define TC_FLAGS_USB_RETIMER_FW_UPDATE_RUN BIT(20)
#define TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN BIT(21)
/* Flag for asynchronous call to request Error Recovery */
-#define TC_FLAGS_REQUEST_ERROR_RECOVERY BIT(22)
+#define TC_FLAGS_REQUEST_ERROR_RECOVERY BIT(22)
/* For checking flag_bit_names[] array */
-#define TC_FLAGS_COUNT 23
+#define TC_FLAGS_COUNT 23
/* On disconnect, clear most of the flags. */
-#define CLR_FLAGS_ON_DISCONNECT(port) TC_CLR_FLAG(port, \
- ~(TC_FLAGS_LPM_ENGAGED | TC_FLAGS_REQUEST_SUSPEND | TC_FLAGS_SUSPENDED))
+#define CLR_FLAGS_ON_DISCONNECT(port) \
+ TC_CLR_FLAG(port, ~(TC_FLAGS_LPM_ENGAGED | TC_FLAGS_REQUEST_SUSPEND | \
+ TC_FLAGS_SUSPENDED))
/*
* 10 ms is enough time for any TCPC transaction to complete
@@ -166,14 +168,14 @@ void print_flag(int port, int set_or_clear, int flag);
* The TypeC state machine uses this bit to disable/enable PD
* This bit corresponds to bit-0 of pd_disabled_mask
*/
-#define PD_DISABLED_NO_CONNECTION BIT(0)
+#define PD_DISABLED_NO_CONNECTION BIT(0)
/*
* Console and Host commands use this bit to override the
* PD_DISABLED_NO_CONNECTION bit that was set by the TypeC
* state machine.
* This bit corresponds to bit-1 of pd_disabled_mask
*/
-#define PD_DISABLED_BY_POLICY BIT(1)
+#define PD_DISABLED_BY_POLICY BIT(1)
/* Unreachable time in future */
#define TIMER_DISABLED 0xffffffffffffffff
@@ -250,9 +252,8 @@ extern int _GPIO_CCD_MODE_ODL;
* If we can't print or the CONFIG_USB_PD_DEBUG_LEVEL is defined to be 0
* then the DEBUG LABELS will be removed from the build.
*/
-#if defined(CONFIG_COMMON_RUNTIME) && \
- (!defined(CONFIG_USB_PD_DEBUG_LEVEL) || \
- (CONFIG_USB_PD_DEBUG_LEVEL > 0))
+#if defined(CONFIG_COMMON_RUNTIME) && (!defined(CONFIG_USB_PD_DEBUG_LEVEL) || \
+ (CONFIG_USB_PD_DEBUG_LEVEL > 0))
#define USB_PD_DEBUG_LABELS
#endif
@@ -268,9 +269,8 @@ extern int _GPIO_CCD_MODE_ODL;
*/
#define IS_ATTACHED_SNK(port) (get_state_tc(port) == TC_ATTACHED_SNK)
-
/* List of human readable state names for console debugging */
-__maybe_unused static __const_data const char * const tc_state_names[] = {
+__maybe_unused static __const_data const char *const tc_state_names[] = {
#ifdef USB_PD_DEBUG_LABELS
[TC_DISABLED] = "Disabled",
[TC_ERROR_RECOVERY] = "ErrorRecovery",
@@ -289,7 +289,7 @@ __maybe_unused static __const_data const char * const tc_state_names[] = {
[TC_LOW_POWER_MODE] = "LowPowerMode",
#endif
#ifdef CONFIG_USB_PE_SM
- [TC_CT_UNATTACHED_SNK] = "CTUnattached.SNK",
+ [TC_CT_UNATTACHED_SNK] = "CTUnattached.SNK",
[TC_CT_ATTACHED_SNK] = "CTAttached.SNK",
#endif
/* Super States */
@@ -304,14 +304,16 @@ __maybe_unused static __const_data const char * const tc_state_names[] = {
/* Debug log level - higher number == more log */
#ifdef CONFIG_USB_PD_DEBUG_LEVEL
static const enum debug_level tc_debug_level = CONFIG_USB_PD_DEBUG_LEVEL;
+#elif defined(CONFIG_USB_PD_INITIAL_DEBUG_LEVEL)
+static enum debug_level tc_debug_level = CONFIG_USB_PD_INITIAL_DEBUG_LEVEL;
#else
static enum debug_level tc_debug_level = DEBUG_LEVEL_1;
#endif
#ifdef DEBUG_PRINT_FLAG_AND_EVENT_NAMES
struct bit_name {
- int value;
- const char *name;
+ int value;
+ const char *name;
};
static struct bit_name flag_bit_names[] = {
@@ -335,11 +337,10 @@ static struct bit_name flag_bit_names[] = {
{ TC_FLAGS_SUSPENDED, "SUSPENDED" },
{ TC_FLAGS_UPDATE_CURRENT, "UPDATE_CURRENT" },
{ TC_FLAGS_UPDATE_USB_MUX, "UPDATE_USB_MUX" },
- { TC_FLAGS_USB_RETIMER_FW_UPDATE_RUN,
- "USB_RETIMER_FW_UPDATE_RUN" },
+ { TC_FLAGS_USB_RETIMER_FW_UPDATE_RUN, "USB_RETIMER_FW_UPDATE_RUN" },
{ TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN,
- "USB_RETIMER_FW_UPDATE_LTD_RUN" },
- { TC_FLAGS_REQUEST_ERROR_RECOVERY, "REQUEST_ERROR_RECOCVERY"},
+ "USB_RETIMER_FW_UPDATE_LTD_RUN" },
+ { TC_FLAGS_REQUEST_ERROR_RECOVERY, "REQUEST_ERROR_RECOCVERY" },
};
BUILD_ASSERT(ARRAY_SIZE(flag_bit_names) == TC_FLAGS_COUNT);
@@ -394,8 +395,8 @@ void print_flag(int port, int set_or_clear, int flag)
#ifndef CONFIG_USB_PD_TRY_SRC
extern int TC_TRY_SRC_UNDEFINED;
extern int TC_TRY_WAIT_SNK_UNDEFINED;
-#define TC_TRY_SRC TC_TRY_SRC_UNDEFINED
-#define TC_TRY_WAIT_SNK TC_TRY_WAIT_SNK_UNDEFINED
+#define TC_TRY_SRC TC_TRY_SRC_UNDEFINED
+#define TC_TRY_WAIT_SNK TC_TRY_WAIT_SNK_UNDEFINED
#endif
static struct type_c {
@@ -444,10 +445,11 @@ static struct type_c {
} tc[CONFIG_USB_PD_PORT_MAX_COUNT];
/* Port dual-role state */
-static volatile __maybe_unused
-enum pd_dual_role_states drp_state[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- [0 ... (CONFIG_USB_PD_PORT_MAX_COUNT - 1)] =
- CONFIG_USB_PD_INITIAL_DRP_STATE};
+static volatile __maybe_unused enum pd_dual_role_states
+ drp_state[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ [0 ...(CONFIG_USB_PD_PORT_MAX_COUNT - 1)] =
+ CONFIG_USB_PD_INITIAL_DRP_STATE
+ };
static void set_vconn(int port, int enable);
@@ -516,7 +518,7 @@ __overridable void pd_set_vbus_discharge(int port, int enable)
/*
* These pd_ functions are implemented in the PE layer
*/
-const uint32_t * const pd_get_src_caps(int port)
+const uint32_t *const pd_get_src_caps(int port)
{
return NULL;
}
@@ -526,7 +528,7 @@ uint8_t pd_get_src_cap_cnt(int port)
return 0;
}
-const uint32_t * const pd_get_snk_caps(int port)
+const uint32_t *const pd_get_snk_caps(int port)
{
return NULL;
}
@@ -718,7 +720,7 @@ __maybe_unused static void tc_enable_try_src(int en)
static void tc_set_modes_exit(int port)
{
if (IS_ENABLED(CONFIG_USB_PE_SM) &&
- IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
+ IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
pd_dfp_exit_mode(port, TCPCI_MSG_SOP, 0, 0);
pd_dfp_exit_mode(port, TCPCI_MSG_SOP_PRIME, 0, 0);
pd_dfp_exit_mode(port, TCPCI_MSG_SOP_PRIME_PRIME, 0, 0);
@@ -738,12 +740,13 @@ static void tc_detached(int port)
/* Clear any mux connection on detach */
if (IS_ENABLED(CONFIG_USBC_SS_MUX))
- usb_mux_set(port, USB_PD_MUX_NONE,
- USB_SWITCH_DISCONNECT, tc[port].polarity);
+ usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_DISCONNECT,
+ tc[port].polarity);
}
static inline void pd_set_dual_role_and_event(int port,
- enum pd_dual_role_states state, uint32_t event)
+ enum pd_dual_role_states state,
+ uint32_t event)
{
drp_state[port] = state;
@@ -1072,8 +1075,8 @@ static void tc_set_partner_role(int port, enum ppc_device_role role,
* to run. So build in 1ms delays, for up to 300ms, to wait for
* the suspend to actually happen.
*/
-#define SUSPEND_SLEEP_DELAY 1
-#define SUSPEND_SLEEP_RETRIES 300
+#define SUSPEND_SLEEP_DELAY 1
+#define SUSPEND_SLEEP_RETRIES 300
void pd_set_suspend(int port, int suspend)
{
@@ -1098,8 +1101,8 @@ void pd_set_suspend(int port, int suspend)
/* Sleep this task if we are not suspended */
while (pd_is_port_enabled(port)) {
if (++wait > SUSPEND_SLEEP_RETRIES) {
- CPRINTS("C%d: NOT SUSPENDED after %dms",
- port, wait * SUSPEND_SLEEP_DELAY);
+ CPRINTS("C%d: NOT SUSPENDED after %dms", port,
+ wait * SUSPEND_SLEEP_DELAY);
return;
}
msleep(SUSPEND_SLEEP_DELAY);
@@ -1177,8 +1180,8 @@ int pd_is_connected(int port)
{
return (IS_ATTACHED_SRC(port) ||
(IS_ENABLED(CONFIG_USB_PE_SM) &&
- ((get_state_tc(port) == TC_CT_UNATTACHED_SNK) ||
- (get_state_tc(port) == TC_CT_ATTACHED_SNK))) ||
+ ((get_state_tc(port) == TC_CT_UNATTACHED_SNK) ||
+ (get_state_tc(port) == TC_CT_ATTACHED_SNK))) ||
IS_ATTACHED_SNK(port));
}
@@ -1235,7 +1238,7 @@ bool pd_get_partner_unconstr_power(int port)
}
static void bc12_role_change_handler(int port, enum pd_data_role prev_data_role,
- enum pd_data_role data_role)
+ enum pd_data_role data_role)
{
int event = 0;
bool role_changed = (data_role != prev_data_role);
@@ -1290,8 +1293,7 @@ void typec_select_src_collision_rp(int port, enum tcpc_rp_value rp)
static enum tcpc_rp_value typec_get_active_select_rp(int port)
{
/* Explicit contract will use the collision Rp */
- if (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- pe_is_explicit_contract(port))
+ if (IS_ENABLED(CONFIG_USB_PD_REV30) && pe_is_explicit_contract(port))
return tc[port].select_collision_rp;
return tc[port].select_current_limit_rp;
}
@@ -1412,7 +1414,7 @@ static bool tc_perform_snk_hard_reset(int port)
tc[port].ps_reset_state = PS_STATE2;
pd_timer_enable(port, TC_TIMER_TIMEOUT,
PD_T_SRC_RECOVER_MAX +
- PD_T_SRC_TURN_ON);
+ PD_T_SRC_TURN_ON);
}
if (pd_timer_is_expired(port, TC_TIMER_TIMEOUT)) {
@@ -1423,7 +1425,7 @@ static bool tc_perform_snk_hard_reset(int port)
tc[port].ps_reset_state = PS_STATE2;
pd_timer_enable(port, TC_TIMER_TIMEOUT,
PD_T_SRC_RECOVER_MAX +
- PD_T_SRC_TURN_ON);
+ PD_T_SRC_TURN_ON);
}
return false;
case PS_STATE2:
@@ -1497,8 +1499,8 @@ static void restart_tc_sm(int port, enum usb_tc_state start_state)
* Update the Rp Value. We don't need to update CC lines though as that
* happens in below set_state transition.
*/
- typec_select_src_current_limit_rp(port,
- typec_get_default_current_limit_rp(port));
+ typec_select_src_current_limit_rp(
+ port, typec_get_default_current_limit_rp(port));
/* Disable if restart failed, otherwise start in default state. */
set_state_tc(port, res ? TC_DISABLED : start_state);
@@ -1567,7 +1569,6 @@ void tc_state_init(int port)
return;
}
-
/* Allow system to set try src enable */
if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC))
tc_try_src_override(TRY_SRC_NO_OVERRIDE);
@@ -1582,11 +1583,13 @@ void tc_state_init(int port)
if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
pd_set_dual_role_and_event(port, PD_DRP_FORCE_SINK, 0);
else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
- pd_set_dual_role_and_event(port, pd_get_drp_state_in_suspend(), 0);
+ pd_set_dual_role_and_event(port, pd_get_drp_state_in_suspend(),
+ 0);
else /* CHIPSET_STATE_ON */
pd_set_dual_role_and_event(port, pd_get_drp_state_in_s0(), 0);
#else
- pd_set_dual_role_and_event(port, board_tc_get_initial_drp_mode(port), 0);
+ pd_set_dual_role_and_event(port, board_tc_get_initial_drp_mode(port),
+ 0);
#endif
/*
@@ -1771,8 +1774,7 @@ void tc_event_check(int port, int evt)
* Notify all ports of sysjump
*/
if (evt & PD_EVENT_SYSJUMP) {
- for (i = 0; i <
- CONFIG_USB_PD_PORT_MAX_COUNT; i++)
+ for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
dpm_set_mode_exit_request(i);
notify_sysjump_ready();
}
@@ -1834,8 +1836,8 @@ static void sink_stop_drawing_current(int port)
if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) {
typec_set_input_current_limit(port, 0, 0);
- charge_manager_set_ceil(port,
- CEIL_REQUESTOR_PD, CHARGE_CEIL_NONE);
+ charge_manager_set_ceil(port, CEIL_REQUESTOR_PD,
+ CHARGE_CEIL_NONE);
}
}
@@ -1861,9 +1863,9 @@ static void set_vconn(int port, int enable)
static void pd_update_dual_role_config(int port)
{
if (tc[port].power_role == PD_ROLE_SOURCE &&
- (drp_state[port] == PD_DRP_FORCE_SINK ||
- (drp_state[port] == PD_DRP_TOGGLE_OFF &&
- get_state_tc(port) == TC_UNATTACHED_SRC))) {
+ (drp_state[port] == PD_DRP_FORCE_SINK ||
+ (drp_state[port] == PD_DRP_TOGGLE_OFF &&
+ get_state_tc(port) == TC_UNATTACHED_SRC))) {
/*
* Change to sink if port is currently a source AND (new DRP
* state is force sink OR new DRP state is toggle off and we are
@@ -1871,7 +1873,7 @@ static void pd_update_dual_role_config(int port)
*/
set_state_tc(port, TC_UNATTACHED_SNK);
} else if (tc[port].power_role == PD_ROLE_SINK &&
- drp_state[port] == PD_DRP_FORCE_SOURCE) {
+ drp_state[port] == PD_DRP_FORCE_SOURCE) {
/*
* Change to source if port is currently a sink and the
* new DRP state is force source.
@@ -1885,10 +1887,9 @@ __maybe_unused static void handle_new_power_state(int port)
if (!IS_ENABLED(CONFIG_POWER_COMMON))
assert(0);
- if (IS_ENABLED(CONFIG_POWER_COMMON) &&
- IS_ENABLED(CONFIG_USB_PE_SM)) {
+ if (IS_ENABLED(CONFIG_POWER_COMMON) && IS_ENABLED(CONFIG_USB_PE_SM)) {
if (chipset_in_or_transitioning_to_state(
- CHIPSET_STATE_ANY_OFF)) {
+ CHIPSET_STATE_ANY_OFF)) {
/*
* The SoC will negotiate alternate mode again when it
* boots up
@@ -1905,8 +1906,7 @@ __maybe_unused static void handle_new_power_state(int port)
*/
if (IS_ENABLED(CONFIG_USB_PE_SM)) {
if (tc_is_vconn_src(port) && tc_is_attached_snk(port) &&
- !pd_check_vconn_swap(port) &&
- pd_is_battery_capable())
+ !pd_check_vconn_swap(port) && pd_is_battery_capable())
pd_dpm_request(port, DPM_REQUEST_HARD_RESET_SEND);
}
@@ -1928,7 +1928,7 @@ __maybe_unused static void handle_new_power_state(int port)
void pd_request_vconn_swap_off(int port)
{
if (get_state_tc(port) == TC_ATTACHED_SRC ||
- get_state_tc(port) == TC_ATTACHED_SNK) {
+ get_state_tc(port) == TC_ATTACHED_SNK) {
TC_SET_FLAG(port, TC_FLAGS_REQUEST_VC_SWAP_OFF);
task_wake(PD_PORT_TO_TASK_ID(port));
}
@@ -1937,7 +1937,7 @@ void pd_request_vconn_swap_off(int port)
void pd_request_vconn_swap_on(int port)
{
if (get_state_tc(port) == TC_ATTACHED_SRC ||
- get_state_tc(port) == TC_ATTACHED_SNK) {
+ get_state_tc(port) == TC_ATTACHED_SNK) {
TC_SET_FLAG(port, TC_FLAGS_REQUEST_VC_SWAP_ON);
task_wake(PD_PORT_TO_TASK_ID(port));
}
@@ -2090,14 +2090,13 @@ static void sink_power_sub_states(int port)
tc[port].typec_curr = usb_get_typec_current_limit(
tc[port].polarity, cc1, cc2);
- typec_set_input_current_limit(port,
- tc[port].typec_curr, TYPE_C_VOLTAGE);
+ typec_set_input_current_limit(port, tc[port].typec_curr,
+ TYPE_C_VOLTAGE);
charge_manager_update_dualrole(port, CAP_DEDICATED);
}
}
}
-
/*
* TYPE-C State Implementations
*/
@@ -2117,6 +2116,7 @@ static void tc_disabled_entry(const int port)
* to indicate to pd_is_port_enabled that we are now suspended.
*/
TC_SET_FLAG(port, TC_FLAGS_SUSPENDED);
+ tcpm_release(port);
}
static void tc_disabled_run(const int port)
@@ -2124,13 +2124,16 @@ static void tc_disabled_run(const int port)
/* If pd_set_suspend clears the request, go to TC_UNATTACHED_SNK/SRC. */
if (!TC_CHK_FLAG(port, TC_FLAGS_REQUEST_SUSPEND)) {
set_state_tc(port, drp_state[port] == PD_DRP_FORCE_SOURCE ?
- TC_UNATTACHED_SRC : TC_UNATTACHED_SNK);
+ TC_UNATTACHED_SRC :
+ TC_UNATTACHED_SNK);
} else {
if (IS_ENABLED(CONFIG_USBC_RETIMER_FW_UPDATE)) {
- if (TC_CHK_FLAG(port,
- TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN)) {
- TC_CLR_FLAG(port,
- TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN);
+ if (TC_CHK_FLAG(
+ port,
+ TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN)) {
+ TC_CLR_FLAG(
+ port,
+ TC_FLAGS_USB_RETIMER_FW_UPDATE_LTD_RUN);
usb_retimer_fw_update_process_op_cb(port);
}
}
@@ -2179,7 +2182,8 @@ static void tc_error_recovery_run(const int port)
*/
if (tc[port].ctx.previous == NULL) {
set_state_tc(port, drp_state[port] == PD_DRP_FORCE_SOURCE ?
- TC_UNATTACHED_SRC : TC_UNATTACHED_SNK);
+ TC_UNATTACHED_SRC :
+ TC_UNATTACHED_SNK);
return;
}
@@ -2230,11 +2234,10 @@ static void tc_unattached_snk_entry(const int port)
*/
tcpm_debug_detach(port);
typec_select_pull(port, TYPEC_CC_RD);
- typec_select_src_current_limit_rp(port,
- typec_get_default_current_limit_rp(port));
+ typec_select_src_current_limit_rp(
+ port, typec_get_default_current_limit_rp(port));
typec_update_cc(port);
-
prev_data_role = tc[port].data_role;
tc[port].data_role = PD_ROLE_DISCONNECTED;
/*
@@ -2256,10 +2259,11 @@ static void tc_unattached_snk_entry(const int port)
pd_execute_data_swap(port, PD_ROLE_DISCONNECTED);
pd_timer_enable(port, TC_TIMER_NEXT_ROLE_SWAP, PD_T_DRP_SNK);
- if (IS_ENABLED(CONFIG_USB_PE_SM)) {
- CLR_FLAGS_ON_DISCONNECT(port);
- tc_enable_pd(port, 0);
- }
+#ifdef CONFIG_USB_PE_SM
+ CLR_FLAGS_ON_DISCONNECT(port);
+ tc_enable_pd(port, 0);
+ tc[port].ps_reset_state = PS_STATE0;
+#endif
}
static void tc_unattached_snk_run(const int port)
@@ -2383,9 +2387,9 @@ static void tc_attach_wait_snk_run(const int port)
if (new_cc_state == PD_CC_NONE &&
pd_timer_is_expired(port, TC_TIMER_PD_DEBOUNCE)) {
/* We are detached */
- if (drp_state[port] == PD_DRP_TOGGLE_OFF
- || drp_state[port] == PD_DRP_FREEZE
- || drp_state[port] == PD_DRP_FORCE_SINK)
+ if (drp_state[port] == PD_DRP_TOGGLE_OFF ||
+ drp_state[port] == PD_DRP_FREEZE ||
+ drp_state[port] == PD_DRP_FORCE_SINK)
set_state_tc(port, TC_UNATTACHED_SNK);
else
set_state_tc(port, TC_UNATTACHED_SRC);
@@ -2425,9 +2429,9 @@ static void tc_attach_wait_snk_run(const int port)
}
if (IS_ENABLED(CONFIG_USB_PE_SM) &&
- IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
+ IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) {
hook_call_deferred(&pd_usb_billboard_deferred_data,
- PD_T_AME);
+ PD_T_AME);
}
}
}
@@ -2471,7 +2475,7 @@ static void tc_attached_snk_entry(const int port)
/* Change role to sink */
tc_set_power_role(port, PD_ROLE_SINK);
tcpm_set_msg_header(port, tc[port].power_role,
- tc[port].data_role);
+ tc[port].data_role);
/*
* Maintain VCONN supply state, whether ON or OFF, and its
@@ -2490,11 +2494,10 @@ static void tc_attached_snk_entry(const int port)
hook_notify(HOOK_USB_PD_CONNECT);
if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) {
- tc[port].typec_curr =
- usb_get_typec_current_limit(tc[port].polarity,
- cc1, cc2);
- typec_set_input_current_limit(port,
- tc[port].typec_curr, TYPE_C_VOLTAGE);
+ tc[port].typec_curr = usb_get_typec_current_limit(
+ tc[port].polarity, cc1, cc2);
+ typec_set_input_current_limit(port, tc[port].typec_curr,
+ TYPE_C_VOLTAGE);
/*
* Start new connections as dedicated until source caps
* are received, at which point the PE will update the
@@ -2550,8 +2553,8 @@ static bool tc_snk_check_vbus_removed(const int port)
TC_TIMER_VBUS_DEBOUNCE)) {
pd_timer_enable(port, TC_TIMER_VBUS_DEBOUNCE,
PD_T_FRS_VBUS_DEBOUNCE);
- } else if (pd_timer_is_expired(port,
- TC_TIMER_VBUS_DEBOUNCE)) {
+ } else if (pd_timer_is_expired(
+ port, TC_TIMER_VBUS_DEBOUNCE)) {
set_state_tc(port, TC_UNATTACHED_SNK);
return true;
}
@@ -2658,8 +2661,9 @@ static void tc_attached_snk_run(const int port)
/* Perform Data Role Swap */
tc_set_data_role(port,
- tc[port].data_role == PD_ROLE_UFP ?
- PD_ROLE_DFP : PD_ROLE_UFP);
+ tc[port].data_role == PD_ROLE_UFP ?
+ PD_ROLE_DFP :
+ PD_ROLE_UFP);
}
/*
@@ -2787,8 +2791,8 @@ static void tc_unattached_src_entry(const int port)
*/
tcpm_debug_detach(port);
typec_select_pull(port, TYPEC_CC_RP);
- typec_select_src_current_limit_rp(port,
- typec_get_default_current_limit_rp(port));
+ typec_select_src_current_limit_rp(
+ port, typec_get_default_current_limit_rp(port));
typec_update_cc(port);
prev_data_role = tc[port].data_role;
@@ -2806,10 +2810,11 @@ static void tc_unattached_src_entry(const int port)
if (IS_ENABLED(CONFIG_CHARGE_MANAGER))
charge_manager_update_dualrole(port, CAP_UNKNOWN);
- if (IS_ENABLED(CONFIG_USB_PE_SM)) {
- CLR_FLAGS_ON_DISCONNECT(port);
- tc_enable_pd(port, 0);
- }
+#ifdef CONFIG_USB_PE_SM
+ CLR_FLAGS_ON_DISCONNECT(port);
+ tc_enable_pd(port, 0);
+ tc[port].ps_reset_state = PS_STATE0;
+#endif
pd_timer_enable(port, TC_TIMER_NEXT_ROLE_SWAP, PD_T_DRP_SRC);
}
@@ -2983,9 +2988,8 @@ static void tc_attached_src_entry(const int port)
if (TC_CHK_FLAG(port, TC_FLAGS_PR_SWAP_IN_PROGRESS)) {
/* Change role to source */
tc_set_power_role(port, PD_ROLE_SOURCE);
- tcpm_set_msg_header(port,
- tc[port].power_role,
- tc[port].data_role);
+ tcpm_set_msg_header(port, tc[port].power_role,
+ tc[port].data_role);
/* Enable VBUS */
tc_src_power_on(port);
@@ -3040,10 +3044,9 @@ static void tc_attached_src_entry(const int port)
set_vconn(port, 0);
if (IS_ENABLED(CONFIG_USBC_SS_MUX))
- usb_mux_set(port,
- USB_PD_MUX_NONE,
- USB_SWITCH_DISCONNECT,
- tc[port].polarity);
+ usb_mux_set(port, USB_PD_MUX_NONE,
+ USB_SWITCH_DISCONNECT,
+ tc[port].polarity);
}
tc_enable_pd(port, 0);
@@ -3093,7 +3096,8 @@ static void tc_attached_src_entry(const int port)
if (IS_ENABLED(CONFIG_USBC_SS_MUX))
usb_mux_set(port, USB_PD_MUX_NONE,
- USB_SWITCH_DISCONNECT, tc[port].polarity);
+ USB_SWITCH_DISCONNECT,
+ tc[port].polarity);
}
}
@@ -3161,13 +3165,13 @@ static void tc_attached_src_run(const int port)
if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC))
tryWait = is_try_src_enabled(port) &&
- !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER);
+ !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER);
if (drp_state[port] == PD_DRP_FORCE_SOURCE)
new_tc_state = TC_UNATTACHED_SRC;
- else if(IS_ENABLED(CONFIG_USB_PD_TRY_SRC))
- new_tc_state = tryWait ?
- TC_TRY_WAIT_SNK : TC_UNATTACHED_SNK;
+ else if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC))
+ new_tc_state = tryWait ? TC_TRY_WAIT_SNK :
+ TC_UNATTACHED_SNK;
set_state_tc(port, new_tc_state);
return;
@@ -3221,8 +3225,9 @@ static void tc_attached_src_run(const int port)
/* Perform Data Role Swap */
tc_set_data_role(port,
- tc[port].data_role == PD_ROLE_DFP ?
- PD_ROLE_UFP : PD_ROLE_DFP);
+ tc[port].data_role == PD_ROLE_DFP ?
+ PD_ROLE_UFP :
+ PD_ROLE_DFP);
}
/*
@@ -3230,7 +3235,7 @@ static void tc_attached_src_run(const int port)
* UnorientedDebugAccessory.SRC shall not drive Vconn
*/
if (IS_ENABLED(CONFIG_USBC_VCONN) &&
- !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) {
+ !TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER)) {
/*
* VCONN Swap Request
*/
@@ -3239,7 +3244,7 @@ static void tc_attached_src_run(const int port)
set_vconn(port, 1);
pe_vconn_swap_complete(port);
} else if (TC_CHK_FLAG(port,
- TC_FLAGS_REQUEST_VC_SWAP_OFF)) {
+ TC_FLAGS_REQUEST_VC_SWAP_OFF)) {
TC_CLR_FLAG(port, TC_FLAGS_REQUEST_VC_SWAP_OFF);
set_vconn(port, 0);
pe_vconn_swap_complete(port);
@@ -3265,8 +3270,7 @@ static void tc_attached_src_run(const int port)
* applied.
*/
if (!TC_CHK_FLAG(port, TC_FLAGS_TS_DTS_PARTNER) &&
- TC_CHK_FLAG(port, TC_FLAGS_CTVPD_DETECTED)) {
-
+ TC_CHK_FLAG(port, TC_FLAGS_CTVPD_DETECTED)) {
set_state_tc(port, TC_CT_UNATTACHED_SNK);
}
}
@@ -3274,13 +3278,13 @@ static void tc_attached_src_run(const int port)
if (TC_CHK_FLAG(port, TC_FLAGS_UPDATE_CURRENT)) {
TC_CLR_FLAG(port, TC_FLAGS_UPDATE_CURRENT);
- typec_set_source_current_limit(port,
- tc[port].select_current_limit_rp);
+ typec_set_source_current_limit(
+ port, tc[port].select_current_limit_rp);
pd_update_contract(port);
/* Update Rp if no contract is present */
if (!IS_ENABLED(CONFIG_USB_PE_SM) ||
- !pe_is_explicit_contract(port))
+ !pe_is_explicit_contract(port))
typec_update_cc(port);
}
}
@@ -3302,7 +3306,7 @@ static void tc_attached_src_exit(const int port)
* a CTVPD was not detected
*/
if (TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON) &&
- !TC_CHK_FLAG(port, TC_FLAGS_CTVPD_DETECTED))
+ !TC_CHK_FLAG(port, TC_FLAGS_CTVPD_DETECTED))
set_vconn(port, 0);
}
@@ -3332,14 +3336,14 @@ static __maybe_unused void check_drp_connection(const int port)
tc[port].drp_sink_time = get_time().val;
/* Get the next toggle state */
- next_state = drp_auto_toggle_next_state(&tc[port].drp_sink_time,
- tc[port].power_role, drp_state[port], cc1, cc2,
- tcpm_auto_toggle_supported(port));
+ next_state = drp_auto_toggle_next_state(
+ &tc[port].drp_sink_time, tc[port].power_role, drp_state[port],
+ cc1, cc2, tcpm_auto_toggle_supported(port));
if (next_state == DRP_TC_DEFAULT)
- next_state = (PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE)
- ? DRP_TC_UNATTACHED_SRC
- : DRP_TC_UNATTACHED_SNK;
+ next_state = (PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE) ?
+ DRP_TC_UNATTACHED_SRC :
+ DRP_TC_UNATTACHED_SNK;
switch (next_state) {
case DRP_TC_UNATTACHED_SNK:
@@ -3491,8 +3495,8 @@ static void tc_try_src_entry(const int port)
*/
typec_select_pull(port, TYPEC_CC_RP);
- typec_select_src_current_limit_rp(port,
- typec_get_default_current_limit_rp(port));
+ typec_select_src_current_limit_rp(
+ port, typec_get_default_current_limit_rp(port));
/* Apply Rp */
typec_update_cc(port);
@@ -3507,7 +3511,7 @@ static void tc_try_src_run(const int port)
tcpm_get_cc(port, &cc1, &cc2);
if ((cc1 == TYPEC_CC_VOLT_RD && cc2 != TYPEC_CC_VOLT_RD) ||
- (cc1 != TYPEC_CC_VOLT_RD && cc2 == TYPEC_CC_VOLT_RD))
+ (cc1 != TYPEC_CC_VOLT_RD && cc2 == TYPEC_CC_VOLT_RD))
new_cc_state = PD_CC_UFP_ATTACHED;
else
new_cc_state = PD_CC_NONE;
@@ -3801,7 +3805,6 @@ static void tc_cc_rd_entry(const int port)
tcpm_set_msg_header(port, tc[port].power_role, tc[port].data_role);
}
-
/**
* Super State CC_RP
*/
@@ -3887,8 +3890,8 @@ void tc_run(const int port)
* If pd_set_suspend set TC_FLAGS_REQUEST_SUSPEND, go directly to
* TC_DISABLED.
*/
- if (get_state_tc(port) != TC_DISABLED
- && TC_CHK_FLAG(port, TC_FLAGS_REQUEST_SUSPEND)) {
+ if (get_state_tc(port) != TC_DISABLED &&
+ TC_CHK_FLAG(port, TC_FLAGS_REQUEST_SUSPEND)) {
/* Invalidate a contract, if there is one */
if (IS_ENABLED(CONFIG_USB_PE_SM))
pe_invalidate_explicit_contract(port);
@@ -3918,17 +3921,16 @@ static void pd_chipset_resume(void)
int i;
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
- if(IS_ENABLED(CONFIG_USB_PE_SM))
+ if (IS_ENABLED(CONFIG_USB_PE_SM))
pd_resume_check_pr_swap_needed(i);
- pd_set_dual_role_and_event(i,
- pd_get_drp_state_in_s0(),
- PD_EVENT_UPDATE_DUAL_ROLE
- | PD_EVENT_POWER_STATE_CHANGE);
+ pd_set_dual_role_and_event(i, pd_get_drp_state_in_s0(),
+ PD_EVENT_UPDATE_DUAL_ROLE |
+ PD_EVENT_POWER_STATE_CHANGE);
if (tc[i].data_role == PD_ROLE_DFP) {
pd_send_alert_msg(i, ADO_EXTENDED_ALERT_EVENT |
- ADO_POWER_STATE_CHANGE);
+ ADO_POWER_STATE_CHANGE);
}
}
@@ -3941,14 +3943,13 @@ static void pd_chipset_suspend(void)
int i;
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
- pd_set_dual_role_and_event(i,
- pd_get_drp_state_in_suspend(),
- PD_EVENT_UPDATE_DUAL_ROLE
- | PD_EVENT_POWER_STATE_CHANGE);
+ pd_set_dual_role_and_event(i, pd_get_drp_state_in_suspend(),
+ PD_EVENT_UPDATE_DUAL_ROLE |
+ PD_EVENT_POWER_STATE_CHANGE);
if (tc[i].data_role == PD_ROLE_DFP) {
pd_send_alert_msg(i, ADO_EXTENDED_ALERT_EVENT |
- ADO_POWER_STATE_CHANGE);
+ ADO_POWER_STATE_CHANGE);
}
}
@@ -3974,12 +3975,15 @@ static void pd_chipset_reset(void)
* kernel knows to consume discovery information for them.
*/
for (tx = TCPCI_MSG_SOP; tx <= TCPCI_MSG_SOP_PRIME; tx++) {
- if (pd_get_identity_discovery(i, tx) != PD_DISC_NEEDED
- && pd_get_svids_discovery(i, tx) != PD_DISC_NEEDED
- && pd_get_modes_discovery(i, tx) != PD_DISC_NEEDED)
- pd_notify_event(i, tx == TCPCI_MSG_SOP ?
- PD_STATUS_EVENT_SOP_DISC_DONE :
- PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
+ if (pd_get_identity_discovery(i, tx) !=
+ PD_DISC_NEEDED &&
+ pd_get_svids_discovery(i, tx) != PD_DISC_NEEDED &&
+ pd_get_modes_discovery(i, tx) != PD_DISC_NEEDED)
+ pd_notify_event(
+ i,
+ tx == TCPCI_MSG_SOP ?
+ PD_STATUS_EVENT_SOP_DISC_DONE :
+ PD_STATUS_EVENT_SOP_PRIME_DISC_DONE);
}
/* Exit mode so AP can enter mode again after reset */
@@ -3995,10 +3999,9 @@ static void pd_chipset_startup(void)
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
TC_SET_FLAG(i, TC_FLAGS_UPDATE_USB_MUX);
- pd_set_dual_role_and_event(i,
- pd_get_drp_state_in_suspend(),
- PD_EVENT_UPDATE_DUAL_ROLE
- | PD_EVENT_POWER_STATE_CHANGE);
+ pd_set_dual_role_and_event(i, pd_get_drp_state_in_suspend(),
+ PD_EVENT_UPDATE_DUAL_ROLE |
+ PD_EVENT_POWER_STATE_CHANGE);
/*
* Request port discovery to restore any
* alt modes.
@@ -4010,7 +4013,7 @@ static void pd_chipset_startup(void)
if (tc[i].data_role == PD_ROLE_DFP) {
pd_send_alert_msg(i, ADO_EXTENDED_ALERT_EVENT |
- ADO_POWER_STATE_CHANGE);
+ ADO_POWER_STATE_CHANGE);
}
}
@@ -4024,14 +4027,13 @@ static void pd_chipset_shutdown(void)
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
TC_SET_FLAG(i, TC_FLAGS_UPDATE_USB_MUX);
- pd_set_dual_role_and_event(i,
- PD_DRP_FORCE_SINK,
- PD_EVENT_UPDATE_DUAL_ROLE
- | PD_EVENT_POWER_STATE_CHANGE);
+ pd_set_dual_role_and_event(i, PD_DRP_FORCE_SINK,
+ PD_EVENT_UPDATE_DUAL_ROLE |
+ PD_EVENT_POWER_STATE_CHANGE);
if (tc[i].data_role == PD_ROLE_DFP) {
pd_send_alert_msg(i, ADO_EXTENDED_ALERT_EVENT |
- ADO_POWER_STATE_CHANGE);
+ ADO_POWER_STATE_CHANGE);
}
}
diff --git a/common/usbc/usb_tc_vpd_sm.c b/common/usbc/usb_tc_vpd_sm.c
index 70f3ed6327..40b855db9b 100644
--- a/common/usbc/usb_tc_vpd_sm.c
+++ b/common/usbc/usb_tc_vpd_sm.c
@@ -1,8 +1,9 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "system.h"
@@ -17,15 +18,15 @@
/* USB Type-C VCONN Powered Device module */
#ifdef CONFIG_COMMON_RUNTIME
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USB, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USB, format, ##args)
#else /* CONFIG_COMMON_RUNTIME */
#define CPRINTF(format, args...)
#define CPRINTS(format, args...)
#endif
/* Type-C Layer Flags */
-#define TC_FLAGS_VCONN_ON BIT(0)
+#define TC_FLAGS_VCONN_ON BIT(0)
/**
* This is the Type-C Port object that contains information needed to
@@ -61,7 +62,7 @@ enum usb_tc_state {
static const struct usb_state tc_states[];
/* List of human readable state names for console debugging */
-__maybe_unused static const char * const tc_state_names[] = {
+__maybe_unused static const char *const tc_state_names[] = {
#ifdef CONFIG_COMMON_RUNTIME
[TC_DISABLED] = "Disabled",
[TC_UNATTACHED_SNK] = "Unattached.SNK",
@@ -270,11 +271,11 @@ static void tc_attach_wait_snk_run(const int port)
if (tc[port].host_cc_state != host_new_cc_state) {
tc[port].host_cc_state = host_new_cc_state;
if (host_new_cc_state == PD_CC_DFP_ATTACHED)
- tc[port].cc_debounce = get_time().val +
- PD_T_CC_DEBOUNCE;
+ tc[port].cc_debounce =
+ get_time().val + PD_T_CC_DEBOUNCE;
else
- tc[port].cc_debounce = get_time().val +
- PD_T_PD_DEBOUNCE;
+ tc[port].cc_debounce =
+ get_time().val + PD_T_PD_DEBOUNCE;
return;
}
@@ -293,7 +294,7 @@ static void tc_attach_wait_snk_run(const int port)
* CC2 pins is SNK.Open for at least tPDDebounce.
*/
if (tc[port].host_cc_state == PD_CC_DFP_ATTACHED &&
- (vpd_is_vconn_present() || vpd_is_host_vbus_present()))
+ (vpd_is_vconn_present() || vpd_is_host_vbus_present()))
set_state_tc(port, TC_ATTACHED_SNK);
else if (tc[port].host_cc_state == PD_CC_NONE)
set_state_tc(port, TC_UNATTACHED_SNK);
diff --git a/common/usbc/usbc_pd_policy.c b/common/usbc/usbc_pd_policy.c
index 6a06d4014f..6d82ed114c 100644
--- a/common/usbc/usbc_pd_policy.c
+++ b/common/usbc/usbc_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.
*/
@@ -19,8 +19,8 @@
* 1) If dr_swap_to_dfp_flag == true and port data role is UFP,
* transition to pe_drs_send_swap
*/
-__overridable bool port_discovery_dr_swap_policy(int port,
- enum pd_data_role dr, bool dr_swap_flag)
+__overridable bool port_discovery_dr_swap_policy(int port, enum pd_data_role dr,
+ bool dr_swap_flag)
{
if (dr_swap_flag && dr == PD_ROLE_UFP)
return true;
@@ -37,10 +37,10 @@ __overridable bool port_discovery_dr_swap_policy(int port,
* then transition to pe_vcs_send_swap
*/
__overridable bool port_discovery_vconn_swap_policy(int port,
- bool vconn_swap_flag)
+ bool vconn_swap_flag)
{
if (IS_ENABLED(CONFIG_USBC_VCONN) && vconn_swap_flag &&
- !tc_is_vconn_src(port) && tc_check_vconn_swap(port))
+ !tc_is_vconn_src(port) && tc_check_vconn_swap(port))
return true;
/* Do not perform a VCONN swap */
diff --git a/common/usbc/usbc_task.c b/common/usbc/usbc_task.c
index 915827b692..56ea3d4d10 100644
--- a/common/usbc/usbc_task.c
+++ b/common/usbc/usbc_task.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+/* Copyright 2019 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
#include "battery.h"
#include "battery_smart.h"
#include "board.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "chipset.h"
@@ -36,8 +37,8 @@
#define USBC_EVENT_TIMEOUT (5 * MSEC)
#define USBC_MIN_EVENT_TIMEOUT (1 * MSEC)
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
/*
* If CONFIG_ASSERT_CCD_MODE_ON_DTS_CONNECT is not defined then
diff --git a/common/usbc_intr_task.c b/common/usbc_intr_task.c
index 0532645a35..3c67ba4102 100644
--- a/common/usbc_intr_task.c
+++ b/common/usbc_intr_task.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,7 +7,7 @@
#include <stdint.h>
-#include "assert.h"
+#include "builtin/assert.h"
#include "common.h"
#include "compile_time_macros.h"
#include "console.h"
@@ -18,19 +18,19 @@
#include "usb_pd.h"
#include "usb_pd_tcpm.h"
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
/* Events for pd_interrupt_handler_task */
-#define PD_PROCESS_INTERRUPT BIT(0)
+#define PD_PROCESS_INTERRUPT BIT(0)
/*
* Theoretically, we may need to support up to 480 USB-PD packets per second for
* intensive operations such as FW update over PD. This value has tested well
* preventing watchdog resets with a single bad port partner plugged in.
*/
-#define ALERT_STORM_MAX_COUNT 480
-#define ALERT_STORM_INTERVAL SECOND
+#define ALERT_STORM_MAX_COUNT 480
+#define ALERT_STORM_INTERVAL SECOND
static uint8_t pd_int_task_id[CONFIG_USB_PD_PORT_MAX_COUNT];
@@ -57,8 +57,7 @@ static void service_one_port(int port)
tcpc_alert(port);
now = get_time();
- if (timestamp_expired(storm_tracker[port].time,
- &now)) {
+ if (timestamp_expired(storm_tracker[port].time, &now)) {
/* Reset timer into future */
storm_tracker[port].time.val = now.val + ALERT_STORM_INTERVAL;
@@ -91,7 +90,7 @@ __overridable void board_process_pd_alert(int port)
*/
void pd_interrupt_handler_task(void *p)
{
- const int port = (int) ((intptr_t) p);
+ const int port = (int)((intptr_t)p);
const int port_mask = (PD_STATUS_TCPC_ALERT_0 << port);
ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_MAX_COUNT);
@@ -122,7 +121,6 @@ void pd_interrupt_handler_task(void *p)
*/
while ((tcpc_get_alert_status() & port_mask) &&
pd_is_port_enabled(port)) {
-
service_one_port(port);
}
@@ -145,9 +143,10 @@ BUILD_ASSERT(PD_STATUS_TCPC_ALERT_3 == (PD_STATUS_TCPC_ALERT_0 << 3));
* is not.
*/
+#if !defined(CONFIG_ZEPHYR) || defined(CONFIG_HAS_TASK_PD_INT_SHARED)
void pd_shared_alert_task(void *p)
{
- const int sources_mask = (int) ((intptr_t) p);
+ const int sources_mask = (int)((intptr_t)p);
int want_alerts = 0;
int port;
int port_mask;
@@ -211,3 +210,4 @@ void pd_shared_alert_task(void *p)
} while (have_alerts != 0);
}
}
+#endif /* !CONFIG_ZEPHYR || CONFIG_HAS_TASK_PD_INT_SHARED */
diff --git a/common/usbc_ocp.c b/common/usbc_ocp.c
index 3694cfec7e..ba975b6105 100644
--- a/common/usbc_ocp.c
+++ b/common/usbc_ocp.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,37 +16,14 @@
#include "util.h"
#ifndef TEST_BUILD
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(args...)
#define CPRINTS(args...)
#endif
/*
- * PD 3.1 Ver 1.3 7.1.7.1 Output Over Current Protection
- *
- * "After three consecutive over current events Source Shall go to
- * ErrorRecovery.
- *
- * Sources Should attempt to send a Hard Reset message when over
- * current protection engages followed by an Alert Message indicating
- * an OCP event once an Explicit Contract has been established.
- *
- * The Source Shall prevent continual system or port cycling if over
- * current protection continues to engage after initially resuming
- * either default operation or renegotiation. Latching off the port or
- * system is an acceptable response to recurring over current."
- *
- * Our policy will be first two OCPs -> hard reset
- * 3rd -> ErrorRecovery
- * 4th -> port latched off
- */
-#define OCP_HR_CNT 2
-
-#define OCP_MAX_CNT 4
-
-/*
* Number of seconds until a latched-off port is re-enabled for sourcing after
* detecting a physical disconnect.
*/
@@ -102,7 +79,6 @@ static void re_enable_ports(void)
}
DECLARE_DEFERRED(re_enable_ports);
-
int usbc_ocp_add_event(int port)
{
int delay = 0;
@@ -122,8 +98,8 @@ int usbc_ocp_add_event(int port)
if (oc_event_cnt_tbl[port] >= OCP_MAX_CNT) {
CPRINTS("C%d: OC event limit reached! "
- "Source path disabled until physical disconnect.",
- port);
+ "Source path disabled until physical disconnect.",
+ port);
pd_power_supply_reset(port);
} else if (oc_event_cnt_tbl[port] <= OCP_HR_CNT) {
/*
@@ -132,7 +108,7 @@ int usbc_ocp_add_event(int port)
* contract.
*/
pd_send_hard_reset(port);
- delay = PD_T_SRC_RECOVER + 100*MSEC;
+ delay = PD_T_SRC_RECOVER + 100 * MSEC;
} else {
/*
* ErrorRecovery must be performed past the third OCP event,
@@ -140,7 +116,7 @@ int usbc_ocp_add_event(int port)
* contract is in place
*/
pd_set_error_recovery(port);
- delay = PD_T_ERROR_RECOVERY + 100*MSEC;
+ delay = PD_T_ERROR_RECOVERY + 100 * MSEC;
}
if (delay) {
@@ -148,11 +124,9 @@ int usbc_ocp_add_event(int port)
hook_call_deferred(&re_enable_ports_data, delay);
}
-
return EC_SUCCESS;
}
-
int usbc_ocp_clear_event_counter(int port)
{
if ((port < 0) || (port >= board_get_usb_pd_port_count())) {
@@ -168,8 +142,7 @@ int usbc_ocp_clear_event_counter(int port)
* actually detect the physical disconnect.
*/
if (oc_event_cnt_tbl[port]) {
- hook_call_deferred(&clear_oc_tbl_data,
- OCP_COOLDOWN_DELAY_US);
+ hook_call_deferred(&clear_oc_tbl_data, OCP_COOLDOWN_DELAY_US);
}
return EC_SUCCESS;
}
diff --git a/common/usbc_ppc.c b/common/usbc_ppc.c
index f6c7f6876d..bc626097f7 100644
--- a/common/usbc_ppc.c
+++ b/common/usbc_ppc.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -15,8 +15,8 @@
#include "util.h"
#ifndef TEST_BUILD
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)
#else
#define CPRINTF(args...)
#define CPRINTS(args...)
@@ -24,20 +24,20 @@
int ppc_prints(const char *string, int port)
{
-#ifndef TEST_BUILD
- return CPRINTS("ppc p%d %s", port, string);
-#else
+#if defined(TEST_BUILD) || !defined(CONFIG_USBC_PPC_LOGGING)
return 0;
-#endif
+#else
+ return CPRINTS("ppc p%d %s", port, string);
+#endif /* defined(TEST_BUILD) || !defined(CONFIG_USBC_PPC_LOGGING) */
}
int ppc_err_prints(const char *string, int port, int error)
{
-#ifndef TEST_BUILD
- return CPRINTS("ppc p%d %s (%d)", port, string, error);
-#else
+#if defined(TEST_BUILD) || !defined(CONFIG_USBC_PPC_LOGGING)
return 0;
-#endif
+#else
+ return CPRINTS("ppc p%d %s (%d)", port, string, error);
+#endif /* defined(TEST_BUILD) || !defined(CONFIG_USBC_PPC_LOGGING) */
}
__overridable bool board_port_has_ppc(int port)
@@ -277,7 +277,7 @@ int ppc_set_frs_enable(int port, int enable)
ppc = &ppc_chips[port];
if (ppc->drv->set_frs_enable)
- rv = ppc->drv->set_frs_enable(port,enable);
+ rv = ppc->drv->set_frs_enable(port, enable);
return rv;
}
@@ -304,7 +304,7 @@ int ppc_is_vbus_present(int port)
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
#ifdef CONFIG_CMD_PPC_DUMP
-static int command_ppc_dump(int argc, char **argv)
+static int command_ppc_dump(int argc, const char **argv)
{
int port;
int rv = EC_ERROR_UNIMPLEMENTED;
diff --git a/common/util.c b/common/util.c
index 7b33cc097e..7672dc1325 100644
--- a/common/util.c
+++ b/common/util.c
@@ -1,30 +1,19 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Utility functions for Chrome EC */
+#include "builtin/assert.h"
#include "common.h"
#include "console.h"
#include "util.h"
-__stdlib_compat int strcasecmp(const char *s1, const char *s2)
+int find_base(int base, int *c, const char **nptr)
{
- int diff;
-
- do {
- diff = tolower(*s1) - tolower(*s2);
- if (diff)
- return diff;
- } while (*(s1++) && *(s2++));
- return 0;
-}
-
-static int find_base(int base, int *c, const char **nptr)
-{
- if ((base == 0 || base == 16) && *c == '0'
- && (**nptr == 'x' || **nptr == 'X')) {
+ if ((base == 0 || base == 16) && *c == '0' &&
+ (**nptr == 'x' || **nptr == 'X')) {
*c = (*nptr)[1];
(*nptr) += 2;
base = 16;
@@ -35,7 +24,7 @@ static int find_base(int base, int *c, const char **nptr)
}
/* Like strtol(), but for integers */
-__stdlib_compat int strtoi(const char *nptr, char **endptr, int base)
+int strtoi(const char *nptr, char **endptr, int base)
{
int result = 0;
int neg = 0;
@@ -71,58 +60,20 @@ __stdlib_compat int strtoi(const char *nptr, char **endptr, int base)
return neg ? -result : result;
}
-#ifndef CONFIG_ZEPHYR
-__stdlib_compat unsigned long long int strtoull(const char *nptr, char **endptr,
- int base)
-{
- uint64_t result = 0;
- int c = '\0';
-
- while ((c = *nptr++) && isspace(c))
- ;
-
- if (c == '+') {
- c = *nptr++;
- } else if (c == '-') {
- if (endptr)
- *endptr = (char *)nptr - 1;
- return result;
- }
-
- base = find_base(base, &c, &nptr);
-
- while (c) {
- if (c >= '0' && c < '0' + MIN(base, 10))
- result = result * base + (c - '0');
- else if (c >= 'A' && c < 'A' + base - 10)
- result = result * base + (c - 'A' + 10);
- else if (c >= 'a' && c < 'a' + base - 10)
- result = result * base + (c - 'a' + 10);
- else
- break;
-
- c = *nptr++;
- }
-
- if (endptr)
- *endptr = (char *)nptr - 1;
- return result;
-}
-#endif /* !CONFIG_ZEPHYR */
-BUILD_ASSERT(sizeof(unsigned long long int) == sizeof(uint64_t));
-
-__stdlib_compat int parse_bool(const char *s, int *dest)
+int parse_bool(const char *s, int *dest)
{
/* off, disable, false, no */
if (!strcasecmp(s, "off") || !strncasecmp(s, "dis", 3) ||
- tolower(*s) == 'f' || tolower(*s) == 'n') {
+ tolower((unsigned char)*s) == 'f' ||
+ tolower((unsigned char)*s) == 'n') {
*dest = 0;
return 1;
}
/* on, enable, true, yes */
if (!strcasecmp(s, "on") || !strncasecmp(s, "ena", 3) ||
- tolower(*s) == 't' || tolower(*s) == 'y') {
+ tolower((unsigned char)*s) == 't' ||
+ tolower((unsigned char)*s) == 'y') {
*dest = 1;
return 1;
}
@@ -131,7 +82,6 @@ __stdlib_compat int parse_bool(const char *s, int *dest)
return 0;
}
-
/* Constant-time memory comparison */
int safe_memcmp(const void *s1, const void *s2, size_t size)
{
@@ -166,7 +116,7 @@ void reverse(void *dest, size_t len)
}
}
-__stdlib_compat char *strzcpy(char *dest, const char *src, int len)
+char *strzcpy(char *dest, const char *src, int len)
{
char *d = dest;
if (len <= 0)
@@ -253,7 +203,7 @@ bool is_aligned(uint32_t addr, uint32_t align)
int alignment_log2(unsigned int x)
{
- ASSERT(x != 0); /* ctz(0) is undefined */
+ ASSERT(x != 0); /* ctz(0) is undefined */
return __builtin_ctz(x);
}
@@ -261,9 +211,9 @@ int alignment_log2(unsigned int x)
/* stateful conditional stuff */
enum cond_internal_bits {
- COND_CURR_MASK = BIT(0), /* current value */
- COND_RISE_MASK = BIT(1), /* set if 0->1 */
- COND_FALL_MASK = BIT(2), /* set if 1->0 */
+ COND_CURR_MASK = BIT(0), /* current value */
+ COND_RISE_MASK = BIT(1), /* set if 0->1 */
+ COND_FALL_MASK = BIT(2), /* set if 1->0 */
};
void cond_init(cond_t *c, int val)
@@ -319,8 +269,8 @@ int cond_went(cond_t *c, int val)
* *offset<0. If argc<shift+1, leaves size unchanged, returning error if
* *size<0.
*/
-int parse_offset_size(int argc, char **argv, int shift,
- int *offset, int *size)
+int parse_offset_size(int argc, const char **argv, int shift, int *offset,
+ int *size)
{
char *e;
int i;
@@ -417,10 +367,10 @@ int binary_first_base3_from_bits(int *bits, int nbits)
switch (bits[i]) {
case 0: /* Ignore '0' digits. */
break;
- case 1: /* Account for binaries 0 to 2^i - 1. */
+ case 1: /* Account for binaries 0 to 2^i - 1. */
binary_below += 1 << i;
break;
- case 2: /* Account for binaries 0 to 2^(i+1) - 1. */
+ case 2: /* Account for binaries 0 to 2^(i+1) - 1. */
binary_below += 1 << (i + 1);
has_z = 1;
}
diff --git a/common/util_stdlib.c b/common/util_stdlib.c
deleted file mode 100644
index 7e59b0fbc5..0000000000
--- a/common/util_stdlib.c
+++ /dev/null
@@ -1,332 +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.
- */
-
-/* Standard library utility functions for Chrome EC */
-
-#include "common.h"
-#include "console.h"
-#include "util.h"
-
-__stdlib_compat size_t strlen(const char *s)
-{
- int len = 0;
-
- while (*s++)
- len++;
-
- return len;
-}
-
-__stdlib_compat size_t strnlen(const char *s, size_t maxlen)
-{
- size_t len = 0;
-
- while (len < maxlen && *s) {
- s++;
- len++;
- }
- return len;
-}
-
-__stdlib_compat size_t strcspn(const char *s, const char *reject)
-{
- size_t i;
- size_t reject_len = strlen(reject);
-
- for (i = 0; s[i] != 0; i++)
- for (size_t j = 0; j < reject_len; j++)
- if (s[i] == reject[j])
- return i;
- return i;
-}
-
-__stdlib_compat int isspace(int c)
-{
- return c == ' ' || c == '\t' || c == '\r' || c == '\n';
-}
-
-__stdlib_compat int isdigit(int c)
-{
- return c >= '0' && c <= '9';
-}
-
-__stdlib_compat int isalpha(int c)
-{
- return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
-}
-
-__stdlib_compat int isupper(int c)
-{
- return c >= 'A' && c <= 'Z';
-}
-
-__stdlib_compat int isprint(int c)
-{
- return c >= ' ' && c <= '~';
-}
-
-__stdlib_compat int tolower(int c)
-{
- return c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c;
-}
-
-__stdlib_compat int strncasecmp(const char *s1, const char *s2, size_t size)
-{
- int diff;
-
- if (!size)
- return 0;
-
- do {
- diff = tolower(*s1) - tolower(*s2);
- if (diff)
- return diff;
- } while (*(s1++) && *(s2++) && --size);
- return 0;
-}
-
-__stdlib_compat char *strstr(const char *s1, const char *s2)
-{
- const char *p, *q, *r;
- size_t len1 = strlen(s1);
- size_t len2 = strlen(s2);
-
- if (len1 == 0 || len2 == 0 || len1 < len2)
- return NULL;
-
- r = s1 + len1 - len2 + 1;
- for (; s1 < r; s1++) {
- if (*s1 == *s2) {
- p = s1 + 1;
- q = s2 + 1;
- for (; q < s2 + len2;) {
- if (*p++ != *q++)
- break;
- }
- if (*q == '\0')
- return (char *)s1;
- }
- }
- return NULL;
-}
-
-__stdlib_compat int atoi(const char *nptr)
-{
- int result = 0;
- int neg = 0;
- char c = '\0';
-
- while ((c = *nptr++) && isspace(c))
- ;
-
- if (c == '-') {
- neg = 1;
- c = *nptr++;
- }
-
- while (isdigit(c)) {
- result = result * 10 + (c - '0');
- c = *nptr++;
- }
-
- return neg ? -result : result;
-}
-
-__keep
-__stdlib_compat int memcmp(const void *s1, const void *s2, size_t len)
-{
- const char *sa = s1;
- const char *sb = s2;
- int diff = 0;
-
- while (len-- > 0) {
- diff = *(sa++) - *(sb++);
- if (diff)
- return diff;
- }
-
- return 0;
-}
-
-#if !(__has_feature(address_sanitizer) || __has_feature(memory_sanitizer))
-__keep
-__stdlib_compat void *memcpy(void *dest, const void *src, size_t len)
-{
- char *d = (char *)dest;
- const char *s = (const char *)src;
- uint32_t *dw;
- const uint32_t *sw;
- char *head;
- char * const tail = (char *)dest + len;
- /* Set 'body' to the last word boundary */
- uint32_t * const body = (uint32_t *)((uintptr_t)tail & ~3);
-
- if (((uintptr_t)dest & 3) != ((uintptr_t)src & 3)) {
- /* Misaligned. no body, no tail. */
- head = tail;
- } else {
- /* Aligned */
- if ((uintptr_t)tail < (((uintptr_t)d + 3) & ~3))
- /* len is shorter than the first word boundary */
- head = tail;
- else
- /* Set 'head' to the first word boundary */
- head = (char *)(((uintptr_t)d + 3) & ~3);
- }
-
- /* Copy head */
- while (d < head)
- *(d++) = *(s++);
-
- /* Copy body */
- dw = (uint32_t *)d;
- sw = (uint32_t *)s;
- while (dw < body)
- *(dw++) = *(sw++);
-
- /* Copy tail */
- d = (char *)dw;
- s = (const char *)sw;
- while (d < tail)
- *(d++) = *(s++);
-
- return dest;
-}
-#endif /* address_sanitizer || memory_sanitizer */
-
-#if !(__has_feature(address_sanitizer) || __has_feature(memory_sanitizer))
-__keep
-__stdlib_compat __visible void *memset(void *dest, int c, size_t len)
-{
- char *d = (char *)dest;
- uint32_t cccc;
- uint32_t *dw;
- char *head;
- char * const tail = (char *)dest + len;
- /* Set 'body' to the last word boundary */
- uint32_t * const body = (uint32_t *)((uintptr_t)tail & ~3);
-
- c &= 0xff; /* Clear upper bits before ORing below */
- cccc = c | (c << 8) | (c << 16) | (c << 24);
-
- if ((uintptr_t)tail < (((uintptr_t)d + 3) & ~3))
- /* len is shorter than the first word boundary */
- head = tail;
- else
- /* Set 'head' to the first word boundary */
- head = (char *)(((uintptr_t)d + 3) & ~3);
-
- /* Copy head */
- while (d < head)
- *(d++) = c;
-
- /* Copy body */
- dw = (uint32_t *)d;
- while (dw < body)
- *(dw++) = cccc;
-
- /* Copy tail */
- d = (char *)dw;
- while (d < tail)
- *(d++) = c;
-
- return dest;
-}
-#endif /* address_sanitizer || memory_sanitizer */
-
-#if !(__has_feature(address_sanitizer) || __has_feature(memory_sanitizer))
-__keep
-__stdlib_compat void *memmove(void *dest, const void *src, size_t len)
-{
- if ((uintptr_t)dest <= (uintptr_t)src ||
- (uintptr_t)dest >= (uintptr_t)src + len) {
- /* Start of destination doesn't overlap source, so just use
- * memcpy().
- */
- return memcpy(dest, src, len);
- } else {
- /* Need to copy from tail because there is overlap. */
- char *d = (char *)dest + len;
- const char *s = (const char *)src + len;
- uint32_t *dw;
- const uint32_t *sw;
- char *head;
- char * const tail = (char *)dest;
- /* Set 'body' to the last word boundary */
- uint32_t * const body = (uint32_t *)(((uintptr_t)tail+3) & ~3);
-
- if (((uintptr_t)dest & 3) != ((uintptr_t)src & 3)) {
- /* Misaligned. no body, no tail. */
- head = tail;
- } else {
- /* Aligned */
- if ((uintptr_t)tail > ((uintptr_t)d & ~3))
- /* Shorter than the first word boundary */
- head = tail;
- else
- /* Set 'head' to the first word boundary */
- head = (char *)((uintptr_t)d & ~3);
- }
-
- /* Copy head */
- while (d > head)
- *(--d) = *(--s);
-
- /* Copy body */
- dw = (uint32_t *)d;
- sw = (uint32_t *)s;
- while (dw > body)
- *(--dw) = *(--sw);
-
- /* Copy tail */
- d = (char *)dw;
- s = (const char *)sw;
- while (d > tail)
- *(--d) = *(--s);
-
- return dest;
- }
-}
-#endif /* address_sanitizer || memory_sanitizer */
-
-__stdlib_compat void *memchr(const void *buffer, int c, size_t n)
-{
- char *current = (char *)buffer;
- char *end = current + n;
-
- while (current != end) {
- if (*current == c)
- return current;
- current++;
- }
- return NULL;
-}
-
-__stdlib_compat char *strncpy(char *dest, const char *src, size_t n)
-{
- char *d = dest;
-
- while (n && *src) {
- *d++ = *src++;
- n--;
- }
- if (n)
- *d = '\0';
- return dest;
-}
-
-__stdlib_compat int strncmp(const char *s1, const char *s2, size_t n)
-{
- while (n--) {
- if (*s1 != *s2)
- return *s1 - *s2;
- if (!*s1)
- break;
- s1++;
- s2++;
-
- }
- return 0;
-}
diff --git a/common/vboot/common.c b/common/vboot/common.c
index 39f8c193c7..a92652364b 100644
--- a/common/vboot/common.c
+++ b/common/vboot/common.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,8 +10,8 @@
#include "shared_mem.h"
#include "vboot.h"
-#define CPRINTS(format, args...) cprints(CC_VBOOT, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_VBOOT, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_VBOOT, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_VBOOT, format, ##args)
int vboot_is_padding_valid(const uint8_t *data, uint32_t start, uint32_t end)
{
@@ -32,8 +32,8 @@ int vboot_is_padding_valid(const uint8_t *data, uint32_t start, uint32_t end)
return EC_SUCCESS;
}
-int vboot_verify(const uint8_t *data, int len,
- const struct rsa_public_key *key, const uint8_t *sig)
+int vboot_verify(const uint8_t *data, int len, const struct rsa_public_key *key,
+ const uint8_t *sig)
{
struct sha256_ctx ctx;
uint8_t *hash;
diff --git a/common/vboot/efs2.c b/common/vboot/efs2.c
index a410c274f5..b45109029d 100644
--- a/common/vboot/efs2.c
+++ b/common/vboot/efs2.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -26,19 +26,23 @@
#include "vboot.h"
#include "vboot_hash.h"
-#define CPRINTS(format, args...) cprints(CC_VBOOT,"VB " format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_VBOOT,"VB " format, ## args)
+#define CPRINTS(format, args...) cprints(CC_VBOOT, "VB " format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_VBOOT, "VB " format, ##args)
+/* LCOV_EXCL_START - TODO(b/172210316) implement is_battery_ready(), and remove
+ * this lcov excl.
+ */
static const char *boot_mode_to_string(uint8_t mode)
{
static const char *boot_mode_str[] = {
- [BOOT_MODE_NORMAL] = "NORMAL",
- [BOOT_MODE_NO_BOOT] = "NO_BOOT",
+ [BOOT_MODE_NORMAL] = "NORMAL",
+ [BOOT_MODE_NO_BOOT] = "NO_BOOT",
};
if (mode < ARRAY_SIZE(boot_mode_str))
return boot_mode_str[mode];
return "UNDEF";
}
+/* LCOV_EXCL_STOP */
/*
* Check whether the session has successfully ended or not. ERR_TIMEOUT is
@@ -46,8 +50,8 @@ static const char *boot_mode_to_string(uint8_t mode)
*/
static bool is_valid_cr50_response(enum cr50_comm_err code)
{
- return code != CR50_COMM_ERR_TIMEOUT
- && (code >> 8) == CR50_COMM_ERR_PREFIX;
+ return code != CR50_COMM_ERR_TIMEOUT &&
+ (code >> 8) == CR50_COMM_ERR_PREFIX;
}
__overridable void board_enable_packet_mode(bool enable)
@@ -74,8 +78,13 @@ static enum cr50_comm_err send_to_cr50(const uint8_t *data, size_t size)
if (uart_shell_stop()) {
/* Failed to stop the shell. */
+ /* LCOV_EXCL_START - At least on posix systems, uart_shell_stop
+ * will never fail, it will crash the binary or hang forever on
+ * error.
+ */
board_enable_packet_mode(false);
return CR50_COMM_ERR_UNKNOWN;
+ /* LCOV_EXCL_STOP */
}
/*
@@ -108,7 +117,7 @@ static enum cr50_comm_err send_to_cr50(const uint8_t *data, size_t size)
while (!timeout) {
int c = uart_getc();
if (c != -1) {
- res.error = res.error | c << (i*8);
+ res.error = res.error | c << (i * 8);
break;
}
msleep(1);
@@ -159,7 +168,7 @@ static enum cr50_comm_err cmd_to_cr50(enum cr50_comm_cmd cmd,
p->size = size;
memcpy(p->data, data, size);
p->crc = cros_crc8((uint8_t *)&p->type,
- sizeof(p->type) + sizeof(p->size) + size);
+ sizeof(p->type) + sizeof(p->size) + size);
do {
rv = send_to_cr50((uint8_t *)&s,
@@ -191,17 +200,21 @@ static enum cr50_comm_err verify_hash(void)
return cmd_to_cr50(CR50_COMM_CMD_VERIFY_HASH, hash, SHA256_DIGEST_SIZE);
}
+/* LCOV_EXCL_START - TODO(b/172210316) implement is_battery_ready(), and remove
+ * this lcov excl.
+ */
static enum cr50_comm_err set_boot_mode(uint8_t mode)
{
enum cr50_comm_err rv;
CPRINTS("Setting boot mode to %s(%d)", boot_mode_to_string(mode), mode);
- rv = cmd_to_cr50(CR50_COMM_CMD_SET_BOOT_MODE,
- &mode, sizeof(enum boot_mode));
+ rv = cmd_to_cr50(CR50_COMM_CMD_SET_BOOT_MODE, &mode,
+ sizeof(enum boot_mode));
if (rv != CR50_COMM_SUCCESS)
CPRINTS("Failed to set boot mode");
return rv;
}
+/* LCOV_EXCL_STOP */
static bool pd_comm_enabled;
@@ -216,10 +229,19 @@ bool vboot_allow_usb_pd(void)
return pd_comm_enabled;
}
+#ifdef TEST_BUILD
+void vboot_disable_pd(void)
+{
+ pd_comm_enabled = false;
+}
+#endif
+
+/* LCOV_EXCL_START - This is just a stub intended to be overridden */
__overridable void show_critical_error(void)
{
CPRINTS("%s", __func__);
}
+/* LCOV_EXCL_STOP */
static void verify_and_jump(void)
{
@@ -244,14 +266,16 @@ static void verify_and_jump(void)
}
}
+/* LCOV_EXCL_START - This is just a stub intended to be overridden */
__overridable void show_power_shortage(void)
{
CPRINTS("%s", __func__);
}
+/* LCOV_EXCL_STOP */
static bool is_battery_ready(void)
{
- /* TODO: Add battery check (https://crbug.com/1045216) */
+ /* TODO(b/172210316): Add battery check */
return true;
}
@@ -274,8 +298,8 @@ void vboot_main(void)
(system_get_reset_flags() & EC_RESET_FLAG_STAY_IN_RO)) {
if (system_is_manual_recovery())
CPRINTS("In recovery mode");
- if (!IS_ENABLED(CONFIG_BATTERY)
- && !IS_ENABLED(HAS_TASK_KEYSCAN)) {
+ if (!IS_ENABLED(CONFIG_BATTERY) &&
+ !IS_ENABLED(HAS_TASK_KEYSCAN)) {
/*
* For Chromeboxes, we relax security by allowing PD in
* RO. Attackers don't gain meaningful advantage on
@@ -293,12 +317,16 @@ void vboot_main(void)
* If battery is drained or bad, we will boot in NO_BOOT mode to
* inform the user of the problem.
*/
+ /* LCOV_EXCL_START - TODO(b/172210316) implement
+ * is_battery_ready(), and remove this lcov excl.
+ */
if (!is_battery_ready()) {
CPRINTS("Battery not ready or bad");
if (set_boot_mode(BOOT_MODE_NO_BOOT) ==
- CR50_COMM_SUCCESS)
+ CR50_COMM_SUCCESS)
enable_pd();
}
+ /* LCOV_EXCL_STOP */
/* We'll enter recovery mode immediately, later, or never. */
return;
diff --git a/common/vboot/vb21_lib.c b/common/vboot/vb21_lib.c
index 4e215c14e5..ab7628371f 100644
--- a/common/vboot/vb21_lib.c
+++ b/common/vboot/vb21_lib.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -52,7 +52,6 @@ const struct vb21_packed_key *vb21_get_packed_key(void)
static void read_rwsig_info(struct ec_response_rwsig_info *r)
{
-
const struct vb21_packed_key *vb21_key;
int rv;
@@ -61,17 +60,21 @@ static void read_rwsig_info(struct ec_response_rwsig_info *r)
r->sig_alg = vb21_key->sig_alg;
r->hash_alg = vb21_key->hash_alg;
r->key_version = vb21_key->key_version;
- { BUILD_ASSERT(sizeof(r->key_id) == sizeof(vb21_key->id),
- "key ID sizes must match"); }
- { BUILD_ASSERT(sizeof(vb21_key->id) == sizeof(vb21_key->id.raw),
- "key ID sizes must match"); }
+ {
+ BUILD_ASSERT(sizeof(r->key_id) == sizeof(vb21_key->id),
+ "key ID sizes must match");
+ }
+ {
+ BUILD_ASSERT(sizeof(vb21_key->id) == sizeof(vb21_key->id.raw),
+ "key ID sizes must match");
+ }
memcpy(r->key_id, vb21_key->id.raw, sizeof(r->key_id));
rv = vb21_is_packed_key_valid(vb21_key);
r->key_is_valid = (rv == EC_SUCCESS);
}
-static int command_rwsig_info(int argc, char **argv)
+static int command_rwsig_info(int argc, const char **argv)
{
int i;
struct ec_response_rwsig_info r;
diff --git a/common/vboot/vboot.c b/common/vboot/vboot.c
index 910156335d..cf449da1b8 100644
--- a/common/vboot/vboot.c
+++ b/common/vboot/vboot.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -25,8 +25,8 @@
#include "vboot.h"
#include "vb21_struct.h"
-#define CPRINTS(format, args...) cprints(CC_VBOOT,"VB " format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_VBOOT,"VB " format, ## args)
+#define CPRINTS(format, args...) cprints(CC_VBOOT, "VB " format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_VBOOT, "VB " format, ##args)
static int has_matrix_keyboard(void)
{
@@ -45,34 +45,34 @@ static int verify_slot(enum ec_image slot)
CPRINTS("Verifying %s", ec_image_to_string(slot));
- vb21_key = (const struct vb21_packed_key *)(
- CONFIG_MAPPED_STORAGE_BASE +
- CONFIG_EC_PROTECTED_STORAGE_OFF +
- CONFIG_RO_PUBKEY_STORAGE_OFF);
+ vb21_key =
+ (const struct vb21_packed_key *)(CONFIG_MAPPED_STORAGE_BASE +
+ CONFIG_EC_PROTECTED_STORAGE_OFF +
+ CONFIG_RO_PUBKEY_STORAGE_OFF);
rv = vb21_is_packed_key_valid(vb21_key);
if (rv) {
CPRINTS("Invalid key (%d)", rv);
return EC_ERROR_VBOOT_KEY;
}
- key = (const struct rsa_public_key *)
- ((const uint8_t *)vb21_key + vb21_key->key_offset);
+ key = (const struct rsa_public_key *)((const uint8_t *)vb21_key +
+ vb21_key->key_offset);
if (slot == EC_IMAGE_RW_A) {
data = (const uint8_t *)(CONFIG_MAPPED_STORAGE_BASE +
- CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_A_STORAGE_OFF);
- vb21_sig = (const struct vb21_signature *)(
- CONFIG_MAPPED_STORAGE_BASE +
- CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_A_SIGN_STORAGE_OFF);
+ CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_A_STORAGE_OFF);
+ vb21_sig = (const struct vb21_signature
+ *)(CONFIG_MAPPED_STORAGE_BASE +
+ CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_A_SIGN_STORAGE_OFF);
} else {
data = (const uint8_t *)(CONFIG_MAPPED_STORAGE_BASE +
- CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_B_STORAGE_OFF);
- vb21_sig = (const struct vb21_signature *)(
- CONFIG_MAPPED_STORAGE_BASE +
- CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_B_SIGN_STORAGE_OFF);
+ CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_B_STORAGE_OFF);
+ vb21_sig = (const struct vb21_signature
+ *)(CONFIG_MAPPED_STORAGE_BASE +
+ CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_B_SIGN_STORAGE_OFF);
}
rv = vb21_is_signature_valid(vb21_sig, vb21_key);
diff --git a/common/vboot_hash.c b/common/vboot_hash.c
index 33172e7c74..ad41269794 100644
--- a/common/vboot_hash.c
+++ b/common/vboot_hash.c
@@ -1,16 +1,18 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Verified boot hash computing module for Chrome EC */
+#include "builtin/assert.h"
#include "clock.h"
#include "common.h"
#include "console.h"
#include "flash.h"
#include "hooks.h"
#include "host_command.h"
+#include "printf.h"
#include "sha256.h"
#include "shared_mem.h"
#include "stdbool.h"
@@ -23,7 +25,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_VBOOT, outstr)
-#define CPRINTS(format, args...) cprints(CC_VBOOT, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_VBOOT, format, ##args)
struct vboot_hash_tag {
uint8_t hash[SHA256_DIGEST_SIZE];
@@ -31,8 +33,8 @@ struct vboot_hash_tag {
uint32_t size;
};
-#define CHUNK_SIZE 1024 /* Bytes to hash per deferred call */
-#define WORK_INTERVAL_US 100 /* Delay between deferred calls */
+#define CHUNK_SIZE 1024 /* Bytes to hash per deferred call */
+#define WORK_INTERVAL_US 100 /* Delay between deferred calls */
/* Check that CHUNK_SIZE fits in shared memory. */
SHARED_MEM_CHECK_SIZE(CHUNK_SIZE);
@@ -40,11 +42,11 @@ SHARED_MEM_CHECK_SIZE(CHUNK_SIZE);
static uint32_t data_offset;
static uint32_t data_size;
static uint32_t curr_pos;
-static const uint8_t *hash; /* Hash, or NULL if not valid */
+static const uint8_t *hash; /* Hash, or NULL if not valid */
static int want_abort;
static int in_progress;
-#define VBOOT_HASH_DEFERRED true
-#define VBOOT_HASH_BLOCKING false
+#define VBOOT_HASH_DEFERRED true
+#define VBOOT_HASH_BLOCKING false
static struct sha256_ctx ctx;
@@ -117,9 +119,10 @@ static void hash_next_chunk(size_t size)
{
#ifdef CONFIG_MAPPED_STORAGE
crec_flash_lock_mapped_storage(1);
- SHA256_update(&ctx, (const uint8_t *)
- ((uintptr_t)CONFIG_MAPPED_STORAGE_BASE +
- data_offset + curr_pos), size);
+ SHA256_update(&ctx,
+ (const uint8_t *)((uintptr_t)CONFIG_MAPPED_STORAGE_BASE +
+ data_offset + curr_pos),
+ size);
crec_flash_lock_mapped_storage(0);
#else
if (read_and_hash_chunk(data_offset + curr_pos, size) != EC_SUCCESS)
@@ -129,6 +132,8 @@ static void hash_next_chunk(size_t size)
static void vboot_hash_all_chunks(void)
{
+ char str_buf[hex_str_buf_size(SHA256_PRINT_SIZE)];
+
do {
size_t size = MIN(CHUNK_SIZE, data_size - curr_pos);
hash_next_chunk(size);
@@ -136,7 +141,9 @@ static void vboot_hash_all_chunks(void)
} while (curr_pos < data_size);
hash = SHA256_final(&ctx);
- CPRINTS("hash done %ph", HEX_BUF(hash, SHA256_PRINT_SIZE));
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(hash, SHA256_PRINT_SIZE));
+ CPRINTS("hash done %s", str_buf);
in_progress = 0;
clock_enable_module(MODULE_FAST_CPU, 0);
@@ -164,9 +171,14 @@ static void vboot_hash_next_chunk(void)
curr_pos += size;
if (curr_pos >= data_size) {
+ char str_buf[hex_str_buf_size(SHA256_PRINT_SIZE)];
+
/* Store the final hash */
hash = SHA256_final(&ctx);
- CPRINTS("hash done %ph", HEX_BUF(hash, SHA256_PRINT_SIZE));
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(hash, SHA256_PRINT_SIZE));
+ CPRINTS("hash done %s", str_buf);
in_progress = 0;
@@ -271,9 +283,9 @@ int vboot_hash_invalidate(int offset, int size)
*/
static uint32_t get_rw_size(void)
{
-#ifdef CONFIG_VBOOT_EFS /* Only needed for EFS, which signs and verifies
- * entire RW, thus not needed for EFS2, which
- * verifies only the used image size. */
+#ifdef CONFIG_VBOOT_EFS /* Only needed for EFS, which signs and verifies \
+ * entire RW, thus not needed for EFS2, which \
+ * verifies only the used image size. */
return CONFIG_RW_SIZE;
#else
return system_get_image_used(EC_IMAGE_RW);
@@ -327,10 +339,10 @@ static int get_offset(int offset)
/****************************************************************************/
/* Console commands */
#ifdef CONFIG_CMD_HASH
-static int command_hash(int argc, char **argv)
+static int command_hash(int argc, const char **argv)
{
- uint32_t offset = CONFIG_EC_WRITABLE_STORAGE_OFF +
- CONFIG_RW_STORAGE_OFF;
+ uint32_t offset =
+ CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF;
uint32_t size = CONFIG_RW_SIZE;
char *e;
@@ -342,9 +354,13 @@ static int command_hash(int argc, char **argv)
ccprintf("(aborting)\n");
else if (in_progress)
ccprintf("(in progress)\n");
- else if (hash)
- ccprintf("%ph\n", HEX_BUF(hash, SHA256_DIGEST_SIZE));
- else
+ else if (hash) {
+ char str_buf[hex_str_buf_size(SHA256_DIGEST_SIZE)];
+
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(hash, SHA256_DIGEST_SIZE));
+ ccprintf("%s\n", str_buf);
+ } else
ccprintf("(invalid)\n");
return EC_SUCCESS;
@@ -356,15 +372,14 @@ static int command_hash(int argc, char **argv)
return EC_SUCCESS;
} else if (!strcasecmp(argv[1], "rw")) {
return vboot_hash_start(
- get_offset(EC_VBOOT_HASH_OFFSET_ACTIVE),
- get_rw_size(),
- NULL, 0, VBOOT_HASH_DEFERRED);
+ get_offset(EC_VBOOT_HASH_OFFSET_ACTIVE),
+ get_rw_size(), NULL, 0, VBOOT_HASH_DEFERRED);
} else if (!strcasecmp(argv[1], "ro")) {
return vboot_hash_start(
CONFIG_EC_PROTECTED_STORAGE_OFF +
- CONFIG_RO_STORAGE_OFF,
- system_get_image_used(EC_IMAGE_RO),
- NULL, 0, VBOOT_HASH_DEFERRED);
+ CONFIG_RO_STORAGE_OFF,
+ system_get_image_used(EC_IMAGE_RO), NULL, 0,
+ VBOOT_HASH_DEFERRED);
}
return EC_ERROR_PARAM2;
}
@@ -384,12 +399,11 @@ static int command_hash(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM3;
- return vboot_hash_start(offset, size,
- (const uint8_t *)&nonce,
+ return vboot_hash_start(offset, size, (const uint8_t *)&nonce,
sizeof(nonce), VBOOT_HASH_DEFERRED);
} else
- return vboot_hash_start(offset, size,
- NULL, 0, VBOOT_HASH_DEFERRED);
+ return vboot_hash_start(offset, size, NULL, 0,
+ VBOOT_HASH_DEFERRED);
}
DECLARE_CONSOLE_COMMAND(hash, command_hash,
"[abort | ro | rw] | [<offset> <size> [<nonce>]]",
@@ -399,8 +413,7 @@ DECLARE_CONSOLE_COMMAND(hash, command_hash,
/* Host commands */
/* Fill in the response with the current hash status */
-static void fill_response(struct ec_response_vboot_hash *r,
- int request_offset)
+static void fill_response(struct ec_response_vboot_hash *r, int request_offset)
{
if (in_progress)
r->status = EC_VBOOT_HASH_STATUS_BUSY;
@@ -439,7 +452,7 @@ static int host_start_hash(const struct ec_params_vboot_hash *p)
if (offset == EC_VBOOT_HASH_OFFSET_RO)
size = system_get_image_used(EC_IMAGE_RO);
else if ((offset == EC_VBOOT_HASH_OFFSET_ACTIVE) ||
- (offset == EC_VBOOT_HASH_OFFSET_UPDATE))
+ (offset == EC_VBOOT_HASH_OFFSET_UPDATE))
size = get_rw_size();
offset = get_offset(offset);
rv = vboot_hash_start(offset, size, p->nonce_data, p->nonce_size,
@@ -493,6 +506,5 @@ host_command_vboot_hash(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
}
}
-DECLARE_HOST_COMMAND(EC_CMD_VBOOT_HASH,
- host_command_vboot_hash,
+DECLARE_HOST_COMMAND(EC_CMD_VBOOT_HASH, host_command_vboot_hash,
EC_VER_MASK(0));
diff --git a/common/vec3.c b/common/vec3.c
index dadf7715ff..67a6049dea 100644
--- a/common/vec3.c
+++ b/common/vec3.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,9 +9,8 @@
#include "vec3.h"
#include "util.h"
-static fpv3_t zero_initialized_vector = {
- FLOAT_TO_FP(0.0f), FLOAT_TO_FP(0.0f), FLOAT_TO_FP(0.0f)
-};
+static fpv3_t zero_initialized_vector = { FLOAT_TO_FP(0.0f), FLOAT_TO_FP(0.0f),
+ FLOAT_TO_FP(0.0f) };
void fpv3_zero(fpv3_t v)
{
diff --git a/common/version.c b/common/version.c
index 3978e796b5..8b1ac5e53d 100644
--- a/common/version.c
+++ b/common/version.c
@@ -1,4 +1,4 @@
-/* Copyright 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright 2012 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -17,8 +17,7 @@
BUILD_ASSERT(CONFIG_ROLLBACK_VERSION >= 0);
BUILD_ASSERT(CONFIG_ROLLBACK_VERSION <= INT32_MAX);
-const struct image_data __keep current_image_data
- FIXED_SECTION("ver") = {
+const struct image_data __keep current_image_data FIXED_SECTION("ver") = {
.cookie1 = CROS_EC_IMAGE_DATA_COOKIE1,
.version = CROS_EC_VERSION32,
#ifndef TEST_BUILD
@@ -69,7 +68,6 @@ static int get_num_commits(const struct image_data *data)
}
return (i == sizeof(data->version) ? 0 : ret);
-
}
/* LCOV_EXCL_STOP */
diff --git a/common/virtual_battery.c b/common/virtual_battery.c
index 8e88e22bcb..a9ad77e22b 100644
--- a/common/virtual_battery.c
+++ b/common/virtual_battery.c
@@ -1,4 +1,4 @@
-/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+/* Copyright 2016 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,7 +14,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_I2C, outstr)
-#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ##args)
#define BATT_MODE_UNINITIALIZED -1
@@ -34,12 +34,10 @@ static uint8_t cache_hit;
static const uint8_t *batt_cmd_head;
static int acc_write_len;
-int virtual_battery_handler(struct ec_response_i2c_passthru *resp,
- int in_len, int *err_code, int xferflags,
- int read_len, int write_len,
- const uint8_t *out)
+int virtual_battery_handler(struct ec_response_i2c_passthru *resp, int in_len,
+ int *err_code, int xferflags, int read_len,
+ int write_len, const uint8_t *out)
{
-
#if defined(CONFIG_BATTERY_PRESENT_GPIO) || \
defined(CONFIG_BATTERY_PRESENT_CUSTOM)
/*
@@ -74,7 +72,7 @@ int virtual_battery_handler(struct ec_response_i2c_passthru *resp,
} else {
sb_cmd_state = READ_VB;
*err_code = virtual_battery_operation(batt_cmd_head,
- NULL, 0, 0);
+ NULL, 0, 0);
/*
* If the reg is not handled by virtual battery, we
* do not support it.
@@ -118,10 +116,8 @@ int virtual_battery_handler(struct ec_response_i2c_passthru *resp,
/* write to virtual battery */
case START:
case WRITE_VB:
- virtual_battery_operation(batt_cmd_head,
- NULL,
- 0,
- acc_write_len);
+ virtual_battery_operation(batt_cmd_head, NULL, 0,
+ acc_write_len);
break;
/* read from virtual battery */
case READ_VB:
@@ -129,15 +125,13 @@ int virtual_battery_handler(struct ec_response_i2c_passthru *resp,
read_len += in_len;
memset(&resp->data[0], 0, read_len);
virtual_battery_operation(batt_cmd_head,
- &resp->data[0],
- read_len,
- 0);
+ &resp->data[0],
+ read_len, 0);
}
break;
default:
reset_parse_state();
return EC_ERROR_INVAL;
-
}
/* Reset the state in the end of messages */
reset_parse_state();
@@ -156,7 +150,7 @@ void reset_parse_state(void)
* Copy memmap string data from offset to dest, up to size len, in the format
* expected by SBS (first byte of dest contains strlen).
*/
-void copy_memmap_string(uint8_t *dest, int offset, int len)
+static void copy_memmap_string(uint8_t *dest, int offset, int len)
{
uint8_t *memmap_str;
uint8_t memmap_strlen;
@@ -166,7 +160,8 @@ void copy_memmap_string(uint8_t *dest, int offset, int len)
memmap_str = host_get_memmap(offset);
/* memmap_str might not be NULL terminated */
memmap_strlen = *(memmap_str + EC_MEMMAP_TEXT_MAX - 1) == '\0' ?
- strlen(memmap_str) : EC_MEMMAP_TEXT_MAX;
+ strlen(memmap_str) :
+ EC_MEMMAP_TEXT_MAX;
dest[0] = memmap_strlen;
memcpy(dest + 1, memmap_str, MIN(memmap_strlen, len - 1));
}
@@ -180,10 +175,8 @@ static void copy_battery_info_string(uint8_t *dst, const uint8_t *src, int len)
strncpy(dst + 1, src, len - 1);
}
-int virtual_battery_operation(const uint8_t *batt_cmd_head,
- uint8_t *dest,
- int read_len,
- int write_len)
+int virtual_battery_operation(const uint8_t *batt_cmd_head, uint8_t *dest,
+ int read_len, int write_len)
{
int val;
int year, month, day;
@@ -233,9 +226,8 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
* typical SB defaults.
*/
batt_mode_cache =
- MODE_INTERNAL_CHARGE_CONTROLLER |
- MODE_ALARM |
- MODE_CHARGER;
+ MODE_INTERNAL_CHARGE_CONTROLLER |
+ MODE_ALARM | MODE_CHARGER;
memcpy(dest, &batt_mode_cache, bounded_read_len);
}
@@ -278,7 +270,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
break;
case SB_FULL_CHARGE_CAPACITY:
if (curr_batt->flags & BATT_FLAG_BAD_FULL_CAPACITY ||
- curr_batt->flags & BATT_FLAG_BAD_VOLTAGE)
+ curr_batt->flags & BATT_FLAG_BAD_VOLTAGE)
return EC_ERROR_BUSY;
val = curr_batt->full_capacity;
if (batt_mode_cache & MODE_CAPACITY)
@@ -308,7 +300,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
break;
case SB_REMAINING_CAPACITY:
if (curr_batt->flags & BATT_FLAG_BAD_REMAINING_CAPACITY ||
- curr_batt->flags & BATT_FLAG_BAD_VOLTAGE)
+ curr_batt->flags & BATT_FLAG_BAD_VOLTAGE)
return EC_ERROR_BUSY;
val = curr_batt->remaining_capacity;
if (batt_mode_cache & MODE_CAPACITY)
diff --git a/common/vstore.c b/common/vstore.c
index 9b4636397c..254a515b48 100644
--- a/common/vstore.c
+++ b/common/vstore.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -22,7 +22,7 @@
#include "system.h"
#include "util.h"
-#define VSTORE_SYSJUMP_TAG 0x5653 /* "VS" */
+#define VSTORE_SYSJUMP_TAG 0x5653 /* "VS" */
#define VSTORE_HOOK_VERSION 1
struct vstore_slot {
@@ -32,7 +32,7 @@ struct vstore_slot {
static struct vstore_slot vstore_slots[CONFIG_VSTORE_SLOT_COUNT];
static const int vstore_size =
- sizeof(struct vstore_slot) * CONFIG_VSTORE_SLOT_COUNT;
+ sizeof(struct vstore_slot) * CONFIG_VSTORE_SLOT_COUNT;
BUILD_ASSERT(ARRAY_SIZE(vstore_slots) <= EC_VSTORE_SLOT_MAX);
/*
@@ -97,7 +97,7 @@ static enum ec_status vstore_write(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_VSTORE_WRITE, vstore_write, EC_VER_MASK(0));
-static void vstore_clear_lock(void)
+test_export_static void vstore_clear_lock(void)
{
int i;
diff --git a/common/webusb_desc.c b/common/webusb_desc.c
index 41d39006e0..e2f51b4c0f 100644
--- a/common/webusb_desc.c
+++ b/common/webusb_desc.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 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/common/wireless.c b/common/wireless.c
index d1f5cad645..dfc2d4843e 100644
--- a/common/wireless.c
+++ b/common/wireless.c
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -34,13 +34,11 @@ static int suspend_flags = CONFIG_WIRELESS_SUSPEND;
static void wireless_enable(int flags)
{
#ifdef WIRELESS_GPIO_WLAN
- gpio_set_level(WIRELESS_GPIO_WLAN,
- flags & EC_WIRELESS_SWITCH_WLAN);
+ gpio_set_level(WIRELESS_GPIO_WLAN, flags & EC_WIRELESS_SWITCH_WLAN);
#endif
#ifdef WIRELESS_GPIO_WWAN
- gpio_set_level(WIRELESS_GPIO_WWAN,
- flags & EC_WIRELESS_SWITCH_WWAN);
+ gpio_set_level(WIRELESS_GPIO_WWAN, flags & EC_WIRELESS_SWITCH_WWAN);
#endif
#ifdef WIRELESS_GPIO_BLUETOOTH
@@ -57,7 +55,6 @@ static void wireless_enable(int flags)
!(flags & EC_WIRELESS_SWITCH_WLAN_POWER));
#endif /* CONFIG_WLAN_POWER_ACTIVE_LOW */
#endif
-
}
static int wireless_get(void)
@@ -126,7 +123,7 @@ static enum ec_status wireless_enable_cmd(struct host_cmd_handler_args *args)
(p->now_flags & p->now_mask));
suspend_flags = (suspend_flags & ~p->suspend_mask) |
- (p->suspend_flags & p->suspend_mask);
+ (p->suspend_flags & p->suspend_mask);
/* And return the current flags */
r->now_flags = wireless_get();
@@ -134,11 +131,10 @@ static enum ec_status wireless_enable_cmd(struct host_cmd_handler_args *args)
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_SWITCH_ENABLE_WIRELESS,
- wireless_enable_cmd,
+DECLARE_HOST_COMMAND(EC_CMD_SWITCH_ENABLE_WIRELESS, wireless_enable_cmd,
EC_VER_MASK(0) | EC_VER_MASK(1));
-static int command_wireless(int argc, char **argv)
+static int command_wireless(int argc, const char **argv)
{
char *e;
int i;
@@ -164,6 +160,5 @@ static int command_wireless(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(wireless, command_wireless,
- "[now [suspend]]",
+DECLARE_CONSOLE_COMMAND(wireless, command_wireless, "[now [suspend]]",
"Get/set wireless flags");