The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: 남관우 <kw46.nam@samsung.com>
To: cbou@mail.ru, dwmw2@infradead.org, linux-kernel@vger.kernel.org
Cc: kw46.nam@samsung.com, kyungmin.park@samsung.com
Subject: [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal registers
Date: Mon, 21 Oct 2013 17:48:35 +0900	[thread overview]
Message-ID: <002101cece3a$53eeff80$fbccfe80$%nam@samsung.com> (raw)

We use regmap to interface with internal registers in fuel guague MAX17040.

Signed-off-by: Nam KwanWoo <kw46.nam@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/power/max17040_battery.c |   71 +++++++++++++++++------------------
---
 1 file changed, 32 insertions(+), 39 deletions(-)

diff --git a/drivers/power/max17040_battery.c
b/drivers/power/max17040_battery.c
index 7f08d69..a1601b4 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -20,6 +20,7 @@
 #include <linux/power_supply.h>
 #include <linux/max17040_battery.h>
 #include <linux/slab.h>
+#include <linux/regmap.h>
 
 #define MAX17040_VCELL_MSB	0x02
 #define MAX17040_VCELL_LSB	0x03
@@ -39,6 +40,7 @@
 
 struct max17040_chip {
 	struct i2c_client		*client;
+	struct regmap			*regmap;
 	struct delayed_work		work;
 	struct power_supply		battery;
 	struct max17040_platform_data	*pdata;
@@ -79,44 +81,22 @@ static int max17040_get_property(struct power_supply
*psy,
 	return 0;
 }
 
-static int max17040_write_reg(struct i2c_client *client, int reg, u8 value)
-{
-	int ret;
-
-	ret = i2c_smbus_write_byte_data(client, reg, value);
-
-	if (ret < 0)
-		dev_err(&client->dev, "%s: err %d\n", __func__, ret);
-
-	return ret;
-}
-
-static int max17040_read_reg(struct i2c_client *client, int reg)
-{
-	int ret;
-
-	ret = i2c_smbus_read_byte_data(client, reg);
-
-	if (ret < 0)
-		dev_err(&client->dev, "%s: err %d\n", __func__, ret);
-
-	return ret;
-}
-
 static void max17040_reset(struct i2c_client *client)
 {
-	max17040_write_reg(client, MAX17040_CMD_MSB, 0x54);
-	max17040_write_reg(client, MAX17040_CMD_LSB, 0x00);
+	struct max17040_chip *chip = i2c_get_clientdata(client);
+
+	regmap_write(chip->regmap, MAX17040_CMD_MSB, 0x54);
+	regmap_write(chip->regmap, MAX17040_CMD_LSB, 0x00);
 }
 
 static void max17040_get_vcell(struct i2c_client *client)
 {
 	struct max17040_chip *chip = i2c_get_clientdata(client);
-	u8 msb;
-	u8 lsb;
+	u32 msb;
+	u32 lsb;
 
-	msb = max17040_read_reg(client, MAX17040_VCELL_MSB);
-	lsb = max17040_read_reg(client, MAX17040_VCELL_LSB);
+	regmap_read(chip->regmap, MAX17040_VCELL_MSB, &msb);
+	regmap_read(chip->regmap, MAX17040_VCELL_LSB, &lsb);
 
 	chip->vcell = (msb << 4) + (lsb >> 4);
 }
@@ -124,22 +104,23 @@ static void max17040_get_vcell(struct i2c_client
*client)
 static void max17040_get_soc(struct i2c_client *client)
 {
 	struct max17040_chip *chip = i2c_get_clientdata(client);
-	u8 msb;
-	u8 lsb;
+	u32 msb;
+	u32 lsb;
 
-	msb = max17040_read_reg(client, MAX17040_SOC_MSB);
-	lsb = max17040_read_reg(client, MAX17040_SOC_LSB);
+	regmap_read(chip->regmap, MAX17040_SOC_MSB, &msb);
+	regmap_read(chip->regmap, MAX17040_SOC_LSB, &lsb);
 
 	chip->soc = msb;
 }
 
 static void max17040_get_version(struct i2c_client *client)
 {
-	u8 msb;
-	u8 lsb;
+	struct max17040_chip *chip = i2c_get_clientdata(client);
+	u32 msb;
+	u32 lsb;
 
-	msb = max17040_read_reg(client, MAX17040_VER_MSB);
-	lsb = max17040_read_reg(client, MAX17040_VER_LSB);
+	regmap_read(chip->regmap, MAX17040_VER_MSB, &msb);
+	regmap_read(chip->regmap, MAX17040_VER_LSB, &lsb);
 
 	dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver %d%d\n", msb, lsb);
 }
@@ -197,12 +178,18 @@ static enum power_supply_property
max17040_battery_props[] = {
 	POWER_SUPPLY_PROP_CAPACITY,
 };
 
+static struct regmap_config max17040_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.val_format_endian = REGMAP_ENDIAN_NATIVE,
+};
+
 static int max17040_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
 	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
 	struct max17040_chip *chip;
-	int ret;
+	u32 ret;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
 		return -EIO;
@@ -212,6 +199,12 @@ static int max17040_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	chip->client = client;
+	chip->regmap = devm_regmap_init_i2c(client,
&max17040_regmap_config);
+	if (IS_ERR(chip->regmap)) {
+		dev_err(&client->dev, "Failed to initialize regmap\n");
+		return -EINVAL;
+	}
+
 	chip->pdata = client->dev.platform_data;
 
 	if (!chip->pdata) {
-- 
1.7.9.5


             reply	other threads:[~2013-10-21  8:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21  8:48 남관우 [this message]
2013-10-26  0:04 ` [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal registers Anton Vorontsov

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='002101cece3a$53eeff80$fbccfe80$%nam@samsung.com' \
    --to=kw46.nam@samsung.com \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.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