aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/tilcdc
diff options
context:
space:
mode:
authorJyri Sarha <jsarha@ti.com>2015-02-10 07:13:23 -0500
committerJyri Sarha <jsarha@ti.com>2015-05-27 06:13:32 -0400
commit103cd8bc1c80ec0a12ef438c4493f7c26edc71bd (patch)
treea920df6557783343097c39d5f29680e6c637fda6 /drivers/gpu/drm/tilcdc
parent6730201f4fdcfbb1e6ec5ec374e6ef95e5bf9662 (diff)
drm/tilcdc: Add support for external tda998x encoder
Add support for an external compontised DRM encoder. The external encoder can be connected to tilcdc trough device tree graph binding. The binding document for tilcdc has been updated. The current implementation supports only tda998x encoder. To be able to filter out the unsupported video modes the tilcdc driver needs to hijack the external connectors helper functions. The tilcdc installes new helper functions that are otherwise identical to orignals, but the mode_valid() call-back check the mode first localy, before calling the original call-back. The tilcdc dirver restores the original helper functions before it is unbound from the external device. I got the idea and some lines of code from Jean-Francois Moine's "drm/tilcdc: Change the interface with the tda998x driver"-patch. Signed-off-by: Jyri Sarha <jsarha@ti.com> Acked-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'drivers/gpu/drm/tilcdc')
-rw-r--r--drivers/gpu/drm/tilcdc/Makefile1
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_crtc.c33
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_drv.c85
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_drv.h5
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_external.c166
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_external.h25
6 files changed, 302 insertions, 13 deletions
diff --git a/drivers/gpu/drm/tilcdc/Makefile b/drivers/gpu/drm/tilcdc/Makefile
index 44485f9d3c88..e1f738b02c1f 100644
--- a/drivers/gpu/drm/tilcdc/Makefile
+++ b/drivers/gpu/drm/tilcdc/Makefile
@@ -7,6 +7,7 @@ tilcdc-y := \
7 tilcdc_crtc.o \ 7 tilcdc_crtc.o \
8 tilcdc_tfp410.o \ 8 tilcdc_tfp410.o \
9 tilcdc_panel.o \ 9 tilcdc_panel.o \
10 tilcdc_external.o \
10 tilcdc_drv.o 11 tilcdc_drv.o
11 12
12obj-$(CONFIG_DRM_TILCDC) += tilcdc.o 13obj-$(CONFIG_DRM_TILCDC) += tilcdc.o
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
index c2d5980b9965..7d07733bdc86 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
@@ -37,6 +37,9 @@ struct tilcdc_crtc {
37 37
38 /* for deferred fb unref's: */ 38 /* for deferred fb unref's: */
39 struct drm_flip_work unref_work; 39 struct drm_flip_work unref_work;
40
41 /* Only set if an external encoder is connected */
42 bool simulate_vesa_sync;
40}; 43};
41#define to_tilcdc_crtc(x) container_of(x, struct tilcdc_crtc, base) 44#define to_tilcdc_crtc(x) container_of(x, struct tilcdc_crtc, base)
42 45
@@ -214,6 +217,28 @@ static bool tilcdc_crtc_mode_fixup(struct drm_crtc *crtc,
214 const struct drm_display_mode *mode, 217 const struct drm_display_mode *mode,
215 struct drm_display_mode *adjusted_mode) 218 struct drm_display_mode *adjusted_mode)
216{ 219{
220 struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
221
222 if (!tilcdc_crtc->simulate_vesa_sync)
223 return true;
224
225 /*
226 * tilcdc does not generate VESA-compliant sync but aligns
227 * VS on the second edge of HS instead of first edge.
228 * We use adjusted_mode, to fixup sync by aligning both rising
229 * edges and add HSKEW offset to fix the sync.
230 */
231 adjusted_mode->hskew = mode->hsync_end - mode->hsync_start;
232 adjusted_mode->flags |= DRM_MODE_FLAG_HSKEW;
233
234 if (mode->flags & DRM_MODE_FLAG_NHSYNC) {
235 adjusted_mode->flags |= DRM_MODE_FLAG_PHSYNC;
236 adjusted_mode->flags &= ~DRM_MODE_FLAG_NHSYNC;
237 } else {
238 adjusted_mode->flags |= DRM_MODE_FLAG_NHSYNC;
239 adjusted_mode->flags &= ~DRM_MODE_FLAG_PHSYNC;
240 }
241
217 return true; 242 return true;
218} 243}
219 244
@@ -534,6 +559,14 @@ void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc,
534 tilcdc_crtc->info = info; 559 tilcdc_crtc->info = info;
535} 560}
536 561
562void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc,
563 bool simulate_vesa_sync)
564{
565 struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
566
567 tilcdc_crtc->simulate_vesa_sync = simulate_vesa_sync;
568}
569
537void tilcdc_crtc_update_clk(struct drm_crtc *crtc) 570void tilcdc_crtc_update_clk(struct drm_crtc *crtc)
538{ 571{
539 struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); 572 struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
index 0f1e09986f56..fcc0508c58c0 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
@@ -17,10 +17,13 @@
17 17
18/* LCDC DRM driver, based on da8xx-fb */ 18/* LCDC DRM driver, based on da8xx-fb */
19 19
20#include <linux/component.h>
21
20#include "tilcdc_drv.h" 22#include "tilcdc_drv.h"
21#include "tilcdc_regs.h" 23#include "tilcdc_regs.h"
22#include "tilcdc_tfp410.h" 24#include "tilcdc_tfp410.h"
23#include "tilcdc_panel.h" 25#include "tilcdc_panel.h"
26#include "tilcdc_external.h"
24 27
25#include "drm_fb_helper.h" 28#include "drm_fb_helper.h"
26 29
@@ -73,13 +76,6 @@ static int modeset_init(struct drm_device *dev)
73 mod->funcs->modeset_init(mod, dev); 76 mod->funcs->modeset_init(mod, dev);
74 } 77 }
75 78
76 if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) {
77 /* oh nos! */
78 dev_err(dev->dev, "no encoders/connectors found\n");
79 drm_mode_config_cleanup(dev);
80 return -ENXIO;
81 }
82
83 dev->mode_config.min_width = 0; 79 dev->mode_config.min_width = 0;
84 dev->mode_config.min_height = 0; 80 dev->mode_config.min_height = 0;
85 dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc); 81 dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc);
@@ -114,6 +110,8 @@ static int tilcdc_unload(struct drm_device *dev)
114{ 110{
115 struct tilcdc_drm_private *priv = dev->dev_private; 111 struct tilcdc_drm_private *priv = dev->dev_private;
116 112
113 tilcdc_remove_external_encoders(dev);
114
117 drm_fbdev_cma_fini(priv->fbdev); 115 drm_fbdev_cma_fini(priv->fbdev);
118 drm_kms_helper_poll_fini(dev); 116 drm_kms_helper_poll_fini(dev);
119 drm_mode_config_cleanup(dev); 117 drm_mode_config_cleanup(dev);
@@ -164,6 +162,9 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
164 162
165 dev->dev_private = priv; 163 dev->dev_private = priv;
166 164
165 priv->is_componentized =
166 tilcdc_get_external_components(dev->dev, NULL) > 0;
167
167 priv->wq = alloc_ordered_workqueue("tilcdc", 0); 168 priv->wq = alloc_ordered_workqueue("tilcdc", 0);
168 if (!priv->wq) { 169 if (!priv->wq) {
169 ret = -ENOMEM; 170 ret = -ENOMEM;
@@ -253,10 +254,28 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
253 goto fail_cpufreq_unregister; 254 goto fail_cpufreq_unregister;
254 } 255 }
255 256
257 platform_set_drvdata(pdev, dev);
258
259 if (priv->is_componentized) {
260 ret = component_bind_all(dev->dev, dev);
261 if (ret < 0)
262 goto fail_mode_config_cleanup;
263
264 ret = tilcdc_add_external_encoders(dev, &bpp);
265 if (ret < 0)
266 goto fail_component_cleanup;
267 }
268
269 if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) {
270 dev_err(dev->dev, "no encoders/connectors found\n");
271 ret = -ENXIO;
272 goto fail_external_cleanup;
273 }
274
256 ret = drm_vblank_init(dev, 1); 275 ret = drm_vblank_init(dev, 1);
257 if (ret < 0) { 276 if (ret < 0) {
258 dev_err(dev->dev, "failed to initialize vblank\n"); 277 dev_err(dev->dev, "failed to initialize vblank\n");
259 goto fail_mode_config_cleanup; 278 goto fail_external_cleanup;
260 } 279 }
261 280
262 pm_runtime_get_sync(dev->dev); 281 pm_runtime_get_sync(dev->dev);
@@ -267,9 +286,6 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
267 goto fail_vblank_cleanup; 286 goto fail_vblank_cleanup;
268 } 287 }
269 288
270 platform_set_drvdata(pdev, dev);
271
272
273 list_for_each_entry(mod, &module_list, list) { 289 list_for_each_entry(mod, &module_list, list) {
274 DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp); 290 DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp);
275 bpp = mod->preferred_bpp; 291 bpp = mod->preferred_bpp;
@@ -300,6 +316,13 @@ fail_vblank_cleanup:
300fail_mode_config_cleanup: 316fail_mode_config_cleanup:
301 drm_mode_config_cleanup(dev); 317 drm_mode_config_cleanup(dev);
302 318
319fail_component_cleanup:
320 if (priv->is_componentized)
321 component_unbind_all(dev->dev, dev);
322
323fail_external_cleanup:
324 tilcdc_remove_external_encoders(dev);
325
303fail_cpufreq_unregister: 326fail_cpufreq_unregister:
304 pm_runtime_disable(dev->dev); 327 pm_runtime_disable(dev->dev);
305#ifdef CONFIG_CPU_FREQ 328#ifdef CONFIG_CPU_FREQ
@@ -605,20 +628,56 @@ static const struct dev_pm_ops tilcdc_pm_ops = {
605 * Platform driver: 628 * Platform driver:
606 */ 629 */
607 630
631static int tilcdc_bind(struct device *dev)
632{
633 return drm_platform_init(&tilcdc_driver, to_platform_device(dev));
634}
635
636static void tilcdc_unbind(struct device *dev)
637{
638 drm_put_dev(dev_get_drvdata(dev));
639}
640
641static const struct component_master_ops tilcdc_comp_ops = {
642 .bind = tilcdc_bind,
643 .unbind = tilcdc_unbind,
644};
645
608static int tilcdc_pdev_probe(struct platform_device *pdev) 646static int tilcdc_pdev_probe(struct platform_device *pdev)
609{ 647{
648 struct component_match *match = NULL;
649 int ret;
650
610 /* bail out early if no DT data: */ 651 /* bail out early if no DT data: */
611 if (!pdev->dev.of_node) { 652 if (!pdev->dev.of_node) {
612 dev_err(&pdev->dev, "device-tree data is missing\n"); 653 dev_err(&pdev->dev, "device-tree data is missing\n");
613 return -ENXIO; 654 return -ENXIO;
614 } 655 }
615 656
616 return drm_platform_init(&tilcdc_driver, pdev); 657 ret = tilcdc_get_external_components(&pdev->dev, &match);
658 if (ret < 0)
659 return ret;
660 else if (ret == 0)
661 return drm_platform_init(&tilcdc_driver, pdev);
662 else
663 return component_master_add_with_match(&pdev->dev,
664 &tilcdc_comp_ops,
665 match);
617} 666}
618 667
619static int tilcdc_pdev_remove(struct platform_device *pdev) 668static int tilcdc_pdev_remove(struct platform_device *pdev)
620{ 669{
621 drm_put_dev(platform_get_drvdata(pdev)); 670 struct drm_device *ddev = dev_get_drvdata(&pdev->dev);
671 struct tilcdc_drm_private *priv = ddev->dev_private;
672
673 /* Check if a subcomponent has already triggered the unloading. */
674 if (!priv)
675 return 0;
676
677 if (priv->is_componentized)
678 component_master_del(&pdev->dev, &tilcdc_comp_ops);
679 else
680 drm_put_dev(platform_get_drvdata(pdev));
622 681
623 return 0; 682 return 0;
624} 683}
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h
index 633651238dbb..e863ad0d26fe 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h
+++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h
@@ -85,6 +85,9 @@ struct tilcdc_drm_private {
85 85
86 unsigned int num_connectors; 86 unsigned int num_connectors;
87 struct drm_connector *connectors[8]; 87 struct drm_connector *connectors[8];
88 const struct drm_connector_helper_funcs *connector_funcs[8];
89
90 bool is_componentized;
88}; 91};
89 92
90/* Sub-module for display. Since we don't know at compile time what panels 93/* Sub-module for display. Since we don't know at compile time what panels
@@ -165,6 +168,8 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc);
165void tilcdc_crtc_update_clk(struct drm_crtc *crtc); 168void tilcdc_crtc_update_clk(struct drm_crtc *crtc);
166void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, 169void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc,
167 const struct tilcdc_panel_info *info); 170 const struct tilcdc_panel_info *info);
171void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc,
172 bool simulate_vesa_sync);
168int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode); 173int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode);
169int tilcdc_crtc_max_width(struct drm_crtc *crtc); 174int tilcdc_crtc_max_width(struct drm_crtc *crtc);
170 175
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c b/drivers/gpu/drm/tilcdc/tilcdc_external.c
new file mode 100644
index 000000000000..03acb4f99982
--- /dev/null
+++ b/drivers/gpu/drm/tilcdc/tilcdc_external.c
@@ -0,0 +1,166 @@
1/*
2 * Copyright (C) 2015 Texas Instruments
3 * Author: Jyri Sarha <jsarha@ti.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 */
10
11#include <linux/component.h>
12#include <linux/of_graph.h>
13
14#include "tilcdc_drv.h"
15#include "tilcdc_external.h"
16
17static const struct tilcdc_panel_info panel_info_tda998x = {
18 .ac_bias = 255,
19 .ac_bias_intrpt = 0,
20 .dma_burst_sz = 16,
21 .bpp = 16,
22 .fdd = 0x80,
23 .tft_alt_mode = 0,
24 .invert_pxl_clk = 1,
25 .sync_edge = 1,
26 .sync_ctrl = 1,
27 .raster_order = 0,
28};
29
30static int tilcdc_external_mode_valid(struct drm_connector *connector,
31 struct drm_display_mode *mode)
32{
33 struct tilcdc_drm_private *priv = connector->dev->dev_private;
34 int ret, i;
35
36 ret = tilcdc_crtc_mode_valid(priv->crtc, mode);
37 if (ret != MODE_OK)
38 return ret;
39
40 for (i = 0; i < priv->num_connectors &&
41 priv->connectors[i] != connector; i++)
42 ;
43
44 BUG_ON(priv->connectors[i] != connector);
45 BUG_ON(!priv->connector_funcs[i]);
46
47 /* If the connector has its own mode_valid call it. */
48 if (!IS_ERR(priv->connector_funcs[i]) &&
49 priv->connector_funcs[i]->mode_valid)
50 return priv->connector_funcs[i]->mode_valid(connector, mode);
51
52 return MODE_OK;
53}
54
55static int tilcdc_add_external_encoder(struct drm_device *dev, int *bpp,
56 struct drm_connector *connector)
57{
58 struct tilcdc_drm_private *priv = dev->dev_private;
59 struct drm_connector_helper_funcs *connector_funcs;
60
61 priv->connectors[priv->num_connectors] = connector;
62 priv->encoders[priv->num_encoders++] = connector->encoder;
63
64 /* Only tda998x is supported at the moment. */
65 tilcdc_crtc_set_simulate_vesa_sync(priv->crtc, true);
66 tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_tda998x);
67 *bpp = panel_info_tda998x.bpp;
68
69 connector_funcs = devm_kzalloc(dev->dev, sizeof(*connector_funcs),
70 GFP_KERNEL);
71 if (!connector_funcs)
72 return -ENOMEM;
73
74 /* connector->helper_private contains always struct
75 * connector_helper_funcs pointer. For tilcdc crtc to have a
76 * say if a specific mode is Ok, we need to install our own
77 * helper functions. In our helper functions we copy
78 * everything else but use our own mode_valid() (above).
79 */
80 if (connector->helper_private) {
81 priv->connector_funcs[priv->num_connectors] =
82 connector->helper_private;
83 *connector_funcs = *priv->connector_funcs[priv->num_connectors];
84 } else {
85 priv->connector_funcs[priv->num_connectors] = ERR_PTR(-ENOENT);
86 }
87 connector_funcs->mode_valid = tilcdc_external_mode_valid;
88 drm_connector_helper_add(connector, connector_funcs);
89 priv->num_connectors++;
90
91 dev_dbg(dev->dev, "External encoder '%s' connected\n",
92 connector->encoder->name);
93
94 return 0;
95}
96
97int tilcdc_add_external_encoders(struct drm_device *dev, int *bpp)
98{
99 struct tilcdc_drm_private *priv = dev->dev_private;
100 struct drm_connector *connector;
101 int num_internal_connectors = priv->num_connectors;
102
103 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
104 bool found = false;
105 int i, ret;
106
107 for (i = 0; i < num_internal_connectors; i++)
108 if (connector == priv->connectors[i])
109 found = true;
110 if (!found) {
111 ret = tilcdc_add_external_encoder(dev, bpp, connector);
112 if (ret)
113 return ret;
114 }
115 }
116 return 0;
117}
118
119void tilcdc_remove_external_encoders(struct drm_device *dev)
120{
121 struct tilcdc_drm_private *priv = dev->dev_private;
122 int i;
123
124 /* Restore the original helper functions, if any. */
125 for (i = 0; i < priv->num_connectors; i++)
126 if (IS_ERR(priv->connector_funcs[i]))
127 drm_connector_helper_add(priv->connectors[i], NULL);
128 else if (priv->connector_funcs[i])
129 drm_connector_helper_add(priv->connectors[i],
130 priv->connector_funcs[i]);
131}
132
133static int dev_match_of(struct device *dev, void *data)
134{
135 return dev->of_node == data;
136}
137
138int tilcdc_get_external_components(struct device *dev,
139 struct component_match **match)
140{
141 struct device_node *ep = NULL;
142 int count = 0;
143
144 while ((ep = of_graph_get_next_endpoint(dev->of_node, ep))) {
145 struct device_node *node;
146
147 node = of_graph_get_remote_port_parent(ep);
148 if (!node && !of_device_is_available(node)) {
149 of_node_put(node);
150 continue;
151 }
152
153 dev_dbg(dev, "Subdevice node '%s' found\n", node->name);
154 if (match)
155 component_match_add(dev, match, dev_match_of, node);
156 of_node_put(node);
157 count++;
158 }
159
160 if (count > 1) {
161 dev_err(dev, "Only one external encoder is supported\n");
162 return -EINVAL;
163 }
164
165 return count;
166}
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.h b/drivers/gpu/drm/tilcdc/tilcdc_external.h
new file mode 100644
index 000000000000..6aabe2788760
--- /dev/null
+++ b/drivers/gpu/drm/tilcdc/tilcdc_external.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2015 Texas Instruments
3 * Author: Jyri Sarha <jsarha@ti.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __TILCDC_EXTERNAL_H__
19#define __TILCDC_EXTERNAL_H__
20
21int tilcdc_add_external_encoders(struct drm_device *dev, int *bpp);
22void tilcdc_remove_external_encoders(struct drm_device *dev);
23int tilcdc_get_external_components(struct device *dev,
24 struct component_match **match);
25#endif /* __TILCDC_SLAVE_H__ */