From patchwork Tue Aug 21 14:29:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovic Desroches X-Patchwork-Id: 1355331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id D075D3FC81 for ; Tue, 21 Aug 2012 14:33:01 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T3pSn-0003XE-L6; Tue, 21 Aug 2012 14:29:49 +0000 Received: from eusmtp01.atmel.com ([212.144.249.242]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T3pSd-0003VE-5u for linux-arm-kernel@lists.infradead.org; Tue, 21 Aug 2012 14:29:40 +0000 Received: from HNOCHT02.corp.atmel.com (10.161.30.162) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server (TLS) id 14.2.318.1; Tue, 21 Aug 2012 16:31:07 +0200 Received: from ibiza.rfo.atmel.com (10.159.245.197) by HNOCHT02.corp.atmel.com (10.161.30.160) with Microsoft SMTP Server (TLS) id 14.2.318.1; Tue, 21 Aug 2012 16:29:37 +0200 From: To: , , Subject: [PATCH 1/5] i2c: at91: add new fixes for some TWI ip versions Date: Tue, 21 Aug 2012 16:29:01 +0200 Message-ID: <1345559345-13988-2-git-send-email-ludovic.desroches@atmel.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1345559345-13988-1-git-send-email-ludovic.desroches@atmel.com> References: <1345559345-13988-1-git-send-email-ludovic.desroches@atmel.com> MIME-Version: 1.0 X-Originating-IP: [10.159.245.197] X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.1 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: plagnioj@jcrosoft.com, Ludovic Desroches , nicolas.ferre@atmel.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Ludovic Desroches The at91sam9261 TWI ip version requires also some fixes. The id_entry field from the platform device structure has been replaced by the use of cpu_is_xxx function to determine when to use these fixes. Signed-off-by: Ludovic Desroches --- arch/arm/mach-at91/at91rm9200_devices.c | 9 ------- drivers/i2c/busses/i2c-at91.c | 42 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c index 2b9b493..e6b7d05 100644 --- a/arch/arm/mach-at91/at91rm9200_devices.c +++ b/arch/arm/mach-at91/at91rm9200_devices.c @@ -494,18 +494,9 @@ static struct resource twi_resources[] = { }, }; -static const struct platform_device_id twi_id = { - /* - * driver_data is "1" for hardware with ckdiv upper limit == 5 - * (AT91RM9200 erratum 22), "0" for twi modules without this bug - */ - .driver_data = 1, -}; - static struct platform_device at91rm9200_twi_device = { .name = "at91_i2c", .id = -1, - .id_entry = &twi_id, .resource = twi_resources, .num_resources = ARRAY_SIZE(twi_resources), }; diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index b1cb780..4599522 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -27,6 +27,8 @@ #include #include +#include + #define TWI_CLK_HZ 100000 /* max 400 Kbits/s */ #define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ @@ -72,7 +74,6 @@ struct at91_twi_dev { int irq; unsigned transfer_status; struct i2c_adapter adapter; - bool is_rm9200; unsigned twi_cwgr_reg; }; @@ -111,20 +112,28 @@ static void at91_init_twi_bus(struct at91_twi_dev *dev) */ static void __devinit at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk) { - const int offset = dev->is_rm9200 ? 3 : 4; - const int div = max(0, (int)DIV_ROUND_UP(clk_get_rate(dev->clk), - 2 * twi_clk) - offset); - int ckdiv = fls(div >> 8); - int cdiv = div >> ckdiv; - - if (dev->is_rm9200 && (ckdiv > 5)) { - dev_warn(dev->dev, "AT91RM9200 erratum 22: using ckdiv = 5.\n"); - ckdiv = 5; - cdiv = 255; - } else if (ckdiv > 7) { - dev_warn(dev->dev, "%d exceeds 3 bits for ckdiv, limiting.\n", - ckdiv); - ckdiv = 7; + int offset, div, max_ckdiv, ckdiv, cdiv; + + if (cpu_is_at91rm9200()) { + offset = 3; + max_ckdiv = 5; + } else if (cpu_is_at91sam9261()) { + offset = 4; + max_ckdiv = 5; + } else { + offset = 4; + max_ckdiv = 7; + } + + div = max(0, (int)DIV_ROUND_UP(clk_get_rate(dev->clk), + 2 * twi_clk) - offset); + ckdiv = fls(div >> 8); + cdiv = div >> ckdiv; + + if (ckdiv > max_ckdiv) { + dev_warn(dev->dev, "%d exceeds ckdiv max value which is %d.\n", + ckdiv, max_ckdiv); + ckdiv = max_ckdiv; cdiv = 255; } @@ -331,9 +340,6 @@ static int __devinit at91_twi_probe(struct platform_device *pdev) goto err_release_region; } - if (pdev->id_entry && pdev->id_entry->driver_data == 1) - dev->is_rm9200 = 1; - init_completion(&dev->cmd_complete); dev->dev = &pdev->dev;