Skip to main content

strat9_bus_drivers/
imx_aipstz.rs

1use crate::{BusChild, BusDriver, BusError, PowerState, mmio::MmioRegion};
2use alloc::{string::String, vec::Vec};
3
4const IMX_AIPSTZ_MPR0: usize = 0x00;
5
6const COMPATIBLE: &[&str] = &["fsl,imx8mp-aipstz"];
7
8pub struct AipstzConfig {
9    pub mpr0: u32,
10}
11
12pub const IMX8MP_DEFAULT_CFG: AipstzConfig = AipstzConfig { mpr0: 0x7777_7777 };
13
14pub struct ImxAipstz {
15    regs: MmioRegion,
16    config: AipstzConfig,
17    power_state: PowerState,
18    children: Vec<BusChild>,
19}
20
21impl ImxAipstz {
22    /// Creates a new instance.
23    pub fn new(config: AipstzConfig) -> Self {
24        Self {
25            regs: MmioRegion::new(),
26            config,
27            power_state: PowerState::Off,
28            children: Vec::new(),
29        }
30    }
31
32    /// Performs the apply config operation.
33    fn apply_config(&self) {
34        if !self.regs.is_valid() {
35            return;
36        }
37        self.regs.write32(IMX_AIPSTZ_MPR0, self.config.mpr0);
38    }
39
40    /// Performs the add child operation.
41    pub fn add_child(&mut self, child: BusChild) {
42        self.children.push(child);
43    }
44}
45
46impl BusDriver for ImxAipstz {
47    /// Performs the name operation.
48    fn name(&self) -> &str {
49        "imx-aipstz"
50    }
51
52    /// Performs the compatible operation.
53    fn compatible(&self) -> &[&str] {
54        COMPATIBLE
55    }
56
57    /// Performs the init operation.
58    fn init(&mut self, base: usize) -> Result<(), BusError> {
59        self.regs.init(base, 0x100);
60        self.apply_config();
61        self.power_state = PowerState::On;
62        Ok(())
63    }
64
65    /// Performs the shutdown operation.
66    fn shutdown(&mut self) -> Result<(), BusError> {
67        self.power_state = PowerState::Off;
68        Ok(())
69    }
70
71    /// Performs the resume operation.
72    fn resume(&mut self) -> Result<(), BusError> {
73        self.apply_config();
74        self.power_state = PowerState::On;
75        Ok(())
76    }
77
78    /// Reads reg.
79    fn read_reg(&self, offset: usize) -> Result<u32, BusError> {
80        if !self.regs.is_valid() {
81            return Err(BusError::InitFailed);
82        }
83        Ok(self.regs.read32(offset))
84    }
85
86    /// Writes reg.
87    fn write_reg(&mut self, offset: usize, value: u32) -> Result<(), BusError> {
88        if !self.regs.is_valid() {
89            return Err(BusError::InitFailed);
90        }
91        self.regs.write32(offset, value);
92        Ok(())
93    }
94
95    /// Performs the children operation.
96    fn children(&self) -> Vec<BusChild> {
97        self.children.clone()
98    }
99}