All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liam Breck <liam@networkimprov.net>
To: Sebastian Reichel <sre@kernel.org>
Cc: "Andrew F. Davis" <afd@ti.com>,
	linux-pm@vger.kernel.org,
	Matt Ranostay <matt@ranostay.consulting>,
	Liam Breck <kernel@networkimprov.net>
Subject: Re: [PATCH v10 8/8] power: bq27xxx_battery_i2c: Add I2C bulk read/write functions
Date: Wed, 15 Mar 2017 15:34:23 -0700	[thread overview]
Message-ID: <CAKvHMgSuvFjD39nv9cfkEs4U+79F=K_DBuBPcAqqvDejszeGfQ@mail.gmail.com> (raw)
In-Reply-To: <20170315221414.mcig3c6bp44bitcu@earth>

On Wed, Mar 15, 2017 at 3:14 PM, Sebastian Reichel <sre@kernel.org> wrote:
> Hi,
>
> On Wed, Mar 15, 2017 at 12:26:53PM -0700, Liam Breck wrote:
>> From: Matt Ranostay <matt@ranostay.consulting>
>>
>> write(), read_bulk(), write_bulk() are required by bq27xxx_battery
>> power_supply_battery_info code.
>>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> Signed-off-by: Liam Breck <kernel@networkimprov.net>
>
> This is required by the previous patch, so your order is not bisect
> safe. Please just merge it with Patch 5.

It is bisect-safe; bq27xxx_battery only uses the functions if available.

Patch 5 could be merged with 7. But the I2C implementation should be
separate from the header.

>>  drivers/power/supply/bq27xxx_battery_i2c.c | 82 +++++++++++++++++++++++++++++-
>>  1 file changed, 81 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
>> index 13def59..abdc266 100644
>> --- a/drivers/power/supply/bq27xxx_battery_i2c.c
>> +++ b/drivers/power/supply/bq27xxx_battery_i2c.c
>> @@ -38,7 +38,7 @@ static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg,
>>  {
>>       struct i2c_client *client = to_i2c_client(di->dev);
>>       struct i2c_msg msg[2];
>> -     unsigned char data[2];
>> +     u8 data[2];
>>       int ret;
>>
>>       if (!client->adapter)
>> @@ -68,6 +68,82 @@ static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg,
>>       return ret;
>>  }
>>
>> +static int bq27xxx_battery_i2c_write(struct bq27xxx_device_info *di, u8 reg,
>> +                                  int value, bool single)
>> +{
>> +     struct i2c_client *client = to_i2c_client(di->dev);
>> +     struct i2c_msg msg;
>> +     u8 data[4];
>> +     int ret;
>> +
>> +     if (!client->adapter)
>> +             return -ENODEV;
>> +
>> +     data[0] = reg;
>> +     if (single) {
>> +             data[1] = (u8) value;
>> +             msg.len = 2;
>> +     } else {
>> +             put_unaligned_le16(value, &data[1]);
>> +             msg.len = 3;
>> +     }
>> +
>> +     msg.buf = data;
>> +     msg.addr = client->addr;
>> +     msg.flags = 0;
>> +
>> +     ret = i2c_transfer(client->adapter, &msg, 1);
>> +     if (ret < 0)
>> +             return ret;
>> +     if (ret != 1)
>> +             return -EINVAL;
>> +     return 0;
>> +}
>> +
>> +static int bq27xxx_battery_i2c_bulk_read(struct bq27xxx_device_info *di, u8 reg,
>> +                                      u8 *data, int len)
>> +{
>> +     struct i2c_client *client = to_i2c_client(di->dev);
>> +     int ret;
>> +
>> +     if (!client->adapter)
>> +             return -ENODEV;
>> +
>> +     ret = i2c_smbus_read_i2c_block_data(client, reg, len, data);
>> +     if (ret < 0)
>> +             return ret;
>> +     if (ret != len)
>> +             return -EINVAL;
>> +     return 0;
>> +}
>> +
>> +static int bq27xxx_battery_i2c_bulk_write(struct bq27xxx_device_info *di,
>> +                                       u8 reg, u8 *data, int len)
>> +{
>> +     struct i2c_client *client = to_i2c_client(di->dev);
>> +     struct i2c_msg msg;
>> +     u8 buf[33];
>> +     int ret;
>> +
>> +     if (!client->adapter)
>> +             return -ENODEV;
>> +
>> +     buf[0] = reg;
>> +     memcpy(&buf[1], data, len);
>> +
>> +     msg.buf = buf;
>> +     msg.addr = client->addr;
>> +     msg.flags = 0;
>> +     msg.len = len + 1;
>> +
>> +     ret = i2c_transfer(client->adapter, &msg, 1);
>> +     if (ret < 0)
>> +             return ret;
>> +     if (ret != 1)
>> +             return -EINVAL;
>> +     return 0;
>> +}
>> +
>>  static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
>>                                    const struct i2c_device_id *id)
>>  {
>> @@ -95,7 +171,11 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
>>       di->dev = &client->dev;
>>       di->chip = id->driver_data;
>>       di->name = name;
>> +
>>       di->bus.read = bq27xxx_battery_i2c_read;
>> +     di->bus.write = bq27xxx_battery_i2c_write;
>> +     di->bus.read_bulk = bq27xxx_battery_i2c_bulk_read;
>> +     di->bus.write_bulk = bq27xxx_battery_i2c_bulk_write;
>>
>>       ret = bq27xxx_battery_setup(di);
>>       if (ret)
>> --
>> 2.9.3
>>

  reply	other threads:[~2017-03-15 22:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 19:26 [PATCH v10 0/8] devicetree battery support and client bq27xxx_battery Liam Breck
2017-03-15 19:26 ` [PATCH v10 2/8] devicetree: property-units: Add uWh and uAh units Liam Breck
     [not found] ` <20170315192653.26799-1-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-03-15 19:26   ` [PATCH v10 1/8] devicetree: power: Add battery.txt Liam Breck
2017-03-15 22:04     ` Sebastian Reichel
2017-03-15 22:18       ` Liam Breck
2017-03-15 22:57         ` Sebastian Reichel
2017-03-16 13:21           ` Andrew F. Davis
2017-03-16 22:58             ` Liam Breck
2017-03-17 15:21               ` Andrew F. Davis
2017-03-17 21:43                 ` Liam Breck
     [not found]                   ` <CAKvHMgS92WFoJa=imfAFiEEc0VyiSsDBbuYi4yzZ=LEa7__yKA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-20 16:45                     ` Andrew F. Davis
2017-03-20 18:26                       ` Liam Breck
2017-03-15 19:26   ` [PATCH v10 3/8] devicetree: power: bq27xxx: Add monitored-battery documentation Liam Breck
     [not found]     ` <20170315192653.26799-4-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-03-15 22:06       ` Sebastian Reichel
2017-03-15 19:26 ` [PATCH v10 4/8] power: power_supply: Add power_supply_battery_info and API Liam Breck
2017-03-15 22:07   ` Sebastian Reichel
2017-03-15 19:26 ` [PATCH v10 5/8] power: bq27xxx_battery: Define access methods to write chip registers Liam Breck
2017-03-15 19:26 ` [PATCH v10 6/8] power: bq27xxx_battery: Keep track of specific chip id Liam Breck
2017-03-16 14:44   ` Andrew F. Davis
2017-03-16 20:12     ` Liam Breck
2017-03-16 20:50       ` Andrew F. Davis
2017-03-16 21:26         ` Liam Breck
2017-03-16 21:30           ` Andrew F. Davis
2017-03-16 21:47             ` Liam Breck
2017-03-16 21:53               ` Andrew F. Davis
2017-03-16 22:38                 ` Liam Breck
2017-03-15 19:26 ` [PATCH v10 7/8] power: bq27xxx_battery: Add power_supply_battery_info support Liam Breck
2017-03-16 15:00   ` Andrew F. Davis
2017-03-16 21:12     ` Liam Breck
2017-03-16 21:39       ` Andrew F. Davis
2017-03-16 22:31         ` Liam Breck
2017-03-15 19:26 ` [PATCH v10 8/8] power: bq27xxx_battery_i2c: Add I2C bulk read/write functions Liam Breck
2017-03-15 22:14   ` Sebastian Reichel
2017-03-15 22:34     ` Liam Breck [this message]
2017-03-15 23:03       ` Sebastian Reichel

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='CAKvHMgSuvFjD39nv9cfkEs4U+79F=K_DBuBPcAqqvDejszeGfQ@mail.gmail.com' \
    --to=liam@networkimprov.net \
    --cc=afd@ti.com \
    --cc=kernel@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 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.