/arch/arm/mach-msm/internal_power_rail.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · C · 108 lines · 68 code · 20 blank · 20 comment · 8 complexity · 1dbcc9cfbff2f0e09fbca4510966fce2 MD5 · raw file

  1. /* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. * 02110-1301, USA.
  16. *
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/spinlock.h>
  21. #include <mach/internal_power_rail.h>
  22. #include "proc_comm.h"
  23. static DEFINE_SPINLOCK(power_rail_lock);
  24. static struct internal_rail {
  25. uint32_t id;
  26. uint32_t mode;
  27. } rails[] = {
  28. { PWR_RAIL_GRP_CLK, PWR_RAIL_CTL_AUTO },
  29. { PWR_RAIL_GRP_2D_CLK, PWR_RAIL_CTL_AUTO },
  30. { PWR_RAIL_MDP_CLK, PWR_RAIL_CTL_MANUAL },
  31. { PWR_RAIL_MFC_CLK, PWR_RAIL_CTL_AUTO },
  32. { PWR_RAIL_ROTATOR_CLK, PWR_RAIL_CTL_AUTO },
  33. { PWR_RAIL_VDC_CLK, PWR_RAIL_CTL_AUTO },
  34. { PWR_RAIL_VFE_CLK, PWR_RAIL_CTL_AUTO },
  35. { PWR_RAIL_VPE_CLK, PWR_RAIL_CTL_AUTO },
  36. };
  37. static struct internal_rail *find_rail(unsigned rail_id)
  38. {
  39. int i;
  40. for (i = 0; i < ARRAY_SIZE(rails); i++)
  41. if (rails[i].id == rail_id)
  42. return rails + i;
  43. return NULL;
  44. }
  45. /* Enable or disable an internal power rail */
  46. int internal_pwr_rail_ctl(unsigned rail_id, bool enable)
  47. {
  48. int cmd, rc;
  49. cmd = enable ? PCOM_CLKCTL_RPC_RAIL_ENABLE :
  50. PCOM_CLKCTL_RPC_RAIL_DISABLE;
  51. rc = msm_proc_comm(cmd, &rail_id, NULL);
  52. return rc;
  53. }
  54. EXPORT_SYMBOL(internal_pwr_rail_ctl);
  55. /* Enable or disable a rail if the rail is in auto mode. */
  56. int internal_pwr_rail_ctl_auto(unsigned rail_id, bool enable)
  57. {
  58. int rc = 0;
  59. unsigned long flags;
  60. struct internal_rail *rail = find_rail(rail_id);
  61. BUG_ON(!rail);
  62. spin_lock_irqsave(&power_rail_lock, flags);
  63. if (rail->mode == PWR_RAIL_CTL_AUTO)
  64. rc = internal_pwr_rail_ctl(rail_id, enable);
  65. spin_unlock_irqrestore(&power_rail_lock, flags);
  66. return rc;
  67. }
  68. /* Specify an internal power rail control mode (ex. auto, manual) */
  69. int internal_pwr_rail_mode(unsigned rail_id, enum rail_ctl_mode mode)
  70. {
  71. int rc;
  72. unsigned long flags;
  73. struct internal_rail *rail = find_rail(rail_id);
  74. spin_lock_irqsave(&power_rail_lock, flags);
  75. rc = msm_proc_comm(PCOM_CLKCTL_RPC_RAIL_CONTROL, &rail_id, &mode);
  76. if (rc)
  77. goto out;
  78. if (rail_id) {
  79. rc = -EINVAL;
  80. goto out;
  81. }
  82. if (rail)
  83. rail->mode = mode;
  84. out:
  85. spin_unlock_irqrestore(&power_rail_lock, flags);
  86. return rc;
  87. }
  88. EXPORT_SYMBOL(internal_pwr_rail_mode);