Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (C) 2012 Red Hat
  3 * based in parts on udlfb.c:
  4 * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
  5 * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
  6 * 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 */
 12
 13#include <drm/drmP.h>
 14#include <drm/drm_crtc.h>
 15#include <drm/drm_edid.h>
 16#include <drm/drm_crtc_helper.h>
 17#include "udl_drv.h"
 18
 19/* dummy connector to just get EDID,
 20   all UDL appear to have a DVI-D */
 21
 22static u8 *udl_get_edid(struct udl_device *udl)
 
 23{
 24	u8 *block;
 25	char *rbuf;
 26	int ret, i;
 
 
 27
 28	block = kmalloc(EDID_LENGTH, GFP_KERNEL);
 29	if (block == NULL)
 30		return NULL;
 31
 32	rbuf = kmalloc(2, GFP_KERNEL);
 33	if (rbuf == NULL)
 34		goto error;
 35
 36	for (i = 0; i < EDID_LENGTH; i++) {
 
 37		ret = usb_control_msg(udl->udev,
 38				      usb_rcvctrlpipe(udl->udev, 0), (0x02),
 39				      (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2,
 40				      HZ);
 41		if (ret < 1) {
 42			DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret);
 43			goto error;
 
 44		}
 45		block[i] = rbuf[1];
 46	}
 47
 48	kfree(rbuf);
 49	return block;
 50
 51error:
 52	kfree(block);
 53	kfree(rbuf);
 54	return NULL;
 55}
 56
 57static int udl_get_modes(struct drm_connector *connector)
 58{
 59	struct udl_device *udl = connector->dev->dev_private;
 60	struct edid *edid;
 61	int ret;
 62
 63	edid = (struct edid *)udl_get_edid(udl);
 64	if (!edid) {
 65		drm_mode_connector_update_edid_property(connector, NULL);
 66		return 0;
 67	}
 68
 69	/*
 70	 * We only read the main block, but if the monitor reports extension
 71	 * blocks then the drm edid code expects them to be present, so patch
 72	 * the extension count to 0.
 73	 */
 74	edid->checksum += edid->extensions;
 75	edid->extensions = 0;
 76
 77	drm_mode_connector_update_edid_property(connector, edid);
 78	ret = drm_add_edid_modes(connector, edid);
 79	kfree(edid);
 80	return ret;
 81}
 82
 83static int udl_mode_valid(struct drm_connector *connector,
 84			  struct drm_display_mode *mode)
 85{
 86	struct udl_device *udl = connector->dev->dev_private;
 87	if (!udl->sku_pixel_limit)
 88		return 0;
 89
 90	if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit)
 91		return MODE_VIRTUAL_Y;
 92
 93	return 0;
 94}
 95
 96static enum drm_connector_status
 97udl_detect(struct drm_connector *connector, bool force)
 98{
 99	if (drm_device_is_unplugged(connector->dev))
100		return connector_status_disconnected;
101	return connector_status_connected;
102}
 
 
 
 
 
 
 
103
104static struct drm_encoder*
105udl_best_single_encoder(struct drm_connector *connector)
106{
107	int enc_id = connector->encoder_ids[0];
108	return drm_encoder_find(connector->dev, enc_id);
109}
110
111static int udl_connector_set_property(struct drm_connector *connector,
112				      struct drm_property *property,
113				      uint64_t val)
114{
115	return 0;
116}
117
118static void udl_connector_destroy(struct drm_connector *connector)
119{
120	drm_connector_unregister(connector);
 
 
 
 
121	drm_connector_cleanup(connector);
 
122	kfree(connector);
123}
124
125static const struct drm_connector_helper_funcs udl_connector_helper_funcs = {
126	.get_modes = udl_get_modes,
127	.mode_valid = udl_mode_valid,
128	.best_encoder = udl_best_single_encoder,
129};
130
131static const struct drm_connector_funcs udl_connector_funcs = {
132	.dpms = drm_helper_connector_dpms,
133	.detect = udl_detect,
134	.fill_modes = drm_helper_probe_single_connector_modes,
135	.destroy = udl_connector_destroy,
136	.set_property = udl_connector_set_property,
 
137};
138
139int udl_connector_init(struct drm_device *dev, struct drm_encoder *encoder)
140{
 
141	struct drm_connector *connector;
142
143	connector = kzalloc(sizeof(struct drm_connector), GFP_KERNEL);
144	if (!connector)
145		return -ENOMEM;
146
147	drm_connector_init(dev, connector, &udl_connector_funcs, DRM_MODE_CONNECTOR_DVII);
 
 
148	drm_connector_helper_add(connector, &udl_connector_helper_funcs);
149
150	drm_connector_register(connector);
151	drm_mode_connector_attach_encoder(connector, encoder);
152
153	drm_object_attach_property(&connector->base,
154				      dev->mode_config.dirty_info_property,
155				      1);
156	return 0;
157}
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2012 Red Hat
  4 * based in parts on udlfb.c:
  5 * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
  6 * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
  7 * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
 
 
 
 
  8 */
  9
 10#include <drm/drm_atomic_state_helper.h>
 
 
 11#include <drm/drm_crtc_helper.h>
 12#include <drm/drm_probe_helper.h>
 13
 14#include "udl_connector.h"
 15#include "udl_drv.h"
 16
 17static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,
 18			       size_t len)
 19{
 
 
 20	int ret, i;
 21	u8 *read_buff;
 22	struct udl_device *udl = data;
 23
 24	read_buff = kmalloc(2, GFP_KERNEL);
 25	if (!read_buff)
 26		return -1;
 
 
 
 
 27
 28	for (i = 0; i < len; i++) {
 29		int bval = (i + block * EDID_LENGTH) << 8;
 30		ret = usb_control_msg(udl->udev,
 31				      usb_rcvctrlpipe(udl->udev, 0),
 32					  (0x02), (0x80 | (0x02 << 5)), bval,
 33					  0xA1, read_buff, 2, HZ);
 34		if (ret < 1) {
 35			DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret);
 36			kfree(read_buff);
 37			return -1;
 38		}
 39		buf[i] = read_buff[1];
 40	}
 41
 42	kfree(read_buff);
 43	return 0;
 
 
 
 
 
 44}
 45
 46static int udl_get_modes(struct drm_connector *connector)
 47{
 48	struct udl_drm_connector *udl_connector =
 49					container_of(connector,
 50					struct udl_drm_connector,
 51					connector);
 52
 53	drm_connector_update_edid_property(connector, udl_connector->edid);
 54	if (udl_connector->edid)
 55		return drm_add_edid_modes(connector, udl_connector->edid);
 56	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 57}
 58
 59static enum drm_mode_status udl_mode_valid(struct drm_connector *connector,
 60			  struct drm_display_mode *mode)
 61{
 62	struct udl_device *udl = to_udl(connector->dev);
 63	if (!udl->sku_pixel_limit)
 64		return 0;
 65
 66	if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit)
 67		return MODE_VIRTUAL_Y;
 68
 69	return 0;
 70}
 71
 72static enum drm_connector_status
 73udl_detect(struct drm_connector *connector, bool force)
 74{
 75	struct udl_device *udl = to_udl(connector->dev);
 76	struct udl_drm_connector *udl_connector =
 77					container_of(connector,
 78					struct udl_drm_connector,
 79					connector);
 80
 81	/* cleanup previous edid */
 82	if (udl_connector->edid != NULL) {
 83		kfree(udl_connector->edid);
 84		udl_connector->edid = NULL;
 85	}
 86
 87	udl_connector->edid = drm_do_get_edid(connector, udl_get_edid_block, udl);
 88	if (!udl_connector->edid)
 89		return connector_status_disconnected;
 
 
 
 90
 91	return connector_status_connected;
 
 
 
 
 92}
 93
 94static void udl_connector_destroy(struct drm_connector *connector)
 95{
 96	struct udl_drm_connector *udl_connector =
 97					container_of(connector,
 98					struct udl_drm_connector,
 99					connector);
100
101	drm_connector_cleanup(connector);
102	kfree(udl_connector->edid);
103	kfree(connector);
104}
105
106static const struct drm_connector_helper_funcs udl_connector_helper_funcs = {
107	.get_modes = udl_get_modes,
108	.mode_valid = udl_mode_valid,
 
109};
110
111static const struct drm_connector_funcs udl_connector_funcs = {
112	.reset = drm_atomic_helper_connector_reset,
113	.detect = udl_detect,
114	.fill_modes = drm_helper_probe_single_connector_modes,
115	.destroy = udl_connector_destroy,
116	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
117	.atomic_destroy_state   = drm_atomic_helper_connector_destroy_state,
118};
119
120struct drm_connector *udl_connector_init(struct drm_device *dev)
121{
122	struct udl_drm_connector *udl_connector;
123	struct drm_connector *connector;
124
125	udl_connector = kzalloc(sizeof(struct udl_drm_connector), GFP_KERNEL);
126	if (!udl_connector)
127		return ERR_PTR(-ENOMEM);
128
129	connector = &udl_connector->connector;
130	drm_connector_init(dev, connector, &udl_connector_funcs,
131			   DRM_MODE_CONNECTOR_DVII);
132	drm_connector_helper_add(connector, &udl_connector_helper_funcs);
133
134	connector->polled = DRM_CONNECTOR_POLL_HPD |
135		DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
136
137	return connector;
 
 
 
138}