aboutsummaryrefslogtreecommitdiff
path: root/drivers/mfd/msm-adie-codec.c
blob: b9e317ef702d6fe9db62ae9e2df03d0a6591eb4b (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
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
/* Copyright (c) 2010, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
#include <linux/module.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/mfd/msm-adie-codec.h>
#include <linux/mfd/marimba.h>

static const struct adie_codec_operations *cur_adie_ops;

int adie_codec_register_codec_operations(
			const struct adie_codec_operations *adie_ops)
{
	if (adie_ops == NULL)
		return -EINVAL;

	if (adie_ops->codec_id != adie_get_detected_codec_type())
		return -EINVAL;

	cur_adie_ops = adie_ops;
	pr_info("%s: codec type %d\n", __func__, adie_ops->codec_id);
	return 0;
}

int adie_codec_open(struct adie_codec_dev_profile *profile,
	struct adie_codec_path **path_pptr)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_open != NULL)
			rc = cur_adie_ops->codec_open(profile, path_pptr);
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_open);

int adie_codec_close(struct adie_codec_path *path_ptr)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_close != NULL)
			rc = cur_adie_ops->codec_close(path_ptr);
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_close);

int adie_codec_set_device_digital_volume(struct adie_codec_path *path_ptr,
		u32 num_channels, u32 vol_percentage /* in percentage */)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_set_device_digital_volume != NULL) {
			rc = cur_adie_ops->codec_set_device_digital_volume(
							path_ptr,
							num_channels,
							vol_percentage);
		}
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_set_device_digital_volume);

int adie_codec_set_device_analog_volume(struct adie_codec_path *path_ptr,
		u32 num_channels, u32 volume /* in percentage */)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_set_device_analog_volume != NULL) {
			rc = cur_adie_ops->codec_set_device_analog_volume(
							path_ptr,
							num_channels,
							volume);
		}
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_set_device_analog_volume);

int adie_codec_setpath(struct adie_codec_path *path_ptr, u32 freq_plan, u32 osr)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_setpath != NULL) {
			rc = cur_adie_ops->codec_setpath(path_ptr,
							freq_plan,
							osr);
		}
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_setpath);

u32 adie_codec_freq_supported(struct adie_codec_dev_profile *profile,
	u32 requested_freq)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_freq_supported != NULL)
			rc = cur_adie_ops->codec_freq_supported(profile,
							requested_freq);
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_freq_supported);

int adie_codec_enable_sidetone(struct adie_codec_path *rx_path_ptr,
	u32 enable)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_enable_sidetone != NULL)
			rc = cur_adie_ops->codec_enable_sidetone(rx_path_ptr,
								enable);
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_enable_sidetone);

int adie_codec_enable_anc(struct adie_codec_path *rx_path_ptr,
	u32 enable, struct adie_codec_anc_data *calibration_writes)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_enable_anc != NULL)
			rc = cur_adie_ops->codec_enable_anc(rx_path_ptr,
				enable, calibration_writes);
	}

	return rc;
}
EXPORT_SYMBOL(adie_codec_enable_anc);

int adie_codec_proceed_stage(struct adie_codec_path *path_ptr, u32 state)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_proceed_stage != NULL)
			rc = cur_adie_ops->codec_proceed_stage(path_ptr,
								state);
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_proceed_stage);

int adie_codec_set_master_mode(struct adie_codec_path *path_ptr, u8 master)
{
	int rc = -EPERM;

	if (cur_adie_ops != NULL) {
		if (cur_adie_ops->codec_set_master_mode != NULL)
			rc = cur_adie_ops->codec_set_master_mode(path_ptr,
					master);
	} else
		rc = -ENODEV;

	return rc;
}
EXPORT_SYMBOL(adie_codec_set_master_mode);