sound/hda/codecs/side-codecs/tas2781_hda.c

Source file repositories/reference/linux-study-clean/sound/hda/codecs/side-codecs/tas2781_hda.c

File Facts

System
Linux kernel
Corpus path
sound/hda/codecs/side-codecs/tas2781_hda.c
Extension
.c
Size
11944 bytes
Lines
422
Domain
Driver Families
Bucket
sound/hda
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (crc != tmp_val[3 + tmp_val[1] * 6]) {
			cali_data->total_sz = 0;
			dev_err(p->dev, "%s: CRC error\n", __func__);
			return;
		}
		node_num = tmp_val[1];

		for (j = 0, k = 0; j < node_num; j++) {
			oft = j * 6 + 3;
			if (tmp_val[oft] == TASDEV_UEFI_CALI_REG_ADDR_FLG) {
				for (i = 0; i < TASDEV_CALIB_N; i++) {
					buf = &data[(oft + i + 1) * 4];
					cali_reg[i] = TASDEVICE_REG(buf[1],
						buf[2], buf[3]);
				}
			} else {
				l = j * (cali_data->cali_dat_sz_per_dev + 1);
				if (k >= p->ndev || l > oft * 4) {
					dev_err(p->dev, "%s: dev sum error\n",
						__func__);
					cali_data->total_sz = 0;
					return;
				}

				data[l] = k;
				oft++;
				cali_cnv(data, 4 * oft, l);
				k++;
			}
		}
	} else {
		/*
		 * Calibration data is in V1 format.
		 * struct cali_data {
		 *     char cali_data[20];
		 * }
		 *
		 * struct {
		 *     struct cali_data cali_data[4];
		 *     int  TimeStamp of Calibration (4 bytes)
		 *     int CRC (4 bytes)
		 * } ueft;
		 */
		crc = crc32(~0, data, 84) ^ ~0;
		if (crc != tmp_val[21]) {
			cali_data->total_sz = 0;
			dev_err(p->dev, "%s: V1 CRC error\n", __func__);
			return;
		}

		for (j = p->ndev - 1; j >= 0; j--) {
			l = j * (cali_data->cali_dat_sz_per_dev + 1);
			cali_cnv(data, cali_data->cali_dat_sz_per_dev * j, l);
			data[l] = j;
		}
	}

	if (p->dspbin_typ == TASDEV_BASIC) {
		r->r0_reg = cali_reg[0];
		r->invr0_reg = cali_reg[1];
		r->r0_low_reg = cali_reg[2];
		r->pow_reg = cali_reg[3];
		r->tlimit_reg = cali_reg[4];
	}

	cali_data->total_sz = p->ndev * (cali_data->cali_dat_sz_per_dev + 1);
}

/*
 * Update the calibration data, including speaker impedance, f0, etc,
 * into algo. Calibrate data is done by manufacturer in the factory.
 * The data is used by Algo for calculating the speaker temperature,
 * speaker membrane excursion and f0 in real time during playback.
 * Calibration data format in EFI is V2, since 2024.
 */
int tas2781_save_calibration(struct tas2781_hda *hda)
{
	/*
	 * GUID was used for data access in BIOS, it was provided by board
	 * manufactory.
	 */
	efi_guid_t efi_guid = tasdev_fct_efi_guid[LENOVO];
	/*
	 * Some devices save the calibrated data into L"CALI_DATA",
	 * and others into L"SmartAmpCalibrationData".
	 */
	static efi_char16_t *efi_name[CALIBRATION_DATA_AREA_NUM] = {
		L"CALI_DATA",
		L"SmartAmpCalibrationData",
	};

Annotation

Implementation Notes