Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1781082pxb; Fri, 5 Feb 2021 00:58:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAe0Uo03tFOxdxPj5X0otH+JOMsELZmzNFhkHUmV0t2brZ3gA/fzCOBz1qI4Db4HAae3zS X-Received: by 2002:a17:906:3401:: with SMTP id c1mr3249366ejb.156.1612515513776; Fri, 05 Feb 2021 00:58:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612515513; cv=none; d=google.com; s=arc-20160816; b=QVBqxjJceFGqr6AiEkqs64Y5N1k1jViaD/B33Vff+ymrrvtaZl4Pm6WfjVSqZ4qseG fosNhWrW5UiwDMQREhZPtDwVDJgz5K3J+OYw5/luZsqlQhFwMIKSftgjK1ce8TYo0fQT g6zhBQCqzc5xJ9tibr62e0cAH2qhE/sC6NAm69WSEnhHsYf7Pp1ClW36KxA2FufP+r9L fvuW2Xem282e/+G/JfWzcmEqhZ8NsPyOhQZeaEHKL5QRnfMbqb+CgwjXds3ZMmRnR9rt gFA9x0rA/XvDQWt438kni07pCQTdMbkUfdh0EN/bJJlcr5Dd0rf0YYGvS9fcdQT1cyHT mgAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=WAtejRpIzmpts18wpGgXgf05/HdqNvlkdeGPvsYexF0=; b=WWi0QI80dEbA178fX0kRcIdKLTAbekUGDk7hcBmE3o5YO2MkVCMC8m9aYXmQFJ8YFr fOU2Pmh384Kw7+aKk/ikt9Ier4iKIRFAKIOWWlBqSA76K35VZzTX2cqfYQvCetx9RE9E HC91n2d2z83VfvR81r87ixgtF47qDJMlNRQX9iuyirtNleS/WWp9dpEF+BGBv2CFTdri /mVVV4BihVXgDwIl20dSVKzbwqNPpSfbM0jjhrQjaPK8Ca04i2Y0WzdRhx+tpguj0D2l AmDuULVI1DD0NDADx44LDmo90I/HvHEuTWUq2vhvuok8rKuu/k/ldFY2/9GB2DLeFMnG GzZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=iEeNsPh2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qp24si5496863ejb.563.2021.02.05.00.58.09; Fri, 05 Feb 2021 00:58:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=iEeNsPh2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbhBEIyY (ORCPT + 99 others); Fri, 5 Feb 2021 03:54:24 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:23508 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhBEIxE (ORCPT ); Fri, 5 Feb 2021 03:53:04 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1158pvIC017513; Fri, 5 Feb 2021 09:52:07 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=WAtejRpIzmpts18wpGgXgf05/HdqNvlkdeGPvsYexF0=; b=iEeNsPh2Cg0fF2r5ArRqppt766EZwLeMYhvIs16HIepNpwi36ZzIPvfa1tTlhaw/y8+J F8Jg7A0p6Lc0E5BrbfpqxBatKUdSYfKSlMuIcdK+pGS7LaZlVgL3dKpNqQ6XjFcldtT0 yYLx2HQueyPTaLjvN1aykWTJzYCBpTCxyc+KOuDilUJfQm28BHcdmSNmyIsLMiL5zu7B O4fhsEdryugMOs7UV5jHxr9dkqDXAOnOsEYTzwh6H343XuV0Byp2WLxXq8kDf+2TSZsy d1stgKxtC3Z0v2Aegk4/J1M+3BjJGidipqYluQlAJN2zHxy/yu1mP/L8kgts2rU+UDg5 PA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 36d0fsdb68-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Feb 2021 09:52:07 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3D805100034; Fri, 5 Feb 2021 09:52:07 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3091D221793; Fri, 5 Feb 2021 09:52:07 +0100 (CET) Received: from localhost (10.75.127.47) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 5 Feb 2021 09:52:06 +0100 From: Alain Volmat To: , CC: , , , , , , , , , , Subject: [PATCH 3/5] i2c: stm32f7: add support for DNF i2c-digital-filter binding Date: Fri, 5 Feb 2021 09:51:42 +0100 Message-ID: <1612515104-838-4-git-send-email-alain.volmat@foss.st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612515104-838-1-git-send-email-alain.volmat@foss.st.com> References: <1612515104-838-1-git-send-email-alain.volmat@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.737 definitions=2021-02-05_06:2021-02-05,2021-02-05 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.17.1