Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/vreg.c |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 4 | * Copyright (c) 2009, Code Aurora Forum. All rights reserved. |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 5 | * 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 | |
| 26 | struct vreg { |
| 27 | const char *name; |
| 28 | unsigned id; |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 29 | int status; |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 32 | #define VREG(_name, _id, _status) \ |
| 33 | { .name = _name, .id = _id, .status = _status } |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 34 | |
| 35 | static struct vreg vregs[] = { |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 36 | 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 Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct 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 Muckle | 0c50b44 | 2010-03-04 12:38:05 -0800 | [diff] [blame] | 76 | return ERR_PTR(-ENOENT); |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void vreg_put(struct vreg *vreg) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | int vreg_enable(struct vreg *vreg) |
| 84 | { |
| 85 | unsigned id = vreg->id; |
| 86 | unsigned enable = 1; |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 87 | |
| 88 | vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable); |
| 89 | return vreg->status; |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 92 | int vreg_disable(struct vreg *vreg) |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 93 | { |
| 94 | unsigned id = vreg->id; |
| 95 | unsigned enable = 0; |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 96 | |
| 97 | vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable); |
| 98 | return vreg->status; |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | int vreg_set_level(struct vreg *vreg, unsigned mv) |
| 102 | { |
| 103 | unsigned id = vreg->id; |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 104 | |
| 105 | vreg->status = msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv); |
| 106 | return vreg->status; |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | #if defined(CONFIG_DEBUG_FS) |
| 110 | |
| 111 | static 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 | |
| 128 | static int vreg_debug_get(void *data, u64 *val) |
| 129 | { |
Steve Muckle | 4783de9 | 2008-12-12 19:33:55 -0500 | [diff] [blame^] | 130 | struct vreg *vreg = data; |
| 131 | |
| 132 | if (!vreg->status) |
| 133 | *val = 0; |
| 134 | else |
| 135 | *val = 1; |
| 136 | |
| 137 | return 0; |
Brian Swetland | f030d7b | 2008-09-29 14:07:14 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n"); |
| 141 | |
| 142 | static 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 | |
| 158 | device_initcall(vreg_debug_init); |
| 159 | #endif |