acpuclock-8226.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #define pr_fmt(fmt) "%s: " fmt, __func__
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/errno.h>
  17. #include <linux/io.h>
  18. #include <linux/clk.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/regulator/consumer.h>
  21. #include <linux/regulator/cpr-regulator.h>
  22. #include <mach/clk-provider.h>
  23. #include <mach/msm_bus.h>
  24. #include <mach/msm_bus_board.h>
  25. #include <mach/rpm-regulator-smd.h>
  26. #include <mach/socinfo.h>
  27. #include "acpuclock-cortex.h"
  28. #define RCG_CONFIG_UPDATE_BIT BIT(0)
  29. static struct msm_bus_paths bw_level_tbl_8226[] = {
  30. [0] = BW_MBPS(152), /* At least 19 MHz on bus. */
  31. [1] = BW_MBPS(300), /* At least 37.5 MHz on bus. */
  32. [2] = BW_MBPS(400), /* At least 50 MHz on bus. */
  33. [3] = BW_MBPS(800), /* At least 100 MHz on bus. */
  34. [4] = BW_MBPS(1600), /* At least 200 MHz on bus. */
  35. [5] = BW_MBPS(2128), /* At least 266 MHz on bus. */
  36. [6] = BW_MBPS(3200), /* At least 400 MHz on bus. */
  37. [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
  38. };
  39. static struct msm_bus_paths bw_level_tbl_8610[] = {
  40. [0] = BW_MBPS(152), /* At least 19 MHz on bus. */
  41. [1] = BW_MBPS(300), /* At least 37.5 MHz on bus. */
  42. [2] = BW_MBPS(400), /* At least 50 MHz on bus. */
  43. [3] = BW_MBPS(800), /* At least 100 MHz on bus. */
  44. [4] = BW_MBPS(1600), /* At least 200 MHz on bus. */
  45. [5] = BW_MBPS(2664), /* At least 333 MHz on bus. */
  46. };
  47. static struct msm_bus_scale_pdata bus_client_pdata = {
  48. .usecase = bw_level_tbl_8226,
  49. .num_usecases = ARRAY_SIZE(bw_level_tbl_8226),
  50. .active_only = 1,
  51. .name = "acpuclock",
  52. };
  53. static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p1[] = {
  54. { 1, 300000, PLL0, 4, 2, CPR_CORNER_2, 0, 4 },
  55. { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_2, 0, 4 },
  56. { 1, 600000, PLL0, 4, 0, CPR_CORNER_4, 0, 4 },
  57. { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_4, 0, 4 },
  58. { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_5, 0, 7 },
  59. { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_6, 0, 7 },
  60. { 0, 1190400, ACPUPLL, 5, 0, CPR_CORNER_7, 0, 7 },
  61. { 0 }
  62. };
  63. static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p2[] = {
  64. { 1, 300000, PLL0, 4, 2, CPR_CORNER_2, 0, 4 },
  65. { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_2, 0, 4 },
  66. { 1, 600000, PLL0, 4, 0, CPR_CORNER_4, 0, 4 },
  67. { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_4, 0, 4 },
  68. { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_5, 0, 7 },
  69. { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_6, 0, 7 },
  70. { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_7, 0, 7 },
  71. { 0 }
  72. };
  73. static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p4[] = {
  74. { 1, 300000, PLL0, 4, 2, CPR_CORNER_2, 0, 4 },
  75. { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_2, 0, 4 },
  76. { 1, 600000, PLL0, 4, 0, CPR_CORNER_4, 0, 4 },
  77. { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_4, 0, 4 },
  78. { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_5, 0, 7 },
  79. { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_6, 0, 7 },
  80. { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_7, 0, 7 },
  81. { 1, 1305600, ACPUPLL, 5, 0, CPR_CORNER_8, 0, 7 },
  82. { 1, 1344000, ACPUPLL, 5, 0, CPR_CORNER_9, 0, 7 },
  83. { 1, 1401600, ACPUPLL, 5, 0, CPR_CORNER_10, 0, 7 },
  84. { 0 }
  85. };
  86. static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p6[] = {
  87. { 1, 300000, PLL0, 4, 2, CPR_CORNER_2, 0, 4 },
  88. { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_2, 0, 4 },
  89. { 1, 600000, PLL0, 4, 0, CPR_CORNER_4, 0, 4 },
  90. { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_4, 0, 4 },
  91. { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_5, 0, 7 },
  92. { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_6, 0, 7 },
  93. { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_7, 0, 7 },
  94. { 1, 1305600, ACPUPLL, 5, 0, CPR_CORNER_8, 0, 7 },
  95. { 1, 1344000, ACPUPLL, 5, 0, CPR_CORNER_9, 0, 7 },
  96. { 1, 1401600, ACPUPLL, 5, 0, CPR_CORNER_10, 0, 7 },
  97. { 1, 1497600, ACPUPLL, 5, 0, CPR_CORNER_11, 0, 7 },
  98. { 1, 1593600, ACPUPLL, 5, 0, CPR_CORNER_12, 0, 7 },
  99. { 0 }
  100. };
  101. static struct clkctl_acpu_speed acpu_freq_tbl_8610[] = {
  102. { 1, 300000, PLL0, 4, 2, CPR_CORNER_2, 0, 3 },
  103. { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_2, 0, 3 },
  104. { 1, 600000, PLL0, 4, 0, CPR_CORNER_4, 0, 4 },
  105. { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_4, 0, 4 },
  106. { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_12, 0, 5 },
  107. { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_12, 0, 5 },
  108. { 0 }
  109. };
  110. static struct clkctl_acpu_speed *pvs_tables_8226[NUM_SPEED_BIN] = {
  111. [0] = acpu_freq_tbl_8226_1p2,
  112. [6] = acpu_freq_tbl_8226_1p2,
  113. [2] = acpu_freq_tbl_8226_1p4,
  114. [5] = acpu_freq_tbl_8226_1p4,
  115. [4] = acpu_freq_tbl_8226_1p4,
  116. [7] = acpu_freq_tbl_8226_1p4,
  117. [1] = acpu_freq_tbl_8226_1p6,
  118. };
  119. static struct acpuclk_drv_data drv_data = {
  120. .freq_tbl = acpu_freq_tbl_8226_1p1,
  121. .pvs_tables = pvs_tables_8226,
  122. .bus_scale = &bus_client_pdata,
  123. .vdd_max_cpu = CPR_CORNER_12,
  124. .src_clocks = {
  125. [PLL0].name = "gpll0",
  126. [ACPUPLL].name = "a7sspll",
  127. },
  128. .reg_data = {
  129. .cfg_src_mask = BM(10, 8),
  130. .cfg_src_shift = 8,
  131. .cfg_div_mask = BM(4, 0),
  132. .cfg_div_shift = 0,
  133. .update_mask = RCG_CONFIG_UPDATE_BIT,
  134. .poll_mask = RCG_CONFIG_UPDATE_BIT,
  135. },
  136. .power_collapse_khz = 300000,
  137. .wait_for_irq_khz = 300000,
  138. };
  139. static int __init acpuclk_a7_probe(struct platform_device *pdev)
  140. {
  141. struct resource *res;
  142. u32 i;
  143. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base");
  144. if (!res)
  145. return -EINVAL;
  146. drv_data.apcs_rcg_cmd = devm_ioremap(&pdev->dev, res->start,
  147. resource_size(res));
  148. if (!drv_data.apcs_rcg_cmd)
  149. return -ENOMEM;
  150. drv_data.apcs_rcg_config = drv_data.apcs_rcg_cmd + 4;
  151. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pte_efuse");
  152. if (res) {
  153. drv_data.pte_efuse_base = devm_ioremap(&pdev->dev, res->start,
  154. resource_size(res));
  155. if (!drv_data.pte_efuse_base)
  156. return -ENOMEM;
  157. }
  158. drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a7_cpu");
  159. if (IS_ERR(drv_data.vdd_cpu)) {
  160. dev_err(&pdev->dev, "regulator for %s get failed\n", "a7_cpu");
  161. return PTR_ERR(drv_data.vdd_cpu);
  162. }
  163. for (i = 0; i < NUM_SRC; i++) {
  164. if (!drv_data.src_clocks[i].name)
  165. continue;
  166. drv_data.src_clocks[i].clk =
  167. devm_clk_get(&pdev->dev, drv_data.src_clocks[i].name);
  168. if (IS_ERR(drv_data.src_clocks[i].clk)) {
  169. dev_err(&pdev->dev, "Unable to get clock %s\n",
  170. drv_data.src_clocks[i].name);
  171. return -EPROBE_DEFER;
  172. }
  173. }
  174. /* Enable the always on source */
  175. clk_prepare_enable(drv_data.src_clocks[PLL0].clk);
  176. return acpuclk_cortex_init(pdev, &drv_data);
  177. }
  178. static struct of_device_id acpuclk_a7_match_table[] = {
  179. {.compatible = "qcom,acpuclk-a7"},
  180. {}
  181. };
  182. static struct platform_driver acpuclk_a7_driver = {
  183. .driver = {
  184. .name = "acpuclk-a7",
  185. .of_match_table = acpuclk_a7_match_table,
  186. .owner = THIS_MODULE,
  187. },
  188. };
  189. void msm8610_acpu_init(void)
  190. {
  191. drv_data.bus_scale->usecase = bw_level_tbl_8610;
  192. drv_data.bus_scale->num_usecases = ARRAY_SIZE(bw_level_tbl_8610);
  193. drv_data.freq_tbl = acpu_freq_tbl_8610;
  194. }
  195. static int __init acpuclk_a7_init(void)
  196. {
  197. if (cpu_is_msm8610())
  198. msm8610_acpu_init();
  199. return platform_driver_probe(&acpuclk_a7_driver, acpuclk_a7_probe);
  200. }
  201. device_initcall(acpuclk_a7_init);