firmware: factor out mod pca9548 from si5324

orepares for further i2c devices.
pull/1356/head
Astro 2019-08-13 00:33:11 +02:00 committed by Sébastien Bourdeauducq
parent e9b78b62db
commit d666f3d573
3 changed files with 24 additions and 21 deletions

View File

@ -25,6 +25,11 @@ pub mod mailbox;
#[cfg(has_kernel_cpu)]
pub mod rpc_queue;
#[cfg(any(soc_platform = "kasli",
soc_platform = "sayma_amc",
soc_platform = "sayma_rtm",
soc_platform = "kc705"))]
mod pca9548;
#[cfg(has_si5324)]
pub mod si5324;

View File

@ -0,0 +1,13 @@
use i2c;
pub fn select(busno: u8, address: u8, channels: u8) -> Result<(), &'static str> {
i2c::start(busno).unwrap();
if !i2c::write(busno, address << 1).unwrap() {
return Err("PCA9548 failed to ack write address")
}
if !i2c::write(busno, channels).unwrap() {
return Err("PCA9548 failed to ack control word")
}
i2c::stop(busno).unwrap();
Ok(())
}

View File

@ -3,28 +3,13 @@ use board_misoc::clock;
#[cfg(not(si5324_soft_reset))]
use board_misoc::csr;
use i2c;
use pca9548;
type Result<T> = result::Result<T, &'static str>;
const BUSNO: u8 = 0;
const ADDRESS: u8 = 0x68;
#[cfg(any(soc_platform = "kasli",
soc_platform = "sayma_amc",
soc_platform = "sayma_rtm",
soc_platform = "kc705"))]
fn pca9548_select(address: u8, channels: u8) -> Result<()> {
i2c::start(BUSNO).unwrap();
if !i2c::write(BUSNO, address << 1).unwrap() {
return Err("PCA9548 failed to ack write address")
}
if !i2c::write(BUSNO, channels).unwrap() {
return Err("PCA9548 failed to ack control word")
}
i2c::stop(BUSNO).unwrap();
Ok(())
}
#[cfg(not(si5324_soft_reset))]
fn hard_reset() {
unsafe { csr::si5324_rst_n::out_write(0); }
@ -196,15 +181,15 @@ fn init() -> Result<()> {
#[cfg(soc_platform = "kasli")]
{
pca9548_select(0x70, 0)?;
pca9548_select(0x71, 1 << 3)?;
pca9548::select(BUSNO, 0x70, 0)?;
pca9548::select(BUSNO, 0x71, 1 << 3)?;
}
#[cfg(soc_platform = "sayma_amc")]
pca9548_select(0x70, 1 << 4)?;
pca9548::select(BUSNO, 0x70, 1 << 4)?;
#[cfg(soc_platform = "sayma_rtm")]
pca9548_select(0x77, 1 << 5)?;
pca9548::select(BUSNO, 0x77, 1 << 5)?;
#[cfg(soc_platform = "kc705")]
pca9548_select(0x74, 1 << 7)?;
pca9548::select(BUSNO, 0x74, 1 << 7)?;
if ident()? != 0x0182 {
return Err("Si5324 does not have expected product number");