From patchwork Mon Mar 16 04:47:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6015461 Return-Path: X-Original-To: patchwork-alsa-devel@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 950FBBF90F for ; Mon, 16 Mar 2015 04:56:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9145A203E3 for ; Mon, 16 Mar 2015 04:56:03 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 31557203DA for ; Mon, 16 Mar 2015 04:56:02 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 52A2126066A; Mon, 16 Mar 2015 05:56:01 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id DC95C2605AB; Mon, 16 Mar 2015 05:51:04 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0A1162610A1; Mon, 16 Mar 2015 05:51:03 +0100 (CET) Received: from relmlie1.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa0.perex.cz (Postfix) with ESMTP id D35342605AB for ; Mon, 16 Mar 2015 05:47:49 +0100 (CET) Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 16 Mar 2015 13:47:48 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 43D834832B; Mon, 16 Mar 2015 13:47:48 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 2AD902806E; Mon, 16 Mar 2015 13:47:48 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id 243B22806D; Mon, 16 Mar 2015 13:47:48 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac2.idc.renesas.com with ESMTP id PAA16060; Mon, 16 Mar 2015 13:47:48 +0900 X-IronPort-AV: E=Sophos;i="5.11,407,1422889200"; d="scan'208";a="181988492" Received: from mail-sg1lp0092.outbound.protection.outlook.com (HELO APAC01-SG1-obe.outbound.protection.outlook.com) ([207.46.51.92]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 16 Mar 2015 13:47:47 +0900 Received: from morimoto-PC.renesas.com (211.11.155.132) by HKNPR06MB308.apcprd06.prod.outlook.com (10.141.37.28) with Microsoft SMTP Server (TLS) id 15.1.112.19; Mon, 16 Mar 2015 04:47:44 +0000 Message-ID: <87wq2him5h.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 To: Mark Brown In-Reply-To: <87egopk13d.wl%kuninori.morimoto.gx@renesas.com> References: <87egopk13d.wl%kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Mon, 16 Mar 2015 04:47:44 +0000 X-Originating-IP: [211.11.155.132] X-ClientProxiedBy: OS1PR01CA0022.jpnprd01.prod.outlook.com (25.161.225.160) To HKNPR06MB308.apcprd06.prod.outlook.com (10.141.37.28) Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HKNPR06MB308; X-Forefront-Antispam-Report: BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(83506001)(76176999)(54356999)(62966003)(77096005)(53416004)(77156002)(86362001)(87976001)(42186005)(19580395003)(19580405001)(110136001)(122386002)(229853001)(40100003)(92566002)(50986999)(2950100001)(66066001)(47776003)(50466002)(23726002)(46406003)(33646002)(46102003)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:HKNPR06MB308; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5002010)(5005006); SRVR:HKNPR06MB308; BCL:0; PCL:0; RULEID:; SRVR:HKNPR06MB308; X-Forefront-PRVS: 05177D47DC X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2015 04:47:44.5915 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKNPR06MB308 Cc: Linux-ALSA , Simon , shiiba , Liam Girdwood , Das Biju Subject: [alsa-devel] [PATCH 12/12 v2] ASoC: rsnd: add DPCM based sampling rate convert X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kuninori Morimoto This patch supports DPCM based sampling rate convert on Renesas sound driver. It assumes... 1. SRC is implemented as FE 2. BE dai_link supports .be_hw_params_fixup Signed-off-by: Kuninori Morimoto --- v1 -> v2 - no change sound/soc/sh/rcar/core.c | 9 +++++++++ sound/soc/sh/rcar/rsnd.h | 6 ++++++ sound/soc/sh/rcar/src.c | 49 ++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index 929c282..b3851cf 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -742,6 +742,15 @@ static int rsnd_pcm_open(struct snd_pcm_substream *substream) static int rsnd_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { + struct snd_soc_dai *dai = rsnd_substream_to_dai(substream); + struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); + struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); + int ret; + + ret = rsnd_dai_call(hw_params, io, substream, hw_params); + if (ret) + return ret; + return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); } diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index be1ca7a..4ada02b 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -240,6 +240,9 @@ struct rsnd_mod_ops { int (*clk)(struct rsnd_mod *mod, int enable); int (*pcm_new)(struct rsnd_mod *mod, struct snd_soc_pcm_runtime *rtd); + int (*hw_params)(struct rsnd_mod *mod, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params); int (*fallback)(struct rsnd_mod *mod, struct rsnd_priv *priv); }; @@ -266,6 +269,7 @@ struct rsnd_mod { * * 31 bit is always called (see __rsnd_mod_call) * 31 0: clk + * 31 0: hw_params */ #define __rsnd_mod_shift_probe 0 #define __rsnd_mod_shift_remove 0 @@ -276,6 +280,7 @@ struct rsnd_mod { #define __rsnd_mod_shift_pcm_new 3 #define __rsnd_mod_shift_fallback 4 #define __rsnd_mod_shift_clk 31 /* always called */ +#define __rsnd_mod_shift_hw_params 31 /* always called */ #define __rsnd_mod_call_probe 0 #define __rsnd_mod_call_remove 1 @@ -286,6 +291,7 @@ struct rsnd_mod { #define __rsnd_mod_call_pcm_new 0 #define __rsnd_mod_call_fallback 0 #define __rsnd_mod_call_clk 0 +#define __rsnd_mod_call_hw_params 0 #define rsnd_mod_to_priv(mod) (rsnd_io_to_priv(rsnd_mod_to_io(mod))) #define rsnd_mod_to_dma(mod) (&(mod)->dma) diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c index 83032ee..f53f625 100644 --- a/sound/soc/sh/rcar/src.c +++ b/sound/soc/sh/rcar/src.c @@ -22,12 +22,13 @@ struct rsnd_src { struct rsnd_src_platform_info *info; /* rcar_snd.h */ struct rsnd_mod mod; + u32 convert_rate; /* sampling rate convert */ int err; }; #define RSND_SRC_NAME_SIZE 16 -#define rsnd_src_convert_rate(p) ((p)->info->convert_rate) +#define rsnd_src_convert_rate(s) ((s)->convert_rate) #define rsnd_src_of_node(priv) \ of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") @@ -288,7 +289,43 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod) return 0; } -static int rsnd_src_init(struct rsnd_mod *mod) +static int rsnd_src_hw_params(struct rsnd_mod *mod, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *fe_params) +{ + struct rsnd_src *src = rsnd_mod_to_src(mod); + struct snd_soc_pcm_runtime *fe = substream->private_data; + + /* default value (mainly for non-DT) */ + src->convert_rate = src->info->convert_rate; + + /* + * SRC assumes that it is used under DPCM if user want to use + * sampling rate convert. Then, SRC should be FE. + * And then, this function will be called *after* BE settings. + * this means, each BE already has fixuped hw_params. + * see + * dpcm_fe_dai_hw_params() + * dpcm_be_dai_hw_params() + */ + if (fe->dai_link->dynamic) { + int stream = substream->stream; + struct snd_soc_dpcm *dpcm; + struct snd_pcm_hw_params *be_params; + + list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { + be_params = &dpcm->hw_params; + + if (params_rate(fe_params) != params_rate(be_params)) + src->convert_rate = params_rate(be_params); + } + } + + return 0; +} + +static int rsnd_src_init(struct rsnd_mod *mod, + struct rsnd_priv *priv) { struct rsnd_src *src = rsnd_mod_to_src(mod); @@ -313,6 +350,8 @@ static int rsnd_src_quit(struct rsnd_mod *mod, dev_warn(dev, "%s[%d] under/over flow err = %d\n", rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); + src->convert_rate = 0; + return 0; } @@ -472,7 +511,7 @@ static int rsnd_src_init_gen1(struct rsnd_mod *mod, { int ret; - ret = rsnd_src_init(mod); + ret = rsnd_src_init(mod, priv); if (ret < 0) return ret; @@ -520,6 +559,7 @@ static struct rsnd_mod_ops rsnd_src_gen1_ops = { .start = rsnd_src_start_gen1, .stop = rsnd_src_stop_gen1, .clk = rsnd_mod_clk, + .hw_params = rsnd_src_hw_params, }; /* @@ -756,7 +796,7 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod, { int ret; - ret = rsnd_src_init(mod); + ret = rsnd_src_init(mod, priv); if (ret < 0) return ret; @@ -801,6 +841,7 @@ static struct rsnd_mod_ops rsnd_src_gen2_ops = { .start = rsnd_src_start_gen2, .stop = rsnd_src_stop_gen2, .clk = rsnd_mod_clk, + .hw_params = rsnd_src_hw_params, }; struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)