* [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal registers
@ 2013-10-21 8:48 남관우
2013-10-26 0:04 ` Anton Vorontsov
0 siblings, 1 reply; 2+ messages in thread
From: 남관우 @ 2013-10-21 8:48 UTC (permalink / raw)
To: cbou, dwmw2, linux-kernel; +Cc: kw46.nam, kyungmin.park
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal registers
2013-10-21 8:48 [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal registers 남관우
@ 2013-10-26 0:04 ` Anton Vorontsov
0 siblings, 0 replies; 2+ messages in thread
From: Anton Vorontsov @ 2013-10-26 0:04 UTC (permalink / raw)
To: ������
Cc: dwmw2, linux-kernel, kyungmin.park
On Mon, Oct 21, 2013 at 05:48:35PM +0900, ������ wrote:
> 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>
> ---
$ git am -s patch
fatal: cannot convert from ks_c_5601-1987 to UTF-8
I fixed this manually, but then I noticed this:
> @@ -124,22 +104,23 @@ static void max17040_get_vcell(struct i2c_client
> *client)
Which means that the patch is also line-wrap damaged... so I gave up.
Anton
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-26 0:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-21 8:48 [PATCH] Fuel Guague: MAX17040: Use regmap to interface with internal registers 남관우
2013-10-26 0:04 ` Anton Vorontsov
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).