blob: b9e317ef702d6fe9db62ae9e2df03d0a6591eb4b [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2010, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#include <linux/module.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/mfd/msm-adie-codec.h>
17#include <linux/mfd/marimba.h>
18
19static const struct adie_codec_operations *cur_adie_ops;
20
21int adie_codec_register_codec_operations(
22 const struct adie_codec_operations *adie_ops)
23{
24 if (adie_ops == NULL)
25 return -EINVAL;
26
27 if (adie_ops->codec_id != adie_get_detected_codec_type())
28 return -EINVAL;
29
30 cur_adie_ops = adie_ops;
31 pr_info("%s: codec type %d\n", __func__, adie_ops->codec_id);
32 return 0;
33}
34
35int adie_codec_open(struct adie_codec_dev_profile *profile,
36 struct adie_codec_path **path_pptr)
37{
38 int rc = -EPERM;
39
40 if (cur_adie_ops != NULL) {
41 if (cur_adie_ops->codec_open != NULL)
42 rc = cur_adie_ops->codec_open(profile, path_pptr);
43 } else
44 rc = -ENODEV;
45
46 return rc;
47}
48EXPORT_SYMBOL(adie_codec_open);
49
50int adie_codec_close(struct adie_codec_path *path_ptr)
51{
52 int rc = -EPERM;
53
54 if (cur_adie_ops != NULL) {
55 if (cur_adie_ops->codec_close != NULL)
56 rc = cur_adie_ops->codec_close(path_ptr);
57 } else
58 rc = -ENODEV;
59
60 return rc;
61}
62EXPORT_SYMBOL(adie_codec_close);
63
64int adie_codec_set_device_digital_volume(struct adie_codec_path *path_ptr,
65 u32 num_channels, u32 vol_percentage /* in percentage */)
66{
67 int rc = -EPERM;
68
69 if (cur_adie_ops != NULL) {
70 if (cur_adie_ops->codec_set_device_digital_volume != NULL) {
71 rc = cur_adie_ops->codec_set_device_digital_volume(
72 path_ptr,
73 num_channels,
74 vol_percentage);
75 }
76 } else
77 rc = -ENODEV;
78
79 return rc;
80}
81EXPORT_SYMBOL(adie_codec_set_device_digital_volume);
82
83int adie_codec_set_device_analog_volume(struct adie_codec_path *path_ptr,
84 u32 num_channels, u32 volume /* in percentage */)
85{
86 int rc = -EPERM;
87
88 if (cur_adie_ops != NULL) {
89 if (cur_adie_ops->codec_set_device_analog_volume != NULL) {
90 rc = cur_adie_ops->codec_set_device_analog_volume(
91 path_ptr,
92 num_channels,
93 volume);
94 }
95 } else
96 rc = -ENODEV;
97
98 return rc;
99}
100EXPORT_SYMBOL(adie_codec_set_device_analog_volume);
101
102int adie_codec_setpath(struct adie_codec_path *path_ptr, u32 freq_plan, u32 osr)
103{
104 int rc = -EPERM;
105
106 if (cur_adie_ops != NULL) {
107 if (cur_adie_ops->codec_setpath != NULL) {
108 rc = cur_adie_ops->codec_setpath(path_ptr,
109 freq_plan,
110 osr);
111 }
112 } else
113 rc = -ENODEV;
114
115 return rc;
116}
117EXPORT_SYMBOL(adie_codec_setpath);
118
119u32 adie_codec_freq_supported(struct adie_codec_dev_profile *profile,
120 u32 requested_freq)
121{
122 int rc = -EPERM;
123
124 if (cur_adie_ops != NULL) {
125 if (cur_adie_ops->codec_freq_supported != NULL)
126 rc = cur_adie_ops->codec_freq_supported(profile,
127 requested_freq);
128 } else
129 rc = -ENODEV;
130
131 return rc;
132}
133EXPORT_SYMBOL(adie_codec_freq_supported);
134
135int adie_codec_enable_sidetone(struct adie_codec_path *rx_path_ptr,
136 u32 enable)
137{
138 int rc = -EPERM;
139
140 if (cur_adie_ops != NULL) {
141 if (cur_adie_ops->codec_enable_sidetone != NULL)
142 rc = cur_adie_ops->codec_enable_sidetone(rx_path_ptr,
143 enable);
144 } else
145 rc = -ENODEV;
146
147 return rc;
148}
149EXPORT_SYMBOL(adie_codec_enable_sidetone);
150
151int adie_codec_enable_anc(struct adie_codec_path *rx_path_ptr,
152 u32 enable, struct adie_codec_anc_data *calibration_writes)
153{
154 int rc = -EPERM;
155
156 if (cur_adie_ops != NULL) {
157 if (cur_adie_ops->codec_enable_anc != NULL)
158 rc = cur_adie_ops->codec_enable_anc(rx_path_ptr,
159 enable, calibration_writes);
160 }
161
162 return rc;
163}
164EXPORT_SYMBOL(adie_codec_enable_anc);
165
166int adie_codec_proceed_stage(struct adie_codec_path *path_ptr, u32 state)
167{
168 int rc = -EPERM;
169
170 if (cur_adie_ops != NULL) {
171 if (cur_adie_ops->codec_proceed_stage != NULL)
172 rc = cur_adie_ops->codec_proceed_stage(path_ptr,
173 state);
174 } else
175 rc = -ENODEV;
176
177 return rc;
178}
179EXPORT_SYMBOL(adie_codec_proceed_stage);
180
181int adie_codec_set_master_mode(struct adie_codec_path *path_ptr, u8 master)
182{
183 int rc = -EPERM;
184
185 if (cur_adie_ops != NULL) {
186 if (cur_adie_ops->codec_set_master_mode != NULL)
187 rc = cur_adie_ops->codec_set_master_mode(path_ptr,
188 master);
189 } else
190 rc = -ENODEV;
191
192 return rc;
193}
194EXPORT_SYMBOL(adie_codec_set_master_mode);
195
196