aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/omap_hwmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap2/omap_hwmod.c')
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c208
1 files changed, 20 insertions, 188 deletions
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 0da4f2ea76c4..8bcea0d83fa0 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -138,7 +138,6 @@
138#include <linux/mutex.h> 138#include <linux/mutex.h>
139#include <linux/spinlock.h> 139#include <linux/spinlock.h>
140#include <linux/slab.h> 140#include <linux/slab.h>
141#include <linux/bootmem.h>
142#include <linux/cpu.h> 141#include <linux/cpu.h>
143#include <linux/of.h> 142#include <linux/of.h>
144#include <linux/of_address.h> 143#include <linux/of_address.h>
@@ -216,49 +215,12 @@ static LIST_HEAD(omap_hwmod_list);
216/* mpu_oh: used to add/remove MPU initiator from sleepdep list */ 215/* mpu_oh: used to add/remove MPU initiator from sleepdep list */
217static struct omap_hwmod *mpu_oh; 216static struct omap_hwmod *mpu_oh;
218 217
219/*
220 * linkspace: ptr to a buffer that struct omap_hwmod_link records are
221 * allocated from - used to reduce the number of small memory
222 * allocations, which has a significant impact on performance
223 */
224static struct omap_hwmod_link *linkspace;
225
226/*
227 * free_ls, max_ls: array indexes into linkspace; representing the
228 * next free struct omap_hwmod_link index, and the maximum number of
229 * struct omap_hwmod_link records allocated (respectively)
230 */
231static unsigned short free_ls, max_ls, ls_supp;
232
233/* inited: set to true once the hwmod code is initialized */ 218/* inited: set to true once the hwmod code is initialized */
234static bool inited; 219static bool inited;
235 220
236/* Private functions */ 221/* Private functions */
237 222
238/** 223/**
239 * _fetch_next_ocp_if - return the next OCP interface in a list
240 * @p: ptr to a ptr to the list_head inside the ocp_if to return
241 * @i: pointer to the index of the element pointed to by @p in the list
242 *
243 * Return a pointer to the struct omap_hwmod_ocp_if record
244 * containing the struct list_head pointed to by @p, and increment
245 * @p such that a future call to this routine will return the next
246 * record.
247 */
248static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
249 int *i)
250{
251 struct omap_hwmod_ocp_if *oi;
252
253 oi = list_entry(*p, struct omap_hwmod_link, node)->ocp_if;
254 *p = (*p)->next;
255
256 *i = *i + 1;
257
258 return oi;
259}
260
261/**
262 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy 224 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
263 * @oh: struct omap_hwmod * 225 * @oh: struct omap_hwmod *
264 * 226 *
@@ -794,15 +756,10 @@ static int _init_main_clk(struct omap_hwmod *oh)
794static int _init_interface_clks(struct omap_hwmod *oh) 756static int _init_interface_clks(struct omap_hwmod *oh)
795{ 757{
796 struct omap_hwmod_ocp_if *os; 758 struct omap_hwmod_ocp_if *os;
797 struct list_head *p;
798 struct clk *c; 759 struct clk *c;
799 int i = 0;
800 int ret = 0; 760 int ret = 0;
801 761
802 p = oh->slave_ports.next; 762 list_for_each_entry(os, &oh->slave_ports, node) {
803
804 while (i < oh->slaves_cnt) {
805 os = _fetch_next_ocp_if(&p, &i);
806 if (!os->clk) 763 if (!os->clk)
807 continue; 764 continue;
808 765
@@ -905,19 +862,13 @@ static void _disable_optional_clocks(struct omap_hwmod *oh)
905static int _enable_clocks(struct omap_hwmod *oh) 862static int _enable_clocks(struct omap_hwmod *oh)
906{ 863{
907 struct omap_hwmod_ocp_if *os; 864 struct omap_hwmod_ocp_if *os;
908 struct list_head *p;
909 int i = 0;
910 865
911 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); 866 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
912 867
913 if (oh->_clk) 868 if (oh->_clk)
914 clk_enable(oh->_clk); 869 clk_enable(oh->_clk);
915 870
916 p = oh->slave_ports.next; 871 list_for_each_entry(os, &oh->slave_ports, node) {
917
918 while (i < oh->slaves_cnt) {
919 os = _fetch_next_ocp_if(&p, &i);
920
921 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE)) 872 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
922 clk_enable(os->_clk); 873 clk_enable(os->_clk);
923 } 874 }
@@ -939,19 +890,13 @@ static int _enable_clocks(struct omap_hwmod *oh)
939static int _disable_clocks(struct omap_hwmod *oh) 890static int _disable_clocks(struct omap_hwmod *oh)
940{ 891{
941 struct omap_hwmod_ocp_if *os; 892 struct omap_hwmod_ocp_if *os;
942 struct list_head *p;
943 int i = 0;
944 893
945 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); 894 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
946 895
947 if (oh->_clk) 896 if (oh->_clk)
948 clk_disable(oh->_clk); 897 clk_disable(oh->_clk);
949 898
950 p = oh->slave_ports.next; 899 list_for_each_entry(os, &oh->slave_ports, node) {
951
952 while (i < oh->slaves_cnt) {
953 os = _fetch_next_ocp_if(&p, &i);
954
955 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE)) 900 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
956 clk_disable(os->_clk); 901 clk_disable(os->_clk);
957 } 902 }
@@ -1190,16 +1135,11 @@ static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
1190static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name, 1135static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
1191 u32 *pa_start, u32 *pa_end) 1136 u32 *pa_start, u32 *pa_end)
1192{ 1137{
1193 int i, j; 1138 int j;
1194 struct omap_hwmod_ocp_if *os; 1139 struct omap_hwmod_ocp_if *os;
1195 struct list_head *p = NULL;
1196 bool found = false; 1140 bool found = false;
1197 1141
1198 p = oh->slave_ports.next; 1142 list_for_each_entry(os, &oh->slave_ports, node) {
1199
1200 i = 0;
1201 while (i < oh->slaves_cnt) {
1202 os = _fetch_next_ocp_if(&p, &i);
1203 1143
1204 if (!os->addr) 1144 if (!os->addr)
1205 return -ENOENT; 1145 return -ENOENT;
@@ -1239,18 +1179,13 @@ static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
1239static void __init _save_mpu_port_index(struct omap_hwmod *oh) 1179static void __init _save_mpu_port_index(struct omap_hwmod *oh)
1240{ 1180{
1241 struct omap_hwmod_ocp_if *os = NULL; 1181 struct omap_hwmod_ocp_if *os = NULL;
1242 struct list_head *p;
1243 int i = 0;
1244 1182
1245 if (!oh) 1183 if (!oh)
1246 return; 1184 return;
1247 1185
1248 oh->_int_flags |= _HWMOD_NO_MPU_PORT; 1186 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
1249 1187
1250 p = oh->slave_ports.next; 1188 list_for_each_entry(os, &oh->slave_ports, node) {
1251
1252 while (i < oh->slaves_cnt) {
1253 os = _fetch_next_ocp_if(&p, &i);
1254 if (os->user & OCP_USER_MPU) { 1189 if (os->user & OCP_USER_MPU) {
1255 oh->_mpu_port = os; 1190 oh->_mpu_port = os;
1256 oh->_int_flags &= ~_HWMOD_NO_MPU_PORT; 1191 oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
@@ -1393,7 +1328,7 @@ static void _enable_sysc(struct omap_hwmod *oh)
1393 */ 1328 */
1394 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) && 1329 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
1395 (sf & SYSC_HAS_CLOCKACTIVITY)) 1330 (sf & SYSC_HAS_CLOCKACTIVITY))
1396 _set_clockactivity(oh, oh->class->sysc->clockact, &v); 1331 _set_clockactivity(oh, CLOCKACT_TEST_ICLK, &v);
1397 1332
1398 _write_sysconfig(v, oh); 1333 _write_sysconfig(v, oh);
1399 1334
@@ -2092,7 +2027,7 @@ static int _enable(struct omap_hwmod *oh)
2092 2027
2093 r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) : 2028 r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
2094 -EINVAL; 2029 -EINVAL;
2095 if (oh->clkdm) 2030 if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
2096 clkdm_allow_idle(oh->clkdm); 2031 clkdm_allow_idle(oh->clkdm);
2097 2032
2098 if (!r) { 2033 if (!r) {
@@ -2149,7 +2084,12 @@ static int _idle(struct omap_hwmod *oh)
2149 _idle_sysc(oh); 2084 _idle_sysc(oh);
2150 _del_initiator_dep(oh, mpu_oh); 2085 _del_initiator_dep(oh, mpu_oh);
2151 2086
2152 if (oh->clkdm) 2087 /*
2088 * If HWMOD_CLKDM_NOAUTO is set then we don't
2089 * deny idle the clkdm again since idle was already denied
2090 * in _enable()
2091 */
2092 if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
2153 clkdm_deny_idle(oh->clkdm); 2093 clkdm_deny_idle(oh->clkdm);
2154 2094
2155 if (oh->flags & HWMOD_BLOCK_WFI) 2095 if (oh->flags & HWMOD_BLOCK_WFI)
@@ -2451,15 +2391,11 @@ static int __init _init(struct omap_hwmod *oh, void *data)
2451static void __init _setup_iclk_autoidle(struct omap_hwmod *oh) 2391static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
2452{ 2392{
2453 struct omap_hwmod_ocp_if *os; 2393 struct omap_hwmod_ocp_if *os;
2454 struct list_head *p; 2394
2455 int i = 0;
2456 if (oh->_state != _HWMOD_STATE_INITIALIZED) 2395 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2457 return; 2396 return;
2458 2397
2459 p = oh->slave_ports.next; 2398 list_for_each_entry(os, &oh->slave_ports, node) {
2460
2461 while (i < oh->slaves_cnt) {
2462 os = _fetch_next_ocp_if(&p, &i);
2463 if (!os->_clk) 2399 if (!os->_clk)
2464 continue; 2400 continue;
2465 2401
@@ -2657,7 +2593,6 @@ static int __init _register(struct omap_hwmod *oh)
2657 2593
2658 list_add_tail(&oh->node, &omap_hwmod_list); 2594 list_add_tail(&oh->node, &omap_hwmod_list);
2659 2595
2660 INIT_LIST_HEAD(&oh->master_ports);
2661 INIT_LIST_HEAD(&oh->slave_ports); 2596 INIT_LIST_HEAD(&oh->slave_ports);
2662 spin_lock_init(&oh->_lock); 2597 spin_lock_init(&oh->_lock);
2663 lockdep_set_class(&oh->_lock, &oh->hwmod_key); 2598 lockdep_set_class(&oh->_lock, &oh->hwmod_key);
@@ -2675,49 +2610,10 @@ static int __init _register(struct omap_hwmod *oh)
2675} 2610}
2676 2611
2677/** 2612/**
2678 * _alloc_links - return allocated memory for hwmod links
2679 * @ml: pointer to a struct omap_hwmod_link * for the master link
2680 * @sl: pointer to a struct omap_hwmod_link * for the slave link
2681 *
2682 * Return pointers to two struct omap_hwmod_link records, via the
2683 * addresses pointed to by @ml and @sl. Will first attempt to return
2684 * memory allocated as part of a large initial block, but if that has
2685 * been exhausted, will allocate memory itself. Since ideally this
2686 * second allocation path will never occur, the number of these
2687 * 'supplemental' allocations will be logged when debugging is
2688 * enabled. Returns 0.
2689 */
2690static int __init _alloc_links(struct omap_hwmod_link **ml,
2691 struct omap_hwmod_link **sl)
2692{
2693 unsigned int sz;
2694
2695 if ((free_ls + LINKS_PER_OCP_IF) <= max_ls) {
2696 *ml = &linkspace[free_ls++];
2697 *sl = &linkspace[free_ls++];
2698 return 0;
2699 }
2700
2701 sz = sizeof(struct omap_hwmod_link) * LINKS_PER_OCP_IF;
2702
2703 *sl = NULL;
2704 *ml = memblock_virt_alloc(sz, 0);
2705
2706 *sl = (void *)(*ml) + sizeof(struct omap_hwmod_link);
2707
2708 ls_supp++;
2709 pr_debug("omap_hwmod: supplemental link allocations needed: %d\n",
2710 ls_supp * LINKS_PER_OCP_IF);
2711
2712 return 0;
2713};
2714
2715/**
2716 * _add_link - add an interconnect between two IP blocks 2613 * _add_link - add an interconnect between two IP blocks
2717 * @oi: pointer to a struct omap_hwmod_ocp_if record 2614 * @oi: pointer to a struct omap_hwmod_ocp_if record
2718 * 2615 *
2719 * Add struct omap_hwmod_link records connecting the master IP block 2616 * Add struct omap_hwmod_link records connecting the slave IP block
2720 * specified in @oi->master to @oi, and connecting the slave IP block
2721 * specified in @oi->slave to @oi. This code is assumed to run before 2617 * specified in @oi->slave to @oi. This code is assumed to run before
2722 * preemption or SMP has been enabled, thus avoiding the need for 2618 * preemption or SMP has been enabled, thus avoiding the need for
2723 * locking in this code. Changes to this assumption will require 2619 * locking in this code. Changes to this assumption will require
@@ -2725,19 +2621,10 @@ static int __init _alloc_links(struct omap_hwmod_link **ml,
2725 */ 2621 */
2726static int __init _add_link(struct omap_hwmod_ocp_if *oi) 2622static int __init _add_link(struct omap_hwmod_ocp_if *oi)
2727{ 2623{
2728 struct omap_hwmod_link *ml, *sl;
2729
2730 pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name, 2624 pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2731 oi->slave->name); 2625 oi->slave->name);
2732 2626
2733 _alloc_links(&ml, &sl); 2627 list_add(&oi->node, &oi->slave->slave_ports);
2734
2735 ml->ocp_if = oi;
2736 list_add(&ml->node, &oi->master->master_ports);
2737 oi->master->masters_cnt++;
2738
2739 sl->ocp_if = oi;
2740 list_add(&sl->node, &oi->slave->slave_ports);
2741 oi->slave->slaves_cnt++; 2628 oi->slave->slaves_cnt++;
2742 2629
2743 return 0; 2630 return 0;
@@ -2784,45 +2671,6 @@ static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2784 return 0; 2671 return 0;
2785} 2672}
2786 2673
2787/**
2788 * _alloc_linkspace - allocate large block of hwmod links
2789 * @ois: pointer to an array of struct omap_hwmod_ocp_if records to count
2790 *
2791 * Allocate a large block of struct omap_hwmod_link records. This
2792 * improves boot time significantly by avoiding the need to allocate
2793 * individual records one by one. If the number of records to
2794 * allocate in the block hasn't been manually specified, this function
2795 * will count the number of struct omap_hwmod_ocp_if records in @ois
2796 * and use that to determine the allocation size. For SoC families
2797 * that require multiple list registrations, such as OMAP3xxx, this
2798 * estimation process isn't optimal, so manual estimation is advised
2799 * in those cases. Returns -EEXIST if the allocation has already occurred
2800 * or 0 upon success.
2801 */
2802static int __init _alloc_linkspace(struct omap_hwmod_ocp_if **ois)
2803{
2804 unsigned int i = 0;
2805 unsigned int sz;
2806
2807 if (linkspace) {
2808 WARN(1, "linkspace already allocated\n");
2809 return -EEXIST;
2810 }
2811
2812 if (max_ls == 0)
2813 while (ois[i++])
2814 max_ls += LINKS_PER_OCP_IF;
2815
2816 sz = sizeof(struct omap_hwmod_link) * max_ls;
2817
2818 pr_debug("omap_hwmod: %s: allocating %d byte linkspace (%d links)\n",
2819 __func__, sz, max_ls);
2820
2821 linkspace = memblock_virt_alloc(sz, 0);
2822
2823 return 0;
2824}
2825
2826/* Static functions intended only for use in soc_ops field function pointers */ 2674/* Static functions intended only for use in soc_ops field function pointers */
2827 2675
2828/** 2676/**
@@ -3180,13 +3028,6 @@ int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3180 if (ois[0] == NULL) /* Empty list */ 3028 if (ois[0] == NULL) /* Empty list */
3181 return 0; 3029 return 0;
3182 3030
3183 if (!linkspace) {
3184 if (_alloc_linkspace(ois)) {
3185 pr_err("omap_hwmod: could not allocate link space\n");
3186 return -ENOMEM;
3187 }
3188 }
3189
3190 i = 0; 3031 i = 0;
3191 do { 3032 do {
3192 r = _register_link(ois[i]); 3033 r = _register_link(ois[i]);
@@ -3398,14 +3239,10 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
3398 ret += _count_sdma_reqs(oh); 3239 ret += _count_sdma_reqs(oh);
3399 3240
3400 if (flags & IORESOURCE_MEM) { 3241 if (flags & IORESOURCE_MEM) {
3401 int i = 0;
3402 struct omap_hwmod_ocp_if *os; 3242 struct omap_hwmod_ocp_if *os;
3403 struct list_head *p = oh->slave_ports.next;
3404 3243
3405 while (i < oh->slaves_cnt) { 3244 list_for_each_entry(os, &oh->slave_ports, node)
3406 os = _fetch_next_ocp_if(&p, &i);
3407 ret += _count_ocp_if_addr_spaces(os); 3245 ret += _count_ocp_if_addr_spaces(os);
3408 }
3409 } 3246 }
3410 3247
3411 return ret; 3248 return ret;
@@ -3424,7 +3261,6 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
3424int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) 3261int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3425{ 3262{
3426 struct omap_hwmod_ocp_if *os; 3263 struct omap_hwmod_ocp_if *os;
3427 struct list_head *p;
3428 int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt; 3264 int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
3429 int r = 0; 3265 int r = 0;
3430 3266
@@ -3454,11 +3290,7 @@ int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3454 r++; 3290 r++;
3455 } 3291 }
3456 3292
3457 p = oh->slave_ports.next; 3293 list_for_each_entry(os, &oh->slave_ports, node) {
3458
3459 i = 0;
3460 while (i < oh->slaves_cnt) {
3461 os = _fetch_next_ocp_if(&p, &i);
3462 addr_cnt = _count_ocp_if_addr_spaces(os); 3294 addr_cnt = _count_ocp_if_addr_spaces(os);
3463 3295
3464 for (j = 0; j < addr_cnt; j++) { 3296 for (j = 0; j < addr_cnt; j++) {