[PATCH] Allow passing platform_data to devices attached to AC97 bus

Marek Vasut
2009-07-21T14:33:34Z

[-- Attachment #1: Type: text/plain, Size: 188 bytes --]

Hi,

I managed to put together this patch with huge help from Mark. It allows
passing platform_data to devices on ac97 bus and implements this for pxa2xx-
ac97. Please consider applying.

[-- Attachment #2: 0001-Allow-passing-platform_data-to-devices-attached-to-A.patch --]
[-- Type: text/x-patch, Size: 5195 bytes --]

From dc427c54f0fede86acb6e21b09908597b066f021 Mon Sep 17 00:00:00 2001
From: Marek Vasut <marek.vasut@gmail.com>
Date: Tue, 21 Jul 2009 16:22:29 +0200
Subject: [PATCH] Allow passing platform_data to devices attached to AC97 bus

This patch allows passing platform_data to devices attached to AC97 bus
(like touchscreens, battery measurement chips ...). This patch also adds
this support into PXA2xx-AC97 driver as a reference implementation.

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
---
arch/arm/mach-pxa/include/mach/audio.h | 1 +
include/sound/ac97_codec.h | 3 +++
include/sound/soc-dai.h | 1 +
sound/arm/pxa2xx-ac97.c | 3 +++
sound/pci/ac97/ac97_codec.c | 7 +++++++
sound/soc/pxa/pxa2xx-ac97.c | 7 ++++++-
sound/soc/soc-core.c | 5 ++++-
7 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-pxa/include/mach/audio.h b/arch/arm/mach-pxa/include/mach/audio.h
index 16eb025..8825b18 100644
--- a/arch/arm/mach-pxa/include/mach/audio.h
+++ b/arch/arm/mach-pxa/include/mach/audio.h
@@ -20,6 +20,7 @@ typedef struct {
void (*resume)(void *);
void *priv;
int reset_gpio;
+ void *codec_pdata[4];
} pxa2xx_audio_ops_t;

extern void pxa_set_ac97_info(pxa2xx_audio_ops_t *ops);
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index 251fc1c..c6b24e2 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -642,4 +642,7 @@ int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime);
/* ad hoc AC97 device driver access */
extern struct bus_type ac97_bus_type;

+/* AC97 platform_data adding function */
+void snd_ac97_dev_add_pdata(struct snd_ac97 *ac97, void *data);
+
#endif /* __SOUND_AC97_CODEC_H */
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 352d7ee..0d65a03 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -179,6 +179,7 @@ struct snd_soc_dai {
int ac97_control;

struct device *dev;
+ void *ac97_pdata; /* platform_data for the ac97 codec */

/* DAI callbacks */
int (*probe)(struct platform_device *pdev,
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index c570ebd..cfab74e 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -170,6 +170,8 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
struct snd_ac97_bus *ac97_bus;
struct snd_ac97_template ac97_template;
int ret;
+ pxa2xx_audio_ops_t *pdata = dev->dev.platform_data;
+ int id = dev->id < 0 ? 0 : dev->id;

ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
THIS_MODULE, 0, &card);
@@ -200,6 +202,7 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
snprintf(card->longname, sizeof(card->longname),
"%s (%s)", dev->dev.driver->name, card->mixername);

+ snd_ac97_dev_add_pdata(ac97_bus->codec[id], pdata->codec_pdata[id]);
snd_card_set_dev(card, &dev->dev);
ret = snd_card_register(card);
if (ret == 0) {
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 78288db..476853a 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -1922,6 +1922,13 @@ static void ac97_device_release(struct device * dev)
{
}

+/* add platform_data to the ac97 device */
+void snd_ac97_dev_add_pdata(struct snd_ac97 *ac97, void *data)
+{
+ ac97->dev.platform_data = data;
+}
+EXPORT_SYMBOL_GPL(snd_ac97_dev_add_pdata);
+
/* register ac97 codec to bus */
static int snd_ac97_dev_register(struct snd_device *device)
{
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index d9c94d7..dea18ee 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -22,6 +22,7 @@
#include <mach/hardware.h>
#include <mach/regs-ac97.h>
#include <mach/dma.h>
+#include <mach/audio.h>

#include "pxa2xx-pcm.h"
#include "pxa2xx-ac97.h"
@@ -241,9 +242,13 @@ EXPORT_SYMBOL_GPL(soc_ac97_ops);
static int __devinit pxa2xx_ac97_dev_probe(struct platform_device *pdev)
{
int i;
+ pxa2xx_audio_ops_t *pdata = pdev->dev.platform_data;

- for (i = 0; i < ARRAY_SIZE(pxa_ac97_dai); i++)
+ for (i = 0; i < ARRAY_SIZE(pxa_ac97_dai); i++) {
pxa_ac97_dai[i].dev = &pdev->dev;
+ pxa_ac97_dai[i].ac97_pdata = pdata->codec_pdata
+ [pdev->id < 0 ? 0 : pdev->id];
+ }

/* Punt most of the init to the SoC probe; we may need the machine
* driver to do interesting things with the clocking to get us up
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 1d70829..0b12fe5 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1381,8 +1381,11 @@ int snd_soc_init_card(struct snd_soc_device *socdev)
continue;
}
}
- if (card->dai_link[i].codec_dai->ac97_control)
+ if (card->dai_link[i].codec_dai->ac97_control) {
ac97 = 1;
+ codec->ac97->dev.platform_data =
+ card->dai_link[i].cpu_dai->ac97_pdata;
+ }
}
snprintf(codec->card->shortname, sizeof(codec->card->shortname),
"%s", card->name);
--
1.6.3.3

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]