omap_device.c 36 KB

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