diff options
| author | Eric Anholt <eric@anholt.net> | 2017-05-11 14:31:28 -0400 |
|---|---|---|
| committer | Archit Taneja <architt@codeaurora.org> | 2017-06-05 06:03:50 -0400 |
| commit | 96160a8071b2d76b5dfe6c2478684207cc758553 (patch) | |
| tree | 02ef4f0b54666fc3fccbcc17ffb478f093622089 /drivers/gpu/drm/atmel-hlcdc | |
| parent | 510fc3c0d761b8f274e2a62f9b4c69bdc6841182 (diff) | |
drm/atmel-hlcdc: Replace the panel usage with drm_panel_bridge.
This cuts 135 lines of boilerplate, at the cost of losing the
filtering of get_modes() using atmel_hlcdc_dc_mode_valid(). The
atomic check will still check that we don't set an invalid mode,
though.
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Archit Taneja <architt@codeaurora.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20170511183128.25085-7-eric@anholt.net
Diffstat (limited to 'drivers/gpu/drm/atmel-hlcdc')
| -rw-r--r-- | drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c | 163 |
1 files changed, 14 insertions, 149 deletions
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c index 4b2cfbd0d43f..340ef962aa81 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c | |||
| @@ -23,191 +23,56 @@ | |||
| 23 | 23 | ||
| 24 | #include <drm/drmP.h> | 24 | #include <drm/drmP.h> |
| 25 | #include <drm/drm_of.h> | 25 | #include <drm/drm_of.h> |
| 26 | #include <drm/drm_bridge.h> | ||
| 26 | 27 | ||
| 27 | #include "atmel_hlcdc_dc.h" | 28 | #include "atmel_hlcdc_dc.h" |
| 28 | 29 | ||
| 29 | /** | ||
| 30 | * Atmel HLCDC RGB connector structure | ||
| 31 | * | ||
| 32 | * This structure stores RGB slave device information. | ||
| 33 | * | ||
| 34 | * @connector: DRM connector | ||
| 35 | * @encoder: DRM encoder | ||
| 36 | * @dc: pointer to the atmel_hlcdc_dc structure | ||
| 37 | * @panel: panel connected on the RGB output | ||
| 38 | */ | ||
| 39 | struct atmel_hlcdc_rgb_output { | ||
| 40 | struct drm_connector connector; | ||
| 41 | struct drm_encoder encoder; | ||
| 42 | struct atmel_hlcdc_dc *dc; | ||
| 43 | struct drm_panel *panel; | ||
| 44 | }; | ||
| 45 | |||
| 46 | static inline struct atmel_hlcdc_rgb_output * | ||
| 47 | drm_connector_to_atmel_hlcdc_rgb_output(struct drm_connector *connector) | ||
| 48 | { | ||
| 49 | return container_of(connector, struct atmel_hlcdc_rgb_output, | ||
| 50 | connector); | ||
| 51 | } | ||
| 52 | |||
| 53 | static inline struct atmel_hlcdc_rgb_output * | ||
| 54 | drm_encoder_to_atmel_hlcdc_rgb_output(struct drm_encoder *encoder) | ||
| 55 | { | ||
| 56 | return container_of(encoder, struct atmel_hlcdc_rgb_output, encoder); | ||
| 57 | } | ||
| 58 | |||
| 59 | static void atmel_hlcdc_rgb_encoder_enable(struct drm_encoder *encoder) | ||
| 60 | { | ||
| 61 | struct atmel_hlcdc_rgb_output *rgb = | ||
| 62 | drm_encoder_to_atmel_hlcdc_rgb_output(encoder); | ||
| 63 | |||
| 64 | if (rgb->panel) { | ||
| 65 | drm_panel_prepare(rgb->panel); | ||
| 66 | drm_panel_enable(rgb->panel); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | static void atmel_hlcdc_rgb_encoder_disable(struct drm_encoder *encoder) | ||
| 71 | { | ||
| 72 | struct atmel_hlcdc_rgb_output *rgb = | ||
| 73 | drm_encoder_to_atmel_hlcdc_rgb_output(encoder); | ||
| 74 | |||
| 75 | if (rgb->panel) { | ||
| 76 | drm_panel_disable(rgb->panel); | ||
| 77 | drm_panel_unprepare(rgb->panel); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | static const struct drm_encoder_helper_funcs atmel_hlcdc_panel_encoder_helper_funcs = { | ||
| 82 | .disable = atmel_hlcdc_rgb_encoder_disable, | ||
| 83 | .enable = atmel_hlcdc_rgb_encoder_enable, | ||
| 84 | }; | ||
| 85 | |||
| 86 | static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = { | 30 | static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = { |
| 87 | .destroy = drm_encoder_cleanup, | 31 | .destroy = drm_encoder_cleanup, |
| 88 | }; | 32 | }; |
| 89 | 33 | ||
| 90 | static int atmel_hlcdc_panel_get_modes(struct drm_connector *connector) | ||
| 91 | { | ||
| 92 | struct atmel_hlcdc_rgb_output *rgb = | ||
| 93 | drm_connector_to_atmel_hlcdc_rgb_output(connector); | ||
| 94 | |||
| 95 | if (rgb->panel) | ||
| 96 | return rgb->panel->funcs->get_modes(rgb->panel); | ||
| 97 | |||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | |||
| 101 | static int atmel_hlcdc_rgb_mode_valid(struct drm_connector *connector, | ||
| 102 | struct drm_display_mode *mode) | ||
| 103 | { | ||
| 104 | struct atmel_hlcdc_rgb_output *rgb = | ||
| 105 | drm_connector_to_atmel_hlcdc_rgb_output(connector); | ||
| 106 | |||
| 107 | return atmel_hlcdc_dc_mode_valid(rgb->dc, mode); | ||
| 108 | } | ||
| 109 | |||
| 110 | static const struct drm_connector_helper_funcs atmel_hlcdc_panel_connector_helper_funcs = { | ||
| 111 | .get_modes = atmel_hlcdc_panel_get_modes, | ||
| 112 | .mode_valid = atmel_hlcdc_rgb_mode_valid, | ||
| 113 | }; | ||
| 114 | |||
| 115 | static enum drm_connector_status | ||
| 116 | atmel_hlcdc_panel_connector_detect(struct drm_connector *connector, bool force) | ||
| 117 | { | ||
| 118 | struct atmel_hlcdc_rgb_output *rgb = | ||
| 119 | drm_connector_to_atmel_hlcdc_rgb_output(connector); | ||
| 120 | |||
| 121 | if (rgb->panel) | ||
| 122 | return connector_status_connected; | ||
| 123 | |||
| 124 | return connector_status_disconnected; | ||
| 125 | } | ||
| 126 | |||
| 127 | static void | ||
| 128 | atmel_hlcdc_panel_connector_destroy(struct drm_connector *connector) | ||
| 129 | { | ||
| 130 | struct atmel_hlcdc_rgb_output *rgb = | ||
| 131 | drm_connector_to_atmel_hlcdc_rgb_output(connector); | ||
| 132 | |||
| 133 | if (rgb->panel) | ||
| 134 | drm_panel_detach(rgb->panel); | ||
| 135 | |||
| 136 | drm_connector_cleanup(connector); | ||
| 137 | } | ||
| 138 | |||
| 139 | static const struct drm_connector_funcs atmel_hlcdc_panel_connector_funcs = { | ||
| 140 | .dpms = drm_atomic_helper_connector_dpms, | ||
| 141 | .detect = atmel_hlcdc_panel_connector_detect, | ||
| 142 | .fill_modes = drm_helper_probe_single_connector_modes, | ||
| 143 | .destroy = atmel_hlcdc_panel_connector_destroy, | ||
| 144 | .reset = drm_atomic_helper_connector_reset, | ||
| 145 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, | ||
| 146 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, | ||
| 147 | }; | ||
| 148 | |||
| 149 | static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, | 34 | static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, |
| 150 | const struct device_node *np) | 35 | const struct device_node *np) |
| 151 | { | 36 | { |
| 152 | struct atmel_hlcdc_dc *dc = dev->dev_private; | 37 | struct drm_encoder *encoder; |
| 153 | struct atmel_hlcdc_rgb_output *output; | ||
| 154 | struct drm_panel *panel; | 38 | struct drm_panel *panel; |
| 155 | struct drm_bridge *bridge; | 39 | struct drm_bridge *bridge; |
| 156 | int ret; | 40 | int ret; |
| 157 | 41 | ||
| 158 | output = devm_kzalloc(dev->dev, sizeof(*output), GFP_KERNEL); | 42 | encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); |
| 159 | if (!output) | 43 | if (!encoder) |
| 160 | return -EINVAL; | 44 | return -EINVAL; |
| 161 | 45 | ||
| 162 | output->dc = dc; | 46 | ret = drm_encoder_init(dev, encoder, |
| 163 | |||
| 164 | drm_encoder_helper_add(&output->encoder, | ||
| 165 | &atmel_hlcdc_panel_encoder_helper_funcs); | ||
| 166 | ret = drm_encoder_init(dev, &output->encoder, | ||
| 167 | &atmel_hlcdc_panel_encoder_funcs, | 47 | &atmel_hlcdc_panel_encoder_funcs, |
| 168 | DRM_MODE_ENCODER_NONE, NULL); | 48 | DRM_MODE_ENCODER_NONE, NULL); |
| 169 | if (ret) | 49 | if (ret) |
| 170 | return ret; | 50 | return ret; |
| 171 | 51 | ||
| 172 | output->encoder.possible_crtcs = 0x1; | 52 | encoder->possible_crtcs = 0x1; |
| 173 | 53 | ||
| 174 | ret = drm_of_find_panel_or_bridge(np, 0, 0, &panel, &bridge); | 54 | ret = drm_of_find_panel_or_bridge(np, 0, 0, &panel, &bridge); |
| 175 | if (ret) | 55 | if (ret) |
| 176 | return ret; | 56 | return ret; |
| 177 | 57 | ||
| 178 | if (panel) { | 58 | if (panel) { |
| 179 | output->connector.dpms = DRM_MODE_DPMS_OFF; | 59 | bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_Unknown); |
| 180 | output->connector.polled = DRM_CONNECTOR_POLL_CONNECT; | 60 | if (IS_ERR(bridge)) |
| 181 | drm_connector_helper_add(&output->connector, | 61 | return PTR_ERR(bridge); |
| 182 | &atmel_hlcdc_panel_connector_helper_funcs); | ||
| 183 | ret = drm_connector_init(dev, &output->connector, | ||
| 184 | &atmel_hlcdc_panel_connector_funcs, | ||
| 185 | DRM_MODE_CONNECTOR_Unknown); | ||
| 186 | if (ret) | ||
| 187 | goto err_encoder_cleanup; | ||
| 188 | |||
| 189 | drm_mode_connector_attach_encoder(&output->connector, | ||
| 190 | &output->encoder); | ||
| 191 | |||
| 192 | ret = drm_panel_attach(panel, &output->connector); | ||
| 193 | if (ret) { | ||
| 194 | drm_connector_cleanup(&output->connector); | ||
| 195 | goto err_encoder_cleanup; | ||
| 196 | } | ||
| 197 | |||
| 198 | output->panel = panel; | ||
| 199 | 62 | ||
| 200 | return 0; | 63 | return 0; |
| 201 | } | 64 | } |
| 202 | 65 | ||
| 203 | if (bridge) { | 66 | if (bridge) { |
| 204 | ret = drm_bridge_attach(&output->encoder, bridge, NULL); | 67 | ret = drm_bridge_attach(encoder, bridge, NULL); |
| 205 | if (!ret) | 68 | if (!ret) |
| 206 | return 0; | 69 | return 0; |
| 70 | |||
| 71 | if (panel) | ||
| 72 | drm_panel_bridge_remove(bridge); | ||
| 207 | } | 73 | } |
| 208 | 74 | ||
| 209 | err_encoder_cleanup: | 75 | drm_encoder_cleanup(encoder); |
| 210 | drm_encoder_cleanup(&output->encoder); | ||
| 211 | 76 | ||
| 212 | return ret; | 77 | return ret; |
| 213 | } | 78 | } |
