From patchwork Fri Nov 17 22:59:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 839169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Pxcj3HdN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydtq4641Pz9s3w for ; Sat, 18 Nov 2017 09:59:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966850AbdKQW7n (ORCPT ); Fri, 17 Nov 2017 17:59:43 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:40346 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935287AbdKQW7k (ORCPT ); Fri, 17 Nov 2017 17:59:40 -0500 Received: by mail-qk0-f196.google.com with SMTP id p7so1287876qkd.7; Fri, 17 Nov 2017 14:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=AbKgo3SgmcZQW61VO3ErzLwpdBI876XVQ8e0LK41AnE=; b=Pxcj3HdNmo8aaGJpLIB0r67EDjPBdT8gpVvyTOvXHBks51x/r3hcqzdC+ixjEuXDmI /oglkMvGLEhH4cnAo+Mee9AHWl2plAQ4fsRKzLukYmxgmy9+ScM7hn1doyuSntfdQhOW OrJrYRrXkfw/r1CPOPcSHZmVdKZ/C9hOyUyNBL16q80pktx1PeSUbQ+AGnBGHrFu6KPU SoeQbRxgpZisoP1XF5PhRu0VRNTHlhXI3eevWhAae8Pi7PzPCwm8S9wyonbQjD3FzrsJ ebhN/ikPlE8rwTLkWwMYnHQq6uTjSLx7M/lp8izapge4QS7Nexq4dNRD+J0yE5pVkclV 1DTQ== 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; bh=AbKgo3SgmcZQW61VO3ErzLwpdBI876XVQ8e0LK41AnE=; b=n7+dJ1NHrzpC8UMFTFEojOi8JIhqvDeuzMVACdBb/uAWBfVIIoqLQFAIRMNHBJs7on /Pc5UyjYfsSQBrgTLWPbeeBM4lgW2hM6EMcgiqzxij+C3JBXp14r7FUqC32R/G62knW9 vwU2pN+MDB3itJJazeR4jDl5lUd7wKW3fnWPqPXq4/rl9hUuBI9QIaGYisNOdy7sSnG7 nyM15g8MQjwOXWgMiYyo4oSLye9wPQVWJucNzjFLbJNEc3IwA3wy7LWAhPf7qTf5G0+Z FxSmtJfdJPOVxZdLy6tDSJORhkUzMpd9zFDbltO7I+sFl+eCkPD/QU8ePHytHB1HfIsY sguw== X-Gm-Message-State: AJaThX7+imDXuko4GUCTCcWH5X5jRmvhFUfToAi8Eldsx/N5oHtI/lMJ JtFlTgMGjqwqMLNpPoFhWn0= X-Google-Smtp-Source: AGs4zMYwVIz280aqrrUc3JvKipMvEOsLMX7y90hp9Q/Q4kM1FNIGyySzIl7tggLJG5FRSx0Xq9NuFA== X-Received: by 10.55.33.70 with SMTP id h67mr10213449qkh.343.1510959578453; Fri, 17 Nov 2017 14:59:38 -0800 (PST) Received: from localhost.localdomain ([189.61.212.159]) by smtp.gmail.com with ESMTPSA id y58sm3335700qtb.9.2017.11.17.14.59.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Nov 2017 14:59:37 -0800 (PST) From: Fabio Estevam To: thierry.reding@gmail.com Cc: robh+dt@kernel.org, linux@arm.linux.org.uk, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH] pwm: imx: Allow keeping the PWM active during suspend Date: Fri, 17 Nov 2017 20:59:27 -0200 Message-Id: <1510959567-7956-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org From: Fabio Estevam In some systems it is desirable to keep the PWM active during system suspend. One use case is the imx6q-cubox-i board, which has an LED driven by PWM. When the system goes into suspend the PWM block is disabled by default, the PWM pin goes to zero and turn on the LED during suspend, which is not really the behaviour we want to see. By keeping the PWM enabled during suspend the pwm-leds driver sets the brightness to zero in suspend and then the LED is turned off as expected. Introduce the 'fsl,suspend-enable' property to indicate that the PWM will stay active during suspend. Signed-off-by: Fabio Estevam --- Documentation/devicetree/bindings/pwm/imx-pwm.txt | 5 +++++ drivers/pwm/pwm-imx.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Documentation/devicetree/bindings/pwm/imx-pwm.txt b/Documentation/devicetree/bindings/pwm/imx-pwm.txt index c61bdf8..1e00a89 100644 --- a/Documentation/devicetree/bindings/pwm/imx-pwm.txt +++ b/Documentation/devicetree/bindings/pwm/imx-pwm.txt @@ -14,6 +14,11 @@ See the clock consumer binding, Documentation/devicetree/bindings/clock/clock-bindings.txt - interrupts: The interrupt for the pwm controller +Optional properties: +- fsl,suspend-enable: Boolean property that indicates that the PWM block stays + enabled during system suspend. If not present, the PWM + block will be disabled during suspend. + Example: pwm1: pwm@53fb4000 { diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index 2ba5c3a..b9c60fe 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -35,6 +35,7 @@ #define MX3_PWMSAR 0x0C /* PWM Sample Register */ #define MX3_PWMPR 0x10 /* PWM Period Register */ #define MX3_PWMCR_PRESCALER(x) ((((x) - 1) & 0xFFF) << 4) +#define MX3_PWMCR_STOPEN (1 << 25) #define MX3_PWMCR_DOZEEN (1 << 24) #define MX3_PWMCR_WAITEN (1 << 23) #define MX3_PWMCR_DBGEN (1 << 22) @@ -54,6 +55,7 @@ struct imx_chip { void __iomem *mmio_base; struct pwm_chip chip; + bool suspend_enable; }; #define to_imx_chip(chip) container_of(chip, struct imx_chip, chip) @@ -217,6 +219,9 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, if (state->polarity == PWM_POLARITY_INVERSED) cr |= MX3_PWMCR_POUTC; + if (imx->suspend_enable) + cr |= MX3_PWMCR_STOPEN; + writel(cr, imx->mmio_base + MX3_PWMCR); } else if (cstate.enabled) { writel(0, imx->mmio_base + MX3_PWMCR); @@ -264,6 +269,7 @@ static int imx_pwm_probe(struct platform_device *pdev) { const struct of_device_id *of_id = of_match_device(imx_pwm_dt_ids, &pdev->dev); + struct device_node *np = pdev->dev.of_node; const struct imx_pwm_data *data; struct imx_chip *imx; struct resource *r; @@ -301,6 +307,8 @@ static int imx_pwm_probe(struct platform_device *pdev) if (IS_ERR(imx->mmio_base)) return PTR_ERR(imx->mmio_base); + imx->suspend_enable = of_property_read_bool(np, "fsl,suspend-enable"); + ret = pwmchip_add(&imx->chip); if (ret < 0) return ret;