pwm: core: Unify fwnode checks in the module
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 7 Jun 2021 12:24:56 +0000 (15:24 +0300)
committerThierry Reding <thierry.reding@gmail.com>
Wed, 30 Jun 2021 17:12:19 +0000 (19:12 +0200)
Historically we have two different approaches on how to check type of fwnode.
Unify them using the latest and greatest fwnode related APIs.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/core.c

index b72fb77aea60f2e4b42cc45fe4a1e0f2ab9cb99a..e823a4eba79e0d90f96f3453486e29de0fc34f7c 100644 (file)
@@ -829,7 +829,7 @@ EXPORT_SYMBOL_GPL(of_pwm_get);
 
 /**
  * acpi_pwm_get() - request a PWM via parsing "pwms" property in ACPI
- * @fwnode: firmware node to get the "pwm" property from
+ * @fwnode: firmware node to get the "pwms" property from
  *
  * Returns the PWM device parsed from the fwnode and index specified in the
  * "pwms" property or a negative error-code on failure.
@@ -844,7 +844,7 @@ EXPORT_SYMBOL_GPL(of_pwm_get);
  * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded
  * error code on failure.
  */
-static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode)
+static struct pwm_device *acpi_pwm_get(const struct fwnode_handle *fwnode)
 {
        struct pwm_device *pwm = ERR_PTR(-ENODEV);
        struct fwnode_reference_args args;
@@ -928,6 +928,7 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num)
  */
 struct pwm_device *pwm_get(struct device *dev, const char *con_id)
 {
+       const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;
        const char *dev_id = dev ? dev_name(dev) : NULL;
        struct pwm_device *pwm;
        struct pwm_chip *chip;
@@ -938,12 +939,12 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
        int err;
 
        /* look up via DT first */
-       if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
-               return of_pwm_get(dev, dev->of_node, con_id);
+       if (is_of_node(fwnode))
+               return of_pwm_get(dev, to_of_node(fwnode), con_id);
 
        /* then lookup via ACPI */
-       if (dev && is_acpi_node(dev->fwnode)) {
-               pwm = acpi_pwm_get(dev->fwnode);
+       if (is_acpi_node(fwnode)) {
+               pwm = acpi_pwm_get(fwnode);
                if (!IS_ERR(pwm) || PTR_ERR(pwm) != -ENOENT)
                        return pwm;
        }