summaryrefslogtreecommitdiff
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* TCPMv2: Do not attempt Enter_USB under PD 2.0Abe Levkoy2023-05-161-0/+4
| | | | | | | | | | | | | | | | If the port partner is not PD 3.0 or higher, do not consider it to support USB4/Enter_USB. If the AP requests USB4 entry, disregard the request and consider mode entry complete. Avoid repeatedly sending Enter_USB to a PD 2.0 partner. BUG=b:279421317 TEST=twister -s drivers/drivers.usbc_usb4_mode Change-Id: I3e82738f816e6dd5af24d627b6cd971a34d74586 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4533369 Commit-Queue: Abe Levkoy <alevkoy@chromium.org> Tested-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Jameson Thies <jthies@google.com>
* motion_sense: Fix null pointer reference in gesture detectionRuihai Zhou2023-05-163-2/+57
| | | | | | | | | | | | | | | | | | | | The motion_sense_fifo_stage_data with NULL were removed in CL:4499747. But we need to stage and commit the motion state changed to activity sensor for body detection on the ap side. Revert the change and Add null pointer check in motion_sense_fifo_stage_data and fifo_stage_unit to fix it. BUG=b:272655176 TEST=./twister -v -i -p native_posix -p unit_testing -s drivers/drivers.body_detection TEST=received User proximity: Near/Far event from powerd log Change-Id: I1ef882f25e07fa17d879d8b0a4b9ffe211b071e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4520740 Tested-by: Ruihai Zhou <zhouruihai@huaqin.corp-partner.google.com> Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: Sung-Chi Li <lschyi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
* charger: Rename enum charge_state_v2 to charge_stateSimon Glass2023-05-151-3/+3
| | | | | | | | | | | | | | | | Now that we don't have an old charge_state, this is the only one. Rename it accordingly. This makes no functional change. BUG=b:218332694 TEST=make buildall Change-Id: I95923eedd2715b8c7793df8f6e3171c82f9347ca Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4516193 Reviewed-by: Tristan Honscheid <honscheid@google.com> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Eric Peers <epeers@google.com>
* common: move chip agnostic trng code from stm32 to commonDavid Cross2023-05-122-1/+84
| | | | | | | | | | | | | | | | | | | | | Making this change causes common trng functions to move memory locations. This change only affects fingerprint (FPMCU) boards BUG=b:280889889 TEST=make BOARD=bloonchipper, CONFIG_CMD_RAND enabled in board.h ALLOW_CONFIG=1 ./util/compare_build.sh -b all => All boards match, except the following Fingerprint boards: bloonchipper dartmonkey hatch_fp nami_fp nocturne_fp nucleo-dartmonkey Change-Id: I4dbb5e255be0f61eb7b446af4565bea487c08e52 Signed-off-by: David Cross <davidmcross@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4507892 Reviewed-by: Bobby Casey <bobbycasey@google.com>
* chgstv2: Change battery near full depends on display SOCwen zhang2023-05-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The battery_near_full is used to set PWR_STATE_DISCHARGE_FULL and PWR_STATE_CHARGE_NEAR_FULL and these two states are used to set LED behaviors. We should change battery_near_full to depend on display SOC because LED bahaviors are already depends on display SOC. There is an exception, isl9241.c also checks charge_get_state() == PWR_STATE_CHARGE_NEAR_FULL in function isl9241_restart_charge_voltage_when_full. With this change, this feature will depend on the battery display SOC rather than RSOC. The display SOC is bigger than RSOC ~3% when the battery is BATTERY_LEVEL_NEAR_FULL(default 97%) so this feature may be 3% ahead of schedule. The 3% difference should have no harm for this feature. BUG=b:278512388 TEST=1.verify LED behavior on voltorb 2.no "E: Node with matching prop not found" on voltorb Change-Id: I87f555571e22cbcdd0e8e0a201f76e3de8204ebe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4478776 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Siyu Qin <qinsiyu@huaqin.corp-partner.google.com> Commit-Queue: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Tested-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com>
* battery: Deprecate CONFIG_BATTERY_LEVEL_NEAR_FULLwen zhang2023-05-112-2/+2
| | | | | | | | | | | | | | | | | | Atlas, coral, corori, eve, morphius, primus, and rammus are setting CONFIG_BATTERY_LEVEL_NEAR_FULL to custom values. This causes their LEDs show 'full' while the display battery percentages are still < 100%. We'll make these boards define CONFIG_BATT_HOST_FULL_FACTOR, instead. And fix LED dts for some zephyr projects. BUG=b:280818345 TEST=build pass Change-Id: I98f97798ea99cc812671d5b31d64e92d55a1e05a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4523043 Commit-Queue: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Tested-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* panic_output: Do not use ccprintf to induce stack overflowRob Barnes2023-05-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | The console command to induce a stack overflow crash uses ccprintf, which acquires a mutex lock internally. The exception handler aborts the thread (shell_uart) when the stack overflow is detected, but the mutex is not released. This causes system safe mode to deadlock. Switch to panic_printf to avoid this deadlock. A more robust long term fix may be to change Zephyr internals to release mutexes on aborted threads. LOW_COVERAGE_REASON=Swapping single function call BUG=b:278792557 TEST=Able to start system safe mode after a stack overflow on skyrim Change-Id: Ib7b50487d27e77fdd5b6cec5176060074868dca3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4504115 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Boris Mittelberg <bmbm@google.com> Auto-Submit: Rob Barnes <robbarnes@google.com> Commit-Queue: Rob Barnes <robbarnes@google.com> Tested-by: Rob Barnes <robbarnes@google.com>
* charger: Move charger_state_v2.h into charge_state.hSimon Glass2023-05-114-4/+4
| | | | | | | | | | | | | | | | | | | | We don't have a v1 anymore, so the name makes no sense. Move it into the existing file. Include charge_state.h instead of v2, doing this in the same change to avoid build errors. This makes no functional change. BUG=b:218332694 TEST=make buildall Change-Id: Ic3e3adc45e4d002c2cd5ba8aa65e24686e01d628 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4516191 Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Yuval Peress <peress@google.com>
* host_command_pd: Avoid using charger_state as a variableSimon Glass2023-05-111-3/+3
| | | | | | | | | | | | | | | We have enum charge_state_v2 and used to have enum charge_state. Try to avoid using charger_state in the source except as an enum. This makes no functional change. BUG=b:218332694 TEST=make buildall Change-Id: I68e4eb3112a32be00819f74c51ea744d148a88d5 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4516189 Reviewed-by: Al Semjonovs <asemjonovs@google.com>
* charger: Rename charge_get_state() to led_pwr_get_state()Simon Glass2023-05-115-5/+5
| | | | | | | | | | | | | | | | | | We have a new 'charge state' in struct charge_state_data as part of the charge_state_v2.h file. This is confusing. Rename this function to match the enum it is referencing. This makes no functional change. BUG=b:218332694 TEST=make buildall Change-Id: I7f08dd4fb11e2939e0ef779018c1e3206ebc8d20 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4516188 Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Aaron Massey <aaronmassey@google.com>
* charger: Rename enum charge_state to led_pwr_stateSimon Glass2023-05-112-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This name is confusing, since its members start with PWR_ and the comment for enum charge_state_v2 says that these values are only used to control the LEDs, with one not-quite-correct exception, whatever that might be. We could rename it to power_state, but that is already fairly widely used as a variable in the code base. Also it seems better to match the enum PWR_ prefix. Future work may rename the members too. Rename the charge_state enum. This makes no functional change. BUG=b:218332694 TEST=make buildall Change-Id: If8a7cc73dcfb4c1e89984e57fc55e432416e8aec Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4516187 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* zephyr: test: Test keyboard_8042.c console commandsTristan Honscheid2023-05-111-2/+29
| | | | | | | | | | | | | | | | Add tests for the `8042` set of console commands in `keyboard_8042.c`, covers about 100 new lines. BUG=b:281691908 TEST=./twister -s drivers/drivers.keyboard_8042 Change-Id: I1e28e0258305d0e1d17571346fcdca8f19102cb9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4520583 Commit-Queue: Peter Marheine <pmarheine@chromium.org> Tested-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Tristan Honscheid <honscheid@google.com> Auto-Submit: Tristan Honscheid <honscheid@google.com> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
* safe_mode: Remove schedule_system_safe_mode_timeoutRob Barnes2023-05-111-8/+2
| | | | | | | | | | | | | | | Zephyr and CrOS EC can use the same method for scheduling the safe mode timeout, so there's no need to have an overridden task. BUG=None TEST=Safe mode starts and timesout on skyrim Change-Id: I57b296223ec86cf47110a00f3f021e8a8a30ead3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4519103 Tested-by: Rob Barnes <robbarnes@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Rob Barnes <robbarnes@google.com> Auto-Submit: Rob Barnes <robbarnes@google.com>
* safe_mode: Shorten stringsRob Barnes2023-05-111-9/+10
| | | | | | | | | | | | | | | | Many old boards are out of flash space, which makes porting safe mode to older boards difficult. To make this process smoother shorten strings so less flash space is needed. BUG=None TEST=Safe mode runs Change-Id: I0934f1a477b01e7c8f71241844ac0eefa093c5ea Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4519102 Commit-Queue: Rob Barnes <robbarnes@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Rob Barnes <robbarnes@google.com> Auto-Submit: Rob Barnes <robbarnes@google.com>
* charger: Move conditional into process_preferred_voltage()Simon Glass2023-05-091-6/+13
| | | | | | | | | | | | | | | Try to work around the code-coverage loss by moving the condition into the function. BUG=b:281109948 TEST=check if coverage goes back up Change-Id: I3374692c7010f3712e87a2e144212488fb58bb91 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4519108 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move setup of input_voltage to charger_base.cSimon Glass2023-05-092-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a way to set the base input-voltage in the charger_base.c file. Use this for the two accesses required in charger_base.c, thus removing the final two base-related #ifdefs in that file. With this we can drop the inclusion of the ec_ec_comm_client/server headers. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69460 bytes in flash and 1120 bytes in RAM lux RW **** Check size on brya: *** 33464 bytes in flash and 23136 bytes in RAM brya RO **** *** 33428 bytes in flash and 23136 bytes in RAM brya RW **** Change-Id: I8b747b8d7dbe890ce071027aaeed23b879ae8070 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510250 Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* charger: Deal with dumping the input voltageSimon Glass2023-05-092-3/+9
| | | | | | | | | | | | | | | | | | | | This field is only accessible when CONFIG_EC_EC_COMM_BATTERY_CLIENT is enabled, but we want to dump it in the main charger file. Add a function to access the value. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69460 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Iebf22c19cd3e2c649715eb3e6010709fda075929 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510249 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Drop a few more #ifdefsSimon Glass2023-05-092-8/+11
| | | | | | | | | | | | | | | | | | | Change the #ifdef in charge_set_input_current_limit() to use if() and move a line of setup code into charger_base_setup(). This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69460 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Ie657a69165b4e2cda56c9966e5831152d6b745d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510248 Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* charger: Make charge_base staticSimon Glass2023-05-092-8/+19
| | | | | | | | | | | | | | | | | | | | Move use of this variable wholly within charger_base.c by adding a function to show the current charge level and another to check if the base is nearly full. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69460 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: I558c3c122f52a8d4e034bd375b20e7ca154fd3a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510247 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Make prev_charge_base staticSimon Glass2023-05-092-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | Move use of this variable wholly within charger_base.c by adding two functions to deal with what charger_state_v2.c needs: - seeing if charge_base has changed since last time - committing that change I did toy with the idea of making these two functions static inlines, but that does tend to obfuscate the fact that they only exist when the base is present. So for now at least I have left two IS_ENABLED() calls in the code. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69448 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Ib9bdbce62cefb99b12aeb235450eac5d29861d3b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510246 Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move base_responsive to charger_base.cSimon Glass2023-05-092-2/+8
| | | | | | | | | | | | | | | | | | | | This variable is not used in the main charger file. Move it over to the base file by creating a setup function for the base, calling it from the charger_setup() function. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69448 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Idbdb7639cb51e65de2c77303545221cca25c8865 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510245 Reviewed-by: Al Semjonovs <asemjonovs@google.com> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Split base code out to its own fileSimon Glass2023-05-093-667/+653
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the essential refactoring complete, move the base code into a new charger_base.c file, with a corresponding charger_base.h header file. The base name 'charger' was chosen since it matches the charger.h header file, even though charge_state_v2.c uses the 'charge' base name. Three variables must be exported for use by the charge_state_v2.c code: charge_base, prev_charge_base and base_responsive. For now these are made global. Future work will tidy that up. The base_connected() function is defined in the new C file, with a stub in the header for when CONFIG_EC_EC_COMM_BATTERY_CLIENT is not enabled. The hook for board_base_reset() is placed at the bottom of the new charger_base.c file. With this change we have 8 #ifdefs for CONFIG_EC_EC_COMM_BATTERY_CLIENT in charge_state_v2.c - future work will tidy those up. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69448 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: I2d8d03e8b07ed1b281b8729cffdb8140239b5b2b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510244 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Tristan Honscheid <honscheid@google.com> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Avoid accessing curr.ac in base_check_extpower()Simon Glass2023-05-091-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We want to move this function into its own file where it will not have access to the 'curr' state. Pass in the ac value and use the return value to indicate whether it should be zeroed. Pass in prev_ac as well, for the same reason. This changes the ordering of curr.ac being set to 0, so it happens after board_base_reset() has been called. From what I can tell, this does not matter, although there is a lot of code what could be affected by the base_detect_deferred hook or the call to base_detect_change(). So this makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69448 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Ie2171016b692d233fda4f7bd527e74cbb965702e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510243 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Pass debugging variable to base functionSimon Glass2023-05-091-4/+6
| | | | | | | | | | | | | | | | | Pass this variable in as an argument, so we can eventually move the base code out into its own file. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69452 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: I14fb41b07a1baa8bc38efe493de9c4242dda3456 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510242 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Pass state to base_charge_allocate_input_current_limit()Simon Glass2023-05-091-17/+18
| | | | | | | | | | | | | | | | | | | | | In preparation for moving this function into its own file, pass in the charge state that we want it to work with. Use a local variable for the battery information to simplify the code. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check code on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69440 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: If6271fcac99eb3af554bda52f86ed63267daea76 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4509873 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Al Semjonovs <asemjonovs@google.com> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Simplify the arguments to charge_request()Simon Glass2023-05-091-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | This function is called in two modes, one where it deals with the currently requested voltage/current and one where it does not. The function has access to the necessary state so there is no need to pass it in. It is better to tell the function which approach to take explicitly, using a boolean, rather than using zero values for the first two arguments to indicate this. Replace the first two arguments with a boolean. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check code on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69416 bytes in flash and 1152 bytes in RAM lux RW **** Change-Id: I8389e35b0f61b2c4f03a7e7aac746eeab20ef0de Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4509872 Reviewed-by: Aaron Massey <aaronmassey@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Make base_connected() a functionSimon Glass2023-05-091-12/+16
| | | | | | | | | | | | | | | | | | | | | | | | The double declaration of this variable is ugly. The only user seems to be lux, where board_is_base_connected() is implemented simply by reading from another variable. So there is really advantage to caching the value in the charger code. Change base_connected() to a function, where it returns false if there is no base, otherwise calls the base code to find out. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check code on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69424 bytes in flash and 1152 bytes in RAM lux RW **** Change-Id: I14a05a7705fa52c92fa15b0ee233f79ef01d1b53 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508350 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Make is_full mostly a local variableSimon Glass2023-05-091-26/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a property of the charger task and various functions access it. Within each iteration of the charger loop, it is only changed at most once. It seems better to use a local variable for that. Unfortunately the exported function charge_get_percent() needs access to this variable. But it seems better to group exported information together, updating it as needed. Then this information it could potentially be accessed as a cohesive whole, rather than a collection of unrelated pieces. Make a start on this by creating a new local struct to hold what will be the 'published' information. Update it once around the charger loop. Update charge_get_percent() to use that version of the information. Code size on lux, which seems to be the only user of the base code, increases a bit. This hits it fairly hard since it adds a 5th function argument to set_base_lid_current(). We could improve that by using flags instead of three booleans. But it seems best to do that once we have all the reported state in one place. Note that we get much of the code space back with the next CL. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Lux adds 136 bytes to RO, less to RW; RAM improves a little Free space before: *** 69624 bytes in flash and 1152 bytes in RAM lux RO **** *** 69444 bytes in flash and 1120 bytes in RAM lux RW **** after: *** 69488 bytes in flash and 1152 bytes in RAM lux RO **** *** 69476 bytes in flash and 1152 bytes in RAM lux RW **** Change-Id: Ide34a613e0bab7868d268b6fa1a9db258d3c5945 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508349 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Make prev_full a local varSimon Glass2023-05-091-3/+4
| | | | | | | | | | | | | | | | This does not need to be global to the whole file. Move it into the charging loop. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Ia9e5b4e202535e6b3f9277a66cbdbc87c984d95e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508348 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Add a way to disable debugging at build timeSimon Glass2023-05-091-10/+38
| | | | | | | | | | | | | | | | | | | | | | Add a way to disable some debugging related to the chgstate command. It is a small, but enough to reclaim 70 bytes for damu. Use functions to avoid needing #ifdefs in the main body of the code. Convert the value to a bool while we are here. BUG=b:218332694 TEST=build on brya and see that the feature is still enabled $ grep CONFIG_CHARGE_DEBUG build/brya/.config CONFIG_CHARGE_DEBUG=y Check damu is the same as before: *** 12 bytes in flash and 10908 bytes in RAM still available on damu RO **** Change-Id: I07d2453aa74ab53a29275bba76cd2e8003c5dc14 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4518028 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move charge-state handling into a functionSimon Glass2023-05-081-31/+39
| | | | | | | | | | | | | | | | Move this related code into a separate function, to reduce the side of the charger_task() function. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I20632ed822df5cc2799959b251c29cb160eabcf7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508347 Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* charger: Move handling of external power to a functionSimon Glass2023-05-081-5/+12
| | | | | | | | | | | | | | | Put this code in a separate function, since it is logically related. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I1ebab33e72d5927bbc3fcd1e0562b66102c5c689 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508346 Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* rollback: Use OPENSSL_cleanse() when BoringSSL is enabledPatryk Duda2023-05-081-5/+14
| | | | | | | | | | | | | | | | | | Since we are switching from cryptoc to BoringSSL on some boards, we should support OPENSSL_cleanse() function provided by BoringSSL to avoid compiling and linking both libcryptoc and BoringSSL. BUG=b:277029648 TEST=make BOARD=prism TEST=make BOARD=hammer TEST=make BOARD=bloonchipper TEST=make BOARD=dartmonkey Change-Id: Ief5dc28adecaf33120094ba42e418144cdafe9e5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4383046 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Tested-by: Patryk Duda <patrykd@google.com> Commit-Queue: Patryk Duda <patrykd@google.com>
* ec: Add #line in common/usbc/usb_pd_dpm.cJeremy Bettis2023-05-061-0/+6
| | | | | | | | | | | | | | | Work around coreboot GCC preprocessor bug. BRANCH=None BUG=b:272518464 TEST=gcc -E Change-Id: I90d096f6f3bd30b0d961d3d1d6e802eded076ecd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510537 Commit-Queue: Tristan Honscheid <honscheid@google.com> Reviewed-by: Tristan Honscheid <honscheid@google.com> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
* charger: Move v/i setup code to decide_charge_state()Simon Glass2023-05-051-21/+21
| | | | | | | | | | | | | | | | This code relates to deciding on the charge state, so move it into the same function. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I2d8fb744047f9d986b47b7460bbfa471233f9689 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508345 Reviewed-by: Al Semjonovs <asemjonovs@google.com> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* TCPMv2: Snoop HPD signal necessities in AP VDM controlDiana Z2023-05-051-0/+71
| | | | | | | | | | | | | | | | When the AP is controlling the VDMs, it still needs the EC to snoop the VDM:Attention messages to transmit the HPD GPIO and also to wake it when a monitor is attached. BUG=b:266714542 TEST=./twister -T ./zephyr/test, observe monitor working with skyrim and DNS patch to enable feature Change-Id: Iebbd434addfd8c3007f330240387130469857403 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4218926 Tested-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* charger: Move calculation of sleep duration to a functionSimon Glass2023-05-051-47/+52
| | | | | | | | | | | | | | | | | Move this related code into a separate function. BUG=b:218332694 TEST=zmake build dev-posix make BOARD=brya -j50 |grep "brya " |sed 's/still.*on //' *** 33552 bytes in flash and 23168 bytes in RAM brya RO **** *** 33392 bytes in flash and 23104 bytes in RAM brya RW **** (RO flash improves a lot, RW down 32 bytes) Change-Id: Iea944de1706b0bababcebd0474303733c199f64d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500692 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move handling of preferred voltage into a functionSimon Glass2023-05-051-50/+44
| | | | | | | | | | | | | | | | | Move this related code into a separate function. Also move the call site up above the sleep-determination code, since they seem to be unrelated and it seems better to do sleep determination at the end of the loop. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I2e9b569c3b1fb10991ae2c368f78b1c7c62542e8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500691 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Aaron Massey <aaronmassey@google.com> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move handling of requested voltage/current to funcSimon Glass2023-05-051-58/+62
| | | | | | | | | | | | | | | | | Move this related code into a separate function. BUG=b:218332694 TEST=zmake build dev-posix make BOARD=brya -j50 |grep "brya " |sed 's/still.*on //' *** 33464 bytes in flash and 23136 bytes in RAM brya RO **** *** 33424 bytes in flash and 23136 bytes in RAM brya RW **** (RO flash space decreased from 33488 = 24 bytes) Change-Id: I24655906c1865e0fc7d3c83a1a74aa708854fbbc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500690 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Yuval Peress <peress@google.com> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Move the early part of charge-deciding into a funcSimon Glass2023-05-051-45/+43
| | | | | | | | | | | | | | | | | | | Move the other goto into the function and turn it into a return. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix make BOARD=brya -j50 |grep "brya " |sed 's/still.*on //' *** 33488 bytes in flash and 23168 bytes in RAM brya RO **** *** 33424 bytes in flash and 23136 bytes in RAM brya RW **** (no change since start of series) Change-Id: I9d0ce317a8bf529aa01c6a0316ec5fb4dfbaa13f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500689 Reviewed-by: Aaron Massey <aaronmassey@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move latter part of charge-deciding into a funcSimon Glass2023-05-051-44/+50
| | | | | | | | | | | | | | | | | | This goes through various steps to decide what charge state to use, using a goto to get to the final state. Move the code into a function instead, so we can use a return. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Ibb46b172c5560e64cac8861f4330ddbc5b35649f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500688 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Move processing of battery-present state to funcSimon Glass2023-05-051-12/+17
| | | | | | | | | | | | | | | | | | | Split this code out into its own function, called if a change is detected. This changes the ordering of the assignment of need_static but should should not matter. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Ia992c9c03ae2d156b490d071b1b1111d3b077939 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500687 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Yuval Peress <peress@google.com> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Move processing of AC change into a functionSimon Glass2023-05-051-42/+40
| | | | | | | | | | | | | | | | | | Split this code out into its own function, called if a change is detected. Tweak a comment while we are here. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Iabcc117a28004a24a0069b2205e87c92c7807f4b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500686 Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Drop some #ifdefs from charger taskSimon Glass2023-05-051-14/+8
| | | | | | | | | | | | | | | Convert these to if() to avoid the extra build paths. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I1933097a0a1085cbbeb21e55fa3a26ad01fa042c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500685 Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* charger: Rename charge_allocate_input_current_limit()Simon Glass2023-05-051-7/+10
| | | | | | | | | | | | | | | | Add a base_ prefix to this so that it is clear it relates to the base handling. Also drop the #ifdef by moving the function outside it. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I40ba3fec0141e3b382f9801fc26cfee5bff92cd6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501290 Reviewed-by: Al Semjonovs <asemjonovs@google.com> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Move state-of-charge-change handling into a functionSimon Glass2023-05-051-15/+22
| | | | | | | | | | | | | | | | | Move this into its own function so simplify the main loop. Fix a comment in the hook at the same time. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Ibdee116e10ab10265ad1718a76ed3401475ad235 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501289 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* charger: Avoid an #ifdef with base-update functionSimon Glass2023-05-051-59/+60
| | | | | | | | | | | | | | | | | | | | Take this function outside the #ifdef so we can call it behind an if() statement. Rename it with a base_ prefix so it is clear which functions relate to the base, and could perhaps be moved to another file. This makes no functional change. Unfortunately we still need the #ifdef in the function due to some variables which are declared behind that #ifdef. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I102a5b6f98b731b9a2cb42c070b9bd1f20e25f99 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501288 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move base-external-power check into a functionSimon Glass2023-05-051-14/+20
| | | | | | | | | | | | | | | | | | | | | | Move this into a function to shorten the main loop and avoid an #ifdef in it. Use a condition check to call the function so that it is clear that it relates to the base. Unfortunately we still need the #ifdef in the function due to the base_responsive variable. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: Ia2c689d5800daff43870dc017defa174f93ea38f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501287 Reviewed-by: Aaron Massey <aaronmassey@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
* charger: Move setup into its own functionSimon Glass2023-05-051-9/+16
| | | | | | | | | | | | | | | | The charger_task() function is extremely long. Start to split it up by creating a charger_setup() function for the initial setup code. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I12b3ff29c59418ce0819fa28973a8be7a4574dd9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501286 Reviewed-by: Aaron Massey <aaronmassey@google.com> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* chgstv2: Always discharge if soc is > sustainer_soc.upperDerek Basehore2023-05-051-6/+10
| | | | | | | | | | | | | | | | For the Charge Limit feature, we need to discharge down to the upper limit for the battery sustainer. The Charge Limit feature requires that the system never charge above 80%, so if the feature is enabled when the system is over that, it needs to discharge down to 80%. BUG=b:222619859 TEST=run-sbs_charging_v2 Change-Id: I3f65743144de64411484dd3f2aa6c5fd681a47c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4507756 Commit-Queue: Derek Basehore <dbasehore@chromium.org> Tested-by: Derek Basehore <dbasehore@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>