Skip to content

Commit

Permalink
Implemented v2.5 changes
Browse files Browse the repository at this point in the history
Changes to the `PinController` and `PowerController`.

* The `bmcd` remains fully compatible with v2.4 and v2.5 hardware.
* The additional Node1 USB source switching for v2.5 is
not yet implemented. The switches are currently configured so that: USB0 is routed to the
usb hub and usb2 is routed to the USB-A port.
* The actual location of gpio pins inside gpiod is still tentative at
  this point for TPv2.5.
  • Loading branch information
svenrademakers committed Feb 16, 2024
1 parent 06d2f2a commit cf7cc76
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 78 deletions.
6 changes: 3 additions & 3 deletions src/api/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ async fn set_usb_mode(bmc: &BmcApplication, query: Query) -> LegacyResult<()> {
let route = if (mode_num >> 2) & 0x1 == 1 {
UsbRoute::Bmc
} else {
UsbRoute::UsbA
UsbRoute::AlternativePort
};

let cfg = match (mode, route) {
(UsbMode::Device, UsbRoute::UsbA) => UsbConfig::UsbA(node),
(UsbMode::Device, UsbRoute::AlternativePort) => UsbConfig::UsbA(node),
(UsbMode::Device, UsbRoute::Bmc) => UsbConfig::Bmc(node),
(UsbMode::Host, route) => UsbConfig::Node(node, route),
(UsbMode::Flash, route) => UsbConfig::Flashing(node, route),
Expand All @@ -479,7 +479,7 @@ async fn get_usb_mode(bmc: &BmcApplication) -> impl Into<LegacyResponse> {
let config = bmc.get_usb_mode().await;

let (node, mode, route) = match config {
UsbConfig::UsbA(node) => (node, UsbMode::Device, UsbRoute::UsbA),
UsbConfig::UsbA(node) => (node, UsbMode::Device, UsbRoute::AlternativePort),
UsbConfig::Bmc(node) => (node, UsbMode::Device, UsbRoute::Bmc),
UsbConfig::Node(node, route) => (node, UsbMode::Host, route),
UsbConfig::Flashing(node, route) => (node, UsbMode::Flash, route),
Expand Down
10 changes: 6 additions & 4 deletions src/app/bmc_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ pub struct BmcApplication {

impl BmcApplication {
pub async fn new(database_write_timeout: Option<Duration>) -> anyhow::Result<Self> {
let pin_controller = PinController::new().context("pin_controller")?;
let power_controller = PowerController::new().context("power_controller")?;
let model_string = std::fs::read_to_string("/proc/device-tree/model");
let is_legacy_dts = matches!(model_string, Ok(model) if model.contains("v2.4"));
let pin_controller = PinController::new(is_legacy_dts).context("pin_controller")?;
let power_controller = PowerController::new(is_legacy_dts).context("power_controller")?;
let app_db = PersistencyBuilder::default()
.register_key(ACTIVATED_NODES_KEY, &0u8)
.register_key(USB_CONFIG, &UsbConfig::UsbA(NodeId::Node1))
Expand Down Expand Up @@ -210,7 +212,7 @@ impl BmcApplication {
async fn configure_usb_internal(&self, config: UsbConfig) -> anyhow::Result<()> {
log::info!("changing usb config to {:?}", config);
let (mode, dest, route) = match config {
UsbConfig::UsbA(device) => (UsbMode::Device, device, UsbRoute::UsbA),
UsbConfig::UsbA(device) => (UsbMode::Device, device, UsbRoute::AlternativePort),
UsbConfig::Bmc(device) => (UsbMode::Device, device, UsbRoute::Bmc),
UsbConfig::Flashing(device, route) => (UsbMode::Flash, device, route),
UsbConfig::Node(host, route) => (UsbMode::Host, host, route),
Expand All @@ -222,7 +224,7 @@ impl BmcApplication {
}
}

self.pin_controller.set_usb_route(route).await?;
self.pin_controller.set_usb_route(route)?;
self.pin_controller.select_usb(dest, mode)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub enum NodeType {
#[derive(Debug, Eq, PartialEq, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub enum UsbRoute {
Bmc,
UsbA,
AlternativePort,
}

#[derive(Debug, Eq, PartialEq, Clone, Copy, serde::Serialize, serde::Deserialize)]
Expand Down
4 changes: 4 additions & 0 deletions src/hal/gpio_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//! This module contains static pin numbers related to GPIO
pub const GPIO_PIN_PG: u32 = 192;

#[allow(unused)]
pub const RTL_RESET: u32 = GPIO_PIN_PG + 13;
#[allow(unused)]
pub const SYS_RESET: u32 = GPIO_PIN_PG + 11;
Expand All @@ -27,3 +28,6 @@ pub const USB_OE1: u32 = GPIO_PIN_PG + 2;
pub const USB_OE2: u32 = GPIO_PIN_PG + 3;

pub const USB_SWITCH: u32 = GPIO_PIN_PG + 5;
pub const USB_SWITCH_V2_5: u32 = GPIO_PIN_PG + 2;
pub const NODE1_OUTPUT_SWITCH_V2_5: u32 = GPIO_PIN_PG;
pub const NODE1_SOURCE_SWITCH_V2_5: u32 = GPIO_PIN_PG + 1;

0 comments on commit cf7cc76

Please sign in to comment.