omap_device.c 21 KB

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