2424#define BD7182x_MASK_CONF_PON BIT(0)
2525#define BD71815_MASK_CONF_XSTB BIT(1)
2626#define BD7182x_MASK_BAT_STAT 0x3f
27+ #define BD7182x_MASK_ILIM 0x3f
2728#define BD7182x_MASK_DCIN_STAT 0x07
2829
2930#define BD7182x_MASK_WDT_AUTO 0x40
@@ -48,9 +49,11 @@ struct pwr_regs {
4849 unsigned int vbat_avg ;
4950 unsigned int ibat ;
5051 unsigned int ibat_avg ;
52+ unsigned int ilim_stat ;
5153 unsigned int btemp_vth ;
5254 unsigned int chg_state ;
5355 unsigned int bat_temp ;
56+ unsigned int dcin_set ;
5457 unsigned int dcin_stat ;
5558 unsigned int dcin_online_mask ;
5659 unsigned int dcin_collapse_limit ;
@@ -66,9 +69,11 @@ static const struct pwr_regs pwr_regs_bd71828 = {
6669 .vbat_avg = BD71828_REG_VBAT_U ,
6770 .ibat = BD71828_REG_IBAT_U ,
6871 .ibat_avg = BD71828_REG_IBAT_AVG_U ,
72+ .ilim_stat = BD71828_REG_ILIM_STAT ,
6973 .btemp_vth = BD71828_REG_VM_BTMP_U ,
7074 .chg_state = BD71828_REG_CHG_STATE ,
7175 .bat_temp = BD71828_REG_BAT_TEMP ,
76+ .dcin_set = BD71828_REG_DCIN_SET ,
7277 .dcin_stat = BD71828_REG_DCIN_STAT ,
7378 .dcin_online_mask = BD7182x_MASK_DCIN_DET ,
7479 .dcin_collapse_limit = BD71828_REG_DCIN_CLPS ,
@@ -441,6 +446,7 @@ static int bd71828_charger_get_property(struct power_supply *psy,
441446 struct bd71828_power * pwr = dev_get_drvdata (psy -> dev .parent );
442447 u32 vot ;
443448 u16 tmp ;
449+ int t ;
444450 int online ;
445451 int ret ;
446452
@@ -459,6 +465,20 @@ static int bd71828_charger_get_property(struct power_supply *psy,
459465 vot = tmp ;
460466 /* 5 milli volt steps */
461467 val -> intval = 5000 * vot ;
468+ break ;
469+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT :
470+ if (!pwr -> regs -> ilim_stat )
471+ return - ENODATA ;
472+
473+ ret = regmap_read (pwr -> regmap , pwr -> regs -> ilim_stat , & t );
474+ if (ret )
475+ return ret ;
476+
477+ t ++ ;
478+ val -> intval = (t & BD7182x_MASK_ILIM ) * 50000 ;
479+ if (val -> intval > 2000000 )
480+ val -> intval = 2000000 ;
481+
462482 break ;
463483 default :
464484 return - EINVAL ;
@@ -467,6 +487,45 @@ static int bd71828_charger_get_property(struct power_supply *psy,
467487 return 0 ;
468488}
469489
490+ static int bd71828_charger_set_property (struct power_supply * psy ,
491+ enum power_supply_property psp ,
492+ const union power_supply_propval * val )
493+ {
494+ struct bd71828_power * pwr = dev_get_drvdata (psy -> dev .parent );
495+
496+ switch (psp ) {
497+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT :
498+ if (val -> intval > 2000000 )
499+ return - EINVAL ;
500+
501+ if (val -> intval < 50000 )
502+ return - EINVAL ;
503+
504+ if (!pwr -> regs -> dcin_set )
505+ return - EINVAL ;
506+
507+ return regmap_update_bits (pwr -> regmap , pwr -> regs -> dcin_set ,
508+ BD7182x_MASK_ILIM ,
509+ val -> intval / 50000 - 1 );
510+ break ;
511+ default :
512+ return - EINVAL ;
513+ }
514+ }
515+
516+ static int bd71828_charger_property_is_writeable (struct power_supply * psy ,
517+ enum power_supply_property psp )
518+ {
519+ struct bd71828_power * pwr = dev_get_drvdata (psy -> dev .parent );
520+
521+ switch (psp ) {
522+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT :
523+ return !!(pwr -> regs -> dcin_set );
524+ default :
525+ return false;
526+ }
527+ }
528+
470529static int bd71828_battery_get_property (struct power_supply * psy ,
471530 enum power_supply_property psp ,
472531 union power_supply_propval * val )
@@ -571,6 +630,7 @@ static int bd71828_battery_property_is_writeable(struct power_supply *psy,
571630
572631/** @brief ac properties */
573632static const enum power_supply_property bd71828_charger_props [] = {
633+ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT ,
574634 POWER_SUPPLY_PROP_ONLINE ,
575635 POWER_SUPPLY_PROP_VOLTAGE_NOW ,
576636};
@@ -600,6 +660,8 @@ static const struct power_supply_desc bd71828_ac_desc = {
600660 .properties = bd71828_charger_props ,
601661 .num_properties = ARRAY_SIZE (bd71828_charger_props ),
602662 .get_property = bd71828_charger_get_property ,
663+ .set_property = bd71828_charger_set_property ,
664+ .property_is_writeable = bd71828_charger_property_is_writeable ,
603665};
604666
605667static const struct power_supply_desc bd71828_bat_desc = {
0 commit comments