i2c: core: Allow getting acpi info by index
Subsystems (2)
PATCH v2 1/3 i2c: core: Allow getting acpi info by index
Modify struct i2c_acpi_lookup and i2c_acpi_fill_info() to allow using them to get the info from a certain index in the acpi-resource list rather then taking the first I2cSerialBus resource.
--- drivers/i2c/i2c-core.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/i2c/i2c-core.c +7 -0
@@ -112,6 +112,8 @@ struct i2c_acpi_lookup {acpi_handle adapter_handle;acpi_handle device_handle;acpi_handle search_handle; +int n; +int index;u32 speed;u32 min_speed; };
@@ -123,6 +125,9 @@ static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data)struct acpi_resource_i2c_serialbus *sb;acpi_status status; +if (lookup->index !=-1 && lookup->n++ != lookup->index) +return 1 ; +if (info->addr || ares->type !=ACPI_RESOURCE_TYPE_SERIAL_BUS )return 1 ;
@@ -182,6 +187,7 @@ static int i2c_acpi_get_info(struct acpi_device *adev,memset (&lookup,0 ,sizeof (lookup)); lookup.info = info; + lookup.index =-1 ; ret =i2c_acpi_do_lookup (adev, &lookup);if (ret)
@@ -328,6 +334,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev) lookup.search_handle =ACPI_HANDLE (dev); lookup.min_speed =UINT_MAX ; lookup.info = &dummy; + lookup.index =-1 ; status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, I2C_ACPI_MAX_SCAN_DEPTH,
Signature · 1 line
2.9.3
PATCH v2 2/3 i2c: core: Add new i2c_acpi_new_device helper function
By default the i2c subsys creates an i2c-client for the first I2cSerialBus resource of an acpi_device, but some acpi_devices have multiple I2cSerialBus resources and the driver may need access to the others.
This commit adds a new i2c_acpi_new_device function which can be used by drivers to create an i2c-client for any (other) I2cSerialBus resource of an acpi_device.
Note that the other resources may even be on a different i2c bus, so just retrieving the client address is not enough.
--- drivers/i2c/i2c-core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 5 +++++ 2 files changed, 53 insertions(+)
drivers/i2c/i2c-core.c +48 -0
@@ -421,6 +421,54 @@ static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,static struct notifier_block i2c_acpi_notifier = { .notifier_call = i2c_acpi_notify, }; + +/** +* i2c_acpi_new_device - Create i2c client for the Nth acpi resource of dev +* @dev: Device owning the acpi resources to get the client from +* @index: Index of acpi resource to get +* +* By default the i2c subsys creates an i2c-client for the first I2cSerialBus +* resource of an acpi_device, but some acpi_devices have multiple +* I2cSerialBus resources and the driver may need access to the others. +* This function can be used by drivers to create an i2c-client for any +* resource of an acpi_device. +* +* Returns a pointer to the new i2c-client, or NULL if the resource or +* adapter were not found. +*/ +struct i2c_client *i2c_acpi_new_device (struct device *dev,int index) +{ +struct i2c_acpi_lookup lookup; +struct i2c_board_info info; +struct i2c_adapter *adapter; +struct acpi_device *adev; +LIST_HEAD (resource_list); +int ret; + + adev =ACPI_COMPANION (dev); +if (!adev) +return NULL ; + +memset (&info,0 ,sizeof (info)); +memset (&lookup,0 ,sizeof (lookup)); + lookup.info = &info; + lookup.device_handle =acpi_device_handle (adev); + lookup.index = index; + + ret =acpi_dev_get_resources (adev, &resource_list, + i2c_acpi_fill_info, &lookup); +acpi_dev_free_resource_list (&resource_list); + +if (ret <0 || !info.addr) +return NULL ; + + adapter =i2c_acpi_find_adapter_by_handle (lookup.adapter_handle); +if (!adapter) +return NULL ; + +return i2c_new_device (adapter, &info); +} +EXPORT_SYMBOL_GPL (i2c_acpi_new_device);#else /* CONFIG_ACPI */ static inline void i2c_acpi_register_devices (struct i2c_adapter *adap) { }extern struct notifier_block i2c_acpi_notifier;
include/linux/i2c.h +5 -0
@@ -824,11 +824,16 @@ static inline const struct of_device_id#if IS_ENABLED (CONFIG_ACPI )u32 i2c_acpi_find_bus_speed (struct device *dev); +struct i2c_client *i2c_acpi_new_device (struct device *dev,int index);#else static inline u32 i2c_acpi_find_bus_speed (struct device *dev) {return 0 ; } +static inline struct i2c_client *i2c_acpi_new_device (struct device *d,int i) +{ +return NULL ; +}#endif /* CONFIG_ACPI */ #endif /* _LINUX_I2C_H */
Signature · 1 line
2.9.3
PATCH v2 3/3 i2c: core: Allow drivers to specify index for irq to get from of / acpi
In reply to Hans de GoedeSome of or acpi declared / enumerated devices may have multiple irq resources declared and the driver may want to use a different irq then the one with index 0.
This commit adds a new irq_index field to struct i2c_driver and makes the i2c-core pass this to of_irq_get / acpi_dev_gpio_irq_get.
This is esp. useful for acpi declared devices where the irq with index 0 may be entirely useless and cause i2c_device_probe to fail with -EPROBE_DEFER.
---
Changes in v2:
-Actually also use the irq_index for of interrupts
--- drivers/i2c/i2c-core.c | 8 ++++++-- include/linux/i2c.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core.c +6 -2
@@ -984,6 +984,8 @@ static int i2c_device_probe(struct device *dev)if (!client)return 0 ; + driver =to_i2c_driver (dev->driver); +if (!client->irq) {int irq = -ENOENT ;
@@ -993,9 +995,11 @@ static int i2c_device_probe(struct device *dev) }else if (dev->of_node) { irq =of_irq_get_byname (dev->of_node,"irq" );if (irq == -EINVAL || irq == -ENODATA ) - irq =of_irq_get (dev->of_node,0 ); + irq =of_irq_get (dev->of_node, + driver->irq_index); }else if (ACPI_COMPANION (dev)) { - irq =acpi_dev_gpio_irq_get (ACPI_COMPANION (dev),0 ); + irq =acpi_dev_gpio_irq_get (ACPI_COMPANION (dev), + driver->irq_index); }if (irq == -EPROBE_DEFER )return irq;
include/linux/i2c.h +3 -0
@@ -212,6 +212,9 @@ struct i2c_driver {int (*detect)(struct i2c_client *,struct i2c_board_info *);const unsigned short *address_list;struct list_head clients; + +/* IRQ index for retreiving irq from ACPI resources */ +int irq_index; };#define to_i2c_driver (d) container_of(d, struct i2c_driver, driver)
Signature · 1 line
2.9.3