18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ISP116x register declarations and HCD data structures
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
68c2ecf20Sopenharmony_ci * Portions:
78c2ecf20Sopenharmony_ci * Copyright (C) 2004 Lothar Wassmann
88c2ecf20Sopenharmony_ci * Copyright (C) 2004 Psion Teklogix
98c2ecf20Sopenharmony_ci * Copyright (C) 2004 David Brownell
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* us of 1ms frame */
138c2ecf20Sopenharmony_ci#define  MAX_LOAD_LIMIT		850
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* Full speed: max # of bytes to transfer for a single urb
168c2ecf20Sopenharmony_ci   at a time must be < 1024 && must be multiple of 64.
178c2ecf20Sopenharmony_ci   832 allows transferring 4kiB within 5 frames. */
188c2ecf20Sopenharmony_ci#define MAX_TRANSFER_SIZE_FULLSPEED	832
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Low speed: there is no reason to schedule in very big
218c2ecf20Sopenharmony_ci   chunks; often the requested long transfers are for
228c2ecf20Sopenharmony_ci   string descriptors containing short strings. */
238c2ecf20Sopenharmony_ci#define MAX_TRANSFER_SIZE_LOWSPEED	64
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Bytetime (us), a rough indication of how much time it
268c2ecf20Sopenharmony_ci   would take to transfer a byte of useful data over USB */
278c2ecf20Sopenharmony_ci#define BYTE_TIME_FULLSPEED	1
288c2ecf20Sopenharmony_ci#define BYTE_TIME_LOWSPEED	20
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Buffer sizes */
318c2ecf20Sopenharmony_ci#define ISP116x_BUF_SIZE	4096
328c2ecf20Sopenharmony_ci#define ISP116x_ITL_BUFSIZE	0
338c2ecf20Sopenharmony_ci#define ISP116x_ATL_BUFSIZE	((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE))
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define ISP116x_WRITE_OFFSET	0x80
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/*------------ ISP116x registers/bits ------------*/
388c2ecf20Sopenharmony_ci#define	HCREVISION	0x00
398c2ecf20Sopenharmony_ci#define	HCCONTROL	0x01
408c2ecf20Sopenharmony_ci#define		HCCONTROL_HCFS	(3 << 6)	/* host controller
418c2ecf20Sopenharmony_ci						   functional state */
428c2ecf20Sopenharmony_ci#define		HCCONTROL_USB_RESET	(0 << 6)
438c2ecf20Sopenharmony_ci#define		HCCONTROL_USB_RESUME	(1 << 6)
448c2ecf20Sopenharmony_ci#define		HCCONTROL_USB_OPER	(2 << 6)
458c2ecf20Sopenharmony_ci#define		HCCONTROL_USB_SUSPEND	(3 << 6)
468c2ecf20Sopenharmony_ci#define		HCCONTROL_RWC	(1 << 9)	/* remote wakeup connected */
478c2ecf20Sopenharmony_ci#define		HCCONTROL_RWE	(1 << 10)	/* remote wakeup enable */
488c2ecf20Sopenharmony_ci#define	HCCMDSTAT	0x02
498c2ecf20Sopenharmony_ci#define		HCCMDSTAT_HCR	(1 << 0)	/* host controller reset */
508c2ecf20Sopenharmony_ci#define		HCCMDSTAT_SOC	(3 << 16)	/* scheduling overrun count */
518c2ecf20Sopenharmony_ci#define	HCINTSTAT	0x03
528c2ecf20Sopenharmony_ci#define		HCINT_SO	(1 << 0)	/* scheduling overrun */
538c2ecf20Sopenharmony_ci#define		HCINT_WDH	(1 << 1)	/* writeback of done_head */
548c2ecf20Sopenharmony_ci#define		HCINT_SF	(1 << 2)	/* start frame */
558c2ecf20Sopenharmony_ci#define		HCINT_RD	(1 << 3)	/* resume detect */
568c2ecf20Sopenharmony_ci#define		HCINT_UE	(1 << 4)	/* unrecoverable error */
578c2ecf20Sopenharmony_ci#define		HCINT_FNO	(1 << 5)	/* frame number overflow */
588c2ecf20Sopenharmony_ci#define		HCINT_RHSC	(1 << 6)	/* root hub status change */
598c2ecf20Sopenharmony_ci#define		HCINT_OC	(1 << 30)	/* ownership change */
608c2ecf20Sopenharmony_ci#define		HCINT_MIE	(1 << 31)	/* master interrupt enable */
618c2ecf20Sopenharmony_ci#define	HCINTENB	0x04
628c2ecf20Sopenharmony_ci#define	HCINTDIS	0x05
638c2ecf20Sopenharmony_ci#define	HCFMINTVL	0x0d
648c2ecf20Sopenharmony_ci#define	HCFMREM		0x0e
658c2ecf20Sopenharmony_ci#define	HCFMNUM		0x0f
668c2ecf20Sopenharmony_ci#define	HCLSTHRESH	0x11
678c2ecf20Sopenharmony_ci#define	HCRHDESCA	0x12
688c2ecf20Sopenharmony_ci#define		RH_A_NDP	(0x3 << 0)	/* # downstream ports */
698c2ecf20Sopenharmony_ci#define		RH_A_PSM	(1 << 8)	/* power switching mode */
708c2ecf20Sopenharmony_ci#define		RH_A_NPS	(1 << 9)	/* no power switching */
718c2ecf20Sopenharmony_ci#define		RH_A_DT		(1 << 10)	/* device type (mbz) */
728c2ecf20Sopenharmony_ci#define		RH_A_OCPM	(1 << 11)	/* overcurrent protection
738c2ecf20Sopenharmony_ci						   mode */
748c2ecf20Sopenharmony_ci#define		RH_A_NOCP	(1 << 12)	/* no overcurrent protection */
758c2ecf20Sopenharmony_ci#define		RH_A_POTPGT	(0xff << 24)	/* power on -> power good
768c2ecf20Sopenharmony_ci						   time */
778c2ecf20Sopenharmony_ci#define	HCRHDESCB	0x13
788c2ecf20Sopenharmony_ci#define		RH_B_DR		(0xffff << 0)	/* device removable flags */
798c2ecf20Sopenharmony_ci#define		RH_B_PPCM	(0xffff << 16)	/* port power control mask */
808c2ecf20Sopenharmony_ci#define	HCRHSTATUS	0x14
818c2ecf20Sopenharmony_ci#define		RH_HS_LPS	(1 << 0)	/* local power status */
828c2ecf20Sopenharmony_ci#define		RH_HS_OCI	(1 << 1)	/* over current indicator */
838c2ecf20Sopenharmony_ci#define		RH_HS_DRWE	(1 << 15)	/* device remote wakeup
848c2ecf20Sopenharmony_ci						   enable */
858c2ecf20Sopenharmony_ci#define		RH_HS_LPSC	(1 << 16)	/* local power status change */
868c2ecf20Sopenharmony_ci#define		RH_HS_OCIC	(1 << 17)	/* over current indicator
878c2ecf20Sopenharmony_ci						   change */
888c2ecf20Sopenharmony_ci#define		RH_HS_CRWE	(1 << 31)	/* clear remote wakeup
898c2ecf20Sopenharmony_ci						   enable */
908c2ecf20Sopenharmony_ci#define	HCRHPORT1	0x15
918c2ecf20Sopenharmony_ci#define		RH_PS_CCS	(1 << 0)	/* current connect status */
928c2ecf20Sopenharmony_ci#define		RH_PS_PES	(1 << 1)	/* port enable status */
938c2ecf20Sopenharmony_ci#define		RH_PS_PSS	(1 << 2)	/* port suspend status */
948c2ecf20Sopenharmony_ci#define		RH_PS_POCI	(1 << 3)	/* port over current
958c2ecf20Sopenharmony_ci						   indicator */
968c2ecf20Sopenharmony_ci#define		RH_PS_PRS	(1 << 4)	/* port reset status */
978c2ecf20Sopenharmony_ci#define		RH_PS_PPS	(1 << 8)	/* port power status */
988c2ecf20Sopenharmony_ci#define		RH_PS_LSDA	(1 << 9)	/* low speed device attached */
998c2ecf20Sopenharmony_ci#define		RH_PS_CSC	(1 << 16)	/* connect status change */
1008c2ecf20Sopenharmony_ci#define		RH_PS_PESC	(1 << 17)	/* port enable status change */
1018c2ecf20Sopenharmony_ci#define		RH_PS_PSSC	(1 << 18)	/* port suspend status
1028c2ecf20Sopenharmony_ci						   change */
1038c2ecf20Sopenharmony_ci#define		RH_PS_OCIC	(1 << 19)	/* over current indicator
1048c2ecf20Sopenharmony_ci						   change */
1058c2ecf20Sopenharmony_ci#define		RH_PS_PRSC	(1 << 20)	/* port reset status change */
1068c2ecf20Sopenharmony_ci#define		HCRHPORT_CLRMASK	(0x1f << 16)
1078c2ecf20Sopenharmony_ci#define	HCRHPORT2	0x16
1088c2ecf20Sopenharmony_ci#define	HCHWCFG		0x20
1098c2ecf20Sopenharmony_ci#define		HCHWCFG_15KRSEL		(1 << 12)
1108c2ecf20Sopenharmony_ci#define		HCHWCFG_CLKNOTSTOP	(1 << 11)
1118c2ecf20Sopenharmony_ci#define		HCHWCFG_ANALOG_OC	(1 << 10)
1128c2ecf20Sopenharmony_ci#define		HCHWCFG_DACK_MODE	(1 << 8)
1138c2ecf20Sopenharmony_ci#define		HCHWCFG_EOT_POL		(1 << 7)
1148c2ecf20Sopenharmony_ci#define		HCHWCFG_DACK_POL	(1 << 6)
1158c2ecf20Sopenharmony_ci#define		HCHWCFG_DREQ_POL	(1 << 5)
1168c2ecf20Sopenharmony_ci#define		HCHWCFG_DBWIDTH_MASK	(0x03 << 3)
1178c2ecf20Sopenharmony_ci#define		HCHWCFG_DBWIDTH(n)	(((n) << 3) & HCHWCFG_DBWIDTH_MASK)
1188c2ecf20Sopenharmony_ci#define		HCHWCFG_INT_POL		(1 << 2)
1198c2ecf20Sopenharmony_ci#define		HCHWCFG_INT_TRIGGER	(1 << 1)
1208c2ecf20Sopenharmony_ci#define		HCHWCFG_INT_ENABLE	(1 << 0)
1218c2ecf20Sopenharmony_ci#define	HCDMACFG	0x21
1228c2ecf20Sopenharmony_ci#define		HCDMACFG_BURST_LEN_MASK	(0x03 << 5)
1238c2ecf20Sopenharmony_ci#define		HCDMACFG_BURST_LEN(n)	(((n) << 5) & HCDMACFG_BURST_LEN_MASK)
1248c2ecf20Sopenharmony_ci#define		HCDMACFG_BURST_LEN_1	HCDMACFG_BURST_LEN(0)
1258c2ecf20Sopenharmony_ci#define		HCDMACFG_BURST_LEN_4	HCDMACFG_BURST_LEN(1)
1268c2ecf20Sopenharmony_ci#define		HCDMACFG_BURST_LEN_8	HCDMACFG_BURST_LEN(2)
1278c2ecf20Sopenharmony_ci#define		HCDMACFG_DMA_ENABLE	(1 << 4)
1288c2ecf20Sopenharmony_ci#define		HCDMACFG_BUF_TYPE_MASK	(0x07 << 1)
1298c2ecf20Sopenharmony_ci#define		HCDMACFG_CTR_SEL	(1 << 2)
1308c2ecf20Sopenharmony_ci#define		HCDMACFG_ITLATL_SEL	(1 << 1)
1318c2ecf20Sopenharmony_ci#define		HCDMACFG_DMA_RW_SELECT	(1 << 0)
1328c2ecf20Sopenharmony_ci#define	HCXFERCTR	0x22
1338c2ecf20Sopenharmony_ci#define	HCuPINT		0x24
1348c2ecf20Sopenharmony_ci#define		HCuPINT_SOF		(1 << 0)
1358c2ecf20Sopenharmony_ci#define		HCuPINT_ATL		(1 << 1)
1368c2ecf20Sopenharmony_ci#define		HCuPINT_AIIEOT		(1 << 2)
1378c2ecf20Sopenharmony_ci#define		HCuPINT_OPR		(1 << 4)
1388c2ecf20Sopenharmony_ci#define		HCuPINT_SUSP		(1 << 5)
1398c2ecf20Sopenharmony_ci#define		HCuPINT_CLKRDY		(1 << 6)
1408c2ecf20Sopenharmony_ci#define	HCuPINTENB	0x25
1418c2ecf20Sopenharmony_ci#define	HCCHIPID	0x27
1428c2ecf20Sopenharmony_ci#define		HCCHIPID_MASK		0xff00
1438c2ecf20Sopenharmony_ci#define		HCCHIPID_MAGIC		0x6100
1448c2ecf20Sopenharmony_ci#define	HCSCRATCH	0x28
1458c2ecf20Sopenharmony_ci#define	HCSWRES		0x29
1468c2ecf20Sopenharmony_ci#define		HCSWRES_MAGIC		0x00f6
1478c2ecf20Sopenharmony_ci#define	HCITLBUFLEN	0x2a
1488c2ecf20Sopenharmony_ci#define	HCATLBUFLEN	0x2b
1498c2ecf20Sopenharmony_ci#define	HCBUFSTAT	0x2c
1508c2ecf20Sopenharmony_ci#define		HCBUFSTAT_ITL0_FULL	(1 << 0)
1518c2ecf20Sopenharmony_ci#define		HCBUFSTAT_ITL1_FULL	(1 << 1)
1528c2ecf20Sopenharmony_ci#define		HCBUFSTAT_ATL_FULL	(1 << 2)
1538c2ecf20Sopenharmony_ci#define		HCBUFSTAT_ITL0_DONE	(1 << 3)
1548c2ecf20Sopenharmony_ci#define		HCBUFSTAT_ITL1_DONE	(1 << 4)
1558c2ecf20Sopenharmony_ci#define		HCBUFSTAT_ATL_DONE	(1 << 5)
1568c2ecf20Sopenharmony_ci#define	HCRDITL0LEN	0x2d
1578c2ecf20Sopenharmony_ci#define	HCRDITL1LEN	0x2e
1588c2ecf20Sopenharmony_ci#define	HCITLPORT	0x40
1598c2ecf20Sopenharmony_ci#define	HCATLPORT	0x41
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* Philips transfer descriptor */
1628c2ecf20Sopenharmony_cistruct ptd {
1638c2ecf20Sopenharmony_ci	u16 count;
1648c2ecf20Sopenharmony_ci#define	PTD_COUNT_MSK	(0x3ff << 0)
1658c2ecf20Sopenharmony_ci#define	PTD_TOGGLE_MSK	(1 << 10)
1668c2ecf20Sopenharmony_ci#define	PTD_ACTIVE_MSK	(1 << 11)
1678c2ecf20Sopenharmony_ci#define	PTD_CC_MSK	(0xf << 12)
1688c2ecf20Sopenharmony_ci	u16 mps;
1698c2ecf20Sopenharmony_ci#define	PTD_MPS_MSK	(0x3ff << 0)
1708c2ecf20Sopenharmony_ci#define	PTD_SPD_MSK	(1 << 10)
1718c2ecf20Sopenharmony_ci#define	PTD_LAST_MSK	(1 << 11)
1728c2ecf20Sopenharmony_ci#define	PTD_EP_MSK	(0xf << 12)
1738c2ecf20Sopenharmony_ci	u16 len;
1748c2ecf20Sopenharmony_ci#define	PTD_LEN_MSK	(0x3ff << 0)
1758c2ecf20Sopenharmony_ci#define	PTD_DIR_MSK	(3 << 10)
1768c2ecf20Sopenharmony_ci#define	PTD_DIR_SETUP	(0)
1778c2ecf20Sopenharmony_ci#define	PTD_DIR_OUT	(1)
1788c2ecf20Sopenharmony_ci#define	PTD_DIR_IN	(2)
1798c2ecf20Sopenharmony_ci#define	PTD_B5_5_MSK	(1 << 13)
1808c2ecf20Sopenharmony_ci	u16 faddr;
1818c2ecf20Sopenharmony_ci#define	PTD_FA_MSK	(0x7f << 0)
1828c2ecf20Sopenharmony_ci#define	PTD_FMT_MSK	(1 << 7)
1838c2ecf20Sopenharmony_ci} __attribute__ ((packed, aligned(2)));
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/* PTD accessor macros. */
1868c2ecf20Sopenharmony_ci#define PTD_GET_COUNT(p)	(((p)->count & PTD_COUNT_MSK) >> 0)
1878c2ecf20Sopenharmony_ci#define PTD_COUNT(v)		(((v) << 0) & PTD_COUNT_MSK)
1888c2ecf20Sopenharmony_ci#define PTD_GET_TOGGLE(p)	(((p)->count & PTD_TOGGLE_MSK) >> 10)
1898c2ecf20Sopenharmony_ci#define PTD_TOGGLE(v)		(((v) << 10) & PTD_TOGGLE_MSK)
1908c2ecf20Sopenharmony_ci#define PTD_GET_ACTIVE(p)	(((p)->count & PTD_ACTIVE_MSK) >> 11)
1918c2ecf20Sopenharmony_ci#define PTD_ACTIVE(v)		(((v) << 11) & PTD_ACTIVE_MSK)
1928c2ecf20Sopenharmony_ci#define PTD_GET_CC(p)		(((p)->count & PTD_CC_MSK) >> 12)
1938c2ecf20Sopenharmony_ci#define PTD_CC(v)		(((v) << 12) & PTD_CC_MSK)
1948c2ecf20Sopenharmony_ci#define PTD_GET_MPS(p)		(((p)->mps & PTD_MPS_MSK) >> 0)
1958c2ecf20Sopenharmony_ci#define PTD_MPS(v)		(((v) << 0) & PTD_MPS_MSK)
1968c2ecf20Sopenharmony_ci#define PTD_GET_SPD(p)		(((p)->mps & PTD_SPD_MSK) >> 10)
1978c2ecf20Sopenharmony_ci#define PTD_SPD(v)		(((v) << 10) & PTD_SPD_MSK)
1988c2ecf20Sopenharmony_ci#define PTD_GET_LAST(p)		(((p)->mps & PTD_LAST_MSK) >> 11)
1998c2ecf20Sopenharmony_ci#define PTD_LAST(v)		(((v) << 11) & PTD_LAST_MSK)
2008c2ecf20Sopenharmony_ci#define PTD_GET_EP(p)		(((p)->mps & PTD_EP_MSK) >> 12)
2018c2ecf20Sopenharmony_ci#define PTD_EP(v)		(((v) << 12) & PTD_EP_MSK)
2028c2ecf20Sopenharmony_ci#define PTD_GET_LEN(p)		(((p)->len & PTD_LEN_MSK) >> 0)
2038c2ecf20Sopenharmony_ci#define PTD_LEN(v)		(((v) << 0) & PTD_LEN_MSK)
2048c2ecf20Sopenharmony_ci#define PTD_GET_DIR(p)		(((p)->len & PTD_DIR_MSK) >> 10)
2058c2ecf20Sopenharmony_ci#define PTD_DIR(v)		(((v) << 10) & PTD_DIR_MSK)
2068c2ecf20Sopenharmony_ci#define PTD_GET_B5_5(p)		(((p)->len & PTD_B5_5_MSK) >> 13)
2078c2ecf20Sopenharmony_ci#define PTD_B5_5(v)		(((v) << 13) & PTD_B5_5_MSK)
2088c2ecf20Sopenharmony_ci#define PTD_GET_FA(p)		(((p)->faddr & PTD_FA_MSK) >> 0)
2098c2ecf20Sopenharmony_ci#define PTD_FA(v)		(((v) << 0) & PTD_FA_MSK)
2108c2ecf20Sopenharmony_ci#define PTD_GET_FMT(p)		(((p)->faddr & PTD_FMT_MSK) >> 7)
2118c2ecf20Sopenharmony_ci#define PTD_FMT(v)		(((v) << 7) & PTD_FMT_MSK)
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci/*  Hardware transfer status codes -- CC from ptd->count */
2148c2ecf20Sopenharmony_ci#define TD_CC_NOERROR      0x00
2158c2ecf20Sopenharmony_ci#define TD_CC_CRC          0x01
2168c2ecf20Sopenharmony_ci#define TD_CC_BITSTUFFING  0x02
2178c2ecf20Sopenharmony_ci#define TD_CC_DATATOGGLEM  0x03
2188c2ecf20Sopenharmony_ci#define TD_CC_STALL        0x04
2198c2ecf20Sopenharmony_ci#define TD_DEVNOTRESP      0x05
2208c2ecf20Sopenharmony_ci#define TD_PIDCHECKFAIL    0x06
2218c2ecf20Sopenharmony_ci#define TD_UNEXPECTEDPID   0x07
2228c2ecf20Sopenharmony_ci#define TD_DATAOVERRUN     0x08
2238c2ecf20Sopenharmony_ci#define TD_DATAUNDERRUN    0x09
2248c2ecf20Sopenharmony_ci    /* 0x0A, 0x0B reserved for hardware */
2258c2ecf20Sopenharmony_ci#define TD_BUFFEROVERRUN   0x0C
2268c2ecf20Sopenharmony_ci#define TD_BUFFERUNDERRUN  0x0D
2278c2ecf20Sopenharmony_ci    /* 0x0E, 0x0F reserved for HCD */
2288c2ecf20Sopenharmony_ci#define TD_NOTACCESSED     0x0F
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci/* map PTD status codes (CC) to errno values */
2318c2ecf20Sopenharmony_cistatic const int cc_to_error[16] = {
2328c2ecf20Sopenharmony_ci	/* No  Error  */ 0,
2338c2ecf20Sopenharmony_ci	/* CRC Error  */ -EILSEQ,
2348c2ecf20Sopenharmony_ci	/* Bit Stuff  */ -EPROTO,
2358c2ecf20Sopenharmony_ci	/* Data Togg  */ -EILSEQ,
2368c2ecf20Sopenharmony_ci	/* Stall      */ -EPIPE,
2378c2ecf20Sopenharmony_ci	/* DevNotResp */ -ETIME,
2388c2ecf20Sopenharmony_ci	/* PIDCheck   */ -EPROTO,
2398c2ecf20Sopenharmony_ci	/* UnExpPID   */ -EPROTO,
2408c2ecf20Sopenharmony_ci	/* DataOver   */ -EOVERFLOW,
2418c2ecf20Sopenharmony_ci	/* DataUnder  */ -EREMOTEIO,
2428c2ecf20Sopenharmony_ci	/* (for hw)   */ -EIO,
2438c2ecf20Sopenharmony_ci	/* (for hw)   */ -EIO,
2448c2ecf20Sopenharmony_ci	/* BufferOver */ -ECOMM,
2458c2ecf20Sopenharmony_ci	/* BuffUnder  */ -ENOSR,
2468c2ecf20Sopenharmony_ci	/* (for HCD)  */ -EALREADY,
2478c2ecf20Sopenharmony_ci	/* (for HCD)  */ -EALREADY
2488c2ecf20Sopenharmony_ci};
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/*--------------------------------------------------------------*/
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci#define	LOG2_PERIODIC_SIZE	5	/* arbitrary; this matches OHCI */
2538c2ecf20Sopenharmony_ci#define	PERIODIC_SIZE		(1 << LOG2_PERIODIC_SIZE)
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistruct isp116x {
2568c2ecf20Sopenharmony_ci	spinlock_t lock;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	void __iomem *addr_reg;
2598c2ecf20Sopenharmony_ci	void __iomem *data_reg;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	struct isp116x_platform_data *board;
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	struct dentry *dentry;
2648c2ecf20Sopenharmony_ci	unsigned long stat1, stat2, stat4, stat8, stat16;
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	/* HC registers */
2678c2ecf20Sopenharmony_ci	u32 intenb;		/* "OHCI" interrupts */
2688c2ecf20Sopenharmony_ci	u16 irqenb;		/* uP interrupts */
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/* Root hub registers */
2718c2ecf20Sopenharmony_ci	u32 rhdesca;
2728c2ecf20Sopenharmony_ci	u32 rhdescb;
2738c2ecf20Sopenharmony_ci	u32 rhstatus;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	/* async schedule: control, bulk */
2768c2ecf20Sopenharmony_ci	struct list_head async;
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	/* periodic schedule: int */
2798c2ecf20Sopenharmony_ci	u16 load[PERIODIC_SIZE];
2808c2ecf20Sopenharmony_ci	struct isp116x_ep *periodic[PERIODIC_SIZE];
2818c2ecf20Sopenharmony_ci	unsigned periodic_count;
2828c2ecf20Sopenharmony_ci	u16 fmindex;
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci	/* Schedule for the current frame */
2858c2ecf20Sopenharmony_ci	struct isp116x_ep *atl_active;
2868c2ecf20Sopenharmony_ci	int atl_buflen;
2878c2ecf20Sopenharmony_ci	int atl_bufshrt;
2888c2ecf20Sopenharmony_ci	int atl_last_dir;
2898c2ecf20Sopenharmony_ci	atomic_t atl_finishing;
2908c2ecf20Sopenharmony_ci};
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic inline struct isp116x *hcd_to_isp116x(struct usb_hcd *hcd)
2938c2ecf20Sopenharmony_ci{
2948c2ecf20Sopenharmony_ci	return (struct isp116x *)(hcd->hcd_priv);
2958c2ecf20Sopenharmony_ci}
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistatic inline struct usb_hcd *isp116x_to_hcd(struct isp116x *isp116x)
2988c2ecf20Sopenharmony_ci{
2998c2ecf20Sopenharmony_ci	return container_of((void *)isp116x, struct usb_hcd, hcd_priv);
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistruct isp116x_ep {
3038c2ecf20Sopenharmony_ci	struct usb_host_endpoint *hep;
3048c2ecf20Sopenharmony_ci	struct usb_device *udev;
3058c2ecf20Sopenharmony_ci	struct ptd ptd;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	u8 maxpacket;
3088c2ecf20Sopenharmony_ci	u8 epnum;
3098c2ecf20Sopenharmony_ci	u8 nextpid;
3108c2ecf20Sopenharmony_ci	u16 error_count;
3118c2ecf20Sopenharmony_ci	u16 length;		/* of current packet */
3128c2ecf20Sopenharmony_ci	unsigned char *data;	/* to databuf */
3138c2ecf20Sopenharmony_ci	/* queue of active EP's (the ones scheduled for the
3148c2ecf20Sopenharmony_ci	   current frame) */
3158c2ecf20Sopenharmony_ci	struct isp116x_ep *active;
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	/* periodic schedule */
3188c2ecf20Sopenharmony_ci	u16 period;
3198c2ecf20Sopenharmony_ci	u16 branch;
3208c2ecf20Sopenharmony_ci	u16 load;
3218c2ecf20Sopenharmony_ci	struct isp116x_ep *next;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	/* async schedule */
3248c2ecf20Sopenharmony_ci	struct list_head schedule;
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/*-------------------------------------------------------------------------*/
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci#define DBG(stuff...)		pr_debug("116x: " stuff)
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci#ifdef VERBOSE
3328c2ecf20Sopenharmony_ci#    define VDBG		DBG
3338c2ecf20Sopenharmony_ci#else
3348c2ecf20Sopenharmony_ci#    define VDBG(stuff...)	do{}while(0)
3358c2ecf20Sopenharmony_ci#endif
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci#define ERR(stuff...)		printk(KERN_ERR "116x: " stuff)
3388c2ecf20Sopenharmony_ci#define WARNING(stuff...)	printk(KERN_WARNING "116x: " stuff)
3398c2ecf20Sopenharmony_ci#define INFO(stuff...)		printk(KERN_INFO "116x: " stuff)
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci/* ------------------------------------------------- */
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci#if defined(USE_PLATFORM_DELAY)
3448c2ecf20Sopenharmony_ci#if defined(USE_NDELAY)
3458c2ecf20Sopenharmony_ci#error USE_PLATFORM_DELAY and USE_NDELAY simultaneously defined.
3468c2ecf20Sopenharmony_ci#endif
3478c2ecf20Sopenharmony_ci#define	isp116x_delay(h,d)	(h)->board->delay(	\
3488c2ecf20Sopenharmony_ci				isp116x_to_hcd(h)->self.controller,d)
3498c2ecf20Sopenharmony_ci#define isp116x_check_platform_delay(h)	((h)->board->delay == NULL)
3508c2ecf20Sopenharmony_ci#elif defined(USE_NDELAY)
3518c2ecf20Sopenharmony_ci#define	isp116x_delay(h,d)	ndelay(d)
3528c2ecf20Sopenharmony_ci#define isp116x_check_platform_delay(h)	0
3538c2ecf20Sopenharmony_ci#else
3548c2ecf20Sopenharmony_ci#define	isp116x_delay(h,d)	do{}while(0)
3558c2ecf20Sopenharmony_ci#define isp116x_check_platform_delay(h)	0
3568c2ecf20Sopenharmony_ci#endif
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_cistatic inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	writew(reg & 0xff, isp116x->addr_reg);
3618c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 300);
3628c2ecf20Sopenharmony_ci}
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistatic inline void isp116x_write_data16(struct isp116x *isp116x, u16 val)
3658c2ecf20Sopenharmony_ci{
3668c2ecf20Sopenharmony_ci	writew(val, isp116x->data_reg);
3678c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
3688c2ecf20Sopenharmony_ci}
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cistatic inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	__raw_writew(val, isp116x->data_reg);
3738c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
3748c2ecf20Sopenharmony_ci}
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistatic inline u16 isp116x_read_data16(struct isp116x *isp116x)
3778c2ecf20Sopenharmony_ci{
3788c2ecf20Sopenharmony_ci	u16 val;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	val = readw(isp116x->data_reg);
3818c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
3828c2ecf20Sopenharmony_ci	return val;
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic inline u16 isp116x_raw_read_data16(struct isp116x *isp116x)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	u16 val;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	val = __raw_readw(isp116x->data_reg);
3908c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
3918c2ecf20Sopenharmony_ci	return val;
3928c2ecf20Sopenharmony_ci}
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_cistatic inline void isp116x_write_data32(struct isp116x *isp116x, u32 val)
3958c2ecf20Sopenharmony_ci{
3968c2ecf20Sopenharmony_ci	writew(val & 0xffff, isp116x->data_reg);
3978c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
3988c2ecf20Sopenharmony_ci	writew(val >> 16, isp116x->data_reg);
3998c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
4008c2ecf20Sopenharmony_ci}
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_cistatic inline u32 isp116x_read_data32(struct isp116x *isp116x)
4038c2ecf20Sopenharmony_ci{
4048c2ecf20Sopenharmony_ci	u32 val;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	val = (u32) readw(isp116x->data_reg);
4078c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
4088c2ecf20Sopenharmony_ci	val |= ((u32) readw(isp116x->data_reg)) << 16;
4098c2ecf20Sopenharmony_ci	isp116x_delay(isp116x, 150);
4108c2ecf20Sopenharmony_ci	return val;
4118c2ecf20Sopenharmony_ci}
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci/* Let's keep register access functions out of line. Hint:
4148c2ecf20Sopenharmony_ci   we wait at least 150 ns at every access.
4158c2ecf20Sopenharmony_ci*/
4168c2ecf20Sopenharmony_cistatic u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg)
4178c2ecf20Sopenharmony_ci{
4188c2ecf20Sopenharmony_ci	isp116x_write_addr(isp116x, reg);
4198c2ecf20Sopenharmony_ci	return isp116x_read_data16(isp116x);
4208c2ecf20Sopenharmony_ci}
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_cistatic u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg)
4238c2ecf20Sopenharmony_ci{
4248c2ecf20Sopenharmony_ci	isp116x_write_addr(isp116x, reg);
4258c2ecf20Sopenharmony_ci	return isp116x_read_data32(isp116x);
4268c2ecf20Sopenharmony_ci}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_cistatic void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg,
4298c2ecf20Sopenharmony_ci				unsigned val)
4308c2ecf20Sopenharmony_ci{
4318c2ecf20Sopenharmony_ci	isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
4328c2ecf20Sopenharmony_ci	isp116x_write_data16(isp116x, (u16) (val & 0xffff));
4338c2ecf20Sopenharmony_ci}
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_cistatic void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg,
4368c2ecf20Sopenharmony_ci				unsigned val)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
4398c2ecf20Sopenharmony_ci	isp116x_write_data32(isp116x, (u32) val);
4408c2ecf20Sopenharmony_ci}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci#define isp116x_show_reg_log(d,r,s) {				\
4438c2ecf20Sopenharmony_ci	if ((r) < 0x20) {			                \
4448c2ecf20Sopenharmony_ci		DBG("%-12s[%02x]: %08x\n", #r,			\
4458c2ecf20Sopenharmony_ci			r, isp116x_read_reg32(d, r));		\
4468c2ecf20Sopenharmony_ci	} else {						\
4478c2ecf20Sopenharmony_ci		DBG("%-12s[%02x]:     %04x\n", #r,		\
4488c2ecf20Sopenharmony_ci			r, isp116x_read_reg16(d, r));	    	\
4498c2ecf20Sopenharmony_ci	}							\
4508c2ecf20Sopenharmony_ci}
4518c2ecf20Sopenharmony_ci#define isp116x_show_reg_seq(d,r,s) {				\
4528c2ecf20Sopenharmony_ci	if ((r) < 0x20) {					\
4538c2ecf20Sopenharmony_ci		seq_printf(s, "%-12s[%02x]: %08x\n", #r,	\
4548c2ecf20Sopenharmony_ci			r, isp116x_read_reg32(d, r));		\
4558c2ecf20Sopenharmony_ci	} else {						\
4568c2ecf20Sopenharmony_ci		seq_printf(s, "%-12s[%02x]:     %04x\n", #r,	\
4578c2ecf20Sopenharmony_ci			r, isp116x_read_reg16(d, r));		\
4588c2ecf20Sopenharmony_ci	}							\
4598c2ecf20Sopenharmony_ci}
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci#define isp116x_show_regs(d,type,s) {			\
4628c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCREVISION, s);	\
4638c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCCONTROL, s);	\
4648c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCCMDSTAT, s);	\
4658c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCINTSTAT, s);	\
4668c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCINTENB, s);	\
4678c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCFMINTVL, s);	\
4688c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCFMREM, s);		\
4698c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCFMNUM, s);		\
4708c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCLSTHRESH, s);	\
4718c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRHDESCA, s);	\
4728c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRHDESCB, s);	\
4738c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRHSTATUS, s);	\
4748c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRHPORT1, s);	\
4758c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRHPORT2, s);	\
4768c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCHWCFG, s);		\
4778c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCDMACFG, s);	\
4788c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCXFERCTR, s);	\
4798c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCuPINT, s);		\
4808c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCuPINTENB, s);	\
4818c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCCHIPID, s);	\
4828c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCSCRATCH, s);	\
4838c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCITLBUFLEN, s);	\
4848c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCATLBUFLEN, s);	\
4858c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCBUFSTAT, s);	\
4868c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRDITL0LEN, s);	\
4878c2ecf20Sopenharmony_ci	isp116x_show_reg_##type(d, HCRDITL1LEN, s);	\
4888c2ecf20Sopenharmony_ci}
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci/*
4918c2ecf20Sopenharmony_ci   Dump registers for debugfs.
4928c2ecf20Sopenharmony_ci*/
4938c2ecf20Sopenharmony_cistatic inline void isp116x_show_regs_seq(struct isp116x *isp116x,
4948c2ecf20Sopenharmony_ci					  struct seq_file *s)
4958c2ecf20Sopenharmony_ci{
4968c2ecf20Sopenharmony_ci	isp116x_show_regs(isp116x, seq, s);
4978c2ecf20Sopenharmony_ci}
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci/*
5008c2ecf20Sopenharmony_ci   Dump registers to syslog.
5018c2ecf20Sopenharmony_ci*/
5028c2ecf20Sopenharmony_cistatic inline void isp116x_show_regs_log(struct isp116x *isp116x)
5038c2ecf20Sopenharmony_ci{
5048c2ecf20Sopenharmony_ci	isp116x_show_regs(isp116x, log, NULL);
5058c2ecf20Sopenharmony_ci}
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci#if defined(URB_TRACE)
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci#define PIPETYPE(pipe)  ({ char *__s;			\
5108c2ecf20Sopenharmony_ci	if (usb_pipecontrol(pipe))	__s = "ctrl";	\
5118c2ecf20Sopenharmony_ci	else if (usb_pipeint(pipe))	__s = "int";	\
5128c2ecf20Sopenharmony_ci	else if (usb_pipebulk(pipe))	__s = "bulk";	\
5138c2ecf20Sopenharmony_ci	else				__s = "iso";	\
5148c2ecf20Sopenharmony_ci	__s;})
5158c2ecf20Sopenharmony_ci#define PIPEDIR(pipe)   ({ usb_pipein(pipe) ? "in" : "out"; })
5168c2ecf20Sopenharmony_ci#define URB_NOTSHORT(urb) ({ (urb)->transfer_flags & URB_SHORT_NOT_OK ? \
5178c2ecf20Sopenharmony_ci	"short_not_ok" : ""; })
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci/* print debug info about the URB */
5208c2ecf20Sopenharmony_cistatic void urb_dbg(struct urb *urb, char *msg)
5218c2ecf20Sopenharmony_ci{
5228c2ecf20Sopenharmony_ci	unsigned int pipe;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	if (!urb) {
5258c2ecf20Sopenharmony_ci		DBG("%s: zero urb\n", msg);
5268c2ecf20Sopenharmony_ci		return;
5278c2ecf20Sopenharmony_ci	}
5288c2ecf20Sopenharmony_ci	pipe = urb->pipe;
5298c2ecf20Sopenharmony_ci	DBG("%s: FA %d ep%d%s %s: len %d/%d %s\n", msg,
5308c2ecf20Sopenharmony_ci	    usb_pipedevice(pipe), usb_pipeendpoint(pipe),
5318c2ecf20Sopenharmony_ci	    PIPEDIR(pipe), PIPETYPE(pipe),
5328c2ecf20Sopenharmony_ci	    urb->transfer_buffer_length, urb->actual_length, URB_NOTSHORT(urb));
5338c2ecf20Sopenharmony_ci}
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci#else
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci#define  urb_dbg(urb,msg)   do{}while(0)
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci#endif				/* ! defined(URB_TRACE) */
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci#if defined(PTD_TRACE)
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci#define PTD_DIR_STR(ptd)  ({char __c;		\
5448c2ecf20Sopenharmony_ci	switch(PTD_GET_DIR(ptd)){		\
5458c2ecf20Sopenharmony_ci	case 0:  __c = 's'; break;		\
5468c2ecf20Sopenharmony_ci	case 1:  __c = 'o'; break;		\
5478c2ecf20Sopenharmony_ci	default: __c = 'i'; break;		\
5488c2ecf20Sopenharmony_ci	}; __c;})
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci/*
5518c2ecf20Sopenharmony_ci  Dump PTD info. The code documents the format
5528c2ecf20Sopenharmony_ci  perfectly, right :)
5538c2ecf20Sopenharmony_ci*/
5548c2ecf20Sopenharmony_cistatic inline void dump_ptd(struct ptd *ptd)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	printk(KERN_WARNING "td: %x %d%c%d %d,%d,%d  %x %x%x%x\n",
5578c2ecf20Sopenharmony_ci	       PTD_GET_CC(ptd), PTD_GET_FA(ptd),
5588c2ecf20Sopenharmony_ci	       PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
5598c2ecf20Sopenharmony_ci	       PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
5608c2ecf20Sopenharmony_ci	       PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd),
5618c2ecf20Sopenharmony_ci	       PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));
5628c2ecf20Sopenharmony_ci}
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_cistatic inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf)
5658c2ecf20Sopenharmony_ci{
5668c2ecf20Sopenharmony_ci	int k;
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci	if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
5698c2ecf20Sopenharmony_ci		printk(KERN_WARNING "-> ");
5708c2ecf20Sopenharmony_ci		for (k = 0; k < PTD_GET_LEN(ptd); ++k)
5718c2ecf20Sopenharmony_ci			printk("%02x ", ((u8 *) buf)[k]);
5728c2ecf20Sopenharmony_ci		printk("\n");
5738c2ecf20Sopenharmony_ci	}
5748c2ecf20Sopenharmony_ci}
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_cistatic inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf)
5778c2ecf20Sopenharmony_ci{
5788c2ecf20Sopenharmony_ci	int k;
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
5818c2ecf20Sopenharmony_ci		printk(KERN_WARNING "<- ");
5828c2ecf20Sopenharmony_ci		for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
5838c2ecf20Sopenharmony_ci			printk("%02x ", ((u8 *) buf)[k]);
5848c2ecf20Sopenharmony_ci		printk("\n");
5858c2ecf20Sopenharmony_ci	}
5868c2ecf20Sopenharmony_ci	if (PTD_GET_LAST(ptd))
5878c2ecf20Sopenharmony_ci		printk(KERN_WARNING "-\n");
5888c2ecf20Sopenharmony_ci}
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci#else
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci#define dump_ptd(ptd)               do{}while(0)
5938c2ecf20Sopenharmony_ci#define dump_ptd_in_data(ptd,buf)   do{}while(0)
5948c2ecf20Sopenharmony_ci#define dump_ptd_out_data(ptd,buf)  do{}while(0)
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci#endif				/* ! defined(PTD_TRACE) */
597