1 /* SPDX-License-Identifier: MIT */
3 * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
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 NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 #include <linux/firmware.h>
29 #include <linux/mfd/core.h>
32 #include "amdgpu_isp.h"
33 #include "isp_v4_1_0.h"
34 #include "isp_v4_1_1.h"
36 static int isp_sw_fini(struct amdgpu_ip_block *ip_block)
42 * isp_hw_init - start and test isp block
44 * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
47 static int isp_hw_init(struct amdgpu_ip_block *ip_block)
49 struct amdgpu_device *adev = ip_block->adev;
50 struct amdgpu_isp *isp = &adev->isp;
52 if (isp->funcs->hw_init != NULL)
53 return isp->funcs->hw_init(isp);
59 * isp_hw_fini - stop the hardware block
61 * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
64 static int isp_hw_fini(struct amdgpu_ip_block *ip_block)
66 struct amdgpu_isp *isp = &ip_block->adev->isp;
68 if (isp->funcs->hw_fini != NULL)
69 return isp->funcs->hw_fini(isp);
74 static int isp_suspend(struct amdgpu_ip_block *ip_block)
79 static int isp_resume(struct amdgpu_ip_block *ip_block)
84 static int isp_load_fw_by_psp(struct amdgpu_device *adev)
86 const struct common_firmware_header *hdr;
87 char ucode_prefix[10];
90 /* get isp fw binary name and path */
91 amdgpu_ucode_ip_version_decode(adev, ISP_HWIP, ucode_prefix,
92 sizeof(ucode_prefix));
95 r = amdgpu_ucode_request(adev, &adev->isp.fw, "amdgpu/%s.bin", ucode_prefix);
97 amdgpu_ucode_release(&adev->isp.fw);
101 hdr = (const struct common_firmware_header *)adev->isp.fw->data;
103 adev->firmware.ucode[AMDGPU_UCODE_ID_ISP].ucode_id =
105 adev->firmware.ucode[AMDGPU_UCODE_ID_ISP].fw = adev->isp.fw;
107 adev->firmware.fw_size +=
108 ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
113 static int isp_early_init(struct amdgpu_ip_block *ip_block)
116 struct amdgpu_device *adev = ip_block->adev;
117 struct amdgpu_isp *isp = &adev->isp;
119 switch (amdgpu_ip_version(adev, ISP_HWIP, 0)) {
120 case IP_VERSION(4, 1, 0):
121 isp_v4_1_0_set_isp_funcs(isp);
123 case IP_VERSION(4, 1, 1):
124 isp_v4_1_1_set_isp_funcs(isp);
131 isp->parent = adev->dev;
133 if (isp_load_fw_by_psp(adev)) {
134 DRM_DEBUG_DRIVER("%s: isp fw load failed\n", __func__);
141 static bool isp_is_idle(void *handle)
146 static int isp_wait_for_idle(struct amdgpu_ip_block *ip_block)
151 static int isp_soft_reset(struct amdgpu_ip_block *ip_block)
156 static int isp_set_clockgating_state(void *handle,
157 enum amd_clockgating_state state)
162 static int isp_set_powergating_state(void *handle,
163 enum amd_powergating_state state)
168 static const struct amd_ip_funcs isp_ip_funcs = {
170 .early_init = isp_early_init,
172 .sw_fini = isp_sw_fini,
173 .hw_init = isp_hw_init,
174 .hw_fini = isp_hw_fini,
175 .suspend = isp_suspend,
176 .resume = isp_resume,
177 .is_idle = isp_is_idle,
178 .wait_for_idle = isp_wait_for_idle,
179 .soft_reset = isp_soft_reset,
180 .set_clockgating_state = isp_set_clockgating_state,
181 .set_powergating_state = isp_set_powergating_state,
184 const struct amdgpu_ip_block_version isp_v4_1_0_ip_block = {
185 .type = AMD_IP_BLOCK_TYPE_ISP,
189 .funcs = &isp_ip_funcs,
192 const struct amdgpu_ip_block_version isp_v4_1_1_ip_block = {
193 .type = AMD_IP_BLOCK_TYPE_ISP,
197 .funcs = &isp_ip_funcs,