Skip to content

Commit fed9e2c

Browse files
committed
system: determine the LXA TAC hardware generation from devicetree
Signed-off-by: Leonard Göhrs <[email protected]>
1 parent 3beae6a commit fed9e2c

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,21 @@ paths:
347347
schema:
348348
type: string
349349

350+
/v1/tac/info/hardware_generation:
351+
get:
352+
summary: Get the LXA TAC hardware generation
353+
tags: [System]
354+
responses:
355+
'200':
356+
content:
357+
application/json:
358+
schema:
359+
type: string
360+
enum:
361+
- Gen1
362+
- Gen2
363+
- Gen3
364+
350365
/v1/tac/setup_mode:
351366
get:
352367
summary: Check if the TAC has completed the set up or is still in setup mode

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use iobus::IoBus;
5050
use led::Led;
5151
use regulators::Regulators;
5252
use setup_mode::SetupMode;
53-
use system::System;
53+
use system::{HardwareGeneration, System};
5454
use temperatures::Temperatures;
5555
use ui::{message, setup_display, ScreenShooter, Ui, UiResources};
5656
use usb_hub::UsbHub;
@@ -68,6 +68,10 @@ async fn init(screenshooter: ScreenShooter) -> Result<(Ui, WatchedTasksBuilder)>
6868
// The topics are also used to pass around data inside the tacd.
6969
let mut bb = BrokerBuilder::new();
7070

71+
// We need to know which generation of LXA TAC we are running on at various
72+
// places in the init process.
73+
let hardware_generation = HardwareGeneration::get()?;
74+
7175
// Expose hardware on the TAC via the broker framework.
7276
let backlight = Backlight::new(&mut bb, &mut wtb)?;
7377
let led = Led::new(&mut bb, &mut wtb)?;
@@ -110,7 +114,7 @@ async fn init(screenshooter: ScreenShooter) -> Result<(Ui, WatchedTasksBuilder)>
110114

111115
// Expose information about the system provided by the kernel via the
112116
// broker framework.
113-
let system = System::new(&mut bb);
117+
let system = System::new(&mut bb, hardware_generation);
114118

115119
// Make sure the ADC and power switching threads of the tacd are not
116120
// stalled for too long by providing watchdog events to systemd

src/system.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// with this program; if not, write to the Free Software Foundation, Inc.,
1616
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

18+
use anyhow::{bail, Result};
1819
use async_std::sync::Arc;
1920
use nix::sys::utsname::uname;
2021
use serde::{Deserialize, Serialize};
@@ -24,6 +25,10 @@ use crate::broker::{BrokerBuilder, Topic};
2425
#[cfg(feature = "demo_mode")]
2526
mod read_dt_props {
2627
const DEMO_DATA_STR: &[(&str, &str)] = &[
28+
(
29+
"compatible",
30+
"lxa,stm32mp153c-tac-gen3\0oct,stm32mp15xx-osd32\0st,stm32mp153",
31+
),
2732
("chosen/barebox-version", "barebox-2022.11.0-20221121-1"),
2833
(
2934
"chosen/baseboard-factory-data/pcba-hardware-release",
@@ -141,23 +146,53 @@ impl Barebox {
141146
}
142147
}
143148

149+
#[derive(Clone, Copy, Serialize, Deserialize)]
150+
pub enum HardwareGeneration {
151+
Gen1,
152+
Gen2,
153+
Gen3,
154+
}
155+
156+
impl HardwareGeneration {
157+
pub fn get() -> Result<Self> {
158+
let compatible = read_dt_property("compatible");
159+
160+
// The compatible property consists of strings separated by NUL bytes.
161+
// We are interested in the first of these strings.
162+
let device = compatible.split('\0').next().unwrap_or("<empty>");
163+
164+
match device {
165+
"lxa,stm32mp157c-tac-gen1" => Ok(Self::Gen1),
166+
"lxa,stm32mp157c-tac-gen2" => Ok(Self::Gen2),
167+
"lxa,stm32mp153c-tac-gen3" => Ok(Self::Gen3),
168+
gen => bail!("Running on unknown LXA TAC hardware generation \"{gen}\""),
169+
}
170+
}
171+
}
172+
144173
pub struct System {
145174
#[allow(dead_code)]
146175
pub uname: Arc<Topic<Arc<Uname>>>,
147176
#[allow(dead_code)]
148177
pub barebox: Arc<Topic<Arc<Barebox>>>,
149178
#[allow(dead_code)]
150179
pub tacd_version: Arc<Topic<String>>,
180+
#[allow(dead_code)]
181+
pub hardware_generation: Arc<Topic<HardwareGeneration>>,
151182
}
152183

153184
impl System {
154-
pub fn new(bb: &mut BrokerBuilder) -> Self {
185+
pub fn new(bb: &mut BrokerBuilder, hardware_generation: HardwareGeneration) -> Self {
155186
let version = env!("VERSION_STRING").to_string();
156187

157188
Self {
158189
uname: bb.topic_ro("/v1/tac/info/uname", Some(Arc::new(Uname::get()))),
159190
barebox: bb.topic_ro("/v1/tac/info/bootloader", Some(Arc::new(Barebox::get()))),
160191
tacd_version: bb.topic_ro("/v1/tac/info/tacd/version", Some(version)),
192+
hardware_generation: bb.topic_ro(
193+
"/v1/tac/info/hardware_generation",
194+
Some(hardware_generation),
195+
),
161196
}
162197
}
163198
}

0 commit comments

Comments
 (0)