RE: [PATCH] i2c: stm32f7_i2c: allows for any bus frequency

2020-03-24 Thread Patrick DELAUNAY
Hi

> From: Patrick DELAUNAY 
> Sent: vendredi 6 mars 2020 11:09
> 
> From: Alain Volmat 
> 
> Do not limit to 3 (100KHz, 400KHz, 1MHz) bus frequencies, but instead allow 
> for
> any frequency. Depending on the requested frequency (via the clock-frequency
> DT entry), use the spec data from either Standard, Fast or Fast Plus mode.
> 
> In order to do so, the driver do not use anymore spec identifier by directly 
> handle
> the requested frequency and from it retrieve the corresponding spec data to be
> used for the computation of the timing register.
> 
> Signed-off-by: Alain Volmat 
> Reviewed-by: Patrick DELAUNAY 
> Signed-off-by: Patrick Delaunay 
> ---

Applied to u-boot-stm/next, thanks!

Regards

Patrick


Re: [PATCH] i2c: stm32f7_i2c: allows for any bus frequency

2020-03-18 Thread Patrice CHOTARD

On 3/6/20 11:09 AM, Patrick Delaunay wrote:
> From: Alain Volmat 
>
> Do not limit to 3 (100KHz, 400KHz, 1MHz) bus frequencies, but
> instead allow for any frequency. Depending on the requested
> frequency (via the clock-frequency DT entry), use the spec
> data from either Standard, Fast or Fast Plus mode.
>
> In order to do so, the driver do not use anymore spec identifier
> by directly handle the requested frequency and from it retrieve
> the corresponding spec data to be used for the computation
> of the timing register.
>
> Signed-off-by: Alain Volmat 
> Reviewed-by: Patrick DELAUNAY 
> Signed-off-by: Patrick Delaunay 
> ---
>
>  drivers/i2c/stm32f7_i2c.c | 105 +-
>  1 file changed, 59 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/i2c/stm32f7_i2c.c b/drivers/i2c/stm32f7_i2c.c
> index 7d046c1a1e..fc5c1221e1 100644
> --- a/drivers/i2c/stm32f7_i2c.c
> +++ b/drivers/i2c/stm32f7_i2c.c
> @@ -7,10 +7,10 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  
>  #include 
> +#include 
>  #include 
>  
>  /* STM32 I2C registers */
> @@ -145,7 +145,6 @@ struct stm32_i2c_spec {
>  
>  /**
>   * struct stm32_i2c_setup - private I2C timing setup parameters
> - * @speed: I2C speed mode (standard, Fast Plus)
>   * @speed_freq: I2C speed frequency  (Hz)
>   * @clock_src: I2C clock source frequency (Hz)
>   * @rise_time: Rise time (ns)
> @@ -154,7 +153,6 @@ struct stm32_i2c_spec {
>   * @analog_filter: Analog filter delay (On/Off)
>   */
>  struct stm32_i2c_setup {
> - enum i2c_speed_mode speed;
>   u32 speed_freq;
>   u32 clock_src;
>   u32 rise_time;
> @@ -184,10 +182,11 @@ struct stm32_i2c_priv {
>   struct stm32_i2c_regs *regs;
>   struct clk clk;
>   struct stm32_i2c_setup *setup;
> - int speed;
> + u32 speed;
>  };
>  
>  static const struct stm32_i2c_spec i2c_specs[] = {
> + /* Standard speed - 100 KHz */
>   [IC_SPEED_MODE_STANDARD] = {
>   .rate = I2C_SPEED_STANDARD_RATE,
>   .rate_min = 8000,
> @@ -200,6 +199,7 @@ static const struct stm32_i2c_spec i2c_specs[] = {
>   .l_min = 4700,
>   .h_min = 4000,
>   },
> + /* Fast speed - 400 KHz */
>   [IC_SPEED_MODE_FAST] = {
>   .rate = I2C_SPEED_FAST_RATE,
>   .rate_min = 32,
> @@ -212,6 +212,7 @@ static const struct stm32_i2c_spec i2c_specs[] = {
>   .l_min = 1300,
>   .h_min = 600,
>   },
> + /* Fast Plus Speed - 1 MHz */
>   [IC_SPEED_MODE_FAST_PLUS] = {
>   .rate = I2C_SPEED_FAST_PLUS_RATE,
>   .rate_min = 80,
> @@ -474,6 +475,7 @@ static int stm32_i2c_xfer(struct udevice *bus, struct 
> i2c_msg *msg,
>  }
>  
>  static int stm32_i2c_compute_solutions(struct stm32_i2c_setup *setup,
> +const struct stm32_i2c_spec *specs,
>  struct list_head *solutions)
>  {
>   struct stm32_i2c_timings *v;
> @@ -490,13 +492,13 @@ static int stm32_i2c_compute_solutions(struct 
> stm32_i2c_setup *setup,
>   af_delay_max = setup->analog_filter ?
>  STM32_I2C_ANALOG_FILTER_DELAY_MAX : 0;
>  
> - sdadel_min = i2c_specs[setup->speed].hddat_min + setup->fall_time -
> + sdadel_min = specs->hddat_min + setup->fall_time -
>af_delay_min - (setup->dnf + 3) * i2cclk;
>  
> - sdadel_max = i2c_specs[setup->speed].vddat_max - setup->rise_time -
> + sdadel_max = specs->vddat_max - setup->rise_time -
>af_delay_max - (setup->dnf + 4) * i2cclk;
>  
> - scldel_min = setup->rise_time + i2c_specs[setup->speed].sudat_min;
> + scldel_min = setup->rise_time + specs->sudat_min;
>  
>   if (sdadel_min < 0)
>   sdadel_min = 0;
> @@ -548,6 +550,7 @@ static int stm32_i2c_compute_solutions(struct 
> stm32_i2c_setup *setup,
>  }
>  
>  static int stm32_i2c_choose_solution(struct stm32_i2c_setup *setup,
> +  const struct stm32_i2c_spec *specs,
>struct list_head *solutions,
>struct stm32_i2c_timings *s)
>  {
> @@ -570,8 +573,8 @@ static int stm32_i2c_choose_solution(struct 
> stm32_i2c_setup *setup,
>   dnf_delay = setup->dnf * i2cclk;
>  
>   tsync = af_delay_min + dnf_delay + (2 * i2cclk);
> - clk_max = STM32_NSEC_PER_SEC / i2c_specs[setup->speed].rate_min;
> - clk_min = STM32_NSEC_PER_SEC / i2c_specs[setup->speed].rate_max;
> + clk_max = STM32_NSEC_PER_SEC / specs->rate_min;
> + clk_min = STM32_NSEC_PER_SEC / specs->rate_max;
>  
>   /*
>* Among Prescaler possibilities discovered above figures out SCL Low
> @@ -589,7 +592,7 @@ static int stm32_i2c_choose_solution(struct 
> stm32_i2c_setup *setup,
>   for (l = 0; l < STM32_SCLL_MAX; l++) {
>   u32 tscl_l = (l + 1) * prescaler + tsync;
>  
> -