xref: /linux/drivers/gpu/drm/amd/amdgpu/isp_v4_1_0.c (revision 69050f8d6d075dc01af7a5f2f550a8067510366f)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
4  * All Rights Reserved.
5  *
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:
13  *
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.
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
26  */
27 
28 #include "amdgpu.h"
29 #include "isp_v4_1_0.h"
30 
31 static const unsigned int isp_4_1_0_int_srcid[MAX_ISP410_INT_SRC] = {
32 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT9,
33 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT10,
34 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT11,
35 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT12,
36 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT13,
37 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT14,
38 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT15,
39 	ISP_4_1__SRCID__ISP_RINGBUFFER_WPT16
40 };
41 
42 static int isp_v4_1_0_hw_init(struct amdgpu_isp *isp)
43 {
44 	struct amdgpu_device *adev = isp->adev;
45 	int idx, int_idx, num_res, r;
46 	u64 isp_base;
47 
48 	if (adev->rmmio_size == 0 || adev->rmmio_size < 0x5289)
49 		return -EINVAL;
50 
51 	isp_base = adev->rmmio_base;
52 
53 	isp->isp_cell = kzalloc_objs(struct mfd_cell, 3, GFP_KERNEL);
54 	if (!isp->isp_cell) {
55 		r = -ENOMEM;
56 		drm_err(&adev->ddev,
57 			"%s: isp mfd cell alloc failed\n", __func__);
58 		goto failure;
59 	}
60 
61 	num_res = MAX_ISP410_MEM_RES + MAX_ISP410_INT_SRC;
62 	isp->isp_res = kzalloc_objs(struct resource, num_res, GFP_KERNEL);
63 	if (!isp->isp_res) {
64 		r = -ENOMEM;
65 		drm_err(&adev->ddev,
66 			"%s: isp mfd res alloc failed\n", __func__);
67 		goto failure;
68 	}
69 
70 	isp->isp_pdata = kzalloc_obj(*isp->isp_pdata, GFP_KERNEL);
71 	if (!isp->isp_pdata) {
72 		r = -ENOMEM;
73 		drm_err(&adev->ddev,
74 			"%s: isp platform data alloc failed\n", __func__);
75 		goto failure;
76 	}
77 
78 	/* initialize isp platform data */
79 	isp->isp_pdata->adev = (void *)adev;
80 	isp->isp_pdata->asic_type = adev->asic_type;
81 	isp->isp_pdata->base_rmmio_size = adev->rmmio_size;
82 
83 	isp->isp_res[0].name = "isp_4_1_0_reg";
84 	isp->isp_res[0].flags = IORESOURCE_MEM;
85 	isp->isp_res[0].start = isp_base;
86 	isp->isp_res[0].end = isp_base + ISP_REGS_OFFSET_END;
87 
88 	isp->isp_res[1].name = "isp_4_1_phy0_reg";
89 	isp->isp_res[1].flags = IORESOURCE_MEM;
90 	isp->isp_res[1].start = isp_base + ISP410_PHY0_OFFSET;
91 	isp->isp_res[1].end = isp_base + ISP410_PHY0_OFFSET + ISP410_PHY0_SIZE;
92 
93 	for (idx = MAX_ISP410_MEM_RES, int_idx = 0; idx < num_res; idx++, int_idx++) {
94 		isp->isp_res[idx].name = "isp_4_1_0_irq";
95 		isp->isp_res[idx].flags = IORESOURCE_IRQ;
96 		isp->isp_res[idx].start =
97 			amdgpu_irq_create_mapping(adev, isp_4_1_0_int_srcid[int_idx]);
98 		isp->isp_res[idx].end =
99 			isp->isp_res[idx].start;
100 	}
101 
102 	isp->isp_cell[0].name = "amd_isp_capture";
103 	isp->isp_cell[0].num_resources = num_res;
104 	isp->isp_cell[0].resources = &isp->isp_res[0];
105 	isp->isp_cell[0].platform_data = isp->isp_pdata;
106 	isp->isp_cell[0].pdata_size = sizeof(struct isp_platform_data);
107 
108 	/* initialize isp i2c platform data */
109 	isp->isp_i2c_res = kzalloc_objs(struct resource, 1, GFP_KERNEL);
110 	if (!isp->isp_i2c_res) {
111 		r = -ENOMEM;
112 		drm_err(&adev->ddev,
113 			"%s: isp mfd res alloc failed\n", __func__);
114 		goto failure;
115 	}
116 
117 	isp->isp_i2c_res[0].name = "isp_i2c0_reg";
118 	isp->isp_i2c_res[0].flags = IORESOURCE_MEM;
119 	isp->isp_i2c_res[0].start = isp_base + ISP410_I2C0_OFFSET;
120 	isp->isp_i2c_res[0].end = isp_base + ISP410_I2C0_OFFSET + ISP410_I2C0_SIZE;
121 
122 	isp->isp_cell[1].name = "amd_isp_i2c_designware";
123 	isp->isp_cell[1].num_resources = 1;
124 	isp->isp_cell[1].resources = &isp->isp_i2c_res[0];
125 	isp->isp_cell[1].platform_data = isp->isp_pdata;
126 	isp->isp_cell[1].pdata_size = sizeof(struct isp_platform_data);
127 
128 	/* initialize isp gpiochip platform data */
129 	isp->isp_gpio_res = kzalloc_objs(struct resource, 1, GFP_KERNEL);
130 	if (!isp->isp_gpio_res) {
131 		r = -ENOMEM;
132 		drm_err(&adev->ddev,
133 			"%s: isp gpio res alloc failed\n", __func__);
134 		goto failure;
135 	}
136 
137 	isp->isp_gpio_res[0].name = "isp_gpio_reg";
138 	isp->isp_gpio_res[0].flags = IORESOURCE_MEM;
139 	isp->isp_gpio_res[0].start = isp_base + ISP410_GPIO_SENSOR_OFFSET;
140 	isp->isp_gpio_res[0].end = isp_base + ISP410_GPIO_SENSOR_OFFSET +
141 				   ISP410_GPIO_SENSOR_SIZE;
142 
143 	isp->isp_cell[2].name = "amdisp-pinctrl";
144 	isp->isp_cell[2].num_resources = 1;
145 	isp->isp_cell[2].resources = &isp->isp_gpio_res[0];
146 	isp->isp_cell[2].platform_data = isp->isp_pdata;
147 	isp->isp_cell[2].pdata_size = sizeof(struct isp_platform_data);
148 
149 	r = mfd_add_hotplug_devices(isp->parent, isp->isp_cell, 3);
150 	if (r) {
151 		drm_err(&adev->ddev,
152 			"%s: add mfd hotplug device failed\n", __func__);
153 		goto failure;
154 	}
155 
156 	return 0;
157 
158 failure:
159 
160 	kfree(isp->isp_pdata);
161 	kfree(isp->isp_res);
162 	kfree(isp->isp_cell);
163 	kfree(isp->isp_i2c_res);
164 	kfree(isp->isp_gpio_res);
165 
166 	return r;
167 }
168 
169 static int isp_v4_1_0_hw_fini(struct amdgpu_isp *isp)
170 {
171 	mfd_remove_devices(isp->parent);
172 
173 	kfree(isp->isp_res);
174 	kfree(isp->isp_cell);
175 	kfree(isp->isp_pdata);
176 	kfree(isp->isp_i2c_res);
177 	kfree(isp->isp_gpio_res);
178 
179 	return 0;
180 }
181 
182 static const struct isp_funcs isp_v4_1_0_funcs = {
183 	.hw_init = isp_v4_1_0_hw_init,
184 	.hw_fini = isp_v4_1_0_hw_fini,
185 };
186 
187 void isp_v4_1_0_set_isp_funcs(struct amdgpu_isp *isp)
188 {
189 	isp->funcs = &isp_v4_1_0_funcs;
190 }
191