staging: greybus: introduce pwm_ops::apply
PATCH v2 1/1 staging: greybus: introduce pwm_ops::apply
Introduce apply in pwm_ops to replace legacy operations, like enable, disable, config and set_polarity.
---
V2:
1, define duty_cycle and period as u64 in gb_pwm_config_operation. 2, define duty and period as u64 in gb_pwm_config_request. 3, disable before configuring duty and period if the eventual goal
is a disabled state.
--- drivers/staging/greybus/pwm.c | 61 ++++++++++++----------- include/linux/greybus/greybus_protocols.h | 4 +- 2 files changed, 34 insertions(+), 31 deletions(-)
drivers/staging/greybus/pwm.c +32 -29
@@ -89,7 +89,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, }static int gb_pwm_config_operation (struct gb_pwm_chip *pwmc, -u8 which,u32 duty,u32 period) +u8 which,u64 duty,u64 period) {struct gb_pwm_config_request request;struct gbphy_device *gbphy_dev;
@@ -99,8 +99,8 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,return -EINVAL ; request.which = which; - request.duty =cpu_to_le32 (duty); - request.period =cpu_to_le32 (period); + request.duty = duty; + request.period = period; gbphy_dev =to_gbphy_dev (pwmc->chip.dev); ret =gbphy_runtime_get_sync (gbphy_dev);
@@ -204,43 +204,46 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)gb_pwm_deactivate_operation (pwmc, pwm->hwpwm); } -static int gb_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, -int duty_ns,int period_ns) +static int gb_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) { +int err; +bool enabled = pwm->state.enabled;struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); -return gb_pwm_config_operation (pwmc, pwm->hwpwm, duty_ns, period_ns); -}; - -static int gb_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm, -enum pwm_polarity polarity) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); - -return gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, polarity); -}; +/* set polarity */ +if (state->polarity != pwm->state.polarity) { +if (enabled) { +gb_pwm_disable_operation (pwmc, pwm->hwpwm); + enabled = false; + } + err =gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, state->polarity); +if (err) +return err; + } -static int gb_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +if (!state->enabled) { +if (enabled) +gb_pwm_disable_operation (pwmc, pwm->hwpwm); +return 0 ; + } -return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -}; +/* set period and duty cycle*/ + err =gb_pwm_config_operation (pwmc, pwm->hwpwm, state->duty_cycle, state->period); +if (err) +return err; -static void gb_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +/* enable/disable */ +if (!enabled) +return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -gb_pwm_disable_operation (pwmc, pwm->hwpwm); -}; +return 0 ; +}static const struct pwm_ops gb_pwm_ops = { .request = gb_pwm_request, .free = gb_pwm_free, - .config = gb_pwm_config, - .set_polarity = gb_pwm_set_polarity, - .enable = gb_pwm_enable, - .disable = gb_pwm_disable, + .apply = gb_pwm_apply, .owner =THIS_MODULE , };
include/linux/greybus/greybus_protocols.h +2 -2
@@ -812,8 +812,8 @@ struct gb_pwm_deactivate_request {struct gb_pwm_config_request {__u8 which; -__le32 duty; -__le32 period; +__u64 duty; +__u64 period; } __packed;struct gb_pwm_polarity_request {
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 118 lines · Song Chen
Introduce apply in
pwm_opsto replace legacy operations, like enable, disable, config andset_polarity.Signed-off-by Song Chen <[email protected]>---
V2:
1, defineduty_cycleand period as u64 ingb_pwm_config_operation. 2, define duty and period as u64 ingb_pwm_config_request. 3, disable before configuring duty and period if the eventual goal
is a disabled state.--- drivers/staging/greybus/pwm.c | 61 ++++++++++++----------- include/linux/greybus/greybus_protocols.h | 4 +- 2 files changed, 34 insertions(+), 31 deletions(-)drivers/staging/greybus/pwm.c +32
-29@@ -89,7 +89,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, }static int gb_pwm_config_operation (struct gb_pwm_chip *pwmc, -u8 which,u32 duty,u32 period) +u8 which,u64 duty,u64 period) {struct gb_pwm_config_request request;struct gbphy_device *gbphy_dev;@@ -99,8 +99,8 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,return -EINVAL ; request.which = which; - request.duty =cpu_to_le32 (duty); - request.period =cpu_to_le32 (period); + request.duty = duty; + request.period = period; gbphy_dev =to_gbphy_dev (pwmc->chip.dev); ret =gbphy_runtime_get_sync (gbphy_dev);@@ -204,43 +204,46 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)gb_pwm_deactivate_operation (pwmc, pwm->hwpwm); } -static int gb_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, -int duty_ns,int period_ns) +static int gb_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) { +int err; +bool enabled = pwm->state.enabled;struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); -return gb_pwm_config_operation (pwmc, pwm->hwpwm, duty_ns, period_ns); -}; - -static int gb_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm, -enum pwm_polarity polarity) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); - -return gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, polarity); -}; +/* set polarity */ +if (state->polarity != pwm->state.polarity) { +if (enabled) { +gb_pwm_disable_operation (pwmc, pwm->hwpwm); + enabled = false; + } + err =gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, state->polarity); +if (err) +return err; + } -static int gb_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +if (!state->enabled) { +if (enabled) +gb_pwm_disable_operation (pwmc, pwm->hwpwm); +return 0 ; + } -return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -}; +/* set period and duty cycle*/ + err =gb_pwm_config_operation (pwmc, pwm->hwpwm, state->duty_cycle, state->period); +if (err) +return err; -static void gb_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +/* enable/disable */ +if (!enabled) +return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -gb_pwm_disable_operation (pwmc, pwm->hwpwm); -}; +return 0 ; +}static const struct pwm_ops gb_pwm_ops = { .request = gb_pwm_request, .free = gb_pwm_free, - .config = gb_pwm_config, - .set_polarity = gb_pwm_set_polarity, - .enable = gb_pwm_enable, - .disable = gb_pwm_disable, + .apply = gb_pwm_apply, .owner =THIS_MODULE , };include/linux/greybus/greybus_protocols.h +0
-0
include/linux/greybus/greybus_protocols.h struct gb_pwm_deactivate_request { · line 817
Quoted 8 lines
include/linux/greybus/greybus_protocols.h +2
-2@@ -812,8 +812,8 @@ struct gb_pwm_deactivate_request {struct gb_pwm_config_request {__u8 which; -__le32 duty; -__le32 period; +__u64 duty; +__u64 period; } __packed;
Did you just change a greybus protocol message that is sent over the wire? Why? And why drop the endian marking of it?
Are you sure this is ok?
thanks,
greg k-h
Hi Greg,
Quoted 120 lines · Greg KH
Quoted 119 lines · Song Chen
Introduce apply in
pwm_opsto replace legacy operations, like enable, disable, config andset_polarity.Signed-off-by Song Chen <[email protected]>---
V2:
1, defineduty_cycleand period as u64 ingb_pwm_config_operation. 2, define duty and period as u64 ingb_pwm_config_request. 3, disable before configuring duty and period if the eventual goal
is a disabled state.--- drivers/staging/greybus/pwm.c | 61 ++++++++++++----------- include/linux/greybus/greybus_protocols.h | 4 +- 2 files changed, 34 insertions(+), 31 deletions(-)drivers/staging/greybus/pwm.c +32
-29@@ -89,7 +89,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, }static int gb_pwm_config_operation (struct gb_pwm_chip *pwmc, -u8 which,u32 duty,u32 period) +u8 which,u64 duty,u64 period) {struct gb_pwm_config_request request;struct gbphy_device *gbphy_dev;@@ -99,8 +99,8 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,return -EINVAL ; request.which = which; - request.duty =cpu_to_le32 (duty); - request.period =cpu_to_le32 (period); + request.duty = duty; + request.period = period; gbphy_dev =to_gbphy_dev (pwmc->chip.dev); ret =gbphy_runtime_get_sync (gbphy_dev);@@ -204,43 +204,46 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)gb_pwm_deactivate_operation (pwmc, pwm->hwpwm); } -static int gb_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, -int duty_ns,int period_ns) +static int gb_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) { +int err; +bool enabled = pwm->state.enabled;struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); -return gb_pwm_config_operation (pwmc, pwm->hwpwm, duty_ns, period_ns); -}; - -static int gb_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm, -enum pwm_polarity polarity) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); - -return gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, polarity); -}; +/* set polarity */ +if (state->polarity != pwm->state.polarity) { +if (enabled) { +gb_pwm_disable_operation (pwmc, pwm->hwpwm); + enabled = false; + } + err =gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, state->polarity); +if (err) +return err; + } -static int gb_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +if (!state->enabled) { +if (enabled) +gb_pwm_disable_operation (pwmc, pwm->hwpwm); +return 0 ; + } -return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -}; +/* set period and duty cycle*/ + err =gb_pwm_config_operation (pwmc, pwm->hwpwm, state->duty_cycle, state->period); +if (err) +return err; -static void gb_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +/* enable/disable */ +if (!enabled) +return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -gb_pwm_disable_operation (pwmc, pwm->hwpwm); -}; +return 0 ; +}static const struct pwm_ops gb_pwm_ops = { .request = gb_pwm_request, .free = gb_pwm_free, - .config = gb_pwm_config, - .set_polarity = gb_pwm_set_polarity, - .enable = gb_pwm_enable, - .disable = gb_pwm_disable, + .apply = gb_pwm_apply, .owner =THIS_MODULE , };include/linux/greybus/greybus_protocols.h +0
-0@@ -812,8 +812,8 @@ struct gb_pwm_deactivate_request {
Quoted 10 lines
include/linux/greybus/greybus_protocols.h struct gb_pwm_deactivate_request { · line 817
Quoted 7 lines
include/linux/greybus/greybus_protocols.h +2
-2struct gb_pwm_config_request {__u8 which; -__le32 duty; -__le32 period; +__u64 duty; +__u64 period; } __packed;Did you just change a greybus protocol message that is sent over the wire? Why? And why drop the endian marking of it?
I discussed with Uwe about losing bit and found there is no perfect way to avoid, even in Uwe's patch[1], as a result, we decided to widen duty and period in gb_pwm_config_request, the other side of the wire is supposed to change accordingly to support 64bit duty and period too(this will introduce compatibility problem and there is no variable like version to address it), similar with ktime_t in y2038, below is the detail [2]
[1]:https://lore.kernel.org/all/[email protected]/ [2]:https://lore.kernel.org/all/[email protected]/
endian is a problem, i shouldn't drop it.
BR
Song
Quoted 7 lines
Are you sure this is ok?
thanks,
greg k-h
Quoted 8 lines · Song Chen
Hi Greg,
Quoted 5 lines · Greg KH
Quoted 4 lines · Song Chen
Introduce apply in
pwm_opsto replace legacy operations, like enable, disable, config andset_polarity.Signed-off-by Song Chen <[email protected]>
. . .
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
include/linux/greybus/greybus_protocols.h +0
-0@@ -812,8 +812,8 @@ struct gb_pwm_deactivate_request { struct gb_pwm_config_request { __u8 which;Quoted 8 lines
include/linux/greybus/greybus_protocols.h struct gb_pwm_deactivate_request { · line 817
Quoted 5 lines
include/linux/greybus/greybus_protocols.h +2
-2- __le32 duty; - __le32 period; + __u64 duty; + __u64 period; } __packed;Did you just change a greybus protocol message that is sent over the wire? Why? And why drop the endian marking of it?
Quoted 2 lines
I discussed with Uwe about losing bit and found there is no perfect way to avoid, even in Uwe's patch[1], as a result, we decided to
The patch you reference [1] does not change the size of the duty cycle and period, it only ensures the value passed is no more than can be represented in an integer.
Quoted 2 lines
widen duty and period in
gb_pwm_config_request, the other side of the wire is supposed to change accordingly to support 64bit duty and
This is what Greg meant about changing the over-the-wire protocol message format. You can't do that, or rather, if you do that, it is a *lot* more work than just changing it as you have done here.
If it is really required (and that's not clear, at least not at this time), then you need to modify the protocol version, and then make sure the versioning logic works correctly, both on the AP side and on the module side for all existing modules.
I would suggest that it is *not* required though, because the existing module code was built with the assumption that it would be provided a 32-bit unsigned value for its duty cycle and period. So as long as you make sure the AP side doesn't send anything nonsensical, they will continue to work as desired.
The correct fix in this case (assuming you don't want to change the protocol) is to ensure that whatever value is passed in to the pwm_ops->config callback (which is gb_pwm_config()) is adjusted to be within a range usable by the existing protocol. Since it's actually an unsigned value, you could double the range supported without changing the protocol if you wanted to do that.
Quoted 3 lines
period too(this will introduce compatibility problem and there is no variable like version to address it), similar with
ktime_tin y2038, below is the detail [2]
And similar to addressing the Y2038 issue, it is not an easy thing to do.
Quoted 4 lines
[1]:https://lore.kernel.org/all/[email protected]/ [2]:https://lore.kernel.org/all/[email protected]/
endian is a problem, i shouldn't drop it.
This is absolutely correct. Did you attempt to compile this?
-Alex
Quoted 11 lines
BR
Song
Quoted 7 lines
Are you sure this is ok?
thanks,
greg k-h
Greg KH
maintainerQuoted 122 lines · Song Chen
Hi Greg,
Quoted 110 lines · Greg KH
Quoted 109 lines · Song Chen
Introduce apply in
pwm_opsto replace legacy operations, like enable, disable, config andset_polarity.Signed-off-by Song Chen <[email protected]>---
V2:
1, defineduty_cycleand period as u64 ingb_pwm_config_operation. 2, define duty and period as u64 ingb_pwm_config_request. 3, disable before configuring duty and period if the eventual goal
is a disabled state.--- drivers/staging/greybus/pwm.c | 61 ++++++++++++----------- include/linux/greybus/greybus_protocols.h | 4 +- 2 files changed, 34 insertions(+), 31 deletions(-)drivers/staging/greybus/pwm.c +32
-29@@ -89,7 +89,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, }static int gb_pwm_config_operation (struct gb_pwm_chip *pwmc, -u8 which,u32 duty,u32 period) +u8 which,u64 duty,u64 period) {struct gb_pwm_config_request request;struct gbphy_device *gbphy_dev;@@ -99,8 +99,8 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,return -EINVAL ; request.which = which; - request.duty =cpu_to_le32 (duty); - request.period =cpu_to_le32 (period); + request.duty = duty; + request.period = period; gbphy_dev =to_gbphy_dev (pwmc->chip.dev); ret =gbphy_runtime_get_sync (gbphy_dev);@@ -204,43 +204,46 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)gb_pwm_deactivate_operation (pwmc, pwm->hwpwm); } -static int gb_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, -int duty_ns,int period_ns) +static int gb_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) { +int err; +bool enabled = pwm->state.enabled;struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); -return gb_pwm_config_operation (pwmc, pwm->hwpwm, duty_ns, period_ns); -}; - -static int gb_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm, -enum pwm_polarity polarity) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); - -return gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, polarity); -}; +/* set polarity */ +if (state->polarity != pwm->state.polarity) { +if (enabled) { +gb_pwm_disable_operation (pwmc, pwm->hwpwm); + enabled = false; + } + err =gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, state->polarity); +if (err) +return err; + } -static int gb_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +if (!state->enabled) { +if (enabled) +gb_pwm_disable_operation (pwmc, pwm->hwpwm); +return 0 ; + } -return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -}; +/* set period and duty cycle*/ + err =gb_pwm_config_operation (pwmc, pwm->hwpwm, state->duty_cycle, state->period); +if (err) +return err; -static void gb_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); +/* enable/disable */ +if (!enabled) +return gb_pwm_enable_operation (pwmc, pwm->hwpwm); -gb_pwm_disable_operation (pwmc, pwm->hwpwm); -}; +return 0 ; +}static const struct pwm_ops gb_pwm_ops = { .request = gb_pwm_request, .free = gb_pwm_free, - .config = gb_pwm_config, - .set_polarity = gb_pwm_set_polarity, - .enable = gb_pwm_enable, - .disable = gb_pwm_disable, + .apply = gb_pwm_apply, .owner =THIS_MODULE , };include/linux/greybus/greybus_protocols.h +0
-0@@ -812,8 +812,8 @@ struct gb_pwm_deactivate_request {struct gb_pwm_config_request {__u8 which;Quoted 8 lines
include/linux/greybus/greybus_protocols.h struct gb_pwm_deactivate_request { · line 817
Quoted 5 lines
include/linux/greybus/greybus_protocols.h +2
-2-__le32 duty; -__le32 period; +__u64 duty; +__u64 period; } __packed;Did you just change a greybus protocol message that is sent over the wire? Why? And why drop the endian marking of it?
Quoted 6 lines
I discussed with Uwe about losing bit and found there is no perfect way to avoid, even in Uwe's patch[1], as a result, we decided to widen duty and period in
gb_pwm_config_request, the other side of the wire is supposed to change accordingly to support 64bit duty and period too(this will introduce compatibility problem and there is no variable like version to address it), similar withktime_tin y2038, below is the detail [2]
Where are you changing the "other side of the wire" here? That wire is in firmware, how are you going to coordinate that change?
This is a hardware API, you can not change it without a lot of very careful work, and I still do not understand why it is needed. What "problem" is this solving that requires the protocol to change?
thanks,
greg k-h
Hello,
orthogonal to the feedback you got for the protocol part, here some thoughts to the PWM specific bits;
Quoted 30 lines · Song Chen
Introduce apply in
pwm_opsto replace legacy operations, like enable, disable, config andset_polarity.Signed-off-by Song Chen <[email protected]>---
V2:
1, defineduty_cycleand period as u64 ingb_pwm_config_operation. 2, define duty and period as u64 ingb_pwm_config_request. 3, disable before configuring duty and period if the eventual goal
is a disabled state.--- drivers/staging/greybus/pwm.c | 61 ++++++++++++----------- include/linux/greybus/greybus_protocols.h | 4 +- 2 files changed, 34 insertions(+), 31 deletions(-)drivers/staging/greybus/pwm.c +1
-1@@ -89,7 +89,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, }static int gb_pwm_config_operation (struct gb_pwm_chip *pwmc, -u8 which,u32 duty,u32 period) +u8 which,u64 duty,u64 period) {struct gb_pwm_config_request request;struct gbphy_device *gbphy_dev;
drivers/staging/greybus/pwm.c static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, · line 103
Quoted 7 lines
drivers/staging/greybus/pwm.c +2
-2@@ -99,8 +99,8 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,return -EINVAL ; request.which = which; - request.duty =cpu_to_le32 (duty); - request.period =cpu_to_le32 (period); + request.duty = duty; + request.period = period;
If you don't change the wire protocol, you want something like:
if (period > U32_MAX) period = U32_MAX; if (duty > period) duty = period;
To further improve the PWM driver it would be great if you added a paragraph about the details of its behaviour; in the format the other drivers do that (see e.g. drivers/pwm/pwm-sifive.c). It should describe the following properties:
- Is a period completed when period/duty changes?
- Is a period completed when the hardware is disabled?
- How does the output behave on disable?
In this specific case I think there is also some rounding behaviour in the backend?! If so, describing this would be good, too.
Quoted 25 lines
drivers/staging/greybus/pwm.c +4
-12gbphy_dev =to_gbphy_dev (pwmc->chip.dev); ret =gbphy_runtime_get_sync (gbphy_dev);@@ -204,43 +204,46 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)gb_pwm_deactivate_operation (pwmc, pwm->hwpwm); } -static int gb_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, -int duty_ns,int period_ns) +static int gb_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) { +int err; +bool enabled = pwm->state.enabled;struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); -return gb_pwm_config_operation (pwmc, pwm->hwpwm, duty_ns, period_ns); -}; - -static int gb_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm, -enum pwm_polarity polarity) -{ -struct gb_pwm_chip *pwmc =pwm_chip_to_gb_pwm_chip (chip); - -return gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, polarity); -};
drivers/staging/greybus/pwm.c static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) · line 223
Quoted 10 lines
drivers/staging/greybus/pwm.c +10
-0+/* set polarity */ +if (state->polarity != pwm->state.polarity) { +if (enabled) { +gb_pwm_disable_operation (pwmc, pwm->hwpwm); + enabled = false; + } + err =gb_pwm_set_polarity_operation (pwmc, pwm->hwpwm, state->polarity); +if (err) +return err; + }
This is copied from the legacy pwm handling in the pwm core. This is good in principle. But if your hardware can change polarity without stopping operation, that would be the thing to do. (The pwm core cannot assume this, so it doesn't.)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |