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