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
|
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-09-23 GuEe-GUI first version
*/
#include "rockchip-display.h"
void display_timing_derive(struct display_timing *tim)
{
rt_uint32_t hsync_start, hsync_end, vsync_start, vsync_end;
hsync_start = tim->hactive + tim->hfront_porch;
hsync_end = hsync_start + tim->hsync_len;
tim->htotal = hsync_end + tim->hback_porch;
vsync_start = tim->vactive + tim->vfront_porch;
vsync_end = vsync_start + tim->vsync_len;
tim->vtotal = vsync_end + tim->vback_porch;
}
static rt_err_t display_timing_read_u32(struct rt_ofw_node *np,
const char *prop, rt_uint32_t *value)
{
int count = rt_ofw_prop_count_of_u32(np, prop);
if (count <= 0)
{
return count ? (rt_err_t)count : -RT_ENOENT;
}
/* Timing bindings may encode <min typical max>; use the typical value. */
return rt_ofw_prop_read_u32_index(np, prop, count >= 3 ? 1 : 0, value);
}
static rt_err_t display_timing_parse_prop(struct rt_ofw_node *np, struct display_timing *tim)
{
rt_uint32_t val, pixelclock;
if (display_timing_read_u32(np, "hactive", &tim->hactive))
{
return -RT_EINVAL;
}
if (display_timing_read_u32(np, "vactive", &tim->vactive))
{
return -RT_EINVAL;
}
if (display_timing_read_u32(np, "clock-frequency", &pixelclock))
{
tim->pixelclock = 0;
}
else
{
tim->pixelclock = pixelclock;
}
if (display_timing_read_u32(np, "hsync-len", &tim->hsync_len))
{
tim->hsync_len = 10;
}
if (display_timing_read_u32(np, "hfront-porch", &tim->hfront_porch))
{
tim->hfront_porch = 40;
}
if (display_timing_read_u32(np, "hback-porch", &tim->hback_porch))
{
tim->hback_porch = 40;
}
if (display_timing_read_u32(np, "vsync-len", &tim->vsync_len))
{
tim->vsync_len = 4;
}
if (display_timing_read_u32(np, "vfront-porch", &tim->vfront_porch))
{
tim->vfront_porch = 20;
}
if (display_timing_read_u32(np, "vback-porch", &tim->vback_porch))
{
tim->vback_porch = 20;
}
tim->flags = 0;
if (!rt_ofw_prop_read_u32(np, "hsync-active", &val) && val)
{
tim->flags |= DISPLAY_TIMING_F_PHSYNC;
}
if (!rt_ofw_prop_read_u32(np, "vsync-active", &val) && val)
{
tim->flags |= DISPLAY_TIMING_F_PVSYNC;
}
if (!rt_ofw_prop_read_u32(np, "pixelclk-active", &val) && !val)
{
tim->flags |= DISPLAY_TIMING_F_PIXDATA_NEGEDGE;
}
display_timing_derive(tim);
return RT_EOK;
}
rt_err_t display_timing_parse(struct rt_ofw_node *np, struct display_timing *tim)
{
struct rt_ofw_node *child, *timings;
rt_err_t err = -RT_ENOSYS;
if (!np || !tim)
{
return -RT_EINVAL;
}
rt_memset(tim, 0, sizeof(*tim));
if (!display_timing_parse_prop(np, tim))
{
return RT_EOK;
}
child = rt_ofw_get_child_by_tag(np, "panel-timing");
if (child)
{
err = display_timing_parse_prop(child, tim);
rt_ofw_node_put(child);
if (!err)
{
return RT_EOK;
}
}
timings = rt_ofw_get_child_by_tag(np, "display-timings");
if (!timings)
{
return err;
}
child = rt_ofw_parse_phandle(timings, "native-mode", 0);
if (child)
{
err = display_timing_parse_prop(child, tim);
rt_ofw_node_put(child);
if (!err)
{
rt_ofw_node_put(timings);
return RT_EOK;
}
}
rt_ofw_foreach_available_child_node(timings, child)
{
err = display_timing_parse_prop(child, tim);
if (!err)
{
rt_ofw_node_put(child);
rt_ofw_node_put(timings);
return RT_EOK;
}
}
rt_ofw_node_put(timings);
return err;
}
|