From: Lee Jones <lee.jones@linaro.org>
To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: linux-pwm@vger.kernel.org, kernel@stlinux.com,
devicetree@vger.kernel.org, patrice.chotard@st.com,
robh+dt@kernel.org, thierry.reding@gmail.com,
Lee Jones <lee.jones@linaro.org>,
maxime.coquelin@st.com
Subject: [PATCH v3 11/20] pwm: sti: Reorganise register names in preparation for new functionality
Date: Wed, 8 Jun 2016 10:21:26 +0100 [thread overview]
Message-ID: <20160608092135.21184-12-lee.jones@linaro.org> (raw)
In-Reply-To: <20160608092135.21184-1-lee.jones@linaro.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 <lee.jones@linaro.org>
---
drivers/pwm/pwm-sti.c | 76 +++++++++++++++++++++++++++------------------------
1 file changed, 41 insertions(+), 35 deletions(-)
diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 3dae127..5fbee61 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -21,18 +21,22 @@
#include <linux/slab.h>
#include <linux/time.h>
-#define STI_DS_REG(ch) (4 * (ch)) /* Device'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))) /* Device'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_devs; i++)
pwm_disable(&pc->chip.pwms[i]);
- clk_unprepare(pc->clk);
+ clk_unprepare(pc->pwm_clk);
return pwmchip_remove(&pc->chip);
}
--
2.8.3
next prev parent reply other threads:[~2016-06-08 9:21 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-08 9:21 [PATCH v3 00/20] pwm: Add support for PWM Capture Lee Jones
2016-06-08 9:21 ` [PATCH v3 01/20] ARM: dts: STi: Rename properites in line with PWM naming conventions Lee Jones
2016-06-08 9:21 ` [PATCH v3 02/20] ARM: dts: STiH407: Supply PWM Capture IRQ Lee Jones
2016-06-08 9:21 ` [PATCH v3 03/20] ARM: dts: STiH407: Declare PWM Capture data lines via Pinctrl Lee Jones
2016-06-08 9:21 ` [PATCH v3 04/20] ARM: dts: STiH416: Supply PWM Capture IRQs Lee Jones
2016-06-08 9:21 ` [PATCH v3 05/20] ARM: dts: STiH416: Declare PWM Capture data lines via Pinctrl Lee Jones
2016-06-08 9:21 ` [PATCH v3 06/20] ARM: dts: STiH416: Define PWM Capture clock Lee Jones
2016-06-08 9:21 ` [PATCH v3 07/20] ARM: dts: STiH416: Define the number of PWM Capture channels Lee Jones
2016-06-08 9:21 ` [PATCH v3 08/20] pwm: Add PWM Capture support Lee Jones
2016-06-10 13:53 ` Thierry Reding
2016-06-10 14:38 ` Lee Jones
2016-06-10 16:39 ` Thierry Reding
2016-06-20 11:14 ` Lee Jones
2016-06-08 9:21 ` [PATCH v3 09/20] pwm: sti: Rename channel => device Lee Jones
2016-06-08 9:21 ` [PATCH v3 10/20] pwm: sysfs: Add PWM Capture support Lee Jones
2016-06-10 14:04 ` Thierry Reding
2016-06-10 14:36 ` Lee Jones
2016-06-08 9:21 ` Lee Jones [this message]
2016-06-08 9:21 ` [PATCH v3 12/20] pwm: sti: Only request clock rate when you need to Lee Jones
2016-06-08 9:21 ` [PATCH v3 13/20] pwm: sti: Supply PWM Capture register addresses and bit locations Lee Jones
2016-06-08 9:21 ` [PATCH v3 14/20] pwm: sti: Supply PWM Capture clock handling Lee Jones
2016-06-08 9:21 ` [PATCH v3 15/20] pwm: sti: Initialise PWM Capture device data Lee Jones
2016-06-08 9:21 ` [PATCH v3 16/20] pwm: sti: Add support for PWM Capture IRQs Lee Jones
2016-06-08 9:21 ` [PATCH v3 17/20] pwm: sti: Add PWM Capture call-back Lee Jones
[not found] ` <20160608092135.21184-1-lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-06-08 9:21 ` [PATCH v3 18/20] pwm: sti: It's now valid for number of PWM channels to be zero Lee Jones
2016-06-08 9:21 ` [PATCH v3 19/20] pwm: sti: Take the opportunity to conduct a little house keeping Lee Jones
2016-06-08 9:21 ` [PATCH v3 20/20] dt-bindings: pwm: sti: Update DT bindings with recent changes Lee Jones
2016-06-08 20:51 ` Rob Herring
2016-06-09 11:41 ` Lee Jones
2016-06-10 13:18 ` Thierry Reding
[not found] ` <20160610131855.GG27142-EkSeR96xj6Pcmrwk2tT4+A@public.gmane.org>
2016-06-10 14:06 ` Lee Jones
2016-06-10 14:53 ` Thierry Reding
[not found] ` <20160610145323.GO27142-EkSeR96xj6Pcmrwk2tT4+A@public.gmane.org>
2016-06-10 15:19 ` Lee Jones
2016-07-13 9:02 ` Lee Jones
2016-06-10 13:10 ` Thierry Reding
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160608092135.21184-12-lee.jones@linaro.org \
--to=lee.jones@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@stlinux.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=maxime.coquelin@st.com \
--cc=patrice.chotard@st.com \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).