1 use alloc::sync::Arc;
2 use system_error::SystemError;
3
4 use crate::driver::base::device::{
5 bus::Bus,
6 driver::{driver_manager, Driver},
7 };
8
9 use super::{serio_bus, serio_device::SerioDevice};
10
11 /// 实现该trait的设备驱动实例应挂载在serio总线上,同时应该实现Driver trait
12 ///
13 /// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/serio.h#67
14 #[allow(dead_code)]
15 pub trait SerioDriver: Driver {
16 // 写入时唤醒设备
write_wakeup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>17 fn write_wakeup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
18 /// # 函数功能
19 /// 中断函数
20 ///
21 /// ## 参数
22 /// - device: Serio设备
23 /// - data: 端口数据
24 /// - flag: 状态掩码
25 ///
26 /// ## 返回值
27 /// 无
28 ///
29 /// todo:https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c?fi=__serio_register_driver#989
interrupt( &self, device: &Arc<dyn SerioDevice>, data: u8, flag: u8, ) -> Result<(), SystemError>30 fn interrupt(
31 &self,
32 device: &Arc<dyn SerioDevice>,
33 data: u8,
34 flag: u8,
35 ) -> Result<(), SystemError>;
36 /// Serio驱动连接设备
connect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>37 fn connect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
38 /// 重新连接设备
reconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>39 fn reconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
40 /// 快速重连设备
fast_reconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>41 fn fast_reconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
42 /// 驱动断开设备
disconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>43 fn disconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
44 /// 清除设备状态
cleanup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>45 fn cleanup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
46 }
47
48 /// todo: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c#810
49 #[allow(dead_code)]
50 #[inline(always)]
serio_driver_manager() -> &'static SerioDriverManager51 pub fn serio_driver_manager() -> &'static SerioDriverManager {
52 &SerioDriverManager
53 }
54
55 pub struct SerioDriverManager;
56
57 #[allow(dead_code)]
58 impl SerioDriverManager {
59 /// # 函数功能
60 /// 注册Serio驱动
61 ///
62 /// ## 参数
63 /// - driver 待注册的Serio驱动
64 ///
65 /// ## 返回值
66 /// 无
register(&self, driver: Arc<dyn SerioDriver>) -> Result<(), SystemError>67 pub fn register(&self, driver: Arc<dyn SerioDriver>) -> Result<(), SystemError> {
68 driver.set_bus(Some(Arc::downgrade(&(serio_bus() as Arc<dyn Bus>))));
69 return driver_manager().register(driver as Arc<dyn Driver>);
70 }
71
72 /// # 函数功能
73 /// 卸载Serio驱动
74 ///
75 /// ## 参数
76 /// - driver 待卸载的Serio驱动
77 ///
78 /// ## 返回值
79 /// 无
80 #[allow(dead_code)]
unregister(&self, driver: &Arc<dyn SerioDriver>)81 pub fn unregister(&self, driver: &Arc<dyn SerioDriver>) {
82 driver_manager().unregister(&(driver.clone() as Arc<dyn Driver>));
83 }
84 }
85