summaryrefslogtreecommitdiff
path: root/common/pmu_tps65090_charger.c
Commit message (Collapse)AuthorAgeFilesLines
* Move battery temp ranges to battery_info structRandall Spangler2013-12-031-6/+12
| | | | | | | | | | | | | | | | | | This allows boards to detect the battery and return the correct temp ranges, which will be needed for upcoming boards. In the board-specific implementations, it's pretty much just moving the fields from one const struct to another, so the impact is minor. BUG=chrome-os-partner:24310 BRANCH=none TEST=build all platforms; verify pit and rambi still charge Change-Id: I7be075b3abb4039577f6362316adc1860c121d5c Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/178424 Reviewed-by: Yung-chieh Lo <yjlou@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org>
* Add battery_get_params()Randall Spangler2013-12-021-22/+27
| | | | | | | | | | | | | | | | | | | | | | | | The charge state machine asks for all of this stuff at the same time anyway. Bundling it into a single function removes a number of redundant (and painfully slow) I2C reads. Also refactor the battery debug command so it doesn't have so many local variables all in one function; it was consuming considerably more stack space than any other debug command. Spring still needs low-level access to the smart battery, so move the two functions it needs directly into the Spring implementation. BUG=chrome-os-partner:20881 BRANCH=none TEST=charge/discharge rambi, pit and spring; watch debug messages and LED and output of 'battery' debug command. All should behave the same as before. Then run 'taskinfo' and see that the console task has at least 20 bytes unused. Change-Id: I951b569542e28bbbb58853d62b57b0aaaf183e3f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/177797
* cleanup: Still more TODO commentsRandall Spangler2013-11-021-5/+4
| | | | | | | | | | | | | More of same. Comment changes only; no code changes. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all platforms; pass unit tests Change-Id: I8c42ed7d332cd9d461067e1aeac670855106cbcd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/175405 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* cleanup: Battery header files and filenamesRandall Spangler2013-10-071-2/+2
| | | | | | | | | | | | | | | | | | | | battery.h is the high-level interface. battery_smart.h is the low-level interface. Most things don't need the low-level interface, but were including smart_battery.h solely to get at battery.h. Fixed this. Also merged battery_pack.h into battery.h, since it was odd to split that data across multiple header files. Tidied the function comments in battery.h as well. No functional changes, just renaming files and adding comments. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all boards; pass unit tests Change-Id: I5ef372f0a5f8f5f36e09a3a1ce24008685c1fd0d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/171967 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Always enable tpschrome low current chargingRong Chang2013-10-021-20/+4
| | | | | | | | | | | | | | | | | | | | | The PMU charger loop is conservative. And there is no need to set hardware low charging current termination. BRANCH=pit BUG=chrome-os-partner:22946 TEST=manual Discharge the battery to level < 40%. Issue console command 'pmu', check register 0x09 output. The NOITERM bit(5) should be set to 1. That means no low charging current termination. Signed-off-by: Rong Chang <rongchang@chromium.org> Change-Id: I45532dcaab3bab566407b209f26693e2c3451014 Reviewed-on: https://chromium-review.googlesource.com/170906 Reviewed-by: Hung-ying Tyan <tyanh@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Jaehoon Kim <jh228.kim@samsung.com> Tested-by: Jaehoon Kim <jh228.kim@samsung.com>
* stm32: Fix polarity of charger interruptRandall Spangler2013-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | The charger interrupt is active-low. Snow and Spring properly triggered on falling (asserting) edge, but Pit (and Daisy/Puppy) didn't. Fix those boards, and rename the signal to end in _L so we don't make that mistake again. BUG=chrome-os-partner:22827 BRANCH=pit TEST=unplug/replug AC adapter on pit; see debug output as follows: [batt] state charging -> idle0 Charger IRQ received. [batt] state idle0 -> charging Charger IRQ received. Change-Id: I1f5c9370d1118461dc033955ba77aab2cebb7ece Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/170256 Reviewed-by: Jaehoon Kim <jh228.kim@samsung.com> Tested-by: Jaehoon Kim <jh228.kim@samsung.com> Reviewed-by: Doug Anderson <dianders@chromium.org>
* pit: Change battery level warning and shutdown levelsDerek Basehore2013-09-121-4/+4
| | | | | | | | | | | | | | | | | This causes the EC to give a warning when the battery is less than 3.5% and shutdown when the batteyr is less than 1.5% BUG=chrome-os-partner:21926 TEST=check that warning happens at < 3.5% and shutdown happens at < 1.5% on the EC console. Change-Id: I1bd06f632e969b55bbb041c65ab106ef764e454b Signed-off-by: Derek Basehore <dbasehore@chromium.org> (cherry picked from commit 2f93978e5e5dcf841ef24fa6b9ba2fa9459d3d98) (cherry picked from commit 447d69abcb3c61440d89b4aac8c4472a35b3b77d) Reviewed-on: https://chromium-review.googlesource.com/169055 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Rename extpower_usb to extpower_springVic Yang2013-08-281-4/+4
| | | | | | | | | | | | | | | | | | | The ID detection and charging circuits on Spring are very different from that on Kirby. PWM current limit is no longer used. The ID detection sequence is also different. Also, there is no boost circuit on Kirby. Given those hardware issues that we had to work around on Spring, it's unlikely that we will have another board that shares the same/similar ID detection design with Spring. Let's rename extpower_usb to extpower_spring to better reflect this. BUG=None TEST=Build and boot Spring. BRANCH=None Change-Id: I7c212a121eed55665593cb7e1b2b672891819940 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/67031
* Use macros for C <-> K conversionsBill Richardson2013-08-071-10/+5
| | | | | | | | | | | | | | | This just replaces all the "X - 273", "Y + 273" stuff with a macro. BUG=none BRANCH=falco,peppy TEST=manual Run the EC console command "temps". It should print human-readable things. Change-Id: Icc4284c89fdbc0cd3b206a0faacf121973652a63 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/65005 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Move TPSChrome charging temperature range to battery packRong Chang2013-07-241-15/+15
| | | | | | | | | | | | | | | | | This change moves vendor specific temperature ranges to battery pack files or board setup files. And added a host test case to verify that does not change x86 smart battery charging state machine behavior. BUG=chrome-os-partner:21181 BRANCH=None TEST=manual build test: util/ecmakeall.sh hosttests: make hosttests && make runtests Change-Id: I48e76826b5555f64b78e3c063ce5f02416c72aa2 Signed-off-by: Rong Chang <rongchang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62978 Reviewed-by: Vic Yang <victoryang@chromium.org>
* Reset charge state machine on charge timeoutVic Yang2013-05-201-0/+8
| | | | | | | | | | | | | | | | For Spring, the charging time can be quite long and TPS65090 ends up in timeout state and stops charging. Let's put charge state machine back to re-init so that the device continues charging after checking charging condition is good. BUG=chrome-os-partner:19405 TEST=Pass charger test BRANCH=spring Change-Id: I838741e7283eb31ed76cf3979dbad7f070947aea Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/55720 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Clean up SPI GPIOsRandall Spangler2013-05-131-7/+0
| | | | | | | | | | | | | | | | | | | SPI is always enabled on pit, so remove #ifdefs SPI1_CLK was aliased to AC_STATUS, which is left over from snow and doesn't exist on pit. That caused it to be driven high briefly during EC boot. Also set SPI pins for 40MHz speed so we can try faster SPI clock. BUG=chrome-os-partner:19304 BRANCH=none TEST=boot system; sspi 2:0 256 9f prints a bunch of FDs then FEEC010001 Change-Id: I10352cff3669d6a087939d9d8e302d70708e9ee3 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/51023 Reviewed-by: Doug Anderson <dianders@chromium.org>
* Rename REINIT to IDLE0 in TPS65090 charge state machineVic Yang2013-05-011-24/+16
| | | | | | | | | | | | | | | | The state REINIT in TPS65090 charge state machine is more like IDLE0 state in charge_state.h. Rename it so that it's less confusing and easier to merge the two state machines in the future. Also move the state name definition to the header file. BUG=chrome-os-partner:18914 TEST=Boot Spring BRANCH=None Change-Id: I116438fedc46ff188dfb6a3964795715b5af4d1f Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49732 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Handle battery charged alarmstabilize-4068.0.BVic Yang2013-04-291-10/+14
| | | | | | | | | | | | | | | | When battery flags TERMINATE_CHARGE or OVER_CHARGED alarm, we should treat them as a signal of battery fully charged. BUG=chrome-os-partner:18914 TEST=On Spring: 1. Plug in adapter when battery if full, see green LED. 2. Plug in adapter when battery is not full, see yellow LED. BRANCH=spring Change-Id: Ica414a0e1667b8f30a0cc9a5d66dba1b119a59ba Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49456 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Don't enable charger interrupt if charger task is disabledRandall Spangler2013-04-291-0/+8
| | | | | | | | | | | | | | | This fixes pmu_init() failing on pit, where the charger task isn't enabled yet (and thus the charger interrupt is NULL - which can't be enabled). BUG=chrome-os-partner:18657 BRANCH=none TEST=build all platforms; on pit, check that pmu_init() no longer fails Change-Id: I191bbaeb4df10241e3508ccf7ef5ea83f42c5697 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49550 Reviewed-by: Simon Glass <sjg@chromium.org>
* Fix charging state descriptionsRandall Spangler2013-04-291-0/+2
| | | | | | | | | | | | Two states were added, but the descriptions weren't. This caused a crash. BUG=chrome-os-partner:18914 TEST=boot spring with no battery, wait a few secs; shouldn't crash BRANCH=spring Change-Id: I10f9280232259a1f467ea3b02f3b1b61cee57471 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49391
* Move PMU charger irq handler to charger moduleRandall Spangler2013-04-261-0/+10
| | | | | | | | | | | | | | | | No code changes; this is just moving the irq to the module which actually handles it. This makes it simpler to disable the charger task separately from the PMU module. BUG=chrome-os-partner:18343 BRANCH=none TEST=build pit, spring Change-Id: Ife44a17f69bf21aa000d162318a459cea6fdf661 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49334 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* Add new TPS65090 charge state REINIT and BAD_CONDVic Yang2013-04-261-20/+23
| | | | | | | | | | | | | | | | | | Currently INIT state can mean different things. This change introduces two new states to demultiplex INIT. Now, REINIT means charge state machine is deciding the next state. BAD_COND means it's waiting for acceptable charging condition. Note that the three states are doing the same thing so there is no functional change. BUG=chrome-os-partner:18914 TEST=none BRANCH=spring CQ-DEPEND=CL:49327 Change-Id: Ia783e76cf27e28103ef44fe7b8a43674dadccc54 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49326 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* PMIC_PWROK is active-high on pitRandall Spangler2013-04-161-7/+1
| | | | | | | | | | | | | | | | | Add a function which handles translation of PWROK from logical level to physical level. Also implement chipset_force_shutdown() in gaia_power.c, so PMU code doesn't need to know about PWROK physical level. BUG=chrome-os-partner:18738 BRANCH=none TEST=build all platforms; boot spring Change-Id: I360266ef89b6ead49a633cd57b7530f791b04c9e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/48251 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Clean up USB external power moduleRandall Spangler2013-04-101-19/+6
| | | | | | | | | | | | | | | | | | | | Make internal APIs static, and remove board_ prefix for clarity. Move TSU6721 calls from charger task to extpower_usb functions for better encapsulation. No functional changes, just moving code. Yes, this will make cherry-picking back from spring to TOT less convenient, but now the code is more readable and it will make maintaining the PMU code easier as we add boards. BUG=chrome-os-partner:18343 BRANCH=none TEST=build spring Change-Id: I52b37e57fc8519859996a110b0503277c6f0bbc8 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47657
* Rename charging task to CHARGER, charger_taskRandall Spangler2013-03-291-3/+3
| | | | | | | | | | | | | | | This makes the charging task name consistent across platform. No functional changes, just renaming. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all EC boards Change-Id: I348b31313f6604df2a05b474bdf6e0be7450c8c9 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/46891 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Use timeout instead of retry count for pre-chargingVic Yang2013-03-201-9/+12
| | | | | | | | | | | | | | | | Now that PMU task is waken not only by timer, we shouldn't depend on retry count anymore. This moves pre-charging timeout to actually use timestamp. BUG=none TEST=Remove battery and boot. See charge state goes to error after 15 seconds. BRANCH=spring Change-Id: Iff587bc824ffee93650184c14f1fc403d26ebc06 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/45957 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* spring: keep AP off when battery level is too lowVic Yang2013-03-201-0/+17
| | | | | | | | | | | | | | | | | | When battery level is too low, we want to keep the AP off even when a power on event is received. Current threshold is set to 1 mAh. Note that after this change, a board without a battery will need to wait for 15 seconds before it can boot up. BUG=chrome-os-partner:18318 TEST=Press power button and see power on event ignored. Charge battery to over AP off threshold and check we can power on the system. BRANCH=spring Change-Id: If32a1935a69be102778bde7ad8976eea0921f87e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/45825 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* spring: More stable battery LED controlstabilize-3881.0.BVic Yang2013-03-191-14/+11
| | | | | | | | | | | | | | | | | | | This includes: - Discharging with AC present now recognized as battery assist mode - Trigger LED update every second instead of from PMU task - Minor breathing effect optimization - Control LED power and color from the same task to prevent simultaneous access to LED driver BUG=chrome-os-partner:18244 TEST=Manual BRANCH=spring Change-Id: I9b34934f46cd4f04aaa7ca30cbe90316aec3e61e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/45632 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Rename board_get_ac() to extpower_is_present()Randall Spangler2013-03-191-8/+8
| | | | | | | | | | | | | | | Code cleanup; use the same function names to mean the same thing across boards. No functional changes; just renaming. BUG=none BRANCH=none TEST=build daisy,snow,spring Change-Id: Icbb4cfda5f5f9ba0cbbc07fee622e9c21af3f8cd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/45867 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: David James <davidjames@chromium.org>
* spring: minimize the window that loses TSU6721 interruptVic Yang2013-02-251-0/+4
| | | | | | | | | | | | | | | Since TSU6721 processing is integrated into PMU task, an interrupt closely following previous one may be dropped. We should check interrupt status before yeilding control. BUG=chrome-os-partner:14319, chrome-os-partner:14318 TEST=Boot on Spring. Check TSU6721 functionality. BRANCH=none Change-Id: I7ce1c70a214bb4afc9456eb206203cc6c3fe2f33 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/43862 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* spring: Handle dead battery and booting with low power chargerVic Yang2013-02-201-0/+3
| | | | | | | | | | | | | | | | This tweaks initial PWM configuration so that: - When battery is dead, more current is allowed to sustain the system. - When EC boots with a low power charger, input current is throttled so as not to kill the charger. BUG=chrome-os-partner:14319 TEST=Manual BRANCH=none Change-Id: Ib52894b07fecdd533aecab312f40afa0b6df5676 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/43600 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* spring: Control battery LEDVic Yang2013-02-051-12/+14
| | | | | | | | | | | | | | | | | This implements a basic battery LED policy: - Charged: green - Charging: yellow - Error: red - No charger: off BUG=chrome-os-partner:17561 TEST=Manual BRANCH=none Change-Id: I7fa8242efa4d0382d8ef0cafe80f01d44c390397 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/42607 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* spring: Sense attached device typeVic Yang2013-01-081-0/+17
| | | | | | | | | | | | | | This adds USB port control to charger task. For now, it only senses attached device type and log it to console. BUG=chrome-os-partner:14319 TEST=Attach/detach charger and see console output. BRANCH=none Change-Id: I1218d520c292d9d398c868122ae3876d3fc889bc Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/40078 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* tps65090: Throttle PMU interrupt instead of charger taskVic Yang2012-12-281-11/+30
| | | | | | | | | | | | | | | | | | | | This is a prepartory work for integrating USB port control into PMU task. Currently TPS65090 charger task is throttled to only waken by event once per 500 ms. This in a way makes it hard to integrate other functionality into this task. This CL moves the throttling mechanism to interrupt handler so as to provide better control of when to throttle the interrupt event. BUG=chrome-os-partner:14319 TEST=Build success and boot on spring. BRANCH=none Change-Id: I72e63180442b379a379e1a87c10ef62395434872 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/40189 Reviewed-by: Rong Chang <rongchang@chromium.org>
* Use SECOND and MSEC constantsRandall Spangler2012-10-291-8/+7
| | | | | | | | | | | | | | | | | | We'd defined them in a number of different files. This moves definitions to timer.h, and uses them everywhere we have large delays (since 10*SECOND is less typo-prone than 10000000). Also add msleep() and sleep() inline functions. No need for mdelay() or delay(), since any delays that long should use sleep funcs instead of spin-waiting. BUG=chrome-os-partner:15579 BRANCH=none TEST=boot system; taskinfo displays similar numbers to before Change-Id: I2a92a9f10f46b6b7b6571759b1f8ab4ecfbf8259 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/36726
* Hook functions no longer return valuesRandall Spangler2012-10-231-3/+2
| | | | | | | | | | | | | | | Previously, all hook functions returned EC_SUCCESS, which was meaningless because nothing ever looked at the return value. Changing the return value to void saves ~100 bytes of code size and an equal amount of source code size. BUG=none BRANCH=none TEST=code still builds; link still boots Change-Id: I2a636339894e5a804831244967a9c9d134df7d13 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/36372
* tpschrome: AC detection is board specific.Vincent Palatin2012-09-201-6/+6
| | | | | | | | | | | | | | | | | | | | | | the PMU VACG signal used to detect AC state is connected to a GPIO, so it's a board specific configuration. On top of that, Daisy variants have custom logic on that line which is not present on the next boards, so we need to update it before doing BSP for next-gen boards. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=chrome-os-partner:14313 TEST=make BOARD=snow && make BOARD=daisy on snow EC console, type "pmu" command with AC plugge and unplugged, see that the "ac gpio" line reflects the right value. BRANCH=none Change-Id: If1e19b89b2f2de45d8dddc8340931e56c5f7f0a5 Reviewed-on: https://gerrit.chromium.org/gerrit/33630 Reviewed-by: David Hendricks <dhendrix@chromium.org> Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
* snow: Clear state of charge calculation window on state changeRong Chang2012-09-101-4/+19
| | | | | | | | | | | | | | | | | The moving average window contains previous discharging state of charge values after state change. This change resets the index to make it calculate only new battery readings. Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:13846 TEST=none Change-Id: Ifc6c6208dea8edf262e7294972d7321501b709e2 Reviewed-on: https://gerrit.chromium.org/gerrit/32865 Commit-Ready: Rong Chang <rongchang@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* snow: Check state of charge using moving averageRong Chang2012-09-101-1/+38
| | | | | | | | | | | | | | | | Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:13846 TEST=manual Connect EC UART console and discharge snow device. The system should be turned off when average state of charge is lower than 2.5%. Change-Id: Iab9797d0aa6b159bedd8ce0d2fa72c6458cd14ac Reviewed-on: https://gerrit.chromium.org/gerrit/32693 Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org> Reviewed-by: Sameer Nanda <snanda@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org>
* snow: Stop discharging when temperature lower than 0CRong Chang2012-09-091-1/+1
| | | | | | | | | | | | | | | Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:13844 TEST=manual When run on battery, system will poweroff on battery temperature < 0C. Change-Id: Ib7f3a5f5149f038e83c67c7ca86f8eb22c4b1a7b Reviewed-on: https://gerrit.chromium.org/gerrit/32686 Reviewed-by: Vic Yang <victoryang@chromium.org> Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* snow: make pmu charge ranges inclusiveDavid Hendricks2012-09-081-2/+2
| | | | | | | | | | | | | | | | | Since we work with integral values for battery temperature, lower limits need to be inclusive when determining when to enable/disable charging. Signed-off-by: David Hendricks <dhendrix@chromium.org> BRANCH=snow BUG=none TEST=none (yet...) Change-Id: Icfc52066ca469b56ebc411bad864111848eab197 Reviewed-on: https://gerrit.chromium.org/gerrit/32652 Reviewed-by: Rong Chang <rongchang@chromium.org> Commit-Ready: David Hendricks <dhendrix@chromium.org> Tested-by: David Hendricks <dhendrix@chromium.org>
* snow: Change charging temperature rangeRong Chang2012-08-311-2/+2
| | | | | | | | | | | | | | | | | Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:13491 TEST=manual Charging can start in temperature range 5C ~ 45C Charging stops when temperature >= 60C System can be powered on when temperature < 100C Change-Id: Ic4d66f7d1877f819892328e298b7442a763ced7a Reviewed-on: https://gerrit.chromium.org/gerrit/32019 Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-by: Yung-Chieh Lo <yjlou@chromium.org>
* Blink charger LED on charging errorRong Chang2012-08-231-7/+67
| | | | | | | | | | | | | | | | | | | | Charger LED is controlled by TPSCHROME chip. And it blinks only when hardware detected charging error. On other charging error conditions not detected by TPSCHROME, we set the temperature thresholds to make charger generate the error blink. Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:12224 TEST=manual Plug AC power, heat up battery to 65 C. The charging LED should start blinking instead of green. Change-Id: Ib1c38a88c026471a52fbbb4f803e3b2aba93ab40 Reviewed-on: https://gerrit.chromium.org/gerrit/31139 Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org> Commit-Ready: Rong Chang <rongchang@chromium.org>
* daisy: Modify charging flow to comply charging specificationRong Chang2012-08-161-71/+148
| | | | | | | | | | | | | | | | | | | | | | | | | This change corrects charger interrupt event handling, charger enable gpio, battery full condition, EC deep sleep mode support when AC unplugged, and lid controlled power off. Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:12573,12574,12575 TEST=manual - ec console command 'gpioget': - SPI1_MISO should be 0 when AP off - CHARGER_EN should be 0 after AC unplugged - charging led should be off after AC unplugged - when battery remaining charge < 3%, system should be powered off without AC. - ec console command 'sleepmask 0', turn off AP: - deep sleep only when AC unplugged Change-Id: I0f63835dae67d90de7a8c8c6c3537ca9a16faed4 Reviewed-on: https://gerrit.chromium.org/gerrit/30316 Commit-Ready: Rong Chang <rongchang@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* Handle IRQ from TPS65090, pass AC status to APSimon Que2012-08-141-39/+7
| | | | | | | | | | | | | | | | | | | Changes made by this patch: 1. Create IRQ handler for the TPS65090 IRQ. IRQ wakes up charger task. 2. Charger task sets the AC_STATUS GPIO based on the AC status. 3. Initialize PMU at power-on. BRANCH=snow BUG=chrome-os-partner:11739 TEST=Power on the system, with servo v2 connected to EC console. Plug and unplug AC. The IRQ handler should be triggered. Change-Id: Ice23411c275111fdb56d2c47ba28c3c44dee4d71 Signed-off-by: Simon Que <sque@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/29914 Commit-Ready: Rong Chang <rongchang@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* Add TPSChrome comments on charging codeRong Chang2012-08-061-5/+38
| | | | | | | | | | | | | | | This change adds more comments on charging states and fixes battery temperature out of range log messages. Signed-off-by: Rong Chang <rongchang@chromium.org> BUG=chrome-os-partner:10900,12222 TEST=none Change-Id: Ie3240dc246ad7590078929e41575c67798373aca Reviewed-on: https://gerrit.chromium.org/gerrit/29253 Reviewed-by: Vic Yang <victoryang@chromium.org> Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* charger: Add delay in tasker task to avoid lockupSimon Glass2012-07-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The charger task relies on calc_next_state() performing a delay before returning. My reading of the code suggests that this doesn't happen always. For example: When pre-charging: if (battery_temperature(&batt_temp) == EC_SUCCESS) return ST_CHARGING; When discharging and capacity is low: /* Check remaining charge % */ if (battery_state_of_charge(&capacity) == 0 && capacity < 10) return notify_battery_low(); I would like to suggest that the code be refactored to more like: int next_checkms = 5000; /* next time to check battery */ while (1) { int action = ACTION_NONE; err = get_state(&state); if (!err) { action = calculate_action(&state); err = perform_action(action, &next_check_ms); } usleep(next_check_ms * 1000); } so that the delays are really clear, the state is all read at once, there is no reliance on earlier state, and we always delay even on error. In the meantime, this CL inserts a mandatory 5 second delay in the loop, which should prevent the charger task lockup. BUG=chrome-os-partner:11285 TEST=manual (please do this test before committing) 1. boot to kernel, see that battery can be seen 2. suspend and resume device 3. see that the charger loop does not cause an EC watchdog reset and AP power off/reset. There should be no watchdog warning message on the EC console. Change-Id: I141e374933c4dc0ec60bcdccf96443f57067c585 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/27353 Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Tested-by: Katie Roberts-Hoffman <katierh@chromium.org> Commit-Ready: Katie Roberts-Hoffman <katierh@chromium.org>
* Get AC state from GPIO instead of PMURong Chang2012-07-111-35/+36
| | | | | | | | | | | | | Signed-off-by: Rong Chang <rongchang@chromium.org> BUG=none TEST=manual plug and unplug the ac adapter, check charging state Change-Id: I933976d79bbd2da59449f0b9208656897713ebf2 Reviewed-on: https://gerrit.chromium.org/gerrit/27146 Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* Initialize PMU default settings using board configurationRong Chang2012-07-031-1/+5
| | | | | | | | | | | | | Signed-off-by: Rong Chang <rongchang@chromium.org> BUG=chrome-os-partner:11749 TEST=on snow with fully discharged dead battery plug ac power and check if it can charge to full Change-Id: Ie90255614bff879780edbd2bf1fc77bf8e2c04c8 Reviewed-on: https://gerrit.chromium.org/gerrit/26674 Reviewed-by: David Hendricks <dhendrix@chromium.org> Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
* Fix multiple charging issues on snowRong Chang2012-07-011-15/+29
| | | | | | | | | | | | | | | | | | | This change fixes mutiple snow charging issues. Including: - disable i2c host auto selection - i2c_read8 got wrong output value - pmu CHARGE_EN control workaround Signed-off-by: Rong Chang <rongchang@chromium.org> BUG=chrome-os-partner:11010 TEST=Only test on snow dvt with AP turned off plug/unplug ac adapter and check charging led check console command 'battery' Change-Id: I29d554b3daa4cfc538bd5bf5ba5233976d381861 Reviewed-on: https://gerrit.chromium.org/gerrit/26529 Tested-by: Rong Chang <rongchang@chromium.org> Commit-Ready: Rong Chang <rongchang@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* tpschrome: skip bad I2C readVincent Palatin2012-06-261-2/+1
| | | | | | | | | | | | | | | | | | | When an I2C read fails, we don't want to switch off the system or even print verbose warnings. Indeed, we are failing all I2C reads and writes to the charger and battery when they are on the same bus as the AP and the AP is ON. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=chrome-os-partner:9724 TEST=on Lucas DVT, run the system and see we have no spurious switch off or verbose EC traces. Change-Id: Ieb2f7836c70a0d2ad2c4a0f775aa190ce81a6932 Reviewed-on: https://gerrit.chromium.org/gerrit/26064 Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
* TPSChrome charging loopRong Chang2012-06-261-0/+282
This change contains a basic charging loop that follows Chromium battery charging flow. The temperature range constants, loop delay time will be move to battery pack later. Signed-off-by: Rong Chang <rongchang@chromium.org> BUG=chrome-os-partner:9724,9757,9759 TEST=manual, uart console Plug AC adapter: > pmu event: 0000000000001110 [batt] state discharging -> idle [batt] state idle -> charging > battery I: 0x04fd = 1277 mA(CHG)a Unplug AC adapter: > pmu event: 0000000000000110 [batt] state charging -> idle [batt] state idle -> discharging > battery I: 0xffcb = -53 mA(DISCHG) Change-Id: Ifed594d78c0ed08c5e4821a9c8581c1a87526729 Reviewed-on: https://gerrit.chromium.org/gerrit/25618 Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Ready: Vincent Palatin <vpalatin@chromium.org>