- Apr 22, 2024
-
-
Jonathon Hall authored
Refactor battery and charging for robustness and to support future products See merge request !27
-
- Apr 10, 2024
-
-
Jonathon Hall authored
If AC is plugged in just as the EC is shutting down, the system would remain on but with SMC_SHUTDOWN_N cleared (the EC is no longer keeping the power latch on). Unplugging AC later would cause the system to shut off suddenly. This is rare but reproducible. Shutting down from PureBoot while on battery, the switching on AC (barrel jack adapter plugged into a switch) can reproduce this issue roughly 1/10 tries when using a stopwatch to try to get the proper timing. To solve the race, if we attempt to shut down the system, but it does not actually shut down, raise SMC_SHUTDOWN_N again. This also eliminates I2C console device freezing due to the EC dropping out in the middle of an I2C transaction. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
- Apr 04, 2024
-
-
Jonathon Hall authored
Dump charger state when this debug command is invoked. Useful to see whether the EC thinks the charger is powered in particular. Also note why the audio frequency limit isn't enabled when charge is inhibited. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Support IDPM on a per-board basis, enable it by default. Disable it for Librem 14 to keep existing behavior. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Support board designs that only power the BQ24715 charger by AC, so it is not powered when on battery. Don't try to program the BQ24715 when it is not powered, but remember parameters given to program when it powers on. Keep track of its power state based on the AC state. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Split up the work done in the 1s event to block the keyboard for less time. It's taking almost 40 ms, mostly battery and charge. Separately they are each under the limit though, so stagger them in two phases. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Manually construct this trace so it adds less time to the 1s event if it does run long. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
uint16_decimal_fast() and int16_decimal_fast() use BCD lookup tables to render decimal integers faster than __uitoa()/__itoa(). Unfortunately, the DA A instruction is slightly broken on this CPU, which adds ~120 cycles per number to work around it. This method is still much faster than __uitoa()/__itoa(), by about 0.5 ms per number, which is very significant compared to the 30 ms limit for 1s events. Hexadecimal output uses printf_fast() which is faster than any alternative tested and is not affected by the DA A bug. Provide a debug command to test the implementation compared to printf(). Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Reduce time spent on periodic 1-second traces by constructing the trace manually, instead of using a printf() format. This saves 10 ms in the 1-second event (even if I2C console is not enabled), which is a significant amount of the allowed 1-second event time. printf_fast() was considered but rejected, it is affected by the DA A but on this CPU, which decimal output of values ~2000-9000 (prints 1000-8000, specifically tested 2038, 3038, etc., probably breaks other values too). Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Add debug commands to SMFI, for testing important resiliency functionality in the EC that can't be tested otherwise. Add ectool support to invoke these commands. Add a debug command to freeze the EC, testing the watchdog reset. Add debug commands to the bq24715 battery charger implementation to test the parameter validation and resiliency. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Refactor the bq24715 charger implementation. Reduce coupling to SBS logic and Librem 14 board logic - reduce global variables, consolidate scattered initialization. Improve robustness and tracing. Validate more parameters to ensure that we don't try to enable charge with configuration that doesn't make sense. Add field events for important failure modes. Facilitate future improvements to support BQ24715 only powered by AC, not from battery (will need to avoid trying to program the BQ24715 when on battery, and program it again when AC is applied). Add periodic validation of BQ24715 registers. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Use symbolic constants for the BQ24715 SMBus register addresses. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Measure the elapsed time during the 1s event and each function invoked. Warn and trace the function times if the event exceeds the defined threshold. Use 16-bit time to tracek the 1-second event, 32 bits aren't needed. Fix the event to run only when 1 second has elapsed, don't run an extra time if the time wraps around. 'time - last_time >= 1000' is correct even if time wraps around for unsigned integers. 16-bit time wraps about once per minute (versus once per 49.7 days for 32-bit time) so this can be tested now. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Move this from DEBUG level to TRACE level (excluded by default). This reduces the 1s event time in production builds (no I2C console) from 46 ms to 39 ms. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
The data is in code, use __code pointers instead of generic. (Necessary for printf_fast() although we're not switching to that just yet.) Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
peci_event() is a 1s event, not a fast event, name it peci_1s_event(). Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
battery_event() and battery_charger_event() are 1-second events, not fast events. Name them *_1s_event(). Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Trace the battery serial number with the battery information. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Use symbolic constants to represent battery registers rather than bare offsets. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Configure the capacity and charger modes to the desired values and check the result. Trace changes to the battery mode. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Represent battery mode bits with constants. Trace the full mode, and check for all defined bits as well as any reserved bits. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
A few limits were written as 0x0000 / 0x7fff, write these as 0 / INT_MAX instead, which is a little clearer and more consistent with the other limits. All of these are actually unsigned, but they represent physical quantities that wouldn't make sense above 32767 (and would be misinterpreted by the current implementation with signed int16_t). Excluding these unreasonably high values makes sense. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Several values that are actually unsigned (or bit flags) in the SBS spec were only accepting the range [-1, 32767], values below -1 would have been rejected. * ManufactureDate (0x16): High bit would be set if the battery thinks it is manufactured in 2044 or later - while this shouldn't happen, it doesn't give us any benefit to exclude this since we still accept the other battery parameters. * SerialNumber (0x1c): Arbitrary serial number, high bit could be set. * BatteryStatus (x16): Highest bit is OVER_CHARGED_ALARM. We never check this bit yet, but there is no sense excluding a status that has it set. battery_mode is also a bit flag field, but requiring the highest bit to be 0 actually has side effects we need, so this remains for now with documentation. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Battery temperature is reported in 1/10 kelvin, not 1/10 degree Celsius. Convert the temperature for tracing. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Move this logic from Librem 14's board_battery_init() to sbs_battery_probe(). Sense battery_present from the sense GPIO, and probe the battery only if sensed. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Move board_battery_print_batinfo() to battery.h/c, as battery_print_batinfo(), this isn't specific to any type of battery. Move i2c_get_safe() to sbs_battery.c, used for SBS logic. Move probe_gas_gauge() and update_gas_gauge() to sbs_battery.h/.c as sbs_battery_probe() and sbs_battery_update(). Take the I2C interface as a parameter for SBS functions. Handle the BATTERY_INITIALIZED flag internally in SBS logic - set/clear it based on probe, check it before trying to update. Initialize updating parameters also during probe (call sbs_battery_update() internally), print battery status, print initialized message. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Don't modify the output value until the function succeeds - don't put intermediate values there that might be out of range, etc. Nearly all of the callers only use the success/failure result to avoid storing an invalid value. Do that in i2c_get_safe itself. Fix the logic setting a default charge max current if the battery didn't report a valid value. It tested tval (the temporary), but this test nearly always passes - tval is nearly always >= 0, and the reasons it could be negative don't make sense for this test. It also checked battery_charge_max_current <= 100, but it can never be 1-100 due to the allowed range 1000-5000. So an equivalent test is to see if the max current is still 0, meaning the read failed for any reason. tval could only be negative if the battery actually returned a set high bit from the current itself (or from any prior parameter and returned partial reads for all later parameters, since partial reads weren't checked). The max current is actually unsigned, so it doesn't make sense to apply this logic for a max current of 32.767 A but not for 32.768 A. The logic may have meant to check the status returned by i2c_get_safe, but it wasn't doing that. Improve trace if current/voltage are both invalid, and add traces if a default maximum current is used. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Now that i2c_get_safe checks the read length internally, it only returns 2 or -1. Return boolean instead. It also traces error values internally using the actual I2C status. Remove the caller error traces, which only traced status -1 anyway. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Remove the len parameter, this is only used with 16-bit values so the length is always 2. Check the actual length read. Previously, if only 1 byte had been read, we'd continue with garbage in the upper byte of the result (hopefully the range check would catch it, but it should check). Trace each type of failure specifically. Include the index in the giving up trace so we can tell which parameter failed. Trace giving up at error level. Fix indentation. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
This is only used to trace the system current when on AC power, and this measurement isn't reliable enough to actually do anything with it. Remove the unused return value and rename the method. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Librem 14 devices all shipped with SBS batteries. The EEPROM non-smart battery was only used in development. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Move PL4 values and logic for DC/AC/DC_LOW to Librem 14. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Move board startup trace above board_init(), the console must be up at this point (board_console_init() inits early if needed). If the board traces any initial state in board_init(), it should be after the startup trace. Add an extra initial newline in the startup trace so there is always a gap, even if a prior trace was interrupted without completing a line. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Rename last_current to charger_current - it's closely related to charger_enabled and is not always the last current setting we sent to the BQ24715. Document its behavior. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
- Mar 26, 2024
-
-
Jonathon Hall authored
Fix the executable name to purism_ectool. Only invoke it if some parameters were given, just build otherwise (facilitates building off-host). Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
Use local 'current' instead of global 'battery_charge_current' when tracing a current change. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
-
Jonathon Hall authored
Indicate charge enable/disable failure and failure to update charge current. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-
Jonathon Hall authored
The minimum system voltages are in mV, but writing in hexadecimal makes the value less obvious. The values must be specified in increments of 256 mV, which is now noted in a comment. 5.632 V, the value used for 2S2P, may be a tiny bit too low - there is a 3% regulation tolerance, so it could dip as low as 5.463 V. That is below the minimum voltage for +V5A. However, raising the value had no effect when tested on a system experiencing freezes, so the value is unchanged for now. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
-