connectTheSignalSlot.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. */