da7210.c (959d851caa48829eb85cb85aa949fd6b4c5d5bc6) da7210.c (e6968a1719a88afa4708ff43696d6615f0be90be)
1/*
2 * DA7210 ALSA Soc codec driver
3 *
4 * Copyright (c) 2009 Dialog Semiconductor
5 * Written by David Chen <Dajun.chen@diasemi.com>
6 *
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
9 *
10 * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
18#include <linux/delay.h>
19#include <linux/i2c.h>
1/*
2 * DA7210 ALSA Soc codec driver
3 *
4 * Copyright (c) 2009 Dialog Semiconductor
5 * Written by David Chen <Dajun.chen@diasemi.com>
6 *
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
9 *
10 * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
18#include <linux/delay.h>
19#include <linux/i2c.h>
20#include <linux/spi/spi.h>
20#include <linux/regmap.h>
21#include <linux/slab.h>
22#include <linux/module.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
26#include <sound/initval.h>
27#include <sound/tlv.h>
28
29/* DA7210 register space */
21#include <linux/regmap.h>
22#include <linux/slab.h>
23#include <linux/module.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
27#include <sound/initval.h>
28#include <sound/tlv.h>
29
30/* DA7210 register space */
31#define DA7210_PAGE_CONTROL 0x00
30#define DA7210_CONTROL 0x01
31#define DA7210_STATUS 0x02
32#define DA7210_STARTUP1 0x03
33#define DA7210_STARTUP2 0x04
34#define DA7210_STARTUP3 0x05
35#define DA7210_MIC_L 0x07
36#define DA7210_MIC_R 0x08
37#define DA7210_AUX1_L 0x09

--- 588 unchanged lines hidden (view full) ---

626};
627
628/* Codec private data */
629struct da7210_priv {
630 struct regmap *regmap;
631};
632
633static struct reg_default da7210_reg_defaults[] = {
32#define DA7210_CONTROL 0x01
33#define DA7210_STATUS 0x02
34#define DA7210_STARTUP1 0x03
35#define DA7210_STARTUP2 0x04
36#define DA7210_STARTUP3 0x05
37#define DA7210_MIC_L 0x07
38#define DA7210_MIC_R 0x08
39#define DA7210_AUX1_L 0x09

--- 588 unchanged lines hidden (view full) ---

628};
629
630/* Codec private data */
631struct da7210_priv {
632 struct regmap *regmap;
633};
634
635static struct reg_default da7210_reg_defaults[] = {
636 { 0x00, 0x00 },
634 { 0x01, 0x11 },
635 { 0x03, 0x00 },
636 { 0x04, 0x00 },
637 { 0x05, 0x00 },
638 { 0x06, 0x00 },
639 { 0x07, 0x00 },
640 { 0x08, 0x00 },
641 { 0x09, 0x00 },

--- 66 unchanged lines hidden (view full) ---

708
709/*
710 * Set PCM DAI word length.
711 */
712static int da7210_hw_params(struct snd_pcm_substream *substream,
713 struct snd_pcm_hw_params *params,
714 struct snd_soc_dai *dai)
715{
637 { 0x01, 0x11 },
638 { 0x03, 0x00 },
639 { 0x04, 0x00 },
640 { 0x05, 0x00 },
641 { 0x06, 0x00 },
642 { 0x07, 0x00 },
643 { 0x08, 0x00 },
644 { 0x09, 0x00 },

--- 66 unchanged lines hidden (view full) ---

711
712/*
713 * Set PCM DAI word length.
714 */
715static int da7210_hw_params(struct snd_pcm_substream *substream,
716 struct snd_pcm_hw_params *params,
717 struct snd_soc_dai *dai)
718{
716 struct snd_soc_pcm_runtime *rtd = substream->private_data;
717 struct snd_soc_codec *codec = rtd->codec;
719 struct snd_soc_codec *codec = dai->codec;
718 u32 dai_cfg1;
719 u32 fs, bypass;
720
721 /* set DAI source to Left and Right ADC */
722 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
723 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
724
725 /* Enable DAI */

--- 197 unchanged lines hidden (view full) ---

923 * When you select different MCLK, please check...
924 * DA7210_PLL_DIV1 val
925 * DA7210_PLL_DIV2 val
926 * DA7210_PLL_DIV3 val
927 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
928 */
929
930 /*
720 u32 dai_cfg1;
721 u32 fs, bypass;
722
723 /* set DAI source to Left and Right ADC */
724 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
725 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
726
727 /* Enable DAI */

--- 197 unchanged lines hidden (view full) ---

925 * When you select different MCLK, please check...
926 * DA7210_PLL_DIV1 val
927 * DA7210_PLL_DIV2 val
928 * DA7210_PLL_DIV3 val
929 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
930 */
931
932 /*
931 * make sure that DA7210 use bypass mode before start up
932 */
933 snd_soc_write(codec, DA7210_STARTUP1, 0);
934 snd_soc_write(codec, DA7210_PLL_DIV3,
935 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
936
937 /*
938 * ADC settings
939 */
940
941 /* Enable Left & Right MIC PGA and Mic Bias */
942 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
943 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
944
945 /* Enable Left and Right input PGA */

--- 74 unchanged lines hidden (view full) ---

1020 * see da7210_hw_params
1021 */
1022 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
1023 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
1024 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
1025 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
1026 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1027
933 * ADC settings
934 */
935
936 /* Enable Left & Right MIC PGA and Mic Bias */
937 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
938 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
939
940 /* Enable Left and Right input PGA */

--- 74 unchanged lines hidden (view full) ---

1015 * see da7210_hw_params
1016 */
1017 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
1018 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
1019 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
1020 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
1021 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1022
1028 /* As suggested by Dialog */
1029 /* unlock */
1030 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x8B);
1031 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0xB4);
1032 regmap_write(da7210->regmap, DA7210_A_PLL1, 0x01);
1033 regmap_write(da7210->regmap, DA7210_A_CP_MODE, 0x7C);
1034 /* re-lock */
1035 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x00);
1036 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0x00);
1037
1038 /* Activate all enabled subsystem */
1039 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
1040
1041 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
1042
1043 return 0;
1044}
1045

--- 4 unchanged lines hidden (view full) ---

1050 .num_controls = ARRAY_SIZE(da7210_snd_controls),
1051
1052 .dapm_widgets = da7210_dapm_widgets,
1053 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
1054 .dapm_routes = da7210_audio_map,
1055 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
1056};
1057
1023 /* Activate all enabled subsystem */
1024 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
1025
1026 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
1027
1028 return 0;
1029}
1030

--- 4 unchanged lines hidden (view full) ---

1035 .num_controls = ARRAY_SIZE(da7210_snd_controls),
1036
1037 .dapm_widgets = da7210_dapm_widgets,
1038 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
1039 .dapm_routes = da7210_audio_map,
1040 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
1041};
1042
1058static struct regmap_config da7210_regmap = {
1043#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1044
1045static struct reg_default da7210_regmap_i2c_patch[] = {
1046
1047 /* System controller master disable */
1048 { DA7210_STARTUP1, 0x00 },
1049 /* make sure that DA7210 use bypass mode before start up */
1050 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1051
1052 /* to unlock */
1053 { DA7210_A_HID_UNLOCK, 0x8B},
1054 { DA7210_A_TEST_UNLOCK, 0xB4},
1055 { DA7210_A_PLL1, 0x01},
1056 { DA7210_A_CP_MODE, 0x7C},
1057 /* to re-lock */
1058 { DA7210_A_HID_UNLOCK, 0x00},
1059 { DA7210_A_TEST_UNLOCK, 0x00},
1060};
1061
1062static const struct regmap_config da7210_regmap_config_i2c = {
1059 .reg_bits = 8,
1060 .val_bits = 8,
1061
1062 .reg_defaults = da7210_reg_defaults,
1063 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1064 .volatile_reg = da7210_volatile_register,
1065 .readable_reg = da7210_readable_register,
1066 .cache_type = REGCACHE_RBTREE,
1067};
1068
1063 .reg_bits = 8,
1064 .val_bits = 8,
1065
1066 .reg_defaults = da7210_reg_defaults,
1067 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1068 .volatile_reg = da7210_volatile_register,
1069 .readable_reg = da7210_readable_register,
1070 .cache_type = REGCACHE_RBTREE,
1071};
1072
1069#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1070static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1071 const struct i2c_device_id *id)
1072{
1073 struct da7210_priv *da7210;
1074 int ret;
1075
1076 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1077 GFP_KERNEL);
1078 if (!da7210)
1079 return -ENOMEM;
1080
1081 i2c_set_clientdata(i2c, da7210);
1082
1073static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1074 const struct i2c_device_id *id)
1075{
1076 struct da7210_priv *da7210;
1077 int ret;
1078
1079 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1080 GFP_KERNEL);
1081 if (!da7210)
1082 return -ENOMEM;
1083
1084 i2c_set_clientdata(i2c, da7210);
1085
1083 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap);
1086 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
1084 if (IS_ERR(da7210->regmap)) {
1085 ret = PTR_ERR(da7210->regmap);
1086 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1087 return ret;
1088 }
1089
1087 if (IS_ERR(da7210->regmap)) {
1088 ret = PTR_ERR(da7210->regmap);
1089 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1090 return ret;
1091 }
1092
1093 ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
1094 ARRAY_SIZE(da7210_regmap_i2c_patch));
1095 if (ret != 0)
1096 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
1097
1090 ret = snd_soc_register_codec(&i2c->dev,
1091 &soc_codec_dev_da7210, &da7210_dai, 1);
1092 if (ret < 0) {
1093 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1094 goto err_regmap;
1095 }
1096 return ret;
1097

--- 16 unchanged lines hidden (view full) ---

1114 { "da7210", 0 },
1115 { }
1116};
1117MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1118
1119/* I2C codec control layer */
1120static struct i2c_driver da7210_i2c_driver = {
1121 .driver = {
1098 ret = snd_soc_register_codec(&i2c->dev,
1099 &soc_codec_dev_da7210, &da7210_dai, 1);
1100 if (ret < 0) {
1101 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1102 goto err_regmap;
1103 }
1104 return ret;
1105

--- 16 unchanged lines hidden (view full) ---

1122 { "da7210", 0 },
1123 { }
1124};
1125MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1126
1127/* I2C codec control layer */
1128static struct i2c_driver da7210_i2c_driver = {
1129 .driver = {
1122 .name = "da7210-codec",
1130 .name = "da7210",
1123 .owner = THIS_MODULE,
1124 },
1125 .probe = da7210_i2c_probe,
1126 .remove = __devexit_p(da7210_i2c_remove),
1127 .id_table = da7210_i2c_id,
1128};
1129#endif
1130
1131 .owner = THIS_MODULE,
1132 },
1133 .probe = da7210_i2c_probe,
1134 .remove = __devexit_p(da7210_i2c_remove),
1135 .id_table = da7210_i2c_id,
1136};
1137#endif
1138
1139#if defined(CONFIG_SPI_MASTER)
1140
1141static struct reg_default da7210_regmap_spi_patch[] = {
1142 /* Dummy read to give two pulses over nCS for SPI */
1143 { DA7210_AUX2, 0x00 },
1144 { DA7210_AUX2, 0x00 },
1145
1146 /* System controller master disable */
1147 { DA7210_STARTUP1, 0x00 },
1148 /* make sure that DA7210 use bypass mode before start up */
1149 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1150
1151 /* to set PAGE1 of SPI register space */
1152 { DA7210_PAGE_CONTROL, 0x80 },
1153 /* to unlock */
1154 { DA7210_A_HID_UNLOCK, 0x8B},
1155 { DA7210_A_TEST_UNLOCK, 0xB4},
1156 { DA7210_A_PLL1, 0x01},
1157 { DA7210_A_CP_MODE, 0x7C},
1158 /* to re-lock */
1159 { DA7210_A_HID_UNLOCK, 0x00},
1160 { DA7210_A_TEST_UNLOCK, 0x00},
1161 /* to set back PAGE0 of SPI register space */
1162 { DA7210_PAGE_CONTROL, 0x00 },
1163};
1164
1165static const struct regmap_config da7210_regmap_config_spi = {
1166 .reg_bits = 8,
1167 .val_bits = 8,
1168 .read_flag_mask = 0x01,
1169 .write_flag_mask = 0x00,
1170
1171 .reg_defaults = da7210_reg_defaults,
1172 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1173 .volatile_reg = da7210_volatile_register,
1174 .readable_reg = da7210_readable_register,
1175 .cache_type = REGCACHE_RBTREE,
1176};
1177
1178static int __devinit da7210_spi_probe(struct spi_device *spi)
1179{
1180 struct da7210_priv *da7210;
1181 int ret;
1182
1183 da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
1184 GFP_KERNEL);
1185 if (!da7210)
1186 return -ENOMEM;
1187
1188 spi_set_drvdata(spi, da7210);
1189 da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi);
1190 if (IS_ERR(da7210->regmap)) {
1191 ret = PTR_ERR(da7210->regmap);
1192 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
1193 return ret;
1194 }
1195
1196 ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
1197 ARRAY_SIZE(da7210_regmap_spi_patch));
1198 if (ret != 0)
1199 dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
1200
1201 ret = snd_soc_register_codec(&spi->dev,
1202 &soc_codec_dev_da7210, &da7210_dai, 1);
1203 if (ret < 0)
1204 goto err_regmap;
1205
1206 return ret;
1207
1208err_regmap:
1209 regmap_exit(da7210->regmap);
1210
1211 return ret;
1212}
1213
1214static int __devexit da7210_spi_remove(struct spi_device *spi)
1215{
1216 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1217 snd_soc_unregister_codec(&spi->dev);
1218 regmap_exit(da7210->regmap);
1219 return 0;
1220}
1221
1222static struct spi_driver da7210_spi_driver = {
1223 .driver = {
1224 .name = "da7210",
1225 .owner = THIS_MODULE,
1226 },
1227 .probe = da7210_spi_probe,
1228 .remove = __devexit_p(da7210_spi_remove)
1229};
1230#endif
1231
1131static int __init da7210_modinit(void)
1132{
1133 int ret = 0;
1134#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1135 ret = i2c_add_driver(&da7210_i2c_driver);
1136#endif
1232static int __init da7210_modinit(void)
1233{
1234 int ret = 0;
1235#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1236 ret = i2c_add_driver(&da7210_i2c_driver);
1237#endif
1238#if defined(CONFIG_SPI_MASTER)
1239 ret = spi_register_driver(&da7210_spi_driver);
1240 if (ret) {
1241 printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
1242 ret);
1243 }
1244#endif
1137 return ret;
1138}
1139module_init(da7210_modinit);
1140
1141static void __exit da7210_exit(void)
1142{
1143#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1144 i2c_del_driver(&da7210_i2c_driver);
1145#endif
1245 return ret;
1246}
1247module_init(da7210_modinit);
1248
1249static void __exit da7210_exit(void)
1250{
1251#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1252 i2c_del_driver(&da7210_i2c_driver);
1253#endif
1254#if defined(CONFIG_SPI_MASTER)
1255 spi_unregister_driver(&da7210_spi_driver);
1256#endif
1146}
1147module_exit(da7210_exit);
1148
1149MODULE_DESCRIPTION("ASoC DA7210 driver");
1150MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1151MODULE_LICENSE("GPL");
1257}
1258module_exit(da7210_exit);
1259
1260MODULE_DESCRIPTION("ASoC DA7210 driver");
1261MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1262MODULE_LICENSE("GPL");