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