Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * OPA362 analog video amplifier with output/power control
0004  *
0005  * Copyright (C) 2014 Golden Delicious Computers
0006  * Author: H. Nikolaus Schaller <hns@goldelico.com>
0007  *
0008  * based on encoder-tfp410
0009  *
0010  * Copyright (C) 2013 Texas Instruments
0011  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
0012  */
0013 
0014 #include <linux/gpio.h>
0015 #include <linux/module.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/slab.h>
0018 #include <linux/of_gpio.h>
0019 
0020 #include <video/omapfb_dss.h>
0021 
0022 struct panel_drv_data {
0023     struct omap_dss_device dssdev;
0024     struct omap_dss_device *in;
0025 
0026     struct gpio_desc *enable_gpio;
0027 
0028     struct omap_video_timings timings;
0029 };
0030 
0031 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
0032 
0033 static int opa362_connect(struct omap_dss_device *dssdev,
0034         struct omap_dss_device *dst)
0035 {
0036     struct panel_drv_data *ddata = to_panel_data(dssdev);
0037     struct omap_dss_device *in = ddata->in;
0038     int r;
0039 
0040     dev_dbg(dssdev->dev, "connect\n");
0041 
0042     if (omapdss_device_is_connected(dssdev))
0043         return -EBUSY;
0044 
0045     r = in->ops.atv->connect(in, dssdev);
0046     if (r)
0047         return r;
0048 
0049     dst->src = dssdev;
0050     dssdev->dst = dst;
0051 
0052     return 0;
0053 }
0054 
0055 static void opa362_disconnect(struct omap_dss_device *dssdev,
0056         struct omap_dss_device *dst)
0057 {
0058     struct panel_drv_data *ddata = to_panel_data(dssdev);
0059     struct omap_dss_device *in = ddata->in;
0060 
0061     dev_dbg(dssdev->dev, "disconnect\n");
0062 
0063     WARN_ON(!omapdss_device_is_connected(dssdev));
0064     if (!omapdss_device_is_connected(dssdev))
0065         return;
0066 
0067     WARN_ON(dst != dssdev->dst);
0068     if (dst != dssdev->dst)
0069         return;
0070 
0071     dst->src = NULL;
0072     dssdev->dst = NULL;
0073 
0074     in->ops.atv->disconnect(in, &ddata->dssdev);
0075 }
0076 
0077 static int opa362_enable(struct omap_dss_device *dssdev)
0078 {
0079     struct panel_drv_data *ddata = to_panel_data(dssdev);
0080     struct omap_dss_device *in = ddata->in;
0081     int r;
0082 
0083     dev_dbg(dssdev->dev, "enable\n");
0084 
0085     if (!omapdss_device_is_connected(dssdev))
0086         return -ENODEV;
0087 
0088     if (omapdss_device_is_enabled(dssdev))
0089         return 0;
0090 
0091     in->ops.atv->set_timings(in, &ddata->timings);
0092 
0093     r = in->ops.atv->enable(in);
0094     if (r)
0095         return r;
0096 
0097     if (ddata->enable_gpio)
0098         gpiod_set_value_cansleep(ddata->enable_gpio, 1);
0099 
0100     dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
0101 
0102     return 0;
0103 }
0104 
0105 static void opa362_disable(struct omap_dss_device *dssdev)
0106 {
0107     struct panel_drv_data *ddata = to_panel_data(dssdev);
0108     struct omap_dss_device *in = ddata->in;
0109 
0110     dev_dbg(dssdev->dev, "disable\n");
0111 
0112     if (!omapdss_device_is_enabled(dssdev))
0113         return;
0114 
0115     if (ddata->enable_gpio)
0116         gpiod_set_value_cansleep(ddata->enable_gpio, 0);
0117 
0118     in->ops.atv->disable(in);
0119 
0120     dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
0121 }
0122 
0123 static void opa362_set_timings(struct omap_dss_device *dssdev,
0124         struct omap_video_timings *timings)
0125 {
0126     struct panel_drv_data *ddata = to_panel_data(dssdev);
0127     struct omap_dss_device *in = ddata->in;
0128 
0129     dev_dbg(dssdev->dev, "set_timings\n");
0130 
0131     ddata->timings = *timings;
0132     dssdev->panel.timings = *timings;
0133 
0134     in->ops.atv->set_timings(in, timings);
0135 }
0136 
0137 static void opa362_get_timings(struct omap_dss_device *dssdev,
0138         struct omap_video_timings *timings)
0139 {
0140     struct panel_drv_data *ddata = to_panel_data(dssdev);
0141 
0142     dev_dbg(dssdev->dev, "get_timings\n");
0143 
0144     *timings = ddata->timings;
0145 }
0146 
0147 static int opa362_check_timings(struct omap_dss_device *dssdev,
0148         struct omap_video_timings *timings)
0149 {
0150     struct panel_drv_data *ddata = to_panel_data(dssdev);
0151     struct omap_dss_device *in = ddata->in;
0152 
0153     dev_dbg(dssdev->dev, "check_timings\n");
0154 
0155     return in->ops.atv->check_timings(in, timings);
0156 }
0157 
0158 static void opa362_set_type(struct omap_dss_device *dssdev,
0159         enum omap_dss_venc_type type)
0160 {
0161     /* we can only drive a COMPOSITE output */
0162     WARN_ON(type != OMAP_DSS_VENC_TYPE_COMPOSITE);
0163 
0164 }
0165 
0166 static const struct omapdss_atv_ops opa362_atv_ops = {
0167     .connect    = opa362_connect,
0168     .disconnect = opa362_disconnect,
0169 
0170     .enable     = opa362_enable,
0171     .disable    = opa362_disable,
0172 
0173     .check_timings  = opa362_check_timings,
0174     .set_timings    = opa362_set_timings,
0175     .get_timings    = opa362_get_timings,
0176 
0177     .set_type   = opa362_set_type,
0178 };
0179 
0180 static int opa362_probe(struct platform_device *pdev)
0181 {
0182     struct device_node *node = pdev->dev.of_node;
0183     struct panel_drv_data *ddata;
0184     struct omap_dss_device *dssdev, *in;
0185     struct gpio_desc *gpio;
0186     int r;
0187 
0188     dev_dbg(&pdev->dev, "probe\n");
0189 
0190     if (node == NULL) {
0191         dev_err(&pdev->dev, "Unable to find device tree\n");
0192         return -EINVAL;
0193     }
0194 
0195     ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
0196     if (!ddata)
0197         return -ENOMEM;
0198 
0199     platform_set_drvdata(pdev, ddata);
0200 
0201     gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
0202     if (IS_ERR(gpio))
0203         return PTR_ERR(gpio);
0204 
0205     ddata->enable_gpio = gpio;
0206 
0207     in = omapdss_of_find_source_for_first_ep(node);
0208     if (IS_ERR(in)) {
0209         dev_err(&pdev->dev, "failed to find video source\n");
0210         return PTR_ERR(in);
0211     }
0212 
0213     ddata->in = in;
0214 
0215     dssdev = &ddata->dssdev;
0216     dssdev->ops.atv = &opa362_atv_ops;
0217     dssdev->dev = &pdev->dev;
0218     dssdev->type = OMAP_DISPLAY_TYPE_VENC;
0219     dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
0220     dssdev->owner = THIS_MODULE;
0221 
0222     r = omapdss_register_output(dssdev);
0223     if (r) {
0224         dev_err(&pdev->dev, "Failed to register output\n");
0225         goto err_reg;
0226     }
0227 
0228     return 0;
0229 err_reg:
0230     omap_dss_put_device(ddata->in);
0231     return r;
0232 }
0233 
0234 static int __exit opa362_remove(struct platform_device *pdev)
0235 {
0236     struct panel_drv_data *ddata = platform_get_drvdata(pdev);
0237     struct omap_dss_device *dssdev = &ddata->dssdev;
0238     struct omap_dss_device *in = ddata->in;
0239 
0240     omapdss_unregister_output(&ddata->dssdev);
0241 
0242     WARN_ON(omapdss_device_is_enabled(dssdev));
0243     if (omapdss_device_is_enabled(dssdev))
0244         opa362_disable(dssdev);
0245 
0246     WARN_ON(omapdss_device_is_connected(dssdev));
0247     if (omapdss_device_is_connected(dssdev))
0248         opa362_disconnect(dssdev, dssdev->dst);
0249 
0250     omap_dss_put_device(in);
0251 
0252     return 0;
0253 }
0254 
0255 static const struct of_device_id opa362_of_match[] = {
0256     { .compatible = "omapdss,ti,opa362", },
0257     {},
0258 };
0259 MODULE_DEVICE_TABLE(of, opa362_of_match);
0260 
0261 static struct platform_driver opa362_driver = {
0262     .probe  = opa362_probe,
0263     .remove = __exit_p(opa362_remove),
0264     .driver = {
0265         .name   = "amplifier-opa362",
0266         .of_match_table = opa362_of_match,
0267         .suppress_bind_attrs = true,
0268     },
0269 };
0270 
0271 module_platform_driver(opa362_driver);
0272 
0273 MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
0274 MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
0275 MODULE_LICENSE("GPL v2");