From: Lode Willems <me@lodewillems.com>
To: linux-input@vger.kernel.org
Cc: jikos@kernel.org, bentiss@kernel.org,
linux-kernel@vger.kernel.org, Lode Willems <me@lodewillems.com>
Subject: [PATCH 4/4] HID: Kysona: add basic online status
Date: Sat, 5 Oct 2024 13:57:06 +0200 [thread overview]
Message-ID: <20241005120256.13847-5-me@lodewillems.com> (raw)
In-Reply-To: <20241005120256.13847-1-me@lodewillems.com>
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>
---
drivers/hid/hid-kysona.c | 21 ++++++++++++++++-----
1 file 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;
--
2.46.1
next prev parent reply other threads:[~2024-10-05 12:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-05 11:57 [PATCH 0/4] HID: add Kysona driver Lode Willems
2024-10-05 11:57 ` [PATCH 1/4] HID: Add IDs for Kysona Lode Willems
2024-10-05 11:57 ` [PATCH 2/4] HID: Kysona: Add basic battery reporting for Kysona M600 Lode Willems
2024-10-05 11:57 ` [PATCH 3/4] HID: Kysona: check battery status every 5s using a workqueue Lode Willems
2024-10-05 11:57 ` Lode Willems [this message]
2024-10-18 10:29 ` [PATCH 0/4] HID: add Kysona driver Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241005120256.13847-5-me@lodewillems.com \
--to=me@lodewillems.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®