diff options
Diffstat (limited to 'drivers/gpu/nvgpu/pmgr/pmgr.c')
-rw-r--r-- | drivers/gpu/nvgpu/pmgr/pmgr.c | 143 |
1 files changed, 143 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..f625e37d --- /dev/null +++ b/drivers/gpu/nvgpu/pmgr/pmgr.c | |||
@@ -0,0 +1,143 @@ | |||
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 | #ifdef CONFIG_DEBUG_FS | ||
20 | static int pmgr_pwr_devices_get_current_power(void *data, u64 *val) | ||
21 | { | ||
22 | struct nv_pmu_pmgr_pwr_devices_query_payload payload; | ||
23 | int status; | ||
24 | struct gk20a *g = (struct gk20a *)data; | ||
25 | |||
26 | status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload); | ||
27 | if (status) | ||
28 | gk20a_err(dev_from_gk20a(g), | ||
29 | "pmgr_pwr_devices_get_current_power failed %x", | ||
30 | status); | ||
31 | |||
32 | *val = payload.devices[0].powerm_w; | ||
33 | |||
34 | return status; | ||
35 | } | ||
36 | |||
37 | static int pmgr_pwr_devices_get_current(void *data, u64 *val) | ||
38 | { | ||
39 | struct nv_pmu_pmgr_pwr_devices_query_payload payload; | ||
40 | int status; | ||
41 | struct gk20a *g = (struct gk20a *)data; | ||
42 | |||
43 | status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload); | ||
44 | if (status) | ||
45 | gk20a_err(dev_from_gk20a(g), | ||
46 | "pmgr_pwr_devices_get_current failed %x", | ||
47 | status); | ||
48 | |||
49 | *val = payload.devices[0].currentm_a; | ||
50 | |||
51 | return status; | ||
52 | } | ||
53 | |||
54 | static int pmgr_pwr_devices_get_current_voltage(void *data, u64 *val) | ||
55 | { | ||
56 | struct nv_pmu_pmgr_pwr_devices_query_payload payload; | ||
57 | int status; | ||
58 | struct gk20a *g = (struct gk20a *)data; | ||
59 | |||
60 | status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload); | ||
61 | if (status) | ||
62 | gk20a_err(dev_from_gk20a(g), | ||
63 | "pmgr_pwr_devices_get_current_voltage failed %x", | ||
64 | status); | ||
65 | |||
66 | *val = payload.devices[0].voltageu_v; | ||
67 | |||
68 | return status; | ||
69 | } | ||
70 | |||
71 | DEFINE_SIMPLE_ATTRIBUTE( | ||
72 | pmgr_power_ctrl_fops, pmgr_pwr_devices_get_current_power, NULL, "%llu\n"); | ||
73 | |||
74 | DEFINE_SIMPLE_ATTRIBUTE( | ||
75 | pmgr_current_ctrl_fops, pmgr_pwr_devices_get_current, NULL, "%llu\n"); | ||
76 | |||
77 | DEFINE_SIMPLE_ATTRIBUTE( | ||
78 | pmgr_voltage_ctrl_fops, pmgr_pwr_devices_get_current_voltage, NULL, "%llu\n"); | ||
79 | |||
80 | static void pmgr_debugfs_init(struct gk20a *g) { | ||
81 | struct gk20a_platform *platform = dev_get_drvdata(g->dev); | ||
82 | struct dentry *dbgentry; | ||
83 | |||
84 | dbgentry = debugfs_create_file( | ||
85 | "power", S_IRUGO, platform->debugfs, g, &pmgr_power_ctrl_fops); | ||
86 | if (!dbgentry) | ||
87 | gk20a_err(dev_from_gk20a(g), | ||
88 | "debugfs entry create failed for power"); | ||
89 | |||
90 | dbgentry = debugfs_create_file( | ||
91 | "current", S_IRUGO, platform->debugfs, g, &pmgr_current_ctrl_fops); | ||
92 | if (!dbgentry) | ||
93 | gk20a_err(dev_from_gk20a(g), | ||
94 | "debugfs entry create failed for current"); | ||
95 | |||
96 | dbgentry = debugfs_create_file( | ||
97 | "voltage", S_IRUGO, platform->debugfs, g, &pmgr_voltage_ctrl_fops); | ||
98 | if (!dbgentry) | ||
99 | gk20a_err(dev_from_gk20a(g), | ||
100 | "debugfs entry create failed for voltage"); | ||
101 | } | ||
102 | #endif | ||
103 | |||
104 | u32 pmgr_domain_sw_setup(struct gk20a *g) | ||
105 | { | ||
106 | u32 status; | ||
107 | |||
108 | status = pmgr_device_sw_setup(g); | ||
109 | if (status) { | ||
110 | gk20a_err(dev_from_gk20a(g), | ||
111 | "error creating boardobjgrp for pmgr devices, status - 0x%x", | ||
112 | status); | ||
113 | goto exit; | ||
114 | } | ||
115 | |||
116 | status = pmgr_monitor_sw_setup(g); | ||
117 | if (status) { | ||
118 | gk20a_err(dev_from_gk20a(g), | ||
119 | "error creating boardobjgrp for pmgr monitor, status - 0x%x", | ||
120 | status); | ||
121 | goto exit; | ||
122 | } | ||
123 | |||
124 | status = pmgr_policy_sw_setup(g); | ||
125 | if (status) { | ||
126 | gk20a_err(dev_from_gk20a(g), | ||
127 | "error creating boardobjgrp for pmgr policy, status - 0x%x", | ||
128 | status); | ||
129 | goto exit; | ||
130 | } | ||
131 | |||
132 | #ifdef CONFIG_DEBUG_FS | ||
133 | pmgr_debugfs_init(g); | ||
134 | #endif | ||
135 | |||
136 | exit: | ||
137 | return status; | ||
138 | } | ||
139 | |||
140 | u32 pmgr_domain_pmu_setup(struct gk20a *g) | ||
141 | { | ||
142 | return pmgr_send_pmgr_tables_to_pmu(g); | ||
143 | } | ||