From: Lars-Peter Clausen <lars@metafoo.de>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>,
linux-kernel@vger.kernel.org,
patches@opensource.wolfsonmicro.com
Subject: Re: [PATCH] mfd: Convert pcf50633 to use new register map API
Date: Mon, 08 Aug 2011 05:29:27 +0200 [thread overview]
Message-ID: <4E3F5817.2090405@metafoo.de> (raw)
In-Reply-To: <1312602304-21504-1-git-send-email-broonie@opensource.wolfsonmicro.com>
> #include <linux/mfd/pcf50633/core.h>
>
[...]
> /* Read a block of up to 32 regs */
> int pcf50633_read_block(struct pcf50633 *pcf, u8 reg,
> int nr_regs, u8 *data)
> {
> - int ret;
> -
> - mutex_lock(&pcf->lock);
> - ret = __pcf50633_read(pcf, reg, nr_regs, data);
> - mutex_unlock(&pcf->lock);
> -
> - return ret;
> + return regmap_raw_read(pcf->regmap, reg, data, nr_regs);
> }
> EXPORT_SYMBOL_GPL(pcf50633_read_block);
There are callers which expect pcf50633_read_block to return the number of
bytes read. We could change the wrapper to return nr_regs if regmap_raw_read
returns 0. But I guess it is best to just update the callers. Incremental patch
which does this at the end of the mail.
>
> @@ -69,23 +40,18 @@ EXPORT_SYMBOL_GPL(pcf50633_read_block);
> int pcf50633_write_block(struct pcf50633 *pcf , u8 reg,
> int nr_regs, u8 *data)
> {
> - int ret;
> -
> - mutex_lock(&pcf->lock);
> - ret = __pcf50633_write(pcf, reg, nr_regs, data);
> - mutex_unlock(&pcf->lock);
> -
> - return ret;
> + return regmap_raw_write(pcf->regmap, reg, data, nr_regs);
> }
> EXPORT_SYMBOL_GPL(pcf50633_write_block);
>
> u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg)
> {
> - u8 val;
> + unsigned int val;
> + int ret;
>
> - mutex_lock(&pcf->lock);
> - __pcf50633_read(pcf, reg, 1, &val);
> - mutex_unlock(&pcf->lock);
> + ret = regmap_read(pcf->regmap, reg, &val);
> + if (ret < 0)
> + return -1;
>
> return val;
> }
> @@ -93,56 +59,19 @@ EXPORT_SYMBOL_GPL(pcf50633_reg_read);
>
> int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val)
> {
> - int ret;
> -
> - mutex_lock(&pcf->lock);
> - ret = __pcf50633_write(pcf, reg, 1, &val);
> - mutex_unlock(&pcf->lock);
> -
> - return ret;
> + return regmap_write(pcf->regmap, reg, val);
> }
> EXPORT_SYMBOL_GPL(pcf50633_reg_write);
>
> int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val)
> {
> - int ret;
> - u8 tmp;
> -
> - val &= mask;
> -
> - mutex_lock(&pcf->lock);
> - ret = __pcf50633_read(pcf, reg, 1, &tmp);
> - if (ret < 0)
> - goto out;
> -
> - tmp &= ~mask;
> - tmp |= val;
> - ret = __pcf50633_write(pcf, reg, 1, &tmp);
> -
> -out:
> - mutex_unlock(&pcf->lock);
> -
> - return ret;
> + return regmap_update_bits(pcf->regmap, reg, mask, val);
> }
> EXPORT_SYMBOL_GPL(pcf50633_reg_set_bit_mask);
>
> int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val)
> {
> - int ret;
> - u8 tmp;
> -
> - mutex_lock(&pcf->lock);
> - ret = __pcf50633_read(pcf, reg, 1, &tmp);
> - if (ret < 0)
> - goto out;
> -
> - tmp &= ~val;
> - ret = __pcf50633_write(pcf, reg, 1, &tmp);
> -
> -out:
> - mutex_unlock(&pcf->lock);
> -
> - return ret;
> + return regmap_update_bits(pcf->regmap, reg, val, 0);
> }
> EXPORT_SYMBOL_GPL(pcf50633_reg_clear_bits);
I would prefer making the wrappers static inline functions.
>
> @@ -251,6 +180,11 @@ static int pcf50633_resume(struct device *dev)
>
> static SIMPLE_DEV_PM_OPS(pcf50633_pm, pcf50633_suspend, pcf50633_resume);
>
> +static struct regmap_config pcf50633_regmap_config = {
const
> + .reg_bits = 8,
> + .val_bits = 8,
> +};
> +
------
diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
index c2231ff..ba107db 100644
--- a/drivers/base/regmap/regmap-i2c.c
+++ b/drivers/base/regmap/regmap-i2c.c
@@ -70,6 +70,8 @@ static int regmap_i2c_read(struct device *dev,
struct i2c_msg xfer[2];
int ret;
+ printk("regmap_read: %d %d\n", reg_size, val_size);
+
xfer[0].addr = i2c->addr;
xfer[0].flags = 0;
xfer[0].len = reg_size;
diff --git a/drivers/mfd/pcf50633-irq.c b/drivers/mfd/pcf50633-irq.c
index 4b8269c..edc1897 100644
--- a/drivers/mfd/pcf50633-irq.c
+++ b/drivers/mfd/pcf50633-irq.c
@@ -96,7 +96,7 @@ static irqreturn_t pcf50633_irq(int irq, void *data)
/* Read the 5 INT regs in one transaction */
ret = pcf50633_read_block(pcf, PCF50633_REG_INT1,
ARRAY_SIZE(pcf_int), pcf_int);
- if (ret != ARRAY_SIZE(pcf_int)) {
+ if (ret) {
dev_err(pcf->dev, "Error reading INT registers\n");
/*
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index b0dc8c2..5bcc8e2 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -114,9 +114,9 @@ static int pcf50633_rtc_read_time(struct device *dev,
ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSC,
PCF50633_TI_EXTENT,
&pcf_tm.time[0]);
- if (ret != PCF50633_TI_EXTENT) {
+ if (ret) {
dev_err(dev, "Failed to read time\n");
- return -EIO;
+ return ret;
}
dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
@@ -186,9 +186,9 @@ static int pcf50633_rtc_read_alarm(struct device *dev,
ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA,
PCF50633_TI_EXTENT, &pcf_tm.time[0]);
- if (ret != PCF50633_TI_EXTENT) {
+ if (ret) {
dev_err(dev, "Failed to read time\n");
- return -EIO;
+ return ret;
}
pcf2rtc_time(&alrm->time, &pcf_tm);
next prev parent reply other threads:[~2011-08-08 3:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-06 3:45 [PATCH] mfd: Convert pcf50633 to use new register map API Mark Brown
2011-08-08 3:29 ` Lars-Peter Clausen [this message]
2011-08-08 5:07 ` Mark Brown
2011-08-22 9:03 ` Samuel Ortiz
2011-08-22 9:10 ` Samuel Ortiz
-- strict thread matches above, loose matches on Subject: below --
2011-08-08 5:14 Mark Brown
2011-08-08 6:37 ` Lars-Peter Clausen
2011-08-08 8:04 Mark Brown
2011-08-10 4:21 ` Lars-Peter Clausen
2011-08-22 9:16 ` Samuel Ortiz
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=4E3F5817.2090405@metafoo.de \
--to=lars@metafoo.de \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.wolfsonmicro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.