From patchwork Thu Nov 5 08:00:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11883459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67FA0697 for ; Thu, 5 Nov 2020 08:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A9F621D46 for ; Thu, 5 Nov 2020 08:00:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VlFn8fkc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729825AbgKEIAZ (ORCPT ); Thu, 5 Nov 2020 03:00:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36030 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729417AbgKEIAZ (ORCPT ); Thu, 5 Nov 2020 03:00:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604563224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ppIkeNqrQXwJdt2qFiq6mkdhN5t6W9eweFCWsL70/gw=; b=VlFn8fkcFKznPdCeXgJcW7dlVOtTgZtS82UTbbi4JzbDKN42tEMOpIIr6cnaU7h2VpmVwo 9SvZ+GBYjzL3wAnAoSEvHeGPoDK+A6sXPH6DvDxC5RkqNqx/7TISWH0a/jewvMo19TGjrb tJXtyuTaT+p/gJIUPAuGRWyOzHqSA5I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-536-BYT2nQZDMJ2OwZmL9xbmrQ-1; Thu, 05 Nov 2020 03:00:20 -0500 X-MC-Unique: BYT2nQZDMJ2OwZmL9xbmrQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2989364149; Thu, 5 Nov 2020 08:00:19 +0000 (UTC) Received: from x1.localdomain.com (ovpn-113-73.ams2.redhat.com [10.36.113.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1C2F5DA79; Thu, 5 Nov 2020 08:00:17 +0000 (UTC) From: Hans de Goede To: Mark Gross , Wolfram Sang Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [RFC 1/4] i2c: core: Allow i2c_board_info to specify that the core should not try to find an IRQ Date: Thu, 5 Nov 2020 09:00:11 +0100 Message-Id: <20201105080014.45410-2-hdegoede@redhat.com> In-Reply-To: <20201105080014.45410-1-hdegoede@redhat.com> References: <20201105080014.45410-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org When I2C devices are enumerated/instantiated through ACPI tables then a single ACPI device may describe multiple separate I2C connected ICs. This is handled by the drivers/platform/x86/i2c-multi-instantiate.c code which contains a table which maps the ACPI-device-id to the information necessary to instantiate the i2c-clients (type and IRQ routing for each described IC). In some cases the i2c-driver may need access to the ACPI-fwnode as that may contain ACPI-methods supplying e.g. orientation-matrix info for accelerometers. Currently setting i2c_board_info.fwnode to point to the ACPI-fwnode will cause the i2c-core to call i2c_acpi_get_irq() for any i2c-clients for which i2c-multi-instantiate.c has not passed an IRQ in i2c_board_info.irq, messing up the IRQ routing done by i2c-multi-instantiate.c. Make i2c_device_probe() accept a client->init_irq value < 0 to skip the i2c-core IRQ handling, while still setting client->irq to 0 after checking for this, since most i2c-drivers expect client->irq == 0 for clients without an IRQ. This allows i2c-multi-instantiate.c to set i2c_board_info.irq = -ENOENT for clients without an IRQ and pass the ACPI-fwnode without issues. Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-base.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 573b5da145d1..1887e2267031 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -467,11 +467,10 @@ static int i2c_device_probe(struct device *dev) goto put_sync_adapter; } - if (irq < 0) - irq = 0; - client->irq = irq; } + if (client->irq < 0) + client->irq = 0; driver = to_i2c_driver(dev->driver); From patchwork Thu Nov 5 08:00:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11883461 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A86CE174A for ; Thu, 5 Nov 2020 08:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F9CD2168B for ; Thu, 5 Nov 2020 08:00:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BcM6hkOs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729893AbgKEIA1 (ORCPT ); Thu, 5 Nov 2020 03:00:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41303 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729779AbgKEIA1 (ORCPT ); Thu, 5 Nov 2020 03:00:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604563226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Pluz2cEJCXCyvPbyI8FVIRYK1Xva1UsmaO+fzo7598=; b=BcM6hkOsG0q+QmCN01KF+hFD3cFp85Zb4VhvNFHnzbF01FN28C+sfacctEV00J9L5XciyW iYuf6a1WjtNMDlfWW0Hge9SijsIsgpBj2EJLO0OV0cFzMRexx+Dfq+/X2L1SsqRE9byftA /EIDkSohXf6Cg10dtMyZhcXCWGVdUDE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-b3Pn88ewN6iRhKgkecumkw-1; Thu, 05 Nov 2020 03:00:22 -0500 X-MC-Unique: b3Pn88ewN6iRhKgkecumkw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E232780474C; Thu, 5 Nov 2020 08:00:20 +0000 (UTC) Received: from x1.localdomain.com (ovpn-113-73.ams2.redhat.com [10.36.113.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70F165D98F; Thu, 5 Nov 2020 08:00:19 +0000 (UTC) From: Hans de Goede To: Mark Gross , Wolfram Sang Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [RFC 2/4] platform/x86: i2c-multi-instantiate: Set i2c_board_info.irq to -ENOENT when no IRQ is specified Date: Thu, 5 Nov 2020 09:00:12 +0100 Message-Id: <20201105080014.45410-3-hdegoede@redhat.com> In-Reply-To: <20201105080014.45410-1-hdegoede@redhat.com> References: <20201105080014.45410-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org In some cases the i2c-driver may need access to the ACPI-fwnode as that may contain ACPI-methods supplying e.g. orientation-matrix info for accelerometers. Setting i2c_board_info.fwnode to point to the ACPI-fwnode, while leaving i2c_board_info.irq set to 0 (in the IRQ_RESOURCE_NONE case) will cause the i2c-core to assign the first IRQ described in the ACPI resources to the client, which we do not want. Set i2c_board_info.irq to -ENOENT instead of 0 in the IRQ_RESOURCE_NONE case, to avoid this issue. This is a preparation patch for passing the fwnode to i2c_acpi_new_device. Signed-off-by: Hans de Goede --- drivers/platform/x86/i2c-multi-instantiate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c index 6acc8457866e..cb4688bdd6b6 100644 --- a/drivers/platform/x86/i2c-multi-instantiate.c +++ b/drivers/platform/x86/i2c-multi-instantiate.c @@ -113,7 +113,7 @@ static int i2c_multi_inst_probe(struct platform_device *pdev) board_info.irq = ret; break; default: - board_info.irq = 0; + board_info.irq = -ENOENT; break; } multi->clients[i] = i2c_acpi_new_device(dev, i, &board_info); From patchwork Thu Nov 5 08:00:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11883465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BD59174A for ; Thu, 5 Nov 2020 08:00:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF33821D7F for ; Thu, 5 Nov 2020 08:00:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dIgv5Fn+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729862AbgKEIA3 (ORCPT ); Thu, 5 Nov 2020 03:00:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50817 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729779AbgKEIA2 (ORCPT ); Thu, 5 Nov 2020 03:00:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604563227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cSCL9O0sLp/tw6Tt9q5kxfE0ulUwEY7xVodcysoHvLQ=; b=dIgv5Fn+1Tg2hmkvW4KD/T4jicv9eUWDXMvXyxO4n7YYCLjMxIvNsKAVA42GsVRmEDumcM Wkbdw8VzEytwjn48/TUTf0V5e4sLGoZFd1mYrwdqTiy2KFywRl3p3QlINGdkln7o8GxuIG GalEOxXS0Zza/Z2ulFW87vePei1vAOo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-4_1wsY_CMy-4x2OLGkP7XA-1; Thu, 05 Nov 2020 03:00:24 -0500 X-MC-Unique: 4_1wsY_CMy-4x2OLGkP7XA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A15486414C; Thu, 5 Nov 2020 08:00:22 +0000 (UTC) Received: from x1.localdomain.com (ovpn-113-73.ams2.redhat.com [10.36.113.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37CF75DA76; Thu, 5 Nov 2020 08:00:21 +0000 (UTC) From: Hans de Goede To: Mark Gross , Wolfram Sang Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [RFC 3/4] platform/x86: i2c-multi-instantiate: Pass ACPI fwnode to instantiated I2C-clients Date: Thu, 5 Nov 2020 09:00:13 +0100 Message-Id: <20201105080014.45410-4-hdegoede@redhat.com> In-Reply-To: <20201105080014.45410-1-hdegoede@redhat.com> References: <20201105080014.45410-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The ACPI fwnode may contain additional info which is useful for the I2C-driver. E.g. some accelerometer ACPI fwnode's contain an ACPI method providing rotation/mount matrix info. Pass the ACPI-fwnode to the instantiated I2C-clients by setting i2c_board_info.fwnode, so that the I2C-drivers can access this info. Now that we set i2c_board_info.irq to -ENOENT if there is no IRQ, avoiding the I2C-core assigning the first IRQ described in the ACPI resources to the client, this is safe to do. Setting the fwnode also influences acpi_device_[uevent_]modalias and acpi_dev_pm_attach, but these both call acpi_device_is_first_physical_node and are a no-op if this returns false. The first physical node for the ACPI fwnode is actually the ACPI core instantiated platform-device to which the I2C-multi-instantiate driver binds, so acpi_device_is_first_physical_node always returns false for the instantiated I2C-clients and thus we can safely pass the fwnode. Signed-off-by: Hans de Goede --- drivers/platform/x86/i2c-multi-instantiate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c index cb4688bdd6b6..cbccfcbed44c 100644 --- a/drivers/platform/x86/i2c-multi-instantiate.c +++ b/drivers/platform/x86/i2c-multi-instantiate.c @@ -93,6 +93,7 @@ static int i2c_multi_inst_probe(struct platform_device *pdev) snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst_data[i].type, i); board_info.dev_name = name; + board_info.fwnode = dev->fwnode; switch (inst_data[i].flags & IRQ_RESOURCE_TYPE) { case IRQ_RESOURCE_GPIO: ret = acpi_dev_gpio_irq_get(adev, inst_data[i].irq_idx); From patchwork Thu Nov 5 08:00:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11883463 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95435139F for ; Thu, 5 Nov 2020 08:00:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CF3E2151B for ; Thu, 5 Nov 2020 08:00:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NXyWz2R4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729918AbgKEIA2 (ORCPT ); Thu, 5 Nov 2020 03:00:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24821 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729490AbgKEIA2 (ORCPT ); Thu, 5 Nov 2020 03:00:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604563227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QexiIGh65OkVEakRusDkQrbb7GvquS9RxDdYOuUFhO0=; b=NXyWz2R4StlCyg4hifdMFieH7vTIlCHJvh290YJAWuq75TUFwddPzsHmUwZKcL0EDN6hZu qCSdZtml+SqK8+x6fI1u7U8old3gjIh2Rja9BeVqcqKyWOTP3+ZZCW1SNURKf8Pt9rrnZY 6+5yGlP98fLwsVbmBtalM3ONS5qJMRo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-C9DdjN0dPPGYzPhvx0ALig-1; Thu, 05 Nov 2020 03:00:25 -0500 X-MC-Unique: C9DdjN0dPPGYzPhvx0ALig-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67F9D64158; Thu, 5 Nov 2020 08:00:24 +0000 (UTC) Received: from x1.localdomain.com (ovpn-113-73.ams2.redhat.com [10.36.113.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id E91C65D98F; Thu, 5 Nov 2020 08:00:22 +0000 (UTC) From: Hans de Goede To: Mark Gross , Wolfram Sang Cc: Hans de Goede , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [RFC 4/4] platform/x86: i2c-multi-instantiate: Add IRQ_RESOURCE_GPIO_OPTIONAL IRQ type Date: Thu, 5 Nov 2020 09:00:14 +0100 Message-Id: <20201105080014.45410-5-hdegoede@redhat.com> In-Reply-To: <20201105080014.45410-1-hdegoede@redhat.com> References: <20201105080014.45410-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Most I2C-drivers treat IRQs as optional and in some cases ACPI devices managed by i2c-multi-instantiate.c may have a GpioInt resource specified on some systems, while it is not there on others. Add a new IRQ_RESOURCE_GPIO_OPTIONAL IRQ type, which still tries to get a GpioInt IRQ, but does not consider it a fatal error when this fails. Signed-off-by: Hans de Goede --- drivers/platform/x86/i2c-multi-instantiate.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c index cbccfcbed44c..55c6d6e8d576 100644 --- a/drivers/platform/x86/i2c-multi-instantiate.c +++ b/drivers/platform/x86/i2c-multi-instantiate.c @@ -15,10 +15,11 @@ #include #include -#define IRQ_RESOURCE_TYPE GENMASK(1, 0) -#define IRQ_RESOURCE_NONE 0 -#define IRQ_RESOURCE_GPIO 1 -#define IRQ_RESOURCE_APIC 2 +#define IRQ_RESOURCE_TYPE GENMASK(1, 0) +#define IRQ_RESOURCE_NONE 0 +#define IRQ_RESOURCE_GPIO 1 +#define IRQ_RESOURCE_GPIO_OPTIONAL 2 +#define IRQ_RESOURCE_APIC 3 struct i2c_inst_data { const char *type; @@ -64,6 +65,7 @@ static int i2c_multi_inst_probe(struct platform_device *pdev) struct i2c_board_info board_info = {}; struct device *dev = &pdev->dev; struct acpi_device *adev; + bool irq_optional; char name[32]; int i, ret; @@ -94,10 +96,14 @@ static int i2c_multi_inst_probe(struct platform_device *pdev) inst_data[i].type, i); board_info.dev_name = name; board_info.fwnode = dev->fwnode; + irq_optional = false; switch (inst_data[i].flags & IRQ_RESOURCE_TYPE) { + case IRQ_RESOURCE_GPIO_OPTIONAL: + irq_optional = true; + fallthrough; case IRQ_RESOURCE_GPIO: ret = acpi_dev_gpio_irq_get(adev, inst_data[i].irq_idx); - if (ret < 0) { + if (ret < 0 && (!irq_optional || ret != -ENOENT)) { dev_err(dev, "Error requesting irq at index %d: %d\n", inst_data[i].irq_idx, ret); goto error;