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"
37 * isp_hw_init - start and test isp block
39 * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
42 static int isp_hw_init(struct amdgpu_ip_block *ip_block)
44 struct amdgpu_device *adev = ip_block->adev;
45 struct amdgpu_isp *isp = &adev->isp;
47 if (isp->funcs->hw_init != NULL)
48 return isp->funcs->hw_init(isp);
54 * isp_hw_fini - stop the hardware block
56 * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
59 static int isp_hw_fini(struct amdgpu_ip_block *ip_block)
61 struct amdgpu_isp *isp = &ip_block->adev->isp;
63 if (isp->funcs->hw_fini != NULL)
64 return isp->funcs->hw_fini(isp);
69 static int isp_load_fw_by_psp(struct amdgpu_device *adev)
71 const struct common_firmware_header *hdr;
72 char ucode_prefix[10];
75 /* get isp fw binary name and path */
76 amdgpu_ucode_ip_version_decode(adev, ISP_HWIP, ucode_prefix,
77 sizeof(ucode_prefix));
80 r = amdgpu_ucode_request(adev, &adev->isp.fw, AMDGPU_UCODE_OPTIONAL,
81 "amdgpu/%s.bin", ucode_prefix);
83 amdgpu_ucode_release(&adev->isp.fw);
87 hdr = (const struct common_firmware_header *)adev->isp.fw->data;
89 adev->firmware.ucode[AMDGPU_UCODE_ID_ISP].ucode_id =
91 adev->firmware.ucode[AMDGPU_UCODE_ID_ISP].fw = adev->isp.fw;
93 adev->firmware.fw_size +=
94 ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
99 static int isp_early_init(struct amdgpu_ip_block *ip_block)
102 struct amdgpu_device *adev = ip_block->adev;
103 struct amdgpu_isp *isp = &adev->isp;
105 switch (amdgpu_ip_version(adev, ISP_HWIP, 0)) {
106 case IP_VERSION(4, 1, 0):
107 isp_v4_1_0_set_isp_funcs(isp);
109 case IP_VERSION(4, 1, 1):
110 isp_v4_1_1_set_isp_funcs(isp);
117 isp->parent = adev->dev;
119 if (isp_load_fw_by_psp(adev)) {
120 DRM_DEBUG_DRIVER("%s: isp fw load failed\n", __func__);
127 static bool isp_is_idle(void *handle)
132 static int isp_set_clockgating_state(struct amdgpu_ip_block *ip_block,
133 enum amd_clockgating_state state)
138 static int isp_set_powergating_state(struct amdgpu_ip_block *ip_block,
139 enum amd_powergating_state state)
144 static const struct amd_ip_funcs isp_ip_funcs = {
146 .early_init = isp_early_init,
147 .hw_init = isp_hw_init,
148 .hw_fini = isp_hw_fini,
149 .is_idle = isp_is_idle,
150 .set_clockgating_state = isp_set_clockgating_state,
151 .set_powergating_state = isp_set_powergating_state,
154 const struct amdgpu_ip_block_version isp_v4_1_0_ip_block = {
155 .type = AMD_IP_BLOCK_TYPE_ISP,
159 .funcs = &isp_ip_funcs,
162 const struct amdgpu_ip_block_version isp_v4_1_1_ip_block = {
163 .type = AMD_IP_BLOCK_TYPE_ISP,
167 .funcs = &isp_ip_funcs,