1*c6b8a0a4Sisaki /* $NetBSD: haltwo.c,v 1.26 2019/05/25 04:41:53 isaki Exp $ */
23111a2e6Slonewolf
33111a2e6Slonewolf /*
43111a2e6Slonewolf * Copyright (c) 2003 Ilpo Ruotsalainen
53111a2e6Slonewolf * All rights reserved.
63111a2e6Slonewolf *
73111a2e6Slonewolf * Redistribution and use in source and binary forms, with or without
83111a2e6Slonewolf * modification, are permitted provided that the following conditions
93111a2e6Slonewolf * are met:
103111a2e6Slonewolf * 1. Redistributions of source code must retain the above copyright
113111a2e6Slonewolf * notice, this list of conditions and the following disclaimer.
123111a2e6Slonewolf * 2. Redistributions in binary form must reproduce the above copyright
133111a2e6Slonewolf * notice, this list of conditions and the following disclaimer in the
143111a2e6Slonewolf * documentation and/or other materials provided with the distribution.
153111a2e6Slonewolf * 3. The name of the author may not be used to endorse or promote products
163111a2e6Slonewolf * derived from this software without specific prior written permission.
173111a2e6Slonewolf *
183111a2e6Slonewolf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
193111a2e6Slonewolf * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
203111a2e6Slonewolf * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
213111a2e6Slonewolf * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223111a2e6Slonewolf * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
233111a2e6Slonewolf * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243111a2e6Slonewolf * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
253111a2e6Slonewolf * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
263111a2e6Slonewolf * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
273111a2e6Slonewolf * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283111a2e6Slonewolf *
293111a2e6Slonewolf * <<Id: LICENSE_GC,v 1.1 2001/10/01 23:24:05 cgd Exp>>
303111a2e6Slonewolf */
313111a2e6Slonewolf
323111a2e6Slonewolf #include <sys/cdefs.h>
33*c6b8a0a4Sisaki __KERNEL_RCSID(0, "$NetBSD: haltwo.c,v 1.26 2019/05/25 04:41:53 isaki Exp $");
343111a2e6Slonewolf
353111a2e6Slonewolf #include <sys/param.h>
363111a2e6Slonewolf #include <sys/systm.h>
373111a2e6Slonewolf #include <sys/device.h>
383111a2e6Slonewolf #include <sys/audioio.h>
398a962f23Sjmcneill #include <sys/kmem.h>
40cf10107dSdyoung #include <sys/bus.h>
411426ceedSrumble #include <machine/sysconf.h>
423111a2e6Slonewolf
43e622eac4Sisaki #include <dev/audio/audio_if.h>
44e622eac4Sisaki
453111a2e6Slonewolf #include <sgimips/hpc/hpcvar.h>
463111a2e6Slonewolf #include <sgimips/hpc/hpcreg.h>
473111a2e6Slonewolf
483111a2e6Slonewolf #include <sgimips/hpc/haltworeg.h>
493111a2e6Slonewolf #include <sgimips/hpc/haltwovar.h>
503111a2e6Slonewolf
513111a2e6Slonewolf #ifdef AUDIO_DEBUG
523111a2e6Slonewolf #define DPRINTF(x) printf x
533111a2e6Slonewolf #else
543111a2e6Slonewolf #define DPRINTF(x)
553111a2e6Slonewolf #endif
563111a2e6Slonewolf
57e622eac4Sisaki static int haltwo_query_format(void *, audio_format_query_t *);
58e622eac4Sisaki static int haltwo_set_format(void *, int,
59e622eac4Sisaki const audio_params_t *, const audio_params_t *,
60e622eac4Sisaki audio_filter_reg_t *, audio_filter_reg_t *);
6123b5d914Skent static int haltwo_round_blocksize(void *, int, int, const audio_params_t *);
623111a2e6Slonewolf static int haltwo_halt_output(void *);
633111a2e6Slonewolf static int haltwo_halt_input(void *);
643111a2e6Slonewolf static int haltwo_getdev(void *, struct audio_device *);
653111a2e6Slonewolf static int haltwo_set_port(void *, mixer_ctrl_t *);
663111a2e6Slonewolf static int haltwo_get_port(void *, mixer_ctrl_t *);
673111a2e6Slonewolf static int haltwo_query_devinfo(void *, mixer_devinfo_t *);
688a962f23Sjmcneill static void *haltwo_malloc(void *, int, size_t);
698a962f23Sjmcneill static void haltwo_free(void *, void *, size_t);
703111a2e6Slonewolf static int haltwo_get_props(void *);
713111a2e6Slonewolf static int haltwo_trigger_output(void *, void *, void *, int, void (*)(void *),
7223b5d914Skent void *, const audio_params_t *);
733111a2e6Slonewolf static int haltwo_trigger_input(void *, void *, void *, int, void (*)(void *),
7423b5d914Skent void *, const audio_params_t *);
758a962f23Sjmcneill static void haltwo_get_locks(void *, kmutex_t **, kmutex_t **);
765d2638c2Stsutsui static bool haltwo_shutdown(device_t, int);
773111a2e6Slonewolf
7818f717bbSyamt static const struct audio_hw_if haltwo_hw_if = {
79e622eac4Sisaki .query_format = haltwo_query_format,
80e622eac4Sisaki .set_format = haltwo_set_format,
816291b134Sisaki .round_blocksize = haltwo_round_blocksize,
826291b134Sisaki .halt_output = haltwo_halt_output,
836291b134Sisaki .halt_input = haltwo_halt_input,
846291b134Sisaki .getdev = haltwo_getdev,
856291b134Sisaki .set_port = haltwo_set_port,
866291b134Sisaki .get_port = haltwo_get_port,
876291b134Sisaki .query_devinfo = haltwo_query_devinfo,
886291b134Sisaki .allocm = haltwo_malloc,
896291b134Sisaki .freem = haltwo_free,
906291b134Sisaki .get_props = haltwo_get_props,
916291b134Sisaki .trigger_output = haltwo_trigger_output,
926291b134Sisaki .trigger_input = haltwo_trigger_input,
936291b134Sisaki .get_locks = haltwo_get_locks,
943111a2e6Slonewolf };
953111a2e6Slonewolf
963111a2e6Slonewolf static const struct audio_device haltwo_device = {
973111a2e6Slonewolf "HAL2",
983111a2e6Slonewolf "",
993111a2e6Slonewolf "haltwo"
1003111a2e6Slonewolf };
1013111a2e6Slonewolf
102e622eac4Sisaki static const struct audio_format haltwo_formats = {
103e622eac4Sisaki .mode = AUMODE_PLAY,
104e622eac4Sisaki .encoding = AUDIO_ENCODING_SLINEAR_NE,
105e622eac4Sisaki .validbits = 16,
106e622eac4Sisaki .precision = 16,
107e622eac4Sisaki .channels = 2,
108e622eac4Sisaki .channel_mask = AUFMT_STEREO,
109e622eac4Sisaki .frequency_type = 2,
110e622eac4Sisaki .frequency = { 44100, 48000 },
111e622eac4Sisaki };
112e622eac4Sisaki #define HALTWO_NFORMATS __arraycount(haltwo_formats)
113e622eac4Sisaki
1148831804fStsutsui static int haltwo_match(device_t, cfdata_t, void *);
1158831804fStsutsui static void haltwo_attach(device_t, device_t, void *);
1163111a2e6Slonewolf static int haltwo_intr(void *);
1173111a2e6Slonewolf
1188831804fStsutsui CFATTACH_DECL_NEW(haltwo, sizeof(struct haltwo_softc),
1193111a2e6Slonewolf haltwo_match, haltwo_attach, NULL, NULL);
1203111a2e6Slonewolf
1213111a2e6Slonewolf #define haltwo_write(sc,type,off,val) \
1223111a2e6Slonewolf bus_space_write_4(sc->sc_st, sc->sc_##type##_sh, off, val)
1233111a2e6Slonewolf
1243111a2e6Slonewolf #define haltwo_read(sc,type,off) \
1253111a2e6Slonewolf bus_space_read_4(sc->sc_st, sc->sc_##type##_sh, off)
1263111a2e6Slonewolf
1273111a2e6Slonewolf static void
haltwo_write_indirect(struct haltwo_softc * sc,uint32_t ireg,uint16_t low,uint16_t high)1283111a2e6Slonewolf haltwo_write_indirect(struct haltwo_softc *sc, uint32_t ireg, uint16_t low,
1293111a2e6Slonewolf uint16_t high)
1303111a2e6Slonewolf {
131d330e7b6Stsutsui
1323111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_IDR0, low);
1333111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_IDR1, high);
1343111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_IDR2, 0);
1353111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_IDR3, 0);
1363111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_IAR, ireg);
1373111a2e6Slonewolf
1383111a2e6Slonewolf while (haltwo_read(sc, ctl, HAL2_REG_CTL_ISR) & HAL2_ISR_TSTATUS)
13993293b9eSkent continue;
1403111a2e6Slonewolf }
1413111a2e6Slonewolf
1423111a2e6Slonewolf static void
haltwo_read_indirect(struct haltwo_softc * sc,uint32_t ireg,uint16_t * low,uint16_t * high)1433111a2e6Slonewolf haltwo_read_indirect(struct haltwo_softc *sc, uint32_t ireg, uint16_t *low,
1443111a2e6Slonewolf uint16_t *high)
1453111a2e6Slonewolf {
146d330e7b6Stsutsui
1473111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_IAR,
1483111a2e6Slonewolf ireg | HAL2_IAR_READ);
1493111a2e6Slonewolf
1503111a2e6Slonewolf while (haltwo_read(sc, ctl, HAL2_REG_CTL_ISR) & HAL2_ISR_TSTATUS)
15193293b9eSkent continue;
1523111a2e6Slonewolf
1533111a2e6Slonewolf if (low)
1543111a2e6Slonewolf *low = haltwo_read(sc, ctl, HAL2_REG_CTL_IDR0);
1553111a2e6Slonewolf
1563111a2e6Slonewolf if (high)
1573111a2e6Slonewolf *high = haltwo_read(sc, ctl, HAL2_REG_CTL_IDR1);
1583111a2e6Slonewolf }
1593111a2e6Slonewolf
1603111a2e6Slonewolf static int
haltwo_init_codec(struct haltwo_softc * sc,struct haltwo_codec * codec)1613111a2e6Slonewolf haltwo_init_codec(struct haltwo_softc *sc, struct haltwo_codec *codec)
1623111a2e6Slonewolf {
1633111a2e6Slonewolf int err;
1643111a2e6Slonewolf int rseg;
16593293b9eSkent size_t allocsz;
1663111a2e6Slonewolf
16793293b9eSkent allocsz = sizeof(struct hpc_dma_desc) * HALTWO_MAX_DMASEGS;
1683111a2e6Slonewolf KASSERT(allocsz <= PAGE_SIZE);
1693111a2e6Slonewolf
1703111a2e6Slonewolf err = bus_dmamem_alloc(sc->sc_dma_tag, allocsz, 0, 0, &codec->dma_seg,
1713111a2e6Slonewolf 1, &rseg, BUS_DMA_NOWAIT);
1723111a2e6Slonewolf if (err)
1733111a2e6Slonewolf goto out;
1743111a2e6Slonewolf
1753111a2e6Slonewolf err = bus_dmamem_map(sc->sc_dma_tag, &codec->dma_seg, rseg, allocsz,
17653524e44Schristos (void **)&codec->dma_descs, BUS_DMA_NOWAIT);
1773111a2e6Slonewolf if (err)
1783111a2e6Slonewolf goto out_free;
1793111a2e6Slonewolf
1803111a2e6Slonewolf err = bus_dmamap_create(sc->sc_dma_tag, allocsz, 1, PAGE_SIZE, 0,
1813111a2e6Slonewolf BUS_DMA_NOWAIT, &codec->dma_map);
1823111a2e6Slonewolf if (err)
1833111a2e6Slonewolf goto out_free;
1843111a2e6Slonewolf
1853111a2e6Slonewolf err = bus_dmamap_load(sc->sc_dma_tag, codec->dma_map, codec->dma_descs,
1863111a2e6Slonewolf allocsz, NULL, BUS_DMA_NOWAIT);
1873111a2e6Slonewolf if (err)
1883111a2e6Slonewolf goto out_destroy;
1893111a2e6Slonewolf
1903111a2e6Slonewolf DPRINTF(("haltwo_init_codec: allocated %d descriptors (%d bytes)"
1913111a2e6Slonewolf " at %p\n", HALTWO_MAX_DMASEGS, allocsz, codec->dma_descs));
1923111a2e6Slonewolf
1933111a2e6Slonewolf memset(codec->dma_descs, 0, allocsz);
1943111a2e6Slonewolf
19593293b9eSkent return 0;
1963111a2e6Slonewolf
1973111a2e6Slonewolf out_destroy:
1983111a2e6Slonewolf bus_dmamap_destroy(sc->sc_dma_tag, codec->dma_map);
1993111a2e6Slonewolf out_free:
2003111a2e6Slonewolf bus_dmamem_free(sc->sc_dma_tag, &codec->dma_seg, rseg);
2013111a2e6Slonewolf out:
2023111a2e6Slonewolf DPRINTF(("haltwo_init_codec failed: %d\n",err));
2033111a2e6Slonewolf
20493293b9eSkent return err;
2053111a2e6Slonewolf }
2063111a2e6Slonewolf
2073111a2e6Slonewolf static void
haltwo_setup_dma(struct haltwo_softc * sc,struct haltwo_codec * codec,struct haltwo_dmabuf * dmabuf,size_t len,int blksize,void (* intr)(void *),void * intrarg)2083111a2e6Slonewolf haltwo_setup_dma(struct haltwo_softc *sc, struct haltwo_codec *codec,
2093111a2e6Slonewolf struct haltwo_dmabuf *dmabuf, size_t len, int blksize,
2103111a2e6Slonewolf void (*intr)(void *), void *intrarg)
2113111a2e6Slonewolf {
2123111a2e6Slonewolf int i;
2133111a2e6Slonewolf bus_dma_segment_t *segp;
2143111a2e6Slonewolf struct hpc_dma_desc *descp;
21593293b9eSkent int next_intr;
2163111a2e6Slonewolf
2173111a2e6Slonewolf KASSERT(len % blksize == 0);
2183111a2e6Slonewolf
21993293b9eSkent next_intr = blksize;
2203111a2e6Slonewolf codec->intr = intr;
2213111a2e6Slonewolf codec->intr_arg = intrarg;
2223111a2e6Slonewolf
2233111a2e6Slonewolf segp = dmabuf->dma_map->dm_segs;
2243111a2e6Slonewolf descp = codec->dma_descs;
2253111a2e6Slonewolf
2263111a2e6Slonewolf /* Build descriptor chain for looping DMA, triggering interrupt every
2273111a2e6Slonewolf * blksize bytes */
2283111a2e6Slonewolf for (i = 0; i < dmabuf->dma_map->dm_nsegs; i++) {
229bc577449Ssekiya descp->hpc3_hdd_bufptr = segp->ds_addr;
230bc577449Ssekiya descp->hpc3_hdd_ctl = segp->ds_len;
2313111a2e6Slonewolf
2323111a2e6Slonewolf KASSERT(next_intr >= segp->ds_len);
2333111a2e6Slonewolf
2343111a2e6Slonewolf if (next_intr == segp->ds_len) {
2353111a2e6Slonewolf /* Generate intr after this DMA buffer */
236801f5271Srumble descp->hpc3_hdd_ctl |= HPC3_HDD_CTL_INTR;
2373111a2e6Slonewolf next_intr = blksize;
238d330e7b6Stsutsui } else
2393111a2e6Slonewolf next_intr -= segp->ds_len;
2403111a2e6Slonewolf
2413111a2e6Slonewolf if (i < dmabuf->dma_map->dm_nsegs - 1)
2423111a2e6Slonewolf descp->hdd_descptr = codec->dma_seg.ds_addr +
2433111a2e6Slonewolf sizeof(struct hpc_dma_desc) * (i + 1);
2443111a2e6Slonewolf else
2453111a2e6Slonewolf descp->hdd_descptr = codec->dma_seg.ds_addr;
2463111a2e6Slonewolf
2473111a2e6Slonewolf DPRINTF(("haltwo_setup_dma: hdd_bufptr = %x hdd_ctl = %x"
248bc577449Ssekiya " hdd_descptr = %x\n", descp->hpc3_hdd_bufptr,
249bc577449Ssekiya descp->hpc3_hdd_ctl, descp->hdd_descptr));
2503111a2e6Slonewolf
2513111a2e6Slonewolf segp++;
2523111a2e6Slonewolf descp++;
2533111a2e6Slonewolf }
2543111a2e6Slonewolf
2553111a2e6Slonewolf bus_dmamap_sync(sc->sc_dma_tag, codec->dma_map, 0,
2563111a2e6Slonewolf codec->dma_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
2573111a2e6Slonewolf }
2583111a2e6Slonewolf
2593111a2e6Slonewolf static int
haltwo_match(device_t parent,cfdata_t cf,void * aux)2608831804fStsutsui haltwo_match(device_t parent, cfdata_t cf, void *aux)
2613111a2e6Slonewolf {
26293293b9eSkent struct hpc_attach_args *haa;
263fc6e81a8Srumble uint32_t rev;
2643111a2e6Slonewolf
26593293b9eSkent haa = aux;
2660baf5763Ssekiya if (strcmp(haa->ha_name, cf->cf_name))
26793293b9eSkent return 0;
268fc6e81a8Srumble
26903d59d87She if ( platform.badaddr((void *)(vaddr_t)(haa->ha_sh + haa->ha_devoff),
270f016e292Stsutsui sizeof(uint32_t)) )
2710baf5763Ssekiya return 0;
2720baf5763Ssekiya
2731426ceedSrumble if ( platform.badaddr(
27403d59d87She (void *)(vaddr_t)(haa->ha_sh + haa->ha_devoff + HAL2_REG_CTL_REV),
275f016e292Stsutsui sizeof(uint32_t)) )
276fc6e81a8Srumble return 0;
277fc6e81a8Srumble
278fc6e81a8Srumble rev = *(uint32_t *)MIPS_PHYS_TO_KSEG1(haa->ha_sh + haa->ha_devoff +
279fc6e81a8Srumble HAL2_REG_CTL_REV);
280fc6e81a8Srumble
281fc6e81a8Srumble /* This bit is inverted, the test is correct */
282fc6e81a8Srumble if (rev & HAL2_REV_AUDIO_PRESENT_N)
283fc6e81a8Srumble return 0;
284fc6e81a8Srumble
2850baf5763Ssekiya return 1;
2863111a2e6Slonewolf }
2873111a2e6Slonewolf
2883111a2e6Slonewolf static void
haltwo_attach(device_t parent,device_t self,void * aux)2898831804fStsutsui haltwo_attach(device_t parent, device_t self, void *aux)
2903111a2e6Slonewolf {
29193293b9eSkent struct haltwo_softc *sc;
29293293b9eSkent struct hpc_attach_args *haa;
2933111a2e6Slonewolf uint32_t rev;
2943111a2e6Slonewolf
2958831804fStsutsui sc = device_private(self);
29693293b9eSkent haa = aux;
2978831804fStsutsui sc->sc_dev = self;
2983111a2e6Slonewolf sc->sc_st = haa->ha_st;
2993111a2e6Slonewolf sc->sc_dma_tag = haa->ha_dmat;
3003111a2e6Slonewolf
3018a962f23Sjmcneill mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
3028de08fa9Smrg mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_AUDIO);
3038a962f23Sjmcneill
3043111a2e6Slonewolf if (bus_space_subregion(haa->ha_st, haa->ha_sh, haa->ha_devoff,
305801f5271Srumble HPC3_PBUS_CH0_DEVREGS_SIZE, &sc->sc_ctl_sh)) {
3063111a2e6Slonewolf aprint_error(": unable to map control registers\n");
3073111a2e6Slonewolf return;
3083111a2e6Slonewolf }
3093111a2e6Slonewolf
310801f5271Srumble if (bus_space_subregion(haa->ha_st, haa->ha_sh, HPC3_PBUS_CH2_DEVREGS,
311801f5271Srumble HPC3_PBUS_CH2_DEVREGS_SIZE, &sc->sc_vol_sh)) {
3123111a2e6Slonewolf aprint_error(": unable to map volume registers\n");
3133111a2e6Slonewolf return;
3143111a2e6Slonewolf }
3153111a2e6Slonewolf
3163111a2e6Slonewolf if (bus_space_subregion(haa->ha_st, haa->ha_sh, haa->ha_dmaoff,
317801f5271Srumble HPC3_PBUS_DMAREGS_SIZE, &sc->sc_dma_sh)) {
3183111a2e6Slonewolf aprint_error(": unable to map DMA registers\n");
3193111a2e6Slonewolf return;
3203111a2e6Slonewolf }
3213111a2e6Slonewolf
3223111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_ISR, 0);
3233111a2e6Slonewolf haltwo_write(sc, ctl, HAL2_REG_CTL_ISR,
3243111a2e6Slonewolf HAL2_ISR_GLOBAL_RESET_N | HAL2_ISR_CODEC_RESET_N);
3253111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_RELAY_C, HAL2_RELAY_C_STATE, 0);
3263111a2e6Slonewolf
3273111a2e6Slonewolf rev = haltwo_read(sc, ctl, HAL2_REG_CTL_REV);
3283111a2e6Slonewolf
3298de08fa9Smrg if (cpu_intr_establish(haa->ha_irq, IPL_AUDIO, haltwo_intr, sc)
3303111a2e6Slonewolf == NULL) {
3313111a2e6Slonewolf aprint_error(": unable to establish interrupt\n");
3323111a2e6Slonewolf return;
3333111a2e6Slonewolf }
3343111a2e6Slonewolf
3353111a2e6Slonewolf aprint_naive(": Audio controller\n");
3363111a2e6Slonewolf
3373111a2e6Slonewolf aprint_normal(": HAL2 revision %d.%d.%d\n", (rev & 0x7000) >> 12,
3383111a2e6Slonewolf (rev & 0x00F0) >> 4, rev & 0x000F);
3393111a2e6Slonewolf
3403111a2e6Slonewolf if (haltwo_init_codec(sc, &sc->sc_dac)) {
3413111a2e6Slonewolf aprint_error(
3423111a2e6Slonewolf "haltwo_attach: unable to create DMA descriptor list\n");
3433111a2e6Slonewolf return;
3443111a2e6Slonewolf }
3453111a2e6Slonewolf
3463111a2e6Slonewolf /* XXX Magic PBUS CFGDMA values from Linux HAL2 driver XXX */
347801f5271Srumble bus_space_write_4(haa->ha_st, haa->ha_sh, HPC3_PBUS_CH0_CFGDMA,
3483111a2e6Slonewolf 0x8208844);
349801f5271Srumble bus_space_write_4(haa->ha_st, haa->ha_sh, HPC3_PBUS_CH1_CFGDMA,
3503111a2e6Slonewolf 0x8208844);
3513111a2e6Slonewolf
3523111a2e6Slonewolf /* Unmute output */
3533111a2e6Slonewolf /* XXX Add mute/unmute support to mixer ops? XXX */
3543111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_DAC_C2, 0, 0);
3553111a2e6Slonewolf
3563111a2e6Slonewolf /* Set master volume to zero */
3573111a2e6Slonewolf sc->sc_vol_left = sc->sc_vol_right = 0;
3583111a2e6Slonewolf haltwo_write(sc, vol, HAL2_REG_VOL_LEFT, sc->sc_vol_left);
3593111a2e6Slonewolf haltwo_write(sc, vol, HAL2_REG_VOL_RIGHT, sc->sc_vol_right);
3603111a2e6Slonewolf
3618831804fStsutsui audio_attach_mi(&haltwo_hw_if, sc, self);
362c0b4306aStsutsui
3635d2638c2Stsutsui if (!pmf_device_register1(self, NULL, NULL, haltwo_shutdown))
364c0b4306aStsutsui aprint_error_dev(self,
3655d2638c2Stsutsui "couldn't establish power handler\n");
3663111a2e6Slonewolf }
3673111a2e6Slonewolf
3683111a2e6Slonewolf static int
haltwo_intr(void * v)3693111a2e6Slonewolf haltwo_intr(void *v)
3703111a2e6Slonewolf {
37193293b9eSkent struct haltwo_softc *sc;
37293293b9eSkent int ret;
3733111a2e6Slonewolf
37493293b9eSkent sc = v;
37593293b9eSkent ret = 0;
3768a962f23Sjmcneill
3778a962f23Sjmcneill mutex_spin_enter(&sc->sc_intr_lock);
3788a962f23Sjmcneill
379801f5271Srumble if (bus_space_read_4(sc->sc_st, sc->sc_dma_sh, HPC3_PBUS_CH0_CTL)
380801f5271Srumble & HPC3_PBUS_DMACTL_IRQ) {
3813111a2e6Slonewolf sc->sc_dac.intr(sc->sc_dac.intr_arg);
3823111a2e6Slonewolf
3833111a2e6Slonewolf ret = 1;
384d330e7b6Stsutsui } else
3853111a2e6Slonewolf DPRINTF(("haltwo_intr: Huh?\n"));
3863111a2e6Slonewolf
3878a962f23Sjmcneill mutex_spin_exit(&sc->sc_intr_lock);
3888a962f23Sjmcneill
38993293b9eSkent return ret;
3903111a2e6Slonewolf }
3913111a2e6Slonewolf
3923111a2e6Slonewolf static int
haltwo_query_format(void * v,audio_format_query_t * afp)393e622eac4Sisaki haltwo_query_format(void *v, audio_format_query_t *afp)
3943111a2e6Slonewolf {
395d330e7b6Stsutsui
396e622eac4Sisaki return audio_query_format(&haltwo_formats, 1, afp);
3973111a2e6Slonewolf }
3983111a2e6Slonewolf
3993111a2e6Slonewolf static int
haltwo_set_format(void * v,int setmode,const audio_params_t * play,const audio_params_t * rec,audio_filter_reg_t * pfil,audio_filter_reg_t * rfil)400e622eac4Sisaki haltwo_set_format(void *v, int setmode,
401e622eac4Sisaki const audio_params_t *play, const audio_params_t *rec,
402e622eac4Sisaki audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
4033111a2e6Slonewolf {
40493293b9eSkent struct haltwo_softc *sc;
405e622eac4Sisaki int inc;
4063111a2e6Slonewolf uint16_t tmp;
4073111a2e6Slonewolf
40893293b9eSkent sc = v;
40923b5d914Skent inc = 4;
4103111a2e6Slonewolf
4113111a2e6Slonewolf /* Setup samplerate to HW */
4123111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_BRES1_C1,
413e622eac4Sisaki play->sample_rate == 44100 ? 1 : 0, 0);
4143111a2e6Slonewolf /* XXX Documentation disagrees but this seems to work XXX */
415e622eac4Sisaki haltwo_write_indirect(sc, HAL2_IREG_BRES1_C2, inc, 0xFFFF);
4163111a2e6Slonewolf
4173111a2e6Slonewolf /* Setup endianness to HW */
4183111a2e6Slonewolf haltwo_read_indirect(sc, HAL2_IREG_DMA_END, &tmp, NULL);
41923b5d914Skent if (play->encoding == AUDIO_ENCODING_SLINEAR_LE)
4203111a2e6Slonewolf tmp |= HAL2_DMA_END_CODECTX;
4213111a2e6Slonewolf else
4223111a2e6Slonewolf tmp &= ~HAL2_DMA_END_CODECTX;
4233111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_DMA_END, tmp, 0);
4243111a2e6Slonewolf
4253111a2e6Slonewolf /* Set PBUS channel, Bresenham clock source, number of channels to HW */
4263111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_DAC_C1,
4273111a2e6Slonewolf (0 << HAL2_C1_DMA_SHIFT) |
4283111a2e6Slonewolf (1 << HAL2_C1_CLKID_SHIFT) |
42923b5d914Skent (play->channels << HAL2_C1_DATAT_SHIFT), 0);
4303111a2e6Slonewolf
431e622eac4Sisaki DPRINTF(("%s: hw_encoding = %d hw_channels = %d\n", __func__,
43223b5d914Skent play->encoding, play->channels));
4333111a2e6Slonewolf
43493293b9eSkent return 0;
4353111a2e6Slonewolf }
4363111a2e6Slonewolf
4373111a2e6Slonewolf static int
haltwo_round_blocksize(void * v,int blocksize,int mode,const audio_params_t * param)43823b5d914Skent haltwo_round_blocksize(void *v, int blocksize,
43923b5d914Skent int mode, const audio_params_t *param)
4403111a2e6Slonewolf {
441d330e7b6Stsutsui
4423111a2e6Slonewolf /* XXX Make this smarter and support DMA descriptor chaining XXX */
4433111a2e6Slonewolf /* XXX Rounding to nearest PAGE_SIZE might work? XXX */
4443111a2e6Slonewolf return PAGE_SIZE;
4453111a2e6Slonewolf }
4463111a2e6Slonewolf
4473111a2e6Slonewolf static int
haltwo_halt_output(void * v)4483111a2e6Slonewolf haltwo_halt_output(void *v)
4493111a2e6Slonewolf {
45093293b9eSkent struct haltwo_softc *sc;
4513111a2e6Slonewolf
45293293b9eSkent sc = v;
4533111a2e6Slonewolf /* Disable PBUS DMA */
454801f5271Srumble bus_space_write_4(sc->sc_st, sc->sc_dma_sh, HPC3_PBUS_CH0_CTL,
455801f5271Srumble HPC3_PBUS_DMACTL_ACT_LD);
4563111a2e6Slonewolf
45793293b9eSkent return 0;
4583111a2e6Slonewolf }
4593111a2e6Slonewolf
4603111a2e6Slonewolf static int
haltwo_halt_input(void * v)4613111a2e6Slonewolf haltwo_halt_input(void *v)
4623111a2e6Slonewolf {
463d330e7b6Stsutsui
46493293b9eSkent return ENXIO;
4653111a2e6Slonewolf }
4663111a2e6Slonewolf
4673111a2e6Slonewolf static int
haltwo_getdev(void * v,struct audio_device * dev)4683111a2e6Slonewolf haltwo_getdev(void *v, struct audio_device *dev)
4693111a2e6Slonewolf {
470d330e7b6Stsutsui
4713111a2e6Slonewolf *dev = haltwo_device;
47293293b9eSkent return 0;
4733111a2e6Slonewolf }
4743111a2e6Slonewolf
4753111a2e6Slonewolf static int
haltwo_set_port(void * v,mixer_ctrl_t * mc)4763111a2e6Slonewolf haltwo_set_port(void *v, mixer_ctrl_t *mc)
4773111a2e6Slonewolf {
47893293b9eSkent struct haltwo_softc *sc;
4793111a2e6Slonewolf int lval, rval;
4803111a2e6Slonewolf
4813111a2e6Slonewolf if (mc->type != AUDIO_MIXER_VALUE)
48293293b9eSkent return EINVAL;
4833111a2e6Slonewolf
4843111a2e6Slonewolf if (mc->un.value.num_channels == 1)
4853111a2e6Slonewolf lval = rval = mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
4863111a2e6Slonewolf else if (mc->un.value.num_channels == 2) {
4873111a2e6Slonewolf lval = mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
4883111a2e6Slonewolf rval = mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
4893111a2e6Slonewolf } else
49093293b9eSkent return EINVAL;
4913111a2e6Slonewolf
49293293b9eSkent sc = v;
4933111a2e6Slonewolf switch (mc->dev) {
4943111a2e6Slonewolf case HALTWO_MASTER_VOL:
4953111a2e6Slonewolf sc->sc_vol_left = lval;
4963111a2e6Slonewolf sc->sc_vol_right = rval;
4973111a2e6Slonewolf
4983111a2e6Slonewolf haltwo_write(sc, vol, HAL2_REG_VOL_LEFT,
4993111a2e6Slonewolf sc->sc_vol_left);
5003111a2e6Slonewolf haltwo_write(sc, vol, HAL2_REG_VOL_RIGHT,
5013111a2e6Slonewolf sc->sc_vol_right);
5023111a2e6Slonewolf break;
5033111a2e6Slonewolf
5043111a2e6Slonewolf default:
50593293b9eSkent return EINVAL;
5063111a2e6Slonewolf }
5073111a2e6Slonewolf
50893293b9eSkent return 0;
5093111a2e6Slonewolf }
5103111a2e6Slonewolf
5113111a2e6Slonewolf static int
haltwo_get_port(void * v,mixer_ctrl_t * mc)5123111a2e6Slonewolf haltwo_get_port(void *v, mixer_ctrl_t *mc)
5133111a2e6Slonewolf {
51493293b9eSkent struct haltwo_softc *sc;
5153111a2e6Slonewolf int l, r;
5163111a2e6Slonewolf
5173111a2e6Slonewolf switch (mc->dev) {
5183111a2e6Slonewolf case HALTWO_MASTER_VOL:
51993293b9eSkent sc = v;
5203111a2e6Slonewolf l = sc->sc_vol_left;
5213111a2e6Slonewolf r = sc->sc_vol_right;
5223111a2e6Slonewolf break;
5233111a2e6Slonewolf
5243111a2e6Slonewolf default:
52593293b9eSkent return EINVAL;
5263111a2e6Slonewolf }
5273111a2e6Slonewolf
5283111a2e6Slonewolf if (mc->un.value.num_channels == 1)
5293111a2e6Slonewolf mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r) / 2;
5303111a2e6Slonewolf else if (mc->un.value.num_channels == 2) {
5313111a2e6Slonewolf mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
5323111a2e6Slonewolf mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
5333111a2e6Slonewolf } else
53493293b9eSkent return EINVAL;
5353111a2e6Slonewolf
53693293b9eSkent return 0;
5373111a2e6Slonewolf }
5383111a2e6Slonewolf
5393111a2e6Slonewolf static int
haltwo_query_devinfo(void * v,mixer_devinfo_t * dev)5403111a2e6Slonewolf haltwo_query_devinfo(void *v, mixer_devinfo_t *dev)
5413111a2e6Slonewolf {
542d330e7b6Stsutsui
5433111a2e6Slonewolf switch (dev->index) {
5443111a2e6Slonewolf /* Mixer values */
5453111a2e6Slonewolf case HALTWO_MASTER_VOL:
5463111a2e6Slonewolf dev->type = AUDIO_MIXER_VALUE;
5473111a2e6Slonewolf dev->mixer_class = HALTWO_OUTPUT_CLASS;
5483111a2e6Slonewolf dev->prev = dev->next = AUDIO_MIXER_LAST;
5493111a2e6Slonewolf strcpy(dev->label.name, AudioNmaster);
5503111a2e6Slonewolf dev->un.v.num_channels = 2;
5519fc47191Smacallan dev->un.v.delta = 16;
5523111a2e6Slonewolf strcpy(dev->un.v.units.name, AudioNvolume);
5533111a2e6Slonewolf break;
5543111a2e6Slonewolf
5553111a2e6Slonewolf /* Mixer classes */
5563111a2e6Slonewolf case HALTWO_OUTPUT_CLASS:
5573111a2e6Slonewolf dev->type = AUDIO_MIXER_CLASS;
5583111a2e6Slonewolf dev->mixer_class = HALTWO_OUTPUT_CLASS;
5593111a2e6Slonewolf dev->next = dev->prev = AUDIO_MIXER_LAST;
5603111a2e6Slonewolf strcpy(dev->label.name, AudioCoutputs);
5613111a2e6Slonewolf break;
5623111a2e6Slonewolf
5633111a2e6Slonewolf default:
56493293b9eSkent return EINVAL;
5653111a2e6Slonewolf }
5663111a2e6Slonewolf
56793293b9eSkent return 0;
5683111a2e6Slonewolf }
5693111a2e6Slonewolf
5703111a2e6Slonewolf static int
haltwo_alloc_dmamem(struct haltwo_softc * sc,size_t size,struct haltwo_dmabuf * p)5713111a2e6Slonewolf haltwo_alloc_dmamem(struct haltwo_softc *sc, size_t size,
5723111a2e6Slonewolf struct haltwo_dmabuf *p)
5733111a2e6Slonewolf {
5743111a2e6Slonewolf int err;
5753111a2e6Slonewolf
5763111a2e6Slonewolf p->size = size;
5773111a2e6Slonewolf
5783111a2e6Slonewolf /* XXX Check align/boundary XXX */
5793111a2e6Slonewolf err = bus_dmamem_alloc(sc->sc_dma_tag, p->size, 0, 0, p->dma_segs,
5808a962f23Sjmcneill HALTWO_MAX_DMASEGS, &p->dma_segcount, BUS_DMA_WAITOK);
5813111a2e6Slonewolf if (err)
5823111a2e6Slonewolf goto out;
5833111a2e6Slonewolf
5843111a2e6Slonewolf /* XXX BUS_DMA_COHERENT? XXX */
5853111a2e6Slonewolf err = bus_dmamem_map(sc->sc_dma_tag, p->dma_segs, p->dma_segcount,
5868a962f23Sjmcneill p->size, &p->kern_addr, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
5873111a2e6Slonewolf if (err)
5883111a2e6Slonewolf goto out_free;
5893111a2e6Slonewolf
5903111a2e6Slonewolf /* XXX Just guessing ... XXX */
5913111a2e6Slonewolf err = bus_dmamap_create(sc->sc_dma_tag, p->size, HALTWO_MAX_DMASEGS,
5928a962f23Sjmcneill PAGE_SIZE, 0, BUS_DMA_WAITOK, &p->dma_map);
5933111a2e6Slonewolf if (err)
5943111a2e6Slonewolf goto out_free;
5953111a2e6Slonewolf
5963111a2e6Slonewolf err = bus_dmamap_load(sc->sc_dma_tag, p->dma_map, p->kern_addr,
5978a962f23Sjmcneill p->size, NULL, BUS_DMA_WAITOK);
5983111a2e6Slonewolf if (err)
5993111a2e6Slonewolf goto out_destroy;
6003111a2e6Slonewolf
6013111a2e6Slonewolf return 0;
6023111a2e6Slonewolf
6033111a2e6Slonewolf out_destroy:
6043111a2e6Slonewolf bus_dmamap_destroy(sc->sc_dma_tag, p->dma_map);
6053111a2e6Slonewolf out_free:
6063111a2e6Slonewolf bus_dmamem_free(sc->sc_dma_tag, p->dma_segs, p->dma_segcount);
6073111a2e6Slonewolf out:
6083111a2e6Slonewolf DPRINTF(("haltwo_alloc_dmamem failed: %d\n",err));
6093111a2e6Slonewolf
6103111a2e6Slonewolf return err;
6113111a2e6Slonewolf }
6123111a2e6Slonewolf
6133111a2e6Slonewolf static void *
haltwo_malloc(void * v,int direction,size_t size)6148a962f23Sjmcneill haltwo_malloc(void *v, int direction, size_t size)
6153111a2e6Slonewolf {
61693293b9eSkent struct haltwo_softc *sc;
6173111a2e6Slonewolf struct haltwo_dmabuf *p;
6183111a2e6Slonewolf
6193111a2e6Slonewolf DPRINTF(("haltwo_malloc size = %d\n", size));
62093293b9eSkent sc = v;
6218a962f23Sjmcneill p = kmem_alloc(sizeof(*p), KM_SLEEP);
6223111a2e6Slonewolf if (haltwo_alloc_dmamem(sc, size, p)) {
6238a962f23Sjmcneill kmem_free(p, sizeof(*p));
6248a962f23Sjmcneill return NULL;
6253111a2e6Slonewolf }
6263111a2e6Slonewolf
6273111a2e6Slonewolf p->next = sc->sc_dma_bufs;
6283111a2e6Slonewolf sc->sc_dma_bufs = p;
6293111a2e6Slonewolf
6303111a2e6Slonewolf return p->kern_addr;
6313111a2e6Slonewolf }
6323111a2e6Slonewolf
6333111a2e6Slonewolf static void
haltwo_free(void * v,void * addr,size_t size)6348a962f23Sjmcneill haltwo_free(void *v, void *addr, size_t size)
6353111a2e6Slonewolf {
63693293b9eSkent struct haltwo_softc *sc;
6373111a2e6Slonewolf struct haltwo_dmabuf *p, **pp;
6383111a2e6Slonewolf
63993293b9eSkent sc = v;
6403111a2e6Slonewolf for (pp = &sc->sc_dma_bufs; (p = *pp) != NULL; pp = &p->next) {
6413111a2e6Slonewolf if (p->kern_addr == addr) {
6423111a2e6Slonewolf *pp = p->next;
6438a962f23Sjmcneill kmem_free(p, sizeof(*p));
6443111a2e6Slonewolf return;
6453111a2e6Slonewolf }
6463111a2e6Slonewolf }
6473111a2e6Slonewolf
6483111a2e6Slonewolf panic("haltwo_free: buffer not in list");
6493111a2e6Slonewolf }
6503111a2e6Slonewolf
6513111a2e6Slonewolf static int
haltwo_get_props(void * v)6523111a2e6Slonewolf haltwo_get_props(void *v)
6533111a2e6Slonewolf {
654d330e7b6Stsutsui
655e622eac4Sisaki return AUDIO_PROP_PLAYBACK;
6563111a2e6Slonewolf }
6573111a2e6Slonewolf
6583111a2e6Slonewolf static int
haltwo_trigger_output(void * v,void * start,void * end,int blksize,void (* intr)(void *),void * intrarg,const audio_params_t * param)6593111a2e6Slonewolf haltwo_trigger_output(void *v, void *start, void *end, int blksize,
66023b5d914Skent void (*intr)(void *), void *intrarg, const audio_params_t *param)
6613111a2e6Slonewolf {
66293293b9eSkent struct haltwo_softc *sc;
6633111a2e6Slonewolf struct haltwo_dmabuf *p;
6643111a2e6Slonewolf uint16_t tmp;
6653111a2e6Slonewolf uint32_t ctrl;
6663111a2e6Slonewolf unsigned int fifobeg, fifoend, highwater;
6673111a2e6Slonewolf
6683111a2e6Slonewolf DPRINTF(("haltwo_trigger_output start = %p end = %p blksize = %d"
6693111a2e6Slonewolf " param = %p\n", start, end, blksize, param));
67093293b9eSkent sc = v;
6713111a2e6Slonewolf for (p = sc->sc_dma_bufs; p != NULL; p = p->next)
6723111a2e6Slonewolf if (p->kern_addr == start)
6733111a2e6Slonewolf break;
6743111a2e6Slonewolf
6753111a2e6Slonewolf if (p == NULL) {
6763111a2e6Slonewolf printf("haltwo_trigger_output: buffer not in list\n");
6773111a2e6Slonewolf
67893293b9eSkent return EINVAL;
6793111a2e6Slonewolf }
6803111a2e6Slonewolf
6813111a2e6Slonewolf /* Disable PBUS DMA */
682801f5271Srumble bus_space_write_4(sc->sc_st, sc->sc_dma_sh, HPC3_PBUS_CH0_CTL,
683801f5271Srumble HPC3_PBUS_DMACTL_ACT_LD);
6843111a2e6Slonewolf
6853111a2e6Slonewolf /* Disable HAL2 codec DMA */
6863111a2e6Slonewolf haltwo_read_indirect(sc, HAL2_IREG_DMA_PORT_EN, &tmp, NULL);
6873111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_DMA_PORT_EN,
6883111a2e6Slonewolf tmp & ~HAL2_DMA_PORT_EN_CODECTX, 0);
6893111a2e6Slonewolf
6903111a2e6Slonewolf haltwo_setup_dma(sc, &sc->sc_dac, p, (char *)end - (char *)start,
6913111a2e6Slonewolf blksize, intr, intrarg);
6923111a2e6Slonewolf
69323b5d914Skent highwater = (param->channels * 4) >> 1;
6943111a2e6Slonewolf fifobeg = 0;
69523b5d914Skent fifoend = (param->channels * 8) >> 3;
6963111a2e6Slonewolf
6973111a2e6Slonewolf DPRINTF(("haltwo_trigger_output: hw_channels = %d highwater = %d"
698*c6b8a0a4Sisaki " fifobeg = %d fifoend = %d\n", param->channels, highwater,
6993111a2e6Slonewolf fifobeg, fifoend));
7003111a2e6Slonewolf
701801f5271Srumble ctrl = HPC3_PBUS_DMACTL_RT
702801f5271Srumble | HPC3_PBUS_DMACTL_ACT_LD
703801f5271Srumble | (highwater << HPC3_PBUS_DMACTL_HIGHWATER_SHIFT)
704801f5271Srumble | (fifobeg << HPC3_PBUS_DMACTL_FIFOBEG_SHIFT)
705801f5271Srumble | (fifoend << HPC3_PBUS_DMACTL_FIFOEND_SHIFT);
7063111a2e6Slonewolf
7073111a2e6Slonewolf /* Using PBUS CH0 for DAC DMA */
7083111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_DMA_DRV, 1, 0);
7093111a2e6Slonewolf
7103111a2e6Slonewolf /* HAL2 is ready for action, now setup PBUS for DMA transfer */
711801f5271Srumble bus_space_write_4(sc->sc_st, sc->sc_dma_sh, HPC3_PBUS_CH0_DP,
7123111a2e6Slonewolf sc->sc_dac.dma_seg.ds_addr);
713801f5271Srumble bus_space_write_4(sc->sc_st, sc->sc_dma_sh, HPC3_PBUS_CH0_CTL,
714801f5271Srumble ctrl | HPC3_PBUS_DMACTL_ACT);
7153111a2e6Slonewolf
7163111a2e6Slonewolf /* Both HAL2 and PBUS have been setup, now start it up */
7173111a2e6Slonewolf haltwo_read_indirect(sc, HAL2_IREG_DMA_PORT_EN, &tmp, NULL);
7183111a2e6Slonewolf haltwo_write_indirect(sc, HAL2_IREG_DMA_PORT_EN,
7193111a2e6Slonewolf tmp | HAL2_DMA_PORT_EN_CODECTX, 0);
7203111a2e6Slonewolf
72193293b9eSkent return 0;
7223111a2e6Slonewolf }
7233111a2e6Slonewolf
7243111a2e6Slonewolf static int
haltwo_trigger_input(void * v,void * start,void * end,int blksize,void (* intr)(void *),void * intrarg,const audio_params_t * param)7253111a2e6Slonewolf haltwo_trigger_input(void *v, void *start, void *end, int blksize,
72623b5d914Skent void (*intr)(void *), void *intrarg, const audio_params_t *param)
7273111a2e6Slonewolf {
72893293b9eSkent struct haltwo_softc *sc;
7293111a2e6Slonewolf struct haltwo_dmabuf *p;
7303111a2e6Slonewolf
7313111a2e6Slonewolf DPRINTF(("haltwo_trigger_input start = %p end = %p blksize = %d\n",
7323111a2e6Slonewolf start, end, blksize));
73393293b9eSkent sc = v;
7343111a2e6Slonewolf for (p = sc->sc_dma_bufs; p != NULL; p = p->next)
7353111a2e6Slonewolf if (p->kern_addr == start)
7363111a2e6Slonewolf break;
7373111a2e6Slonewolf
7383111a2e6Slonewolf if (p == NULL) {
7393111a2e6Slonewolf printf("haltwo_trigger_input: buffer not in list\n");
7403111a2e6Slonewolf
74193293b9eSkent return EINVAL;
7423111a2e6Slonewolf }
7433111a2e6Slonewolf
7443111a2e6Slonewolf #if 0
7453111a2e6Slonewolf haltwo_setup_dma(sc, &sc->sc_adc, p, (char *)end - (char *)start,
7463111a2e6Slonewolf blksize, intr, intrarg);
7473111a2e6Slonewolf #endif
7483111a2e6Slonewolf
74993293b9eSkent return ENXIO;
7503111a2e6Slonewolf }
751c0b4306aStsutsui
7528a962f23Sjmcneill static void
haltwo_get_locks(void * v,kmutex_t ** intr,kmutex_t ** thread)7538a962f23Sjmcneill haltwo_get_locks(void *v, kmutex_t **intr, kmutex_t **thread)
7548a962f23Sjmcneill {
7558a962f23Sjmcneill struct haltwo_softc *sc;
7568a962f23Sjmcneill
7578a962f23Sjmcneill DPRINTF(("haltwo_get_locks\n"));
7588a962f23Sjmcneill sc = v;
7598a962f23Sjmcneill
7608a962f23Sjmcneill *intr = &sc->sc_intr_lock;
7618a962f23Sjmcneill *thread = &sc->sc_lock;
7628a962f23Sjmcneill }
7638a962f23Sjmcneill
7645d2638c2Stsutsui bool
haltwo_shutdown(device_t self,int howto)7655d2638c2Stsutsui haltwo_shutdown(device_t self, int howto)
766c0b4306aStsutsui {
7675d2638c2Stsutsui struct haltwo_softc *sc;
768c0b4306aStsutsui
7695d2638c2Stsutsui sc = device_private(self);
770c0b4306aStsutsui haltwo_write(sc, ctl, HAL2_REG_CTL_ISR, 0);
771c0b4306aStsutsui haltwo_write(sc, ctl, HAL2_REG_CTL_ISR,
772c0b4306aStsutsui HAL2_ISR_GLOBAL_RESET_N | HAL2_ISR_CODEC_RESET_N);
7735d2638c2Stsutsui
7745d2638c2Stsutsui return true;
775c0b4306aStsutsui }
776