All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: Hamza Mahfooz <someguy@effective-light.com>,
	linux-kernel@vger.kernel.org
Cc: "Jiri Kosina" <jikos@kernel.org>,
	"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
	"Filipe Laíns" <lains@riseup.net>,
	linux-input@vger.kernel.org
Subject: Re: [PATCH v2] HID: logitech-hidpp: battery: provide CAPACITY property for newer devices
Date: Fri, 23 Jul 2021 13:37:45 +0200	[thread overview]
Message-ID: <ac1c288bc64183128d7bc0da09573ca6aaa6f299.camel@hadess.net> (raw)
In-Reply-To: <20210723112337.101495-1-someguy@effective-light.com>

On Fri, 2021-07-23 at 07:23 -0400, Hamza Mahfooz wrote:
> For devices that only support the BATTERY_VOLTAGE (0x1001) feature,
> UPower
> requires the additional information provided by this patch, to set
> them up.
> 
> v2: use ARRAY_SIZE() and set voltages[]'s size to 100

This information should be under the "---" below, so that it gets
stripped when the patch is applied by git. I'm sure Jiri can fix that
up though.

> 
> Signed-off-by: Hamza Mahfooz <someguy@effective-light.com>
> ---
>  drivers/hid/hid-logitech-hidpp.c | 30 +++++++++++++++++++++++++++++-
>  1 file changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-
> logitech-hidpp.c
> index 61635e629469..6d63804a9a0f 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -1331,6 +1331,31 @@ static int
> hidpp20_battery_get_battery_voltage(struct hidpp_device *hidpp,
>         return 0;
>  }
>  
> +static int hidpp20_map_battery_capacity(int voltage)
> +{
> +       static const int voltages[100] = {

Looks good to me.

Is there a way to make sure that there are actually 100 values being
set in the array?

> +               4186, 4156, 4143, 4133, 4122, 4113, 4103, 4094, 4086,
> 4075,
> +               4067, 4059, 4051, 4043, 4035, 4027, 4019, 4011, 4003,
> 3997,
> +               3989, 3983, 3976, 3969, 3961, 3955, 3949, 3942, 3935,
> 3929,
> +               3922, 3916, 3909, 3902, 3896, 3890, 3883, 3877, 3870,
> 3865,
> +               3859, 3853, 3848, 3842, 3837, 3833, 3828, 3824, 3819,
> 3815,
> +               3811, 3808, 3804, 3800, 3797, 3793, 3790, 3787, 3784,
> 3781,
> +               3778, 3775, 3772, 3770, 3767, 3764, 3762, 3759, 3757,
> 3754,
> +               3751, 3748, 3744, 3741, 3737, 3734, 3730, 3726, 3724,
> 3720,
> +               3717, 3714, 3710, 3706, 3702, 3697, 3693, 3688, 3683,
> 3677,
> +               3671, 3666, 3662, 3658, 3654, 3646, 3633, 3612, 3579,
> 3537
> +       };
> +
> +       int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(voltages); i++) {
> +               if (voltage >= voltages[i])
> +                       return ARRAY_SIZE(voltages) - i;
> +       }
> +
> +       return 0;
> +}
> +
>  static int hidpp20_query_battery_voltage_info(struct hidpp_device
> *hidpp)
>  {
>         u8 feature_type;
> @@ -1354,6 +1379,7 @@ static int
> hidpp20_query_battery_voltage_info(struct hidpp_device *hidpp)
>  
>         hidpp->battery.status = status;
>         hidpp->battery.voltage = voltage;
> +       hidpp->battery.capacity =
> hidpp20_map_battery_capacity(voltage);
>         hidpp->battery.level = level;
>         hidpp->battery.charge_type = charge_type;
>         hidpp->battery.online = status !=
> POWER_SUPPLY_STATUS_NOT_CHARGING;
> @@ -1378,6 +1404,7 @@ static int hidpp20_battery_voltage_event(struct
> hidpp_device *hidpp,
>  
>         if (voltage != hidpp->battery.voltage || status != hidpp-
> >battery.status) {
>                 hidpp->battery.voltage = voltage;
> +               hidpp->battery.capacity =
> hidpp20_map_battery_capacity(voltage);
>                 hidpp->battery.status = status;
>                 hidpp->battery.level = level;
>                 hidpp->battery.charge_type = charge_type;
> @@ -3717,7 +3744,8 @@ static int hidpp_initialize_battery(struct
> hidpp_device *hidpp)
>         num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3;
>  
>         if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE ||
> -           hidpp->capabilities &
> HIDPP_CAPABILITY_BATTERY_PERCENTAGE)
> +           hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE
> ||
> +           hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
>                 battery_props[num_battery_props++] =
>                                 POWER_SUPPLY_PROP_CAPACITY;
>  



      reply	other threads:[~2021-07-23 11:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23 11:23 [PATCH v2] HID: logitech-hidpp: battery: provide CAPACITY property for newer devices Hamza Mahfooz
2021-07-23 11:37 ` Bastien Nocera [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=ac1c288bc64183128d7bc0da09573ca6aaa6f299.camel@hadess.net \
    --to=hadess@hadess.net \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=lains@riseup.net \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=someguy@effective-light.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.