/* 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
* @oh: struct omap_hwmod *
*/
static int _init_interface_clks(struct omap_hwmod *oh)
{
+ struct omap_hwmod_ocp_if *os;
struct clk *c;
- int i;
+ int i = 0;
int ret = 0;
- if (oh->slaves_cnt == 0)
- return 0;
-
- for (i = 0; i < oh->slaves_cnt; i++) {
- struct omap_hwmod_ocp_if *os = oh->slaves[i];
-
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
if (!os->clk)
continue;
*/
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);
if (oh->_clk)
clk_enable(oh->_clk);
- if (oh->slaves_cnt > 0) {
- for (i = 0; i < oh->slaves_cnt; i++) {
- struct omap_hwmod_ocp_if *os = oh->slaves[i];
- struct clk *c = os->_clk;
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
- if (c && (os->flags & OCPIF_SWSUP_IDLE))
- clk_enable(c);
- }
+ if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
+ clk_enable(os->_clk);
}
/* The opt clocks are controlled by the device driver. */
*/
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);
if (oh->_clk)
clk_disable(oh->_clk);
- if (oh->slaves_cnt > 0) {
- for (i = 0; i < oh->slaves_cnt; i++) {
- struct omap_hwmod_ocp_if *os = oh->slaves[i];
- struct clk *c = os->_clk;
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
- if (c && (os->flags & OCPIF_SWSUP_IDLE))
- clk_disable(c);
- }
+ if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
+ clk_disable(os->_clk);
}
/* The opt clocks are controlled by the device driver. */
struct omap_hwmod_ocp_if *os;
bool found = false;
- for (i = 0; i < oh->slaves_cnt; i++) {
- os = oh->slaves[i];
+ i = 0;
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
if (!os->addr)
return -ENOENT;
*/
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;
- if (!oh || oh->slaves_cnt == 0)
+ if (!oh)
return -EINVAL;
- for (i = 0; i < oh->slaves_cnt; i++) {
- struct omap_hwmod_ocp_if *os = oh->slaves[i];
-
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
if (os->user & OCP_USER_MPU) {
found = 1;
break;
if (found)
pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
- oh->name, i);
+ oh->name, i - 1);
else
pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
oh->name);
- return (found) ? i : -EINVAL;
+ return (found) ? (i - 1) : -EINVAL;
}
/**
*/
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)
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;
if (os->flags & OCPIF_SWSUP_IDLE) {
/* XXX omap_iclk_deny_idle(c); */
} else {
/* XXX omap_iclk_allow_idle(c); */
- clk_enable(c);
+ clk_enable(os->_clk);
}
}
*/
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);
- for (i = 0; i < oh->slaves_cnt; i++)
- ret += _count_ocp_if_addr_spaces(oh->slaves[i]);
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
+ ret += _count_ocp_if_addr_spaces(os);
+ }
return ret;
}
*/
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;
/* For each IRQ, DMA, memory area, fill in array.*/
r++;
}
- for (i = 0; i < oh->slaves_cnt; i++) {
- struct omap_hwmod_ocp_if *os;
- int addr_cnt;
-
- os = oh->slaves[i];
+ i = 0;
+ while (i < oh->slaves_cnt) {
+ os = _fetch_next_ocp_if(NULL, oh->slaves, &i);
addr_cnt = _count_ocp_if_addr_spaces(os);
for (j = 0; j < addr_cnt; j++) {