| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2012 Red Hat |
|---|
| 3 | 4 | * based in parts on udlfb.c: |
|---|
| 4 | 5 | * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it> |
|---|
| 5 | 6 | * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com> |
|---|
| 6 | 7 | * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This file is subject to the terms and conditions of the GNU General Public |
|---|
| 9 | | - * License v2. See the file COPYING in the main directory of this archive for |
|---|
| 10 | | - * more details. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | | -#include <drm/drmP.h> |
|---|
| 14 | | -#include <drm/drm_crtc.h> |
|---|
| 15 | | -#include <drm/drm_edid.h> |
|---|
| 10 | +#include <drm/drm_atomic_state_helper.h> |
|---|
| 16 | 11 | #include <drm/drm_crtc_helper.h> |
|---|
| 12 | +#include <drm/drm_probe_helper.h> |
|---|
| 13 | + |
|---|
| 17 | 14 | #include "udl_connector.h" |
|---|
| 18 | 15 | #include "udl_drv.h" |
|---|
| 19 | 16 | |
|---|
| 20 | | -static bool udl_get_edid_block(struct udl_device *udl, int block_idx, |
|---|
| 21 | | - u8 *buff) |
|---|
| 17 | +static int udl_get_edid_block(void *data, u8 *buf, unsigned int block, |
|---|
| 18 | + size_t len) |
|---|
| 22 | 19 | { |
|---|
| 23 | 20 | int ret, i; |
|---|
| 24 | 21 | u8 *read_buff; |
|---|
| 22 | + struct udl_device *udl = data; |
|---|
| 25 | 23 | |
|---|
| 26 | 24 | read_buff = kmalloc(2, GFP_KERNEL); |
|---|
| 27 | 25 | if (!read_buff) |
|---|
| 28 | | - return false; |
|---|
| 26 | + return -1; |
|---|
| 29 | 27 | |
|---|
| 30 | | - for (i = 0; i < EDID_LENGTH; i++) { |
|---|
| 31 | | - int bval = (i + block_idx * EDID_LENGTH) << 8; |
|---|
| 28 | + for (i = 0; i < len; i++) { |
|---|
| 29 | + int bval = (i + block * EDID_LENGTH) << 8; |
|---|
| 32 | 30 | ret = usb_control_msg(udl->udev, |
|---|
| 33 | 31 | usb_rcvctrlpipe(udl->udev, 0), |
|---|
| 34 | 32 | (0x02), (0x80 | (0x02 << 5)), bval, |
|---|
| .. | .. |
|---|
| 36 | 34 | if (ret < 1) { |
|---|
| 37 | 35 | DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret); |
|---|
| 38 | 36 | kfree(read_buff); |
|---|
| 39 | | - return false; |
|---|
| 37 | + return -1; |
|---|
| 40 | 38 | } |
|---|
| 41 | | - buff[i] = read_buff[1]; |
|---|
| 39 | + buf[i] = read_buff[1]; |
|---|
| 42 | 40 | } |
|---|
| 43 | 41 | |
|---|
| 44 | 42 | kfree(read_buff); |
|---|
| 45 | | - return true; |
|---|
| 46 | | -} |
|---|
| 47 | | - |
|---|
| 48 | | -static bool udl_get_edid(struct udl_device *udl, u8 **result_buff, |
|---|
| 49 | | - int *result_buff_size) |
|---|
| 50 | | -{ |
|---|
| 51 | | - int i, extensions; |
|---|
| 52 | | - u8 *block_buff = NULL, *buff_ptr; |
|---|
| 53 | | - |
|---|
| 54 | | - block_buff = kmalloc(EDID_LENGTH, GFP_KERNEL); |
|---|
| 55 | | - if (block_buff == NULL) |
|---|
| 56 | | - return false; |
|---|
| 57 | | - |
|---|
| 58 | | - if (udl_get_edid_block(udl, 0, block_buff) && |
|---|
| 59 | | - memchr_inv(block_buff, 0, EDID_LENGTH)) { |
|---|
| 60 | | - extensions = ((struct edid *)block_buff)->extensions; |
|---|
| 61 | | - if (extensions > 0) { |
|---|
| 62 | | - /* we have to read all extensions one by one */ |
|---|
| 63 | | - *result_buff_size = EDID_LENGTH * (extensions + 1); |
|---|
| 64 | | - *result_buff = kmalloc(*result_buff_size, GFP_KERNEL); |
|---|
| 65 | | - buff_ptr = *result_buff; |
|---|
| 66 | | - if (buff_ptr == NULL) { |
|---|
| 67 | | - kfree(block_buff); |
|---|
| 68 | | - return false; |
|---|
| 69 | | - } |
|---|
| 70 | | - memcpy(buff_ptr, block_buff, EDID_LENGTH); |
|---|
| 71 | | - kfree(block_buff); |
|---|
| 72 | | - buff_ptr += EDID_LENGTH; |
|---|
| 73 | | - for (i = 1; i < extensions; ++i) { |
|---|
| 74 | | - if (udl_get_edid_block(udl, i, buff_ptr)) { |
|---|
| 75 | | - buff_ptr += EDID_LENGTH; |
|---|
| 76 | | - } else { |
|---|
| 77 | | - kfree(*result_buff); |
|---|
| 78 | | - *result_buff = NULL; |
|---|
| 79 | | - return false; |
|---|
| 80 | | - } |
|---|
| 81 | | - } |
|---|
| 82 | | - return true; |
|---|
| 83 | | - } |
|---|
| 84 | | - /* we have only base edid block */ |
|---|
| 85 | | - *result_buff = block_buff; |
|---|
| 86 | | - *result_buff_size = EDID_LENGTH; |
|---|
| 87 | | - return true; |
|---|
| 88 | | - } |
|---|
| 89 | | - |
|---|
| 90 | | - kfree(block_buff); |
|---|
| 91 | | - |
|---|
| 92 | | - return false; |
|---|
| 43 | + return 0; |
|---|
| 93 | 44 | } |
|---|
| 94 | 45 | |
|---|
| 95 | 46 | static int udl_get_modes(struct drm_connector *connector) |
|---|
| .. | .. |
|---|
| 108 | 59 | static enum drm_mode_status udl_mode_valid(struct drm_connector *connector, |
|---|
| 109 | 60 | struct drm_display_mode *mode) |
|---|
| 110 | 61 | { |
|---|
| 111 | | - struct udl_device *udl = connector->dev->dev_private; |
|---|
| 62 | + struct udl_device *udl = to_udl(connector->dev); |
|---|
| 112 | 63 | if (!udl->sku_pixel_limit) |
|---|
| 113 | 64 | return 0; |
|---|
| 114 | 65 | |
|---|
| .. | .. |
|---|
| 121 | 72 | static enum drm_connector_status |
|---|
| 122 | 73 | udl_detect(struct drm_connector *connector, bool force) |
|---|
| 123 | 74 | { |
|---|
| 124 | | - u8 *edid_buff = NULL; |
|---|
| 125 | | - int edid_buff_size = 0; |
|---|
| 126 | | - struct udl_device *udl = connector->dev->dev_private; |
|---|
| 75 | + struct udl_device *udl = to_udl(connector->dev); |
|---|
| 127 | 76 | struct udl_drm_connector *udl_connector = |
|---|
| 128 | 77 | container_of(connector, |
|---|
| 129 | 78 | struct udl_drm_connector, |
|---|
| .. | .. |
|---|
| 135 | 84 | udl_connector->edid = NULL; |
|---|
| 136 | 85 | } |
|---|
| 137 | 86 | |
|---|
| 138 | | - |
|---|
| 139 | | - if (!udl_get_edid(udl, &edid_buff, &edid_buff_size)) |
|---|
| 87 | + udl_connector->edid = drm_do_get_edid(connector, udl_get_edid_block, udl); |
|---|
| 88 | + if (!udl_connector->edid) |
|---|
| 140 | 89 | return connector_status_disconnected; |
|---|
| 141 | 90 | |
|---|
| 142 | | - udl_connector->edid = (struct edid *)edid_buff; |
|---|
| 143 | | - |
|---|
| 144 | 91 | return connector_status_connected; |
|---|
| 145 | | -} |
|---|
| 146 | | - |
|---|
| 147 | | -static struct drm_encoder* |
|---|
| 148 | | -udl_best_single_encoder(struct drm_connector *connector) |
|---|
| 149 | | -{ |
|---|
| 150 | | - int enc_id = connector->encoder_ids[0]; |
|---|
| 151 | | - return drm_encoder_find(connector->dev, NULL, enc_id); |
|---|
| 152 | | -} |
|---|
| 153 | | - |
|---|
| 154 | | -static int udl_connector_set_property(struct drm_connector *connector, |
|---|
| 155 | | - struct drm_property *property, |
|---|
| 156 | | - uint64_t val) |
|---|
| 157 | | -{ |
|---|
| 158 | | - return 0; |
|---|
| 159 | 92 | } |
|---|
| 160 | 93 | |
|---|
| 161 | 94 | static void udl_connector_destroy(struct drm_connector *connector) |
|---|
| .. | .. |
|---|
| 165 | 98 | struct udl_drm_connector, |
|---|
| 166 | 99 | connector); |
|---|
| 167 | 100 | |
|---|
| 168 | | - drm_connector_unregister(connector); |
|---|
| 169 | 101 | drm_connector_cleanup(connector); |
|---|
| 170 | 102 | kfree(udl_connector->edid); |
|---|
| 171 | 103 | kfree(connector); |
|---|
| .. | .. |
|---|
| 174 | 106 | static const struct drm_connector_helper_funcs udl_connector_helper_funcs = { |
|---|
| 175 | 107 | .get_modes = udl_get_modes, |
|---|
| 176 | 108 | .mode_valid = udl_mode_valid, |
|---|
| 177 | | - .best_encoder = udl_best_single_encoder, |
|---|
| 178 | 109 | }; |
|---|
| 179 | 110 | |
|---|
| 180 | 111 | static const struct drm_connector_funcs udl_connector_funcs = { |
|---|
| 181 | | - .dpms = drm_helper_connector_dpms, |
|---|
| 112 | + .reset = drm_atomic_helper_connector_reset, |
|---|
| 182 | 113 | .detect = udl_detect, |
|---|
| 183 | 114 | .fill_modes = drm_helper_probe_single_connector_modes, |
|---|
| 184 | 115 | .destroy = udl_connector_destroy, |
|---|
| 185 | | - .set_property = udl_connector_set_property, |
|---|
| 116 | + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
|---|
| 117 | + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
|---|
| 186 | 118 | }; |
|---|
| 187 | 119 | |
|---|
| 188 | | -int udl_connector_init(struct drm_device *dev, struct drm_encoder *encoder) |
|---|
| 120 | +struct drm_connector *udl_connector_init(struct drm_device *dev) |
|---|
| 189 | 121 | { |
|---|
| 190 | 122 | struct udl_drm_connector *udl_connector; |
|---|
| 191 | 123 | struct drm_connector *connector; |
|---|
| 192 | 124 | |
|---|
| 193 | 125 | udl_connector = kzalloc(sizeof(struct udl_drm_connector), GFP_KERNEL); |
|---|
| 194 | 126 | if (!udl_connector) |
|---|
| 195 | | - return -ENOMEM; |
|---|
| 127 | + return ERR_PTR(-ENOMEM); |
|---|
| 196 | 128 | |
|---|
| 197 | 129 | connector = &udl_connector->connector; |
|---|
| 198 | 130 | drm_connector_init(dev, connector, &udl_connector_funcs, |
|---|
| 199 | 131 | DRM_MODE_CONNECTOR_DVII); |
|---|
| 200 | 132 | drm_connector_helper_add(connector, &udl_connector_helper_funcs); |
|---|
| 201 | 133 | |
|---|
| 202 | | - drm_connector_register(connector); |
|---|
| 203 | | - drm_connector_attach_encoder(connector, encoder); |
|---|
| 204 | 134 | connector->polled = DRM_CONNECTOR_POLL_HPD | |
|---|
| 205 | 135 | DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; |
|---|
| 206 | 136 | |
|---|
| 207 | | - return 0; |
|---|
| 137 | + return connector; |
|---|
| 208 | 138 | } |
|---|