From: Sebastian Reichel <sre@kernel.org>
To: Matt Ranostay <matt@ranostay.consulting>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, tony@atomide.com
Subject: Re: [PATCH v4 6/8] power: bq27xxx_battery: add i2c bulk read/write functions
Date: Sun, 29 Jan 2017 19:38:26 +0100 [thread overview]
Message-ID: <20170129183826.cyysprznipidkttb@earth> (raw)
In-Reply-To: <20170122071404.9654-7-matt@ranostay.consulting>
[-- Attachment #1: Type: text/plain, Size: 3938 bytes --]
Hi,
On Sat, Jan 21, 2017 at 11:14:02PM -0800, Matt Ranostay wrote:
> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> ---
> drivers/power/supply/bq27xxx_battery_i2c.c | 62 ++++++++++++++++++++++++++++++
> include/linux/power/bq27xxx_battery.h | 4 ++
> 2 files changed, 66 insertions(+)
>
> diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
> index 2ea2d0b06948..feeb04ed88c8 100644
> --- a/drivers/power/supply/bq27xxx_battery_i2c.c
> +++ b/drivers/power/supply/bq27xxx_battery_i2c.c
> @@ -68,6 +68,64 @@ 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;
> + unsigned char data[4];
> +
> + if (!client->adapter)
> + return -ENODEV;
> +
> + data[0] = reg;
> + if (single) {
> + data[1] = (unsigned char) value;
> + msg.len = 2;
> + } else {
> + put_unaligned_le16(value, &data[1]);
> + msg.len = 3;
> + }
> +
> + msg.buf = data;
> + msg.addr = client->addr;
> + msg.flags = 0;
> +
> + return i2c_transfer(client->adapter, &msg, 1) == 1 ? 0 : -EINVAL;
> +}
> +
> +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);
> +
> + if (!client->adapter)
> + return -ENODEV;
> +
> + return i2c_smbus_read_i2c_block_data(client, reg, len, data);
> +}
> +
> +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];
> +
> + 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;
> +
> + return i2c_transfer(client->adapter, &msg, 1) == 1 ? 0 : -EINVAL;
> +}
> +
> static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -95,7 +153,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)
> diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h
> index 3f265dbf11af..581402380d6e 100644
> --- a/include/linux/power/bq27xxx_battery.h
> +++ b/include/linux/power/bq27xxx_battery.h
> @@ -41,6 +41,9 @@ struct bq27xxx_platform_data {
> struct bq27xxx_device_info;
> struct bq27xxx_access_methods {
> int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single);
> + int (*write)(struct bq27xxx_device_info *di, u8 reg, int value, bool single);
> + int (*read_bulk)(struct bq27xxx_device_info *di, u8 reg, u8 *data, int len);
> + int (*write_bulk)(struct bq27xxx_device_info *di, u8 reg, u8 *data, int len);
So I had a look at patch 8 and I think we should start with finally
converting bq27xxx to regmap API and probably a second regmap for
the block data stuff. That way you get all the debugging info in
debugfs and the driver looks much cleaner.
> };
>
> struct bq27xxx_reg_cache {
> @@ -71,6 +74,7 @@ struct bq27xxx_device_info {
> struct list_head list;
> struct mutex lock;
> u8 *regs;
> + u8 buffer[32];
unrelated change.
> };
>
> void bq27xxx_battery_update(struct bq27xxx_device_info *di);
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-01-29 18:38 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-22 7:13 [PATCH v4 0/8] power: bq27xxx: add support for NVRAM R/W access Matt Ranostay
2017-01-22 7:13 ` [PATCH v4 1/8] devicetree: property-units: add mWh and mAh units Matt Ranostay
2017-01-23 17:50 ` Rob Herring
2017-01-22 7:13 ` [PATCH v4 2/8] devicetree: power: add battery state machine documentation Matt Ranostay
2017-01-22 22:22 ` Liam Breck
2017-01-24 19:56 ` Liam Breck
[not found] ` <CAKvHMgS9ZxE2qxDqeAVRJFzerjkJV=io58aQjtU51j=kFzbYtw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-29 17:27 ` Sebastian Reichel
2017-01-26 6:19 ` Liam Breck
2017-01-26 7:02 ` Matt Ranostay
2017-01-29 17:20 ` Sebastian Reichel
2017-01-29 23:22 ` Liam Breck
2017-01-30 2:30 ` Sebastian Reichel
2017-01-30 10:54 ` Liam Breck
[not found] ` <CAKvHMgQi1tRyUXh0504rP8VUVkFVPt_4NnYTOrBXeO4dde6KMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-30 21:40 ` Liam Breck
[not found] ` <20170122222212.27086-1-liam-RYWXG+zxWwBdeoIcmNTgJF6hYfS7NtTn@public.gmane.org>
2017-01-29 18:06 ` Sebastian Reichel
2017-01-29 23:32 ` Liam Breck
[not found] ` <CAKvHMgTrFjjEWwK-NeGOF1o6KRQPXYUvcqWcDwaW+5ZKjQ7VZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-30 2:39 ` Sebastian Reichel
2017-01-30 2:46 ` Liam Breck
2017-01-31 20:59 ` Liam Breck
[not found] ` <20170122071404.9654-1-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-22 7:13 ` [PATCH v4 3/8] power: power_supply: add battery information struct Matt Ranostay
[not found] ` <20170122071404.9654-4-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-29 18:23 ` Sebastian Reichel
2017-01-22 7:14 ` [PATCH v4 4/8] power: power_supply: add battery info platform data retrieval Matt Ranostay
[not found] ` <20170122071404.9654-5-matt-sk+viVC6FLCDq+mSdOJa79kegs52MxvZ@public.gmane.org>
2017-01-29 18:28 ` Sebastian Reichel
2017-01-22 7:14 ` [PATCH v4 5/8] power: bq27xxx_battery: add BQ27425 chip id Matt Ranostay
2017-01-22 7:14 ` [PATCH v4 7/8] devicetree: power: bq27xxx: add monitored battery documentation Matt Ranostay
2017-01-22 7:14 ` [PATCH v4 6/8] power: bq27xxx_battery: add i2c bulk read/write functions Matt Ranostay
2017-01-29 18:38 ` Sebastian Reichel [this message]
2017-01-22 7:14 ` [PATCH v4 8/8] power: bq27xxx_battery: add initial state machine support Matt Ranostay
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=20170129183826.cyysprznipidkttb@earth \
--to=sre@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=matt@ranostay.consulting \
--cc=tony@atomide.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).