# Generic HDA devices for analog I/O

Define.LineDevice ""
Define.hpvol "Headphone"
Define.hpjack "Headphone Jack"
Define.loctl "Line"
Define.lovol "Line"

If.hpjack {
	Condition {
		Type ControlExists
		Control "iface=CARD,name='Headphone Mic Jack'"
	}
	True.Define.hpjack "Headphone Mic Jack"
	False.If.front {
		Condition {
			Type ControlExists
			Control "iface=CARD,name='Front Headphone Jack'"
		}
		True.Define.hpjack "Front Headphone Jack"
	}
}

If.lineout {
	Condition {
		Type ControlExists
		Control "name='Line Out Playback Volume'"
	}
	True.Define {
		loctl "Line Out"
		lovol "Line Out"
	}
}

If.linefront {
	Condition {
		Type ControlExists
		Control "name='Front Playback Volume'"
	}
	True.Define {
		LineDevice "1"
	}
}

If.hplo {
	Condition {
		Type ControlExists
		Control "name='Headphone+LO Playback Volume'"
	}
	True.Define {
		hpvol "Headphone+LO"
		lovol "Headphone+LO"
	}
}

SectionDevice."Headphones" {
	Comment "Headphones"

	If.headphone_switch {
		Condition {
			Type ControlExists
			Control "name='Headphone Playback Switch'"
		}
		True {
			EnableSequence [
				cset "name='Headphone Playback Switch' on"
			]
			DisableSequence [
				cset "name='Headphone Playback Switch' off"
			]
		}
	}

	Value {
		PlaybackPriority 200
		PlaybackPCM "hw:${CardId}"
		PlaybackMixerElem "${var:hpvol}"
		PlaybackMasterElem "Master"
		PlaybackVolume "${var:hpvol} Playback Volume"
		PlaybackSwitch "Headphone Playback Switch"
		JackControl "${var:hpjack}"
	}
}

If.spk {
	Condition {
		Type ControlExists
		Control "name='Speaker Playback Switch'"
	}
	True.SectionDevice."Speaker" {
		Comment "Speaker"

		If.seq {
			Condition {
				Type ControlExists
				Control "name='Bass Speaker Playback Switch'"
			}
			True {
				EnableSequence [
					cset "name='Speaker Playback Switch' on"
					cset "name='Bass Speaker Playback Switch' on"
				]

				DisableSequence [
					cset "name='Speaker Playback Switch' off"
					cset "name='Bass Speaker Playback Switch' off"
				]
			}
			False {
				EnableSequence [
					cset "name='Speaker Playback Switch' on"
				]

				DisableSequence [
					cset "name='Speaker Playback Switch' off"
				]
			}
		}

		Value {
			PlaybackPriority 100
			PlaybackPCM "hw:${CardId}"
			PlaybackMixerElem "Speaker"
			PlaybackMasterElem "Master"
			PlaybackVolume "Speaker Playback Volume"
			PlaybackSwitch "Speaker Playback Switch"
		}
	}
}

Include.hifi-mic.File "/HDA/HiFi-mic.conf"

If.line {
	Condition {
		Type ControlExists
		Control "name='${var:loctl} Playback Switch'"
	}
	True.SectionDevice."Line${var:LineDevice}" {
		Comment "Line Output"

		If.conflict {
			Condition {
				Type String
				String1 "${var:lovol}"
				String2 "Headphone+LO"
			}
			True.ConflictingDevice [
				"Headphones"
			]
		}

		EnableSequence [
			cset "name='${var:loctl} Playback Switch' on"
		]
		DisableSequence [
			cset "name='${var:loctl} Playback Switch' off"
		]

		Value {
			PlaybackPriority 300
			PlaybackPCM "hw:${CardId}"
			PlaybackMixerElem "${var:lovol}"
			PlaybackMasterElem "Master"
			PlaybackVolume "${var:lovol} Playback Volume"
			PlaybackSwitch "${var:loctl} Playback Switch"
			JackControl "${var:loctl} Jack"
		}
	}
}

If.linefront {
	Condition {
		Type ControlExists
		Control "name='Front Playback Switch'"
	}
	True.SectionDevice."Line2" {
		Comment "Second Line Output"

		ConflictingDevice [
			"Line${var:LineDevice}"
		]

		EnableSequence [
			cset "name='Front Playback Switch' on"
		]
		DisableSequence [
			cset "name='Front Playback Switch' off"
		]

		Value {
			PlaybackPriority 250
			PlaybackPCM "hw:${CardId}"
			PlaybackMixerElem "Front"
			PlaybackMasterElem "Master"
			PlaybackVolume "Front Playback Volume"
			PlaybackSwitch "Front Playback Switch"
			JackControl "Line Out Front Jack"
		}
	}
}
