Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Copyright(c) 2020 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Author: Cezary Rojewski <cezary.rojewski@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) // Special thanks to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) //    Marcin Barlik <marcin.barlik@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) //    Piotr Papierkowski <piotr.papierkowski@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) // for sharing LPT-LP and WTP-LP AudioDSP architecture expertise and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) // helping backtrack its historical background
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <sound/soc-acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <sound/soc-acpi-intel-match.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "registers.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int __maybe_unused catpt_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct catpt_dev *cdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct dma_chan *chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	chan = catpt_dma_request_config_chan(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (IS_ERR(chan))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return PTR_ERR(chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	memset(&cdev->dx_ctx, 0, sizeof(cdev->dx_ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	ret = catpt_ipc_enter_dxstate(cdev, CATPT_DX_STATE_D3, &cdev->dx_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		ret = CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		goto release_dma_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	ret = catpt_dsp_stall(cdev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		goto release_dma_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	ret = catpt_store_memdumps(cdev, chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		dev_err(cdev->dev, "store memdumps failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		goto release_dma_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	ret = catpt_store_module_states(cdev, chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		dev_err(cdev->dev, "store module states failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		goto release_dma_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	ret = catpt_store_streams_context(cdev, chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		dev_err(cdev->dev, "store streams ctx failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) release_dma_chan:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	dma_release_channel(chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return cdev->spec->power_down(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static int __maybe_unused catpt_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct catpt_dev *cdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	ret = cdev->spec->power_up(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (!try_module_get(dev->driver->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		dev_info(dev, "module unloading, skipping fw boot\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	module_put(dev->driver->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	ret = catpt_boot_firmware(cdev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		dev_err(cdev->dev, "boot firmware failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/* reconfigure SSP devices after Dx transition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	for (i = 0; i < CATPT_SSP_COUNT; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (cdev->devfmt[i].iface == UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		ret = catpt_ipc_set_device_format(cdev, &cdev->devfmt[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int __maybe_unused catpt_runtime_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (!try_module_get(dev->driver->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		dev_info(dev, "module unloading, skipping suspend\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	module_put(dev->driver->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return catpt_suspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int __maybe_unused catpt_runtime_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return catpt_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static const struct dev_pm_ops catpt_dev_pm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	SET_SYSTEM_SLEEP_PM_OPS(catpt_suspend, catpt_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	SET_RUNTIME_PM_OPS(catpt_runtime_suspend, catpt_runtime_resume, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* machine board owned by CATPT is removed with this hook */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void board_pdev_unregister(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	platform_device_unregister(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int catpt_register_board(struct catpt_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	const struct catpt_spec *spec = cdev->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct snd_soc_acpi_mach *mach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct platform_device *board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	mach = snd_soc_acpi_find_machine(spec->machines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!mach) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		dev_info(cdev->dev, "no machines present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	mach->mach_params.platform = "catpt-platform";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	board = platform_device_register_data(NULL, mach->drv_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 					PLATFORM_DEVID_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					(const void *)mach, sizeof(*mach));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (IS_ERR(board)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		dev_err(cdev->dev, "board register failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return PTR_ERR(board);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return devm_add_action_or_reset(cdev->dev, board_pdev_unregister,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 					board);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int catpt_probe_components(struct catpt_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	ret = cdev->spec->power_up(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	ret = catpt_dmac_probe(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		dev_err(cdev->dev, "DMAC probe failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		goto err_dmac_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	ret = catpt_first_boot_firmware(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		dev_err(cdev->dev, "first fw boot failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		goto err_boot_fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	ret = catpt_register_plat_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		dev_err(cdev->dev, "register plat comp failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		goto err_boot_fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ret = catpt_register_board(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		dev_err(cdev->dev, "register board failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		goto err_reg_board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/* reflect actual ADSP state in pm_runtime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	pm_runtime_set_active(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	pm_runtime_set_autosuspend_delay(cdev->dev, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	pm_runtime_use_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	pm_runtime_enable(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) err_reg_board:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	snd_soc_unregister_component(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) err_boot_fw:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	catpt_dmac_remove(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) err_dmac_probe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	cdev->spec->power_down(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void catpt_dev_init(struct catpt_dev *cdev, struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			   const struct catpt_spec *spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	cdev->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	cdev->spec = spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	init_completion(&cdev->fw_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	INIT_LIST_HEAD(&cdev->stream_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	spin_lock_init(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	mutex_init(&cdev->clk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * Mark both device formats as uninitialized. Once corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 * cpu_dai's pcm is created, proper values are assigned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	cdev->devfmt[CATPT_SSP_IFACE_0].iface = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	cdev->devfmt[CATPT_SSP_IFACE_1].iface = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	catpt_ipc_init(&cdev->ipc, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	catpt_sram_init(&cdev->dram, spec->host_dram_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			catpt_dram_size(cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	catpt_sram_init(&cdev->iram, spec->host_iram_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			catpt_iram_size(cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int catpt_acpi_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	const struct catpt_spec *spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct catpt_dev *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	spec = device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (!spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (!cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	catpt_dev_init(cdev, dev, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	/* map DSP bar address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	cdev->lpe_ba = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (IS_ERR(cdev->lpe_ba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return PTR_ERR(cdev->lpe_ba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	cdev->lpe_base = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* map PCI bar address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	cdev->pci_ba = devm_platform_ioremap_resource(pdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (IS_ERR(cdev->pci_ba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		return PTR_ERR(cdev->pci_ba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* alloc buffer for storing DRAM context during dx transitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	cdev->dxbuf_vaddr = dmam_alloc_coherent(dev, catpt_dram_size(cdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 						&cdev->dxbuf_paddr, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (!cdev->dxbuf_vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ret = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	cdev->irq = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	platform_set_drvdata(pdev, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	ret = devm_request_threaded_irq(dev, cdev->irq, catpt_dsp_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 					catpt_dsp_irq_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					IRQF_SHARED, "AudioDSP", cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return catpt_probe_components(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int catpt_acpi_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct catpt_dev *cdev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	pm_runtime_disable(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	snd_soc_unregister_component(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	catpt_dmac_remove(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	cdev->spec->power_down(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	catpt_sram_free(&cdev->iram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	catpt_sram_free(&cdev->dram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static struct catpt_spec lpt_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	.machines = snd_soc_acpi_intel_haswell_machines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	.core_id = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	.host_dram_offset = 0x000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	.host_iram_offset = 0x080000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	.host_shim_offset = 0x0E7000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	.host_dma_offset = { 0x0F0000, 0x0F8000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	.host_ssp_offset = { 0x0E8000, 0x0E9000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	.dram_mask = LPT_VDRTCTL0_DSRAMPGE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	.iram_mask = LPT_VDRTCTL0_ISRAMPGE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	.pll_shutdown = lpt_dsp_pll_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.power_up = lpt_dsp_power_up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.power_down = lpt_dsp_power_down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static struct catpt_spec wpt_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	.machines = snd_soc_acpi_intel_broadwell_machines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	.core_id = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	.host_dram_offset = 0x000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	.host_iram_offset = 0x0A0000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	.host_shim_offset = 0x0FB000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.host_dma_offset = { 0x0FE000, 0x0FF000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.host_ssp_offset = { 0x0FC000, 0x0FD000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	.dram_mask = WPT_VDRTCTL0_DSRAMPGE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.iram_mask = WPT_VDRTCTL0_ISRAMPGE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.pll_shutdown = wpt_dsp_pll_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.power_up = wpt_dsp_power_up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.power_down = wpt_dsp_power_down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static const struct acpi_device_id catpt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	{ "INT33C8", (unsigned long)&lpt_desc },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	{ "INT3438", (unsigned long)&wpt_desc },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_DEVICE_TABLE(acpi, catpt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static struct platform_driver catpt_acpi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	.probe = catpt_acpi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	.remove = catpt_acpi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		.name = "intel_catpt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		.acpi_match_table = catpt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		.pm = &catpt_dev_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		.dev_groups = catpt_attr_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) module_platform_driver(catpt_acpi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) MODULE_AUTHOR("Cezary Rojewski <cezary.rojewski@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) MODULE_DESCRIPTION("Intel LPT/WPT AudioDSP driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) MODULE_LICENSE("GPL v2");