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