Skip to content

Commit b552f84

Browse files
vantomanvbajs
authored andcommitted
Improve charger detection in usbpd_check_cp_psy
- Added a list of charger names to support multiple charger types. - Implemented a retry mechanism to handle cases where the charger is not yet registered. - Added detailed debug logs to track charger search and detection. - Improved error handling and fallback mechanism. Signed-off-by: Yahya Wessam <yahyawessam2002@gmail.com>
1 parent d5881b6 commit b552f84

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

drivers/power/supply/ti/pd_policy_manager.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,39 @@ static int usbpd_set_new_fcc_voter(struct usbpd_pm *pdpm)
356356

357357
static void usbpd_check_cp_psy(struct usbpd_pm *pdpm)
358358
{
359-
if (!pdpm->cp_psy) {
360-
if (pm_config.cp_sec_enable)
361-
pdpm->cp_psy = power_supply_get_by_name("bq2597x-master");
362-
else
363-
pdpm->cp_psy = power_supply_get_by_name("bq2597x-standalone");
364-
if (!pdpm->cp_psy)
365-
{
366-
pdpm->cp_psy = power_supply_get_by_name("ln8000");
367-
if (!pdpm->cp_psy)
368-
pr_err("cp_psy not found\n");
369-
}
370-
}
359+
const char *cp_psy_names[] = {
360+
"bq2597x-master",
361+
"bq2597x-standalone",
362+
"ln8000",
363+
NULL
364+
};
365+
int retries = 3;
366+
int i;
367+
368+
if (pdpm->cp_psy) {
369+
pr_info("cp_psy already set: %s\n", pdpm->cp_psy->desc->name);
370+
return;
371+
}
372+
373+
while (retries--) {
374+
for (i = 0; cp_psy_names[i]; i++) {
375+
pr_info("Searching for cp_psy: %s\n", cp_psy_names[i]);
376+
pdpm->cp_psy = power_supply_get_by_name(cp_psy_names[i]);
377+
if (pdpm->cp_psy) {
378+
pr_info("Found cp_psy: %s\n", cp_psy_names[i]);
379+
return;
380+
}
381+
}
382+
383+
if (!pdpm->cp_psy) {
384+
pr_info("cp_psy not found, retrying... (%d retries left)\n", retries);
385+
msleep(100);
386+
}
387+
}
388+
389+
if (!pdpm->cp_psy) {
390+
pr_err("cp_psy not found after retries\n");
391+
}
371392
}
372393

373394
static void usbpd_check_cp_sec_psy(struct usbpd_pm *pdpm)

0 commit comments

Comments
 (0)