2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "common_baco.h"
27 static bool baco_wait_register(struct pp_hwmgr *hwmgr, u32 reg, u32 mask, u32 value)
29 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
30 u32 timeout = 5000, data;
36 } while (value != (data & mask) && (timeout != 0));
44 static bool baco_cmd_handler(struct pp_hwmgr *hwmgr, u32 command, u32 reg, u32 mask,
45 u32 shift, u32 value, u32 timeout)
47 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
53 WREG32(reg, value << shift);
55 case CMD_READMODIFYWRITE:
57 data = (data & (~mask)) | (value << shift);
61 ret = baco_wait_register(hwmgr, reg, mask, value);
65 /* Delay in milli Seconds */
70 /* Delay in micro Seconds */
75 dev_warn(adev->dev, "Invalid BACO command.\n");
82 bool soc15_baco_program_registers(struct pp_hwmgr *hwmgr,
83 const struct soc15_baco_cmd_entry *entry,
86 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
89 for (i = 0; i < array_size; i++) {
90 if ((entry[i].cmd == CMD_WRITE) ||
91 (entry[i].cmd == CMD_READMODIFYWRITE) ||
92 (entry[i].cmd == CMD_WAITFOR))
93 reg = adev->reg_offset[entry[i].hwip][entry[i].inst][entry[i].seg]
94 + entry[i].reg_offset;
95 if (!baco_cmd_handler(hwmgr, entry[i].cmd, reg, entry[i].mask,
96 entry[i].shift, entry[i].val, entry[i].timeout))