From: "Rafael J. Wysocki" <rafael.j.wyso...@intel.com>

Modify is_acpi_node() to return "true" for ACPI data-only subnodes as
well as for ACPI device objects and change the name of to_acpi_node()
to to_acpi_device_node() so it is clear that it covers ACPI device
objects only.  Accordingly, introduce to_acpi_data_node() to cover
data-only subnodes in an analogous way.

With that, make the fwnode_property_* family of functions work with
ACPI data-only subnodes introduced previously.

Signed-off-by: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
Tested-by: Mika Westerberg <mika.westerb...@linux.intel.com>
(cherry picked from commit 3a7a2ab839ad18c2d542b40f4a647c98d068e55a)
Signed-off-by: Voon, Weifeng <weifeng.v...@intel.com>
---
 drivers/acpi/property.c | 138 ++++++++++++++++++++++++++++++++++++------------
 drivers/base/property.c |  16 +++---
 drivers/gpio/gpiolib.c  |   6 +--
 include/acpi/acpi_bus.h |  21 +++++++-
 include/linux/acpi.h    |  53 +++++++++++++------
 5 files changed, 173 insertions(+), 61 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 17c436d..5859fd1 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -19,6 +19,11 @@
 
 #include "internal.h"
 
+static int acpi_data_get_property_array(struct acpi_device_data *data,
+                                       const char *name,
+                                       acpi_object_type type,
+                                       const union acpi_object **obj);
+
 /* ACPI _DSD device properties UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */
 static const u8 prp_uuid[16] = {
        0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
@@ -190,8 +195,8 @@ static void acpi_init_of_compatible(struct acpi_device 
*adev)
        const union acpi_object *of_compatible;
        int ret;
 
-       ret = acpi_dev_get_property_array(adev, "compatible", ACPI_TYPE_STRING,
-                                         &of_compatible);
+       ret = acpi_data_get_property_array(&adev->data, "compatible",
+                                          ACPI_TYPE_STRING, &of_compatible);
        if (ret) {
                ret = acpi_dev_get_property(adev, "compatible",
                                            ACPI_TYPE_STRING, &of_compatible);
@@ -318,8 +323,8 @@ void acpi_free_properties(struct acpi_device *adev)
 }
 
 /**
- * acpi_dev_get_property - return an ACPI property with given name
- * @adev: ACPI device to get property
+ * acpi_data_get_property - return an ACPI property with given name
+ * @data: ACPI device deta object to get the property from
  * @name: Name of the property
  * @type: Expected property type
  * @obj: Location to store the property value (if not %NULL)
@@ -328,26 +333,27 @@ void acpi_free_properties(struct acpi_device *adev)
  * object at the location pointed to by @obj if found.
  *
  * Callers must not attempt to free the returned objects.  These objects will 
be
- * freed by the ACPI core automatically during the removal of @adev.
+ * freed by the ACPI core automatically during the removal of @data.
  *
  * Return: %0 if property with @name has been found (success),
  *         %-EINVAL if the arguments are invalid,
  *         %-ENODATA if the property doesn't exist,
  *         %-EPROTO if the property value type doesn't match @type.
  */
-int acpi_dev_get_property(struct acpi_device *adev, const char *name,
-                         acpi_object_type type, const union acpi_object **obj)
+static int acpi_data_get_property(struct acpi_device_data *data,
+                                 const char *name, acpi_object_type type,
+                                 const union acpi_object **obj)
 {
        const union acpi_object *properties;
        int i;
 
-       if (!adev || !name)
+       if (!data || !name)
                return -EINVAL;
 
-       if (!adev->data.pointer || !adev->data.properties)
+       if (!data->pointer || !data->properties)
                return -ENODATA;
 
-       properties = adev->data.properties;
+       properties = data->properties;
        for (i = 0; i < properties->package.count; i++) {
                const union acpi_object *propname, *propvalue;
                const union acpi_object *property;
@@ -368,11 +374,50 @@ int acpi_dev_get_property(struct acpi_device *adev, const 
char *name,
        }
        return -ENODATA;
 }
+
+/**
+ * acpi_dev_get_property - return an ACPI property with given name.
+ * @adev: ACPI device to get the property from.
+ * @name: Name of the property.
+ * @type: Expected property type.
+ * @obj: Location to store the property value (if not %NULL).
+ */
+int acpi_dev_get_property(struct acpi_device *adev, const char *name,
+                         acpi_object_type type, const union acpi_object **obj)
+{
+       return adev ? acpi_data_get_property(&adev->data, name, type, obj) : 
-EINVAL;
+}
 EXPORT_SYMBOL_GPL(acpi_dev_get_property);
 
+static struct acpi_device_data *acpi_device_data_of_node(struct fwnode_handle 
*fwnode)
+{
+       if (fwnode->type == FWNODE_ACPI) {
+               struct acpi_device *adev = to_acpi_device_node(fwnode);
+               return &adev->data;
+       } else if (fwnode->type == FWNODE_ACPI_DATA) {
+               struct acpi_data_node *dn = to_acpi_data_node(fwnode);
+               return &dn->data;
+       }
+       return NULL;
+}
+
 /**
- * acpi_dev_get_property_array - return an ACPI array property with given name
- * @adev: ACPI device to get property
+ * acpi_node_prop_get - return an ACPI property with given name.
+ * @fwnode: Firmware node to get the property from.
+ * @propname: Name of the property.
+ * @valptr: Location to store a pointer to the property value (if not %NULL).
+ */
+int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname,
+                      void **valptr)
+{
+       return acpi_data_get_property(acpi_device_data_of_node(fwnode),
+                                     propname, ACPI_TYPE_ANY,
+                                     (const union acpi_object **)valptr);
+}
+
+/**
+ * acpi_data_get_property_array - return an ACPI array property with given name
+ * @adev: ACPI data object to get the property from
  * @name: Name of the property
  * @type: Expected type of array elements
  * @obj: Location to store a pointer to the property value (if not NULL)
@@ -381,7 +426,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_property);
  * ACPI object at the location pointed to by @obj if found.
  *
  * Callers must not attempt to free the returned objects.  Those objects will 
be
- * freed by the ACPI core automatically during the removal of @adev.
+ * freed by the ACPI core automatically during the removal of @data.
  *
  * Return: %0 if array property (package) with @name has been found (success),
  *         %-EINVAL if the arguments are invalid,
@@ -389,14 +434,15 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_property);
  *         %-EPROTO if the property is not a package or the type of its 
elements
  *           doesn't match @type.
  */
-int acpi_dev_get_property_array(struct acpi_device *adev, const char *name,
-                               acpi_object_type type,
-                               const union acpi_object **obj)
+static int acpi_data_get_property_array(struct acpi_device_data *data,
+                                       const char *name,
+                                       acpi_object_type type,
+                                       const union acpi_object **obj)
 {
        const union acpi_object *prop;
        int ret, i;
 
-       ret = acpi_dev_get_property(adev, name, ACPI_TYPE_PACKAGE, &prop);
+       ret = acpi_data_get_property(data, name, ACPI_TYPE_PACKAGE, &prop);
        if (ret)
                return ret;
 
@@ -411,7 +457,6 @@ int acpi_dev_get_property_array(struct acpi_device *adev, 
const char *name,
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(acpi_dev_get_property_array);
 
 /**
  * acpi_dev_get_property_reference - returns handle to the referenced object
@@ -516,15 +561,9 @@ int acpi_dev_get_property_reference(struct acpi_device 
*adev,
 }
 EXPORT_SYMBOL_GPL(acpi_dev_get_property_reference);
 
-int acpi_dev_prop_get(struct acpi_device *adev, const char *propname,
-                     void **valptr)
-{
-       return acpi_dev_get_property(adev, propname, ACPI_TYPE_ANY,
-                                    (const union acpi_object **)valptr);
-}
-
-int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
-                             enum dev_prop_type proptype, void *val)
+static int acpi_data_prop_read_single(struct acpi_device_data *data,
+                                     const char *propname,
+                                     enum dev_prop_type proptype, void *val)
 {
        const union acpi_object *obj;
        int ret;
@@ -533,7 +572,7 @@ int acpi_dev_prop_read_single(struct acpi_device *adev, 
const char *propname,
                return -EINVAL;
 
        if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
-               ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_INTEGER, 
&obj);
+               ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, 
&obj);
                if (ret)
                        return ret;
 
@@ -558,7 +597,7 @@ int acpi_dev_prop_read_single(struct acpi_device *adev, 
const char *propname,
                        break;
                }
        } else if (proptype == DEV_PROP_STRING) {
-               ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_STRING, 
&obj);
+               ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, 
&obj);
                if (ret)
                        return ret;
 
@@ -569,6 +608,12 @@ int acpi_dev_prop_read_single(struct acpi_device *adev, 
const char *propname,
        return ret;
 }
 
+int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
+                             enum dev_prop_type proptype, void *val)
+{
+       return adev ? acpi_data_prop_read_single(&adev->data, propname, 
proptype, val) : -EINVAL;
+}
+
 static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
                                       size_t nval)
 {
@@ -645,20 +690,22 @@ static int acpi_copy_property_array_string(const union 
acpi_object *items,
        return 0;
 }
 
-int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
-                      enum dev_prop_type proptype, void *val, size_t nval)
+static int acpi_data_prop_read(struct acpi_device_data *data,
+                              const char *propname,
+                              enum dev_prop_type proptype,
+                              void *val, size_t nval)
 {
        const union acpi_object *obj;
        const union acpi_object *items;
        int ret;
 
        if (val && nval == 1) {
-               ret = acpi_dev_prop_read_single(adev, propname, proptype, val);
+               ret = acpi_data_prop_read_single(data, propname, proptype, val);
                if (!ret)
                        return ret;
        }
 
-       ret = acpi_dev_get_property_array(adev, propname, ACPI_TYPE_ANY, &obj);
+       ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
        if (ret)
                return ret;
 
@@ -694,3 +741,28 @@ int acpi_dev_prop_read(struct acpi_device *adev, const 
char *propname,
        }
        return ret;
 }
+
+int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
+                      enum dev_prop_type proptype, void *val, size_t nval)
+{
+       return adev ? acpi_data_prop_read(&adev->data, propname, proptype, val, 
nval) : -EINVAL;
+}
+
+/**
+ * acpi_node_prop_read - retrieve the value of an ACPI property with given 
name.
+ * @fwnode: Firmware node to get the property from.
+ * @propname: Name of the property.
+ * @proptype: Expected property type.
+ * @val: Location to store the property value (if not %NULL).
+ * @nval: Size of the array pointed to by @val.
+ *
+ * If @val is %NULL, return the number of array elements comprising the value
+ * of the property.  Otherwise, read at most @nval values to the array at the
+ * location pointed to by @val.
+ */
+int acpi_node_prop_read(struct fwnode_handle *fwnode,  const char *propname,
+                       enum dev_prop_type proptype, void *val, size_t nval)
+{
+       return acpi_data_prop_read(acpi_device_data_of_node(fwnode),
+                                  propname, proptype, val, nval);
+}
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 33013b1..dce2331 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -131,7 +131,7 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, 
const char *propname)
        if (is_of_node(fwnode))
                return of_property_read_bool(to_of_node(fwnode), propname);
        else if (is_acpi_node(fwnode))
-               return !acpi_dev_prop_get(to_acpi_node(fwnode), propname, NULL);
+               return !acpi_node_prop_get(fwnode, propname, NULL);
 
        return !!pset_prop_get(to_pset(fwnode), propname);
 }
@@ -295,8 +295,8 @@ EXPORT_SYMBOL_GPL(device_property_read_string);
                _ret_ = OF_DEV_PROP_READ_ARRAY(to_of_node(_fwnode_), 
_propname_, \
                                               _type_, _val_, _nval_); \
        else if (is_acpi_node(_fwnode_)) \
-               _ret_ = acpi_dev_prop_read(to_acpi_node(_fwnode_), _propname_, \
-                                          _proptype_, _val_, _nval_); \
+               _ret_ = acpi_node_prop_read(_fwnode_, _propname_, _proptype_, \
+                                           _val_, _nval_); \
        else if (is_pset(_fwnode_)) \
                _ret_ = pset_prop_read_array(to_pset(_fwnode_), _propname_, \
                                             _proptype_, _val_, _nval_); \
@@ -437,8 +437,8 @@ int fwnode_property_read_string_array(struct fwnode_handle 
*fwnode,
                                                      propname, val, nval) :
                        of_property_count_strings(to_of_node(fwnode), propname);
        else if (is_acpi_node(fwnode))
-               return acpi_dev_prop_read(to_acpi_node(fwnode), propname,
-                                         DEV_PROP_STRING, val, nval);
+               return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
+                                          val, nval);
        else if (is_pset(fwnode))
                return pset_prop_read_array(to_pset(fwnode), propname,
                                            DEV_PROP_STRING, val, nval);
@@ -467,8 +467,8 @@ int fwnode_property_read_string(struct fwnode_handle 
*fwnode,
        if (is_of_node(fwnode))
                return of_property_read_string(to_of_node(fwnode), propname, 
val);
        else if (is_acpi_node(fwnode))
-               return acpi_dev_prop_read(to_acpi_node(fwnode), propname,
-                                         DEV_PROP_STRING, val, 1);
+               return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
+                                          val, 1);
 
        return -ENXIO;
 }
@@ -491,7 +491,7 @@ struct fwnode_handle *device_get_next_child_node(struct 
device *dev,
        } else if (IS_ENABLED(CONFIG_ACPI)) {
                struct acpi_device *node;
 
-               node = acpi_get_next_child(dev, to_acpi_node(child));
+               node = acpi_get_next_child(dev, to_acpi_device_node(child));
                if (node)
                        return acpi_fwnode_handle(node);
        }
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8e53f83..9b51f81 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2062,11 +2062,11 @@ struct gpio_desc *fwnode_get_named_gpiod(struct 
fwnode_handle *fwnode,
                                                &flags);
                if (!IS_ERR(desc))
                        active_low = flags & OF_GPIO_ACTIVE_LOW;
-       } else if (is_acpi_node(fwnode)) {
+       } else if (is_acpi_device_node(fwnode)) {
                struct acpi_gpio_info info;
 
-               desc = acpi_get_gpiod_by_index(to_acpi_node(fwnode), propname, 
0,
-                                              &info);
+               desc = acpi_get_gpiod_by_index(to_acpi_device_node(fwnode),
+                                              propname, 0, &info);
                if (!IS_ERR(desc))
                        active_low = info.active_low;
        }
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index fbbf436..4796899 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -427,15 +427,32 @@ static inline bool acpi_check_dma(struct acpi_device 
*adev, bool *coherent)
 
 static inline bool is_acpi_node(struct fwnode_handle *fwnode)
 {
+       return fwnode && (fwnode->type == FWNODE_ACPI
+               || fwnode->type == FWNODE_ACPI_DATA);
+}
+
+static inline bool is_acpi_device_node(struct fwnode_handle *fwnode)
+{
        return fwnode && fwnode->type == FWNODE_ACPI;
 }
 
-static inline struct acpi_device *to_acpi_node(struct fwnode_handle *fwnode)
+static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle 
*fwnode)
 {
-       return is_acpi_node(fwnode) ?
+       return is_acpi_device_node(fwnode) ?
                container_of(fwnode, struct acpi_device, fwnode) : NULL;
 }
 
+static inline bool is_acpi_data_node(struct fwnode_handle *fwnode)
+{
+       return fwnode && fwnode->type == FWNODE_ACPI_DATA;
+}
+
+static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle 
*fwnode)
+{
+       return is_acpi_data_node(fwnode) ?
+               container_of(fwnode, struct acpi_data_node, fwnode) : NULL;
+}
+
 static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device 
*adev)
 {
        return &adev->fwnode;
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index b78180e..aed41730 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -53,14 +53,14 @@ static inline acpi_handle acpi_device_handle(struct 
acpi_device *adev)
        return adev ? adev->handle : NULL;
 }
 
-#define ACPI_COMPANION(dev)            to_acpi_node((dev)->fwnode)
+#define ACPI_COMPANION(dev)            to_acpi_device_node((dev)->fwnode)
 #define ACPI_COMPANION_SET(dev, adev)  set_primary_fwnode(dev, (adev) ? \
        acpi_fwnode_handle(adev) : NULL)
 #define ACPI_HANDLE(dev)               acpi_device_handle(ACPI_COMPANION(dev))
 
 static inline bool has_acpi_companion(struct device *dev)
 {
-       return is_acpi_node(dev->fwnode);
+       return is_acpi_device_node(dev->fwnode);
 }
 
 static inline void acpi_preset_companion(struct device *dev,
@@ -474,7 +474,22 @@ static inline bool is_acpi_node(struct fwnode_handle 
*fwnode)
        return false;
 }
 
-static inline struct acpi_device *to_acpi_node(struct fwnode_handle *fwnode)
+static inline bool is_acpi_device_node(struct fwnode_handle *fwnode)
+{
+       return false;
+}
+
+static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle 
*fwnode)
+{
+       return NULL;
+}
+
+static inline bool is_acpi_data_node(struct fwnode_handle *fwnode)
+{
+       return false;
+}
+
+static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle 
*fwnode)
 {
        return NULL;
 }
@@ -756,17 +771,16 @@ struct acpi_reference_args {
 #ifdef CONFIG_ACPI
 int acpi_dev_get_property(struct acpi_device *adev, const char *name,
                          acpi_object_type type, const union acpi_object **obj);
-int acpi_dev_get_property_array(struct acpi_device *adev, const char *name,
-                               acpi_object_type type,
-                               const union acpi_object **obj);
 int acpi_dev_get_property_reference(struct acpi_device *adev,
                                    const char *name, size_t index,
                                    struct acpi_reference_args *args);
 
-int acpi_dev_prop_get(struct acpi_device *adev, const char *propname,
-                     void **valptr);
+int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname,
+                      void **valptr);
 int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
                              enum dev_prop_type proptype, void *val);
+int acpi_node_prop_read(struct fwnode_handle *fwnode, const char *propname,
+                       enum dev_prop_type proptype, void *val, size_t nval);
 int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
                       enum dev_prop_type proptype, void *val, size_t nval);
 
@@ -779,13 +793,7 @@ static inline int acpi_dev_get_property(struct acpi_device 
*adev,
 {
        return -ENXIO;
 }
-static inline int acpi_dev_get_property_array(struct acpi_device *adev,
-                                             const char *name,
-                                             acpi_object_type type,
-                                             const union acpi_object **obj)
-{
-       return -ENXIO;
-}
+
 static inline int acpi_dev_get_property_reference(struct acpi_device *adev,
                                const char *name, const char *cells_name,
                                size_t index, struct acpi_reference_args *args)
@@ -793,6 +801,13 @@ static inline int acpi_dev_get_property_reference(struct 
acpi_device *adev,
        return -ENXIO;
 }
 
+static inline int acpi_node_prop_get(struct fwnode_handle *fwnode,
+                                    const char *propname,
+                                    void **valptr)
+{
+       return -ENXIO;
+}
+
 static inline int acpi_dev_prop_get(struct acpi_device *adev,
                                    const char *propname,
                                    void **valptr)
@@ -808,6 +823,14 @@ static inline int acpi_dev_prop_read_single(struct 
acpi_device *adev,
        return -ENXIO;
 }
 
+static inline int acpi_node_prop_read(struct fwnode_handle *fwnode,
+                                     const char *propname,
+                                     enum dev_prop_type proptype,
+                                     void *val, size_t nval)
+{
+       return -ENXIO;
+}
+
 static inline int acpi_dev_prop_read(struct acpi_device *adev,
                                     const char *propname,
                                     enum dev_prop_type proptype,
-- 
1.9.1

-- 
_______________________________________________
linux-yocto mailing list
linux-yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/linux-yocto

Reply via email to