summaryrefslogtreecommitdiff
path: root/gm12u320_drv.h
blob: 4af1feba0cd239d304e7cc3fa3a730ee395fd953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright (C) 2012-2015 Red Hat Inc.
 *
 * Based in parts on the udl code. Based in parts on the gm12u320 fb driver:
 * Copyright (C) 2013 Viacheslav Nurmekhamitov <slavrn@yandex.ru>
 * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
 * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
 * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License v2. See the file COPYING in the main directory of this archive for
 * more details.
 */

#ifndef GM12U320_DRV_H
#define GM12U320_DRV_H

#include <linux/usb.h>
#include <linux/spinlock.h>
#include <drm/drm_gem.h>

#define DRIVER_NAME		"gm12u320"
#define DRIVER_DESC		"Grain Media GM12U320 USB projector display"
#define DRIVER_DATE		"20150107"

#define DRIVER_MAJOR		0
#define DRIVER_MINOR		0
#define DRIVER_PATCHLEVEL	1

#define GM12U320_BO_CACHEABLE	(1 << 0)
#define GM12U320_BO_WC		(1 << 1)

/*
 * The DLP has an actual width of 854 pixels, but that is not a multiple
 * of 4, breaking things left and right, so we export a width of 852.
 */
#define GM12U320_USER_WIDTH	852
#define GM12U320_REAL_WIDTH	854
#define GM12U320_HEIGHT		480

#define GM12U320_BLOCK_COUNT	20

struct gm12u320_device;

struct gm12u320_fbdev;

struct gm12u320_device {
	struct device *dev;
	struct usb_device *udev;
	struct drm_device *ddev;
	struct gm12u320_fbdev *fbdev;
	unsigned char *cmd_buf;
	unsigned char *data_buf[GM12U320_BLOCK_COUNT];
	struct {
		struct workqueue_struct *workq;
		struct work_struct work;
		wait_queue_head_t waitq;
		spinlock_t lock;
		struct gm12u320_framebuffer *fb;
		int x1;
		int x2;
		int y1;
		int y2;
	} fb_update;
};

struct gm12u320_gem_object {
	struct drm_gem_object base;
	struct page **pages;
	void *vmapping;
	struct sg_table *sg;
	unsigned int flags;
};

#define to_gm12u320_bo(x) container_of(x, struct gm12u320_gem_object, base)

struct gm12u320_framebuffer {
	struct drm_framebuffer base;
	struct gm12u320_gem_object *obj;
};

#define to_gm12u320_fb(x) container_of(x, struct gm12u320_framebuffer, base)

/* modeset */
int gm12u320_modeset_init(struct drm_device *dev);
void gm12u320_modeset_cleanup(struct drm_device *dev);
int gm12u320_connector_init(struct drm_device *dev, struct drm_encoder *encoder);

struct drm_encoder *gm12u320_encoder_init(struct drm_device *dev);

int gm12u320_driver_load(struct drm_device *dev, unsigned long flags);
int gm12u320_driver_unload(struct drm_device *dev);

int gm12u320_fbdev_init(struct drm_device *dev);
void gm12u320_fbdev_cleanup(struct drm_device *dev);
void gm12u320_fbdev_unplug(struct drm_device *dev);
struct drm_framebuffer *
gm12u320_fb_user_fb_create(struct drm_device *dev,
		      struct drm_file *file,
		      struct drm_mode_fb_cmd2 *mode_cmd);

int gm12u320_dumb_create(struct drm_file *file_priv,
		    struct drm_device *dev,
		    struct drm_mode_create_dumb *args);
int gm12u320_gem_mmap(struct drm_file *file_priv, struct drm_device *dev,
		 uint32_t handle, uint64_t *offset);

void gm12u320_gem_free_object(struct drm_gem_object *gem_obj);
struct gm12u320_gem_object *gm12u320_gem_alloc_object(struct drm_device *dev,
					    size_t size);
struct dma_buf *gm12u320_gem_prime_export(struct drm_device *dev,
				     struct drm_gem_object *obj, int flags);
struct drm_gem_object *gm12u320_gem_prime_import(struct drm_device *dev,
				struct dma_buf *dma_buf);

int gm12u320_gem_get_pages(struct gm12u320_gem_object *obj);
void gm12u320_gem_put_pages(struct gm12u320_gem_object *obj);
int gm12u320_gem_vmap(struct gm12u320_gem_object *obj);
void gm12u320_gem_vunmap(struct gm12u320_gem_object *obj);
int gm12u320_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
int gm12u320_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);

void gm12u320_fb_mark_dirty(struct gm12u320_framebuffer *fb,
			    int x1, int x2, int y1, int y2);
#endif