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.c599
1 files changed, 496 insertions, 103 deletions
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index cb911d7d1a3c..5a30658444d0 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -13,10 +13,102 @@
13 * it under the terms of the GNU General Public License version 2 as 13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation. 14 * published by the Free Software Foundation.
15 * 15 *
16 * This code manages "OMAP modules" (on-chip devices) and their 16 * Introduction
17 * integration with Linux device driver and bus code. 17 * ------------
18 * 18 * One way to view an OMAP SoC is as a collection of largely unrelated
19 * References: 19 * IP blocks connected by interconnects. The IP blocks include
20 * devices such as ARM processors, audio serial interfaces, UARTs,
21 * etc. Some of these devices, like the DSP, are created by TI;
22 * others, like the SGX, largely originate from external vendors. In
23 * TI's documentation, on-chip devices are referred to as "OMAP
24 * modules." Some of these IP blocks are identical across several
25 * OMAP versions. Others are revised frequently.
26 *
27 * These OMAP modules are tied together by various interconnects.
28 * Most of the address and data flow between modules is via OCP-based
29 * interconnects such as the L3 and L4 buses; but there are other
30 * interconnects that distribute the hardware clock tree, handle idle
31 * and reset signaling, supply power, and connect the modules to
32 * various pads or balls on the OMAP package.
33 *
34 * OMAP hwmod provides a consistent way to describe the on-chip
35 * hardware blocks and their integration into the rest of the chip.
36 * This description can be automatically generated from the TI
37 * hardware database. OMAP hwmod provides a standard, consistent API
38 * to reset, enable, idle, and disable these hardware blocks. And
39 * hwmod provides a way for other core code, such as the Linux device
40 * code or the OMAP power management and address space mapping code,
41 * to query the hardware database.
42 *
43 * Using hwmod
44 * -----------
45 * Drivers won't call hwmod functions directly. That is done by the
46 * omap_device code, and in rare occasions, by custom integration code
47 * in arch/arm/ *omap*. The omap_device code includes functions to
48 * build a struct platform_device using omap_hwmod data, and that is
49 * currently how hwmod data is communicated to drivers and to the
50 * Linux driver model. Most drivers will call omap_hwmod functions only
51 * indirectly, via pm_runtime*() functions.
52 *
53 * From a layering perspective, here is where the OMAP hwmod code
54 * fits into the kernel software stack:
55 *
56 * +-------------------------------+
57 * | Device driver code |
58 * | (e.g., drivers/) |
59 * +-------------------------------+
60 * | Linux driver model |
61 * | (platform_device / |
62 * | platform_driver data/code) |
63 * +-------------------------------+
64 * | OMAP core-driver integration |
65 * |(arch/arm/mach-omap2/devices.c)|
66 * +-------------------------------+
67 * | omap_device code |
68 * | (../plat-omap/omap_device.c) |
69 * +-------------------------------+
70 * ----> | omap_hwmod code/data | <-----
71 * | (../mach-omap2/omap_hwmod*) |
72 * +-------------------------------+
73 * | OMAP clock/PRCM/register fns |
74 * | (__raw_{read,write}l, clk*) |
75 * +-------------------------------+
76 *
77 * Device drivers should not contain any OMAP-specific code or data in
78 * them. They should only contain code to operate the IP block that
79 * the driver is responsible for. This is because these IP blocks can
80 * also appear in other SoCs, either from TI (such as DaVinci) or from
81 * other manufacturers; and drivers should be reusable across other
82 * platforms.
83 *
84 * The OMAP hwmod code also will attempt to reset and idle all on-chip
85 * devices upon boot. The goal here is for the kernel to be
86 * completely self-reliant and independent from bootloaders. This is
87 * to ensure a repeatable configuration, both to ensure consistent
88 * runtime behavior, and to make it easier for others to reproduce
89 * bugs.
90 *
91 * OMAP module activity states
92 * ---------------------------
93 * The hwmod code considers modules to be in one of several activity
94 * states. IP blocks start out in an UNKNOWN state, then once they
95 * are registered via the hwmod code, proceed to the REGISTERED state.
96 * Once their clock names are resolved to clock pointers, the module
97 * enters the CLKS_INITED state; and finally, once the module has been
98 * reset and the integration registers programmed, the INITIALIZED state
99 * is entered. The hwmod code will then place the module into either
100 * the IDLE state to save power, or in the case of a critical system
101 * module, the ENABLED state.
102 *
103 * OMAP core integration code can then call omap_hwmod*() functions
104 * directly to move the module between the IDLE, ENABLED, and DISABLED
105 * states, as needed. This is done during both the PM idle loop, and
106 * in the OMAP core integration code's implementation of the PM runtime
107 * functions.
108 *
109 * References
110 * ----------
111 * This is a partial list.
20 * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064) 112 * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
21 * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090) 113 * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
22 * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108) 114 * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
@@ -50,11 +142,13 @@
50#include <plat/powerdomain.h> 142#include <plat/powerdomain.h>
51#include <plat/clock.h> 143#include <plat/clock.h>
52#include <plat/omap_hwmod.h> 144#include <plat/omap_hwmod.h>
145#include <plat/prcm.h>
53 146
54#include "cm.h" 147#include "cm.h"
148#include "prm.h"
55 149
56/* Maximum microseconds to wait for OMAP module to reset */ 150/* Maximum microseconds to wait for OMAP module to softreset */
57#define MAX_MODULE_RESET_WAIT 10000 151#define MAX_MODULE_SOFTRESET_WAIT 10000
58 152
59/* Name of the OMAP hwmod for the MPU */ 153/* Name of the OMAP hwmod for the MPU */
60#define MPU_INITIATOR_NAME "mpu" 154#define MPU_INITIATOR_NAME "mpu"
@@ -90,7 +184,7 @@ static int _update_sysc_cache(struct omap_hwmod *oh)
90 184
91 /* XXX ensure module interface clock is up */ 185 /* XXX ensure module interface clock is up */
92 186
93 oh->_sysc_cache = omap_hwmod_readl(oh, oh->class->sysc->sysc_offs); 187 oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
94 188
95 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE)) 189 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
96 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED; 190 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
@@ -117,7 +211,7 @@ static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
117 211
118 if (oh->_sysc_cache != v) { 212 if (oh->_sysc_cache != v) {
119 oh->_sysc_cache = v; 213 oh->_sysc_cache = v;
120 omap_hwmod_writel(v, oh, oh->class->sysc->sysc_offs); 214 omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
121 } 215 }
122} 216}
123 217
@@ -544,6 +638,36 @@ static int _disable_clocks(struct omap_hwmod *oh)
544 return 0; 638 return 0;
545} 639}
546 640
641static void _enable_optional_clocks(struct omap_hwmod *oh)
642{
643 struct omap_hwmod_opt_clk *oc;
644 int i;
645
646 pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
647
648 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
649 if (oc->_clk) {
650 pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
651 oc->_clk->name);
652 clk_enable(oc->_clk);
653 }
654}
655
656static void _disable_optional_clocks(struct omap_hwmod *oh)
657{
658 struct omap_hwmod_opt_clk *oc;
659 int i;
660
661 pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
662
663 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
664 if (oc->_clk) {
665 pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
666 oc->_clk->name);
667 clk_disable(oc->_clk);
668 }
669}
670
547/** 671/**
548 * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use 672 * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
549 * @oh: struct omap_hwmod * 673 * @oh: struct omap_hwmod *
@@ -622,7 +746,7 @@ static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
622} 746}
623 747
624/** 748/**
625 * _sysc_enable - try to bring a module out of idle via OCP_SYSCONFIG 749 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
626 * @oh: struct omap_hwmod * 750 * @oh: struct omap_hwmod *
627 * 751 *
628 * If module is marked as SWSUP_SIDLE, force the module out of slave 752 * If module is marked as SWSUP_SIDLE, force the module out of slave
@@ -630,7 +754,7 @@ static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
630 * as SWSUP_MSUSPEND, force the module out of master standby; 754 * as SWSUP_MSUSPEND, force the module out of master standby;
631 * otherwise, configure it for smart-standby. No return value. 755 * otherwise, configure it for smart-standby. No return value.
632 */ 756 */
633static void _sysc_enable(struct omap_hwmod *oh) 757static void _enable_sysc(struct omap_hwmod *oh)
634{ 758{
635 u8 idlemode, sf; 759 u8 idlemode, sf;
636 u32 v; 760 u32 v;
@@ -653,14 +777,6 @@ static void _sysc_enable(struct omap_hwmod *oh)
653 _set_master_standbymode(oh, idlemode, &v); 777 _set_master_standbymode(oh, idlemode, &v);
654 } 778 }
655 779
656 if (sf & SYSC_HAS_AUTOIDLE) {
657 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
658 0 : 1;
659 _set_module_autoidle(oh, idlemode, &v);
660 }
661
662 /* XXX OCP ENAWAKEUP bit? */
663
664 /* 780 /*
665 * XXX The clock framework should handle this, by 781 * XXX The clock framework should handle this, by
666 * calling into this code. But this must wait until the 782 * calling into this code. But this must wait until the
@@ -671,10 +787,25 @@ static void _sysc_enable(struct omap_hwmod *oh)
671 _set_clockactivity(oh, oh->class->sysc->clockact, &v); 787 _set_clockactivity(oh, oh->class->sysc->clockact, &v);
672 788
673 _write_sysconfig(v, oh); 789 _write_sysconfig(v, oh);
790
791 /* If slave is in SMARTIDLE, also enable wakeup */
792 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
793 _enable_wakeup(oh);
794
795 /*
796 * Set the autoidle bit only after setting the smartidle bit
797 * Setting this will not have any impact on the other modules.
798 */
799 if (sf & SYSC_HAS_AUTOIDLE) {
800 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
801 0 : 1;
802 _set_module_autoidle(oh, idlemode, &v);
803 _write_sysconfig(v, oh);
804 }
674} 805}
675 806
676/** 807/**
677 * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG 808 * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
678 * @oh: struct omap_hwmod * 809 * @oh: struct omap_hwmod *
679 * 810 *
680 * If module is marked as SWSUP_SIDLE, force the module into slave 811 * If module is marked as SWSUP_SIDLE, force the module into slave
@@ -682,7 +813,7 @@ static void _sysc_enable(struct omap_hwmod *oh)
682 * as SWSUP_MSUSPEND, force the module into master standby; otherwise, 813 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
683 * configure it for smart-standby. No return value. 814 * configure it for smart-standby. No return value.
684 */ 815 */
685static void _sysc_idle(struct omap_hwmod *oh) 816static void _idle_sysc(struct omap_hwmod *oh)
686{ 817{
687 u8 idlemode, sf; 818 u8 idlemode, sf;
688 u32 v; 819 u32 v;
@@ -709,13 +840,13 @@ static void _sysc_idle(struct omap_hwmod *oh)
709} 840}
710 841
711/** 842/**
712 * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG 843 * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
713 * @oh: struct omap_hwmod * 844 * @oh: struct omap_hwmod *
714 * 845 *
715 * Force the module into slave idle and master suspend. No return 846 * Force the module into slave idle and master suspend. No return
716 * value. 847 * value.
717 */ 848 */
718static void _sysc_shutdown(struct omap_hwmod *oh) 849static void _shutdown_sysc(struct omap_hwmod *oh)
719{ 850{
720 u32 v; 851 u32 v;
721 u8 sf; 852 u8 sf;
@@ -767,10 +898,10 @@ static struct omap_hwmod *_lookup(const char *name)
767 * @data: not used; pass NULL 898 * @data: not used; pass NULL
768 * 899 *
769 * Called by omap_hwmod_late_init() (after omap2_clk_init()). 900 * Called by omap_hwmod_late_init() (after omap2_clk_init()).
770 * Resolves all clock names embedded in the hwmod. Must be called 901 * Resolves all clock names embedded in the hwmod. Returns -EINVAL if
771 * with omap_hwmod_mutex held. Returns -EINVAL if the omap_hwmod 902 * the omap_hwmod has not yet been registered or if the clocks have
772 * has not yet been registered or if the clocks have already been 903 * already been initialized, 0 on success, or a non-zero error on
773 * initialized, 0 on success, or a non-zero error on failure. 904 * failure.
774 */ 905 */
775static int _init_clocks(struct omap_hwmod *oh, void *data) 906static int _init_clocks(struct omap_hwmod *oh, void *data)
776{ 907{
@@ -834,56 +965,202 @@ static int _wait_target_ready(struct omap_hwmod *oh)
834} 965}
835 966
836/** 967/**
968 * _lookup_hardreset - return the register bit shift for this hwmod/reset line
969 * @oh: struct omap_hwmod *
970 * @name: name of the reset line in the context of this hwmod
971 *
972 * Return the bit position of the reset line that match the
973 * input name. Return -ENOENT if not found.
974 */
975static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name)
976{
977 int i;
978
979 for (i = 0; i < oh->rst_lines_cnt; i++) {
980 const char *rst_line = oh->rst_lines[i].name;
981 if (!strcmp(rst_line, name)) {
982 u8 shift = oh->rst_lines[i].rst_shift;
983 pr_debug("omap_hwmod: %s: _lookup_hardreset: %s: %d\n",
984 oh->name, rst_line, shift);
985
986 return shift;
987 }
988 }
989
990 return -ENOENT;
991}
992
993/**
994 * _assert_hardreset - assert the HW reset line of submodules
995 * contained in the hwmod module.
996 * @oh: struct omap_hwmod *
997 * @name: name of the reset line to lookup and assert
998 *
999 * Some IP like dsp, ipu or iva contain processor that require
1000 * an HW reset line to be assert / deassert in order to enable fully
1001 * the IP.
1002 */
1003static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1004{
1005 u8 shift;
1006
1007 if (!oh)
1008 return -EINVAL;
1009
1010 shift = _lookup_hardreset(oh, name);
1011 if (IS_ERR_VALUE(shift))
1012 return shift;
1013
1014 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1015 return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
1016 shift);
1017 else if (cpu_is_omap44xx())
1018 return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg,
1019 shift);
1020 else
1021 return -EINVAL;
1022}
1023
1024/**
1025 * _deassert_hardreset - deassert the HW reset line of submodules contained
1026 * in the hwmod module.
1027 * @oh: struct omap_hwmod *
1028 * @name: name of the reset line to look up and deassert
1029 *
1030 * Some IP like dsp, ipu or iva contain processor that require
1031 * an HW reset line to be assert / deassert in order to enable fully
1032 * the IP.
1033 */
1034static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1035{
1036 u8 shift;
1037 int r;
1038
1039 if (!oh)
1040 return -EINVAL;
1041
1042 shift = _lookup_hardreset(oh, name);
1043 if (IS_ERR_VALUE(shift))
1044 return shift;
1045
1046 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1047 r = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
1048 shift);
1049 else if (cpu_is_omap44xx())
1050 r = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg,
1051 shift);
1052 else
1053 return -EINVAL;
1054
1055 if (r == -EBUSY)
1056 pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
1057
1058 return r;
1059}
1060
1061/**
1062 * _read_hardreset - read the HW reset line state of submodules
1063 * contained in the hwmod module
1064 * @oh: struct omap_hwmod *
1065 * @name: name of the reset line to look up and read
1066 *
1067 * Return the state of the reset line.
1068 */
1069static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1070{
1071 u8 shift;
1072
1073 if (!oh)
1074 return -EINVAL;
1075
1076 shift = _lookup_hardreset(oh, name);
1077 if (IS_ERR_VALUE(shift))
1078 return shift;
1079
1080 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1081 return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
1082 shift);
1083 } else if (cpu_is_omap44xx()) {
1084 return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg,
1085 shift);
1086 } else {
1087 return -EINVAL;
1088 }
1089}
1090
1091/**
837 * _reset - reset an omap_hwmod 1092 * _reset - reset an omap_hwmod
838 * @oh: struct omap_hwmod * 1093 * @oh: struct omap_hwmod *
839 * 1094 *
840 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be 1095 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
841 * enabled for this to work. Must be called with omap_hwmod_mutex 1096 * enabled for this to work. Returns -EINVAL if the hwmod cannot be
842 * held. Returns -EINVAL if the hwmod cannot be reset this way or if 1097 * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
843 * the hwmod is in the wrong state, -ETIMEDOUT if the module did not 1098 * the module did not reset in time, or 0 upon success.
844 * reset in time, or 0 upon success. 1099 *
1100 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
1101 * Starting in OMAP4, some IPs does not have SYSSTATUS register and instead
1102 * use the SYSCONFIG softreset bit to provide the status.
1103 *
1104 * Note that some IP like McBSP does have a reset control but no reset status.
845 */ 1105 */
846static int _reset(struct omap_hwmod *oh) 1106static int _reset(struct omap_hwmod *oh)
847{ 1107{
848 u32 r, v; 1108 u32 v;
849 int c = 0; 1109 int c = 0;
1110 int ret = 0;
850 1111
851 if (!oh->class->sysc || 1112 if (!oh->class->sysc ||
852 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET) || 1113 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
853 (oh->class->sysc->sysc_flags & SYSS_MISSING))
854 return -EINVAL; 1114 return -EINVAL;
855 1115
856 /* clocks must be on for this operation */ 1116 /* clocks must be on for this operation */
857 if (oh->_state != _HWMOD_STATE_ENABLED) { 1117 if (oh->_state != _HWMOD_STATE_ENABLED) {
858 WARN(1, "omap_hwmod: %s: reset can only be entered from " 1118 pr_warning("omap_hwmod: %s: reset can only be entered from "
859 "enabled state\n", oh->name); 1119 "enabled state\n", oh->name);
860 return -EINVAL; 1120 return -EINVAL;
861 } 1121 }
862 1122
1123 /* For some modules, all optionnal clocks need to be enabled as well */
1124 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1125 _enable_optional_clocks(oh);
1126
863 pr_debug("omap_hwmod: %s: resetting\n", oh->name); 1127 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
864 1128
865 v = oh->_sysc_cache; 1129 v = oh->_sysc_cache;
866 r = _set_softreset(oh, &v); 1130 ret = _set_softreset(oh, &v);
867 if (r) 1131 if (ret)
868 return r; 1132 goto dis_opt_clks;
869 _write_sysconfig(v, oh); 1133 _write_sysconfig(v, oh);
870 1134
871 omap_test_timeout((omap_hwmod_readl(oh, oh->class->sysc->syss_offs) & 1135 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
872 SYSS_RESETDONE_MASK), 1136 omap_test_timeout((omap_hwmod_read(oh,
873 MAX_MODULE_RESET_WAIT, c); 1137 oh->class->sysc->syss_offs)
874 1138 & SYSS_RESETDONE_MASK),
875 if (c == MAX_MODULE_RESET_WAIT) 1139 MAX_MODULE_SOFTRESET_WAIT, c);
876 WARN(1, "omap_hwmod: %s: failed to reset in %d usec\n", 1140 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS)
877 oh->name, MAX_MODULE_RESET_WAIT); 1141 omap_test_timeout(!(omap_hwmod_read(oh,
1142 oh->class->sysc->sysc_offs)
1143 & SYSC_TYPE2_SOFTRESET_MASK),
1144 MAX_MODULE_SOFTRESET_WAIT, c);
1145
1146 if (c == MAX_MODULE_SOFTRESET_WAIT)
1147 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1148 oh->name, MAX_MODULE_SOFTRESET_WAIT);
878 else 1149 else
879 pr_debug("omap_hwmod: %s: reset in %d usec\n", oh->name, c); 1150 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
880 1151
881 /* 1152 /*
882 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from 1153 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
883 * _wait_target_ready() or _reset() 1154 * _wait_target_ready() or _reset()
884 */ 1155 */
885 1156
886 return (c == MAX_MODULE_RESET_WAIT) ? -ETIMEDOUT : 0; 1157 ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
1158
1159dis_opt_clks:
1160 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1161 _disable_optional_clocks(oh);
1162
1163 return ret;
887} 1164}
888 1165
889/** 1166/**
@@ -891,9 +1168,11 @@ static int _reset(struct omap_hwmod *oh)
891 * @oh: struct omap_hwmod * 1168 * @oh: struct omap_hwmod *
892 * 1169 *
893 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's 1170 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
894 * register target. Must be called with omap_hwmod_mutex held. 1171 * register target. (This function has a full name --
895 * Returns -EINVAL if the hwmod is in the wrong state or passes along 1172 * _omap_hwmod_enable() rather than simply _enable() -- because it is
896 * the return value of _wait_target_ready(). 1173 * currently required by the pm34xx.c idle loop.) Returns -EINVAL if
1174 * the hwmod is in the wrong state or passes along the return value of
1175 * _wait_target_ready().
897 */ 1176 */
898int _omap_hwmod_enable(struct omap_hwmod *oh) 1177int _omap_hwmod_enable(struct omap_hwmod *oh)
899{ 1178{
@@ -909,6 +1188,15 @@ int _omap_hwmod_enable(struct omap_hwmod *oh)
909 1188
910 pr_debug("omap_hwmod: %s: enabling\n", oh->name); 1189 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
911 1190
1191 /*
1192 * If an IP contains only one HW reset line, then de-assert it in order
1193 * to allow to enable the clocks. Otherwise the PRCM will return
1194 * Intransition status, and the init will failed.
1195 */
1196 if ((oh->_state == _HWMOD_STATE_INITIALIZED ||
1197 oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
1198 _deassert_hardreset(oh, oh->rst_lines[0].name);
1199
912 /* XXX mux balls */ 1200 /* XXX mux balls */
913 1201
914 _add_initiator_dep(oh, mpu_oh); 1202 _add_initiator_dep(oh, mpu_oh);
@@ -922,7 +1210,7 @@ int _omap_hwmod_enable(struct omap_hwmod *oh)
922 if (oh->class->sysc) { 1210 if (oh->class->sysc) {
923 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED)) 1211 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
924 _update_sysc_cache(oh); 1212 _update_sysc_cache(oh);
925 _sysc_enable(oh); 1213 _enable_sysc(oh);
926 } 1214 }
927 } else { 1215 } else {
928 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n", 1216 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
@@ -933,12 +1221,14 @@ int _omap_hwmod_enable(struct omap_hwmod *oh)
933} 1221}
934 1222
935/** 1223/**
936 * _idle - idle an omap_hwmod 1224 * _omap_hwmod_idle - idle an omap_hwmod
937 * @oh: struct omap_hwmod * 1225 * @oh: struct omap_hwmod *
938 * 1226 *
939 * Idles an omap_hwmod @oh. This should be called once the hwmod has 1227 * Idles an omap_hwmod @oh. This should be called once the hwmod has
940 * no further work. Returns -EINVAL if the hwmod is in the wrong 1228 * no further work. (This function has a full name --
941 * state or returns 0. 1229 * _omap_hwmod_idle() rather than simply _idle() -- because it is
1230 * currently required by the pm34xx.c idle loop.) Returns -EINVAL if
1231 * the hwmod is in the wrong state or returns 0.
942 */ 1232 */
943int _omap_hwmod_idle(struct omap_hwmod *oh) 1233int _omap_hwmod_idle(struct omap_hwmod *oh)
944{ 1234{
@@ -951,7 +1241,7 @@ int _omap_hwmod_idle(struct omap_hwmod *oh)
951 pr_debug("omap_hwmod: %s: idling\n", oh->name); 1241 pr_debug("omap_hwmod: %s: idling\n", oh->name);
952 1242
953 if (oh->class->sysc) 1243 if (oh->class->sysc)
954 _sysc_idle(oh); 1244 _idle_sysc(oh);
955 _del_initiator_dep(oh, mpu_oh); 1245 _del_initiator_dep(oh, mpu_oh);
956 _disable_clocks(oh); 1246 _disable_clocks(oh);
957 1247
@@ -981,10 +1271,21 @@ static int _shutdown(struct omap_hwmod *oh)
981 pr_debug("omap_hwmod: %s: disabling\n", oh->name); 1271 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
982 1272
983 if (oh->class->sysc) 1273 if (oh->class->sysc)
984 _sysc_shutdown(oh); 1274 _shutdown_sysc(oh);
985 _del_initiator_dep(oh, mpu_oh); 1275
986 /* XXX what about the other system initiators here? DMA, tesla, d2d */ 1276 /*
987 _disable_clocks(oh); 1277 * If an IP contains only one HW reset line, then assert it
1278 * before disabling the clocks and shutting down the IP.
1279 */
1280 if (oh->rst_lines_cnt == 1)
1281 _assert_hardreset(oh, oh->rst_lines[0].name);
1282
1283 /* clocks and deps are already disabled in idle */
1284 if (oh->_state == _HWMOD_STATE_ENABLED) {
1285 _del_initiator_dep(oh, mpu_oh);
1286 /* XXX what about the other system initiators here? dma, dsp */
1287 _disable_clocks(oh);
1288 }
988 /* XXX Should this code also force-disable the optional clocks? */ 1289 /* XXX Should this code also force-disable the optional clocks? */
989 1290
990 /* XXX mux any associated balls to safe mode */ 1291 /* XXX mux any associated balls to safe mode */
@@ -1000,11 +1301,10 @@ static int _shutdown(struct omap_hwmod *oh)
1000 * @skip_setup_idle_p: do not idle hwmods at the end of the fn if 1 1301 * @skip_setup_idle_p: do not idle hwmods at the end of the fn if 1
1001 * 1302 *
1002 * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh 1303 * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
1003 * OCP_SYSCONFIG register. Must be called with omap_hwmod_mutex held. 1304 * OCP_SYSCONFIG register. @skip_setup_idle is intended to be used on
1004 * @skip_setup_idle is intended to be used on a system that will not 1305 * a system that will not call omap_hwmod_enable() to enable devices
1005 * call omap_hwmod_enable() to enable devices (e.g., a system without 1306 * (e.g., a system without PM runtime). Returns -EINVAL if the hwmod
1006 * PM runtime). Returns -EINVAL if the hwmod is in the wrong state or 1307 * is in the wrong state or returns 0.
1007 * returns 0.
1008 */ 1308 */
1009static int _setup(struct omap_hwmod *oh, void *data) 1309static int _setup(struct omap_hwmod *oh, void *data)
1010{ 1310{
@@ -1034,8 +1334,19 @@ static int _setup(struct omap_hwmod *oh, void *data)
1034 } 1334 }
1035 } 1335 }
1036 1336
1337 mutex_init(&oh->_mutex);
1037 oh->_state = _HWMOD_STATE_INITIALIZED; 1338 oh->_state = _HWMOD_STATE_INITIALIZED;
1038 1339
1340 /*
1341 * In the case of hwmod with hardreset that should not be
1342 * de-assert at boot time, we have to keep the module
1343 * initialized, because we cannot enable it properly with the
1344 * reset asserted. Exit without warning because that behavior is
1345 * expected.
1346 */
1347 if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1)
1348 return 0;
1349
1039 r = _omap_hwmod_enable(oh); 1350 r = _omap_hwmod_enable(oh);
1040 if (r) { 1351 if (r) {
1041 pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n", 1352 pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
@@ -1044,16 +1355,16 @@ static int _setup(struct omap_hwmod *oh, void *data)
1044 } 1355 }
1045 1356
1046 if (!(oh->flags & HWMOD_INIT_NO_RESET)) { 1357 if (!(oh->flags & HWMOD_INIT_NO_RESET)) {
1358 _reset(oh);
1359
1047 /* 1360 /*
1048 * XXX Do the OCP_SYSCONFIG bits need to be 1361 * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
1049 * reprogrammed after a reset? If not, then this can 1362 * The _omap_hwmod_enable() function should be split to
1050 * be removed. If they do, then probably the 1363 * avoid the rewrite of the OCP_SYSCONFIG register.
1051 * _omap_hwmod_enable() function should be split to avoid the
1052 * rewrite of the OCP_SYSCONFIG register.
1053 */ 1364 */
1054 if (oh->class->sysc) { 1365 if (oh->class->sysc) {
1055 _update_sysc_cache(oh); 1366 _update_sysc_cache(oh);
1056 _sysc_enable(oh); 1367 _enable_sysc(oh);
1057 } 1368 }
1058 } 1369 }
1059 1370
@@ -1067,14 +1378,20 @@ static int _setup(struct omap_hwmod *oh, void *data)
1067 1378
1068/* Public functions */ 1379/* Public functions */
1069 1380
1070u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs) 1381u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
1071{ 1382{
1072 return __raw_readl(oh->_mpu_rt_va + reg_offs); 1383 if (oh->flags & HWMOD_16BIT_REG)
1384 return __raw_readw(oh->_mpu_rt_va + reg_offs);
1385 else
1386 return __raw_readl(oh->_mpu_rt_va + reg_offs);
1073} 1387}
1074 1388
1075void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs) 1389void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
1076{ 1390{
1077 __raw_writel(v, oh->_mpu_rt_va + reg_offs); 1391 if (oh->flags & HWMOD_16BIT_REG)
1392 __raw_writew(v, oh->_mpu_rt_va + reg_offs);
1393 else
1394 __raw_writel(v, oh->_mpu_rt_va + reg_offs);
1078} 1395}
1079 1396
1080/** 1397/**
@@ -1309,7 +1626,7 @@ int omap_hwmod_unregister(struct omap_hwmod *oh)
1309 * omap_hwmod_enable - enable an omap_hwmod 1626 * omap_hwmod_enable - enable an omap_hwmod
1310 * @oh: struct omap_hwmod * 1627 * @oh: struct omap_hwmod *
1311 * 1628 *
1312 * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable(). 1629 * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
1313 * Returns -EINVAL on error or passes along the return value from _enable(). 1630 * Returns -EINVAL on error or passes along the return value from _enable().
1314 */ 1631 */
1315int omap_hwmod_enable(struct omap_hwmod *oh) 1632int omap_hwmod_enable(struct omap_hwmod *oh)
@@ -1319,9 +1636,9 @@ int omap_hwmod_enable(struct omap_hwmod *oh)
1319 if (!oh) 1636 if (!oh)
1320 return -EINVAL; 1637 return -EINVAL;
1321 1638
1322 mutex_lock(&omap_hwmod_mutex); 1639 mutex_lock(&oh->_mutex);
1323 r = _omap_hwmod_enable(oh); 1640 r = _omap_hwmod_enable(oh);
1324 mutex_unlock(&omap_hwmod_mutex); 1641 mutex_unlock(&oh->_mutex);
1325 1642
1326 return r; 1643 return r;
1327} 1644}
@@ -1331,7 +1648,7 @@ int omap_hwmod_enable(struct omap_hwmod *oh)
1331 * omap_hwmod_idle - idle an omap_hwmod 1648 * omap_hwmod_idle - idle an omap_hwmod
1332 * @oh: struct omap_hwmod * 1649 * @oh: struct omap_hwmod *
1333 * 1650 *
1334 * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle(). 1651 * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
1335 * Returns -EINVAL on error or passes along the return value from _idle(). 1652 * Returns -EINVAL on error or passes along the return value from _idle().
1336 */ 1653 */
1337int omap_hwmod_idle(struct omap_hwmod *oh) 1654int omap_hwmod_idle(struct omap_hwmod *oh)
@@ -1339,9 +1656,9 @@ int omap_hwmod_idle(struct omap_hwmod *oh)
1339 if (!oh) 1656 if (!oh)
1340 return -EINVAL; 1657 return -EINVAL;
1341 1658
1342 mutex_lock(&omap_hwmod_mutex); 1659 mutex_lock(&oh->_mutex);
1343 _omap_hwmod_idle(oh); 1660 _omap_hwmod_idle(oh);
1344 mutex_unlock(&omap_hwmod_mutex); 1661 mutex_unlock(&oh->_mutex);
1345 1662
1346 return 0; 1663 return 0;
1347} 1664}
@@ -1350,7 +1667,7 @@ int omap_hwmod_idle(struct omap_hwmod *oh)
1350 * omap_hwmod_shutdown - shutdown an omap_hwmod 1667 * omap_hwmod_shutdown - shutdown an omap_hwmod
1351 * @oh: struct omap_hwmod * 1668 * @oh: struct omap_hwmod *
1352 * 1669 *
1353 * Shutdown an omap_hwomd @oh. Intended to be called by 1670 * Shutdown an omap_hwmod @oh. Intended to be called by
1354 * omap_device_shutdown(). Returns -EINVAL on error or passes along 1671 * omap_device_shutdown(). Returns -EINVAL on error or passes along
1355 * the return value from _shutdown(). 1672 * the return value from _shutdown().
1356 */ 1673 */
@@ -1359,9 +1676,9 @@ int omap_hwmod_shutdown(struct omap_hwmod *oh)
1359 if (!oh) 1676 if (!oh)
1360 return -EINVAL; 1677 return -EINVAL;
1361 1678
1362 mutex_lock(&omap_hwmod_mutex); 1679 mutex_lock(&oh->_mutex);
1363 _shutdown(oh); 1680 _shutdown(oh);
1364 mutex_unlock(&omap_hwmod_mutex); 1681 mutex_unlock(&oh->_mutex);
1365 1682
1366 return 0; 1683 return 0;
1367} 1684}
@@ -1374,9 +1691,9 @@ int omap_hwmod_shutdown(struct omap_hwmod *oh)
1374 */ 1691 */
1375int omap_hwmod_enable_clocks(struct omap_hwmod *oh) 1692int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
1376{ 1693{
1377 mutex_lock(&omap_hwmod_mutex); 1694 mutex_lock(&oh->_mutex);
1378 _enable_clocks(oh); 1695 _enable_clocks(oh);
1379 mutex_unlock(&omap_hwmod_mutex); 1696 mutex_unlock(&oh->_mutex);
1380 1697
1381 return 0; 1698 return 0;
1382} 1699}
@@ -1389,9 +1706,9 @@ int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
1389 */ 1706 */
1390int omap_hwmod_disable_clocks(struct omap_hwmod *oh) 1707int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
1391{ 1708{
1392 mutex_lock(&omap_hwmod_mutex); 1709 mutex_lock(&oh->_mutex);
1393 _disable_clocks(oh); 1710 _disable_clocks(oh);
1394 mutex_unlock(&omap_hwmod_mutex); 1711 mutex_unlock(&oh->_mutex);
1395 1712
1396 return 0; 1713 return 0;
1397} 1714}
@@ -1421,7 +1738,7 @@ void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
1421 * Forces posted writes to complete on the OCP thread handling 1738 * Forces posted writes to complete on the OCP thread handling
1422 * register writes 1739 * register writes
1423 */ 1740 */
1424 omap_hwmod_readl(oh, oh->class->sysc->sysc_offs); 1741 omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
1425} 1742}
1426 1743
1427/** 1744/**
@@ -1430,20 +1747,18 @@ void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
1430 * 1747 *
1431 * Under some conditions, a driver may wish to reset the entire device. 1748 * Under some conditions, a driver may wish to reset the entire device.
1432 * Called from omap_device code. Returns -EINVAL on error or passes along 1749 * Called from omap_device code. Returns -EINVAL on error or passes along
1433 * the return value from _reset()/_enable(). 1750 * the return value from _reset().
1434 */ 1751 */
1435int omap_hwmod_reset(struct omap_hwmod *oh) 1752int omap_hwmod_reset(struct omap_hwmod *oh)
1436{ 1753{
1437 int r; 1754 int r;
1438 1755
1439 if (!oh || !(oh->_state & _HWMOD_STATE_ENABLED)) 1756 if (!oh)
1440 return -EINVAL; 1757 return -EINVAL;
1441 1758
1442 mutex_lock(&omap_hwmod_mutex); 1759 mutex_lock(&oh->_mutex);
1443 r = _reset(oh); 1760 r = _reset(oh);
1444 if (!r) 1761 mutex_unlock(&oh->_mutex);
1445 r = _omap_hwmod_enable(oh);
1446 mutex_unlock(&omap_hwmod_mutex);
1447 1762
1448 return r; 1763 return r;
1449} 1764}
@@ -1468,7 +1783,7 @@ int omap_hwmod_count_resources(struct omap_hwmod *oh)
1468{ 1783{
1469 int ret, i; 1784 int ret, i;
1470 1785
1471 ret = oh->mpu_irqs_cnt + oh->sdma_chs_cnt; 1786 ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt;
1472 1787
1473 for (i = 0; i < oh->slaves_cnt; i++) 1788 for (i = 0; i < oh->slaves_cnt; i++)
1474 ret += oh->slaves[i]->addr_cnt; 1789 ret += oh->slaves[i]->addr_cnt;
@@ -1501,10 +1816,10 @@ int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
1501 r++; 1816 r++;
1502 } 1817 }
1503 1818
1504 for (i = 0; i < oh->sdma_chs_cnt; i++) { 1819 for (i = 0; i < oh->sdma_reqs_cnt; i++) {
1505 (res + r)->name = (oh->sdma_chs + i)->name; 1820 (res + r)->name = (oh->sdma_reqs + i)->name;
1506 (res + r)->start = (oh->sdma_chs + i)->dma_ch; 1821 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
1507 (res + r)->end = (oh->sdma_chs + i)->dma_ch; 1822 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
1508 (res + r)->flags = IORESOURCE_DMA; 1823 (res + r)->flags = IORESOURCE_DMA;
1509 r++; 1824 r++;
1510 } 1825 }
@@ -1644,9 +1959,9 @@ int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
1644 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) 1959 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
1645 return -EINVAL; 1960 return -EINVAL;
1646 1961
1647 mutex_lock(&omap_hwmod_mutex); 1962 mutex_lock(&oh->_mutex);
1648 _enable_wakeup(oh); 1963 _enable_wakeup(oh);
1649 mutex_unlock(&omap_hwmod_mutex); 1964 mutex_unlock(&oh->_mutex);
1650 1965
1651 return 0; 1966 return 0;
1652} 1967}
@@ -1669,14 +1984,92 @@ int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
1669 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) 1984 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
1670 return -EINVAL; 1985 return -EINVAL;
1671 1986
1672 mutex_lock(&omap_hwmod_mutex); 1987 mutex_lock(&oh->_mutex);
1673 _disable_wakeup(oh); 1988 _disable_wakeup(oh);
1674 mutex_unlock(&omap_hwmod_mutex); 1989 mutex_unlock(&oh->_mutex);
1675 1990
1676 return 0; 1991 return 0;
1677} 1992}
1678 1993
1679/** 1994/**
1995 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
1996 * contained in the hwmod module.
1997 * @oh: struct omap_hwmod *
1998 * @name: name of the reset line to lookup and assert
1999 *
2000 * Some IP like dsp, ipu or iva contain processor that require
2001 * an HW reset line to be assert / deassert in order to enable fully
2002 * the IP. Returns -EINVAL if @oh is null or if the operation is not
2003 * yet supported on this OMAP; otherwise, passes along the return value
2004 * from _assert_hardreset().
2005 */
2006int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
2007{
2008 int ret;
2009
2010 if (!oh)
2011 return -EINVAL;
2012
2013 mutex_lock(&oh->_mutex);
2014 ret = _assert_hardreset(oh, name);
2015 mutex_unlock(&oh->_mutex);
2016
2017 return ret;
2018}
2019
2020/**
2021 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
2022 * contained in the hwmod module.
2023 * @oh: struct omap_hwmod *
2024 * @name: name of the reset line to look up and deassert
2025 *
2026 * Some IP like dsp, ipu or iva contain processor that require
2027 * an HW reset line to be assert / deassert in order to enable fully
2028 * the IP. Returns -EINVAL if @oh is null or if the operation is not
2029 * yet supported on this OMAP; otherwise, passes along the return value
2030 * from _deassert_hardreset().
2031 */
2032int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
2033{
2034 int ret;
2035
2036 if (!oh)
2037 return -EINVAL;
2038
2039 mutex_lock(&oh->_mutex);
2040 ret = _deassert_hardreset(oh, name);
2041 mutex_unlock(&oh->_mutex);
2042
2043 return ret;
2044}
2045
2046/**
2047 * omap_hwmod_read_hardreset - read the HW reset line state of submodules
2048 * contained in the hwmod module
2049 * @oh: struct omap_hwmod *
2050 * @name: name of the reset line to look up and read
2051 *
2052 * Return the current state of the hwmod @oh's reset line named @name:
2053 * returns -EINVAL upon parameter error or if this operation
2054 * is unsupported on the current OMAP; otherwise, passes along the return
2055 * value from _read_hardreset().
2056 */
2057int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
2058{
2059 int ret;
2060
2061 if (!oh)
2062 return -EINVAL;
2063
2064 mutex_lock(&oh->_mutex);
2065 ret = _read_hardreset(oh, name);
2066 mutex_unlock(&oh->_mutex);
2067
2068 return ret;
2069}
2070
2071
2072/**
1680 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname 2073 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
1681 * @classname: struct omap_hwmod_class name to search for 2074 * @classname: struct omap_hwmod_class name to search for
1682 * @fn: callback function pointer to call for each hwmod in class @classname 2075 * @fn: callback function pointer to call for each hwmod in class @classname