From patchwork Sun May 20 13:28:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjRq1vvKz9s4V for ; Sun, 20 May 2018 23:29:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751428AbeETN3H (ORCPT ); Sun, 20 May 2018 09:29:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41662 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751372AbeETN3F (ORCPT ); Sun, 20 May 2018 09:29:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3010BB414; Sun, 20 May 2018 13:29:04 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 293AE215CDA7; Sun, 20 May 2018 13:29:03 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 1/9] ACPI: export __acpi_match_device and __acpi_device[_uevent]_modalias Date: Sun, 20 May 2018 15:28:49 +0200 Message-Id: <20180520132857.8103-2-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 20 May 2018 13:29:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 20 May 2018 13:29:04 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Normally __acpi_match_device and __acpi_device[_uevent]_modalias are only called through functions calling acpi_companion_match() so that if their are multiple devices sharing the ACPI firmware node only one matches / gets the acpi:ACPIHID modalias. Some DSDTs defines multiple i2c devices in a single apci_device and in the i2c-core-acpi code we want to instantiate separate devices for these, with all devices reporting / matching the acpi_devices's modalias. This commit exports __acpi_match_device and __acpi_device[_uevent]_modalias for use in the i2c-core-acpi code only, with a comment added that they should not be used in normal code. Signed-off-by: Hans de Goede --- drivers/acpi/bus.c | 11 ++++++----- drivers/acpi/device_sysfs.c | 4 +++- include/linux/acpi.h | 11 +++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 84b4a62018eb..29a0e8fa2a13 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -767,11 +767,11 @@ static bool __acpi_match_device_cls(const struct acpi_device_id *id, return true; } -static bool __acpi_match_device(struct acpi_device *device, - const struct acpi_device_id *acpi_ids, - const struct of_device_id *of_ids, - const struct acpi_device_id **acpi_id, - const struct of_device_id **of_id) +bool __acpi_match_device(struct acpi_device *device, + const struct acpi_device_id *acpi_ids, + const struct of_device_id *of_ids, + const struct acpi_device_id **acpi_id, + const struct of_device_id **of_id) { const struct acpi_device_id *id; struct acpi_hardware_id *hwid; @@ -808,6 +808,7 @@ static bool __acpi_match_device(struct acpi_device *device, *acpi_id = id; return true; } +EXPORT_SYMBOL_GPL(__acpi_match_device); /** * acpi_match_device - Match a struct device against a given list of ACPI IDs diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 545e91420cde..e6d784ef00da 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -276,6 +276,7 @@ int __acpi_device_uevent_modalias(struct acpi_device *adev, return 0; } +EXPORT_SYMBOL_GPL(__acpi_device_uevent_modalias); /** * acpi_device_uevent_modalias - uevent modalias for ACPI-enumerated devices. @@ -291,7 +292,7 @@ int acpi_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) } EXPORT_SYMBOL_GPL(acpi_device_uevent_modalias); -static int __acpi_device_modalias(struct acpi_device *adev, char *buf, int size) +int __acpi_device_modalias(struct acpi_device *adev, char *buf, int size) { int len, count; @@ -321,6 +322,7 @@ static int __acpi_device_modalias(struct acpi_device *adev, char *buf, int size) return len; } +EXPORT_SYMBOL_GPL(__acpi_device_modalias); /** * acpi_device_modalias - modalias sysfs attribute for ACPI-enumerated devices. diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 15bfb15c2fa5..cf97902792a5 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -586,12 +586,23 @@ extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *), const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, const struct device *dev); +/* Skips the acpi_companion_match() check, normal code must not use this */ +bool __acpi_match_device(struct acpi_device *device, + const struct acpi_device_id *acpi_ids, + const struct of_device_id *of_ids, + const struct acpi_device_id **acpi_id, + const struct of_device_id **of_id); const void *acpi_device_get_match_data(const struct device *dev); extern bool acpi_driver_match_device(struct device *dev, const struct device_driver *drv); int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *); +/* Skips the acpi_companion_match() check, normal code must not use this */ +int __acpi_device_uevent_modalias(struct acpi_device *adev, + struct kobj_uevent_env *env); int acpi_device_modalias(struct device *, char *, int); +/* Skips the acpi_companion_match() check, normal code must not use this */ +int __acpi_device_modalias(struct acpi_device *adev, char *buf, int size); void acpi_walk_dep_device_list(acpi_handle handle); struct platform_device *acpi_create_platform_device(struct acpi_device *, From patchwork Sun May 20 13:28:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjRt0Qr4z9s4b for ; Sun, 20 May 2018 23:29:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751460AbeETN3I (ORCPT ); Sun, 20 May 2018 09:29:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41372 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751421AbeETN3H (ORCPT ); Sun, 20 May 2018 09:29:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C40E40201A2; Sun, 20 May 2018 13:29:06 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id E584C215CDA7; Sun, 20 May 2018 13:29:04 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 2/9] i2c: Allow specifying irq-index to be used in i2c_device_probe() Date: Sun, 20 May 2018 15:28:50 +0200 Message-Id: <20180520132857.8103-3-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Some types of interrupts are retrieved in i2c_device_probe() because getting them might fail with -EPROBE_DEFER. So far we've always assumed the first IRQ (index 0) in the firmware-node is the one we want. At least with ACPI enumerated i2c-clients in some cases the firmware-node is shared between multiple i2c-clients so we need to be able to specify the index rather then hardcoding it at 0. This commit adds a new fwnode_irq_index member to i2c_board_info and i2c_client which allows specifying the index. Signed-off-by: Hans de Goede Reviewed-by: Andy Shevchenko --- drivers/i2c/i2c-core-base.c | 7 +++++-- include/linux/i2c.h | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 1ba40bb2b966..ae3fda2c96a4 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -312,9 +312,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, + client->fwnode_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), + client->fwnode_irq_index); } if (irq == -EPROBE_DEFER) return irq; @@ -724,6 +726,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) client->flags = info->flags; client->addr = info->addr; + client->fwnode_irq_index = info->fwnode_irq_index; client->irq = info->irq; if (!client->irq) client->irq = i2c_dev_irq_from_resources(info->resources, diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 44ad14e016b5..7f9506714a5e 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -316,6 +316,8 @@ struct i2c_driver { * generic enough to hide second-sourcing and compatible revisions. * @adapter: manages the bus segment hosting this I2C device * @dev: Driver model device node for the slave. + * @fwnode_irq_index: some devices share a single fwnode, this tells + * i2c_device_probe() to use the Nth irq from the fwnode * @irq: indicates the IRQ generated by this device (if any) * @detected: member of an i2c_driver.clients list or i2c-core's * userspace_devices list @@ -334,6 +336,7 @@ struct i2c_client { char name[I2C_NAME_SIZE]; struct i2c_adapter *adapter; /* the adapter we sit on */ struct device dev; /* the device structure */ + int fwnode_irq_index; /* index for irq lookup */ int irq; /* irq issued by device */ struct list_head detected; #if IS_ENABLED(CONFIG_I2C_SLAVE) @@ -400,6 +403,7 @@ static inline bool i2c_detect_slave_mode(struct device *dev) { return false; } * @properties: additional device properties for the device * @resources: resources associated with the device * @num_resources: number of resources in the @resources array + * @fwnode_irq_index: stored in i2c_client.fwnode_irq_index * @irq: stored in i2c_client.irq * * I2C doesn't actually support hardware probing, although controllers and @@ -425,6 +429,7 @@ struct i2c_board_info { const struct property_entry *properties; const struct resource *resources; unsigned int num_resources; + int fwnode_irq_index; int irq; }; From patchwork Sun May 20 13:28:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjRt6M4Nz9s3x for ; Sun, 20 May 2018 23:29:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751521AbeETN3L (ORCPT ); Sun, 20 May 2018 09:29:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41386 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751372AbeETN3I (ORCPT ); Sun, 20 May 2018 09:29:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44263401DEA6; Sun, 20 May 2018 13:29:08 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEC21215CDA7; Sun, 20 May 2018 13:29:06 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 3/9] i2c: acpi: Introduce i2c_acpi_get_i2c_resource() helper Date: Sun, 20 May 2018 15:28:51 +0200 Message-Id: <20180520132857.8103-4-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:08 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Andy Shevchenko Besides current two users one more is coming. Definitely makes sense to introduce a helper. No functional change intended. Signed-off-by: Andy Shevchenko Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-acpi.c | 31 +++++++++++++++++++------------ include/linux/acpi.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index 7c3b4740b94b..7b1b0aeced36 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -45,6 +45,23 @@ struct i2c_acpi_lookup { u32 min_speed; }; +bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, + struct acpi_resource_i2c_serialbus **i2c) +{ + struct acpi_resource_i2c_serialbus *sb; + + if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) + return false; + + sb = &ares->data.i2c_serial_bus; + if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) + return false; + + *i2c = sb; + return true; +} +EXPORT_SYMBOL_GPL(i2c_acpi_get_i2c_resource); + static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data) { struct i2c_acpi_lookup *lookup = data; @@ -52,11 +69,7 @@ static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data) struct acpi_resource_i2c_serialbus *sb; acpi_status status; - if (info->addr || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) - return 1; - - sb = &ares->data.i2c_serial_bus; - if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) + if (info->addr || !i2c_acpi_get_i2c_resource(ares, &sb)) return 1; if (lookup->index != -1 && lookup->n++ != lookup->index) @@ -516,13 +529,7 @@ i2c_acpi_space_handler(u32 function, acpi_physical_address command, goto err; } - if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) { - ret = AE_BAD_PARAMETER; - goto err; - } - - sb = &ares->data.i2c_serial_bus; - if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) { + if (!value64 || !i2c_acpi_get_i2c_resource(ares, &sb)) { ret = AE_BAD_PARAMETER; goto err; } diff --git a/include/linux/acpi.h b/include/linux/acpi.h index cf97902792a5..f97c70f8ba4b 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1062,6 +1062,17 @@ static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) } #endif +#if defined(CONFIG_ACPI) && IS_ENABLED(CONFIG_I2C) +bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, + struct acpi_resource_i2c_serialbus **i2c); +#else +static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, + struct acpi_resource_i2c_serialbus **i2c) +{ + return false; +} +#endif + /* Device properties */ #define MAX_ACPI_REFERENCE_ARGS 8 From patchwork Sun May 20 13:28:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjRy00gmz9s3x for ; Sun, 20 May 2018 23:29:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751549AbeETN3M (ORCPT ); Sun, 20 May 2018 09:29:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41400 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751514AbeETN3K (ORCPT ); Sun, 20 May 2018 09:29:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BC40401DEAC; Sun, 20 May 2018 13:29:10 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 768D6215CDA7; Sun, 20 May 2018 13:29:08 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 4/9] i2c: acpi: Allow get info by index in i2c_acpi_get_info() Date: Sun, 20 May 2018 15:28:52 +0200 Message-Id: <20180520132857.8103-5-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:10 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Andy Shevchenko For some devices we need to get info based on index. As a preparation of support such, slightly modify i2c_acpi_get_info() helper. While here, assume that interrupt resources are provided in the same amount with 1:1 mapping to serial bus resources. This will not affect existing behaviour because only first resource of each type is considered. Signed-off-by: Andy Shevchenko Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-acpi.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index 7b1b0aeced36..75352b3744e5 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -129,17 +129,19 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev, static int i2c_acpi_get_info(struct acpi_device *adev, struct i2c_board_info *info, + int index, struct i2c_adapter *adapter, acpi_handle *adapter_handle) { struct list_head resource_list; struct resource_entry *entry; struct i2c_acpi_lookup lookup; + unsigned int n; int ret; memset(&lookup, 0, sizeof(lookup)); lookup.info = info; - lookup.index = -1; + lookup.index = index; ret = i2c_acpi_do_lookup(adev, &lookup); if (ret) @@ -170,10 +172,13 @@ static int i2c_acpi_get_info(struct acpi_device *adev, if (ret < 0) return -EINVAL; + n = 0; resource_list_for_each_entry(entry, &resource_list) { if (resource_type(entry->res) == IORESOURCE_IRQ) { - info->irq = entry->res->start; - break; + if (index == -1 || n++ == index) { + info->irq = entry->res->start; + break; + } } } @@ -210,7 +215,7 @@ static acpi_status i2c_acpi_add_device(acpi_handle handle, u32 level, if (acpi_bus_get_device(handle, &adev)) return AE_OK; - if (i2c_acpi_get_info(adev, &info, adapter, NULL)) + if (i2c_acpi_get_info(adev, &info, -1, adapter, NULL)) return AE_OK; i2c_acpi_register_device(adapter, adev, &info); @@ -356,7 +361,7 @@ static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value, switch (value) { case ACPI_RECONFIG_DEVICE_ADD: - if (i2c_acpi_get_info(adev, &info, NULL, &adapter_handle)) + if (i2c_acpi_get_info(adev, &info, -1, NULL, &adapter_handle)) break; adapter = i2c_acpi_find_adapter_by_handle(adapter_handle); From patchwork Sun May 20 13:28:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjRy6Cy8z9s4V for ; Sun, 20 May 2018 23:29:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751669AbeETN3P (ORCPT ); Sun, 20 May 2018 09:29:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41412 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751529AbeETN3M (ORCPT ); Sun, 20 May 2018 09:29:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C87CA401DEB1; Sun, 20 May 2018 13:29:11 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DE11215CDA7; Sun, 20 May 2018 13:29:10 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 5/9] i2c: acpi: Enumerate several instances out of one device Date: Sun, 20 May 2018 15:28:53 +0200 Message-Id: <20180520132857.8103-6-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:11 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Andy Shevchenko Some broken BIOSes provide one ACPI node for several same I2C devices. Introduce a quirk to handle this case with a list of such devices. [hdegoede@redhat.com: Add and use i2c_acpi_device_uevent() and i2c_acpi_device_modalias() helpers] Signed-off-by: Andy Shevchenko Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-acpi.c | 101 ++++++++++++++++++++++++++++++++++-- drivers/i2c/i2c-core-base.c | 6 +-- drivers/i2c/i2c-core.h | 13 +++++ 3 files changed, 112 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index 75352b3744e5..f2f9048caffd 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -105,8 +105,10 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev, struct list_head resource_list; int ret; - if (acpi_bus_get_status(adev) || !adev->status.present || - acpi_device_enumerated(adev)) + if (acpi_bus_get_status(adev) || !adev->status.present) + return -EINVAL; + + if (lookup->index < 0 && acpi_device_enumerated(adev)) return -EINVAL; if (acpi_match_device_ids(adev, i2c_acpi_ignored_device_ids) == 0) @@ -187,6 +189,8 @@ static int i2c_acpi_get_info(struct acpi_device *adev, acpi_set_modalias(adev, dev_name(&adev->dev), info->type, sizeof(info->type)); + info->fwnode_irq_index = index == -1 ? 0 : index; + return 0; } @@ -205,20 +209,73 @@ static void i2c_acpi_register_device(struct i2c_adapter *adapter, } } +static const struct acpi_device_id i2c_acpi_multiple_devices_ids[] = { + /* + * Some devices are defined as a single ACPI entry while + * providing more than one instance of the same IP. Try to + * enumerate them all. + */ + { "BOSC0200", 0 }, + { "INT3515", 0 }, + {} +}; + +static int i2c_acpi_check_resource(struct acpi_resource *ares, void *data) +{ + struct acpi_resource_i2c_serialbus *sb; + int *count = data; + + if (i2c_acpi_get_i2c_resource(ares, &sb)) + *count = *count + 1; + + return 1; +} + +static int i2c_acpi_count_resource(struct acpi_device *adev) +{ + LIST_HEAD(r); + int count = 0; + int ret; + + ret = acpi_dev_get_resources(adev, &r, i2c_acpi_check_resource, &count); + if (ret < 0) + return ret; + + acpi_dev_free_resource_list(&r); + return count; +} + static acpi_status i2c_acpi_add_device(acpi_handle handle, u32 level, void *data, void **return_value) { struct i2c_adapter *adapter = data; struct acpi_device *adev; struct i2c_board_info info; + int index, count; + char name[16]; if (acpi_bus_get_device(handle, &adev)) return AE_OK; - if (i2c_acpi_get_info(adev, &info, -1, adapter, NULL)) - return AE_OK; + if (!acpi_match_device_ids(adev, i2c_acpi_multiple_devices_ids)) { + count = i2c_acpi_count_resource(adev); + if (count < 0) + return AE_OK; + } else { + count = 1; + } + + for (index = 0; index < count; index++) { + if (i2c_acpi_get_info(adev, &info, index, adapter, NULL)) + return AE_OK; + + if (count > 1) { + sprintf(name, "%s.%d", acpi_dev_name(adev), index); + info.dev_name = name; + } - i2c_acpi_register_device(adapter, adev, &info); + i2c_acpi_register_device(adapter, adev, &info); + } return AE_OK; } @@ -252,12 +309,46 @@ const struct acpi_device_id * i2c_acpi_match_device(const struct acpi_device_id *matches, struct i2c_client *client) { + const struct acpi_device_id *id = NULL; + struct acpi_device *adev; + if (!(client && matches)) return NULL; + adev = ACPI_COMPANION(&client->dev); + + /* Std acpi_match_device() only works for the first physical device */ + if (!acpi_match_device_ids(adev, i2c_acpi_multiple_devices_ids)) { + __acpi_match_device(adev, matches, NULL, &id, NULL); + return id; + } + return acpi_match_device(matches, &client->dev); } +int i2c_acpi_device_uevent(struct i2c_client *client, + struct kobj_uevent_env *env) +{ + struct acpi_device *adev = ACPI_COMPANION(&client->dev); + + /* Std ACPI function only works for the first physical device */ + if (!acpi_match_device_ids(adev, i2c_acpi_multiple_devices_ids)) + return __acpi_device_uevent_modalias(adev, env); + + return acpi_device_uevent_modalias(&client->dev, env); +} + +int i2c_acpi_device_modalias(struct i2c_client *client, char *buf, int size) +{ + struct acpi_device *adev = ACPI_COMPANION(&client->dev); + + /* Std ACPI function only works for the first physical device */ + if (!acpi_match_device_ids(adev, i2c_acpi_multiple_devices_ids)) + return __acpi_device_modalias(adev, buf, size); + + return acpi_device_modalias(&client->dev, buf, size); +} + static acpi_status i2c_acpi_lookup_speed(acpi_handle handle, u32 level, void *data, void **return_value) { diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index ae3fda2c96a4..7bf9d8d1f8e7 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -109,7 +109,7 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv) return 1; /* Then ACPI style match */ - if (acpi_driver_match_device(dev, drv)) + if (i2c_acpi_match_device(drv->acpi_match_table, client)) return 1; driver = to_i2c_driver(drv); @@ -130,7 +130,7 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) if (rc != -ENODEV) return rc; - rc = acpi_device_uevent_modalias(dev, env); + rc = i2c_acpi_device_uevent(client, env); if (rc != -ENODEV) return rc; @@ -451,7 +451,7 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf) if (len != -ENODEV) return len; - len = acpi_device_modalias(dev, buf, PAGE_SIZE -1); + len = i2c_acpi_device_modalias(client, buf, PAGE_SIZE - 1); if (len != -ENODEV) return len; diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index 37576f50fe20..887353e1d58d 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h @@ -33,6 +33,9 @@ int i2c_check_7bit_addr_validity_strict(unsigned short addr); const struct acpi_device_id * i2c_acpi_match_device(const struct acpi_device_id *matches, struct i2c_client *client); +int i2c_acpi_device_uevent(struct i2c_client *client, + struct kobj_uevent_env *env); +int i2c_acpi_device_modalias(struct i2c_client *client, char *buf, int size); void i2c_acpi_register_devices(struct i2c_adapter *adap); #else /* CONFIG_ACPI */ static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { } @@ -42,6 +45,16 @@ i2c_acpi_match_device(const struct acpi_device_id *matches, { return NULL; } +static inline int i2c_acpi_device_uevent(struct i2c_client *client, + struct kobj_uevent_env *env) +{ + return -ENODEV; +} +static inline int i2c_acpi_device_modalias(struct i2c_client *client, + char *buf, int size) +{ + return -ENODEV; +} #endif /* CONFIG_ACPI */ extern struct notifier_block i2c_acpi_notifier; From patchwork Sun May 20 13:28:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjS135Hhz9s3x for ; Sun, 20 May 2018 23:29:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751752AbeETN3T (ORCPT ); Sun, 20 May 2018 09:29:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41426 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751637AbeETN3O (ORCPT ); Sun, 20 May 2018 09:29:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F6C5401DEBA; Sun, 20 May 2018 13:29:13 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07308215CDA7; Sun, 20 May 2018 13:29:11 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 6/9] i2c: acpi: Add BSG1160 to i2c_acpi_multiple_devices_ids Date: Sun, 20 May 2018 15:28:54 +0200 Message-Id: <20180520132857.8103-7-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 20 May 2018 13:29:13 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The BSG1160 ACPI HID is a HID describing a sensor complex consisting of 3 sensors: Accel: BMC150A at addr 0x11 Gyro: BMG160 at addr 0x68 Magneto: BMC150B at addr 0x13 The ACPI resources table contains I2cSerialBusV2 resources for each, add the BSG1160 id to the i2c_acpi_multiple_devices_ids list, so that an i2c_client gets instantiated for each sensor. Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-acpi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index f2f9048caffd..7fb622b269db 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -216,6 +216,7 @@ static const struct acpi_device_id i2c_acpi_multiple_devices_ids[] = { * enumerate them all. */ { "BOSC0200", 0 }, + { "BSG1160", 0 }, { "INT3515", 0 }, {} }; From patchwork Sun May 20 13:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917164 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjS42Sxtz9s3x for ; Sun, 20 May 2018 23:29:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751637AbeETN3V (ORCPT ); Sun, 20 May 2018 09:29:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41682 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751372AbeETN3P (ORCPT ); Sun, 20 May 2018 09:29:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57DC7BB41A; Sun, 20 May 2018 13:29:15 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1B2D215CDA7; Sun, 20 May 2018 13:29:13 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 7/9] iio: accel: bmc150: Add support for BSG1160 ACPI HID Date: Sun, 20 May 2018 15:28:55 +0200 Message-Id: <20180520132857.8103-8-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 20 May 2018 13:29:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 20 May 2018 13:29:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The BSG1160 ACPI HID is a HID describing a sensor complex consisting of 3 sensors: Accel: BMC150A at addr 0x11 Gyro: BMG160 at addr 0x68 Magneto: BMC150B at addr 0x13 A previous patch on this series has added the BSG1160 HID to the i2c_acpi_multiple_devices_ids list, so that one i2c_client gets instantiated per sensor. This commit not only adds the BSG1160 HID to the bmc150 code, but it also makes the i2c probe function check the client address for devices with a BSG1160 HID and only bind to the one at address 0x11. Signed-off-by: Hans de Goede --- drivers/iio/accel/bmc150-accel-i2c.c | 8 ++++++++ drivers/iio/accel/bmc150-accel.h | 1 + 2 files changed, 9 insertions(+) diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c index 8ffc308d5fd0..e0d7b507e397 100644 --- a/drivers/iio/accel/bmc150-accel-i2c.c +++ b/drivers/iio/accel/bmc150-accel-i2c.c @@ -31,13 +31,20 @@ static int bmc150_accel_probe(struct i2c_client *client, const struct i2c_device_id *id) { + const struct acpi_device_id *acpi_id; struct regmap *regmap; + struct device *dev = &client->dev; const char *name = NULL; bool block_supported = i2c_check_functionality(client->adapter, I2C_FUNC_I2C) || i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK); + /* The BSG1160 ACPI id describes multiple sensors, only bind to ours */ + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); + if (acpi_id && acpi_id->driver_data == bsg1160 && client->addr != 0x11) + return -ENODEV; + regmap = devm_regmap_init_i2c(client, &bmc150_regmap_conf); if (IS_ERR(regmap)) { dev_err(&client->dev, "Failed to initialize i2c regmap\n"); @@ -64,6 +71,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = { {"BMA250E", bma250e}, {"BMA222E", bma222e}, {"BMA0280", bma280}, + {"BSG1160", bsg1160}, {"BOSC0200"}, { }, }; diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h index ae6118ae11b1..ac540a775d54 100644 --- a/drivers/iio/accel/bmc150-accel.h +++ b/drivers/iio/accel/bmc150-accel.h @@ -11,6 +11,7 @@ enum { bma250e, bma222e, bma280, + bsg1160, }; int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, From patchwork Sun May 20 13:28:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjS621YFz9s3x for ; Sun, 20 May 2018 23:29:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751783AbeETN3W (ORCPT ); Sun, 20 May 2018 09:29:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59932 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751732AbeETN3R (ORCPT ); Sun, 20 May 2018 09:29:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F2B67D839; Sun, 20 May 2018 13:29:17 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A374215CDA7; Sun, 20 May 2018 13:29:15 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 8/9] iio: gyro: bmg160: Add support for BSG1160 ACPI HID Date: Sun, 20 May 2018 15:28:56 +0200 Message-Id: <20180520132857.8103-9-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sun, 20 May 2018 13:29:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sun, 20 May 2018 13:29:17 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The BSG1160 ACPI HID is a HID describing a sensor complex consisting of 3 sensors: Accel: BMC150A at addr 0x11 Gyro: BMG160 at addr 0x68 Magneto: BMC150B at addr 0x13 A previous patch on this series has added the BSG1160 HID to the i2c_acpi_multiple_devices_ids list, so that one i2c_client gets instantiated per sensor. This commit not only adds the BSG1160 HID to the bmg160 code, but it also makes the i2c probe function check the client address for devices with a BSG1160 HID and only bind to the one at address 0x68. Signed-off-by: Hans de Goede --- drivers/iio/gyro/bmg160_i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c index 90126a5a7663..2f72f41e33bb 100644 --- a/drivers/iio/gyro/bmg160_i2c.c +++ b/drivers/iio/gyro/bmg160_i2c.c @@ -15,9 +15,17 @@ static const struct regmap_config bmg160_regmap_i2c_conf = { static int bmg160_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { + const struct acpi_device_id *acpi_id; struct regmap *regmap; + struct device *dev = &client->dev; const char *name = NULL; + /* The BSG1160 ACPI id describes multiple sensors, only bind to ours */ + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); + if (acpi_id && acpi_id->driver_data && + client->addr != acpi_id->driver_data) + return -ENODEV; + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); if (IS_ERR(regmap)) { dev_err(&client->dev, "Failed to register i2c regmap %d\n", @@ -41,6 +49,7 @@ static int bmg160_i2c_remove(struct i2c_client *client) static const struct acpi_device_id bmg160_acpi_match[] = { {"BMG0160", 0}, {"BMI055B", 0}, + {"BSG1160", 0x68}, {}, }; From patchwork Sun May 20 13:28:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 917165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40pjS521nwz9s4V for ; Sun, 20 May 2018 23:29:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751372AbeETN3X (ORCPT ); Sun, 20 May 2018 09:29:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46788 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751749AbeETN3T (ORCPT ); Sun, 20 May 2018 09:29:19 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCE3240122A0; Sun, 20 May 2018 13:29:18 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52102215CDA7; Sun, 20 May 2018 13:29:17 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Mika Westerberg , Wolfram Sang , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , linux-iio@vger.kernel.org Subject: [PATCH 9/9] iio: magnetometer: bmc150: Add support for BSG1160 ACPI HID Date: Sun, 20 May 2018 15:28:57 +0200 Message-Id: <20180520132857.8103-10-hdegoede@redhat.com> In-Reply-To: <20180520132857.8103-1-hdegoede@redhat.com> References: <20180520132857.8103-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 20 May 2018 13:29:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 20 May 2018 13:29:18 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The BSG1160 ACPI HID is a HID describing a sensor complex consisting of 3 sensors: Accel: BMC150A at addr 0x11 Gyro: BMG160 at addr 0x68 Magneto: BMC150B at addr 0x13 A previous patch on this series has added the BSG1160 HID to the i2c_acpi_multiple_devices_ids list, so that one i2c_client gets instantiated per sensor. This commit not only adds the BSG1160 HID to the bmc150 code, but it also makes the i2c probe function check the client address for devices with a BSG1160 HID and only bind to the one at address 0x13. Signed-off-by: Hans de Goede --- drivers/iio/magnetometer/bmc150_magn_i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iio/magnetometer/bmc150_magn_i2c.c b/drivers/iio/magnetometer/bmc150_magn_i2c.c index 57e40dd1222e..c8a1e4178462 100644 --- a/drivers/iio/magnetometer/bmc150_magn_i2c.c +++ b/drivers/iio/magnetometer/bmc150_magn_i2c.c @@ -27,9 +27,17 @@ static int bmc150_magn_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { + const struct acpi_device_id *acpi_id; struct regmap *regmap; + struct device *dev = &client->dev; const char *name = NULL; + /* The BSG1160 ACPI id describes multiple sensors, only bind to ours */ + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); + if (acpi_id && acpi_id->driver_data && + client->addr != acpi_id->driver_data) + return -ENODEV; + regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config); if (IS_ERR(regmap)) { dev_err(&client->dev, "Failed to initialize i2c regmap\n"); @@ -51,6 +59,7 @@ static const struct acpi_device_id bmc150_magn_acpi_match[] = { {"BMC150B", 0}, {"BMC156B", 0}, {"BMM150B", 0}, + {"BSG1160", 0x13}, {}, }; MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);