Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Analog TV Connector driver |
| 3 | * |
| 4 | * Copyright (C) 2013 Texas Instruments |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@ti.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/platform_device.h> |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 15 | #include <linux/of.h> |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 16 | |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 17 | #include <video/omap-panel-data.h> |
| 18 | |
Peter Ujfalusi | 32043da | 2016-05-27 14:40:49 +0300 | [diff] [blame] | 19 | #include "../dss/omapdss.h" |
| 20 | |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 21 | struct panel_drv_data { |
| 22 | struct omap_dss_device dssdev; |
| 23 | struct omap_dss_device *in; |
| 24 | |
| 25 | struct device *dev; |
| 26 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 27 | struct videomode vm; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 28 | |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 29 | bool invert_polarity; |
| 30 | }; |
| 31 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 32 | static const struct videomode tvc_pal_vm = { |
Peter Ujfalusi | 8189906 | 2016-09-22 14:06:46 +0300 | [diff] [blame] | 33 | .hactive = 720, |
Peter Ujfalusi | fb7f3c4 | 2016-09-22 14:06:47 +0300 | [diff] [blame] | 34 | .vactive = 574, |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 35 | .pixelclock = 13500000, |
Peter Ujfalusi | 4dc2250 | 2016-09-22 14:06:48 +0300 | [diff] [blame] | 36 | .hsync_len = 64, |
Peter Ujfalusi | 0a30e15 | 2016-09-22 14:06:49 +0300 | [diff] [blame] | 37 | .hfront_porch = 12, |
Peter Ujfalusi | a85f4a8 | 2016-09-22 14:06:50 +0300 | [diff] [blame] | 38 | .hback_porch = 68, |
Peter Ujfalusi | d5bcf0a | 2016-09-22 14:06:51 +0300 | [diff] [blame] | 39 | .vsync_len = 5, |
Peter Ujfalusi | 0996c68 | 2016-09-22 14:06:52 +0300 | [diff] [blame] | 40 | .vfront_porch = 5, |
Peter Ujfalusi | 458540c | 2016-09-22 14:06:53 +0300 | [diff] [blame] | 41 | .vback_porch = 41, |
Tomi Valkeinen | 005358c | 2013-08-02 10:15:01 +0300 | [diff] [blame] | 42 | |
Peter Ujfalusi | 6b44cd2 | 2016-09-22 14:06:57 +0300 | [diff] [blame] | 43 | .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW | |
| 44 | DISPLAY_FLAGS_VSYNC_LOW, |
Tomi Valkeinen | 005358c | 2013-08-02 10:15:01 +0300 | [diff] [blame] | 45 | }; |
| 46 | |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 47 | static const struct of_device_id tvc_of_match[]; |
| 48 | |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 49 | #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) |
| 50 | |
| 51 | static int tvc_connect(struct omap_dss_device *dssdev) |
| 52 | { |
| 53 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 54 | struct omap_dss_device *in = ddata->in; |
| 55 | int r; |
| 56 | |
| 57 | dev_dbg(ddata->dev, "connect\n"); |
| 58 | |
| 59 | if (omapdss_device_is_connected(dssdev)) |
| 60 | return 0; |
| 61 | |
| 62 | r = in->ops.atv->connect(in, dssdev); |
| 63 | if (r) |
| 64 | return r; |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static void tvc_disconnect(struct omap_dss_device *dssdev) |
| 70 | { |
| 71 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 72 | struct omap_dss_device *in = ddata->in; |
| 73 | |
| 74 | dev_dbg(ddata->dev, "disconnect\n"); |
| 75 | |
| 76 | if (!omapdss_device_is_connected(dssdev)) |
| 77 | return; |
| 78 | |
| 79 | in->ops.atv->disconnect(in, dssdev); |
| 80 | } |
| 81 | |
| 82 | static int tvc_enable(struct omap_dss_device *dssdev) |
| 83 | { |
| 84 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 85 | struct omap_dss_device *in = ddata->in; |
| 86 | int r; |
| 87 | |
| 88 | dev_dbg(ddata->dev, "enable\n"); |
| 89 | |
| 90 | if (!omapdss_device_is_connected(dssdev)) |
| 91 | return -ENODEV; |
| 92 | |
| 93 | if (omapdss_device_is_enabled(dssdev)) |
| 94 | return 0; |
| 95 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 96 | in->ops.atv->set_timings(in, &ddata->vm); |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 97 | |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 98 | if (!ddata->dev->of_node) { |
Peter Ujfalusi | e2e1d8f | 2016-05-30 13:21:06 +0300 | [diff] [blame] | 99 | in->ops.atv->set_type(in, OMAP_DSS_VENC_TYPE_COMPOSITE); |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 100 | |
| 101 | in->ops.atv->invert_vid_out_polarity(in, |
| 102 | ddata->invert_polarity); |
| 103 | } |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 104 | |
| 105 | r = in->ops.atv->enable(in); |
| 106 | if (r) |
| 107 | return r; |
| 108 | |
| 109 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 110 | |
| 111 | return r; |
| 112 | } |
| 113 | |
| 114 | static void tvc_disable(struct omap_dss_device *dssdev) |
| 115 | { |
| 116 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 117 | struct omap_dss_device *in = ddata->in; |
| 118 | |
| 119 | dev_dbg(ddata->dev, "disable\n"); |
| 120 | |
| 121 | if (!omapdss_device_is_enabled(dssdev)) |
| 122 | return; |
| 123 | |
| 124 | in->ops.atv->disable(in); |
| 125 | |
| 126 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
| 127 | } |
| 128 | |
| 129 | static void tvc_set_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 130 | struct videomode *vm) |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 131 | { |
| 132 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 133 | struct omap_dss_device *in = ddata->in; |
| 134 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 135 | ddata->vm = *vm; |
| 136 | dssdev->panel.vm = *vm; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 137 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 138 | in->ops.atv->set_timings(in, vm); |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static void tvc_get_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 142 | struct videomode *vm) |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 143 | { |
| 144 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 145 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 146 | *vm = ddata->vm; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static int tvc_check_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 150 | struct videomode *vm) |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 151 | { |
| 152 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 153 | struct omap_dss_device *in = ddata->in; |
| 154 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 155 | return in->ops.atv->check_timings(in, vm); |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static u32 tvc_get_wss(struct omap_dss_device *dssdev) |
| 159 | { |
| 160 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 161 | struct omap_dss_device *in = ddata->in; |
| 162 | |
| 163 | return in->ops.atv->get_wss(in); |
| 164 | } |
| 165 | |
| 166 | static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss) |
| 167 | { |
| 168 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 169 | struct omap_dss_device *in = ddata->in; |
| 170 | |
| 171 | return in->ops.atv->set_wss(in, wss); |
| 172 | } |
| 173 | |
| 174 | static struct omap_dss_driver tvc_driver = { |
| 175 | .connect = tvc_connect, |
| 176 | .disconnect = tvc_disconnect, |
| 177 | |
| 178 | .enable = tvc_enable, |
| 179 | .disable = tvc_disable, |
| 180 | |
| 181 | .set_timings = tvc_set_timings, |
| 182 | .get_timings = tvc_get_timings, |
| 183 | .check_timings = tvc_check_timings, |
| 184 | |
| 185 | .get_resolution = omapdss_default_get_resolution, |
| 186 | |
| 187 | .get_wss = tvc_get_wss, |
| 188 | .set_wss = tvc_set_wss, |
| 189 | }; |
| 190 | |
| 191 | static int tvc_probe_pdata(struct platform_device *pdev) |
| 192 | { |
| 193 | struct panel_drv_data *ddata = platform_get_drvdata(pdev); |
| 194 | struct connector_atv_platform_data *pdata; |
| 195 | struct omap_dss_device *in, *dssdev; |
| 196 | |
| 197 | pdata = dev_get_platdata(&pdev->dev); |
| 198 | |
| 199 | in = omap_dss_find_output(pdata->source); |
| 200 | if (in == NULL) { |
| 201 | dev_err(&pdev->dev, "Failed to find video source\n"); |
Sathya Prakash M R | 0fd9560 | 2013-09-12 14:12:55 +0530 | [diff] [blame] | 202 | return -EPROBE_DEFER; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | ddata->in = in; |
| 206 | |
Rasmus Villemoes | 493a584 | 2015-01-05 14:09:47 +0100 | [diff] [blame] | 207 | ddata->invert_polarity = pdata->invert_polarity; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 208 | |
| 209 | dssdev = &ddata->dssdev; |
| 210 | dssdev->name = pdata->name; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 215 | static int tvc_probe_of(struct platform_device *pdev) |
| 216 | { |
| 217 | struct panel_drv_data *ddata = platform_get_drvdata(pdev); |
| 218 | struct device_node *node = pdev->dev.of_node; |
| 219 | struct omap_dss_device *in; |
| 220 | |
| 221 | in = omapdss_of_find_source_for_first_ep(node); |
| 222 | if (IS_ERR(in)) { |
| 223 | dev_err(&pdev->dev, "failed to find video source\n"); |
| 224 | return PTR_ERR(in); |
| 225 | } |
| 226 | |
| 227 | ddata->in = in; |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 232 | static int tvc_probe(struct platform_device *pdev) |
| 233 | { |
| 234 | struct panel_drv_data *ddata; |
| 235 | struct omap_dss_device *dssdev; |
| 236 | int r; |
| 237 | |
| 238 | ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); |
| 239 | if (!ddata) |
| 240 | return -ENOMEM; |
| 241 | |
| 242 | platform_set_drvdata(pdev, ddata); |
| 243 | ddata->dev = &pdev->dev; |
| 244 | |
| 245 | if (dev_get_platdata(&pdev->dev)) { |
| 246 | r = tvc_probe_pdata(pdev); |
| 247 | if (r) |
| 248 | return r; |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 249 | } else if (pdev->dev.of_node) { |
| 250 | r = tvc_probe_of(pdev); |
| 251 | if (r) |
| 252 | return r; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 253 | } else { |
| 254 | return -ENODEV; |
| 255 | } |
| 256 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 257 | ddata->vm = tvc_pal_vm; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 258 | |
| 259 | dssdev = &ddata->dssdev; |
| 260 | dssdev->driver = &tvc_driver; |
| 261 | dssdev->dev = &pdev->dev; |
| 262 | dssdev->type = OMAP_DISPLAY_TYPE_VENC; |
| 263 | dssdev->owner = THIS_MODULE; |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 264 | dssdev->panel.vm = tvc_pal_vm; |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 265 | |
| 266 | r = omapdss_register_display(dssdev); |
| 267 | if (r) { |
| 268 | dev_err(&pdev->dev, "Failed to register panel\n"); |
| 269 | goto err_reg; |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | err_reg: |
| 274 | omap_dss_put_device(ddata->in); |
| 275 | return r; |
| 276 | } |
| 277 | |
| 278 | static int __exit tvc_remove(struct platform_device *pdev) |
| 279 | { |
| 280 | struct panel_drv_data *ddata = platform_get_drvdata(pdev); |
| 281 | struct omap_dss_device *dssdev = &ddata->dssdev; |
| 282 | struct omap_dss_device *in = ddata->in; |
| 283 | |
| 284 | omapdss_unregister_display(&ddata->dssdev); |
| 285 | |
| 286 | tvc_disable(dssdev); |
| 287 | tvc_disconnect(dssdev); |
| 288 | |
| 289 | omap_dss_put_device(in); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 294 | static const struct of_device_id tvc_of_match[] = { |
| 295 | { .compatible = "omapdss,svideo-connector", }, |
| 296 | { .compatible = "omapdss,composite-video-connector", }, |
| 297 | {}, |
| 298 | }; |
| 299 | |
Marek Belisko | 4ee9d9d | 2014-10-27 21:24:03 +0100 | [diff] [blame] | 300 | MODULE_DEVICE_TABLE(of, tvc_of_match); |
| 301 | |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 302 | static struct platform_driver tvc_connector_driver = { |
| 303 | .probe = tvc_probe, |
| 304 | .remove = __exit_p(tvc_remove), |
| 305 | .driver = { |
| 306 | .name = "connector-analog-tv", |
Tomi Valkeinen | fcc900a | 2013-05-29 15:34:06 +0300 | [diff] [blame] | 307 | .of_match_table = tvc_of_match, |
Tomi Valkeinen | 422ccbd | 2014-10-16 09:54:25 +0300 | [diff] [blame] | 308 | .suppress_bind_attrs = true, |
Tomi Valkeinen | 61a7f24 | 2013-05-24 14:21:30 +0300 | [diff] [blame] | 309 | }, |
| 310 | }; |
| 311 | |
| 312 | module_platform_driver(tvc_connector_driver); |
| 313 | |
| 314 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); |
| 315 | MODULE_DESCRIPTION("Analog TV Connector driver"); |
| 316 | MODULE_LICENSE("GPL"); |