From patchwork Thu Oct 4 07:50:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Slenska X-Patchwork-Id: 10625681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 450261515 for ; Thu, 4 Oct 2018 07:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F42428C56 for ; Thu, 4 Oct 2018 07:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 236AB28C9E; Thu, 4 Oct 2018 07:51:12 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 11C1328C56 for ; Thu, 4 Oct 2018 07:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727483AbeJDOnH (ORCPT ); Thu, 4 Oct 2018 10:43:07 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:40876 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727319AbeJDOnH (ORCPT ); Thu, 4 Oct 2018 10:43:07 -0400 Received: by mail-lf1-f66.google.com with SMTP id t22-v6so6055285lfb.7 for ; Thu, 04 Oct 2018 00:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=jMC/1VzKgfve0s9IqhagGqBYj9HY/yZHf60xXhOJymQ=; b=sXA1zmSqdwCW3IfJNK+35lJ6Q2gKISPP11Y1J7m0wV6uwwKW6Kpab9zicHM+tVttgQ EYZ5BnGo+u6R/hXOlRd3sL2jrjJQtcm/h3TLk36zHbDUqYLb7jfMbrtJhgmoy+8hBJuO h7a42Xju/0RZLOw9QpPr4Mu4jWQt2/FxxCCJ/h7k64gXEgTTR1POMuUgvhVgiUrI1L6W XGyApd2nBHgaL0wkE+0TCdity89j6EqXQ5a1gqxtCL7u8G2qx7aUppahqfgl2bWq/h9W 45qKfnfH7BPvVhwXRS4LKbNum1v/iHVa5obBF0umU0T9TQGnMQ2yv1zodXNHVT/Nsltj SSTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jMC/1VzKgfve0s9IqhagGqBYj9HY/yZHf60xXhOJymQ=; b=GXcCK+5+gQEPOqIgLeCOAkCrGY0nztuT7C1OHkLmCIvQY4PZusEGIdOf5WoSOEV+67 fpNDFFUNafJNDlq5TDS+fx51YML/+6IRBoO1ozjC//M1TuGDAhCPyo4ef2JQ1yRmM/4/ 0AIXL9/C90RKUGrJBY2QheAFpzZRiSg4w9bH+M2oYICv6Pa7jGilNlysQWQrb52QcVnD itXZ9Vdp2IfH6R5I4ttXY7Gh8MXtkwtmDehSNjcaoT9TJ+NeklE+DJz536xKz+4gk4/M p9Afj5/VR4Lvdhk4Tzh5B6vP3gQQny3SwKzOOYoEJj7ptM59HYwgHkJ2Y/0MBjXkHr1O rwtw== X-Gm-Message-State: ABuFfojD8VGYppHut/K6pkyQ5PXh+uoLvLdBXBZY1W2gR1m7RK1I5CfT IePyYwFK9O1BKBwbzZgEnivoNu2bLwzo0A== X-Google-Smtp-Source: ACcGV60+qyTvPhkF32/L9mnAxXKe/pO7gRdB4RuwsBN8kVPRE5JyShGGXAb3drfTL5Ql5YhJGkmXOg== X-Received: by 2002:a19:5311:: with SMTP id h17-v6mr3005964lfb.24.1538639468360; Thu, 04 Oct 2018 00:51:08 -0700 (PDT) Received: from slew-ThinkPad-P51.fuewroclaw.com (viessmann-01.technologpark.net. [185.75.1.34]) by smtp.gmail.com with ESMTPSA id y1-v6sm842528lfk.89.2018.10.04.00.51.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 00:51:07 -0700 (PDT) From: Wojciech Slenska To: linux-hwmon@vger.kernel.org Cc: Wojciech Slenska Subject: [PATCH] hwmon: (sht3x) add devicetree support Date: Thu, 4 Oct 2018 09:50:51 +0200 Message-Id: <1538639451-28264-1-git-send-email-wojciech.slenska@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Wojciech Slenska --- Documentation/devicetree/bindings/hwmon/sht3x.txt | 16 +++++++++++++ drivers/hwmon/sht3x.c | 28 ++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/sht3x.txt diff --git a/Documentation/devicetree/bindings/hwmon/sht3x.txt b/Documentation/devicetree/bindings/hwmon/sht3x.txt new file mode 100644 index 0000000..80b117e --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/sht3x.txt @@ -0,0 +1,16 @@ +Sensirion SHT3x Humidity and Temperature Sensor + +Required node properties: +- compatible: "sensirion,sht3x" or "sensirion,sts3x" +- reg: I2C bus address of the device + +Optional properties: +- blocking-io: enable blocking mode on i2c +- no-high-precision: disable high accuracy + +Example sht3x node: + +sensor { + compatible = "sensirion,sht3x"; + reg = <0x4a>; +} diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index 370b57d..1f8b7e7 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -31,6 +31,7 @@ #include #include #include +#include /* commands (high precision mode) */ static const unsigned char sht3x_cmd_measure_blocking_hpm[] = { 0x2c, 0x06 }; @@ -699,6 +700,7 @@ static int sht3x_probe(struct i2c_client *client, struct i2c_adapter *adap = client->adapter; struct device *dev = &client->dev; const struct attribute_group **attribute_groups; + struct device_node *np = client->dev.of_node; /* * we require full i2c support since the sht3x uses multi-byte read and @@ -724,8 +726,16 @@ static int sht3x_probe(struct i2c_client *client, data->client = client; crc8_populate_msb(sht3x_crc8_table, SHT3X_CRC8_POLYNOMIAL); - if (client->dev.platform_data) - data->setup = *(struct sht3x_platform_data *)dev->platform_data; + if (np) { + if (of_find_property(np, "blocking-io", NULL)) + data->setup.blocking_io = true; + if (of_find_property(np, "no-high-precision", NULL)) + data->setup.high_precision = false; + } else { + if (client->dev.platform_data) + data->setup = *(struct sht3x_platform_data *) + dev->platform_data; + } sht3x_select_command(data); @@ -768,8 +778,20 @@ static const struct i2c_device_id sht3x_ids[] = { MODULE_DEVICE_TABLE(i2c, sht3x_ids); +#ifdef CONFIG_OF +static const struct of_device_id sht3x_dt_match[] = { + { .compatible = "sensirion,sht3x" }, + { .compatible = "sensirion,sts3x" }, + {} +}; +MODULE_DEVICE_TABLE(of, sht3x_dt_match); +#endif + static struct i2c_driver sht3x_i2c_driver = { - .driver.name = "sht3x", + .driver = { + .name = "sht3x", + .of_match_table = of_match_ptr(sht3x_dt_match), + }, .probe = sht3x_probe, .id_table = sht3x_ids, };