mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Leo Yang <leo.yang.sy0@gmail.com>,
	jdelvare@suse.com, linux@roeck-us.net, robh@kernel.org,
	davem@davemloft.net, krzk+dt@kernel.org, conor+dt@kernel.org,
	Leo-Yang@quantatw.com, corbet@lwn.net,
	Delphine_CC_Chiu@Wiwynn.com, linux-hwmon@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH v2 2/2] hwmon: Add driver for TI INA232 Current and Power Monitor
Date: Fri, 10 Jan 2025 22:19:02 +0100	[thread overview]
Message-ID: <dc0bba60-72e1-46a5-a341-a2aa30095042@wanadoo.fr> (raw)
In-Reply-To: <20250110081546.61667-3-Leo-Yang@quantatw.com>

 > Re: [PATCH v2 2/2] hwmon: Add driver for TI INA232 Current and Power 
Monitor

Should the subject be INA233?


Le 10/01/2025 à 09:15, Leo Yang a écrit :
> Support ina233 driver for Meta Yosemite V4.
> 
> Driver for Texas Instruments INA233 Current and Power Monitor
> With I2C-, SMBus-, and PMBus-Compatible Interface
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202501092213.X9mbPW5Q-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202501061734.nPNdRKqO-lkp@intel.com/
> Signed-off-by: Leo Yang <Leo-Yang@quantatw.com>

...

> +static void calculate_coef(int *m, int *R, int power_coef)
> +{
> +	s64 scaled_m;
> +	int scale_factor = 0;
> +	int scale_coef = 1;
> +	bool is_integer = false;

Is is_integer really needed?

See below.

> +
> +	/*
> +	 * 1000000 from Current_LSB A->uA .
> +	 * scale_coef is for scaling up to minimize rounding errors,
> +	 * If there is no decimal information, No need to scale.
> +	 */
> +	if (1000000 % *m) {
> +		/* Scaling to keep integer precision */
> +		scale_factor = -3;
> +		scale_coef = 1000;
> +	} else {
> +		is_integer = true;
> +	}
> +
> +	/*
> +	 * Unit Conversion (Current_LSB A->uA) and use scaling(scale_factor)
> +	 * to keep integer precision.
> +	 * Formulae referenced from spec.
> +	 */
> +	scaled_m = div_s64(1000000 * scale_coef, *m * power_coef);
> +
> +	/* Maximize while keeping it bounded.*/
> +	while (scaled_m > MAX_M_VAL || scaled_m < MIN_M_VAL) {
> +		scaled_m = div_s64(scaled_m, 10);
> +		scale_factor++;
> +	}
> +	/* Scale up only if fractional part exists. */
> +	while (scaled_m * 10 < MAX_M_VAL && scaled_m * 10 > MIN_M_VAL && !is_integer) {

s/!is_integer/scale_coef != 1/
?

> +		scaled_m *= 10;
> +		scale_factor--;
> +	}
> +
> +	*m = scaled_m;
> +	*R = scale_factor;
> +}

...

> +static const struct i2c_device_id ina233_id[] = {
> +	{"ina233", 0},

Extra spaces to be consistant with ina233_of_match below?

> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, ina233_id);
> +
> +static const struct of_device_id __maybe_unused ina233_of_match[] = {
> +	{ .compatible = "ti,ina233" },
> +	{ },

No need for an extra comma after a terminator.

> +};
> +MODULE_DEVICE_TABLE(of, ina233_of_match);

...

CJ

      parent reply	other threads:[~2025-01-10 21:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-10  8:15 [PATCH v2 0/2] hwmon: Add support for INA233 Leo Yang
2025-01-10  8:15 ` [PATCH v2 1/2] dt-bindings: hwmon: ti,ina2xx: Add INA233 device Leo Yang
2025-01-10  8:22   ` Krzysztof Kozlowski
2025-01-10  8:36   ` Krzysztof Kozlowski
2025-01-10  8:15 ` [PATCH v2 2/2] hwmon: Add driver for TI INA232 Current and Power Monitor Leo Yang
2025-01-10  8:25   ` Krzysztof Kozlowski
2025-01-10 16:22   ` Guenter Roeck
2025-01-14  8:02     ` Leo Yang
2025-01-14 19:23       ` Guenter Roeck
2025-01-10 21:19   ` Christophe JAILLET [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dc0bba60-72e1-46a5-a341-a2aa30095042@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=Delphine_CC_Chiu@Wiwynn.com \
    --cc=Leo-Yang@quantatw.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzk+dt@kernel.org \
    --cc=leo.yang.sy0@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®