Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+329 -13
+27
Documentation/devicetree/bindings/drm/tilcdc/tilcdc.txt
··· 18 18 - max-pixelclock: The maximum pixel clock that can be supported 19 19 by the lcd controller in KHz. 20 20 21 + Optional nodes: 22 + 23 + - port/ports: to describe a connection to an external encoder. The 24 + binding follows Documentation/devicetree/bindings/graph.txt and 25 + suppors a single port with a single endpoint. 26 + 21 27 Example: 22 28 23 29 fb: fb@4830e000 { ··· 32 26 interrupt-parent = <&intc>; 33 27 interrupts = <36>; 34 28 ti,hwmods = "lcdc"; 29 + 30 + port { 31 + lcdc_0: endpoint@0 { 32 + remote-endpoint = <&hdmi_0>; 33 + }; 34 + }; 35 + }; 36 + 37 + tda19988: tda19988 { 38 + compatible = "nxp,tda998x"; 39 + reg = <0x70>; 40 + 41 + pinctrl-names = "default", "off"; 42 + pinctrl-0 = <&nxp_hdmi_bonelt_pins>; 43 + pinctrl-1 = <&nxp_hdmi_bonelt_off_pins>; 44 + 45 + port { 46 + hdmi_0: endpoint@0 { 47 + remote-endpoint = <&lcdc_0>; 48 + }; 49 + }; 35 50 };
+1
drivers/gpu/drm/tilcdc/Makefile
··· 7 7 tilcdc_crtc.o \ 8 8 tilcdc_tfp410.o \ 9 9 tilcdc_panel.o \ 10 + tilcdc_external.o \ 10 11 tilcdc_drv.o 11 12 12 13 obj-$(CONFIG_DRM_TILCDC) += tilcdc.o
+33
drivers/gpu/drm/tilcdc/tilcdc_crtc.c
··· 37 37 38 38 /* for deferred fb unref's: */ 39 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 44 #define to_tilcdc_crtc(x) container_of(x, struct tilcdc_crtc, base) 42 45 ··· 217 214 const struct drm_display_mode *mode, 218 215 struct drm_display_mode *adjusted_mode) 219 216 { 217 + struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); 218 + 219 + if (!tilcdc_crtc->simulate_vesa_sync) 220 + return true; 221 + 222 + /* 223 + * tilcdc does not generate VESA-compliant sync but aligns 224 + * VS on the second edge of HS instead of first edge. 225 + * We use adjusted_mode, to fixup sync by aligning both rising 226 + * edges and add HSKEW offset to fix the sync. 227 + */ 228 + adjusted_mode->hskew = mode->hsync_end - mode->hsync_start; 229 + adjusted_mode->flags |= DRM_MODE_FLAG_HSKEW; 230 + 231 + if (mode->flags & DRM_MODE_FLAG_NHSYNC) { 232 + adjusted_mode->flags |= DRM_MODE_FLAG_PHSYNC; 233 + adjusted_mode->flags &= ~DRM_MODE_FLAG_NHSYNC; 234 + } else { 235 + adjusted_mode->flags |= DRM_MODE_FLAG_NHSYNC; 236 + adjusted_mode->flags &= ~DRM_MODE_FLAG_PHSYNC; 237 + } 238 + 220 239 return true; 221 240 } 222 241 ··· 557 532 { 558 533 struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); 559 534 tilcdc_crtc->info = info; 535 + } 536 + 537 + void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc, 538 + bool simulate_vesa_sync) 539 + { 540 + struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); 541 + 542 + tilcdc_crtc->simulate_vesa_sync = simulate_vesa_sync; 560 543 } 561 544 562 545 void tilcdc_crtc_update_clk(struct drm_crtc *crtc)
+72 -13
drivers/gpu/drm/tilcdc/tilcdc_drv.c
··· 17 17 18 18 /* LCDC DRM driver, based on da8xx-fb */ 19 19 20 + #include <linux/component.h> 21 + 20 22 #include "tilcdc_drv.h" 21 23 #include "tilcdc_regs.h" 22 24 #include "tilcdc_tfp410.h" 23 25 #include "tilcdc_panel.h" 26 + #include "tilcdc_external.h" 24 27 25 28 #include "drm_fb_helper.h" 26 29 ··· 76 73 mod->funcs->modeset_init(mod, dev); 77 74 } 78 75 79 - if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) { 80 - /* oh nos! */ 81 - dev_err(dev->dev, "no encoders/connectors found\n"); 82 - drm_mode_config_cleanup(dev); 83 - return -ENXIO; 84 - } 85 - 86 76 dev->mode_config.min_width = 0; 87 77 dev->mode_config.min_height = 0; 88 78 dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc); ··· 109 113 static int tilcdc_unload(struct drm_device *dev) 110 114 { 111 115 struct tilcdc_drm_private *priv = dev->dev_private; 116 + 117 + tilcdc_remove_external_encoders(dev); 112 118 113 119 drm_fbdev_cma_fini(priv->fbdev); 114 120 drm_kms_helper_poll_fini(dev); ··· 161 163 } 162 164 163 165 dev->dev_private = priv; 166 + 167 + priv->is_componentized = 168 + tilcdc_get_external_components(dev->dev, NULL) > 0; 164 169 165 170 priv->wq = alloc_ordered_workqueue("tilcdc", 0); 166 171 if (!priv->wq) { ··· 254 253 goto fail_cpufreq_unregister; 255 254 } 256 255 256 + platform_set_drvdata(pdev, dev); 257 + 258 + if (priv->is_componentized) { 259 + ret = component_bind_all(dev->dev, dev); 260 + if (ret < 0) 261 + goto fail_mode_config_cleanup; 262 + 263 + ret = tilcdc_add_external_encoders(dev, &bpp); 264 + if (ret < 0) 265 + goto fail_component_cleanup; 266 + } 267 + 268 + if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) { 269 + dev_err(dev->dev, "no encoders/connectors found\n"); 270 + ret = -ENXIO; 271 + goto fail_external_cleanup; 272 + } 273 + 257 274 ret = drm_vblank_init(dev, 1); 258 275 if (ret < 0) { 259 276 dev_err(dev->dev, "failed to initialize vblank\n"); 260 - goto fail_mode_config_cleanup; 277 + goto fail_external_cleanup; 261 278 } 262 279 263 280 pm_runtime_get_sync(dev->dev); ··· 285 266 dev_err(dev->dev, "failed to install IRQ handler\n"); 286 267 goto fail_vblank_cleanup; 287 268 } 288 - 289 - platform_set_drvdata(pdev, dev); 290 - 291 269 292 270 list_for_each_entry(mod, &module_list, list) { 293 271 DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp); ··· 315 299 316 300 fail_mode_config_cleanup: 317 301 drm_mode_config_cleanup(dev); 302 + 303 + fail_component_cleanup: 304 + if (priv->is_componentized) 305 + component_unbind_all(dev->dev, dev); 306 + 307 + fail_external_cleanup: 308 + tilcdc_remove_external_encoders(dev); 318 309 319 310 fail_cpufreq_unregister: 320 311 pm_runtime_disable(dev->dev); ··· 628 605 * Platform driver: 629 606 */ 630 607 608 + static int tilcdc_bind(struct device *dev) 609 + { 610 + return drm_platform_init(&tilcdc_driver, to_platform_device(dev)); 611 + } 612 + 613 + static void tilcdc_unbind(struct device *dev) 614 + { 615 + drm_put_dev(dev_get_drvdata(dev)); 616 + } 617 + 618 + static const struct component_master_ops tilcdc_comp_ops = { 619 + .bind = tilcdc_bind, 620 + .unbind = tilcdc_unbind, 621 + }; 622 + 631 623 static int tilcdc_pdev_probe(struct platform_device *pdev) 632 624 { 625 + struct component_match *match = NULL; 626 + int ret; 627 + 633 628 /* bail out early if no DT data: */ 634 629 if (!pdev->dev.of_node) { 635 630 dev_err(&pdev->dev, "device-tree data is missing\n"); 636 631 return -ENXIO; 637 632 } 638 633 639 - return drm_platform_init(&tilcdc_driver, pdev); 634 + ret = tilcdc_get_external_components(&pdev->dev, &match); 635 + if (ret < 0) 636 + return ret; 637 + else if (ret == 0) 638 + return drm_platform_init(&tilcdc_driver, pdev); 639 + else 640 + return component_master_add_with_match(&pdev->dev, 641 + &tilcdc_comp_ops, 642 + match); 640 643 } 641 644 642 645 static int tilcdc_pdev_remove(struct platform_device *pdev) 643 646 { 644 - drm_put_dev(platform_get_drvdata(pdev)); 647 + struct drm_device *ddev = dev_get_drvdata(&pdev->dev); 648 + struct tilcdc_drm_private *priv = ddev->dev_private; 649 + 650 + /* Check if a subcomponent has already triggered the unloading. */ 651 + if (!priv) 652 + return 0; 653 + 654 + if (priv->is_componentized) 655 + component_master_del(&pdev->dev, &tilcdc_comp_ops); 656 + else 657 + drm_put_dev(platform_get_drvdata(pdev)); 645 658 646 659 return 0; 647 660 }
+5
drivers/gpu/drm/tilcdc/tilcdc_drv.h
··· 85 85 86 86 unsigned int num_connectors; 87 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 93 /* Sub-module for display. Since we don't know at compile time what panels ··· 168 165 void tilcdc_crtc_update_clk(struct drm_crtc *crtc); 169 166 void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, 170 167 const struct tilcdc_panel_info *info); 168 + void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc, 169 + bool simulate_vesa_sync); 171 170 int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode); 172 171 int tilcdc_crtc_max_width(struct drm_crtc *crtc); 173 172
+166
drivers/gpu/drm/tilcdc/tilcdc_external.c
··· 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 + 17 + static 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 + 30 + static 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 + 55 + static 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 + 97 + int 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 + 119 + void 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 + 133 + static int dev_match_of(struct device *dev, void *data) 134 + { 135 + return dev->of_node == data; 136 + } 137 + 138 + int 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 + }
+25
drivers/gpu/drm/tilcdc/tilcdc_external.h
··· 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 + 21 + int tilcdc_add_external_encoders(struct drm_device *dev, int *bpp); 22 + void tilcdc_remove_external_encoders(struct drm_device *dev); 23 + int tilcdc_get_external_components(struct device *dev, 24 + struct component_match **match); 25 + #endif /* __TILCDC_SLAVE_H__ */