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