All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Guanqun <guanqun.lu@intel.com>
To: ALSA <alsa-devel@alsa-project.org>, Lu Guanqun <guanqun.lu@intel.com>
Cc: Takashi Iwai <tiwai@suse.de>, Koul Vinod <vinod.koul@intel.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Liam Girdwood <lrg@ti.com>,
	Wang Xingchao <xingchao.wang@intel.com>
Subject: [PATCH v2 03/10] ASoC: mrst_machine: add moorestown machine driver
Date: Fri, 06 May 2011 13:46:14 +0800	[thread overview]
Message-ID: <20110506054613.26312.16829.stgit@localhost> (raw)
In-Reply-To: <20110506053852.26312.79083.stgit@localhost>

This machine driver glues upd9976 codec driver and sst_platform driver.

Playback via headphone and internal speaker is supported.  To note: This
internal speaker needs an extra GPIO to control its power. And these two output
devices can be enabled and disabled independently.

Signed-off-by: Lu Guanqun <guanqun.lu@intel.com>
Signed-off-by: Wang Xingchao <xingchao.wang@intel.com>
---
 sound/soc/mid-x86/Kconfig        |   12 ++
 sound/soc/mid-x86/Makefile       |    2 
 sound/soc/mid-x86/mrst_machine.c |  194 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/mid-x86/mrst_machine.c

diff --git a/sound/soc/mid-x86/Kconfig b/sound/soc/mid-x86/Kconfig
index 2935042..f76acba 100644
--- a/sound/soc/mid-x86/Kconfig
+++ b/sound/soc/mid-x86/Kconfig
@@ -10,5 +10,17 @@ config SND_MFLD_MACHINE
           Say Y if you have such a device
           If unsure select "N".
 
+config SND_MRST_MACHINE
+	tristate "SoC Machine Audio Driver for Intel Moorestown Platform"
+	depends on INTEL_SCU_IPC
+	depends on SND_INTEL_SST
+	select SND_SOC_UPD9976
+	select SND_SST_PLATFORM
+	help
+	  This adds support for ASoC machine driver for Intel(R) MID Moorestown platform.
+	  It is used as ALSA device in audio substream in Intel(R) MID devices.
+	  Say Y if you have such a device.
+	  If unsure, select 'N'.
+
 config SND_SST_PLATFORM
 	tristate
diff --git a/sound/soc/mid-x86/Makefile b/sound/soc/mid-x86/Makefile
index 6398833..d0f2c29 100644
--- a/sound/soc/mid-x86/Makefile
+++ b/sound/soc/mid-x86/Makefile
@@ -1,5 +1,7 @@
 snd-soc-sst-platform-objs := sst_platform.o
 snd-soc-mfld-machine-objs := mfld_machine.o
+snd-soc-mrst-machine-objs := mrst_machine.o
 
 obj-$(CONFIG_SND_SST_PLATFORM) += snd-soc-sst-platform.o
 obj-$(CONFIG_SND_MFLD_MACHINE) += snd-soc-mfld-machine.o
+obj-$(CONFIG_SND_MRST_MACHINE) += snd-soc-mrst-machine.o
diff --git a/sound/soc/mid-x86/mrst_machine.c b/sound/soc/mid-x86/mrst_machine.c
new file mode 100644
index 0000000..10e4d40
--- /dev/null
+++ b/sound/soc/mid-x86/mrst_machine.c
@@ -0,0 +1,194 @@
+/*
+ *  mrst_machine.c - ASoC Machine driver for Intel Moorestown MID platform
+ *
+ *  Copyright (C) 2011 Intel Corporation
+ *
+ *  Maintainer:
+ *              Lu Guanqun <guanqun.lu@intel.com>
+ *              Wang Xingchao <xingchao.wang@intel.com>
+ *
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+static const struct snd_kcontrol_new mrst_snd_controls[] = {
+	SOC_DAPM_PIN_SWITCH("Headphone"),
+	SOC_DAPM_PIN_SWITCH("Speaker"),
+};
+
+/*
+ * GPIO pin to power on/off Internal Speaker
+ */
+static int mrst_gpio_amp;
+
+static int mrst_speaker_event(struct snd_soc_dapm_widget *widget,
+			      struct snd_kcontrol *control, int event)
+{
+	if (mrst_gpio_amp)
+		gpio_set_value_cansleep(mrst_gpio_amp,
+					SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
+static const struct snd_soc_dapm_widget mrst_audio_widgets[] = {
+	SND_SOC_DAPM_HP("Headphone", NULL),
+	SND_SOC_DAPM_SPK("Speaker", mrst_speaker_event),
+};
+
+static const struct snd_soc_dapm_route mrst_audio_map[] = {
+	{"HPINL", NULL, "PREOUTL"},
+	{"HPINR", NULL, "PREOUTR"},
+
+	{"Headphone", NULL, "HPOUTL"},
+	{"Headphone", NULL, "HPOUTR"},
+
+	{"Speaker", NULL, "PREOUTL"},
+	{"Speaker", NULL, "PREOUTR"},
+};
+
+static int mrst_audio_init(struct snd_soc_pcm_runtime *runtime)
+{
+	struct snd_soc_codec *codec = runtime->codec;
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+
+	snd_soc_dapm_nc_pin(dapm, "LINEINL");
+	snd_soc_dapm_nc_pin(dapm, "LINEINR");
+	snd_soc_dapm_nc_pin(dapm, "LINEOUTL");
+	snd_soc_dapm_nc_pin(dapm, "LINEOUTR");
+
+	snd_soc_dapm_disable_pin(dapm, "Headphone");
+	snd_soc_dapm_enable_pin(dapm, "Speaker");
+
+	snd_soc_dapm_sync(dapm);
+
+	return 0;
+}
+
+static int mrst_hw_params(struct snd_pcm_substream *substream,
+			  struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	int ret;
+
+	ret = snd_soc_dai_set_fmt(codec_dai,
+				  SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM);
+
+	return ret;
+}
+
+static struct snd_soc_ops mrst_audio_ops = {
+	.hw_params = mrst_hw_params,
+};
+
+struct snd_soc_dai_link mrst_dailinks[] = {
+	{
+		.name = "Moorestown Audio",
+		.stream_name = "Audio",
+		.cpu_dai_name = "Headset-cpu-dai",
+		.codec_dai_name = "upd9976-audio",
+		.codec_name = "upd9976",
+		.platform_name = "sst-platform",
+		.init = mrst_audio_init,
+		.ops = &mrst_audio_ops,
+	},
+};
+
+static struct snd_soc_card snd_soc_card_mrst = {
+	.name = "moorestown_audio",
+
+	.dai_link = mrst_dailinks,
+	.num_links = ARRAY_SIZE(mrst_dailinks),
+
+	.controls = mrst_snd_controls,
+	.num_controls = ARRAY_SIZE(mrst_snd_controls),
+	.dapm_widgets = mrst_audio_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(mrst_audio_widgets),
+	.dapm_routes = mrst_audio_map,
+	.num_dapm_routes = ARRAY_SIZE(mrst_audio_map),
+};
+
+static int __devinit snd_mrst_audio_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	if (pdev->dev.platform_data) {
+		mrst_gpio_amp = *(int *)pdev->dev.platform_data;
+		if (gpio_request_one(mrst_gpio_amp,
+				     GPIOF_OUT_INIT_LOW, "amp power"))
+			mrst_gpio_amp = 0;
+	}
+
+	snd_soc_card_mrst.dev = &pdev->dev;
+	ret = snd_soc_register_card(&snd_soc_card_mrst);
+	if (ret)
+		goto fail_register_card;
+
+	return 0;
+
+fail_register_card:
+	if (mrst_gpio_amp)
+		gpio_free(mrst_gpio_amp);
+	return ret;
+}
+
+static int __devexit snd_mrst_audio_remove(struct platform_device *pdev)
+{
+	if (mrst_gpio_amp)
+		gpio_free(mrst_gpio_amp);
+	snd_soc_unregister_card(&snd_soc_card_mrst);
+	return 0;
+}
+
+static struct platform_driver snd_mrst_audio_driver = {
+	.driver = {
+		.owner = THIS_MODULE,
+		.name = "pmic_audio",
+	},
+	.probe = snd_mrst_audio_probe,
+	.remove = __devexit_p(snd_mrst_audio_remove),
+};
+
+static int __init snd_mrst_driver_init(void)
+{
+	return platform_driver_register(&snd_mrst_audio_driver);
+}
+module_init(snd_mrst_driver_init);
+
+static void __exit snd_mrst_driver_exit(void)
+{
+	platform_driver_unregister(&snd_mrst_audio_driver);
+}
+module_exit(snd_mrst_driver_exit);
+
+MODULE_DESCRIPTION("ASoC Intel(R) MID Moorestown Machine Driver");
+MODULE_AUTHOR("Lu Guanqun <guanqun.lu@intel.com>");
+MODULE_AUTHOR("Wang Xingchao <xingchao.wang@intel.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:mrst-audio");

  parent reply	other threads:[~2011-05-06  5:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-06  5:45 [PATCH v2 00/10] ASoC Support For Moorestown Lu Guanqun
2011-05-06  5:46 ` [PATCH v2 01/10] ASoC: upd9976: Add Renesas uPD9976 codec driver Lu Guanqun
2011-05-06 10:17   ` Mark Brown
2011-05-07 14:21     ` Lu Guanqun
2011-05-07 14:27       ` Mark Brown
2011-05-07 14:43         ` Lu Guanqun
2011-05-06  5:46 ` [PATCH v2 02/10] ASoC: sst_platform: modify current cpu dai driver to suit the needs for moorestown platform Lu Guanqun
2011-05-06  5:46 ` Lu Guanqun [this message]
2011-05-06  5:46 ` [PATCH v2 04/10] ASoC: upd9976: add capture ability for dai driver Lu Guanqun
2011-05-06  5:46 ` [PATCH v2 05/10] ASoC: upd9976: add DMIC support Lu Guanqun
2011-05-06 11:07   ` Mark Brown
2011-05-06  5:46 ` [PATCH v2 06/10] ASoC: upd9976: add Analog MIC support Lu Guanqun
2011-05-06  5:46 ` [PATCH v2 07/10] ASoC: upd9976: add jack detection function Lu Guanqun
2011-05-06 12:53   ` Mark Brown
2011-05-06  5:46 ` [PATCH v2 08/10] ASoC: mrst_machine: add capture functionality Lu Guanqun
2011-05-06  5:46 ` [PATCH v2 09/10] ASoC: mrst_machine: add jack detection support Lu Guanqun
2011-05-06  5:46 ` [PATCH v2 10/10] ASoC: mrst_machine: add initial config to machine driver Lu Guanqun
2011-05-06 12:54   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110506054613.26312.16829.stgit@localhost \
    --to=guanqun.lu@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=lrg@ti.com \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    --cc=xingchao.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.