From patchwork Mon Jan 27 15:11:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Santos X-Patchwork-Id: 13951526 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5549213959D; Mon, 27 Jan 2025 15:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737990697; cv=none; b=oYsuVMkE3RvcXscF5MLGY3ZnV/drxDu77XOiNuTQxgf3afJoeAhlWsBsbenPiitnQufLKYPAbp7NLi8K9nraqlexJAqYLEN+wlXOIoTcTYRiwydj2XPAeP9z7gM85sLT1s1Xbfyg8b/lUW3rd7dX7H7IhRumGIs47l+ZBi25XFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737990697; c=relaxed/simple; bh=qOYcTGQB9wTnJxpMb02AAig2CDcgutp1313sBJKzN8w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I7yfwU3gmx4IPj6iDa+iAR871ZGh7cKhneaUafKBW2X+PHzwRUlXcuObHm4iUMlUCHfnO0aQ0RDNPWhdCa6ATkRcEYT1+q36qkddpIUUmTNp2n0O6Rt7i1CpgMKl20OBt0R+vWD9ljxJv3hZWe7oAHRAYN4nH1bPEue6944L+Ww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=D3XWmDNu; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="D3XWmDNu" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50RDWCXb005707; Mon, 27 Jan 2025 10:11:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=n35zO GD7GuLNZpWxs0SR7wJS1RQieHw/nDhVhHgJtLw=; b=D3XWmDNu3R85l6TRYn4OA coMNMciHs5aKEHsHJ3dJWuT4Xsc/UuQUV6hT87dVpxhHVM+AK/gBEKsDohnHWb32 M+TQFg9s/VB3cdb1IDy3vp7x4KIO57XntbuU/vEDOYaZAie8rZxLvz5AqobovhGz gSBirYHSt4gh5k43jUKRU6Eg1S42YpnZzVOb1gMlRsqoKsuMX/p+oFwt0v0ziVvq CNLrxD3oggHuhEZIm+l+az48uVRURu7XM+K4RwwCRefgkuJTujNk1lrY1pzkHaIq TjdMBZ2+u8v80Pp0j7iJ/vA5DLepCwlsul6Cx6+mQWhDF/FWtv55CqaEN4/YBgEV Q== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 44eb44gdbp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 10:11:19 -0500 (EST) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 50RFBI5h038378 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Jan 2025 10:11:18 -0500 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Mon, 27 Jan 2025 10:11:17 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Mon, 27 Jan 2025 10:11:17 -0500 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 50RFB1YI008230; Mon, 27 Jan 2025 10:11:04 -0500 From: Jonathan Santos To: , , CC: Sergiu Cuciurean , , , , , , , , , , David Lechner Subject: [PATCH v2 01/16] iio: adc: ad7768-1: Fix conversion result sign Date: Mon, 27 Jan 2025 12:11:01 -0300 Message-ID: <64e32c0ac7357ca7ddea813ba932bf957cbbeca2.1737985435.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: Jwbk1u7J0A78YqJB3PX5SIinIc5GXktY X-Proofpoint-GUID: Jwbk1u7J0A78YqJB3PX5SIinIc5GXktY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_07,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 adultscore=0 suspectscore=0 clxscore=1011 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501270121 From: Sergiu Cuciurean The ad7768-1 ADC output code is two's complement, meaning that the voltage conversion result is a signed value.. Since the value is a 24 bit one, stored in a 32 bit variable, the sign should be extended in order to get the correct representation. Also the channel description has been updated to signed representation, to match the ADC specifications. Fixes: a5f8c7da3dbe ("iio: adc: Add AD7768-1 ADC basic support") Reviewed-by: David Lechner Reviewed-by: Marcelo Schmitt Signed-off-by: Sergiu Cuciurean --- v2 Changes: * Patch moved to the start of the patch series. --- drivers/iio/adc/ad7768-1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index 113703fb7245..c3cf04311c40 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -142,7 +142,7 @@ static const struct iio_chan_spec ad7768_channels[] = { .channel = 0, .scan_index = 0, .scan_type = { - .sign = 'u', + .sign = 's', .realbits = 24, .storagebits = 32, .shift = 8, @@ -371,7 +371,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, ret = ad7768_scan_direct(indio_dev); if (ret >= 0) - *val = ret; + *val = sign_extend32(ret, chan->scan_type.realbits - 1); iio_device_release_direct_mode(indio_dev); if (ret < 0)