1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
|
#ifndef __OF_H
#define __OF_H
#include <fdt.h>
#include <errno.h>
#include <linux/types.h>
#include <linux/list.h>
#include <asm/byteorder.h>
/* Default string compare functions */
#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
#define OF_BAD_ADDR ((u64)-1)
typedef u32 phandle;
struct property {
char *name;
int length;
void *value;
const void *value_const;
struct list_head list;
};
struct device_node {
char *name;
char *full_name;
struct list_head properties;
struct device_node *parent;
struct list_head children;
struct list_head parent_list;
struct list_head list;
phandle phandle;
};
struct of_device_id {
char *compatible;
const void *data;
};
#define MAX_PHANDLE_ARGS 8
struct of_phandle_args {
struct device_node *np;
int args_count;
uint32_t args[MAX_PHANDLE_ARGS];
};
#define OF_MAX_RESERVE_MAP 16
struct of_reserve_map {
uint64_t start[OF_MAX_RESERVE_MAP];
uint64_t end[OF_MAX_RESERVE_MAP];
int num_entries;
};
int of_add_reserve_entry(resource_size_t start, resource_size_t end);
struct of_reserve_map *of_get_reserve_map(void);
void of_clean_reserve_map(void);
void fdt_add_reserve_map(void *fdt);
struct device_d;
struct driver_d;
int of_fix_tree(struct device_node *);
int of_match(struct device_d *dev, struct driver_d *drv);
int of_add_initrd(struct device_node *root, resource_size_t start,
resource_size_t end);
struct fdt_header *fdt_get_tree(void);
struct fdt_header *of_get_fixed_tree(struct device_node *node);
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
u64 r = 0;
while (size--)
r = (r << 32) | be32_to_cpu(*(cell++));
return r;
}
/* Helper to write a big number; size is in cells (not bytes) */
static inline void of_write_number(void *__cell, u64 val, int size)
{
__be32 *cell = __cell;
while (size--) {
cell[size] = cpu_to_be32(val);
val >>= 32;
}
}
static inline const void *of_property_get_value(struct property *pp)
{
return pp->value ? pp->value : pp->value_const;
}
void of_print_property(const void *data, int len);
void of_print_cmdline(struct device_node *root);
void of_print_nodes(struct device_node *node, int indent);
void of_diff(struct device_node *a, struct device_node *b, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
struct device_node *of_unflatten_dtb(const void *fdt);
struct device_node *of_unflatten_dtb_const(const void *infdt);
struct cdev;
#ifdef CONFIG_OFTREE
extern int of_n_addr_cells(struct device_node *np);
extern int of_n_size_cells(struct device_node *np);
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
extern const void *of_get_property(const struct device_node *np,
const char *name, int *lenp);
extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
extern int of_set_property(struct device_node *node, const char *p,
const void *val, int len, int create);
extern struct property *of_new_property(struct device_node *node,
const char *name, const void *data, int len);
extern struct property *of_new_property_const(struct device_node *node,
const char *name,
const void *data, int len);
extern void of_delete_property(struct property *pp);
extern struct device_node *of_find_node_by_name(struct device_node *from,
const char *name);
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
extern struct device_node *of_find_node_by_phandle(phandle phandle);
extern struct device_node *of_find_node_by_phandle_from(phandle phandle,
struct device_node *root);
extern struct device_node *of_find_node_by_type(struct device_node *from,
const char *type);
extern struct device_node *of_find_compatible_node(struct device_node *from,
const char *type, const char *compat);
extern const struct of_device_id *of_match_node(
const struct of_device_id *matches, const struct device_node *node);
extern struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match);
extern struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name);
extern struct device_node *of_new_node(struct device_node *parent,
const char *name);
extern struct device_node *of_create_node(struct device_node *root,
const char *path);
extern struct device_node *of_copy_node(struct device_node *parent,
const struct device_node *other);
extern void of_delete_node(struct device_node *node);
extern const char *of_get_machine_compatible(void);
extern int of_machine_is_compatible(const char *compat);
extern int of_device_is_compatible(const struct device_node *device,
const char *compat);
extern int of_device_is_available(const struct device_node *device);
extern bool of_device_is_big_endian(const struct device_node *device);
extern struct device_node *of_get_parent(const struct device_node *node);
extern struct device_node *of_get_next_available_child(
const struct device_node *node, struct device_node *prev);
struct device_node *of_get_next_child(const struct device_node *node,
struct device_node *prev);
extern int of_get_child_count(const struct device_node *parent);
extern int of_get_available_child_count(const struct device_node *parent);
extern struct device_node *of_get_child_by_name(const struct device_node *node,
const char *name);
extern char *of_get_reproducible_name(struct device_node *node);
extern struct device_node *of_find_node_by_reproducible_name(struct device_node
*from,
const char *name);
extern int of_property_read_u32_index(const struct device_node *np,
const char *propname,
u32 index, u32 *out_value);
extern int of_property_read_u8_array(const struct device_node *np,
const char *propname, u8 *out_values, size_t sz);
extern int of_property_read_u16_array(const struct device_node *np,
const char *propname, u16 *out_values, size_t sz);
extern int of_property_read_u32_array(const struct device_node *np,
const char *propname,
u32 *out_values,
size_t sz);
extern int of_property_read_u64(const struct device_node *np,
const char *propname, u64 *out_value);
extern int of_property_read_string(struct device_node *np,
const char *propname,
const char **out_string);
extern int of_property_read_string_index(struct device_node *np,
const char *propname,
int index, const char **output);
extern int of_property_match_string(struct device_node *np,
const char *propname,
const char *string);
extern int of_property_count_strings(struct device_node *np,
const char *propname);
extern const __be32 *of_prop_next_u32(struct property *prop,
const __be32 *cur, u32 *pu);
extern const char *of_prop_next_string(struct property *prop, const char *cur);
extern int of_property_write_bool(struct device_node *np,
const char *propname, const bool value);
extern int of_property_write_u8_array(struct device_node *np,
const char *propname, const u8 *values,
size_t sz);
extern int of_property_write_u16_array(struct device_node *np,
const char *propname, const u16 *values,
size_t sz);
extern int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz);
extern int of_property_write_u64_array(struct device_node *np,
const char *propname, const u64 *values,
size_t sz);
extern int of_property_write_string(struct device_node *np, const char *propname,
const char *value);
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
int index);
extern struct device_node *of_parse_phandle_from(const struct device_node *np,
struct device_node *root,
const char *phandle_name,
int index);
extern int of_parse_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name, int index,
struct of_phandle_args *out_args);
extern int of_count_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name);
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
extern int of_modalias_node(struct device_node *node, char *modalias, int len);
extern struct device_node *of_get_root_node(void);
extern int of_set_root_node(struct device_node *node);
extern struct device_d *of_platform_device_create(struct device_node *np,
struct device_d *parent);
extern int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
struct device_d *parent);
extern struct device_d *of_find_device_by_node(struct device_node *np);
extern struct device_d *of_device_enable_and_register(struct device_node *np);
extern struct device_d *of_device_enable_and_register_by_name(const char *name);
extern struct device_d *of_device_enable_and_register_by_alias(
const char *alias);
struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_partitions_register_fixup(struct cdev *cdev);
int of_device_is_stdout_path(struct device_d *dev);
const char *of_get_model(void);
void *of_flatten_dtb(struct device_node *node);
int of_add_memory(struct device_node *node, bool dump);
void of_add_memory_bank(struct device_node *node, bool dump, int r,
u64 base, u64 size);
struct device_d *of_find_device_by_node_path(const char *path);
#define OF_FIND_PATH_FLAGS_BB 1 /* return .bb device if available */
int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags);
int of_find_path_by_node(struct device_node *node, char **outpath, unsigned flags);
struct device_node *of_find_node_by_devpath(struct device_node *root, const char *path);
int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context);
int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void *context);
int of_register_set_status_fixup(const char *node, bool status);
struct device_node *of_find_node_by_alias(struct device_node *root,
const char *alias);
struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
const char *str);
int of_autoenable_device_by_path(char *path);
int of_autoenable_i2c_by_component(char *path);
#else
static inline int of_parse_partitions(struct cdev *cdev,
struct device_node *node)
{
return -EINVAL;
}
static inline int of_partitions_register_fixup(struct cdev *cdev)
{
return -ENOSYS;
}
static inline int of_device_is_stdout_path(struct device_d *dev)
{
return 0;
}
static inline const char *of_get_model(void)
{
return NULL;
}
static inline void *of_flatten_dtb(struct device_node *node)
{
return NULL;
}
static inline int of_add_memory(struct device_node *node, bool dump)
{
return -EINVAL;
}
static inline struct device_node *of_get_root_node(void)
{
return NULL;
}
static inline int of_set_root_node(struct device_node *node)
{
return -ENOSYS;
}
static inline struct device_d *of_platform_device_create(struct device_node *np,
struct device_d *parent)
{
return NULL;
}
static inline int of_n_addr_cells(struct device_node *np)
{
return 0;
}
static inline int of_n_size_cells(struct device_node *np)
{
return 0;
}
static inline struct device_node *of_get_parent(const struct device_node *node)
{
return NULL;
}
static inline struct device_node *of_get_next_available_child(
const struct device_node *node, struct device_node *prev)
{
return NULL;
}
static inline struct device_node *of_get_next_child(const struct device_node *node,
struct device_node *prev)
{
return NULL;
}
static inline int of_get_child_count(const struct device_node *parent)
{
return -ENOSYS;
}
static inline int of_get_available_child_count(const struct device_node *parent)
{
return -ENOSYS;
}
static inline struct device_node *of_get_child_by_name(
const struct device_node *node, const char *name)
{
return NULL;
}
static inline struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp)
{
return NULL;
}
static inline const void *of_get_property(const struct device_node *np,
const char *name, int *lenp)
{
return NULL;
}
static inline struct device_node *of_get_cpu_node(int cpu,
unsigned int *thread)
{
return NULL;
}
static inline int of_set_property(struct device_node *node, const char *p,
const void *val, int len, int create)
{
return -ENOSYS;
}
static inline struct property *of_new_property(struct device_node *node,
const char *name, const void *data, int len)
{
return NULL;
}
static inline void of_delete_property(struct property *pp)
{
}
static inline int of_property_read_u32_index(const struct device_node *np,
const char *propname, u32 index, u32 *out_value)
{
return -ENOSYS;
}
static inline int of_property_read_u8_array(const struct device_node *np,
const char *propname, u8 *out_values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_read_u16_array(const struct device_node *np,
const char *propname, u16 *out_values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_read_u64(const struct device_node *np,
const char *propname, u64 *out_value)
{
return -ENOSYS;
}
static inline int of_property_read_string(struct device_node *np,
const char *propname, const char **out_string)
{
return -ENOSYS;
}
static inline int of_property_read_string_index(struct device_node *np,
const char *propname, int index, const char **output)
{
return -ENOSYS;
}
static inline int of_property_match_string(struct device_node *np,
const char *propname, const char *string)
{
return -ENOSYS;
}
static inline int of_property_count_strings(struct device_node *np,
const char *propname)
{
return -ENOSYS;
}
static inline const __be32 *of_prop_next_u32(struct property *prop,
const __be32 *cur, u32 *pu)
{
return 0;
}
static inline const char *of_prop_next_string(struct property *prop,
const char *cur)
{
return NULL;
}
static inline int of_property_write_bool(struct device_node *np,
const char *propname, const bool value)
{
return -ENOSYS;
}
static inline int of_property_write_u8_array(struct device_node *np,
const char *propname, const u8 *values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_write_u16_array(struct device_node *np,
const char *propname, const u16 *values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_write_u64_array(struct device_node *np,
const char *propname, const u64 *values, size_t sz)
{
return -ENOSYS;
}
static inline int of_property_write_string(struct device_node *np, const char *propname,
const char *value)
{
return -ENOSYS;
}
static inline struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name, int index)
{
return NULL;
}
static inline struct device_node *of_parse_phandle_from(const struct device_node *np,
struct device_node *root,
const char *phandle_name, int index)
{
return NULL;
}
static inline int of_parse_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name, int index,
struct of_phandle_args *out_args)
{
return -ENOSYS;
}
static inline int of_count_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name)
{
return -ENOSYS;
}
static inline struct device_node *of_find_node_by_path_from(
struct device_node *from, const char *path)
{
return NULL;
}
static inline struct device_node *of_find_node_by_path(const char *path)
{
return NULL;
}
static inline struct device_node *of_find_node_by_name(struct device_node *from,
const char *name)
{
return NULL;
}
static inline struct device_node *of_find_node_by_phandle(phandle phandle)
{
return NULL;
}
static inline struct device_node *of_find_node_by_phandle_from(phandle phandle,
struct device_node *root)
{
return NULL;
}
static inline struct device_node *of_find_compatible_node(
struct device_node *from,
const char *type,
const char *compat)
{
return NULL;
}
static inline const struct of_device_id *of_match_node(
const struct of_device_id *matches, const struct device_node *node)
{
return NULL;
}
static inline struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match)
{
return NULL;
}
static inline struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name)
{
return NULL;
}
static inline struct device_node *of_new_node(struct device_node *parent,
const char *name)
{
return NULL;
}
static inline struct device_node *of_create_node(struct device_node *root,
const char *path)
{
return NULL;
}
static inline void of_delete_node(struct device_node *node)
{
}
static inline int of_machine_is_compatible(const char *compat)
{
return 0;
}
static inline int of_device_is_compatible(const struct device_node *device,
const char *compat)
{
return 0;
}
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
}
static inline bool of_device_is_big_endian(const struct device_node *device)
{
return false;
}
static inline void of_alias_scan(void)
{
}
static inline int of_alias_get_id(struct device_node *np, const char *stem)
{
return -ENOSYS;
}
static inline const char *of_alias_get(struct device_node *np)
{
return NULL;
}
static inline int of_modalias_node(struct device_node *node, char *modalias,
int len)
{
return -ENOSYS;
}
static inline int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
struct device_d *parent)
{
return -ENOSYS;
}
static inline struct device_d *of_find_device_by_node(struct device_node *np)
{
return NULL;
}
static inline struct device_d *of_device_enable_and_register(
struct device_node *np)
{
return NULL;
}
static inline struct device_d *of_device_enable_and_register_by_name(
const char *name)
{
return NULL;
}
static inline struct device_d *of_device_enable_and_register_by_alias(
const char *alias)
{
return NULL;
}
static inline int of_register_fixup(int (*fixup)(struct device_node *, void *),
void *context)
{
return -ENOSYS;
}
static inline struct device_node *of_find_node_by_alias(
struct device_node *root, const char *alias)
{
return NULL;
}
static inline struct device_node *of_find_node_by_path_or_alias(
struct device_node *root, const char *str)
{
return NULL;
}
static inline int of_autoenable_i2c_by_path(char *path)
{
return -ENODEV;
}
static inline int of_autoenable_i2c_by_component(char *path)
{
return -ENODEV;
}
#endif
#define for_each_node_by_name(dn, name) \
for (dn = of_find_node_by_name(NULL, name); dn; \
dn = of_find_node_by_name(dn, name))
#define for_each_node_by_type(dn, type) \
for (dn = of_find_node_by_type(NULL, type); dn; \
dn = of_find_node_by_type(dn, type))
#define for_each_node_by_name_from(dn, root, name) \
for (dn = of_find_node_by_name(root, name); dn; \
dn = of_find_node_by_name(dn, name))
/* Iterate over compatible nodes starting from given root */
#define for_each_compatible_node_from(dn, root, type, compatible) \
for (dn = of_find_compatible_node(root, type, compatible); dn; \
dn = of_find_compatible_node(dn, type, compatible))
/* Iterate over compatible nodes in default device tree */
#define for_each_compatible_node(dn, type, compatible) \
for_each_compatible_node_from(dn, NULL, type, compatible)
static inline struct device_node *of_find_matching_node(
struct device_node *from,
const struct of_device_id *matches)
{
return of_find_matching_node_and_match(from, matches, NULL);
}
#define for_each_matching_node_from(dn, root, matches) \
for (dn = of_find_matching_node(root, matches); dn; \
dn = of_find_matching_node(dn, matches))
#define for_each_matching_node(dn, matches) \
for_each_matching_node_from(dn, NULL, matches)
#define for_each_matching_node_and_match(dn, matches, match) \
for (dn = of_find_matching_node_and_match(NULL, matches, match); \
dn; dn = of_find_matching_node_and_match(dn, matches, match))
#define for_each_node_with_property(dn, prop_name) \
for (dn = of_find_node_with_property(NULL, prop_name); dn; \
dn = of_find_node_with_property(dn, prop_name))
#define for_each_child_of_node_safe(parent, tmp, child) \
list_for_each_entry_safe(child, tmp, &parent->children, parent_list)
#define for_each_child_of_node(parent, child) \
list_for_each_entry(child, &parent->children, parent_list)
#define for_each_available_child_of_node(parent, child) \
for (child = of_get_next_available_child(parent, NULL); child != NULL; \
child = of_get_next_available_child(parent, child))
/**
* of_property_read_bool - Findfrom a property
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
*
* Search for a property in a device node.
* Returns true if the property exist false otherwise.
*/
static inline bool of_property_read_bool(const struct device_node *np,
const char *propname)
{
struct property *prop = of_find_property(np, propname, NULL);
return prop ? true : false;
}
static inline int of_property_read_u8(const struct device_node *np,
const char *propname,
u8 *out_value)
{
return of_property_read_u8_array(np, propname, out_value, 1);
}
static inline int of_property_read_u16(const struct device_node *np,
const char *propname,
u16 *out_value)
{
return of_property_read_u16_array(np, propname, out_value, 1);
}
static inline int of_property_read_u32(const struct device_node *np,
const char *propname,
u32 *out_value)
{
return of_property_read_u32_array(np, propname, out_value, 1);
}
/*
* struct property *prop;
* const __be32 *p;
* u32 u;
*
* of_property_for_each_u32(np, "propname", prop, p, u)
* printk("U32 value: %x\n", u);
*/
#define of_property_for_each_u32(np, propname, prop, p, u) \
for (prop = of_find_property(np, propname, NULL), \
p = of_prop_next_u32(prop, NULL, &u); \
p; \
p = of_prop_next_u32(prop, p, &u))
/*
* struct property *prop;
* const char *s;
*
* of_property_for_each_string(np, "propname", prop, s)
* printk("String value: %s\n", s);
*/
#define of_property_for_each_string(np, propname, prop, s) \
for (prop = of_find_property(np, propname, NULL), \
s = of_prop_next_string(prop, NULL); \
s; \
s = of_prop_next_string(prop, s))
/*
* struct device_node *n;
*
* of_property_for_each_phandle(np, root, "propname", n)
* printk("phandle points to: %s\n", n->full_name);
*/
#define of_property_for_each_phandle(np, root, propname, n) \
for (int _i = 0; \
(n = of_parse_phandle_from(np, root, propname, _i));\
_i++)
static inline int of_property_write_u8(struct device_node *np,
const char *propname, u8 value)
{
return of_property_write_u8_array(np, propname, &value, 1);
}
static inline int of_property_write_u16(struct device_node *np,
const char *propname, u16 value)
{
return of_property_write_u16_array(np, propname, &value, 1);
}
static inline int of_property_write_u32(struct device_node *np,
const char *propname,
u32 value)
{
return of_property_write_u32_array(np, propname, &value, 1);
}
static inline int of_property_write_u64(struct device_node *np,
const char *propname,
u64 value)
{
return of_property_write_u64_array(np, propname, &value, 1);
}
extern const struct of_device_id of_default_bus_match_table[];
int of_device_enable(struct device_node *node);
int of_device_enable_path(const char *path);
int of_device_disable(struct device_node *node);
int of_device_disable_path(const char *path);
phandle of_get_tree_max_phandle(struct device_node *root);
phandle of_node_create_phandle(struct device_node *node);
int of_set_property_to_child_phandle(struct device_node *node, char *prop_name);
static inline struct device_node *of_find_root_node(struct device_node *node)
{
while (node->parent)
node = node->parent;
return node;
}
#ifdef CONFIG_OF_OVERLAY
struct device_node *of_resolve_phandles(struct device_node *root,
const struct device_node *overlay);
int of_overlay_apply_tree(struct device_node *root,
struct device_node *overlay);
int of_register_overlay(struct device_node *overlay);
int of_process_overlay(struct device_node *root,
struct device_node *overlay,
int (*process)(struct device_node *target,
struct device_node *overlay, void *data),
void *data);
int of_firmware_load_overlay(struct device_node *overlay, const char *path);
#else
static inline struct device_node *of_resolve_phandles(struct device_node *root,
const struct device_node *overlay)
{
return NULL;
}
static inline int of_overlay_apply_tree(struct device_node *root,
struct device_node *overlay)
{
return -ENOSYS;
}
static inline int of_register_overlay(struct device_node *overlay)
{
return -ENOSYS;
}
static inline int of_process_overlay(struct device_node *root,
struct device_node *overlay,
int (*process)(struct device_node *target,
struct device_node *overlay, void *data),
void *data)
{
return -ENOSYS;
}
static inline int of_firmware_load_overlay(struct device_node *overlay, const char *path)
{
return -ENOSYS;
}
#endif
#endif /* __OF_H */
|