@@ -126,6 +126,11 @@ static void wacom_notify_battery(struct wacom_wac *wacom_wac,
126
126
bool bat_connected , bool ps_connected )
127
127
{
128
128
struct wacom * wacom = container_of (wacom_wac , struct wacom , wacom_wac );
129
+ bool bat_initialized = WACOM_POWERSUPPLY_DEVICE (wacom -> battery .battery );
130
+ bool has_quirk = wacom_wac -> features .quirks & WACOM_QUIRK_BATTERY ;
131
+
132
+ if (bat_initialized != has_quirk )
133
+ wacom_schedule_work (wacom_wac , WACOM_WORKER_BATTERY );
129
134
130
135
__wacom_notify_battery (& wacom -> battery , bat_status , bat_capacity ,
131
136
bat_charging , bat_connected , ps_connected );
@@ -1954,18 +1959,7 @@ static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
1954
1959
static void wacom_wac_battery_usage_mapping (struct hid_device * hdev ,
1955
1960
struct hid_field * field , struct hid_usage * usage )
1956
1961
{
1957
- struct wacom * wacom = hid_get_drvdata (hdev );
1958
- struct wacom_wac * wacom_wac = & wacom -> wacom_wac ;
1959
- struct wacom_features * features = & wacom_wac -> features ;
1960
- unsigned equivalent_usage = wacom_equivalent_usage (usage -> hid );
1961
-
1962
- switch (equivalent_usage ) {
1963
- case HID_DG_BATTERYSTRENGTH :
1964
- case WACOM_HID_WD_BATTERY_LEVEL :
1965
- case WACOM_HID_WD_BATTERY_CHARGING :
1966
- features -> quirks |= WACOM_QUIRK_BATTERY ;
1967
- break ;
1968
- }
1962
+ return ;
1969
1963
}
1970
1964
1971
1965
static void wacom_wac_battery_event (struct hid_device * hdev , struct hid_field * field ,
@@ -1986,18 +1980,21 @@ static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *f
1986
1980
wacom_wac -> hid_data .bat_connected = 1 ;
1987
1981
wacom_wac -> hid_data .bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO ;
1988
1982
}
1983
+ wacom_wac -> features .quirks |= WACOM_QUIRK_BATTERY ;
1989
1984
break ;
1990
1985
case WACOM_HID_WD_BATTERY_LEVEL :
1991
1986
value = value * 100 / (field -> logical_maximum - field -> logical_minimum );
1992
1987
wacom_wac -> hid_data .battery_capacity = value ;
1993
1988
wacom_wac -> hid_data .bat_connected = 1 ;
1994
1989
wacom_wac -> hid_data .bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO ;
1990
+ wacom_wac -> features .quirks |= WACOM_QUIRK_BATTERY ;
1995
1991
break ;
1996
1992
case WACOM_HID_WD_BATTERY_CHARGING :
1997
1993
wacom_wac -> hid_data .bat_charging = value ;
1998
1994
wacom_wac -> hid_data .ps_connected = value ;
1999
1995
wacom_wac -> hid_data .bat_connected = 1 ;
2000
1996
wacom_wac -> hid_data .bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO ;
1997
+ wacom_wac -> features .quirks |= WACOM_QUIRK_BATTERY ;
2001
1998
break ;
2002
1999
}
2003
2000
}
@@ -2013,18 +2010,15 @@ static void wacom_wac_battery_report(struct hid_device *hdev,
2013
2010
{
2014
2011
struct wacom * wacom = hid_get_drvdata (hdev );
2015
2012
struct wacom_wac * wacom_wac = & wacom -> wacom_wac ;
2016
- struct wacom_features * features = & wacom_wac -> features ;
2017
2013
2018
- if (features -> quirks & WACOM_QUIRK_BATTERY ) {
2019
- int status = wacom_wac -> hid_data .bat_status ;
2020
- int capacity = wacom_wac -> hid_data .battery_capacity ;
2021
- bool charging = wacom_wac -> hid_data .bat_charging ;
2022
- bool connected = wacom_wac -> hid_data .bat_connected ;
2023
- bool powered = wacom_wac -> hid_data .ps_connected ;
2014
+ int status = wacom_wac -> hid_data .bat_status ;
2015
+ int capacity = wacom_wac -> hid_data .battery_capacity ;
2016
+ bool charging = wacom_wac -> hid_data .bat_charging ;
2017
+ bool connected = wacom_wac -> hid_data .bat_connected ;
2018
+ bool powered = wacom_wac -> hid_data .ps_connected ;
2024
2019
2025
- wacom_notify_battery (wacom_wac , status , capacity , charging ,
2026
- connected , powered );
2027
- }
2020
+ wacom_notify_battery (wacom_wac , status , capacity , charging ,
2021
+ connected , powered );
2028
2022
}
2029
2023
2030
2024
static void wacom_wac_pad_usage_mapping (struct hid_device * hdev ,
@@ -3389,19 +3383,13 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
3389
3383
int battery = (data [8 ] & 0x3f ) * 100 / 31 ;
3390
3384
bool charging = !!(data [8 ] & 0x80 );
3391
3385
3386
+ features -> quirks |= WACOM_QUIRK_BATTERY ;
3392
3387
wacom_notify_battery (wacom_wac , WACOM_POWER_SUPPLY_STATUS_AUTO ,
3393
3388
battery , charging , battery || charging , 1 );
3394
-
3395
- if (!WACOM_POWERSUPPLY_DEVICE (wacom -> battery .battery ) &&
3396
- !(features -> quirks & WACOM_QUIRK_BATTERY )) {
3397
- features -> quirks |= WACOM_QUIRK_BATTERY ;
3398
- wacom_schedule_work (wacom_wac , WACOM_WORKER_BATTERY );
3399
- }
3400
3389
}
3401
3390
else if ((features -> quirks & WACOM_QUIRK_BATTERY ) &&
3402
3391
WACOM_POWERSUPPLY_DEVICE (wacom -> battery .battery )) {
3403
3392
features -> quirks &= ~WACOM_QUIRK_BATTERY ;
3404
- wacom_schedule_work (wacom_wac , WACOM_WORKER_BATTERY );
3405
3393
wacom_notify_battery (wacom_wac , POWER_SUPPLY_STATUS_UNKNOWN , 0 , 0 , 0 , 0 );
3406
3394
}
3407
3395
return 0 ;
0 commit comments