Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp391882ybl; Tue, 13 Aug 2019 23:10:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzC8UBADyFH4cz7KYtWb0SzQaQQwMko4tz4xnuxcsVFkLHvcSTySXyqZYuNgDDgjT3NFQhL X-Received: by 2002:a62:7790:: with SMTP id s138mr19476717pfc.243.1565763047364; Tue, 13 Aug 2019 23:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565763047; cv=none; d=google.com; s=arc-20160816; b=C6LqPwi66hlXSIz4cdE/Hu5bYlc8bo79OM0LBg7m/76TySAjisIK8GL/WBDA1WPN8V 5+qqH7EZtzFaxDu222F0cJ5qcYBi2tmeB7R9B10Uc8nOBfPpZ+aJF2+fTdRAJLEF6L3q UxEiqFTqjKV0lIEmo4qzm2ru/o9glmnbASm8lqaXEJkND3xvWhnPcvMjhO/9G0LevbUL aINeaRtZqwTviaZKAD+sta11pBLTaV/BLlcqbJDENearhfAvCi9+oUx5uo5awqTSZgvU gEyAQrwEQ5I8Xg64OH6szU4+bTNTtJREfVVU3Im/v6v6bIG/IYOdSXm9zrpxeFBm5Zeu 8Wvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cgF+iQ71N63fzGiwQW4cF1hqYUHS6u6C/HWG5UzaxPs=; b=A29HTQfCUnjsthNPupcllvJ578Hht7za1wVhBBrhnPof1GCzBLYNlH8PFMWpBWU309 WF4XLfp9KZf8g5o7i4OOe0P9hfQI3Da1jWc2zr8EZZAuSZcHoqjYxQk2Fm6gdO6Fk6xT vwXcxqW7vrgV9CKKrX/qBe/gBCaUvyk19kIX6hMp2CKf7bn2urUGUEO4hFCL0ukwP6ON JmRuQ5NCHyY0qVtr9RWjujA2fuxmzKFjRn1To2PVASYnd/5QbFAVYmU9iw65amBFf0ng Fr8yeMCiPj+zW1af5TAw3orHs4QKHJuQEGg6PP2L7ssokzIbGbd3nb7vKw2jTBJD6HIl Wbvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="f/JFLeR3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z30si2152666pga.346.2019.08.13.23.10.30; Tue, 13 Aug 2019 23:10:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="f/JFLeR3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727738AbfHNGJe (ORCPT + 99 others); Wed, 14 Aug 2019 02:09:34 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46177 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727659AbfHNGJU (ORCPT ); Wed, 14 Aug 2019 02:09:20 -0400 Received: by mail-lf1-f67.google.com with SMTP id n19so10066177lfe.13 for ; Tue, 13 Aug 2019 23:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cgF+iQ71N63fzGiwQW4cF1hqYUHS6u6C/HWG5UzaxPs=; b=f/JFLeR3DcJywbYWdN8lm2tKUulDCXEf9JpBXBUBrF041WiZSdgsyB4Wi9PMvDUjX6 NEPWQAkrBgCH90ub/1Mq2e289lSfxj7EOu17iL2kahf/PiRsQPsVM5gkxIpVBDEQIt8Z R7BEWYAvbPXnsFE6DHJsyjllky7PZdgjgY6oRelW3PBGn3sKabNjeUcz94fyytsnpsPW Dl5tIZhp9o1FklMyxbSIjSW88Cykrke7ZVbuTA7xmUhG6qOcd72iBleye8UmxutefK+d Y36C0TGhkoL6fBBuo2nhUma62HQR2ZZnet7xOtunYR7qALgXG1Xm8ApQYJC/bMVrPXAn Bhkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cgF+iQ71N63fzGiwQW4cF1hqYUHS6u6C/HWG5UzaxPs=; b=j2Qxp68a4qVzJfTpnqOiofCTKVF5BBedYImwrcUaZGyUPqMVcHU5hxH4qSUOF1nBKN kmVaSHuLXzI47sewTzUjw3uPwlx0IUaNIto4zQmIJKuAXm8tHP6E06YeTuYNwfj+okNe QU1D8nEpmyAZQzZ2DbJpmwr+atBmDNGa3kSc26y8vZLiLaaZ1WH5b+6chXU3iIz65T/k FxviN+bs33PUP3ys9DcO2x3PCofd4f/iOYRaBWHxOl9abhzoWTZco0uyW9xTaWHJxlcD noO1dcZkDeWwH6qFc3DQ1zY/eZYE17KfdU4TTAVbYk1k4Hh+rR/ryFoGb3LKkOfeGVIi UGWg== X-Gm-Message-State: APjAAAVjXdkdsA27Vx0GyyZOZjX0zerTHORQzOHfM+NjPwIb0bZcK0Qa thewnNm/qK80fxqZtdMEccY= X-Received: by 2002:a19:5217:: with SMTP id m23mr24260832lfb.124.1565762957909; Tue, 13 Aug 2019 23:09:17 -0700 (PDT) Received: from localhost.localdomain (c213-102-74-69.bredband.comhem.se. [213.102.74.69]) by smtp.gmail.com with ESMTPSA id s10sm3124235ljm.35.2019.08.13.23.09.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 23:09:17 -0700 (PDT) From: codekipper@gmail.com To: maxime.ripard@free-electrons.com, wens@csie.org, linux-sunxi@googlegroups.com Cc: linux-arm-kernel@lists.infradead.org, lgirdwood@gmail.com, broonie@kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, be17068@iperbole.bo.it, Marcus Cooper Subject: [PATCH v5 13/15] ASoC: sun4i-i2s: Add multichannel functionality Date: Wed, 14 Aug 2019 08:08:52 +0200 Message-Id: <20190814060854.26345-14-codekipper@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814060854.26345-1-codekipper@gmail.com> References: <20190814060854.26345-1-codekipper@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcus Cooper The i2s block can be used to pass PCM data over multiple channels and is sometimes used for the audio side of an HDMI connection. Signed-off-by: Marcus Cooper --- sound/soc/sunxi/sun4i-i2s.c | 93 +++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c index a020c3b372a8..a71969167053 100644 --- a/sound/soc/sunxi/sun4i-i2s.c +++ b/sound/soc/sunxi/sun4i-i2s.c @@ -617,41 +617,74 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream, int lines; channels = params_channels(params); - if (channels != 2) { - dev_err(dai->dev, "Unsupported number of channels: %d\n", - channels); - return -EINVAL; - } - - lines = (channels + 1) / 2; + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + if ((channels > dai->driver->playback.channels_max) || + (channels < dai->driver->playback.channels_min)) { + dev_err(dai->dev, "Unsupported number of channels: %d\n", + channels); + return -EINVAL; + } - /* Enable the required output lines */ - regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, - SUN4I_I2S_CTRL_SDO_EN_MASK, - SUN4I_I2S_CTRL_SDO_EN(lines)); - - if (i2s->variant->has_chcfg) { - regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG, - SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM_MASK, - SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM(channels)); - regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG, - SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM_MASK, - SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM(channels)); - } + lines = (channels + 1) / 2; - /* Map the channels for playback and capture */ - i2s->variant->set_txchanmap(i2s, 0, 0x76543210); - i2s->variant->set_rxchanmap(i2s, 0x00003210); + /* Enable the required output lines */ + regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, + SUN4I_I2S_CTRL_SDO_EN_MASK, + SUN4I_I2S_CTRL_SDO_EN(lines)); + + i2s->variant->set_txchanmap(i2s, 0, 0x10); + i2s->variant->set_txchansel(i2s, 0, channels > 1 ? 2:1); + + if (i2s->variant->set_txchanen) + i2s->variant->set_txchanen(i2s, 0, 2); + + if (i2s->variant->has_chcfg) { + regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG, + SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM_MASK, + SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM(channels)); + + if (channels > 2) { + i2s->variant->set_txchanmap(i2s, 1, 0x32); + i2s->variant->set_txchanoffset(i2s, 1); + i2s->variant->set_txchansel(i2s, 1, + channels > 3 ? 2:1); + i2s->variant->set_txchanen(i2s, 1, 2); + } + if (channels > 4) { + i2s->variant->set_txchanmap(i2s, 2, 0x54); + i2s->variant->set_txchanoffset(i2s, 2); + i2s->variant->set_txchansel(i2s, 2, + channels > 5 ? 2:1); + i2s->variant->set_txchanen(i2s, 2, 2); + } + if (channels > 6) { + i2s->variant->set_txchanmap(i2s, 3, 0x76); + i2s->variant->set_txchanoffset(i2s, 3); + i2s->variant->set_txchansel(i2s, 3, + channels > 6 ? 2:1); + i2s->variant->set_txchanen(i2s, 3, 2); + } + } + } else { + if ((channels > dai->driver->capture.channels_max) || + (channels < dai->driver->capture.channels_min)) { + dev_err(dai->dev, "Unsupported number of channels: %d\n", + channels); + return -EINVAL; + } - /* Configure the channels */ - i2s->variant->set_txchansel(i2s, 0, channels); - i2s->variant->set_rxchansel(i2s, channels); + /* Map the channels for capture */ + i2s->variant->set_rxchanmap(i2s, 0x10); + i2s->variant->set_rxchansel(i2s, channels); - if (i2s->variant->set_txchanen) - i2s->variant->set_txchanen(i2s, 0, channels); + if (i2s->variant->set_rxchanen) + i2s->variant->set_rxchanen(i2s, channels); - if (i2s->variant->set_rxchanen) - i2s->variant->set_rxchanen(i2s, channels); + if (i2s->variant->has_chcfg) + regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG, + SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM_MASK, + SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM(channels)); + } switch (params_physical_width(params)) { case 16: -- 2.22.0