summaryrefslogtreecommitdiff
path: root/sound/soc/fsl/fsl_dsp_cpu.c
blob: c203b70160f4dc0cd3acd02fd974f5a9a51a8436 (plain)
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
// SPDX-License-Identifier: GPL-2.0+
//
// DSP Audio platform driver
//
// Copyright 2018 NXP

#include <linux/clk.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <sound/soc.h>
#include <sound/core.h>
#include <sound/compress_driver.h>

#include "fsl_dsp_cpu.h"

static int dsp_audio_startup(struct snd_pcm_substream *substream,
			     struct snd_soc_dai *cpu_dai) {
	pm_runtime_get_sync(cpu_dai->dev);
	return 0;
}


static void dsp_audio_shutdown(struct snd_pcm_substream *substream,
			       struct snd_soc_dai *cpu_dai) {
	pm_runtime_put_sync(cpu_dai->dev);
}

static const struct snd_soc_dai_ops dsp_audio_dai_ops = {
	.startup = dsp_audio_startup,
	.shutdown = dsp_audio_shutdown,
};

static struct snd_soc_dai_driver dsp_audio_dai = {
	.name = "dsp-audio-cpu-dai",
	.compress_new = snd_soc_new_compress,
	.ops = &dsp_audio_dai_ops,
	.playback = {
		.stream_name = "Compress Playback",
		.channels_min = 1,
	},
};

static const struct snd_soc_component_driver audio_dsp_component = {
	.name           = "audio-dsp",
};

static int dsp_audio_probe(struct platform_device *pdev)
{
	struct fsl_dsp_audio *dsp_audio;
	int ret;

	dsp_audio = devm_kzalloc(&pdev->dev, sizeof(*dsp_audio), GFP_KERNEL);
	if (dsp_audio == NULL)
		return -ENOMEM;

	dev_dbg(&pdev->dev, "probing DSP device....\n");

	/* intialise sof device */
	dev_set_drvdata(&pdev->dev, dsp_audio);

	/* No error out for old DTB cases but only mark the clock NULL */
	dsp_audio->bus_clk = devm_clk_get(&pdev->dev, "bus");
	if (IS_ERR(dsp_audio->bus_clk)) {
		dev_err(&pdev->dev, "failed to get bus clock: %ld\n",
				PTR_ERR(dsp_audio->bus_clk));
		dsp_audio->bus_clk = NULL;
	}

	dsp_audio->m_clk = devm_clk_get(&pdev->dev, "mclk");
	if (IS_ERR(dsp_audio->m_clk)) {
		dev_err(&pdev->dev, "failed to get m clock: %ld\n",
				PTR_ERR(dsp_audio->m_clk));
		dsp_audio->m_clk = NULL;
	}

	pm_runtime_enable(&pdev->dev);

	/* now register audio DSP platform driver */
	ret = snd_soc_register_component(&pdev->dev, &audio_dsp_component,
			&dsp_audio_dai, 1);
	if (ret < 0) {
		dev_err(&pdev->dev,
			"error: failed to register DSP DAI driver %d\n", ret);
		goto err;
	}

        return 0;

err:
	return ret;
}

static int dsp_audio_remove(struct platform_device *pdev)
{
	snd_soc_unregister_component(&pdev->dev);
	return 0;
}

#ifdef CONFIG_PM
static int dsp_runtime_resume(struct device *dev)
{
	struct fsl_dsp_audio *dsp_audio = dev_get_drvdata(dev);
	int ret;

	ret = clk_prepare_enable(dsp_audio->bus_clk);
	if (ret) {
		dev_err(dev, "failed to enable bus clock: %d\n", ret);
		return ret;
	}

	ret = clk_prepare_enable(dsp_audio->m_clk);
	if (ret) {
		dev_err(dev, "failed to enable m clock: %d\n", ret);
		return ret;
	}

	return ret;
}

static int dsp_runtime_suspend(struct device *dev)
{
	struct fsl_dsp_audio *dsp_audio = dev_get_drvdata(dev);

	clk_disable_unprepare(dsp_audio->m_clk);
	clk_disable_unprepare(dsp_audio->bus_clk);

	return 0;
}
#endif

static const struct dev_pm_ops dsp_pm_ops = {
	SET_RUNTIME_PM_OPS(dsp_runtime_suspend,
			   dsp_runtime_resume,
			   NULL)
	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
};

static const struct of_device_id dsp_audio_ids[] = {
	{ .compatible = "fsl,dsp-audio"},
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, dsp_audio_ids);

static struct platform_driver dsp_audio_driver = {
	.driver = {
		.name = "dsp-audio",
		.of_match_table = dsp_audio_ids,
		.pm = &dsp_pm_ops,
	},
	.probe = dsp_audio_probe,
	.remove = dsp_audio_remove,
};
module_platform_driver(dsp_audio_driver);