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

Configure Feed

Select the types of activity you want to include in your feed.

at master 321 lines 9.1 kB view raw
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (C) 2015-2016 Free Electrons 4 * Copyright (C) 2015-2016 NextThing Co 5 * 6 * Maxime Ripard <maxime.ripard@free-electrons.com> 7 */ 8 9#include <linux/gpio/consumer.h> 10#include <linux/module.h> 11#include <linux/of.h> 12#include <linux/of_graph.h> 13#include <linux/platform_device.h> 14#include <linux/regulator/consumer.h> 15 16#include <drm/drm_atomic_helper.h> 17#include <drm/drm_bridge.h> 18#include <drm/drm_crtc.h> 19#include <drm/drm_edid.h> 20#include <drm/drm_print.h> 21#include <drm/drm_probe_helper.h> 22 23struct simple_bridge_info { 24 const struct drm_bridge_timings *timings; 25 unsigned int connector_type; 26}; 27 28struct simple_bridge { 29 struct drm_bridge bridge; 30 struct drm_connector connector; 31 32 const struct simple_bridge_info *info; 33 34 struct regulator *vdd; 35 struct gpio_desc *enable; 36}; 37 38static inline struct simple_bridge * 39drm_bridge_to_simple_bridge(struct drm_bridge *bridge) 40{ 41 return container_of(bridge, struct simple_bridge, bridge); 42} 43 44static inline struct simple_bridge * 45drm_connector_to_simple_bridge(struct drm_connector *connector) 46{ 47 return container_of(connector, struct simple_bridge, connector); 48} 49 50static int simple_bridge_get_modes(struct drm_connector *connector) 51{ 52 struct simple_bridge *sbridge = drm_connector_to_simple_bridge(connector); 53 const struct drm_edid *drm_edid; 54 int ret; 55 56 if (sbridge->bridge.next_bridge->ops & DRM_BRIDGE_OP_EDID) { 57 drm_edid = drm_bridge_edid_read(sbridge->bridge.next_bridge, connector); 58 if (!drm_edid) 59 DRM_INFO("EDID read failed. Fallback to standard modes\n"); 60 } else { 61 drm_edid = NULL; 62 } 63 64 drm_edid_connector_update(connector, drm_edid); 65 66 if (!drm_edid) { 67 /* 68 * In case we cannot retrieve the EDIDs (missing or broken DDC 69 * bus from the next bridge), fallback on the XGA standards and 70 * prefer a mode pretty much anyone can handle. 71 */ 72 ret = drm_add_modes_noedid(connector, 1920, 1200); 73 drm_set_preferred_mode(connector, 1024, 768); 74 return ret; 75 } 76 77 ret = drm_edid_connector_add_modes(connector); 78 drm_edid_free(drm_edid); 79 80 return ret; 81} 82 83static const struct drm_connector_helper_funcs simple_bridge_con_helper_funcs = { 84 .get_modes = simple_bridge_get_modes, 85}; 86 87static enum drm_connector_status 88simple_bridge_connector_detect(struct drm_connector *connector, bool force) 89{ 90 struct simple_bridge *sbridge = drm_connector_to_simple_bridge(connector); 91 92 return drm_bridge_detect(sbridge->bridge.next_bridge, connector); 93} 94 95static const struct drm_connector_funcs simple_bridge_con_funcs = { 96 .detect = simple_bridge_connector_detect, 97 .fill_modes = drm_helper_probe_single_connector_modes, 98 .destroy = drm_connector_cleanup, 99 .reset = drm_atomic_helper_connector_reset, 100 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 101 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 102}; 103 104static int simple_bridge_attach(struct drm_bridge *bridge, 105 struct drm_encoder *encoder, 106 enum drm_bridge_attach_flags flags) 107{ 108 struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge); 109 int ret; 110 111 ret = drm_bridge_attach(encoder, sbridge->bridge.next_bridge, bridge, 112 DRM_BRIDGE_ATTACH_NO_CONNECTOR); 113 if (ret < 0) 114 return ret; 115 116 if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) 117 return 0; 118 119 drm_connector_helper_add(&sbridge->connector, 120 &simple_bridge_con_helper_funcs); 121 ret = drm_connector_init_with_ddc(bridge->dev, &sbridge->connector, 122 &simple_bridge_con_funcs, 123 sbridge->info->connector_type, 124 sbridge->bridge.next_bridge->ddc); 125 if (ret) { 126 DRM_ERROR("Failed to initialize connector\n"); 127 return ret; 128 } 129 130 drm_connector_attach_encoder(&sbridge->connector, encoder); 131 132 return 0; 133} 134 135static void simple_bridge_enable(struct drm_bridge *bridge) 136{ 137 struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge); 138 int ret; 139 140 if (sbridge->vdd) { 141 ret = regulator_enable(sbridge->vdd); 142 if (ret) 143 DRM_ERROR("Failed to enable vdd regulator: %d\n", ret); 144 } 145 146 gpiod_set_value_cansleep(sbridge->enable, 1); 147} 148 149static void simple_bridge_disable(struct drm_bridge *bridge) 150{ 151 struct simple_bridge *sbridge = drm_bridge_to_simple_bridge(bridge); 152 153 gpiod_set_value_cansleep(sbridge->enable, 0); 154 155 if (sbridge->vdd) 156 regulator_disable(sbridge->vdd); 157} 158 159static const struct drm_bridge_funcs simple_bridge_bridge_funcs = { 160 .attach = simple_bridge_attach, 161 .enable = simple_bridge_enable, 162 .disable = simple_bridge_disable, 163}; 164 165static int simple_bridge_probe(struct platform_device *pdev) 166{ 167 struct simple_bridge *sbridge; 168 struct device_node *remote; 169 170 sbridge = devm_drm_bridge_alloc(&pdev->dev, struct simple_bridge, 171 bridge, &simple_bridge_bridge_funcs); 172 if (IS_ERR(sbridge)) 173 return PTR_ERR(sbridge); 174 175 sbridge->info = of_device_get_match_data(&pdev->dev); 176 177 /* Get the next bridge in the pipeline. */ 178 remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1); 179 if (!remote) 180 return -EINVAL; 181 182 sbridge->bridge.next_bridge = of_drm_find_and_get_bridge(remote); 183 of_node_put(remote); 184 185 if (!sbridge->bridge.next_bridge) { 186 dev_dbg(&pdev->dev, "Next bridge not found, deferring probe\n"); 187 return -EPROBE_DEFER; 188 } 189 190 /* Get the regulator and GPIO resources. */ 191 sbridge->vdd = devm_regulator_get_optional(&pdev->dev, "vdd"); 192 if (IS_ERR(sbridge->vdd)) { 193 int ret = PTR_ERR(sbridge->vdd); 194 if (ret == -EPROBE_DEFER) 195 return -EPROBE_DEFER; 196 sbridge->vdd = NULL; 197 dev_dbg(&pdev->dev, "No vdd regulator found: %d\n", ret); 198 } 199 200 sbridge->enable = devm_gpiod_get_optional(&pdev->dev, "enable", 201 GPIOD_OUT_LOW); 202 if (IS_ERR(sbridge->enable)) 203 return dev_err_probe(&pdev->dev, PTR_ERR(sbridge->enable), 204 "Unable to retrieve enable GPIO\n"); 205 206 /* Register the bridge. */ 207 sbridge->bridge.of_node = pdev->dev.of_node; 208 sbridge->bridge.timings = sbridge->info->timings; 209 210 return devm_drm_bridge_add(&pdev->dev, &sbridge->bridge); 211} 212 213/* 214 * We assume the ADV7123 DAC is the "default" for historical reasons 215 * Information taken from the ADV7123 datasheet, revision D. 216 * NOTE: the ADV7123EP seems to have other timings and need a new timings 217 * set if used. 218 */ 219static const struct drm_bridge_timings default_bridge_timings = { 220 /* Timing specifications, datasheet page 7 */ 221 .input_bus_flags = DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE, 222 .setup_time_ps = 500, 223 .hold_time_ps = 1500, 224}; 225 226/* 227 * Information taken from the THS8134, THS8134A, THS8134B datasheet named 228 * "SLVS205D", dated May 1990, revised March 2000. 229 */ 230static const struct drm_bridge_timings ti_ths8134_bridge_timings = { 231 /* From timing diagram, datasheet page 9 */ 232 .input_bus_flags = DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE, 233 /* From datasheet, page 12 */ 234 .setup_time_ps = 3000, 235 /* I guess this means latched input */ 236 .hold_time_ps = 0, 237}; 238 239/* 240 * Information taken from the THS8135 datasheet named "SLAS343B", dated 241 * May 2001, revised April 2013. 242 */ 243static const struct drm_bridge_timings ti_ths8135_bridge_timings = { 244 /* From timing diagram, datasheet page 14 */ 245 .input_bus_flags = DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE, 246 /* From datasheet, page 16 */ 247 .setup_time_ps = 2000, 248 .hold_time_ps = 500, 249}; 250 251static const struct of_device_id simple_bridge_match[] = { 252 { 253 .compatible = "dumb-vga-dac", 254 .data = &(const struct simple_bridge_info) { 255 .connector_type = DRM_MODE_CONNECTOR_VGA, 256 }, 257 }, { 258 .compatible = "adi,adv7123", 259 .data = &(const struct simple_bridge_info) { 260 .timings = &default_bridge_timings, 261 .connector_type = DRM_MODE_CONNECTOR_VGA, 262 }, 263 }, { 264 .compatible = "algoltek,ag6311", 265 .data = &(const struct simple_bridge_info) { 266 .connector_type = DRM_MODE_CONNECTOR_HDMIA, 267 }, 268 }, { 269 .compatible = "asl-tek,cs5263", 270 .data = &(const struct simple_bridge_info) { 271 .connector_type = DRM_MODE_CONNECTOR_HDMIA, 272 }, 273 }, { 274 .compatible = "parade,ps185hdm", 275 .data = &(const struct simple_bridge_info) { 276 .connector_type = DRM_MODE_CONNECTOR_HDMIA, 277 }, 278 }, { 279 .compatible = "radxa,ra620", 280 .data = &(const struct simple_bridge_info) { 281 .connector_type = DRM_MODE_CONNECTOR_HDMIA, 282 }, 283 }, { 284 .compatible = "realtek,rtd2171", 285 .data = &(const struct simple_bridge_info) { 286 .connector_type = DRM_MODE_CONNECTOR_HDMIA, 287 }, 288 }, { 289 .compatible = "ti,opa362", 290 .data = &(const struct simple_bridge_info) { 291 .connector_type = DRM_MODE_CONNECTOR_Composite, 292 }, 293 }, { 294 .compatible = "ti,ths8135", 295 .data = &(const struct simple_bridge_info) { 296 .timings = &ti_ths8135_bridge_timings, 297 .connector_type = DRM_MODE_CONNECTOR_VGA, 298 }, 299 }, { 300 .compatible = "ti,ths8134", 301 .data = &(const struct simple_bridge_info) { 302 .timings = &ti_ths8134_bridge_timings, 303 .connector_type = DRM_MODE_CONNECTOR_VGA, 304 }, 305 }, 306 {}, 307}; 308MODULE_DEVICE_TABLE(of, simple_bridge_match); 309 310static struct platform_driver simple_bridge_driver = { 311 .probe = simple_bridge_probe, 312 .driver = { 313 .name = "simple-bridge", 314 .of_match_table = simple_bridge_match, 315 }, 316}; 317module_platform_driver(simple_bridge_driver); 318 319MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 320MODULE_DESCRIPTION("Simple DRM bridge driver"); 321MODULE_LICENSE("GPL");