blob: 7a6b766200f96048db248fe45c1700c0f9826f08 [file] [log] [blame]
/*
* Copyright (C) 2018 Synaptics Incorporated. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND
* SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY
* INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR
* CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE
* OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND
* BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF
* COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT
* DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY
* TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS.
*/
#ifndef __DIAG_USB_H__
#define __DIAG_USB_H__
#define readw(addr) (*(volatile u16 *) (addr))
#define readl(addr) (*(volatile u32 *) (addr))
#define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
#define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
#define EAGAIN 11 /* Try again */
#define ETIMEDOUT 110 /* Connection timed out */
#define debug(x,args...) dbg_printf(PRN_INFO | PRN_BUFFERED,x, ##args)
#define puts(x,args...) dbg_printf(PRN_RES,x, ##args)
#define printf(x,args...) dbg_printf(PRN_RES,x, ##args)
#define RETURN_ON_ERROR(res) {if (res) return res;}
/*----------------------------------------------------------------**
** Chapter 9.4 Standard Device Requests -- all devices **
** See Table 9-3 p. 250 of USB 2.0 spec for combinations **
** of request type bitfields with requests, WVALUE, WINDEX etc. **
**----------------------------------------------------------------*/
/* USB recipients */
#define REQ_TYPE_DEVICE 0x00
#define REQ_TYPE_INTERFACE 0x01
#define REQ_TYPE_ENDPOINT 0x02
#define REQ_TYPE_OTHER 0x03
/* Combine one of the 3 above with one of the following 2 */
/* USB directiions */
#define REQ_TYPE_IN 0x80
#define REQ_TYPE_OUT 0x00
/* Also for class requests set the following bit */
/* USB request types*/
#define REQ_TYPE_STANDARD (0x00 << 5)
#define REQ_TYPE_CLASS (0x01 << 5)
#define REQ_TYPE_VENDOR (0x02 << 5)
#define REQ_TYPE_RESERVED (0x03 << 5)
/* Standard USB requests, see Chapter 9 */
#define REQ_GET_STATUS 0
#define REQ_CLEAR_FEATURE 1
#define REQ_SET_FEATURE 3
#define REQ_SET_ADDRESS 5
#define REQ_GET_DESCRIPTOR 6
#define REQ_SET_DESCRIPTOR 7
#define REQ_GET_CONFIGURATION 8
#define REQ_SET_CONFIGURATION 9
#define REQ_GET_INTERFACE 10
#define REQ_SET_INTERFACE 11
#define REQ_SYNCH_FRAME 12
#define DESCTYPE_DEVICE 0x1
#define DESCTYPE_CONFIG 0x2
#define DESCTYPE_STRING 0x3
#define DESCTYPE_INTERFACE 0x4
#define DESCTYPE_ENDPOINT 0x5
#define DESCTYPE_QUALIFIER 0x6
#define DESCTYPE_OTHER_SPEED 0x7
#define DESCTYPE_INTF_POWER 0x8
#define DESCTYPE_OTG 0x9
/* Sub STORAGE Classes */
#define US_SC_RBC 1 /* Typically, flash devices */
#define US_SC_8020 2 /* CD-ROM */
#define US_SC_QIC 3 /* QIC-157 Tapes */
#define US_SC_UFI 4 /* Floppy */
#define US_SC_8070 5 /* Removable media */
#define US_SC_SCSI 6 /* Transparent */
#define US_SC_MIN US_SC_RBC
#define US_SC_MAX US_SC_SCSI
/* USB types */
#define USB_TYPE_STANDARD (0x00 << 5)
#define USB_TYPE_CLASS (0x01 << 5)
#define USB_TYPE_VENDOR (0x02 << 5)
#define USB_TYPE_RESERVED (0x03 << 5)
/* USB recipients */
#define USB_RECIP_DEVICE 0x00
#define USB_RECIP_INTERFACE 0x01
#define USB_RECIP_ENDPOINT 0x02
#define USB_RECIP_OTHER 0x03
/* USB directions */
#define USB_DIR_OUT 0
#define USB_DIR_IN 0x80
/*
* "pipe" definitions, use unsigned so we can compare reliably, since this
* value is shifted up to bits 30/31.
*/
#define PIPE_ISOCHRONOUS 0U
#define PIPE_INTERRUPT 1U
#define PIPE_CONTROL 2U
#define PIPE_BULK 3U
#define PIPE_DEVEP_MASK 0x0007ff00
/* USB-status codes: */
#define USB_ST_ACTIVE 0x1 /* TD is active */
#define USB_ST_STALLED 0x2 /* TD is stalled */
#define USB_ST_BUF_ERR 0x4 /* buffer error */
#define USB_ST_BABBLE_DET 0x8 /* Babble detected */
#define USB_ST_NAK_REC 0x10 /* NAK Received*/
#define USB_ST_CRC_ERR 0x20 /* CRC/timeout Error */
#define USB_ST_BIT_ERR 0x40 /* Bitstuff error */
#define USB_ST_NOT_PROC 0x80000000L /* Not yet processed */
/*
* BULK only
*/
#define US_BBB_RESET 0xff
#define US_BBB_GET_MAX_LUN 0xfe
#define USB_DMA_MINALIGN 32
/* Everything is aribtrary */
#define USB_ALTSETTINGALLOC 4
#define USB_MAXALTSETTING 128
#define USB_MAX_DEVICE 32
#define USB_MAXCONFIG 8
#define USB_MAXINTERFACES 8
#define USB_MAXENDPOINTS 16
#define USB_MAXCHILDREN 8
#define USB_MAX_HUB 16
#define USB_CNTL_TIMEOUT 100 /* 100ms */
/* Some useful macros to use to create struct usb_device_id */
#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
#define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
/* Match anything, indicates this is a valid entry even if everything is 0 */
#define USB_DEVICE_ID_MATCH_NONE 0x0800
#define USB_DEVICE_ID_MATCH_ALL 0x07ff
#define udelay(n) mydelay_us(n)
#define TIME_SPEED 5
#define mdelay(n) A_F_V(mydelay_us((n)*(200*TIME_SPEED)),mydelay_us((n)*(200*TIME_SPEED)),mydelay_us((n)*TIME_SPEED))
#endif