linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pedro Vanzella <pedro@pedrovanzella.com>
To: linux-input@vger.kernel.org
Cc: lains@archlinux.org, Pedro Vanzella <pedro@pedrovanzella.com>,
	Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 3/4] hid-logitech-hidpp: report battery voltage to the power supply
Date: Thu, 22 Aug 2019 16:18:47 -0400	[thread overview]
Message-ID: <20190822201849.28924-4-pedro@pedrovanzella.com> (raw)
In-Reply-To: <20190822201849.28924-1-pedro@pedrovanzella.com>

If we know the device supports reading its voltage, report that.

Note that the protocol only gives us the current voltage in millivolts.

Signed-off-by: Pedro Vanzella <pedro@pedrovanzella.com>
---
 drivers/hid/hid-logitech-hidpp.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index e1ddc9cdcc8b..06bee97d33b4 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -1319,6 +1319,7 @@ static enum power_supply_property hidpp_battery_props[] = {
 	POWER_SUPPLY_PROP_SERIAL_NUMBER,
 	0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
 	0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
+	0, /* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */
 };
 
 static int hidpp_battery_get_property(struct power_supply *psy,
@@ -1356,6 +1357,9 @@ static int hidpp_battery_get_property(struct power_supply *psy,
 		case POWER_SUPPLY_PROP_SERIAL_NUMBER:
 			val->strval = hidpp->hid_dev->uniq;
 			break;
+		case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+			val->intval = hidpp->battery.voltage;
+			break;
 		default:
 			ret = -EINVAL;
 			break;
@@ -3328,7 +3332,7 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
 	if (!battery_props)
 		return -ENOMEM;
 
-	num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2;
+	num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3;
 
 	if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
 		battery_props[num_battery_props++] =
@@ -3338,6 +3342,10 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
 		battery_props[num_battery_props++] =
 				POWER_SUPPLY_PROP_CAPACITY_LEVEL;
 
+	if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
+		battery_props[num_battery_props++] =
+			POWER_SUPPLY_PROP_VOLTAGE_NOW;
+
 	battery = &hidpp->battery;
 
 	n = atomic_inc_return(&battery_no) - 1;
-- 
2.23.0


  parent reply	other threads:[~2019-08-22 20:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-22 20:18 [Resubmit] Read battery voltage from Logitech Gaming mice Pedro Vanzella
2019-08-22 20:18 ` [PATCH v3 1/4] hid-logitech-hidpp: add quirk to handle battery voltage Pedro Vanzella
2019-08-22 20:18 ` [PATCH v3 2/4] hid-logitech-hidpp: add function to query " Pedro Vanzella
2019-08-22 20:18 ` Pedro Vanzella [this message]
2019-08-22 20:18 ` [PATCH v3 4/4] hid-logitech-hidpp: subscribe to battery voltage events Pedro Vanzella
2019-08-23  8:25 ` [Resubmit] Read battery voltage from Logitech Gaming mice Benjamin Tissoires
2019-08-23 14:22   ` Pedro Vanzella
2019-08-23 14:29     ` Filipe Laíns
2019-08-23 14:32     ` Benjamin Tissoires
2019-08-23 14:48       ` Filipe Laíns
2019-08-23 15:32         ` Benjamin Tissoires
2019-08-23 15:46       ` Pedro Vanzella

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=20190822201849.28924-4-pedro@pedrovanzella.com \
    --to=pedro@pedrovanzella.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=lains@archlinux.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;
as well as URLs for NNTP newsgroup(s).