Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * OPA362 analog video amplifier with output/power control |
| 3 | * |
| 4 | * Copyright (C) 2014 Golden Delicious Computers |
| 5 | * Author: H. Nikolaus Schaller <hns@goldelico.com> |
| 6 | * |
| 7 | * based on encoder-tfp410 |
| 8 | * |
Andrew F. Davis | bb5cdf8 | 2017-12-05 14:29:31 -0600 | [diff] [blame] | 9 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 10 | * Author: Tomi Valkeinen <tomi.valkeinen@ti.com> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published by |
| 14 | * the Free Software Foundation. |
| 15 | */ |
| 16 | |
Tomi Valkeinen | d9e32ec | 2016-03-18 09:02:18 +0200 | [diff] [blame] | 17 | #include <linux/gpio/consumer.h> |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/slab.h> |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 21 | |
Peter Ujfalusi | 32043da | 2016-05-27 14:40:49 +0300 | [diff] [blame] | 22 | #include "../dss/omapdss.h" |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 23 | |
| 24 | struct panel_drv_data { |
| 25 | struct omap_dss_device dssdev; |
| 26 | struct omap_dss_device *in; |
| 27 | |
| 28 | struct gpio_desc *enable_gpio; |
| 29 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 30 | struct videomode vm; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) |
| 34 | |
| 35 | static int opa362_connect(struct omap_dss_device *dssdev, |
| 36 | struct omap_dss_device *dst) |
| 37 | { |
| 38 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 39 | struct omap_dss_device *in; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 40 | int r; |
| 41 | |
| 42 | dev_dbg(dssdev->dev, "connect\n"); |
| 43 | |
| 44 | if (omapdss_device_is_connected(dssdev)) |
| 45 | return -EBUSY; |
| 46 | |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 47 | in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node); |
| 48 | if (IS_ERR(in)) { |
| 49 | dev_err(dssdev->dev, "failed to find video source\n"); |
| 50 | return PTR_ERR(in); |
| 51 | } |
| 52 | |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 53 | r = in->ops.atv->connect(in, dssdev); |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 54 | if (r) { |
| 55 | omap_dss_put_device(in); |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 56 | return r; |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 57 | } |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 58 | |
| 59 | dst->src = dssdev; |
| 60 | dssdev->dst = dst; |
| 61 | |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 62 | ddata->in = in; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static void opa362_disconnect(struct omap_dss_device *dssdev, |
| 67 | struct omap_dss_device *dst) |
| 68 | { |
| 69 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 70 | struct omap_dss_device *in = ddata->in; |
| 71 | |
| 72 | dev_dbg(dssdev->dev, "disconnect\n"); |
| 73 | |
| 74 | WARN_ON(!omapdss_device_is_connected(dssdev)); |
| 75 | if (!omapdss_device_is_connected(dssdev)) |
| 76 | return; |
| 77 | |
| 78 | WARN_ON(dst != dssdev->dst); |
| 79 | if (dst != dssdev->dst) |
| 80 | return; |
| 81 | |
| 82 | dst->src = NULL; |
| 83 | dssdev->dst = NULL; |
| 84 | |
| 85 | in->ops.atv->disconnect(in, &ddata->dssdev); |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 86 | |
| 87 | omap_dss_put_device(in); |
| 88 | ddata->in = NULL; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static int opa362_enable(struct omap_dss_device *dssdev) |
| 92 | { |
| 93 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 94 | struct omap_dss_device *in = ddata->in; |
| 95 | int r; |
| 96 | |
| 97 | dev_dbg(dssdev->dev, "enable\n"); |
| 98 | |
| 99 | if (!omapdss_device_is_connected(dssdev)) |
| 100 | return -ENODEV; |
| 101 | |
| 102 | if (omapdss_device_is_enabled(dssdev)) |
| 103 | return 0; |
| 104 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 105 | in->ops.atv->set_timings(in, &ddata->vm); |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 106 | |
| 107 | r = in->ops.atv->enable(in); |
| 108 | if (r) |
| 109 | return r; |
| 110 | |
| 111 | if (ddata->enable_gpio) |
| 112 | gpiod_set_value_cansleep(ddata->enable_gpio, 1); |
| 113 | |
| 114 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static void opa362_disable(struct omap_dss_device *dssdev) |
| 120 | { |
| 121 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 122 | struct omap_dss_device *in = ddata->in; |
| 123 | |
| 124 | dev_dbg(dssdev->dev, "disable\n"); |
| 125 | |
| 126 | if (!omapdss_device_is_enabled(dssdev)) |
| 127 | return; |
| 128 | |
| 129 | if (ddata->enable_gpio) |
| 130 | gpiod_set_value_cansleep(ddata->enable_gpio, 0); |
| 131 | |
| 132 | in->ops.atv->disable(in); |
| 133 | |
| 134 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
| 135 | } |
| 136 | |
| 137 | static void opa362_set_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 138 | struct videomode *vm) |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 139 | { |
| 140 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 141 | struct omap_dss_device *in = ddata->in; |
| 142 | |
| 143 | dev_dbg(dssdev->dev, "set_timings\n"); |
| 144 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 145 | ddata->vm = *vm; |
| 146 | dssdev->panel.vm = *vm; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 147 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 148 | in->ops.atv->set_timings(in, vm); |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void opa362_get_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 152 | struct videomode *vm) |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 153 | { |
| 154 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 155 | |
| 156 | dev_dbg(dssdev->dev, "get_timings\n"); |
| 157 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 158 | *vm = ddata->vm; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static int opa362_check_timings(struct omap_dss_device *dssdev, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 162 | struct videomode *vm) |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 163 | { |
| 164 | struct panel_drv_data *ddata = to_panel_data(dssdev); |
| 165 | struct omap_dss_device *in = ddata->in; |
| 166 | |
| 167 | dev_dbg(dssdev->dev, "check_timings\n"); |
| 168 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 169 | return in->ops.atv->check_timings(in, vm); |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 172 | static const struct omapdss_atv_ops opa362_atv_ops = { |
| 173 | .connect = opa362_connect, |
| 174 | .disconnect = opa362_disconnect, |
| 175 | |
| 176 | .enable = opa362_enable, |
| 177 | .disable = opa362_disable, |
| 178 | |
| 179 | .check_timings = opa362_check_timings, |
| 180 | .set_timings = opa362_set_timings, |
| 181 | .get_timings = opa362_get_timings, |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | static int opa362_probe(struct platform_device *pdev) |
| 185 | { |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 186 | struct panel_drv_data *ddata; |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 187 | struct omap_dss_device *dssdev; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 188 | struct gpio_desc *gpio; |
| 189 | int r; |
| 190 | |
| 191 | dev_dbg(&pdev->dev, "probe\n"); |
| 192 | |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 193 | ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); |
| 194 | if (!ddata) |
| 195 | return -ENOMEM; |
| 196 | |
| 197 | platform_set_drvdata(pdev, ddata); |
| 198 | |
Uwe Kleine-König | ca8c67d | 2015-05-28 10:05:15 +0200 | [diff] [blame] | 199 | gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW); |
| 200 | if (IS_ERR(gpio)) |
| 201 | return PTR_ERR(gpio); |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 202 | |
| 203 | ddata->enable_gpio = gpio; |
| 204 | |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 205 | dssdev = &ddata->dssdev; |
| 206 | dssdev->ops.atv = &opa362_atv_ops; |
| 207 | dssdev->dev = &pdev->dev; |
| 208 | dssdev->type = OMAP_DISPLAY_TYPE_VENC; |
| 209 | dssdev->output_type = OMAP_DISPLAY_TYPE_VENC; |
| 210 | dssdev->owner = THIS_MODULE; |
| 211 | |
| 212 | r = omapdss_register_output(dssdev); |
| 213 | if (r) { |
| 214 | dev_err(&pdev->dev, "Failed to register output\n"); |
Laurent Pinchart | e28cea0 | 2018-02-11 15:07:41 +0200 | [diff] [blame] | 215 | return r; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | return 0; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int __exit opa362_remove(struct platform_device *pdev) |
| 222 | { |
| 223 | struct panel_drv_data *ddata = platform_get_drvdata(pdev); |
| 224 | struct omap_dss_device *dssdev = &ddata->dssdev; |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 225 | |
| 226 | omapdss_unregister_output(&ddata->dssdev); |
| 227 | |
| 228 | WARN_ON(omapdss_device_is_enabled(dssdev)); |
| 229 | if (omapdss_device_is_enabled(dssdev)) |
| 230 | opa362_disable(dssdev); |
| 231 | |
| 232 | WARN_ON(omapdss_device_is_connected(dssdev)); |
| 233 | if (omapdss_device_is_connected(dssdev)) |
| 234 | opa362_disconnect(dssdev, dssdev->dst); |
| 235 | |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static const struct of_device_id opa362_of_match[] = { |
| 240 | { .compatible = "omapdss,ti,opa362", }, |
| 241 | {}, |
| 242 | }; |
| 243 | MODULE_DEVICE_TABLE(of, opa362_of_match); |
| 244 | |
| 245 | static struct platform_driver opa362_driver = { |
| 246 | .probe = opa362_probe, |
| 247 | .remove = __exit_p(opa362_remove), |
| 248 | .driver = { |
| 249 | .name = "amplifier-opa362", |
Marek Belisko | 0e87873 | 2014-12-03 22:33:20 +0100 | [diff] [blame] | 250 | .of_match_table = opa362_of_match, |
| 251 | .suppress_bind_attrs = true, |
| 252 | }, |
| 253 | }; |
| 254 | |
| 255 | module_platform_driver(opa362_driver); |
| 256 | |
| 257 | MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>"); |
| 258 | MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control"); |
| 259 | MODULE_LICENSE("GPL v2"); |