diff mbox series

[4/5] i2c: cadence: Remove always false ternary operator

Message ID 20230107211814.1179438-5-lars@metafoo.de
State New
Headers show
Series i2c: cadence: Small cleanups | expand

Commit Message

Lars-Peter Clausen Jan. 7, 2023, 9:18 p.m. UTC
When selecting the clock dividers the Cadence I2C driver skips settings
where the resulting I2C bus frequency is larger than the requested
frequency.

If the resulting frequency is lower it will compute the error to actual
frequency. When calculating the difference it also handles the case where
the resulting frequency is larger.

Since the resulting frequency is always smaller or equal the computation of
the error can be simplified by only considering this case.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/i2c/busses/i2c-cadence.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Michal Simek Jan. 16, 2023, 3 p.m. UTC | #1
On 1/7/23 22:18, Lars-Peter Clausen wrote:
> 
> When selecting the clock dividers the Cadence I2C driver skips settings
> where the resulting I2C bus frequency is larger than the requested
> frequency.
> 
> If the resulting frequency is lower it will compute the error to actual
> frequency. When calculating the difference it also handles the case where
> the resulting frequency is larger.
> 
> Since the resulting frequency is always smaller or equal the computation of
> the error can be simplified by only considering this case.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>   drivers/i2c/busses/i2c-cadence.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index b5d22e7282c2..bec50bfe7aad 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -1030,8 +1030,7 @@ static int cdns_i2c_calc_divs(unsigned long *f, unsigned long input_clk,
>                  if (actual_fscl > fscl)
>                          continue;
> 
> -               current_error = ((actual_fscl > fscl) ? (actual_fscl - fscl) :
> -                                                       (fscl - actual_fscl));
> +               current_error = fscl - actual_fscl;
> 
>                  if (last_error > current_error) {
>                          calc_div_a = div_a;
> --
> 2.30.2
> 

Shubhrajyoti: Please check this patch.

Thanks,
Michal
Michal Simek Feb. 27, 2023, 10:46 a.m. UTC | #2
On 1/7/23 22:18, Lars-Peter Clausen wrote:
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
> 
> 
> When selecting the clock dividers the Cadence I2C driver skips settings
> where the resulting I2C bus frequency is larger than the requested
> frequency.
> 
> If the resulting frequency is lower it will compute the error to actual
> frequency. When calculating the difference it also handles the case where
> the resulting frequency is larger.
> 
> Since the resulting frequency is always smaller or equal the computation of
> the error can be simplified by only considering this case.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>   drivers/i2c/busses/i2c-cadence.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index b5d22e7282c2..bec50bfe7aad 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -1030,8 +1030,7 @@ static int cdns_i2c_calc_divs(unsigned long *f, unsigned long input_clk,
>                  if (actual_fscl > fscl)
>                          continue;
> 
> -               current_error = ((actual_fscl > fscl) ? (actual_fscl - fscl) :
> -                                                       (fscl - actual_fscl));
> +               current_error = fscl - actual_fscl;
> 
>                  if (last_error > current_error) {
>                          calc_div_a = div_a;
> --
> 2.30.2
> 

Mani has tested it that's why
Acked-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal
Wolfram Sang March 16, 2023, 7:29 p.m. UTC | #3
On Sat, Jan 07, 2023 at 01:18:13PM -0800, Lars-Peter Clausen wrote:
> When selecting the clock dividers the Cadence I2C driver skips settings
> where the resulting I2C bus frequency is larger than the requested
> frequency.
> 
> If the resulting frequency is lower it will compute the error to actual
> frequency. When calculating the difference it also handles the case where
> the resulting frequency is larger.
> 
> Since the resulting frequency is always smaller or equal the computation of
> the error can be simplified by only considering this case.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index b5d22e7282c2..bec50bfe7aad 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -1030,8 +1030,7 @@  static int cdns_i2c_calc_divs(unsigned long *f, unsigned long input_clk,
 		if (actual_fscl > fscl)
 			continue;
 
-		current_error = ((actual_fscl > fscl) ? (actual_fscl - fscl) :
-							(fscl - actual_fscl));
+		current_error = fscl - actual_fscl;
 
 		if (last_error > current_error) {
 			calc_div_a = div_a;