device property: Introduce device_is_compatible()
Subsystems (5)
Andy Shevchenko
reviewercover device property: Introduce device_is_compatible()
Introduce a new helper to tell if device (node) is compatible to the given string value. This will help some drivers to get rid of unneeded OF APIs/etc and in may help others to be agnostic to OF/ACPI.
While doing it, I have noticed that ACPI_DEVICE_CLASS() macro seems defined in unsuitable location. Move it to the better one.
Last patch is an example of what the first two are doing.
The entire series can go, I believe, via ACPI (linux-pm) tree in case the last patch gets tag from the respective maintainer.
Andy Shevchenko (3):
ACPI: Move ACPI_DEVICE_CLASS() to mod_devicetable.h device property: Implement device_is_compatible()
ata: ahci_platform: Make code agnostic to OF/ACPI
drivers/ata/ahci_platform.c | 6 +++--- include/linux/acpi.h | 14 -------------- include/linux/mod_devicetable.h | 13 +++++++++++++ include/linux/property.h | 5 +++++ 4 files changed, 21 insertions(+), 17 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
Andy Shevchenko
reviewerPATCH 2/3 device property: Implement device_is_compatible()
Some users want to use the struct device pointer to see if the device is compatible. Provide inline helpers for them.
--- include/linux/property.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/property.h +5 -0
@@ -85,6 +85,11 @@ bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const charreturn fwnode_property_match_string (fwnode,"compatible" , compat) >=0 ; } +static inline bool device_is_compatible (const struct device *dev,const char *compat) +{ +return fwnode_device_is_compatible (dev_fwnode (dev), compat); +} + int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, const char *prop, const char *nargs_prop, unsigned int nargs, unsigned int index,
Signature · 1 line
2.40.0.1.gaa8946217a0b
Andy Shevchenko
reviewerPATCH 1/3 ACPI: Move ACPI_DEVICE_CLASS() to mod_devicetable.h
In reply to Andy ShevchenkoThe data type of struct acpi_device_id is defined in the mod_devicetable.h. It's suboptimal to require user with the almost agnostic code to include acpi.h solely for the macro that affects the data type defined elsewhere.
Taking into account the above and for the sake of consistency move ACPI_DEVICE_CLASS() to mod_devicetable.h.
Note, that with CONFIG_ACPI=n the ID table will be filed with data but it does not really matter because either it won't be used, or won't be compiled in some cases (when guarded by respective ifdeffery).
--- include/linux/acpi.h | 14 -------------- include/linux/mod_devicetable.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-)
include/linux/acpi.h +0 -14
@@ -70,19 +70,6 @@ static inline void acpi_free_fwnode_static(struct fwnode_handle *fwnode)kfree (fwnode); } -/** -* ACPI_DEVICE_CLASS - macro used to describe an ACPI device with -* the PCI-defined class-code information -* -* @_cls : the class, subclass, prog-if triple for this device -* @_msk : the class mask for this device -* -* This macro is used to create a struct acpi_device_id that matches a -* specific PCI class. The .id and .driver_data fields will be left -* initialized with the default value. -*/ -#define ACPI_DEVICE_CLASS (_cls, _msk) .cls = (_cls), .cls_msk = (_msk), -static inline bool has_acpi_companion (struct device *dev) {return is_acpi_device_node (dev->fwnode);
@@ -782,7 +769,6 @@ const char *acpi_get_subsystem_id(acpi_handle handle);#define ACPI_COMPANION_SET (dev, adev) do { } while (0)#define ACPI_HANDLE (dev) (NULL)#define ACPI_HANDLE_FWNODE (fwnode) (NULL) -#define ACPI_DEVICE_CLASS (_cls, _msk) .cls = (0), .cls_msk = (0),#include <acpi/acpi_numa.h>
include/linux/mod_devicetable.h +13 -0
@@ -221,6 +221,19 @@ struct acpi_device_id {__u32 cls_msk; }; +/** +* ACPI_DEVICE_CLASS - macro used to describe an ACPI device with +* the PCI-defined class-code information +* +* @_cls : the class, subclass, prog-if triple for this device +* @_msk : the class mask for this device +* +* This macro is used to create a struct acpi_device_id that matches a +* specific PCI class. The .id and .driver_data fields will be left +* initialized with the default value. +*/ +#define ACPI_DEVICE_CLASS (_cls, _msk) .cls = (_cls), .cls_msk = (_msk), +#define PNP_ID_LEN 8#define PNP_MAX_DEVICES 8
Signature · 1 line
2.40.0.1.gaa8946217a0b
Andy Shevchenko
reviewerPATCH 3/3 ata: ahci_platform: Make code agnostic to OF/ACPI
In reply to Andy ShevchenkoWith the help of a new device_is_compatible() make the driver code agnostic to the OF/ACPI. This makes it neater. As a side effect the header inclusions is corrected (seems mod_devicetable.h was implicitly included).
--- drivers/ata/ahci_platform.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/ata/ahci_platform.c +3 -3
@@ -12,11 +12,11 @@#include <linux/module.h> #include <linux/pm.h> #include <linux/device.h> -#include <linux/of_device.h> +#include <linux/mod_devicetable.h> +#include <linux/property.h> #include <linux/platform_device.h> #include <linux/libata.h> #include <linux/ahci_platform.h> -#include <linux/acpi.h> #include <linux/pci_ids.h> #include "ahci.h"
@@ -56,7 +56,7 @@ static int ahci_probe(struct platform_device *pdev)if (rc)return rc; -if (of_device_is_compatible (dev->of_node,"hisilicon,hisi-ahci" )) +if (device_is_compatible (dev,"hisilicon,hisi-ahci" )) hpriv->flags |=AHCI_HFLAG_NO_FBS |AHCI_HFLAG_NO_NCQ ; port =acpi_device_get_match_data (dev);
Signature · 1 line
2.40.0.1.gaa8946217a0b
Greg Kroah-Hartman
maintainerRe: [PATCH v1 2/3] device property: Implement device_is_compatible()
In reply to Andy ShevchenkoQuoted 2 lines · Andy Shevchenko
Some users want to use the struct device pointer to see if the device is compatible. Provide inline helpers for them.
What do you mean by "compatible"?
thanks,
greg k-h
Andy Shevchenko
reviewerRe: [PATCH v1 2/3] device property: Implement device_is_compatible()
Quoted 4 lines · Greg Kroah-Hartman
Quoted 2 lines · Andy Shevchenko
Some users want to use the struct device pointer to see if the device is compatible. Provide inline helpers for them.
What do you mean by "compatible"?
In terms of how OF defines it (note that ACPI may also utilize it, so it's wider than there).
I will elaborate this in v2.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [PATCH v1 3/3] ata: ahci_platform: Make code agnostic to OF/ACPI
In reply to Andy ShevchenkoQuoted 5 lines · Andy Shevchenko
With the help of a new
device_is_compatible()make the driver code agnostic to the OF/ACPI. This makes it neater. As a side effect the header inclusions is corrected (seemsmod_devicetable.hwas implicitly included).
...
drivers/ata/ahci_platform.c static int ahci_probe(struct platform_device *pdev) · line 62
Quoted 5 lines
drivers/ata/ahci_platform.c +1
-1-if (of_device_is_compatible (dev->of_node,"hisilicon,hisi-ahci" )) +if (device_is_compatible (dev,"hisilicon,hisi-ahci" )) hpriv->flags |=AHCI_HFLAG_NO_FBS |AHCI_HFLAG_NO_NCQ ; port =acpi_device_get_match_data (dev);
Oops, missed this one, will send a v2. This is Friday :-)
Signature · 2 lines
With Best Regards, Andy Shevchenko