efc: turn on power of FMC peripheral

- Add efc's io expander method
- Enable VADJ, P3V3_FMC in satman main during startup
This commit is contained in:
linuswck 2023-08-01 00:29:45 +00:00 committed by GitHub
parent 72a5231493
commit cb547c8a46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 1 deletions

View File

@ -81,6 +81,32 @@ impl IoExpander {
Ok(io_expander) Ok(io_expander)
} }
#[cfg(soc_platform = "efc")]
pub fn new() -> Result<Self, &'static str> {
// TODO: Put Virtual User LEDs L0 L1 in gateware
const VIRTUAL_LED_MAPPING: [(u8, u8, u8); 2] = [(0, 0, 5), (1, 0, 6)];
let mut io_expander = IoExpander {
busno: 0,
port: 1,
address: 0x40,
virtual_led_mapping: &VIRTUAL_LED_MAPPING,
iodir: [0xff; 2],
out_current: [0; 2],
out_target: [0; 2],
registers: Registers {
iodira: 0x00,
iodirb: 0x01,
gpioa: 0x12,
gpiob: 0x13,
},
};
if !io_expander.check_ack()? {
return Err("MCP23017 io expander not found.");
};
Ok(io_expander)
}
#[cfg(soc_platform = "kasli")] #[cfg(soc_platform = "kasli")]
fn select(&self) -> Result<(), &'static str> { fn select(&self) -> Result<(), &'static str> {
let mask: u16 = 1 << self.port; let mask: u16 = 1 << self.port;
@ -89,6 +115,13 @@ impl IoExpander {
Ok(()) Ok(())
} }
#[cfg(soc_platform = "efc")]
fn select(&self) -> Result<(), &'static str> {
let mask: u16 = 1 << self.port;
i2c::switch_select(self.busno, 0x70, mask as u8)?;
Ok(())
}
fn write(&self, addr: u8, value: u8) -> Result<(), &'static str> { fn write(&self, addr: u8, value: u8) -> Result<(), &'static str> {
i2c::start(self.busno)?; i2c::start(self.busno)?;
i2c::write(self.busno, self.address)?; i2c::write(self.busno, self.address)?;

View File

@ -40,7 +40,7 @@ pub mod ethmac;
pub mod i2c; pub mod i2c;
#[cfg(soc_platform = "kasli")] #[cfg(soc_platform = "kasli")]
pub mod i2c_eeprom; pub mod i2c_eeprom;
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))] #[cfg(any(all(soc_platform = "kasli", hw_rev = "v2.0"), soc_platform = "efc"))]
pub mod io_expander; pub mod io_expander;
#[cfg(all(has_ethmac, feature = "smoltcp"))] #[cfg(all(has_ethmac, feature = "smoltcp"))]
pub mod net_settings; pub mod net_settings;

View File

@ -529,6 +529,19 @@ pub extern fn main() -> i32 {
sysclk_setup(); sysclk_setup();
#[cfg(soc_platform = "efc")]
{
let mut io_expander = board_misoc::io_expander::IoExpander::new().unwrap();
// Enable VADJ and P3V3_FMC
io_expander.set_oe(1, 1 << 0 | 1 << 1).unwrap();
io_expander.set(1, 0, true);
io_expander.set(1, 1, true);
io_expander.service().unwrap();
}
#[cfg(not(soc_platform = "efc"))]
unsafe { unsafe {
csr::drtio_transceiver::txenable_write(0xffffffffu32 as _); csr::drtio_transceiver::txenable_write(0xffffffffu32 as _);
} }