regulator: max8649 Convert max8649 to user regmap api
PATCH 1/1 regulator: max8649 Convert max8649 to user regmap api
From: Jonghwan Choi <[email protected]>
--- drivers/regulator/Kconfig | 1 + drivers/regulator/max8649.c | 113 +++++++++++++++---------------------------- 2 files changed, 41 insertions(+), 73 deletions(-)
drivers/regulator/Kconfig +1 -0
@@ -83,6 +83,7 @@ config REGULATOR_MAX1586 config REGULATOR_MAX8649 tristate "Maxim 8649 voltage regulator" depends on I2C + select REGMAP_I2C help This driver controls a Maxim 8649 voltage output regulator via I2C bus.
drivers/regulator/max8649.c +40 -73
253 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 1/1 regulator: max8649 Convert max8649 to user regmap api
Quoted 2 lines · On Tue, Oct 18, 2011 at 3:23 PM, <[email protected]> wrote:
From: Jonghwan Choi <[email protected]>
Comments?
Quoted 119 lines
Signed-off-by Jonghwan Choi <[email protected]>---
?drivers/regulator/Kconfig ? | ? ?1 +
?drivers/regulator/max8649.c | ?113 +++++++++++++++---------------------------- ?2 files changed, 41 insertions(+), 73 deletions(-)drivers/regulator/Kconfig +0
-0@@ -83,6 +83,7 @@ config REGULATOR_MAX1586?config
REGULATOR_MAX8649
? ? ? ?tristate "Maxim 8649 voltage regulator"
? ? ? ?depends on I2C
+ ? ? ? selectREGMAP_I2C
? ? ? ?help
? ? ? ? ?This driver controls a Maxim 8649 voltage output regulator via ? ? ? ? ?I2C bus.drivers/regulator/max8649.c +0
-0@@ -16,6 +16,7 @@?#include <
linux/regulator/driver.h>
?#include <linux/slab.h>
?#include <linux/regulator/max8649.h>
+#include <linux/regmap.h>?#define
MAX8649_DCDC_VMIN? ? ?750000 ? ? ? ? ?/* uV */ ?#defineMAX8649_DCDC_VMAX? ? ?1380000 ? ? ? ? /* uV */drivers/regulator/max8649.c +1
-2@@ -49,9 +50,8 @@ ?struct max8649_regulator_info { ? ? ? ?struct regulator_dev ? ?*regulator; - ? ? ? struct i2c_client ? ? ? *i2c; ? ? ? ?struct device ? ? ? ? ? *dev; - ? ? ? struct mutex ? ? ? ? ? ?io_lock; + ? ? ? struct regmap ? ? ? ? ? *regmap; ? ? ? ?int ? ? ? ? ? ? vol_reg;? ? ? ?unsigned ? ? ? ?mode:2; /* bit[1:0] = VID1, VID0 */
drivers/regulator/max8649.c +0
-0@@ -63,69 +63,23 @@ struct max8649_regulator_info {?/* I2C operations */
drivers/regulator/max8649.c +1
-2-static inline int max8649_read_device (struct i2c_client *i2c, - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int reg, int bytes, void *dest) +static int max8649_reg_read (struct max8649_regulator_info *info,int reg)?{
- ? ? ? unsigned char data;
- ? ? ? int ret;drivers/regulator/max8649.c +1
-15- - ? ? ? data = (unsigned char)reg; - ? ? ? ret = i2c_master_send(i2c, &data, 1); - ? ? ? if (ret < 0) - ? ? ? ? ? ? ? return ret; - ? ? ? ret = i2c_master_recv(i2c, dest, bytes); - ? ? ? if (ret < 0) - ? ? ? ? ? ? ? return ret; - ? ? ? return 0; -} - -static inline int max8649_write_device (struct i2c_client *i2c, - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int reg, int bytes, void *src) -{ - ? ? ? unsigned char buf[bytes + 1]; + ? ? ? unsigned int val;? ? ? ?int ret;
- ? ? ? buf[0] = (unsigned char)reg;
- ? ? ?memcpy(&buf[1], src, bytes);
+ ? ? ? ret =regmap_read(info->regmap, reg, &val);- ? ? ? ret =
i2c_master_send(i2c, buf, bytes + 1);
- ? ? ? if (ret < 0)
+ ? ? ? if (ret != 0)
? ? ? ? ? ? ? ?return ret;
- ? ? ? return 0;drivers/regulator/max8649.c +1
-14-} -static int max8649_reg_read (struct i2c_client *i2c,int reg) -{ - ? ? ? struct max8649_regulator_info *info = i2c_get_clientdata(i2c); - ? ? ? unsigned char data; - ? ? ? int ret; - - ? ? ? mutex_lock(&info->io_lock); - ? ? ? ret = max8649_read_device(i2c, reg, 1, &data); - ? ? ? mutex_unlock(&info->io_lock); - - ? ? ? if (ret < 0) - ? ? ? ? ? ? ? return ret; - ? ? ? return (int)data; + ? ? ? return val;?}
drivers/regulator/max8649.c +1
-1-static int max8649_set_bits(struct i2c_client *i2c, int reg, +static int max8649_set_bits(struct max8649_regulator_info *info, int reg,? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned char mask, unsigned char data) ?{
- ? ? ? structmax8649_regulator_info*info =i2c_get_clientdata(i2c);
- ? ? ? unsigned char value;
- ? ? ? int ret;drivers/regulator/max8649.c +1
-11- - ? ? ? mutex_lock(&info->io_lock); - ? ? ? ret = max8649_read_device(i2c, reg, 1, &value); - ? ? ? if (ret < 0) - ? ? ? ? ? ? ? goto out; - ? ? ? value &= ~mask; - ? ? ? value |= data; - ? ? ? ret = max8649_write_device(i2c, reg, 1, &value); -out: - ? ? ? mutex_unlock(&info->io_lock); - ? ? ? return ret; + ? ? ? return regmap_update_bits(info->regmap, reg, mask, data);?}
?static inline int
check_range(int min_uV, int max_uV)
drivers/regulator/max8649.c static int max8649_get_voltage(struct regulator_dev *rdev) · line 104
Quoted 5 lines
drivers/regulator/max8649.c +1
-1@@ -147,7 +101,7 @@ static int max8649_get_voltage(struct regulator_dev *rdev) ? ? ? ?unsigned char data; ? ? ? ?int ret; - ? ? ? ret = max8649_reg_read(info->i2c, info->vol_reg); + ? ? ? ret = max8649_reg_read(info, info->vol_reg);
max8649_reg_read() only calls regmap_read(), so you can use regmap_read() directly.
Quoted 11 lines
drivers/regulator/max8649.c +1
-1? ? ? ?if (ret < 0) ? ? ? ? ? ? ? ?return ret; ? ? ? ?data = (unsigned char)ret & MAX8649_VOL_MASK;@@ -170,14 +124,14 @@ static int max8649_set_voltage(struct regulator_dev *rdev, ? ? ? ?mask = MAX8649_VOL_MASK; ? ? ? ?*selector = data & mask; - ? ? ? return max8649_set_bits(info->i2c, info->vol_reg, mask, data); + ? ? ? return max8649_set_bits(info, info->vol_reg, mask, data); ?}
Quoted 6 lines
?/*
EN_PDmeans pulldown on EN input */
?static intmax8649_enable(struct regulator_dev *rdev)
?{
? ? ? ?structmax8649_regulator_info*info =rdev_get_drvdata(rdev);
- ? ? ? returnmax8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_EN_PD, 0);
+ ? ? ? returnmax8649_set_bits(info, MAX8649_CONTROL, MAX8649_EN_PD, 0);
max8649_set_bits() only calls regmap_update_bits(). So you can use regmap_update_bits() to replace max8649_set_bits().
Quoted 62 lines
?}
?/*
drivers/regulator/max8649.c +2
-2@@ -187,7 +141,7 @@ static int max8649_enable(struct regulator_dev *rdev) ?static int max8649_disable(struct regulator_dev *rdev) ?{ ? ? ? ?struct max8649_regulator_info *info = rdev_get_drvdata(rdev); - ? ? ? return max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_EN_PD, + ? ? ? return max8649_set_bits(info, MAX8649_CONTROL, MAX8649_EN_PD, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MAX8649_EN_PD); ?}@@ -196,7 +150,7 @@ static int max8649_is_enabled(struct regulator_dev *rdev) ? ? ? ?struct max8649_regulator_info *info = rdev_get_drvdata(rdev); ? ? ? ?int ret; - ? ? ? ret = max8649_reg_read(info->i2c, MAX8649_CONTROL); + ? ? ? ret = max8649_reg_read(info, MAX8649_CONTROL); ? ? ? ?if (ret < 0) ? ? ? ? ? ? ? ?return ret; ? ? ? ?return !((unsigned char)ret & MAX8649_EN_PD);@@ -208,14 +162,14 @@ static int max8649_enable_time(struct regulator_dev *rdev) ? ? ? ?int voltage, rate, ret;? ? ? ?/* get voltage */
- ? ? ? ret =max8649_reg_read(info->i2c, info->vol_reg);
+ ? ? ? ret =max8649_reg_read(info, info->vol_reg);
? ? ? ?if (ret < 0)
? ? ? ? ? ? ? ?return ret;
? ? ? ?ret &=MAX8649_VOL_MASK;
? ? ? ?voltage =max8649_list_voltage(rdev, (unsigned char)ret); /* uV */? ? ? ?/* get rate */
- ? ? ? ret =max8649_reg_read(info->i2c, MAX8649_RAMP);
+ ? ? ? ret =max8649_reg_read(info, MAX8649_RAMP); ? ? ? ?if (ret < 0)
? ? ? ? ? ? ? ?return ret;
? ? ? ?ret = (ret &MAX8649_RAMP_MASK) >> 5;drivers/regulator/max8649.c +0
-0@@ -230,11 +184,11 @@ static int max8649_set_mode(struct regulator_dev *rdev, unsigned int mode) ? ? ? ?switch (mode) {? ? ? ?case
REGULATOR_MODE_FAST:
- ? ? ? ? ? ? ? max8649_set_bits(info->i2c,info->vol_reg,MAX8649_FORCE_PWM,
+ ? ? ? ? ? ? ?max8649_set_bits(info, info->vol_reg, MAX8649_FORCE_PWM, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MAX8649_FORCE_PWM);
? ? ? ? ? ? ? ?break;
? ? ? ?caseREGULATOR_MODE_NORMAL:
- ? ? ? ? ? ? ? max8649_set_bits(info->i2c,info->vol_reg,
+ ? ? ? ? ? ? ? max8649_set_bits(info,info->vol_reg,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MAX8649_FORCE_PWM, 0);
? ? ? ? ? ? ? ?break;
? ? ? ?default:drivers/regulator/max8649.c +1
-1@@ -248,7 +202,7 @@ static unsigned int max8649_get_mode(struct regulator_dev *rdev) ? ? ? ?struct max8649_regulator_info *info = rdev_get_drvdata(rdev); ? ? ? ?int ret; - ? ? ? ret = max8649_reg_read(info->i2c, info->vol_reg); + ? ? ? ret = max8649_reg_read(info, info->vol_reg); ? ? ? ?if (ret & MAX8649_FORCE_PWM) ? ? ? ? ? ? ? ?return REGULATOR_MODE_FAST; ? ? ? ?return REGULATOR_MODE_NORMAL;
drivers/regulator/max8649.c static struct regulator_desc dcdc_desc = { · line 236
Quoted 8 lines
drivers/regulator/max8649.c +5
-0@@ -275,6 +229,11 @@ static struct regulator_desc dcdc_desc = { ? ? ? ?.owner ? ? ? ? ?= THIS_MODULE, ?}; +static struct regmap_config max8649_regmap_config = { + ? ? ? .reg_bits = 8, + ? ? ? .val_bits = 8, +}; +
Register CHIP_ID1 & CHIP_ID2 are only readable. But it isn't mentioned in your code.
Quoted 89 lines
drivers/regulator/max8649.c +8
-3?static int __devinit max8649_regulator_probe(struct i2c_client *client, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? const struct i2c_device_id *id) ?{@@ -289,9 +248,14 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, ? ? ? ? ? ? ? ?return -ENOMEM; ? ? ? ?} - ? ? ? info->i2c = client; + ? ? ? info->regmap = regmap_init_i2c(client, &max8649_regmap_config); + ? ? ? if (IS_ERR(info->regmap)) { + ? ? ? ? ? ? ? ret = PTR_ERR(info->regmap); + ? ? ? ? ? ? ? dev_err(&client->dev, "Failed to allocate register map: %d\n", ret); + ? ? ? ? ? ? ? goto fail; + ? ? ? } + ? ? ? ?info->dev = &client->dev; - ? ? ? mutex_init(&info->io_lock); ? ? ? ?i2c_set_clientdata(client, info); ? ? ? ?info->mode = pdata->mode;@@ -312,7 +276,7 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, ? ? ? ? ? ? ? ?break; ? ? ? ?} - ? ? ? ret = max8649_reg_read(info->i2c, MAX8649_CHIP_ID1); + ? ? ? ret = max8649_reg_read(info, MAX8649_CHIP_ID1); ? ? ? ?if (ret < 0) { ? ? ? ? ? ? ? ?dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n", ? ? ? ? ? ? ? ? ? ? ? ?ret);@@ -321,28 +285,28 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, ? ? ? ?dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", ret);? ? ? ?/* enable VID0 & VID1 */
- ? ? ?max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_VID_MASK, 0);
+ ? ? ?max8649_set_bits(info, MAX8649_CONTROL, MAX8649_VID_MASK, 0);? ? ? ?/* enable/disable external clock synchronization */
? ? ? ?info->extclk =pdata->extclk;
? ? ? ?data = (info->extclk) ?MAX8649_SYNC_EXTCLK: 0;
- ? ? ?max8649_set_bits(info->i2c, info->vol_reg, MAX8649_SYNC_EXTCLK, data);
+ ? ? ?max8649_set_bits(info, info->vol_reg, MAX8649_SYNC_EXTCLK, data); ? ? ? ?if (info->extclk) {
? ? ? ? ? ? ? ?/* set external clock frequency */
? ? ? ? ? ? ? ?info->extclk_freq =pdata->extclk_freq;
- ? ? ? ? ? ? ? max8649_set_bits(info->i2c,MAX8649_SYNC,MAX8649_EXT_MASK,
+ ? ? ? ? ? ? ?max8649_set_bits(info, MAX8649_SYNC, MAX8649_EXT_MASK, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? info->extclk_freq << 6);
? ? ? ?}? ? ? ?if (
pdata->ramp_timing) {
? ? ? ? ? ? ? ?info->ramp_timing =pdata->ramp_timing;
- ? ? ? ? ? ? ? max8649_set_bits(info->i2c,MAX8649_RAMP,MAX8649_RAMP_MASK,
+ ? ? ? ? ? ? ?max8649_set_bits(info, MAX8649_RAMP, MAX8649_RAMP_MASK, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? info->ramp_timing << 5);
? ? ? ?}? ? ? ?info->ramp_down =
pdata->ramp_down;
? ? ? ?if (info->ramp_down) {
- ? ? ? ? ? ? ? max8649_set_bits(info->i2c,MAX8649_RAMP,MAX8649_RAMP_DOWN,
+ ? ? ? ? ? ? ?max8649_set_bits(info, MAX8649_RAMP, MAX8649_RAMP_DOWN, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MAX8649_RAMP_DOWN);
? ? ? ?}drivers/regulator/max8649.c +0
-0@@ -358,6 +322,8 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, ? ? ? ?dev_info(info->dev, "Max8649 regulator device is detected.\n"); ? ? ? ?return 0;?out:
+ ? ? ?regmap_exit(info->regmap);
+fail:
? ? ? ?kfree(info);
? ? ? ?return ret;
?}drivers/regulator/max8649.c +1
-1@@ -369,6 +335,7 @@ static int __devexit max8649_regulator_remove(struct i2c_client *client) ? ? ? ?if (info) { ? ? ? ? ? ? ? ?if (info->regulator) ? ? ? ? ? ? ? ? ? ? ? ?regulator_unregister(info->regulator); + ? ? ? ? ? ? ? regmap_exit(info->regmap); ? ? ? ? ? ? ? ?kfree(info); ? ? ? ?} --1.7.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/1 regulator: max8649 Convert max8649 to user regmap api
Quoted 4 lines · Haojian Zhuang
Quoted 1 line · On Tue, Oct 18, 2011 at 3:23 PM, <[email protected]> wrote:
From: Jonghwan Choi <[email protected]>
Comments?
There's not really much more to say than the changelog TBH.
Quoted 8 lines
drivers/regulator/max8649.c static struct regulator_desc dcdc_desc = { · line 236
Quoted 5 lines
drivers/regulator/max8649.c +5
-0+static struct regmap_config max8649_regmap_config = { + ? ? ? .reg_bits = 8, + ? ? ? .val_bits = 8, +}; +Register
CHIP_ID1&CHIP_ID2are only readable. But it isn't mentioned in your code.
This is optional unless the device is using the cache code, especially given that not even max_register has been provided. For a conversion like this providing access information is not needed.