Home | History | Annotate | Line # | Download | only in sunxi
sunxi_codec.h revision 1.4.6.1
      1  1.4.6.1  christos /* $NetBSD: sunxi_codec.h,v 1.4.6.1 2019/06/10 22:05:56 christos Exp $ */
      2      1.1  jmcneill 
      3      1.1  jmcneill /*-
      4      1.1  jmcneill  * Copyright (c) 2014-2017 Jared McNeill <jmcneill (at) invisible.ca>
      5      1.1  jmcneill  * All rights reserved.
      6      1.1  jmcneill  *
      7      1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8      1.1  jmcneill  * modification, are permitted provided that the following conditions
      9      1.1  jmcneill  * are met:
     10      1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12      1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15      1.1  jmcneill  *
     16      1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21      1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22      1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23      1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24      1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.1  jmcneill  * SUCH DAMAGE.
     27      1.1  jmcneill  */
     28      1.1  jmcneill 
     29      1.1  jmcneill #ifndef _ARM_SUNXI_CODEC_H
     30      1.1  jmcneill #define _ARM_SUNXI_CODEC_H
     31      1.1  jmcneill 
     32      1.1  jmcneill #include <sys/audioio.h>
     33  1.4.6.1  christos #include <dev/audio/audio_if.h>
     34      1.1  jmcneill 
     35      1.1  jmcneill #include <dev/fdt/fdtvar.h>
     36      1.1  jmcneill 
     37      1.1  jmcneill #include "h3_codec.h"
     38      1.1  jmcneill 
     39      1.1  jmcneill struct sunxi_codec_softc;
     40      1.1  jmcneill 
     41      1.1  jmcneill struct sunxi_codec_conf {
     42      1.1  jmcneill 	const char	*name;
     43      1.1  jmcneill 
     44      1.1  jmcneill 	/* initialize codec */
     45      1.1  jmcneill 	int		(*init)(struct sunxi_codec_softc *);
     46      1.1  jmcneill 	/* toggle DAC/ADC mute */
     47      1.1  jmcneill 	void		(*mute)(struct sunxi_codec_softc *, int, u_int);
     48      1.1  jmcneill 	/* mixer controls */
     49      1.1  jmcneill 	int		(*set_port)(struct sunxi_codec_softc *,
     50      1.1  jmcneill 				    mixer_ctrl_t *);
     51      1.1  jmcneill 	int		(*get_port)(struct sunxi_codec_softc *,
     52      1.1  jmcneill 				    mixer_ctrl_t *);
     53      1.1  jmcneill 	int		(*query_devinfo)(struct sunxi_codec_softc *,
     54      1.1  jmcneill 					 mixer_devinfo_t *);
     55      1.1  jmcneill 
     56      1.1  jmcneill 	/* register map */
     57      1.1  jmcneill 	bus_size_t	DPC,
     58      1.1  jmcneill 			DAC_FIFOC,
     59      1.1  jmcneill 			DAC_FIFOS,
     60      1.1  jmcneill 			DAC_TXDATA,
     61      1.1  jmcneill 			ADC_FIFOC,
     62      1.1  jmcneill 			ADC_FIFOS,
     63      1.1  jmcneill 			ADC_RXDATA,
     64      1.1  jmcneill 			DAC_CNT,
     65      1.1  jmcneill 			ADC_CNT;
     66      1.1  jmcneill };
     67      1.1  jmcneill 
     68      1.1  jmcneill struct sunxi_codec_chan {
     69      1.1  jmcneill 	struct sunxi_codec_softc *ch_sc;
     70      1.1  jmcneill 	u_int			ch_mode;
     71      1.1  jmcneill 
     72      1.1  jmcneill 	struct fdtbus_dma	*ch_dma;
     73      1.1  jmcneill 	struct fdtbus_dma_req	ch_req;
     74      1.1  jmcneill 
     75      1.1  jmcneill 	audio_params_t		ch_params;
     76      1.1  jmcneill 
     77      1.1  jmcneill 	bus_addr_t		ch_start_phys;
     78      1.1  jmcneill 	bus_addr_t		ch_end_phys;
     79      1.1  jmcneill 	bus_addr_t		ch_cur_phys;
     80      1.1  jmcneill 	int			ch_blksize;
     81      1.1  jmcneill 
     82      1.1  jmcneill 	void			(*ch_intr)(void *);
     83      1.1  jmcneill 	void			*ch_intrarg;
     84      1.1  jmcneill };
     85      1.1  jmcneill 
     86      1.1  jmcneill struct sunxi_codec_dma {
     87      1.1  jmcneill 	LIST_ENTRY(sunxi_codec_dma) dma_list;
     88      1.1  jmcneill 	bus_dmamap_t		dma_map;
     89      1.1  jmcneill 	void			*dma_addr;
     90      1.1  jmcneill 	size_t			dma_size;
     91      1.1  jmcneill 	bus_dma_segment_t	dma_segs[1];
     92      1.1  jmcneill 	int			dma_nsegs;
     93      1.1  jmcneill };
     94      1.1  jmcneill 
     95      1.1  jmcneill struct sunxi_codec_softc {
     96      1.1  jmcneill 	device_t		sc_dev;
     97      1.1  jmcneill 	bus_space_tag_t		sc_bst;
     98      1.1  jmcneill 	bus_space_handle_t	sc_bsh;
     99      1.1  jmcneill 	bus_dma_tag_t		sc_dmat;
    100      1.1  jmcneill 	int			sc_phandle;
    101      1.1  jmcneill 	bus_addr_t		sc_baseaddr;
    102      1.1  jmcneill 
    103      1.1  jmcneill 	struct sunxi_codec_conf	*sc_cfg;
    104      1.1  jmcneill 	void			*sc_codec_priv;
    105      1.1  jmcneill 
    106      1.1  jmcneill 	struct fdtbus_gpio_pin	*sc_pin_pa;
    107      1.1  jmcneill 
    108      1.1  jmcneill 	LIST_HEAD(, sunxi_codec_dma) sc_dmalist;
    109      1.1  jmcneill 
    110      1.1  jmcneill 	kmutex_t		sc_lock;
    111      1.1  jmcneill 	kmutex_t		sc_intr_lock;
    112      1.1  jmcneill 
    113      1.1  jmcneill 	struct audio_format	sc_format;
    114      1.1  jmcneill 
    115      1.1  jmcneill 	struct sunxi_codec_chan	sc_pchan;
    116      1.1  jmcneill 	struct sunxi_codec_chan	sc_rchan;
    117      1.1  jmcneill };
    118      1.1  jmcneill 
    119      1.1  jmcneill #if NH3_CODEC > 0
    120      1.1  jmcneill extern const struct sunxi_codec_conf sun8i_h3_codecconf;
    121      1.1  jmcneill #define	H3_CODEC_COMPATDATA	\
    122      1.1  jmcneill 	{ "allwinner,sun8i-h3-codec",	(uintptr_t)&sun8i_h3_codecconf }
    123      1.1  jmcneill #else
    124      1.1  jmcneill #define	H3_CODEC_COMPATDATA
    125      1.1  jmcneill #endif
    126      1.1  jmcneill 
    127      1.2  jmcneill extern const struct sunxi_codec_conf sun4i_a10_codecconf;
    128      1.2  jmcneill #define	A10_CODEC_COMPATDATA	\
    129      1.3  jmcneill 	{ "allwinner,sun4i-a10-codec",	(uintptr_t)&sun4i_a10_codecconf }, \
    130      1.3  jmcneill 	{ "allwinner,sun7i-a20-codec",	(uintptr_t)&sun4i_a10_codecconf }
    131      1.2  jmcneill 
    132      1.4  jmcneill extern const struct sunxi_codec_conf sun6i_a31_codecconf;
    133      1.4  jmcneill #define	A31_CODEC_COMPATDATA	\
    134      1.4  jmcneill 	{ "allwinner,sun6i-a31-codec",	(uintptr_t)&sun6i_a31_codecconf }
    135      1.4  jmcneill 
    136      1.1  jmcneill #endif /* !_ARM_SUNXI_CODEC_H */
    137