From patchwork Fri Jun 21 12:24:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 806419 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DBC31509B9 for ; Fri, 21 Jun 2024 12:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972745; cv=none; b=dqrntYRgGTxPJ9ENbsWvzw624ZMpwdyhHfx3wIvrx83QP3P2eIsYTwWCnIAohRXLNiwQtS4cRHVXrYbltgcLXLyeEcUYr48TXbT+Nl4L/VexlC1rOUqcdzSoTA6CWTJnet6vl6WF9D/1Tjxxk3m66UK2oLctS62kbtu+td/DBN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972745; c=relaxed/simple; bh=3QU6ZyVaBkkmIiBEFdsmiq53YAbradVpP/7O0qV7DGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d0kSSyu/EVBkPP7wqb4vfpqh8x1G45P+gPxp6CtLfiZVlhVG+SBOrMrL+Dg01TrvSm+fKuIro+j5mK+xGNFNxThwy2pN9ChqxUaj+nEWqpouslfetCXpynXCFq4Pdyijgntboc30biM3kNtWq+xbvHzclnhjTVe+OPQ98Vr+3YM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=atow1myc; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="atow1myc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718972742; 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=TtoIiYy272+KWaweSsE43k7xo44wbDfLPE8VNpELdg4=; b=atow1mycA1RiEr3DmX94FlUpmJXFKKqILBsxnDdWCVyHySM/XsJODAwPTuN52vds6zFh8U SOi2vaHA55vNx7z6734NC4aXis5lRsUZam/ZJnKDRzUQEsoFEUHMs7y8FmRmd7ExVhVk+J P67DS97nKo6qx/hIL/CxImV0/koMkao= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-6kgrN5tvOnyuFgB0DfJUpQ-1; Fri, 21 Jun 2024 08:25:39 -0400 X-MC-Unique: 6kgrN5tvOnyuFgB0DfJUpQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 538A81937A99; Fri, 21 Jun 2024 12:25:25 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.69]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9DBFD3000F04; Fri, 21 Jun 2024 12:25:10 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Andy Shevchenko , Paul Menzel , Wolfram Sang Cc: Hans de Goede , eric.piel@tremplin-utc.net, Marius Hoch , Dell.Client.Kernel@dell.com, Kai Heng Feng , platform-driver-x86@vger.kernel.org, Jean Delvare , Andi Shyti , linux-i2c@vger.kernel.org Subject: [PATCH v3 1/6] i2c: core: Setup i2c_adapter runtime-pm before calling device_add() Date: Fri, 21 Jun 2024 14:24:56 +0200 Message-ID: <20240621122503.10034-2-hdegoede@redhat.com> In-Reply-To: <20240621122503.10034-1-hdegoede@redhat.com> References: <20240621122503.10034-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Platform glue code, which is not build into the kernel and thus cannot use i2c_register_board_info() may want to use bus_register_notifier() to listen for i2c-adapters to show up on which the platform code needs to manually instantiate platform specific i2c_clients. This results in calling i2c_new_client_device() from the bus notifier which happens near the device_add() call. If the i2c-core has not yet setup runtime-pm (specifically the no-callbacks and ignore-children flags) for the device embedded inside struct i2c_adapter and the driver for the i2c_client calls pm_runtime_set_active() this will trigger the following error inside __pm_runtime_set_status(): "runtime PM trying to activate child device %s but parent (%s) is not active\n" and the i2c_client's runtime-status will not be updated. Split the device_register() call for the adapter into device_initialize() and device_add() and move the pm-runtime init calls inbetween these 2 calls so that the runtime-status can be correctly set when a driver binds from the bus-notifier. Note the moved pm-runtime init calls just override the initial value of some flags in struct device set by device_initialize() and calling these before device_add() is safe. Signed-off-by: Hans de Goede --- drivers/i2c/i2c-core-base.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index db0d1ac82910..fcb4696f1f93 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1521,7 +1521,13 @@ static int i2c_register_adapter(struct i2c_adapter *adap) dev_set_name(&adap->dev, "i2c-%d", adap->nr); adap->dev.bus = &i2c_bus_type; adap->dev.type = &i2c_adapter_type; - res = device_register(&adap->dev); + device_initialize(&adap->dev); + device_enable_async_suspend(&adap->dev); + pm_runtime_no_callbacks(&adap->dev); + pm_suspend_ignore_children(&adap->dev, true); + pm_runtime_enable(&adap->dev); + + res = device_add(&adap->dev); if (res) { pr_err("adapter '%s': can't register device (%d)\n", adap->name, res); goto out_list; @@ -1533,11 +1539,6 @@ static int i2c_register_adapter(struct i2c_adapter *adap) if (res) goto out_reg; - device_enable_async_suspend(&adap->dev); - pm_runtime_no_callbacks(&adap->dev); - pm_suspend_ignore_children(&adap->dev, true); - pm_runtime_enable(&adap->dev); - res = i2c_init_recovery(adap); if (res == -EPROBE_DEFER) goto out_reg; From patchwork Fri Jun 21 12:24:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 806922 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47FB01509A5 for ; Fri, 21 Jun 2024 12:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972752; cv=none; b=kObEC1jVK0l1/9bw9DYbTskykxh+iCEHIUHyltKi+CdWyDOwomGkNpin1XrgclzyldR/xWMIW+sMtECzAlmb0R+ga1DS1k42LU375jvw72gR+YRZOUz4W6phc0AWasL11kvNSjo1UMN8QCXqp0xOHeDYhKVE4diuEz+R4SokAc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972752; c=relaxed/simple; bh=7AnuA9t8SkOmHDhFL3owoQl2T6QwQo0Re8HYlaQvRjg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tXKnFa9uBwnpLbE/Yq1IHJ6YhT4xnO75+ntriPH8XJNrWmCWZfPdEkYTPXimi8pnYIKPFaZXlh/tVJPCfzOUu1W7b8mtP8hGgRbYg8JQqCtPQW6AmMZ1D2xvmEFyAGrBjceFbAnAgMUXxXWJE2RCKZxQ4GjsOTgkDBdF3GFnDEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BatQ4vtO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BatQ4vtO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718972750; 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=ou2/aaKZonzrrblU7wDVgfWljjZmis7Sflpk2l1xDq8=; b=BatQ4vtOoLbUVItu3EwobNjvLasr8sDZBmWa8Keg5eukuM2QCpaQjAvW5qLv/FPvfKpe7k EdwhSzSzLqCNdc09nUEjGnJeJFX1HFM7sw2u9dBixSGvEs/87dR5m2W5yHWIvFv+LzuUeF WC+Jd22P+Ng52z1N86FupUWba7rNYcw= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-VB-BFExeOeq8ahAshSZtpw-1; Fri, 21 Jun 2024 08:25:46 -0400 X-MC-Unique: VB-BFExeOeq8ahAshSZtpw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 49A951953963; Fri, 21 Jun 2024 12:25:41 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.69]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B11D53002085; Fri, 21 Jun 2024 12:25:25 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Andy Shevchenko , Paul Menzel , Wolfram Sang Cc: Hans de Goede , eric.piel@tremplin-utc.net, Marius Hoch , Dell.Client.Kernel@dell.com, Kai Heng Feng , platform-driver-x86@vger.kernel.org, Jean Delvare , Andi Shyti , linux-i2c@vger.kernel.org Subject: [PATCH v3 2/6] i2c: i801: Use a different adapter-name for IDF adapters Date: Fri, 21 Jun 2024 14:24:57 +0200 Message-ID: <20240621122503.10034-3-hdegoede@redhat.com> In-Reply-To: <20240621122503.10034-1-hdegoede@redhat.com> References: <20240621122503.10034-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On chipsets with a second 'Integrated Device Function' SMBus controller use a different adapter-name for the second IDF adapter. This allows platform glue code which is looking for the primary i801 adapter to manually instantiate i2c_clients on to differentiate between the 2. This allows such code to find the primary i801 adapter by name, without needing to duplicate the PCI-ids to feature-flags mapping from i2c-i801.c. Signed-off-by: Hans de Goede --- drivers/i2c/busses/i2c-i801.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index d2d2a6dbe29f..5ac5bbd60d45 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1760,8 +1760,13 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) i801_add_tco(priv); - snprintf(priv->adapter.name, sizeof(priv->adapter.name), - "SMBus I801 adapter at %04lx", priv->smba); + if (priv->features & FEATURE_IDF) + snprintf(priv->adapter.name, sizeof(priv->adapter.name), + "SMBus I801 IDF adapter at %04lx", priv->smba); + else + snprintf(priv->adapter.name, sizeof(priv->adapter.name), + "SMBus I801 adapter at %04lx", priv->smba); + err = i2c_add_adapter(&priv->adapter); if (err) { platform_device_unregister(priv->tco_pdev); From patchwork Fri Jun 21 12:24:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 806418 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AED811514D3 for ; Fri, 21 Jun 2024 12:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972757; cv=none; b=Ww8vFznGysqCWXh6yJ8Rr2IMJBoLQS6HJqWVgyZxCQFOOaIA/8zhIcZ+uHWTVV2/DllxP6Z2eHd3e15WaQld7i9tmzqL85ngU/JELD/6x4j/a2b9w/W23XgCLBi6vdhJtBe/TMCnh0IrtQyVxVEvzSMAXgnMtVNV+Qx2iP6U87Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972757; c=relaxed/simple; bh=hi2IhcAPrEkuVdC3lEIuP7TEcptRUyH6TYUl2OKXttk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e9BGstdFhezmT8q3z3rQ27OAb6paVhDqpR6LleUuAb5uCfdHieYqH4sJpg5UFABQTZhFGr/c02yGNxs2+ZQ5jUhCwe6jzccC0HGfEsoqrLDAIGEB5/J9V/fOjE67c1nLEGIe1b6K5QvuHUiKg50XQEX6A6vVa96QSyHQNoe2V9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VZ69y9wx; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VZ69y9wx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718972754; 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=ecMUNR1vnhIBeZ6R6L+1jK0hzBXkgvwZGYbHmBO4gSk=; b=VZ69y9wx05i+a53saeincdL8RNedckUj4yYat2E8DFJ4xgAVHlFrurSWyeklMcmvqnHi0M iqWSmpf6xI2/Z9EE4xtsmJedGFwlAlhii1KcJa4lh/OlmyExCmGemlEYSvKyDDdAV9fnQm q2AXyBkHptMzQ2aCXrOQ2C9tvh1owbU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-oXZ0Ljk2Nz6DR0nCuhwSvg-1; Fri, 21 Jun 2024 08:25:49 -0400 X-MC-Unique: oXZ0Ljk2Nz6DR0nCuhwSvg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 68A4C1956094; Fri, 21 Jun 2024 12:25:45 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.69]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A1EBF3000218; Fri, 21 Jun 2024 12:25:41 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Andy Shevchenko , Paul Menzel , Wolfram Sang Cc: Hans de Goede , eric.piel@tremplin-utc.net, Marius Hoch , Dell.Client.Kernel@dell.com, Kai Heng Feng , platform-driver-x86@vger.kernel.org, Jean Delvare , Andi Shyti , linux-i2c@vger.kernel.org Subject: [PATCH v3 3/6] platform/x86: dell-smo8800: Move instantiation of lis3lv02d i2c_client from i2c-i801 to dell-smo8800 Date: Fri, 21 Jun 2024 14:24:58 +0200 Message-ID: <20240621122503.10034-4-hdegoede@redhat.com> In-Reply-To: <20240621122503.10034-1-hdegoede@redhat.com> References: <20240621122503.10034-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 It is not necessary to handle the Dell specific instantiation of i2c_client-s for SMO88xx ACPI devices without an ACPI I2cResource inside the generic i801 I2C adapter driver. The kernel already instantiates platform_device-s for these ACPI devices and the drivers/platform/x86/dell/dell-smo8800.c driver binds to these platform drivers. Move the i2c_client instantiation from the generic i2c-i801 driver to the SMO88xx specific dell-smo8800 driver. Moving the i2c_client instantiation here has the following advantages: 1. This moves the SMO88xx ACPI device quirk handling away from the generic i2c-i801 module which is loaded on all Intel x86 machines to the SMO88xx specific dell-smo8800 module where it belongs. 2. This removes the duplication of the SMO88xx ACPI Hardware ID (HID) table between the i2c-i801 and dell-smo8800 drivers. 3. This allows extending the quirk handling by adding new code and related module parameters to the dell-smo8800 driver, without needing to modify the i2c-i801 code. Signed-off-by: Hans de Goede --- Note the goto out_put_adapter, which can be avoided by moving the DMI check up, is there deliberately as preparation for adding support to probe for the i2c address in case there is no DMI match. --- Changes in v3: - Use an i2c bus notifier so that the i2c_client will still be instantiated if the i801 i2c_adapter shows up later or is re-probed (removed + added again) - Switch to standard dmi_system_id matching to check both sys-vendor + product-name DMI fields - Use unique i2c_adapter->name prefix for primary i2c_801 controller to avoid needing to duplicate PCI ids for extra IDF i2c_801 i2c_adapter-s - Drop MODULE_SOFTDEP("pre: i2c-i801"), this is now no longer necessary - Rebase on Torvalds master for recent additions of extra models in the dell_lis3lv02d_devices[] list Changes in v2: - Use a pci_device_id table to check for IDF (non main) i2c-i801 SMBusses - Add a comment documenting the IDF PCI device ids --- drivers/i2c/busses/i2c-i801.c | 124 ------------- drivers/platform/x86/dell/dell-smo8800.c | 214 ++++++++++++++++++++++- 2 files changed, 213 insertions(+), 125 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 5ac5bbd60d45..db8d31411148 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1153,127 +1153,6 @@ static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap) } } -/* NOTE: Keep this list in sync with drivers/platform/x86/dell-smo8800.c */ -static const char *const acpi_smo8800_ids[] = { - "SMO8800", - "SMO8801", - "SMO8810", - "SMO8811", - "SMO8820", - "SMO8821", - "SMO8830", - "SMO8831", -}; - -static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle, - u32 nesting_level, - void *context, - void **return_value) -{ - struct acpi_device_info *info; - acpi_status status; - char *hid; - int i; - - status = acpi_get_object_info(obj_handle, &info); - if (ACPI_FAILURE(status)) - return AE_OK; - - if (!(info->valid & ACPI_VALID_HID)) - goto smo88xx_not_found; - - hid = info->hardware_id.string; - if (!hid) - goto smo88xx_not_found; - - i = match_string(acpi_smo8800_ids, ARRAY_SIZE(acpi_smo8800_ids), hid); - if (i < 0) - goto smo88xx_not_found; - - kfree(info); - - *return_value = NULL; - return AE_CTRL_TERMINATE; - -smo88xx_not_found: - kfree(info); - return AE_OK; -} - -static bool is_dell_system_with_lis3lv02d(void) -{ - void *err = ERR_PTR(-ENOENT); - - if (!dmi_match(DMI_SYS_VENDOR, "Dell Inc.")) - return false; - - /* - * Check that ACPI device SMO88xx is present and is functioning. - * Function acpi_get_devices() already filters all ACPI devices - * which are not present or are not functioning. - * ACPI device SMO88xx represents our ST microelectronics lis3lv02d - * accelerometer but unfortunately ACPI does not provide any other - * information (like I2C address). - */ - acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err); - - return !IS_ERR(err); -} - -/* - * Accelerometer's I2C address is not specified in DMI nor ACPI, - * so it is needed to define mapping table based on DMI product names. - */ -static const struct { - const char *dmi_product_name; - unsigned short i2c_addr; -} dell_lis3lv02d_devices[] = { - /* - * Dell platform team told us that these Latitude devices have - * ST microelectronics accelerometer at I2C address 0x29. - */ - { "Latitude E5250", 0x29 }, - { "Latitude E5450", 0x29 }, - { "Latitude E5550", 0x29 }, - { "Latitude E6440", 0x29 }, - { "Latitude E6440 ATG", 0x29 }, - { "Latitude E6540", 0x29 }, - /* - * Additional individual entries were added after verification. - */ - { "Latitude 5480", 0x29 }, - { "Precision 3540", 0x29 }, - { "Vostro V131", 0x1d }, - { "Vostro 5568", 0x29 }, - { "XPS 15 7590", 0x29 }, -}; - -static void register_dell_lis3lv02d_i2c_device(struct i801_priv *priv) -{ - struct i2c_board_info info; - const char *dmi_product_name; - int i; - - dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME); - for (i = 0; i < ARRAY_SIZE(dell_lis3lv02d_devices); ++i) { - if (strcmp(dmi_product_name, - dell_lis3lv02d_devices[i].dmi_product_name) == 0) - break; - } - - if (i == ARRAY_SIZE(dell_lis3lv02d_devices)) { - dev_warn(&priv->pci_dev->dev, - "Accelerometer lis3lv02d is present on SMBus but its" - " address is unknown, skipping registration\n"); - return; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = dell_lis3lv02d_devices[i].i2c_addr; - strscpy(info.type, "lis3lv02d", I2C_NAME_SIZE); - i2c_new_client_device(&priv->adapter, &info); -} - /* Register optional slaves */ static void i801_probe_optional_slaves(struct i801_priv *priv) { @@ -1293,9 +1172,6 @@ static void i801_probe_optional_slaves(struct i801_priv *priv) if (dmi_name_in_vendors("FUJITSU")) dmi_walk(dmi_check_onboard_devices, &priv->adapter); - if (is_dell_system_with_lis3lv02d()) - register_dell_lis3lv02d_i2c_device(priv); - /* Instantiate SPD EEPROMs unless the SMBus is multiplexed */ #ifdef CONFIG_I2C_I801_MUX if (!priv->mux_pdev) diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c index f7ec17c56833..cd2e48405859 100644 --- a/drivers/platform/x86/dell/dell-smo8800.c +++ b/drivers/platform/x86/dell/dell-smo8800.c @@ -4,20 +4,26 @@ * * Copyright (C) 2012 Sonal Santan * Copyright (C) 2014 Pali Rohár + * Copyright (C) 2023 Hans de Goede * * This is loosely based on lis3lv02d driver. */ #define DRIVER_NAME "smo8800" +#include +#include #include +#include #include #include #include #include #include +#include #include #include +#include struct smo8800_device { u32 irq; /* acpi device irq */ @@ -25,6 +31,9 @@ struct smo8800_device { struct miscdevice miscdev; /* for /dev/freefall */ unsigned long misc_opened; /* whether the device is open */ wait_queue_head_t misc_wait; /* Wait queue for the misc dev */ + struct notifier_block i2c_nb;/* i2c bus notifier */ + struct work_struct i2c_work; /* Work for instantiating lis3lv02d i2c_client */ + struct i2c_client *i2c_dev; /* i2c_client for lis3lv02d */ struct device *dev; /* acpi device */ }; @@ -103,6 +112,184 @@ static const struct file_operations smo8800_misc_fops = { .release = smo8800_misc_release, }; +/* + * Accelerometer's I2C address is not specified in DMI nor ACPI, + * so it is needed to define mapping table based on DMI product names. + */ +static const struct dmi_system_id smo8800_lis3lv02d_devices[] = { + /* + * Dell platform team told us that these Latitude devices have + * ST microelectronics accelerometer at I2C address 0x29. + */ + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5250"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5450"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5550"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6440 ATG"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6540"), + }, + .driver_data = (void *)0x29L, + }, + /* + * Additional individual entries were added after verification. + */ + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3540"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), + }, + .driver_data = (void *)0x1dL, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 5568"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 7590"), + }, + .driver_data = (void *)0x29L, + }, + { } +}; + +static int smo8800_find_i801(struct device *dev, void *data) +{ + struct i2c_adapter *adap, **adap_ret = data; + + adap = i2c_verify_adapter(dev); + if (!adap) + return 0; + + if (!strstarts(adap->name, "SMBus I801 adapter")) + return 0; + + *adap_ret = i2c_get_adapter(adap->nr); + return 1; +} + +static void smo8800_instantiate_i2c_client(struct work_struct *work) +{ + struct smo8800_device *smo8800 = + container_of(work, struct smo8800_device, i2c_work); + const struct dmi_system_id *lis3lv02d_dmi_id; + struct i2c_board_info info = { }; + struct i2c_adapter *adap = NULL; + + if (smo8800->i2c_dev) + return; + + bus_for_each_dev(&i2c_bus_type, NULL, &adap, smo8800_find_i801); + if (!adap) + return; + + lis3lv02d_dmi_id = dmi_first_match(smo8800_lis3lv02d_devices); + if (!lis3lv02d_dmi_id) + goto out_put_adapter; + + info.addr = (long)lis3lv02d_dmi_id->driver_data; + strscpy(info.type, "lis3lv02d", I2C_NAME_SIZE); + + smo8800->i2c_dev = i2c_new_client_device(adap, &info); + if (IS_ERR(smo8800->i2c_dev)) { + dev_err(smo8800->dev, "error %ld registering %s i2c_client\n", + PTR_ERR(smo8800->i2c_dev), info.type); + smo8800->i2c_dev = NULL; + } else { + dev_dbg(smo8800->dev, "registered %s i2c_client on address 0x%02x\n", + info.type, info.addr); + } + +out_put_adapter: + i2c_put_adapter(adap); +} + +static int smo8800_i2c_bus_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct smo8800_device *smo8800 = + container_of(nb, struct smo8800_device, i2c_nb); + struct device *dev = data; + struct i2c_client *client; + struct i2c_adapter *adap; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + adap = i2c_verify_adapter(dev); + if (!adap) + break; + + if (strstarts(adap->name, "SMBus I801 adapter")) + queue_work(system_long_wq, &smo8800->i2c_work); + break; + case BUS_NOTIFY_REMOVED_DEVICE: + client = i2c_verify_client(dev); + if (!client) + break; + + if (smo8800->i2c_dev == client) { + dev_dbg(smo8800->dev, "accelerometer i2c_client removed\n"); + smo8800->i2c_dev = NULL; + } + break; + default: + break; + } + + return 0; +} + static int smo8800_probe(struct platform_device *device) { int err; @@ -118,8 +305,10 @@ static int smo8800_probe(struct platform_device *device) smo8800->miscdev.minor = MISC_DYNAMIC_MINOR; smo8800->miscdev.name = "freefall"; smo8800->miscdev.fops = &smo8800_misc_fops; + smo8800->i2c_nb.notifier_call = smo8800_i2c_bus_notify; init_waitqueue_head(&smo8800->misc_wait); + INIT_WORK(&smo8800->i2c_work, smo8800_instantiate_i2c_client); err = misc_register(&smo8800->miscdev); if (err) { @@ -147,8 +336,26 @@ static int smo8800_probe(struct platform_device *device) dev_dbg(&device->dev, "device /dev/freefall registered with IRQ %d\n", smo8800->irq); + + if (dmi_check_system(smo8800_lis3lv02d_devices)) { + /* + * Register i2c-bus notifier + queue initial scan for lis3lv02d + * i2c_client instantiation. + */ + err = bus_register_notifier(&i2c_bus_type, &smo8800->i2c_nb); + if (err) + goto error_free_irq; + + queue_work(system_long_wq, &smo8800->i2c_work); + } else { + dev_warn(&device->dev, + "lis3lv02d accelerometer is present on SMBus but its address is unknown, skipping registration\n"); + } + return 0; +error_free_irq: + free_irq(smo8800->irq, smo8800); error: misc_deregister(&smo8800->miscdev); return err; @@ -158,12 +365,17 @@ static void smo8800_remove(struct platform_device *device) { struct smo8800_device *smo8800 = platform_get_drvdata(device); + if (dmi_check_system(smo8800_lis3lv02d_devices)) { + bus_unregister_notifier(&i2c_bus_type, &smo8800->i2c_nb); + cancel_work_sync(&smo8800->i2c_work); + i2c_unregister_device(smo8800->i2c_dev); + } + free_irq(smo8800->irq, smo8800); misc_deregister(&smo8800->miscdev); dev_dbg(&device->dev, "device /dev/freefall unregistered\n"); } -/* NOTE: Keep this list in sync with drivers/i2c/busses/i2c-i801.c */ static const struct acpi_device_id smo8800_ids[] = { { "SMO8800", 0 }, { "SMO8801", 0 }, From patchwork Fri Jun 21 12:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 806921 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B01A1514FF for ; Fri, 21 Jun 2024 12:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972765; cv=none; b=uN21ZziKDAU2MyPpRDK5ofrYeaFiyemIHOOaaJQt5N9jWwemvjHXKM/snyeB2yKd/p8k/xKVDUSCiC8hlUKA7aLlOfCSYydcxyAwTTM+jQ8U81KRmpz5jzkf26l3IqVa68IHQe6NjtDEors4498gV4ZEB8FHm/KmI6mSVTSa/jQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972765; c=relaxed/simple; bh=5zQtHHEySJrpIHG82D6ki2OwG6KBFQm58fIYJBGhuVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i2L3XkNePmCRbl0JwLrMENZ1Lf4jmDZrG/3kd44FM84vv0YqRLI3D43gkI1l8nyTBC1jTAFde/+IZprAoO8ObbiSfoh9oNi7sJ3mGrtvi6D1ZmSj/LJAtYzMtfXAnKZ3LEOXg1QvOnL9zWFpnVAzIS5D5MPmZEPdrCoi5EfZ7Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aVSvfytw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aVSvfytw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718972763; 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=xZgONObBZJffcLWVJq2vpGlbmD97vuv/2ZnFqkIiFGQ=; b=aVSvfytwaq69kUR3R+fPMHeD7EFvwDIXqlSZ/R+vBYrLwqpcDsahgBN6AuBJY58rBq4htT iUnV2dy7ZGyqqFOq7RPSrV6a2YFPz+3z/tLPiev8G/5uzAJLGTJ8vQKbt8r17SlBM7Jerf RbnAFW0kOBx0NDgWiwCXhqZ1sv+ChZs= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-n771SOZxPHicxhsxLcz6ew-1; Fri, 21 Jun 2024 08:25:53 -0400 X-MC-Unique: n771SOZxPHicxhsxLcz6ew-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7960F1953976; Fri, 21 Jun 2024 12:25:49 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.69]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C31103000603; Fri, 21 Jun 2024 12:25:45 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Andy Shevchenko , Paul Menzel , Wolfram Sang Cc: Hans de Goede , eric.piel@tremplin-utc.net, Marius Hoch , Dell.Client.Kernel@dell.com, Kai Heng Feng , platform-driver-x86@vger.kernel.org, Jean Delvare , Andi Shyti , linux-i2c@vger.kernel.org Subject: [PATCH v3 4/6] platform/x86: dell-smo8800: Allow lis3lv02d i2c_client instantiation without IRQ Date: Fri, 21 Jun 2024 14:24:59 +0200 Message-ID: <20240621122503.10034-5-hdegoede@redhat.com> In-Reply-To: <20240621122503.10034-1-hdegoede@redhat.com> References: <20240621122503.10034-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 The Dell XPS 15 9550 can have a 60Wh battery, leaving space for a 2.5" sata disk; or a 90Wh battery in which case the battery occupies the space for the optional 2.5" sata disk. On models with the 90Wh battery and thus without a 2.5" sata disk, the BIOS does not add an IRQ resource to the SMO8810 ACPI device. Make the misc-device registration and the requesting of the IRQ optional and instantiate a lis3lv02d i2c_client independent of the IRQ being there, so that the non freefall lis3lv02d functionality can still be used. Note that IRQ 0 is not a valid IRQ number for platform IRQs and this patch relies on that. Signed-off-by: Hans de Goede --- drivers/platform/x86/dell/dell-smo8800.c | 67 +++++++++++++----------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c index cd2e48405859..2e49bbb569c6 100644 --- a/drivers/platform/x86/dell/dell-smo8800.c +++ b/drivers/platform/x86/dell/dell-smo8800.c @@ -310,33 +310,32 @@ static int smo8800_probe(struct platform_device *device) init_waitqueue_head(&smo8800->misc_wait); INIT_WORK(&smo8800->i2c_work, smo8800_instantiate_i2c_client); - err = misc_register(&smo8800->miscdev); - if (err) { - dev_err(&device->dev, "failed to register misc dev: %d\n", err); - return err; + err = platform_get_irq_optional(device, 0); + if (err > 0) + smo8800->irq = err; + + if (smo8800->irq) { + err = misc_register(&smo8800->miscdev); + if (err) { + dev_err(&device->dev, "failed to register misc dev: %d\n", err); + return err; + } + + err = request_threaded_irq(smo8800->irq, smo8800_interrupt_quick, + smo8800_interrupt_thread, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + DRIVER_NAME, smo8800); + if (err) { + dev_err(&device->dev, + "failed to request thread for IRQ %d: %d\n", + smo8800->irq, err); + goto error; + } + + dev_dbg(&device->dev, "device /dev/freefall registered with IRQ %d\n", + smo8800->irq); } - platform_set_drvdata(device, smo8800); - - err = platform_get_irq(device, 0); - if (err < 0) - goto error; - smo8800->irq = err; - - err = request_threaded_irq(smo8800->irq, smo8800_interrupt_quick, - smo8800_interrupt_thread, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - DRIVER_NAME, smo8800); - if (err) { - dev_err(&device->dev, - "failed to request thread for IRQ %d: %d\n", - smo8800->irq, err); - goto error; - } - - dev_dbg(&device->dev, "device /dev/freefall registered with IRQ %d\n", - smo8800->irq); - if (dmi_check_system(smo8800_lis3lv02d_devices)) { /* * Register i2c-bus notifier + queue initial scan for lis3lv02d @@ -350,14 +349,20 @@ static int smo8800_probe(struct platform_device *device) } else { dev_warn(&device->dev, "lis3lv02d accelerometer is present on SMBus but its address is unknown, skipping registration\n"); + if (!smo8800->irq) + return -ENODEV; } + platform_set_drvdata(device, smo8800); return 0; error_free_irq: - free_irq(smo8800->irq, smo8800); + if (smo8800->irq) { + free_irq(smo8800->irq, smo8800); error: - misc_deregister(&smo8800->miscdev); + misc_deregister(&smo8800->miscdev); + } + return err; } @@ -371,9 +376,11 @@ static void smo8800_remove(struct platform_device *device) i2c_unregister_device(smo8800->i2c_dev); } - free_irq(smo8800->irq, smo8800); - misc_deregister(&smo8800->miscdev); - dev_dbg(&device->dev, "device /dev/freefall unregistered\n"); + if (smo8800->irq) { + free_irq(smo8800->irq, smo8800); + misc_deregister(&smo8800->miscdev); + dev_dbg(&device->dev, "device /dev/freefall unregistered\n"); + } } static const struct acpi_device_id smo8800_ids[] = { From patchwork Fri Jun 21 12:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 806417 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB3B015216C for ; Fri, 21 Jun 2024 12:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972789; cv=none; b=VbeVnsGntNB5L5l1JgdeETjGFXsTimhqcgnHmWBfxo1ntiz4GQuFzRZRwtgVXugib9rdBIdKHbn/2C3Nu2AHq6I/A4/cHT9oOvfdS9tTSuetqfWlvNHHwf07xovlNPuLF2XRClI2HlaUKU4ii2FZBnF6teWXo4xwLOGMxP1BQgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972789; c=relaxed/simple; bh=GqCJUEu6HvllrEv6mt7zNui7VJwFT5x1A/AE8OsFp+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eghezDPy1Od9b3B0uhDmEvEN4weGsEDjN6q+d9wMnSAImTPqFIf7ceR+pdzxqYY0+w+j5uL4Tuio/QyntM5DtGPMCYKI/3rW9XpNZ5DqNeOktw/4jEe69YmLO/+nYOTqYhjrUMo40LDxalpa2PYdnFHH7H/sBX3d/OsGBmMrA9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=O9mUBpJW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O9mUBpJW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718972787; 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=6vIlGIjnZaRmqlGYYwh9589os9i1avVj+5PIgcozfw4=; b=O9mUBpJWgxT+JsCsNuog5C774GOkoBFFEUQWMP/Fm/b1PojNr8ZGDqp/3KXAEwMw0eRshl xTAOMeKVGWJXVy897MvcBo7Ud4fAQ4vOc73XLrN2UZ/nxSa+jboLE0hCyOsYpU2EeEGjbM 21Ys/IU5YKHI7/ASH1byAQHfc3iIeoQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-IkT0cEbvPgCDX_HyHi4ZVg-1; Fri, 21 Jun 2024 08:26:19 -0400 X-MC-Unique: IkT0cEbvPgCDX_HyHi4ZVg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84F601955D89; Fri, 21 Jun 2024 12:26:06 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.69]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E7965300144C; Fri, 21 Jun 2024 12:25:49 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Andy Shevchenko , Paul Menzel , Wolfram Sang Cc: Hans de Goede , eric.piel@tremplin-utc.net, Marius Hoch , Dell.Client.Kernel@dell.com, Kai Heng Feng , platform-driver-x86@vger.kernel.org, Jean Delvare , Andi Shyti , linux-i2c@vger.kernel.org Subject: [PATCH v3 5/6] platform/x86: dell-smo8800: Add a couple more models to dell_lis3lv02d_devices[] Date: Fri, 21 Jun 2024 14:25:00 +0200 Message-ID: <20240621122503.10034-6-hdegoede@redhat.com> In-Reply-To: <20240621122503.10034-1-hdegoede@redhat.com> References: <20240621122503.10034-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Add the accelerometer address for the following laptop models to dell_lis3lv02d_devices[]: Dell Latitude E6330 Dell Latitude E6430 Dell XPS 15 9550 Tested-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/platform/x86/dell/dell-smo8800.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c index 2e49bbb569c6..4c79b2599d96 100644 --- a/drivers/platform/x86/dell/dell-smo8800.c +++ b/drivers/platform/x86/dell/dell-smo8800.c @@ -173,6 +173,20 @@ static const struct dmi_system_id smo8800_lis3lv02d_devices[] = { }, .driver_data = (void *)0x29L, }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6330"), + }, + .driver_data = (void *)0x29L, + }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6430"), + }, + .driver_data = (void *)0x29L, + }, { .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), @@ -194,6 +208,13 @@ static const struct dmi_system_id smo8800_lis3lv02d_devices[] = { }, .driver_data = (void *)0x29L, }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9550"), + }, + .driver_data = (void *)0x29L, + }, { .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), From patchwork Fri Jun 21 12:25:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 806920 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5227152166 for ; Fri, 21 Jun 2024 12:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972794; cv=none; b=Wy1MSP4xlsmZyXFHGFiRJs8iYNiBkCG0SwPaPFevmgv1MOySjzf/2R0qGm+ub0xp7RxEqAP179DZkMouUbCAa5/F4AMYQpzSRxgZ7PeC/HpZGx8aEzVgNlTfBpUuZwyL8Sgum+LxCmlB8uPhozlmIsU8nNFSDZaTFcmw2OEXmf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718972794; c=relaxed/simple; bh=A1l8Jhz+bDuY7N9pVlYA3yIk/SruRDs0ivBIjXPv9Dk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A8v3YKZ/pR7ScLgU2x8DV/hIu9uYbc0YO42ELo7ZRA/vIAmXHCyjMQ4rLaW96yF2lYano92Y0/mQRdBVNm+IcseBF/TfwszhbgkQqaI0bxIXrxF9DQTBk4OhwUS/6ozKgIOG4RZJgffSAwZurmsOTuxIO0FT9RhwZjhCokPAQ2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bDkbD4uy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bDkbD4uy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718972790; 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=/CYA+8vSRT7esfgbbxqXlZIh5TtFOMmDACTrtwInIDY=; b=bDkbD4uyChzmZySW5v/TAF7BcMslRm5aahn6d6avnHGWesticOCFerCBYWq4ZYyZZ9AgW0 5W2aySHEpGmhWnKbgrcOgsJJJ7fSzWA3k6B4OdW5+vccQNG+LCiIcW9Ap6OmIBtKNm1CUM 718jwpkwGSjkFsSQOa0NlNtmtq0g79c= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-HjhuZd9HMjC6EIy_xiCuNw-1; Fri, 21 Jun 2024 08:26:25 -0400 X-MC-Unique: HjhuZd9HMjC6EIy_xiCuNw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7370F19373F3; Fri, 21 Jun 2024 12:26:21 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.69]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BB08D301B8DE; Fri, 21 Jun 2024 12:26:05 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Andy Shevchenko , Paul Menzel , Wolfram Sang Cc: Hans de Goede , eric.piel@tremplin-utc.net, Marius Hoch , Dell.Client.Kernel@dell.com, Kai Heng Feng , platform-driver-x86@vger.kernel.org, Jean Delvare , Andi Shyti , linux-i2c@vger.kernel.org Subject: [PATCH v3 6/6] platform/x86: dell-smo8800: Add support for probing for the accelerometer i2c address Date: Fri, 21 Jun 2024 14:25:01 +0200 Message-ID: <20240621122503.10034-7-hdegoede@redhat.com> In-Reply-To: <20240621122503.10034-1-hdegoede@redhat.com> References: <20240621122503.10034-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Unfortunately the SMOxxxx ACPI device does not contain the i2c-address of the accelerometer. So a DMI product-name to address mapping table is used. At support to have the kernel probe for the i2c-address for modesl which are not on the list. The new probing code sits behind a new probe_i2c_addr module parameter, which is disabled by default because probing might be dangerous. Signed-off-by: Hans de Goede --- drivers/platform/x86/dell/dell-smo8800.c | 152 ++++++++++++++++++++++- 1 file changed, 147 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c index 4c79b2599d96..d64d200e927a 100644 --- a/drivers/platform/x86/dell/dell-smo8800.c +++ b/drivers/platform/x86/dell/dell-smo8800.c @@ -10,6 +10,7 @@ */ #define DRIVER_NAME "smo8800" +#define LIS3_WHO_AM_I 0x0f #include #include @@ -25,6 +26,10 @@ #include #include +static bool probe_i2c_addr; +module_param(probe_i2c_addr, bool, 0444); +MODULE_PARM_DESC(probe_i2c_addr, "Probe the i801 I2C bus for the accelerometer on models where the address is unknown"); + struct smo8800_device { u32 irq; /* acpi device irq */ atomic_t counter; /* count after last read */ @@ -225,6 +230,130 @@ static const struct dmi_system_id smo8800_lis3lv02d_devices[] = { { } }; +/* + * This is the kernel version of the single register device sanity checks from + * the i2c_safety_check function from lm_sensors sensor-detect script: + * This is meant to prevent access to 1-register-only devices, + * which are designed to be accessed with SMBus receive byte and SMBus send + * byte transactions (i.e. short reads and short writes) and treat SMBus + * read byte as a real write followed by a read. The device detection + * routines would write random values to the chip with possibly very nasty + * results for the hardware. Note that this function won't catch all such + * chips, as it assumes that reads and writes relate to the same register, + * but that's the best we can do. + */ +static int i2c_safety_check(struct device *dev, struct i2c_adapter *adap, u8 addr) +{ + union i2c_smbus_data smbus_data; + int err; + u8 data; + + /* + * First receive a byte from the chip, and remember it. This + * also checks if there is a device at the address at all. + */ + err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, + I2C_SMBUS_BYTE, &smbus_data); + if (err < 0) + return err; + + data = smbus_data.byte; + + /* + * Receive a byte again; very likely to be the same for + * 1-register-only devices. + */ + err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, + I2C_SMBUS_BYTE, &smbus_data); + if (err < 0) + return err; + + if (smbus_data.byte != data) + return 0; /* Not a 1-register-only device. */ + + /* + * Then try a standard byte read, with a register offset equal to + * the read byte; for 1-register-only device this should read + * the same byte value in return. + */ + err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, data, + I2C_SMBUS_BYTE_DATA, &smbus_data); + if (err < 0) + return err; + + if (smbus_data.byte != data) + return 0; /* Not a 1-register-only device. */ + + /* + * Then try a standard byte read, with a slightly different register + * offset; this should again read the register offset in return. + */ + err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, data ^ 0x01, + I2C_SMBUS_BYTE_DATA, &smbus_data); + if (err < 0) + return err; + + if (smbus_data.byte != (data ^ 0x01)) + return 0; /* Not a 1-register-only device. */ + + /* + * Apparently this is a 1-register-only device, restore the original + * register value and leave it alone. + */ + i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, data, + I2C_SMBUS_BYTE, NULL); + dev_warn(dev, "I2C safety check for address 0x%02x failed, skipping\n", addr); + return -ENODEV; +} + +static int smo8800_detect_accel(struct smo8800_device *smo8800, + struct i2c_adapter *adap, u8 addr, + struct i2c_board_info *info, bool probe) +{ + union i2c_smbus_data smbus_data; + const char *type; + int err; + + if (probe) { + dev_info(smo8800->dev, "Probing for accelerometer on address 0x%02x\n", addr); + err = i2c_safety_check(smo8800->dev, adap, addr); + if (err < 0) + return err; + } + + err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, LIS3_WHO_AM_I, + I2C_SMBUS_BYTE_DATA, &smbus_data); + if (err < 0) { + dev_warn(smo8800->dev, "Failed to read who-am-i register: %d\n", err); + return err; + } + + /* who-am-i register mappings from drivers/misc/lis3lv02d/lis3lv02d.c */ + switch (smbus_data.byte) { + case 0x32: + type = "lis331dlh"; + break; + case 0x33: + type = "lis2de12"; /* LIS3DC / HP3DC in drivers/misc/lis3lv02d/lis3lv02d.c */ + break; + case 0x3a: + type = "lis3lv02dl_accel"; + break; + case 0x3b: + type = "lis302dl"; + break; + default: + dev_warn(smo8800->dev, "Unknown who-am-i register value 0x%02x\n", + smbus_data.byte); + return -ENODEV; + } + + dev_dbg(smo8800->dev, "Detected %s accelerometer on address 0x%02x\n", type, addr); + strscpy(info->type, "lis3lv02d", I2C_NAME_SIZE); + info->addr = addr; + return 0; +} + static int smo8800_find_i801(struct device *dev, void *data) { struct i2c_adapter *adap, **adap_ret = data; @@ -247,6 +376,7 @@ static void smo8800_instantiate_i2c_client(struct work_struct *work) const struct dmi_system_id *lis3lv02d_dmi_id; struct i2c_board_info info = { }; struct i2c_adapter *adap = NULL; + int err; if (smo8800->i2c_dev) return; @@ -256,11 +386,22 @@ static void smo8800_instantiate_i2c_client(struct work_struct *work) return; lis3lv02d_dmi_id = dmi_first_match(smo8800_lis3lv02d_devices); - if (!lis3lv02d_dmi_id) + if (lis3lv02d_dmi_id) { + info.addr = (long)lis3lv02d_dmi_id->driver_data; + /* Always detect the accel-type, this also checks the accel is actually there */ + err = smo8800_detect_accel(smo8800, adap, info.addr, &info, false); + if (err) + goto out_put_adapter; + } else if (probe_i2c_addr) { + /* First try address 0x29 (most used) and then try 0x1d */ + if (smo8800_detect_accel(smo8800, adap, 0x29, &info, true) != 0 && + smo8800_detect_accel(smo8800, adap, 0x1d, &info, true) != 0) { + dev_warn(smo8800->dev, "failed to probe for lis3lv02d I2C address\n"); + goto out_put_adapter; + } + } else { goto out_put_adapter; - - info.addr = (long)lis3lv02d_dmi_id->driver_data; - strscpy(info.type, "lis3lv02d", I2C_NAME_SIZE); + } smo8800->i2c_dev = i2c_new_client_device(adap, &info); if (IS_ERR(smo8800->i2c_dev)) { @@ -357,7 +498,7 @@ static int smo8800_probe(struct platform_device *device) smo8800->irq); } - if (dmi_check_system(smo8800_lis3lv02d_devices)) { + if (dmi_check_system(smo8800_lis3lv02d_devices) || probe_i2c_addr) { /* * Register i2c-bus notifier + queue initial scan for lis3lv02d * i2c_client instantiation. @@ -370,6 +511,7 @@ static int smo8800_probe(struct platform_device *device) } else { dev_warn(&device->dev, "lis3lv02d accelerometer is present on SMBus but its address is unknown, skipping registration\n"); + dev_info(&device->dev, "Pass dell_smo8800.probe_i2c_addr=1 on the kernel commandline to probe, this may be dangerous!\n"); if (!smo8800->irq) return -ENODEV; }