@@ -35,6 +35,8 @@ static int battery_capacity = 50;
3535static int battery_voltage = 3300 ;
3636static int battery_charge_counter = -1000 ;
3737static int battery_current = -1600 ;
38+ static enum power_supply_charge_behaviour battery_charge_behaviour =
39+ POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO ;
3840
3941static bool module_initialized ;
4042
@@ -123,6 +125,9 @@ static int test_power_get_battery_property(struct power_supply *psy,
123125 case POWER_SUPPLY_PROP_CURRENT_NOW :
124126 val -> intval = battery_current ;
125127 break ;
128+ case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR :
129+ val -> intval = battery_charge_behaviour ;
130+ break ;
126131 default :
127132 pr_info ("%s: some properties deliberately report errors.\n" ,
128133 __func__ );
@@ -131,6 +136,31 @@ static int test_power_get_battery_property(struct power_supply *psy,
131136 return 0 ;
132137}
133138
139+ static int test_power_battery_property_is_writeable (struct power_supply * psy ,
140+ enum power_supply_property psp )
141+ {
142+ return psp == POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR ;
143+ }
144+
145+ static int test_power_set_battery_property (struct power_supply * psy ,
146+ enum power_supply_property psp ,
147+ const union power_supply_propval * val )
148+ {
149+ switch (psp ) {
150+ case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR :
151+ if (val -> intval < 0 ||
152+ val -> intval >= BITS_PER_TYPE (typeof (psy -> desc -> charge_behaviours )) ||
153+ !(BIT (val -> intval ) & psy -> desc -> charge_behaviours )) {
154+ return - EINVAL ;
155+ }
156+ battery_charge_behaviour = val -> intval ;
157+ break ;
158+ default :
159+ return - EINVAL ;
160+ }
161+ return 0 ;
162+ }
163+
134164static enum power_supply_property test_power_ac_props [] = {
135165 POWER_SUPPLY_PROP_ONLINE ,
136166};
@@ -156,6 +186,7 @@ static enum power_supply_property test_power_battery_props[] = {
156186 POWER_SUPPLY_PROP_VOLTAGE_NOW ,
157187 POWER_SUPPLY_PROP_CURRENT_AVG ,
158188 POWER_SUPPLY_PROP_CURRENT_NOW ,
189+ POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR ,
159190};
160191
161192static char * test_power_ac_supplied_to [] = {
@@ -178,6 +209,11 @@ static const struct power_supply_desc test_power_desc[] = {
178209 .properties = test_power_battery_props ,
179210 .num_properties = ARRAY_SIZE (test_power_battery_props ),
180211 .get_property = test_power_get_battery_property ,
212+ .set_property = test_power_set_battery_property ,
213+ .property_is_writeable = test_power_battery_property_is_writeable ,
214+ .charge_behaviours = BIT (POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO )
215+ | BIT (POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE )
216+ | BIT (POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE ),
181217 },
182218 [TEST_USB ] = {
183219 .name = "test_usb" ,
0 commit comments