Repository navigation
Expand file tree
/
Copy pathalh.c
More file actions
179 lines (141 loc) · 4.31 KB
/
Copy pathalh.c
File metadata and controls
179 lines (141 loc) · 4.31 KB
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
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
//
// Author: Slawomir Blauciak <slawomir.blauciak@linux.intel.com>
#include <sof/drivers/alh.h>
#include <sof/lib/dai.h>
#include <sof/lib/dma.h>
#include <sof/lib/memory.h>
#include <sof/lib/uuid.h>
#include <sof/trace/trace.h>
#include <sof/common.h>
#include <ipc/dai.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <user/trace.h>
#include <stdint.h>
#include <ipc4/alh.h>
LOG_MODULE_REGISTER(alh_dai, CONFIG_SOF_LOG_LEVEL);
/* a8e4218c-e863-4c93-84e7-5c27d2504501 */
DECLARE_SOF_UUID("alh-dai", alh_uuid, 0xa8e4218c, 0xe863, 0x4c93,
0x84, 0xe7, 0x5c, 0x27, 0xd2, 0x50, 0x45, 0x01);
DECLARE_TR_CTX(alh_tr, SOF_UUID(alh_uuid), LOG_LEVEL_INFO);
static int alh_trigger(struct dai *dai, int cmd, int direction)
{
dai_info(dai, "alh_trigger() cmd %d", cmd);
return 0;
}
static int alh_set_config_tplg(struct dai *dai, struct ipc_config_dai *common_config,
void *spec_config)
{
struct alh_pdata *alh = dai_get_drvdata(dai);
struct sof_ipc_dai_config *config = spec_config;
dai_info(dai, "alh_set_config_tplg() config->format = 0x%4x", config->format);
if (config->alh.channels || config->alh.rate) {
alh->params.channels = config->alh.channels;
alh->params.rate = config->alh.rate;
dai_info(dai, "alh_set_config() channels %d rate %d",
config->alh.channels, config->alh.rate);
}
alh->params.stream_id = config->alh.stream_id;
return 0;
}
static int alh_set_config_blob(struct dai *dai, struct ipc_config_dai *common_config,
void *spec_config)
{
struct alh_pdata *alh = dai_get_drvdata(dai);
struct sof_alh_configuration_blob *blob = spec_config;
struct ipc4_alh_multi_gtw_cfg *alh_cfg = &blob->alh_cfg;
int i;
dai_info(dai, "alh_set_config_blob()");
alh->params.rate = 48000;
for (i = 0; i < alh_cfg->count; i++) {
/* the LSB 8bits are for stream id */
int alh_id = alh_cfg->mapping[i].alh_id & 0xff;
if (IPC4_ALH_DAI_INDEX(alh_id) == dai->index) {
alh->params.stream_id = alh_id;
alh->params.channels = popcount(alh_cfg->mapping[i].channel_mask);
break;
}
}
return 0;
}
static int alh_set_config(struct dai *dai, struct ipc_config_dai *common_config,
void *spec_config)
{
if (!common_config->is_config_blob)
return alh_set_config_tplg(dai, common_config, spec_config);
else
return alh_set_config_blob(dai, common_config, spec_config);
}
/* get ALH hw params */
static int alh_get_hw_params(struct dai *dai,
struct sof_ipc_stream_params *params, int dir)
{
struct alh_pdata *alh = dai_get_drvdata(dai);
params->rate = alh->params.rate;
params->channels = alh->params.channels;
/* 0 means variable */
params->buffer_fmt = 0;
/* FIFO format is static */
params->frame_fmt = SOF_IPC_FRAME_S32_LE;
return 0;
}
static int alh_probe(struct dai *dai)
{
struct alh_pdata *alh;
dai_info(dai, "alh_probe()");
if (dai_get_drvdata(dai))
return -EEXIST;
alh = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*alh));
if (!alh) {
dai_err(dai, "alh_probe() error: alloc failed");
return -ENOMEM;
}
dai_set_drvdata(dai, alh);
return 0;
}
static int alh_remove(struct dai *dai)
{
dai_info(dai, "alh_remove()");
rfree(dai_get_drvdata(dai));
dai_set_drvdata(dai, NULL);
return 0;
}
static int alh_get_handshake(struct dai *dai, int direction, int stream_id)
{
if (stream_id >= ARRAY_SIZE(alh_handshake_map)) {
dai_err(dai, "alh_get_handshake(): "
"stream_id %d out of range", stream_id);
return -1;
}
return alh_handshake_map[stream_id];
}
static int alh_get_fifo(struct dai *dai, int direction, int stream_id)
{
uint32_t offset = direction == SOF_IPC_STREAM_PLAYBACK ?
ALH_TXDA_OFFSET : ALH_RXDA_OFFSET;
return ALH_BASE + offset + ALH_STREAM_OFFSET * stream_id;
}
static int alh_get_fifo_depth(struct dai *dai, int direction)
{
return dai->plat_data.fifo[direction].depth;
}
const struct dai_driver alh_driver = {
.type = SOF_DAI_INTEL_ALH,
.uid = SOF_UUID(alh_uuid),
.tctx = &alh_tr,
.dma_caps = DMA_CAP_GP_LP | DMA_CAP_GP_HP,
.dma_dev = DMA_DEV_ALH,
.ops = {
.trigger = alh_trigger,
.set_config = alh_set_config,
.get_hw_params = alh_get_hw_params,
.get_handshake = alh_get_handshake,
.get_fifo = alh_get_fifo,
.get_fifo_depth = alh_get_fifo_depth,
.probe = alh_probe,
.remove = alh_remove,
},
};