提交 5d95dde7 编写于 作者: P Paul Walmsley

ARM: OMAP2+: hwmod: add function to iterate over struct omap_hwmod_ocp_if

To reduce the number of lines of data in the OMAP portion of the Linux
code base, subsequent patches will remove the lists of hwmod
interconnect links from the static hwmod data.  These lists will be
built dynamically during boot.  To ease this transition, this patch
centralizes the way that interconnect links are iterated into a single
function, _fetch_next_ocp_if().
Signed-off-by: NPaul Walmsley <paul@pwsan.com>
Cc: Benoît Cousson <b-cousson@ti.com>
上级 2d6141ba
...@@ -168,6 +168,29 @@ static struct omap_hwmod *mpu_oh; ...@@ -168,6 +168,29 @@ static struct omap_hwmod *mpu_oh;
/* Private functions */ /* Private functions */
/**
* _fetch_next_ocp_if - return @i'th OCP interface in an array
* @p: ptr to a ptr to the list_head inside the ocp_if to return (not yet used)
* @old: ptr to an array of struct omap_hwmod_ocp_if records
* @i: pointer to the index into the @old array
*
* Return a pointer to the next struct omap_hwmod_ocp_if record in a
* sequence. Currently returns a struct omap_hwmod_ocp_if record
* corresponding to the element index pointed to by @i in the @old
* array, and increments the index pointed to by @i.
*/
static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
struct omap_hwmod_ocp_if **old,
int *i)
{
struct omap_hwmod_ocp_if *oi;
oi = old[*i];
*i = *i + 1;
return oi;
}
/** /**
* _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
* @oh: struct omap_hwmod * * @oh: struct omap_hwmod *
...@@ -582,16 +605,13 @@ static int _init_main_clk(struct omap_hwmod *oh) ...@@ -582,16 +605,13 @@ static int _init_main_clk(struct omap_hwmod *oh)
*/ */
static int _init_interface_clks(struct omap_hwmod *oh) static int _init_interface_clks(struct omap_hwmod *oh)
{ {
struct omap_hwmod_ocp_if *os;
struct clk *c; struct clk *c;
int i; int i = 0;
int ret = 0; int ret = 0;
if (oh->slaves_cnt == 0) while (i < oh->slaves_cnt) {
return 0; os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
for (i = 0; i < oh->slaves_cnt; i++) {
struct omap_hwmod_ocp_if *os = oh->slaves[i];
if (!os->clk) if (!os->clk)
continue; continue;
...@@ -643,21 +663,19 @@ static int _init_opt_clks(struct omap_hwmod *oh) ...@@ -643,21 +663,19 @@ static int _init_opt_clks(struct omap_hwmod *oh)
*/ */
static int _enable_clocks(struct omap_hwmod *oh) static int _enable_clocks(struct omap_hwmod *oh)
{ {
int i; struct omap_hwmod_ocp_if *os;
int i = 0;
pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
if (oh->_clk) if (oh->_clk)
clk_enable(oh->_clk); clk_enable(oh->_clk);
if (oh->slaves_cnt > 0) { while (i < oh->slaves_cnt) {
for (i = 0; i < oh->slaves_cnt; i++) { os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
struct omap_hwmod_ocp_if *os = oh->slaves[i];
struct clk *c = os->_clk;
if (c && (os->flags & OCPIF_SWSUP_IDLE)) if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
clk_enable(c); clk_enable(os->_clk);
}
} }
/* The opt clocks are controlled by the device driver. */ /* The opt clocks are controlled by the device driver. */
...@@ -673,21 +691,19 @@ static int _enable_clocks(struct omap_hwmod *oh) ...@@ -673,21 +691,19 @@ static int _enable_clocks(struct omap_hwmod *oh)
*/ */
static int _disable_clocks(struct omap_hwmod *oh) static int _disable_clocks(struct omap_hwmod *oh)
{ {
int i; struct omap_hwmod_ocp_if *os;
int i = 0;
pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
if (oh->_clk) if (oh->_clk)
clk_disable(oh->_clk); clk_disable(oh->_clk);
if (oh->slaves_cnt > 0) { while (i < oh->slaves_cnt) {
for (i = 0; i < oh->slaves_cnt; i++) { os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
struct omap_hwmod_ocp_if *os = oh->slaves[i];
struct clk *c = os->_clk;
if (c && (os->flags & OCPIF_SWSUP_IDLE)) if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
clk_disable(c); clk_disable(os->_clk);
}
} }
/* The opt clocks are controlled by the device driver. */ /* The opt clocks are controlled by the device driver. */
...@@ -961,8 +977,9 @@ static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name, ...@@ -961,8 +977,9 @@ static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
struct omap_hwmod_ocp_if *os; struct omap_hwmod_ocp_if *os;
bool found = false; bool found = false;
for (i = 0; i < oh->slaves_cnt; i++) { i = 0;
os = oh->slaves[i]; while (i < oh->slaves_cnt) {
os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
if (!os->addr) if (!os->addr)
return -ENOENT; return -ENOENT;
...@@ -999,15 +1016,15 @@ static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name, ...@@ -999,15 +1016,15 @@ static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
*/ */
static int __init _find_mpu_port_index(struct omap_hwmod *oh) static int __init _find_mpu_port_index(struct omap_hwmod *oh)
{ {
int i; struct omap_hwmod_ocp_if *os;
int i = 0;
int found = 0; int found = 0;
if (!oh || oh->slaves_cnt == 0) if (!oh)
return -EINVAL; return -EINVAL;
for (i = 0; i < oh->slaves_cnt; i++) { while (i < oh->slaves_cnt) {
struct omap_hwmod_ocp_if *os = oh->slaves[i]; os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
if (os->user & OCP_USER_MPU) { if (os->user & OCP_USER_MPU) {
found = 1; found = 1;
break; break;
...@@ -1016,12 +1033,12 @@ static int __init _find_mpu_port_index(struct omap_hwmod *oh) ...@@ -1016,12 +1033,12 @@ static int __init _find_mpu_port_index(struct omap_hwmod *oh)
if (found) if (found)
pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n", pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
oh->name, i); oh->name, i - 1);
else else
pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n", pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
oh->name); oh->name);
return (found) ? i : -EINVAL; return (found) ? (i - 1) : -EINVAL;
} }
/** /**
...@@ -2027,23 +2044,22 @@ static int __init _init(struct omap_hwmod *oh, void *data) ...@@ -2027,23 +2044,22 @@ static int __init _init(struct omap_hwmod *oh, void *data)
*/ */
static void __init _setup_iclk_autoidle(struct omap_hwmod *oh) static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
{ {
int i; struct omap_hwmod_ocp_if *os;
int i = 0;
if (oh->_state != _HWMOD_STATE_INITIALIZED) if (oh->_state != _HWMOD_STATE_INITIALIZED)
return; return;
for (i = 0; i < oh->slaves_cnt; i++) {
struct omap_hwmod_ocp_if *os = oh->slaves[i];
struct clk *c = os->_clk;
if (!c) while (i < oh->slaves_cnt) {
os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
if (!os->_clk)
continue; continue;
if (os->flags & OCPIF_SWSUP_IDLE) { if (os->flags & OCPIF_SWSUP_IDLE) {
/* XXX omap_iclk_deny_idle(c); */ /* XXX omap_iclk_deny_idle(c); */
} else { } else {
/* XXX omap_iclk_allow_idle(c); */ /* XXX omap_iclk_allow_idle(c); */
clk_enable(c); clk_enable(os->_clk);
} }
} }
...@@ -2623,12 +2639,16 @@ int omap_hwmod_reset(struct omap_hwmod *oh) ...@@ -2623,12 +2639,16 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
*/ */
int omap_hwmod_count_resources(struct omap_hwmod *oh) int omap_hwmod_count_resources(struct omap_hwmod *oh)
{ {
int ret, i; struct omap_hwmod_ocp_if *os;
int ret;
int i = 0;
ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh); ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
for (i = 0; i < oh->slaves_cnt; i++) while (i < oh->slaves_cnt) {
ret += _count_ocp_if_addr_spaces(oh->slaves[i]); os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
ret += _count_ocp_if_addr_spaces(os);
}
return ret; return ret;
} }
...@@ -2645,7 +2665,8 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh) ...@@ -2645,7 +2665,8 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh)
*/ */
int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
{ {
int i, j, mpu_irqs_cnt, sdma_reqs_cnt; struct omap_hwmod_ocp_if *os;
int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
int r = 0; int r = 0;
/* For each IRQ, DMA, memory area, fill in array.*/ /* For each IRQ, DMA, memory area, fill in array.*/
...@@ -2668,11 +2689,9 @@ int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) ...@@ -2668,11 +2689,9 @@ int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
r++; r++;
} }
for (i = 0; i < oh->slaves_cnt; i++) { i = 0;
struct omap_hwmod_ocp_if *os; while (i < oh->slaves_cnt) {
int addr_cnt; os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
os = oh->slaves[i];
addr_cnt = _count_ocp_if_addr_spaces(os); addr_cnt = _count_ocp_if_addr_spaces(os);
for (j = 0; j < addr_cnt; j++) { for (j = 0; j < addr_cnt; j++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册