Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2681174lqz; Wed, 3 Apr 2024 05:50:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXQUkSc5sIJAQhRdjrrJ9PGNfr15Z1pcN9g4nFdHuMJMWy6pUv+8FQMuYHs+BlfTd/2ES54vLVSH5r3tSiFHQCZOeITpsGyQjCKfe3Iyg== X-Google-Smtp-Source: AGHT+IEFOnyn3vdMMGW7qqTxYg3PwLa0ynLyfNIgE3LTTrTmchXpr3T5bAye376Ql2BCpuXMzzq1 X-Received: by 2002:a19:ae01:0:b0:515:9d9e:7339 with SMTP id f1-20020a19ae01000000b005159d9e7339mr3851751lfc.20.1712148634039; Wed, 03 Apr 2024 05:50:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712148634; cv=pass; d=google.com; s=arc-20160816; b=mwStsdrrfmGvLxmGHrPbUD2U4GfpsOKFeeQ9F3pqKLuU5d8JKJNsQ2kHOUna7a6eZz QIbnonCYbhoKUHldo3+PjeH2zhzuinf2aqcRD9P2Hgoh/MDkerIP6ssdr84SZ9mB5Z5V xof2K2ESSnYSyNNERaSY8Vpka4+BE2hiZHn4PKnGkkLNG96l1uK/9GuGRUjdNK3LGf6x LgmyuuUYA1P4zozYIxq6l1CAgxjCTwT2fQjpoRNO4k+SFF/SgLLiegiDEVkwY6Pr2lox 7ORpP+hNOTtVjQLuMhIdpmTEDmQZ9b0i1yDz+IzZiM/LOR5s2ElNJkzY6LraggxB1big iAAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=+5iWsvHrpDbEsaeCop9La7eAOEHAARegOBLVbcwGQYA=; fh=1FTLFE0ZGQd3S6NIapo5KARpNor0N+6jnByvjMZkMKk=; b=bnOfwSN5VH/NQylTHTkdLoa/o2iivyf9gjCyM4Gg1ryH9LbfiP40KtO3vnXL2JCkDv zRsiBqtq8cR7MIa88zhYf6gVUewIzS/moHI0xWMEeGhiZ9ZcRUGHi/+42yioBNb0Of/g rMLEeeHDgJP4VvP3ZNitmQMhhNDk2A8bMYZfwg2SxPTTQ0C2UTXMFK0ahAIKKz8Bg/D5 ttWbJtTjniyQiJAGU1FNhlOxxmmDFR3OMwQQzEssuYPlmiMc8Yq4N8bLS3OOcma8HO9z N4PRBZj/1IX2n8vvbxqYR53Eq0+Be1F0YP5LelvdqYk4CtAp+txnZ8fUmV3cx1/4aZ7g us5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KkvbsMi0; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-129736-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129736-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kn18-20020a170906aa5200b00a46ee0ca85bsi6493655ejb.525.2024.04.03.05.50.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129736-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KkvbsMi0; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-129736-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129736-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BBA111F21E88 for ; Wed, 3 Apr 2024 12:50:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8657E146D57; Wed, 3 Apr 2024 12:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KkvbsMi0" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BEE444C97; Wed, 3 Apr 2024 12:50:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712148624; cv=none; b=sLa1yWhwy7W8BRLKqeyj9IVoNAPljOpY+EwjZmQVRM6v0qHkHI9xlseSsUMWhdPCfwVQyt2N9JFxXhY9YXAbY1pDgB3CnXqHBEbNCVR8pCnJodpg2MArKxnur1nwfwYSay5yXMTspbVJKPhw64L7EkROFryn7ZN/Mq6jcNPaqFM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712148624; c=relaxed/simple; bh=rhp7e6puQyVUMErtQ1wrKsDuOwsFw8HjdJrVLLq+GRo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LPgI8W444QcA7qWQ38FKyiIMojUHDDAjaGcexJE2/46Dwb/u462DS15nDGAGx39Uqa8FkWzcWXMnzZizzX5s4mHLWPRYK0hCW0j8EQ59QjucFP+c3tBnF/i+NWHqc82uXabD5NDlorIExDEn2iyckO/CPnU/LC8lPKLucRknB78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KkvbsMi0; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712148623; x=1743684623; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=rhp7e6puQyVUMErtQ1wrKsDuOwsFw8HjdJrVLLq+GRo=; b=KkvbsMi0a3GwZQH6OS4qDkK6GKzMItf+9mMJQrlpnAi+meTSbsOpwtnP FrSQJtA+D8R+fGZLlKi413OBM0d2wxX2d0lcMbdI3Xcf3x3UHIzwKGWMa 7QyqBahdXupDHXm+T9LRIA6BxqfPBAkL//QX8cuYRQRKr2Lc79jNTlGWM 7fCDKhToPD8wPp5EcPOImuBBgtO7EvHAd007FxI6BdVsZAeMU5U+AQ0f6 +o+PUOxWUIZCKnQtKtR4WYBmQWOfW7i/EC+Dklt+O0XhTn8fv+NXQIaeJ 8j1Ycl9ci1pAUy3adZT1gwjFLO+U4HDJWY2SQlWTpmT7Q9Xvh5Bdy3zPM g==; X-CSE-ConnectionGUID: v9EQG/HkTBuqCVkMznfwog== X-CSE-MsgGUID: tsE9gVh+SEKW4sMbKWWVYQ== X-IronPort-AV: E=McAfee;i="6600,9927,11033"; a="7539277" X-IronPort-AV: E=Sophos;i="6.07,177,1708416000"; d="scan'208";a="7539277" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2024 05:50:23 -0700 X-CSE-ConnectionGUID: 1/2JH2STQ7WDV9dzV2GDbw== X-CSE-MsgGUID: R5MUllpuTCKa7NQ8b3XutA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,177,1708416000"; d="scan'208";a="18343201" Received: from makulkar-mobl1.amr.corp.intel.com (HELO [10.212.52.18]) ([10.212.52.18]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2024 05:50:21 -0700 Message-ID: Date: Tue, 2 Apr 2024 08:57:14 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?UTF-8?B?UmU6IOWbnuWkjTogW1BBVENIIHYyIDIvMl0gQVNvQzogY2RuczogQWRk?= =?UTF-8?Q?_drivers_of_Cadence_Multi-Channel_I2S_Controller?= To: Xingyu Wu , Liam Girdwood , Mark Brown , Claudiu Beznea , Jaroslav Kysela , Takashi Iwai , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "alsa-devel@alsa-project.org" , "linux-sound@vger.kernel.org" References: <20240320090239.168743-1-xingyu.wu@starfivetech.com> <20240320090239.168743-3-xingyu.wu@starfivetech.com> <1d0399d2-684f-490e-8711-f636e987a0b8@linux.intel.com> Content-Language: en-US From: Pierre-Louis Bossart In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit >> >>> +#define PERIODS_MIN 2 >>> + >>> +static unsigned int cdns_i2s_pcm_tx(struct cdns_i2s_dev *dev, >>> + struct snd_pcm_runtime *runtime, >>> + unsigned int tx_ptr, bool *period_elapsed, >>> + snd_pcm_format_t format) >>> +{ >>> + unsigned int period_pos = tx_ptr % runtime->period_size; >> >> not following what the modulo is for, usually it's modulo the buffer size? > > This is to see if the new data is divisible by period_size and to determine whether > it is enough for a period_size in the later loop. That didn't answer to my question, the position is usually between 0..buffer_size.1. Doing increments on a modulo value then comparisons as done below seems rather questionable. >>> + >>> + iowrite32(data[0], dev->base + CDNS_FIFO_MEM); >>> + iowrite32(data[1], dev->base + CDNS_FIFO_MEM); >>> + period_pos++; >>> + if (++tx_ptr >= runtime->buffer_size) >>> + tx_ptr = 0; >>> + } >>> + >>> + *period_elapsed = period_pos >= runtime->period_size; >>> + return tx_ptr; >>> +} >>> + pm_runtime_enable(&pdev->dev); >>> + if (pm_runtime_enabled(&pdev->dev)) >>> + cdns_i2s_runtime_suspend(&pdev->dev); >> >> that sequence looks suspicious.... Why would you suspend immediately during the >> probe? You're probably missing all the autosuspend stuff? > > Since I have enabled clocks before, and the device is in the suspend state after > pm_runtime_enable(), I need to disable clocks in cdns_i2s_runtime_suspend() > to match the suspend state. That is very odd on two counts a) if you haven't enabled the clocks, why do you need to disbale them? b) if you do a pm_runtime_enable(), then the branch if (pm_runtime_enabled) is always true. > >> >>> + >>> + dev_dbg(&pdev->dev, "I2S supports %d stereo channels with %s.\n", >>> + i2s->max_channels, ((i2s->irq < 0) ? "dma" : "interrupt")); >>> + >>> + return 0; >>> + >>> +err: >>> + return ret; >>> +} >>> + >>> +static int cdns_i2s_remove(struct platform_device *pdev) { >>> + pm_runtime_disable(&pdev->dev); >>> + if (!pm_runtime_status_suspended(&pdev->dev)) >>> + cdns_i2s_runtime_suspend(&pdev->dev); >> >> ... and this one too. Once you've disabled pm_runtime, checking the status is >> irrelevant... > > I think the clocks need to be always enabled after probe if disable pm_runtime, > and should be disabled when remove. This will do that. if you are disabling pm_runtime, then the pm_runtime state becames invalid. When pm_runtime_disable() is added in remove operations, it's mainly to prevent the device from suspending.