lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <usb/global.h>
|
| 2 | #include <usb/config.h>
|
| 3 | extern WORD32 USB_CDC_Enum(WORD32 USB_ADDR);
|
| 4 | //extern void USB_Pll_Clk_Rst_InitEnv(void);
|
| 5 |
|
| 6 | void USB_TstDev_InitEnv(void);
|
| 7 |
|
| 8 | #if 0
|
| 9 | void tsp_usb_init(WORD32 USB_ADDR)
|
| 10 | {
|
| 11 | WORD32 dwConnect;
|
| 12 |
|
| 13 | /*ÅäÖÃÍâΧ»·¾³*/
|
| 14 |
|
| 15 | USB_Pll_Clk_Rst_InitEnv();
|
| 16 |
|
| 17 | dwConnect=USB_CDC_Enum(USB_ADDR);
|
| 18 |
|
| 19 | if(0==dwConnect)
|
| 20 | {
|
| 21 | printk("NOLINK\n");
|
| 22 | return ;
|
| 23 | }
|
| 24 |
|
| 25 | printk("FAILED\n");
|
| 26 |
|
| 27 | }
|
| 28 | #endif
|
| 29 |
|
| 30 | int tsp_usb_init(void)
|
| 31 | {
|
| 32 | WORD32 retVal = 0;
|
| 33 | WORD32 usb_addr = 0;
|
| 34 | // BYTE boot_mode = get_boot_mode();
|
| 35 | BYTE boot_mode = 1;
|
| 36 | data_init();
|
| 37 | /*add by sunyunchen*/
|
| 38 | if(2 == boot_mode)
|
| 39 | //if(0)
|
| 40 | {
|
| 41 | printf("hsic\n");
|
| 42 | global.g_USB_MODE = 1;
|
| 43 | usb_addr = SYS_USB_HSIC_BASE;
|
| 44 | }
|
| 45 | else
|
| 46 | {
|
| 47 | printf("usb\n");
|
| 48 | global.g_USB_MODE = 0;
|
| 49 | usb_addr = SYS_USB_BASE;
|
| 50 | }
|
| 51 | if((REG32(usb_addr+DWC_DEV_GLOBAL_REG_OFFSET)&0x7f0)!=0)//dcfg register
|
| 52 | {
|
| 53 | //printf("usb_g_enum!\n");
|
| 54 | global.g_enum =DONOT_NEED_ENUM;
|
| 55 |
|
| 56 |
|
| 57 | //global.g_enum =NEED_ENUM;
|
| 58 | }
|
| 59 | if(NEED_ENUM == global.g_enum)
|
| 60 | {
|
| 61 | //printf("need enum\n");
|
| 62 | USB_TstDev_InitEnv();
|
| 63 | }
|
| 64 | else
|
| 65 | {
|
| 66 | //printf("global.g_dwc\n");
|
| 67 | global.g_dwc_otg_pcd_tp.ep0state = EP0_IDLE;
|
| 68 | global.dwRxQuit = 1;
|
| 69 | global.dwTxQuit = 1;
|
| 70 | global.g_dwc_otg_pcd_tp.request_config = 1;
|
| 71 | }
|
| 72 |
|
| 73 | retVal = USB_CDC_Enum(usb_addr);
|
| 74 |
|
| 75 | return retVal;
|
| 76 | }
|
| 77 |
|
| 78 | void USB_TstDev_InitEnv(void)
|
| 79 | {
|
| 80 | #if USE_ASIC
|
| 81 | WORD32 i;
|
| 82 | if(0 == global.g_USB_MODE)
|
| 83 | {
|
| 84 |
|
| 85 | //ÊÍ·ÅUSB¸ôÀë8bit for usb ctrl
|
| 86 | REG32(POWER_DOMAIN_ISO) |= (1<<8);
|
| 87 | usdelay(10);
|
| 88 |
|
| 89 | REG32(POWER_DOMAIN_RST) |= (1<<8);
|
| 90 | usdelay(10);
|
| 91 |
|
| 92 | REG32(POWER_DOMAIN_POWERON) &= ~(1<<8);
|
| 93 | usdelay(10);
|
| 94 |
|
| 95 | REG32(POWER_DOMAIN_POWERON) |= (1<<8);
|
| 96 | usdelay(10);
|
| 97 |
|
| 98 | REG32(POWER_DOMAIN_RST) &= ~(1<<8);
|
| 99 | usdelay(10);
|
| 100 |
|
| 101 | REG32(POWER_DOMAIN_ISO) &= ~(1<<8);
|
| 102 | usdelay(10);
|
| 103 |
|
| 104 | //usb ahb clock enable
|
| 105 | REG32(SOC_MOD_CLKEN0)&=~(1<<4);
|
| 106 | usdelay(20);
|
| 107 | REG32(SOC_MOD_CLKEN0)|=(1<<4);
|
| 108 | //usb phy clock enable
|
| 109 | REG32(SOC_MOD_CLKEN1)&=~(1<<3);
|
| 110 | usdelay(20);
|
| 111 | REG32(SOC_MOD_CLKEN1)|=(1<<3);
|
| 112 |
|
| 113 | // usb ahb reset ÏÈ×ÜÏߺó¹¤×÷
|
| 114 | REG32(SOC_MOD_RSTEN)&=~(1<<5);
|
| 115 | usdelay(100);
|
| 116 | REG32(SOC_MOD_RSTEN)|=(1<<5);
|
| 117 | usdelay(100);
|
| 118 |
|
| 119 | // usb work reset
|
| 120 | REG32(SOC_MOD_RSTEN)&=~(1<<4);
|
| 121 | usdelay(100);
|
| 122 | REG32(SOC_MOD_RSTEN)|=(1<<4);
|
| 123 | usdelay(100);
|
| 124 |
|
| 125 | //release usb phy reset
|
| 126 | REG32(SOC_MOD_RSTEN)&=~(1<<3);
|
| 127 | usdelay(100);
|
| 128 | REG32(SOC_MOD_RSTEN) |= 1<<3;
|
| 129 | usdelay(100);
|
| 130 |
|
| 131 | i = 0;
|
| 132 | while((REG32(SOC_MOD_USBSTATECTRL)&0x2) == 0)
|
| 133 | {
|
| 134 | i++;
|
| 135 | usdelay(20);
|
| 136 | if(i>50000) break;
|
| 137 | }
|
| 138 | }
|
| 139 | else
|
| 140 | {
|
| 141 | //ÊÍ·ÅUSB_HSIC¸ôÀë9bit for hsic
|
| 142 | REG32(POWER_DOMAIN_ISO) |= (1<<9);
|
| 143 | usdelay(10);
|
| 144 |
|
| 145 | REG32(POWER_DOMAIN_RST) |= (1<<9);
|
| 146 | usdelay(10);
|
| 147 |
|
| 148 | REG32(POWER_DOMAIN_POWERON) &= ~(1<<9);
|
| 149 | usdelay(10);
|
| 150 |
|
| 151 | REG32(POWER_DOMAIN_POWERON) |= (1<<9);
|
| 152 | usdelay(10);
|
| 153 |
|
| 154 | REG32(POWER_DOMAIN_RST) &= ~(1<<9);
|
| 155 | usdelay(10);
|
| 156 |
|
| 157 | REG32(POWER_DOMAIN_ISO) &= ~(1<<9);
|
| 158 | usdelay(10);
|
| 159 |
|
| 160 | //usb hsic ahb clock enable
|
| 161 | REG32(SOC_MOD_CLKEN0)&=~(1<<2);
|
| 162 | usdelay(20);
|
| 163 | REG32(SOC_MOD_CLKEN0)|=(1<<2);
|
| 164 | //usb hsic phy clock enable
|
| 165 | REG32(SOC_MOD_CLKEN0)&=~(1<<1);
|
| 166 | usdelay(20);
|
| 167 | REG32(SOC_MOD_CLKEN0)|=(1<<1);
|
| 168 |
|
| 169 | //usb hsic 480M clock enable
|
| 170 | REG32(SOC_MOD_CLKEN0)&=~(1<<0);
|
| 171 | usdelay(20);
|
| 172 | REG32(SOC_MOD_CLKEN0)|=(1<<0);
|
| 173 |
|
| 174 | // usb hsic ahb reset
|
| 175 | REG32(SOC_MOD_RSTEN)&=~(1<<2);
|
| 176 | usdelay(20);
|
| 177 | REG32(SOC_MOD_RSTEN)|=(1<<2);
|
| 178 | usdelay(10);
|
| 179 |
|
| 180 | // usb hsic work reset
|
| 181 | REG32(SOC_MOD_RSTEN)&=~(1<<1);
|
| 182 | usdelay(20);
|
| 183 | REG32(SOC_MOD_RSTEN)|=(1<<1);
|
| 184 | //release usb hsic phy reset
|
| 185 | REG32(SOC_MOD_RSTEN)&=~(1<<0);
|
| 186 | usdelay(20);
|
| 187 | REG32(SOC_MOD_RSTEN)|=(1<<0);
|
| 188 |
|
| 189 | usdelay(100);
|
| 190 | i = 0;
|
| 191 | while((REG32(SOC_MOD_USBSTATECTRL)&0x1) == 0)
|
| 192 | {
|
| 193 | i++;
|
| 194 | usdelay(20);
|
| 195 | if(i>50000) break;
|
| 196 | }
|
| 197 |
|
| 198 | #if SYNC_USB_HSIC
|
| 199 | usdelay(20);
|
| 200 | REG32(REG_GPIO_OUT)=1;
|
| 201 | while(REG32(REG_GPIO_IN)!=0xFF);
|
| 202 | usdelay(1);
|
| 203 | REG32(REG_GPIO_OUT)=0;
|
| 204 | #endif
|
| 205 | }
|
| 206 | #endif
|
| 207 | #if !USE_ASIC
|
| 208 | #if 1
|
| 209 | //usb power on
|
| 210 | REG32(POWER_DOMAIN_POWERON) |= 0x300;
|
| 211 | usdelay(10);
|
| 212 | //usb disable reset
|
| 213 | REG32(POWER_DOMAIN_RST) &= 0xfffffcff; //
|
| 214 | usdelay(10);
|
| 215 | //usb disable iso
|
| 216 | REG32(POWER_DOMAIN_ISO) &= 0xfffffcff;
|
| 217 | usdelay(10);
|
| 218 |
|
| 219 | //open usb0 and usb1
|
| 220 | //usb ahb clock enable
|
| 221 | REG32(SOC_MOD_CLKEN0)&=0xeffffffb;
|
| 222 | usdelay(20);
|
| 223 | REG32(SOC_MOD_CLKEN0)|=0x10000004;
|
| 224 | //usb phy clock enable
|
| 225 | REG32(SOC_MOD_CLKEN1)&=~(3<<16);
|
| 226 | usdelay(20);
|
| 227 | REG32(SOC_MOD_CLKEN1)|=(3<<16);
|
| 228 |
|
| 229 |
|
| 230 | // usb ctr reset
|
| 231 | REG32(SOC_MOD_RSTEN)&=0xeffffff7;
|
| 232 | usdelay(20);
|
| 233 | REG32(SOC_MOD_RSTEN)|=0x10000008;
|
| 234 |
|
| 235 | // usb ahb reset
|
| 236 | REG32(SOC_MOD_RSTEN)&=0xf7fffffb;
|
| 237 | usdelay(20);
|
| 238 | REG32(SOC_MOD_RSTEN)|=0x8000004;
|
| 239 | #endif
|
| 240 | /*
|
| 241 | usb ctr and ahb reset release ,delay 60us, check usb reset state,
|
| 242 | if the reset state is 0, reset ,if 1,reset release.
|
| 243 | */
|
| 244 | #endif
|
| 245 | }
|
| 246 |
|
| 247 |
|
| 248 |
|