From patchwork Wed May 10 10:22:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 680690 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE73DC77B7D for ; Wed, 10 May 2023 10:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236581AbjEJKX3 (ORCPT ); Wed, 10 May 2023 06:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236573AbjEJKX2 (ORCPT ); Wed, 10 May 2023 06:23:28 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02F9D30CA; Wed, 10 May 2023 03:23:25 -0700 (PDT) Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 8B4D9846B6; Wed, 10 May 2023 12:23:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1683714204; bh=l3nzFfntxHF9pjhdFKzLn4pB7Uc09xfOJyBZjOmwiPM=; h=From:To:Cc:Subject:Date:From; b=GrsJ99EH8/USS/x16SPqIqcI2+8C4svPqGRy/nujr0dStlN5oPB6ugU4QyWZR/9+s UHO8th+l4kn/ggQN8xeHEI93bQ18s2L49EmX18TnrwDLAbkMY2lX2114swfo5Rpvck Y4yCTGB93g2dvFeV/5x2/1T58Nefq9S7AgSZgwqoHT78qqNHLqfNVkogVe4eHjNac/ 8OZPDVujhO9ssRCXN6CBGUwMNj2XN9j8giMjKl+Z0pjVVTaKYZLaPdiOkfoJ6CEi2Y 7nbTQkTzgjN6UqXVz4AYHeZW7SeVSxPsBOGC9mTW1OWzyHc1UYMH9yIXJnE1ZQi/io 1dI1gLWauD/QQ== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Crt Mori , Krzysztof Kozlowski , Jonathan Cameron , Krzysztof Kozlowski , Lars-Peter Clausen , Peter Meerwald , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v3 1/6] dt-bindings: iio: temperature: melexis,mlx90614: Document MLX90615 support Date: Wed, 10 May 2023 12:22:46 +0200 Message-Id: <20230510102251.10118-1-marex@denx.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Document support for MLX90615 Infra Red Thermometer, which seems to be the predecesor of MLX90614 . There are significant differences in the register layout compared to MLX90614, but the functionality of the device is virtually identical. Acked-by: Crt Mori Acked-by: Krzysztof Kozlowski Signed-off-by: Marek Vasut --- Cc: Crt Mori Cc: Jonathan Cameron Cc: Krzysztof Kozlowski Cc: Lars-Peter Clausen Cc: Marek Vasut Cc: Peter Meerwald Cc: Rob Herring Cc: devicetree@vger.kernel.org Cc: linux-iio@vger.kernel.org --- V2: - Add spaces to subject tags - Add AB from Krzysztof V3: Add AB from Crt --- .../bindings/iio/temperature/melexis,mlx90614.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90614.yaml b/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90614.yaml index d6965a0c1cf30..654d31f65d360 100644 --- a/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90614.yaml +++ b/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90614.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/iio/temperature/melexis,mlx90614.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Melexis MLX90614 contactless IR temperature sensor +title: Melexis MLX90614/MLX90615 contactless IR temperature sensor maintainers: - Peter Meerwald @@ -15,7 +15,9 @@ description: | properties: compatible: - const: melexis,mlx90614 + enum: + - melexis,mlx90614 + - melexis,mlx90615 reg: maxItems: 1 From patchwork Wed May 10 10:22:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 680689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EA7AC7EE2E for ; Wed, 10 May 2023 10:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236594AbjEJKXb (ORCPT ); Wed, 10 May 2023 06:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235317AbjEJKX3 (ORCPT ); Wed, 10 May 2023 06:23:29 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D584F44BA; Wed, 10 May 2023 03:23:26 -0700 (PDT) Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 236B986008; Wed, 10 May 2023 12:23:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1683714205; bh=/WvgxSTBQJIYwkct9ItX5iqLZqd8FdduZoy1sgKWOlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBmoUEQxacmg42e5UCufNA0Jcvur1NqUnfjmlawKTp+o9RZz4iaultGrvURPJue0K GTrQDD80m8cJZdpx02n0j7Lrj+n+DZGcQ/xR2OdlZMQgQeq9NtQypTZbqjgLt96U3I qDLsPHsayZ/mpmAo02yVt4OUJHxNu8jrXdJnWPS38Vy2HFX7EOR4t4mx1h1sCTjqHs tK0On+TcqernudAOvszzYa5/5ApFRFGmtjWmzUqgOwKiabxNfay61dglmq9SY1kKmy y2b9o2RfPvOZZumc8knfkPWqXSQ9qhXHmFMz7XtkOzTdED7ovNS5zDasXpDItCb+mc Jx3KlVwttz2LQ== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Crt Mori , Jonathan Cameron , Krzysztof Kozlowski , Lars-Peter Clausen , Peter Meerwald , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v3 4/6] iio: mlx90614: Drop MLX90614_CONST_EMISSIVITY_RESOLUTION Date: Wed, 10 May 2023 12:22:49 +0200 Message-Id: <20230510102251.10118-4-marex@denx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230510102251.10118-1-marex@denx.de> References: <20230510102251.10118-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The MLX90614_CONST_EMISSIVITY_RESOLUTION can be calculated from MLX90614_CONST_RAW_EMISSIVITY_MAX, perform the calculation inline and drio the MLX90614_CONST_EMISSIVITY_RESOLUTION. Signed-off-by: Marek Vasut Acked-by: Crt Mori --- Cc: Crt Mori Cc: Jonathan Cameron Cc: Krzysztof Kozlowski Cc: Lars-Peter Clausen Cc: Marek Vasut Cc: Peter Meerwald Cc: Rob Herring Cc: devicetree@vger.kernel.org Cc: linux-iio@vger.kernel.org --- V3: New patch --- drivers/iio/temperature/mlx90614.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c index b0f69a7b05abc..ecd27fe0c8666 100644 --- a/drivers/iio/temperature/mlx90614.c +++ b/drivers/iio/temperature/mlx90614.c @@ -63,7 +63,6 @@ #define MLX90614_CONST_OFFSET_REM 500000 /* remainder of offset (273.15*50) */ #define MLX90614_CONST_SCALE 20 /* Scale in milliKelvin (0.02 * 1000) */ #define MLX90614_CONST_RAW_EMISSIVITY_MAX 65535 /* max value for emissivity */ -#define MLX90614_CONST_EMISSIVITY_RESOLUTION 15259 /* 1/65535 ~ 0.000015259 */ #define MLX90614_CONST_FIR 0x7 /* Fixed value for FIR part of low pass filter */ struct mlx90614_data { @@ -283,7 +282,8 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev, *val2 = 0; } else { *val = 0; - *val2 = ret * MLX90614_CONST_EMISSIVITY_RESOLUTION; + *val2 = ret * NSEC_PER_SEC / + MLX90614_CONST_RAW_EMISSIVITY_MAX; } return IIO_VAL_INT_PLUS_NANO; case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with @@ -321,7 +321,7 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev, if (val < 0 || val2 < 0 || val > 1 || (val == 1 && val2 != 0)) return -EINVAL; val = val * MLX90614_CONST_RAW_EMISSIVITY_MAX + - val2 / MLX90614_CONST_EMISSIVITY_RESOLUTION; + val2 * MLX90614_CONST_RAW_EMISSIVITY_MAX / NSEC_PER_SEC; ret = mlx90614_power_get(data, false); if (ret < 0) From patchwork Wed May 10 10:22:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 680688 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE316C7EE23 for ; Wed, 10 May 2023 10:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236600AbjEJKXl (ORCPT ); Wed, 10 May 2023 06:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236605AbjEJKXf (ORCPT ); Wed, 10 May 2023 06:23:35 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AA4F6597; Wed, 10 May 2023 03:23:30 -0700 (PDT) Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 127D386046; Wed, 10 May 2023 12:23:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1683714206; bh=V2gCP1JQKiP2Q62kgi8JEznvs51An9SWl74pIaFIAqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zg5VFE217DUswDx/AdDLVAnQ+Y9LDwJH3whsnnLhNKKpDNxLSFyun7xjiRqEE5D0c h7u0o5gj2MUsdfH6lJG+23xKMwWBn7ay3JqUpKnrv/H5W5Bp7z/PZceZ3QmnWUZhBQ jHFCBeOLPC1SIpSIw3nSYJTTzX6J/ZA54eZgaNjcXim4u2QwzAhE2XFzpJSAPCtKEr t+8UNDS019tlz/CuJ8514hAGaN3lE26mYhlZ6UUW662rcbQ75XvG2K5OlQ3wOmsqy/ RGRh7arf7i1GKjeeq7hSMza6D4/pj/19qEX5iV1RcjdvhzIio8nAYae3x+IHKyTrI4 gJ4n+5nkakmQg== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Crt Mori , Jonathan Cameron , Krzysztof Kozlowski , Lars-Peter Clausen , Peter Meerwald , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v3 6/6] iio: mlx90614: Add MLX90615 support Date: Wed, 10 May 2023 12:22:51 +0200 Message-Id: <20230510102251.10118-6-marex@denx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230510102251.10118-1-marex@denx.de> References: <20230510102251.10118-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support for MLX90615 Infra Red Thermometer, which seems to be the predecesor of MLX90614 . There are significant differences in the register layout compared to MLX90614, but the functionality of the device is virtually identical. The following differences have been identified: - RAM/EEPROM/SLEEP access opcodes are different - RAM/EEPROM registers are at different offsets - EEPROM emissivity and configuration registers are at different offsets - EEPROM configuration register bits are shuffled around - EEPROM emissivity settings are 14 bit on MLX90615 , 16 bit on MLX90614 - MLX90615 can only ever support one sensor, MLX90614 could support two - FIR filter is set to fixed settings on MLX90615 - IIR filter coefficients are different This patch fills in the MLX90615 specific description and quirk handling. The IIR filter coefficients were provided by Melexis as follows: 0b0000 - Forbidden value 0b0001 - 100% - settling time = refresh rate = 205ms (around 5Hz) 0b0010 - 50% - settling time = 2050ms (around 0.5Hz) 0b0011 - 33% - settling time = 36900ms (around 0.3Hz) 0b0100 - 25% - settling time = 5125ms (around 0.2Hz) 0b0101 - 20% - settling time = 6355ms (around 0.15Hz) 0b0110 - 17% - settling time = 7790ms (around 0.13Hz) 0b0111 - 14% - settling time = 9225ms (around 0.1Hz) Signed-off-by: Marek Vasut Acked-by: Crt Mori --- Cc: Crt Mori Cc: Jonathan Cameron Cc: Krzysztof Kozlowski Cc: Lars-Peter Clausen Cc: Marek Vasut Cc: Peter Meerwald Cc: Rob Herring Cc: devicetree@vger.kernel.org Cc: linux-iio@vger.kernel.org --- V2: Split the patch up into cleanups, abstraction and MLX90615 addition V3: Drop emissivity_res, update IIR filter coefficients per Melexis input --- drivers/iio/temperature/mlx90614.c | 48 +++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c index 3aa108a652bb4..b2affcb795e00 100644 --- a/drivers/iio/temperature/mlx90614.c +++ b/drivers/iio/temperature/mlx90614.c @@ -1,12 +1,15 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * mlx90614.c - Support for Melexis MLX90614 contactless IR temperature sensor + * mlx90614.c - Support for Melexis MLX90614/MLX90615 contactless IR temperature sensor * * Copyright (c) 2014 Peter Meerwald * Copyright (c) 2015 Essensium NV * Copyright (c) 2015 Melexis * - * Driver for the Melexis MLX90614 I2C 16-bit IR thermopile sensor + * Driver for the Melexis MLX90614/MLX90615 I2C 16-bit IR thermopile sensor + * + * MLX90614 - 17-bit ADC + MLX90302 DSP + * MLX90615 - 16-bit ADC + MLX90325 DSP * * (7-bit I2C slave address 0x5a, 100KHz bus speed only!) * @@ -35,6 +38,10 @@ #define MLX90614_OP_EEPROM 0x20 #define MLX90614_OP_SLEEP 0xff +#define MLX90615_OP_EEPROM 0x10 +#define MLX90615_OP_RAM 0x20 +#define MLX90615_OP_SLEEP 0xc6 + /* Control bits in configuration register */ #define MLX90614_CONFIG_IIR_SHIFT 0 /* IIR coefficient */ #define MLX90614_CONFIG_IIR_MASK (0x7 << MLX90614_CONFIG_IIR_SHIFT) @@ -43,11 +50,16 @@ #define MLX90614_CONFIG_FIR_SHIFT 8 /* FIR coefficient */ #define MLX90614_CONFIG_FIR_MASK (0x7 << MLX90614_CONFIG_FIR_SHIFT) +#define MLX90615_CONFIG_IIR_SHIFT 12 /* IIR coefficient */ +#define MLX90615_CONFIG_IIR_MASK (0x7 << MLX90615_CONFIG_IIR_SHIFT) + /* Timings (in ms) */ #define MLX90614_TIMING_EEPROM 20 /* time for EEPROM write/erase to complete */ #define MLX90614_TIMING_WAKEUP 34 /* time to hold SDA low for wake-up */ #define MLX90614_TIMING_STARTUP 250 /* time before first data after wake-up */ +#define MLX90615_TIMING_WAKEUP 22 /* time to hold SCL low for wake-up */ + #define MLX90614_AUTOSLEEP_DELAY 5000 /* default autosleep delay */ /* Magic constants */ @@ -305,8 +317,8 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev, *val2 = ret * NSEC_PER_SEC / chip_info->emissivity_max; } return IIO_VAL_INT_PLUS_NANO; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with - FIR = 1024 */ + /* IIR setting with FIR=1024 (MLX90614) or FIR=65536 (MLX90615) */ + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: ret = mlx90614_power_get(data, false); if (ret < 0) return ret; @@ -664,14 +676,42 @@ static const struct mlx_chip_info mlx90614_chip_info = { }, }; +static const struct mlx_chip_info mlx90615_chip_info = { + .op_eeprom_emissivity = MLX90615_OP_EEPROM | 0x03, + .op_eeprom_config1 = MLX90615_OP_EEPROM | 0x02, + .op_ram_ta = MLX90615_OP_RAM | 0x06, + .op_ram_tobj1 = MLX90615_OP_RAM | 0x07, + .op_ram_tobj2 = MLX90615_OP_RAM | 0x08, + .op_sleep = MLX90615_OP_SLEEP, + .dual_channel = false, + .wakeup_delay_ms = MLX90615_TIMING_WAKEUP, + .emissivity_max = 16383, + .fir_config_mask = 0, /* MLX90615 FIR is fixed */ + .iir_config_mask = MLX90615_CONFIG_IIR_MASK, + /* IIR value 0 is FORBIDDEN COMBINATION on MLX90615 */ + .iir_valid_offset = 1, + .iir_values = { 500, 50, 30, 20, 15, 13, 10 }, + .iir_freqs = { + { 0, 100000 }, /* 14% ~= 0.10 Hz */ + { 0, 130000 }, /* 17% ~= 0.13 Hz */ + { 0, 150000 }, /* 20% ~= 0.15 Hz */ + { 0, 200000 }, /* 25% ~= 0.20 Hz */ + { 0, 300000 }, /* 33% ~= 0.30 Hz */ + { 0, 500000 }, /* 50% ~= 0.50 Hz */ + { 5, 000000 }, /* 100% ~= 5.00 Hz */ + }, +}; + static const struct i2c_device_id mlx90614_id[] = { { "mlx90614", .driver_data = (kernel_ulong_t)&mlx90614_chip_info }, + { "mlx90615", .driver_data = (kernel_ulong_t)&mlx90615_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, mlx90614_id); static const struct of_device_id mlx90614_of_match[] = { { .compatible = "melexis,mlx90614", .data = &mlx90614_chip_info }, + { .compatible = "melexis,mlx90615", .data = &mlx90615_chip_info }, { } }; MODULE_DEVICE_TABLE(of, mlx90614_of_match);