/*
* Copyright (c) 2002 Valeriy E. Ushakov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* These are the register we get from the prom:
* - CS4231 registers
* - Playback EBus DMA controller
* - Capture EBus DMA controller
* - AUXIO audio register (codec powerdown)
*
* Map my registers in, if they aren't already in virtual
* address space.
*/
if (bus_space_map(ea->ea_bustag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
ea->ea_reg[0].size, 0, &bh) != 0) {
printf(": unable to map registers\n");
return;
}
if (bus_space_map(ea->ea_bustag,
#ifdef MSIIEP /* XXX: Krups */
/*
* XXX: map playback DMA registers
* (we just know where they are)
*/
BUS_ADDR(0x14, 0x702000), /* XXX: magic num */
EBUS_DMAC_SIZE,
#else
EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
ea->ea_reg[1].size,
#endif
0, &ebsc->sc_pdmareg) != 0)
{
printf(": unable to map playback DMA registers\n");
return;
}
if (bus_space_map(ea->ea_bustag,
#ifdef MSIIEP /* XXX: Krups */
/*
* XXX: map capture DMA registers
* (we just know where they are)
*/
BUS_ADDR(0x14, 0x704000), /* XXX: magic num */
EBUS_DMAC_SIZE,
#else
EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
ea->ea_reg[2].size,
#endif
0, &ebsc->sc_cdmareg) != 0)
{
printf(": unable to map capture DMA registers\n");
return;
}
ad1848_init_locks(&sc->sc_ad1848, IPL_SCHED);
/* establish interrupt channels */
for (i = 0; i < ea->ea_nintr; ++i)
bus_intr_establish(ea->ea_bustag,
ea->ea_intr[i], IPL_SCHED,
cs4231_ebus_intr, ebsc);
cs4231_common_attach(sc, self, bh);
printf("\n");
/* XXX: todo: move to cs4231_common_attach, pass hw_if as arg? */
audio_attach_mi(&audiocs_ebus_hw_if, sc, sc->sc_ad1848.sc_dev);
}
static int
cs4231_ebus_round_blocksize(void *addr, int blk, int mode,
const audio_params_t *param)
{
int sz;
/* we want to use DMA burst size of 16 words */
sz = blk & -64;
if (sz == 0)
sz = 64; /* zero is not a good blocksize */
return sz;
}
printf("cs4231regdump(%s): regs:", label);
/* XXX: dump ebus DMA and aux registers */
ad1848_dump_regs(&ebsc->sc_cs4231.sc_ad1848);
}
#endif /* AUDIO_DEBUG */
/* XXX: nothing CS4231-specific in this code... */
static int
cs4231_ebus_dma_reset(bus_space_tag_t dt, bus_space_handle_t dh)
{
u_int32_t csr;
int timo;
/* reset, also clear TC, just in case */
bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, EBDMA_RESET | EBDMA_TC);
for (timo = 50000; timo != 0; --timo) {
csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
if ((csr & (EBDMA_CYC_PEND | EBDMA_DRAIN)) == 0)
break;
}