Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5935651ybi; Wed, 12 Jun 2019 11:00:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqxJK68t0ouaPmPys91BEkytidz6Ph2mb6So0QUSjtVZv1/TfvNkYW/+etgpSWDgpprL14 X-Received: by 2002:a17:90a:ae10:: with SMTP id t16mr434646pjq.51.1560362423187; Wed, 12 Jun 2019 11:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560362423; cv=none; d=google.com; s=arc-20160816; b=ZVuzTGDi42mMkpiotUZgdj7i7RyL1CL44vj9UR0Mj41rY2QCPDjFnEAyhvBx7PicB6 L0LX50IcE+FecF1iKO4hW7Wt69rn0E7Q2+d1K4fwV3y5XXjCfm3sPgEfuKGW9jsn1Ot/ DBrO3VnEx38jN0zJIc+JVYWZk5jspyWwEO689fyn/NgYH6Z0DAqrktQCuVekJ3yc6GiY Yje+ToUl49QW5v3wf0J+1/+3IIHE73O2tLrmyS0q2G1gs2bodJBLsaeiOkz2aCFNcLPz ejM/Z7e7mMbOkXx7IFGZv6hSAJQTpf9ms0q04oSMRFg8pQfjgCZ3jjSfgQxhEyJht7+W 3x/A== 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=dnpQA/36f3puBoeFdufMNivJajWtYx7kIb4vLCA2A/8=; b=jKmy2Ab/fi0o4G2ZBs/LXtPPp6k+AiVa056kE/wgRxbX7Cqy+yU3TzbWN1C/B9skqe 3qricUzCNiE6oZGY/nCeYH+7oJ8Zz2tZQtkW0OfoXYqKgxXM1ZInfJQL3YRbexUDxs1x flyYkqJDgFiNo1g8svFzFYFkf02lz6mMlCNSqmEhGtJPb8uoWsoDQXkfXLSHqFb2rmIc pcTZDPW7rRG1EJbXD2yKeCNuikL6BX/UlqL6as2QwyPdy0OaiDCrMFmVL+DdqEDos/Hh iUiIkP+/eHuW+awkxyrJ5Rxps1BoxXjqpdNL0jPzu5RUr8T63Qs3hQW210bjIxU3+MO1 LXSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@essensium-com.20150623.gappssmtp.com header.s=20150623 header.b=P6WoLLKD; 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 a17si395967pfa.108.2019.06.12.11.00.08; Wed, 12 Jun 2019 11:00:23 -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=@essensium-com.20150623.gappssmtp.com header.s=20150623 header.b=P6WoLLKD; 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 S1732440AbfFLONT (ORCPT + 99 others); Wed, 12 Jun 2019 10:13:19 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:35873 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731247AbfFLONO (ORCPT ); Wed, 12 Jun 2019 10:13:14 -0400 Received: by mail-ed1-f66.google.com with SMTP id k21so22640442edq.3 for ; Wed, 12 Jun 2019 07:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dnpQA/36f3puBoeFdufMNivJajWtYx7kIb4vLCA2A/8=; b=P6WoLLKDEQq28OBHm7SuaGw4zqDlXJ0Z/hMhyJYWPEVHGF/7EksRN/sHsUHVbvBp5q JFjOAVpKVtFvlan05c6wb9hjFWT4luqHxi8ZF/PLD1hTksqOzBgO+DUrrg36a6fFH+r+ NYynLU2AvvrKmT6HcQ43EjcwdxSNZciavMh8iRV9R5iXLPLVDMmJE0WVunA6b+y40cgy yweJoXJnHuiODpzHMPGg0P++G+fXQQKzIaRYeSaMNDzCYne6jIuhvCgbC0wGtHPM5X9D l2totDj2/6M2qX7IaYXIGjkDtuiKK8YGZEdSrTmeQhATqh7Yjku2qQusF6SnklYSdtje 6Bew== 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=dnpQA/36f3puBoeFdufMNivJajWtYx7kIb4vLCA2A/8=; b=rxPMFOD+eSsbnWByKysSaaNKcS1KLfLbtHl51xRG1ZvdtYcnRs7APrY0BuOIyAwDwM 5UbRMM0auFQmWEjQOdOcssyYQ6KBbnDnqkX0aiNa4byTOCLdvHmiVFRP6bMfRtgJHMPd X5s+qOOG7EWhkv9YzW7OmXINRW7xC0Y3Tj3iIyuRT7us7D1K8CvN3hooUlClvgV0fxp6 JU6xmilNaF1gNh5yrdbfvlT+i3li6fbTl/EP671BTVNOrh1pgRqnSOxSoN45iElBb7L+ bu2yKYaPzn4hmL3LvnvwP+QwpJTQL6smkT/DWTpxqr+EJSE04E2z5VmUbzTHxZvM+rQ8 M5bQ== X-Gm-Message-State: APjAAAUPggfwPlxzKJH0gPtlVf0dow9vP9Zt40gt0XkXAJEUA+nDHKmv YxjIlhbm7/y8MYwXLXXTEb7vGw== X-Received: by 2002:a17:906:e204:: with SMTP id gf4mr29870786ejb.302.1560348793032; Wed, 12 Jun 2019 07:13:13 -0700 (PDT) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id g2sm7095eja.23.2019.06.12.07.13.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 12 Jun 2019 07:13:12 -0700 (PDT) From: Patrick Havelange To: Thierry Reding , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiubo Li Cc: Patrick Havelange Subject: [PATCH 2/2] pwm: pwm-fsl-ftm: Use write protection for prescaler & polarity Date: Wed, 12 Jun 2019 16:12:46 +0200 Message-Id: <20190612141246.7366-2-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190612141246.7366-1-patrick.havelange@essensium.com> References: <20190612141246.7366-1-patrick.havelange@essensium.com> 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 Modifying the prescaler or polarity value must be done with the write protection disabled. Currently this is working by chance as the write protection is in a disabled state by default. This patch makes sure that we enable/disable the write protection when needed. Signed-off-by: Patrick Havelange --- drivers/pwm/pwm-fsl-ftm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c index cd5fe39ab95d..e955b1cdfd2f 100644 --- a/drivers/pwm/pwm-fsl-ftm.c +++ b/drivers/pwm/pwm-fsl-ftm.c @@ -59,6 +59,21 @@ static inline struct fsl_pwm_chip *to_fsl_chip(struct pwm_chip *chip) return container_of(chip, struct fsl_pwm_chip, chip); } +static void ftm_clear_write_protection(struct fsl_pwm_chip *fpc) +{ + u32 val; + + regmap_read(fpc->regmap, FTM_FMS, &val); + if (val & FTM_FMS_WPEN) + regmap_update_bits(fpc->regmap, FTM_MODE, FTM_MODE_WPDIS, + FTM_MODE_WPDIS); +} + +static void ftm_set_write_protection(struct fsl_pwm_chip *fpc) +{ + regmap_update_bits(fpc->regmap, FTM_FMS, FTM_FMS_WPEN, FTM_FMS_WPEN); +} + static bool fsl_pwm_periodcfg_are_equal(const struct fsl_pwm_periodcfg *a, const struct fsl_pwm_periodcfg *b) { @@ -253,6 +268,8 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc, do_write_period = true; } + ftm_clear_write_protection(fpc); + if (do_write_period) { regmap_update_bits(fpc->regmap, FTM_SC, FTM_SC_CLK_MASK, FTM_SC_CLK(periodcfg.clk_select)); @@ -279,6 +296,8 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc, fpc->period.mod_period + 1); newstate->duty_cycle = fsl_pwm_ticks_to_ns(fpc, duty); + ftm_set_write_protection(fpc); + return 0; } @@ -359,6 +378,8 @@ static int fsl_pwm_init(struct fsl_pwm_chip *fpc) static bool fsl_pwm_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { + case FTM_FMS: + case FTM_MODE: case FTM_CNT: return true; } -- 2.19.1