Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1255875yba; Tue, 2 Apr 2019 05:40:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrHfJZY4DOrsSx5e/C9BcVk+3xEWPbzZZv9reB26ar9ieEL0jniUXivgqTSVzlzSCysR18 X-Received: by 2002:aa7:8145:: with SMTP id d5mr28189516pfn.215.1554208824528; Tue, 02 Apr 2019 05:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554208824; cv=none; d=google.com; s=arc-20160816; b=KSNgWgNNMO/R6Pgfqgt//+H7cVsPr/AcSh0BKjLUJd4/AzmMJ2+cDCgz9X7PrbuqvI cQzpR0mxh2ELLehUuX2qyBqEt8jek1uSPIlNTMg6bGB8h+LO5Xjbl/7QnG2FmUvv6H+V 8b7PKf3fkAX4nYAGkm1uHlAGgSDxcxHy17YFfSOZO90MSoNb2gBkN4X/4B7X8t8EqCDI +Arfnu2LlVD3M6exa8C64ysZVHdlIsbc0F5QoWpYPdFFBYZbO6S7sgjX/xQ4+oeC/ZLX dHgTS8fG/33ZRr27y6Bo68w5u0w3VZN7JnP5LXdEMus6zxrck9nUMQ6rnEhV4vkgEmQB HVqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=akDvzJg2UMFcDLitfhyj8Ci5A1nPrHmsr5XyD67+QKk=; b=mYav52y3l8UvmRBfLNezF99bi434sa0uOocGYV/2cnWCukSQTyWSlA9XaZHz8bkP76 80CJehDV88o+s5bVB7jBkewfnPUA2l2fFdAl3PyTHdPbAQgqj+8k6jKx5nW1EGz6THH3 NtKxTeqvXb0dyISXuntvyoSZFH2f3mHnWZCE5skOd/4hPWCtmrGu/0OcD3ABFKSzIynA 8OzuhjEzRveDtWfQGsUBCxnRlDw3ZTYIO9H99ii7NhsyFJD9VH/XILG5FtJGBLepbFRY YNRE+kUgx4zt04w/HaHah92AQxgFg3noB6mg7JCt1gr8k0I/e1Xv06RdczsdYl61Ddl1 nPVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u185si11179868pgd.489.2019.04.02.05.40.09; Tue, 02 Apr 2019 05:40:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730791AbfDBMgR (ORCPT + 99 others); Tue, 2 Apr 2019 08:36:17 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:51298 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730371AbfDBMgQ (ORCPT ); Tue, 2 Apr 2019 08:36:16 -0400 X-UUID: ad22af807a914084be1f1b94ef151c19-20190402 X-UUID: ad22af807a914084be1f1b94ef151c19-20190402 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 203089298; Tue, 02 Apr 2019 20:36:11 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 2 Apr 2019 20:36:09 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 2 Apr 2019 20:36:09 +0800 From: Qii Wang To: CC: , , , , , , , , , , Subject: [PATCH RESEND v6 3/6] i2c: mediatek: Add arb clock in i2c driver Date: Tue, 2 Apr 2019 20:35:57 +0800 Message-ID: <1554208560-14817-4-git-send-email-qii.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1554208560-14817-1-git-send-email-qii.wang@mediatek.com> References: <1554208560-14817-1-git-send-email-qii.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: F667A60E98AAC97AC6022E4B507BD1DDB4F6965D142566EE88B017C13EC2E8D22000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When two i2c controllers are internally connected to the same GPIO pins, the arb clock is needed to ensure that the waveforms do not interfere with each other. And we also need to enable the interrupt to find arb lost, old i2c controllers also have the bit. Signed-off-by: Qii Wang Reviewed-by: Nicolas Boichat --- drivers/i2c/busses/i2c-mt65xx.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index be36018..1a7235e 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -35,6 +35,7 @@ #include #define I2C_RS_TRANSFER (1 << 4) +#define I2C_ARB_LOST (1 << 3) #define I2C_HS_NACKERR (1 << 2) #define I2C_ACKERR (1 << 1) #define I2C_TRANSAC_COMP (1 << 0) @@ -181,6 +182,7 @@ struct mtk_i2c { struct clk *clk_main; /* main clock for i2c bus */ struct clk *clk_dma; /* DMA clock for i2c via DMA */ struct clk *clk_pmic; /* PMIC clock for i2c from PMIC */ + struct clk *clk_arb; /* Arbitrator clock for i2c */ bool have_pmic; /* can use i2c pins from PMIC */ bool use_push_pull; /* IO config push-pull mode */ @@ -299,8 +301,18 @@ static int mtk_i2c_clock_enable(struct mtk_i2c *i2c) if (ret) goto err_pmic; } + + if (i2c->clk_arb) { + ret = clk_prepare_enable(i2c->clk_arb); + if (ret) + goto err_arb; + } + return 0; +err_arb: + if (i2c->have_pmic) + clk_disable_unprepare(i2c->clk_pmic); err_pmic: clk_disable_unprepare(i2c->clk_main); err_main: @@ -311,6 +323,9 @@ static int mtk_i2c_clock_enable(struct mtk_i2c *i2c) static void mtk_i2c_clock_disable(struct mtk_i2c *i2c) { + if (i2c->clk_arb) + clk_disable_unprepare(i2c->clk_arb); + if (i2c->have_pmic) clk_disable_unprepare(i2c->clk_pmic); @@ -519,13 +534,13 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, /* Clear interrupt status */ mtk_i2c_writew(i2c, restart_flag | I2C_HS_NACKERR | I2C_ACKERR | - I2C_TRANSAC_COMP, OFFSET_INTR_STAT); + I2C_ARB_LOST | I2C_TRANSAC_COMP, OFFSET_INTR_STAT); mtk_i2c_writew(i2c, I2C_FIFO_ADDR_CLR, OFFSET_FIFO_ADDR_CLR); /* Enable interrupt */ mtk_i2c_writew(i2c, restart_flag | I2C_HS_NACKERR | I2C_ACKERR | - I2C_TRANSAC_COMP, OFFSET_INTR_MASK); + I2C_ARB_LOST | I2C_TRANSAC_COMP, OFFSET_INTR_MASK); /* Set transfer and transaction len */ if (i2c->op == I2C_MASTER_WRRD) { @@ -659,7 +674,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, /* Clear interrupt mask */ mtk_i2c_writew(i2c, ~(restart_flag | I2C_HS_NACKERR | I2C_ACKERR | - I2C_TRANSAC_COMP), OFFSET_INTR_MASK); + I2C_ARB_LOST | I2C_TRANSAC_COMP), OFFSET_INTR_MASK); if (i2c->op == I2C_MASTER_WR) { dma_unmap_single(i2c->dev, wpaddr, @@ -884,6 +899,10 @@ static int mtk_i2c_probe(struct platform_device *pdev) return PTR_ERR(i2c->clk_dma); } + i2c->clk_arb = devm_clk_get(&pdev->dev, "arb"); + if (IS_ERR(i2c->clk_arb)) + i2c->clk_arb = NULL; + clk = i2c->clk_main; if (i2c->have_pmic) { i2c->clk_pmic = devm_clk_get(&pdev->dev, "pmic"); -- 1.7.9.5