Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3374725pxu; Tue, 8 Dec 2020 10:17:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjSr5BzOP45bPMmLK31VA+opSYBC3x5lDncF22KnXr0pRJ9Bgc5ag5PP4vKuzJIU6XBb5u X-Received: by 2002:a50:e84d:: with SMTP id k13mr25205344edn.154.1607451464966; Tue, 08 Dec 2020 10:17:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607451464; cv=none; d=google.com; s=arc-20160816; b=RI2cAPudo9UKrWwIWE71ZrAUMfFLPE9pJGFHFAZh0CXlTqpR8smAHY01Aqfh2YwkmD fkaWPC2ZdV40nPEk5xAwqTkPIb2U9fvhclXZa6Z9+ijmZ4Yc4Avzapcys5X/OfIPFuWx BsXtw+0kt7038109wRenSjxInj+/vASZNmIlz023Q7+r0QI4A+hJMBo5MloWMxoCkoC+ ViUoA6EXXJ/2WoTq61FezjJaAn3MEYUwPSJyBb52Vl2LRhMvNzHkJ2ghXGfyjYpQLOH8 /1NsGOnlthW+DvgkpCSkx11NHejZSp+2myvTdMobEhyQyaPkXa88SBu4BGaCI2z2eBTv ox2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=M8SVSLFtz8XCFX35QtBBhLioF4VkLss3R+vxBxh9OlM=; b=C2s11F/bZBdhg69H18ui1i3qg3BUaQwbd3UcMx7xzIAJ1743u1PS0jMf06LVvXcCtl TkwU8kAqJLmrzNx69ZAX9d4mo1IqZ3CPcLPlAPqCEsfVUBv4Adwxs51l4joV/mW8Gw5d XB7pRrD1AbMqPPHvOan0WcbPD6043gUa3mbclCZ0FHzLfG4E4x+5Epg+oaQm+I1S0XNX gr6ufQzNX1Lz4CY+B/IEMLuzJseccXnkjEdZryXR0Co9w/v7QqEgZ5kYOQyUHNu50vkJ Dc6lnuf13xO1Xh7ztdrLXfvzeGu7sqCRp5KBkrXrvRSQ9nXuz+LjhDxtf7ikSRjVbT2Q GAsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IXMCJvQn; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id re20si8660385ejb.112.2020.12.08.10.17.21; Tue, 08 Dec 2020 10:17:44 -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=@gmail.com header.s=20161025 header.b=IXMCJvQn; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730832AbgLHSQE (ORCPT + 99 others); Tue, 8 Dec 2020 13:16:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730483AbgLHSQD (ORCPT ); Tue, 8 Dec 2020 13:16:03 -0500 Received: from mail-ua1-x941.google.com (mail-ua1-x941.google.com [IPv6:2607:f8b0:4864:20::941]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D439C061749; Tue, 8 Dec 2020 10:15:23 -0800 (PST) Received: by mail-ua1-x941.google.com with SMTP id t19so5912736uaq.1; Tue, 08 Dec 2020 10:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M8SVSLFtz8XCFX35QtBBhLioF4VkLss3R+vxBxh9OlM=; b=IXMCJvQn8ys5LSKXqaH2S2FHBiJJTdR62QBskWNgyXtob6K6y0GNFeOLFVUToI7zCg ZmiNWtCVVMNIwMYRl4BIjrrBvOcsEwSYyVmw2RMBotSNbcjXjB3DOGG2yDbr2gYmq3xL JYt8C4BajLMBqq5eF1E68jmP1WycYUFzYP8SWoTjudEXQWgWyUjqN+nwRmSAnT3kxSMM z/+FVU1qQQtdp5Sgaisd2EsLpG3YBRjFDkCORNwTn/FgYi104NdMGV8QSpg+NWBApMPD kUGxeyZZuN6wOvhAiMizdYIOMbLeZKPixTKDvQ0Ve9wShEHRDdLndaB1X5ozuF76QoKq qQ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M8SVSLFtz8XCFX35QtBBhLioF4VkLss3R+vxBxh9OlM=; b=t5Qu7/gmT8aHFz7/5GuSPAxEk/aafqsB59NJ+IBw33aJYDgXRrgQRBeulA10Fvv1PQ CaWDH0ha9NJ69aeZoex8RLTT9rKXsS+exhCTpHcVWPrd2m8ykBHMliSJ7vRKAmTVbr3E ys/X9hf2lqtNEZgaASlaGIEcEnU9i3AhRmlUkuSBnlq2PMJFwVb7+9nZBcQgKiQXPeN5 MTVLgWheyYmKOstJs9pRv5/9PP63oEA3dfgmbKyr9+NQr2ZfQ43wxyqSCfnW8LwVo2eB +AigfcUqu/NDttzyXIeg0iHLgk+8OEPpibhqw8CF2rnTs+hC/o0pl3a7iPY1BgVQPb3w t0ew== X-Gm-Message-State: AOAM532CeDxVrjwsUjAMTQwZuvcAr2vbwce0PJGL016s3/hsLaqUFhCC XLZI5gbqFr2PMb6XNyoYqyVqemnuBSaoyMkRQ+Q= X-Received: by 2002:ab0:4881:: with SMTP id x1mr17207972uac.101.1607451322316; Tue, 08 Dec 2020 10:15:22 -0800 (PST) MIME-Version: 1.0 References: <20201207193629.493241-1-clemens.gruber@pqgruber.com> <20201207220025.42b6g76wq7ph5nvb@pengutronix.de> <20201208091033.bxzrlad7mjbe3dsp@pengutronix.de> In-Reply-To: From: Sven Van Asbroeck Date: Tue, 8 Dec 2020 13:15:10 -0500 Message-ID: Subject: Re: [PATCH v4 1/4] pwm: pca9685: Switch to atomic API To: Thierry Reding Cc: Clemens Gruber , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , linux-pwm@vger.kernel.org, Lee Jones , Linux Kernel Mailing List , Mika Westerberg , David Jander Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 8, 2020 at 11:57 AM Thierry Reding wrote: > > Is this really that complicated? I sounds to me like the only thing that > you need is to have some sort of usage count for the prescaler. Whenever > you want to use the prescaler you check that usage count. If it is zero, > then you can just set it to whatever you need. If it isn't zero, that > means somebody else is already using it and you can't change it, which > means you have to check if you're trying to request the value that's > already set. If so, you can succeed, but otherwise you'll have to fail. +1 I think your suggestion is an elegant solution to get the required behaviour. One possible complication is synchronization. The sysfs interface has a lock protecting against concurrent pwm_apply() calls. But the in-kernel API (e.g. pwm_apply_state()) doesn't seem to. This is not normally a problem when pwm bits are strictly separated. But in this case we have shared state (prescale value and use count), so we probably need to protect pwm_apply() with a mutex? Not sure if it is currently possible *in practice* for two regulator consumer drivers to call pwm_apply() from different threads. But Linux is slowly moving towards asynchronous probing. Uwe and Thierry, what is your opinion? Do you think we need to worry about synchronization?