From patchwork Tue May 12 09:26:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xing Zheng X-Patchwork-Id: 6386741 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 07820BEEE1 for ; Tue, 12 May 2015 09:32:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DAB50203ED for ; Tue, 12 May 2015 09:32:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE3C3203B5 for ; Tue, 12 May 2015 09:32:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ys6Xh-0004WI-Qa; Tue, 12 May 2015 09:32:01 +0000 Received: from mail-pa0-x234.google.com ([2607:f8b0:400e:c03::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ys6XC-0004Cu-1R; Tue, 12 May 2015 09:31:31 +0000 Received: by pabsx10 with SMTP id sx10so2167833pab.3; Tue, 12 May 2015 02:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yRVClYSZKaBHIesP2qVNP37my7utcRCogYi4vUDCdKg=; b=SPzZ2AqQykWYy6TBWFg8ll+GwMyfVhFTSLyjj3kvy/StqouKv3mVX9b4Tc/cqbYDgB P7UXDlZ4DiQeHAvu6gRETZ3sKxNPVNdHa31X95ivhKdNo8r+UeoiDiB+Hr6QUEMC1E0r L9HsGGIZ3toDl8KooGX64kcnUAboudPcNm/OmPvOvqC1O2Y80z1T3LiWEFXynJBfo6tM 1dIt+KFzrAtWlkjo003/PwauVkDA9DfIt5u4GAozv2XDxcoPm6HUo1yHBdPnwfxkJyIy hsMDbc8VGNbdBSZzXjdLBXRGPE7mR49iO9f6gszkQoew8ImCKv46ljJyZGhuBupUnTDn UQTw== X-Received: by 10.70.134.35 with SMTP id ph3mr26194790pdb.91.1431423069109; Tue, 12 May 2015 02:31:09 -0700 (PDT) Received: from localhost.localdomain ([103.47.144.18]) by mx.google.com with ESMTPSA id pw9sm15635818pac.27.2015.05.12.02.31.01 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 May 2015 02:31:07 -0700 (PDT) From: Xing Zheng X-Google-Original-From: Xing Zheng To: dgreid@chromium.org, dianders@chromium.org, heiko@sntech.de, sonnyrao@chromium.org Subject: [PATCH 2/4] ASoC: rockchip: add rockchip machine driver for max98090 Date: Tue, 12 May 2015 17:26:35 +0800 Message-Id: <1431422797-31903-3-git-send-email-zhengxing@rock-chips.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1431422797-31903-1-git-send-email-zhengxing@rock-chips.com> References: <1431422797-31903-1-git-send-email-zhengxing@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150512_023130_221168_09DA0087 X-CRM114-Status: GOOD ( 18.62 ) X-Spam-Score: 0.9 (/) Cc: alsa-devel@alsa-project.org, zhengxing , Takashi Iwai , linux-kernel@vger.kernel.org, Liam Girdwood , Jaroslav Kysela , linux-rockchip@lists.infradead.org, Mark Brown , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY,URIBL_BLACK autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: zhengxing The driver is used for rockchip board using a max98090. Test on RK3288 with max98090. Signed-off-by: zhengxing --- sound/soc/rockchip/Kconfig | 10 ++ sound/soc/rockchip/Makefile | 2 + sound/soc/rockchip/rockchip_machine_driver.c | 6 + sound/soc/rockchip/rockchip_machine_driver.h | 6 + sound/soc/rockchip/rockchip_max98090.c | 185 ++++++++++++++++++++++++++ 5 files changed, 209 insertions(+) create mode 100644 sound/soc/rockchip/rockchip_max98090.c diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig index e3f51cf..057c457 100644 --- a/sound/soc/rockchip/Kconfig +++ b/sound/soc/rockchip/Kconfig @@ -21,3 +21,13 @@ config SND_SOC_ROCKCHIP_MACHINE help Say Y or M if you want to add support for Machine driver for Rockchip I2S device. + +config SND_SOC_ROCKCHIP_MAX98090 + tristate "ASoC support for Rockchip boards using a MAX98090 codec" + depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB + select SND_SOC_ROCKCHIP_I2S + select SND_SOC_MAX98090 + select SND_SOC_TS3A227E + help + Say Y or M here if you want to add support for SoC audio on Rockchip + boards using the MAX98090 codec, such as Veyron. diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile index 47d7c84..23e9b64 100644 --- a/sound/soc/rockchip/Makefile +++ b/sound/soc/rockchip/Makefile @@ -5,5 +5,7 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o # ROCKCHIP Machine Support snd-soc-rockchip-machine-objs := rockchip_machine_driver.o +snd-soc-rockchip-max98090-objs := rockchip_max98090.o obj-$(CONFIG_SND_SOC_ROCKCHIP_MACHINE) += snd-soc-rockchip-machine.o +obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o diff --git a/sound/soc/rockchip/rockchip_machine_driver.c b/sound/soc/rockchip/rockchip_machine_driver.c index 34cae3f..ee09c62 100644 --- a/sound/soc/rockchip/rockchip_machine_driver.c +++ b/sound/soc/rockchip/rockchip_machine_driver.c @@ -36,6 +36,12 @@ /* the sound cards of rockchp supports. */ static struct rk_snd_soc_cards rk_snd_cards[] = { +#ifdef CONFIG_SND_SOC_ROCKCHIP_MAX98090 + { + .name = RK_SND_CARD_MAX98090, + .preinit = rk_machine_preinit_max98090, + }, +#endif }; static int snd_rk_mc_preinit(void) diff --git a/sound/soc/rockchip/rockchip_machine_driver.h b/sound/soc/rockchip/rockchip_machine_driver.h index 39a7a77..903ed94 100644 --- a/sound/soc/rockchip/rockchip_machine_driver.h +++ b/sound/soc/rockchip/rockchip_machine_driver.h @@ -27,4 +27,10 @@ struct rk_snd_soc_cards { int (*preinit)(struct rk_snd_soc_cards *soc_card); }; +/* the sound cards of rockchp supports. */ +#ifdef CONFIG_SND_SOC_ROCKCHIP_MAX98090 +#define RK_SND_CARD_MAX98090 "rk_snd_max98090" +int rk_machine_preinit_max98090(struct rk_snd_soc_cards *soc_card); +#endif + #endif /* __ROCKCHIP_MACHINE_DRIVER_H__ */ diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c new file mode 100644 index 0000000..f56dc69c --- /dev/null +++ b/sound/soc/rockchip/rockchip_max98090.c @@ -0,0 +1,185 @@ +/* + * Rockchip machine ASoC driver for boards using a MAX90809 CODEC. + * + * Copyright (c) 2014, ROCKCHIP CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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, see . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rockchip_i2s.h" +#include "../codecs/ts3a227e.h" +#include "rockchip_machine_driver.h" + +static const struct snd_soc_dapm_widget rk_dapm_widgets[] = { + SND_SOC_DAPM_HP("Headphone", NULL), + SND_SOC_DAPM_MIC("Headset Mic", NULL), + SND_SOC_DAPM_MIC("Int Mic", NULL), + SND_SOC_DAPM_SPK("Speaker", NULL), +}; + +static const struct snd_soc_dapm_route rk_audio_map[] = { + {"IN34", NULL, "Headset Mic"}, + {"IN34", NULL, "MICBIAS"}, + {"MICBIAS", NULL, "Headset Mic"}, + {"DMICL", NULL, "Int Mic"}, + {"Headphone", NULL, "HPL"}, + {"Headphone", NULL, "HPR"}, + {"Speaker", NULL, "SPKL"}, + {"Speaker", NULL, "SPKR"}, +}; + +static const struct snd_kcontrol_new rk_mc_controls[] = { + SOC_DAPM_PIN_SWITCH("Headphone"), + SOC_DAPM_PIN_SWITCH("Headset Mic"), + SOC_DAPM_PIN_SWITCH("Int Mic"), + SOC_DAPM_PIN_SWITCH("Speaker"), +}; + +static int rk_aif1_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + int ret = 0; + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *codec_dai = rtd->codec_dai; + int mclk; + + switch (params_rate(params)) { + case 48000: + mclk = 12288000; + break; + case 44100: + mclk = 11289600; + break; + default: + return -EINVAL; + } + + ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, + SND_SOC_CLOCK_OUT); + if (ret < 0) { + dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret); + return ret; + } + + ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, + SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret); + return ret; + } + + return ret; +} + +static int rk_init(struct snd_soc_pcm_runtime *runtime) +{ + struct snd_soc_codec *codec = runtime->codec; + struct snd_soc_dapm_context *dapm = &codec->dapm; + struct snd_soc_card *card = runtime->card; + struct rk_mc_private *drv = snd_soc_card_get_drvdata(card); + + card->dapm.idle_bias_off = true; + + snd_soc_dapm_enable_pin(dapm, "Headset Mic"); + snd_soc_dapm_enable_pin(dapm, "Headphone"); + snd_soc_dapm_enable_pin(dapm, "Speaker"); + snd_soc_dapm_enable_pin(dapm, "Int Mic"); + + snd_soc_dapm_force_enable_pin(dapm, "MICBIAS"); + + snd_soc_dapm_sync(dapm); + + /* Enable headphone jack detection */ + return snd_soc_card_jack_new(card, "Headset Jack", + SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | + SND_JACK_BTN_0 | SND_JACK_BTN_1 | + SND_JACK_BTN_2 | SND_JACK_BTN_3, + &drv->headphone_jack, + NULL, + 0); +} + +static int rk_98090_headset_init(struct snd_soc_component *component) +{ + struct snd_soc_card *card = component->card; + struct rk_mc_private *drv = snd_soc_card_get_drvdata(card); + + return ts3a227e_enable_jack_detect(component, &drv->headphone_jack); +} + +static struct snd_soc_ops rk_aif1_ops = { + .hw_params = rk_aif1_hw_params, +}; + +static struct snd_soc_aux_dev rk_98090_headset_dev = { + .name = "Headset Chip", + .init = rk_98090_headset_init, +}; + +static struct snd_soc_dai_link rk_dailink = { + .name = "max98090", + .stream_name = "Audio", + .codec_dai_name = "HiFi", + .init = rk_init, + .ops = &rk_aif1_ops, + /* set max98090 as slave */ + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, +}; + +/* rockchip machine driver for max98090 */ +static struct snd_soc_card snd_soc_card_rk = { + .name = "ROCKCHIP-I2S", + .dai_link = &rk_dailink, + .num_links = 1, + .aux_dev = &rk_98090_headset_dev, + .num_aux_devs = 1, + .dapm_widgets = rk_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets), + .dapm_routes = rk_audio_map, + .num_dapm_routes = ARRAY_SIZE(rk_audio_map), + .controls = rk_mc_controls, + .num_controls = ARRAY_SIZE(rk_mc_controls), +}; + +int rk_machine_preinit_max98090(struct rk_snd_soc_cards *soc_card) +{ + if (soc_card && !strcmp(soc_card->name, RK_SND_CARD_MAX98090)) { + /* pre-init snd card info. */ + soc_card->card = &snd_soc_card_rk; + strcpy(soc_card->compatible, + "rockchip,rockchip-audio-max98090"); + + return 0; + } + + return -ENODEV; +} + +MODULE_AUTHOR("jianqun "); +MODULE_AUTHOR("Xing Zheng "); +MODULE_DESCRIPTION("Rockchip max98090 machine ASoC driver"); +MODULE_LICENSE("GPL v2");