clk-tegra124-dfll-fcpu.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Tegra124 DFLL FCPU clock source driver
  3. *
  4. * Copyright (C) 2012-2014 NVIDIA Corporation. All rights reserved.
  5. *
  6. * Aleksandr Frid <afrid@nvidia.com>
  7. * Paul Walmsley <pwalmsley@nvidia.com>
  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. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. */
  19. #include <linux/cpu.h>
  20. #include <linux/err.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <soc/tegra/fuse.h>
  25. #include "clk.h"
  26. #include "clk-dfll.h"
  27. #include "cvb.h"
  28. /* Maximum CPU frequency, indexed by CPU speedo id */
  29. static const unsigned long cpu_max_freq_table[] = {
  30. [0] = 2014500000UL,
  31. [1] = 2320500000UL,
  32. [2] = 2116500000UL,
  33. [3] = 2524500000UL,
  34. };
  35. static const struct cvb_table tegra124_cpu_cvb_tables[] = {
  36. {
  37. .speedo_id = -1,
  38. .process_id = -1,
  39. .min_millivolts = 900,
  40. .max_millivolts = 1260,
  41. .alignment = {
  42. .step_uv = 10000, /* 10mV */
  43. },
  44. .speedo_scale = 100,
  45. .voltage_scale = 1000,
  46. .cvb_table = {
  47. {204000000UL, {1112619, -29295, 402} },
  48. {306000000UL, {1150460, -30585, 402} },
  49. {408000000UL, {1190122, -31865, 402} },
  50. {510000000UL, {1231606, -33155, 402} },
  51. {612000000UL, {1274912, -34435, 402} },
  52. {714000000UL, {1320040, -35725, 402} },
  53. {816000000UL, {1366990, -37005, 402} },
  54. {918000000UL, {1415762, -38295, 402} },
  55. {1020000000UL, {1466355, -39575, 402} },
  56. {1122000000UL, {1518771, -40865, 402} },
  57. {1224000000UL, {1573009, -42145, 402} },
  58. {1326000000UL, {1629068, -43435, 402} },
  59. {1428000000UL, {1686950, -44715, 402} },
  60. {1530000000UL, {1746653, -46005, 402} },
  61. {1632000000UL, {1808179, -47285, 402} },
  62. {1734000000UL, {1871526, -48575, 402} },
  63. {1836000000UL, {1936696, -49855, 402} },
  64. {1938000000UL, {2003687, -51145, 402} },
  65. {2014500000UL, {2054787, -52095, 402} },
  66. {2116500000UL, {2124957, -53385, 402} },
  67. {2218500000UL, {2196950, -54665, 402} },
  68. {2320500000UL, {2270765, -55955, 402} },
  69. {2422500000UL, {2346401, -57235, 402} },
  70. {2524500000UL, {2437299, -58535, 402} },
  71. {0, { 0, 0, 0} },
  72. },
  73. .cpu_dfll_data = {
  74. .tune0_low = 0x005020ff,
  75. .tune0_high = 0x005040ff,
  76. .tune1 = 0x00000060,
  77. }
  78. },
  79. };
  80. static int tegra124_dfll_fcpu_probe(struct platform_device *pdev)
  81. {
  82. int process_id, speedo_id, speedo_value;
  83. struct tegra_dfll_soc_data *soc;
  84. const struct cvb_table *cvb;
  85. process_id = tegra_sku_info.cpu_process_id;
  86. speedo_id = tegra_sku_info.cpu_speedo_id;
  87. speedo_value = tegra_sku_info.cpu_speedo_value;
  88. if (speedo_id >= ARRAY_SIZE(cpu_max_freq_table)) {
  89. dev_err(&pdev->dev, "unknown max CPU freq for speedo_id=%d\n",
  90. speedo_id);
  91. return -ENODEV;
  92. }
  93. soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL);
  94. if (!soc)
  95. return -ENOMEM;
  96. soc->dev = get_cpu_device(0);
  97. if (!soc->dev) {
  98. dev_err(&pdev->dev, "no CPU0 device\n");
  99. return -ENODEV;
  100. }
  101. cvb = tegra_cvb_build_opp_table(tegra124_cpu_cvb_tables,
  102. ARRAY_SIZE(tegra124_cpu_cvb_tables),
  103. process_id, speedo_id, speedo_value,
  104. cpu_max_freq_table[speedo_id],
  105. soc->dev);
  106. if (IS_ERR(cvb)) {
  107. dev_err(&pdev->dev, "couldn't build OPP table: %ld\n",
  108. PTR_ERR(cvb));
  109. return PTR_ERR(cvb);
  110. }
  111. soc->min_millivolts = cvb->min_millivolts;
  112. soc->tune0_low = cvb->cpu_dfll_data.tune0_low;
  113. soc->tune0_high = cvb->cpu_dfll_data.tune0_high;
  114. soc->tune1 = cvb->cpu_dfll_data.tune1;
  115. return tegra_dfll_register(pdev, soc);
  116. }
  117. static const struct of_device_id tegra124_dfll_fcpu_of_match[] = {
  118. { .compatible = "nvidia,tegra124-dfll", },
  119. { },
  120. };
  121. MODULE_DEVICE_TABLE(of, tegra124_dfll_fcpu_of_match);
  122. static const struct dev_pm_ops tegra124_dfll_pm_ops = {
  123. SET_RUNTIME_PM_OPS(tegra_dfll_runtime_suspend,
  124. tegra_dfll_runtime_resume, NULL)
  125. };
  126. static struct platform_driver tegra124_dfll_fcpu_driver = {
  127. .probe = tegra124_dfll_fcpu_probe,
  128. .remove = tegra_dfll_unregister,
  129. .driver = {
  130. .name = "tegra124-dfll",
  131. .of_match_table = tegra124_dfll_fcpu_of_match,
  132. .pm = &tegra124_dfll_pm_ops,
  133. },
  134. };
  135. static int __init tegra124_dfll_fcpu_init(void)
  136. {
  137. return platform_driver_register(&tegra124_dfll_fcpu_driver);
  138. }
  139. module_init(tegra124_dfll_fcpu_init);
  140. static void __exit tegra124_dfll_fcpu_exit(void)
  141. {
  142. platform_driver_unregister(&tegra124_dfll_fcpu_driver);
  143. }
  144. module_exit(tegra124_dfll_fcpu_exit);
  145. MODULE_DESCRIPTION("Tegra124 DFLL clock source driver");
  146. MODULE_LICENSE("GPL v2");
  147. MODULE_AUTHOR("Aleksandr Frid <afrid@nvidia.com>");
  148. MODULE_AUTHOR("Paul Walmsley <pwalmsley@nvidia.com>");