From patchwork Wed Feb 10 13:02:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 61655 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2631025lbl; Wed, 10 Feb 2016 05:06:30 -0800 (PST) X-Received: by 10.98.93.155 with SMTP id n27mr25436350pfj.88.1455109590236; Wed, 10 Feb 2016 05:06:30 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ff7si5000648pab.184.2016.02.10.05.06.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Feb 2016 05:06:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTUSd-0007Ig-Ka; Wed, 10 Feb 2016 13:05:35 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTUS3-0005vc-PA for linux-arm-kernel@lists.infradead.org; Wed, 10 Feb 2016 13:05:02 +0000 Received: by mail-wm0-x233.google.com with SMTP id 128so25910431wmz.1 for ; Wed, 10 Feb 2016 05:04:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Agt9G510QOnzmwJ5IkxO4YSGzAZhoBB+fqAW9Gsyd/4=; b=TuoXP8E6vY8U5edKCK0RkH6/ZDGSRwtl7wFsFAjGz2TbmdZh2QRCrcr72rU9ENtmtO KJ587aDYxdAPx1hWvjSXZOZwhzHNkQfgIx0P2K42lNUyTuneLdyIWeU0IzAQTFcqi9gj 2d/hE6hEsTSy0D1TX8pf1hLjGDfrYlb4GuGP0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Agt9G510QOnzmwJ5IkxO4YSGzAZhoBB+fqAW9Gsyd/4=; b=GRWMLEwTYkq6seWWc8Ypc5SC5qq9oYa9THZ6Ftmg5uXAaOsOaLB/6V5koqlRccDMwv CFvfqxqOaB1SC6PlV5gdGVwVNunHugGifnBud76s0ToLWggYR4ds4TMUQr19/c2bV7dl hoCHOrwpfBDUWC/bHyWK/TWcJkwM6pStqFYyYDuSYvBm6Rp34+hDr6qMGfzMrnpG9I6b G3kXvijWP8bPzpvFSs89pLdFSuwRN0lalNK41UwmJDqzJy1xTDgFjym2lmiCvEyyokMB 4qjF2lIKQDamd3361QcJlrOxHTZgNmbktf8yJVRielWXXimGgIMNkUs6KnSOW3ebyPcb mZzg== X-Gm-Message-State: AG10YOTm23w0TYYbfBw0YFVKRek3es6F7dK4Dhl/MduDRU4eqjrLf9IN/UCPQaHpRDvioYnz X-Received: by 10.194.238.162 with SMTP id vl2mr38444352wjc.91.1455109478154; Wed, 10 Feb 2016 05:04:38 -0800 (PST) Received: from localhost.localdomain (host81-129-170-149.range81-129.btcentralplus.com. [81.129.170.149]) by smtp.gmail.com with ESMTPSA id q75sm22429319wmd.6.2016.02.10.05.04.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 05:04:37 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, thierry.reding@gmail.com, linux-pwm@vger.kernel.org, ajitpal.singh@st.com Subject: [PATCH 03/11] pwm: sti: Reorganise register names in preparation for new functionality Date: Wed, 10 Feb 2016 13:02:20 +0000 Message-Id: <1455109348-32767-4-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455109348-32767-1-git-send-email-lee.jones@linaro.org> References: <1455109348-32767-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160210_050500_088366_9D5B5217 X-CRM114-Status: GOOD ( 18.34 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:233 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lee Jones , kernel@stlinux.com, maxime.coquelin@st.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Exciting functionality is on the way to this device. But before we can add it, we need to do some basic housekeeping so the additions can be added cleanly. Signed-off-by: Lee Jones --- drivers/pwm/pwm-sti.c | 76 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 35 deletions(-) -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 92abbd5..4e06c4d 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -21,18 +21,22 @@ #include #include -#define STI_DS_REG(ch) (4 * (ch)) /* Channel's Duty Cycle register */ -#define STI_PWMCR 0x50 /* Control/Config register */ -#define STI_INTEN 0x54 /* Interrupt Enable/Disable register */ +#define PWM_OUT_VAL(x) (0x00 + (4 * (x))) /* Channel's Duty Cycle register */ + +#define STI_PWM_CTRL 0x50 /* Control/Config register */ +#define STI_INT_EN 0x54 /* Interrupt Enable/Disable register */ #define PWM_PRESCALE_LOW_MASK 0x0f #define PWM_PRESCALE_HIGH_MASK 0xf0 /* Regfield IDs */ enum { + /* Bits in PWM_CTRL*/ PWMCLK_PRESCALE_LOW, PWMCLK_PRESCALE_HIGH, - PWM_EN, - PWM_INT_EN, + + PWM_OUT_EN, + + PWM_CPT_INT_EN, /* Keep last */ MAX_REGFIELDS @@ -47,14 +51,14 @@ struct sti_pwm_compat_data { struct sti_pwm_chip { struct device *dev; - struct clk *clk; unsigned long clk_rate; + struct clk *pwm_clk; struct regmap *regmap; struct sti_pwm_compat_data *cdata; struct regmap_field *prescale_low; struct regmap_field *prescale_high; - struct regmap_field *pwm_en; - struct regmap_field *pwm_int_en; + struct regmap_field *pwm_out_en; + struct regmap_field *pwm_cpt_int_en; struct pwm_chip chip; struct pwm_device *cur; unsigned long configured; @@ -64,10 +68,10 @@ struct sti_pwm_chip { }; static const struct reg_field sti_pwm_regfields[MAX_REGFIELDS] = { - [PWMCLK_PRESCALE_LOW] = REG_FIELD(STI_PWMCR, 0, 3), - [PWMCLK_PRESCALE_HIGH] = REG_FIELD(STI_PWMCR, 11, 14), - [PWM_EN] = REG_FIELD(STI_PWMCR, 9, 9), - [PWM_INT_EN] = REG_FIELD(STI_INTEN, 0, 0), + [PWMCLK_PRESCALE_LOW] = REG_FIELD(STI_PWM_CTRL, 0, 3), + [PWMCLK_PRESCALE_HIGH] = REG_FIELD(STI_PWM_CTRL, 11, 14), + [PWM_OUT_EN] = REG_FIELD(STI_PWM_CTRL, 9, 9), + [PWM_CPT_INT_EN] = REG_FIELD(STI_INT_EN, 1, 4), }; static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip) @@ -144,7 +148,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ((ncfg == 1) && (pwm->hwpwm != cur->hwpwm) && period_same) || ((ncfg > 1) && period_same)) { /* Enable clock before writing to PWM registers. */ - ret = clk_enable(pc->clk); + ret = clk_enable(pc->pwm_clk); if (ret) return ret; @@ -174,11 +178,12 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, */ pwmvalx = cdata->max_pwm_cnt * duty_ns / period_ns; - ret = regmap_write(pc->regmap, STI_DS_REG(pwm->hwpwm), pwmvalx); + ret = regmap_write(pc->regmap, + PWM_OUT_VAL(pwm->hwpwm), pwmvalx); if (ret) goto clk_dis; - ret = regmap_field_write(pc->pwm_int_en, 0); + ret = regmap_field_write(pc->pwm_cpt_int_en, 0); set_bit(pwm->hwpwm, &pc->configured); pc->cur = pwm; @@ -190,7 +195,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, } clk_dis: - clk_disable(pc->clk); + clk_disable(pc->pwm_clk); return ret; } @@ -206,11 +211,11 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) */ mutex_lock(&pc->sti_pwm_lock); if (!pc->en_count) { - ret = clk_enable(pc->clk); + ret = clk_enable(pc->pwm_clk); if (ret) goto out; - ret = regmap_field_write(pc->pwm_en, 1); + ret = regmap_field_write(pc->pwm_out_en, 1); if (ret) { dev_err(dev, "failed to enable PWM device:%d\n", pwm->hwpwm); @@ -232,9 +237,9 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) mutex_unlock(&pc->sti_pwm_lock); return; } - regmap_field_write(pc->pwm_en, 0); + regmap_field_write(pc->pwm_out_en, 0); - clk_disable(pc->clk); + clk_disable(pc->pwm_clk); mutex_unlock(&pc->sti_pwm_lock); } @@ -277,15 +282,16 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc) if (IS_ERR(pc->prescale_high)) return PTR_ERR(pc->prescale_high); - pc->pwm_en = devm_regmap_field_alloc(dev, pc->regmap, - reg_fields[PWM_EN]); - if (IS_ERR(pc->pwm_en)) - return PTR_ERR(pc->pwm_en); - pc->pwm_int_en = devm_regmap_field_alloc(dev, pc->regmap, - reg_fields[PWM_INT_EN]); - if (IS_ERR(pc->pwm_int_en)) - return PTR_ERR(pc->pwm_int_en); + pc->pwm_out_en = devm_regmap_field_alloc(dev, pc->regmap, + reg_fields[PWM_OUT_EN]); + if (IS_ERR(pc->pwm_out_en)) + return PTR_ERR(pc->pwm_out_en); + + pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap, + reg_fields[PWM_CPT_INT_EN]); + if (IS_ERR(pc->pwm_cpt_int_en)) + return PTR_ERR(pc->pwm_cpt_int_en); return 0; } @@ -341,19 +347,19 @@ static int sti_pwm_probe(struct platform_device *pdev) if (ret) return ret; - pc->clk = of_clk_get_by_name(dev->of_node, "pwm"); - if (IS_ERR(pc->clk)) { + pc->pwm_clk = of_clk_get_by_name(dev->of_node, "pwm"); + if (IS_ERR(pc->pwm_clk)) { dev_err(dev, "failed to get PWM clock\n"); - return PTR_ERR(pc->clk); + return PTR_ERR(pc->pwm_clk); } - pc->clk_rate = clk_get_rate(pc->clk); + pc->clk_rate = clk_get_rate(pc->pwm_clk); if (!pc->clk_rate) { dev_err(dev, "failed to get clock rate\n"); return -EINVAL; } - ret = clk_prepare(pc->clk); + ret = clk_prepare(pc->pwm_clk); if (ret) { dev_err(dev, "failed to prepare clock\n"); return ret; @@ -367,7 +373,7 @@ static int sti_pwm_probe(struct platform_device *pdev) ret = pwmchip_add(&pc->chip); if (ret < 0) { - clk_unprepare(pc->clk); + clk_unprepare(pc->pwm_clk); return ret; } @@ -384,7 +390,7 @@ static int sti_pwm_remove(struct platform_device *pdev) for (i = 0; i < pc->cdata->num_chan; i++) pwm_disable(&pc->chip.pwms[i]); - clk_unprepare(pc->clk); + clk_unprepare(pc->pwm_clk); return pwmchip_remove(&pc->chip); }