Skip to content

Commit c537be0

Browse files
committed
i2c: acpi: Add i2c_acpi_new_device_by_fwnode() function
Change i2c_acpi_new_device() into i2c_acpi_new_device_by_fwnode() and add a static inline wrapper providing the old i2c_acpi_new_device() behavior. This is necessary because in some cases we may only have access to the fwnode / acpi_device and not to the matching physical-node struct device *. Suggested-by: Andy Shevchenko <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Mika Westerberg <[email protected]> Acked-by: Wolfram Sang <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fb90e58 commit c537be0

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

drivers/i2c/i2c-core-acpi.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ struct notifier_block i2c_acpi_notifier = {
476476
};
477477

478478
/**
479-
* i2c_acpi_new_device - Create i2c-client for the Nth I2cSerialBus resource
480-
* @dev: Device owning the ACPI resources to get the client from
479+
* i2c_acpi_new_device_by_fwnode - Create i2c-client for the Nth I2cSerialBus resource
480+
* @fwnode: fwnode with the ACPI resources to get the client from
481481
* @index: Index of ACPI resource to get
482482
* @info: describes the I2C device; note this is modified (addr gets set)
483483
* Context: can sleep
@@ -493,15 +493,20 @@ struct notifier_block i2c_acpi_notifier = {
493493
* Returns a pointer to the new i2c-client, or error pointer in case of failure.
494494
* Specifically, -EPROBE_DEFER is returned if the adapter is not found.
495495
*/
496-
struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
497-
struct i2c_board_info *info)
496+
struct i2c_client *i2c_acpi_new_device_by_fwnode(struct fwnode_handle *fwnode,
497+
int index,
498+
struct i2c_board_info *info)
498499
{
499-
struct acpi_device *adev = ACPI_COMPANION(dev);
500500
struct i2c_acpi_lookup lookup;
501501
struct i2c_adapter *adapter;
502+
struct acpi_device *adev;
502503
LIST_HEAD(resource_list);
503504
int ret;
504505

506+
adev = to_acpi_device_node(fwnode);
507+
if (!adev)
508+
return ERR_PTR(-ENODEV);
509+
505510
memset(&lookup, 0, sizeof(lookup));
506511
lookup.info = info;
507512
lookup.device_handle = acpi_device_handle(adev);
@@ -523,7 +528,7 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
523528

524529
return i2c_new_client_device(adapter, info);
525530
}
526-
EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
531+
EXPORT_SYMBOL_GPL(i2c_acpi_new_device_by_fwnode);
527532

528533
bool i2c_acpi_waive_d0_probe(struct device *dev)
529534
{

include/linux/i2c.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,8 +1025,9 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
10251025
struct acpi_resource_i2c_serialbus **i2c);
10261026
int i2c_acpi_client_count(struct acpi_device *adev);
10271027
u32 i2c_acpi_find_bus_speed(struct device *dev);
1028-
struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
1029-
struct i2c_board_info *info);
1028+
struct i2c_client *i2c_acpi_new_device_by_fwnode(struct fwnode_handle *fwnode,
1029+
int index,
1030+
struct i2c_board_info *info);
10301031
struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
10311032
bool i2c_acpi_waive_d0_probe(struct device *dev);
10321033
#else
@@ -1043,8 +1044,9 @@ static inline u32 i2c_acpi_find_bus_speed(struct device *dev)
10431044
{
10441045
return 0;
10451046
}
1046-
static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
1047-
int index, struct i2c_board_info *info)
1047+
static inline struct i2c_client *i2c_acpi_new_device_by_fwnode(
1048+
struct fwnode_handle *fwnode, int index,
1049+
struct i2c_board_info *info)
10481050
{
10491051
return ERR_PTR(-ENODEV);
10501052
}
@@ -1058,4 +1060,11 @@ static inline bool i2c_acpi_waive_d0_probe(struct device *dev)
10581060
}
10591061
#endif /* CONFIG_ACPI */
10601062

1063+
static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
1064+
int index,
1065+
struct i2c_board_info *info)
1066+
{
1067+
return i2c_acpi_new_device_by_fwnode(dev_fwnode(dev), index, info);
1068+
}
1069+
10611070
#endif /* _LINUX_I2C_H */

0 commit comments

Comments
 (0)