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 | |
| 55 | omap_encoder_set_enabled(encoder, false); |
| 56 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 57 | drm_encoder_cleanup(encoder); |
| 58 | kfree(omap_encoder); |
| 59 | } |
| 60 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 61 | static const struct drm_encoder_funcs omap_encoder_funcs = { |
| 62 | .destroy = omap_encoder_destroy, |
| 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * The CRTC drm_crtc_helper_set_mode() doesn't really give us the right |
| 67 | * order.. the easiest way to work around this for now is to make all |
| 68 | * the encoder-helper's no-op's and have the omap_crtc code take care |
| 69 | * of the sequencing and call us in the right points. |
| 70 | * |
| 71 | * Eventually to handle connecting CRTCs to different encoders properly, |
| 72 | * either the CRTC helpers need to change or we need to replace |
| 73 | * drm_crtc_helper_set_mode(), but lets wait until atomic-modeset for |
| 74 | * that. |
| 75 | */ |
| 76 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 77 | static void omap_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 78 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static bool omap_encoder_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 82 | const struct drm_display_mode *mode, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 83 | struct drm_display_mode *adjusted_mode) |
| 84 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 85 | return true; |
| 86 | } |
| 87 | |
| 88 | static void omap_encoder_mode_set(struct drm_encoder *encoder, |
| 89 | struct drm_display_mode *mode, |
| 90 | struct drm_display_mode *adjusted_mode) |
| 91 | { |
Tomi Valkeinen | 4f930c0 | 2014-06-18 14:19:48 +0300 | [diff] [blame] | 92 | struct drm_device *dev = encoder->dev; |
| 93 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
| 94 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 95 | struct drm_connector *connector; |
| 96 | bool hdmi_mode; |
| 97 | int r; |
| 98 | |
| 99 | hdmi_mode = false; |
| 100 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 101 | if (connector->encoder == encoder) { |
| 102 | hdmi_mode = omap_connector_get_hdmi_mode(connector); |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (dssdev->driver->set_hdmi_mode) |
| 108 | dssdev->driver->set_hdmi_mode(dssdev, hdmi_mode); |
| 109 | |
| 110 | if (hdmi_mode && dssdev->driver->set_hdmi_infoframe) { |
| 111 | struct hdmi_avi_infoframe avi; |
| 112 | |
| 113 | r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode); |
| 114 | if (r == 0) |
| 115 | dssdev->driver->set_hdmi_infoframe(dssdev, &avi); |
| 116 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static void omap_encoder_prepare(struct drm_encoder *encoder) |
| 120 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void omap_encoder_commit(struct drm_encoder *encoder) |
| 124 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 125 | } |
| 126 | |
Laurent Pinchart | 68dc039 | 2015-03-07 00:22:39 +0200 | [diff] [blame^] | 127 | static void omap_encoder_disable(struct drm_encoder *encoder) |
| 128 | { |
| 129 | } |
| 130 | |
| 131 | static void omap_encoder_enable(struct drm_encoder *encoder) |
| 132 | { |
| 133 | } |
| 134 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 135 | static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = { |
| 136 | .dpms = omap_encoder_dpms, |
| 137 | .mode_fixup = omap_encoder_mode_fixup, |
| 138 | .mode_set = omap_encoder_mode_set, |
| 139 | .prepare = omap_encoder_prepare, |
| 140 | .commit = omap_encoder_commit, |
Laurent Pinchart | 68dc039 | 2015-03-07 00:22:39 +0200 | [diff] [blame^] | 141 | .disable = omap_encoder_disable, |
| 142 | .enable = omap_encoder_enable, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 143 | }; |
| 144 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 145 | /* |
| 146 | * Instead of relying on the helpers for modeset, the omap_crtc code |
| 147 | * calls these functions in the proper sequence. |
| 148 | */ |
| 149 | |
| 150 | int omap_encoder_set_enabled(struct drm_encoder *encoder, bool enabled) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 151 | { |
| 152 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 153 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 154 | struct omap_dss_driver *dssdrv = dssdev->driver; |
| 155 | |
| 156 | if (enabled) { |
| 157 | return dssdrv->enable(dssdev); |
| 158 | } else { |
| 159 | dssdrv->disable(dssdev); |
| 160 | return 0; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | int omap_encoder_update(struct drm_encoder *encoder, |
| 165 | struct omap_overlay_manager *mgr, |
| 166 | struct omap_video_timings *timings) |
| 167 | { |
| 168 | struct drm_device *dev = encoder->dev; |
| 169 | struct omap_encoder *omap_encoder = to_omap_encoder(encoder); |
| 170 | struct omap_dss_device *dssdev = omap_encoder->dssdev; |
| 171 | struct omap_dss_driver *dssdrv = dssdev->driver; |
| 172 | int ret; |
| 173 | |
Tomi Valkeinen | a73fdc6 | 2013-07-24 13:01:34 +0300 | [diff] [blame] | 174 | dssdev->src->manager = mgr; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 175 | |
Archit Taneja | bddabbe | 2013-03-26 19:15:20 +0530 | [diff] [blame] | 176 | if (dssdrv->check_timings) { |
| 177 | ret = dssdrv->check_timings(dssdev, timings); |
| 178 | } else { |
| 179 | struct omap_video_timings t = {0}; |
| 180 | |
| 181 | dssdrv->get_timings(dssdev, &t); |
| 182 | |
| 183 | if (memcmp(timings, &t, sizeof(struct omap_video_timings))) |
| 184 | ret = -EINVAL; |
| 185 | else |
| 186 | ret = 0; |
| 187 | } |
| 188 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 189 | if (ret) { |
| 190 | dev_err(dev->dev, "could not set timings: %d\n", ret); |
| 191 | return ret; |
| 192 | } |
| 193 | |
Archit Taneja | bddabbe | 2013-03-26 19:15:20 +0530 | [diff] [blame] | 194 | if (dssdrv->set_timings) |
| 195 | dssdrv->set_timings(dssdev, timings); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 196 | |
| 197 | return 0; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* initialize encoder */ |
| 201 | struct drm_encoder *omap_encoder_init(struct drm_device *dev, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 202 | struct omap_dss_device *dssdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 203 | { |
| 204 | struct drm_encoder *encoder = NULL; |
| 205 | struct omap_encoder *omap_encoder; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 206 | |
| 207 | omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 208 | if (!omap_encoder) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 209 | goto fail; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 210 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 211 | omap_encoder->dssdev = dssdev; |
| 212 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 213 | encoder = &omap_encoder->base; |
| 214 | |
| 215 | drm_encoder_init(dev, encoder, &omap_encoder_funcs, |
| 216 | DRM_MODE_ENCODER_TMDS); |
| 217 | drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs); |
| 218 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 219 | return encoder; |
| 220 | |
| 221 | fail: |
YAMANE Toshiaki | 582bc28 | 2012-11-14 19:31:27 +0900 | [diff] [blame] | 222 | if (encoder) |
Rob Clark | 65b0bd0 | 2011-12-09 23:26:07 -0600 | [diff] [blame] | 223 | omap_encoder_destroy(encoder); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 224 | |
| 225 | return NULL; |
| 226 | } |