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 pub trait SerioDriver: Driver { 15 // 写入时唤醒设备 16 fn write_wakeup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 17 /// # 函数功能 18 /// 中断函数 19 /// 20 /// ## 参数 21 /// - device: Serio设备 22 /// - data: 端口数据 23 /// - flag: 状态掩码 24 /// 25 /// ## 返回值 26 /// 无 27 fn interrupt( 28 &self, 29 device: &Arc<dyn SerioDevice>, 30 data: u8, 31 flag: u8, 32 ) -> Result<(), SystemError>; 33 /// Serio驱动连接设备 34 fn connect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 35 /// 重新连接设备 36 fn reconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 37 /// 快速重连设备 38 fn fast_reconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 39 /// 驱动断开设备 40 fn disconnect(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 41 /// 清除设备状态 42 fn cleanup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 43 } 44 45 ///todo: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c#810 46 pub struct SerioDriverManager; 47 48 #[allow(dead_code)] 49 impl SerioDriverManager { 50 /// # 函数功能 51 /// 注册Serio驱动 52 /// 53 /// ## 参数 54 /// - driver 待注册的Serio驱动 55 /// 56 /// ## 返回值 57 /// 无 58 pub fn register(&self, driver: Arc<dyn SerioDriver>) -> Result<(), SystemError> { 59 driver.set_bus(Some(Arc::downgrade(&(serio_bus() as Arc<dyn Bus>)))); 60 return driver_manager().register(driver as Arc<dyn Driver>); 61 } 62 63 /// # 函数功能 64 /// 卸载Serio驱动 65 /// 66 /// ## 参数 67 /// - driver 待卸载的Serio驱动 68 /// 69 /// ## 返回值 70 /// 无 71 #[allow(dead_code)] 72 pub fn unregister(&self, driver: &Arc<dyn SerioDriver>) { 73 driver_manager().unregister(&(driver.clone() as Arc<dyn Driver>)); 74 } 75 } 76