/arch/arm/mach-msm/internal_power_rail.c
C | 108 lines | 68 code | 20 blank | 20 comment | 8 complexity | 1dbcc9cfbff2f0e09fbca4510966fce2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
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
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/spinlock.h>
22
23#include <mach/internal_power_rail.h>
24
25#include "proc_comm.h"
26
27static DEFINE_SPINLOCK(power_rail_lock);
28
29static struct internal_rail {
30 uint32_t id;
31 uint32_t mode;
32} rails[] = {
33 { PWR_RAIL_GRP_CLK, PWR_RAIL_CTL_AUTO },
34 { PWR_RAIL_GRP_2D_CLK, PWR_RAIL_CTL_AUTO },
35 { PWR_RAIL_MDP_CLK, PWR_RAIL_CTL_MANUAL },
36 { PWR_RAIL_MFC_CLK, PWR_RAIL_CTL_AUTO },
37 { PWR_RAIL_ROTATOR_CLK, PWR_RAIL_CTL_AUTO },
38 { PWR_RAIL_VDC_CLK, PWR_RAIL_CTL_AUTO },
39 { PWR_RAIL_VFE_CLK, PWR_RAIL_CTL_AUTO },
40 { PWR_RAIL_VPE_CLK, PWR_RAIL_CTL_AUTO },
41};
42
43static struct internal_rail *find_rail(unsigned rail_id)
44{
45 int i;
46 for (i = 0; i < ARRAY_SIZE(rails); i++)
47 if (rails[i].id == rail_id)
48 return rails + i;
49
50 return NULL;
51}
52
53/* Enable or disable an internal power rail */
54int internal_pwr_rail_ctl(unsigned rail_id, bool enable)
55{
56 int cmd, rc;
57
58 cmd = enable ? PCOM_CLKCTL_RPC_RAIL_ENABLE :
59 PCOM_CLKCTL_RPC_RAIL_DISABLE;
60
61 rc = msm_proc_comm(cmd, &rail_id, NULL);
62
63 return rc;
64
65}
66EXPORT_SYMBOL(internal_pwr_rail_ctl);
67
68/* Enable or disable a rail if the rail is in auto mode. */
69int internal_pwr_rail_ctl_auto(unsigned rail_id, bool enable)
70{
71 int rc = 0;
72 unsigned long flags;
73 struct internal_rail *rail = find_rail(rail_id);
74
75 BUG_ON(!rail);
76
77 spin_lock_irqsave(&power_rail_lock, flags);
78 if (rail->mode == PWR_RAIL_CTL_AUTO)
79 rc = internal_pwr_rail_ctl(rail_id, enable);
80 spin_unlock_irqrestore(&power_rail_lock, flags);
81
82 return rc;
83}
84
85/* Specify an internal power rail control mode (ex. auto, manual) */
86int internal_pwr_rail_mode(unsigned rail_id, enum rail_ctl_mode mode)
87{
88 int rc;
89 unsigned long flags;
90 struct internal_rail *rail = find_rail(rail_id);
91
92 spin_lock_irqsave(&power_rail_lock, flags);
93 rc = msm_proc_comm(PCOM_CLKCTL_RPC_RAIL_CONTROL, &rail_id, &mode);
94 if (rc)
95 goto out;
96 if (rail_id) {
97 rc = -EINVAL;
98 goto out;
99 }
100
101 if (rail)
102 rail->mode = mode;
103out:
104 spin_unlock_irqrestore(&power_rail_lock, flags);
105 return rc;
106}
107EXPORT_SYMBOL(internal_pwr_rail_mode);
108