omap_hwmod.c 72 KB

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