1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
|
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
//
// Copyright 2019-2025 NXP
//
// Author: Daniel Baluta <daniel.baluta@nxp.com>
//
// Hardware interface for audio DSP on i.MX8
#include <dt-bindings/firmware/imx/rsrc.h>
#include <linux/arm-smccc.h>
#include <linux/firmware/imx/svc/misc.h>
#include <linux/mfd/syscon.h>
#include <linux/reset.h>
#include "imx-common.h"
/* imx8/imx8x macros */
#define RESET_VECTOR_VADDR 0x596f8000
/* imx8m macros */
#define IMX8M_DAP_DEBUG 0x28800000
#define IMX8M_DAP_DEBUG_SIZE (64 * 1024)
#define IMX8M_DAP_PWRCTL (0x4000 + 0x3020)
#define IMX8M_PWRCTL_CORERESET BIT(16)
/* imx8ulp macros */
#define FSL_SIP_HIFI_XRDC 0xc200000e
#define SYSCTRL0 0x8
#define EXECUTE_BIT BIT(13)
#define RESET_BIT BIT(16)
#define HIFI4_CLK_BIT BIT(17)
#define PB_CLK_BIT BIT(18)
#define PLAT_CLK_BIT BIT(19)
#define DEBUG_LOGIC_BIT BIT(25)
struct imx8m_chip_data {
void __iomem *dap;
struct regmap *regmap;
struct reset_control *run_stall;
};
static int imx8_shutdown(struct snd_sof_dev *sdev)
{
/*
* Force the DSP to stall. After the firmware image is loaded,
* the stall will be removed during run() by a matching
* imx_sc_pm_cpu_start() call.
*/
imx_sc_pm_cpu_start(get_chip_pdata(sdev), IMX_SC_R_DSP, false,
RESET_VECTOR_VADDR);
return 0;
}
/*
* DSP control.
*/
static int imx8x_run(struct snd_sof_dev *sdev)
{
int ret;
ret = imx_sc_misc_set_control(get_chip_pdata(sdev), IMX_SC_R_DSP,
IMX_SC_C_OFS_SEL, 1);
if (ret < 0) {
dev_err(sdev->dev, "Error system address offset source select\n");
return ret;
}
ret = imx_sc_misc_set_control(get_chip_pdata(sdev), IMX_SC_R_DSP,
IMX_SC_C_OFS_AUDIO, 0x80);
if (ret < 0) {
dev_err(sdev->dev, "Error system address offset of AUDIO\n");
return ret;
}
ret = imx_sc_misc_set_control(get_chip_pdata(sdev), IMX_SC_R_DSP,
IMX_SC_C_OFS_PERIPH, 0x5A);
if (ret < 0) {
dev_err(sdev->dev, "Error system address offset of PERIPH %d\n",
ret);
return ret;
}
ret = imx_sc_misc_set_control(get_chip_pdata(sdev), IMX_SC_R_DSP,
IMX_SC_C_OFS_IRQ, 0x51);
if (ret < 0) {
dev_err(sdev->dev, "Error system address offset of IRQ\n");
return ret;
}
imx_sc_pm_cpu_start(get_chip_pdata(sdev), IMX_SC_R_DSP, true,
RESET_VECTOR_VADDR);
return 0;
}
static int imx8_run(struct snd_sof_dev *sdev)
{
int ret;
ret = imx_sc_misc_set_control(get_chip_pdata(sdev), IMX_SC_R_DSP,
IMX_SC_C_OFS_SEL, 0);
if (ret < 0) {
dev_err(sdev->dev, "Error system address offset source select\n");
return ret;
}
imx_sc_pm_cpu_start(get_chip_pdata(sdev), IMX_SC_R_DSP, true,
RESET_VECTOR_VADDR);
return 0;
}
static int imx8_probe(struct snd_sof_dev *sdev)
{
struct imx_sc_ipc *sc_ipc_handle;
struct imx_common_data *common;
int ret;
common = sdev->pdata->hw_pdata;
ret = imx_scu_get_handle(&sc_ipc_handle);
if (ret < 0)
return dev_err_probe(sdev->dev, ret,
"failed to fetch SC IPC handle\n");
common->chip_pdata = sc_ipc_handle;
return 0;
}
static int imx8m_reset(struct snd_sof_dev *sdev)
{
struct imx8m_chip_data *chip;
u32 pwrctl;
chip = get_chip_pdata(sdev);
/* put DSP into reset and stall */
pwrctl = readl(chip->dap + IMX8M_DAP_PWRCTL);
pwrctl |= IMX8M_PWRCTL_CORERESET;
writel(pwrctl, chip->dap + IMX8M_DAP_PWRCTL);
/* keep reset asserted for 10 cycles */
usleep_range(1, 2);
reset_control_assert(chip->run_stall);
/* take the DSP out of reset and keep stalled for FW loading */
pwrctl = readl(chip->dap + IMX8M_DAP_PWRCTL);
pwrctl &= ~IMX8M_PWRCTL_CORERESET;
writel(pwrctl, chip->dap + IMX8M_DAP_PWRCTL);
return 0;
}
static int imx8m_run(struct snd_sof_dev *sdev)
{
struct imx8m_chip_data *chip = get_chip_pdata(sdev);
return reset_control_deassert(chip->run_stall);
}
static int imx8m_probe(struct snd_sof_dev *sdev)
{
struct imx_common_data *common;
struct imx8m_chip_data *chip;
common = sdev->pdata->hw_pdata;
chip = devm_kzalloc(sdev->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
return dev_err_probe(sdev->dev, -ENOMEM,
"failed to allocate chip data\n");
chip->dap = devm_ioremap(sdev->dev, IMX8M_DAP_DEBUG, IMX8M_DAP_DEBUG_SIZE);
if (!chip->dap)
return dev_err_probe(sdev->dev, -ENODEV,
"failed to ioremap DAP\n");
chip->run_stall = devm_reset_control_get_exclusive(sdev->dev, "runstall");
if (IS_ERR(chip->run_stall))
return dev_err_probe(sdev->dev, PTR_ERR(chip->run_stall),
"failed to get dsp runstall reset control\n");
common->chip_pdata = chip;
return 0;
}
static int imx8ulp_run(struct snd_sof_dev *sdev)
{
struct regmap *regmap = get_chip_pdata(sdev);
/* Controls the HiFi4 DSP Reset: 1 in reset, 0 out of reset */
regmap_update_bits(regmap, SYSCTRL0, RESET_BIT, 0);
/* Reset HiFi4 DSP Debug logic: 1 debug reset, 0 out of reset*/
regmap_update_bits(regmap, SYSCTRL0, DEBUG_LOGIC_BIT, 0);
/* Stall HIFI4 DSP Execution: 1 stall, 0 run */
regmap_update_bits(regmap, SYSCTRL0, EXECUTE_BIT, 0);
return 0;
}
static int imx8ulp_reset(struct snd_sof_dev *sdev)
{
struct arm_smccc_res smc_res;
struct regmap *regmap;
regmap = get_chip_pdata(sdev);
/* HiFi4 Platform Clock Enable: 1 enabled, 0 disabled */
regmap_update_bits(regmap, SYSCTRL0, PLAT_CLK_BIT, PLAT_CLK_BIT);
/* HiFi4 PBCLK clock enable: 1 enabled, 0 disabled */
regmap_update_bits(regmap, SYSCTRL0, PB_CLK_BIT, PB_CLK_BIT);
/* HiFi4 Clock Enable: 1 enabled, 0 disabled */
regmap_update_bits(regmap, SYSCTRL0, HIFI4_CLK_BIT, HIFI4_CLK_BIT);
regmap_update_bits(regmap, SYSCTRL0, RESET_BIT, RESET_BIT);
usleep_range(1, 2);
/* Stall HIFI4 DSP Execution: 1 stall, 0 not stall */
regmap_update_bits(regmap, SYSCTRL0, EXECUTE_BIT, EXECUTE_BIT);
usleep_range(1, 2);
arm_smccc_smc(FSL_SIP_HIFI_XRDC, 0, 0, 0, 0, 0, 0, 0, &smc_res);
return smc_res.a0;
}
static int imx8ulp_probe(struct snd_sof_dev *sdev)
{
struct imx_common_data *common;
struct regmap *regmap;
common = sdev->pdata->hw_pdata;
regmap = syscon_regmap_lookup_by_phandle(sdev->dev->of_node, "fsl,dsp-ctrl");
if (IS_ERR(regmap))
return dev_err_probe(sdev->dev, PTR_ERR(regmap),
"failed to fetch dsp ctrl regmap\n");
common->chip_pdata = regmap;
return 0;
}
static struct snd_soc_dai_driver imx8_dai[] = {
IMX_SOF_DAI_DRV_ENTRY_BIDIR("esai0", 1, 8),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai1", 1, 32),
};
static struct snd_soc_dai_driver imx8m_dai[] = {
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai1", 1, 32),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai2", 1, 32),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai3", 1, 32),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai5", 1, 32),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai6", 1, 32),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai7", 1, 32),
IMX_SOF_DAI_DRV_ENTRY("micfil", 0, 0, 1, 8),
};
static struct snd_soc_dai_driver imx8ulp_dai[] = {
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai5", 1, 32),
IMX_SOF_DAI_DRV_ENTRY_BIDIR("sai6", 1, 32),
};
static struct snd_sof_dsp_ops sof_imx8_ops;
static int imx8_ops_init(struct snd_sof_dev *sdev)
{
/* first copy from template */
memcpy(&sof_imx8_ops, &sof_imx_ops, sizeof(sof_imx_ops));
/* then set common imx8 ops */
sof_imx8_ops.dbg_dump = imx8_dump;
sof_imx8_ops.dsp_arch_ops = &sof_xtensa_arch_ops;
sof_imx8_ops.debugfs_add_region_item =
snd_sof_debugfs_add_region_item_iomem;
/* ... and finally set DAI driver */
sof_imx8_ops.drv = get_chip_info(sdev)->drv;
sof_imx8_ops.num_drv = get_chip_info(sdev)->num_drv;
return 0;
}
static const struct imx_chip_ops imx8_chip_ops = {
.probe = imx8_probe,
.core_kick = imx8_run,
.core_shutdown = imx8_shutdown,
};
static const struct imx_chip_ops imx8x_chip_ops = {
.probe = imx8_probe,
.core_kick = imx8x_run,
.core_shutdown = imx8_shutdown,
};
static const struct imx_chip_ops imx8m_chip_ops = {
.probe = imx8m_probe,
.core_kick = imx8m_run,
.core_reset = imx8m_reset,
};
static const struct imx_chip_ops imx8ulp_chip_ops = {
.probe = imx8ulp_probe,
.core_kick = imx8ulp_run,
.core_reset = imx8ulp_reset,
};
static struct imx_memory_info imx8_memory_regions[] = {
{ .name = "iram", .reserved = false },
{ .name = "sram", .reserved = true },
{ }
};
static struct imx_memory_info imx8m_memory_regions[] = {
{ .name = "iram", .reserved = false },
{ .name = "sram", .reserved = true },
{ }
};
static struct imx_memory_info imx8ulp_memory_regions[] = {
{ .name = "iram", .reserved = false },
{ .name = "sram", .reserved = true },
{ }
};
static const struct imx_chip_info imx8_chip_info = {
.ipc_info = {
.has_panic_code = true,
.boot_mbox_offset = 0x800000,
.window_offset = 0x800000,
},
.memory = imx8_memory_regions,
.drv = imx8_dai,
.num_drv = ARRAY_SIZE(imx8_dai),
.ops = &imx8_chip_ops,
};
static const struct imx_chip_info imx8x_chip_info = {
.ipc_info = {
.has_panic_code = true,
.boot_mbox_offset = 0x800000,
.window_offset = 0x800000,
},
.memory = imx8_memory_regions,
.drv = imx8_dai,
.num_drv = ARRAY_SIZE(imx8_dai),
.ops = &imx8x_chip_ops,
};
static const struct imx_chip_info imx8m_chip_info = {
.ipc_info = {
.has_panic_code = true,
.boot_mbox_offset = 0x800000,
.window_offset = 0x800000,
},
.memory = imx8m_memory_regions,
.drv = imx8m_dai,
.num_drv = ARRAY_SIZE(imx8m_dai),
.ops = &imx8m_chip_ops,
};
static const struct imx_chip_info imx8ulp_chip_info = {
.ipc_info = {
.has_panic_code = true,
.boot_mbox_offset = 0x800000,
.window_offset = 0x800000,
},
.has_dma_reserved = true,
.memory = imx8ulp_memory_regions,
.drv = imx8ulp_dai,
.num_drv = ARRAY_SIZE(imx8ulp_dai),
.ops = &imx8ulp_chip_ops,
};
static struct snd_sof_of_mach sof_imx8_machs[] = {
{
.compatible = "fsl,imx8qxp-mek",
.sof_tplg_filename = "sof-imx8-wm8960.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8qxp-mek-wcpu",
.sof_tplg_filename = "sof-imx8-wm8962.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8qm-mek",
.sof_tplg_filename = "sof-imx8-wm8960.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8qm-mek-revd",
.sof_tplg_filename = "sof-imx8-wm8962.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8qxp-mek-bb",
.sof_tplg_filename = "sof-imx8-cs42888.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8qm-mek-bb",
.sof_tplg_filename = "sof-imx8-cs42888.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8mp-evk",
.sof_tplg_filename = "sof-imx8mp-wm8960.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8mp-evk-revb4",
.sof_tplg_filename = "sof-imx8mp-wm8962.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{
.compatible = "fsl,imx8ulp-evk",
.sof_tplg_filename = "sof-imx8ulp-btsco.tplg",
.drv_name = "asoc-audio-graph-card2",
},
{}
};
IMX_SOF_DEV_DESC(imx8, sof_imx8_machs, &imx8_chip_info, &sof_imx8_ops, imx8_ops_init);
IMX_SOF_DEV_DESC(imx8x, sof_imx8_machs, &imx8x_chip_info, &sof_imx8_ops, imx8_ops_init);
IMX_SOF_DEV_DESC(imx8m, sof_imx8_machs, &imx8m_chip_info, &sof_imx8_ops, imx8_ops_init);
IMX_SOF_DEV_DESC(imx8ulp, sof_imx8_machs, &imx8ulp_chip_info, &sof_imx8_ops, imx8_ops_init);
static const struct of_device_id sof_of_imx8_ids[] = {
{
.compatible = "fsl,imx8qxp-dsp",
.data = &IMX_SOF_DEV_DESC_NAME(imx8x),
},
{
.compatible = "fsl,imx8qm-dsp",
.data = &IMX_SOF_DEV_DESC_NAME(imx8),
},
{
.compatible = "fsl,imx8mp-dsp",
.data = &IMX_SOF_DEV_DESC_NAME(imx8m),
},
{
.compatible = "fsl,imx8ulp-dsp",
.data = &IMX_SOF_DEV_DESC_NAME(imx8ulp),
},
{ }
};
MODULE_DEVICE_TABLE(of, sof_of_imx8_ids);
/* DT driver definition */
static struct platform_driver snd_sof_of_imx8_driver = {
.probe = sof_of_probe,
.remove = sof_of_remove,
.driver = {
.name = "sof-audio-of-imx8",
.pm = pm_ptr(&sof_of_pm),
.of_match_table = sof_of_imx8_ids,
},
};
module_platform_driver(snd_sof_of_imx8_driver);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("SOF support for IMX8 platforms");
MODULE_IMPORT_NS("SND_SOC_SOF_XTENSA");
|