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
|
/* $NetBSD: panel_fdt.c,v 1.6 2021/01/27 03:10:21 thorpej Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Manuel Bouyer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* lvds panel driver.
* specified in linux/Documentation/devicetree/bindings/display/panel/
* Simple RGB panels could be added as well
* registers an endpoint for use by graphic controller drivers
*
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(1, "$NetBSD: panel_fdt.c,v 1.6 2021/01/27 03:10:21 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <sys/gpio.h>
#include <dev/fdt/fdtvar.h>
#include <dev/fdt/panel_fdt.h>
static int fdt_panel_match(device_t, cfdata_t, void *);
static void fdt_panel_attach(device_t, device_t, void *);
static void *fdt_panel_get_data(device_t, struct fdt_endpoint *);
static int fdt_panel_enable(device_t, struct fdt_endpoint *, bool);
struct fdt_panel_softc {
device_t sc_dev;
int sc_phandle;
struct fdt_panel sc_panel;
struct fdt_device_ports sc_ports;
#define MAX_GPIO_ENABLES 8
struct fdtbus_gpio_pin *sc_gpios_enable[MAX_GPIO_ENABLES];
};
CFATTACH_DECL_NEW(fdt_panel, sizeof(struct fdt_panel_softc),
fdt_panel_match, fdt_panel_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
{ .compat = "panel-lvds", .value = PANEL_LVDS},
{ .compat = "panel-dual-lvds", .value = PANEL_DUAL_LVDS},
DEVICE_COMPAT_EOL
};
static int
fdt_panel_match(device_t parent, cfdata_t cf, void *aux)
{
const struct fdt_attach_args *faa = aux;
return of_compatible_match(faa->faa_phandle, compat_data);
}
static void
fdt_panel_attach(device_t parent, device_t self, void *aux)
{
struct fdt_panel_softc *sc = device_private(self);
const struct fdt_attach_args * const faa = aux;
const int phandle = faa->faa_phandle;
const struct display_timing * const timing =
&sc->sc_panel.panel_timing;
int child;
char buf[16];
const char *val;
int i;
sc->sc_dev = self;
sc->sc_phandle = phandle;
sc->sc_panel.panel_type =
of_compatible_lookup(phandle, compat_data)->value;
if (of_getprop_uint32(phandle, "width-mm", &sc->sc_panel.panel_width) ||
of_getprop_uint32(phandle, "height-mm", &sc->sc_panel.panel_height)){
aprint_error(": missing width-mm or height-mm properties\n");
return;
}
for (child = OF_child(phandle); child; child = OF_peer(child)) {
if (OF_getprop(child, "name", buf, sizeof(buf)) <= 0)
continue;
if (strcmp(buf, "panel-timing") != 0)
continue;
if (display_timing_parse(child,
&sc->sc_panel.panel_timing) != 0) {
aprint_error(": failed to parse panel-timing\n");
return;
}
}
if (sc->sc_panel.panel_timing.clock_freq == 0) {
aprint_error(": missing panel-timing\n");
return;
}
switch(sc->sc_panel.panel_type) {
case PANEL_LVDS:
case PANEL_DUAL_LVDS:
val = fdtbus_get_string(phandle, "data-mapping");
if (val == NULL) {
aprint_error(": missing data-mapping\n");
return;
}
if (strcmp(val, "jeida-18") == 0)
sc->sc_panel.panel_lvds_format = LVDS_JEIDA_18;
else if (strcmp(val, "jeida-24") == 0)
sc->sc_panel.panel_lvds_format = LVDS_JEIDA_24;
else if (strcmp(val, "vesa-24") == 0)
sc->sc_panel.panel_lvds_format = LVDS_VESA_24;
else {
aprint_error(": unknown data-mapping \"%s\"\n", val);
return;
}
break;
default:
panic("unknown panel type %d", sc->sc_panel.panel_type);
}
aprint_naive("\n");
aprint_normal(": %dx%d", timing->hactive, timing->vactive);
switch(sc->sc_panel.panel_type) {
case PANEL_LVDS:
aprint_normal(" LVDS");
break;
case PANEL_DUAL_LVDS:
aprint_normal(" dual-link LVDS");
break;
default:
panic(" unknown panel type %d", sc->sc_panel.panel_type);
}
aprint_normal(" panel\n");
for (i = 0; i < MAX_GPIO_ENABLES ; i++) {
sc->sc_gpios_enable[i] = fdtbus_gpio_acquire_index(phandle,
"enable-gpios", i, GPIO_PIN_OUTPUT);
if (sc->sc_gpios_enable[i] == NULL)
break;
}
aprint_verbose_dev(self, "%d enable GPIO%c\n", i, i > 1 ? 's' : ' ');
sc->sc_ports.dp_ep_get_data = fdt_panel_get_data;
sc->sc_ports.dp_ep_enable = fdt_panel_enable;
fdt_ports_register(&sc->sc_ports, self, phandle, EP_PANEL);
}
static void *
fdt_panel_get_data(device_t dev, struct fdt_endpoint *ep)
{
struct fdt_panel_softc *sc = device_private(dev);
return &sc->sc_panel;
}
static int
fdt_panel_enable(device_t dev, struct fdt_endpoint *ep, bool enable)
{
struct fdt_panel_softc *sc = device_private(dev);
for (int i = 0; i < MAX_GPIO_ENABLES ; i++) {
if (sc->sc_gpios_enable[i] == NULL)
break;
fdtbus_gpio_write(sc->sc_gpios_enable[i], enable);
}
return 0;
}
|