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