summaryrefslogtreecommitdiff
path: root/arch/arm/mach-msm/vreg.c
blob: fcb0b9f256841a291616d85cd1099a09bd8bc088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* arch/arm/mach-msm/vreg.c
 *
 * Copyright (C) 2008 Google, Inc.
 * Author: Brian Swetland <swetland@google.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/debugfs.h>
#include <mach/vreg.h>

#include "proc_comm.h"

struct vreg {
	const char *name;
	unsigned id;
};

#define VREG(_name, _id) { .name = _name, .id = _id, }

static struct vreg vregs[] = {
	VREG("msma",	0),
	VREG("msmp",	1),
	VREG("msme1",	2),
	VREG("msmc1",	3),
	VREG("msmc2",	4),
	VREG("gp3",	5),
	VREG("msme2",	6),
	VREG("gp4",	7),
	VREG("gp1",	8),
	VREG("tcxo",	9),
	VREG("pa",	10),
	VREG("rftx",	11),
	VREG("rfrx1",	12),
	VREG("rfrx2",	13),
	VREG("synt",	14),
	VREG("wlan",	15),
	VREG("usb",	16),
	VREG("boost",	17),
	VREG("mmc",	18),
	VREG("ruim",	19),
	VREG("msmc0",	20),
	VREG("gp2",	21),
	VREG("gp5",	22),
	VREG("gp6",	23),
	VREG("rf",	24),
	VREG("rf_vco",	26),
	VREG("mpll",	27),
	VREG("s2",	28),
	VREG("s3",	29),
	VREG("rfubm",	30),
	VREG("ncp",	31),
};

struct vreg *vreg_get(struct device *dev, const char *id)
{
	int n;
	for (n = 0; n < ARRAY_SIZE(vregs); n++) {
		if (!strcmp(vregs[n].name, id))
			return vregs + n;
	}
	return 0;
}

void vreg_put(struct vreg *vreg)
{
}

int vreg_enable(struct vreg *vreg)
{
	unsigned id = vreg->id;
	unsigned enable = 1;
	return msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
}

void vreg_disable(struct vreg *vreg)
{
	unsigned id = vreg->id;
	unsigned enable = 0;
	msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
}

int vreg_set_level(struct vreg *vreg, unsigned mv)
{
	unsigned id = vreg->id;
	return msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
}

#if defined(CONFIG_DEBUG_FS)

static int vreg_debug_set(void *data, u64 val)
{
	struct vreg *vreg = data;
	switch (val) {
	case 0:
		vreg_disable(vreg);
		break;
	case 1:
		vreg_enable(vreg);
		break;
	default:
		vreg_set_level(vreg, val);
		break;
	}
	return 0;
}

static int vreg_debug_get(void *data, u64 *val)
{
	return -ENOSYS;
}

DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");

static int __init vreg_debug_init(void)
{
	struct dentry *dent;
	int n;

	dent = debugfs_create_dir("vreg", 0);
	if (IS_ERR(dent))
		return 0;

	for (n = 0; n < ARRAY_SIZE(vregs); n++)
		(void) debugfs_create_file(vregs[n].name, 0644,
					   dent, vregs + n, &vreg_fops);

	return 0;
}

device_initcall(vreg_debug_init);
#endif