* [PATCH v2 1/3] i2c: core: Allow getting acpi info by index
@ 2017-03-10 23:57 Hans de Goede
2017-03-10 23:57 ` [PATCH v2 2/3] i2c: core: Add new i2c_acpi_new_device helper function Hans de Goede
2017-03-10 23:57 ` [PATCH v2 3/3] i2c: core: Allow drivers to specify index for irq to get from of / acpi Hans de Goede
0 siblings, 2 replies; 3+ messages in thread
From: Hans de Goede @ 2017-03-10 23:57 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c, Hans de Goede
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.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/i2c/i2c-core.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index d2402bb..32b58fb 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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,
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/3] i2c: core: Add new i2c_acpi_new_device helper function
2017-03-10 23:57 [PATCH v2 1/3] i2c: core: Allow getting acpi info by index Hans de Goede
@ 2017-03-10 23:57 ` Hans de Goede
2017-03-10 23:57 ` [PATCH v2 3/3] i2c: core: Allow drivers to specify index for irq to get from of / acpi Hans de Goede
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2017-03-10 23:57 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c, Hans de Goede
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.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/i2c/i2c-core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/i2c.h | 5 +++++
2 files changed, 53 insertions(+)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 32b58fb..8ddd55b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6b18352..369ebfa 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -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 */
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 3/3] i2c: core: Allow drivers to specify index for irq to get from of / acpi
2017-03-10 23:57 [PATCH v2 1/3] i2c: core: Allow getting acpi info by index Hans de Goede
2017-03-10 23:57 ` [PATCH v2 2/3] i2c: core: Add new i2c_acpi_new_device helper function Hans de Goede
@ 2017-03-10 23:57 ` Hans de Goede
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2017-03-10 23:57 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c, Hans de Goede
Some 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.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
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(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 8ddd55b..f016278 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 369ebfa..a5ffe29 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -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)
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-10 23:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-10 23:57 [PATCH v2 1/3] i2c: core: Allow getting acpi info by index Hans de Goede
2017-03-10 23:57 ` [PATCH v2 2/3] i2c: core: Add new i2c_acpi_new_device helper function Hans de Goede
2017-03-10 23:57 ` [PATCH v2 3/3] i2c: core: Allow drivers to specify index for irq to get from of / acpi Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).