xref: /openbsd/sys/dev/sdmmc/sdmmcchip.h (revision 834ff46c)
1 /*	$OpenBSD: sdmmcchip.h,v 1.15 2023/04/19 02:01:02 dlg Exp $	*/
2 
3 /*
4  * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _SDMMC_CHIP_H_
20 #define _SDMMC_CHIP_H_
21 
22 #include <machine/bus.h>
23 
24 struct sdmmc_command;
25 
26 typedef struct sdmmc_chip_functions *sdmmc_chipset_tag_t;
27 typedef void *sdmmc_chipset_handle_t;
28 
29 struct sdmmc_chip_functions {
30 	/* host controller reset */
31 	int	(*host_reset)(sdmmc_chipset_handle_t);
32 	/* host capabilities */
33 	u_int32_t (*host_ocr)(sdmmc_chipset_handle_t);
34 	int	(*host_maxblklen)(sdmmc_chipset_handle_t);
35 	/* card detection */
36 	int	(*card_detect)(sdmmc_chipset_handle_t);
37 	/* bus power and clock frequency */
38 	int	(*bus_power)(sdmmc_chipset_handle_t, u_int32_t);
39 	int	(*bus_clock)(sdmmc_chipset_handle_t, int, int);
40 	int	(*bus_width)(sdmmc_chipset_handle_t, int);
41 	/* command execution */
42 	void	(*exec_command)(sdmmc_chipset_handle_t,
43 		    struct sdmmc_command *);
44 	/* card interrupt */
45 	void	(*card_intr_mask)(sdmmc_chipset_handle_t, int);
46 	void	(*card_intr_ack)(sdmmc_chipset_handle_t);
47 	/* UHS functions */
48 	int	(*signal_voltage)(sdmmc_chipset_handle_t, int);
49 	int	(*execute_tuning)(sdmmc_chipset_handle_t, int);
50 	/* hibernate */
51 	int	(*hibernate_init)(sdmmc_chipset_handle_t, void *);
52 };
53 
54 /* host controller reset */
55 #define sdmmc_chip_host_reset(tag, handle)				\
56 	((tag)->host_reset((handle)))
57 /* host capabilities */
58 #define sdmmc_chip_host_ocr(tag, handle)				\
59 	((tag)->host_ocr((handle)))
60 #define sdmmc_chip_host_maxblklen(tag, handle)				\
61 	((tag)->host_maxblklen((handle)))
62 /* card detection */
63 #define sdmmc_chip_card_detect(tag, handle)				\
64 	((tag)->card_detect((handle)))
65 /* bus power and clock frequency */
66 #define sdmmc_chip_bus_power(tag, handle, ocr)				\
67 	((tag)->bus_power((handle), (ocr)))
68 #define sdmmc_chip_bus_clock(tag, handle, freq, timing)			\
69 	((tag)->bus_clock((handle), (freq), (timing)))
70 #define sdmmc_chip_bus_width(tag, handle, width)			\
71 	((tag)->bus_width((handle), (width)))
72 /* command execution */
73 #define sdmmc_chip_exec_command(tag, handle, cmdp)			\
74 	((tag)->exec_command((handle), (cmdp)))
75 /* card interrupt */
76 #define sdmmc_chip_card_intr_mask(tag, handle, enable)			\
77 	((tag)->card_intr_mask((handle), (enable)))
78 #define sdmmc_chip_card_intr_ack(tag, handle)				\
79 	((tag)->card_intr_ack((handle)))
80 /* UHS functions */
81 #define sdmmc_chip_signal_voltage(tag, handle, voltage)			\
82 	((tag)->signal_voltage((handle), (voltage)))
83 #define sdmmc_chip_execute_tuning(tag, handle, timing)			\
84 	((tag)->execute_tuning((handle), (timing)))
85 
86 /* clock frequencies for sdmmc_chip_bus_clock() */
87 #define SDMMC_SDCLK_OFF		0
88 #define SDMMC_SDCLK_400KHZ	400
89 #define SDMMC_SDCLK_25MHZ	25000
90 #define SDMMC_SDCLK_50MHZ	50000
91 
92 /* voltage levels for sdmmc_chip_signal_voltage() */
93 #define SDMMC_SIGNAL_VOLTAGE_330	0
94 #define SDMMC_SIGNAL_VOLTAGE_180	1
95 
96 #define SDMMC_TIMING_LEGACY	0
97 #define SDMMC_TIMING_HIGHSPEED	1
98 #define SDMMC_TIMING_UHS_SDR50	2
99 #define SDMMC_TIMING_UHS_SDR104	3
100 #define SDMMC_TIMING_MMC_DDR52	4
101 #define SDMMC_TIMING_MMC_HS200	5
102 
103 #define SDMMC_MAX_FUNCTIONS	8
104 
105 struct sdmmcbus_attach_args {
106 	const char *saa_busname;
107 	sdmmc_chipset_tag_t sct;
108 	sdmmc_chipset_handle_t sch;
109 	bus_dma_tag_t dmat;
110 	bus_dmamap_t dmap;
111 	int	flags;
112 	int	caps;
113 	long	max_seg;
114 	long	max_xfer;
115 	bus_size_t dma_boundary;
116 	void	*cookies[SDMMC_MAX_FUNCTIONS];
117 };
118 
119 void	sdmmc_needs_discover(struct device *);
120 void	sdmmc_card_intr(struct device *);
121 void	sdmmc_delay(u_int);
122 
123 #endif
124