Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: codecs: Add aw88083 amplifier driver

The driver is for amplifiers aw88083 of Awinic Technology
Corporation. The AW88083 is an intelligent digital audio
amplifier with low noise.

Signed-off-by: Weidong Wang <wangweidong.a@awinic.com>
Link: https://patch.msgid.link/20241231125610.465614-3-wangweidong.a@awinic.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Weidong Wang and committed by
Mark Brown
be947cc0 e7b73981

+321 -57
+1 -1
sound/soc/codecs/Kconfig
··· 692 692 the input amplitude. 693 693 694 694 config SND_SOC_AW88081 695 - tristate "Soc Audio for awinic aw88081" 695 + tristate "Soc Audio for awinic aw88081/aw88083" 696 696 depends on I2C 697 697 select REGMAP_I2C 698 698 select SND_SOC_AW88395_LIB
+277 -56
sound/soc/codecs/aw88081.c
··· 14 14 #include "aw88081.h" 15 15 #include "aw88395/aw88395_device.h" 16 16 17 + enum aw8808x_type { 18 + AW88081, 19 + AW88083, 20 + }; 21 + 17 22 struct aw88081 { 18 23 struct aw_device *aw_pa; 19 24 struct mutex lock; 20 25 struct delayed_work start_work; 21 26 struct regmap *regmap; 22 27 struct aw_container *aw_cfg; 23 - 28 + enum aw8808x_type devtype; 24 29 bool phase_sync; 25 30 }; 26 31 ··· 33 28 .val_bits = 16, 34 29 .reg_bits = 8, 35 30 .max_register = AW88081_REG_MAX, 31 + .reg_format_endian = REGMAP_ENDIAN_LITTLE, 32 + .val_format_endian = REGMAP_ENDIAN_BIG, 33 + }; 34 + 35 + static const struct regmap_config aw88083_regmap_config = { 36 + .val_bits = 16, 37 + .reg_bits = 8, 38 + .max_register = AW88083_REG_MAX, 36 39 .reg_format_endian = REGMAP_ENDIAN_LITTLE, 37 40 .val_format_endian = REGMAP_ENDIAN_BIG, 38 41 }; ··· 209 196 ~AW88081_EN_PA_MASK, AW88081_EN_PA_WORKING_VALUE); 210 197 } 211 198 199 + static void aw88083_i2c_wen(struct aw88081 *aw88081, bool flag) 200 + { 201 + struct aw_device *aw_dev = aw88081->aw_pa; 202 + 203 + if (aw88081->devtype != AW88083) 204 + return; 205 + 206 + if (flag) 207 + regmap_update_bits(aw_dev->regmap, AW88081_SYSCTRL_REG, 208 + ~AW88083_I2C_WEN_MASK, AW88083_I2C_WEN_ENABLE_VALUE); 209 + else 210 + regmap_update_bits(aw_dev->regmap, AW88081_SYSCTRL_REG, 211 + ~AW88083_I2C_WEN_MASK, AW88083_I2C_WEN_DISABLE_VALUE); 212 + } 213 + 214 + static void aw88083_dev_amppd(struct aw_device *aw_dev, bool amppd) 215 + { 216 + if (amppd) 217 + regmap_update_bits(aw_dev->regmap, AW88081_SYSCTRL_REG, 218 + ~AW88083_AMPPD_MASK, AW88083_AMPPD_POWER_DOWN_VALUE); 219 + else 220 + regmap_update_bits(aw_dev->regmap, AW88081_SYSCTRL_REG, 221 + ~AW88083_AMPPD_MASK, AW88083_AMPPD_WORKING_VALUE); 222 + } 223 + 224 + static void aw88083_dev_pllpd(struct aw_device *aw_dev, bool pllpd) 225 + { 226 + if (pllpd) 227 + regmap_update_bits(aw_dev->regmap, AW88081_SYSCTRL_REG, 228 + ~AW88083_PLL_PD_MASK, AW88083_PLL_PD_WORKING_VALUE); 229 + else 230 + regmap_update_bits(aw_dev->regmap, AW88081_SYSCTRL_REG, 231 + ~AW88083_PLL_PD_MASK, AW88083_PLL_PD_POWER_DOWN_VALUE); 232 + } 233 + 212 234 static void aw88081_dev_clear_int_status(struct aw_device *aw_dev) 213 235 { 214 236 unsigned int int_status; ··· 332 284 AW88081_ULS_HMUTE_DISABLE_VALUE); 333 285 } 334 286 287 + static int aw88081_dev_reg_value_check(struct aw_device *aw_dev, 288 + unsigned char reg_addr, unsigned short *reg_val) 289 + { 290 + unsigned int read_vol; 291 + 292 + if (reg_addr == AW88081_SYSCTRL_REG) { 293 + *reg_val &= ~(~AW88081_EN_PA_MASK | 294 + ~AW88081_PWDN_MASK | 295 + ~AW88081_HMUTE_MASK | 296 + ~AW88081_ULS_HMUTE_MASK); 297 + 298 + *reg_val |= AW88081_EN_PA_POWER_DOWN_VALUE | 299 + AW88081_PWDN_POWER_DOWN_VALUE | 300 + AW88081_HMUTE_ENABLE_VALUE | 301 + AW88081_ULS_HMUTE_ENABLE_VALUE; 302 + } 303 + 304 + if (reg_addr == AW88081_SYSCTRL2_REG) { 305 + read_vol = (*reg_val & (~AW88081_VOL_MASK)) >> AW88081_VOL_START_BIT; 306 + aw_dev->volume_desc.init_volume = read_vol; 307 + } 308 + 309 + /* i2stxen */ 310 + if (reg_addr == AW88081_I2SCTRL3_REG) { 311 + /* close tx */ 312 + *reg_val &= AW88081_I2STXEN_MASK; 313 + *reg_val |= AW88081_I2STXEN_DISABLE_VALUE; 314 + } 315 + 316 + return 0; 317 + } 318 + 319 + static int aw88083_dev_reg_value_check(struct aw_device *aw_dev, 320 + unsigned char reg_addr, unsigned short *reg_val) 321 + { 322 + unsigned int read_vol; 323 + 324 + if (reg_addr == AW88081_SYSCTRL_REG) { 325 + *reg_val &= ~(~AW88083_AMPPD_MASK | 326 + ~AW88081_PWDN_MASK | 327 + ~AW88081_HMUTE_MASK | 328 + ~AW88083_I2C_WEN_MASK); 329 + 330 + *reg_val |= AW88083_AMPPD_POWER_DOWN_VALUE | 331 + AW88081_PWDN_POWER_DOWN_VALUE | 332 + AW88081_HMUTE_ENABLE_VALUE | 333 + AW88083_I2C_WEN_ENABLE_VALUE; 334 + } 335 + 336 + if (reg_addr == AW88081_SYSCTRL2_REG) { 337 + read_vol = (*reg_val & (~AW88081_VOL_MASK)) >> AW88081_VOL_START_BIT; 338 + aw_dev->volume_desc.init_volume = read_vol; 339 + } 340 + 341 + return 0; 342 + } 343 + 344 + static int aw88081_reg_value_check(struct aw88081 *aw88081, 345 + unsigned char reg_addr, unsigned short *reg_val) 346 + { 347 + struct aw_device *aw_dev = aw88081->aw_pa; 348 + int ret; 349 + 350 + switch (aw88081->devtype) { 351 + case AW88081: 352 + ret = aw88081_dev_reg_value_check(aw_dev, reg_addr, reg_val); 353 + break; 354 + case AW88083: 355 + ret = aw88083_dev_reg_value_check(aw_dev, reg_addr, reg_val); 356 + break; 357 + default: 358 + dev_err(aw_dev->dev, "unsupported device\n"); 359 + ret = -EINVAL; 360 + break; 361 + } 362 + 363 + return ret; 364 + } 365 + 335 366 static int aw88081_dev_reg_update(struct aw88081 *aw88081, 336 367 unsigned char *data, unsigned int len) 337 368 { 338 369 struct aw_device *aw_dev = aw88081->aw_pa; 339 370 struct aw_volume_desc *vol_desc = &aw_dev->volume_desc; 340 - unsigned int read_vol; 341 371 int data_len, i, ret; 342 372 int16_t *reg_data; 343 373 u16 reg_val; ··· 438 312 reg_addr = reg_data[i]; 439 313 reg_val = reg_data[i + 1]; 440 314 441 - if (reg_addr == AW88081_SYSCTRL_REG) { 442 - reg_val &= ~(~AW88081_EN_PA_MASK | 443 - ~AW88081_PWDN_MASK | 444 - ~AW88081_HMUTE_MASK | 445 - ~AW88081_ULS_HMUTE_MASK); 446 - 447 - reg_val |= AW88081_EN_PA_POWER_DOWN_VALUE | 448 - AW88081_PWDN_POWER_DOWN_VALUE | 449 - AW88081_HMUTE_ENABLE_VALUE | 450 - AW88081_ULS_HMUTE_ENABLE_VALUE; 451 - } 452 - 453 - if (reg_addr == AW88081_SYSCTRL2_REG) { 454 - read_vol = (reg_val & (~AW88081_VOL_MASK)) >> 455 - AW88081_VOL_START_BIT; 456 - aw_dev->volume_desc.init_volume = read_vol; 457 - } 458 - 459 - /* i2stxen */ 460 - if (reg_addr == AW88081_I2SCTRL3_REG) { 461 - /* close tx */ 462 - reg_val &= AW88081_I2STXEN_MASK; 463 - reg_val |= AW88081_I2STXEN_DISABLE_VALUE; 464 - } 315 + ret = aw88081_reg_value_check(aw88081, reg_addr, &reg_val); 316 + if (ret) 317 + return ret; 465 318 466 319 ret = regmap_write(aw_dev->regmap, reg_addr, reg_val); 467 320 if (ret) ··· 579 474 return ret; 580 475 } 581 476 582 - static int aw88081_dev_stop(struct aw_device *aw_dev) 477 + static int aw88083_dev_start(struct aw88081 *aw88081) 583 478 { 479 + struct aw_device *aw_dev = aw88081->aw_pa; 480 + 481 + if (aw_dev->status == AW88081_DEV_PW_ON) { 482 + dev_dbg(aw_dev->dev, "already power on"); 483 + return 0; 484 + } 485 + 486 + aw88083_i2c_wen(aw88081, true); 487 + 488 + /* power on */ 489 + aw88081_dev_pwd(aw_dev, false); 490 + usleep_range(AW88081_2000_US, AW88081_2000_US + 10); 491 + 492 + aw88083_dev_pllpd(aw_dev, true); 493 + /* amppd on */ 494 + aw88083_dev_amppd(aw_dev, false); 495 + usleep_range(AW88081_2000_US, AW88081_2000_US + 50); 496 + 497 + /* close mute */ 498 + aw88081_dev_mute(aw_dev, false); 499 + 500 + aw88083_i2c_wen(aw88081, false); 501 + 502 + aw_dev->status = AW88081_DEV_PW_ON; 503 + 504 + return 0; 505 + } 506 + 507 + static int aw88081_device_start(struct aw88081 *aw88081) 508 + { 509 + int ret; 510 + 511 + switch (aw88081->devtype) { 512 + case AW88081: 513 + ret = aw88081_dev_start(aw88081); 514 + break; 515 + case AW88083: 516 + ret = aw88083_dev_start(aw88081); 517 + break; 518 + default: 519 + ret = -EINVAL; 520 + dev_err(aw88081->aw_pa->dev, "unsupported device\n"); 521 + break; 522 + } 523 + 524 + return ret; 525 + } 526 + 527 + static int aw88081_dev_stop(struct aw88081 *aw88081) 528 + { 529 + struct aw_device *aw_dev = aw88081->aw_pa; 530 + 584 531 if (aw_dev->status == AW88081_DEV_PW_OFF) { 585 532 dev_dbg(aw_dev->dev, "already power off"); 586 533 return 0; ··· 658 501 aw88081_dev_pwd(aw_dev, true); 659 502 660 503 return 0; 504 + } 505 + 506 + static int aw88083_dev_stop(struct aw88081 *aw88081) 507 + { 508 + struct aw_device *aw_dev = aw88081->aw_pa; 509 + 510 + if (aw_dev->status == AW88081_DEV_PW_OFF) { 511 + dev_dbg(aw_dev->dev, "already power off"); 512 + return 0; 513 + } 514 + 515 + aw_dev->status = AW88081_DEV_PW_OFF; 516 + 517 + aw88083_i2c_wen(aw88081, true); 518 + /* set mute */ 519 + aw88081_dev_mute(aw_dev, true); 520 + 521 + usleep_range(AW88081_2000_US, AW88081_2000_US + 100); 522 + 523 + /* enable amppd */ 524 + aw88083_dev_amppd(aw_dev, true); 525 + 526 + aw88083_dev_pllpd(aw_dev, false); 527 + 528 + /* set power down */ 529 + aw88081_dev_pwd(aw_dev, true); 530 + 531 + aw88083_i2c_wen(aw88081, false); 532 + 533 + return 0; 534 + } 535 + 536 + static int aw88081_stop(struct aw88081 *aw88081) 537 + { 538 + int ret; 539 + 540 + switch (aw88081->devtype) { 541 + case AW88081: 542 + ret = aw88081_dev_stop(aw88081); 543 + break; 544 + case AW88083: 545 + ret = aw88083_dev_stop(aw88081); 546 + break; 547 + default: 548 + dev_err(aw88081->aw_pa->dev, "unsupported device\n"); 549 + ret = -EINVAL; 550 + break; 551 + } 552 + 553 + return ret; 661 554 } 662 555 663 556 static int aw88081_reg_update(struct aw88081 *aw88081, bool force) ··· 747 540 dev_err(aw88081->aw_pa->dev, "fw update failed, cnt:%d\n", i); 748 541 continue; 749 542 } 750 - ret = aw88081_dev_start(aw88081); 543 + ret = aw88081_device_start(aw88081); 751 544 if (ret) { 752 545 dev_err(aw88081->aw_pa->dev, "aw88081 device start failed. retry = %d", i); 753 546 continue; ··· 952 745 } 953 746 954 747 if (aw88081->aw_pa->status) { 955 - aw88081_dev_stop(aw88081->aw_pa); 748 + aw88081_stop(aw88081); 956 749 aw88081_start(aw88081, AW88081_SYNC_START); 957 750 } 958 751 ··· 988 781 if (value < mc->min || value > mc->max) 989 782 return -EINVAL; 990 783 784 + aw88083_i2c_wen(aw88081, true); 785 + 991 786 if (vol_desc->ctl_volume != value) { 992 787 vol_desc->ctl_volume = value; 993 788 aw88081_dev_set_volume(aw88081->aw_pa, vol_desc->ctl_volume); 994 789 return 1; 995 790 } 791 + 792 + aw88083_i2c_wen(aw88081, false); 996 793 997 794 return 0; 998 795 } ··· 1071 860 dev_err(&i2c->dev, "%s read chipid error. ret = %d", __func__, ret); 1072 861 return ret; 1073 862 } 1074 - if (chip_id != AW88081_CHIP_ID) { 863 + 864 + switch (chip_id) { 865 + case AW88081_CHIP_ID: 866 + dev_dbg(&i2c->dev, "chip id = 0x%x\n", chip_id); 867 + break; 868 + case AW88083_CHIP_ID: 869 + dev_dbg(&i2c->dev, "chip id = 0x%x\n", chip_id); 870 + break; 871 + default: 1075 872 dev_err(&i2c->dev, "unsupported device"); 1076 873 return -ENXIO; 1077 874 } 1078 - 1079 - dev_dbg(&i2c->dev, "chip id = %x\n", chip_id); 1080 875 1081 876 aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); 1082 877 if (!aw_dev) ··· 1092 875 aw_dev->i2c = i2c; 1093 876 aw_dev->regmap = regmap; 1094 877 aw_dev->dev = &i2c->dev; 1095 - aw_dev->chip_id = AW88081_CHIP_ID; 878 + aw_dev->chip_id = chip_id; 1096 879 aw_dev->acf = NULL; 1097 880 aw_dev->prof_info.prof_desc = NULL; 1098 881 aw_dev->prof_info.prof_type = AW88395_DEV_NONE_TYPE_ID; ··· 1129 912 return ret; 1130 913 } 1131 914 1132 - aw88081_dev_clear_int_status(aw_dev); 1133 - 1134 - aw88081_dev_uls_hmute(aw_dev, true); 1135 - 1136 - aw88081_dev_mute(aw_dev, true); 1137 - 1138 - usleep_range(AW88081_5000_US, AW88081_5000_US + 10); 1139 - 1140 - aw88081_dev_i2s_tx_enable(aw_dev, false); 1141 - 1142 - usleep_range(AW88081_1000_US, AW88081_1000_US + 100); 1143 - 1144 - aw88081_dev_amppd(aw_dev, true); 1145 - 1146 - aw88081_dev_pwd(aw_dev, true); 915 + aw_dev->status = AW88081_DEV_PW_ON; 916 + aw88081_stop(aw88081); 1147 917 1148 918 return 0; 1149 919 } ··· 1181 977 aw88081_start(aw88081, AW88081_ASYNC_START); 1182 978 break; 1183 979 case SND_SOC_DAPM_POST_PMD: 1184 - aw88081_dev_stop(aw88081->aw_pa); 980 + aw88081_stop(aw88081); 1185 981 break; 1186 982 default: 1187 983 break; ··· 1240 1036 .num_controls = ARRAY_SIZE(aw88081_controls), 1241 1037 }; 1242 1038 1039 + static const struct i2c_device_id aw88081_i2c_id[] = { 1040 + { AW88081_I2C_NAME, AW88081}, 1041 + { AW88083_I2C_NAME, AW88083}, 1042 + { } 1043 + }; 1044 + MODULE_DEVICE_TABLE(i2c, aw88081_i2c_id); 1045 + 1243 1046 static int aw88081_i2c_probe(struct i2c_client *i2c) 1244 1047 { 1048 + const struct regmap_config *regmap_config; 1049 + const struct i2c_device_id *id; 1245 1050 struct aw88081 *aw88081; 1246 1051 int ret; 1247 1052 ··· 1262 1049 if (!aw88081) 1263 1050 return -ENOMEM; 1264 1051 1052 + id = i2c_match_id(aw88081_i2c_id, i2c); 1053 + aw88081->devtype = id->driver_data; 1054 + 1265 1055 mutex_init(&aw88081->lock); 1266 1056 1267 1057 i2c_set_clientdata(i2c, aw88081); 1268 1058 1269 - aw88081->regmap = devm_regmap_init_i2c(i2c, &aw88081_regmap_config); 1059 + switch (aw88081->devtype) { 1060 + case AW88081: 1061 + regmap_config = &aw88081_regmap_config; 1062 + break; 1063 + case AW88083: 1064 + regmap_config = &aw88083_regmap_config; 1065 + break; 1066 + default: 1067 + return -EINVAL; 1068 + } 1069 + 1070 + aw88081->regmap = devm_regmap_init_i2c(i2c, regmap_config); 1270 1071 if (IS_ERR(aw88081->regmap)) 1271 1072 return dev_err_probe(&i2c->dev, PTR_ERR(aw88081->regmap), 1272 1073 "failed to init regmap\n"); ··· 1294 1067 &soc_codec_dev_aw88081, 1295 1068 aw88081_dai, ARRAY_SIZE(aw88081_dai)); 1296 1069 } 1297 - 1298 - static const struct i2c_device_id aw88081_i2c_id[] = { 1299 - { AW88081_I2C_NAME }, 1300 - { } 1301 - }; 1302 - MODULE_DEVICE_TABLE(i2c, aw88081_i2c_id); 1303 1070 1304 1071 static struct i2c_driver aw88081_i2c_driver = { 1305 1072 .driver = {
+43
sound/soc/codecs/aw88081.h
··· 231 231 #define AW88081_CCO_MUX_BYPASS_VALUE \ 232 232 (AW88081_CCO_MUX_BYPASS << AW88081_CCO_MUX_START_BIT) 233 233 234 + #define AW88083_I2C_WEN_START_BIT (14) 235 + #define AW88083_I2C_WEN_BITS_LEN (2) 236 + #define AW88083_I2C_WEN_MASK \ 237 + (~(((1<<AW88083_I2C_WEN_BITS_LEN)-1) << AW88083_I2C_WEN_START_BIT)) 238 + 239 + #define AW88083_I2C_WEN_DISABLE (0) 240 + #define AW88083_I2C_WEN_DISABLE_VALUE \ 241 + (AW88083_I2C_WEN_DISABLE << AW88083_I2C_WEN_START_BIT) 242 + 243 + #define AW88083_I2C_WEN_ENABLE (2) 244 + #define AW88083_I2C_WEN_ENABLE_VALUE \ 245 + (AW88083_I2C_WEN_ENABLE << AW88083_I2C_WEN_START_BIT) 246 + 247 + #define AW88083_PLL_PD_START_BIT (2) 248 + #define AW88083_PLL_PD_BITS_LEN (1) 249 + #define AW88083_PLL_PD_MASK \ 250 + (~(((1<<AW88083_PLL_PD_BITS_LEN)-1) << AW88083_PLL_PD_START_BIT)) 251 + 252 + #define AW88083_PLL_PD_POWER_DOWN (1) 253 + #define AW88083_PLL_PD_POWER_DOWN_VALUE \ 254 + (AW88083_PLL_PD_POWER_DOWN << AW88083_PLL_PD_START_BIT) 255 + 256 + #define AW88083_PLL_PD_WORKING (0) 257 + #define AW88083_PLL_PD_WORKING_VALUE \ 258 + (AW88083_PLL_PD_WORKING << AW88083_PLL_PD_START_BIT) 259 + 260 + #define AW88083_AMPPD_START_BIT (1) 261 + #define AW88083_AMPPD_BITS_LEN (1) 262 + #define AW88083_AMPPD_MASK \ 263 + (~(((1<<AW88083_AMPPD_BITS_LEN)-1) << AW88083_AMPPD_START_BIT)) 264 + 265 + #define AW88083_AMPPD_WORKING (0) 266 + #define AW88083_AMPPD_WORKING_VALUE \ 267 + (AW88083_AMPPD_WORKING << AW88083_AMPPD_START_BIT) 268 + 269 + #define AW88083_AMPPD_POWER_DOWN (1) 270 + #define AW88083_AMPPD_POWER_DOWN_VALUE \ 271 + (AW88083_AMPPD_POWER_DOWN << AW88083_AMPPD_START_BIT) 272 + 273 + #define AW88083_REG_MAX (0x7D) 274 + #define AW88083_I2C_NAME "aw88083" 275 + #define AW88083_CHIP_ID 0x2407 276 + 234 277 #define AW88081_START_RETRIES (5) 235 278 #define AW88081_START_WORK_DELAY_MS (0) 236 279