xref: /haiku/headers/private/drivers/mmc.h (revision 683d891a6bed1db6ad3821f0a5bc2f6c529900dd)
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_bus/driver_v1"
16 
17 
18 enum {
19 	CARD_TYPE_MMC,
20 	CARD_TYPE_SD,
21 	CARD_TYPE_SDHC,
22 	CARD_TYPE_UHS1,
23 	CARD_TYPE_UHS2,
24 	CARD_TYPE_SDIO
25 };
26 
27 
28 // Commands for SD cards defined in SD Specifications Part 1:
29 // Physical Layer Simplified Specification Version 8.00
30 // They are in the common .h file for the mmc stack because the SDHCI driver
31 // currently needs to map them to the corresponding expected response types.
32 enum SD_COMMANDS {
33 	// Basic commands, class 0
34 	SD_GO_IDLE_STATE 		= 0,
35 	SD_ALL_SEND_CID			= 2,
36 	SD_SEND_RELATIVE_ADDR	= 3,
37 	SD_SELECT_DESELECT_CARD	= 7,
38 	SD_SEND_IF_COND			= 8,
39 	SD_SEND_CSD				= 9,
40 	SD_STOP_TRANSMISSION	= 12,
41 
42 	// Block oriented read commands, class 2
43 	SD_READ_SINGLE_BLOCK = 17,
44 	SD_READ_MULTIPLE_BLOCKS = 18,
45 
46 	// Application specific commands, class 8
47 	SD_APP_CMD = 55,
48 
49 	// I/O mode commands, class 9
50 	SD_IO_ABORT = 52,
51 };
52 
53 
54 enum SDHCI_APPLICATION_COMMANDS {
55 	SD_SEND_OP_COND = 41,
56 };
57 
58 
59 // Interface between mmc_bus and underlying implementation (sdhci_pci or any
60 // other thing that can execute mmc commands)
61 typedef struct mmc_bus_interface {
62 	driver_module_info info;
63 
64 	status_t (*set_clock)(void* controller, uint32_t kilohertz);
65 	status_t (*execute_command)(void* controller, uint8_t command,
66 		uint32_t argument, uint32_t* result);
67 	status_t (*read_naive)(void* controller, off_t pos,
68 		void* buffer, size_t* _length);
69 } mmc_bus_interface;
70 
71 
72 // Interface between mmc device driver (mmc_disk, sdio drivers, ...) and mmc_bus
73 typedef struct mmc_device_interface {
74 	driver_module_info info;
75 	status_t (*execute_command)(device_node* node, uint8_t command,
76 		uint32_t argument, uint32_t* result);
77 	status_t (*read_naive)(device_node* controller, uint16_t rca, off_t pos,
78 		void* buffer, size_t* _length);
79 } mmc_device_interface;
80 
81 
82 // Device attribute paths for the MMC device
83 static const char* kMmcRcaAttribute = "mmc/rca";
84 static const char* kMmcTypeAttribute = "mmc/type";
85 
86 
87 #endif /* _MMC_H */
88