2012-11-06 13:48:21 +00:00
|
|
|
#include <common.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2020-07-19 16:15:55 +00:00
|
|
|
#include <dm.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2013-06-04 09:10:01 +00:00
|
|
|
#include <watchdog.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2012-11-06 13:48:21 +00:00
|
|
|
#include <linux/usb/ch9.h>
|
|
|
|
#include <linux/usb/gadget.h>
|
|
|
|
|
|
|
|
#include <usb.h>
|
|
|
|
#include "linux-compat.h"
|
|
|
|
#include "usb-compat.h"
|
|
|
|
#include "musb_core.h"
|
|
|
|
#include "musb_host.h"
|
|
|
|
#include "musb_gadget.h"
|
2015-06-17 19:33:57 +00:00
|
|
|
#include "musb_uboot.h"
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2015-08-04 15:04:06 +00:00
|
|
|
#ifdef CONFIG_USB_MUSB_HOST
|
2015-01-11 19:34:54 +00:00
|
|
|
struct int_queue {
|
|
|
|
struct usb_host_endpoint hep;
|
|
|
|
struct urb urb;
|
|
|
|
};
|
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_USB)
|
2015-06-17 19:33:57 +00:00
|
|
|
struct musb_host_data musb_host;
|
2015-06-17 19:33:58 +00:00
|
|
|
#endif
|
2012-11-06 13:48:21 +00:00
|
|
|
|
|
|
|
static void musb_host_complete_urb(struct urb *urb)
|
|
|
|
{
|
|
|
|
urb->dev->status &= ~USB_ST_NOT_PROC;
|
|
|
|
urb->dev->act_len = urb->actual_length;
|
|
|
|
}
|
|
|
|
|
2015-01-11 19:34:53 +00:00
|
|
|
static void construct_urb(struct urb *urb, struct usb_host_endpoint *hep,
|
|
|
|
struct usb_device *dev, int endpoint_type,
|
|
|
|
unsigned long pipe, void *buffer, int len,
|
|
|
|
struct devrequest *setup, int interval)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
|
|
|
int epnum = usb_pipeendpoint(pipe);
|
|
|
|
int is_in = usb_pipein(pipe);
|
|
|
|
|
2015-01-11 19:34:53 +00:00
|
|
|
memset(urb, 0, sizeof(struct urb));
|
|
|
|
memset(hep, 0, sizeof(struct usb_host_endpoint));
|
|
|
|
INIT_LIST_HEAD(&hep->urb_list);
|
|
|
|
INIT_LIST_HEAD(&urb->urb_list);
|
|
|
|
urb->ep = hep;
|
|
|
|
urb->complete = musb_host_complete_urb;
|
|
|
|
urb->status = -EINPROGRESS;
|
|
|
|
urb->dev = dev;
|
|
|
|
urb->pipe = pipe;
|
|
|
|
urb->transfer_buffer = buffer;
|
|
|
|
urb->transfer_dma = (unsigned long)buffer;
|
|
|
|
urb->transfer_buffer_length = len;
|
|
|
|
urb->setup_packet = (unsigned char *)setup;
|
|
|
|
|
|
|
|
urb->ep->desc.wMaxPacketSize =
|
2012-11-06 13:48:21 +00:00
|
|
|
__cpu_to_le16(is_in ? dev->epmaxpacketin[epnum] :
|
|
|
|
dev->epmaxpacketout[epnum]);
|
2015-01-11 19:34:53 +00:00
|
|
|
urb->ep->desc.bmAttributes = endpoint_type;
|
|
|
|
urb->ep->desc.bEndpointAddress =
|
2012-11-06 13:48:21 +00:00
|
|
|
(is_in ? USB_DIR_IN : USB_DIR_OUT) | epnum;
|
2015-01-11 19:34:53 +00:00
|
|
|
urb->ep->desc.bInterval = interval;
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int submit_urb(struct usb_hcd *hcd, struct urb *urb)
|
|
|
|
{
|
|
|
|
struct musb *host = hcd->hcd_priv;
|
|
|
|
int ret;
|
2015-01-11 19:34:49 +00:00
|
|
|
unsigned long timeout;
|
2012-11-06 13:48:21 +00:00
|
|
|
|
|
|
|
ret = musb_urb_enqueue(hcd, urb, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("Failed to enqueue URB to controller\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-11 19:34:49 +00:00
|
|
|
timeout = get_timer(0) + USB_TIMEOUT_MS(urb->pipe);
|
2012-11-06 13:48:21 +00:00
|
|
|
do {
|
|
|
|
if (ctrlc())
|
|
|
|
return -EIO;
|
|
|
|
host->isr(0, host);
|
2015-01-11 19:34:50 +00:00
|
|
|
} while (urb->status == -EINPROGRESS &&
|
2015-01-11 19:34:49 +00:00
|
|
|
get_timer(0) < timeout);
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2015-01-11 19:34:52 +00:00
|
|
|
if (urb->status == -EINPROGRESS)
|
|
|
|
musb_urb_dequeue(hcd, urb, -ETIME);
|
|
|
|
|
2012-11-06 13:48:21 +00:00
|
|
|
return urb->status;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static int _musb_submit_control_msg(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev, unsigned long pipe,
|
|
|
|
void *buffer, int len, struct devrequest *setup)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
construct_urb(&host->urb, &host->hep, dev, USB_ENDPOINT_XFER_CONTROL,
|
|
|
|
pipe, buffer, len, setup, 0);
|
2012-11-06 13:48:21 +00:00
|
|
|
|
|
|
|
/* Fix speed for non hub-attached devices */
|
2015-06-17 19:33:55 +00:00
|
|
|
if (!usb_dev_get_parent(dev))
|
2015-06-17 19:33:57 +00:00
|
|
|
dev->speed = host->host_speed;
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
return submit_urb(&host->hcd, &host->urb);
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static int _musb_submit_bulk_msg(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev, unsigned long pipe, void *buffer, int len)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
construct_urb(&host->urb, &host->hep, dev, USB_ENDPOINT_XFER_BULK,
|
|
|
|
pipe, buffer, len, NULL, 0);
|
|
|
|
return submit_urb(&host->hcd, &host->urb);
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static int _musb_submit_int_msg(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev, unsigned long pipe,
|
2019-08-18 08:55:27 +00:00
|
|
|
void *buffer, int len, int interval, bool nonblock)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
construct_urb(&host->urb, &host->hep, dev, USB_ENDPOINT_XFER_INT, pipe,
|
2015-01-11 19:34:53 +00:00
|
|
|
buffer, len, NULL, interval);
|
2015-06-17 19:33:57 +00:00
|
|
|
return submit_urb(&host->hcd, &host->urb);
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static struct int_queue *_musb_create_int_queue(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev, unsigned long pipe, int queuesize,
|
|
|
|
int elementsize, void *buffer, int interval)
|
2015-01-11 19:34:54 +00:00
|
|
|
{
|
|
|
|
struct int_queue *queue;
|
|
|
|
int ret, index = usb_pipein(pipe) * 16 + usb_pipeendpoint(pipe);
|
|
|
|
|
|
|
|
if (queuesize != 1) {
|
|
|
|
printf("ERROR musb int-queues only support queuesize 1\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->int_pending & (1 << index)) {
|
|
|
|
printf("ERROR int-urb is already pending on pipe %lx\n", pipe);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue = malloc(sizeof(*queue));
|
|
|
|
if (!queue)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
construct_urb(&queue->urb, &queue->hep, dev, USB_ENDPOINT_XFER_INT,
|
|
|
|
pipe, buffer, elementsize, NULL, interval);
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
ret = musb_urb_enqueue(&host->hcd, &queue->urb, 0);
|
2015-01-11 19:34:54 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
printf("Failed to enqueue URB to controller\n");
|
|
|
|
free(queue);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->int_pending |= 1 << index;
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static int _musb_destroy_int_queue(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev, struct int_queue *queue)
|
2015-01-11 19:34:54 +00:00
|
|
|
{
|
2021-09-27 15:42:38 +00:00
|
|
|
int index = usb_pipein(queue->urb.pipe) * 16 +
|
2015-01-11 19:34:54 +00:00
|
|
|
usb_pipeendpoint(queue->urb.pipe);
|
|
|
|
|
|
|
|
if (queue->urb.status == -EINPROGRESS)
|
2015-06-17 19:33:57 +00:00
|
|
|
musb_urb_dequeue(&host->hcd, &queue->urb, -ETIME);
|
2015-01-11 19:34:54 +00:00
|
|
|
|
|
|
|
dev->int_pending &= ~(1 << index);
|
|
|
|
free(queue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static void *_musb_poll_int_queue(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev, struct int_queue *queue)
|
2015-01-11 19:34:54 +00:00
|
|
|
{
|
|
|
|
if (queue->urb.status != -EINPROGRESS)
|
|
|
|
return NULL; /* URB has already completed in a prev. poll */
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
host->host->isr(0, host->host);
|
2015-01-11 19:34:54 +00:00
|
|
|
|
|
|
|
if (queue->urb.status != -EINPROGRESS)
|
|
|
|
return queue->urb.transfer_buffer; /* Done */
|
|
|
|
|
|
|
|
return NULL; /* URB still pending */
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
static int _musb_reset_root_port(struct musb_host_data *host,
|
|
|
|
struct usb_device *dev)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
void *mbase = host->host->mregs;
|
2012-11-06 13:48:21 +00:00
|
|
|
u8 power;
|
2015-01-11 19:34:51 +00:00
|
|
|
|
|
|
|
power = musb_readb(mbase, MUSB_POWER);
|
|
|
|
power &= 0xf0;
|
|
|
|
musb_writeb(mbase, MUSB_POWER, MUSB_POWER_RESET | power);
|
|
|
|
mdelay(50);
|
2018-05-07 07:33:37 +00:00
|
|
|
|
|
|
|
if (host->host->ops->pre_root_reset_end)
|
|
|
|
host->host->ops->pre_root_reset_end(host->host);
|
|
|
|
|
2015-01-11 19:34:51 +00:00
|
|
|
power = musb_readb(mbase, MUSB_POWER);
|
|
|
|
musb_writeb(mbase, MUSB_POWER, ~MUSB_POWER_RESET & power);
|
2018-05-07 07:33:37 +00:00
|
|
|
|
|
|
|
if (host->host->ops->post_root_reset_end)
|
|
|
|
host->host->ops->post_root_reset_end(host->host);
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
host->host->isr(0, host->host);
|
|
|
|
host->host_speed = (musb_readb(mbase, MUSB_POWER) & MUSB_POWER_HSMODE) ?
|
2015-01-11 19:34:51 +00:00
|
|
|
USB_SPEED_HIGH :
|
|
|
|
(musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_FSDEV) ?
|
|
|
|
USB_SPEED_FULL : USB_SPEED_LOW;
|
2015-06-17 19:33:57 +00:00
|
|
|
mdelay((host->host_speed == USB_SPEED_LOW) ? 200 : 50);
|
2015-03-25 18:21:59 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-01-11 19:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
int musb_lowlevel_init(struct musb_host_data *host)
|
2015-01-11 19:34:51 +00:00
|
|
|
{
|
2012-11-06 13:48:21 +00:00
|
|
|
void *mbase;
|
2015-01-11 19:34:49 +00:00
|
|
|
/* USB spec says it may take up to 1 second for a device to connect */
|
|
|
|
unsigned long timeout = get_timer(0) + 1000;
|
2015-06-17 19:33:54 +00:00
|
|
|
int ret;
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
if (!host->host) {
|
2012-11-06 13:48:21 +00:00
|
|
|
printf("MUSB host is not registered\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
ret = musb_start(host->host);
|
2015-06-17 19:33:54 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
mbase = host->host->mregs;
|
2012-11-06 13:48:21 +00:00
|
|
|
do {
|
|
|
|
if (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_HM)
|
|
|
|
break;
|
2015-01-11 19:34:49 +00:00
|
|
|
} while (get_timer(0) < timeout);
|
2016-04-02 18:46:10 +00:00
|
|
|
if (get_timer(0) >= timeout) {
|
|
|
|
musb_stop(host->host);
|
2012-11-06 13:48:21 +00:00
|
|
|
return -ENODEV;
|
2016-04-02 18:46:10 +00:00
|
|
|
}
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
_musb_reset_root_port(host, NULL);
|
|
|
|
host->host->is_active = 1;
|
|
|
|
host->hcd.hcd_priv = host->host;
|
2012-11-06 13:48:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_USB)
|
2012-11-06 13:48:21 +00:00
|
|
|
int usb_lowlevel_stop(int index)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
if (!musb_host.host) {
|
2012-11-06 13:48:21 +00:00
|
|
|
printf("MUSB host is not registered\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:33:57 +00:00
|
|
|
musb_stop(musb_host.host);
|
2012-11-06 13:48:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-06-17 19:33:56 +00:00
|
|
|
|
|
|
|
int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
|
|
|
|
void *buffer, int length)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return _musb_submit_bulk_msg(&musb_host, dev, pipe, buffer, length);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int submit_control_msg(struct usb_device *dev, unsigned long pipe,
|
|
|
|
void *buffer, int length, struct devrequest *setup)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return _musb_submit_control_msg(&musb_host, dev, pipe, buffer, length, setup);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int submit_int_msg(struct usb_device *dev, unsigned long pipe,
|
2019-08-18 08:55:27 +00:00
|
|
|
void *buffer, int length, int interval, bool nonblock)
|
2015-06-17 19:33:56 +00:00
|
|
|
{
|
2019-08-18 08:55:27 +00:00
|
|
|
return _musb_submit_int_msg(&musb_host, dev, pipe, buffer, length,
|
|
|
|
interval, nonblock);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct int_queue *create_int_queue(struct usb_device *dev,
|
|
|
|
unsigned long pipe, int queuesize, int elementsize,
|
|
|
|
void *buffer, int interval)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return _musb_create_int_queue(&musb_host, dev, pipe, queuesize, elementsize,
|
2015-06-17 19:33:56 +00:00
|
|
|
buffer, interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *poll_int_queue(struct usb_device *dev, struct int_queue *queue)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return _musb_poll_int_queue(&musb_host, dev, queue);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int destroy_int_queue(struct usb_device *dev, struct int_queue *queue)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return _musb_destroy_int_queue(&musb_host, dev, queue);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int usb_reset_root_port(struct usb_device *dev)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return _musb_reset_root_port(&musb_host, dev);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
|
|
|
|
{
|
2015-06-17 19:33:57 +00:00
|
|
|
return musb_lowlevel_init(&musb_host);
|
2015-06-17 19:33:56 +00:00
|
|
|
}
|
2018-11-21 07:43:56 +00:00
|
|
|
#endif /* !CONFIG_IS_ENABLED(DM_USB) */
|
2015-06-17 19:33:58 +00:00
|
|
|
|
2018-11-21 07:43:56 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_USB)
|
2015-06-17 19:33:58 +00:00
|
|
|
static int musb_submit_control_msg(struct udevice *dev, struct usb_device *udev,
|
|
|
|
unsigned long pipe, void *buffer, int length,
|
|
|
|
struct devrequest *setup)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
return _musb_submit_control_msg(host, udev, pipe, buffer, length, setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int musb_submit_bulk_msg(struct udevice *dev, struct usb_device *udev,
|
|
|
|
unsigned long pipe, void *buffer, int length)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
return _musb_submit_bulk_msg(host, udev, pipe, buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int musb_submit_int_msg(struct udevice *dev, struct usb_device *udev,
|
|
|
|
unsigned long pipe, void *buffer, int length,
|
2019-08-18 08:55:27 +00:00
|
|
|
int interval, bool nonblock)
|
2015-06-17 19:33:58 +00:00
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
2019-08-18 08:55:27 +00:00
|
|
|
return _musb_submit_int_msg(host, udev, pipe, buffer, length, interval,
|
|
|
|
nonblock);
|
2015-06-17 19:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct int_queue *musb_create_int_queue(struct udevice *dev,
|
|
|
|
struct usb_device *udev, unsigned long pipe, int queuesize,
|
|
|
|
int elementsize, void *buffer, int interval)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
return _musb_create_int_queue(host, udev, pipe, queuesize, elementsize,
|
|
|
|
buffer, interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *musb_poll_int_queue(struct udevice *dev, struct usb_device *udev,
|
|
|
|
struct int_queue *queue)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
return _musb_poll_int_queue(host, udev, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int musb_destroy_int_queue(struct udevice *dev, struct usb_device *udev,
|
|
|
|
struct int_queue *queue)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
return _musb_destroy_int_queue(host, udev, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int musb_reset_root_port(struct udevice *dev, struct usb_device *udev)
|
|
|
|
{
|
|
|
|
struct musb_host_data *host = dev_get_priv(dev);
|
|
|
|
return _musb_reset_root_port(host, udev);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dm_usb_ops musb_usb_ops = {
|
|
|
|
.control = musb_submit_control_msg,
|
|
|
|
.bulk = musb_submit_bulk_msg,
|
|
|
|
.interrupt = musb_submit_int_msg,
|
|
|
|
.create_int_queue = musb_create_int_queue,
|
|
|
|
.poll_int_queue = musb_poll_int_queue,
|
|
|
|
.destroy_int_queue = musb_destroy_int_queue,
|
|
|
|
.reset_root_port = musb_reset_root_port,
|
|
|
|
};
|
2018-11-21 07:43:56 +00:00
|
|
|
#endif /* CONFIG_IS_ENABLED(DM_USB) */
|
2015-08-04 15:04:06 +00:00
|
|
|
#endif /* CONFIG_USB_MUSB_HOST */
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2018-12-04 10:30:57 +00:00
|
|
|
#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET)
|
2012-11-06 13:48:21 +00:00
|
|
|
static struct musb *gadget;
|
|
|
|
|
2015-02-23 13:10:23 +00:00
|
|
|
int usb_gadget_handle_interrupts(int index)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
2013-06-04 09:10:01 +00:00
|
|
|
WATCHDOG_RESET();
|
2012-11-06 13:48:21 +00:00
|
|
|
if (!gadget || !gadget->isr)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return gadget->isr(0, gadget);
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2013-03-21 05:27:49 +00:00
|
|
|
if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind ||
|
2012-11-06 13:48:21 +00:00
|
|
|
!driver->setup) {
|
|
|
|
printf("bad parameter.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gadget) {
|
|
|
|
printf("Controller uninitialized\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = musb_gadget_start(&gadget->g, driver);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("gadget_start failed with %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = driver->bind(&gadget->g);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("bind failed with %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
|
|
|
|
{
|
2014-04-18 13:54:30 +00:00
|
|
|
if (driver->disconnect)
|
|
|
|
driver->disconnect(&gadget->g);
|
|
|
|
if (driver->unbind)
|
|
|
|
driver->unbind(&gadget->g);
|
2012-11-06 13:48:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-04 15:04:06 +00:00
|
|
|
#endif /* CONFIG_USB_MUSB_GADGET */
|
2012-11-06 13:48:21 +00:00
|
|
|
|
2018-07-20 07:13:56 +00:00
|
|
|
struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
|
|
|
|
void *ctl_regs)
|
2012-11-06 13:48:21 +00:00
|
|
|
{
|
|
|
|
struct musb **musbp;
|
|
|
|
|
|
|
|
switch (plat->mode) {
|
2018-11-21 07:43:56 +00:00
|
|
|
#if defined(CONFIG_USB_MUSB_HOST) && !CONFIG_IS_ENABLED(DM_USB)
|
2012-11-06 13:48:21 +00:00
|
|
|
case MUSB_HOST:
|
2015-06-17 19:33:57 +00:00
|
|
|
musbp = &musb_host.host;
|
2012-11-06 13:48:21 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2018-12-04 10:30:57 +00:00
|
|
|
#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET)
|
2012-11-06 13:48:21 +00:00
|
|
|
case MUSB_PERIPHERAL:
|
|
|
|
musbp = &gadget;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2018-07-20 07:13:56 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*musbp = musb_init_controller(plat, (struct device *)bdata, ctl_regs);
|
2018-07-20 07:13:56 +00:00
|
|
|
if (IS_ERR(*musbp)) {
|
2012-11-06 13:48:21 +00:00
|
|
|
printf("Failed to init the controller\n");
|
2018-07-20 07:13:56 +00:00
|
|
|
return ERR_CAST(*musbp);
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 07:13:56 +00:00
|
|
|
return *musbp;
|
2012-11-06 13:48:21 +00:00
|
|
|
}
|
2020-07-19 16:15:55 +00:00
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(DM_USB)
|
|
|
|
struct usb_device *usb_dev_get_parent(struct usb_device *udev)
|
|
|
|
{
|
|
|
|
struct udevice *parent = udev->dev->parent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When called from usb-uclass.c: usb_scan_device() udev->dev points
|
|
|
|
* to the parent udevice, not the actual udevice belonging to the
|
|
|
|
* udev as the device is not instantiated yet.
|
|
|
|
*
|
|
|
|
* If dev is an usb-bus, then we are called from usb_scan_device() for
|
|
|
|
* an usb-device plugged directly into the root port, return NULL.
|
|
|
|
*/
|
|
|
|
if (device_get_uclass_id(udev->dev) == UCLASS_USB)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If these 2 are not the same we are being called from
|
|
|
|
* usb_scan_device() and udev itself is the parent.
|
|
|
|
*/
|
|
|
|
if (dev_get_parent_priv(udev->dev) != udev)
|
|
|
|
return udev;
|
|
|
|
|
|
|
|
/* We are being called normally, use the parent pointer */
|
|
|
|
if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
|
|
|
|
return dev_get_parent_priv(parent);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
struct usb_device *usb_dev_get_parent(struct usb_device *udev)
|
|
|
|
{
|
|
|
|
return udev->parent;
|
|
|
|
}
|
|
|
|
#endif
|