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