add HDMI audio driver
This commit is contained in:
parent
5c4bf708f5
commit
a425fe6943
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: awin_hdmi.c,v 1.6 2014/11/10 18:18:09 jmcneill Exp $ */
|
||||
/* $NetBSD: awin_hdmi.c,v 1.7 2014/11/11 17:00:59 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -33,7 +33,7 @@
|
||||
#define AWIN_HDMI_PLL 3 /* PLL7 or PLL3 */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: awin_hdmi.c,v 1.6 2014/11/10 18:18:09 jmcneill Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: awin_hdmi.c,v 1.7 2014/11/11 17:00:59 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
@ -102,6 +102,7 @@ static void awin_hdmi_thread(void *);
|
||||
#if 0
|
||||
static int awin_hdmi_intr(void *);
|
||||
#endif
|
||||
|
||||
#if defined(DDB)
|
||||
void awin_hdmi_dump_regs(void);
|
||||
#endif
|
||||
@ -533,7 +534,8 @@ awin_hdmi_video_enable(struct awin_hdmi_softc *sc, bool enable)
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmi_set_videomode(struct awin_hdmi_softc *sc, const struct videomode *mode)
|
||||
awin_hdmi_set_videomode(struct awin_hdmi_softc *sc,
|
||||
const struct videomode *mode)
|
||||
{
|
||||
uint32_t val;
|
||||
const u_int dblscan_p = !!(mode->flags & VID_DBLSCAN);
|
||||
@ -598,6 +600,8 @@ awin_hdmi_set_videomode(struct awin_hdmi_softc *sc, const struct videomode *mode
|
||||
#endif
|
||||
|
||||
val = HDMI_READ(sc, AWIN_HDMI_VID_CTRL_REG);
|
||||
val |= __SHIFTIN(AWIN_HDMI_VID_CTRL_HDMI_MODE_HDMI,
|
||||
AWIN_HDMI_VID_CTRL_HDMI_MODE);
|
||||
if (dblscan_p) {
|
||||
val |= __SHIFTIN(AWIN_HDMI_VID_CTRL_REPEATER_SEL_2X,
|
||||
AWIN_HDMI_VID_CTRL_REPEATER_SEL);
|
||||
@ -651,13 +655,81 @@ awin_hdmi_set_videomode(struct awin_hdmi_softc *sc, const struct videomode *mode
|
||||
val |= __SHIFTIN(AWIN_HDMI_VID_TIMING_4_TX_CLOCK_NORMAL,
|
||||
AWIN_HDMI_VID_TIMING_4_TX_CLOCK);
|
||||
HDMI_WRITE(sc, AWIN_HDMI_VID_TIMING_4_REG, val);
|
||||
|
||||
/* Packet control */
|
||||
HDMI_WRITE(sc, AWIN_HDMI_PKT_CTRL0_REG, 0x00005321);
|
||||
HDMI_WRITE(sc, AWIN_HDMI_PKT_CTRL1_REG, 0x0000000f);
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmi_set_audiomode(struct awin_hdmi_softc *sc, const struct videomode *mode)
|
||||
awin_hdmi_set_audiomode(struct awin_hdmi_softc *sc,
|
||||
const struct videomode *mode)
|
||||
{
|
||||
/* TODO */
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_CTRL_REG, 0);
|
||||
uint32_t cts, n, val;
|
||||
|
||||
/*
|
||||
* Before changing audio parameters, disable and reset the
|
||||
* audio module. Wait for the soft reset bit to clear before
|
||||
* configuring the audio parameters.
|
||||
*/
|
||||
val = HDMI_READ(sc, AWIN_HDMI_AUD_CTRL_REG);
|
||||
val &= ~AWIN_HDMI_AUD_CTRL_EN;
|
||||
val |= AWIN_HDMI_AUD_CTRL_RST;
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_CTRL_REG, val);
|
||||
do {
|
||||
val = HDMI_READ(sc, AWIN_HDMI_AUD_CTRL_REG);
|
||||
} while (val & AWIN_HDMI_AUD_CTRL_RST);
|
||||
|
||||
/* DMA & FIFO control */
|
||||
val = HDMI_READ(sc, AWIN_HDMI_ADMA_CTRL_REG);
|
||||
val |= AWIN_HDMI_ADMA_CTRL_SRC_DMA_MODE; /* NDMA */
|
||||
val &= ~AWIN_HDMI_ADMA_CTRL_SRC_DMA_SAMPLE_RATE;
|
||||
val &= ~AWIN_HDMI_ADMA_CTRL_SRC_SAMPLE_LAYOUT;
|
||||
val &= ~AWIN_HDMI_ADMA_CTRL_SRC_WORD_LEN;
|
||||
val &= ~AWIN_HDMI_ADMA_CTRL_DATA_SEL;
|
||||
HDMI_WRITE(sc, AWIN_HDMI_ADMA_CTRL_REG, val);
|
||||
|
||||
/* Audio format control */
|
||||
val = HDMI_READ(sc, AWIN_HDMI_AUD_FMT_REG);
|
||||
val &= ~AWIN_HDMI_AUD_FMT_SRC_SEL;
|
||||
val &= ~AWIN_HDMI_AUD_FMT_SEL;
|
||||
val &= ~AWIN_HDMI_AUD_FMT_DSD_FMT;
|
||||
val &= ~AWIN_HDMI_AUD_FMT_LAYOUT;
|
||||
val &= ~AWIN_HDMI_AUD_FMT_SRC_CH_CFG;
|
||||
val |= __SHIFTIN(1, AWIN_HDMI_AUD_FMT_SRC_CH_CFG);
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_FMT_REG, val);
|
||||
|
||||
/* PCM control (channel map) */
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_PCM_CTRL_REG, 0x76543210);
|
||||
|
||||
/* Clock setup */
|
||||
n = 6144; /* 48 kHz */
|
||||
cts = ((mode->dot_clock * 10) * (n / 128)) / 480;
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_CTS_REG, cts);
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_N_REG, n);
|
||||
|
||||
/* Audio PCM channel status 0 */
|
||||
val = __SHIFTIN(AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_48,
|
||||
AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ);
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_CH_STATUS0_REG, val);
|
||||
|
||||
/* Audio PCM channel status 1 */
|
||||
val = HDMI_READ(sc, AWIN_HDMI_AUD_CH_STATUS1_REG);
|
||||
val &= ~AWIN_HDMI_AUD_CH_STATUS1_CGMS_A;
|
||||
val &= ~AWIN_HDMI_AUD_CH_STATUS1_ORIGINAL_FS;
|
||||
val &= ~AWIN_HDMI_AUD_CH_STATUS1_WORD_LEN;
|
||||
val |= __SHIFTIN(5, AWIN_HDMI_AUD_CH_STATUS1_WORD_LEN);
|
||||
val |= AWIN_HDMI_AUD_CH_STATUS1_WORD_LEN_MAX;
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_CH_STATUS1_REG, val);
|
||||
|
||||
/* Re-enable */
|
||||
val = HDMI_READ(sc, AWIN_HDMI_AUD_CTRL_REG);
|
||||
val |= AWIN_HDMI_AUD_CTRL_EN;
|
||||
HDMI_WRITE(sc, AWIN_HDMI_AUD_CTRL_REG, val);
|
||||
|
||||
#if defined(DDB)
|
||||
awin_hdmi_dump_regs();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
@ -698,7 +770,7 @@ awin_hdmi_intr(void *priv)
|
||||
uint32_t intsts;
|
||||
|
||||
intsts = HDMI_READ(sc, AWIN_HDMI_INT_STATUS_REG);
|
||||
if (!intsts)
|
||||
if (!(intsts & 0x73))
|
||||
return 0;
|
||||
|
||||
HDMI_WRITE(sc, AWIN_HDMI_INT_STATUS_REG, intsts);
|
||||
|
647
sys/arch/arm/allwinner/awin_hdmiaudio.c
Normal file
647
sys/arch/arm/allwinner/awin_hdmiaudio.c
Normal file
@ -0,0 +1,647 @@
|
||||
/* $NetBSD: awin_hdmiaudio.c,v 1.1 2014/11/11 17:00:59 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: awin_hdmiaudio.c,v 1.1 2014/11/11 17:00:59 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/intr.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#include <sys/audioio.h>
|
||||
#include <dev/audio_if.h>
|
||||
#include <dev/auconv.h>
|
||||
|
||||
#include <arm/allwinner/awin_reg.h>
|
||||
#include <arm/allwinner/awin_var.h>
|
||||
|
||||
struct awin_hdmiaudio_dma {
|
||||
LIST_ENTRY(awin_hdmiaudio_dma) dma_list;
|
||||
bus_dmamap_t dma_map;
|
||||
void *dma_addr;
|
||||
size_t dma_size;
|
||||
bus_dma_segment_t dma_segs[1];
|
||||
int dma_nsegs;
|
||||
};
|
||||
|
||||
struct awin_hdmiaudio_softc {
|
||||
device_t sc_dev;
|
||||
device_t sc_audiodev;
|
||||
|
||||
bus_space_tag_t sc_bst;
|
||||
bus_space_handle_t sc_bsh;
|
||||
bus_dma_tag_t sc_dmat;
|
||||
|
||||
uint32_t sc_ver;
|
||||
|
||||
LIST_HEAD(, awin_hdmiaudio_dma) sc_dmalist;
|
||||
|
||||
uint8_t sc_drqtype_hdmiaudio;
|
||||
uint8_t sc_drqtype_sdram;
|
||||
|
||||
kmutex_t sc_lock;
|
||||
kmutex_t sc_intr_lock;
|
||||
|
||||
struct audio_format sc_format;
|
||||
struct audio_encoding_set *sc_encodings;
|
||||
|
||||
audio_params_t sc_pparam;
|
||||
struct awin_dma_channel *sc_pdma;
|
||||
void (*sc_pint)(void *);
|
||||
void *sc_pintarg;
|
||||
bus_addr_t sc_pstart;
|
||||
bus_addr_t sc_pend;
|
||||
bus_addr_t sc_pcur;
|
||||
int sc_pblksize;
|
||||
};
|
||||
|
||||
static int awin_hdmiaudio_match(device_t, cfdata_t, void *);
|
||||
static void awin_hdmiaudio_attach(device_t, device_t, void *);
|
||||
static int awin_hdmiaudio_rescan(device_t, const char *, const int *);
|
||||
static void awin_hdmiaudio_childdet(device_t, device_t);
|
||||
|
||||
static int awin_hdmiaudio_allocdma(struct awin_hdmiaudio_softc *, size_t,
|
||||
size_t, struct awin_hdmiaudio_dma *);
|
||||
static void awin_hdmiaudio_freedma(struct awin_hdmiaudio_softc *,
|
||||
struct awin_hdmiaudio_dma *);
|
||||
|
||||
static void awin_hdmiaudio_pint(void *);
|
||||
static int awin_hdmiaudio_play(struct awin_hdmiaudio_softc *);
|
||||
|
||||
#if defined(DDB)
|
||||
void awin_hdmiaudio_dump_regs(void);
|
||||
#endif
|
||||
|
||||
static int awin_hdmiaudio_open(void *, int);
|
||||
static void awin_hdmiaudio_close(void *);
|
||||
static int awin_hdmiaudio_drain(void *);
|
||||
static int awin_hdmiaudio_query_encoding(void *, struct audio_encoding *);
|
||||
static int awin_hdmiaudio_set_params(void *, int, int,
|
||||
audio_params_t *, audio_params_t *,
|
||||
stream_filter_list_t *,
|
||||
stream_filter_list_t *);
|
||||
static int awin_hdmiaudio_halt_output(void *);
|
||||
static int awin_hdmiaudio_halt_input(void *);
|
||||
static int awin_hdmiaudio_set_port(void *, mixer_ctrl_t *);
|
||||
static int awin_hdmiaudio_get_port(void *, mixer_ctrl_t *);
|
||||
static int awin_hdmiaudio_query_devinfo(void *, mixer_devinfo_t *);
|
||||
static void * awin_hdmiaudio_allocm(void *, int, size_t);
|
||||
static void awin_hdmiaudio_freem(void *, void *, size_t);
|
||||
static paddr_t awin_hdmiaudio_mappage(void *, void *, off_t, int);
|
||||
static int awin_hdmiaudio_getdev(void *, struct audio_device *);
|
||||
static int awin_hdmiaudio_get_props(void *);
|
||||
static int awin_hdmiaudio_round_blocksize(void *, int, int,
|
||||
const audio_params_t *);
|
||||
static size_t awin_hdmiaudio_round_buffersize(void *, int, size_t);
|
||||
static int awin_hdmiaudio_trigger_output(void *, void *, void *, int,
|
||||
void (*)(void *), void *,
|
||||
const audio_params_t *);
|
||||
static int awin_hdmiaudio_trigger_input(void *, void *, void *, int,
|
||||
void (*)(void *), void *,
|
||||
const audio_params_t *);
|
||||
static void awin_hdmiaudio_get_locks(void *, kmutex_t **, kmutex_t **);
|
||||
|
||||
static const struct audio_hw_if awin_hdmiaudio_hw_if = {
|
||||
.open = awin_hdmiaudio_open,
|
||||
.close = awin_hdmiaudio_close,
|
||||
.drain = awin_hdmiaudio_drain,
|
||||
.query_encoding = awin_hdmiaudio_query_encoding,
|
||||
.set_params = awin_hdmiaudio_set_params,
|
||||
.halt_output = awin_hdmiaudio_halt_output,
|
||||
.halt_input = awin_hdmiaudio_halt_input,
|
||||
.allocm = awin_hdmiaudio_allocm,
|
||||
.freem = awin_hdmiaudio_freem,
|
||||
.mappage = awin_hdmiaudio_mappage,
|
||||
.getdev = awin_hdmiaudio_getdev,
|
||||
.set_port = awin_hdmiaudio_set_port,
|
||||
.get_port = awin_hdmiaudio_get_port,
|
||||
.query_devinfo = awin_hdmiaudio_query_devinfo,
|
||||
.get_props = awin_hdmiaudio_get_props,
|
||||
.round_blocksize = awin_hdmiaudio_round_blocksize,
|
||||
.round_buffersize = awin_hdmiaudio_round_buffersize,
|
||||
.trigger_output = awin_hdmiaudio_trigger_output,
|
||||
.trigger_input = awin_hdmiaudio_trigger_input,
|
||||
.get_locks = awin_hdmiaudio_get_locks,
|
||||
};
|
||||
|
||||
enum {
|
||||
HDMIAUDIO_OUTPUT_CLASS,
|
||||
HDMIAUDIO_INPUT_CLASS,
|
||||
HDMIAUDIO_OUTPUT_MASTER_VOLUME,
|
||||
HDMIAUDIO_INPUT_DHDMIAUDIO_VOLUME,
|
||||
HDMIAUDIO_ENUM_LAST
|
||||
};
|
||||
|
||||
CFATTACH_DECL2_NEW(awin_hdmiaudio, sizeof(struct awin_hdmiaudio_softc),
|
||||
awin_hdmiaudio_match, awin_hdmiaudio_attach, NULL, NULL,
|
||||
awin_hdmiaudio_rescan, awin_hdmiaudio_childdet);
|
||||
|
||||
#define HDMIAUDIO_WRITE(sc, reg, val) \
|
||||
bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
|
||||
#define HDMIAUDIO_READ(sc, reg) \
|
||||
bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_match(device_t parent, cfdata_t cf, void *aux)
|
||||
{
|
||||
struct awinio_attach_args * const aio = aux;
|
||||
const struct awin_locators * const loc = &aio->aio_loc;
|
||||
|
||||
if (strcmp(cf->cf_name, loc->loc_name))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_attach(device_t parent, device_t self, void *aux)
|
||||
{
|
||||
struct awin_hdmiaudio_softc * const sc = device_private(self);
|
||||
struct awinio_attach_args * const aio = aux;
|
||||
const struct awin_locators * const loc = &aio->aio_loc;
|
||||
int error;
|
||||
|
||||
sc->sc_dev = self;
|
||||
sc->sc_bst = aio->aio_core_bst;
|
||||
sc->sc_dmat = aio->aio_dmat;
|
||||
LIST_INIT(&sc->sc_dmalist);
|
||||
bus_space_subregion(sc->sc_bst, aio->aio_core_bsh,
|
||||
loc->loc_offset, loc->loc_size, &sc->sc_bsh);
|
||||
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
|
||||
|
||||
sc->sc_ver = HDMIAUDIO_READ(sc, AWIN_HDMI_VERSION_ID_REG);
|
||||
|
||||
const int vmaj = __SHIFTOUT(sc->sc_ver, AWIN_HDMI_VERSION_ID_H);
|
||||
const int vmin = __SHIFTOUT(sc->sc_ver, AWIN_HDMI_VERSION_ID_L);
|
||||
|
||||
aprint_naive("\n");
|
||||
aprint_normal(": HDMI %d.%d\n", vmaj, vmin);
|
||||
|
||||
sc->sc_drqtype_hdmiaudio = awin_chip_id() == AWIN_CHIP_ID_A31 ?
|
||||
AWIN_A31_DMA_DRQ_TYPE_HDMIAUDIO :
|
||||
AWIN_DDMA_CTL_DRQ_HDMI_AUDIO;
|
||||
sc->sc_drqtype_sdram = awin_chip_id() == AWIN_CHIP_ID_A31 ?
|
||||
AWIN_A31_DMA_DRQ_TYPE_SDRAM :
|
||||
AWIN_DDMA_CTL_DRQ_SDRAM;
|
||||
|
||||
sc->sc_pdma = awin_dma_alloc("hdmiaudio", awin_hdmiaudio_pint, sc);
|
||||
if (sc->sc_pdma == NULL) {
|
||||
aprint_error_dev(self, "couldn't allocate play DMA channel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sc->sc_format.mode = AUMODE_PLAY|AUMODE_RECORD;
|
||||
sc->sc_format.encoding = AUDIO_ENCODING_SLINEAR_LE;
|
||||
sc->sc_format.validbits = 16;
|
||||
sc->sc_format.precision = 16;
|
||||
sc->sc_format.channels = 2;
|
||||
sc->sc_format.channel_mask = AUFMT_STEREO;
|
||||
sc->sc_format.frequency_type = 0;
|
||||
sc->sc_format.frequency[0] = sc->sc_format.frequency[1] = 48000;
|
||||
|
||||
error = auconv_create_encodings(&sc->sc_format, 1, &sc->sc_encodings);
|
||||
if (error) {
|
||||
aprint_error_dev(self, "couldn't create encodings (error=%d)\n",
|
||||
error);
|
||||
return;
|
||||
}
|
||||
|
||||
awin_hdmiaudio_rescan(self, NULL, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_rescan(device_t self, const char *ifattr, const int *locs)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = device_private(self);
|
||||
|
||||
if (ifattr_match(ifattr, "audiobus") && sc->sc_audiodev == NULL) {
|
||||
if (sc->sc_encodings == NULL)
|
||||
return EIO;
|
||||
sc->sc_audiodev = audio_attach_mi(&awin_hdmiaudio_hw_if,
|
||||
sc, sc->sc_dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_childdet(device_t self, device_t child)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = device_private(self);
|
||||
|
||||
if (sc->sc_audiodev == child)
|
||||
sc->sc_audiodev = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_allocdma(struct awin_hdmiaudio_softc *sc, size_t size, size_t align,
|
||||
struct awin_hdmiaudio_dma *dma)
|
||||
{
|
||||
int error;
|
||||
|
||||
dma->dma_size = size;
|
||||
error = bus_dmamem_alloc(sc->sc_dmat, dma->dma_size, align, 0,
|
||||
dma->dma_segs, 1, &dma->dma_nsegs, BUS_DMA_WAITOK);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = bus_dmamem_map(sc->sc_dmat, dma->dma_segs, dma->dma_nsegs,
|
||||
dma->dma_size, &dma->dma_addr, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
|
||||
if (error)
|
||||
goto free;
|
||||
|
||||
error = bus_dmamap_create(sc->sc_dmat, dma->dma_size, dma->dma_nsegs,
|
||||
dma->dma_size, 0, BUS_DMA_WAITOK, &dma->dma_map);
|
||||
if (error)
|
||||
goto unmap;
|
||||
|
||||
error = bus_dmamap_load(sc->sc_dmat, dma->dma_map, dma->dma_addr,
|
||||
dma->dma_size, NULL, BUS_DMA_WAITOK);
|
||||
if (error)
|
||||
goto destroy;
|
||||
|
||||
return 0;
|
||||
|
||||
destroy:
|
||||
bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
|
||||
unmap:
|
||||
bus_dmamem_unmap(sc->sc_dmat, dma->dma_addr, dma->dma_size);
|
||||
free:
|
||||
bus_dmamem_free(sc->sc_dmat, dma->dma_segs, dma->dma_nsegs);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_freedma(struct awin_hdmiaudio_softc *sc, struct awin_hdmiaudio_dma *dma)
|
||||
{
|
||||
bus_dmamap_unload(sc->sc_dmat, dma->dma_map);
|
||||
bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
|
||||
bus_dmamem_unmap(sc->sc_dmat, dma->dma_addr, dma->dma_size);
|
||||
bus_dmamem_free(sc->sc_dmat, dma->dma_segs, dma->dma_nsegs);
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_pint(void *priv)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
|
||||
mutex_enter(&sc->sc_intr_lock);
|
||||
if (sc->sc_pint == NULL) {
|
||||
mutex_exit(&sc->sc_intr_lock);
|
||||
return;
|
||||
}
|
||||
sc->sc_pint(sc->sc_pintarg);
|
||||
mutex_exit(&sc->sc_intr_lock);
|
||||
|
||||
awin_hdmiaudio_play(sc);
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_play(struct awin_hdmiaudio_softc *sc)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = awin_dma_transfer(sc->sc_pdma, sc->sc_pcur,
|
||||
AWIN_CORE_PBASE + AWIN_HDMI_OFFSET + AWIN_HDMI_AUX_TX_FIFO_REG,
|
||||
sc->sc_pblksize);
|
||||
if (error) {
|
||||
device_printf(sc->sc_dev, "failed to transfer DMA; error %d\n",
|
||||
error);
|
||||
return error;
|
||||
}
|
||||
|
||||
sc->sc_pcur += sc->sc_pblksize;
|
||||
if (sc->sc_pcur >= sc->sc_pend)
|
||||
sc->sc_pcur = sc->sc_pstart;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_open(void *priv, int flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_close(void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_drain(void *priv)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
uint32_t val;
|
||||
|
||||
val = HDMIAUDIO_READ(sc, AWIN_HDMI_ADMA_CTRL_REG);
|
||||
val |= AWIN_HDMI_ADMA_CTRL_FIFO_CLEAR;
|
||||
HDMIAUDIO_WRITE(sc, AWIN_HDMI_ADMA_CTRL_REG, val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_query_encoding(void *priv, struct audio_encoding *ae)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
|
||||
return auconv_query_encoding(sc->sc_encodings, ae);
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_set_params(void *priv, int setmode, int usemode,
|
||||
audio_params_t *play, audio_params_t *rec,
|
||||
stream_filter_list_t *pfil, stream_filter_list_t *rfil)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
int index;
|
||||
|
||||
if (play && (setmode & AUMODE_PLAY)) {
|
||||
index = auconv_set_converter(&sc->sc_format, 1,
|
||||
AUMODE_PLAY, play, true, pfil);
|
||||
if (index < 0)
|
||||
return EINVAL;
|
||||
sc->sc_pparam = pfil->req_size > 0 ?
|
||||
pfil->filters[0].param :
|
||||
*play;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_halt_output(void *priv)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
|
||||
awin_dma_halt(sc->sc_pdma);
|
||||
|
||||
sc->sc_pint = NULL;
|
||||
sc->sc_pintarg = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_halt_input(void *priv)
|
||||
{
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_set_port(void *priv, mixer_ctrl_t *mc)
|
||||
{
|
||||
switch (mc->dev) {
|
||||
case HDMIAUDIO_OUTPUT_MASTER_VOLUME:
|
||||
case HDMIAUDIO_INPUT_DHDMIAUDIO_VOLUME:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_get_port(void *priv, mixer_ctrl_t *mc)
|
||||
{
|
||||
switch (mc->dev) {
|
||||
case HDMIAUDIO_OUTPUT_MASTER_VOLUME:
|
||||
case HDMIAUDIO_INPUT_DHDMIAUDIO_VOLUME:
|
||||
mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = 255;
|
||||
mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 255;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_query_devinfo(void *priv, mixer_devinfo_t *di)
|
||||
{
|
||||
switch (di->index) {
|
||||
case HDMIAUDIO_OUTPUT_CLASS:
|
||||
di->mixer_class = HDMIAUDIO_OUTPUT_CLASS;
|
||||
strcpy(di->label.name, AudioCoutputs);
|
||||
di->type = AUDIO_MIXER_CLASS;
|
||||
di->next = di->prev = AUDIO_MIXER_LAST;
|
||||
return 0;
|
||||
case HDMIAUDIO_INPUT_CLASS:
|
||||
di->mixer_class = HDMIAUDIO_INPUT_CLASS;
|
||||
strcpy(di->label.name, AudioCinputs);
|
||||
di->type = AUDIO_MIXER_CLASS;
|
||||
di->next = di->prev = AUDIO_MIXER_LAST;
|
||||
return 0;
|
||||
case HDMIAUDIO_OUTPUT_MASTER_VOLUME:
|
||||
di->mixer_class = HDMIAUDIO_OUTPUT_CLASS;
|
||||
strcpy(di->label.name, AudioNmaster);
|
||||
di->type = AUDIO_MIXER_VALUE;
|
||||
di->next = di->prev = AUDIO_MIXER_LAST;
|
||||
di->un.v.num_channels = 2;
|
||||
strcpy(di->un.v.units.name, AudioNvolume);
|
||||
return 0;
|
||||
case HDMIAUDIO_INPUT_DHDMIAUDIO_VOLUME:
|
||||
di->mixer_class = HDMIAUDIO_INPUT_CLASS;
|
||||
strcpy(di->label.name, AudioNdac);
|
||||
di->type = AUDIO_MIXER_VALUE;
|
||||
di->next = di->prev = AUDIO_MIXER_LAST;
|
||||
di->un.v.num_channels = 2;
|
||||
strcpy(di->un.v.units.name, AudioNvolume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
static void *
|
||||
awin_hdmiaudio_allocm(void *priv, int dir, size_t size)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
struct awin_hdmiaudio_dma *dma;
|
||||
int error;
|
||||
|
||||
dma = kmem_alloc(sizeof(*dma), KM_SLEEP);
|
||||
if (dma == NULL)
|
||||
return NULL;
|
||||
|
||||
error = awin_hdmiaudio_allocdma(sc, size, 16, dma);
|
||||
if (error) {
|
||||
kmem_free(dma, sizeof(*dma));
|
||||
device_printf(sc->sc_dev, "couldn't allocate DMA memory (%d)\n",
|
||||
error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIST_INSERT_HEAD(&sc->sc_dmalist, dma, dma_list);
|
||||
|
||||
return dma->dma_addr;
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_freem(void *priv, void *addr, size_t size)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
struct awin_hdmiaudio_dma *dma;
|
||||
|
||||
LIST_FOREACH(dma, &sc->sc_dmalist, dma_list) {
|
||||
if (dma->dma_addr == addr) {
|
||||
awin_hdmiaudio_freedma(sc, dma);
|
||||
LIST_REMOVE(dma, dma_list);
|
||||
kmem_free(dma, sizeof(*dma));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static paddr_t
|
||||
awin_hdmiaudio_mappage(void *priv, void *addr, off_t off, int prot)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
struct awin_hdmiaudio_dma *dma;
|
||||
|
||||
if (off < 0)
|
||||
return -1;
|
||||
|
||||
LIST_FOREACH(dma, &sc->sc_dmalist, dma_list) {
|
||||
if (dma->dma_addr == addr) {
|
||||
return bus_dmamem_mmap(sc->sc_dmat, dma->dma_segs,
|
||||
dma->dma_nsegs, off, prot, BUS_DMA_WAITOK);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_getdev(void *priv, struct audio_device *audiodev)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
|
||||
const int vmaj = __SHIFTOUT(sc->sc_ver, AWIN_HDMI_VERSION_ID_H);
|
||||
const int vmin = __SHIFTOUT(sc->sc_ver, AWIN_HDMI_VERSION_ID_L);
|
||||
|
||||
snprintf(audiodev->name, sizeof(audiodev->name), "Allwinner");
|
||||
snprintf(audiodev->version, sizeof(audiodev->version),
|
||||
"HDMI %d.%d", vmaj, vmin);
|
||||
snprintf(audiodev->config, sizeof(audiodev->config), "awin_hdmiaudio");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_get_props(void *priv)
|
||||
{
|
||||
return AUDIO_PROP_PLAYBACK|AUDIO_PROP_MMAP;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_round_blocksize(void *priv, int bs, int mode,
|
||||
const audio_params_t *params)
|
||||
{
|
||||
return bs & ~3;
|
||||
}
|
||||
|
||||
static size_t
|
||||
awin_hdmiaudio_round_buffersize(void *priv, int direction, size_t bufsize)
|
||||
{
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_trigger_output(void *priv, void *start, void *end, int blksize,
|
||||
void (*intr)(void *), void *intrarg, const audio_params_t *params)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
struct awin_hdmiaudio_dma *dma;
|
||||
bus_addr_t pstart;
|
||||
bus_size_t psize;
|
||||
uint32_t dmacfg;
|
||||
int error;
|
||||
|
||||
pstart = 0;
|
||||
psize = (uintptr_t)end - (uintptr_t)start;
|
||||
|
||||
LIST_FOREACH(dma, &sc->sc_dmalist, dma_list) {
|
||||
if (dma->dma_addr == start) {
|
||||
pstart = dma->dma_map->dm_segs[0].ds_addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pstart == 0) {
|
||||
device_printf(sc->sc_dev, "bad addr %p\n", start);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
sc->sc_pint = intr;
|
||||
sc->sc_pintarg = intrarg;
|
||||
sc->sc_pstart = sc->sc_pcur = pstart;
|
||||
sc->sc_pend = sc->sc_pstart + psize;
|
||||
sc->sc_pblksize = blksize;
|
||||
|
||||
dmacfg = 0;
|
||||
dmacfg |= __SHIFTIN(AWIN_DMA_CTL_DATA_WIDTH_32,
|
||||
AWIN_DMA_CTL_DST_DATA_WIDTH);
|
||||
dmacfg |= __SHIFTIN(AWIN_DMA_CTL_BURST_LEN_4,
|
||||
AWIN_DMA_CTL_DST_BURST_LEN);
|
||||
dmacfg |= __SHIFTIN(AWIN_DMA_CTL_DATA_WIDTH_16,
|
||||
AWIN_DMA_CTL_SRC_DATA_WIDTH);
|
||||
dmacfg |= __SHIFTIN(AWIN_DMA_CTL_BURST_LEN_4,
|
||||
AWIN_DMA_CTL_SRC_BURST_LEN);
|
||||
dmacfg |= AWIN_DMA_CTL_BC_REMAINING;
|
||||
dmacfg |= AWIN_NDMA_CTL_DST_ADDR_NOINCR;
|
||||
dmacfg |= __SHIFTIN(sc->sc_drqtype_hdmiaudio,
|
||||
AWIN_DMA_CTL_DST_DRQ_TYPE);
|
||||
dmacfg |= __SHIFTIN(sc->sc_drqtype_sdram,
|
||||
AWIN_DMA_CTL_SRC_DRQ_TYPE);
|
||||
awin_dma_set_config(sc->sc_pdma, dmacfg);
|
||||
|
||||
error = awin_hdmiaudio_play(sc);
|
||||
if (error)
|
||||
awin_hdmiaudio_halt_output(sc);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
awin_hdmiaudio_trigger_input(void *priv, void *start, void *end, int blksize,
|
||||
void (*intr)(void *), void *intrarg, const audio_params_t *params)
|
||||
{
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static void
|
||||
awin_hdmiaudio_get_locks(void *priv, kmutex_t **intr, kmutex_t **thread)
|
||||
{
|
||||
struct awin_hdmiaudio_softc *sc = priv;
|
||||
|
||||
*intr = &sc->sc_intr_lock;
|
||||
*thread = &sc->sc_lock;
|
||||
}
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__KERNEL_RCSID(1, "$NetBSD: awin_io.c,v 1.27 2014/11/09 14:10:54 jmcneill Exp $");
|
||||
__KERNEL_RCSID(1, "$NetBSD: awin_io.c,v 1.28 2014/11/11 17:00:59 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
@ -153,6 +153,8 @@ static const struct awin_locators awin_locators[] = {
|
||||
{ "awincrypto", OFFANDSIZE(SS), NOPORT, AWIN_IRQ_SS, AANY },
|
||||
{ "awinac", OFFANDSIZE(AC), NOPORT, AWIN_IRQ_AC, A10|A20 },
|
||||
{ "awinac", OFFANDSIZE(AC), NOPORT, AWIN_A31_IRQ_AC, A31 },
|
||||
{ "awinhdmiaudio", OFFANDSIZE(HDMI), NOPORT, NOINTR, A20 },
|
||||
{ "awinhdmiaudio", OFFANDSIZE(HDMI), NOPORT, NOINTR, A31 },
|
||||
{ "awinnand", OFFANDSIZE(NFC), NOPORT, AWIN_IRQ_NAND, A10|A20 },
|
||||
{ "awinir", OFFANDSIZE(IR0), 0, AWIN_IRQ_IR0, A10|A20 },
|
||||
{ "awinir", OFFANDSIZE(IR1), 1, AWIN_IRQ_IR1, A10|A20 },
|
||||
|
@ -1903,6 +1903,47 @@ struct awin_mmc_idma_descriptor {
|
||||
#define AWIN_HDMI_PLL_CTRL_PREDIV __BITS(7,4)
|
||||
#define AWIN_HDMI_PLL_CTRL_VCO_S __BITS(3,0)
|
||||
|
||||
#define AWIN_HDMI_AUD_CTRL_EN __BIT(31)
|
||||
#define AWIN_HDMI_AUD_CTRL_RST __BIT(30)
|
||||
|
||||
#define AWIN_HDMI_ADMA_CTRL_SRC_DMA_MODE __BIT(31)
|
||||
#define AWIN_HDMI_ADMA_CTRL_DMA_REQ_CTRL __BITS(25,24)
|
||||
#define AWIN_HDMI_ADMA_CTRL_SRC_DMA_SAMPLE_RATE __BIT(19)
|
||||
#define AWIN_HDMI_ADMA_CTRL_SRC_SAMPLE_LAYOUT __BIT(18)
|
||||
#define AWIN_HDMI_ADMA_CTRL_SRC_WORD_LEN __BITS(17,16)
|
||||
#define AWIN_HDMI_ADMA_CTRL_FIFO_CLEAR __BIT(15)
|
||||
#define AWIN_HDMI_ADMA_CTRL_DATA_SEL __BIT(0)
|
||||
|
||||
#define AWIN_HDMI_AUD_FMT_SRC_SEL __BIT(31)
|
||||
#define AWIN_HDMI_AUD_FMT_SEL __BITS(26,24)
|
||||
#define AWIN_HDMI_AUD_FMT_DSD_FMT __BIT(4)
|
||||
#define AWIN_HDMI_AUD_FMT_LAYOUT __BIT(3)
|
||||
#define AWIN_HDMI_AUD_FMT_SRC_CH_CFG __BITS(2,0)
|
||||
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_CHNL_BIT1 __BITS(31,30)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_CLK_ACCUR __BITS(29,28)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ __BITS(27,24)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_44_1 0
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_48 2
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_32 3
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_88_2 8
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_96 10
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_176_4 12
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_FS_FREQ_192 14
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_CH_NUM __BITS(23,20)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_SOURCE_NUM __BITS(19,16)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_CATEGORY_CODE __BITS(15,8)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_MODE __BITS(7,6)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_EMPHASIS __BITS(5,3)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_CP __BIT(2)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_DATA_TYPE __BIT(1)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS0_APP_TYPE __BIT(0)
|
||||
|
||||
#define AWIN_HDMI_AUD_CH_STATUS1_CGMS_A __BITS(9,8)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS1_ORIGINAL_FS __BITS(7,4)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS1_WORD_LEN __BITS(3,1)
|
||||
#define AWIN_HDMI_AUD_CH_STATUS1_WORD_LEN_MAX __BIT(0)
|
||||
|
||||
#define AWIN_HDMI_DDC_CTRL_EN __BIT(31)
|
||||
#define AWIN_HDMI_DDC_CTRL_ACCESS_CMD_START __BIT(30)
|
||||
#define AWIN_HDMI_DDC_CTRL_FIFO_DIR __BIT(8)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.awin,v 1.23 2014/11/09 14:30:55 jmcneill Exp $
|
||||
# $NetBSD: files.awin,v 1.24 2014/11/11 17:00:59 jmcneill Exp $
|
||||
#
|
||||
# Configuration info for Allwinner ARM Peripherals
|
||||
#
|
||||
@ -134,11 +134,16 @@ device awinac: audiobus, auconv, mulaw, aurateconv
|
||||
attach awinac at awinio with awin_ac
|
||||
file arch/arm/allwinner/awin_ac.c awin_ac
|
||||
|
||||
# A10/A20/A31 HDMI
|
||||
# A20/A31 HDMI
|
||||
device awinhdmi: edid, ddc_read_edid, videomode
|
||||
attach awinhdmi at awinio with awin_hdmi
|
||||
file arch/arm/allwinner/awin_hdmi.c awin_hdmi
|
||||
|
||||
# A20/A31 HDMI audio (HDMIAUDIO)
|
||||
device awinhdmiaudio: audiobus, auconv, mulaw, aurateconv
|
||||
attach awinhdmiaudio at awinio with awin_hdmiaudio
|
||||
file arch/arm/allwinner/awin_hdmiaudio.c awin_hdmiaudio
|
||||
|
||||
# A10/A20/A31 LCD/TV timing controller (TCON)
|
||||
device awintcon
|
||||
attach awintcon at awinio with awin_tcon
|
||||
|
Loading…
Reference in New Issue
Block a user