xref: /netbsd-src/sys/dev/sdmmc/sdmmcchip.h (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: sdmmcchip.h,v 1.3 2010/10/07 12:00:21 kiyohara Exp $	*/
2 /*	$OpenBSD: sdmmcchip.h,v 1.3 2007/05/31 10:09:01 uwe Exp $	*/
3 
4 /*
5  * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef	_SDMMC_CHIP_H_
21 #define	_SDMMC_CHIP_H_
22 
23 #include <sys/device.h>
24 
25 #include <machine/bus.h>
26 
27 struct sdmmc_command;
28 
29 typedef struct sdmmc_chip_functions *sdmmc_chipset_tag_t;
30 typedef struct sdmmc_spi_chip_functions *sdmmc_spi_chipset_tag_t;
31 typedef void *sdmmc_chipset_handle_t;
32 
33 struct sdmmc_chip_functions {
34 	/* host controller reset */
35 	int		(*host_reset)(sdmmc_chipset_handle_t);
36 
37 	/* host capabilities */
38 	uint32_t	(*host_ocr)(sdmmc_chipset_handle_t);
39 	int		(*host_maxblklen)(sdmmc_chipset_handle_t);
40 
41 	/* card detection */
42 	int		(*card_detect)(sdmmc_chipset_handle_t);
43 
44 	/* write protect */
45 	int		(*write_protect)(sdmmc_chipset_handle_t);
46 
47 	/* bus power, clock frequency, width and ROD(OpenDrain/PushPull) */
48 	int		(*bus_power)(sdmmc_chipset_handle_t, uint32_t);
49 	int		(*bus_clock)(sdmmc_chipset_handle_t, int);
50 	int		(*bus_width)(sdmmc_chipset_handle_t, int);
51 	int		(*bus_rod)(sdmmc_chipset_handle_t, int);
52 
53 	/* command execution */
54 	void		(*exec_command)(sdmmc_chipset_handle_t,
55 			    struct sdmmc_command *);
56 
57 	/* card interrupt */
58 	void		(*card_enable_intr)(sdmmc_chipset_handle_t, int);
59 	void		(*card_intr_ack)(sdmmc_chipset_handle_t);
60 };
61 
62 /* host controller reset */
63 #define sdmmc_chip_host_reset(tag, handle)				\
64 	((tag)->host_reset((handle)))
65 /* host capabilities */
66 #define sdmmc_chip_host_ocr(tag, handle)				\
67 	((tag)->host_ocr((handle)))
68 #define sdmmc_chip_host_maxblklen(tag, handle)				\
69 	((tag)->host_maxblklen((handle)))
70 /* card detection */
71 #define sdmmc_chip_card_detect(tag, handle)				\
72 	((tag)->card_detect((handle)))
73 /* write protect */
74 #define sdmmc_chip_write_protect(tag, handle)				\
75 	((tag)->write_protect((handle)))
76 /* bus power, clock frequency, width and rod */
77 #define sdmmc_chip_bus_power(tag, handle, ocr)				\
78 	((tag)->bus_power((handle), (ocr)))
79 #define sdmmc_chip_bus_clock(tag, handle, freq)				\
80 	((tag)->bus_clock((handle), (freq)))
81 #define sdmmc_chip_bus_width(tag, handle, width)			\
82 	((tag)->bus_width((handle), (width)))
83 #define sdmmc_chip_bus_rod(tag, handle, width)				\
84 	((tag)->bus_rod((handle), (width)))
85 /* command execution */
86 #define sdmmc_chip_exec_command(tag, handle, cmdp)			\
87 	((tag)->exec_command((handle), (cmdp)))
88 /* card interrupt */
89 #define sdmmc_chip_card_enable_intr(tag, handle, enable)		\
90 	((tag)->card_enable_intr((handle), (enable)))
91 #define sdmmc_chip_card_intr_ack(tag, handle)				\
92 	((tag)->card_intr_ack((handle)))
93 
94 /* clock frequencies for sdmmc_chip_bus_clock() */
95 #define SDMMC_SDCLK_OFF		0
96 #define SDMMC_SDCLK_400K	400
97 
98 /* SPI mode */
99 struct sdmmc_spi_chip_functions {
100 	/* card initialize */
101 	void		(*initialize)(sdmmc_chipset_handle_t);
102 };
103 #define sdmmc_spi_chip_initialize(tag, handle)				\
104 	((tag)->initialize((handle)))
105 
106 struct sdmmcbus_attach_args {
107 	const char		*saa_busname;
108 	sdmmc_chipset_tag_t	saa_sct;
109 	sdmmc_spi_chipset_tag_t	saa_spi_sct;
110 	sdmmc_chipset_handle_t	saa_sch;
111 	bus_dma_tag_t		saa_dmat;
112 	u_int			saa_clkmin;
113 	u_int			saa_clkmax;
114 	uint32_t		saa_caps;	/* see sdmmc_softc.sc_caps */
115 };
116 
117 void	sdmmc_needs_discover(device_t);
118 void	sdmmc_card_intr(device_t);
119 void	sdmmc_delay(u_int);
120 
121 #endif	/* _SDMMC_CHIP_H_ */
122