ASoC: Tegra+WM8903 machine: Add device tree binding

This driver is parameterized in two ways:

a) Platform data, which supplies the set of GPIOs used by the driver.
   These GPIOs can now be parsed out of device tree.

b) Machine-specific DAPM route arrays embedded into the ASoC machine
   driver itself. Historically, the driver picks the appropriate array
   to use using machine_is_*(). The driver now requires this array to
   be parsed from device tree when instantiated through device tree,
   using the core ASoC support for this parsing.

Based on work by John Bonesio, but significantly reworked since then.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Stephen Warren 2011-12-12 15:55:36 -07:00 коммит произвёл Mark Brown
Родитель a4a54dd5bb
Коммит 07cdf36d8c
2 изменённых файлов: 174 добавлений и 25 удалений

Просмотреть файл

@ -0,0 +1,71 @@
NVIDIA Tegra audio complex
Required properties:
- compatible : "nvidia,tegra-audio-wm8903"
- nvidia,model : The user-visible name of this sound complex.
- nvidia,audio-routing : A list of the connections between audio components.
Each entry is a pair of strings, the first being the connection's sink,
the second being the connection's source. Valid names for sources and
sinks are the WM8903's pins, and the jacks on the board:
WM8903 pins:
* IN1L
* IN1R
* IN2L
* IN2R
* IN3L
* IN3R
* DMICDAT
* HPOUTL
* HPOUTR
* LINEOUTL
* LINEOUTR
* LOP
* LON
* ROP
* RON
* MICBIAS
Board connectors:
* Headphone Jack
* Int Spk
* Mic Jack
- nvidia,i2s-controller : The phandle of the Tegra I2S1 controller
- nvidia,audio-codec : The phandle of the WM8903 audio codec
Optional properties:
- nvidia,spkr-en-gpios : The GPIO that enables the speakers
- nvidia,hp-mute-gpios : The GPIO that mutes the headphones
- nvidia,hp-det-gpios : The GPIO that detect headphones are plugged in
- nvidia,int-mic-en-gpios : The GPIO that enables the internal microphone
- nvidia,ext-mic-en-gpios : The GPIO that enables the external microphone
Example:
sound {
compatible = "nvidia,tegra-audio-wm8903-harmony",
"nvidia,tegra-audio-wm8903"
nvidia,model = "tegra-wm8903-harmony";
nvidia,audio-routing =
"Headphone Jack", "HPOUTR",
"Headphone Jack", "HPOUTL",
"Int Spk", "ROP",
"Int Spk", "RON",
"Int Spk", "LOP",
"Int Spk", "LON",
"Mic Jack", "MICBIAS",
"IN1L", "Mic Jack";
nvidia,i2s-controller = <&i2s1>;
nvidia,audio-codec = <&wm8903>;
nvidia,spkr-en-gpios = <&codec 2 0>;
nvidia,hp-det-gpios = <&gpio 178 0>; /* gpio PW2 */
nvidia,int-mic-en-gpios = <&gpio 184 0>; /*gpio PX0 */
nvidia,ext-mic-en-gpios = <&gpio 185 0>; /* gpio PX1 */
};

Просмотреть файл

@ -34,6 +34,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <mach/tegra_wm8903_pdata.h> #include <mach/tegra_wm8903_pdata.h>
@ -59,8 +60,9 @@
#define GPIO_HP_DET BIT(4) #define GPIO_HP_DET BIT(4)
struct tegra_wm8903 { struct tegra_wm8903 {
struct tegra_wm8903_platform_data pdata;
struct platform_device *pcm_dev;
struct tegra_asoc_utils_data util_data; struct tegra_asoc_utils_data util_data;
struct tegra_wm8903_platform_data *pdata;
int gpio_requested; int gpio_requested;
}; };
@ -160,7 +162,7 @@ static int tegra_wm8903_event_int_spk(struct snd_soc_dapm_widget *w,
struct snd_soc_dapm_context *dapm = w->dapm; struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card; struct snd_soc_card *card = dapm->card;
struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
struct tegra_wm8903_platform_data *pdata = machine->pdata; struct tegra_wm8903_platform_data *pdata = &machine->pdata;
if (!(machine->gpio_requested & GPIO_SPKR_EN)) if (!(machine->gpio_requested & GPIO_SPKR_EN))
return 0; return 0;
@ -177,7 +179,7 @@ static int tegra_wm8903_event_hp(struct snd_soc_dapm_widget *w,
struct snd_soc_dapm_context *dapm = w->dapm; struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card; struct snd_soc_card *card = dapm->card;
struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
struct tegra_wm8903_platform_data *pdata = machine->pdata; struct tegra_wm8903_platform_data *pdata = &machine->pdata;
if (!(machine->gpio_requested & GPIO_HP_MUTE)) if (!(machine->gpio_requested & GPIO_HP_MUTE))
return 0; return 0;
@ -246,9 +248,36 @@ static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
struct snd_soc_dapm_context *dapm = &codec->dapm; struct snd_soc_dapm_context *dapm = &codec->dapm;
struct snd_soc_card *card = codec->card; struct snd_soc_card *card = codec->card;
struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
struct tegra_wm8903_platform_data *pdata = machine->pdata; struct tegra_wm8903_platform_data *pdata = &machine->pdata;
struct device_node *np = card->dev->of_node;
int ret; int ret;
if (card->dev->platform_data) {
memcpy(pdata, card->dev->platform_data, sizeof(*pdata));
} else if (np) {
/*
* This part must be in init() rather than probe() in order to
* guarantee that the WM8903 has been probed, and hence its
* GPIO controller registered, which is a pre-condition for
* of_get_named_gpio() to be able to map the phandles in the
* properties to the controller node. Given this, all
* pdata handling is in init() for consistency.
*/
pdata->gpio_spkr_en = of_get_named_gpio(np,
"nvidia,spkr-en-gpios", 0);
pdata->gpio_hp_mute = of_get_named_gpio(np,
"nvidia,hp-mute-gpios", 0);
pdata->gpio_hp_det = of_get_named_gpio(np,
"nvidia,hp-det-gpios", 0);
pdata->gpio_int_mic_en = of_get_named_gpio(np,
"nvidia,int-mic-en-gpios", 0);
pdata->gpio_ext_mic_en = of_get_named_gpio(np,
"nvidia,ext-mic-en-gpios", 0);
} else {
dev_err(card->dev, "No platform data supplied\n");
return -EINVAL;
}
if (gpio_is_valid(pdata->gpio_spkr_en)) { if (gpio_is_valid(pdata->gpio_spkr_en)) {
ret = gpio_request(pdata->gpio_spkr_en, "spkr_en"); ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
if (ret) { if (ret) {
@ -348,11 +377,9 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
{ {
struct snd_soc_card *card = &snd_soc_tegra_wm8903; struct snd_soc_card *card = &snd_soc_tegra_wm8903;
struct tegra_wm8903 *machine; struct tegra_wm8903 *machine;
struct tegra_wm8903_platform_data *pdata;
int ret; int ret;
pdata = pdev->dev.platform_data; if (!pdev->dev.platform_data && !pdev->dev.of_node) {
if (!pdata) {
dev_err(&pdev->dev, "No platform data supplied\n"); dev_err(&pdev->dev, "No platform data supplied\n");
return -EINVAL; return -EINVAL;
} }
@ -364,31 +391,70 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
} }
machine->pcm_dev = ERR_PTR(-EINVAL);
machine->pdata = pdata;
ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
if (ret)
goto err;
card->dev = &pdev->dev; card->dev = &pdev->dev;
platform_set_drvdata(pdev, card); platform_set_drvdata(pdev, card);
snd_soc_card_set_drvdata(card, machine); snd_soc_card_set_drvdata(card, machine);
if (machine_is_harmony()) { if (pdev->dev.of_node) {
card->dapm_routes = harmony_audio_map; ret = snd_soc_of_parse_card_name(card, "nvidia,model");
card->num_dapm_routes = ARRAY_SIZE(harmony_audio_map); if (ret)
} else if (machine_is_seaboard()) { goto err;
card->dapm_routes = seaboard_audio_map;
card->num_dapm_routes = ARRAY_SIZE(seaboard_audio_map); ret = snd_soc_of_parse_audio_routing(card,
} else if (machine_is_kaen()) { "nvidia,audio-routing");
card->dapm_routes = kaen_audio_map; if (ret)
card->num_dapm_routes = ARRAY_SIZE(kaen_audio_map); goto err;
tegra_wm8903_dai.codec_name = NULL;
tegra_wm8903_dai.codec_of_node = of_parse_phandle(
pdev->dev.of_node, "nvidia,audio-codec", 0);
if (!tegra_wm8903_dai.codec_of_node) {
dev_err(&pdev->dev,
"Property 'nvidia,audio-codec' missing or invalid\n");
ret = -EINVAL;
goto err;
}
tegra_wm8903_dai.cpu_dai_name = NULL;
tegra_wm8903_dai.cpu_dai_of_node = of_parse_phandle(
pdev->dev.of_node, "nvidia,i2s-controller", 0);
if (!tegra_wm8903_dai.cpu_dai_of_node) {
dev_err(&pdev->dev,
"Property 'nvidia,i2s-controller' missing or invalid\n");
ret = -EINVAL;
goto err;
}
machine->pcm_dev = platform_device_register_simple(
"tegra-pcm-audio", -1, NULL, 0);
if (IS_ERR(machine->pcm_dev)) {
dev_err(&pdev->dev,
"Can't instantiate tegra-pcm-audio\n");
ret = PTR_ERR(machine->pcm_dev);
goto err;
}
} else { } else {
card->dapm_routes = aebl_audio_map; if (machine_is_harmony()) {
card->num_dapm_routes = ARRAY_SIZE(aebl_audio_map); card->dapm_routes = harmony_audio_map;
card->num_dapm_routes = ARRAY_SIZE(harmony_audio_map);
} else if (machine_is_seaboard()) {
card->dapm_routes = seaboard_audio_map;
card->num_dapm_routes = ARRAY_SIZE(seaboard_audio_map);
} else if (machine_is_kaen()) {
card->dapm_routes = kaen_audio_map;
card->num_dapm_routes = ARRAY_SIZE(kaen_audio_map);
} else {
card->dapm_routes = aebl_audio_map;
card->num_dapm_routes = ARRAY_SIZE(aebl_audio_map);
}
} }
ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
if (ret)
goto err_unregister;
ret = snd_soc_register_card(card); ret = snd_soc_register_card(card);
if (ret) { if (ret) {
dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
@ -400,6 +466,9 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
err_fini_utils: err_fini_utils:
tegra_asoc_utils_fini(&machine->util_data); tegra_asoc_utils_fini(&machine->util_data);
err_unregister:
if (!IS_ERR(machine->pcm_dev))
platform_device_unregister(machine->pcm_dev);
err: err:
return ret; return ret;
} }
@ -408,7 +477,7 @@ static int __devexit tegra_wm8903_driver_remove(struct platform_device *pdev)
{ {
struct snd_soc_card *card = platform_get_drvdata(pdev); struct snd_soc_card *card = platform_get_drvdata(pdev);
struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
struct tegra_wm8903_platform_data *pdata = machine->pdata; struct tegra_wm8903_platform_data *pdata = &machine->pdata;
if (machine->gpio_requested & GPIO_HP_DET) if (machine->gpio_requested & GPIO_HP_DET)
snd_soc_jack_free_gpios(&tegra_wm8903_hp_jack, snd_soc_jack_free_gpios(&tegra_wm8903_hp_jack,
@ -427,15 +496,23 @@ static int __devexit tegra_wm8903_driver_remove(struct platform_device *pdev)
snd_soc_unregister_card(card); snd_soc_unregister_card(card);
tegra_asoc_utils_fini(&machine->util_data); tegra_asoc_utils_fini(&machine->util_data);
if (!IS_ERR(machine->pcm_dev))
platform_device_unregister(machine->pcm_dev);
return 0; return 0;
} }
static const struct of_device_id tegra_wm8903_of_match[] __devinitconst = {
{ .compatible = "nvidia,tegra-audio-wm8903", },
{},
};
static struct platform_driver tegra_wm8903_driver = { static struct platform_driver tegra_wm8903_driver = {
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.pm = &snd_soc_pm_ops, .pm = &snd_soc_pm_ops,
.of_match_table = tegra_wm8903_of_match,
}, },
.probe = tegra_wm8903_driver_probe, .probe = tegra_wm8903_driver_probe,
.remove = __devexit_p(tegra_wm8903_driver_remove), .remove = __devexit_p(tegra_wm8903_driver_remove),
@ -446,3 +523,4 @@ MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver"); MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRV_NAME); MODULE_ALIAS("platform:" DRV_NAME);
MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match);