Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1775903pxb; Mon, 12 Apr 2021 06:33:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7OAOBFyYnnxkL2OZkB0qxcLelufBS3erBzH8iEMRmdnp4HzHUaoWaFP/+OkHzcbazKHWI X-Received: by 2002:a05:6402:518:: with SMTP id m24mr26158759edv.170.1618234381737; Mon, 12 Apr 2021 06:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618234381; cv=none; d=google.com; s=arc-20160816; b=N8t44gCef70LPC5YfCZ5aNRskkIDHro7gRUsyBv8lwkY+OQbBBZdnbTHY9lOZ9qj+W QzD4p8hyIclALMqrzxAxb0Wlj0nxiFCcRhadQ5raxc/jLLccz2EfbTAfYAR0jk6pS9Av w6fyog/utsqYdeTeGi3zYRzeMQi8C8w2Z/1g47inQtHvQvcm/4juLeCq6Gx4zoxUzXZc UKR3JjQo7vSCODRyPT1xAAuJqncOejcCNjmqcZVHZpq5SJBQwUW3WijQbyEkDrR4EWEV AO7zSpvnarUCKuE0pjPmV6q5u3/3KG+WsqLklMeNu/Ma3jNCYqZ23+L8SN/4q4a8qd6y rkYQ== 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=47roS7h1w/gFKIyyGhSyndlIjYrwGN4+o9+olPMtSqA=; b=RDEOeg+1TZR8GQx/UC9w55zJAuB6Sqv61y6NSbh6GEE3D4oq1N6lUVN06V43mhXTnK JXgvFK+arbGBBw27YLVHV4we8o9b/X/xMTWAxmRLfCzKtu2/+NBPGMb3rg45nti1Vg0W Z2KeoKiT4IkEdBPbYM3puWhy2kFThkDpN4sDKekmFDYqWqLuM2r1yfR7Mry5uAKIshhT y5THKpIxIZHooa9VsxjrY/pU/QGVvu0urY6DZSLJ0PpVbq+1ktjHUjcTWTwyDb2w7ga6 BIvq6BPGd8VqD/Xsh2pKaBUU9dqxC8pAwR4Or2ci1Jk1GJswzLa6ooTNQvl0obfavmEG WjxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pqgruber.com header.s=mail header.b=fdJxTt6r; 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 dt15si8043966ejc.66.2021.04.12.06.32.37; Mon, 12 Apr 2021 06:33:01 -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=fdJxTt6r; 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 S241739AbhDLN3a (ORCPT + 99 others); Mon, 12 Apr 2021 09:29:30 -0400 Received: from mail.pqgruber.com ([52.59.78.55]:59804 "EHLO mail.pqgruber.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241725AbhDLN32 (ORCPT ); Mon, 12 Apr 2021 09:29:28 -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 79298C725CF; Mon, 12 Apr 2021 15:29:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqgruber.com; s=mail; t=1618234146; bh=47roS7h1w/gFKIyyGhSyndlIjYrwGN4+o9+olPMtSqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fdJxTt6raJoDjSPosRIg3eSLfSlPs9y788N7zMabrLM1I6fJpA9J59upXZwZ65wmI RKWevNOtvN+DE2XQzAlRWcuY5B5Cq8Fih/Q5KEkVxvULrjaN8OEztoRg7oZUn7lHgP +0shSW9SmAetnC7KqplK3T9LOpW+nqS67iCh6MZI= 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 v8 3/8] pwm: pca9685: Improve runtime PM behavior Date: Mon, 12 Apr 2021 15:27:40 +0200 Message-Id: <20210412132745.76609-3-clemens.gruber@pqgruber.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412132745.76609-1-clemens.gruber@pqgruber.com> References: <20210412132745.76609-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 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 b39c0ba701ab..7f97965033e7 100644 --- a/drivers/pwm/pwm-pca9685.c +++ b/drivers/pwm/pwm-pca9685.c @@ -460,14 +460,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; } @@ -479,7 +485,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