|
| 1 | +From 40ec16b79e0da5333b4e48037e1fe2ec60628128 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ruud Derwig < [email protected]> |
| 3 | +Date: Mon, 6 Jun 2016 10:47:46 +0300 |
| 4 | +Subject: [PATCH 15/17] drm/arcpgu: Make ARC PGU usable on simulation platforms |
| 5 | + |
| 6 | +In case of simulation there's no real encoder/transmitter device |
| 7 | +because in the model's virtual LCD we're rendering whatever |
| 8 | +appears in frame-buffer memory. |
| 9 | + |
| 10 | +Signed-off-by: Ruud Derwig < [email protected]> |
| 11 | +Signed-off-by: Alexey Brodkin < [email protected]> |
| 12 | +--- |
| 13 | + drivers/gpu/drm/arc/Makefile | 2 +- |
| 14 | + drivers/gpu/drm/arc/arcpgu.h | 1 + |
| 15 | + drivers/gpu/drm/arc/arcpgu_drv.c | 15 ++-- |
| 16 | + drivers/gpu/drm/arc/arcpgu_sim.c | 177 +++++++++++++++++++++++++++++++++++++++ |
| 17 | + 4 files changed, 187 insertions(+), 8 deletions(-) |
| 18 | + create mode 100644 drivers/gpu/drm/arc/arcpgu_sim.c |
| 19 | + |
| 20 | +diff --git a/drivers/gpu/drm/arc/Makefile b/drivers/gpu/drm/arc/Makefile |
| 21 | +index d48fda7..73de56a 100644 |
| 22 | +--- a/drivers/gpu/drm/arc/Makefile |
| 23 | ++++ b/drivers/gpu/drm/arc/Makefile |
| 24 | +@@ -1,2 +1,2 @@ |
| 25 | +-arcpgu-y := arcpgu_crtc.o arcpgu_hdmi.o arcpgu_drv.o |
| 26 | ++arcpgu-y := arcpgu_crtc.o arcpgu_hdmi.o arcpgu_sim.o arcpgu_drv.o |
| 27 | + obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o |
| 28 | +diff --git a/drivers/gpu/drm/arc/arcpgu.h b/drivers/gpu/drm/arc/arcpgu.h |
| 29 | +index 86574b6..329ac75 100644 |
| 30 | +--- a/drivers/gpu/drm/arc/arcpgu.h |
| 31 | ++++ b/drivers/gpu/drm/arc/arcpgu.h |
| 32 | +@@ -43,6 +43,7 @@ static inline u32 arc_pgu_read(struct arcpgu_drm_private *arcpgu, |
| 33 | + |
| 34 | + int arc_pgu_setup_crtc(struct drm_device *dev); |
| 35 | + int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np); |
| 36 | ++int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np); |
| 37 | + struct drm_fbdev_cma *arcpgu_fbdev_cma_init(struct drm_device *dev, |
| 38 | + unsigned int preferred_bpp, unsigned int num_crtc, |
| 39 | + unsigned int max_conn_count); |
| 40 | +diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c |
| 41 | +index 5c64eb1..56899b7 100644 |
| 42 | +--- a/drivers/gpu/drm/arc/arcpgu_drv.c |
| 43 | ++++ b/drivers/gpu/drm/arc/arcpgu_drv.c |
| 44 | +@@ -149,15 +149,16 @@ static int arcpgu_load(struct drm_device *drm) |
| 45 | + |
| 46 | + /* find the encoder node and initialize it */ |
| 47 | + encoder_node = of_parse_phandle(drm->dev->of_node, "encoder-slave", 0); |
| 48 | +- if (!encoder_node) { |
| 49 | +- dev_err(drm->dev, "failed to get an encoder slave node\n"); |
| 50 | +- return -ENODEV; |
| 51 | ++ if (encoder_node) { |
| 52 | ++ ret = arcpgu_drm_hdmi_init(drm, encoder_node); |
| 53 | ++ if (ret < 0) |
| 54 | ++ return ret; |
| 55 | ++ } else { |
| 56 | ++ ret = arcpgu_drm_sim_init(drm, 0); |
| 57 | ++ if (ret < 0) |
| 58 | ++ return ret; |
| 59 | + } |
| 60 | + |
| 61 | +- ret = arcpgu_drm_hdmi_init(drm, encoder_node); |
| 62 | +- if (ret < 0) |
| 63 | +- return ret; |
| 64 | +- |
| 65 | + drm_mode_config_reset(drm); |
| 66 | + drm_kms_helper_poll_init(drm); |
| 67 | + |
| 68 | +diff --git a/drivers/gpu/drm/arc/arcpgu_sim.c b/drivers/gpu/drm/arc/arcpgu_sim.c |
| 69 | +new file mode 100644 |
| 70 | +index 0000000..9f5bd3f |
| 71 | +--- /dev/null |
| 72 | ++++ b/drivers/gpu/drm/arc/arcpgu_sim.c |
| 73 | +@@ -0,0 +1,177 @@ |
| 74 | ++/* |
| 75 | ++ * ARC PGU DRM driver. |
| 76 | ++ * |
| 77 | ++ * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com) |
| 78 | ++ * |
| 79 | ++ * This program is free software; you can redistribute it and/or modify |
| 80 | ++ * it under the terms of the GNU General Public License version 2 as |
| 81 | ++ * published by the Free Software Foundation. |
| 82 | ++ * |
| 83 | ++ * This program is distributed in the hope that it will be useful, |
| 84 | ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 85 | ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 86 | ++ * GNU General Public License for more details. |
| 87 | ++ * |
| 88 | ++ */ |
| 89 | ++ |
| 90 | ++#include <drm/drm_crtc_helper.h> |
| 91 | ++#include <drm/drm_encoder_slave.h> |
| 92 | ++#include <drm/drm_atomic_helper.h> |
| 93 | ++ |
| 94 | ++#include "arcpgu.h" |
| 95 | ++ |
| 96 | ++#define XRES_DEF 640 |
| 97 | ++#define YRES_DEF 480 |
| 98 | ++ |
| 99 | ++#define XRES_MAX 8192 |
| 100 | ++#define YRES_MAX 8192 |
| 101 | ++ |
| 102 | ++ |
| 103 | ++struct arcpgu_drm_connector { |
| 104 | ++ struct drm_connector connector; |
| 105 | ++ struct drm_encoder_slave *encoder_slave; |
| 106 | ++}; |
| 107 | ++ |
| 108 | ++static int arcpgu_drm_connector_get_modes(struct drm_connector *connector) |
| 109 | ++{ |
| 110 | ++ int count; |
| 111 | ++ |
| 112 | ++ count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); |
| 113 | ++ drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF); |
| 114 | ++ return count; |
| 115 | ++} |
| 116 | ++ |
| 117 | ++static struct drm_encoder * |
| 118 | ++arcpgu_drm_connector_best_encoder(struct drm_connector *connector) |
| 119 | ++{ |
| 120 | ++ struct drm_encoder_slave *slave; |
| 121 | ++ struct arcpgu_drm_connector *con = |
| 122 | ++ container_of(connector, struct arcpgu_drm_connector, connector); |
| 123 | ++ |
| 124 | ++ slave = con->encoder_slave; |
| 125 | ++ if (slave == NULL) { |
| 126 | ++ dev_err(connector->dev->dev, |
| 127 | ++ "connector_best_encoder: cannot find slave encoder for connector\n"); |
| 128 | ++ return NULL; |
| 129 | ++ } |
| 130 | ++ |
| 131 | ++ return &slave->base; |
| 132 | ++} |
| 133 | ++ |
| 134 | ++static enum drm_connector_status |
| 135 | ++arcpgu_drm_connector_detect(struct drm_connector *connector, bool force) |
| 136 | ++{ |
| 137 | ++ return connector_status_connected; |
| 138 | ++} |
| 139 | ++ |
| 140 | ++static void arcpgu_drm_connector_destroy(struct drm_connector *connector) |
| 141 | ++{ |
| 142 | ++ drm_connector_unregister(connector); |
| 143 | ++ drm_connector_cleanup(connector); |
| 144 | ++} |
| 145 | ++ |
| 146 | ++static const struct drm_connector_helper_funcs |
| 147 | ++arcpgu_drm_connector_helper_funcs = { |
| 148 | ++ .get_modes = arcpgu_drm_connector_get_modes, |
| 149 | ++ .best_encoder = arcpgu_drm_connector_best_encoder, |
| 150 | ++}; |
| 151 | ++ |
| 152 | ++static const struct drm_connector_funcs arcpgu_drm_connector_funcs = { |
| 153 | ++ .dpms = drm_helper_connector_dpms, |
| 154 | ++ .reset = drm_atomic_helper_connector_reset, |
| 155 | ++ .detect = arcpgu_drm_connector_detect, |
| 156 | ++ .fill_modes = drm_helper_probe_single_connector_modes, |
| 157 | ++ .destroy = arcpgu_drm_connector_destroy, |
| 158 | ++ .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 159 | ++ .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
| 160 | ++}; |
| 161 | ++ |
| 162 | ++static bool sim_enc_mode_fixup(struct drm_encoder *encoder, |
| 163 | ++ const struct drm_display_mode *mode, |
| 164 | ++ struct drm_display_mode *adjusted_mode) |
| 165 | ++{ |
| 166 | ++ return true; |
| 167 | ++} |
| 168 | ++ |
| 169 | ++static void sim_enc_mode_set(struct drm_encoder *encoder, |
| 170 | ++ struct drm_display_mode *mode, |
| 171 | ++ struct drm_display_mode *adjusted_mode) |
| 172 | ++{ |
| 173 | ++} |
| 174 | ++ |
| 175 | ++static void sim_enc_enable(struct drm_encoder *encoder) |
| 176 | ++{ |
| 177 | ++} |
| 178 | ++ |
| 179 | ++static void sim_enc_disable(struct drm_encoder *encoder) |
| 180 | ++{ |
| 181 | ++} |
| 182 | ++ |
| 183 | ++static struct drm_encoder_helper_funcs arcpgu_drm_encoder_helper_funcs = { |
| 184 | ++ .mode_fixup = sim_enc_mode_fixup, |
| 185 | ++ .mode_set = sim_enc_mode_set, |
| 186 | ++ .enable = sim_enc_enable, |
| 187 | ++ .disable = sim_enc_disable, |
| 188 | ++}; |
| 189 | ++ |
| 190 | ++static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = { |
| 191 | ++ .destroy = drm_encoder_cleanup, |
| 192 | ++}; |
| 193 | ++ |
| 194 | ++int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np) |
| 195 | ++{ |
| 196 | ++ struct arcpgu_drm_connector *arcpgu_connector; |
| 197 | ++ struct drm_encoder_slave *encoder; |
| 198 | ++ struct drm_connector *connector; |
| 199 | ++ int ret; |
| 200 | ++ |
| 201 | ++ encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL); |
| 202 | ++ if (encoder == NULL) |
| 203 | ++ return -ENOMEM; |
| 204 | ++ |
| 205 | ++ encoder->base.possible_crtcs = 1; |
| 206 | ++ encoder->base.possible_clones = 0; |
| 207 | ++ |
| 208 | ++ ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs, |
| 209 | ++ DRM_MODE_ENCODER_VIRTUAL); |
| 210 | ++ if (ret) |
| 211 | ++ return ret; |
| 212 | ++ |
| 213 | ++ drm_encoder_helper_add(&encoder->base, |
| 214 | ++ &arcpgu_drm_encoder_helper_funcs); |
| 215 | ++ |
| 216 | ++ arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector), |
| 217 | ++ GFP_KERNEL); |
| 218 | ++ if (!arcpgu_connector) { |
| 219 | ++ ret = -ENOMEM; |
| 220 | ++ goto error_encoder_cleanup; |
| 221 | ++ } |
| 222 | ++ |
| 223 | ++ connector = &arcpgu_connector->connector; |
| 224 | ++ drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs); |
| 225 | ++ |
| 226 | ++ ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs, |
| 227 | ++ DRM_MODE_CONNECTOR_VIRTUAL); |
| 228 | ++ if (ret < 0) { |
| 229 | ++ dev_err(drm->dev, "failed to initialize drm connector\n"); |
| 230 | ++ goto error_encoder_cleanup; |
| 231 | ++ } |
| 232 | ++ |
| 233 | ++ ret = drm_mode_connector_attach_encoder(connector, &encoder->base); |
| 234 | ++ if (ret < 0) { |
| 235 | ++ dev_err(drm->dev, "could not attach connector to encoder\n"); |
| 236 | ++ drm_connector_unregister(connector); |
| 237 | ++ goto error_connector_cleanup; |
| 238 | ++ } |
| 239 | ++ |
| 240 | ++ arcpgu_connector->encoder_slave = encoder; |
| 241 | ++ |
| 242 | ++ return 0; |
| 243 | ++ |
| 244 | ++error_connector_cleanup: |
| 245 | ++ drm_connector_cleanup(connector); |
| 246 | ++ |
| 247 | ++error_encoder_cleanup: |
| 248 | ++ drm_encoder_cleanup(&encoder->base); |
| 249 | ++ return ret; |
| 250 | ++} |
| 251 | +-- |
| 252 | +2.5.5 |
| 253 | + |
0 commit comments