summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/usb-drv-as3525v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/usb-drv-as3525v2.c')
-rw-r--r--firmware/target/arm/as3525/usb-drv-as3525v2.c72
1 files changed, 28 insertions, 44 deletions
diff --git a/firmware/target/arm/as3525/usb-drv-as3525v2.c b/firmware/target/arm/as3525/usb-drv-as3525v2.c
index 951e0b0687..d420c113b7 100644
--- a/firmware/target/arm/as3525/usb-drv-as3525v2.c
+++ b/firmware/target/arm/as3525/usb-drv-as3525v2.c
@@ -144,8 +144,8 @@ static void flush_tx_fifos(int nums)
144{ 144{
145 unsigned int i = 0; 145 unsigned int i = 0;
146 146
147 GRSTCTL = (GRSTCTL & (~GRSTCTL_txfnum_bits)) 147 GRSTCTL = (GRSTCTL & ~bitm(GRSTCTL, txfnum))
148 | (nums << GRSTCTL_txfnum_bit_pos) 148 | (nums << GRSTCTL_txfnum_bitp)
149 | GRSTCTL_txfflsh_flush; 149 | GRSTCTL_txfflsh_flush;
150 while(GRSTCTL & GRSTCTL_txfflsh_flush && i < 0x300) 150 while(GRSTCTL & GRSTCTL_txfflsh_flush && i < 0x300)
151 i++; 151 i++;
@@ -209,8 +209,8 @@ static void reset_endpoints(void)
209 * Setup EP0 IN/OUT with 64 byte maximum packet size and activate both. Enable transfer on EP0 OUT 209 * Setup EP0 IN/OUT with 64 byte maximum packet size and activate both. Enable transfer on EP0 OUT
210 */ 210 */
211 211
212 DOEPTSIZ(0) = (1 << DEPTSIZ0_supcnt_bit_pos) 212 DOEPTSIZ(0) = (1 << DEPTSIZ0_supcnt_bitp)
213 | (1 << DEPTSIZ0_pkcnt_bit_pos) 213 | (1 << DEPTSIZ0_pkcnt_bitp)
214 | 8; 214 | 8;
215 215
216 /* setup DMA */ 216 /* setup DMA */
@@ -219,10 +219,10 @@ static void reset_endpoints(void)
219 219
220 /* Enable endpoint, clear nak */ 220 /* Enable endpoint, clear nak */
221 DOEPCTL(0) = DEPCTL_epena | DEPCTL_cnak | DEPCTL_usbactep 221 DOEPCTL(0) = DEPCTL_epena | DEPCTL_cnak | DEPCTL_usbactep
222 | (DEPCTL_MPS_8 << DEPCTL_mps_bit_pos); 222 | (DEPCTL_MPS_8 << DEPCTL_mps_bitp);
223 223
224 /* 64 bytes packet size, active endpoint */ 224 /* 64 bytes packet size, active endpoint */
225 DIEPCTL(0) = (DEPCTL_MPS_8 << DEPCTL_mps_bit_pos) 225 DIEPCTL(0) = (DEPCTL_MPS_8 << DEPCTL_mps_bitp)
226 | DEPCTL_usbactep; 226 | DEPCTL_usbactep;
227 227
228 DCTL = DCTL_cgnpinnak | DCTL_cgoutnak; 228 DCTL = DCTL_cgnpinnak | DCTL_cgoutnak;
@@ -236,22 +236,22 @@ static void core_dev_init(void)
236 /* Restart the phy clock */ 236 /* Restart the phy clock */
237 PCGCCTL = 0; 237 PCGCCTL = 0;
238 /* Set phy speed : high speed */ 238 /* Set phy speed : high speed */
239 DCFG = (DCFG & ~DCFG_devspd_bits) | DCFG_devspd_hs_phy_hs; 239 DCFG = (DCFG & ~bitm(DCFG, devspd)) | DCFG_devspd_hs_phy_hs;
240 240
241 /* Check hardware capabilities */ 241 /* Check hardware capabilities */
242 if(extract(GHWCFG2, ARCH) != INT_DMA_ARCH) 242 if(extract(GHWCFG2, arch) != GHWCFG2_ARCH_INTERNAL_DMA)
243 panicf("usb: wrong architecture (%ld)", extract(GHWCFG2, ARCH)); 243 panicf("usb: wrong architecture (%ld)", extract(GHWCFG2, arch));
244 if(extract(GHWCFG2, HS_PHY_TYPE) != PHY_TYPE_UTMI) 244 if(extract(GHWCFG2, hs_phy_type) != GHWCFG2_PHY_TYPE_UTMI)
245 panicf("usb: wrong HS phy type (%ld)", extract(GHWCFG2, HS_PHY_TYPE)); 245 panicf("usb: wrong HS phy type (%ld)", extract(GHWCFG2, hs_phy_type));
246 if(extract(GHWCFG2, FS_PHY_TYPE) != PHY_TYPE_UNSUPPORTED) 246 if(extract(GHWCFG2, fs_phy_type) != GHWCFG2_PHY_TYPE_UNSUPPORTED)
247 panicf("usb: wrong FS phy type (%ld)", extract(GHWCFG2, FS_PHY_TYPE)); 247 panicf("usb: wrong FS phy type (%ld)", extract(GHWCFG2, fs_phy_type));
248 if(GHWCFG4_UTMI_PHY_DATA_WIDTH != 0x2) 248 if(extract(GHWCFG4, utmi_phy_data_width) != 0x2)
249 panicf("usb: wrong utmi data width (%ld)", GHWCFG4_UTMI_PHY_DATA_WIDTH); 249 panicf("usb: wrong utmi data width (%ld)", extract(GHWCFG4, utmi_phy_data_width));
250 if(GHWCFG4_DED_FIFO_EN != 1) /* it seems to be multiple tx fifo support */ 250 if(!(GHWCFG4 & GHWCFG4_ded_fifo_en)) /* it seems to be multiple tx fifo support */
251 panicf("usb: no multiple tx fifo"); 251 panicf("usb: no multiple tx fifo");
252 252
253 #ifdef USE_CUSTOM_FIFO_LAYOUT 253 #ifdef USE_CUSTOM_FIFO_LAYOUT
254 if(!(GHWCFG2 & GHWCFG2_DYN_FIFO)) 254 if(!(GHWCFG2 & GHWCFG2_dyn_fifo))
255 panicf("usb: no dynamic fifo"); 255 panicf("usb: no dynamic fifo");
256 if(GRXFSIZ != DATA_FIFO_DEPTH) 256 if(GRXFSIZ != DATA_FIFO_DEPTH)
257 panicf("usb: wrong data fifo size"); 257 panicf("usb: wrong data fifo size");
@@ -263,10 +263,10 @@ static void core_dev_init(void)
263 logf("hwcfg3: %08lx", GHWCFG3); 263 logf("hwcfg3: %08lx", GHWCFG3);
264 logf("hwcfg4: %08lx", GHWCFG4); 264 logf("hwcfg4: %08lx", GHWCFG4);
265 265
266 logf("%ld endpoints", extract(GHWCFG2, NUM_EP)); 266 logf("%ld endpoints", extract(GHWCFG2, num_ep));
267 num_in_ep = 0; 267 num_in_ep = 0;
268 num_out_ep = 0; 268 num_out_ep = 0;
269 for(i = 0; i < extract(GHWCFG2, NUM_EP); i++) 269 for(i = 0; i < extract(GHWCFG2, num_ep); i++)
270 { 270 {
271 if(GHWCFG1 & GHWCFG1_IN_EP(i)) 271 if(GHWCFG1 & GHWCFG1_IN_EP(i))
272 num_in_ep++; 272 num_in_ep++;
@@ -277,8 +277,8 @@ static void core_dev_init(void)
277 GHWCFG1 & GHWCFG1_OUT_EP(i) ? "yes" : "no"); 277 GHWCFG1 & GHWCFG1_OUT_EP(i) ? "yes" : "no");
278 } 278 }
279 279
280 if(num_in_ep != GHWCFG4_NUM_IN_EP) 280 if(num_in_ep != extract(GHWCFG4, num_in_ep))
281 panicf("usb: num in ep mismatch(%d,%lu)", num_in_ep, GHWCFG4_NUM_IN_EP); 281 panicf("usb: num in ep mismatch(%d,%lu)", num_in_ep, extract(GHWCFG4, num_in_ep));
282 if(num_in_ep != NUM_IN_EP) 282 if(num_in_ep != NUM_IN_EP)
283 panicf("usb: num in ep static mismatch(%u,%u)", num_in_ep, NUM_IN_EP); 283 panicf("usb: num in ep static mismatch(%u,%u)", num_in_ep, NUM_IN_EP);
284 if(num_out_ep != NUM_OUT_EP) 284 if(num_out_ep != NUM_OUT_EP)
@@ -287,7 +287,7 @@ static void core_dev_init(void)
287 logf("%d in ep, %d out ep", num_in_ep, num_out_ep); 287 logf("%d in ep, %d out ep", num_in_ep, num_out_ep);
288 288
289 logf("initial:"); 289 logf("initial:");
290 logf(" tot fifo sz: %lx", GHWCFG3_DFIFO_LEN); 290 logf(" tot fifo sz: %lx", extract(GHWCFG3, dfifo_len));
291 logf(" rx fifo: [%04x,+%4lx]", 0, GRXFSIZ); 291 logf(" rx fifo: [%04x,+%4lx]", 0, GRXFSIZ);
292 logf(" nptx fifo: [%04lx,+%4lx]", GET_FIFOSIZE_START_ADR(GNPTXFSIZ), 292 logf(" nptx fifo: [%04lx,+%4lx]", GET_FIFOSIZE_START_ADR(GNPTXFSIZ),
293 GET_FIFOSIZE_DEPTH(GNPTXFSIZ)); 293 GET_FIFOSIZE_DEPTH(GNPTXFSIZ));
@@ -344,9 +344,9 @@ static void core_dev_init(void)
344 logf("threshold control:"); 344 logf("threshold control:");
345 logf(" non_iso_thr_en: %d", (DTHRCTL & DTHRCTL_non_iso_thr_en) ? 1 : 0); 345 logf(" non_iso_thr_en: %d", (DTHRCTL & DTHRCTL_non_iso_thr_en) ? 1 : 0);
346 logf(" iso_thr_en: %d", (DTHRCTL & DTHRCTL_iso_thr_en) ? 1 : 0); 346 logf(" iso_thr_en: %d", (DTHRCTL & DTHRCTL_iso_thr_en) ? 1 : 0);
347 logf(" tx_thr_len: %lu", (DTHRCTL & DTHRCTL_tx_thr_len_bits) >> DTHRCTL_tx_thr_len_bit_pos); 347 logf(" tx_thr_len: %lu", extract(DTHRCTL, tx_thr_len));
348 logf(" rx_thr_en: %d", (DTHRCTL & DTHRCTL_rx_thr_en) ? 1 : 0); 348 logf(" rx_thr_en: %d", (DTHRCTL & DTHRCTL_rx_thr_en) ? 1 : 0);
349 logf(" rx_thr_len: %lu", (DTHRCTL & DTHRCTL_rx_thr_len_bits) >> DTHRCTL_rx_thr_len_bit_pos); 349 logf(" rx_thr_len: %lu", extract(DTHRCTL, rx_thr_len));
350 */ 350 */
351 351
352 DTHRCTL = 0; 352 DTHRCTL = 0;
@@ -365,7 +365,7 @@ static void core_init(void)
365 /* fixme: the current code is for internal DMA only, the clip+ architecture 365 /* fixme: the current code is for internal DMA only, the clip+ architecture
366 * define the internal DMA model */ 366 * define the internal DMA model */
367 /* Set burstlen and enable DMA*/ 367 /* Set burstlen and enable DMA*/
368 GAHBCFG = (GAHBCFG_INT_DMA_BURST_INCR4 << GAHBCFG_hburstlen_bit_pos) 368 GAHBCFG = (GAHBCFG_INT_DMA_BURST_INCR4 << GAHBCFG_hburstlen_bitp)
369 | GAHBCFG_dma_enable; 369 | GAHBCFG_dma_enable;
370 /* Disable HNP and SRP, not sure it's useful because we already forced dev mode */ 370 /* Disable HNP and SRP, not sure it's useful because we already forced dev mode */
371 GUSBCFG &= ~(GUSBCFG_srpcap | GUSBCFG_hnpcapp); 371 GUSBCFG &= ~(GUSBCFG_srpcap | GUSBCFG_hnpcapp);
@@ -422,7 +422,7 @@ static bool handle_reset(void)
422 reset_endpoints(); 422 reset_endpoints();
423 423
424 /* Reset Device Address */ 424 /* Reset Device Address */
425 DCFG &= ~DCFG_devadr_bits; 425 DCFG &= bitm(DCFG, devadr);
426 426
427 usb_core_bus_reset(); 427 usb_core_bus_reset();
428 428
@@ -450,7 +450,7 @@ static bool handle_enum_done(void)
450 logf("DCFG=%lx", DCFG); 450 logf("DCFG=%lx", DCFG);
451 logf("DTHRCTL=%lx", DTHRCTL); 451 logf("DTHRCTL=%lx", DTHRCTL);
452 452
453 switch((DSTS & DSTS_enumspd_bits) >> DSTS_enumspd_bit_pos) 453 switch(extract(DSTS, enumspd))
454 { 454 {
455 case DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ: 455 case DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
456 logf("usb: HS"); 456 logf("usb: HS");
@@ -463,23 +463,7 @@ static bool handle_enum_done(void)
463 panicf("usb: LS is not supported"); 463 panicf("usb: LS is not supported");
464 } 464 }
465 465
466 DOEPCTL(0) = (DOEPCTL(0) & ~DEPCTL_mps_bits) 466 /* fixme: change EP0 mps here */
467 | (DEPCTL_MPS_64 << DEPCTL_mps_bit_pos);
468 DIEPCTL(0) = (DIEPCTL(0) & ~DEPCTL_mps_bits)
469 | (DEPCTL_MPS_64 << DEPCTL_mps_bit_pos);
470
471 unsigned i, ep;
472 FOR_EACH_IN_EP(i, ep)
473 DIEPCTL(ep) = (DIEPCTL(ep) & ~DEPCTL_mps_bits)
474 | (512 << DEPCTL_mps_bit_pos);
475
476 FOR_EACH_OUT_EP(i, ep)
477 DOEPCTL(ep) = (DOEPCTL(ep) & ~DEPCTL_mps_bits)
478 | (512 << DEPCTL_mps_bit_pos);
479
480 DOEPTSIZ(0) = (1 << DEPTSIZ0_supcnt_bit_pos)
481 | (1 << DEPTSIZ0_pkcnt_bit_pos)
482 | 64;
483 467
484 return true; 468 return true;
485} 469}