lkml.org 
[lkml]   [2013]   [Jan]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/3] pwm: Add pwm_cansleep() as exported API to users
On 01/25/2013 11:01 AM, Florian Vaussard wrote:
> Calls to some external PWM chips can sleep. To help users,
> add pwm_cansleep() API.
>
> Signed-off-by: Florian Vaussard <florian.vaussard@epfl.ch>
> ---
> drivers/pwm/core.c | 12 ++++++++++++
> include/linux/pwm.h | 10 ++++++++++
> 2 files changed, 22 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 4a13da4..f49bfa6 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -763,6 +763,18 @@ void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
> }
> EXPORT_SYMBOL_GPL(devm_pwm_put);
>
> +/**
> + * pwm_can_sleep() - report whether pwm access will sleep
> + * @pwm: PWM device
> + *
> + * It returns nonzero if accessing the PWM can sleep.
> + */
> +int pwm_can_sleep(struct pwm_device *pwm)
> +{
> + return pwm->chip->can_sleep;
> +}
> +EXPORT_SYMBOL_GPL(pwm_can_sleep);

Can we name this as pwm_cansleep() to be more alligned with the
gpio_cansleep() API?

> +
> #ifdef CONFIG_DEBUG_FS
> static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
> {
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index 70655a2..2aee75d 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -146,6 +146,8 @@ struct pwm_ops {
> * @base: number of first PWM controlled by this chip
> * @npwm: number of PWMs controlled by this chip
> * @pwms: array of PWM devices allocated by the framework
> + * @can_sleep: flag must be set iff config()/enable()/disable() methods sleep,
> + * as they must while accessing PWM chips over I2C or SPI
> */
> struct pwm_chip {
> struct device *dev;
> @@ -159,6 +161,7 @@ struct pwm_chip {
> struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
> const struct of_phandle_args *args);
> unsigned int of_pwm_n_cells;
> + unsigned int can_sleep:1;
> };
>
> #if IS_ENABLED(CONFIG_PWM)
> @@ -182,6 +185,8 @@ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
> struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
> const char *con_id);
> void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
> +
> +int pwm_can_sleep(struct pwm_device *pwm);
> #else
> static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
> {
> @@ -242,6 +247,11 @@ static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
> static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
> {
> }
> +
> +static inline int pwm_can_sleep(struct pwm_device *pwm)
> +{
> + return -EINVAL;

I think we should return 0 here instead an error.

> +}
> #endif
>
> struct pwm_lookup {
>


--
Péter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2013-01-25 14:21    [W:0.070 / U:5.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site