omap_device.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * omap_device implementation
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Paul Walmsley, Kevin Hilman
  6. *
  7. * Developed in collaboration with (alphabetical order): Benoit
  8. * Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
  9. * Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
  10. * Woodruff
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * This code provides a consistent interface for OMAP device drivers
  17. * to control power management and interconnect properties of their
  18. * devices.
  19. *
  20. * In the medium- to long-term, this code should either be
  21. * a) implemented via arch-specific pointers in platform_data
  22. * or
  23. * b) implemented as a proper omap_bus/omap_device in Linux, no more
  24. * platform_data func pointers
  25. *
  26. *
  27. * Guidelines for usage by driver authors:
  28. *
  29. * 1. These functions are intended to be used by device drivers via
  30. * function pointers in struct platform_data. As an example,
  31. * omap_device_enable() should be passed to the driver as
  32. *
  33. * struct foo_driver_platform_data {
  34. * ...
  35. * int (*device_enable)(struct platform_device *pdev);
  36. * ...
  37. * }
  38. *
  39. * Note that the generic "device_enable" name is used, rather than
  40. * "omap_device_enable". This is so other architectures can pass in their
  41. * own enable/disable functions here.
  42. *
  43. * This should be populated during device setup:
  44. *
  45. * ...
  46. * pdata->device_enable = omap_device_enable;
  47. * ...
  48. *
  49. * 2. Drivers should first check to ensure the function pointer is not null
  50. * before calling it, as in:
  51. *
  52. * if (pdata->device_enable)
  53. * pdata->device_enable(pdev);
  54. *
  55. * This allows other architectures that don't use similar device_enable()/
  56. * device_shutdown() functions to execute normally.
  57. *
  58. * ...
  59. *
  60. * Suggested usage by device drivers:
  61. *
  62. * During device initialization:
  63. * device_enable()
  64. *
  65. * During device idle:
  66. * (save remaining device context if necessary)
  67. * device_idle();
  68. *
  69. * During device resume:
  70. * device_enable();
  71. * (restore context if necessary)
  72. *
  73. * During device shutdown:
  74. * device_shutdown()
  75. * (device must be reinitialized at this point to use it again)
  76. *
  77. */
  78. #undef DEBUG
  79. #include <linux/kernel.h>
  80. #include <linux/platform_device.h>
  81. #include <linux/slab.h>
  82. #include <linux/err.h>
  83. #include <linux/io.h>
  84. #include <plat/omap_device.h>
  85. #include <plat/omap_hwmod.h>
  86. /* These parameters are passed to _omap_device_{de,}activate() */
  87. #define USE_WAKEUP_LAT 0
  88. #define IGNORE_WAKEUP_LAT 1
  89. #define OMAP_DEVICE_MAGIC 0xf00dcafe
  90. /* Private functions */
  91. /**
  92. * _omap_device_activate - increase device readiness
  93. * @od: struct omap_device *
  94. * @ignore_lat: increase to latency target (0) or full readiness (1)?
  95. *
  96. * Increase readiness of omap_device @od (thus decreasing device
  97. * wakeup latency, but consuming more power). If @ignore_lat is
  98. * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
  99. * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
  100. * latency is greater than the requested maximum wakeup latency, step
  101. * backwards in the omap_device_pm_latency table to ensure the
  102. * device's maximum wakeup latency is less than or equal to the
  103. * requested maximum wakeup latency. Returns 0.
  104. */
  105. static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
  106. {
  107. struct timespec a, b, c;
  108. pr_debug("omap_device: %s: activating\n", od->pdev.name);
  109. while (od->pm_lat_level > 0) {
  110. struct omap_device_pm_latency *odpl;
  111. unsigned long long act_lat = 0;
  112. od->pm_lat_level--;
  113. odpl = od->pm_lats + od->pm_lat_level;
  114. if (!ignore_lat &&
  115. (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
  116. break;
  117. read_persistent_clock(&a);
  118. /* XXX check return code */
  119. odpl->activate_func(od);
  120. read_persistent_clock(&b);
  121. c = timespec_sub(b, a);
  122. act_lat = timespec_to_ns(&c);
  123. pr_debug("omap_device: %s: pm_lat %d: activate: elapsed time "
  124. "%llu nsec\n", od->pdev.name, od->pm_lat_level,
  125. act_lat);
  126. if (act_lat > odpl->activate_lat) {
  127. odpl->activate_lat_worst = act_lat;
  128. if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
  129. odpl->activate_lat = act_lat;
  130. pr_warning("omap_device: %s.%d: new worst case "
  131. "activate latency %d: %llu\n",
  132. od->pdev.name, od->pdev.id,
  133. od->pm_lat_level, act_lat);
  134. } else
  135. pr_warning("omap_device: %s.%d: activate "
  136. "latency %d higher than exptected. "
  137. "(%llu > %d)\n",
  138. od->pdev.name, od->pdev.id,
  139. od->pm_lat_level, act_lat,
  140. odpl->activate_lat);
  141. }
  142. od->dev_wakeup_lat -= odpl->activate_lat;
  143. }
  144. return 0;
  145. }
  146. /**
  147. * _omap_device_deactivate - decrease device readiness
  148. * @od: struct omap_device *
  149. * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
  150. *
  151. * Decrease readiness of omap_device @od (thus increasing device
  152. * wakeup latency, but conserving power). If @ignore_lat is
  153. * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
  154. * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
  155. * latency is less than the requested maximum wakeup latency, step
  156. * forwards in the omap_device_pm_latency table to ensure the device's
  157. * maximum wakeup latency is less than or equal to the requested
  158. * maximum wakeup latency. Returns 0.
  159. */
  160. static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
  161. {
  162. struct timespec a, b, c;
  163. pr_debug("omap_device: %s: deactivating\n", od->pdev.name);
  164. while (od->pm_lat_level < od->pm_lats_cnt) {
  165. struct omap_device_pm_latency *odpl;
  166. unsigned long long deact_lat = 0;
  167. odpl = od->pm_lats + od->pm_lat_level;
  168. if (!ignore_lat &&
  169. ((od->dev_wakeup_lat + odpl->activate_lat) >
  170. od->_dev_wakeup_lat_limit))
  171. break;
  172. read_persistent_clock(&a);
  173. /* XXX check return code */
  174. odpl->deactivate_func(od);
  175. read_persistent_clock(&b);
  176. c = timespec_sub(b, a);
  177. deact_lat = timespec_to_ns(&c);
  178. pr_debug("omap_device: %s: pm_lat %d: deactivate: elapsed time "
  179. "%llu nsec\n", od->pdev.name, od->pm_lat_level,
  180. deact_lat);
  181. if (deact_lat > odpl->deactivate_lat) {
  182. odpl->deactivate_lat_worst = deact_lat;
  183. if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
  184. odpl->deactivate_lat = deact_lat;
  185. pr_warning("omap_device: %s.%d: new worst case "
  186. "deactivate latency %d: %llu\n",
  187. od->pdev.name, od->pdev.id,
  188. od->pm_lat_level, deact_lat);
  189. } else
  190. pr_warning("omap_device: %s.%d: deactivate "
  191. "latency %d higher than exptected. "
  192. "(%llu > %d)\n",
  193. od->pdev.name, od->pdev.id,
  194. od->pm_lat_level, deact_lat,
  195. odpl->deactivate_lat);
  196. }
  197. od->dev_wakeup_lat += odpl->activate_lat;
  198. od->pm_lat_level++;
  199. }
  200. return 0;
  201. }
  202. static inline struct omap_device *_find_by_pdev(struct platform_device *pdev)
  203. {
  204. return container_of(pdev, struct omap_device, pdev);
  205. }
  206. /* Public functions for use by core code */
  207. /**
  208. * omap_device_count_resources - count number of struct resource entries needed
  209. * @od: struct omap_device *
  210. *
  211. * Count the number of struct resource entries needed for this
  212. * omap_device @od. Used by omap_device_build_ss() to determine how
  213. * much memory to allocate before calling
  214. * omap_device_fill_resources(). Returns the count.
  215. */
  216. int omap_device_count_resources(struct omap_device *od)
  217. {
  218. struct omap_hwmod *oh;
  219. int c = 0;
  220. int i;
  221. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
  222. c += omap_hwmod_count_resources(oh);
  223. pr_debug("omap_device: %s: counted %d total resources across %d "
  224. "hwmods\n", od->pdev.name, c, od->hwmods_cnt);
  225. return c;
  226. }
  227. /**
  228. * omap_device_fill_resources - fill in array of struct resource
  229. * @od: struct omap_device *
  230. * @res: pointer to an array of struct resource to be filled in
  231. *
  232. * Populate one or more empty struct resource pointed to by @res with
  233. * the resource data for this omap_device @od. Used by
  234. * omap_device_build_ss() after calling omap_device_count_resources().
  235. * Ideally this function would not be needed at all. If omap_device
  236. * replaces platform_device, then we can specify our own
  237. * get_resource()/ get_irq()/etc functions that use the underlying
  238. * omap_hwmod information. Or if platform_device is extended to use
  239. * subarchitecture-specific function pointers, the various
  240. * platform_device functions can simply call omap_device internal
  241. * functions to get device resources. Hacking around the existing
  242. * platform_device code wastes memory. Returns 0.
  243. */
  244. int omap_device_fill_resources(struct omap_device *od, struct resource *res)
  245. {
  246. struct omap_hwmod *oh;
  247. int c = 0;
  248. int i, r;
  249. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++) {
  250. r = omap_hwmod_fill_resources(oh, res);
  251. res += r;
  252. c += r;
  253. }
  254. return 0;
  255. }
  256. /**
  257. * omap_device_build - build and register an omap_device with one omap_hwmod
  258. * @pdev_name: name of the platform_device driver to use
  259. * @pdev_id: this platform_device's connection ID
  260. * @oh: ptr to the single omap_hwmod that backs this omap_device
  261. * @pdata: platform_data ptr to associate with the platform_device
  262. * @pdata_len: amount of memory pointed to by @pdata
  263. * @pm_lats: pointer to a omap_device_pm_latency array for this device
  264. * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
  265. * @is_early_device: should the device be registered as an early device or not
  266. *
  267. * Convenience function for building and registering a single
  268. * omap_device record, which in turn builds and registers a
  269. * platform_device record. See omap_device_build_ss() for more
  270. * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
  271. * passes along the return value of omap_device_build_ss().
  272. */
  273. struct omap_device *omap_device_build(const char *pdev_name, int pdev_id,
  274. struct omap_hwmod *oh, void *pdata,
  275. int pdata_len,
  276. struct omap_device_pm_latency *pm_lats,
  277. int pm_lats_cnt, int is_early_device)
  278. {
  279. struct omap_hwmod *ohs[] = { oh };
  280. if (!oh)
  281. return ERR_PTR(-EINVAL);
  282. return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
  283. pdata_len, pm_lats, pm_lats_cnt,
  284. is_early_device);
  285. }
  286. /**
  287. * omap_device_build_ss - build and register an omap_device with multiple hwmods
  288. * @pdev_name: name of the platform_device driver to use
  289. * @pdev_id: this platform_device's connection ID
  290. * @oh: ptr to the single omap_hwmod that backs this omap_device
  291. * @pdata: platform_data ptr to associate with the platform_device
  292. * @pdata_len: amount of memory pointed to by @pdata
  293. * @pm_lats: pointer to a omap_device_pm_latency array for this device
  294. * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
  295. * @is_early_device: should the device be registered as an early device or not
  296. *
  297. * Convenience function for building and registering an omap_device
  298. * subsystem record. Subsystem records consist of multiple
  299. * omap_hwmods. This function in turn builds and registers a
  300. * platform_device record. Returns an ERR_PTR() on error, or passes
  301. * along the return value of omap_device_register().
  302. */
  303. struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
  304. struct omap_hwmod **ohs, int oh_cnt,
  305. void *pdata, int pdata_len,
  306. struct omap_device_pm_latency *pm_lats,
  307. int pm_lats_cnt, int is_early_device)
  308. {
  309. int ret = -ENOMEM;
  310. struct omap_device *od;
  311. char *pdev_name2;
  312. struct resource *res = NULL;
  313. int i, res_count;
  314. struct omap_hwmod **hwmods;
  315. if (!ohs || oh_cnt == 0 || !pdev_name)
  316. return ERR_PTR(-EINVAL);
  317. if (!pdata && pdata_len > 0)
  318. return ERR_PTR(-EINVAL);
  319. pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name,
  320. oh_cnt);
  321. od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
  322. if (!od)
  323. return ERR_PTR(-ENOMEM);
  324. od->hwmods_cnt = oh_cnt;
  325. hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt,
  326. GFP_KERNEL);
  327. if (!hwmods)
  328. goto odbs_exit1;
  329. memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt);
  330. od->hwmods = hwmods;
  331. pdev_name2 = kzalloc(strlen(pdev_name) + 1, GFP_KERNEL);
  332. if (!pdev_name2)
  333. goto odbs_exit2;
  334. strcpy(pdev_name2, pdev_name);
  335. od->pdev.name = pdev_name2;
  336. od->pdev.id = pdev_id;
  337. res_count = omap_device_count_resources(od);
  338. if (res_count > 0) {
  339. res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
  340. if (!res)
  341. goto odbs_exit3;
  342. }
  343. omap_device_fill_resources(od, res);
  344. od->pdev.num_resources = res_count;
  345. od->pdev.resource = res;
  346. platform_device_add_data(&od->pdev, pdata, pdata_len);
  347. od->pm_lats = pm_lats;
  348. od->pm_lats_cnt = pm_lats_cnt;
  349. od->magic = OMAP_DEVICE_MAGIC;
  350. if (is_early_device)
  351. ret = omap_early_device_register(od);
  352. else
  353. ret = omap_device_register(od);
  354. for (i = 0; i < oh_cnt; i++)
  355. hwmods[i]->od = od;
  356. if (ret)
  357. goto odbs_exit4;
  358. return od;
  359. odbs_exit4:
  360. kfree(res);
  361. odbs_exit3:
  362. kfree(pdev_name2);
  363. odbs_exit2:
  364. kfree(hwmods);
  365. odbs_exit1:
  366. kfree(od);
  367. pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
  368. return ERR_PTR(ret);
  369. }
  370. /**
  371. * omap_early_device_register - register an omap_device as an early platform
  372. * device.
  373. * @od: struct omap_device * to register
  374. *
  375. * Register the omap_device structure. This currently just calls
  376. * platform_early_add_device() on the underlying platform_device.
  377. * Returns 0 by default.
  378. */
  379. int omap_early_device_register(struct omap_device *od)
  380. {
  381. struct platform_device *devices[1];
  382. devices[0] = &(od->pdev);
  383. early_platform_add_devices(devices, 1);
  384. return 0;
  385. }
  386. /**
  387. * omap_device_register - register an omap_device with one omap_hwmod
  388. * @od: struct omap_device * to register
  389. *
  390. * Register the omap_device structure. This currently just calls
  391. * platform_device_register() on the underlying platform_device.
  392. * Returns the return value of platform_device_register().
  393. */
  394. int omap_device_register(struct omap_device *od)
  395. {
  396. pr_debug("omap_device: %s: registering\n", od->pdev.name);
  397. return platform_device_register(&od->pdev);
  398. }
  399. /* Public functions for use by device drivers through struct platform_data */
  400. /**
  401. * omap_device_enable - fully activate an omap_device
  402. * @od: struct omap_device * to activate
  403. *
  404. * Do whatever is necessary for the hwmods underlying omap_device @od
  405. * to be accessible and ready to operate. This generally involves
  406. * enabling clocks, setting SYSCONFIG registers; and in the future may
  407. * involve remuxing pins. Device drivers should call this function
  408. * (through platform_data function pointers) where they would normally
  409. * enable clocks, etc. Returns -EINVAL if called when the omap_device
  410. * is already enabled, or passes along the return value of
  411. * _omap_device_activate().
  412. */
  413. int omap_device_enable(struct platform_device *pdev)
  414. {
  415. int ret;
  416. struct omap_device *od;
  417. od = _find_by_pdev(pdev);
  418. if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
  419. WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n",
  420. od->pdev.name, od->pdev.id, __func__, od->_state);
  421. return -EINVAL;
  422. }
  423. /* Enable everything if we're enabling this device from scratch */
  424. if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
  425. od->pm_lat_level = od->pm_lats_cnt;
  426. ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
  427. od->dev_wakeup_lat = 0;
  428. od->_dev_wakeup_lat_limit = UINT_MAX;
  429. od->_state = OMAP_DEVICE_STATE_ENABLED;
  430. return ret;
  431. }
  432. /**
  433. * omap_device_idle - idle an omap_device
  434. * @od: struct omap_device * to idle
  435. *
  436. * Idle omap_device @od by calling as many .deactivate_func() entries
  437. * in the omap_device's pm_lats table as is possible without exceeding
  438. * the device's maximum wakeup latency limit, pm_lat_limit. Device
  439. * drivers should call this function (through platform_data function
  440. * pointers) where they would normally disable clocks after operations
  441. * complete, etc.. Returns -EINVAL if the omap_device is not
  442. * currently enabled, or passes along the return value of
  443. * _omap_device_deactivate().
  444. */
  445. int omap_device_idle(struct platform_device *pdev)
  446. {
  447. int ret;
  448. struct omap_device *od;
  449. od = _find_by_pdev(pdev);
  450. if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
  451. WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n",
  452. od->pdev.name, od->pdev.id, __func__, od->_state);
  453. return -EINVAL;
  454. }
  455. ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
  456. od->_state = OMAP_DEVICE_STATE_IDLE;
  457. return ret;
  458. }
  459. /**
  460. * omap_device_shutdown - shut down an omap_device
  461. * @od: struct omap_device * to shut down
  462. *
  463. * Shut down omap_device @od by calling all .deactivate_func() entries
  464. * in the omap_device's pm_lats table and then shutting down all of
  465. * the underlying omap_hwmods. Used when a device is being "removed"
  466. * or a device driver is being unloaded. Returns -EINVAL if the
  467. * omap_device is not currently enabled or idle, or passes along the
  468. * return value of _omap_device_deactivate().
  469. */
  470. int omap_device_shutdown(struct platform_device *pdev)
  471. {
  472. int ret, i;
  473. struct omap_device *od;
  474. struct omap_hwmod *oh;
  475. od = _find_by_pdev(pdev);
  476. if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
  477. od->_state != OMAP_DEVICE_STATE_IDLE) {
  478. WARN(1, "omap_device: %s.%d: %s() called from invalid state %d\n",
  479. od->pdev.name, od->pdev.id, __func__, od->_state);
  480. return -EINVAL;
  481. }
  482. ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
  483. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
  484. omap_hwmod_shutdown(oh);
  485. od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
  486. return ret;
  487. }
  488. /**
  489. * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
  490. * @od: struct omap_device *
  491. *
  492. * When a device's maximum wakeup latency limit changes, call some of
  493. * the .activate_func or .deactivate_func function pointers in the
  494. * omap_device's pm_lats array to ensure that the device's maximum
  495. * wakeup latency is less than or equal to the new latency limit.
  496. * Intended to be called by OMAP PM code whenever a device's maximum
  497. * wakeup latency limit changes (e.g., via
  498. * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
  499. * done (e.g., if the omap_device is not currently idle, or if the
  500. * wakeup latency is already current with the new limit) or passes
  501. * along the return value of _omap_device_deactivate() or
  502. * _omap_device_activate().
  503. */
  504. int omap_device_align_pm_lat(struct platform_device *pdev,
  505. u32 new_wakeup_lat_limit)
  506. {
  507. int ret = -EINVAL;
  508. struct omap_device *od;
  509. od = _find_by_pdev(pdev);
  510. if (new_wakeup_lat_limit == od->dev_wakeup_lat)
  511. return 0;
  512. od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
  513. if (od->_state != OMAP_DEVICE_STATE_IDLE)
  514. return 0;
  515. else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
  516. ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
  517. else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
  518. ret = _omap_device_activate(od, USE_WAKEUP_LAT);
  519. return ret;
  520. }
  521. /**
  522. * omap_device_is_valid - Check if pointer is a valid omap_device
  523. * @od: struct omap_device *
  524. *
  525. * Return whether struct omap_device pointer @od points to a valid
  526. * omap_device.
  527. */
  528. bool omap_device_is_valid(struct omap_device *od)
  529. {
  530. return (od && od->magic == OMAP_DEVICE_MAGIC);
  531. }
  532. /**
  533. * omap_device_get_pwrdm - return the powerdomain * associated with @od
  534. * @od: struct omap_device *
  535. *
  536. * Return the powerdomain associated with the first underlying
  537. * omap_hwmod for this omap_device. Intended for use by core OMAP PM
  538. * code. Returns NULL on error or a struct powerdomain * upon
  539. * success.
  540. */
  541. struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
  542. {
  543. /*
  544. * XXX Assumes that all omap_hwmod powerdomains are identical.
  545. * This may not necessarily be true. There should be a sanity
  546. * check in here to WARN() if any difference appears.
  547. */
  548. if (!od->hwmods_cnt)
  549. return NULL;
  550. return omap_hwmod_get_pwrdm(od->hwmods[0]);
  551. }
  552. /**
  553. * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
  554. * @od: struct omap_device *
  555. *
  556. * Return the MPU's virtual address for the base of the hwmod, from
  557. * the ioremap() that the hwmod code does. Only valid if there is one
  558. * hwmod associated with this device. Returns NULL if there are zero
  559. * or more than one hwmods associated with this omap_device;
  560. * otherwise, passes along the return value from
  561. * omap_hwmod_get_mpu_rt_va().
  562. */
  563. void __iomem *omap_device_get_rt_va(struct omap_device *od)
  564. {
  565. if (od->hwmods_cnt != 1)
  566. return NULL;
  567. return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
  568. }
  569. /*
  570. * Public functions intended for use in omap_device_pm_latency
  571. * .activate_func and .deactivate_func function pointers
  572. */
  573. /**
  574. * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
  575. * @od: struct omap_device *od
  576. *
  577. * Enable all underlying hwmods. Returns 0.
  578. */
  579. int omap_device_enable_hwmods(struct omap_device *od)
  580. {
  581. struct omap_hwmod *oh;
  582. int i;
  583. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
  584. omap_hwmod_enable(oh);
  585. /* XXX pass along return value here? */
  586. return 0;
  587. }
  588. /**
  589. * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
  590. * @od: struct omap_device *od
  591. *
  592. * Idle all underlying hwmods. Returns 0.
  593. */
  594. int omap_device_idle_hwmods(struct omap_device *od)
  595. {
  596. struct omap_hwmod *oh;
  597. int i;
  598. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
  599. omap_hwmod_idle(oh);
  600. /* XXX pass along return value here? */
  601. return 0;
  602. }
  603. /**
  604. * omap_device_disable_clocks - disable all main and interface clocks
  605. * @od: struct omap_device *od
  606. *
  607. * Disable the main functional clock and interface clock for all of the
  608. * omap_hwmods associated with the omap_device. Returns 0.
  609. */
  610. int omap_device_disable_clocks(struct omap_device *od)
  611. {
  612. struct omap_hwmod *oh;
  613. int i;
  614. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
  615. omap_hwmod_disable_clocks(oh);
  616. /* XXX pass along return value here? */
  617. return 0;
  618. }
  619. /**
  620. * omap_device_enable_clocks - enable all main and interface clocks
  621. * @od: struct omap_device *od
  622. *
  623. * Enable the main functional clock and interface clock for all of the
  624. * omap_hwmods associated with the omap_device. Returns 0.
  625. */
  626. int omap_device_enable_clocks(struct omap_device *od)
  627. {
  628. struct omap_hwmod *oh;
  629. int i;
  630. for (i = 0, oh = *od->hwmods; i < od->hwmods_cnt; i++, oh++)
  631. omap_hwmod_enable_clocks(oh);
  632. /* XXX pass along return value here? */
  633. return 0;
  634. }