From nobody Mon Feb 9 02:13:40 2026 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 743A01EEE6 for ; Tue, 28 Jan 2025 17:31:51 +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=1738085513; cv=none; b=SB9jpur11V4MVWtmUmGq8wEI8JiL5Hh9MQUkfYX5DyNtBrZ5fLff3L+aBfdfGj6PyE376y+wg/9ezkXeWPALymbB/4Nx9QLdQdSX5uP0OiKQ2TIHNSnCYihIvgTJS5YcZ8dQjRnGIvGkP0ESFr/nGBzaI3uBqTl7Spq6+iEjFZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738085513; c=relaxed/simple; bh=ZDh1rJ6zYSYKNTYDdyAwo+6D07MUtL73glHA++eQ7hU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VD2bZvjIK3/tQAmESOsULta66C1a7lUFj+kVrnGe29pa6weXVpb7AxvDrFFihNtjoVhhU86wyGYqqVuDdIWvydi58nrQqoKedMv9eNqRzcZwjk69ttHKD1kGJX8osvYg+Z4CSst8bXU3GTQWvvLZPgMfQLFWwr2a2yHVOSc48DU= 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=DZqjpQ2q; 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="DZqjpQ2q" 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 59480AB5; Tue, 28 Jan 2025 18:30:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1738085442; bh=ZDh1rJ6zYSYKNTYDdyAwo+6D07MUtL73glHA++eQ7hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DZqjpQ2q/oqc0ptGV6SGSpEEhcb3PEaBpCuZrn4bd7QFFnPICd96vSpdUsQGPnroV EY3ahbq+xz5ChFynup++nVvbCfs2rDf05YnqAFrteWsrIssfKvbdaE4zASz/ACWhqu 4u6zq4HYdKbgYJbaX1Unkrfh7xmlTr/6VNfLc4yA= 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 1/3] regulator: ad5398: change enable bit name to improve readibility Date: Tue, 28 Jan 2025 17:31:41 +0000 Message-ID: <20250128173143.959600-2-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: quoted-printable Content-Type: text/plain; charset="utf-8" The mask name AD5398_CURRENT_EN_MASK is misleading, as it implies that setting bit 16 of the AD5398 enables current flow. In fact, setting this bit prevents current flow, due to this bit being a software power down control. This bit is referred to as "soft power down" in the datasheet. As such, change the name of the bit and modify its use in the driver to make the regulator more intuitively usable. (When calling ad5398_enable, current will start flowing, and vice versa). Signed-off-by: Isaac Scott --- drivers/regulator/ad5398.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 40f7dba42b5a..e6f45c6e750c 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -15,7 +15,7 @@ #include #include =20 -#define AD5398_CURRENT_EN_MASK 0x8000 +#define AD5398_SW_POWER_DOWN BIT(16) =20 struct ad5398_chip_info { struct i2c_client *client; @@ -113,7 +113,7 @@ static int ad5398_set_current_limit(struct regulator_de= v *rdev, int min_uA, int =20 /* prepare register data */ selector =3D (selector << chip->current_offset) & chip->current_mask; - data =3D (unsigned short)selector | (data & AD5398_CURRENT_EN_MASK); + data =3D (unsigned short)selector | (data & AD5398_SW_POWER_DOWN); =20 /* write the new current value back as well as enable bit */ ret =3D ad5398_write_reg(client, data); @@ -132,10 +132,10 @@ static int ad5398_is_enabled(struct regulator_dev *rd= ev) if (ret < 0) return ret; =20 - if (data & AD5398_CURRENT_EN_MASK) - return 1; - else + if (data & AD5398_SW_POWER_DOWN) return 0; + else + return 1; } =20 static int ad5398_enable(struct regulator_dev *rdev) @@ -149,10 +149,10 @@ static int ad5398_enable(struct regulator_dev *rdev) if (ret < 0) return ret; =20 - if (data & AD5398_CURRENT_EN_MASK) + if (!(data & AD5398_SW_POWER_DOWN)) return 0; =20 - data |=3D AD5398_CURRENT_EN_MASK; + data &=3D ~AD5398_SW_POWER_DOWN; =20 ret =3D ad5398_write_reg(client, data); =20 @@ -170,10 +170,10 @@ static int ad5398_disable(struct regulator_dev *rdev) if (ret < 0) return ret; =20 - if (!(data & AD5398_CURRENT_EN_MASK)) + if (data & AD5398_SW_POWER_DOWN) return 0; =20 - data &=3D ~AD5398_CURRENT_EN_MASK; + data |=3D AD5398_SW_POWER_DOWN; =20 ret =3D ad5398_write_reg(client, data); =20 --=20 2.43.0 From nobody Mon Feb 9 02:13:40 2026 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: quoted-printable Content-Type: text/plain; charset="utf-8" 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; =20 - selector =3D DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, - range_uA); + selector =3D ((min_uA - chip->min_uA) * chip->current_level / range_uA); if (ad5398_calc_current(chip, selector) > max_uA) return -EINVAL; =20 --=20 2.43.0 From nobody Mon Feb 9 02:13:40 2026 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 D15FD1DE4F9 for ; Tue, 28 Jan 2025 17:31:54 +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=1738085516; cv=none; b=H94Du3cct2quEKccOQuS7Ul/u9ArxvEPKka0mKxqdJL30SY3dPPmwpajiGWOo4DC4lTtkPA/h9+f+jQOoVxkBvJHlIHmfUoiPGkg/f0GLn7R6FGhHtm12NZOmhPknv/OdPU95VFI47rmDnr6gvL7Xj5mxaAd/kXHQY0Yga290cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738085516; c=relaxed/simple; bh=PyR/S0tgIuQRKHj3akh42/2D1m+YvBfkaDyKrG7X7/o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6p39BXAttaA7esj9XDHJpMOxUVxU4PISOnchxGGAHGOr9wGNQbu4HgTSsN0h/AMoRjw15iUz74una2neR9Tw9X2p6Zm91M6YO5khxV4A7KyWR1Jzcsy5xvGkbqDAuS4mMFFhvlAnQwmj0to05MJUzJHjtEMad6VinswPD5KNWw= 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=Hue4+izK; 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="Hue4+izK" 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 491511054; Tue, 28 Jan 2025 18:30:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1738085444; bh=PyR/S0tgIuQRKHj3akh42/2D1m+YvBfkaDyKrG7X7/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hue4+izKT71eoteMz2pjxvJSMULfvi2sBoZcExQHNgYywxPas5KEoeLVkjsH+Q8YC hmPgoL0y1WYU6BU7FXJDGU8GQ8uzUMfJDh1B9XVA7wcfZJs3cyD7J5uqPs+eaE955s 8iGCd1j1Fv1C7ttN4K6zzdegFuqreCnPquRyWnjA= 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 3/3] regulator: ad5398: Add device tree support Date: Tue, 28 Jan 2025 17:31:43 +0000 Message-ID: <20250128173143.959600-4-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: quoted-printable Content-Type: text/plain; charset="utf-8" Previously, the ad5398 driver used only platform_data, which is deprecated in favour of device tree. This caused the AD5398 to fail to probe as it could not load its init_data. If the AD5398 has a device tree node, pull the init_data from there using of_get_regulator_init_data. Signed-off-by: Isaac Scott --- drivers/regulator/ad5398.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 0c60ecd1f0f2..619c999946f3 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 #define AD5398_SW_POWER_DOWN BIT(16) =20 @@ -220,15 +221,20 @@ static int ad5398_probe(struct i2c_client *client) const struct ad5398_current_data_format *df =3D (struct ad5398_current_data_format *)id->driver_data; =20 - if (!init_data) - return -EINVAL; - chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; =20 config.dev =3D &client->dev; + if (client->dev.of_node) + init_data =3D of_get_regulator_init_data(&client->dev, + client->dev.of_node, + &ad5398_reg); + if (!init_data) + return -EINVAL; + config.init_data =3D init_data; + config.of_node =3D client->dev.of_node; config.driver_data =3D chip; =20 chip->client =3D client; --=20 2.43.0