Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1930108pxb; Fri, 29 Jan 2021 08:39:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0DtaJdyJ64v33rmexmLFZceVU6W8B8Jt7pWpxomeVKA2BIZW7AXhs2C3VXxUIUYPkwyOQ X-Received: by 2002:a05:6402:31bb:: with SMTP id dj27mr6041252edb.285.1611938372839; Fri, 29 Jan 2021 08:39:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611938372; cv=none; d=google.com; s=arc-20160816; b=cMbz0QXBhMK93HhF4+DqvtTfNndUR6K/1SbWLtDE5KAo0Uxe4I5dBrVeRMUpUr8cw8 wzLc8SffJvktshHTNIpvIY1tC+kiIbvNsCRTHZ/8LP6EmvGuBZZ3GolZm9ZIGQXm8Zka rZ9uZqpYRzPRSP86EH8zDeaBF58gIQZK/sAXe46jSDEyy5I88FT1bFMBrkfcX1AIXP9G bqonKM22hs3P7uecugEvp06Zaw0//DBwwMnTsVbZ+Yd1kMsNzTkq2KjSHQq7W7gcGbnC BitvlMa16hEEe+Uh6o9vqvmSCIGLrkjG/Z5G0QvjMQuzzvCvVy2ybHVxWsFUzOxFenl2 NVnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=DyVjiqkvwtlqI4o3EcQtV2h3pSbBneM1WDytITBk7RI=; b=XgqnG7uuY8m3f+vDiz0V4l4MLXJlw6eAdkN8Fm1z7JzmcFGx455XWqRaUzk3YNvaHH LMabbYzDeFiMhHbm0iofQ9fJrXF1VhKBs3y2S+jLlynYhRzHXnp2x0ISI/FB7euCinpx ++uL4A5CTR9nDQNZFHkfeBf7Ar1Bs9evstIUNwrHqtzCwhM28HJCDeGvKdJ8clZuK3oc opleQKjIiTiccf7vFCYI+/K7+SpujKR4+bQgVgPowZGOzbKdoEd3UDAXK+R7StOjYIQP 25Fc8ns1CybbfmMM9tblIEDK0MmbaXZSY050/kujUPCNRwT3UqjF8Qp6B4W8PSHAbMi1 j8xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pqgruber.com header.s=mail header.b=QvmqkrRH; 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=QUARANTINE sp=NONE dis=NONE) header.from=pqgruber.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s20si4970169eji.61.2021.01.29.08.39.08; Fri, 29 Jan 2021 08:39: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=@pqgruber.com header.s=mail header.b=QvmqkrRH; 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=QUARANTINE sp=NONE dis=NONE) header.from=pqgruber.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbhA2Qd4 (ORCPT + 99 others); Fri, 29 Jan 2021 11:33:56 -0500 Received: from mail.pqgruber.com ([52.59.78.55]:55744 "EHLO mail.pqgruber.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231452AbhA2Qcb (ORCPT ); Fri, 29 Jan 2021 11:32:31 -0500 Received: from workstation.tuxnet (213-47-165-233.cable.dynamic.surfer.at [213.47.165.233]) by mail.pqgruber.com (Postfix) with ESMTPSA id B31B0C6B26F; Fri, 29 Jan 2021 17:31:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqgruber.com; s=mail; t=1611937908; bh=DyVjiqkvwtlqI4o3EcQtV2h3pSbBneM1WDytITBk7RI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QvmqkrRHoO8OTWpUz6Mk8rhaDh2GYebv8JjCP4MzmIpHbNvim7sdHMXdvdxdk1WV6 wh8DkbdtjnGeJljhSaUYGVmhqJNmnOmqZQycOFhkEvCq+/twNMF7ojFC9pl5EukbN9 gOerXCtBQV58ahmyweGooFaqHbEaj7t/MRYb2SFw= Date: Fri, 29 Jan 2021 17:31:47 +0100 From: Clemens Gruber To: Sven Van Asbroeck Cc: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Thierry Reding , Linux Kernel Mailing List , linux-pwm@vger.kernel.org Subject: Re: [PATCH v5 2/7] pwm: pca9685: Support hardware readout Message-ID: References: <20201216125320.5277-1-clemens.gruber@pqgruber.com> <20201216125320.5277-2-clemens.gruber@pqgruber.com> <20210111203532.m3yvq6e5bcpjs7mc@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sven, On Fri, Jan 29, 2021 at 08:42:13AM -0500, Sven Van Asbroeck wrote: > On Mon, Jan 11, 2021 at 3:35 PM Uwe Kleine-K?nig > wrote: > > > > My position here is: A consumer should disable a PWM before calling > > pwm_put. The driver should however not enforce this and so should not > > modify the hardware state in .free(). > > > > Also .probe should not change the PWM configuration. > > I agree that this is the most user-friendly behaviour. > > The problem however with the pca9685 is that it has many degrees of > freedom: there are many possible register values which produce the same > physical chip outputs. > > This could lead to a situation where, if .probe() does not reset the register > values, subsequent writes may lead to different outputs than expected. > > One possible solution is to write .get_state() so that it always reads the > correct state, even if "unconventional" register settings are present, i.e. > those written by an outside entity, e.g. a bootloader. Then write that > state back using driver conventions. > > This may be trickier than it sounds - after all we've learnt that the pca9685 > looks simple on the surface, but is actually quite challenging to get right. > > Clemens, Uwe, what do you think? Ok, so you suggest we extend our get_state logic to deal with cases like the following: If neither full OFF nor full ON is set && ON == OFF, we should probably set the full OFF bit to disable the PWM and log a warning message? (e.g. "invalid register setting detected: pwm disabled" ?) If the ON registers are set and the nxp,staggered-outputs property is not, I'd calculate (off - on) & 4095, set the OFF register to that value and clear the ON register. And then call our get_state in .probe, followed by a write of the resulting / fixed-up state? This would definitely solve the problem of invalid/unconventional values set by the bootloader and avoid inconsistencies. Sounds good to me! If Thierry and Uwe have no objections, I can send out a new round of patches in the upcoming weeks. My current goal is to get the changes into 5.13. Thanks, Clemens