static int ak4642_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; struct snd_soc_codec *codec = dai->codec; if (is_play) { /* * start headphone output * * PLL, Master Mode * Audio I/F Format :MSB justified (ADC & DAC) * Bass Boost Level : Middle * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p97. */ snd_soc_update_bits(codec, MD_CTL4, DACH, DACH); snd_soc_update_bits(codec, MD_CTL3, BST1, BST1); ak4642_write(codec, L_IVC, 0x91); /* volume */ ak4642_write(codec, R_IVC, 0x91); /* volume */ snd_soc_update_bits(codec, PW_MGMT1, PMVCM | PMMIN | PMDAC, PMVCM | PMMIN | PMDAC); snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK, PMHP); snd_soc_update_bits(codec, PW_MGMT2, HPMTN, HPMTN); } else { /* * start stereo input * * PLL Master Mode * Audio I/F Format:MSB justified (ADC & DAC) * Pre MIC AMP:+20dB * MIC Power On * ALC setting:Refer to Table 35 * ALC bit=“1” * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p94. */ ak4642_write(codec, SG_SL1, PMMP | MGAIN0); ak4642_write(codec, TIMER, ZTM(0x3) | WTM(0x3)); ak4642_write(codec, ALC_CTL1, ALC | LMTH0); snd_soc_update_bits(codec, PW_MGMT1, PMVCM | PMADL, PMVCM | PMADL); snd_soc_update_bits(codec, PW_MGMT3, PMADR, PMADR); } return 0; }
static int ak4642_sync(struct snd_soc_codec *codec) { u16 *cache = codec->reg_cache; int i, r = 0; for (i = 0; i < AK4642_CACHEREGNUM; i++) r |= ak4642_write(codec, i, cache[i]); return r; };
static void ak4642_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; struct snd_soc_codec *codec = dai->codec; if (is_play) { /* stop headphone output */ ak4642_write(codec, 0x01, 0x3b); ak4642_write(codec, 0x01, 0x0b); ak4642_write(codec, 0x00, 0x40); ak4642_write(codec, 0x0e, 0x11); ak4642_write(codec, 0x0f, 0x08); } else { /* stop stereo input */ ak4642_write(codec, 0x00, 0x40); ak4642_write(codec, 0x10, 0x00); ak4642_write(codec, 0x07, 0x01); } }
/* * initialise the AK4642 driver * register the mixer and dsp interfaces with the kernel */ static int ak4642_init(struct ak4642_priv *ak4642) { struct snd_soc_codec *codec = &ak4642->codec; int ret = 0; if (ak4642_codec) { dev_err(codec->dev, "Another ak4642 is registered\n"); return -EINVAL; } mutex_init(&codec->mutex); INIT_LIST_HEAD(&codec->dapm_widgets); INIT_LIST_HEAD(&codec->dapm_paths); codec->private_data = ak4642; codec->name = "AK4642"; codec->owner = THIS_MODULE; codec->read = ak4642_read_reg_cache; codec->write = ak4642_write; codec->dai = &ak4642_dai; codec->num_dai = 1; codec->hw_write = (hw_write_t)i2c_master_send; codec->reg_cache_size = ARRAY_SIZE(ak4642_reg); codec->reg_cache = kmemdup(ak4642_reg, sizeof(ak4642_reg), GFP_KERNEL); if (!codec->reg_cache) return -ENOMEM; ak4642_dai.dev = codec->dev; ak4642_codec = codec; ret = snd_soc_register_codec(codec); if (ret) { dev_err(codec->dev, "Failed to register codec: %d\n", ret); goto reg_cache_err; } ret = snd_soc_register_dai(&ak4642_dai); if (ret) { dev_err(codec->dev, "Failed to register DAI: %d\n", ret); snd_soc_unregister_codec(codec); goto reg_cache_err; } /* * clock setting * * Audio I/F Format: MSB justified (ADC & DAC) * BICK frequency at Master Mode: 64fs * Input Master Clock Select at PLL Mode: 11.2896MHz * MCKO: Enable * Sampling Frequency: 44.1kHz * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p89. * * please fix-me */ ak4642_write(codec, 0x01, 0x08); ak4642_write(codec, 0x04, 0x4a); ak4642_write(codec, 0x05, 0x27); ak4642_write(codec, 0x00, 0x40); ak4642_write(codec, 0x01, 0x0b); return ret; reg_cache_err: kfree(codec->reg_cache); codec->reg_cache = NULL; return ret; }
static int ak4642_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; struct snd_soc_codec *codec = dai->codec; if (is_play) { /* * start headphone output * * PLL, Master Mode * Audio I/F Format :MSB justified (ADC & DAC) * Sampling Frequency: 44.1kHz * Digital Volume: −8dB * Bass Boost Level : Middle * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p97. * * Example code use 0x39, 0x79 value for 0x01 address, * But we need MCKO (0x02) bit now */ ak4642_write(codec, 0x05, 0x27); ak4642_write(codec, 0x0f, 0x09); ak4642_write(codec, 0x0e, 0x19); ak4642_write(codec, 0x09, 0x91); ak4642_write(codec, 0x0c, 0x91); ak4642_write(codec, 0x0a, 0x28); ak4642_write(codec, 0x0d, 0x28); ak4642_write(codec, 0x00, 0x64); ak4642_write(codec, 0x01, 0x3b); /* + MCKO bit */ ak4642_write(codec, 0x01, 0x7b); /* + MCKO bit */ } else { /* * start stereo input * * PLL Master Mode * Audio I/F Format:MSB justified (ADC & DAC) * Sampling Frequency:44.1kHz * Pre MIC AMP:+20dB * MIC Power On * ALC setting:Refer to Table 35 * ALC bit=“1” * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p94. */ ak4642_write(codec, 0x05, 0x27); ak4642_write(codec, 0x02, 0x05); ak4642_write(codec, 0x06, 0x3c); ak4642_write(codec, 0x08, 0xe1); ak4642_write(codec, 0x0b, 0x00); ak4642_write(codec, 0x07, 0x21); ak4642_write(codec, 0x00, 0x41); ak4642_write(codec, 0x10, 0x01); } return 0; }
static int ak4642_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; struct snd_soc_codec *codec = dai->codec; if (is_play) { /* * start headphone output * * PLL, Master Mode * Audio I/F Format :MSB justified (ADC & DAC) * Bass Boost Level : Middle * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p97. */ ak4642_write(codec, 0x0f, 0x09); ak4642_write(codec, 0x0e, 0x19); ak4642_write(codec, 0x09, 0x91); ak4642_write(codec, 0x0c, 0x91); ak4642_write(codec, 0x00, 0x64); snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK, PMHP); snd_soc_update_bits(codec, PW_MGMT2, HPMTN, HPMTN); } else { /* * start stereo input * * PLL Master Mode * Audio I/F Format:MSB justified (ADC & DAC) * Pre MIC AMP:+20dB * MIC Power On * ALC setting:Refer to Table 35 * ALC bit=“1” * * This operation came from example code of * "ASAHI KASEI AK4642" (japanese) manual p94. */ ak4642_write(codec, 0x02, 0x05); ak4642_write(codec, 0x06, 0x3c); ak4642_write(codec, 0x08, 0xe1); ak4642_write(codec, 0x0b, 0x00); ak4642_write(codec, 0x07, 0x21); ak4642_write(codec, 0x00, 0x41); ak4642_write(codec, 0x10, 0x01); } return 0; }