1 /* $OpenBSD: sdmmcchip.h,v 1.9 2016/05/05 20:40:48 kettenis 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 }; 50 51 /* host controller reset */ 52 #define sdmmc_chip_host_reset(tag, handle) \ 53 ((tag)->host_reset((handle))) 54 /* host capabilities */ 55 #define sdmmc_chip_host_ocr(tag, handle) \ 56 ((tag)->host_ocr((handle))) 57 #define sdmmc_chip_host_maxblklen(tag, handle) \ 58 ((tag)->host_maxblklen((handle))) 59 /* card detection */ 60 #define sdmmc_chip_card_detect(tag, handle) \ 61 ((tag)->card_detect((handle))) 62 /* bus power and clock frequency */ 63 #define sdmmc_chip_bus_power(tag, handle, ocr) \ 64 ((tag)->bus_power((handle), (ocr))) 65 #define sdmmc_chip_bus_clock(tag, handle, freq, timing) \ 66 ((tag)->bus_clock((handle), (freq), (timing))) 67 #define sdmmc_chip_bus_width(tag, handle, width) \ 68 ((tag)->bus_width((handle), (width))) 69 /* command execution */ 70 #define sdmmc_chip_exec_command(tag, handle, cmdp) \ 71 ((tag)->exec_command((handle), (cmdp))) 72 /* card interrupt */ 73 #define sdmmc_chip_card_intr_mask(tag, handle, enable) \ 74 ((tag)->card_intr_mask((handle), (enable))) 75 #define sdmmc_chip_card_intr_ack(tag, handle) \ 76 ((tag)->card_intr_ack((handle))) 77 /* UHS functions */ 78 #define sdmmc_chip_signal_voltage(tag, handle, voltage) \ 79 ((tag)->signal_voltage((handle), (voltage))) 80 81 /* clock frequencies for sdmmc_chip_bus_clock() */ 82 #define SDMMC_SDCLK_OFF 0 83 #define SDMMC_SDCLK_400KHZ 400 84 #define SDMMC_SDCLK_25MHZ 25000 85 #define SDMMC_SDCLK_50MHZ 50000 86 87 /* voltage levels for sdmmc_chip_signal_voltage() */ 88 #define SDMMC_SIGNAL_VOLTAGE_330 0 89 #define SDMMC_SIGNAL_VOLTAGE_180 1 90 91 #define SDMMC_TIMING_LEGACY 0 92 #define SDMMC_TIMING_HIGHSPEED 1 93 #define SDMMC_TIMING_MMC_DDR52 2 94 95 struct sdmmcbus_attach_args { 96 const char *saa_busname; 97 sdmmc_chipset_tag_t sct; 98 sdmmc_chipset_handle_t sch; 99 bus_dma_tag_t dmat; 100 int flags; 101 int caps; 102 long max_xfer; 103 }; 104 105 void sdmmc_needs_discover(struct device *); 106 void sdmmc_card_intr(struct device *); 107 void sdmmc_delay(u_int); 108 109 #endif 110