1 /* 2 * Copyright 2018 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * B Krishnan Iyer, krishnaniyer97@gmail.com 7 */ 8 #ifndef MMC_BUS_H 9 #define MMC_BUS_H 10 11 12 #include <new> 13 #include <stdio.h> 14 #include <string.h> 15 16 #include <lock.h> 17 #include <util/AutoLock.h> 18 #include "mmc.h" 19 20 21 #define MMCBUS_TRACE 22 #ifdef MMCBUS_TRACE 23 # define TRACE(x...) dprintf("\33[33mmmc_bus:\33[0m " x) 24 #else 25 # define TRACE(x...) 26 #endif 27 #define TRACE_ALWAYS(x...) dprintf("\33[33mmmc_bus:\33[0m " x) 28 #define ERROR(x...) dprintf("\33[33mmmc_bus:\33[0m " x) 29 #define CALLED() TRACE("CALLED %s\n", __PRETTY_FUNCTION__) 30 31 extern device_manager_info *gDeviceManager; 32 33 34 class MMCBus; 35 36 class MMCBus { 37 public: 38 39 MMCBus(device_node *node); 40 ~MMCBus(); 41 status_t InitCheck(); 42 void Rescan(); 43 44 status_t ExecuteCommand(uint8_t command, 45 uint32_t argument, uint32_t* response); 46 status_t Read(uint16_t rca, off_t position, void* buffer, 47 size_t* length); 48 49 void AcquireBus() { acquire_sem(fLockSemaphore); } 50 void ReleaseBus() { release_sem(fLockSemaphore); } 51 private: 52 status_t _ActivateDevice(uint16_t rca); 53 static status_t _WorkerThread(void*); 54 55 private: 56 57 device_node* fNode; 58 mmc_bus_interface* fController; 59 void* fCookie; 60 status_t fStatus; 61 thread_id fWorkerThread; 62 sem_id fScanSemaphore; 63 sem_id fLockSemaphore; 64 uint16 fActiveDevice; 65 }; 66 67 68 #endif /*MMC_BUS_H*/ 69