ARM: sc8830: fdl: remove build warnings
[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 extern void usb_core_init (void);
63 /*----------------------------------------------------------------------------*
64 **                         Local Function Prototype                           *
65 **---------------------------------------------------------------------------*/
66
67 void usb_write (unsigned char *write_buf,  unsigned int write_len);
68 void usb_init (unsigned long ext_clk26M);
69
70 #if !(defined( CONFIG_SC8830) || defined(CONFIG_SC9630))
71 static void SetPllClock (void)
72 {
73     uint32 clk;
74     clk = * (volatile uint32 *) (AHB_ARM_CLK);
75     clk &= ~ ( (3 << 23) | (7 << 4) | (7));
76     clk |= ( (1 << 23) | (1 << 4) | (0));
77
78     * (volatile uint32 *) (AHB_ARM_CLK) = clk;
79 }
80 #endif
81 /*****************************************************************************/
82 //  Description:
83 //    Global resource dependence:
84 //  Author:         Daniel.Ding
85 //    Note:
86 /*****************************************************************************/
87 void usb_init (unsigned long ext_clk26M)
88 {
89 #if !(defined( CONFIG_SC8830) || defined(CONFIG_SC9630))
90 #if (!defined(_LITTLE_ENDIAN) && !defined(CHIP_ENDIAN_LITTLE))
91     *(volatile uint32 *)AHB_CONTROL_REG3 |= USB_S_HBIGENDIAN;    //master AHB interface: Big Endian
92 #else
93     *(volatile uint32 *)AHB_CONTROL_REG3 &= ~USB_S_HBIGENDIAN;    //master AHB interface: Little Endian
94 #endif
95 #endif
96     
97     *(volatile uint32 *)AHB_CTRL0 |= USBD_EN;  // usbd enable
98     usb_core_init();
99 }
100 /*****************************************************************************/
101 //  Description:
102 //    Global resource dependence:
103 //  Author:         Daniel.Ding
104 //    Note:
105 /*****************************************************************************/
106 void usb_boot (uint32 ext_clk26M)
107 {
108     usb_init (ext_clk26M);
109 }
110 void usb_varinit (void)
111 {
112     usb_init (0);
113 }
114 /*****************************************************************************/
115 //  Description:
116 //    Global resource dependence:
117 //  Author:
118 //    Note:
119 /*****************************************************************************/
120 PUBLIC void usb_ldo_enable (BOOLEAN is_usb_ldo_enabled)
121 {
122     volatile unsigned long usb_ldo = 0;
123
124     // usb_ldo  = *(volatile unsigned long *)(GLOBAL_CTL_LDO);
125
126     if (is_usb_ldo_enabled)
127     {
128         usb_ldo &= ~ (BIT_10);
129         usb_ldo |= (BIT_11);
130     }
131     else
132     {
133         usb_ldo |= (BIT_10);
134         usb_ldo &= ~ (BIT_11);
135     }
136
137     //*(volatile unsigned long *)(GLOBAL_CTL_LDO) = usb_ldo;
138
139     return;
140 }
141 /*****************************************************************************/
142 //  Description:
143 //    Global resource dependence:
144 //  Author:         Daniel.Ding
145 //    Note:
146 /*****************************************************************************/
147 void usb_write (unsigned char *write_buf,unsigned int write_len)
148 {
149     memcpy (s_usb_snd_buff, write_buf, write_len);
150     USB_EPxSendData (USB_EP5 , (unsigned int *) s_usb_snd_buff, write_len);
151 }
152 extern char VCOM_GetChar (void);
153 extern int VCOM_GetSingleChar (void);
154 extern int VCOM_Read(unsigned char *buf, unsigned int len);
155
156 static int FDL_UsbOpen (struct FDL_ChannelHandler  *channel, unsigned int baudrate)
157 {
158     return 0;
159 }
160 static int FDL_UsbRead (struct FDL_ChannelHandler  *channel, unsigned char *buf, unsigned int len)
161 {
162     return VCOM_Read(buf, len);
163 }
164 static char FDL_UsbGetChar (struct FDL_ChannelHandler  *channel)
165 {
166     return VCOM_GetChar();
167 }
168 static int FDL_UsbGetSingleChar (struct FDL_ChannelHandler  *channel)
169 {
170     return VCOM_GetSingleChar();
171 }
172 static int FDL_UsbWrite (struct FDL_ChannelHandler  *channel, const unsigned char *buf, unsigned int len)
173 {
174     usb_write ( (unsigned char *) buf, len);
175     return 0;
176 }
177
178 static int FDL_UsbPutChar (struct FDL_ChannelHandler  *channel, const unsigned char ch)
179 {
180     s_usb_snd_buff[0] = ch;
181     //int data = ch;
182     USB_EPxSendData (USB_EP3 , (unsigned int *) &s_usb_snd_buff, 1);
183     return 0;
184 }
185
186 static int FDL_UsbSetBaudrate (struct FDL_ChannelHandler  *channel,  unsigned int baudrate)
187 {
188     return 0;
189 }
190 static int FDL_UsbClose (struct FDL_ChannelHandler  *channel)
191 {
192     return 0;
193 }
194 struct FDL_ChannelHandler gUSBChannel =
195 {
196     FDL_UsbOpen,
197     FDL_UsbRead,
198     FDL_UsbGetChar,
199     FDL_UsbGetSingleChar,
200     FDL_UsbWrite,
201     FDL_UsbPutChar,
202     FDL_UsbSetBaudrate,
203     FDL_UsbClose,
204     0
205 };
206
207 /**---------------------------------------------------------------------------*
208 **                         Compiler Flag                                      *
209 **---------------------------------------------------------------------------*/
210 #ifdef   __cplusplus
211 }
212 #endif