]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/pwm/core.c
Merge branch 'md-next' into md-linus
[karo-tx-linux.git] / drivers / pwm / core.c
index e3d6c5437070efcc656c9088c138ccb9971b0ab7..a0860b30bd931760480ca6800d539d08d6433478 100644 (file)
@@ -759,12 +759,13 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num)
  */
 struct pwm_device *pwm_get(struct device *dev, const char *con_id)
 {
-       struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER);
        const char *dev_id = dev ? dev_name(dev) : NULL;
-       struct pwm_chip *chip = NULL;
+       struct pwm_device *pwm;
+       struct pwm_chip *chip;
        unsigned int best = 0;
        struct pwm_lookup *p, *chosen = NULL;
        unsigned int match;
+       int err;
 
        /* look up via DT first */
        if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
@@ -819,24 +820,35 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
                }
        }
 
-       if (!chosen) {
-               pwm = ERR_PTR(-ENODEV);
-               goto out;
-       }
+       mutex_unlock(&pwm_lookup_lock);
+
+       if (!chosen)
+               return ERR_PTR(-ENODEV);
 
        chip = pwmchip_find_by_name(chosen->provider);
+
+       /*
+        * If the lookup entry specifies a module, load the module and retry
+        * the PWM chip lookup. This can be used to work around driver load
+        * ordering issues if driver's can't be made to properly support the
+        * deferred probe mechanism.
+        */
+       if (!chip && chosen->module) {
+               err = request_module(chosen->module);
+               if (err == 0)
+                       chip = pwmchip_find_by_name(chosen->provider);
+       }
+
        if (!chip)
-               goto out;
+               return ERR_PTR(-EPROBE_DEFER);
 
        pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
        if (IS_ERR(pwm))
-               goto out;
+               return pwm;
 
        pwm->args.period = chosen->period;
        pwm->args.polarity = chosen->polarity;
 
-out:
-       mutex_unlock(&pwm_lookup_lock);
        return pwm;
 }
 EXPORT_SYMBOL_GPL(pwm_get);