xref: /netbsd-src/sys/dev/ic/rtsxvar.h (revision ddb8613d0ae9c5f67eb6f1226aef7fd3e013b950)
1 /*	$NetBSD: rtsxvar.h,v 1.3 2018/04/24 18:34:30 maya Exp $	*/
2 /*	$OpenBSD: rtsxvar.h,v 1.3 2014/08/19 17:55:03 phessler Exp $	*/
3 
4 /*
5  * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
6  * Copyright (c) 2012 Stefan Sperling <stsp@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #ifndef _RTSXVAR_H_
22 #define _RTSXVAR_H_
23 
24 #include <sys/bus.h>
25 #include <sys/device.h>
26 #include <sys/pmf.h>
27 #include <sys/mutex.h>
28 #include <sys/condvar.h>
29 
30 /* Number of registers to save for suspend/resume in terms of their ranges. */
31 #define RTSX_NREG ((0XFDAE - 0XFDA0) + (0xFD69 - 0xFD32) + (0xFE34 - 0xFE20))
32 
33 struct rtsx_softc {
34 	device_t	sc_dev;
35 
36 	device_t	sc_sdmmc;	/* generic SD/MMC device */
37 
38 	bus_space_tag_t	sc_iot;		/* host register set tag */
39 	bus_space_handle_t sc_ioh;	/* host register set handle */
40 	bus_size_t      sc_iosize;
41 	bus_dma_tag_t	sc_dmat;	/* DMA tag from attachment driver */
42 	bus_dmamap_t	sc_dmap_cmd;	/* DMA map for command transfer */
43 
44 	struct kmutex	sc_host_mtx;
45 	struct kmutex	sc_intr_mtx;
46 	struct kcondvar sc_intr_cv;
47 
48 	uint32_t 	sc_intr_status;	/* soft interrupt status */
49 
50 	uint8_t		sc_regs[RTSX_NREG]; /* host controller state */
51 	uint32_t	sc_regs4[6];	/* host controller state */
52 
53 	uint32_t	sc_flags;
54 #define	RTSX_F_CARD_PRESENT	__BIT(0)
55 #define	RTSX_F_SDIO_SUPPORT	__BIT(1)
56 #define	RTSX_F_5209		__BIT(2)
57 #define	RTSX_F_5227		__BIT(3)
58 #define	RTSX_F_5229		__BIT(4)
59 #define	RTSX_F_5229_TYPE_C	__BIT(5)
60 #define	RTSX_F_525A		__BIT(6)
61 #define	RTSX_F_8402		__BIT(7)
62 #define	RTSX_F_8411		__BIT(8)
63 #define	RTSX_F_8411B		__BIT(9)
64 #define	RTSX_F_8411B_QFN48	__BIT(10)
65 };
66 
67 #define	RTSX_IS_RTS5209(sc)	(((sc)->sc_flags & RTSX_F_5209) == RTSX_F_5209)
68 #define	RTSX_IS_RTS5227(sc)	(((sc)->sc_flags & RTSX_F_5227) == RTSX_F_5227)
69 #define	RTSX_IS_RTS5229(sc)	(((sc)->sc_flags & RTSX_F_5229) == RTSX_F_5229)
70 #define	RTSX_IS_RTS5229_TYPE_C(sc)					\
71 	(((sc)->sc_flags & (RTSX_F_5229|RTSX_F_5229_TYPE_C)) ==		\
72 	                   (RTSX_F_5229|RTSX_F_5229_TYPE_C))
73 #define	RTSX_IS_RTS525A(sc)	(((sc)->sc_flags & RTSX_F_525A) == RTSX_F_525A)
74 #define	RTSX_IS_RTL8402(sc)	(((sc)->sc_flags & RTSX_F_8402) == RTSX_F_8402)
75 #define	RTSX_IS_RTL8411(sc)	(((sc)->sc_flags & RTSX_F_8411) == RTSX_F_8411)
76 #define	RTSX_IS_RTL8411B(sc)						\
77 	(((sc)->sc_flags & RTSX_F_8411B) == RTSX_F_8411B)
78 #define	RTSX_IS_RTL8411B_QFN48(sc)					\
79 	(((sc)->sc_flags & (RTSX_F_8411B|RTSX_F_8411B_QFN48)) ==	\
80 	                   (RTSX_F_8411B|RTSX_F_8411B_QFN48))
81 
82 /* Host controller functions called by the attachment driver. */
83 int	rtsx_attach(struct rtsx_softc *, bus_space_tag_t,
84 	    bus_space_handle_t, bus_size_t, bus_dma_tag_t, int);
85 int	rtsx_detach(struct rtsx_softc *, int);
86 bool	rtsx_suspend(device_t, const pmf_qual_t *);
87 bool	rtsx_resume(device_t, const pmf_qual_t *);
88 bool	rtsx_shutdown(device_t, int);
89 int	rtsx_intr(void *);
90 
91 #endif	/* _RTSXVAR_H_ */
92