From patchwork Fri Oct 6 00:50:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 149074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp11969vqo; Thu, 5 Oct 2023 17:53:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFflr/mXC0pScKKgfu/syoxtrWNMCB1tJkGek/yqNeUdfBuDn0Niamo5J8BuKdYh/qClH0l X-Received: by 2002:a05:6358:440a:b0:135:3f5c:9675 with SMTP id z10-20020a056358440a00b001353f5c9675mr7038650rwc.19.1696553595248; Thu, 05 Oct 2023 17:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696553595; cv=none; d=google.com; s=arc-20160816; b=fuPRoTfE3ncisZ8Fk+L8MTxpc/2jD0z662a7S7pJE8u0qg5zsDRxHw78vGzVFuZ/OV zTLhdWCf/mgJKeoUTQMOYsjIFF9fenHY9weMcc5onT9xRJCMaClG3v8CuSs1ToSxopbi 4TGoVLmlre7MwJBZLB8npjzeDACCboujEqArHScqb3Q3+NlYj7set6mZcvB07HPhOccs WwnxwcZBgOvytJBmJ3y83ny/RIpmf/T/R31tibHWL9XFdyKCXCWvyW8MdQi3RkjAq0L+ t7jdV84VqySONU15imr7b/vTl5kOQhhE5HvRGMOCD+rObdyllJ+FGDL65LPI7cU5pmH0 luvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X2efrAvqiPu7nPX2fJ+YIXWQO7bvmVd6GU0zDZ4vqNY=; fh=kszEk+gff9dv1Go/VyZgnfqxXXEwVKycZ4FkCeISyE4=; b=puwLrWb+3AbXKcT3Pp5eoE0liYDNvUWZ5a9Ed3NrEV7N3IbBjEjQAqN4+QtC2QOaRi WjGTrvmyFkSGQ2dBGivpKKXqhjuSR6rYjRLxK/CkvYUqSue8Aje3yAtzyZEXzzX6jl3p ACyrrQVmMGnZ2vzTImCMMjvZFj+UKHTZu8S0kLO3ij59SEqO1SHQRJ3PATVScF0bM8FS Z4MkNzLkk4T8160bVTHo/ZTVwLzMUrIP5bayKI996ZGeL3LSrAN7Yicnzm43UgKRSmmr blV/6G2k/yQ9YK5ACniZSISAa79udLXFmuqlXsl8nCZ4jq+TDL4JH/I/kAeMa8iwDE0k QD8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=rVb2mV1t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id lr17-20020a17090b4b9100b0026ce877b4cbsi4912599pjb.151.2023.10.05.17.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 17:53:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=rVb2mV1t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5FBEB8085994; Thu, 5 Oct 2023 17:53:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229901AbjJFAvi (ORCPT + 18 others); Thu, 5 Oct 2023 20:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbjJFAvR (ORCPT ); Thu, 5 Oct 2023 20:51:17 -0400 Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697C9FC for ; Thu, 5 Oct 2023 17:51:13 -0700 (PDT) Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1dd54aca17cso1115018fac.3 for ; Thu, 05 Oct 2023 17:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1696553472; x=1697158272; darn=vger.kernel.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=X2efrAvqiPu7nPX2fJ+YIXWQO7bvmVd6GU0zDZ4vqNY=; b=rVb2mV1t5s47XuyCgfBTxeZDZGTfV69r5rwdRLuqqwqErNwgo4j8n1vCI9Gjl0U97U 3/cWiD6aOAmzfWLnnPfYjNbdQxi4ESTtXojF+MfsszaXpHpwiWmujQsCfJdKnUeHNrof NlYhMqumzw+gzn0Kg1GJYSXuZTj8/Q8365CkzfPO3FEnEUiphj2GMbODaD/bfJzOOPXk 1I+ect8Yr8WG8d9wEuZi9FQhhct7vattrrTT3PfTJXzgzfftHqF/q0NAgcmbDZSXSIKO ilrSPvQGlIWjRJPrexcO9fI0zbb6L14FZUfkXQIsly4K+GVhGRQA02Lta4RjOpLDNrjC 1sKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696553472; x=1697158272; 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=X2efrAvqiPu7nPX2fJ+YIXWQO7bvmVd6GU0zDZ4vqNY=; b=KqVdnemcc5QZOOmH7iNpyNqnfYtN4mYC4LTsFqvhWc2gzgeYe1loaVsIsNxrAxYIhL EXPA74pALkvG+usdVVYvJW7pOke4Ixj3BnMXPGkH+G71Hxyr8P4KaC0cN5Rhkfd1Rbyu dHNX5Hz3cFmZLzCnaqn2fKQnBmtks/1o7DpfFZXuDVHyZ4rpciGxwsFlW5K6oGt21t3u OExte7ntnZq4o+6oVyzwFXdkjiduAwTf6mJkCsRUDWtR9Tovdv6Ntt1l3CFEbfYjywjV OoC1t4t6P/rroNecjo48M3iAnzJ9cCoz2v/f9heZoiB1VFPHPjjHHeaX/cDYAPrv0MCD XiQA== X-Gm-Message-State: AOJu0YztOPrjK1n0KsJfbiEYoDiCQfLAdh092o/em0sOGE5KtYuQKk0b sVYywCQtyUCfE514b4b7p07/2A== X-Received: by 2002:a05:6871:14c:b0:1e1:8591:3f3 with SMTP id z12-20020a056871014c00b001e1859103f3mr7646969oab.41.1696553472739; Thu, 05 Oct 2023 17:51:12 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id mo9-20020a056871320900b001dd0ff401edsm545072oac.51.2023.10.05.17.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 17:51:12 -0700 (PDT) From: David Lechner To: linux-iio@vger.kernel.org, linux-staging@lists.linux.dev Cc: David Lechner , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Axel Haslam , Philip Molloy , linux-kernel@vger.kernel.org Subject: [PATCH v4 10/17] staging: iio: resolver: ad2s1210: convert DOS mismatch threshold to event attr Date: Thu, 5 Oct 2023 19:50:27 -0500 Message-ID: <20231005-ad2s1210-mainline-v4-10-ec00746840fc@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231005-ad2s1210-mainline-v4-0-ec00746840fc@baylibre.com> References: <20231005-ad2s1210-mainline-v4-0-ec00746840fc@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 05 Oct 2023 17:53:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778965382703316613 X-GMAIL-MSGID: 1778965382703316613 The AD2S1210 has a programmable threshold for the degradation of signal (DOS) mismatch fault. This fault is triggered when the difference in voltage between the sine and cosine inputs exceeds the threshold. In other words, when the magnitude of sine and cosine inputs are equal, the AC component of the monitor signal is zero and when the magnitudes of the sine and cosine inputs are not equal, the AC component of the monitor signal is the difference between the sine and cosine inputs. So the fault occurs when the magnitude of the AC component of the monitor signal exceeds the DOS mismatch threshold voltage. This patch converts the custom device DOS mismatch threshold attribute to an event magnitude attribute on the monitor signal channel. The attribute now uses millivolts instead of the raw register value in accordance with the IIO ABI. Emitting the event will be implemented in a later patch. Signed-off-by: David Lechner --- v4 changes: * Changed event direction from none to rising. * Fixed missing static qualifier on attribute definition. v3 changes: This is a new patch in v3 drivers/staging/iio/resolver/ad2s1210.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 3c224bbeae17..870c4a9a6214 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -747,9 +747,6 @@ static int ad2s1210_write_raw(struct iio_dev *indio_dev, static IIO_DEVICE_ATTR(fault, 0644, ad2s1210_show_fault, ad2s1210_clear_fault, 0); -static IIO_DEVICE_ATTR(dos_mis_thrd, 0644, - ad2s1210_show_reg, ad2s1210_store_reg, - AD2S1210_REG_DOS_MIS_THRD); static IIO_DEVICE_ATTR(dos_rst_max_thrd, 0644, ad2s1210_show_reg, ad2s1210_store_reg, AD2S1210_REG_DOS_RST_MAX_THRD); @@ -795,6 +792,12 @@ static const struct iio_event_spec ad2s1210_monitor_signal_event_spec[] = { /* Degredation of signal overrange threshold. */ .mask_separate = BIT(IIO_EV_INFO_VALUE), }, + { + /* Sine/cosine DOS mismatch fault.*/ + .type = IIO_EV_TYPE_MAG, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE), + }, }; static const struct iio_chan_spec ad2s1210_channels[] = { @@ -868,7 +871,6 @@ static const struct iio_chan_spec ad2s1210_channels[] = { static struct attribute *ad2s1210_attributes[] = { &iio_dev_attr_fault.dev_attr.attr, - &iio_dev_attr_dos_mis_thrd.dev_attr.attr, &iio_dev_attr_dos_rst_max_thrd.dev_attr.attr, &iio_dev_attr_dos_rst_min_thrd.dev_attr.attr, NULL, @@ -909,6 +911,8 @@ static IIO_CONST_ATTR(in_altvoltage0_thresh_falling_value_available, THRESHOLD_RANGE_STR); static IIO_CONST_ATTR(in_altvoltage0_thresh_rising_value_available, THRESHOLD_RANGE_STR); +static IIO_CONST_ATTR(in_altvoltage0_mag_rising_value_available, + THRESHOLD_RANGE_STR); static IIO_DEVICE_ATTR_RO(in_angl1_thresh_rising_value_available, 0); static IIO_DEVICE_ATTR_RO(in_angl1_thresh_rising_hysteresis_available, 0); @@ -916,6 +920,7 @@ static struct attribute *ad2s1210_event_attributes[] = { &iio_const_attr_in_phase0_mag_rising_value_available.dev_attr.attr, &iio_const_attr_in_altvoltage0_thresh_falling_value_available.dev_attr.attr, &iio_const_attr_in_altvoltage0_thresh_rising_value_available.dev_attr.attr, + &iio_const_attr_in_altvoltage0_mag_rising_value_available.dev_attr.attr, &iio_dev_attr_in_angl1_thresh_rising_value_available.dev_attr.attr, &iio_dev_attr_in_angl1_thresh_rising_hysteresis_available.dev_attr.attr, NULL, @@ -977,6 +982,9 @@ static int ad2s1210_read_event_value(struct iio_dev *indio_dev, if (type == IIO_EV_TYPE_THRESH && dir == IIO_EV_DIR_RISING) return ad2s1210_get_voltage_threshold(st, AD2S1210_REG_DOS_OVR_THRD, val); + if (type == IIO_EV_TYPE_MAG) + return ad2s1210_get_voltage_threshold(st, + AD2S1210_REG_DOS_MIS_THRD, val); return -EINVAL; case IIO_PHASE: return ad2s1210_get_phase_lock_range(st, val, val2); @@ -1013,6 +1021,9 @@ static int ad2s1210_write_event_value(struct iio_dev *indio_dev, if (type == IIO_EV_TYPE_THRESH && dir == IIO_EV_DIR_RISING) return ad2s1210_set_voltage_threshold(st, AD2S1210_REG_DOS_OVR_THRD, val); + if (type == IIO_EV_TYPE_MAG) + return ad2s1210_set_voltage_threshold(st, + AD2S1210_REG_DOS_MIS_THRD, val); return -EINVAL; case IIO_PHASE: return ad2s1210_set_phase_lock_range(st, val, val2);