1 /* 2 * Copyright 2020, Jérôme Duval, jerome.duval@gmail.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "I2CPrivate.h" 8 9 10 device_manager_info *gDeviceManager = NULL; 11 12 13 // #pragma mark - 14 15 16 status_t 17 i2c_added_device(device_node *parent) 18 { 19 CALLED(); 20 21 int32 pathID = gDeviceManager->create_id(I2C_PATHID_GENERATOR); 22 if (pathID < 0) { 23 ERROR("cannot register i2c controller - out of path IDs\n"); 24 return B_ERROR; 25 } 26 27 device_attr attributes[] = { 28 // info about device 29 { B_DEVICE_PRETTY_NAME, B_STRING_TYPE, { .string = "I2C bus" }}, 30 { B_DEVICE_BUS, B_STRING_TYPE, { .string = "i2c" }}, 31 { I2C_BUS_PATH_ID_ITEM, B_UINT8_TYPE, { .ui8 = (uint8)pathID }}, 32 { NULL } 33 }; 34 35 TRACE("i2c_added_device parent %p\n", parent); 36 37 return gDeviceManager->register_node(parent, I2C_BUS_MODULE_NAME, 38 attributes, NULL, NULL); 39 } 40 41 42 status_t 43 i2c_register_device(i2c_bus _bus, i2c_addr slaveAddress, char* hid, 44 char** cid, acpi_handle acpiHandle) 45 { 46 CALLED(); 47 I2CBus* bus = (I2CBus*)_bus; 48 return bus->RegisterDevice(slaveAddress, hid, cid, acpiHandle); 49 } 50 51 52 static status_t 53 std_ops(int32 op, ...) 54 { 55 switch (op) { 56 case B_MODULE_INIT: 57 case B_MODULE_UNINIT: 58 return B_OK; 59 60 default: 61 break; 62 } 63 64 return B_ERROR; 65 } 66 67 68 // #pragma mark - 69 70 71 i2c_for_controller_interface gI2CForControllerModule = { 72 { 73 { 74 I2C_FOR_CONTROLLER_MODULE_NAME, 75 0, 76 &std_ops 77 }, 78 79 NULL, // supported devices 80 i2c_added_device, 81 NULL, 82 NULL, 83 NULL 84 }, 85 86 i2c_register_device, 87 }; 88 89 90 module_dependency module_dependencies[] = { 91 { B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&gDeviceManager }, 92 {} 93 }; 94 95 96 module_info *modules[] = { 97 (module_info *)&gI2CForControllerModule, 98 (module_info *)&gI2CBusModule, 99 (module_info *)&gI2CDeviceModule, 100 (module_info *)&gI2CBusRawModule, 101 NULL 102 }; 103 104