Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2345270imm; Thu, 7 Jun 2018 09:06:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIkR4ITYLP1gQ9DmgqaMqoinl9+nT9ts4OpzRO6wR/bHwfxMIM0q7n1G1dGO5CP7yIZmv1W X-Received: by 2002:a63:6882:: with SMTP id d124-v6mr2037074pgc.83.1528387605720; Thu, 07 Jun 2018 09:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528387605; cv=none; d=google.com; s=arc-20160816; b=AuSIb0qsQ0rOiXeIDUjaIMx96Gp6erUN658B5r8dybFUVQWAzFsw9Rg5b0WYaLxepI wQ2p9N4WH+bJjtT5HefWte3cYbWmqaw8qeDQnFh7AaYWmlYzpMXNGgAfSPu/jtvNticN wY3ika49hqdC7hQIncFlagYnytcS4P3V7KwvI1v8eh9iKgfdvYGDNgQzrR2iFVbxKZ8t HOZbeLDsMR5Z52vyh8ZorOA5d/6EVmxGWn7PRIUxA+MiCkHAWX236prvszA4+OtFr6yY zM0+78moIW3XmSvTpNUIsMWcoW9elSCuAHUv0g7BXeJekhxR/DhYvZ9ObUlokXTjVJnf TYTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=TH4Z48IVCwNWcJypkI8J/7b3OWuerFvQHK8Q1Ex1Jkg=; b=fd2goyO+21AVKWeSZumWGVm3Ccy0TYD0A3fKubXbKpNOibYxlR4AzWVmIIwbgCojP6 PQSfShto+lzisNPRpDbLOtR6JwLqNEGzx6kaxnJlQdj9IwUaHW782xLoyWgGrNilm7ap nbZ7NwzHIuGMq6TAGe7hN0XvtMRZEVJVsm+mNBRqCUSNvlbnHGUY+iwsW4sr16n8WpCV PeyKgGxKtjn2ISwHEBkwAQF2tHj8CQXpOhORJuCrz8VNMG9d7L8k87/BTOL6XJ0Jc93/ 0R84ayN0MATtD6f62mEMVLjgkEJ0bLwYuV0/7s1hcj0pIcrlQ3L8JkM7rspVZOUWT86L 2ajg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2-v6si32313781plr.598.2018.06.07.09.06.30; Thu, 07 Jun 2018 09:06:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936043AbeFGQFR (ORCPT + 99 others); Thu, 7 Jun 2018 12:05:17 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39229 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933000AbeFGOJD (ORCPT ); Thu, 7 Jun 2018 10:09:03 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvb4-0005Zs-6G; Thu, 07 Jun 2018 15:09:02 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb0-0002oO-UI; Thu, 07 Jun 2018 15:08:58 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Andy Shevchenko" , "Linus Walleij" , "Florian Fainelli" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 089/410] pinctrl: Really force states during suspend/resume In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Florian Fainelli commit 981ed1bfbc6c4660b2ddaa8392893e20a6255048 upstream. In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes in a way that the pin states are not preserved by the hardware, when we resume, we would call pinctrl_single_resume() -> pinctrl_force_default() -> pinctrl_select_state() and the first thing we do is check that the pins state is the same as before, and do nothing. In order to fix this, decouple the actual state change from pinctrl_select_state() and move it pinctrl_commit_state(), while keeping the p->state == state check in pinctrl_select_state() not to change the caller assumptions. pinctrl_force_sleep() and pinctrl_force_default() are updated to bypass the state check by calling pinctrl_commit_state(). [Linus Walleij] The forced pin control states are currently only used in some pin controller drivers that grab their own reference to their own pins. This is equal to the pin control hogs: pins taken by pin control devices since there are no corresponding device in the Linux device hierarchy, such as memory controller lines or unused GPIO lines, or GPIO lines that are used orthogonally from the GPIO subsystem but pincontrol-wise managed as hogs (non-strict mode, allowing simultaneous use by GPIO and pin control). For this case forcing the state from the drivers' suspend()/resume() callbacks makes sense and should semantically match the name of the function. Fixes: 6e5e959dde0d ("pinctrl: API changes to support multiple states per device") Signed-off-by: Florian Fainelli Reviewed-by: Andy Shevchenko Signed-off-by: Linus Walleij Signed-off-by: Ben Hutchings --- drivers/pinctrl/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -977,19 +977,16 @@ struct pinctrl_state *pinctrl_lookup_sta EXPORT_SYMBOL_GPL(pinctrl_lookup_state); /** - * pinctrl_select_state() - select/activate/program a pinctrl state to HW + * pinctrl_commit_state() - select/activate/program a pinctrl state to HW * @p: the pinctrl handle for the device that requests configuration * @state: the state handle to select/activate/program */ -int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) +static int pinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state) { struct pinctrl_setting *setting, *setting2; struct pinctrl_state *old_state = p->state; int ret; - if (p->state == state) - return 0; - if (p->state) { /* * The set of groups with a mux configuration in the old state @@ -1067,6 +1064,19 @@ unapply_new_state: return ret; } + +/** + * pinctrl_select_state() - select/activate/program a pinctrl state to HW + * @p: the pinctrl handle for the device that requests configuration + * @state: the state handle to select/activate/program + */ +int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) +{ + if (p->state == state) + return 0; + + return pinctrl_commit_state(p, state); +} EXPORT_SYMBOL_GPL(pinctrl_select_state); static void devm_pinctrl_release(struct device *dev, void *res) @@ -1235,7 +1245,7 @@ void pinctrl_unregister_map(struct pinct int pinctrl_force_sleep(struct pinctrl_dev *pctldev) { if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep)) - return pinctrl_select_state(pctldev->p, pctldev->hog_sleep); + return pinctrl_commit_state(pctldev->p, pctldev->hog_sleep); return 0; } EXPORT_SYMBOL_GPL(pinctrl_force_sleep); @@ -1247,7 +1257,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep); int pinctrl_force_default(struct pinctrl_dev *pctldev) { if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default)) - return pinctrl_select_state(pctldev->p, pctldev->hog_default); + return pinctrl_commit_state(pctldev->p, pctldev->hog_default); return 0; } EXPORT_SYMBOL_GPL(pinctrl_force_default);