All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Yves MORDRET <pierre-yves.mordret@foss.st.com>
To: Alain Volmat <alain.volmat@foss.st.com>, <wsa@kernel.org>,
	<robh+dt@kernel.org>
Cc: <mark.rutland@arm.com>, <mcoquelin.stm32@gmail.com>,
	<alexandre.torgue@foss.st.com>, <linux-i2c@vger.kernel.org>,
	<devicetree@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <fabrice.gasnier@foss.st.com>
Subject: Re: [PATCH 3/5] i2c: stm32f7: add support for DNF i2c-digital-filter binding
Date: Fri, 5 Feb 2021 15:59:19 +0100	[thread overview]
Message-ID: <be1c42b6-c86b-7f17-bf50-f2f67ddb88af@foss.st.com> (raw)
In-Reply-To: <1612515104-838-4-git-send-email-alain.volmat@foss.st.com>

Hello all

Looks good to me

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com>

Regards

On 2/5/21 9:51 AM, Alain Volmat wrote:
> Add the support for the i2c-digital-filter binding, allowing to enable
> the digital filter via the device-tree and indicate its value in the DT.
> 
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
> index 0c539fea2754..f77cd6512a86 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -222,7 +222,6 @@ struct stm32f7_i2c_spec {
>   * @clock_src: I2C clock source frequency (Hz)
>   * @rise_time: Rise time (ns)
>   * @fall_time: Fall time (ns)
> - * @dnf: Digital filter coefficient (0-16)
>   * @fmp_clr_offset: Fast Mode Plus clear register offset from set register
>   */
>  struct stm32f7_i2c_setup {
> @@ -230,7 +229,6 @@ struct stm32f7_i2c_setup {
>  	u32 clock_src;
>  	u32 rise_time;
>  	u32 fall_time;
> -	u8 dnf;
>  	u32 fmp_clr_offset;
>  };
>  
> @@ -310,6 +308,8 @@ struct stm32f7_i2c_msg {
>   * @smbus_mode: states that the controller is configured in SMBus mode
>   * @host_notify_client: SMBus host-notify client
>   * @analog_filter: boolean to indicate enabling of the analog filter
> + * @dnf_dt: value of digital filter requested via dt
> + * @dnf: value of digital filter to apply
>   */
>  struct stm32f7_i2c_dev {
>  	struct i2c_adapter adap;
> @@ -339,6 +339,8 @@ struct stm32f7_i2c_dev {
>  	bool smbus_mode;
>  	struct i2c_client *host_notify_client;
>  	bool analog_filter;
> +	u32 dnf_dt;
> +	u32 dnf;
>  };
>  
>  /*
> @@ -384,13 +386,11 @@ static struct stm32f7_i2c_spec stm32f7_i2c_specs[] = {
>  static const struct stm32f7_i2c_setup stm32f7_setup = {
>  	.rise_time = STM32F7_I2C_RISE_TIME_DEFAULT,
>  	.fall_time = STM32F7_I2C_FALL_TIME_DEFAULT,
> -	.dnf = STM32F7_I2C_DNF_DEFAULT,
>  };
>  
>  static const struct stm32f7_i2c_setup stm32mp15_setup = {
>  	.rise_time = STM32F7_I2C_RISE_TIME_DEFAULT,
>  	.fall_time = STM32F7_I2C_FALL_TIME_DEFAULT,
> -	.dnf = STM32F7_I2C_DNF_DEFAULT,
>  	.fmp_clr_offset = 0x40,
>  };
>  
> @@ -459,10 +459,11 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
>  		return -EINVAL;
>  	}
>  
> -	if (setup->dnf > STM32F7_I2C_DNF_MAX) {
> +	i2c_dev->dnf = DIV_ROUND_CLOSEST(i2c_dev->dnf_dt, i2cclk);
> +	if (i2c_dev->dnf > STM32F7_I2C_DNF_MAX) {
>  		dev_err(i2c_dev->dev,
>  			"DNF out of bound %d/%d\n",
> -			setup->dnf, STM32F7_I2C_DNF_MAX);
> +			i2c_dev->dnf * i2cclk, STM32F7_I2C_DNF_MAX * i2cclk);
>  		return -EINVAL;
>  	}
>  
> @@ -473,13 +474,13 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
>  	af_delay_max =
>  		(i2c_dev->analog_filter ?
>  		 STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0);
> -	dnf_delay = setup->dnf * i2cclk;
> +	dnf_delay = i2c_dev->dnf * i2cclk;
>  
>  	sdadel_min = specs->hddat_min + setup->fall_time -
> -		af_delay_min - (setup->dnf + 3) * i2cclk;
> +		af_delay_min - (i2c_dev->dnf + 3) * i2cclk;
>  
>  	sdadel_max = specs->vddat_max - setup->rise_time -
> -		af_delay_max - (setup->dnf + 4) * i2cclk;
> +		af_delay_max - (i2c_dev->dnf + 4) * i2cclk;
>  
>  	scldel_min = setup->rise_time + specs->sudat_min;
>  
> @@ -645,6 +646,7 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
>  	setup->speed_freq = t->bus_freq_hz;
>  	i2c_dev->setup.rise_time = t->scl_rise_ns;
>  	i2c_dev->setup.fall_time = t->scl_fall_ns;
> +	i2c_dev->dnf_dt = t->digital_filter_width_ns;
>  	setup->clock_src = clk_get_rate(i2c_dev->clk);
>  
>  	if (!setup->clock_src) {
> @@ -652,6 +654,9 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
>  		return -EINVAL;
>  	}
>  
> +	if (!of_property_read_bool(i2c_dev->dev->of_node, "i2c-digital-filter"))
> +		i2c_dev->dnf_dt = STM32F7_I2C_DNF_DEFAULT;
> +
>  	do {
>  		ret = stm32f7_i2c_compute_timing(i2c_dev, setup,
>  						 &i2c_dev->timing);
> @@ -681,7 +686,7 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
>  	dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n",
>  		setup->rise_time, setup->fall_time);
>  	dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n",
> -		(i2c_dev->analog_filter ? "On" : "Off"), setup->dnf);
> +		(i2c_dev->analog_filter ? "On" : "Off"), i2c_dev->dnf);
>  
>  	i2c_dev->bus_rate = setup->speed_freq;
>  
> @@ -732,7 +737,7 @@ static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev)
>  	stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1,
>  			     STM32F7_I2C_CR1_DNF_MASK);
>  	stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1,
> -			     STM32F7_I2C_CR1_DNF(i2c_dev->setup.dnf));
> +			     STM32F7_I2C_CR1_DNF(i2c_dev->dnf));
>  
>  	stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1,
>  			     STM32F7_I2C_CR1_PE);
> 

-- 
--
~ Py MORDRET
--

WARNING: multiple messages have this Message-ID (diff)
From: Pierre Yves MORDRET <pierre-yves.mordret@foss.st.com>
To: Alain Volmat <alain.volmat@foss.st.com>, <wsa@kernel.org>,
	<robh+dt@kernel.org>
Cc: mark.rutland@arm.com, devicetree@vger.kernel.org,
	alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org,
	fabrice.gasnier@foss.st.com, linux-i2c@vger.kernel.org,
	mcoquelin.stm32@gmail.com,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 3/5] i2c: stm32f7: add support for DNF i2c-digital-filter binding
Date: Fri, 5 Feb 2021 15:59:19 +0100	[thread overview]
Message-ID: <be1c42b6-c86b-7f17-bf50-f2f67ddb88af@foss.st.com> (raw)
In-Reply-To: <1612515104-838-4-git-send-email-alain.volmat@foss.st.com>

Hello all

Looks good to me

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com>

Regards

On 2/5/21 9:51 AM, Alain Volmat wrote:
> Add the support for the i2c-digital-filter binding, allowing to enable
> the digital filter via the device-tree and indicate its value in the DT.
> 
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
> index 0c539fea2754..f77cd6512a86 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -222,7 +222,6 @@ struct stm32f7_i2c_spec {
>   * @clock_src: I2C clock source frequency (Hz)
>   * @rise_time: Rise time (ns)
>   * @fall_time: Fall time (ns)
> - * @dnf: Digital filter coefficient (0-16)
>   * @fmp_clr_offset: Fast Mode Plus clear register offset from set register
>   */
>  struct stm32f7_i2c_setup {
> @@ -230,7 +229,6 @@ struct stm32f7_i2c_setup {
>  	u32 clock_src;
>  	u32 rise_time;
>  	u32 fall_time;
> -	u8 dnf;
>  	u32 fmp_clr_offset;
>  };
>  
> @@ -310,6 +308,8 @@ struct stm32f7_i2c_msg {
>   * @smbus_mode: states that the controller is configured in SMBus mode
>   * @host_notify_client: SMBus host-notify client
>   * @analog_filter: boolean to indicate enabling of the analog filter
> + * @dnf_dt: value of digital filter requested via dt
> + * @dnf: value of digital filter to apply
>   */
>  struct stm32f7_i2c_dev {
>  	struct i2c_adapter adap;
> @@ -339,6 +339,8 @@ struct stm32f7_i2c_dev {
>  	bool smbus_mode;
>  	struct i2c_client *host_notify_client;
>  	bool analog_filter;
> +	u32 dnf_dt;
> +	u32 dnf;
>  };
>  
>  /*
> @@ -384,13 +386,11 @@ static struct stm32f7_i2c_spec stm32f7_i2c_specs[] = {
>  static const struct stm32f7_i2c_setup stm32f7_setup = {
>  	.rise_time = STM32F7_I2C_RISE_TIME_DEFAULT,
>  	.fall_time = STM32F7_I2C_FALL_TIME_DEFAULT,
> -	.dnf = STM32F7_I2C_DNF_DEFAULT,
>  };
>  
>  static const struct stm32f7_i2c_setup stm32mp15_setup = {
>  	.rise_time = STM32F7_I2C_RISE_TIME_DEFAULT,
>  	.fall_time = STM32F7_I2C_FALL_TIME_DEFAULT,
> -	.dnf = STM32F7_I2C_DNF_DEFAULT,
>  	.fmp_clr_offset = 0x40,
>  };
>  
> @@ -459,10 +459,11 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
>  		return -EINVAL;
>  	}
>  
> -	if (setup->dnf > STM32F7_I2C_DNF_MAX) {
> +	i2c_dev->dnf = DIV_ROUND_CLOSEST(i2c_dev->dnf_dt, i2cclk);
> +	if (i2c_dev->dnf > STM32F7_I2C_DNF_MAX) {
>  		dev_err(i2c_dev->dev,
>  			"DNF out of bound %d/%d\n",
> -			setup->dnf, STM32F7_I2C_DNF_MAX);
> +			i2c_dev->dnf * i2cclk, STM32F7_I2C_DNF_MAX * i2cclk);
>  		return -EINVAL;
>  	}
>  
> @@ -473,13 +474,13 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
>  	af_delay_max =
>  		(i2c_dev->analog_filter ?
>  		 STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0);
> -	dnf_delay = setup->dnf * i2cclk;
> +	dnf_delay = i2c_dev->dnf * i2cclk;
>  
>  	sdadel_min = specs->hddat_min + setup->fall_time -
> -		af_delay_min - (setup->dnf + 3) * i2cclk;
> +		af_delay_min - (i2c_dev->dnf + 3) * i2cclk;
>  
>  	sdadel_max = specs->vddat_max - setup->rise_time -
> -		af_delay_max - (setup->dnf + 4) * i2cclk;
> +		af_delay_max - (i2c_dev->dnf + 4) * i2cclk;
>  
>  	scldel_min = setup->rise_time + specs->sudat_min;
>  
> @@ -645,6 +646,7 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
>  	setup->speed_freq = t->bus_freq_hz;
>  	i2c_dev->setup.rise_time = t->scl_rise_ns;
>  	i2c_dev->setup.fall_time = t->scl_fall_ns;
> +	i2c_dev->dnf_dt = t->digital_filter_width_ns;
>  	setup->clock_src = clk_get_rate(i2c_dev->clk);
>  
>  	if (!setup->clock_src) {
> @@ -652,6 +654,9 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
>  		return -EINVAL;
>  	}
>  
> +	if (!of_property_read_bool(i2c_dev->dev->of_node, "i2c-digital-filter"))
> +		i2c_dev->dnf_dt = STM32F7_I2C_DNF_DEFAULT;
> +
>  	do {
>  		ret = stm32f7_i2c_compute_timing(i2c_dev, setup,
>  						 &i2c_dev->timing);
> @@ -681,7 +686,7 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
>  	dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n",
>  		setup->rise_time, setup->fall_time);
>  	dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n",
> -		(i2c_dev->analog_filter ? "On" : "Off"), setup->dnf);
> +		(i2c_dev->analog_filter ? "On" : "Off"), i2c_dev->dnf);
>  
>  	i2c_dev->bus_rate = setup->speed_freq;
>  
> @@ -732,7 +737,7 @@ static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev)
>  	stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1,
>  			     STM32F7_I2C_CR1_DNF_MASK);
>  	stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1,
> -			     STM32F7_I2C_CR1_DNF(i2c_dev->setup.dnf));
> +			     STM32F7_I2C_CR1_DNF(i2c_dev->dnf));
>  
>  	stm32f7_i2c_set_bits(i2c_dev->base + STM32F7_I2C_CR1,
>  			     STM32F7_I2C_CR1_PE);
> 

-- 
--
~ Py MORDRET
--

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-02-05 23:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  8:51 [PATCH 0/5] i2c: stm32: filter binding support & debug info Alain Volmat
2021-02-05  8:51 ` Alain Volmat
2021-02-05  8:51 ` [PATCH 1/5] i2c: stm32f7: fix configuration of the digital filter Alain Volmat
2021-02-05  8:51   ` Alain Volmat
2021-02-05 14:58   ` Pierre Yves MORDRET
2021-02-05 14:58     ` Pierre Yves MORDRET
2021-02-12 10:36   ` Wolfram Sang
2021-02-12 10:36     ` Wolfram Sang
2021-02-05  8:51 ` [PATCH 2/5] i2c: stm32f7: support DT binding i2c-analog-filter Alain Volmat
2021-02-05  8:51   ` Alain Volmat
2021-02-05 14:58   ` Pierre Yves MORDRET
2021-02-05 14:58     ` Pierre Yves MORDRET
2021-03-18 10:51     ` Wolfram Sang
2021-03-18 10:51       ` Wolfram Sang
2021-03-18 10:54   ` Wolfram Sang
2021-03-18 10:54     ` Wolfram Sang
2021-02-05  8:51 ` [PATCH 3/5] i2c: stm32f7: add support for DNF i2c-digital-filter binding Alain Volmat
2021-02-05  8:51   ` Alain Volmat
2021-02-05 14:59   ` Pierre Yves MORDRET [this message]
2021-02-05 14:59     ` Pierre Yves MORDRET
2021-03-18 10:54   ` Wolfram Sang
2021-03-18 10:54     ` Wolfram Sang
2021-02-05  8:51 ` [PATCH 4/5] ARM: dts: stm32: enable the analog filter for all I2C nodes in stm32mp151 Alain Volmat
2021-02-05  8:51   ` Alain Volmat
2021-02-10  8:39   ` Pierre Yves MORDRET
2021-02-10  8:39     ` Pierre Yves MORDRET
2021-03-29  9:16     ` Alexandre TORGUE
2021-03-29  9:16       ` Alexandre TORGUE
2021-03-18 10:55   ` Wolfram Sang
2021-03-18 10:55     ` Wolfram Sang
2021-03-18 13:16     ` Alexandre TORGUE
2021-03-18 13:16       ` Alexandre TORGUE
2021-02-05  8:51 ` [PATCH 5/5] i2c: stm32f7: indicate the address being accessed on errors Alain Volmat
2021-02-05  8:51   ` Alain Volmat
2021-02-05 14:59   ` Pierre Yves MORDRET
2021-02-05 14:59     ` Pierre Yves MORDRET
2021-03-18 10:58   ` Wolfram Sang
2021-03-18 10:58     ` Wolfram Sang
2021-02-05 14:57 ` [PATCH 0/5] i2c: stm32: filter binding support & debug info Pierre Yves MORDRET
2021-02-05 14:57   ` Pierre Yves MORDRET

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=be1c42b6-c86b-7f17-bf50-f2f67ddb88af@foss.st.com \
    --to=pierre-yves.mordret@foss.st.com \
    --cc=alain.volmat@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mark.rutland@arm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=wsa@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.