summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/as3525/usb-drv-as3525v2.c72
-rw-r--r--firmware/target/arm/as3525/usb-drv-as3525v2.h292
2 files changed, 190 insertions, 174 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}
diff --git a/firmware/target/arm/as3525/usb-drv-as3525v2.h b/firmware/target/arm/as3525/usb-drv-as3525v2.h
index 96b13f2028..0f5714eadd 100644
--- a/firmware/target/arm/as3525/usb-drv-as3525v2.h
+++ b/firmware/target/arm/as3525/usb-drv-as3525v2.h
@@ -24,15 +24,26 @@
24#include "as3525v2.h" 24#include "as3525v2.h"
25 25
26/* All multi-bit fields in the driver use the following convention. 26/* All multi-bit fields in the driver use the following convention.
27 * If the register name is NAME, then there is one define NAME_bit_pos 27 * If the register name is NAME, then there is one define NAME_bitp
28 * which holds the bit position and one define NAME_bits which holds 28 * which holds the bit position and one define NAME_bits which holds
29 * a mask of the bits within the register. 29 * a mask of the bits within the register (after shift).
30 * These macros allow easy access and construction of such fields */ 30 * These macros allow easy access and construction of such fields */
31/* Usage: 31/* Usage:
32 * - extract(reg_name,field_name) 32 * - extract(reg_name,field_name)
33 note: the field_name must not be prefix with the reg name */ 33 * extract a field of the register
34 * - bitm(reg_name,field_name)
35 * build a bitmask for the field
36 * - make(reg_name,field_name,value)
37 * build the value of the field (doesn't mask)
38 */
34#define extract(reg_name, field_name) \ 39#define extract(reg_name, field_name) \
35 ((reg_name & reg_name##_##field_name##_bits) >> reg_name##_##field_name##_bit_pos) 40 ((reg_name >> reg_name##_##field_name##_bitp) & reg_name##_##field_name##_bits)
41
42#define bitm(reg_name, field_name) \
43 (reg_name##_##field_name##_bits << reg_name##_##field_name##_bitp)
44
45#define make(reg_name, field_name, value) \
46 ((value) << reg_name##_##field_name##_bitp)
36 47
37#define USB_DEVICE (USB_BASE + 0x0800) /** USB Device base address */ 48#define USB_DEVICE (USB_BASE + 0x0800) /** USB Device base address */
38 49
@@ -50,7 +61,7 @@
50/** Core AHB Configuration Register */ 61/** Core AHB Configuration Register */
51#define GAHBCFG BASE_REG(0x008) 62#define GAHBCFG BASE_REG(0x008)
52#define GAHBCFG_glblintrmsk (1 << 0) /** Global interrupt mask */ 63#define GAHBCFG_glblintrmsk (1 << 0) /** Global interrupt mask */
53#define GAHBCFG_hburstlen_bit_pos 1 64#define GAHBCFG_hburstlen_bitp 1
54#define GAHBCFG_INT_DMA_BURST_SINGLE 0 65#define GAHBCFG_INT_DMA_BURST_SINGLE 0
55#define GAHBCFG_INT_DMA_BURST_INCR 1 /** note: the linux patch has several other value, this is one picked for internal dma */ 66#define GAHBCFG_INT_DMA_BURST_INCR 1 /** note: the linux patch has several other value, this is one picked for internal dma */
56#define GAHBCFG_INT_DMA_BURST_INCR4 3 67#define GAHBCFG_INT_DMA_BURST_INCR4 3
@@ -60,8 +71,8 @@
60 71
61/** Core USB Configuration Register */ 72/** Core USB Configuration Register */
62#define GUSBCFG BASE_REG(0x00C) 73#define GUSBCFG BASE_REG(0x00C)
63#define GUSBCFG_toutcal_bit_pos 0 74#define GUSBCFG_toutcal_bitp 0
64#define GUSBCFG_toutcal_bits (0x7 << GUSBCFG_toutcal_bit_pos) 75#define GUSBCFG_toutcal_bits 0x7
65#define GUSBCFG_phy_if (1 << 3) /** select utmi bus width ? */ 76#define GUSBCFG_phy_if (1 << 3) /** select utmi bus width ? */
66#define GUSBCFG_ulpi_utmi_sel (1 << 4) /** select ulpi:1 or utmi:0 */ 77#define GUSBCFG_ulpi_utmi_sel (1 << 4) /** select ulpi:1 or utmi:0 */
67#define GUSBCFG_fsintf (1 << 5) 78#define GUSBCFG_fsintf (1 << 5)
@@ -69,8 +80,8 @@
69#define GUSBCFG_ddrsel (1 << 7) 80#define GUSBCFG_ddrsel (1 << 7)
70#define GUSBCFG_srpcap (1 << 8) 81#define GUSBCFG_srpcap (1 << 8)
71#define GUSBCFG_hnpcapp (1 << 9) 82#define GUSBCFG_hnpcapp (1 << 9)
72#define GUSBCFG_usbtrdtim_bit_pos 10 83#define GUSBCFG_usbtrdtim_bitp 10
73#define GUSBCFG_usbtrdtim_bits (0xf << GUSBCFG_usbtrdtim_bit_pos) 84#define GUSBCFG_usbtrdtim_bits 0xf
74#define GUSBCFG_nptxfrwnden (1 << 14) 85#define GUSBCFG_nptxfrwnden (1 << 14)
75#define GUSBCFG_phylpwrclksel (1 << 15) 86#define GUSBCFG_phylpwrclksel (1 << 15)
76#define GUSBCFG_otgutmifssel (1 << 16) 87#define GUSBCFG_otgutmifssel (1 << 16)
@@ -91,8 +102,8 @@
91#define GRSTCTL_intknqflsh (1 << 3) /** In Token Sequence Learning Queue Flush */ 102#define GRSTCTL_intknqflsh (1 << 3) /** In Token Sequence Learning Queue Flush */
92#define GRSTCTL_rxfflsh_flush (1 << 4) /** RxFIFO Flush */ 103#define GRSTCTL_rxfflsh_flush (1 << 4) /** RxFIFO Flush */
93#define GRSTCTL_txfflsh_flush (1 << 5) /** TxFIFO Flush */ 104#define GRSTCTL_txfflsh_flush (1 << 5) /** TxFIFO Flush */
94#define GRSTCTL_txfnum_bit_pos 6 /** TxFIFO Number */ 105#define GRSTCTL_txfnum_bitp 6 /** TxFIFO Number */
95#define GRSTCTL_txfnum_bits (0x1f << 6) 106#define GRSTCTL_txfnum_bits 0x1f
96#define GRSTCTL_ahbidle (1 << 31) /** AHB idle state*/ 107#define GRSTCTL_ahbidle (1 << 31) /** AHB idle state*/
97 108
98/** Core Interrupt Register */ 109/** Core Interrupt Register */
@@ -166,25 +177,32 @@
166 177
167/** User HW Config2 Register */ 178/** User HW Config2 Register */
168#define GHWCFG2 BASE_REG(0x048) 179#define GHWCFG2 BASE_REG(0x048)
169#define GHWCFG2_ARCH_bit_pos 3 /** Architecture */ 180#define GHWCFG2_arch_bitp 3 /** Architecture */
170#define GHWCFG2_ARCH_bits (0x3 << GHWCFG2_ARCH_bit_pos) 181#define GHWCFG2_arch_bits 0x3
171#define GHWCFG2_HS_PHY_TYPE_bit_pos 6 /** High speed PHY type */ 182#define GHWCFG2_hs_phy_type_bitp 6 /** High speed PHY type */
172#define GHWCFG2_HS_PHY_TYPE_bits (0x3 << GHWCFG2_HS_PHY_TYPE_bit_pos) 183#define GHWCFG2_hs_phy_type_bits 0x3
173#define GHWCFG2_FS_PHY_TYPE_bit_pos 8 /** Full speed PHY type */ 184#define GHWCFG2_fs_phy_type_bitp 8 /** Full speed PHY type */
174#define GHWCFG2_FS_PHY_TYPE_bits (0x3 << GHWCFG2_FS_PHY_TYPE_bit_pos) 185#define GHWCFG2_fs_phy_type_bits 0x3
175#define GHWCFG2_NUM_EP_bit_pos 10 /** Number of endpoints */ 186#define GHWCFG2_num_ep_bitp 10 /** Number of endpoints */
176#define GHWCFG2_NUM_EP_bits (0xf << GHWCFG2_NUM_EP_bit_pos) 187#define GHWCFG2_num_ep_bits 0xf
177#define GHWCFG2_DYN_FIFO (1 << 19) /** Dynamic FIFO */ 188#define GHWCFG2_dyn_fifo (1 << 19) /** Dynamic FIFO */
178/* For GHWCFG2_HS_PHY_TYPE and GHWCFG2_SS_PHY_TYPE */ 189/* For GHWCFG2_HS_PHY_TYPE and GHWCFG2_FS_PHY_TYPE */
179#define PHY_TYPE_UNSUPPORTED 0 190#define GHWCFG2_PHY_TYPE_UNSUPPORTED 0
180#define PHY_TYPE_UTMI 1 191#define GHWCFG2_PHY_TYPE_UTMI 1
181#define INT_DMA_ARCH 2 192#define GHWCFG2_ARCH_INTERNAL_DMA 2
182 193
183/** User HW Config3 Register */ 194/** User HW Config3 Register */
184#define GHWCFG3 BASE_REG(0x04C) 195#define GHWCFG3 BASE_REG(0x04C)
196#define GHWCFG3_dfifo_len_bitp 16 /** Total fifo size */
197#define GHWCFG3_dfifo_len_bits 0xffff
185 198
186/** User HW Config4 Register */ 199/** User HW Config4 Register */
187#define GHWCFG4 BASE_REG(0x050) 200#define GHWCFG4 BASE_REG(0x050)
201#define GHWCFG4_utmi_phy_data_width_bitp 14 /** UTMI+ data bus width */
202#define GHWCFG4_utmi_phy_data_width_bits 0x3
203#define GHWCFG4_ded_fifo_en (1 << 25) /** Dedicated Tx FIFOs */
204#define GHWCFG4_num_in_ep_bitp 26 /** Number of IN endpoints */
205#define GHWCFG4_num_in_ep_bits 0xf
188 206
189/* 1<=ep<=15, don't use ep=0 !!! */ 207/* 1<=ep<=15, don't use ep=0 !!! */
190/** Device IN Endpoint Transmit FIFO (ep) Size Register */ 208/** Device IN Endpoint Transmit FIFO (ep) Size Register */
@@ -200,100 +218,58 @@
200#define GET_FIFOSIZE_START_ADR(data) \ 218#define GET_FIFOSIZE_START_ADR(data) \
201 ((data) & 0xffff) 219 ((data) & 0xffff)
202 220
203
204
205
206
207#define GHWCFG3_DFIFO_LEN (GHWCFG3 >> 16) /** Total fifo size */
208
209#define GHWCFG4_UTMI_PHY_DATA_WIDTH ((GHWCFG4 >> 14) & 0x3) /** UTMI+ data bus width (format is unsure) */
210#define GHWCFG4_DED_FIFO_EN ((GHWCFG4 >> 25) & 0x1) /** Dedicated Tx FIFOs */
211#define GHWCFG4_NUM_IN_EP ((GHWCFG4 >> 26) & 0xf) /** Number of IN endpoints */
212
213
214
215/** 221/**
216 * Device Registers Base Addresses 222 * Device Registers Base Addresses
217 */ 223 */
218#define DEV_REG(offset) (*(volatile unsigned long *)(USB_DEVICE + offset)) 224#define DEV_REG(offset) (*(volatile unsigned long *)(USB_DEVICE + offset))
219 225
220#define DCFG DEV_REG(0x00) /** Device Configuration Register */ 226/** Device Configuration Register */
221#define DCTL DEV_REG(0x04) /** Device Control Register */ 227#define DCFG DEV_REG(0x00)
222#define DSTS DEV_REG(0x08) /** Device Status Register */ 228#define DCFG_devspd_bitp 0 /** Device Speed */
223#define DIEPMSK DEV_REG(0x10) /** Device IN Endpoint Common Interrupt Mask Register */ 229#define DCFG_devspd_bits 0x3
224#define DOEPMSK DEV_REG(0x14) /** Device OUT Endpoint Common Interrupt Mask Register */ 230#define DCFG_devspd_hs_phy_hs 0 /** High speed PHY running at high speed */
225#define DAINT DEV_REG(0x18) /** Device All Endpoints Interrupt Register */ 231#define DCFG_devspd_hs_phy_fs 1 /** High speed PHY running at full speed */
226#define DAINTMSK DEV_REG(0x1C) /** Device Endpoints Interrupt Mask Register */ 232#define DCFG_nzstsouthshk (1 << 2) /** Non Zero Length Status OUT Handshake */
227#define DTKNQR1 DEV_REG(0x20) /** Device IN Token Sequence Learning Queue Read Register 1 */ 233#define DCFG_devadr_bitp 4 /** Device Address */
228#define DTKNQR2 DEV_REG(0x24) /** Device IN Token Sequence Learning Queue Register 2 */ 234#define DCFG_devadr_bits 0x7f
229#define DTKNQP DEV_REG(0x28) /** Device IN Token Queue Pop register */ 235#define DCFG_perfrint_bitp 11 /** Periodic Frame Interval */
230/* fixme: those registers are not present in registers.h but are in dwc_otgh_regs.h. 236#define DCFG_perfrint_bits 0x3
231 * the previous registers exists but has a different name :( */ 237#define DCFG_FRAME_INTERVAL_80 0
232#define DVBUSDIS DEV_REG(0x28) /** Device VBUS discharge register*/ 238#define DCFG_FRAME_INTERVAL_85 1
233#define DVBUSPULSE DEV_REG(0x2C) /** Device VBUS pulse register */ 239#define DCFG_FRAME_INTERVAL_90 2
234#define DTKNQR3 DEV_REG(0x30) /** Device IN Token Queue Read Register 3 (RO) */ 240#define DCFG_FRAME_INTERVAL_95 3
235#define DTHRCTL DEV_REG(0x30) /** Device Thresholding control register */ 241
236#define DTKNQR4 DEV_REG(0x34) /** Device IN Token Queue Read Register 4 (RO) */ 242/** Device Control Register */
237#define FFEMPTYMSK DEV_REG(0x34) /** Device IN EPs empty Inr. Mask Register */ 243#define DCTL DEV_REG(0x04)
238 244#define DCTL_rmtwkupsig (1 << 0) /** Remote Wakeup */
239#define DCTL_rmtwkupsig (1 << 0) /** Remote Wakeup */ 245#define DCTL_sftdiscon (1 << 1) /** Soft Disconnect */
240#define DCTL_sftdiscon (1 << 1) /** Soft Disconnect */ 246#define DCTL_gnpinnaksts (1 << 2) /** Global Non-Periodic IN NAK Status */
241#define DCTL_gnpinnaksts (1 << 2) /** Global Non-Periodic IN NAK Status */ 247#define DCTL_goutnaksts (1 << 3) /** Global OUT NAK Status */
242#define DCTL_goutnaksts (1 << 3) /** Global OUT NAK Status */ 248#define DCTL_tstctl_bitp 4 /** Test Control */
243#define DCTL_tstctl_bit_pos 4 /** Test Control */ 249#define DCTL_tstctl_bits 0x7
244#define DCTL_tstctl_bits (0x7 << DCTL_tstctl_bit_pos) 250#define DCTL_sgnpinnak (1 << 7) /** Set Global Non-Periodic IN NAK */
245#define DCTL_sgnpinnak (1 << 7) /** Set Global Non-Periodic IN NAK */ 251#define DCTL_cgnpinnak (1 << 8) /** Clear Global Non-Periodic IN NAK */
246#define DCTL_cgnpinnak (1 << 8) /** Clear Global Non-Periodic IN NAK */ 252#define DCTL_sgoutnak (1 << 9) /** Set Global OUT NAK */
247#define DCTL_sgoutnak (1 << 9) /** Set Global OUT NAK */ 253#define DCTL_cgoutnak (1 << 10) /** Clear Global OUT NAK */
248#define DCTL_cgoutnak (1 << 10) /** Clear Global OUT NAK */
249/* "documented" in constants.h only */ 254/* "documented" in constants.h only */
250#define DCTL_pwronprgdone (1 << 11) /** Power on Program Done ? */ 255#define DCTL_pwronprgdone (1 << 11) /** Power on Program Done ? */
251 256
252#define DCFG_devspd_bits 0x3 /** Device Speed */ 257/** Device Status Register */
253#define DCFG_devspd_hs_phy_hs 0 /** High speed PHY running at high speed */ 258#define DSTS DEV_REG(0x08)
254#define DCFG_devspd_hs_phy_fs 1 /** High speed PHY running at full speed */ 259#define DSTS_suspsts (1 << 0) /** Suspend status */
255#define DCFG_nzstsouthshk (1 << 2) /** Non Zero Length Status OUT Handshake */ 260#define DSTS_enumspd_bitp 1 /** Enumerated speed */
256#define DCFG_devadr_bit_pos 4 /** Device Address */ 261#define DSTS_enumspd_bits 0x3
257#define DCFG_devadr_bits (0x7f << DCFG_devadr_bit_pos)
258#define DCFG_perfrint_bit_pos 11 /** Periodic Frame Interval */
259#define DCFG_perfrint_bits (0x3 << DCFG_perfrint_bit_pos)
260#define DCFG_FRAME_INTERVAL_80 0
261#define DCFG_FRAME_INTERVAL_85 1
262#define DCFG_FRAME_INTERVAL_90 2
263#define DCFG_FRAME_INTERVAL_95 3
264
265#define DSTS_suspsts (1 << 0) /** Suspend status */
266#define DSTS_enumspd_bit_pos 1 /** Enumerated speed */
267#define DSTS_enumspd_bits (0x3 << DSTS_enumspd_bit_pos)
268#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0 262#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
269#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1 263#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
270#define DSTS_ENUMSPD_LS_PHY_6MHZ 2 264#define DSTS_ENUMSPD_LS_PHY_6MHZ 2
271#define DSTS_ENUMSPD_FS_PHY_48MHZ 3 265#define DSTS_ENUMSPD_FS_PHY_48MHZ 3
272#define DSTS_errticerr (1 << 3) /** Erratic errors ? */ 266#define DSTS_errticerr (1 << 3) /** Erratic errors ? */
273#define DSTS_soffn_bit_pos 7 /** Frame or Microframe Number of the received SOF */ 267#define DSTS_soffn_bitp 7 /** Frame or Microframe Number of the received SOF */
274#define DSTS_soffn_bits (0x3fff << DSTS_soffn_bit_pos) 268#define DSTS_soffn_bits 0x3fff
275
276#define DTHRCTL_non_iso_thr_en (1 << 0)
277#define DTHRCTL_iso_thr_en (1 << 1)
278#define DTHRCTL_tx_thr_len_bit_pos 2
279#define DTHRCTL_tx_thr_len_bits (0x1FF << DTHRCTL_tx_thr_len_bit_pos)
280#define DTHRCTL_rx_thr_en (1 << 16)
281#define DTHRCTL_rx_thr_len_bit_pos 17
282#define DTHRCTL_rx_thr_len_bits (0x1FF << DTHRCTL_rx_thr_len_bit_pos)
283
284/* 0<=ep<=15, you can use ep=0 */
285/** Device IN Endpoint (ep) Control Register */
286#define DIEPCTL(ep) DEV_REG(0x100 + (ep) * 0x20)
287/** Device IN Endpoint (ep) Interrupt Register */
288#define DIEPINT(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x8)
289/** Device IN Endpoint (ep) Transfer Size Register */
290#define DIEPTSIZ(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x10)
291/** Device IN Endpoint (ep) DMA Address Register */
292#define DIEPDMA(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x14)
293/** Device IN Endpoint (ep) Transmit FIFO Status Register */
294#define DTXFSTS(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x18)
295 269
296/* the following also apply to DIEPMSK */ 270/** Device IN Endpoint Common Interrupt Mask Register */
271#define DIEPMSK DEV_REG(0x10)
272/* the following apply to DIEPMSK and DIEPINT */
297#define DIEPINT_xfercompl (1 << 0) /** Transfer complete */ 273#define DIEPINT_xfercompl (1 << 0) /** Transfer complete */
298#define DIEPINT_epdisabled (1 << 1) /** Endpoint disabled */ 274#define DIEPINT_epdisabled (1 << 1) /** Endpoint disabled */
299#define DIEPINT_ahberr (1 << 2) /** AHB error */ 275#define DIEPINT_ahberr (1 << 2) /** AHB error */
@@ -304,12 +280,72 @@
304#define DIEPINT_emptyintr (1 << 7) /** linux doc broken on this, empty fifo ? */ 280#define DIEPINT_emptyintr (1 << 7) /** linux doc broken on this, empty fifo ? */
305#define DIEPINT_txfifoundrn (1 << 8) /** linux doc void on this, tx fifo underrun ? */ 281#define DIEPINT_txfifoundrn (1 << 8) /** linux doc void on this, tx fifo underrun ? */
306 282
307/* the following also apply to DOEPMSK */ 283/** Device OUT Endpoint Common Interrupt Mask Register */
284#define DOEPMSK DEV_REG(0x14)
285/* the following apply to DOEPMSK and DOEPINT */
308#define DOEPINT_xfercompl (1 << 0) /** Transfer complete */ 286#define DOEPINT_xfercompl (1 << 0) /** Transfer complete */
309#define DOEPINT_epdisabled (1 << 1) /** Endpoint disabled */ 287#define DOEPINT_epdisabled (1 << 1) /** Endpoint disabled */
310#define DOEPINT_ahberr (1 << 2) /** AHB error */ 288#define DOEPINT_ahberr (1 << 2) /** AHB error */
311#define DOEPINT_setup (1 << 3) /** Setup Phase Done (control EPs)*/ 289#define DOEPINT_setup (1 << 3) /** Setup Phase Done (control EPs)*/
312 290
291/** Device All Endpoints Interrupt Register */
292#define DAINT DEV_REG(0x18)
293/* valid for DAINT and DAINTMSK, for 0<=ep<=15 */
294#define DAINT_IN_EP(i) (1 << (i))
295#define DAINT_OUT_EP(i) (1 << ((i) + 16))
296
297/** Device Endpoints Interrupt Mask Register */
298#define DAINTMSK DEV_REG(0x1C)
299
300/** Device IN Token Sequence Learning Queue Read Register 1 */
301#define DTKNQR1 DEV_REG(0x20)
302
303/** Device IN Token Sequence Learning Queue Register 2 */
304#define DTKNQR2 DEV_REG(0x24)
305
306/** Device IN Token Queue Pop register */
307#define DTKNQP DEV_REG(0x28)
308
309/* fixme: those registers are not present in registers.h but are in dwc_otgh_regs.h.
310 * the previous registers exists but has a different name :( */
311/** Device VBUS discharge register*/
312#define DVBUSDIS DEV_REG(0x28)
313
314/** Device VBUS pulse register */
315#define DVBUSPULSE DEV_REG(0x2C)
316
317/** Device IN Token Queue Read Register 3 (RO) */
318#define DTKNQR3 DEV_REG(0x30)
319
320/** Device Thresholding control register */
321#define DTHRCTL DEV_REG(0x30)
322#define DTHRCTL_non_iso_thr_en (1 << 0)
323#define DTHRCTL_iso_thr_en (1 << 1)
324#define DTHRCTL_tx_thr_len_bitp 2
325#define DTHRCTL_tx_thr_len_bits 0x1FF
326#define DTHRCTL_rx_thr_en (1 << 16)
327#define DTHRCTL_rx_thr_len_bitp 17
328#define DTHRCTL_rx_thr_len_bits 0x1FF
329
330/** Device IN Token Queue Read Register 4 (RO) */
331#define DTKNQR4 DEV_REG(0x34)
332
333/** Device IN EPs empty Inr. Mask Register */
334#define FFEMPTYMSK DEV_REG(0x34)
335
336
337/* 0<=ep<=15, you can use ep=0 */
338/** Device IN Endpoint (ep) Control Register */
339#define DIEPCTL(ep) DEV_REG(0x100 + (ep) * 0x20)
340/** Device IN Endpoint (ep) Interrupt Register */
341#define DIEPINT(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x8)
342/** Device IN Endpoint (ep) Transfer Size Register */
343#define DIEPTSIZ(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x10)
344/** Device IN Endpoint (ep) DMA Address Register */
345#define DIEPDMA(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x14)
346/** Device IN Endpoint (ep) Transmit FIFO Status Register */
347#define DTXFSTS(ep) DEV_REG(0x100 + (ep) * 0x20 + 0x18)
348
313/* 0<=ep<=15, you can use ep=0 */ 349/* 0<=ep<=15, you can use ep=0 */
314/** Device OUT Endpoint (ep) Control Register */ 350/** Device OUT Endpoint (ep) Control Register */
315#define DOEPCTL(ep) DEV_REG(0x300 + (ep) * 0x20) 351#define DOEPCTL(ep) DEV_REG(0x300 + (ep) * 0x20)
@@ -332,8 +368,8 @@
332 * 2'b01: 32 368 * 2'b01: 32
333 * 2'b10: 16 369 * 2'b10: 16
334 * 2'b11: 8 */ 370 * 2'b11: 8 */
371#define DEPCTL_mps_bitp 0
335#define DEPCTL_mps_bits 0x7ff 372#define DEPCTL_mps_bits 0x7ff
336#define DEPCTL_mps_bit_pos 0
337#define DEPCTL_MPS_64 0 373#define DEPCTL_MPS_64 0
338#define DEPCTL_MPS_32 1 374#define DEPCTL_MPS_32 1
339#define DEPCTL_MPS_16 2 375#define DEPCTL_MPS_16 2
@@ -341,8 +377,8 @@
341/** Next Endpoint 377/** Next Endpoint
342 * IN EPn/IN EP0 378 * IN EPn/IN EP0
343 * OUT EPn/OUT EP0 - reserved */ 379 * OUT EPn/OUT EP0 - reserved */
344#define DEPCTL_nextep_bit_pos 11 380#define DEPCTL_nextep_bitp 11
345#define DEPCTL_nextep_bits (0xf << DEPCTL_nextep_bit_pos) 381#define DEPCTL_nextep_bits 0xf
346#define DEPCTL_usbactep (1 << 15) /** USB Active Endpoint */ 382#define DEPCTL_usbactep (1 << 15) /** USB Active Endpoint */
347/** Endpoint DPID (INTR/Bulk IN and OUT endpoints) 383/** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
348 * This field contains the PID of the packet going to 384 * This field contains the PID of the packet going to
@@ -365,8 +401,8 @@
365 * 2'b01: Isochronous 401 * 2'b01: Isochronous
366 * 2'b10: Bulk 402 * 2'b10: Bulk
367 * 2'b11: Interrupt */ 403 * 2'b11: Interrupt */
368#define DEPCTL_eptype_bit_pos 18 404#define DEPCTL_eptype_bitp 18
369#define DEPCTL_eptype_bits (0x3 << DEPCTL_eptype_bit_pos) 405#define DEPCTL_eptype_bits 0x3
370/** Snoop Mode 406/** Snoop Mode
371 * OUT EPn/OUT EP0 407 * OUT EPn/OUT EP0
372 * IN EPn/IN EP0 - reserved */ 408 * IN EPn/IN EP0 - reserved */
@@ -375,8 +411,8 @@
375/** Tx Fifo Number 411/** Tx Fifo Number
376 * IN EPn/IN EP0 412 * IN EPn/IN EP0
377 * OUT EPn/OUT EP0 - reserved */ 413 * OUT EPn/OUT EP0 - reserved */
378#define DEPCTL_txfnum_bit_pos 22 414#define DEPCTL_txfnum_bitp 22
379#define DEPCTL_txfnum_bits (0xf << DEPCTL_txfnum_bit_pos) 415#define DEPCTL_txfnum_bits 0xf
380 416
381#define DEPCTL_cnak (1 << 26) /** Clear NAK */ 417#define DEPCTL_cnak (1 << 26) /** Clear NAK */
382#define DEPCTL_snak (1 << 27) /** Set NAK */ 418#define DEPCTL_snak (1 << 27) /** Set NAK */
@@ -403,21 +439,17 @@
403 439
404/* valid for any D{I,O}EPTSIZi with 1<=i<=15, NOT for i=0 ! */ 440/* valid for any D{I,O}EPTSIZi with 1<=i<=15, NOT for i=0 ! */
405#define DEPTSIZ_xfersize_bits 0x7ffff /** Transfer Size */ 441#define DEPTSIZ_xfersize_bits 0x7ffff /** Transfer Size */
406#define DEPTSIZ_pkcnt_bit_pos 19 /** Packet Count */ 442#define DEPTSIZ_pkcnt_bitp 19 /** Packet Count */
407#define DEPTSIZ_pkcnt_bits (0x3ff << DEPTSIZ_pkcnt_bit_pos) 443#define DEPTSIZ_pkcnt_bits 0x3ff
408#define DEPTSIZ_mc_bit_pos 29 /** Multi Count - Periodic IN endpoints */ 444#define DEPTSIZ_mc_bitp 29 /** Multi Count - Periodic IN endpoints */
409#define DEPTSIZ_mc_bits (0x3 << DEPTSIZ_mc_bit_pos) 445#define DEPTSIZ_mc_bits 0x3
410 446
411/* idem but for i=0 */ 447/* idem but for i=0 */
412#define DEPTSIZ0_xfersize_bits 0x7f /** Transfer Size */ 448#define DEPTSIZ0_xfersize_bits 0x7f /** Transfer Size */
413#define DEPTSIZ0_pkcnt_bit_pos 19 /** Packet Count */ 449#define DEPTSIZ0_pkcnt_bitp 19 /** Packet Count */
414#define DEPTSIZ0_pkcnt_bits (0x1 << DEPTSIZ0_pkcnt_bit_pos) 450#define DEPTSIZ0_pkcnt_bits 0x1
415#define DEPTSIZ0_supcnt_bit_pos 29 /** Setup Packet Count (DOEPTSIZ0 Only) */ 451#define DEPTSIZ0_supcnt_bitp 29 /** Setup Packet Count (DOEPTSIZ0 Only) */
416#define DEPTSIZ0_supcnt_bits (0x3 << DEPTSIZ0_supcnt_bit_pos) 452#define DEPTSIZ0_supcnt_bits 0x3
417
418/* valid for DAINT and DAINTMSK, for 0<=ep<=15 */
419#define DAINT_IN_EP(i) (1 << (i))
420#define DAINT_OUT_EP(i) (1 << ((i) + 16))
421 453
422/** 454/**
423 * Parameters 455 * Parameters