From patchwork Fri Mar 17 09:55:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 740209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vl1560LbDz9s1h for ; Fri, 17 Mar 2017 20:58:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751257AbdCQJ6k (ORCPT ); Fri, 17 Mar 2017 05:58:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33522 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751066AbdCQJ4t (ORCPT ); Fri, 17 Mar 2017 05:56:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56026445D1; Fri, 17 Mar 2017 09:56:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 56026445D1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=hdegoede@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 56026445D1 Received: from shalem.localdomain.com (ovpn-116-172.ams2.redhat.com [10.36.116.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id E336C5C3FA; Fri, 17 Mar 2017 09:56:03 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Wolfram Sang , Andy Shevchenko , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi Cc: Hans de Goede , linux-acpi@vger.kernel.org, Takashi Iwai , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 12/15] i2c: core: Add new i2c_acpi_new_device helper function Date: Fri, 17 Mar 2017 10:55:24 +0100 Message-Id: <20170317095527.10487-13-hdegoede@redhat.com> In-Reply-To: <20170317095527.10487-1-hdegoede@redhat.com> References: <20170317095527.10487-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 17 Mar 2017 09:56:06 +0000 (UTC) Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 Reviewed-by: Andy Shevchenko --- 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..fd45207 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 */