From patchwork Wed Aug 7 09:05:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingchang Lu X-Patchwork-Id: 265450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 81ABB2C0219 for ; Wed, 7 Aug 2013 19:59:07 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757236Ab3HGJ7G (ORCPT ); Wed, 7 Aug 2013 05:59:06 -0400 Received: from co1ehsobe002.messaging.microsoft.com ([216.32.180.185]:59598 "EHLO co1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757225Ab3HGJ7F (ORCPT ); Wed, 7 Aug 2013 05:59:05 -0400 Received: from mail22-co1-R.bigfish.com (10.243.78.240) by CO1EHSOBE031.bigfish.com (10.243.66.96) with Microsoft SMTP Server id 14.1.225.22; Wed, 7 Aug 2013 09:59:04 +0000 Received: from mail22-co1 (localhost [127.0.0.1]) by mail22-co1-R.bigfish.com (Postfix) with ESMTP id EF2BDC01CE; Wed, 7 Aug 2013 09:59:03 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h8275bh1de097hz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23h1155h) Received: from mail22-co1 (localhost.localdomain [127.0.0.1]) by mail22-co1 (MessageSwitch) id 1375869542638339_9182; Wed, 7 Aug 2013 09:59:02 +0000 (UTC) Received: from CO1EHSMHS002.bigfish.com (unknown [10.243.78.228]) by mail22-co1.bigfish.com (Postfix) with ESMTP id 8CE9F980048; Wed, 7 Aug 2013 09:59:02 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO1EHSMHS002.bigfish.com (10.243.66.12) with Microsoft SMTP Server (TLS) id 14.16.227.3; Wed, 7 Aug 2013 09:59:02 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.3.136.1; Wed, 7 Aug 2013 09:59:01 +0000 Received: from rock.am.freescale.net (rock.ap.freescale.net [10.193.20.106]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r779wqx3022506; Wed, 7 Aug 2013 02:58:58 -0700 From: Jingchang Lu To: CC: , , , , , Jingchang Lu Subject: [PATCH 1/8] i2c: imx: use struct representing i2c clk{div, val} pair Date: Wed, 7 Aug 2013 17:05:36 +0800 Message-ID: <1375866343-2074-1-git-send-email-b35083@freescale.com> X-Mailer: git-send-email 1.8.0 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org using struct representing the i2c clk{div, val} pair would make the i2c_clk_div array more clear. Signed-off-by: Jingchang Lu reviewed-by: Sascha Hauer --- drivers/i2c/busses/i2c-imx.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index e242797..9167d43 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -30,6 +30,8 @@ * Copyright (C) 2007 RightHand Technologies, Inc. * Copyright (C) 2008 Darius Augulis * + * Copyright 2013 Freescale Semiconductor, Inc. + * */ /** Includes ******************************************************************* @@ -95,8 +97,12 @@ * * Duplicated divider values removed from list */ +struct imx_i2c_clk_pair { + u16 div; + u16 val; +}; -static u16 __initdata i2c_clk_div[50][2] = { +static struct imx_i2c_clk_pair __initdata i2c_clk_div[] = { { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 }, { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 }, { 42, 0x03 }, { 44, 0x27 }, { 48, 0x28 }, { 52, 0x05 }, @@ -274,15 +280,15 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, /* Divider value calculation */ i2c_clk_rate = clk_get_rate(i2c_imx->clk); div = (i2c_clk_rate + rate - 1) / rate; - if (div < i2c_clk_div[0][0]) + if (div < i2c_clk_div[0].div) i = 0; - else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1][0]) + else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1].div) i = ARRAY_SIZE(i2c_clk_div) - 1; else - for (i = 0; i2c_clk_div[i][0] < div; i++); + for (i = 0; i2c_clk_div[i].div < div; i++); /* Store divider value */ - i2c_imx->ifdr = i2c_clk_div[i][1]; + i2c_imx->ifdr = i2c_clk_div[i].val; /* * There dummy delay is calculated. @@ -290,7 +296,7 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, * This delay is used in I2C bus disable function * to fix chip hardware bug. */ - i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0] + i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); /* dev_dbg() can't be used, because adapter is not yet registered */ @@ -298,7 +304,7 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C_CLK=%d, REQ DIV=%d\n", __func__, i2c_clk_rate, div); dev_dbg(&i2c_imx->adapter.dev, "<%s> IFDR[IC]=0x%x, REAL DIV=%d\n", - __func__, i2c_clk_div[i][1], i2c_clk_div[i][0]); + __func__, i2c_clk_div[i].val, i2c_clk_div[i].div); #endif }