Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1034290ybb; Fri, 3 Apr 2020 16:53:56 -0700 (PDT) X-Google-Smtp-Source: APiQypIPazBkKFi+kITJ+ppJC0HO7/R33T5jY/n4Vt02jdTTZ3eWX+KMaK2Qcfr4urUHa7y3RI/T X-Received: by 2002:a9d:6b02:: with SMTP id g2mr8778570otp.340.1585958036361; Fri, 03 Apr 2020 16:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585958036; cv=none; d=google.com; s=arc-20160816; b=V98UJp9Vi4YCu05hLKIuYtBRmU3/9zhAHJo7Md5W/SYC3ROM/ADlmAcE/ay55I87BZ ve43opv3cWUjePoruFV3RdBexVBX96mqWgP2bSKiI/rFA/wYVMN1HxA9/i8Se76A8Dky xjeerWGc9R4pmqkAhR7H5MFeQw1hNDV4V7oV63fIFLNq0KEH4NqZOqjncSSyq6XRjhaO tkyu0p/x8Hw+rPf09jqGCk1o9p2rIcXMyp/wKpIWoP8DdNA9oAwCdNikHp/dWAv657Ba IqDfJ27+TGUNDofP7eZHj4vJz7HPLO+kZLxvjh+5c/HQq2GcwSnR1zzogCmeJnINqlQw B9cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ybaTpFfXn+LxmLPmE6oKCLBK1aHCu6fnDl0UMen+FlQ=; b=Nr04HfmWm+i7OziB6oo3q6J7+zMJR5oq7zzMlikqZ8cYvMw5SkXiCjRr1CyN6LZXzw yzBAIjMwNTXMVGL2VtbPjhMw+1AEQs38iMhu01uIMyG7RNgM/Q9SDL5O1T+vk0X6pVCE AxGV8Z4sDum76yZDWGwUohV/MY6FURBG8fQJCuEaykPbOzKkB/+vKpzCIwejZTgD6FIM FPVVsUDMKFmdTLit8kVa0hdK39/E3Ddzu+q9l0nMAw6GWcoAHNs9RWxNHbQxKrkPfiBo hcD7JImrDs/ZnJT6fjexPDpfDBhPmLDpUDYOQk6JtMbGoxXkwGEtneoGylOf79RzQL7b rfow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c+WwfWnO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id z22si4367098oto.237.2020.04.03.16.53.43; Fri, 03 Apr 2020 16:53:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c+WwfWnO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726197AbgDCXx3 (ORCPT + 99 others); Fri, 3 Apr 2020 19:53:29 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:34896 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgDCXx3 (ORCPT ); Fri, 3 Apr 2020 19:53:29 -0400 Received: by mail-qk1-f193.google.com with SMTP id k13so10067926qki.2; Fri, 03 Apr 2020 16:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ybaTpFfXn+LxmLPmE6oKCLBK1aHCu6fnDl0UMen+FlQ=; b=c+WwfWnOklwmjmATtt9PNjWRluiTClyYp0jcstMXvu/qdAut4CGP9x02z61LxH7M3i PtPUsAPcCc704lQFMf5323rEJBO1nohLgnzhGarL0ULJuYJgvR4lQB+vwHso2W3oOI6z Dfyj3zM/xpBVy7Wk/0Z82xsof4atcTG9GBwRRHimkSIm6VghfgXi8N7cxdmjmuvRq7zT KBGJTnu0slPw65DkF+gngJ2UIp4c4e/4sp52KI9r7r7xuHagqEXVvKD/VrBq1zloBiSS 0jo099Yb7hQsxPUlXKMgZbN9crlMd+29e1VsF/FuEUC5Xny9KX6+85RjkDGzkbSK22/+ BKkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ybaTpFfXn+LxmLPmE6oKCLBK1aHCu6fnDl0UMen+FlQ=; b=P+0vpRfZR/4dkDliFZ5xcUcan+sKoA0XtDIMrVXZrQg3EiEPzssi6NoCiknz6o6fIV +1B1x4MX5dedqBcAffcYO4tK6TW9Uai/teQsQarqKGzOul0r8dVYIU0SlAw+hciheJIV nkaDd4dacYMDwTK+HVr9FxmwwETwKKvrlzgp4RP7+eFlIXJQ5JwIM3zxuaSlJgkkwojq kBDK65gku+ezZhJjsUfk0OZFCWfhn7ykiWHpbLRX8H4pML4y5RIniseNp/945YVg0oar kqSl6ecN10zYTrdtEl5ktnftPxGYeHSEDKiojPMN/mHcKgadqmQ3LbUOmAz6ulaVczxM jDIg== X-Gm-Message-State: AGi0Pub+AHTSziPQyl7foG+hiyW5FNDXmImdkyTPLzU+rkpr1KaKu7t3 PsL3kGOy2Qdqv7YNaMibRAc= X-Received: by 2002:a37:9dc9:: with SMTP id g192mr11860484qke.50.1585958007869; Fri, 03 Apr 2020 16:53:27 -0700 (PDT) Received: from localhost.localdomain ([72.53.229.195]) by smtp.gmail.com with ESMTPSA id p186sm2143388qkb.71.2020.04.03.16.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 16:53:27 -0700 (PDT) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Thierry Reding Cc: Matthias Schiffer , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Clemens Gruber , Andy Shevchenko , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] pwm: pca9685: re-enable active pwm channels on pwm period change Date: Fri, 3 Apr 2020 19:53:24 -0400 Message-Id: <20200403235324.27437-1-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to change the pwm period, this chip must be put in sleep mode. However, when coming out of sleep mode, the pwm channel state is not completely restored: all pwm channels are off by default. This results in a bug in this driver: when the pwm period is changed on a pwm channel, all other pwm channels will be deactivated. Fix by clearing the RESTART bit when coming out of sleep mode - this will restore all pwm channels to their pre-sleep on/off state. Reported-by: Matthias Schiffer Cc: Matthias Schiffer Cc: Uwe Kleine-König Cc: Clemens Gruber Cc: Andy Shevchenko Cc: linux-pwm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Link: https://lore.kernel.org/lkml/32ec35c2b3da119dd2c7bc09742796a0d8a9607e.camel@ew.tq-group.com/ Signed-off-by: Sven Van Asbroeck --- I no longer have access to pca9685 hardware, so I'm unable to test: - if this is indeed a bug - if this patch fixes it Made against: Tree-repo: git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git Tree-branch: for-next Tree-git-id: 9cc5f232a4b6a0ef6e9b57876d61b88f61bdd7c2 drivers/pwm/pwm-pca9685.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c index 76cd22bd6614..0a16f0122e0e 100644 --- a/drivers/pwm/pwm-pca9685.c +++ b/drivers/pwm/pwm-pca9685.c @@ -59,6 +59,7 @@ #define LED_FULL (1 << 4) #define MODE1_SLEEP (1 << 4) +#define MODE1_RESTART (1 << 7) #define MODE2_INVRT (1 << 4) #define MODE2_OUTDRV (1 << 2) @@ -271,6 +272,15 @@ static int pca9685_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, /* Wake the chip up */ pca9685_set_sleep_mode(pca, false); + /* If any pwm channels were active when the chip was put + * in sleep mode, re-activate them. + */ + if (!regmap_read(pca->regmap, PCA9685_MODE1, ®) && + reg & MODE1_RESTART) + regmap_update_bits(pca->regmap, PCA9685_MODE1, + MODE1_RESTART, + MODE1_RESTART); + pca->period_ns = period_ns; } else { dev_err(chip->dev, -- 2.17.1