Add QCOM pwm-lpg and tri-led drivers
Subsystems (3)
cover Add QCOM pwm-lpg and tri-led drivers
Hello,
This series brings QCOM pwm-lpg and tri-led drivers from 4.14 that is required to support pmic-connected notification LED. This comes straight from downstream and I'm ready for your comments.
Fenglin Wu (6):
pwm: Add different PWM output types support
pwm: core: Add option to config PWM duty/period with u64 data length
pwm: pwm-qti-lpg: Add PWM driver for QTI LPG module
leds: leds-qti-tri-led: Add LED driver for QTI TRI_LED module
Documentation: Add binding for qti-tri-led
Documentation: Add binding for pwm-qti-lpg
.../bindings/leds/leds-qti-tri-led.txt | 72 + .../devicetree/bindings/pwm/pwm-qti-lpg.txt | 163 +++ drivers/leds/Kconfig | 9 + drivers/leds/Makefile | 1 + drivers/leds/leds-qti-tri-led.c | 640 ++++++++ drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/core.c | 56 +- drivers/pwm/pwm-qti-lpg.c | 1284 +++++++++++++++++ drivers/pwm/sysfs.c | 56 +- include/linux/pwm.h | 144 +- 11 files changed, 2418 insertions(+), 18 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/leds-qti-tri-led.txt create mode 100644 Documentation/devicetree/bindings/pwm/pwm-qti-lpg.txt create mode 100644 drivers/leds/leds-qti-tri-led.c create mode 100644 drivers/pwm/pwm-qti-lpg.c
Signature · 1 line
2.27.0
PATCH 1/6 pwm: Add different PWM output types support
From: Fenglin Wu <[email protected]>
Normally, PWM channel has fixed output until software request to change its settings. There are some PWM devices which their outputs could be changed autonomously according to a predefined pattern programmed in hardware. Add pwm_output_type enum type to identify these two different PWM types and add relevant helper functions to set and get PWM output types and pattern.
--- drivers/pwm/core.c | 26 +++++++++++++++++ drivers/pwm/sysfs.c | 50 ++++++++++++++++++++++++++++++++ include/linux/pwm.h | 69 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+)
drivers/pwm/core.c +26 -0
@@ -304,6 +304,7 @@ int pwmchip_add_with_polarity(struct pwm_chip *chip, pwm->pwm = chip->base + i; pwm->hwpwm = i; pwm->state.polarity = polarity; + pwm->state.output_type =PWM_OUTPUT_FIXED ;radix_tree_insert (&pwm_tree, pwm->pwm, pwm); }
@@ -627,6 +628,31 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state) pwm->state.polarity = state->polarity; } +if (state->output_type != pwm->state.output_type) { +if (!pwm->chip->ops->set_output_type) +return -ENOTSUPP ; + + err = pwm->chip->ops->set_output_type (pwm->chip, pwm, + state->output_type); +if (err) +return err; + + pwm->state.output_type = state->output_type; + } + +if (state->output_pattern != pwm->state.output_pattern && + state->output_pattern !=NULL ) { +if (!pwm->chip->ops->set_output_pattern) +return -ENOTSUPP ; + + err = pwm->chip->ops->set_output_pattern (pwm->chip, + pwm, state->output_pattern); +if (err) +return err; + + pwm->state.output_pattern = state->output_pattern; + } +if (state->period != pwm->state.period || state->duty_cycle != pwm->state.duty_cycle) { err = chip->ops->config(pwm->chip, pwm,
drivers/pwm/sysfs.c +50 -0
67 lines not on this page · raw message
include/linux/pwm.h +69 -0
105 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH RCC 1/6] pwm: Add different PWM output types support
Hello,
Quoted 3 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Normally, PWM channel has fixed output until software request to change
"fixed" in the sense of "periodic", not "constant", right?
Quoted 5 lines
its settings. There are some PWM devices which their outputs could be changed autonomously according to a predefined pattern programmed in hardware. Add
pwm_output_typeenum type to identify these two different PWM types and add relevant helper functions to set and get PWM output types and pattern.
You write "some devices". Which do you have in mind?
drivers/pwm/sysfs.c
Quoted 5 lines
[...]
drivers/pwm/sysfs.c +0
-0
adapting the sysfs stuff should be done in a separate step.
Quoted 20 lines
drivers/pwm/sysfs.c +16
-0@@ -215,11 +215,60 @@ static ssize_t capture_show(struct device *child,return sprintf (buf,"%u %u\n" , result.period, result.duty_cycle); } +static ssize_t output_type_show (struct device *child, +struct device_attribute *attr, +char *buf) +{ +const struct pwm_device *pwm =child_to_pwm_device (child); +const char *output_type ="unknown" ; +struct pwm_state state; + +pwm_get_state (pwm, &state); +switch (state.output_type) { +case PWM_OUTPUT_FIXED : + output_type ="fixed" ; +break ; +case PWM_OUTPUT_MODULATED : + output_type ="modulated" ; +break ;
drivers/pwm/sysfs.c static ssize_t capture_show(struct device *child, · line 243
Quoted 10 lines
drivers/pwm/sysfs.c +10
-0+default : +break ; + } + +return snprintf (buf,PAGE_SIZE ,"%s\n" , output_type); +} + +static ssize_t output_type_store (struct device *child, +struct device_attribute *attr, +const char *buf,size_t size)
Indention is broken here. Please align to the opening (.
Quoted 59 lines
drivers/pwm/sysfs.c +24
-0+{ +struct pwm_export *export =child_to_pwm_export (child); +struct pwm_device *pwm = export->pwm; +struct pwm_state state; +int ret = -EINVAL ; + +mutex_lock (&export->lock); +pwm_get_state (pwm, &state); +if (sysfs_streq (buf,"fixed" )) + state.output_type =PWM_OUTPUT_FIXED ; +else if (sysfs_streq (buf,"modulated" )) + state.output_type =PWM_OUTPUT_MODULATED ; +else + goto unlock; + + ret =pwm_apply_state (pwm, &state); +unlock: +mutex_unlock (&export->lock); + +return ret ? : size; +} +static DEVICE_ATTR_RW (period);static DEVICE_ATTR_RW (duty_cycle);static DEVICE_ATTR_RW (enable);static DEVICE_ATTR_RW (polarity);static DEVICE_ATTR_RO (capture); +static DEVICE_ATTR_RW (output_type);static struct attribute *pwm_attrs[] = { &dev_attr_period.attr,@@ -227,6 +276,7 @@ static struct attribute *pwm_attrs[] = { &dev_attr_enable.attr, &dev_attr_polarity.attr, &dev_attr_capture.attr, + &dev_attr_output_type.attr, NULL };ATTRIBUTE_GROUPS (pwm);include/linux/pwm.h +12
-0@@ -48,6 +48,29 @@ enum { PWMF_EXPORTED = 1 << 1, }; +/* +* enum pwm_output_type - output type of the PWM signal +* @PWM_OUTPUT_FIXED: PWM output is fixed until a change request +* @PWM_OUTPUT_MODULATED: PWM output is modulated in hardware +* autonomously with a predefined pattern +*/ +enum pwm_output_type { +PWM_OUTPUT_FIXED =1 <<0 , +PWM_OUTPUT_MODULATED =1 <<1 , +}; + +/*
include/linux/pwm.h enum { · line 72
Quoted 10 lines
include/linux/pwm.h +10
-0+* struct pwm_output_pattern - PWM duty pattern for MODULATED duty type +* @duty_pattern: PWM duty cycles in the pattern for duty modulation +* @num_entries: number of entries in the pattern +* @cycles_per_duty: number of PWM period cycles an entry stays at +*/ +struct pwm_output_pattern { +unsigned int *duty_pattern; +unsigned int num_entries; +unsigned int cycles_per_duty; +};
I don't understand the semantics here. (i.e. how does a given pwm_output_pattern map to the intended wave form?)
Quoted 25 lines
include/linux/pwm.h +11
-0+/* * struct pwm_state - state of a PWM channel * @period: PWM period (in nanoseconds) @@ -59,6 +82,8 @@ struct pwm_state {unsigned int period;unsigned int duty_cycle;enum pwm_polarity polarity; +enum pwm_output_type output_type; +struct pwm_output_pattern *output_pattern;bool enabled; };@@ -146,6 +171,26 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)return state.polarity; } +static inline enum pwm_output_type pwm_get_output_type ( +const struct pwm_device *pwm) +{ +struct pwm_state state; + +pwm_get_state (pwm, &state); + +return state.output_type;
include/linux/pwm.h static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) · line 191
Quoted 10 lines
include/linux/pwm.h +10
-0+} + +static inline struct pwm_output_pattern *pwm_get_output_pattern ( +struct pwm_device *pwm) +{ +struct pwm_state state; + +pwm_get_state (pwm, &state); + +return pwm->state.output_pattern ?:NULL ;
Who is the owner of the data behind this pointer? Is it expected to be valid only until the next call to change the output? What happens if the caller modifies the data returned?
Quoted 16 lines
include/linux/pwm.h +5
-0+} +static inline void pwm_get_args (const struct pwm_device *pwm,struct pwm_args *args) {@@ -254,6 +299,9 @@ pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,* @set_polarity: configure the polarity of this PWM * @enable: enable PWM output toggling * @disable: disable PWM output toggling +* @get_output_type_supported: get the supported output type +* @set_output_type: set PWM output type +* @set_output_pattern: set the pattern for the modulated output */ struct pwm_ops {int (*request)(struct pwm_chip *chip,struct pwm_device *pwm);
include/linux/pwm.h struct pwm_ops { · line 330
Quoted 10 lines
include/linux/pwm.h +7
-0@@ -273,6 +321,13 @@ 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 (*get_output_type_supported)(struct pwm_chip *chip, +struct pwm_device *pwm); +int (*set_output_type)(struct pwm_chip *chip,struct pwm_device *pwm, +enum pwm_output_type output_type); +int (*set_output_pattern)(struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_output_pattern *output_pattern);
This doesn't match the atomic approach that we're following since the introduction of .apply. Please don't add new non-atomic callbacks.
Quoted 10 lines
include/linux/pwm.h +3
-0};/** @@ -318,6 +373,20 @@ void pwm_free(struct pwm_device *pwm);int pwm_apply_state (struct pwm_device *pwm,const struct pwm_state *state);int pwm_adjust_config (struct pwm_device *pwm); +/* +* pwm_output_type_support() +* @pwm: PWM device
include/linux/pwm.h void pwm_free(struct pwm_device *pwm); · line 388
Quoted 10 lines
include/linux/pwm.h +10
-0+* +* Returns: output types supported by the PWM device +*/ +static inline int pwm_get_output_type_supported (struct pwm_device *pwm) +{ +if (pwm->chip->ops->get_output_type_supported !=NULL ) +return pwm->chip->ops->get_output_type_supported (pwm->chip, pwm); +else +return PWM_OUTPUT_FIXED ; +}
I don't like this "advertising" for specific functions. I'd prefer to handle this in .apply(), fix all drivers to return -ESOMETHING when the request cannot be fulfilled.
Having said that I wonder if this output pattern is a common enough property to add support for it in the PWM framework.
If the only usage is to drive a LED this might maybe better be a dedicated LED driver? (Though I'm not sure this is a good idea either.)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH RCC 1/6] pwm: Add different PWM output types support
Quoted 9 lines · Mo 27. 7. 2020 at 22:10 Uwe Kleine-König <[email protected]> wrote:
Hello,
Quoted 3 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Normally, PWM channel has fixed output until software request to change
"fixed" in the sense of "periodic", not "constant", right?
Correct.
Quoted 8 lines
Quoted 6 lines
its settings. There are some PWM devices which their outputs could be changed autonomously according to a predefined pattern programmed in hardware. Add
pwm_output_typeenum type to identify these two different PWM types and add relevant helper functions to set and get PWM output types and pattern.You write "some devices". Which do you have in mind?
As can be seen this commit is not authored by me so the commit message is from the original author.
So i don't know what the original author meant here.
I can only guess that s/he meant all the PWM chips made by Qcom or other companies that also have hardware based support for patterns.
Quoted 8 lines
drivers/pwm/sysfs.c
Quoted 6 lines
[...]
drivers/pwm/sysfs.c +0
-0adapting the sysfs stuff should be done in a separate step.
By that you mean in separate commit right ?
Quoted 25 lines
Quoted 25 lines
drivers/pwm/sysfs.c +20
-0@@ -215,11 +215,60 @@ static ssize_t capture_show(struct device *child,return sprintf (buf,"%u %u\n" , result.period, result.duty_cycle); } +static ssize_t output_type_show (struct device *child, +struct device_attribute *attr, +char *buf) +{ +const struct pwm_device *pwm =child_to_pwm_device (child); +const char *output_type ="unknown" ; +struct pwm_state state; + +pwm_get_state (pwm, &state); +switch (state.output_type) { +case PWM_OUTPUT_FIXED : + output_type ="fixed" ; +break ; +case PWM_OUTPUT_MODULATED : + output_type ="modulated" ; +break ; +default : +break ; + } +
Quoted 8 lines
drivers/pwm/sysfs.c static ssize_t capture_show(struct device *child, · line 243
Quoted 6 lines
drivers/pwm/sysfs.c +6
-0+return snprintf (buf,PAGE_SIZE ,"%s\n" , output_type); +} + +static ssize_t output_type_store (struct device *child, +struct device_attribute *attr, +const char *buf,size_t size)Indention is broken here. Please align to the opening (.
OK. Will do.
Quoted 65 lines
Quoted 65 lines
drivers/pwm/sysfs.c +24
-0+{ +struct pwm_export *export =child_to_pwm_export (child); +struct pwm_device *pwm = export->pwm; +struct pwm_state state; +int ret = -EINVAL ; + +mutex_lock (&export->lock); +pwm_get_state (pwm, &state); +if (sysfs_streq (buf,"fixed" )) + state.output_type =PWM_OUTPUT_FIXED ; +else if (sysfs_streq (buf,"modulated" )) + state.output_type =PWM_OUTPUT_MODULATED ; +else + goto unlock; + + ret =pwm_apply_state (pwm, &state); +unlock: +mutex_unlock (&export->lock); + +return ret ? : size; +} +static DEVICE_ATTR_RW (period);static DEVICE_ATTR_RW (duty_cycle);static DEVICE_ATTR_RW (enable);static DEVICE_ATTR_RW (polarity);static DEVICE_ATTR_RO (capture); +static DEVICE_ATTR_RW (output_type);static struct attribute *pwm_attrs[] = { &dev_attr_period.attr,@@ -227,6 +276,7 @@ static struct attribute *pwm_attrs[] = { &dev_attr_enable.attr, &dev_attr_polarity.attr, &dev_attr_capture.attr, + &dev_attr_output_type.attr, NULL };ATTRIBUTE_GROUPS (pwm);include/linux/pwm.h +17
-0@@ -48,6 +48,29 @@ enum { PWMF_EXPORTED = 1 << 1, }; +/* +* enum pwm_output_type - output type of the PWM signal +* @PWM_OUTPUT_FIXED: PWM output is fixed until a change request +* @PWM_OUTPUT_MODULATED: PWM output is modulated in hardware +* autonomously with a predefined pattern +*/ +enum pwm_output_type { +PWM_OUTPUT_FIXED =1 <<0 , +PWM_OUTPUT_MODULATED =1 <<1 , +}; + +/* +* struct pwm_output_pattern - PWM duty pattern for MODULATED duty type +* @duty_pattern: PWM duty cycles in the pattern for duty modulation +* @num_entries: number of entries in the pattern +* @cycles_per_duty: number of PWM period cycles an entry stays at +*/
Quoted 8 lines
include/linux/pwm.h enum { · line 72
Quoted 5 lines
include/linux/pwm.h +5
-0+struct pwm_output_pattern { +unsigned int *duty_pattern; +unsigned int num_entries; +unsigned int cycles_per_duty; +};I don't understand the semantics here. (i.e. how does a given
pwm_output_patternmap to the intended wave form?)
I did not understand that part either.
It's not uncommon for Qcom to have some stuff hidden like this in other drivers that we have in downstream (Tho they mainly hide that in pre-compiled binary blobs).
Here it's either the missing PBS driver from downstream that i want to send later in separate series.
Or that it's fully done in hardware. Unlikely but you never know with Qcom.
Quoted 87 lines
Quoted 26 lines
include/linux/pwm.h +11
-0+/* * struct pwm_state - state of a PWM channel * @period: PWM period (in nanoseconds) @@ -59,6 +82,8 @@ struct pwm_state {unsigned int period;unsigned int duty_cycle;enum pwm_polarity polarity; +enum pwm_output_type output_type; +struct pwm_output_pattern *output_pattern;bool enabled; };@@ -146,6 +171,26 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)return state.polarity; } +static inline enum pwm_output_type pwm_get_output_type ( +const struct pwm_device *pwm) +{ +struct pwm_state state; + +pwm_get_state (pwm, &state); + +return state.output_type;include/linux/pwm.h static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) · line 191
Quoted 10 lines
include/linux/pwm.h +10
-0+} + +static inline struct pwm_output_pattern *pwm_get_output_pattern ( +struct pwm_device *pwm) +{ +struct pwm_state state; + +pwm_get_state (pwm, &state); + +return pwm->state.output_pattern ?:NULL ;Who is the owner of the data behind this pointer? Is it expected to be valid only until the next call to change the output? What happens if the caller modifies the data returned?
Quoted 16 lines
include/linux/pwm.h +5
-0+} +static inline void pwm_get_args (const struct pwm_device *pwm,struct pwm_args *args) {@@ -254,6 +299,9 @@ pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,* @set_polarity: configure the polarity of this PWM * @enable: enable PWM output toggling * @disable: disable PWM output toggling +* @get_output_type_supported: get the supported output type +* @set_output_type: set PWM output type +* @set_output_pattern: set the pattern for the modulated output */ struct pwm_ops {int (*request)(struct pwm_chip *chip,struct pwm_device *pwm);include/linux/pwm.h struct pwm_ops { · line 330
Quoted 10 lines
include/linux/pwm.h +7
-0@@ -273,6 +321,13 @@ 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 (*get_output_type_supported)(struct pwm_chip *chip, +struct pwm_device *pwm); +int (*set_output_type)(struct pwm_chip *chip,struct pwm_device *pwm, +enum pwm_output_type output_type); +int (*set_output_pattern)(struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_output_pattern *output_pattern);This doesn't match the atomic approach that we're following since the introduction of .apply. Please don't add new non-atomic callbacks.
Quoted 16 lines
include/linux/pwm.h +9
-0};/** @@ -318,6 +373,20 @@ void pwm_free(struct pwm_device *pwm);int pwm_apply_state (struct pwm_device *pwm,const struct pwm_state *state);int pwm_adjust_config (struct pwm_device *pwm); +/* +* pwm_output_type_support() +* @pwm: PWM device +* +* Returns: output types supported by the PWM device +*/ +static inline int pwm_get_output_type_supported (struct pwm_device *pwm) +{ +if (pwm->chip->ops->get_output_type_supported !=NULL )
Quoted 8 lines
include/linux/pwm.h void pwm_free(struct pwm_device *pwm); · line 388
Quoted 4 lines
include/linux/pwm.h +4
-0+return pwm->chip->ops->get_output_type_supported (pwm->chip, pwm); + else + return PWM_OUTPUT_FIXED; +}I don't like this "advertising" for specific functions. I'd prefer to handle this in .apply(), fix all drivers to return
-ESOMETHINGwhen the request cannot be fulfilled.
I will have to disagree on this one. As the functions are called in multiple places it would just make mess in the driver.
As the driver is even now not exactly the definition of clean driver i would not like to make it even more messy.
Quoted 4 lines
Having said that I wonder if this output pattern is a common enough property to add support for it in the PWM framework.
I have gotten an email from Guru Das Srinagesh regarding this exact issue you are pointing to. Yes the output pattern will be dropped in V2.
Best Regards,
Martin
Re: [PATCH RCC 1/6] pwm: Add different PWM output types support
Hello Martin,
Quoted 20 lines · Martin Botka
Quoted 10 lines · Mo 27. 7. 2020 at 22:10 Uwe Kleine-König <[email protected]> wrote:
Quoted 9 lines · Martin Botka
include/linux/pwm.h +9
-0+/* +* pwm_output_type_support() +* @pwm: PWM device +* +* Returns: output types supported by the PWM device +*/ +static inline int pwm_get_output_type_supported (struct pwm_device *pwm) +{ +if (pwm->chip->ops->get_output_type_supported !=NULL )Quoted 8 lines
include/linux/pwm.h void pwm_free(struct pwm_device *pwm); · line 388
Quoted 4 lines
include/linux/pwm.h +4
-0+return pwm->chip->ops->get_output_type_supported (pwm->chip, pwm); + else + return PWM_OUTPUT_FIXED; +}I don't like this "advertising" for specific functions. I'd prefer to handle this in .apply(), fix all drivers to return
-ESOMETHINGwhen the request cannot be fulfilled.
Quoted 2 lines
I will have to disagree on this one. As the functions are called in multiple places it would just make mess in the driver.
Note this is something where (I think) I don't agree with Thierry either. This popped up just yesterday, see
https://www.spinics.net/lists/linux-pwm/msg13290.html
For sure I want at most one such function per driver, so if we really want to go this path and introduce a capability indicator, this should be named differently and have a different prototype.
Quoted 10 lines
As the driver is even now not exactly the definition of clean driver i would not like to make it even more messy.
Quoted 3 lines
Having said that I wonder if this output pattern is a common enough property to add support for it in the PWM framework.
I have gotten an email from Guru Das Srinagesh regarding this exact issue you are pointing to. Yes the output pattern will be dropped in V2.
That's good.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH RCC 1/6] pwm: Add different PWM output types support
In reply to Martin BotkaQuoted 9 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Normally, PWM channel has fixed output until software request to change its settings. There are some PWM devices which their outputs could be changed autonomously according to a predefined pattern programmed in hardware. Add
pwm_output_typeenum type to identify these two different PWM types and add relevant helper functions to set and get PWM output types and pattern.
Quoted 4 lines
Signed-off-by Fenglin Wu <[email protected]>[[email protected]: Fast-forward from kernel 4.14 to 5.8]Signed-off-by Konrad Dybcio <[email protected]>Signed-off-by Martin Botka <[email protected]>
Hello,
Re-sending my reply as somehow the cc-fields got dropped when I posted earlier.
This was the feedback received from the maintainers when I posted this patch last year [1]. Accordingly, we updated the patch to drop "output_pattern" altogether and made "output_type" read-only [2] - haven't attempted upstreaming this version yet.
[1]: https://lore.kernel.org/lkml/20190916140146.GC7488@ulmo/
[2]: https://android-review.googlesource.com/c/kernel/common/+/1170135
Thank you.
Guru Das.
RFC PATCH 2/6 pwm: core: Add option to config PWM duty/period with u64 data length
In reply to Martin BotkaFrom: Fenglin Wu <[email protected]>
Currently, PWM core driver provides interfaces for configuring PWM period and duty length in nanoseconds with an integer data type, so the max period can be only set to ~2.147 seconds. Add interfaces which can set PWM period and duty with u64 data type to remove this limitation.
--- drivers/pwm/core.c | 30 +++++++++++------ drivers/pwm/sysfs.c | 6 ++-- include/linux/pwm.h | 79 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 95 insertions(+), 20 deletions(-)
drivers/pwm/core.c +20 -10
@@ -511,12 +511,12 @@ static void pwm_apply_state_debug(struct pwm_device *pwm, last->period > s2.period && last->period <= state->period)dev_warn (chip->dev, -".apply didn't pick the best available period (requested: %u, applied: %u, possible: %u)\n" , +".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n" , state->period, s2.period, last->period);if (state->enabled && state->period < s2.period)dev_warn (chip->dev, -".apply is supposed to round down period (requested: %u, applied: %u)\n" , +".apply is supposed to round down period (requested: %llu, applied: %llu)\n" , state->period, s2.period); if (state->enabled &&
@@ -525,14 +525,14 @@ static void pwm_apply_state_debug(struct pwm_device *pwm, last->duty_cycle > s2.duty_cycle && last->duty_cycle <= state->duty_cycle)dev_warn (chip->dev, -".apply didn't pick the best available duty cycle (requested: %u/%u, applied: %u/%u, possible: %u/%u)\n" , +".apply didn't pick the best available duty cycle (requested: %llu/%llu, applied: %llu/%llu, possible: %llu/%llu)\n" , state->duty_cycle, state->period, s2.duty_cycle, s2.period, last->duty_cycle, last->period);if (state->enabled && state->duty_cycle < s2.duty_cycle)dev_warn (chip->dev, -".apply is supposed to round down duty_cycle (requested: %u/%u, applied: %u/%u)\n" , +".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n" , state->duty_cycle, state->period, s2.duty_cycle, s2.period);
@@ -559,7 +559,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm, (s1.enabled && s1.period != last->period) || (s1.enabled && s1.duty_cycle != last->duty_cycle)) {dev_err (chip->dev, -".apply is not idempotent (ena=%d pol=%d %u/%u) -> (ena=%d pol=%d %u/%u)\n" , +".apply is not idempotent (ena=%d pol=%d %llu/%llu) -> (ena=%d pol=%d %llu/%llu)\n" , s1.enabled, s1.polarity, s1.duty_cycle, s1.period, last->enabled, last->polarity, last->duty_cycle, last->period);
@@ -655,9 +655,19 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)if (state->period != pwm->state.period || state->duty_cycle != pwm->state.duty_cycle) { - err = chip->ops->config (pwm->chip, pwm, - state->duty_cycle, - state->period); +if (pwm->chip->ops->config_extend) { + err = pwm->chip->ops->config_extend (pwm->chip, + pwm, state->duty_cycle, + state->period); + }else { +if (state->period >UINT_MAX ) +pr_warn ("period %llu duty_cycle %llu will be truncated\n" , + state->period, + state->duty_cycle); + err = pwm->chip->ops->config (pwm->chip, pwm, + state->duty_cycle, + state->period); + }if (err)return err;
@@ -1310,8 +1320,8 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)if (state.enabled)seq_puts (s," enabled" ); -seq_printf (s," period: %u ns" , state.period); -seq_printf (s," duty: %u ns" , state.duty_cycle); +seq_printf (s," period: %llu ns" , state.period); +seq_printf (s," duty: %llu ns" , state.duty_cycle);seq_printf (s," polarity: %s" , state.polarity ?"inverse" :"normal" );
drivers/pwm/sysfs.c +3 -3
@@ -42,7 +42,7 @@ static ssize_t period_show(struct device *child,pwm_get_state (pwm, &state); -return sprintf (buf,"%u\n" , state.period); +return sprintf (buf,"%llu\n" , state.period); } static ssize_t period_store(struct device *child,
@@ -77,7 +77,7 @@ static ssize_t duty_cycle_show(struct device *child,pwm_get_state (pwm, &state); -return sprintf (buf,"%u\n" , state.duty_cycle); +return sprintf (buf,"%llu\n" , state.duty_cycle); } static ssize_t duty_cycle_store(struct device *child,
@@ -212,7 +212,7 @@ static ssize_t capture_show(struct device *child,if (ret)return ret; -return sprintf (buf,"%u %u\n" , result.period, result.duty_cycle); +return sprintf (buf,"%llu %llu\n" , result.period, result.duty_cycle); } static ssize_t output_type_show(struct device *child,
include/linux/pwm.h +72 -7
146 lines not on this page · raw message
Signature · 1 line
2.27.0
kernel test robot
build botRe: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Martin,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on pavel-linux-leds/for-next]
[also build test ERROR on v5.8-rc6]
[cannot apply to pwm/for-next j.anaszewski-leds/for-next next-20200724] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Martin-Botka/Add-QCOM-pwm-lpg-and-tri-led-drivers/20200725-054120 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next config: i386-randconfig-s001-20200724 (attached as .config) compiler: gcc-9 (Debian 9.3.0-14) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-93-g4c6cbe55-dirty # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
ERROR: modpost: "__udivdi3" [drivers/video/backlight/pwm_bl.ko] undefined!
>> ERROR: modpost: "__udivdi3" [drivers/pwm/pwm-iqs620a.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
In reply to Martin Botka[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Martin,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on pavel-linux-leds/for-next]
[also build test ERROR on v5.8-rc6]
[cannot apply to pwm/for-next j.anaszewski-leds/for-next next-20200724] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Martin-Botka/Add-QCOM-pwm-lpg-and-tri-led-drivers/20200725-054120 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next config: arm-randconfig-r034-20200724 (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "__udivdi3" [drivers/video/backlight/pwm_bl.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
In reply to Martin BotkaHello,
As can be seen this divides llu by llu in few warnings and error. At the time of sending i didn't realize it but this fails on 32 bit architectures.
So i would like to ask how would you like this fixed ? Using macro or some other way ?
Thank you.
Best regards,
Martin
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Hi!
Quoted 6 lines
As can be seen this divides llu by llu in few warnings and error. At the time of sending i didn't realize it but this fails on 32 bit architectures.
So i would like to ask how would you like this fixed ? Using macro or some other way ?
+#include <linux/math64.h>
- gain_q23 = (gain_q23 * dmic->boost_gain) / 100;
+ gain_q23 = div_u64(gain_q23 * dmic->boost_gain, 100);
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Review
Quoted 3 lines
(quoted diff) +2
-1+#include <linux/math64.h> - gain_q23 = (gain_q23 * dmic->boost_gain) / 100; + gain_q23 = div_u64(gain_q23 * dmic->boost_gain, 100);
Ok so using a macro.
Thank you.
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
In reply to Martin BotkaQuoted 8 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Currently, PWM core driver provides interfaces for configuring PWM period and duty length in nanoseconds with an integer data type, so the max period can be only set to ~2.147 seconds. Add interfaces which can set PWM period and duty with u64 data type to remove this limitation.
And all divisions go mad on 32-bit CPU, right?
Please, if you thought about it carefully, update a commit message to clarify that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Quoted 3 lines
And all divisions go mad on 32-bit CPU, right?
Please, if you thought about it carefully, update a commit message to clarify that.
Hello,
This patch will be dropped in V2 since another series already made these u64. See a9d887dc1c60ed67f2271d66560cdcf864c4a578 in linux-next.
I have not tested compiling that commit in linux-next on 32 bit arch but if it fails i can replace this commit with fix for that.
Also I'm not the author of this commit.
Konrad Dybcio fast forwarded it to 5.8 from 4.14. Fenglin Wu is the author and also created that commit message.
Thank you.
Best regards
Martin
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Hello Uwe,
Quoted 8 lines · Martin Botka
Quoted 5 lines
Quoted 2 lines
Note there is already a series that changes these values to u64. See
a9d887dc1c60ed67f2271d66560cdcf864c4a578in linux-next.Amazing. But isn't there the same issue with it as this one where this would fail to build on 32 bit architecture?
In theory all these cases are coped for. I didn't see any problems yet, so I still assume also the 32 bit archs are fine.
OK then all is fine. I will drop the patch in V2.
Also Uwe i just realized that you sent the original message and also this reply only to me and not to anyone else.
Could you please send the messages also to everyone else ?
Thank you.
Best regards,
Martin
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Quoted 1 line
Could you please send the messages also to everyone else ?
Next time of course.
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
In reply to Martin BotkaHello Martin,
Quoted 7 lines · Martin Botka
Quoted 6 lines · Martin Botka
Quoted 5 lines
Quoted 2 lines
Note there is already a series that changes these values to u64. See
a9d887dc1c60ed67f2271d66560cdcf864c4a578in linux-next.Amazing. But isn't there the same issue with it as this one where this would fail to build on 32 bit architecture?
Quoted 8 lines
Quoted 2 lines
In theory all these cases are coped for. I didn't see any problems yet, so I still assume also the 32 bit archs are fine.
OK then all is fine. I will drop the patch in V2.
Also Uwe i just realized that you sent the original message and also this reply only to me and not to anyone else.
Could you please send the messages also to everyone else ?
I hit "reply-to-all" and the mail only was sent to you because you wrote to only me.
Also threading is somehow strange because your reply to my mail (with
Message-Id: [email protected]
) has
In-Reply-To: <CADQ2G_HkiAZx8OhfQ_jeizveMaB-QN9dfN6Tcwfk9XuF97rmOg@mail.gmail.com>
. So I assume all the strange things happened on your side until proved otherwise. :-)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Hello,
Quoted 2 lines
I hit "reply-to-all" and the mail only was sent to you because you wrote to only me.
Yes my reply was only to you. But your original message was sent only to me too. So when i clicked reply to all it was only you as you sent it only to me.
Quoted 1 line
Also threading is somehow strange because your reply to my mail
Yes Gmail would not allow me to reply to your message and also send it to everyone so i had to reply to Andy's email which is why the threading is broken there. Sorry for that.
Quoted 2 lines
So I assume all the strange things happened on your side until proved otherwise. :-)
I think i just proved otherwise :)
Best Regards,
Martin
Re: [PATCH RFC 2/6] pwm: core: Add option to config PWM duty/period with u64 data length
Hello Martin,
Quoted 5 lines · Martin Botka
Quoted 2 lines
I hit "reply-to-all" and the mail only was sent to you because you wrote to only me.
Yes my reply was only to you. But your original message was sent only to me too. So when i clicked reply to all it was only you as you sent it only to me.
Oh indeed. Bummer, and I was so sure to always reply to all :-|
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
RFC PATCH 3/6 pwm: pwm-qti-lpg: Add PWM driver for QTI LPG module
In reply to Martin BotkaFrom: Fenglin Wu <[email protected]>
Add pwm_chip to support QTI LPG module and export LPG channels as PWM devices for consumer drivers' usage.
--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-qti-lpg.c | 1284 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1295 insertions(+) create mode 100644 drivers/pwm/pwm-qti-lpg.c
drivers/pwm/Kconfig +10 -0
@@ -399,6 +399,16 @@ config PWM_RCAR To compile this driver as a module, choose M here: the module will be called pwm-rcar. +config PWM_QTI_LPG + tristate "Qualcomm Technologies, Inc. LPG driver" + depends on MFD_SPMI_PMIC && OF + help + This driver supports the LPG (Light Pulse Generator) module found in + Qualcomm Technologies, Inc. PMIC chips. Each LPG channel can be + configured to operate in PWM mode to output a fixed amplitude with + variable duty cycle or in LUT (Look up table) mode to output PWM + signal with a modulated amplitude. + config PWM_RENESAS_TPU tristate "Renesas TPU PWM support" depends on ARCH_RENESAS || COMPILE_TEST
drivers/pwm/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o obj-$(CONFIG_PWM_RCAR) += pwm-rcar.o +obj-$(CONFIG_PWM_QTI_LPG) += pwm-qti-lpg.o obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o
drivers/pwm/pwm-qti-lpg.c new file +1284 -0
1,284 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH RFC 3/6] pwm: pwm-qti-lpg: Add PWM driver for QTI LPG module
Quoted 41 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Add
pwm_chipto support QTI LPG module and export LPG channels as PWM devices for consumer drivers' usage.Signed-off-by Fenglin Wu <[email protected]>[[email protected]: Fast-forward the driver from kernel 4.14 to 5.8]Signed-off-by Martin Botka <[email protected]>--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-qti-lpg.c | 1284 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1295 insertions(+) create mode 100644 drivers/pwm/pwm-qti-lpg.cdrivers/pwm/Kconfig +10
-0@@ -399,6 +399,16 @@ config PWM_RCAR To compile this driver as a module, choose M here: the module will be called pwm-rcar. +config PWM_QTI_LPG + tristate "Qualcomm Technologies, Inc. LPG driver" + depends on MFD_SPMI_PMIC && OF + help + This driver supports the LPG (Light Pulse Generator) module found in + Qualcomm Technologies, Inc. PMIC chips. Each LPG channel can be + configured to operate in PWM mode to output a fixed amplitude with + variable duty cycle or in LUT (Look up table) mode to output PWM + signal with a modulated amplitude. + config PWM_RENESAS_TPU tristate "Renesas TPU PWM support" depends on ARCH_RENESAS || COMPILE_TESTdrivers/pwm/Makefile +0
-0
drivers/pwm/Makefile obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o · line 40
Quoted 4 lines
drivers/pwm/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o obj-$(CONFIG_PWM_RCAR) += pwm-rcar.o +obj-$(CONFIG_PWM_QTI_LPG) += pwm-qti-lpg.o
Please keep this list alphabetically sorted.
Quoted 9 lines
drivers/pwm/Makefile +0
-0obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.odrivers/pwm/pwm-qti-lpg.c new file +0
-0
drivers/pwm/pwm-qti-lpg.c line 6
Quoted 6 lines
drivers/pwm/pwm-qti-lpg.c new file +6
-0@@ -0,0 +1,1284 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2020, The Linux Foundation. All rights reserved. +*/ + +#define pr_fmt (fmt) "%s: " fmt, __func__
This smells like debug stuff. Please drop this.
Quoted 93 lines
drivers/pwm/pwm-qti-lpg.c new file +93
-0+#include <linux/bitops.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/pwm.h> +#include <linux/regmap.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/types.h> + +#define REG_SIZE_PER_LPG 0x100 +#define LPG_BASE "lpg-base" +#define LUT_BASE "lut-base" + +/* LPG module registers */ +#define REG_LPG_PERPH_SUBTYPE 0x05 +#define REG_LPG_PATTERN_CONFIG 0x40 +#define REG_LPG_PWM_SIZE_CLK 0x41 +#define REG_LPG_PWM_FREQ_PREDIV_CLK 0x42 +#define REG_LPG_PWM_TYPE_CONFIG 0x43 +#define REG_LPG_PWM_VALUE_LSB 0x44 +#define REG_LPG_PWM_VALUE_MSB 0x45 +#define REG_LPG_ENABLE_CONTROL 0x46 +#define REG_LPG_PWM_SYNC 0x47 +#define REG_LPG_RAMP_STEP_DURATION_LSB 0x50 +#define REG_LPG_RAMP_STEP_DURATION_MSB 0x51 +#define REG_LPG_PAUSE_HI_MULTIPLIER 0x52 +#define REG_LPG_PAUSE_LO_MULTIPLIER 0x54 +#define REG_LPG_HI_INDEX 0x56 +#define REG_LPG_LO_INDEX 0x57 + +/* REG_LPG_PATTERN_CONFIG */ +#define LPG_PATTERN_EN_PAUSE_LO BIT(0) +#define LPG_PATTERN_EN_PAUSE_HI BIT(1) +#define LPG_PATTERN_RAMP_TOGGLE BIT(2) +#define LPG_PATTERN_REPEAT BIT(3) +#define LPG_PATTERN_RAMP_LO_TO_HI BIT(4) + +/* REG_LPG_PERPH_SUBTYPE */ +#define SUBTYPE_PWM 0x0b +#define SUBTYPE_LPG_LITE 0x11 + +/* REG_LPG_PWM_SIZE_CLK */ +#define LPG_PWM_SIZE_LPG_MASK BIT(4) +#define LPG_PWM_SIZE_PWM_MASK BIT(2) +#define LPG_PWM_SIZE_LPG_SHIFT 4 +#define LPG_PWM_SIZE_PWM_SHIFT 2 +#define LPG_PWM_CLK_FREQ_SEL_MASK GENMASK(1, 0) + +/* REG_LPG_PWM_FREQ_PREDIV_CLK */ +#define LPG_PWM_FREQ_PREDIV_MASK GENMASK(6, 5) +#define LPG_PWM_FREQ_PREDIV_SHIFT 5 +#define LPG_PWM_FREQ_EXPONENT_MASK GENMASK(2, 0) + +/* REG_LPG_PWM_TYPE_CONFIG */ +#define LPG_PWM_EN_GLITCH_REMOVAL_MASK BIT(5) + +/* REG_LPG_PWM_VALUE_LSB */ +#define LPG_PWM_VALUE_LSB_MASK GENMASK(7, 0) + +/* REG_LPG_PWM_VALUE_MSB */ +#define LPG_PWM_VALUE_MSB_MASK BIT(0) + +/* REG_LPG_ENABLE_CONTROL */ +#define LPG_EN_LPG_OUT_BIT BIT(7) +#define LPG_EN_LPG_OUT_SHIFT 7 +#define LPG_PWM_SRC_SELECT_MASK BIT(2) +#define LPG_PWM_SRC_SELECT_SHIFT 2 +#define LPG_EN_RAMP_GEN_MASK BIT(1) +#define LPG_EN_RAMP_GEN_SHIFT 1 + +/* REG_LPG_PWM_SYNC */ +#define LPG_PWM_VALUE_SYNC BIT(0) + +#define NUM_PWM_SIZE 2 +#define NUM_PWM_CLK 3 +#define NUM_CLK_PREDIV 4 +#define NUM_PWM_EXP 8 + +#define LPG_HI_LO_IDX_MASK GENMASK(5, 0) + +/* LUT module registers */ +#define REG_LPG_LUT_1_LSB 0x42 +#define REG_LPG_LUT_RAMP_CONTROL 0xc8 + +#define LPG_LUT_VALUE_MSB_MASK BIT(0) +#define LPG_LUT_COUNT_MAX 47
drivers/pwm/pwm-qti-lpg.c line 110
Quoted 10 lines
drivers/pwm/pwm-qti-lpg.c new file +10
-0+ +enum lpg_src { +LUT_PATTERN =0 , +PWM_VALUE , +}; + +static const int pwm_size[NUM_PWM_SIZE ] = {6 ,9 }; +static const int clk_freq_hz[NUM_PWM_CLK ] = {1024 ,32768 ,19200000 }; +static const int clk_prediv[NUM_CLK_PREDIV ] = {1 ,3 ,5 ,6 }; +static const int pwm_exponent[NUM_PWM_EXP ] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 };
I don't know what the compiler makes of these arrays, but the last one at least can be replaces by some simple math.
drivers/pwm/pwm-qti-lpg.c line 242
Quoted 13 lines
drivers/pwm/pwm-qti-lpg.c new file +13
-0+static int qpnp_lut_masked_write (struct qpnp_lpg_lut *lut,u16 addr,u8 mask, +u8 val) +{ +int rc; + +mutex_lock (&lut->chip->bus_lock); + rc =regmap_update_bits (lut->chip->regmap, lut->reg_base + addr, mask, + val); +if (rc <0 ) +dev_err (lut->chip->dev, +"Update addr 0x%x to val 0x%x with mask 0x%x failed, rc=%d\n" , + lut->reg_base + addr, val, mask, rc); +mutex_unlock (&lut->chip->bus_lock);
The error logging can be moved out of the lock.
Quoted 33 lines
drivers/pwm/pwm-qti-lpg.c new file +33
-0+ +return rc; +} + +static struct qpnp_lpg_channel *pwm_dev_to_qpnp_lpg (struct pwm_chip *pwm_chip, +struct pwm_device *pwm) +{ +struct qpnp_lpg_chip *chip = + container_of(pwm_chip, struct qpnp_lpg_chip, pwm_chip); +u32 hw_idx = pwm->hwpwm; + +if (hw_idx >= chip->num_lpgs) { +dev_err (chip->dev,"hw index %d out of range [0-%d]\n" , hw_idx, + chip->num_lpgs -1 ); +return NULL ; + } + +return &chip->lpgs[hw_idx]; +} + +static int __find_index_in_array (int member,const int array[],int length) +{ +int i; + +for (i =0 ; i < length; i++) { +if (member == array[i]) +return i; + } + +return -EINVAL ; +} + +static int qpnp_lpg_set_glitch_removal (struct qpnp_lpg_channel *lpg,bool en)
drivers/pwm/pwm-qti-lpg.c line 285
Quoted 10 lines
drivers/pwm/pwm-qti-lpg.c new file +10
-0+{ +int rc; +u8 mask, val; + + val = en ?LPG_PWM_EN_GLITCH_REMOVAL_MASK :0 ; + mask =LPG_PWM_EN_GLITCH_REMOVAL_MASK ; + rc =qpnp_lpg_masked_write (lpg,REG_LPG_PWM_TYPE_CONFIG , mask, val); +if (rc <0 ) +dev_err (lpg->chip->dev, +"Write LPG_PWM_TYPE_CONFIG failed, rc=%d\n" , rc);
qpnp_lpg_masked_write already issues a warning.
drivers/pwm/pwm-qti-lpg.c line 962
Quoted 12 lines
drivers/pwm/pwm-qti-lpg.c new file +11
-0+return rc; +} + +static const struct pwm_ops qpnp_lpg_pwm_ops = { + .config = qpnp_lpg_pwm_config, + .config_extend = qpnp_lpg_pwm_config_extend, + .get_output_type_supported = qpnp_lpg_pwm_output_types_supported, + .set_output_type = qpnp_lpg_pwm_set_output_type, + .set_output_pattern = qpnp_lpg_pwm_set_output_pattern, + .enable = qpnp_lpg_pwm_enable, + .disable = qpnp_lpg_pwm_disable,
As already noted in the former patch: Please implement .apply() and .get_state().
Quoted 24 lines
drivers/pwm/pwm-qti-lpg.c new file +24
-0+ .owner = THIS_MODULE, +}; + +static int qpnp_lpg_parse_dt (struct qpnp_lpg_chip *chip) +{ +struct device_node *child; +struct qpnp_lpg_channel *lpg; +struct lpg_ramp_config *ramp; +int rc =0 , i; +u32 base, length, lpg_chan_id, tmp; +const __be32 *addr; + + addr =of_get_address (chip->dev->of_node,0 ,NULL ,NULL ); +if (!addr) { +dev_err (chip->dev,"Get %s address failed\n" ,LPG_BASE ); +return -EINVAL ; + } + + base =be32_to_cpu (addr[0 ]); + rc =of_property_read_u32 (chip->dev->of_node,"qcom,num-lpg-channels" , + &chip->num_lpgs); +if (rc <0 ) { +dev_err (chip->dev, +"Failed to get qcom,num-lpg-channels, rc=%d\n" , rc);
drivers/pwm/pwm-qti-lpg.c line 996
Quoted 10 lines
drivers/pwm/pwm-qti-lpg.c new file +10
-0+return rc; + } + +if (chip->num_lpgs ==0 ) { +dev_err (chip->dev,"No LPG channels specified\n" ); +return -EINVAL ; + } + + chip->lpgs =devm_kcalloc (chip->dev, chip->num_lpgs, +sizeof (*chip->lpgs),GFP_KERNEL );
Would be great to lower the number of allocations - ideally to one at probe time.
Quoted 252 lines
drivers/pwm/pwm-qti-lpg.c new file +252
-0+if (!chip->lpgs) +return -ENOMEM ; + +for (i =0 ; i < chip->num_lpgs; i++) { + chip->lpgs[i].chip = chip; + chip->lpgs[i].lpg_idx = i; + chip->lpgs[i].reg_base = base + i *REG_SIZE_PER_LPG ; + chip->lpgs[i].src_sel =PWM_VALUE ; + rc =qpnp_lpg_read (&chip->lpgs[i],REG_LPG_PERPH_SUBTYPE , + &chip->lpgs[i].subtype); +if (rc <0 ) { +dev_err (chip->dev,"Read subtype failed, rc=%d\n" , rc); +return rc; + } + } + + addr =of_get_address (chip->dev->of_node,1 ,NULL ,NULL ); +if (!addr) { +pr_debug ("NO LUT address assigned\n" ); +return 0 ; + } + + chip->lut =devm_kmalloc (chip->dev,sizeof (*chip->lut),GFP_KERNEL ); +if (!chip->lut) +return -ENOMEM ; + + chip->lut->chip = chip; + chip->lut->reg_base =be32_to_cpu (*addr); +mutex_init (&chip->lut->lock); + + rc =of_property_count_elems_of_size (chip->dev->of_node, +"qcom,lut-patterns" ,sizeof (u32)); +if (rc <0 ) { +dev_err (chip->dev,"Read qcom,lut-patterns failed, rc=%d\n" , + rc); +return rc; + } + + length = rc; +if (length >LPG_LUT_COUNT_MAX ) { +dev_err (chip->dev, +"qcom,lut-patterns length %d exceed max %d\n" , length, +LPG_LUT_COUNT_MAX ); +return -EINVAL ; + } + + chip->lut->pattern = +devm_kcalloc (chip->dev,LPG_LUT_COUNT_MAX , +sizeof (*chip->lut->pattern),GFP_KERNEL ); +if (!chip->lut->pattern) +return -ENOMEM ; + + rc =of_property_read_u32_array (chip->dev->of_node,"qcom,lut-patterns" , + chip->lut->pattern, length); +if (rc <0 ) { +dev_err (chip->dev,"Get qcom,lut-patterns failed, rc=%d\n" , rc); +return rc; + } + +if (of_get_available_child_count (chip->dev->of_node) ==0 ) { +dev_err (chip->dev,"No ramp configuration for any LPG\n" ); +return -EINVAL ; + } + + for_each_available_child_of_node (chip->dev->of_node, child) { + rc =of_property_read_u32 (child,"qcom,lpg-chan-id" , + &lpg_chan_id); +if (rc <0 ) { +dev_err (chip->dev, +"Get qcom,lpg-chan-id failed for node %s, rc=%d\n" , + child->name, rc); +return rc; + } + +if (lpg_chan_id > chip->num_lpgs) { +dev_err (chip->dev, +"lpg-chann-id %d is out of range 1~%d\n" , + lpg_chan_id, chip->num_lpgs); +return -EINVAL ; + } + +/* lpg channel id is indexed from 1 in hardware */ + lpg = &chip->lpgs[lpg_chan_id -1 ]; + ramp = &lpg->ramp_config; + + rc =of_property_read_u32 (child,"qcom,ramp-step-ms" , &tmp); +if (rc <0 ) { +dev_err (chip->dev, +"get qcom,ramp-step-ms failed for lpg%d, rc=%d\n" , + lpg_chan_id, rc); +return rc; + } + ramp->step_ms = (u16 )tmp; + + rc =of_property_read_u32 (child,"qcom,ramp-low-index" , &tmp); +if (rc <0 ) { +dev_err (chip->dev, +"get qcom,ramp-low-index failed for lpg%d, rc=%d\n" , + lpg_chan_id, rc); +return rc; + } + ramp->lo_idx = (u8 )tmp; +if (ramp->lo_idx >=LPG_LUT_COUNT_MAX ) { +dev_err (chip->dev, +"qcom,ramp-low-index should less than max %d\n" , +LPG_LUT_COUNT_MAX ); +return -EINVAL ; + } + + rc =of_property_read_u32 (child,"qcom,ramp-high-index" , &tmp); +if (rc <0 ) { +dev_err (chip->dev, +"get qcom,ramp-high-index failed for lpg%d, rc=%d\n" , + lpg_chan_id, rc); +return rc; + } + ramp->hi_idx = (u8 )tmp; + +if (ramp->hi_idx >LPG_LUT_COUNT_MAX ) { +dev_err (chip->dev, +"qcom,ramp-high-index shouldn't exceed max %d\n" , +LPG_LUT_COUNT_MAX ); +return -EINVAL ; + } + +if (ramp->hi_idx <= ramp->lo_idx) { +dev_err (chip->dev, +"high-index(%d) should be larger than low-index(%d)\n" , + ramp->hi_idx, ramp->lo_idx); +return -EINVAL ; + } + + ramp->pattern_length = ramp->hi_idx - ramp->lo_idx +1 ; + ramp->pattern = &chip->lut->pattern[ramp->lo_idx]; + lpg->max_pattern_length = ramp->pattern_length; + + rc =of_property_read_u32 (child,"qcom,ramp-pause-hi-count" , + &tmp); +if (rc <0 ) + ramp->pause_hi_count =0 ; +else + ramp->pause_hi_count = (u8 )tmp; + + rc =of_property_read_u32 (child,"qcom,ramp-pause-lo-count" , + &tmp); +if (rc <0 ) + ramp->pause_lo_count =0 ; +else + ramp->pause_lo_count = (u8 )tmp; + + ramp->ramp_dir_low_to_hi =of_property_read_bool ( + child,"qcom,ramp-from-low-to-high" ); + + ramp->pattern_repeat =of_property_read_bool ( + child,"qcom,ramp-pattern-repeat" ); + + ramp->toggle =of_property_read_bool (child,"qcom,ramp-toggle" ); + } + + rc =of_property_count_elems_of_size ( + chip->dev->of_node,"qcom,sync-channel-ids" ,sizeof (u32)); +if (rc <0 ) +return 0 ; + + length = rc; +if (length > chip->num_lpgs) { +dev_err (chip->dev, +"qcom,sync-channel-ids has too many channels: %d\n" , + length); +return -EINVAL ; + } + + chip->lpg_group =devm_kcalloc (chip->dev, chip->num_lpgs,sizeof (u32), +GFP_KERNEL ); +if (!chip->lpg_group) +return -ENOMEM ; + + rc =of_property_read_u32_array (chip->dev->of_node, +"qcom,sync-channel-ids" , + chip->lpg_group, length); +if (rc <0 ) { +dev_err (chip->dev,"Get qcom,sync-channel-ids failed, rc=%d\n" , + rc); +return rc; + } + +for (i =0 ; i < length; i++) { +if (chip->lpg_group[i] <=0 || + chip->lpg_group[i] > chip->num_lpgs) { +dev_err (chip->dev, +"lpg_group[%d]: %d is not a valid channel\n" , i, + chip->lpg_group[i]); +return -EINVAL ; + } + } + +/* +* The LPG channel in the same group should have the same ramping +* configuration, so force to use the ramping configuration of the +* 1st LPG channel in the group for sychronization. +*/ + lpg = &chip->lpgs[chip->lpg_group[0 ] -1 ]; + ramp = &lpg->ramp_config; + +for (i =1 ; i < length; i++) { + lpg = &chip->lpgs[chip->lpg_group[i] -1 ]; +memcpy (&lpg->ramp_config, ramp,sizeof (struct lpg_ramp_config )); + } + +return 0 ; +} + +static int qpnp_lpg_probe (struct platform_device *pdev) +{ +int rc; +struct qpnp_lpg_chip *chip; + + chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->dev = &pdev->dev; + chip->regmap =dev_get_regmap (chip->dev->parent,NULL ); +if (!chip->regmap) { +dev_err (chip->dev,"Getting regmap failed\n" ); +return -EINVAL ; + } + +mutex_init (&chip->bus_lock); + rc =qpnp_lpg_parse_dt (chip); +if (rc <0 ) { +dev_err (chip->dev, +"Devicetree properties parsing failed, rc=%d\n" , rc); + goto err_out; + } + +dev_set_drvdata (chip->dev, chip); + chip->pwm_chip.dev = chip->dev; + chip->pwm_chip.base =-1 ; + chip->pwm_chip.npwm = chip->num_lpgs; + chip->pwm_chip.ops = &qpnp_lpg_pwm_ops; + + rc =pwmchip_add (&chip->pwm_chip); +if (rc <0 ) { +dev_err (chip->dev,"Add pwmchip failed, rc=%d\n" , rc); + goto err_out; + } + +return 0 ; +err_out: +mutex_destroy (&chip->bus_lock); +return rc;
drivers/pwm/pwm-qti-lpg.c line 1258
Quoted 10 lines
drivers/pwm/pwm-qti-lpg.c new file +10
-0+} + +static int qpnp_lpg_remove (struct platform_device *pdev) +{ +struct qpnp_lpg_chip *chip =dev_get_drvdata (&pdev->dev); +int rc =0 ; + + rc =pwmchip_remove (&chip->pwm_chip); +if (rc <0 ) +dev_err (chip->dev,"Remove pwmchip failed, rc=%d\n" , rc);
Please use %pe instead of %d for error codes.
drivers/pwm/pwm-qti-lpg.c line 1261
Quoted 3 lines
drivers/pwm/pwm-qti-lpg.c new file +3
-0+ +mutex_destroy (&chip->bus_lock); +dev_set_drvdata (chip->dev,NULL );
dev_set_drvdata(..., NULL) is not needed.
Quoted 27 lines
drivers/pwm/pwm-qti-lpg.c new file +23
-0+ +return rc; +} + +static const struct of_device_id qpnp_lpg_of_match[] = { + { + .compatible ="qcom,pwm-lpg" , + }, + {}, +}; + +static struct platform_driver qpnp_lpg_driver = { + .driver = { + .name ="qcom,pwm-lpg" , + .of_match_table = qpnp_lpg_of_match, + }, + .probe = qpnp_lpg_probe, + .remove = qpnp_lpg_remove, +}; +module_platform_driver (qpnp_lpg_driver); + +MODULE_DESCRIPTION ("QTI LPG driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.27.0
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH RFC 3/6] pwm: pwm-qti-lpg: Add PWM driver for QTI LPG module
Hello,
Quoted 41 lines · Mo 27. 7. 2020 at 22:10 Uwe Kleine-König <[email protected]> wrote:
Quoted 39 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Add
pwm_chipto support QTI LPG module and export LPG channels as PWM devices for consumer drivers' usage.Signed-off-by Fenglin Wu <[email protected]>[[email protected]: Fast-forward the driver from kernel 4.14 to 5.8]Signed-off-by Martin Botka <[email protected]>--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-qti-lpg.c | 1284 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1295 insertions(+) create mode 100644 drivers/pwm/pwm-qti-lpg.cdrivers/pwm/Kconfig +10
-0@@ -399,6 +399,16 @@ config PWM_RCAR To compile this driver as a module, choose M here: the module will be called pwm-rcar. +config PWM_QTI_LPG + tristate "Qualcomm Technologies, Inc. LPG driver" + depends on MFD_SPMI_PMIC && OF + help + This driver supports the LPG (Light Pulse Generator) module found in + Qualcomm Technologies, Inc. PMIC chips. Each LPG channel can be + configured to operate in PWM mode to output a fixed amplitude with + variable duty cycle or in LUT (Look up table) mode to output PWM + signal with a modulated amplitude. + config PWM_RENESAS_TPU tristate "Renesas TPU PWM support" depends on ARCH_RENESAS || COMPILE_TESTdrivers/pwm/Makefile +0
-1--- a/drivers/pwm/Makefile
Quoted 8 lines
drivers/pwm/Makefile obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o · line 40
Quoted 6 lines
+++ b/drivers/pwm/Makefile
drivers/pwm/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o obj-$(CONFIG_PWM_RCAR) += pwm-rcar.o +obj-$(CONFIG_PWM_QTI_LPG) += pwm-qti-lpg.oPlease keep this list alphabetically sorted.
OK
Quoted 10 lines
Quoted 10 lines
drivers/pwm/Makefile +0
-0obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.odrivers/pwm/pwm-qti-lpg.c new file +0
-0@@ -0,0 +1,1284 @@
Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c line 6
Quoted 6 lines
drivers/pwm/pwm-qti-lpg.c new file +6
-0+// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2020, The Linux Foundation. All rights reserved. +*/ + +#define pr_fmt (fmt) "%s: " fmt, __func__This smells like debug stuff. Please drop this.
What do you mean ?
The #define pr_fmt(fmt) or the tons of REG definitions ?
Quoted 99 lines
Quoted 99 lines
drivers/pwm/pwm-qti-lpg.c new file +98
-0+#include <linux/bitops.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/pwm.h> +#include <linux/regmap.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/types.h> + +#define REG_SIZE_PER_LPG 0x100 +#define LPG_BASE "lpg-base" +#define LUT_BASE "lut-base" + +/* LPG module registers */ +#define REG_LPG_PERPH_SUBTYPE 0x05 +#define REG_LPG_PATTERN_CONFIG 0x40 +#define REG_LPG_PWM_SIZE_CLK 0x41 +#define REG_LPG_PWM_FREQ_PREDIV_CLK 0x42 +#define REG_LPG_PWM_TYPE_CONFIG 0x43 +#define REG_LPG_PWM_VALUE_LSB 0x44 +#define REG_LPG_PWM_VALUE_MSB 0x45 +#define REG_LPG_ENABLE_CONTROL 0x46 +#define REG_LPG_PWM_SYNC 0x47 +#define REG_LPG_RAMP_STEP_DURATION_LSB 0x50 +#define REG_LPG_RAMP_STEP_DURATION_MSB 0x51 +#define REG_LPG_PAUSE_HI_MULTIPLIER 0x52 +#define REG_LPG_PAUSE_LO_MULTIPLIER 0x54 +#define REG_LPG_HI_INDEX 0x56 +#define REG_LPG_LO_INDEX 0x57 + +/* REG_LPG_PATTERN_CONFIG */ +#define LPG_PATTERN_EN_PAUSE_LO BIT(0) +#define LPG_PATTERN_EN_PAUSE_HI BIT(1) +#define LPG_PATTERN_RAMP_TOGGLE BIT(2) +#define LPG_PATTERN_REPEAT BIT(3) +#define LPG_PATTERN_RAMP_LO_TO_HI BIT(4) + +/* REG_LPG_PERPH_SUBTYPE */ +#define SUBTYPE_PWM 0x0b +#define SUBTYPE_LPG_LITE 0x11 + +/* REG_LPG_PWM_SIZE_CLK */ +#define LPG_PWM_SIZE_LPG_MASK BIT(4) +#define LPG_PWM_SIZE_PWM_MASK BIT(2) +#define LPG_PWM_SIZE_LPG_SHIFT 4 +#define LPG_PWM_SIZE_PWM_SHIFT 2 +#define LPG_PWM_CLK_FREQ_SEL_MASK GENMASK(1, 0) + +/* REG_LPG_PWM_FREQ_PREDIV_CLK */ +#define LPG_PWM_FREQ_PREDIV_MASK GENMASK(6, 5) +#define LPG_PWM_FREQ_PREDIV_SHIFT 5 +#define LPG_PWM_FREQ_EXPONENT_MASK GENMASK(2, 0) + +/* REG_LPG_PWM_TYPE_CONFIG */ +#define LPG_PWM_EN_GLITCH_REMOVAL_MASK BIT(5) + +/* REG_LPG_PWM_VALUE_LSB */ +#define LPG_PWM_VALUE_LSB_MASK GENMASK(7, 0) + +/* REG_LPG_PWM_VALUE_MSB */ +#define LPG_PWM_VALUE_MSB_MASK BIT(0) + +/* REG_LPG_ENABLE_CONTROL */ +#define LPG_EN_LPG_OUT_BIT BIT(7) +#define LPG_EN_LPG_OUT_SHIFT 7 +#define LPG_PWM_SRC_SELECT_MASK BIT(2) +#define LPG_PWM_SRC_SELECT_SHIFT 2 +#define LPG_EN_RAMP_GEN_MASK BIT(1) +#define LPG_EN_RAMP_GEN_SHIFT 1 + +/* REG_LPG_PWM_SYNC */ +#define LPG_PWM_VALUE_SYNC BIT(0) + +#define NUM_PWM_SIZE 2 +#define NUM_PWM_CLK 3 +#define NUM_CLK_PREDIV 4 +#define NUM_PWM_EXP 8 + +#define LPG_HI_LO_IDX_MASK GENMASK(5, 0) + +/* LUT module registers */ +#define REG_LPG_LUT_1_LSB 0x42 +#define REG_LPG_LUT_RAMP_CONTROL 0xc8 + +#define LPG_LUT_VALUE_MSB_MASK BIT(0) +#define LPG_LUT_COUNT_MAX 47 + +enum lpg_src { +LUT_PATTERN =0 , +PWM_VALUE , +};
Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c line 110
Quoted 5 lines
drivers/pwm/pwm-qti-lpg.c new file +5
-0+ +static const int pwm_size[NUM_PWM_SIZE ] = {6 ,9 }; +static const int clk_freq_hz[NUM_PWM_CLK ] = {1024 ,32768 ,19200000 }; +static const int clk_prediv[NUM_CLK_PREDIV ] = {1 ,3 ,5 ,6 }; +static const int pwm_exponent[NUM_PWM_EXP ] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 };I don't know what the compiler makes of these arrays, but the last one at least can be replaces by some simple math.
Yup.
Quoted 16 lines
Quoted 4 lines
drivers/pwm/pwm-qti-lpg.c new file +3
-0+static int qpnp_lut_masked_write (struct qpnp_lpg_lut *lut,u16 addr,u8 mask, +u8 val) +{drivers/pwm/pwm-qti-lpg.c line 242
Quoted 10 lines
drivers/pwm/pwm-qti-lpg.c new file +10
-0+int rc; + +mutex_lock (&lut->chip->bus_lock); + rc =regmap_update_bits (lut->chip->regmap, lut->reg_base + addr, mask, + val); +if (rc <0 ) +dev_err (lut->chip->dev, +"Update addr 0x%x to val 0x%x with mask 0x%x failed, rc=%d\n" , + lut->reg_base + addr, val, mask, rc); +mutex_unlock (&lut->chip->bus_lock);The error logging can be moved out of the lock.
Will do.
Quoted 47 lines
Quoted 34 lines
drivers/pwm/pwm-qti-lpg.c new file +33
-0+ +return rc; +} + +static struct qpnp_lpg_channel *pwm_dev_to_qpnp_lpg (struct pwm_chip *pwm_chip, +struct pwm_device *pwm) +{ +struct qpnp_lpg_chip *chip = + container_of(pwm_chip, struct qpnp_lpg_chip, pwm_chip); +u32 hw_idx = pwm->hwpwm; + +if (hw_idx >= chip->num_lpgs) { +dev_err (chip->dev,"hw index %d out of range [0-%d]\n" , hw_idx, + chip->num_lpgs -1 ); +return NULL ; + } + +return &chip->lpgs[hw_idx]; +} + +static int __find_index_in_array (int member,const int array[],int length) +{ +int i; + +for (i =0 ; i < length; i++) { +if (member == array[i]) +return i; + } + +return -EINVAL ; +} + +static int qpnp_lpg_set_glitch_removal (struct qpnp_lpg_channel *lpg,bool en)drivers/pwm/pwm-qti-lpg.c line 285
Quoted 10 lines
drivers/pwm/pwm-qti-lpg.c new file +10
-0+{ +int rc; +u8 mask, val; + + val = en ?LPG_PWM_EN_GLITCH_REMOVAL_MASK :0 ; + mask =LPG_PWM_EN_GLITCH_REMOVAL_MASK ; + rc =qpnp_lpg_masked_write (lpg,REG_LPG_PWM_TYPE_CONFIG , mask, val); +if (rc <0 ) +dev_err (lpg->chip->dev, +"Write LPG_PWM_TYPE_CONFIG failed, rc=%d\n" , rc);
qpnp_lpg_masked_writealready issues a warning.
Quoted 15 lines
drivers/pwm/pwm-qti-lpg.c line 962
Quoted 12 lines
drivers/pwm/pwm-qti-lpg.c new file +11
-0+return rc; +} + +static const struct pwm_ops qpnp_lpg_pwm_ops = { + .config = qpnp_lpg_pwm_config, + .config_extend = qpnp_lpg_pwm_config_extend, + .get_output_type_supported = qpnp_lpg_pwm_output_types_supported, + .set_output_type = qpnp_lpg_pwm_set_output_type, + .set_output_pattern = qpnp_lpg_pwm_set_output_pattern, + .enable = qpnp_lpg_pwm_enable, + .disable = qpnp_lpg_pwm_disable,As already noted in the former patch: Please implement .apply() and .get_state().
So drop:
.get_output_type_supported = qpnp_lpg_pwm_output_types_supported, .set_output_type = qpnp_lpg_pwm_set_output_type, .set_output_pattern = qpnp_lpg_pwm_set_output_pattern,
Ad implement implement .apply and .get_state if i understood you correctly. Right ?
Quoted 30 lines
Quoted 30 lines
drivers/pwm/pwm-qti-lpg.c new file +29
-0+ .owner = THIS_MODULE, +}; + +static int qpnp_lpg_parse_dt (struct qpnp_lpg_chip *chip) +{ +struct device_node *child; +struct qpnp_lpg_channel *lpg; +struct lpg_ramp_config *ramp; +int rc =0 , i; +u32 base, length, lpg_chan_id, tmp; +const __be32 *addr; + + addr =of_get_address (chip->dev->of_node,0 ,NULL ,NULL ); +if (!addr) { +dev_err (chip->dev,"Get %s address failed\n" ,LPG_BASE ); +return -EINVAL ; + } + + base =be32_to_cpu (addr[0 ]); + rc =of_property_read_u32 (chip->dev->of_node,"qcom,num-lpg-channels" , + &chip->num_lpgs); +if (rc <0 ) { +dev_err (chip->dev, +"Failed to get qcom,num-lpg-channels, rc=%d\n" , rc); +return rc; + } + +if (chip->num_lpgs ==0 ) { +dev_err (chip->dev,"No LPG channels specified\n" );
Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c line 996
Quoted 5 lines
drivers/pwm/pwm-qti-lpg.c new file +5
-0+return -EINVAL ; + } + + chip->lpgs =devm_kcalloc (chip->dev, chip->num_lpgs, +sizeof (*chip->lpgs),GFP_KERNEL );Would be great to lower the number of allocations - ideally to one at probe time.
Hmmmm. Okay.
Quoted 257 lines
Quoted 257 lines
drivers/pwm/pwm-qti-lpg.c new file +256
-0+if (!chip->lpgs) +return -ENOMEM ; + +for (i =0 ; i < chip->num_lpgs; i++) { + chip->lpgs[i].chip = chip; + chip->lpgs[i].lpg_idx = i; + chip->lpgs[i].reg_base = base + i *REG_SIZE_PER_LPG ; + chip->lpgs[i].src_sel =PWM_VALUE ; + rc =qpnp_lpg_read (&chip->lpgs[i],REG_LPG_PERPH_SUBTYPE , + &chip->lpgs[i].subtype); +if (rc <0 ) { +dev_err (chip->dev,"Read subtype failed, rc=%d\n" , rc); +return rc; + } + } + + addr =of_get_address (chip->dev->of_node,1 ,NULL ,NULL ); +if (!addr) { +pr_debug ("NO LUT address assigned\n" ); +return 0 ; + } + + chip->lut =devm_kmalloc (chip->dev,sizeof (*chip->lut),GFP_KERNEL ); +if (!chip->lut) +return -ENOMEM ; + + chip->lut->chip = chip; + chip->lut->reg_base =be32_to_cpu (*addr); +mutex_init (&chip->lut->lock); + + rc =of_property_count_elems_of_size (chip->dev->of_node, +"qcom,lut-patterns" ,sizeof (u32)); +if (rc <0 ) { +dev_err (chip->dev,"Read qcom,lut-patterns failed, rc=%d\n" , + rc); +return rc; + } + + length = rc; +if (length >LPG_LUT_COUNT_MAX ) { +dev_err (chip->dev, +"qcom,lut-patterns length %d exceed max %d\n" , length, +LPG_LUT_COUNT_MAX ); +return -EINVAL ; + } + + chip->lut->pattern = +devm_kcalloc (chip->dev,LPG_LUT_COUNT_MAX , +sizeof (*chip->lut->pattern),GFP_KERNEL ); +if (!chip->lut->pattern) +return -ENOMEM ; + + rc =of_property_read_u32_array (chip->dev->of_node,"qcom,lut-patterns" , + chip->lut->pattern, length); +if (rc <0 ) { +dev_err (chip->dev,"Get qcom,lut-patterns failed, rc=%d\n" , rc); +return rc; + } + +if (of_get_available_child_count (chip->dev->of_node) ==0 ) { +dev_err (chip->dev,"No ramp configuration for any LPG\n" ); +return -EINVAL ; + } + + for_each_available_child_of_node (chip->dev->of_node, child) { + rc =of_property_read_u32 (child,"qcom,lpg-chan-id" , + &lpg_chan_id); +if (rc <0 ) { +dev_err (chip->dev, +"Get qcom,lpg-chan-id failed for node %s, rc=%d\n" , + child->name, rc); +return rc; + } + +if (lpg_chan_id > chip->num_lpgs) { +dev_err (chip->dev, +"lpg-chann-id %d is out of range 1~%d\n" , + lpg_chan_id, chip->num_lpgs); +return -EINVAL ; + } + +/* lpg channel id is indexed from 1 in hardware */ + lpg = &chip->lpgs[lpg_chan_id -1 ]; + ramp = &lpg->ramp_config; + + rc =of_property_read_u32 (child,"qcom,ramp-step-ms" , &tmp); +if (rc <0 ) { +dev_err (chip->dev, +"get qcom,ramp-step-ms failed for lpg%d, rc=%d\n" , + lpg_chan_id, rc); +return rc; + } + ramp->step_ms = (u16 )tmp; + + rc =of_property_read_u32 (child,"qcom,ramp-low-index" , &tmp); +if (rc <0 ) { +dev_err (chip->dev, +"get qcom,ramp-low-index failed for lpg%d, rc=%d\n" , + lpg_chan_id, rc); +return rc; + } + ramp->lo_idx = (u8 )tmp; +if (ramp->lo_idx >=LPG_LUT_COUNT_MAX ) { +dev_err (chip->dev, +"qcom,ramp-low-index should less than max %d\n" , +LPG_LUT_COUNT_MAX ); +return -EINVAL ; + } + + rc =of_property_read_u32 (child,"qcom,ramp-high-index" , &tmp); +if (rc <0 ) { +dev_err (chip->dev, +"get qcom,ramp-high-index failed for lpg%d, rc=%d\n" , + lpg_chan_id, rc); +return rc; + } + ramp->hi_idx = (u8 )tmp; + +if (ramp->hi_idx >LPG_LUT_COUNT_MAX ) { +dev_err (chip->dev, +"qcom,ramp-high-index shouldn't exceed max %d\n" , +LPG_LUT_COUNT_MAX ); +return -EINVAL ; + } + +if (ramp->hi_idx <= ramp->lo_idx) { +dev_err (chip->dev, +"high-index(%d) should be larger than low-index(%d)\n" , + ramp->hi_idx, ramp->lo_idx); +return -EINVAL ; + } + + ramp->pattern_length = ramp->hi_idx - ramp->lo_idx +1 ; + ramp->pattern = &chip->lut->pattern[ramp->lo_idx]; + lpg->max_pattern_length = ramp->pattern_length; + + rc =of_property_read_u32 (child,"qcom,ramp-pause-hi-count" , + &tmp); +if (rc <0 ) + ramp->pause_hi_count =0 ; +else + ramp->pause_hi_count = (u8 )tmp; + + rc =of_property_read_u32 (child,"qcom,ramp-pause-lo-count" , + &tmp); +if (rc <0 ) + ramp->pause_lo_count =0 ; +else + ramp->pause_lo_count = (u8 )tmp; + + ramp->ramp_dir_low_to_hi =of_property_read_bool ( + child,"qcom,ramp-from-low-to-high" ); + + ramp->pattern_repeat =of_property_read_bool ( + child,"qcom,ramp-pattern-repeat" ); + + ramp->toggle =of_property_read_bool (child,"qcom,ramp-toggle" ); + } + + rc =of_property_count_elems_of_size ( + chip->dev->of_node,"qcom,sync-channel-ids" ,sizeof (u32)); +if (rc <0 ) +return 0 ; + + length = rc; +if (length > chip->num_lpgs) { +dev_err (chip->dev, +"qcom,sync-channel-ids has too many channels: %d\n" , + length); +return -EINVAL ; + } + + chip->lpg_group =devm_kcalloc (chip->dev, chip->num_lpgs,sizeof (u32), +GFP_KERNEL ); +if (!chip->lpg_group) +return -ENOMEM ; + + rc =of_property_read_u32_array (chip->dev->of_node, +"qcom,sync-channel-ids" , + chip->lpg_group, length); +if (rc <0 ) { +dev_err (chip->dev,"Get qcom,sync-channel-ids failed, rc=%d\n" , + rc); +return rc; + } + +for (i =0 ; i < length; i++) { +if (chip->lpg_group[i] <=0 || + chip->lpg_group[i] > chip->num_lpgs) { +dev_err (chip->dev, +"lpg_group[%d]: %d is not a valid channel\n" , i, + chip->lpg_group[i]); +return -EINVAL ; + } + } + +/* +* The LPG channel in the same group should have the same ramping +* configuration, so force to use the ramping configuration of the +* 1st LPG channel in the group for sychronization. +*/ + lpg = &chip->lpgs[chip->lpg_group[0 ] -1 ]; + ramp = &lpg->ramp_config; + +for (i =1 ; i < length; i++) { + lpg = &chip->lpgs[chip->lpg_group[i] -1 ]; +memcpy (&lpg->ramp_config, ramp,sizeof (struct lpg_ramp_config )); + } + +return 0 ; +} + +static int qpnp_lpg_probe (struct platform_device *pdev) +{ +int rc; +struct qpnp_lpg_chip *chip; + + chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->dev = &pdev->dev; + chip->regmap =dev_get_regmap (chip->dev->parent,NULL ); +if (!chip->regmap) { +dev_err (chip->dev,"Getting regmap failed\n" ); +return -EINVAL ; + } + +mutex_init (&chip->bus_lock); + rc =qpnp_lpg_parse_dt (chip); +if (rc <0 ) { +dev_err (chip->dev, +"Devicetree properties parsing failed, rc=%d\n" , rc); + goto err_out; + } + +dev_set_drvdata (chip->dev, chip); + chip->pwm_chip.dev = chip->dev; + chip->pwm_chip.base =-1 ; + chip->pwm_chip.npwm = chip->num_lpgs; + chip->pwm_chip.ops = &qpnp_lpg_pwm_ops; + + rc =pwmchip_add (&chip->pwm_chip); +if (rc <0 ) { +dev_err (chip->dev,"Add pwmchip failed, rc=%d\n" , rc); + goto err_out; + } + +return 0 ; +err_out: +mutex_destroy (&chip->bus_lock); +return rc; +} + +static int qpnp_lpg_remove (struct platform_device *pdev) +{
Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c line 1258
Quoted 6 lines
drivers/pwm/pwm-qti-lpg.c new file +6
-0+struct qpnp_lpg_chip *chip =dev_get_drvdata (&pdev->dev); +int rc =0 ; + + rc =pwmchip_remove (&chip->pwm_chip); +if (rc <0 ) +dev_err (chip->dev,"Remove pwmchip failed, rc=%d\n" , rc);Please use %pe instead of %d for error codes.
OK.
Quoted 6 lines
drivers/pwm/pwm-qti-lpg.c line 1261
Quoted 4 lines
drivers/pwm/pwm-qti-lpg.c new file +3
-0+ +mutex_destroy (&chip->bus_lock); +dev_set_drvdata (chip->dev,NULL );
dev_set_drvdata(..., NULL)is not needed.
Okay.
Quoted 18 lines
Quoted 18 lines
drivers/pwm/pwm-qti-lpg.c new file +17
-0+ +return rc; +} + +static const struct of_device_id qpnp_lpg_of_match[] = { + { + .compatible ="qcom,pwm-lpg" , + }, + {}, +}; + +static struct platform_driver qpnp_lpg_driver = { + .driver = { + .name ="qcom,pwm-lpg" , + .of_match_table = qpnp_lpg_of_match, + }, + .probe = qpnp_lpg_probe,
Quoted 8 lines
Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c new file +6
-1+ .remove = qpnp_lpg_remove, +}; +module_platform_driver (qpnp_lpg_driver); + +MODULE_DESCRIPTION ("QTI LPG driver" ); +MODULE_LICENSE ("GPL v2" ); --2.27.0
Thank you.
Best Regards,
Martin
Re: [PATCH RFC 3/6] pwm: pwm-qti-lpg: Add PWM driver for QTI LPG module
Hello Martin,
Quoted 72 lines · Martin Botka
Quoted 41 lines · Mo 27. 7. 2020 at 22:10 Uwe Kleine-König <[email protected]> wrote:
Quoted 39 lines · Martin Botka
From: Fenglin Wu <[email protected]>
Add
pwm_chipto support QTI LPG module and export LPG channels as PWM devices for consumer drivers' usage.Signed-off-by Fenglin Wu <[email protected]>[[email protected]: Fast-forward the driver from kernel 4.14 to 5.8]Signed-off-by Martin Botka <[email protected]>--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-qti-lpg.c | 1284 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1295 insertions(+) create mode 100644 drivers/pwm/pwm-qti-lpg.cdrivers/pwm/Kconfig +10
-0@@ -399,6 +399,16 @@ config PWM_RCAR To compile this driver as a module, choose M here: the module will be called pwm-rcar. +config PWM_QTI_LPG + tristate "Qualcomm Technologies, Inc. LPG driver" + depends on MFD_SPMI_PMIC && OF + help + This driver supports the LPG (Light Pulse Generator) module found in + Qualcomm Technologies, Inc. PMIC chips. Each LPG channel can be + configured to operate in PWM mode to output a fixed amplitude with + variable duty cycle or in LUT (Look up table) mode to output PWM + signal with a modulated amplitude. + config PWM_RENESAS_TPU tristate "Renesas TPU PWM support" depends on ARCH_RENESAS || COMPILE_TESTdrivers/pwm/Makefile +0
-1--- a/drivers/pwm/MakefileQuoted 8 lines
drivers/pwm/Makefile obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o · line 40
Quoted 6 lines
+++ b/drivers/pwm/Makefile
drivers/pwm/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o obj-$(CONFIG_PWM_RCAR) += pwm-rcar.o +obj-$(CONFIG_PWM_QTI_LPG) += pwm-qti-lpg.oPlease keep this list alphabetically sorted.
OK
Quoted 10 lines
Quoted 10 lines
drivers/pwm/Makefile +0
-0obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.odrivers/pwm/pwm-qti-lpg.c new file +0
-0@@ -0,0 +1,1284 @@Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c line 6
Quoted 6 lines
drivers/pwm/pwm-qti-lpg.c new file +6
-0+// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2020, The Linux Foundation. All rights reserved. +*/ + +#define pr_fmt (fmt) "%s: " fmt, __func__This smells like debug stuff. Please drop this.
Quoted 2 lines
What do you mean ?
The #definepr_fmt(fmt)or the tons of REG definitions ?
Either drop pr_fmt or at least don't have __func__ in it. This doesn't belong into the kernel log (in the non-debug case at least). (For debugging I like:
#define pr_fmt(fmt) "%s:%d: " fmt, __func__, __LINE__
which helps finding the right printk line in the code from a given output in functions with many printks.)
I don't mind the REG definitions, though aligning the values vertically is common.
Quoted 12 lines
Quoted 11 lines
drivers/pwm/pwm-qti-lpg.c line 962
Quoted 8 lines
drivers/pwm/pwm-qti-lpg.c new file +8
-0+static const struct pwm_ops qpnp_lpg_pwm_ops = { + .config = qpnp_lpg_pwm_config, + .config_extend = qpnp_lpg_pwm_config_extend, + .get_output_type_supported = qpnp_lpg_pwm_output_types_supported, + .set_output_type = qpnp_lpg_pwm_set_output_type, + .set_output_pattern = qpnp_lpg_pwm_set_output_pattern, + .enable = qpnp_lpg_pwm_enable, + .disable = qpnp_lpg_pwm_disable,As already noted in the former patch: Please implement .apply() and .get_state().
Quoted 7 lines
So drop:
.get_output_type_supported =qpnp_lpg_pwm_output_types_supported, .set_output_type =qpnp_lpg_pwm_set_output_type, .set_output_pattern =qpnp_lpg_pwm_set_output_pattern,Ad implement implement .apply and .get_state if i understood you correctly. Right ?
ack
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
RFC PATCH 4/6 leds: leds-qti-tri-led: Add LED driver for QTI TRI_LED module
In reply to Martin BotkaFrom: Fenglin Wu <[email protected]>
QTI TRI_LED module has 3 current sinks at max for LED driver and each is controlled by a PWM channel used for LED dimming or blinking. Add the driver to support it.
--- drivers/leds/Kconfig | 9 + drivers/leds/Makefile | 1 + drivers/leds/leds-qti-tri-led.c | 640 ++++++++++++++++++++++++++++++++ 3 files changed, 650 insertions(+) create mode 100644 drivers/leds/leds-qti-tri-led.c
drivers/leds/Kconfig +9 -0
@@ -768,6 +768,15 @@ config LEDS_POWERNV To compile this driver as a module, choose 'm' here: the module will be called leds-powernv. +config LEDS_QTI_TRI_LED + tristate "LED support for Qualcomm Technologies, Inc. TRI_LED" + depends on LEDS_CLASS && MFD_SPMI_PMIC && PWM && OF + help + This driver supports the TRI_LED module found in Qualcomm + Technologies, Inc. PMIC chips. TRI_LED supports 3 LED drivers + at max and each is controlled by a PWM channel used for dimming + or blinking. + config LEDS_SYSCON bool "LED support for LEDs on system controllers" depends on LEDS_CLASS=y
drivers/leds/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_LEDS_BCM6328) += leds-bcm6328.o obj-$(CONFIG_LEDS_BCM6358) += leds-bcm6358.o obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o +obj-$(CONFIG_LEDS_QTI_TRI_LED) += leds-qti-tri-led.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
drivers/leds/leds-qti-tri-led.c new file +640 -0
640 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH RFC 4/6] leds: leds-qti-tri-led: Add LED driver for QTI TRI_LED module
Hello.
This driver has the breath feature of the driver broken as I sent a slightly modified version of it from when I was testing it. The proper version will come when i will be sending out V2 which will be hopefully soon as I'm little busy.
Best regards
Martin
RFC PATCH 5/6 Documentation: Add binding for qti-tri-led
In reply to Martin BotkaFrom: Fenglin Wu <[email protected]>
Add documentation for qti-tri-led
--- .../bindings/leds/leds-qti-tri-led.txt | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-qti-tri-led.txt
Documentation/devicetree/bindings/leds/leds-qti-tri-led.txt new file +72 -0
@@ -0,0 +1,72 @@ +Qualcomm Technologies, Inc. TRI_LED driver specific bindings + +This binding document describes the properties of TRI_LED module in +Qualcomm Technologies, Inc. PMIC chips. + +- compatible: + Usage: required + Value type: <string> + Definition: Must be "qcom,tri-led". + +- reg: + Usage: required + Value type: <prop-encoded-array> + Definition: Register base of the TRI_LED module and length. + +- nvmem-names: + Usage: optional + Value type: <string> + Definition: Nvmem device name for SDAM to do PBS trigger. It must be + defined as "pbs_sdam". This is required only for HR_LEDs. + +- nvmem: + Usage: optional + Value type: <phandle> + Definition: Phandle of the nvmem device name to access SDAM to do PBS + trigger. This is required only for HR_LEDs. + +Properties for child nodes: +- pwms: + Usage: required + Value type: <prop-encoded-array> + Definition: The PWM device (phandle) used for controlling LED. + +- led-sources: + Usage: required + Value type: <prop-encoded-array> + Definition: see Documentation/devicetree/bindings/leds/common.txt; + Device current output identifiers are: 0 - LED1_EN, + 1 - LED2_EN, 2 - LED3_EN. + +- label: + Usage: optional + Value type: <string> + Definition: see Documentation/devicetree/bindings/leds/common.txt; + +- linux,default-trigger: + Usage: optional + Value_type: <string> + Definition: see Documentation/devicetree/bindings/leds/common.txt; + +Example: + + pmi8998_rgb: tri-led@d000{ + compatible = "qcom,tri-led"; + reg = <0xd000 0x100>; + + red { + label = "red"; + pwms = <&pmi8998_lpg 4 1000000>; + led-sources = <0>; + }; + green { + label = "green"; + pwms = <&pmi8998_lpg 3 1000000>; + led-sources = <1>; + }; + blue { + label = "blue"; + pwms = <&pmi8998_lpg 2 1000000>; + led-sources = <2>; + }; + };
Signature · 1 line
2.27.0
RFC PATCH 6/6 Documentation: Add binding for pwm-qti-lpg
In reply to Martin BotkaFrom: Fenglin Wu <[email protected]>
Add documentation for pwm-qti-lpg
--- .../devicetree/bindings/pwm/pwm-qti-lpg.txt | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-qti-lpg.txt
Documentation/devicetree/bindings/pwm/pwm-qti-lpg.txt new file +163 -0
@@ -0,0 +1,163 @@ +Qualcomm Technologies, Inc. LPG driver specific bindings + +This binding document describes the properties of LPG (Light Pulse Generator) +device module in Qualcomm Technologies, Inc. PMIC chips. + +- compatible: + Usage: required + Value type: <string> + Definition: Must be "qcom,pwm-lpg". + +- reg: + Usage: required + Value type: <prop-encoded-array> + Definition: Register base for LPG and LUT modules. + +- reg-names: + Usage: required + Value type: <string> + Definition: The name of the register defined in the reg property. + It must have "lpg-base", "lut-base" is optional but + it's required if any LPG channels support LUT mode. + +- #pwm-cells: + Usage: required + Value type: <u32> + Definition: The number of cells in "pwms" property specified in + PWM user nodes. It should be 2. The first cell is + the PWM channel ID indexed from 0, and the second + cell is the PWM default period in nanoseconds. + +- qcom,num-lpg-channels: + Usage: required + Value type: <u32> + Definition: The number of the consecutive LPG/PWM channels in the chip. + +- qcom,lut-patterns: + Usage: optional + Value type: <prop-encoded-array> + Definition: Duty ratios in percentages for LPG working at LUT mode. + These duty ratios will be translated into PWM values + and stored in LUT module. The LUT module has resource + to store 47 PWM values at max and shared for all LPG + channels. This property is required if any LPG channels + support LUT mode. + +- qcom,sync-channel-ids: + Usage: optional + Value type: <prop-encoded-array> + Definition: The hardware IDs of the LPG channel that required be + grouped together. These channels will share the same LUT + ramping configuration so that they will be enabled with a + synchronized pattern. If the LUT ramping configuration + differs for the channels grouped for synchronization, + configuration of the first channel will be applied for + all others. + +Subnode is optional if LUT mode is not required, it's required if any LPG +channels expected to be supported in LUT mode. + +Subnode properties: +Subnodes for each LPG channel (lpg@X) can be defined if any of the following +parameters needs to be configured for that channel. + +- qcom,lpg-chan-id: + Usage: required + Value type: <u32> + Definition: The LPG channel's hardware ID indexed from 1. Allowed + range is 1 - 8. Maximum value depends on the number of + channels supported on PMIC. + +- qcom,ramp-step-ms: + Usage: required + Value type: <u32> + Definition: The step duration in milliseconds for LPG staying at each + duty specified in the LUT pattern. Allowed range is + 1 - 511. + +- qcom,ramp-high-index: + Usage: required + Value type: <u32> + Definition: The high index of the LUT pattern where LPG ends up + ramping to. Allowed range is 1 - 47. + +- qcom,ramp-low-index: + Usage: required + Value type: <u32> + Definition: The low index of the LUT pattern from where LPG begins + ramping from. Allowed range is 0 - 46. + +- qcom,ramp-from-low-to-high: + Usage: optional + Value type: <empty> + Definition: The flag to specify the LPG ramping direction. The ramping + direction is from low index to high index of the LUT + pattern if it's specified. + +- qcom,ramp-pattern-repeat: + Usage: optional + Value type: <empty> + Definition: The flag to specify if LPG would be ramping with the LUT + pattern repeatedly. + +- qcom,ramp-toggle: + Usage: optional + Value type: <empty> + Definition: The flag to specify if LPG would toggle the LUT pattern + in ramping. If toggling enabled, LPG would return to the + low index when high index is reached, or return to the high + index when low index is reached. + +- qcom,ramp-pause-hi-count: + Usage: optional + Value type: <u32> + Definition: The step count that LPG stop the output when it ramped up + to the high index of the LUT. + +- qcom,ramp-pause-lo-count: + Usage: optional + Value type: <u32> + Definition: The step count that LPG stop the output when it ramped up + to the low index of the LUT. +Example: + + pmi8998_lpg: lpg@b100 { + compatible = "qcom,pwm-lpg"; + reg = <0xb100 0x600>, <0xb000 0x100>; + reg-names = "lpg-base", "lut-base"; + qcom,num-lpg-channels = <6>; + #pwm-cells = <2>; + qcom,lut-patterns = <0 14 28 42 56 70 84 100 + 100 84 70 56 42 28 14 0>; + qcom,sync-channel-ids = <3 4 5>; + lpg@3 { + qcom,lpg-chan-id = <3>; + qcom,ramp-step-ms = <200>; + qcom,ramp-pause-hi-count = <10>; + qcom,ramp-pause-lo-count = <10>; + qcom,ramp-low-index = <0>; + qcom,ramp-high-index = <15>; + qcom,ramp-from-low-to-high; + qcom,ramp-pattern-repeat; + }; + lpg@4 { + qcom,lpg-chan-id = <4>; + qcom,ramp-step-ms = <200>; + qcom,ramp-pause-hi-count = <10>; + qcom,ramp-pause-lo-count = <10>; + qcom,ramp-low-index = <0>; + qcom,ramp-high-index = <15>; + qcom,ramp-from-low-to-high; + qcom,ramp-pattern-repeat; + }; + lpg@5 { + qcom,lpg-chan-id = <5>; + qcom,ramp-step-ms = <200>; + qcom,ramp-pause-hi-count = <10>; + qcom,ramp-pause-lo-count = <10>; + qcom,ramp-low-index = <0>; + qcom,ramp-high-index = <15>; + qcom,ramp-from-low-to-high; + qcom,ramp-pattern-repeat; + }; + };
Signature · 1 line
2.27.0
Hi!
Dalsi cech co hackuje LEDky?
Quoted 2 lines
This series brings QCOM pwm-lpg and tri-led drivers from 4.14 that is required to support pmic-connected notification LED. This comes straight from downstream and I'm ready for your comments.
Yeah, so...
Bindings should go first, they may need to be converted to yml (devicetree people will know).
Can generic pwm driver be used here?
This is for RGB modules, right? It will need to use multicolor framework.
"Breathing" will need to be figured out. It should become a trigger.
Is this for phone, btw? If so, which one?
Best regards,
Pavel
Quoted 17 lines
.../bindings/leds/leds-qti-tri-led.txt | 72 + .../devicetree/bindings/pwm/pwm-qti-lpg.txt | 163 +++ drivers/leds/Kconfig | 9 + drivers/leds/Makefile | 1 + drivers/leds/leds-qti-tri-led.c | 640 ++++++++ drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/core.c | 56 +- drivers/pwm/pwm-qti-lpg.c | 1284 +++++++++++++++++ drivers/pwm/sysfs.c | 56 +- include/linux/pwm.h | 144 +- 11 files changed, 2418 insertions(+), 18 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/leds-qti-tri-led.txt create mode 100644 Documentation/devicetree/bindings/pwm/pwm-qti-lpg.txt create mode 100644 drivers/leds/leds-qti-tri-led.c create mode 100644 drivers/pwm/pwm-qti-lpg.c
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi,
Quoted 1 line
Dalsi cech co hackuje LEDky?
Nie. Slovak.
Quoted 2 lines
Bindings should go first, they may need to be converted to yml (devicetree people will know).
OK
Quoted 1 line
Can generic pwm driver be used here?
I have not tried to do that. But considering it's custom chip from Qualcomm then it's unlikely.
Quoted 2 lines
This is for RGB modules, right? It will need to use multicolor framework.
This is for RGB LEDs in phones that are connected via pmic.
Quoted 1 line
Is this for phone, btw? If so, which one?
Yes it is. And it's for many many phones actually. I have done this mainly for SONY phones (Xperia 10, 10 Plus, XA2, XA2 Plus, XA2 Ultra). All of them use these drivers for generating the PWM and controlling the LEDs.
Best Regards,
Martin
Hi!
Quoted 3 lines
Quoted 1 line
Dalsi cech co hackuje LEDky?
Nie. Slovak.
Vitej do klubu :-).
Quoted 4 lines
Quoted 2 lines
Bindings should go first, they may need to be converted to yml (devicetree people will know).
OK
I'm not 100% sure, please double check.
Quoted 4 lines
Quoted 1 line
Can generic pwm driver be used here?
I have not tried to do that. But considering it's custom chip from Qualcomm then it's unlikely.
Please double check. Actually, is the series for one chip or for two of them? LED framework should is happy to talk to generic pwm driver...
Quoted 4 lines
Quoted 2 lines
This is for RGB modules, right? It will need to use multicolor framework.
This is for RGB LEDs in phones that are connected via pmic.
Ok. Check multicolor framework in -next.
Quoted 6 lines
Quoted 1 line
Is this for phone, btw? If so, which one?
Yes it is. And it's for many many phones actually. I have done this mainly for SONY phones (Xperia 10, 10 Plus, XA2, XA2 Plus, XA2 Ultra). All of them use these drivers for generating the PWM and controlling the LEDs.
Aha, ok. I assume they are still quite far away from being usable with mainline kernels.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 1 line
Vitej do klubu :-).
Dakujem
Quoted 2 lines
Please double check. Actually, is the series for one chip or for two of them? LED framework should is happy to talk to generic pwm driver...
I'm not sure on that one. I will have to talk to some people about that. I will get back to you on that when i find out how it actually is. But i think its one single chip. Not sure tho.
Quoted 1 line
Ok. Check multicolor framework in -next.
I will look into it. Thank you
Quoted 2 lines
Aha, ok. I assume they are still quite far away from being usable with mainline kernels.
Actually no.
While Konrad didn't send the patches yet we have some stuff working as:
Panel
Touchscreen
LEDs with this series
Flash light
You can check https://github.com/konradybcio/linux/commits/ninges_labs
for the current progress on those phones.
Best Regards,
Martin
Hi,
Dalsi cech co hackuje LEDky?
Nie. Slovak.
Bindings should go first, they may need to be converted to yml (devicetree people will know).
OK
Can generic pwm driver be used here?
I have not tried to do that. But considering it's custom chip from Qualcomm then it's unlikely.
This is for RGB modules, right? It will need to use multicolor framework.
This is for RGB LEDs in phones that are connected via pmic.
Is this for phone, btw? If so, which one?
Yes it is. And it's for many many phones actually. I have done this mainly for SONY phones (Xperia 10, 10 Plus, XA2, XA2 Plus, XA2 Ultra). All of them use these drivers for generating the PWM and controlling the LEDs.
P.S resending because i sent it as HTML apparently. Best Regards,
Martin
Hi!
Quoted 7 lines
Is this for phone, btw? If so, which one?
Yes it is. And it's for many many phones actually. I have done this mainly for SONY phones (Xperia 10, 10 Plus, XA2, XA2 Plus, XA2 Ultra). All of them use these drivers for generating the PWM and controlling the LEDs.
P.Sresending because i sent it as HTML apparently.
First copy was ok. Second had broken formatting. Both were plaintext AFAICT.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 2 lines
First copy was ok. Second had broken formatting. Both were plaintext AFAICT.
It's just that gmail was telling me that it didn't send it to some of the email addresses because i forgot to check the "Use plain text" in Gmail.