From patchwork Sat Mar 20 06:45:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 12152385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F108C433E0 for ; Sat, 20 Mar 2021 11:13:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A635619A3 for ; Sat, 20 Mar 2021 11:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbhCTLMg (ORCPT ); Sat, 20 Mar 2021 07:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbhCTLMM (ORCPT ); Sat, 20 Mar 2021 07:12:12 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE7CAC05BD0C; Sat, 20 Mar 2021 04:08:20 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id h3so7673352pfr.12; Sat, 20 Mar 2021 04:08:20 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=RArRJ3KrSsXGgvSpLUXkus1FiNSIwSvWr9imzk+34J0=; b=g9rgCau1/GByYgq8pbu+ZdIh71m8PpEtTTukzGGHDFDGrpJcT2K+Bgp7rbyNO+8krv CoGQp+/R0eJqbE4AcOjO60NaeuLJQHlwllseZEpzd9efETAyGJeU0SEv065FnHOOIdOM lNnpJSLRW1Xzf+T7w++zsLTJQClMd475EqkE9zn/c5jKkXvA9tPRwGfPSFH9TPBIlOSn gAwZuX/Qiy7J2J8GfKLhWT/8WwFm2uB+4sOKPHKUtxZjeXn6f+I0smlJ2l4PZ/K2togx tB/UPQa8b0mZW5zk6fU75wiCRu6jcWF5i+3JmAaF9LOE+HI71SzesQFwvkDC8m9s9pY/ tnVw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=RArRJ3KrSsXGgvSpLUXkus1FiNSIwSvWr9imzk+34J0=; b=ah0XBJmIwiVAWqgICisruOjojzCuNRr0Bkl6GLsnMNMw3bg+fa6rle26c6iFKtsqnn a8DmrfkD8C1Y75UcbsX5VbWDeKVVUOhSvJATfG6hHf7HLxZtcLZxBIjYPlXU4P/5x5zF 7d8ozUjZNdmh2W1WLYd+QkWPsjwdg+/gylSLf09oFBa5L3rbsN1OVUsND7WtzVWUUlZ5 fZmQKo5Py5AaS77HAVQIeJoCGqwafuzYULzDHiEFdyEOT+SJooKmkGA++o2N1bDvQkOw x2Nfm1h1cn5cTfpdl3ge7MNBtfzUFNWSPiPQxXyfidW4svMlHbSnu6KdhGKZcnbIvioV 2Msg== X-Gm-Message-State: AOAM5309OSFYwB+6YkJUVovWdG+0MAwpSrmeeyoTEZTxDZ0kuTNosTae eFmhYw1TU/n3C+WpAGJANJ9lT1pSz474qg== X-Google-Smtp-Source: ABdhPJxVDcDYwMB0V+DxrfuLI/XmV/AMorIYQDcFsNkaMRkHpMwNKLZRP6guh5EpuHAQpPyyzv8bkw== X-Received: by 2002:a63:4504:: with SMTP id s4mr14547017pga.184.1616222722079; Fri, 19 Mar 2021 23:45:22 -0700 (PDT) Received: from localhost.localdomain ([27.255.177.158]) by smtp.googlemail.com with ESMTPSA id f15sm7237887pgr.90.2021.03.19.23.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 23:45:21 -0700 (PDT) From: Puranjay Mohan To: alexandru.ardelean@analog.com, jic23@kernel.org, devicetree@vger.kernel.org, knaack.h@gmx.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Puranjay Mohan Subject: [PATCH v1 1/2] dt-bindings: iio: temperature: Add DT bindings for TMP117 Date: Sat, 20 Mar 2021 12:15:08 +0530 Message-Id: <20210320064509.119878-2-puranjay12@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210320064509.119878-1-puranjay12@gmail.com> References: <20210320064509.119878-1-puranjay12@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add devicetree binding document for TMP117, a digital temperature sensor. Signed-off-by: Puranjay Mohan --- .../bindings/iio/temperature/ti,tmp117.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml diff --git a/Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml b/Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file mode 100644 index 000000000..927660461 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/iio/temperature/ti,tmp117.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" +description: | + TI TMP117 - Digital temperature sensor with integrated NV memory that supports + I2C interface. + https://www.ti.com/lit/gpn/tmp1 +examples: | + tmp117@48 { + compatible = "ti,tmp117"; + reg = <0x48>; + }; +maintainers: + - "Puranjay Mohan " +properties: + compatible: + enum: + - "ti,tmp117" + reg: + maxItems: 1 +required: + - compatible + - reg +title: "TI TMP117 - Digital temperature sensor with integrated NV memory" + From patchwork Sat Mar 20 06:45:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 12152387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 880CCC43445 for ; Sat, 20 Mar 2021 11:13:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A6FE61946 for ; Sat, 20 Mar 2021 11:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbhCTLMi (ORCPT ); Sat, 20 Mar 2021 07:12:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhCTLM0 (ORCPT ); Sat, 20 Mar 2021 07:12:26 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BBAC05BD11; Sat, 20 Mar 2021 04:11:28 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id x26so7674932pfn.0; Sat, 20 Mar 2021 04:11:28 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bzk3gv3neOHFmq66OkXdKmbZpftj7BOZ5l77TBbGY94=; b=rhUTZS8YqCUXMYjfPPXrM1TnN7x3rop1/Wl8sCSZ9mKxlmKGTwBm4Y8j7etds+P9XT 2kpYPhBWkiRxh2xi6FIoHa3H8SxYPIAl1oJIyzvW7MKLOWp1RrLio3hqJq632NSCNOxC zFwXsKiWAHyB6plRHs4KMl8xAS9Zl3YRVoguKNMVB0N5heLS0Mkr/HkCGzszJ7SOomc+ vYtez6uJSmeyBPiyh0rSDsFP0mtfzsXW1P3thWTKDNoZjDrEqkdzAKw2EbMCriUZ40kc YFpHP7VWgrbshBjzdc2YNd69mVC606PExIXbS7FCXBLpbysU1LyY57adSttoGg9IpXsW P3Aw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bzk3gv3neOHFmq66OkXdKmbZpftj7BOZ5l77TBbGY94=; b=rdNC/SZz3hy1XIgt0qrGF1WKppt8NqTZ1POWsseHqzYa11LNeoe6HOgfXrmb0XY2vw joYTwhiIVeiCDg1RN+03zR/VV544zvwi88flVT3PlE7DBMGU2ZOlOuMqwMjyfLuR1Rwa 8UKJxG8k9FsyYlPcdSfLRJTEWjmGX1486qfn8fh0J4oJITM0VscAchMNaLZgvsRdts2y 3s3UN5iaIN8TrCS9I+TdC0wdyldbIHO1MMl1uqDGTmF/ost+A5d05FK/Lu/NYTRVn/KV 4m7cIjdQBAvK42HPBwARGPctpeG9Cs+KtjsDR2mMlKZl2/Bf7+AJHv7lFWZSZNKkdW8m NNxQ== X-Gm-Message-State: AOAM5306BSXzKbRAQEF2y5iME5WAAgCjvAc2Nd6fzD/czLsMtAPu5hz1 QwfGRkgomhtynNlZURAUws7tmKTHDVxCzw== X-Google-Smtp-Source: ABdhPJwD/pukcp33GPw+UUEfS1fHczAzJFx4vEaIACljNQo0OSvd1kKYTy7dfcF4ePCrFToGLax3aQ== X-Received: by 2002:a62:5b43:0:b029:1ef:21ad:846 with SMTP id p64-20020a625b430000b02901ef21ad0846mr12690031pfb.51.1616222725402; Fri, 19 Mar 2021 23:45:25 -0700 (PDT) Received: from localhost.localdomain ([27.255.177.158]) by smtp.googlemail.com with ESMTPSA id f15sm7237887pgr.90.2021.03.19.23.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 23:45:24 -0700 (PDT) From: Puranjay Mohan To: alexandru.ardelean@analog.com, jic23@kernel.org, devicetree@vger.kernel.org, knaack.h@gmx.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Puranjay Mohan Subject: [PATCH v1 2/2] iio: temperature: add driver support for ti tmp117 Date: Sat, 20 Mar 2021 12:15:09 +0530 Message-Id: <20210320064509.119878-3-puranjay12@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210320064509.119878-1-puranjay12@gmail.com> References: <20210320064509.119878-1-puranjay12@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org TMP117 is a Digital temperature sensor with integrated NV memory. Add support for tmp117 driver in iio subsystem. Datasheet:-https://www.ti.com/lit/gpn/tmp117 Signed-off-by: Puranjay Mohan --- drivers/iio/temperature/Kconfig | 10 ++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 182 +++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 drivers/iio/temperature/tmp117.c diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig index f1f2a1499..c5482983f 100644 --- a/drivers/iio/temperature/Kconfig +++ b/drivers/iio/temperature/Kconfig @@ -97,6 +97,16 @@ config TMP007 This driver can also be built as a module. If so, the module will be called tmp007. +config TMP117 + tristate "TMP117 Digital temperature sensor with integrated NV memory" + depends on I2C + help + If you say yes here you get support for the Texas Instruments + TMP117 Digital temperature sensor with integrated NV memory. + + This driver can also be built as a module. If so, the module will + be called tmp117. + config TSYS01 tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection" depends on I2C diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile index 90c113115..e3392c4b2 100644 --- a/drivers/iio/temperature/Makefile +++ b/drivers/iio/temperature/Makefile @@ -12,5 +12,6 @@ obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_MLX90632) += mlx90632.o obj-$(CONFIG_TMP006) += tmp006.o obj-$(CONFIG_TMP007) += tmp007.o +obj-$(CONFIG_TMP117) += tmp117.o obj-$(CONFIG_TSYS01) += tsys01.o obj-$(CONFIG_TSYS02D) += tsys02d.o diff --git a/drivers/iio/temperature/tmp117.c b/drivers/iio/temperature/tmp117.c new file mode 100644 index 000000000..194820700 --- /dev/null +++ b/drivers/iio/temperature/tmp117.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * tmp117.c - Digital temperature sensor with integrated NV memory + * + * Copyright (c) 2021 Puranjay Mohan + * + * Driver for the Texas Instruments TMP117 Temperature Sensor + * + * (7-bit I2C slave address (0x48 - 0x4B), changeable via ADD pins) + * + * Note: This driver assumes that the sensor has been calibrated beforehand. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define TMP117_REG_TEMP 0x0 +#define TMP117_REG_CFGR 0x1 +#define TMP117_REG_HIGH_LIM 0x2 +#define TMP117_REG_LOW_LIM 0x3 +#define TMP117_REG_EEPROM_UL 0x4 +#define TMP117_REG_EEPROM1 0x5 +#define TMP117_REG_EEPROM2 0x6 +#define TMP117_REG_TEMP_OFFSET 0x7 +#define TMP117_REG_EEPROM3 0x8 +#define TMP117_REG_DEVICE_ID 0xF + +#define TMP117_SCALE 7812500 /* in uCelsius*/ +#define TMP117_RESOLUTION 78125 +#define TMP117_DEVICE_ID 0x0117 + +struct tmp117_data { + struct i2c_client *client; + struct mutex lock; +}; + +static int tmp117_read_reg(struct tmp117_data *data, u8 reg) +{ + return i2c_smbus_read_word_swapped(data->client, reg); +} + +static int tmp117_write_reg(struct tmp117_data *data, u8 reg, int val) +{ + return i2c_smbus_write_word_swapped(data->client, reg, val); +} + +static int tmp117_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + struct tmp117_data *data = iio_priv(indio_dev); + u16 tmp, off; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + tmp = tmp117_read_reg(data, TMP117_REG_TEMP); + *val = tmp; + return IIO_VAL_INT; + + case IIO_CHAN_INFO_CALIBBIAS: + off = tmp117_read_reg(data, TMP117_REG_TEMP_OFFSET); + *val = ((int16_t)off * (int32_t)TMP117_RESOLUTION) / 10000000; + *val2 = ((int16_t)off * (int32_t)TMP117_RESOLUTION) % 10000000; + return IIO_VAL_INT_PLUS_MICRO; + + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = TMP117_SCALE; + return IIO_VAL_INT_PLUS_NANO; + + default: + return -EINVAL; + } +} + +static int tmp117_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int val, + int val2, long mask) +{ + struct tmp117_data *data = iio_priv(indio_dev); + u16 off; + + switch (mask) { + case IIO_CHAN_INFO_CALIBBIAS: + off = ((val * 10000000) + (val2 * 10)) + / (int32_t)TMP117_RESOLUTION; + return tmp117_write_reg(data, TMP117_REG_TEMP_OFFSET, off); + + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec tmp117_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_SCALE), + }, +}; + +static const struct iio_info tmp117_info = { + .read_raw = tmp117_read_raw, + .write_raw = tmp117_write_raw, +}; + +static bool tmp117_identify(struct i2c_client *client) +{ + int dev_id; + + dev_id = i2c_smbus_read_word_swapped(client, TMP117_REG_DEVICE_ID); + if (dev_id < 0) + return false; + + return (dev_id == TMP117_DEVICE_ID); +} + +static int tmp117_probe(struct i2c_client *client, + const struct i2c_device_id *tmp117_id) +{ + struct tmp117_data *data; + struct iio_dev *indio_dev; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) + return -EOPNOTSUPP; + + if (!tmp117_identify(client)) { + dev_err(&client->dev, "TMP117 not found\n"); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + data->client = client; + mutex_init(&data->lock); + + indio_dev->name = "tmp117"; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &tmp117_info; + + indio_dev->channels = tmp117_channels; + indio_dev->num_channels = ARRAY_SIZE(tmp117_channels); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct of_device_id tmp117_of_match[] = { + { .compatible = "ti,tmp117", }, + { }, +}; +MODULE_DEVICE_TABLE(of, tmp117_of_match); + +static const struct i2c_device_id tmp117_id[] = { + { "tmp117", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, tmp117_id); + +static struct i2c_driver tmp117_driver = { + .driver = { + .name = "tmp117", + .of_match_table = of_match_ptr(tmp117_of_match), + }, + .probe = tmp117_probe, + .id_table = tmp117_id, +}; +module_i2c_driver(tmp117_driver); + +MODULE_AUTHOR("Puranjay Mohan "); +MODULE_DESCRIPTION("TI TMP117 Temperature sensor driver"); +MODULE_LICENSE("GPL");