Home | History | Annotate | Line # | Download | only in hdaudio
hdaudiovar.h revision 1.2
      1 /* $NetBSD: hdaudiovar.h,v 1.2 2015/03/28 14:50:20 jmcneill Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2009 Precedence Technologies Ltd <support (at) precedence.co.uk>
      5  * Copyright (c) 2009 Jared D. McNeill <jmcneill (at) invisible.ca>
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to The NetBSD Foundation
      9  * by Precedence Technologies Ltd
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _HDAUDIOVAR_H
     33 #define _HDAUDIOVAR_H
     34 
     35 #include <dev/auconv.h>
     36 
     37 #ifdef _KERNEL_OPT
     38 #include "opt_hdaudio.h"
     39 #endif
     40 
     41 #define	HDAUDIO_MAX_CODECS	15
     42 
     43 #define	hda_read1(sc, off)		\
     44 	bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (off))
     45 #define	hda_read2(sc, off)		\
     46 	bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (off))
     47 #define	hda_read4(sc, off)		\
     48 	bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (off))
     49 #define	hda_write1(sc, off, val)	\
     50 	bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (off), (val))
     51 #define	hda_write2(sc, off, val)	\
     52 	bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (off), (val))
     53 #define	hda_write4(sc, off, val)	\
     54 	bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (off), (val))
     55 #define	hda_print(sc, ...)		\
     56 	aprint_normal_dev((sc)->sc_dev, __VA_ARGS__)
     57 #define	hda_print1(sc, ...)		\
     58 	aprint_normal(__VA_ARGS__)
     59 #define	hda_error(sc, ...)		\
     60 	aprint_error_dev((sc)->sc_dev, __VA_ARGS__)
     61 #ifdef HDAUDIO_DEBUG
     62 #define	hda_trace(sc, ...)		\
     63 	aprint_normal_dev((sc)->sc_dev, __VA_ARGS__)
     64 #define	hda_trace1(sc, ...)		\
     65 	aprint_normal(__VA_ARGS__)
     66 #else
     67 #define hda_trace(sc, ...) do { } while (0)
     68 #define hda_trace1(sc, ...) do { } while (0)
     69 #endif
     70 #define	hda_delay(us)			\
     71 	delay((us))
     72 
     73 struct hdaudio_softc;
     74 
     75 enum function_group_type {
     76 	HDAUDIO_GROUP_TYPE_UNKNOWN = 0,
     77 	HDAUDIO_GROUP_TYPE_AFG,
     78 	HDAUDIO_GROUP_TYPE_VSM_FG,
     79 };
     80 
     81 struct hdaudio_function_group {
     82 	device_t			fg_device;
     83 	struct hdaudio_codec		*fg_codec;
     84 	enum function_group_type	fg_type;
     85 	int				fg_nid;
     86 	uint16_t			fg_vendor;
     87 	uint16_t			fg_product;
     88 
     89 	int				(*fg_unsol)(device_t, uint8_t);
     90 };
     91 
     92 struct hdaudio_codec {
     93 	bool				co_valid;
     94 	u_int				co_addr;
     95 	u_int				co_nfg;
     96 	struct hdaudio_function_group	*co_fg;
     97 	struct hdaudio_softc		*co_host;
     98 };
     99 
    100 #define	DMA_KERNADDR(dma)	((dma)->dma_addr)
    101 #define DMA_DMAADDR(dma)	((dma)->dma_map->dm_segs[0].ds_addr)
    102 
    103 struct hdaudio_dma {
    104 	bus_dmamap_t		dma_map;
    105 	void			*dma_addr;
    106 	bus_dma_segment_t	dma_segs[1];
    107 	int			dma_nsegs;
    108 	bus_size_t		dma_size;
    109 	bool			dma_valid;
    110 	uint8_t			dma_sizereg;
    111 };
    112 
    113 #define	HDAUDIO_MAX_STREAMS	30
    114 
    115 struct hdaudio_dma_position {
    116 	uint32_t	position;
    117 	uint32_t	reserved;
    118 } __packed;
    119 
    120 struct hdaudio_bdl_entry {
    121 	uint32_t	address_lo;
    122 	uint32_t	address_hi;
    123 	uint32_t	length;
    124 	uint32_t	flags;
    125 #define	HDAUDIO_BDL_ENTRY_IOC	0x00000001
    126 } __packed;
    127 
    128 #define	HDAUDIO_BDL_MAX		256
    129 
    130 enum hdaudio_stream_type {
    131 	HDAUDIO_STREAM_ISS = 0,
    132 	HDAUDIO_STREAM_OSS = 1,
    133 	HDAUDIO_STREAM_BSS = 2
    134 };
    135 
    136 struct hdaudio_stream {
    137 	struct hdaudio_softc		*st_host;
    138 	bool				st_enable;
    139 	enum hdaudio_stream_type	st_type;
    140 	int				st_shift;
    141 	int				st_num;
    142 
    143 	int				(*st_intr)(struct hdaudio_stream *);
    144 	void				*st_cookie;
    145 
    146 	struct hdaudio_dma		st_data;
    147 	struct hdaudio_dma		st_bdl;
    148 };
    149 
    150 struct hdaudio_softc {
    151 	device_t		sc_dev;
    152 
    153 	bus_dma_tag_t		sc_dmat;
    154 	bus_space_tag_t		sc_memt;
    155 	bus_space_handle_t	sc_memh;
    156 	bus_addr_t		sc_membase;
    157 	bus_size_t		sc_memsize;
    158 	bool			sc_memvalid;
    159 
    160 	uint32_t		sc_subsystem;
    161 
    162 	kmutex_t		sc_corb_mtx;
    163 	struct hdaudio_dma	sc_corb;
    164 	struct hdaudio_dma	sc_rirb;
    165 	uint16_t		sc_rirbrp;
    166 
    167 	struct hdaudio_codec	sc_codec[HDAUDIO_MAX_CODECS];
    168 
    169 	struct hdaudio_stream	sc_stream[HDAUDIO_MAX_STREAMS];
    170 	uint32_t		sc_stream_mask;
    171 	kmutex_t		sc_stream_mtx;
    172 };
    173 
    174 int	hdaudio_attach(device_t, struct hdaudio_softc *);
    175 int	hdaudio_detach(struct hdaudio_softc *, int);
    176 bool	hdaudio_resume(struct hdaudio_softc *);
    177 int	hdaudio_rescan(struct hdaudio_softc *, const char *, const int *);
    178 void	hdaudio_childdet(struct hdaudio_softc *, device_t);
    179 
    180 uint32_t hdaudio_command(struct hdaudio_codec *, int, uint32_t, uint32_t);
    181 uint32_t hdaudio_command_unlocked(struct hdaudio_codec *, int, uint32_t,
    182     uint32_t);
    183 int	hdaudio_intr(struct hdaudio_softc *);
    184 
    185 int	hdaudio_dma_alloc(struct hdaudio_softc *, struct hdaudio_dma *, int);
    186 void	hdaudio_dma_free(struct hdaudio_softc *, struct hdaudio_dma *);
    187 
    188 struct hdaudio_stream *	hdaudio_stream_establish(struct hdaudio_softc *,
    189 				    enum hdaudio_stream_type,
    190 				    int (*)(struct hdaudio_stream *), void *);
    191 void	hdaudio_stream_disestablish(struct hdaudio_stream *);
    192 void	hdaudio_stream_start(struct hdaudio_stream *, int, bus_size_t,
    193 			     const audio_params_t *);
    194 void	hdaudio_stream_stop(struct hdaudio_stream *);
    195 void	hdaudio_stream_reset(struct hdaudio_stream *);
    196 int	hdaudio_stream_tag(struct hdaudio_stream *);
    197 uint16_t hdaudio_stream_param(struct hdaudio_stream *, const audio_params_t *);
    198 
    199 #endif /* !_HDAUDIOVAR_H */
    200