diff options
author | Lode Willems <me@lodewillems.com> | 2024-10-05 13:57:06 +0200 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.com> | 2024-10-18 12:28:40 +0200 |
commit | 9372b6c4ed80f474810d562058b625309827e36e (patch) | |
tree | 65c2ec68762f6697d722c82492254678487e084d /drivers/hid | |
parent | 94ec1cd82f55ebbf5c0d63c8aa7f849fdab2b535 (diff) |
HID: Kysona: add basic online status
Wait for a response to the battery status request to set the device as
online. This prevent wrong power info when the dongle is connected but
the mouse is turned off.
Signed-off-by: Lode Willems <me@lodewillems.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/hid-kysona.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/hid/hid-kysona.c b/drivers/hid/hid-kysona.c index 403bdc4a5e12..d4c0406b3323 100644 --- a/drivers/hid/hid-kysona.c +++ b/drivers/hid/hid-kysona.c @@ -18,6 +18,8 @@ struct kysona_drvdata { struct hid_device *hdev; + bool online; + struct power_supply_desc battery_desc; struct power_supply *battery; u8 battery_capacity; @@ -32,7 +34,8 @@ static enum power_supply_property kysona_battery_props[] = { POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_MODEL_NAME, - POWER_SUPPLY_PROP_VOLTAGE_NOW + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_ONLINE }; static int kysona_battery_get_property(struct power_supply *psy, @@ -46,11 +49,16 @@ static int kysona_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_PRESENT: val->intval = 1; break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = drv_data->online; + break; case POWER_SUPPLY_PROP_STATUS: - // TODO: check if device is online - val->intval = drv_data->battery_charging ? - POWER_SUPPLY_STATUS_CHARGING : - POWER_SUPPLY_STATUS_DISCHARGING; + if (drv_data->online) + val->intval = drv_data->battery_charging ? + POWER_SUPPLY_STATUS_CHARGING : + POWER_SUPPLY_STATUS_DISCHARGING; + else + val->intval = POWER_SUPPLY_STATUS_UNKNOWN; break; case POWER_SUPPLY_PROP_SCOPE: val->intval = POWER_SUPPLY_SCOPE_DEVICE; @@ -124,7 +132,9 @@ static int kysona_battery_probe(struct hid_device *hdev) struct power_supply_config pscfg = { .drv_data = drv_data }; int ret = 0; + drv_data->online = false; drv_data->battery_capacity = 100; + drv_data->battery_voltage = 4200; drv_data->battery_desc.properties = kysona_battery_props; drv_data->battery_desc.num_properties = ARRAY_SIZE(kysona_battery_props); @@ -201,6 +211,7 @@ static int kysona_raw_event(struct hid_device *hdev, drv_data->battery_capacity = data[6]; drv_data->battery_charging = data[7]; drv_data->battery_voltage = (data[8] << 8) | data[9]; + drv_data->online = true; } return 0; |