static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) { struct snd_soc_codec *codec = codec_dai->codec; u32 dai_cfg1; u32 dai_cfg3; dai_cfg1 = 0x7f & da7210_read(codec, DA7210_DAI_CFG1); dai_cfg3 = 0xfc & da7210_read(codec, DA7210_DAI_CFG3); switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: dai_cfg1 |= DA7210_DAI_MODE_MASTER; break; default: return -EINVAL; } /* FIXME * * It support I2S only now */ switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE; break; default: return -EINVAL; } /* FIXME * * It support 64bit data transmission only now */ dai_cfg1 |= DA7210_DAI_FLEN_64BIT; da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1); da7210_write(codec, DA7210_DAI_CFG3, dai_cfg3); return 0; }
static int da7210_init(struct da7210_priv *da7210) { struct snd_soc_codec *codec = &da7210->codec; int ret = 0; if (da7210_codec) { dev_err(codec->dev, "Another da7210 is registered\n"); return -EINVAL; } mutex_init(&codec->mutex); INIT_LIST_HEAD(&codec->dapm_widgets); INIT_LIST_HEAD(&codec->dapm_paths); snd_soc_codec_set_drvdata(codec, da7210); codec->name = "DA7210"; codec->owner = THIS_MODULE; codec->read = da7210_read; codec->write = da7210_write; codec->dai = &da7210_dai; codec->num_dai = 1; codec->hw_write = (hw_write_t)i2c_master_send; codec->reg_cache_size = ARRAY_SIZE(da7210_reg); codec->reg_cache = kmemdup(da7210_reg, sizeof(da7210_reg), GFP_KERNEL); if (!codec->reg_cache) return -ENOMEM; da7210_dai.dev = codec->dev; da7210_codec = codec; ret = snd_soc_register_codec(codec); if (ret) { dev_err(codec->dev, "Failed to register CODEC: %d\n", ret); goto init_err; } ret = snd_soc_register_dai(&da7210_dai); if (ret) { dev_err(codec->dev, "Failed to register DAI: %d\n", ret); goto init_err; } /* FIXME * * This driver use fixed value here * And below settings expects MCLK = 12.288MHz * * When you select different MCLK, please check... * DA7210_PLL_DIV1 val * DA7210_PLL_DIV2 val * DA7210_PLL_DIV3 val * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx */ /* * make sure that DA7210 use bypass mode before start up */ da7210_write(codec, DA7210_STARTUP1, 0); da7210_write(codec, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); /* * ADC settings */ /* Enable Left & Right MIC PGA and Mic Bias */ da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); /* Enable Left and Right input PGA */ da7210_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); da7210_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); /* Enable Left and Right ADC */ da7210_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); /* * DAC settings */ /* Enable Left and Right DAC */ da7210_write(codec, DA7210_DAC_SEL, DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); /* Enable Left and Right out PGA */ da7210_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); da7210_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); /* Enable Left and Right HeadPhone PGA */ da7210_write(codec, DA7210_HP_CFG, DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); /* Diable PLL and bypass it */ da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); /* * If 48kHz sound came, it use bypass mode, * and when it is 44.1kHz, it use PLL. * * This time, this driver sets PLL always ON * and controls bypass/PLL mode by switching * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. * see da7210_hw_params */ da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ da7210_write(codec, DA7210_PLL_DIV2, 0x99); da7210_write(codec, DA7210_PLL_DIV3, 0x0A | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); /* As suggested by Dialog */ da7210_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ da7210_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); da7210_write(codec, DA7210_A_PLL1, 0x01); da7210_write(codec, DA7210_A_CP_MODE, 0x7C); da7210_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ da7210_write(codec, DA7210_A_TEST_UNLOCK, 0x00); /* Activate all enabled subsystem */ da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); return ret; init_err: kfree(codec->reg_cache); codec->reg_cache = NULL; return ret; }
static int da7210_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_device *socdev = rtd->socdev; struct snd_soc_codec *codec = socdev->card->codec; u32 dai_cfg1; u32 hpf_reg, hpf_mask, hpf_value; u32 fs, bypass; /* set DAI source to Left and Right ADC */ da7210_write(codec, DA7210_DAI_SRC_SEL, DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); /* Enable DAI */ da7210_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN); dai_cfg1 = 0xFC & da7210_read(codec, DA7210_DAI_CFG1); switch (params_format(params)) { case SNDRV_PCM_FORMAT_S16_LE: dai_cfg1 |= DA7210_DAI_WORD_S16_LE; break; case SNDRV_PCM_FORMAT_S24_LE: dai_cfg1 |= DA7210_DAI_WORD_S24_LE; break; default: return -EINVAL; } da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1); hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ? DA7210_DAC_HPF : DA7210_ADC_HPF; switch (params_rate(params)) { case 8000: fs = DA7210_PLL_FS_8000; hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; bypass = DA7210_PLL_BYP; break; case 11025: fs = DA7210_PLL_FS_11025; hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; bypass = 0; break; case 12000: fs = DA7210_PLL_FS_12000; hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; bypass = DA7210_PLL_BYP; break; case 16000: fs = DA7210_PLL_FS_16000; hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; bypass = DA7210_PLL_BYP; break; case 22050: fs = DA7210_PLL_FS_22050; hpf_mask = DA7210_VOICE_EN; hpf_value = 0; bypass = 0; break; case 32000: fs = DA7210_PLL_FS_32000; hpf_mask = DA7210_VOICE_EN; hpf_value = 0; bypass = DA7210_PLL_BYP; break; case 44100: fs = DA7210_PLL_FS_44100; hpf_mask = DA7210_VOICE_EN; hpf_value = 0; bypass = 0; break; case 48000: fs = DA7210_PLL_FS_48000; hpf_mask = DA7210_VOICE_EN; hpf_value = 0; bypass = DA7210_PLL_BYP; break; case 88200: fs = DA7210_PLL_FS_88200; hpf_mask = DA7210_VOICE_EN; hpf_value = 0; bypass = 0; break; case 96000: fs = DA7210_PLL_FS_96000; hpf_mask = DA7210_VOICE_EN; hpf_value = 0; bypass = DA7210_PLL_BYP; break; default: return -EINVAL; } /* Disable active mode */ snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value); snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass); /* Enable active mode */ snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, DA7210_SC_MST_EN); return 0; }
static int da7210_probe(struct snd_soc_codec *codec) { struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); codec->control_data = da7210->control_data; codec->hw_write = (hw_write_t)i2c_master_send; /* FIXME * * This driver use fixed value here * And below settings expects MCLK = 12.288MHz * * When you select different MCLK, please check... * DA7210_PLL_DIV1 val * DA7210_PLL_DIV2 val * DA7210_PLL_DIV3 val * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx */ /* * make sure that DA7210 use bypass mode before start up */ da7210_write(codec, DA7210_STARTUP1, 0); da7210_write(codec, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); /* * ADC settings */ /* Enable Left & Right MIC PGA and Mic Bias */ da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); /* Enable Left and Right input PGA */ da7210_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); da7210_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); /* Enable Left and Right ADC */ da7210_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); /* * DAC settings */ /* Enable Left and Right DAC */ da7210_write(codec, DA7210_DAC_SEL, DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); /* Enable Left and Right out PGA */ da7210_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); da7210_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); /* Enable Left and Right HeadPhone PGA */ da7210_write(codec, DA7210_HP_CFG, DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); /* Diable PLL and bypass it */ da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); /* * If 48kHz sound came, it use bypass mode, * and when it is 44.1kHz, it use PLL. * * This time, this driver sets PLL always ON * and controls bypass/PLL mode by switching * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. * see da7210_hw_params */ da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ da7210_write(codec, DA7210_PLL_DIV2, 0x99); da7210_write(codec, DA7210_PLL_DIV3, 0x0A | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); /* As suggested by Dialog */ da7210_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ da7210_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); da7210_write(codec, DA7210_A_PLL1, 0x01); da7210_write(codec, DA7210_A_CP_MODE, 0x7C); da7210_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ da7210_write(codec, DA7210_A_TEST_UNLOCK, 0x00); /* Activate all enabled subsystem */ da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); snd_soc_add_controls(codec, da7210_snd_controls, ARRAY_SIZE(da7210_snd_controls)); dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); return 0; }