Home | History | Annotate | Line # | Download | only in sunxi
      1  1.8  jmcneill /* $NetBSD: sunxi_codec.h,v 1.8 2021/05/05 20:58:03 jmcneill 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.5     isaki #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.7  jmcneill #include "v3s_codec.h"
     39  1.1  jmcneill 
     40  1.1  jmcneill struct sunxi_codec_softc;
     41  1.1  jmcneill 
     42  1.1  jmcneill struct sunxi_codec_conf {
     43  1.1  jmcneill 	const char	*name;
     44  1.1  jmcneill 
     45  1.1  jmcneill 	/* initialize codec */
     46  1.1  jmcneill 	int		(*init)(struct sunxi_codec_softc *);
     47  1.1  jmcneill 	/* toggle DAC/ADC mute */
     48  1.1  jmcneill 	void		(*mute)(struct sunxi_codec_softc *, int, u_int);
     49  1.1  jmcneill 	/* mixer controls */
     50  1.1  jmcneill 	int		(*set_port)(struct sunxi_codec_softc *,
     51  1.1  jmcneill 				    mixer_ctrl_t *);
     52  1.1  jmcneill 	int		(*get_port)(struct sunxi_codec_softc *,
     53  1.1  jmcneill 				    mixer_ctrl_t *);
     54  1.1  jmcneill 	int		(*query_devinfo)(struct sunxi_codec_softc *,
     55  1.1  jmcneill 					 mixer_devinfo_t *);
     56  1.1  jmcneill 
     57  1.1  jmcneill 	/* register map */
     58  1.1  jmcneill 	bus_size_t	DPC,
     59  1.1  jmcneill 			DAC_FIFOC,
     60  1.1  jmcneill 			DAC_FIFOS,
     61  1.1  jmcneill 			DAC_TXDATA,
     62  1.1  jmcneill 			ADC_FIFOC,
     63  1.1  jmcneill 			ADC_FIFOS,
     64  1.1  jmcneill 			ADC_RXDATA,
     65  1.1  jmcneill 			DAC_CNT,
     66  1.1  jmcneill 			ADC_CNT;
     67  1.1  jmcneill };
     68  1.1  jmcneill 
     69  1.1  jmcneill struct sunxi_codec_chan {
     70  1.1  jmcneill 	struct sunxi_codec_softc *ch_sc;
     71  1.1  jmcneill 	u_int			ch_mode;
     72  1.1  jmcneill 
     73  1.1  jmcneill 	struct fdtbus_dma	*ch_dma;
     74  1.1  jmcneill 	struct fdtbus_dma_req	ch_req;
     75  1.1  jmcneill 
     76  1.1  jmcneill 	audio_params_t		ch_params;
     77  1.1  jmcneill 
     78  1.1  jmcneill 	bus_addr_t		ch_start_phys;
     79  1.1  jmcneill 	bus_addr_t		ch_end_phys;
     80  1.1  jmcneill 	bus_addr_t		ch_cur_phys;
     81  1.1  jmcneill 	int			ch_blksize;
     82  1.1  jmcneill 
     83  1.1  jmcneill 	void			(*ch_intr)(void *);
     84  1.1  jmcneill 	void			*ch_intrarg;
     85  1.1  jmcneill };
     86  1.1  jmcneill 
     87  1.1  jmcneill struct sunxi_codec_dma {
     88  1.1  jmcneill 	LIST_ENTRY(sunxi_codec_dma) dma_list;
     89  1.1  jmcneill 	bus_dmamap_t		dma_map;
     90  1.1  jmcneill 	void			*dma_addr;
     91  1.1  jmcneill 	size_t			dma_size;
     92  1.1  jmcneill 	bus_dma_segment_t	dma_segs[1];
     93  1.1  jmcneill 	int			dma_nsegs;
     94  1.1  jmcneill };
     95  1.1  jmcneill 
     96  1.1  jmcneill struct sunxi_codec_softc {
     97  1.1  jmcneill 	device_t		sc_dev;
     98  1.1  jmcneill 	bus_space_tag_t		sc_bst;
     99  1.1  jmcneill 	bus_space_handle_t	sc_bsh;
    100  1.1  jmcneill 	bus_dma_tag_t		sc_dmat;
    101  1.1  jmcneill 	int			sc_phandle;
    102  1.1  jmcneill 	bus_addr_t		sc_baseaddr;
    103  1.1  jmcneill 
    104  1.6   thorpej 	const struct sunxi_codec_conf	*sc_cfg;
    105  1.1  jmcneill 	void			*sc_codec_priv;
    106  1.1  jmcneill 
    107  1.1  jmcneill 	struct fdtbus_gpio_pin	*sc_pin_pa;
    108  1.1  jmcneill 
    109  1.1  jmcneill 	LIST_HEAD(, sunxi_codec_dma) sc_dmalist;
    110  1.1  jmcneill 
    111  1.1  jmcneill 	kmutex_t		sc_lock;
    112  1.1  jmcneill 	kmutex_t		sc_intr_lock;
    113  1.1  jmcneill 
    114  1.1  jmcneill 	struct audio_format	sc_format;
    115  1.1  jmcneill 
    116  1.1  jmcneill 	struct sunxi_codec_chan	sc_pchan;
    117  1.1  jmcneill 	struct sunxi_codec_chan	sc_rchan;
    118  1.1  jmcneill };
    119  1.1  jmcneill 
    120  1.1  jmcneill #if NH3_CODEC > 0
    121  1.1  jmcneill extern const struct sunxi_codec_conf sun8i_h3_codecconf;
    122  1.6   thorpej #define	H3_CODEC_COMPATDATA						\
    123  1.6   thorpej 	{ .compat = "allwinner,sun8i-h3-codec",				\
    124  1.8  jmcneill 	  .data = &sun8i_h3_codecconf },
    125  1.1  jmcneill #else
    126  1.1  jmcneill #define	H3_CODEC_COMPATDATA
    127  1.1  jmcneill #endif
    128  1.1  jmcneill 
    129  1.7  jmcneill #if NV3S_CODEC > 0
    130  1.7  jmcneill extern const struct sunxi_codec_conf sun8i_v3s_codecconf;
    131  1.7  jmcneill #define V3S_CODEC_COMPATDATA						\
    132  1.7  jmcneill 	{ .compat = "allwinner,sun8i-v3s-codec",			\
    133  1.8  jmcneill 	  .data = &sun8i_v3s_codecconf },
    134  1.7  jmcneill #else
    135  1.7  jmcneill #define V3S_CODEC_COMPATDATA
    136  1.7  jmcneill #endif
    137  1.7  jmcneill 
    138  1.2  jmcneill extern const struct sunxi_codec_conf sun4i_a10_codecconf;
    139  1.6   thorpej #define	A10_CODEC_COMPATDATA						\
    140  1.6   thorpej 	{ .compat = "allwinner,sun4i-a10-codec",			\
    141  1.6   thorpej 	  .data = &sun4i_a10_codecconf }, 				\
    142  1.6   thorpej 	{ .compat = "allwinner,sun7i-a20-codec",			\
    143  1.8  jmcneill 	  .data = &sun4i_a10_codecconf },
    144  1.2  jmcneill 
    145  1.4  jmcneill extern const struct sunxi_codec_conf sun6i_a31_codecconf;
    146  1.6   thorpej #define	A31_CODEC_COMPATDATA						\
    147  1.6   thorpej 	{ .compat = "allwinner,sun6i-a31-codec",			\
    148  1.8  jmcneill 	  .data = &sun6i_a31_codecconf },
    149  1.4  jmcneill 
    150  1.1  jmcneill #endif /* !_ARM_SUNXI_CODEC_H */
    151