Linux Audio

Check our new training course

Loading...
v5.4
  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_crtc_helper.h>
 11#include <drm/drm_probe_helper.h>
 12
 13#include "udl_connector.h"
 14#include "udl_drv.h"
 15
 16static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,
 17			       size_t len)
 
 
 18{
 
 
 19	int ret, i;
 20	u8 *read_buff;
 21	struct udl_device *udl = data;
 22
 23	read_buff = kmalloc(2, GFP_KERNEL);
 24	if (!read_buff)
 25		return -1;
 26
 27	for (i = 0; i < len; i++) {
 28		int bval = (i + block * EDID_LENGTH) << 8;
 29		ret = usb_control_msg(udl->udev,
 30				      usb_rcvctrlpipe(udl->udev, 0),
 31					  (0x02), (0x80 | (0x02 << 5)), bval,
 32					  0xA1, read_buff, 2, HZ);
 33		if (ret < 1) {
 34			DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret);
 35			kfree(read_buff);
 36			return -1;
 37		}
 38		buf[i] = read_buff[1];
 39	}
 40
 41	kfree(read_buff);
 42	return 0;
 
 
 
 43}
 44
 45static int udl_get_modes(struct drm_connector *connector)
 46{
 47	struct udl_drm_connector *udl_connector =
 48					container_of(connector,
 49					struct udl_drm_connector,
 50					connector);
 51
 52	drm_connector_update_edid_property(connector, udl_connector->edid);
 53	if (udl_connector->edid)
 54		return drm_add_edid_modes(connector, udl_connector->edid);
 55	return 0;
 
 
 
 
 56}
 57
 58static enum drm_mode_status udl_mode_valid(struct drm_connector *connector,
 59			  struct drm_display_mode *mode)
 60{
 61	struct udl_device *udl = connector->dev->dev_private;
 62	if (!udl->sku_pixel_limit)
 63		return 0;
 64
 65	if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit)
 66		return MODE_VIRTUAL_Y;
 67
 68	return 0;
 69}
 70
 71static enum drm_connector_status
 72udl_detect(struct drm_connector *connector, bool force)
 73{
 74	struct udl_device *udl = connector->dev->dev_private;
 75	struct udl_drm_connector *udl_connector =
 76					container_of(connector,
 77					struct udl_drm_connector,
 78					connector);
 79
 80	/* cleanup previous edid */
 81	if (udl_connector->edid != NULL) {
 82		kfree(udl_connector->edid);
 83		udl_connector->edid = NULL;
 84	}
 85
 86	udl_connector->edid = drm_do_get_edid(connector, udl_get_edid_block, udl);
 87	if (!udl_connector->edid)
 88		return connector_status_disconnected;
 89
 90	return connector_status_connected;
 91}
 92
 93static struct drm_encoder*
 94udl_best_single_encoder(struct drm_connector *connector)
 95{
 96	int enc_id = connector->encoder_ids[0];
 97	return drm_encoder_find(connector->dev, NULL, enc_id);
 
 
 
 
 
 
 
 98}
 99
100static int udl_connector_set_property(struct drm_connector *connector,
101				      struct drm_property *property,
102				      uint64_t val)
103{
104	return 0;
105}
106
107static void udl_connector_destroy(struct drm_connector *connector)
108{
109	struct udl_drm_connector *udl_connector =
110					container_of(connector,
111					struct udl_drm_connector,
112					connector);
113
114	drm_connector_unregister(connector);
115	drm_connector_cleanup(connector);
116	kfree(udl_connector->edid);
117	kfree(connector);
118}
119
120static const struct drm_connector_helper_funcs udl_connector_helper_funcs = {
121	.get_modes = udl_get_modes,
122	.mode_valid = udl_mode_valid,
123	.best_encoder = udl_best_single_encoder,
124};
125
126static const struct drm_connector_funcs udl_connector_funcs = {
127	.dpms = drm_helper_connector_dpms,
128	.detect = udl_detect,
129	.fill_modes = drm_helper_probe_single_connector_modes,
130	.destroy = udl_connector_destroy,
131	.set_property = udl_connector_set_property,
132};
133
134int udl_connector_init(struct drm_device *dev, struct drm_encoder *encoder)
135{
136	struct udl_drm_connector *udl_connector;
137	struct drm_connector *connector;
138
139	udl_connector = kzalloc(sizeof(struct udl_drm_connector), GFP_KERNEL);
140	if (!udl_connector)
141		return -ENOMEM;
142
143	connector = &udl_connector->connector;
144	drm_connector_init(dev, connector, &udl_connector_funcs,
145			   DRM_MODE_CONNECTOR_DVII);
146	drm_connector_helper_add(connector, &udl_connector_helper_funcs);
147
148	drm_connector_register(connector);
149	drm_connector_attach_encoder(connector, encoder);
150	connector->polled = DRM_CONNECTOR_POLL_HPD |
151		DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
152
 
 
 
153	return 0;
154}
v3.5.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 "drmP.h"
 14#include "drm_crtc.h"
 15#include "drm_edid.h"
 16#include "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[3];
 26	int ret, i;
 
 
 27
 28	block = kmalloc(EDID_LENGTH, GFP_KERNEL);
 29	if (block == NULL)
 30		return NULL;
 31
 32	for (i = 0; i < EDID_LENGTH; i++) {
 33		ret = usb_control_msg(udl->ddev->usbdev,
 34				      usb_rcvctrlpipe(udl->ddev->usbdev, 0), (0x02),
 35				      (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2,
 36				      HZ);
 
 37		if (ret < 1) {
 38			DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret);
 39			i--;
 40			goto error;
 41		}
 42		block[i] = rbuf[1];
 43	}
 44
 45	return block;
 46
 47error:
 48	kfree(block);
 49	return NULL;
 50}
 51
 52static int udl_get_modes(struct drm_connector *connector)
 53{
 54	struct udl_device *udl = connector->dev->dev_private;
 55	struct edid *edid;
 56	int ret;
 57
 58	edid = (struct edid *)udl_get_edid(udl);
 59
 60	connector->display_info.raw_edid = (char *)edid;
 61
 62	drm_mode_connector_update_edid_property(connector, edid);
 63	ret = drm_add_edid_modes(connector, edid);
 64	connector->display_info.raw_edid = NULL;
 65	kfree(edid);
 66	return ret;
 67}
 68
 69static int udl_mode_valid(struct drm_connector *connector,
 70			  struct drm_display_mode *mode)
 71{
 72	struct udl_device *udl = connector->dev->dev_private;
 73	if (!udl->sku_pixel_limit)
 74		return 0;
 75
 76	if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit)
 77		return MODE_VIRTUAL_Y;
 78
 79	return 0;
 80}
 81
 82static enum drm_connector_status
 83udl_detect(struct drm_connector *connector, bool force)
 84{
 85	if (drm_device_is_unplugged(connector->dev))
 
 
 
 
 
 
 
 
 
 
 
 
 
 86		return connector_status_disconnected;
 
 87	return connector_status_connected;
 88}
 89
 90struct drm_encoder *udl_best_single_encoder(struct drm_connector *connector)
 
 91{
 92	int enc_id = connector->encoder_ids[0];
 93	struct drm_mode_object *obj;
 94	struct drm_encoder *encoder;
 95
 96	obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
 97	if (!obj)
 98		return NULL;
 99	encoder = obj_to_encoder(obj);
100	return encoder;
101}
102
103int udl_connector_set_property(struct drm_connector *connector, struct drm_property *property,
104			       uint64_t val)
 
105{
106	return 0;
107}
108
109static void udl_connector_destroy(struct drm_connector *connector)
110{
111	drm_sysfs_connector_remove(connector);
 
 
 
 
 
112	drm_connector_cleanup(connector);
 
113	kfree(connector);
114}
115
116struct drm_connector_helper_funcs udl_connector_helper_funcs = {
117	.get_modes = udl_get_modes,
118	.mode_valid = udl_mode_valid,
119	.best_encoder = udl_best_single_encoder,
120};
121
122struct drm_connector_funcs udl_connector_funcs = {
123	.dpms = drm_helper_connector_dpms,
124	.detect = udl_detect,
125	.fill_modes = drm_helper_probe_single_connector_modes,
126	.destroy = udl_connector_destroy,
127	.set_property = udl_connector_set_property,
128};
129
130int udl_connector_init(struct drm_device *dev, struct drm_encoder *encoder)
131{
 
132	struct drm_connector *connector;
133
134	connector = kzalloc(sizeof(struct drm_connector), GFP_KERNEL);
135	if (!connector)
136		return -ENOMEM;
137
138	drm_connector_init(dev, connector, &udl_connector_funcs, DRM_MODE_CONNECTOR_DVII);
 
 
139	drm_connector_helper_add(connector, &udl_connector_helper_funcs);
140
141	drm_sysfs_connector_add(connector);
142	drm_mode_connector_attach_encoder(connector, encoder);
 
 
143
144	drm_connector_attach_property(connector,
145				      dev->mode_config.dirty_info_property,
146				      1);
147	return 0;
148}