22 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/module.h>
54 #define H2_BLOCK_SIZE 1024
55 #define H2_BUF_SIZE 16384
85 #define H2_MIX_OUTPUT_ATT 0
86 #define H2_MIX_INPUT_GAIN 1
100 #define H2_INDIRECT_WAIT(regs) while (hal2_read(®s->isr) & H2_ISR_TSTATUS);
102 #define H2_READ_ADDR(addr) (addr | (1<<7))
103 #define H2_WRITE_ADDR(addr) (addr)
123 ret = hal2_read(®s->
idr0) & 0xffff;
126 ret |= (hal2_read(®s->
idr0) & 0xffff) << 16;
134 hal2_write(val, ®s->
idr0);
135 hal2_write(0, ®s->
idr1);
136 hal2_write(0, ®s->
idr2);
137 hal2_write(0, ®s->
idr3);
142 static void hal2_i_write32(
struct snd_hal2 *hal2,
u16 addr,
u32 val)
146 hal2_write(val & 0xffff, ®s->
idr0);
147 hal2_write(val >> 16, ®s->
idr1);
148 hal2_write(0, ®s->
idr2);
149 hal2_write(0, ®s->
idr3);
160 hal2_write((hal2_read(®s->
idr0) & 0xffff) | bit, ®s->
idr0);
161 hal2_write(0, ®s->
idr1);
162 hal2_write(0, ®s->
idr2);
163 hal2_write(0, ®s->
idr3);
168 static void hal2_i_clearbit16(
struct snd_hal2 *hal2,
u16 addr,
u16 bit)
174 hal2_write((hal2_read(®s->
idr0) & 0xffff) & ~bit, ®s->
idr0);
175 hal2_write(0, ®s->
idr1);
176 hal2_write(0, ®s->
idr2);
177 hal2_write(0, ®s->
idr3);
182 static int hal2_gain_info(
struct snd_kcontrol *kcontrol,
223 ucontrol->
value.integer.value[0] =
l;
224 ucontrol->
value.integer.value[1] =
r;
236 l = ucontrol->
value.integer.value[0];
237 r = ucontrol->
value.integer.value[1];
265 .name =
"Headphone Playback Volume",
268 .info = hal2_gain_info,
269 .get = hal2_gain_get,
270 .put = hal2_gain_put,
275 .name =
"Mic Capture Volume",
278 .info = hal2_gain_info,
279 .get = hal2_gain_get,
280 .put = hal2_gain_put,
327 if (44100 % rate < 48000 % rate) {
328 mod = 4 * 44100 /
rate;
331 mod = 4 * 48000 /
rate;
342 static void hal2_set_dac_rate(
struct snd_hal2 *hal2)
344 unsigned int master = hal2->
dac.master;
346 int mod = hal2->
dac.mod;
348 hal2_i_write16(hal2,
H2I_BRES1_C1, (master == 44100) ? 1 : 0);
350 ((0xffff & (inc - mod - 1)) << 16) | inc);
353 static void hal2_set_adc_rate(
struct snd_hal2 *hal2)
355 unsigned int master = hal2->
adc.master;
356 int inc = hal2->
adc.inc;
357 int mod = hal2->
adc.mod;
359 hal2_i_write16(hal2,
H2I_BRES2_C1, (master == 44100) ? 1 : 0);
361 ((0xffff & (inc - mod - 1)) << 16) | inc);
364 static void hal2_setup_dac(
struct snd_hal2 *hal2)
366 unsigned int fifobeg, fifoend, highwater,
sample_size;
374 sample_size = 2 * hal2->
dac.voices;
377 highwater = (sample_size * 2) >> 1;
379 fifoend = (sample_size * 4) >> 3;
381 (highwater << 8) | (fifobeg << 16) | (fifoend << 24);
386 hal2_set_dac_rate(hal2);
397 static void hal2_setup_adc(
struct snd_hal2 *hal2)
399 unsigned int fifobeg, fifoend, highwater,
sample_size;
402 sample_size = 2 * hal2->
adc.voices;
403 highwater = (sample_size * 2) >> 1;
404 fifobeg = (4 * 4) >> 3;
405 fifoend = (4 * 4 + sample_size * 4) >> 3;
407 (highwater << 8) | (fifobeg << 16) | (fifoend << 24);
411 hal2_set_adc_rate(hal2);
422 static void hal2_start_dac(
struct snd_hal2 *hal2)
426 pbus->
pbus->pbdma_dptr = hal2->
dac.desc_dma;
432 static void hal2_start_adc(
struct snd_hal2 *hal2)
436 pbus->
pbus->pbdma_dptr = hal2->
adc.desc_dma;
442 static inline void hal2_stop_dac(
struct snd_hal2 *hal2)
448 static inline void hal2_stop_adc(
struct snd_hal2 *hal2)
453 static int hal2_alloc_dmabuf(
struct hal2_codec *codec)
468 codec->
buffer, buffer_dma);
474 for (i = 0; i <
count; i++) {
477 desc->
desc.pnext = (i == count - 1) ?
478 desc_dma : desc_dma + (i + 1) *
sizeof(
struct hal2_desc);
487 static void hal2_free_dmabuf(
struct hal2_codec *codec)
536 runtime->
hw = hal2_pcm_hw;
538 err = hal2_alloc_dmabuf(&hal2->
dac);
548 hal2_free_dmabuf(&hal2->
dac);
562 dac->
pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
564 hal2_setup_dac(hal2);
574 hal2->
dac.pcm_indirect.hw_io = hal2->
dac.buffer_dma;
575 hal2->
dac.pcm_indirect.hw_data = 0;
576 substream->
ops->ack(substream);
577 hal2_start_dac(hal2);
594 return snd_pcm_indirect_playback_pointer(substream, &dac->
pcm_indirect,
595 dac->
pbus.pbus->pbdma_bptr);
615 snd_pcm_indirect_playback_transfer(substream,
617 hal2_playback_transfer);
628 runtime->
hw = hal2_pcm_hw;
630 err = hal2_alloc_dmabuf(adc);
640 hal2_free_dmabuf(&hal2->
adc);
655 adc->
pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
657 hal2_setup_adc(hal2);
667 hal2->
adc.pcm_indirect.hw_io = hal2->
adc.buffer_dma;
668 hal2->
adc.pcm_indirect.hw_data = 0;
670 hal2_start_adc(hal2);
687 return snd_pcm_indirect_capture_pointer(substream, &adc->
pcm_indirect,
688 adc->
pbus.pbus->pbdma_bptr);
706 snd_pcm_indirect_capture_transfer(substream,
708 hal2_capture_transfer);
713 .open = hal2_playback_open,
714 .close = hal2_playback_close,
716 .hw_params = hal2_pcm_hw_params,
717 .hw_free = hal2_pcm_hw_free,
718 .prepare = hal2_playback_prepare,
719 .trigger = hal2_playback_trigger,
720 .pointer = hal2_playback_pointer,
721 .ack = hal2_playback_ack,
725 .open = hal2_capture_open,
726 .close = hal2_capture_close,
728 .hw_params = hal2_pcm_hw_params,
729 .hw_free = hal2_pcm_hw_free,
730 .prepare = hal2_capture_prepare,
731 .trigger = hal2_capture_trigger,
732 .pointer = hal2_capture_pointer,
733 .ack = hal2_capture_ack,
771 .dev_free = hal2_dev_free,
781 static int hal2_detect(
struct snd_hal2 *hal2)
787 hal2_write(0, &hal2->
ctl_regs->isr);
795 rev = hal2_read(&hal2->
ctl_regs->rev);
804 board, major, minor);
833 if (hal2_detect(hal2) < 0) {
838 hal2_init_codec(&hal2->
dac, hpc3, 0);
839 hal2_init_codec(&hal2->
adc, hpc3, 1);
849 #define HAL2_PBUS_DMACFG ((0 << HPC3_DMACFG_D3R_SHIFT) | \
850 (2 << HPC3_DMACFG_D4R_SHIFT) | \
851 (2 << HPC3_DMACFG_D5R_SHIFT) | \
852 (0 << HPC3_DMACFG_D3W_SHIFT) | \
853 (2 << HPC3_DMACFG_D4W_SHIFT) | \
854 (2 << HPC3_DMACFG_D5W_SHIFT) | \
856 HPC3_DMACFG_EVENHI | \
857 HPC3_DMACFG_RTIME | \
858 (8 << HPC3_DMACFG_BURST_SHIFT) | \
887 err = hal2_create(card, &chip);
894 err = hal2_pcm_create(chip);
899 err = hal2_mixer_create(chip);
916 platform_set_drvdata(pdev, card);
922 struct snd_card *card = platform_get_drvdata(pdev);
925 platform_set_drvdata(pdev,
NULL);