clk-divider.c (06a691e64b11323a735db3c3bd909d3c0712698f) clk-divider.c (fab88ca788dcacf2fbb006d5663456cbd390ee18)
1/*
2 * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
3 * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@linaro.org>
4 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.

--- 18 unchanged lines hidden (view full) ---

27 * rate - rate is adjustable. clk->rate = ceiling(parent->rate / divisor)
28 * parent - fixed parent. No clk_set_parent support
29 */
30
31#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
32
33#define div_mask(width) ((1 << (width)) - 1)
34
1/*
2 * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
3 * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@linaro.org>
4 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.

--- 18 unchanged lines hidden (view full) ---

27 * rate - rate is adjustable. clk->rate = ceiling(parent->rate / divisor)
28 * parent - fixed parent. No clk_set_parent support
29 */
30
31#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
32
33#define div_mask(width) ((1 << (width)) - 1)
34
35static unsigned int _get_table_maxdiv(const struct clk_div_table *table)
35static unsigned int _get_table_maxdiv(const struct clk_div_table *table,
36 u8 width)
36{
37{
37 unsigned int maxdiv = 0;
38 unsigned int maxdiv = 0, mask = div_mask(width);
38 const struct clk_div_table *clkt;
39
40 for (clkt = table; clkt->div; clkt++)
39 const struct clk_div_table *clkt;
40
41 for (clkt = table; clkt->div; clkt++)
41 if (clkt->div > maxdiv)
42 if (clkt->div > maxdiv && clkt->val <= mask)
42 maxdiv = clkt->div;
43 return maxdiv;
44}
45
46static unsigned int _get_table_mindiv(const struct clk_div_table *table)
47{
48 unsigned int mindiv = UINT_MAX;
49 const struct clk_div_table *clkt;

--- 7 unchanged lines hidden (view full) ---

57static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width,
58 unsigned long flags)
59{
60 if (flags & CLK_DIVIDER_ONE_BASED)
61 return div_mask(width);
62 if (flags & CLK_DIVIDER_POWER_OF_TWO)
63 return 1 << div_mask(width);
64 if (table)
43 maxdiv = clkt->div;
44 return maxdiv;
45}
46
47static unsigned int _get_table_mindiv(const struct clk_div_table *table)
48{
49 unsigned int mindiv = UINT_MAX;
50 const struct clk_div_table *clkt;

--- 7 unchanged lines hidden (view full) ---

58static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width,
59 unsigned long flags)
60{
61 if (flags & CLK_DIVIDER_ONE_BASED)
62 return div_mask(width);
63 if (flags & CLK_DIVIDER_POWER_OF_TWO)
64 return 1 << div_mask(width);
65 if (table)
65 return _get_table_maxdiv(table);
66 return _get_table_maxdiv(table, width);
66 return div_mask(width) + 1;
67}
68
69static unsigned int _get_table_div(const struct clk_div_table *table,
70 unsigned int val)
71{
72 const struct clk_div_table *clkt;
73

--- 459 unchanged lines hidden ---
67 return div_mask(width) + 1;
68}
69
70static unsigned int _get_table_div(const struct clk_div_table *table,
71 unsigned int val)
72{
73 const struct clk_div_table *clkt;
74

--- 459 unchanged lines hidden ---