aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pwm/core.c')
-rw-r--r--drivers/pwm/core.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index d2c35920ff08..966497d10c6e 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -236,7 +236,7 @@ int pwmchip_add(struct pwm_chip *chip)
236 int ret; 236 int ret;
237 237
238 if (!chip || !chip->dev || !chip->ops || !chip->ops->config || 238 if (!chip || !chip->dev || !chip->ops || !chip->ops->config ||
239 !chip->ops->enable || !chip->ops->disable) 239 !chip->ops->enable || !chip->ops->disable || !chip->npwm)
240 return -EINVAL; 240 return -EINVAL;
241 241
242 mutex_lock(&pwm_lock); 242 mutex_lock(&pwm_lock);
@@ -602,12 +602,9 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
602 struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER); 602 struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER);
603 const char *dev_id = dev ? dev_name(dev) : NULL; 603 const char *dev_id = dev ? dev_name(dev) : NULL;
604 struct pwm_chip *chip = NULL; 604 struct pwm_chip *chip = NULL;
605 unsigned int index = 0;
606 unsigned int best = 0; 605 unsigned int best = 0;
607 struct pwm_lookup *p; 606 struct pwm_lookup *p, *chosen = NULL;
608 unsigned int match; 607 unsigned int match;
609 unsigned int period;
610 enum pwm_polarity polarity;
611 608
612 /* look up via DT first */ 609 /* look up via DT first */
613 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) 610 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
@@ -653,10 +650,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
653 } 650 }
654 651
655 if (match > best) { 652 if (match > best) {
656 chip = pwmchip_find_by_name(p->provider); 653 chosen = p;
657 index = p->index;
658 period = p->period;
659 polarity = p->polarity;
660 654
661 if (match != 3) 655 if (match != 3)
662 best = match; 656 best = match;
@@ -665,17 +659,22 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
665 } 659 }
666 } 660 }
667 661
668 mutex_unlock(&pwm_lookup_lock); 662 if (!chosen)
663 goto out;
669 664
670 if (chip) 665 chip = pwmchip_find_by_name(chosen->provider);
671 pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id); 666 if (!chip)
672 if (IS_ERR(pwm)) 667 goto out;
673 return pwm;
674 668
675 pwm_set_period(pwm, period); 669 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
676 pwm_set_polarity(pwm, polarity); 670 if (IS_ERR(pwm))
671 goto out;
677 672
673 pwm_set_period(pwm, chosen->period);
674 pwm_set_polarity(pwm, chosen->polarity);
678 675
676out:
677 mutex_unlock(&pwm_lookup_lock);
679 return pwm; 678 return pwm;
680} 679}
681EXPORT_SYMBOL_GPL(pwm_get); 680EXPORT_SYMBOL_GPL(pwm_get);