All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liam Breck <liam@networkimprov.net>
To: "Andrew F. Davis" <afd@ti.com>
Cc: Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org,
	Matt Ranostay <matt@ranostay.consulting>
Subject: Re: [PATCH v7 7/9] power: bq27xxx_battery: Add power_supply_battery_info support
Date: Thu, 23 Feb 2017 08:38:37 -0800	[thread overview]
Message-ID: <CAKvHMgTfWJCW2vDsGf3anW2Day_nGDOaR0PyC3OAk=ZR_LFS9A@mail.gmail.com> (raw)
In-Reply-To: <3e407e80-3c35-5a16-5e0c-503cec5fe70f@ti.com>

On Thu, Feb 23, 2017 at 8:08 AM, Andrew F. Davis <afd@ti.com> wrote:
> On 02/23/2017 09:49 AM, Liam Breck wrote:
>> On Thu, Feb 23, 2017 at 7:17 AM, Andrew F. Davis <afd@ti.com> wrote:
>>> On 02/22/2017 06:54 PM, Liam Breck wrote:
>>>> On Wed, Feb 22, 2017 at 4:30 PM, Andrew F. Davis <afd@ti.com> wrote:
>>>>> On 02/22/2017 03:29 PM, Liam Breck wrote:
>>>>>> On Wed, Feb 22, 2017 at 12:35 PM, Andrew F. Davis <afd@ti.com> wrote:
>>>>>>> On 02/21/2017 03:30 PM, Liam Breck wrote:
>>>>>>>> From: Liam Breck <kernel@networkimprov.net>
>>>>>>>>
>>>>>>>> Previously there was no way to configure chip registers in the event that the
>>>>>>>> defaults didn't match the battery in question.
>>>>>>>>
>>>>>>>> BQ27xxx driver now calls power_supply_get_battery_info, checks the inputs,
>>>>>>>> and writes battery data to chip RAM or non-volatile memory.
>>>>>>>>
>>>>>>>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>>>>>>>> Signed-off-by: Liam Breck <kernel@networkimprov.net>
>>>>>>>> ---
>>>>>>>>  drivers/power/supply/bq27xxx_battery.c | 399 ++++++++++++++++++++++++++++++++-
>>>>>>>>  1 file changed, 397 insertions(+), 2 deletions(-)
>>>>>>>>
>>>>>>>> diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
>>>>>>>> index 7475a5f..8085d4a 100644
>>>>>>>> --- a/drivers/power/supply/bq27xxx_battery.c
>>>>>>>> +++ b/drivers/power/supply/bq27xxx_battery.c
>>>>>>>> @@ -51,7 +51,7 @@
>>>>>>>>
>>>>>>>>  #include <linux/power/bq27xxx_battery.h>
>>>>>>>>
>>>>>>>> -#define DRIVER_VERSION               "1.2.0"
>>>>>>>> +#define DRIVER_VERSION               "1.3.0"
>>>>>>>>
>>>>>>>>  #define BQ27XXX_MANUFACTURER "Texas Instruments"
>>>>>>>>
>>>>>>>> @@ -452,6 +452,99 @@ static struct {
>>>>>>>>  static DEFINE_MUTEX(bq27xxx_list_lock);
>>>>>>>>  static LIST_HEAD(bq27xxx_battery_devices);
>>>>>>>>
>>>>>>>> +/* writable registers */
>>>>>>>> +#define BQ27XXX_CONTROL                      0x00
>>>>>>>> +#define BQ27XXX_DATA_CLASS           0x3E
>>>>>>>> +#define BQ27XXX_DATA_BLOCK           0x3F
>>>>>>>> +#define BQ27XXX_BLOCK_DATA           0x40
>>>>>>>> +#define BQ27XXX_BLOCK_DATA_CHECKSUM  0x60
>>>>>>>> +#define BQ27XXX_BLOCK_DATA_CONTROL   0x61
>>>>>>>> +
>>>>>>>
>>>>>>> These all belong in the bq27xxx_regs array, you can add new register
>>>>>>> types to the bq27xxx_reg_index enum.
>>>>>>
>>>>>> They're the same on all chips. Let's dup this code 9+ times when we have cause.
>>>>>>
>>>>>
>>>>> They are not the same on all chips, some chips don't have these
>>>>> registers at all. Plus, BQ27XXX_CONTROL is the same for all chips, and
>>>>> we already have it in all the chips bq27xxx_regs.
>>>>
>>>> Datasheets? Do those chips even support this feature set? Bqtool
>>>> doesn't appear to support any other memory update scheme.
>>>>
>>>
>>> Many chips don't, which is why we don't want these registers being
>>> global defines, you can have the chips without these registers as
>>> INVALID_REG_ADDR
>>
>> Chips that don't support memory update won't have a bq27xxx_dm_regs
>> list; we look for that at the start of this code path and do nothing
>> if it's null for di->chip. All chips that do support memory update use
>> the same command registers, so there's no reason to dup those.
>>
>
> Someday they might use a different value, we don't lose anything by
> putting these device registers in the table with the other device
> registers. I would rather duplicate some lines if it makes the code more
> uniform and easier to follow, again this is not a contest, we write code
> for ourselves, let the compiler organize/optimize things.

I prefer the principle that every line you write must have a purpose
in the current codebase, vs a future one. But if you are adamant, I
capitulate.

>> Also you can delete REG_CTRL as it's not used by the existing code  :-)
>>
>
> True, but as before, I just like having the complete register set in a
> nice simple table, as opposed to having to add and change things all
> over if/when we may need that register.
>
> Being a static table, I wonder if a sufficiently smart compiler could
> see that it is not used and optimize the value out for us...

No :-p All the compiler can do for unused data is issue a warning. And
it can't do so for array elements.

You really should define those tables in a function which memcpy's the
right one onto di.regs.

>>>>>> Or make a default array of reg numbers and memcopy it onto each chip
>>>>>> array, then alter as req'd per chip. But that's outside our scope.
>>>>>>
>>>>>>>> +/* control register params */
>>>>>>>> +#define BQ27XXX_SEALED                       0x20
>>>>>>>> +#define BQ27XXX_SET_CFGUPDATE                0x13
>>>>>>>> +#define BQ27XXX_SOFT_RESET           0x42
>>>>>>>> +
>>>>>>>> +#define BQ27XXX_MSLEEP(i) usleep_range((i)*1000, (i)*1000+500)
>>>>>>>

  reply	other threads:[~2017-02-23 16:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 21:29 [PATCH v7 0/9] devicetree battery support and client bq27xxx_battery Liam Breck
     [not found] ` <20170221213008.30044-1-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-02-21 21:30   ` [PATCH v7 1/9] devicetree: power: Add battery.txt Liam Breck
     [not found]     ` <20170221213008.30044-2-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-02-22 20:05       ` Andrew F. Davis
     [not found]         ` <bd747560-8780-3294-86dd-f7f7f4de1736-l0cyMroinI0@public.gmane.org>
2017-02-22 21:39           ` Liam Breck
2017-02-21 21:30   ` [PATCH v7 3/9] devicetree: power: bq27xxx: Add monitored-battery documentation Liam Breck
2017-02-21 21:30 ` [PATCH v7 2/9] devicetree: property-units: Add uWh and uAh units Liam Breck
2017-02-21 21:30   ` Liam Breck
2017-02-21 21:30 ` [PATCH v7 4/9] power: power_supply: Add power_supply_battery_info and API Liam Breck
2017-02-21 21:30 ` [PATCH v7 5/9] power: bq27xxx_battery: Define access methods to write chip registers Liam Breck
2017-02-21 21:30 ` [PATCH v7 6/9] power: bq27xxx_battery: Add BQ27425 chip id Liam Breck
2017-02-22 20:15   ` Andrew F. Davis
2017-02-21 21:30 ` [PATCH v7 7/9] power: bq27xxx_battery: Add power_supply_battery_info support Liam Breck
2017-02-22 20:35   ` Andrew F. Davis
2017-02-22 21:29     ` Liam Breck
2017-02-23  0:30       ` Andrew F. Davis
2017-02-23  0:54         ` Liam Breck
2017-02-23 15:17           ` Andrew F. Davis
2017-02-23 15:49             ` Liam Breck
2017-02-23 16:08               ` Andrew F. Davis
2017-02-23 16:38                 ` Liam Breck [this message]
2017-02-23 16:53                   ` Andrew F. Davis
2017-02-23 17:36                     ` Liam Breck
2017-02-23 18:02                       ` Andrew F. Davis
2017-02-23 21:28                         ` Liam Breck
2017-02-24 14:51                           ` Andrew F. Davis
2017-02-23 21:15     ` Liam Breck
2017-02-24 14:47       ` Andrew F. Davis
2017-02-21 21:30 ` [PATCH v7 8/9] power: bq27xxx_battery: Add print_dm() to log chip memory Liam Breck
2017-02-22 20:39   ` Andrew F. Davis
2017-02-22 21:36     ` Liam Breck
2017-02-23  0:34       ` Andrew F. Davis
2017-02-21 21:30 ` [PATCH v7 9/9] power: bq27xxx_battery_i2c: Add I2C bulk read/write functions Liam Breck
2017-03-02 22:52 ` [PATCH v7 0/9] devicetree battery support and client bq27xxx_battery Liam Breck
2017-03-02 23:04   ` Andrew F. Davis

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='CAKvHMgTfWJCW2vDsGf3anW2Day_nGDOaR0PyC3OAk=ZR_LFS9A@mail.gmail.com' \
    --to=liam@networkimprov.net \
    --cc=afd@ti.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=matt@ranostay.consulting \
    --cc=sre@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 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.