Skip to content

Commit b4d5c3f

Browse files
authored
Separate device type and chip for power config (#1992)
On Gimlet and Sidecar, the mapping from `DeviceType` (CPU, memory, fans, etc) to chip (RAA229618, MAX5970, etc) was one-to-one. However, that's going to change for Cosmo (RAA229620A power controller, new hot-swap ICs, etc). This PR adds a separate `chip: DeviceChip` field to the (static) power controller configuration. It leaves the previous `DeviceType` field unchanged, although I'm not _totally_ sure if it's still relevant.
1 parent 75ab62f commit b4d5c3f

5 files changed

Lines changed: 52 additions & 31 deletions

File tree

task/power/src/bsp/gimlet_bcdef.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use crate::{
6-
i2c_config, i2c_config::sensors, Device, DeviceType, PowerControllerConfig,
7-
PowerState, SensorId,
6+
i2c_config, i2c_config::sensors, Device, PowerControllerConfig, PowerState,
7+
SensorId,
88
};
99

1010
use drv_i2c_devices::max5970::*;

task/power/src/bsp/gimletlet_2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::{
66
i2c_config::{self, sensors},
7-
DeviceType, Ohms, PowerControllerConfig, PowerState,
7+
Ohms, PowerControllerConfig, PowerState,
88
};
99

1010
pub(crate) const CONTROLLER_CONFIG_LEN: usize = 1;

task/power/src/bsp/psc_bc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::{
66
i2c_config::{self, sensors},
7-
DeviceType, PowerControllerConfig, PowerState,
7+
PowerControllerConfig, PowerState,
88
};
99

1010
pub(crate) const CONTROLLER_CONFIG_LEN: usize = 12;

task/power/src/bsp/sidecar_bcd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::{
66
i2c_config::{self, sensors},
7-
DeviceType, Ohms, PowerControllerConfig, PowerState,
7+
Ohms, PowerControllerConfig, PowerState,
88
};
99

1010
pub(crate) const CONTROLLER_CONFIG_LEN: usize = 16;

task/power/src/main.rs

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,30 @@ enum DeviceType {
6767
Mem,
6868
MemVpp,
6969
Sys,
70-
HotSwap(Ohms),
71-
Fan(Ohms),
72-
HotSwapIO(Ohms),
73-
HotSwapQSFP(Ohms),
70+
HotSwap,
71+
Fan,
72+
HotSwapIO,
73+
HotSwapQSFP,
7474
PowerShelf,
7575
}
7676

77+
/// Chip used to talk to the given device
78+
#[allow(dead_code)]
79+
enum DeviceChip {
80+
Bmr491,
81+
Raa229618,
82+
Isl68224,
83+
Tps546B24A,
84+
Adm1272(Ohms),
85+
Max5970(Ohms),
86+
Mwocp68,
87+
Ltc4282(Ohms),
88+
}
89+
7790
struct PowerControllerConfig {
7891
state: PowerState,
7992
device: DeviceType,
93+
chip: DeviceChip,
8094
builder: fn(TaskId) -> (drv_i2c_api::I2cDevice, u8), // device, rail
8195
voltage: SensorId,
8296
input_voltage: Option<SensorId>,
@@ -86,6 +100,7 @@ struct PowerControllerConfig {
86100
phases: Option<&'static [u8]>,
87101
}
88102

103+
/// Bound device, which exposes sensor functions
89104
enum Device {
90105
Bmr491(Bmr491),
91106
Raa229618(Raa229618),
@@ -227,23 +242,23 @@ impl Device {
227242
impl PowerControllerConfig {
228243
fn get_device(&self, task: TaskId) -> Device {
229244
let (dev, rail) = (self.builder)(task);
230-
match &self.device {
231-
DeviceType::IBC => Device::Bmr491(Bmr491::new(&dev, rail)),
232-
DeviceType::Core | DeviceType::Mem => {
245+
match &self.chip {
246+
DeviceChip::Bmr491 => Device::Bmr491(Bmr491::new(&dev, rail)),
247+
DeviceChip::Raa229618 => {
233248
Device::Raa229618(Raa229618::new(&dev, rail))
234249
}
235-
DeviceType::MemVpp | DeviceType::SerDes => {
236-
Device::Isl68224(Isl68224::new(&dev, rail))
250+
DeviceChip::Isl68224 => Device::Isl68224(Isl68224::new(&dev, rail)),
251+
DeviceChip::Tps546B24A => {
252+
Device::Tps546B24A(Tps546B24A::new(&dev, rail))
237253
}
238-
DeviceType::Sys => Device::Tps546B24A(Tps546B24A::new(&dev, rail)),
239-
DeviceType::HotSwap(sense) | DeviceType::Fan(sense) => {
254+
DeviceChip::Adm1272(sense) => {
240255
Device::Adm1272(Adm1272::new(&dev, *sense))
241256
}
242-
DeviceType::HotSwapIO(sense) => {
257+
DeviceChip::Max5970(sense) => {
243258
Device::Max5970(Max5970::new(&dev, rail, *sense))
244259
}
245-
DeviceType::PowerShelf => Device::Mwocp68(Mwocp68::new(&dev, rail)),
246-
DeviceType::HotSwapQSFP(sense) => {
260+
DeviceChip::Mwocp68 => Device::Mwocp68(Mwocp68::new(&dev, rail)),
261+
DeviceChip::Ltc4282(sense) => {
247262
Device::Ltc4282(Ltc4282::new(&dev, *sense))
248263
}
249264
}
@@ -255,8 +270,9 @@ macro_rules! rail_controller {
255270
($which:ident, $dev:ident, $rail:ident, $state:ident) => {
256271
paste::paste! {
257272
PowerControllerConfig {
258-
state: PowerState::$state,
259-
device: DeviceType::$which,
273+
state: $crate::PowerState::$state,
274+
device: $crate::DeviceType::$which,
275+
chip: $crate::DeviceChip::[< $dev:camel >],
260276
builder: i2c_config::pmbus::$rail,
261277
voltage: sensors::[<$dev:upper _ $rail:upper _VOLTAGE_SENSOR>],
262278
input_voltage: None,
@@ -276,8 +292,9 @@ macro_rules! rail_controller_notemp {
276292
($which:ident, $dev:ident, $rail:ident, $state:ident) => {
277293
paste::paste! {
278294
PowerControllerConfig {
279-
state: PowerState::$state,
280-
device: DeviceType::$which,
295+
state: $crate::PowerState::$state,
296+
device: $crate::DeviceType::$which,
297+
chip: $crate::DeviceChip::[< $dev:camel >],
281298
builder:i2c_config::pmbus::$rail,
282299
voltage: sensors::[<$dev:upper _ $rail:upper _VOLTAGE_SENSOR>],
283300
input_voltage: None,
@@ -295,8 +312,9 @@ macro_rules! adm1272_controller {
295312
($which:ident, $rail:ident, $state:ident, $rsense:expr) => {
296313
paste::paste! {
297314
PowerControllerConfig {
298-
state: PowerState::$state,
299-
device: DeviceType::$which($rsense),
315+
state: $crate::PowerState::$state,
316+
device: $crate::DeviceType::$which,
317+
chip: $crate::DeviceChip::Adm1272($rsense),
300318
builder: i2c_config::pmbus::$rail,
301319
voltage: sensors::[<ADM1272_ $rail:upper _VOLTAGE_SENSOR>],
302320
input_voltage: None,
@@ -316,8 +334,9 @@ macro_rules! ltc4282_controller {
316334
($which:ident, $rail:ident, $state:ident, $rsense:expr) => {
317335
paste::paste! {
318336
PowerControllerConfig {
319-
state: PowerState::$state,
320-
device: DeviceType::$which($rsense),
337+
state: $crate::PowerState::$state,
338+
device: $crate::DeviceType::$which,
339+
chip: $crate::DeviceChip::Ltc4282($rsense),
321340
builder: i2c_config::power::$rail,
322341
voltage: sensors::[<LTC4282_ $rail:upper _VOLTAGE_SENSOR>],
323342
input_voltage: None,
@@ -335,8 +354,9 @@ macro_rules! max5970_controller {
335354
($which:ident, $rail:ident, $state:ident, $rsense:expr) => {
336355
paste::paste! {
337356
PowerControllerConfig {
338-
state: PowerState::$state,
339-
device: DeviceType::$which($rsense),
357+
state: $crate::PowerState::$state,
358+
device: $crate::DeviceType::$which,
359+
chip: $crate::DeviceChip::Max5970($rsense),
340360
builder: i2c_config::power::$rail,
341361
voltage: sensors::[<MAX5970_ $rail:upper _VOLTAGE_SENSOR>],
342362
input_voltage: None,
@@ -354,8 +374,9 @@ macro_rules! mwocp68_controller {
354374
($which:ident, $rail:ident, $state:ident) => {
355375
paste::paste! {
356376
PowerControllerConfig {
357-
state: PowerState::$state,
358-
device: DeviceType::$which,
377+
state: $crate::PowerState::$state,
378+
device: $crate::DeviceType::$which,
379+
chip: $crate::DeviceChip::Mwocp68,
359380
builder: i2c_config::pmbus::$rail,
360381
voltage: sensors::[<MWOCP68_ $rail:upper _VOLTAGE_SENSOR>],
361382
input_voltage: Some(

0 commit comments

Comments
 (0)