From: "Andrew F. Davis" <afd@ti.com>
To: Liam Breck <liam@networkimprov.net>, Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org,
Matt Ranostay <matt@ranostay.consulting>,
Liam Breck <kernel@networkimprov.net>
Subject: Re: [PATCH v8 7/9] power: bq27xxx_battery: Add power_supply_battery_info support
Date: Fri, 3 Mar 2017 15:51:41 -0600 [thread overview]
Message-ID: <3690ab9c-ea76-1b18-b51c-8ed6c165bf43@ti.com> (raw)
In-Reply-To: <CAKvHMgQCfVK5k1-HU4UjT4oxOYDXU2LP7UaApNHZ8_NXM94How@mail.gmail.com>
On 03/03/2017 03:36 PM, Liam Breck wrote:
> Hi Andrew,
>
> On Sun, Feb 26, 2017 at 11:11 PM, Liam Breck <liam@networkimprov.net> 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 | 458 ++++++++++++++++++++++++++++++++-
>> 1 file changed, 456 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
>> index 7475a5f..41d4ce7 100644
>> --- a/drivers/power/supply/bq27xxx_battery.c
>> +++ b/drivers/power/supply/bq27xxx_battery.c
>
>> @@ -452,6 +508,81 @@ static struct {
>> static DEFINE_MUTEX(bq27xxx_list_lock);
>> static LIST_HEAD(bq27xxx_battery_devices);
>>
>> +#define BQ27XXX_DM_SZ 32
>> +
>> +#define BQ27XXX_MSLEEP(i) usleep_range((i)*1000, (i)*1000+500)
>> +
>> +struct bq27xxx_dm_reg {
>> + u8 subclass_id;
>> + u8 offset;
>> + u8 bytes;
>> + u16 min, max;
>> +};
>> +
>> +struct bq27xxx_dm_buf {
>> + u8 class;
>> + u8 block;
>> + u8 a[BQ27XXX_DM_SZ];
>> + bool full, updt;
>> +};
>> +
>> +#define BQ27XXX_DM_BUF(di, i) { \
>> + .class = bq27xxx_dm_regs[(di)->chip][i].subclass_id, \
>> + .block = bq27xxx_dm_regs[(di)->chip][i].offset / BQ27XXX_DM_SZ, \
>> +}
>> +
>> +static inline u16* bq27xxx_dm_buf_ptr(struct bq27xxx_dm_buf *buf,
>> + struct bq27xxx_dm_reg *reg) {
>> + if (buf->class == reg->subclass_id
>> + && buf->block == reg->offset / BQ27XXX_DM_SZ)
>> + return (u16*) (buf->a + reg->offset % BQ27XXX_DM_SZ);
>> +
>> + return NULL;
>> +}
>> +
>> +enum bq27xxx_dm_reg_id {
>> + BQ27XXX_DM_DESIGN_CAPACITY = 0,
>> + BQ27XXX_DM_DESIGN_ENERGY,
>> + BQ27XXX_DM_TERMINATE_VOLTAGE,
>> +};
>> +
>> +static const char* bq27xxx_dm_reg_name[] = {
>> + [BQ27XXX_DM_DESIGN_CAPACITY] = "design-capacity",
>> + [BQ27XXX_DM_DESIGN_ENERGY] = "design-energy",
>> + [BQ27XXX_DM_TERMINATE_VOLTAGE] = "terminate-voltage",
>> +};
>> +
>> +static struct bq27xxx_dm_reg bq27425_dm_regs[] = {
>> + [BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 12, 2, 0, 32767 },
>> + [BQ27XXX_DM_DESIGN_ENERGY] = { 82, 14, 2, 0, 32767 },
>> + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 18, 2, 2800, 3700 },
>> +};
>> +
>> +static struct bq27xxx_dm_reg bq27421_dm_regs[] = { /* not tested */
>> + [BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 10, 2, 0, 8000 },
>> + [BQ27XXX_DM_DESIGN_ENERGY] = { 82, 12, 2, 0, 32767 },
>> + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 16, 2, 2500, 3700 },
>> +};
>> +
>> +//static struct bq27xxx_dm_reg bq27621_dm_regs[] = { /* not tested */
>> +// [BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 3, 2, 0, 8000 },
>> +// [BQ27XXX_DM_DESIGN_ENERGY] = { 82, 5, 2, 0, 32767 },
>> +// [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 9, 2, 2500, 3700 },
>> +//};
>> +
>> +static struct bq27xxx_dm_reg *bq27xxx_dm_regs[] = {
>> + [BQ27421] = bq27421_dm_regs, /* and BQ27441 */
>> + [BQ27425] = bq27425_dm_regs,
>> +// [BQ27621] = bq27621_dm_regs,
>> +};
>> +
>> +static u32 bq27xxx_unseal_keys[] = {
>> + [BQ27421] = 0x80008000, /* and BQ27441 */
>> + [BQ27425] = 0x04143672,
>> +// [BQ27621] = 0x80008000,
>> +};
>
> Maybe instead of defining dm_regs_* tables for many chips in this
> file, we should land them in a new header, to let the kernel builder
> define and/or pick one for his platform by setting a config option,
> e.g. config_bq27xxx_dm_type=421
>
Size isn't really an issue, we build drivers for parts we may not have,
you should be able to add a part to a system and only change the DT. So
supporting all these chips is okay.
> We could also pull in the dm update code if such an option is defined,
> tho it isn't that much code, ~230 lines plus whitespace.
>
We can have a config option to enable support for DM update, if it can
be factored out in such a way. Otherwise if someone uses it, just
include it for everyone, if they need it it's there, if they don't then
no harm done.
> Thoughts?
>
next prev parent reply other threads:[~2017-03-03 21:51 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 7:11 [PATCH v8 0/9] devicetree battery support and client bq27xxx_battery Liam Breck
2017-02-27 7:11 ` [PATCH v8 2/9] devicetree: property-units: Add uWh and uAh units Liam Breck
[not found] ` <20170227071117.18934-1-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-02-27 7:11 ` [PATCH v8 1/9] devicetree: power: Add battery.txt Liam Breck
[not found] ` <20170227071117.18934-2-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-03-02 15:14 ` Rob Herring
2017-03-02 18:31 ` Liam Breck
2017-03-15 20:10 ` Rob Herring
[not found] ` <CAL_Jsq+8Y=GtyjVZA-suZLH+ySDshaoU9qh96BF+PeUYK3FZxg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15 22:04 ` Liam Breck
2017-03-15 23:50 ` Rob Herring
[not found] ` <CAL_JsqJOFUSRY_KPzwNWrx4FF1_F6XNK8OfkqhqgBpxH9WrZeQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-16 6:45 ` Liam Breck
2017-03-16 13:31 ` Andrew F. Davis
[not found] ` <bb0928ce-6d29-3d09-2c5b-f4a084fe06e9-l0cyMroinI0@public.gmane.org>
2017-03-16 14:07 ` Liam Breck
[not found] ` <CAKvHMgQujE4uYNt0vPkt6qUOtVqdvzXs0zXTkDVRq9YLNvunBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-18 20:34 ` Rob Herring
2017-02-27 7:11 ` [PATCH v8 3/9] devicetree: power: bq27xxx: Add monitored-battery documentation Liam Breck
[not found] ` <20170227071117.18934-4-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-03-02 15:16 ` Rob Herring
2017-02-27 7:11 ` [PATCH v8 4/9] power: power_supply: Add power_supply_battery_info and API Liam Breck
2017-02-27 7:11 ` [PATCH v8 5/9] power: bq27xxx_battery: Define access methods to write chip registers Liam Breck
2017-02-27 7:11 ` [PATCH v8 6/9] power: bq27xxx_battery: Add BQ27425 chip id Liam Breck
2017-02-27 16:28 ` Andrew F. Davis
2017-02-27 7:11 ` [PATCH v8 7/9] power: bq27xxx_battery: Add power_supply_battery_info support Liam Breck
2017-02-27 18:06 ` Andrew F. Davis
2017-02-27 20:05 ` Liam Breck
2017-02-27 21:21 ` Andrew F. Davis
2017-02-27 21:35 ` Liam Breck
2017-02-27 21:47 ` Andrew F. Davis
2017-02-27 22:14 ` Liam Breck
2017-02-27 22:37 ` Liam Breck
2017-03-01 23:09 ` Liam Breck
2017-03-03 21:36 ` Liam Breck
2017-03-03 21:51 ` Andrew F. Davis [this message]
2017-03-03 22:04 ` Liam Breck
2017-03-03 22:07 ` Andrew F. Davis
2017-03-03 22:13 ` Liam Breck
2017-03-06 16:42 ` Andrew F. Davis
2017-03-06 20:14 ` Liam Breck
2017-02-27 7:11 ` [PATCH v8 8/9] power: bq27xxx_battery: Add print_dm_blocks() to log chip memory Liam Breck
2017-02-27 18:07 ` Andrew F. Davis
2017-02-27 7:11 ` [PATCH v8 9/9] power: bq27xxx_battery_i2c: Add I2C bulk read/write functions Liam Breck
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=3690ab9c-ea76-1b18-b51c-8ed6c165bf43@ti.com \
--to=afd@ti.com \
--cc=kernel@networkimprov.net \
--cc=liam@networkimprov.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox