omap_device.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * omap_device implementation
  3. *
  4. * Copyright (C) 2009-2010 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/export.h>
  81. #include <linux/platform_device.h>
  82. #include <linux/slab.h>
  83. #include <linux/err.h>
  84. #include <linux/io.h>
  85. #include <linux/clk.h>
  86. #include <linux/clkdev.h>
  87. #include <linux/pm_runtime.h>
  88. #include <linux/of.h>
  89. #include <linux/notifier.h>
  90. #include "omap_device.h"
  91. #include "omap_hwmod.h"
  92. /* These parameters are passed to _omap_device_{de,}activate() */
  93. #define USE_WAKEUP_LAT 0
  94. #define IGNORE_WAKEUP_LAT 1
  95. static int omap_early_device_register(struct platform_device *pdev);
  96. static struct omap_device_pm_latency omap_default_latency[] = {
  97. {
  98. .deactivate_func = omap_device_idle_hwmods,
  99. .activate_func = omap_device_enable_hwmods,
  100. .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
  101. }
  102. };
  103. /* Private functions */
  104. /**
  105. * _omap_device_activate - increase device readiness
  106. * @od: struct omap_device *
  107. * @ignore_lat: increase to latency target (0) or full readiness (1)?
  108. *
  109. * Increase readiness of omap_device @od (thus decreasing device
  110. * wakeup latency, but consuming more power). If @ignore_lat is
  111. * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
  112. * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
  113. * latency is greater than the requested maximum wakeup latency, step
  114. * backwards in the omap_device_pm_latency table to ensure the
  115. * device's maximum wakeup latency is less than or equal to the
  116. * requested maximum wakeup latency. Returns 0.
  117. */
  118. static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
  119. {
  120. struct timespec a, b, c;
  121. dev_dbg(&od->pdev->dev, "omap_device: activating\n");
  122. while (od->pm_lat_level > 0) {
  123. struct omap_device_pm_latency *odpl;
  124. unsigned long long act_lat = 0;
  125. od->pm_lat_level--;
  126. odpl = od->pm_lats + od->pm_lat_level;
  127. if (!ignore_lat &&
  128. (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
  129. break;
  130. read_persistent_clock(&a);
  131. /* XXX check return code */
  132. odpl->activate_func(od);
  133. read_persistent_clock(&b);
  134. c = timespec_sub(b, a);
  135. act_lat = timespec_to_ns(&c);
  136. dev_dbg(&od->pdev->dev,
  137. "omap_device: pm_lat %d: activate: elapsed time %llu nsec\n",
  138. od->pm_lat_level, act_lat);
  139. if (act_lat > odpl->activate_lat) {
  140. odpl->activate_lat_worst = act_lat;
  141. if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
  142. odpl->activate_lat = act_lat;
  143. dev_dbg(&od->pdev->dev,
  144. "new worst case activate latency %d: %llu\n",
  145. od->pm_lat_level, act_lat);
  146. } else
  147. dev_warn(&od->pdev->dev,
  148. "activate latency %d higher than expected. (%llu > %d)\n",
  149. od->pm_lat_level, act_lat,
  150. odpl->activate_lat);
  151. }
  152. od->dev_wakeup_lat -= odpl->activate_lat;
  153. }
  154. return 0;
  155. }
  156. /**
  157. * _omap_device_deactivate - decrease device readiness
  158. * @od: struct omap_device *
  159. * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
  160. *
  161. * Decrease readiness of omap_device @od (thus increasing device
  162. * wakeup latency, but conserving power). If @ignore_lat is
  163. * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
  164. * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
  165. * latency is less than the requested maximum wakeup latency, step
  166. * forwards in the omap_device_pm_latency table to ensure the device's
  167. * maximum wakeup latency is less than or equal to the requested
  168. * maximum wakeup latency. Returns 0.
  169. */
  170. static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
  171. {
  172. struct timespec a, b, c;
  173. dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
  174. while (od->pm_lat_level < od->pm_lats_cnt) {
  175. struct omap_device_pm_latency *odpl;
  176. unsigned long long deact_lat = 0;
  177. odpl = od->pm_lats + od->pm_lat_level;
  178. if (!ignore_lat &&
  179. ((od->dev_wakeup_lat + odpl->activate_lat) >
  180. od->_dev_wakeup_lat_limit))
  181. break;
  182. read_persistent_clock(&a);
  183. /* XXX check return code */
  184. odpl->deactivate_func(od);
  185. read_persistent_clock(&b);
  186. c = timespec_sub(b, a);
  187. deact_lat = timespec_to_ns(&c);
  188. dev_dbg(&od->pdev->dev,
  189. "omap_device: pm_lat %d: deactivate: elapsed time %llu nsec\n",
  190. od->pm_lat_level, deact_lat);
  191. if (deact_lat > odpl->deactivate_lat) {
  192. odpl->deactivate_lat_worst = deact_lat;
  193. if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
  194. odpl->deactivate_lat = deact_lat;
  195. dev_dbg(&od->pdev->dev,
  196. "new worst case deactivate latency %d: %llu\n",
  197. od->pm_lat_level, deact_lat);
  198. } else
  199. dev_warn(&od->pdev->dev,
  200. "deactivate latency %d higher than expected. (%llu > %d)\n",
  201. od->pm_lat_level, deact_lat,
  202. odpl->deactivate_lat);
  203. }
  204. od->dev_wakeup_lat += odpl->activate_lat;
  205. od->pm_lat_level++;
  206. }
  207. return 0;
  208. }
  209. static void _add_clkdev(struct omap_device *od, const char *clk_alias,
  210. const char *clk_name)
  211. {
  212. struct clk *r;
  213. struct clk_lookup *l;
  214. if (!clk_alias || !clk_name)
  215. return;
  216. dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
  217. r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
  218. if (!IS_ERR(r)) {
  219. dev_warn(&od->pdev->dev,
  220. "alias %s already exists\n", clk_alias);
  221. clk_put(r);
  222. return;
  223. }
  224. r = clk_get(NULL, clk_name);
  225. if (IS_ERR(r)) {
  226. dev_err(&od->pdev->dev,
  227. "clk_get for %s failed\n", clk_name);
  228. return;
  229. }
  230. l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
  231. if (!l) {
  232. dev_err(&od->pdev->dev,
  233. "clkdev_alloc for %s failed\n", clk_alias);
  234. return;
  235. }
  236. clkdev_add(l);
  237. }
  238. /**
  239. * _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
  240. * and main clock
  241. * @od: struct omap_device *od
  242. * @oh: struct omap_hwmod *oh
  243. *
  244. * For the main clock and every optional clock present per hwmod per
  245. * omap_device, this function adds an entry in the clkdev table of the
  246. * form <dev-id=dev_name, con-id=role> if it does not exist already.
  247. *
  248. * The function is called from inside omap_device_build_ss(), after
  249. * omap_device_register.
  250. *
  251. * This allows drivers to get a pointer to its optional clocks based on its role
  252. * by calling clk_get(<dev*>, <role>).
  253. * In the case of the main clock, a "fck" alias is used.
  254. *
  255. * No return value.
  256. */
  257. static void _add_hwmod_clocks_clkdev(struct omap_device *od,
  258. struct omap_hwmod *oh)
  259. {
  260. int i;
  261. _add_clkdev(od, "fck", oh->main_clk);
  262. for (i = 0; i < oh->opt_clks_cnt; i++)
  263. _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
  264. }
  265. /**
  266. * omap_device_build_from_dt - build an omap_device with multiple hwmods
  267. * @pdev_name: name of the platform_device driver to use
  268. * @pdev_id: this platform_device's connection ID
  269. * @oh: ptr to the single omap_hwmod that backs this omap_device
  270. * @pdata: platform_data ptr to associate with the platform_device
  271. * @pdata_len: amount of memory pointed to by @pdata
  272. * @pm_lats: pointer to a omap_device_pm_latency array for this device
  273. * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
  274. * @is_early_device: should the device be registered as an early device or not
  275. *
  276. * Function for building an omap_device already registered from device-tree
  277. *
  278. * Returns 0 or PTR_ERR() on error.
  279. */
  280. static int omap_device_build_from_dt(struct platform_device *pdev)
  281. {
  282. struct omap_hwmod **hwmods;
  283. struct omap_device *od;
  284. struct omap_hwmod *oh;
  285. struct device_node *node = pdev->dev.of_node;
  286. const char *oh_name;
  287. int oh_cnt, i, ret = 0;
  288. oh_cnt = of_property_count_strings(node, "ti,hwmods");
  289. if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) {
  290. dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
  291. return -ENODEV;
  292. }
  293. hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
  294. if (!hwmods) {
  295. ret = -ENOMEM;
  296. goto odbfd_exit;
  297. }
  298. for (i = 0; i < oh_cnt; i++) {
  299. of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
  300. oh = omap_hwmod_lookup(oh_name);
  301. if (!oh) {
  302. dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
  303. oh_name);
  304. ret = -EINVAL;
  305. goto odbfd_exit1;
  306. }
  307. hwmods[i] = oh;
  308. }
  309. od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0);
  310. if (!od) {
  311. dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
  312. oh_name);
  313. ret = PTR_ERR(od);
  314. goto odbfd_exit1;
  315. }
  316. /* Fix up missing resource names */
  317. for (i = 0; i < pdev->num_resources; i++) {
  318. struct resource *r = &pdev->resource[i];
  319. if (r->name == NULL)
  320. r->name = dev_name(&pdev->dev);
  321. }
  322. if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
  323. omap_device_disable_idle_on_suspend(pdev);
  324. pdev->dev.pm_domain = &omap_device_pm_domain;
  325. odbfd_exit1:
  326. kfree(hwmods);
  327. odbfd_exit:
  328. return ret;
  329. }
  330. static int _omap_device_notifier_call(struct notifier_block *nb,
  331. unsigned long event, void *dev)
  332. {
  333. struct platform_device *pdev = to_platform_device(dev);
  334. struct omap_device *od;
  335. switch (event) {
  336. case BUS_NOTIFY_DEL_DEVICE:
  337. if (pdev->archdata.od)
  338. omap_device_delete(pdev->archdata.od);
  339. break;
  340. case BUS_NOTIFY_ADD_DEVICE:
  341. if (pdev->dev.of_node)
  342. omap_device_build_from_dt(pdev);
  343. /* fall through */
  344. default:
  345. od = to_omap_device(pdev);
  346. if (od)
  347. od->_driver_status = event;
  348. }
  349. return NOTIFY_DONE;
  350. }
  351. /* Public functions for use by core code */
  352. /**
  353. * omap_device_get_context_loss_count - get lost context count
  354. * @od: struct omap_device *
  355. *
  356. * Using the primary hwmod, query the context loss count for this
  357. * device.
  358. *
  359. * Callers should consider context for this device lost any time this
  360. * function returns a value different than the value the caller got
  361. * the last time it called this function.
  362. *
  363. * If any hwmods exist for the omap_device assoiated with @pdev,
  364. * return the context loss counter for that hwmod, otherwise return
  365. * zero.
  366. */
  367. int omap_device_get_context_loss_count(struct platform_device *pdev)
  368. {
  369. struct omap_device *od;
  370. u32 ret = 0;
  371. od = to_omap_device(pdev);
  372. if (od->hwmods_cnt)
  373. ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
  374. return ret;
  375. }
  376. /**
  377. * omap_device_count_resources - count number of struct resource entries needed
  378. * @od: struct omap_device *
  379. * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
  380. *
  381. * Count the number of struct resource entries needed for this
  382. * omap_device @od. Used by omap_device_build_ss() to determine how
  383. * much memory to allocate before calling
  384. * omap_device_fill_resources(). Returns the count.
  385. */
  386. static int omap_device_count_resources(struct omap_device *od,
  387. unsigned long flags)
  388. {
  389. int c = 0;
  390. int i;
  391. for (i = 0; i < od->hwmods_cnt; i++)
  392. c += omap_hwmod_count_resources(od->hwmods[i], flags);
  393. pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
  394. od->pdev->name, c, od->hwmods_cnt);
  395. return c;
  396. }
  397. /**
  398. * omap_device_fill_resources - fill in array of struct resource
  399. * @od: struct omap_device *
  400. * @res: pointer to an array of struct resource to be filled in
  401. *
  402. * Populate one or more empty struct resource pointed to by @res with
  403. * the resource data for this omap_device @od. Used by
  404. * omap_device_build_ss() after calling omap_device_count_resources().
  405. * Ideally this function would not be needed at all. If omap_device
  406. * replaces platform_device, then we can specify our own
  407. * get_resource()/ get_irq()/etc functions that use the underlying
  408. * omap_hwmod information. Or if platform_device is extended to use
  409. * subarchitecture-specific function pointers, the various
  410. * platform_device functions can simply call omap_device internal
  411. * functions to get device resources. Hacking around the existing
  412. * platform_device code wastes memory. Returns 0.
  413. */
  414. static int omap_device_fill_resources(struct omap_device *od,
  415. struct resource *res)
  416. {
  417. int i, r;
  418. for (i = 0; i < od->hwmods_cnt; i++) {
  419. r = omap_hwmod_fill_resources(od->hwmods[i], res);
  420. res += r;
  421. }
  422. return 0;
  423. }
  424. /**
  425. * _od_fill_dma_resources - fill in array of struct resource with dma resources
  426. * @od: struct omap_device *
  427. * @res: pointer to an array of struct resource to be filled in
  428. *
  429. * Populate one or more empty struct resource pointed to by @res with
  430. * the dma resource data for this omap_device @od. Used by
  431. * omap_device_alloc() after calling omap_device_count_resources().
  432. *
  433. * Ideally this function would not be needed at all. If we have
  434. * mechanism to get dma resources from DT.
  435. *
  436. * Returns 0.
  437. */
  438. static int _od_fill_dma_resources(struct omap_device *od,
  439. struct resource *res)
  440. {
  441. int i, r;
  442. for (i = 0; i < od->hwmods_cnt; i++) {
  443. r = omap_hwmod_fill_dma_resources(od->hwmods[i], res);
  444. res += r;
  445. }
  446. return 0;
  447. }
  448. /**
  449. * omap_device_alloc - allocate an omap_device
  450. * @pdev: platform_device that will be included in this omap_device
  451. * @oh: ptr to the single omap_hwmod that backs this omap_device
  452. * @pdata: platform_data ptr to associate with the platform_device
  453. * @pdata_len: amount of memory pointed to by @pdata
  454. * @pm_lats: pointer to a omap_device_pm_latency array for this device
  455. * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
  456. *
  457. * Convenience function for allocating an omap_device structure and filling
  458. * hwmods, resources and pm_latency attributes.
  459. *
  460. * Returns an struct omap_device pointer or ERR_PTR() on error;
  461. */
  462. struct omap_device *omap_device_alloc(struct platform_device *pdev,
  463. struct omap_hwmod **ohs, int oh_cnt,
  464. struct omap_device_pm_latency *pm_lats,
  465. int pm_lats_cnt)
  466. {
  467. int ret = -ENOMEM;
  468. struct omap_device *od;
  469. struct resource *res = NULL;
  470. int i, res_count;
  471. struct omap_hwmod **hwmods;
  472. od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
  473. if (!od) {
  474. ret = -ENOMEM;
  475. goto oda_exit1;
  476. }
  477. od->hwmods_cnt = oh_cnt;
  478. hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
  479. if (!hwmods)
  480. goto oda_exit2;
  481. od->hwmods = hwmods;
  482. od->pdev = pdev;
  483. /*
  484. * Non-DT Boot:
  485. * Here, pdev->num_resources = 0, and we should get all the
  486. * resources from hwmod.
  487. *
  488. * DT Boot:
  489. * OF framework will construct the resource structure (currently
  490. * does for MEM & IRQ resource) and we should respect/use these
  491. * resources, killing hwmod dependency.
  492. * If pdev->num_resources > 0, we assume that MEM & IRQ resources
  493. * have been allocated by OF layer already (through DTB).
  494. * As preparation for the future we examine the OF provided resources
  495. * to see if we have DMA resources provided already. In this case
  496. * there is no need to update the resources for the device, we use the
  497. * OF provided ones.
  498. *
  499. * TODO: Once DMA resource is available from OF layer, we should
  500. * kill filling any resources from hwmod.
  501. */
  502. if (!pdev->num_resources) {
  503. /* Count all resources for the device */
  504. res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
  505. IORESOURCE_DMA |
  506. IORESOURCE_MEM);
  507. } else {
  508. /* Take a look if we already have DMA resource via DT */
  509. for (i = 0; i < pdev->num_resources; i++) {
  510. struct resource *r = &pdev->resource[i];
  511. /* We have it, no need to touch the resources */
  512. if (r->flags == IORESOURCE_DMA)
  513. goto have_everything;
  514. }
  515. /* Count only DMA resources for the device */
  516. res_count = omap_device_count_resources(od, IORESOURCE_DMA);
  517. /* The device has no DMA resource, no need for update */
  518. if (!res_count)
  519. goto have_everything;
  520. res_count += pdev->num_resources;
  521. }
  522. /* Allocate resources memory to account for new resources */
  523. res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
  524. if (!res)
  525. goto oda_exit3;
  526. if (!pdev->num_resources) {
  527. dev_dbg(&pdev->dev, "%s: using %d resources from hwmod\n",
  528. __func__, res_count);
  529. omap_device_fill_resources(od, res);
  530. } else {
  531. dev_dbg(&pdev->dev,
  532. "%s: appending %d DMA resources from hwmod\n",
  533. __func__, res_count - pdev->num_resources);
  534. memcpy(res, pdev->resource,
  535. sizeof(struct resource) * pdev->num_resources);
  536. _od_fill_dma_resources(od, &res[pdev->num_resources]);
  537. }
  538. ret = platform_device_add_resources(pdev, res, res_count);
  539. kfree(res);
  540. if (ret)
  541. goto oda_exit3;
  542. have_everything:
  543. if (!pm_lats) {
  544. pm_lats = omap_default_latency;
  545. pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
  546. }
  547. od->pm_lats_cnt = pm_lats_cnt;
  548. od->pm_lats = kmemdup(pm_lats,
  549. sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
  550. GFP_KERNEL);
  551. if (!od->pm_lats)
  552. goto oda_exit3;
  553. pdev->archdata.od = od;
  554. for (i = 0; i < oh_cnt; i++) {
  555. hwmods[i]->od = od;
  556. _add_hwmod_clocks_clkdev(od, hwmods[i]);
  557. }
  558. return od;
  559. oda_exit3:
  560. kfree(hwmods);
  561. oda_exit2:
  562. kfree(od);
  563. oda_exit1:
  564. dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
  565. return ERR_PTR(ret);
  566. }
  567. void omap_device_delete(struct omap_device *od)
  568. {
  569. if (!od)
  570. return;
  571. od->pdev->archdata.od = NULL;
  572. kfree(od->pm_lats);
  573. kfree(od->hwmods);
  574. kfree(od);
  575. }
  576. /**
  577. * omap_device_build - build and register an omap_device with one omap_hwmod
  578. * @pdev_name: name of the platform_device driver to use
  579. * @pdev_id: this platform_device's connection ID
  580. * @oh: ptr to the single omap_hwmod that backs this omap_device
  581. * @pdata: platform_data ptr to associate with the platform_device
  582. * @pdata_len: amount of memory pointed to by @pdata
  583. * @pm_lats: pointer to a omap_device_pm_latency array for this device
  584. * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
  585. * @is_early_device: should the device be registered as an early device or not
  586. *
  587. * Convenience function for building and registering a single
  588. * omap_device record, which in turn builds and registers a
  589. * platform_device record. See omap_device_build_ss() for more
  590. * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
  591. * passes along the return value of omap_device_build_ss().
  592. */
  593. struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
  594. struct omap_hwmod *oh, void *pdata,
  595. int pdata_len,
  596. struct omap_device_pm_latency *pm_lats,
  597. int pm_lats_cnt, int is_early_device)
  598. {
  599. struct omap_hwmod *ohs[] = { oh };
  600. if (!oh)
  601. return ERR_PTR(-EINVAL);
  602. return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
  603. pdata_len, pm_lats, pm_lats_cnt,
  604. is_early_device);
  605. }
  606. /**
  607. * omap_device_build_ss - build and register an omap_device with multiple hwmods
  608. * @pdev_name: name of the platform_device driver to use
  609. * @pdev_id: this platform_device's connection ID
  610. * @oh: ptr to the single omap_hwmod that backs this omap_device
  611. * @pdata: platform_data ptr to associate with the platform_device
  612. * @pdata_len: amount of memory pointed to by @pdata
  613. * @pm_lats: pointer to a omap_device_pm_latency array for this device
  614. * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
  615. * @is_early_device: should the device be registered as an early device or not
  616. *
  617. * Convenience function for building and registering an omap_device
  618. * subsystem record. Subsystem records consist of multiple
  619. * omap_hwmods. This function in turn builds and registers a
  620. * platform_device record. Returns an ERR_PTR() on error, or passes
  621. * along the return value of omap_device_register().
  622. */
  623. struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
  624. struct omap_hwmod **ohs, int oh_cnt,
  625. void *pdata, int pdata_len,
  626. struct omap_device_pm_latency *pm_lats,
  627. int pm_lats_cnt, int is_early_device)
  628. {
  629. int ret = -ENOMEM;
  630. struct platform_device *pdev;
  631. struct omap_device *od;
  632. if (!ohs || oh_cnt == 0 || !pdev_name)
  633. return ERR_PTR(-EINVAL);
  634. if (!pdata && pdata_len > 0)
  635. return ERR_PTR(-EINVAL);
  636. pdev = platform_device_alloc(pdev_name, pdev_id);
  637. if (!pdev) {
  638. ret = -ENOMEM;
  639. goto odbs_exit;
  640. }
  641. /* Set the dev_name early to allow dev_xxx in omap_device_alloc */
  642. if (pdev->id != -1)
  643. dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
  644. else
  645. dev_set_name(&pdev->dev, "%s", pdev->name);
  646. od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
  647. if (IS_ERR(od))
  648. goto odbs_exit1;
  649. ret = platform_device_add_data(pdev, pdata, pdata_len);
  650. if (ret)
  651. goto odbs_exit2;
  652. if (is_early_device)
  653. ret = omap_early_device_register(pdev);
  654. else
  655. ret = omap_device_register(pdev);
  656. if (ret)
  657. goto odbs_exit2;
  658. return pdev;
  659. odbs_exit2:
  660. omap_device_delete(od);
  661. odbs_exit1:
  662. platform_device_put(pdev);
  663. odbs_exit:
  664. pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
  665. return ERR_PTR(ret);
  666. }
  667. /**
  668. * omap_early_device_register - register an omap_device as an early platform
  669. * device.
  670. * @od: struct omap_device * to register
  671. *
  672. * Register the omap_device structure. This currently just calls
  673. * platform_early_add_device() on the underlying platform_device.
  674. * Returns 0 by default.
  675. */
  676. static int __init omap_early_device_register(struct platform_device *pdev)
  677. {
  678. struct platform_device *devices[1];
  679. devices[0] = pdev;
  680. early_platform_add_devices(devices, 1);
  681. return 0;
  682. }
  683. #ifdef CONFIG_PM_RUNTIME
  684. static int _od_runtime_suspend(struct device *dev)
  685. {
  686. struct platform_device *pdev = to_platform_device(dev);
  687. int ret;
  688. ret = pm_generic_runtime_suspend(dev);
  689. if (!ret)
  690. omap_device_idle(pdev);
  691. return ret;
  692. }
  693. static int _od_runtime_idle(struct device *dev)
  694. {
  695. return pm_generic_runtime_idle(dev);
  696. }
  697. static int _od_runtime_resume(struct device *dev)
  698. {
  699. struct platform_device *pdev = to_platform_device(dev);
  700. omap_device_enable(pdev);
  701. return pm_generic_runtime_resume(dev);
  702. }
  703. #endif
  704. #ifdef CONFIG_SUSPEND
  705. static int _od_suspend_noirq(struct device *dev)
  706. {
  707. struct platform_device *pdev = to_platform_device(dev);
  708. struct omap_device *od = to_omap_device(pdev);
  709. int ret;
  710. /* Don't attempt late suspend on a driver that is not bound */
  711. if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER)
  712. return 0;
  713. ret = pm_generic_suspend_noirq(dev);
  714. if (!ret && !pm_runtime_status_suspended(dev)) {
  715. if (pm_generic_runtime_suspend(dev) == 0) {
  716. if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND))
  717. omap_device_idle(pdev);
  718. od->flags |= OMAP_DEVICE_SUSPENDED;
  719. }
  720. }
  721. return ret;
  722. }
  723. static int _od_resume_noirq(struct device *dev)
  724. {
  725. struct platform_device *pdev = to_platform_device(dev);
  726. struct omap_device *od = to_omap_device(pdev);
  727. if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
  728. !pm_runtime_status_suspended(dev)) {
  729. od->flags &= ~OMAP_DEVICE_SUSPENDED;
  730. if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND))
  731. omap_device_enable(pdev);
  732. pm_generic_runtime_resume(dev);
  733. }
  734. return pm_generic_resume_noirq(dev);
  735. }
  736. #else
  737. #define _od_suspend_noirq NULL
  738. #define _od_resume_noirq NULL
  739. #endif
  740. struct dev_pm_domain omap_device_pm_domain = {
  741. .ops = {
  742. SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
  743. _od_runtime_idle)
  744. USE_PLATFORM_PM_SLEEP_OPS
  745. .suspend_noirq = _od_suspend_noirq,
  746. .resume_noirq = _od_resume_noirq,
  747. }
  748. };
  749. /**
  750. * omap_device_register - register an omap_device with one omap_hwmod
  751. * @od: struct omap_device * to register
  752. *
  753. * Register the omap_device structure. This currently just calls
  754. * platform_device_register() on the underlying platform_device.
  755. * Returns the return value of platform_device_register().
  756. */
  757. int omap_device_register(struct platform_device *pdev)
  758. {
  759. pr_debug("omap_device: %s: registering\n", pdev->name);
  760. pdev->dev.pm_domain = &omap_device_pm_domain;
  761. return platform_device_add(pdev);
  762. }
  763. /* Public functions for use by device drivers through struct platform_data */
  764. /**
  765. * omap_device_enable - fully activate an omap_device
  766. * @od: struct omap_device * to activate
  767. *
  768. * Do whatever is necessary for the hwmods underlying omap_device @od
  769. * to be accessible and ready to operate. This generally involves
  770. * enabling clocks, setting SYSCONFIG registers; and in the future may
  771. * involve remuxing pins. Device drivers should call this function
  772. * (through platform_data function pointers) where they would normally
  773. * enable clocks, etc. Returns -EINVAL if called when the omap_device
  774. * is already enabled, or passes along the return value of
  775. * _omap_device_activate().
  776. */
  777. int omap_device_enable(struct platform_device *pdev)
  778. {
  779. int ret;
  780. struct omap_device *od;
  781. od = to_omap_device(pdev);
  782. if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
  783. dev_warn(&pdev->dev,
  784. "omap_device: %s() called from invalid state %d\n",
  785. __func__, od->_state);
  786. return -EINVAL;
  787. }
  788. /* Enable everything if we're enabling this device from scratch */
  789. if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
  790. od->pm_lat_level = od->pm_lats_cnt;
  791. ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
  792. od->dev_wakeup_lat = 0;
  793. od->_dev_wakeup_lat_limit = UINT_MAX;
  794. od->_state = OMAP_DEVICE_STATE_ENABLED;
  795. return ret;
  796. }
  797. /**
  798. * omap_device_idle - idle an omap_device
  799. * @od: struct omap_device * to idle
  800. *
  801. * Idle omap_device @od by calling as many .deactivate_func() entries
  802. * in the omap_device's pm_lats table as is possible without exceeding
  803. * the device's maximum wakeup latency limit, pm_lat_limit. Device
  804. * drivers should call this function (through platform_data function
  805. * pointers) where they would normally disable clocks after operations
  806. * complete, etc.. Returns -EINVAL if the omap_device is not
  807. * currently enabled, or passes along the return value of
  808. * _omap_device_deactivate().
  809. */
  810. int omap_device_idle(struct platform_device *pdev)
  811. {
  812. int ret;
  813. struct omap_device *od;
  814. od = to_omap_device(pdev);
  815. if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
  816. dev_warn(&pdev->dev,
  817. "omap_device: %s() called from invalid state %d\n",
  818. __func__, od->_state);
  819. return -EINVAL;
  820. }
  821. ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
  822. od->_state = OMAP_DEVICE_STATE_IDLE;
  823. return ret;
  824. }
  825. /**
  826. * omap_device_shutdown - shut down an omap_device
  827. * @od: struct omap_device * to shut down
  828. *
  829. * Shut down omap_device @od by calling all .deactivate_func() entries
  830. * in the omap_device's pm_lats table and then shutting down all of
  831. * the underlying omap_hwmods. Used when a device is being "removed"
  832. * or a device driver is being unloaded. Returns -EINVAL if the
  833. * omap_device is not currently enabled or idle, or passes along the
  834. * return value of _omap_device_deactivate().
  835. */
  836. int omap_device_shutdown(struct platform_device *pdev)
  837. {
  838. int ret, i;
  839. struct omap_device *od;
  840. od = to_omap_device(pdev);
  841. if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
  842. od->_state != OMAP_DEVICE_STATE_IDLE) {
  843. dev_warn(&pdev->dev,
  844. "omap_device: %s() called from invalid state %d\n",
  845. __func__, od->_state);
  846. return -EINVAL;
  847. }
  848. ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
  849. for (i = 0; i < od->hwmods_cnt; i++)
  850. omap_hwmod_shutdown(od->hwmods[i]);
  851. od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
  852. return ret;
  853. }
  854. /**
  855. * omap_device_assert_hardreset - set a device's hardreset line
  856. * @pdev: struct platform_device * to reset
  857. * @name: const char * name of the reset line
  858. *
  859. * Set the hardreset line identified by @name on the IP blocks
  860. * associated with the hwmods backing the platform_device @pdev. All
  861. * of the hwmods associated with @pdev must have the same hardreset
  862. * line linked to them for this to work. Passes along the return value
  863. * of omap_hwmod_assert_hardreset() in the event of any failure, or
  864. * returns 0 upon success.
  865. */
  866. int omap_device_assert_hardreset(struct platform_device *pdev, const char *name)
  867. {
  868. struct omap_device *od = to_omap_device(pdev);
  869. int ret = 0;
  870. int i;
  871. for (i = 0; i < od->hwmods_cnt; i++) {
  872. ret = omap_hwmod_assert_hardreset(od->hwmods[i], name);
  873. if (ret)
  874. break;
  875. }
  876. return ret;
  877. }
  878. /**
  879. * omap_device_deassert_hardreset - release a device's hardreset line
  880. * @pdev: struct platform_device * to reset
  881. * @name: const char * name of the reset line
  882. *
  883. * Release the hardreset line identified by @name on the IP blocks
  884. * associated with the hwmods backing the platform_device @pdev. All
  885. * of the hwmods associated with @pdev must have the same hardreset
  886. * line linked to them for this to work. Passes along the return
  887. * value of omap_hwmod_deassert_hardreset() in the event of any
  888. * failure, or returns 0 upon success.
  889. */
  890. int omap_device_deassert_hardreset(struct platform_device *pdev,
  891. const char *name)
  892. {
  893. struct omap_device *od = to_omap_device(pdev);
  894. int ret = 0;
  895. int i;
  896. for (i = 0; i < od->hwmods_cnt; i++) {
  897. ret = omap_hwmod_deassert_hardreset(od->hwmods[i], name);
  898. if (ret)
  899. break;
  900. }
  901. return ret;
  902. }
  903. /**
  904. * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
  905. * @od: struct omap_device *
  906. *
  907. * When a device's maximum wakeup latency limit changes, call some of
  908. * the .activate_func or .deactivate_func function pointers in the
  909. * omap_device's pm_lats array to ensure that the device's maximum
  910. * wakeup latency is less than or equal to the new latency limit.
  911. * Intended to be called by OMAP PM code whenever a device's maximum
  912. * wakeup latency limit changes (e.g., via
  913. * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
  914. * done (e.g., if the omap_device is not currently idle, or if the
  915. * wakeup latency is already current with the new limit) or passes
  916. * along the return value of _omap_device_deactivate() or
  917. * _omap_device_activate().
  918. */
  919. int omap_device_align_pm_lat(struct platform_device *pdev,
  920. u32 new_wakeup_lat_limit)
  921. {
  922. int ret = -EINVAL;
  923. struct omap_device *od;
  924. od = to_omap_device(pdev);
  925. if (new_wakeup_lat_limit == od->dev_wakeup_lat)
  926. return 0;
  927. od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
  928. if (od->_state != OMAP_DEVICE_STATE_IDLE)
  929. return 0;
  930. else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
  931. ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
  932. else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
  933. ret = _omap_device_activate(od, USE_WAKEUP_LAT);
  934. return ret;
  935. }
  936. /**
  937. * omap_device_get_pwrdm - return the powerdomain * associated with @od
  938. * @od: struct omap_device *
  939. *
  940. * Return the powerdomain associated with the first underlying
  941. * omap_hwmod for this omap_device. Intended for use by core OMAP PM
  942. * code. Returns NULL on error or a struct powerdomain * upon
  943. * success.
  944. */
  945. struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
  946. {
  947. /*
  948. * XXX Assumes that all omap_hwmod powerdomains are identical.
  949. * This may not necessarily be true. There should be a sanity
  950. * check in here to WARN() if any difference appears.
  951. */
  952. if (!od->hwmods_cnt)
  953. return NULL;
  954. return omap_hwmod_get_pwrdm(od->hwmods[0]);
  955. }
  956. /**
  957. * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
  958. * @od: struct omap_device *
  959. *
  960. * Return the MPU's virtual address for the base of the hwmod, from
  961. * the ioremap() that the hwmod code does. Only valid if there is one
  962. * hwmod associated with this device. Returns NULL if there are zero
  963. * or more than one hwmods associated with this omap_device;
  964. * otherwise, passes along the return value from
  965. * omap_hwmod_get_mpu_rt_va().
  966. */
  967. void __iomem *omap_device_get_rt_va(struct omap_device *od)
  968. {
  969. if (od->hwmods_cnt != 1)
  970. return NULL;
  971. return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
  972. }
  973. /**
  974. * omap_device_get_by_hwmod_name() - convert a hwmod name to
  975. * device pointer.
  976. * @oh_name: name of the hwmod device
  977. *
  978. * Returns back a struct device * pointer associated with a hwmod
  979. * device represented by a hwmod_name
  980. */
  981. struct device *omap_device_get_by_hwmod_name(const char *oh_name)
  982. {
  983. struct omap_hwmod *oh;
  984. if (!oh_name) {
  985. WARN(1, "%s: no hwmod name!\n", __func__);
  986. return ERR_PTR(-EINVAL);
  987. }
  988. oh = omap_hwmod_lookup(oh_name);
  989. if (IS_ERR_OR_NULL(oh)) {
  990. WARN(1, "%s: no hwmod for %s\n", __func__,
  991. oh_name);
  992. return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
  993. }
  994. if (IS_ERR_OR_NULL(oh->od)) {
  995. WARN(1, "%s: no omap_device for %s\n", __func__,
  996. oh_name);
  997. return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
  998. }
  999. if (IS_ERR_OR_NULL(oh->od->pdev))
  1000. return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
  1001. return &oh->od->pdev->dev;
  1002. }
  1003. EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
  1004. /*
  1005. * Public functions intended for use in omap_device_pm_latency
  1006. * .activate_func and .deactivate_func function pointers
  1007. */
  1008. /**
  1009. * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
  1010. * @od: struct omap_device *od
  1011. *
  1012. * Enable all underlying hwmods. Returns 0.
  1013. */
  1014. int omap_device_enable_hwmods(struct omap_device *od)
  1015. {
  1016. int i;
  1017. for (i = 0; i < od->hwmods_cnt; i++)
  1018. omap_hwmod_enable(od->hwmods[i]);
  1019. /* XXX pass along return value here? */
  1020. return 0;
  1021. }
  1022. /**
  1023. * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
  1024. * @od: struct omap_device *od
  1025. *
  1026. * Idle all underlying hwmods. Returns 0.
  1027. */
  1028. int omap_device_idle_hwmods(struct omap_device *od)
  1029. {
  1030. int i;
  1031. for (i = 0; i < od->hwmods_cnt; i++)
  1032. omap_hwmod_idle(od->hwmods[i]);
  1033. /* XXX pass along return value here? */
  1034. return 0;
  1035. }
  1036. /**
  1037. * omap_device_disable_clocks - disable all main and interface clocks
  1038. * @od: struct omap_device *od
  1039. *
  1040. * Disable the main functional clock and interface clock for all of the
  1041. * omap_hwmods associated with the omap_device. Returns 0.
  1042. */
  1043. int omap_device_disable_clocks(struct omap_device *od)
  1044. {
  1045. int i;
  1046. for (i = 0; i < od->hwmods_cnt; i++)
  1047. omap_hwmod_disable_clocks(od->hwmods[i]);
  1048. /* XXX pass along return value here? */
  1049. return 0;
  1050. }
  1051. /**
  1052. * omap_device_enable_clocks - enable all main and interface clocks
  1053. * @od: struct omap_device *od
  1054. *
  1055. * Enable the main functional clock and interface clock for all of the
  1056. * omap_hwmods associated with the omap_device. Returns 0.
  1057. */
  1058. int omap_device_enable_clocks(struct omap_device *od)
  1059. {
  1060. int i;
  1061. for (i = 0; i < od->hwmods_cnt; i++)
  1062. omap_hwmod_enable_clocks(od->hwmods[i]);
  1063. /* XXX pass along return value here? */
  1064. return 0;
  1065. }
  1066. static struct notifier_block platform_nb = {
  1067. .notifier_call = _omap_device_notifier_call,
  1068. };
  1069. static int __init omap_device_init(void)
  1070. {
  1071. bus_register_notifier(&platform_bus_type, &platform_nb);
  1072. return 0;
  1073. }
  1074. core_initcall(omap_device_init);
  1075. /**
  1076. * omap_device_late_idle - idle devices without drivers
  1077. * @dev: struct device * associated with omap_device
  1078. * @data: unused
  1079. *
  1080. * Check the driver bound status of this device, and idle it
  1081. * if there is no driver attached.
  1082. */
  1083. static int __init omap_device_late_idle(struct device *dev, void *data)
  1084. {
  1085. struct platform_device *pdev = to_platform_device(dev);
  1086. struct omap_device *od = to_omap_device(pdev);
  1087. if (!od)
  1088. return 0;
  1089. /*
  1090. * If omap_device state is enabled, but has no driver bound,
  1091. * idle it.
  1092. */
  1093. if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER) {
  1094. if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
  1095. dev_warn(dev, "%s: enabled but no driver. Idling\n",
  1096. __func__);
  1097. omap_device_idle(pdev);
  1098. }
  1099. }
  1100. return 0;
  1101. }
  1102. static int __init omap_device_late_init(void)
  1103. {
  1104. bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
  1105. return 0;
  1106. }
  1107. late_initcall(omap_device_late_init);