device property: Introduce device_is_compatible()
Subsystems (5)
Andy Shevchenko
reviewerPATCH v3 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/ata/ahci_platform.c +4 -4
@@ -9,14 +9,14 @@*/ #include <linux/kernel.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/pm.h> #include <linux/device.h> -#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/libata.h> #include <linux/ahci_platform.h> -#include <linux/acpi.h> #include <linux/pci_ids.h> #include "ahci.h"
@@ -56,10 +56,10 @@ 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); + port =device_get_match_data (dev);if (!port) port = &ahci_port_info;
Signature · 1 line
2.40.0.1.gaa8946217a0b
Andy Shevchenko
reviewerv3 cover 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.
In v3:
- added tag to patch 1 (Rafael), patches 2&3 (Sakari)
- made commit message text wider in patch 3 (Sakari)
In v2:
- updated commit message and added kernel doc for a new API (Greg)
- also replaced acpi_device_get_match_data() with the agnostic API
- tried to keep header inclusions ordered (to some extent)
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 | 8 ++++---- include/linux/acpi.h | 14 -------------- include/linux/mod_devicetable.h | 13 +++++++++++++ include/linux/property.h | 12 ++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
Andy Shevchenko
reviewerPATCH v3 2/3 device property: Implement device_is_compatible()
Some users want to use the struct device pointer to see if the device is compatible in terms of Open Firmware specifications, i.e. if it has a 'compatible' property and it matches to the given value. Provide inline helper for the users.
--- include/linux/property.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/property.h +12 -0
@@ -90,6 +90,18 @@ bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const charreturn fwnode_property_match_string (fwnode,"compatible" , compat) >=0 ; } +/** +* device_is_compatible - match 'compatible' property of the device with a given string +* @dev: Pointer to the struct device +* @compat: The string to match 'compatible' property with +* +* Returns: true if matches, otherwise false. +*/ +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 v3 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
Re: [PATCH v3 3/3] ata: ahci_platform: Make code agnostic to OF/ACPI
In reply to Andy ShevchenkoQuoted 7 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).Reviewed-by Sakari Ailus <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v3 2/3] device property: Implement device_is_compatible()
In reply to Andy ShevchenkoQuoted 7 lines · Andy Shevchenko
Some users want to use the struct device pointer to see if the device is compatible in terms of Open Firmware specifications, i.e. if it has a 'compatible' property and it matches to the given value. Provide inline helper for the users.
Reviewed-by Sakari Ailus <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
C/P v2: IMO much useful wrapper. Thanks for the patch.
-Serge(y)
Quoted 31 lines
--- include/linux/property.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/property.h +12
-0@@ -90,6 +90,18 @@ bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const charreturn fwnode_property_match_string (fwnode,"compatible" , compat) >=0 ; } +/** +* device_is_compatible - match 'compatible' property of the device with a given string +* @dev: Pointer to the struct device +* @compat: The string to match 'compatible' property with +* +* Returns: true if matches, otherwise false. +*/ +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
Re: [PATCH v3 3/3] ata: ahci_platform: Make code agnostic to OF/ACPI
In reply to Andy ShevchenkoQuoted 7 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).Reviewed-by Sakari Ailus <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
C/P v2:
I don't think the driver will get to be fully agnostic after this patch because for instance the ahci_platform_get_resources() method directly uses the OF-available functions, walks over the OF subnodes, touches the OF-properties, etc. So AFAICS in order to be fully OF/ACPI agnostic the entire libahci_platform.o driver needs to be converted too, but it's not trivial at all.
Anyway as a start this patch looks good.
-Serge(y)
Quoted 42 lines
--- drivers/ata/ahci_platform.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/ata/ahci_platform.c +4
-4@@ -9,14 +9,14 @@*/ #include <linux/kernel.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/pm.h> #include <linux/device.h> -#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/libata.h> #include <linux/ahci_platform.h> -#include <linux/acpi.h> #include <linux/pci_ids.h> #include "ahci.h" @@ -56,10 +56,10 @@ 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); + port =device_get_match_data (dev);if (!port) port = &ahci_port_info;Signature · 1 line
2.40.0.1.gaa8946217a0b
Rafael J. Wysocki
maintainerQuoted 27 lines · Andy Shevchenko
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.
In v3:
- added tag to patch 1 (Rafael), patches 2&3 (Sakari)
- made commit message text wider in patch 3 (Sakari)In v2:
- updated commit message and added kernel doc for a new API (Greg)
- also replacedacpi_device_get_match_data()with the agnostic API
- tried to keep header inclusions ordered (to some extent)Andy Shevchenko (3):
ACPI: MoveACPI_DEVICE_CLASS()tomod_devicetable.hdevice property: Implementdevice_is_compatible()
ata:ahci_platform: Make code agnostic to OF/ACPI
Quoted 7 lines
drivers/ata/ahci_platform.c | 8 ++++---- include/linux/acpi.h | 14 -------------- include/linux/mod_devicetable.h | 13 +++++++++++++ include/linux/property.h | 12 ++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-)--
All applied as 6.5 material, thanks!
Rafael J. Wysocki
maintainerQuoted 36 lines · Rafael J. Wysocki
Quoted 33 lines · Andy Shevchenko
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.
In v3:
- added tag to patch 1 (Rafael), patches 2&3 (Sakari)
- made commit message text wider in patch 3 (Sakari)In v2:
- updated commit message and added kernel doc for a new API (Greg)
- also replacedacpi_device_get_match_data()with the agnostic API
- tried to keep header inclusions ordered (to some extent)Andy Shevchenko (3):
ACPI: MoveACPI_DEVICE_CLASS()tomod_devicetable.hdevice property: Implementdevice_is_compatible()
ata:ahci_platform: Make code agnostic to OF/ACPIdrivers/ata/ahci_platform.c | 8 ++++---- include/linux/acpi.h | 14 -------------- include/linux/mod_devicetable.h | 13 +++++++++++++ include/linux/property.h | 12 ++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-)
Quoted 3 lines
Quoted 1 line
--
All applied as 6.5 material, thanks!
But I see that Greg has taken it too, so I'll drop it.
Andy Shevchenko
reviewerQuoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Andy Shevchenko
--
All applied as 6.5 material, thanks!
But I see that Greg has taken it too, so I'll drop it.
Yep, thank you, guys!
Signature · 2 lines
With Best Regards, Andy Shevchenko