clk-tegra124-dfll-fcpu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. .entries = {
  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. { 0UL, { 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, err;
  83. struct tegra_dfll_soc_data *soc;
  84. process_id = tegra_sku_info.cpu_process_id;
  85. speedo_id = tegra_sku_info.cpu_speedo_id;
  86. speedo_value = tegra_sku_info.cpu_speedo_value;
  87. if (speedo_id >= ARRAY_SIZE(cpu_max_freq_table)) {
  88. dev_err(&pdev->dev, "unknown max CPU freq for speedo_id=%d\n",
  89. speedo_id);
  90. return -ENODEV;
  91. }
  92. soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL);
  93. if (!soc)
  94. return -ENOMEM;
  95. soc->dev = get_cpu_device(0);
  96. if (!soc->dev) {
  97. dev_err(&pdev->dev, "no CPU0 device\n");
  98. return -ENODEV;
  99. }
  100. soc->max_freq = cpu_max_freq_table[speedo_id];
  101. soc->cvb = tegra_cvb_add_opp_table(soc->dev, tegra124_cpu_cvb_tables,
  102. ARRAY_SIZE(tegra124_cpu_cvb_tables),
  103. process_id, speedo_id, speedo_value,
  104. soc->max_freq);
  105. if (IS_ERR(soc->cvb)) {
  106. dev_err(&pdev->dev, "couldn't add OPP table: %ld\n",
  107. PTR_ERR(soc->cvb));
  108. return PTR_ERR(soc->cvb);
  109. }
  110. err = tegra_dfll_register(pdev, soc);
  111. if (err < 0) {
  112. tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);
  113. return err;
  114. }
  115. platform_set_drvdata(pdev, soc);
  116. return 0;
  117. }
  118. static int tegra124_dfll_fcpu_remove(struct platform_device *pdev)
  119. {
  120. struct tegra_dfll_soc_data *soc = platform_get_drvdata(pdev);
  121. int err;
  122. err = tegra_dfll_unregister(pdev);
  123. if (err < 0)
  124. dev_err(&pdev->dev, "failed to unregister DFLL: %d\n", err);
  125. tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);
  126. return 0;
  127. }
  128. static const struct of_device_id tegra124_dfll_fcpu_of_match[] = {
  129. { .compatible = "nvidia,tegra124-dfll", },
  130. { },
  131. };
  132. MODULE_DEVICE_TABLE(of, tegra124_dfll_fcpu_of_match);
  133. static const struct dev_pm_ops tegra124_dfll_pm_ops = {
  134. SET_RUNTIME_PM_OPS(tegra_dfll_runtime_suspend,
  135. tegra_dfll_runtime_resume, NULL)
  136. };
  137. static struct platform_driver tegra124_dfll_fcpu_driver = {
  138. .probe = tegra124_dfll_fcpu_probe,
  139. .remove = tegra124_dfll_fcpu_remove,
  140. .driver = {
  141. .name = "tegra124-dfll",
  142. .of_match_table = tegra124_dfll_fcpu_of_match,
  143. .pm = &tegra124_dfll_pm_ops,
  144. },
  145. };
  146. static int __init tegra124_dfll_fcpu_init(void)
  147. {
  148. return platform_driver_register(&tegra124_dfll_fcpu_driver);
  149. }
  150. module_init(tegra124_dfll_fcpu_init);
  151. static void __exit tegra124_dfll_fcpu_exit(void)
  152. {
  153. platform_driver_unregister(&tegra124_dfll_fcpu_driver);
  154. }
  155. module_exit(tegra124_dfll_fcpu_exit);
  156. MODULE_DESCRIPTION("Tegra124 DFLL clock source driver");
  157. MODULE_LICENSE("GPL v2");
  158. MODULE_AUTHOR("Aleksandr Frid <afrid@nvidia.com>");
  159. MODULE_AUTHOR("Paul Walmsley <pwalmsley@nvidia.com>");