All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ognjen Galić" <smclt30p-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Andy Shevchenko
	<andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: "Platform Driver"
	<platform-driver-x86-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"Rafael J. Wysocki"
	<rafael-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Henrique de Moraes Holschuh"
	<ibm-acpi-N3TV7GIv+o9fyO9Q7EP/yw@public.gmane.org>,
	"Linux PM" <linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"Rafael J. Wysocki" <rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org>,
	"Robert Moore"
	<robert.moore-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	"Sebastian Reichel" <sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"ACPI Devel Maling List"
	<linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"Lv Zheng" <lv.zheng-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	"Christoph Böhmwalder"
	<christoph-KeW1gJXA36yNJhrcwGid2A@public.gmane.org>,
	"Kevin Locke" <kevin-yFOG++GfaLUI8/NkjqMgMw@public.gmane.org>,
	"Darren Hart" <dvhart-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	devel-E0kO6a4B6psdnm+yROfE0A@public.gmane.org,
	ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	"Andy Shevchenko" <andy-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	"Len Brown" <lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: Re: [PATCH 2/3 v8] thinkpad_acpi: Add support for battery thresholds
Date: Thu, 21 Dec 2017 16:24:06 +0100	[thread overview]
Message-ID: <CALgTWSvnyBysDJqGFwCxB43wgzMAAUqYZ2M5r8-L9ZdJ9J4XxQ@mail.gmail.com> (raw)
In-Reply-To: <CAHp75Vc2MYDLanvZmqaPkmFVfNbyBQoPwbRDDFmKDtSPAmfj9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 5228 bytes --]

On 21 Dec 2017 2:53 pm, "Andy Shevchenko" <andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

On Thu, Dec 21, 2017 at 12:00 PM, Ognjen Galic <smclt30p-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> thinkpad_acpi registers two new attributes for each battery:
>
> 1) Charge start threshold
> /sys/class/power_supply/BATN/charge_start_threshold
>
> Valid values are [0, 99]. A value of 0 turns off the
> start threshold wear control.
>
> 2) Charge stop threshold
> /sys/class/power_supply/BATN/charge_stop_threshold
>
> Valid values are [1, 100]. A value of 100 turns off
> the stop threshold wear control. This must be
> configured first.
>
> This patch depends on the following patches:
>
> "battery: Add the battery hooking API"

Sorry, didn't notice earlier some things commented below.

>  #include <acpi/video.h>
>
> +
>  /* ThinkPad CMOS commands */

Redundant change.

> +enum {
> +       /* Error condition bit */
> +       METHOD_ERR = (1 << 31),

bitops.h but no BIT() use?

BIT(31) ?

> +};

> +static int tpacpi_battery_set(int what, int battery, int value)
> +{

> +

Redundant.

> +       int param = 0x0, ret = 0xFFFFFFFF;

Useless assignment for param, not sure abour ret.

> +
> +       /* The first 8 bits are the value of the threshold */
> +       param = value;
> +       /* The battery ID is in bits 8-9, 2 bits */
> +       param |= battery << 8;
> +
> +       switch (what) {
> +
> +       case THRESHOLD_START:
> +
> +               if (tpacpi_battery_acpi_eval(SET_START, &ret, param)) {
> +                       pr_err("failed to set charge threshold on battery
%d",
> +                                       battery);
> +                       return -ENODEV;
> +               }
> +
> +               return 0;
> +
> +       case THRESHOLD_STOP:
> +
> +               if (tpacpi_battery_acpi_eval(SET_STOP, &ret, param)) {
> +                       pr_err("failed to set charge stop threshold: %d",
battery);
> +                       return -ENODEV;
> +               }
> +
> +               return 0;
> +
> +       default:
> +               pr_crit("wrong parameter: %d", what);
> +               return -EINVAL;
> +       }

> +

Redundant.

> +}

> +
> +static int tpacpi_battery_probe(int battery)
> +{
> +       int ret = 0;
> +

> +       /* Reset the struct */

Useless.

> +       memset(&battery_info, 0, sizeof(struct
tpacpi_battery_driver_data));

> +}

> +static ssize_t tpacpi_battery_store(struct device *dev,
> +                                  struct device_attribute *devattr,
> +                                  const char *buf, size_t count)
> +{
> +       int attr, battery;
> +       unsigned long value;
> +       struct power_supply *supply = to_power_supply(dev);

Can you use reverse xmas tree, esp. put assignments first.

> +       if (!supply) {

How this could be possible?!

> +               pr_err("Can't upcast to power_supply!");
> +               return -ENODEV;
> +       }

> +       if (kstrtoul(buf, 10, &value))
> +               return -EINVAL;

Don't shadow an error code from kstrtoul().

> +static ssize_t tpacpi_battery_show(struct device *dev,
> +                                 struct device_attribute *devattr,
> +                                 char *buf)
> +{
> +       int ret = 0x0, attr, battery;
> +       struct power_supply *supply = to_power_supply(dev);

> +       if (!supply) {

How this could be possible?!

> +               pr_crit("Can't upcast to power_supply!");
> +               return -ENODEV;
> +       }

> +       return sprintf(buf, "%d\n", ret);
> +}
> +
> +DEVICE_ATTR(charge_start_threshold, 0644,
> +               tpacpi_battery_show, tpacpi_battery_store);
> +DEVICE_ATTR(charge_stop_threshold, 0644,
> +       tpacpi_battery_show, tpacpi_battery_store);

DEVICE_ATTR_RW().


I did not use DEVICE_ATTR_RW() because I can't use a common store and show
function for both attributes to minimize the code I need. If I used
DEVICE_ATTR_RW() I would need to define 4 more functions that do the same.
That seems redundant.


> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -371,6 +371,8 @@ devm_power_supply_register_no_ws(struct device
*parent,
>  extern void power_supply_unregister(struct power_supply *psy);
>  extern int power_supply_powers(struct power_supply *psy, struct device
*dev);
>
> +#define to_power_supply(device) container_of(device, struct
power_supply, dev)
> +
>  extern void *power_supply_get_drvdata(struct power_supply *psy);
>  /* For APM emulation, think legacy userspace. */
>  extern struct class *power_supply_class;

This one sounds to me as a separate change.

At the same time you may convert the current user of it to make sense
of the change.
drivers/power/supply/power_supply_core.c:671:

I think I pointed to this out once.


I wanted to minimize the changes in pm to avoid going through all the
review process hassle for a few simple changes, because I'm modifying a
third subsystem. But I will do it later tonight.

This is my first patchset and I did not expect for the review process to be
this agonizingly slow, so I wanted to speed it up by not touching pm.

Thanks for the comments!

Ognjen


--
With Best Regards,
Andy Shevchenko

[-- Attachment #1.2: Type: text/html, Size: 8499 bytes --]

[-- Attachment #2: Type: text/plain, Size: 202 bytes --]

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
ibm-acpi-devel mailing list
ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/ibm-acpi-devel

  parent reply	other threads:[~2017-12-21 15:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 10:00 [PATCH 2/3 v8] thinkpad_acpi: Add support for battery thresholds Ognjen Galic
2017-12-21 13:53 ` Andy Shevchenko
2017-12-21 13:53   ` [Devel] " Andy Shevchenko
     [not found]   ` <CAHp75Vc2MYDLanvZmqaPkmFVfNbyBQoPwbRDDFmKDtSPAmfj9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-12-21 15:24     ` Ognjen Galić [this message]
2017-12-21 17:08       ` Andy Shevchenko
2017-12-21 17:08         ` [Devel] " Andy Shevchenko

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=CALgTWSvnyBysDJqGFwCxB43wgzMAAUqYZ2M5r8-L9ZdJ9J4XxQ@mail.gmail.com \
    --to=smclt30p-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=andy-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=christoph-KeW1gJXA36yNJhrcwGid2A@public.gmane.org \
    --cc=devel-E0kO6a4B6psdnm+yROfE0A@public.gmane.org \
    --cc=dvhart-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=ibm-acpi-N3TV7GIv+o9fyO9Q7EP/yw@public.gmane.org \
    --cc=ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=kevin-yFOG++GfaLUI8/NkjqMgMw@public.gmane.org \
    --cc=lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lv.zheng-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=platform-driver-x86-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=rafael-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org \
    --cc=robert.moore-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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 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.