1*d8e29bffSR0ronoa use alloc::sync::Arc; 2*d8e29bffSR0ronoa use system_error::SystemError; 3*d8e29bffSR0ronoa 4*d8e29bffSR0ronoa use crate::driver::base::device::{bus::Bus, Device}; 5*d8e29bffSR0ronoa 6*d8e29bffSR0ronoa use super::serio_bus; 7*d8e29bffSR0ronoa 8*d8e29bffSR0ronoa /// 串行设备,实现该trait的设备实例挂载在serio总线上,同时应该实现Device trait 9*d8e29bffSR0ronoa /// 10*d8e29bffSR0ronoa /// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/serio.h#20 11*d8e29bffSR0ronoa pub trait SerioDevice: Device { 12*d8e29bffSR0ronoa /// # 函数功能 13*d8e29bffSR0ronoa /// 14*d8e29bffSR0ronoa /// Serio设备写入数据 15*d8e29bffSR0ronoa /// 16*d8e29bffSR0ronoa /// ## 参数 17*d8e29bffSR0ronoa /// 18*d8e29bffSR0ronoa /// - data 写入的数据 19*d8e29bffSR0ronoa /// 20*d8e29bffSR0ronoa /// ## 返回值 21*d8e29bffSR0ronoa /// 22*d8e29bffSR0ronoa /// 无 23*d8e29bffSR0ronoa fn write(&self, device: &Arc<dyn SerioDevice>, data: u8) -> Result<(), SystemError>; 24*d8e29bffSR0ronoa /// Serio设备连接驱动时调用 25*d8e29bffSR0ronoa fn open(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 26*d8e29bffSR0ronoa /// Serio设备断开驱动时调用 27*d8e29bffSR0ronoa fn close(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 28*d8e29bffSR0ronoa /// Serio设备初始化时调用 29*d8e29bffSR0ronoa fn start(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 30*d8e29bffSR0ronoa /// Serio设备销毁时调用 31*d8e29bffSR0ronoa fn stop(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 32*d8e29bffSR0ronoa } 33*d8e29bffSR0ronoa 34*d8e29bffSR0ronoa #[allow(dead_code)] 35*d8e29bffSR0ronoa #[inline(always)] 36*d8e29bffSR0ronoa pub fn serio_device_manager() -> &'static SerioDeviceManager { 37*d8e29bffSR0ronoa &SerioDeviceManager 38*d8e29bffSR0ronoa } 39*d8e29bffSR0ronoa 40*d8e29bffSR0ronoa pub struct SerioDeviceManager; 41*d8e29bffSR0ronoa 42*d8e29bffSR0ronoa #[allow(dead_code)] 43*d8e29bffSR0ronoa impl SerioDeviceManager { 44*d8e29bffSR0ronoa /// # 函数功能 45*d8e29bffSR0ronoa /// 注册Serio设备 46*d8e29bffSR0ronoa /// 47*d8e29bffSR0ronoa /// ## 参数 48*d8e29bffSR0ronoa /// - device 待注册的设备 49*d8e29bffSR0ronoa /// 50*d8e29bffSR0ronoa /// ## 返回值 51*d8e29bffSR0ronoa /// 无 52*d8e29bffSR0ronoa pub fn register_port(&self, device: Arc<dyn SerioDevice>) -> Result<(), SystemError> { 53*d8e29bffSR0ronoa self.init_port(device) 54*d8e29bffSR0ronoa } 55*d8e29bffSR0ronoa 56*d8e29bffSR0ronoa /// # 函数功能 57*d8e29bffSR0ronoa /// 初始化Serio设备 58*d8e29bffSR0ronoa /// 59*d8e29bffSR0ronoa /// ## 参数 60*d8e29bffSR0ronoa /// - device 待初始化的Serio设备 61*d8e29bffSR0ronoa /// 62*d8e29bffSR0ronoa /// ## 返回值 63*d8e29bffSR0ronoa /// 无 64*d8e29bffSR0ronoa /// 65*d8e29bffSR0ronoa /// todo:https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c#494 66*d8e29bffSR0ronoa pub fn init_port(&self, device: Arc<dyn SerioDevice>) -> Result<(), SystemError> { 67*d8e29bffSR0ronoa device.set_bus(Some(Arc::downgrade(&(serio_bus() as Arc<dyn Bus>)))); 68*d8e29bffSR0ronoa Ok(()) 69*d8e29bffSR0ronoa } 70*d8e29bffSR0ronoa } 71