This source file includes following definitions.
- get_frame_num
- hcd_to_fhci
- fhci_to_hcd
- cq_new
- cq_delete
- cq_howmany
- cq_put
- cq_get
- fhci_dbg_isr
- fhci_dfs_destroy
- fhci_dfs_create
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #ifndef __FHCI_H
15 #define __FHCI_H
16
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/bug.h>
20 #include <linux/spinlock.h>
21 #include <linux/interrupt.h>
22 #include <linux/kfifo.h>
23 #include <linux/io.h>
24 #include <linux/usb.h>
25 #include <linux/usb/hcd.h>
26 #include <soc/fsl/qe/qe.h>
27 #include <soc/fsl/qe/immap_qe.h>
28
29 #define USB_CLOCK 48000000
30
31 #define FHCI_PRAM_SIZE 0x100
32
33 #define MAX_EDS 32
34 #define MAX_TDS 32
35
36
37
38 #define CRC_SIZE 2
39
40
41 #define PROTOCOL_OVERHEAD 7
42
43
44 #define PKT_PID_DATA0 0x80000000
45 #define PKT_PID_DATA1 0x40000000
46 #define PKT_PID_SETUP 0x20000000
47 #define PKT_SETUP_STATUS 0x10000000
48 #define PKT_SETADDR_STATUS 0x08000000
49 #define PKT_SET_HOST_LAST 0x04000000
50 #define PKT_HOST_DATA 0x02000000
51 #define PKT_FIRST_IN_FRAME 0x01000000
52 #define PKT_TOKEN_FRAME 0x00800000
53 #define PKT_ZLP 0x00400000
54 #define PKT_IN_TOKEN_FRAME 0x00200000
55 #define PKT_OUT_TOKEN_FRAME 0x00100000
56 #define PKT_SETUP_TOKEN_FRAME 0x00080000
57 #define PKT_STALL_FRAME 0x00040000
58 #define PKT_NACK_FRAME 0x00020000
59 #define PKT_NO_PID 0x00010000
60 #define PKT_NO_CRC 0x00008000
61 #define PKT_HOST_COMMAND 0x00004000
62 #define PKT_DUMMY_PACKET 0x00002000
63 #define PKT_LOW_SPEED_PACKET 0x00001000
64
65 #define TRANS_OK (0)
66 #define TRANS_INPROGRESS (-1)
67 #define TRANS_DISCARD (-2)
68 #define TRANS_FAIL (-3)
69
70 #define PS_INT 0
71 #define PS_DISCONNECTED 1
72 #define PS_CONNECTED 2
73 #define PS_READY 3
74 #define PS_MISSING 4
75
76
77 #define USB_TD_OK 0x00000000
78 #define USB_TD_INPROGRESS 0x80000000
79 #define USB_TD_RX_ER_NONOCT 0x40000000
80 #define USB_TD_RX_ER_BITSTUFF 0x20000000
81 #define USB_TD_RX_ER_CRC 0x10000000
82 #define USB_TD_RX_ER_OVERUN 0x08000000
83 #define USB_TD_RX_ER_PID 0x04000000
84 #define USB_TD_RX_DATA_UNDERUN 0x02000000
85 #define USB_TD_RX_DATA_OVERUN 0x01000000
86 #define USB_TD_TX_ER_NAK 0x00800000
87 #define USB_TD_TX_ER_STALL 0x00400000
88 #define USB_TD_TX_ER_TIMEOUT 0x00200000
89 #define USB_TD_TX_ER_UNDERUN 0x00100000
90
91 #define USB_TD_ERROR (USB_TD_RX_ER_NONOCT | USB_TD_RX_ER_BITSTUFF | \
92 USB_TD_RX_ER_CRC | USB_TD_RX_ER_OVERUN | USB_TD_RX_ER_PID | \
93 USB_TD_RX_DATA_UNDERUN | USB_TD_RX_DATA_OVERUN | \
94 USB_TD_TX_ER_NAK | USB_TD_TX_ER_STALL | \
95 USB_TD_TX_ER_TIMEOUT | USB_TD_TX_ER_UNDERUN)
96
97
98 #define USB_TD_TOGGLE_DATA0 0
99 #define USB_TD_TOGGLE_DATA1 1
100 #define USB_TD_TOGGLE_CARRY 2
101
102
103
104
105 #define BUS_MODE_GBL 0x20
106 #define BUS_MODE_BO 0x18
107 #define BUS_MODE_BO_BE 0x10
108 #define BUS_MODE_DTB 0x02
109
110
111
112
113 #define USB_MODE_EN 0x01
114 #define USB_MODE_HOST 0x02
115 #define USB_MODE_TEST 0x04
116 #define USB_MODE_SFTE 0x08
117 #define USB_MODE_RESUME 0x40
118 #define USB_MODE_LSS 0x80
119
120
121 #define USB_SLVADDR_MASK 0x7F
122
123
124 #define USB_EPNUM_MASK 0xF000
125 #define USB_EPNUM_SHIFT 12
126
127 #define USB_TRANS_MODE_SHIFT 8
128 #define USB_TRANS_CTR 0x0000
129 #define USB_TRANS_INT 0x0100
130 #define USB_TRANS_BULK 0x0200
131 #define USB_TRANS_ISO 0x0300
132
133 #define USB_EP_MF 0x0020
134 #define USB_EP_RTE 0x0010
135
136 #define USB_THS_SHIFT 2
137 #define USB_THS_MASK 0x000c
138 #define USB_THS_NORMAL 0x0
139 #define USB_THS_IGNORE_IN 0x0004
140 #define USB_THS_NACK 0x0008
141 #define USB_THS_STALL 0x000c
142
143 #define USB_RHS_SHIFT 0
144 #define USB_RHS_MASK 0x0003
145 #define USB_RHS_NORMAL 0x0
146 #define USB_RHS_IGNORE_OUT 0x0001
147 #define USB_RHS_NACK 0x0002
148 #define USB_RHS_STALL 0x0003
149
150 #define USB_RTHS_MASK 0x000f
151
152
153 #define USB_CMD_STR_FIFO 0x80
154 #define USB_CMD_FLUSH_FIFO 0x40
155 #define USB_CMD_ISFT 0x20
156 #define USB_CMD_DSFT 0x10
157 #define USB_CMD_EP_MASK 0x03
158
159
160 #define USB_E_MSF_MASK 0x0800
161 #define USB_E_SFT_MASK 0x0400
162 #define USB_E_RESET_MASK 0x0200
163 #define USB_E_IDLE_MASK 0x0100
164 #define USB_E_TXE4_MASK 0x0080
165 #define USB_E_TXE3_MASK 0x0040
166 #define USB_E_TXE2_MASK 0x0020
167 #define USB_E_TXE1_MASK 0x0010
168 #define USB_E_SOF_MASK 0x0008
169 #define USB_E_BSY_MASK 0x0004
170 #define USB_E_TXB_MASK 0x0002
171 #define USB_E_RXB_MASK 0x0001
172
173
174 struct fhci_pram {
175 __be16 ep_ptr[4];
176 __be32 rx_state;
177 __be32 rx_ptr;
178 __be16 frame_num;
179 __be16 rx_cnt;
180 __be32 rx_temp;
181 __be32 rx_data_temp;
182 __be16 rx_u_ptr;
183 u8 reserved1[2];
184 __be32 sof_tbl;
185 u8 sof_u_crc_temp;
186 u8 reserved2[0xdb];
187 };
188
189
190 struct fhci_ep_pram {
191 __be16 rx_base;
192 __be16 tx_base;
193 u8 rx_func_code;
194 u8 tx_func_code;
195 __be16 rx_buff_len;
196 __be16 rx_bd_ptr;
197 __be16 tx_bd_ptr;
198 __be32 tx_state;
199 __be32 tx_ptr;
200 __be16 tx_crc;
201 __be16 tx_cnt;
202 __be32 tx_temp;
203 __be16 tx_u_ptr;
204 __be16 reserved;
205 };
206
207 struct fhci_controller_list {
208 struct list_head ctrl_list;
209 struct list_head bulk_list;
210 struct list_head iso_list;
211 struct list_head intr_list;
212 struct list_head done_list;
213 };
214
215 struct virtual_root_hub {
216 int dev_num;
217 u32 feature;
218 struct usb_hub_status hub;
219 struct usb_port_status port;
220 };
221
222 enum fhci_gpios {
223 GPIO_USBOE = 0,
224 GPIO_USBTP,
225 GPIO_USBTN,
226 GPIO_USBRP,
227 GPIO_USBRN,
228
229 GPIO_SPEED,
230 GPIO_POWER,
231 NUM_GPIOS,
232 };
233
234 enum fhci_pins {
235 PIN_USBOE = 0,
236 PIN_USBTP,
237 PIN_USBTN,
238 NUM_PINS,
239 };
240
241 struct fhci_hcd {
242 enum qe_clock fullspeed_clk;
243 enum qe_clock lowspeed_clk;
244 struct qe_pin *pins[NUM_PINS];
245 int gpios[NUM_GPIOS];
246 bool alow_gpios[NUM_GPIOS];
247
248 struct qe_usb_ctlr __iomem *regs;
249 struct fhci_pram __iomem *pram;
250 struct gtm_timer *timer;
251
252 spinlock_t lock;
253 struct fhci_usb *usb_lld;
254 struct virtual_root_hub *vroot_hub;
255 int active_urbs;
256 struct fhci_controller_list *hc_list;
257 struct tasklet_struct *process_done_task;
258
259 struct list_head empty_eds;
260 struct list_head empty_tds;
261
262 #ifdef CONFIG_FHCI_DEBUG
263 int usb_irq_stat[13];
264 struct dentry *dfs_root;
265 #endif
266 };
267
268 #define USB_FRAME_USAGE 90
269 #define FRAME_TIME_USAGE (USB_FRAME_USAGE*10)
270 #define SW_FIX_TIME_BETWEEN_TRANSACTION 150
271 #define MAX_BYTES_PER_FRAME (USB_FRAME_USAGE*15)
272 #define MAX_PERIODIC_FRAME_USAGE 90
273
274
275 enum fhci_ta_type {
276 FHCI_TA_IN = 0,
277 FHCI_TA_OUT,
278 FHCI_TA_SETUP,
279 };
280
281
282 enum fhci_tf_mode {
283 FHCI_TF_CTRL = 0,
284 FHCI_TF_ISO,
285 FHCI_TF_BULK,
286 FHCI_TF_INTR,
287 };
288
289 enum fhci_speed {
290 FHCI_FULL_SPEED,
291 FHCI_LOW_SPEED,
292 };
293
294
295 enum fhci_ed_state {
296 FHCI_ED_NEW = 0,
297 FHCI_ED_OPER,
298 FHCI_ED_URB_DEL,
299 FHCI_ED_SKIP,
300 FHCI_ED_HALTED,
301 };
302
303 enum fhci_port_status {
304 FHCI_PORT_POWER_OFF = 0,
305 FHCI_PORT_DISABLED,
306 FHCI_PORT_DISCONNECTING,
307 FHCI_PORT_WAITING,
308 FHCI_PORT_FULL,
309 FHCI_PORT_LOW,
310 };
311
312 enum fhci_mem_alloc {
313 MEM_CACHABLE_SYS = 0x00000001,
314 MEM_NOCACHE_SYS = 0x00000004,
315 MEM_SECONDARY = 0x00000002,
316 MEM_PRAM = 0x00000008,
317 };
318
319
320 #define DEFAULT_RING_LEN 8
321 #define DEFAULT_DATA_MEM MEM_CACHABLE_SYS
322
323 struct ed {
324 u8 dev_addr;
325 u8 ep_addr;
326 enum fhci_tf_mode mode;
327 enum fhci_speed speed;
328 unsigned int max_pkt_size;
329 enum fhci_ed_state state;
330 struct list_head td_list;
331 struct list_head node;
332
333
334 u8 toggle_carry;
335 u16 next_iso;
336 struct td *td_head;
337 };
338
339 struct td {
340 void *data;
341 unsigned int len;
342 unsigned int actual_len;
343 enum fhci_ta_type type;
344 u8 toggle;
345 u16 iso_index;
346 u16 start_frame;
347 u16 interval;
348 u32 status;
349 struct ed *ed;
350 struct urb *urb;
351 bool ioc;
352 struct list_head node;
353
354
355 struct packet *pkt;
356 int nak_cnt;
357 int error_cnt;
358 struct list_head frame_lh;
359 };
360
361 struct packet {
362 u8 *data;
363 u32 len;
364 u32 status;
365
366 u32 info;
367 void __iomem *priv_data;
368 };
369
370
371 #define URB_INPROGRESS 0
372 #define URB_DEL 1
373
374
375 #define US_BULK 0
376 #define US_BULK0 1
377
378
379 #define US_CTRL_SETUP 2
380 #define US_CTRL_DATA 1
381 #define US_CTRL_ACK 0
382
383 #define EP_ZERO 0
384
385 struct urb_priv {
386 int num_of_tds;
387 int tds_cnt;
388 int state;
389
390 struct td **tds;
391 struct ed *ed;
392 struct timer_list time_out;
393 };
394
395 struct endpoint {
396
397 struct fhci_ep_pram __iomem *ep_pram_ptr;
398
399
400 struct usb_td __iomem *td_base;
401 struct usb_td __iomem *conf_td;
402 struct usb_td __iomem *empty_td;
403 struct kfifo empty_frame_Q;
404 struct kfifo conf_frame_Q;
405 struct kfifo dummy_packets_Q;
406
407 bool already_pushed_dummy_bd;
408 };
409
410
411 #define FRAME_IS_TRANSMITTED 0x00
412 #define FRAME_TIMER_END_TRANSMISSION 0x01
413 #define FRAME_DATA_END_TRANSMISSION 0x02
414 #define FRAME_END_TRANSMISSION 0x03
415 #define FRAME_IS_PREPARED 0x04
416
417 struct fhci_time_frame {
418 u16 frame_num;
419 u16 total_bytes;
420 u8 frame_status;
421 struct list_head tds_list;
422 };
423
424
425 struct fhci_usb {
426 u16 saved_msk;
427 struct endpoint *ep0;
428 int intr_nesting_cnt;
429 u16 max_frame_usage;
430 u16 max_bytes_per_frame;
431 u32 sw_transaction_time;
432 struct fhci_time_frame *actual_frame;
433 struct fhci_controller_list *hc_list;
434 struct virtual_root_hub *vroot_hub;
435 enum fhci_port_status port_status;
436
437 u32 (*transfer_confirm)(struct fhci_hcd *fhci);
438
439 struct fhci_hcd *fhci;
440 };
441
442
443
444
445
446 static inline u16 get_frame_num(struct fhci_hcd *fhci)
447 {
448 return in_be16(&fhci->pram->frame_num) & 0x07ff;
449 }
450
451 #define fhci_dbg(fhci, fmt, args...) \
452 dev_dbg(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
453 #define fhci_vdbg(fhci, fmt, args...) \
454 dev_vdbg(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
455 #define fhci_err(fhci, fmt, args...) \
456 dev_err(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
457 #define fhci_info(fhci, fmt, args...) \
458 dev_info(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
459 #define fhci_warn(fhci, fmt, args...) \
460 dev_warn(fhci_to_hcd(fhci)->self.controller, fmt, ##args)
461
462 static inline struct fhci_hcd *hcd_to_fhci(struct usb_hcd *hcd)
463 {
464 return (struct fhci_hcd *)hcd->hcd_priv;
465 }
466
467 static inline struct usb_hcd *fhci_to_hcd(struct fhci_hcd *fhci)
468 {
469 return container_of((void *)fhci, struct usb_hcd, hcd_priv);
470 }
471
472
473 static inline int cq_new(struct kfifo *fifo, int size)
474 {
475 return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL);
476 }
477
478 static inline void cq_delete(struct kfifo *kfifo)
479 {
480 kfifo_free(kfifo);
481 }
482
483 static inline unsigned int cq_howmany(struct kfifo *kfifo)
484 {
485 return kfifo_len(kfifo) / sizeof(void *);
486 }
487
488 static inline int cq_put(struct kfifo *kfifo, void *p)
489 {
490 return kfifo_in(kfifo, (void *)&p, sizeof(p));
491 }
492
493 static inline void *cq_get(struct kfifo *kfifo)
494 {
495 unsigned int sz;
496 void *p;
497
498 sz = kfifo_out(kfifo, (void *)&p, sizeof(p));
499 if (sz != sizeof(p))
500 return NULL;
501
502 return p;
503 }
504
505
506 void fhci_start_sof_timer(struct fhci_hcd *fhci);
507 void fhci_stop_sof_timer(struct fhci_hcd *fhci);
508 u16 fhci_get_sof_timer_count(struct fhci_usb *usb);
509 void fhci_usb_enable_interrupt(struct fhci_usb *usb);
510 void fhci_usb_disable_interrupt(struct fhci_usb *usb);
511 int fhci_ioports_check_bus_state(struct fhci_hcd *fhci);
512
513
514 void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td);
515 void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed);
516 struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci);
517 struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
518 struct urb_priv *urb_priv, struct ed *ed, u16 index,
519 enum fhci_ta_type type, int toggle, u8 *data, u32 len,
520 u16 interval, u16 start_frame, bool ioc);
521 void fhci_add_tds_to_ed(struct ed *ed, struct td **td_list, int number);
522
523
524 void fhci_config_transceiver(struct fhci_hcd *fhci,
525 enum fhci_port_status status);
526 void fhci_port_disable(struct fhci_hcd *fhci);
527 void fhci_port_enable(void *lld);
528 void fhci_io_port_generate_reset(struct fhci_hcd *fhci);
529 void fhci_port_reset(void *lld);
530 int fhci_hub_status_data(struct usb_hcd *hcd, char *buf);
531 int fhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
532 u16 wIndex, char *buf, u16 wLength);
533
534
535 void fhci_flush_bds(struct fhci_usb *usb);
536 void fhci_flush_actual_frame(struct fhci_usb *usb);
537 u32 fhci_host_transaction(struct fhci_usb *usb, struct packet *pkt,
538 enum fhci_ta_type trans_type, u8 dest_addr,
539 u8 dest_ep, enum fhci_tf_mode trans_mode,
540 enum fhci_speed dest_speed, u8 data_toggle);
541 void fhci_host_transmit_actual_frame(struct fhci_usb *usb);
542 void fhci_tx_conf_interrupt(struct fhci_usb *usb);
543 void fhci_push_dummy_bd(struct endpoint *ep);
544 u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
545 u32 ring_len);
546 void fhci_init_ep_registers(struct fhci_usb *usb,
547 struct endpoint *ep,
548 enum fhci_mem_alloc data_mem);
549 void fhci_ep0_free(struct fhci_usb *usb);
550
551
552 extern struct tasklet_struct fhci_tasklet;
553 void fhci_transaction_confirm(struct fhci_usb *usb, struct packet *pkt);
554 void fhci_flush_all_transmissions(struct fhci_usb *usb);
555 void fhci_schedule_transactions(struct fhci_usb *usb);
556 void fhci_device_connected_interrupt(struct fhci_hcd *fhci);
557 void fhci_device_disconnected_interrupt(struct fhci_hcd *fhci);
558 void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb);
559 u32 fhci_transfer_confirm_callback(struct fhci_hcd *fhci);
560 irqreturn_t fhci_irq(struct usb_hcd *hcd);
561 irqreturn_t fhci_frame_limit_timer_irq(int irq, void *_hcd);
562
563
564 void fhci_urb_complete_free(struct fhci_hcd *fhci, struct urb *urb);
565 struct td *fhci_remove_td_from_ed(struct ed *ed);
566 struct td *fhci_remove_td_from_frame(struct fhci_time_frame *frame);
567 void fhci_move_td_from_ed_to_done_list(struct fhci_usb *usb, struct ed *ed);
568 struct td *fhci_peek_td_from_frame(struct fhci_time_frame *frame);
569 void fhci_add_td_to_frame(struct fhci_time_frame *frame, struct td *td);
570 struct td *fhci_remove_td_from_done_list(struct fhci_controller_list *p_list);
571 void fhci_done_td(struct urb *urb, struct td *td);
572 void fhci_del_ed_list(struct fhci_hcd *fhci, struct ed *ed);
573
574 #ifdef CONFIG_FHCI_DEBUG
575
576 void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er);
577 void fhci_dfs_destroy(struct fhci_hcd *fhci);
578 void fhci_dfs_create(struct fhci_hcd *fhci);
579
580 #else
581
582 static inline void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er) {}
583 static inline void fhci_dfs_destroy(struct fhci_hcd *fhci) {}
584 static inline void fhci_dfs_create(struct fhci_hcd *fhci) {}
585
586 #endif
587
588 #endif