Skip to content

Commit e8e4fcc

Browse files
Lucas Tanurebroonie
authored andcommitted
ASoC: cs35l41: Create shared function for boost configuration
ASoC and HDA will use the same registers to configure internal boost for the device Signed-off-by: Lucas Tanure <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 3bc3e3d commit e8e4fcc

File tree

3 files changed

+102
-103
lines changed

3 files changed

+102
-103
lines changed

include/sound/cs35l41.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,5 +767,7 @@ int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsign
767767
int cs35l41_set_channels(struct device *dev, struct regmap *reg,
768768
unsigned int tx_num, unsigned int *tx_slot,
769769
unsigned int rx_num, unsigned int *rx_slot);
770+
int cs35l41_boost_config(struct device *dev, struct regmap *regmap, int boost_ind, int boost_cap,
771+
int boost_ipk);
770772

771773
#endif /* __CS35L41_H */

sound/soc/codecs/cs35l41-lib.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,104 @@ int cs35l41_set_channels(struct device *dev, struct regmap *reg,
966966
}
967967
EXPORT_SYMBOL_GPL(cs35l41_set_channels);
968968

969+
static const unsigned char cs35l41_bst_k1_table[4][5] = {
970+
{ 0x24, 0x32, 0x32, 0x4F, 0x57 },
971+
{ 0x24, 0x32, 0x32, 0x4F, 0x57 },
972+
{ 0x40, 0x32, 0x32, 0x4F, 0x57 },
973+
{ 0x40, 0x32, 0x32, 0x4F, 0x57 }
974+
};
975+
976+
static const unsigned char cs35l41_bst_k2_table[4][5] = {
977+
{ 0x24, 0x49, 0x66, 0xA3, 0xEA },
978+
{ 0x24, 0x49, 0x66, 0xA3, 0xEA },
979+
{ 0x48, 0x49, 0x66, 0xA3, 0xEA },
980+
{ 0x48, 0x49, 0x66, 0xA3, 0xEA }
981+
};
982+
983+
static const unsigned char cs35l41_bst_slope_table[4] = {
984+
0x75, 0x6B, 0x3B, 0x28
985+
};
986+
987+
988+
int cs35l41_boost_config(struct device *dev, struct regmap *regmap, int boost_ind, int boost_cap,
989+
int boost_ipk)
990+
{
991+
unsigned char bst_lbst_val, bst_cbst_range, bst_ipk_scaled;
992+
int ret;
993+
994+
switch (boost_ind) {
995+
case 1000: /* 1.0 uH */
996+
bst_lbst_val = 0;
997+
break;
998+
case 1200: /* 1.2 uH */
999+
bst_lbst_val = 1;
1000+
break;
1001+
case 1500: /* 1.5 uH */
1002+
bst_lbst_val = 2;
1003+
break;
1004+
case 2200: /* 2.2 uH */
1005+
bst_lbst_val = 3;
1006+
break;
1007+
default:
1008+
dev_err(dev, "Invalid boost inductor value: %d nH\n", boost_ind);
1009+
return -EINVAL;
1010+
}
1011+
1012+
switch (boost_cap) {
1013+
case 0 ... 19:
1014+
bst_cbst_range = 0;
1015+
break;
1016+
case 20 ... 50:
1017+
bst_cbst_range = 1;
1018+
break;
1019+
case 51 ... 100:
1020+
bst_cbst_range = 2;
1021+
break;
1022+
case 101 ... 200:
1023+
bst_cbst_range = 3;
1024+
break;
1025+
default: /* 201 uF and greater */
1026+
bst_cbst_range = 4;
1027+
}
1028+
1029+
ret = regmap_update_bits(regmap, CS35L41_BSTCVRT_COEFF,
1030+
CS35L41_BST_K1_MASK | CS35L41_BST_K2_MASK,
1031+
cs35l41_bst_k1_table[bst_lbst_val][bst_cbst_range]
1032+
<< CS35L41_BST_K1_SHIFT |
1033+
cs35l41_bst_k2_table[bst_lbst_val][bst_cbst_range]
1034+
<< CS35L41_BST_K2_SHIFT);
1035+
if (ret) {
1036+
dev_err(dev, "Failed to write boost coefficients: %d\n", ret);
1037+
return ret;
1038+
}
1039+
1040+
ret = regmap_update_bits(regmap, CS35L41_BSTCVRT_SLOPE_LBST,
1041+
CS35L41_BST_SLOPE_MASK | CS35L41_BST_LBST_VAL_MASK,
1042+
cs35l41_bst_slope_table[bst_lbst_val]
1043+
<< CS35L41_BST_SLOPE_SHIFT |
1044+
bst_lbst_val << CS35L41_BST_LBST_VAL_SHIFT);
1045+
if (ret) {
1046+
dev_err(dev, "Failed to write boost slope/inductor value: %d\n", ret);
1047+
return ret;
1048+
}
1049+
1050+
if (boost_ipk < 1600 || boost_ipk > 4500) {
1051+
dev_err(dev, "Invalid boost inductor peak current: %d mA\n", boost_ipk);
1052+
return -EINVAL;
1053+
}
1054+
bst_ipk_scaled = ((boost_ipk - 1600) / 50) + 0x10;
1055+
1056+
ret = regmap_update_bits(regmap, CS35L41_BSTCVRT_PEAK_CUR, CS35L41_BST_IPK_MASK,
1057+
bst_ipk_scaled << CS35L41_BST_IPK_SHIFT);
1058+
if (ret) {
1059+
dev_err(dev, "Failed to write boost inductor peak current: %d\n", ret);
1060+
return ret;
1061+
}
1062+
1063+
return 0;
1064+
}
1065+
EXPORT_SYMBOL_GPL(cs35l41_boost_config);
1066+
9691067
MODULE_DESCRIPTION("CS35L41 library");
9701068
MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <[email protected]>");
9711069
MODULE_AUTHOR("Lucas Tanure, Cirrus Logic Inc, <[email protected]>");

sound/soc/codecs/cs35l41.c

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,6 @@ static const struct cs35l41_fs_mon_config cs35l41_fs_mon[] = {
150150
{ 6144000, 16, 24 },
151151
};
152152

153-
static const unsigned char cs35l41_bst_k1_table[4][5] = {
154-
{ 0x24, 0x32, 0x32, 0x4F, 0x57 },
155-
{ 0x24, 0x32, 0x32, 0x4F, 0x57 },
156-
{ 0x40, 0x32, 0x32, 0x4F, 0x57 },
157-
{ 0x40, 0x32, 0x32, 0x4F, 0x57 }
158-
};
159-
160-
static const unsigned char cs35l41_bst_k2_table[4][5] = {
161-
{ 0x24, 0x49, 0x66, 0xA3, 0xEA },
162-
{ 0x24, 0x49, 0x66, 0xA3, 0xEA },
163-
{ 0x48, 0x49, 0x66, 0xA3, 0xEA },
164-
{ 0x48, 0x49, 0x66, 0xA3, 0xEA }
165-
};
166-
167-
static const unsigned char cs35l41_bst_slope_table[4] = {
168-
0x75, 0x6B, 0x3B, 0x28
169-
};
170-
171153
static int cs35l41_get_fs_mon_config_index(int freq)
172154
{
173155
int i;
@@ -992,88 +974,6 @@ static int cs35l41_dai_set_sysclk(struct snd_soc_dai *dai,
992974
return 0;
993975
}
994976

995-
static int cs35l41_boost_config(struct cs35l41_private *cs35l41,
996-
int boost_ind, int boost_cap, int boost_ipk)
997-
{
998-
unsigned char bst_lbst_val, bst_cbst_range, bst_ipk_scaled;
999-
struct regmap *regmap = cs35l41->regmap;
1000-
struct device *dev = cs35l41->dev;
1001-
int ret;
1002-
1003-
switch (boost_ind) {
1004-
case 1000: /* 1.0 uH */
1005-
bst_lbst_val = 0;
1006-
break;
1007-
case 1200: /* 1.2 uH */
1008-
bst_lbst_val = 1;
1009-
break;
1010-
case 1500: /* 1.5 uH */
1011-
bst_lbst_val = 2;
1012-
break;
1013-
case 2200: /* 2.2 uH */
1014-
bst_lbst_val = 3;
1015-
break;
1016-
default:
1017-
dev_err(dev, "Invalid boost inductor value: %d nH\n", boost_ind);
1018-
return -EINVAL;
1019-
}
1020-
1021-
switch (boost_cap) {
1022-
case 0 ... 19:
1023-
bst_cbst_range = 0;
1024-
break;
1025-
case 20 ... 50:
1026-
bst_cbst_range = 1;
1027-
break;
1028-
case 51 ... 100:
1029-
bst_cbst_range = 2;
1030-
break;
1031-
case 101 ... 200:
1032-
bst_cbst_range = 3;
1033-
break;
1034-
default: /* 201 uF and greater */
1035-
bst_cbst_range = 4;
1036-
}
1037-
1038-
ret = regmap_update_bits(regmap, CS35L41_BSTCVRT_COEFF,
1039-
CS35L41_BST_K1_MASK | CS35L41_BST_K2_MASK,
1040-
cs35l41_bst_k1_table[bst_lbst_val][bst_cbst_range]
1041-
<< CS35L41_BST_K1_SHIFT |
1042-
cs35l41_bst_k2_table[bst_lbst_val][bst_cbst_range]
1043-
<< CS35L41_BST_K2_SHIFT);
1044-
if (ret) {
1045-
dev_err(dev, "Failed to write boost coefficients: %d\n", ret);
1046-
return ret;
1047-
}
1048-
1049-
ret = regmap_update_bits(regmap, CS35L41_BSTCVRT_SLOPE_LBST,
1050-
CS35L41_BST_SLOPE_MASK | CS35L41_BST_LBST_VAL_MASK,
1051-
cs35l41_bst_slope_table[bst_lbst_val]
1052-
<< CS35L41_BST_SLOPE_SHIFT |
1053-
bst_lbst_val << CS35L41_BST_LBST_VAL_SHIFT);
1054-
if (ret) {
1055-
dev_err(dev, "Failed to write boost slope/inductor value: %d\n", ret);
1056-
return ret;
1057-
}
1058-
1059-
if (boost_ipk < 1600 || boost_ipk > 4500) {
1060-
dev_err(dev, "Invalid boost inductor peak current: %d mA\n",
1061-
boost_ipk);
1062-
return -EINVAL;
1063-
}
1064-
bst_ipk_scaled = ((boost_ipk - 1600) / 50) + 0x10;
1065-
1066-
ret = regmap_update_bits(regmap, CS35L41_BSTCVRT_PEAK_CUR,
1067-
CS35L41_BST_IPK_MASK,
1068-
bst_ipk_scaled << CS35L41_BST_IPK_SHIFT);
1069-
if (ret) {
1070-
dev_err(dev, "Failed to write boost inductor peak current: %d\n", ret);
1071-
return ret;
1072-
}
1073-
1074-
return 0;
1075-
}
1076-
1077977
static int cs35l41_set_pdata(struct cs35l41_private *cs35l41)
1078978
{
1079979
int ret;
@@ -1082,9 +982,8 @@ static int cs35l41_set_pdata(struct cs35l41_private *cs35l41)
1082982
/* Required */
1083983
if (cs35l41->pdata.bst_ipk &&
1084984
cs35l41->pdata.bst_ind && cs35l41->pdata.bst_cap) {
1085-
ret = cs35l41_boost_config(cs35l41, cs35l41->pdata.bst_ind,
1086-
cs35l41->pdata.bst_cap,
1087-
cs35l41->pdata.bst_ipk);
985+
ret = cs35l41_boost_config(cs35l41->dev, cs35l41->regmap, cs35l41->pdata.bst_ind,
986+
cs35l41->pdata.bst_cap, cs35l41->pdata.bst_ipk);
1088987
if (ret) {
1089988
dev_err(cs35l41->dev, "Error in Boost DT config: %d\n", ret);
1090989
return ret;

0 commit comments

Comments
 (0)