lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-id: <002101cece3a$53eeff80$fbccfe80$%nam@samsung.com>
Date:	Mon, 21 Oct 2013 17:48:35 +0900
From:	³²°ü¿ì <kw46.nam@...sung.com>
To:	cbou@...l.ru, dwmw2@...radead.org, linux-kernel@...r.kernel.org
Cc:	kw46.nam@...sung.com, kyungmin.park@...sung.com
Subject: [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal
 registers

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

Signed-off-by: Nam KwanWoo <kw46.nam@...sung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@...sung.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ