sdmmcchip.h revision 1.5 1 /* $NetBSD: sdmmcchip.h,v 1.5 2015/08/02 21:44:36 jmcneill 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 (at) 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 <sys/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 /* UHS functions */
62 int (*signal_voltage)(sdmmc_chipset_handle_t, int);
63 };
64
65 /* host controller reset */
66 #define sdmmc_chip_host_reset(tag, handle) \
67 ((tag)->host_reset((handle)))
68 /* host capabilities */
69 #define sdmmc_chip_host_ocr(tag, handle) \
70 ((tag)->host_ocr((handle)))
71 #define sdmmc_chip_host_maxblklen(tag, handle) \
72 ((tag)->host_maxblklen((handle)))
73 /* card detection */
74 #define sdmmc_chip_card_detect(tag, handle) \
75 ((tag)->card_detect((handle)))
76 /* write protect */
77 #define sdmmc_chip_write_protect(tag, handle) \
78 ((tag)->write_protect((handle)))
79 /* bus power, clock frequency, width and rod */
80 #define sdmmc_chip_bus_power(tag, handle, ocr) \
81 ((tag)->bus_power((handle), (ocr)))
82 #define sdmmc_chip_bus_clock(tag, handle, freq) \
83 ((tag)->bus_clock((handle), (freq)))
84 #define sdmmc_chip_bus_width(tag, handle, width) \
85 ((tag)->bus_width((handle), (width)))
86 #define sdmmc_chip_bus_rod(tag, handle, width) \
87 ((tag)->bus_rod((handle), (width)))
88 /* command execution */
89 #define sdmmc_chip_exec_command(tag, handle, cmdp) \
90 ((tag)->exec_command((handle), (cmdp)))
91 /* card interrupt */
92 #define sdmmc_chip_card_enable_intr(tag, handle, enable) \
93 ((tag)->card_enable_intr((handle), (enable)))
94 #define sdmmc_chip_card_intr_ack(tag, handle) \
95 ((tag)->card_intr_ack((handle)))
96 /* UHS functions */
97 #define sdmmc_chip_signal_voltage(tag, handle, voltage) \
98 ((tag)->signal_voltage((handle), (voltage)))
99
100 /* clock frequencies for sdmmc_chip_bus_clock() */
101 #define SDMMC_SDCLK_OFF 0
102 #define SDMMC_SDCLK_400K 400
103
104 /* voltage levels for sdmmc_chip_signal_voltage() */
105 #define SDMMC_SIGNAL_VOLTAGE_330 0
106 #define SDMMC_SIGNAL_VOLTAGE_180 1
107
108 /* SPI mode */
109 struct sdmmc_spi_chip_functions {
110 /* card initialize */
111 void (*initialize)(sdmmc_chipset_handle_t);
112 };
113 #define sdmmc_spi_chip_initialize(tag, handle) \
114 ((tag)->initialize((handle)))
115
116 struct sdmmcbus_attach_args {
117 const char *saa_busname;
118 sdmmc_chipset_tag_t saa_sct;
119 sdmmc_spi_chipset_tag_t saa_spi_sct;
120 sdmmc_chipset_handle_t saa_sch;
121 bus_dma_tag_t saa_dmat;
122 u_int saa_clkmin;
123 u_int saa_clkmax;
124 uint32_t saa_caps; /* see sdmmc_softc.sc_caps */
125 };
126
127 void sdmmc_needs_discover(device_t);
128 void sdmmc_card_intr(device_t);
129 void sdmmc_delay(u_int);
130
131 #endif /* _SDMMC_CHIP_H_ */
132