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
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2015 Texas Instruments
* Author: Jyri Sarha <jsarha@ti.com>
*/
#include <linux/component.h>
#include <linux/of_graph.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_of.h>
#include "tilcdc_drv.h"
#include "tilcdc_external.h"
static const struct tilcdc_panel_info panel_info_tda998x = {
.ac_bias = 255,
.ac_bias_intrpt = 0,
.dma_burst_sz = 16,
.bpp = 16,
.fdd = 0x80,
.tft_alt_mode = 0,
.invert_pxl_clk = 1,
.sync_edge = 1,
.sync_ctrl = 1,
.raster_order = 0,
};
static const struct tilcdc_panel_info panel_info_default = {
.ac_bias = 255,
.ac_bias_intrpt = 0,
.dma_burst_sz = 16,
.bpp = 16,
.fdd = 0x80,
.tft_alt_mode = 0,
.sync_edge = 0,
.sync_ctrl = 1,
.raster_order = 0,
};
static
struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev,
struct drm_encoder *encoder)
{
struct drm_connector *connector;
list_for_each_entry(connector, &ddev->mode_config.connector_list, head) {
if (drm_connector_has_possible_encoder(connector, encoder))
return connector;
}
dev_err(ddev->dev, "No connector found for %s encoder (id %d)\n",
encoder->name, encoder->base.id);
return NULL;
}
int tilcdc_add_component_encoder(struct drm_device *ddev)
{
struct tilcdc_drm_private *priv = ddev->dev_private;
struct drm_encoder *encoder;
list_for_each_entry(encoder, &ddev->mode_config.encoder_list, head)
if (encoder->possible_crtcs & (1 << priv->crtc->index))
break;
if (!encoder) {
dev_err(ddev->dev, "%s: No suitable encoder found\n", __func__);
return -ENODEV;
}
priv->external_connector =
tilcdc_encoder_find_connector(ddev, encoder);
if (!priv->external_connector)
return -ENODEV;
/* Only tda998x is supported at the moment. */
tilcdc_crtc_set_simulate_vesa_sync(priv->crtc, true);
tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_tda998x);
return 0;
}
static const struct drm_encoder_funcs tilcdc_external_encoder_funcs = {
.destroy = drm_encoder_cleanup,
};
static
int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge)
{
struct tilcdc_drm_private *priv = ddev->dev_private;
int ret;
priv->external_encoder->possible_crtcs = BIT(0);
ret = drm_bridge_attach(priv->external_encoder, bridge, NULL);
if (ret) {
dev_err(ddev->dev, "drm_bridge_attach() failed %d\n", ret);
return ret;
}
tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_default);
priv->external_connector =
tilcdc_encoder_find_connector(ddev, priv->external_encoder);
if (!priv->external_connector)
return -ENODEV;
return 0;
}
int tilcdc_attach_external_device(struct drm_device *ddev)
{
struct tilcdc_drm_private *priv = ddev->dev_private;
struct drm_bridge *bridge;
struct drm_panel *panel;
int ret;
ret = drm_of_find_panel_or_bridge(ddev->dev->of_node, 0, 0,
&panel, &bridge);
if (ret == -ENODEV)
return 0;
else if (ret)
return ret;
priv->external_encoder = devm_kzalloc(ddev->dev,
sizeof(*priv->external_encoder),
GFP_KERNEL);
if (!priv->external_encoder)
return -ENOMEM;
ret = drm_encoder_init(ddev, priv->external_encoder,
&tilcdc_external_encoder_funcs,
DRM_MODE_ENCODER_NONE, NULL);
if (ret) {
dev_err(ddev->dev, "drm_encoder_init() failed %d\n", ret);
return ret;
}
if (panel) {
bridge = devm_drm_panel_bridge_add_typed(ddev->dev, panel,
DRM_MODE_CONNECTOR_DPI);
if (IS_ERR(bridge)) {
ret = PTR_ERR(bridge);
goto err_encoder_cleanup;
}
}
ret = tilcdc_attach_bridge(ddev, bridge);
if (ret)
goto err_encoder_cleanup;
return 0;
err_encoder_cleanup:
drm_encoder_cleanup(priv->external_encoder);
return ret;
}
static int dev_match_of(struct device *dev, void *data)
{
return dev->of_node == data;
}
int tilcdc_get_external_components(struct device *dev,
struct component_match **match)
{
struct device_node *node;
node = of_graph_get_remote_node(dev->of_node, 0, 0);
if (!of_device_is_compatible(node, "nxp,tda998x")) {
of_node_put(node);
return 0;
}
if (match)
drm_of_component_match_add(dev, match, dev_match_of, node);
of_node_put(node);
return 1;
}
|