Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
udl_connector.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Red Hat
3  * based in parts on udlfb.c:
4  * Copyright (C) 2009 Roberto De Ioris <[email protected]>
5  * Copyright (C) 2009 Jaya Kumar <[email protected]>
6  * Copyright (C) 2009 Bernie Thompson <[email protected]>
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 
22 static 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 
47 error:
48  kfree(block);
49  return NULL;
50 }
51 
52 static 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 
61  ret = drm_add_edid_modes(connector, edid);
62  kfree(edid);
63  return ret;
64 }
65 
66 static int udl_mode_valid(struct drm_connector *connector,
67  struct drm_display_mode *mode)
68 {
69  struct udl_device *udl = connector->dev->dev_private;
70  if (!udl->sku_pixel_limit)
71  return 0;
72 
73  if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit)
74  return MODE_VIRTUAL_Y;
75 
76  return 0;
77 }
78 
79 static enum drm_connector_status
80 udl_detect(struct drm_connector *connector, bool force)
81 {
82  if (drm_device_is_unplugged(connector->dev))
85 }
86 
88 {
89  int enc_id = connector->encoder_ids[0];
90  struct drm_mode_object *obj;
91  struct drm_encoder *encoder;
92 
93  obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
94  if (!obj)
95  return NULL;
96  encoder = obj_to_encoder(obj);
97  return encoder;
98 }
99 
101  uint64_t val)
102 {
103  return 0;
104 }
105 
106 static void udl_connector_destroy(struct drm_connector *connector)
107 {
108  drm_sysfs_connector_remove(connector);
109  drm_connector_cleanup(connector);
110  kfree(connector);
111 }
112 
114  .get_modes = udl_get_modes,
115  .mode_valid = udl_mode_valid,
116  .best_encoder = udl_best_single_encoder,
117 };
118 
121  .detect = udl_detect,
123  .destroy = udl_connector_destroy,
124  .set_property = udl_connector_set_property,
125 };
126 
127 int udl_connector_init(struct drm_device *dev, struct drm_encoder *encoder)
128 {
129  struct drm_connector *connector;
130 
131  connector = kzalloc(sizeof(struct drm_connector), GFP_KERNEL);
132  if (!connector)
133  return -ENOMEM;
134 
135  drm_connector_init(dev, connector, &udl_connector_funcs, DRM_MODE_CONNECTOR_DVII);
136  drm_connector_helper_add(connector, &udl_connector_helper_funcs);
137 
138  drm_sysfs_connector_add(connector);
139  drm_mode_connector_attach_encoder(connector, encoder);
140 
142  dev->mode_config.dirty_info_property,
143  1);
144  return 0;
145 }