summaryrefslogtreecommitdiff
path: root/common/usb_charger.c
Commit message (Collapse)AuthorAgeFilesLines
* bd99955: Improve interrupt / USB charger task wake schemeShawn Nematbakhsh2016-06-161-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Previously our charger ISR called a deferred task which woke our charger task. We can skip the deferred task and just wake our charger task directly. The other meaningful change here is to assume that we're using the charger for VBUS detection / BC1.2 if we have a usb_chg task, which holds true for all of our current boards with this charger. BUG=None TEST=Manual on kevin with subsequent commit. Verify charger connect / disconnect detection works properly on both ports, with zinger, donette and generic DCP charger. BRANCH=None Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Iad4f3ea90947b50859c549b591675e325717209f Reviewed-on: https://chromium-review.googlesource.com/352822 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* BD99955: Use only one USB charger task for both the portsVijay Hiremath2016-06-141-0/+5
| | | | | | | | | | | | | | | | | | | | | There is only one charger IC and one interrupt PIN for both the ports and also from the ISR it's not possible to decode from which port the interrupt is triggered hence a deferred function is used to trigger the wake event for the ports. As there is no additional benefit of having an extra task, added code to use only one USB charger task for both the ports. BUG=chrome-os-partner:54272 BRANCH=none TEST=Manually tested on Amenia. BC1.2 detection is success and the battery can charge on both the ports (VBUS/VCC). Change-Id: I2745a5a179662aaeef8d48c8c1763919e8853fd0 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/351752 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>
* Driver: BD99955: Use Charger interrupt to detect VBUS activityVijay Hiremath2016-06-081-5/+7
| | | | | | | | | | | | | | | | | | | Added support to enable the BD99955 charger interrupt to detect the VBUS activity. With this approach GPIO USB_Cx_VBUS_DET_N pin can be removed. BUG=chrome-os-partner:53688 BRANCH=none TEST=Manually tested on Amenia. Type-C, DCP & SDP chargers can negotiate to desired current & voltage. Battery can charge. USB3.0 & USB2.0 sync devices are detected by the Kernel. Change-Id: I5470092c5cd43026aafc1a638ba446d0037c71e7 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/343650 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>
* usb_charger: Support inverted 5V_EN GPIO polarityShawn Nematbakhsh2016-06-021-2/+8
| | | | | | | | | | | | | | | | | Kevin uses inverted polarity (low = enable 5V output), so add a new CONFIG to support this. BUG=chrome-os-partner:53777 BRANCH=None TEST=Manual on Kevin. Enable USB charger tasks, verify that VBUS is properly detected on no-battery case. Change-Id: Ifb3e5fa9db1973d9826435712711f0cb0fd1d3a5 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/349260 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cleanup: pd: Define VBUS detection sourceShawn Nematbakhsh2016-06-021-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously CONFIG_USB_PD_TCPM_VBUS had two uses which were independent: - When operating as a TCPC, it indicated that the VBUS level should be tracked (through GPIO inputs) and sent to the external TCPM when appropriate. - When operating as a TCPM, it indicated that the VBUS level should be obtained by querying the TCPC. These two independent uses have been split into CONFIG_USB_PD_TCPC_TRACK_VBUS and CONFIG_USB_PD_VBUS_DETECT_TCPC, which sould be more clear. In addition, CONFIG_USB_PD_VBUS_DETECT_* CONFIGs have been added for other means of VBUS detection. BUG=chromium:616580 BRANCH=None TEST=Verify kevin continues to boot + charge. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I936821481d6577e17e3e9c61ff97c037574d6923 Reviewed-on: https://chromium-review.googlesource.com/348950 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* reef: Initialize charge suppliers after change manager is initializedVijay Hiremath2016-05-281-2/+2
| | | | | | | | | | | | | | | | | | Initialize the charge suppliers after change manager is initialized, otherwise charge supplier current & voltage values will be overwritten to -1 by the charge manager ini function. BUG=chrome-os-partner:53788 BRANCH=None TEST=Observed there are no "CL: p(port) s(supplier) i-1 v-1" prints on the EC console. Change-Id: Id0212c502d5833c016ac79ee15d21304d6d7ceb2 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/347896 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>
* usb_charger: Move part-specific code to usb_switch driverShawn Nematbakhsh2016-05-131-189/+6
| | | | | | | | | | | | | | | | | | | | | | | Previously usb_charger.c supported only pi3usb9281, but now support for additional parts is required. Move pericom-specific code (including the usb_charger tasks that handles various quirks of that part) to the pi3usb9281 usb_switch driver. Going forward, usb_switch drivers must implement usb_charger_set_switches() and must have some method (such as a task or interrupt handler) to update charge_manager with information about attached chargers. BUG=chrome-os-partner:53363 BRANCH=None TEST=`make buildall -j` Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I4df74e043d8cf2e532d48c39c73b7dc2930f7d3b Reviewed-on: https://chromium-review.googlesource.com/344289 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* oak: avoid reading BC1.2 interrupt reg during handling vbus eventBen Lok2016-03-011-8/+8
| | | | | | | | | | | | | | | | | | | | PI3USB9281 may not assert the interrupt line if device is detached and reading the interrupt register simultaneously. And it is not necessary to check the interrupt status when vbus change event happens. To prevent losing the detach interrupt during vbus change event happens, only check the interrupt status only if receiving the USB_CHG_EVENT_INTR event. BUG=chrome-os-partner:48797 BRANCH=none TEST=Plug/Unplug PD charger 20 times, UI should not display "Low power charger" warning message each time during the PD charger is unplugged. Change-Id: I51fe68732ece882029f1503294c2122cfbb00c34 Signed-off-by: Ben Lok <ben.lok@mediatek.com> Reviewed-on: https://chromium-review.googlesource.com/328897 Reviewed-by: Shawn N <shawnn@chromium.org>
* usb_charger: disconnect usb switch until connection is debouncedAlec Berg2015-11-111-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | Re-order logic in BC1.2 detection task so that we open the USB switches immediately upon detecting a connection, then debounce the connection, then reset the pericom and determine BC1.2 charger type. This fixes two problems: - Problem where host could enumerate dut, detect disconnect, and then re-enumerate. - Problem where sometimes dut would detect a host workstation as a proprietary charger because we weren't delaying long enough after opening USB switches before triggering pericom reset. BUG=chrome-os-partner:47219 BRANCH=smaug TEST=tested by connecting workstation to ryu (tested both pluggin in A side first and C side first). Without this patch, my workstation often see's disconnect and reconnect. With this change we only get one connect. Change-Id: I07cc3473ff32953fad3cc6d1db01b86b44969c4e Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311804 Reviewed-by: Shawn N <shawnn@chromium.org>
* pd: send soft reset on boot if VBUS is presentAlec Berg2015-10-231-0/+2
| | | | | | | | | | | | | | | | | | | | | | On boot, if VBUS is present, then when PD protocol gets to SNK_DISCOVERY state, if it times out waiting for source cap, then send attempt to send a soft reset first instead of directly sending a hard reset. This allows us to not lose VBUS in the case that we were in a stable contract as a sink before this boot (for example a sysjump or EC reboot). BUG=chrome-os-partner:44085, chrome-os-partner:44952 BRANCH=none TEST=test on glados and samus. test by sysjumping between RO and RW with zinger plugged in and no battery, and verify that we don't lose power. also test rebooting with a battery and verify we don't lose power. also tested with a third party PD charger. Change-Id: Ib7ce46d8b9843db66805ba3237d8919d611324e0 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/308201 Reviewed-by: Rong Chang <rongchang@chromium.org>
* oak: handle USB BC 1.2 status changeRong Chang2015-09-031-4/+11
| | | | | | | | | | | | | | | | Before oak rev4, BC 1.2 status change was polled on VBUS change. The designed is changed to use a single interrupt pin for both ports. BRANCH=none BUG=chrome-os-partner:42610 TEST=manual make EXTRA_CFLAGS=-DBOARD_REV=3 BOARD=oak -j emerge-oak chromeos-ec load on oak rev3 and check BC 1.2 charging current Change-Id: I9e6cdbb83468b5e4086cc86caadf7f2e3cbe6e48 Signed-off-by: Rong Chang <rongchang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/294442
* oak: add usb charger tasksAlec Berg2015-08-211-0/+4
| | | | | | | | | | | | | | | Add USB charger tasks to oak to detect legacy charger type. BUG=none BRANCH=none TEST=make -j buildall Change-Id: Idb8061c39b0bb8b42f47cbe3ff213b04f14c889a Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/290420 Reviewed-by: Rong Chang <rongchang@chromium.org> Commit-Queue: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* usb_charger: move common usb charger code out of board directoryAlec Berg2015-08-051-97/+183
| | | | | | | | | | | | | | | | | | | | Move common USB charger code out of board directory including setting VBUS supplier when VBUS changes, and initializing BC1.2 supplier types on init. This also enables re-enabling of Pericom BC1.2 detection interrupts when VBUS is changed on all boards that use USB_CHG task. BUG=chrome-os-partner:42292 BRANCH=none TEST=make -j buildall. Tested on glados and samus by plugging in a few different chargers and making sure we charge. Change-Id: Ib102fbf7a6aace998e6fcb6d35f3c97e5f03f5c2 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/290453 Reviewed-by: Shawn N <shawnn@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org>
* usb_charger: cleanup: move setting usb 2 switches to usb_chargerAlec Berg2015-08-041-1/+21
| | | | | | | | | | | | | | Move function to set D+/D- switches from board directory to usb_charger module. BUG=none BRANCH=strago TEST=make -j buildall Change-Id: I5c5997c799cecea90448444863167af860a8f3e1 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/290421 Reviewed-by: Shawn N <shawnn@chromium.org>
* cleanup: define one set of USB charger voltage and min currentAlec Berg2015-07-131-1/+1
| | | | | | | | | | | | | | | Remove duplicate definitions of USB charger min current across boards and make one set of defines for standard USB charger voltage and minimum USB charger current. BUG=none BRANCH=smaug TEST=make -j buildall Change-Id: Ib842fafb317417c8de9a67d314fdde4c1e47ad9d Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/284956 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pi3usb9281: fix BC1.2 re-detection when using USB device modeVincent Palatin2015-07-011-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | When the USB2.0 port is used in device mode, having the D+/D- lines connected just before resetting the PI3USB9281 (for the 2nd detection used a BC1.2 debouncing) triggers a misdetection where DCP chargers are seen as Apple 2.4A chargers. To avoid this, disconnect the D+/D- lines and let them relax before triggering the PI3USB9281 reset. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=smaug BUG=chrome-os-partner:42048 TEST=connect and disconnect a DCP charger to the Smaug type-C port with the AP running, see it constantly detected as DCP and no Pericom interrupt storm. Change-Id: I8f6043439c2c6b52f2689b4947baffe51f62eba8 Reviewed-on: https://chromium-review.googlesource.com/282594 Reviewed-by: Shawn N <shawnn@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Trybot-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
* usb: pi3usb9281: Allow flexible chip configurationsShawn Nematbakhsh2015-06-121-6/+19
| | | | | | | | | | | | | | | | | | Previously we supported using a single pi3usb9281 chip, or using two chips on the same i2c bus behind a mux. Now that we need to support a third configuration of multiple chips on different busses, it makes sense to be able to configure the configuration freely at the board level. BUG=chrome-os-partner:40920 TEST=Manual on samus_pd. Plug USB charger, verify detection is correct on both charge ports. BRANCH=None Change-Id: I120dcb1c3ceb6f013b92407effcd8cb66e7ffcce Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276511 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charger: Move USB charger / BC1.2 task to common codeShawn Nematbakhsh2015-06-101-0/+138
Move the task responsible for detection of USB chargers to common code to reduce code duplication. BUG=chrome-os-partner:40920 TEST=Manual on samus_pd. Plug USB charger, verify detection is correct on both charge ports. BRANCH=None Change-Id: I362f8b5b51741509e459c66928131f1f6d2a3b1d Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276210 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>