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