* [PATCH v4 08/24] leds: pwm: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>
---
drivers/leds/leds-pwm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index 1d07e3e..2c564d1 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -125,7 +125,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
if (led_data->can_sleep)
INIT_WORK(&led_data->work, led_pwm_work);
- led_data->period = pwm_get_period(led_data->pwm);
+ led_data->period = pwm_get_default_period(led_data->pwm);
if (!led_data->period && (led->pwm_period_ns > 0))
led_data->period = led->pwm_period_ns;
--
2.1.4
^ permalink raw reply related
* [PATCH v4 09/24] regulator: pwm: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/regulator/pwm-regulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index 3aca067b..9ffdbd6 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -56,7 +56,7 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
int dutycycle;
int ret;
- pwm_reg_period = pwm_get_period(drvdata->pwm);
+ pwm_reg_period = pwm_get_default_period(drvdata->pwm);
dutycycle = (pwm_reg_period *
drvdata->duty_cycle_table[selector].dutycycle) / 100;
@@ -131,7 +131,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
{
struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
unsigned int ramp_delay = rdev->constraints->ramp_delay;
- unsigned int period = pwm_get_period(drvdata->pwm);
+ unsigned int period = pwm_get_default_period(drvdata->pwm);
int duty_cycle;
int ret;
--
2.1.4
^ permalink raw reply related
* [PATCH v4 10/24] backlight: pwm: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
drivers/video/backlight/lm3630a_bl.c | 4 ++--
drivers/video/backlight/pwm_bl.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c
index 35fe482..449ebc3 100644
--- a/drivers/video/backlight/lm3630a_bl.c
+++ b/drivers/video/backlight/lm3630a_bl.c
@@ -162,7 +162,7 @@ static int lm3630a_intr_config(struct lm3630a_chip *pchip)
static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max)
{
- unsigned int period = pwm_get_period(pchip->pwmd);
+ unsigned int period = pwm_get_default_period(pchip->pwmd);
unsigned int duty = br * period / br_max;
pwm_config(pchip->pwmd, duty, period);
@@ -425,7 +425,7 @@ static int lm3630a_probe(struct i2c_client *client,
return PTR_ERR(pchip->pwmd);
}
}
- pchip->pwmd->period = pdata->pwm_period;
+ pwm_set_default_period(pchip->pwmd, pdata->pwm_period);
/* interrupt enable : irq 0 is not allowed */
pchip->irq = client->irq;
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index ae3c6b6..54d5a03 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -293,7 +293,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
* set the period from platform data if it has not already been set
* via the PWM lookup table.
*/
- pb->period = pwm_get_period(pb->pwm);
+ pb->period = pwm_get_default_period(pb->pwm);
if (!pb->period && (data->pwm_period_ns > 0)) {
pb->period = data->pwm_period_ns;
pwm_set_period(pb->pwm, data->pwm_period_ns);
--
2.1.4
^ permalink raw reply related
* [PATCH v4 11/24] fbdev: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/video/fbdev/ssd1307fb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index fa34808..81f4885 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -294,7 +294,7 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
return PTR_ERR(par->pwm);
}
- par->pwm_period = pwm_get_period(par->pwm);
+ par->pwm_period = pwm_get_default_period(par->pwm);
/* Enable the PWM */
pwm_config(par->pwm, par->pwm_period / 2, par->pwm_period);
pwm_enable(par->pwm);
--
2.1.4
^ permalink raw reply related
* [PATCH v4 12/24] misc: max77693: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/input/misc/max77693-haptic.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
index a038fb3..89f5055 100644
--- a/drivers/input/misc/max77693-haptic.c
+++ b/drivers/input/misc/max77693-haptic.c
@@ -70,11 +70,12 @@ struct max77693_haptic {
static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
{
- int delta = (pwm_get_period((haptic->pwm_dev)) + haptic->pwm_duty) / 2;
+ int delta = (pwm_get_default_period((haptic->pwm_dev)) +
+ haptic->pwm_duty) / 2;
int error;
error = pwm_config(haptic->pwm_dev, delta,
- pwm_get_period((haptic->pwm_dev)));
+ pwm_get_default_period((haptic->pwm_dev)));
if (error) {
dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
return error;
@@ -246,7 +247,8 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
* The formula to convert magnitude to pwm_duty as follows:
* - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF)
*/
- period_mag_multi = (u64)pwm_get_period((haptic->pwm_dev)) * haptic->magnitude;
+ period_mag_multi = (u64)pwm_get_default_period((haptic->pwm_dev)) *
+ haptic->magnitude;
haptic->pwm_duty = (unsigned int)(period_mag_multi >>
MAX_MAGNITUDE_SHIFT);
--
2.1.4
^ permalink raw reply related
* [PATCH v4 13/24] hwmon: pwm-fan: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/hwmon/pwm-fan.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 105b964..989d7b4 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -47,8 +47,9 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
if (ctx->pwm_value = pwm)
goto exit_set_pwm_err;
- duty = DIV_ROUND_UP(pwm * (pwm_get_period((ctx->pwm)) - 1), MAX_PWM);
- ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm)));
+ duty = DIV_ROUND_UP(pwm * (pwm_get_default_period((ctx->pwm)) - 1),
+ MAX_PWM);
+ ret = pwm_config(ctx->pwm, duty, pwm_get_default_period((ctx->pwm)));
if (ret)
goto exit_set_pwm_err;
@@ -234,10 +235,11 @@ static int pwm_fan_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ctx);
/* Set duty cycle to maximum allowed */
- duty_cycle = pwm_get_period((ctx->pwm)) - 1;
+ duty_cycle = pwm_get_default_period((ctx->pwm)) - 1;
ctx->pwm_value = MAX_PWM;
- ret = pwm_config(ctx->pwm, duty_cycle, pwm_get_period((ctx->pwm)));
+ ret = pwm_config(ctx->pwm, duty_cycle,
+ pwm_get_default_period((ctx->pwm)));
if (ret) {
dev_err(&pdev->dev, "Failed to configure PWM\n");
return ret;
@@ -309,9 +311,10 @@ static int pwm_fan_resume(struct device *dev)
if (ctx->pwm_value = 0)
return 0;
- duty = DIV_ROUND_UP(ctx->pwm_value * (pwm_get_period((ctx->pwm)) - 1),
+ duty = DIV_ROUND_UP(ctx->pwm_value *
+ (pwm_get_default_period((ctx->pwm)) - 1),
MAX_PWM);
- ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm)));
+ ret = pwm_config(ctx->pwm, duty, pwm_get_default_period((ctx->pwm)));
if (ret)
return ret;
return pwm_enable(ctx->pwm);
--
2.1.4
^ permalink raw reply related
* [PATCH v4 14/24] clk: pwm: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
pwm_set/get_default_xxx() helpers have been introduced to differentiate
the default PWM states (those retrieved through DT, PWM lookup table or
statically assigned by the driver) and the current ones.
Make use of those helpers where appropriate.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/clk/clk-pwm.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/clk/clk-pwm.c b/drivers/clk/clk-pwm.c
index b6306a2..642a49a 100644
--- a/drivers/clk/clk-pwm.c
+++ b/drivers/clk/clk-pwm.c
@@ -71,23 +71,23 @@ static int clk_pwm_probe(struct platform_device *pdev)
if (IS_ERR(pwm))
return PTR_ERR(pwm);
- if (!pwm_get_period((pwm))) {
+ if (!pwm_get_default_period((pwm))) {
dev_err(&pdev->dev, "invalid PWM period\n");
return -EINVAL;
}
if (of_property_read_u32(node, "clock-frequency", &clk_pwm->fixed_rate))
- clk_pwm->fixed_rate = NSEC_PER_SEC / pwm_get_period((pwm));
+ clk_pwm->fixed_rate = NSEC_PER_SEC / pwm_get_default_period((pwm));
- if (pwm_get_period((pwm)) != NSEC_PER_SEC / clk_pwm->fixed_rate &&
- pwm_get_period((pwm)) != DIV_ROUND_UP(NSEC_PER_SEC, clk_pwm->fixed_rate)) {
+ if (pwm_get_default_period((pwm)) != NSEC_PER_SEC / clk_pwm->fixed_rate &&
+ pwm_get_default_period((pwm)) != DIV_ROUND_UP(NSEC_PER_SEC, clk_pwm->fixed_rate)) {
dev_err(&pdev->dev,
"clock-frequency does not match PWM period\n");
return -EINVAL;
}
- ret = pwm_config(pwm, (pwm_get_period((pwm)) + 1) >> 1,
- pwm_get_period((pwm)));
+ ret = pwm_config(pwm, (pwm_get_default_period((pwm)) + 1) >> 1,
+ pwm_get_default_period((pwm)));
if (ret < 0)
return ret;
--
2.1.4
^ permalink raw reply related
* [PATCH v4 15/24] pwm: define a new pwm_state struct
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
The PWM state, represented by its period, duty_cycle and polarity,
is currently directly stored in the PWM device.
Declare a pwm_state structure embedding those field so that we can later
use this struct to atomically update all the PWM parameters at once.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/pwm/core.c | 6 +++---
include/linux/pwm.h | 30 +++++++++++++++++++-----------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 59073a1..f1c6769 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -447,8 +447,8 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
if (err)
return err;
- pwm->duty_cycle = duty_ns;
- pwm->period = period_ns;
+ pwm->state.duty_cycle = duty_ns;
+ pwm->state.period = period_ns;
return 0;
}
@@ -485,7 +485,7 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
if (err)
goto unlock;
- pwm->polarity = polarity;
+ pwm->state.polarity = polarity;
unlock:
mutex_unlock(&pwm->lock);
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 8ba57fc..af42299 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -80,6 +80,18 @@ enum {
PWMF_EXPORTED = 1 << 2,
};
+/*
+ * struct pwm_state - state of a PWM channel
+ * @period: PWM period (in nanoseconds)
+ * @duty_cycle: PWM duty cycle (in nanoseconds)
+ * @polarity: PWM polarity
+ */
+struct pwm_state {
+ unsigned int period;
+ unsigned int duty_cycle;
+ enum pwm_polarity polarity;
+};
+
/**
* struct pwm_device - PWM channel object
* @label: name of the PWM device
@@ -89,9 +101,7 @@ enum {
* @chip: PWM chip providing this PWM device
* @chip_data: chip-private data associated with the PWM device
* @lock: used to serialize accesses to the PWM device where necessary
- * @period: period of the PWM signal (in nanoseconds)
- * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
- * @polarity: polarity of the PWM signal
+ * @state: curent PWM channel state
*/
struct pwm_device {
const char *label;
@@ -102,9 +112,7 @@ struct pwm_device {
void *chip_data;
struct mutex lock;
- unsigned int period;
- unsigned int duty_cycle;
- enum pwm_polarity polarity;
+ struct pwm_state state;
};
static inline bool pwm_is_enabled(const struct pwm_device *pwm)
@@ -115,7 +123,7 @@ static inline bool pwm_is_enabled(const struct pwm_device *pwm)
static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
{
if (pwm)
- pwm->period = period;
+ pwm->state.period = period;
}
static inline void pwm_set_default_period(struct pwm_device *pwm,
@@ -126,7 +134,7 @@ static inline void pwm_set_default_period(struct pwm_device *pwm,
static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
{
- return pwm ? pwm->period : 0;
+ return pwm ? pwm->state.period : 0;
}
static inline unsigned int pwm_get_default_period(const struct pwm_device *pwm)
@@ -137,12 +145,12 @@ static inline unsigned int pwm_get_default_period(const struct pwm_device *pwm)
static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
{
if (pwm)
- pwm->duty_cycle = duty;
+ pwm->state.duty_cycle = duty;
}
static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
{
- return pwm ? pwm->duty_cycle : 0;
+ return pwm ? pwm->state.duty_cycle : 0;
}
/*
@@ -158,7 +166,7 @@ static inline void pwm_set_default_polarity(struct pwm_device *pwm,
static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
{
- return pwm ? pwm->polarity : PWM_POLARITY_NORMAL;
+ return pwm ? pwm->state.polarity : PWM_POLARITY_NORMAL;
}
/**
--
2.1.4
^ permalink raw reply related
* [PATCH v4 16/24] pwm: move the enabled/disabled info to pwm_state struct
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Prepare the transition to PWM atomic update by moving the enabled/disabled
state into the pwm_state struct. This way we can easily update the whole
PWM state by copying the new state in the ->state field.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/pwm/core.c | 17 +++++++++++++----
include/linux/pwm.h | 7 ++++---
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index f1c6769..6bbda6c 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -508,10 +508,10 @@ int pwm_enable(struct pwm_device *pwm)
mutex_lock(&pwm->lock);
- if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) {
+ if (!pwm_is_enabled(pwm)) {
err = pwm->chip->ops->enable(pwm->chip, pwm);
- if (err)
- clear_bit(PWMF_ENABLED, &pwm->flags);
+ if (!err)
+ pwm->state.enabled = true;
}
mutex_unlock(&pwm->lock);
@@ -526,8 +526,17 @@ EXPORT_SYMBOL_GPL(pwm_enable);
*/
void pwm_disable(struct pwm_device *pwm)
{
- if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
+ if (!pwm)
+ return;
+
+ mutex_lock(&pwm->lock);
+
+ if (pwm_is_enabled(pwm)) {
pwm->chip->ops->disable(pwm->chip, pwm);
+ pwm->state.enabled = false;
+ }
+
+ mutex_unlock(&pwm->lock);
}
EXPORT_SYMBOL_GPL(pwm_disable);
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index af42299..398c58c 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -76,8 +76,7 @@ enum pwm_polarity {
enum {
PWMF_REQUESTED = 1 << 0,
- PWMF_ENABLED = 1 << 1,
- PWMF_EXPORTED = 1 << 2,
+ PWMF_EXPORTED = 1 << 1,
};
/*
@@ -85,11 +84,13 @@ enum {
* @period: PWM period (in nanoseconds)
* @duty_cycle: PWM duty cycle (in nanoseconds)
* @polarity: PWM polarity
+ * @enabled: PWM enabled status
*/
struct pwm_state {
unsigned int period;
unsigned int duty_cycle;
enum pwm_polarity polarity;
+ bool enabled;
};
/**
@@ -117,7 +118,7 @@ struct pwm_device {
static inline bool pwm_is_enabled(const struct pwm_device *pwm)
{
- return test_bit(PWMF_ENABLED, &pwm->flags);
+ return pwm->state.enabled;
}
static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
--
2.1.4
^ permalink raw reply related
* [PATCH v4 17/24] backlight: pwm_bl: remove useless call to pwm_set_period
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
The PWM period will be set when calling pwm_config. Remove this useless
call to pwm_set_period, which might mess up with the initial PWM state
once we have added proper support for PWM init state retrieval.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
drivers/video/backlight/pwm_bl.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 54d5a03..5ff2976 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -292,12 +292,14 @@ static int pwm_backlight_probe(struct platform_device *pdev)
* period, parsed from the DT, in the PWM device. For the non-DT case,
* set the period from platform data if it has not already been set
* via the PWM lookup table.
+ * FIXME: This assignment should be dropped as soon as all the boards
+ * have moved to the PWM lookup table approach. The same goes for the
+ * pb->period field which should be replaced by
+ * pwm_get_default_period() calls.
*/
pb->period = pwm_get_default_period(pb->pwm);
- if (!pb->period && (data->pwm_period_ns > 0)) {
+ if (!pb->period && (data->pwm_period_ns > 0))
pb->period = data->pwm_period_ns;
- pwm_set_period(pb->pwm, data->pwm_period_ns);
- }
pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale);
--
2.1.4
^ permalink raw reply related
* [PATCH v4 18/24] pwm: declare a default PWM state
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Prepare the addition of the PWM initial state retrieval by adding a default
state where all the parameters retrieved from DT, platform data or
statically forced by the hardware will be stored.
Once done we will be able to store the initial state in the ->state field
without risking to loose the default parameters.
Update the pwm_set/get_default_xxx helpers accordingly.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
include/linux/pwm.h | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 398c58c..292e7da 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -103,6 +103,7 @@ struct pwm_state {
* @chip_data: chip-private data associated with the PWM device
* @lock: used to serialize accesses to the PWM device where necessary
* @state: curent PWM channel state
+ * @default_state: default PWM channel state
*/
struct pwm_device {
const char *label;
@@ -114,6 +115,7 @@ struct pwm_device {
struct mutex lock;
struct pwm_state state;
+ struct pwm_state default_state;
};
static inline bool pwm_is_enabled(const struct pwm_device *pwm)
@@ -130,7 +132,8 @@ static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
static inline void pwm_set_default_period(struct pwm_device *pwm,
unsigned int period)
{
- pwm_set_period(pwm, period);
+ if (pwm)
+ pwm->default_state.period = period;
}
static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
@@ -140,7 +143,7 @@ static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
static inline unsigned int pwm_get_default_period(const struct pwm_device *pwm)
{
- return pwm_get_period(pwm);
+ return pwm ? pwm->default_state.period : 0;
}
static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
@@ -162,7 +165,8 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
static inline void pwm_set_default_polarity(struct pwm_device *pwm,
enum pwm_polarity polarity)
{
- pwm_set_polarity(pwm, polarity);
+ if (pwm)
+ pwm->default_state.polarity = polarity;
}
static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
--
2.1.4
^ permalink raw reply related
* [PATCH v4 19/24] pwm: add the PWM initial state retrieval infra
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Add a ->reset_state() function to the pwm_ops struct to let PWM drivers
initialize the PWM state attached to a PWM device.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/pwm/core.c | 3 +++
include/linux/pwm.h | 4 ++++
2 files changed, 7 insertions(+)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 6bbda6c..ce8b373 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -271,6 +271,9 @@ int pwmchip_add_with_polarity(struct pwm_chip *chip,
pwm_set_default_polarity(pwm, polarity);
mutex_init(&pwm->lock);
+ if (chip->ops->reset_state)
+ chip->ops->reset_state(chip, pwm);
+
radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
}
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 292e7da..caa0ffe 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -182,6 +182,9 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
* @set_polarity: configure the polarity of this PWM
* @enable: enable PWM output toggling
* @disable: disable PWM output toggling
+ * @reset_state: reset the current PWM state (pwm->state) to the actual
+ * hardware state. This function is only called once per
+ * PWM device when the PWM chip is registered.
* @dbg_show: optional routine to show contents in debugfs
* @owner: helps prevent removal of modules exporting active PWMs
*/
@@ -194,6 +197,7 @@ struct pwm_ops {
enum pwm_polarity polarity);
int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
+ void (*reset_state)(struct pwm_chip *chip, struct pwm_device *pwm);
#ifdef CONFIG_DEBUG_FS
void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
#endif
--
2.1.4
^ permalink raw reply related
* [PATCH v4 20/24] pwm: add the core infrastructure to allow atomic update
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Add an ->apply() method to the pwm_ops struct to allow PWM drivers to
implement atomic update.
This method will be preferred over the ->enable(), ->disable() and
->config() methods if available.
Add the pwm_get_state(), pwm_get_default_state() and pwm_apply_state()
functions for PWM users to be able to use the atomic update feature.
Note that the pwm_apply_state() does not guarantee the atomicity of the
update operation, it all depends on the availability and implementation
of the ->apply() method.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/pwm/core.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++---
include/linux/pwm.h | 27 ++++++++++++
2 files changed, 146 insertions(+), 5 deletions(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index ce8b373..fbc71d3 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -46,6 +46,12 @@ static struct pwm_device *pwm_to_device(unsigned int pwm)
return radix_tree_lookup(&pwm_tree, pwm);
}
+static void pwm_set_state(struct pwm_device *pwm,
+ const struct pwm_state *state)
+{
+ pwm->state = *state;
+}
+
static int alloc_pwms(int pwm, unsigned int count)
{
unsigned int from = 0;
@@ -226,6 +232,19 @@ void *pwm_get_chip_data(struct pwm_device *pwm)
}
EXPORT_SYMBOL_GPL(pwm_get_chip_data);
+static bool pwm_ops_check(const struct pwm_ops *ops)
+{
+ /* driver supports legacy, non-atomic operation */
+ if (ops->config && ops->enable && ops->disable)
+ return true;
+
+ /* driver supports atomic operation */
+ if (ops->apply)
+ return true;
+
+ return false;
+}
+
/**
* pwmchip_add_with_polarity() - register a new PWM chip
* @chip: the PWM chip to add
@@ -244,8 +263,10 @@ int pwmchip_add_with_polarity(struct pwm_chip *chip,
unsigned int i;
int ret;
- if (!chip || !chip->dev || !chip->ops || !chip->ops->config ||
- !chip->ops->enable || !chip->ops->disable || !chip->npwm)
+ if (!chip || !chip->dev || !chip->ops || !chip->npwm)
+ return -EINVAL;
+
+ if (!pwm_ops_check(chip->ops))
return -EINVAL;
mutex_lock(&pwm_lock);
@@ -446,7 +467,19 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns)
return -EINVAL;
- err = pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
+ if (pwm->chip->ops->apply) {
+ struct pwm_state state;
+
+ pwm_get_state(pwm, &state);
+ state.period = period_ns;
+ state.duty_cycle = duty_ns;
+
+ err = pwm->chip->ops->apply(pwm->chip, pwm, &state);
+ } else {
+ err = pwm->chip->ops->config(pwm->chip, pwm, duty_ns,
+ period_ns);
+ }
+
if (err)
return err;
@@ -474,6 +507,18 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
if (!pwm || !pwm->chip->ops)
return -EINVAL;
+ if (pwm->chip->ops->apply) {
+ struct pwm_state state;
+
+ pwm_get_state(pwm, &state);
+ state.polarity = polarity;
+ err = pwm->chip->ops->apply(pwm->chip, pwm, &state);
+ if (!err)
+ pwm->state.polarity = polarity;
+
+ return err;
+ }
+
if (!pwm->chip->ops->set_polarity)
return -ENOSYS;
@@ -512,7 +557,17 @@ int pwm_enable(struct pwm_device *pwm)
mutex_lock(&pwm->lock);
if (!pwm_is_enabled(pwm)) {
- err = pwm->chip->ops->enable(pwm->chip, pwm);
+ if (pwm->chip->ops->apply) {
+ struct pwm_state state;
+
+ pwm_get_state(pwm, &state);
+ state.enabled = true;
+
+ err = pwm->chip->ops->apply(pwm->chip, pwm, &state);
+ } else {
+ err = pwm->chip->ops->enable(pwm->chip, pwm);
+ }
+
if (!err)
pwm->state.enabled = true;
}
@@ -535,7 +590,16 @@ void pwm_disable(struct pwm_device *pwm)
mutex_lock(&pwm->lock);
if (pwm_is_enabled(pwm)) {
- pwm->chip->ops->disable(pwm->chip, pwm);
+ if (pwm->chip->ops->apply) {
+ struct pwm_state state;
+
+ pwm_get_state(pwm, &state);
+ state.enabled = false;
+
+ pwm->chip->ops->apply(pwm->chip, pwm, &state);
+ } else {
+ pwm->chip->ops->disable(pwm->chip, pwm);
+ }
pwm->state.enabled = false;
}
@@ -543,6 +607,56 @@ void pwm_disable(struct pwm_device *pwm)
}
EXPORT_SYMBOL_GPL(pwm_disable);
+/**
+ * pwm_apply_state() - atomically apply a new state to a PWM device
+ * @pwm: PWM device
+ * @state: new state to apply
+ */
+int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
+{
+ int err = 0;
+
+ if (!pwm)
+ return -EINVAL;
+
+ if (!memcmp(state, &pwm->state, sizeof(*state)))
+ return 0;
+
+ if (pwm->chip->ops->apply) {
+ err = pwm->chip->ops->apply(pwm->chip, pwm, state);
+ if (!err)
+ pwm_set_state(pwm, state);
+ } else {
+ /*
+ * FIXME: restore the initial state in case of error.
+ */
+ if (state->polarity != pwm->state.polarity) {
+ pwm_disable(pwm);
+ err = pwm_set_polarity(pwm, state->polarity);
+ if (err)
+ goto out;
+ }
+
+ if (state->period != pwm->state.period ||
+ state->duty_cycle != pwm->state.duty_cycle) {
+ err = pwm_config(pwm, state->period, state->duty_cycle);
+ if (err)
+ goto out;
+ }
+
+ if (state->enabled != pwm->state.enabled) {
+ if (state->enabled)
+ err = pwm_enable(pwm);
+ else
+ pwm_disable(pwm);
+ }
+ }
+
+out:
+ return err;
+}
+EXPORT_SYMBOL_GPL(pwm_apply_state);
+
static struct pwm_chip *of_node_to_pwmchip(struct device_node *np)
{
struct pwm_chip *chip;
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index caa0ffe..5e7b378 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -174,6 +174,30 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
return pwm ? pwm->state.polarity : PWM_POLARITY_NORMAL;
}
+int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state);
+
+/**
+ * pwm_get_state() - retrieve the current PWM state
+ * @pwm: PWM device
+ * @state: state to fill with the current PWM state
+ */
+static inline void pwm_get_state(struct pwm_device *pwm,
+ struct pwm_state *state)
+{
+ *state = pwm->state;
+}
+
+/**
+ * pwm_get_default_state() - retrieve the default PWM state
+ * @pwm: PWM device
+ * @state: state to fill with the default PWM state
+ */
+static inline void pwm_get_default_state(struct pwm_device *pwm,
+ struct pwm_state *state)
+{
+ *state = pwm->default_state;
+}
+
/**
* struct pwm_ops - PWM controller operations
* @request: optional hook for requesting a PWM
@@ -182,6 +206,7 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
* @set_polarity: configure the polarity of this PWM
* @enable: enable PWM output toggling
* @disable: disable PWM output toggling
+ * @apply: atomically apply a new PWM config
* @reset_state: reset the current PWM state (pwm->state) to the actual
* hardware state. This function is only called once per
* PWM device when the PWM chip is registered.
@@ -197,6 +222,8 @@ struct pwm_ops {
enum pwm_polarity polarity);
int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
+ int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
+ const struct pwm_state *state);
void (*reset_state)(struct pwm_chip *chip, struct pwm_device *pwm);
#ifdef CONFIG_DEBUG_FS
void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
--
2.1.4
^ permalink raw reply related
* [PATCH v4 21/24] pwm: add information about polarity, duty cycle and period to debugfs
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
From: Heiko Stübner <heiko@sntech.de>
The pwm-states make it possible to also output the polarity, duty cycle
and period information in the debugfs pwm summary-outout.
This makes it easier to gather overview information about pwms without
needing to walk through the sysfs attributes of every pwm.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/pwm/core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index fbc71d3..1619101 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1035,6 +1035,11 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
if (pwm_is_enabled(pwm))
seq_puts(s, " enabled");
+ seq_printf(s, " period:%uns", pwm_get_period(pwm));
+ seq_printf(s, " duty:%uns", pwm_get_duty_cycle(pwm));
+ seq_printf(s, " polarity:%s", pwm_get_polarity(pwm) ? "inverse"
+ : "normal");
+
seq_puts(s, "\n");
}
}
--
2.1.4
^ permalink raw reply related
* [PATCH v4 22/24] pwm: rockchip: add initial state retrieval
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Implement the ->reset_state() function to expose initial state.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/pwm/pwm-rockchip.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c
index 7d9cc90..6eab25c 100644
--- a/drivers/pwm/pwm-rockchip.c
+++ b/drivers/pwm/pwm-rockchip.c
@@ -51,6 +51,7 @@ struct rockchip_pwm_data {
void (*set_enable)(struct pwm_chip *chip,
struct pwm_device *pwm, bool enable);
+ void (*reset_state)(struct pwm_chip *chip, struct pwm_device *pwm);
};
static inline struct rockchip_pwm_chip *to_rockchip_pwm_chip(struct pwm_chip *c)
@@ -75,6 +76,18 @@ static void rockchip_pwm_set_enable_v1(struct pwm_chip *chip,
writel_relaxed(val, pc->base + pc->data->regs.ctrl);
}
+static void rockchip_pwm_reset_state_v1(struct pwm_chip *chip,
+ struct pwm_device *pwm)
+{
+ struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
+ u32 enable_conf = PWM_CTRL_OUTPUT_EN | PWM_CTRL_TIMER_EN;
+ u32 val;
+
+ val = readl(pc->base + pc->data->regs.ctrl);
+ if ((val & enable_conf) = enable_conf)
+ pwm->state.enabled = true;
+}
+
static void rockchip_pwm_set_enable_v2(struct pwm_chip *chip,
struct pwm_device *pwm, bool enable)
{
@@ -98,6 +111,54 @@ static void rockchip_pwm_set_enable_v2(struct pwm_chip *chip,
writel_relaxed(val, pc->base + pc->data->regs.ctrl);
}
+static void rockchip_pwm_reset_state_v2(struct pwm_chip *chip,
+ struct pwm_device *pwm)
+{
+ struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
+ u32 enable_conf = PWM_OUTPUT_LEFT | PWM_LP_DISABLE | PWM_ENABLE |
+ PWM_CONTINUOUS;
+ u32 val;
+
+ val = readl(pc->base + pc->data->regs.ctrl);
+ if ((val & enable_conf) != enable_conf)
+ return;
+
+ pwm->state.enabled = true;
+
+ if (!(val & PWM_DUTY_POSITIVE))
+ pwm->state.polarity = PWM_POLARITY_INVERSED;
+}
+
+static void rockchip_pwm_reset_state(struct pwm_chip *chip,
+ struct pwm_device *pwm)
+{
+ struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
+ unsigned long clk_rate;
+ u64 tmp;
+ int ret;
+
+ ret = clk_enable(pc->clk);
+ if (ret)
+ return;
+
+ clk_rate = clk_get_rate(pc->clk);
+
+ tmp = readl(pc->base + pc->data->regs.period);
+ tmp *= pc->data->prescaler * NSEC_PER_SEC;
+ do_div(tmp, clk_rate);
+ pwm->state.period = tmp;
+
+ tmp = readl(pc->base + pc->data->regs.duty);
+ tmp *= pc->data->prescaler * NSEC_PER_SEC;
+ do_div(tmp, clk_rate);
+ pwm->state.duty_cycle = tmp;
+
+ pc->data->reset_state(chip, chip->pwms);
+
+ if (!pwm_is_enabled(pwm))
+ clk_disable(pc->clk);
+}
+
static int rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
{
@@ -171,6 +232,7 @@ static void rockchip_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
}
static const struct pwm_ops rockchip_pwm_ops_v1 = {
+ .reset_state = rockchip_pwm_reset_state,
.config = rockchip_pwm_config,
.enable = rockchip_pwm_enable,
.disable = rockchip_pwm_disable,
@@ -178,6 +240,7 @@ static const struct pwm_ops rockchip_pwm_ops_v1 = {
};
static const struct pwm_ops rockchip_pwm_ops_v2 = {
+ .reset_state = rockchip_pwm_reset_state,
.config = rockchip_pwm_config,
.set_polarity = rockchip_pwm_set_polarity,
.enable = rockchip_pwm_enable,
@@ -195,6 +258,7 @@ static const struct rockchip_pwm_data pwm_data_v1 = {
.prescaler = 2,
.ops = &rockchip_pwm_ops_v1,
.set_enable = rockchip_pwm_set_enable_v1,
+ .reset_state = rockchip_pwm_reset_state_v1,
};
static const struct rockchip_pwm_data pwm_data_v2 = {
@@ -207,6 +271,7 @@ static const struct rockchip_pwm_data pwm_data_v2 = {
.prescaler = 1,
.ops = &rockchip_pwm_ops_v2,
.set_enable = rockchip_pwm_set_enable_v2,
+ .reset_state = rockchip_pwm_reset_state_v2,
};
static const struct rockchip_pwm_data pwm_data_vop = {
@@ -219,6 +284,7 @@ static const struct rockchip_pwm_data pwm_data_vop = {
.prescaler = 1,
.ops = &rockchip_pwm_ops_v2,
.set_enable = rockchip_pwm_set_enable_v2,
+ .reset_state = rockchip_pwm_reset_state_v2,
};
static const struct of_device_id rockchip_pwm_dt_ids[] = {
--
2.1.4
^ permalink raw reply related
* [PATCH v4 23/24] pwm: rockchip: add support for atomic update
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Implement the ->apply() function to add support for atomic update.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/pwm/pwm-rockchip.c | 53 +++++++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 24 deletions(-)
diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c
index 6eab25c..48b814d 100644
--- a/drivers/pwm/pwm-rockchip.c
+++ b/drivers/pwm/pwm-rockchip.c
@@ -50,7 +50,8 @@ struct rockchip_pwm_data {
const struct pwm_ops *ops;
void (*set_enable)(struct pwm_chip *chip,
- struct pwm_device *pwm, bool enable);
+ struct pwm_device *pwm, bool enable,
+ enum pwm_polarity polarity);
void (*reset_state)(struct pwm_chip *chip, struct pwm_device *pwm);
};
@@ -60,7 +61,8 @@ static inline struct rockchip_pwm_chip *to_rockchip_pwm_chip(struct pwm_chip *c)
}
static void rockchip_pwm_set_enable_v1(struct pwm_chip *chip,
- struct pwm_device *pwm, bool enable)
+ struct pwm_device *pwm, bool enable,
+ enum pwm_polarity polarity)
{
struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
u32 enable_conf = PWM_CTRL_OUTPUT_EN | PWM_CTRL_TIMER_EN;
@@ -89,14 +91,15 @@ static void rockchip_pwm_reset_state_v1(struct pwm_chip *chip,
}
static void rockchip_pwm_set_enable_v2(struct pwm_chip *chip,
- struct pwm_device *pwm, bool enable)
+ struct pwm_device *pwm, bool enable,
+ enum pwm_polarity polarity)
{
struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
u32 enable_conf = PWM_OUTPUT_LEFT | PWM_LP_DISABLE | PWM_ENABLE |
PWM_CONTINUOUS;
u32 val;
- if (pwm_get_polarity(pwm) = PWM_POLARITY_INVERSED)
+ if (polarity = PWM_POLARITY_INVERSED)
enable_conf |= PWM_DUTY_NEGATIVE | PWM_INACTIVE_POSITIVE;
else
enable_conf |= PWM_DUTY_POSITIVE | PWM_INACTIVE_NEGATIVE;
@@ -165,7 +168,6 @@ static int rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
unsigned long period, duty;
u64 clk_rate, div;
- int ret;
clk_rate = clk_get_rate(pc->clk);
@@ -182,15 +184,8 @@ static int rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
do_div(div, pc->data->prescaler * NSEC_PER_SEC);
duty = div;
- ret = clk_enable(pc->clk);
- if (ret)
- return ret;
-
writel(period, pc->base + pc->data->regs.period);
writel(duty, pc->base + pc->data->regs.duty);
- writel(0, pc->base + pc->data->regs.cntr);
-
- clk_disable(pc->clk);
return 0;
}
@@ -208,43 +203,53 @@ static int rockchip_pwm_set_polarity(struct pwm_chip *chip,
return 0;
}
-static int rockchip_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
+static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+ const struct pwm_state *state)
{
struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
+ bool enabled = pwm_is_enabled(pwm);
int ret;
ret = clk_enable(pc->clk);
if (ret)
return ret;
- pc->data->set_enable(chip, pwm, true);
+ if (state->polarity != pwm_get_polarity(pwm) && enabled) {
+ pc->data->set_enable(chip, pwm, false, state->polarity);
+ enabled = false;
+ }
- return 0;
-}
+ ret = rockchip_pwm_config(chip, pwm, state->duty_cycle, state->period);
+ if (ret) {
+ if (enabled != pwm_is_enabled(pwm))
+ pc->data->set_enable(chip, pwm, !enabled,
+ state->polarity);
-static void rockchip_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
-{
- struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
+ goto out;
+ }
- pc->data->set_enable(chip, pwm, false);
+ if (state->enabled != enabled)
+ pc->data->set_enable(chip, pwm, state->enabled,
+ state->polarity);
+out:
clk_disable(pc->clk);
+
+ return ret;
}
static const struct pwm_ops rockchip_pwm_ops_v1 = {
.reset_state = rockchip_pwm_reset_state,
.config = rockchip_pwm_config,
- .enable = rockchip_pwm_enable,
- .disable = rockchip_pwm_disable,
+ .apply = rockchip_pwm_apply,
.owner = THIS_MODULE,
};
static const struct pwm_ops rockchip_pwm_ops_v2 = {
.reset_state = rockchip_pwm_reset_state,
.config = rockchip_pwm_config,
+ .apply = rockchip_pwm_apply,
.set_polarity = rockchip_pwm_set_polarity,
- .enable = rockchip_pwm_enable,
- .disable = rockchip_pwm_disable,
.owner = THIS_MODULE,
};
--
2.1.4
^ permalink raw reply related
* [PATCH v4 24/24] regulator: pwm: properly initialize the ->state field
From: Boris Brezillon @ 2015-11-16 8:56 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
The ->state field is currently initialized to 0, thus referencing the
voltage selector at index 0, which might not reflect the current voltage
value.
If possible, retrieve the current voltage selector from the PWM state, else
return -EINVAL.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Mark Brown <broonie@kernel.org>
---
drivers/regulator/pwm-regulator.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index 9ffdbd6..449e3b3 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -41,10 +41,35 @@ struct pwm_voltages {
/**
* Voltage table call-backs
*/
+static void pwm_regulator_init_state(struct regulator_dev *rdev)
+{
+ struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
+ struct pwm_state pwm_state;
+ unsigned int dutycycle;
+ int i;
+
+ pwm_get_state(drvdata->pwm, &pwm_state);
+
+ if (!pwm_state.period)
+ return;
+
+ dutycycle = (pwm_state.duty_cycle * 100) / pwm_state.period;
+
+ for (i = 0; i < rdev->desc->n_voltages; i++) {
+ if (dutycycle = drvdata->duty_cycle_table[i].dutycycle) {
+ drvdata->state = i;
+ return;
+ }
+ }
+}
+
static int pwm_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
+ if (drvdata->state < 0)
+ pwm_regulator_init_state(rdev);
+
return drvdata->state;
}
@@ -211,6 +236,7 @@ static int pwm_regulator_init_table(struct platform_device *pdev,
return ret;
}
+ drvdata->state = -EINVAL;
drvdata->duty_cycle_table = duty_cycle_table;
pwm_regulator_desc.ops = &pwm_regulator_voltage_table_ops;
pwm_regulator_desc.n_voltages = length / sizeof(*duty_cycle_table);
--
2.1.4
^ permalink raw reply related
* Re: [PATCH v4 09/24] regulator: pwm: use pwm_get/set_default_xxx() helpers where appropriate
From: Mark Brown @ 2015-11-16 10:55 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-10-git-send-email-boris.brezillon@free-electrons.com>
[-- Attachment #1: Type: text/plain, Size: 651 bytes --]
On Mon, Nov 16, 2015 at 09:56:32AM +0100, Boris Brezillon wrote:
> +++ b/drivers/regulator/pwm-regulator.c
> @@ -56,7 +56,7 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
> int dutycycle;
> int ret;
>
> - pwm_reg_period = pwm_get_period(drvdata->pwm);
> + pwm_reg_period = pwm_get_default_period(drvdata->pwm);
>
> dutycycle = (pwm_reg_period *
> drvdata->duty_cycle_table[selector].dutycycle) / 100;
It's not clear to me that we're not looking for the current period here
or in the other use. Won't configuring based on a period other than the
one that has been set give the wrong answer?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply
* Re: [PATCH] [media] hdmi: added functions for MPEG InfoFrames
From: Thierry Reding @ 2015-11-16 11:50 UTC (permalink / raw)
To: Enric Balletbo i Serra
Cc: linux-fbdev, Mauro Carvalho Chehab, linux-kernel, dri-devel,
Tomi Valkeinen, Hans Verkuil, Martin Bugge,
Jean-Christophe Plagniol-Villard
In-Reply-To: <1447526299-4222-1-git-send-email-enric.balletbo@collabora.com>
[-- Attachment #1: Type: text/plain, Size: 2699 bytes --]
On Sat, Nov 14, 2015 at 07:38:19PM +0100, Enric Balletbo i Serra wrote:
> The MPEG Source (MS) InfoFrame is in EIA/CEA-861B. It describes aspects of
> the compressed video stream that were used to produce the uncompressed
> video.
>
> The patch adds functions to work with MPEG InfoFrames.
>
> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> ---
> drivers/video/hdmi.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/hdmi.h | 24 ++++++++
> 2 files changed, 180 insertions(+)
According to the CEA specification a source is expected to send this
type of infoframe once per video frame. I'm curious how you envision
this to be ensured. Would hardware provide a mechanism to store this
data and send the infoframe automatically? How would you ensure that
updates sent to the hardware match the upcoming frame?
> diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
[...]
> @@ -435,6 +510,8 @@ hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size)
> length = hdmi_vendor_any_infoframe_pack(&frame->vendor,
> buffer, size);
> break;
> + case HDMI_INFOFRAME_TYPE_MPEG:
> + length = hdmi_mpeg_infoframe_pack(&frame->mpeg, buffer, size);
Missing "break;"?
> @@ -899,6 +978,41 @@ static void hdmi_audio_infoframe_log(const char *level,
> frame->downmix_inhibit ? "Yes" : "No");
> }
>
> +static const char *hdmi_mpeg_picture_get_name(enum hdmi_mpeg_picture_type type)
> +{
> + switch (type) {
> + case HDMI_MPEG_PICTURE_TYPE_UNKNOWN:
> + return "Unknown";
> + case HDMI_MPEG_PICTURE_TYPE_I:
> + return "Intra-coded picture";
> + case HDMI_MPEG_PICTURE_TYPE_B:
> + return "Bi-predictive picture";
> + case HDMI_MPEG_PICTURE_TYPE_P:
> + return "Predicted picture";
> + }
I'd have chosen the slightly more canonical "I-Frame", "P-Frame",
"B-Frame" here, but that's not a strong objection.
> + return "Reserved";
There really can't be another value here, so I think this should either
return NULL or even go as far as let it crash. There should be no way
for the invalid value to make it this far.
> +static int hdmi_mpeg_infoframe_unpack(struct hdmi_mpeg_infoframe *frame,
> + void *buffer)
> +{
> + u8 *ptr = buffer;
> +
> + if (ptr[0] != HDMI_INFOFRAME_TYPE_MPEG ||
> + ptr[1] != 1 ||
> + ptr[2] != HDMI_MPEG_INFOFRAME_SIZE) {
> + return -EINVAL;
> + }
There's no need for the braces here.
> @@ -314,6 +336,7 @@ union hdmi_vendor_any_infoframe {
> * @spd: spd infoframe
> * @vendor: union of all vendor infoframes
> * @audio: audio infoframe
> + * @mpeg: mpeg infoframe
s/mpeg/MPEG/
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply
* Re: [PATCH v4 09/24] regulator: pwm: use pwm_get/set_default_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 12:23 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <20151116105558.GB31303@sirena.org.uk>
Hi Mark,
On Mon, 16 Nov 2015 10:55:58 +0000
Mark Brown <broonie@kernel.org> wrote:
> On Mon, Nov 16, 2015 at 09:56:32AM +0100, Boris Brezillon wrote:
>
> > +++ b/drivers/regulator/pwm-regulator.c
> > @@ -56,7 +56,7 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
> > int dutycycle;
> > int ret;
> >
> > - pwm_reg_period = pwm_get_period(drvdata->pwm);
> > + pwm_reg_period = pwm_get_default_period(drvdata->pwm);
> >
> > dutycycle = (pwm_reg_period *
> > drvdata->duty_cycle_table[selector].dutycycle) / 100;
>
> It's not clear to me that we're not looking for the current period here
> or in the other use. Won't configuring based on a period other than the
> one that has been set give the wrong answer?
Hm, maybe that's naming problem. What I call the 'default' period here
is actually the period configured in your board file (using a PWM lookup
table) or your DT. This value represent the period requested by the PWM
user not a default value specified by the PWM chip driver.
The reason we're not using the 'current' period value is because it may
have been set by the bootloader, and may be inappropriate for our use
case (ie. the period may be to small to represent the different
voltages).
ITOH, we're using the current period value when calculating the current
voltage, because we want to get the correct voltage value, and the PWM
device may still use the configuration set by the bootloader (not the
default one specified in your board or DT files).
I hope this clarifies the differences between the current and default
period, and why we should use the default value here.
Best Regards,
Boris
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply
* Re: [PATCH v4 05/24] misc: max77693-haptic: use pwm_get_xxx() helpers where appropriate
From: Krzysztof Kozlowski @ 2015-11-16 13:10 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-6-git-send-email-boris.brezillon@free-electrons.com>
W dniu 16.11.2015 o 17:56, Boris Brezillon pisze:
> Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field.
> Doing that will ease adaptation of the PWM framework to support atomic
> update.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> Patch generated with the following coccinelle script:
>
> --->8---
> virtual patch
>
> @@
> struct pwm_device *p;
> expression e;
> @@
> (
> -(p)->polarity = e;
> +pwm_set_polarity((p), e);
> |
> -(p)->polarity
> +pwm_get_polarity((p))
> |
> -(p)->period = e;
> +pwm_set_period((p), e);
> |
> -(p)->period
> +pwm_get_period((p))
> |
> -(p)->duty_cycle = e;
> +pwm_set_duty_cycle((p), e);
> |
> -(p)->duty_cycle
> +pwm_get_duty_cycle((p))
> )
> --->8---
> ---
> drivers/input/misc/max77693-haptic.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
> index 6d96bff..a038fb3 100644
> --- a/drivers/input/misc/max77693-haptic.c
> +++ b/drivers/input/misc/max77693-haptic.c
> @@ -70,10 +70,11 @@ struct max77693_haptic {
>
> static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
> {
> - int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2;
> + int delta = (pwm_get_period((haptic->pwm_dev)) + haptic->pwm_duty) / 2;
Double parentheses over argument are not needed so just:
pwm_get_period(haptic->pwm_dev) + ...
Beside that patch looks good, so with removing parentheses here and below:
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Best regards,
Krzysztof
> int error;
>
> - error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period);
> + error = pwm_config(haptic->pwm_dev, delta,
> + pwm_get_period((haptic->pwm_dev)));
> if (error) {
> dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
> return error;
> @@ -245,7 +246,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
> * The formula to convert magnitude to pwm_duty as follows:
> * - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF)
> */
> - period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude;
> + period_mag_multi = (u64)pwm_get_period((haptic->pwm_dev)) * haptic->magnitude;
> haptic->pwm_duty = (unsigned int)(period_mag_multi >>
> MAX_MAGNITUDE_SHIFT);
>
>
^ permalink raw reply
* Re: [PATCH v4 05/24] misc: max77693-haptic: use pwm_get_xxx() helpers where appropriate
From: Boris Brezillon @ 2015-11-16 13:55 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <5649D5D0.6080204@samsung.com>
Hi Krzysztof,
On Mon, 16 Nov 2015 22:10:40 +0900
Krzysztof Kozlowski <k.kozlowski@samsung.com> wrote:
> W dniu 16.11.2015 o 17:56, Boris Brezillon pisze:
> > Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field.
> > Doing that will ease adaptation of the PWM framework to support atomic
> > update.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> > Patch generated with the following coccinelle script:
> >
> > --->8---
> > virtual patch
> >
> > @@
> > struct pwm_device *p;
> > expression e;
> > @@
> > (
> > -(p)->polarity = e;
> > +pwm_set_polarity((p), e);
> > |
> > -(p)->polarity
> > +pwm_get_polarity((p))
> > |
> > -(p)->period = e;
> > +pwm_set_period((p), e);
> > |
> > -(p)->period
> > +pwm_get_period((p))
> > |
> > -(p)->duty_cycle = e;
> > +pwm_set_duty_cycle((p), e);
> > |
> > -(p)->duty_cycle
> > +pwm_get_duty_cycle((p))
> > )
> > --->8---
> > ---
> > drivers/input/misc/max77693-haptic.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
> > index 6d96bff..a038fb3 100644
> > --- a/drivers/input/misc/max77693-haptic.c
> > +++ b/drivers/input/misc/max77693-haptic.c
> > @@ -70,10 +70,11 @@ struct max77693_haptic {
> >
> > static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
> > {
> > - int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2;
> > + int delta = (pwm_get_period((haptic->pwm_dev)) + haptic->pwm_duty) / 2;
>
> Double parentheses over argument are not needed so just:
> pwm_get_period(haptic->pwm_dev) + ...
Actually it was generated with coccinelle, hence I didn't fix existing
coding style issues, but I have no problem fixing them.
Thanks,
Boris
>
> Beside that patch looks good, so with removing parentheses here and below:
>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>
> Best regards,
> Krzysztof
>
> > int error;
> >
> > - error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period);
> > + error = pwm_config(haptic->pwm_dev, delta,
> > + pwm_get_period((haptic->pwm_dev)));
> > if (error) {
> > dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
> > return error;
> > @@ -245,7 +246,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
> > * The formula to convert magnitude to pwm_duty as follows:
> > * - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF)
> > */
> > - period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude;
> > + period_mag_multi = (u64)pwm_get_period((haptic->pwm_dev)) * haptic->magnitude;
> > haptic->pwm_duty = (unsigned int)(period_mag_multi >>
> > MAX_MAGNITUDE_SHIFT);
> >
> >
>
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply
* Re: [PATCH v4 00/24] pwm: add support for atomic update
From: Heiko Stübner @ 2015-11-16 14:45 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com>
Hi Boris,
Am Montag, 16. November 2015, 09:56:23 schrieb Boris Brezillon:
> Hello,
>
> This series adds support for atomic PWM update, or IOW, the capability
> to update all the parameters of a PWM device (enabled/disabled, period,
> duty and polarity) in one go.
you already include my tested-by tags, but anyway, the series still works
nicely on 4.4-rc1 on my veyron chromebook.
Heiko
^ permalink raw reply
* Re: [PATCH v4 05/24] misc: max77693-haptic: use pwm_get_xxx() helpers where appropriate
From: Guenter Roeck @ 2015-11-16 15:55 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <20151116145509.3ea50eb0@bbrezillon>
On 11/16/2015 05:55 AM, Boris Brezillon wrote:
> Hi Krzysztof,
>
> On Mon, 16 Nov 2015 22:10:40 +0900
> Krzysztof Kozlowski <k.kozlowski@samsung.com> wrote:
>
>> W dniu 16.11.2015 o 17:56, Boris Brezillon pisze:
>>> Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field.
>>> Doing that will ease adaptation of the PWM framework to support atomic
>>> update.
>>>
>>> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
>>> ---
>>> Patch generated with the following coccinelle script:
>>>
>>> --->8---
>>> virtual patch
>>>
>>> @@
>>> struct pwm_device *p;
>>> expression e;
>>> @@
>>> (
>>> -(p)->polarity = e;
>>> +pwm_set_polarity((p), e);
>>> |
>>> -(p)->polarity
>>> +pwm_get_polarity((p))
>>> |
>>> -(p)->period = e;
>>> +pwm_set_period((p), e);
>>> |
>>> -(p)->period
>>> +pwm_get_period((p))
>>> |
>>> -(p)->duty_cycle = e;
>>> +pwm_set_duty_cycle((p), e);
>>> |
>>> -(p)->duty_cycle
>>> +pwm_get_duty_cycle((p))
>>> )
>>> --->8---
>>> ---
>>> drivers/input/misc/max77693-haptic.c | 7 ++++---
>>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
>>> index 6d96bff..a038fb3 100644
>>> --- a/drivers/input/misc/max77693-haptic.c
>>> +++ b/drivers/input/misc/max77693-haptic.c
>>> @@ -70,10 +70,11 @@ struct max77693_haptic {
>>>
>>> static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
>>> {
>>> - int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2;
>>> + int delta = (pwm_get_period((haptic->pwm_dev)) + haptic->pwm_duty) / 2;
>>
>> Double parentheses over argument are not needed so just:
>> pwm_get_period(haptic->pwm_dev) + ...
>
> Actually it was generated with coccinelle, hence I didn't fix existing
> coding style issues, but I have no problem fixing them.
>
There was no existing coding style issue. Your coccinelle script introduces it.
You might want to consider updating your script and remove the unnecessary (( ))
from it.
Guenter
> Thanks,
>
> Boris
>
>>
>> Beside that patch looks good, so with removing parentheses here and below:
>>
>> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>>
>> Best regards,
>> Krzysztof
>>
>>> int error;
>>>
>>> - error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period);
>>> + error = pwm_config(haptic->pwm_dev, delta,
>>> + pwm_get_period((haptic->pwm_dev)));
>>> if (error) {
>>> dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
>>> return error;
>>> @@ -245,7 +246,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
>>> * The formula to convert magnitude to pwm_duty as follows:
>>> * - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF)
>>> */
>>> - period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude;
>>> + period_mag_multi = (u64)pwm_get_period((haptic->pwm_dev)) * haptic->magnitude;
>>> haptic->pwm_duty = (unsigned int)(period_mag_multi >>
>>> MAX_MAGNITUDE_SHIFT);
>>>
>>>
>>
>
>
>
^ permalink raw reply
* Re: [PATCH v4 04/24] hwmon: pwm-fan: use pwm_get_xxx() helpers where appropriate
From: Guenter Roeck @ 2015-11-16 15:59 UTC (permalink / raw)
To: linux-arm-kernel
In-Reply-To: <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com>
On 11/16/2015 12:56 AM, Boris Brezillon wrote:
> Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field.
> Doing that will ease adaptation of the PWM framework to support atomic
> update.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> Patch generated with the following coccinelle script:
>
> --->8---
> virtual patch
>
> @@
> struct pwm_device *p;
> expression e;
> @@
> (
> -(p)->polarity = e;
> +pwm_set_polarity((p), e);
> |
> -(p)->polarity
> +pwm_get_polarity((p))
s/((p))/(p)/
> |
> -(p)->period = e;
> +pwm_set_period((p), e);
> |
> -(p)->period
> +pwm_get_period((p))
s/((p))/(p)/
> |
> -(p)->duty_cycle = e;
> +pwm_set_duty_cycle((p), e);
The (p) seems unnecessary here.
> |
> -(p)->duty_cycle
> +pwm_get_duty_cycle((p))
s/((p))/(p)/
> )
> --->8---
> ---
> drivers/hwmon/pwm-fan.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 3e23003..105b964 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -47,8 +47,8 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
> if (ctx->pwm_value = pwm)
> goto exit_set_pwm_err;
>
> - duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM);
> - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
> + duty = DIV_ROUND_UP(pwm * (pwm_get_period((ctx->pwm)) - 1), MAX_PWM);
> + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm)));
Please drop all the unnecessary ( ).
Thanks,
Guenter
> if (ret)
> goto exit_set_pwm_err;
>
> @@ -234,10 +234,10 @@ static int pwm_fan_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, ctx);
>
> /* Set duty cycle to maximum allowed */
> - duty_cycle = ctx->pwm->period - 1;
> + duty_cycle = pwm_get_period((ctx->pwm)) - 1;
> ctx->pwm_value = MAX_PWM;
>
> - ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period);
> + ret = pwm_config(ctx->pwm, duty_cycle, pwm_get_period((ctx->pwm)));
> if (ret) {
> dev_err(&pdev->dev, "Failed to configure PWM\n");
> return ret;
> @@ -309,8 +309,9 @@ static int pwm_fan_resume(struct device *dev)
> if (ctx->pwm_value = 0)
> return 0;
>
> - duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM);
> - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
> + duty = DIV_ROUND_UP(ctx->pwm_value * (pwm_get_period((ctx->pwm)) - 1),
> + MAX_PWM);
> + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm)));
> if (ret)
> return ret;
> return pwm_enable(ctx->pwm);
>
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox