arm_big_little.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * ARM big.LITTLE Platforms CPUFreq support
  3. *
  4. * Copyright (C) 2013 ARM Ltd.
  5. * Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com>
  6. *
  7. * Copyright (C) 2013 Linaro.
  8. * Viresh Kumar <viresh.kumar@linaro.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  15. * kind, whether express or implied; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/clk.h>
  21. #include <linux/cpu.h>
  22. #include <linux/cpufreq.h>
  23. #include <linux/cpumask.h>
  24. #include <linux/cpu_cooling.h>
  25. #include <linux/export.h>
  26. #include <linux/module.h>
  27. #include <linux/mutex.h>
  28. #include <linux/of_platform.h>
  29. #include <linux/pm_opp.h>
  30. #include <linux/slab.h>
  31. #include <linux/topology.h>
  32. #include <linux/types.h>
  33. #include "arm_big_little.h"
  34. /* Currently we support only two clusters */
  35. #define A15_CLUSTER 0
  36. #define A7_CLUSTER 1
  37. #define MAX_CLUSTERS 2
  38. #ifdef CONFIG_BL_SWITCHER
  39. #include <asm/bL_switcher.h>
  40. static bool bL_switching_enabled;
  41. #define is_bL_switching_enabled() bL_switching_enabled
  42. #define set_switching_enabled(x) (bL_switching_enabled = (x))
  43. #else
  44. #define is_bL_switching_enabled() false
  45. #define set_switching_enabled(x) do { } while (0)
  46. #define bL_switch_request(...) do { } while (0)
  47. #define bL_switcher_put_enabled() do { } while (0)
  48. #define bL_switcher_get_enabled() do { } while (0)
  49. #endif
  50. #define ACTUAL_FREQ(cluster, freq) ((cluster == A7_CLUSTER) ? freq << 1 : freq)
  51. #define VIRT_FREQ(cluster, freq) ((cluster == A7_CLUSTER) ? freq >> 1 : freq)
  52. static struct thermal_cooling_device *cdev[MAX_CLUSTERS];
  53. static struct cpufreq_arm_bL_ops *arm_bL_ops;
  54. static struct clk *clk[MAX_CLUSTERS];
  55. static struct cpufreq_frequency_table *freq_table[MAX_CLUSTERS + 1];
  56. static atomic_t cluster_usage[MAX_CLUSTERS + 1];
  57. static unsigned int clk_big_min; /* (Big) clock frequencies */
  58. static unsigned int clk_little_max; /* Maximum clock frequency (Little) */
  59. static DEFINE_PER_CPU(unsigned int, physical_cluster);
  60. static DEFINE_PER_CPU(unsigned int, cpu_last_req_freq);
  61. static struct mutex cluster_lock[MAX_CLUSTERS];
  62. static inline int raw_cpu_to_cluster(int cpu)
  63. {
  64. return topology_physical_package_id(cpu);
  65. }
  66. static inline int cpu_to_cluster(int cpu)
  67. {
  68. return is_bL_switching_enabled() ?
  69. MAX_CLUSTERS : raw_cpu_to_cluster(cpu);
  70. }
  71. static unsigned int find_cluster_maxfreq(int cluster)
  72. {
  73. int j;
  74. u32 max_freq = 0, cpu_freq;
  75. for_each_online_cpu(j) {
  76. cpu_freq = per_cpu(cpu_last_req_freq, j);
  77. if ((cluster == per_cpu(physical_cluster, j)) &&
  78. (max_freq < cpu_freq))
  79. max_freq = cpu_freq;
  80. }
  81. pr_debug("%s: cluster: %d, max freq: %d\n", __func__, cluster,
  82. max_freq);
  83. return max_freq;
  84. }
  85. static unsigned int clk_get_cpu_rate(unsigned int cpu)
  86. {
  87. u32 cur_cluster = per_cpu(physical_cluster, cpu);
  88. u32 rate = clk_get_rate(clk[cur_cluster]) / 1000;
  89. /* For switcher we use virtual A7 clock rates */
  90. if (is_bL_switching_enabled())
  91. rate = VIRT_FREQ(cur_cluster, rate);
  92. pr_debug("%s: cpu: %d, cluster: %d, freq: %u\n", __func__, cpu,
  93. cur_cluster, rate);
  94. return rate;
  95. }
  96. static unsigned int bL_cpufreq_get_rate(unsigned int cpu)
  97. {
  98. if (is_bL_switching_enabled()) {
  99. pr_debug("%s: freq: %d\n", __func__, per_cpu(cpu_last_req_freq,
  100. cpu));
  101. return per_cpu(cpu_last_req_freq, cpu);
  102. } else {
  103. return clk_get_cpu_rate(cpu);
  104. }
  105. }
  106. static unsigned int
  107. bL_cpufreq_set_rate(u32 cpu, u32 old_cluster, u32 new_cluster, u32 rate)
  108. {
  109. u32 new_rate, prev_rate;
  110. int ret;
  111. bool bLs = is_bL_switching_enabled();
  112. mutex_lock(&cluster_lock[new_cluster]);
  113. if (bLs) {
  114. prev_rate = per_cpu(cpu_last_req_freq, cpu);
  115. per_cpu(cpu_last_req_freq, cpu) = rate;
  116. per_cpu(physical_cluster, cpu) = new_cluster;
  117. new_rate = find_cluster_maxfreq(new_cluster);
  118. new_rate = ACTUAL_FREQ(new_cluster, new_rate);
  119. } else {
  120. new_rate = rate;
  121. }
  122. pr_debug("%s: cpu: %d, old cluster: %d, new cluster: %d, freq: %d\n",
  123. __func__, cpu, old_cluster, new_cluster, new_rate);
  124. ret = clk_set_rate(clk[new_cluster], new_rate * 1000);
  125. if (!ret) {
  126. /*
  127. * FIXME: clk_set_rate hasn't returned an error here however it
  128. * may be that clk_change_rate failed due to hardware or
  129. * firmware issues and wasn't able to report that due to the
  130. * current design of the clk core layer. To work around this
  131. * problem we will read back the clock rate and check it is
  132. * correct. This needs to be removed once clk core is fixed.
  133. */
  134. if (clk_get_rate(clk[new_cluster]) != new_rate * 1000)
  135. ret = -EIO;
  136. }
  137. if (WARN_ON(ret)) {
  138. pr_err("clk_set_rate failed: %d, new cluster: %d\n", ret,
  139. new_cluster);
  140. if (bLs) {
  141. per_cpu(cpu_last_req_freq, cpu) = prev_rate;
  142. per_cpu(physical_cluster, cpu) = old_cluster;
  143. }
  144. mutex_unlock(&cluster_lock[new_cluster]);
  145. return ret;
  146. }
  147. mutex_unlock(&cluster_lock[new_cluster]);
  148. /* Recalc freq for old cluster when switching clusters */
  149. if (old_cluster != new_cluster) {
  150. pr_debug("%s: cpu: %d, old cluster: %d, new cluster: %d\n",
  151. __func__, cpu, old_cluster, new_cluster);
  152. /* Switch cluster */
  153. bL_switch_request(cpu, new_cluster);
  154. mutex_lock(&cluster_lock[old_cluster]);
  155. /* Set freq of old cluster if there are cpus left on it */
  156. new_rate = find_cluster_maxfreq(old_cluster);
  157. new_rate = ACTUAL_FREQ(old_cluster, new_rate);
  158. if (new_rate) {
  159. pr_debug("%s: Updating rate of old cluster: %d, to freq: %d\n",
  160. __func__, old_cluster, new_rate);
  161. if (clk_set_rate(clk[old_cluster], new_rate * 1000))
  162. pr_err("%s: clk_set_rate failed: %d, old cluster: %d\n",
  163. __func__, ret, old_cluster);
  164. }
  165. mutex_unlock(&cluster_lock[old_cluster]);
  166. }
  167. return 0;
  168. }
  169. /* Set clock frequency */
  170. static int bL_cpufreq_set_target(struct cpufreq_policy *policy,
  171. unsigned int index)
  172. {
  173. u32 cpu = policy->cpu, cur_cluster, new_cluster, actual_cluster;
  174. unsigned int freqs_new;
  175. cur_cluster = cpu_to_cluster(cpu);
  176. new_cluster = actual_cluster = per_cpu(physical_cluster, cpu);
  177. freqs_new = freq_table[cur_cluster][index].frequency;
  178. if (is_bL_switching_enabled()) {
  179. if ((actual_cluster == A15_CLUSTER) &&
  180. (freqs_new < clk_big_min)) {
  181. new_cluster = A7_CLUSTER;
  182. } else if ((actual_cluster == A7_CLUSTER) &&
  183. (freqs_new > clk_little_max)) {
  184. new_cluster = A15_CLUSTER;
  185. }
  186. }
  187. return bL_cpufreq_set_rate(cpu, actual_cluster, new_cluster, freqs_new);
  188. }
  189. static inline u32 get_table_count(struct cpufreq_frequency_table *table)
  190. {
  191. int count;
  192. for (count = 0; table[count].frequency != CPUFREQ_TABLE_END; count++)
  193. ;
  194. return count;
  195. }
  196. /* get the minimum frequency in the cpufreq_frequency_table */
  197. static inline u32 get_table_min(struct cpufreq_frequency_table *table)
  198. {
  199. struct cpufreq_frequency_table *pos;
  200. uint32_t min_freq = ~0;
  201. cpufreq_for_each_entry(pos, table)
  202. if (pos->frequency < min_freq)
  203. min_freq = pos->frequency;
  204. return min_freq;
  205. }
  206. /* get the maximum frequency in the cpufreq_frequency_table */
  207. static inline u32 get_table_max(struct cpufreq_frequency_table *table)
  208. {
  209. struct cpufreq_frequency_table *pos;
  210. uint32_t max_freq = 0;
  211. cpufreq_for_each_entry(pos, table)
  212. if (pos->frequency > max_freq)
  213. max_freq = pos->frequency;
  214. return max_freq;
  215. }
  216. static int merge_cluster_tables(void)
  217. {
  218. int i, j, k = 0, count = 1;
  219. struct cpufreq_frequency_table *table;
  220. for (i = 0; i < MAX_CLUSTERS; i++)
  221. count += get_table_count(freq_table[i]);
  222. table = kzalloc(sizeof(*table) * count, GFP_KERNEL);
  223. if (!table)
  224. return -ENOMEM;
  225. freq_table[MAX_CLUSTERS] = table;
  226. /* Add in reverse order to get freqs in increasing order */
  227. for (i = MAX_CLUSTERS - 1; i >= 0; i--) {
  228. for (j = 0; freq_table[i][j].frequency != CPUFREQ_TABLE_END;
  229. j++) {
  230. table[k].frequency = VIRT_FREQ(i,
  231. freq_table[i][j].frequency);
  232. pr_debug("%s: index: %d, freq: %d\n", __func__, k,
  233. table[k].frequency);
  234. k++;
  235. }
  236. }
  237. table[k].driver_data = k;
  238. table[k].frequency = CPUFREQ_TABLE_END;
  239. pr_debug("%s: End, table: %p, count: %d\n", __func__, table, k);
  240. return 0;
  241. }
  242. static void _put_cluster_clk_and_freq_table(struct device *cpu_dev)
  243. {
  244. u32 cluster = raw_cpu_to_cluster(cpu_dev->id);
  245. if (!freq_table[cluster])
  246. return;
  247. clk_put(clk[cluster]);
  248. dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table[cluster]);
  249. if (arm_bL_ops->free_opp_table)
  250. arm_bL_ops->free_opp_table(cpu_dev);
  251. dev_dbg(cpu_dev, "%s: cluster: %d\n", __func__, cluster);
  252. }
  253. static void put_cluster_clk_and_freq_table(struct device *cpu_dev)
  254. {
  255. u32 cluster = cpu_to_cluster(cpu_dev->id);
  256. int i;
  257. if (atomic_dec_return(&cluster_usage[cluster]))
  258. return;
  259. if (cluster < MAX_CLUSTERS)
  260. return _put_cluster_clk_and_freq_table(cpu_dev);
  261. for_each_present_cpu(i) {
  262. struct device *cdev = get_cpu_device(i);
  263. if (!cdev) {
  264. pr_err("%s: failed to get cpu%d device\n", __func__, i);
  265. return;
  266. }
  267. _put_cluster_clk_and_freq_table(cdev);
  268. }
  269. /* free virtual table */
  270. kfree(freq_table[cluster]);
  271. }
  272. static int _get_cluster_clk_and_freq_table(struct device *cpu_dev)
  273. {
  274. u32 cluster = raw_cpu_to_cluster(cpu_dev->id);
  275. int ret;
  276. if (freq_table[cluster])
  277. return 0;
  278. ret = arm_bL_ops->init_opp_table(cpu_dev);
  279. if (ret) {
  280. dev_err(cpu_dev, "%s: init_opp_table failed, cpu: %d, err: %d\n",
  281. __func__, cpu_dev->id, ret);
  282. goto out;
  283. }
  284. ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table[cluster]);
  285. if (ret) {
  286. dev_err(cpu_dev, "%s: failed to init cpufreq table, cpu: %d, err: %d\n",
  287. __func__, cpu_dev->id, ret);
  288. goto free_opp_table;
  289. }
  290. clk[cluster] = clk_get(cpu_dev, NULL);
  291. if (!IS_ERR(clk[cluster])) {
  292. dev_dbg(cpu_dev, "%s: clk: %p & freq table: %p, cluster: %d\n",
  293. __func__, clk[cluster], freq_table[cluster],
  294. cluster);
  295. return 0;
  296. }
  297. dev_err(cpu_dev, "%s: Failed to get clk for cpu: %d, cluster: %d\n",
  298. __func__, cpu_dev->id, cluster);
  299. ret = PTR_ERR(clk[cluster]);
  300. dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table[cluster]);
  301. free_opp_table:
  302. if (arm_bL_ops->free_opp_table)
  303. arm_bL_ops->free_opp_table(cpu_dev);
  304. out:
  305. dev_err(cpu_dev, "%s: Failed to get data for cluster: %d\n", __func__,
  306. cluster);
  307. return ret;
  308. }
  309. static int get_cluster_clk_and_freq_table(struct device *cpu_dev)
  310. {
  311. u32 cluster = cpu_to_cluster(cpu_dev->id);
  312. int i, ret;
  313. if (atomic_inc_return(&cluster_usage[cluster]) != 1)
  314. return 0;
  315. if (cluster < MAX_CLUSTERS) {
  316. ret = _get_cluster_clk_and_freq_table(cpu_dev);
  317. if (ret)
  318. atomic_dec(&cluster_usage[cluster]);
  319. return ret;
  320. }
  321. /*
  322. * Get data for all clusters and fill virtual cluster with a merge of
  323. * both
  324. */
  325. for_each_present_cpu(i) {
  326. struct device *cdev = get_cpu_device(i);
  327. if (!cdev) {
  328. pr_err("%s: failed to get cpu%d device\n", __func__, i);
  329. return -ENODEV;
  330. }
  331. ret = _get_cluster_clk_and_freq_table(cdev);
  332. if (ret)
  333. goto put_clusters;
  334. }
  335. ret = merge_cluster_tables();
  336. if (ret)
  337. goto put_clusters;
  338. /* Assuming 2 cluster, set clk_big_min and clk_little_max */
  339. clk_big_min = get_table_min(freq_table[0]);
  340. clk_little_max = VIRT_FREQ(1, get_table_max(freq_table[1]));
  341. pr_debug("%s: cluster: %d, clk_big_min: %d, clk_little_max: %d\n",
  342. __func__, cluster, clk_big_min, clk_little_max);
  343. return 0;
  344. put_clusters:
  345. for_each_present_cpu(i) {
  346. struct device *cdev = get_cpu_device(i);
  347. if (!cdev) {
  348. pr_err("%s: failed to get cpu%d device\n", __func__, i);
  349. return -ENODEV;
  350. }
  351. _put_cluster_clk_and_freq_table(cdev);
  352. }
  353. atomic_dec(&cluster_usage[cluster]);
  354. return ret;
  355. }
  356. /* Per-CPU initialization */
  357. static int bL_cpufreq_init(struct cpufreq_policy *policy)
  358. {
  359. u32 cur_cluster = cpu_to_cluster(policy->cpu);
  360. struct device *cpu_dev;
  361. int ret;
  362. cpu_dev = get_cpu_device(policy->cpu);
  363. if (!cpu_dev) {
  364. pr_err("%s: failed to get cpu%d device\n", __func__,
  365. policy->cpu);
  366. return -ENODEV;
  367. }
  368. ret = get_cluster_clk_and_freq_table(cpu_dev);
  369. if (ret)
  370. return ret;
  371. ret = cpufreq_table_validate_and_show(policy, freq_table[cur_cluster]);
  372. if (ret) {
  373. dev_err(cpu_dev, "CPU %d, cluster: %d invalid freq table\n",
  374. policy->cpu, cur_cluster);
  375. put_cluster_clk_and_freq_table(cpu_dev);
  376. return ret;
  377. }
  378. if (cur_cluster < MAX_CLUSTERS) {
  379. int cpu;
  380. cpumask_copy(policy->cpus, topology_core_cpumask(policy->cpu));
  381. for_each_cpu(cpu, policy->cpus)
  382. per_cpu(physical_cluster, cpu) = cur_cluster;
  383. } else {
  384. /* Assumption: during init, we are always running on A15 */
  385. per_cpu(physical_cluster, policy->cpu) = A15_CLUSTER;
  386. }
  387. if (arm_bL_ops->get_transition_latency)
  388. policy->cpuinfo.transition_latency =
  389. arm_bL_ops->get_transition_latency(cpu_dev);
  390. else
  391. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  392. if (is_bL_switching_enabled())
  393. per_cpu(cpu_last_req_freq, policy->cpu) = clk_get_cpu_rate(policy->cpu);
  394. dev_info(cpu_dev, "%s: CPU %d initialized\n", __func__, policy->cpu);
  395. return 0;
  396. }
  397. static int bL_cpufreq_exit(struct cpufreq_policy *policy)
  398. {
  399. struct device *cpu_dev;
  400. int cur_cluster = cpu_to_cluster(policy->cpu);
  401. if (cur_cluster < MAX_CLUSTERS) {
  402. cpufreq_cooling_unregister(cdev[cur_cluster]);
  403. cdev[cur_cluster] = NULL;
  404. }
  405. cpu_dev = get_cpu_device(policy->cpu);
  406. if (!cpu_dev) {
  407. pr_err("%s: failed to get cpu%d device\n", __func__,
  408. policy->cpu);
  409. return -ENODEV;
  410. }
  411. put_cluster_clk_and_freq_table(cpu_dev);
  412. dev_dbg(cpu_dev, "%s: Exited, cpu: %d\n", __func__, policy->cpu);
  413. return 0;
  414. }
  415. static void bL_cpufreq_ready(struct cpufreq_policy *policy)
  416. {
  417. struct device *cpu_dev = get_cpu_device(policy->cpu);
  418. int cur_cluster = cpu_to_cluster(policy->cpu);
  419. struct device_node *np;
  420. /* Do not register a cpu_cooling device if we are in IKS mode */
  421. if (cur_cluster >= MAX_CLUSTERS)
  422. return;
  423. np = of_node_get(cpu_dev->of_node);
  424. if (WARN_ON(!np))
  425. return;
  426. if (of_find_property(np, "#cooling-cells", NULL)) {
  427. u32 power_coefficient = 0;
  428. of_property_read_u32(np, "dynamic-power-coefficient",
  429. &power_coefficient);
  430. cdev[cur_cluster] = of_cpufreq_power_cooling_register(np,
  431. policy->related_cpus, power_coefficient, NULL);
  432. if (IS_ERR(cdev[cur_cluster])) {
  433. dev_err(cpu_dev,
  434. "running cpufreq without cooling device: %ld\n",
  435. PTR_ERR(cdev[cur_cluster]));
  436. cdev[cur_cluster] = NULL;
  437. }
  438. }
  439. of_node_put(np);
  440. }
  441. static struct cpufreq_driver bL_cpufreq_driver = {
  442. .name = "arm-big-little",
  443. .flags = CPUFREQ_STICKY |
  444. CPUFREQ_HAVE_GOVERNOR_PER_POLICY |
  445. CPUFREQ_NEED_INITIAL_FREQ_CHECK,
  446. .verify = cpufreq_generic_frequency_table_verify,
  447. .target_index = bL_cpufreq_set_target,
  448. .get = bL_cpufreq_get_rate,
  449. .init = bL_cpufreq_init,
  450. .exit = bL_cpufreq_exit,
  451. .ready = bL_cpufreq_ready,
  452. .attr = cpufreq_generic_attr,
  453. };
  454. #ifdef CONFIG_BL_SWITCHER
  455. static int bL_cpufreq_switcher_notifier(struct notifier_block *nfb,
  456. unsigned long action, void *_arg)
  457. {
  458. pr_debug("%s: action: %ld\n", __func__, action);
  459. switch (action) {
  460. case BL_NOTIFY_PRE_ENABLE:
  461. case BL_NOTIFY_PRE_DISABLE:
  462. cpufreq_unregister_driver(&bL_cpufreq_driver);
  463. break;
  464. case BL_NOTIFY_POST_ENABLE:
  465. set_switching_enabled(true);
  466. cpufreq_register_driver(&bL_cpufreq_driver);
  467. break;
  468. case BL_NOTIFY_POST_DISABLE:
  469. set_switching_enabled(false);
  470. cpufreq_register_driver(&bL_cpufreq_driver);
  471. break;
  472. default:
  473. return NOTIFY_DONE;
  474. }
  475. return NOTIFY_OK;
  476. }
  477. static struct notifier_block bL_switcher_notifier = {
  478. .notifier_call = bL_cpufreq_switcher_notifier,
  479. };
  480. static int __bLs_register_notifier(void)
  481. {
  482. return bL_switcher_register_notifier(&bL_switcher_notifier);
  483. }
  484. static int __bLs_unregister_notifier(void)
  485. {
  486. return bL_switcher_unregister_notifier(&bL_switcher_notifier);
  487. }
  488. #else
  489. static int __bLs_register_notifier(void) { return 0; }
  490. static int __bLs_unregister_notifier(void) { return 0; }
  491. #endif
  492. int bL_cpufreq_register(struct cpufreq_arm_bL_ops *ops)
  493. {
  494. int ret, i;
  495. if (arm_bL_ops) {
  496. pr_debug("%s: Already registered: %s, exiting\n", __func__,
  497. arm_bL_ops->name);
  498. return -EBUSY;
  499. }
  500. if (!ops || !strlen(ops->name) || !ops->init_opp_table) {
  501. pr_err("%s: Invalid arm_bL_ops, exiting\n", __func__);
  502. return -ENODEV;
  503. }
  504. arm_bL_ops = ops;
  505. set_switching_enabled(bL_switcher_get_enabled());
  506. for (i = 0; i < MAX_CLUSTERS; i++)
  507. mutex_init(&cluster_lock[i]);
  508. ret = cpufreq_register_driver(&bL_cpufreq_driver);
  509. if (ret) {
  510. pr_info("%s: Failed registering platform driver: %s, err: %d\n",
  511. __func__, ops->name, ret);
  512. arm_bL_ops = NULL;
  513. } else {
  514. ret = __bLs_register_notifier();
  515. if (ret) {
  516. cpufreq_unregister_driver(&bL_cpufreq_driver);
  517. arm_bL_ops = NULL;
  518. } else {
  519. pr_info("%s: Registered platform driver: %s\n",
  520. __func__, ops->name);
  521. }
  522. }
  523. bL_switcher_put_enabled();
  524. return ret;
  525. }
  526. EXPORT_SYMBOL_GPL(bL_cpufreq_register);
  527. void bL_cpufreq_unregister(struct cpufreq_arm_bL_ops *ops)
  528. {
  529. if (arm_bL_ops != ops) {
  530. pr_err("%s: Registered with: %s, can't unregister, exiting\n",
  531. __func__, arm_bL_ops->name);
  532. return;
  533. }
  534. bL_switcher_get_enabled();
  535. __bLs_unregister_notifier();
  536. cpufreq_unregister_driver(&bL_cpufreq_driver);
  537. bL_switcher_put_enabled();
  538. pr_info("%s: Un-registered platform driver: %s\n", __func__,
  539. arm_bL_ops->name);
  540. arm_bL_ops = NULL;
  541. }
  542. EXPORT_SYMBOL_GPL(bL_cpufreq_unregister);
  543. MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>");
  544. MODULE_DESCRIPTION("Generic ARM big LITTLE cpufreq driver");
  545. MODULE_LICENSE("GPL v2");