@@ -35,6 +35,8 @@ static int battery_capacity = 50;
35
35
static int battery_voltage = 3300 ;
36
36
static int battery_charge_counter = -1000 ;
37
37
static int battery_current = -1600 ;
38
+ static enum power_supply_charge_behaviour battery_charge_behaviour =
39
+ POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO ;
38
40
39
41
static bool module_initialized ;
40
42
@@ -123,6 +125,9 @@ static int test_power_get_battery_property(struct power_supply *psy,
123
125
case POWER_SUPPLY_PROP_CURRENT_NOW :
124
126
val -> intval = battery_current ;
125
127
break ;
128
+ case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR :
129
+ val -> intval = battery_charge_behaviour ;
130
+ break ;
126
131
default :
127
132
pr_info ("%s: some properties deliberately report errors.\n" ,
128
133
__func__ );
@@ -131,6 +136,31 @@ static int test_power_get_battery_property(struct power_supply *psy,
131
136
return 0 ;
132
137
}
133
138
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
+
134
164
static enum power_supply_property test_power_ac_props [] = {
135
165
POWER_SUPPLY_PROP_ONLINE ,
136
166
};
@@ -156,6 +186,7 @@ static enum power_supply_property test_power_battery_props[] = {
156
186
POWER_SUPPLY_PROP_VOLTAGE_NOW ,
157
187
POWER_SUPPLY_PROP_CURRENT_AVG ,
158
188
POWER_SUPPLY_PROP_CURRENT_NOW ,
189
+ POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR ,
159
190
};
160
191
161
192
static char * test_power_ac_supplied_to [] = {
@@ -178,6 +209,11 @@ static const struct power_supply_desc test_power_desc[] = {
178
209
.properties = test_power_battery_props ,
179
210
.num_properties = ARRAY_SIZE (test_power_battery_props ),
180
211
.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 ),
181
217
},
182
218
[TEST_USB ] = {
183
219
.name = "test_usb" ,
0 commit comments