blob: 624c5d24ef37596b2b776d389bbf00472d772e4b [file] [log] [blame]
Simon Glassc3014452018-12-10 10:37:48 -07001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +00002/*
3 * max98095.c -- MAX98095 ALSA SoC Audio driver
4 *
5 * Copyright 2011 Maxim Integrated Products
6 *
Simon Glassc3014452018-12-10 10:37:48 -07007 * Modified for U-Boot by R. Chandrasekar (rcsekar@samsung.com)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +00008 */
Simon Glass1d9af1f2017-05-30 21:47:09 -06009
10#include <common.h>
Simon Glass4070ba62018-12-10 10:37:39 -070011#include <audio_codec.h>
12#include <dm.h>
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000013#include <div64.h>
14#include <fdtdec.h>
15#include <i2c.h>
16#include <sound.h>
Simon Glassf2222362018-12-03 04:37:34 -070017#include <asm/gpio.h>
18#include <asm/io.h>
19#include <asm/arch/clk.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/power.h>
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000022#include "i2s.h"
23#include "max98095.h"
24
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000025/* Index 0 is reserved. */
26int rate_table[] = {0, 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000,
27 88200, 96000};
28
29/*
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000030 * codec mclk clock divider coefficients based on sampling rate
31 *
32 * @param rate sampling rate
33 * @param value address of indexvalue to be stored
34 *
35 * @return 0 for success or negative error code.
36 */
37static int rate_value(int rate, u8 *value)
38{
39 int i;
40
41 for (i = 1; i < ARRAY_SIZE(rate_table); i++) {
42 if (rate_table[i] >= rate) {
43 *value = i;
44 return 0;
45 }
46 }
47 *value = 1;
48
49 return -1;
50}
51
52/*
53 * Sets hw params for max98095
54 *
Simon Glassfd7d6972018-12-03 04:37:25 -070055 * @param priv max98095 information pointer
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000056 * @param rate Sampling rate
57 * @param bits_per_sample Bits per sample
58 *
59 * @return -1 for error and 0 Success.
60 */
Simon Glass504a7902018-12-10 10:37:42 -070061static int max98095_hw_params(struct maxim_priv *priv,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +053062 enum en_max_audio_interface aif_id,
63 unsigned int rate, unsigned int bits_per_sample)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000064{
65 u8 regval;
66 int error;
Dani Krishna Mohan6e194902013-09-11 16:38:50 +053067 unsigned short M98095_DAI_CLKMODE;
68 unsigned short M98095_DAI_FORMAT;
69 unsigned short M98095_DAI_FILTERS;
70
71 if (aif_id == AIF1) {
72 M98095_DAI_CLKMODE = M98095_027_DAI1_CLKMODE;
73 M98095_DAI_FORMAT = M98095_02A_DAI1_FORMAT;
74 M98095_DAI_FILTERS = M98095_02E_DAI1_FILTERS;
75 } else {
76 M98095_DAI_CLKMODE = M98095_031_DAI2_CLKMODE;
77 M98095_DAI_FORMAT = M98095_034_DAI2_FORMAT;
78 M98095_DAI_FILTERS = M98095_038_DAI2_FILTERS;
79 }
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000080
81 switch (bits_per_sample) {
82 case 16:
Simon Glass504a7902018-12-10 10:37:42 -070083 error = maxim_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_WS, 0);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000084 break;
85 case 24:
Simon Glass504a7902018-12-10 10:37:42 -070086 error = maxim_bic_or(priv, M98095_DAI_FORMAT, M98095_DAI_WS,
87 M98095_DAI_WS);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000088 break;
89 default:
90 debug("%s: Illegal bits per sample %d.\n",
Dani Krishna Mohan6e194902013-09-11 16:38:50 +053091 __func__, bits_per_sample);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000092 return -1;
93 }
94
95 if (rate_value(rate, &regval)) {
96 debug("%s: Failed to set sample rate to %d.\n",
Dani Krishna Mohan6e194902013-09-11 16:38:50 +053097 __func__, rate);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +000098 return -1;
99 }
Simon Glassfd7d6972018-12-03 04:37:25 -0700100 priv->rate = rate;
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000101
Simon Glass504a7902018-12-10 10:37:42 -0700102 error |= maxim_bic_or(priv, M98095_DAI_CLKMODE, M98095_CLKMODE_MASK,
Simon Glassfd7d6972018-12-03 04:37:25 -0700103 regval);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000104
105 /* Update sample rate mode */
106 if (rate < 50000)
Simon Glass504a7902018-12-10 10:37:42 -0700107 error |= maxim_bic_or(priv, M98095_DAI_FILTERS,
Simon Glassfd7d6972018-12-03 04:37:25 -0700108 M98095_DAI_DHF, 0);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000109 else
Simon Glass504a7902018-12-10 10:37:42 -0700110 error |= maxim_bic_or(priv, M98095_DAI_FILTERS,
Simon Glassfd7d6972018-12-03 04:37:25 -0700111 M98095_DAI_DHF, M98095_DAI_DHF);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000112
113 if (error < 0) {
114 debug("%s: Error setting hardware params.\n", __func__);
115 return -1;
116 }
117
118 return 0;
119}
120
121/*
122 * Configures Audio interface system clock for the given frequency
123 *
Simon Glassfd7d6972018-12-03 04:37:25 -0700124 * @param priv max98095 information
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000125 * @param freq Sampling frequency in Hz
126 *
127 * @return -1 for error and 0 success.
128 */
Simon Glass504a7902018-12-10 10:37:42 -0700129static int max98095_set_sysclk(struct maxim_priv *priv, unsigned int freq)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000130{
131 int error = 0;
132
133 /* Requested clock frequency is already setup */
Simon Glassfd7d6972018-12-03 04:37:25 -0700134 if (freq == priv->sysclk)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000135 return 0;
136
137 /* Setup clocks for slave mode, and using the PLL
138 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
139 * 0x02 (when master clk is 20MHz to 40MHz)..
140 * 0x03 (when master clk is 40MHz to 60MHz)..
141 */
142 if ((freq >= 10000000) && (freq < 20000000)) {
Simon Glass504a7902018-12-10 10:37:42 -0700143 error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x10);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000144 } else if ((freq >= 20000000) && (freq < 40000000)) {
Simon Glass504a7902018-12-10 10:37:42 -0700145 error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x20);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000146 } else if ((freq >= 40000000) && (freq < 60000000)) {
Simon Glass504a7902018-12-10 10:37:42 -0700147 error = maxim_i2c_write(priv, M98095_026_SYS_CLK, 0x30);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000148 } else {
149 debug("%s: Invalid master clock frequency\n", __func__);
150 return -1;
151 }
152
153 debug("%s: Clock at %uHz\n", __func__, freq);
154
155 if (error < 0)
156 return -1;
157
Simon Glassfd7d6972018-12-03 04:37:25 -0700158 priv->sysclk = freq;
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000159 return 0;
160}
161
162/*
163 * Sets Max98095 I2S format
164 *
Simon Glassfd7d6972018-12-03 04:37:25 -0700165 * @param priv max98095 information
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000166 * @param fmt i2S format - supports a subset of the options defined
167 * in i2s.h.
168 *
169 * @return -1 for error and 0 Success.
170 */
Simon Glass504a7902018-12-10 10:37:42 -0700171static int max98095_set_fmt(struct maxim_priv *priv, int fmt,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530172 enum en_max_audio_interface aif_id)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000173{
174 u8 regval = 0;
175 int error = 0;
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530176 unsigned short M98095_DAI_CLKCFG_HI;
177 unsigned short M98095_DAI_CLKCFG_LO;
178 unsigned short M98095_DAI_FORMAT;
179 unsigned short M98095_DAI_CLOCK;
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000180
Simon Glassfd7d6972018-12-03 04:37:25 -0700181 if (fmt == priv->fmt)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000182 return 0;
183
Simon Glassfd7d6972018-12-03 04:37:25 -0700184 priv->fmt = fmt;
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000185
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530186 if (aif_id == AIF1) {
187 M98095_DAI_CLKCFG_HI = M98095_028_DAI1_CLKCFG_HI;
188 M98095_DAI_CLKCFG_LO = M98095_029_DAI1_CLKCFG_LO;
189 M98095_DAI_FORMAT = M98095_02A_DAI1_FORMAT;
190 M98095_DAI_CLOCK = M98095_02B_DAI1_CLOCK;
191 } else {
192 M98095_DAI_CLKCFG_HI = M98095_032_DAI2_CLKCFG_HI;
193 M98095_DAI_CLKCFG_LO = M98095_033_DAI2_CLKCFG_LO;
194 M98095_DAI_FORMAT = M98095_034_DAI2_FORMAT;
195 M98095_DAI_CLOCK = M98095_035_DAI2_CLOCK;
196 }
197
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000198 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
199 case SND_SOC_DAIFMT_CBS_CFS:
200 /* Slave mode PLL */
Simon Glass504a7902018-12-10 10:37:42 -0700201 error |= maxim_i2c_write(priv, M98095_DAI_CLKCFG_HI, 0x80);
202 error |= maxim_i2c_write(priv, M98095_DAI_CLKCFG_LO, 0x00);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000203 break;
204 case SND_SOC_DAIFMT_CBM_CFM:
205 /* Set to master mode */
206 regval |= M98095_DAI_MAS;
207 break;
208 case SND_SOC_DAIFMT_CBS_CFM:
209 case SND_SOC_DAIFMT_CBM_CFS:
210 default:
211 debug("%s: Clock mode unsupported\n", __func__);
212 return -1;
213 }
214
215 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
216 case SND_SOC_DAIFMT_I2S:
217 regval |= M98095_DAI_DLY;
218 break;
219 case SND_SOC_DAIFMT_LEFT_J:
220 break;
221 default:
222 debug("%s: Unrecognized format.\n", __func__);
223 return -1;
224 }
225
226 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
227 case SND_SOC_DAIFMT_NB_NF:
228 break;
229 case SND_SOC_DAIFMT_NB_IF:
230 regval |= M98095_DAI_WCI;
231 break;
232 case SND_SOC_DAIFMT_IB_NF:
233 regval |= M98095_DAI_BCI;
234 break;
235 case SND_SOC_DAIFMT_IB_IF:
236 regval |= M98095_DAI_BCI | M98095_DAI_WCI;
237 break;
238 default:
239 debug("%s: Unrecognized inversion settings.\n", __func__);
240 return -1;
241 }
242
Simon Glass504a7902018-12-10 10:37:42 -0700243 error |= maxim_bic_or(priv, M98095_DAI_FORMAT,
Simon Glassfd7d6972018-12-03 04:37:25 -0700244 M98095_DAI_MAS | M98095_DAI_DLY |
245 M98095_DAI_BCI | M98095_DAI_WCI, regval);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000246
Simon Glass504a7902018-12-10 10:37:42 -0700247 error |= maxim_i2c_write(priv, M98095_DAI_CLOCK, M98095_DAI_BSEL64);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000248
249 if (error < 0) {
250 debug("%s: Error setting i2s format.\n", __func__);
251 return -1;
252 }
253
254 return 0;
255}
256
257/*
258 * resets the audio codec
259 *
Simon Glassfd7d6972018-12-03 04:37:25 -0700260 * @param priv Private data for driver
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000261 * @return -1 for error and 0 success.
262 */
Simon Glass504a7902018-12-10 10:37:42 -0700263static int max98095_reset(struct maxim_priv *priv)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000264{
265 int i, ret;
266
267 /*
268 * Gracefully reset the DSP core and the codec hardware in a proper
269 * sequence.
270 */
Simon Glass504a7902018-12-10 10:37:42 -0700271 ret = maxim_i2c_write(priv, M98095_00F_HOST_CFG, 0);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000272 if (ret != 0) {
273 debug("%s: Failed to reset DSP: %d\n", __func__, ret);
274 return ret;
275 }
276
Simon Glass504a7902018-12-10 10:37:42 -0700277 ret = maxim_i2c_write(priv, M98095_097_PWR_SYS, 0);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000278 if (ret != 0) {
279 debug("%s: Failed to reset codec: %d\n", __func__, ret);
280 return ret;
281 }
282
283 /*
284 * Reset to hardware default for registers, as there is not a soft
285 * reset hardware control register.
286 */
287 for (i = M98095_010_HOST_INT_CFG; i < M98095_REG_MAX_CACHED; i++) {
Simon Glass504a7902018-12-10 10:37:42 -0700288 ret = maxim_i2c_write(priv, i, 0);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000289 if (ret < 0) {
290 debug("%s: Failed to reset: %d\n", __func__, ret);
291 return ret;
292 }
293 }
294
295 return 0;
296}
297
298/*
299 * Intialise max98095 codec device
300 *
Simon Glassfd7d6972018-12-03 04:37:25 -0700301 * @param priv max98095 information
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000302 *
303 * @returns -1 for error and 0 Success.
304 */
Simon Glass504a7902018-12-10 10:37:42 -0700305static int max98095_device_init(struct maxim_priv *priv)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000306{
307 unsigned char id;
308 int error = 0;
309
Simon Glasse1458f62018-12-03 04:37:28 -0700310 /* Enable codec clock */
311 set_xclkout();
312
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000313 /* reset the codec, the DSP core, and disable all interrupts */
Simon Glassfd7d6972018-12-03 04:37:25 -0700314 error = max98095_reset(priv);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000315 if (error != 0) {
316 debug("Reset\n");
317 return error;
318 }
319
320 /* initialize private data */
Simon Glassfd7d6972018-12-03 04:37:25 -0700321 priv->sysclk = -1U;
322 priv->rate = -1U;
323 priv->fmt = -1U;
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000324
Simon Glass504a7902018-12-10 10:37:42 -0700325 error = maxim_i2c_read(priv, M98095_0FF_REV_ID, &id);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000326 if (error < 0) {
327 debug("%s: Failure reading hardware revision: %d\n",
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530328 __func__, id);
Simon Glasse1458f62018-12-03 04:37:28 -0700329 return error;
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000330 }
331 debug("%s: Hardware revision: %c\n", __func__, (id - 0x40) + 'A');
332
Simon Glasse1458f62018-12-03 04:37:28 -0700333 return 0;
334}
335
Simon Glass504a7902018-12-10 10:37:42 -0700336static int max98095_setup_interface(struct maxim_priv *priv,
Simon Glasse1458f62018-12-03 04:37:28 -0700337 enum en_max_audio_interface aif_id)
338{
339 int error;
340
Simon Glass504a7902018-12-10 10:37:42 -0700341 error = maxim_i2c_write(priv, M98095_097_PWR_SYS, M98095_PWRSV);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000342
343 /*
344 * initialize registers to hardware default configuring audio
345 * interface2 to DAC
346 */
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530347 if (aif_id == AIF1)
Simon Glass504a7902018-12-10 10:37:42 -0700348 error |= maxim_i2c_write(priv, M98095_048_MIX_DAC_LR,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530349 M98095_DAI1L_TO_DACL |
350 M98095_DAI1R_TO_DACR);
351 else
Simon Glass504a7902018-12-10 10:37:42 -0700352 error |= maxim_i2c_write(priv, M98095_048_MIX_DAC_LR,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530353 M98095_DAI2M_TO_DACL |
354 M98095_DAI2M_TO_DACR);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000355
Simon Glass504a7902018-12-10 10:37:42 -0700356 error |= maxim_i2c_write(priv, M98095_092_PWR_EN_OUT,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530357 M98095_SPK_SPREADSPECTRUM);
Simon Glass504a7902018-12-10 10:37:42 -0700358 error |= maxim_i2c_write(priv, M98095_04E_CFG_HP, M98095_HPNORMAL);
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530359 if (aif_id == AIF1)
Simon Glass504a7902018-12-10 10:37:42 -0700360 error |= maxim_i2c_write(priv, M98095_02C_DAI1_IOCFG,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530361 M98095_S1NORMAL | M98095_SDATA);
362 else
Simon Glass504a7902018-12-10 10:37:42 -0700363 error |= maxim_i2c_write(priv, M98095_036_DAI2_IOCFG,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530364 M98095_S2NORMAL | M98095_SDATA);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000365
366 /* take the codec out of the shut down */
Simon Glass504a7902018-12-10 10:37:42 -0700367 error |= maxim_bic_or(priv, M98095_097_PWR_SYS, M98095_SHDNRUN,
Simon Glassfd7d6972018-12-03 04:37:25 -0700368 M98095_SHDNRUN);
369 /*
370 * route DACL and DACR output to HO and Speakers
371 * Ordering: DACL, DACR, DACL, DACR
372 */
Simon Glass504a7902018-12-10 10:37:42 -0700373 error |= maxim_i2c_write(priv, M98095_050_MIX_SPK_LEFT, 0x01);
374 error |= maxim_i2c_write(priv, M98095_051_MIX_SPK_RIGHT, 0x01);
375 error |= maxim_i2c_write(priv, M98095_04C_MIX_HP_LEFT, 0x01);
376 error |= maxim_i2c_write(priv, M98095_04D_MIX_HP_RIGHT, 0x01);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000377
378 /* power Enable */
Simon Glass504a7902018-12-10 10:37:42 -0700379 error |= maxim_i2c_write(priv, M98095_091_PWR_EN_OUT, 0xF3);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000380
381 /* set Volume */
Simon Glass504a7902018-12-10 10:37:42 -0700382 error |= maxim_i2c_write(priv, M98095_064_LVL_HP_L, 15);
383 error |= maxim_i2c_write(priv, M98095_065_LVL_HP_R, 15);
384 error |= maxim_i2c_write(priv, M98095_067_LVL_SPK_L, 16);
385 error |= maxim_i2c_write(priv, M98095_068_LVL_SPK_R, 16);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000386
387 /* Enable DAIs */
Simon Glass504a7902018-12-10 10:37:42 -0700388 error |= maxim_i2c_write(priv, M98095_093_BIAS_CTRL, 0x30);
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530389 if (aif_id == AIF1)
Simon Glass504a7902018-12-10 10:37:42 -0700390 error |= maxim_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x01);
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530391 else
Simon Glass504a7902018-12-10 10:37:42 -0700392 error |= maxim_i2c_write(priv, M98095_096_PWR_DAC_CK, 0x07);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000393
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000394 if (error < 0)
395 return -1;
396
397 return 0;
398}
399
Simon Glass504a7902018-12-10 10:37:42 -0700400static int max98095_do_init(struct maxim_priv *priv,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530401 enum en_max_audio_interface aif_id,
402 int sampling_rate, int mclk_freq,
403 int bits_per_sample)
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000404{
405 int ret = 0;
406
Simon Glass860b11c2018-12-03 04:37:32 -0700407 ret = max98095_setup_interface(priv, aif_id);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000408 if (ret < 0) {
Simon Glass4070ba62018-12-10 10:37:39 -0700409 debug("%s: max98095 setup interface failed\n", __func__);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000410 return ret;
411 }
412
Simon Glass860b11c2018-12-03 04:37:32 -0700413 ret = max98095_set_sysclk(priv, mclk_freq);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000414 if (ret < 0) {
415 debug("%s: max98095 codec set sys clock failed\n", __func__);
416 return ret;
417 }
418
Simon Glass860b11c2018-12-03 04:37:32 -0700419 ret = max98095_hw_params(priv, aif_id, sampling_rate,
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530420 bits_per_sample);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000421
422 if (ret == 0) {
Simon Glass860b11c2018-12-03 04:37:32 -0700423 ret = max98095_set_fmt(priv, SND_SOC_DAIFMT_I2S |
Dani Krishna Mohan6e194902013-09-11 16:38:50 +0530424 SND_SOC_DAIFMT_NB_NF |
425 SND_SOC_DAIFMT_CBS_CFS,
426 aif_id);
Rajeshwari Shindecd93e9b2013-02-14 19:46:12 +0000427 }
428
429 return ret;
430}
431
Simon Glass4070ba62018-12-10 10:37:39 -0700432static int max98095_set_params(struct udevice *dev, int interface, int rate,
433 int mclk_freq, int bits_per_sample,
434 uint channels)
435{
Simon Glass504a7902018-12-10 10:37:42 -0700436 struct maxim_priv *priv = dev_get_priv(dev);
Simon Glass4070ba62018-12-10 10:37:39 -0700437
438 return max98095_do_init(priv, interface, rate, mclk_freq,
439 bits_per_sample);
440}
441
442static int max98095_probe(struct udevice *dev)
443{
Simon Glass504a7902018-12-10 10:37:42 -0700444 struct maxim_priv *priv = dev_get_priv(dev);
Simon Glass4070ba62018-12-10 10:37:39 -0700445 int ret;
446
447 priv->dev = dev;
448 ret = max98095_device_init(priv);
449 if (ret < 0) {
450 debug("%s: max98095 codec chip init failed\n", __func__);
451 return ret;
452 }
453
454 return 0;
455}
456
457static const struct audio_codec_ops max98095_ops = {
458 .set_params = max98095_set_params,
459};
460
461static const struct udevice_id max98095_ids[] = {
462 { .compatible = "maxim,max98095" },
463 { }
464};
465
466U_BOOT_DRIVER(max98095) = {
467 .name = "max98095",
468 .id = UCLASS_AUDIO_CODEC,
469 .of_match = max98095_ids,
470 .probe = max98095_probe,
471 .ops = &max98095_ops,
Simon Glass504a7902018-12-10 10:37:42 -0700472 .priv_auto_alloc_size = sizeof(struct maxim_priv),
Simon Glass4070ba62018-12-10 10:37:39 -0700473};