Home | History | Annotate | Line # | Download | only in usb
udl.h revision 1.1.26.1
      1       1.1   tsutsui /*	$NetBSD: udl.h,v 1.1.26.1 2017/12/03 11:37:34 jdolecek Exp $	*/
      2       1.1   tsutsui 
      3       1.1   tsutsui /*-
      4       1.1   tsutsui  * Copyright (c) 2009 FUKAUMI Naoki.
      5       1.1   tsutsui  * All rights reserved.
      6       1.1   tsutsui  *
      7       1.1   tsutsui  * Redistribution and use in source and binary forms, with or without
      8       1.1   tsutsui  * modification, are permitted provided that the following conditions
      9       1.1   tsutsui  * are met:
     10       1.1   tsutsui  * 1. Redistributions of source code must retain the above copyright
     11       1.1   tsutsui  *    notice, this list of conditions and the following disclaimer.
     12       1.1   tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   tsutsui  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   tsutsui  *    documentation and/or other materials provided with the distribution.
     15       1.1   tsutsui  *
     16       1.1   tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1   tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.1   tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.1   tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.1   tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.1   tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.1   tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.1   tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.1   tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.1   tsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1   tsutsui  */
     27       1.1   tsutsui 
     28       1.1   tsutsui /*
     29       1.1   tsutsui  * Copyright (c) 2009 Marcus Glocker <mglocker (at) openbsd.org>
     30       1.1   tsutsui  *
     31       1.1   tsutsui  * Permission to use, copy, modify, and distribute this software for any
     32       1.1   tsutsui  * purpose with or without fee is hereby granted, provided that the above
     33       1.1   tsutsui  * copyright notice and this permission notice appear in all copies.
     34       1.1   tsutsui  *
     35       1.1   tsutsui  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     36       1.1   tsutsui  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     37       1.1   tsutsui  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     38       1.1   tsutsui  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     39       1.1   tsutsui  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     40       1.1   tsutsui  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     41       1.1   tsutsui  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     42       1.1   tsutsui  */
     43       1.1   tsutsui 
     44       1.1   tsutsui #ifdef UDL_EVENT_COUNTERS
     45       1.1   tsutsui #define UDL_EVCNT_INCR(ev)	(ev)->ev_count++
     46       1.1   tsutsui #else
     47       1.1   tsutsui #define UDL_EVCNT_INCR(ev)	do {} while (/* CONSTCOND */ 0)
     48       1.1   tsutsui #endif
     49       1.1   tsutsui 
     50       1.1   tsutsui /*
     51       1.1   tsutsui  * Bulk command xfer structure.
     52       1.1   tsutsui  */
     53       1.1   tsutsui #define UDL_CMD_BUFFER_SIZE	(64 * 1024)
     54       1.1   tsutsui #define UDL_CMD_HEADER_SIZE	6
     55       1.1   tsutsui #define UDL_CMD_WIDTH_MAX	256
     56       1.1   tsutsui #define UDL_CMD_DRAW_SIZE(width) \
     57       1.1   tsutsui 				(UDL_CMD_HEADER_SIZE + (width) * 2)
     58       1.1   tsutsui #define UDL_CMD_FILL_SIZE	(UDL_CMD_HEADER_SIZE + 3)
     59       1.1   tsutsui #define UDL_CMD_COPY_SIZE	(UDL_CMD_HEADER_SIZE + 3)
     60       1.1   tsutsui #define UDL_CMD_COMP_WORD_SIZE	4
     61       1.1   tsutsui #define UDL_CMD_COMP_MIN_SIZE	(UDL_CMD_HEADER_SIZE + UDL_CMD_COMP_WORD_SIZE)
     62       1.1   tsutsui #define UDL_CMD_COMP_BLOCK_SIZE	512
     63       1.1   tsutsui #define UDL_CMD_COMP_THRESHOLD \
     64       1.1   tsutsui     (UDL_CMD_BUFFER_SIZE - (UDL_CMD_COMP_BLOCK_SIZE * 2))
     65       1.1   tsutsui 
     66       1.1   tsutsui #define UDL_NCMDQ	32
     67       1.1   tsutsui 
     68       1.1   tsutsui struct udl_cmdq {
     69       1.1   tsutsui 	TAILQ_ENTRY(udl_cmdq)	 cq_chain;
     70       1.1   tsutsui 	struct udl_softc	*cq_sc;
     71  1.1.26.1  jdolecek 	struct usbd_xfer	*cq_xfer;
     72       1.1   tsutsui 	uint8_t			*cq_buf;
     73       1.1   tsutsui };
     74       1.1   tsutsui 
     75       1.1   tsutsui /*
     76       1.1   tsutsui  * Our per device structure.
     77       1.1   tsutsui  */
     78       1.1   tsutsui struct udl_softc {
     79       1.1   tsutsui 	device_t		 sc_dev;
     80  1.1.26.1  jdolecek 	struct usbd_device *	 sc_udev;
     81  1.1.26.1  jdolecek 	struct usbd_interface *	 sc_iface;
     82  1.1.26.1  jdolecek 	struct usbd_pipe *	 sc_tx_pipeh;
     83       1.1   tsutsui 
     84       1.1   tsutsui 	struct udl_cmdq		 sc_cmdq[UDL_NCMDQ];
     85       1.1   tsutsui 	TAILQ_HEAD(udl_cmdq_head, udl_cmdq)	sc_freecmd,
     86       1.1   tsutsui 						sc_xfercmd;
     87       1.1   tsutsui 
     88       1.1   tsutsui 	struct udl_cmdq		*sc_cmd_cur;
     89       1.1   tsutsui 	uint8_t			*sc_cmd_buf;
     90       1.1   tsutsui #define UDL_CMD_BUFINIT(sc)	((sc)->sc_cmd_buf = (sc)->sc_cmd_cur->cq_buf)
     91       1.1   tsutsui #define UDL_CMD_BUFSIZE(sc)	((sc)->sc_cmd_buf - (sc)->sc_cmd_cur->cq_buf)
     92       1.1   tsutsui 	int			 sc_cmd_cblen;
     93       1.1   tsutsui 
     94       1.1   tsutsui 	struct edid_info	 sc_ei;
     95       1.1   tsutsui 	int			 sc_width;
     96       1.1   tsutsui 	int			 sc_height;
     97       1.1   tsutsui 	int			 sc_offscreen;
     98       1.1   tsutsui 	uint8_t			 sc_depth;
     99       1.1   tsutsui 
    100       1.1   tsutsui 	/* wsdisplay glue */
    101       1.1   tsutsui 	struct wsscreen_descr	 sc_defaultscreen;
    102       1.1   tsutsui 	const struct wsscreen_descr	*sc_screens[1];
    103       1.1   tsutsui 	struct wsscreen_list	 sc_screenlist;
    104       1.1   tsutsui 	struct rasops_info	 sc_ri;
    105       1.1   tsutsui 	device_t		 sc_wsdisplay;
    106       1.1   tsutsui 	u_int			 sc_mode;
    107       1.1   tsutsui 	u_int			 sc_blank;
    108       1.1   tsutsui 	uint8_t			 sc_nscreens;
    109       1.1   tsutsui 
    110       1.1   tsutsui 	uint8_t			*sc_fbmem;	/* framebuffer for X11 */
    111  1.1.26.1  jdolecek 	uint8_t			*sc_fbmem_prev;	/* prev. framebuffer */
    112       1.1   tsutsui #define UDL_FBMEM_SIZE(sc) \
    113       1.1   tsutsui     ((sc)->sc_width * (sc)->sc_height * ((sc)->sc_depth / 8))
    114       1.1   tsutsui 
    115       1.1   tsutsui 	uint8_t			*sc_huffman;
    116       1.1   tsutsui 	uint8_t			*sc_huffman_base;
    117       1.1   tsutsui 	size_t			 sc_huffman_size;
    118       1.1   tsutsui 
    119  1.1.26.1  jdolecek 	kcondvar_t		 sc_thread_cv;
    120  1.1.26.1  jdolecek 	kmutex_t		 sc_thread_mtx;
    121  1.1.26.1  jdolecek 	bool			 sc_dying;
    122  1.1.26.1  jdolecek 	bool			 sc_thread_stop;
    123  1.1.26.1  jdolecek 	lwp_t			*sc_thread;
    124  1.1.26.1  jdolecek 
    125       1.1   tsutsui 	kcondvar_t		 sc_cv;
    126       1.1   tsutsui 	kmutex_t		 sc_mtx;
    127       1.1   tsutsui 
    128       1.1   tsutsui #define UDL_DECOMPRDY	(1 << 0)
    129       1.1   tsutsui #define UDL_COMPRDY	(1 << 1)
    130       1.1   tsutsui 	uint32_t		 sc_flags;
    131       1.1   tsutsui #ifdef UDL_EVENT_COUNTERS
    132       1.1   tsutsui 	struct evcnt		 sc_ev_cmdq_get;
    133       1.1   tsutsui 	struct evcnt		 sc_ev_cmdq_put;
    134       1.1   tsutsui 	struct evcnt		 sc_ev_cmdq_wait;
    135       1.1   tsutsui 	struct evcnt		 sc_ev_cmdq_timeout;
    136       1.1   tsutsui #endif
    137       1.1   tsutsui };
    138       1.1   tsutsui 
    139       1.1   tsutsui /*
    140       1.1   tsutsui  * Chip commands.
    141       1.1   tsutsui  */
    142       1.1   tsutsui #define UDL_CTRL_CMD_READ_EDID		0x02
    143       1.1   tsutsui #define UDL_CTRL_CMD_WRITE_1		0x03
    144       1.1   tsutsui #define UDL_CTRL_CMD_READ_1		0x04
    145       1.1   tsutsui #define UDL_CTRL_CMD_READ_STATUS	0x06
    146       1.1   tsutsui #define UDL_CTRL_CMD_SET_KEY		0x12
    147       1.1   tsutsui 
    148       1.1   tsutsui #define UDL_BULK_SOC			0xaf	/* start of command token */
    149       1.1   tsutsui 
    150       1.1   tsutsui #define UDL_BULK_CMD_REG_WRITE_1	0x20	/* write 1 byte to register */
    151       1.1   tsutsui #define UDL_BULK_CMD_EOC		0xa0	/* end of command stack */
    152       1.1   tsutsui #define UDL_BULK_CMD_DECOMP		0xe0	/* send decompression table */
    153       1.1   tsutsui 
    154       1.1   tsutsui #define UDL_BULK_CMD_FB_BASE8		0x60
    155       1.1   tsutsui #define UDL_BULK_CMD_FB_WRITE8		(UDL_BULK_CMD_FB_BASE8 | 0x00)
    156       1.1   tsutsui #define UDL_BULK_CMD_FB_RLE8		(UDL_BULK_CMD_FB_BASE8 | 0x01)
    157       1.1   tsutsui #define UDL_BULK_CMD_FB_COPY8		(UDL_BULK_CMD_FB_BASE8 | 0x02)
    158       1.1   tsutsui #define UDL_BULK_CMD_FB_BASE16		0x68
    159       1.1   tsutsui #define UDL_BULK_CMD_FB_WRITE16		(UDL_BULK_CMD_FB_BASE16 | 0x00)
    160       1.1   tsutsui #define UDL_BULK_CMD_FB_RLE16		(UDL_BULK_CMD_FB_BASE16 | 0x01)
    161       1.1   tsutsui #define UDL_BULK_CMD_FB_COPY16		(UDL_BULK_CMD_FB_BASE16 | 0x02)
    162       1.1   tsutsui #define UDL_BULK_CMD_FB_COMP		0x10
    163       1.1   tsutsui 
    164       1.1   tsutsui /*
    165       1.1   tsutsui  * Chip registers.
    166       1.1   tsutsui  */
    167       1.1   tsutsui #define UDL_REG_COLORDEPTH		0x00
    168       1.1   tsutsui  #define UDL_REG_COLORDEPTH_16		0x00
    169       1.1   tsutsui  #define UDL_REG_COLORDEPTH_24		0x01
    170       1.1   tsutsui #define UDL_REG_XDISPLAYSTART		0x01
    171       1.1   tsutsui #define UDL_REG_XDISPLAYEND		0x03
    172       1.1   tsutsui #define UDL_REG_YDISPLAYSTART		0x05
    173       1.1   tsutsui #define UDL_REG_YDISPLAYEND		0x07
    174       1.1   tsutsui #define UDL_REG_XENDCOUNT		0x09
    175       1.1   tsutsui #define UDL_REG_HSYNCSTART		0x0b
    176       1.1   tsutsui #define UDL_REG_HSYNCEND		0x0d
    177       1.1   tsutsui #define UDL_REG_HPIXELS			0x0f
    178       1.1   tsutsui #define UDL_REG_YENDCOUNT		0x11
    179       1.1   tsutsui #define UDL_REG_VSYNCSTART		0x13
    180       1.1   tsutsui #define UDL_REG_VSYNCEND		0x15
    181       1.1   tsutsui #define UDL_REG_VPIXELS			0x17
    182       1.1   tsutsui #define UDL_REG_PIXELCLOCK5KHZ		0x1b
    183       1.1   tsutsui #define UDL_REG_BLANK			0x1f
    184       1.1   tsutsui  #define UDL_REG_BLANK_OFF		0x00
    185       1.1   tsutsui  #define UDL_REG_BLANK_ON		0x01
    186       1.1   tsutsui #define UDL_REG_ADDR_START16		0x20
    187       1.1   tsutsui #define UDL_REG_ADDR_STRIDE16		0x23
    188       1.1   tsutsui #define UDL_REG_ADDR_START8		0x26
    189       1.1   tsutsui #define UDL_REG_ADDR_STRIDE8		0x29
    190       1.1   tsutsui #define UDL_REG_SYNC			0xff
    191       1.1   tsutsui 
    192       1.1   tsutsui /*
    193       1.1   tsutsui  * Compression.
    194       1.1   tsutsui  */
    195       1.1   tsutsui struct udl_huffman {
    196       1.1   tsutsui 	uint8_t		bit_count;
    197       1.1   tsutsui 	uint8_t		pad[3];
    198       1.1   tsutsui 	uint32_t	bit_pattern;
    199       1.1   tsutsui };
    200       1.1   tsutsui #define UDL_HUFFMAN_RECORD_SIZE		sizeof(struct udl_huffman)
    201       1.1   tsutsui #define UDL_HUFFMAN_RECORDS		(65536 + 1)
    202       1.1   tsutsui #define UDL_HUFFMAN_BASE		(((UDL_HUFFMAN_RECORDS - 1) / 2) * \
    203       1.1   tsutsui 					    UDL_HUFFMAN_RECORD_SIZE)
    204