@@ -16,7 +16,8 @@ pub use embedded_hal_nb::nb::block;
16
16
pub use embedded_hal_nb:: serial:: ErrorKind ;
17
17
18
18
use aux_mini:: AuxMini ;
19
- use fdt_parser:: { Chosen , Fdt , Node } ;
19
+ pub use fdt_parser:: Node ;
20
+ use fdt_parser:: { Chosen , Fdt } ;
20
21
use ns16550:: Ns16550 ;
21
22
use pl011:: Pl011 ;
22
23
@@ -35,7 +36,7 @@ pub struct Uart {
35
36
}
36
37
37
38
impl Uart {
38
- fn new < C : Console > ( data : UartData ) -> Self {
39
+ fn _new < C : Console > ( data : UartData ) -> Self {
39
40
let op = C :: to_op ( ) ;
40
41
41
42
Self {
@@ -46,6 +47,33 @@ impl Uart {
46
47
}
47
48
}
48
49
50
+ pub fn new_by_fdt_node ( node : & Node < ' _ > , f : FnPhysToVirt ) -> Option < Self > {
51
+ let reg = node. reg ( ) ?. next ( ) ?;
52
+
53
+ let io_kind = IoKind :: Mmio32 ;
54
+
55
+ // TODO: support io kind detect
56
+
57
+ let uart = UartData :: new ( reg. address , io_kind, f) ;
58
+
59
+ for c in node. compatibles ( ) {
60
+ macro_rules! of_uart {
61
+ ( $name: ty, $compatible: expr) => {
62
+ for want in $compatible {
63
+ if c. contains( want) {
64
+ return Some ( Uart :: _new:: <$name>( uart) ) ;
65
+ }
66
+ }
67
+ } ;
68
+ }
69
+
70
+ of_uart ! ( AuxMini , [ "brcm,bcm2835-aux-uart" ] ) ;
71
+ of_uart ! ( Pl011 , [ "arm,pl011" , "arm,primecell" ] ) ;
72
+ of_uart ! ( Ns16550 , [ "snps,dw-apb-uart" ] ) ;
73
+ }
74
+ None
75
+ }
76
+
49
77
pub fn set_irq_enable ( & mut self , enable : bool ) {
50
78
( self . op . set_irq_enable ) ( self . data , enable) ;
51
79
}
@@ -226,14 +254,14 @@ pub fn init(fdt_addr: NonNull<u8>, fn_phys_to_virt: FnPhysToVirt) -> Option<Uart
226
254
let uart = UartData :: new ( reg. address , io_kind, fn_phys_to_virt) ;
227
255
228
256
if is_8250 {
229
- return Some ( Uart :: new :: < Ns16550 > ( uart) ) ;
257
+ return Some ( Uart :: _new :: < Ns16550 > ( uart) ) ;
230
258
} else {
231
259
for c in node. compatibles ( ) {
232
260
macro_rules! of_uart {
233
261
( $name: ty, $compatible: expr) => {
234
262
for want in $compatible {
235
263
if c. contains( want) {
236
- return Some ( Uart :: new :: <$name>( uart) ) ;
264
+ return Some ( Uart :: _new :: <$name>( uart) ) ;
237
265
}
238
266
}
239
267
} ;
0 commit comments