xref: /DragonOS/kernel/src/driver/input/serio/i8042/mod.rs (revision da152319797436368304cbc3f85a3b9ec049134b)
1 use alloc::sync::Arc;
2 use system_error::SystemError;
3 use unified_init::macros::unified_init;
4 
5 use crate::{
6     driver::{
7         base::{
8             device::{device_manager, Device},
9             kobject::KObject,
10             platform::{
11                 platform_device::{platform_device_manager, PlatformDevice},
12                 platform_driver::{platform_driver_manager, PlatformDriver},
13             },
14         },
15         input::ps2_mouse::ps_mouse_device::rs_ps2_mouse_device_init,
16     },
17     init::initcall::INITCALL_DEVICE,
18 };
19 
20 use self::{
21     i8042_device::I8042PlatformDevice, i8042_driver::I8042Driver, i8042_ports::I8042AuxPort,
22 };
23 
24 use super::serio_device::{serio_device_manager, SerioDevice};
25 
26 pub mod i8042_device;
27 pub mod i8042_driver;
28 pub mod i8042_ports;
29 
30 static mut I8042_PLATFORM_DEVICE: Option<Arc<I8042PlatformDevice>> = None;
31 
32 pub fn i8042_platform_device() -> Arc<I8042PlatformDevice> {
33     unsafe { I8042_PLATFORM_DEVICE.clone().unwrap() }
34 }
35 
36 // TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#1612
37 #[unified_init(INITCALL_DEVICE)]
38 pub fn i8042_init() -> Result<(), SystemError> {
39     kdebug!("i8042 initializing...");
40     let i8042_device = Arc::new(I8042PlatformDevice::new());
41     device_manager().device_default_initialize(&(i8042_device.clone() as Arc<dyn Device>));
42     platform_device_manager().device_add(i8042_device.clone() as Arc<dyn PlatformDevice>)?;
43     unsafe {
44         I8042_PLATFORM_DEVICE = Some(i8042_device);
45     }
46 
47     let i8042_driver = I8042Driver::new();
48     platform_driver_manager().register(i8042_driver.clone() as Arc<dyn PlatformDriver>)?;
49     Ok(())
50 }
51 
52 // TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#441
53 pub fn i8042_start(_serio: &Arc<dyn SerioDevice>) -> Result<(), SystemError> {
54     todo!()
55 }
56 
57 // TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#471
58 pub fn i8042_stop(_serio: &Arc<dyn SerioDevice>) -> Result<(), SystemError> {
59     todo!()
60 }
61 
62 /// # 函数的功能
63 /// 创建i8042 Aux设备
64 ///
65 /// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#i8042_setup_aux
66 pub fn i8042_setup_aux() -> Result<(), SystemError> {
67     let aux_port = Arc::new(I8042AuxPort::new());
68     aux_port.set_parent(Some(Arc::downgrade(
69         &(i8042_platform_device() as Arc<dyn KObject>),
70     )));
71     serio_device_manager().register_port(aux_port.clone() as Arc<dyn SerioDevice>)?;
72 
73     rs_ps2_mouse_device_init(aux_port.clone() as Arc<dyn KObject>)?;
74     Ok(())
75 }
76