From patchwork Thu Nov 28 22:11:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 21853 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A0B5723FC4 for ; Thu, 28 Nov 2013 22:12:05 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id va2sf28693670obc.0 for ; Thu, 28 Nov 2013 14:12:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=NvC5N8MUWcriZQ8+nEDH3NLDBCqechbSKP2ViTVBmos=; b=YR5SAt2HRH9yigHSYtVjr8t7j6u78zJwHJovfYarhrjes4KZq3HJ7HfU9oC2H2syTH IlSrg6nXg3/eslMix+u3kCIDYd5wbkcPKfZqfXbqdtsAzFZ5dTouD3SfzMdDxgKueRxV LfKScBA28TsQAJw0huQMdjL4R5ZvGvr/qctY96mTV6Xh6/n6y/UnB9IVQl1/Dc7wr1Gd 9WDoRmipfPKm45WutO6QElEWnF8otGjThki0rjrOA560aMPo2agdX68VDLwxVUWM+uvz iFaMggt3nx1ZiWVPTc0QqhQNtVhDDo8g8oc4L20okqphQsljIbra3bPt0pMY+VdgukZI DFeg== X-Gm-Message-State: ALoCoQm9wtftGAinwsbNDdrEXbsotkGlqhoVVtgRJQXEMPTUJiQlJKurysT0zN0n+YnOAquFxZMc X-Received: by 10.182.53.165 with SMTP id c5mr15640633obp.0.1385676724801; Thu, 28 Nov 2013 14:12:04 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.41.66 with SMTP id d2ls132806qel.10.gmail; Thu, 28 Nov 2013 14:12:04 -0800 (PST) X-Received: by 10.52.118.98 with SMTP id kl2mr58243vdb.30.1385676724683; Thu, 28 Nov 2013 14:12:04 -0800 (PST) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id z17si11771555vcy.83.2013.11.28.14.12.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Nov 2013 14:12:04 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hz11so6040740vcb.17 for ; Thu, 28 Nov 2013 14:12:04 -0800 (PST) X-Received: by 10.220.144.80 with SMTP id y16mr40316374vcu.4.1385676723968; Thu, 28 Nov 2013 14:12:03 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp43620vcz; Thu, 28 Nov 2013 14:12:03 -0800 (PST) X-Received: by 10.152.7.67 with SMTP id h3mr64563laa.29.1385676722876; Thu, 28 Nov 2013 14:12:02 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by mx.google.com with ESMTPS id ax2si7690866lbc.90.2013.11.28.14.12.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Nov 2013 14:12:02 -0800 (PST) Received-SPF: neutral (google.com: 209.85.217.179 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so6420459lbv.24 for ; Thu, 28 Nov 2013 14:12:02 -0800 (PST) X-Received: by 10.152.120.135 with SMTP id lc7mr61041lab.38.1385676722257; Thu, 28 Nov 2013 14:12:02 -0800 (PST) Received: from localhost.localdomain (c83-254-156-99.bredband.comhem.se. [83.254.156.99]) by mx.google.com with ESMTPSA id c10sm47824430lbd.9.2013.11.28.14.12.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Nov 2013 14:12:01 -0800 (PST) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij , Lee Jones Subject: [PATCH 1/3] i2c: nomadik: auto-calculate slave setup time Date: Thu, 28 Nov 2013 23:11:45 +0100 Message-Id: <1385676705-15051-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The Nomadik I2C controller needs to have the slave set-up time configured based off the clock used to drive the I2C bus block. Currently this is done with static assignments assuming that the block is clocked 48MHz which is pretty likely to be bug-prone. Calculate the SLSU from the equation given in the datasheet instead. Cc: Lee Jones Signed-off-by: Linus Walleij --- drivers/i2c/busses/i2c-nomadik.c | 40 +++++++++++++++++++++---------- include/linux/platform_data/i2c-nomadik.h | 5 ---- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 8bf9ac01301a..51e61d8127cb 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -340,6 +340,8 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev) { u32 brcr1, brcr2; u32 i2c_clk, div; + u32 ns; + u16 slsu; writel(0x0, dev->virtbase + I2C_CR); writel(0x0, dev->virtbase + I2C_HSMCR); @@ -347,18 +349,38 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev) writel(0x0, dev->virtbase + I2C_RFTR); writel(0x0, dev->virtbase + I2C_DMAR); + i2c_clk = clk_get_rate(dev->clk); + /* * set the slsu: * * slsu defines the data setup time after SCL clock - * stretching in terms of i2c clk cycles. The - * needed setup time for the three modes are 250ns, - * 100ns, 10ns respectively thus leading to the values - * of 14, 6, 2 for a 48 MHz i2c clk. + * stretching in terms of i2c clk cycles + 1 (zero means + * "wait one cycle"), the needed setup time for the three + * modes are 250ns, 100ns, 10ns respectively. + * + * As the time for one cycle T in nanoseconds is + * T = (1/f) * 1000000000 => + * slsu = cycles / (1000000000 / f) + 1 */ - writel(dev->cfg.slsu << 16, dev->virtbase + I2C_SCR); + ns = DIV_ROUND_UP_ULL(1000000000ULL, i2c_clk); + switch (dev->cfg.sm) { + case I2C_FREQ_MODE_FAST: + case I2C_FREQ_MODE_FAST_PLUS: + slsu = DIV_ROUND_UP(100, ns); /* Fast */ + break; + case I2C_FREQ_MODE_HIGH_SPEED: + slsu = DIV_ROUND_UP(10, ns); /* High */ + break; + case I2C_FREQ_MODE_STANDARD: + default: + slsu = DIV_ROUND_UP(250, ns); /* Standard */ + break; + } + slsu += 1; - i2c_clk = clk_get_rate(dev->clk); + dev_dbg(&dev->adev->dev, "calculated SLSU = %04x\n", slsu); + writel(slsu << 16, dev->virtbase + I2C_SCR); /* * The spec says, in case of std. mode the divider is @@ -915,11 +937,6 @@ static const struct i2c_algorithm nmk_i2c_algo = { }; static struct nmk_i2c_controller u8500_i2c = { - /* - * Slave data setup time; 250ns, 100ns, and 10ns, which - * is 14, 6 and 2 respectively for a 48Mhz i2c clock. - */ - .slsu = 0xe, .tft = 1, /* Tx FIFO threshold */ .rft = 8, /* Rx FIFO threshold */ .clk_freq = 400000, /* fast mode operation */ @@ -1027,7 +1044,6 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) /* fetch the controller configuration from machine */ dev->cfg.clk_freq = pdata->clk_freq; - dev->cfg.slsu = pdata->slsu; dev->cfg.tft = pdata->tft; dev->cfg.rft = pdata->rft; dev->cfg.sm = pdata->sm; diff --git a/include/linux/platform_data/i2c-nomadik.h b/include/linux/platform_data/i2c-nomadik.h index 3a8be9cdc95c..8681893f7b66 100644 --- a/include/linux/platform_data/i2c-nomadik.h +++ b/include/linux/platform_data/i2c-nomadik.h @@ -18,10 +18,6 @@ enum i2c_freq_mode { /** * struct nmk_i2c_controller - client specific controller configuration * @clk_freq: clock frequency for the operation mode - * @slsu: Slave data setup time in ns. - * The needed setup time for three modes of operation - * are 250ns, 100ns and 10ns respectively thus leading - * to the values of 14, 6, 2 for a 48 MHz i2c clk * @tft: Tx FIFO Threshold in bytes * @rft: Rx FIFO Threshold in bytes * @timeout Slave response timeout(ms) @@ -29,7 +25,6 @@ enum i2c_freq_mode { */ struct nmk_i2c_controller { u32 clk_freq; - unsigned short slsu; unsigned char tft; unsigned char rft; int timeout;