tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / nand_fdl / common / src / usb_boot.c
1 /******************************************************************************
2  ** File Name:    usb_boot.c                                                  *
3  ** Author:       Daniel.Ding                                                 *
4  ** DATE:         4/25/2005                                                   *
5  ** Copyright:    2005 Spreatrum, Incoporated. All Rights Reserved.           *
6  ** Description:                                                              *
7  *****************************************************************************/
8 /******************************************************************************
9  **                   Edit    History                                         *
10  **---------------------------------------------------------------------------*
11  ** DATE          NAME            DESCRIPTION                                 *
12  ** 3/25/2005     Daniel.Ding     Create.                                     *
13  *****************************************************************************/
14 /*----------------------------------------------------------------------------*
15 **                        Dependencies                                        *
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 /**---------------------------------------------------------------------------*
24 **                        Compiler Flag                                       *
25 **---------------------------------------------------------------------------*/
26 #ifdef   __cplusplus
27 extern   "C"
28 {
29 #endif
30 /*----------------------------------------------------------------------------*
31 **                            Mcaro Definitions                               *
32 **---------------------------------------------------------------------------*/
33 //AHB Register
34 #if (defined CONFIG_SC8830) || (defined CONFIG_SC9630)
35 #define AHB_CTRL0                           (0x20D00000)
36 #ifdef CONFIG_SPX15
37 #define USBD_EN                             BIT_4
38 #else
39 #define USBD_EN                             BIT_5
40 #endif
41 #else
42 #define AHB_CTRL0                           (0x20900200)
43 #define USBD_EN                             BIT_4
44 #endif
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)
52
53 #define USB_BUFF_SIZE  0x4000
54 /*----------------------------------------------------------------------------*
55 **                             Data Structures                                *
56 **---------------------------------------------------------------------------*/
57
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 **---------------------------------------------------------------------------*/
65
66 void usb_write (unsigned char *write_buf,  unsigned int write_len);
67 void usb_init (unsigned long ext_clk26M);
68
69 #if !(defined( CONFIG_SC8830) || defined(CONFIG_SC9630))
70 static void SetPllClock (void)
71 {
72     uint32 clk;
73     clk = * (volatile uint32 *) (AHB_ARM_CLK);
74     clk &= ~ ( (3 << 23) | (7 << 4) | (7));
75     clk |= ( (1 << 23) | (1 << 4) | (0));
76
77     * (volatile uint32 *) (AHB_ARM_CLK) = clk;
78 }
79 #endif
80 /*****************************************************************************/
81 //  Description:
82 //    Global resource dependence:
83 //  Author:         Daniel.Ding
84 //    Note:
85 /*****************************************************************************/
86 void usb_init (unsigned long ext_clk26M)
87 {
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
91 #else
92     *(volatile uint32 *)AHB_CONTROL_REG3 &= ~USB_S_HBIGENDIAN;    //master AHB interface: Little Endian
93 #endif
94 #endif
95     
96     *(volatile uint32 *)AHB_CTRL0 |= USBD_EN;  // usbd enable
97     usb_core_init();
98 }
99 /*****************************************************************************/
100 //  Description:
101 //    Global resource dependence:
102 //  Author:         Daniel.Ding
103 //    Note:
104 /*****************************************************************************/
105 void usb_boot (uint32 ext_clk26M)
106 {
107     usb_init (ext_clk26M);
108 }
109 void usb_varinit (void)
110 {
111     usb_init (0);
112 }
113 /*****************************************************************************/
114 //  Description:
115 //    Global resource dependence:
116 //  Author:
117 //    Note:
118 /*****************************************************************************/
119 PUBLIC void usb_ldo_enable (BOOLEAN is_usb_ldo_enabled)
120 {
121     volatile unsigned long usb_ldo = 0;
122
123     // usb_ldo  = *(volatile unsigned long *)(GLOBAL_CTL_LDO);
124
125     if (is_usb_ldo_enabled)
126     {
127         usb_ldo &= ~ (BIT_10);
128         usb_ldo |= (BIT_11);
129     }
130     else
131     {
132         usb_ldo |= (BIT_10);
133         usb_ldo &= ~ (BIT_11);
134     }
135
136     //*(volatile unsigned long *)(GLOBAL_CTL_LDO) = usb_ldo;
137
138     return;
139 }
140 /*****************************************************************************/
141 //  Description:
142 //    Global resource dependence:
143 //  Author:         Daniel.Ding
144 //    Note:
145 /*****************************************************************************/
146 void usb_write (unsigned char *write_buf,unsigned int write_len)
147 {
148     memcpy (s_usb_snd_buff, write_buf, write_len);
149     USB_EPxSendData (USB_EP5 , (unsigned int *) s_usb_snd_buff, write_len);
150 }
151 extern char VCOM_GetChar (void);
152 extern int VCOM_GetSingleChar (void);
153 extern int VCOM_Read(const unsigned char *buf, unsigned int len);
154
155 static int FDL_UsbOpen (struct FDL_ChannelHandler  *channel, unsigned int baudrate)
156 {
157     return 0;
158 }
159 static int FDL_UsbRead (struct FDL_ChannelHandler  *channel, const unsigned char *buf, unsigned int len)
160 {
161     return VCOM_Read(buf, len);
162 }
163 static char FDL_UsbGetChar (struct FDL_ChannelHandler  *channel)
164 {
165     return VCOM_GetChar();
166 }
167 static int FDL_UsbGetSingleChar (struct FDL_ChannelHandler  *channel)
168 {
169     return VCOM_GetSingleChar();
170 }
171 static int FDL_UsbWrite (struct FDL_ChannelHandler  *channel, const unsigned char *buf, unsigned int len)
172 {
173     usb_write ( (unsigned char *) buf, len);
174     return 0;
175 }
176
177 static int FDL_UsbPutChar (struct FDL_ChannelHandler  *channel, const unsigned char ch)
178 {
179     s_usb_snd_buff[0] = ch;
180     //int data = ch;
181     USB_EPxSendData (USB_EP3 , (unsigned int *) &s_usb_snd_buff, 1);
182     return 0;
183 }
184
185 static int FDL_UsbSetBaudrate (struct FDL_ChannelHandler  *channel,  unsigned int baudrate)
186 {
187     return 0;
188 }
189 static int FDL_UsbClose (struct FDL_ChannelHandler  *channel)
190 {
191     return 0;
192 }
193 struct FDL_ChannelHandler gUSBChannel =
194 {
195     FDL_UsbOpen,
196     FDL_UsbRead,
197     FDL_UsbGetChar,
198     FDL_UsbGetSingleChar,
199     FDL_UsbWrite,
200     FDL_UsbPutChar,
201     FDL_UsbSetBaudrate,
202     FDL_UsbClose,
203     0
204 };
205
206 /**---------------------------------------------------------------------------*
207 **                         Compiler Flag                                      *
208 **---------------------------------------------------------------------------*/
209 #ifdef   __cplusplus
210 }
211 #endif