Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp886684ybp; Fri, 4 Oct 2019 06:33:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDIqZnG+8Sit43WxfUWsQNbZhDj2E1mvCh30ju659QIW28sxZ2ZULwKEQ8lV9BqRy744Ko X-Received: by 2002:a50:87ca:: with SMTP id 10mr15337521edz.77.1570196023788; Fri, 04 Oct 2019 06:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570196023; cv=none; d=google.com; s=arc-20160816; b=pdMxP1QQ0VUDe5+nPbMxDODqoU0yaqjZzCN+Y08eT4nMTpl/PhbIHewYF9RtxBLOxC iuPgbpSMFhyxHm1fxfcxrYvauzrU1/ttF4jIiP8FIW/ZNIqJ/x/2gXdmpxmJ7pB5lXZs c3rk3j58dlx3TP7ktw97x/Hgyw6bOFKOF+oQNMpgT6Nt6JezOt/PNNX3mSh+aDbaPOeS 2W6IrvcKBXYAjkPhwUFHk3ZfYUcztQdkb/+XfyCI5yHi12X5XvN5lZuyB4xeQ87DJtNr Vwl2IYCcSLGtkvBRT+0uThfOMVb1H4j7SVUXk3i3tTvsIy8LdSffEOYlxZa50fo/czwb +jfQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X6Db+RHzUjtZcLjspCPiiVLnQJwYqeZzGLFvIcIslUs=; b=Hou2CVPjF6qDq7ye819r5bUWYsb5G18EY4D4AHd8y6tqL/l75kTKQ13AWsF9cC1lQx hwb+LOJm6OGzD1bp+9O43eU6YmTZwM6GOTPPxlru2fv69s60vzaM8ipuEzysL8zTcb2e lS+VsJL3+T0h7DvCdhE2jYaX379skHqIQ0JMZ/qKDu2g+N1P4hf5PzToOc6UzX2xKhRI 45Nsqf1zrvlNmehGl9MfMSRNO0oqI3Dn1St77R0Zgyba7jrafPTZmMaIbewkbywsJP54 F57LgihVBLaw+iVWnZLQTHRSSqzv1dllWJ2Q5GpJoHqSzkZ57nr00Qp2bKrHcd4HsetQ QpXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=EGVRYZjk; 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 h4si4116001edd.189.2019.10.04.06.33.19; Fri, 04 Oct 2019 06:33:43 -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=@rasmusvillemoes.dk header.s=google header.b=EGVRYZjk; 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 S2388648AbfJDNdF (ORCPT + 99 others); Fri, 4 Oct 2019 09:33:05 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:37363 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388577AbfJDNdE (ORCPT ); Fri, 4 Oct 2019 09:33:04 -0400 Received: by mail-lf1-f65.google.com with SMTP id w67so4506375lff.4 for ; Fri, 04 Oct 2019 06:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X6Db+RHzUjtZcLjspCPiiVLnQJwYqeZzGLFvIcIslUs=; b=EGVRYZjk/WuzVKJ889bp0hqc2OMOmT3XYKoBXPdA1Vo8S9tycus3E4uyFwntaQNmPZ ah6F1kEyygcpepYCQED3SNi4fnY76jnic5yumvljF37O+sFQp84qgT9FeUWGnGJiOnf9 2MQ+vNE9bqr9v/kHpqcszX8Vk4g2WdcXlhoek= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=X6Db+RHzUjtZcLjspCPiiVLnQJwYqeZzGLFvIcIslUs=; b=mQ3dqEx/p0Wx94Ir3olDBDgYR+iBKtYgPqiLec5dnn3B4pBq/vsDigGg6Pzxfbfh9G LQGXZodqshl+PqEu+hbkrfeysTmsPRLwKSg7ll9HphvhwDyWQTj0FJSpAWKN1l+IMJiB RQe27sO5a10EPjDV0Iy5j/B9XowCgs8IPnkcJlop8dAgTyAl78xRYf5hQdxdnMB5JyVQ X2hVh8nq13e4e/0Q0jt5vyyDq+9tiRkyhOfj1s6gfPAqsDRIt36aauj5QdS+hBXIyv2f mAhL3IuvRQGl8pjeKaS+D4R+6pYHIW1czTKlgL4yOAC27A8yx+sVAG5T1ByExMaXHt9i HN7w== X-Gm-Message-State: APjAAAVbbNdKa6aP7M3nTbQ3ZNDfvSzsBSA71CxYtf2mBZ2qorUPLIW0 N12jQvLBmg9Sy301UM6ws/tMkw== X-Received: by 2002:ac2:4424:: with SMTP id w4mr8804306lfl.65.1570195982562; Fri, 04 Oct 2019 06:33:02 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id y26sm1534991ljj.90.2019.10.04.06.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:33:01 -0700 (PDT) From: Rasmus Villemoes To: Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: devicetree@vger.kernel.org, Rob Herring , Rasmus Villemoes , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] pwm: mxs: add support for inverse polarity Date: Fri, 4 Oct 2019 15:32:04 +0200 Message-Id: <20191004133207.6663-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004133207.6663-1-linux@rasmusvillemoes.dk> References: <20191004133207.6663-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If I'm reading of_pwm_xlate_with_flags() right, existing device trees that set #pwm-cells = 2 will continue to work. Signed-off-by: Rasmus Villemoes --- drivers/pwm/pwm-mxs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index 5a6835e18fc6..57562221c439 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -25,8 +25,11 @@ #define PERIOD_PERIOD(p) ((p) & 0xffff) #define PERIOD_PERIOD_MAX 0x10000 #define PERIOD_ACTIVE_HIGH (3 << 16) +#define PERIOD_ACTIVE_LOW (2 << 16) +#define PERIOD_INACTIVE_HIGH (3 << 18) #define PERIOD_INACTIVE_LOW (2 << 18) #define PERIOD_POLARITY_NORMAL (PERIOD_ACTIVE_HIGH | PERIOD_INACTIVE_LOW) +#define PERIOD_POLARITY_INVERSE (PERIOD_ACTIVE_LOW | PERIOD_INACTIVE_HIGH) #define PERIOD_CDIV(div) (((div) & 0x7) << 20) #define PERIOD_CDIV_MAX 8 @@ -50,9 +53,7 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, unsigned int period_cycles, duty_cycles; unsigned long rate; unsigned long long c; - - if (state->polarity != PWM_POLARITY_NORMAL) - return -ENOTSUPP; + unsigned int pol_bits; /* * If the PWM channel is disabled, make sure to turn on the @@ -91,9 +92,12 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, * only take effect at the beginning of a new period, avoiding * glitches. */ + + pol_bits = state->polarity == PWM_POLARITY_NORMAL ? + PERIOD_POLARITY_NORMAL : PERIOD_POLARITY_INVERSE; writel(duty_cycles << 16, mxs->base + PWM_ACTIVE0 + pwm->hwpwm * 0x20); - writel(PERIOD_PERIOD(period_cycles) | PERIOD_POLARITY_NORMAL | PERIOD_CDIV(div), + writel(PERIOD_PERIOD(period_cycles) | pol_bits | PERIOD_CDIV(div), mxs->base + PWM_PERIOD0 + pwm->hwpwm * 0x20); if (state->enabled) { @@ -135,6 +139,8 @@ static int mxs_pwm_probe(struct platform_device *pdev) mxs->chip.dev = &pdev->dev; mxs->chip.ops = &mxs_pwm_ops; + mxs->chip.of_xlate = of_pwm_xlate_with_flags; + mxs->chip.of_pwm_n_cells = 3; mxs->chip.base = -1; ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm); -- 2.20.1