Message ID | 20221124110718.3925934-2-sbinding@opensource.cirrus.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3331577wrr; Thu, 24 Nov 2022 03:18:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7yyrsKxtmPn/UtPSn/if0HyScEN0+n6YBlTDJSXIHiXd7FPNlVdyGa8Lb9Tm+9Hp2TsNf0 X-Received: by 2002:a63:5c0f:0:b0:470:8e8a:8e11 with SMTP id q15-20020a635c0f000000b004708e8a8e11mr11848817pgb.490.1669288721718; Thu, 24 Nov 2022 03:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669288721; cv=none; d=google.com; s=arc-20160816; b=iDrIIz9w4qOXV691EB4Nfn5UpOwqgSUcbCFwQtvkmZZCP5xvkBoqTGWUwO+OZmLM9C YEVGqzIEG+3tBmhgN+gDuNg55Mk4QTKdsHAXXlbrPTuY6ryJWN+gzS8waB8q0wEn5idi dJzYHdfIAWUuJuluLJeA3mmlk0RSCubAivMKayxl85OkkRA8cpKVNxeepnXN0Zzxi3eN KIEpLVOXz0aAspGpmxRPuJWG8+dPq0MjiOmwTrS+JanLpibjqkekZ5PsTWv3N8x9cF7+ a5/myfHXpi7hro7CEa9dCZkWWwKNk1ZdqDV80b6XkElIUEJ/sMu4IIftcLuPQzsE6cLP 9Buw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MUgtFemw9mzys2LF+P1154GAYh2HscnFbiU7ai50jsM=; b=nCd2xfILGMWWvNMQQgbiXCcwb+p223XVXqoIkCsdJLylSsgJar5yX0RXd7x7WmxJuE SAlicAUioh36PQ0atwV+GQO0RjOIG+nAvBlNzAzlHLZoqsXfNQWq8wyYDRv65LNdGlrr yNPv0WBusdx+aHkWm1+Vb6b8yaTL6mrZvl4si/fY3VxQbuVjz82MlT+gH3g7+86cmbDW doelqXYeyeS/eteWjc3CamnT06WZfOqMAh1+9Zin8qvSLGuQE+l3LYQHfJaRsmFWEQki sA/3zNkHopX9XNB6jTJnVjR2rdRoNDj77AMqp5LPGhKtg8dzgHTSg7i/m/RkIQ8v95gw aB9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=MeHXoUqI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a1709027c1800b00186e5ede745si744684pll.89.2022.11.24.03.18.27; Thu, 24 Nov 2022 03:18:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=MeHXoUqI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbiKXLHy (ORCPT <rfc822;fengqi706@gmail.com> + 99 others); Thu, 24 Nov 2022 06:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbiKXLHv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 24 Nov 2022 06:07:51 -0500 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3927A24BFE; Thu, 24 Nov 2022 03:07:49 -0800 (PST) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AO7LNJS015819; Thu, 24 Nov 2022 05:07:25 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=MUgtFemw9mzys2LF+P1154GAYh2HscnFbiU7ai50jsM=; b=MeHXoUqIMuOg3cycTuD4gsB053mgOXXamO21I+tA0MZNyBU3obed1qZE/NHgy1vk0Qh7 ZlAU12ynGS1uEl1APXMElucwMK2jggKYZ2ftDzGsh6N5M4ovZ+ZcOxqQGDtFBfGHFIWb EmcrJwMsmlX5rbA9HvCz/3x8mq3U0AloaQeQ/kXjPtbnXzM7eWg7CZC3ndFAu2rE8LXp btOTZv1RJj303n+qdZZG8JqLFuV6eoJe07wk7aREN5Yw1AzZjY94xBVkJpUIx75AhUol z8PZCLfrrHJ3yDa+s/vo7vz9K7oRHSxiSwep8T5P0QVU2ZIXfc7dRuROm/PyT0o7g26S iA== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3kxwe6x2du-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Nov 2022 05:07:24 -0600 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Thu, 24 Nov 2022 05:07:22 -0600 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.20 via Frontend Transport; Thu, 24 Nov 2022 05:07:22 -0600 Received: from sbinding-cirrus-dsktp2.ad.cirrus.com (unknown [198.90.202.160]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 85BD7B10; Thu, 24 Nov 2022 11:07:22 +0000 (UTC) From: Stefan Binding <sbinding@opensource.cirrus.com> To: Andy Shevchenko <andy.shevchenko@gmail.com>, Dmitry Torokhov <dmitry.torokhov@gmail.com>, "Rafael J . Wysocki" <rafael@kernel.org>, Hans de Goede <hdegoede@redhat.com>, Mark Gross <markgross@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com> CC: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>, <platform-driver-x86@vger.kernel.org>, <patches@opensource.cirrus.com>, Stefan Binding <sbinding@opensource.cirrus.com> Subject: [PATCH v1 1/2] platform/x86: serial-multi-instantiate: Set fwnode for i2c Date: Thu, 24 Nov 2022 11:07:17 +0000 Message-ID: <20221124110718.3925934-2-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221124110718.3925934-1-sbinding@opensource.cirrus.com> References: <20221124110718.3925934-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: oibzOdWpY9mctqOdzlYetaHUXXSPowin X-Proofpoint-GUID: oibzOdWpY9mctqOdzlYetaHUXXSPowin X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750376090715937806?= X-GMAIL-MSGID: =?utf-8?q?1750376090715937806?= |
Series |
Use ACPI_COMPANION macro to obtain acpi_device in cs35l41_hda
|
|
Commit Message
Stefan Binding
Nov. 24, 2022, 11:07 a.m. UTC
This allows the i2c driver to obtain the ACPI_COMPANION.
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
---
drivers/platform/x86/serial-multi-instantiate.c | 1 +
1 file changed, 1 insertion(+)
Comments
On Thu, Nov 24, 2022 at 1:07 PM Stefan Binding <sbinding@opensource.cirrus.com> wrote: > > This allows the i2c driver to obtain the ACPI_COMPANION. As far as I get how it's done in the SPI case the real fix should lie among i2c_acpi_new_device_by_fwnode(), right?
Hi Stefan, On 11/24/22 12:07, Stefan Binding wrote: > This allows the i2c driver to obtain the ACPI_COMPANION. > > Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com> > --- > drivers/platform/x86/serial-multi-instantiate.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/platform/x86/serial-multi-instantiate.c > index 5362f1a7b77c..15ef2f3c442e 100644 > --- a/drivers/platform/x86/serial-multi-instantiate.c > +++ b/drivers/platform/x86/serial-multi-instantiate.c > @@ -194,6 +194,7 @@ static int smi_i2c_probe(struct platform_device *pdev, struct smi *smi, > strscpy(board_info.type, inst_array[i].type, I2C_NAME_SIZE); > snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst_array[i].type, i); > board_info.dev_name = name; > + board_info.fwnode = acpi_fwnode_handle(adev); > > ret = smi_get_irq(pdev, adev, &inst_array[i]); > if (ret < 0) I'm afraid that making this change is not as straight forward as it looks. I know that I have tried to do this in the past and it failed. IIRC there were 3 problems: 1. I was expecting this to also allow the driver for the instantiated i2c-client to be able to bind using an acpi_match_table but that unfortunately does not work. acpi_match_table matches only work for the first physical_node linked under /sys/bus/acpi/devices/xxxx:xx/physical_node and that is the platform device to which serial-multi-instantiate.c binds. The i2c_client becomes the second physical node. Note this is not really an issue, just something to be aware of. 2. This causes the i2c-core to use the first IRQ resource in the ACPI fwnode as client->irq for any clients for which we do not set an IRQ when instantiating. Which may very well be wrong. Sometimes that IRQ is only valid for the first i2c-client which we instantiate; and not for the others! And sometimes it is a problem because it may point to an irqchip for which we never wrote a driver leading to all probes of the i2c-client failing with -EPROBE_DEFER, see: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d1d84bb95364ed604015c2b788caaf3dbca0262f Note that patch has been reverted since that specific -EPROBE_DEFER issue has been solved by making the ACPI core instantiate a platform_device instead of an i2c_client (in this case we did not need the actual i2c_client at all). The current i2c-core code has a (!client-irq) test guarding its code of trying to use the first ACPI fwnode IRQ resource. So we could disable this by setting client->irq = -ENOENT in serial-multi-instantiate.c when (inst->flags & IRQ_RESOURCE_TYPE) == IRQ_RESOURCE_NONE). But that will introduce a new problem. Many i2c-drivers check if there is an IRQ for them to use by doing: "if (client->irq) request_irq(client->irq, ...)" but then with error checking/so setting client->irq to -ENOENT will cause the request_irq to fail, leading the probe to fail. So before you can write a patch setting client->irq = -ENOENT when (inst->flags & IRQ_RESOURCE_TYPE) == IRQ_RESOURCE_NONE), you would first need to patch all i2c-drivers for clients instantiated through serial-multi-instantiate.c changing: if (client->irq) { ... } to: if (client->irq > 0) { ... } Note this is not as bad as it sounds, since there are only a few drivers for clients instantiated by serial-multi-instantiate.c . 3. Some drivers may check for an ACPI companion device and then change their behavior. So all drivers for clients instantiated through serial-multi-instantiate.c will need to be audited for this (and a summary of this audit needs to be added to the commit msg). Regards, Hans
Hi, On 11/24/22 12:35, Andy Shevchenko wrote: > On Thu, Nov 24, 2022 at 1:07 PM Stefan Binding > <sbinding@opensource.cirrus.com> wrote: >> >> This allows the i2c driver to obtain the ACPI_COMPANION. > > As far as I get how it's done in the SPI case the real fix should lie > among i2c_acpi_new_device_by_fwnode(), right? Eventually maybe, but not for the initial change. It is complicated, making this change has side-effects and we want to limit those side-effects to only i2c-clients instantiated from serial-multi-instantiate for now, see my other reply to this patch. I do believe that we eventually want to make this change, to easily give drivers access to all sorts of info (e.g. _DSM methods) from the matching ACPI fw-node, but as I said it is complicated... Regards, Hans
Hi, On 11/24/22 12:47, Hans de Goede wrote: > Hi Stefan, > > On 11/24/22 12:07, Stefan Binding wrote: >> This allows the i2c driver to obtain the ACPI_COMPANION. >> >> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com> >> --- >> drivers/platform/x86/serial-multi-instantiate.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/platform/x86/serial-multi-instantiate.c >> index 5362f1a7b77c..15ef2f3c442e 100644 >> --- a/drivers/platform/x86/serial-multi-instantiate.c >> +++ b/drivers/platform/x86/serial-multi-instantiate.c >> @@ -194,6 +194,7 @@ static int smi_i2c_probe(struct platform_device *pdev, struct smi *smi, >> strscpy(board_info.type, inst_array[i].type, I2C_NAME_SIZE); >> snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst_array[i].type, i); >> board_info.dev_name = name; >> + board_info.fwnode = acpi_fwnode_handle(adev); >> >> ret = smi_get_irq(pdev, adev, &inst_array[i]); >> if (ret < 0) > > I'm afraid that making this change is not as straight forward as it looks. > > I know that I have tried to do this in the past and it failed. > > IIRC there were 3 problems: > > 1. I was expecting this to also allow the driver for the instantiated > i2c-client to be able to bind using an acpi_match_table but that > unfortunately does not work. acpi_match_table matches only work for > the first physical_node linked under > /sys/bus/acpi/devices/xxxx:xx/physical_node and that is the platform > device to which serial-multi-instantiate.c binds. The i2c_client becomes > the second physical node. Note this is not really an issue, > just something to be aware of. > > > 2. This causes the i2c-core to use the first IRQ resource in the ACPI > fwnode as client->irq for any clients for which we do not set an > IRQ when instantiating. Which may very well be wrong. Sometimes that > IRQ is only valid for the first i2c-client which we instantiate; and > not for the others! And sometimes it is a problem because it may > point to an irqchip for which we never wrote a driver leading to > all probes of the i2c-client failing with -EPROBE_DEFER, see: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d1d84bb95364ed604015c2b788caaf3dbca0262f > > Note that patch has been reverted since that specific -EPROBE_DEFER > issue has been solved by making the ACPI core instantiate a > platform_device instead of an i2c_client (in this case we > did not need the actual i2c_client at all). > > The current i2c-core code has a (!client-irq) test guarding its > code of trying to use the first ACPI fwnode IRQ resource. > > So we could disable this by setting client->irq = -ENOENT in > serial-multi-instantiate.c when (inst->flags & IRQ_RESOURCE_TYPE) == > IRQ_RESOURCE_NONE). But that will introduce a new problem. Many > i2c-drivers check if there is an IRQ for them to use by doing: > "if (client->irq) request_irq(client->irq, ...)" but then with > error checking/so setting client->irq to -ENOENT will cause > the request_irq to fail, leading the probe to fail. > > So before you can write a patch setting client->irq = -ENOENT > when (inst->flags & IRQ_RESOURCE_TYPE) == IRQ_RESOURCE_NONE), > you would first need to patch all i2c-drivers for clients > instantiated through serial-multi-instantiate.c changing: > > if (client->irq) { > ... > } > > to: > > if (client->irq > 0) { > ... > } > > Note this is not as bad as it sounds, since there are only > a few drivers for clients instantiated by serial-multi-instantiate.c . Possibly a nicer way to fix this would be to make the i2c-core change client->irq to 0 if it is -ENOENT before calling the i2c_driver's probe method, thus fixing things centrally for all i2c-drivers without needing to audit/patch them all. Specifically in: drivers/i2c/i2c-core-base.c: i2c_device_probe() change: if (!client->irq) { ... } to: if (!client->irq) { ... } else if (client->irq == -ENOENT) { client->irq = 0; /* Drivers expect 0 for "no-IRQ" */ } And maybe as Andy suggested, handle at least the IRQ in i2c_acpi_new_device_by_fwnode() by adding something like that there: /* Disable the i2c-core attempting to get an IRQ from ACPI itself */ if (!board_info->irq) board_info->irq= -ENOENT; I also agree with Andy that setting board_info->fw_node would be done there ideally too. But then you would need to extend the audit of impacted drivers mentioned below to also include drivers for i2c-clients instantiated through other code-paths calling i2c_acpi_new_device_by_fwnode() (of which there are not many, but there are a few others). > 3. Some drivers may check for an ACPI companion device and then > change their behavior. So all drivers for clients instantiated > through serial-multi-instantiate.c will need to be audited for > this (and a summary of this audit needs to be added to the commit > msg). Regards, Hans
diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/platform/x86/serial-multi-instantiate.c index 5362f1a7b77c..15ef2f3c442e 100644 --- a/drivers/platform/x86/serial-multi-instantiate.c +++ b/drivers/platform/x86/serial-multi-instantiate.c @@ -194,6 +194,7 @@ static int smi_i2c_probe(struct platform_device *pdev, struct smi *smi, strscpy(board_info.type, inst_array[i].type, I2C_NAME_SIZE); snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst_array[i].type, i); board_info.dev_name = name; + board_info.fwnode = acpi_fwnode_handle(adev); ret = smi_get_irq(pdev, adev, &inst_array[i]); if (ret < 0)