From patchwork Mon May 4 12:55:46 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: 194235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 926A6C47259 for ; Mon, 4 May 2020 12:57:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AF4B2075B for ; Mon, 4 May 2020 12:57:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gc5kxk8e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726922AbgEDM5A (ORCPT ); Mon, 4 May 2020 08:57:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36052 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728357AbgEDM4Z (ORCPT ); Mon, 4 May 2020 08:56:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588596984; 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=xgyXcNfc0s1FPSxm2MNo1SSdMk7yteMrkiwIrq6sprw=; b=Gc5kxk8eTUZODfC6qfGCKlWNRr8654ad1E1kSDyja4POHcrTCs9DTGpKiQ2SSe/v7uPpNU ZRxC54Xm5Ppg7q+264i1jdeYSG4RGg2QH+xp0vdrZri70BmTo+Scub3l25ivoYU9TQKovY 6ePNeuyKbmlQmmacHEQYd6qxIq8wR0c= 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-393-bcjkzDsFOGKj9QhqZFCaRw-1; Mon, 04 May 2020 08:56:22 -0400 X-MC-Unique: bcjkzDsFOGKj9QhqZFCaRw-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 691B3100CD0B; Mon, 4 May 2020 12:56:20 +0000 (UTC) Received: from x1.localdomain.com (ovpn-114-224.ams2.redhat.com [10.36.114.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD8035D9D5; Mon, 4 May 2020 12:56:17 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Darren Hart , Andy Shevchenko , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v4 06/11] iio: light: cm32181: Handle CM3218 ACPI devices with 2 I2C resources Date: Mon, 4 May 2020 14:55:46 +0200 Message-Id: <20200504125551.434647-6-hdegoede@redhat.com> In-Reply-To: <20200504125551.434647-1-hdegoede@redhat.com> References: <20200504125551.434647-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Some ACPI systems list 2 I2C resources for the CM3218 sensor. On these systems the first I2cSerialBus ACPI-resource points to the SMBus Alert Response Address (ARA, 0x0c) and the second I2cSerialBus ACPI-resource points to the actual CM3218 sensor address: Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings { Name (SBUF, ResourceTemplate () { I2cSerialBusV2 (0x000C, ControllerInitiated, 0x00061A80, AddressingMode7Bit, "\\_SB.I2C3", 0x00, ResourceConsumer, , Exclusive, ) I2cSerialBusV2 (0x0048, ControllerInitiated, 0x00061A80, AddressingMode7Bit, "\\_SB.I2C3", 0x00, ResourceConsumer, , Exclusive, ) Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive, ,, ) { 0x00000033, } }) Return (SBUF) /* \_SB_.I2C3.ALSD._CRS.SBUF */ } Detect this and take the following step to deal with it: 1. When a SMBus Alert capable sensor has an Alert asserted, it will not respond on its actual I2C address. Read a byte from the ARA to clear any pending Alerts. 2. Create a "dummy" client for the actual I2C address and use that client to communicate with the sensor. Signed-off-by: Hans de Goede --- Changes in v3: - Create and use a dummy client instead of relying on i2c-multi-instantiate to create 2 separate clients for the 2 I2C resources Changes in v2 - s/i2c_client-s/I2C clients/ in added comment --- drivers/iio/light/cm32181.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index f6261798baa3..fd760e209dfa 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -51,6 +51,8 @@ #define CM32181_CALIBSCALE_RESOLUTION 1000 #define MLUX_PER_LUX 1000 +#define SMBUS_ALERT_RESPONSE_ADDRESS 0x0c + static const u8 cm32181_reg[CM32181_CONF_REG_NUM] = { CM32181_REG_ADDR_CMD, }; @@ -351,6 +353,26 @@ static int cm32181_probe(struct i2c_client *client) if (!indio_dev) return -ENOMEM; + /* + * Some ACPI systems list 2 I2C resources for the CM3218 sensor, the + * SMBus Alert Response Address (ARA, 0x0c) and the actual I2C address. + * Detect this and take the following step to deal with it: + * 1. When a SMBus Alert capable sensor has an Alert asserted, it will + * not respond on its actual I2C address. Read a byte from the ARA + * to clear any pending Alerts. + * 2. Create a "dummy" client for the actual I2C address and + * use that client to communicate with the sensor. + */ + if (ACPI_HANDLE(dev) && client->addr == SMBUS_ALERT_RESPONSE_ADDRESS) { + struct i2c_board_info board_info = { .type = "dummy" }; + + i2c_smbus_read_byte(client); + + client = i2c_acpi_new_device(dev, 1, &board_info); + if (IS_ERR(client)) + return PTR_ERR(client); + } + cm32181 = iio_priv(indio_dev); cm32181->client = client;