omap_hwmod.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531
  1. /*
  2. * omap_hwmod implementation for OMAP2/3/4
  3. *
  4. * Copyright (C) 2009-2011 Nokia Corporation
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. *
  7. * Paul Walmsley, Benoît Cousson, Kevin Hilman
  8. *
  9. * Created in collaboration with (alphabetical order): Thara Gopinath,
  10. * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand
  11. * Sawant, Santosh Shilimkar, Richard Woodruff
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * Introduction
  18. * ------------
  19. * One way to view an OMAP SoC is as a collection of largely unrelated
  20. * IP blocks connected by interconnects. The IP blocks include
  21. * devices such as ARM processors, audio serial interfaces, UARTs,
  22. * etc. Some of these devices, like the DSP, are created by TI;
  23. * others, like the SGX, largely originate from external vendors. In
  24. * TI's documentation, on-chip devices are referred to as "OMAP
  25. * modules." Some of these IP blocks are identical across several
  26. * OMAP versions. Others are revised frequently.
  27. *
  28. * These OMAP modules are tied together by various interconnects.
  29. * Most of the address and data flow between modules is via OCP-based
  30. * interconnects such as the L3 and L4 buses; but there are other
  31. * interconnects that distribute the hardware clock tree, handle idle
  32. * and reset signaling, supply power, and connect the modules to
  33. * various pads or balls on the OMAP package.
  34. *
  35. * OMAP hwmod provides a consistent way to describe the on-chip
  36. * hardware blocks and their integration into the rest of the chip.
  37. * This description can be automatically generated from the TI
  38. * hardware database. OMAP hwmod provides a standard, consistent API
  39. * to reset, enable, idle, and disable these hardware blocks. And
  40. * hwmod provides a way for other core code, such as the Linux device
  41. * code or the OMAP power management and address space mapping code,
  42. * to query the hardware database.
  43. *
  44. * Using hwmod
  45. * -----------
  46. * Drivers won't call hwmod functions directly. That is done by the
  47. * omap_device code, and in rare occasions, by custom integration code
  48. * in arch/arm/ *omap*. The omap_device code includes functions to
  49. * build a struct platform_device using omap_hwmod data, and that is
  50. * currently how hwmod data is communicated to drivers and to the
  51. * Linux driver model. Most drivers will call omap_hwmod functions only
  52. * indirectly, via pm_runtime*() functions.
  53. *
  54. * From a layering perspective, here is where the OMAP hwmod code
  55. * fits into the kernel software stack:
  56. *
  57. * +-------------------------------+
  58. * | Device driver code |
  59. * | (e.g., drivers/) |
  60. * +-------------------------------+
  61. * | Linux driver model |
  62. * | (platform_device / |
  63. * | platform_driver data/code) |
  64. * +-------------------------------+
  65. * | OMAP core-driver integration |
  66. * |(arch/arm/mach-omap2/devices.c)|
  67. * +-------------------------------+
  68. * | omap_device code |
  69. * | (../plat-omap/omap_device.c) |
  70. * +-------------------------------+
  71. * ----> | omap_hwmod code/data | <-----
  72. * | (../mach-omap2/omap_hwmod*) |
  73. * +-------------------------------+
  74. * | OMAP clock/PRCM/register fns |
  75. * | (__raw_{read,write}l, clk*) |
  76. * +-------------------------------+
  77. *
  78. * Device drivers should not contain any OMAP-specific code or data in
  79. * them. They should only contain code to operate the IP block that
  80. * the driver is responsible for. This is because these IP blocks can
  81. * also appear in other SoCs, either from TI (such as DaVinci) or from
  82. * other manufacturers; and drivers should be reusable across other
  83. * platforms.
  84. *
  85. * The OMAP hwmod code also will attempt to reset and idle all on-chip
  86. * devices upon boot. The goal here is for the kernel to be
  87. * completely self-reliant and independent from bootloaders. This is
  88. * to ensure a repeatable configuration, both to ensure consistent
  89. * runtime behavior, and to make it easier for others to reproduce
  90. * bugs.
  91. *
  92. * OMAP module activity states
  93. * ---------------------------
  94. * The hwmod code considers modules to be in one of several activity
  95. * states. IP blocks start out in an UNKNOWN state, then once they
  96. * are registered via the hwmod code, proceed to the REGISTERED state.
  97. * Once their clock names are resolved to clock pointers, the module
  98. * enters the CLKS_INITED state; and finally, once the module has been
  99. * reset and the integration registers programmed, the INITIALIZED state
  100. * is entered. The hwmod code will then place the module into either
  101. * the IDLE state to save power, or in the case of a critical system
  102. * module, the ENABLED state.
  103. *
  104. * OMAP core integration code can then call omap_hwmod*() functions
  105. * directly to move the module between the IDLE, ENABLED, and DISABLED
  106. * states, as needed. This is done during both the PM idle loop, and
  107. * in the OMAP core integration code's implementation of the PM runtime
  108. * functions.
  109. *
  110. * References
  111. * ----------
  112. * This is a partial list.
  113. * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
  114. * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
  115. * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
  116. * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
  117. * - Open Core Protocol Specification 2.2
  118. *
  119. * To do:
  120. * - handle IO mapping
  121. * - bus throughput & module latency measurement code
  122. *
  123. * XXX add tests at the beginning of each function to ensure the hwmod is
  124. * in the appropriate state
  125. * XXX error return values should be checked to ensure that they are
  126. * appropriate
  127. */
  128. #undef DEBUG
  129. #include <linux/kernel.h>
  130. #include <linux/errno.h>
  131. #include <linux/io.h>
  132. #include <linux/clk.h>
  133. #include <linux/delay.h>
  134. #include <linux/err.h>
  135. #include <linux/list.h>
  136. #include <linux/mutex.h>
  137. #include <linux/spinlock.h>
  138. #include <plat/common.h>
  139. #include <plat/cpu.h>
  140. #include "clockdomain.h"
  141. #include "powerdomain.h"
  142. #include <plat/clock.h>
  143. #include <plat/omap_hwmod.h>
  144. #include <plat/prcm.h>
  145. #include "cm2xxx_3xxx.h"
  146. #include "cminst44xx.h"
  147. #include "prm2xxx_3xxx.h"
  148. #include "prm44xx.h"
  149. #include "mux.h"
  150. /* Maximum microseconds to wait for OMAP module to softreset */
  151. #define MAX_MODULE_SOFTRESET_WAIT 10000
  152. /* Name of the OMAP hwmod for the MPU */
  153. #define MPU_INITIATOR_NAME "mpu"
  154. /* omap_hwmod_list contains all registered struct omap_hwmods */
  155. static LIST_HEAD(omap_hwmod_list);
  156. /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
  157. static struct omap_hwmod *mpu_oh;
  158. /* Private functions */
  159. /**
  160. * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
  161. * @oh: struct omap_hwmod *
  162. *
  163. * Load the current value of the hwmod OCP_SYSCONFIG register into the
  164. * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
  165. * OCP_SYSCONFIG register or 0 upon success.
  166. */
  167. static int _update_sysc_cache(struct omap_hwmod *oh)
  168. {
  169. if (!oh->class->sysc) {
  170. WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  171. return -EINVAL;
  172. }
  173. /* XXX ensure module interface clock is up */
  174. oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  175. if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
  176. oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
  177. return 0;
  178. }
  179. /**
  180. * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
  181. * @v: OCP_SYSCONFIG value to write
  182. * @oh: struct omap_hwmod *
  183. *
  184. * Write @v into the module class' OCP_SYSCONFIG register, if it has
  185. * one. No return value.
  186. */
  187. static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
  188. {
  189. if (!oh->class->sysc) {
  190. WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  191. return;
  192. }
  193. /* XXX ensure module interface clock is up */
  194. /* Module might have lost context, always update cache and register */
  195. oh->_sysc_cache = v;
  196. omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
  197. }
  198. /**
  199. * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
  200. * @oh: struct omap_hwmod *
  201. * @standbymode: MIDLEMODE field bits
  202. * @v: pointer to register contents to modify
  203. *
  204. * Update the master standby mode bits in @v to be @standbymode for
  205. * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
  206. * upon error or 0 upon success.
  207. */
  208. static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
  209. u32 *v)
  210. {
  211. u32 mstandby_mask;
  212. u8 mstandby_shift;
  213. if (!oh->class->sysc ||
  214. !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
  215. return -EINVAL;
  216. if (!oh->class->sysc->sysc_fields) {
  217. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  218. return -EINVAL;
  219. }
  220. mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
  221. mstandby_mask = (0x3 << mstandby_shift);
  222. *v &= ~mstandby_mask;
  223. *v |= __ffs(standbymode) << mstandby_shift;
  224. return 0;
  225. }
  226. /**
  227. * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
  228. * @oh: struct omap_hwmod *
  229. * @idlemode: SIDLEMODE field bits
  230. * @v: pointer to register contents to modify
  231. *
  232. * Update the slave idle mode bits in @v to be @idlemode for the @oh
  233. * hwmod. Does not write to the hardware. Returns -EINVAL upon error
  234. * or 0 upon success.
  235. */
  236. static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
  237. {
  238. u32 sidle_mask;
  239. u8 sidle_shift;
  240. if (!oh->class->sysc ||
  241. !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
  242. return -EINVAL;
  243. if (!oh->class->sysc->sysc_fields) {
  244. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  245. return -EINVAL;
  246. }
  247. sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
  248. sidle_mask = (0x3 << sidle_shift);
  249. *v &= ~sidle_mask;
  250. *v |= __ffs(idlemode) << sidle_shift;
  251. return 0;
  252. }
  253. /**
  254. * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  255. * @oh: struct omap_hwmod *
  256. * @clockact: CLOCKACTIVITY field bits
  257. * @v: pointer to register contents to modify
  258. *
  259. * Update the clockactivity mode bits in @v to be @clockact for the
  260. * @oh hwmod. Used for additional powersaving on some modules. Does
  261. * not write to the hardware. Returns -EINVAL upon error or 0 upon
  262. * success.
  263. */
  264. static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
  265. {
  266. u32 clkact_mask;
  267. u8 clkact_shift;
  268. if (!oh->class->sysc ||
  269. !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
  270. return -EINVAL;
  271. if (!oh->class->sysc->sysc_fields) {
  272. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  273. return -EINVAL;
  274. }
  275. clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
  276. clkact_mask = (0x3 << clkact_shift);
  277. *v &= ~clkact_mask;
  278. *v |= clockact << clkact_shift;
  279. return 0;
  280. }
  281. /**
  282. * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  283. * @oh: struct omap_hwmod *
  284. * @v: pointer to register contents to modify
  285. *
  286. * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
  287. * error or 0 upon success.
  288. */
  289. static int _set_softreset(struct omap_hwmod *oh, u32 *v)
  290. {
  291. u32 softrst_mask;
  292. if (!oh->class->sysc ||
  293. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  294. return -EINVAL;
  295. if (!oh->class->sysc->sysc_fields) {
  296. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  297. return -EINVAL;
  298. }
  299. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  300. *v |= softrst_mask;
  301. return 0;
  302. }
  303. /**
  304. * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
  305. * @oh: struct omap_hwmod *
  306. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  307. * @v: pointer to register contents to modify
  308. *
  309. * Update the module autoidle bit in @v to be @autoidle for the @oh
  310. * hwmod. The autoidle bit controls whether the module can gate
  311. * internal clocks automatically when it isn't doing anything; the
  312. * exact function of this bit varies on a per-module basis. This
  313. * function does not write to the hardware. Returns -EINVAL upon
  314. * error or 0 upon success.
  315. */
  316. static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
  317. u32 *v)
  318. {
  319. u32 autoidle_mask;
  320. u8 autoidle_shift;
  321. if (!oh->class->sysc ||
  322. !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
  323. return -EINVAL;
  324. if (!oh->class->sysc->sysc_fields) {
  325. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  326. return -EINVAL;
  327. }
  328. autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
  329. autoidle_mask = (0x1 << autoidle_shift);
  330. *v &= ~autoidle_mask;
  331. *v |= autoidle << autoidle_shift;
  332. return 0;
  333. }
  334. /**
  335. * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  336. * @oh: struct omap_hwmod *
  337. *
  338. * Allow the hardware module @oh to send wakeups. Returns -EINVAL
  339. * upon error or 0 upon success.
  340. */
  341. static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
  342. {
  343. if (!oh->class->sysc ||
  344. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  345. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  346. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  347. return -EINVAL;
  348. if (!oh->class->sysc->sysc_fields) {
  349. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  350. return -EINVAL;
  351. }
  352. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  353. *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
  354. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  355. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  356. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  357. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  358. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  359. oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
  360. return 0;
  361. }
  362. /**
  363. * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  364. * @oh: struct omap_hwmod *
  365. *
  366. * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
  367. * upon error or 0 upon success.
  368. */
  369. static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
  370. {
  371. if (!oh->class->sysc ||
  372. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  373. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  374. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  375. return -EINVAL;
  376. if (!oh->class->sysc->sysc_fields) {
  377. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  378. return -EINVAL;
  379. }
  380. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  381. *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  382. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  383. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
  384. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  385. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  386. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  387. oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
  388. return 0;
  389. }
  390. /**
  391. * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
  392. * @oh: struct omap_hwmod *
  393. *
  394. * Prevent the hardware module @oh from entering idle while the
  395. * hardare module initiator @init_oh is active. Useful when a module
  396. * will be accessed by a particular initiator (e.g., if a module will
  397. * be accessed by the IVA, there should be a sleepdep between the IVA
  398. * initiator and the module). Only applies to modules in smart-idle
  399. * mode. If the clockdomain is marked as not needing autodeps, return
  400. * 0 without doing anything. Otherwise, returns -EINVAL upon error or
  401. * passes along clkdm_add_sleepdep() value upon success.
  402. */
  403. static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  404. {
  405. if (!oh->_clk)
  406. return -EINVAL;
  407. if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
  408. return 0;
  409. return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  410. }
  411. /**
  412. * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
  413. * @oh: struct omap_hwmod *
  414. *
  415. * Allow the hardware module @oh to enter idle while the hardare
  416. * module initiator @init_oh is active. Useful when a module will not
  417. * be accessed by a particular initiator (e.g., if a module will not
  418. * be accessed by the IVA, there should be no sleepdep between the IVA
  419. * initiator and the module). Only applies to modules in smart-idle
  420. * mode. If the clockdomain is marked as not needing autodeps, return
  421. * 0 without doing anything. Returns -EINVAL upon error or passes
  422. * along clkdm_del_sleepdep() value upon success.
  423. */
  424. static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  425. {
  426. if (!oh->_clk)
  427. return -EINVAL;
  428. if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
  429. return 0;
  430. return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
  431. }
  432. /**
  433. * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
  434. * @oh: struct omap_hwmod *
  435. *
  436. * Called from _init_clocks(). Populates the @oh _clk (main
  437. * functional clock pointer) if a main_clk is present. Returns 0 on
  438. * success or -EINVAL on error.
  439. */
  440. static int _init_main_clk(struct omap_hwmod *oh)
  441. {
  442. int ret = 0;
  443. if (!oh->main_clk)
  444. return 0;
  445. oh->_clk = omap_clk_get_by_name(oh->main_clk);
  446. if (!oh->_clk) {
  447. pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
  448. oh->name, oh->main_clk);
  449. return -EINVAL;
  450. }
  451. if (!oh->_clk->clkdm)
  452. pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n",
  453. oh->main_clk, oh->_clk->name);
  454. return ret;
  455. }
  456. /**
  457. * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
  458. * @oh: struct omap_hwmod *
  459. *
  460. * Called from _init_clocks(). Populates the @oh OCP slave interface
  461. * clock pointers. Returns 0 on success or -EINVAL on error.
  462. */
  463. static int _init_interface_clks(struct omap_hwmod *oh)
  464. {
  465. struct clk *c;
  466. int i;
  467. int ret = 0;
  468. if (oh->slaves_cnt == 0)
  469. return 0;
  470. for (i = 0; i < oh->slaves_cnt; i++) {
  471. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  472. if (!os->clk)
  473. continue;
  474. c = omap_clk_get_by_name(os->clk);
  475. if (!c) {
  476. pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
  477. oh->name, os->clk);
  478. ret = -EINVAL;
  479. }
  480. os->_clk = c;
  481. }
  482. return ret;
  483. }
  484. /**
  485. * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
  486. * @oh: struct omap_hwmod *
  487. *
  488. * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
  489. * clock pointers. Returns 0 on success or -EINVAL on error.
  490. */
  491. static int _init_opt_clks(struct omap_hwmod *oh)
  492. {
  493. struct omap_hwmod_opt_clk *oc;
  494. struct clk *c;
  495. int i;
  496. int ret = 0;
  497. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
  498. c = omap_clk_get_by_name(oc->clk);
  499. if (!c) {
  500. pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
  501. oh->name, oc->clk);
  502. ret = -EINVAL;
  503. }
  504. oc->_clk = c;
  505. }
  506. return ret;
  507. }
  508. /**
  509. * _enable_clocks - enable hwmod main clock and interface clocks
  510. * @oh: struct omap_hwmod *
  511. *
  512. * Enables all clocks necessary for register reads and writes to succeed
  513. * on the hwmod @oh. Returns 0.
  514. */
  515. static int _enable_clocks(struct omap_hwmod *oh)
  516. {
  517. int i;
  518. pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
  519. if (oh->_clk)
  520. clk_enable(oh->_clk);
  521. if (oh->slaves_cnt > 0) {
  522. for (i = 0; i < oh->slaves_cnt; i++) {
  523. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  524. struct clk *c = os->_clk;
  525. if (c && (os->flags & OCPIF_SWSUP_IDLE))
  526. clk_enable(c);
  527. }
  528. }
  529. /* The opt clocks are controlled by the device driver. */
  530. return 0;
  531. }
  532. /**
  533. * _disable_clocks - disable hwmod main clock and interface clocks
  534. * @oh: struct omap_hwmod *
  535. *
  536. * Disables the hwmod @oh main functional and interface clocks. Returns 0.
  537. */
  538. static int _disable_clocks(struct omap_hwmod *oh)
  539. {
  540. int i;
  541. pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
  542. if (oh->_clk)
  543. clk_disable(oh->_clk);
  544. if (oh->slaves_cnt > 0) {
  545. for (i = 0; i < oh->slaves_cnt; i++) {
  546. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  547. struct clk *c = os->_clk;
  548. if (c && (os->flags & OCPIF_SWSUP_IDLE))
  549. clk_disable(c);
  550. }
  551. }
  552. /* The opt clocks are controlled by the device driver. */
  553. return 0;
  554. }
  555. static void _enable_optional_clocks(struct omap_hwmod *oh)
  556. {
  557. struct omap_hwmod_opt_clk *oc;
  558. int i;
  559. pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
  560. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  561. if (oc->_clk) {
  562. pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
  563. oc->_clk->name);
  564. clk_enable(oc->_clk);
  565. }
  566. }
  567. static void _disable_optional_clocks(struct omap_hwmod *oh)
  568. {
  569. struct omap_hwmod_opt_clk *oc;
  570. int i;
  571. pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
  572. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  573. if (oc->_clk) {
  574. pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
  575. oc->_clk->name);
  576. clk_disable(oc->_clk);
  577. }
  578. }
  579. /**
  580. * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
  581. * @oh: struct omap_hwmod *oh
  582. *
  583. * Count and return the number of MPU IRQs associated with the hwmod
  584. * @oh. Used to allocate struct resource data. Returns 0 if @oh is
  585. * NULL.
  586. */
  587. static int _count_mpu_irqs(struct omap_hwmod *oh)
  588. {
  589. struct omap_hwmod_irq_info *ohii;
  590. int i = 0;
  591. if (!oh || !oh->mpu_irqs)
  592. return 0;
  593. do {
  594. ohii = &oh->mpu_irqs[i++];
  595. } while (ohii->irq != -1);
  596. return i;
  597. }
  598. /**
  599. * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
  600. * @oh: struct omap_hwmod *oh
  601. *
  602. * Count and return the number of SDMA request lines associated with
  603. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  604. * if @oh is NULL.
  605. */
  606. static int _count_sdma_reqs(struct omap_hwmod *oh)
  607. {
  608. struct omap_hwmod_dma_info *ohdi;
  609. int i = 0;
  610. if (!oh || !oh->sdma_reqs)
  611. return 0;
  612. do {
  613. ohdi = &oh->sdma_reqs[i++];
  614. } while (ohdi->dma_req != -1);
  615. return i;
  616. }
  617. /**
  618. * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
  619. * @oh: struct omap_hwmod *oh
  620. *
  621. * Count and return the number of address space ranges associated with
  622. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  623. * if @oh is NULL.
  624. */
  625. static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
  626. {
  627. struct omap_hwmod_addr_space *mem;
  628. int i = 0;
  629. if (!os || !os->addr)
  630. return 0;
  631. do {
  632. mem = &os->addr[i++];
  633. } while (mem->pa_start != mem->pa_end);
  634. return i;
  635. }
  636. /**
  637. * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
  638. * @oh: struct omap_hwmod *
  639. *
  640. * Returns the array index of the OCP slave port that the MPU
  641. * addresses the device on, or -EINVAL upon error or not found.
  642. */
  643. static int __init _find_mpu_port_index(struct omap_hwmod *oh)
  644. {
  645. int i;
  646. int found = 0;
  647. if (!oh || oh->slaves_cnt == 0)
  648. return -EINVAL;
  649. for (i = 0; i < oh->slaves_cnt; i++) {
  650. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  651. if (os->user & OCP_USER_MPU) {
  652. found = 1;
  653. break;
  654. }
  655. }
  656. if (found)
  657. pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
  658. oh->name, i);
  659. else
  660. pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
  661. oh->name);
  662. return (found) ? i : -EINVAL;
  663. }
  664. /**
  665. * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU
  666. * @oh: struct omap_hwmod *
  667. *
  668. * Return the virtual address of the base of the register target of
  669. * device @oh, or NULL on error.
  670. */
  671. static void __iomem * __init _find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
  672. {
  673. struct omap_hwmod_ocp_if *os;
  674. struct omap_hwmod_addr_space *mem;
  675. int i = 0, found = 0;
  676. void __iomem *va_start;
  677. if (!oh || oh->slaves_cnt == 0)
  678. return NULL;
  679. os = oh->slaves[index];
  680. if (!os->addr)
  681. return NULL;
  682. do {
  683. mem = &os->addr[i++];
  684. if (mem->flags & ADDR_TYPE_RT)
  685. found = 1;
  686. } while (!found && mem->pa_start != mem->pa_end);
  687. if (found) {
  688. va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
  689. if (!va_start) {
  690. pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
  691. return NULL;
  692. }
  693. pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
  694. oh->name, va_start);
  695. } else {
  696. pr_debug("omap_hwmod: %s: no MPU register target found\n",
  697. oh->name);
  698. }
  699. return (found) ? va_start : NULL;
  700. }
  701. /**
  702. * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
  703. * @oh: struct omap_hwmod *
  704. *
  705. * If module is marked as SWSUP_SIDLE, force the module out of slave
  706. * idle; otherwise, configure it for smart-idle. If module is marked
  707. * as SWSUP_MSUSPEND, force the module out of master standby;
  708. * otherwise, configure it for smart-standby. No return value.
  709. */
  710. static void _enable_sysc(struct omap_hwmod *oh)
  711. {
  712. u8 idlemode, sf;
  713. u32 v;
  714. if (!oh->class->sysc)
  715. return;
  716. v = oh->_sysc_cache;
  717. sf = oh->class->sysc->sysc_flags;
  718. if (sf & SYSC_HAS_SIDLEMODE) {
  719. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  720. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  721. _set_slave_idlemode(oh, idlemode, &v);
  722. }
  723. if (sf & SYSC_HAS_MIDLEMODE) {
  724. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  725. idlemode = HWMOD_IDLEMODE_NO;
  726. } else {
  727. if (sf & SYSC_HAS_ENAWAKEUP)
  728. _enable_wakeup(oh, &v);
  729. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  730. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  731. else
  732. idlemode = HWMOD_IDLEMODE_SMART;
  733. }
  734. _set_master_standbymode(oh, idlemode, &v);
  735. }
  736. /*
  737. * XXX The clock framework should handle this, by
  738. * calling into this code. But this must wait until the
  739. * clock structures are tagged with omap_hwmod entries
  740. */
  741. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  742. (sf & SYSC_HAS_CLOCKACTIVITY))
  743. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  744. /* If slave is in SMARTIDLE, also enable wakeup */
  745. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  746. _enable_wakeup(oh, &v);
  747. _write_sysconfig(v, oh);
  748. /*
  749. * Set the autoidle bit only after setting the smartidle bit
  750. * Setting this will not have any impact on the other modules.
  751. */
  752. if (sf & SYSC_HAS_AUTOIDLE) {
  753. idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
  754. 0 : 1;
  755. _set_module_autoidle(oh, idlemode, &v);
  756. _write_sysconfig(v, oh);
  757. }
  758. }
  759. /**
  760. * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
  761. * @oh: struct omap_hwmod *
  762. *
  763. * If module is marked as SWSUP_SIDLE, force the module into slave
  764. * idle; otherwise, configure it for smart-idle. If module is marked
  765. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  766. * configure it for smart-standby. No return value.
  767. */
  768. static void _idle_sysc(struct omap_hwmod *oh)
  769. {
  770. u8 idlemode, sf;
  771. u32 v;
  772. if (!oh->class->sysc)
  773. return;
  774. v = oh->_sysc_cache;
  775. sf = oh->class->sysc->sysc_flags;
  776. if (sf & SYSC_HAS_SIDLEMODE) {
  777. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  778. HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
  779. _set_slave_idlemode(oh, idlemode, &v);
  780. }
  781. if (sf & SYSC_HAS_MIDLEMODE) {
  782. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  783. idlemode = HWMOD_IDLEMODE_FORCE;
  784. } else {
  785. if (sf & SYSC_HAS_ENAWAKEUP)
  786. _enable_wakeup(oh, &v);
  787. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  788. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  789. else
  790. idlemode = HWMOD_IDLEMODE_SMART;
  791. }
  792. _set_master_standbymode(oh, idlemode, &v);
  793. }
  794. /* If slave is in SMARTIDLE, also enable wakeup */
  795. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  796. _enable_wakeup(oh, &v);
  797. _write_sysconfig(v, oh);
  798. }
  799. /**
  800. * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
  801. * @oh: struct omap_hwmod *
  802. *
  803. * Force the module into slave idle and master suspend. No return
  804. * value.
  805. */
  806. static void _shutdown_sysc(struct omap_hwmod *oh)
  807. {
  808. u32 v;
  809. u8 sf;
  810. if (!oh->class->sysc)
  811. return;
  812. v = oh->_sysc_cache;
  813. sf = oh->class->sysc->sysc_flags;
  814. if (sf & SYSC_HAS_SIDLEMODE)
  815. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  816. if (sf & SYSC_HAS_MIDLEMODE)
  817. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  818. if (sf & SYSC_HAS_AUTOIDLE)
  819. _set_module_autoidle(oh, 1, &v);
  820. _write_sysconfig(v, oh);
  821. }
  822. /**
  823. * _lookup - find an omap_hwmod by name
  824. * @name: find an omap_hwmod by name
  825. *
  826. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  827. */
  828. static struct omap_hwmod *_lookup(const char *name)
  829. {
  830. struct omap_hwmod *oh, *temp_oh;
  831. oh = NULL;
  832. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  833. if (!strcmp(name, temp_oh->name)) {
  834. oh = temp_oh;
  835. break;
  836. }
  837. }
  838. return oh;
  839. }
  840. /**
  841. * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
  842. * @oh: struct omap_hwmod *
  843. *
  844. * Convert a clockdomain name stored in a struct omap_hwmod into a
  845. * clockdomain pointer, and save it into the struct omap_hwmod.
  846. * return -EINVAL if clkdm_name does not exist or if the lookup failed.
  847. */
  848. static int _init_clkdm(struct omap_hwmod *oh)
  849. {
  850. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  851. return 0;
  852. if (!oh->clkdm_name) {
  853. pr_warning("omap_hwmod: %s: no clkdm_name\n", oh->name);
  854. return -EINVAL;
  855. }
  856. oh->clkdm = clkdm_lookup(oh->clkdm_name);
  857. if (!oh->clkdm) {
  858. pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
  859. oh->name, oh->clkdm_name);
  860. return -EINVAL;
  861. }
  862. pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
  863. oh->name, oh->clkdm_name);
  864. return 0;
  865. }
  866. /**
  867. * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
  868. * well the clockdomain.
  869. * @oh: struct omap_hwmod *
  870. * @data: not used; pass NULL
  871. *
  872. * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
  873. * Resolves all clock names embedded in the hwmod. Returns 0 on
  874. * success, or a negative error code on failure.
  875. */
  876. static int _init_clocks(struct omap_hwmod *oh, void *data)
  877. {
  878. int ret = 0;
  879. if (oh->_state != _HWMOD_STATE_REGISTERED)
  880. return 0;
  881. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  882. ret |= _init_main_clk(oh);
  883. ret |= _init_interface_clks(oh);
  884. ret |= _init_opt_clks(oh);
  885. ret |= _init_clkdm(oh);
  886. if (!ret)
  887. oh->_state = _HWMOD_STATE_CLKS_INITED;
  888. else
  889. pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
  890. return ret;
  891. }
  892. /**
  893. * _wait_target_ready - wait for a module to leave slave idle
  894. * @oh: struct omap_hwmod *
  895. *
  896. * Wait for a module @oh to leave slave idle. Returns 0 if the module
  897. * does not have an IDLEST bit or if the module successfully leaves
  898. * slave idle; otherwise, pass along the return value of the
  899. * appropriate *_cm*_wait_module_ready() function.
  900. */
  901. static int _wait_target_ready(struct omap_hwmod *oh)
  902. {
  903. struct omap_hwmod_ocp_if *os;
  904. int ret;
  905. if (!oh)
  906. return -EINVAL;
  907. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  908. return 0;
  909. os = oh->slaves[oh->_mpu_port_index];
  910. if (oh->flags & HWMOD_NO_IDLEST)
  911. return 0;
  912. /* XXX check module SIDLEMODE */
  913. /* XXX check clock enable states */
  914. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  915. ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
  916. oh->prcm.omap2.idlest_reg_id,
  917. oh->prcm.omap2.idlest_idle_bit);
  918. } else if (cpu_is_omap44xx()) {
  919. if (!oh->clkdm)
  920. return -EINVAL;
  921. ret = omap4_cminst_wait_module_ready(oh->clkdm->prcm_partition,
  922. oh->clkdm->cm_inst,
  923. oh->clkdm->clkdm_offs,
  924. oh->prcm.omap4.clkctrl_offs);
  925. } else {
  926. BUG();
  927. };
  928. return ret;
  929. }
  930. /**
  931. * _lookup_hardreset - fill register bit info for this hwmod/reset line
  932. * @oh: struct omap_hwmod *
  933. * @name: name of the reset line in the context of this hwmod
  934. * @ohri: struct omap_hwmod_rst_info * that this function will fill in
  935. *
  936. * Return the bit position of the reset line that match the
  937. * input name. Return -ENOENT if not found.
  938. */
  939. static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name,
  940. struct omap_hwmod_rst_info *ohri)
  941. {
  942. int i;
  943. for (i = 0; i < oh->rst_lines_cnt; i++) {
  944. const char *rst_line = oh->rst_lines[i].name;
  945. if (!strcmp(rst_line, name)) {
  946. ohri->rst_shift = oh->rst_lines[i].rst_shift;
  947. ohri->st_shift = oh->rst_lines[i].st_shift;
  948. pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
  949. oh->name, __func__, rst_line, ohri->rst_shift,
  950. ohri->st_shift);
  951. return 0;
  952. }
  953. }
  954. return -ENOENT;
  955. }
  956. /**
  957. * _assert_hardreset - assert the HW reset line of submodules
  958. * contained in the hwmod module.
  959. * @oh: struct omap_hwmod *
  960. * @name: name of the reset line to lookup and assert
  961. *
  962. * Some IP like dsp, ipu or iva contain processor that require
  963. * an HW reset line to be assert / deassert in order to enable fully
  964. * the IP.
  965. */
  966. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  967. {
  968. struct omap_hwmod_rst_info ohri;
  969. u8 ret;
  970. if (!oh)
  971. return -EINVAL;
  972. ret = _lookup_hardreset(oh, name, &ohri);
  973. if (IS_ERR_VALUE(ret))
  974. return ret;
  975. if (cpu_is_omap24xx() || cpu_is_omap34xx())
  976. return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
  977. ohri.rst_shift);
  978. else if (cpu_is_omap44xx())
  979. return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg,
  980. ohri.rst_shift);
  981. else
  982. return -EINVAL;
  983. }
  984. /**
  985. * _deassert_hardreset - deassert the HW reset line of submodules contained
  986. * in the hwmod module.
  987. * @oh: struct omap_hwmod *
  988. * @name: name of the reset line to look up and deassert
  989. *
  990. * Some IP like dsp, ipu or iva contain processor that require
  991. * an HW reset line to be assert / deassert in order to enable fully
  992. * the IP.
  993. */
  994. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  995. {
  996. struct omap_hwmod_rst_info ohri;
  997. int ret;
  998. if (!oh)
  999. return -EINVAL;
  1000. ret = _lookup_hardreset(oh, name, &ohri);
  1001. if (IS_ERR_VALUE(ret))
  1002. return ret;
  1003. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1004. ret = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
  1005. ohri.rst_shift,
  1006. ohri.st_shift);
  1007. } else if (cpu_is_omap44xx()) {
  1008. if (ohri.st_shift)
  1009. pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
  1010. oh->name, name);
  1011. ret = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg,
  1012. ohri.rst_shift);
  1013. } else {
  1014. return -EINVAL;
  1015. }
  1016. if (ret == -EBUSY)
  1017. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  1018. return ret;
  1019. }
  1020. /**
  1021. * _read_hardreset - read the HW reset line state of submodules
  1022. * contained in the hwmod module
  1023. * @oh: struct omap_hwmod *
  1024. * @name: name of the reset line to look up and read
  1025. *
  1026. * Return the state of the reset line.
  1027. */
  1028. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  1029. {
  1030. struct omap_hwmod_rst_info ohri;
  1031. u8 ret;
  1032. if (!oh)
  1033. return -EINVAL;
  1034. ret = _lookup_hardreset(oh, name, &ohri);
  1035. if (IS_ERR_VALUE(ret))
  1036. return ret;
  1037. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  1038. return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
  1039. ohri.st_shift);
  1040. } else if (cpu_is_omap44xx()) {
  1041. return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg,
  1042. ohri.rst_shift);
  1043. } else {
  1044. return -EINVAL;
  1045. }
  1046. }
  1047. /**
  1048. * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
  1049. * @oh: struct omap_hwmod *
  1050. *
  1051. * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
  1052. * enabled for this to work. Returns -EINVAL if the hwmod cannot be
  1053. * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
  1054. * the module did not reset in time, or 0 upon success.
  1055. *
  1056. * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
  1057. * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
  1058. * use the SYSCONFIG softreset bit to provide the status.
  1059. *
  1060. * Note that some IP like McBSP do have reset control but don't have
  1061. * reset status.
  1062. */
  1063. static int _ocp_softreset(struct omap_hwmod *oh)
  1064. {
  1065. u32 v;
  1066. int c = 0;
  1067. int ret = 0;
  1068. if (!oh->class->sysc ||
  1069. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  1070. return -EINVAL;
  1071. /* clocks must be on for this operation */
  1072. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1073. pr_warning("omap_hwmod: %s: reset can only be entered from "
  1074. "enabled state\n", oh->name);
  1075. return -EINVAL;
  1076. }
  1077. /* For some modules, all optionnal clocks need to be enabled as well */
  1078. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1079. _enable_optional_clocks(oh);
  1080. pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
  1081. v = oh->_sysc_cache;
  1082. ret = _set_softreset(oh, &v);
  1083. if (ret)
  1084. goto dis_opt_clks;
  1085. _write_sysconfig(v, oh);
  1086. if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  1087. omap_test_timeout((omap_hwmod_read(oh,
  1088. oh->class->sysc->syss_offs)
  1089. & SYSS_RESETDONE_MASK),
  1090. MAX_MODULE_SOFTRESET_WAIT, c);
  1091. else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS)
  1092. omap_test_timeout(!(omap_hwmod_read(oh,
  1093. oh->class->sysc->sysc_offs)
  1094. & SYSC_TYPE2_SOFTRESET_MASK),
  1095. MAX_MODULE_SOFTRESET_WAIT, c);
  1096. if (c == MAX_MODULE_SOFTRESET_WAIT)
  1097. pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
  1098. oh->name, MAX_MODULE_SOFTRESET_WAIT);
  1099. else
  1100. pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
  1101. /*
  1102. * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
  1103. * _wait_target_ready() or _reset()
  1104. */
  1105. ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  1106. dis_opt_clks:
  1107. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1108. _disable_optional_clocks(oh);
  1109. return ret;
  1110. }
  1111. /**
  1112. * _reset - reset an omap_hwmod
  1113. * @oh: struct omap_hwmod *
  1114. *
  1115. * Resets an omap_hwmod @oh. The default software reset mechanism for
  1116. * most OMAP IP blocks is triggered via the OCP_SYSCONFIG.SOFTRESET
  1117. * bit. However, some hwmods cannot be reset via this method: some
  1118. * are not targets and therefore have no OCP header registers to
  1119. * access; others (like the IVA) have idiosyncratic reset sequences.
  1120. * So for these relatively rare cases, custom reset code can be
  1121. * supplied in the struct omap_hwmod_class .reset function pointer.
  1122. * Passes along the return value from either _reset() or the custom
  1123. * reset function - these must return -EINVAL if the hwmod cannot be
  1124. * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
  1125. * the module did not reset in time, or 0 upon success.
  1126. */
  1127. static int _reset(struct omap_hwmod *oh)
  1128. {
  1129. int ret;
  1130. pr_debug("omap_hwmod: %s: resetting\n", oh->name);
  1131. ret = (oh->class->reset) ? oh->class->reset(oh) : _ocp_softreset(oh);
  1132. return ret;
  1133. }
  1134. /**
  1135. * _enable - enable an omap_hwmod
  1136. * @oh: struct omap_hwmod *
  1137. *
  1138. * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
  1139. * register target. Returns -EINVAL if the hwmod is in the wrong
  1140. * state or passes along the return value of _wait_target_ready().
  1141. */
  1142. static int _enable(struct omap_hwmod *oh)
  1143. {
  1144. int r;
  1145. pr_debug("omap_hwmod: %s: enabling\n", oh->name);
  1146. if (oh->_state != _HWMOD_STATE_INITIALIZED &&
  1147. oh->_state != _HWMOD_STATE_IDLE &&
  1148. oh->_state != _HWMOD_STATE_DISABLED) {
  1149. WARN(1, "omap_hwmod: %s: enabled state can only be entered "
  1150. "from initialized, idle, or disabled state\n", oh->name);
  1151. return -EINVAL;
  1152. }
  1153. /* Mux pins for device runtime if populated */
  1154. if (oh->mux && (!oh->mux->enabled ||
  1155. ((oh->_state == _HWMOD_STATE_IDLE) &&
  1156. oh->mux->pads_dynamic)))
  1157. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1158. _add_initiator_dep(oh, mpu_oh);
  1159. _enable_clocks(oh);
  1160. /*
  1161. * If an IP contains only one HW reset line, then de-assert it in order
  1162. * to allow the module state transition. Otherwise the PRCM will return
  1163. * Intransition status, and the init will failed.
  1164. */
  1165. if ((oh->_state == _HWMOD_STATE_INITIALIZED ||
  1166. oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
  1167. _deassert_hardreset(oh, oh->rst_lines[0].name);
  1168. r = _wait_target_ready(oh);
  1169. if (r) {
  1170. pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
  1171. oh->name, r);
  1172. _disable_clocks(oh);
  1173. return r;
  1174. }
  1175. oh->_state = _HWMOD_STATE_ENABLED;
  1176. /* Access the sysconfig only if the target is ready */
  1177. if (oh->class->sysc) {
  1178. if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
  1179. _update_sysc_cache(oh);
  1180. _enable_sysc(oh);
  1181. }
  1182. return r;
  1183. }
  1184. /**
  1185. * _idle - idle an omap_hwmod
  1186. * @oh: struct omap_hwmod *
  1187. *
  1188. * Idles an omap_hwmod @oh. This should be called once the hwmod has
  1189. * no further work. Returns -EINVAL if the hwmod is in the wrong
  1190. * state or returns 0.
  1191. */
  1192. static int _idle(struct omap_hwmod *oh)
  1193. {
  1194. pr_debug("omap_hwmod: %s: idling\n", oh->name);
  1195. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1196. WARN(1, "omap_hwmod: %s: idle state can only be entered from "
  1197. "enabled state\n", oh->name);
  1198. return -EINVAL;
  1199. }
  1200. if (oh->class->sysc)
  1201. _idle_sysc(oh);
  1202. _del_initiator_dep(oh, mpu_oh);
  1203. _disable_clocks(oh);
  1204. /* Mux pins for device idle if populated */
  1205. if (oh->mux && oh->mux->pads_dynamic)
  1206. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  1207. oh->_state = _HWMOD_STATE_IDLE;
  1208. return 0;
  1209. }
  1210. /**
  1211. * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
  1212. * @oh: struct omap_hwmod *
  1213. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  1214. *
  1215. * Sets the IP block's OCP autoidle bit in hardware, and updates our
  1216. * local copy. Intended to be used by drivers that require
  1217. * direct manipulation of the AUTOIDLE bits.
  1218. * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
  1219. * along the return value from _set_module_autoidle().
  1220. *
  1221. * Any users of this function should be scrutinized carefully.
  1222. */
  1223. int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
  1224. {
  1225. u32 v;
  1226. int retval = 0;
  1227. unsigned long flags;
  1228. if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
  1229. return -EINVAL;
  1230. spin_lock_irqsave(&oh->_lock, flags);
  1231. v = oh->_sysc_cache;
  1232. retval = _set_module_autoidle(oh, autoidle, &v);
  1233. if (!retval)
  1234. _write_sysconfig(v, oh);
  1235. spin_unlock_irqrestore(&oh->_lock, flags);
  1236. return retval;
  1237. }
  1238. /**
  1239. * _shutdown - shutdown an omap_hwmod
  1240. * @oh: struct omap_hwmod *
  1241. *
  1242. * Shut down an omap_hwmod @oh. This should be called when the driver
  1243. * used for the hwmod is removed or unloaded or if the driver is not
  1244. * used by the system. Returns -EINVAL if the hwmod is in the wrong
  1245. * state or returns 0.
  1246. */
  1247. static int _shutdown(struct omap_hwmod *oh)
  1248. {
  1249. int ret;
  1250. u8 prev_state;
  1251. if (oh->_state != _HWMOD_STATE_IDLE &&
  1252. oh->_state != _HWMOD_STATE_ENABLED) {
  1253. WARN(1, "omap_hwmod: %s: disabled state can only be entered "
  1254. "from idle, or enabled state\n", oh->name);
  1255. return -EINVAL;
  1256. }
  1257. pr_debug("omap_hwmod: %s: disabling\n", oh->name);
  1258. if (oh->class->pre_shutdown) {
  1259. prev_state = oh->_state;
  1260. if (oh->_state == _HWMOD_STATE_IDLE)
  1261. _enable(oh);
  1262. ret = oh->class->pre_shutdown(oh);
  1263. if (ret) {
  1264. if (prev_state == _HWMOD_STATE_IDLE)
  1265. _idle(oh);
  1266. return ret;
  1267. }
  1268. }
  1269. if (oh->class->sysc) {
  1270. if (oh->_state == _HWMOD_STATE_IDLE)
  1271. _enable(oh);
  1272. _shutdown_sysc(oh);
  1273. }
  1274. /* clocks and deps are already disabled in idle */
  1275. if (oh->_state == _HWMOD_STATE_ENABLED) {
  1276. _del_initiator_dep(oh, mpu_oh);
  1277. /* XXX what about the other system initiators here? dma, dsp */
  1278. _disable_clocks(oh);
  1279. }
  1280. /* XXX Should this code also force-disable the optional clocks? */
  1281. /*
  1282. * If an IP contains only one HW reset line, then assert it
  1283. * after disabling the clocks and before shutting down the IP.
  1284. */
  1285. if (oh->rst_lines_cnt == 1)
  1286. _assert_hardreset(oh, oh->rst_lines[0].name);
  1287. /* Mux pins to safe mode or use populated off mode values */
  1288. if (oh->mux)
  1289. omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
  1290. oh->_state = _HWMOD_STATE_DISABLED;
  1291. return 0;
  1292. }
  1293. /**
  1294. * _setup - do initial configuration of omap_hwmod
  1295. * @oh: struct omap_hwmod *
  1296. *
  1297. * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
  1298. * OCP_SYSCONFIG register. Returns 0.
  1299. */
  1300. static int _setup(struct omap_hwmod *oh, void *data)
  1301. {
  1302. int i, r;
  1303. u8 postsetup_state;
  1304. if (oh->_state != _HWMOD_STATE_CLKS_INITED)
  1305. return 0;
  1306. /* Set iclk autoidle mode */
  1307. if (oh->slaves_cnt > 0) {
  1308. for (i = 0; i < oh->slaves_cnt; i++) {
  1309. struct omap_hwmod_ocp_if *os = oh->slaves[i];
  1310. struct clk *c = os->_clk;
  1311. if (!c)
  1312. continue;
  1313. if (os->flags & OCPIF_SWSUP_IDLE) {
  1314. /* XXX omap_iclk_deny_idle(c); */
  1315. } else {
  1316. /* XXX omap_iclk_allow_idle(c); */
  1317. clk_enable(c);
  1318. }
  1319. }
  1320. }
  1321. oh->_state = _HWMOD_STATE_INITIALIZED;
  1322. /*
  1323. * In the case of hwmod with hardreset that should not be
  1324. * de-assert at boot time, we have to keep the module
  1325. * initialized, because we cannot enable it properly with the
  1326. * reset asserted. Exit without warning because that behavior is
  1327. * expected.
  1328. */
  1329. if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1)
  1330. return 0;
  1331. r = _enable(oh);
  1332. if (r) {
  1333. pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
  1334. oh->name, oh->_state);
  1335. return 0;
  1336. }
  1337. if (!(oh->flags & HWMOD_INIT_NO_RESET)) {
  1338. _reset(oh);
  1339. /*
  1340. * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
  1341. * The _enable() function should be split to
  1342. * avoid the rewrite of the OCP_SYSCONFIG register.
  1343. */
  1344. if (oh->class->sysc) {
  1345. _update_sysc_cache(oh);
  1346. _enable_sysc(oh);
  1347. }
  1348. }
  1349. postsetup_state = oh->_postsetup_state;
  1350. if (postsetup_state == _HWMOD_STATE_UNKNOWN)
  1351. postsetup_state = _HWMOD_STATE_ENABLED;
  1352. /*
  1353. * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
  1354. * it should be set by the core code as a runtime flag during startup
  1355. */
  1356. if ((oh->flags & HWMOD_INIT_NO_IDLE) &&
  1357. (postsetup_state == _HWMOD_STATE_IDLE))
  1358. postsetup_state = _HWMOD_STATE_ENABLED;
  1359. if (postsetup_state == _HWMOD_STATE_IDLE)
  1360. _idle(oh);
  1361. else if (postsetup_state == _HWMOD_STATE_DISABLED)
  1362. _shutdown(oh);
  1363. else if (postsetup_state != _HWMOD_STATE_ENABLED)
  1364. WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
  1365. oh->name, postsetup_state);
  1366. return 0;
  1367. }
  1368. /**
  1369. * _register - register a struct omap_hwmod
  1370. * @oh: struct omap_hwmod *
  1371. *
  1372. * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
  1373. * already has been registered by the same name; -EINVAL if the
  1374. * omap_hwmod is in the wrong state, if @oh is NULL, if the
  1375. * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
  1376. * name, or if the omap_hwmod's class is missing a name; or 0 upon
  1377. * success.
  1378. *
  1379. * XXX The data should be copied into bootmem, so the original data
  1380. * should be marked __initdata and freed after init. This would allow
  1381. * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
  1382. * that the copy process would be relatively complex due to the large number
  1383. * of substructures.
  1384. */
  1385. static int __init _register(struct omap_hwmod *oh)
  1386. {
  1387. int ms_id;
  1388. if (!oh || !oh->name || !oh->class || !oh->class->name ||
  1389. (oh->_state != _HWMOD_STATE_UNKNOWN))
  1390. return -EINVAL;
  1391. pr_debug("omap_hwmod: %s: registering\n", oh->name);
  1392. if (_lookup(oh->name))
  1393. return -EEXIST;
  1394. ms_id = _find_mpu_port_index(oh);
  1395. if (!IS_ERR_VALUE(ms_id))
  1396. oh->_mpu_port_index = ms_id;
  1397. else
  1398. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1399. list_add_tail(&oh->node, &omap_hwmod_list);
  1400. spin_lock_init(&oh->_lock);
  1401. oh->_state = _HWMOD_STATE_REGISTERED;
  1402. /*
  1403. * XXX Rather than doing a strcmp(), this should test a flag
  1404. * set in the hwmod data, inserted by the autogenerator code.
  1405. */
  1406. if (!strcmp(oh->name, MPU_INITIATOR_NAME))
  1407. mpu_oh = oh;
  1408. return 0;
  1409. }
  1410. /* Public functions */
  1411. u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
  1412. {
  1413. if (oh->flags & HWMOD_16BIT_REG)
  1414. return __raw_readw(oh->_mpu_rt_va + reg_offs);
  1415. else
  1416. return __raw_readl(oh->_mpu_rt_va + reg_offs);
  1417. }
  1418. void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
  1419. {
  1420. if (oh->flags & HWMOD_16BIT_REG)
  1421. __raw_writew(v, oh->_mpu_rt_va + reg_offs);
  1422. else
  1423. __raw_writel(v, oh->_mpu_rt_va + reg_offs);
  1424. }
  1425. /**
  1426. * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
  1427. * @oh: struct omap_hwmod *
  1428. *
  1429. * This is a public function exposed to drivers. Some drivers may need to do
  1430. * some settings before and after resetting the device. Those drivers after
  1431. * doing the necessary settings could use this function to start a reset by
  1432. * setting the SYSCONFIG.SOFTRESET bit.
  1433. */
  1434. int omap_hwmod_softreset(struct omap_hwmod *oh)
  1435. {
  1436. u32 v;
  1437. int ret;
  1438. if (!oh || !(oh->_sysc_cache))
  1439. return -EINVAL;
  1440. v = oh->_sysc_cache;
  1441. ret = _set_softreset(oh, &v);
  1442. if (ret)
  1443. goto error;
  1444. _write_sysconfig(v, oh);
  1445. error:
  1446. return ret;
  1447. }
  1448. /**
  1449. * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
  1450. * @oh: struct omap_hwmod *
  1451. * @idlemode: SIDLEMODE field bits (shifted to bit 0)
  1452. *
  1453. * Sets the IP block's OCP slave idlemode in hardware, and updates our
  1454. * local copy. Intended to be used by drivers that have some erratum
  1455. * that requires direct manipulation of the SIDLEMODE bits. Returns
  1456. * -EINVAL if @oh is null, or passes along the return value from
  1457. * _set_slave_idlemode().
  1458. *
  1459. * XXX Does this function have any current users? If not, we should
  1460. * remove it; it is better to let the rest of the hwmod code handle this.
  1461. * Any users of this function should be scrutinized carefully.
  1462. */
  1463. int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
  1464. {
  1465. u32 v;
  1466. int retval = 0;
  1467. if (!oh)
  1468. return -EINVAL;
  1469. v = oh->_sysc_cache;
  1470. retval = _set_slave_idlemode(oh, idlemode, &v);
  1471. if (!retval)
  1472. _write_sysconfig(v, oh);
  1473. return retval;
  1474. }
  1475. /**
  1476. * omap_hwmod_lookup - look up a registered omap_hwmod by name
  1477. * @name: name of the omap_hwmod to look up
  1478. *
  1479. * Given a @name of an omap_hwmod, return a pointer to the registered
  1480. * struct omap_hwmod *, or NULL upon error.
  1481. */
  1482. struct omap_hwmod *omap_hwmod_lookup(const char *name)
  1483. {
  1484. struct omap_hwmod *oh;
  1485. if (!name)
  1486. return NULL;
  1487. oh = _lookup(name);
  1488. return oh;
  1489. }
  1490. /**
  1491. * omap_hwmod_for_each - call function for each registered omap_hwmod
  1492. * @fn: pointer to a callback function
  1493. * @data: void * data to pass to callback function
  1494. *
  1495. * Call @fn for each registered omap_hwmod, passing @data to each
  1496. * function. @fn must return 0 for success or any other value for
  1497. * failure. If @fn returns non-zero, the iteration across omap_hwmods
  1498. * will stop and the non-zero return value will be passed to the
  1499. * caller of omap_hwmod_for_each(). @fn is called with
  1500. * omap_hwmod_for_each() held.
  1501. */
  1502. int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
  1503. void *data)
  1504. {
  1505. struct omap_hwmod *temp_oh;
  1506. int ret = 0;
  1507. if (!fn)
  1508. return -EINVAL;
  1509. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1510. ret = (*fn)(temp_oh, data);
  1511. if (ret)
  1512. break;
  1513. }
  1514. return ret;
  1515. }
  1516. /**
  1517. * omap_hwmod_register - register an array of hwmods
  1518. * @ohs: pointer to an array of omap_hwmods to register
  1519. *
  1520. * Intended to be called early in boot before the clock framework is
  1521. * initialized. If @ohs is not null, will register all omap_hwmods
  1522. * listed in @ohs that are valid for this chip. Returns 0.
  1523. */
  1524. int __init omap_hwmod_register(struct omap_hwmod **ohs)
  1525. {
  1526. int r, i;
  1527. if (!ohs)
  1528. return 0;
  1529. i = 0;
  1530. do {
  1531. if (!omap_chip_is(ohs[i]->omap_chip))
  1532. continue;
  1533. r = _register(ohs[i]);
  1534. WARN(r, "omap_hwmod: %s: _register returned %d\n", ohs[i]->name,
  1535. r);
  1536. } while (ohs[++i]);
  1537. return 0;
  1538. }
  1539. /*
  1540. * _populate_mpu_rt_base - populate the virtual address for a hwmod
  1541. *
  1542. * Must be called only from omap_hwmod_setup_*() so ioremap works properly.
  1543. * Assumes the caller takes care of locking if needed.
  1544. */
  1545. static int __init _populate_mpu_rt_base(struct omap_hwmod *oh, void *data)
  1546. {
  1547. if (oh->_state != _HWMOD_STATE_REGISTERED)
  1548. return 0;
  1549. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1550. return 0;
  1551. oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
  1552. return 0;
  1553. }
  1554. /**
  1555. * omap_hwmod_setup_one - set up a single hwmod
  1556. * @oh_name: const char * name of the already-registered hwmod to set up
  1557. *
  1558. * Must be called after omap2_clk_init(). Resolves the struct clk
  1559. * names to struct clk pointers for each registered omap_hwmod. Also
  1560. * calls _setup() on each hwmod. Returns -EINVAL upon error or 0 upon
  1561. * success.
  1562. */
  1563. int __init omap_hwmod_setup_one(const char *oh_name)
  1564. {
  1565. struct omap_hwmod *oh;
  1566. int r;
  1567. pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
  1568. if (!mpu_oh) {
  1569. pr_err("omap_hwmod: %s: cannot setup_one: MPU initiator hwmod %s not yet registered\n",
  1570. oh_name, MPU_INITIATOR_NAME);
  1571. return -EINVAL;
  1572. }
  1573. oh = _lookup(oh_name);
  1574. if (!oh) {
  1575. WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
  1576. return -EINVAL;
  1577. }
  1578. if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
  1579. omap_hwmod_setup_one(MPU_INITIATOR_NAME);
  1580. r = _populate_mpu_rt_base(oh, NULL);
  1581. if (IS_ERR_VALUE(r)) {
  1582. WARN(1, "omap_hwmod: %s: couldn't set mpu_rt_base\n", oh_name);
  1583. return -EINVAL;
  1584. }
  1585. r = _init_clocks(oh, NULL);
  1586. if (IS_ERR_VALUE(r)) {
  1587. WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh_name);
  1588. return -EINVAL;
  1589. }
  1590. _setup(oh, NULL);
  1591. return 0;
  1592. }
  1593. /**
  1594. * omap_hwmod_setup - do some post-clock framework initialization
  1595. *
  1596. * Must be called after omap2_clk_init(). Resolves the struct clk names
  1597. * to struct clk pointers for each registered omap_hwmod. Also calls
  1598. * _setup() on each hwmod. Returns 0 upon success.
  1599. */
  1600. static int __init omap_hwmod_setup_all(void)
  1601. {
  1602. int r;
  1603. if (!mpu_oh) {
  1604. pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
  1605. __func__, MPU_INITIATOR_NAME);
  1606. return -EINVAL;
  1607. }
  1608. r = omap_hwmod_for_each(_populate_mpu_rt_base, NULL);
  1609. r = omap_hwmod_for_each(_init_clocks, NULL);
  1610. WARN(IS_ERR_VALUE(r),
  1611. "omap_hwmod: %s: _init_clocks failed\n", __func__);
  1612. omap_hwmod_for_each(_setup, NULL);
  1613. return 0;
  1614. }
  1615. core_initcall(omap_hwmod_setup_all);
  1616. /**
  1617. * omap_hwmod_enable - enable an omap_hwmod
  1618. * @oh: struct omap_hwmod *
  1619. *
  1620. * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
  1621. * Returns -EINVAL on error or passes along the return value from _enable().
  1622. */
  1623. int omap_hwmod_enable(struct omap_hwmod *oh)
  1624. {
  1625. int r;
  1626. unsigned long flags;
  1627. if (!oh)
  1628. return -EINVAL;
  1629. spin_lock_irqsave(&oh->_lock, flags);
  1630. r = _enable(oh);
  1631. spin_unlock_irqrestore(&oh->_lock, flags);
  1632. return r;
  1633. }
  1634. /**
  1635. * omap_hwmod_idle - idle an omap_hwmod
  1636. * @oh: struct omap_hwmod *
  1637. *
  1638. * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
  1639. * Returns -EINVAL on error or passes along the return value from _idle().
  1640. */
  1641. int omap_hwmod_idle(struct omap_hwmod *oh)
  1642. {
  1643. unsigned long flags;
  1644. if (!oh)
  1645. return -EINVAL;
  1646. spin_lock_irqsave(&oh->_lock, flags);
  1647. _idle(oh);
  1648. spin_unlock_irqrestore(&oh->_lock, flags);
  1649. return 0;
  1650. }
  1651. /**
  1652. * omap_hwmod_shutdown - shutdown an omap_hwmod
  1653. * @oh: struct omap_hwmod *
  1654. *
  1655. * Shutdown an omap_hwmod @oh. Intended to be called by
  1656. * omap_device_shutdown(). Returns -EINVAL on error or passes along
  1657. * the return value from _shutdown().
  1658. */
  1659. int omap_hwmod_shutdown(struct omap_hwmod *oh)
  1660. {
  1661. unsigned long flags;
  1662. if (!oh)
  1663. return -EINVAL;
  1664. spin_lock_irqsave(&oh->_lock, flags);
  1665. _shutdown(oh);
  1666. spin_unlock_irqrestore(&oh->_lock, flags);
  1667. return 0;
  1668. }
  1669. /**
  1670. * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
  1671. * @oh: struct omap_hwmod *oh
  1672. *
  1673. * Intended to be called by the omap_device code.
  1674. */
  1675. int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
  1676. {
  1677. unsigned long flags;
  1678. spin_lock_irqsave(&oh->_lock, flags);
  1679. _enable_clocks(oh);
  1680. spin_unlock_irqrestore(&oh->_lock, flags);
  1681. return 0;
  1682. }
  1683. /**
  1684. * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
  1685. * @oh: struct omap_hwmod *oh
  1686. *
  1687. * Intended to be called by the omap_device code.
  1688. */
  1689. int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
  1690. {
  1691. unsigned long flags;
  1692. spin_lock_irqsave(&oh->_lock, flags);
  1693. _disable_clocks(oh);
  1694. spin_unlock_irqrestore(&oh->_lock, flags);
  1695. return 0;
  1696. }
  1697. /**
  1698. * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
  1699. * @oh: struct omap_hwmod *oh
  1700. *
  1701. * Intended to be called by drivers and core code when all posted
  1702. * writes to a device must complete before continuing further
  1703. * execution (for example, after clearing some device IRQSTATUS
  1704. * register bits)
  1705. *
  1706. * XXX what about targets with multiple OCP threads?
  1707. */
  1708. void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
  1709. {
  1710. BUG_ON(!oh);
  1711. if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
  1712. WARN(1, "omap_device: %s: OCP barrier impossible due to "
  1713. "device configuration\n", oh->name);
  1714. return;
  1715. }
  1716. /*
  1717. * Forces posted writes to complete on the OCP thread handling
  1718. * register writes
  1719. */
  1720. omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  1721. }
  1722. /**
  1723. * omap_hwmod_reset - reset the hwmod
  1724. * @oh: struct omap_hwmod *
  1725. *
  1726. * Under some conditions, a driver may wish to reset the entire device.
  1727. * Called from omap_device code. Returns -EINVAL on error or passes along
  1728. * the return value from _reset().
  1729. */
  1730. int omap_hwmod_reset(struct omap_hwmod *oh)
  1731. {
  1732. int r;
  1733. unsigned long flags;
  1734. if (!oh)
  1735. return -EINVAL;
  1736. spin_lock_irqsave(&oh->_lock, flags);
  1737. r = _reset(oh);
  1738. spin_unlock_irqrestore(&oh->_lock, flags);
  1739. return r;
  1740. }
  1741. /**
  1742. * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  1743. * @oh: struct omap_hwmod *
  1744. * @res: pointer to the first element of an array of struct resource to fill
  1745. *
  1746. * Count the number of struct resource array elements necessary to
  1747. * contain omap_hwmod @oh resources. Intended to be called by code
  1748. * that registers omap_devices. Intended to be used to determine the
  1749. * size of a dynamically-allocated struct resource array, before
  1750. * calling omap_hwmod_fill_resources(). Returns the number of struct
  1751. * resource array elements needed.
  1752. *
  1753. * XXX This code is not optimized. It could attempt to merge adjacent
  1754. * resource IDs.
  1755. *
  1756. */
  1757. int omap_hwmod_count_resources(struct omap_hwmod *oh)
  1758. {
  1759. int ret, i;
  1760. ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
  1761. for (i = 0; i < oh->slaves_cnt; i++)
  1762. ret += _count_ocp_if_addr_spaces(oh->slaves[i]);
  1763. return ret;
  1764. }
  1765. /**
  1766. * omap_hwmod_fill_resources - fill struct resource array with hwmod data
  1767. * @oh: struct omap_hwmod *
  1768. * @res: pointer to the first element of an array of struct resource to fill
  1769. *
  1770. * Fill the struct resource array @res with resource data from the
  1771. * omap_hwmod @oh. Intended to be called by code that registers
  1772. * omap_devices. See also omap_hwmod_count_resources(). Returns the
  1773. * number of array elements filled.
  1774. */
  1775. int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
  1776. {
  1777. int i, j, mpu_irqs_cnt, sdma_reqs_cnt;
  1778. int r = 0;
  1779. /* For each IRQ, DMA, memory area, fill in array.*/
  1780. mpu_irqs_cnt = _count_mpu_irqs(oh);
  1781. for (i = 0; i < mpu_irqs_cnt; i++) {
  1782. (res + r)->name = (oh->mpu_irqs + i)->name;
  1783. (res + r)->start = (oh->mpu_irqs + i)->irq;
  1784. (res + r)->end = (oh->mpu_irqs + i)->irq;
  1785. (res + r)->flags = IORESOURCE_IRQ;
  1786. r++;
  1787. }
  1788. sdma_reqs_cnt = _count_sdma_reqs(oh);
  1789. for (i = 0; i < sdma_reqs_cnt; i++) {
  1790. (res + r)->name = (oh->sdma_reqs + i)->name;
  1791. (res + r)->start = (oh->sdma_reqs + i)->dma_req;
  1792. (res + r)->end = (oh->sdma_reqs + i)->dma_req;
  1793. (res + r)->flags = IORESOURCE_DMA;
  1794. r++;
  1795. }
  1796. for (i = 0; i < oh->slaves_cnt; i++) {
  1797. struct omap_hwmod_ocp_if *os;
  1798. int addr_cnt;
  1799. os = oh->slaves[i];
  1800. addr_cnt = _count_ocp_if_addr_spaces(os);
  1801. for (j = 0; j < addr_cnt; j++) {
  1802. (res + r)->name = (os->addr + j)->name;
  1803. (res + r)->start = (os->addr + j)->pa_start;
  1804. (res + r)->end = (os->addr + j)->pa_end;
  1805. (res + r)->flags = IORESOURCE_MEM;
  1806. r++;
  1807. }
  1808. }
  1809. return r;
  1810. }
  1811. /**
  1812. * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
  1813. * @oh: struct omap_hwmod *
  1814. *
  1815. * Return the powerdomain pointer associated with the OMAP module
  1816. * @oh's main clock. If @oh does not have a main clk, return the
  1817. * powerdomain associated with the interface clock associated with the
  1818. * module's MPU port. (XXX Perhaps this should use the SDMA port
  1819. * instead?) Returns NULL on error, or a struct powerdomain * on
  1820. * success.
  1821. */
  1822. struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
  1823. {
  1824. struct clk *c;
  1825. if (!oh)
  1826. return NULL;
  1827. if (oh->_clk) {
  1828. c = oh->_clk;
  1829. } else {
  1830. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1831. return NULL;
  1832. c = oh->slaves[oh->_mpu_port_index]->_clk;
  1833. }
  1834. if (!c->clkdm)
  1835. return NULL;
  1836. return c->clkdm->pwrdm.ptr;
  1837. }
  1838. /**
  1839. * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
  1840. * @oh: struct omap_hwmod *
  1841. *
  1842. * Returns the virtual address corresponding to the beginning of the
  1843. * module's register target, in the address range that is intended to
  1844. * be used by the MPU. Returns the virtual address upon success or NULL
  1845. * upon error.
  1846. */
  1847. void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
  1848. {
  1849. if (!oh)
  1850. return NULL;
  1851. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1852. return NULL;
  1853. if (oh->_state == _HWMOD_STATE_UNKNOWN)
  1854. return NULL;
  1855. return oh->_mpu_rt_va;
  1856. }
  1857. /**
  1858. * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
  1859. * @oh: struct omap_hwmod *
  1860. * @init_oh: struct omap_hwmod * (initiator)
  1861. *
  1862. * Add a sleep dependency between the initiator @init_oh and @oh.
  1863. * Intended to be called by DSP/Bridge code via platform_data for the
  1864. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  1865. * code needs to add/del initiator dependencies dynamically
  1866. * before/after accessing a device. Returns the return value from
  1867. * _add_initiator_dep().
  1868. *
  1869. * XXX Keep a usecount in the clockdomain code
  1870. */
  1871. int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
  1872. struct omap_hwmod *init_oh)
  1873. {
  1874. return _add_initiator_dep(oh, init_oh);
  1875. }
  1876. /*
  1877. * XXX what about functions for drivers to save/restore ocp_sysconfig
  1878. * for context save/restore operations?
  1879. */
  1880. /**
  1881. * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
  1882. * @oh: struct omap_hwmod *
  1883. * @init_oh: struct omap_hwmod * (initiator)
  1884. *
  1885. * Remove a sleep dependency between the initiator @init_oh and @oh.
  1886. * Intended to be called by DSP/Bridge code via platform_data for the
  1887. * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
  1888. * code needs to add/del initiator dependencies dynamically
  1889. * before/after accessing a device. Returns the return value from
  1890. * _del_initiator_dep().
  1891. *
  1892. * XXX Keep a usecount in the clockdomain code
  1893. */
  1894. int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
  1895. struct omap_hwmod *init_oh)
  1896. {
  1897. return _del_initiator_dep(oh, init_oh);
  1898. }
  1899. /**
  1900. * omap_hwmod_enable_wakeup - allow device to wake up the system
  1901. * @oh: struct omap_hwmod *
  1902. *
  1903. * Sets the module OCP socket ENAWAKEUP bit to allow the module to
  1904. * send wakeups to the PRCM. Eventually this should sets PRCM wakeup
  1905. * registers to cause the PRCM to receive wakeup events from the
  1906. * module. Does not set any wakeup routing registers beyond this
  1907. * point - if the module is to wake up any other module or subsystem,
  1908. * that must be set separately. Called by omap_device code. Returns
  1909. * -EINVAL on error or 0 upon success.
  1910. */
  1911. int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
  1912. {
  1913. unsigned long flags;
  1914. u32 v;
  1915. if (!oh->class->sysc ||
  1916. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  1917. return -EINVAL;
  1918. spin_lock_irqsave(&oh->_lock, flags);
  1919. v = oh->_sysc_cache;
  1920. _enable_wakeup(oh, &v);
  1921. _write_sysconfig(v, oh);
  1922. spin_unlock_irqrestore(&oh->_lock, flags);
  1923. return 0;
  1924. }
  1925. /**
  1926. * omap_hwmod_disable_wakeup - prevent device from waking the system
  1927. * @oh: struct omap_hwmod *
  1928. *
  1929. * Clears the module OCP socket ENAWAKEUP bit to prevent the module
  1930. * from sending wakeups to the PRCM. Eventually this should clear
  1931. * PRCM wakeup registers to cause the PRCM to ignore wakeup events
  1932. * from the module. Does not set any wakeup routing registers beyond
  1933. * this point - if the module is to wake up any other module or
  1934. * subsystem, that must be set separately. Called by omap_device
  1935. * code. Returns -EINVAL on error or 0 upon success.
  1936. */
  1937. int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
  1938. {
  1939. unsigned long flags;
  1940. u32 v;
  1941. if (!oh->class->sysc ||
  1942. !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
  1943. return -EINVAL;
  1944. spin_lock_irqsave(&oh->_lock, flags);
  1945. v = oh->_sysc_cache;
  1946. _disable_wakeup(oh, &v);
  1947. _write_sysconfig(v, oh);
  1948. spin_unlock_irqrestore(&oh->_lock, flags);
  1949. return 0;
  1950. }
  1951. /**
  1952. * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
  1953. * contained in the hwmod module.
  1954. * @oh: struct omap_hwmod *
  1955. * @name: name of the reset line to lookup and assert
  1956. *
  1957. * Some IP like dsp, ipu or iva contain processor that require
  1958. * an HW reset line to be assert / deassert in order to enable fully
  1959. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  1960. * yet supported on this OMAP; otherwise, passes along the return value
  1961. * from _assert_hardreset().
  1962. */
  1963. int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
  1964. {
  1965. int ret;
  1966. unsigned long flags;
  1967. if (!oh)
  1968. return -EINVAL;
  1969. spin_lock_irqsave(&oh->_lock, flags);
  1970. ret = _assert_hardreset(oh, name);
  1971. spin_unlock_irqrestore(&oh->_lock, flags);
  1972. return ret;
  1973. }
  1974. /**
  1975. * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
  1976. * contained in the hwmod module.
  1977. * @oh: struct omap_hwmod *
  1978. * @name: name of the reset line to look up and deassert
  1979. *
  1980. * Some IP like dsp, ipu or iva contain processor that require
  1981. * an HW reset line to be assert / deassert in order to enable fully
  1982. * the IP. Returns -EINVAL if @oh is null or if the operation is not
  1983. * yet supported on this OMAP; otherwise, passes along the return value
  1984. * from _deassert_hardreset().
  1985. */
  1986. int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1987. {
  1988. int ret;
  1989. unsigned long flags;
  1990. if (!oh)
  1991. return -EINVAL;
  1992. spin_lock_irqsave(&oh->_lock, flags);
  1993. ret = _deassert_hardreset(oh, name);
  1994. spin_unlock_irqrestore(&oh->_lock, flags);
  1995. return ret;
  1996. }
  1997. /**
  1998. * omap_hwmod_read_hardreset - read the HW reset line state of submodules
  1999. * contained in the hwmod module
  2000. * @oh: struct omap_hwmod *
  2001. * @name: name of the reset line to look up and read
  2002. *
  2003. * Return the current state of the hwmod @oh's reset line named @name:
  2004. * returns -EINVAL upon parameter error or if this operation
  2005. * is unsupported on the current OMAP; otherwise, passes along the return
  2006. * value from _read_hardreset().
  2007. */
  2008. int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
  2009. {
  2010. int ret;
  2011. unsigned long flags;
  2012. if (!oh)
  2013. return -EINVAL;
  2014. spin_lock_irqsave(&oh->_lock, flags);
  2015. ret = _read_hardreset(oh, name);
  2016. spin_unlock_irqrestore(&oh->_lock, flags);
  2017. return ret;
  2018. }
  2019. /**
  2020. * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
  2021. * @classname: struct omap_hwmod_class name to search for
  2022. * @fn: callback function pointer to call for each hwmod in class @classname
  2023. * @user: arbitrary context data to pass to the callback function
  2024. *
  2025. * For each omap_hwmod of class @classname, call @fn.
  2026. * If the callback function returns something other than
  2027. * zero, the iterator is terminated, and the callback function's return
  2028. * value is passed back to the caller. Returns 0 upon success, -EINVAL
  2029. * if @classname or @fn are NULL, or passes back the error code from @fn.
  2030. */
  2031. int omap_hwmod_for_each_by_class(const char *classname,
  2032. int (*fn)(struct omap_hwmod *oh,
  2033. void *user),
  2034. void *user)
  2035. {
  2036. struct omap_hwmod *temp_oh;
  2037. int ret = 0;
  2038. if (!classname || !fn)
  2039. return -EINVAL;
  2040. pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
  2041. __func__, classname);
  2042. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  2043. if (!strcmp(temp_oh->class->name, classname)) {
  2044. pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
  2045. __func__, temp_oh->name);
  2046. ret = (*fn)(temp_oh, user);
  2047. if (ret)
  2048. break;
  2049. }
  2050. }
  2051. if (ret)
  2052. pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
  2053. __func__, ret);
  2054. return ret;
  2055. }
  2056. /**
  2057. * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
  2058. * @oh: struct omap_hwmod *
  2059. * @state: state that _setup() should leave the hwmod in
  2060. *
  2061. * Sets the hwmod state that @oh will enter at the end of _setup()
  2062. * (called by omap_hwmod_setup_*()). Only valid to call between
  2063. * calling omap_hwmod_register() and omap_hwmod_setup_*(). Returns
  2064. * 0 upon success or -EINVAL if there is a problem with the arguments
  2065. * or if the hwmod is in the wrong state.
  2066. */
  2067. int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
  2068. {
  2069. int ret;
  2070. unsigned long flags;
  2071. if (!oh)
  2072. return -EINVAL;
  2073. if (state != _HWMOD_STATE_DISABLED &&
  2074. state != _HWMOD_STATE_ENABLED &&
  2075. state != _HWMOD_STATE_IDLE)
  2076. return -EINVAL;
  2077. spin_lock_irqsave(&oh->_lock, flags);
  2078. if (oh->_state != _HWMOD_STATE_REGISTERED) {
  2079. ret = -EINVAL;
  2080. goto ohsps_unlock;
  2081. }
  2082. oh->_postsetup_state = state;
  2083. ret = 0;
  2084. ohsps_unlock:
  2085. spin_unlock_irqrestore(&oh->_lock, flags);
  2086. return ret;
  2087. }
  2088. /**
  2089. * omap_hwmod_get_context_loss_count - get lost context count
  2090. * @oh: struct omap_hwmod *
  2091. *
  2092. * Query the powerdomain of of @oh to get the context loss
  2093. * count for this device.
  2094. *
  2095. * Returns the context loss count of the powerdomain assocated with @oh
  2096. * upon success, or zero if no powerdomain exists for @oh.
  2097. */
  2098. u32 omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
  2099. {
  2100. struct powerdomain *pwrdm;
  2101. int ret = 0;
  2102. pwrdm = omap_hwmod_get_pwrdm(oh);
  2103. if (pwrdm)
  2104. ret = pwrdm_get_context_loss_count(pwrdm);
  2105. return ret;
  2106. }
  2107. /**
  2108. * omap_hwmod_no_setup_reset - prevent a hwmod from being reset upon setup
  2109. * @oh: struct omap_hwmod *
  2110. *
  2111. * Prevent the hwmod @oh from being reset during the setup process.
  2112. * Intended for use by board-*.c files on boards with devices that
  2113. * cannot tolerate being reset. Must be called before the hwmod has
  2114. * been set up. Returns 0 upon success or negative error code upon
  2115. * failure.
  2116. */
  2117. int omap_hwmod_no_setup_reset(struct omap_hwmod *oh)
  2118. {
  2119. if (!oh)
  2120. return -EINVAL;
  2121. if (oh->_state != _HWMOD_STATE_REGISTERED) {
  2122. pr_err("omap_hwmod: %s: cannot prevent setup reset; in wrong state\n",
  2123. oh->name);
  2124. return -EINVAL;
  2125. }
  2126. oh->flags |= HWMOD_INIT_NO_RESET;
  2127. return 0;
  2128. }