blob: e6c68c6546773b6deeb2ee4969172a1898b38029 [file] [log] [blame]
Greg Kroah-Hartman39e7df52009-06-03 14:47:00 -07001#ifndef UDLFB_H
2#define UDLFB_H
Roberto De Ioris88e58b12009-06-03 14:03:06 -07003
Greg Kroah-Hartman39e7df52009-06-03 14:47:00 -07004/* as libdlo */
5#define BUF_HIGH_WATER_MARK 1024
6#define BUF_SIZE (64*1024)
Roberto De Ioris88e58b12009-06-03 14:03:06 -07007
Bernie Thompson4a4854d2010-02-15 06:45:55 -08008struct urb_node {
9 struct list_head entry;
10 struct dlfb_data *dev;
11 struct urb *urb;
12};
13
14struct urb_list {
15 struct list_head list;
16 spinlock_t lock;
17 struct semaphore limit_sem;
18 int available;
19 int count;
20 size_t size;
21};
22
Roberto De Ioris88e58b12009-06-03 14:03:06 -070023struct dlfb_data {
24 struct usb_device *udev;
Bernie Thompson4a4854d2010-02-15 06:45:55 -080025 struct device *gdev; /* &udev->dev */
Roberto De Ioris88e58b12009-06-03 14:03:06 -070026 struct usb_interface *interface;
27 struct urb *tx_urb, *ctrl_urb;
Roberto De Ioris88e58b12009-06-03 14:03:06 -070028 struct fb_info *info;
Bernie Thompson4a4854d2010-02-15 06:45:55 -080029 struct urb_list urbs;
30 struct kref kref;
Roberto De Ioris88e58b12009-06-03 14:03:06 -070031 char *buf;
32 char *bufend;
33 char *backing_buffer;
Bernie Thompson2469d5d2010-02-15 06:46:13 -080034 struct delayed_work deferred_work;
35 struct mutex fb_open_lock;
Roberto De Ioris88e58b12009-06-03 14:03:06 -070036 struct mutex bulk_mutex;
Bernie Thompson7d9485e2010-02-15 06:46:08 -080037 int fb_count;
38 atomic_t usb_active; /* 0 = update virtual buffer, but no usb traffic */
Bernie Thompson4a4854d2010-02-15 06:45:55 -080039 atomic_t lost_pixels; /* 1 = a render op failed. Need screen refresh */
Bernie Thompson7d9485e2010-02-15 06:46:08 -080040 atomic_t use_defio; /* 0 = rely on ioctls and blit/copy/fill rects */
Roberto De Ioris88e58b12009-06-03 14:03:06 -070041 char edid[128];
Bernie Thompson7d9485e2010-02-15 06:46:08 -080042 int sku_pixel_limit;
Roberto De Ioris88e58b12009-06-03 14:03:06 -070043 int screen_size;
44 int line_length;
45 struct completion done;
46 int base16;
Roberto De Ioris7316bc52009-06-10 23:02:19 -070047 int base16d;
Roberto De Ioris88e58b12009-06-03 14:03:06 -070048 int base8;
Roberto De Ioris7316bc52009-06-10 23:02:19 -070049 int base8d;
Bernie Thompson59277b62009-11-24 15:52:21 -080050 u32 pseudo_palette[256];
Bernie Thompson7d9485e2010-02-15 06:46:08 -080051 /* blit-only rendering path metrics, exposed through sysfs */
52 atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
53 atomic_t bytes_identical; /* saved effort with backbuffer comparison */
54 atomic_t bytes_sent; /* to usb, after compression including overhead */
55 atomic_t cpu_kcycles_used; /* transpired during pixel processing */
56 /* interface usage metrics. Clients can call driver via several */
57 atomic_t blit_count;
58 atomic_t copy_count;
59 atomic_t fill_count;
60 atomic_t damage_count;
61 atomic_t defio_fault_count;
Roberto De Ioris88e58b12009-06-03 14:03:06 -070062};
63
Bernie Thompsoncc403dc2010-02-15 06:45:49 -080064#define NR_USB_REQUEST_I2C_SUB_IO 0x02
65#define NR_USB_REQUEST_CHANNEL 0x12
66
Bernie Thompson4a4854d2010-02-15 06:45:55 -080067/* -BULK_SIZE as per usb-skeleton. Can we get full page and avoid overhead? */
68#define BULK_SIZE 512
69#define MAX_TRANSFER (PAGE_SIZE*16 - BULK_SIZE)
70#define WRITES_IN_FLIGHT (4)
71
72#define GET_URB_TIMEOUT HZ
73#define FREE_URB_TIMEOUT (HZ*2)
74
Roberto De Ioris88e58b12009-06-03 14:03:06 -070075static void dlfb_bulk_callback(struct urb *urb)
76{
Roberto De Ioris88e58b12009-06-03 14:03:06 -070077 struct dlfb_data *dev_info = urb->context;
78 complete(&dev_info->done);
Roberto De Ioris88e58b12009-06-03 14:03:06 -070079}
80
Roberto De Ioris7316bc52009-06-10 23:02:19 -070081static void dlfb_edid(struct dlfb_data *dev_info)
82{
83 int i;
84 int ret;
85 char rbuf[2];
86
87 for (i = 0; i < 128; i++) {
88 ret =
89 usb_control_msg(dev_info->udev,
90 usb_rcvctrlpipe(dev_info->udev, 0), (0x02),
91 (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2,
92 0);
Roberto De Ioris7316bc52009-06-10 23:02:19 -070093 dev_info->edid[i] = rbuf[1];
94 }
95
96}
97
Roberto De Ioris88e58b12009-06-03 14:03:06 -070098static int dlfb_bulk_msg(struct dlfb_data *dev_info, int len)
99{
Roberto De Ioris88e58b12009-06-03 14:03:06 -0700100 int ret;
101
102 init_completion(&dev_info->done);
103
104 dev_info->tx_urb->actual_length = 0;
105 dev_info->tx_urb->transfer_buffer_length = len;
106
107 ret = usb_submit_urb(dev_info->tx_urb, GFP_KERNEL);
108 if (!wait_for_completion_timeout(&dev_info->done, 1000)) {
109 usb_kill_urb(dev_info->tx_urb);
110 printk("usb timeout !!!\n");
111 }
112
113 return dev_info->tx_urb->actual_length;
Roberto De Ioris88e58b12009-06-03 14:03:06 -0700114}
115
Bernie Thompson59277b62009-11-24 15:52:21 -0800116#define dlfb_set_register insert_command
Greg Kroah-Hartman39e7df52009-06-03 14:47:00 -0700117
Bernie Thompson7d9485e2010-02-15 06:46:08 -0800118/* remove once this gets added to sysfs.h */
119#define __ATTR_RW(attr) __ATTR(attr, 0644, attr##_show, attr##_store)
120
Bernie Thompson4a4854d2010-02-15 06:45:55 -0800121#define dl_err(format, arg...) \
122 dev_err(dev->gdev, "dlfb: " format, ## arg)
123#define dl_warn(format, arg...) \
124 dev_warn(dev->gdev, "dlfb: " format, ## arg)
125#define dl_notice(format, arg...) \
126 dev_notice(dev->gdev, "dlfb: " format, ## arg)
127#define dl_info(format, arg...) \
128 dev_info(dev->gdev, "dlfb: " format, ## arg)
Greg Kroah-Hartman39e7df52009-06-03 14:47:00 -0700129#endif