From nobody Sun Sep 14 20:31:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1A75C46467 for ; Wed, 18 Jan 2023 17:05:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229499AbjARRFX (ORCPT ); Wed, 18 Jan 2023 12:05:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbjARRFT (ORCPT ); Wed, 18 Jan 2023 12:05:19 -0500 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4063A46D68; Wed, 18 Jan 2023 09:05:15 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (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 smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id E3DC04380B; Wed, 18 Jan 2023 17:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674061513; bh=8C8DkVQ2gQHEAlCG1z28SbrUvr9harQd3HM2fc4Ri0U=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tp8C1A9YqPwvyGlIkzPyTp6A17m/TQBE6HaR7TQMNpFzJp7gOiSyLsrnhOY+YqqJ1 +wf6DkU43RtGg2cD/ksyixp0cL0JwVE76rPFzMCdPYHQxkSyE/meNGuDJXr7rj6lDC 6PcJ/6G3i1wLoX2nbMEgYqgHngOvtW9/AJYTOghwZfc1DjPsw/rEd//WH++2Dcai0+ hB0CT5IqLhoOpLLLk9VnqMH7/OK9xSBI86d7gllXjQdiwll48he3fD2cR8jey0lXSz EUMLzEe7inzqd4APT7mduN78Ss6o7zd/xVZzAmmqbbcoPlVzSpVMuhZOY0NNjN16Jz pVEE55LLJxhuQ== From: Kai-Heng Feng To: ktsai@capellamicro.com, jic23@kernel.org, lars@metafoo.de Cc: hdegoede@redhat.com, Kai-Heng Feng , Wahaj , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] iio: light: cm32181: Fix PM support on system with 2 I2C resources Date: Thu, 19 Jan 2023 01:04:22 +0800 Message-Id: <20230118170422.339619-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit c1e62062ff54 ("iio: light: cm32181: Handle CM3218 ACPI devices with 2 I2C resources") creates a second client for the actual I2C address, but the "struct device" passed to PM ops is the first I2C client that can't talk to the sensor. That means the I2C transfers in both suspend and resume routines can fail and blocking the whole suspend process. Instead of using the first client for I2C transfer, use the I2C client stored in the cm32181 private struct so the PM ops can get the correct I2C client to really talk to the sensor device. Fixes: 68c1b3dd5c48 ("iio: light: cm32181: Add PM support") BugLink: https://bugs.launchpad.net/bugs/1988346 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D2152281 Tested-by: Wahaj Signed-off-by: Kai-Heng Feng Reviewed-by: Hans de Goede --- v2: - Removed setting drvdata to the dummy client. - Added bug links. - Wording. drivers/iio/light/cm32181.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index 001055d097509..b1674a5bfa368 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -440,6 +440,8 @@ static int cm32181_probe(struct i2c_client *client) if (!indio_dev) return -ENOMEM; =20 + i2c_set_clientdata(client, indio_dev); + /* * Some ACPI systems list 2 I2C resources for the CM3218 sensor, the * SMBus Alert Response Address (ARA, 0x0c) and the actual I2C address. @@ -460,8 +462,6 @@ static int cm32181_probe(struct i2c_client *client) return PTR_ERR(client); } =20 - i2c_set_clientdata(client, indio_dev); - cm32181 =3D iio_priv(indio_dev); cm32181->client =3D client; cm32181->dev =3D dev; @@ -490,7 +490,8 @@ static int cm32181_probe(struct i2c_client *client) =20 static int cm32181_suspend(struct device *dev) { - struct i2c_client *client =3D to_i2c_client(dev); + struct cm32181_chip *cm32181 =3D iio_priv(dev_get_drvdata(dev)); + struct i2c_client *client =3D cm32181->client; =20 return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD, CM32181_CMD_ALS_DISABLE); @@ -498,8 +499,8 @@ static int cm32181_suspend(struct device *dev) =20 static int cm32181_resume(struct device *dev) { - struct i2c_client *client =3D to_i2c_client(dev); struct cm32181_chip *cm32181 =3D iio_priv(dev_get_drvdata(dev)); + struct i2c_client *client =3D cm32181->client; =20 return i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD, cm32181->conf_regs[CM32181_REG_ADDR_CMD]); --=20 2.34.1