alarmDataOperation.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  1. /*
  2. * omap_hwmod implementation for OMAP2/3/4
  3. *
  4. * Copyright (C) 2009-2011 Nokia Corporation
  5. * Copyright (C) 2011-2012 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-provider.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 <linux/slab.h>
  139. #include <linux/bootmem.h>
  140. #include "clock.h"
  141. #include "omap_hwmod.h"
  142. #include "soc.h"
  143. #include "common.h"
  144. #include "clockdomain.h"
  145. #include "powerdomain.h"
  146. #include "cm2xxx.h"
  147. #include "cm3xxx.h"
  148. #include "cminst44xx.h"
  149. #include "cm33xx.h"
  150. #include "prm.h"
  151. #include "prm3xxx.h"
  152. #include "prm44xx.h"
  153. #include "prm33xx.h"
  154. #include "prminst44xx.h"
  155. #include "mux.h"
  156. #include "pm.h"
  157. /* Name of the OMAP hwmod for the MPU */
  158. #define MPU_INITIATOR_NAME "mpu"
  159. /*
  160. * Number of struct omap_hwmod_link records per struct
  161. * omap_hwmod_ocp_if record (master->slave and slave->master)
  162. */
  163. #define LINKS_PER_OCP_IF 2
  164. /**
  165. * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
  166. * @enable_module: function to enable a module (via MODULEMODE)
  167. * @disable_module: function to disable a module (via MODULEMODE)
  168. *
  169. * XXX Eventually this functionality will be hidden inside the PRM/CM
  170. * device drivers. Until then, this should avoid huge blocks of cpu_is_*()
  171. * conditionals in this code.
  172. */
  173. struct omap_hwmod_soc_ops {
  174. void (*enable_module)(struct omap_hwmod *oh);
  175. int (*disable_module)(struct omap_hwmod *oh);
  176. int (*wait_target_ready)(struct omap_hwmod *oh);
  177. int (*assert_hardreset)(struct omap_hwmod *oh,
  178. struct omap_hwmod_rst_info *ohri);
  179. int (*deassert_hardreset)(struct omap_hwmod *oh,
  180. struct omap_hwmod_rst_info *ohri);
  181. int (*is_hardreset_asserted)(struct omap_hwmod *oh,
  182. struct omap_hwmod_rst_info *ohri);
  183. int (*init_clkdm)(struct omap_hwmod *oh);
  184. void (*update_context_lost)(struct omap_hwmod *oh);
  185. int (*get_context_lost)(struct omap_hwmod *oh);
  186. };
  187. /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
  188. static struct omap_hwmod_soc_ops soc_ops;
  189. /* omap_hwmod_list contains all registered struct omap_hwmods */
  190. static LIST_HEAD(omap_hwmod_list);
  191. /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
  192. static struct omap_hwmod *mpu_oh;
  193. /* io_chain_lock: used to serialize reconfigurations of the I/O chain */
  194. static DEFINE_SPINLOCK(io_chain_lock);
  195. /*
  196. * linkspace: ptr to a buffer that struct omap_hwmod_link records are
  197. * allocated from - used to reduce the number of small memory
  198. * allocations, which has a significant impact on performance
  199. */
  200. static struct omap_hwmod_link *linkspace;
  201. /*
  202. * free_ls, max_ls: array indexes into linkspace; representing the
  203. * next free struct omap_hwmod_link index, and the maximum number of
  204. * struct omap_hwmod_link records allocated (respectively)
  205. */
  206. static unsigned short free_ls, max_ls, ls_supp;
  207. /* inited: set to true once the hwmod code is initialized */
  208. static bool inited;
  209. /* Private functions */
  210. /**
  211. * _fetch_next_ocp_if - return the next OCP interface in a list
  212. * @p: ptr to a ptr to the list_head inside the ocp_if to return
  213. * @i: pointer to the index of the element pointed to by @p in the list
  214. *
  215. * Return a pointer to the struct omap_hwmod_ocp_if record
  216. * containing the struct list_head pointed to by @p, and increment
  217. * @p such that a future call to this routine will return the next
  218. * record.
  219. */
  220. static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
  221. int *i)
  222. {
  223. struct omap_hwmod_ocp_if *oi;
  224. oi = list_entry(*p, struct omap_hwmod_link, node)->ocp_if;
  225. *p = (*p)->next;
  226. *i = *i + 1;
  227. return oi;
  228. }
  229. /**
  230. * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
  231. * @oh: struct omap_hwmod *
  232. *
  233. * Load the current value of the hwmod OCP_SYSCONFIG register into the
  234. * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
  235. * OCP_SYSCONFIG register or 0 upon success.
  236. */
  237. static int _update_sysc_cache(struct omap_hwmod *oh)
  238. {
  239. if (!oh->class->sysc) {
  240. WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  241. return -EINVAL;
  242. }
  243. /* XXX ensure module interface clock is up */
  244. oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
  245. if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
  246. oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
  247. return 0;
  248. }
  249. /**
  250. * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
  251. * @v: OCP_SYSCONFIG value to write
  252. * @oh: struct omap_hwmod *
  253. *
  254. * Write @v into the module class' OCP_SYSCONFIG register, if it has
  255. * one. No return value.
  256. */
  257. static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
  258. {
  259. if (!oh->class->sysc) {
  260. WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
  261. return;
  262. }
  263. /* XXX ensure module interface clock is up */
  264. /* Module might have lost context, always update cache and register */
  265. oh->_sysc_cache = v;
  266. omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
  267. }
  268. /**
  269. * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
  270. * @oh: struct omap_hwmod *
  271. * @standbymode: MIDLEMODE field bits
  272. * @v: pointer to register contents to modify
  273. *
  274. * Update the master standby mode bits in @v to be @standbymode for
  275. * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
  276. * upon error or 0 upon success.
  277. */
  278. static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
  279. u32 *v)
  280. {
  281. u32 mstandby_mask;
  282. u8 mstandby_shift;
  283. if (!oh->class->sysc ||
  284. !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
  285. return -EINVAL;
  286. if (!oh->class->sysc->sysc_fields) {
  287. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  288. return -EINVAL;
  289. }
  290. mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
  291. mstandby_mask = (0x3 << mstandby_shift);
  292. *v &= ~mstandby_mask;
  293. *v |= __ffs(standbymode) << mstandby_shift;
  294. return 0;
  295. }
  296. /**
  297. * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
  298. * @oh: struct omap_hwmod *
  299. * @idlemode: SIDLEMODE field bits
  300. * @v: pointer to register contents to modify
  301. *
  302. * Update the slave idle mode bits in @v to be @idlemode for the @oh
  303. * hwmod. Does not write to the hardware. Returns -EINVAL upon error
  304. * or 0 upon success.
  305. */
  306. static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
  307. {
  308. u32 sidle_mask;
  309. u8 sidle_shift;
  310. if (!oh->class->sysc ||
  311. !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
  312. return -EINVAL;
  313. if (!oh->class->sysc->sysc_fields) {
  314. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  315. return -EINVAL;
  316. }
  317. sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
  318. sidle_mask = (0x3 << sidle_shift);
  319. *v &= ~sidle_mask;
  320. *v |= __ffs(idlemode) << sidle_shift;
  321. return 0;
  322. }
  323. /**
  324. * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  325. * @oh: struct omap_hwmod *
  326. * @clockact: CLOCKACTIVITY field bits
  327. * @v: pointer to register contents to modify
  328. *
  329. * Update the clockactivity mode bits in @v to be @clockact for the
  330. * @oh hwmod. Used for additional powersaving on some modules. Does
  331. * not write to the hardware. Returns -EINVAL upon error or 0 upon
  332. * success.
  333. */
  334. static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
  335. {
  336. u32 clkact_mask;
  337. u8 clkact_shift;
  338. if (!oh->class->sysc ||
  339. !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
  340. return -EINVAL;
  341. if (!oh->class->sysc->sysc_fields) {
  342. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  343. return -EINVAL;
  344. }
  345. clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
  346. clkact_mask = (0x3 << clkact_shift);
  347. *v &= ~clkact_mask;
  348. *v |= clockact << clkact_shift;
  349. return 0;
  350. }
  351. /**
  352. * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
  353. * @oh: struct omap_hwmod *
  354. * @v: pointer to register contents to modify
  355. *
  356. * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
  357. * error or 0 upon success.
  358. */
  359. static int _set_softreset(struct omap_hwmod *oh, u32 *v)
  360. {
  361. u32 softrst_mask;
  362. if (!oh->class->sysc ||
  363. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  364. return -EINVAL;
  365. if (!oh->class->sysc->sysc_fields) {
  366. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  367. return -EINVAL;
  368. }
  369. softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
  370. *v |= softrst_mask;
  371. return 0;
  372. }
  373. /**
  374. * _wait_softreset_complete - wait for an OCP softreset to complete
  375. * @oh: struct omap_hwmod * to wait on
  376. *
  377. * Wait until the IP block represented by @oh reports that its OCP
  378. * softreset is complete. This can be triggered by software (see
  379. * _ocp_softreset()) or by hardware upon returning from off-mode (one
  380. * example is HSMMC). Waits for up to MAX_MODULE_SOFTRESET_WAIT
  381. * microseconds. Returns the number of microseconds waited.
  382. */
  383. static int _wait_softreset_complete(struct omap_hwmod *oh)
  384. {
  385. struct omap_hwmod_class_sysconfig *sysc;
  386. u32 softrst_mask;
  387. int c = 0;
  388. sysc = oh->class->sysc;
  389. if (sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
  390. omap_test_timeout((omap_hwmod_read(oh, sysc->syss_offs)
  391. & SYSS_RESETDONE_MASK),
  392. MAX_MODULE_SOFTRESET_WAIT, c);
  393. else if (sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
  394. softrst_mask = (0x1 << sysc->sysc_fields->srst_shift);
  395. omap_test_timeout(!(omap_hwmod_read(oh, sysc->sysc_offs)
  396. & softrst_mask),
  397. MAX_MODULE_SOFTRESET_WAIT, c);
  398. }
  399. return c;
  400. }
  401. /**
  402. * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
  403. * @oh: struct omap_hwmod *
  404. *
  405. * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
  406. * of some modules. When the DMA must perform read/write accesses, the
  407. * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
  408. * for power management, software must set the DMADISABLE bit back to 1.
  409. *
  410. * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon
  411. * error or 0 upon success.
  412. */
  413. static int _set_dmadisable(struct omap_hwmod *oh)
  414. {
  415. u32 v;
  416. u32 dmadisable_mask;
  417. if (!oh->class->sysc ||
  418. !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
  419. return -EINVAL;
  420. if (!oh->class->sysc->sysc_fields) {
  421. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  422. return -EINVAL;
  423. }
  424. /* clocks must be on for this operation */
  425. if (oh->_state != _HWMOD_STATE_ENABLED) {
  426. pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
  427. return -EINVAL;
  428. }
  429. pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
  430. v = oh->_sysc_cache;
  431. dmadisable_mask =
  432. (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
  433. v |= dmadisable_mask;
  434. _write_sysconfig(v, oh);
  435. return 0;
  436. }
  437. /**
  438. * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
  439. * @oh: struct omap_hwmod *
  440. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  441. * @v: pointer to register contents to modify
  442. *
  443. * Update the module autoidle bit in @v to be @autoidle for the @oh
  444. * hwmod. The autoidle bit controls whether the module can gate
  445. * internal clocks automatically when it isn't doing anything; the
  446. * exact function of this bit varies on a per-module basis. This
  447. * function does not write to the hardware. Returns -EINVAL upon
  448. * error or 0 upon success.
  449. */
  450. static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
  451. u32 *v)
  452. {
  453. u32 autoidle_mask;
  454. u8 autoidle_shift;
  455. if (!oh->class->sysc ||
  456. !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
  457. return -EINVAL;
  458. if (!oh->class->sysc->sysc_fields) {
  459. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  460. return -EINVAL;
  461. }
  462. autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
  463. autoidle_mask = (0x1 << autoidle_shift);
  464. *v &= ~autoidle_mask;
  465. *v |= autoidle << autoidle_shift;
  466. return 0;
  467. }
  468. /**
  469. * _set_idle_ioring_wakeup - enable/disable IO pad wakeup on hwmod idle for mux
  470. * @oh: struct omap_hwmod *
  471. * @set_wake: bool value indicating to set (true) or clear (false) wakeup enable
  472. *
  473. * Set or clear the I/O pad wakeup flag in the mux entries for the
  474. * hwmod @oh. This function changes the @oh->mux->pads_dynamic array
  475. * in memory. If the hwmod is currently idled, and the new idle
  476. * values don't match the previous ones, this function will also
  477. * update the SCM PADCTRL registers. Otherwise, if the hwmod is not
  478. * currently idled, this function won't touch the hardware: the new
  479. * mux settings are written to the SCM PADCTRL registers when the
  480. * hwmod is idled. No return value.
  481. */
  482. static void _set_idle_ioring_wakeup(struct omap_hwmod *oh, bool set_wake)
  483. {
  484. struct omap_device_pad *pad;
  485. bool change = false;
  486. u16 prev_idle;
  487. int j;
  488. if (!oh->mux || !oh->mux->enabled)
  489. return;
  490. for (j = 0; j < oh->mux->nr_pads_dynamic; j++) {
  491. pad = oh->mux->pads_dynamic[j];
  492. if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP))
  493. continue;
  494. prev_idle = pad->idle;
  495. if (set_wake)
  496. pad->idle |= OMAP_WAKEUP_EN;
  497. else
  498. pad->idle &= ~OMAP_WAKEUP_EN;
  499. if (prev_idle != pad->idle)
  500. change = true;
  501. }
  502. if (change && oh->_state == _HWMOD_STATE_IDLE)
  503. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  504. }
  505. /**
  506. * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  507. * @oh: struct omap_hwmod *
  508. *
  509. * Allow the hardware module @oh to send wakeups. Returns -EINVAL
  510. * upon error or 0 upon success.
  511. */
  512. static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
  513. {
  514. if (!oh->class->sysc ||
  515. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  516. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  517. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  518. return -EINVAL;
  519. if (!oh->class->sysc->sysc_fields) {
  520. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  521. return -EINVAL;
  522. }
  523. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  524. *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
  525. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  526. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  527. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  528. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
  529. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  530. oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
  531. return 0;
  532. }
  533. /**
  534. * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
  535. * @oh: struct omap_hwmod *
  536. *
  537. * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
  538. * upon error or 0 upon success.
  539. */
  540. static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
  541. {
  542. if (!oh->class->sysc ||
  543. !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
  544. (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
  545. (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
  546. return -EINVAL;
  547. if (!oh->class->sysc->sysc_fields) {
  548. WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
  549. return -EINVAL;
  550. }
  551. if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
  552. *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
  553. if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
  554. _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
  555. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  556. _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
  557. /* XXX test pwrdm_get_wken for this hwmod's subsystem */
  558. oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
  559. return 0;
  560. }
  561. static struct clockdomain *_get_clkdm(struct omap_hwmod *oh)
  562. {
  563. struct clk_hw_omap *clk;
  564. if (oh->clkdm) {
  565. return oh->clkdm;
  566. } else if (oh->_clk) {
  567. clk = to_clk_hw_omap(__clk_get_hw(oh->_clk));
  568. return clk->clkdm;
  569. }
  570. return NULL;
  571. }
  572. /**
  573. * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
  574. * @oh: struct omap_hwmod *
  575. *
  576. * Prevent the hardware module @oh from entering idle while the
  577. * hardare module initiator @init_oh is active. Useful when a module
  578. * will be accessed by a particular initiator (e.g., if a module will
  579. * be accessed by the IVA, there should be a sleepdep between the IVA
  580. * initiator and the module). Only applies to modules in smart-idle
  581. * mode. If the clockdomain is marked as not needing autodeps, return
  582. * 0 without doing anything. Otherwise, returns -EINVAL upon error or
  583. * passes along clkdm_add_sleepdep() value upon success.
  584. */
  585. static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  586. {
  587. struct clockdomain *clkdm, *init_clkdm;
  588. clkdm = _get_clkdm(oh);
  589. init_clkdm = _get_clkdm(init_oh);
  590. if (!clkdm || !init_clkdm)
  591. return -EINVAL;
  592. if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
  593. return 0;
  594. return clkdm_add_sleepdep(clkdm, init_clkdm);
  595. }
  596. /**
  597. * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
  598. * @oh: struct omap_hwmod *
  599. *
  600. * Allow the hardware module @oh to enter idle while the hardare
  601. * module initiator @init_oh is active. Useful when a module will not
  602. * be accessed by a particular initiator (e.g., if a module will not
  603. * be accessed by the IVA, there should be no sleepdep between the IVA
  604. * initiator and the module). Only applies to modules in smart-idle
  605. * mode. If the clockdomain is marked as not needing autodeps, return
  606. * 0 without doing anything. Returns -EINVAL upon error or passes
  607. * along clkdm_del_sleepdep() value upon success.
  608. */
  609. static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
  610. {
  611. struct clockdomain *clkdm, *init_clkdm;
  612. clkdm = _get_clkdm(oh);
  613. init_clkdm = _get_clkdm(init_oh);
  614. if (!clkdm || !init_clkdm)
  615. return -EINVAL;
  616. if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
  617. return 0;
  618. return clkdm_del_sleepdep(clkdm, init_clkdm);
  619. }
  620. /**
  621. * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
  622. * @oh: struct omap_hwmod *
  623. *
  624. * Called from _init_clocks(). Populates the @oh _clk (main
  625. * functional clock pointer) if a main_clk is present. Returns 0 on
  626. * success or -EINVAL on error.
  627. */
  628. static int _init_main_clk(struct omap_hwmod *oh)
  629. {
  630. int ret = 0;
  631. if (!oh->main_clk)
  632. return 0;
  633. oh->_clk = clk_get(NULL, oh->main_clk);
  634. if (IS_ERR(oh->_clk)) {
  635. pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
  636. oh->name, oh->main_clk);
  637. return -EINVAL;
  638. }
  639. /*
  640. * HACK: This needs a re-visit once clk_prepare() is implemented
  641. * to do something meaningful. Today its just a no-op.
  642. * If clk_prepare() is used at some point to do things like
  643. * voltage scaling etc, then this would have to be moved to
  644. * some point where subsystems like i2c and pmic become
  645. * available.
  646. */
  647. clk_prepare(oh->_clk);
  648. if (!_get_clkdm(oh))
  649. pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
  650. oh->name, oh->main_clk);
  651. return ret;
  652. }
  653. /**
  654. * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
  655. * @oh: struct omap_hwmod *
  656. *
  657. * Called from _init_clocks(). Populates the @oh OCP slave interface
  658. * clock pointers. Returns 0 on success or -EINVAL on error.
  659. */
  660. static int _init_interface_clks(struct omap_hwmod *oh)
  661. {
  662. struct omap_hwmod_ocp_if *os;
  663. struct list_head *p;
  664. struct clk *c;
  665. int i = 0;
  666. int ret = 0;
  667. p = oh->slave_ports.next;
  668. while (i < oh->slaves_cnt) {
  669. os = _fetch_next_ocp_if(&p, &i);
  670. if (!os->clk)
  671. continue;
  672. c = clk_get(NULL, os->clk);
  673. if (IS_ERR(c)) {
  674. pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
  675. oh->name, os->clk);
  676. ret = -EINVAL;
  677. }
  678. os->_clk = c;
  679. /*
  680. * HACK: This needs a re-visit once clk_prepare() is implemented
  681. * to do something meaningful. Today its just a no-op.
  682. * If clk_prepare() is used at some point to do things like
  683. * voltage scaling etc, then this would have to be moved to
  684. * some point where subsystems like i2c and pmic become
  685. * available.
  686. */
  687. clk_prepare(os->_clk);
  688. }
  689. return ret;
  690. }
  691. /**
  692. * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
  693. * @oh: struct omap_hwmod *
  694. *
  695. * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
  696. * clock pointers. Returns 0 on success or -EINVAL on error.
  697. */
  698. static int _init_opt_clks(struct omap_hwmod *oh)
  699. {
  700. struct omap_hwmod_opt_clk *oc;
  701. struct clk *c;
  702. int i;
  703. int ret = 0;
  704. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
  705. c = clk_get(NULL, oc->clk);
  706. if (IS_ERR(c)) {
  707. pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
  708. oh->name, oc->clk);
  709. ret = -EINVAL;
  710. }
  711. oc->_clk = c;
  712. /*
  713. * HACK: This needs a re-visit once clk_prepare() is implemented
  714. * to do something meaningful. Today its just a no-op.
  715. * If clk_prepare() is used at some point to do things like
  716. * voltage scaling etc, then this would have to be moved to
  717. * some point where subsystems like i2c and pmic become
  718. * available.
  719. */
  720. clk_prepare(oc->_clk);
  721. }
  722. return ret;
  723. }
  724. /**
  725. * _enable_clocks - enable hwmod main clock and interface clocks
  726. * @oh: struct omap_hwmod *
  727. *
  728. * Enables all clocks necessary for register reads and writes to succeed
  729. * on the hwmod @oh. Returns 0.
  730. */
  731. static int _enable_clocks(struct omap_hwmod *oh)
  732. {
  733. struct omap_hwmod_ocp_if *os;
  734. struct list_head *p;
  735. int i = 0;
  736. pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
  737. if (oh->_clk)
  738. clk_enable(oh->_clk);
  739. p = oh->slave_ports.next;
  740. while (i < oh->slaves_cnt) {
  741. os = _fetch_next_ocp_if(&p, &i);
  742. if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
  743. clk_enable(os->_clk);
  744. }
  745. /* The opt clocks are controlled by the device driver. */
  746. return 0;
  747. }
  748. /**
  749. * _disable_clocks - disable hwmod main clock and interface clocks
  750. * @oh: struct omap_hwmod *
  751. *
  752. * Disables the hwmod @oh main functional and interface clocks. Returns 0.
  753. */
  754. static int _disable_clocks(struct omap_hwmod *oh)
  755. {
  756. struct omap_hwmod_ocp_if *os;
  757. struct list_head *p;
  758. int i = 0;
  759. pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
  760. if (oh->_clk)
  761. clk_disable(oh->_clk);
  762. p = oh->slave_ports.next;
  763. while (i < oh->slaves_cnt) {
  764. os = _fetch_next_ocp_if(&p, &i);
  765. if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
  766. clk_disable(os->_clk);
  767. }
  768. /* The opt clocks are controlled by the device driver. */
  769. return 0;
  770. }
  771. static void _enable_optional_clocks(struct omap_hwmod *oh)
  772. {
  773. struct omap_hwmod_opt_clk *oc;
  774. int i;
  775. pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
  776. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  777. if (oc->_clk) {
  778. pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
  779. __clk_get_name(oc->_clk));
  780. clk_enable(oc->_clk);
  781. }
  782. }
  783. static void _disable_optional_clocks(struct omap_hwmod *oh)
  784. {
  785. struct omap_hwmod_opt_clk *oc;
  786. int i;
  787. pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
  788. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  789. if (oc->_clk) {
  790. pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
  791. __clk_get_name(oc->_clk));
  792. clk_disable(oc->_clk);
  793. }
  794. }
  795. /**
  796. * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
  797. * @oh: struct omap_hwmod *
  798. *
  799. * Enables the PRCM module mode related to the hwmod @oh.
  800. * No return value.
  801. */
  802. static void _omap4_enable_module(struct omap_hwmod *oh)
  803. {
  804. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  805. return;
  806. pr_debug("omap_hwmod: %s: %s: %d\n",
  807. oh->name, __func__, oh->prcm.omap4.modulemode);
  808. omap4_cminst_module_enable(oh->prcm.omap4.modulemode,
  809. oh->clkdm->prcm_partition,
  810. oh->clkdm->cm_inst,
  811. oh->clkdm->clkdm_offs,
  812. oh->prcm.omap4.clkctrl_offs);
  813. }
  814. /**
  815. * _am33xx_enable_module - enable CLKCTRL modulemode on AM33XX
  816. * @oh: struct omap_hwmod *
  817. *
  818. * Enables the PRCM module mode related to the hwmod @oh.
  819. * No return value.
  820. */
  821. static void _am33xx_enable_module(struct omap_hwmod *oh)
  822. {
  823. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  824. return;
  825. pr_debug("omap_hwmod: %s: %s: %d\n",
  826. oh->name, __func__, oh->prcm.omap4.modulemode);
  827. am33xx_cm_module_enable(oh->prcm.omap4.modulemode, oh->clkdm->cm_inst,
  828. oh->clkdm->clkdm_offs,
  829. oh->prcm.omap4.clkctrl_offs);
  830. }
  831. /**
  832. * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
  833. * @oh: struct omap_hwmod *
  834. *
  835. * Wait for a module @oh to enter slave idle. Returns 0 if the module
  836. * does not have an IDLEST bit or if the module successfully enters
  837. * slave idle; otherwise, pass along the return value of the
  838. * appropriate *_cm*_wait_module_idle() function.
  839. */
  840. static int _omap4_wait_target_disable(struct omap_hwmod *oh)
  841. {
  842. if (!oh)
  843. return -EINVAL;
  844. if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
  845. return 0;
  846. if (oh->flags & HWMOD_NO_IDLEST)
  847. return 0;
  848. return omap4_cminst_wait_module_idle(oh->clkdm->prcm_partition,
  849. oh->clkdm->cm_inst,
  850. oh->clkdm->clkdm_offs,
  851. oh->prcm.omap4.clkctrl_offs);
  852. }
  853. /**
  854. * _am33xx_wait_target_disable - wait for a module to be disabled on AM33XX
  855. * @oh: struct omap_hwmod *
  856. *
  857. * Wait for a module @oh to enter slave idle. Returns 0 if the module
  858. * does not have an IDLEST bit or if the module successfully enters
  859. * slave idle; otherwise, pass along the return value of the
  860. * appropriate *_cm*_wait_module_idle() function.
  861. */
  862. static int _am33xx_wait_target_disable(struct omap_hwmod *oh)
  863. {
  864. if (!oh)
  865. return -EINVAL;
  866. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  867. return 0;
  868. if (oh->flags & HWMOD_NO_IDLEST)
  869. return 0;
  870. return am33xx_cm_wait_module_idle(oh->clkdm->cm_inst,
  871. oh->clkdm->clkdm_offs,
  872. oh->prcm.omap4.clkctrl_offs);
  873. }
  874. /**
  875. * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
  876. * @oh: struct omap_hwmod *oh
  877. *
  878. * Count and return the number of MPU IRQs associated with the hwmod
  879. * @oh. Used to allocate struct resource data. Returns 0 if @oh is
  880. * NULL.
  881. */
  882. static int _count_mpu_irqs(struct omap_hwmod *oh)
  883. {
  884. struct omap_hwmod_irq_info *ohii;
  885. int i = 0;
  886. if (!oh || !oh->mpu_irqs)
  887. return 0;
  888. do {
  889. ohii = &oh->mpu_irqs[i++];
  890. } while (ohii->irq != -1);
  891. return i-1;
  892. }
  893. /**
  894. * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
  895. * @oh: struct omap_hwmod *oh
  896. *
  897. * Count and return the number of SDMA request lines associated with
  898. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  899. * if @oh is NULL.
  900. */
  901. static int _count_sdma_reqs(struct omap_hwmod *oh)
  902. {
  903. struct omap_hwmod_dma_info *ohdi;
  904. int i = 0;
  905. if (!oh || !oh->sdma_reqs)
  906. return 0;
  907. do {
  908. ohdi = &oh->sdma_reqs[i++];
  909. } while (ohdi->dma_req != -1);
  910. return i-1;
  911. }
  912. /**
  913. * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
  914. * @oh: struct omap_hwmod *oh
  915. *
  916. * Count and return the number of address space ranges associated with
  917. * the hwmod @oh. Used to allocate struct resource data. Returns 0
  918. * if @oh is NULL.
  919. */
  920. static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
  921. {
  922. struct omap_hwmod_addr_space *mem;
  923. int i = 0;
  924. if (!os || !os->addr)
  925. return 0;
  926. do {
  927. mem = &os->addr[i++];
  928. } while (mem->pa_start != mem->pa_end);
  929. return i-1;
  930. }
  931. /**
  932. * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
  933. * @oh: struct omap_hwmod * to operate on
  934. * @name: pointer to the name of the MPU interrupt number to fetch (optional)
  935. * @irq: pointer to an unsigned int to store the MPU IRQ number to
  936. *
  937. * Retrieve a MPU hardware IRQ line number named by @name associated
  938. * with the IP block pointed to by @oh. The IRQ number will be filled
  939. * into the address pointed to by @dma. When @name is non-null, the
  940. * IRQ line number associated with the named entry will be returned.
  941. * If @name is null, the first matching entry will be returned. Data
  942. * order is not meaningful in hwmod data, so callers are strongly
  943. * encouraged to use a non-null @name whenever possible to avoid
  944. * unpredictable effects if hwmod data is later added that causes data
  945. * ordering to change. Returns 0 upon success or a negative error
  946. * code upon error.
  947. */
  948. static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
  949. unsigned int *irq)
  950. {
  951. int i;
  952. bool found = false;
  953. if (!oh->mpu_irqs)
  954. return -ENOENT;
  955. i = 0;
  956. while (oh->mpu_irqs[i].irq != -1) {
  957. if (name == oh->mpu_irqs[i].name ||
  958. !strcmp(name, oh->mpu_irqs[i].name)) {
  959. found = true;
  960. break;
  961. }
  962. i++;
  963. }
  964. if (!found)
  965. return -ENOENT;
  966. *irq = oh->mpu_irqs[i].irq;
  967. return 0;
  968. }
  969. /**
  970. * _get_sdma_req_by_name - fetch SDMA request line ID by name
  971. * @oh: struct omap_hwmod * to operate on
  972. * @name: pointer to the name of the SDMA request line to fetch (optional)
  973. * @dma: pointer to an unsigned int to store the request line ID to
  974. *
  975. * Retrieve an SDMA request line ID named by @name on the IP block
  976. * pointed to by @oh. The ID will be filled into the address pointed
  977. * to by @dma. When @name is non-null, the request line ID associated
  978. * with the named entry will be returned. If @name is null, the first
  979. * matching entry will be returned. Data order is not meaningful in
  980. * hwmod data, so callers are strongly encouraged to use a non-null
  981. * @name whenever possible to avoid unpredictable effects if hwmod
  982. * data is later added that causes data ordering to change. Returns 0
  983. * upon success or a negative error code upon error.
  984. */
  985. static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
  986. unsigned int *dma)
  987. {
  988. int i;
  989. bool found = false;
  990. if (!oh->sdma_reqs)
  991. return -ENOENT;
  992. i = 0;
  993. while (oh->sdma_reqs[i].dma_req != -1) {
  994. if (name == oh->sdma_reqs[i].name ||
  995. !strcmp(name, oh->sdma_reqs[i].name)) {
  996. found = true;
  997. break;
  998. }
  999. i++;
  1000. }
  1001. if (!found)
  1002. return -ENOENT;
  1003. *dma = oh->sdma_reqs[i].dma_req;
  1004. return 0;
  1005. }
  1006. /**
  1007. * _get_addr_space_by_name - fetch address space start & end by name
  1008. * @oh: struct omap_hwmod * to operate on
  1009. * @name: pointer to the name of the address space to fetch (optional)
  1010. * @pa_start: pointer to a u32 to store the starting address to
  1011. * @pa_end: pointer to a u32 to store the ending address to
  1012. *
  1013. * Retrieve address space start and end addresses for the IP block
  1014. * pointed to by @oh. The data will be filled into the addresses
  1015. * pointed to by @pa_start and @pa_end. When @name is non-null, the
  1016. * address space data associated with the named entry will be
  1017. * returned. If @name is null, the first matching entry will be
  1018. * returned. Data order is not meaningful in hwmod data, so callers
  1019. * are strongly encouraged to use a non-null @name whenever possible
  1020. * to avoid unpredictable effects if hwmod data is later added that
  1021. * causes data ordering to change. Returns 0 upon success or a
  1022. * negative error code upon error.
  1023. */
  1024. static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
  1025. u32 *pa_start, u32 *pa_end)
  1026. {
  1027. int i, j;
  1028. struct omap_hwmod_ocp_if *os;
  1029. struct list_head *p = NULL;
  1030. bool found = false;
  1031. p = oh->slave_ports.next;
  1032. i = 0;
  1033. while (i < oh->slaves_cnt) {
  1034. os = _fetch_next_ocp_if(&p, &i);
  1035. if (!os->addr)
  1036. return -ENOENT;
  1037. j = 0;
  1038. while (os->addr[j].pa_start != os->addr[j].pa_end) {
  1039. if (name == os->addr[j].name ||
  1040. !strcmp(name, os->addr[j].name)) {
  1041. found = true;
  1042. break;
  1043. }
  1044. j++;
  1045. }
  1046. if (found)
  1047. break;
  1048. }
  1049. if (!found)
  1050. return -ENOENT;
  1051. *pa_start = os->addr[j].pa_start;
  1052. *pa_end = os->addr[j].pa_end;
  1053. return 0;
  1054. }
  1055. /**
  1056. * _save_mpu_port_index - find and save the index to @oh's MPU port
  1057. * @oh: struct omap_hwmod *
  1058. *
  1059. * Determines the array index of the OCP slave port that the MPU uses
  1060. * to address the device, and saves it into the struct omap_hwmod.
  1061. * Intended to be called during hwmod registration only. No return
  1062. * value.
  1063. */
  1064. static void __init _save_mpu_port_index(struct omap_hwmod *oh)
  1065. {
  1066. struct omap_hwmod_ocp_if *os = NULL;
  1067. struct list_head *p;
  1068. int i = 0;
  1069. if (!oh)
  1070. return;
  1071. oh->_int_flags |= _HWMOD_NO_MPU_PORT;
  1072. p = oh->slave_ports.next;
  1073. while (i < oh->slaves_cnt) {
  1074. os = _fetch_next_ocp_if(&p, &i);
  1075. if (os->user & OCP_USER_MPU) {
  1076. oh->_mpu_port = os;
  1077. oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
  1078. break;
  1079. }
  1080. }
  1081. return;
  1082. }
  1083. /**
  1084. * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
  1085. * @oh: struct omap_hwmod *
  1086. *
  1087. * Given a pointer to a struct omap_hwmod record @oh, return a pointer
  1088. * to the struct omap_hwmod_ocp_if record that is used by the MPU to
  1089. * communicate with the IP block. This interface need not be directly
  1090. * connected to the MPU (and almost certainly is not), but is directly
  1091. * connected to the IP block represented by @oh. Returns a pointer
  1092. * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
  1093. * error or if there does not appear to be a path from the MPU to this
  1094. * IP block.
  1095. */
  1096. static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
  1097. {
  1098. if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
  1099. return NULL;
  1100. return oh->_mpu_port;
  1101. };
  1102. /**
  1103. * _find_mpu_rt_addr_space - return MPU register target address space for @oh
  1104. * @oh: struct omap_hwmod *
  1105. *
  1106. * Returns a pointer to the struct omap_hwmod_addr_space record representing
  1107. * the register target MPU address space; or returns NULL upon error.
  1108. */
  1109. static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
  1110. {
  1111. struct omap_hwmod_ocp_if *os;
  1112. struct omap_hwmod_addr_space *mem;
  1113. int found = 0, i = 0;
  1114. os = _find_mpu_rt_port(oh);
  1115. if (!os || !os->addr)
  1116. return NULL;
  1117. do {
  1118. mem = &os->addr[i++];
  1119. if (mem->flags & ADDR_TYPE_RT)
  1120. found = 1;
  1121. } while (!found && mem->pa_start != mem->pa_end);
  1122. return (found) ? mem : NULL;
  1123. }
  1124. /**
  1125. * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
  1126. * @oh: struct omap_hwmod *
  1127. *
  1128. * Ensure that the OCP_SYSCONFIG register for the IP block represented
  1129. * by @oh is set to indicate to the PRCM that the IP block is active.
  1130. * Usually this means placing the module into smart-idle mode and
  1131. * smart-standby, but if there is a bug in the automatic idle handling
  1132. * for the IP block, it may need to be placed into the force-idle or
  1133. * no-idle variants of these modes. No return value.
  1134. */
  1135. static void _enable_sysc(struct omap_hwmod *oh)
  1136. {
  1137. u8 idlemode, sf;
  1138. u32 v;
  1139. bool clkdm_act;
  1140. struct clockdomain *clkdm;
  1141. if (!oh->class->sysc)
  1142. return;
  1143. /*
  1144. * Wait until reset has completed, this is needed as the IP
  1145. * block is reset automatically by hardware in some cases
  1146. * (off-mode for example), and the drivers require the
  1147. * IP to be ready when they access it
  1148. */
  1149. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1150. _enable_optional_clocks(oh);
  1151. _wait_softreset_complete(oh);
  1152. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1153. _disable_optional_clocks(oh);
  1154. v = oh->_sysc_cache;
  1155. sf = oh->class->sysc->sysc_flags;
  1156. clkdm = _get_clkdm(oh);
  1157. if (sf & SYSC_HAS_SIDLEMODE) {
  1158. clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU);
  1159. if (clkdm_act && !(oh->class->sysc->idlemodes &
  1160. (SIDLE_SMART | SIDLE_SMART_WKUP)))
  1161. idlemode = HWMOD_IDLEMODE_FORCE;
  1162. else
  1163. idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
  1164. HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
  1165. _set_slave_idlemode(oh, idlemode, &v);
  1166. }
  1167. if (sf & SYSC_HAS_MIDLEMODE) {
  1168. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  1169. idlemode = HWMOD_IDLEMODE_NO;
  1170. } else {
  1171. if (sf & SYSC_HAS_ENAWAKEUP)
  1172. _enable_wakeup(oh, &v);
  1173. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  1174. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  1175. else
  1176. idlemode = HWMOD_IDLEMODE_SMART;
  1177. }
  1178. _set_master_standbymode(oh, idlemode, &v);
  1179. }
  1180. /*
  1181. * XXX The clock framework should handle this, by
  1182. * calling into this code. But this must wait until the
  1183. * clock structures are tagged with omap_hwmod entries
  1184. */
  1185. if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
  1186. (sf & SYSC_HAS_CLOCKACTIVITY))
  1187. _set_clockactivity(oh, oh->class->sysc->clockact, &v);
  1188. /* If slave is in SMARTIDLE, also enable wakeup */
  1189. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  1190. _enable_wakeup(oh, &v);
  1191. _write_sysconfig(v, oh);
  1192. /*
  1193. * Set the autoidle bit only after setting the smartidle bit
  1194. * Setting this will not have any impact on the other modules.
  1195. */
  1196. if (sf & SYSC_HAS_AUTOIDLE) {
  1197. idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
  1198. 0 : 1;
  1199. _set_module_autoidle(oh, idlemode, &v);
  1200. _write_sysconfig(v, oh);
  1201. }
  1202. }
  1203. /**
  1204. * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
  1205. * @oh: struct omap_hwmod *
  1206. *
  1207. * If module is marked as SWSUP_SIDLE, force the module into slave
  1208. * idle; otherwise, configure it for smart-idle. If module is marked
  1209. * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
  1210. * configure it for smart-standby. No return value.
  1211. */
  1212. static void _idle_sysc(struct omap_hwmod *oh)
  1213. {
  1214. u8 idlemode, sf;
  1215. u32 v;
  1216. if (!oh->class->sysc)
  1217. return;
  1218. v = oh->_sysc_cache;
  1219. sf = oh->class->sysc->sysc_flags;
  1220. if (sf & SYSC_HAS_SIDLEMODE) {
  1221. /* XXX What about HWMOD_IDLEMODE_SMART_WKUP? */
  1222. if (oh->flags & HWMOD_SWSUP_SIDLE ||
  1223. !(oh->class->sysc->idlemodes &
  1224. (SIDLE_SMART | SIDLE_SMART_WKUP)))
  1225. idlemode = HWMOD_IDLEMODE_FORCE;
  1226. else
  1227. idlemode = HWMOD_IDLEMODE_SMART;
  1228. _set_slave_idlemode(oh, idlemode, &v);
  1229. }
  1230. if (sf & SYSC_HAS_MIDLEMODE) {
  1231. if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
  1232. idlemode = HWMOD_IDLEMODE_FORCE;
  1233. } else {
  1234. if (sf & SYSC_HAS_ENAWAKEUP)
  1235. _enable_wakeup(oh, &v);
  1236. if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
  1237. idlemode = HWMOD_IDLEMODE_SMART_WKUP;
  1238. else
  1239. idlemode = HWMOD_IDLEMODE_SMART;
  1240. }
  1241. _set_master_standbymode(oh, idlemode, &v);
  1242. }
  1243. /* If slave is in SMARTIDLE, also enable wakeup */
  1244. if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
  1245. _enable_wakeup(oh, &v);
  1246. _write_sysconfig(v, oh);
  1247. }
  1248. /**
  1249. * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
  1250. * @oh: struct omap_hwmod *
  1251. *
  1252. * Force the module into slave idle and master suspend. No return
  1253. * value.
  1254. */
  1255. static void _shutdown_sysc(struct omap_hwmod *oh)
  1256. {
  1257. u32 v;
  1258. u8 sf;
  1259. if (!oh->class->sysc)
  1260. return;
  1261. v = oh->_sysc_cache;
  1262. sf = oh->class->sysc->sysc_flags;
  1263. if (sf & SYSC_HAS_SIDLEMODE)
  1264. _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
  1265. if (sf & SYSC_HAS_MIDLEMODE)
  1266. _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
  1267. if (sf & SYSC_HAS_AUTOIDLE)
  1268. _set_module_autoidle(oh, 1, &v);
  1269. _write_sysconfig(v, oh);
  1270. }
  1271. /**
  1272. * _lookup - find an omap_hwmod by name
  1273. * @name: find an omap_hwmod by name
  1274. *
  1275. * Return a pointer to an omap_hwmod by name, or NULL if not found.
  1276. */
  1277. static struct omap_hwmod *_lookup(const char *name)
  1278. {
  1279. struct omap_hwmod *oh, *temp_oh;
  1280. oh = NULL;
  1281. list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
  1282. if (!strcmp(name, temp_oh->name)) {
  1283. oh = temp_oh;
  1284. break;
  1285. }
  1286. }
  1287. return oh;
  1288. }
  1289. /**
  1290. * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
  1291. * @oh: struct omap_hwmod *
  1292. *
  1293. * Convert a clockdomain name stored in a struct omap_hwmod into a
  1294. * clockdomain pointer, and save it into the struct omap_hwmod.
  1295. * Return -EINVAL if the clkdm_name lookup failed.
  1296. */
  1297. static int _init_clkdm(struct omap_hwmod *oh)
  1298. {
  1299. if (!oh->clkdm_name) {
  1300. pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
  1301. return 0;
  1302. }
  1303. oh->clkdm = clkdm_lookup(oh->clkdm_name);
  1304. if (!oh->clkdm) {
  1305. pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
  1306. oh->name, oh->clkdm_name);
  1307. return -EINVAL;
  1308. }
  1309. pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
  1310. oh->name, oh->clkdm_name);
  1311. return 0;
  1312. }
  1313. /**
  1314. * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
  1315. * well the clockdomain.
  1316. * @oh: struct omap_hwmod *
  1317. * @data: not used; pass NULL
  1318. *
  1319. * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
  1320. * Resolves all clock names embedded in the hwmod. Returns 0 on
  1321. * success, or a negative error code on failure.
  1322. */
  1323. static int _init_clocks(struct omap_hwmod *oh, void *data)
  1324. {
  1325. int ret = 0;
  1326. if (oh->_state != _HWMOD_STATE_REGISTERED)
  1327. return 0;
  1328. pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
  1329. if (soc_ops.init_clkdm)
  1330. ret |= soc_ops.init_clkdm(oh);
  1331. ret |= _init_main_clk(oh);
  1332. ret |= _init_interface_clks(oh);
  1333. ret |= _init_opt_clks(oh);
  1334. if (!ret)
  1335. oh->_state = _HWMOD_STATE_CLKS_INITED;
  1336. else
  1337. pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
  1338. return ret;
  1339. }
  1340. /**
  1341. * _lookup_hardreset - fill register bit info for this hwmod/reset line
  1342. * @oh: struct omap_hwmod *
  1343. * @name: name of the reset line in the context of this hwmod
  1344. * @ohri: struct omap_hwmod_rst_info * that this function will fill in
  1345. *
  1346. * Return the bit position of the reset line that match the
  1347. * input name. Return -ENOENT if not found.
  1348. */
  1349. static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
  1350. struct omap_hwmod_rst_info *ohri)
  1351. {
  1352. int i;
  1353. for (i = 0; i < oh->rst_lines_cnt; i++) {
  1354. const char *rst_line = oh->rst_lines[i].name;
  1355. if (!strcmp(rst_line, name)) {
  1356. ohri->rst_shift = oh->rst_lines[i].rst_shift;
  1357. ohri->st_shift = oh->rst_lines[i].st_shift;
  1358. pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
  1359. oh->name, __func__, rst_line, ohri->rst_shift,
  1360. ohri->st_shift);
  1361. return 0;
  1362. }
  1363. }
  1364. return -ENOENT;
  1365. }
  1366. /**
  1367. * _assert_hardreset - assert the HW reset line of submodules
  1368. * contained in the hwmod module.
  1369. * @oh: struct omap_hwmod *
  1370. * @name: name of the reset line to lookup and assert
  1371. *
  1372. * Some IP like dsp, ipu or iva contain processor that require an HW
  1373. * reset line to be assert / deassert in order to enable fully the IP.
  1374. * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
  1375. * asserting the hardreset line on the currently-booted SoC, or passes
  1376. * along the return value from _lookup_hardreset() or the SoC's
  1377. * assert_hardreset code.
  1378. */
  1379. static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
  1380. {
  1381. struct omap_hwmod_rst_info ohri;
  1382. int ret = -EINVAL;
  1383. if (!oh)
  1384. return -EINVAL;
  1385. if (!soc_ops.assert_hardreset)
  1386. return -ENOSYS;
  1387. ret = _lookup_hardreset(oh, name, &ohri);
  1388. if (ret < 0)
  1389. return ret;
  1390. ret = soc_ops.assert_hardreset(oh, &ohri);
  1391. return ret;
  1392. }
  1393. /**
  1394. * _deassert_hardreset - deassert the HW reset line of submodules contained
  1395. * in the hwmod module.
  1396. * @oh: struct omap_hwmod *
  1397. * @name: name of the reset line to look up and deassert
  1398. *
  1399. * Some IP like dsp, ipu or iva contain processor that require an HW
  1400. * reset line to be assert / deassert in order to enable fully the IP.
  1401. * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
  1402. * deasserting the hardreset line on the currently-booted SoC, or passes
  1403. * along the return value from _lookup_hardreset() or the SoC's
  1404. * deassert_hardreset code.
  1405. */
  1406. static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
  1407. {
  1408. struct omap_hwmod_rst_info ohri;
  1409. int ret = -EINVAL;
  1410. int hwsup = 0;
  1411. if (!oh)
  1412. return -EINVAL;
  1413. if (!soc_ops.deassert_hardreset)
  1414. return -ENOSYS;
  1415. ret = _lookup_hardreset(oh, name, &ohri);
  1416. if (IS_ERR_VALUE(ret))
  1417. return ret;
  1418. if (oh->clkdm) {
  1419. /*
  1420. * A clockdomain must be in SW_SUP otherwise reset
  1421. * might not be completed. The clockdomain can be set
  1422. * in HW_AUTO only when the module become ready.
  1423. */
  1424. hwsup = clkdm_in_hwsup(oh->clkdm);
  1425. ret = clkdm_hwmod_enable(oh->clkdm, oh);
  1426. if (ret) {
  1427. WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
  1428. oh->name, oh->clkdm->name, ret);
  1429. return ret;
  1430. }
  1431. }
  1432. _enable_clocks(oh);
  1433. if (soc_ops.enable_module)
  1434. soc_ops.enable_module(oh);
  1435. ret = soc_ops.deassert_hardreset(oh, &ohri);
  1436. if (soc_ops.disable_module)
  1437. soc_ops.disable_module(oh);
  1438. _disable_clocks(oh);
  1439. if (ret == -EBUSY)
  1440. pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
  1441. if (!ret) {
  1442. /*
  1443. * Set the clockdomain to HW_AUTO, assuming that the
  1444. * previous state was HW_AUTO.
  1445. */
  1446. if (oh->clkdm && hwsup)
  1447. clkdm_allow_idle(oh->clkdm);
  1448. } else {
  1449. if (oh->clkdm)
  1450. clkdm_hwmod_disable(oh->clkdm, oh);
  1451. }
  1452. return ret;
  1453. }
  1454. /**
  1455. * _read_hardreset - read the HW reset line state of submodules
  1456. * contained in the hwmod module
  1457. * @oh: struct omap_hwmod *
  1458. * @name: name of the reset line to look up and read
  1459. *
  1460. * Return the state of the reset line. Returns -EINVAL if @oh is
  1461. * null, -ENOSYS if we have no way of reading the hardreset line
  1462. * status on the currently-booted SoC, or passes along the return
  1463. * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
  1464. * code.
  1465. */
  1466. static int _read_hardreset(struct omap_hwmod *oh, const char *name)
  1467. {
  1468. struct omap_hwmod_rst_info ohri;
  1469. int ret = -EINVAL;
  1470. if (!oh)
  1471. return -EINVAL;
  1472. if (!soc_ops.is_hardreset_asserted)
  1473. return -ENOSYS;
  1474. ret = _lookup_hardreset(oh, name, &ohri);
  1475. if (ret < 0)
  1476. return ret;
  1477. return soc_ops.is_hardreset_asserted(oh, &ohri);
  1478. }
  1479. /**
  1480. * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
  1481. * @oh: struct omap_hwmod *
  1482. *
  1483. * If all hardreset lines associated with @oh are asserted, then return true.
  1484. * Otherwise, if part of @oh is out hardreset or if no hardreset lines
  1485. * associated with @oh are asserted, then return false.
  1486. * This function is used to avoid executing some parts of the IP block
  1487. * enable/disable sequence if its hardreset line is set.
  1488. */
  1489. static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
  1490. {
  1491. int i, rst_cnt = 0;
  1492. if (oh->rst_lines_cnt == 0)
  1493. return false;
  1494. for (i = 0; i < oh->rst_lines_cnt; i++)
  1495. if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
  1496. rst_cnt++;
  1497. if (oh->rst_lines_cnt == rst_cnt)
  1498. return true;
  1499. return false;
  1500. }
  1501. /**
  1502. * _are_any_hardreset_lines_asserted - return true if any part of @oh is
  1503. * hard-reset
  1504. * @oh: struct omap_hwmod *
  1505. *
  1506. * If any hardreset lines associated with @oh are asserted, then
  1507. * return true. Otherwise, if no hardreset lines associated with @oh
  1508. * are asserted, or if @oh has no hardreset lines, then return false.
  1509. * This function is used to avoid executing some parts of the IP block
  1510. * enable/disable sequence if any hardreset line is set.
  1511. */
  1512. static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
  1513. {
  1514. int rst_cnt = 0;
  1515. int i;
  1516. for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
  1517. if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
  1518. rst_cnt++;
  1519. return (rst_cnt) ? true : false;
  1520. }
  1521. /**
  1522. * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
  1523. * @oh: struct omap_hwmod *
  1524. *
  1525. * Disable the PRCM module mode related to the hwmod @oh.
  1526. * Return EINVAL if the modulemode is not supported and 0 in case of success.
  1527. */
  1528. static int _omap4_disable_module(struct omap_hwmod *oh)
  1529. {
  1530. int v;
  1531. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  1532. return -EINVAL;
  1533. /*
  1534. * Since integration code might still be doing something, only
  1535. * disable if all lines are under hardreset.
  1536. */
  1537. if (_are_any_hardreset_lines_asserted(oh))
  1538. return 0;
  1539. pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
  1540. omap4_cminst_module_disable(oh->clkdm->prcm_partition,
  1541. oh->clkdm->cm_inst,
  1542. oh->clkdm->clkdm_offs,
  1543. oh->prcm.omap4.clkctrl_offs);
  1544. v = _omap4_wait_target_disable(oh);
  1545. if (v)
  1546. pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
  1547. oh->name);
  1548. return 0;
  1549. }
  1550. /**
  1551. * _am33xx_disable_module - enable CLKCTRL modulemode on AM33XX
  1552. * @oh: struct omap_hwmod *
  1553. *
  1554. * Disable the PRCM module mode related to the hwmod @oh.
  1555. * Return EINVAL if the modulemode is not supported and 0 in case of success.
  1556. */
  1557. static int _am33xx_disable_module(struct omap_hwmod *oh)
  1558. {
  1559. int v;
  1560. if (!oh->clkdm || !oh->prcm.omap4.modulemode)
  1561. return -EINVAL;
  1562. pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
  1563. if (_are_any_hardreset_lines_asserted(oh))
  1564. return 0;
  1565. am33xx_cm_module_disable(oh->clkdm->cm_inst, oh->clkdm->clkdm_offs,
  1566. oh->prcm.omap4.clkctrl_offs);
  1567. v = _am33xx_wait_target_disable(oh);
  1568. if (v)
  1569. pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
  1570. oh->name);
  1571. return 0;
  1572. }
  1573. /**
  1574. * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
  1575. * @oh: struct omap_hwmod *
  1576. *
  1577. * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
  1578. * enabled for this to work. Returns -ENOENT if the hwmod cannot be
  1579. * reset this way, -EINVAL if the hwmod is in the wrong state,
  1580. * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
  1581. *
  1582. * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
  1583. * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
  1584. * use the SYSCONFIG softreset bit to provide the status.
  1585. *
  1586. * Note that some IP like McBSP do have reset control but don't have
  1587. * reset status.
  1588. */
  1589. static int _ocp_softreset(struct omap_hwmod *oh)
  1590. {
  1591. u32 v;
  1592. int c = 0;
  1593. int ret = 0;
  1594. if (!oh->class->sysc ||
  1595. !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
  1596. return -ENOENT;
  1597. /* clocks must be on for this operation */
  1598. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1599. pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n",
  1600. oh->name);
  1601. return -EINVAL;
  1602. }
  1603. /* For some modules, all optionnal clocks need to be enabled as well */
  1604. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1605. _enable_optional_clocks(oh);
  1606. pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
  1607. v = oh->_sysc_cache;
  1608. ret = _set_softreset(oh, &v);
  1609. if (ret)
  1610. goto dis_opt_clks;
  1611. _write_sysconfig(v, oh);
  1612. if (oh->class->sysc->srst_udelay)
  1613. udelay(oh->class->sysc->srst_udelay);
  1614. c = _wait_softreset_complete(oh);
  1615. if (c == MAX_MODULE_SOFTRESET_WAIT)
  1616. pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
  1617. oh->name, MAX_MODULE_SOFTRESET_WAIT);
  1618. else
  1619. pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
  1620. /*
  1621. * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
  1622. * _wait_target_ready() or _reset()
  1623. */
  1624. ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  1625. dis_opt_clks:
  1626. if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
  1627. _disable_optional_clocks(oh);
  1628. return ret;
  1629. }
  1630. /**
  1631. * _reset - reset an omap_hwmod
  1632. * @oh: struct omap_hwmod *
  1633. *
  1634. * Resets an omap_hwmod @oh. If the module has a custom reset
  1635. * function pointer defined, then call it to reset the IP block, and
  1636. * pass along its return value to the caller. Otherwise, if the IP
  1637. * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
  1638. * associated with it, call a function to reset the IP block via that
  1639. * method, and pass along the return value to the caller. Finally, if
  1640. * the IP block has some hardreset lines associated with it, assert
  1641. * all of those, but do _not_ deassert them. (This is because driver
  1642. * authors have expressed an apparent requirement to control the
  1643. * deassertion of the hardreset lines themselves.)
  1644. *
  1645. * The default software reset mechanism for most OMAP IP blocks is
  1646. * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some
  1647. * hwmods cannot be reset via this method. Some are not targets and
  1648. * therefore have no OCP header registers to access. Others (like the
  1649. * IVA) have idiosyncratic reset sequences. So for these relatively
  1650. * rare cases, custom reset code can be supplied in the struct
  1651. * omap_hwmod_class .reset function pointer.
  1652. *
  1653. * _set_dmadisable() is called to set the DMADISABLE bit so that it
  1654. * does not prevent idling of the system. This is necessary for cases
  1655. * where ROMCODE/BOOTLOADER uses dma and transfers control to the
  1656. * kernel without disabling dma.
  1657. *
  1658. * Passes along the return value from either _ocp_softreset() or the
  1659. * custom reset function - these must return -EINVAL if the hwmod
  1660. * cannot be reset this way or if the hwmod is in the wrong state,
  1661. * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
  1662. */
  1663. static int _reset(struct omap_hwmod *oh)
  1664. {
  1665. int i, r;
  1666. pr_debug("omap_hwmod: %s: resetting\n", oh->name);
  1667. if (oh->class->reset) {
  1668. r = oh->class->reset(oh);
  1669. } else {
  1670. if (oh->rst_lines_cnt > 0) {
  1671. for (i = 0; i < oh->rst_lines_cnt; i++)
  1672. _assert_hardreset(oh, oh->rst_lines[i].name);
  1673. return 0;
  1674. } else {
  1675. r = _ocp_softreset(oh);
  1676. if (r == -ENOENT)
  1677. r = 0;
  1678. }
  1679. }
  1680. _set_dmadisable(oh);
  1681. /*
  1682. * OCP_SYSCONFIG bits need to be reprogrammed after a
  1683. * softreset. The _enable() function should be split to avoid
  1684. * the rewrite of the OCP_SYSCONFIG register.
  1685. */
  1686. if (oh->class->sysc) {
  1687. _update_sysc_cache(oh);
  1688. _enable_sysc(oh);
  1689. }
  1690. return r;
  1691. }
  1692. /**
  1693. * _reconfigure_io_chain - clear any I/O chain wakeups and reconfigure chain
  1694. *
  1695. * Call the appropriate PRM function to clear any logged I/O chain
  1696. * wakeups and to reconfigure the chain. This apparently needs to be
  1697. * done upon every mux change. Since hwmods can be concurrently
  1698. * enabled and idled, hold a spinlock around the I/O chain
  1699. * reconfiguration sequence. No return value.
  1700. *
  1701. * XXX When the PRM code is moved to drivers, this function can be removed,
  1702. * as the PRM infrastructure should abstract this.
  1703. */
  1704. static void _reconfigure_io_chain(void)
  1705. {
  1706. unsigned long flags;
  1707. spin_lock_irqsave(&io_chain_lock, flags);
  1708. if (cpu_is_omap34xx() && omap3_has_io_chain_ctrl())
  1709. omap3xxx_prm_reconfigure_io_chain();
  1710. else if (cpu_is_omap44xx())
  1711. omap44xx_prm_reconfigure_io_chain();
  1712. spin_unlock_irqrestore(&io_chain_lock, flags);
  1713. }
  1714. /**
  1715. * _omap4_update_context_lost - increment hwmod context loss counter if
  1716. * hwmod context was lost, and clear hardware context loss reg
  1717. * @oh: hwmod to check for context loss
  1718. *
  1719. * If the PRCM indicates that the hwmod @oh lost context, increment
  1720. * our in-memory context loss counter, and clear the RM_*_CONTEXT
  1721. * bits. No return value.
  1722. */
  1723. static void _omap4_update_context_lost(struct omap_hwmod *oh)
  1724. {
  1725. if (oh->prcm.omap4.flags & HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT)
  1726. return;
  1727. if (!prm_was_any_context_lost_old(oh->clkdm->pwrdm.ptr->prcm_partition,
  1728. oh->clkdm->pwrdm.ptr->prcm_offs,
  1729. oh->prcm.omap4.context_offs))
  1730. return;
  1731. oh->prcm.omap4.context_lost_counter++;
  1732. prm_clear_context_loss_flags_old(oh->clkdm->pwrdm.ptr->prcm_partition,
  1733. oh->clkdm->pwrdm.ptr->prcm_offs,
  1734. oh->prcm.omap4.context_offs);
  1735. }
  1736. /**
  1737. * _omap4_get_context_lost - get context loss counter for a hwmod
  1738. * @oh: hwmod to get context loss counter for
  1739. *
  1740. * Returns the in-memory context loss counter for a hwmod.
  1741. */
  1742. static int _omap4_get_context_lost(struct omap_hwmod *oh)
  1743. {
  1744. return oh->prcm.omap4.context_lost_counter;
  1745. }
  1746. /**
  1747. * _enable - enable an omap_hwmod
  1748. * @oh: struct omap_hwmod *
  1749. *
  1750. * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
  1751. * register target. Returns -EINVAL if the hwmod is in the wrong
  1752. * state or passes along the return value of _wait_target_ready().
  1753. */
  1754. static int _enable(struct omap_hwmod *oh)
  1755. {
  1756. int r;
  1757. int hwsup = 0;
  1758. pr_debug("omap_hwmod: %s: enabling\n", oh->name);
  1759. /*
  1760. * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
  1761. * state at init. Now that someone is really trying to enable
  1762. * them, just ensure that the hwmod mux is set.
  1763. */
  1764. if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
  1765. /*
  1766. * If the caller has mux data populated, do the mux'ing
  1767. * which wouldn't have been done as part of the _enable()
  1768. * done during setup.
  1769. */
  1770. if (oh->mux)
  1771. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1772. oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
  1773. return 0;
  1774. }
  1775. if (oh->_state != _HWMOD_STATE_INITIALIZED &&
  1776. oh->_state != _HWMOD_STATE_IDLE &&
  1777. oh->_state != _HWMOD_STATE_DISABLED) {
  1778. WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
  1779. oh->name);
  1780. return -EINVAL;
  1781. }
  1782. /*
  1783. * If an IP block contains HW reset lines and all of them are
  1784. * asserted, we let integration code associated with that
  1785. * block handle the enable. We've received very little
  1786. * information on what those driver authors need, and until
  1787. * detailed information is provided and the driver code is
  1788. * posted to the public lists, this is probably the best we
  1789. * can do.
  1790. */
  1791. if (_are_all_hardreset_lines_asserted(oh))
  1792. return 0;
  1793. /* Mux pins for device runtime if populated */
  1794. if (oh->mux && (!oh->mux->enabled ||
  1795. ((oh->_state == _HWMOD_STATE_IDLE) &&
  1796. oh->mux->pads_dynamic))) {
  1797. omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
  1798. _reconfigure_io_chain();
  1799. }
  1800. _add_initiator_dep(oh, mpu_oh);
  1801. if (oh->clkdm) {
  1802. /*
  1803. * A clockdomain must be in SW_SUP before enabling
  1804. * completely the module. The clockdomain can be set
  1805. * in HW_AUTO only when the module become ready.
  1806. */
  1807. hwsup = clkdm_in_hwsup(oh->clkdm) &&
  1808. !clkdm_missing_idle_reporting(oh->clkdm);
  1809. r = clkdm_hwmod_enable(oh->clkdm, oh);
  1810. if (r) {
  1811. WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
  1812. oh->name, oh->clkdm->name, r);
  1813. return r;
  1814. }
  1815. }
  1816. _enable_clocks(oh);
  1817. if (soc_ops.enable_module)
  1818. soc_ops.enable_module(oh);
  1819. if (soc_ops.update_context_lost)
  1820. soc_ops.update_context_lost(oh);
  1821. r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
  1822. -EINVAL;
  1823. if (!r) {
  1824. /*
  1825. * Set the clockdomain to HW_AUTO only if the target is ready,
  1826. * assuming that the previous state was HW_AUTO
  1827. */
  1828. if (oh->clkdm && hwsup)
  1829. clkdm_allow_idle(oh->clkdm);
  1830. oh->_state = _HWMOD_STATE_ENABLED;
  1831. /* Access the sysconfig only if the target is ready */
  1832. if (oh->class->sysc) {
  1833. if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
  1834. _update_sysc_cache(oh);
  1835. _enable_sysc(oh);
  1836. }
  1837. } else {
  1838. if (soc_ops.disable_module)
  1839. soc_ops.disable_module(oh);
  1840. _disable_clocks(oh);
  1841. pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
  1842. oh->name, r);
  1843. if (oh->clkdm)
  1844. clkdm_hwmod_disable(oh->clkdm, oh);
  1845. }
  1846. return r;
  1847. }
  1848. /**
  1849. * _idle - idle an omap_hwmod
  1850. * @oh: struct omap_hwmod *
  1851. *
  1852. * Idles an omap_hwmod @oh. This should be called once the hwmod has
  1853. * no further work. Returns -EINVAL if the hwmod is in the wrong
  1854. * state or returns 0.
  1855. */
  1856. static int _idle(struct omap_hwmod *oh)
  1857. {
  1858. pr_debug("omap_hwmod: %s: idling\n", oh->name);
  1859. if (oh->_state != _HWMOD_STATE_ENABLED) {
  1860. WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
  1861. oh->name);
  1862. return -EINVAL;
  1863. }
  1864. if (_are_all_hardreset_lines_asserted(oh))
  1865. return 0;
  1866. if (oh->class->sysc)
  1867. _idle_sysc(oh);
  1868. _del_initiator_dep(oh, mpu_oh);
  1869. if (soc_ops.disable_module)
  1870. soc_ops.disable_module(oh);
  1871. /*
  1872. * The module must be in idle mode before disabling any parents
  1873. * clocks. Otherwise, the parent clock might be disabled before
  1874. * the module transition is done, and thus will prevent the
  1875. * transition to complete properly.
  1876. */
  1877. _disable_clocks(oh);
  1878. if (oh->clkdm)
  1879. clkdm_hwmod_disable(oh->clkdm, oh);
  1880. /* Mux pins for device idle if populated */
  1881. if (oh->mux && oh->mux->pads_dynamic) {
  1882. omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
  1883. _reconfigure_io_chain();
  1884. }
  1885. oh->_state = _HWMOD_STATE_IDLE;
  1886. return 0;
  1887. }
  1888. /**
  1889. * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
  1890. * @oh: struct omap_hwmod *
  1891. * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
  1892. *
  1893. * Sets the IP block's OCP autoidle bit in hardware, and updates our
  1894. * local copy. Intended to be used by drivers that require
  1895. * direct manipulation of the AUTOIDLE bits.
  1896. * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
  1897. * along the return value from _set_module_autoidle().
  1898. *
  1899. * Any users of this function should be scrutinized carefully.
  1900. */
  1901. int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
  1902. {
  1903. u32 v;
  1904. int retval = 0;
  1905. unsigned long flags;
  1906. if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
  1907. return -EINVAL;
  1908. spin_lock_irqsave(&oh->_lock, flags);
  1909. v = oh->_sysc_cache;
  1910. retval = _set_module_autoidle(oh, autoidle, &v);
  1911. if (!retval)
  1912. _write_sysconfig(v, oh);
  1913. spin_unlock_irqrestore(&oh->_lock, flags);
  1914. return retval;
  1915. }
  1916. /**
  1917. * _shutdown - shutdown an omap_hwmod
  1918. * @oh: struct omap_hwmod *
  1919. *
  1920. * Shut down an omap_hwmod @oh. This should be called when the driver
  1921. * used for the hwmod is removed or unloaded or if the driver is not
  1922. * used by the system. Returns -EINVAL if the hwmod is in the wrong
  1923. * state or returns 0.
  1924. */
  1925. static int _shutdown(struct omap_hwmod *oh)
  1926. {
  1927. int ret, i;
  1928. u8 prev_state;
  1929. if (oh->_state != _HWMOD_STATE_IDLE &&
  1930. oh->_state != _HWMOD_STATE_ENABLED) {
  1931. WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
  1932. oh->name);
  1933. return -EINVAL;
  1934. }
  1935. if (_are_all_hardreset_lines_asserted(oh))
  1936. return 0;
  1937. pr_debug("omap_hwmod: %s: disabling\n", oh->name);
  1938. if (oh->class->pre_shutdown) {
  1939. prev_state = oh->_state;
  1940. if (oh->_state == _HWMOD_STATE_IDLE)
  1941. _enable(oh);
  1942. ret = oh->class->pre_shutdown(oh);
  1943. if (ret) {
  1944. if (prev_state == _HWMOD_STATE_IDLE)
  1945. _idle(oh);
  1946. return ret;
  1947. }
  1948. }
  1949. if (oh->class->sysc) {
  1950. if (oh->_state == _HWMOD_STATE_IDLE)
  1951. _enable(oh);
  1952. _shutdown_sysc(oh);
  1953. }
  1954. /* clocks and deps are already disabled in idle */
  1955. if (oh->_state == _HWMOD_STATE_ENABLED) {
  1956. _del_initiator_dep(oh, mpu_oh);
  1957. /* XXX what about the other system initiators here? dma, dsp */
  1958. if (soc_ops.disable_module)
  1959. soc_ops.disable_module(oh);
  1960. _disable_clocks(oh);
  1961. if (oh->clkdm)
  1962. clkdm_hwmod_disable(oh->clkdm, oh);
  1963. }
  1964. /* XXX Should this code also force-disable the optional clocks? */
  1965. for (i = 0; i < oh->rst_lines_cnt; i++)
  1966. _assert_hardreset(oh, oh->rst_lines[i].name);
  1967. /* Mux pins to safe mode or use populated off mode values */
  1968. if (oh->mux)
  1969. omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
  1970. oh->_state = _HWMOD_STATE_DISABLED;
  1971. return 0;
  1972. }
  1973. /**
  1974. * _init_mpu_rt_base - populate the virtual address for a hwmod
  1975. * @oh: struct omap_hwmod * to locate the virtual address
  1976. *
  1977. * Cache the virtual address used by the MPU to access this IP block's
  1978. * registers. This address is needed early so the OCP registers that
  1979. * are part of the device's address space can be ioremapped properly.
  1980. * No return value.
  1981. */
  1982. static void __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data)
  1983. {
  1984. struct omap_hwmod_addr_space *mem;
  1985. void __iomem *va_start;
  1986. if (!oh)
  1987. return;
  1988. _save_mpu_port_index(oh);
  1989. if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
  1990. return;
  1991. mem = _find_mpu_rt_addr_space(oh);
  1992. if (!mem) {
  1993. pr_debug("omap_hwmod: %s: no MPU register target found\n",
  1994. oh->name);
  1995. return;
  1996. }
  1997. va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
  1998. if (!va_start) {
  1999. pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
  2000. return;
  2001. }
  2002. pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
  2003. oh->name, va_start);
  2004. oh->_mpu_rt_va = va_start;
  2005. }
  2006. /**
  2007. * _init - initialize internal data for the hwmod @oh
  2008. * @oh: struct omap_hwmod *
  2009. * @n: (unused)
  2010. *
  2011. * Look up the clocks and the address space used by the MPU to access
  2012. * registers belonging to the hwmod @oh. @oh must already be
  2013. * registered at this point. This is the first of two phases for
  2014. * hwmod initialization. Code called here does not touch any hardware
  2015. * registers, it simply prepares internal data structures. Returns 0
  2016. * upon success or if the hwmod isn't registered, or -EINVAL upon
  2017. * failure.
  2018. */
  2019. static int __init _init(struct omap_hwmod *oh, void *data)
  2020. {
  2021. int r;
  2022. if (oh->_state != _HWMOD_STATE_REGISTERED)
  2023. return 0;
  2024. _init_mpu_rt_base(oh, NULL);
  2025. r = _init_clocks(oh, NULL);
  2026. if (IS_ERR_VALUE(r)) {
  2027. WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
  2028. return -EINVAL;
  2029. }
  2030. oh->_state = _HWMOD_STATE_INITIALIZED;
  2031. return 0;
  2032. }
  2033. /**
  2034. * _setup_iclk_autoidle - configure an IP block's interface clocks
  2035. * @oh: struct omap_hwmod *
  2036. *
  2037. * Set up the module's interface clocks. XXX This function is still mostly
  2038. * a stub; implementing this properly requires iclk autoidle usecounting in
  2039. * the clock code. No return value.
  2040. */
  2041. static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
  2042. {
  2043. struct omap_hwmod_ocp_if *os;
  2044. struct list_head *p;
  2045. int i = 0;
  2046. if (oh->_state != _HWMOD_STATE_INITIALIZED)
  2047. return;
  2048. p = oh->slave_ports.next;
  2049. while (i < oh->slaves_cnt) {
  2050. os = _fetch_next_ocp_if(&p, &i);
  2051. if (!os->_clk)
  2052. continue;
  2053. if (os->flags & OCPIF_SWSUP_IDLE) {
  2054. /* XXX omap_iclk_deny_idle(c); */
  2055. } else {
  2056. /* XXX omap_iclk_allow_idle(c); */
  2057. clk_enable(os->_clk);
  2058. }
  2059. }
  2060. return;
  2061. }
  2062. /**
  2063. * _setup_reset - reset an IP block during the setup process
  2064. * @oh: struct omap_hwmod *