3333#define CM_DEFAULT_RECHARGE_TEMP_DIFF 50
3434#define CM_DEFAULT_CHARGE_TEMP_MAX 500
3535
36- static const char * const default_event_names [] = {
37- [CM_EVENT_UNKNOWN ] = "Unknown" ,
38- [CM_EVENT_BATT_FULL ] = "Battery Full" ,
39- [CM_EVENT_BATT_IN ] = "Battery Inserted" ,
40- [CM_EVENT_BATT_OUT ] = "Battery Pulled Out" ,
41- [CM_EVENT_BATT_OVERHEAT ] = "Battery Overheat" ,
42- [CM_EVENT_BATT_COLD ] = "Battery Cold" ,
43- [CM_EVENT_EXT_PWR_IN_OUT ] = "External Power Attach/Detach" ,
44- [CM_EVENT_CHG_START_STOP ] = "Charging Start/Stop" ,
45- [CM_EVENT_OTHERS ] = "Other battery events"
46- };
47-
4836/*
4937 * Regard CM_JIFFIES_SMALL jiffies is small enough to ignore for
5038 * delayed works so that we can run delayed works with CM_JIFFIES_SMALL
@@ -61,8 +49,6 @@ static const char * const default_event_names[] = {
6149 */
6250#define CM_RTC_SMALL (2)
6351
64- #define UEVENT_BUF_SIZE 32
65-
6652static LIST_HEAD (cm_list );
6753static DEFINE_MUTEX (cm_list_mtx );
6854
@@ -446,61 +432,6 @@ static int try_charger_restart(struct charger_manager *cm)
446432 return try_charger_enable (cm , true);
447433}
448434
449- /**
450- * uevent_notify - Let users know something has changed.
451- * @cm: the Charger Manager representing the battery.
452- * @event: the event string.
453- *
454- * If @event is null, it implies that uevent_notify is called
455- * by resume function. When called in the resume function, cm_suspended
456- * should be already reset to false in order to let uevent_notify
457- * notify the recent event during the suspend to users. While
458- * suspended, uevent_notify does not notify users, but tracks
459- * events so that uevent_notify can notify users later after resumed.
460- */
461- static void uevent_notify (struct charger_manager * cm , const char * event )
462- {
463- static char env_str [UEVENT_BUF_SIZE + 1 ] = "" ;
464- static char env_str_save [UEVENT_BUF_SIZE + 1 ] = "" ;
465-
466- if (cm_suspended ) {
467- /* Nothing in suspended-event buffer */
468- if (env_str_save [0 ] == 0 ) {
469- if (!strncmp (env_str , event , UEVENT_BUF_SIZE ))
470- return ; /* status not changed */
471- strncpy (env_str_save , event , UEVENT_BUF_SIZE );
472- return ;
473- }
474-
475- if (!strncmp (env_str_save , event , UEVENT_BUF_SIZE ))
476- return ; /* Duplicated. */
477- strncpy (env_str_save , event , UEVENT_BUF_SIZE );
478- return ;
479- }
480-
481- if (event == NULL ) {
482- /* No messages pending */
483- if (!env_str_save [0 ])
484- return ;
485-
486- strncpy (env_str , env_str_save , UEVENT_BUF_SIZE );
487- kobject_uevent (& cm -> dev -> kobj , KOBJ_CHANGE );
488- env_str_save [0 ] = 0 ;
489-
490- return ;
491- }
492-
493- /* status not changed */
494- if (!strncmp (env_str , event , UEVENT_BUF_SIZE ))
495- return ;
496-
497- /* save the status and notify the update */
498- strncpy (env_str , event , UEVENT_BUF_SIZE );
499- kobject_uevent (& cm -> dev -> kobj , KOBJ_CHANGE );
500-
501- dev_info (cm -> dev , "%s\n" , event );
502- }
503-
504435/**
505436 * fullbatt_vchk - Check voltage drop some times after "FULL" event.
506437 * @work: the work_struct appointing the function
@@ -538,7 +469,7 @@ static void fullbatt_vchk(struct work_struct *work)
538469
539470 if (diff > desc -> fullbatt_vchkdrop_uV ) {
540471 try_charger_restart (cm );
541- uevent_notify (cm , "Recharging" );
472+ power_supply_changed (cm -> charger_psy );
542473 }
543474}
544475
@@ -569,7 +500,7 @@ static int check_charging_duration(struct charger_manager *cm)
569500 if (duration > desc -> charging_max_duration_ms ) {
570501 dev_info (cm -> dev , "Charging duration exceed %ums\n" ,
571502 desc -> charging_max_duration_ms );
572- uevent_notify (cm , "Discharging" );
503+ power_supply_changed (cm -> charger_psy );
573504 try_charger_enable (cm , false);
574505 ret = true;
575506 }
@@ -580,7 +511,7 @@ static int check_charging_duration(struct charger_manager *cm)
580511 is_ext_pwr_online (cm )) {
581512 dev_info (cm -> dev , "Discharging duration exceed %ums\n" ,
582513 desc -> discharging_max_duration_ms );
583- uevent_notify (cm , "Recharging" );
514+ power_supply_changed (cm -> charger_psy );
584515 try_charger_enable (cm , true);
585516 ret = true;
586517 }
@@ -688,7 +619,7 @@ static bool _cm_monitor(struct charger_manager *cm)
688619 if (temp_alrt ) {
689620 cm -> emergency_stop = temp_alrt ;
690621 if (!try_charger_enable (cm , false))
691- uevent_notify (cm , default_event_names [ temp_alrt ] );
622+ power_supply_changed (cm -> charger_psy );
692623
693624 /*
694625 * Check whole charging duration and discharging duration
@@ -713,7 +644,7 @@ static bool _cm_monitor(struct charger_manager *cm)
713644 } else if (!cm -> emergency_stop && is_full_charged (cm ) &&
714645 cm -> charger_enabled ) {
715646 dev_info (cm -> dev , "EVENT_HANDLE: Battery Fully Charged\n" );
716- uevent_notify (cm , default_event_names [ CM_EVENT_BATT_FULL ] );
647+ power_supply_changed (cm -> charger_psy );
717648
718649 try_charger_enable (cm , false);
719650
@@ -722,7 +653,7 @@ static bool _cm_monitor(struct charger_manager *cm)
722653 cm -> emergency_stop = 0 ;
723654 if (is_ext_pwr_online (cm )) {
724655 if (!try_charger_enable (cm , true))
725- uevent_notify (cm , "CHARGING" );
656+ power_supply_changed (cm -> charger_psy );
726657 }
727658 }
728659
@@ -843,7 +774,7 @@ static void fullbatt_handler(struct charger_manager *cm)
843774
844775out :
845776 dev_info (cm -> dev , "EVENT_HANDLE: Battery Fully Charged\n" );
846- uevent_notify (cm , default_event_names [ CM_EVENT_BATT_FULL ] );
777+ power_supply_changed (cm -> charger_psy );
847778}
848779
849780/**
@@ -857,9 +788,9 @@ static void battout_handler(struct charger_manager *cm)
857788
858789 if (!is_batt_present (cm )) {
859790 dev_emerg (cm -> dev , "Battery Pulled Out!\n" );
860- uevent_notify (cm , default_event_names [ CM_EVENT_BATT_OUT ] );
791+ power_supply_changed (cm -> charger_psy );
861792 } else {
862- uevent_notify (cm , "Battery Reinserted?" );
793+ power_supply_changed (cm -> charger_psy );
863794 }
864795}
865796
@@ -876,7 +807,7 @@ static void misc_event_handler(struct charger_manager *cm,
876807
877808 if (is_polling_required (cm ) && cm -> desc -> polling_interval_ms )
878809 schedule_work (& setup_polling );
879- uevent_notify (cm , default_event_names [ type ] );
810+ power_supply_changed (cm -> charger_psy );
880811}
881812
882813static int charger_get_property (struct power_supply * psy ,
@@ -2048,7 +1979,7 @@ void cm_notify_event(struct power_supply *psy, enum cm_event_types type,
20481979 break ;
20491980 case CM_EVENT_UNKNOWN :
20501981 case CM_EVENT_OTHERS :
2051- uevent_notify (cm , msg ? msg : default_event_names [ type ] );
1982+ power_supply_changed (cm -> charger_psy );
20521983 break ;
20531984 default :
20541985 dev_err (cm -> dev , "%s: type not specified\n" , __func__ );
0 commit comments