linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support
@ 2012-08-14 14:22 Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 01/14] MFD: twl4030-audio: Clean up MODULE_* and platform_driver part Peter Ujfalusi
                   ` (14 more replies)
  0 siblings, 15 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Hello,

Changes since v1:
- Get the MCLK frequencey from twl-core driver (via new API)
- hs_extmute_disable_level parameter has been removed
- empty of_find_node_by_name() in of.h for !CONFIG_OF builds

Mark: the extmute GPIO handling (when it is used) remained in the codec driver
for now. I can think more on how to add support for this type of mute control.
If you can point me to other codec needing this it would help on designing
something which is common enough for other users.
As for now I have a separate series to add GPIO controlled output amps (hp/spk).
I will send that to review soon.

Introl mail from v1:

The following series adds DT support for the twl4030 audio submodule which
provides audio codec and vibra functionality.

The MFD core driver is probed via DT, it will create the needed child devices
based on the provided information in the DT blob.
Child drivers (vibra, ASoC codec) will parse the core's node if needed to get
the needed parameters for their configuration.

In the ASoC codec driver the hs_extmute callback (which was used to toggle a
GPIO line) has been removed. The codec driver will receive the GPIO number
(if it is needed on the platform).

If the series is OK (and no objections from the maintainers), it would be good
if this can go via audio. Changed files are well contained within the
twl4030-audio stack so I do not expect merge issues later.

The series has been tested on BeagleBoard (with the McBSP DT series, and with
the upcoming DT audio support for BeagleBoard).

Regards,
Peter
---
Peter Ujfalusi (14):
  MFD: twl4030-audio: Clean up MODULE_* and platform_driver part
  MFD: twl4030-audio: Convert to use devm_kzalloc
  MFD: twl4030-audio: Rearange and clean-up the probe function
  MFD: twl-core: Add API to query the HFCLK rate
  MFD: twl4030-audio: Get audio MCLK via twl-core API instead of pdata
  dt: Add empty of_find_node_by_name() function
  MFD: twl4030-audio: Add DT support
  Input: twl4030-vibra: Support for DT booted kernel
  ASoC: twl4030: Move hs_extmute GPIO handling to driver
  ARM: OMAP/ASoC: Zoom2: Let the codec to handle the hs_extmute GPIO
  ASoC/MFD: twl4030: Remove set_hs_extmute callback from platform data
  ASoC: twl4030: Convert to use devm_kzalloc
  ASoC: twl4030: Add pointer to pdata within the private data
  ASoC: twl4030: Support for DT booted kernel

 .../devicetree/bindings/mfd/twl4030-audio.txt      |   46 +++++++++
 arch/arm/mach-omap2/board-zoom-peripherals.c       |    9 +--
 arch/arm/mach-omap2/include/mach/board-zoom.h      |    2 -
 drivers/input/misc/twl4030-vibra.c                 |   20 ++++-
 drivers/mfd/twl-core.c                             |   32 ++++++
 drivers/mfd/twl4030-audio.c                        |  107 +++++++++++++-------
 include/linux/i2c/twl.h                            |    3 +-
 include/linux/of.h                                 |    6 +
 sound/soc/codecs/twl4030.c                         |  103 +++++++++++++++----
 sound/soc/omap/zoom2.c                             |    4 -
 10 files changed, 261 insertions(+), 71 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/twl4030-audio.txt

-- 
1.7.8.6


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 01/14] MFD: twl4030-audio: Clean up MODULE_* and platform_driver part
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc Peter Ujfalusi
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Place the MODULE_* lines in the same block and add MODULE_DESCRIPTION.
Rearange the platform_driver structure at the same time.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mfd/twl4030-audio.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index 838ce4e..ac04b4f 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -250,18 +250,18 @@ static int __devexit twl4030_audio_remove(struct platform_device *pdev)
 	return 0;
 }
 
-MODULE_ALIAS("platform:twl4030-audio");
-
 static struct platform_driver twl4030_audio_driver = {
-	.probe		= twl4030_audio_probe,
-	.remove		= __devexit_p(twl4030_audio_remove),
 	.driver		= {
 		.owner	= THIS_MODULE,
 		.name	= "twl4030-audio",
 	},
+	.probe		= twl4030_audio_probe,
+	.remove		= __devexit_p(twl4030_audio_remove),
 };
 
 module_platform_driver(twl4030_audio_driver);
 
 MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
+MODULE_DESCRIPTION("TWL4030 audio block MFD driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:twl4030-audio");
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 01/14] MFD: twl4030-audio: Clean up MODULE_* and platform_driver part Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-28  9:50   ` Tero Kristo
  2012-08-14 14:22 ` [PATCH v2 03/14] MFD: twl4030-audio: Rearange and clean-up the probe function Peter Ujfalusi
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mfd/twl4030-audio.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index ac04b4f..efa2d42 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -188,7 +188,8 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 	twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
 					val, TWL4030_REG_APLL_CTL);
 
-	audio = kzalloc(sizeof(struct twl4030_audio), GFP_KERNEL);
+	audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio),
+			     GFP_KERNEL);
 	if (!audio)
 		return -ENOMEM;
 
@@ -229,22 +230,18 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 		ret = -ENODEV;
 	}
 
-	if (!ret)
-		return 0;
+	if (ret) {
+		platform_set_drvdata(pdev, NULL);
+		twl4030_audio_dev = NULL;
+	}
 
-	platform_set_drvdata(pdev, NULL);
-	kfree(audio);
-	twl4030_audio_dev = NULL;
 	return ret;
 }
 
 static int __devexit twl4030_audio_remove(struct platform_device *pdev)
 {
-	struct twl4030_audio *audio = platform_get_drvdata(pdev);
-
 	mfd_remove_devices(&pdev->dev);
 	platform_set_drvdata(pdev, NULL);
-	kfree(audio);
 	twl4030_audio_dev = NULL;
 
 	return 0;
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 03/14] MFD: twl4030-audio: Rearange and clean-up the probe function
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 01/14] MFD: twl4030-audio: Clean up MODULE_* and platform_driver part Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 04/14] MFD: twl-core: Add API to query the HFCLK rate Peter Ujfalusi
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

To facilitate the device tree support the probe function need to be rearanged.
Small cleanup in the APLL frequency selection part as well.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mfd/twl4030-audio.c |   34 ++++++++++++++++------------------
 1 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index efa2d42..ca2d669 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -169,35 +169,30 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio),
+			     GFP_KERNEL);
+	if (!audio)
+		return -ENOMEM;
+
+	mutex_init(&audio->mutex);
+	audio->audio_mclk = pdata->audio_mclk;
+
 	/* Configure APLL_INFREQ and disable APLL if enabled */
-	val = 0;
-	switch (pdata->audio_mclk) {
+	switch (audio->audio_mclk) {
 	case 19200000:
-		val |= TWL4030_APLL_INFREQ_19200KHZ;
+		val = TWL4030_APLL_INFREQ_19200KHZ;
 		break;
 	case 26000000:
-		val |= TWL4030_APLL_INFREQ_26000KHZ;
+		val = TWL4030_APLL_INFREQ_26000KHZ;
 		break;
 	case 38400000:
-		val |= TWL4030_APLL_INFREQ_38400KHZ;
+		val = TWL4030_APLL_INFREQ_38400KHZ;
 		break;
 	default:
 		dev_err(&pdev->dev, "Invalid audio_mclk\n");
 		return -EINVAL;
 	}
-	twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
-					val, TWL4030_REG_APLL_CTL);
-
-	audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio),
-			     GFP_KERNEL);
-	if (!audio)
-		return -ENOMEM;
-
-	platform_set_drvdata(pdev, audio);
-
-	twl4030_audio_dev = pdev;
-	mutex_init(&audio->mutex);
-	audio->audio_mclk = pdata->audio_mclk;
+	twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, val, TWL4030_REG_APLL_CTL);
 
 	/* Codec power */
 	audio->resource[TWL4030_AUDIO_RES_POWER].reg = TWL4030_REG_CODEC_MODE;
@@ -222,6 +217,9 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 		childs++;
 	}
 
+	platform_set_drvdata(pdev, audio);
+	twl4030_audio_dev = pdev;
+
 	if (childs)
 		ret = mfd_add_devices(&pdev->dev, pdev->id, audio->cells,
 				      childs, NULL, 0);
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 04/14] MFD: twl-core: Add API to query the HFCLK rate
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (2 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 03/14] MFD: twl4030-audio: Rearange and clean-up the probe function Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 05/14] MFD: twl4030-audio: Get audio MCLK via twl-core API instead of pdata Peter Ujfalusi
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

CFG_BOOT register's HFCLK_FREQ field hold information about the used HFCLK
frequency.
Add possibility for users to get the configured rate based on this
register.
This register was configured during boot, without it the chip would not
operate correctly, so we can trust on this information.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mfd/twl-core.c  |   32 ++++++++++++++++++++++++++++++++
 include/linux/i2c/twl.h |    1 +
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 1c32afe..f162b68 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -552,6 +552,38 @@ int twl_get_version(void)
 }
 EXPORT_SYMBOL_GPL(twl_get_version);
 
+/**
+ * twl_get_hfclk_rate - API to get TWL external HFCLK clock rate.
+ *
+ * Api to get the TWL HFCLK rate based on BOOT_CFG register.
+ */
+int twl_get_hfclk_rate(void)
+{
+	u8 ctrl;
+	int rate;
+
+	twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &ctrl, R_CFG_BOOT);
+
+	switch (ctrl & 0x3) {
+	case HFCLK_FREQ_19p2_MHZ:
+		rate = 19200000;
+		break;
+	case HFCLK_FREQ_26_MHZ:
+		rate = 26000000;
+		break;
+	case HFCLK_FREQ_38p4_MHZ:
+		rate = 38400000;
+		break;
+	default:
+		pr_err("TWL4030: HFCLK is not configured\n");
+		rate = -EINVAL;
+		break;
+	}
+
+	return rate;
+}
+EXPORT_SYMBOL_GPL(twl_get_hfclk_rate);
+
 static struct device *
 add_numbered_child(unsigned chip, const char *name, int num,
 		void *pdata, unsigned pdata_len,
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 7ea898c..ac6488c 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -188,6 +188,7 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes);
 
 int twl_get_type(void);
 int twl_get_version(void);
+int twl_get_hfclk_rate(void);
 
 int twl6030_interrupt_unmask(u8 bit_mask, u8 offset);
 int twl6030_interrupt_mask(u8 bit_mask, u8 offset);
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 05/14] MFD: twl4030-audio: Get audio MCLK via twl-core API instead of pdata
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (3 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 04/14] MFD: twl-core: Add API to query the HFCLK rate Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 06/14] dt: Add empty of_find_node_by_name() function Peter Ujfalusi
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

twl-core has API to get the boot time configured HFCLK rate which has the
same rate as the audio MCLK.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mfd/twl4030-audio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index ca2d669..a48bf3a 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -175,7 +175,7 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	mutex_init(&audio->mutex);
-	audio->audio_mclk = pdata->audio_mclk;
+	audio->audio_mclk = twl_get_hfclk_rate();
 
 	/* Configure APLL_INFREQ and disable APLL if enabled */
 	switch (audio->audio_mclk) {
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 06/14] dt: Add empty of_find_node_by_name() function
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (4 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 05/14] MFD: twl4030-audio: Get audio MCLK via twl-core API instead of pdata Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 07/14] MFD: twl4030-audio: Add DT support Peter Ujfalusi
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

This commit adds an empty of_find_node_by_name() function for !CONFIG_OF
builds.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 include/linux/of.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index 5919ee3..c90e59a 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -308,6 +308,12 @@ static inline const char* of_node_full_name(struct device_node *np)
 	return "<no-node>";
 }
 
+static inline device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	return NULL;
+}
+
 static inline bool of_have_populated_dt(void)
 {
 	return false;
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 07/14] MFD: twl4030-audio: Add DT support
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (5 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 06/14] dt: Add empty of_find_node_by_name() function Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 08/14] Input: twl4030-vibra: Support for DT booted kernel Peter Ujfalusi
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Support for loading the twl4030 audio module via devicetree.
Sub devices for codec and vibra will be created as mfd devices once the
core MFD driver is loaded when the kernel is booted with a DT blob.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 .../devicetree/bindings/mfd/twl4030-audio.txt      |   46 ++++++++++++++++
 drivers/mfd/twl4030-audio.c                        |   56 +++++++++++++++++---
 2 files changed, 95 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/twl4030-audio.txt

diff --git a/Documentation/devicetree/bindings/mfd/twl4030-audio.txt b/Documentation/devicetree/bindings/mfd/twl4030-audio.txt
new file mode 100644
index 0000000..414d2ae
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/twl4030-audio.txt
@@ -0,0 +1,46 @@
+Texas Instruments TWL family (twl4030) audio module
+
+The audio module inside the TWL family consist of an audio codec and a vibra
+driver.
+
+Required properties:
+- compatible : must be "ti,twl4030-audio"
+
+Optional properties, nodes:
+
+Audio functionality:
+- codec { }: Need to be present if the audio functionality is used. Within this
+	     section the following options can be used:
+- ti,digimic_delay: Delay need after enabling the digimic to reduce artifacts
+		    from the start of the recorded sample (in ms)
+-ti,ramp_delay_value: HS ramp delay configuration to reduce pop noise
+-ti,hs_extmute: Use external mute for HS pop reduction
+-ti,hs_extmute_gpio: Use external GPIO to control the external mute
+-ti,offset_cncl_path: Offset cancellation path selection, refer to TRM for the
+		      valid values.
+
+Vibra functionality
+- ti,enable-vibra: Need to be set to <1> if the vibra functionality is used. if
+		   missing or it is 0, the vibra functionality is disabled.
+
+Example:
+&i2c1 {
+	clock-frequency = <2600000>;
+
+	twl: twl@48 {
+		reg = <0x48>;
+		interrupts = <7>; /* SYS_NIRQ cascaded to intc */
+		interrupt-parent = <&intc>;
+
+		twl_audio: audio {
+			compatible = "ti,twl4030-audio";
+
+			ti,enable-vibra = <1>;
+
+			codec {
+				ti,ramp_delay_value = <3>;
+			};
+
+		};
+	};
+};
diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index a48bf3a..ed9c5d9 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -28,6 +28,8 @@
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
 #include <linux/i2c/twl.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/twl4030-audio.h>
@@ -156,15 +158,44 @@ unsigned int twl4030_audio_get_mclk(void)
 }
 EXPORT_SYMBOL_GPL(twl4030_audio_get_mclk);
 
+static bool twl4030_audio_has_codec(struct twl4030_audio_data *pdata,
+			      struct device_node *node)
+{
+	if (pdata && pdata->codec)
+		return true;
+
+#ifdef CONFIG_OF
+	if (of_find_node_by_name(node, "codec"))
+		return true;
+#endif
+
+	return false;
+}
+
+static bool twl4030_audio_has_vibra(struct twl4030_audio_data *pdata,
+			      struct device_node *node)
+{
+	int vibra;
+
+	if (pdata && pdata->vibra)
+		return true;
+
+	if (!of_property_read_u32(node, "ti,enable-vibra", &vibra) && vibra)
+		return true;
+
+	return false;
+}
+
 static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 {
 	struct twl4030_audio *audio;
 	struct twl4030_audio_data *pdata = pdev->dev.platform_data;
+	struct device_node *node = pdev->dev.of_node;
 	struct mfd_cell *cell = NULL;
 	int ret, childs = 0;
 	u8 val;
 
-	if (!pdata) {
+	if (!pdata && !node) {
 		dev_err(&pdev->dev, "Platform data is missing\n");
 		return -EINVAL;
 	}
@@ -202,18 +233,22 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
 	audio->resource[TWL4030_AUDIO_RES_APLL].reg = TWL4030_REG_APLL_CTL;
 	audio->resource[TWL4030_AUDIO_RES_APLL].mask = TWL4030_APLL_EN;
 
-	if (pdata->codec) {
+	if (twl4030_audio_has_codec(pdata, node)) {
 		cell = &audio->cells[childs];
 		cell->name = "twl4030-codec";
-		cell->platform_data = pdata->codec;
-		cell->pdata_size = sizeof(*pdata->codec);
+		if (pdata) {
+			cell->platform_data = pdata->codec;
+			cell->pdata_size = sizeof(*pdata->codec);
+		}
 		childs++;
 	}
-	if (pdata->vibra) {
+	if (twl4030_audio_has_vibra(pdata, node)) {
 		cell = &audio->cells[childs];
 		cell->name = "twl4030-vibra";
-		cell->platform_data = pdata->vibra;
-		cell->pdata_size = sizeof(*pdata->vibra);
+		if (pdata) {
+			cell->platform_data = pdata->vibra;
+			cell->pdata_size = sizeof(*pdata->vibra);
+		}
 		childs++;
 	}
 
@@ -245,10 +280,17 @@ static int __devexit twl4030_audio_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id twl4030_audio_of_match[] = {
+	{.compatible = "ti,twl4030-audio", },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, twl4030_audio_of_match);
+
 static struct platform_driver twl4030_audio_driver = {
 	.driver		= {
 		.owner	= THIS_MODULE,
 		.name	= "twl4030-audio",
+		.of_match_table = twl4030_audio_of_match,
 	},
 	.probe		= twl4030_audio_probe,
 	.remove		= __devexit_p(twl4030_audio_remove),
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 08/14] Input: twl4030-vibra: Support for DT booted kernel
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (6 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 07/14] MFD: twl4030-audio: Add DT support Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 09/14] ASoC: twl4030: Move hs_extmute GPIO handling to driver Peter Ujfalusi
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Add support when the kernel has been booted with DT blob. In this case the
pdata is NULL, we need to reach up to the core node and check if the codec
part has been enabled to determine if we need to coexist with the codec or
not.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/input/misc/twl4030-vibra.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/input/misc/twl4030-vibra.c b/drivers/input/misc/twl4030-vibra.c
index d1e1a7e..2cfc6c7 100644
--- a/drivers/input/misc/twl4030-vibra.c
+++ b/drivers/input/misc/twl4030-vibra.c
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/jiffies.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
 #include <linux/workqueue.h>
 #include <linux/i2c/twl.h>
 #include <linux/mfd/twl4030-audio.h>
@@ -194,13 +195,28 @@ static int twl4030_vibra_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(twl4030_vibra_pm_ops,
 			 twl4030_vibra_suspend, twl4030_vibra_resume);
 
+static bool twl4030_vibra_check_coexist(struct twl4030_vibra_data *pdata,
+			      struct device_node *node)
+{
+	if (pdata && pdata->coexist)
+		return true;
+
+#ifdef CONFIG_OF
+	if (of_find_node_by_name(node, "codec"))
+		return true;
+#endif
+
+	return false;
+}
+
 static int __devinit twl4030_vibra_probe(struct platform_device *pdev)
 {
 	struct twl4030_vibra_data *pdata = pdev->dev.platform_data;
+	struct device_node *twl4030_core_node = pdev->dev.parent->of_node;
 	struct vibra_info *info;
 	int ret;
 
-	if (!pdata) {
+	if (!pdata && !twl4030_core_node) {
 		dev_dbg(&pdev->dev, "platform_data not available\n");
 		return -EINVAL;
 	}
@@ -210,7 +226,7 @@ static int __devinit twl4030_vibra_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	info->dev = &pdev->dev;
-	info->coexist = pdata->coexist;
+	info->coexist = twl4030_vibra_check_coexist(pdata, twl4030_core_node);
 	INIT_WORK(&info->play_work, vibra_play_work);
 
 	info->input_dev = input_allocate_device();
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 09/14] ASoC: twl4030: Move hs_extmute GPIO handling to driver
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (7 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 08/14] Input: twl4030-vibra: Support for DT booted kernel Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 10/14] ARM: OMAP/ASoC: Zoom2: Let the codec to handle the hs_extmute GPIO Peter Ujfalusi
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

The external mute (if it is in use) is handled by a GPIO line. Prepare to
remove the set_hs_extmute callback and replace it with:
hs_extmute_gpio: the GPIO number to use for external mute

When the users of set_hs_extmute has been converted the callback can be removed.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 include/linux/i2c/twl.h    |    4 +++-
 sound/soc/codecs/twl4030.c |   32 ++++++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index ac6488c..2040309 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -667,7 +667,9 @@ struct twl4030_codec_data {
 	unsigned int check_defaults:1;
 	unsigned int reset_registers:1;
 	unsigned int hs_extmute:1;
-	void (*set_hs_extmute)(int mute);
+	void (*set_hs_extmute)(int mute); /* Deprecated, use hs_extmute_gpio and
+					     hs_extmute_disable_level */
+	int hs_extmute_gpio;
 };
 
 struct twl4030_vibra_data {
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 391fcfc..5fc271a 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -28,6 +28,7 @@
 #include <linux/platform_device.h>
 #include <linux/i2c/twl.h>
 #include <linux/slab.h>
+#include <linux/gpio.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -302,6 +303,22 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
 	u8 reg, byte;
 	int i = 0;
 
+	if (pdata && pdata->hs_extmute &&
+	    gpio_is_valid(pdata->hs_extmute_gpio)) {
+		int ret;
+
+		if (!pdata->hs_extmute_gpio)
+			dev_warn(codec->dev,
+				 "Extmute GPIO is 0 is this correct?\n");
+
+		ret = gpio_request_one(pdata->hs_extmute_gpio,
+				       GPIOF_OUT_INIT_LOW, "hs_extmute");
+		if (ret) {
+			dev_err(codec->dev, "Failed to get hs_extmute GPIO\n");
+			pdata->hs_extmute_gpio = -1;
+		}
+	}
+
 	/* Check defaults, if instructed before anything else */
 	if (pdata && pdata->check_defaults)
 		twl4030_check_defaults(codec);
@@ -748,7 +765,10 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 	/* Enable external mute control, this dramatically reduces
 	 * the pop-noise */
 	if (pdata && pdata->hs_extmute) {
-		if (pdata->set_hs_extmute) {
+		if (gpio_is_valid(pdata->hs_extmute_gpio)) {
+			gpio_set_value(pdata->hs_extmute_gpio, 1);
+		} else if (pdata->set_hs_extmute) {
+			dev_warn(codec->dev, "set_hs_extmute is deprecated\n");
 			pdata->set_hs_extmute(1);
 		} else {
 			hs_pop |= TWL4030_EXTMUTE;
@@ -786,7 +806,10 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 
 	/* Disable external mute */
 	if (pdata && pdata->hs_extmute) {
-		if (pdata->set_hs_extmute) {
+		if (gpio_is_valid(pdata->hs_extmute_gpio)) {
+			gpio_set_value(pdata->hs_extmute_gpio, 0);
+		} else if (pdata->set_hs_extmute) {
+			dev_warn(codec->dev, "set_hs_extmute is deprecated\n");
 			pdata->set_hs_extmute(0);
 		} else {
 			hs_pop &= ~TWL4030_EXTMUTE;
@@ -2230,12 +2253,17 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec)
 
 static int twl4030_soc_remove(struct snd_soc_codec *codec)
 {
+	struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev);
 	struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
 	/* Reset registers to their chip default before leaving */
 	twl4030_reset_registers(codec);
 	twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
 	kfree(twl4030);
+
+	if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio))
+		gpio_free(pdata->hs_extmute_gpio);
+
 	return 0;
 }
 
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 10/14] ARM: OMAP/ASoC: Zoom2: Let the codec to handle the hs_extmute GPIO
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (8 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 09/14] ASoC: twl4030: Move hs_extmute GPIO handling to driver Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 11/14] ASoC/MFD: twl4030: Remove set_hs_extmute callback from platform data Peter Ujfalusi
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Remove the use of set_hs_extmute callback and let the codec driver to
handle the extmute GPIO.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 arch/arm/mach-omap2/board-zoom-peripherals.c  |    9 ++-------
 arch/arm/mach-omap2/include/mach/board-zoom.h |    2 --
 sound/soc/omap/zoom2.c                        |    4 ----
 3 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-omap2/board-zoom-peripherals.c b/arch/arm/mach-omap2/board-zoom-peripherals.c
index b797cb2..a7d3b04 100644
--- a/arch/arm/mach-omap2/board-zoom-peripherals.c
+++ b/arch/arm/mach-omap2/board-zoom-peripherals.c
@@ -34,6 +34,7 @@
 #include "common-board-devices.h"
 
 #define OMAP_ZOOM_WLAN_PMENA_GPIO	(101)
+#define ZOOM2_HEADSET_EXTMUTE_GPIO	(153)
 #define OMAP_ZOOM_WLAN_IRQ_GPIO		(162)
 
 #define LCD_PANEL_ENABLE_GPIO		(7 + OMAP_MAX_GPIO_LINES)
@@ -244,12 +245,6 @@ static int zoom_twl_gpio_setup(struct device *dev,
 	return ret;
 }
 
-/* EXTMUTE callback function */
-static void zoom2_set_hs_extmute(int mute)
-{
-	gpio_set_value(ZOOM2_HEADSET_EXTMUTE_GPIO, mute);
-}
-
 static struct twl4030_gpio_platform_data zoom_gpio_data = {
 	.gpio_base	= OMAP_MAX_GPIO_LINES,
 	.irq_base	= TWL4030_GPIO_IRQ_BASE,
@@ -279,7 +274,7 @@ static int __init omap_i2c_init(void)
 
 		codec_data->ramp_delay_value = 3;	/* 161 ms */
 		codec_data->hs_extmute = 1;
-		codec_data->set_hs_extmute = zoom2_set_hs_extmute;
+		codec_data->hs_extmute_gpio = ZOOM2_HEADSET_EXTMUTE_GPIO;
 	}
 	omap_pmic_init(1, 2400, "twl5030", INT_34XX_SYS_NIRQ, &zoom_twldata);
 	omap_register_i2c_bus(2, 400, NULL, 0);
diff --git a/arch/arm/mach-omap2/include/mach/board-zoom.h b/arch/arm/mach-omap2/include/mach/board-zoom.h
index 775fdc3..2e94869 100644
--- a/arch/arm/mach-omap2/include/mach/board-zoom.h
+++ b/arch/arm/mach-omap2/include/mach/board-zoom.h
@@ -8,5 +8,3 @@
 extern int __init zoom_debugboard_init(void);
 extern void __init zoom_peripherals_init(void);
 extern void __init zoom_display_init(void);
-
-#define ZOOM2_HEADSET_EXTMUTE_GPIO	153
diff --git a/sound/soc/omap/zoom2.c b/sound/soc/omap/zoom2.c
index 920e0d9..df97a41 100644
--- a/sound/soc/omap/zoom2.c
+++ b/sound/soc/omap/zoom2.c
@@ -191,9 +191,6 @@ static int __init zoom2_soc_init(void)
 	BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
 	gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
 
-	BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
-	gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
-
 	return 0;
 
 err1:
@@ -207,7 +204,6 @@ module_init(zoom2_soc_init);
 static void __exit zoom2_soc_exit(void)
 {
 	gpio_free(ZOOM2_HEADSET_MUX_GPIO);
-	gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
 
 	platform_device_unregister(zoom2_snd_device);
 }
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 11/14] ASoC/MFD: twl4030: Remove set_hs_extmute callback from platform data
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (9 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 10/14] ARM: OMAP/ASoC: Zoom2: Let the codec to handle the hs_extmute GPIO Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 12/14] ASoC: twl4030: Convert to use devm_kzalloc Peter Ujfalusi
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

We no longer have users for the set_hs_extmute callback which has been
replaced by hs_extmute_gpio so the codec driver can handle the external
mute if it is needed by the board.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 include/linux/i2c/twl.h    |    2 --
 sound/soc/codecs/twl4030.c |    6 ------
 2 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 2040309..a4885a6 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -667,8 +667,6 @@ struct twl4030_codec_data {
 	unsigned int check_defaults:1;
 	unsigned int reset_registers:1;
 	unsigned int hs_extmute:1;
-	void (*set_hs_extmute)(int mute); /* Deprecated, use hs_extmute_gpio and
-					     hs_extmute_disable_level */
 	int hs_extmute_gpio;
 };
 
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 5fc271a..27ccea4 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -767,9 +767,6 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 	if (pdata && pdata->hs_extmute) {
 		if (gpio_is_valid(pdata->hs_extmute_gpio)) {
 			gpio_set_value(pdata->hs_extmute_gpio, 1);
-		} else if (pdata->set_hs_extmute) {
-			dev_warn(codec->dev, "set_hs_extmute is deprecated\n");
-			pdata->set_hs_extmute(1);
 		} else {
 			hs_pop |= TWL4030_EXTMUTE;
 			twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
@@ -808,9 +805,6 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 	if (pdata && pdata->hs_extmute) {
 		if (gpio_is_valid(pdata->hs_extmute_gpio)) {
 			gpio_set_value(pdata->hs_extmute_gpio, 0);
-		} else if (pdata->set_hs_extmute) {
-			dev_warn(codec->dev, "set_hs_extmute is deprecated\n");
-			pdata->set_hs_extmute(0);
 		} else {
 			hs_pop &= ~TWL4030_EXTMUTE;
 			twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 12/14] ASoC: twl4030: Convert to use devm_kzalloc
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (10 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 11/14] ASoC/MFD: twl4030: Remove set_hs_extmute callback from platform data Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 13/14] ASoC: twl4030: Add pointer to pdata within the private data Peter Ujfalusi
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Allocate the private data with devm_kzalloc.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/twl4030.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 27ccea4..413e698 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -2231,7 +2231,8 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec)
 {
 	struct twl4030_priv *twl4030;
 
-	twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL);
+	twl4030 = devm_kzalloc(codec->dev, sizeof(struct twl4030_priv),
+			       GFP_KERNEL);
 	if (twl4030 == NULL) {
 		dev_err(codec->dev, "Can not allocate memory\n");
 		return -ENOMEM;
@@ -2253,7 +2254,6 @@ static int twl4030_soc_remove(struct snd_soc_codec *codec)
 	/* Reset registers to their chip default before leaving */
 	twl4030_reset_registers(codec);
 	twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
-	kfree(twl4030);
 
 	if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio))
 		gpio_free(pdata->hs_extmute_gpio);
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 13/14] ASoC: twl4030: Add pointer to pdata within the private data
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (11 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 12/14] ASoC: twl4030: Convert to use devm_kzalloc Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-14 14:22 ` [PATCH v2 14/14] ASoC: twl4030: Support for DT booted kernel Peter Ujfalusi
  2012-08-28  9:51 ` [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Tero Kristo
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Access the pdata via a pointer within the twl4030_priv structure.
In preparation for DeviceTree support.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/twl4030.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 413e698..8b13d50 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -153,8 +153,7 @@ struct twl4030_priv {
 	u8 predrivel_enabled, predriver_enabled;
 	u8 carkitl_enabled, carkitr_enabled;
 
-	/* Delay needed after enabling the digimic interface */
-	unsigned int digimic_delay;
+	struct twl4030_codec_data *pdata;
 };
 
 /*
@@ -348,7 +347,7 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
 	if (!pdata)
 		return;
 
-	twl4030->digimic_delay = pdata->digimic_delay;
+	twl4030->pdata = pdata;
 
 	reg = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
 	reg &= ~TWL4030_RAMP_DELAY;
@@ -749,9 +748,9 @@ static int aif_event(struct snd_soc_dapm_widget *w,
 
 static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 {
-	struct twl4030_codec_data *pdata = codec->dev->platform_data;
 	unsigned char hs_gain, hs_pop;
 	struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+	struct twl4030_codec_data *pdata = twl4030->pdata;
 	/* Base values for ramp delay calculation: 2^19 - 2^26 */
 	unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
 				    8388608, 16777216, 33554432, 67108864};
@@ -864,9 +863,10 @@ static int digimic_event(struct snd_soc_dapm_widget *w,
 		struct snd_kcontrol *kcontrol, int event)
 {
 	struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
+	struct twl4030_codec_data *pdata = twl4030->pdata;
 
-	if (twl4030->digimic_delay)
-		twl4030_wait_ms(twl4030->digimic_delay);
+	if (pdata && pdata->digimic_delay)
+		twl4030_wait_ms(pdata->digimic_delay);
 	return 0;
 }
 
@@ -2248,8 +2248,8 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec)
 
 static int twl4030_soc_remove(struct snd_soc_codec *codec)
 {
-	struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev);
 	struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+	struct twl4030_codec_data *pdata = twl4030->pdata;
 
 	/* Reset registers to their chip default before leaving */
 	twl4030_reset_registers(codec);
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 14/14] ASoC: twl4030: Support for DT booted kernel
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (12 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 13/14] ASoC: twl4030: Add pointer to pdata within the private data Peter Ujfalusi
@ 2012-08-14 14:22 ` Peter Ujfalusi
  2012-08-28  9:51 ` [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Tero Kristo
  14 siblings, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-14 14:22 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely, Rob Herring
  Cc: Tero Kristo, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

When the kernel has been booted with DT blob the platform data is NULL for
the driver.
We need to construct the pdata based on the DT information for runtime use.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/twl4030.c |   57 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 8b13d50..f13c91a 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -26,6 +26,8 @@
 #include <linux/pm.h>
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <linux/i2c/twl.h>
 #include <linux/slab.h>
 #include <linux/gpio.h>
@@ -295,13 +297,59 @@ static inline void twl4030_reset_registers(struct snd_soc_codec *codec)
 
 }
 
-static void twl4030_init_chip(struct snd_soc_codec *codec)
+static void twl4030_setup_pdata_of(struct twl4030_codec_data *pdata,
+				   struct device_node *node)
+{
+	int value;
+
+	of_property_read_u32(node, "ti,digimic_delay",
+			     &pdata->digimic_delay);
+	of_property_read_u32(node, "ti,ramp_delay_value",
+			     &pdata->ramp_delay_value);
+	of_property_read_u32(node, "ti,offset_cncl_path",
+			     &pdata->offset_cncl_path);
+	if (!of_property_read_u32(node, "ti,hs_extmute", &value))
+		pdata->hs_extmute = value;
+
+	pdata->hs_extmute_gpio = of_get_named_gpio(node,
+						   "ti,hs_extmute_gpio", 0);
+	if (gpio_is_valid(pdata->hs_extmute_gpio))
+		pdata->hs_extmute = 1;
+}
+
+static struct twl4030_codec_data *twl4030_get_pdata(struct snd_soc_codec *codec)
 {
 	struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev);
+	struct device_node *twl4030_codec_node = NULL;
+
+#ifdef CONFIG_OF
+	twl4030_codec_node = of_find_node_by_name(codec->dev->parent->of_node,
+						  "codec");
+#endif
+
+	if (!pdata && twl4030_codec_node) {
+		pdata = devm_kzalloc(codec->dev,
+				     sizeof(struct twl4030_codec_data),
+				     GFP_KERNEL);
+		if (!pdata) {
+			dev_err(codec->dev, "Can not allocate memory\n");
+			return NULL;
+		}
+		twl4030_setup_pdata_of(pdata, twl4030_codec_node);
+	}
+
+	return pdata;
+}
+
+static void twl4030_init_chip(struct snd_soc_codec *codec)
+{
+	struct twl4030_codec_data *pdata;
 	struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 	u8 reg, byte;
 	int i = 0;
 
+	pdata = twl4030_get_pdata(codec);
+
 	if (pdata && pdata->hs_extmute &&
 	    gpio_is_valid(pdata->hs_extmute_gpio)) {
 		int ret;
@@ -2284,13 +2332,6 @@ static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
 
 static int __devinit twl4030_codec_probe(struct platform_device *pdev)
 {
-	struct twl4030_codec_data *pdata = pdev->dev.platform_data;
-
-	if (!pdata) {
-		dev_err(&pdev->dev, "platform_data is missing\n");
-		return -EINVAL;
-	}
-
 	return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030,
 			twl4030_dai, ARRAY_SIZE(twl4030_dai));
 }
-- 
1.7.8.6


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc
  2012-08-14 14:22 ` [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc Peter Ujfalusi
@ 2012-08-28  9:50   ` Tero Kristo
  2012-08-28 16:48     ` Mark Brown
  2012-08-30  9:19     ` Peter Ujfalusi
  0 siblings, 2 replies; 19+ messages in thread
From: Tero Kristo @ 2012-08-28  9:50 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely,
	Rob Herring, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

On Tue, 2012-08-14 at 17:22 +0300, Peter Ujfalusi wrote:
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

I think this one could use a short commit message, also about why
kfree():s are dropped (handled internally by devm_* etc.)

-Tero


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support
  2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
                   ` (13 preceding siblings ...)
  2012-08-14 14:22 ` [PATCH v2 14/14] ASoC: twl4030: Support for DT booted kernel Peter Ujfalusi
@ 2012-08-28  9:51 ` Tero Kristo
  14 siblings, 0 replies; 19+ messages in thread
From: Tero Kristo @ 2012-08-28  9:51 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely,
	Rob Herring, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Hi Peter,

The MFD patches in this set look good to me except for the minor comment
on patch 2 I just sent. That is with my limited knowledge of DT
though...

-Tero



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc
  2012-08-28  9:50   ` Tero Kristo
@ 2012-08-28 16:48     ` Mark Brown
  2012-08-30  9:19     ` Peter Ujfalusi
  1 sibling, 0 replies; 19+ messages in thread
From: Mark Brown @ 2012-08-28 16:48 UTC (permalink / raw)
  To: Tero Kristo
  Cc: Peter Ujfalusi, Liam Girdwood, Tony Lindgren, Grant Likely,
	Rob Herring, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

On Tue, Aug 28, 2012 at 12:50:10PM +0300, Tero Kristo wrote:
> On Tue, 2012-08-14 at 17:22 +0300, Peter Ujfalusi wrote:
> > Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

> I think this one could use a short commit message, also about why
> kfree():s are dropped (handled internally by devm_* etc.)

Honestly I think people should be able to figure this out, it's not like
it's an obscure API nobody ever used before.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc
  2012-08-28  9:50   ` Tero Kristo
  2012-08-28 16:48     ` Mark Brown
@ 2012-08-30  9:19     ` Peter Ujfalusi
  1 sibling, 0 replies; 19+ messages in thread
From: Peter Ujfalusi @ 2012-08-30  9:19 UTC (permalink / raw)
  To: t-kristo
  Cc: Mark Brown, Liam Girdwood, Tony Lindgren, Grant Likely,
	Rob Herring, alsa-devel, linux-omap, linux-arm-kernel,
	devicetree-discuss, Benoit Cousson, linux-kernel

Hi Tero,

On 08/28/2012 12:50 PM, Tero Kristo wrote:
> On Tue, 2012-08-14 at 17:22 +0300, Peter Ujfalusi wrote:
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> 
> I think this one could use a short commit message, also about why
> kfree():s are dropped (handled internally by devm_* etc.)

I don't like empty commit messages either but this patch is self explaining I
would think that the commit title explains it.

-- 
Péter

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-08-30  9:19 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-14 14:22 [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 01/14] MFD: twl4030-audio: Clean up MODULE_* and platform_driver part Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 02/14] MFD: twl4030-audio: Convert to use devm_kzalloc Peter Ujfalusi
2012-08-28  9:50   ` Tero Kristo
2012-08-28 16:48     ` Mark Brown
2012-08-30  9:19     ` Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 03/14] MFD: twl4030-audio: Rearange and clean-up the probe function Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 04/14] MFD: twl-core: Add API to query the HFCLK rate Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 05/14] MFD: twl4030-audio: Get audio MCLK via twl-core API instead of pdata Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 06/14] dt: Add empty of_find_node_by_name() function Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 07/14] MFD: twl4030-audio: Add DT support Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 08/14] Input: twl4030-vibra: Support for DT booted kernel Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 09/14] ASoC: twl4030: Move hs_extmute GPIO handling to driver Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 10/14] ARM: OMAP/ASoC: Zoom2: Let the codec to handle the hs_extmute GPIO Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 11/14] ASoC/MFD: twl4030: Remove set_hs_extmute callback from platform data Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 12/14] ASoC: twl4030: Convert to use devm_kzalloc Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 13/14] ASoC: twl4030: Add pointer to pdata within the private data Peter Ujfalusi
2012-08-14 14:22 ` [PATCH v2 14/14] ASoC: twl4030: Support for DT booted kernel Peter Ujfalusi
2012-08-28  9:51 ` [PATCH v2 00/14] MFD/ASoC/Input: twl4030-audio submodule DT support Tero Kristo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).