diff options
author | Jingchang Lu <b35083@freescale.com> | 2013-08-07 05:05:36 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2013-08-15 10:11:08 -0400 |
commit | d533f0492b6371025a4f88506c7f1828a7a48e81 (patch) | |
tree | b350233f307e8cb8f78af1da0b164d475bf6007f /drivers/i2c/busses/i2c-imx.c | |
parent | a94dd00f2e1c20deacffadaaa6eebf73b217c907 (diff) |
i2c: imx: use struct representing i2c clk{div, val} pair
using struct representing the i2c clk{div, val} pair would
make the i2c_clk_div array more clear.
Signed-off-by: Jingchang Lu <b35083@freescale.com>
Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/busses/i2c-imx.c')
-rw-r--r-- | drivers/i2c/busses/i2c-imx.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index e24279725d36..9167d4332d77 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c | |||
@@ -30,6 +30,8 @@ | |||
30 | * Copyright (C) 2007 RightHand Technologies, Inc. | 30 | * Copyright (C) 2007 RightHand Technologies, Inc. |
31 | * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt> | 31 | * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt> |
32 | * | 32 | * |
33 | * Copyright 2013 Freescale Semiconductor, Inc. | ||
34 | * | ||
33 | */ | 35 | */ |
34 | 36 | ||
35 | /** Includes ******************************************************************* | 37 | /** Includes ******************************************************************* |
@@ -95,8 +97,12 @@ | |||
95 | * | 97 | * |
96 | * Duplicated divider values removed from list | 98 | * Duplicated divider values removed from list |
97 | */ | 99 | */ |
100 | struct imx_i2c_clk_pair { | ||
101 | u16 div; | ||
102 | u16 val; | ||
103 | }; | ||
98 | 104 | ||
99 | static u16 __initdata i2c_clk_div[50][2] = { | 105 | static struct imx_i2c_clk_pair __initdata i2c_clk_div[] = { |
100 | { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 }, | 106 | { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 }, |
101 | { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 }, | 107 | { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 }, |
102 | { 42, 0x03 }, { 44, 0x27 }, { 48, 0x28 }, { 52, 0x05 }, | 108 | { 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, | |||
274 | /* Divider value calculation */ | 280 | /* Divider value calculation */ |
275 | i2c_clk_rate = clk_get_rate(i2c_imx->clk); | 281 | i2c_clk_rate = clk_get_rate(i2c_imx->clk); |
276 | div = (i2c_clk_rate + rate - 1) / rate; | 282 | div = (i2c_clk_rate + rate - 1) / rate; |
277 | if (div < i2c_clk_div[0][0]) | 283 | if (div < i2c_clk_div[0].div) |
278 | i = 0; | 284 | i = 0; |
279 | else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1][0]) | 285 | else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1].div) |
280 | i = ARRAY_SIZE(i2c_clk_div) - 1; | 286 | i = ARRAY_SIZE(i2c_clk_div) - 1; |
281 | else | 287 | else |
282 | for (i = 0; i2c_clk_div[i][0] < div; i++); | 288 | for (i = 0; i2c_clk_div[i].div < div; i++); |
283 | 289 | ||
284 | /* Store divider value */ | 290 | /* Store divider value */ |
285 | i2c_imx->ifdr = i2c_clk_div[i][1]; | 291 | i2c_imx->ifdr = i2c_clk_div[i].val; |
286 | 292 | ||
287 | /* | 293 | /* |
288 | * There dummy delay is calculated. | 294 | * There dummy delay is calculated. |
@@ -290,7 +296,7 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, | |||
290 | * This delay is used in I2C bus disable function | 296 | * This delay is used in I2C bus disable function |
291 | * to fix chip hardware bug. | 297 | * to fix chip hardware bug. |
292 | */ | 298 | */ |
293 | i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0] | 299 | i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div |
294 | + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); | 300 | + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); |
295 | 301 | ||
296 | /* dev_dbg() can't be used, because adapter is not yet registered */ | 302 | /* 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, | |||
298 | dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C_CLK=%d, REQ DIV=%d\n", | 304 | dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C_CLK=%d, REQ DIV=%d\n", |
299 | __func__, i2c_clk_rate, div); | 305 | __func__, i2c_clk_rate, div); |
300 | dev_dbg(&i2c_imx->adapter.dev, "<%s> IFDR[IC]=0x%x, REAL DIV=%d\n", | 306 | dev_dbg(&i2c_imx->adapter.dev, "<%s> IFDR[IC]=0x%x, REAL DIV=%d\n", |
301 | __func__, i2c_clk_div[i][1], i2c_clk_div[i][0]); | 307 | __func__, i2c_clk_div[i].val, i2c_clk_div[i].div); |
302 | #endif | 308 | #endif |
303 | } | 309 | } |
304 | 310 | ||