Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2992951ybz; Mon, 27 Apr 2020 08:09:16 -0700 (PDT) X-Google-Smtp-Source: APiQypLgSNwnQyIfRTeneZh7wg4RJvPl93jT1JcS4v4GTXXrGfrTuo5nUzYno58qjLhjI3xYTU3i X-Received: by 2002:a17:906:4bc9:: with SMTP id x9mr19637840ejv.27.1588000156140; Mon, 27 Apr 2020 08:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588000156; cv=none; d=google.com; s=arc-20160816; b=Utuqotg0PQeE9Msi3VIEVdMKceWF3GOSyIDnlk4DaEWJ4lbdMGODT7PZU1yiqVYTcn 2zJIyUaFWdiOSSHHAgQE9UOQ8HmnoDjOEBRyP6eqww1LMimz4EYHNQFBDZCnHFWa87b9 8qpEGw6fhgExfTMuTXyw303EWXqYNmLRPLluARAvHBwpHVU+dH67WqhKbgSJk3in8/Fr +E3ksgLxQxbIATxAK2H2VjoCEiaOyLUcTTumIE9+QXuV3QvDXzAHN/lgfD1Y+3V+KNnJ 9JSBFcT9TSotnMntRP/CVenZP39WE8YPf5wHS2q+v5caZAZ07GtFZQBPV6wqrhyCvGTM AB8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=ZHWkGUvj4t05y2VKSH2hO4KlsW7WN90Jqwx2sM7eu3Q=; b=oHDFgcfEtgIb198+t8bKzyctG4GErXh44tPNlAELcFF23a8jeAA0XOFDtqXDDMwzEG 5dhMnVUSV/U1hmOC7rVBmzlPOOdqP/L6XyAnDl+78jGIaFdO4GnGp8VLSXwfdZkOaMPu PknB/FHYgylLVjXOuYfjVuJRdCxZoIqsiECJ7Q4/VE4ChQkxvq57LQnSgFEco4G8ftYn W+3fxSsofA4FAjuDCE0OOuNGhQwIsvVaLURlyMmJQER/0+ggTMxXUm1XNNDqac/Rk4Od lyuqNyimCaQqkf9C9ylf/hclA5u6MN4/zqCJ4XUR/Kgj3HgC4JE55SUSnaZ3gvUF6NnG x6ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KN3GSgw2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k18si3996270edx.296.2020.04.27.08.08.39; Mon, 27 Apr 2020 08:09:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KN3GSgw2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727864AbgD0PGO (ORCPT + 99 others); Mon, 27 Apr 2020 11:06:14 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52020 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727822AbgD0PGM (ORCPT ); Mon, 27 Apr 2020 11:06:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587999970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZHWkGUvj4t05y2VKSH2hO4KlsW7WN90Jqwx2sM7eu3Q=; b=KN3GSgw2Lc7dHg3JfYlgWqVcCdpzCptoow1kwrXmk6eDt1h+96r8raUzSp1dImlTtNknhP npgVhSGyYShluUHxIF/xE/P7BycbNs874B1lqA1nvHSrNaBgRDTWAkL5E96P+C4a4vtarl N/CUGD0ORkHO0mW7lMnNWasIVpOneBI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-VQmHB7WVMgeIoCHZcwUaDQ-1; Mon, 27 Apr 2020 11:06:07 -0400 X-MC-Unique: VQmHB7WVMgeIoCHZcwUaDQ-1 Received: by mail-wr1-f72.google.com with SMTP id y10so10614961wrn.5 for ; Mon, 27 Apr 2020 08:06:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZHWkGUvj4t05y2VKSH2hO4KlsW7WN90Jqwx2sM7eu3Q=; b=DfmV6NgJtxBQp5AAMCKEOuG92b2Sgy5hqp5w9KdllYa83SPadARjFyPBDzHn+bBcB2 ECDcPXq7oRQeCNRoTHrKgZhNH1UEFYFMbxbF92uQ3wPrFUh67X0tEk5JFl6YN1kD7OFZ iAsGmSBSsd2vpz7sjzSkkLAt65p39DQy+jHGgIISxFns/WUMvqpC1I8a/Ssn7K10cWbm Rfyo2kyPeCx+5lbE8CbZDYMnTqHNn59kjZNq6l/C0SN2QpWDF9EXW6KkWRGYz1DapcyG S92m1xa4qXgh6+xbeU9mBoMb0Mu2lXmX2WH0Da3F4/MjAEmELocABHZswEMbd44bmvmi 7yrw== X-Gm-Message-State: AGi0PubeF+gy1ANeP2vf9HEiJBzLkyudVp9mF6mcKydZ4vcE5bEpvN8X yr0KxGdpUlKOLebAkgWGj6kdIGD/EswyWM5D5dRXbIfmfWDEfDeu47zut3N+aL+MqkmNCuWlV77 M/o4KYchv7kVwSUYl6HuYrmdj X-Received: by 2002:a5d:6cc2:: with SMTP id c2mr16647072wrc.60.1587999965126; Mon, 27 Apr 2020 08:06:05 -0700 (PDT) X-Received: by 2002:a5d:6cc2:: with SMTP id c2mr16647048wrc.60.1587999964863; Mon, 27 Apr 2020 08:06:04 -0700 (PDT) Received: from x1.localdomain (2001-1c00-0c0c-fe00-d2ea-f29d-118b-24dc.cable.dynamic.v6.ziggo.nl. [2001:1c00:c0c:fe00:d2ea:f29d:118b:24dc]) by smtp.gmail.com with ESMTPSA id r20sm15244349wmh.26.2020.04.27.08.06.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Apr 2020 08:06:04 -0700 (PDT) Subject: Re: [PATCH 1/2] platform/x86: i2c-multi-instantiate: Add flag for passing fwnode To: Andy Shevchenko , Wolfram Sang Cc: "Rafael J . Wysocki" , Len Brown , Darren Hart , Andy Shevchenko , ACPI Devel Maling List , Platform Driver , Linux Kernel Mailing List , linux-i2c@vger.kernel.org References: <20200426104713.216896-1-hdegoede@redhat.com> <20200426104713.216896-2-hdegoede@redhat.com> From: Hans de Goede Message-ID: <66619a61-c398-5a8a-4ee0-13dbe5d2c559@redhat.com> Date: Mon, 27 Apr 2020 17:06:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 4/27/20 3:18 PM, Andy Shevchenko wrote: > On Mon, Apr 27, 2020 at 3:51 PM Hans de Goede wrote: >> >> Hi, >> >> On 4/26/20 7:59 PM, Andy Shevchenko wrote: >>> On Sun, Apr 26, 2020 at 1:47 PM Hans de Goede wrote: >>>> >>>> In some cases the driver for the i2c_client-s which i2c-multi-instantiate >>>> instantiates may need access some fields / methods from to the ACPI fwnode >>>> for which i2c_clients are being instantiated. >>>> >>>> An example of this are CPLM3218 ACPI device-s. These contain CPM0 and >>>> CPM1 packages with various information (e.g. register init values) which >>>> the driver needs. >>>> >>>> Passing the fwnode through the i2c_board_info struct also gives the >>>> i2c-core access to it, and if we do not pass an IRQ then the i2c-core >>>> will use the fwnode to get an IRQ, see i2c_acpi_get_irq(). >>> >>> I'm wondering, can we rather do it in the same way like we do for >>> GPIO/APIC case here. >>> Introduce IRQ_RESOURCE_SHARED (or so) and >>> >>> case _SHARED: >>> irq = i2c_acpi_get_irq(); >>> ... >>> >>> ? >> >> I think you are miss-understanding the problem. The problem is not that >> we want to share the IRQ, the problem is that we want to pass the single >> IRQ in the resources to only 1 of the instantiated I2C-clients. But if we >> do not pass an IRQ (we leave it at 0) and we do pass the fwnode then >> i2c-core-base.c will see that there is an ACPI-node attached to the >> device and will call i2c_acpi_get_irq(). > > Do we know ahead which device should take IRQ resource and which should not? > Can we use current _NONE flag for them? The problem is not internal to i2c-multi-instantiate.c, the problem (once we pass a fwnode) is the API between i2c-multi-instantiate.c and the i2c-core. For the IRQ_RESOURCE_NONE case i2c-multi-instantiate.c sets board_info.irq to 0, which is the correct way to specify that we do not have an IRQ, but if don't pass an IRQ then the i2c-core will try to find one itself. And once we pass the fwnode, then the "try to find one itself" code will call i2c_acpi_get_irq() and find the same IRQ for clients we instantiate, leading to the earlier mentioned IRQ conflict. We could set board_info.irq to -ENOENT to indicate that there should not be an irq. But that will get passed to various i2c-drivers, many of which check for an irq like this: if (client->irq) { ... } We can avoid this, without needing to change all the drivers by making the i2c-core check for board_info.irq < 0 to skip its own "try to find IRQ" code and then set client->irq to 0 after that check, rather then setting it to board_info.irq = -ENOENT. If we do that then we can unconditionally pass the fwnode in the i2c-multi-instantiate code. Regards, Hans >> So the solution is definitely not calling i2c_acpi_get_irq() inside >> i2c-multi-instantiate.c we want to avoid the i2c_acpi_get_irq(), >> leaving the other 2 clients for the BSG1160 device without an IRQ >> and thus avoiding the IRQ mismatch (it is a mismatch because the >> drivers do not set the shared flag; and that is ok, we do not want >> to share the IRQ, it is just for the accelerometer AFAIK). > >>>> This is a problem when there is only an IRQ for 1 of the clients described >>>> in the ACPI device we are instantiating clients for. If we unconditionally >>>> pass the fwnode, then i2c_acpi_get_irq() will assign the same IRQ to all >>>> clients instantiated, leading to kernel-oopses like this (BSG1160 device): >>>> >>>> [ 27.340557] genirq: Flags mismatch irq 76. 00002001 (bmc150_magn_event) vs. 00000001 (bmc150_accel_event) >>>> [ 27.340567] Call Trace: >>>> ... >>>> >>>> So we cannot simply always pass the fwnode. This commit adds a PASS_FWNODE >>>> flag, which can be used to pass the fwnode in cases where we do not have >>>> the IRQ problem and the driver for the instantiated client(s) needs access >>>> to the fwnode. >>>> >>>> Signed-off-by: Hans de Goede >>>> --- >>>> drivers/platform/x86/i2c-multi-instantiate.c | 6 ++++++ >>>> 1 file changed, 6 insertions(+) >>>> >>>> diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c >>>> index 6acc8457866e..dcafb1a29d17 100644 >>>> --- a/drivers/platform/x86/i2c-multi-instantiate.c >>>> +++ b/drivers/platform/x86/i2c-multi-instantiate.c >>>> @@ -20,6 +20,8 @@ >>>> #define IRQ_RESOURCE_GPIO 1 >>>> #define IRQ_RESOURCE_APIC 2 >>>> >>>> +#define PASS_FWNODE BIT(2) >>>> + >>>> struct i2c_inst_data { >>>> const char *type; >>>> unsigned int flags; >>>> @@ -93,6 +95,10 @@ 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; >>>> + >>>> + if (inst_data[i].flags & PASS_FWNODE) >>>> + 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); >>>> -- >>>> 2.26.0 >>>> >>> >>> >> > >