2019-02-11 00:39:02 +03:00
|
|
|
/*
|
2019-02-19 22:12:08 +03:00
|
|
|
* Copyright 2019-2020, Haiku, Inc. All Rights Reserved.
|
2019-02-11 00:39:02 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Adrien Destugues, pulkomandy@pulkomandy.tk
|
|
|
|
*/
|
|
|
|
#ifndef _MMC_H
|
|
|
|
#define _MMC_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <device_manager.h>
|
|
|
|
|
|
|
|
|
2018-12-23 13:31:48 +03:00
|
|
|
#define MMC_BUS_MODULE_NAME "bus_managers/mmc/driver_v1"
|
2019-02-11 00:39:02 +03:00
|
|
|
|
|
|
|
|
2020-12-06 19:44:45 +03:00
|
|
|
struct IOOperation;
|
|
|
|
|
|
|
|
|
2019-02-17 13:54:12 +03:00
|
|
|
enum {
|
|
|
|
CARD_TYPE_MMC,
|
|
|
|
CARD_TYPE_SD,
|
|
|
|
CARD_TYPE_SDHC,
|
|
|
|
CARD_TYPE_UHS1,
|
|
|
|
CARD_TYPE_UHS2,
|
|
|
|
CARD_TYPE_SDIO
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-14 16:10:01 +03:00
|
|
|
// Commands for SD cards defined in SD Specifications Part 1:
|
|
|
|
// Physical Layer Simplified Specification Version 8.00
|
|
|
|
// They are in the common .h file for the mmc stack because the SDHCI driver
|
|
|
|
// currently needs to map them to the corresponding expected response types.
|
|
|
|
enum SD_COMMANDS {
|
|
|
|
// Basic commands, class 0
|
|
|
|
SD_GO_IDLE_STATE = 0,
|
|
|
|
SD_ALL_SEND_CID = 2,
|
|
|
|
SD_SEND_RELATIVE_ADDR = 3,
|
|
|
|
SD_SELECT_DESELECT_CARD = 7,
|
|
|
|
SD_SEND_IF_COND = 8,
|
|
|
|
SD_SEND_CSD = 9,
|
|
|
|
SD_STOP_TRANSMISSION = 12,
|
|
|
|
|
2020-12-13 14:25:03 +03:00
|
|
|
// Block oriented read and write commands, class 2
|
2020-10-14 16:10:01 +03:00
|
|
|
SD_READ_SINGLE_BLOCK = 17,
|
|
|
|
SD_READ_MULTIPLE_BLOCKS = 18,
|
|
|
|
|
2020-12-13 14:25:03 +03:00
|
|
|
SD_WRITE_SINGLE_BLOCK = 24,
|
|
|
|
SD_WRITE_MULTIPLE_BLOCKS = 25,
|
|
|
|
|
2020-10-14 16:10:01 +03:00
|
|
|
// Application specific commands, class 8
|
|
|
|
SD_APP_CMD = 55,
|
|
|
|
|
|
|
|
// I/O mode commands, class 9
|
|
|
|
SD_IO_ABORT = 52,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum SDHCI_APPLICATION_COMMANDS {
|
|
|
|
SD_SEND_OP_COND = 41,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-02-19 22:12:08 +03:00
|
|
|
// Interface between mmc_bus and underlying implementation (sdhci_pci or any
|
|
|
|
// other thing that can execute mmc commands)
|
2019-02-11 00:39:02 +03:00
|
|
|
typedef struct mmc_bus_interface {
|
|
|
|
driver_module_info info;
|
|
|
|
|
|
|
|
status_t (*set_clock)(void* controller, uint32_t kilohertz);
|
2020-12-13 14:25:03 +03:00
|
|
|
// Configure the bus clock. The bus is initialized with a slow clock
|
|
|
|
// that allows device enumeration in all cases, but after enumeration
|
|
|
|
// the mmc_bus knows how fast each card can go, and configures the bus
|
|
|
|
// accordingly.
|
2019-02-11 00:39:02 +03:00
|
|
|
status_t (*execute_command)(void* controller, uint8_t command,
|
|
|
|
uint32_t argument, uint32_t* result);
|
2020-12-13 14:25:03 +03:00
|
|
|
// Execute a command with no I/O phase
|
|
|
|
status_t (*do_io)(void* controller, uint8_t command,
|
|
|
|
IOOperation* operation);
|
|
|
|
// Execute a command that involves a data transfer.
|
2019-02-11 00:39:02 +03:00
|
|
|
} mmc_bus_interface;
|
|
|
|
|
|
|
|
|
2020-07-26 14:49:20 +03:00
|
|
|
// Interface between mmc device driver (mmc_disk, sdio drivers, ...) and mmc_bus
|
2020-12-13 14:25:03 +03:00
|
|
|
// This interface is rather generic as it allows implementation of drivers for
|
|
|
|
// different type of cards, which will use different commands. The bus
|
|
|
|
// provides a generic interface for all of them, and is not specific to any
|
|
|
|
// type of card.
|
2020-07-26 14:49:20 +03:00
|
|
|
typedef struct mmc_device_interface {
|
|
|
|
driver_module_info info;
|
|
|
|
status_t (*execute_command)(device_node* node, uint8_t command,
|
|
|
|
uint32_t argument, uint32_t* result);
|
2020-12-13 14:25:03 +03:00
|
|
|
// Execute a command with no I/O phase
|
2020-12-06 19:44:45 +03:00
|
|
|
status_t (*do_io)(device_node* controller, uint16_t rca,
|
2020-12-13 14:25:03 +03:00
|
|
|
uint8_t command, IOOperation* operation);
|
|
|
|
// Execute a command that involves a data transfer.
|
2020-07-26 14:49:20 +03:00
|
|
|
} mmc_device_interface;
|
|
|
|
|
|
|
|
|
2019-02-19 22:12:08 +03:00
|
|
|
// Device attribute paths for the MMC device
|
|
|
|
static const char* kMmcRcaAttribute = "mmc/rca";
|
|
|
|
static const char* kMmcTypeAttribute = "mmc/type";
|
|
|
|
|
|
|
|
|
2019-02-11 00:39:02 +03:00
|
|
|
#endif /* _MMC_H */
|