xref: /haiku/headers/private/drivers/mmc.h (revision 7b3e89c0944ae1efa9a8fc66c7303874b7a344b2)
1 /*
2  * Copyright 2019-2020, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Adrien Destugues, pulkomandy@pulkomandy.tk
7  */
8 #ifndef _MMC_H
9 #define _MMC_H
10 
11 
12 #include <device_manager.h>
13 
14 
15 #define MMC_BUS_MODULE_NAME "bus_managers/mmc/driver_v1"
16 
17 
18 struct IOOperation;
19 
20 
21 enum {
22 	CARD_TYPE_MMC,
23 	CARD_TYPE_SD,
24 	CARD_TYPE_SDHC,
25 	CARD_TYPE_UHS1,
26 	CARD_TYPE_UHS2,
27 	CARD_TYPE_SDIO
28 };
29 
30 
31 // Commands for SD cards defined in SD Specifications Part 1:
32 // Physical Layer Simplified Specification Version 8.00
33 // They are in the common .h file for the mmc stack because the SDHCI driver
34 // currently needs to map them to the corresponding expected response types.
35 enum SD_COMMANDS {
36 	// Basic commands, class 0
37 	SD_GO_IDLE_STATE 		= 0,
38 	SD_ALL_SEND_CID			= 2,
39 	SD_SEND_RELATIVE_ADDR	= 3,
40 	SD_SELECT_DESELECT_CARD	= 7,
41 	SD_SEND_IF_COND			= 8,
42 	SD_SEND_CSD				= 9,
43 	SD_STOP_TRANSMISSION	= 12,
44 
45 	// Block oriented read and write commands, class 2
46 	SD_READ_SINGLE_BLOCK = 17,
47 	SD_READ_MULTIPLE_BLOCKS = 18,
48 
49 	SD_WRITE_SINGLE_BLOCK = 24,
50 	SD_WRITE_MULTIPLE_BLOCKS = 25,
51 
52 	// Erase commands, class 5
53 	SD_ERASE_WR_BLK_START = 32,
54 	SD_ERASE_WR_BLK_END = 33,
55 	SD_ERASE = 38,
56 
57 	// Application specific commands, class 8
58 	SD_APP_CMD = 55,
59 
60 	// I/O mode commands, class 9
61 	SD_IO_ABORT = 52,
62 };
63 
64 
65 enum SDHCI_APPLICATION_COMMANDS {
66 	SD_SET_BUS_WIDTH = 6,
67 	SD_SEND_OP_COND = 41,
68 };
69 
70 
71 // Interface between mmc_bus and underlying implementation (sdhci_pci or any
72 // other thing that can execute mmc commands)
73 typedef struct mmc_bus_interface {
74 	driver_module_info info;
75 
76 	status_t (*set_clock)(void* controller, uint32_t kilohertz);
77 		// Configure the bus clock. The bus is initialized with a slow clock
78 		// that allows device enumeration in all cases, but after enumeration
79 		// the mmc_bus knows how fast each card can go, and configures the bus
80 		// accordingly.
81 	status_t (*execute_command)(void* controller, uint8_t command,
82 		uint32_t argument, uint32_t* result);
83 		// Execute a command with no I/O phase
84 	status_t (*do_io)(void* controller, uint8_t command,
85 		IOOperation* operation, bool offsetAsSectors);
86 		// Execute a command that involves a data transfer.
87 	void (*set_scan_semaphore)(void* controller, sem_id sem);
88 		// Pass the semaphore used for device rescan to the bus controller
89 	void (*set_bus_width)(void* controller, int width);
90 		// Set the data bus width to 1, 4 or 8 bit mode.
91 } mmc_bus_interface;
92 
93 
94 // Interface between mmc device driver (mmc_disk, sdio drivers, ...) and mmc_bus
95 // This interface is rather generic as it allows implementation of drivers for
96 // different type of cards, which will use different commands. The bus
97 // provides a generic interface for all of them, and is not specific to any
98 // type of card.
99 typedef struct mmc_device_interface {
100 	driver_module_info info;
101 	status_t (*execute_command)(device_node* node, void* cookie, uint16_t rca,
102 		uint8_t command, uint32_t argument, uint32_t* result);
103 		// Execute a command with no I/O phase
104 	status_t (*do_io)(device_node* controller, void* cookie, uint16_t rca,
105 		uint8_t command, IOOperation* operation, bool offsetAsSectors);
106 		// Execute a command that involves a data transfer.
107 	void (*set_bus_width)(device_node* controller, void* cookie, int width);
108 		// Set the data bus width to 1, 4 or 8 bit mode.
109 } mmc_device_interface;
110 
111 
112 // Device attribute paths for the MMC device
113 const char* const kMmcRcaAttribute = "mmc/rca";
114 const char* const kMmcTypeAttribute = "mmc/type";
115 
116 
117 #endif /* _MMC_H */
118