From patchwork Tue Apr 12 13:29:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 65615 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1921558qge; Tue, 12 Apr 2016 06:29:32 -0700 (PDT) X-Received: by 10.98.74.74 with SMTP id x71mr4654953pfa.25.1460467772442; Tue, 12 Apr 2016 06:29:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o126si9990182pfo.29.2016.04.12.06.29.32; Tue, 12 Apr 2016 06:29:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756789AbcDLN3Z (ORCPT + 1 other); Tue, 12 Apr 2016 09:29:25 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:34523 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756783AbcDLN3Y (ORCPT ); Tue, 12 Apr 2016 09:29:24 -0400 Received: by mail-wm0-f46.google.com with SMTP id l6so188183067wml.1 for ; Tue, 12 Apr 2016 06:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=JlCxA9vYDIbo0xGrU7sX0DhHYKFalBqNRcZLD4vEwoA=; b=aWRrl9b1hxATSqMOoY6z/U2Obk8E8+AdpC2JZEnSLSrOPi0PUesUyzol0NfEPVP9/h GAQ8CMcR5TpDMFNAA+jytRU5bNBZJJRKBFiGp55V9yS0G1hQ78yYrkA5gARVk0sTGD5T BIh13U1Lrssp9wdtE09kMvbK5I9zlmelmfKl0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JlCxA9vYDIbo0xGrU7sX0DhHYKFalBqNRcZLD4vEwoA=; b=hdfXm9TEyLv40FGEjCh9Axpz+4kUyh7IwDWtm2YCM5Nhbc8z1MUl9aqCYqVkmwgJuT f35kTuqwsmNFknErGmkgljineirDXkDiyEIIDKuar0qRs2TAqXzcuhra5Y/9CtfIVdYG 8JBJ2VQsvKM2cDcWKQzEW6r0c4eBv4qwpDT9m/orVlcqvZHFxxEVMILMcf1TO4xFOWqr QHfsE3C1xePaLH74Im7SVopFRiE4JpUEEP9mqb11QrfeucJKO2HdYqBzoZSQJ9kj4Cfj 9DN67pL8iTB5bKP5ahy7xsyZvty3lvObOdiDymWxATnt6nYiw1Vesbpx4NavkHaM9vX1 +gpQ== X-Gm-Message-State: AOPr4FUP88UnGkn8mxPDT+LOfD0jdLzizsORfVjboB9rLOC88SUPlFAV8EW0UOZi0UpSsipC X-Received: by 10.194.71.226 with SMTP id y2mr3650524wju.127.1460467762821; Tue, 12 Apr 2016 06:29:22 -0700 (PDT) Received: from localhost.localdomain (cpc84787-aztw28-2-0-cust15.18-1.cable.virginm.net. [82.37.140.16]) by smtp.gmail.com with ESMTPSA id j18sm22975653wmd.2.2016.04.12.06.29.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Apr 2016 06:29:21 -0700 (PDT) From: Peter Griffin To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, srinivas.kandagatla@gmail.com, maxime.coquelin@st.com, patrice.chotard@st.com, wsa@the-dreams.de Cc: peter.griffin@linaro.org, lee.jones@linaro.org, linux-i2c@vger.kernel.org, Frederic Pillon Subject: [PATCH] i2c: st: Implement i2c_bus_recovery_info callbacks Date: Tue, 12 Apr 2016 14:29:19 +0100 Message-Id: <1460467759-11737-1-git-send-email-peter.griffin@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org >From I2C specification: http://www.nxp.com/documents/user_manual/UM10204.pdf Rev. 03 section 3.1.16 titled "Bus clear". When the i2c device held the SDA line low, the master should send 9 clocks pulses to try to recover. Signed-off-by: Frederic Pillon Signed-off-by: Peter Griffin --- drivers/i2c/busses/i2c-st.c | 56 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c index 6ee7715..37b0b34 100644 --- a/drivers/i2c/busses/i2c-st.c +++ b/drivers/i2c/busses/i2c-st.c @@ -337,10 +337,51 @@ static void st_i2c_hw_config(struct st_i2c_dev *i2c_dev) writel_relaxed(val, i2c_dev->base + SSC_NOISE_SUPP_WIDTH_DATAOUT); } +/* + * i2c bus recovery routines + * get_scl and set_scl must be defined to avoid the recover_bus field of + * i2c_bus_recovery_info to be overriden with NULL during the + * i2c_add_adapter call + */ + +static int st_i2c_get_scl(struct i2c_adapter *adap) +{ + return 0; +} + +static void st_i2c_set_scl(struct i2c_adapter *adap, int val) +{ +} + +static int st_i2c_recover_bus(struct i2c_adapter *i2c_adap) +{ + struct st_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); + u32 ctl; + + dev_err(i2c_dev->dev, "Trying to recover bus\n"); + + /* Disable interrupts */ + writel_relaxed(0, i2c_dev->base + SSC_IEN); + + st_i2c_hw_config(i2c_dev); + + ctl = SSC_CTL_EN | SSC_CTL_MS | SSC_CTL_EN_RX_FIFO | SSC_CTL_EN_TX_FIFO; + st_i2c_set_bits(i2c_dev->base + SSC_CTL, ctl); + + st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_I2CM); + usleep_range(8000, 10000); + + writel_relaxed(0, i2c_dev->base + SSC_TBUF); + usleep_range(2000, 4000); + st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_I2CM); + + return 0; +} + static int st_i2c_wait_free_bus(struct st_i2c_dev *i2c_dev) { u32 sta; - int i; + int i, ret; for (i = 0; i < 10; i++) { sta = readl_relaxed(i2c_dev->base + SSC_STA); @@ -352,6 +393,12 @@ static int st_i2c_wait_free_bus(struct st_i2c_dev *i2c_dev) dev_err(i2c_dev->dev, "bus not free (status = 0x%08x)\n", sta); + ret = i2c_recover_bus(&i2c_dev->adap); + if (ret) { + dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret); + return ret; + } + return -EBUSY; } @@ -744,6 +791,12 @@ static struct i2c_algorithm st_i2c_algo = { .functionality = st_i2c_func, }; +static struct i2c_bus_recovery_info st_i2c_recovery_info = { + .recover_bus = st_i2c_recover_bus, + .get_scl = st_i2c_get_scl, + .set_scl = st_i2c_set_scl, +}; + static int st_i2c_of_get_deglitch(struct device_node *np, struct st_i2c_dev *i2c_dev) { @@ -826,6 +879,7 @@ static int st_i2c_probe(struct platform_device *pdev) adap->timeout = 2 * HZ; adap->retries = 0; adap->algo = &st_i2c_algo; + adap->bus_recovery_info = &st_i2c_recovery_info; adap->dev.parent = &pdev->dev; adap->dev.of_node = pdev->dev.of_node;