1 /******************************************************************************
2 ** File Name: usb_boot.c *
3 ** Author: Daniel.Ding *
5 ** Copyright: 2005 Spreatrum, Incoporated. All Rights Reserved. *
7 *****************************************************************************/
8 /******************************************************************************
10 **---------------------------------------------------------------------------*
11 ** DATE NAME DESCRIPTION *
12 ** 3/25/2005 Daniel.Ding Create. *
13 *****************************************************************************/
14 /*----------------------------------------------------------------------------*
16 **---------------------------------------------------------------------------*/
17 #include <asm/arch/usb_boot.h>
18 #include <asm/arch/drv_usb.h>
19 #include <asm/arch/virtual_com.h>
20 #include <asm/arch/fdl_crc.h>
21 #include <asm/arch/fdl_channel.h>
22 #include <asm/arch/usb20_reg_v3.h>
23 /**---------------------------------------------------------------------------*
25 **---------------------------------------------------------------------------*/
30 /*----------------------------------------------------------------------------*
31 ** Mcaro Definitions *
32 **---------------------------------------------------------------------------*/
34 #if (defined CONFIG_SC8830) || (defined CONFIG_SC9630)
35 #define AHB_CTRL0 (0x20D00000)
42 #define AHB_CTRL0 (0x20900200)
45 #define AHB_CONTROL_REG3 (0x2090020c)
46 #define CLK_USB_REF_SEL BIT_1
47 #define USB_S_HBIGENDIAN BIT_2
48 #define CLK_USB_REF_EN BIT_6
49 //#define AHB_SOFT_RST (0x20900210)
50 //#define USBPHY_SOFT_RST BIT_7
51 //#define AHB_ARM_CLK (0x20900224)
53 #define USB_BUFF_SIZE 0x4000
54 /*----------------------------------------------------------------------------*
56 **---------------------------------------------------------------------------*/
58 /*--------------------------- Local Data ------------------------------------*/
59 LOCAL __align(32) uint8 s_usb_snd_buff[USB_BUFF_SIZE];
60 /*--------------------------- Global Data -----------------------------------*/
61 /*--------------------------- External Data ---------------------------------*/
62 /*----------------------------------------------------------------------------*
63 ** Local Function Prototype *
64 **---------------------------------------------------------------------------*/
66 void usb_write (unsigned char *write_buf, unsigned int write_len);
67 void usb_init (unsigned long ext_clk26M);
69 #if !(defined( CONFIG_SC8830) || defined(CONFIG_SC9630))
70 static void SetPllClock (void)
73 clk = * (volatile uint32 *) (AHB_ARM_CLK);
74 clk &= ~ ( (3 << 23) | (7 << 4) | (7));
75 clk |= ( (1 << 23) | (1 << 4) | (0));
77 * (volatile uint32 *) (AHB_ARM_CLK) = clk;
80 /*****************************************************************************/
82 // Global resource dependence:
83 // Author: Daniel.Ding
85 /*****************************************************************************/
86 void usb_init (unsigned long ext_clk26M)
88 #if !(defined( CONFIG_SC8830) || defined(CONFIG_SC9630))
89 #if (!defined(_LITTLE_ENDIAN) && !defined(CHIP_ENDIAN_LITTLE))
90 *(volatile uint32 *)AHB_CONTROL_REG3 |= USB_S_HBIGENDIAN; //master AHB interface: Big Endian
92 *(volatile uint32 *)AHB_CONTROL_REG3 &= ~USB_S_HBIGENDIAN; //master AHB interface: Little Endian
96 *(volatile uint32 *)AHB_CTRL0 |= USBD_EN; // usbd enable
99 /*****************************************************************************/
101 // Global resource dependence:
102 // Author: Daniel.Ding
104 /*****************************************************************************/
105 void usb_boot (uint32 ext_clk26M)
107 usb_init (ext_clk26M);
109 void usb_varinit (void)
113 /*****************************************************************************/
115 // Global resource dependence:
118 /*****************************************************************************/
119 PUBLIC void usb_ldo_enable (BOOLEAN is_usb_ldo_enabled)
121 volatile unsigned long usb_ldo = 0;
123 // usb_ldo = *(volatile unsigned long *)(GLOBAL_CTL_LDO);
125 if (is_usb_ldo_enabled)
127 usb_ldo &= ~ (BIT_10);
133 usb_ldo &= ~ (BIT_11);
136 //*(volatile unsigned long *)(GLOBAL_CTL_LDO) = usb_ldo;
140 /*****************************************************************************/
142 // Global resource dependence:
143 // Author: Daniel.Ding
145 /*****************************************************************************/
146 void usb_write (unsigned char *write_buf,unsigned int write_len)
148 memcpy (s_usb_snd_buff, write_buf, write_len);
149 USB_EPxSendData (USB_EP5 , (unsigned int *) s_usb_snd_buff, write_len);
151 extern char VCOM_GetChar (void);
152 extern int VCOM_GetSingleChar (void);
153 extern int VCOM_Read(const unsigned char *buf, unsigned int len);
155 static int FDL_UsbOpen (struct FDL_ChannelHandler *channel, unsigned int baudrate)
159 static int FDL_UsbRead (struct FDL_ChannelHandler *channel, const unsigned char *buf, unsigned int len)
161 return VCOM_Read(buf, len);
163 static char FDL_UsbGetChar (struct FDL_ChannelHandler *channel)
165 return VCOM_GetChar();
167 static int FDL_UsbGetSingleChar (struct FDL_ChannelHandler *channel)
169 return VCOM_GetSingleChar();
171 static int FDL_UsbWrite (struct FDL_ChannelHandler *channel, const unsigned char *buf, unsigned int len)
173 usb_write ( (unsigned char *) buf, len);
177 static int FDL_UsbPutChar (struct FDL_ChannelHandler *channel, const unsigned char ch)
179 s_usb_snd_buff[0] = ch;
181 USB_EPxSendData (USB_EP3 , (unsigned int *) &s_usb_snd_buff, 1);
185 static int FDL_UsbSetBaudrate (struct FDL_ChannelHandler *channel, unsigned int baudrate)
189 static int FDL_UsbClose (struct FDL_ChannelHandler *channel)
193 struct FDL_ChannelHandler gUSBChannel =
198 FDL_UsbGetSingleChar,
206 /**---------------------------------------------------------------------------*
208 **---------------------------------------------------------------------------*/