File Index
Files and directories
Sign in
FILE

udl_edid.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/udl/udl_edid.c C
 1// SPDX-License-Identifier: GPL-2.0-only
 2
 3#include <linux/string.h>
 4
 5#include <drm/drm_drv.h>
 6#include <drm/drm_edid.h>
 7#include <drm/drm_print.h>
 8
 9#include "udl_drv.h"
10#include "udl_edid.h"
11
12static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
13{
14	struct udl_device *udl = data;
15	struct drm_device *dev = &udl->drm;
16	struct usb_device *udev = udl_to_usb_device(udl);
17	u8 *read_buff;
18	int idx, ret;
19	size_t i;
20
21	read_buff = kmalloc(2, GFP_KERNEL);
22	if (!read_buff)
23		return -ENOMEM;
24
25	if (!drm_dev_enter(dev, &idx)) {
26		ret = -ENODEV;
27		goto err_kfree;
28	}
29
30	for (i = 0; i < len; i++) {
31		int bval = (i + block * EDID_LENGTH) << 8;
32
33		ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
34				      0x02, (0x80 | (0x02 << 5)), bval,
35				      0xA1, read_buff, 2, USB_CTRL_GET_TIMEOUT);
36		if (ret < 0) {
37			drm_err(dev, "Read EDID byte %zu failed err %x\n", i, ret);
38			goto err_drm_dev_exit;
39		} else if (ret < 1) {
40			ret = -EIO;
41			drm_err(dev, "Read EDID byte %zu failed\n", i);
42			goto err_drm_dev_exit;
43		}
44
45		buf[i] = read_buff[1];
46	}
47
48	drm_dev_exit(idx);
49	kfree(read_buff);
50
51	return 0;
52
53err_drm_dev_exit:
54	drm_dev_exit(idx);
55err_kfree:
56	kfree(read_buff);
57	return ret;
58}
59
60bool udl_probe_edid(struct udl_device *udl)
61{
62	u8 hdr[8];
63	int ret;
64
65	ret = udl_read_edid_block(udl, hdr, 0, sizeof(hdr));
66	if (ret)
67		return false;
68
69	/*
70	 * The adapter sends all-zeros if no monitor has been
71	 * connected. We consider anything else a connection.
72	 */
73	return !mem_is_zero(hdr, sizeof(hdr));
74}
75
76const struct drm_edid *udl_edid_read(struct drm_connector *connector)
77{
78	struct udl_device *udl = to_udl(connector->dev);
79
80	return drm_edid_read_custom(connector, udl_read_edid_block, udl);
81}
~/ Read-only file preview.