diff options
Diffstat (limited to 'drivers/gpu/nvgpu/pmgr/pmgr.c')
-rw-r--r-- | drivers/gpu/nvgpu/pmgr/pmgr.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/pmgr/pmgr.c b/drivers/gpu/nvgpu/pmgr/pmgr.c new file mode 100644 index 00000000..e101aba8 --- /dev/null +++ b/drivers/gpu/nvgpu/pmgr/pmgr.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | */ | ||
13 | |||
14 | #include "gk20a/gk20a.h" | ||
15 | #include "pwrdev.h" | ||
16 | #include "pmgrpmu.h" | ||
17 | #include <linux/debugfs.h> | ||
18 | |||
19 | int pmgr_pwr_devices_get_power(struct gk20a *g, u32 *val) | ||
20 | { | ||
21 | struct nv_pmu_pmgr_pwr_devices_query_payload payload; | ||
22 | int status; | ||
23 | |||
24 | status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload); | ||
25 | if (status) | ||
26 | gk20a_err(dev_from_gk20a(g), | ||
27 | "pmgr_pwr_devices_get_current_power failed %x", | ||
28 | status); | ||
29 | |||
30 | *val = payload.devices[0].powerm_w; | ||
31 | |||
32 | return status; | ||
33 | } | ||
34 | |||
35 | int pmgr_pwr_devices_get_current(struct gk20a *g, u32 *val) | ||
36 | { | ||
37 | struct nv_pmu_pmgr_pwr_devices_query_payload payload; | ||
38 | int status; | ||
39 | |||
40 | status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload); | ||
41 | if (status) | ||
42 | gk20a_err(dev_from_gk20a(g), | ||
43 | "pmgr_pwr_devices_get_current failed %x", | ||
44 | status); | ||
45 | |||
46 | *val = payload.devices[0].currentm_a; | ||
47 | |||
48 | return status; | ||
49 | } | ||
50 | |||
51 | int pmgr_pwr_devices_get_voltage(struct gk20a *g, u32 *val) | ||
52 | { | ||
53 | struct nv_pmu_pmgr_pwr_devices_query_payload payload; | ||
54 | int status; | ||
55 | |||
56 | status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload); | ||
57 | if (status) | ||
58 | gk20a_err(dev_from_gk20a(g), | ||
59 | "pmgr_pwr_devices_get_current_voltage failed %x", | ||
60 | status); | ||
61 | |||
62 | *val = payload.devices[0].voltageu_v; | ||
63 | |||
64 | return status; | ||
65 | } | ||
66 | |||
67 | #ifdef CONFIG_DEBUG_FS | ||
68 | int pmgr_pwr_devices_get_power_u64(void *data, u64 *p) | ||
69 | { | ||
70 | struct gk20a *g = (struct gk20a *)data; | ||
71 | int err; | ||
72 | u32 val; | ||
73 | |||
74 | err = pmgr_pwr_devices_get_power(g, &val); | ||
75 | *p = val; | ||
76 | |||
77 | return err; | ||
78 | } | ||
79 | |||
80 | int pmgr_pwr_devices_get_current_u64(void *data, u64 *p) | ||
81 | { | ||
82 | struct gk20a *g = (struct gk20a *)data; | ||
83 | int err; | ||
84 | u32 val; | ||
85 | |||
86 | err = pmgr_pwr_devices_get_current(g, &val); | ||
87 | *p = val; | ||
88 | |||
89 | return err; | ||
90 | } | ||
91 | |||
92 | int pmgr_pwr_devices_get_voltage_u64(void *data, u64 *p) | ||
93 | { | ||
94 | struct gk20a *g = (struct gk20a *)data; | ||
95 | int err; | ||
96 | u32 val; | ||
97 | |||
98 | err = pmgr_pwr_devices_get_voltage(g, &val); | ||
99 | *p = val; | ||
100 | |||
101 | return err; | ||
102 | } | ||
103 | |||
104 | DEFINE_SIMPLE_ATTRIBUTE( | ||
105 | pmgr_power_ctrl_fops, pmgr_pwr_devices_get_power_u64, NULL, "%llu\n"); | ||
106 | |||
107 | DEFINE_SIMPLE_ATTRIBUTE( | ||
108 | pmgr_current_ctrl_fops, pmgr_pwr_devices_get_current_u64, NULL, "%llu\n"); | ||
109 | |||
110 | DEFINE_SIMPLE_ATTRIBUTE( | ||
111 | pmgr_voltage_ctrl_fops, pmgr_pwr_devices_get_voltage_u64, NULL, "%llu\n"); | ||
112 | |||
113 | static void pmgr_debugfs_init(struct gk20a *g) { | ||
114 | struct gk20a_platform *platform = dev_get_drvdata(g->dev); | ||
115 | struct dentry *dbgentry; | ||
116 | |||
117 | dbgentry = debugfs_create_file( | ||
118 | "power", S_IRUGO, platform->debugfs, g, &pmgr_power_ctrl_fops); | ||
119 | if (!dbgentry) | ||
120 | gk20a_err(dev_from_gk20a(g), | ||
121 | "debugfs entry create failed for power"); | ||
122 | |||
123 | dbgentry = debugfs_create_file( | ||
124 | "current", S_IRUGO, platform->debugfs, g, &pmgr_current_ctrl_fops); | ||
125 | if (!dbgentry) | ||
126 | gk20a_err(dev_from_gk20a(g), | ||
127 | "debugfs entry create failed for current"); | ||
128 | |||
129 | dbgentry = debugfs_create_file( | ||
130 | "voltage", S_IRUGO, platform->debugfs, g, &pmgr_voltage_ctrl_fops); | ||
131 | if (!dbgentry) | ||
132 | gk20a_err(dev_from_gk20a(g), | ||
133 | "debugfs entry create failed for voltage"); | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | u32 pmgr_domain_sw_setup(struct gk20a *g) | ||
138 | { | ||
139 | u32 status; | ||
140 | |||
141 | status = pmgr_device_sw_setup(g); | ||
142 | if (status) { | ||
143 | gk20a_err(dev_from_gk20a(g), | ||
144 | "error creating boardobjgrp for pmgr devices, status - 0x%x", | ||
145 | status); | ||
146 | goto exit; | ||
147 | } | ||
148 | |||
149 | status = pmgr_monitor_sw_setup(g); | ||
150 | if (status) { | ||
151 | gk20a_err(dev_from_gk20a(g), | ||
152 | "error creating boardobjgrp for pmgr monitor, status - 0x%x", | ||
153 | status); | ||
154 | goto exit; | ||
155 | } | ||
156 | |||
157 | status = pmgr_policy_sw_setup(g); | ||
158 | if (status) { | ||
159 | gk20a_err(dev_from_gk20a(g), | ||
160 | "error creating boardobjgrp for pmgr policy, status - 0x%x", | ||
161 | status); | ||
162 | goto exit; | ||
163 | } | ||
164 | |||
165 | #ifdef CONFIG_DEBUG_FS | ||
166 | pmgr_debugfs_init(g); | ||
167 | #endif | ||
168 | |||
169 | exit: | ||
170 | return status; | ||
171 | } | ||
172 | |||
173 | u32 pmgr_domain_pmu_setup(struct gk20a *g) | ||
174 | { | ||
175 | return pmgr_send_pmgr_tables_to_pmu(g); | ||
176 | } | ||