| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* Hisilicon Hibmc SoC drm driver |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Based on the bochs drm driver. |
|---|
| .. | .. |
|---|
| 8 | 9 | * Rongrong Zou <zourongrong@huawei.com> |
|---|
| 9 | 10 | * Rongrong Zou <zourongrong@gmail.com> |
|---|
| 10 | 11 | * Jianhua Li <lijianhua@huawei.com> |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 13 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 14 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 15 | | - * (at your option) any later version. |
|---|
| 16 | | - * |
|---|
| 17 | 12 | */ |
|---|
| 18 | 13 | |
|---|
| 19 | 14 | #include <drm/drm_atomic_helper.h> |
|---|
| 20 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 15 | +#include <drm/drm_probe_helper.h> |
|---|
| 16 | +#include <drm/drm_print.h> |
|---|
| 21 | 17 | |
|---|
| 22 | 18 | #include "hibmc_drm_drv.h" |
|---|
| 23 | 19 | #include "hibmc_drm_regs.h" |
|---|
| 24 | 20 | |
|---|
| 25 | 21 | static int hibmc_connector_get_modes(struct drm_connector *connector) |
|---|
| 26 | 22 | { |
|---|
| 27 | | - return drm_add_modes_noedid(connector, 800, 600); |
|---|
| 23 | + int count; |
|---|
| 24 | + |
|---|
| 25 | + count = drm_add_modes_noedid(connector, |
|---|
| 26 | + connector->dev->mode_config.max_width, |
|---|
| 27 | + connector->dev->mode_config.max_height); |
|---|
| 28 | + drm_set_preferred_mode(connector, 1024, 768); |
|---|
| 29 | + |
|---|
| 30 | + return count; |
|---|
| 28 | 31 | } |
|---|
| 29 | 32 | |
|---|
| 30 | 33 | static enum drm_mode_status hibmc_connector_mode_valid(struct drm_connector *connector, |
|---|
| .. | .. |
|---|
| 33 | 36 | return MODE_OK; |
|---|
| 34 | 37 | } |
|---|
| 35 | 38 | |
|---|
| 36 | | -static struct drm_encoder * |
|---|
| 37 | | -hibmc_connector_best_encoder(struct drm_connector *connector) |
|---|
| 38 | | -{ |
|---|
| 39 | | - return drm_encoder_find(connector->dev, NULL, connector->encoder_ids[0]); |
|---|
| 40 | | -} |
|---|
| 41 | | - |
|---|
| 42 | 39 | static const struct drm_connector_helper_funcs |
|---|
| 43 | 40 | hibmc_connector_helper_funcs = { |
|---|
| 44 | 41 | .get_modes = hibmc_connector_get_modes, |
|---|
| 45 | 42 | .mode_valid = hibmc_connector_mode_valid, |
|---|
| 46 | | - .best_encoder = hibmc_connector_best_encoder, |
|---|
| 47 | 43 | }; |
|---|
| 48 | 44 | |
|---|
| 49 | 45 | static const struct drm_connector_funcs hibmc_connector_funcs = { |
|---|
| .. | .. |
|---|
| 53 | 49 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
|---|
| 54 | 50 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
|---|
| 55 | 51 | }; |
|---|
| 56 | | - |
|---|
| 57 | | -static struct drm_connector * |
|---|
| 58 | | -hibmc_connector_init(struct hibmc_drm_private *priv) |
|---|
| 59 | | -{ |
|---|
| 60 | | - struct drm_device *dev = priv->dev; |
|---|
| 61 | | - struct drm_connector *connector; |
|---|
| 62 | | - int ret; |
|---|
| 63 | | - |
|---|
| 64 | | - connector = devm_kzalloc(dev->dev, sizeof(*connector), GFP_KERNEL); |
|---|
| 65 | | - if (!connector) { |
|---|
| 66 | | - DRM_ERROR("failed to alloc memory when init connector\n"); |
|---|
| 67 | | - return ERR_PTR(-ENOMEM); |
|---|
| 68 | | - } |
|---|
| 69 | | - |
|---|
| 70 | | - ret = drm_connector_init(dev, connector, |
|---|
| 71 | | - &hibmc_connector_funcs, |
|---|
| 72 | | - DRM_MODE_CONNECTOR_VGA); |
|---|
| 73 | | - if (ret) { |
|---|
| 74 | | - DRM_ERROR("failed to init connector: %d\n", ret); |
|---|
| 75 | | - return ERR_PTR(ret); |
|---|
| 76 | | - } |
|---|
| 77 | | - drm_connector_helper_add(connector, |
|---|
| 78 | | - &hibmc_connector_helper_funcs); |
|---|
| 79 | | - |
|---|
| 80 | | - return connector; |
|---|
| 81 | | -} |
|---|
| 82 | 52 | |
|---|
| 83 | 53 | static void hibmc_encoder_mode_set(struct drm_encoder *encoder, |
|---|
| 84 | 54 | struct drm_display_mode *mode, |
|---|
| .. | .. |
|---|
| 107 | 77 | int hibmc_vdac_init(struct hibmc_drm_private *priv) |
|---|
| 108 | 78 | { |
|---|
| 109 | 79 | struct drm_device *dev = priv->dev; |
|---|
| 110 | | - struct drm_encoder *encoder; |
|---|
| 111 | | - struct drm_connector *connector; |
|---|
| 80 | + struct drm_encoder *encoder = &priv->encoder; |
|---|
| 81 | + struct drm_connector *connector = &priv->connector; |
|---|
| 112 | 82 | int ret; |
|---|
| 113 | | - |
|---|
| 114 | | - connector = hibmc_connector_init(priv); |
|---|
| 115 | | - if (IS_ERR(connector)) { |
|---|
| 116 | | - DRM_ERROR("failed to create connector: %ld\n", |
|---|
| 117 | | - PTR_ERR(connector)); |
|---|
| 118 | | - return PTR_ERR(connector); |
|---|
| 119 | | - } |
|---|
| 120 | | - |
|---|
| 121 | | - encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); |
|---|
| 122 | | - if (!encoder) { |
|---|
| 123 | | - DRM_ERROR("failed to alloc memory when init encoder\n"); |
|---|
| 124 | | - return -ENOMEM; |
|---|
| 125 | | - } |
|---|
| 126 | 83 | |
|---|
| 127 | 84 | encoder->possible_crtcs = 0x1; |
|---|
| 128 | 85 | ret = drm_encoder_init(dev, encoder, &hibmc_encoder_funcs, |
|---|
| 129 | 86 | DRM_MODE_ENCODER_DAC, NULL); |
|---|
| 130 | 87 | if (ret) { |
|---|
| 131 | | - DRM_ERROR("failed to init encoder: %d\n", ret); |
|---|
| 88 | + drm_err(dev, "failed to init encoder: %d\n", ret); |
|---|
| 132 | 89 | return ret; |
|---|
| 133 | 90 | } |
|---|
| 134 | 91 | |
|---|
| 135 | 92 | drm_encoder_helper_add(encoder, &hibmc_encoder_helper_funcs); |
|---|
| 93 | + |
|---|
| 94 | + ret = drm_connector_init(dev, connector, &hibmc_connector_funcs, |
|---|
| 95 | + DRM_MODE_CONNECTOR_VGA); |
|---|
| 96 | + if (ret) { |
|---|
| 97 | + drm_err(dev, "failed to init connector: %d\n", ret); |
|---|
| 98 | + return ret; |
|---|
| 99 | + } |
|---|
| 100 | + drm_connector_helper_add(connector, &hibmc_connector_helper_funcs); |
|---|
| 101 | + |
|---|
| 136 | 102 | drm_connector_attach_encoder(connector, encoder); |
|---|
| 137 | 103 | |
|---|
| 138 | 104 | return 0; |
|---|