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 #include "mmc_bus.h" 9 10 11 #define MMC_BUS_DEVICE_NAME "bus_managers/mmc_bus/device/v1" 12 13 14 device_manager_info* gDeviceManager = NULL; 15 16 17 static status_t 18 mmc_bus_init(device_node* node, void** _device) 19 { 20 CALLED(); 21 MMCBus* device = new(std::nothrow) MMCBus(node); 22 if (device == NULL) { 23 ERROR("Unable to allocate MMC bus\n"); 24 return B_NO_MEMORY; 25 } 26 27 status_t result = device->InitCheck(); 28 if (result != B_OK) { 29 TRACE("failed to set up mmc bus device object\n"); 30 return result; 31 } 32 TRACE("MMC bus object created\n"); 33 34 *_device = device; 35 return B_OK; 36 } 37 38 39 static void 40 mmc_bus_uninit(void* _device) 41 { 42 CALLED(); 43 MMCBus* device = (MMCBus*)_device; 44 delete device; 45 } 46 47 48 static void 49 mmc_bus_removed(void* _device) 50 { 51 CALLED(); 52 } 53 54 55 status_t 56 mmc_bus_added_device(device_node* parent) 57 { 58 CALLED(); 59 60 device_attr attributes[] = { 61 { B_DEVICE_BUS, B_STRING_TYPE, { string: "mmc bus"}}, 62 { NULL } 63 }; 64 65 return gDeviceManager->register_node(parent, MMC_BUS_DEVICE_NAME, 66 attributes, NULL, NULL); 67 } 68 69 70 static status_t 71 std_ops(int32 op, ...) 72 { 73 switch (op) { 74 case B_MODULE_INIT: 75 // Nothing to do 76 case B_MODULE_UNINIT: 77 return B_OK; 78 79 default: 80 break; 81 } 82 83 return B_ERROR; 84 } 85 86 87 driver_module_info mmc_bus_device_module = { 88 { 89 MMC_BUS_DEVICE_NAME, 90 0, 91 std_ops 92 }, 93 NULL, // supported devices 94 NULL, // register node 95 mmc_bus_init, 96 mmc_bus_uninit, 97 NULL, // register child devices 98 NULL, // rescan 99 mmc_bus_removed, 100 NULL, // suspend 101 NULL // resume 102 }; 103 104 105 driver_module_info mmc_bus_controller_module = { 106 { 107 MMC_BUS_MODULE_NAME, 108 0, 109 &std_ops 110 }, 111 112 NULL, // supported devices 113 mmc_bus_added_device, 114 NULL, 115 NULL, 116 NULL 117 }; 118 119 120 module_dependency module_dependencies[] = { 121 { B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&gDeviceManager }, 122 {} 123 }; 124 125 126 module_info* modules[] = { 127 (module_info*)&mmc_bus_controller_module, 128 (module_info*)&mmc_bus_device_module, 129 NULL 130 }; 131