From patchwork Fri Dec 11 14:33:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wu X-Patchwork-Id: 7830391 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C7C459F1C2 for ; Fri, 11 Dec 2015 14:34:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC0612045B for ; Fri, 11 Dec 2015 14:34:14 +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 079FF20532 for ; Fri, 11 Dec 2015 14:34:14 +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 1a7Olw-0001U4-Je; Fri, 11 Dec 2015 14:34:12 +0000 Received: from lucky1.263xmail.com ([211.157.147.133]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a7Olg-0001GN-2h; Fri, 11 Dec 2015 14:34:00 +0000 Received: from david.wu?rock-chips.com (unknown [192.168.167.78]) by lucky1.263xmail.com (Postfix) with SMTP id CD6AD4E7D7; Fri, 11 Dec 2015 22:33:27 +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 7650028141; Fri, 11 Dec 2015 22:33:19 +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 22620T8M4YF; Fri, 11 Dec 2015 22:33:20 +0800 (CST) From: David Wu To: heiko@sntech.de Subject: [PATCH v1 3/3] i2c: rk3x: support I2C Hs-mode for rk3399 Date: Fri, 11 Dec 2015 22:33:04 +0800 Message-Id: <1449844384-6236-3-git-send-email-wdc@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449844384-6236-1-git-send-email-wdc@rock-chips.com> References: <1449844384-6236-1-git-send-email-wdc@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151211_063357_267326_55F47EF2 X-CRM114-Status: UNSURE ( 9.74 ) 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, dianders@chromium.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, xjq@rock-chips.com, linux-i2c@vger.kernel.org, David Wu , zyw@rock-chips.com, 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, T_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 From: David Wu The i2c controller of new version1 supports highspeed mode, 1.7M and 3.4M rate. It also could be calculated divs by the rules. The final divs would be effected a lot by hardware elements like scl_rise_ns, scl_fall_ns and sda_rise_ns,sds_fall_ns. Signed-off-by: David Wu --- drivers/i2c/busses/i2c-rk3x.c | 56 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index fae5099..ec0e37f 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c @@ -700,8 +700,8 @@ static int rk3x_i2c_v1_calc_divs(unsigned long clk_rate, unsigned long scl_rate, int ret = 0; - if (WARN_ON(scl_rate > 400000)) - scl_rate = 400000; + if (WARN_ON(scl_rate > 3400000)) + scl_rate = 3400000; if (WARN_ON(scl_rate < 100000)) scl_rate = 100000; @@ -719,7 +719,7 @@ static int rk3x_i2c_v1_calc_divs(unsigned long clk_rate, unsigned long scl_rate, start_setup_cnt = 0; stop_setup_cnt = 0; - } else { + } else if (scl_rate <= 400000) { spec_min_setup_start = 600; spec_min_hold_start = 600; @@ -732,6 +732,32 @@ static int rk3x_i2c_v1_calc_divs(unsigned long clk_rate, unsigned long scl_rate, start_setup_cnt = 0; stop_setup_cnt = 0; + } else if (scl_rate <= 1700000) { + spec_min_low_ns = 320; + spec_min_high_ns = 120; + + spec_min_setup_start = 160; + spec_min_hold_start = 160; + + spec_max_data_hold_ns = 150; + spec_min_data_setup = 10; + spec_min_stop_setup = 160; + + start_setup_cnt = 1; + stop_setup_cnt = 1; + } else { + spec_min_low_ns = 160; + spec_min_high_ns = 60; + + spec_min_setup_start = 160; + spec_min_hold_start = 160; + + spec_min_data_setup = 10; + spec_max_data_hold_ns = 70; + spec_min_stop_setup = 160; + + start_setup_cnt = 2; + stop_setup_cnt = 2; } clk_rate_khz = DIV_ROUND_UP(clk_rate, 1000); @@ -1126,15 +1152,29 @@ static int rk3x_i2c_probe(struct platform_device *pdev) &i2c->scl_rise_ns)) { if (i2c->scl_frequency <= 100000) i2c->scl_rise_ns = 1000; - else + else if (i2c->scl_frequency <= 400000) i2c->scl_rise_ns = 300; + else if (i2c->scl_frequency <= 1700000) + i2c->scl_rise_ns = 80; + else + i2c->scl_rise_ns = 40; } if (of_property_read_u32(pdev->dev.of_node, "i2c-scl-falling-time-ns", - &i2c->scl_fall_ns)) - i2c->scl_fall_ns = 300; + &i2c->scl_fall_ns)) { + if (i2c->scl_frequency <= 400000) + i2c->scl_fall_ns = 300; + else if (i2c->scl_frequency <= 1700000) + i2c->scl_fall_ns = 80; + else + i2c->scl_fall_ns = 40; + } if (of_property_read_u32(pdev->dev.of_node, "i2c-sda-falling-time-ns", - &i2c->scl_fall_ns)) - i2c->sda_fall_ns = i2c->scl_fall_ns; + &i2c->scl_fall_ns)) { + if (i2c->scl_frequency <= 400000) + i2c->sda_fall_ns = i2c->scl_fall_ns; + else + i2c->sda_fall_ns = 2 * i2c->scl_fall_ns; + } strlcpy(i2c->adap.name, "rk3x-i2c", sizeof(i2c->adap.name)); i2c->adap.owner = THIS_MODULE;