Skip to contentSkip to conversation

MFD: twl6040: Conversion to use regmap_irq

PATCH In review Peter Ujfalusi 3 participants 10 messages Oct 11, 2012 – Nov 13, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover MFD: twl6040: Conversion to use regmap_irq

Hello,

This series will convert the twl6040 MFD core driver to use regmap_irq instead of the custom interrupt code it used. In this way considerable amount of code can be removed and we are going to use common, well tested code for the interrupt dispatch.

The series is for 3.8.

Regards,
Peter
---
Peter Ujfalusi (6):
MFD: twl6040: Fix typo for power on failure
MFD: twl6040: Remove unused parameter for

    twl6040_power_up_completion()

MFD: twl6040: Restructure power up and down code
MFD: twl6040: Correct Ready and Thermal interrupt handling
MFD: twl6040: Convert to use regmap_irq
MFD: twl6040: Rename the core driver

 drivers/mfd/Kconfig                       |   4 +-
 drivers/mfd/Makefile                      |   2 +-
 drivers/mfd/twl6040-irq.c                 | 205 ------------------------------
 drivers/mfd/{twl6040-core.c => twl6040.c} | 137 ++++++++++++--------
 include/linux/mfd/twl6040.h               |  10 +-
 5 files changed, 92 insertions(+), 266 deletions(-)
 delete mode 100644 drivers/mfd/twl6040-irq.c
 rename drivers/mfd/{twl6040-core.c => twl6040.c} (84%)
Signature · 1 line
1.7.12
#1 lore raw

PATCH 1/6 MFD: twl6040: Fix typo for power on failure

Fix old copy paste bug:
automatic power-down failed -> automatic power-up failed

---
 drivers/mfd/twl6040-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/twl6040-core.c +1 -1
index 3f2a1cf..b220aa2 100644
@@ -258,7 +258,7 @@ int twl6040_power(struct twl6040 *twl6040, int on)
 			ret = twl6040_power_up_completion(twl6040, naudint);
 			if (ret) {
 				dev_err(twl6040->dev,
-					"automatic power-down failed\n");
+					"automatic power-up failed\n");
 				twl6040->power_count = 0;
 				goto out;
 			}
Signature · 1 line
1.7.12
#2 lore raw

PATCH 2/6 MFD: twl6040: Remove unused parameter for twl6040_power_up_completion()

In reply to Peter Ujfalusi

naudint parameter has not been used, remove it.

---
 drivers/mfd/twl6040-core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/mfd/twl6040-core.c +2 -4
index b220aa2..a46d987 100644
@@ -218,8 +218,7 @@ static irqreturn_t twl6040_naudint_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static int twl6040_power_up_completion(struct twl6040 *twl6040,
-				       int naudint)
+static int twl6040_power_up_completion(struct twl6040 *twl6040)
 {
 	int time_left;
 	u8 intid;
@@ -241,7 +240,6 @@ static int twl6040_power_up_completion(struct twl6040 *twl6040,
 int twl6040_power(struct twl6040 *twl6040, int on)
 {
 	int audpwron = twl6040->audpwron;
-	int naudint = twl6040->irq;
 	int ret = 0;
 
 	mutex_lock(&twl6040->mutex);
@@ -255,7 +253,7 @@ int twl6040_power(struct twl6040 *twl6040, int on)
 			/* use AUDPWRON line */
 			gpio_set_value(audpwron, 1);
 			/* wait for power-up completion */
-			ret = twl6040_power_up_completion(twl6040, naudint);
+			ret = twl6040_power_up_completion(twl6040);
 			if (ret) {
 				dev_err(twl6040->dev,
 					"automatic power-up failed\n");
Signature · 1 line
1.7.12
#7 lore raw

PATCH 6/6 MFD: twl6040: Rename the core driver

In reply to Peter Ujfalusi

After the regmap_irq conversion there is no need to call the driver as twl6040-core.c since there is only one c file remained.

---
 drivers/mfd/Makefile                      | 2 +-
 drivers/mfd/{twl6040-core.c => twl6040.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/mfd/{twl6040-core.c => twl6040.c} (100%)
drivers/mfd/Makefile +1 -1
index 360233f..8c8331b 100644
@@ -63,7 +63,7 @@ obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
 obj-$(CONFIG_TWL4030_MADC)      += twl4030-madc.o
 obj-$(CONFIG_TWL4030_POWER)    += twl4030-power.o
 obj-$(CONFIG_MFD_TWL4030_AUDIO)	+= twl4030-audio.o
-obj-$(CONFIG_TWL6040_CORE)	+= twl6040-core.o
+obj-$(CONFIG_TWL6040_CORE)	+= twl6040.o
 
 obj-$(CONFIG_MFD_MC13XXX)	+= mc13xxx-core.o
 obj-$(CONFIG_MFD_MC13XXX_SPI)	+= mc13xxx-spi.o
drivers/mfd/twl6040.c renamed from drivers/mfd/twl6040-core.c +0 -0
similarity index 100%
rename from drivers/mfd/twl6040-core.c
rename to drivers/mfd/twl6040.c
Signature · 1 line
1.7.12
#5 lore raw

PATCH 5/6 MFD: twl6040: Convert to use regmap_irq

In reply to Peter Ujfalusi

With regmap_irq it is possibole to remove the twl6040-irq.c file and simplify the code.

---
 drivers/mfd/Kconfig         |   4 +-
 drivers/mfd/Makefile        |   2 +-
 drivers/mfd/twl6040-core.c  |  55 ++++++++----
 drivers/mfd/twl6040-irq.c   | 205 --------------------------------------------
 include/linux/mfd/twl6040.h |  10 +--
 5 files changed, 48 insertions(+), 228 deletions(-)
 delete mode 100644 drivers/mfd/twl6040-irq.c
drivers/mfd/Kconfig +2 -2
index acab3ef..a0d0758 100644
@@ -300,10 +300,10 @@ config MFD_TWL4030_AUDIO
 
 config TWL6040_CORE
 	bool "Support for TWL6040 audio codec"
-	depends on I2C=y && GENERIC_HARDIRQS
+	depends on I2C=y
 	select MFD_CORE
 	select REGMAP_I2C
-	select IRQ_DOMAIN
+	select REGMAP_IRQ
 	default n
 	help
 	  Say yes here if you want support for Texas Instruments TWL6040 audio
drivers/mfd/Makefile +1 -1
index d8ccb63..360233f 100644
@@ -63,7 +63,7 @@ obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
 obj-$(CONFIG_TWL4030_MADC)      += twl4030-madc.o
 obj-$(CONFIG_TWL4030_POWER)    += twl4030-power.o
 obj-$(CONFIG_MFD_TWL4030_AUDIO)	+= twl4030-audio.o
-obj-$(CONFIG_TWL6040_CORE)	+= twl6040-core.o twl6040-irq.o
+obj-$(CONFIG_TWL6040_CORE)	+= twl6040-core.o
 
 obj-$(CONFIG_MFD_MC13XXX)	+= mc13xxx-core.o
 obj-$(CONFIG_MFD_MC13XXX_SPI)	+= mc13xxx-spi.o
drivers/mfd/twl6040-core.c +40 -15

101 lines not on this page · raw message

drivers/mfd/twl6040-irq.c deleted +0 -205

205 lines not on this page · raw message

include/linux/mfd/twl6040.h +5 -5
index a8eff4a..94ac944 100644
@@ -207,10 +207,12 @@ struct twl6040_platform_data {
 };
 
 struct regmap;
+struct regmap_irq_chips_data;
 
 struct twl6040 {
 	struct device *dev;
 	struct regmap *regmap;
+	struct regmap_irq_chip_data *irq_data;
 	struct regulator_bulk_data supplies[2]; /* supplies for vio, v2v1 */
 	struct mutex mutex;
 	struct mutex irq_mutex;
@@ -228,9 +230,8 @@ struct twl6040 {
 	unsigned int mclk;
 
 	unsigned int irq;
-	unsigned int irq_base;
-	u8 irq_masks_cur;
-	u8 irq_masks_cache;
+	unsigned int irq_ready;
+	unsigned int irq_th;
 };
 
 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg);
@@ -245,8 +246,7 @@ int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
 		    unsigned int freq_in, unsigned int freq_out);
 int twl6040_get_pll(struct twl6040 *twl6040);
 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040);
-int twl6040_irq_init(struct twl6040 *twl6040);
-void twl6040_irq_exit(struct twl6040 *twl6040);
+
 /* Get the combined status of the vibra control register */
 int twl6040_get_vibralr_status(struct twl6040 *twl6040);
 
Signature · 1 line
1.7.12
#4 lore raw

PATCH 4/6 MFD: twl6040: Correct Ready and Thermal interrupt handling

In reply to Peter Ujfalusi

Create new irq handler for thermal events in order to be able to handle the event and clean up the code regarding to interrupt handling:
Use proper function names for the irq handlers
No need to read the INTD register anymore.

---
 drivers/mfd/twl6040-core.c | 52 +++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 21 deletions(-)
drivers/mfd/twl6040-core.c +31 -21
index 6d9db27..5817bc6 100644
@@ -193,27 +193,27 @@ static void twl6040_power_down_manual(struct twl6040 *twl6040)
 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
 }
 
-static irqreturn_t twl6040_naudint_handler(int irq, void *data)
+static irqreturn_t twl6040_readyint_handler(int irq, void *data)
 {
 	struct twl6040 *twl6040 = data;
-	u8 intid, status;
 
-	intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
+	complete(&twl6040->ready);
 
-	if (intid & TWL6040_READYINT)
-		complete(&twl6040->ready);
+	return IRQ_HANDLED;
+}
 
-	if (intid & TWL6040_THINT) {
-		status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
-		if (status & TWL6040_TSHUTDET) {
-			dev_warn(twl6040->dev,
-				 "Thermal shutdown, powering-off");
-			twl6040_power(twl6040, 0);
-		} else {
-			dev_warn(twl6040->dev,
-				 "Leaving thermal shutdown, powering-on");
-			twl6040_power(twl6040, 1);
-		}
+static irqreturn_t twl6040_thint_handler(int irq, void *data)
+{
+	struct twl6040 *twl6040 = data;
+	u8 status;
+
+	status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
+	if (status & TWL6040_TSHUTDET) {
+		dev_warn(twl6040->dev, "Thermal shutdown, powering-off");
+		twl6040_power(twl6040, 0);
+	} else {
+		dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on");
+		twl6040_power(twl6040, 1);
 	}
 
 	return IRQ_HANDLED;
@@ -580,12 +580,19 @@ static int __devinit twl6040_probe(struct i2c_client *client,
 		goto irq_init_err;
 
 	ret = request_threaded_irq(twl6040->irq_base + TWL6040_IRQ_READY,
-				   NULL, twl6040_naudint_handler, IRQF_ONESHOT,
+				   NULL, twl6040_readyint_handler, IRQF_ONESHOT,
 				   "twl6040_irq_ready", twl6040);
 	if (ret) {
-		dev_err(twl6040->dev, "READY IRQ request failed: %d\n",
-			ret);
-		goto irq_err;
+		dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret);
+		goto readyirq_err;
+	}
+
+	ret = request_threaded_irq(twl6040->irq_base + TWL6040_IRQ_TH,
+				   NULL, twl6040_thint_handler, IRQF_ONESHOT,
+				   "twl6040_irq_th", twl6040);
+	if (ret) {
+		dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret);
+		goto thirq_err;
 	}
 
 	/* dual-access registers controlled by I2C only */
@@ -650,8 +657,10 @@ static int __devinit twl6040_probe(struct i2c_client *client,
 	return 0;
 
 mfd_err:
+	free_irq(twl6040->irq_base + TWL6040_IRQ_TH, twl6040);
+thirq_err:
 	free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040);
-irq_err:
+readyirq_err:
 	twl6040_irq_exit(twl6040);
 irq_init_err:
 	if (gpio_is_valid(twl6040->audpwron))
@@ -677,6 +686,7 @@ static int __devexit twl6040_remove(struct i2c_client *client)
 		gpio_free(twl6040->audpwron);
 
 	free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040);
+	free_irq(twl6040->irq_base + TWL6040_IRQ_TH, twl6040);
 	twl6040_irq_exit(twl6040);
 
 	mfd_remove_devices(&client->dev);
Signature · 1 line
1.7.12
#3 lore raw

PATCH 3/6 MFD: twl6040: Restructure power up and down code

In reply to Peter Ujfalusi

Rearrange the code path for power up and down sequence.

---
 drivers/mfd/twl6040-core.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/mfd/twl6040-core.c +18 -20
index a46d987..6d9db27 100644
@@ -104,7 +104,7 @@ int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
 EXPORT_SYMBOL(twl6040_clear_bits);
 
 /* twl6040 codec manual power-up sequence */
-static int twl6040_power_up(struct twl6040 *twl6040)
+static int twl6040_power_up_manual(struct twl6040 *twl6040)
 {
 	u8 ldoctl, ncpctl, lppllctl;
 	int ret;
@@ -158,11 +158,12 @@ ncp_err:
 	ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
 
+	dev_err(twl6040->dev, "manual power-up failed\n");
 	return ret;
 }
 
 /* twl6040 manual power-down sequence */
-static void twl6040_power_down(struct twl6040 *twl6040)
+static void twl6040_power_down_manual(struct twl6040 *twl6040)
 {
 	u8 ncpctl, ldoctl, lppllctl;
 
@@ -218,18 +219,22 @@ static irqreturn_t twl6040_naudint_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static int twl6040_power_up_completion(struct twl6040 *twl6040)
+static int twl6040_power_up_automatic(struct twl6040 *twl6040)
 {
 	int time_left;
-	u8 intid;
+
+	gpio_set_value(twl6040->audpwron, 1);
 
 	time_left = wait_for_completion_timeout(&twl6040->ready,
 						msecs_to_jiffies(144));
 	if (!time_left) {
+		u8 intid;
+
+		dev_warn(twl6040->dev, "timeout waiting for READYINT\n");
 		intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
 		if (!(intid & TWL6040_READYINT)) {
-			dev_err(twl6040->dev,
-				"timeout waiting for READYINT\n");
+			dev_err(twl6040->dev, "automatic power-up failed\n");
+			gpio_set_value(twl6040->audpwron, 0);
 			return -ETIMEDOUT;
 		}
 	}
@@ -239,7 +244,6 @@ static int twl6040_power_up_completion(struct twl6040 *twl6040)
 
 int twl6040_power(struct twl6040 *twl6040, int on)
 {
-	int audpwron = twl6040->audpwron;
 	int ret = 0;
 
 	mutex_lock(&twl6040->mutex);
@@ -249,23 +253,17 @@ int twl6040_power(struct twl6040 *twl6040, int on)
 		if (twl6040->power_count++)
 			goto out;
 
-		if (gpio_is_valid(audpwron)) {
-			/* use AUDPWRON line */
-			gpio_set_value(audpwron, 1);
-			/* wait for power-up completion */
-			ret = twl6040_power_up_completion(twl6040);
+		if (gpio_is_valid(twl6040->audpwron)) {
+			/* use automatic power-up sequence */
+			ret = twl6040_power_up_automatic(twl6040);
 			if (ret) {
-				dev_err(twl6040->dev,
-					"automatic power-up failed\n");
 				twl6040->power_count = 0;
 				goto out;
 			}
 		} else {
 			/* use manual power-up sequence */
-			ret = twl6040_power_up(twl6040);
+			ret = twl6040_power_up_manual(twl6040);
 			if (ret) {
-				dev_err(twl6040->dev,
-					"manual power-up failed\n");
 				twl6040->power_count = 0;
 				goto out;
 			}
@@ -286,15 +284,15 @@ int twl6040_power(struct twl6040 *twl6040, int on)
 		if (--twl6040->power_count)
 			goto out;
 
-		if (gpio_is_valid(audpwron)) {
+		if (gpio_is_valid(twl6040->audpwron)) {
 			/* use AUDPWRON line */
-			gpio_set_value(audpwron, 0);
+			gpio_set_value(twl6040->audpwron, 0);
 
 			/* power-down sequence latency */
 			usleep_range(500, 700);
 		} else {
 			/* use manual power-down sequence */
-			twl6040_power_down(twl6040);
+			twl6040_power_down_manual(twl6040);
 		}
 		twl6040->sysclk = 0;
 		twl6040->mclk = 0;
Signature · 1 line
1.7.12
#8 lore raw
In reply to Peter Ujfalusi

Hi Samuel,

Quoted 8 lines · Peter Ujfalusi

Hello,

This series will convert the twl6040 MFD core driver to use regmap_irq instead of the custom interrupt code it used. In this way considerable amount of code can be removed and we are going to use common, well tested code for the interrupt dispatch.

The series is for 3.8.

Did you had time to look at this series?
I can resend it if it is better for you.

Regards,
Péter

Quoted 22 lines

Regards,
Peter
---
Peter Ujfalusi (6):
MFD: twl6040: Fix typo for power on failure
MFD: twl6040: Remove unused parameter for

    twl6040_power_up_completion()

MFD: twl6040: Restructure power up and down code
MFD: twl6040: Correct Ready and Thermal interrupt handling
MFD: twl6040: Convert to use regmap_irq
MFD: twl6040: Rename the core driver

 drivers/mfd/Kconfig                       |   4 +-
 drivers/mfd/Makefile                      |   2 +-
 drivers/mfd/twl6040-irq.c                 | 205 ------------------------------
 drivers/mfd/{twl6040-core.c => twl6040.c} | 137 ++++++++++++--------
 include/linux/mfd/twl6040.h               |  10 +-
 5 files changed, 92 insertions(+), 266 deletions(-)
 delete mode 100644 drivers/mfd/twl6040-irq.c
 rename drivers/mfd/{twl6040-core.c => twl6040.c} (84%)
#9 lore raw
In reply to Peter Ujfalusi
Quoted 6 lines · Peter Ujfalusi

Hello,

This series will convert the twl6040 MFD core driver to use regmap_irq instead of the custom interrupt code it used. In this way considerable amount of code can be removed and we are going to use common, well tested code for the interrupt dispatch.

Looks great. I applied all 6 patches to my for-next branch, thanks. Mark, thanks for the review.

Cheers,
Samuel.

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