opp.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * OMAP SoC specific OPP wrapper function
  3. *
  4. * Copyright (C) 2009-2010 Texas Instruments Incorporated - http://www.ti.com/
  5. * Nishanth Menon
  6. * Kevin Hilman
  7. * Copyright (C) 2010 Nokia Corporation.
  8. * Eduardo Valentin
  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. #include <linux/module.h>
  20. #include <linux/opp.h>
  21. #include <linux/cpu.h>
  22. #include "omap_device.h"
  23. #include "omap_opp_data.h"
  24. /* Temp variable to allow multiple calls */
  25. static u8 __initdata omap_table_init;
  26. /**
  27. * omap_init_opp_table() - Initialize opp table as per the CPU type
  28. * @opp_def: opp default list for this silicon
  29. * @opp_def_size: number of opp entries for this silicon
  30. *
  31. * Register the initial OPP table with the OPP library based on the CPU
  32. * type. This is meant to be used only by SoC specific registration.
  33. */
  34. int __init omap_init_opp_table(struct omap_opp_def *opp_def,
  35. u32 opp_def_size)
  36. {
  37. int i, r;
  38. if (!opp_def || !opp_def_size) {
  39. pr_err("%s: invalid params!\n", __func__);
  40. return -EINVAL;
  41. }
  42. /*
  43. * Initialize only if not already initialized even if the previous
  44. * call failed, because, no reason we'd succeed again.
  45. */
  46. if (omap_table_init)
  47. return -EEXIST;
  48. omap_table_init = 1;
  49. /* Lets now register with OPP library */
  50. for (i = 0; i < opp_def_size; i++, opp_def++) {
  51. struct omap_hwmod *oh;
  52. struct device *dev;
  53. if (!opp_def->hwmod_name) {
  54. pr_err("%s: NULL name of omap_hwmod, failing [%d].\n",
  55. __func__, i);
  56. return -EINVAL;
  57. }
  58. if (!strncmp(opp_def->hwmod_name, "mpu", 3)) {
  59. /*
  60. * All current OMAPs share voltage rail and
  61. * clock source, so CPU0 is used to represent
  62. * the MPU-SS.
  63. */
  64. dev = get_cpu_device(0);
  65. } else {
  66. oh = omap_hwmod_lookup(opp_def->hwmod_name);
  67. if (!oh || !oh->od) {
  68. pr_debug("%s: no hwmod or odev for %s, [%d] cannot add OPPs.\n",
  69. __func__, opp_def->hwmod_name, i);
  70. continue;
  71. }
  72. dev = &oh->od->pdev->dev;
  73. }
  74. r = opp_add(dev, opp_def->freq, opp_def->u_volt);
  75. if (r) {
  76. dev_err(dev, "%s: add OPP %ld failed for %s [%d] result=%d\n",
  77. __func__, opp_def->freq,
  78. opp_def->hwmod_name, i, r);
  79. } else {
  80. if (!opp_def->default_available)
  81. r = opp_disable(dev, opp_def->freq);
  82. if (r)
  83. dev_err(dev, "%s: disable %ld failed for %s [%d] result=%d\n",
  84. __func__, opp_def->freq,
  85. opp_def->hwmod_name, i, r);
  86. }
  87. }
  88. return 0;
  89. }