Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1384928 > unrolled thread
| Started by | Lee Jones <lee.jones@linaro.org> |
|---|---|
| First post | 2016-04-22 12:20 +0200 |
| Last post | 2016-04-22 12:30 +0200 |
| Articles | 6 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH v2 00/11] pwm: Add support for PWM Capture Lee Jones <lee.jones@linaro.org> - 2016-04-22 12:20 +0200
[[PATCH v2] 07/11] pwm: sti: Supply PWM Capture clock handling Lee Jones <lee.jones@linaro.org> - 2016-04-22 12:20 +0200
[[PATCH v2] 10/11] pwm: sti: Add PWM Capture call-back Lee Jones <lee.jones@linaro.org> - 2016-04-22 12:20 +0200
[[PATCH v2] 01/11] pwm: Add PWM Capture support Lee Jones <lee.jones@linaro.org> - 2016-04-22 12:30 +0200
[[PATCH v2] 02/11] pwm: sti: Rename channel => device Lee Jones <lee.jones@linaro.org> - 2016-04-22 12:30 +0200
[[PATCH v2] 04/11] pwm: sti: Reorganise register names in preparation for new functionality Lee Jones <lee.jones@linaro.org> - 2016-04-22 12:30 +0200
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-04-22 12:20 +0200 |
| Subject | [PATCH v2 00/11] pwm: Add support for PWM Capture |
| Message-ID | <rqGlQ-lQ-5@gated-at.bofh.it> |
The first part of this set extends the current PWM API to allow external
code to request a PWM Capture. Subsequent patches then make use of the
new API by providing a userspace offering via /sysfs. The final part of
the set supplies PWM Capture functionality into the already existing STi
PWM driver.
This patch-set has been tested end to end via /sysfs.
v1 => v2:
API change
- Use a struct to carry the result back to the caller
- Use 'struct pwm' to store device specific data
- Make timeout configurable
- Don't use clear_bit(), instead use raw bit logic
- Propagate return value of platform_get_irq()
- Don't cast to (void *)
- Move to subsystem terminology (channels => devices)
- Remove channel select feature
- Enable Capture IP during capture
Lee Jones (11):
pwm: Add PWM Capture support
pwm: sti: Rename channel => device
pwm: sysfs: Add PWM Capture support
pwm: sti: Reorganise register names in preparation for new
functionality
pwm: sti: Only request clock rate when you need to
pwm: sti: Supply PWM Capture register addresses and bit locations
pwm: sti: Supply PWM Capture clock handling
pwm: sti: Initialise PWM Capture device data
pwm: sti: Add support for PWM Capture IRQs
pwm: sti: Add PWM Capture call-back
pwm: sti: Take the opportunity to conduct a little house keeping
drivers/pwm/core.c | 27 ++++
drivers/pwm/pwm-sti.c | 411 +++++++++++++++++++++++++++++++++++++++++---------
drivers/pwm/sysfs.c | 17 +++
include/linux/pwm.h | 28 ++++
4 files changed, 412 insertions(+), 71 deletions(-)
--
2.8.0
[toc] | [next] | [standalone]
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-04-22 12:20 +0200 |
| Subject | [[PATCH v2] 07/11] pwm: sti: Supply PWM Capture clock handling |
| Message-ID | <rqGlQ-lQ-23@gated-at.bofh.it> |
| In reply to | #1384928 |
ST's PWM IP is supplied by 2 different clocks. One for PWM
Output and the other for Capture. This patch provides clock
handling for the latter.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/pwm/pwm-sti.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 2f61e1e..78979d0 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -74,6 +74,7 @@ struct sti_pwm_compat_data {
struct sti_pwm_chip {
struct device *dev;
struct clk *pwm_clk;
+ struct clk *cpt_clk;
struct regmap *regmap;
struct sti_pwm_compat_data *cdata;
struct regmap_field *prescale_low;
@@ -183,6 +184,10 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
if (ret)
return ret;
+ ret = clk_enable(pc->cpt_clk);
+ if (ret)
+ return ret;
+
if (!period_same) {
ret = sti_pwm_get_prescale(pc, period_ns, &prescale);
if (ret)
@@ -227,6 +232,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
clk_dis:
clk_disable(pc->pwm_clk);
+ clk_disable(pc->cpt_clk);
return ret;
}
@@ -246,6 +252,10 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
if (ret)
goto out;
+ ret = clk_enable(pc->cpt_clk);
+ if (ret)
+ goto out;
+
ret = regmap_field_write(pc->pwm_out_en, 1);
if (ret) {
dev_err(dev, "failed to enable PWM device:%d\n",
@@ -271,6 +281,7 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
regmap_field_write(pc->pwm_out_en, 0);
clk_disable(pc->pwm_clk);
+ clk_disable(pc->cpt_clk);
mutex_unlock(&pc->sti_pwm_lock);
}
@@ -390,6 +401,18 @@ static int sti_pwm_probe(struct platform_device *pdev)
return ret;
}
+ pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
+ if (IS_ERR(pc->cpt_clk)) {
+ dev_err(dev, "failed to get PWM capture clock\n");
+ return PTR_ERR(pc->cpt_clk);
+ }
+
+ ret = clk_prepare(pc->cpt_clk);
+ if (ret) {
+ dev_err(dev, "failed to prepare clock\n");
+ return ret;
+ }
+
pc->chip.dev = dev;
pc->chip.ops = &sti_pwm_ops;
pc->chip.base = -1;
@@ -399,6 +422,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
ret = pwmchip_add(&pc->chip);
if (ret < 0) {
clk_unprepare(pc->pwm_clk);
+ clk_unprepare(pc->cpt_clk);
return ret;
}
@@ -416,6 +440,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
pwm_disable(&pc->chip.pwms[i]);
clk_unprepare(pc->pwm_clk);
+ clk_unprepare(pc->cpt_clk);
return pwmchip_remove(&pc->chip);
}
--
2.8.0
[toc] | [prev] | [next] | [standalone]
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-04-22 12:20 +0200 |
| Subject | [[PATCH v2] 10/11] pwm: sti: Add PWM Capture call-back |
| Message-ID | <rqGlQ-lQ-27@gated-at.bofh.it> |
| In reply to | #1384928 |
Once a PWM Capture has been initiated, the capture call
enables a rising edge detection IRQ, then waits. Once each
of the 3 phase changes have been recorded the thread then
wakes. The remaining part of the call carries out the
relevant calculations and passes back a formatted string to
the caller.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/pwm/pwm-sti.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 2230afb..cecb6d4 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -24,6 +24,8 @@
#include <linux/time.h>
#include <linux/wait.h>
+#define SECS_TO_NANOSECS(x) ((x) * 1000 * 1000 * 1000)
+
#define PWM_OUT_VAL(x) (0x00 + (4 * (x))) /* Device's Duty Cycle register */
#define PWM_CPT_VAL(x) (0x10 + (4 * (x))) /* Capture value */
#define PWM_CPT_EDGE(x) (0x30 + (4 * (x))) /* Edge to capture on */
@@ -305,7 +307,88 @@ static void sti_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
clear_bit(pwm->hwpwm, &pc->configured);
}
+static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
+ struct pwm_capture *result, unsigned int timeout_ms)
+{
+ struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
+ struct sti_pwm_compat_data *cdata = pc->cdata;
+ struct sti_cpt_ddata *ddata = pwm_get_chip_data(pwm);
+ struct device *dev = pc->dev;
+ unsigned int effective_ticks;
+ unsigned long long high, low;
+ int ret;
+
+ if (pwm->hwpwm > cdata->cpt_num_devs - 1) {
+ dev_err(dev, "Device %d is not valid\n", pwm->hwpwm);
+ return -EINVAL;
+ }
+
+ mutex_lock(&ddata->lock);
+
+ /* Prepare capture measurement */
+ ddata->index = 0;
+ regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_RISING);
+ regmap_field_write(pc->pwm_cpt_int_en, BIT(pwm->hwpwm));
+
+ /* Enable capture */
+ ret = regmap_field_write(pc->pwm_cpt_en, 1);
+ if (ret) {
+ dev_err(dev, "failed to enable PWM capture %d\n", pwm->hwpwm);
+ goto out;
+ }
+
+ ret = wait_event_interruptible_timeout(ddata->wait,
+ ddata->index > 1,
+ msecs_to_jiffies(timeout_ms));
+
+ regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_DISABLED);
+
+ if (ret == -ERESTARTSYS)
+ goto out;
+
+ switch (ddata->index) {
+ case 0:
+ case 1:
+ /*
+ * Getting here could mean :
+ * - input signal is constant of less than 1Hz
+ * - there is no input signal at all
+ *
+ * In such case the frequency is rounded down to 0
+ */
+
+ result->period = 0;
+ result->duty_cycle = 0;
+
+ break;
+ case 2:
+ /* We have everying we need */
+ high = ddata->snapshot[1] - ddata->snapshot[0];
+ low = ddata->snapshot[2] - ddata->snapshot[1];
+
+ effective_ticks = clk_get_rate(pc->cpt_clk);
+
+ result->period = SECS_TO_NANOSECS(high + low);
+ do_div(result->period, effective_ticks);
+
+ result->duty_cycle = SECS_TO_NANOSECS(high);
+ do_div(result->duty_cycle, effective_ticks);
+
+ break;
+ default:
+ dev_err(dev, "Internal error\n");
+ }
+
+out:
+ /* Disable capture */
+ regmap_field_write(pc->pwm_cpt_en, 0);
+
+ mutex_unlock(&ddata->lock);
+ return ret;
+}
+
static const struct pwm_ops sti_pwm_ops = {
+ .capture = sti_pwm_capture,
.config = sti_pwm_config,
.enable = sti_pwm_enable,
.disable = sti_pwm_disable,
@@ -418,6 +501,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
if (IS_ERR(pc->pwm_out_en))
return PTR_ERR(pc->pwm_out_en);
+ pc->pwm_cpt_en = devm_regmap_field_alloc(dev, pc->regmap,
+ reg_fields[PWM_CPT_EN]);
+ if (IS_ERR(pc->pwm_cpt_en))
+ return PTR_ERR(pc->pwm_cpt_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))
--
2.8.0
[toc] | [prev] | [next] | [standalone]
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-04-22 12:30 +0200 |
| Subject | [[PATCH v2] 01/11] pwm: Add PWM Capture support |
| Message-ID | <rqGvv-qK-1@gated-at.bofh.it> |
| In reply to | #1384928 |
Supply a PWM Capture call-back Op in order to pass back
information obtained by running analysis on PWM a signal.
This would normally (at least during testing) be called from
the Sysfs routines with a view to printing out PWM Capture
data which has been encoded into a string.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/pwm/core.c | 27 +++++++++++++++++++++++++++
include/linux/pwm.h | 28 ++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 7831bc6..160784d 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -494,6 +494,33 @@ unlock:
EXPORT_SYMBOL_GPL(pwm_set_polarity);
/**
+ * pwm_capture() - capture and report a PWM signal
+ * @pwm: PWM device
+ * @result: struct to fill with capture result
+ * @timeout_ms: time to wait, in milliseconds, before giving up on capture
+ *
+ * Returns: 0 on success or a negative error code on failure.
+ */
+int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
+ unsigned int timeout_ms)
+{
+ int err;
+
+ if (!pwm || !pwm->chip->ops)
+ return -EINVAL;
+
+ if (!pwm->chip->ops->capture)
+ return -ENOSYS;
+
+ mutex_lock(&pwm->lock);
+ err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout_ms);
+ mutex_unlock(&pwm->lock);
+
+ return err;
+}
+EXPORT_SYMBOL_GPL(pwm_capture);
+
+/**
* pwm_enable() - start a PWM output toggling
* @pwm: PWM device
*
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index cfc3ed4..49f9648 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -6,6 +6,7 @@
#include <linux/of.h>
struct pwm_device;
+struct pwm_capture;
struct seq_file;
#if IS_ENABLED(CONFIG_PWM)
@@ -33,6 +34,13 @@ int pwm_enable(struct pwm_device *pwm);
* pwm_disable - stop a PWM output toggling
*/
void pwm_disable(struct pwm_device *pwm);
+
+/*
+ * pwm_capture - capture and report a PWM signal
+ */
+int pwm_capture(struct pwm_device *pwm,
+ struct pwm_capture *result,
+ unsigned int timeout_ms);
#else
static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
{
@@ -56,6 +64,13 @@ static inline int pwm_enable(struct pwm_device *pwm)
static inline void pwm_disable(struct pwm_device *pwm)
{
}
+
+static inline int pwm_capture(struct pwm_device *pwm,
+ struct pwm_capture *result,
+ unsigned int timeout_ms)
+{
+ return -EINVAL;
+}
#endif
struct pwm_chip;
@@ -107,6 +122,16 @@ struct pwm_device {
enum pwm_polarity polarity;
};
+/**
+ * struct pwm_capture - PWM capture data
+ * @period: period of the PWM signal (in nanoseconds)
+ * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
+ */
+struct pwm_capture {
+ unsigned long long period;
+ unsigned long long duty_cycle;
+};
+
static inline bool pwm_is_enabled(const struct pwm_device *pwm)
{
return test_bit(PWMF_ENABLED, &pwm->flags);
@@ -150,6 +175,7 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
* @free: optional hook for freeing a PWM
* @config: configure duty cycles and period length for this PWM
* @set_polarity: configure the polarity of this PWM
+ * @capture: capture and report PWM signal
* @enable: enable PWM output toggling
* @disable: disable PWM output toggling
* @dbg_show: optional routine to show contents in debugfs
@@ -162,6 +188,8 @@ struct pwm_ops {
int duty_ns, int period_ns);
int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
enum pwm_polarity polarity);
+ int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
+ struct pwm_capture *result, unsigned int timeout_ms);
int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
#ifdef CONFIG_DEBUG_FS
--
2.8.0
[toc] | [prev] | [next] | [standalone]
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-04-22 12:30 +0200 |
| Subject | [[PATCH v2] 02/11] pwm: sti: Rename channel => device |
| Message-ID | <rqGvw-qK-25@gated-at.bofh.it> |
| In reply to | #1384928 |
This is to bring the terminology used in the STi PWM driver more
into line with the PWM subsystem.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/pwm/pwm-sti.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index 92abbd5..3dae127 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -21,7 +21,7 @@
#include <linux/slab.h>
#include <linux/time.h>
-#define STI_DS_REG(ch) (4 * (ch)) /* Channel's Duty Cycle register */
+#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_PRESCALE_LOW_MASK 0x0f
@@ -40,7 +40,7 @@ enum {
struct sti_pwm_compat_data {
const struct reg_field *reg_fields;
- unsigned int num_chan;
+ unsigned int num_devs;
unsigned int max_pwm_cnt;
unsigned int max_prescale;
};
@@ -130,13 +130,13 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
/* Allow configuration changes if one of the
* following conditions satisfy.
- * 1. No channels have been configured.
- * 2. Only one channel has been configured and the new request
- * is for the same channel.
- * 3. Only one channel has been configured and the new request is
- * for a new channel and period of the new channel is same as
+ * 1. No devices have been configured.
+ * 2. Only one device has been configured and the new request
+ * is for the same device.
+ * 3. Only one device has been configured and the new request is
+ * for a new device and period of the new device is same as
* the current configured period.
- * 4. More than one channels are configured and period of the new
+ * 4. More than one devices are configured and period of the new
* requestis the same as the current period.
*/
if (!ncfg ||
@@ -201,7 +201,7 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
int ret = 0;
/*
- * Since we have a common enable for all PWM channels,
+ * Since we have a common enable for all PWM devices,
* do not enable if already enabled.
*/
mutex_lock(&pc->sti_pwm_lock);
@@ -259,11 +259,11 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
const struct reg_field *reg_fields;
struct device_node *np = dev->of_node;
struct sti_pwm_compat_data *cdata = pc->cdata;
- u32 num_chan;
+ u32 num_devs;
- of_property_read_u32(np, "st,pwm-num-chan", &num_chan);
- if (num_chan)
- cdata->num_chan = num_chan;
+ of_property_read_u32(np, "st,pwm-num-devs", &num_devs);
+ if (num_devs)
+ cdata->num_devs = num_devs;
reg_fields = cdata->reg_fields;
@@ -330,7 +330,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
cdata->reg_fields = &sti_pwm_regfields[0];
cdata->max_prescale = 0xff;
cdata->max_pwm_cnt = 255;
- cdata->num_chan = 1;
+ cdata->num_devs = 1;
pc->cdata = cdata;
pc->dev = dev;
@@ -362,7 +362,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
pc->chip.dev = dev;
pc->chip.ops = &sti_pwm_ops;
pc->chip.base = -1;
- pc->chip.npwm = pc->cdata->num_chan;
+ pc->chip.npwm = pc->cdata->num_devs;
pc->chip.can_sleep = true;
ret = pwmchip_add(&pc->chip);
@@ -381,7 +381,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
struct sti_pwm_chip *pc = platform_get_drvdata(pdev);
unsigned int i;
- for (i = 0; i < pc->cdata->num_chan; i++)
+ for (i = 0; i < pc->cdata->num_devs; i++)
pwm_disable(&pc->chip.pwms[i]);
clk_unprepare(pc->clk);
--
2.8.0
[toc] | [prev] | [next] | [standalone]
| From | Lee Jones <lee.jones@linaro.org> |
|---|---|
| Date | 2016-04-22 12:30 +0200 |
| Subject | [[PATCH v2] 04/11] pwm: sti: Reorganise register names in preparation for new functionality |
| Message-ID | <rqGvw-qK-31@gated-at.bofh.it> |
| In reply to | #1384928 |
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.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web