From patchwork Thu Jun 5 09:01:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 4304091 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A2A0DBEEA7 for ; Thu, 5 Jun 2014 09:02:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94E7920320 for ; Thu, 5 Jun 2014 09:02:39 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 488A9201B4 for ; Thu, 5 Jun 2014 09:02:38 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 035F92654B0; Thu, 5 Jun 2014 11:02:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 2F70F265611; Thu, 5 Jun 2014 11:02:03 +0200 (CEST) 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 9AA402655DF; Thu, 5 Jun 2014 11:02:01 +0200 (CEST) Received: from mail-pd0-f180.google.com (mail-pd0-f180.google.com [209.85.192.180]) by alsa0.perex.cz (Postfix) with ESMTP id 0139C265468 for ; Thu, 5 Jun 2014 11:01:12 +0200 (CEST) Received: by mail-pd0-f180.google.com with SMTP id y13so805287pdi.11 for ; Thu, 05 Jun 2014 02:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:sender:message-id:from:subject:user-agent:to:cc:in-reply-to :references:mime-version:content-type; bh=CtTUbRohelRETR1r8qJASiMky/Y7gvLZdTqg1OwH428=; b=X3+MhkEppYFDrTxhIz1HY/D3DnrYuolfu6Vgr/Snbhh3xuAzbdEPBMbg5P6zUpO16D KJU7Hhcfbfv7OSWRxKtN5DnJAEg8TuzV4QueAOe8SxS4s4kXngK1XzHZqAm4h/h6jvPc O9Pib5mcgL8pAM1ezTzg602hM6ZHODBk7PCu64yc2mpGEP7glpFzIYcz2RxTQFuEAzRn IurelmeI0pGbzsiZ8eywsORFuMd7c6C58b7Y6icKlAKL5DKZTakNxsGVQOTvSWaCca9F VpXt6+z0DHwx6ugZSzjLhsdnz91q0mOksEFUu3Os68q9l7/pm/XKaSBQmIIEAoxcuwov ZPFA== X-Received: by 10.68.190.74 with SMTP id go10mr75925997pbc.16.1401958871797; Thu, 05 Jun 2014 02:01:11 -0700 (PDT) Received: from remon.gmail.com (49.14.32.202.bf.2iij.net. [202.32.14.49]) by mx.google.com with ESMTPSA id yw3sm20127249pbc.69.2014.06.05.02.01.09 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Jun 2014 02:01:11 -0700 (PDT) Date: Thu, 05 Jun 2014 02:01:11 -0700 (PDT) Message-ID: <87ioofivca.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto User-Agent: Wanderlust/2.14.0 Emacs/23.3 Mule/6.0 To: Mark Brown In-Reply-To: <87mwdrivhe.wl%kuninori.morimoto.gx@gmail.com> References: <87mwdrivhe.wl%kuninori.morimoto.gx@gmail.com> MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: Linux-ALSA , cm-hiep@jinso.co.jp, Liam Girdwood , bd-phuc@jinso.co.jp, nx-nui@jinso.co.jp, Simon , h-inayoshi@jinso.co.jp, m-miura@jinso.co.jp, Kuninori Morimoto , nv-dung@jinso.co.jp Subject: [alsa-devel] [PATCH 3/4] ASoC: fsi: use dmaengine_prep_dma_cyclic() for DMA transfer 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 Current FSI driver is using DMAEngine directly, but, ASoC is requesting to use common DMA transfer method, like snd_dmaengine_pcm_trigger() or dmaengine_pcm_ops. It is difficult to switch at this point, since Renesas driver is also supporting PIO transfer. This patch uses dmaengine_prep_dma_cyclic() instead of dmaengine_prep_slave_single(). It is used in requested method, and is good first step to switch over. Signed-off-by: Kuninori Morimoto --- sound/soc/sh/fsi.c | 94 +++++++++++++++------------------------------------- 1 file changed, 27 insertions(+), 67 deletions(-) diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 820a408..a57eb96 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c @@ -232,10 +232,7 @@ struct fsi_stream { * these are for DMAEngine */ struct dma_chan *chan; - struct work_struct work; int dma_id; - int loop_cnt; - int additional_pos; }; struct fsi_clk { @@ -1281,24 +1278,9 @@ static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io) io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | BUSOP_SET(16, PACKAGE_16BITBUS_STREAM); - io->loop_cnt = 2; /* push 1st, 2nd period first, then 3rd, 4th... */ - io->additional_pos = 0; - return 0; } -static dma_addr_t fsi_dma_get_area(struct fsi_stream *io, int additional) -{ - struct snd_pcm_runtime *runtime = io->substream->runtime; - int period = io->period_pos + additional; - - if (period >= runtime->periods) - period = 0; - - return runtime->dma_addr + - samples_to_bytes(runtime, period * io->period_samples); -} - static void fsi_dma_complete(void *data) { struct fsi_stream *io = (struct fsi_stream *)data; @@ -1307,53 +1289,37 @@ static void fsi_dma_complete(void *data) fsi_pointer_update(io, io->period_samples); fsi_count_fifo_err(fsi); - fsi_stream_transfer(io); } -static void fsi_dma_do_work(struct work_struct *work) +static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io) { - struct fsi_stream *io = container_of(work, struct fsi_stream, work); - struct fsi_priv *fsi = fsi_stream_to_priv(io); - struct snd_soc_dai *dai; + struct snd_soc_dai *dai = fsi_get_dai(io->substream); + struct snd_pcm_substream *substream = io->substream; struct dma_async_tx_descriptor *desc; - struct snd_pcm_runtime *runtime; - enum dma_data_direction dir; int is_play = fsi_stream_is_play(fsi, io); - int len, i; - dma_addr_t buf; - - if (!fsi_stream_is_working(fsi, io)) - return; - - dai = fsi_get_dai(io->substream); - runtime = io->substream->runtime; - dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE; - len = samples_to_bytes(runtime, io->period_samples); - - for (i = 0; i < io->loop_cnt; i++) { - buf = fsi_dma_get_area(io, io->additional_pos); - - desc = dmaengine_prep_slave_single(io->chan, buf, len, dir, - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); - if (!desc) { - dev_err(dai->dev, "dmaengine_prep_slave_sg() fail\n"); - return; - } - - desc->callback = fsi_dma_complete; - desc->callback_param = io; - - if (dmaengine_submit(desc) < 0) { - dev_err(dai->dev, "tx_submit() fail\n"); - return; - } + enum dma_data_direction dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE; + int ret = -EIO; + + desc = dmaengine_prep_dma_cyclic(io->chan, + substream->runtime->dma_addr, + snd_pcm_lib_buffer_bytes(substream), + snd_pcm_lib_period_bytes(substream), + dir, + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); + if (!desc) { + dev_err(dai->dev, "dmaengine_prep_dma_cyclic() fail\n"); + goto fsi_dma_transfer_err; + } - dma_async_issue_pending(io->chan); + desc->callback = fsi_dma_complete; + desc->callback_param = io; - io->additional_pos = 1; + if (dmaengine_submit(desc) < 0) { + dev_err(dai->dev, "tx_submit() fail\n"); + goto fsi_dma_transfer_err; } - io->loop_cnt = 1; + dma_async_issue_pending(io->chan); /* * FIXME @@ -1370,13 +1336,11 @@ static void fsi_dma_do_work(struct work_struct *work) fsi_reg_write(fsi, DIFF_ST, 0); } } -} -static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io) -{ - schedule_work(&io->work); + ret = 0; - return 0; +fsi_dma_transfer_err: + return ret; } static int fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, @@ -1437,15 +1401,11 @@ static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io, struct dev return fsi_stream_probe(fsi, dev); } - INIT_WORK(&io->work, fsi_dma_do_work); - return 0; } static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io) { - cancel_work_sync(&io->work); - fsi_stream_stop(fsi, io); if (io->chan) @@ -1618,9 +1578,9 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, if (!ret) ret = fsi_hw_startup(fsi, io, dai->dev); if (!ret) - ret = fsi_stream_transfer(io); + ret = fsi_stream_start(fsi, io); if (!ret) - fsi_stream_start(fsi, io); + ret = fsi_stream_transfer(io); break; case SNDRV_PCM_TRIGGER_STOP: if (!ret)