📄 hdspm.c
字号:
strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int snd_hdspm_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm); return 0;}static int snd_hdspm_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 6) val = 6; spin_lock_irq(&hdspm->lock); if (val != hdspm_clock_source(hdspm)) change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdspm->lock); return change;}#define HDSPM_PREF_SYNC_REF(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_pref_sync_ref, \ .get = snd_hdspm_get_pref_sync_ref, \ .put = snd_hdspm_put_pref_sync_ref \}static int hdspm_pref_sync_ref(hdspm_t * hdspm){ /* Notice that this looks at the requested sync source, not the one actually in use. */ switch (hdspm->control_register & HDSPM_SyncRefMask) { case HDSPM_SyncRef_Word: return HDSPM_SYNC_FROM_WORD; case HDSPM_SyncRef_MADI: return HDSPM_SYNC_FROM_MADI; } return HDSPM_SYNC_FROM_WORD;}static int hdspm_set_pref_sync_ref(hdspm_t * hdspm, int pref){ hdspm->control_register &= ~HDSPM_SyncRefMask; switch (pref) { case HDSPM_SYNC_FROM_MADI: hdspm->control_register |= HDSPM_SyncRef_MADI; break; case HDSPM_SYNC_FROM_WORD: hdspm->control_register |= HDSPM_SyncRef_Word; break; default: return -1; } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0;}static int snd_hdspm_info_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ static char *texts[] = { "Word", "MADI" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 2; if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int snd_hdspm_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_pref_sync_ref(hdspm); return 0;}static int snd_hdspm_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); int change, max; unsigned int val; max = 2; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.enumerated.item[0] % max; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_pref_sync_ref(hdspm); hdspm_set_pref_sync_ref(hdspm, val); spin_unlock_irq(&hdspm->lock); return change;}#define HDSPM_AUTOSYNC_REF(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdspm_info_autosync_ref, \ .get = snd_hdspm_get_autosync_ref, \}static int hdspm_autosync_ref(hdspm_t * hdspm){ /* This looks at the autosync selected sync reference */ unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); switch (status2 & HDSPM_SelSyncRefMask) { case HDSPM_SelSyncRef_WORD: return HDSPM_AUTOSYNC_FROM_WORD; case HDSPM_SelSyncRef_MADI: return HDSPM_AUTOSYNC_FROM_MADI; case HDSPM_SelSyncRef_NVALID: return HDSPM_AUTOSYNC_FROM_NONE; default: return 0; } return 0;}static int snd_hdspm_info_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ static char *texts[] = { "WordClock", "MADI", "None" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 3; if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int snd_hdspm_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_pref_sync_ref(hdspm); return 0;}#define HDSPM_LINE_OUT(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_line_out, \ .get = snd_hdspm_get_line_out, \ .put = snd_hdspm_put_line_out \}static int hdspm_line_out(hdspm_t * hdspm){ return (hdspm->control_register & HDSPM_LineOut) ? 1 : 0;}static int hdspm_set_line_output(hdspm_t * hdspm, int out){ if (out) hdspm->control_register |= HDSPM_LineOut; else hdspm->control_register &= ~HDSPM_LineOut; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0;}static int snd_hdspm_info_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int snd_hdspm_get_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.integer.value[0] = hdspm_line_out(hdspm); spin_unlock_irq(&hdspm->lock); return 0;}static int snd_hdspm_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_line_out(hdspm); hdspm_set_line_output(hdspm, val); spin_unlock_irq(&hdspm->lock); return change;}#define HDSPM_TX_64(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_tx_64, \ .get = snd_hdspm_get_tx_64, \ .put = snd_hdspm_put_tx_64 \}static int hdspm_tx_64(hdspm_t * hdspm){ return (hdspm->control_register & HDSPM_TX_64ch) ? 1 : 0;}static int hdspm_set_tx_64(hdspm_t * hdspm, int out){ if (out) hdspm->control_register |= HDSPM_TX_64ch; else hdspm->control_register &= ~HDSPM_TX_64ch; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0;}static int snd_hdspm_info_tx_64(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int snd_hdspm_get_tx_64(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.integer.value[0] = hdspm_tx_64(hdspm); spin_unlock_irq(&hdspm->lock); return 0;}static int snd_hdspm_put_tx_64(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_tx_64(hdspm); hdspm_set_tx_64(hdspm, val); spin_unlock_irq(&hdspm->lock); return change;}#define HDSPM_C_TMS(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_c_tms, \ .get = snd_hdspm_get_c_tms, \ .put = snd_hdspm_put_c_tms \}static int hdspm_c_tms(hdspm_t * hdspm){ return (hdspm->control_register & HDSPM_clr_tms) ? 1 : 0;}static int hdspm_set_c_tms(hdspm_t * hdspm, int out){ if (out) hdspm->control_register |= HDSPM_clr_tms; else hdspm->control_register &= ~HDSPM_clr_tms; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0;}static int snd_hdspm_info_c_tms(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int snd_hdspm_get_c_tms(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.integer.value[0] = hdspm_c_tms(hdspm); spin_unlock_irq(&hdspm->lock); return 0;}static int snd_hdspm_put_c_tms(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_c_tms(hdspm); hdspm_set_c_tms(hdspm, val); spin_unlock_irq(&hdspm->lock); return change;}#define HDSPM_SAFE_MODE(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_safe_mode, \ .get = snd_hdspm_get_safe_mode, \ .put = snd_hdspm_put_safe_mode \}static int hdspm_safe_mode(hdspm_t * hdspm){ return (hdspm->control_register & HDSPM_AutoInp) ? 1 : 0;}static int hdspm_set_safe_mode(hdspm_t * hdspm, int out){ if (out) hdspm->control_register |= HDSPM_AutoInp; else hdspm->control_register &= ~HDSPM_AutoInp; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0;}static int snd_hdspm_info_safe_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int snd_hdspm_get_safe_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.integer.value[0] = hdspm_safe_mode(hdspm); spin_unlock_irq(&hdspm->lock); return 0;}static int snd_hdspm_put_safe_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ hdspm_t *hdspm = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_safe_mode(hdspm); hdspm_set_safe_mode(hdspm, val); spin_unlock_irq(&hdspm->lock); return change;}#define HDSPM_INPUT_SELECT(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_input_select, \ .get = snd_hdspm_get_input_select, \ .put = snd_hdspm_put_input_select \}static int hdspm_input_select(hdspm_t * hdspm){ return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;}static int hdspm_set_input_select(hdspm_t * hdspm, int out){ if (out) hdspm->control_register |= HDSPM_InputSelect0; else hdspm->control_register &= ~HDSPM_InputSelect0; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0;}static int snd_hdspm_info_input_select(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo){ static char *texts[] = { "optical", "coaxial" };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -