opp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * Generic OPP Interface
  3. *
  4. * Copyright (C) 2009-2010 Texas Instruments Incorporated.
  5. * Nishanth Menon
  6. * Romit Dasgupta
  7. * Kevin Hilman
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/err.h>
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/cpufreq.h>
  19. #include <linux/list.h>
  20. #include <linux/rculist.h>
  21. #include <linux/rcupdate.h>
  22. #include <linux/opp.h>
  23. /*
  24. * Internal data structure organization with the OPP layer library is as
  25. * follows:
  26. * dev_opp_list (root)
  27. * |- device 1 (represents voltage domain 1)
  28. * | |- opp 1 (availability, freq, voltage)
  29. * | |- opp 2 ..
  30. * ... ...
  31. * | `- opp n ..
  32. * |- device 2 (represents the next voltage domain)
  33. * ...
  34. * `- device m (represents mth voltage domain)
  35. * device 1, 2.. are represented by dev_opp structure while each opp
  36. * is represented by the opp structure.
  37. */
  38. /**
  39. * struct opp - Generic OPP description structure
  40. * @node: opp list node. The nodes are maintained throughout the lifetime
  41. * of boot. It is expected only an optimal set of OPPs are
  42. * added to the library by the SoC framework.
  43. * RCU usage: opp list is traversed with RCU locks. node
  44. * modification is possible realtime, hence the modifications
  45. * are protected by the dev_opp_list_lock for integrity.
  46. * IMPORTANT: the opp nodes should be maintained in increasing
  47. * order.
  48. * @available: true/false - marks if this OPP as available or not
  49. * @rate: Frequency in hertz
  50. * @u_volt: Nominal voltage in microvolts corresponding to this OPP
  51. * @dev_opp: points back to the device_opp struct this opp belongs to
  52. *
  53. * This structure stores the OPP information for a given device.
  54. */
  55. struct opp {
  56. struct list_head node;
  57. bool available;
  58. unsigned long rate;
  59. unsigned long u_volt;
  60. struct device_opp *dev_opp;
  61. };
  62. /**
  63. * struct device_opp - Device opp structure
  64. * @node: list node - contains the devices with OPPs that
  65. * have been registered. Nodes once added are not modified in this
  66. * list.
  67. * RCU usage: nodes are not modified in the list of device_opp,
  68. * however addition is possible and is secured by dev_opp_list_lock
  69. * @dev: device pointer
  70. * @opp_list: list of opps
  71. *
  72. * This is an internal data structure maintaining the link to opps attached to
  73. * a device. This structure is not meant to be shared to users as it is
  74. * meant for book keeping and private to OPP library
  75. */
  76. struct device_opp {
  77. struct list_head node;
  78. struct device *dev;
  79. struct list_head opp_list;
  80. };
  81. /*
  82. * The root of the list of all devices. All device_opp structures branch off
  83. * from here, with each device_opp containing the list of opp it supports in
  84. * various states of availability.
  85. */
  86. static LIST_HEAD(dev_opp_list);
  87. /* Lock to allow exclusive modification to the device and opp lists */
  88. static DEFINE_MUTEX(dev_opp_list_lock);
  89. /**
  90. * find_device_opp() - find device_opp struct using device pointer
  91. * @dev: device pointer used to lookup device OPPs
  92. *
  93. * Search list of device OPPs for one containing matching device. Does a RCU
  94. * reader operation to grab the pointer needed.
  95. *
  96. * Returns pointer to 'struct device_opp' if found, otherwise -ENODEV or
  97. * -EINVAL based on type of error.
  98. *
  99. * Locking: This function must be called under rcu_read_lock(). device_opp
  100. * is a RCU protected pointer. This means that device_opp is valid as long
  101. * as we are under RCU lock.
  102. */
  103. static struct device_opp *find_device_opp(struct device *dev)
  104. {
  105. struct device_opp *tmp_dev_opp, *dev_opp = ERR_PTR(-ENODEV);
  106. if (unlikely(IS_ERR_OR_NULL(dev))) {
  107. pr_err("%s: Invalid parameters\n", __func__);
  108. return ERR_PTR(-EINVAL);
  109. }
  110. list_for_each_entry_rcu(tmp_dev_opp, &dev_opp_list, node) {
  111. if (tmp_dev_opp->dev == dev) {
  112. dev_opp = tmp_dev_opp;
  113. break;
  114. }
  115. }
  116. return dev_opp;
  117. }
  118. /**
  119. * opp_get_voltage() - Gets the voltage corresponding to an available opp
  120. * @opp: opp for which voltage has to be returned for
  121. *
  122. * Return voltage in micro volt corresponding to the opp, else
  123. * return 0
  124. *
  125. * Locking: This function must be called under rcu_read_lock(). opp is a rcu
  126. * protected pointer. This means that opp which could have been fetched by
  127. * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are
  128. * under RCU lock. The pointer returned by the opp_find_freq family must be
  129. * used in the same section as the usage of this function with the pointer
  130. * prior to unlocking with rcu_read_unlock() to maintain the integrity of the
  131. * pointer.
  132. */
  133. unsigned long opp_get_voltage(struct opp *opp)
  134. {
  135. struct opp *tmp_opp;
  136. unsigned long v = 0;
  137. tmp_opp = rcu_dereference(opp);
  138. if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
  139. pr_err("%s: Invalid parameters\n", __func__);
  140. else
  141. v = tmp_opp->u_volt;
  142. return v;
  143. }
  144. /**
  145. * opp_get_freq() - Gets the frequency corresponding to an available opp
  146. * @opp: opp for which frequency has to be returned for
  147. *
  148. * Return frequency in hertz corresponding to the opp, else
  149. * return 0
  150. *
  151. * Locking: This function must be called under rcu_read_lock(). opp is a rcu
  152. * protected pointer. This means that opp which could have been fetched by
  153. * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are
  154. * under RCU lock. The pointer returned by the opp_find_freq family must be
  155. * used in the same section as the usage of this function with the pointer
  156. * prior to unlocking with rcu_read_unlock() to maintain the integrity of the
  157. * pointer.
  158. */
  159. unsigned long opp_get_freq(struct opp *opp)
  160. {
  161. struct opp *tmp_opp;
  162. unsigned long f = 0;
  163. tmp_opp = rcu_dereference(opp);
  164. if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
  165. pr_err("%s: Invalid parameters\n", __func__);
  166. else
  167. f = tmp_opp->rate;
  168. return f;
  169. }
  170. /**
  171. * opp_get_opp_count() - Get number of opps available in the opp list
  172. * @dev: device for which we do this operation
  173. *
  174. * This function returns the number of available opps if there are any,
  175. * else returns 0 if none or the corresponding error value.
  176. *
  177. * Locking: This function must be called under rcu_read_lock(). This function
  178. * internally references two RCU protected structures: device_opp and opp which
  179. * are safe as long as we are under a common RCU locked section.
  180. */
  181. int opp_get_opp_count(struct device *dev)
  182. {
  183. struct device_opp *dev_opp;
  184. struct opp *temp_opp;
  185. int count = 0;
  186. dev_opp = find_device_opp(dev);
  187. if (IS_ERR(dev_opp)) {
  188. int r = PTR_ERR(dev_opp);
  189. dev_err(dev, "%s: device OPP not found (%d)\n", __func__, r);
  190. return r;
  191. }
  192. list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
  193. if (temp_opp->available)
  194. count++;
  195. }
  196. return count;
  197. }
  198. /**
  199. * opp_find_freq_exact() - search for an exact frequency
  200. * @dev: device for which we do this operation
  201. * @freq: frequency to search for
  202. * @available: true/false - match for available opp
  203. *
  204. * Searches for exact match in the opp list and returns pointer to the matching
  205. * opp if found, else returns ERR_PTR in case of error and should be handled
  206. * using IS_ERR.
  207. *
  208. * Note: available is a modifier for the search. if available=true, then the
  209. * match is for exact matching frequency and is available in the stored OPP
  210. * table. if false, the match is for exact frequency which is not available.
  211. *
  212. * This provides a mechanism to enable an opp which is not available currently
  213. * or the opposite as well.
  214. *
  215. * Locking: This function must be called under rcu_read_lock(). opp is a rcu
  216. * protected pointer. The reason for the same is that the opp pointer which is
  217. * returned will remain valid for use with opp_get_{voltage, freq} only while
  218. * under the locked area. The pointer returned must be used prior to unlocking
  219. * with rcu_read_unlock() to maintain the integrity of the pointer.
  220. */
  221. struct opp *opp_find_freq_exact(struct device *dev, unsigned long freq,
  222. bool available)
  223. {
  224. struct device_opp *dev_opp;
  225. struct opp *temp_opp, *opp = ERR_PTR(-ENODEV);
  226. dev_opp = find_device_opp(dev);
  227. if (IS_ERR(dev_opp)) {
  228. int r = PTR_ERR(dev_opp);
  229. dev_err(dev, "%s: device OPP not found (%d)\n", __func__, r);
  230. return ERR_PTR(r);
  231. }
  232. list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
  233. if (temp_opp->available == available &&
  234. temp_opp->rate == freq) {
  235. opp = temp_opp;
  236. break;
  237. }
  238. }
  239. return opp;
  240. }
  241. /**
  242. * opp_find_freq_ceil() - Search for an rounded ceil freq
  243. * @dev: device for which we do this operation
  244. * @freq: Start frequency
  245. *
  246. * Search for the matching ceil *available* OPP from a starting freq
  247. * for a device.
  248. *
  249. * Returns matching *opp and refreshes *freq accordingly, else returns
  250. * ERR_PTR in case of error and should be handled using IS_ERR.
  251. *
  252. * Locking: This function must be called under rcu_read_lock(). opp is a rcu
  253. * protected pointer. The reason for the same is that the opp pointer which is
  254. * returned will remain valid for use with opp_get_{voltage, freq} only while
  255. * under the locked area. The pointer returned must be used prior to unlocking
  256. * with rcu_read_unlock() to maintain the integrity of the pointer.
  257. */
  258. struct opp *opp_find_freq_ceil(struct device *dev, unsigned long *freq)
  259. {
  260. struct device_opp *dev_opp;
  261. struct opp *temp_opp, *opp = ERR_PTR(-ENODEV);
  262. if (!dev || !freq) {
  263. dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
  264. return ERR_PTR(-EINVAL);
  265. }
  266. dev_opp = find_device_opp(dev);
  267. if (IS_ERR(dev_opp))
  268. return opp;
  269. list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
  270. if (temp_opp->available && temp_opp->rate >= *freq) {
  271. opp = temp_opp;
  272. *freq = opp->rate;
  273. break;
  274. }
  275. }
  276. return opp;
  277. }
  278. /**
  279. * opp_find_freq_floor() - Search for a rounded floor freq
  280. * @dev: device for which we do this operation
  281. * @freq: Start frequency
  282. *
  283. * Search for the matching floor *available* OPP from a starting freq
  284. * for a device.
  285. *
  286. * Returns matching *opp and refreshes *freq accordingly, else returns
  287. * ERR_PTR in case of error and should be handled using IS_ERR.
  288. *
  289. * Locking: This function must be called under rcu_read_lock(). opp is a rcu
  290. * protected pointer. The reason for the same is that the opp pointer which is
  291. * returned will remain valid for use with opp_get_{voltage, freq} only while
  292. * under the locked area. The pointer returned must be used prior to unlocking
  293. * with rcu_read_unlock() to maintain the integrity of the pointer.
  294. */
  295. struct opp *opp_find_freq_floor(struct device *dev, unsigned long *freq)
  296. {
  297. struct device_opp *dev_opp;
  298. struct opp *temp_opp, *opp = ERR_PTR(-ENODEV);
  299. if (!dev || !freq) {
  300. dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
  301. return ERR_PTR(-EINVAL);
  302. }
  303. dev_opp = find_device_opp(dev);
  304. if (IS_ERR(dev_opp))
  305. return opp;
  306. list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
  307. if (temp_opp->available) {
  308. /* go to the next node, before choosing prev */
  309. if (temp_opp->rate > *freq)
  310. break;
  311. else
  312. opp = temp_opp;
  313. }
  314. }
  315. if (!IS_ERR(opp))
  316. *freq = opp->rate;
  317. return opp;
  318. }
  319. /**
  320. * opp_add() - Add an OPP table from a table definitions
  321. * @dev: device for which we do this operation
  322. * @freq: Frequency in Hz for this OPP
  323. * @u_volt: Voltage in uVolts for this OPP
  324. *
  325. * This function adds an opp definition to the opp list and returns status.
  326. * The opp is made available by default and it can be controlled using
  327. * opp_enable/disable functions.
  328. *
  329. * Locking: The internal device_opp and opp structures are RCU protected.
  330. * Hence this function internally uses RCU updater strategy with mutex locks
  331. * to keep the integrity of the internal data structures. Callers should ensure
  332. * that this function is *NOT* called under RCU protection or in contexts where
  333. * mutex cannot be locked.
  334. */
  335. int opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
  336. {
  337. struct device_opp *dev_opp = NULL;
  338. struct opp *opp, *new_opp;
  339. struct list_head *head;
  340. /* allocate new OPP node */
  341. new_opp = kzalloc(sizeof(struct opp), GFP_KERNEL);
  342. if (!new_opp) {
  343. dev_warn(dev, "%s: Unable to create new OPP node\n", __func__);
  344. return -ENOMEM;
  345. }
  346. /* Hold our list modification lock here */
  347. mutex_lock(&dev_opp_list_lock);
  348. /* Check for existing list for 'dev' */
  349. dev_opp = find_device_opp(dev);
  350. if (IS_ERR(dev_opp)) {
  351. /*
  352. * Allocate a new device OPP table. In the infrequent case
  353. * where a new device is needed to be added, we pay this
  354. * penalty.
  355. */
  356. dev_opp = kzalloc(sizeof(struct device_opp), GFP_KERNEL);
  357. if (!dev_opp) {
  358. mutex_unlock(&dev_opp_list_lock);
  359. kfree(new_opp);
  360. dev_warn(dev,
  361. "%s: Unable to create device OPP structure\n",
  362. __func__);
  363. return -ENOMEM;
  364. }
  365. dev_opp->dev = dev;
  366. INIT_LIST_HEAD(&dev_opp->opp_list);
  367. /* Secure the device list modification */
  368. list_add_rcu(&dev_opp->node, &dev_opp_list);
  369. }
  370. /* populate the opp table */
  371. new_opp->dev_opp = dev_opp;
  372. new_opp->rate = freq;
  373. new_opp->u_volt = u_volt;
  374. new_opp->available = true;
  375. /* Insert new OPP in order of increasing frequency */
  376. head = &dev_opp->opp_list;
  377. list_for_each_entry_rcu(opp, &dev_opp->opp_list, node) {
  378. if (new_opp->rate < opp->rate)
  379. break;
  380. else
  381. head = &opp->node;
  382. }
  383. list_add_rcu(&new_opp->node, head);
  384. mutex_unlock(&dev_opp_list_lock);
  385. return 0;
  386. }
  387. /**
  388. * opp_set_availability() - helper to set the availability of an opp
  389. * @dev: device for which we do this operation
  390. * @freq: OPP frequency to modify availability
  391. * @availability_req: availability status requested for this opp
  392. *
  393. * Set the availability of an OPP with an RCU operation, opp_{enable,disable}
  394. * share a common logic which is isolated here.
  395. *
  396. * Returns -EINVAL for bad pointers, -ENOMEM if no memory available for the
  397. * copy operation, returns 0 if no modifcation was done OR modification was
  398. * successful.
  399. *
  400. * Locking: The internal device_opp and opp structures are RCU protected.
  401. * Hence this function internally uses RCU updater strategy with mutex locks to
  402. * keep the integrity of the internal data structures. Callers should ensure
  403. * that this function is *NOT* called under RCU protection or in contexts where
  404. * mutex locking or synchronize_rcu() blocking calls cannot be used.
  405. */
  406. static int opp_set_availability(struct device *dev, unsigned long freq,
  407. bool availability_req)
  408. {
  409. struct device_opp *tmp_dev_opp, *dev_opp = ERR_PTR(-ENODEV);
  410. struct opp *new_opp, *tmp_opp, *opp = ERR_PTR(-ENODEV);
  411. int r = 0;
  412. /* keep the node allocated */
  413. new_opp = kmalloc(sizeof(struct opp), GFP_KERNEL);
  414. if (!new_opp) {
  415. dev_warn(dev, "%s: Unable to create OPP\n", __func__);
  416. return -ENOMEM;
  417. }
  418. mutex_lock(&dev_opp_list_lock);
  419. /* Find the device_opp */
  420. list_for_each_entry(tmp_dev_opp, &dev_opp_list, node) {
  421. if (dev == tmp_dev_opp->dev) {
  422. dev_opp = tmp_dev_opp;
  423. break;
  424. }
  425. }
  426. if (IS_ERR(dev_opp)) {
  427. r = PTR_ERR(dev_opp);
  428. dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
  429. goto unlock;
  430. }
  431. /* Do we have the frequency? */
  432. list_for_each_entry(tmp_opp, &dev_opp->opp_list, node) {
  433. if (tmp_opp->rate == freq) {
  434. opp = tmp_opp;
  435. break;
  436. }
  437. }
  438. if (IS_ERR(opp)) {
  439. r = PTR_ERR(opp);
  440. goto unlock;
  441. }
  442. /* Is update really needed? */
  443. if (opp->available == availability_req)
  444. goto unlock;
  445. /* copy the old data over */
  446. *new_opp = *opp;
  447. /* plug in new node */
  448. new_opp->available = availability_req;
  449. list_replace_rcu(&opp->node, &new_opp->node);
  450. mutex_unlock(&dev_opp_list_lock);
  451. synchronize_rcu();
  452. /* clean up old opp */
  453. new_opp = opp;
  454. goto out;
  455. unlock:
  456. mutex_unlock(&dev_opp_list_lock);
  457. out:
  458. kfree(new_opp);
  459. return r;
  460. }
  461. /**
  462. * opp_enable() - Enable a specific OPP
  463. * @dev: device for which we do this operation
  464. * @freq: OPP frequency to enable
  465. *
  466. * Enables a provided opp. If the operation is valid, this returns 0, else the
  467. * corresponding error value. It is meant to be used for users an OPP available
  468. * after being temporarily made unavailable with opp_disable.
  469. *
  470. * Locking: The internal device_opp and opp structures are RCU protected.
  471. * Hence this function indirectly uses RCU and mutex locks to keep the
  472. * integrity of the internal data structures. Callers should ensure that
  473. * this function is *NOT* called under RCU protection or in contexts where
  474. * mutex locking or synchronize_rcu() blocking calls cannot be used.
  475. */
  476. int opp_enable(struct device *dev, unsigned long freq)
  477. {
  478. return opp_set_availability(dev, freq, true);
  479. }
  480. /**
  481. * opp_disable() - Disable a specific OPP
  482. * @dev: device for which we do this operation
  483. * @freq: OPP frequency to disable
  484. *
  485. * Disables a provided opp. If the operation is valid, this returns
  486. * 0, else the corresponding error value. It is meant to be a temporary
  487. * control by users to make this OPP not available until the circumstances are
  488. * right to make it available again (with a call to opp_enable).
  489. *
  490. * Locking: The internal device_opp and opp structures are RCU protected.
  491. * Hence this function indirectly uses RCU and mutex locks to keep the
  492. * integrity of the internal data structures. Callers should ensure that
  493. * this function is *NOT* called under RCU protection or in contexts where
  494. * mutex locking or synchronize_rcu() blocking calls cannot be used.
  495. */
  496. int opp_disable(struct device *dev, unsigned long freq)
  497. {
  498. return opp_set_availability(dev, freq, false);
  499. }
  500. #ifdef CONFIG_CPU_FREQ
  501. /**
  502. * opp_init_cpufreq_table() - create a cpufreq table for a device
  503. * @dev: device for which we do this operation
  504. * @table: Cpufreq table returned back to caller
  505. *
  506. * Generate a cpufreq table for a provided device- this assumes that the
  507. * opp list is already initialized and ready for usage.
  508. *
  509. * This function allocates required memory for the cpufreq table. It is
  510. * expected that the caller does the required maintenance such as freeing
  511. * the table as required.
  512. *
  513. * Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
  514. * if no memory available for the operation (table is not populated), returns 0
  515. * if successful and table is populated.
  516. *
  517. * WARNING: It is important for the callers to ensure refreshing their copy of
  518. * the table if any of the mentioned functions have been invoked in the interim.
  519. *
  520. * Locking: The internal device_opp and opp structures are RCU protected.
  521. * To simplify the logic, we pretend we are updater and hold relevant mutex here
  522. * Callers should ensure that this function is *NOT* called under RCU protection
  523. * or in contexts where mutex locking cannot be used.
  524. */
  525. int opp_init_cpufreq_table(struct device *dev,
  526. struct cpufreq_frequency_table **table)
  527. {
  528. struct device_opp *dev_opp;
  529. struct opp *opp;
  530. struct cpufreq_frequency_table *freq_table;
  531. int i = 0;
  532. /* Pretend as if I am an updater */
  533. mutex_lock(&dev_opp_list_lock);
  534. dev_opp = find_device_opp(dev);
  535. if (IS_ERR(dev_opp)) {
  536. int r = PTR_ERR(dev_opp);
  537. mutex_unlock(&dev_opp_list_lock);
  538. dev_err(dev, "%s: Device OPP not found (%d)\n", __func__, r);
  539. return r;
  540. }
  541. freq_table = kzalloc(sizeof(struct cpufreq_frequency_table) *
  542. (opp_get_opp_count(dev) + 1), GFP_KERNEL);
  543. if (!freq_table) {
  544. mutex_unlock(&dev_opp_list_lock);
  545. dev_warn(dev, "%s: Unable to allocate frequency table\n",
  546. __func__);
  547. return -ENOMEM;
  548. }
  549. list_for_each_entry(opp, &dev_opp->opp_list, node) {
  550. if (opp->available) {
  551. freq_table[i].index = i;
  552. freq_table[i].frequency = opp->rate / 1000;
  553. i++;
  554. }
  555. }
  556. mutex_unlock(&dev_opp_list_lock);
  557. freq_table[i].index = i;
  558. freq_table[i].frequency = CPUFREQ_TABLE_END;
  559. *table = &freq_table[0];
  560. return 0;
  561. }
  562. /**
  563. * opp_free_cpufreq_table() - free the cpufreq table
  564. * @dev: device for which we do this operation
  565. * @table: table to free
  566. *
  567. * Free up the table allocated by opp_init_cpufreq_table
  568. */
  569. void opp_free_cpufreq_table(struct device *dev,
  570. struct cpufreq_frequency_table **table)
  571. {
  572. if (!table)
  573. return;
  574. kfree(*table);
  575. *table = NULL;
  576. }
  577. #endif /* CONFIG_CPU_FREQ */