usb: ohci: Pass around a pointer to ohci_t rather then accessing global vars

This is a preparation patch for adding driver-model support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Marek Vasut <marex@denx.de>
This commit is contained in:
Hans de Goede 2015-05-05 23:56:07 +02:00 committed by Simon Glass
parent 69710ce3ee
commit c5613df585

View File

@ -122,9 +122,9 @@ static inline u32 roothub_portstatus(struct ohci *hc, int i)
{ return ohci_readl(&hc->regs->roothub.portstatus[i]); } { return ohci_readl(&hc->regs->roothub.portstatus[i]); }
/* forward declaration */ /* forward declaration */
static int hc_interrupt(void); static int hc_interrupt(ohci_t *ohci);
static void td_submit_job(struct usb_device *dev, unsigned long pipe, static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
void *buffer, int transfer_len, unsigned long pipe, void *buffer, int transfer_len,
struct devrequest *setup, urb_priv_t *urb, struct devrequest *setup, urb_priv_t *urb,
int interval); int interval);
@ -156,18 +156,18 @@ static void urb_free_priv(urb_priv_t *urb)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#ifdef DEBUG #ifdef DEBUG
static int sohci_get_current_frame_number(struct usb_device *dev); static int sohci_get_current_frame_number(ohci_t *ohci);
/* debug| print the main components of an URB /* debug| print the main components of an URB
* small: 0) header + data packets 1) just header */ * small: 0) header + data packets 1) just header */
static void pkt_print(urb_priv_t *purb, struct usb_device *dev, static void pkt_print(ohci_t *ohci, urb_priv_t *purb, struct usb_device *dev,
unsigned long pipe, void *buffer, int transfer_len, unsigned long pipe, void *buffer, int transfer_len,
struct devrequest *setup, char *str, int small) struct devrequest *setup, char *str, int small)
{ {
dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx", dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx",
str, str,
sohci_get_current_frame_number(dev), sohci_get_current_frame_number(ohci),
usb_pipedevice(pipe), usb_pipedevice(pipe),
usb_pipeendpoint(pipe), usb_pipeendpoint(pipe),
usb_pipeout(pipe)? 'O': 'I', usb_pipeout(pipe)? 'O': 'I',
@ -389,9 +389,8 @@ static void ohci_dump(ohci_t *controller, int verbose)
/* get a transfer request */ /* get a transfer request */
int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup) int sohci_submit_job(ohci_t *ohci, urb_priv_t *urb, struct devrequest *setup)
{ {
ohci_t *ohci;
ed_t *ed; ed_t *ed;
urb_priv_t *purb_priv = urb; urb_priv_t *purb_priv = urb;
int i, size = 0; int i, size = 0;
@ -401,8 +400,6 @@ int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup)
int transfer_len = urb->transfer_buffer_length; int transfer_len = urb->transfer_buffer_length;
int interval = urb->interval; int interval = urb->interval;
ohci = &gohci;
/* when controller's hung, permit only roothub cleanup attempts /* when controller's hung, permit only roothub cleanup attempts
* such as powering down ports */ * such as powering down ports */
if (ohci->disabled) { if (ohci->disabled) {
@ -471,7 +468,7 @@ int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup)
ep_link(ohci, ed); ep_link(ohci, ed);
/* fill the TDs and link it to the ed */ /* fill the TDs and link it to the ed */
td_submit_job(dev, pipe, buffer, transfer_len, td_submit_job(ohci, dev, pipe, buffer, transfer_len,
setup, purb_priv, interval); setup, purb_priv, interval);
return 0; return 0;
@ -493,7 +490,7 @@ static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb)
ohci_readl(&regs->intrdisable); /* PCI posting flush */ ohci_readl(&regs->intrdisable); /* PCI posting flush */
} }
urb->actual_length = 0; urb->actual_length = 0;
td_submit_job( td_submit_job( hc,
urb->dev, urb->dev,
urb->pipe, urb->pipe,
urb->transfer_buffer, urb->transfer_buffer,
@ -515,11 +512,8 @@ static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb)
#ifdef DEBUG #ifdef DEBUG
/* tell us the current USB frame number */ /* tell us the current USB frame number */
static int sohci_get_current_frame_number(ohci_t *ohci)
static int sohci_get_current_frame_number(struct usb_device *usb_dev)
{ {
ohci_t *ohci = &gohci;
return m16_swap(ohci->hcca->frame_no); return m16_swap(ohci->hcca->frame_no);
} }
#endif #endif
@ -849,12 +843,11 @@ static void td_fill(ohci_t *ohci, unsigned int info,
/* prepare all TDs of a transfer */ /* prepare all TDs of a transfer */
static void td_submit_job(struct usb_device *dev, unsigned long pipe, static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
void *buffer, int transfer_len, unsigned long pipe, void *buffer, int transfer_len,
struct devrequest *setup, urb_priv_t *urb, struct devrequest *setup, urb_priv_t *urb,
int interval) int interval)
{ {
ohci_t *ohci = &gohci;
int data_len = transfer_len; int data_len = transfer_len;
void *data; void *data;
int cnt = 0; int cnt = 0;
@ -1098,16 +1091,16 @@ static int dl_done_list(ohci_t *ohci)
#define OK(x) len = (x); break #define OK(x) len = (x); break
#ifdef DEBUG #ifdef DEBUG
#define WR_RH_STAT(x) {info("WR:status %#8x", (x)); ohci_writel((x), \ #define WR_RH_STAT(x) {info("WR:status %#8x", (x)); ohci_writel((x), \
&gohci.regs->roothub.status); } &ohci->regs->roothub.status); }
#define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \ #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \
(x)); ohci_writel((x), &gohci.regs->roothub.portstatus[wIndex-1]); } (x)); ohci_writel((x), &ohci->regs->roothub.portstatus[wIndex-1]); }
#else #else
#define WR_RH_STAT(x) ohci_writel((x), &gohci.regs->roothub.status) #define WR_RH_STAT(x) ohci_writel((x), &ohci->regs->roothub.status)
#define WR_RH_PORTSTAT(x) ohci_writel((x), \ #define WR_RH_PORTSTAT(x) ohci_writel((x), \
&gohci.regs->roothub.portstatus[wIndex-1]) &ohci->regs->roothub.portstatus[wIndex-1])
#endif #endif
#define RD_RH_STAT roothub_status(&gohci) #define RD_RH_STAT roothub_status(ohci)
#define RD_RH_PORTSTAT roothub_portstatus(&gohci, wIndex-1) #define RD_RH_PORTSTAT roothub_portstatus(ohci, wIndex-1)
/* request to virtual root hub */ /* request to virtual root hub */
@ -1135,8 +1128,9 @@ int rh_check_port_status(ohci_t *controller)
return res; return res;
} }
static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev,
void *buffer, int transfer_len, struct devrequest *cmd) unsigned long pipe, void *buffer, int transfer_len,
struct devrequest *cmd)
{ {
void *data = buffer; void *data = buffer;
int leni = transfer_len; int leni = transfer_len;
@ -1149,7 +1143,7 @@ static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
ALLOC_ALIGN_BUFFER(__u8, databuf, 16, sizeof(u32)); ALLOC_ALIGN_BUFFER(__u8, databuf, 16, sizeof(u32));
#ifdef DEBUG #ifdef DEBUG
pkt_print(NULL, dev, pipe, buffer, transfer_len, pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len,
cmd, "SUB(rh)", usb_pipein(pipe)); cmd, "SUB(rh)", usb_pipein(pipe));
#else #else
mdelay(1); mdelay(1);
@ -1243,7 +1237,7 @@ pkt_print(NULL, dev, pipe, buffer, transfer_len,
break; break;
case RH_SET_ADDRESS: case RH_SET_ADDRESS:
gohci.rh.devnum = wValue; ohci->rh.devnum = wValue;
OK(0); OK(0);
case RH_GET_DESCRIPTOR: case RH_GET_DESCRIPTOR:
@ -1288,7 +1282,7 @@ pkt_print(NULL, dev, pipe, buffer, transfer_len,
case RH_GET_DESCRIPTOR | RH_CLASS: case RH_GET_DESCRIPTOR | RH_CLASS:
{ {
__u32 temp = roothub_a(&gohci); __u32 temp = roothub_a(ohci);
databuf[0] = 9; /* min length; */ databuf[0] = 9; /* min length; */
databuf[1] = 0x29; databuf[1] = 0x29;
@ -1307,7 +1301,7 @@ pkt_print(NULL, dev, pipe, buffer, transfer_len,
databuf[4] = 0; databuf[4] = 0;
databuf[5] = (temp & RH_A_POTPGT) >> 24; databuf[5] = (temp & RH_A_POTPGT) >> 24;
databuf[6] = 0; databuf[6] = 0;
temp = roothub_b(&gohci); temp = roothub_b(ohci);
databuf[7] = temp & RH_B_DR; databuf[7] = temp & RH_B_DR;
if (databuf[2] < 7) { if (databuf[2] < 7) {
databuf[8] = 0xff; databuf[8] = 0xff;
@ -1336,7 +1330,7 @@ pkt_print(NULL, dev, pipe, buffer, transfer_len,
} }
#ifdef DEBUG #ifdef DEBUG
ohci_dump_roothub(&gohci, 1); ohci_dump_roothub(ohci, 1);
#else #else
mdelay(1); mdelay(1);
#endif #endif
@ -1348,7 +1342,7 @@ pkt_print(NULL, dev, pipe, buffer, transfer_len,
dev->status = stat; dev->status = stat;
#ifdef DEBUG #ifdef DEBUG
pkt_print(NULL, dev, pipe, buffer, pkt_print(ohci, NULL, dev, pipe, buffer,
transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/); transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
#else #else
mdelay(1); mdelay(1);
@ -1361,8 +1355,9 @@ pkt_print(NULL, dev, pipe, buffer, transfer_len,
/* common code for handling submit messages - used for all but root hub */ /* common code for handling submit messages - used for all but root hub */
/* accesses. */ /* accesses. */
int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer, static int submit_common_msg(ohci_t *ohci, struct usb_device *dev,
int transfer_len, struct devrequest *setup, int interval) unsigned long pipe, void *buffer, int transfer_len,
struct devrequest *setup, int interval)
{ {
int stat = 0; int stat = 0;
int maxsize = usb_maxpacket(dev, pipe); int maxsize = usb_maxpacket(dev, pipe);
@ -1380,7 +1375,7 @@ int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
#ifdef DEBUG #ifdef DEBUG
urb->actual_length = 0; urb->actual_length = 0;
pkt_print(urb, dev, pipe, buffer, transfer_len, pkt_print(ohci, urb, dev, pipe, buffer, transfer_len,
setup, "SUB", usb_pipein(pipe)); setup, "SUB", usb_pipein(pipe));
#else #else
mdelay(1); mdelay(1);
@ -1391,14 +1386,14 @@ int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
return -1; return -1;
} }
if (sohci_submit_job(urb, setup) < 0) { if (sohci_submit_job(ohci, urb, setup) < 0) {
err("sohci_submit_job failed"); err("sohci_submit_job failed");
return -1; return -1;
} }
#if 0 #if 0
mdelay(10); mdelay(10);
/* ohci_dump_status(&gohci); */ /* ohci_dump_status(ohci); */
#endif #endif
timeout = USB_TIMEOUT_MS(pipe); timeout = USB_TIMEOUT_MS(pipe);
@ -1406,7 +1401,7 @@ int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
/* wait for it to complete */ /* wait for it to complete */
for (;;) { for (;;) {
/* check whether the controller is done */ /* check whether the controller is done */
stat = hc_interrupt(); stat = hc_interrupt(ohci);
if (stat < 0) { if (stat < 0) {
stat = USB_ST_CRC_ERR; stat = USB_ST_CRC_ERR;
break; break;
@ -1444,7 +1439,7 @@ int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
dev->act_len = urb->actual_length; dev->act_len = urb->actual_length;
#ifdef DEBUG #ifdef DEBUG
pkt_print(urb, dev, pipe, buffer, transfer_len, pkt_print(ohci, urb, dev, pipe, buffer, transfer_len,
setup, "RET(ctlr)", usb_pipein(pipe)); setup, "RET(ctlr)", usb_pipein(pipe));
#else #else
mdelay(1); mdelay(1);
@ -1461,17 +1456,27 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
int transfer_len) int transfer_len)
{ {
info("submit_bulk_msg"); info("submit_bulk_msg");
return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0); return submit_common_msg(&gohci, dev, pipe, buffer, transfer_len,
NULL, 0);
} }
int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
int transfer_len, struct devrequest *setup) int transfer_len, int interval)
{
info("submit_int_msg");
return submit_common_msg(&gohci, dev, pipe, buffer, transfer_len, NULL,
interval);
}
static int _ohci_submit_control_msg(ohci_t *ohci, struct usb_device *dev,
unsigned long pipe, void *buffer, int transfer_len,
struct devrequest *setup)
{ {
int maxsize = usb_maxpacket(dev, pipe); int maxsize = usb_maxpacket(dev, pipe);
info("submit_control_msg"); info("submit_control_msg");
#ifdef DEBUG #ifdef DEBUG
pkt_print(NULL, dev, pipe, buffer, transfer_len, pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len,
setup, "SUB", usb_pipein(pipe)); setup, "SUB", usb_pipein(pipe));
#else #else
mdelay(1); mdelay(1);
@ -1481,22 +1486,15 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
pipe); pipe);
return -1; return -1;
} }
if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) { if (((pipe >> 8) & 0x7f) == ohci->rh.devnum) {
gohci.rh.dev = dev; ohci->rh.dev = dev;
/* root hub - redirect */ /* root hub - redirect */
return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len, return ohci_submit_rh_msg(ohci, dev, pipe, buffer,
setup); transfer_len, setup);
} }
return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0); return submit_common_msg(ohci, dev, pipe, buffer, transfer_len,
} setup, 0);
int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
int transfer_len, int interval)
{
info("submit_int_msg");
return submit_common_msg(dev, pipe, buffer, transfer_len, NULL,
interval);
} }
/*-------------------------------------------------------------------------* /*-------------------------------------------------------------------------*
@ -1640,9 +1638,8 @@ static int hc_start(ohci_t *ohci)
/* an interrupt happens */ /* an interrupt happens */
static int hc_interrupt(void) static int hc_interrupt(ohci_t *ohci)
{ {
ohci_t *ohci = &gohci;
struct ohci_regs *regs = ohci->regs; struct ohci_regs *regs = ohci->regs;
int ints; int ints;
int stat = -1; int stat = -1;
@ -1694,7 +1691,7 @@ static int hc_interrupt(void)
mdelay(1); mdelay(1);
ohci_writel(OHCI_INTR_WDH, &regs->intrdisable); ohci_writel(OHCI_INTR_WDH, &regs->intrdisable);
(void)ohci_readl(&regs->intrdisable); /* flush */ (void)ohci_readl(&regs->intrdisable); /* flush */
stat = dl_done_list(&gohci); stat = dl_done_list(ohci);
ohci_writel(OHCI_INTR_WDH, &regs->intrenable); ohci_writel(OHCI_INTR_WDH, &regs->intrenable);
(void)ohci_readl(&regs->intrdisable); /* flush */ (void)ohci_readl(&regs->intrdisable); /* flush */
} }
@ -1872,3 +1869,10 @@ int usb_lowlevel_stop(int index)
ohci_inited = 0; ohci_inited = 0;
return 0; return 0;
} }
int submit_control_msg(struct usb_device *dev, unsigned long pipe,
void *buffer, int transfer_len, struct devrequest *setup)
{
return _ohci_submit_control_msg(&gohci, dev, pipe, buffer,
transfer_len, setup);
}