summaryrefslogtreecommitdiff
path: root/common/host_command_pd.c
Commit message (Collapse)AuthorAgeFilesLines
* tree: Files should end with single newlineTom Hughes2021-10-181-1/+0
| | | | | | | | | | | | | | | | | | | | | | | One of the checks that runs as part of "repo upload" looks for a single newline at the end of each file. I'm getting warnings about this when I touch files that do not follow this, even though I didn't add the extra newlines. This commit fixes all files by running the following: for f in $(find . -name '*.[ch]'); do printf '%s\n' "$(cat ${f})" > ${f}; done BRANCH=none BUG=b:172020503 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ia3ece5b64b549d21ca11708791368002bb6e9b0e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3229797 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* tcpm: Move tcpm.h into an include directorySimon Glass2020-12-221-1/+1
| | | | | | | | | | | | | | | | | | This header file is used from quite a few files, relying on the EC build system to find includes in the driver/tcpm directory. For Zephyr we don't want to add that as an include. It makes more sense for header files to be in an include directory, so move it and fix up the users. BUG=b:175434113 BRANCH=none TEST=build Zephyr and ECOS on volteer Signed-off-by: Simon Glass <sjg@chromium.org> Change-Id: I5851914b1a7d3fdc1ba911c0fbe9046afbaf6f5d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2597985 Reviewed-by: Keith Short <keithshort@chromium.org>
* task_set_event: remove the wait argumentDawid Niedzwiecki2020-12-141-2/+2
| | | | | | | | | | | | | | | | | | | | There is an option in the task_set_event function which force the calling task to wait for an event. However, the option is never used thus remove it. This also will help in the Zephyr migration process. BUG=b:172360521 BRANCH=none TEST=make buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: Ic152fd3d6862d487bcc0024c48d136556c0b81bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2521599 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
* PD: Pull EC_CMD_PD_HOST_EVENT_STATUS into common codeDiana Z2020-05-201-34/+0
| | | | | | | | | | | | | | | | This command is unrelated to the PDCMD task and can be safely pulled into the common PD host command code. After this commit, most boards using the PD_INT tasks may safely remove the PDCMD task from their boards. BRANCH=None BUG=b:154959596 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I2915acd5398a5dc7da2e6daff1e213fc8dfbadc8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2208220 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Add a board specific helper to return USB PD port countKarthikeyan Ramasubramanian2019-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | | Certain SKUs of certain boards have less number of USB PD ports than configured in CONFIG_USB_PD_PORT_MAX_COUNT. Hence define an overrideable board specific helper to return the number of USB PD ports. This helps to avoid initiating a PD firmware update in SKUs where there are less number of USB PD ports. Also update charge manager to ensure that absent/ invalid PD ports are skipped during port initialization and management. BUG=b:140816510, b:143196487 BRANCH=octopus TEST=make -j buildall; Boot to ChromeOS in bobba(2A + 2C config) and garg(2A + 1C + 1HDMI config). Change-Id: Ie345cef470ad878ec443ddf4797e5d17cfe1f61e Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879338 Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Karthikeyan Ramasubramanian <kramasub@chromium.org>
* Rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNTKarthikeyan Ramasubramanian2019-11-011-1/+1
| | | | | | | | | | | | | | | | | Certain SKUs of certain boards have lesser number of USB PD ports than defined by CONFIG_USB_PD_PORT_COUNT. Hence rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNT. BUG=b:140816510, b:143196487 BRANCH=octopus TEST=make -j buildall; Boot to ChromeOS Change-Id: I7c33b27150730a1a3b5813b7b4a72fd24ab73c6a Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879337 Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* host_command: Change host command return value to enum ec_statusTom Hughes2019-10-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the host command handler callback function returns an int, it's easy to accidentally mix up the enum ec_error_list and enum ec_status types. The host commands always expect an enum ec_status type, so we change the return value to be of that explicit type. Compilation will then fail if you accidentally try to return an enum ec_error_list value. Ran the following commands and then manually fixed up a few remaining instances that were not caught: git grep --name-only 'static int .*(struct host_cmd_handler_args \*args)' |\ xargs sed -i 's#static int \(.*\)(struct host_cmd_handler_args \*args)#\ static enum ec_status \1(struct host_cmd_handler_args \*args)##' git grep --name-only 'int .*(struct host_cmd_handler_args \*args)' |\ xargs sed -i 's#int \(.*\)(struct host_cmd_handler_args \*args)#\ enum ec_status \1(struct host_cmd_handler_args \*args)##' BRANCH=none BUG=chromium:1004831 TEST=make buildall -j Cq-Depend: chrome-internal:1872675 Change-Id: Id93df9387ac53d016a1594dba86c6642babbfd1e Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1816865 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* tasks: convert TASK_EVENT_CUSTOM macro to bitJett Rink2019-04-241-2/+2
| | | | | | | | | | | | | | | | | | | | | We should ensure that all custom task definition are non-zero and fit with the globally defined events. Add compile time check and change semantics to specify bit number (instead of making all callers use the BIT macro). This also fixes an error with TASK_EVENT_PHY_TX_DONE for ITE being 0. The bug that made that happen hasn't landed on any firmware branches that use it though. BRANCH=none BUG=none TEST=builds Cq-Depend:chrome-internal:1178968,chrome-internal:1178952 Change-Id: I5e1d1312382d200280c548e9128e53f4eddd3e61 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1570607 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
* Fix inconsistent task function declarationsStefan Reinauer2017-08-081-1/+1
| | | | | | | | | | | | | | | Tasks are defined inconsistently across the code base. Signed-off-by: Stefan Reinauer <reinauer@google.com> BRANCH=none TEST=make buildall -j, also verify kevin boots to OS BUG=none Change-Id: I19a076395a9a8ee1e457e67a89d80d2f70277c97 Reviewed-on: https://chromium-review.googlesource.com/602739 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* usb_pd: only service interrupts on enabled ports.Caveh Jalali2017-06-301-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as it turns out, we're pretty aggressive in iterating over all TCPCs checking for alerts when any of them generate an interrupt or their interrupt line is low. this can cause unfortunate behavior if the driver hasn't initialized itself (and the chip) yet for interrupts to be handled or we've released (disconnected) the driver so we can do a TCPC firmware update. so, check the PD task state to see if it makes sense to service the port's interrupt. note: there seems to be a quirk with the ps8751 in that it holds its ALERT# (interrupt) line low during firmware update. this line is supposed to be falling edge triggered, so it's technically not interrupting, but since we also poll the line level, we think there's a continuous interrupt that isn't acutally there. we get away with this because pd_exchange_status() has a 5ms delay in its polling loop to avoid spinning. the particular test case was to unplug the PD power brick during TCPC firmware update (over i2c). the interrupt handler would be called, accessing the TCPC over i2c and causing all sorts of havoc. TEST=tested with follow-up CLs and verified ps8751 firmware update works on electro. BRANCH=none BUG=b:35586896 Change-Id: I880cff49e0e9637256efa9003bcc46274536e631 Signed-off-by: Caveh Jalali <caveh@google.com> Reviewed-on: https://chromium-review.googlesource.com/544661 Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charge_state_v2: Limit i/p current to meet allowed MAX i/p system powerVijay Hiremath2016-12-051-1/+1
| | | | | | | | | | | | | | | | | | | | | If battery is not present, input current is set to PD_MAX_CURRENT_MA. If the input power set is greater than the maximum allowed system power, system might get damaged. Hence, limit the input current to meet maximum allowed input system power. BUG=chrome-os-partner:58498 BRANCH=none TEST=Manually tested on Reef. Removed the battery & using 'charger' console command observed the following. With Zinger charger at 20V - Input current is set to 2.25A With Type-C & other chargers - Input current is set to 3A Change-Id: Ife8686f322e095aa74b740a7c469bfe87107fb9a Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/397865 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* include/host_command: Conditionally define host event functionsNicolas Boichat2016-11-161-1/+1
| | | | | | | | | | | | | | | | | | | Some functions are only defined if CONFIG_HOSTCMD_EVENTS is set, leading to link-time failures. In particular, do not call these functions from keyboard_scan, and do not define PD host event commands if the configuration option is not set. BRANCH=none BUG=chrome-os-partner:59083 TEST=make buildall -j Change-Id: I0da31cdec08f86f148aa883698a44f462de46d8e Reviewed-on: https://chromium-review.googlesource.com/410923 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* host_command_pd: reduce to 5msec delay in between PD interrupt handlingKevin K Wong2016-11-041-1/+2
| | | | | | | | | | | | | | | | | | | | | | Since PD task are highest priority, the 50msec delay between was intended allow other tasks to execute if PD has continuous interrupt. With two separate TCPC handled by host_command_pd task, interrupt from one TCPC will block the interrupt handling of another TCPC by this 50msec and cause error in the PD negotiation. Reduced to 5msec to ensure TCPC interrupt is handled as soon as possible while allow other tasks to execute if needed. BUG=chrome-os-partner:59061 BRANCH=none TEST=Verify zinger can negotiate to 20V, hoho can get display. Also tested with faking PD interrupt always asserted to check for watchdog reset. Change-Id: I9b71277a3d65923f1f5bbfd744b3399e34fd0e6c Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Reviewed-on: https://chromium-review.googlesource.com/407542 Tested-by: Divya S Sasidharan <divya.s.sasidharan@intel.com> Reviewed-by: Scott Collyer <scollyer@chromium.org>
* host_command_pd: pd_exchange_status: Fix first_exchange logicNicolas Boichat2016-10-201-1/+4
| | | | | | | | | | | | | | | | | | | The code clearly indends to sleep on the second time the loop is taken, but the variable first_exchange is reset to 1 inside the loop. If, for whatever reason, PD alert status cannot be cleared, the code will then loop forever, and lead to a watchdog reset. BRANCH=none BUG=chrome-os-partner:58750 TEST=Flash EC RO using ec_util Run fwupdatetest with charger unplugged for 10 iterations. Change-Id: I9e13f2523111853fdc5c45e75886c11f1c8006eb Reviewed-on: https://chromium-review.googlesource.com/401238 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* tcpm: update code to support multiple tcpm driverKevin K Wong2016-04-171-0/+1
| | | | | | | | | | | BUG=chromium:593822 BRANCH=none TEST=make buildall Change-Id: Ic30c1b890da7639aa80a53040ecc5bebfb4be2e8 Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Reviewed-on: https://chromium-review.googlesource.com/336030 Reviewed-by: Shawn N <shawnn@chromium.org>
* pd: Add common EC_HOST_EVENT_PD_MCU implementationShawn Nematbakhsh2016-01-071-0/+34
| | | | | | | | | | | | | | | | | | | | | For TCPMs with an off chip TCPC, PD MCU host event status can be handled in a common way. When a status flag is updated (ex. from charge_manager), notify the AP through the host event, and save the status flag for later retrieval. BUG=chrome-os-partner:49124 BRANCH=None TEST=Verify `cat /sys/class/power_supply/CROS_USB_PD_CHARGER1/online` on chell reflects the actual online status of the charger. Also verify UI charge icon tracks the online status correctly. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I63bc70205627474590e38ffd282faedaea3bcc66 Reviewed-on: https://chromium-review.googlesource.com/320796 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* pd: Add support for multiple distinct TCPC alert signalsShawn Nematbakhsh2015-11-251-9/+17
| | | | | | | | | | | | | | | | | | | | | If multiple TCPCs are present on a system then we may have multiple alert signals, each of which alerts us to the status of a different TCPC. Make boards with external non cros-ec TCPCs define tcpc_get_alert_status, which returns alert status based upon any alert GPIOs present, and then service only ports which are alerting. BUG=chromium:551683,chrome-os-partner:47851 TEST=Verify snoball PDCMD task sleeps appropriately when no devices are inserted, and verify ports go to PD_DISCOVERY state when we attach samus. Also verify that glados / glados_pd can still negotiate PD. BRANCH=None Change-Id: Iae6c4e1ef4d6685cb5bf7feef713505925a07c8c Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313209 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
* pd: Allow EC to request PD hibernate via host commandShawn Nematbakhsh2015-10-051-19/+23
| | | | | | | | | | | | | | | | | | | On some systems, we may wish to have the PD follow the EC into hibernate. Add a status field to EC_CMD_PD_EXCHANGE_STATUS to support this. BUG=chrome-os-partner:45010 TEST=Manual on glados with subsequent commit. Run 'hibernate' on EC console, verify that both EC and PD go to hibernate. Plug zinger and verify that both EC and PD wake, AP boots, and battery begins charging. BRANCH=None Change-Id: I0476bc8a47ffb0fe113dccda9d4f8074105c1c84 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/302712 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* host_command_pd: loop over sending PD status host commandAlec Berg2015-07-291-69/+83
| | | | | | | | | | | | | | | | | | | | | | | | Modify host_command_pd.c to loop over sending of PD status host command and processing the response as long as the alert GPIO is active. This fixes a potential bug that if the alert line is held low for more than one PD status host command, then we would not process the return status. Also, fix a bug in which we could call alert() for a non-existent port. BUG=none BRANCH=strago TEST=verified on samus and glados. connected charger and verified that we negotiate a contract and set appropriate input currnet limit. Change-Id: I3b2db87b51f55fc2b20a4695bd466ff8bb09ea55 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/288819 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Trybot-Ready: David James <davidjames@chromium.org>
* pd: allow pdcmd task to check TCPC alert status w/o sending HCAlec Berg2015-06-231-9/+22
| | | | | | | | | | | | | | | | | | | | | | Modify PDCMD task to allow for TCPCs that do not support host commands. CONFIG_HOSTCMD_PD is a new config option to be used by TCPCs that implement our host command protocol such as the PD MCU on glados and oak. Otherwise, the PDCMD task will not send host commands and will be used simply to check TCPC interrupt status. BUG=none BRANCH=none TEST=test on glados and samus and make sure we can send host commands from the EC to the PD and that we can negotiate a PD contract. Change-Id: I618badb5db3f9e490ae4eedfdb2a0c54513496ff Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/278215 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pd: Add support for TCPC Alert and Alert_Mask registersScott2015-06-231-10/+48
| | | | | | | | | | | | | | | | | | | Changed the alert function to hold the ec_int line until all of the alert bits are cleared. Added support for the alert_mask register. In addition, created ec_int_status variable to distinguish which of 3 ec_int sources is driving the pd_mcu_int line. BUG=none BRANCH=tot TEST=Tested Zinger to Glados and Zinger to Samus and verified that it established a power contract in both cases. Did not test Oak, but put exact same changes in board.c as in glados. Change-Id: I372e75b8fd5d66a0c01db18b46100b86fd9ac064 Signed-off-by: Scott Collyer <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/278256 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* pd: use pdcmd task to handle tcpc interruptAlec Berg2015-06-051-5/+18
| | | | | | | | | | | | | | | | | | | | Use the PDCMD task to handle PD MCU interrupts, and use it to trigger the tcpc_alert(). Note this fixes bug on Glados and Oak that could cause watchdog reset because tcpc_alert() which uses i2c to talk to tcpc was called from hooks task and can delay tickling watchdog. BUG=chrome-os-partner:40920 BRANCH=none TEST=load on glados and plug zinger into both ports many times. make sure we get a stable contract and no watchdog reset. Change-Id: I37625fae2ca0057d2ee8fa1eea6974f2d26d1b91 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/275296 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* samus: panic reboot EC if PD MCU crashesAlec Berg2015-02-181-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | Use the EC to check if PD MCU has crashed. The EC knows this by checking the PD status bits: if PD MCU was in RW, and is now in RO, AND it did not get to RO via a sysjump, then it must have crashed. When the EC detects this, the EC will also panic and reboot the entire system, so that we can software sync to a known good state. Also, when EC panics due to PD crash, it will log panic info. BUG=chrome-os-partner:36636 BRANCH=samus TEST=load onto samus EC and PD, try sysjump'ing back and forth on PD MCU console and verify EC does not do anything. Crash the PD MCU when in RW by reboot command and crash divzero command, and make sure the EC panics with PD crash panic message. Crash the PD MCU when in RO (before sysjumping to RW) and make sure EC does not panic. Change-Id: I57961028e6b23a878b8e477a9d8e180cb121a742 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/250100 Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* samus: fix lightbar tap sequence doesn't always show on AC eventAlec Berg2015-02-041-10/+31
| | | | | | | | | | | | | | | | | | | | | | | | Fix bug on samus that the battery status doesn't always show on lightbar when AC is plugged/unplugged. It doesn't show when the battery is full is S3 or S5 because in these states we turn off CHARGE_EN so that ACOK to the EC never toggles. Instead, what we want to do is display battery status whenever the active charge port changes. This will happen when AC is plugged or unplugged OR if a user has AC on both ports and toggles between them using the charge override hot-keys. BUG=chrome-os-partner:36317 BRANCH=samus TEST=test plugging and unplugging AC on both sides when battery is full and unit is in S0, and when unit is in S5. also tested lightbar flashes battery percentage when two zingers are plugged in and you switch between them using Ctrl+Search+0|1|2. Change-Id: I5cd7fff4f466adf857f1e63f07f3b0c7ae8422c7 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/245922 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* samus: automatically recover from charge circuit failuresstabilize-6752.BAlec Berg2015-02-031-3/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Occasionally the charge circuit on samus gets wedged and will not charge. This change detects when the charge circuit has failed and automatically recovers from it. It uses the BQ PROCHOT warning to detect the failure by setting PROCHOT to trigger when the BQ thinks input current is higher than the input current limit. When the failure is detected, the EC disables charging and tells PD MCU to disable CHARGE_EN, then a couple seconds later, it re-enables charging. This CL also adds more communication between EC and PD for the EC to be able to set the charge state for the PD. Valid charge states are: No charging allowed, 5V charging only, and max charging. The EC uses this as such: - When the EC gets AC present interrupt, it sets off a deferred function to change charge state to max charging after some delay to give time for the charge circuit to settle down. - When the EC gets AC disconnect interrupt, it disables charging briefly, enables learn mode, and then sets 5V charging allowed. This allows for the same starting conditions in the charge circuit for every AC attach. - When the EC detects a wedged charge circuit, it disables charging and waits a few seconds before re-enabling 5V only charging. Additionally, this change moves the charging cutoff in S3/S5/G3 when the battery is full to the EC. With the added control for the EC to set the PD charging state, it is more convenient for the EC to manage cutting off charging when battery is full. BUG=chrome-os-partner:36081 BRANCH=samus TEST=test the basics: - connect/disconnect zinger a bunch of times - connect and disconnect two zingers in different order - connect two zingers and charge override between the two test the automatic charge wedge recover: - wedge the charge circuit by setting charger voltage under battery voltage: "charger voltage 7000" - wait a few seconds for the system to recover and check it is charging with "battery" command test full battery charge cutoff: - added console command to change battery soc in board/samus/extpower.c: static int cmd_battfake(int argc, char **argv) { char *e; battery_soc = strtoi(argv[1], &e, 10); batt_soc_change(); return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(battfake, cmd_battfake, "", "", NULL); - in S0, tested "battfake 100" does not disable charging. - in G3, tested "battfake 100" disables charging and "battfake 99" re-enables charging. - set "battfake 100" and tested transitioning to S0 enables charging and transitioning to S5 disables charging. - attached two chargers and used charge override to select active port. then toggled "battfake 100" to "battfake 99" back and forth and verified charge override port is still the same. test third-party 12V charger: - plug in a bunch of times and make sure we stay at 5V for 500ms and then transition to 12V test with no battery: - tested five different units with no battery and just zinger. 3/5 boot, while the other 2 don't. But, the 2 that don't boot without battery also can't boot w/o battery when this CL is reverted, so I don't think this change is causing the problem, I think there is an electrical limitation. test with EVT zinger: - EVT zingers (P2 - C2) negotiate very quickly after connection, which can cause INA problems w/o this CL. Tested an EVT zinger with samus and did a bunch of connections and disconnections and verified that we always wait at 5V for 500ms and that we don't wedge the INA circuit on connect. test backwards compatibility: - test new PD with old EC and make sure we can charge with zinger. (note that if the charge circuit wedges, we won't be able to unwedge it). - test old PD with new EC and make sure we can charge with zinger. Change-Id: I7703b7a2ab1209d7f559b265b03517e79c74b16a Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/245253 Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* lightbar: ask the PD MCU for the charge directionBill Richardson2014-12-111-5/+10
| | | | | | | | | | | | | | | This exposes the pd_exchange_status() function and lets it return the charge port that the PD reports, so that the lightbar TAP sequence can decide which direction to display. BUG=chrome-os-partner:32227 BRANCH=ToT, samus TEST=make buildall -j Change-Id: I78b57fbeaaf38fee15c86eca4d90abce77e2f722 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/232092 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* samus: exchange status with PD MCU on bootAlec Berg2014-09-171-0/+2
| | | | | | | | | | | | | | | | | | | | | On boot, the EC should send host command to exchange status with PD MCU. This allows EC to get the correct input current limit when EC reboots and PD does not. Also had to move some of the charger state machine initialization to run with HOOK_INIT so that it runs before the tasks run. BUG=none BRANCH=none TEST=tested on EVT samus. Without this change, if you reboot EC, and run charger command, the charger input current limit is 512mA. with this change, when the EC reboots, it sends host command to PD MCU to get current limit and sets it appropriately. Change-Id: I5426f0fc3a62b6cd7a73f55cb11b895902a54903 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/216879 Reviewed-by: Todd Broch <tbroch@chromium.org>
* samus: add automatic retries for host commands from EC to PDAlec Berg2014-09-171-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add three retries for EC to PD host commands. With this change, removed retry mechanism in host_command_pd.c which was a retry only for the specific EC_CMD_PD_EXCHANGE_STATUS host command. BUG=chrome-os-partner:32006 BRANCH=none TEST=Loaded EC code onto samus. Added the following code for testing failed host commands to samus_pd common/host_command.c host_command_task(): if ((evt & TASK_EVENT_CMD_PENDING) && pending_args) { if (i++ != 4) pending_args->result = host_command_process(pending_args); else { pending_args->result = -7; i = 0; } host_send_response(pending_args); } This test code on samus_pd drops one in every five host commands. With this code, from the EC, I send "pdcmd 0 0", and verified that 1 out of 5 times the EC prints a host command failed code, but then retries successfully. Change-Id: Ibf43feefbfc7d791c45c6689b82c66f5d71046ab Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/217461 Reviewed-by: Todd Broch <tbroch@chromium.org>
* host_command_pd: Fix condition for sending a PD MCU host eventShawn Nematbakhsh2014-08-281-1/+1
| | | | | | | | | | | | | | | | PD_STATUS_HOST_EVENT is a non-zero bitmask, so use '&' to check the proper bit(s) in the condition. BUG=chrome-os-partner:31361 TEST=Manual on Samus. Plug + unplug zinger, verify that host events are not set. Also, verify that 'pdevent' console command still sets the host event. BRANCH=None. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I15c61c3c872ce8e7425678b2c669fcfa1eec89a6 Reviewed-on: https://chromium-review.googlesource.com/214631 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* samus: add ability for PD MCU to send host event to APAlec Berg2014-08-271-0/+4
| | | | | | | | | | | | | | | | | | | | | Add host event for PD up to AP. The PD toggles a gpio line to EC causing an interrupt on EC. The EC then sends host command down to PD MCU to get its status. There is a new status bit for PD host event, so when EC see's the PD host event status bit, it sends a PD host event to the AP. There is currently only one host event for PD to AP. BUG=chrome-os-partner:31361 BRANCH=none TEST=added PD console command pdevent, which initiates the host event. when sent, verified on EC that it sets the correct host event bit using hostevent console command Change-Id: If1a59a3232e2f9a49f272c6dee5319254d87b9a9 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/213371 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* samus: change input current limit to the real limitAlec Berg2014-08-261-7/+0
| | | | | | | | | | | | | | | | | | | Remove the hack to set the input current limit to 2/3 of the real limit. This was a hardware limitation of p2b systems. This change will only work on EVT. BUG=chrome-os-partner:28532 BRANCH=none TEST=loaded onto a samus with all of the charging circuit reworks and tested with an EVT zinger to make sure we don't OCP the zinger. We limit current to 2944mA and zinger reads current draw as 3150mA. The discrepancy is a hardware problem on zinger side measuring current, but is still comfortably below 3.6A OCP limit. Change-Id: Ia6adc79a0c6c7599ded76fb8f48de1479f021fe1 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/213772 Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* samus: ryu: fix charge state machine init of input currentstabilize-6146.BAlec Berg2014-08-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | Currently charge state machine resets input current limit to default every time AC is connected. Problem is by the time charge state machine gets around to setting input current, it could have already been set by successful PD negotiation, and this ends up overriding that value. This fix has the state machine store desired input current limit, as determined from PD negotation or any other place, and send last desired input current limit on AC connect. BUG=chrome-os-partner:24461 BRANCH=none TEST=load on samus, test toggling between "pd 0 dev 5" and "pd 0 dev 20", and test plugging and unplugging zinger numerous times, and verify charger command always gives the expected input current limit based on PD negotiation. Change-Id: I18d8acc9e2085739e783c9c70c682d46bcce7fdb Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211639 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* samus: ryu: set input current limit based on PD negotiationAlec Berg2014-08-091-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Set input current limit based on the max current from the PD negotiation. For samus, this information is passed to the EC as a host command. For ryu, the max current is set directly following a negotiation. CONFIG_CHARGER_INPUT_CURRENT is now just the default limit, but after a successful PD negotiation, the limit can be raised. Note, for now the input current limit for samus is set to 2/3 of the value negotiated for. This is due to hardware problems measuring input current on p2b boards. BUG=chrome-os-partner:28532, chrome-os-partner:24461 BRANCH=none TEST=tested on a samus. Verified input current limit using "charger" console command from EC. Input current limit after a reboot is 512. When zinger is plugged in, it jumps to the appropriate value (currently 1280mA), and when the negotiation is changed using the "pd 0 dev 5" command on the PD console, the input current limit is adjusted to match (2000mA). Change-Id: Iab9186a0f9814655e3240217a9baf4a38f15f84d Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211023 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* samus_pd: remove dead code around allowing PD negotiationAlec Berg2014-08-061-4/+0
| | | | | | | | | | | | | | | | | | | | Remove code for preventing PD negotiation until the battery is at some minimum SOC. This was originally necessary because transitioning voltages would cause the source voltage to go briefly to 0V, which would kill power to the system unless the battery was at some minimum level of charge. But, that isn't true anymore. It is safe to transition up or down in voltage and the source voltage should never drop to 0V. BUG=chrome-os-partner:29499 BRANCH=none TEST=make -j buildall. No need to do any more testing because this code has been disabled for a while. Change-Id: I8a3dca117f01f0f9c7d04b5d489e4a8588a89be6 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211021 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* samus: use real AC_PRESENT signalAlec Berg2014-07-111-15/+1
| | | | | | | | | | | | | | | | | | | | | | | Revert - https://chromium-review.googlesource.com/#/c/205145/2 - https://chromium-review.googlesource.com/#/c/205147/4 Now using the real AC_PRESENT gpio signal instead of whether or not the PD MCU negotiated for 20V. BUG=chrome-os-partner:29841, chrome-os-partner:29842 BRANCH=none TEST=tested on a board with reworked AC_PRESENT signal. Verified that gpio is correctly reporting state of AC and is charging when AC is plugged in. Tested the no battery case to make sure board powers on and stays on with just a charger. Also tested the dead battery case by plugging in a dead battery, then plugging in a charger and making sure system powers on and starts charging. Change-Id: I4424771c91c8a2aa19eda68a8b5194e9265d529c Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/206598 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* samus: add retry mechanism for EC to PD host commandsAlec Berg2014-06-281-2/+13
| | | | | | | | | | | | | | | Add a retry mechanism for EC to PD host commands to make the communication channel more robust. BUG=none BRANCH=none TEST=run on system to verify that we don't drop host commands to PD MCU. Change-Id: Ida6f02a149e4dd9e85a5aac21790928b16864104 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205148 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* samus: hack to read AC present state from PDDuncan Laurie2014-06-271-2/+20
| | | | | | | | | | | | | | | | | | The ACOK input to the EC is not connected to the charger so that signal cannot be relied on for AC presence. Instead have the PD report when it negotiates to 20V and when it disconnects and have the EC use that for AC presence. BUG=chrome-os-partner:29841 BRANCH=none TEST=test charging with zinger on samus system. Change-Id: Ia9096a24ab05d110e31910218dc8c214a846a9a4 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205145 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* samus: Allow samus to charge w/o battery or with dead batterystabilize-5942.BAlec Berg2014-06-091-0/+52
Use a EC to PD host command to notify the PD MCU when a battery is present and charged enough that it is ok to negotiate for a higher power. The PD MCU will not negotiate until the host command is received, which allows the system to be powered without a battery or with a dead battery with 5V. BUG=chrome-os-partner:28611 BRANCH=none TEST=Tested on a samus: 1) Tested the normal case of battery charged and plugged in. When charger is plugged in, the device immediately starts negotiating for 20V and starts charging. 2) Tested with no battery. Plug in a charger, samus boots and stays alive. VBUS measured at 5V. When a battery is plugged in, device negotiates for 20V and starts charging. 3) Tested dead battery by taking a battery with no charge, and plugging in zinger. Everything boots, but PD does not negotiate for power. Then when battery reaches 1%, PD negotiates and zinger switches to 20V without causing a reboot. Change-Id: Iaa451403674e86cddbd3fe80e9503584910be576 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/201958 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>