mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	ALSA: hda: Code refactoring snd_hda_pick_fixup()
This contains a slight code refactoring of snd_hda_pick_fixup(): - Unify the ID setup - Unify the debug print message - Use snd_pci_quirk_lookup_id() for the codec SSID matching Mostly for simplifying the code flow but also it makes easier to add the codec alias handling in the upcoming patch. Link: https://lore.kernel.org/r/20210823073722.14873-2-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
		
							parent
							
								
									23c671be97
								
							
						
					
					
						commit
						73355ddd87
					
				
					 1 changed files with 39 additions and 38 deletions
				
			
		| 
						 | 
					@ -982,65 +982,66 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
 | 
				
			||||||
	const struct snd_pci_quirk *q;
 | 
						const struct snd_pci_quirk *q;
 | 
				
			||||||
	int id = HDA_FIXUP_ID_NOT_SET;
 | 
						int id = HDA_FIXUP_ID_NOT_SET;
 | 
				
			||||||
	const char *name = NULL;
 | 
						const char *name = NULL;
 | 
				
			||||||
 | 
						const char *type = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET)
 | 
						if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* when model=nofixup is given, don't pick up any fixups */
 | 
						/* when model=nofixup is given, don't pick up any fixups */
 | 
				
			||||||
	if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
 | 
						if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
 | 
				
			||||||
		codec->fixup_list = NULL;
 | 
							id = HDA_FIXUP_ID_NO_FIXUP;
 | 
				
			||||||
		codec->fixup_name = NULL;
 | 
							fixlist = NULL;
 | 
				
			||||||
		codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP;
 | 
					 | 
				
			||||||
		codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n",
 | 
							codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n",
 | 
				
			||||||
			  codec->core.chip_name);
 | 
								  codec->core.chip_name);
 | 
				
			||||||
		return;
 | 
							goto found;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* match with the model name string */
 | 
				
			||||||
	if (codec->modelname && models) {
 | 
						if (codec->modelname && models) {
 | 
				
			||||||
		while (models->name) {
 | 
							while (models->name) {
 | 
				
			||||||
			if (!strcmp(codec->modelname, models->name)) {
 | 
								if (!strcmp(codec->modelname, models->name)) {
 | 
				
			||||||
				codec->fixup_id = models->id;
 | 
									id = models->id;
 | 
				
			||||||
				codec->fixup_name = models->name;
 | 
									name = models->name;
 | 
				
			||||||
				codec->fixup_list = fixlist;
 | 
					 | 
				
			||||||
				codec_dbg(codec, "%s: picked fixup %s (model specified)\n",
 | 
									codec_dbg(codec, "%s: picked fixup %s (model specified)\n",
 | 
				
			||||||
					  codec->core.chip_name, codec->fixup_name);
 | 
										  codec->core.chip_name, codec->fixup_name);
 | 
				
			||||||
				return;
 | 
									goto found;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			models++;
 | 
								models++;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (quirk) {
 | 
					
 | 
				
			||||||
		q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
 | 
						if (!quirk)
 | 
				
			||||||
		if (q) {
 | 
							return;
 | 
				
			||||||
			id = q->value;
 | 
					
 | 
				
			||||||
#ifdef CONFIG_SND_DEBUG_VERBOSE
 | 
						/* match with the PCI SSID */
 | 
				
			||||||
			name = q->name;
 | 
						q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
 | 
				
			||||||
			codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n",
 | 
						if (q) {
 | 
				
			||||||
				  codec->core.chip_name, name, q->subdevice_mask ? "" : " - vendor generic");
 | 
							type = "PCI SSID";
 | 
				
			||||||
#endif
 | 
							goto found_device;
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (id < 0 && quirk) {
 | 
					 | 
				
			||||||
		for (q = quirk; q->subvendor || q->subdevice; q++) {
 | 
					 | 
				
			||||||
			unsigned int vendorid =
 | 
					 | 
				
			||||||
				q->subdevice | (q->subvendor << 16);
 | 
					 | 
				
			||||||
			unsigned int mask = 0xffff0000 | q->subdevice_mask;
 | 
					 | 
				
			||||||
			if ((codec->core.subsystem_id & mask) == (vendorid & mask)) {
 | 
					 | 
				
			||||||
				id = q->value;
 | 
					 | 
				
			||||||
#ifdef CONFIG_SND_DEBUG_VERBOSE
 | 
					 | 
				
			||||||
				name = q->name;
 | 
					 | 
				
			||||||
				codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n",
 | 
					 | 
				
			||||||
					  codec->core.chip_name, name);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	codec->fixup_id = id;
 | 
						/* match with the codec SSID */
 | 
				
			||||||
	if (id >= 0) {
 | 
						q = snd_pci_quirk_lookup_id(codec->core.subsystem_id >> 16,
 | 
				
			||||||
		codec->fixup_list = fixlist;
 | 
									    codec->core.subsystem_id & 0xffff,
 | 
				
			||||||
		codec->fixup_name = name;
 | 
									    quirk);
 | 
				
			||||||
 | 
						if (q) {
 | 
				
			||||||
 | 
							type = "codec SSID";
 | 
				
			||||||
 | 
							goto found_device;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return; /* no matching */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 found_device:
 | 
				
			||||||
 | 
						id = q->value;
 | 
				
			||||||
 | 
					#ifdef CONFIG_SND_DEBUG_VERBOSE
 | 
				
			||||||
 | 
						name = q->name;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						codec_dbg(codec, "%s: picked fixup %s for %s %04x:%04x\n",
 | 
				
			||||||
 | 
							  codec->core.chip_name, name ? name : "",
 | 
				
			||||||
 | 
							  type, q->subvendor, q->subdevice);
 | 
				
			||||||
 | 
					 found:
 | 
				
			||||||
 | 
						codec->fixup_id = id;
 | 
				
			||||||
 | 
						codec->fixup_list = fixlist;
 | 
				
			||||||
 | 
						codec->fixup_name = name;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(snd_hda_pick_fixup);
 | 
					EXPORT_SYMBOL_GPL(snd_hda_pick_fixup);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue