Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp726182pxb; Thu, 15 Apr 2021 05:16:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGkRu8JND1BxufAj/no5KykgN/YU0L5SwW27era5MSGOjmWXb2wRo/eci+FHErGnK050Im X-Received: by 2002:a62:808b:0:b029:252:eddc:afb0 with SMTP id j133-20020a62808b0000b0290252eddcafb0mr3046083pfd.41.1618488973968; Thu, 15 Apr 2021 05:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618488973; cv=none; d=google.com; s=arc-20160816; b=FgUohpZo+IpYW8oJ0N7KtJWq2Iet+w+qTESypjGVHXZs91wqJPTYeLqaUbDlmRplxP KwTt3n8q9d3NPd2rhsaoXBgtsjJ8ncOYAqIr8dQGsEUcnW0YFttrHHO5mVZH8bo/6Ac+ DPqZaGoaCZrHXTToAxvO6ZLB8bgGbZfeH1T1h0DwNa1COw89V82NvIxTWOdNrYaFJFNn BhLHA1EyLPWDKJgdyByf8puVmbTgWhX3QQlaXGUJry/bhxPU6moYkLaCTYIAsHKrgTRo DYqgLWvCd8S9Ga5VQP4slOCN8gPzSNzxtuvQk7qGOmHit2DzmaRs+dtiRrleYJY6J74u 4DVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F3hXPjM9wtbrWoMAGiw2fyCzbJmA6VnJB+0OF7F65tY=; b=Jv28OSz5DNd9uRXKXxxRby8QdUA7FgZ6vk1ePly0PRqXcmj4q70Wi5taCdniRQKtAp l9MKMI6+oROy7n5R/tTXeWBiZxytaNGY5dkQoVsL0UrCcvHtAK51mjix23B4N5Ey7HNX urvkJNjilcz866mQOeOqYga3jA7UucL8hNaT60xjKUeiKVsb+n+AKvAv4BJpk9zdfOBX JCkLziwGiThPE4NArS0oryY7uCW9tZX3wv0CiKx6ohwRqK95QnD9FKtB+mr5/WYZmFhh +tTLX/XaCnhufwXyX230OihMV4sKbtIKfhBV2pDV5FFuK9GjJoFCAD4JnxEWZ9ISNmlZ 2sHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pqgruber.com header.s=mail header.b=AqQ3olZy; 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=REJECT 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 v3si2861265pjh.78.2021.04.15.05.16.02; Thu, 15 Apr 2021 05:16:13 -0700 (PDT) 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=AqQ3olZy; 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=REJECT sp=NONE dis=NONE) header.from=pqgruber.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232785AbhDOMPt (ORCPT + 99 others); Thu, 15 Apr 2021 08:15:49 -0400 Received: from mail.pqgruber.com ([52.59.78.55]:34772 "EHLO mail.pqgruber.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232771AbhDOMPs (ORCPT ); Thu, 15 Apr 2021 08:15:48 -0400 Received: from workstation.tuxnet (213-47-165-233.cable.dynamic.surfer.at [213.47.165.233]) by mail.pqgruber.com (Postfix) with ESMTPSA id 9C870C725D8; Thu, 15 Apr 2021 14:15:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqgruber.com; s=mail; t=1618488923; bh=F3hXPjM9wtbrWoMAGiw2fyCzbJmA6VnJB+0OF7F65tY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AqQ3olZyjCQYfsjVpd3xIG9dQEy9l/9Ga/mspDkEtI66pSBDKLSCBh4g9QKLvvEvg rDkaCBTJxKzscs6vcy9Tk1KMVufSEA3ww8INe7IU4cCW00WF/UJuHmZiDLZynG5SWj cJRdkkdfI154aBaVFvNMULVRjpd1HxifhSSzRs3c= From: Clemens Gruber To: linux-pwm@vger.kernel.org Cc: Thierry Reding , Sven Van Asbroeck , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Clemens Gruber Subject: [PATCH v9 3/8] pwm: pca9685: Improve runtime PM behavior Date: Thu, 15 Apr 2021 14:14:50 +0200 Message-Id: <20210415121455.39536-3-clemens.gruber@pqgruber.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210415121455.39536-1-clemens.gruber@pqgruber.com> References: <20210415121455.39536-1-clemens.gruber@pqgruber.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The chip does not come out of POR in active state but in sleep state. To be sure (in case the bootloader woke it up) we force it to sleep in probe. If runtime PM is disabled, we instead wake the chip in .probe and put it to sleep in .remove. Signed-off-by: Clemens Gruber --- Changes since v8: - Rebased Changes since v7: - Handle sysfs power control as well and not just CONFIG_PM Changes since v6: - Improved !CONFIG_PM handling (wake it up without putting it to sleep first) drivers/pwm/pwm-pca9685.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c index aa48c45bd294..1b013d03f5d8 100644 --- a/drivers/pwm/pwm-pca9685.c +++ b/drivers/pwm/pwm-pca9685.c @@ -462,14 +462,20 @@ static int pca9685_pwm_probe(struct i2c_client *client, return ret; } - /* The chip comes out of power-up in the active state */ - pm_runtime_set_active(&client->dev); - /* - * Enable will put the chip into suspend, which is what we - * want as all outputs are disabled at this point - */ pm_runtime_enable(&client->dev); + if (pm_runtime_enabled(&client->dev)) { + /* + * Although the chip comes out of power-up in the sleep state, + * we force it to sleep in case it was woken up before + */ + pca9685_set_sleep_mode(pca, true); + pm_runtime_set_suspended(&client->dev); + } else { + /* Wake the chip up if runtime PM is disabled */ + pca9685_set_sleep_mode(pca, false); + } + return 0; } @@ -481,7 +487,14 @@ static int pca9685_pwm_remove(struct i2c_client *client) ret = pwmchip_remove(&pca->chip); if (ret) return ret; + + if (!pm_runtime_enabled(&client->dev)) { + /* Put chip in sleep state if runtime PM is disabled */ + pca9685_set_sleep_mode(pca, true); + } + pm_runtime_disable(&client->dev); + return 0; } -- 2.31.1