blob: 8b0f7b2fd8f7c7ccded980d126bca85381fd722f [file] [log] [blame]
Brian Swetlandf030d7b2008-09-29 14:07:14 -07001/* arch/arm/mach-msm/vreg.c
2 *
3 * Copyright (C) 2008 Google, Inc.
Steve Muckle4783de92008-12-12 19:33:55 -05004 * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
Brian Swetlandf030d7b2008-09-29 14:07:14 -07005 * Author: Brian Swetland <swetland@google.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/kernel.h>
19#include <linux/device.h>
20#include <linux/init.h>
21#include <linux/debugfs.h>
22#include <mach/vreg.h>
23
24#include "proc_comm.h"
25
26struct vreg {
27 const char *name;
28 unsigned id;
Steve Muckle4783de92008-12-12 19:33:55 -050029 int status;
Brian Swetlandf030d7b2008-09-29 14:07:14 -070030};
31
Steve Muckle4783de92008-12-12 19:33:55 -050032#define VREG(_name, _id, _status) \
33 { .name = _name, .id = _id, .status = _status }
Brian Swetlandf030d7b2008-09-29 14:07:14 -070034
35static struct vreg vregs[] = {
Steve Muckle4783de92008-12-12 19:33:55 -050036 VREG("msma", 0, 0),
37 VREG("msmp", 1, 0),
38 VREG("msme1", 2, 0),
39 VREG("msmc1", 3, 0),
40 VREG("msmc2", 4, 0),
41 VREG("gp3", 5, 0),
42 VREG("msme2", 6, 0),
43 VREG("gp4", 7, 0),
44 VREG("gp1", 8, 0),
45 VREG("tcxo", 9, 0),
46 VREG("pa", 10, 0),
47 VREG("rftx", 11, 0),
48 VREG("rfrx1", 12, 0),
49 VREG("rfrx2", 13, 0),
50 VREG("synt", 14, 0),
51 VREG("wlan", 15, 0),
52 VREG("usb", 16, 0),
53 VREG("boost", 17, 0),
54 VREG("mmc", 18, 0),
55 VREG("ruim", 19, 0),
56 VREG("msmc0", 20, 0),
57 VREG("gp2", 21, 0),
58 VREG("gp5", 22, 0),
59 VREG("gp6", 23, 0),
60 VREG("rf", 24, 0),
61 VREG("rf_vco", 26, 0),
62 VREG("mpll", 27, 0),
63 VREG("s2", 28, 0),
64 VREG("s3", 29, 0),
65 VREG("rfubm", 30, 0),
66 VREG("ncp", 31, 0),
Brian Swetlandf030d7b2008-09-29 14:07:14 -070067};
68
69struct vreg *vreg_get(struct device *dev, const char *id)
70{
71 int n;
72 for (n = 0; n < ARRAY_SIZE(vregs); n++) {
73 if (!strcmp(vregs[n].name, id))
74 return vregs + n;
75 }
Steve Muckle0c50b442010-03-04 12:38:05 -080076 return ERR_PTR(-ENOENT);
Brian Swetlandf030d7b2008-09-29 14:07:14 -070077}
78
79void vreg_put(struct vreg *vreg)
80{
81}
82
83int vreg_enable(struct vreg *vreg)
84{
85 unsigned id = vreg->id;
86 unsigned enable = 1;
Steve Muckle4783de92008-12-12 19:33:55 -050087
88 vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
89 return vreg->status;
Brian Swetlandf030d7b2008-09-29 14:07:14 -070090}
91
Steve Muckle4783de92008-12-12 19:33:55 -050092int vreg_disable(struct vreg *vreg)
Brian Swetlandf030d7b2008-09-29 14:07:14 -070093{
94 unsigned id = vreg->id;
95 unsigned enable = 0;
Steve Muckle4783de92008-12-12 19:33:55 -050096
97 vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
98 return vreg->status;
Brian Swetlandf030d7b2008-09-29 14:07:14 -070099}
100
101int vreg_set_level(struct vreg *vreg, unsigned mv)
102{
103 unsigned id = vreg->id;
Steve Muckle4783de92008-12-12 19:33:55 -0500104
105 vreg->status = msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
106 return vreg->status;
Brian Swetlandf030d7b2008-09-29 14:07:14 -0700107}
108
109#if defined(CONFIG_DEBUG_FS)
110
111static int vreg_debug_set(void *data, u64 val)
112{
113 struct vreg *vreg = data;
114 switch (val) {
115 case 0:
116 vreg_disable(vreg);
117 break;
118 case 1:
119 vreg_enable(vreg);
120 break;
121 default:
122 vreg_set_level(vreg, val);
123 break;
124 }
125 return 0;
126}
127
128static int vreg_debug_get(void *data, u64 *val)
129{
Steve Muckle4783de92008-12-12 19:33:55 -0500130 struct vreg *vreg = data;
131
132 if (!vreg->status)
133 *val = 0;
134 else
135 *val = 1;
136
137 return 0;
Brian Swetlandf030d7b2008-09-29 14:07:14 -0700138}
139
140DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");
141
142static int __init vreg_debug_init(void)
143{
144 struct dentry *dent;
145 int n;
146
147 dent = debugfs_create_dir("vreg", 0);
148 if (IS_ERR(dent))
149 return 0;
150
151 for (n = 0; n < ARRAY_SIZE(vregs); n++)
152 (void) debugfs_create_file(vregs[n].name, 0644,
153 dent, vregs + n, &vreg_fops);
154
155 return 0;
156}
157
158device_initcall(vreg_debug_init);
159#endif