Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp660342lqb; Wed, 29 May 2024 07:07:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXm6Q/1bRfoTuUghQEUFYWKXScbdsCtJe25VsOmzFsdCahw2JVZPMAyToE/jN1ujD9N+ONb7Wc4khCrrB+Sb4tuynqc7o+Q3qBpEJBhTg== X-Google-Smtp-Source: AGHT+IGCXY9WHxnx23lem9dyaN71GgLtOZuetNW4q6dJNmuSsSmggle8x8jEdr1OjP0ruDxridzO X-Received: by 2002:a19:5e59:0:b0:52a:f341:2026 with SMTP id 2adb3069b0e04-52af34122dfmr1108808e87.57.1716991652125; Wed, 29 May 2024 07:07:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716991652; cv=pass; d=google.com; s=arc-20160816; b=qXFDl4NgHS61ESzCPiIKkyPDbHBBjxCMBM9Ge+1UfkDvG8DOHVFEbK6RbWklrbWAia ijPJkq3Q7GkPzYjOA4eEx3hnPjjKuXXw+3UHj3Pt1Qeim1AFnjR6bgWFq0fFmO+RztWC 2C+hxjHgUsgSGxr5F7MkJD2vC3QSFwXxOgxMSpsa9+rQUCi/+OBFVfSRJkU7Rv4YOWAp kA8WG6ezmPXACTBsZmNI528Cb133wfJo2BWrXsoLrtKyh5oXAW0bASUZFMb2465seNxI ok4yj6/aLOoexwdRgWnYUThOdSNykSzo3wDJMAh/g2BPm/krmBun7yC++qJnpmVTmdXP 2e4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :sender:dkim-signature; bh=2ZzzbwW0Sya6qTFwpCKnB6KXP4SAHrttnB1q+QFBqeU=; fh=h4gvHm9EH6hF5ucXZCPweVUwH5P5/0jOwsBlntgP1us=; b=cxJ8UVcEub78ADT02wuCgjPVk8ZVCSmT6/U69PuSK6I8Zr87Jf6n12kFDAlfjpvUkt OYxgLHXdNVibbyggFkCECB1w+cxPavnCrh3NiWbfIb0y/2raQTkC4x3I9ETSOJpgwmgZ ZYSKRYHAp8y2H6awnWE5V4UF1pIeXGl4G1ZMF2rSglclP+IrGrWZJzDOm56GOc16uE/c Qex6PUT0ypUDuMaRuQKCiB5/Fq/F2+t9DWdHQvf9ZHYu2YSjs1kaX8ydlmmxbmeXvksc 5jpbXqqER6YcNnKYwgJ/0c6f/j2MUTvtPkyUpXt/17ntlNGoZ4/h1nejyC9fP+xNcB4o XwmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Vst+Qvzu; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-194231-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194231-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-578524d1ae6si6414797a12.619.2024.05.29.07.07.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194231-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Vst+Qvzu; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-194231-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194231-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A6F9F1F25309 for ; Wed, 29 May 2024 14:07:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4B871D54F; Wed, 29 May 2024 14:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vst+Qvzu" Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 497124C83; Wed, 29 May 2024 14:07:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716991641; cv=none; b=NCPvTVNhZRQ33gcSCf8cuK8GVAnetIgjBmVB3nzYp2vlzmmpz71hu1xmWkMyAH+nlkfu5sD0y7FRNuo+dKrsfnkISRZQj496X915zcPPatM734oE79d/fxAb5DaijCjH4uyGRAoVtg7VDnS21XqADLHTbaTrvhiW4eeLD1c/W2w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716991641; c=relaxed/simple; bh=8aAQl6vo/460yrxhxt6zDyqiOWfsxNKRVIOR41neUFs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tKFbqQyBudaAsZbCj8tiwpf+OQKjgqZ2THryT1I7TFVXPWbFVWMBXcpwdXeEFV9xzSb0mMAekQ18M4jagn6mAj20oiHSlIN6oOGqgpmvSyDYg2rCaPJQr7uq9HvstCnUDuE/2nQ+e39mMbU7H1hhzufSImBkbagFBzm2/Z5UwEU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vst+Qvzu; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2c034b016e6so478997a91.2; Wed, 29 May 2024 07:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991639; x=1717596439; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:from:to:cc:subject:date:message-id:reply-to; bh=2ZzzbwW0Sya6qTFwpCKnB6KXP4SAHrttnB1q+QFBqeU=; b=Vst+QvzuJ7WQHRViSfomiloDSyU+15VUhfGtrjTHjOl2uU8prok9I7tcTLES0uAqsC ktoA43Pn0rBwIdgUkz11H/DfBFc+bz/hH9u03kWUi8jwfvwM9yfUBQHrT19CB9KQTjhg dHcNhNbukJRTzKKAmAUxiI10xGyGq7YgDdYSiHhQRlJBqSjWVwrg7jDpjB6SBg+HA+QT 17X4h3ymmQ6Q1AHMt4vnqH6Oan7lZm1Zr+QhsxMmdahKcjiZtNtZrsiibhXhxyxgPyr6 0FeegoMAtniray3az5cv3+SgAqalBPFOsHi0LaZxoJZFMbo4oCVGtXAl5xkUwxo9WxY4 tLtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991639; x=1717596439; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2ZzzbwW0Sya6qTFwpCKnB6KXP4SAHrttnB1q+QFBqeU=; b=HYV+qCFvhotRsR5BOQVJ5a7IzrwR8ZVrLIH9T2hFwp2yPfBhk1iMgl0KLkkHGKw7EH XTqN+tft3x+ExLpOilNQAZVhhMVr15WKynrnGELx3K/HAc7LkakhkDxaxfbJ/hczKeyC F/l4qFKKfzVolW2LhYMUnf+DhcBCF+RPJi2GkGKnt+gtq41dsRgMvg9iOa6i2wHI/cA/ AG4yoz8UfCdaL8hnukOVFbaZ6A74DJRkpjh16AtXLEoqoy7eCclqhSBJuL+U7bt+ce8B GEft+UFV+dEGLFtHTk0Up798EEH/3ucn5uOk14llP0ocqzhRXfRLwPNK/GMDjN2WBeuy svAQ== X-Forwarded-Encrypted: i=1; AJvYcCUFUXoZfIK0RljAzWfSAjBPv1IDIjptXKVySqo8dMOmteXa0mahpLSTT03Zo5gikkFd64fFbHOZcsIqj6qUMQrlwvK0+lRAkqysJihuFZSPEFxsr9QamKW9yHu/U203KwGRytEX94HCYTAQg3ocrf/JpttiLeDidD59rUY06TY5V4vq1wo1 X-Gm-Message-State: AOJu0YwNqT0XhBEJ4XhtNb7xcPT0Qbygurs2MJP+5jiYh3bg8mfpMRZK /VlOiPDrvkhcreG5+rILy3aNRtQptnW0HsUpjPLxKZQ9zQpqayg+lIvTxQ== X-Received: by 2002:a17:90b:1046:b0:2bd:d6c3:2430 with SMTP id 98e67ed59e1d1-2bf5f1081b1mr14089429a91.40.1716991639252; Wed, 29 May 2024 07:07:19 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:329c:23ff:fee3:9d7c? ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2bf57720f19sm9852521a91.56.2024.05.29.07.07.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 07:07:18 -0700 (PDT) Sender: Guenter Roeck Message-ID: <6f2d2e7e-99b4-4f5d-a2c5-523b5534917b@roeck-us.net> Date: Wed, 29 May 2024 07:07:17 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] hwmon: (ina2xx) Add device tree support to pass alert polarity To: Amna Waseem , Jean Delvare , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Krzysztof Kozlowski , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@axis.com References: <20240529-apol-ina2xx-fix-v1-0-77b4b382190f@axis.com> <20240529-apol-ina2xx-fix-v1-2-77b4b382190f@axis.com> Content-Language: en-US From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+hVL2Prf8xrXuZe1CMS7ID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PSk1J64R8O3HjSLdertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= In-Reply-To: <20240529-apol-ina2xx-fix-v1-2-77b4b382190f@axis.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/28/24 23:07, Amna Waseem wrote: > The INA230 has an Alert pin which is asserted when the alert > function selected in the Mask/Enable register exceeds the > value programmed into the Alert Limit register. Assertion is based > on the Alert Polarity Bit (APOL, bit 1 of the Mask/Enable register). > It is default set to value 0 i.e Normal (active-low open collector). > However, hardware can be designed in such a way that expects Alert pin > to become active high if a user-defined threshold in Alert limit > register has been exceeded. This patch adds a way to pass alert polarity > value to the driver via device tree. > > Signed-off-by: Amna Waseem > --- > drivers/hwmon/ina2xx.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c > index d8415d1f21fc..b58e795bdc8f 100644 > --- a/drivers/hwmon/ina2xx.c > +++ b/drivers/hwmon/ina2xx.c > @@ -73,6 +73,9 @@ > #define INA226_READ_AVG(reg) (((reg) & INA226_AVG_RD_MASK) >> 9) > #define INA226_SHIFT_AVG(val) ((val) << 9) > > +#define INA226_ALERT_POLARITY_MASK 0x0002 > +#define INA226_SHIFT_ALERT_POLARITY(val) ((val) << 1) > + > /* bit number of alert functions in Mask/Enable Register */ > #define INA226_SHUNT_OVER_VOLTAGE_BIT 15 > #define INA226_SHUNT_UNDER_VOLTAGE_BIT 14 > @@ -178,6 +181,23 @@ static u16 ina226_interval_to_reg(int interval) > return INA226_SHIFT_AVG(avg_bits); > } > > +static int ina2xx_set_alert_polarity(struct ina2xx_data *data, > + unsigned long val) > +{ > + int ret; > + > + if (val > INT_MAX || !(val == 0 || val == 1)) if (val != 0 && val !=1) would be sufficient and much easier to understand. > + return -EINVAL; > + > + mutex_lock(&data->config_lock); Pointless lock. > + ret = regmap_update_bits(data->regmap, INA226_MASK_ENABLE, > + INA226_ALERT_POLARITY_MASK, > + INA226_SHIFT_ALERT_POLARITY(val)); > + > + mutex_unlock(&data->config_lock); > + return ret; > +} > + > /* > * Calibration register is set to the best value, which eliminates > * truncation errors on calculating current register in hardware. > @@ -659,6 +679,14 @@ static int ina2xx_probe(struct i2c_client *client) > if (ret) > return dev_err_probe(dev, ret, "failed to enable vs regulator\n"); > > + if (!of_property_read_u32(dev->of_node, "alert-polarity", &val)) { > + ret = ina2xx_set_alert_polarity(data, val); > + if (ret < 0) > + return dev_err_probe( > + dev, ret, > + "failed to set APOL bit of Enable/Mask register\n"); > + } INA219 and INA220 do not support alert pin configuration (or, naturally, the mask register in the first place). This will need to be validated. Guenter