xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c (revision db5d28c0bfe566908719bec8e25443aabecbb802)
1a8fe58ceSMaruthi Bayyavarapu /*
2a8fe58ceSMaruthi Bayyavarapu  * Copyright 2015 Advanced Micro Devices, Inc.
3a8fe58ceSMaruthi Bayyavarapu  *
4a8fe58ceSMaruthi Bayyavarapu  * Permission is hereby granted, free of charge, to any person obtaining a
5a8fe58ceSMaruthi Bayyavarapu  * copy of this software and associated documentation files (the "Software"),
6a8fe58ceSMaruthi Bayyavarapu  * to deal in the Software without restriction, including without limitation
7a8fe58ceSMaruthi Bayyavarapu  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8a8fe58ceSMaruthi Bayyavarapu  * and/or sell copies of the Software, and to permit persons to whom the
9a8fe58ceSMaruthi Bayyavarapu  * Software is furnished to do so, subject to the following conditions:
10a8fe58ceSMaruthi Bayyavarapu  *
11a8fe58ceSMaruthi Bayyavarapu  * The above copyright notice and this permission notice shall be included in
12a8fe58ceSMaruthi Bayyavarapu  * all copies or substantial portions of the Software.
13a8fe58ceSMaruthi Bayyavarapu  *
14a8fe58ceSMaruthi Bayyavarapu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15a8fe58ceSMaruthi Bayyavarapu  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16a8fe58ceSMaruthi Bayyavarapu  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17a8fe58ceSMaruthi Bayyavarapu  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18a8fe58ceSMaruthi Bayyavarapu  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19a8fe58ceSMaruthi Bayyavarapu  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20a8fe58ceSMaruthi Bayyavarapu  * OTHER DEALINGS IN THE SOFTWARE.
21a8fe58ceSMaruthi Bayyavarapu  *
22a8fe58ceSMaruthi Bayyavarapu  * Authors: AMD
23a8fe58ceSMaruthi Bayyavarapu  *
24a8fe58ceSMaruthi Bayyavarapu  */
25a8fe58ceSMaruthi Bayyavarapu 
26a8fe58ceSMaruthi Bayyavarapu #include <linux/irqdomain.h>
27841d0023SSam Ravnborg #include <linux/pci.h>
2825030321SMaruthi Srinivas Bayyavarapu #include <linux/pm_domain.h>
29a8fe58ceSMaruthi Bayyavarapu #include <linux/platform_device.h>
30a8fe58ceSMaruthi Bayyavarapu #include <sound/designware_i2s.h>
31a8fe58ceSMaruthi Bayyavarapu #include <sound/pcm.h>
3249062ee3SVijendar Mukunda #include <linux/acpi.h>
3349062ee3SVijendar Mukunda #include <linux/dmi.h>
34a8fe58ceSMaruthi Bayyavarapu 
35a8fe58ceSMaruthi Bayyavarapu #include "amdgpu.h"
36a8fe58ceSMaruthi Bayyavarapu #include "atom.h"
37a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
38a8fe58ceSMaruthi Bayyavarapu 
39a8fe58ceSMaruthi Bayyavarapu #include "acp_gfx_if.h"
40a8fe58ceSMaruthi Bayyavarapu 
4149062ee3SVijendar Mukunda #define ST_JADEITE 1
42a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_ON_MASK			0x03
43a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_OFF_MASK			0x02
44a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_ON_RETAIN_REG_MASK		0x1f
45a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_OFF_RETAIN_REG_MASK		0x20
46a8fe58ceSMaruthi Bayyavarapu 
47a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_P1_MASK			0x3e
48a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_P2_MASK			0x3d
49a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_DSP0_MASK			0x3b
50a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_DSP1_MASK			0x37
51a8fe58ceSMaruthi Bayyavarapu 
52a8fe58ceSMaruthi Bayyavarapu #define ACP_TILE_DSP2_MASK			0x2f
53a8fe58ceSMaruthi Bayyavarapu 
54a8fe58ceSMaruthi Bayyavarapu #define ACP_DMA_REGS_END			0x146c0
55a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_PLAY_REGS_START			0x14840
56a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_PLAY_REGS_END			0x148b4
57a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_CAP_REGS_START			0x148b8
58a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_CAP_REGS_END			0x1496c
59a8fe58ceSMaruthi Bayyavarapu 
60a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_COMP1_CAP_REG_OFFSET		0xac
61a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_COMP2_CAP_REG_OFFSET		0xa8
62a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_COMP1_PLAY_REG_OFFSET		0x6c
63a8fe58ceSMaruthi Bayyavarapu #define ACP_I2S_COMP2_PLAY_REG_OFFSET		0x68
642d95ceb4SVijendar Mukunda #define ACP_BT_PLAY_REGS_START			0x14970
652d95ceb4SVijendar Mukunda #define ACP_BT_PLAY_REGS_END			0x14a24
662d95ceb4SVijendar Mukunda #define ACP_BT_COMP1_REG_OFFSET			0xac
672d95ceb4SVijendar Mukunda #define ACP_BT_COMP2_REG_OFFSET			0xa8
68a8fe58ceSMaruthi Bayyavarapu 
69a8fe58ceSMaruthi Bayyavarapu #define mmACP_PGFSM_RETAIN_REG			0x51c9
70a8fe58ceSMaruthi Bayyavarapu #define mmACP_PGFSM_CONFIG_REG			0x51ca
71a8fe58ceSMaruthi Bayyavarapu #define mmACP_PGFSM_READ_REG_0			0x51cc
72a8fe58ceSMaruthi Bayyavarapu 
73a8fe58ceSMaruthi Bayyavarapu #define mmACP_MEM_SHUT_DOWN_REQ_LO		0x51f8
74a8fe58ceSMaruthi Bayyavarapu #define mmACP_MEM_SHUT_DOWN_REQ_HI		0x51f9
75a8fe58ceSMaruthi Bayyavarapu #define mmACP_MEM_SHUT_DOWN_STS_LO		0x51fa
76a8fe58ceSMaruthi Bayyavarapu #define mmACP_MEM_SHUT_DOWN_STS_HI		0x51fb
77a8fe58ceSMaruthi Bayyavarapu 
7837c5f2c9SAkshu Agrawal #define mmACP_CONTROL				0x5131
7937c5f2c9SAkshu Agrawal #define mmACP_STATUS				0x5133
8037c5f2c9SAkshu Agrawal #define mmACP_SOFT_RESET			0x5134
8137c5f2c9SAkshu Agrawal #define ACP_CONTROL__ClkEn_MASK			0x1
8237c5f2c9SAkshu Agrawal #define ACP_SOFT_RESET__SoftResetAud_MASK	0x100
8337c5f2c9SAkshu Agrawal #define ACP_SOFT_RESET__SoftResetAudDone_MASK	0x1000000
8437c5f2c9SAkshu Agrawal #define ACP_CLOCK_EN_TIME_OUT_VALUE		0x000000FF
8537c5f2c9SAkshu Agrawal #define ACP_SOFT_RESET_DONE_TIME_OUT_VALUE	0x000000FF
8637c5f2c9SAkshu Agrawal 
87a8fe58ceSMaruthi Bayyavarapu #define ACP_TIMEOUT_LOOP			0x000000FF
882d95ceb4SVijendar Mukunda #define ACP_DEVS				4
89a8fe58ceSMaruthi Bayyavarapu #define ACP_SRC_ID				162
90a8fe58ceSMaruthi Bayyavarapu 
9149062ee3SVijendar Mukunda static unsigned long acp_machine_id;
9249062ee3SVijendar Mukunda 
93a8fe58ceSMaruthi Bayyavarapu enum {
94a8fe58ceSMaruthi Bayyavarapu 	ACP_TILE_P1 = 0,
95a8fe58ceSMaruthi Bayyavarapu 	ACP_TILE_P2,
96a8fe58ceSMaruthi Bayyavarapu 	ACP_TILE_DSP0,
97a8fe58ceSMaruthi Bayyavarapu 	ACP_TILE_DSP1,
98a8fe58ceSMaruthi Bayyavarapu 	ACP_TILE_DSP2,
99a8fe58ceSMaruthi Bayyavarapu };
100a8fe58ceSMaruthi Bayyavarapu 
acp_sw_init(void * handle)101a8fe58ceSMaruthi Bayyavarapu static int acp_sw_init(void *handle)
102a8fe58ceSMaruthi Bayyavarapu {
103a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
104a8fe58ceSMaruthi Bayyavarapu 
105a8fe58ceSMaruthi Bayyavarapu 	adev->acp.parent = adev->dev;
106a8fe58ceSMaruthi Bayyavarapu 
107a8fe58ceSMaruthi Bayyavarapu 	adev->acp.cgs_device =
108a8fe58ceSMaruthi Bayyavarapu 		amdgpu_cgs_create_device(adev);
109a8fe58ceSMaruthi Bayyavarapu 	if (!adev->acp.cgs_device)
110a8fe58ceSMaruthi Bayyavarapu 		return -EINVAL;
111a8fe58ceSMaruthi Bayyavarapu 
112a8fe58ceSMaruthi Bayyavarapu 	return 0;
113a8fe58ceSMaruthi Bayyavarapu }
114a8fe58ceSMaruthi Bayyavarapu 
acp_sw_fini(void * handle)115a8fe58ceSMaruthi Bayyavarapu static int acp_sw_fini(void *handle)
116a8fe58ceSMaruthi Bayyavarapu {
117a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
118a8fe58ceSMaruthi Bayyavarapu 
119a8fe58ceSMaruthi Bayyavarapu 	if (adev->acp.cgs_device)
120a8fe58ceSMaruthi Bayyavarapu 		amdgpu_cgs_destroy_device(adev->acp.cgs_device);
121a8fe58ceSMaruthi Bayyavarapu 
122a8fe58ceSMaruthi Bayyavarapu 	return 0;
123a8fe58ceSMaruthi Bayyavarapu }
124a8fe58ceSMaruthi Bayyavarapu 
12525030321SMaruthi Srinivas Bayyavarapu struct acp_pm_domain {
1263a54d2c8SRex Zhu 	void *adev;
12725030321SMaruthi Srinivas Bayyavarapu 	struct generic_pm_domain gpd;
12825030321SMaruthi Srinivas Bayyavarapu };
12925030321SMaruthi Srinivas Bayyavarapu 
acp_poweroff(struct generic_pm_domain * genpd)13025030321SMaruthi Srinivas Bayyavarapu static int acp_poweroff(struct generic_pm_domain *genpd)
13125030321SMaruthi Srinivas Bayyavarapu {
13225030321SMaruthi Srinivas Bayyavarapu 	struct acp_pm_domain *apd;
1333a54d2c8SRex Zhu 	struct amdgpu_device *adev;
13425030321SMaruthi Srinivas Bayyavarapu 
13525030321SMaruthi Srinivas Bayyavarapu 	apd = container_of(genpd, struct acp_pm_domain, gpd);
1363a54d2c8SRex Zhu 	adev = apd->adev;
1373a54d2c8SRex Zhu 	/* call smu to POWER GATE ACP block
1383a54d2c8SRex Zhu 	 * smu will
1393a54d2c8SRex Zhu 	 * 1. turn off the acp clock
1403a54d2c8SRex Zhu 	 * 2. power off the acp tiles
1413a54d2c8SRex Zhu 	 * 3. check and enter ulv state
14225030321SMaruthi Srinivas Bayyavarapu 	 */
1433a54d2c8SRex Zhu 	amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, true);
14425030321SMaruthi Srinivas Bayyavarapu 	return 0;
14525030321SMaruthi Srinivas Bayyavarapu }
14625030321SMaruthi Srinivas Bayyavarapu 
acp_poweron(struct generic_pm_domain * genpd)14725030321SMaruthi Srinivas Bayyavarapu static int acp_poweron(struct generic_pm_domain *genpd)
14825030321SMaruthi Srinivas Bayyavarapu {
14925030321SMaruthi Srinivas Bayyavarapu 	struct acp_pm_domain *apd;
1503a54d2c8SRex Zhu 	struct amdgpu_device *adev;
15125030321SMaruthi Srinivas Bayyavarapu 
15225030321SMaruthi Srinivas Bayyavarapu 	apd = container_of(genpd, struct acp_pm_domain, gpd);
1533a54d2c8SRex Zhu 	adev = apd->adev;
1543a54d2c8SRex Zhu 	/* call smu to UNGATE ACP block
1553a54d2c8SRex Zhu 	 * smu will
1563a54d2c8SRex Zhu 	 * 1. exit ulv
1573a54d2c8SRex Zhu 	 * 2. turn on acp clock
1583a54d2c8SRex Zhu 	 * 3. power on acp tiles
1593a54d2c8SRex Zhu 	 */
1603a54d2c8SRex Zhu 	amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, false);
16125030321SMaruthi Srinivas Bayyavarapu 	return 0;
16225030321SMaruthi Srinivas Bayyavarapu }
16325030321SMaruthi Srinivas Bayyavarapu 
acp_genpd_add_device(struct device * dev,void * data)164aff89028SKai-Heng Feng static int acp_genpd_add_device(struct device *dev, void *data)
16525030321SMaruthi Srinivas Bayyavarapu {
166aff89028SKai-Heng Feng 	struct generic_pm_domain *gpd = data;
167aff89028SKai-Heng Feng 	int ret;
16825030321SMaruthi Srinivas Bayyavarapu 
169aff89028SKai-Heng Feng 	ret = pm_genpd_add_device(gpd, dev);
170aff89028SKai-Heng Feng 	if (ret)
171aff89028SKai-Heng Feng 		dev_err(dev, "Failed to add dev to genpd %d\n", ret);
17225030321SMaruthi Srinivas Bayyavarapu 
173aff89028SKai-Heng Feng 	return ret;
174aff89028SKai-Heng Feng }
175aff89028SKai-Heng Feng 
acp_genpd_remove_device(struct device * dev,void * data)176aff89028SKai-Heng Feng static int acp_genpd_remove_device(struct device *dev, void *data)
177aff89028SKai-Heng Feng {
178aff89028SKai-Heng Feng 	int ret;
179aff89028SKai-Heng Feng 
180aff89028SKai-Heng Feng 	ret = pm_genpd_remove_device(dev);
181aff89028SKai-Heng Feng 	if (ret)
182aff89028SKai-Heng Feng 		dev_err(dev, "Failed to remove dev from genpd %d\n", ret);
183aff89028SKai-Heng Feng 
184aff89028SKai-Heng Feng 	/* Continue to remove */
185aff89028SKai-Heng Feng 	return 0;
18625030321SMaruthi Srinivas Bayyavarapu }
18725030321SMaruthi Srinivas Bayyavarapu 
acp_quirk_cb(const struct dmi_system_id * id)18849062ee3SVijendar Mukunda static int acp_quirk_cb(const struct dmi_system_id *id)
18949062ee3SVijendar Mukunda {
19049062ee3SVijendar Mukunda 	acp_machine_id = ST_JADEITE;
19149062ee3SVijendar Mukunda 	return 1;
19249062ee3SVijendar Mukunda }
19349062ee3SVijendar Mukunda 
19449062ee3SVijendar Mukunda static const struct dmi_system_id acp_quirk_table[] = {
19549062ee3SVijendar Mukunda 	{
19649062ee3SVijendar Mukunda 		.callback = acp_quirk_cb,
19749062ee3SVijendar Mukunda 		.matches = {
19849062ee3SVijendar Mukunda 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMD"),
19949062ee3SVijendar Mukunda 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Jadeite"),
20049062ee3SVijendar Mukunda 		}
20149062ee3SVijendar Mukunda 	},
20249062ee3SVijendar Mukunda 	{
20349062ee3SVijendar Mukunda 		.callback = acp_quirk_cb,
20449062ee3SVijendar Mukunda 		.matches = {
20549062ee3SVijendar Mukunda 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "IP3 Technology CO.,Ltd."),
20649062ee3SVijendar Mukunda 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ASN1D"),
20749062ee3SVijendar Mukunda 		},
20849062ee3SVijendar Mukunda 	},
20949062ee3SVijendar Mukunda 	{
21049062ee3SVijendar Mukunda 		.callback = acp_quirk_cb,
21149062ee3SVijendar Mukunda 		.matches = {
21249062ee3SVijendar Mukunda 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Standard"),
21349062ee3SVijendar Mukunda 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ASN10"),
21449062ee3SVijendar Mukunda 		},
21549062ee3SVijendar Mukunda 	},
21649062ee3SVijendar Mukunda 	{}
21749062ee3SVijendar Mukunda };
21849062ee3SVijendar Mukunda 
219a8fe58ceSMaruthi Bayyavarapu /**
220a8fe58ceSMaruthi Bayyavarapu  * acp_hw_init - start and test ACP block
221a8fe58ceSMaruthi Bayyavarapu  *
222adf0125aSLee Jones  * @handle: handle used to pass amdgpu_device pointer
223a8fe58ceSMaruthi Bayyavarapu  *
224a8fe58ceSMaruthi Bayyavarapu  */
acp_hw_init(void * handle)225a8fe58ceSMaruthi Bayyavarapu static int acp_hw_init(void *handle)
226a8fe58ceSMaruthi Bayyavarapu {
227aff89028SKai-Heng Feng 	int r;
228604d3a3fSVijendar Mukunda 	u64 acp_base;
22937c5f2c9SAkshu Agrawal 	u32 val = 0;
23037c5f2c9SAkshu Agrawal 	u32 count = 0;
23157be09c6SNavid Emamdoost 	struct i2s_platform_data *i2s_pdata = NULL;
232a8fe58ceSMaruthi Bayyavarapu 
233a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
234a8fe58ceSMaruthi Bayyavarapu 
235a1255107SAlex Deucher 	const struct amdgpu_ip_block *ip_block =
2362990a1fcSAlex Deucher 		amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_ACP);
237a8fe58ceSMaruthi Bayyavarapu 
238a1255107SAlex Deucher 	if (!ip_block)
239a8fe58ceSMaruthi Bayyavarapu 		return -EINVAL;
240a8fe58ceSMaruthi Bayyavarapu 
241a8fe58ceSMaruthi Bayyavarapu 	r = amd_acp_hw_init(adev->acp.cgs_device,
242a1255107SAlex Deucher 			    ip_block->version->major, ip_block->version->minor);
243a8fe58ceSMaruthi Bayyavarapu 	/* -ENODEV means board uses AZ rather than ACP */
244be2d6aa5SRex Zhu 	if (r == -ENODEV) {
245be2d6aa5SRex Zhu 		amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, true);
246a8fe58ceSMaruthi Bayyavarapu 		return 0;
247be2d6aa5SRex Zhu 	} else if (r) {
248a8fe58ceSMaruthi Bayyavarapu 		return r;
249be2d6aa5SRex Zhu 	}
250a8fe58ceSMaruthi Bayyavarapu 
251d32d6617SRex Zhu 	if (adev->rmmio_size == 0 || adev->rmmio_size < 0x5289)
252d32d6617SRex Zhu 		return -EINVAL;
253d32d6617SRex Zhu 
254d32d6617SRex Zhu 	acp_base = adev->rmmio_base;
25525030321SMaruthi Srinivas Bayyavarapu 	adev->acp.acp_genpd = kzalloc(sizeof(struct acp_pm_domain), GFP_KERNEL);
256604d3a3fSVijendar Mukunda 	if (!adev->acp.acp_genpd)
25725030321SMaruthi Srinivas Bayyavarapu 		return -ENOMEM;
25825030321SMaruthi Srinivas Bayyavarapu 
25925030321SMaruthi Srinivas Bayyavarapu 	adev->acp.acp_genpd->gpd.name = "ACP_AUDIO";
26025030321SMaruthi Srinivas Bayyavarapu 	adev->acp.acp_genpd->gpd.power_off = acp_poweroff;
26125030321SMaruthi Srinivas Bayyavarapu 	adev->acp.acp_genpd->gpd.power_on = acp_poweron;
2623a54d2c8SRex Zhu 	adev->acp.acp_genpd->adev = adev;
26325030321SMaruthi Srinivas Bayyavarapu 
26425030321SMaruthi Srinivas Bayyavarapu 	pm_genpd_init(&adev->acp.acp_genpd->gpd, NULL, false);
2654c33e517SVijendar Mukunda 	dmi_check_system(acp_quirk_table);
2664c33e517SVijendar Mukunda 	switch (acp_machine_id) {
2674c33e517SVijendar Mukunda 	case ST_JADEITE:
2684c33e517SVijendar Mukunda 	{
2694c33e517SVijendar Mukunda 		adev->acp.acp_cell = kcalloc(2, sizeof(struct mfd_cell),
2704c33e517SVijendar Mukunda 					     GFP_KERNEL);
2714c33e517SVijendar Mukunda 		if (!adev->acp.acp_cell) {
2724c33e517SVijendar Mukunda 			r = -ENOMEM;
2734c33e517SVijendar Mukunda 			goto failure;
2744c33e517SVijendar Mukunda 		}
27525030321SMaruthi Srinivas Bayyavarapu 
2764c33e517SVijendar Mukunda 		adev->acp.acp_res = kcalloc(3, sizeof(struct resource), GFP_KERNEL);
2774c33e517SVijendar Mukunda 		if (!adev->acp.acp_res) {
2784c33e517SVijendar Mukunda 			r = -ENOMEM;
2794c33e517SVijendar Mukunda 			goto failure;
2804c33e517SVijendar Mukunda 		}
2814c33e517SVijendar Mukunda 
2824c33e517SVijendar Mukunda 		i2s_pdata = kcalloc(1, sizeof(struct i2s_platform_data), GFP_KERNEL);
2834c33e517SVijendar Mukunda 		if (!i2s_pdata) {
2844c33e517SVijendar Mukunda 			r = -ENOMEM;
2854c33e517SVijendar Mukunda 			goto failure;
2864c33e517SVijendar Mukunda 		}
2874c33e517SVijendar Mukunda 
2884c33e517SVijendar Mukunda 		i2s_pdata[0].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET |
2894c33e517SVijendar Mukunda 				      DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
2904c33e517SVijendar Mukunda 		i2s_pdata[0].cap = DWC_I2S_PLAY | DWC_I2S_RECORD;
2914c33e517SVijendar Mukunda 		i2s_pdata[0].snd_rates = SNDRV_PCM_RATE_8000_96000;
2924c33e517SVijendar Mukunda 		i2s_pdata[0].i2s_reg_comp1 = ACP_I2S_COMP1_CAP_REG_OFFSET;
2934c33e517SVijendar Mukunda 		i2s_pdata[0].i2s_reg_comp2 = ACP_I2S_COMP2_CAP_REG_OFFSET;
2944c33e517SVijendar Mukunda 
2954c33e517SVijendar Mukunda 		adev->acp.acp_res[0].name = "acp2x_dma";
2964c33e517SVijendar Mukunda 		adev->acp.acp_res[0].flags = IORESOURCE_MEM;
2974c33e517SVijendar Mukunda 		adev->acp.acp_res[0].start = acp_base;
2984c33e517SVijendar Mukunda 		adev->acp.acp_res[0].end = acp_base + ACP_DMA_REGS_END;
2994c33e517SVijendar Mukunda 
3004c33e517SVijendar Mukunda 		adev->acp.acp_res[1].name = "acp2x_dw_i2s_play_cap";
3014c33e517SVijendar Mukunda 		adev->acp.acp_res[1].flags = IORESOURCE_MEM;
3024c33e517SVijendar Mukunda 		adev->acp.acp_res[1].start = acp_base + ACP_I2S_CAP_REGS_START;
3034c33e517SVijendar Mukunda 		adev->acp.acp_res[1].end = acp_base + ACP_I2S_CAP_REGS_END;
3044c33e517SVijendar Mukunda 
3054c33e517SVijendar Mukunda 		adev->acp.acp_res[2].name = "acp2x_dma_irq";
3064c33e517SVijendar Mukunda 		adev->acp.acp_res[2].flags = IORESOURCE_IRQ;
3074c33e517SVijendar Mukunda 		adev->acp.acp_res[2].start = amdgpu_irq_create_mapping(adev, 162);
3084c33e517SVijendar Mukunda 		adev->acp.acp_res[2].end = adev->acp.acp_res[2].start;
3094c33e517SVijendar Mukunda 
3104c33e517SVijendar Mukunda 		adev->acp.acp_cell[0].name = "acp_audio_dma";
3114c33e517SVijendar Mukunda 		adev->acp.acp_cell[0].num_resources = 3;
3124c33e517SVijendar Mukunda 		adev->acp.acp_cell[0].resources = &adev->acp.acp_res[0];
3134c33e517SVijendar Mukunda 		adev->acp.acp_cell[0].platform_data = &adev->asic_type;
3144c33e517SVijendar Mukunda 		adev->acp.acp_cell[0].pdata_size = sizeof(adev->asic_type);
3154c33e517SVijendar Mukunda 
3164c33e517SVijendar Mukunda 		adev->acp.acp_cell[1].name = "designware-i2s";
3174c33e517SVijendar Mukunda 		adev->acp.acp_cell[1].num_resources = 1;
3184c33e517SVijendar Mukunda 		adev->acp.acp_cell[1].resources = &adev->acp.acp_res[1];
3194c33e517SVijendar Mukunda 		adev->acp.acp_cell[1].platform_data = &i2s_pdata[0];
3204c33e517SVijendar Mukunda 		adev->acp.acp_cell[1].pdata_size = sizeof(struct i2s_platform_data);
3214c33e517SVijendar Mukunda 		r = mfd_add_hotplug_devices(adev->acp.parent, adev->acp.acp_cell, 2);
3224c33e517SVijendar Mukunda 		if (r)
3234c33e517SVijendar Mukunda 			goto failure;
3244c33e517SVijendar Mukunda 		r = device_for_each_child(adev->acp.parent, &adev->acp.acp_genpd->gpd,
3254c33e517SVijendar Mukunda 					  acp_genpd_add_device);
3264c33e517SVijendar Mukunda 		if (r)
3274c33e517SVijendar Mukunda 			goto failure;
3284c33e517SVijendar Mukunda 		break;
3294c33e517SVijendar Mukunda 	}
3304c33e517SVijendar Mukunda 	default:
3314c33e517SVijendar Mukunda 		adev->acp.acp_cell = kcalloc(ACP_DEVS, sizeof(struct mfd_cell),
3324c33e517SVijendar Mukunda 					     GFP_KERNEL);
333a8fe58ceSMaruthi Bayyavarapu 
334604d3a3fSVijendar Mukunda 		if (!adev->acp.acp_cell) {
33557be09c6SNavid Emamdoost 			r = -ENOMEM;
33657be09c6SNavid Emamdoost 			goto failure;
33757be09c6SNavid Emamdoost 		}
338a8fe58ceSMaruthi Bayyavarapu 
3392d95ceb4SVijendar Mukunda 		adev->acp.acp_res = kcalloc(5, sizeof(struct resource), GFP_KERNEL);
340604d3a3fSVijendar Mukunda 		if (!adev->acp.acp_res) {
34157be09c6SNavid Emamdoost 			r = -ENOMEM;
34257be09c6SNavid Emamdoost 			goto failure;
343a8fe58ceSMaruthi Bayyavarapu 		}
344a8fe58ceSMaruthi Bayyavarapu 
3452d95ceb4SVijendar Mukunda 		i2s_pdata = kcalloc(3, sizeof(struct i2s_platform_data), GFP_KERNEL);
346604d3a3fSVijendar Mukunda 		if (!i2s_pdata) {
34757be09c6SNavid Emamdoost 			r = -ENOMEM;
34857be09c6SNavid Emamdoost 			goto failure;
349a8fe58ceSMaruthi Bayyavarapu 		}
350a8fe58ceSMaruthi Bayyavarapu 
35181454cadSVijendar Mukunda 		switch (adev->asic_type) {
35281454cadSVijendar Mukunda 		case CHIP_STONEY:
35381454cadSVijendar Mukunda 			i2s_pdata[0].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET |
35481454cadSVijendar Mukunda 				DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
35581454cadSVijendar Mukunda 			break;
35681454cadSVijendar Mukunda 		default:
357a8fe58ceSMaruthi Bayyavarapu 			i2s_pdata[0].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
35881454cadSVijendar Mukunda 		}
359a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[0].cap = DWC_I2S_PLAY;
360a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[0].snd_rates = SNDRV_PCM_RATE_8000_96000;
361a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[0].i2s_reg_comp1 = ACP_I2S_COMP1_PLAY_REG_OFFSET;
362a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[0].i2s_reg_comp2 = ACP_I2S_COMP2_PLAY_REG_OFFSET;
36381454cadSVijendar Mukunda 		switch (adev->asic_type) {
36481454cadSVijendar Mukunda 		case CHIP_STONEY:
36581454cadSVijendar Mukunda 			i2s_pdata[1].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET |
36681454cadSVijendar Mukunda 				DW_I2S_QUIRK_COMP_PARAM1 |
36781454cadSVijendar Mukunda 				DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
36881454cadSVijendar Mukunda 			break;
36981454cadSVijendar Mukunda 		default:
370a8fe58ceSMaruthi Bayyavarapu 			i2s_pdata[1].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET |
371a8fe58ceSMaruthi Bayyavarapu 				DW_I2S_QUIRK_COMP_PARAM1;
37281454cadSVijendar Mukunda 		}
37381454cadSVijendar Mukunda 
374a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[1].cap = DWC_I2S_RECORD;
375a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[1].snd_rates = SNDRV_PCM_RATE_8000_96000;
376a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[1].i2s_reg_comp1 = ACP_I2S_COMP1_CAP_REG_OFFSET;
377a8fe58ceSMaruthi Bayyavarapu 		i2s_pdata[1].i2s_reg_comp2 = ACP_I2S_COMP2_CAP_REG_OFFSET;
378a8fe58ceSMaruthi Bayyavarapu 
3792d95ceb4SVijendar Mukunda 		i2s_pdata[2].quirks = DW_I2S_QUIRK_COMP_REG_OFFSET;
3802d95ceb4SVijendar Mukunda 		switch (adev->asic_type) {
3812d95ceb4SVijendar Mukunda 		case CHIP_STONEY:
3822d95ceb4SVijendar Mukunda 			i2s_pdata[2].quirks |= DW_I2S_QUIRK_16BIT_IDX_OVERRIDE;
3832d95ceb4SVijendar Mukunda 			break;
3842d95ceb4SVijendar Mukunda 		default:
3852d95ceb4SVijendar Mukunda 			break;
3862d95ceb4SVijendar Mukunda 		}
3872d95ceb4SVijendar Mukunda 
3882d95ceb4SVijendar Mukunda 		i2s_pdata[2].cap = DWC_I2S_PLAY | DWC_I2S_RECORD;
3892d95ceb4SVijendar Mukunda 		i2s_pdata[2].snd_rates = SNDRV_PCM_RATE_8000_96000;
3902d95ceb4SVijendar Mukunda 		i2s_pdata[2].i2s_reg_comp1 = ACP_BT_COMP1_REG_OFFSET;
3912d95ceb4SVijendar Mukunda 		i2s_pdata[2].i2s_reg_comp2 = ACP_BT_COMP2_REG_OFFSET;
3922d95ceb4SVijendar Mukunda 
393a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[0].name = "acp2x_dma";
394a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[0].flags = IORESOURCE_MEM;
395a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[0].start = acp_base;
396a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[0].end = acp_base + ACP_DMA_REGS_END;
397a8fe58ceSMaruthi Bayyavarapu 
398a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[1].name = "acp2x_dw_i2s_play";
399a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[1].flags = IORESOURCE_MEM;
400a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[1].start = acp_base + ACP_I2S_PLAY_REGS_START;
401a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[1].end = acp_base + ACP_I2S_PLAY_REGS_END;
402a8fe58ceSMaruthi Bayyavarapu 
403a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[2].name = "acp2x_dw_i2s_cap";
404a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[2].flags = IORESOURCE_MEM;
405a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[2].start = acp_base + ACP_I2S_CAP_REGS_START;
406a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_res[2].end = acp_base + ACP_I2S_CAP_REGS_END;
407a8fe58ceSMaruthi Bayyavarapu 
4082d95ceb4SVijendar Mukunda 		adev->acp.acp_res[3].name = "acp2x_dw_bt_i2s_play_cap";
4092d95ceb4SVijendar Mukunda 		adev->acp.acp_res[3].flags = IORESOURCE_MEM;
4102d95ceb4SVijendar Mukunda 		adev->acp.acp_res[3].start = acp_base + ACP_BT_PLAY_REGS_START;
4112d95ceb4SVijendar Mukunda 		adev->acp.acp_res[3].end = acp_base + ACP_BT_PLAY_REGS_END;
4122d95ceb4SVijendar Mukunda 
4132d95ceb4SVijendar Mukunda 		adev->acp.acp_res[4].name = "acp2x_dma_irq";
4142d95ceb4SVijendar Mukunda 		adev->acp.acp_res[4].flags = IORESOURCE_IRQ;
4152d95ceb4SVijendar Mukunda 		adev->acp.acp_res[4].start = amdgpu_irq_create_mapping(adev, 162);
4162d95ceb4SVijendar Mukunda 		adev->acp.acp_res[4].end = adev->acp.acp_res[4].start;
417a8fe58ceSMaruthi Bayyavarapu 
418a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[0].name = "acp_audio_dma";
4192d95ceb4SVijendar Mukunda 		adev->acp.acp_cell[0].num_resources = 5;
420a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[0].resources = &adev->acp.acp_res[0];
4211fd16f36SVijendar Mukunda 		adev->acp.acp_cell[0].platform_data = &adev->asic_type;
4221fd16f36SVijendar Mukunda 		adev->acp.acp_cell[0].pdata_size = sizeof(adev->asic_type);
423a8fe58ceSMaruthi Bayyavarapu 
424a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[1].name = "designware-i2s";
425a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[1].num_resources = 1;
426a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[1].resources = &adev->acp.acp_res[1];
427a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[1].platform_data = &i2s_pdata[0];
428a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[1].pdata_size = sizeof(struct i2s_platform_data);
429a8fe58ceSMaruthi Bayyavarapu 
430a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[2].name = "designware-i2s";
431a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[2].num_resources = 1;
432a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[2].resources = &adev->acp.acp_res[2];
433a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[2].platform_data = &i2s_pdata[1];
434a8fe58ceSMaruthi Bayyavarapu 		adev->acp.acp_cell[2].pdata_size = sizeof(struct i2s_platform_data);
435a8fe58ceSMaruthi Bayyavarapu 
4362d95ceb4SVijendar Mukunda 		adev->acp.acp_cell[3].name = "designware-i2s";
4372d95ceb4SVijendar Mukunda 		adev->acp.acp_cell[3].num_resources = 1;
4382d95ceb4SVijendar Mukunda 		adev->acp.acp_cell[3].resources = &adev->acp.acp_res[3];
4392d95ceb4SVijendar Mukunda 		adev->acp.acp_cell[3].platform_data = &i2s_pdata[2];
4402d95ceb4SVijendar Mukunda 		adev->acp.acp_cell[3].pdata_size = sizeof(struct i2s_platform_data);
4412d95ceb4SVijendar Mukunda 
442604d3a3fSVijendar Mukunda 		r = mfd_add_hotplug_devices(adev->acp.parent, adev->acp.acp_cell, ACP_DEVS);
443a8fe58ceSMaruthi Bayyavarapu 		if (r)
44457be09c6SNavid Emamdoost 			goto failure;
445a8fe58ceSMaruthi Bayyavarapu 
446aff89028SKai-Heng Feng 		r = device_for_each_child(adev->acp.parent, &adev->acp.acp_genpd->gpd,
447aff89028SKai-Heng Feng 					  acp_genpd_add_device);
448aff89028SKai-Heng Feng 		if (r)
44957be09c6SNavid Emamdoost 			goto failure;
4504c33e517SVijendar Mukunda 	}
45125030321SMaruthi Srinivas Bayyavarapu 
45237c5f2c9SAkshu Agrawal 	/* Assert Soft reset of ACP */
45337c5f2c9SAkshu Agrawal 	val = cgs_read_register(adev->acp.cgs_device, mmACP_SOFT_RESET);
45437c5f2c9SAkshu Agrawal 
45537c5f2c9SAkshu Agrawal 	val |= ACP_SOFT_RESET__SoftResetAud_MASK;
45637c5f2c9SAkshu Agrawal 	cgs_write_register(adev->acp.cgs_device, mmACP_SOFT_RESET, val);
45737c5f2c9SAkshu Agrawal 
45837c5f2c9SAkshu Agrawal 	count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE;
45937c5f2c9SAkshu Agrawal 	while (true) {
46037c5f2c9SAkshu Agrawal 		val = cgs_read_register(adev->acp.cgs_device, mmACP_SOFT_RESET);
46137c5f2c9SAkshu Agrawal 		if (ACP_SOFT_RESET__SoftResetAudDone_MASK ==
46237c5f2c9SAkshu Agrawal 		    (val & ACP_SOFT_RESET__SoftResetAudDone_MASK))
46337c5f2c9SAkshu Agrawal 			break;
46437c5f2c9SAkshu Agrawal 		if (--count == 0) {
46537c5f2c9SAkshu Agrawal 			dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
46657be09c6SNavid Emamdoost 			r = -ETIMEDOUT;
46757be09c6SNavid Emamdoost 			goto failure;
46837c5f2c9SAkshu Agrawal 		}
46937c5f2c9SAkshu Agrawal 		udelay(100);
47037c5f2c9SAkshu Agrawal 	}
47137c5f2c9SAkshu Agrawal 	/* Enable clock to ACP and wait until the clock is enabled */
47237c5f2c9SAkshu Agrawal 	val = cgs_read_register(adev->acp.cgs_device, mmACP_CONTROL);
47337c5f2c9SAkshu Agrawal 	val = val | ACP_CONTROL__ClkEn_MASK;
47437c5f2c9SAkshu Agrawal 	cgs_write_register(adev->acp.cgs_device, mmACP_CONTROL, val);
47537c5f2c9SAkshu Agrawal 
47637c5f2c9SAkshu Agrawal 	count = ACP_CLOCK_EN_TIME_OUT_VALUE;
47737c5f2c9SAkshu Agrawal 
47837c5f2c9SAkshu Agrawal 	while (true) {
47937c5f2c9SAkshu Agrawal 		val = cgs_read_register(adev->acp.cgs_device, mmACP_STATUS);
48037c5f2c9SAkshu Agrawal 		if (val & (u32) 0x1)
48137c5f2c9SAkshu Agrawal 			break;
48237c5f2c9SAkshu Agrawal 		if (--count == 0) {
48337c5f2c9SAkshu Agrawal 			dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
48457be09c6SNavid Emamdoost 			r = -ETIMEDOUT;
48557be09c6SNavid Emamdoost 			goto failure;
48637c5f2c9SAkshu Agrawal 		}
48737c5f2c9SAkshu Agrawal 		udelay(100);
48837c5f2c9SAkshu Agrawal 	}
48937c5f2c9SAkshu Agrawal 	/* Deassert the SOFT RESET flags */
49037c5f2c9SAkshu Agrawal 	val = cgs_read_register(adev->acp.cgs_device, mmACP_SOFT_RESET);
49137c5f2c9SAkshu Agrawal 	val &= ~ACP_SOFT_RESET__SoftResetAud_MASK;
49237c5f2c9SAkshu Agrawal 	cgs_write_register(adev->acp.cgs_device, mmACP_SOFT_RESET, val);
493a8fe58ceSMaruthi Bayyavarapu 	return 0;
49457be09c6SNavid Emamdoost 
49557be09c6SNavid Emamdoost failure:
49657be09c6SNavid Emamdoost 	kfree(i2s_pdata);
49757be09c6SNavid Emamdoost 	kfree(adev->acp.acp_res);
49857be09c6SNavid Emamdoost 	kfree(adev->acp.acp_cell);
49957be09c6SNavid Emamdoost 	kfree(adev->acp.acp_genpd);
50057be09c6SNavid Emamdoost 	return r;
501a8fe58ceSMaruthi Bayyavarapu }
502a8fe58ceSMaruthi Bayyavarapu 
503a8fe58ceSMaruthi Bayyavarapu /**
504a8fe58ceSMaruthi Bayyavarapu  * acp_hw_fini - stop the hardware block
505a8fe58ceSMaruthi Bayyavarapu  *
506adf0125aSLee Jones  * @handle: handle used to pass amdgpu_device pointer
507a8fe58ceSMaruthi Bayyavarapu  *
508a8fe58ceSMaruthi Bayyavarapu  */
acp_hw_fini(void * handle)509a8fe58ceSMaruthi Bayyavarapu static int acp_hw_fini(void *handle)
510a8fe58ceSMaruthi Bayyavarapu {
51137c5f2c9SAkshu Agrawal 	u32 val = 0;
51237c5f2c9SAkshu Agrawal 	u32 count = 0;
513a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
514a8fe58ceSMaruthi Bayyavarapu 
515757124d9SAlex Deucher 	/* return early if no ACP */
5161062ddb6SVijendar Mukunda 	if (!adev->acp.acp_genpd) {
517be2d6aa5SRex Zhu 		amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, false);
518757124d9SAlex Deucher 		return 0;
519be2d6aa5SRex Zhu 	}
520757124d9SAlex Deucher 
52137c5f2c9SAkshu Agrawal 	/* Assert Soft reset of ACP */
52237c5f2c9SAkshu Agrawal 	val = cgs_read_register(adev->acp.cgs_device, mmACP_SOFT_RESET);
52337c5f2c9SAkshu Agrawal 
52437c5f2c9SAkshu Agrawal 	val |= ACP_SOFT_RESET__SoftResetAud_MASK;
52537c5f2c9SAkshu Agrawal 	cgs_write_register(adev->acp.cgs_device, mmACP_SOFT_RESET, val);
52637c5f2c9SAkshu Agrawal 
52737c5f2c9SAkshu Agrawal 	count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE;
52837c5f2c9SAkshu Agrawal 	while (true) {
52937c5f2c9SAkshu Agrawal 		val = cgs_read_register(adev->acp.cgs_device, mmACP_SOFT_RESET);
53037c5f2c9SAkshu Agrawal 		if (ACP_SOFT_RESET__SoftResetAudDone_MASK ==
53137c5f2c9SAkshu Agrawal 		    (val & ACP_SOFT_RESET__SoftResetAudDone_MASK))
53237c5f2c9SAkshu Agrawal 			break;
53337c5f2c9SAkshu Agrawal 		if (--count == 0) {
53437c5f2c9SAkshu Agrawal 			dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
53537c5f2c9SAkshu Agrawal 			return -ETIMEDOUT;
53637c5f2c9SAkshu Agrawal 		}
53737c5f2c9SAkshu Agrawal 		udelay(100);
53837c5f2c9SAkshu Agrawal 	}
53937c5f2c9SAkshu Agrawal 	/* Disable ACP clock */
54037c5f2c9SAkshu Agrawal 	val = cgs_read_register(adev->acp.cgs_device, mmACP_CONTROL);
54137c5f2c9SAkshu Agrawal 	val &= ~ACP_CONTROL__ClkEn_MASK;
54237c5f2c9SAkshu Agrawal 	cgs_write_register(adev->acp.cgs_device, mmACP_CONTROL, val);
54337c5f2c9SAkshu Agrawal 
54437c5f2c9SAkshu Agrawal 	count = ACP_CLOCK_EN_TIME_OUT_VALUE;
54537c5f2c9SAkshu Agrawal 
54637c5f2c9SAkshu Agrawal 	while (true) {
54737c5f2c9SAkshu Agrawal 		val = cgs_read_register(adev->acp.cgs_device, mmACP_STATUS);
54837c5f2c9SAkshu Agrawal 		if (val & (u32) 0x1)
54937c5f2c9SAkshu Agrawal 			break;
55037c5f2c9SAkshu Agrawal 		if (--count == 0) {
55137c5f2c9SAkshu Agrawal 			dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
55237c5f2c9SAkshu Agrawal 			return -ETIMEDOUT;
55337c5f2c9SAkshu Agrawal 		}
55437c5f2c9SAkshu Agrawal 		udelay(100);
55537c5f2c9SAkshu Agrawal 	}
55637c5f2c9SAkshu Agrawal 
557aff89028SKai-Heng Feng 	device_for_each_child(adev->acp.parent, NULL,
558aff89028SKai-Heng Feng 			      acp_genpd_remove_device);
55925030321SMaruthi Srinivas Bayyavarapu 
560a8fe58ceSMaruthi Bayyavarapu 	mfd_remove_devices(adev->acp.parent);
561a8fe58ceSMaruthi Bayyavarapu 	kfree(adev->acp.acp_res);
5621062ddb6SVijendar Mukunda 	kfree(adev->acp.acp_genpd);
563a8fe58ceSMaruthi Bayyavarapu 	kfree(adev->acp.acp_cell);
564a8fe58ceSMaruthi Bayyavarapu 
565a8fe58ceSMaruthi Bayyavarapu 	return 0;
566a8fe58ceSMaruthi Bayyavarapu }
567a8fe58ceSMaruthi Bayyavarapu 
acp_suspend(void * handle)568a8fe58ceSMaruthi Bayyavarapu static int acp_suspend(void *handle)
569a8fe58ceSMaruthi Bayyavarapu {
570be2d6aa5SRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
571be2d6aa5SRex Zhu 
572be2d6aa5SRex Zhu 	/* power up on suspend */
573be2d6aa5SRex Zhu 	if (!adev->acp.acp_cell)
574be2d6aa5SRex Zhu 		amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, false);
575a8fe58ceSMaruthi Bayyavarapu 	return 0;
576a8fe58ceSMaruthi Bayyavarapu }
577a8fe58ceSMaruthi Bayyavarapu 
acp_resume(void * handle)578a8fe58ceSMaruthi Bayyavarapu static int acp_resume(void *handle)
579a8fe58ceSMaruthi Bayyavarapu {
580be2d6aa5SRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
581be2d6aa5SRex Zhu 
582be2d6aa5SRex Zhu 	/* power down again on resume */
583be2d6aa5SRex Zhu 	if (!adev->acp.acp_cell)
584be2d6aa5SRex Zhu 		amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, true);
585a8fe58ceSMaruthi Bayyavarapu 	return 0;
586a8fe58ceSMaruthi Bayyavarapu }
587a8fe58ceSMaruthi Bayyavarapu 
acp_early_init(void * handle)588a8fe58ceSMaruthi Bayyavarapu static int acp_early_init(void *handle)
589a8fe58ceSMaruthi Bayyavarapu {
590a8fe58ceSMaruthi Bayyavarapu 	return 0;
591a8fe58ceSMaruthi Bayyavarapu }
592a8fe58ceSMaruthi Bayyavarapu 
acp_is_idle(void * handle)593a8fe58ceSMaruthi Bayyavarapu static bool acp_is_idle(void *handle)
594a8fe58ceSMaruthi Bayyavarapu {
595a8fe58ceSMaruthi Bayyavarapu 	return true;
596a8fe58ceSMaruthi Bayyavarapu }
597a8fe58ceSMaruthi Bayyavarapu 
acp_wait_for_idle(void * handle)598a8fe58ceSMaruthi Bayyavarapu static int acp_wait_for_idle(void *handle)
599a8fe58ceSMaruthi Bayyavarapu {
600a8fe58ceSMaruthi Bayyavarapu 	return 0;
601a8fe58ceSMaruthi Bayyavarapu }
602a8fe58ceSMaruthi Bayyavarapu 
acp_soft_reset(void * handle)603a8fe58ceSMaruthi Bayyavarapu static int acp_soft_reset(void *handle)
604a8fe58ceSMaruthi Bayyavarapu {
605a8fe58ceSMaruthi Bayyavarapu 	return 0;
606a8fe58ceSMaruthi Bayyavarapu }
607a8fe58ceSMaruthi Bayyavarapu 
acp_set_clockgating_state(void * handle,enum amd_clockgating_state state)608a8fe58ceSMaruthi Bayyavarapu static int acp_set_clockgating_state(void *handle,
609a8fe58ceSMaruthi Bayyavarapu 				     enum amd_clockgating_state state)
610a8fe58ceSMaruthi Bayyavarapu {
611a8fe58ceSMaruthi Bayyavarapu 	return 0;
612a8fe58ceSMaruthi Bayyavarapu }
613a8fe58ceSMaruthi Bayyavarapu 
acp_set_powergating_state(void * handle,enum amd_powergating_state state)614a8fe58ceSMaruthi Bayyavarapu static int acp_set_powergating_state(void *handle,
615a8fe58ceSMaruthi Bayyavarapu 				     enum amd_powergating_state state)
616a8fe58ceSMaruthi Bayyavarapu {
617c36628d8SRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
618a9d4fe2fSNirmoy Das 	bool enable = (state == AMD_PG_STATE_GATE);
619c36628d8SRex Zhu 
620c36628d8SRex Zhu 	amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_ACP, enable);
621c36628d8SRex Zhu 
622a8fe58ceSMaruthi Bayyavarapu 	return 0;
623a8fe58ceSMaruthi Bayyavarapu }
624a8fe58ceSMaruthi Bayyavarapu 
625a1255107SAlex Deucher static const struct amd_ip_funcs acp_ip_funcs = {
62688a907d6STom St Denis 	.name = "acp_ip",
627a8fe58ceSMaruthi Bayyavarapu 	.early_init = acp_early_init,
628a8fe58ceSMaruthi Bayyavarapu 	.late_init = NULL,
629a8fe58ceSMaruthi Bayyavarapu 	.sw_init = acp_sw_init,
630a8fe58ceSMaruthi Bayyavarapu 	.sw_fini = acp_sw_fini,
631a8fe58ceSMaruthi Bayyavarapu 	.hw_init = acp_hw_init,
632a8fe58ceSMaruthi Bayyavarapu 	.hw_fini = acp_hw_fini,
633a8fe58ceSMaruthi Bayyavarapu 	.suspend = acp_suspend,
634a8fe58ceSMaruthi Bayyavarapu 	.resume = acp_resume,
635a8fe58ceSMaruthi Bayyavarapu 	.is_idle = acp_is_idle,
636a8fe58ceSMaruthi Bayyavarapu 	.wait_for_idle = acp_wait_for_idle,
637a8fe58ceSMaruthi Bayyavarapu 	.soft_reset = acp_soft_reset,
638a8fe58ceSMaruthi Bayyavarapu 	.set_clockgating_state = acp_set_clockgating_state,
639a8fe58ceSMaruthi Bayyavarapu 	.set_powergating_state = acp_set_powergating_state,
640e21d253bSSunil Khatri 	.dump_ip_state = NULL,
641*40356542SSunil Khatri 	.print_ip_state = NULL,
642a8fe58ceSMaruthi Bayyavarapu };
643a1255107SAlex Deucher 
644604d3a3fSVijendar Mukunda const struct amdgpu_ip_block_version acp_ip_block = {
645a1255107SAlex Deucher 	.type = AMD_IP_BLOCK_TYPE_ACP,
646a1255107SAlex Deucher 	.major = 2,
647a1255107SAlex Deucher 	.minor = 2,
648a1255107SAlex Deucher 	.rev = 0,
649a1255107SAlex Deucher 	.funcs = &acp_ip_funcs,
650a1255107SAlex Deucher };
651