xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/usbhost/drvEhciHcd_2.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi //<MStar Software>
2*53ee8cc1Swenshuai.xi //******************************************************************************
3*53ee8cc1Swenshuai.xi // MStar Software
4*53ee8cc1Swenshuai.xi // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5*53ee8cc1Swenshuai.xi // All software, firmware and related documentation herein ("MStar Software") are
6*53ee8cc1Swenshuai.xi // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7*53ee8cc1Swenshuai.xi // law, including, but not limited to, copyright law and international treaties.
8*53ee8cc1Swenshuai.xi // Any use, modification, reproduction, retransmission, or republication of all
9*53ee8cc1Swenshuai.xi // or part of MStar Software is expressly prohibited, unless prior written
10*53ee8cc1Swenshuai.xi // permission has been granted by MStar.
11*53ee8cc1Swenshuai.xi //
12*53ee8cc1Swenshuai.xi // By accessing, browsing and/or using MStar Software, you acknowledge that you
13*53ee8cc1Swenshuai.xi // have read, understood, and agree, to be bound by below terms ("Terms") and to
14*53ee8cc1Swenshuai.xi // comply with all applicable laws and regulations:
15*53ee8cc1Swenshuai.xi //
16*53ee8cc1Swenshuai.xi // 1. MStar shall retain any and all right, ownership and interest to MStar
17*53ee8cc1Swenshuai.xi //    Software and any modification/derivatives thereof.
18*53ee8cc1Swenshuai.xi //    No right, ownership, or interest to MStar Software and any
19*53ee8cc1Swenshuai.xi //    modification/derivatives thereof is transferred to you under Terms.
20*53ee8cc1Swenshuai.xi //
21*53ee8cc1Swenshuai.xi // 2. You understand that MStar Software might include, incorporate or be
22*53ee8cc1Swenshuai.xi //    supplied together with third party`s software and the use of MStar
23*53ee8cc1Swenshuai.xi //    Software may require additional licenses from third parties.
24*53ee8cc1Swenshuai.xi //    Therefore, you hereby agree it is your sole responsibility to separately
25*53ee8cc1Swenshuai.xi //    obtain any and all third party right and license necessary for your use of
26*53ee8cc1Swenshuai.xi //    such third party`s software.
27*53ee8cc1Swenshuai.xi //
28*53ee8cc1Swenshuai.xi // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29*53ee8cc1Swenshuai.xi //    MStar`s confidential information and you agree to keep MStar`s
30*53ee8cc1Swenshuai.xi //    confidential information in strictest confidence and not disclose to any
31*53ee8cc1Swenshuai.xi //    third party.
32*53ee8cc1Swenshuai.xi //
33*53ee8cc1Swenshuai.xi // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34*53ee8cc1Swenshuai.xi //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35*53ee8cc1Swenshuai.xi //    without limitation, any warranties of merchantability, non-infringement of
36*53ee8cc1Swenshuai.xi //    intellectual property rights, fitness for a particular purpose, error free
37*53ee8cc1Swenshuai.xi //    and in conformity with any international standard.  You agree to waive any
38*53ee8cc1Swenshuai.xi //    claim against MStar for any loss, damage, cost or expense that you may
39*53ee8cc1Swenshuai.xi //    incur related to your use of MStar Software.
40*53ee8cc1Swenshuai.xi //    In no event shall MStar be liable for any direct, indirect, incidental or
41*53ee8cc1Swenshuai.xi //    consequential damages, including without limitation, lost of profit or
42*53ee8cc1Swenshuai.xi //    revenues, lost or damage of data, and unauthorized system use.
43*53ee8cc1Swenshuai.xi //    You agree that this Section 4 shall still apply without being affected
44*53ee8cc1Swenshuai.xi //    even if MStar Software has been modified by MStar in accordance with your
45*53ee8cc1Swenshuai.xi //    request or instruction for your use, except otherwise agreed by both
46*53ee8cc1Swenshuai.xi //    parties in writing.
47*53ee8cc1Swenshuai.xi //
48*53ee8cc1Swenshuai.xi // 5. If requested, MStar may from time to time provide technical supports or
49*53ee8cc1Swenshuai.xi //    services in relation with MStar Software to you for your use of
50*53ee8cc1Swenshuai.xi //    MStar Software in conjunction with your or your customer`s product
51*53ee8cc1Swenshuai.xi //    ("Services").
52*53ee8cc1Swenshuai.xi //    You understand and agree that, except otherwise agreed by both parties in
53*53ee8cc1Swenshuai.xi //    writing, Services are provided on an "AS IS" basis and the warranty
54*53ee8cc1Swenshuai.xi //    disclaimer set forth in Section 4 above shall apply.
55*53ee8cc1Swenshuai.xi //
56*53ee8cc1Swenshuai.xi // 6. Nothing contained herein shall be construed as by implication, estoppels
57*53ee8cc1Swenshuai.xi //    or otherwise:
58*53ee8cc1Swenshuai.xi //    (a) conferring any license or right to use MStar name, trademark, service
59*53ee8cc1Swenshuai.xi //        mark, symbol or any other identification;
60*53ee8cc1Swenshuai.xi //    (b) obligating MStar or any of its affiliates to furnish any person,
61*53ee8cc1Swenshuai.xi //        including without limitation, you and your customers, any assistance
62*53ee8cc1Swenshuai.xi //        of any kind whatsoever, or any information; or
63*53ee8cc1Swenshuai.xi //    (c) conferring any license or right under any intellectual property right.
64*53ee8cc1Swenshuai.xi //
65*53ee8cc1Swenshuai.xi // 7. These terms shall be governed by and construed in accordance with the laws
66*53ee8cc1Swenshuai.xi //    of Taiwan, R.O.C., excluding its conflict of law rules.
67*53ee8cc1Swenshuai.xi //    Any and all dispute arising out hereof or related hereto shall be finally
68*53ee8cc1Swenshuai.xi //    settled by arbitration referred to the Chinese Arbitration Association,
69*53ee8cc1Swenshuai.xi //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70*53ee8cc1Swenshuai.xi //    Rules of the Association by three (3) arbitrators appointed in accordance
71*53ee8cc1Swenshuai.xi //    with the said Rules.
72*53ee8cc1Swenshuai.xi //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73*53ee8cc1Swenshuai.xi //    be English.
74*53ee8cc1Swenshuai.xi //    The arbitration award shall be final and binding to both parties.
75*53ee8cc1Swenshuai.xi //
76*53ee8cc1Swenshuai.xi //******************************************************************************
77*53ee8cc1Swenshuai.xi //<MStar Software>
78*53ee8cc1Swenshuai.xi 
79*53ee8cc1Swenshuai.xi #include "include/drvConfig.h"
80*53ee8cc1Swenshuai.xi 
81*53ee8cc1Swenshuai.xi #include <MsCommon.h>
82*53ee8cc1Swenshuai.xi #include "include/drvCompiler.h"
83*53ee8cc1Swenshuai.xi #include "include/drvPorts.h"
84*53ee8cc1Swenshuai.xi #include "include/drvErrno.h"
85*53ee8cc1Swenshuai.xi #include "include/drvIO.h"
86*53ee8cc1Swenshuai.xi #include "include/drvPCIMEM.h"
87*53ee8cc1Swenshuai.xi #include "include/drvList.h"
88*53ee8cc1Swenshuai.xi #include "include/drvTimer.h"
89*53ee8cc1Swenshuai.xi #include "include/drvKernel.h"
90*53ee8cc1Swenshuai.xi // USB related implemented header files
91*53ee8cc1Swenshuai.xi #include "include/drvUSB.h"
92*53ee8cc1Swenshuai.xi #include "drvHCD.h"
93*53ee8cc1Swenshuai.xi #include "include/drvCPE_EHCI.h"
94*53ee8cc1Swenshuai.xi #include "drvEHCI.h"
95*53ee8cc1Swenshuai.xi #include "drvUSBHwCtl.h"
96*53ee8cc1Swenshuai.xi #include "drvUsbHostConfig.h"
97*53ee8cc1Swenshuai.xi #include "include/drvCPE_AMBA.h"
98*53ee8cc1Swenshuai.xi #include "drvHUB.h"
99*53ee8cc1Swenshuai.xi 
100*53ee8cc1Swenshuai.xi #define EHCI_DEBUG
101*53ee8cc1Swenshuai.xi #ifdef EHCI_DEBUG
102*53ee8cc1Swenshuai.xi #define EHCI_Dbg		diag_printf
103*53ee8cc1Swenshuai.xi #else
104*53ee8cc1Swenshuai.xi #define EHCI_Dbg(x,...)
105*53ee8cc1Swenshuai.xi #endif
106*53ee8cc1Swenshuai.xi 
107*53ee8cc1Swenshuai.xi #define EHCI_ERR		diag_printf
108*53ee8cc1Swenshuai.xi 
109*53ee8cc1Swenshuai.xi struct cpe_dev cpe_ehci_dev_Port2;
110*53ee8cc1Swenshuai.xi struct cpe_driver ehci_hcd_cpe_driver_Port2;
111*53ee8cc1Swenshuai.xi struct hc_driver ehci_cpe_hc_driver_Port2;
112*53ee8cc1Swenshuai.xi struct usb_hcd *g_pUsbHcd_Port2 = NULL;
113*53ee8cc1Swenshuai.xi 
114*53ee8cc1Swenshuai.xi extern void cpe_ehci_start_hc(struct cpe_dev *dev);
115*53ee8cc1Swenshuai.xi extern void usb_hcd_cpe_ehci_remove (struct usb_hcd *hcd, struct cpe_dev *dev);
116*53ee8cc1Swenshuai.xi extern void cpe_ehci_stop_hc(struct cpe_dev *dev);
117*53ee8cc1Swenshuai.xi extern void ehci_irq (struct usb_hcd *hcd, struct pt_regs *regs);
118*53ee8cc1Swenshuai.xi extern int ehci_hc_reset (struct usb_hcd *hcd);
119*53ee8cc1Swenshuai.xi extern  int ehci_start (struct usb_hcd *hcd);
120*53ee8cc1Swenshuai.xi extern int ehci_suspend (struct usb_hcd *hcd, U32 state);
121*53ee8cc1Swenshuai.xi extern int ehci_resume (struct usb_hcd *hcd);
122*53ee8cc1Swenshuai.xi extern void ehci_stop (struct usb_hcd *hcd);
123*53ee8cc1Swenshuai.xi extern  struct usb_hcd *ehci_hcd_alloc (void);
124*53ee8cc1Swenshuai.xi extern  void ehci_hcd_free (struct usb_hcd *hcd);
125*53ee8cc1Swenshuai.xi extern  int ehci_urb_enqueue (struct usb_hcd  *hcd, struct urb  *urb, int    mem_flags);
126*53ee8cc1Swenshuai.xi extern  int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb);
127*53ee8cc1Swenshuai.xi extern  void ehci_endpoint_disable (struct usb_hcd *hcd, struct hcd_dev *dev, int ep);
128*53ee8cc1Swenshuai.xi extern int ehci_get_frame (struct usb_hcd *hcd);
129*53ee8cc1Swenshuai.xi extern int ehci_hub_status_data (struct usb_hcd *hcd, char *buf);
130*53ee8cc1Swenshuai.xi extern  int ehci_hub_control (struct usb_hcd  *hcd, U16 typeReq, U16 wValue, U16 wIndex, char *buf, U16 wLength);
131*53ee8cc1Swenshuai.xi 
132*53ee8cc1Swenshuai.xi extern struct list_head hub_event_list_Port2;
133*53ee8cc1Swenshuai.xi extern void init_OS_Resource_EX(S32 *USBWaitFlg);
134*53ee8cc1Swenshuai.xi extern int ehci_hcd_cpe_ehci_drv_remove(struct device_s *_dev);
135*53ee8cc1Swenshuai.xi extern int ehci_hcd_cpe_ehci_drv_suspend(struct device_s *_dev, U32 state, U32 level);
136*53ee8cc1Swenshuai.xi extern int ehci_hcd_cpe_ehci_drv_resume(struct device_s *_dev, U32 level);
137*53ee8cc1Swenshuai.xi extern struct bus_type CPE_AMBA_bus_type_Port2;
138*53ee8cc1Swenshuai.xi 
139*53ee8cc1Swenshuai.xi 
usb_hcd_cpe_ehci_probe_Port2(struct hc_driver * driver,struct usb_hcd ** hcd_out,struct cpe_dev * dev)140*53ee8cc1Swenshuai.xi int usb_hcd_cpe_ehci_probe_Port2(struct hc_driver *driver,
141*53ee8cc1Swenshuai.xi         struct usb_hcd **hcd_out,
142*53ee8cc1Swenshuai.xi         struct cpe_dev *dev)
143*53ee8cc1Swenshuai.xi {
144*53ee8cc1Swenshuai.xi 	int retval;
145*53ee8cc1Swenshuai.xi 	struct usb_hcd *hcd = 0;
146*53ee8cc1Swenshuai.xi 	//Basic initialization for FPFA version IP
147*53ee8cc1Swenshuai.xi //	mwPeri20_Control_ChipEnable_Set();
148*53ee8cc1Swenshuai.xi //    #ifdef CYGPKG_USB_HALF_SPEED_MODE
149*53ee8cc1Swenshuai.xi //	mwPeri20_Control_HALFSPEEDEnable_Set();
150*53ee8cc1Swenshuai.xi  //  #endif
151*53ee8cc1Swenshuai.xi 
152*53ee8cc1Swenshuai.xi //#ifdef FORCE_FULL_SPEED
153*53ee8cc1Swenshuai.xi 	// Force HC to full speed
154*53ee8cc1Swenshuai.xi 	//mwOTG20_Control_ForceFullSpeed_Set();
155*53ee8cc1Swenshuai.xi 	//mwOTG20_Control_ForceHighSpeed_Clr();
156*53ee8cc1Swenshuai.xi //#endif
157*53ee8cc1Swenshuai.xi //#ifdef FORCE_HIGH_SPEED
158*53ee8cc1Swenshuai.xi 	// Force HC to high speed
159*53ee8cc1Swenshuai.xi 	//mwOTG20_Control_ForceFullSpeed_Clr();
160*53ee8cc1Swenshuai.xi 	//mwOTG20_Control_ForceHighSpeed_Set();
161*53ee8cc1Swenshuai.xi //#endif
162*53ee8cc1Swenshuai.xi 
163*53ee8cc1Swenshuai.xi 
164*53ee8cc1Swenshuai.xi        diag_printf("usb_hcd_cpe_ehci_probe port2\n");
165*53ee8cc1Swenshuai.xi 	cpe_ehci_start_hc(dev);
166*53ee8cc1Swenshuai.xi 
167*53ee8cc1Swenshuai.xi 	/*
168*53ee8cc1Swenshuai.xi 	* driver->hcd_alloc() will allocate a memory space of (struct ehci_hcd) and then return the reference of ehci_hcd.hcd back
169*53ee8cc1Swenshuai.xi 	* Therefore, driver can access the member of ehci_hcd later.
170*53ee8cc1Swenshuai.xi 	* driver->hcd_alloc is a function point of ehci_hcd_alloc()
171*53ee8cc1Swenshuai.xi 	*/
172*53ee8cc1Swenshuai.xi 
173*53ee8cc1Swenshuai.xi 	hcd = driver->hcd_alloc();
174*53ee8cc1Swenshuai.xi        diag_printf("hcd: %lx\n", (U32)hcd);
175*53ee8cc1Swenshuai.xi 	if (hcd == NULL){
176*53ee8cc1Swenshuai.xi 		dbg ("hcd_alloc failed%s"," ");
177*53ee8cc1Swenshuai.xi 		retval = -ENOMEM;
178*53ee8cc1Swenshuai.xi 		goto err1;
179*53ee8cc1Swenshuai.xi 	}
180*53ee8cc1Swenshuai.xi 
181*53ee8cc1Swenshuai.xi 	hcd->driver = (struct hc_driver *) driver;
182*53ee8cc1Swenshuai.xi 	//hcd->description = driver->description;
183*53ee8cc1Swenshuai.xi 
184*53ee8cc1Swenshuai.xi 	memcpy((char*)hcd,(char*)driver,24);
185*53ee8cc1Swenshuai.xi 
186*53ee8cc1Swenshuai.xi 	hcd->irq  = gIrqUHC2; //CPE_USB_EHCI1_IRQ;
187*53ee8cc1Swenshuai.xi 	hcd->regs = (U32*) gBaseUHC2;
188*53ee8cc1Swenshuai.xi         hcd->host_id = 2; // new
189*53ee8cc1Swenshuai.xi         hcd->phub_event = &hub_event_list_Port2;
190*53ee8cc1Swenshuai.xi 	hcd->pdev = (struct pci_dev  *)(1111); //Fake PCI device
191*53ee8cc1Swenshuai.xi 	hcd->self.controller = &dev->dev;
192*53ee8cc1Swenshuai.xi 	hcd->controller = hcd->self.controller;
193*53ee8cc1Swenshuai.xi 
194*53ee8cc1Swenshuai.xi 	retval = hcd_buffer_create (hcd);
195*53ee8cc1Swenshuai.xi 	if (retval != 0) {
196*53ee8cc1Swenshuai.xi 		dbg ("pool alloc fail%s","\n");
197*53ee8cc1Swenshuai.xi 		goto err1;
198*53ee8cc1Swenshuai.xi 	}
199*53ee8cc1Swenshuai.xi 
200*53ee8cc1Swenshuai.xi 	/* till now HC has been in an indeterminate state ... */
201*53ee8cc1Swenshuai.xi 	if (driver->reset && (retval = driver->reset (hcd)) < 0) {
202*53ee8cc1Swenshuai.xi 		dev_err (hcd->controller, "can't reset%s","\n");
203*53ee8cc1Swenshuai.xi 		goto err2;
204*53ee8cc1Swenshuai.xi 	}
205*53ee8cc1Swenshuai.xi 	// Initialize IRQ and ISR Trap, enable interrupt later (at the end)
206*53ee8cc1Swenshuai.xi #if 0
207*53ee8cc1Swenshuai.xi 	fLib_CloseInt(hcd->irq);
208*53ee8cc1Swenshuai.xi 	fLib_SetIntTrig(hcd->irq,LEVEL,L_ACTIVE);
209*53ee8cc1Swenshuai.xi 	retval = fLib_ReqInt (hcd->irq, usb_hcd_cpe_ehci_hcim_irq, hcd);
210*53ee8cc1Swenshuai.xi 	if ( retval == FALSE )
211*53ee8cc1Swenshuai.xi 	{
212*53ee8cc1Swenshuai.xi 		err("Register ISR fail%s","");
213*53ee8cc1Swenshuai.xi 		retval = -EINVAL;
214*53ee8cc1Swenshuai.xi 		goto err1;
215*53ee8cc1Swenshuai.xi 	}
216*53ee8cc1Swenshuai.xi #ifdef CONFIG_OTG
217*53ee8cc1Swenshuai.xi #ifndef CONFIG_FARADAY_FOTG200
218*53ee8cc1Swenshuai.xi 	// Enable CPE EHCI HC's Interrupt
219*53ee8cc1Swenshuai.xi 	fLib_EnableInt(hcd->irq);
220*53ee8cc1Swenshuai.xi #else
221*53ee8cc1Swenshuai.xi 	// Enable EHCI interrupt after intilizing OTG controller driver
222*53ee8cc1Swenshuai.xi #endif
223*53ee8cc1Swenshuai.xi #else
224*53ee8cc1Swenshuai.xi 	// Do OTG support ==> Enable CPE EHCI HC's Interrupt now
225*53ee8cc1Swenshuai.xi 	fLib_EnableInt(hcd->irq);
226*53ee8cc1Swenshuai.xi #endif
227*53ee8cc1Swenshuai.xi #endif
228*53ee8cc1Swenshuai.xi 	//mwOTG20_Interrupt_Mask_HOST_Clr();//yuwen mark
229*53ee8cc1Swenshuai.xi 
230*53ee8cc1Swenshuai.xi #if 0
231*53ee8cc1Swenshuai.xi 	if (retval != TRUE) {
232*53ee8cc1Swenshuai.xi 		dbg("request_irq failed%s"," ");
233*53ee8cc1Swenshuai.xi 		retval = -EBUSY;
234*53ee8cc1Swenshuai.xi 		goto err2;
235*53ee8cc1Swenshuai.xi 	}
236*53ee8cc1Swenshuai.xi #endif
237*53ee8cc1Swenshuai.xi 
238*53ee8cc1Swenshuai.xi 	usb_info ("%s (CPE_AMBA) at 0x%p, irq %d\n",
239*53ee8cc1Swenshuai.xi 		hcd->description, hcd->regs, hcd->irq);
240*53ee8cc1Swenshuai.xi 	usb_bus_init (&hcd->self);
241*53ee8cc1Swenshuai.xi 	hcd->self.op = &usb_hcd_operations;
242*53ee8cc1Swenshuai.xi 	hcd->self.hcpriv = (void *) hcd;
243*53ee8cc1Swenshuai.xi 	hcd->self.bus_name = "cpe_ehci_2";
244*53ee8cc1Swenshuai.xi 	//hcd->product_desc = "CPE_AMBA EHCI";
245*53ee8cc1Swenshuai.xi 	memcpy(hcd->product_desc, "CPE_AMBA EHCI 2", sizeof(hcd->product_desc));
246*53ee8cc1Swenshuai.xi 
247*53ee8cc1Swenshuai.xi         hcd->pre_sts = 0; // new
248*53ee8cc1Swenshuai.xi         hcd->pre_temp = 0; // new
249*53ee8cc1Swenshuai.xi         init_OS_Resource_EX(&hcd->USBWaitFlg);
250*53ee8cc1Swenshuai.xi 	INIT_LIST_HEAD (&hcd->dev_list);
251*53ee8cc1Swenshuai.xi 	usb_register_bus (&hcd->self);    //For USB2, marked???
252*53ee8cc1Swenshuai.xi 
253*53ee8cc1Swenshuai.xi 	if ((retval = driver->start (hcd)) < 0)
254*53ee8cc1Swenshuai.xi 	{
255*53ee8cc1Swenshuai.xi 		usb_hcd_cpe_ehci_remove(hcd, dev);
256*53ee8cc1Swenshuai.xi 		return retval;
257*53ee8cc1Swenshuai.xi 	}
258*53ee8cc1Swenshuai.xi 
259*53ee8cc1Swenshuai.xi 	*hcd_out = hcd;
260*53ee8cc1Swenshuai.xi 
261*53ee8cc1Swenshuai.xi 	return retval;
262*53ee8cc1Swenshuai.xi 
263*53ee8cc1Swenshuai.xi err2:
264*53ee8cc1Swenshuai.xi 	hcd_buffer_destroy (hcd);
265*53ee8cc1Swenshuai.xi 	if (hcd)
266*53ee8cc1Swenshuai.xi 	driver->hcd_free(hcd);
267*53ee8cc1Swenshuai.xi err1:
268*53ee8cc1Swenshuai.xi 	cpe_ehci_stop_hc(dev);
269*53ee8cc1Swenshuai.xi 	//release_mem_region(dev->res.start, dev->res.end - dev->res.start + 1);
270*53ee8cc1Swenshuai.xi 	return retval;
271*53ee8cc1Swenshuai.xi }
cpe_ehci_hcd_init_Port2(void)272*53ee8cc1Swenshuai.xi static void cpe_ehci_hcd_init_Port2(void)
273*53ee8cc1Swenshuai.xi {
274*53ee8cc1Swenshuai.xi 	memcpy( ehci_cpe_hc_driver_Port2.description ,  "ehci_hcd_2", sizeof("ehci_hcd_2")+1);
275*53ee8cc1Swenshuai.xi 
276*53ee8cc1Swenshuai.xi 	/*
277*53ee8cc1Swenshuai.xi 	* generic hardware linkage
278*53ee8cc1Swenshuai.xi 	*/
279*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.irq =      ehci_irq;
280*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.flags =    HCD_MEMORY | HCD_USB2;
281*53ee8cc1Swenshuai.xi 
282*53ee8cc1Swenshuai.xi 	/*
283*53ee8cc1Swenshuai.xi 	* basic lifecycle operations
284*53ee8cc1Swenshuai.xi 	*/
285*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.reset =    ehci_hc_reset;
286*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.start =    ehci_start;
287*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.suspend =  ehci_suspend;
288*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.resume  =  ehci_resume;
289*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.stop    =  ehci_stop;
290*53ee8cc1Swenshuai.xi 
291*53ee8cc1Swenshuai.xi 	/*
292*53ee8cc1Swenshuai.xi 	* memory lifecycle (except per-request)
293*53ee8cc1Swenshuai.xi 	*/
294*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.hcd_alloc =  ehci_hcd_alloc;
295*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.hcd_free  =  ehci_hcd_free;
296*53ee8cc1Swenshuai.xi 
297*53ee8cc1Swenshuai.xi 	/*
298*53ee8cc1Swenshuai.xi 	* managing i/o requests and associated device resources
299*53ee8cc1Swenshuai.xi 	*/
300*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.urb_enqueue      = ehci_urb_enqueue;
301*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.urb_dequeue      = ehci_urb_dequeue;
302*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.endpoint_disable =  ehci_endpoint_disable;
303*53ee8cc1Swenshuai.xi 
304*53ee8cc1Swenshuai.xi 	/*
305*53ee8cc1Swenshuai.xi 	* scheduling support
306*53ee8cc1Swenshuai.xi 	*/
307*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.get_frame_number =  ehci_get_frame;
308*53ee8cc1Swenshuai.xi 
309*53ee8cc1Swenshuai.xi 	/*
310*53ee8cc1Swenshuai.xi 	* root hub support
311*53ee8cc1Swenshuai.xi 	*/
312*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.hub_status_data =  ehci_hub_status_data;
313*53ee8cc1Swenshuai.xi 	ehci_cpe_hc_driver_Port2.hub_control     =  ehci_hub_control;
314*53ee8cc1Swenshuai.xi }
315*53ee8cc1Swenshuai.xi 
316*53ee8cc1Swenshuai.xi extern void InitUSBIntr_Port2(struct usb_hcd * hcd);
ehci_hcd_cpe_ehci_drv_probe_Port2(struct device_s * _dev)317*53ee8cc1Swenshuai.xi static int ehci_hcd_cpe_ehci_drv_probe_Port2(struct device_s *_dev)
318*53ee8cc1Swenshuai.xi {
319*53ee8cc1Swenshuai.xi     struct cpe_dev *dev;
320*53ee8cc1Swenshuai.xi     struct usb_hcd *hcd = NULL;
321*53ee8cc1Swenshuai.xi     int ret;
322*53ee8cc1Swenshuai.xi 
323*53ee8cc1Swenshuai.xi     const struct device_s *__mptr = _dev;
324*53ee8cc1Swenshuai.xi     dev = (struct cpe_dev *)( (char *)__mptr - (char *)offsetof(struct cpe_dev,dev) );
325*53ee8cc1Swenshuai.xi 
326*53ee8cc1Swenshuai.xi     EHCI_Dbg("ehci_hcd_cpe_ehci_drv_probe_Port2 enter\n");
327*53ee8cc1Swenshuai.xi     if (usb_disabled())
328*53ee8cc1Swenshuai.xi         return -ENODEV;
329*53ee8cc1Swenshuai.xi 
330*53ee8cc1Swenshuai.xi     cpe_ehci_hcd_init_Port2();
331*53ee8cc1Swenshuai.xi 
332*53ee8cc1Swenshuai.xi     ret = usb_hcd_cpe_ehci_probe_Port2(&ehci_cpe_hc_driver_Port2, &hcd, dev);
333*53ee8cc1Swenshuai.xi 
334*53ee8cc1Swenshuai.xi     if (ret == 0)
335*53ee8cc1Swenshuai.xi     {
336*53ee8cc1Swenshuai.xi         dev->dev.driver_data = hcd;
337*53ee8cc1Swenshuai.xi         g_pUsbHcd_Port2 = hcd;
338*53ee8cc1Swenshuai.xi         InitUSBIntr_Port2(hcd);					//add USB interrupt entry . yuwen
339*53ee8cc1Swenshuai.xi     }
340*53ee8cc1Swenshuai.xi 
341*53ee8cc1Swenshuai.xi     return ret;
342*53ee8cc1Swenshuai.xi }
ehci_hcd_cpe_ehci_init_Port2(void)343*53ee8cc1Swenshuai.xi static int __init ehci_hcd_cpe_ehci_init_Port2(void)
344*53ee8cc1Swenshuai.xi {
345*53ee8cc1Swenshuai.xi 	pr_debug ("ehci_hcd: block sizes: qh %d qtd %d itd %d sitd %d\n",
346*53ee8cc1Swenshuai.xi 				sizeof (struct ehci_qh), sizeof (struct ehci_qtd),
347*53ee8cc1Swenshuai.xi 				sizeof (struct ehci_itd), sizeof (struct ehci_sitd));
348*53ee8cc1Swenshuai.xi 	strncpy(ehci_hcd_cpe_driver_Port2.drv.name, "cpe_ehci_2", sizeof("cpe_ehci_2"));
349*53ee8cc1Swenshuai.xi 	ehci_hcd_cpe_driver_Port2.drv.bus     = &CPE_AMBA_bus_type_Port2;
350*53ee8cc1Swenshuai.xi 	ehci_hcd_cpe_driver_Port2.drv.probe   = ehci_hcd_cpe_ehci_drv_probe_Port2;
351*53ee8cc1Swenshuai.xi 	ehci_hcd_cpe_driver_Port2.drv.remove  = ehci_hcd_cpe_ehci_drv_remove;
352*53ee8cc1Swenshuai.xi 	ehci_hcd_cpe_driver_Port2.drv.suspend = ehci_hcd_cpe_ehci_drv_suspend;
353*53ee8cc1Swenshuai.xi 	ehci_hcd_cpe_driver_Port2.drv.resume  = ehci_hcd_cpe_ehci_drv_resume;
354*53ee8cc1Swenshuai.xi 	ehci_hcd_cpe_driver_Port2.devid       = CPE_DEVID_USB_PORT2;
355*53ee8cc1Swenshuai.xi 	return driver_register(&ehci_hcd_cpe_driver_Port2.drv);
356*53ee8cc1Swenshuai.xi }
357*53ee8cc1Swenshuai.xi 
358*53ee8cc1Swenshuai.xi 
ehci_cpe_dev_init_Port2(void)359*53ee8cc1Swenshuai.xi int __init ehci_cpe_dev_init_Port2(void)
360*53ee8cc1Swenshuai.xi {
361*53ee8cc1Swenshuai.xi 	// Cannot remove: Init list heads of device and driver lists of CPE EHCI device
362*53ee8cc1Swenshuai.xi 	EHCI_Dbg("ehci_cpe_dev_init_Port2 enter\n");
363*53ee8cc1Swenshuai.xi 	device_initialize(&cpe_ehci_dev_Port2.dev);
364*53ee8cc1Swenshuai.xi #ifdef DEBUG
365*53ee8cc1Swenshuai.xi 	//dbg (DRIVER_INFO " Init CPE EHCI Host Controller%s"," ");
366*53ee8cc1Swenshuai.xi #endif
367*53ee8cc1Swenshuai.xi 	// Init CPE EHCI device data structure
368*53ee8cc1Swenshuai.xi 	cpe_ehci_dev_Port2.dev.parent =  NULL; //parent should be CPE AMBA
369*53ee8cc1Swenshuai.xi 	strncpy(cpe_ehci_dev_Port2.dev.name,"CPE_EHCI HC 2", sizeof("CPE_EHCI HC 2"));
370*53ee8cc1Swenshuai.xi 	strncpy(cpe_ehci_dev_Port2.dev.bus_id,"AHB0_EHCI_2", sizeof("AHB0_EHCI_2"));
371*53ee8cc1Swenshuai.xi 	cpe_ehci_dev_Port2.dev.bus  = &CPE_AMBA_bus_type_Port2;
372*53ee8cc1Swenshuai.xi 	cpe_ehci_dev_Port2.devid    = CPE_DEVID_USB_PORT2;
373*53ee8cc1Swenshuai.xi 	cpe_ehci_dev_Port2.mapbase  = gBaseUHC2;
374*53ee8cc1Swenshuai.xi 	cpe_ehci_dev_Port2.utmibase  = gBaseUTMI2;
375*53ee8cc1Swenshuai.xi         cpe_ehci_dev_Port2.usbcbase  = gBaseUSBC2;
376*53ee8cc1Swenshuai.xi 	cpe_ehci_dev_Port2.dma_mask = 0x00; //Unsupport DMA
377*53ee8cc1Swenshuai.xi 	//register cpe_ehci devie to CPE AMBA bus
378*53ee8cc1Swenshuai.xi 	device_add(&cpe_ehci_dev_Port2.dev);
379*53ee8cc1Swenshuai.xi 
380*53ee8cc1Swenshuai.xi 	return ehci_hcd_cpe_ehci_init_Port2();
381*53ee8cc1Swenshuai.xi }
382*53ee8cc1Swenshuai.xi 
383