From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 D3D481D90B1 for ; Tue, 28 Jan 2025 17:31:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738085515; cv=none; b=U7tL3Pya/9ThEhnF/lkvrAXmV4J2Fs99YVKkUeJ3F5eBtKyJmK6Dpb+j7AceZtDCaibcqrtNomLPkWuBZgH62nzo0KxK9rnuP4F6ucnBCaWOGNiDfukC/jhTx6lGWIBnXbVcAN8B8BU7CkiAW81qdu2HgpQxXyDkkbdje7IhMdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738085515; c=relaxed/simple; bh=LU+XznUeXH5Q7W1JsPfuSa1yFz5ev1vlDsAe0VCGZlg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j3TyDVh7Gb5joaAERVgxlqY8prmpOUA+LAG8Y94BfzO1pdU4lrvhnhPkKZX60NGWTmSxg2DPYd5oDnvXZMJp6qT2cyFJwRcoDxYkBDj8gvl1emILv0iHa7ei1H49H6lwhEUrRPNn1I1RvN2HXGkR26fdWpbPJV660p68P54kZZE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=fwa97BDE; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fwa97BDE" Received: from isaac-ThinkPad-T16-Gen-2.lan (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 593FEF02; Tue, 28 Jan 2025 18:30:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1738085443; bh=LU+XznUeXH5Q7W1JsPfuSa1yFz5ev1vlDsAe0VCGZlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fwa97BDEZWlzH4SH1dtnpfFEvavDjQfQFG0SV4lHyPYwfS73nVPBuA83miIBshI0P 8Ws/0Ud0sDkNFy/P9K0vO+AlBVXO1iQgcdi6F6tnfvmHZusWdt6KEe/LgbMzeczr+Z 9aufvnVo8kDHyIeoVVE6h10MyHKHdQ4dZpKCcHiI= From: Isaac Scott To: michael.hennerich@analog.com Cc: lgirdwood@gmail.com, broonie@kernel.org, linux-kernel@vger.kernel.org, Isaac Scott Subject: [PATCH v2 2/3] RFC: regulator: ad5398: Change selector division calculation Date: Tue, 28 Jan 2025 17:31:42 +0000 Message-ID: <20250128173143.959600-3-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250128173143.959600-1-isaac.scott@ideasonboard.com> References: <20250128173143.959600-1-isaac.scott@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If the AD5398 is defined to have a current limit with no range, i.e. when max_Ua and min_Ua are equal, the DIV_ROUND_UP erroneously tries to set the current to a higher level than the max_Ua, which causes the driver to fail to set the current. Fix this so the driver slightly underestimates the current to set. Signed-off-by: Isaac Scott --- drivers/regulator/ad5398.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index e6f45c6e750c..0c60ecd1f0f2 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -98,8 +98,7 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int if (min_uA > chip->max_uA || max_uA < chip->min_uA) return -EINVAL; - selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, - range_uA); + selector = ((min_uA - chip->min_uA) * chip->current_level / range_uA); if (ad5398_calc_current(chip, selector) > max_uA) return -EINVAL; -- 2.43.0