Skip to content

Commit

Permalink
pwm: Add pwmchip_add_with_polarity() API
Browse files Browse the repository at this point in the history
Add a new function to register a PWM chip with channels that have their
initial polarity as specified by an additional parameter. This benefits
drivers of controllers that by default operate with inversed polarity
by removing the need to modify the polarity during initialization.

Signed-off-by: Tim Kryger <tim.kryger@gmail.com>
Signed-off-by: Jonathan Richardson <jonathar@broadcom.com>
[thierry.reding@gmail.com: export pwmchip_add_with_polarity()]
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Tim Kryger authored and Thierry Reding committed Jun 12, 2015
1 parent 472ac3d commit b6a00fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 20 additions & 3 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,16 @@ void *pwm_get_chip_data(struct pwm_device *pwm)
EXPORT_SYMBOL_GPL(pwm_get_chip_data);

/**
* pwmchip_add() - register a new PWM chip
* pwmchip_add_with_polarity() - register a new PWM chip
* @chip: the PWM chip to add
* @polarity: initial polarity of PWM channels
*
* Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
* will be used.
* will be used. The initial polarity for all channels is specified by the
* @polarity parameter.
*/
int pwmchip_add(struct pwm_chip *chip)
int pwmchip_add_with_polarity(struct pwm_chip *chip,
enum pwm_polarity polarity)
{
struct pwm_device *pwm;
unsigned int i;
Expand Down Expand Up @@ -259,6 +262,7 @@ int pwmchip_add(struct pwm_chip *chip)
pwm->chip = chip;
pwm->pwm = chip->base + i;
pwm->hwpwm = i;
pwm->polarity = polarity;

radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
}
Expand All @@ -279,6 +283,19 @@ int pwmchip_add(struct pwm_chip *chip)
mutex_unlock(&pwm_lock);
return ret;
}
EXPORT_SYMBOL_GPL(pwmchip_add_with_polarity);

/**
* pwmchip_add() - register a new PWM chip
* @chip: the PWM chip to add
*
* Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
* will be used. The initial polarity for all channels is normal.
*/
int pwmchip_add(struct pwm_chip *chip)
{
return pwmchip_add_with_polarity(chip, PWM_POLARITY_NORMAL);
}
EXPORT_SYMBOL_GPL(pwmchip_add);

/**
Expand Down
7 changes: 7 additions & 0 deletions include/linux/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ struct pwm_chip {
int pwm_set_chip_data(struct pwm_device *pwm, void *data);
void *pwm_get_chip_data(struct pwm_device *pwm);

int pwmchip_add_with_polarity(struct pwm_chip *chip,
enum pwm_polarity polarity);
int pwmchip_add(struct pwm_chip *chip);
int pwmchip_remove(struct pwm_chip *chip);
struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
Expand Down Expand Up @@ -217,6 +219,11 @@ static inline int pwmchip_add(struct pwm_chip *chip)
return -EINVAL;
}

static inline int pwmchip_add_inversed(struct pwm_chip *chip)
{
return -EINVAL;
}

static inline int pwmchip_remove(struct pwm_chip *chip)
{
return -EINVAL;
Expand Down

0 comments on commit b6a00fa

Please sign in to comment.