Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 1 | /* |
Rob Clark | 8bb0daf | 2013-02-11 12:43:09 -0500 | [diff] [blame] | 2 | * drivers/gpu/drm/omapdrm/omap_encoder.c |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2011 Texas Instruments |
| 5 | * Author: Rob Clark <rob@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 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 20 | #include <linux/list.h> |
| 21 | |
| 22 | #include <drm/drm_crtc.h> |
| 23 | #include <drm/drm_crtc_helper.h> |
Tomi Valkeinen | 4f930c0 | 2014-06-18 14:19:48 +0300 | [diff] [blame] | 24 | #include <drm/drm_edid.h> |
| 25 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 26 | #include "omap_drv.h" |
| 27 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 28 | /* |
| 29 | * encoder funcs |
| 30 | */ |
| 31 | |
| 32 | #define to_omap_encoder(x) container_of(x, struct omap_encoder, base) |
| 33 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 34 | /* The encoder and connector both map to same dssdev.. the encoder |
| 35 | * handles the 'active' parts, ie. anything the modifies the state |
| 36 | * of the hw, and the connector handles the 'read-only' parts, like |
| 37 | * detecting connection and reading edid. |
| 38 | */ |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 39 | struct omap_encoder { |
| 40 | struct drm_encoder base; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 41 | struct omap_dss_device *dssdev; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 42 | }; |
| 43 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 44 | struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder) |
| 45 | { |
| 46 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
| 47 | |
| 48 | return omap_encoder->dssdev; |
| 49 | } |
| 50 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 51 | static void omap_encoder_destroy(struct drm_encoder *encoder) |
| 52 | { |
| 53 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
Archit Taneja | ec72a81 | 2014-01-02 14:49:53 +0530 | [diff] [blame] | 54 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 55 | drm_encoder_cleanup(encoder); |
| 56 | kfree(omap_encoder); |
| 57 | } |
| 58 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 59 | static const struct drm_encoder_funcs omap_encoder_funcs = { |
| 60 | .destroy = omap_encoder_destroy, |
| 61 | }; |
| 62 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 63 | static void omap_encoder_mode_set(struct drm_encoder *encoder, |
| 64 | struct drm_display_mode *mode, |
| 65 | struct drm_display_mode *adjusted_mode) |
| 66 | { |
Tomi Valkeinen | 4f930c0 | 2014-06-18 14:19:48 +0300 | [diff] [blame] | 67 | struct drm_device *dev = encoder->dev; |
| 68 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
| 69 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 70 | struct drm_connector *connector; |
| 71 | bool hdmi_mode; |
| 72 | int r; |
| 73 | |
| 74 | hdmi_mode = false; |
| 75 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 76 | if (connector->encoder == encoder) { |
| 77 | hdmi_mode = omap_connector_get_hdmi_mode(connector); |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (dssdev->driver->set_hdmi_mode) |
| 83 | dssdev->driver->set_hdmi_mode(dssdev, hdmi_mode); |
| 84 | |
| 85 | if (hdmi_mode && dssdev->driver->set_hdmi_infoframe) { |
| 86 | struct hdmi_avi_infoframe avi; |
| 87 | |
| 88 | r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode); |
| 89 | if (r == 0) |
| 90 | dssdev->driver->set_hdmi_infoframe(dssdev, &avi); |
| 91 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Laurent Pinchart | 68dc039 | 2015-03-07 00:22:39 +0200 | [diff] [blame] | 94 | static void omap_encoder_disable(struct drm_encoder *encoder) |
| 95 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 96 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 97 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 98 | struct omap_dss_driver *dssdrv = dssdev->driver; |
| 99 | |
Laurent Pinchart | 4029755 | 2015-05-28 02:34:05 +0300 | [diff] [blame] | 100 | dssdrv->disable(dssdev); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 101 | } |
| 102 | |
Laurent Pinchart | 4029755 | 2015-05-28 02:34:05 +0300 | [diff] [blame] | 103 | static int omap_encoder_update(struct drm_encoder *encoder, |
| 104 | enum omap_channel channel, |
| 105 | struct omap_video_timings *timings) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 106 | { |
| 107 | struct drm_device *dev = encoder->dev; |
| 108 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
| 109 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 110 | struct omap_dss_driver *dssdrv = dssdev->driver; |
| 111 | int ret; |
| 112 | |
Laurent Pinchart | 4029755 | 2015-05-28 02:34:05 +0300 | [diff] [blame] | 113 | dssdev->src->manager = omap_dss_get_overlay_manager(channel); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 114 | |
Archit Taneja | bddabbe | 2013-03-26 19:15:20 +0530 | [diff] [blame] | 115 | if (dssdrv->check_timings) { |
| 116 | ret = dssdrv->check_timings(dssdev, timings); |
| 117 | } else { |
| 118 | struct omap_video_timings t = {0}; |
| 119 | |
| 120 | dssdrv->get_timings(dssdev, &t); |
| 121 | |
| 122 | if (memcmp(timings, &t, sizeof(struct omap_video_timings))) |
| 123 | ret = -EINVAL; |
| 124 | else |
| 125 | ret = 0; |
| 126 | } |
| 127 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 128 | if (ret) { |
| 129 | dev_err(dev->dev, "could not set timings: %d\n", ret); |
| 130 | return ret; |
| 131 | } |
| 132 | |
Archit Taneja | bddabbe | 2013-03-26 19:15:20 +0530 | [diff] [blame] | 133 | if (dssdrv->set_timings) |
| 134 | dssdrv->set_timings(dssdev, timings); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 135 | |
| 136 | return 0; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 137 | } |
| 138 | |
Laurent Pinchart | 4029755 | 2015-05-28 02:34:05 +0300 | [diff] [blame] | 139 | static void omap_encoder_enable(struct drm_encoder *encoder) |
| 140 | { |
| 141 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
| 142 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 143 | struct omap_dss_driver *dssdrv = dssdev->driver; |
| 144 | |
| 145 | omap_encoder_update(encoder, omap_crtc_channel(encoder->crtc), |
| 146 | omap_crtc_timings(encoder->crtc)); |
| 147 | |
| 148 | dssdrv->enable(dssdev); |
| 149 | } |
| 150 | |
| 151 | static int omap_encoder_atomic_check(struct drm_encoder *encoder, |
| 152 | struct drm_crtc_state *crtc_state, |
| 153 | struct drm_connector_state *conn_state) |
| 154 | { |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = { |
| 159 | .mode_set = omap_encoder_mode_set, |
| 160 | .disable = omap_encoder_disable, |
| 161 | .enable = omap_encoder_enable, |
| 162 | .atomic_check = omap_encoder_atomic_check, |
| 163 | }; |
| 164 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 165 | /* initialize encoder */ |
| 166 | struct drm_encoder *omap_encoder_init(struct drm_device *dev, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 167 | struct omap_dss_device *dssdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 168 | { |
| 169 | struct drm_encoder *encoder = NULL; |
| 170 | struct omap_encoder *omap_encoder; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 171 | |
| 172 | omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 173 | if (!omap_encoder) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 174 | goto fail; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 175 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 176 | omap_encoder->dssdev = dssdev; |
| 177 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 178 | encoder = &omap_encoder->base; |
| 179 | |
| 180 | drm_encoder_init(dev, encoder, &omap_encoder_funcs, |
| 181 | DRM_MODE_ENCODER_TMDS); |
| 182 | drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs); |
| 183 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 184 | return encoder; |
| 185 | |
| 186 | fail: |
YAMANE Toshiaki | 582bc28 | 2012-11-14 19:31:27 +0900 | [diff] [blame] | 187 | if (encoder) |
Rob Clark | 65b0bd0 | 2011-12-09 23:26:07 -0600 | [diff] [blame] | 188 | omap_encoder_destroy(encoder); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 189 | |
| 190 | return NULL; |
| 191 | } |