Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Freescale QUICC Engine USB Host Controller Driver
  4 *
  5 * Copyright (c) Freescale Semicondutor, Inc. 2006.
  6 *               Shlomi Gridish <gridish@freescale.com>
  7 *               Jerry Huang <Chang-Ming.Huang@freescale.com>
  8 * Copyright (c) Logic Product Development, Inc. 2007
  9 *               Peter Barada <peterb@logicpd.com>
 10 * Copyright (c) MontaVista Software, Inc. 2008.
 11 *               Anton Vorontsov <avorontsov@ru.mvista.com>
 
 
 
 
 
 12 */
 13
 14#include <linux/kernel.h>
 15#include <linux/types.h>
 16#include <linux/delay.h>
 17#include <linux/slab.h>
 18#include <linux/list.h>
 19#include <linux/usb.h>
 20#include <linux/usb/hcd.h>
 21#include "fhci.h"
 22
 23static void init_td(struct td *td)
 24{
 25	memset(td, 0, sizeof(*td));
 26	INIT_LIST_HEAD(&td->node);
 27	INIT_LIST_HEAD(&td->frame_lh);
 28}
 29
 30static void init_ed(struct ed *ed)
 31{
 32	memset(ed, 0, sizeof(*ed));
 33	INIT_LIST_HEAD(&ed->td_list);
 34	INIT_LIST_HEAD(&ed->node);
 35}
 36
 37static struct td *get_empty_td(struct fhci_hcd *fhci)
 38{
 39	struct td *td;
 40
 41	if (!list_empty(&fhci->empty_tds)) {
 42		td = list_entry(fhci->empty_tds.next, struct td, node);
 43		list_del(fhci->empty_tds.next);
 44	} else {
 45		td = kmalloc(sizeof(*td), GFP_ATOMIC);
 46		if (!td)
 47			fhci_err(fhci, "No memory to allocate to TD\n");
 48		else
 49			init_td(td);
 50	}
 51
 52	return td;
 53}
 54
 55void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
 56{
 57	init_td(td);
 58	list_add(&td->node, &fhci->empty_tds);
 59}
 60
 61struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
 62{
 63	struct ed *ed;
 64
 65	if (!list_empty(&fhci->empty_eds)) {
 66		ed = list_entry(fhci->empty_eds.next, struct ed, node);
 67		list_del(fhci->empty_eds.next);
 68	} else {
 69		ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
 70		if (!ed)
 71			fhci_err(fhci, "No memory to allocate to ED\n");
 72		else
 73			init_ed(ed);
 74	}
 75
 76	return ed;
 77}
 78
 79void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
 80{
 81	init_ed(ed);
 82	list_add(&ed->node, &fhci->empty_eds);
 83}
 84
 85struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
 86			struct urb_priv *urb_priv, struct ed *ed, u16 index,
 87			enum fhci_ta_type type, int toggle, u8 *data, u32 len,
 88			u16 interval, u16 start_frame, bool ioc)
 89{
 90	struct td *td = get_empty_td(fhci);
 91
 92	if (!td)
 93		return NULL;
 94
 95	td->urb = urb;
 96	td->ed = ed;
 97	td->type = type;
 98	td->toggle = toggle;
 99	td->data = data;
100	td->len = len;
101	td->iso_index = index;
102	td->interval = interval;
103	td->start_frame = start_frame;
104	td->ioc = ioc;
105	td->status = USB_TD_OK;
106
107	urb_priv->tds[index] = td;
108
109	return td;
110}
v3.1
 
  1/*
  2 * Freescale QUICC Engine USB Host Controller Driver
  3 *
  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>
 11 *
 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.
 16 */
 17
 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>
 25#include "fhci.h"
 26
 27static void init_td(struct td *td)
 28{
 29	memset(td, 0, sizeof(*td));
 30	INIT_LIST_HEAD(&td->node);
 31	INIT_LIST_HEAD(&td->frame_lh);
 32}
 33
 34static void init_ed(struct ed *ed)
 35{
 36	memset(ed, 0, sizeof(*ed));
 37	INIT_LIST_HEAD(&ed->td_list);
 38	INIT_LIST_HEAD(&ed->node);
 39}
 40
 41static struct td *get_empty_td(struct fhci_hcd *fhci)
 42{
 43	struct td *td;
 44
 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);
 48	} else {
 49		td = kmalloc(sizeof(*td), GFP_ATOMIC);
 50		if (!td)
 51			fhci_err(fhci, "No memory to allocate to TD\n");
 52		else
 53			init_td(td);
 54	}
 55
 56	return td;
 57}
 58
 59void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
 60{
 61	init_td(td);
 62	list_add(&td->node, &fhci->empty_tds);
 63}
 64
 65struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
 66{
 67	struct ed *ed;
 68
 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);
 72	} else {
 73		ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
 74		if (!ed)
 75			fhci_err(fhci, "No memory to allocate to ED\n");
 76		else
 77			init_ed(ed);
 78	}
 79
 80	return ed;
 81}
 82
 83void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
 84{
 85	init_ed(ed);
 86	list_add(&ed->node, &fhci->empty_eds);
 87}
 88
 89struct 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)
 93{
 94	struct td *td = get_empty_td(fhci);
 95
 96	if (!td)
 97		return NULL;
 98
 99	td->urb = urb;
100	td->ed = ed;
101	td->type = type;
102	td->toggle = toggle;
103	td->data = data;
104	td->len = len;
105	td->iso_index = index;
106	td->interval = interval;
107	td->start_frame = start_frame;
108	td->ioc = ioc;
109	td->status = USB_TD_OK;
110
111	urb_priv->tds[index] = td;
112
113	return td;
114}