0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/slab.h>
0010 #include <linux/module.h>
0011 #include <linux/platform_device.h>
0012 #include <linux/of.h>
0013
0014 #include <video/omapfb_dss.h>
0015 #include <video/omap-panel-data.h>
0016
0017 struct panel_drv_data {
0018 struct omap_dss_device dssdev;
0019 struct omap_dss_device *in;
0020
0021 struct device *dev;
0022
0023 struct omap_video_timings timings;
0024
0025 bool invert_polarity;
0026 };
0027
0028 static const struct omap_video_timings tvc_pal_timings = {
0029 .x_res = 720,
0030 .y_res = 574,
0031 .pixelclock = 13500000,
0032 .hsw = 64,
0033 .hfp = 12,
0034 .hbp = 68,
0035 .vsw = 5,
0036 .vfp = 5,
0037 .vbp = 41,
0038
0039 .interlace = true,
0040 };
0041
0042 static const struct of_device_id tvc_of_match[];
0043
0044 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
0045
0046 static int tvc_connect(struct omap_dss_device *dssdev)
0047 {
0048 struct panel_drv_data *ddata = to_panel_data(dssdev);
0049 struct omap_dss_device *in = ddata->in;
0050
0051 dev_dbg(ddata->dev, "connect\n");
0052
0053 if (omapdss_device_is_connected(dssdev))
0054 return 0;
0055
0056 return in->ops.atv->connect(in, dssdev);
0057 }
0058
0059 static void tvc_disconnect(struct omap_dss_device *dssdev)
0060 {
0061 struct panel_drv_data *ddata = to_panel_data(dssdev);
0062 struct omap_dss_device *in = ddata->in;
0063
0064 dev_dbg(ddata->dev, "disconnect\n");
0065
0066 if (!omapdss_device_is_connected(dssdev))
0067 return;
0068
0069 in->ops.atv->disconnect(in, dssdev);
0070 }
0071
0072 static int tvc_enable(struct omap_dss_device *dssdev)
0073 {
0074 struct panel_drv_data *ddata = to_panel_data(dssdev);
0075 struct omap_dss_device *in = ddata->in;
0076 int r;
0077
0078 dev_dbg(ddata->dev, "enable\n");
0079
0080 if (!omapdss_device_is_connected(dssdev))
0081 return -ENODEV;
0082
0083 if (omapdss_device_is_enabled(dssdev))
0084 return 0;
0085
0086 in->ops.atv->set_timings(in, &ddata->timings);
0087
0088 if (!ddata->dev->of_node) {
0089 in->ops.atv->set_type(in, OMAP_DSS_VENC_TYPE_COMPOSITE);
0090
0091 in->ops.atv->invert_vid_out_polarity(in,
0092 ddata->invert_polarity);
0093 }
0094
0095 r = in->ops.atv->enable(in);
0096 if (r)
0097 return r;
0098
0099 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
0100
0101 return r;
0102 }
0103
0104 static void tvc_disable(struct omap_dss_device *dssdev)
0105 {
0106 struct panel_drv_data *ddata = to_panel_data(dssdev);
0107 struct omap_dss_device *in = ddata->in;
0108
0109 dev_dbg(ddata->dev, "disable\n");
0110
0111 if (!omapdss_device_is_enabled(dssdev))
0112 return;
0113
0114 in->ops.atv->disable(in);
0115
0116 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
0117 }
0118
0119 static void tvc_set_timings(struct omap_dss_device *dssdev,
0120 struct omap_video_timings *timings)
0121 {
0122 struct panel_drv_data *ddata = to_panel_data(dssdev);
0123 struct omap_dss_device *in = ddata->in;
0124
0125 ddata->timings = *timings;
0126 dssdev->panel.timings = *timings;
0127
0128 in->ops.atv->set_timings(in, timings);
0129 }
0130
0131 static void tvc_get_timings(struct omap_dss_device *dssdev,
0132 struct omap_video_timings *timings)
0133 {
0134 struct panel_drv_data *ddata = to_panel_data(dssdev);
0135
0136 *timings = ddata->timings;
0137 }
0138
0139 static int tvc_check_timings(struct omap_dss_device *dssdev,
0140 struct omap_video_timings *timings)
0141 {
0142 struct panel_drv_data *ddata = to_panel_data(dssdev);
0143 struct omap_dss_device *in = ddata->in;
0144
0145 return in->ops.atv->check_timings(in, timings);
0146 }
0147
0148 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
0149 {
0150 struct panel_drv_data *ddata = to_panel_data(dssdev);
0151 struct omap_dss_device *in = ddata->in;
0152
0153 return in->ops.atv->get_wss(in);
0154 }
0155
0156 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
0157 {
0158 struct panel_drv_data *ddata = to_panel_data(dssdev);
0159 struct omap_dss_device *in = ddata->in;
0160
0161 return in->ops.atv->set_wss(in, wss);
0162 }
0163
0164 static struct omap_dss_driver tvc_driver = {
0165 .connect = tvc_connect,
0166 .disconnect = tvc_disconnect,
0167
0168 .enable = tvc_enable,
0169 .disable = tvc_disable,
0170
0171 .set_timings = tvc_set_timings,
0172 .get_timings = tvc_get_timings,
0173 .check_timings = tvc_check_timings,
0174
0175 .get_resolution = omapdss_default_get_resolution,
0176
0177 .get_wss = tvc_get_wss,
0178 .set_wss = tvc_set_wss,
0179 };
0180
0181 static int tvc_probe_pdata(struct platform_device *pdev)
0182 {
0183 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
0184 struct connector_atv_platform_data *pdata;
0185 struct omap_dss_device *in, *dssdev;
0186
0187 pdata = dev_get_platdata(&pdev->dev);
0188
0189 in = omap_dss_find_output(pdata->source);
0190 if (in == NULL) {
0191 dev_err(&pdev->dev, "Failed to find video source\n");
0192 return -EPROBE_DEFER;
0193 }
0194
0195 ddata->in = in;
0196
0197 ddata->invert_polarity = pdata->invert_polarity;
0198
0199 dssdev = &ddata->dssdev;
0200 dssdev->name = pdata->name;
0201
0202 return 0;
0203 }
0204
0205 static int tvc_probe_of(struct platform_device *pdev)
0206 {
0207 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
0208 struct device_node *node = pdev->dev.of_node;
0209 struct omap_dss_device *in;
0210
0211 in = omapdss_of_find_source_for_first_ep(node);
0212 if (IS_ERR(in)) {
0213 dev_err(&pdev->dev, "failed to find video source\n");
0214 return PTR_ERR(in);
0215 }
0216
0217 ddata->in = in;
0218
0219 return 0;
0220 }
0221
0222 static int tvc_probe(struct platform_device *pdev)
0223 {
0224 struct panel_drv_data *ddata;
0225 struct omap_dss_device *dssdev;
0226 int r;
0227
0228 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
0229 if (!ddata)
0230 return -ENOMEM;
0231
0232 platform_set_drvdata(pdev, ddata);
0233 ddata->dev = &pdev->dev;
0234
0235 if (dev_get_platdata(&pdev->dev)) {
0236 r = tvc_probe_pdata(pdev);
0237 if (r)
0238 return r;
0239 } else if (pdev->dev.of_node) {
0240 r = tvc_probe_of(pdev);
0241 if (r)
0242 return r;
0243 } else {
0244 return -ENODEV;
0245 }
0246
0247 ddata->timings = tvc_pal_timings;
0248
0249 dssdev = &ddata->dssdev;
0250 dssdev->driver = &tvc_driver;
0251 dssdev->dev = &pdev->dev;
0252 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
0253 dssdev->owner = THIS_MODULE;
0254 dssdev->panel.timings = tvc_pal_timings;
0255
0256 r = omapdss_register_display(dssdev);
0257 if (r) {
0258 dev_err(&pdev->dev, "Failed to register panel\n");
0259 goto err_reg;
0260 }
0261
0262 return 0;
0263 err_reg:
0264 omap_dss_put_device(ddata->in);
0265 return r;
0266 }
0267
0268 static int __exit tvc_remove(struct platform_device *pdev)
0269 {
0270 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
0271 struct omap_dss_device *dssdev = &ddata->dssdev;
0272 struct omap_dss_device *in = ddata->in;
0273
0274 omapdss_unregister_display(&ddata->dssdev);
0275
0276 tvc_disable(dssdev);
0277 tvc_disconnect(dssdev);
0278
0279 omap_dss_put_device(in);
0280
0281 return 0;
0282 }
0283
0284 static const struct of_device_id tvc_of_match[] = {
0285 { .compatible = "omapdss,svideo-connector", },
0286 { .compatible = "omapdss,composite-video-connector", },
0287 {},
0288 };
0289
0290 MODULE_DEVICE_TABLE(of, tvc_of_match);
0291
0292 static struct platform_driver tvc_connector_driver = {
0293 .probe = tvc_probe,
0294 .remove = __exit_p(tvc_remove),
0295 .driver = {
0296 .name = "connector-analog-tv",
0297 .of_match_table = tvc_of_match,
0298 .suppress_bind_attrs = true,
0299 },
0300 };
0301
0302 module_platform_driver(tvc_connector_driver);
0303
0304 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
0305 MODULE_DESCRIPTION("Analog TV Connector driver");
0306 MODULE_LICENSE("GPL");