opp.c 2.8 KB

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