strat9_bus_drivers/
ti_pwmss.rs1use crate::{BusChild, BusDriver, BusError, PowerState, mmio::MmioRegion};
2use alloc::{string::String, vec::Vec};
3
4const COMPATIBLE: &[&str] = &["ti,am33xx-pwmss"];
5
6pub struct TiPwmss {
7 regs: MmioRegion,
8 power_state: PowerState,
9 children: Vec<BusChild>,
10}
11
12impl TiPwmss {
13 pub fn new() -> Self {
15 Self {
16 regs: MmioRegion::new(),
17 power_state: PowerState::Off,
18 children: Vec::new(),
19 }
20 }
21
22 pub fn add_child(&mut self, child: BusChild) {
24 self.children.push(child);
25 }
26}
27
28impl BusDriver for TiPwmss {
29 fn name(&self) -> &str {
31 "ti-pwmss"
32 }
33
34 fn compatible(&self) -> &[&str] {
36 COMPATIBLE
37 }
38
39 fn init(&mut self, base: usize) -> Result<(), BusError> {
41 self.regs.init(base, 0x1000);
42 self.power_state = PowerState::On;
43 Ok(())
44 }
45
46 fn shutdown(&mut self) -> Result<(), BusError> {
48 self.power_state = PowerState::Off;
49 Ok(())
50 }
51
52 fn read_reg(&self, offset: usize) -> Result<u32, BusError> {
54 if !self.regs.is_valid() {
55 return Err(BusError::InitFailed);
56 }
57 Ok(self.regs.read32(offset))
58 }
59
60 fn write_reg(&mut self, offset: usize, value: u32) -> Result<(), BusError> {
62 if !self.regs.is_valid() {
63 return Err(BusError::InitFailed);
64 }
65 self.regs.write32(offset, value);
66 Ok(())
67 }
68
69 fn children(&self) -> Vec<BusChild> {
71 self.children.clone()
72 }
73}