xref: /linux/sound/hda/intel-nhlt.c (revision b82779648dfd3814df4e381f086326ec70fd791f)
1e149ca29SPierre-Louis Bossart // SPDX-License-Identifier: GPL-2.0-only
2303681f4SPierre-Louis Bossart // Copyright (c) 2015-2019 Intel Corporation
3303681f4SPierre-Louis Bossart 
4303681f4SPierre-Louis Bossart #include <linux/acpi.h>
5303681f4SPierre-Louis Bossart #include <sound/intel-nhlt.h>
6303681f4SPierre-Louis Bossart 
intel_nhlt_init(struct device * dev)7303681f4SPierre-Louis Bossart struct nhlt_acpi_table *intel_nhlt_init(struct device *dev)
8303681f4SPierre-Louis Bossart {
90d283287SCezary Rojewski 	struct nhlt_acpi_table *nhlt;
100d283287SCezary Rojewski 	acpi_status status;
11303681f4SPierre-Louis Bossart 
120d283287SCezary Rojewski 	status = acpi_get_table(ACPI_SIG_NHLT, 0,
130d283287SCezary Rojewski 				(struct acpi_table_header **)&nhlt);
140d283287SCezary Rojewski 	if (ACPI_FAILURE(status)) {
150d283287SCezary Rojewski 		dev_warn(dev, "NHLT table not found\n");
16303681f4SPierre-Louis Bossart 		return NULL;
17303681f4SPierre-Louis Bossart 	}
18303681f4SPierre-Louis Bossart 
190d283287SCezary Rojewski 	return nhlt;
20303681f4SPierre-Louis Bossart }
21303681f4SPierre-Louis Bossart EXPORT_SYMBOL_GPL(intel_nhlt_init);
22303681f4SPierre-Louis Bossart 
intel_nhlt_free(struct nhlt_acpi_table * nhlt)23303681f4SPierre-Louis Bossart void intel_nhlt_free(struct nhlt_acpi_table *nhlt)
24303681f4SPierre-Louis Bossart {
250d283287SCezary Rojewski 	acpi_put_table((struct acpi_table_header *)nhlt);
26303681f4SPierre-Louis Bossart }
27303681f4SPierre-Louis Bossart EXPORT_SYMBOL_GPL(intel_nhlt_free);
28303681f4SPierre-Louis Bossart 
intel_nhlt_get_dmic_geo(struct device * dev,struct nhlt_acpi_table * nhlt)29303681f4SPierre-Louis Bossart int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
30303681f4SPierre-Louis Bossart {
31303681f4SPierre-Louis Bossart 	struct nhlt_endpoint *epnt;
32303681f4SPierre-Louis Bossart 	struct nhlt_dmic_array_config *cfg;
337a33ea70SPierre-Louis Bossart 	struct nhlt_vendor_dmic_array_config *cfg_vendor;
34a864e8f1SPierre-Louis Bossart 	struct nhlt_fmt *fmt_configs;
35303681f4SPierre-Louis Bossart 	unsigned int dmic_geo = 0;
36a864e8f1SPierre-Louis Bossart 	u16 max_ch = 0;
37a864e8f1SPierre-Louis Bossart 	u8 i, j;
38303681f4SPierre-Louis Bossart 
39303681f4SPierre-Louis Bossart 	if (!nhlt)
40303681f4SPierre-Louis Bossart 		return 0;
41303681f4SPierre-Louis Bossart 
42a14a6219SMark Pearson 	if (nhlt->header.length <= sizeof(struct acpi_table_header)) {
43a14a6219SMark Pearson 		dev_warn(dev, "Invalid DMIC description table\n");
44a14a6219SMark Pearson 		return 0;
45a14a6219SMark Pearson 	}
46a14a6219SMark Pearson 
47a864e8f1SPierre-Louis Bossart 	for (j = 0, epnt = nhlt->desc; j < nhlt->endpoint_count; j++,
48a864e8f1SPierre-Louis Bossart 	     epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length)) {
49303681f4SPierre-Louis Bossart 
50a864e8f1SPierre-Louis Bossart 		if (epnt->linktype != NHLT_LINK_DMIC)
51a864e8f1SPierre-Louis Bossart 			continue;
52a864e8f1SPierre-Louis Bossart 
53a864e8f1SPierre-Louis Bossart 		cfg = (struct nhlt_dmic_array_config  *)(epnt->config.caps);
54a864e8f1SPierre-Louis Bossart 		fmt_configs = (struct nhlt_fmt *)(epnt->config.caps + epnt->config.size);
55a864e8f1SPierre-Louis Bossart 
56a864e8f1SPierre-Louis Bossart 		/* find max number of channels based on format_configuration */
57a864e8f1SPierre-Louis Bossart 		if (fmt_configs->fmt_count) {
582e6481a3SPeter Ujfalusi 			struct nhlt_fmt_cfg *fmt_cfg = fmt_configs->fmt_config;
592e6481a3SPeter Ujfalusi 
606376ab02SPierre-Louis Bossart 			dev_dbg(dev, "found %d format definitions\n",
616376ab02SPierre-Louis Bossart 				fmt_configs->fmt_count);
62a864e8f1SPierre-Louis Bossart 
63a864e8f1SPierre-Louis Bossart 			for (i = 0; i < fmt_configs->fmt_count; i++) {
64a864e8f1SPierre-Louis Bossart 				struct wav_fmt_ext *fmt_ext;
65a864e8f1SPierre-Louis Bossart 
662e6481a3SPeter Ujfalusi 				fmt_ext = &fmt_cfg->fmt_ext;
67a864e8f1SPierre-Louis Bossart 
68a864e8f1SPierre-Louis Bossart 				if (fmt_ext->fmt.channels > max_ch)
69a864e8f1SPierre-Louis Bossart 					max_ch = fmt_ext->fmt.channels;
702e6481a3SPeter Ujfalusi 
712e6481a3SPeter Ujfalusi 				/* Move to the next nhlt_fmt_cfg */
722e6481a3SPeter Ujfalusi 				fmt_cfg = (struct nhlt_fmt_cfg *)(fmt_cfg->config.caps +
732e6481a3SPeter Ujfalusi 								  fmt_cfg->config.size);
74a864e8f1SPierre-Louis Bossart 			}
756376ab02SPierre-Louis Bossart 			dev_dbg(dev, "max channels found %d\n", max_ch);
76a864e8f1SPierre-Louis Bossart 		} else {
776376ab02SPierre-Louis Bossart 			dev_dbg(dev, "No format information found\n");
78a864e8f1SPierre-Louis Bossart 		}
79a864e8f1SPierre-Louis Bossart 
80a864e8f1SPierre-Louis Bossart 		if (cfg->device_config.config_type != NHLT_CONFIG_TYPE_MIC_ARRAY) {
81a864e8f1SPierre-Louis Bossart 			dmic_geo = max_ch;
82a864e8f1SPierre-Louis Bossart 		} else {
83303681f4SPierre-Louis Bossart 			switch (cfg->array_type) {
84303681f4SPierre-Louis Bossart 			case NHLT_MIC_ARRAY_2CH_SMALL:
85303681f4SPierre-Louis Bossart 			case NHLT_MIC_ARRAY_2CH_BIG:
86303681f4SPierre-Louis Bossart 				dmic_geo = MIC_ARRAY_2CH;
87303681f4SPierre-Louis Bossart 				break;
88303681f4SPierre-Louis Bossart 
89303681f4SPierre-Louis Bossart 			case NHLT_MIC_ARRAY_4CH_1ST_GEOM:
90303681f4SPierre-Louis Bossart 			case NHLT_MIC_ARRAY_4CH_L_SHAPED:
91303681f4SPierre-Louis Bossart 			case NHLT_MIC_ARRAY_4CH_2ND_GEOM:
92303681f4SPierre-Louis Bossart 				dmic_geo = MIC_ARRAY_4CH;
93303681f4SPierre-Louis Bossart 				break;
947a33ea70SPierre-Louis Bossart 			case NHLT_MIC_ARRAY_VENDOR_DEFINED:
957a33ea70SPierre-Louis Bossart 				cfg_vendor = (struct nhlt_vendor_dmic_array_config *)cfg;
967a33ea70SPierre-Louis Bossart 				dmic_geo = cfg_vendor->nb_mics;
977a33ea70SPierre-Louis Bossart 				break;
98303681f4SPierre-Louis Bossart 			default:
99a864e8f1SPierre-Louis Bossart 				dev_warn(dev, "%s: undefined DMIC array_type 0x%0x\n",
100a864e8f1SPierre-Louis Bossart 					 __func__, cfg->array_type);
101a864e8f1SPierre-Louis Bossart 			}
102a864e8f1SPierre-Louis Bossart 
103a864e8f1SPierre-Louis Bossart 			if (dmic_geo > 0) {
1046376ab02SPierre-Louis Bossart 				dev_dbg(dev, "Array with %d dmics\n", dmic_geo);
105a864e8f1SPierre-Louis Bossart 			}
106a864e8f1SPierre-Louis Bossart 			if (max_ch > dmic_geo) {
1076376ab02SPierre-Louis Bossart 				dev_dbg(dev, "max channels %d exceed dmic number %d\n",
1086376ab02SPierre-Louis Bossart 					max_ch, dmic_geo);
109303681f4SPierre-Louis Bossart 			}
110303681f4SPierre-Louis Bossart 		}
111303681f4SPierre-Louis Bossart 	}
112303681f4SPierre-Louis Bossart 
1136376ab02SPierre-Louis Bossart 	dev_dbg(dev, "dmic number %d max_ch %d\n", dmic_geo, max_ch);
114a864e8f1SPierre-Louis Bossart 
115303681f4SPierre-Louis Bossart 	return dmic_geo;
116303681f4SPierre-Louis Bossart }
117303681f4SPierre-Louis Bossart EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo);
11815fa179fSAmadeusz Sławiński 
intel_nhlt_has_endpoint_type(struct nhlt_acpi_table * nhlt,u8 link_type)11915fa179fSAmadeusz Sławiński bool intel_nhlt_has_endpoint_type(struct nhlt_acpi_table *nhlt, u8 link_type)
12015fa179fSAmadeusz Sławiński {
12115fa179fSAmadeusz Sławiński 	struct nhlt_endpoint *epnt;
12215fa179fSAmadeusz Sławiński 	int i;
12315fa179fSAmadeusz Sławiński 
12415fa179fSAmadeusz Sławiński 	if (!nhlt)
12515fa179fSAmadeusz Sławiński 		return false;
12615fa179fSAmadeusz Sławiński 
12715fa179fSAmadeusz Sławiński 	epnt = (struct nhlt_endpoint *)nhlt->desc;
12815fa179fSAmadeusz Sławiński 	for (i = 0; i < nhlt->endpoint_count; i++) {
12915fa179fSAmadeusz Sławiński 		if (epnt->linktype == link_type)
13015fa179fSAmadeusz Sławiński 			return true;
13115fa179fSAmadeusz Sławiński 
13215fa179fSAmadeusz Sławiński 		epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
13315fa179fSAmadeusz Sławiński 	}
13415fa179fSAmadeusz Sławiński 	return false;
13515fa179fSAmadeusz Sławiński }
13615fa179fSAmadeusz Sławiński EXPORT_SYMBOL(intel_nhlt_has_endpoint_type);
13715fa179fSAmadeusz Sławiński 
intel_nhlt_ssp_endpoint_mask(struct nhlt_acpi_table * nhlt,u8 device_type)1380c470db0SPierre-Louis Bossart int intel_nhlt_ssp_endpoint_mask(struct nhlt_acpi_table *nhlt, u8 device_type)
1390c470db0SPierre-Louis Bossart {
1400c470db0SPierre-Louis Bossart 	struct nhlt_endpoint *epnt;
1410c470db0SPierre-Louis Bossart 	int ssp_mask = 0;
1420c470db0SPierre-Louis Bossart 	int i;
1430c470db0SPierre-Louis Bossart 
1440c470db0SPierre-Louis Bossart 	if (!nhlt || (device_type != NHLT_DEVICE_BT && device_type != NHLT_DEVICE_I2S))
1450c470db0SPierre-Louis Bossart 		return 0;
1460c470db0SPierre-Louis Bossart 
1470c470db0SPierre-Louis Bossart 	epnt = (struct nhlt_endpoint *)nhlt->desc;
1480c470db0SPierre-Louis Bossart 	for (i = 0; i < nhlt->endpoint_count; i++) {
1490c470db0SPierre-Louis Bossart 		if (epnt->linktype == NHLT_LINK_SSP && epnt->device_type == device_type) {
1500c470db0SPierre-Louis Bossart 			/* for SSP the virtual bus id is the SSP port */
1510c470db0SPierre-Louis Bossart 			ssp_mask |= BIT(epnt->virtual_bus_id);
1520c470db0SPierre-Louis Bossart 		}
1530c470db0SPierre-Louis Bossart 		epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
1540c470db0SPierre-Louis Bossart 	}
1550c470db0SPierre-Louis Bossart 
1560c470db0SPierre-Louis Bossart 	return ssp_mask;
1570c470db0SPierre-Louis Bossart }
1580c470db0SPierre-Louis Bossart EXPORT_SYMBOL(intel_nhlt_ssp_endpoint_mask);
1590c470db0SPierre-Louis Bossart 
16072176fccSPierre-Louis Bossart #define SSP_BLOB_V1_0_SIZE		84
16172176fccSPierre-Louis Bossart #define SSP_BLOB_V1_0_MDIVC_OFFSET	19 /* offset in u32 */
16272176fccSPierre-Louis Bossart 
16372176fccSPierre-Louis Bossart #define SSP_BLOB_V1_5_SIZE		96
16472176fccSPierre-Louis Bossart #define SSP_BLOB_V1_5_MDIVC_OFFSET	21 /* offset in u32 */
16572176fccSPierre-Louis Bossart #define SSP_BLOB_VER_1_5		0xEE000105
16672176fccSPierre-Louis Bossart 
16772176fccSPierre-Louis Bossart #define SSP_BLOB_V2_0_SIZE		88
16872176fccSPierre-Louis Bossart #define SSP_BLOB_V2_0_MDIVC_OFFSET	20 /* offset in u32 */
16972176fccSPierre-Louis Bossart #define SSP_BLOB_VER_2_0		0xEE000200
17072176fccSPierre-Louis Bossart 
intel_nhlt_ssp_mclk_mask(struct nhlt_acpi_table * nhlt,int ssp_num)17172176fccSPierre-Louis Bossart int intel_nhlt_ssp_mclk_mask(struct nhlt_acpi_table *nhlt, int ssp_num)
17272176fccSPierre-Louis Bossart {
17372176fccSPierre-Louis Bossart 	struct nhlt_endpoint *epnt;
17472176fccSPierre-Louis Bossart 	struct nhlt_fmt *fmt;
17572176fccSPierre-Louis Bossart 	struct nhlt_fmt_cfg *cfg;
17672176fccSPierre-Louis Bossart 	int mclk_mask = 0;
17772176fccSPierre-Louis Bossart 	int i, j;
17872176fccSPierre-Louis Bossart 
17972176fccSPierre-Louis Bossart 	if (!nhlt)
18072176fccSPierre-Louis Bossart 		return 0;
18172176fccSPierre-Louis Bossart 
18272176fccSPierre-Louis Bossart 	epnt = (struct nhlt_endpoint *)nhlt->desc;
18372176fccSPierre-Louis Bossart 	for (i = 0; i < nhlt->endpoint_count; i++) {
18472176fccSPierre-Louis Bossart 
18572176fccSPierre-Louis Bossart 		/* we only care about endpoints connected to an audio codec over SSP */
18672176fccSPierre-Louis Bossart 		if (epnt->linktype == NHLT_LINK_SSP &&
18772176fccSPierre-Louis Bossart 		    epnt->device_type == NHLT_DEVICE_I2S &&
18872176fccSPierre-Louis Bossart 		    epnt->virtual_bus_id == ssp_num) {
18972176fccSPierre-Louis Bossart 
19072176fccSPierre-Louis Bossart 			fmt = (struct nhlt_fmt *)(epnt->config.caps + epnt->config.size);
19172176fccSPierre-Louis Bossart 			cfg = fmt->fmt_config;
19272176fccSPierre-Louis Bossart 
19372176fccSPierre-Louis Bossart 			/*
19472176fccSPierre-Louis Bossart 			 * In theory all formats should use the same MCLK but it doesn't hurt to
19572176fccSPierre-Louis Bossart 			 * double-check that the configuration is consistent
19672176fccSPierre-Louis Bossart 			 */
19772176fccSPierre-Louis Bossart 			for (j = 0; j < fmt->fmt_count; j++) {
19872176fccSPierre-Louis Bossart 				u32 *blob;
19972176fccSPierre-Louis Bossart 				int mdivc_offset;
20072176fccSPierre-Louis Bossart 				int size;
20172176fccSPierre-Louis Bossart 
20272176fccSPierre-Louis Bossart 				/* first check we have enough data to read the blob type */
20372176fccSPierre-Louis Bossart 				if (cfg->config.size < 8)
20472176fccSPierre-Louis Bossart 					return -EINVAL;
20572176fccSPierre-Louis Bossart 
20672176fccSPierre-Louis Bossart 				blob = (u32 *)cfg->config.caps;
20772176fccSPierre-Louis Bossart 
20872176fccSPierre-Louis Bossart 				if (blob[1] == SSP_BLOB_VER_2_0) {
20972176fccSPierre-Louis Bossart 					mdivc_offset = SSP_BLOB_V2_0_MDIVC_OFFSET;
21072176fccSPierre-Louis Bossart 					size = SSP_BLOB_V2_0_SIZE;
21172176fccSPierre-Louis Bossart 				} else if (blob[1] == SSP_BLOB_VER_1_5) {
21272176fccSPierre-Louis Bossart 					mdivc_offset = SSP_BLOB_V1_5_MDIVC_OFFSET;
21372176fccSPierre-Louis Bossart 					size = SSP_BLOB_V1_5_SIZE;
21472176fccSPierre-Louis Bossart 				} else {
21572176fccSPierre-Louis Bossart 					mdivc_offset = SSP_BLOB_V1_0_MDIVC_OFFSET;
21672176fccSPierre-Louis Bossart 					size = SSP_BLOB_V1_0_SIZE;
21772176fccSPierre-Louis Bossart 				}
21872176fccSPierre-Louis Bossart 
21972176fccSPierre-Louis Bossart 				/* make sure we have enough data for the fixed part of the blob */
22072176fccSPierre-Louis Bossart 				if (cfg->config.size < size)
22172176fccSPierre-Louis Bossart 					return -EINVAL;
22272176fccSPierre-Louis Bossart 
22372176fccSPierre-Louis Bossart 				mclk_mask |=  blob[mdivc_offset] & GENMASK(1, 0);
22472176fccSPierre-Louis Bossart 
22572176fccSPierre-Louis Bossart 				cfg = (struct nhlt_fmt_cfg *)(cfg->config.caps + cfg->config.size);
22672176fccSPierre-Louis Bossart 			}
22772176fccSPierre-Louis Bossart 		}
22872176fccSPierre-Louis Bossart 		epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
22972176fccSPierre-Louis Bossart 	}
23072176fccSPierre-Louis Bossart 
23172176fccSPierre-Louis Bossart 	/* make sure only one MCLK is used */
23272176fccSPierre-Louis Bossart 	if (hweight_long(mclk_mask) != 1)
23372176fccSPierre-Louis Bossart 		return -EINVAL;
23472176fccSPierre-Louis Bossart 
23572176fccSPierre-Louis Bossart 	return mclk_mask;
23672176fccSPierre-Louis Bossart }
23772176fccSPierre-Louis Bossart EXPORT_SYMBOL(intel_nhlt_ssp_mclk_mask);
23872176fccSPierre-Louis Bossart 
23915fa179fSAmadeusz Sławiński static struct nhlt_specific_cfg *
nhlt_get_specific_cfg(struct device * dev,struct nhlt_fmt * fmt,u8 num_ch,u32 rate,u8 vbps,u8 bps,bool ignore_vbps)24015fa179fSAmadeusz Sławiński nhlt_get_specific_cfg(struct device *dev, struct nhlt_fmt *fmt, u8 num_ch,
2417b4c93a5SPeter Ujfalusi 		      u32 rate, u8 vbps, u8 bps, bool ignore_vbps)
24215fa179fSAmadeusz Sławiński {
24315fa179fSAmadeusz Sławiński 	struct nhlt_fmt_cfg *cfg = fmt->fmt_config;
24415fa179fSAmadeusz Sławiński 	struct wav_fmt *wfmt;
24515fa179fSAmadeusz Sławiński 	u16 _bps, _vbps;
24615fa179fSAmadeusz Sławiński 	int i;
24715fa179fSAmadeusz Sławiński 
24815fa179fSAmadeusz Sławiński 	dev_dbg(dev, "Endpoint format count=%d\n", fmt->fmt_count);
24915fa179fSAmadeusz Sławiński 
25015fa179fSAmadeusz Sławiński 	for (i = 0; i < fmt->fmt_count; i++) {
25115fa179fSAmadeusz Sławiński 		wfmt = &cfg->fmt_ext.fmt;
25215fa179fSAmadeusz Sławiński 		_bps = wfmt->bits_per_sample;
25315fa179fSAmadeusz Sławiński 		_vbps = cfg->fmt_ext.sample.valid_bits_per_sample;
25415fa179fSAmadeusz Sławiński 
25515fa179fSAmadeusz Sławiński 		dev_dbg(dev, "Endpoint format: ch=%d fmt=%d/%d rate=%d\n",
25615fa179fSAmadeusz Sławiński 			wfmt->channels, _vbps, _bps, wfmt->samples_per_sec);
25715fa179fSAmadeusz Sławiński 
2587b4c93a5SPeter Ujfalusi 		/*
2597b4c93a5SPeter Ujfalusi 		 * When looking for exact match of configuration ignore the vbps
2607b4c93a5SPeter Ujfalusi 		 * from NHLT table when ignore_vbps is true
2617b4c93a5SPeter Ujfalusi 		 */
26215fa179fSAmadeusz Sławiński 		if (wfmt->channels == num_ch && wfmt->samples_per_sec == rate &&
2637b4c93a5SPeter Ujfalusi 		    (ignore_vbps || vbps == _vbps) && bps == _bps)
26415fa179fSAmadeusz Sławiński 			return &cfg->config;
26515fa179fSAmadeusz Sławiński 
26615fa179fSAmadeusz Sławiński 		cfg = (struct nhlt_fmt_cfg *)(cfg->config.caps + cfg->config.size);
26715fa179fSAmadeusz Sławiński 	}
26815fa179fSAmadeusz Sławiński 
26915fa179fSAmadeusz Sławiński 	return NULL;
27015fa179fSAmadeusz Sławiński }
27115fa179fSAmadeusz Sławiński 
nhlt_check_ep_match(struct device * dev,struct nhlt_endpoint * epnt,u32 bus_id,u8 link_type,u8 dir,u8 dev_type)27215fa179fSAmadeusz Sławiński static bool nhlt_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
27315fa179fSAmadeusz Sławiński 				u32 bus_id, u8 link_type, u8 dir, u8 dev_type)
27415fa179fSAmadeusz Sławiński {
27515fa179fSAmadeusz Sławiński 	dev_dbg(dev, "Endpoint: vbus_id=%d link_type=%d dir=%d dev_type = %d\n",
27615fa179fSAmadeusz Sławiński 		epnt->virtual_bus_id, epnt->linktype,
27715fa179fSAmadeusz Sławiński 		epnt->direction, epnt->device_type);
27815fa179fSAmadeusz Sławiński 
27915fa179fSAmadeusz Sławiński 	if ((epnt->virtual_bus_id != bus_id) ||
28015fa179fSAmadeusz Sławiński 	    (epnt->linktype != link_type) ||
28115fa179fSAmadeusz Sławiński 	    (epnt->direction != dir))
28215fa179fSAmadeusz Sławiński 		return false;
28315fa179fSAmadeusz Sławiński 
28415fa179fSAmadeusz Sławiński 	/* link of type DMIC bypasses device_type check */
28515fa179fSAmadeusz Sławiński 	return epnt->linktype == NHLT_LINK_DMIC ||
28615fa179fSAmadeusz Sławiński 	       epnt->device_type == dev_type;
28715fa179fSAmadeusz Sławiński }
28815fa179fSAmadeusz Sławiński 
28915fa179fSAmadeusz Sławiński struct nhlt_specific_cfg *
intel_nhlt_get_endpoint_blob(struct device * dev,struct nhlt_acpi_table * nhlt,u32 bus_id,u8 link_type,u8 vbps,u8 bps,u8 num_ch,u32 rate,u8 dir,u8 dev_type)29015fa179fSAmadeusz Sławiński intel_nhlt_get_endpoint_blob(struct device *dev, struct nhlt_acpi_table *nhlt,
29115fa179fSAmadeusz Sławiński 			     u32 bus_id, u8 link_type, u8 vbps, u8 bps,
29215fa179fSAmadeusz Sławiński 			     u8 num_ch, u32 rate, u8 dir, u8 dev_type)
29315fa179fSAmadeusz Sławiński {
29415fa179fSAmadeusz Sławiński 	struct nhlt_specific_cfg *cfg;
29515fa179fSAmadeusz Sławiński 	struct nhlt_endpoint *epnt;
2967b4c93a5SPeter Ujfalusi 	bool ignore_vbps = false;
29715fa179fSAmadeusz Sławiński 	struct nhlt_fmt *fmt;
29815fa179fSAmadeusz Sławiński 	int i;
29915fa179fSAmadeusz Sławiński 
30015fa179fSAmadeusz Sławiński 	if (!nhlt)
30115fa179fSAmadeusz Sławiński 		return NULL;
30215fa179fSAmadeusz Sławiński 
30315fa179fSAmadeusz Sławiński 	dev_dbg(dev, "Looking for configuration:\n");
30415fa179fSAmadeusz Sławiński 	dev_dbg(dev, "  vbus_id=%d link_type=%d dir=%d, dev_type=%d\n",
30515fa179fSAmadeusz Sławiński 		bus_id, link_type, dir, dev_type);
3067b4c93a5SPeter Ujfalusi 	if (link_type == NHLT_LINK_DMIC && bps == 32 && (vbps == 24 || vbps == 32)) {
3077b4c93a5SPeter Ujfalusi 		/*
3087b4c93a5SPeter Ujfalusi 		 * The DMIC hardware supports only one type of 32 bits sample
3097b4c93a5SPeter Ujfalusi 		 * size, which is 24 bit sampling on the MSB side and bits[1:0]
3107b4c93a5SPeter Ujfalusi 		 * are used for indicating the channel number.
3117b4c93a5SPeter Ujfalusi 		 * It has been observed that some NHLT tables have the vbps
3127b4c93a5SPeter Ujfalusi 		 * specified as 32 while some uses 24.
3137b4c93a5SPeter Ujfalusi 		 * The format these variations describe are identical, the
3147b4c93a5SPeter Ujfalusi 		 * hardware is configured and behaves the same way.
3157b4c93a5SPeter Ujfalusi 		 * Note: when the samples assumed to be vbps=32 then the 'noise'
3167b4c93a5SPeter Ujfalusi 		 * introduced by the lower two bits (channel number) have no
3177b4c93a5SPeter Ujfalusi 		 * real life implication on audio quality.
3187b4c93a5SPeter Ujfalusi 		 */
3197b4c93a5SPeter Ujfalusi 		dev_dbg(dev,
3207b4c93a5SPeter Ujfalusi 			"  ch=%d fmt=%d rate=%d (vbps is ignored for DMIC 32bit format)\n",
3217b4c93a5SPeter Ujfalusi 			num_ch, bps, rate);
3227b4c93a5SPeter Ujfalusi 		ignore_vbps = true;
3237b4c93a5SPeter Ujfalusi 	} else {
32415fa179fSAmadeusz Sławiński 		dev_dbg(dev, "  ch=%d fmt=%d/%d rate=%d\n", num_ch, vbps, bps, rate);
3257b4c93a5SPeter Ujfalusi 	}
32615fa179fSAmadeusz Sławiński 	dev_dbg(dev, "Endpoint count=%d\n", nhlt->endpoint_count);
32715fa179fSAmadeusz Sławiński 
32815fa179fSAmadeusz Sławiński 	epnt = (struct nhlt_endpoint *)nhlt->desc;
32915fa179fSAmadeusz Sławiński 
33015fa179fSAmadeusz Sławiński 	for (i = 0; i < nhlt->endpoint_count; i++) {
33115fa179fSAmadeusz Sławiński 		if (nhlt_check_ep_match(dev, epnt, bus_id, link_type, dir, dev_type)) {
33215fa179fSAmadeusz Sławiński 			fmt = (struct nhlt_fmt *)(epnt->config.caps + epnt->config.size);
33315fa179fSAmadeusz Sławiński 
3347b4c93a5SPeter Ujfalusi 			cfg = nhlt_get_specific_cfg(dev, fmt, num_ch, rate,
3357b4c93a5SPeter Ujfalusi 						    vbps, bps, ignore_vbps);
33615fa179fSAmadeusz Sławiński 			if (cfg)
33715fa179fSAmadeusz Sławiński 				return cfg;
33815fa179fSAmadeusz Sławiński 		}
33915fa179fSAmadeusz Sławiński 
34015fa179fSAmadeusz Sławiński 		epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
34115fa179fSAmadeusz Sławiński 	}
34215fa179fSAmadeusz Sławiński 
34315fa179fSAmadeusz Sławiński 	return NULL;
34415fa179fSAmadeusz Sławiński }
34515fa179fSAmadeusz Sławiński EXPORT_SYMBOL(intel_nhlt_get_endpoint_blob);
346*02545bc5SBrent Lu 
intel_nhlt_ssp_device_type(struct device * dev,struct nhlt_acpi_table * nhlt,u8 virtual_bus_id)347*02545bc5SBrent Lu int intel_nhlt_ssp_device_type(struct device *dev, struct nhlt_acpi_table *nhlt,
348*02545bc5SBrent Lu 			       u8 virtual_bus_id)
349*02545bc5SBrent Lu {
350*02545bc5SBrent Lu 	struct nhlt_endpoint *epnt;
351*02545bc5SBrent Lu 	int i;
352*02545bc5SBrent Lu 
353*02545bc5SBrent Lu 	if (!nhlt)
354*02545bc5SBrent Lu 		return -EINVAL;
355*02545bc5SBrent Lu 
356*02545bc5SBrent Lu 	epnt = (struct nhlt_endpoint *)nhlt->desc;
357*02545bc5SBrent Lu 	for (i = 0; i < nhlt->endpoint_count; i++) {
358*02545bc5SBrent Lu 		/* for SSP link the virtual bus id is the SSP port number */
359*02545bc5SBrent Lu 		if (epnt->linktype == NHLT_LINK_SSP &&
360*02545bc5SBrent Lu 		    epnt->virtual_bus_id == virtual_bus_id) {
361*02545bc5SBrent Lu 			dev_dbg(dev, "SSP%d: dev_type=%d\n", virtual_bus_id,
362*02545bc5SBrent Lu 				epnt->device_type);
363*02545bc5SBrent Lu 			return epnt->device_type;
364*02545bc5SBrent Lu 		}
365*02545bc5SBrent Lu 
366*02545bc5SBrent Lu 		epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
367*02545bc5SBrent Lu 	}
368*02545bc5SBrent Lu 
369*02545bc5SBrent Lu 	return -EINVAL;
370*02545bc5SBrent Lu }
371*02545bc5SBrent Lu EXPORT_SYMBOL(intel_nhlt_ssp_device_type);
372