* [PATCH] mfd: tps6105x: Use i2c regmap to access registers
@ 2015-10-02 16:14 Grigoryev Denis
2015-10-02 17:36 ` Mark Brown
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Grigoryev Denis @ 2015-10-02 16:14 UTC (permalink / raw)
To: linux-kernel; +Cc: Lee Jones, broonie@kernel.org, lgirdwood@gmail.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 7042 bytes --]
This patch modifies tps6105x and associated function driver to use regmap
instead of operating directly on i2c.
Signed-off-by: Denis Grigoryev <grigoryev@fastwel.ru>
---
drivers/mfd/tps6105x.c | 78 ++++++----------------------------
drivers/regulator/tps6105x-regulator.c | 16 +++----
include/linux/mfd/tps6105x.h | 10 ++---
3 files changed, 24 insertions(+), 80 deletions(-)
diff --git a/drivers/mfd/tps6105x.c b/drivers/mfd/tps6105x.c
index 182ebe0..51c5495 100644
--- a/drivers/mfd/tps6105x.c
+++ b/drivers/mfd/tps6105x.c
@@ -16,7 +16,7 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
-#include <linux/mutex.h>
+#include <linux/regmap.h>
#include <linux/gpio.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
@@ -25,73 +25,18 @@
#include <linux/mfd/core.h>
#include <linux/mfd/tps6105x.h>
-int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value)
-{
- int ret;
-
- ret = mutex_lock_interruptible(&tps6105x->lock);
- if (ret)
- return ret;
- ret = i2c_smbus_write_byte_data(tps6105x->client, reg, value);
- mutex_unlock(&tps6105x->lock);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-EXPORT_SYMBOL(tps6105x_set);
-
-int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf)
-{
- int ret;
-
- ret = mutex_lock_interruptible(&tps6105x->lock);
- if (ret)
- return ret;
- ret = i2c_smbus_read_byte_data(tps6105x->client, reg);
- mutex_unlock(&tps6105x->lock);
- if (ret < 0)
- return ret;
-
- *buf = ret;
- return 0;
-}
-EXPORT_SYMBOL(tps6105x_get);
-
-/*
- * Masks off the bits in the mask and sets the bits in the bitvalues
- * parameter in one atomic operation
- */
-int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg,
- u8 bitmask, u8 bitvalues)
-{
- int ret;
- u8 regval;
-
- ret = mutex_lock_interruptible(&tps6105x->lock);
- if (ret)
- return ret;
- ret = i2c_smbus_read_byte_data(tps6105x->client, reg);
- if (ret < 0)
- goto fail;
- regval = ret;
- regval = (~bitmask & regval) | (bitmask & bitvalues);
- ret = i2c_smbus_write_byte_data(tps6105x->client, reg, regval);
-fail:
- mutex_unlock(&tps6105x->lock);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-EXPORT_SYMBOL(tps6105x_mask_and_set);
+static struct regmap_config tps6105x_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = TPS6105X_REG_3,
+};
static int tps6105x_startup(struct tps6105x *tps6105x)
{
int ret;
- u8 regval;
+ unsigned int regval;
- ret = tps6105x_get(tps6105x, TPS6105X_REG_0, ®val);
+ ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val);
if (ret)
return ret;
switch (regval >> TPS6105X_REG0_MODE_SHIFT) {
@@ -165,10 +110,13 @@ static int tps6105x_probe(struct i2c_client *client,
if (!tps6105x)
return -ENOMEM;
+ tps6105x->regmap = devm_regmap_init_i2c(client, &tps6105x_regmap_config);
+ if (IS_ERR(tps6105x->regmap))
+ return PTR_ERR(tps6105x->regmap);
+
i2c_set_clientdata(client, tps6105x);
tps6105x->client = client;
tps6105x->pdata = pdata;
- mutex_init(&tps6105x->lock);
ret = tps6105x_startup(tps6105x);
if (ret) {
@@ -212,7 +160,7 @@ static int tps6105x_remove(struct i2c_client *client)
mfd_remove_devices(&client->dev);
/* Put chip in shutdown mode */
- tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
+ regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
TPS6105X_REG0_MODE_MASK,
TPS6105X_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);
diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c
index 3510b3e..ddc4f10 100644
--- a/drivers/regulator/tps6105x-regulator.c
+++ b/drivers/regulator/tps6105x-regulator.c
@@ -14,7 +14,7 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/err.h>
-#include <linux/i2c.h>
+#include <linux/regmap.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/mfd/core.h>
@@ -33,7 +33,7 @@ static int tps6105x_regulator_enable(struct regulator_dev *rdev)
int ret;
/* Activate voltage mode */
- ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
+ ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
TPS6105X_REG0_MODE_MASK,
TPS6105X_REG0_MODE_VOLTAGE << TPS6105X_REG0_MODE_SHIFT);
if (ret)
@@ -48,7 +48,7 @@ static int tps6105x_regulator_disable(struct regulator_dev *rdev)
int ret;
/* Set into shutdown mode */
- ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
+ ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
TPS6105X_REG0_MODE_MASK,
TPS6105X_REG0_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);
if (ret)
@@ -60,10 +60,10 @@ static int tps6105x_regulator_disable(struct regulator_dev *rdev)
static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev)
{
struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
- u8 regval;
+ unsigned int regval;
int ret;
- ret = tps6105x_get(tps6105x, TPS6105X_REG_0, ®val);
+ ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val);
if (ret)
return ret;
regval &= TPS6105X_REG0_MODE_MASK;
@@ -78,10 +78,10 @@ static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev)
static int tps6105x_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
- u8 regval;
+ unsigned int regval;
int ret;
- ret = tps6105x_get(tps6105x, TPS6105X_REG_0, ®val);
+ ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val);
if (ret)
return ret;
@@ -96,7 +96,7 @@ static int tps6105x_regulator_set_voltage_sel(struct regulator_dev *rdev,
struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
int ret;
- ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
+ ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
TPS6105X_REG0_VOLTAGE_MASK,
selector << TPS6105X_REG0_VOLTAGE_SHIFT);
if (ret)
diff --git a/include/linux/mfd/tps6105x.h b/include/linux/mfd/tps6105x.h
index 386743d..8bc5118 100644
--- a/include/linux/mfd/tps6105x.h
+++ b/include/linux/mfd/tps6105x.h
@@ -10,6 +10,7 @@
#define MFD_TPS6105X_H
#include <linux/i2c.h>
+#include <linux/regmap.h>
#include <linux/regulator/machine.h>
/*
@@ -82,20 +83,15 @@ struct tps6105x_platform_data {
/**
* struct tps6105x - state holder for the TPS6105x drivers
- * @mutex: mutex to serialize I2C accesses
* @i2c_client: corresponding I2C client
* @regulator: regulator device if used in voltage mode
+ * @regmap: used for i2c communcation on accessing registers
*/
struct tps6105x {
struct tps6105x_platform_data *pdata;
- struct mutex lock;
struct i2c_client *client;
struct regulator_dev *regulator;
+ struct regmap *regmap;
};
-extern int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value);
-extern int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf);
-extern int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg,
- u8 bitmask, u8 bitvalues);
-
#endif
--
1.9.1
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mfd: tps6105x: Use i2c regmap to access registers
2015-10-02 16:14 [PATCH] mfd: tps6105x: Use i2c regmap to access registers Grigoryev Denis
@ 2015-10-02 17:36 ` Mark Brown
2015-10-05 9:42 ` Lee Jones
2015-10-05 9:43 ` [GIT PULL] Immutable branch between MFD and Regulator for v4.3 Lee Jones
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2015-10-02 17:36 UTC (permalink / raw)
To: Grigoryev Denis; +Cc: linux-kernel, Lee Jones, lgirdwood@gmail.com
[-- Attachment #1: Type: text/plain, Size: 388 bytes --]
On Fri, Oct 02, 2015 at 04:14:41PM +0000, Grigoryev Denis wrote:
> This patch modifies tps6105x and associated function driver to use regmap
> instead of operating directly on i2c.
Acked-by: Mark Brown <broonie@kernel.org>
You could also have done this by just implementing the existing
functions in terms of the regmap ones as static inlines and avoided the
need for cross tree stuff.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mfd: tps6105x: Use i2c regmap to access registers
2015-10-02 16:14 [PATCH] mfd: tps6105x: Use i2c regmap to access registers Grigoryev Denis
2015-10-02 17:36 ` Mark Brown
@ 2015-10-05 9:42 ` Lee Jones
2015-10-05 9:43 ` [GIT PULL] Immutable branch between MFD and Regulator for v4.3 Lee Jones
2 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2015-10-05 9:42 UTC (permalink / raw)
To: Grigoryev Denis; +Cc: linux-kernel, broonie@kernel.org, lgirdwood@gmail.com
On Fri, 02 Oct 2015, Grigoryev Denis wrote:
> This patch modifies tps6105x and associated function driver to use regmap
> instead of operating directly on i2c.
>
> Signed-off-by: Denis Grigoryev <grigoryev@fastwel.ru>
> ---
> drivers/mfd/tps6105x.c | 78 ++++++----------------------------
> drivers/regulator/tps6105x-regulator.c | 16 +++----
> include/linux/mfd/tps6105x.h | 10 ++---
> 3 files changed, 24 insertions(+), 80 deletions(-)
Applied, thanks.
> diff --git a/drivers/mfd/tps6105x.c b/drivers/mfd/tps6105x.c
> index 182ebe0..51c5495 100644
> --- a/drivers/mfd/tps6105x.c
> +++ b/drivers/mfd/tps6105x.c
> @@ -16,7 +16,7 @@
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/i2c.h>
> -#include <linux/mutex.h>
> +#include <linux/regmap.h>
> #include <linux/gpio.h>
> #include <linux/spinlock.h>
> #include <linux/slab.h>
> @@ -25,73 +25,18 @@
> #include <linux/mfd/core.h>
> #include <linux/mfd/tps6105x.h>
>
> -int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value)
> -{
> - int ret;
> -
> - ret = mutex_lock_interruptible(&tps6105x->lock);
> - if (ret)
> - return ret;
> - ret = i2c_smbus_write_byte_data(tps6105x->client, reg, value);
> - mutex_unlock(&tps6105x->lock);
> - if (ret < 0)
> - return ret;
> -
> - return 0;
> -}
> -EXPORT_SYMBOL(tps6105x_set);
> -
> -int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf)
> -{
> - int ret;
> -
> - ret = mutex_lock_interruptible(&tps6105x->lock);
> - if (ret)
> - return ret;
> - ret = i2c_smbus_read_byte_data(tps6105x->client, reg);
> - mutex_unlock(&tps6105x->lock);
> - if (ret < 0)
> - return ret;
> -
> - *buf = ret;
> - return 0;
> -}
> -EXPORT_SYMBOL(tps6105x_get);
> -
> -/*
> - * Masks off the bits in the mask and sets the bits in the bitvalues
> - * parameter in one atomic operation
> - */
> -int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg,
> - u8 bitmask, u8 bitvalues)
> -{
> - int ret;
> - u8 regval;
> -
> - ret = mutex_lock_interruptible(&tps6105x->lock);
> - if (ret)
> - return ret;
> - ret = i2c_smbus_read_byte_data(tps6105x->client, reg);
> - if (ret < 0)
> - goto fail;
> - regval = ret;
> - regval = (~bitmask & regval) | (bitmask & bitvalues);
> - ret = i2c_smbus_write_byte_data(tps6105x->client, reg, regval);
> -fail:
> - mutex_unlock(&tps6105x->lock);
> - if (ret < 0)
> - return ret;
> -
> - return 0;
> -}
> -EXPORT_SYMBOL(tps6105x_mask_and_set);
> +static struct regmap_config tps6105x_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = TPS6105X_REG_3,
> +};
>
> static int tps6105x_startup(struct tps6105x *tps6105x)
> {
> int ret;
> - u8 regval;
> + unsigned int regval;
>
> - ret = tps6105x_get(tps6105x, TPS6105X_REG_0, ®val);
> + ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val);
> if (ret)
> return ret;
> switch (regval >> TPS6105X_REG0_MODE_SHIFT) {
> @@ -165,10 +110,13 @@ static int tps6105x_probe(struct i2c_client *client,
> if (!tps6105x)
> return -ENOMEM;
>
> + tps6105x->regmap = devm_regmap_init_i2c(client, &tps6105x_regmap_config);
> + if (IS_ERR(tps6105x->regmap))
> + return PTR_ERR(tps6105x->regmap);
> +
> i2c_set_clientdata(client, tps6105x);
> tps6105x->client = client;
> tps6105x->pdata = pdata;
> - mutex_init(&tps6105x->lock);
>
> ret = tps6105x_startup(tps6105x);
> if (ret) {
> @@ -212,7 +160,7 @@ static int tps6105x_remove(struct i2c_client *client)
> mfd_remove_devices(&client->dev);
>
> /* Put chip in shutdown mode */
> - tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
> + regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
> TPS6105X_REG0_MODE_MASK,
> TPS6105X_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);
>
> diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c
> index 3510b3e..ddc4f10 100644
> --- a/drivers/regulator/tps6105x-regulator.c
> +++ b/drivers/regulator/tps6105x-regulator.c
> @@ -14,7 +14,7 @@
> #include <linux/kernel.h>
> #include <linux/init.h>
> #include <linux/err.h>
> -#include <linux/i2c.h>
> +#include <linux/regmap.h>
> #include <linux/platform_device.h>
> #include <linux/regulator/driver.h>
> #include <linux/mfd/core.h>
> @@ -33,7 +33,7 @@ static int tps6105x_regulator_enable(struct regulator_dev *rdev)
> int ret;
>
> /* Activate voltage mode */
> - ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
> + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
> TPS6105X_REG0_MODE_MASK,
> TPS6105X_REG0_MODE_VOLTAGE << TPS6105X_REG0_MODE_SHIFT);
> if (ret)
> @@ -48,7 +48,7 @@ static int tps6105x_regulator_disable(struct regulator_dev *rdev)
> int ret;
>
> /* Set into shutdown mode */
> - ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
> + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
> TPS6105X_REG0_MODE_MASK,
> TPS6105X_REG0_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);
> if (ret)
> @@ -60,10 +60,10 @@ static int tps6105x_regulator_disable(struct regulator_dev *rdev)
> static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev)
> {
> struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
> - u8 regval;
> + unsigned int regval;
> int ret;
>
> - ret = tps6105x_get(tps6105x, TPS6105X_REG_0, ®val);
> + ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val);
> if (ret)
> return ret;
> regval &= TPS6105X_REG0_MODE_MASK;
> @@ -78,10 +78,10 @@ static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev)
> static int tps6105x_regulator_get_voltage_sel(struct regulator_dev *rdev)
> {
> struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
> - u8 regval;
> + unsigned int regval;
> int ret;
>
> - ret = tps6105x_get(tps6105x, TPS6105X_REG_0, ®val);
> + ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val);
> if (ret)
> return ret;
>
> @@ -96,7 +96,7 @@ static int tps6105x_regulator_set_voltage_sel(struct regulator_dev *rdev,
> struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
> int ret;
>
> - ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
> + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
> TPS6105X_REG0_VOLTAGE_MASK,
> selector << TPS6105X_REG0_VOLTAGE_SHIFT);
> if (ret)
> diff --git a/include/linux/mfd/tps6105x.h b/include/linux/mfd/tps6105x.h
> index 386743d..8bc5118 100644
> --- a/include/linux/mfd/tps6105x.h
> +++ b/include/linux/mfd/tps6105x.h
> @@ -10,6 +10,7 @@
> #define MFD_TPS6105X_H
>
> #include <linux/i2c.h>
> +#include <linux/regmap.h>
> #include <linux/regulator/machine.h>
>
> /*
> @@ -82,20 +83,15 @@ struct tps6105x_platform_data {
>
> /**
> * struct tps6105x - state holder for the TPS6105x drivers
> - * @mutex: mutex to serialize I2C accesses
> * @i2c_client: corresponding I2C client
> * @regulator: regulator device if used in voltage mode
> + * @regmap: used for i2c communcation on accessing registers
> */
> struct tps6105x {
> struct tps6105x_platform_data *pdata;
> - struct mutex lock;
> struct i2c_client *client;
> struct regulator_dev *regulator;
> + struct regmap *regmap;
> };
>
> -extern int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value);
> -extern int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf);
> -extern int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg,
> - u8 bitmask, u8 bitvalues);
> -
> #endif
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [GIT PULL] Immutable branch between MFD and Regulator for v4.3
2015-10-02 16:14 [PATCH] mfd: tps6105x: Use i2c regmap to access registers Grigoryev Denis
2015-10-02 17:36 ` Mark Brown
2015-10-05 9:42 ` Lee Jones
@ 2015-10-05 9:43 ` Lee Jones
2 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2015-10-05 9:43 UTC (permalink / raw)
To: Grigoryev Denis; +Cc: linux-kernel, broonie@kernel.org, lgirdwood@gmail.com
The following changes since commit 1f93e4a96c9109378204c147b3eec0d0e8100fde:
Linux 4.3-rc2 (2015-09-20 14:32:34 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git tags/ib-mfd-regulator-v4.3
for you to fetch changes up to 7e50711993552800644a4667daa0f569a7665eca:
mfd: tps6105x: Use i2c regmap to access registers (2015-10-05 10:38:22 +0100)
----------------------------------------------------------------
Immutable branch between MFD and Regulator due for v4.3
----------------------------------------------------------------
Grigoryev Denis (1):
mfd: tps6105x: Use i2c regmap to access registers
drivers/mfd/tps6105x.c | 78 ++++++----------------------------
drivers/regulator/tps6105x-regulator.c | 16 +++----
include/linux/mfd/tps6105x.h | 10 ++---
3 files changed, 24 insertions(+), 80 deletions(-)
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-05 9:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-02 16:14 [PATCH] mfd: tps6105x: Use i2c regmap to access registers Grigoryev Denis
2015-10-02 17:36 ` Mark Brown
2015-10-05 9:42 ` Lee Jones
2015-10-05 9:43 ` [GIT PULL] Immutable branch between MFD and Regulator for v4.3 Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox