From patchwork Tue Nov 19 15:50:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 3203071 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 497B1C045B for ; Tue, 19 Nov 2013 15:57:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F8BB20265 for ; Tue, 19 Nov 2013 15:57:57 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD81F2022F for ; Tue, 19 Nov 2013 15:57:55 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VinfC-0005nt-FQ; Tue, 19 Nov 2013 15:56:31 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vines-0002nA-Dr; Tue, 19 Nov 2013 15:56:10 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VineF-0002iw-CR for linux-arm-kernel@lists.infradead.org; Tue, 19 Nov 2013 15:55:34 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 61D5F846; Tue, 19 Nov 2013 16:55:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id BB8F4804; Tue, 19 Nov 2013 16:55:03 +0100 (CET) From: Maxime Ripard To: Shawn Guo , Jonathan Cameron Subject: [RFC PATCH 1/3] iio: accel: Add device tree probing for STMicro accelerometers Date: Tue, 19 Nov 2013 16:50:31 +0100 Message-Id: <1384876234-1211-2-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1384876234-1211-1-git-send-email-maxime.ripard@free-electrons.com> References: <1384876234-1211-1-git-send-email-maxime.ripard@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131119_105531_841113_532E52ED X-CRM114-Status: GOOD ( 16.12 ) X-Spam-Score: -1.8 (-) Cc: Brian Lilly , linux-iio@vger.kernel.org, Brent-Crosby , Jim Wall , Alexandre Belloni , Denis Ciocca , Maxime Ripard , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add the compatibles supported by the st_sensors library. This uses kind of a hack, since the st_sensors core will actively check at probe time that the device name matches the one reported when using old style i2c probing, and that this name will be different with device tree. Signed-off-by: Maxime Ripard --- .../devicetree/bindings/iio/accel/st_accel_i2c.txt | 22 +++++++++++++++ drivers/iio/accel/st_accel_i2c.c | 33 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/st_accel_i2c.txt diff --git a/Documentation/devicetree/bindings/iio/accel/st_accel_i2c.txt b/Documentation/devicetree/bindings/iio/accel/st_accel_i2c.txt new file mode 100644 index 000000000000..4a1efdf1775f --- /dev/null +++ b/Documentation/devicetree/bindings/iio/accel/st_accel_i2c.txt @@ -0,0 +1,22 @@ +* ST Micro accelerometer sensors + +Required properties: + - compatible : should be either: + * "st,lis3dh" + * "st,lis331dlh" + * "st,lsm303dl-accel" + * "st,lsm303dlh-accel" + * "st,lsm303dlhc-accel" + * "st,lsm303dlm-accel" + * "st,lsm330-accel" + * "st,lsm330d-accel" + * "st,lsm330dl-accel" + * "st,lsm330dlc-accel" + - reg : the I2C address of the sensor + +Example: + +accel: accel@19 { + compatible = "st,lsm330dlc-accel"; + reg = <0x19>; +}; diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index d7bedbdfc81d..de2bf76378d8 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -13,11 +13,27 @@ #include #include #include +#include #include #include #include "st_accel.h" +static const struct of_device_id st_accel_of_table[] = { + { .compatible = "st,lis3dh", .data = LIS3DH_ACCEL_DEV_NAME }, + { .compatible = "st,lis331dlh", .data = LIS331DLH_ACCEL_DEV_NAME }, + { .compatible = "st,lsm303dl-accel", .data = LSM303DL_ACCEL_DEV_NAME }, + { .compatible = "st,lsm303dlh-accel", .data = LSM303DLH_ACCEL_DEV_NAME }, + { .compatible = "st,lsm303dlhc-accel", .data = LSM303DLHC_ACCEL_DEV_NAME }, + { .compatible = "st,lsm303dlm-accel", .data = LSM303DLM_ACCEL_DEV_NAME }, + { .compatible = "st,lsm330-accel", .data = LSM330_ACCEL_DEV_NAME }, + { .compatible = "st,lsm330d-accel", .data = LSM330D_ACCEL_DEV_NAME }, + { .compatible = "st,lsm330dl-accel", .data = LSM330DL_ACCEL_DEV_NAME }, + { .compatible = "st,lsm330dlc-accel", .data = LSM330DLC_ACCEL_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(of, st_accel_of_table); + static int st_accel_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -34,6 +50,22 @@ static int st_accel_i2c_probe(struct i2c_client *client, st_sensors_i2c_configure(indio_dev, client, adata); + /* + * If we are probed through DT, st_sensors_i2c_configure will + * fill the indio_dev->name string with the client->name, + * which is the compatible without the vendor prefix. Since + * compatibles separators are usually "-", and that the + * convention in this driver is using "_", we obviously have a + * problem when the st-sensors core checks that the two + * strings matches. We need to set again the indio_dev->name + * string to the real value used by the core later on. + */ + if (client->dev.of_node) { + const struct of_device_id *device; + device = of_match_device(st_accel_of_table, &client->dev); + indio_dev->name = device->data; + } + err = st_accel_common_probe(indio_dev, client->dev.platform_data); if (err < 0) return err; @@ -67,6 +99,7 @@ static struct i2c_driver st_accel_driver = { .driver = { .owner = THIS_MODULE, .name = "st-accel-i2c", + .of_match_table = of_match_ptr(st_accel_of_table), }, .probe = st_accel_i2c_probe, .remove = st_accel_i2c_remove,