From patchwork Wed Nov 29 22:31:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Cline X-Patchwork-Id: 10083759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCA5A60234 for ; Wed, 29 Nov 2017 22:32:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE41E29CD4 for ; Wed, 29 Nov 2017 22:32:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B316129CD6; Wed, 29 Nov 2017 22:32:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42DCD29CD4 for ; Wed, 29 Nov 2017 22:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752534AbdK2WbO (ORCPT ); Wed, 29 Nov 2017 17:31:14 -0500 Received: from a8-242.smtp-out.amazonses.com ([54.240.8.242]:41640 "EHLO a8-242.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752218AbdK2WbN (ORCPT ); Wed, 29 Nov 2017 17:31:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=rdybrs3533vx7mghocfwl3vdwgpl2v5u; d=jcline.org; t=1511994672; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; bh=Sk2Ri5BbZnMrpZmUqDDZiPAHtLjVsB+X2zBLs+nOKEU=; b=LXC1SxnavGMQ+58YLqUFVAZyqg6gm/l3FTyvEI9g9ZpbqfaY6pqseS1fWdrQlNJc AqteZ9ou1V6KTJMsOOpqUWi7kkES+Fof6dVWHdOdsPmF5E3oc7WzRZumk9NA5BrAHqc IhdvXJshANTdUP5D7KgqUPCe0BEO3EmBXbz9ik8w= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=224i4yxa5dv7c2xz3womw6peuasteono; d=amazonses.com; t=1511994672; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Feedback-ID; bh=Sk2Ri5BbZnMrpZmUqDDZiPAHtLjVsB+X2zBLs+nOKEU=; b=l+F5AKhANE6DNaJmdxRgwxsHIdhExzVe6n0p+Lht449mVQ+qAJDI/8k75pxOBdcL ZGDMEeLoIuKY94/taGPC8OZiOLeayeD9ZWHqw1g533/Wo5GEgFJG03lPdaqlBt4GwEC mY/rZaodndfd3tXXPRYE3w8kWurr7hBL2me7051Q= X-Virus-Scanned: amavisd-new at jcline.org From: Jeremy Cline To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: Hans de Goede , Lars Kellogg-Stedman , Steven Presser , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Cline Subject: [PATCH 2/2] iio: accel: bmc150: Check for a second ACPI device for BOSC0200 Date: Wed, 29 Nov 2017 22:31:12 +0000 Message-ID: <0100016009e7c30a-407c2980-d8d5-4506-ab47-d0fb2fed481d-000000@email.amazonses.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171129223016.17848-1-jeremy@jcline.org> References: <20171129223016.17848-1-jeremy@jcline.org> X-SES-Outgoing: 2017.11.29-54.240.8.242 Feedback-ID: 1.us-east-1.z18Isoc/FaoPOvCyJyi1mnTt8STwoRuibXVNoUcvG6g=:AmazonSES Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some BOSC0200 acpi_device-s describe two accelerometers in a single ACPI device. Check for a companion device and handle a second i2c_client if it is present. Signed-off-by: Jeremy Cline --- drivers/iio/accel/bmc150-accel-i2c.c | 33 ++++++++++++++++++++++++++++++++- drivers/iio/accel/bmc150-accel.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c index f85014fbaa12..c4557e18123c 100644 --- a/drivers/iio/accel/bmc150-accel-i2c.c +++ b/drivers/iio/accel/bmc150-accel-i2c.c @@ -31,6 +31,10 @@ static int bmc150_accel_probe(struct i2c_client *client, const struct i2c_device_id *id) { + int ret; + struct acpi_device *adev; + struct i2c_board_info board_info; + struct bmc150_accel_data *data; struct regmap *regmap; const char *name = NULL; bool block_supported = @@ -47,12 +51,39 @@ static int bmc150_accel_probe(struct i2c_client *client, if (id) name = id->name; - return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, + ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported); + if (ret) + return ret; + + /* + * Some BOSC0200 acpi_devices describe 2 accelerometers in a single ACPI + * device, try instantiating a second i2c_client for an I2cSerialBusV2 + * ACPI resource with index 1. + */ + adev = ACPI_COMPANION(&client->dev); + if (adev && strcmp(acpi_device_hid(adev), "BOSC0200") == 0) { + data = i2c_get_clientdata(client); + memset(&board_info, 0, sizeof(board_info)); + strlcpy(board_info.type, "bma250e", I2C_NAME_SIZE); + data->driver_priv = i2c_acpi_new_device(&client->dev, + 1, &board_info); + /* + * Don't check for bosc0200 == NULL since most BOSC0200 ACPI + * devices describe only one i2c_client + */ + } + + return ret; } static int bmc150_accel_remove(struct i2c_client *client) { + struct bmc150_accel_data *data = i2c_get_clientdata(client); + + if (data->driver_priv) + i2c_unregister_device(data->driver_priv); + return bmc150_accel_core_remove(&client->dev); } diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h index c38754452883..7f49a09b136f 100644 --- a/drivers/iio/accel/bmc150-accel.h +++ b/drivers/iio/accel/bmc150-accel.h @@ -47,6 +47,7 @@ struct bmc150_accel_data { int ev_enable_state; int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ const struct bmc150_accel_chip_info *chip_info; + void *driver_priv; }; struct regmap;