1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/string.h>
5 #include <drm/drm_drv.h>
6 #include <drm/drm_edid.h>
11 static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
13 struct udl_device *udl = data;
14 struct drm_device *dev = &udl->drm;
15 struct usb_device *udev = udl_to_usb_device(udl);
20 read_buff = kmalloc(2, GFP_KERNEL);
24 if (!drm_dev_enter(dev, &idx)) {
29 for (i = 0; i < len; i++) {
30 int bval = (i + block * EDID_LENGTH) << 8;
32 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
33 0x02, (0x80 | (0x02 << 5)), bval,
34 0xA1, read_buff, 2, USB_CTRL_GET_TIMEOUT);
36 drm_err(dev, "Read EDID byte %zu failed err %x\n", i, ret);
37 goto err_drm_dev_exit;
40 drm_err(dev, "Read EDID byte %zu failed\n", i);
41 goto err_drm_dev_exit;
44 buf[i] = read_buff[1];
59 bool udl_probe_edid(struct udl_device *udl)
64 ret = udl_read_edid_block(udl, hdr, 0, sizeof(hdr));
69 * The adapter sends all-zeros if no monitor has been
70 * connected. We consider anything else a connection.
72 return !mem_is_zero(hdr, sizeof(hdr));
75 const struct drm_edid *udl_edid_read(struct drm_connector *connector)
77 struct udl_device *udl = to_udl(connector->dev);
79 return drm_edid_read_custom(connector, udl_read_edid_block, udl);