aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/sgtl5000.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/sgtl5000.c')
-rw-r--r--sound/soc/codecs/sgtl5000.c198
1 files changed, 67 insertions, 131 deletions
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index ff29380c9ed..7e4066e131e 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -33,73 +33,31 @@
33#define SGTL5000_DAP_REG_OFFSET 0x0100 33#define SGTL5000_DAP_REG_OFFSET 0x0100
34#define SGTL5000_MAX_REG_OFFSET 0x013A 34#define SGTL5000_MAX_REG_OFFSET 0x013A
35 35
36/* default value of sgtl5000 registers except DAP */ 36/* default value of sgtl5000 registers */
37static const u16 sgtl5000_regs[SGTL5000_MAX_REG_OFFSET >> 1] = { 37static const u16 sgtl5000_regs[SGTL5000_MAX_REG_OFFSET] = {
38 0xa011, /* 0x0000, CHIP_ID. 11 stand for revison 17 */ 38 [SGTL5000_CHIP_CLK_CTRL] = 0x0008,
39 0x0000, /* 0x0002, CHIP_DIG_POWER. */ 39 [SGTL5000_CHIP_I2S_CTRL] = 0x0010,
40 0x0008, /* 0x0004, CHIP_CKL_CTRL */ 40 [SGTL5000_CHIP_SSS_CTRL] = 0x0008,
41 0x0010, /* 0x0006, CHIP_I2S_CTRL */ 41 [SGTL5000_CHIP_DAC_VOL] = 0x3c3c,
42 0x0000, /* 0x0008, reserved */ 42 [SGTL5000_CHIP_PAD_STRENGTH] = 0x015f,
43 0x0008, /* 0x000A, CHIP_SSS_CTRL */ 43 [SGTL5000_CHIP_ANA_HP_CTRL] = 0x1818,
44 0x0000, /* 0x000C, reserved */ 44 [SGTL5000_CHIP_ANA_CTRL] = 0x0111,
45 0x020c, /* 0x000E, CHIP_ADCDAC_CTRL */ 45 [SGTL5000_CHIP_LINE_OUT_VOL] = 0x0404,
46 0x3c3c, /* 0x0010, CHIP_DAC_VOL */ 46 [SGTL5000_CHIP_ANA_POWER] = 0x7060,
47 0x0000, /* 0x0012, reserved */ 47 [SGTL5000_CHIP_PLL_CTRL] = 0x5000,
48 0x015f, /* 0x0014, CHIP_PAD_STRENGTH */ 48 [SGTL5000_DAP_BASS_ENHANCE] = 0x0040,
49 0x0000, /* 0x0016, reserved */ 49 [SGTL5000_DAP_BASS_ENHANCE_CTRL] = 0x051f,
50 0x0000, /* 0x0018, reserved */ 50 [SGTL5000_DAP_SURROUND] = 0x0040,
51 0x0000, /* 0x001A, reserved */ 51 [SGTL5000_DAP_EQ_BASS_BAND0] = 0x002f,
52 0x0000, /* 0x001E, reserved */ 52 [SGTL5000_DAP_EQ_BASS_BAND1] = 0x002f,
53 0x0000, /* 0x0020, CHIP_ANA_ADC_CTRL */ 53 [SGTL5000_DAP_EQ_BASS_BAND2] = 0x002f,
54 0x1818, /* 0x0022, CHIP_ANA_HP_CTRL */ 54 [SGTL5000_DAP_EQ_BASS_BAND3] = 0x002f,
55 0x0111, /* 0x0024, CHIP_ANN_CTRL */ 55 [SGTL5000_DAP_EQ_BASS_BAND4] = 0x002f,
56 0x0000, /* 0x0026, CHIP_LINREG_CTRL */ 56 [SGTL5000_DAP_MAIN_CHAN] = 0x8000,
57 0x0000, /* 0x0028, CHIP_REF_CTRL */ 57 [SGTL5000_DAP_AVC_CTRL] = 0x0510,
58 0x0000, /* 0x002A, CHIP_MIC_CTRL */ 58 [SGTL5000_DAP_AVC_THRESHOLD] = 0x1473,
59 0x0000, /* 0x002C, CHIP_LINE_OUT_CTRL */ 59 [SGTL5000_DAP_AVC_ATTACK] = 0x0028,
60 0x0404, /* 0x002E, CHIP_LINE_OUT_VOL */ 60 [SGTL5000_DAP_AVC_DECAY] = 0x0050,
61 0x7060, /* 0x0030, CHIP_ANA_POWER */
62 0x5000, /* 0x0032, CHIP_PLL_CTRL */
63 0x0000, /* 0x0034, CHIP_CLK_TOP_CTRL */
64 0x0000, /* 0x0036, CHIP_ANA_STATUS */
65 0x0000, /* 0x0038, reserved */
66 0x0000, /* 0x003A, CHIP_ANA_TEST2 */
67 0x0000, /* 0x003C, CHIP_SHORT_CTRL */
68 0x0000, /* reserved */
69};
70
71/* default value of dap registers */
72static const u16 sgtl5000_dap_regs[] = {
73 0x0000, /* 0x0100, DAP_CONTROL */
74 0x0000, /* 0x0102, DAP_PEQ */
75 0x0040, /* 0x0104, DAP_BASS_ENHANCE */
76 0x051f, /* 0x0106, DAP_BASS_ENHANCE_CTRL */
77 0x0000, /* 0x0108, DAP_AUDIO_EQ */
78 0x0040, /* 0x010A, DAP_SGTL_SURROUND */
79 0x0000, /* 0x010C, DAP_FILTER_COEF_ACCESS */
80 0x0000, /* 0x010E, DAP_COEF_WR_B0_MSB */
81 0x0000, /* 0x0110, DAP_COEF_WR_B0_LSB */
82 0x0000, /* 0x0112, reserved */
83 0x0000, /* 0x0114, reserved */
84 0x002f, /* 0x0116, DAP_AUDIO_EQ_BASS_BAND0 */
85 0x002f, /* 0x0118, DAP_AUDIO_EQ_BAND0 */
86 0x002f, /* 0x011A, DAP_AUDIO_EQ_BAND2 */
87 0x002f, /* 0x011C, DAP_AUDIO_EQ_BAND3 */
88 0x002f, /* 0x011E, DAP_AUDIO_EQ_TREBLE_BAND4 */
89 0x8000, /* 0x0120, DAP_MAIN_CHAN */
90 0x0000, /* 0x0122, DAP_MIX_CHAN */
91 0x0510, /* 0x0124, DAP_AVC_CTRL */
92 0x1473, /* 0x0126, DAP_AVC_THRESHOLD */
93 0x0028, /* 0x0128, DAP_AVC_ATTACK */
94 0x0050, /* 0x012A, DAP_AVC_DECAY */
95 0x0000, /* 0x012C, DAP_COEF_WR_B1_MSB */
96 0x0000, /* 0x012E, DAP_COEF_WR_B1_LSB */
97 0x0000, /* 0x0130, DAP_COEF_WR_B2_MSB */
98 0x0000, /* 0x0132, DAP_COEF_WR_B2_LSB */
99 0x0000, /* 0x0134, DAP_COEF_WR_A1_MSB */
100 0x0000, /* 0x0136, DAP_COEF_WR_A1_LSB */
101 0x0000, /* 0x0138, DAP_COEF_WR_A2_MSB */
102 0x0000, /* 0x013A, DAP_COEF_WR_A2_LSB */
103}; 61};
104 62
105/* regulator supplies for sgtl5000, VDDD is an optional external supply */ 63/* regulator supplies for sgtl5000, VDDD is an optional external supply */
@@ -907,6 +865,7 @@ static int ldo_regulator_register(struct snd_soc_codec *codec,
907 struct regulator_init_data *init_data, 865 struct regulator_init_data *init_data,
908 int voltage) 866 int voltage)
909{ 867{
868 dev_err(codec->dev, "this setup needs regulator support in the kernel\n");
910 return -EINVAL; 869 return -EINVAL;
911} 870}
912 871
@@ -1022,12 +981,10 @@ static int sgtl5000_suspend(struct snd_soc_codec *codec, pm_message_t state)
1022static int sgtl5000_restore_regs(struct snd_soc_codec *codec) 981static int sgtl5000_restore_regs(struct snd_soc_codec *codec)
1023{ 982{
1024 u16 *cache = codec->reg_cache; 983 u16 *cache = codec->reg_cache;
1025 int i; 984 u16 reg;
1026 int regular_regs = SGTL5000_CHIP_SHORT_CTRL >> 1;
1027 985
1028 /* restore regular registers */ 986 /* restore regular registers */
1029 for (i = 0; i < regular_regs; i++) { 987 for (reg = 0; reg <= SGTL5000_CHIP_SHORT_CTRL; reg += 2) {
1030 int reg = i << 1;
1031 988
1032 /* this regs depends on the others */ 989 /* this regs depends on the others */
1033 if (reg == SGTL5000_CHIP_ANA_POWER || 990 if (reg == SGTL5000_CHIP_ANA_POWER ||
@@ -1037,35 +994,31 @@ static int sgtl5000_restore_regs(struct snd_soc_codec *codec)
1037 reg == SGTL5000_CHIP_CLK_CTRL) 994 reg == SGTL5000_CHIP_CLK_CTRL)
1038 continue; 995 continue;
1039 996
1040 snd_soc_write(codec, reg, cache[i]); 997 snd_soc_write(codec, reg, cache[reg]);
1041 } 998 }
1042 999
1043 /* restore dap registers */ 1000 /* restore dap registers */
1044 for (i = SGTL5000_DAP_REG_OFFSET >> 1; 1001 for (reg = SGTL5000_DAP_REG_OFFSET; reg < SGTL5000_MAX_REG_OFFSET; reg += 2)
1045 i < SGTL5000_MAX_REG_OFFSET >> 1; i++) { 1002 snd_soc_write(codec, reg, cache[reg]);
1046 int reg = i << 1;
1047
1048 snd_soc_write(codec, reg, cache[i]);
1049 }
1050 1003
1051 /* 1004 /*
1052 * restore power and other regs according 1005 * restore power and other regs according
1053 * to set_power() and set_clock() 1006 * to set_power() and set_clock()
1054 */ 1007 */
1055 snd_soc_write(codec, SGTL5000_CHIP_LINREG_CTRL, 1008 snd_soc_write(codec, SGTL5000_CHIP_LINREG_CTRL,
1056 cache[SGTL5000_CHIP_LINREG_CTRL >> 1]); 1009 cache[SGTL5000_CHIP_LINREG_CTRL]);
1057 1010
1058 snd_soc_write(codec, SGTL5000_CHIP_ANA_POWER, 1011 snd_soc_write(codec, SGTL5000_CHIP_ANA_POWER,
1059 cache[SGTL5000_CHIP_ANA_POWER >> 1]); 1012 cache[SGTL5000_CHIP_ANA_POWER]);
1060 1013
1061 snd_soc_write(codec, SGTL5000_CHIP_CLK_CTRL, 1014 snd_soc_write(codec, SGTL5000_CHIP_CLK_CTRL,
1062 cache[SGTL5000_CHIP_CLK_CTRL >> 1]); 1015 cache[SGTL5000_CHIP_CLK_CTRL]);
1063 1016
1064 snd_soc_write(codec, SGTL5000_CHIP_REF_CTRL, 1017 snd_soc_write(codec, SGTL5000_CHIP_REF_CTRL,
1065 cache[SGTL5000_CHIP_REF_CTRL >> 1]); 1018 cache[SGTL5000_CHIP_REF_CTRL]);
1066 1019
1067 snd_soc_write(codec, SGTL5000_CHIP_LINE_OUT_CTRL, 1020 snd_soc_write(codec, SGTL5000_CHIP_LINE_OUT_CTRL,
1068 cache[SGTL5000_CHIP_LINE_OUT_CTRL >> 1]); 1021 cache[SGTL5000_CHIP_LINE_OUT_CTRL]);
1069 return 0; 1022 return 0;
1070} 1023}
1071 1024
@@ -1218,6 +1171,34 @@ static int sgtl5000_set_power_regs(struct snd_soc_codec *codec)
1218 return 0; 1171 return 0;
1219} 1172}
1220 1173
1174static int sgtl5000_replace_vddd_with_ldo(struct snd_soc_codec *codec)
1175{
1176 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
1177 int ret;
1178
1179 /* set internal ldo to 1.2v */
1180 ret = ldo_regulator_register(codec, &ldo_init_data, LDO_VOLTAGE);
1181 if (ret) {
1182 dev_err(codec->dev,
1183 "Failed to register vddd internal supplies: %d\n", ret);
1184 return ret;
1185 }
1186
1187 sgtl5000->supplies[VDDD].supply = LDO_CONSUMER_NAME;
1188
1189 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(sgtl5000->supplies),
1190 sgtl5000->supplies);
1191
1192 if (ret) {
1193 ldo_regulator_remove(codec);
1194 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
1195 return ret;
1196 }
1197
1198 dev_info(codec->dev, "Using internal LDO instead of VDDD\n");
1199 return 0;
1200}
1201
1221static int sgtl5000_enable_regulators(struct snd_soc_codec *codec) 1202static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
1222{ 1203{
1223 u16 reg; 1204 u16 reg;
@@ -1235,30 +1216,9 @@ static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
1235 if (!ret) 1216 if (!ret)
1236 external_vddd = 1; 1217 external_vddd = 1;
1237 else { 1218 else {
1238 /* set internal ldo to 1.2v */ 1219 ret = sgtl5000_replace_vddd_with_ldo(codec);
1239 int voltage = LDO_VOLTAGE; 1220 if (ret)
1240
1241 ret = ldo_regulator_register(codec, &ldo_init_data, voltage);
1242 if (ret) {
1243 dev_err(codec->dev,
1244 "Failed to register vddd internal supplies: %d\n",
1245 ret);
1246 return ret;
1247 }
1248
1249 sgtl5000->supplies[VDDD].supply = LDO_CONSUMER_NAME;
1250
1251 ret = regulator_bulk_get(codec->dev,
1252 ARRAY_SIZE(sgtl5000->supplies),
1253 sgtl5000->supplies);
1254
1255 if (ret) {
1256 ldo_regulator_remove(codec);
1257 dev_err(codec->dev,
1258 "Failed to request supplies: %d\n", ret);
1259
1260 return ret; 1221 return ret;
1261 }
1262 } 1222 }
1263 1223
1264 ret = regulator_bulk_enable(ARRAY_SIZE(sgtl5000->supplies), 1224 ret = regulator_bulk_enable(ARRAY_SIZE(sgtl5000->supplies),
@@ -1287,7 +1247,6 @@ static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
1287 * roll back to use internal LDO 1247 * roll back to use internal LDO
1288 */ 1248 */
1289 if (external_vddd && rev >= 0x11) { 1249 if (external_vddd && rev >= 0x11) {
1290 int voltage = LDO_VOLTAGE;
1291 /* disable all regulator first */ 1250 /* disable all regulator first */
1292 regulator_bulk_disable(ARRAY_SIZE(sgtl5000->supplies), 1251 regulator_bulk_disable(ARRAY_SIZE(sgtl5000->supplies),
1293 sgtl5000->supplies); 1252 sgtl5000->supplies);
@@ -1295,23 +1254,10 @@ static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
1295 regulator_bulk_free(ARRAY_SIZE(sgtl5000->supplies), 1254 regulator_bulk_free(ARRAY_SIZE(sgtl5000->supplies),
1296 sgtl5000->supplies); 1255 sgtl5000->supplies);
1297 1256
1298 ret = ldo_regulator_register(codec, &ldo_init_data, voltage); 1257 ret = sgtl5000_replace_vddd_with_ldo(codec);
1299 if (ret) 1258 if (ret)
1300 return ret; 1259 return ret;
1301 1260
1302 sgtl5000->supplies[VDDD].supply = LDO_CONSUMER_NAME;
1303
1304 ret = regulator_bulk_get(codec->dev,
1305 ARRAY_SIZE(sgtl5000->supplies),
1306 sgtl5000->supplies);
1307 if (ret) {
1308 ldo_regulator_remove(codec);
1309 dev_err(codec->dev,
1310 "Failed to request supplies: %d\n", ret);
1311
1312 return ret;
1313 }
1314
1315 ret = regulator_bulk_enable(ARRAY_SIZE(sgtl5000->supplies), 1261 ret = regulator_bulk_enable(ARRAY_SIZE(sgtl5000->supplies),
1316 sgtl5000->supplies); 1262 sgtl5000->supplies);
1317 if (ret) 1263 if (ret)
@@ -1460,16 +1406,6 @@ static __devinit int sgtl5000_i2c_probe(struct i2c_client *client,
1460 if (!sgtl5000) 1406 if (!sgtl5000)
1461 return -ENOMEM; 1407 return -ENOMEM;
1462 1408
1463 /*
1464 * copy DAP default values to default value array.
1465 * sgtl5000 register space has a big hole, merge it
1466 * at init phase makes life easy.
1467 * FIXME: should we drop 'const' of sgtl5000_regs?
1468 */
1469 memcpy((void *)(&sgtl5000_regs[0] + (SGTL5000_DAP_REG_OFFSET >> 1)),
1470 sgtl5000_dap_regs,
1471 SGTL5000_MAX_REG_OFFSET - SGTL5000_DAP_REG_OFFSET);
1472
1473 i2c_set_clientdata(client, sgtl5000); 1409 i2c_set_clientdata(client, sgtl5000);
1474 1410
1475 ret = snd_soc_register_codec(&client->dev, 1411 ret = snd_soc_register_codec(&client->dev,