diff options
Diffstat (limited to 'drivers/gpu/nvgpu/volt/volt_dev.c')
-rw-r--r-- | drivers/gpu/nvgpu/volt/volt_dev.c | 588 |
1 files changed, 588 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/volt/volt_dev.c b/drivers/gpu/nvgpu/volt/volt_dev.c new file mode 100644 index 00000000..3a7ed1b5 --- /dev/null +++ b/drivers/gpu/nvgpu/volt/volt_dev.c | |||
@@ -0,0 +1,588 @@ | |||
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 <linux/sort.h> | ||
15 | |||
16 | #include "gk20a/gk20a.h" | ||
17 | #include "include/bios.h" | ||
18 | #include "boardobj/boardobjgrp.h" | ||
19 | #include "boardobj/boardobjgrp_e32.h" | ||
20 | #include "pmuif/gpmuifboardobj.h" | ||
21 | #include "gm206/bios_gm206.h" | ||
22 | #include "ctrl/ctrlvolt.h" | ||
23 | #include "gk20a/pmu_gk20a.h" | ||
24 | |||
25 | #include "pmuif/gpmuifperfvfe.h" | ||
26 | #include "include/bios.h" | ||
27 | #include "volt.h" | ||
28 | |||
29 | #define VOLT_DEV_PWM_VOLTAGE_STEPS_INVALID 0 | ||
30 | #define VOLT_DEV_PWM_VOLTAGE_STEPS_DEFAULT 1 | ||
31 | |||
32 | u32 volt_device_pmu_data_init_super(struct gk20a *g, | ||
33 | struct boardobj *pboard_obj, struct nv_pmu_boardobj *ppmudata) | ||
34 | { | ||
35 | u32 status; | ||
36 | struct voltage_device *pdev; | ||
37 | struct nv_pmu_volt_volt_device_boardobj_set *pset; | ||
38 | |||
39 | status = boardobj_pmudatainit_super(g, pboard_obj, ppmudata); | ||
40 | if (status) | ||
41 | return status; | ||
42 | |||
43 | pdev = (struct voltage_device *)pboard_obj; | ||
44 | pset = (struct nv_pmu_volt_volt_device_boardobj_set *)ppmudata; | ||
45 | |||
46 | pset->switch_delay_us = pdev->switch_delay_us; | ||
47 | pset->voltage_min_uv = pdev->voltage_min_uv; | ||
48 | pset->voltage_max_uv = pdev->voltage_max_uv; | ||
49 | pset->volt_step_uv = pdev->volt_step_uv; | ||
50 | |||
51 | return status; | ||
52 | } | ||
53 | |||
54 | static u32 volt_device_pmu_data_init_pwm(struct gk20a *g, | ||
55 | struct boardobj *pboard_obj, struct nv_pmu_boardobj *ppmudata) | ||
56 | { | ||
57 | u32 status = 0; | ||
58 | struct voltage_device_pwm *pdev; | ||
59 | struct nv_pmu_volt_volt_device_pwm_boardobj_set *pset; | ||
60 | |||
61 | status = volt_device_pmu_data_init_super(g, pboard_obj, ppmudata); | ||
62 | if (status) | ||
63 | return status; | ||
64 | |||
65 | pdev = (struct voltage_device_pwm *)pboard_obj; | ||
66 | pset = (struct nv_pmu_volt_volt_device_pwm_boardobj_set *)ppmudata; | ||
67 | |||
68 | pset->raw_period = pdev->raw_period; | ||
69 | pset->voltage_base_uv = pdev->voltage_base_uv; | ||
70 | pset->voltage_offset_scale_uv = pdev->voltage_offset_scale_uv; | ||
71 | pset->pwm_source = pdev->source; | ||
72 | |||
73 | return status; | ||
74 | } | ||
75 | |||
76 | u32 construct_volt_device(struct gk20a *g, | ||
77 | struct boardobj **ppboardobj, u16 size, void *pargs) | ||
78 | { | ||
79 | struct voltage_device *ptmp_dev = (struct voltage_device *)pargs; | ||
80 | struct voltage_device *pvolt_dev = NULL; | ||
81 | u32 status = 0; | ||
82 | |||
83 | status = boardobj_construct_super(g, ppboardobj, size, pargs); | ||
84 | if (status) | ||
85 | return status; | ||
86 | |||
87 | pvolt_dev = (struct voltage_device *)*ppboardobj; | ||
88 | |||
89 | pvolt_dev->volt_domain = ptmp_dev->volt_domain; | ||
90 | pvolt_dev->i2c_dev_idx = ptmp_dev->i2c_dev_idx; | ||
91 | pvolt_dev->switch_delay_us = ptmp_dev->switch_delay_us; | ||
92 | pvolt_dev->rsvd_0 = VOLTAGE_DESCRIPTOR_TABLE_ENTRY_INVALID; | ||
93 | pvolt_dev->rsvd_1 = | ||
94 | VOLTAGE_DESCRIPTOR_TABLE_ENTRY_INVALID; | ||
95 | pvolt_dev->operation_type = ptmp_dev->operation_type; | ||
96 | pvolt_dev->voltage_min_uv = ptmp_dev->voltage_min_uv; | ||
97 | pvolt_dev->voltage_max_uv = ptmp_dev->voltage_max_uv; | ||
98 | |||
99 | pvolt_dev->super.pmudatainit = volt_device_pmu_data_init_super; | ||
100 | |||
101 | return status; | ||
102 | } | ||
103 | |||
104 | u32 construct_pwm_volt_device(struct gk20a *g, struct boardobj **ppboardobj, | ||
105 | u16 size, void *pargs) | ||
106 | { | ||
107 | struct boardobj *pboard_obj = NULL; | ||
108 | struct voltage_device_pwm *ptmp_dev = | ||
109 | (struct voltage_device_pwm *)pargs; | ||
110 | struct voltage_device_pwm *pdev = NULL; | ||
111 | u32 status = 0; | ||
112 | |||
113 | status = construct_volt_device(g, ppboardobj, size, pargs); | ||
114 | if (status) | ||
115 | return status; | ||
116 | |||
117 | pboard_obj = (*ppboardobj); | ||
118 | pdev = (struct voltage_device_pwm *)*ppboardobj; | ||
119 | |||
120 | pboard_obj->pmudatainit = volt_device_pmu_data_init_pwm; | ||
121 | |||
122 | /* Set VOLTAGE_DEVICE_PWM-specific parameters */ | ||
123 | pdev->voltage_base_uv = ptmp_dev->voltage_base_uv; | ||
124 | pdev->voltage_offset_scale_uv = ptmp_dev->voltage_offset_scale_uv; | ||
125 | pdev->source = ptmp_dev->source; | ||
126 | pdev->raw_period = ptmp_dev->raw_period; | ||
127 | |||
128 | return status; | ||
129 | } | ||
130 | |||
131 | |||
132 | struct voltage_device_entry *volt_dev_construct_dev_entry_pwm(struct gk20a *g, | ||
133 | u32 voltage_uv, void *pargs) | ||
134 | { | ||
135 | struct voltage_device_pwm_entry *pentry = NULL; | ||
136 | struct voltage_device_pwm_entry *ptmp_entry = | ||
137 | (struct voltage_device_pwm_entry *)pargs; | ||
138 | |||
139 | pentry = kzalloc(sizeof(struct voltage_device_pwm_entry), GFP_KERNEL); | ||
140 | if (pentry == NULL) | ||
141 | return NULL; | ||
142 | |||
143 | memset(pentry, 0, sizeof(struct voltage_device_pwm_entry)); | ||
144 | |||
145 | pentry->super.voltage_uv = voltage_uv; | ||
146 | pentry->duty_cycle = ptmp_entry->duty_cycle; | ||
147 | |||
148 | return (struct voltage_device_entry *)pentry; | ||
149 | } | ||
150 | |||
151 | static u8 volt_dev_operation_type_convert(u8 vbios_type) | ||
152 | { | ||
153 | switch (vbios_type) { | ||
154 | case NV_VBIOS_VDT_1X_ENTRY_PARAM1_PSV_OPERATION_TYPE_DEFAULT: | ||
155 | return CTRL_VOLT_DEVICE_OPERATION_TYPE_DEFAULT; | ||
156 | |||
157 | case NV_VBIOS_VDT_1X_ENTRY_PARAM1_PSV_OPERATION_TYPE_LPWR_STEADY_STATE: | ||
158 | return CTRL_VOLT_DEVICE_OPERATION_TYPE_LPWR_STEADY_STATE; | ||
159 | |||
160 | case NV_VBIOS_VDT_1X_ENTRY_PARAM1_PSV_OPERATION_TYPE_LPWR_SLEEP_STATE: | ||
161 | return CTRL_VOLT_DEVICE_OPERATION_TYPE_LPWR_SLEEP_STATE; | ||
162 | } | ||
163 | |||
164 | return CTRL_VOLT_DEVICE_OPERATION_TYPE_INVALID; | ||
165 | } | ||
166 | |||
167 | struct voltage_device *volt_volt_device_construct(struct gk20a *g, | ||
168 | void *pargs) | ||
169 | { | ||
170 | struct boardobj *pboard_obj = NULL; | ||
171 | |||
172 | if (BOARDOBJ_GET_TYPE(pargs) == CTRL_VOLT_DEVICE_TYPE_PWM) { | ||
173 | u32 status = construct_pwm_volt_device(g, &pboard_obj, | ||
174 | sizeof(struct voltage_device_pwm), pargs); | ||
175 | if (status) { | ||
176 | gk20a_err(dev_from_gk20a(g), | ||
177 | " Could not allocate memory for VOLTAGE_DEVICE type (%x).", | ||
178 | BOARDOBJ_GET_TYPE(pargs)); | ||
179 | pboard_obj = NULL; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | return (struct voltage_device *)pboard_obj; | ||
184 | } | ||
185 | |||
186 | static u32 volt_get_voltage_device_table_1x_psv(struct gk20a *g, | ||
187 | struct vbios_voltage_device_table_1x_entry *p_bios_entry, | ||
188 | struct voltage_device_metadata *p_Volt_Device_Meta_Data, | ||
189 | u8 entry_Idx) | ||
190 | { | ||
191 | u32 status = 0; | ||
192 | u32 entry_cnt = 0; | ||
193 | struct voltage_device *pvolt_dev = NULL; | ||
194 | struct voltage_device_pwm *pvolt_dev_pwm = NULL; | ||
195 | struct voltage_device_pwm *ptmp_dev = NULL; | ||
196 | u32 duty_cycle; | ||
197 | u32 frequency_hz; | ||
198 | u32 voltage_uv; | ||
199 | u8 ext_dev_idx; | ||
200 | u8 steps; | ||
201 | u8 volt_domain = 0; | ||
202 | struct voltage_device_pwm_entry pwm_entry = { { 0 } }; | ||
203 | |||
204 | ptmp_dev = kzalloc(sizeof(struct voltage_device_pwm), GFP_KERNEL); | ||
205 | if (ptmp_dev == NULL) | ||
206 | return -ENOMEM; | ||
207 | |||
208 | frequency_hz = (u32)BIOS_GET_FIELD(p_bios_entry->param0, | ||
209 | NV_VBIOS_VDT_1X_ENTRY_PARAM0_PSV_INPUT_FREQUENCY); | ||
210 | |||
211 | ext_dev_idx = (u8)BIOS_GET_FIELD(p_bios_entry->param0, | ||
212 | NV_VBIOS_VDT_1X_ENTRY_PARAM0_PSV_EXT_DEVICE_INDEX); | ||
213 | |||
214 | ptmp_dev->super.operation_type = volt_dev_operation_type_convert( | ||
215 | (u8)BIOS_GET_FIELD(p_bios_entry->param1, | ||
216 | NV_VBIOS_VDT_1X_ENTRY_PARAM1_PSV_OPERATION_TYPE)); | ||
217 | |||
218 | if (ptmp_dev->super.operation_type == | ||
219 | CTRL_VOLT_DEVICE_OPERATION_TYPE_INVALID) { | ||
220 | gk20a_err(dev_from_gk20a(g), | ||
221 | " Invalid Voltage Device Operation Type."); | ||
222 | |||
223 | status = -EINVAL; | ||
224 | goto done; | ||
225 | } | ||
226 | |||
227 | ptmp_dev->super.voltage_min_uv = | ||
228 | (u32)BIOS_GET_FIELD(p_bios_entry->param1, | ||
229 | NV_VBIOS_VDT_1X_ENTRY_PARAM1_PSV_VOLTAGE_MINIMUM); | ||
230 | |||
231 | ptmp_dev->super.voltage_max_uv = | ||
232 | (u32)BIOS_GET_FIELD(p_bios_entry->param2, | ||
233 | NV_VBIOS_VDT_1X_ENTRY_PARAM2_PSV_VOLTAGE_MAXIMUM); | ||
234 | |||
235 | ptmp_dev->voltage_base_uv = BIOS_GET_FIELD(p_bios_entry->param3, | ||
236 | NV_VBIOS_VDT_1X_ENTRY_PARAM3_PSV_VOLTAGE_BASE); | ||
237 | |||
238 | steps = (u8)BIOS_GET_FIELD(p_bios_entry->param3, | ||
239 | NV_VBIOS_VDT_1X_ENTRY_PARAM3_PSV_VOLTAGE_STEPS); | ||
240 | if (steps == VOLT_DEV_PWM_VOLTAGE_STEPS_INVALID) | ||
241 | steps = VOLT_DEV_PWM_VOLTAGE_STEPS_DEFAULT; | ||
242 | |||
243 | ptmp_dev->voltage_offset_scale_uv = | ||
244 | BIOS_GET_FIELD(p_bios_entry->param4, | ||
245 | NV_VBIOS_VDT_1X_ENTRY_PARAM4_PSV_OFFSET_SCALE); | ||
246 | |||
247 | volt_domain = volt_rail_vbios_volt_domain_convert_to_internal(g, | ||
248 | (u8)p_bios_entry->volt_domain); | ||
249 | if (volt_domain == CTRL_VOLT_DOMAIN_INVALID) { | ||
250 | gk20a_err(dev_from_gk20a(g), | ||
251 | "invalid voltage domain = %d", | ||
252 | (u8)p_bios_entry->volt_domain); | ||
253 | status = -EINVAL; | ||
254 | goto done; | ||
255 | } | ||
256 | |||
257 | if (ptmp_dev->super.operation_type == | ||
258 | CTRL_VOLT_DEVICE_OPERATION_TYPE_DEFAULT) { | ||
259 | if (volt_domain == CTRL_VOLT_DOMAIN_LOGIC) | ||
260 | ptmp_dev->source = | ||
261 | NV_PMU_PMGR_PWM_SOURCE_THERM_VID_PWM_0; | ||
262 | if (volt_domain == CTRL_VOLT_DOMAIN_SRAM) | ||
263 | ptmp_dev->source = | ||
264 | NV_PMU_PMGR_PWM_SOURCE_THERM_VID_PWM_1; | ||
265 | ptmp_dev->raw_period = | ||
266 | g->ops.clk.get_crystal_clk_hz(g) / frequency_hz; | ||
267 | } else if (ptmp_dev->super.operation_type == | ||
268 | CTRL_VOLT_DEVICE_OPERATION_TYPE_LPWR_STEADY_STATE) { | ||
269 | ptmp_dev->source = NV_PMU_PMGR_PWM_SOURCE_RSVD_0; | ||
270 | ptmp_dev->raw_period = 0; | ||
271 | } else if (ptmp_dev->super.operation_type == | ||
272 | CTRL_VOLT_DEVICE_OPERATION_TYPE_LPWR_SLEEP_STATE) { | ||
273 | ptmp_dev->source = NV_PMU_PMGR_PWM_SOURCE_RSVD_1; | ||
274 | ptmp_dev->raw_period = 0; | ||
275 | } | ||
276 | |||
277 | /* Initialize data for parent class. */ | ||
278 | ptmp_dev->super.super.type = CTRL_VOLT_DEVICE_TYPE_PWM; | ||
279 | ptmp_dev->super.volt_domain = volt_domain; | ||
280 | ptmp_dev->super.i2c_dev_idx = ext_dev_idx; | ||
281 | ptmp_dev->super.switch_delay_us = (u16)p_bios_entry->settle_time_us; | ||
282 | |||
283 | pvolt_dev = volt_volt_device_construct(g, ptmp_dev); | ||
284 | if (pvolt_dev == NULL) { | ||
285 | gk20a_err(dev_from_gk20a(g), | ||
286 | " Failure to construct VOLTAGE_DEVICE object."); | ||
287 | |||
288 | status = -EINVAL; | ||
289 | goto done; | ||
290 | } | ||
291 | |||
292 | status = boardobjgrp_objinsert( | ||
293 | &p_Volt_Device_Meta_Data->volt_devices.super, | ||
294 | (struct boardobj *)pvolt_dev, entry_Idx); | ||
295 | if (status) { | ||
296 | gk20a_err(dev_from_gk20a(g), | ||
297 | "could not add VOLTAGE_DEVICE for entry %d into boardobjgrp ", | ||
298 | entry_Idx); | ||
299 | goto done; | ||
300 | } | ||
301 | |||
302 | pvolt_dev_pwm = (struct voltage_device_pwm *)pvolt_dev; | ||
303 | |||
304 | duty_cycle = 0; | ||
305 | do { | ||
306 | voltage_uv = (u32)(pvolt_dev_pwm->voltage_base_uv + | ||
307 | (s32)((((s64)((s32)duty_cycle)) * | ||
308 | pvolt_dev_pwm->voltage_offset_scale_uv) | ||
309 | / ((s64)((s32) pvolt_dev_pwm->raw_period)))); | ||
310 | |||
311 | /* Skip creating entry for invalid voltage. */ | ||
312 | if ((voltage_uv >= pvolt_dev_pwm->super.voltage_min_uv) && | ||
313 | (voltage_uv <= pvolt_dev_pwm->super.voltage_max_uv)) { | ||
314 | if (pvolt_dev_pwm->voltage_offset_scale_uv < 0) | ||
315 | pwm_entry.duty_cycle = | ||
316 | pvolt_dev_pwm->raw_period - duty_cycle; | ||
317 | else | ||
318 | pwm_entry.duty_cycle = duty_cycle; | ||
319 | |||
320 | /* Check if there is room left in the voltage table. */ | ||
321 | if (entry_cnt == VOLTAGE_TABLE_MAX_ENTRIES) { | ||
322 | gk20a_err(dev_from_gk20a(g), "Voltage table is full"); | ||
323 | status = -EINVAL; | ||
324 | goto done; | ||
325 | } | ||
326 | |||
327 | pvolt_dev->pentry[entry_cnt] = | ||
328 | volt_dev_construct_dev_entry_pwm(g, | ||
329 | voltage_uv, &pwm_entry); | ||
330 | if (pvolt_dev->pentry[entry_cnt] == NULL) { | ||
331 | gk20a_err(dev_from_gk20a(g), | ||
332 | " Error creating voltage_device_pwm_entry!"); | ||
333 | status = -EINVAL; | ||
334 | goto done; | ||
335 | } | ||
336 | |||
337 | entry_cnt++; | ||
338 | } | ||
339 | |||
340 | /* Obtain next value after the specified steps. */ | ||
341 | duty_cycle = duty_cycle + (u32)steps; | ||
342 | |||
343 | /* Cap duty cycle to PWM period. */ | ||
344 | if (duty_cycle > pvolt_dev_pwm->raw_period) | ||
345 | duty_cycle = pvolt_dev_pwm->raw_period; | ||
346 | |||
347 | } while (duty_cycle < pvolt_dev_pwm->raw_period); | ||
348 | |||
349 | done: | ||
350 | if (pvolt_dev != NULL) | ||
351 | pvolt_dev->num_entries = entry_cnt; | ||
352 | |||
353 | kfree(ptmp_dev); | ||
354 | return status; | ||
355 | } | ||
356 | |||
357 | static u32 volt_get_volt_devices_table(struct gk20a *g, | ||
358 | struct voltage_device_metadata *pvolt_device_metadata) | ||
359 | { | ||
360 | u32 status = 0; | ||
361 | u8 *volt_device_table_ptr = NULL; | ||
362 | struct vbios_voltage_device_table_1x_header header = { 0 }; | ||
363 | struct vbios_voltage_device_table_1x_entry entry = { 0 }; | ||
364 | u8 entry_idx; | ||
365 | u8 *entry_offset; | ||
366 | |||
367 | if (g->ops.bios.get_perf_table_ptrs) { | ||
368 | volt_device_table_ptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, | ||
369 | g->bios.perf_token, VOLTAGE_DEVICE_TABLE); | ||
370 | if (volt_device_table_ptr == NULL) { | ||
371 | status = -EINVAL; | ||
372 | goto done; | ||
373 | } | ||
374 | } else { | ||
375 | status = -EINVAL; | ||
376 | goto done; | ||
377 | } | ||
378 | |||
379 | memcpy(&header, volt_device_table_ptr, | ||
380 | sizeof(struct vbios_voltage_device_table_1x_header)); | ||
381 | |||
382 | /* Read in the entries. */ | ||
383 | for (entry_idx = 0; entry_idx < header.num_table_entries; entry_idx++) { | ||
384 | entry_offset = (volt_device_table_ptr + header.header_size + | ||
385 | (entry_idx * header.table_entry_size)); | ||
386 | |||
387 | memcpy(&entry, entry_offset, | ||
388 | sizeof(struct vbios_voltage_device_table_1x_entry)); | ||
389 | |||
390 | if (entry.type == NV_VBIOS_VOLTAGE_DEVICE_1X_ENTRY_TYPE_PSV) | ||
391 | status = volt_get_voltage_device_table_1x_psv(g, | ||
392 | &entry, pvolt_device_metadata, | ||
393 | entry_idx); | ||
394 | } | ||
395 | |||
396 | done: | ||
397 | return status; | ||
398 | } | ||
399 | |||
400 | static u32 _volt_device_devgrp_pmudata_instget(struct gk20a *g, | ||
401 | struct nv_pmu_boardobjgrp *pmuboardobjgrp, | ||
402 | struct nv_pmu_boardobj **ppboardobjpmudata, u8 idx) | ||
403 | { | ||
404 | struct nv_pmu_volt_volt_device_boardobj_grp_set *pgrp_set = | ||
405 | (struct nv_pmu_volt_volt_device_boardobj_grp_set *) | ||
406 | pmuboardobjgrp; | ||
407 | |||
408 | gk20a_dbg_info(""); | ||
409 | |||
410 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
411 | if (((u32)BIT(idx) & | ||
412 | pgrp_set->hdr.data.super.obj_mask.super.data[0]) == 0) | ||
413 | return -EINVAL; | ||
414 | |||
415 | *ppboardobjpmudata = (struct nv_pmu_boardobj *) | ||
416 | &pgrp_set->objects[idx].data.board_obj; | ||
417 | gk20a_dbg_info("Done"); | ||
418 | return 0; | ||
419 | } | ||
420 | |||
421 | static u32 _volt_device_devgrp_pmustatus_instget(struct gk20a *g, | ||
422 | void *pboardobjgrppmu, | ||
423 | struct nv_pmu_boardobj_query **ppboardobjpmustatus, u8 idx) | ||
424 | { | ||
425 | struct nv_pmu_volt_volt_device_boardobj_grp_get_status *pgrp_get_status | ||
426 | = (struct nv_pmu_volt_volt_device_boardobj_grp_get_status *) | ||
427 | pboardobjgrppmu; | ||
428 | |||
429 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
430 | if (((u32)BIT(idx) & | ||
431 | pgrp_get_status->hdr.data.super.obj_mask.super.data[0]) == 0) | ||
432 | return -EINVAL; | ||
433 | |||
434 | *ppboardobjpmustatus = (struct nv_pmu_boardobj_query *) | ||
435 | &pgrp_get_status->objects[idx].data.board_obj; | ||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | static int volt_device_volt_cmp(const void *a, const void *b) | ||
440 | { | ||
441 | const struct voltage_device_entry *a_entry = *(const struct voltage_device_entry **)a; | ||
442 | const struct voltage_device_entry *b_entry = *(const struct voltage_device_entry **)b; | ||
443 | |||
444 | return (int)a_entry->voltage_uv - (int)b_entry->voltage_uv; | ||
445 | } | ||
446 | |||
447 | u32 volt_device_state_init(struct gk20a *g, struct voltage_device *pvolt_dev) | ||
448 | { | ||
449 | u32 status = 0; | ||
450 | struct voltage_rail *pRail = NULL; | ||
451 | u8 rail_idx = 0; | ||
452 | |||
453 | sort(pvolt_dev->pentry, pvolt_dev->num_entries, | ||
454 | sizeof(*pvolt_dev->pentry), volt_device_volt_cmp, | ||
455 | NULL); | ||
456 | |||
457 | /* Initialize VOLT_DEVICE step size. */ | ||
458 | if (pvolt_dev->num_entries <= VOLTAGE_TABLE_MAX_ENTRIES_ONE) | ||
459 | pvolt_dev->volt_step_uv = NV_PMU_VOLT_VALUE_0V_IN_UV; | ||
460 | else | ||
461 | pvolt_dev->volt_step_uv = (pvolt_dev->pentry[1]->voltage_uv - | ||
462 | pvolt_dev->pentry[0]->voltage_uv); | ||
463 | |||
464 | /* Build VOLT_RAIL SW state from VOLT_DEVICE SW state. */ | ||
465 | /* If VOLT_RAIL isn't supported, exit. */ | ||
466 | if (VOLT_RAIL_VOLT_3X_SUPPORTED(&g->perf_pmu.volt)) { | ||
467 | rail_idx = volt_rail_volt_domain_convert_to_idx(g, | ||
468 | pvolt_dev->volt_domain); | ||
469 | if (rail_idx == CTRL_BOARDOBJ_IDX_INVALID) { | ||
470 | gk20a_err(dev_from_gk20a(g), | ||
471 | " could not convert voltage domain to rail index."); | ||
472 | status = -EINVAL; | ||
473 | goto done; | ||
474 | } | ||
475 | |||
476 | pRail = VOLT_GET_VOLT_RAIL(&g->perf_pmu.volt, rail_idx); | ||
477 | if (pRail == NULL) { | ||
478 | gk20a_err(dev_from_gk20a(g), | ||
479 | "could not obtain ptr to rail object from rail index"); | ||
480 | status = -EINVAL; | ||
481 | goto done; | ||
482 | } | ||
483 | |||
484 | status = volt_rail_volt_dev_register(g, pRail, | ||
485 | BOARDOBJ_GET_IDX(pvolt_dev), pvolt_dev->operation_type); | ||
486 | if (status) { | ||
487 | gk20a_err(dev_from_gk20a(g), | ||
488 | "Failed to register the device with rail obj"); | ||
489 | goto done; | ||
490 | } | ||
491 | } | ||
492 | |||
493 | done: | ||
494 | if (status) | ||
495 | gk20a_err(dev_from_gk20a(g), | ||
496 | "Error in building rail sw state device sw"); | ||
497 | |||
498 | return status; | ||
499 | } | ||
500 | |||
501 | u32 volt_dev_pmu_setup(struct gk20a *g) | ||
502 | { | ||
503 | u32 status; | ||
504 | struct boardobjgrp *pboardobjgrp = NULL; | ||
505 | |||
506 | gk20a_dbg_info(""); | ||
507 | |||
508 | pboardobjgrp = &g->perf_pmu.volt.volt_dev_metadata.volt_devices.super; | ||
509 | |||
510 | if (!pboardobjgrp->bconstructed) | ||
511 | return -EINVAL; | ||
512 | |||
513 | status = pboardobjgrp->pmuinithandle(g, pboardobjgrp); | ||
514 | |||
515 | gk20a_dbg_info("Done"); | ||
516 | return status; | ||
517 | } | ||
518 | |||
519 | u32 volt_dev_sw_setup(struct gk20a *g) | ||
520 | { | ||
521 | u32 status = 0; | ||
522 | struct boardobjgrp *pboardobjgrp = NULL; | ||
523 | struct voltage_device *pvolt_device; | ||
524 | u8 i; | ||
525 | |||
526 | gk20a_dbg_info(""); | ||
527 | |||
528 | status = boardobjgrpconstruct_e32(&g->perf_pmu.volt.volt_dev_metadata. | ||
529 | volt_devices); | ||
530 | if (status) { | ||
531 | gk20a_err(dev_from_gk20a(g), | ||
532 | "error creating boardobjgrp for volt rail, status - 0x%x", | ||
533 | status); | ||
534 | goto done; | ||
535 | } | ||
536 | |||
537 | pboardobjgrp = &g->perf_pmu.volt.volt_dev_metadata.volt_devices.super; | ||
538 | |||
539 | pboardobjgrp->pmudatainstget = _volt_device_devgrp_pmudata_instget; | ||
540 | pboardobjgrp->pmustatusinstget = _volt_device_devgrp_pmustatus_instget; | ||
541 | |||
542 | /* Obtain Voltage Rail Table from VBIOS */ | ||
543 | status = volt_get_volt_devices_table(g, &g->perf_pmu.volt. | ||
544 | volt_dev_metadata); | ||
545 | if (status) | ||
546 | goto done; | ||
547 | |||
548 | /* Populate data for the VOLT_RAIL PMU interface */ | ||
549 | BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, VOLT, VOLT_DEVICE); | ||
550 | |||
551 | status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp, | ||
552 | volt, VOLT, volt_device, VOLT_DEVICE); | ||
553 | if (status) { | ||
554 | gk20a_err(dev_from_gk20a(g), | ||
555 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
556 | status); | ||
557 | goto done; | ||
558 | } | ||
559 | |||
560 | status = BOARDOBJGRP_PMU_CMD_GRP_GET_STATUS_CONSTRUCT(g, | ||
561 | &g->perf_pmu.volt.volt_dev_metadata.volt_devices.super, | ||
562 | volt, VOLT, volt_device, VOLT_DEVICE); | ||
563 | if (status) { | ||
564 | gk20a_err(dev_from_gk20a(g), | ||
565 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
566 | status); | ||
567 | goto done; | ||
568 | } | ||
569 | |||
570 | /* update calibration to fuse */ | ||
571 | BOARDOBJGRP_FOR_EACH(&(g->perf_pmu.volt.volt_dev_metadata.volt_devices. | ||
572 | super), | ||
573 | struct voltage_device *, pvolt_device, i) { | ||
574 | status = volt_device_state_init(g, pvolt_device); | ||
575 | if (status) { | ||
576 | gk20a_err(dev_from_gk20a(g), | ||
577 | "failure while executing devices's state init interface"); | ||
578 | gk20a_err(dev_from_gk20a(g), | ||
579 | " railIdx = %d, status = 0x%x", i, status); | ||
580 | goto done; | ||
581 | } | ||
582 | } | ||
583 | |||
584 | done: | ||
585 | gk20a_dbg_info(" done status %x", status); | ||
586 | return status; | ||
587 | } | ||
588 | |||