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 31extern device_manager_info *gDeviceManager; 32 33 34class MMCBus; 35 36class MMCBus { 37public: 38 39 MMCBus(device_node *node); 40 ~MMCBus(); 41 status_t InitCheck(); 42 void Rescan(); 43 44 status_t ExecuteCommand(uint16_t rca, uint8_t command, 45 uint32_t argument, uint32_t* response); 46 status_t DoIO(uint16_t rca, uint8_t command, 47 IOOperation* operation, 48 bool offsetAsSectors); 49 50 void SetClock(int frequency); 51 void SetBusWidth(int width); 52 53 void AcquireBus() { acquire_sem(fLockSemaphore); } 54 void ReleaseBus() { release_sem(fLockSemaphore); } 55private: 56 status_t _ActivateDevice(uint16_t rca); 57 void _AcquireScanSemaphore(); 58 static status_t _WorkerThread(void*); 59 60private: 61 62 device_node* fNode; 63 mmc_bus_interface* fController; 64 void* fCookie; 65 status_t fStatus; 66 thread_id fWorkerThread; 67 sem_id fScanSemaphore; 68 sem_id fLockSemaphore; 69 uint16 fActiveDevice; 70}; 71 72 73#endif /*MMC_BUS_H*/ 74