devfreq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * devfreq: Generic Dynamic Voltage and Frequency Scaling (DVFS) Framework
  3. * for Non-CPU Devices.
  4. *
  5. * Copyright (C) 2011 Samsung Electronics
  6. * MyungJoo Ham <myungjoo.ham@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/errno.h>
  15. #include <linux/err.h>
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  19. #include <linux/stat.h>
  20. #include <linux/opp.h>
  21. #include <linux/devfreq.h>
  22. #include <linux/workqueue.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/list.h>
  25. #include <linux/printk.h>
  26. #include <linux/hrtimer.h>
  27. #include "governor.h"
  28. struct class *devfreq_class;
  29. /*
  30. * devfreq core provides delayed work based load monitoring helper
  31. * functions. Governors can use these or can implement their own
  32. * monitoring mechanism.
  33. */
  34. static struct workqueue_struct *devfreq_wq;
  35. /* The list of all device-devfreq */
  36. static LIST_HEAD(devfreq_list);
  37. static DEFINE_MUTEX(devfreq_list_lock);
  38. /**
  39. * find_device_devfreq() - find devfreq struct using device pointer
  40. * @dev: device pointer used to lookup device devfreq.
  41. *
  42. * Search the list of device devfreqs and return the matched device's
  43. * devfreq info. devfreq_list_lock should be held by the caller.
  44. */
  45. static struct devfreq *find_device_devfreq(struct device *dev)
  46. {
  47. struct devfreq *tmp_devfreq;
  48. if (unlikely(IS_ERR_OR_NULL(dev))) {
  49. pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
  50. return ERR_PTR(-EINVAL);
  51. }
  52. WARN(!mutex_is_locked(&devfreq_list_lock),
  53. "devfreq_list_lock must be locked.");
  54. list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
  55. if (tmp_devfreq->dev.parent == dev)
  56. return tmp_devfreq;
  57. }
  58. return ERR_PTR(-ENODEV);
  59. }
  60. /* Load monitoring helper functions for governors use */
  61. /**
  62. * update_devfreq() - Reevaluate the device and configure frequency.
  63. * @devfreq: the devfreq instance.
  64. *
  65. * Note: Lock devfreq->lock before calling update_devfreq
  66. * This function is exported for governors.
  67. */
  68. int update_devfreq(struct devfreq *devfreq)
  69. {
  70. unsigned long freq;
  71. int err = 0;
  72. u32 flags = 0;
  73. if (!mutex_is_locked(&devfreq->lock)) {
  74. WARN(true, "devfreq->lock must be locked by the caller.\n");
  75. return -EINVAL;
  76. }
  77. /* Reevaluate the proper frequency */
  78. err = devfreq->governor->get_target_freq(devfreq, &freq);
  79. if (err)
  80. return err;
  81. /*
  82. * Adjust the freuqency with user freq and QoS.
  83. *
  84. * List from the highest proiority
  85. * max_freq (probably called by thermal when it's too hot)
  86. * min_freq
  87. */
  88. if (devfreq->min_freq && freq < devfreq->min_freq) {
  89. freq = devfreq->min_freq;
  90. flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */
  91. }
  92. if (devfreq->max_freq && freq > devfreq->max_freq) {
  93. freq = devfreq->max_freq;
  94. flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
  95. }
  96. err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
  97. if (err)
  98. return err;
  99. devfreq->previous_freq = freq;
  100. return err;
  101. }
  102. /**
  103. * devfreq_monitor() - Periodically poll devfreq objects.
  104. * @work: the work struct used to run devfreq_monitor periodically.
  105. *
  106. */
  107. static void devfreq_monitor(struct work_struct *work)
  108. {
  109. int err;
  110. struct devfreq *devfreq = container_of(work,
  111. struct devfreq, work.work);
  112. mutex_lock(&devfreq->lock);
  113. err = update_devfreq(devfreq);
  114. if (err)
  115. dev_err(&devfreq->dev, "dvfs failed with (%d) error\n", err);
  116. queue_delayed_work(devfreq_wq, &devfreq->work,
  117. msecs_to_jiffies(devfreq->profile->polling_ms));
  118. mutex_unlock(&devfreq->lock);
  119. }
  120. /**
  121. * devfreq_monitor_start() - Start load monitoring of devfreq instance
  122. * @devfreq: the devfreq instance.
  123. *
  124. * Helper function for starting devfreq device load monitoing. By
  125. * default delayed work based monitoring is supported. Function
  126. * to be called from governor in response to DEVFREQ_GOV_START
  127. * event when device is added to devfreq framework.
  128. */
  129. void devfreq_monitor_start(struct devfreq *devfreq)
  130. {
  131. INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor);
  132. if (devfreq->profile->polling_ms)
  133. queue_delayed_work(devfreq_wq, &devfreq->work,
  134. msecs_to_jiffies(devfreq->profile->polling_ms));
  135. }
  136. /**
  137. * devfreq_monitor_stop() - Stop load monitoring of a devfreq instance
  138. * @devfreq: the devfreq instance.
  139. *
  140. * Helper function to stop devfreq device load monitoing. Function
  141. * to be called from governor in response to DEVFREQ_GOV_STOP
  142. * event when device is removed from devfreq framework.
  143. */
  144. void devfreq_monitor_stop(struct devfreq *devfreq)
  145. {
  146. cancel_delayed_work_sync(&devfreq->work);
  147. }
  148. /**
  149. * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance
  150. * @devfreq: the devfreq instance.
  151. *
  152. * Helper function to suspend devfreq device load monitoing. Function
  153. * to be called from governor in response to DEVFREQ_GOV_SUSPEND
  154. * event or when polling interval is set to zero.
  155. *
  156. * Note: Though this function is same as devfreq_monitor_stop(),
  157. * intentionally kept separate to provide hooks for collecting
  158. * transition statistics.
  159. */
  160. void devfreq_monitor_suspend(struct devfreq *devfreq)
  161. {
  162. mutex_lock(&devfreq->lock);
  163. if (devfreq->stop_polling) {
  164. mutex_unlock(&devfreq->lock);
  165. return;
  166. }
  167. devfreq->stop_polling = true;
  168. mutex_unlock(&devfreq->lock);
  169. cancel_delayed_work_sync(&devfreq->work);
  170. }
  171. /**
  172. * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance
  173. * @devfreq: the devfreq instance.
  174. *
  175. * Helper function to resume devfreq device load monitoing. Function
  176. * to be called from governor in response to DEVFREQ_GOV_RESUME
  177. * event or when polling interval is set to non-zero.
  178. */
  179. void devfreq_monitor_resume(struct devfreq *devfreq)
  180. {
  181. mutex_lock(&devfreq->lock);
  182. if (!devfreq->stop_polling)
  183. goto out;
  184. if (!delayed_work_pending(&devfreq->work) &&
  185. devfreq->profile->polling_ms)
  186. queue_delayed_work(devfreq_wq, &devfreq->work,
  187. msecs_to_jiffies(devfreq->profile->polling_ms));
  188. devfreq->stop_polling = false;
  189. out:
  190. mutex_unlock(&devfreq->lock);
  191. }
  192. /**
  193. * devfreq_interval_update() - Update device devfreq monitoring interval
  194. * @devfreq: the devfreq instance.
  195. * @delay: new polling interval to be set.
  196. *
  197. * Helper function to set new load monitoring polling interval. Function
  198. * to be called from governor in response to DEVFREQ_GOV_INTERVAL event.
  199. */
  200. void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay)
  201. {
  202. unsigned int cur_delay = devfreq->profile->polling_ms;
  203. unsigned int new_delay = *delay;
  204. mutex_lock(&devfreq->lock);
  205. devfreq->profile->polling_ms = new_delay;
  206. if (devfreq->stop_polling)
  207. goto out;
  208. /* if new delay is zero, stop polling */
  209. if (!new_delay) {
  210. mutex_unlock(&devfreq->lock);
  211. cancel_delayed_work_sync(&devfreq->work);
  212. return;
  213. }
  214. /* if current delay is zero, start polling with new delay */
  215. if (!cur_delay) {
  216. queue_delayed_work(devfreq_wq, &devfreq->work,
  217. msecs_to_jiffies(devfreq->profile->polling_ms));
  218. goto out;
  219. }
  220. /* if current delay is greater than new delay, restart polling */
  221. if (cur_delay > new_delay) {
  222. mutex_unlock(&devfreq->lock);
  223. cancel_delayed_work_sync(&devfreq->work);
  224. mutex_lock(&devfreq->lock);
  225. if (!devfreq->stop_polling)
  226. queue_delayed_work(devfreq_wq, &devfreq->work,
  227. msecs_to_jiffies(devfreq->profile->polling_ms));
  228. }
  229. out:
  230. mutex_unlock(&devfreq->lock);
  231. }
  232. /**
  233. * devfreq_notifier_call() - Notify that the device frequency requirements
  234. * has been changed out of devfreq framework.
  235. * @nb: the notifier_block (supposed to be devfreq->nb)
  236. * @type: not used
  237. * @devp: not used
  238. *
  239. * Called by a notifier that uses devfreq->nb.
  240. */
  241. static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
  242. void *devp)
  243. {
  244. struct devfreq *devfreq = container_of(nb, struct devfreq, nb);
  245. int ret;
  246. mutex_lock(&devfreq->lock);
  247. ret = update_devfreq(devfreq);
  248. mutex_unlock(&devfreq->lock);
  249. return ret;
  250. }
  251. /**
  252. * _remove_devfreq() - Remove devfreq from the list and release its resources.
  253. * @devfreq: the devfreq struct
  254. * @skip: skip calling device_unregister().
  255. */
  256. static void _remove_devfreq(struct devfreq *devfreq, bool skip)
  257. {
  258. mutex_lock(&devfreq_list_lock);
  259. if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) {
  260. mutex_unlock(&devfreq_list_lock);
  261. dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n");
  262. return;
  263. }
  264. list_del(&devfreq->node);
  265. mutex_unlock(&devfreq_list_lock);
  266. devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_STOP, NULL);
  267. if (devfreq->profile->exit)
  268. devfreq->profile->exit(devfreq->dev.parent);
  269. if (!skip && get_device(&devfreq->dev)) {
  270. device_unregister(&devfreq->dev);
  271. put_device(&devfreq->dev);
  272. }
  273. mutex_destroy(&devfreq->lock);
  274. kfree(devfreq);
  275. }
  276. /**
  277. * devfreq_dev_release() - Callback for struct device to release the device.
  278. * @dev: the devfreq device
  279. *
  280. * This calls _remove_devfreq() if _remove_devfreq() is not called.
  281. * Note that devfreq_dev_release() could be called by _remove_devfreq() as
  282. * well as by others unregistering the device.
  283. */
  284. static void devfreq_dev_release(struct device *dev)
  285. {
  286. struct devfreq *devfreq = to_devfreq(dev);
  287. _remove_devfreq(devfreq, true);
  288. }
  289. /**
  290. * devfreq_add_device() - Add devfreq feature to the device
  291. * @dev: the device to add devfreq feature.
  292. * @profile: device-specific profile to run devfreq.
  293. * @governor: the policy to choose frequency.
  294. * @data: private data for the governor. The devfreq framework does not
  295. * touch this value.
  296. */
  297. struct devfreq *devfreq_add_device(struct device *dev,
  298. struct devfreq_dev_profile *profile,
  299. const struct devfreq_governor *governor,
  300. void *data)
  301. {
  302. struct devfreq *devfreq;
  303. int err = 0;
  304. if (!dev || !profile || !governor) {
  305. dev_err(dev, "%s: Invalid parameters.\n", __func__);
  306. return ERR_PTR(-EINVAL);
  307. }
  308. mutex_lock(&devfreq_list_lock);
  309. devfreq = find_device_devfreq(dev);
  310. mutex_unlock(&devfreq_list_lock);
  311. if (!IS_ERR(devfreq)) {
  312. dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
  313. err = -EINVAL;
  314. goto err_out;
  315. }
  316. devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
  317. if (!devfreq) {
  318. dev_err(dev, "%s: Unable to create devfreq for the device\n",
  319. __func__);
  320. err = -ENOMEM;
  321. goto err_out;
  322. }
  323. mutex_init(&devfreq->lock);
  324. mutex_lock(&devfreq->lock);
  325. devfreq->dev.parent = dev;
  326. devfreq->dev.class = devfreq_class;
  327. devfreq->dev.release = devfreq_dev_release;
  328. devfreq->profile = profile;
  329. devfreq->governor = governor;
  330. devfreq->previous_freq = profile->initial_freq;
  331. devfreq->data = data;
  332. devfreq->nb.notifier_call = devfreq_notifier_call;
  333. dev_set_name(&devfreq->dev, dev_name(dev));
  334. err = device_register(&devfreq->dev);
  335. if (err) {
  336. put_device(&devfreq->dev);
  337. mutex_unlock(&devfreq->lock);
  338. goto err_dev;
  339. }
  340. mutex_unlock(&devfreq->lock);
  341. mutex_lock(&devfreq_list_lock);
  342. list_add(&devfreq->node, &devfreq_list);
  343. mutex_unlock(&devfreq_list_lock);
  344. err = devfreq->governor->event_handler(devfreq,
  345. DEVFREQ_GOV_START, NULL);
  346. if (err) {
  347. dev_err(dev, "%s: Unable to start governor for the device\n",
  348. __func__);
  349. goto err_init;
  350. }
  351. return devfreq;
  352. err_init:
  353. list_del(&devfreq->node);
  354. device_unregister(&devfreq->dev);
  355. err_dev:
  356. kfree(devfreq);
  357. err_out:
  358. return ERR_PTR(err);
  359. }
  360. EXPORT_SYMBOL(devfreq_add_device);
  361. /**
  362. * devfreq_remove_device() - Remove devfreq feature from a device.
  363. * @devfreq: the devfreq instance to be removed
  364. */
  365. int devfreq_remove_device(struct devfreq *devfreq)
  366. {
  367. if (!devfreq)
  368. return -EINVAL;
  369. _remove_devfreq(devfreq, false);
  370. return 0;
  371. }
  372. EXPORT_SYMBOL(devfreq_remove_device);
  373. /**
  374. * devfreq_suspend_device() - Suspend devfreq of a device.
  375. * @devfreq: the devfreq instance to be suspended
  376. */
  377. int devfreq_suspend_device(struct devfreq *devfreq)
  378. {
  379. if (!devfreq)
  380. return -EINVAL;
  381. return devfreq->governor->event_handler(devfreq,
  382. DEVFREQ_GOV_SUSPEND, NULL);
  383. }
  384. EXPORT_SYMBOL(devfreq_suspend_device);
  385. /**
  386. * devfreq_resume_device() - Resume devfreq of a device.
  387. * @devfreq: the devfreq instance to be resumed
  388. */
  389. int devfreq_resume_device(struct devfreq *devfreq)
  390. {
  391. if (!devfreq)
  392. return -EINVAL;
  393. return devfreq->governor->event_handler(devfreq,
  394. DEVFREQ_GOV_RESUME, NULL);
  395. }
  396. EXPORT_SYMBOL(devfreq_resume_device);
  397. static ssize_t show_governor(struct device *dev,
  398. struct device_attribute *attr, char *buf)
  399. {
  400. return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
  401. }
  402. static ssize_t show_freq(struct device *dev,
  403. struct device_attribute *attr, char *buf)
  404. {
  405. unsigned long freq;
  406. struct devfreq *devfreq = to_devfreq(dev);
  407. if (devfreq->profile->get_cur_freq &&
  408. !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
  409. return sprintf(buf, "%lu\n", freq);
  410. return sprintf(buf, "%lu\n", devfreq->previous_freq);
  411. }
  412. static ssize_t show_target_freq(struct device *dev,
  413. struct device_attribute *attr, char *buf)
  414. {
  415. return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq);
  416. }
  417. static ssize_t show_polling_interval(struct device *dev,
  418. struct device_attribute *attr, char *buf)
  419. {
  420. return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms);
  421. }
  422. static ssize_t store_polling_interval(struct device *dev,
  423. struct device_attribute *attr,
  424. const char *buf, size_t count)
  425. {
  426. struct devfreq *df = to_devfreq(dev);
  427. unsigned int value;
  428. int ret;
  429. ret = sscanf(buf, "%u", &value);
  430. if (ret != 1)
  431. goto out;
  432. df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
  433. ret = count;
  434. out:
  435. return ret;
  436. }
  437. static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr,
  438. const char *buf, size_t count)
  439. {
  440. struct devfreq *df = to_devfreq(dev);
  441. unsigned long value;
  442. int ret;
  443. unsigned long max;
  444. ret = sscanf(buf, "%lu", &value);
  445. if (ret != 1)
  446. goto out;
  447. mutex_lock(&df->lock);
  448. max = df->max_freq;
  449. if (value && max && value > max) {
  450. ret = -EINVAL;
  451. goto unlock;
  452. }
  453. df->min_freq = value;
  454. update_devfreq(df);
  455. ret = count;
  456. unlock:
  457. mutex_unlock(&df->lock);
  458. out:
  459. return ret;
  460. }
  461. static ssize_t show_min_freq(struct device *dev, struct device_attribute *attr,
  462. char *buf)
  463. {
  464. return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq);
  465. }
  466. static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr,
  467. const char *buf, size_t count)
  468. {
  469. struct devfreq *df = to_devfreq(dev);
  470. unsigned long value;
  471. int ret;
  472. unsigned long min;
  473. ret = sscanf(buf, "%lu", &value);
  474. if (ret != 1)
  475. goto out;
  476. mutex_lock(&df->lock);
  477. min = df->min_freq;
  478. if (value && min && value < min) {
  479. ret = -EINVAL;
  480. goto unlock;
  481. }
  482. df->max_freq = value;
  483. update_devfreq(df);
  484. ret = count;
  485. unlock:
  486. mutex_unlock(&df->lock);
  487. out:
  488. return ret;
  489. }
  490. static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr,
  491. char *buf)
  492. {
  493. return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq);
  494. }
  495. static struct device_attribute devfreq_attrs[] = {
  496. __ATTR(governor, S_IRUGO, show_governor, NULL),
  497. __ATTR(cur_freq, S_IRUGO, show_freq, NULL),
  498. __ATTR(target_freq, S_IRUGO, show_target_freq, NULL),
  499. __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval,
  500. store_polling_interval),
  501. __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq),
  502. __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq),
  503. { },
  504. };
  505. static int __init devfreq_init(void)
  506. {
  507. devfreq_class = class_create(THIS_MODULE, "devfreq");
  508. if (IS_ERR(devfreq_class)) {
  509. pr_err("%s: couldn't create class\n", __FILE__);
  510. return PTR_ERR(devfreq_class);
  511. }
  512. devfreq_wq = create_freezable_workqueue("devfreq_wq");
  513. if (IS_ERR(devfreq_wq)) {
  514. class_destroy(devfreq_class);
  515. pr_err("%s: couldn't create workqueue\n", __FILE__);
  516. return PTR_ERR(devfreq_wq);
  517. }
  518. devfreq_class->dev_attrs = devfreq_attrs;
  519. return 0;
  520. }
  521. subsys_initcall(devfreq_init);
  522. static void __exit devfreq_exit(void)
  523. {
  524. class_destroy(devfreq_class);
  525. destroy_workqueue(devfreq_wq);
  526. }
  527. module_exit(devfreq_exit);
  528. /*
  529. * The followings are helper functions for devfreq user device drivers with
  530. * OPP framework.
  531. */
  532. /**
  533. * devfreq_recommended_opp() - Helper function to get proper OPP for the
  534. * freq value given to target callback.
  535. * @dev: The devfreq user device. (parent of devfreq)
  536. * @freq: The frequency given to target function
  537. * @flags: Flags handed from devfreq framework.
  538. *
  539. */
  540. struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq,
  541. u32 flags)
  542. {
  543. struct opp *opp;
  544. if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
  545. /* The freq is an upper bound. opp should be lower */
  546. opp = opp_find_freq_floor(dev, freq);
  547. /* If not available, use the closest opp */
  548. if (opp == ERR_PTR(-ENODEV))
  549. opp = opp_find_freq_ceil(dev, freq);
  550. } else {
  551. /* The freq is an lower bound. opp should be higher */
  552. opp = opp_find_freq_ceil(dev, freq);
  553. /* If not available, use the closest opp */
  554. if (opp == ERR_PTR(-ENODEV))
  555. opp = opp_find_freq_floor(dev, freq);
  556. }
  557. return opp;
  558. }
  559. /**
  560. * devfreq_register_opp_notifier() - Helper function to get devfreq notified
  561. * for any changes in the OPP availability
  562. * changes
  563. * @dev: The devfreq user device. (parent of devfreq)
  564. * @devfreq: The devfreq object.
  565. */
  566. int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
  567. {
  568. struct srcu_notifier_head *nh = opp_get_notifier(dev);
  569. if (IS_ERR(nh))
  570. return PTR_ERR(nh);
  571. return srcu_notifier_chain_register(nh, &devfreq->nb);
  572. }
  573. /**
  574. * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq
  575. * notified for any changes in the OPP
  576. * availability changes anymore.
  577. * @dev: The devfreq user device. (parent of devfreq)
  578. * @devfreq: The devfreq object.
  579. *
  580. * At exit() callback of devfreq_dev_profile, this must be included if
  581. * devfreq_recommended_opp is used.
  582. */
  583. int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
  584. {
  585. struct srcu_notifier_head *nh = opp_get_notifier(dev);
  586. if (IS_ERR(nh))
  587. return PTR_ERR(nh);
  588. return srcu_notifier_chain_unregister(nh, &devfreq->nb);
  589. }
  590. MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
  591. MODULE_DESCRIPTION("devfreq class support");
  592. MODULE_LICENSE("GPL");