From patchwork Mon Dec 25 15:57:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc CAPDEVILLE X-Patchwork-Id: 10132609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 682546037D for ; Mon, 25 Dec 2017 15:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38EE62ECEC for ; Mon, 25 Dec 2017 15:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BFCF2ECFE; Mon, 25 Dec 2017 15:57:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 522082ECEC for ; Mon, 25 Dec 2017 15:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752593AbdLYP5o (ORCPT ); Mon, 25 Dec 2017 10:57:44 -0500 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:38313 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752288AbdLYP5n (ORCPT ); Mon, 25 Dec 2017 10:57:43 -0500 Received: from azrael.lan ([90.14.74.106]) by mwinf5d28 with ME id qFxa1w00K2HbjxE03FxbPi; Mon, 25 Dec 2017 16:57:41 +0100 X-ME-Helo: azrael.lan X-ME-Date: Mon, 25 Dec 2017 16:57:41 +0100 X-ME-IP: 90.14.74.106 Received: (nullmailer pid 6383 invoked by uid 1000); Mon, 25 Dec 2017 15:57:31 -0000 From: Marc CAPDEVILLE To: Kevin Tsai Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mika Westerberg , Wolfram Sang , linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc CAPDEVILLE Subject: [PATCH v6 1/4] i2c-core-acpi : Add i2c_acpi_set_connection Date: Mon, 25 Dec 2017 16:57:20 +0100 Message-Id: <20171225155723.6338-1-m.capdeville@no-log.org> X-Mailer: git-send-email 2.11.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a methode to allow clients to change their connection address on same adapter. On ACPI enumerated device, when a device support smbus alert protocol, there are two acpi serial bus connection description. The order in which connection is given is not well defined and devices may be enumerated with the wrong address (the first one). So let the driver detect the unsupported address and request i2c acpi core to choose the second one at probing time. Signed-off-by: Marc CAPDEVILLE --- drivers/i2c/i2c-core-acpi.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 10 +++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index a9126b3cda61..47bc0da12055 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -421,6 +421,56 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, } EXPORT_SYMBOL_GPL(i2c_acpi_new_device); +int i2c_acpi_set_connection(struct i2c_client *client, int index) +{ + struct i2c_acpi_lookup lookup; + struct i2c_adapter *adapter; + struct acpi_device *adev; + struct i2c_board_info info; + LIST_HEAD(resource_list); + int ret; + + if (!client) + return -ENODEV; + + adev = ACPI_COMPANION(&client->dev); + if (!adev) + return -ENODEV; + + 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); + + adapter = i2c_acpi_find_adapter_by_handle(lookup.adapter_handle); + + if (ret < 0 || !info.addr) + return -EINVAL; + + /* Only accept connection on same adapter */ + if (adapter != client->adapter) + return -EINVAL; + + ret = i2c_check_addr_validity(info.addr, info.flags); + if (ret) { + dev_err(&client->dev, "Invalid %d-bit I2C address 0x%02hx\n", + info.flags & I2C_CLIENT_TEN ? 10 : 7, info.addr); + return -EINVAL; + } + + /* Set new address and flags */ + client->addr = info.addr; + client->flags = info.flags; + + return 0; +} +EXPORT_SYMBOL_GPL(i2c_acpi_set_connection); + #ifdef CONFIG_ACPI_I2C_OPREGION static int acpi_gsb_i2c_read_bytes(struct i2c_client *client, u8 cmd, u8 *data, u8 data_len) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 0f774406fad0..618b453901da 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -595,6 +595,8 @@ struct i2c_adapter { const struct i2c_adapter_quirks *quirks; struct irq_domain *host_notify_domain; + + struct i2c_client *smbus_ara; /* ARA for SMBUS if present */ }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) @@ -839,16 +841,24 @@ static inline const struct of_device_id 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); + +int i2c_acpi_set_connection(struct i2c_client *client, 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 *dev, int index, struct i2c_board_info *info) { return NULL; } + +static inline int i2c_acpi_set_connection(struct i2c_client *client, int index) +{ + return -EINVAL; +} #endif /* CONFIG_ACPI */ #endif /* _LINUX_I2C_H */