From patchwork Mon Dec 11 03:13:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Potin Lai X-Patchwork-Id: 1874302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YTfPsqE2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SpRzt2mlqz20Gd for ; Mon, 11 Dec 2023 14:28:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YTfPsqE2; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SpRzt1fmdz3vj7 for ; Mon, 11 Dec 2023 14:28:58 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YTfPsqE2; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::22e; helo=mail-oi1-x22e.google.com; envelope-from=potin.lai.pt@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SpRhS3dpGz30QJ for ; Mon, 11 Dec 2023 14:15:35 +1100 (AEDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b86f3cdca0so3065703b6e.3 for ; Sun, 10 Dec 2023 19:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702264530; x=1702869330; darn=lists.ozlabs.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3QsPLbyBhalpeCT8ZCWUjA1czC86N1Fb7t3x26LhWyo=; b=YTfPsqE2kaW9Soz3HWx2GhQENcFp9WSAaKihAbQMBOjE2gx3Mnl5RnrpMASmyiN7oM yeOQNn54KBUNpRvUGZELG+2su9HUiGfQPB8tIgXqRkU+4F1TBpdG805N+FB/+wgNUqiR n+KdhrOkj7Ez/h979v6rDosFMVF1qAnt4mVx80c4utm1EKYlAJBtY0Fpvi+aIuneyvnt 9QirvCAWlnn7IlbaPnsF97Pdg1w/dAjX7gnGxiCOnYnkzo/xPkmUpXi/2MUfSgdczghw 6/88KeqJ1tjwND/GP3i/enf5CSjwN4C2OAKaPAvRLzTKHv9Cg0wmsNq26mh9pIdr9OMO +8cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702264530; x=1702869330; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3QsPLbyBhalpeCT8ZCWUjA1czC86N1Fb7t3x26LhWyo=; b=TN9r96ZffXb8HTS5JioOQuUz6/aCFmuPXzQGDGmIJYF5atmspc8q+s7OYnb7hSxBjS ET5/RTTSs6AqXDJluf4xRcEM1cTJAK8Pm2/ZujOQT42XrrvDXcz6lXvDSJHQIT//GPqq iKGXy1h4hEWXZAuL0ElPfjULYdAsTNWdkXeIuBVQyBlpcymytGIadhDWgWA3EcW0Py/t APSQeChTtJXdzy6R5QOPFq9KpYgz3a3SmT2NruzYxf4LGVAPL/q/nji5w89uVWsR1r2g cuRfMby0FARF0kjdQt/QKVCYznwmpmpdh14p8ZHD3q0w9qY/ewjopiE6DqKJSfIpKYxO bSuQ== X-Gm-Message-State: AOJu0YxUW2xM+yORBdBK63kLzTxF1FwNtBWTSNjI4fJyoUw5h3OKSFWm o257r5qcb/8T9J5x/wGOvHbO353WcB0= X-Google-Smtp-Source: AGHT+IEipgnG44F1Iro4gOmV1Oss10cUM1JNF2anBMsyaSJ0Px8rr4EDysj1M6fpy3Kk8ER3kcA74w== X-Received: by 2002:a05:6808:2225:b0:3b9:d75e:f972 with SMTP id bd37-20020a056808222500b003b9d75ef972mr4965697oib.85.1702264530187; Sun, 10 Dec 2023 19:15:30 -0800 (PST) Received: from localhost.localdomain (1-34-21-66.hinet-ip.hinet.net. [1.34.21.66]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ec8400b001d05456394csm5428080plg.28.2023.12.10.19.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 19:15:29 -0800 (PST) From: Potin Lai To: openbmc@lists.ozlabs.org, joel@jms.id.au Subject: [PATCH linux dev-6.6 1/2] dt-bindings: iio: Add MCP9600 thermocouple EMF converter Date: Mon, 11 Dec 2023 11:13:18 +0800 Message-Id: <20231211031319.3810692-1-potin.lai.pt@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: potin.lai@quantatw.com Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Andrew Hepp Add support for the MCP9600 thermocouple electromotive force converter. The sensor has integrated cold junction compensation and a typical accuracy of 0.5 degrees Celsius. The driver supports a resolution of 0.0625 degrees Celsius. Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/MCP960X-Data-Sheet-20005426.pdf Signed-off-by: Andrew Hepp Reviewed-by: Krzysztof Kozlowski --- .../iio/temperature/microchip,mcp9600.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9600.yaml diff --git a/Documentation/devicetree/bindings/iio/temperature/microchip,mcp9600.yaml b/Documentation/devicetree/bindings/iio/temperature/microchip,mcp9600.yaml new file mode 100644 index 0000000000000..d2cafa38a5442 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/temperature/microchip,mcp9600.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/temperature/microchip,mcp9600.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip MCP9600 thermocouple EMF converter + +maintainers: + - Andrew Hepp + +description: + https://ww1.microchip.com/downloads/en/DeviceDoc/MCP960X-Data-Sheet-20005426.pdf + +properties: + compatible: + const: microchip,mcp9600 + + reg: + maxItems: 1 + + interrupts: + minItems: 1 + maxItems: 6 + + interrupt-names: + minItems: 1 + maxItems: 6 + items: + enum: + - open-circuit + - short-circuit + - alert1 + - alert2 + - alert3 + - alert4 + + thermocouple-type: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Type of thermocouple (THERMOCOUPLE_TYPE_K if omitted). + Use defines in dt-bindings/iio/temperature/thermocouple.h. + Supported types are B, E, J, K, N, R, S, T. + + vdd-supply: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + temperature-sensor@60 { + compatible = "microchip,mcp9600"; + reg = <0x60>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "open-circuit"; + thermocouple-type = ; + vdd-supply = <&vdd>; + }; + }; From patchwork Mon Dec 11 03:13:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Potin Lai X-Patchwork-Id: 1874303 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TKBSOs2+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SpS0s62v3z20Gd for ; Mon, 11 Dec 2023 14:29:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TKBSOs2+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SpS0s4yRbz3vlV for ; Mon, 11 Dec 2023 14:29:49 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TKBSOs2+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::630; helo=mail-pl1-x630.google.com; envelope-from=potin.lai.pt@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SpRhS2sXsz30gM for ; Mon, 11 Dec 2023 14:15:35 +1100 (AEDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d06d42a58aso37347665ad.0 for ; Sun, 10 Dec 2023 19:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702264532; x=1702869332; darn=lists.ozlabs.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QlQbBJUOFRVDiG6vKHEIKVAFU+117kn2UrHR2PnF+30=; b=TKBSOs2+22VAdA2oBu1lLprfn9T/q93rNaKrUffl0YbYrHkx6XaxLMCG3sbf3rvBtg qYqhQ286WkEd4ZzBdU2uyq6BILSrZdSUj+6zcx0K64Yp+VG0bc+5K4hy0BtGLJ7F4IhT sQp6RJEkSOkvSacfWEy4szss2bGyokhwDcQE28SEcF4Nlw7kfcbgZ4WGWdNDyo50Y2kE YX8iWuxV48ZfDX2WSJzy2Zxbj/dTX3XFYHTFLMcdCNrnB1ih6i2tmRVCN8jUkEO2P4wi 3YOm+1rylos29vYuiBnszwxXYKXffh+uYGDMvL86erxY+jaFZt8NeNRhZgQFS9MabqRM +WHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702264532; x=1702869332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QlQbBJUOFRVDiG6vKHEIKVAFU+117kn2UrHR2PnF+30=; b=Dx62RKMl8StfY8vYtu3IX+iCe6EcjmHmzPaWRWDBCcBeRJfupSXVF6tEcgMtu15QF6 bbUaTTU1YGDSU58BuYOkd7UgEJ3RSwLXDdjYzXF0C+KIYM9oxqQbWFLpI/zmP8F8fc3X ZX+IPq+XfeQDaQBdhKy8KKEZLgLh7aHcZE17ARycCnWLP7IOnHjzGsZrgyigciJLI5hq q7vbhar9P56JFtk6XF4127Am+5Orqg3PzLAQKudzuRcfyvpDluTUaGiy2+/2xgYvRzpT 2jI+7QqzZ/VFve+DBpcP/Oe3dpzqZg7PqmZJSaylMaYKLKARTV+j3ugnRiAwlKzl7Yz6 Hvpw== X-Gm-Message-State: AOJu0YyZGQ6bFgQYNWYi0lV64XfnU1gh26499O6x768qTPp0ihxz6LgP Ts4bWCdn1gkkpVTp1ukAZFMdPEcSSIY= X-Google-Smtp-Source: AGHT+IGreadHygqDYbPyw+IGn/duaVhfQjTD4JNkMkmBZAShlSEYbD21zv67GyPap4JbY91Uy+Xjyg== X-Received: by 2002:a17:902:dacf:b0:1d0:3358:4e26 with SMTP id q15-20020a170902dacf00b001d033584e26mr4743359plx.1.1702264531933; Sun, 10 Dec 2023 19:15:31 -0800 (PST) Received: from localhost.localdomain (1-34-21-66.hinet-ip.hinet.net. [1.34.21.66]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ec8400b001d05456394csm5428080plg.28.2023.12.10.19.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 19:15:31 -0800 (PST) From: Potin Lai To: openbmc@lists.ozlabs.org, joel@jms.id.au Subject: [PATCH linux dev-6.6 2/2] iio: temperature: Add MCP9600 thermocouple EMF converter Date: Mon, 11 Dec 2023 11:13:19 +0800 Message-Id: <20231211031319.3810692-2-potin.lai.pt@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231211031319.3810692-1-potin.lai.pt@gmail.com> References: <20231211031319.3810692-1-potin.lai.pt@gmail.com> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: potin.lai@quantatw.com Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" From: Andrew Hepp Add support for the MCP9600 thermocouple electromotive force converter. The sensor has integrated cold junction compensation and a typical accuracy of 0.5 degrees Celsius. The driver supports a resolution of 0.0625 degrees Celsius. Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/MCP960X-Data-Sheet-20005426.pdf Signed-off-by: Andrew Hepp --- drivers/iio/temperature/Kconfig | 10 +++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/mcp9600.c | 139 ++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 drivers/iio/temperature/mcp9600.c diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig index ed384f33e0c76..ea2ce364b2e91 100644 --- a/drivers/iio/temperature/Kconfig +++ b/drivers/iio/temperature/Kconfig @@ -158,4 +158,14 @@ config MAX31865 This driver can also be build as a module. If so, the module will be called max31865. +config MCP9600 + tristate "MCP9600 thermocouple EMF converter" + depends on I2C + help + If you say yes here you get support for MCP9600 + thermocouple EMF converter connected via I2C. + + This driver can also be built as a module. If so, the module + will be called mcp9600. + endmenu diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile index dfec8c6d30193..9330d4a39598d 100644 --- a/drivers/iio/temperature/Makefile +++ b/drivers/iio/temperature/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o obj-$(CONFIG_MAX30208) += max30208.o obj-$(CONFIG_MAX31856) += max31856.o obj-$(CONFIG_MAX31865) += max31865.o +obj-$(CONFIG_MCP9600) += mcp9600.o obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_MLX90632) += mlx90632.o obj-$(CONFIG_TMP006) += tmp006.o diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c new file mode 100644 index 0000000000000..46845804292bf --- /dev/null +++ b/drivers/iio/temperature/mcp9600.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * mcp9600.c - Support for Microchip MCP9600 thermocouple EMF converter + * + * Copyright (c) 2022 Andrew Hepp + * Author: + */ + +#include +#include +#include +#include +#include + +#include + +/* MCP9600 registers */ +#define MCP9600_HOT_JUNCTION 0x0 +#define MCP9600_COLD_JUNCTION 0x2 +#define MCP9600_DEVICE_ID 0x20 + +/* MCP9600 device id value */ +#define MCP9600_DEVICE_ID_MCP9600 0x40 + +static const struct iio_chan_spec mcp9600_channels[] = { + { + .type = IIO_TEMP, + .address = MCP9600_HOT_JUNCTION, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + }, + { + .type = IIO_TEMP, + .address = MCP9600_COLD_JUNCTION, + .channel2 = IIO_MOD_TEMP_AMBIENT, + .modified = 1, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + }, +}; + +struct mcp9600_data { + struct i2c_client *client; +}; + +static int mcp9600_read(struct mcp9600_data *data, + struct iio_chan_spec const *chan, int *val) +{ + int ret; + + ret = i2c_smbus_read_word_swapped(data->client, chan->address); + + if (ret < 0) + return ret; + *val = ret; + + return 0; +} + +static int mcp9600_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct mcp9600_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = mcp9600_read(data, chan, val); + if (ret) + return ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 62; + *val2 = 500000; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static const struct iio_info mcp9600_info = { + .read_raw = mcp9600_read_raw, +}; + +static int mcp9600_probe(struct i2c_client *client) +{ + struct iio_dev *indio_dev; + struct mcp9600_data *data; + int ret; + + ret = i2c_smbus_read_byte_data(client, MCP9600_DEVICE_ID); + if (ret < 0) + return dev_err_probe(&client->dev, ret, "Failed to read device ID\n"); + if (ret != MCP9600_DEVICE_ID_MCP9600) + dev_warn(&client->dev, "Expected ID %x, got %x\n", + MCP9600_DEVICE_ID_MCP9600, ret); + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + data->client = client; + + indio_dev->info = &mcp9600_info; + indio_dev->name = "mcp9600"; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = mcp9600_channels; + indio_dev->num_channels = ARRAY_SIZE(mcp9600_channels); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id mcp9600_id[] = { + { "mcp9600" }, + {} +}; +MODULE_DEVICE_TABLE(i2c, mcp9600_id); + +static const struct of_device_id mcp9600_of_match[] = { + { .compatible = "microchip,mcp9600" }, + {} +}; +MODULE_DEVICE_TABLE(of, mcp9600_of_match); + +static struct i2c_driver mcp9600_driver = { + .driver = { + .name = "mcp9600", + .of_match_table = mcp9600_of_match, + }, + .probe = mcp9600_probe, + .id_table = mcp9600_id +}; +module_i2c_driver(mcp9600_driver); + +MODULE_AUTHOR("Andrew Hepp "); +MODULE_DESCRIPTION("Microchip MCP9600 thermocouple EMF converter driver"); +MODULE_LICENSE("GPL");