devfreq.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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/pm_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 <linux/of.h>
  28. #include "governor.h"
  29. static struct class *devfreq_class;
  30. /*
  31. * devfreq core provides delayed work based load monitoring helper
  32. * functions. Governors can use these or can implement their own
  33. * monitoring mechanism.
  34. */
  35. static struct workqueue_struct *devfreq_wq;
  36. /* The list of all device-devfreq governors */
  37. static LIST_HEAD(devfreq_governor_list);
  38. /* The list of all device-devfreq */
  39. static LIST_HEAD(devfreq_list);
  40. static DEFINE_MUTEX(devfreq_list_lock);
  41. /**
  42. * find_device_devfreq() - find devfreq struct using device pointer
  43. * @dev: device pointer used to lookup device devfreq.
  44. *
  45. * Search the list of device devfreqs and return the matched device's
  46. * devfreq info. devfreq_list_lock should be held by the caller.
  47. */
  48. static struct devfreq *find_device_devfreq(struct device *dev)
  49. {
  50. struct devfreq *tmp_devfreq;
  51. if (IS_ERR_OR_NULL(dev)) {
  52. pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
  53. return ERR_PTR(-EINVAL);
  54. }
  55. WARN(!mutex_is_locked(&devfreq_list_lock),
  56. "devfreq_list_lock must be locked.");
  57. list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
  58. if (tmp_devfreq->dev.parent == dev)
  59. return tmp_devfreq;
  60. }
  61. return ERR_PTR(-ENODEV);
  62. }
  63. /**
  64. * devfreq_get_freq_level() - Lookup freq_table for the frequency
  65. * @devfreq: the devfreq instance
  66. * @freq: the target frequency
  67. */
  68. static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq)
  69. {
  70. int lev;
  71. for (lev = 0; lev < devfreq->profile->max_state; lev++)
  72. if (freq == devfreq->profile->freq_table[lev])
  73. return lev;
  74. return -EINVAL;
  75. }
  76. /**
  77. * devfreq_set_freq_table() - Initialize freq_table for the frequency
  78. * @devfreq: the devfreq instance
  79. */
  80. static void devfreq_set_freq_table(struct devfreq *devfreq)
  81. {
  82. struct devfreq_dev_profile *profile = devfreq->profile;
  83. struct dev_pm_opp *opp;
  84. unsigned long freq;
  85. int i, count;
  86. /* Initialize the freq_table from OPP table */
  87. count = dev_pm_opp_get_opp_count(devfreq->dev.parent);
  88. if (count <= 0)
  89. return;
  90. profile->max_state = count;
  91. profile->freq_table = devm_kcalloc(devfreq->dev.parent,
  92. profile->max_state,
  93. sizeof(*profile->freq_table),
  94. GFP_KERNEL);
  95. if (!profile->freq_table) {
  96. profile->max_state = 0;
  97. return;
  98. }
  99. rcu_read_lock();
  100. for (i = 0, freq = 0; i < profile->max_state; i++, freq++) {
  101. opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq);
  102. if (IS_ERR(opp)) {
  103. devm_kfree(devfreq->dev.parent, profile->freq_table);
  104. profile->max_state = 0;
  105. rcu_read_unlock();
  106. return;
  107. }
  108. profile->freq_table[i] = freq;
  109. }
  110. rcu_read_unlock();
  111. }
  112. /**
  113. * devfreq_update_status() - Update statistics of devfreq behavior
  114. * @devfreq: the devfreq instance
  115. * @freq: the update target frequency
  116. */
  117. static int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
  118. {
  119. int lev, prev_lev, ret = 0;
  120. unsigned long cur_time;
  121. cur_time = jiffies;
  122. prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq);
  123. if (prev_lev < 0) {
  124. ret = prev_lev;
  125. goto out;
  126. }
  127. devfreq->time_in_state[prev_lev] +=
  128. cur_time - devfreq->last_stat_updated;
  129. lev = devfreq_get_freq_level(devfreq, freq);
  130. if (lev < 0) {
  131. ret = lev;
  132. goto out;
  133. }
  134. if (lev != prev_lev) {
  135. devfreq->trans_table[(prev_lev *
  136. devfreq->profile->max_state) + lev]++;
  137. devfreq->total_trans++;
  138. }
  139. out:
  140. devfreq->last_stat_updated = cur_time;
  141. return ret;
  142. }
  143. /**
  144. * find_devfreq_governor() - find devfreq governor from name
  145. * @name: name of the governor
  146. *
  147. * Search the list of devfreq governors and return the matched
  148. * governor's pointer. devfreq_list_lock should be held by the caller.
  149. */
  150. static struct devfreq_governor *find_devfreq_governor(const char *name)
  151. {
  152. struct devfreq_governor *tmp_governor;
  153. if (IS_ERR_OR_NULL(name)) {
  154. pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
  155. return ERR_PTR(-EINVAL);
  156. }
  157. WARN(!mutex_is_locked(&devfreq_list_lock),
  158. "devfreq_list_lock must be locked.");
  159. list_for_each_entry(tmp_governor, &devfreq_governor_list, node) {
  160. if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN))
  161. return tmp_governor;
  162. }
  163. return ERR_PTR(-ENODEV);
  164. }
  165. /* Load monitoring helper functions for governors use */
  166. /**
  167. * update_devfreq() - Reevaluate the device and configure frequency.
  168. * @devfreq: the devfreq instance.
  169. *
  170. * Note: Lock devfreq->lock before calling update_devfreq
  171. * This function is exported for governors.
  172. */
  173. int update_devfreq(struct devfreq *devfreq)
  174. {
  175. unsigned long freq;
  176. int err = 0;
  177. u32 flags = 0;
  178. if (!mutex_is_locked(&devfreq->lock)) {
  179. WARN(true, "devfreq->lock must be locked by the caller.\n");
  180. return -EINVAL;
  181. }
  182. if (!devfreq->governor)
  183. return -EINVAL;
  184. /* Reevaluate the proper frequency */
  185. err = devfreq->governor->get_target_freq(devfreq, &freq);
  186. if (err)
  187. return err;
  188. /*
  189. * Adjust the frequency with user freq and QoS.
  190. *
  191. * List from the highest priority
  192. * max_freq
  193. * min_freq
  194. */
  195. if (devfreq->min_freq && freq < devfreq->min_freq) {
  196. freq = devfreq->min_freq;
  197. flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */
  198. }
  199. if (devfreq->max_freq && freq > devfreq->max_freq) {
  200. freq = devfreq->max_freq;
  201. flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
  202. }
  203. err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
  204. if (err)
  205. return err;
  206. if (devfreq->profile->freq_table)
  207. if (devfreq_update_status(devfreq, freq))
  208. dev_err(&devfreq->dev,
  209. "Couldn't update frequency transition information.\n");
  210. devfreq->previous_freq = freq;
  211. return err;
  212. }
  213. EXPORT_SYMBOL(update_devfreq);
  214. /**
  215. * devfreq_monitor() - Periodically poll devfreq objects.
  216. * @work: the work struct used to run devfreq_monitor periodically.
  217. *
  218. */
  219. static void devfreq_monitor(struct work_struct *work)
  220. {
  221. int err;
  222. struct devfreq *devfreq = container_of(work,
  223. struct devfreq, work.work);
  224. mutex_lock(&devfreq->lock);
  225. err = update_devfreq(devfreq);
  226. if (err)
  227. dev_err(&devfreq->dev, "dvfs failed with (%d) error\n", err);
  228. queue_delayed_work(devfreq_wq, &devfreq->work,
  229. msecs_to_jiffies(devfreq->profile->polling_ms));
  230. mutex_unlock(&devfreq->lock);
  231. }
  232. /**
  233. * devfreq_monitor_start() - Start load monitoring of devfreq instance
  234. * @devfreq: the devfreq instance.
  235. *
  236. * Helper function for starting devfreq device load monitoing. By
  237. * default delayed work based monitoring is supported. Function
  238. * to be called from governor in response to DEVFREQ_GOV_START
  239. * event when device is added to devfreq framework.
  240. */
  241. void devfreq_monitor_start(struct devfreq *devfreq)
  242. {
  243. INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor);
  244. if (devfreq->profile->polling_ms)
  245. queue_delayed_work(devfreq_wq, &devfreq->work,
  246. msecs_to_jiffies(devfreq->profile->polling_ms));
  247. }
  248. EXPORT_SYMBOL(devfreq_monitor_start);
  249. /**
  250. * devfreq_monitor_stop() - Stop load monitoring of a devfreq instance
  251. * @devfreq: the devfreq instance.
  252. *
  253. * Helper function to stop devfreq device load monitoing. Function
  254. * to be called from governor in response to DEVFREQ_GOV_STOP
  255. * event when device is removed from devfreq framework.
  256. */
  257. void devfreq_monitor_stop(struct devfreq *devfreq)
  258. {
  259. cancel_delayed_work_sync(&devfreq->work);
  260. }
  261. EXPORT_SYMBOL(devfreq_monitor_stop);
  262. /**
  263. * devfreq_monitor_suspend() - Suspend load monitoring of a devfreq instance
  264. * @devfreq: the devfreq instance.
  265. *
  266. * Helper function to suspend devfreq device load monitoing. Function
  267. * to be called from governor in response to DEVFREQ_GOV_SUSPEND
  268. * event or when polling interval is set to zero.
  269. *
  270. * Note: Though this function is same as devfreq_monitor_stop(),
  271. * intentionally kept separate to provide hooks for collecting
  272. * transition statistics.
  273. */
  274. void devfreq_monitor_suspend(struct devfreq *devfreq)
  275. {
  276. mutex_lock(&devfreq->lock);
  277. if (devfreq->stop_polling) {
  278. mutex_unlock(&devfreq->lock);
  279. return;
  280. }
  281. devfreq_update_status(devfreq, devfreq->previous_freq);
  282. devfreq->stop_polling = true;
  283. mutex_unlock(&devfreq->lock);
  284. cancel_delayed_work_sync(&devfreq->work);
  285. }
  286. EXPORT_SYMBOL(devfreq_monitor_suspend);
  287. /**
  288. * devfreq_monitor_resume() - Resume load monitoring of a devfreq instance
  289. * @devfreq: the devfreq instance.
  290. *
  291. * Helper function to resume devfreq device load monitoing. Function
  292. * to be called from governor in response to DEVFREQ_GOV_RESUME
  293. * event or when polling interval is set to non-zero.
  294. */
  295. void devfreq_monitor_resume(struct devfreq *devfreq)
  296. {
  297. unsigned long freq;
  298. mutex_lock(&devfreq->lock);
  299. if (!devfreq->stop_polling)
  300. goto out;
  301. if (!delayed_work_pending(&devfreq->work) &&
  302. devfreq->profile->polling_ms)
  303. queue_delayed_work(devfreq_wq, &devfreq->work,
  304. msecs_to_jiffies(devfreq->profile->polling_ms));
  305. devfreq->last_stat_updated = jiffies;
  306. devfreq->stop_polling = false;
  307. if (devfreq->profile->get_cur_freq &&
  308. !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
  309. devfreq->previous_freq = freq;
  310. out:
  311. mutex_unlock(&devfreq->lock);
  312. }
  313. EXPORT_SYMBOL(devfreq_monitor_resume);
  314. /**
  315. * devfreq_interval_update() - Update device devfreq monitoring interval
  316. * @devfreq: the devfreq instance.
  317. * @delay: new polling interval to be set.
  318. *
  319. * Helper function to set new load monitoring polling interval. Function
  320. * to be called from governor in response to DEVFREQ_GOV_INTERVAL event.
  321. */
  322. void devfreq_interval_update(struct devfreq *devfreq, unsigned int *delay)
  323. {
  324. unsigned int cur_delay = devfreq->profile->polling_ms;
  325. unsigned int new_delay = *delay;
  326. mutex_lock(&devfreq->lock);
  327. devfreq->profile->polling_ms = new_delay;
  328. if (devfreq->stop_polling)
  329. goto out;
  330. /* if new delay is zero, stop polling */
  331. if (!new_delay) {
  332. mutex_unlock(&devfreq->lock);
  333. cancel_delayed_work_sync(&devfreq->work);
  334. return;
  335. }
  336. /* if current delay is zero, start polling with new delay */
  337. if (!cur_delay) {
  338. queue_delayed_work(devfreq_wq, &devfreq->work,
  339. msecs_to_jiffies(devfreq->profile->polling_ms));
  340. goto out;
  341. }
  342. /* if current delay is greater than new delay, restart polling */
  343. if (cur_delay > new_delay) {
  344. mutex_unlock(&devfreq->lock);
  345. cancel_delayed_work_sync(&devfreq->work);
  346. mutex_lock(&devfreq->lock);
  347. if (!devfreq->stop_polling)
  348. queue_delayed_work(devfreq_wq, &devfreq->work,
  349. msecs_to_jiffies(devfreq->profile->polling_ms));
  350. }
  351. out:
  352. mutex_unlock(&devfreq->lock);
  353. }
  354. EXPORT_SYMBOL(devfreq_interval_update);
  355. /**
  356. * devfreq_notifier_call() - Notify that the device frequency requirements
  357. * has been changed out of devfreq framework.
  358. * @nb: the notifier_block (supposed to be devfreq->nb)
  359. * @type: not used
  360. * @devp: not used
  361. *
  362. * Called by a notifier that uses devfreq->nb.
  363. */
  364. static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
  365. void *devp)
  366. {
  367. struct devfreq *devfreq = container_of(nb, struct devfreq, nb);
  368. int ret;
  369. mutex_lock(&devfreq->lock);
  370. ret = update_devfreq(devfreq);
  371. mutex_unlock(&devfreq->lock);
  372. return ret;
  373. }
  374. /**
  375. * _remove_devfreq() - Remove devfreq from the list and release its resources.
  376. * @devfreq: the devfreq struct
  377. */
  378. static void _remove_devfreq(struct devfreq *devfreq)
  379. {
  380. mutex_lock(&devfreq_list_lock);
  381. if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) {
  382. mutex_unlock(&devfreq_list_lock);
  383. dev_warn(&devfreq->dev, "releasing devfreq which doesn't exist\n");
  384. return;
  385. }
  386. list_del(&devfreq->node);
  387. mutex_unlock(&devfreq_list_lock);
  388. if (devfreq->governor)
  389. devfreq->governor->event_handler(devfreq,
  390. DEVFREQ_GOV_STOP, NULL);
  391. if (devfreq->profile->exit)
  392. devfreq->profile->exit(devfreq->dev.parent);
  393. mutex_destroy(&devfreq->lock);
  394. kfree(devfreq);
  395. }
  396. /**
  397. * devfreq_dev_release() - Callback for struct device to release the device.
  398. * @dev: the devfreq device
  399. *
  400. * This calls _remove_devfreq() if _remove_devfreq() is not called.
  401. */
  402. static void devfreq_dev_release(struct device *dev)
  403. {
  404. struct devfreq *devfreq = to_devfreq(dev);
  405. _remove_devfreq(devfreq);
  406. }
  407. /**
  408. * devfreq_add_device() - Add devfreq feature to the device
  409. * @dev: the device to add devfreq feature.
  410. * @profile: device-specific profile to run devfreq.
  411. * @governor_name: name of the policy to choose frequency.
  412. * @data: private data for the governor. The devfreq framework does not
  413. * touch this value.
  414. */
  415. struct devfreq *devfreq_add_device(struct device *dev,
  416. struct devfreq_dev_profile *profile,
  417. const char *governor_name,
  418. void *data)
  419. {
  420. struct devfreq *devfreq;
  421. struct devfreq_governor *governor;
  422. int err = 0;
  423. if (!dev || !profile || !governor_name) {
  424. dev_err(dev, "%s: Invalid parameters.\n", __func__);
  425. return ERR_PTR(-EINVAL);
  426. }
  427. mutex_lock(&devfreq_list_lock);
  428. devfreq = find_device_devfreq(dev);
  429. mutex_unlock(&devfreq_list_lock);
  430. if (!IS_ERR(devfreq)) {
  431. dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__);
  432. err = -EINVAL;
  433. goto err_out;
  434. }
  435. devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL);
  436. if (!devfreq) {
  437. dev_err(dev, "%s: Unable to create devfreq for the device\n",
  438. __func__);
  439. err = -ENOMEM;
  440. goto err_out;
  441. }
  442. mutex_init(&devfreq->lock);
  443. mutex_lock(&devfreq->lock);
  444. devfreq->dev.parent = dev;
  445. devfreq->dev.class = devfreq_class;
  446. devfreq->dev.release = devfreq_dev_release;
  447. devfreq->profile = profile;
  448. strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
  449. devfreq->previous_freq = profile->initial_freq;
  450. devfreq->data = data;
  451. devfreq->nb.notifier_call = devfreq_notifier_call;
  452. if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
  453. mutex_unlock(&devfreq->lock);
  454. devfreq_set_freq_table(devfreq);
  455. mutex_lock(&devfreq->lock);
  456. }
  457. devfreq->trans_table = devm_kzalloc(dev, sizeof(unsigned int) *
  458. devfreq->profile->max_state *
  459. devfreq->profile->max_state,
  460. GFP_KERNEL);
  461. devfreq->time_in_state = devm_kzalloc(dev, sizeof(unsigned long) *
  462. devfreq->profile->max_state,
  463. GFP_KERNEL);
  464. devfreq->last_stat_updated = jiffies;
  465. dev_set_name(&devfreq->dev, "%s", dev_name(dev));
  466. err = device_register(&devfreq->dev);
  467. if (err) {
  468. put_device(&devfreq->dev);
  469. mutex_unlock(&devfreq->lock);
  470. goto err_out;
  471. }
  472. mutex_unlock(&devfreq->lock);
  473. mutex_lock(&devfreq_list_lock);
  474. list_add(&devfreq->node, &devfreq_list);
  475. governor = find_devfreq_governor(devfreq->governor_name);
  476. if (!IS_ERR(governor))
  477. devfreq->governor = governor;
  478. if (devfreq->governor)
  479. err = devfreq->governor->event_handler(devfreq,
  480. DEVFREQ_GOV_START, NULL);
  481. mutex_unlock(&devfreq_list_lock);
  482. if (err) {
  483. dev_err(dev, "%s: Unable to start governor for the device\n",
  484. __func__);
  485. goto err_init;
  486. }
  487. return devfreq;
  488. err_init:
  489. list_del(&devfreq->node);
  490. device_unregister(&devfreq->dev);
  491. kfree(devfreq);
  492. err_out:
  493. return ERR_PTR(err);
  494. }
  495. EXPORT_SYMBOL(devfreq_add_device);
  496. /**
  497. * devfreq_remove_device() - Remove devfreq feature from a device.
  498. * @devfreq: the devfreq instance to be removed
  499. *
  500. * The opposite of devfreq_add_device().
  501. */
  502. int devfreq_remove_device(struct devfreq *devfreq)
  503. {
  504. if (!devfreq)
  505. return -EINVAL;
  506. device_unregister(&devfreq->dev);
  507. put_device(&devfreq->dev);
  508. return 0;
  509. }
  510. EXPORT_SYMBOL(devfreq_remove_device);
  511. static int devm_devfreq_dev_match(struct device *dev, void *res, void *data)
  512. {
  513. struct devfreq **r = res;
  514. if (WARN_ON(!r || !*r))
  515. return 0;
  516. return *r == data;
  517. }
  518. static void devm_devfreq_dev_release(struct device *dev, void *res)
  519. {
  520. devfreq_remove_device(*(struct devfreq **)res);
  521. }
  522. /**
  523. * devm_devfreq_add_device() - Resource-managed devfreq_add_device()
  524. * @dev: the device to add devfreq feature.
  525. * @profile: device-specific profile to run devfreq.
  526. * @governor_name: name of the policy to choose frequency.
  527. * @data: private data for the governor. The devfreq framework does not
  528. * touch this value.
  529. *
  530. * This function manages automatically the memory of devfreq device using device
  531. * resource management and simplify the free operation for memory of devfreq
  532. * device.
  533. */
  534. struct devfreq *devm_devfreq_add_device(struct device *dev,
  535. struct devfreq_dev_profile *profile,
  536. const char *governor_name,
  537. void *data)
  538. {
  539. struct devfreq **ptr, *devfreq;
  540. ptr = devres_alloc(devm_devfreq_dev_release, sizeof(*ptr), GFP_KERNEL);
  541. if (!ptr)
  542. return ERR_PTR(-ENOMEM);
  543. devfreq = devfreq_add_device(dev, profile, governor_name, data);
  544. if (IS_ERR(devfreq)) {
  545. devres_free(ptr);
  546. return ERR_PTR(-ENOMEM);
  547. }
  548. *ptr = devfreq;
  549. devres_add(dev, ptr);
  550. return devfreq;
  551. }
  552. EXPORT_SYMBOL(devm_devfreq_add_device);
  553. #ifdef CONFIG_OF
  554. /*
  555. * devfreq_get_devfreq_by_phandle - Get the devfreq device from devicetree
  556. * @dev - instance to the given device
  557. * @index - index into list of devfreq
  558. *
  559. * return the instance of devfreq device
  560. */
  561. struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
  562. {
  563. struct device_node *node;
  564. struct devfreq *devfreq;
  565. if (!dev)
  566. return ERR_PTR(-EINVAL);
  567. if (!dev->of_node)
  568. return ERR_PTR(-EINVAL);
  569. node = of_parse_phandle(dev->of_node, "devfreq", index);
  570. if (!node)
  571. return ERR_PTR(-ENODEV);
  572. mutex_lock(&devfreq_list_lock);
  573. list_for_each_entry(devfreq, &devfreq_list, node) {
  574. if (devfreq->dev.parent
  575. && devfreq->dev.parent->of_node == node) {
  576. mutex_unlock(&devfreq_list_lock);
  577. return devfreq;
  578. }
  579. }
  580. mutex_unlock(&devfreq_list_lock);
  581. return ERR_PTR(-EPROBE_DEFER);
  582. }
  583. #else
  584. struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
  585. {
  586. return ERR_PTR(-ENODEV);
  587. }
  588. #endif /* CONFIG_OF */
  589. EXPORT_SYMBOL_GPL(devfreq_get_devfreq_by_phandle);
  590. /**
  591. * devm_devfreq_remove_device() - Resource-managed devfreq_remove_device()
  592. * @dev: the device to add devfreq feature.
  593. * @devfreq: the devfreq instance to be removed
  594. */
  595. void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq)
  596. {
  597. WARN_ON(devres_release(dev, devm_devfreq_dev_release,
  598. devm_devfreq_dev_match, devfreq));
  599. }
  600. EXPORT_SYMBOL(devm_devfreq_remove_device);
  601. /**
  602. * devfreq_suspend_device() - Suspend devfreq of a device.
  603. * @devfreq: the devfreq instance to be suspended
  604. *
  605. * This function is intended to be called by the pm callbacks
  606. * (e.g., runtime_suspend, suspend) of the device driver that
  607. * holds the devfreq.
  608. */
  609. int devfreq_suspend_device(struct devfreq *devfreq)
  610. {
  611. if (!devfreq)
  612. return -EINVAL;
  613. if (!devfreq->governor)
  614. return 0;
  615. return devfreq->governor->event_handler(devfreq,
  616. DEVFREQ_GOV_SUSPEND, NULL);
  617. }
  618. EXPORT_SYMBOL(devfreq_suspend_device);
  619. /**
  620. * devfreq_resume_device() - Resume devfreq of a device.
  621. * @devfreq: the devfreq instance to be resumed
  622. *
  623. * This function is intended to be called by the pm callbacks
  624. * (e.g., runtime_resume, resume) of the device driver that
  625. * holds the devfreq.
  626. */
  627. int devfreq_resume_device(struct devfreq *devfreq)
  628. {
  629. if (!devfreq)
  630. return -EINVAL;
  631. if (!devfreq->governor)
  632. return 0;
  633. return devfreq->governor->event_handler(devfreq,
  634. DEVFREQ_GOV_RESUME, NULL);
  635. }
  636. EXPORT_SYMBOL(devfreq_resume_device);
  637. /**
  638. * devfreq_add_governor() - Add devfreq governor
  639. * @governor: the devfreq governor to be added
  640. */
  641. int devfreq_add_governor(struct devfreq_governor *governor)
  642. {
  643. struct devfreq_governor *g;
  644. struct devfreq *devfreq;
  645. int err = 0;
  646. if (!governor) {
  647. pr_err("%s: Invalid parameters.\n", __func__);
  648. return -EINVAL;
  649. }
  650. mutex_lock(&devfreq_list_lock);
  651. g = find_devfreq_governor(governor->name);
  652. if (!IS_ERR(g)) {
  653. pr_err("%s: governor %s already registered\n", __func__,
  654. g->name);
  655. err = -EINVAL;
  656. goto err_out;
  657. }
  658. list_add(&governor->node, &devfreq_governor_list);
  659. list_for_each_entry(devfreq, &devfreq_list, node) {
  660. int ret = 0;
  661. struct device *dev = devfreq->dev.parent;
  662. if (!strncmp(devfreq->governor_name, governor->name,
  663. DEVFREQ_NAME_LEN)) {
  664. /* The following should never occur */
  665. if (devfreq->governor) {
  666. dev_warn(dev,
  667. "%s: Governor %s already present\n",
  668. __func__, devfreq->governor->name);
  669. ret = devfreq->governor->event_handler(devfreq,
  670. DEVFREQ_GOV_STOP, NULL);
  671. if (ret) {
  672. dev_warn(dev,
  673. "%s: Governor %s stop = %d\n",
  674. __func__,
  675. devfreq->governor->name, ret);
  676. }
  677. /* Fall through */
  678. }
  679. devfreq->governor = governor;
  680. ret = devfreq->governor->event_handler(devfreq,
  681. DEVFREQ_GOV_START, NULL);
  682. if (ret) {
  683. dev_warn(dev, "%s: Governor %s start=%d\n",
  684. __func__, devfreq->governor->name,
  685. ret);
  686. }
  687. }
  688. }
  689. err_out:
  690. mutex_unlock(&devfreq_list_lock);
  691. return err;
  692. }
  693. EXPORT_SYMBOL(devfreq_add_governor);
  694. /**
  695. * devfreq_remove_device() - Remove devfreq feature from a device.
  696. * @governor: the devfreq governor to be removed
  697. */
  698. int devfreq_remove_governor(struct devfreq_governor *governor)
  699. {
  700. struct devfreq_governor *g;
  701. struct devfreq *devfreq;
  702. int err = 0;
  703. if (!governor) {
  704. pr_err("%s: Invalid parameters.\n", __func__);
  705. return -EINVAL;
  706. }
  707. mutex_lock(&devfreq_list_lock);
  708. g = find_devfreq_governor(governor->name);
  709. if (IS_ERR(g)) {
  710. pr_err("%s: governor %s not registered\n", __func__,
  711. governor->name);
  712. err = PTR_ERR(g);
  713. goto err_out;
  714. }
  715. list_for_each_entry(devfreq, &devfreq_list, node) {
  716. int ret;
  717. struct device *dev = devfreq->dev.parent;
  718. if (!strncmp(devfreq->governor_name, governor->name,
  719. DEVFREQ_NAME_LEN)) {
  720. /* we should have a devfreq governor! */
  721. if (!devfreq->governor) {
  722. dev_warn(dev, "%s: Governor %s NOT present\n",
  723. __func__, governor->name);
  724. continue;
  725. /* Fall through */
  726. }
  727. ret = devfreq->governor->event_handler(devfreq,
  728. DEVFREQ_GOV_STOP, NULL);
  729. if (ret) {
  730. dev_warn(dev, "%s: Governor %s stop=%d\n",
  731. __func__, devfreq->governor->name,
  732. ret);
  733. }
  734. devfreq->governor = NULL;
  735. }
  736. }
  737. list_del(&governor->node);
  738. err_out:
  739. mutex_unlock(&devfreq_list_lock);
  740. return err;
  741. }
  742. EXPORT_SYMBOL(devfreq_remove_governor);
  743. static ssize_t governor_show(struct device *dev,
  744. struct device_attribute *attr, char *buf)
  745. {
  746. if (!to_devfreq(dev)->governor)
  747. return -EINVAL;
  748. return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
  749. }
  750. static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
  751. const char *buf, size_t count)
  752. {
  753. struct devfreq *df = to_devfreq(dev);
  754. int ret;
  755. char str_governor[DEVFREQ_NAME_LEN + 1];
  756. struct devfreq_governor *governor;
  757. ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
  758. if (ret != 1)
  759. return -EINVAL;
  760. mutex_lock(&devfreq_list_lock);
  761. governor = find_devfreq_governor(str_governor);
  762. if (IS_ERR(governor)) {
  763. ret = PTR_ERR(governor);
  764. goto out;
  765. }
  766. if (df->governor == governor) {
  767. ret = 0;
  768. goto out;
  769. }
  770. if (df->governor) {
  771. ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
  772. if (ret) {
  773. dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
  774. __func__, df->governor->name, ret);
  775. goto out;
  776. }
  777. }
  778. df->governor = governor;
  779. strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
  780. ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
  781. if (ret)
  782. dev_warn(dev, "%s: Governor %s not started(%d)\n",
  783. __func__, df->governor->name, ret);
  784. out:
  785. mutex_unlock(&devfreq_list_lock);
  786. if (!ret)
  787. ret = count;
  788. return ret;
  789. }
  790. static DEVICE_ATTR_RW(governor);
  791. static ssize_t available_governors_show(struct device *d,
  792. struct device_attribute *attr,
  793. char *buf)
  794. {
  795. struct devfreq_governor *tmp_governor;
  796. ssize_t count = 0;
  797. mutex_lock(&devfreq_list_lock);
  798. list_for_each_entry(tmp_governor, &devfreq_governor_list, node)
  799. count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
  800. "%s ", tmp_governor->name);
  801. mutex_unlock(&devfreq_list_lock);
  802. /* Truncate the trailing space */
  803. if (count)
  804. count--;
  805. count += sprintf(&buf[count], "\n");
  806. return count;
  807. }
  808. static DEVICE_ATTR_RO(available_governors);
  809. static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
  810. char *buf)
  811. {
  812. unsigned long freq;
  813. struct devfreq *devfreq = to_devfreq(dev);
  814. if (devfreq->profile->get_cur_freq &&
  815. !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
  816. return sprintf(buf, "%lu\n", freq);
  817. return sprintf(buf, "%lu\n", devfreq->previous_freq);
  818. }
  819. static DEVICE_ATTR_RO(cur_freq);
  820. static ssize_t target_freq_show(struct device *dev,
  821. struct device_attribute *attr, char *buf)
  822. {
  823. return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq);
  824. }
  825. static DEVICE_ATTR_RO(target_freq);
  826. static ssize_t polling_interval_show(struct device *dev,
  827. struct device_attribute *attr, char *buf)
  828. {
  829. return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms);
  830. }
  831. static ssize_t polling_interval_store(struct device *dev,
  832. struct device_attribute *attr,
  833. const char *buf, size_t count)
  834. {
  835. struct devfreq *df = to_devfreq(dev);
  836. unsigned int value;
  837. int ret;
  838. if (!df->governor)
  839. return -EINVAL;
  840. ret = sscanf(buf, "%u", &value);
  841. if (ret != 1)
  842. return -EINVAL;
  843. df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
  844. ret = count;
  845. return ret;
  846. }
  847. static DEVICE_ATTR_RW(polling_interval);
  848. static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
  849. const char *buf, size_t count)
  850. {
  851. struct devfreq *df = to_devfreq(dev);
  852. unsigned long value;
  853. int ret;
  854. unsigned long max;
  855. ret = sscanf(buf, "%lu", &value);
  856. if (ret != 1)
  857. return -EINVAL;
  858. mutex_lock(&df->lock);
  859. max = df->max_freq;
  860. if (value && max && value > max) {
  861. ret = -EINVAL;
  862. goto unlock;
  863. }
  864. df->min_freq = value;
  865. update_devfreq(df);
  866. ret = count;
  867. unlock:
  868. mutex_unlock(&df->lock);
  869. return ret;
  870. }
  871. static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
  872. const char *buf, size_t count)
  873. {
  874. struct devfreq *df = to_devfreq(dev);
  875. unsigned long value;
  876. int ret;
  877. unsigned long min;
  878. ret = sscanf(buf, "%lu", &value);
  879. if (ret != 1)
  880. return -EINVAL;
  881. mutex_lock(&df->lock);
  882. min = df->min_freq;
  883. if (value && min && value < min) {
  884. ret = -EINVAL;
  885. goto unlock;
  886. }
  887. df->max_freq = value;
  888. update_devfreq(df);
  889. ret = count;
  890. unlock:
  891. mutex_unlock(&df->lock);
  892. return ret;
  893. }
  894. #define show_one(name) \
  895. static ssize_t name##_show \
  896. (struct device *dev, struct device_attribute *attr, char *buf) \
  897. { \
  898. return sprintf(buf, "%lu\n", to_devfreq(dev)->name); \
  899. }
  900. show_one(min_freq);
  901. show_one(max_freq);
  902. static DEVICE_ATTR_RW(min_freq);
  903. static DEVICE_ATTR_RW(max_freq);
  904. static ssize_t available_frequencies_show(struct device *d,
  905. struct device_attribute *attr,
  906. char *buf)
  907. {
  908. struct devfreq *df = to_devfreq(d);
  909. struct device *dev = df->dev.parent;
  910. struct dev_pm_opp *opp;
  911. ssize_t count = 0;
  912. unsigned long freq = 0;
  913. rcu_read_lock();
  914. do {
  915. opp = dev_pm_opp_find_freq_ceil(dev, &freq);
  916. if (IS_ERR(opp))
  917. break;
  918. count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
  919. "%lu ", freq);
  920. freq++;
  921. } while (1);
  922. rcu_read_unlock();
  923. /* Truncate the trailing space */
  924. if (count)
  925. count--;
  926. count += sprintf(&buf[count], "\n");
  927. return count;
  928. }
  929. static DEVICE_ATTR_RO(available_frequencies);
  930. static ssize_t trans_stat_show(struct device *dev,
  931. struct device_attribute *attr, char *buf)
  932. {
  933. struct devfreq *devfreq = to_devfreq(dev);
  934. ssize_t len;
  935. int i, j;
  936. unsigned int max_state = devfreq->profile->max_state;
  937. if (!devfreq->stop_polling &&
  938. devfreq_update_status(devfreq, devfreq->previous_freq))
  939. return 0;
  940. if (max_state == 0)
  941. return sprintf(buf, "Not Supported.\n");
  942. len = sprintf(buf, " From : To\n");
  943. len += sprintf(buf + len, " :");
  944. for (i = 0; i < max_state; i++)
  945. len += sprintf(buf + len, "%10lu",
  946. devfreq->profile->freq_table[i]);
  947. len += sprintf(buf + len, " time(ms)\n");
  948. for (i = 0; i < max_state; i++) {
  949. if (devfreq->profile->freq_table[i]
  950. == devfreq->previous_freq) {
  951. len += sprintf(buf + len, "*");
  952. } else {
  953. len += sprintf(buf + len, " ");
  954. }
  955. len += sprintf(buf + len, "%10lu:",
  956. devfreq->profile->freq_table[i]);
  957. for (j = 0; j < max_state; j++)
  958. len += sprintf(buf + len, "%10u",
  959. devfreq->trans_table[(i * max_state) + j]);
  960. len += sprintf(buf + len, "%10u\n",
  961. jiffies_to_msecs(devfreq->time_in_state[i]));
  962. }
  963. len += sprintf(buf + len, "Total transition : %u\n",
  964. devfreq->total_trans);
  965. return len;
  966. }
  967. static DEVICE_ATTR_RO(trans_stat);
  968. static struct attribute *devfreq_attrs[] = {
  969. &dev_attr_governor.attr,
  970. &dev_attr_available_governors.attr,
  971. &dev_attr_cur_freq.attr,
  972. &dev_attr_available_frequencies.attr,
  973. &dev_attr_target_freq.attr,
  974. &dev_attr_polling_interval.attr,
  975. &dev_attr_min_freq.attr,
  976. &dev_attr_max_freq.attr,
  977. &dev_attr_trans_stat.attr,
  978. NULL,
  979. };
  980. ATTRIBUTE_GROUPS(devfreq);
  981. static int __init devfreq_init(void)
  982. {
  983. devfreq_class = class_create(THIS_MODULE, "devfreq");
  984. if (IS_ERR(devfreq_class)) {
  985. pr_err("%s: couldn't create class\n", __FILE__);
  986. return PTR_ERR(devfreq_class);
  987. }
  988. devfreq_wq = create_freezable_workqueue("devfreq_wq");
  989. if (!devfreq_wq) {
  990. class_destroy(devfreq_class);
  991. pr_err("%s: couldn't create workqueue\n", __FILE__);
  992. return -ENOMEM;
  993. }
  994. devfreq_class->dev_groups = devfreq_groups;
  995. return 0;
  996. }
  997. subsys_initcall(devfreq_init);
  998. static void __exit devfreq_exit(void)
  999. {
  1000. class_destroy(devfreq_class);
  1001. destroy_workqueue(devfreq_wq);
  1002. }
  1003. module_exit(devfreq_exit);
  1004. /*
  1005. * The followings are helper functions for devfreq user device drivers with
  1006. * OPP framework.
  1007. */
  1008. /**
  1009. * devfreq_recommended_opp() - Helper function to get proper OPP for the
  1010. * freq value given to target callback.
  1011. * @dev: The devfreq user device. (parent of devfreq)
  1012. * @freq: The frequency given to target function
  1013. * @flags: Flags handed from devfreq framework.
  1014. *
  1015. * Locking: This function must be called under rcu_read_lock(). opp is a rcu
  1016. * protected pointer. The reason for the same is that the opp pointer which is
  1017. * returned will remain valid for use with opp_get_{voltage, freq} only while
  1018. * under the locked area. The pointer returned must be used prior to unlocking
  1019. * with rcu_read_unlock() to maintain the integrity of the pointer.
  1020. */
  1021. struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
  1022. unsigned long *freq,
  1023. u32 flags)
  1024. {
  1025. struct dev_pm_opp *opp;
  1026. if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
  1027. /* The freq is an upper bound. opp should be lower */
  1028. opp = dev_pm_opp_find_freq_floor(dev, freq);
  1029. /* If not available, use the closest opp */
  1030. if (opp == ERR_PTR(-ERANGE))
  1031. opp = dev_pm_opp_find_freq_ceil(dev, freq);
  1032. } else {
  1033. /* The freq is an lower bound. opp should be higher */
  1034. opp = dev_pm_opp_find_freq_ceil(dev, freq);
  1035. /* If not available, use the closest opp */
  1036. if (opp == ERR_PTR(-ERANGE))
  1037. opp = dev_pm_opp_find_freq_floor(dev, freq);
  1038. }
  1039. return opp;
  1040. }
  1041. EXPORT_SYMBOL(devfreq_recommended_opp);
  1042. /**
  1043. * devfreq_register_opp_notifier() - Helper function to get devfreq notified
  1044. * for any changes in the OPP availability
  1045. * changes
  1046. * @dev: The devfreq user device. (parent of devfreq)
  1047. * @devfreq: The devfreq object.
  1048. */
  1049. int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
  1050. {
  1051. struct srcu_notifier_head *nh;
  1052. int ret = 0;
  1053. rcu_read_lock();
  1054. nh = dev_pm_opp_get_notifier(dev);
  1055. if (IS_ERR(nh))
  1056. ret = PTR_ERR(nh);
  1057. rcu_read_unlock();
  1058. if (!ret)
  1059. ret = srcu_notifier_chain_register(nh, &devfreq->nb);
  1060. return ret;
  1061. }
  1062. EXPORT_SYMBOL(devfreq_register_opp_notifier);
  1063. /**
  1064. * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq
  1065. * notified for any changes in the OPP
  1066. * availability changes anymore.
  1067. * @dev: The devfreq user device. (parent of devfreq)
  1068. * @devfreq: The devfreq object.
  1069. *
  1070. * At exit() callback of devfreq_dev_profile, this must be included if
  1071. * devfreq_recommended_opp is used.
  1072. */
  1073. int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
  1074. {
  1075. struct srcu_notifier_head *nh;
  1076. int ret = 0;
  1077. rcu_read_lock();
  1078. nh = dev_pm_opp_get_notifier(dev);
  1079. if (IS_ERR(nh))
  1080. ret = PTR_ERR(nh);
  1081. rcu_read_unlock();
  1082. if (!ret)
  1083. ret = srcu_notifier_chain_unregister(nh, &devfreq->nb);
  1084. return ret;
  1085. }
  1086. EXPORT_SYMBOL(devfreq_unregister_opp_notifier);
  1087. static void devm_devfreq_opp_release(struct device *dev, void *res)
  1088. {
  1089. devfreq_unregister_opp_notifier(dev, *(struct devfreq **)res);
  1090. }
  1091. /**
  1092. * devm_ devfreq_register_opp_notifier()
  1093. * - Resource-managed devfreq_register_opp_notifier()
  1094. * @dev: The devfreq user device. (parent of devfreq)
  1095. * @devfreq: The devfreq object.
  1096. */
  1097. int devm_devfreq_register_opp_notifier(struct device *dev,
  1098. struct devfreq *devfreq)
  1099. {
  1100. struct devfreq **ptr;
  1101. int ret;
  1102. ptr = devres_alloc(devm_devfreq_opp_release, sizeof(*ptr), GFP_KERNEL);
  1103. if (!ptr)
  1104. return -ENOMEM;
  1105. ret = devfreq_register_opp_notifier(dev, devfreq);
  1106. if (ret) {
  1107. devres_free(ptr);
  1108. return ret;
  1109. }
  1110. *ptr = devfreq;
  1111. devres_add(dev, ptr);
  1112. return 0;
  1113. }
  1114. EXPORT_SYMBOL(devm_devfreq_register_opp_notifier);
  1115. /**
  1116. * devm_devfreq_unregister_opp_notifier()
  1117. * - Resource-managed devfreq_unregister_opp_notifier()
  1118. * @dev: The devfreq user device. (parent of devfreq)
  1119. * @devfreq: The devfreq object.
  1120. */
  1121. void devm_devfreq_unregister_opp_notifier(struct device *dev,
  1122. struct devfreq *devfreq)
  1123. {
  1124. WARN_ON(devres_release(dev, devm_devfreq_opp_release,
  1125. devm_devfreq_dev_match, devfreq));
  1126. }
  1127. EXPORT_SYMBOL(devm_devfreq_unregister_opp_notifier);
  1128. MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
  1129. MODULE_DESCRIPTION("devfreq class support");
  1130. MODULE_LICENSE("GPL");