Commit Graph

48 Commits

Author SHA1 Message Date
a24c65a6ea msm5.15: Import ayn changes from ayn_8550.xz (01/18/2026)
Signed-off-by: AnierinB <anierin@evolution-x.org>
2026-01-19 09:53:56 +00:00
Subbaraman Narayanamurthy
945240174f power: supply: qti_battery_charger: Add battery cooling device
Add a thermal cooling device for battery power supply so that
thermal SW can use it to get or set charge control limit through
which battery charging current can be voted.

Please note that this can be helpful only if power supply framework
removes psy_register_cooler() as done with the following upstream

'commit c85c191694cb ("power: supply: remove faulty cooling logic")'.

Otherwise, two thermal cooling devices would be registered for
battery power supply and one of them would fail.

Change-Id: I0cc1bce5432703831740ed47c8db40b1e4b36c38
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
Signed-off-by: Kamal Wadhwa <quic_kamalw@quicinc.com>
2023-08-28 17:44:08 +05:30
Jishnu Prakash
4950b4a67c power: supply: qti_battery_charger: Update error handling
At present, if HLOS tries to read or write some power supply property which
is not supported on the remote processor side, there is a wait time for the
acknowledgment, of one second, before timeout. This is unnecessary as the
remote processor sends the acknowledgment for unsupported properties
immediately with an error indicated in return code value.

Update the error handling to ensure that if any unsupported property is
read or written, the calling API exits immediately with error, without
waiting for the one second timeout to expire.

Change-Id: Ic736e9747d797ef752ef123982033145fa5a5012
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
2023-06-13 17:05:23 +05:30
Anjelique Melendez
b417ef2911 power: supply: qti_battery_charger: Update IDT FW version offset
IDT FW version offset has been changed in IDT9415 and above. Update the
offset value accordingly.

Change-Id: Ic8b8c0d3af4c6587e85f1f87bcdf9ac2ea806eae
Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
2023-03-24 11:26:44 -07:00
Subbaraman Narayanamurthy
7f477c6176 power: supply: qti_battery_charger: Handle error properly when probe fails
Currently, panel_event_notifier_unregister() is called only when
the driver is removed. However, during driver probe, there can be
other error cases like power supply registration failure.

Stack trace:

9.045419:   BATTERY_CHG: battery_chg_init_psy: Failed to register battery power supply, rc=-11
9.056065:   qti_battery_charger: probe of soc:qcom,pmic_glink:qcom,battery_charger failed with error -11
...
10.380031:   ------------[ cut here ]------------
10.397227:   DEBUG_LOCKS_WARN_ON(lock->magic != lock)
10.407294:   WARNING: CPU: 7 PID: 988 at kernel/locking/mutex.c:582 __mutex_lock+0x2c0/0xd1c
...
10.548169:   Call trace:
10.548169:    __mutex_lock+0x2c0/0xd1c
10.548172:    __mutex_lock_slowpath+0x1c/0x30
10.548174:    mutex_lock+0x40/0x78
10.548176:    battery_chg_write+0x4c/0xf4 [qti_battery_charger]
10.548185:    panel_event_notifier_callback+0xe8/0x1c4 [qti_battery_charger]
10.548191:    panel_event_notification_trigger+0xec/0x178 [panel_event_notifier]

Fix this by calling panel_event_notifier_unregister() in the error
return path so that panel notifier events are not handled.

In addition, add a semaphore to update "initialized" flag as well
as "state" variable so that they can be updated exclusively when
the driver probe fails and other worker threads trying to access
bcdev->client thereby preventing invalid access.

Change-Id: I0caac3da5a9f94907d86cae84483c7907653798a
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2023-03-13 15:49:19 +05:30
Subbaraman Narayanamurthy
ccb856163b power: supply: qti_battery_charger: initialize psy pointers to NULL upon failure
For some reason, if the power supply registration fails after
registering with pmic_glink driver and a notification is received
from the charger FW at the same time, power_supply_changed() can
be called on a power supply device pointer that is invalid.

[6.993242][  T698] BATTERY_CHG: battery_chg_init_psy: Failed to register battery power supply, rc=-11
[7.002865][  T138] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000409
...
[7.618797][  T138] Call trace:
[7.622022][  T138]  do_raw_spin_lock+0x2c/0x140
[7.626757][  T138]  _raw_spin_lock_irqsave+0x40/0x84
[7.631943][  T138]  power_supply_changed+0x30/0xa8
[7.636952][  T138]  battery_chg_callback+0x328/0x54c [qti_battery_charger]
[7.644105][  T138]  pmic_glink_rx_work+0x114/0x1d0 [pmic_glink]

Fix this by setting psy pointers to NULL again when
devm_power_supply_register() fails.

Change-Id: Iceb707103c694aa31e24c891502400abc801db5e
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2023-03-01 10:32:46 -08:00
Jishnu Prakash
a466d844c3 power: supply: qti_battery_charger: Allow setting ICL for CDP adapters
Allow battery charger clients to vote for setting ICL for CDP adapters
for any value instead of 0 and 1.5A alone. This prevents an issue
where USB may vote for 0A to suspend charging and some value below 1.5A
to unsuspend charging with CDP connected. With this change, all such
requests are sent directly to charger firmware, which will change ICL
as required.

Change-Id: If9e5d70a6637f2f0fabf34fba5cc33490e62748d
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
2023-01-09 00:20:40 -08:00
Jishnu Prakash
5e13a5fcba power: supply: qti_battery_charger: Add ICL voting support for CDP
Add support to set input current limit for CDP adapters, to
either suspend or resume charging through CDP.

Change-Id: I7b1e5c2ad3135bdc80ca4988b7680c61d3ab9566
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
2023-01-02 01:16:44 -08:00
Subbaraman Narayanamurthy
4ff41daac6 power: supply: qti_battery_charger: Fix NULL pointer dereference
With psy initialized in battery_chg_init_psy(), read_property_id()
when called from battery_chg_parse_dt() can try accessing
psy->desc->name when dynamic debugging is enabled. Fix it.

Change-Id: I88114ea9779d5113524b8b15659bf8bafe6364ed
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2022-08-25 12:01:36 -07:00
Subbaraman Narayanamurthy
12edde60e4 power: supply: qti_battery_charger: Fix unintended invocation of state_cb()
Currently, pmic_glink_register_client() is getting called even
before battery_chg_register_panel_notifier() is called. However,
if of_drm_find_panel() doesn't return an active panel, then
battery_chg_register_panel_notifier() returns -EPROBE_DEFER which
would end up in calling pmic_glink_unregister_client() and this
would happen forever. Though this error return path is handled
properly, when SSR/PDR event is triggered, pmic_glink driver can
invoke state_cb() for all of its clients if they've registered.

With the following sequence happening occasionally, it can end up
accessing an invalid bcdev pointer use-after-free.

- Battery charger driver calling pmic_glink_register_client()
- PDR event
- pmic_glink driver invoking state_cb() for all clients
- Battery charger driver schedules subsys_work
- Battery charger driver calling pmic_glink_unregister_client()
  because battery_chg_register_panel_notifier() returns
  -EPROBE_DEFER
- Battery charger driver's subsys work runs with an invalid bcdev
  pointer

Fix this by moving battery_chg_register_panel_notifier() before
calling pmic_glink_register_client(). With this, battery charger
driver won't register with pmic_glink driver if it can't get an
active panel from using of_drm_find_panel() on the boards where
"qcom,display-panels" is specified. Also, update bcdev->state to
PMIC_GLINK_STATE_UP only after pmic_glink_register_client()
succeeds so that battery_chg_write() won't go through. In the
driver probe error return path, cancel subsys_up_work to ensure
that it's not invoked after pmic_glink_register_client() succeeds
but an error path follows that.

CRs-Fixed: 3274512
Fixes: 94f2a17469 ("power: supply: qti_battery_charger: Disable notifications while in sleep")
Change-Id: I12b9f9137602b760a751ad0119fce1cd10ba8fbd
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2022-08-25 10:30:14 -07:00
Subbaraman Narayanamurthy
5c42a255bc power: supply: qti_battery_charger: Handle state only if driver is initialized
There is a chance that battery_chg_state_cb() can get invoked before the
battery charger driver finishes initialization. Handle it.

Change-Id: If959b00d3055e0194184b5c3992b0c0906d29213
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2022-08-18 15:56:18 -07:00
Subbaraman Narayanamurthy
1ce3c314b8 power: supply: qti_battery_charger: add an error log in wireless_fw_update()
If wireless FW name is not specified for battery_charger device,
then it's better to print an error log and bail out without
requesting a firmware.

Change-Id: Iaf384bee625b1ec69b87de6b5d309569b4b10a17
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2022-03-30 16:31:11 -07:00
Subbaraman Narayanamurthy
0a64f58c64 power: supply: qti_battery_charger: add more properties for wireless psy
Add more power supply properties related to wireless charging.

- /sys/class/power_supply/wireless/input_current_limit
- /sys/class/power_supply/wireless/temp
- /sys/class/qcom-battery/wireless_type

This is useful for testing.

Change-Id: I5fe57c0eafbd43fe19863c9b38a1292af4ba5360
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2022-03-21 13:07:55 -07:00
Fenglin Wu
7084681be3 power: supply: qti_battery_charger: handle hBoost VMAX_CLAMP notification
The haptics boost can be used to supply either USB or wireless sourcing
mode by the charger firmware, and it needs to notify haptics driver to
clamp the haptics Vmax settings accordingly. Handle the VMAX_CLAMP
notification from charger firmware and notify the haptics driver through
a notifier call.

Change-Id: If06fa8631d9f4dc264b729ccb9fbc7c154ad3f27
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
2022-03-17 18:59:57 +08:00
Anjelique Melendez
94f2a17469 power: supply: qti_battery_charger: Disable notifications while in sleep
Currently during fast charging, charger FW on ADSP sends battery power
supply notifications to HLOS even while in sleep. These notifications
cause HLOS to come out of sleep to process the request. This is not needed
as display is OFF and any change in battery status will not be updated on
screen.

Add panel event notifiers to receive notifications from display FW so that
power supply notifications from the charger FW can be disabled when the
panel is turned off and re-enabled when the panel is on.

Change-Id: Ibf9e688f1571fd40ca18a1155fce95efd039690b
Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
2022-01-18 15:50:57 -08:00
Subbaraman Narayanamurthy
fd7f6d2add power: supply: qti_battery_charger: Fix debugfs_create_bool() usage
debugfs_create_bool() return type got changed. Fix it.

Change-Id: Ia83ed4b50a42b22718bdf5bc6ba0c2b25f0a5631
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
2021-12-03 19:39:48 -08:00
Anjelique Melendez
6ef90c46ec power: supply: qti_battery_charger: Add support for thermal-mitigation-step
Currently, thermal mitigation is supported with "qcom,thermal-mitigation"
property where different fast charging current(FCC) levels can be
specified as an array. This would be applied when thermal SW votes for a
mitigation level through CHARGE_CONTROL_LIMIT property.

For some boards, the number of levels can be simply obtained by specifying
a fixed FCC tep as the maximum FCC supported is already obtained from the
charger FW. Add Support for this via "qcom,thermal-mitigation-step"
property. With this, we don't have to override "qcom,thermal-mitigation"
property for battery type variation (1S vs 2S).

Change-Id: I16af90545924d8880a6c49d02935b4d21a86c417
Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
2021-10-26 12:57:25 -07:00
Subbaraman Narayanamurthy
b875d233af power: supply: qti_battery_charger: change battery power supply registration
Userspace health HAL implementation waits for capacity property from
the battery power supply to be available before starting health HAL
service. This is needed to ensure the battery power supply device
is found by health HAL consistently. However, if the registration
of other power supply devices like USB and Wireless takes time and
health HAL initializes before that, Android battery monitor would
not be reading any properties from these power supply devices.

Fix this by registering the battery power supply after registering
USB and Wireless power supply. This would ensure that by the time
health HAL initializes, USB and Wireless power supply devices can
be available.

CRs-Fixed: 2998433
Change-Id: I3b71c86eaa774bdfcef3686109d7a25ac52be16c
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-10-04 18:23:49 -07:00
Subbaraman Narayanamurthy
ec7e26d731 power: supply: qti_battery_charger: add support for emergency shutdown
Currently, when SOC reaches 0 and device is not charging, we
depend on the userspace (e.g. Android battery manager service)
to initiate a shutdown. Sometimes, this takes more time than
expected (> 20 seconds). When the device is discharging with a
high system load, this may cause device to brown out as the
battery voltage can go below the safe operating level. Add
support to initiate an emergency shutdown when the following
conditions are met.

- Battery SOC is 0
- Battery is not charging
- Battery voltage is lower than a specified level

Add "qcom,shutdown-voltage" to support this.

Change-Id: I542ae08037c4e9db23d338b8de2eeb32c809a0a6
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
4e005dd910 power: supply: qti_battery_charger: Increase wireless FW prepare time
Currently, prepare time for wireless FW update is set to 300 ms.
This was sufficient enough for previous targets which had used
wireless receiver IDT9412. For IDT9415, a prepare time > 300 ms
is required to make sure pre-regulator is disabled and WLS_IN is
plugged out. Hence, increase this to 1 second so that it can be
well accommodated.

Change-Id: Ibff4ec606257e04fcf0405c3f145585d30a38ed7
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
bad95dae13 power: supply: qti_battery_charger: Handle BC_SHIP_MODE_REQ_SET response
During shutdown when configuring ship mode based on user request,
battery charger driver sends BC_SHIP_MODE_REQ_SET message to the
charger firmware to do configuration before the shutdown. However
the response from the charger firmware is not handled and hence a
timeout is observed in the logs. Fix it.

Fixes: 1df95fc50926 ("power: supply: qti_battery_charger: Enable Ship mode shutdown")
Change-Id: I9149a256e4af40c3dcf2f0019f27e711a97f4493
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
831c9ed352 power: qti_battery_charger: support configuring wireless FW update time
Currently, during wireless FW update process, qti_battery_charger
driver waits for FW update status for a period of 1 second after
sending all of the FW chunks. This wireless FW update time depends
on the wireless transceiver being used. E.g. IDT9412 needed only
1 second but IDT9415 requires up to 2 seconds as computing and
validating the CRC seems to be consuming more time. To support
such variance in wireless FW update time, add a parameter which
can be configured at runtime.

This can be configured (in ms) as below.

  echo 2000 > /sys/class/qcom-battery/wireless_fw_update_time_ms

Change-Id: Ifa8104544138254e1029ab1fcaa9f40e61cc0961
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
38bdfa2006 power: supply: qti_battery_charger: Handle BC_SHUTDOWN_NOTIFY response
During shutdown, battery charger driver sends BC_SHUTDOWN_NOTIFY
message to the charger firmware to do configuration before the
shutdown. However, the response from the charger firmware is not
handled and hence a timeout is observed in the logs. Fix it.

Fixes: eab52908558f ("power: qti_battery_charger: Add a shutdown notification")
Change-Id: I56f06b60bea0f1059f10684c32e9a7cf7acbdc9e
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Kiran Gunda
2ca18c3943 power: supply: qti_battery_charger: Add TIME_TO_FULL_NOW property
Report TIME_TO_FULL_NOW battery power-supply class property required
by userspace.

Change-Id: Idc5ea4718bd9537e46191d254fa2e3e252141041
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
2021-09-24 12:46:56 -07:00
Anirudh Ghayal
4ec2719a32 power: qti_battery_charger: Add a shutdown notification
Notify charger-firmware of a shutdown event.

Change-Id: I291c9230bb7fb5df414db8f80bfb17a50c8fc7c1
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
2021-09-24 12:46:56 -07:00
Fenglin Wu
3e41faf522 power: supply: qti_battery_charger: run usb_type_work during probe
Currently, updating USB type only depends on USB status change
notification from the charger firmware. During a reboot with USB
connected, there is a chance that a USB power supply notification would
have been sent by the charger firmware little earlier even before the
battery charger driver was ready to handle it. Hence it would've got
missed and USB type is not updated properly. Fix it by scheduling
usb_type_work once the driver probes.

Change-Id: I0ae482e90a76a0b2128fcc45561adb77a2ca017c
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
2021-09-24 12:46:56 -07:00
Kiran Gunda
0d54522549 power: supply: qti_battery_charger: Handle probe failure gracefully
Due to a race condition between the probe and glink message
callback, it is observed that the glink messages/notifications
can be handled even after the probe failure which leads to
an invalid memory access. Fix it by introducing "initialized"
flag. While at it, add few error logs to identify the exact
message failures.

Change-Id: I18e61dea734efde6a11ee072793da8eead269b12
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
4fd5a8ede0 power: supply: qti_battery_charger: add support for wireless FW CRC check
Currently, wireless FW update is done by the user once a FW file
is pushed to one of the firmware folders and with user writing
to "wireless_fw_update" or "wireless_fw_force_update" under
/sys/class/qcom-battery.

As per the recent requirements to add CRC check during wireless
firmware update process, add "wireless_fw_crc" property through
which the user can pass CRC before doing FW update. Since this
adds extra time for validating the CRC, increase the wait time
for FW update completion from 500 ms to 1 second. Also, print an
error log if FW update is not done.

E.g.

echo 0x1234 > /sys/class/qcom-battery/wireless_fw_crc
echo 1 > /sys/class/qcom-battery/wireless_fw_update

Now with adding this support, if CRC is not set, FW update would
fail as the charger firmware validates the CRC passed.

Change-Id: Id66cd84984b6206bf866ee1f18f7b32d9090c5dd
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
612eef264a power: supply: qti_battery_charger: Configure ICL and FCC post SSR/PDR
When the remote subsystem restarts (SSR) or the charger firmware
restarts (PDR), resend the ICL/FCC votes from clients like USB
driver, thermal SW once the subsystem is up.

Change-Id: Ia0da3747fdb98c7873b65c948b76f6b6a286e31c
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
0428c2d8a5 power: supply: qti_battery_charger: Fix FCC configuration
With adding support to restricted charging through properties
restricted_chg and restricted_cur under /sys/class/qcom-battery,
configuring fast charging current (FCC) via "charge_control"
property in battery power supply is not working as expected.
Especially, when the restricted charging is disabled, FCC
configured (i.e. after setting it in ascending order first and
in descending order) is based on the previous request instead of
the current request. Fix it.

Fixes: 9c3f7e472cb6 ("power: supply: qti_battery_charger: add some more properties")
Change-Id: I6c591a0e1e914b37764350fb7389824410800868
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
54bf5d5cef power: supply: qti_battery_charger: Change wireless power supply type
Now that the power supply framework has POWER_SUPPLY_TYPE_WIRELESS
change the wireless power supply type from MAINS to WIRELESS. This
would help android healthd to show "chg=w" rather than "chg=a" in
logs when a wireless charger is connected.

Change-Id: I871779aa806f775e2cdf1e0994593fc991fe77f9
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
5cf5e25e1d power: supply: qti_battery_charger: allow setting ICL for USB_PD charger
USB driver can request for an ICL override (e.g. 2 mA when the
host enters suspend) when the device is connected to the host to
a SDP or a port that supports USB_PD. With USB_PD, if PDO 1 has
bit 28 set to 1, it advertises that suspend is supported. Hence
allow setting ICL for USB_PD charger as well.

Change-Id: I5a9eea05c58a7c8140c2910be97788f7f63efb05
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
e957b7e87c power: supply: qti_battery_charger: update USB power supply type runtime
Currently, USB power supply type is set to POWER_SUPPLY_TYPE_USB
in power supply descriptor. power_supply_show_property() would
show POWER_SUPPLY_PROP_TYPE based on psy->desc->type. Userspace
process like healthd would read POWER_SUPPLY_PROP_TYPE to print
the adapter type in logs (e.g. "chg=u" for SDP, "chg=a" for DCP).
Hence update usb_psy_desc type runtime to show the USB power
supply type accordingly. This is useful for testing.

Change-Id: Icd88098f97beba053105d826614b4182f3716144
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
d63e00fcdc power: supply: qti_battery_charger: add some more properties
To support userspace application and testing, add some more
properties under USB power supply and qcom-battery class.

To show USB connector temperature, following property is added.

- /sys/class/power_supply/usb/temp

To support restricted charging similar to legacy targets,
following parameters are added.

- /sys/class/qcom-battery/restrict_cur
- /sys/class/qcom-battery/restrict_chg

To show whether the Type-C sink/source connected is compliant,
following parameter is added.

- /sys/class/qcom-battery/usb_typec_compliant

To show the custom USB_TYPE for Quick charge adapters like HVDCP,
HVDCP3 etc., following parameter is added.

- /sys/class/qcom-battery/usb_real_type.

Change-Id: Ia8dfba41c6ed3056dda588a1955a60ef19568112
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
49fd66424d power: supply: qti_battery_charger: Keep device awake during notification
With charger mode enabled in android, device boots into charger
mode when it is powered on with USB insertion. In this mode,
health HAL and charger service handles the power supply uevents
sent from power supply framework to take certain actions. For
example, when the USB or travel adapter (TA) is removed, device
would shut down in 10 seconds.

With a TA connected, device can enter suspend whenever possible
during charging. When the TA is removed after the device has
entered suspend, device comes out of suspend upon the notification
received from charger firmware (CHGFW) over PMIC Glink. Battery
charger driver handles this and calls power_supply_changed on one
of the power supply devices. However, before this uevent is
received and handled by charger service in the userspace, device
can enter suspend immediately.

In a low power discharging state, device stays in this state for
minutes until it gets another notification from CHGFW for battery
power supply, a periodic event which makes charger service to
initiate a shutdown. This conflicts with the user expectation
where the device has to shutdown in 10 seconds upon TA removal.

Workaround this problem by keeping the device awake for at least
50 ms when a notification is received from CHGFW. This way,
userspace process like charger could get a chance to receive and
handle the power supply uevents.

Change-Id: I9ea78eb6565988ffac0e6c5eee1ccae8dc7e3e3a
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Guru Das Srinagesh
94ada0c079 power: supply: qti_battery_charger: Enable Ship mode shutdown
This feature is to enable the disconnection of the battery from the
device as the final step in the assembly of a phone on the factory floor
to prevent battery rundown while in transit to the hands of the final
consumer.

Usage:
  # echo 1 > /sys/class/qcom-battery/ship_mode_en
  Following this, either manually shut down using power key, or:
  # reboot -p

Change-Id: Ifef053c6ebb3b86c10f9dbe3c9c47d7c3548d95b
Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
0dfd62cc77 power: supply: qti_battery_charger: support wireless firmware update
Add support for wireless charger firmware update in battery charger
driver through "wireless_fw_update" and "wireless_fw_force_update"
properties under "/sys/class/qcom-battery". Support firmware update
for wireless charger (IDT9412) for which firmware is split into
multiple chunks (128 bytes each) and sent over PMIC Glink. Charger
firmware running on the remote subsystem does the FW update by
communicating with IDT9412.

Wireless charger firmware name should be specified via a device tree
property "qcom,wireless-fw-name".

To update wireless firmware, user has to push the FW binary to a
firmware partition (e.g. /vendor/firmware) and then do one of the
following.

Normal update for which FW version check is made:

 # echo 1 > /sys/class/qcom-battery/wireless_fw_update

Forced update for which FW version check is skipped:

 # echo 1 > /sys/class/qcom-battery/wireless_fw_force_update

To read back FW version:

 # cat /sys/class/qcom-battery/wireless_fw_version

Change-Id: Id565e7d5a73041d6e0340edc66eb8b1615396435
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
bd131a5bcd power: qti_battery_charger: call power_supply_changed() if fake_soc is set
There are clients who are waiting for power supply change events
when fake soc is set during testing. Call power_supply_changed()
to support them.

Change-Id: I6a1f4e7daa136b3783f5ed35f37abafad7447378
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Guru Das Srinagesh
20b80f3419 power: qti_battery_charger: Block PMIC GLINK Tx for debug battery
The remote subsystem does not transmit PMIC GLINK notifications
triggered by charging parameter changes when a debug battery (one whose
battery ID is set to 7.5 Kohms) is detected. This allows it to enter low
power mode provided no queries for individual power supply (PSY)
properties are made of it.

Power consumption monitoring tests require it to enter low power mode
and stay there, which can happen only if it is not disturbed by having
to respond to queries made by HLOS for PSY properties. This change
enables the user to block all PMIC GLINK Tx messages from this driver to
remote subsystem by setting the boolean debugfs property "block_tx".

Once this is done, all subsequent reads of PSY properties will return
not the instantaneous values of those quantities, but the last (stale)
values obtained during the last read that was made prior to Tx being
blocked. To return to normal behaviour and obtain instantaneous values
from the remote subsystem, the debugfs property must be cleared.

Change-Id: Ie9b6ec78dcb8ec00102e9d7d23e238445045206f
Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
b547a4fc20 power: supply: qti-battery-charger: Fix buffer handling in handle_message()
Currently, prop_id (u32) and val (u32) are obtained for all messages
in handle_message(). However, the response for notification request
doesn't have the same payload but only an u32 return code. Because
of this, an unintentional memory read for u32 is being made even
though it is not used.

Fix this by getting prop_id and val only for response messages that
are intended to get battery/USB/wireless power supply properties.

CRs-Fixed: 2655408
Change-Id: I4d17d965f911eb6a4357e29117191f78830e9e5c
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
5f24c5a1d7 power: supply: qti-battery-charger: Handle incorrect thermal levels
Currently, when "qcom,thermal-levels" is specified and the
values are not in descending order, an error is returned which
fails the driver probe thereby causing battery/USB power supply
not available. Same problem can happen when charger firmware
returns a lower value for BATT_CHG_CTRL_LIM_MAX than the maximum
value specified under "qcom,thermal-levels" property. Without a
battery power supply, user would not know the battery charging
status. To avoid this, just return 0 after printing an error.

This would only affect the user by disallowing a change to the
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT property under battery
power supply.

Change-Id: I216d4d370e71ec5003adbee2600191e36a45e870
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
d510fed6c9 power: supply: qti_battery_charger: add support to set fake SOC for battery
Setting a fake battery SOC (state of charge) is useful to test
different mitigation levels. Add support for it by exposing
fake_soc under qcom-battery class which can be set only when
CONFIG_QTI_PMIC_GLINK_CLIENT_DEBUG is enabled.

To set fake_soc of 50%,

 echo 50 > /sys/class/qcom-battery/fake_soc

To clear fake_soc so that actual battery SOC can be displayed,
any value other than 0-100 can be set to fake_soc.

 echo -1 > /sys/class/qcom-battery/fake_soc

Change-Id: Ibff337fb4da9d4e9aadbe148f3eecca9e2d69604
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
118b9b4fca power: supply: qti_battery_charger: add SSR support
Add subsystem restart (SSR) support to battery charger driver so
that it can stop read/write properties when subsystem goes down.
Also, send message to enable notification again once subsystem
comes up.

Change-Id: I64f3abfa1d12c4e6a65fd01d7f66155c8741e68a
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
fa4c593866 power: supply: qti_battery_charger: Allow ICL to be set only for SDP
Input Current Limit (ICL) needs to be set only for SDP and not
for other charger types. Add that logic.

Change-Id: Ib48acf5666ea4190b7a11c27ab9cefbb534632fb
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
e3913a8487 power: supply: qti-battery-charger: Initialize pmic_glink_client_data
Fix pmic_glink_client_data initialization without which ssr_cb
that would be added in the upcoming patch causes an incorrect
list addition to PMIC Glink notification list.

Change-Id: I7588ae894e8188c30456f4c16711bc6b757a9863
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
d1ec86b2ea power: supply: qti_battery_charger: add thermal mitigation support
Add "qcom,thermal-mitigation" property to specify charging
current thresholds for thermal mitigation levels. These values
will be passed on to the charger firmware running on a remote
subsystem when thermal SW sets CHARGE_CONTROL_LIMIT property in
battery power supply.

Change-Id: I67be3f9012718de9b2cd529ed6043fb54f503003
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
977a64d048 power: supply: qti_battery_charger: Handle generic notification
Charger firmware sends some battery related events with a generic
notification opcode. Handle such notifications as well to send
events up to the userspace.

Change-Id: Ia35fb7dbe56183d3c7c7a66b5f387b94072e6ed0
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00
Subbaraman Narayanamurthy
bf5cca2dcf power: supply: Add QTI battery charger
Add Qualcomm Technologies, Inc. battery charger driver which
interfaces with the charger firmware running on the remote
subsystem (e.g. DSP) by communicating over PMIC Glink channel and
provides information about the battery, USB and wireless charging
by exposing them as power supply devices.

Change-Id: I36a2efd0b66bc5f79515b5faa318c537a5927e76
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2021-09-24 12:46:56 -07:00