From patchwork Thu Oct 20 09:02:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 6063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp145016wrs; Thu, 20 Oct 2022 02:04:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5V85wgrz2LsxmZhq5GaZWjef9Q0dlZr7Sl3nRkbYhIDhSsU3WDBQMqFOWf4jfnFvuGLm+5 X-Received: by 2002:a17:906:c151:b0:78d:cdbc:9fb7 with SMTP id dp17-20020a170906c15100b0078dcdbc9fb7mr9731489ejc.688.1666256650837; Thu, 20 Oct 2022 02:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666256650; cv=none; d=google.com; s=arc-20160816; b=vFhY/fa3b86dRsZI79PyHaj76xHnFraM9wd4FahNpyToBZW8LA4Qfpze44o9OLaD9i 5pHj+mKLNLIG7BXPDlBWypZTbmnLqvfgWYXn5lJB0cm9bL2yHjQvzwDf35LRZ00VRbJZ VZdKhCpGGPK1UpbJnk9K+jRSCWa22Dgqxoi8nhoHHi6WsXHjI+AWc+uoI/pY3QymPQrP dekyIQhdKQEdFXeoTb7QeUpMSnj+4BYrXogfSIoxFjGUIWzIURG+E4MpFH8EwGU1oU8Z EuQ+QFLvdQH73yPsToxuG2kyOJOXOJJHtnUMOeyeLCOOsa28cfWNdNRxm/AW6LCuz/Vo yL7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=1rWGlafMlqwMwhfThN+R1n4/HH5vIykVnEuONb/Vfvk=; b=oTQv9r7aEA/lD2a8B2jlqDlByeB6FkMFE2h3EONrF3kWKgxusHKILd7yRJZWEw13b2 k2MWt+6uXS7f3oEQUVja1mz83qBJ5uZaE8hjCLX1IPmxoSeFJ4RUL/asjpVP//TmFCy2 2TVddI96Tn2mh6vUu5mBfleb3i3Y64RpSk9uvE4TbFlrj990GQJWhs8QcFYiDLvHKWh2 E6H2VqCOrIqL9O58yeKZZa7fwxWvmXUjB0Ydp3z7GHxJDXQQTe0JsYKd7GTEBluOsKo5 +745/1oQC1ynCu2oOQ5tscWSIoVqeNm8qDVXFZRrMzlHjPIbk/qcdU3yeb920RjT/5AJ SA/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=R6aBFYyU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i21-20020a1709061cd500b007825bd02a6asi13488752ejh.54.2022.10.20.02.03.45; Thu, 20 Oct 2022 02:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=R6aBFYyU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbiJTJDT (ORCPT + 99 others); Thu, 20 Oct 2022 05:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbiJTJDO (ORCPT ); Thu, 20 Oct 2022 05:03:14 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84EB41958DA; Thu, 20 Oct 2022 02:03:13 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id t16so9662263edd.2; Thu, 20 Oct 2022 02:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=1rWGlafMlqwMwhfThN+R1n4/HH5vIykVnEuONb/Vfvk=; b=R6aBFYyUxc69y4wyygkhgEBYwbcwUcvtxKjhr8gKfQ8AA7m7u02wwLwXGdMO1YV31E l4Mxx4f95bNxd3X4xo1swAZzPVT+qBzSYuIaJ0MWf60a3aYmh9szneYPat6X6STUDeyl Q/2ELfV4LPBAvugtqWC+e6C3tzRawDHo0jX4AxC0pSSmWbyVrOz35GAS1vTPfYawptWi SQYCJmAKyt90Lery+QzwhMOzsx95qkxgSLesSd3AoaRjihn4dHCh34Fg9v68x98sBxgg bu/RbL2Tw5ZkD8wp1Bab7UiKyDS9L3MXyPLMLWM1jknKgeYrzlZViGABLzNFtyia+qB6 qkqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=1rWGlafMlqwMwhfThN+R1n4/HH5vIykVnEuONb/Vfvk=; b=VCYQCE8OYhhEkoRda0/1ZOIqC750IR0v1kfWk8hbB074fhQ0HPCzxT++S6T5kzhx4f xgltbbLwNjC5vscwF7PtxDNMK+87xNpvYFVmkrB1xLQ7CDHpujSQbGrV/fL1guoYkZDs nvpckggY5N7r8E0SrSly/eFSpT0Eyu2ScwdK6MhUlfeR/jFYemnDgK/nv5EnmgbRHCbw OUKKkLyBBdOtnWwP0NFP0h1+NvpW86NU51CUg25Q/+y843YUeBHKvjWilXcqDZUCGtGf KGLhYX4wI/TUOpSvfkgRuxGH9ZrbaBgtjrX+8zY0AQZvkWvLuCTKv7CUIOkPu6ujRrwL LkRg== X-Gm-Message-State: ACrzQf1FxQ5Od1yB174y2AS2BGfuIOY9N3cIvzNecHdyQttSGyK0IKNf 33agW2b50HiEpEgdCmaJ0Sxp/w3uiDw= X-Received: by 2002:a05:6402:f96:b0:459:4180:6cf4 with SMTP id eh22-20020a0564020f9600b0045941806cf4mr11307056edb.64.1666256591948; Thu, 20 Oct 2022 02:03:11 -0700 (PDT) Received: from localhost.localdomain ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id c2-20020a17090618a200b007933047f923sm1668381ejf.118.2022.10.20.02.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:03:11 -0700 (PDT) From: Cosmin Tanislav Cc: =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v2 1/5] iio: temperature: ltc2983: allocate iio channels once Date: Thu, 20 Oct 2022 12:02:53 +0300 Message-Id: <20221020090257.1717053-2-demonsingur@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221020090257.1717053-1-demonsingur@gmail.com> References: <20221020090257.1717053-1-demonsingur@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747196733907596654?= X-GMAIL-MSGID: =?utf-8?q?1747196733907596654?= From: Cosmin Tanislav Currently, every time the device wakes up from sleep, the iio_chan array is reallocated, leaking the previous one until the device is removed (basically never). Move the allocation to the probe function to avoid this. Fixes: f110f3188e56 ("iio: temperature: Add support for LTC2983") Signed-off-by: Cosmin Tanislav --- drivers/iio/temperature/ltc2983.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index b652d2b39bcf..a60ccf183687 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -1385,13 +1385,6 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) return ret; } - st->iio_chan = devm_kzalloc(&st->spi->dev, - st->iio_channels * sizeof(*st->iio_chan), - GFP_KERNEL); - - if (!st->iio_chan) - return -ENOMEM; - ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG, LTC2983_NOTCH_FREQ_MASK, LTC2983_NOTCH_FREQ(st->filter_notch_freq)); @@ -1514,6 +1507,12 @@ static int ltc2983_probe(struct spi_device *spi) gpiod_set_value_cansleep(gpio, 0); } + st->iio_chan = devm_kzalloc(&spi->dev, + st->iio_channels * sizeof(*st->iio_chan), + GFP_KERNEL); + if (!st->iio_chan) + return -ENOMEM; + ret = ltc2983_setup(st, true); if (ret) return ret; From patchwork Thu Oct 20 09:02:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 6064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp145039wrs; Thu, 20 Oct 2022 02:04:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6iB3dh4Hn4T4zEmxHvhkaqCgFhB2XAzs5yxeTUO2mAhZi4vV/XNz1bb4NPajigOpWh5iOj X-Received: by 2002:a17:907:7252:b0:791:9fd8:222e with SMTP id ds18-20020a170907725200b007919fd8222emr9279379ejc.729.1666256653345; Thu, 20 Oct 2022 02:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666256653; cv=none; d=google.com; s=arc-20160816; b=zIABRG80L+8drKpd8fmAyXLSGTzS4Eh3A25XF3Hd55oF+VwL/sPTICd8Fxxp/ndb2r S49CMKLYXoAnLhvN0iYQ6uDYHrINTAkU0Ny/0PlZJXtWYXUGExK05JCpU8m7FAWYJdjx +ygIUb+6hwml7FBEOKMUZ8f+9KgAx5bPXBMjYPFKTM27Ka4mQNJC+PH+mr5O4TUuMJrN P15CVKnwDgQYLhYWONRjDMP1r3b2SzjUrOWEX1TqrGrHgwwmWH0G5M60yPgC0FfUG3W4 0LJHt7SmzMI0eacBXfDzqqdO9wFGPjnI/NagARki2j8Md6mYGvi0npaSVD5qyeAzoFIV dMNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=NsbaewV9DVD6hC+LhVH29kK0IrjFkaoSLZjl3o+0gnM=; b=h2/q4aZNt7CC7nErccpDm/29+wzOZ5tCC5PmXPE9OEIyCjTZIqO81qFNDPIVTsoit8 mMPsV1KUyUe0Uf/G36TRDtgA+AptU9vBLEGrMZRkBdoiOp9IX/c+3uw8ICWZ+SXDfok3 QSCKiNv6nG750Y4aftv2D4U1uS31uyBpmTYg9TJSp/rOD3L7DOvBnB1N58o4k+2IdOgH EMmdmR3UDtaXVBsZq2UdG9NO6+1oASwb/SYACwIiF9hjQ+pzvChKj1hjMJe3co43OoAA fD0CCmiLfYar1fJDABNgLxaXYQYc0ICtR0vjWsT0F8gZ/HYHe04PkPc/ymjajQ8mrZz2 E/3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=OJMnkNse; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g32-20020a056402322000b004609e72d0e2si950152eda.85.2022.10.20.02.03.48; Thu, 20 Oct 2022 02:04:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=OJMnkNse; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230178AbiJTJDV (ORCPT + 99 others); Thu, 20 Oct 2022 05:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbiJTJDR (ORCPT ); Thu, 20 Oct 2022 05:03:17 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B7C196EDE; Thu, 20 Oct 2022 02:03:15 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id t16so9662420edd.2; Thu, 20 Oct 2022 02:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=NsbaewV9DVD6hC+LhVH29kK0IrjFkaoSLZjl3o+0gnM=; b=OJMnkNseZoxkZNSn9kWzz7OlkLoAxWgdg6PimTCA8ja+dqkWffM+gonl20S4ZJcEL9 SD9EHJ2IkWfkYXgM9c/eSsMQQgvlyGfiiLn/XGNSAVhehZyML/EP9iuwfFUZyXAWzjoh /W1s6R8tPzq+IjaUE0e9GYE3ou3uczcOXfF7ep+v1lJ+YIpMQ2AJtI8lgwE8xDQQ8k3K 3SD1bKfnx3SRwaaGAUM37cDuYQmkEU0fEaYNmF59rOORGEwFGzRXiirXYhSB7nn0Syre DWi42Cajp6hyCtQJM+z17zzSb5iBv0qv2+pJIy8zOV8FHgEDpBUKRdZpGeNfq4mprq0H s9ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NsbaewV9DVD6hC+LhVH29kK0IrjFkaoSLZjl3o+0gnM=; b=LawnNFO1+/032vj7QoJNTHY9Yq8lxnx2sll4Qi7mccOjtr9cj4zqq2uQrEx++RdW92 w3zpLfuHtKT6JtB7FN9GgXDgl5a6QvoBSzfMN6uhK4jxOSY3NE62WKZyVTdWFbwru+PG i1AoMtEuEpmbqBaFhnEvmuNpvo9aloOtpCpaH194bT/7v61ITkiboXzjaEOql+it3WYD /A+BMT3Do5e9s5qnCHyxZ6AM5mqYlDj6o1dHyp1SYARDHJnulGa3GkHTDfNOPEERTDNG 16iQ9KyPjZnoVilj8GT0sRsTKi5yziwdY8sdI4X2l1igvgNEOpRnAPsbijuLdVcIu9YB 5LjA== X-Gm-Message-State: ACrzQf3VNl0sz+f0zZ1/lCjLQ28pr3RCHpL9sBYmbEvYJYj+YgLIokEW ndoJyujIw2pKi5WYRH9NN3U= X-Received: by 2002:aa7:c956:0:b0:43b:206d:c283 with SMTP id h22-20020aa7c956000000b0043b206dc283mr11276180edt.381.1666256594270; Thu, 20 Oct 2022 02:03:14 -0700 (PDT) Received: from localhost.localdomain ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id c2-20020a17090618a200b007933047f923sm1668381ejf.118.2022.10.20.02.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:03:14 -0700 (PDT) From: Cosmin Tanislav Cc: =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v2 2/5] iio: temperature: ltc2983: make bulk write buffer DMA-safe Date: Thu, 20 Oct 2022 12:02:54 +0300 Message-Id: <20221020090257.1717053-3-demonsingur@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221020090257.1717053-1-demonsingur@gmail.com> References: <20221020090257.1717053-1-demonsingur@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747196736756482999?= X-GMAIL-MSGID: =?utf-8?q?1747196736756482999?= From: Cosmin Tanislav regmap_bulk_write() does not guarantee implicit DMA-safety, even though the current implementation duplicates the given buffer. Do not rely on it. Fixes: f110f3188e56 ("iio: temperature: Add support for LTC2983") Signed-off-by: Cosmin Tanislav Reviewed-by: Nuno Sá --- drivers/iio/temperature/ltc2983.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index a60ccf183687..1117991ca2ab 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -209,6 +209,7 @@ struct ltc2983_data { * Holds the converted temperature */ __be32 temp __aligned(IIO_DMA_MINALIGN); + __be32 chan_val; }; struct ltc2983_sensor { @@ -313,19 +314,18 @@ static int __ltc2983_fault_handler(const struct ltc2983_data *st, return 0; } -static int __ltc2983_chan_assign_common(const struct ltc2983_data *st, +static int __ltc2983_chan_assign_common(struct ltc2983_data *st, const struct ltc2983_sensor *sensor, u32 chan_val) { u32 reg = LTC2983_CHAN_START_ADDR(sensor->chan); - __be32 __chan_val; chan_val |= LTC2983_CHAN_TYPE(sensor->type); dev_dbg(&st->spi->dev, "Assign reg:0x%04X, val:0x%08X\n", reg, chan_val); - __chan_val = cpu_to_be32(chan_val); - return regmap_bulk_write(st->regmap, reg, &__chan_val, - sizeof(__chan_val)); + st->chan_val = cpu_to_be32(chan_val); + return regmap_bulk_write(st->regmap, reg, &st->chan_val, + sizeof(st->chan_val)); } static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data *st, From patchwork Thu Oct 20 09:02:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 6066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp146025wrs; Thu, 20 Oct 2022 02:06:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7F4y2JrbivZametyiXRVclOBXsAftKRPPvpYcShfsROrfI0M9aH7riURoIQBGZkgoUvyo2 X-Received: by 2002:a17:906:8473:b0:77b:efa8:50e4 with SMTP id hx19-20020a170906847300b0077befa850e4mr10064101ejc.250.1666256799786; Thu, 20 Oct 2022 02:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666256799; cv=none; d=google.com; s=arc-20160816; b=Xva0z8SyWiJGqFQItZQQBkJPB8y4qUH56pFXjhExs6F+IBEicGteGHZXrBZfRlaugC hex3CnRMhlyeRZ53RhIdskYgiSKGFshChk6fxoU1IQttKNxwJm+zJKU4iPBryghOqRSH +Go7NodmAx8RkDestMHb0N7wZrDYuwH1KFiLzLoEcf0AsIzOD0ueva69PSpjeWdCwAIB ssYpxf5COyaR8xyLkfr7fvCL84vrii9gBGD9ow+emK7wxayGm9DwRqH140SzrFPSNEQB dR3DrAjrqo5XWkP/pU+sEpcCdZjH+Ve3GRtOKJt58WujLyVkAGLAwgq77lcAUs2PpCK5 LTpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=DayiKLlvbIIue7g6LBPYF4GqrTQZTG5BKYE4ilcFye8=; b=YwBjpVbKm0lUdl9mgMMOcJanBKESDybHoFJLBY+a8ybTGqMxaEFBjSiYr5AMlVs2K1 NYpT3Aonr88+DIQ0b2KvQfqhxS5uY9pT3XHPf+FKu7wnNBxtC/+rARgP+y6tZdw04ON0 J09FjvFPv5zUxzYvn/B3rLc4uzJORzjZJr8aEy5CWSIW9kbV41FYjwcbmiDsSpfQCdrB yg+wd0HExhXdb8u0dteyOvF8kmwknkj2kEU82vIwZ8duxBOYNWUdA6UC38ZVSCXWggnb 8bIocA7lMqOUCtYo6nNiAjmQ0mTMPpOrh2/kJJBMzpl5tQJOav+qf3dq/DkXofYWZp1f Isog== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=VGCyTal8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a170906974a00b0078dcdb1c9dfsi17412944ejy.553.2022.10.20.02.06.13; Thu, 20 Oct 2022 02:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=VGCyTal8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbiJTJD1 (ORCPT + 99 others); Thu, 20 Oct 2022 05:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbiJTJDX (ORCPT ); Thu, 20 Oct 2022 05:03:23 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 574651960AF; Thu, 20 Oct 2022 02:03:19 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id sc25so45737412ejc.12; Thu, 20 Oct 2022 02:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=DayiKLlvbIIue7g6LBPYF4GqrTQZTG5BKYE4ilcFye8=; b=VGCyTal8LA1G76/CSx8YcuHU2Zms5xsOQGnB0JKISjBurU6oFAaefzNZGO+dSnE+Ag NLaGUTiV9bdAg6g5ihI0FjxidQNmZz4v0ZShB3OxSn92NI4y6Ghtsafbt8T3ckcoKwzE o6/aGk8BizK7N9y4hLjl2humzyQxYZ3DfQBBwhxpYVdG0Kt8KhLBqM1Ji1RNaaBElwQ4 xBcxToapErMuLqnDuUw0X3xB2L60zDHkYrEwgpDZRmNNa9WvEPVNBciBdKSfTTxqvrvu DqQFKDE+JP8ou4eKwvtbCShcYzEx2h6yL8gI9HvdgZpxOnNlXGzrU0e0PeR7gt/A939O 4mDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=DayiKLlvbIIue7g6LBPYF4GqrTQZTG5BKYE4ilcFye8=; b=w8FcMpTUfV4DwVCizlldSkzOoueZGMdOUAA8Q+0fhuH6AipoOF8FW5BM/B+ub7II9z S1K9XV8tyUt7yynms7aNM1UbYnVvYEMU3YbXGdHq2YttQ0aCtoIQF7Iy6nuxgFdGBUWg zEZrCTRUte0dY2CyJciEq+7GbUOhhFy5JV+rmXQgLWPj0QBFBCQm8mvajcND0CrhfS8E H496w0yhyy1PsA7hcXwlea8zeAM1j0GfAneHefvhf/SCzflvK3HAlmfo0f1yVzDqyKw0 3hCrkOHFSRgGtZRLr1pR4uhU3HqDXrQknKOepEk/HxFYttinbs5H18mDuBxijI4KyP+H lBog== X-Gm-Message-State: ACrzQf3EUfIHzav3uQ8lS3RCEbKlgWE8WiTlPPzbbCG21TLeDxf9t/d8 YjLQl/zYy9AL9qehsQmWwoo= X-Received: by 2002:a17:907:25c5:b0:783:f5df:900e with SMTP id ae5-20020a17090725c500b00783f5df900emr9753337ejc.491.1666256597449; Thu, 20 Oct 2022 02:03:17 -0700 (PDT) Received: from localhost.localdomain ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id c2-20020a17090618a200b007933047f923sm1668381ejf.118.2022.10.20.02.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:03:17 -0700 (PDT) From: Cosmin Tanislav Cc: =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v2 3/5] dt-bindings: iio: temperature: ltc2983: refine Date: Thu, 20 Oct 2022 12:02:55 +0300 Message-Id: <20221020090257.1717053-4-demonsingur@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221020090257.1717053-1-demonsingur@gmail.com> References: <20221020090257.1717053-1-demonsingur@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747196890306617175?= X-GMAIL-MSGID: =?utf-8?q?1747196890306617175?= From: Cosmin Tanislav * make sure addresses are represented as hex * add note about wrong unit value for adi,mux-delay-config-us * simplify descriptions * add descriptions for the items of custom sensor tables * add default property values where applicable * use conditionals to extend minimum reg value for single ended sensors * remove " around phandle schema $ref * remove label from example and use generic temperature sensor name Signed-off-by: Cosmin Tanislav --- .../bindings/iio/temperature/adi,ltc2983.yaml | 309 +++++++++++------- 1 file changed, 182 insertions(+), 127 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml index 722781aa4697..3e97ec841fd6 100644 --- a/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml +++ b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml @@ -26,25 +26,25 @@ properties: adi,mux-delay-config-us: description: - The LTC2983 performs 2 or 3 internal conversion cycles per temperature - result. Each conversion cycle is performed with different excitation and - input multiplexer configurations. Prior to each conversion, these - excitation circuits and input switch configurations are changed and an - internal 1ms delay ensures settling prior to the conversion cycle in most - cases. An extra delay can be configured using this property. The value is - rounded to nearest 100us. + Extra delay prior to each conversion, in addition to the internal 1ms + delay, for the multiplexer to switch input configurations and + excitation values. + + This property is supposed to be in microseconds, but to maintain + compatibility, this value will be multiplied by 100 before usage. maximum: 255 + default: 0 adi,filter-notch-freq: description: - Set's the default setting of the digital filter. The default is - simultaneous 50/60Hz rejection. + Notch frequency of the digital filter. 0 - 50/60Hz rejection 1 - 60Hz rejection 2 - 50Hz rejection $ref: /schemas/types.yaml#/definitions/uint32 minimum: 0 maximum: 2 + default: 0 '#address-cells': const: 1 @@ -53,19 +53,19 @@ properties: const: 0 patternProperties: - "@([1-9]|1[0-9]|20)$": + "@([0-9a-f]+)$": type: object - + description: Sensor. properties: reg: description: - The channel number. It can be connected to one of the 20 channels of - the device. - minimum: 1 + Channel number. Connects the sensor to the channel with this number + of the device. + minimum: 2 maximum: 20 adi,sensor-type: - description: Identifies the type of sensor connected to the device. + description: Type of sensor connected to the device. $ref: /schemas/types.yaml#/definitions/uint32 required: @@ -74,10 +74,7 @@ patternProperties: "^thermocouple@": type: object - description: - Represents a thermocouple sensor which is connected to one of the device - channels. - + description: Thermocouple sensor. properties: adi,sensor-type: description: | @@ -95,87 +92,104 @@ patternProperties: maximum: 9 adi,single-ended: - description: - Boolean property which set's the thermocouple as single-ended. + description: Whether the sensor is single-ended. type: boolean adi,sensor-oc-current-microamp: - description: - This property set's the pulsed current value applied during - open-circuit detect. + description: Pulsed current value applied during open-circuit detect. enum: [10, 100, 500, 1000] + default: 10 adi,cold-junction-handle: description: - Phandle which points to a sensor object responsible for measuring - the thermocouple cold junction temperature. - $ref: "/schemas/types.yaml#/definitions/phandle" + Sensor responsible for measuring the thermocouple cold junction + temperature. + $ref: /schemas/types.yaml#/definitions/phandle adi,custom-thermocouple: description: - This is a table, where each entry should be a pair of - voltage(mv)-temperature(K). The entries must be given in nv and uK - so that, the original values must be multiplied by 1000000. For - more details look at table 69 and 70. - Note should be signed, but dtc doesn't currently maintain the - sign. + Used for digitizing custom thermocouples. + See Page 59 of the datasheet. $ref: /schemas/types.yaml#/definitions/uint64-matrix minItems: 3 maxItems: 64 items: - minItems: 2 - maxItems: 2 + items: + - description: Voltage point in nV, signed. + - description: Temperature point in uK. + + allOf: + - if: + properties: + adi,single-ended: + const: true + then: + properties: + reg: + minimum: 1 + - if: + properties: + adi,sensor-type: + const: 9 + then: + required: + - adi,custom-thermocouple "^diode@": type: object - description: - Represents a diode sensor which is connected to one of the device - channels. - + description: Diode sensor. properties: adi,sensor-type: - description: Identifies the sensor as a diode. + description: Sensor type for diodes. $ref: /schemas/types.yaml#/definitions/uint32 const: 28 adi,single-ended: - description: Boolean property which set's the diode as single-ended. + description: Whether the sensor is single-ended. type: boolean adi,three-conversion-cycles: description: - Boolean property which set's three conversion cycles removing - parasitic resistance effects between the LTC2983 and the diode. + Whether to use three conversion cycles to remove parasitic + resistance between the device and the diode. type: boolean adi,average-on: description: - Boolean property which enables a running average of the diode - temperature reading. This reduces the noise when the diode is used - as a cold junction temperature element on an isothermal block - where temperatures change slowly. + Whether to use a running average of the diode temperature + reading to reduce the noise when the diode is used as a cold + junction temperature element on an isothermal block where + temperatures change slowly. type: boolean adi,excitation-current-microamp: description: - This property controls the magnitude of the excitation current - applied to the diode. Depending on the number of conversions - cycles, this property will assume different predefined values on - each cycle. Just set the value of the first cycle (1l). + Magnitude of the 1l excitation current applied to the diode. + 4l excitation current will be 4 times this value, and 8l + excitation current will be 8 times value. enum: [10, 20, 40, 80] + default: 10 adi,ideal-factor-value: description: - This property sets the diode ideality factor. The real value must - be multiplied by 1000000 to remove the fractional part. For more - information look at table 20 of the datasheet. + Diode ideality factor. + Set this property to 1000000 times the real value. $ref: /schemas/types.yaml#/definitions/uint32 + default: 0 + + allOf: + - if: + properties: + adi,single-ended: + const: true + then: + properties: + reg: + minimum: 1 "^rtd@": type: object - description: - Represents a rtd sensor which is connected to one of the device channels. - + description: RTD sensor. properties: reg: minimum: 2 @@ -197,56 +211,57 @@ patternProperties: maximum: 18 adi,rsense-handle: - description: - Phandle pointing to a rsense object associated with this RTD. - $ref: "/schemas/types.yaml#/definitions/phandle" + description: Associated sense resistor sensor. + $ref: /schemas/types.yaml#/definitions/phandle adi,number-of-wires: description: - Identifies the number of wires used by the RTD. Setting this - property to 5 means 4 wires with Kelvin Rsense. + Number of wires used by the RTD. + 5 means 4 wires with Kelvin sense resistor. $ref: /schemas/types.yaml#/definitions/uint32 enum: [2, 3, 4, 5] + default: 2 adi,rsense-share: description: - Boolean property which enables Rsense sharing, where one sense - resistor is used for multiple 2-, 3-, and/or 4-wire RTDs. + Whether to enable sense resistor sharing, where one sense + resistor is used by multiple sensors. type: boolean adi,current-rotate: description: - Boolean property which enables excitation current rotation to - automatically remove parasitic thermocouple effects. Note that - this property is not allowed for 2- and 3-wire RTDs. + Whether to enable excitation current rotation to automatically + remove parasitic thermocouple effects. type: boolean adi,excitation-current-microamp: - description: - This property controls the magnitude of the excitation current - applied to the RTD. + description: Excitation current applied to the RTD. enum: [5, 10, 25, 50, 100, 250, 500, 1000] + default: 5 adi,rtd-curve: description: - This property set the RTD curve used and the corresponding - Callendar-VanDusen constants. Look at table 30 of the datasheet. + RTD curve and the corresponding Callendar-VanDusen constants. + 0 - European + 1 - American + 2 - Japanese + 3 - ITS-90 $ref: /schemas/types.yaml#/definitions/uint32 minimum: 0 maximum: 3 + default: 0 adi,custom-rtd: description: - This is a table, where each entry should be a pair of - resistance(ohm)-temperature(K). The entries added here are in uohm - and uK. For more details values look at table 74 and 75. + Used for digitizing custom RTDs. + See Page 62 of the datasheet. $ref: /schemas/types.yaml#/definitions/uint64-matrix + minItems: 3 + maxItems: 64 items: - minItems: 3 - maxItems: 64 items: - minItems: 2 - maxItems: 2 + - description: Resistance point in uOhms. + - description: Temperature point in uK. required: - adi,rsense-handle @@ -254,12 +269,25 @@ patternProperties: dependencies: adi,current-rotate: [ "adi,rsense-share" ] + allOf: + - if: + properties: + adi,number-of-wires: + enum: [2, 3] + then: + properties: + adi,current-rotate: false + - if: + properties: + adi,sensor-type: + const: 18 + then: + required: + - adi,custom-rtd + "^thermistor@": type: object - description: - Represents a thermistor sensor which is connected to one of the device - channels. - + description: Thermistor sensor. properties: adi,sensor-type: description: @@ -277,61 +305,54 @@ patternProperties: maximum: 27 adi,rsense-handle: - description: - Phandle pointing to a rsense object associated with this - thermistor. - $ref: "/schemas/types.yaml#/definitions/phandle" + description: Associated sense resistor sensor. + $ref: /schemas/types.yaml#/definitions/phandle adi,single-ended: - description: - Boolean property which set's the thermistor as single-ended. + description: Whether the sensor is single-ended. type: boolean adi,rsense-share: description: - Boolean property which enables Rsense sharing, where one sense - resistor is used for multiple thermistors. Note that this property - is ignored if adi,single-ended is set. + Whether to enable sense resistor sharing, where one sense + resistor is used by multiple sensors. type: boolean adi,current-rotate: description: - Boolean property which enables excitation current rotation to - automatically remove parasitic thermocouple effects. + Whether to enable excitation current rotation to automatically + remove parasitic thermocouple effects. type: boolean adi,excitation-current-nanoamp: description: - This property controls the magnitude of the excitation current - applied to the thermistor. Value 0 set's the sensor in auto-range - mode. + Excitation current applied to the thermistor. + 0 sets the sensor in auto-range mode. $ref: /schemas/types.yaml#/definitions/uint32 enum: [0, 250, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000, 500000, 1000000] + default: 0 + + adi,custom-steinhart: + description: + Steinhart-Hart coefficients in raw format, used for digitizing + custom thermistors. + See Page 68 of the datasheet. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 6 + maxItems: 6 adi,custom-thermistor: description: - This is a table, where each entry should be a pair of - resistance(ohm)-temperature(K). The entries added here are in uohm - and uK only for custom thermistors. For more details look at table - 78 and 79. + Used for digitizing custom thermistors. + See Page 65 of the datasheet. $ref: /schemas/types.yaml#/definitions/uint64-matrix minItems: 3 maxItems: 64 items: - minItems: 2 - maxItems: 2 - - adi,custom-steinhart: - description: - Steinhart-Hart coefficients are also supported and can - be programmed into the device memory using this property. For - Steinhart sensors the coefficients are given in the raw - format. Look at table 82 for more information. - $ref: /schemas/types.yaml#/definitions/uint32-array - items: - minItems: 6 - maxItems: 6 + items: + - description: Resistance point in uOhms. + - description: Temperature point in uK. required: - adi,rsense-handle @@ -339,40 +360,74 @@ patternProperties: dependencies: adi,current-rotate: [ "adi,rsense-share" ] + allOf: + - if: + properties: + adi,single-ended: + const: true + then: + properties: + reg: + minimum: 1 + - if: + properties: + adi,sensor-type: + const: 26 + then: + properties: + adi,excitation-current-nanoamp: + default: 1000 + required: + - adi,custom-steinhart + - if: + properties: + adi,sensor-type: + const: 27 + then: + properties: + adi,excitation-current-nanoamp: + default: 1000 + required: + - adi,custom-thermistor + "^adc@": type: object - description: Represents a channel which is being used as a direct adc. - + description: Direct ADC sensor. properties: adi,sensor-type: - description: Identifies the sensor as a direct adc. + description: Sensor type for direct ADC sensors. $ref: /schemas/types.yaml#/definitions/uint32 const: 30 adi,single-ended: - description: Boolean property which set's the adc as single-ended. + description: Whether the sensor is single-ended. type: boolean + allOf: + - if: + properties: + adi,single-ended: + const: true + then: + properties: + reg: + minimum: 1 + "^rsense@": type: object - description: - Represents a rsense which is connected to one of the device channels. - Rsense are used by thermistors and RTD's. - + description: Sense resistor sensor. properties: reg: minimum: 2 maximum: 20 adi,sensor-type: - description: Identifies the sensor as a rsense. + description: Sensor type sense resistor sensors. $ref: /schemas/types.yaml#/definitions/uint32 const: 29 adi,rsense-val-milli-ohms: - description: - Sets the value of the sense resistor. Look at table 20 of the - datasheet for information. + description: Value of the sense resistor. required: - adi,rsense-val-milli-ohms @@ -391,7 +446,7 @@ examples: #address-cells = <1>; #size-cells = <0>; - sensor_ltc2983: ltc2983@0 { + temp@0 { compatible = "adi,ltc2983"; reg = <0>; From patchwork Thu Oct 20 09:02:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 6068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp146764wrs; Thu, 20 Oct 2022 02:08:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM643QzRogWZnvz5Iywk0nEEucDOEIoh6G14xfOAL2f1C7kkVxyx8p1807EtAqpMbp4Pz3s1 X-Received: by 2002:a17:907:7610:b0:78d:b374:898e with SMTP id jx16-20020a170907761000b0078db374898emr10580842ejc.28.1666256918269; Thu, 20 Oct 2022 02:08:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666256918; cv=none; d=google.com; s=arc-20160816; b=o/yBuYz4MyXXoXXpjtqrH6k+PW+VNNBFO99+BCGnrVUXAXVF7fMHNV9ucSNXG7Khzt GomUjDu/lLhql5QPm+DcTs1B8IoWNQeIqTWXUiiMHDpNmfqVpHNCCX6AespWxiwhl31t evGLAvk+ePi4K0cgwcjGgZIieuI1ntsDXi0ni11HhnRcUBAoqYvQIRkt35e/xPnU8rgo P1Jgvh0FfQtDYYSZ2ZsriGJIv96cAesk97lWJrbZrprA788x7ByNjuv87ZWcgggdMIsD pHrgnNsPfBDTTiEWERP6ZkAb/CVqGZZnhcCnVLhg99zl00VoDX+YiJMSn444yKowKOrB xwRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=Ocaa0fWoUBQts1Nll9hf2RSXba2nGL80I4cFxGD4zfw=; b=OBBYRi12PsHL2WqZqNdk0uVGc0KDJLOWbHPgjwgOITTg8TKoBGkJ18i3xGDnPQ5AtH o9LY7q9M+KuKMOQbpuL+T2WrVLoJ73MTCmgh6TTcuxusfBEwoVwAyE2E2AmvYWzV1DSm 4ntIelqGr3kDzF4MbJETivQBM5g+03iRrHmNLLyW43U8rKTQCxvsYoFv+vcKM+zZni9Z Xs72pu1e/jkv3oWtwrQ8cNf5XrlPPYE7atesxfjZHFnleT8AiuYe0/ICI1pbqr5I/oyl mLqFEt74K4FWG3CtLzZJbf5cfld1JKoBwigYVKxWuT4388CsIgmJZktqKJxO93o1JLuS o6LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=b5sdQPZB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a056402520400b0044615ee1b6fsi18796750edd.218.2022.10.20.02.08.12; Thu, 20 Oct 2022 02:08:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=b5sdQPZB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbiJTJDa (ORCPT + 99 others); Thu, 20 Oct 2022 05:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbiJTJDY (ORCPT ); Thu, 20 Oct 2022 05:03:24 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B1B9196EEE; Thu, 20 Oct 2022 02:03:20 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id d26so45771219ejc.8; Thu, 20 Oct 2022 02:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Ocaa0fWoUBQts1Nll9hf2RSXba2nGL80I4cFxGD4zfw=; b=b5sdQPZBGojRFy+o/RHtPAQUZqYZC9zZt2BeyUz+jmujTlrUCPyYW8SpLQZV8aF0Je 9pqPPz+93xgkfjLphFpn/KKOX0I02mig0kQDP66M4X4Jk+pYBLpWTzAZh/grAQ+upaI4 l4slRSpheqrIuXjLa0wGIhq8lmXWCC3+HBOatebsbgLOm9qAD1ckMYSh3zCawT73MxqY /iEUeWL4YoME1vUV8edBXg2qdjvJdYpjYGA5pRd49X5lW+3smwaEl/CjAE5VKiMdmFrU HMp5v2RfvMyLv5JC9JSERkRYJ8Um9uJLDaMjtEeJrFPzPH7L1YzQGNxQ5E8DEKDkxu2+ tuWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Ocaa0fWoUBQts1Nll9hf2RSXba2nGL80I4cFxGD4zfw=; b=0R4dIJ9Vjda55JXeUuX4Y0utb/aK8NJv3yBmQU/rBRCsV9Y2Gbh304pq66wbN2J3Gz ZDoueDc0AuXbW2TCPUIE0DPM54v3xceop+lRtFOuGJQ2aWcWV6fO9H9aQ50nAeLsoP3a QTTvISyPlMR4cjxvTzfu+ieIdCU6ZbJkH4jJsL8Yl19Q9g9V4VnvHkUNolGKkKVD8WyY 0bdMQkwFN665b9V8HQErYujVNtcTsL1YPCkICDu/sHpHVbuWl8cuNtnlUECZvZo3aWCV kRt0rpJyWeIWH0gCNzckuzl2VHsO075UKjNTDoNoWnXZ30x2gyD9Ig/saEhLwQzj2m6H KZGA== X-Gm-Message-State: ACrzQf3F23B1/H5szu3PkQR0i8xBj58lWOB7nLap6imSMwWWSwcrJVsQ RUiVx+mH62DaOjDxcksWQC8= X-Received: by 2002:a17:907:2e0d:b0:78e:314:9d88 with SMTP id ig13-20020a1709072e0d00b0078e03149d88mr10223826ejc.54.1666256599010; Thu, 20 Oct 2022 02:03:19 -0700 (PDT) Received: from localhost.localdomain ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id c2-20020a17090618a200b007933047f923sm1668381ejf.118.2022.10.20.02.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:03:18 -0700 (PDT) From: Cosmin Tanislav Cc: =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v2 4/5] dt-bindings: iio: temperature: ltc2983: support more parts Date: Thu, 20 Oct 2022 12:02:56 +0300 Message-Id: <20221020090257.1717053-5-demonsingur@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221020090257.1717053-1-demonsingur@gmail.com> References: <20221020090257.1717053-1-demonsingur@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747197014174298103?= X-GMAIL-MSGID: =?utf-8?q?1747197014174298103?= From: Cosmin Tanislav Add support for the following parts: * LTC2984 * LTC2986 * LTM2985 The LTC2984 is a variant of the LTC2983 with EEPROM. The LTC2986 is a variant of the LTC2983 with only 10 channels, EEPROM and support for active analog temperature sensors. The LTM2985 is software-compatible with the LTC2986. Signed-off-by: Cosmin Tanislav --- .../bindings/iio/temperature/adi,ltc2983.yaml | 69 +++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml index 3e97ec841fd6..1cb31d896c9a 100644 --- a/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml +++ b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml @@ -4,19 +4,30 @@ $id: http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Analog Devices LTC2983 Multi-sensor Temperature system +title: Analog Devices LTC2983, LTC2986, LTM2985 Multi-sensor Temperature system maintainers: - Nuno Sá description: | - Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System + Analog Devices LTC2983, LTC2984, LTC2986, LTM2985 Multi-Sensor Digital + Temperature Measurement Systems + https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/2984fb.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/29861fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ltm2985.pdf properties: compatible: - enum: - - adi,ltc2983 + oneOf: + - enum: + - adi,ltc2983 + - adi,ltc2986 + - adi,ltm2985 + - items: + - const: adi,ltc2984 + - const: adi,ltc2983 reg: maxItems: 1 @@ -413,6 +424,44 @@ patternProperties: reg: minimum: 1 + "^temp@": + type: object + description: Active analog temperature sensor. + properties: + adi,sensor-type: + description: Sensor type for active analog temperature sensors. + $ref: /schemas/types.yaml#/definitions/uint32 + const: 31 + + adi,single-ended: + description: Whether the sensor is single-ended. + type: boolean + + adi,custom-temp: + description: + Used for digitizing active analog temperature sensors. + See Page 67 of the LTM2985 datasheet. + $ref: /schemas/types.yaml#/definitions/uint64-matrix + minItems: 3 + maxItems: 64 + items: + items: + - description: Voltage point in nV, signed. + - description: Temperature point in uK. + + required: + - adi,custom-temp + + allOf: + - if: + properties: + adi,single-ended: + const: true + then: + properties: + reg: + minimum: 1 + "^rsense@": type: object description: Sense resistor sensor. @@ -439,6 +488,18 @@ required: additionalProperties: false +allOf: + - if: + properties: + compatible: + contains: + enum: + - adi,ltc2983 + - adi,ltc2984 + then: + patternProperties: + "^temp@": false + examples: - | #include From patchwork Thu Oct 20 09:02:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 6065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp145996wrs; Thu, 20 Oct 2022 02:06:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+8QD55zW53sk4PYpjk1/jeSR6SQW9q92dXpksnxxvUWfFJbqrOJLrwn436i1z/tTUhYJF X-Received: by 2002:a17:907:3fa3:b0:78d:d11c:389f with SMTP id hr35-20020a1709073fa300b0078dd11c389fmr9972214ejc.415.1666256795684; Thu, 20 Oct 2022 02:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666256795; cv=none; d=google.com; s=arc-20160816; b=UIth2lw6Ph1HwbrJlq1WPnL3MHNvNgL+KTkFCJgQ2y2CO0xwvcYLAAiwgVflayeo4Z nLu0qhJtc44FHoDvimMe3JQb5ndVe2SyzBTNymv7vVje6k3D8aNG61NGMvZV8d7AFYp7 xilmJlzCaP6KZREIwnTcGMsPJDDhGDyTuuB6K/BoAtfUwMbG8unJRBay2KLChez4k7Ig 9o1vBvTl1WaITQzimKpy4smm6OZTvfw4S0hTW0WgT2sVZxLcHiFtP5kkXI8lu4Ad7ayO pYLDtGUqqC/vvCtc8sjr0xkZ9v8TKfJAhkE3XVGeWe6oXLKtGQZLVpZdTmpHDfnH3PUS 3LgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=H3SsMlRhgwbEjPjg3QxCE5Fj4HBuYWqOK4znVMfmmYI=; b=WF0LT4lMuVO56L1P4bPEZSWrSumPertRXJrr8CKuzyhlDS+1n0G29koV4jy1bCxItc JZeNbe0JQQIHyXNdC2zZGc4fTzU4zt1JhFDXs8JkMDv4ydpjYGnWKdZqvmWPo6CmXITP sF4BziMaoIz5yHLObpG1bOTs/7mRa+8Ty+t4d4i3hP5ndlCvw4KhvTBf+aaZ1RoI10qh EgeiHqvQY0dRD1k+LAhIytS5UKNsd00BSCEdayR2fMi402OHKQb2R+bxEIg8/1WWnJWO Ft6NITKyf9IZvk/7p9gWBRt2Yvmh2n1teqmOC2oStH34/UOb7uBV/PMYOur5TC258bLF uOtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=B3P3SRae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a1709064c8500b0078200f886bbsi16549801eju.361.2022.10.20.02.06.07; Thu, 20 Oct 2022 02:06:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=B3P3SRae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230477AbiJTJDr (ORCPT + 99 others); Thu, 20 Oct 2022 05:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230294AbiJTJDZ (ORCPT ); Thu, 20 Oct 2022 05:03:25 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9951197F88; Thu, 20 Oct 2022 02:03:22 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id y14so45750656ejd.9; Thu, 20 Oct 2022 02:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=H3SsMlRhgwbEjPjg3QxCE5Fj4HBuYWqOK4znVMfmmYI=; b=B3P3SRaebL/Z/Uk6EFvCZPxZD4MY8MeAoW7MYY5K4Q9mqR0ZVsIWsNim9SqnsKFu+j X9wSv7y8FM6PiEcZ9nc3ZBl6QysIBk4kcUb58DpVjmXZCRCouTEqf9BEATf/06h677Rc hSKlQH3mYF56f5Q4frXCOy9ESNEvGLtu2fVZ8oX7IOPGs/u599DyfQ7Guw8J0usN09no xoc/srZq9btCnKYhwj3eBG9Tz7s7k3+sKTYTCRjwR38VTjOTUFOcEWlnKYCPxy+vvSiI I728EGW/fWA5ruzqy0rOfckyxCBr0Xp470f7tzhonOL6NJtTR41RLQYDpYDoxHugQ9U2 ybGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=H3SsMlRhgwbEjPjg3QxCE5Fj4HBuYWqOK4znVMfmmYI=; b=k20ImL1Lfb81jgpVA9IcKs+BKyhEydT62PSy6/WOPvgyMYF8+nkwDA3ocECkvD4dj6 CQ/4Aiu5Ha1aWBF10M6wQfV/jx6u70R58H5Jf0x+KMW0BigAyGbAuMouluqw3TvhwFAl +gz9iaxMsBIjgHZ6rl5aOrZC0MGkEpCd9Fd8BUb1SicLXJUN8B2VdgVz5jY3n4YScI1D BHxMw4xdyhTy+zIdpxCfr9PQqK2K8jZ1XomA0W3dFlMlpjHB/mniZ+57BdjeciNXWlm1 FwyrMrSn8LaXpqlTtrWNT86sktueyaWtk7cYPDrfNU26xCzEk0mX+v6S7EmAGgRYVTQ6 GDjg== X-Gm-Message-State: ACrzQf2UBs8rg0llx3tWTlMO/6AaM4VuWJget78LCM2inyqBfOib9TVt hlx1zHieOw5YHWtpZYRn0pw= X-Received: by 2002:a17:906:cc4d:b0:78d:fb86:3979 with SMTP id mm13-20020a170906cc4d00b0078dfb863979mr10358396ejb.421.1666256600611; Thu, 20 Oct 2022 02:03:20 -0700 (PDT) Received: from localhost.localdomain ([5.2.194.157]) by smtp.gmail.com with ESMTPSA id c2-20020a17090618a200b007933047f923sm1668381ejf.118.2022.10.20.02.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:03:20 -0700 (PDT) From: Cosmin Tanislav Cc: =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v2 5/5] iio: temperature: ltc2983: support more parts Date: Thu, 20 Oct 2022 12:02:57 +0300 Message-Id: <20221020090257.1717053-6-demonsingur@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221020090257.1717053-1-demonsingur@gmail.com> References: <20221020090257.1717053-1-demonsingur@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747196886046744978?= X-GMAIL-MSGID: =?utf-8?q?1747196886046744978?= From: Cosmin Tanislav Add support for the following parts: * LTC2984 * LTC2986 * LTM2985 The LTC2984 is a variant of the LTC2983 with EEPROM. The LTC2986 is a variant of the LTC2983 with only 10 channels, EEPROM and support for active analog temperature sensors. The LTM2985 is software-compatible with the LTC2986. Signed-off-by: Cosmin Tanislav Reviewed-by: Nuno Sá --- drivers/iio/temperature/ltc2983.c | 183 ++++++++++++++++++++++++++++-- 1 file changed, 176 insertions(+), 7 deletions(-) diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index 1117991ca2ab..fcb96c44d954 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -25,9 +25,12 @@ #define LTC2983_STATUS_REG 0x0000 #define LTC2983_TEMP_RES_START_REG 0x0010 #define LTC2983_TEMP_RES_END_REG 0x005F +#define LTC2983_EEPROM_KEY_REG 0x00B0 +#define LTC2983_EEPROM_READ_STATUS_REG 0x00D0 #define LTC2983_GLOBAL_CONFIG_REG 0x00F0 #define LTC2983_MULT_CHANNEL_START_REG 0x00F4 #define LTC2983_MULT_CHANNEL_END_REG 0x00F7 +#define LTC2986_EEPROM_STATUS_REG 0x00F9 #define LTC2983_MUX_CONFIG_REG 0x00FF #define LTC2983_CHAN_ASSIGN_START_REG 0x0200 #define LTC2983_CHAN_ASSIGN_END_REG 0x024F @@ -35,13 +38,21 @@ #define LTC2983_CUST_SENS_TBL_END_REG 0x03CF #define LTC2983_DIFFERENTIAL_CHAN_MIN 2 -#define LTC2983_MAX_CHANNELS_NR 20 #define LTC2983_MIN_CHANNELS_NR 1 #define LTC2983_SLEEP 0x97 #define LTC2983_CUSTOM_STEINHART_SIZE 24 #define LTC2983_CUSTOM_SENSOR_ENTRY_SZ 6 #define LTC2983_CUSTOM_STEINHART_ENTRY_SZ 4 +#define LTC2983_EEPROM_KEY 0xA53C0F5A +#define LTC2983_EEPROM_WRITE_CMD 0x15 +#define LTC2983_EEPROM_READ_CMD 0x16 +#define LTC2983_EEPROM_STATUS_FAILURE_MASK GENMASK(3, 1) +#define LTC2983_EEPROM_READ_FAILURE_MASK GENMASK(7, 0) + +#define LTC2983_EEPROM_WRITE_TIME_MS 2600 +#define LTC2983_EEPROM_READ_TIME_MS 20 + #define LTC2983_CHAN_START_ADDR(chan) \ (((chan - 1) * 4) + LTC2983_CHAN_ASSIGN_START_REG) #define LTC2983_CHAN_RES_ADDR(chan) \ @@ -171,6 +182,7 @@ enum { LTC2983_SENSOR_DIODE = 28, LTC2983_SENSOR_SENSE_RESISTOR = 29, LTC2983_SENSOR_DIRECT_ADC = 30, + LTC2983_SENSOR_ACTIVE_TEMP = 31, }; #define to_thermocouple(_sensor) \ @@ -191,7 +203,17 @@ enum { #define to_adc(_sensor) \ container_of(_sensor, struct ltc2983_adc, sensor) +#define to_temp(_sensor) \ + container_of(_sensor, struct ltc2983_temp, sensor) + +struct ltc2983_chip_info { + unsigned int max_channels_nr; + bool has_temp; + bool has_eeprom; +}; + struct ltc2983_data { + const struct ltc2983_chip_info *info; struct regmap *regmap; struct spi_device *spi; struct mutex lock; @@ -210,6 +232,7 @@ struct ltc2983_data { */ __be32 temp __aligned(IIO_DMA_MINALIGN); __be32 chan_val; + __be32 eeprom_key; }; struct ltc2983_sensor { @@ -272,6 +295,12 @@ struct ltc2983_adc { bool single_ended; }; +struct ltc2983_temp { + struct ltc2983_sensor sensor; + struct ltc2983_custom_sensor *custom; + bool single_ended; +}; + /* * Convert to Q format numbers. These number's are integers where * the number of integer and fractional bits are specified. The resolution @@ -606,6 +635,22 @@ static int ltc2983_adc_assign_chan(struct ltc2983_data *st, return __ltc2983_chan_assign_common(st, sensor, chan_val); } +static int ltc2983_temp_assign_chan(struct ltc2983_data *st, + const struct ltc2983_sensor *sensor) +{ + struct ltc2983_temp *temp = to_temp(sensor); + u32 chan_val; + int ret; + + chan_val = LTC2983_ADC_SINGLE_ENDED(temp->single_ended); + + ret = __ltc2983_chan_custom_sensor_assign(st, temp->custom, &chan_val); + if (ret) + return ret; + + return __ltc2983_chan_assign_common(st, sensor, chan_val); +} + static struct ltc2983_sensor * ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data *st, const struct ltc2983_sensor *sensor) @@ -771,10 +816,10 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, if (rtd->sensor_config & LTC2983_RTD_4_WIRE_MASK) { /* 4-wire */ u8 min = LTC2983_DIFFERENTIAL_CHAN_MIN, - max = LTC2983_MAX_CHANNELS_NR; + max = st->info->max_channels_nr; if (rtd->sensor_config & LTC2983_RTD_ROTATION_MASK) - max = LTC2983_MAX_CHANNELS_NR - 1; + max = st->info->max_channels_nr - 1; if (((rtd->sensor_config & LTC2983_RTD_KELVIN_R_SENSE_MASK) == LTC2983_RTD_KELVIN_R_SENSE_MASK) && @@ -1143,6 +1188,38 @@ static struct ltc2983_sensor *ltc2983_adc_new(struct fwnode_handle *child, return &adc->sensor; } +static struct ltc2983_sensor *ltc2983_temp_new(struct fwnode_handle *child, + struct ltc2983_data *st, + const struct ltc2983_sensor *sensor) +{ + struct ltc2983_temp *temp; + + temp = devm_kzalloc(&st->spi->dev, sizeof(*temp), GFP_KERNEL); + if (!temp) + return ERR_PTR(-ENOMEM); + + if (fwnode_property_read_bool(child, "adi,single-ended")) + temp->single_ended = true; + + if (!temp->single_ended && + sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { + dev_err(&st->spi->dev, "Invalid chan:%d for differential temp\n", + sensor->chan); + return ERR_PTR(-EINVAL); + } + + temp->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-temp", + false, 4096, true); + if (IS_ERR(temp->custom)) + return ERR_CAST(temp->custom); + + /* set common parameters */ + temp->sensor.assign_chan = ltc2983_temp_assign_chan; + temp->sensor.fault_handler = ltc2983_common_fault_handler; + + return &temp->sensor; +} + static int ltc2983_chan_read(struct ltc2983_data *st, const struct ltc2983_sensor *sensor, int *val) { @@ -1302,10 +1379,10 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) /* check if we have a valid channel */ if (sensor.chan < LTC2983_MIN_CHANNELS_NR || - sensor.chan > LTC2983_MAX_CHANNELS_NR) { + sensor.chan > st->info->max_channels_nr) { ret = -EINVAL; dev_err(dev, "chan:%d must be from %u to %u\n", sensor.chan, - LTC2983_MIN_CHANNELS_NR, LTC2983_MAX_CHANNELS_NR); + LTC2983_MIN_CHANNELS_NR, st->info->max_channels_nr); goto put_child; } else if (channel_avail_mask & BIT(sensor.chan)) { ret = -EINVAL; @@ -1345,6 +1422,9 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) st->iio_channels--; } else if (sensor.type == LTC2983_SENSOR_DIRECT_ADC) { st->sensors[chan] = ltc2983_adc_new(child, st, &sensor); + } else if (st->info->has_temp && + sensor.type == LTC2983_SENSOR_ACTIVE_TEMP) { + st->sensors[chan] = ltc2983_temp_new(child, st, &sensor); } else { dev_err(dev, "Unknown sensor type %d\n", sensor.type); ret = -EINVAL; @@ -1371,6 +1451,45 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) return ret; } +static int ltc2983_eeprom_cmd(struct ltc2983_data *st, unsigned int cmd, + unsigned int wait_time, unsigned int status_reg, + unsigned long status_fail_mask) +{ + unsigned long time; + unsigned int val; + int ret; + + ret = regmap_bulk_write(st->regmap, LTC2983_EEPROM_KEY_REG, + &st->eeprom_key, sizeof(st->eeprom_key)); + if (ret) + return ret; + + reinit_completion(&st->completion); + + ret = regmap_write(st->regmap, LTC2983_STATUS_REG, + LTC2983_STATUS_START(true) | cmd); + if (ret) + return ret; + + time = wait_for_completion_timeout(&st->completion, + msecs_to_jiffies(wait_time)); + if (!time) { + dev_err(&st->spi->dev, "EEPROM command timed out\n"); + return -ETIMEDOUT; + } + + ret = regmap_read(st->regmap, status_reg, &val); + if (ret) + return ret; + + if (val & status_fail_mask) { + dev_err(&st->spi->dev, "EEPROM command failed: 0x%02X\n", val); + return -EINVAL; + } + + return 0; +} + static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) { u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status; @@ -1396,6 +1515,15 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) if (ret) return ret; + if (st->info->has_eeprom && !assign_iio) { + ret = ltc2983_eeprom_cmd(st, LTC2983_EEPROM_READ_CMD, + LTC2983_EEPROM_READ_TIME_MS, + LTC2983_EEPROM_READ_STATUS_REG, + LTC2983_EEPROM_READ_FAILURE_MASK); + if (!ret) + return 0; + } + for (chan = 0; chan < st->num_channels; chan++) { u32 chan_type = 0, *iio_chan; @@ -1435,9 +1563,13 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) static const struct regmap_range ltc2983_reg_ranges[] = { regmap_reg_range(LTC2983_STATUS_REG, LTC2983_STATUS_REG), regmap_reg_range(LTC2983_TEMP_RES_START_REG, LTC2983_TEMP_RES_END_REG), + regmap_reg_range(LTC2983_EEPROM_KEY_REG, LTC2983_EEPROM_KEY_REG), + regmap_reg_range(LTC2983_EEPROM_READ_STATUS_REG, + LTC2983_EEPROM_READ_STATUS_REG), regmap_reg_range(LTC2983_GLOBAL_CONFIG_REG, LTC2983_GLOBAL_CONFIG_REG), regmap_reg_range(LTC2983_MULT_CHANNEL_START_REG, LTC2983_MULT_CHANNEL_END_REG), + regmap_reg_range(LTC2986_EEPROM_STATUS_REG, LTC2986_EEPROM_STATUS_REG), regmap_reg_range(LTC2983_MUX_CONFIG_REG, LTC2983_MUX_CONFIG_REG), regmap_reg_range(LTC2983_CHAN_ASSIGN_START_REG, LTC2983_CHAN_ASSIGN_END_REG), @@ -1482,6 +1614,12 @@ static int ltc2983_probe(struct spi_device *spi) st = iio_priv(indio_dev); + st->info = device_get_match_data(&spi->dev); + if (!st->info) + st->info = (void *)spi_get_device_id(spi)->driver_data; + if (!st->info) + return -ENODEV; + st->regmap = devm_regmap_init_spi(spi, <c2983_regmap_config); if (IS_ERR(st->regmap)) { dev_err(&spi->dev, "Failed to initialize regmap\n"); @@ -1491,6 +1629,7 @@ static int ltc2983_probe(struct spi_device *spi) mutex_init(&st->lock); init_completion(&st->completion); st->spi = spi; + st->eeprom_key = cpu_to_be32(LTC2983_EEPROM_KEY); spi_set_drvdata(spi, st); ret = ltc2983_parse_dt(st); @@ -1524,6 +1663,15 @@ static int ltc2983_probe(struct spi_device *spi) return ret; } + if (st->info->has_eeprom) { + ret = ltc2983_eeprom_cmd(st, LTC2983_EEPROM_WRITE_CMD, + LTC2983_EEPROM_WRITE_TIME_MS, + LTC2986_EEPROM_STATUS_REG, + LTC2983_EEPROM_STATUS_FAILURE_MASK); + if (ret) + return ret; + } + indio_dev->name = name; indio_dev->num_channels = st->iio_channels; indio_dev->channels = st->iio_chan; @@ -1554,14 +1702,35 @@ static int ltc2983_suspend(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(ltc2983_pm_ops, ltc2983_suspend, ltc2983_resume); +static const struct ltc2983_chip_info ltc2983_chip_info_data = { + .max_channels_nr = 20, +}; + +static const struct ltc2983_chip_info ltc2984_chip_info_data = { + .max_channels_nr = 20, + .has_eeprom = true, +}; + +static const struct ltc2983_chip_info ltc2986_chip_info_data = { + .max_channels_nr = 10, + .has_temp = true, + .has_eeprom = true, +}; + static const struct spi_device_id ltc2983_id_table[] = { - { "ltc2983" }, + { "ltc2983", (kernel_ulong_t)<c2983_chip_info_data }, + { "ltc2984", (kernel_ulong_t)<c2984_chip_info_data }, + { "ltc2986", (kernel_ulong_t)<c2986_chip_info_data }, + { "ltm2985", (kernel_ulong_t)<c2986_chip_info_data }, {}, }; MODULE_DEVICE_TABLE(spi, ltc2983_id_table); static const struct of_device_id ltc2983_of_match[] = { - { .compatible = "adi,ltc2983" }, + { .compatible = "adi,ltc2983", .data = <c2983_chip_info_data }, + { .compatible = "adi,ltc2984", .data = <c2984_chip_info_data }, + { .compatible = "adi,ltc2986", .data = <c2986_chip_info_data }, + { .compatible = "adi,ltm2985", .data = <c2986_chip_info_data }, {}, }; MODULE_DEVICE_TABLE(of, ltc2983_of_match);