From patchwork Fri Oct 5 05:38:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Slenska X-Patchwork-Id: 979317 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ObpNCLs6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42RJVV70pyz9s4s for ; Fri, 5 Oct 2018 15:39:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbeJEMgS (ORCPT ); Fri, 5 Oct 2018 08:36:18 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38290 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727127AbeJEMgS (ORCPT ); Fri, 5 Oct 2018 08:36:18 -0400 Received: by mail-lj1-f196.google.com with SMTP id v7-v6so10024285ljg.5; Thu, 04 Oct 2018 22:38:41 -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=CQVOQPp5xIDJQuuoASVOve//cv1MzsK5iaXRQnVjZ0o=; b=ObpNCLs6On25Oat51XoudGhhH5CYLM408Hu+jbp/wqcxELvjuFsMrAAOme/1zxDDaY X7Z1jMAp9OFK6CaofsBrFvhjuTSsi/4LR9t8NYhREB5xtKsiLgmce7HdhQhzVlXHX1ey yk0l2vJg0H94qrx/O19e0omN019WCGXNldd6ZdYhtEnSLe4aCdRQfj14axyjO0yrTVxq Gj5/tJM6rer9kh1UiJ37bBLfIF2r5rPJiyGSH9rUTdCaEYBprmAU3wKyhYARt8pc/wbG qydi3/LT6e0a7Jeb+8E1L1J+gwqdCD3eRzKTGKltpbERBzR60hZODiwUaCN38dQZ/eiZ 0fng== 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=CQVOQPp5xIDJQuuoASVOve//cv1MzsK5iaXRQnVjZ0o=; b=bT1e7GA5uQUEGBaW18tWt7hpyvc3uO+oH9RW1sjH8m3dpvNP6HJxfqum5aOZYhVunl 5LhcLN0RYDFOYmNP8no834ixUYoM0hUb1vrKH1gMq9+J0Dl61hSsq5WHMMW2bw1Y2zjz auPEBa/bbMYRED5CUsXcrXRJW0bgrBZFgf7Us6Zk1XnyLWT6pRQygDPE0Y2x5ZdTEW+7 cgVISD62Mz0L0SEfmbleHv6fsvNf8sI4YvgZ5Km1bbOFhIMnSrkEyZVNIQFq4d2fkYCi SSeJFtxSaYCPB9a3tiEKkux3Qa/tssAOf9jy5EmP15vp83PIKTMWTOrOe6d8AusnLb3W Y5TQ== X-Gm-Message-State: ABuFfojGkfhuTSToIp5W9WC+RP+23wdVX/RVTt+MiEM8/m683wVvgYLq f/M/kNvvFICrrrH8ZusD3/g= X-Google-Smtp-Source: ACcGV60V2rESNYRNwiPBdkC2S5d/sxpoNlMPPJxp0JVHi6OTbaBcy6Jw3hUKInKatAOv6bF3AoptBg== X-Received: by 2002:a2e:908b:: with SMTP id l11-v6mr6032808ljg.25.1538717920920; Thu, 04 Oct 2018 22:38:40 -0700 (PDT) Received: from slew-ThinkPad-P51.fuewroclaw.com (viessmann-01.technologpark.net. [185.75.1.34]) by smtp.gmail.com with ESMTPSA id z142-v6sm1502558lff.82.2018.10.04.22.38.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 22:38:40 -0700 (PDT) From: Wojciech Slenska To: linux@roeck-us.net Cc: jdelvare@suse.com, robh+dt@kernel.org, mark.rutland@arm.com, linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, Wojciech Slenska Subject: [PATCH v2] hwmon: (sht3x) add devicetree support Date: Fri, 5 Oct 2018 07:38:35 +0200 Message-Id: <1538717915-22294-1-git-send-email-wojciech.slenska@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 -- 2.7.4 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: +- sensirion,blocking-io: enable blocking mode on i2c +- sensirion,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_property_read_bool(np, "sensirion,blocking-io")) + data->setup.blocking_io = true; + if (of_property_read_bool(np, "sensirion,no-high-precision")) + 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, };