Lines Matching +full:invert +full:- +full:ext
1 // SPDX-License-Identifier: GPL-2.0-only
41 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
121 * now.... -DaveM
125 #include <sound/cs4231-regs.h>
128 #define CS4231U(chip, x) ((chip)->port + ((c_d_c_CS4231##x) << 2))
142 /* Defines for SBUS DMA-routines */
157 #define APC_XINT_ENA 0x80000 /* General ext int. enable */
158 #define APC_XINT_PLAY 0x40000 /* Playback ext intr */
159 #define APC_XINT_CAPT 0x20000 /* Capture ext intr */
160 #define APC_XINT_GENL 0x10000 /* Error ext intr */
222 0x00, /* 00/00 - lic */
223 0x00, /* 01/01 - ric */
224 0x9f, /* 02/02 - la1ic */
225 0x9f, /* 03/03 - ra1ic */
226 0x9f, /* 04/04 - la2ic */
227 0x9f, /* 05/05 - ra2ic */
228 0xbf, /* 06/06 - loc */
229 0xbf, /* 07/07 - roc */
230 0x20, /* 08/08 - pdfr */
231 CS4231_AUTOCALIB, /* 09/09 - ic */
232 0x00, /* 0a/10 - pc */
233 0x00, /* 0b/11 - ti */
234 CS4231_MODE2, /* 0c/12 - mi */
235 0x00, /* 0d/13 - lbc */
236 0x00, /* 0e/14 - pbru */
237 0x00, /* 0f/15 - pbrl */
238 0x80, /* 10/16 - afei */
239 0x01, /* 11/17 - afeii */
240 0x9f, /* 12/18 - llic */
241 0x9f, /* 13/19 - rlic */
242 0x00, /* 14/20 - tlb */
243 0x00, /* 15/21 - thb */
244 0x00, /* 16/22 - la3mic/reserved */
245 0x00, /* 17/23 - ra3mic/reserved */
246 0x00, /* 18/24 - afs */
247 0x00, /* 19/25 - lamoc/version */
248 0x00, /* 1a/26 - mioc */
249 0x00, /* 1b/27 - ramoc/reserved */
250 0x20, /* 1c/28 - cdfr */
251 0x00, /* 1d/29 - res4 */
252 0x00, /* 1e/30 - cbru */
253 0x00, /* 1f/31 - cbrl */
258 if (cp->flags & CS4231_FLAG_EBUS) in __cs4231_readb()
267 if (cp->flags & CS4231_FLAG_EBUS) in __cs4231_writeb()
281 for (timeout = 250; timeout > 0; timeout--) { in snd_cs4231_ready()
295 dev_dbg(chip->card->dev, in snd_cs4231_dout()
296 "out: auto calibration time out - reg = 0x%x, value = 0x%x\n", in snd_cs4231_dout()
299 __cs4231_writeb(chip, chip->mce_bit | reg, CS4231U(chip, REGSEL)); in snd_cs4231_dout()
308 unsigned char tmp = (chip->image[reg] & mask) | value; in snd_cs4231_outm()
310 chip->image[reg] = tmp; in snd_cs4231_outm()
311 if (!chip->calibrate_mute) in snd_cs4231_outm()
319 chip->image[reg] = value; in snd_cs4231_out()
328 dev_dbg(chip->card->dev, in snd_cs4231_in()
329 "in: auto calibration time out - reg = 0x%x\n", in snd_cs4231_in()
332 __cs4231_writeb(chip, chip->mce_bit | reg, CS4231U(chip, REGSEL)); in snd_cs4231_in()
346 for (timeout = 5; timeout > 0; timeout--) in snd_cs4231_busy_wait()
350 for (timeout = 500; timeout > 0; timeout--) { in snd_cs4231_busy_wait()
363 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_mce_up()
367 dev_dbg(chip->card->dev, in snd_cs4231_mce_up()
368 "mce_up - auto calibration time out (0)\n"); in snd_cs4231_mce_up()
370 chip->mce_bit |= CS4231_MCE; in snd_cs4231_mce_up()
373 dev_dbg(chip->card->dev, in snd_cs4231_mce_up()
374 "mce_up [%p]: serious init problem - codec still busy\n", in snd_cs4231_mce_up()
375 chip->port); in snd_cs4231_mce_up()
377 __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), in snd_cs4231_mce_up()
379 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_mce_up()
388 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_mce_down()
391 dev_dbg(chip->card->dev, in snd_cs4231_mce_down()
392 "mce_down [%p] - auto calibration time out (0)\n", in snd_cs4231_mce_down()
395 chip->mce_bit &= ~CS4231_MCE; in snd_cs4231_mce_down()
397 __cs4231_writeb(chip, chip->mce_bit | (reg & 0x1f), in snd_cs4231_mce_down()
400 dev_dbg(chip->card->dev, in snd_cs4231_mce_down()
401 "mce_down [%p]: serious init problem - codec still busy\n", in snd_cs4231_mce_down()
402 chip->port); in snd_cs4231_mce_down()
404 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_mce_down()
409 * Wait for auto-calibration (AC) process to finish, i.e. ACI to go low. in snd_cs4231_mce_down()
413 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_mce_down()
415 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_mce_down()
419 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_mce_down()
422 dev_err(chip->card->dev, in snd_cs4231_mce_down()
423 "mce_down - auto calibration time out (2)\n"); in snd_cs4231_mce_down()
430 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cs4231_advance_dma()
439 if (dma_cont->request(dma_cont, in snd_cs4231_advance_dma()
440 runtime->dma_addr + offset, period_size)) in snd_cs4231_advance_dma()
442 (*periods_sent) = ((*periods_sent) + 1) % runtime->periods; in snd_cs4231_advance_dma()
453 dma_cont = &chip->p_dma; in cs4231_dma_trigger()
455 dma_cont->prepare(dma_cont, 0); in cs4231_dma_trigger()
456 dma_cont->enable(dma_cont, 1); in cs4231_dma_trigger()
458 chip->playback_substream, in cs4231_dma_trigger()
459 &chip->p_periods_sent); in cs4231_dma_trigger()
461 dma_cont->enable(dma_cont, 0); in cs4231_dma_trigger()
465 dma_cont = &chip->c_dma; in cs4231_dma_trigger()
467 dma_cont->prepare(dma_cont, 1); in cs4231_dma_trigger()
468 dma_cont->enable(dma_cont, 1); in cs4231_dma_trigger()
470 chip->capture_substream, in cs4231_dma_trigger()
471 &chip->c_periods_sent); in cs4231_dma_trigger()
473 dma_cont->enable(dma_cont, 0); in cs4231_dma_trigger()
492 if (s == chip->playback_substream) { in snd_cs4231_trigger()
495 } else if (s == chip->capture_substream) { in snd_cs4231_trigger()
501 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_trigger()
504 chip->image[CS4231_IFACE_CTRL] |= what; in snd_cs4231_trigger()
507 chip->image[CS4231_IFACE_CTRL] &= ~what; in snd_cs4231_trigger()
510 chip->image[CS4231_IFACE_CTRL]); in snd_cs4231_trigger()
511 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_trigger()
515 result = -EINVAL; in snd_cs4231_trigger()
570 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_calibrate_mute()
571 if (chip->calibrate_mute == mute) { in snd_cs4231_calibrate_mute()
572 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_calibrate_mute()
577 chip->image[CS4231_LEFT_INPUT]); in snd_cs4231_calibrate_mute()
579 chip->image[CS4231_RIGHT_INPUT]); in snd_cs4231_calibrate_mute()
581 chip->image[CS4231_LOOPBACK]); in snd_cs4231_calibrate_mute()
584 mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]); in snd_cs4231_calibrate_mute()
586 mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]); in snd_cs4231_calibrate_mute()
588 mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]); in snd_cs4231_calibrate_mute()
590 mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]); in snd_cs4231_calibrate_mute()
592 mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]); in snd_cs4231_calibrate_mute()
594 mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]); in snd_cs4231_calibrate_mute()
596 mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]); in snd_cs4231_calibrate_mute()
598 mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]); in snd_cs4231_calibrate_mute()
600 mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]); in snd_cs4231_calibrate_mute()
601 chip->calibrate_mute = mute; in snd_cs4231_calibrate_mute()
602 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_calibrate_mute()
611 mutex_lock(&chip->mce_mutex); in snd_cs4231_playback_format()
616 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_playback_format()
618 (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ? in snd_cs4231_playback_format()
619 (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) : in snd_cs4231_playback_format()
621 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_playback_format()
626 mutex_unlock(&chip->mce_mutex); in snd_cs4231_playback_format()
635 mutex_lock(&chip->mce_mutex); in snd_cs4231_capture_format()
640 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_capture_format()
641 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) { in snd_cs4231_capture_format()
643 ((chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) | in snd_cs4231_capture_format()
645 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_capture_format()
648 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_capture_format()
651 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_capture_format()
656 mutex_unlock(&chip->mce_mutex); in snd_cs4231_capture_format()
667 return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920; in snd_cs4231_timer_resolution()
676 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_timer_start()
677 ticks = timer->sticks; in snd_cs4231_timer_start()
678 if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 || in snd_cs4231_timer_start()
679 (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] || in snd_cs4231_timer_start()
680 (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) { in snd_cs4231_timer_start()
682 chip->image[CS4231_TIMER_HIGH] = in snd_cs4231_timer_start()
685 chip->image[CS4231_TIMER_LOW] = in snd_cs4231_timer_start()
688 chip->image[CS4231_ALT_FEATURE_1] | in snd_cs4231_timer_start()
691 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_timer_start()
701 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_timer_stop()
702 chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE; in snd_cs4231_timer_stop()
704 chip->image[CS4231_ALT_FEATURE_1]); in snd_cs4231_timer_stop()
705 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_timer_stop()
720 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_init()
721 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | in snd_cs4231_init()
726 chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB; in snd_cs4231_init()
727 snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); in snd_cs4231_init()
728 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_init()
736 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_init()
738 chip->image[CS4231_ALT_FEATURE_1]); in snd_cs4231_init()
739 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_init()
743 pr_debug("init: (3) - afei = 0x%x\n", in snd_cs4231_init()
744 chip->image[CS4231_ALT_FEATURE_1]); in snd_cs4231_init()
747 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_init()
749 chip->image[CS4231_ALT_FEATURE_2]); in snd_cs4231_init()
750 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_init()
753 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_init()
755 chip->image[CS4231_PLAYBK_FORMAT]); in snd_cs4231_init()
756 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_init()
764 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_init()
765 snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]); in snd_cs4231_init()
766 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_init()
778 mutex_lock(&chip->open_mutex); in snd_cs4231_open()
779 if ((chip->mode & mode)) { in snd_cs4231_open()
780 mutex_unlock(&chip->open_mutex); in snd_cs4231_open()
781 return -EAGAIN; in snd_cs4231_open()
783 if (chip->mode & CS4231_MODE_OPEN) { in snd_cs4231_open()
784 chip->mode |= mode; in snd_cs4231_open()
785 mutex_unlock(&chip->open_mutex); in snd_cs4231_open()
789 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_open()
802 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_open()
804 chip->mode = mode; in snd_cs4231_open()
805 mutex_unlock(&chip->open_mutex); in snd_cs4231_open()
813 mutex_lock(&chip->open_mutex); in snd_cs4231_close()
814 chip->mode &= ~mode; in snd_cs4231_close()
815 if (chip->mode & CS4231_MODE_OPEN) { in snd_cs4231_close()
816 mutex_unlock(&chip->open_mutex); in snd_cs4231_close()
822 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_close()
829 if (chip->image[CS4231_IFACE_CTRL] & in snd_cs4231_close()
832 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_close()
834 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_close()
835 chip->image[CS4231_IFACE_CTRL] &= in snd_cs4231_close()
839 chip->image[CS4231_IFACE_CTRL]); in snd_cs4231_close()
840 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_close()
842 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_close()
849 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_close()
853 chip->mode = 0; in snd_cs4231_close()
854 mutex_unlock(&chip->open_mutex); in snd_cs4231_close()
907 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cs4231_playback_prepare()
911 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_playback_prepare()
913 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | in snd_cs4231_playback_prepare()
916 if (WARN_ON(runtime->period_size > 0xffff + 1)) { in snd_cs4231_playback_prepare()
917 ret = -EINVAL; in snd_cs4231_playback_prepare()
921 chip->p_periods_sent = 0; in snd_cs4231_playback_prepare()
924 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_playback_prepare()
948 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_capture_prepare()
949 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | in snd_cs4231_capture_prepare()
953 chip->c_periods_sent = 0; in snd_cs4231_capture_prepare()
954 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_capture_prepare()
964 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_overrange()
966 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_overrange()
970 chip->capture_substream->runtime->overrange++; in snd_cs4231_overrange()
975 if (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) { in snd_cs4231_play_callback()
976 snd_pcm_period_elapsed(chip->playback_substream); in snd_cs4231_play_callback()
977 snd_cs4231_advance_dma(&chip->p_dma, chip->playback_substream, in snd_cs4231_play_callback()
978 &chip->p_periods_sent); in snd_cs4231_play_callback()
984 if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) { in snd_cs4231_capture_callback()
985 snd_pcm_period_elapsed(chip->capture_substream); in snd_cs4231_capture_callback()
986 snd_cs4231_advance_dma(&chip->c_dma, chip->capture_substream, in snd_cs4231_capture_callback()
987 &chip->c_periods_sent); in snd_cs4231_capture_callback()
995 struct cs4231_dma_control *dma_cont = &chip->p_dma; in snd_cs4231_playback_pointer()
998 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) in snd_cs4231_playback_pointer()
1000 ptr = dma_cont->address(dma_cont); in snd_cs4231_playback_pointer()
1002 ptr -= substream->runtime->dma_addr; in snd_cs4231_playback_pointer()
1004 return bytes_to_frames(substream->runtime, ptr); in snd_cs4231_playback_pointer()
1011 struct cs4231_dma_control *dma_cont = &chip->c_dma; in snd_cs4231_capture_pointer()
1014 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) in snd_cs4231_capture_pointer()
1016 ptr = dma_cont->address(dma_cont); in snd_cs4231_capture_pointer()
1018 ptr -= substream->runtime->dma_addr; in snd_cs4231_capture_pointer()
1020 return bytes_to_frames(substream->runtime, ptr); in snd_cs4231_capture_pointer()
1036 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_probe()
1040 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_probe()
1045 dev_dbg(chip->card->dev, in snd_cs4231_probe()
1046 "cs4231: port = %p, id = 0x%x\n", chip->port, id); in snd_cs4231_probe()
1048 return -ENODEV; /* no valid device found */ in snd_cs4231_probe()
1050 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_probe()
1057 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_probe()
1059 chip->image[CS4231_MISC_INFO] = CS4231_MODE2; in snd_cs4231_probe()
1060 chip->image[CS4231_IFACE_CTRL] = in snd_cs4231_probe()
1061 chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA; in snd_cs4231_probe()
1062 chip->image[CS4231_ALT_FEATURE_1] = 0x80; in snd_cs4231_probe()
1063 chip->image[CS4231_ALT_FEATURE_2] = 0x01; in snd_cs4231_probe()
1065 chip->image[CS4231_ALT_FEATURE_2] |= 0x02; in snd_cs4231_probe()
1067 ptr = (unsigned char *) &chip->image; in snd_cs4231_probe()
1071 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_probe()
1076 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_probe()
1138 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cs4231_playback_open()
1141 runtime->hw = snd_cs4231_playback; in snd_cs4231_playback_open()
1146 chip->playback_substream = substream; in snd_cs4231_playback_open()
1147 chip->p_periods_sent = 0; in snd_cs4231_playback_open()
1157 struct snd_pcm_runtime *runtime = substream->runtime; in snd_cs4231_capture_open()
1160 runtime->hw = snd_cs4231_capture; in snd_cs4231_capture_open()
1165 chip->capture_substream = substream; in snd_cs4231_capture_open()
1166 chip->c_periods_sent = 0; in snd_cs4231_capture_open()
1178 chip->playback_substream = NULL; in snd_cs4231_playback_close()
1188 chip->capture_substream = NULL; in snd_cs4231_capture_close()
1193 /* XXX We can do some power-management, in particular on EBUS using
1217 struct snd_cs4231 *chip = card->private_data; in snd_cs4231_pcm()
1231 pcm->private_data = chip; in snd_cs4231_pcm()
1232 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; in snd_cs4231_pcm()
1233 strcpy(pcm->name, "CS4231"); in snd_cs4231_pcm()
1236 &chip->op->dev, 64 * 1024, 128 * 1024); in snd_cs4231_pcm()
1238 chip->pcm = pcm; in snd_cs4231_pcm()
1245 struct snd_cs4231 *chip = card->private_data; in snd_cs4231_timer()
1253 tid.card = card->number; in snd_cs4231_timer()
1259 strcpy(timer->name, "CS4231"); in snd_cs4231_timer()
1260 timer->private_data = chip; in snd_cs4231_timer()
1261 timer->hw = snd_cs4231_timer_table; in snd_cs4231_timer()
1262 chip->timer = timer; in snd_cs4231_timer()
1287 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_get_mux()
1288 ucontrol->value.enumerated.item[0] = in snd_cs4231_get_mux()
1289 (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6; in snd_cs4231_get_mux()
1290 ucontrol->value.enumerated.item[1] = in snd_cs4231_get_mux()
1291 (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6; in snd_cs4231_get_mux()
1292 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_get_mux()
1305 if (ucontrol->value.enumerated.item[0] > 3 || in snd_cs4231_put_mux()
1306 ucontrol->value.enumerated.item[1] > 3) in snd_cs4231_put_mux()
1307 return -EINVAL; in snd_cs4231_put_mux()
1308 left = ucontrol->value.enumerated.item[0] << 6; in snd_cs4231_put_mux()
1309 right = ucontrol->value.enumerated.item[1] << 6; in snd_cs4231_put_mux()
1311 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_put_mux()
1313 left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left; in snd_cs4231_put_mux()
1314 right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right; in snd_cs4231_put_mux()
1315 change = left != chip->image[CS4231_LEFT_INPUT] || in snd_cs4231_put_mux()
1316 right != chip->image[CS4231_RIGHT_INPUT]; in snd_cs4231_put_mux()
1320 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_put_mux()
1328 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_cs4231_info_single()
1330 uinfo->type = (mask == 1) ? in snd_cs4231_info_single()
1332 uinfo->count = 1; in snd_cs4231_info_single()
1333 uinfo->value.integer.min = 0; in snd_cs4231_info_single()
1334 uinfo->value.integer.max = mask; in snd_cs4231_info_single()
1344 int reg = kcontrol->private_value & 0xff; in snd_cs4231_get_single()
1345 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_cs4231_get_single()
1346 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_cs4231_get_single()
1347 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_cs4231_get_single() local
1349 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_get_single()
1351 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; in snd_cs4231_get_single()
1353 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_get_single()
1355 if (invert) in snd_cs4231_get_single()
1356 ucontrol->value.integer.value[0] = in snd_cs4231_get_single()
1357 (mask - ucontrol->value.integer.value[0]); in snd_cs4231_get_single()
1367 int reg = kcontrol->private_value & 0xff; in snd_cs4231_put_single()
1368 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_cs4231_put_single()
1369 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_cs4231_put_single()
1370 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_cs4231_put_single() local
1374 val = (ucontrol->value.integer.value[0] & mask); in snd_cs4231_put_single()
1375 if (invert) in snd_cs4231_put_single()
1376 val = mask - val; in snd_cs4231_put_single()
1379 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_put_single()
1381 val = (chip->image[reg] & ~(mask << shift)) | val; in snd_cs4231_put_single()
1382 change = val != chip->image[reg]; in snd_cs4231_put_single()
1385 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_put_single()
1393 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_cs4231_info_double()
1395 uinfo->type = mask == 1 ? in snd_cs4231_info_double()
1397 uinfo->count = 2; in snd_cs4231_info_double()
1398 uinfo->value.integer.min = 0; in snd_cs4231_info_double()
1399 uinfo->value.integer.max = mask; in snd_cs4231_info_double()
1409 int left_reg = kcontrol->private_value & 0xff; in snd_cs4231_get_double()
1410 int right_reg = (kcontrol->private_value >> 8) & 0xff; in snd_cs4231_get_double()
1411 int shift_left = (kcontrol->private_value >> 16) & 0x07; in snd_cs4231_get_double()
1412 int shift_right = (kcontrol->private_value >> 19) & 0x07; in snd_cs4231_get_double()
1413 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_cs4231_get_double()
1414 int invert = (kcontrol->private_value >> 22) & 1; in snd_cs4231_get_double() local
1416 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_get_double()
1418 ucontrol->value.integer.value[0] = in snd_cs4231_get_double()
1419 (chip->image[left_reg] >> shift_left) & mask; in snd_cs4231_get_double()
1420 ucontrol->value.integer.value[1] = in snd_cs4231_get_double()
1421 (chip->image[right_reg] >> shift_right) & mask; in snd_cs4231_get_double()
1423 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_get_double()
1425 if (invert) { in snd_cs4231_get_double()
1426 ucontrol->value.integer.value[0] = in snd_cs4231_get_double()
1427 (mask - ucontrol->value.integer.value[0]); in snd_cs4231_get_double()
1428 ucontrol->value.integer.value[1] = in snd_cs4231_get_double()
1429 (mask - ucontrol->value.integer.value[1]); in snd_cs4231_get_double()
1440 int left_reg = kcontrol->private_value & 0xff; in snd_cs4231_put_double()
1441 int right_reg = (kcontrol->private_value >> 8) & 0xff; in snd_cs4231_put_double()
1442 int shift_left = (kcontrol->private_value >> 16) & 0x07; in snd_cs4231_put_double()
1443 int shift_right = (kcontrol->private_value >> 19) & 0x07; in snd_cs4231_put_double()
1444 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_cs4231_put_double()
1445 int invert = (kcontrol->private_value >> 22) & 1; in snd_cs4231_put_double() local
1449 val1 = ucontrol->value.integer.value[0] & mask; in snd_cs4231_put_double()
1450 val2 = ucontrol->value.integer.value[1] & mask; in snd_cs4231_put_double()
1451 if (invert) { in snd_cs4231_put_double()
1452 val1 = mask - val1; in snd_cs4231_put_double()
1453 val2 = mask - val2; in snd_cs4231_put_double()
1458 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_put_double()
1460 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; in snd_cs4231_put_double()
1461 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; in snd_cs4231_put_double()
1462 change = val1 != chip->image[left_reg]; in snd_cs4231_put_double()
1463 change |= val2 != chip->image[right_reg]; in snd_cs4231_put_double()
1467 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_put_double()
1472 #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \ argument
1476 .private_value = (reg) | ((shift) << 8) | ((mask) << 16) | ((invert) << 24) }
1479 shift_right, mask, invert) \ argument
1484 ((shift_right) << 19) | ((mask) << 24) | ((invert) << 22) }
1527 struct snd_cs4231 *chip = card->private_data; in snd_cs4231_mixer()
1530 if (snd_BUG_ON(!chip || !chip->pcm)) in snd_cs4231_mixer()
1531 return -EINVAL; in snd_cs4231_mixer()
1533 strcpy(card->mixername, chip->pcm->name); in snd_cs4231_mixer()
1556 return -ENODEV; in cs4231_attach_begin()
1560 return -ENOENT; in cs4231_attach_begin()
1563 err = snd_card_new(&op->dev, index[dev], id[dev], THIS_MODULE, in cs4231_attach_begin()
1568 strcpy(card->driver, "CS4231"); in cs4231_attach_begin()
1569 strcpy(card->shortname, "Sun CS4231"); in cs4231_attach_begin()
1571 chip = card->private_data; in cs4231_attach_begin()
1572 chip->card = card; in cs4231_attach_begin()
1580 struct snd_cs4231 *chip = card->private_data; in cs4231_attach_finish()
1599 dev_set_drvdata(&chip->op->dev, chip); in cs4231_attach_finish()
1623 csr = sbus_readl(chip->port + APCCSR); in snd_cs4231_sbus_interrupt()
1625 sbus_writel(csr, chip->port + APCCSR); in snd_cs4231_sbus_interrupt()
1642 if (chip->timer) in snd_cs4231_sbus_interrupt()
1643 snd_timer_interrupt(chip->timer, chip->timer->sticks); in snd_cs4231_sbus_interrupt()
1650 spin_lock_irqsave(&chip->lock, flags); in snd_cs4231_sbus_interrupt()
1652 spin_unlock_irqrestore(&chip->lock, flags); in snd_cs4231_sbus_interrupt()
1667 struct sbus_dma_info *base = &dma_cont->sbus_info; in sbus_dma_request()
1670 return -EINVAL; in sbus_dma_request()
1671 spin_lock_irqsave(&base->lock, flags); in sbus_dma_request()
1672 csr = sbus_readl(base->regs + APCCSR); in sbus_dma_request()
1673 err = -EINVAL; in sbus_dma_request()
1675 if (base->dir == APC_PLAY) in sbus_dma_request()
1679 err = -EBUSY; in sbus_dma_request()
1681 if (base->dir == APC_PLAY) in sbus_dma_request()
1686 sbus_writel(bus_addr, base->regs + base->dir + APCNVA); in sbus_dma_request()
1687 sbus_writel(len, base->regs + base->dir + APCNC); in sbus_dma_request()
1689 spin_unlock_irqrestore(&base->lock, flags); in sbus_dma_request()
1697 struct sbus_dma_info *base = &dma_cont->sbus_info; in sbus_dma_prepare()
1699 spin_lock_irqsave(&base->lock, flags); in sbus_dma_prepare()
1700 csr = sbus_readl(base->regs + APCCSR); in sbus_dma_prepare()
1704 if (base->dir == APC_RECORD) in sbus_dma_prepare()
1708 sbus_writel(csr, base->regs + APCCSR); in sbus_dma_prepare()
1709 spin_unlock_irqrestore(&base->lock, flags); in sbus_dma_prepare()
1716 struct sbus_dma_info *base = &dma_cont->sbus_info; in sbus_dma_enable()
1718 spin_lock_irqsave(&base->lock, flags); in sbus_dma_enable()
1720 sbus_writel(0, base->regs + base->dir + APCNC); in sbus_dma_enable()
1721 sbus_writel(0, base->regs + base->dir + APCNVA); in sbus_dma_enable()
1722 if (base->dir == APC_PLAY) { in sbus_dma_enable()
1723 sbus_writel(0, base->regs + base->dir + APCC); in sbus_dma_enable()
1724 sbus_writel(0, base->regs + base->dir + APCVA); in sbus_dma_enable()
1729 csr = sbus_readl(base->regs + APCCSR); in sbus_dma_enable()
1731 if (base->dir == APC_PLAY) in sbus_dma_enable()
1737 sbus_writel(csr, base->regs + APCCSR); in sbus_dma_enable()
1742 sbus_writel(csr, base->regs + APCCSR); in sbus_dma_enable()
1744 spin_unlock_irqrestore(&base->lock, flags); in sbus_dma_enable()
1749 struct sbus_dma_info *base = &dma_cont->sbus_info; in sbus_dma_addr()
1751 return sbus_readl(base->regs + base->dir + APCVA); in sbus_dma_addr()
1760 struct platform_device *op = chip->op; in snd_cs4231_sbus_free()
1762 if (chip->irq[0]) in snd_cs4231_sbus_free()
1763 free_irq(chip->irq[0], chip); in snd_cs4231_sbus_free()
1765 if (chip->port) in snd_cs4231_sbus_free()
1766 of_iounmap(&op->resource[0], chip->port, chip->regs_size); in snd_cs4231_sbus_free()
1773 struct snd_cs4231 *cp = device->device_data; in snd_cs4231_sbus_dev_free()
1786 struct snd_cs4231 *chip = card->private_data; in snd_cs4231_sbus_create()
1789 spin_lock_init(&chip->lock); in snd_cs4231_sbus_create()
1790 spin_lock_init(&chip->c_dma.sbus_info.lock); in snd_cs4231_sbus_create()
1791 spin_lock_init(&chip->p_dma.sbus_info.lock); in snd_cs4231_sbus_create()
1792 mutex_init(&chip->mce_mutex); in snd_cs4231_sbus_create()
1793 mutex_init(&chip->open_mutex); in snd_cs4231_sbus_create()
1794 chip->op = op; in snd_cs4231_sbus_create()
1795 chip->regs_size = resource_size(&op->resource[0]); in snd_cs4231_sbus_create()
1796 memcpy(&chip->image, &snd_cs4231_original_image, in snd_cs4231_sbus_create()
1799 chip->port = of_ioremap(&op->resource[0], 0, in snd_cs4231_sbus_create()
1800 chip->regs_size, "cs4231"); in snd_cs4231_sbus_create()
1801 if (!chip->port) { in snd_cs4231_sbus_create()
1802 dev_dbg(chip->card->dev, in snd_cs4231_sbus_create()
1803 "cs4231-%d: Unable to map chip registers.\n", dev); in snd_cs4231_sbus_create()
1804 return -EIO; in snd_cs4231_sbus_create()
1807 chip->c_dma.sbus_info.regs = chip->port; in snd_cs4231_sbus_create()
1808 chip->p_dma.sbus_info.regs = chip->port; in snd_cs4231_sbus_create()
1809 chip->c_dma.sbus_info.dir = APC_RECORD; in snd_cs4231_sbus_create()
1810 chip->p_dma.sbus_info.dir = APC_PLAY; in snd_cs4231_sbus_create()
1812 chip->p_dma.prepare = sbus_dma_prepare; in snd_cs4231_sbus_create()
1813 chip->p_dma.enable = sbus_dma_enable; in snd_cs4231_sbus_create()
1814 chip->p_dma.request = sbus_dma_request; in snd_cs4231_sbus_create()
1815 chip->p_dma.address = sbus_dma_addr; in snd_cs4231_sbus_create()
1817 chip->c_dma.prepare = sbus_dma_prepare; in snd_cs4231_sbus_create()
1818 chip->c_dma.enable = sbus_dma_enable; in snd_cs4231_sbus_create()
1819 chip->c_dma.request = sbus_dma_request; in snd_cs4231_sbus_create()
1820 chip->c_dma.address = sbus_dma_addr; in snd_cs4231_sbus_create()
1822 if (request_irq(op->archdata.irqs[0], snd_cs4231_sbus_interrupt, in snd_cs4231_sbus_create()
1824 dev_dbg(chip->card->dev, in snd_cs4231_sbus_create()
1825 "cs4231-%d: Unable to grab SBUS IRQ %d\n", in snd_cs4231_sbus_create()
1826 dev, op->archdata.irqs[0]); in snd_cs4231_sbus_create()
1828 return -EBUSY; in snd_cs4231_sbus_create()
1830 chip->irq[0] = op->archdata.irqs[0]; in snd_cs4231_sbus_create()
1834 return -ENODEV; in snd_cs4231_sbus_create()
1850 struct resource *rp = &op->resource[0]; in cs4231_sbus_probe()
1858 sprintf(card->longname, "%s at 0x%02lx:0x%016Lx, irq %d", in cs4231_sbus_probe()
1859 card->shortname, in cs4231_sbus_probe()
1860 rp->flags & 0xffL, in cs4231_sbus_probe()
1861 (unsigned long long)rp->start, in cs4231_sbus_probe()
1862 op->archdata.irqs[0]); in cs4231_sbus_probe()
1899 return ebus_dma_request(&dma_cont->ebus_info, bus_addr, len); in _ebus_dma_request()
1904 ebus_dma_enable(&dma_cont->ebus_info, on); in _ebus_dma_enable()
1909 ebus_dma_prepare(&dma_cont->ebus_info, dir); in _ebus_dma_prepare()
1914 return ebus_dma_addr(&dma_cont->ebus_info); in _ebus_dma_addr()
1923 struct platform_device *op = chip->op; in snd_cs4231_ebus_free()
1925 if (chip->c_dma.ebus_info.regs) { in snd_cs4231_ebus_free()
1926 ebus_dma_unregister(&chip->c_dma.ebus_info); in snd_cs4231_ebus_free()
1927 of_iounmap(&op->resource[2], chip->c_dma.ebus_info.regs, 0x10); in snd_cs4231_ebus_free()
1929 if (chip->p_dma.ebus_info.regs) { in snd_cs4231_ebus_free()
1930 ebus_dma_unregister(&chip->p_dma.ebus_info); in snd_cs4231_ebus_free()
1931 of_iounmap(&op->resource[1], chip->p_dma.ebus_info.regs, 0x10); in snd_cs4231_ebus_free()
1934 if (chip->port) in snd_cs4231_ebus_free()
1935 of_iounmap(&op->resource[0], chip->port, 0x10); in snd_cs4231_ebus_free()
1942 struct snd_cs4231 *cp = device->device_data; in snd_cs4231_ebus_dev_free()
1955 struct snd_cs4231 *chip = card->private_data; in snd_cs4231_ebus_create()
1958 spin_lock_init(&chip->lock); in snd_cs4231_ebus_create()
1959 spin_lock_init(&chip->c_dma.ebus_info.lock); in snd_cs4231_ebus_create()
1960 spin_lock_init(&chip->p_dma.ebus_info.lock); in snd_cs4231_ebus_create()
1961 mutex_init(&chip->mce_mutex); in snd_cs4231_ebus_create()
1962 mutex_init(&chip->open_mutex); in snd_cs4231_ebus_create()
1963 chip->flags |= CS4231_FLAG_EBUS; in snd_cs4231_ebus_create()
1964 chip->op = op; in snd_cs4231_ebus_create()
1965 memcpy(&chip->image, &snd_cs4231_original_image, in snd_cs4231_ebus_create()
1967 strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)"); in snd_cs4231_ebus_create()
1968 chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; in snd_cs4231_ebus_create()
1969 chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback; in snd_cs4231_ebus_create()
1970 chip->c_dma.ebus_info.client_cookie = chip; in snd_cs4231_ebus_create()
1971 chip->c_dma.ebus_info.irq = op->archdata.irqs[0]; in snd_cs4231_ebus_create()
1972 strcpy(chip->p_dma.ebus_info.name, "cs4231(play)"); in snd_cs4231_ebus_create()
1973 chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; in snd_cs4231_ebus_create()
1974 chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback; in snd_cs4231_ebus_create()
1975 chip->p_dma.ebus_info.client_cookie = chip; in snd_cs4231_ebus_create()
1976 chip->p_dma.ebus_info.irq = op->archdata.irqs[1]; in snd_cs4231_ebus_create()
1978 chip->p_dma.prepare = _ebus_dma_prepare; in snd_cs4231_ebus_create()
1979 chip->p_dma.enable = _ebus_dma_enable; in snd_cs4231_ebus_create()
1980 chip->p_dma.request = _ebus_dma_request; in snd_cs4231_ebus_create()
1981 chip->p_dma.address = _ebus_dma_addr; in snd_cs4231_ebus_create()
1983 chip->c_dma.prepare = _ebus_dma_prepare; in snd_cs4231_ebus_create()
1984 chip->c_dma.enable = _ebus_dma_enable; in snd_cs4231_ebus_create()
1985 chip->c_dma.request = _ebus_dma_request; in snd_cs4231_ebus_create()
1986 chip->c_dma.address = _ebus_dma_addr; in snd_cs4231_ebus_create()
1988 chip->port = of_ioremap(&op->resource[0], 0, 0x10, "cs4231"); in snd_cs4231_ebus_create()
1989 chip->p_dma.ebus_info.regs = in snd_cs4231_ebus_create()
1990 of_ioremap(&op->resource[1], 0, 0x10, "cs4231_pdma"); in snd_cs4231_ebus_create()
1991 chip->c_dma.ebus_info.regs = in snd_cs4231_ebus_create()
1992 of_ioremap(&op->resource[2], 0, 0x10, "cs4231_cdma"); in snd_cs4231_ebus_create()
1993 if (!chip->port || !chip->p_dma.ebus_info.regs || in snd_cs4231_ebus_create()
1994 !chip->c_dma.ebus_info.regs) { in snd_cs4231_ebus_create()
1996 dev_dbg(chip->card->dev, in snd_cs4231_ebus_create()
1997 "cs4231-%d: Unable to map chip registers.\n", dev); in snd_cs4231_ebus_create()
1998 return -EIO; in snd_cs4231_ebus_create()
2001 if (ebus_dma_register(&chip->c_dma.ebus_info)) { in snd_cs4231_ebus_create()
2003 dev_dbg(chip->card->dev, in snd_cs4231_ebus_create()
2004 "cs4231-%d: Unable to register EBUS capture DMA\n", in snd_cs4231_ebus_create()
2006 return -EBUSY; in snd_cs4231_ebus_create()
2008 if (ebus_dma_irq_enable(&chip->c_dma.ebus_info, 1)) { in snd_cs4231_ebus_create()
2010 dev_dbg(chip->card->dev, in snd_cs4231_ebus_create()
2011 "cs4231-%d: Unable to enable EBUS capture IRQ\n", in snd_cs4231_ebus_create()
2013 return -EBUSY; in snd_cs4231_ebus_create()
2016 if (ebus_dma_register(&chip->p_dma.ebus_info)) { in snd_cs4231_ebus_create()
2018 dev_dbg(chip->card->dev, in snd_cs4231_ebus_create()
2019 "cs4231-%d: Unable to register EBUS play DMA\n", in snd_cs4231_ebus_create()
2021 return -EBUSY; in snd_cs4231_ebus_create()
2023 if (ebus_dma_irq_enable(&chip->p_dma.ebus_info, 1)) { in snd_cs4231_ebus_create()
2025 dev_dbg(chip->card->dev, in snd_cs4231_ebus_create()
2026 "cs4231-%d: Unable to enable EBUS play IRQ\n", dev); in snd_cs4231_ebus_create()
2027 return -EBUSY; in snd_cs4231_ebus_create()
2032 return -ENODEV; in snd_cs4231_ebus_create()
2055 sprintf(card->longname, "%s at 0x%llx, irq %d", in cs4231_ebus_probe()
2056 card->shortname, in cs4231_ebus_probe()
2057 op->resource[0].start, in cs4231_ebus_probe()
2058 op->archdata.irqs[0]); in cs4231_ebus_probe()
2073 if (of_node_name_eq(op->dev.of_node->parent, "ebus")) in cs4231_probe()
2077 if (of_node_name_eq(op->dev.of_node->parent, "sbus") || in cs4231_probe()
2078 of_node_name_eq(op->dev.of_node->parent, "sbi")) in cs4231_probe()
2081 return -ENODEV; in cs4231_probe()
2086 struct snd_cs4231 *chip = dev_get_drvdata(&op->dev); in cs4231_remove()
2088 snd_card_free(chip->card); in cs4231_remove()