| .. | .. |
|---|
| 6 | 6 | |
|---|
| 7 | 7 | #include <linux/clk.h> |
|---|
| 8 | 8 | |
|---|
| 9 | | -#include <drm/drmP.h> |
|---|
| 10 | 9 | #include <drm/drm_atomic_helper.h> |
|---|
| 11 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 10 | +#include <drm/drm_bridge.h> |
|---|
| 12 | 11 | #include <drm/drm_of.h> |
|---|
| 13 | 12 | #include <drm/drm_panel.h> |
|---|
| 13 | +#include <drm/drm_print.h> |
|---|
| 14 | +#include <drm/drm_probe_helper.h> |
|---|
| 15 | +#include <drm/drm_simple_kms_helper.h> |
|---|
| 14 | 16 | |
|---|
| 15 | 17 | #include "sun4i_crtc.h" |
|---|
| 16 | 18 | #include "sun4i_tcon.h" |
|---|
| .. | .. |
|---|
| 20 | 22 | struct drm_connector connector; |
|---|
| 21 | 23 | struct drm_encoder encoder; |
|---|
| 22 | 24 | |
|---|
| 23 | | - struct sun4i_tcon *tcon; |
|---|
| 25 | + struct drm_panel *panel; |
|---|
| 24 | 26 | }; |
|---|
| 25 | 27 | |
|---|
| 26 | 28 | static inline struct sun4i_lvds * |
|---|
| .. | .. |
|---|
| 41 | 43 | { |
|---|
| 42 | 44 | struct sun4i_lvds *lvds = |
|---|
| 43 | 45 | drm_connector_to_sun4i_lvds(connector); |
|---|
| 44 | | - struct sun4i_tcon *tcon = lvds->tcon; |
|---|
| 45 | 46 | |
|---|
| 46 | | - return drm_panel_get_modes(tcon->panel); |
|---|
| 47 | + return drm_panel_get_modes(lvds->panel, connector); |
|---|
| 47 | 48 | } |
|---|
| 48 | 49 | |
|---|
| 49 | | -static struct drm_connector_helper_funcs sun4i_lvds_con_helper_funcs = { |
|---|
| 50 | +static const struct drm_connector_helper_funcs sun4i_lvds_con_helper_funcs = { |
|---|
| 50 | 51 | .get_modes = sun4i_lvds_get_modes, |
|---|
| 51 | 52 | }; |
|---|
| 52 | 53 | |
|---|
| 53 | 54 | static void |
|---|
| 54 | 55 | sun4i_lvds_connector_destroy(struct drm_connector *connector) |
|---|
| 55 | 56 | { |
|---|
| 56 | | - struct sun4i_lvds *lvds = drm_connector_to_sun4i_lvds(connector); |
|---|
| 57 | | - struct sun4i_tcon *tcon = lvds->tcon; |
|---|
| 58 | | - |
|---|
| 59 | | - drm_panel_detach(tcon->panel); |
|---|
| 60 | 57 | drm_connector_cleanup(connector); |
|---|
| 61 | 58 | } |
|---|
| 62 | 59 | |
|---|
| .. | .. |
|---|
| 71 | 68 | static void sun4i_lvds_encoder_enable(struct drm_encoder *encoder) |
|---|
| 72 | 69 | { |
|---|
| 73 | 70 | struct sun4i_lvds *lvds = drm_encoder_to_sun4i_lvds(encoder); |
|---|
| 74 | | - struct sun4i_tcon *tcon = lvds->tcon; |
|---|
| 75 | 71 | |
|---|
| 76 | 72 | DRM_DEBUG_DRIVER("Enabling LVDS output\n"); |
|---|
| 77 | 73 | |
|---|
| 78 | | - if (!IS_ERR(tcon->panel)) { |
|---|
| 79 | | - drm_panel_prepare(tcon->panel); |
|---|
| 80 | | - drm_panel_enable(tcon->panel); |
|---|
| 74 | + if (lvds->panel) { |
|---|
| 75 | + drm_panel_prepare(lvds->panel); |
|---|
| 76 | + drm_panel_enable(lvds->panel); |
|---|
| 81 | 77 | } |
|---|
| 82 | 78 | } |
|---|
| 83 | 79 | |
|---|
| 84 | 80 | static void sun4i_lvds_encoder_disable(struct drm_encoder *encoder) |
|---|
| 85 | 81 | { |
|---|
| 86 | 82 | struct sun4i_lvds *lvds = drm_encoder_to_sun4i_lvds(encoder); |
|---|
| 87 | | - struct sun4i_tcon *tcon = lvds->tcon; |
|---|
| 88 | 83 | |
|---|
| 89 | 84 | DRM_DEBUG_DRIVER("Disabling LVDS output\n"); |
|---|
| 90 | 85 | |
|---|
| 91 | | - if (!IS_ERR(tcon->panel)) { |
|---|
| 92 | | - drm_panel_disable(tcon->panel); |
|---|
| 93 | | - drm_panel_unprepare(tcon->panel); |
|---|
| 86 | + if (lvds->panel) { |
|---|
| 87 | + drm_panel_disable(lvds->panel); |
|---|
| 88 | + drm_panel_unprepare(lvds->panel); |
|---|
| 94 | 89 | } |
|---|
| 95 | 90 | } |
|---|
| 96 | 91 | |
|---|
| 97 | 92 | static const struct drm_encoder_helper_funcs sun4i_lvds_enc_helper_funcs = { |
|---|
| 98 | 93 | .disable = sun4i_lvds_encoder_disable, |
|---|
| 99 | 94 | .enable = sun4i_lvds_encoder_enable, |
|---|
| 100 | | -}; |
|---|
| 101 | | - |
|---|
| 102 | | -static const struct drm_encoder_funcs sun4i_lvds_enc_funcs = { |
|---|
| 103 | | - .destroy = drm_encoder_cleanup, |
|---|
| 104 | 95 | }; |
|---|
| 105 | 96 | |
|---|
| 106 | 97 | int sun4i_lvds_init(struct drm_device *drm, struct sun4i_tcon *tcon) |
|---|
| .. | .. |
|---|
| 113 | 104 | lvds = devm_kzalloc(drm->dev, sizeof(*lvds), GFP_KERNEL); |
|---|
| 114 | 105 | if (!lvds) |
|---|
| 115 | 106 | return -ENOMEM; |
|---|
| 116 | | - lvds->tcon = tcon; |
|---|
| 117 | 107 | encoder = &lvds->encoder; |
|---|
| 118 | 108 | |
|---|
| 119 | 109 | ret = drm_of_find_panel_or_bridge(tcon->dev->of_node, 1, 0, |
|---|
| 120 | | - &tcon->panel, &bridge); |
|---|
| 110 | + &lvds->panel, &bridge); |
|---|
| 121 | 111 | if (ret) { |
|---|
| 122 | 112 | dev_info(drm->dev, "No panel or bridge found... LVDS output disabled\n"); |
|---|
| 123 | 113 | return 0; |
|---|
| .. | .. |
|---|
| 125 | 115 | |
|---|
| 126 | 116 | drm_encoder_helper_add(&lvds->encoder, |
|---|
| 127 | 117 | &sun4i_lvds_enc_helper_funcs); |
|---|
| 128 | | - ret = drm_encoder_init(drm, |
|---|
| 129 | | - &lvds->encoder, |
|---|
| 130 | | - &sun4i_lvds_enc_funcs, |
|---|
| 131 | | - DRM_MODE_ENCODER_LVDS, |
|---|
| 132 | | - NULL); |
|---|
| 118 | + ret = drm_simple_encoder_init(drm, &lvds->encoder, |
|---|
| 119 | + DRM_MODE_ENCODER_LVDS); |
|---|
| 133 | 120 | if (ret) { |
|---|
| 134 | 121 | dev_err(drm->dev, "Couldn't initialise the lvds encoder\n"); |
|---|
| 135 | 122 | goto err_out; |
|---|
| .. | .. |
|---|
| 138 | 125 | /* The LVDS encoder can only work with the TCON channel 0 */ |
|---|
| 139 | 126 | lvds->encoder.possible_crtcs = drm_crtc_mask(&tcon->crtc->crtc); |
|---|
| 140 | 127 | |
|---|
| 141 | | - if (tcon->panel) { |
|---|
| 128 | + if (lvds->panel) { |
|---|
| 142 | 129 | drm_connector_helper_add(&lvds->connector, |
|---|
| 143 | 130 | &sun4i_lvds_con_helper_funcs); |
|---|
| 144 | 131 | ret = drm_connector_init(drm, &lvds->connector, |
|---|
| .. | .. |
|---|
| 151 | 138 | |
|---|
| 152 | 139 | drm_connector_attach_encoder(&lvds->connector, |
|---|
| 153 | 140 | &lvds->encoder); |
|---|
| 154 | | - |
|---|
| 155 | | - ret = drm_panel_attach(tcon->panel, &lvds->connector); |
|---|
| 156 | | - if (ret) { |
|---|
| 157 | | - dev_err(drm->dev, "Couldn't attach our panel\n"); |
|---|
| 158 | | - goto err_cleanup_connector; |
|---|
| 159 | | - } |
|---|
| 160 | 141 | } |
|---|
| 161 | 142 | |
|---|
| 162 | 143 | if (bridge) { |
|---|
| 163 | | - ret = drm_bridge_attach(encoder, bridge, NULL); |
|---|
| 144 | + ret = drm_bridge_attach(encoder, bridge, NULL, 0); |
|---|
| 164 | 145 | if (ret) { |
|---|
| 165 | 146 | dev_err(drm->dev, "Couldn't attach our bridge\n"); |
|---|
| 166 | 147 | goto err_cleanup_connector; |
|---|