sprayTerminalOperation.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * OMAP3/OMAP4 Voltage Management Routines
  3. *
  4. * Author: Thara Gopinath <thara@ti.com>
  5. *
  6. * Copyright (C) 2007 Texas Instruments, Inc.
  7. * Rajendra Nayak <rnayak@ti.com>
  8. * Lesly A M <x0080970@ti.com>
  9. *
  10. * Copyright (C) 2008, 2011 Nokia Corporation
  11. * Kalle Jokiniemi
  12. * Paul Walmsley
  13. *
  14. * Copyright (C) 2010 Texas Instruments, Inc.
  15. * Thara Gopinath <thara@ti.com>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License version 2 as
  19. * published by the Free Software Foundation.
  20. */
  21. #include <linux/delay.h>
  22. #include <linux/io.h>
  23. #include <linux/err.h>
  24. #include <linux/export.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/slab.h>
  27. #include <linux/clk.h>
  28. #include "common.h"
  29. #include "prm-regbits-34xx.h"
  30. #include "prm-regbits-44xx.h"
  31. #include "prm44xx.h"
  32. #include "prcm44xx.h"
  33. #include "prminst44xx.h"
  34. #include "control.h"
  35. #include "voltage.h"
  36. #include "powerdomain.h"
  37. #include "vc.h"
  38. #include "vp.h"
  39. static LIST_HEAD(voltdm_list);
  40. /* Public functions */
  41. /**
  42. * voltdm_get_voltage() - Gets the current non-auto-compensated voltage
  43. * @voltdm: pointer to the voltdm for which current voltage info is needed
  44. *
  45. * API to get the current non-auto-compensated voltage for a voltage domain.
  46. * Returns 0 in case of error else returns the current voltage.
  47. */
  48. unsigned long voltdm_get_voltage(struct voltagedomain *voltdm)
  49. {
  50. if (!voltdm || IS_ERR(voltdm)) {
  51. pr_warning("%s: VDD specified does not exist!\n", __func__);
  52. return 0;
  53. }
  54. return voltdm->nominal_volt;
  55. }
  56. /**
  57. * voltdm_scale() - API to scale voltage of a particular voltage domain.
  58. * @voltdm: pointer to the voltage domain which is to be scaled.
  59. * @target_volt: The target voltage of the voltage domain
  60. *
  61. * This API should be called by the kernel to do the voltage scaling
  62. * for a particular voltage domain during DVFS.
  63. */
  64. int voltdm_scale(struct voltagedomain *voltdm,
  65. unsigned long target_volt)
  66. {
  67. int ret, i;
  68. unsigned long volt = 0;
  69. if (!voltdm || IS_ERR(voltdm)) {
  70. pr_warning("%s: VDD specified does not exist!\n", __func__);
  71. return -EINVAL;
  72. }
  73. if (!voltdm->scale) {
  74. pr_err("%s: No voltage scale API registered for vdd_%s\n",
  75. __func__, voltdm->name);
  76. return -ENODATA;
  77. }
  78. /* Adjust voltage to the exact voltage from the OPP table */
  79. for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) {
  80. if (voltdm->volt_data[i].volt_nominal >= target_volt) {
  81. volt = voltdm->volt_data[i].volt_nominal;
  82. break;
  83. }
  84. }
  85. if (!volt) {
  86. pr_warning("%s: not scaling. OPP voltage for %lu, not found.\n",
  87. __func__, target_volt);
  88. return -EINVAL;
  89. }
  90. ret = voltdm->scale(voltdm, volt);
  91. if (!ret)
  92. voltdm->nominal_volt = volt;
  93. return ret;
  94. }
  95. /**
  96. * voltdm_reset() - Resets the voltage of a particular voltage domain
  97. * to that of the current OPP.
  98. * @voltdm: pointer to the voltage domain whose voltage is to be reset.
  99. *
  100. * This API finds out the correct voltage the voltage domain is supposed
  101. * to be at and resets the voltage to that level. Should be used especially
  102. * while disabling any voltage compensation modules.
  103. */
  104. void voltdm_reset(struct voltagedomain *voltdm)
  105. {
  106. unsigned long target_volt;
  107. if (!voltdm || IS_ERR(voltdm)) {
  108. pr_warning("%s: VDD specified does not exist!\n", __func__);
  109. return;
  110. }
  111. target_volt = voltdm_get_voltage(voltdm);
  112. if (!target_volt) {
  113. pr_err("%s: unable to find current voltage for vdd_%s\n",
  114. __func__, voltdm->name);
  115. return;
  116. }
  117. voltdm_scale(voltdm, target_volt);
  118. }
  119. /**
  120. * omap_voltage_get_volttable() - API to get the voltage table associated with a
  121. * particular voltage domain.
  122. * @voltdm: pointer to the VDD for which the voltage table is required
  123. * @volt_data: the voltage table for the particular vdd which is to be
  124. * populated by this API
  125. *
  126. * This API populates the voltage table associated with a VDD into the
  127. * passed parameter pointer. Returns the count of distinct voltages
  128. * supported by this vdd.
  129. *
  130. */
  131. void omap_voltage_get_volttable(struct voltagedomain *voltdm,
  132. struct omap_volt_data **volt_data)
  133. {
  134. if (!voltdm || IS_ERR(voltdm)) {
  135. pr_warning("%s: VDD specified does not exist!\n", __func__);
  136. return;
  137. }
  138. *volt_data = voltdm->volt_data;
  139. }