Re: [PATCH 2/5] i2c: stm32f7: support DT binding i2c-analog-filter

From: Pierre Yves MORDRET
Date: Fri Feb 05 2021 - 14:46:52 EST


Hello all

Looks good to me

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@xxxxxxxxxxx>

Regards

On 2/5/21 9:51 AM, Alain Volmat wrote:
> Replace driver internally coded enabling/disabling of the
> analog-filter with the DT binding "i2c-analog-filter".
>
> Signed-off-by: Alain Volmat <alain.volmat@xxxxxxxxxxx>
> ---
> drivers/i2c/busses/i2c-stm32f7.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
> index 473fbe144b7e..0c539fea2754 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -164,7 +164,6 @@ enum {
> #define STM32F7_I2C_DNF_DEFAULT 0
> #define STM32F7_I2C_DNF_MAX 15
>
> -#define STM32F7_I2C_ANALOG_FILTER_ENABLE 1
> #define STM32F7_I2C_ANALOG_FILTER_DELAY_MIN 50 /* ns */
> #define STM32F7_I2C_ANALOG_FILTER_DELAY_MAX 260 /* ns */
>
> @@ -224,7 +223,6 @@ struct stm32f7_i2c_spec {
> * @rise_time: Rise time (ns)
> * @fall_time: Fall time (ns)
> * @dnf: Digital filter coefficient (0-16)
> - * @analog_filter: Analog filter delay (On/Off)
> * @fmp_clr_offset: Fast Mode Plus clear register offset from set register
> */
> struct stm32f7_i2c_setup {
> @@ -233,7 +231,6 @@ struct stm32f7_i2c_setup {
> u32 rise_time;
> u32 fall_time;
> u8 dnf;
> - bool analog_filter;
> u32 fmp_clr_offset;
> };
>
> @@ -312,6 +309,7 @@ struct stm32f7_i2c_msg {
> * @wakeup_src: boolean to know if the device is a wakeup source
> * @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
> */
> struct stm32f7_i2c_dev {
> struct i2c_adapter adap;
> @@ -340,6 +338,7 @@ struct stm32f7_i2c_dev {
> bool wakeup_src;
> bool smbus_mode;
> struct i2c_client *host_notify_client;
> + bool analog_filter;
> };
>
> /*
> @@ -386,14 +385,12 @@ 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,
> - .analog_filter = STM32F7_I2C_ANALOG_FILTER_ENABLE,
> };
>
> 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,
> - .analog_filter = STM32F7_I2C_ANALOG_FILTER_ENABLE,
> .fmp_clr_offset = 0x40,
> };
>
> @@ -471,10 +468,10 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
>
> /* Analog and Digital Filters */
> af_delay_min =
> - (setup->analog_filter ?
> + (i2c_dev->analog_filter ?
> STM32F7_I2C_ANALOG_FILTER_DELAY_MIN : 0);
> af_delay_max =
> - (setup->analog_filter ?
> + (i2c_dev->analog_filter ?
> STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0);
> dnf_delay = setup->dnf * i2cclk;
>
> @@ -676,12 +673,15 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
> return ret;
> }
>
> + i2c_dev->analog_filter = of_property_read_bool(i2c_dev->dev->of_node,
> + "i2c-analog-filter");
> +
> dev_dbg(i2c_dev->dev, "I2C Speed(%i), Clk Source(%i)\n",
> setup->speed_freq, setup->clock_src);
> 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",
> - (setup->analog_filter ? "On" : "Off"), setup->dnf);
> + (i2c_dev->analog_filter ? "On" : "Off"), setup->dnf);
>
> i2c_dev->bus_rate = setup->speed_freq;
>
> @@ -720,8 +720,8 @@ static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev)
> timing |= STM32F7_I2C_TIMINGR_SCLL(t->scll);
> writel_relaxed(timing, i2c_dev->base + STM32F7_I2C_TIMINGR);
>
> - /* Enable I2C */
> - if (i2c_dev->setup.analog_filter)
> + /* Configure the Analog Filter */
> + if (i2c_dev->analog_filter)
> stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1,
> STM32F7_I2C_CR1_ANFOFF);
> else
>

--
--
~ Py MORDRET
--