environmentalHumidityAnalysis.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * OMAP2/3/4 clockdomain framework functions
  3. *
  4. * Copyright (C) 2008-2011 Texas Instruments, Inc.
  5. * Copyright (C) 2008-2011 Nokia Corporation
  6. *
  7. * Written by Paul Walmsley and Jouni Högander
  8. * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #undef DEBUG
  15. #include <linux/kernel.h>
  16. #include <linux/device.h>
  17. #include <linux/list.h>
  18. #include <linux/errno.h>
  19. #include <linux/string.h>
  20. #include <linux/delay.h>
  21. #include <linux/clk.h>
  22. #include <linux/limits.h>
  23. #include <linux/err.h>
  24. #include <linux/clk-provider.h>
  25. #include <linux/io.h>
  26. #include <linux/bitops.h>
  27. #include "soc.h"
  28. #include "clock.h"
  29. #include "clockdomain.h"
  30. /* clkdm_list contains all registered struct clockdomains */
  31. static LIST_HEAD(clkdm_list);
  32. /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
  33. static struct clkdm_autodep *autodeps;
  34. static struct clkdm_ops *arch_clkdm;
  35. /* Private functions */
  36. static struct clockdomain *_clkdm_lookup(const char *name)
  37. {
  38. struct clockdomain *clkdm, *temp_clkdm;
  39. if (!name)
  40. return NULL;
  41. clkdm = NULL;
  42. list_for_each_entry(temp_clkdm, &clkdm_list, node) {
  43. if (!strcmp(name, temp_clkdm->name)) {
  44. clkdm = temp_clkdm;
  45. break;
  46. }
  47. }
  48. return clkdm;
  49. }
  50. /**
  51. * _clkdm_register - register a clockdomain
  52. * @clkdm: struct clockdomain * to register
  53. *
  54. * Adds a clockdomain to the internal clockdomain list.
  55. * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
  56. * already registered by the provided name, or 0 upon success.
  57. */
  58. static int _clkdm_register(struct clockdomain *clkdm)
  59. {
  60. struct powerdomain *pwrdm;
  61. if (!clkdm || !clkdm->name)
  62. return -EINVAL;
  63. pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
  64. if (!pwrdm) {
  65. pr_err("clockdomain: %s: powerdomain %s does not exist\n",
  66. clkdm->name, clkdm->pwrdm.name);
  67. return -EINVAL;
  68. }
  69. clkdm->pwrdm.ptr = pwrdm;
  70. /* Verify that the clockdomain is not already registered */
  71. if (_clkdm_lookup(clkdm->name))
  72. return -EEXIST;
  73. list_add(&clkdm->node, &clkdm_list);
  74. pwrdm_add_clkdm(pwrdm, clkdm);
  75. spin_lock_init(&clkdm->lock);
  76. pr_debug("clockdomain: registered %s\n", clkdm->name);
  77. return 0;
  78. }
  79. /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
  80. static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
  81. struct clkdm_dep *deps)
  82. {
  83. struct clkdm_dep *cd;
  84. if (!clkdm || !deps)
  85. return ERR_PTR(-EINVAL);
  86. for (cd = deps; cd->clkdm_name; cd++) {
  87. if (!cd->clkdm && cd->clkdm_name)
  88. cd->clkdm = _clkdm_lookup(cd->clkdm_name);
  89. if (cd->clkdm == clkdm)
  90. break;
  91. }
  92. if (!cd->clkdm_name)
  93. return ERR_PTR(-ENOENT);
  94. return cd;
  95. }
  96. /*
  97. * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
  98. * @autodep: struct clkdm_autodep * to resolve
  99. *
  100. * Resolve autodep clockdomain names to clockdomain pointers via
  101. * clkdm_lookup() and store the pointers in the autodep structure. An
  102. * "autodep" is a clockdomain sleep/wakeup dependency that is
  103. * automatically added and removed whenever clocks in the associated
  104. * clockdomain are enabled or disabled (respectively) when the
  105. * clockdomain is in hardware-supervised mode. Meant to be called
  106. * once at clockdomain layer initialization, since these should remain
  107. * fixed for a particular architecture. No return value.
  108. *
  109. * XXX autodeps are deprecated and should be removed at the earliest
  110. * opportunity
  111. */
  112. static void _autodep_lookup(struct clkdm_autodep *autodep)
  113. {
  114. struct clockdomain *clkdm;
  115. if (!autodep)
  116. return;
  117. clkdm = clkdm_lookup(autodep->clkdm.name);
  118. if (!clkdm) {
  119. pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
  120. autodep->clkdm.name);
  121. clkdm = ERR_PTR(-ENOENT);
  122. }
  123. autodep->clkdm.ptr = clkdm;
  124. }
  125. /*
  126. * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
  127. * @clkdm: struct clockdomain *
  128. *
  129. * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
  130. * in hardware-supervised mode. Meant to be called from clock framework
  131. * when a clock inside clockdomain 'clkdm' is enabled. No return value.
  132. *
  133. * XXX autodeps are deprecated and should be removed at the earliest
  134. * opportunity
  135. */
  136. void _clkdm_add_autodeps(struct clockdomain *clkdm)
  137. {
  138. struct clkdm_autodep *autodep;
  139. if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
  140. return;
  141. for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
  142. if (IS_ERR(autodep->clkdm.ptr))
  143. continue;
  144. pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
  145. clkdm->name, autodep->clkdm.ptr->name);
  146. clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
  147. clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
  148. }
  149. }
  150. /*
  151. * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
  152. * @clkdm: struct clockdomain *
  153. *
  154. * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
  155. * in hardware-supervised mode. Meant to be called from clock framework
  156. * when a clock inside clockdomain 'clkdm' is disabled. No return value.
  157. *
  158. * XXX autodeps are deprecated and should be removed at the earliest
  159. * opportunity
  160. */
  161. void _clkdm_del_autodeps(struct clockdomain *clkdm)
  162. {
  163. struct clkdm_autodep *autodep;
  164. if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
  165. return;
  166. for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
  167. if (IS_ERR(autodep->clkdm.ptr))
  168. continue;
  169. pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
  170. clkdm->name, autodep->clkdm.ptr->name);
  171. clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
  172. clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
  173. }
  174. }
  175. /**
  176. * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
  177. * @clkdm: clockdomain that we are resolving dependencies for
  178. * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
  179. *
  180. * Iterates through @clkdm_deps, looking up the struct clockdomain named by
  181. * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
  182. * No return value.
  183. */
  184. static void _resolve_clkdm_deps(struct clockdomain *clkdm,
  185. struct clkdm_dep *clkdm_deps)
  186. {
  187. struct clkdm_dep *cd;
  188. for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
  189. if (cd->clkdm)
  190. continue;
  191. cd->clkdm = _clkdm_lookup(cd->clkdm_name);
  192. WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
  193. clkdm->name, cd->clkdm_name);
  194. }
  195. }
  196. /* Public functions */
  197. /**
  198. * clkdm_register_platform_funcs - register clockdomain implementation fns
  199. * @co: func pointers for arch specific implementations
  200. *
  201. * Register the list of function pointers used to implement the
  202. * clockdomain functions on different OMAP SoCs. Should be called
  203. * before any other clkdm_register*() function. Returns -EINVAL if
  204. * @co is null, -EEXIST if platform functions have already been
  205. * registered, or 0 upon success.
  206. */
  207. int clkdm_register_platform_funcs(struct clkdm_ops *co)
  208. {
  209. if (!co)
  210. return -EINVAL;
  211. if (arch_clkdm)
  212. return -EEXIST;