1 /* 2 * Copyright 2019 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef TFA98XXPARAMETERS_H_ 9 #define TFA98XXPARAMETERS_H_ 10 11 #ifdef __KERNEL__ 12 #include <linux/types.h> 13 #else 14 #include <stdint.h> 15 #endif 16 17 typedef struct tfa_msg 18 { 19 uint8_t msg_size; 20 unsigned char cmdId[3]; 21 int data[9]; 22 } tfa_msg_t; 23 24 //#if (defined(WIN32) || defined(_X64)) 25 ///* These warnings are disabled because it is only given by Windows and there is no easy fix */ 26 //#pragma warning(disable:4200) 27 //#pragma warning(disable:4214) 28 //#endif 29 30 /* 31 * profiles & volumesteps 32 * 33 */ 34 #define TFA_MAX_PROFILES (64) 35 #define TFA_MAX_MSGS (10) 36 37 // the pack pragma is required to make that the size in memory 38 // matches the actual variable lenghts 39 // This is to assure that the binary files can be transported between 40 // different platforms. 41 #pragma pack(push, 1) 42 43 /* 44 * typedef for 24 bit value using 3 bytes 45 */ 46 typedef struct uint24 47 { 48 uint8_t b[3]; 49 } uint24_t; 50 /* 51 * the generic header 52 * all char types are in ASCII 53 */ 54 typedef struct nxpTfaHeader 55 { 56 uint16_t id; 57 char version[2]; // "V_" : V=version, vv=subversion 58 char subversion[2]; // "vv" : vv=subversion 59 uint16_t size; // data size in bytes following CRC 60 uint32_t CRC; // 32-bits CRC for following data 61 char customer[8]; // “name of customer” 62 char application[8]; // “application name” 63 char type[8]; // “application type name” 64 } nxpTfaHeader_t; 65 66 typedef enum nxpTfaSamplerate 67 { 68 fs_8k, // 8kHz 69 fs_11k025, // 11.025kHz 70 fs_12k, // 12kHz 71 fs_16k, // 16kHz 72 fs_22k05, // 22.05kHz 73 fs_24k, // 24kHz 74 fs_32k, // 32kHz 75 fs_44k1, // 44.1kHz 76 fs_48k, // 48kHz 77 fs_96k, // 96kHz 78 fs_192k, // 192kHz 79 fs_count // Should always be last item. 80 } nxpTfaSamplerate_t; 81 82 // Keep in sync with nxpTfaSamplerate_t ! 83 static const int nxpTfaSamplerateHz[fs_count] = {8000, 11025, 12000, 16000, 22050, 24000, 84 32000, 44100, 48000, 96000, 192000}; 85 86 /* 87 * coolflux direct memory access 88 */ 89 typedef struct nxpTfaDspMem 90 { 91 uint8_t type; /* 0--3: p, x, y, iomem */ 92 uint16_t address; /* target address */ 93 uint8_t size; /* data size in words */ 94 int words[]; /* payload in signed 32bit integer (two's complement) */ 95 } nxpTfaDspMem_t; 96 97 /* 98 * the biquad coefficients for the API together with index in filter 99 * the biquad_index is the actual index in the equalizer +1 100 */ 101 #define BIQUAD_COEFF_SIZE 6 102 103 /* 104 * Output fixed point coeffs structure 105 */ 106 typedef struct 107 { 108 int a2; 109 int a1; 110 int b2; 111 int b1; 112 int b0; 113 } nxpTfaBiquad_t; 114 115 typedef struct nxpTfaBiquadOld 116 { 117 uint8_t bytes[BIQUAD_COEFF_SIZE * sizeof(uint24_t)]; 118 } nxpTfaBiquadOld_t; 119 120 typedef struct nxpTfaBiquadFloat 121 { 122 float headroom; 123 float b0; 124 float b1; 125 float b2; 126 float a1; 127 float a2; 128 } nxpTfaBiquadFloat_t; 129 130 /* 131 * EQ filter definitions 132 * Note: This is not in line with smartstudio (JV: 12/12/2016) 133 */ 134 typedef enum nxpTfaFilterType 135 { 136 fCustom, // User defined biquad coefficients 137 fFlat, // Vary only gain 138 fLowpass, // 2nd order Butterworth low pass 139 fHighpass, // 2nd order Butterworth high pass 140 fLowshelf, 141 fHighshelf, 142 fNotch, 143 fPeak, 144 fBandpass, 145 f1stLP, 146 f1stHP, 147 fElliptic 148 } nxpTfaFilterType_t; 149 150 /* 151 * filter parameters for biquad (re-)calculation 152 */ 153 typedef struct nxpTfaFilter 154 { 155 nxpTfaBiquadOld_t biquad; 156 uint8_t enabled; 157 uint8_t type; // (== enum FilterTypes, assure 8bits length) 158 float frequency; 159 float Q; 160 float gain; 161 } nxpTfaFilter_t; // 8 * float + int32 + byte == 37 162 163 /* 164 * biquad params for calculation 165 */ 166 167 #define TFA_BQ_EQ_INDEX 0 168 #define TFA_BQ_ANTI_ALIAS_INDEX 10 169 #define TFA_BQ_INTEGRATOR_INDEX 13 170 171 /* 172 * Loudspeaker Compensation filter definitions 173 */ 174 typedef struct nxpTfaLsCompensationFilter 175 { 176 nxpTfaBiquad_t biquad; 177 uint8_t lsCompOn; // Loudspeaker compensation on/off; when 'off', the DSP code doesn't apply the bwExt => bwExtOn 178 // GUI flag should be gray to avoid confusion 179 uint8_t bwExtOn; // Bandwidth extension on/off 180 float fRes; // [Hz] speaker resonance frequency 181 float Qt; // Speaker resonance Q-factor 182 float fBwExt; // [Hz] Band width extension frequency 183 float samplingFreq; // [Hz] Sampling frequency 184 } nxpTfaLsCompensationFilter_t; 185 186 /* 187 * Anti Aliasing Elliptic filter definitions 188 */ 189 typedef struct nxpTfaAntiAliasFilter 190 { 191 nxpTfaBiquad_t biquad; /**< Output results fixed point coeffs */ 192 uint8_t enabled; 193 float cutOffFreq; // cut off frequency 194 float samplingFreq; // sampling frequency 195 float rippleDb; // range: [0.1 3.0] 196 float rolloff; // range: [-1.0 1.0] 197 } nxpTfaAntiAliasFilter_t; 198 199 /** 200 * Integrator filter input definitions 201 */ 202 typedef struct nxpTfaIntegratorFilter 203 { 204 nxpTfaBiquad_t biquad; /**< Output results fixed point coeffs */ 205 uint8_t type; /**< Butterworth filter type: high or low pass */ 206 float cutOffFreq; /**< cut off frequency in Hertz; range: [100.0 4000.0] */ 207 float samplingFreq; /**< sampling frequency in Hertz */ 208 float leakage; /**< leakage factor; range [0.0 1.0] */ 209 } nxpTfaIntegratorFilter_t; 210 211 typedef struct nxpTfaEqFilter 212 { 213 nxpTfaBiquad_t biquad; 214 uint8_t enabled; 215 uint8_t type; // (== enum FilterTypes, assure 8bits length) 216 float cutOffFreq; // cut off frequency, // range: [100.0 4000.0] 217 float samplingFreq; // sampling frequency 218 float Q; // range: [0.5 5.0] 219 float gainDb; // range: [-10.0 10.0] 220 } nxpTfaEqFilter_t; // 8 * float + int32 + byte == 37 221 222 typedef struct nxpTfaContAntiAlias 223 { 224 int8_t index; /**< index determines destination type; anti-alias, integrator,eq */ 225 uint8_t type; 226 float cutOffFreq; // cut off frequency 227 float samplingFreq; 228 float rippleDb; // integrator leakage 229 float rolloff; 230 uint8_t bytes[5 * 3]; // payload 5*24buts coeffs 231 } nxpTfaContAntiAlias_t; 232 233 typedef struct nxpTfaContIntegrator 234 { 235 int8_t index; /**< index determines destination type; anti-alias, integrator,eq */ 236 uint8_t type; 237 float cutOffFreq; // cut off frequency 238 float samplingFreq; 239 float leakage; // integrator leakage 240 float reserved; 241 uint8_t bytes[5 * 3]; // payload 5*24buts coeffs 242 } nxpTfaContIntegrator_t; 243 244 typedef struct nxpTfaContEq 245 { 246 int8_t index; 247 uint8_t type; // (== enum FilterTypes, assure 8bits length) 248 float cutOffFreq; // cut off frequency, // range: [100.0 4000.0] 249 float samplingFreq; // sampling frequency 250 float Q; // range: [0.5 5.0] 251 float gainDb; // range: [-10.0 10.0] 252 uint8_t bytes[5 * 3]; // payload 5*24buts coeffs 253 } nxpTfaContEq_t; // 8 * float + int32 + byte == 37 254 255 typedef union nxpTfaContBiquad 256 { 257 nxpTfaContEq_t eq; 258 nxpTfaContAntiAlias_t aa; 259 nxpTfaContIntegrator_t in; 260 } nxpTfaContBiquad_t; 261 262 #define TFA_BQ_EQ_INDEX 0 263 #define TFA_BQ_ANTI_ALIAS_INDEX 10 264 #define TFA_BQ_INTEGRATOR_INDEX 13 265 #define TFA98XX_MAX_EQ 10 266 267 typedef struct nxpTfaEqualizer 268 { 269 nxpTfaFilter_t filter[TFA98XX_MAX_EQ]; 270 } nxpTfaEqualizer_t; 271 272 /* 273 * files 274 */ 275 #define HDR(c1, c2) (c2 << 8 | c1) // little endian 276 typedef enum nxpTfaHeaderType 277 { 278 paramsHdr = HDR('P', 'M'), /* container file */ 279 volstepHdr = HDR('V', 'P'), 280 patchHdr = HDR('P', 'A'), 281 speakerHdr = HDR('S', 'P'), 282 presetHdr = HDR('P', 'R'), 283 configHdr = HDR('C', 'O'), 284 equalizerHdr = HDR('E', 'Q'), 285 drcHdr = HDR('D', 'R'), 286 msgHdr = HDR('M', 'G'), /* generic message */ 287 infoHdr = HDR('I', 'N') 288 } nxpTfaHeaderType_t; 289 290 /* 291 * equalizer file 292 */ 293 #define NXPTFA_EQ_VERSION '1' 294 #define NXPTFA_EQ_SUBVERSION "00" 295 typedef struct nxpTfaEqualizerFile 296 { 297 nxpTfaHeader_t hdr; 298 uint8_t samplerate; // ==enum samplerates, assure 8 bits 299 nxpTfaFilter_t filter[TFA98XX_MAX_EQ]; // note: API index counts from 1..10 300 } nxpTfaEqualizerFile_t; 301 302 /* 303 * patch file 304 */ 305 #define NXPTFA_PA_VERSION '1' 306 #define NXPTFA_PA_SUBVERSION "00" 307 typedef struct nxpTfaPatchFile 308 { 309 nxpTfaHeader_t hdr; 310 uint8_t data[]; 311 } nxpTfaPatch_t; 312 313 /* 314 * generic message file 315 * - the payload of this file includes the opcode and is send straight to the DSP 316 */ 317 #define NXPTFA_MG_VERSION '3' 318 #define NXPTFA_MG_SUBVERSION "00" 319 typedef struct tfa_msg_file 320 { 321 nxpTfaHeader_t hdr; 322 uint8_t data[]; 323 } tfa_msg_file_t; 324 325 /* 326 * NOTE the tfa98xx API defines the enum tfa9xxx_config_type that defines 327 * the subtypes as decribes below. 328 * tfa98xx_dsp_config_parameter_type() can be used to get the 329 * supported type for the active device.. 330 */ 331 /* 332 * config file V1 sub 1 333 */ 334 #define NXPTFA_CO_VERSION '1' 335 #define NXPTFA_CO3_VERSION '3' 336 #define NXPTFA_CO_SUBVERSION1 "01" 337 typedef struct nxpTfaConfigS1File 338 { 339 nxpTfaHeader_t hdr; 340 uint8_t data[55 * 3]; 341 } nxpTfaConfigS1_t; 342 343 /* 344 * config file V1 sub 2 345 */ 346 #define NXPTFA_CO_SUBVERSION2 "02" 347 typedef struct nxpTfaConfigS2File 348 { 349 nxpTfaHeader_t hdr; 350 uint8_t data[67 * 3]; 351 } nxpTfaConfigS2_t; 352 353 /* 354 * config file V1 sub 3 355 */ 356 #define NXPTFA_CO_SUBVERSION3 "03" 357 typedef struct nxpTfaConfigS3File 358 { 359 nxpTfaHeader_t hdr; 360 uint8_t data[67 * 3]; 361 } nxpTfaConfigS3_t; 362 363 /* 364 * config file V1.0 365 */ 366 #define NXPTFA_CO_SUBVERSION "00" 367 typedef struct nxpTfaConfigFile 368 { 369 nxpTfaHeader_t hdr; 370 uint8_t data[]; 371 } nxpTfaConfig_t; 372 373 /* 374 * preset file 375 */ 376 #define NXPTFA_PR_VERSION '1' 377 #define NXPTFA_PR_SUBVERSION "00" 378 typedef struct nxpTfaPresetFile 379 { 380 nxpTfaHeader_t hdr; 381 uint8_t data[]; 382 } nxpTfaPreset_t; 383 384 /* 385 * drc file 386 */ 387 #define NXPTFA_DR_VERSION '1' 388 #define NXPTFA_DR_SUBVERSION "00" 389 typedef struct nxpTfaDrcFile 390 { 391 nxpTfaHeader_t hdr; 392 uint8_t data[]; 393 } nxpTfaDrc_t; 394 395 /* 396 * drc file 397 * for tfa 2 there is also a xml-version 398 */ 399 #define NXPTFA_DR3_VERSION '3' 400 #define NXPTFA_DR3_SUBVERSION "00" 401 typedef struct nxpTfaDrcFile2 402 { 403 nxpTfaHeader_t hdr; 404 uint8_t version[3]; 405 uint8_t data[]; 406 } nxpTfaDrc2_t; 407 408 /* 409 * speaker file header 410 */ 411 struct nxpTfaSpkHeader 412 { 413 struct nxpTfaHeader hdr; 414 char name[8]; // speaker nick name (e.g. “dumbo”) 415 char vendor[16]; 416 char type[8]; 417 // dimensions (mm) 418 uint8_t height; 419 uint8_t width; 420 uint8_t depth; 421 uint16_t ohm; 422 }; 423 424 /* 425 * speaker file 426 */ 427 #define NXPTFA_SP_VERSION '1' 428 #define NXPTFA_SP_SUBVERSION "00" 429 typedef struct nxpTfaSpeakerFile 430 { 431 nxpTfaHeader_t hdr; 432 char name[8]; // speaker nick name (e.g. “dumbo”) 433 char vendor[16]; 434 char type[8]; 435 // dimensions (mm) 436 uint8_t height; 437 uint8_t width; 438 uint8_t depth; 439 uint8_t ohm_primary; 440 uint8_t ohm_secondary; 441 uint8_t data[]; // payload TFA98XX_SPEAKERPARAMETER_LENGTH 442 } nxpTfaSpeakerFile_t; 443 444 struct nxpTfaFWVer 445 { 446 uint8_t Major; 447 uint8_t minor; 448 uint8_t minor_update : 6; 449 uint8_t Update : 2; 450 }; 451 452 struct nxpTfaFWMsg 453 { 454 struct nxpTfaFWVer fwVersion; 455 struct tfa_msg payload; 456 }; 457 458 typedef struct nxpTfaLiveData 459 { 460 char name[25]; 461 char addrs[25]; 462 int tracker; 463 int scalefactor; 464 } nxpTfaLiveData_t; 465 466 #define NXPTFA_SP3_VERSION '3' 467 #define NXPTFA_SP3_SUBVERSION "00" 468 struct nxpTfaSpeakerFileMax2 469 { 470 nxpTfaHeader_t hdr; 471 char name[8]; // speaker nick name (e.g. “dumbo”) 472 char vendor[16]; 473 char type[8]; 474 // dimensions (mm) 475 uint8_t height; 476 uint8_t width; 477 uint8_t depth; 478 uint8_t ohm_primary; 479 uint8_t ohm_secondary; 480 struct nxpTfaFWMsg FWmsg; // payload including FW ver and Cmd ID 481 }; 482 483 /* 484 * parameter container file 485 */ 486 /* 487 * descriptors 488 * Note 1: append new DescriptorType at the end 489 * Note 2: add new descriptors to dsc_name[] in tfaContUtil.c 490 */ 491 typedef enum nxpTfaDescriptorType 492 { 493 dscDevice, // device list 494 dscProfile, // profile list 495 dscRegister, // register patch 496 dscString, // ascii, zero terminated string 497 dscFile, // filename + file contents 498 dscPatch, // patch file 499 dscMarker, // marker to indicate end of a list 500 dscMode, 501 dscSetInputSelect, 502 dscSetOutputSelect, 503 dscSetProgramConfig, 504 dscSetLagW, 505 dscSetGains, 506 dscSetvBatFactors, 507 dscSetSensesCal, 508 dscSetSensesDelay, 509 dscBitfield, 510 dscDefault, // used to reset bitfields to there default values 511 dscLiveData, 512 dscLiveDataString, 513 dscGroup, 514 dscCmd, 515 dscSetMBDrc, 516 dscFilter, 517 dscNoInit, 518 dscFeatures, 519 dscCfMem, // coolflux memory x,y,io 520 dscSetFwkUseCase, 521 dscSetVddpConfig, 522 dscTfaHal, 523 dscInfoText, // info keyword for storing text into container 524 dscInfoFile, // info keyword for storing a file into container 525 dsc_last, // trailer 526 dsc_listend = -1 527 } nxpTfaDescriptorType_t; 528 529 #define TFA_BITFIELDDSCMSK 0x7fffffff 530 typedef struct nxpTfaDescPtr 531 { 532 uint32_t offset : 24; 533 uint32_t type : 8; // (== enum nxpTfaDescriptorType, assure 8bits length) 534 } nxpTfaDescPtr_t; 535 536 /* 537 * generic file descriptor 538 */ 539 typedef struct nxpTfaFileDsc 540 { 541 nxpTfaDescPtr_t name; 542 uint32_t size; // file data length in bytes 543 uint8_t data[]; // payload 544 } nxpTfaFileDsc_t; 545 546 /* 547 * device descriptor list 548 */ 549 typedef struct nxpTfaDeviceList 550 { 551 uint8_t length; // nr of items in the list 552 uint8_t bus; // bus 553 uint8_t dev; // device 554 uint8_t func; // subfunction or subdevice 555 uint32_t devid; // device hw fw id 556 nxpTfaDescPtr_t name; // device name 557 nxpTfaDescPtr_t list[]; // items list 558 } nxpTfaDeviceList_t; 559 560 /* 561 * profile descriptor list 562 */ 563 typedef struct nxpTfaProfileList 564 { 565 uint32_t length : 8; // nr of items in the list + name 566 uint32_t group : 8; // profile group number 567 uint32_t ID : 16; // profile ID 568 nxpTfaDescPtr_t name; // profile name 569 nxpTfaDescPtr_t list[]; // items list (lenght-1 items) 570 } nxpTfaProfileList_t; 571 #define TFA_PROFID 0x1234 572 573 /* 574 * livedata descriptor list 575 */ 576 typedef struct nxpTfaLiveDataList 577 { 578 uint32_t length : 8; // nr of items in the list 579 uint32_t ID : 24; // profile ID 580 nxpTfaDescPtr_t name; // livedata name 581 nxpTfaDescPtr_t list[]; // items list 582 } nxpTfaLiveDataList_t; 583 #define TFA_LIVEDATAID 0x5678 584 585 /* 586 * Bitfield descriptor 587 */ 588 typedef struct nxpTfaBitfield 589 { 590 uint16_t value; 591 uint16_t field; // ==datasheet defined, 16 bits 592 } nxpTfaBitfield_t; 593 594 /* 595 * Bitfield enumuration bits descriptor 596 */ 597 typedef struct nxpTfaBfEnum 598 { 599 unsigned int len : 4; // this is the actual length-1 600 unsigned int pos : 4; 601 unsigned int address : 8; 602 } nxpTfaBfEnum_t; 603 604 /* 605 * Register patch descriptor 606 */ 607 typedef struct nxpTfaRegpatch 608 { 609 uint8_t address; // register address 610 uint16_t value; // value to write 611 uint16_t mask; // mask of bits to write 612 } nxpTfaRegpatch_t; 613 614 /* 615 * Mode descriptor 616 */ 617 typedef struct nxpTfaUseCase 618 { 619 int value; // mode value, maps to enum tfa9xxx_Mode 620 } nxpTfaMode_t; 621 622 /* 623 * NoInit descriptor 624 */ 625 typedef struct nxpTfaNoInit 626 { 627 uint8_t value; // noInit value 628 } nxpTfaNoInit_t; 629 630 /* 631 * Features descriptor 632 */ 633 typedef struct nxpTfaFeatures 634 { 635 uint16_t value[3]; // features value 636 } nxpTfaFeatures_t; 637 638 /* 639 * the container file 640 * - the size field is 32bits long (generic=16) 641 * - all char types are in ASCII 642 */ 643 #define NXPTFA_PM_VERSION '1' 644 #define NXPTFA_PM3_VERSION '3' 645 #define NXPTFA_PM_SUBVERSION '1' 646 typedef struct nxpTfaContainer 647 { 648 char id[2]; // "XX" : XX=type 649 char version[2]; // "V_" : V=version, vv=subversion 650 char subversion[2]; // "vv" : vv=subversion 651 uint32_t size; // data size in bytes following CRC 652 uint32_t CRC; // 32-bits CRC for following data 653 uint16_t rev; // "extra chars for rev nr" 654 char customer[8]; // “name of customer” 655 char application[8]; // “application name” 656 char type[8]; // “application type name” 657 uint16_t ndev; // "nr of device lists" 658 uint16_t nprof; // "nr of profile lists" 659 uint16_t nliveData; // "nr of livedata lists" 660 nxpTfaDescPtr_t index[]; // start of item index table 661 } nxpTfaContainer_t; 662 663 #pragma pack(pop) 664 665 #endif /* TFA98XXPARAMETERS_H_ */ 666