linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "José Expósito" <jose.exposito89@gmail.com>
To: jikos@kernel.org
Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"José Expósito" <jose.exposito89@gmail.com>
Subject: [PATCH 5/5] HID: magicmouse: report battery status
Date: Tue, 11 May 2021 20:20:23 +0200	[thread overview]
Message-ID: <20210511182023.730524-5-jose.exposito89@gmail.com> (raw)
In-Reply-To: <20210511182023.730524-1-jose.exposito89@gmail.com>

Report the battery charging status for the Apple Magic Mouse 2
and the Apple Magic Trackpad 2.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-magicmouse.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 53e8a10f0551..4085b6698f2c 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -155,6 +155,7 @@ static enum power_supply_property magicmouse_ps_props[] = {
 	POWER_SUPPLY_PROP_PRESENT,
 	POWER_SUPPLY_PROP_SCOPE,
 	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_STATUS,
 };
 
 static bool magicmouse_can_report_battery(struct magicmouse_sc *msc)
@@ -229,6 +230,15 @@ static int magicmouse_battery_get_property(struct power_supply *psy,
 
 		val->intval = msc->battery.capacity;
 		break;
+	case POWER_SUPPLY_PROP_STATUS:
+		if (msc->input->id.vendor == BT_VENDOR_ID_APPLE) {
+			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+		} else { /* USB_VENDOR_ID_APPLE */
+			val->intval = (msc->battery.capacity == 100) ?
+				      POWER_SUPPLY_STATUS_FULL :
+				      POWER_SUPPLY_STATUS_CHARGING;
+		}
+		break;
 	default:
 		ret = -EINVAL;
 		break;
-- 
2.25.1


      parent reply	other threads:[~2021-05-11 18:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 18:20 [PATCH 1/5] HID: magicmouse: register power supply José Expósito
2021-05-11 18:20 ` [PATCH 2/5] HID: magicmouse: report battery capacity over bluetooth José Expósito
2021-05-11 18:20 ` [PATCH 3/5] HID: magicmouse: Magic Trackpad 2 USB battery capacity José Expósito
2021-05-12  9:39   ` kernel test robot
2021-05-15 18:50     ` José Expósito
2021-05-20  9:18       ` [kbuild-all] " Rong Chen
2021-05-22 17:41         ` José Expósito
2021-05-12 11:28   ` kernel test robot
2021-05-11 18:20 ` [PATCH 4/5] HID: magicmouse: Magic Mouse " José Expósito
2021-05-11 18:20 ` José Expósito [this message]

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=20210511182023.730524-5-jose.exposito89@gmail.com \
    --to=jose.exposito89@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).