125b6a6f1Skrish_iyer /* 225b6a6f1Skrish_iyer * Copyright 2018 Haiku, Inc. All rights reserved. 325b6a6f1Skrish_iyer * Distributed under the terms of the MIT License. 425b6a6f1Skrish_iyer * 525b6a6f1Skrish_iyer * Authors: 625b6a6f1Skrish_iyer * B Krishnan Iyer, krishnaniyer97@gmail.com 725b6a6f1Skrish_iyer */ 825b6a6f1Skrish_iyer #ifndef MMC_BUS_H 925b6a6f1Skrish_iyer #define MMC_BUS_H 1025b6a6f1Skrish_iyer 1125b6a6f1Skrish_iyer 1225b6a6f1Skrish_iyer #include <new> 1325b6a6f1Skrish_iyer #include <stdio.h> 1425b6a6f1Skrish_iyer #include <string.h> 1525b6a6f1Skrish_iyer 1625b6a6f1Skrish_iyer #include <lock.h> 1725b6a6f1Skrish_iyer #include <util/AutoLock.h> 18ff76d2dfSAdrien Destugues #include "mmc.h" 1925b6a6f1Skrish_iyer 2025b6a6f1Skrish_iyer 2125b6a6f1Skrish_iyer #define MMCBUS_TRACE 2225b6a6f1Skrish_iyer #ifdef MMCBUS_TRACE 2325b6a6f1Skrish_iyer # define TRACE(x...) dprintf("\33[33mmmc_bus:\33[0m " x) 2425b6a6f1Skrish_iyer #else 2525b6a6f1Skrish_iyer # define TRACE(x...) 2625b6a6f1Skrish_iyer #endif 2725b6a6f1Skrish_iyer #define TRACE_ALWAYS(x...) dprintf("\33[33mmmc_bus:\33[0m " x) 2825b6a6f1Skrish_iyer #define ERROR(x...) dprintf("\33[33mmmc_bus:\33[0m " x) 2925b6a6f1Skrish_iyer #define CALLED() TRACE("CALLED %s\n", __PRETTY_FUNCTION__) 3025b6a6f1Skrish_iyer 3125b6a6f1Skrish_iyer extern device_manager_info *gDeviceManager; 3225b6a6f1Skrish_iyer 3325b6a6f1Skrish_iyer 3425b6a6f1Skrish_iyer class MMCBus; 3525b6a6f1Skrish_iyer 3625b6a6f1Skrish_iyer class MMCBus { 3725b6a6f1Skrish_iyer public: 3825b6a6f1Skrish_iyer 3925b6a6f1Skrish_iyer MMCBus(device_node *node); 4025b6a6f1Skrish_iyer ~MMCBus(); 4125b6a6f1Skrish_iyer status_t InitCheck(); 42dedbe94eSAdrien Destugues void Rescan(); 4325b6a6f1Skrish_iyer 44522c141dSAdrien Destugues status_t ExecuteCommand(uint16_t rca, uint8_t command, 45ff76d2dfSAdrien Destugues uint32_t argument, uint32_t* response); 469a37366bSAdrien Destugues status_t DoIO(uint16_t rca, uint8_t command, 47d1fee57dSAdrien Destugues IOOperation* operation, 48d1fee57dSAdrien Destugues bool offsetAsSectors); 4974b60970SAnarchos 50522c141dSAdrien Destugues void SetClock(int frequency); 51*34552f8eSAdrien Destugues void SetBusWidth(int width); 52522c141dSAdrien Destugues AcquireBus()5374b60970SAnarchos void AcquireBus() { acquire_sem(fLockSemaphore); } ReleaseBus()5474b60970SAnarchos void ReleaseBus() { release_sem(fLockSemaphore); } 5574b60970SAnarchos private: 5674b60970SAnarchos status_t _ActivateDevice(uint16_t rca); 5724136793SAdrien Destugues void _AcquireScanSemaphore(); 5874b60970SAnarchos static status_t _WorkerThread(void*); 59ff76d2dfSAdrien Destugues 60ff76d2dfSAdrien Destugues private: 6125b6a6f1Skrish_iyer 6225b6a6f1Skrish_iyer device_node* fNode; 63ff76d2dfSAdrien Destugues mmc_bus_interface* fController; 6425b6a6f1Skrish_iyer void* fCookie; 6525b6a6f1Skrish_iyer status_t fStatus; 66ff76d2dfSAdrien Destugues thread_id fWorkerThread; 6774b60970SAnarchos sem_id fScanSemaphore; 6874b60970SAnarchos sem_id fLockSemaphore; 6974b60970SAnarchos uint16 fActiveDevice; 7025b6a6f1Skrish_iyer }; 7125b6a6f1Skrish_iyer 7225b6a6f1Skrish_iyer 7325b6a6f1Skrish_iyer #endif /*MMC_BUS_H*/ 74