162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * sisusb - usb kernel driver for Net2280/SiS315 based USB2VGA dongles 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * If distributed as part of the Linux kernel, this code is licensed under the 862306a36Sopenharmony_ci * terms of the GPL v2. 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * Otherwise, the following license terms apply: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 1362306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 1462306a36Sopenharmony_ci * are met: 1562306a36Sopenharmony_ci * 1) Redistributions of source code must retain the above copyright 1662306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 1762306a36Sopenharmony_ci * 2) Redistributions in binary form must reproduce the above copyright 1862306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 1962306a36Sopenharmony_ci * documentation and/or other materials provided with the distribution. 2062306a36Sopenharmony_ci * 3) The name of the author may not be used to endorse or promote products 2162306a36Sopenharmony_ci * derived from this software without specific prior written permission. 2262306a36Sopenharmony_ci * 2362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR 2462306a36Sopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2562306a36Sopenharmony_ci * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2662306a36Sopenharmony_ci * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2762306a36Sopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2862306a36Sopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2962306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3062306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3162306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3262306a36Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3362306a36Sopenharmony_ci * 3462306a36Sopenharmony_ci * Author: Thomas Winischhofer <thomas@winischhofer.net> 3562306a36Sopenharmony_ci * 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#ifndef _SISUSB_H_ 3962306a36Sopenharmony_ci#define _SISUSB_H_ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#include <linux/mutex.h> 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* Version Information */ 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define SISUSB_VERSION 0 4662306a36Sopenharmony_ci#define SISUSB_REVISION 0 4762306a36Sopenharmony_ci#define SISUSB_PATCHLEVEL 8 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* Include console and mode switching code? */ 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#include <linux/vt_kern.h> 5262306a36Sopenharmony_ci#include "sisusb_struct.h" 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* USB related */ 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define SISUSB_MINOR 133 /* official */ 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci/* Size of the sisusb input/output buffers */ 5962306a36Sopenharmony_ci#define SISUSB_IBUF_SIZE 0x01000 6062306a36Sopenharmony_ci#define SISUSB_OBUF_SIZE 0x10000 /* fixed */ 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define NUMOBUFS 8 /* max number of output buffers/output URBs */ 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci/* About endianness: 6562306a36Sopenharmony_ci * 6662306a36Sopenharmony_ci * 1) I/O ports, PCI config registers. The read/write() 6762306a36Sopenharmony_ci * calls emulate inX/outX. Hence, the data is 6862306a36Sopenharmony_ci * expected/delivered in machine endiannes by this 6962306a36Sopenharmony_ci * driver. 7062306a36Sopenharmony_ci * 2) Video memory. The data is copied 1:1. There is 7162306a36Sopenharmony_ci * no swapping. Ever. This means for userland that 7262306a36Sopenharmony_ci * the data has to be prepared properly. (Hint: 7362306a36Sopenharmony_ci * think graphics data format, command queue, 7462306a36Sopenharmony_ci * hardware cursor.) 7562306a36Sopenharmony_ci * 3) MMIO. Data is copied 1:1. MMIO must be swapped 7662306a36Sopenharmony_ci * properly by userland. 7762306a36Sopenharmony_ci * 7862306a36Sopenharmony_ci */ 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci#ifdef __BIG_ENDIAN 8162306a36Sopenharmony_ci#define SISUSB_CORRECT_ENDIANNESS_PACKET(p) \ 8262306a36Sopenharmony_ci do { \ 8362306a36Sopenharmony_ci p->header = cpu_to_le16(p->header); \ 8462306a36Sopenharmony_ci p->address = cpu_to_le32(p->address); \ 8562306a36Sopenharmony_ci p->data = cpu_to_le32(p->data); \ 8662306a36Sopenharmony_ci } while(0) 8762306a36Sopenharmony_ci#else 8862306a36Sopenharmony_ci#define SISUSB_CORRECT_ENDIANNESS_PACKET(p) 8962306a36Sopenharmony_ci#endif 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cistruct sisusb_usb_data; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_cistruct sisusb_urb_context { /* urb->context for outbound bulk URBs */ 9462306a36Sopenharmony_ci struct sisusb_usb_data *sisusb; 9562306a36Sopenharmony_ci int urbindex; 9662306a36Sopenharmony_ci int *actual_length; 9762306a36Sopenharmony_ci}; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_cistruct sisusb_usb_data { 10062306a36Sopenharmony_ci struct usb_device *sisusb_dev; 10162306a36Sopenharmony_ci struct usb_interface *interface; 10262306a36Sopenharmony_ci struct kref kref; 10362306a36Sopenharmony_ci wait_queue_head_t wait_q; /* for syncind and timeouts */ 10462306a36Sopenharmony_ci struct mutex lock; /* general race avoidance */ 10562306a36Sopenharmony_ci unsigned int ifnum; /* interface number of the USB device */ 10662306a36Sopenharmony_ci int minor; /* minor (for logging clarity) */ 10762306a36Sopenharmony_ci int isopen; /* !=0 if open */ 10862306a36Sopenharmony_ci int present; /* !=0 if device is present on the bus */ 10962306a36Sopenharmony_ci int ready; /* !=0 if device is ready for userland */ 11062306a36Sopenharmony_ci int numobufs; /* number of obufs = number of out urbs */ 11162306a36Sopenharmony_ci char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ 11262306a36Sopenharmony_ci int obufsize, ibufsize; 11362306a36Sopenharmony_ci struct urb *sisurbout[NUMOBUFS]; 11462306a36Sopenharmony_ci struct urb *sisurbin; 11562306a36Sopenharmony_ci unsigned char urbstatus[NUMOBUFS]; 11662306a36Sopenharmony_ci unsigned char completein; 11762306a36Sopenharmony_ci struct sisusb_urb_context urbout_context[NUMOBUFS]; 11862306a36Sopenharmony_ci unsigned long flagb0; 11962306a36Sopenharmony_ci unsigned long vrambase; /* framebuffer base */ 12062306a36Sopenharmony_ci unsigned int vramsize; /* framebuffer size (bytes) */ 12162306a36Sopenharmony_ci unsigned long mmiobase; 12262306a36Sopenharmony_ci unsigned int mmiosize; 12362306a36Sopenharmony_ci unsigned long ioportbase; 12462306a36Sopenharmony_ci unsigned char devinit; /* device initialized? */ 12562306a36Sopenharmony_ci unsigned char gfxinit; /* graphics core initialized? */ 12662306a36Sopenharmony_ci unsigned short chipid, chipvendor; 12762306a36Sopenharmony_ci unsigned short chiprevision; 12862306a36Sopenharmony_ci}; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci#define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref) 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/* USB transport related */ 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/* urbstatus */ 13562306a36Sopenharmony_ci#define SU_URB_BUSY 1 13662306a36Sopenharmony_ci#define SU_URB_ALLOC 2 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/* Endpoints */ 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci#define SISUSB_EP_GFX_IN 0x0e /* gfx std packet out(0e)/in(8e) */ 14162306a36Sopenharmony_ci#define SISUSB_EP_GFX_OUT 0x0e 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define SISUSB_EP_GFX_BULK_OUT 0x01 /* gfx mem bulk out/in */ 14462306a36Sopenharmony_ci#define SISUSB_EP_GFX_BULK_IN 0x02 /* ? 2 is "OUT" ? */ 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci#define SISUSB_EP_GFX_LBULK_OUT 0x03 /* gfx large mem bulk out */ 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci#define SISUSB_EP_UNKNOWN_04 0x04 /* ? 4 is "OUT" ? - unused */ 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci#define SISUSB_EP_BRIDGE_IN 0x0d /* Net2280 out(0d)/in(8d) */ 15162306a36Sopenharmony_ci#define SISUSB_EP_BRIDGE_OUT 0x0d 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci#define SISUSB_TYPE_MEM 0 15462306a36Sopenharmony_ci#define SISUSB_TYPE_IO 1 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_cistruct sisusb_packet { 15762306a36Sopenharmony_ci unsigned short header; 15862306a36Sopenharmony_ci u32 address; 15962306a36Sopenharmony_ci u32 data; 16062306a36Sopenharmony_ci} __attribute__ ((__packed__)); 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define CLEARPACKET(packet) memset(packet, 0, 10) 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci/* PCI bridge related */ 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci#define SISUSB_PCI_MEMBASE 0xd0000000 16762306a36Sopenharmony_ci#define SISUSB_PCI_MMIOBASE 0xe4000000 16862306a36Sopenharmony_ci#define SISUSB_PCI_IOPORTBASE 0x0000d000 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci#define SISUSB_PCI_PSEUDO_MEMBASE 0x10000000 17162306a36Sopenharmony_ci#define SISUSB_PCI_PSEUDO_MMIOBASE 0x20000000 17262306a36Sopenharmony_ci#define SISUSB_PCI_PSEUDO_IOPORTBASE 0x0000d000 17362306a36Sopenharmony_ci#define SISUSB_PCI_PSEUDO_PCIBASE 0x00010000 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci#define SISUSB_PCI_MMIOSIZE (128*1024) 17662306a36Sopenharmony_ci#define SISUSB_PCI_PCONFSIZE 0x5c 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* graphics core related */ 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci#define AROFFSET 0x40 18162306a36Sopenharmony_ci#define ARROFFSET 0x41 18262306a36Sopenharmony_ci#define GROFFSET 0x4e 18362306a36Sopenharmony_ci#define SROFFSET 0x44 18462306a36Sopenharmony_ci#define CROFFSET 0x54 18562306a36Sopenharmony_ci#define MISCROFFSET 0x4c 18662306a36Sopenharmony_ci#define MISCWOFFSET 0x42 18762306a36Sopenharmony_ci#define INPUTSTATOFFSET 0x5A 18862306a36Sopenharmony_ci#define PART1OFFSET 0x04 18962306a36Sopenharmony_ci#define PART2OFFSET 0x10 19062306a36Sopenharmony_ci#define PART3OFFSET 0x12 19162306a36Sopenharmony_ci#define PART4OFFSET 0x14 19262306a36Sopenharmony_ci#define PART5OFFSET 0x16 19362306a36Sopenharmony_ci#define CAPTUREOFFSET 0x00 19462306a36Sopenharmony_ci#define VIDEOOFFSET 0x02 19562306a36Sopenharmony_ci#define COLREGOFFSET 0x48 19662306a36Sopenharmony_ci#define PELMASKOFFSET 0x46 19762306a36Sopenharmony_ci#define VGAENABLE 0x43 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#define SISAR SISUSB_PCI_IOPORTBASE + AROFFSET 20062306a36Sopenharmony_ci#define SISARR SISUSB_PCI_IOPORTBASE + ARROFFSET 20162306a36Sopenharmony_ci#define SISGR SISUSB_PCI_IOPORTBASE + GROFFSET 20262306a36Sopenharmony_ci#define SISSR SISUSB_PCI_IOPORTBASE + SROFFSET 20362306a36Sopenharmony_ci#define SISCR SISUSB_PCI_IOPORTBASE + CROFFSET 20462306a36Sopenharmony_ci#define SISMISCR SISUSB_PCI_IOPORTBASE + MISCROFFSET 20562306a36Sopenharmony_ci#define SISMISCW SISUSB_PCI_IOPORTBASE + MISCWOFFSET 20662306a36Sopenharmony_ci#define SISINPSTAT SISUSB_PCI_IOPORTBASE + INPUTSTATOFFSET 20762306a36Sopenharmony_ci#define SISPART1 SISUSB_PCI_IOPORTBASE + PART1OFFSET 20862306a36Sopenharmony_ci#define SISPART2 SISUSB_PCI_IOPORTBASE + PART2OFFSET 20962306a36Sopenharmony_ci#define SISPART3 SISUSB_PCI_IOPORTBASE + PART3OFFSET 21062306a36Sopenharmony_ci#define SISPART4 SISUSB_PCI_IOPORTBASE + PART4OFFSET 21162306a36Sopenharmony_ci#define SISPART5 SISUSB_PCI_IOPORTBASE + PART5OFFSET 21262306a36Sopenharmony_ci#define SISCAP SISUSB_PCI_IOPORTBASE + CAPTUREOFFSET 21362306a36Sopenharmony_ci#define SISVID SISUSB_PCI_IOPORTBASE + VIDEOOFFSET 21462306a36Sopenharmony_ci#define SISCOLIDXR SISUSB_PCI_IOPORTBASE + COLREGOFFSET - 1 21562306a36Sopenharmony_ci#define SISCOLIDX SISUSB_PCI_IOPORTBASE + COLREGOFFSET 21662306a36Sopenharmony_ci#define SISCOLDATA SISUSB_PCI_IOPORTBASE + COLREGOFFSET + 1 21762306a36Sopenharmony_ci#define SISCOL2IDX SISPART5 21862306a36Sopenharmony_ci#define SISCOL2DATA SISPART5 + 1 21962306a36Sopenharmony_ci#define SISPEL SISUSB_PCI_IOPORTBASE + PELMASKOFFSET 22062306a36Sopenharmony_ci#define SISVGAEN SISUSB_PCI_IOPORTBASE + VGAENABLE 22162306a36Sopenharmony_ci#define SISDACA SISCOLIDX 22262306a36Sopenharmony_ci#define SISDACD SISCOLDATA 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci/* ioctl related */ 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci/* Structure argument for SISUSB_GET_INFO ioctl */ 22762306a36Sopenharmony_cistruct sisusb_info { 22862306a36Sopenharmony_ci __u32 sisusb_id; /* for identifying sisusb */ 22962306a36Sopenharmony_ci#define SISUSB_ID 0x53495355 /* Identify myself with 'SISU' */ 23062306a36Sopenharmony_ci __u8 sisusb_version; 23162306a36Sopenharmony_ci __u8 sisusb_revision; 23262306a36Sopenharmony_ci __u8 sisusb_patchlevel; 23362306a36Sopenharmony_ci __u8 sisusb_gfxinit; /* graphics core initialized? */ 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci __u32 sisusb_vrambase; 23662306a36Sopenharmony_ci __u32 sisusb_mmiobase; 23762306a36Sopenharmony_ci __u32 sisusb_iobase; 23862306a36Sopenharmony_ci __u32 sisusb_pcibase; 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci __u32 sisusb_vramsize; /* framebuffer size in bytes */ 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci __u32 sisusb_minor; 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci __u32 sisusb_fbdevactive; /* != 0 if framebuffer device active */ 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci __u32 sisusb_conactive; /* != 0 if console driver active */ 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci __u8 sisusb_reserved[28]; /* for future use */ 24962306a36Sopenharmony_ci}; 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_cistruct sisusb_command { 25262306a36Sopenharmony_ci __u8 operation; /* see below */ 25362306a36Sopenharmony_ci __u8 data0; /* operation dependent */ 25462306a36Sopenharmony_ci __u8 data1; /* operation dependent */ 25562306a36Sopenharmony_ci __u8 data2; /* operation dependent */ 25662306a36Sopenharmony_ci __u32 data3; /* operation dependent */ 25762306a36Sopenharmony_ci __u32 data4; /* for future use */ 25862306a36Sopenharmony_ci}; 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci#define SUCMD_GET 0x01 /* for all: data0 = index, data3 = port */ 26162306a36Sopenharmony_ci#define SUCMD_SET 0x02 /* data1 = value */ 26262306a36Sopenharmony_ci#define SUCMD_SETOR 0x03 /* data1 = or */ 26362306a36Sopenharmony_ci#define SUCMD_SETAND 0x04 /* data1 = and */ 26462306a36Sopenharmony_ci#define SUCMD_SETANDOR 0x05 /* data1 = and, data2 = or */ 26562306a36Sopenharmony_ci#define SUCMD_SETMASK 0x06 /* data1 = data, data2 = mask */ 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci#define SUCMD_CLRSCR 0x07 /* data0:1:2 = length, data3 = address */ 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci#define SUCMD_HANDLETEXTMODE 0x08 /* Reset/destroy text mode */ 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci#define SUCMD_SETMODE 0x09 /* Set a display mode (data3 = SiS mode) */ 27262306a36Sopenharmony_ci#define SUCMD_SETVESAMODE 0x0a /* Set a display mode (data3 = VESA mode) */ 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci#define SISUSB_COMMAND _IOWR(0xF3,0x3D,struct sisusb_command) 27562306a36Sopenharmony_ci#define SISUSB_GET_CONFIG_SIZE _IOR(0xF3,0x3E,__u32) 27662306a36Sopenharmony_ci#define SISUSB_GET_CONFIG _IOR(0xF3,0x3F,struct sisusb_info) 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci#endif /* SISUSB_H */ 279