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