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 // Application specific commands, class 8 53 SD_APP_CMD = 55, 54 55 // I/O mode commands, class 9 56 SD_IO_ABORT = 52, 57 }; 58 59 60 enum SDHCI_APPLICATION_COMMANDS { 61 SD_SET_BUS_WIDTH = 6, 62 SD_SEND_OP_COND = 41, 63 }; 64 65 66 // Interface between mmc_bus and underlying implementation (sdhci_pci or any 67 // other thing that can execute mmc commands) 68 typedef struct mmc_bus_interface { 69 driver_module_info info; 70 71 status_t (*set_clock)(void* controller, uint32_t kilohertz); 72 // Configure the bus clock. The bus is initialized with a slow clock 73 // that allows device enumeration in all cases, but after enumeration 74 // the mmc_bus knows how fast each card can go, and configures the bus 75 // accordingly. 76 status_t (*execute_command)(void* controller, uint8_t command, 77 uint32_t argument, uint32_t* result); 78 // Execute a command with no I/O phase 79 status_t (*do_io)(void* controller, uint8_t command, 80 IOOperation* operation, bool offsetAsSectors); 81 // Execute a command that involves a data transfer. 82 void (*set_scan_semaphore)(void* controller, sem_id sem); 83 // Pass the semaphore used for device rescan to the bus controller 84 void (*set_bus_width)(void* controller, int width); 85 // Set the data bus width to 1, 4 or 8 bit mode. 86 } mmc_bus_interface; 87 88 89 // Interface between mmc device driver (mmc_disk, sdio drivers, ...) and mmc_bus 90 // This interface is rather generic as it allows implementation of drivers for 91 // different type of cards, which will use different commands. The bus 92 // provides a generic interface for all of them, and is not specific to any 93 // type of card. 94 typedef struct mmc_device_interface { 95 driver_module_info info; 96 status_t (*execute_command)(device_node* node, void* cookie, uint16_t rca, 97 uint8_t command, uint32_t argument, uint32_t* result); 98 // Execute a command with no I/O phase 99 status_t (*do_io)(device_node* controller, void* cookie, uint16_t rca, 100 uint8_t command, IOOperation* operation, bool offsetAsSectors); 101 // Execute a command that involves a data transfer. 102 void (*set_bus_width)(device_node* controller, void* cookie, int width); 103 // Set the data bus width to 1, 4 or 8 bit mode. 104 } mmc_device_interface; 105 106 107 // Device attribute paths for the MMC device 108 static const char* kMmcRcaAttribute = "mmc/rca"; 109 static const char* kMmcTypeAttribute = "mmc/type"; 110 111 112 #endif /* _MMC_H */ 113