@@ -105,6 +105,17 @@ static int max77705_get_online(struct regmap *regmap, int *val)
105105 return 0 ;
106106}
107107
108+ static int max77705_set_integer (struct max77705_charger_data * chg , enum max77705_field_idx fidx ,
109+ unsigned int clamp_min , unsigned int clamp_max ,
110+ unsigned int div , int val )
111+ {
112+ unsigned int regval ;
113+
114+ regval = clamp_val (val , clamp_min , clamp_max ) / div ;
115+
116+ return regmap_field_write (chg -> rfield [fidx ], regval );
117+ }
118+
108119static int max77705_check_battery (struct max77705_charger_data * chg , int * val )
109120{
110121 unsigned int reg_data ;
@@ -384,12 +395,55 @@ static int max77705_chg_get_property(struct power_supply *psy,
384395 return 0 ;
385396}
386397
398+ static int max77705_set_property (struct power_supply * psy ,
399+ enum power_supply_property psp ,
400+ const union power_supply_propval * val )
401+ {
402+ struct max77705_charger_data * chg = power_supply_get_drvdata (psy );
403+ int err = 0 ;
404+
405+ switch (psp ) {
406+ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
407+ err = max77705_set_integer (chg , MAX77705_CHG_CC_LIM ,
408+ MAX77705_CURRENT_CHGIN_MIN ,
409+ MAX77705_CURRENT_CHGIN_MAX ,
410+ MAX77705_CURRENT_CHG_STEP ,
411+ val -> intval );
412+ break ;
413+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT :
414+ err = max77705_set_integer (chg , MAX77705_CHG_CHGIN_LIM ,
415+ MAX77705_CURRENT_CHGIN_MIN ,
416+ MAX77705_CURRENT_CHGIN_MAX ,
417+ MAX77705_CURRENT_CHGIN_STEP ,
418+ val -> intval );
419+ break ;
420+ default :
421+ err = - EINVAL ;
422+ }
423+
424+ return err ;
425+ };
426+
427+ static int max77705_property_is_writeable (struct power_supply * psy ,
428+ enum power_supply_property psp )
429+ {
430+ switch (psp ) {
431+ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
432+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT :
433+ return true;
434+ default :
435+ return false;
436+ }
437+ }
438+
387439static const struct power_supply_desc max77705_charger_psy_desc = {
388440 .name = "max77705-charger" ,
389- .type = POWER_SUPPLY_TYPE_USB ,
441+ .type = POWER_SUPPLY_TYPE_USB ,
390442 .properties = max77705_charger_props ,
443+ .property_is_writeable = max77705_property_is_writeable ,
391444 .num_properties = ARRAY_SIZE (max77705_charger_props ),
392445 .get_property = max77705_chg_get_property ,
446+ .set_property = max77705_set_property ,
393447};
394448
395449static void max77705_chgin_isr_work (struct work_struct * work )
0 commit comments