From: Grant Likely <grant.likely@secretlab.ca>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Greg KH <greg@kroah.com>,
Dimitris Papastamos <dp@opensource.wolfsonmicro.com>,
Liam Girdwood <lrg@ti.com>, Samuel Oritz <sameo@linux.intel.com>,
Graeme Gregory <gg@slimlogic.co.uk>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] regulator: Convert tps65023 to use regmap API
Date: Thu, 14 Jul 2011 20:53:28 -0600 [thread overview]
Message-ID: <20110715025328.GJ2927@ponder.secretlab.ca> (raw)
In-Reply-To: <1310187044-13269-4-git-send-email-broonie@opensource.wolfsonmicro.com>
On Sat, Jul 09, 2011 at 01:50:44PM +0900, Mark Brown wrote:
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> Acked-by: Liam Girdwood <lrg@ti.com>
> ---
> drivers/regulator/Kconfig | 1 +
> drivers/regulator/tps65023-regulator.c | 98 +++++++++-----------------------
> 2 files changed, 28 insertions(+), 71 deletions(-)
Nice diffstat. :-)
>
> diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
> index 065892a..8128db3 100644
> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -235,6 +235,7 @@ config REGULATOR_TPS6105X
> config REGULATOR_TPS65023
> tristate "TI TPS65023 Power regulators"
> depends on I2C
> + select REGMAP
> help
> This driver supports TPS65023 voltage regulator chips. TPS65023 provides
> three step-down converters and two general-purpose LDO voltage regulators.
> diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
> index fbddc15..3fa3ba5 100644
> --- a/drivers/regulator/tps65023-regulator.c
> +++ b/drivers/regulator/tps65023-regulator.c
> @@ -25,6 +25,7 @@
> #include <linux/i2c.h>
> #include <linux/delay.h>
> #include <linux/slab.h>
> +#include <linux/regmap.h>
>
> /* Register definitions */
> #define TPS65023_REG_VERSION 0
> @@ -125,93 +126,35 @@ struct tps_pmic {
> struct i2c_client *client;
> struct regulator_dev *rdev[TPS65023_NUM_REGULATOR];
> const struct tps_info *info[TPS65023_NUM_REGULATOR];
> - struct mutex io_lock;
> + struct regmap *regmap;
> };
>
> -static inline int tps_65023_read(struct tps_pmic *tps, u8 reg)
> -{
> - return i2c_smbus_read_byte_data(tps->client, reg);
> -}
> -
> -static inline int tps_65023_write(struct tps_pmic *tps, u8 reg, u8 val)
> -{
> - return i2c_smbus_write_byte_data(tps->client, reg, val);
> -}
> -
> static int tps_65023_set_bits(struct tps_pmic *tps, u8 reg, u8 mask)
> {
> - int err, data;
> -
> - mutex_lock(&tps->io_lock);
> -
> - data = tps_65023_read(tps, reg);
> - if (data < 0) {
> - dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
> - err = data;
> - goto out;
> - }
> -
> - data |= mask;
> - err = tps_65023_write(tps, reg, data);
> - if (err)
> - dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
> -
> -out:
> - mutex_unlock(&tps->io_lock);
> - return err;
> + return regmap_update_bits(tps->regmap, reg, mask, mask);
> }
>
> static int tps_65023_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask)
> {
> - int err, data;
> -
> - mutex_lock(&tps->io_lock);
> -
> - data = tps_65023_read(tps, reg);
> - if (data < 0) {
> - dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
> - err = data;
> - goto out;
> - }
> -
> - data &= ~mask;
> -
> - err = tps_65023_write(tps, reg, data);
> - if (err)
> - dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
> -
> -out:
> - mutex_unlock(&tps->io_lock);
> - return err;
> -
> + return regmap_update_bits(tps->regmap, reg, mask, 0);
> }
>
> static int tps_65023_reg_read(struct tps_pmic *tps, u8 reg)
> {
> - int data;
> + unsigned int val;
> + int ret;
>
> - mutex_lock(&tps->io_lock);
> + ret = regmap_read(tps->regmap, reg, &val);
>
> - data = tps_65023_read(tps, reg);
> - if (data < 0)
> - dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
> -
> - mutex_unlock(&tps->io_lock);
> - return data;
> + if (ret != 0)
> + return ret;
> + else
> + return val;
> }
>
> static int tps_65023_reg_write(struct tps_pmic *tps, u8 reg, u8 val)
> {
> - int err;
> -
> - mutex_lock(&tps->io_lock);
> -
> - err = tps_65023_write(tps, reg, val);
> - if (err < 0)
> - dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
> -
> - mutex_unlock(&tps->io_lock);
> - return err;
> + return regmap_write(tps->regmap, reg, val);
> }
>
> static int tps65023_dcdc_is_enabled(struct regulator_dev *dev)
> @@ -463,6 +406,10 @@ static struct regulator_ops tps65023_ldo_ops = {
> .list_voltage = tps65023_ldo_list_voltage,
> };
>
> +static struct regmap_config tps65023_regmap_config = {
> + .reg_bits = 8, .val_bits = 8,
> +};
> +
> static int __devinit tps_65023_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -488,7 +435,13 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
> if (!tps)
> return -ENOMEM;
>
> - mutex_init(&tps->io_lock);
> + tps->regmap = regmap_init(&client->dev, &tps65023_regmap_config);
Yeah, if this usage is typical, the caller will always know exactly
what kind of regmap it needs to set up because it had an i2c_client or
an spi_device instance. I think it would be better to drop the
central registration of regmap bus types and use bus-specific init
variant. It just makes for one more bit of registration
infrastructure that needs to be setup before any drivers us it.
> + if (IS_ERR(tps->regmap)) {
> + error = PTR_ERR(tps->regmap);
> + dev_err(&client->dev, "Failed to allocate register map: %d\n",
> + error);
> + goto fail_alloc;
> + }
>
> /* common for all regulators */
> tps->client = client;
> @@ -523,10 +476,12 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
>
> return 0;
>
> - fail:
> +fail:
> while (--i >= 0)
> regulator_unregister(tps->rdev[i]);
>
> + regmap_exit(tps->regmap);
> +fail_alloc:
> kfree(tps);
> return error;
> }
> @@ -545,6 +500,7 @@ static int __devexit tps_65023_remove(struct i2c_client *client)
> for (i = 0; i < TPS65023_NUM_REGULATOR; i++)
> regulator_unregister(tps->rdev[i]);
>
> + regmap_exit(tps->regmap);
> kfree(tps);
>
> return 0;
> --
> 1.7.5.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2011-07-15 2:54 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-09 4:49 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-09 4:50 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-09 4:50 ` [PATCH 2/4] regmap: Add I2C bus support Mark Brown
2011-07-09 11:53 ` Wolfram Sang
2011-07-09 14:08 ` Mark Brown
2011-07-09 14:57 ` Wolfram Sang
2011-07-10 2:59 ` Mark Brown
2011-07-10 9:03 ` Wolfram Sang
2011-07-09 4:50 ` [PATCH 3/4] regmap: Add SPI " Mark Brown
2011-07-15 2:53 ` Grant Likely
2011-07-15 4:39 ` Mark Brown
2011-07-15 5:04 ` Grant Likely
2011-07-15 5:09 ` Mark Brown
2011-07-15 9:01 ` Jonathan Cameron
2011-07-15 18:30 ` Grant Likely
2011-07-09 4:50 ` [PATCH 4/4] regulator: Convert tps65023 to use regmap API Mark Brown
2011-07-15 2:53 ` Grant Likely [this message]
2011-07-15 4:48 ` Mark Brown
2011-07-15 18:29 ` Grant Likely
2011-07-16 1:47 ` Mark Brown
2011-07-16 2:06 ` Grant Likely
2011-07-16 2:13 ` Mark Brown
2011-07-09 5:44 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Greg KH
2011-07-15 2:53 ` Grant Likely
2011-07-15 3:25 ` Mark Brown
2011-07-15 3:30 ` Grant Likely
2011-07-15 6:22 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-15 6:23 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-15 6:23 ` [PATCH 4/4] regulator: Convert tps65023 to use regmap API Mark Brown
2011-07-15 10:31 ` Jean Delvare
2011-07-15 12:16 ` Mark Brown
2011-07-15 12:58 ` Jean Delvare
2011-07-15 13:10 ` Mark Brown
2011-07-15 13:17 ` Mark Brown
2011-07-17 15:53 ` Jean Delvare
2011-07-18 0:00 ` Grant Likely
2011-07-18 9:44 ` Mark Brown
2011-07-16 2:48 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-16 2:48 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-16 2:48 ` [PATCH 4/4] regulator: Convert tps65023 to use regmap API Mark Brown
2011-07-18 10:04 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-18 10:07 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-18 10:07 ` [PATCH 4/4] regulator: Convert tps65023 to use regmap API Mark Brown
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=20110715025328.GJ2927@ponder.secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=dp@opensource.wolfsonmicro.com \
--cc=gg@slimlogic.co.uk \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.com \
--cc=sameo@linux.intel.com \
/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
all inboxes | Powered by JetHome®