Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1030279pxb; Fri, 22 Jan 2021 05:40:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfsqXJ96LAv3C6P3tCuSdRR/SA0/p829gyMpC+8uUnEKSa0dJqVwjo5Llm8ZeGHm8gH5oo X-Received: by 2002:aa7:d504:: with SMTP id y4mr3140264edq.372.1611322832224; Fri, 22 Jan 2021 05:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611322832; cv=none; d=google.com; s=arc-20160816; b=nZo5lV51n7xzvTaexVDQjdnMKtnNUiL3UtcfS2Nk5Xm2bKeK72fJVbU2bmQnvbvMGq o1gaQ8dJDrBWx+oe03vQOWdbkBzeYBf6ZpQDjWJplgmQlIOvildiG2XbTDMvSarulAkv 78kT8Aukbqu8PAua3GI5G6pyX20w4va1k6idVWrmws+iVvFRf7a25uDLG9uwXFCL4qTj k5lULKqaWoLMZzgLaced5whuYhs/SZKdoHz7v5IFlMjGgp8HOXOkRyN2MTk8wns2242O ZiucR+qrRxKT10tYQ/CDka4Ns1jgiRzWrxJByqrjuYJquKBdoKP+M4trsRHsgZPqB9MR Zq0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=QTrYS3guDB5O8MQKW0DTv3afyR+7WyuzK5+Av9id7t8=; b=evgSo3jXoZ7k5EB6aiJdg4qLDd4Hb01gAzCoRL/I5hiLlu+Welpr+9dDxrzNJxhr0B VpmDvkwzSpe1BARRv7Wa53Gzd0FaQtJChdKW3XhMuQ+RtxsvRhVGPttQD1zJR/1XMlY2 SlFbEsZNbiyfGzqxx29SxfjjJPQ9RUmMPSKBk/A1osocQn6PmqtKf4DjhE+klIfQIjK/ HY2zhOC5WSl3G7sK5oQ8M/++mWuXd3iGljGK6bOCqb2BM/Q+RklHRl8BLT/FztxWqAwo REWhY4mFCaidelxRMla65Znhta99fZyp0oYnAuBfJwDI7WrZWDilyQWVjnV0O4iO7/31 Dddw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dqzyvgy6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o27si3035416ejc.279.2021.01.22.05.40.08; Fri, 22 Jan 2021 05:40:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dqzyvgy6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727919AbhAVNhs (ORCPT + 99 others); Fri, 22 Jan 2021 08:37:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32512 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727869AbhAVNhd (ORCPT ); Fri, 22 Jan 2021 08:37:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611322566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QTrYS3guDB5O8MQKW0DTv3afyR+7WyuzK5+Av9id7t8=; b=Dqzyvgy6vvVDqI368RHIn6mTf/CuyBJXC3cv3yQ/GaGFeDQQPMeAdHd+jN+JJBmQX9ZL1v tZgtVuruQvFDmOd7R2IKeNgP3dJeUg72+jjA60JGnZaAFaGvJ42rFO4a6R8WHQc0CEnRrw DwmcVI3QnnOjsk5B7vgDMt6r5AsBwxg= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-534-y9WuY4r9OBGXl7RsgZjgmQ-1; Fri, 22 Jan 2021 08:36:04 -0500 X-MC-Unique: y9WuY4r9OBGXl7RsgZjgmQ-1 Received: by mail-ed1-f71.google.com with SMTP id n8so2909466edo.19 for ; Fri, 22 Jan 2021 05:36:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QTrYS3guDB5O8MQKW0DTv3afyR+7WyuzK5+Av9id7t8=; b=pjSpyAqxN5zRZvIDUNy7hEzM8huahD9dJQVf/fZFcqCsNW1+6gwpZkYQTBkT6Fix8f 0DSgDA22XV3IEgJMZT+A0oDDrYHQb9mMVP6te3VcFu6seWrG8PU4Gzd8h8r9Goy89r6l hBIfb1z9lHJMo4EPgQ/Lz3PfjAe/YxEWJ/DOsYUchn23L3oLqq5amPmg3tpXH3RlAF2K tqSIRHqJEDU6oxDKcj9ILc6dKIUlQSTiQ+ButjXDchIDIFyM/EM1rd5Vo5aWSXjC8pCJ axuSv5z5zi7OtUKkCytK6Egie06S7wpKoV7G3o0uEzzJbW8OnFKCxEBetKS4nN0pyWBC I4Cw== X-Gm-Message-State: AOAM531upZ2V6jjwi5qN+6wo3asolG5kmRObFmZkDBpo13Od2y6SEBqr pjeCw+osecpoXoy670V1yh/HBV+LzsMei7KU0phQEXUdZz+LHKWT7+awEJ1N63uhxI7NoX/D+XA 0xEyxJWLzoXNA+nXrNPKPYeZd X-Received: by 2002:a05:6402:31a4:: with SMTP id dj4mr3226330edb.156.1611322563015; Fri, 22 Jan 2021 05:36:03 -0800 (PST) X-Received: by 2002:a05:6402:31a4:: with SMTP id dj4mr3226311edb.156.1611322562829; Fri, 22 Jan 2021 05:36:02 -0800 (PST) Received: from x1.localdomain (2001-1c00-0c1e-bf00-37a3-353b-be90-1238.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:37a3:353b:be90:1238]) by smtp.gmail.com with ESMTPSA id n5sm3715254edw.7.2021.01.22.05.36.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Jan 2021 05:36:02 -0800 (PST) Subject: Re: [PATCH v2 08/12] ASoC: arizona-jack: convert into a helper library for codec drivers To: Charles Keepax Cc: Richard Fitzgerald , Andy Shevchenko , Lee Jones , Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Jie Yang , Mark Brown , patches@opensource.cirrus.com, Linux Kernel Mailing List , ALSA Development Mailing List References: <20210117160555.78376-1-hdegoede@redhat.com> <20210117160555.78376-9-hdegoede@redhat.com> <5c1f181f-f074-397d-cdba-d37ab58f9a2b@redhat.com> <20210122112607.GH106851@ediswmail.ad.cirrus.com> <4274589c-9a52-7f1a-f937-1c5d60b76559@redhat.com> <20210122130412.GI106851@ediswmail.ad.cirrus.com> From: Hans de Goede Message-ID: <5436af42-e6d1-b0ed-7f16-60658b590919@redhat.com> Date: Fri, 22 Jan 2021 14:36:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20210122130412.GI106851@ediswmail.ad.cirrus.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 1/22/21 2:04 PM, Charles Keepax wrote: > On Fri, Jan 22, 2021 at 01:23:44PM +0100, Hans de Goede wrote: >> On 1/22/21 12:26 PM, Charles Keepax wrote: >>> On Thu, Jan 21, 2021 at 05:55:00PM +0100, Hans de Goede wrote: >>>> On 1/19/21 10:51 AM, Richard Fitzgerald wrote: >>>>> On 18/01/2021 17:24, Andy Shevchenko wrote: >>>>>> On Sun, Jan 17, 2021 at 6:06 PM Hans de Goede wrote: >>>> Note there is a pretty big issue with the original code here, if >>>> the MICVDD DAPM pin is on for an internal-mic and then we run through the >>>> jack-detect mic-detect sequence, we end up setting >>>> bypass=true causing the micbias for the internal-mic to no longer >>>> be what was configured. IOW poking the bypass setting underneath the >>>> DAPM code is racy. >>>> >>> >>> The regulator bypass code keeps an internal reference count. All >>> the users of the regulator need to allow bypass for it to be >>> placed into bypass mode, so I believe this can't happen. >> >> Ah I did not know that, since the regulator_allow_bypass function >> takes a bool rather then having enable/disable variants I thought >> it would directly set the bypass, but you are right. So this is not >> a problem, good. >> >> So this has made me look at the problem again and I believe that >> a much better solution is to simply re-use the MICVDD regulator-reference >> which has been regulator_get-ed by the dapm code when instantiating the: >> >> SND_SOC_DAPM_REGULATOR_SUPPLY("MICVDD", 0, SND_SOC_DAPM_REGULATOR_BYPASS), >> >> widget. So I plan to have a new patch in v3 of the series which replaces >> the devm_regulator_get with something like this: >> >> /* >> * There is a DAPM widget for the MICVDD regulator, since >> * the button-press detection has special requirements wrt >> * the regulator bypass settings we cannot directly >> * use snd_soc_component_force_enable_pin("MICVDD") / >> * snd_soc_component_disable_pin("MICVDD"). >> * >> * Instead we lookup the widget's regulator reference here >> * and use that to directly control the regulator. >> * Both the regulator's enable and bypass settings are >> * ref-counted so this will not interfere with the DAPM use >> * of the regulator. >> */ >> for_each_card_widgets(dapm->card, w) { >> if (!strcmp(w->name, "MICVDD")) >> info->micvdd_regulator = w->regulator; >> break; >> } >> } >> >> (note I've not tested this yet, but I expect this to work fine). >> > > Alas this won't work either. When I say reference count that > isn't quite a totally accurate reflection of the usage of the > function. When you call allow_bypass you are saying as this > consumer of the regulator I don't mind if it goes into bypass. > Then if all consumers agree the regulator will be put into > bypass. So it is comparing the reference count to the number of > consumers the regulator has to make a decision. > > If you call allow_bypass independently from the jack detection > code and the ASoC framework on the same consumer, as you > describe here you will get bad effects. For example the > regulator has two consumers, our CODEC driver and some other > device. If our codec driver calls allow_bypass twice, then > the regulator would go into bypass without the other consumer > having approved it would could be fatal to that device. So I just double checked the regulator core code and you are right that the bypass thing is per consumer. So we will indeed need 2 calls to regulator_get, one for the dapm use and one for the jack-det use since those 2 are independent. Note your example does not work as you think it will though: int regulator_allow_bypass(struct regulator *regulator, bool enable) { ... if (enable && !regulator->bypass) { rdev->bypass_count++; ... } else if (!enable && regulator->bypass) { rdev->bypass_count--; ... } if (ret == 0) regulator->bypass = enable; } So a second call to allow_bypass(..., true) from the same consumer will be a no-op. Sharing the same struct regulator result between the dapm widget and the jack-det code would still be an issue though since it will introduce the race which I was worried about earlier. >> 1. Keep the code as is, live with the debugfs error. This might be >> best for now, as I don't want to grow the scope of this series too much. >> I will go with this for the next version of this series (unless >> I receive feedback otherwise before I get around to posting the next >> version). > > I wonder if this commit was related to that: > > commit ff268b56ce8c ("regulator: core: Don't spew backtraces on duplicate sysfs") > > Apologies I don't have as much time as I normally would to look > into such issues at the moment, due to various internal company > things going on. Actually you are being super helpful, thank you. I believe that with your latest email this is fully resolved. > I do suspect that this option is the way to go though and if > there are issues of duplicates being created by the regulator > core those probably need to be resolved in there. But that can > probably be done separate from this series. Good catch, thanks. This means that having multiple consumers / regulator_get calls from the same consumer-dev is supposed to work and the debugfs error needs to be silenced somehow. I will look into silencing the error (as a patch separate from this series). Regards, Hans