1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2012 Red Hat
4 *
5 * based in parts on udlfb.c:
6 * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
7 * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
8 * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
9 */
10
11 #ifndef UDL_DRV_H
12 #define UDL_DRV_H
13
14 #include <linux/mm_types.h>
15 #include <linux/usb.h>
16
17 #include <drm/drm_device.h>
18 #include <drm/drm_framebuffer.h>
19 #include <drm/drm_gem.h>
20 #include <drm/drm_simple_kms_helper.h>
21
22 struct drm_mode_create_dumb;
23
24 #define DRIVER_NAME "udl"
25 #define DRIVER_DESC "DisplayLink"
26 #define DRIVER_DATE "20120220"
27
28 #define DRIVER_MAJOR 0
29 #define DRIVER_MINOR 0
30 #define DRIVER_PATCHLEVEL 1
31
32 struct udl_device;
33
34 struct urb_node {
35 struct list_head entry;
36 struct udl_device *dev;
37 struct urb *urb;
38 };
39
40 struct urb_list {
41 struct list_head list;
42 spinlock_t lock;
43 wait_queue_head_t sleep;
44 int available;
45 int count;
46 size_t size;
47 };
48
49 struct udl_device {
50 struct drm_device drm;
51 struct device *dev;
52 struct device *dmadev;
53
54 struct drm_simple_display_pipe display_pipe;
55
56 struct mutex gem_lock;
57
58 int sku_pixel_limit;
59
60 struct urb_list urbs;
61
62 char mode_buf[1024];
63 uint32_t mode_buf_len;
64 };
65
66 #define to_udl(x) container_of(x, struct udl_device, drm)
67
udl_to_usb_device(struct udl_device * udl)68 static inline struct usb_device *udl_to_usb_device(struct udl_device *udl)
69 {
70 return interface_to_usbdev(to_usb_interface(udl->drm.dev));
71 }
72
73 /* modeset */
74 int udl_modeset_init(struct drm_device *dev);
75 struct drm_connector *udl_connector_init(struct drm_device *dev);
76
77 struct urb *udl_get_urb(struct drm_device *dev);
78
79 int udl_submit_urb(struct drm_device *dev, struct urb *urb, size_t len);
80 void udl_sync_pending_urbs(struct drm_device *dev);
81 void udl_urb_completion(struct urb *urb);
82
83 int udl_init(struct udl_device *udl);
84
85 int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr,
86 const char *front, char **urb_buf_ptr,
87 u32 byte_offset, u32 device_byte_offset, u32 byte_width);
88
89 int udl_drop_usb(struct drm_device *dev);
90 int udl_select_std_channel(struct udl_device *udl);
91
92 #define CMD_WRITE_RAW8 "\xAF\x60" /**< 8 bit raw write command. */
93 #define CMD_WRITE_RL8 "\xAF\x61" /**< 8 bit run length command. */
94 #define CMD_WRITE_COPY8 "\xAF\x62" /**< 8 bit copy command. */
95 #define CMD_WRITE_RLX8 "\xAF\x63" /**< 8 bit extended run length command. */
96
97 #define CMD_WRITE_RAW16 "\xAF\x68" /**< 16 bit raw write command. */
98 #define CMD_WRITE_RL16 "\xAF\x69" /**< 16 bit run length command. */
99 #define CMD_WRITE_COPY16 "\xAF\x6A" /**< 16 bit copy command. */
100 #define CMD_WRITE_RLX16 "\xAF\x6B" /**< 16 bit extended run length command. */
101
102 /* On/Off for driving the DisplayLink framebuffer to the display */
103 #define UDL_REG_BLANK_MODE 0x1f
104
105 #define UDL_BLANK_MODE_ON 0x00 /* hsync and vsync on, visible */
106 #define UDL_BLANK_MODE_BLANKED 0x01 /* hsync and vsync on, blanked */
107 #define UDL_BLANK_MODE_VSYNC_OFF 0x03 /* vsync off, blanked */
108 #define UDL_BLANK_MODE_HSYNC_OFF 0x05 /* hsync off, blanked */
109 #define UDL_BLANK_MODE_POWERDOWN 0x07 /* powered off; requires modeset */
110
111 #endif
112