Skip to contentSkip to conversation

mfd: Convert pcf50633 to use new register map API

PATCH In review Mark Brown 3 participants 5 messages Aug 6, 2011 – Aug 22, 2011

Subsystems (4)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 mfd: Convert pcf50633 to use new register map API

---

The regmap API has gone into mainline now so this can be merged into -next.

 drivers/mfd/Kconfig               |    1 +
 drivers/mfd/pcf50633-core.c       |  114 +++++++++---------------------------
 include/linux/mfd/pcf50633/core.h |    3 +-
 3 files changed, 32 insertions(+), 86 deletions(-)
drivers/mfd/Kconfig +1 -0
index a67adcb..a992948 100644
@@ -503,6 +503,7 @@ config MFD_WM8994
 config MFD_PCF50633
 	tristate "Support for NXP PCF50633"
 	depends on I2C
+	select REGMAP_I2C
 	help
 	  Say yes here if you have NXP PCF50633 chip on your board.
 	  This core driver provides register access and IRQ handling
drivers/mfd/pcf50633-core.c +29 -85

187 lines not on this page · raw message

include/linux/mfd/pcf50633/core.h +2 -1
index 50d4a04..a808407 100644
@@ -21,6 +21,7 @@
 #include <linux/mfd/pcf50633/backlight.h>
 
 struct pcf50633;
+struct regmap;
 
 #define PCF50633_NUM_REGULATORS	11
 
@@ -134,7 +135,7 @@ enum {
 
 struct pcf50633 {
 	struct device *dev;
-	struct i2c_client *i2c_client;
+	struct regmap *regmap;
 
 	struct pcf50633_platform_data *pdata;
 	int irq;
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 3 lines

#include <linux/mfd/pcf50633/core.h>

[...]

Quoted 4 lines

/* Read a block of up to 32 regs */
int pcf50633_read_block(struct pcf50633 *pcf, u8 reg,

(quoted diff) +0 -0
 					int nr_regs, u8 *data)
 {

Review

Quoted 10 lines
(quoted diff) +1 -7
-	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.

Quoted 80 lines
(quoted diff) +8 -44
@@ -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;
-

Review EXPORT_SYMBOL_GPL(pcf50633_reg_read); · line 76

Quoted 10 lines
(quoted diff) +1 -7
-	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.

Review static int pcf50633_resume(struct device *dev) · line 183

Quoted 6 lines
(quoted diff) +1 -0
@@ -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

Review static int pcf50633_resume(struct device *dev) · line 187

Quoted 4 lines
(quoted diff) +4 -0
+	.reg_bits = 8,
+	.val_bits = 8,
+};
+

------

drivers/base/regmap/regmap-i2c.c +2 -0
index c2231ff..ba107db 100644
@@ -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;
drivers/mfd/pcf50633-irq.c +1 -1
index 4b8269c..edc1897 100644
@@ -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");
 
 		/*
drivers/rtc/rtc-pcf50633.c +4 -4
index b0dc8c2..5bcc8e2 100644
@@ -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);
author
#2 lore raw
Quoted 3 lines · Lars-Peter Clausen
Quoted 1 line

EXPORT_SYMBOL_GPL(pcf50633_reg_clear_bits);

I would prefer making the wrappers static inline functions.

I considered doing this for all the conversions but preferred to go for a minimal diff for ease of review, it seems better to do such code motion changes later on. Similarly for the return value stuff which I'll update shortly.

drivers/base/regmap/regmap-i2c.c static int regmap_i2c_read(struct device *dev, · line 74

Quoted 8 lines
drivers/base/regmap/regmap-i2c.c +2 -0
@@ -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);
+

Clearly not ideal...

#3 lore raw
In reply to Lars-Peter Clausen

Hi Lars,

Quoted 15 lines · Lars-Peter Clausen
Quoted 3 lines

#include <linux/mfd/pcf50633/core.h>

[...]

Quoted 11 lines

/* Read a block of up to 32 regs */
int pcf50633_read_block(struct pcf50633 *pcf, u8 reg,

(quoted diff) +0 -7
 					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;
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +1 -0
+	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.

I'd like to apply Mark's patch and yours. Could you please remove the unnecesary printk in your patch and I'll go ahead.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#4 lore raw
Quoted 26 lines · Samuel Ortiz

Hi Lars,

Quoted 15 lines · Lars-Peter Clausen
Quoted 3 lines

#include <linux/mfd/pcf50633/core.h>

[...]

Quoted 11 lines

/* Read a block of up to 32 regs */
int pcf50633_read_block(struct pcf50633 *pcf, u8 reg,

(quoted diff) +0 -7
 					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;
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +1 -0
+	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.

Quoted 2 lines

I'd like to apply Mark's patch and yours. Could you please remove the unnecesary printk in your patch and I'll go ahead.

Nevermind, I just saw Mark's updated patch.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/