xref: /linux/drivers/usb/host/isp116x.h (revision 7c7b971d)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
24808a1c0SOlav Kongas /*
34808a1c0SOlav Kongas  * ISP116x register declarations and HCD data structures
44808a1c0SOlav Kongas  *
54808a1c0SOlav Kongas  * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
64808a1c0SOlav Kongas  * Portions:
74808a1c0SOlav Kongas  * Copyright (C) 2004 Lothar Wassmann
84808a1c0SOlav Kongas  * Copyright (C) 2004 Psion Teklogix
94808a1c0SOlav Kongas  * Copyright (C) 2004 David Brownell
104808a1c0SOlav Kongas  */
114808a1c0SOlav Kongas 
124808a1c0SOlav Kongas /* us of 1ms frame */
134808a1c0SOlav Kongas #define  MAX_LOAD_LIMIT		850
144808a1c0SOlav Kongas 
154808a1c0SOlav Kongas /* Full speed: max # of bytes to transfer for a single urb
164808a1c0SOlav Kongas    at a time must be < 1024 && must be multiple of 64.
1725985edcSLucas De Marchi    832 allows transferring 4kiB within 5 frames. */
184808a1c0SOlav Kongas #define MAX_TRANSFER_SIZE_FULLSPEED	832
194808a1c0SOlav Kongas 
204808a1c0SOlav Kongas /* Low speed: there is no reason to schedule in very big
214808a1c0SOlav Kongas    chunks; often the requested long transfers are for
224808a1c0SOlav Kongas    string descriptors containing short strings. */
234808a1c0SOlav Kongas #define MAX_TRANSFER_SIZE_LOWSPEED	64
244808a1c0SOlav Kongas 
254808a1c0SOlav Kongas /* Bytetime (us), a rough indication of how much time it
264808a1c0SOlav Kongas    would take to transfer a byte of useful data over USB */
274808a1c0SOlav Kongas #define BYTE_TIME_FULLSPEED	1
284808a1c0SOlav Kongas #define BYTE_TIME_LOWSPEED	20
294808a1c0SOlav Kongas 
304808a1c0SOlav Kongas /* Buffer sizes */
314808a1c0SOlav Kongas #define ISP116x_BUF_SIZE	4096
324808a1c0SOlav Kongas #define ISP116x_ITL_BUFSIZE	0
334808a1c0SOlav Kongas #define ISP116x_ATL_BUFSIZE	((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE))
344808a1c0SOlav Kongas 
354808a1c0SOlav Kongas #define ISP116x_WRITE_OFFSET	0x80
364808a1c0SOlav Kongas 
374808a1c0SOlav Kongas /*------------ ISP116x registers/bits ------------*/
384808a1c0SOlav Kongas #define	HCREVISION	0x00
394808a1c0SOlav Kongas #define	HCCONTROL	0x01
404808a1c0SOlav Kongas #define		HCCONTROL_HCFS	(3 << 6)	/* host controller
414808a1c0SOlav Kongas 						   functional state */
424808a1c0SOlav Kongas #define		HCCONTROL_USB_RESET	(0 << 6)
434808a1c0SOlav Kongas #define		HCCONTROL_USB_RESUME	(1 << 6)
444808a1c0SOlav Kongas #define		HCCONTROL_USB_OPER	(2 << 6)
454808a1c0SOlav Kongas #define		HCCONTROL_USB_SUSPEND	(3 << 6)
464808a1c0SOlav Kongas #define		HCCONTROL_RWC	(1 << 9)	/* remote wakeup connected */
474808a1c0SOlav Kongas #define		HCCONTROL_RWE	(1 << 10)	/* remote wakeup enable */
484808a1c0SOlav Kongas #define	HCCMDSTAT	0x02
494808a1c0SOlav Kongas #define		HCCMDSTAT_HCR	(1 << 0)	/* host controller reset */
504808a1c0SOlav Kongas #define		HCCMDSTAT_SOC	(3 << 16)	/* scheduling overrun count */
514808a1c0SOlav Kongas #define	HCINTSTAT	0x03
524808a1c0SOlav Kongas #define		HCINT_SO	(1 << 0)	/* scheduling overrun */
534808a1c0SOlav Kongas #define		HCINT_WDH	(1 << 1)	/* writeback of done_head */
544808a1c0SOlav Kongas #define		HCINT_SF	(1 << 2)	/* start frame */
554808a1c0SOlav Kongas #define		HCINT_RD	(1 << 3)	/* resume detect */
564808a1c0SOlav Kongas #define		HCINT_UE	(1 << 4)	/* unrecoverable error */
574808a1c0SOlav Kongas #define		HCINT_FNO	(1 << 5)	/* frame number overflow */
584808a1c0SOlav Kongas #define		HCINT_RHSC	(1 << 6)	/* root hub status change */
594808a1c0SOlav Kongas #define		HCINT_OC	(1 << 30)	/* ownership change */
604808a1c0SOlav Kongas #define		HCINT_MIE	(1 << 31)	/* master interrupt enable */
614808a1c0SOlav Kongas #define	HCINTENB	0x04
624808a1c0SOlav Kongas #define	HCINTDIS	0x05
634808a1c0SOlav Kongas #define	HCFMINTVL	0x0d
644808a1c0SOlav Kongas #define	HCFMREM		0x0e
654808a1c0SOlav Kongas #define	HCFMNUM		0x0f
664808a1c0SOlav Kongas #define	HCLSTHRESH	0x11
674808a1c0SOlav Kongas #define	HCRHDESCA	0x12
684808a1c0SOlav Kongas #define		RH_A_NDP	(0x3 << 0)	/* # downstream ports */
694808a1c0SOlav Kongas #define		RH_A_PSM	(1 << 8)	/* power switching mode */
704808a1c0SOlav Kongas #define		RH_A_NPS	(1 << 9)	/* no power switching */
714808a1c0SOlav Kongas #define		RH_A_DT		(1 << 10)	/* device type (mbz) */
724808a1c0SOlav Kongas #define		RH_A_OCPM	(1 << 11)	/* overcurrent protection
734808a1c0SOlav Kongas 						   mode */
744808a1c0SOlav Kongas #define		RH_A_NOCP	(1 << 12)	/* no overcurrent protection */
754808a1c0SOlav Kongas #define		RH_A_POTPGT	(0xff << 24)	/* power on -> power good
764808a1c0SOlav Kongas 						   time */
774808a1c0SOlav Kongas #define	HCRHDESCB	0x13
784808a1c0SOlav Kongas #define		RH_B_DR		(0xffff << 0)	/* device removable flags */
794808a1c0SOlav Kongas #define		RH_B_PPCM	(0xffff << 16)	/* port power control mask */
804808a1c0SOlav Kongas #define	HCRHSTATUS	0x14
814808a1c0SOlav Kongas #define		RH_HS_LPS	(1 << 0)	/* local power status */
824808a1c0SOlav Kongas #define		RH_HS_OCI	(1 << 1)	/* over current indicator */
834808a1c0SOlav Kongas #define		RH_HS_DRWE	(1 << 15)	/* device remote wakeup
844808a1c0SOlav Kongas 						   enable */
854808a1c0SOlav Kongas #define		RH_HS_LPSC	(1 << 16)	/* local power status change */
864808a1c0SOlav Kongas #define		RH_HS_OCIC	(1 << 17)	/* over current indicator
874808a1c0SOlav Kongas 						   change */
884808a1c0SOlav Kongas #define		RH_HS_CRWE	(1 << 31)	/* clear remote wakeup
894808a1c0SOlav Kongas 						   enable */
904808a1c0SOlav Kongas #define	HCRHPORT1	0x15
914808a1c0SOlav Kongas #define		RH_PS_CCS	(1 << 0)	/* current connect status */
924808a1c0SOlav Kongas #define		RH_PS_PES	(1 << 1)	/* port enable status */
934808a1c0SOlav Kongas #define		RH_PS_PSS	(1 << 2)	/* port suspend status */
944808a1c0SOlav Kongas #define		RH_PS_POCI	(1 << 3)	/* port over current
954808a1c0SOlav Kongas 						   indicator */
964808a1c0SOlav Kongas #define		RH_PS_PRS	(1 << 4)	/* port reset status */
974808a1c0SOlav Kongas #define		RH_PS_PPS	(1 << 8)	/* port power status */
984808a1c0SOlav Kongas #define		RH_PS_LSDA	(1 << 9)	/* low speed device attached */
994808a1c0SOlav Kongas #define		RH_PS_CSC	(1 << 16)	/* connect status change */
1004808a1c0SOlav Kongas #define		RH_PS_PESC	(1 << 17)	/* port enable status change */
1014808a1c0SOlav Kongas #define		RH_PS_PSSC	(1 << 18)	/* port suspend status
1024808a1c0SOlav Kongas 						   change */
1034808a1c0SOlav Kongas #define		RH_PS_OCIC	(1 << 19)	/* over current indicator
1044808a1c0SOlav Kongas 						   change */
1054808a1c0SOlav Kongas #define		RH_PS_PRSC	(1 << 20)	/* port reset status change */
1064808a1c0SOlav Kongas #define		HCRHPORT_CLRMASK	(0x1f << 16)
1074808a1c0SOlav Kongas #define	HCRHPORT2	0x16
1084808a1c0SOlav Kongas #define	HCHWCFG		0x20
1094808a1c0SOlav Kongas #define		HCHWCFG_15KRSEL		(1 << 12)
1104808a1c0SOlav Kongas #define		HCHWCFG_CLKNOTSTOP	(1 << 11)
1114808a1c0SOlav Kongas #define		HCHWCFG_ANALOG_OC	(1 << 10)
1124808a1c0SOlav Kongas #define		HCHWCFG_DACK_MODE	(1 << 8)
1134808a1c0SOlav Kongas #define		HCHWCFG_EOT_POL		(1 << 7)
1144808a1c0SOlav Kongas #define		HCHWCFG_DACK_POL	(1 << 6)
1154808a1c0SOlav Kongas #define		HCHWCFG_DREQ_POL	(1 << 5)
1164808a1c0SOlav Kongas #define		HCHWCFG_DBWIDTH_MASK	(0x03 << 3)
1174808a1c0SOlav Kongas #define		HCHWCFG_DBWIDTH(n)	(((n) << 3) & HCHWCFG_DBWIDTH_MASK)
1184808a1c0SOlav Kongas #define		HCHWCFG_INT_POL		(1 << 2)
1194808a1c0SOlav Kongas #define		HCHWCFG_INT_TRIGGER	(1 << 1)
1204808a1c0SOlav Kongas #define		HCHWCFG_INT_ENABLE	(1 << 0)
1214808a1c0SOlav Kongas #define	HCDMACFG	0x21
1224808a1c0SOlav Kongas #define		HCDMACFG_BURST_LEN_MASK	(0x03 << 5)
1234808a1c0SOlav Kongas #define		HCDMACFG_BURST_LEN(n)	(((n) << 5) & HCDMACFG_BURST_LEN_MASK)
1244808a1c0SOlav Kongas #define		HCDMACFG_BURST_LEN_1	HCDMACFG_BURST_LEN(0)
1254808a1c0SOlav Kongas #define		HCDMACFG_BURST_LEN_4	HCDMACFG_BURST_LEN(1)
1264808a1c0SOlav Kongas #define		HCDMACFG_BURST_LEN_8	HCDMACFG_BURST_LEN(2)
1274808a1c0SOlav Kongas #define		HCDMACFG_DMA_ENABLE	(1 << 4)
1284808a1c0SOlav Kongas #define		HCDMACFG_BUF_TYPE_MASK	(0x07 << 1)
1294808a1c0SOlav Kongas #define		HCDMACFG_CTR_SEL	(1 << 2)
1304808a1c0SOlav Kongas #define		HCDMACFG_ITLATL_SEL	(1 << 1)
1314808a1c0SOlav Kongas #define		HCDMACFG_DMA_RW_SELECT	(1 << 0)
1324808a1c0SOlav Kongas #define	HCXFERCTR	0x22
1334808a1c0SOlav Kongas #define	HCuPINT		0x24
1344808a1c0SOlav Kongas #define		HCuPINT_SOF		(1 << 0)
1354808a1c0SOlav Kongas #define		HCuPINT_ATL		(1 << 1)
1364808a1c0SOlav Kongas #define		HCuPINT_AIIEOT		(1 << 2)
1374808a1c0SOlav Kongas #define		HCuPINT_OPR		(1 << 4)
1384808a1c0SOlav Kongas #define		HCuPINT_SUSP		(1 << 5)
1394808a1c0SOlav Kongas #define		HCuPINT_CLKRDY		(1 << 6)
1404808a1c0SOlav Kongas #define	HCuPINTENB	0x25
1414808a1c0SOlav Kongas #define	HCCHIPID	0x27
1424808a1c0SOlav Kongas #define		HCCHIPID_MASK		0xff00
1434808a1c0SOlav Kongas #define		HCCHIPID_MAGIC		0x6100
1444808a1c0SOlav Kongas #define	HCSCRATCH	0x28
1454808a1c0SOlav Kongas #define	HCSWRES		0x29
1464808a1c0SOlav Kongas #define		HCSWRES_MAGIC		0x00f6
1474808a1c0SOlav Kongas #define	HCITLBUFLEN	0x2a
1484808a1c0SOlav Kongas #define	HCATLBUFLEN	0x2b
1494808a1c0SOlav Kongas #define	HCBUFSTAT	0x2c
1504808a1c0SOlav Kongas #define		HCBUFSTAT_ITL0_FULL	(1 << 0)
1514808a1c0SOlav Kongas #define		HCBUFSTAT_ITL1_FULL	(1 << 1)
1524808a1c0SOlav Kongas #define		HCBUFSTAT_ATL_FULL	(1 << 2)
1534808a1c0SOlav Kongas #define		HCBUFSTAT_ITL0_DONE	(1 << 3)
1544808a1c0SOlav Kongas #define		HCBUFSTAT_ITL1_DONE	(1 << 4)
1554808a1c0SOlav Kongas #define		HCBUFSTAT_ATL_DONE	(1 << 5)
1564808a1c0SOlav Kongas #define	HCRDITL0LEN	0x2d
1574808a1c0SOlav Kongas #define	HCRDITL1LEN	0x2e
1584808a1c0SOlav Kongas #define	HCITLPORT	0x40
1594808a1c0SOlav Kongas #define	HCATLPORT	0x41
1604808a1c0SOlav Kongas 
1614808a1c0SOlav Kongas /* Philips transfer descriptor */
1624808a1c0SOlav Kongas struct ptd {
1634808a1c0SOlav Kongas 	u16 count;
1644808a1c0SOlav Kongas #define	PTD_COUNT_MSK	(0x3ff << 0)
1654808a1c0SOlav Kongas #define	PTD_TOGGLE_MSK	(1 << 10)
1664808a1c0SOlav Kongas #define	PTD_ACTIVE_MSK	(1 << 11)
1674808a1c0SOlav Kongas #define	PTD_CC_MSK	(0xf << 12)
1684808a1c0SOlav Kongas 	u16 mps;
1694808a1c0SOlav Kongas #define	PTD_MPS_MSK	(0x3ff << 0)
1704808a1c0SOlav Kongas #define	PTD_SPD_MSK	(1 << 10)
1714808a1c0SOlav Kongas #define	PTD_LAST_MSK	(1 << 11)
1724808a1c0SOlav Kongas #define	PTD_EP_MSK	(0xf << 12)
1734808a1c0SOlav Kongas 	u16 len;
1744808a1c0SOlav Kongas #define	PTD_LEN_MSK	(0x3ff << 0)
1754808a1c0SOlav Kongas #define	PTD_DIR_MSK	(3 << 10)
1764808a1c0SOlav Kongas #define	PTD_DIR_SETUP	(0)
1774808a1c0SOlav Kongas #define	PTD_DIR_OUT	(1)
1784808a1c0SOlav Kongas #define	PTD_DIR_IN	(2)
1794808a1c0SOlav Kongas #define	PTD_B5_5_MSK	(1 << 13)
1804808a1c0SOlav Kongas 	u16 faddr;
1814808a1c0SOlav Kongas #define	PTD_FA_MSK	(0x7f << 0)
1824808a1c0SOlav Kongas #define	PTD_FMT_MSK	(1 << 7)
1834808a1c0SOlav Kongas } __attribute__ ((packed, aligned(2)));
1844808a1c0SOlav Kongas 
1854808a1c0SOlav Kongas /* PTD accessor macros. */
1864808a1c0SOlav Kongas #define PTD_GET_COUNT(p)	(((p)->count & PTD_COUNT_MSK) >> 0)
1874808a1c0SOlav Kongas #define PTD_COUNT(v)		(((v) << 0) & PTD_COUNT_MSK)
1884808a1c0SOlav Kongas #define PTD_GET_TOGGLE(p)	(((p)->count & PTD_TOGGLE_MSK) >> 10)
1894808a1c0SOlav Kongas #define PTD_TOGGLE(v)		(((v) << 10) & PTD_TOGGLE_MSK)
1904808a1c0SOlav Kongas #define PTD_GET_ACTIVE(p)	(((p)->count & PTD_ACTIVE_MSK) >> 11)
1914808a1c0SOlav Kongas #define PTD_ACTIVE(v)		(((v) << 11) & PTD_ACTIVE_MSK)
1924808a1c0SOlav Kongas #define PTD_GET_CC(p)		(((p)->count & PTD_CC_MSK) >> 12)
1934808a1c0SOlav Kongas #define PTD_CC(v)		(((v) << 12) & PTD_CC_MSK)
1944808a1c0SOlav Kongas #define PTD_GET_MPS(p)		(((p)->mps & PTD_MPS_MSK) >> 0)
1954808a1c0SOlav Kongas #define PTD_MPS(v)		(((v) << 0) & PTD_MPS_MSK)
1964808a1c0SOlav Kongas #define PTD_GET_SPD(p)		(((p)->mps & PTD_SPD_MSK) >> 10)
1974808a1c0SOlav Kongas #define PTD_SPD(v)		(((v) << 10) & PTD_SPD_MSK)
1984808a1c0SOlav Kongas #define PTD_GET_LAST(p)		(((p)->mps & PTD_LAST_MSK) >> 11)
1994808a1c0SOlav Kongas #define PTD_LAST(v)		(((v) << 11) & PTD_LAST_MSK)
2004808a1c0SOlav Kongas #define PTD_GET_EP(p)		(((p)->mps & PTD_EP_MSK) >> 12)
2014808a1c0SOlav Kongas #define PTD_EP(v)		(((v) << 12) & PTD_EP_MSK)
2024808a1c0SOlav Kongas #define PTD_GET_LEN(p)		(((p)->len & PTD_LEN_MSK) >> 0)
2034808a1c0SOlav Kongas #define PTD_LEN(v)		(((v) << 0) & PTD_LEN_MSK)
2044808a1c0SOlav Kongas #define PTD_GET_DIR(p)		(((p)->len & PTD_DIR_MSK) >> 10)
2054808a1c0SOlav Kongas #define PTD_DIR(v)		(((v) << 10) & PTD_DIR_MSK)
2064808a1c0SOlav Kongas #define PTD_GET_B5_5(p)		(((p)->len & PTD_B5_5_MSK) >> 13)
2074808a1c0SOlav Kongas #define PTD_B5_5(v)		(((v) << 13) & PTD_B5_5_MSK)
2084808a1c0SOlav Kongas #define PTD_GET_FA(p)		(((p)->faddr & PTD_FA_MSK) >> 0)
2094808a1c0SOlav Kongas #define PTD_FA(v)		(((v) << 0) & PTD_FA_MSK)
2104808a1c0SOlav Kongas #define PTD_GET_FMT(p)		(((p)->faddr & PTD_FMT_MSK) >> 7)
2114808a1c0SOlav Kongas #define PTD_FMT(v)		(((v) << 7) & PTD_FMT_MSK)
2124808a1c0SOlav Kongas 
2134808a1c0SOlav Kongas /*  Hardware transfer status codes -- CC from ptd->count */
2144808a1c0SOlav Kongas #define TD_CC_NOERROR      0x00
2154808a1c0SOlav Kongas #define TD_CC_CRC          0x01
2164808a1c0SOlav Kongas #define TD_CC_BITSTUFFING  0x02
2174808a1c0SOlav Kongas #define TD_CC_DATATOGGLEM  0x03
2184808a1c0SOlav Kongas #define TD_CC_STALL        0x04
2194808a1c0SOlav Kongas #define TD_DEVNOTRESP      0x05
2204808a1c0SOlav Kongas #define TD_PIDCHECKFAIL    0x06
2214808a1c0SOlav Kongas #define TD_UNEXPECTEDPID   0x07
2224808a1c0SOlav Kongas #define TD_DATAOVERRUN     0x08
2234808a1c0SOlav Kongas #define TD_DATAUNDERRUN    0x09
2244808a1c0SOlav Kongas     /* 0x0A, 0x0B reserved for hardware */
2254808a1c0SOlav Kongas #define TD_BUFFEROVERRUN   0x0C
2264808a1c0SOlav Kongas #define TD_BUFFERUNDERRUN  0x0D
2274808a1c0SOlav Kongas     /* 0x0E, 0x0F reserved for HCD */
2284808a1c0SOlav Kongas #define TD_NOTACCESSED     0x0F
2294808a1c0SOlav Kongas 
2304808a1c0SOlav Kongas /* map PTD status codes (CC) to errno values */
2314808a1c0SOlav Kongas static const int cc_to_error[16] = {
2324808a1c0SOlav Kongas 	/* No  Error  */ 0,
2334808a1c0SOlav Kongas 	/* CRC Error  */ -EILSEQ,
2344808a1c0SOlav Kongas 	/* Bit Stuff  */ -EPROTO,
2354808a1c0SOlav Kongas 	/* Data Togg  */ -EILSEQ,
2364808a1c0SOlav Kongas 	/* Stall      */ -EPIPE,
23738e2bfc9SPete Zaitcev 	/* DevNotResp */ -ETIME,
2384808a1c0SOlav Kongas 	/* PIDCheck   */ -EPROTO,
2394808a1c0SOlav Kongas 	/* UnExpPID   */ -EPROTO,
2404808a1c0SOlav Kongas 	/* DataOver   */ -EOVERFLOW,
2414808a1c0SOlav Kongas 	/* DataUnder  */ -EREMOTEIO,
2424808a1c0SOlav Kongas 	/* (for hw)   */ -EIO,
2434808a1c0SOlav Kongas 	/* (for hw)   */ -EIO,
2444808a1c0SOlav Kongas 	/* BufferOver */ -ECOMM,
2454808a1c0SOlav Kongas 	/* BuffUnder  */ -ENOSR,
2464808a1c0SOlav Kongas 	/* (for HCD)  */ -EALREADY,
2474808a1c0SOlav Kongas 	/* (for HCD)  */ -EALREADY
2484808a1c0SOlav Kongas };
2494808a1c0SOlav Kongas 
2504808a1c0SOlav Kongas /*--------------------------------------------------------------*/
2514808a1c0SOlav Kongas 
2524808a1c0SOlav Kongas #define	LOG2_PERIODIC_SIZE	5	/* arbitrary; this matches OHCI */
2534808a1c0SOlav Kongas #define	PERIODIC_SIZE		(1 << LOG2_PERIODIC_SIZE)
2544808a1c0SOlav Kongas 
2554808a1c0SOlav Kongas struct isp116x {
2564808a1c0SOlav Kongas 	spinlock_t lock;
2574808a1c0SOlav Kongas 
2584808a1c0SOlav Kongas 	void __iomem *addr_reg;
2594808a1c0SOlav Kongas 	void __iomem *data_reg;
2604808a1c0SOlav Kongas 
2614808a1c0SOlav Kongas 	struct isp116x_platform_data *board;
2624808a1c0SOlav Kongas 
2634808a1c0SOlav Kongas 	unsigned long stat1, stat2, stat4, stat8, stat16;
2644808a1c0SOlav Kongas 
2654808a1c0SOlav Kongas 	/* HC registers */
2664808a1c0SOlav Kongas 	u32 intenb;		/* "OHCI" interrupts */
2674808a1c0SOlav Kongas 	u16 irqenb;		/* uP interrupts */
2684808a1c0SOlav Kongas 
2694808a1c0SOlav Kongas 	/* Root hub registers */
2704808a1c0SOlav Kongas 	u32 rhdesca;
2714808a1c0SOlav Kongas 	u32 rhdescb;
2724808a1c0SOlav Kongas 	u32 rhstatus;
2734808a1c0SOlav Kongas 
2744808a1c0SOlav Kongas 	/* async schedule: control, bulk */
2754808a1c0SOlav Kongas 	struct list_head async;
2764808a1c0SOlav Kongas 
2774808a1c0SOlav Kongas 	/* periodic schedule: int */
2784808a1c0SOlav Kongas 	u16 load[PERIODIC_SIZE];
2794808a1c0SOlav Kongas 	struct isp116x_ep *periodic[PERIODIC_SIZE];
2804808a1c0SOlav Kongas 	unsigned periodic_count;
2814808a1c0SOlav Kongas 	u16 fmindex;
2824808a1c0SOlav Kongas 
2834808a1c0SOlav Kongas 	/* Schedule for the current frame */
2844808a1c0SOlav Kongas 	struct isp116x_ep *atl_active;
2854808a1c0SOlav Kongas 	int atl_buflen;
2864808a1c0SOlav Kongas 	int atl_bufshrt;
2874808a1c0SOlav Kongas 	int atl_last_dir;
2884808a1c0SOlav Kongas 	atomic_t atl_finishing;
2894808a1c0SOlav Kongas };
2904808a1c0SOlav Kongas 
hcd_to_isp116x(struct usb_hcd * hcd)2914808a1c0SOlav Kongas static inline struct isp116x *hcd_to_isp116x(struct usb_hcd *hcd)
2924808a1c0SOlav Kongas {
2934808a1c0SOlav Kongas 	return (struct isp116x *)(hcd->hcd_priv);
2944808a1c0SOlav Kongas }
2954808a1c0SOlav Kongas 
isp116x_to_hcd(struct isp116x * isp116x)2964808a1c0SOlav Kongas static inline struct usb_hcd *isp116x_to_hcd(struct isp116x *isp116x)
2974808a1c0SOlav Kongas {
2984808a1c0SOlav Kongas 	return container_of((void *)isp116x, struct usb_hcd, hcd_priv);
2994808a1c0SOlav Kongas }
3004808a1c0SOlav Kongas 
3014808a1c0SOlav Kongas struct isp116x_ep {
3024808a1c0SOlav Kongas 	struct usb_host_endpoint *hep;
3034808a1c0SOlav Kongas 	struct usb_device *udev;
3044808a1c0SOlav Kongas 	struct ptd ptd;
3054808a1c0SOlav Kongas 
3064808a1c0SOlav Kongas 	u8 maxpacket;
3074808a1c0SOlav Kongas 	u8 epnum;
3084808a1c0SOlav Kongas 	u8 nextpid;
3094808a1c0SOlav Kongas 	u16 error_count;
3104808a1c0SOlav Kongas 	u16 length;		/* of current packet */
3114808a1c0SOlav Kongas 	unsigned char *data;	/* to databuf */
3124808a1c0SOlav Kongas 	/* queue of active EP's (the ones scheduled for the
3134808a1c0SOlav Kongas 	   current frame) */
3144808a1c0SOlav Kongas 	struct isp116x_ep *active;
3154808a1c0SOlav Kongas 
3164808a1c0SOlav Kongas 	/* periodic schedule */
3174808a1c0SOlav Kongas 	u16 period;
3184808a1c0SOlav Kongas 	u16 branch;
3194808a1c0SOlav Kongas 	u16 load;
3204808a1c0SOlav Kongas 	struct isp116x_ep *next;
3214808a1c0SOlav Kongas 
3224808a1c0SOlav Kongas 	/* async schedule */
3234808a1c0SOlav Kongas 	struct list_head schedule;
3244808a1c0SOlav Kongas };
3254808a1c0SOlav Kongas 
3264808a1c0SOlav Kongas /*-------------------------------------------------------------------------*/
3274808a1c0SOlav Kongas 
3281d896ceaSGreg Kroah-Hartman #define DBG(stuff...)		pr_debug("116x: " stuff)
3294808a1c0SOlav Kongas 
3304808a1c0SOlav Kongas #ifdef VERBOSE
3314808a1c0SOlav Kongas #    define VDBG		DBG
3324808a1c0SOlav Kongas #else
3334808a1c0SOlav Kongas #    define VDBG(stuff...)	do{}while(0)
3344808a1c0SOlav Kongas #endif
3354808a1c0SOlav Kongas 
3364808a1c0SOlav Kongas #define ERR(stuff...)		printk(KERN_ERR "116x: " stuff)
337b6c63937SArjan van de Ven #define WARNING(stuff...)	printk(KERN_WARNING "116x: " stuff)
3384808a1c0SOlav Kongas #define INFO(stuff...)		printk(KERN_INFO "116x: " stuff)
3394808a1c0SOlav Kongas 
3404808a1c0SOlav Kongas /* ------------------------------------------------- */
3414808a1c0SOlav Kongas 
3424808a1c0SOlav Kongas #if defined(USE_PLATFORM_DELAY)
3434808a1c0SOlav Kongas #if defined(USE_NDELAY)
3444808a1c0SOlav Kongas #error USE_PLATFORM_DELAY and USE_NDELAY simultaneously defined.
3454808a1c0SOlav Kongas #endif
3464808a1c0SOlav Kongas #define	isp116x_delay(h,d)	(h)->board->delay(	\
3474808a1c0SOlav Kongas 				isp116x_to_hcd(h)->self.controller,d)
3484808a1c0SOlav Kongas #define isp116x_check_platform_delay(h)	((h)->board->delay == NULL)
3494808a1c0SOlav Kongas #elif defined(USE_NDELAY)
3504808a1c0SOlav Kongas #define	isp116x_delay(h,d)	ndelay(d)
3514808a1c0SOlav Kongas #define isp116x_check_platform_delay(h)	0
3524808a1c0SOlav Kongas #else
3534808a1c0SOlav Kongas #define	isp116x_delay(h,d)	do{}while(0)
3544808a1c0SOlav Kongas #define isp116x_check_platform_delay(h)	0
3554808a1c0SOlav Kongas #endif
3564808a1c0SOlav Kongas 
isp116x_write_addr(struct isp116x * isp116x,unsigned reg)3574808a1c0SOlav Kongas static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
3584808a1c0SOlav Kongas {
3594808a1c0SOlav Kongas 	writew(reg & 0xff, isp116x->addr_reg);
3604808a1c0SOlav Kongas 	isp116x_delay(isp116x, 300);
3614808a1c0SOlav Kongas }
3624808a1c0SOlav Kongas 
isp116x_write_data16(struct isp116x * isp116x,u16 val)3634808a1c0SOlav Kongas static inline void isp116x_write_data16(struct isp116x *isp116x, u16 val)
3644808a1c0SOlav Kongas {
3654808a1c0SOlav Kongas 	writew(val, isp116x->data_reg);
3664808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
3674808a1c0SOlav Kongas }
3684808a1c0SOlav Kongas 
isp116x_raw_write_data16(struct isp116x * isp116x,u16 val)3694808a1c0SOlav Kongas static inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val)
3704808a1c0SOlav Kongas {
3714808a1c0SOlav Kongas 	__raw_writew(val, isp116x->data_reg);
3724808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
3734808a1c0SOlav Kongas }
3744808a1c0SOlav Kongas 
isp116x_read_data16(struct isp116x * isp116x)3754808a1c0SOlav Kongas static inline u16 isp116x_read_data16(struct isp116x *isp116x)
3764808a1c0SOlav Kongas {
3774808a1c0SOlav Kongas 	u16 val;
3784808a1c0SOlav Kongas 
3794808a1c0SOlav Kongas 	val = readw(isp116x->data_reg);
3804808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
3814808a1c0SOlav Kongas 	return val;
3824808a1c0SOlav Kongas }
3834808a1c0SOlav Kongas 
isp116x_raw_read_data16(struct isp116x * isp116x)3844808a1c0SOlav Kongas static inline u16 isp116x_raw_read_data16(struct isp116x *isp116x)
3854808a1c0SOlav Kongas {
3864808a1c0SOlav Kongas 	u16 val;
3874808a1c0SOlav Kongas 
3884808a1c0SOlav Kongas 	val = __raw_readw(isp116x->data_reg);
3894808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
3904808a1c0SOlav Kongas 	return val;
3914808a1c0SOlav Kongas }
3924808a1c0SOlav Kongas 
isp116x_write_data32(struct isp116x * isp116x,u32 val)3934808a1c0SOlav Kongas static inline void isp116x_write_data32(struct isp116x *isp116x, u32 val)
3944808a1c0SOlav Kongas {
3954808a1c0SOlav Kongas 	writew(val & 0xffff, isp116x->data_reg);
3964808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
3974808a1c0SOlav Kongas 	writew(val >> 16, isp116x->data_reg);
3984808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
3994808a1c0SOlav Kongas }
4004808a1c0SOlav Kongas 
isp116x_read_data32(struct isp116x * isp116x)4014808a1c0SOlav Kongas static inline u32 isp116x_read_data32(struct isp116x *isp116x)
4024808a1c0SOlav Kongas {
4034808a1c0SOlav Kongas 	u32 val;
4044808a1c0SOlav Kongas 
4054808a1c0SOlav Kongas 	val = (u32) readw(isp116x->data_reg);
4064808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
4074808a1c0SOlav Kongas 	val |= ((u32) readw(isp116x->data_reg)) << 16;
4084808a1c0SOlav Kongas 	isp116x_delay(isp116x, 150);
4094808a1c0SOlav Kongas 	return val;
4104808a1c0SOlav Kongas }
4114808a1c0SOlav Kongas 
4124808a1c0SOlav Kongas /* Let's keep register access functions out of line. Hint:
4134808a1c0SOlav Kongas    we wait at least 150 ns at every access.
4144808a1c0SOlav Kongas */
isp116x_read_reg16(struct isp116x * isp116x,unsigned reg)4154808a1c0SOlav Kongas static u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg)
4164808a1c0SOlav Kongas {
4174808a1c0SOlav Kongas 	isp116x_write_addr(isp116x, reg);
4184808a1c0SOlav Kongas 	return isp116x_read_data16(isp116x);
4194808a1c0SOlav Kongas }
4204808a1c0SOlav Kongas 
isp116x_read_reg32(struct isp116x * isp116x,unsigned reg)4214808a1c0SOlav Kongas static u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg)
4224808a1c0SOlav Kongas {
4234808a1c0SOlav Kongas 	isp116x_write_addr(isp116x, reg);
4244808a1c0SOlav Kongas 	return isp116x_read_data32(isp116x);
4254808a1c0SOlav Kongas }
4264808a1c0SOlav Kongas 
isp116x_write_reg16(struct isp116x * isp116x,unsigned reg,unsigned val)4274808a1c0SOlav Kongas static void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg,
4284808a1c0SOlav Kongas 				unsigned val)
4294808a1c0SOlav Kongas {
4304808a1c0SOlav Kongas 	isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
4314808a1c0SOlav Kongas 	isp116x_write_data16(isp116x, (u16) (val & 0xffff));
4324808a1c0SOlav Kongas }
4334808a1c0SOlav Kongas 
isp116x_write_reg32(struct isp116x * isp116x,unsigned reg,unsigned val)4344808a1c0SOlav Kongas static void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg,
4354808a1c0SOlav Kongas 				unsigned val)
4364808a1c0SOlav Kongas {
4374808a1c0SOlav Kongas 	isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
4384808a1c0SOlav Kongas 	isp116x_write_data32(isp116x, (u32) val);
4394808a1c0SOlav Kongas }
4404808a1c0SOlav Kongas 
441959eea21SOlav Kongas #define isp116x_show_reg_log(d,r,s) {				\
4424808a1c0SOlav Kongas 	if ((r) < 0x20) {			                \
4434808a1c0SOlav Kongas 		DBG("%-12s[%02x]: %08x\n", #r,			\
4444808a1c0SOlav Kongas 			r, isp116x_read_reg32(d, r));		\
4454808a1c0SOlav Kongas 	} else {						\
4464808a1c0SOlav Kongas 		DBG("%-12s[%02x]:     %04x\n", #r,		\
4474808a1c0SOlav Kongas 			r, isp116x_read_reg16(d, r));	    	\
4484808a1c0SOlav Kongas 	}							\
4494808a1c0SOlav Kongas }
450959eea21SOlav Kongas #define isp116x_show_reg_seq(d,r,s) {				\
451959eea21SOlav Kongas 	if ((r) < 0x20) {					\
452959eea21SOlav Kongas 		seq_printf(s, "%-12s[%02x]: %08x\n", #r,	\
453959eea21SOlav Kongas 			r, isp116x_read_reg32(d, r));		\
454959eea21SOlav Kongas 	} else {						\
455959eea21SOlav Kongas 		seq_printf(s, "%-12s[%02x]:     %04x\n", #r,	\
456959eea21SOlav Kongas 			r, isp116x_read_reg16(d, r));		\
457959eea21SOlav Kongas 	}							\
458959eea21SOlav Kongas }
4594808a1c0SOlav Kongas 
460959eea21SOlav Kongas #define isp116x_show_regs(d,type,s) {			\
461959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCREVISION, s);	\
462959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCCONTROL, s);	\
463959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCCMDSTAT, s);	\
464959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCINTSTAT, s);	\
465959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCINTENB, s);	\
466959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCFMINTVL, s);	\
467959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCFMREM, s);		\
468959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCFMNUM, s);		\
469959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCLSTHRESH, s);	\
470959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRHDESCA, s);	\
471959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRHDESCB, s);	\
472959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRHSTATUS, s);	\
473959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRHPORT1, s);	\
474959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRHPORT2, s);	\
475959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCHWCFG, s);		\
476959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCDMACFG, s);	\
477959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCXFERCTR, s);	\
478959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCuPINT, s);		\
479959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCuPINTENB, s);	\
480959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCCHIPID, s);	\
481959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCSCRATCH, s);	\
482959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCITLBUFLEN, s);	\
483959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCATLBUFLEN, s);	\
484959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCBUFSTAT, s);	\
485959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRDITL0LEN, s);	\
486959eea21SOlav Kongas 	isp116x_show_reg_##type(d, HCRDITL1LEN, s);	\
487959eea21SOlav Kongas }
488959eea21SOlav Kongas 
489959eea21SOlav Kongas /*
490959eea21SOlav Kongas    Dump registers for debugfs.
491959eea21SOlav Kongas */
isp116x_show_regs_seq(struct isp116x * isp116x,struct seq_file * s)492959eea21SOlav Kongas static inline void isp116x_show_regs_seq(struct isp116x *isp116x,
493959eea21SOlav Kongas 					  struct seq_file *s)
4944808a1c0SOlav Kongas {
495959eea21SOlav Kongas 	isp116x_show_regs(isp116x, seq, s);
496959eea21SOlav Kongas }
497959eea21SOlav Kongas 
498959eea21SOlav Kongas /*
499959eea21SOlav Kongas    Dump registers to syslog.
500959eea21SOlav Kongas */
isp116x_show_regs_log(struct isp116x * isp116x)501959eea21SOlav Kongas static inline void isp116x_show_regs_log(struct isp116x *isp116x)
502959eea21SOlav Kongas {
503959eea21SOlav Kongas 	isp116x_show_regs(isp116x, log, NULL);
5044808a1c0SOlav Kongas }
5054808a1c0SOlav Kongas 
5064808a1c0SOlav Kongas #if defined(URB_TRACE)
5074808a1c0SOlav Kongas 
5084808a1c0SOlav Kongas #define PIPETYPE(pipe)  ({ char *__s;			\
5094808a1c0SOlav Kongas 	if (usb_pipecontrol(pipe))	__s = "ctrl";	\
5104808a1c0SOlav Kongas 	else if (usb_pipeint(pipe))	__s = "int";	\
5114808a1c0SOlav Kongas 	else if (usb_pipebulk(pipe))	__s = "bulk";	\
5124808a1c0SOlav Kongas 	else				__s = "iso";	\
5134808a1c0SOlav Kongas 	__s;})
5144808a1c0SOlav Kongas #define PIPEDIR(pipe)   ({ usb_pipein(pipe) ? "in" : "out"; })
5154808a1c0SOlav Kongas #define URB_NOTSHORT(urb) ({ (urb)->transfer_flags & URB_SHORT_NOT_OK ? \
5164808a1c0SOlav Kongas 	"short_not_ok" : ""; })
5174808a1c0SOlav Kongas 
5184808a1c0SOlav Kongas /* print debug info about the URB */
urb_dbg(struct urb * urb,char * msg)5194808a1c0SOlav Kongas static void urb_dbg(struct urb *urb, char *msg)
5204808a1c0SOlav Kongas {
5214808a1c0SOlav Kongas 	unsigned int pipe;
5224808a1c0SOlav Kongas 
5234808a1c0SOlav Kongas 	if (!urb) {
5244808a1c0SOlav Kongas 		DBG("%s: zero urb\n", msg);
5254808a1c0SOlav Kongas 		return;
5264808a1c0SOlav Kongas 	}
5274808a1c0SOlav Kongas 	pipe = urb->pipe;
5284808a1c0SOlav Kongas 	DBG("%s: FA %d ep%d%s %s: len %d/%d %s\n", msg,
5294808a1c0SOlav Kongas 	    usb_pipedevice(pipe), usb_pipeendpoint(pipe),
5304808a1c0SOlav Kongas 	    PIPEDIR(pipe), PIPETYPE(pipe),
5314808a1c0SOlav Kongas 	    urb->transfer_buffer_length, urb->actual_length, URB_NOTSHORT(urb));
5324808a1c0SOlav Kongas }
5334808a1c0SOlav Kongas 
5344808a1c0SOlav Kongas #else
5354808a1c0SOlav Kongas 
5364808a1c0SOlav Kongas #define  urb_dbg(urb,msg)   do{}while(0)
5374808a1c0SOlav Kongas 
5384808a1c0SOlav Kongas #endif				/* ! defined(URB_TRACE) */
5394808a1c0SOlav Kongas 
5404808a1c0SOlav Kongas #if defined(PTD_TRACE)
5414808a1c0SOlav Kongas 
5424808a1c0SOlav Kongas #define PTD_DIR_STR(ptd)  ({char __c;		\
5434808a1c0SOlav Kongas 	switch(PTD_GET_DIR(ptd)){		\
5444808a1c0SOlav Kongas 	case 0:  __c = 's'; break;		\
5454808a1c0SOlav Kongas 	case 1:  __c = 'o'; break;		\
5464808a1c0SOlav Kongas 	default: __c = 'i'; break;		\
5474808a1c0SOlav Kongas 	}; __c;})
5484808a1c0SOlav Kongas 
5494808a1c0SOlav Kongas /*
5504808a1c0SOlav Kongas   Dump PTD info. The code documents the format
5514808a1c0SOlav Kongas   perfectly, right :)
5524808a1c0SOlav Kongas */
dump_ptd(struct ptd * ptd)5534808a1c0SOlav Kongas static inline void dump_ptd(struct ptd *ptd)
5544808a1c0SOlav Kongas {
5556f8aa65bSFrank Seidel 	printk(KERN_WARNING "td: %x %d%c%d %d,%d,%d  %x %x%x%x\n",
5564808a1c0SOlav Kongas 	       PTD_GET_CC(ptd), PTD_GET_FA(ptd),
5574808a1c0SOlav Kongas 	       PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
5584808a1c0SOlav Kongas 	       PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
5594808a1c0SOlav Kongas 	       PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd),
5604808a1c0SOlav Kongas 	       PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));
5614808a1c0SOlav Kongas }
5624808a1c0SOlav Kongas 
dump_ptd_out_data(struct ptd * ptd,u8 * buf)5634808a1c0SOlav Kongas static inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf)
5644808a1c0SOlav Kongas {
5654808a1c0SOlav Kongas 	int k;
5664808a1c0SOlav Kongas 
5674808a1c0SOlav Kongas 	if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
5686f8aa65bSFrank Seidel 		printk(KERN_WARNING "-> ");
5694808a1c0SOlav Kongas 		for (k = 0; k < PTD_GET_LEN(ptd); ++k)
5704808a1c0SOlav Kongas 			printk("%02x ", ((u8 *) buf)[k]);
5714808a1c0SOlav Kongas 		printk("\n");
5724808a1c0SOlav Kongas 	}
5734808a1c0SOlav Kongas }
5744808a1c0SOlav Kongas 
dump_ptd_in_data(struct ptd * ptd,u8 * buf)5754808a1c0SOlav Kongas static inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf)
5764808a1c0SOlav Kongas {
5774808a1c0SOlav Kongas 	int k;
5784808a1c0SOlav Kongas 
5794808a1c0SOlav Kongas 	if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
5806f8aa65bSFrank Seidel 		printk(KERN_WARNING "<- ");
5814808a1c0SOlav Kongas 		for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
5824808a1c0SOlav Kongas 			printk("%02x ", ((u8 *) buf)[k]);
5834808a1c0SOlav Kongas 		printk("\n");
5844808a1c0SOlav Kongas 	}
5854808a1c0SOlav Kongas 	if (PTD_GET_LAST(ptd))
5866f8aa65bSFrank Seidel 		printk(KERN_WARNING "-\n");
5874808a1c0SOlav Kongas }
5884808a1c0SOlav Kongas 
5894808a1c0SOlav Kongas #else
5904808a1c0SOlav Kongas 
5914808a1c0SOlav Kongas #define dump_ptd(ptd)               do{}while(0)
5924808a1c0SOlav Kongas #define dump_ptd_in_data(ptd,buf)   do{}while(0)
5934808a1c0SOlav Kongas #define dump_ptd_out_data(ptd,buf)  do{}while(0)
5944808a1c0SOlav Kongas 
5954808a1c0SOlav Kongas #endif				/* ! defined(PTD_TRACE) */
596