From patchwork Wed Dec 6 17:52:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Cline X-Patchwork-Id: 10096709 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 1639B60210 for ; Wed, 6 Dec 2017 17:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A4AA28533 for ; Wed, 6 Dec 2017 17:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F30E1288F4; Wed, 6 Dec 2017 17:52:49 +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 E18D428533 for ; Wed, 6 Dec 2017 17:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752071AbdLFRws (ORCPT ); Wed, 6 Dec 2017 12:52:48 -0500 Received: from a8-53.smtp-out.amazonses.com ([54.240.8.53]:46506 "EHLO a8-53.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752182AbdLFRwg (ORCPT ); Wed, 6 Dec 2017 12:52:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=rdybrs3533vx7mghocfwl3vdwgpl2v5u; d=jcline.org; t=1512582755; h=From:To:Cc:Subject:Date:Message-Id; bh=q5r5vj6iY2KLYryoYklPHAhxMpwFjHi0htqaR2cROaE=; b=AbI5/oPterBjHkFWg3ILx7SEZ+lLMtyoE76bULrWSXGXbDkkIxIvgbn9iWZI73rC sfpbS8EoHtHd6NmMDzP6KzIyuSbvHJhBjMtWrM85QdIIv0NU+TEpTraXYY2xR8onAml e0ieE6+oOgnDrCFXEvuy/RwgtdD+kqGY4JJN0gHI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=224i4yxa5dv7c2xz3womw6peuasteono; d=amazonses.com; t=1512582755; h=From:To:Cc:Subject:Date:Message-Id:Feedback-ID; bh=q5r5vj6iY2KLYryoYklPHAhxMpwFjHi0htqaR2cROaE=; b=SJAD13YiVVTqm2swi43hW3TLm6GGNlsQWZ0GaUbHbyqCpIJNgbtV7WZcpb95U88z TikxCrb5Ak/QU8g6hAHklfRUSNusAyDb0CylLmc1jVKubhQ2tKR4Tt5BQvVsfdPQkzO /LR6xnoHzIglPuETuyYWC4SfKO/konBvz/ypwTUs= 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 , Mika Westerberg , Wolfram Sang , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Cline Subject: [PATCH v2] iio: accel: bmc150: Check for a second ACPI device for BOSC0200 Date: Wed, 6 Dec 2017 17:52:34 +0000 Message-ID: <010001602cf53153-39ad69f1-1b39-4e6d-a748-9455a16c2fbd-000000@email.amazonses.com> X-Mailer: git-send-email 2.14.3 X-SES-Outgoing: 2017.12.06-54.240.8.53 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 --- Changes in v2: - Rather than exposing the bmc150_accel_data struct, use get and set functions. drivers/iio/accel/bmc150-accel-core.c | 20 ++++++++++++++++++++ drivers/iio/accel/bmc150-accel-i2c.c | 29 ++++++++++++++++++++++++++++- drivers/iio/accel/bmc150-accel.h | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 870f92ef61c2..7496c5121a8c 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -204,6 +204,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; + struct i2c_client *second_device; }; static const struct { @@ -1659,6 +1660,25 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, } EXPORT_SYMBOL_GPL(bmc150_accel_core_probe); +struct i2c_client *bmc150_get_second_device(struct i2c_client *client) +{ + struct bmc150_accel_data *data = i2c_get_clientdata(client); + + if (!data) + return NULL; + + return data->second_device; +} +EXPORT_SYMBOL_GPL(bmc150_get_second_device); + +void bmc150_set_second_device(struct i2c_client *client) +{ + struct bmc150_accel_data *data = i2c_get_clientdata(client); + if (data) + data->second_device = client; +} +EXPORT_SYMBOL_GPL(bmc150_set_second_device); + int bmc150_accel_core_remove(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c index f85014fbaa12..c7341df086e2 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 i2c_client *second_dev; struct regmap *regmap; const char *name = NULL; bool block_supported = @@ -47,12 +51,35 @@ 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) { + memset(&board_info, 0, sizeof(board_info)); + strlcpy(board_info.type, "bma250e", I2C_NAME_SIZE); + second_dev = i2c_acpi_new_device(&client->dev, 1, &board_info); + if (second_dev) + bmc150_set_second_device(second_dev); + } + + return ret; } static int bmc150_accel_remove(struct i2c_client *client) { + struct i2c_client *second_dev = bmc150_get_second_device(client); + + if (second_dev) + i2c_unregister_device(second_dev); + return bmc150_accel_core_remove(&client->dev); } diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h index ae6118ae11b1..6e965a3ca322 100644 --- a/drivers/iio/accel/bmc150-accel.h +++ b/drivers/iio/accel/bmc150-accel.h @@ -16,6 +16,8 @@ enum { int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, const char *name, bool block_supported); int bmc150_accel_core_remove(struct device *dev); +struct i2c_client *bmc150_get_second_device(struct i2c_client *second_device); +void bmc150_set_second_device(struct i2c_client *second_device); extern const struct dev_pm_ops bmc150_accel_pm_ops; extern const struct regmap_config bmc150_regmap_conf;