opp.c 2.5 KB

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