From cfffd9e13d7d9a33817edfbb4a6274da9d6b139f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 23 Jan 2018 13:16:34 +0800 Subject: [PATCH] si5324: kasli support --- artiq/firmware/libboard_artiq/si5324.rs | 49 +++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/artiq/firmware/libboard_artiq/si5324.rs b/artiq/firmware/libboard_artiq/si5324.rs index 574e1ba53..147cb2302 100644 --- a/artiq/firmware/libboard_artiq/si5324.rs +++ b/artiq/firmware/libboard_artiq/si5324.rs @@ -1,5 +1,7 @@ use core::result; -use board::{csr, clock}; +use board::clock; +#[cfg(not(si5324_soft_reset))] +use board::csr; use i2c; type Result = result::Result; @@ -7,23 +9,27 @@ type Result = result::Result; const BUSNO: u8 = 0; const ADDRESS: u8 = 0x68; -#[cfg(any(soc_platform = "sayma_amc", soc_platform = "kc705"))] -fn pca9548_select(address: u8, channel: u8) -> Result<()> { +#[cfg(any(soc_platform = "kasli", + soc_platform = "sayma_amc", + 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, 1 << channel).unwrap() { + if !i2c::write(BUSNO, channels).unwrap() { return Err("PCA9548 failed to ack control word") } i2c::stop(BUSNO).unwrap(); Ok(()) } -fn reset(en: bool) { - unsafe { - csr::si5324_rst_n::out_write(if en { 0 } else { 1 }) - } +#[cfg(not(si5324_soft_reset))] +fn hard_reset() { + unsafe { csr::si5324_rst_n::out_write(0); } + clock::spin_us(1_000); + unsafe { csr::si5324_rst_n::out_write(1); } + clock::spin_us(10_000); } // NOTE: the logical parameters DO NOT MAP to physical values written @@ -127,6 +133,13 @@ fn ident() -> Result { Ok(((read(134)? as u16) << 8) | (read(135)? as u16)) } +#[cfg(si5324_soft_reset)] +fn soft_reset() -> Result<()> { + write(136, read(136)? | 0x80)?; + clock::spin_us(10_000); + Ok(()) +} + fn has_xtal() -> Result { Ok((read(129)? & 0x01) == 0) // LOSX_INT=0 } @@ -154,20 +167,26 @@ fn monitor_lock() -> Result<()> { pub fn setup(settings: &FrequencySettings) -> Result<()> { let s = map_frequency_settings(settings)?; - reset(true); - clock::spin_us(1_000); - reset(false); - clock::spin_us(10_000); + #[cfg(not(si5324_soft_reset))] + hard_reset(); - #[cfg(soc_platform = "kc705")] - pca9548_select(0x74, 7)?; + #[cfg(soc_platform = "kasli")] + { + pca9548_select(0x70, 0)?; + pca9548_select(0x71, 1 << 3)?; + } #[cfg(soc_platform = "sayma_amc")] - pca9548_select(0x70, 4)?; + pca9548_select(0x70, 1 << 4)?; + #[cfg(soc_platform = "kc705")] + pca9548_select(0x74, 1 << 7)?; if ident()? != 0x0182 { return Err("Si5324 does not have expected product number"); } + #[cfg(si5324_soft_reset)] + soft_reset()?; + write(0, read(0)? | 0x40)?; // FREE_RUN=1 write(2, (read(2)? & 0x0f) | (s.bwsel << 4))?; write(21, read(21)? & 0xfe)?; // CKSEL_PIN=0