From patchwork Mon Nov 12 05:34:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mukunda,Vijendar" X-Patchwork-Id: 10678125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 993FE14BA for ; Mon, 12 Nov 2018 05:32:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83C4529E28 for ; Mon, 12 Nov 2018 05:32:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7526A29E3A; Mon, 12 Nov 2018 05:32:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D80429E28 for ; Mon, 12 Nov 2018 05:32:50 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 04EA926792F; Mon, 12 Nov 2018 06:32:49 +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 8DA0C267A7E; Mon, 12 Nov 2018 06:32:46 +0100 (CET) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-eopbgr810058.outbound.protection.outlook.com [40.107.81.58]) by alsa0.perex.cz (Postfix) with ESMTP id 0FC7F2677E4 for ; Mon, 12 Nov 2018 06:32:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tp7HEclraTkGRT3T+PPVhue20IIJzbgWXrHx5uEldTs=; b=cz3HfFrz2O2gEa/cDfOc5L6DsmSphpVaVA84VKyXgJdeWc/Z/iIMQeaCTHWZ4XVtxS/Oi/2An6NZ6TFmdW7LNMdoEC+fMMT1jOZYak3Vr6Yvsg0m6SgOEBXfjSj6XY6Yaxx15zZ9nb1NmVbyvFz2Sb3Y3UucXdyPuTEP+58B+n8= Received: from BN6PR1201CA0010.namprd12.prod.outlook.com (2603:10b6:405:4c::20) by CY1PR12MB0618.namprd12.prod.outlook.com (2a01:111:e400:c43c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.20; Mon, 12 Nov 2018 05:32:41 +0000 Received: from CO1NAM03FT026.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::201) by BN6PR1201CA0010.outlook.office365.com (2603:10b6:405:4c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1294.21 via Frontend Transport; Mon, 12 Nov 2018 05:32:40 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT026.mail.protection.outlook.com (10.152.80.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1339.10 via Frontend Transport; Mon, 12 Nov 2018 05:32:39 +0000 Received: from LinuxHost.amd.com (10.34.1.3) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Sun, 11 Nov 2018 23:32:37 -0600 From: Vijendar Mukunda To: Date: Mon, 12 Nov 2018 11:04:57 +0530 Message-ID: <1542000903-19020-7-git-send-email-Vijendar.Mukunda@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542000903-19020-1-git-send-email-Vijendar.Mukunda@amd.com> References: <1542000903-19020-1-git-send-email-Vijendar.Mukunda@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(346002)(376002)(396003)(136003)(39860400002)(2980300002)(428003)(199004)(189003)(81166006)(8676002)(81156014)(8936002)(68736007)(47776003)(50226002)(106466001)(72206003)(39060400002)(305945005)(2906002)(6666004)(104016004)(356004)(36756003)(76176011)(11346002)(5660300001)(478600001)(426003)(1671002)(336012)(186003)(26005)(126002)(53416004)(50466002)(77096007)(14444005)(48376002)(7696005)(51416003)(86362001)(19627235002)(476003)(2616005)(53936002)(105586002)(16586007)(316002)(54906003)(446003)(4326008)(97736004)(109986005)(486006)(42413003)(266003)(32563001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0618; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT026; 1:uNnbUqtQaYBzPoIEW6J3bmxflO823VTG5WIRdeVCRyL2jTLg5CUnQ09VHk0XtfQ9Bcoui4d5IxkTSGGkQMS8SsTxYve8JqVObnzNZXdyJDCiKfiSPQ+7glyneSu+KaEa X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0efa729d-1f70-46b3-6b80-08d648604317 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390040)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060); SRVR:CY1PR12MB0618; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0618; 3:lr2h+4rVFHdQBUkX6NxA2XSGjnQ/ktHkCZRjLhctoiAmVaZDHZNGD8TmFGUX876IcrjAPr3ffQbkTw8XDmwLL4RLFwcH3mcoNgjTyNCLLlDzEj/eO+nyGLhqqCm2HrQL0L4XiPTxzmMMf1FeHPZNUv/rHTpEo/+SWkov3GaNe86bgHKHy7AJTo33eWbSiA5k+PvCWx1lvVPoE5J8k24G0N8pSvwt1FlEojF8zFJ8vC2bw0J7z92DmIKB5oKv7ycLWwWpg+yimfNDXu38U95JUJzpZrHCSz/AioWHzVxJPCGnnRVngPcde9uvvvSpX6MUiS066AoF9kTOegLJLi9Y5F+M8kjGg62LFtXlqTZXFhc=; 25:Syg7H4QyZR8CxVzh7jv27XvvHwYhUEzwTVM1Kn2w7rHNWN82jyHFfRuHkEZxd+jbD6TtAtoHfYqYZ6wIup4C0PNFAVoVzNUbEH3jdXR7bWFGQRWQgxd8ubC1RvLaUny9yd4hHXKAubkcmWZZvM0jVFx3u48u+nscFVDApm64oQFJOpoQtiFxWUAdN2zg9/jutwkKKuZijl+N8Zh+qLpozT9W6ZVuVI6x6H8LfCAF/o0GcrOZ6VFSW+VAU0c5D/DCkrBfFd2vJPHpZy/vgZevvUyRg51Hl2W0TRH9gyGHewm61ZZQ60LDv3YZN8xMKPLnjTvkRg1nolsdviKrJDuRK15wOkUpdCbQk7GwDOk3Lq8= X-MS-TrafficTypeDiagnostic: CY1PR12MB0618: X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0618; 31:GAwdYL6eh/zOR1ZewkJadyTK0mnhHKIgI+lLk838NP2h+Z2i3wuvlTkKQOEvOBkPnO6kxs1jMbvSVlz0eqo/cD1QlqIrR+BfbsISpLDQR4jJ1a1vEsU9gYK3wjAiby1/YbeaaYJw2r4FdV0I0TwH7Ph4xK0rZYGFlCjaTeJkfXR4wyaN1qF3gIzodq2iAd4XsigPMcvD3HAhIg1q7Tx04YwpcYzAsM0yXbpHQUV5eeA=; 20:OjTme/FI9Bi6SqCoPUOqxTLBqgNBRhOI+xRoYT72qecPdugzOO7sxGUYX22H5AIJ8x0HYXJNeC9Y02KBVUY2YDj69c6/rc8mYkJpHz9+RdTdcraTZ4MJPF/xBvya2cHhTaCBFDwjusAXT2iA3UhfJO/u9HpLQg8Ln2eNpTJF24uEVq1G5H1A74ect2bcf0W1zUsxd0Zy/ak9NR4NiLVvk9K2dkJSYkVZ46p+DrtnhDQrc6in7dzH5EYJmPv1LDTZeQu136JMq7D24haFwHWem2ryoHB2F/MGQU0zww8wcsP1zwngTHh/Fkhg9cEWjXv+oHUIwtRhvB/SPmPQVY2D/p0JAD5Y7Yl6FDAXwrV0+/TnaxgvVajUU9ZiQWgUmGYWsLcQdvihJ3rQIv+f5ieNYKd7/VS1mocf0XVtaS9OE+drUjAf37ON0quouemxjrrO9ongrGcrRZu2LenXCJMkW59UG93hx3/DEqo5H/Lnz1Rwz9X94yeeJaB+8LSwWiVo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231402)(944501410)(52105112)(93006095)(93003095)(10201501046)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:CY1PR12MB0618; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0618; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0618; 4:a6VmfmOb9/BmntC0c+d+apAwbOxcFJiDAL81H7r0SxLPH0pkkXEGCtK+vDb4BkgIcMNslEQINXHrExsINO/Go0yWTJTNoY69KrOBJ8hXxaZqRutb00zq+c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BySVeO1JvdEx7gsjtwxwLLsONoUAejdtk80u+27WtTaqdJmr9hdxLedjTDsntXMRtM5MWIwQrSe6otLuXw6XT0moXrdcJWuSSKRhp0CarSD0nx5MX2jPsZLN8tAiniIn9qrEpq5QoJoi/3e2A+gnKEp7bDxUCbdhohhIT2iI2U94FSFa6YsQIitqn1nqQ3Y7J2bQ7+BWu1TQNxersHyjKokx9c50b3OeFmsw7O4LoxilOGh5ZqCwronDquSaJJOtMEKK5H951eFYG0JYOFEeW8FZhXgmX6REOZjdru3Nlnt6ojEbX2wy7qRPWCyNa/rkBRrW3gPiMD8fYt1pPQ==; 5:KQ+7yRRAYZT+GXzBIhxQO5mNNU5QIRXF4t/FsS1/Yd5QVIIskhEhkRB+UwLILyqz8hyN+5IrBqsYsfhickRPh77HZtpNXd0+Sp2YXQGpneEB1Zm3gOEzF/T2WRWHLl6oZeQxp8ox6Be4Fe/WeeqHFMn/AytTksxivqSnNhPlfdI=; 7:mgsEiDLJL/JG/DanNyrg2xgrcPCwkfuBCR1uSi3cKj/TRCCtMJedqKIKOMMSM2YSqhvOp9EZhKnTRKHA0ZcNx10qVHTg5M6Y3fQRR6sGfZyFi3Y2H3pBQM4NyBcleUWlyGjVfxa4zLhpygE6Kdb5ew== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0618; 20:ZsY784dDjUmb+nH1olUiveNy7mMdrQU6jTCj+aR/jMxWptAGWFNLcxi7xCjtmOdJphF9MixYF/30/zdn8eBJd7WRGiyT/UWn7tAV4AQNboW77C8nqqwLMwtsA6B3FH9euvklA6qngbIJRrigh1P2j5ak/76DWPISbXZxCUVjg7Wlr8DPzoXXCRF+y8dwtZwl/lEg5P4IZrfko8Kr/fi1Wmsx5mdh95W19DQKgntU2hX4VmIGzTEPRZOtluf5l2Kh X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2018 05:32:39.4797 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0efa729d-1f70-46b3-6b80-08d648604317 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0618 Cc: "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Maruthi Bayyavarapu , open list , Takashi Iwai , Liam Girdwood , Sanju R Mehta , Vishnuvardhanrao.Ravulapati@amd.com, Mark Brown , Vijendar Mukunda , Alexander.Deucher@amd.com Subject: [alsa-devel] [PATCH 06/11] ASoC: amd: add acp3x pcm driver dma ops 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 ACP3x has a DMA controller to access system memory. This controller transfers data from/to system memory to/from the ACP internal FIFO. The patch adds PCM driver DMA operations. Signed-off-by: Maruthi Bayyavarapu Tested-by: Ravulapati Vishnu vardhan Rao Signed-off-by: Vijendar Mukunda --- sound/soc/amd/raven/acp3x-pcm-dma.c | 262 +++++++++++++++++++++++++++++++++++- sound/soc/amd/raven/acp3x.h | 20 +++ 2 files changed, 275 insertions(+), 7 deletions(-) diff --git a/sound/soc/amd/raven/acp3x-pcm-dma.c b/sound/soc/amd/raven/acp3x-pcm-dma.c index 94f915a..06c1985 100644 --- a/sound/soc/amd/raven/acp3x-pcm-dma.c +++ b/sound/soc/amd/raven/acp3x-pcm-dma.c @@ -33,6 +33,54 @@ struct i2s_dev_data { struct snd_pcm_substream *capture_stream; }; +struct i2s_stream_instance { + u16 num_pages; + u16 channels; + u32 xfer_resolution; + struct page *pg; + void __iomem *acp3x_base; +}; + +static const struct snd_pcm_hardware acp3x_pcm_hardware_playback = { + .info = SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_BATCH | + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | + SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S32_LE, + .channels_min = 2, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_8000_96000, + .rate_min = 8000, + .rate_max = 96000, + .buffer_bytes_max = PLAYBACK_MAX_NUM_PERIODS * PLAYBACK_MAX_PERIOD_SIZE, + .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE, + .period_bytes_max = PLAYBACK_MAX_PERIOD_SIZE, + .periods_min = PLAYBACK_MIN_NUM_PERIODS, + .periods_max = PLAYBACK_MAX_NUM_PERIODS, +}; + +static const struct snd_pcm_hardware acp3x_pcm_hardware_capture = { + .info = SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_BATCH | + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | + SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S32_LE, + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_8000_48000, + .rate_min = 8000, + .rate_max = 48000, + .buffer_bytes_max = CAPTURE_MAX_NUM_PERIODS * CAPTURE_MAX_PERIOD_SIZE, + .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE, + .period_bytes_max = CAPTURE_MAX_PERIOD_SIZE, + .periods_min = CAPTURE_MIN_NUM_PERIODS, + .periods_max = CAPTURE_MAX_NUM_PERIODS, +}; + static int acp3x_power_on(void __iomem *acp3x_base, bool on) { u16 val, mask; @@ -165,14 +213,214 @@ static irqreturn_t i2s_irq_handler(int irq, void *dev_id) return IRQ_NONE; } +static void config_acp3x_dma(struct i2s_stream_instance *rtd, int direction) +{ + u16 page_idx; + u64 addr; + u32 low, high, val, acp_fifo_addr; + struct page *pg = rtd->pg; + + /* 8 scratch registers used to map one 64 bit address */ + if (direction == SNDRV_PCM_STREAM_PLAYBACK) + val = 0; + else + val = rtd->num_pages * 8; + + /* Group Enable */ + rv_writel(ACP_SRAM_PTE_OFFSET | BIT(31), rtd->acp3x_base + + mmACPAXI2AXI_ATU_BASE_ADDR_GRP_1); + rv_writel(PAGE_SIZE_4K_ENABLE, rtd->acp3x_base + + mmACPAXI2AXI_ATU_PAGE_SIZE_GRP_1); + + for (page_idx = 0; page_idx < rtd->num_pages; page_idx++) { + /* Load the low address of page int ACP SRAM through SRBM */ + addr = page_to_phys(pg); + low = lower_32_bits(addr); + high = upper_32_bits(addr); + + rv_writel(low, rtd->acp3x_base + mmACP_SCRATCH_REG_0 + val); + high |= BIT(31); + rv_writel(high, rtd->acp3x_base + mmACP_SCRATCH_REG_0 + val + + 4); + /* Move to next physically contiguos page */ + val += 8; + pg++; + } + + if (direction == SNDRV_PCM_STREAM_PLAYBACK) { + /* Config ringbuffer */ + rv_writel(MEM_WINDOW_START, rtd->acp3x_base + + mmACP_BT_TX_RINGBUFADDR); + rv_writel(MAX_BUFFER, rtd->acp3x_base + + mmACP_BT_TX_RINGBUFSIZE); + rv_writel(DMA_SIZE, rtd->acp3x_base + mmACP_BT_TX_DMA_SIZE); + + /* Config audio fifo */ + acp_fifo_addr = ACP_SRAM_PTE_OFFSET + (rtd->num_pages * 8) + + PLAYBACK_FIFO_ADDR_OFFSET; + rv_writel(acp_fifo_addr, rtd->acp3x_base + + mmACP_BT_TX_FIFOADDR); + rv_writel(FIFO_SIZE, rtd->acp3x_base + mmACP_BT_TX_FIFOSIZE); + } else { + /* Config ringbuffer */ + rv_writel(MEM_WINDOW_START + MAX_BUFFER, rtd->acp3x_base + + mmACP_BT_RX_RINGBUFADDR); + rv_writel(MAX_BUFFER, rtd->acp3x_base + + mmACP_BT_RX_RINGBUFSIZE); + rv_writel(DMA_SIZE, rtd->acp3x_base + mmACP_BT_RX_DMA_SIZE); + + /* Config audio fifo */ + acp_fifo_addr = ACP_SRAM_PTE_OFFSET + + (rtd->num_pages * 8) + CAPTURE_FIFO_ADDR_OFFSET; + rv_writel(acp_fifo_addr, rtd->acp3x_base + + mmACP_BT_RX_FIFOADDR); + rv_writel(FIFO_SIZE, rtd->acp3x_base + mmACP_BT_RX_FIFOSIZE); + } + + /* Enable watermark/period interrupt to host */ + rv_writel(BIT(BT_TX_THRESHOLD) | BIT(BT_RX_THRESHOLD), + rtd->acp3x_base + mmACP_EXTERNAL_INTR_CNTL); +} + +static int acp3x_dma_open(struct snd_pcm_substream *substream) +{ + int ret = 0; + + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_soc_pcm_runtime *prtd = substream->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, + DRV_NAME); + struct i2s_dev_data *adata = dev_get_drvdata(component->dev); + + struct i2s_stream_instance *i2s_data = kzalloc(sizeof(struct i2s_stream_instance), + GFP_KERNEL); + if (!i2s_data) + return -EINVAL; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + runtime->hw = acp3x_pcm_hardware_playback; + else + runtime->hw = acp3x_pcm_hardware_capture; + + ret = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (ret < 0) { + dev_err(component->dev, "set integer constraint failed\n"); + return ret; + } + + if (!adata->play_stream && !adata->capture_stream) + rv_writel(1, adata->acp3x_base + mmACP_EXTERNAL_INTR_ENB); + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + adata->play_stream = substream; + else + adata->capture_stream = substream; + + i2s_data->acp3x_base = adata->acp3x_base; + runtime->private_data = i2s_data; + return 0; +} + +static int acp3x_dma_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + int status; + u64 size; + struct snd_dma_buffer *dma_buffer; + struct page *pg; + struct snd_pcm_runtime *runtime = substream->runtime; + struct i2s_stream_instance *rtd = runtime->private_data; + + if (!rtd) + return -EINVAL; + + dma_buffer = &substream->dma_buffer; + size = params_buffer_bytes(params); + status = snd_pcm_lib_malloc_pages(substream, size); + if (status < 0) + return status; + + memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); + pg = virt_to_page(substream->dma_buffer.area); + if (pg) { + rtd->pg = pg; + rtd->num_pages = (PAGE_ALIGN(size) >> PAGE_SHIFT); + config_acp3x_dma(rtd, substream->stream); + status = 0; + } else { + status = -ENOMEM; + } + return status; +} + +static snd_pcm_uframes_t acp3x_dma_pointer(struct snd_pcm_substream *substream) +{ + u32 pos = 0; + struct i2s_stream_instance *rtd = substream->runtime->private_data; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + pos = rv_readl(rtd->acp3x_base + + mmACP_BT_TX_LINKPOSITIONCNTR); + else + pos = rv_readl(rtd->acp3x_base + + mmACP_BT_RX_LINKPOSITIONCNTR); + + if (pos >= MAX_BUFFER) + pos = 0; + + return bytes_to_frames(substream->runtime, pos); +} + +static int acp3x_dma_new(struct snd_soc_pcm_runtime *rtd) +{ + return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, + SNDRV_DMA_TYPE_DEV, + NULL, MIN_BUFFER, + MAX_BUFFER); +} + +static int acp3x_dma_hw_free(struct snd_pcm_substream *substream) +{ + return snd_pcm_lib_free_pages(substream); +} + +static int acp3x_dma_mmap(struct snd_pcm_substream *substream, + struct vm_area_struct *vma) +{ + return snd_pcm_lib_default_mmap(substream, vma); +} + +static int acp3x_dma_close(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *prtd = substream->private_data; + struct i2s_stream_instance *rtd = substream->runtime->private_data; + struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, + DRV_NAME); + struct i2s_dev_data *adata = dev_get_drvdata(component->dev); + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + adata->play_stream = NULL; + else + adata->capture_stream = NULL; + + /* Disable ACP irq, when the current stream is being closed and + * another stream is also not active. + */ + if (!adata->play_stream && !adata->capture_stream) + rv_writel(0, adata->acp3x_base + mmACP_EXTERNAL_INTR_ENB); + kfree(rtd); + return 0; +} + static struct snd_pcm_ops acp3x_dma_ops = { - .open = NULL, - .close = NULL, - .ioctl = NULL, - .hw_params = NULL, - .hw_free = NULL, - .pointer = NULL, - .mmap = NULL, + .open = acp3x_dma_open, + .close = acp3x_dma_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = acp3x_dma_hw_params, + .hw_free = acp3x_dma_hw_free, + .pointer = acp3x_dma_pointer, + .mmap = acp3x_dma_mmap, }; struct snd_soc_dai_ops acp3x_dai_i2s_ops = { diff --git a/sound/soc/amd/raven/acp3x.h b/sound/soc/amd/raven/acp3x.h index f3d3e51..9f33e34 100644 --- a/sound/soc/amd/raven/acp3x.h +++ b/sound/soc/amd/raven/acp3x.h @@ -13,6 +13,26 @@ #define ACP3x_POWER_OFF_IN_PROGRESS 0x03 #define ACP3x_SOFT_RESET__SoftResetAudDone_MASK 0x00010001 +#define ACP_SRAM_PTE_OFFSET 0x02050000 +#define PAGE_SIZE_4K_ENABLE 0x2 +#define MEM_WINDOW_START 0x4000000 +#define PLAYBACK_FIFO_ADDR_OFFSET 0x400 +#define CAPTURE_FIFO_ADDR_OFFSET 0x500 + +#define PLAYBACK_MIN_NUM_PERIODS 2 +#define PLAYBACK_MAX_NUM_PERIODS 8 +#define PLAYBACK_MAX_PERIOD_SIZE 16384 +#define PLAYBACK_MIN_PERIOD_SIZE 4096 +#define CAPTURE_MIN_NUM_PERIODS 2 +#define CAPTURE_MAX_NUM_PERIODS 8 +#define CAPTURE_MAX_PERIOD_SIZE 16384 +#define CAPTURE_MIN_PERIOD_SIZE 4096 + +#define MAX_BUFFER (PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS) +#define MIN_BUFFER MAX_BUFFER +#define FIFO_SIZE 0x100 +#define DMA_SIZE 0x40 + static inline u32 rv_readl(void __iomem *base_addr) { return readl(base_addr - ACP3x_PHY_BASE_ADDRESS);