1use alloc::string::String;
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum Compatible {
6 CdnsQspiNor,
8 CdnsXspiNor,
10 CdnsUsb3,
12 DwApbI2c,
14 DwApbUart,
16 DwAxiDmac,
18 DwMac,
20 DwMmc,
22 Jh7110AonCrg,
24 Jh7110AonPinctrl,
26 Jh7110AonSyscon,
28 Jh7110Crypto,
30 Jh7110IspCrg,
32 Jh7110IspSyscon,
34 Jh7110MipiTxDphy,
36 Jh7110Pmu,
38 Jh7110StgCrg,
40 Jh7110StgSyscon,
42 Jh7110SysCrg,
44 Jh7110SysPinctrl,
46 Jh7110SysSyscon,
48 Jh7110Tdm,
50 Jh7110Trng,
52 Jh7110Usb,
54 Jh7110UsbPhy,
56 Jh7110VoutCrg,
58 Jh7110VoutSyscon,
60 Jh7110Wdt,
62 Pl022SspSpi,
64 Pl080Dmac,
66 RiscvClint,
68 RiscvPlic,
70 OcPwm,
72 OeOmc,
74 OeOphy,
76 SiFiveU74L2pm,
78 SiFiveU74Sram,
80 Unknown(String),
82 None,
84}
85
86impl Compatible {
87 pub const fn is_known(&self) -> bool {
89 !(matches!(self, Self::Unknown(_)) || matches!(self, Self::None))
90 }
91}
92
93impl From<&str> for Compatible {
94 fn from(val: &str) -> Self {
95 if val.contains("cdns,qspi-nor") {
96 Self::CdnsQspiNor
97 } else if val.contains("cdns,xspi-nor") {
98 Self::CdnsXspiNor
99 } else if val.contains("cdns,usb3") {
100 Self::CdnsUsb3
101 } else if val.contains("dw-apb-i2c") || val.contains("designware-i2c") {
102 Self::DwApbI2c
103 } else if val.contains("dw-apb-uart") {
104 Self::DwApbUart
105 } else if val.contains("snps,dw-axi-dmac") {
106 Self::DwAxiDmac
107 } else if val.contains("snps,dwmac") {
108 Self::DwMac
109 } else if val.contains("snps,dwmmc") || val.contains("starfive,jh7110-mmc") {
110 Self::DwMmc
112 } else if val.contains("starfive,jh7110-aoncrg") {
113 Self::Jh7110AonCrg
114 } else if val.contains("starfive,jh7110-aon-pinctrl") {
115 Self::Jh7110AonPinctrl
116 } else if val.contains("starfive,jh7110-aon-syscon") {
117 Self::Jh7110AonSyscon
118 } else if val.contains("starfive,jh7110-crypto") {
119 Self::Jh7110Crypto
120 } else if val.contains("starfive,jh7110-ispcrg") {
121 Self::Jh7110IspCrg
122 } else if val.contains("starfive,jh7110-isp-syscon") {
123 Self::Jh7110IspSyscon
124 } else if val.contains("starfive,jh7110-mipitx-dphy") {
125 Self::Jh7110MipiTxDphy
126 } else if val.contains("starfive,jh7110-pmu") {
127 Self::Jh7110Pmu
128 } else if val.contains("starfive,jh7110-stgcrg") {
129 Self::Jh7110StgCrg
130 } else if val.contains("starfive,jh7110-stg-syscon") {
131 Self::Jh7110StgSyscon
132 } else if val.contains("starfive,jh7110-syscrg") {
133 Self::Jh7110SysCrg
134 } else if val.contains("starfive,jh7110-sys-pinctrl") {
135 Self::Jh7110SysPinctrl
136 } else if val.contains("starfive,jh7110-sys-syscon") {
137 Self::Jh7110SysSyscon
138 } else if val.contains("starfive,jh7110-tdm") {
139 Self::Jh7110Tdm
140 } else if val.contains("starfive,jh7110-trng") {
141 Self::Jh7110Trng
142 } else if val.contains("starfive,jh7110-usb-phy") {
143 Self::Jh7110UsbPhy
144 } else if val.contains("starfive,jh7110-usb") {
145 Self::Jh7110Usb
146 } else if val.contains("starfive,jh7110-vout-syscon") {
147 Self::Jh7110VoutSyscon
148 } else if val.contains("starfive,jh7110-voutcrg") {
149 Self::Jh7110VoutCrg
150 } else if val.contains("starfive,jh7110-wdt") {
151 Self::Jh7110Wdt
152 } else if val.contains("arm,pl022") {
153 Self::Pl022SspSpi
154 } else if val.contains("arm,pl080") {
155 Self::Pl080Dmac
156 } else if val.contains("riscv,clint") {
157 Self::RiscvClint
158 } else if val.contains("riscv,plic") {
159 Self::RiscvPlic
160 } else if val.contains("opencores,pwm-v1") {
161 Self::OcPwm
162 } else if val.contains("openedges,omc") {
163 Self::OeOmc
164 } else if val.contains("openedges,ophy") {
165 Self::OeOphy
166 } else if val.contains("sifive,u74-mc-l2pm")
167 || val.contains("sifive,u74-l2pm")
168 || val.contains("sifive,ccache0")
169 {
170 Self::SiFiveU74L2pm
171 } else if val.contains("sifive,u74-mc-sram")
172 || val.contains("sifive,u74-sram")
173 || val.contains("sifive,u74-mc-l2-lim")
174 || val.contains("sifive,u74-l2-lim")
175 {
176 Self::SiFiveU74Sram
177 } else if val.is_empty() {
178 Self::None
179 } else {
180 Self::Unknown(val.into())
181 }
182 }
183}
184
185impl From<&Compatible> for &'static str {
186 fn from(val: &Compatible) -> Self {
187 match val {
188 Compatible::CdnsQspiNor => "cdns,qspi-nor",
189 Compatible::CdnsXspiNor => "cdns,xspi-nor",
190 Compatible::CdnsUsb3 => "cdns,usb3",
191 Compatible::DwApbI2c => "snps,dw-apb-i2c",
192 Compatible::DwApbUart => "snps,dw-apb-uart",
193 Compatible::DwAxiDmac => "snps,dw-axi-dmac",
194 Compatible::DwMac => "snps,dwmac",
195 Compatible::DwMmc => "snps,dwmmc",
196 Compatible::Jh7110AonCrg => "starfive,jh7110-aoncrg",
197 Compatible::Jh7110AonPinctrl => "starfive,jh7110-aon-pinctrl",
198 Compatible::Jh7110AonSyscon => "starfive,jh7110-aon-syscon",
199 Compatible::Jh7110Crypto => "starfive,jh7110-crypto",
200 Compatible::Jh7110IspCrg => "starfive,jh7110-ispcrg",
201 Compatible::Jh7110IspSyscon => "starfive,jh7110-isp-syscon",
202 Compatible::Jh7110MipiTxDphy => "starfive,jh7110-mipitx-dphy",
203 Compatible::Jh7110Pmu => "starfive,jh7110-pmu",
204 Compatible::Jh7110StgCrg => "starfive,jh7110-stgcrg",
205 Compatible::Jh7110StgSyscon => "starfive,jh7110-stg-syscon",
206 Compatible::Jh7110SysCrg => "starfive,jh7110-syscrg",
207 Compatible::Jh7110SysPinctrl => "starfive,jh7110-sys-pinctrl",
208 Compatible::Jh7110SysSyscon => "starfive,jh7110-sys-syscon",
209 Compatible::Jh7110Tdm => "starfive,jh7110-tdm",
210 Compatible::Jh7110Trng => "starfive,jh7110-trng",
211 Compatible::Jh7110UsbPhy => "starfive,jh7110-usb-phy",
212 Compatible::Jh7110Usb => "starfive,jh7110-usb",
213 Compatible::Jh7110VoutSyscon => "starfive,jh7110-vout-syscon",
214 Compatible::Jh7110VoutCrg => "starfive,jh7110-voutcrg",
215 Compatible::Jh7110Wdt => "starfive,jh7110-wdt",
216 Compatible::Pl022SspSpi => "arm,pl022",
217 Compatible::Pl080Dmac => "arm,pl080",
218 Compatible::RiscvClint => "riscv,clint",
219 Compatible::RiscvPlic => "riscv,plic",
220 Compatible::OcPwm => "opencores,pwm-v1",
221 Compatible::OeOmc => "openedges,omc",
222 Compatible::OeOphy => "openedges,ophy",
223 Compatible::SiFiveU74L2pm => "sifive,u74-",
224 Compatible::SiFiveU74Sram => "sifive,u74-sram",
225 Compatible::Unknown(_val) => "unknown",
226 Compatible::None => "",
227 }
228 }
229}
230
231impl From<Compatible> for &'static str {
232 fn from(val: Compatible) -> Self {
233 (&val).into()
234 }
235}
236
237impl<'b, 'a: 'b> From<&fdt::node::FdtNode<'b, 'a>> for Compatible {
238 fn from(val: &fdt::node::FdtNode<'b, 'a>) -> Self {
239 match val.property("compatible") {
240 Some(compatible) => match compatible.as_str() {
241 Some(comp) => Compatible::from(comp),
242 None => Self::None,
243 },
244 None => Self::None,
245 }
246 }
247}
248
249impl<'b, 'a: 'b> From<fdt::node::FdtNode<'b, 'a>> for Compatible {
250 fn from(val: fdt::node::FdtNode<'b, 'a>) -> Self {
251 (&val).into()
252 }
253}