Skip to content

Commit

Permalink
i2c: i2c-core-acpi: Add i2c_acpi_dev_name()
Browse files Browse the repository at this point in the history
We want to refer to an i2c device by name before it has been
created by the kernel; add a function that constructs the name
from the acpi device instead.

Signed-off-by: Daniel Scally <djrscally@gmail.com>
Patchset: cameras
  • Loading branch information
djrscally authored and qzed committed Feb 15, 2021
1 parent 0502b78 commit 40e472f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/i2c/i2c-core-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
}
EXPORT_SYMBOL_GPL(i2c_acpi_new_device);

/**
* i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
* @adev: ACPI device to construct the name for
*
* Constructs the name of an i2c device matching the format used by
* i2c_dev_set_name() to allow users to refer to an i2c device by name even
* before they have been instantiated.
*
* The caller is responsible for freeing the returned pointer.
*/
char *i2c_acpi_dev_name(struct acpi_device *adev)
{
return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
}
EXPORT_SYMBOL_GPL(i2c_acpi_dev_name);

#ifdef CONFIG_ACPI_I2C_OPREGION
static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
u8 cmd, u8 *data, u8 data_len)
Expand Down
1 change: 1 addition & 0 deletions include/linux/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
u32 i2c_acpi_find_bus_speed(struct device *dev);
struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
struct i2c_board_info *info);
char *i2c_acpi_dev_name(struct acpi_device *adev);
struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
#else
static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
Expand Down

0 comments on commit 40e472f

Please sign in to comment.