From patchwork Thu Jan 14 12:31:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wu X-Patchwork-Id: 8031481 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 10C86BEEE5 for ; Thu, 14 Jan 2016 12:32:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40EC420454 for ; Thu, 14 Jan 2016 12:32:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 60C4720451 for ; Thu, 14 Jan 2016 12:32:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJh4a-0003hU-VS; Thu, 14 Jan 2016 12:32:16 +0000 Received: from lucky1.263xmail.com ([211.157.147.130]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJh3y-0003Hp-2m; Thu, 14 Jan 2016 12:31:40 +0000 Received: from david.wu?rock-chips.com (unknown [192.168.167.12]) by lucky1.263xmail.com (Postfix) with SMTP id D43E11E89F7; Thu, 14 Jan 2016 20:31:12 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-ADDR-CHECKED: 0 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 767A73E4; Thu, 14 Jan 2016 20:31:11 +0800 (CST) X-RL-SENDER: david.wu@rock-chips.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: david.wu@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: wdc@rock-chips.com X-DNS-TYPE: 0 Received: from unknown (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith SMTP id 11366NWPT3U; Thu, 14 Jan 2016 20:31:12 +0800 (CST) From: David Wu To: heiko@sntech.de Subject: [PATCH v3 4/4] i2c: rk3x: support I2C Highspeed Mode Date: Thu, 14 Jan 2016 20:31:39 +0800 Message-Id: <1452774699-57455-5-git-send-email-david.wu@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452774699-57455-1-git-send-email-david.wu@rock-chips.com> References: <1452774699-57455-1-git-send-email-david.wu@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160114_043138_655060_36CD8035 X-CRM114-Status: UNSURE ( 9.52 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huangtao@rock-chips.com, hl@rock-chips.com, wsa@the-dreams.de, linux-gpio@vger.kernel.org, dianders@chromium.org, linux-kernel@vger.kernel.org, cf@rock-chips.com, andy.shevchenko@gmail.com, xjq@rock-chips.com, David Wu , zyw@rock-chips.com, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The i2c controller of new version1 supports highspeed mode, 1.7M and 3.4M rate. It also could be calculated clocks by the rules. Note: The final divs would be effected a lot by hardware elements like scl_rise_ns, scl_fall_ns and sda_rise_ns. There are two examples of div calculated by the rules, not contain hardware elements like scl_rise time, scl_fall time and sda_rise time: 1. scl: 1.7M: Source Pclk: 200M, Target scl: 1700K, Final scl: 1.667K; Tpclk = 5ns; divl = 9, divh = 4; l = 10, h = 5; tLow = 400ns, tHigh = 200ns; start_setup_cnt = stop_setup_cnt = 0; u = p = 1; tSU;sta = (8h * u + 1) * T = 205ns; tHD;sta = [8h * (u + 1) - 1] * T = 395ns; tSU;sto = (8h * p + 1) * T = 205ns; data_upd_st = 1; s = data_upd_st + 1 = 2; tHD;sda = (l * s + 1) * T = 105; tSU;sda = [(8 - s) * l + 1] * T = 295; 2. scl: 3.4M Source Pclk: 200M, Target scl: 3400K, Final scl: 3125K; Tpclk = 5ns; divl = 4, divh = 2; l = 5, h = 3; tLow = 200ns, tHigh = 120ns; start_setup_cnt = stop_setup_cnt = 1; u = p = 2; tSU;sta = (8h * u + 1) * T = 245ns; tHD;sta = [8h * (u + 1) - 1] * T = 355ns; tSU;sto = (8h * p + 1) * T = 245ns; data_upd_st = 1; s = data_upd_st + 1 = 2; tHD;sda = (l * s + 1) * T = 55ns; tSU;sda = [(8 - l) * s + 1] * T = 145ns; Signed-off-by: David Wu --- Changes in v3: None changes in v2: - split patch to three patches(Heiko) drivers/i2c/busses/i2c-rk3x.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index b7229a7..bb041aa 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c @@ -700,9 +700,9 @@ static int rk3x_i2c_v1_calc_clock(unsigned long clk_rate, int ret = 0; - /* Support standard-mode and fast-mode */ - if (WARN_ON(t_input->bus_freq_hz > 400000)) - t_input->bus_freq_hz = 400000; + /* Support standard-mode, fast-mode and highspeed-mode */ + if (WARN_ON(t_input->bus_freq_hz > 3400000)) + t_input->bus_freq_hz = 3400000; /* prevent scl_rate_khz from becoming 0 */ if (WARN_ON(t_input->bus_freq_hz < 1000)) @@ -732,6 +732,24 @@ static int rk3x_i2c_v1_calc_clock(unsigned long clk_rate, spec_min_data_setup_ns = 100; spec_max_data_hold_ns = 900; + } else if (t_input->bus_freq_hz <= 1700000) { + spec_min_low_ns = 320; + spec_min_high_ns = 120; + + spec_min_setup_start_ns = 160; + spec_min_stop_setup_ns = 160; + + spec_min_data_setup_ns = 10; + spec_max_data_hold_ns = 150; + } else { + spec_min_low_ns = 160; + spec_min_high_ns = 60; + + spec_min_setup_start_ns = 160; + spec_min_stop_setup_ns = 160; + + spec_min_data_setup_ns = 10; + spec_max_data_hold_ns = 70; } /* caculate min-divh and min-divl */