13e45ed3cSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */
2236dd4d1SAnton Vorontsov /*
3236dd4d1SAnton Vorontsov * Freescale QUICC Engine USB Host Controller Driver
4236dd4d1SAnton Vorontsov *
5236dd4d1SAnton Vorontsov * Copyright (c) Freescale Semicondutor, Inc. 2006.
6236dd4d1SAnton Vorontsov * Shlomi Gridish <gridish@freescale.com>
7236dd4d1SAnton Vorontsov * Jerry Huang <Chang-Ming.Huang@freescale.com>
8236dd4d1SAnton Vorontsov * Copyright (c) Logic Product Development, Inc. 2007
9236dd4d1SAnton Vorontsov * Peter Barada <peterb@logicpd.com>
10236dd4d1SAnton Vorontsov * Copyright (c) MontaVista Software, Inc. 2008.
11236dd4d1SAnton Vorontsov * Anton Vorontsov <avorontsov@ru.mvista.com>
12236dd4d1SAnton Vorontsov */
13236dd4d1SAnton Vorontsov
14236dd4d1SAnton Vorontsov #ifndef __FHCI_H
15236dd4d1SAnton Vorontsov #define __FHCI_H
16236dd4d1SAnton Vorontsov
17236dd4d1SAnton Vorontsov #include <linux/kernel.h>
18236dd4d1SAnton Vorontsov #include <linux/types.h>
197f1cccd3SAnton Vorontsov #include <linux/bug.h>
20236dd4d1SAnton Vorontsov #include <linux/spinlock.h>
21236dd4d1SAnton Vorontsov #include <linux/interrupt.h>
22236dd4d1SAnton Vorontsov #include <linux/kfifo.h>
23236dd4d1SAnton Vorontsov #include <linux/io.h>
24236dd4d1SAnton Vorontsov #include <linux/usb.h>
2527729aadSEric Lescouet #include <linux/usb/hcd.h>
26*a4efdb8aSLinus Walleij #include <linux/gpio/consumer.h>
277aa1aa6eSZhao Qiang #include <soc/fsl/qe/qe.h>
287aa1aa6eSZhao Qiang #include <soc/fsl/qe/immap_qe.h>
29236dd4d1SAnton Vorontsov
30236dd4d1SAnton Vorontsov #define USB_CLOCK 48000000
31236dd4d1SAnton Vorontsov
32236dd4d1SAnton Vorontsov #define FHCI_PRAM_SIZE 0x100
33236dd4d1SAnton Vorontsov
34236dd4d1SAnton Vorontsov #define MAX_EDS 32
35236dd4d1SAnton Vorontsov #define MAX_TDS 32
36236dd4d1SAnton Vorontsov
37236dd4d1SAnton Vorontsov
38236dd4d1SAnton Vorontsov /* CRC16 field size */
39236dd4d1SAnton Vorontsov #define CRC_SIZE 2
40236dd4d1SAnton Vorontsov
41236dd4d1SAnton Vorontsov /* USB protocol overhead for each frame transmitted from the host */
42236dd4d1SAnton Vorontsov #define PROTOCOL_OVERHEAD 7
43236dd4d1SAnton Vorontsov
44236dd4d1SAnton Vorontsov /* Packet structure, info field */
45236dd4d1SAnton Vorontsov #define PKT_PID_DATA0 0x80000000 /* PID - Data toggle zero */
46236dd4d1SAnton Vorontsov #define PKT_PID_DATA1 0x40000000 /* PID - Data toggle one */
47236dd4d1SAnton Vorontsov #define PKT_PID_SETUP 0x20000000 /* PID - Setup bit */
48236dd4d1SAnton Vorontsov #define PKT_SETUP_STATUS 0x10000000 /* Setup status bit */
49236dd4d1SAnton Vorontsov #define PKT_SETADDR_STATUS 0x08000000 /* Set address status bit */
50236dd4d1SAnton Vorontsov #define PKT_SET_HOST_LAST 0x04000000 /* Last data packet */
51236dd4d1SAnton Vorontsov #define PKT_HOST_DATA 0x02000000 /* Data packet */
52236dd4d1SAnton Vorontsov #define PKT_FIRST_IN_FRAME 0x01000000 /* First packet in the frame */
53236dd4d1SAnton Vorontsov #define PKT_TOKEN_FRAME 0x00800000 /* Token packet */
54236dd4d1SAnton Vorontsov #define PKT_ZLP 0x00400000 /* Zero length packet */
55236dd4d1SAnton Vorontsov #define PKT_IN_TOKEN_FRAME 0x00200000 /* IN token packet */
56236dd4d1SAnton Vorontsov #define PKT_OUT_TOKEN_FRAME 0x00100000 /* OUT token packet */
57236dd4d1SAnton Vorontsov #define PKT_SETUP_TOKEN_FRAME 0x00080000 /* SETUP token packet */
58236dd4d1SAnton Vorontsov #define PKT_STALL_FRAME 0x00040000 /* STALL packet */
59236dd4d1SAnton Vorontsov #define PKT_NACK_FRAME 0x00020000 /* NACK packet */
60236dd4d1SAnton Vorontsov #define PKT_NO_PID 0x00010000 /* No PID */
61236dd4d1SAnton Vorontsov #define PKT_NO_CRC 0x00008000 /* don't append CRC */
62236dd4d1SAnton Vorontsov #define PKT_HOST_COMMAND 0x00004000 /* Host command packet */
63236dd4d1SAnton Vorontsov #define PKT_DUMMY_PACKET 0x00002000 /* Dummy packet, used for mmm */
64236dd4d1SAnton Vorontsov #define PKT_LOW_SPEED_PACKET 0x00001000 /* Low-Speed packet */
65236dd4d1SAnton Vorontsov
66236dd4d1SAnton Vorontsov #define TRANS_OK (0)
67236dd4d1SAnton Vorontsov #define TRANS_INPROGRESS (-1)
68236dd4d1SAnton Vorontsov #define TRANS_DISCARD (-2)
69236dd4d1SAnton Vorontsov #define TRANS_FAIL (-3)
70236dd4d1SAnton Vorontsov
71236dd4d1SAnton Vorontsov #define PS_INT 0
72236dd4d1SAnton Vorontsov #define PS_DISCONNECTED 1
73236dd4d1SAnton Vorontsov #define PS_CONNECTED 2
74236dd4d1SAnton Vorontsov #define PS_READY 3
75236dd4d1SAnton Vorontsov #define PS_MISSING 4
76236dd4d1SAnton Vorontsov
77236dd4d1SAnton Vorontsov /* Transfer Descriptor status field */
78236dd4d1SAnton Vorontsov #define USB_TD_OK 0x00000000 /* TD transmited or received ok */
79236dd4d1SAnton Vorontsov #define USB_TD_INPROGRESS 0x80000000 /* TD is being transmitted */
80236dd4d1SAnton Vorontsov #define USB_TD_RX_ER_NONOCT 0x40000000 /* Tx Non Octet Aligned Packet */
81236dd4d1SAnton Vorontsov #define USB_TD_RX_ER_BITSTUFF 0x20000000 /* Frame Aborted-Received pkt */
82236dd4d1SAnton Vorontsov #define USB_TD_RX_ER_CRC 0x10000000 /* CRC error */
8325985edcSLucas De Marchi #define USB_TD_RX_ER_OVERUN 0x08000000 /* Over - run occurred */
84236dd4d1SAnton Vorontsov #define USB_TD_RX_ER_PID 0x04000000 /* wrong PID received */
85236dd4d1SAnton Vorontsov #define USB_TD_RX_DATA_UNDERUN 0x02000000 /* shorter than expected */
86236dd4d1SAnton Vorontsov #define USB_TD_RX_DATA_OVERUN 0x01000000 /* longer than expected */
87236dd4d1SAnton Vorontsov #define USB_TD_TX_ER_NAK 0x00800000 /* NAK handshake */
88236dd4d1SAnton Vorontsov #define USB_TD_TX_ER_STALL 0x00400000 /* STALL handshake */
89236dd4d1SAnton Vorontsov #define USB_TD_TX_ER_TIMEOUT 0x00200000 /* transmit time out */
90236dd4d1SAnton Vorontsov #define USB_TD_TX_ER_UNDERUN 0x00100000 /* transmit underrun */
91236dd4d1SAnton Vorontsov
92236dd4d1SAnton Vorontsov #define USB_TD_ERROR (USB_TD_RX_ER_NONOCT | USB_TD_RX_ER_BITSTUFF | \
93236dd4d1SAnton Vorontsov USB_TD_RX_ER_CRC | USB_TD_RX_ER_OVERUN | USB_TD_RX_ER_PID | \
94236dd4d1SAnton Vorontsov USB_TD_RX_DATA_UNDERUN | USB_TD_RX_DATA_OVERUN | \
95236dd4d1SAnton Vorontsov USB_TD_TX_ER_NAK | USB_TD_TX_ER_STALL | \
96236dd4d1SAnton Vorontsov USB_TD_TX_ER_TIMEOUT | USB_TD_TX_ER_UNDERUN)
97236dd4d1SAnton Vorontsov
98236dd4d1SAnton Vorontsov /* Transfer Descriptor toggle field */
99236dd4d1SAnton Vorontsov #define USB_TD_TOGGLE_DATA0 0
100236dd4d1SAnton Vorontsov #define USB_TD_TOGGLE_DATA1 1
101236dd4d1SAnton Vorontsov #define USB_TD_TOGGLE_CARRY 2
102236dd4d1SAnton Vorontsov
103236dd4d1SAnton Vorontsov /* #define MULTI_DATA_BUS */
104236dd4d1SAnton Vorontsov
105236dd4d1SAnton Vorontsov /* Bus mode register RBMR/TBMR */
106236dd4d1SAnton Vorontsov #define BUS_MODE_GBL 0x20 /* Global snooping */
107236dd4d1SAnton Vorontsov #define BUS_MODE_BO 0x18 /* Byte ordering */
108236dd4d1SAnton Vorontsov #define BUS_MODE_BO_BE 0x10 /* Byte ordering - Big-endian */
109236dd4d1SAnton Vorontsov #define BUS_MODE_DTB 0x02 /* Data bus */
110236dd4d1SAnton Vorontsov
111236dd4d1SAnton Vorontsov /* FHCI QE USB Register Description */
112236dd4d1SAnton Vorontsov
113236dd4d1SAnton Vorontsov /* USB Mode Register bit define */
114236dd4d1SAnton Vorontsov #define USB_MODE_EN 0x01
115236dd4d1SAnton Vorontsov #define USB_MODE_HOST 0x02
116236dd4d1SAnton Vorontsov #define USB_MODE_TEST 0x04
117236dd4d1SAnton Vorontsov #define USB_MODE_SFTE 0x08
118236dd4d1SAnton Vorontsov #define USB_MODE_RESUME 0x40
119236dd4d1SAnton Vorontsov #define USB_MODE_LSS 0x80
120236dd4d1SAnton Vorontsov
121236dd4d1SAnton Vorontsov /* USB Slave Address Register Mask */
122236dd4d1SAnton Vorontsov #define USB_SLVADDR_MASK 0x7F
123236dd4d1SAnton Vorontsov
124236dd4d1SAnton Vorontsov /* USB Endpoint register define */
125236dd4d1SAnton Vorontsov #define USB_EPNUM_MASK 0xF000
126236dd4d1SAnton Vorontsov #define USB_EPNUM_SHIFT 12
127236dd4d1SAnton Vorontsov
128236dd4d1SAnton Vorontsov #define USB_TRANS_MODE_SHIFT 8
129236dd4d1SAnton Vorontsov #define USB_TRANS_CTR 0x0000
130236dd4d1SAnton Vorontsov #define USB_TRANS_INT 0x0100
131236dd4d1SAnton Vorontsov #define USB_TRANS_BULK 0x0200
132236dd4d1SAnton Vorontsov #define USB_TRANS_ISO 0x0300
133236dd4d1SAnton Vorontsov
134236dd4d1SAnton Vorontsov #define USB_EP_MF 0x0020
135236dd4d1SAnton Vorontsov #define USB_EP_RTE 0x0010
136236dd4d1SAnton Vorontsov
137236dd4d1SAnton Vorontsov #define USB_THS_SHIFT 2
138236dd4d1SAnton Vorontsov #define USB_THS_MASK 0x000c
139236dd4d1SAnton Vorontsov #define USB_THS_NORMAL 0x0
140236dd4d1SAnton Vorontsov #define USB_THS_IGNORE_IN 0x0004
141236dd4d1SAnton Vorontsov #define USB_THS_NACK 0x0008
142236dd4d1SAnton Vorontsov #define USB_THS_STALL 0x000c
143236dd4d1SAnton Vorontsov
144236dd4d1SAnton Vorontsov #define USB_RHS_SHIFT 0
145236dd4d1SAnton Vorontsov #define USB_RHS_MASK 0x0003
146236dd4d1SAnton Vorontsov #define USB_RHS_NORMAL 0x0
147236dd4d1SAnton Vorontsov #define USB_RHS_IGNORE_OUT 0x0001
148236dd4d1SAnton Vorontsov #define USB_RHS_NACK 0x0002
149236dd4d1SAnton Vorontsov #define USB_RHS_STALL 0x0003
150236dd4d1SAnton Vorontsov
151236dd4d1SAnton Vorontsov #define USB_RTHS_MASK 0x000f
152236dd4d1SAnton Vorontsov
153236dd4d1SAnton Vorontsov /* USB Command Register define */
154236dd4d1SAnton Vorontsov #define USB_CMD_STR_FIFO 0x80
155236dd4d1SAnton Vorontsov #define USB_CMD_FLUSH_FIFO 0x40
156236dd4d1SAnton Vorontsov #define USB_CMD_ISFT 0x20
157236dd4d1SAnton Vorontsov #define USB_CMD_DSFT 0x10
158236dd4d1SAnton Vorontsov #define USB_CMD_EP_MASK 0x03
159236dd4d1SAnton Vorontsov
160236dd4d1SAnton Vorontsov /* USB Event and Mask Register define */
161236dd4d1SAnton Vorontsov #define USB_E_MSF_MASK 0x0800
162236dd4d1SAnton Vorontsov #define USB_E_SFT_MASK 0x0400
163236dd4d1SAnton Vorontsov #define USB_E_RESET_MASK 0x0200
164236dd4d1SAnton Vorontsov #define USB_E_IDLE_MASK 0x0100
165236dd4d1SAnton Vorontsov #define USB_E_TXE4_MASK 0x0080
166236dd4d1SAnton Vorontsov #define USB_E_TXE3_MASK 0x0040
167236dd4d1SAnton Vorontsov #define USB_E_TXE2_MASK 0x0020
168236dd4d1SAnton Vorontsov #define USB_E_TXE1_MASK 0x0010
169236dd4d1SAnton Vorontsov #define USB_E_SOF_MASK 0x0008
170236dd4d1SAnton Vorontsov #define USB_E_BSY_MASK 0x0004
171236dd4d1SAnton Vorontsov #define USB_E_TXB_MASK 0x0002
172236dd4d1SAnton Vorontsov #define USB_E_RXB_MASK 0x0001
173236dd4d1SAnton Vorontsov
174236dd4d1SAnton Vorontsov /* Freescale USB HOST */
175236dd4d1SAnton Vorontsov struct fhci_pram {
176236dd4d1SAnton Vorontsov __be16 ep_ptr[4]; /* Endpoint porter reg */
177236dd4d1SAnton Vorontsov __be32 rx_state; /* Rx internal state */
178236dd4d1SAnton Vorontsov __be32 rx_ptr; /* Rx internal data pointer */
179236dd4d1SAnton Vorontsov __be16 frame_num; /* Frame number */
180236dd4d1SAnton Vorontsov __be16 rx_cnt; /* Rx byte count */
181236dd4d1SAnton Vorontsov __be32 rx_temp; /* Rx temp */
182236dd4d1SAnton Vorontsov __be32 rx_data_temp; /* Rx data temp */
183236dd4d1SAnton Vorontsov __be16 rx_u_ptr; /* Rx microcode return address temp */
184236dd4d1SAnton Vorontsov u8 reserved1[2]; /* reserved area */
185236dd4d1SAnton Vorontsov __be32 sof_tbl; /* SOF lookup table pointer */
186236dd4d1SAnton Vorontsov u8 sof_u_crc_temp; /* SOF micorcode CRC5 temp reg */
187236dd4d1SAnton Vorontsov u8 reserved2[0xdb];
188236dd4d1SAnton Vorontsov };
189236dd4d1SAnton Vorontsov
190236dd4d1SAnton Vorontsov /* Freescale USB Endpoint*/
191236dd4d1SAnton Vorontsov struct fhci_ep_pram {
192236dd4d1SAnton Vorontsov __be16 rx_base; /* Rx BD base address */
193236dd4d1SAnton Vorontsov __be16 tx_base; /* Tx BD base address */
194236dd4d1SAnton Vorontsov u8 rx_func_code; /* Rx function code */
195236dd4d1SAnton Vorontsov u8 tx_func_code; /* Tx function code */
196236dd4d1SAnton Vorontsov __be16 rx_buff_len; /* Rx buffer length */
197236dd4d1SAnton Vorontsov __be16 rx_bd_ptr; /* Rx BD pointer */
198236dd4d1SAnton Vorontsov __be16 tx_bd_ptr; /* Tx BD pointer */
199236dd4d1SAnton Vorontsov __be32 tx_state; /* Tx internal state */
200236dd4d1SAnton Vorontsov __be32 tx_ptr; /* Tx internal data pointer */
201236dd4d1SAnton Vorontsov __be16 tx_crc; /* temp transmit CRC */
202236dd4d1SAnton Vorontsov __be16 tx_cnt; /* Tx byte count */
203236dd4d1SAnton Vorontsov __be32 tx_temp; /* Tx temp */
204236dd4d1SAnton Vorontsov __be16 tx_u_ptr; /* Tx microcode return address temp */
205236dd4d1SAnton Vorontsov __be16 reserved;
206236dd4d1SAnton Vorontsov };
207236dd4d1SAnton Vorontsov
208236dd4d1SAnton Vorontsov struct fhci_controller_list {
209236dd4d1SAnton Vorontsov struct list_head ctrl_list; /* control endpoints */
210236dd4d1SAnton Vorontsov struct list_head bulk_list; /* bulk endpoints */
211236dd4d1SAnton Vorontsov struct list_head iso_list; /* isochronous endpoints */
212236dd4d1SAnton Vorontsov struct list_head intr_list; /* interruput endpoints */
213236dd4d1SAnton Vorontsov struct list_head done_list; /* done transfers */
214236dd4d1SAnton Vorontsov };
215236dd4d1SAnton Vorontsov
216236dd4d1SAnton Vorontsov struct virtual_root_hub {
217236dd4d1SAnton Vorontsov int dev_num; /* USB address of the root hub */
218236dd4d1SAnton Vorontsov u32 feature; /* indicates what feature has been set */
219236dd4d1SAnton Vorontsov struct usb_hub_status hub;
220236dd4d1SAnton Vorontsov struct usb_port_status port;
221236dd4d1SAnton Vorontsov };
222236dd4d1SAnton Vorontsov
223236dd4d1SAnton Vorontsov enum fhci_gpios {
224236dd4d1SAnton Vorontsov GPIO_USBOE = 0,
225236dd4d1SAnton Vorontsov GPIO_USBTP,
226236dd4d1SAnton Vorontsov GPIO_USBTN,
227236dd4d1SAnton Vorontsov GPIO_USBRP,
228236dd4d1SAnton Vorontsov GPIO_USBRN,
229236dd4d1SAnton Vorontsov /* these are optional */
230236dd4d1SAnton Vorontsov GPIO_SPEED,
231236dd4d1SAnton Vorontsov GPIO_POWER,
232236dd4d1SAnton Vorontsov NUM_GPIOS,
233236dd4d1SAnton Vorontsov };
234236dd4d1SAnton Vorontsov
235236dd4d1SAnton Vorontsov enum fhci_pins {
236236dd4d1SAnton Vorontsov PIN_USBOE = 0,
237236dd4d1SAnton Vorontsov PIN_USBTP,
238236dd4d1SAnton Vorontsov PIN_USBTN,
239236dd4d1SAnton Vorontsov NUM_PINS,
240236dd4d1SAnton Vorontsov };
241236dd4d1SAnton Vorontsov
242236dd4d1SAnton Vorontsov struct fhci_hcd {
243236dd4d1SAnton Vorontsov enum qe_clock fullspeed_clk;
244236dd4d1SAnton Vorontsov enum qe_clock lowspeed_clk;
245236dd4d1SAnton Vorontsov struct qe_pin *pins[NUM_PINS];
246*a4efdb8aSLinus Walleij struct gpio_desc *gpiods[NUM_GPIOS];
247236dd4d1SAnton Vorontsov
248cf61fdb9SGuilherme Maciel Ferreira struct qe_usb_ctlr __iomem *regs; /* I/O memory used to communicate */
249236dd4d1SAnton Vorontsov struct fhci_pram __iomem *pram; /* Parameter RAM */
250236dd4d1SAnton Vorontsov struct gtm_timer *timer;
251236dd4d1SAnton Vorontsov
252236dd4d1SAnton Vorontsov spinlock_t lock;
253236dd4d1SAnton Vorontsov struct fhci_usb *usb_lld; /* Low-level driver */
254236dd4d1SAnton Vorontsov struct virtual_root_hub *vroot_hub; /* the virtual root hub */
255236dd4d1SAnton Vorontsov int active_urbs;
256236dd4d1SAnton Vorontsov struct fhci_controller_list *hc_list;
257236dd4d1SAnton Vorontsov struct tasklet_struct *process_done_task; /* tasklet for done list */
258236dd4d1SAnton Vorontsov
259236dd4d1SAnton Vorontsov struct list_head empty_eds;
260236dd4d1SAnton Vorontsov struct list_head empty_tds;
261236dd4d1SAnton Vorontsov
262236dd4d1SAnton Vorontsov #ifdef CONFIG_FHCI_DEBUG
263236dd4d1SAnton Vorontsov int usb_irq_stat[13];
264236dd4d1SAnton Vorontsov struct dentry *dfs_root;
265236dd4d1SAnton Vorontsov #endif
266236dd4d1SAnton Vorontsov };
267236dd4d1SAnton Vorontsov
268236dd4d1SAnton Vorontsov #define USB_FRAME_USAGE 90
269236dd4d1SAnton Vorontsov #define FRAME_TIME_USAGE (USB_FRAME_USAGE*10) /* frame time usage */
270236dd4d1SAnton Vorontsov #define SW_FIX_TIME_BETWEEN_TRANSACTION 150 /* SW */
271236dd4d1SAnton Vorontsov #define MAX_BYTES_PER_FRAME (USB_FRAME_USAGE*15)
272236dd4d1SAnton Vorontsov #define MAX_PERIODIC_FRAME_USAGE 90
273236dd4d1SAnton Vorontsov
274236dd4d1SAnton Vorontsov /* transaction type */
275236dd4d1SAnton Vorontsov enum fhci_ta_type {
276236dd4d1SAnton Vorontsov FHCI_TA_IN = 0, /* input transaction */
277236dd4d1SAnton Vorontsov FHCI_TA_OUT, /* output transaction */
278236dd4d1SAnton Vorontsov FHCI_TA_SETUP, /* setup transaction */
279236dd4d1SAnton Vorontsov };
280236dd4d1SAnton Vorontsov
281236dd4d1SAnton Vorontsov /* transfer mode */
282236dd4d1SAnton Vorontsov enum fhci_tf_mode {
283236dd4d1SAnton Vorontsov FHCI_TF_CTRL = 0,
284236dd4d1SAnton Vorontsov FHCI_TF_ISO,
285236dd4d1SAnton Vorontsov FHCI_TF_BULK,
286236dd4d1SAnton Vorontsov FHCI_TF_INTR,
287236dd4d1SAnton Vorontsov };
288236dd4d1SAnton Vorontsov
289236dd4d1SAnton Vorontsov enum fhci_speed {
290236dd4d1SAnton Vorontsov FHCI_FULL_SPEED,
291236dd4d1SAnton Vorontsov FHCI_LOW_SPEED,
292236dd4d1SAnton Vorontsov };
293236dd4d1SAnton Vorontsov
294236dd4d1SAnton Vorontsov /* endpoint state */
295236dd4d1SAnton Vorontsov enum fhci_ed_state {
296236dd4d1SAnton Vorontsov FHCI_ED_NEW = 0, /* pipe is new */
297236dd4d1SAnton Vorontsov FHCI_ED_OPER, /* pipe is operating */
298236dd4d1SAnton Vorontsov FHCI_ED_URB_DEL, /* pipe is in hold because urb is being deleted */
299236dd4d1SAnton Vorontsov FHCI_ED_SKIP, /* skip this pipe */
300236dd4d1SAnton Vorontsov FHCI_ED_HALTED, /* pipe is halted */
301236dd4d1SAnton Vorontsov };
302236dd4d1SAnton Vorontsov
303236dd4d1SAnton Vorontsov enum fhci_port_status {
304236dd4d1SAnton Vorontsov FHCI_PORT_POWER_OFF = 0,
305236dd4d1SAnton Vorontsov FHCI_PORT_DISABLED,
306236dd4d1SAnton Vorontsov FHCI_PORT_DISCONNECTING,
307236dd4d1SAnton Vorontsov FHCI_PORT_WAITING, /* waiting for connection */
308236dd4d1SAnton Vorontsov FHCI_PORT_FULL, /* full speed connected */
309236dd4d1SAnton Vorontsov FHCI_PORT_LOW, /* low speed connected */
310236dd4d1SAnton Vorontsov };
311236dd4d1SAnton Vorontsov
312236dd4d1SAnton Vorontsov enum fhci_mem_alloc {
313236dd4d1SAnton Vorontsov MEM_CACHABLE_SYS = 0x00000001, /* primary DDR,cachable */
314236dd4d1SAnton Vorontsov MEM_NOCACHE_SYS = 0x00000004, /* primary DDR,non-cachable */
315236dd4d1SAnton Vorontsov MEM_SECONDARY = 0x00000002, /* either secondary DDR or SDRAM */
316236dd4d1SAnton Vorontsov MEM_PRAM = 0x00000008, /* multi-user RAM identifier */
317236dd4d1SAnton Vorontsov };
318236dd4d1SAnton Vorontsov
319236dd4d1SAnton Vorontsov /* USB default parameters*/
320236dd4d1SAnton Vorontsov #define DEFAULT_RING_LEN 8
321236dd4d1SAnton Vorontsov #define DEFAULT_DATA_MEM MEM_CACHABLE_SYS
322236dd4d1SAnton Vorontsov
323236dd4d1SAnton Vorontsov struct ed {
324236dd4d1SAnton Vorontsov u8 dev_addr; /* device address */
325236dd4d1SAnton Vorontsov u8 ep_addr; /* endpoint address */
326236dd4d1SAnton Vorontsov enum fhci_tf_mode mode; /* USB transfer mode */
327236dd4d1SAnton Vorontsov enum fhci_speed speed;
328236dd4d1SAnton Vorontsov unsigned int max_pkt_size;
329236dd4d1SAnton Vorontsov enum fhci_ed_state state;
330236dd4d1SAnton Vorontsov struct list_head td_list; /* a list of all queued TD to this pipe */
331236dd4d1SAnton Vorontsov struct list_head node;
332236dd4d1SAnton Vorontsov
333236dd4d1SAnton Vorontsov /* read only parameters, should be cleared upon initialization */
334236dd4d1SAnton Vorontsov u8 toggle_carry; /* toggle carry from the last TD submitted */
335f467ff4cSAlan Stern u16 next_iso; /* time stamp of next queued ISO transfer */
336236dd4d1SAnton Vorontsov struct td *td_head; /* a pointer to the current TD handled */
337236dd4d1SAnton Vorontsov };
338236dd4d1SAnton Vorontsov
339236dd4d1SAnton Vorontsov struct td {
340236dd4d1SAnton Vorontsov void *data; /* a pointer to the data buffer */
341236dd4d1SAnton Vorontsov unsigned int len; /* length of the data to be submitted */
34225985edcSLucas De Marchi unsigned int actual_len; /* actual bytes transferred on this td */
343236dd4d1SAnton Vorontsov enum fhci_ta_type type; /* transaction type */
344236dd4d1SAnton Vorontsov u8 toggle; /* toggle for next trans. within this TD */
345236dd4d1SAnton Vorontsov u16 iso_index; /* ISO transaction index */
346236dd4d1SAnton Vorontsov u16 start_frame; /* start frame time stamp */
347236dd4d1SAnton Vorontsov u16 interval; /* interval between trans. (for ISO/Intr) */
348236dd4d1SAnton Vorontsov u32 status; /* status of the TD */
349236dd4d1SAnton Vorontsov struct ed *ed; /* a handle to the corresponding ED */
350236dd4d1SAnton Vorontsov struct urb *urb; /* a handle to the corresponding URB */
351236dd4d1SAnton Vorontsov bool ioc; /* Inform On Completion */
352236dd4d1SAnton Vorontsov struct list_head node;
353236dd4d1SAnton Vorontsov
354236dd4d1SAnton Vorontsov /* read only parameters should be cleared upon initialization */
355236dd4d1SAnton Vorontsov struct packet *pkt;
356236dd4d1SAnton Vorontsov int nak_cnt;
357236dd4d1SAnton Vorontsov int error_cnt;
358236dd4d1SAnton Vorontsov struct list_head frame_lh;
359236dd4d1SAnton Vorontsov };
360236dd4d1SAnton Vorontsov
361236dd4d1SAnton Vorontsov struct packet {
362236dd4d1SAnton Vorontsov u8 *data; /* packet data */
363236dd4d1SAnton Vorontsov u32 len; /* packet length */
364236dd4d1SAnton Vorontsov u32 status; /* status of the packet - equivalent to the status
365236dd4d1SAnton Vorontsov * field for the corresponding structure td */
366236dd4d1SAnton Vorontsov u32 info; /* packet information */
367236dd4d1SAnton Vorontsov void __iomem *priv_data; /* private data of the driver (TDs or BDs) */
368236dd4d1SAnton Vorontsov };
369236dd4d1SAnton Vorontsov
370236dd4d1SAnton Vorontsov /* struct for each URB */
371236dd4d1SAnton Vorontsov #define URB_INPROGRESS 0
372236dd4d1SAnton Vorontsov #define URB_DEL 1
373236dd4d1SAnton Vorontsov
374236dd4d1SAnton Vorontsov /* URB states (state field) */
375236dd4d1SAnton Vorontsov #define US_BULK 0
376236dd4d1SAnton Vorontsov #define US_BULK0 1
377236dd4d1SAnton Vorontsov
378236dd4d1SAnton Vorontsov /* three setup states */
379236dd4d1SAnton Vorontsov #define US_CTRL_SETUP 2
380236dd4d1SAnton Vorontsov #define US_CTRL_DATA 1
381236dd4d1SAnton Vorontsov #define US_CTRL_ACK 0
382236dd4d1SAnton Vorontsov
383236dd4d1SAnton Vorontsov #define EP_ZERO 0
384236dd4d1SAnton Vorontsov
385236dd4d1SAnton Vorontsov struct urb_priv {
386236dd4d1SAnton Vorontsov int num_of_tds;
387236dd4d1SAnton Vorontsov int tds_cnt;
388236dd4d1SAnton Vorontsov int state;
389236dd4d1SAnton Vorontsov
390236dd4d1SAnton Vorontsov struct td **tds;
391236dd4d1SAnton Vorontsov struct ed *ed;
392236dd4d1SAnton Vorontsov struct timer_list time_out;
393236dd4d1SAnton Vorontsov };
394236dd4d1SAnton Vorontsov
395236dd4d1SAnton Vorontsov struct endpoint {
396236dd4d1SAnton Vorontsov /* Pointer to ep parameter RAM */
397236dd4d1SAnton Vorontsov struct fhci_ep_pram __iomem *ep_pram_ptr;
398236dd4d1SAnton Vorontsov
399236dd4d1SAnton Vorontsov /* Host transactions */
400236dd4d1SAnton Vorontsov struct usb_td __iomem *td_base; /* first TD in the ring */
401236dd4d1SAnton Vorontsov struct usb_td __iomem *conf_td; /* next TD for confirm after transac */
402236dd4d1SAnton Vorontsov struct usb_td __iomem *empty_td;/* next TD for new transaction req. */
40345465487SStefani Seibold struct kfifo empty_frame_Q; /* Empty frames list to use */
40445465487SStefani Seibold struct kfifo conf_frame_Q; /* frames passed to TDs,waiting for tx */
40545465487SStefani Seibold struct kfifo dummy_packets_Q;/* dummy packets for the CRC overun */
406236dd4d1SAnton Vorontsov
407236dd4d1SAnton Vorontsov bool already_pushed_dummy_bd;
408236dd4d1SAnton Vorontsov };
409236dd4d1SAnton Vorontsov
410236dd4d1SAnton Vorontsov /* struct for each 1mSec frame time */
411236dd4d1SAnton Vorontsov #define FRAME_IS_TRANSMITTED 0x00
412236dd4d1SAnton Vorontsov #define FRAME_TIMER_END_TRANSMISSION 0x01
413236dd4d1SAnton Vorontsov #define FRAME_DATA_END_TRANSMISSION 0x02
414236dd4d1SAnton Vorontsov #define FRAME_END_TRANSMISSION 0x03
415236dd4d1SAnton Vorontsov #define FRAME_IS_PREPARED 0x04
416236dd4d1SAnton Vorontsov
417236dd4d1SAnton Vorontsov struct fhci_time_frame {
418236dd4d1SAnton Vorontsov u16 frame_num; /* frame number */
419236dd4d1SAnton Vorontsov u16 total_bytes; /* total bytes submitted within this frame */
420236dd4d1SAnton Vorontsov u8 frame_status; /* flag that indicates to stop fill this frame */
421236dd4d1SAnton Vorontsov struct list_head tds_list; /* all tds of this frame */
422236dd4d1SAnton Vorontsov };
423236dd4d1SAnton Vorontsov
424236dd4d1SAnton Vorontsov /* internal driver structure*/
425236dd4d1SAnton Vorontsov struct fhci_usb {
426236dd4d1SAnton Vorontsov u16 saved_msk; /* saving of the USB mask register */
427236dd4d1SAnton Vorontsov struct endpoint *ep0; /* pointer for endpoint0 structure */
428236dd4d1SAnton Vorontsov int intr_nesting_cnt; /* interrupt nesting counter */
429236dd4d1SAnton Vorontsov u16 max_frame_usage; /* max frame time usage,in micro-sec */
430236dd4d1SAnton Vorontsov u16 max_bytes_per_frame; /* max byte can be tx in one time frame */
431236dd4d1SAnton Vorontsov u32 sw_transaction_time; /* sw complete trans time,in micro-sec */
432236dd4d1SAnton Vorontsov struct fhci_time_frame *actual_frame;
433236dd4d1SAnton Vorontsov struct fhci_controller_list *hc_list; /* main structure for hc */
434236dd4d1SAnton Vorontsov struct virtual_root_hub *vroot_hub;
435236dd4d1SAnton Vorontsov enum fhci_port_status port_status; /* v_rh port status */
436236dd4d1SAnton Vorontsov
437236dd4d1SAnton Vorontsov u32 (*transfer_confirm)(struct fhci_hcd *fhci);
438236dd4d1SAnton Vorontsov
439236dd4d1SAnton Vorontsov struct fhci_hcd *fhci;
440236dd4d1SAnton Vorontsov };
441236dd4d1SAnton Vorontsov
442236dd4d1SAnton Vorontsov /*
443236dd4d1SAnton Vorontsov * Various helpers and prototypes below.
444236dd4d1SAnton Vorontsov */
445236dd4d1SAnton Vorontsov
get_frame_num(struct fhci_hcd * fhci)446236dd4d1SAnton Vorontsov static inline u16 get_frame_num(struct fhci_hcd *fhci)
447236dd4d1SAnton Vorontsov {
448236dd4d1SAnton Vorontsov return in_be16(&fhci->pram->frame_num) & 0x07ff;
449236dd4d1SAnton Vorontsov }
450236dd4d1SAnton Vorontsov
451236dd4d1SAnton Vorontsov #define fhci_dbg(fhci, fmt, args...) \
452236dd4d1SAnton Vorontsov dev_dbg(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
453236dd4d1SAnton Vorontsov #define fhci_vdbg(fhci, fmt, args...) \
454236dd4d1SAnton Vorontsov dev_vdbg(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
455236dd4d1SAnton Vorontsov #define fhci_err(fhci, fmt, args...) \
456236dd4d1SAnton Vorontsov dev_err(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
457236dd4d1SAnton Vorontsov #define fhci_info(fhci, fmt, args...) \
458236dd4d1SAnton Vorontsov dev_info(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
459236dd4d1SAnton Vorontsov #define fhci_warn(fhci, fmt, args...) \
460236dd4d1SAnton Vorontsov dev_warn(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
461236dd4d1SAnton Vorontsov
hcd_to_fhci(struct usb_hcd * hcd)462236dd4d1SAnton Vorontsov static inline struct fhci_hcd *hcd_to_fhci(struct usb_hcd *hcd)
463236dd4d1SAnton Vorontsov {
464236dd4d1SAnton Vorontsov return (struct fhci_hcd *)hcd->hcd_priv;
465236dd4d1SAnton Vorontsov }
466236dd4d1SAnton Vorontsov
fhci_to_hcd(struct fhci_hcd * fhci)467236dd4d1SAnton Vorontsov static inline struct usb_hcd *fhci_to_hcd(struct fhci_hcd *fhci)
468236dd4d1SAnton Vorontsov {
469236dd4d1SAnton Vorontsov return container_of((void *)fhci, struct usb_hcd, hcd_priv);
470236dd4d1SAnton Vorontsov }
471236dd4d1SAnton Vorontsov
472236dd4d1SAnton Vorontsov /* fifo of pointers */
cq_new(struct kfifo * fifo,int size)47345465487SStefani Seibold static inline int cq_new(struct kfifo *fifo, int size)
474236dd4d1SAnton Vorontsov {
475c1e13f25SStefani Seibold return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL);
476236dd4d1SAnton Vorontsov }
477236dd4d1SAnton Vorontsov
cq_delete(struct kfifo * kfifo)478236dd4d1SAnton Vorontsov static inline void cq_delete(struct kfifo *kfifo)
479236dd4d1SAnton Vorontsov {
480236dd4d1SAnton Vorontsov kfifo_free(kfifo);
481236dd4d1SAnton Vorontsov }
482236dd4d1SAnton Vorontsov
cq_howmany(struct kfifo * kfifo)483236dd4d1SAnton Vorontsov static inline unsigned int cq_howmany(struct kfifo *kfifo)
484236dd4d1SAnton Vorontsov {
485e64c026dSStefani Seibold return kfifo_len(kfifo) / sizeof(void *);
486236dd4d1SAnton Vorontsov }
487236dd4d1SAnton Vorontsov
cq_put(struct kfifo * kfifo,void * p)488236dd4d1SAnton Vorontsov static inline int cq_put(struct kfifo *kfifo, void *p)
489236dd4d1SAnton Vorontsov {
4907acd72ebSStefani Seibold return kfifo_in(kfifo, (void *)&p, sizeof(p));
491236dd4d1SAnton Vorontsov }
492236dd4d1SAnton Vorontsov
cq_get(struct kfifo * kfifo)493236dd4d1SAnton Vorontsov static inline void *cq_get(struct kfifo *kfifo)
494236dd4d1SAnton Vorontsov {
4957f1cccd3SAnton Vorontsov unsigned int sz;
4967f1cccd3SAnton Vorontsov void *p;
497236dd4d1SAnton Vorontsov
4987f1cccd3SAnton Vorontsov sz = kfifo_out(kfifo, (void *)&p, sizeof(p));
4997f1cccd3SAnton Vorontsov if (sz != sizeof(p))
5007f1cccd3SAnton Vorontsov return NULL;
5017f1cccd3SAnton Vorontsov
502236dd4d1SAnton Vorontsov return p;
503236dd4d1SAnton Vorontsov }
504236dd4d1SAnton Vorontsov
505236dd4d1SAnton Vorontsov /* fhci-hcd.c */
506236dd4d1SAnton Vorontsov void fhci_start_sof_timer(struct fhci_hcd *fhci);
507236dd4d1SAnton Vorontsov void fhci_stop_sof_timer(struct fhci_hcd *fhci);
508236dd4d1SAnton Vorontsov u16 fhci_get_sof_timer_count(struct fhci_usb *usb);
509236dd4d1SAnton Vorontsov void fhci_usb_enable_interrupt(struct fhci_usb *usb);
510236dd4d1SAnton Vorontsov void fhci_usb_disable_interrupt(struct fhci_usb *usb);
511236dd4d1SAnton Vorontsov int fhci_ioports_check_bus_state(struct fhci_hcd *fhci);
512236dd4d1SAnton Vorontsov
513236dd4d1SAnton Vorontsov /* fhci-mem.c */
514236dd4d1SAnton Vorontsov void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td);
515236dd4d1SAnton Vorontsov void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed);
516236dd4d1SAnton Vorontsov struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci);
517236dd4d1SAnton Vorontsov struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
518236dd4d1SAnton Vorontsov struct urb_priv *urb_priv, struct ed *ed, u16 index,
519236dd4d1SAnton Vorontsov enum fhci_ta_type type, int toggle, u8 *data, u32 len,
520236dd4d1SAnton Vorontsov u16 interval, u16 start_frame, bool ioc);
521236dd4d1SAnton Vorontsov void fhci_add_tds_to_ed(struct ed *ed, struct td **td_list, int number);
522236dd4d1SAnton Vorontsov
523236dd4d1SAnton Vorontsov /* fhci-hub.c */
524236dd4d1SAnton Vorontsov void fhci_config_transceiver(struct fhci_hcd *fhci,
525236dd4d1SAnton Vorontsov enum fhci_port_status status);
526236dd4d1SAnton Vorontsov void fhci_port_disable(struct fhci_hcd *fhci);
527236dd4d1SAnton Vorontsov void fhci_port_enable(void *lld);
528236dd4d1SAnton Vorontsov void fhci_io_port_generate_reset(struct fhci_hcd *fhci);
529236dd4d1SAnton Vorontsov void fhci_port_reset(void *lld);
530236dd4d1SAnton Vorontsov int fhci_hub_status_data(struct usb_hcd *hcd, char *buf);
531236dd4d1SAnton Vorontsov int fhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
532236dd4d1SAnton Vorontsov u16 wIndex, char *buf, u16 wLength);
533236dd4d1SAnton Vorontsov
534236dd4d1SAnton Vorontsov /* fhci-tds.c */
535236dd4d1SAnton Vorontsov void fhci_flush_bds(struct fhci_usb *usb);
536236dd4d1SAnton Vorontsov void fhci_flush_actual_frame(struct fhci_usb *usb);
537236dd4d1SAnton Vorontsov u32 fhci_host_transaction(struct fhci_usb *usb, struct packet *pkt,
538236dd4d1SAnton Vorontsov enum fhci_ta_type trans_type, u8 dest_addr,
539236dd4d1SAnton Vorontsov u8 dest_ep, enum fhci_tf_mode trans_mode,
540236dd4d1SAnton Vorontsov enum fhci_speed dest_speed, u8 data_toggle);
541236dd4d1SAnton Vorontsov void fhci_host_transmit_actual_frame(struct fhci_usb *usb);
542236dd4d1SAnton Vorontsov void fhci_tx_conf_interrupt(struct fhci_usb *usb);
543236dd4d1SAnton Vorontsov void fhci_push_dummy_bd(struct endpoint *ep);
544236dd4d1SAnton Vorontsov u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
545236dd4d1SAnton Vorontsov u32 ring_len);
546236dd4d1SAnton Vorontsov void fhci_init_ep_registers(struct fhci_usb *usb,
547236dd4d1SAnton Vorontsov struct endpoint *ep,
548236dd4d1SAnton Vorontsov enum fhci_mem_alloc data_mem);
549236dd4d1SAnton Vorontsov void fhci_ep0_free(struct fhci_usb *usb);
550236dd4d1SAnton Vorontsov
551236dd4d1SAnton Vorontsov /* fhci-sched.c */
552236dd4d1SAnton Vorontsov extern struct tasklet_struct fhci_tasklet;
553236dd4d1SAnton Vorontsov void fhci_transaction_confirm(struct fhci_usb *usb, struct packet *pkt);
554236dd4d1SAnton Vorontsov void fhci_flush_all_transmissions(struct fhci_usb *usb);
555236dd4d1SAnton Vorontsov void fhci_schedule_transactions(struct fhci_usb *usb);
556236dd4d1SAnton Vorontsov void fhci_device_connected_interrupt(struct fhci_hcd *fhci);
557236dd4d1SAnton Vorontsov void fhci_device_disconnected_interrupt(struct fhci_hcd *fhci);
558236dd4d1SAnton Vorontsov void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb);
559236dd4d1SAnton Vorontsov u32 fhci_transfer_confirm_callback(struct fhci_hcd *fhci);
560236dd4d1SAnton Vorontsov irqreturn_t fhci_irq(struct usb_hcd *hcd);
561236dd4d1SAnton Vorontsov irqreturn_t fhci_frame_limit_timer_irq(int irq, void *_hcd);
562236dd4d1SAnton Vorontsov
563236dd4d1SAnton Vorontsov /* fhci-q.h */
564236dd4d1SAnton Vorontsov void fhci_urb_complete_free(struct fhci_hcd *fhci, struct urb *urb);
565236dd4d1SAnton Vorontsov struct td *fhci_remove_td_from_ed(struct ed *ed);
566236dd4d1SAnton Vorontsov struct td *fhci_remove_td_from_frame(struct fhci_time_frame *frame);
567236dd4d1SAnton Vorontsov void fhci_move_td_from_ed_to_done_list(struct fhci_usb *usb, struct ed *ed);
568236dd4d1SAnton Vorontsov struct td *fhci_peek_td_from_frame(struct fhci_time_frame *frame);
569236dd4d1SAnton Vorontsov void fhci_add_td_to_frame(struct fhci_time_frame *frame, struct td *td);
570236dd4d1SAnton Vorontsov struct td *fhci_remove_td_from_done_list(struct fhci_controller_list *p_list);
571236dd4d1SAnton Vorontsov void fhci_done_td(struct urb *urb, struct td *td);
572236dd4d1SAnton Vorontsov void fhci_del_ed_list(struct fhci_hcd *fhci, struct ed *ed);
573236dd4d1SAnton Vorontsov
574236dd4d1SAnton Vorontsov #ifdef CONFIG_FHCI_DEBUG
575236dd4d1SAnton Vorontsov
576236dd4d1SAnton Vorontsov void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er);
577236dd4d1SAnton Vorontsov void fhci_dfs_destroy(struct fhci_hcd *fhci);
578236dd4d1SAnton Vorontsov void fhci_dfs_create(struct fhci_hcd *fhci);
579236dd4d1SAnton Vorontsov
580236dd4d1SAnton Vorontsov #else
581236dd4d1SAnton Vorontsov
fhci_dbg_isr(struct fhci_hcd * fhci,int usb_er)582236dd4d1SAnton Vorontsov static inline void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er) {}
fhci_dfs_destroy(struct fhci_hcd * fhci)583236dd4d1SAnton Vorontsov static inline void fhci_dfs_destroy(struct fhci_hcd *fhci) {}
fhci_dfs_create(struct fhci_hcd * fhci)584236dd4d1SAnton Vorontsov static inline void fhci_dfs_create(struct fhci_hcd *fhci) {}
585236dd4d1SAnton Vorontsov
586236dd4d1SAnton Vorontsov #endif /* CONFIG_FHCI_DEBUG */
587236dd4d1SAnton Vorontsov
588236dd4d1SAnton Vorontsov #endif /* __FHCI_H */
589