• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright (c) 2021 Allwinnertech Co., Ltd.
4  * Author: libairong <libairong@allwinnertech.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9 */
10 #include <linux/of.h>
11 #include <linux/of_device.h>
12 #include <linux/of_address.h>
13 #include <linux/of_irq.h>
14 #include "of_service.h"
15 
get_node_by_name(char * main_name)16 struct device_node *get_node_by_name(char *main_name)
17 {
18 	char compat[NAME_LENGTH];
19 	u32 len = 0;
20 	struct device_node *node;
21 
22 	len = sprintf(compat, "allwinner,sunxi-%s", main_name);
23 
24 	if (len > 32)
25 		printk("size of mian_name is out of range\n");
26 
27 	node = of_find_compatible_node(NULL, NULL, compat);
28 
29 	if (!node) {
30 		printk("of_find_compatible_node %s fail\n", compat);
31 		return NULL;
32 	}
33 
34 	return node;
35 }
36 /**
37  * get_property_by_name - retrieve a property from of by name
38  */
get_property_by_name(struct device_node * node,char * property_name,int * property_length)39 struct property *get_property_by_name(struct device_node *node, char *property_name, int *property_length)
40 {
41 	struct property *pp;
42 
43 	pp = of_find_property(node, property_name, property_length);
44 	if (pp == NULL) {
45 		printk("[DEBUG] pp is not found! pp name : %s \n", property_name);
46 		return NULL;
47 	}
48 
49 	return pp;
50 }
51 
52 /**
53  * get_property_by_index - retrieve a property from of by index
54  */
get_property_by_index(struct device_node * node,char * config_start,int index)55 struct property *get_property_by_index(struct device_node *node, char *config_start, int index)
56 {
57 	struct property *pp;
58 	int i;
59 	int length;
60 
61 	pp = get_property_by_name(node, config_start, &length);
62 	// printk("property index : %d \n", index);
63 	for (i = 0; pp; pp = pp->next, i++) {
64 		if (i == index - 1) {
65 			return pp;
66 		}
67 	}
68 
69 	return pp;
70 
71 }
72 
insert_property(struct device_node * node,struct property ** new_pp,char * reference_name,int index)73 int insert_property(struct device_node *node, struct property **new_pp, char *reference_name, int index)
74 {
75 	struct property **pp;
76 	int i;
77 
78 	pp = &node->properties;
79 
80 	// Find start property by reference name
81 	while (*pp) {
82 		if (strcmp(reference_name, (*pp)->name) == 0) {
83 			break;
84 		}
85 
86 		pp = &(*pp)->next;
87 	}
88 
89 	if (pp == NULL) {
90 		return 1;
91 	}
92 
93 	for (i = 0; i < index; i++, pp = &(*pp)->next) {
94 		if (i == (index - 1)) {
95 			// Insert
96 			(*new_pp)->next = (*pp)->next;
97 			(*pp)->next = (*new_pp);
98 			return 0;
99 		}
100 	}
101 
102 	return 2;
103 }
104 
105 /* FIXME,can not to call function, when build disp to be a module. */
106 #ifdef MODULE
of_remove_property(struct device_node * np,struct property * prop)107 int of_remove_property(struct device_node *np, struct property *prop)
108 {
109 	printk("[INFO] Can not to remove property in device tree, when disp was built to be a module \n");
110 	return -1;
111 }
112 #endif
113 
delete_property(struct device_node * np,struct property * prop)114 int delete_property(struct device_node *np, struct property *prop)
115 {
116 	return of_remove_property(np, prop);
117 }
118 
119