From patchwork Sun Jul 1 12:23:42 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: 937577 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 41JV121Rctz9s2R for ; Sun, 1 Jul 2018 22:23:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752082AbeGAMXs (ORCPT ); Sun, 1 Jul 2018 08:23:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752153AbeGAMXr (ORCPT ); Sun, 1 Jul 2018 08:23:47 -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 1F2757C6A9; Sun, 1 Jul 2018 12:23:47 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-57.ams2.redhat.com [10.36.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34C12215688A; Sun, 1 Jul 2018 12:23:46 +0000 (UTC) From: Hans de Goede To: Wolfram Sang , Andy Shevchenko , Mika Westerberg Cc: Hans de Goede , Heikki Krogerus , linux-i2c@vger.kernel.org Subject: [PATCH v2 1/2] i2c: Add new I2C_CLIENT_IGNORE_BUSY flag Date: Sun, 1 Jul 2018 14:23:42 +0200 Message-Id: <20180701122343.27194-2-hdegoede@redhat.com> In-Reply-To: <20180701122343.27194-1-hdegoede@redhat.com> References: <20180701122343.27194-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, 01 Jul 2018 12:23:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sun, 01 Jul 2018 12:23:47 +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 i2c_new_device will check that a client at the same address does not already exists. On systems with ACPI instantiated i2c-clients, normally there is 1 fw_node per i2c-device and that fw-node contains 1 I2cSerialBus resource for that 1 i2c-device. But in some rare cases the manufacturer has decided to describe multiple i2c-devices in a single ACPI fwnode with multiple I2cSerialBus resources. After an earlier attempt to fix this in the i2c-core which resulted in a lot of extra code to support this corner-case it was decided to go for a different approach. The next patch in this series introduces a new special i2c-multi-instantiate driver which can be build as a module and which will bind to the i2c-client which gets instantiated by the core for the first I2cSerialBus resource in the fwnode. This driver will instantiate a new i2c-client per I2cSerialBus resource, using the driver_data from the acpi_device_id it is binding to to tell it which chip-type (and optional irq-resource) to use when instantiating. Since it binds to the core instantiated i2c-client and claims the acpi_device_id of the fwnode, it also needs to instantiate a new i2c-client for the first I2cSerialBus resource uses the chip-id for the real driver, so that that can bind to the i2c-device described by the first I2cSerialBus resource, this requires the new I2C_CLIENT_IGNORE_BUSY flag. Note this means that we will be instantiating 2 i2c_client-s for the first I2cSerialBus resource, this is not pretty, but since the multi-instantiate driver does exactly 0 i2c-transfers this is not a problem. Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-base.c | 11 +++++++---- include/linux/i2c.h | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 31d16ada6e7d..1806ad6ffa95 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -717,7 +717,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) client->adapter = adap; client->dev.platform_data = info->platform_data; - client->flags = info->flags; + client->flags = info->flags & ~I2C_CLIENT_IGNORE_BUSY; client->addr = info->addr; client->irq = info->irq; @@ -735,9 +735,12 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) } /* Check for address business */ - status = i2c_check_addr_busy(adap, i2c_encode_flags_to_addr(client)); - if (status) - goto out_err; + if (!(info->flags & I2C_CLIENT_IGNORE_BUSY)) { + status = i2c_check_addr_busy(adap, + i2c_encode_flags_to_addr(client)); + if (status) + goto out_err; + } client->dev.parent = &client->adapter->dev; client->dev.bus = &i2c_bus_type; diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 254cd34eeae2..82280d1c8e7b 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -773,6 +773,9 @@ i2c_unlock_adapter(struct i2c_adapter *adapter) #define I2C_CLIENT_SLAVE 0x20 /* we are the slave */ #define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */ #define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */ +#define I2C_CLIENT_IGNORE_BUSY 0x100 /* For board_info; skip busy check */ + /* Do NOT use, reserved for use by */ + /* drv/i2c/i2c-multi-instantiate.c */ #define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */ /* Must match I2C_M_STOP|IGNORE_NAK */