# Adapted from https://github.com/plbossart/UCM/tree/master/cht-bsw-rt5672

Define.Speaker "yes"
Define.Headphones "yes"
Define.MonoSpeaker "yes"
Define.DigitalMic1 "yes"
Define.DigitalMic2 "yes"
Define.HeadsetMic "yes"

# Figure out which components are in use on the device, we check both the
# components string (present on newer kernels) as well as checking for DMI
# strings for compatibility with older kernels. Note DMI matches for new
# models should only be added to the kernel, this UCM profile will then
# automatically pick up the info from the components string.

If.components-stereo-spk {
	Condition {
		Type String
		Haystack "${CardComponents}"
		Needle "cfg-spk:2"
	}
	True.Define.MonoSpeaker ""
}

If.components-dmic1 {
	Condition {
		Type String
		Haystack "${CardComponents}"
		Needle "cfg-mic:dmic1"
	}
	True.Define.DigitalMic2 ""
}

If.components-dmic2 {
	Condition {
		Type String
		Haystack "${CardComponents}"
		Needle "cfg-mic:dmic2"
	}
	True.Define.DigitalMic1 ""
}

If.dmi-dmic1 {
	Condition {
		Type RegexMatch
		String "${CardLongName}"
		Regex "(LENOVO.*LenovoMiix210)|(LENOVO.*ThinkPad10)"
	}
	True {
		Define.MonoSpeaker ""
		Define.DigitalMic2 ""
	}
}

If.dmi-dmic2 {
	Condition {
		Type RegexMatch
		String "${CardLongName}"
		Regex "(LENOVO.*ThinkPad8)"
	}
	True {
		Define.MonoSpeaker ""
		Define.DigitalMic1 ""
	}
}

SectionVerb {
	Include.e.File "/codecs/rt5672/EnableSeq.conf"

	If.Controls {
		Condition {
			Type ControlExists
			Control "name='media0_in Gain 0 Switch'"
		}
		Before.EnableSequence "0"
		True {
			Include.pe.File "/platforms/bytcr/PlatformEnableSeq.conf"
			Include.pd.File "/platforms/bytcr/PlatformDisableSeq.conf"
		}
	}
}

If.spk {
	Condition {
		Type String
		Empty "${var:Speaker}"
	}
	False.Include.spk.File "/codecs/rt5672/Speaker.conf"
}

If.mspk {
	Condition {
		Type String
		Empty "${var:MonoSpeaker}"
	}
	True {
		RenameDevice."Speaker1" "Speaker"
		RemoveDevice."Speaker2" "Speaker2"
	}
	False.Include.mspk.File "/codecs/rt5672/MonoSpeaker.conf"
}

If.hp {
	Condition {
		Type String
		Empty "${var:Headphones}"
	}
	#True.RemoveDevice."Headphones" "Headphones"
	False.Include.hp.File "/codecs/rt5672/HeadPhones.conf"
}

If.dmic1 {
	Condition {
		Type String
		Empty "${var:DigitalMic1}"
	}
	True.RemoveDevice."Mic1" "Mic1"
	False {
		Include.dmic1.File "/codecs/rt5672/DMIC1.conf"
		If.dmic2 {
			Condition {
				Type "String"
				Empty "${var:DigitalMic2}"
			}
			True.RenameDevice."Mic1" "Mic"
		}
	}
}

If.dmic2 {
	Condition {
		Type String
		Empty "${var:DigitalMic2}"
	}
	True.RemoveDevice."Mic2" "Mic2"
	False {
		Include.dmic2.File "/codecs/rt5672/DMIC2.conf"
		If.dmic1 {
			Condition {
				Type "String"
				Empty "${var:DigitalMic1}"
			}
			True.RenameDevice."Mic2" "Mic"
		}
	}
}

If.hsmic {
	Condition {
		Type String
		Empty "${var:HeadsetMic}"
	}
	#True.RemoveDevice."Headset" "Headset"
	False.Include.hsmic.File "/codecs/rt5672/HeadsetMic.conf"
}
