2 * Freescale QUICC Engine USB Host Controller Driver
4 * Copyright (c) Freescale Semicondutor, Inc. 2006.
5 * Shlomi Gridish <gridish@freescale.com>
6 * Jerry Huang <Chang-Ming.Huang@freescale.com>
7 * Copyright (c) Logic Product Development, Inc. 2007
8 * Peter Barada <peterb@logicpd.com>
9 * Copyright (c) MontaVista Software, Inc. 2008.
10 * Anton Vorontsov <avorontsov@ru.mvista.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/kernel.h>
19 #include <linux/types.h>
20 #include <linux/delay.h>
21 #include <linux/slab.h>
22 #include <linux/list.h>
23 #include <linux/usb.h>
24 #include <linux/usb/hcd.h>
27 static void init_td(struct td
*td
)
29 memset(td
, 0, sizeof(*td
));
30 INIT_LIST_HEAD(&td
->node
);
31 INIT_LIST_HEAD(&td
->frame_lh
);
34 static void init_ed(struct ed
*ed
)
36 memset(ed
, 0, sizeof(*ed
));
37 INIT_LIST_HEAD(&ed
->td_list
);
38 INIT_LIST_HEAD(&ed
->node
);
41 static struct td
*get_empty_td(struct fhci_hcd
*fhci
)
45 if (!list_empty(&fhci
->empty_tds
)) {
46 td
= list_entry(fhci
->empty_tds
.next
, struct td
, node
);
47 list_del(fhci
->empty_tds
.next
);
49 td
= kmalloc(sizeof(*td
), GFP_ATOMIC
);
51 fhci_err(fhci
, "No memory to allocate to TD\n");
59 void fhci_recycle_empty_td(struct fhci_hcd
*fhci
, struct td
*td
)
62 list_add(&td
->node
, &fhci
->empty_tds
);
65 struct ed
*fhci_get_empty_ed(struct fhci_hcd
*fhci
)
69 if (!list_empty(&fhci
->empty_eds
)) {
70 ed
= list_entry(fhci
->empty_eds
.next
, struct ed
, node
);
71 list_del(fhci
->empty_eds
.next
);
73 ed
= kmalloc(sizeof(*ed
), GFP_ATOMIC
);
75 fhci_err(fhci
, "No memory to allocate to ED\n");
83 void fhci_recycle_empty_ed(struct fhci_hcd
*fhci
, struct ed
*ed
)
86 list_add(&ed
->node
, &fhci
->empty_eds
);
89 struct td
*fhci_td_fill(struct fhci_hcd
*fhci
, struct urb
*urb
,
90 struct urb_priv
*urb_priv
, struct ed
*ed
, u16 index
,
91 enum fhci_ta_type type
, int toggle
, u8
*data
, u32 len
,
92 u16 interval
, u16 start_frame
, bool ioc
)
94 struct td
*td
= get_empty_td(fhci
);
105 td
->iso_index
= index
;
106 td
->interval
= interval
;
107 td
->start_frame
= start_frame
;
109 td
->status
= USB_TD_OK
;
111 urb_priv
->tds
[index
] = td
;