Changeset 18b6a88 in mainline for uspace/drv/platform/amdm37x/amdm37x.c
- Timestamp:
- 2018-04-15T09:35:04Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c1f44ca
- Parents:
- 8ebe212
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/platform/amdm37x/amdm37x.c
r8ebe212 r18b6a88 48 48 void *data, bool write) 49 49 { 50 printf("PIO %s: %p(%p) %#" PRIx64"\n", write ? "WRITE" : "READ",50 printf("PIO %s: %p(%p) %#" PRIx64 "\n", write ? "WRITE" : "READ", 51 51 (place - base) + data, place, val); 52 52 } … … 58 58 errno_t ret = EOK; 59 59 60 ret = pio_enable((void *)USBHOST_CM_BASE_ADDRESS, USBHOST_CM_SIZE,61 (void **)&device->cm.usbhost);62 if (ret != EOK) 63 return ret; 64 65 ret = pio_enable((void *)CORE_CM_BASE_ADDRESS, CORE_CM_SIZE,66 (void **)&device->cm.core);67 if (ret != EOK) 68 return ret; 69 70 ret = pio_enable((void *)CLOCK_CONTROL_CM_BASE_ADDRESS,71 CLOCK_CONTROL_CM_SIZE, (void**)&device->cm.clocks);72 if (ret != EOK) 73 return ret; 74 75 ret = pio_enable((void *)MPU_CM_BASE_ADDRESS,76 MPU_CM_SIZE, (void**)&device->cm.mpu);77 if (ret != EOK) 78 return ret; 79 80 ret = pio_enable((void *)IVA2_CM_BASE_ADDRESS,81 IVA2_CM_SIZE, (void**)&device->cm.iva2);82 if (ret != EOK) 83 return ret; 84 85 ret = pio_enable((void *)CLOCK_CONTROL_PRM_BASE_ADDRESS,86 CLOCK_CONTROL_PRM_SIZE, (void **)&device->prm.clocks);87 if (ret != EOK) 88 return ret; 89 90 ret = pio_enable((void *)GLOBAL_REG_PRM_BASE_ADDRESS,91 GLOBAL_REG_PRM_SIZE, (void **)&device->prm.global);92 if (ret != EOK) 93 return ret; 94 95 ret = pio_enable((void *)AMDM37x_USBTLL_BASE_ADDRESS,96 AMDM37x_USBTLL_SIZE, (void **)&device->tll);97 if (ret != EOK) 98 return ret; 99 100 ret = pio_enable((void *)AMDM37x_UHH_BASE_ADDRESS,101 AMDM37x_UHH_SIZE, (void **)&device->uhh);60 ret = pio_enable((void *)USBHOST_CM_BASE_ADDRESS, USBHOST_CM_SIZE, 61 (void **)&device->cm.usbhost); 62 if (ret != EOK) 63 return ret; 64 65 ret = pio_enable((void *)CORE_CM_BASE_ADDRESS, CORE_CM_SIZE, 66 (void **)&device->cm.core); 67 if (ret != EOK) 68 return ret; 69 70 ret = pio_enable((void *)CLOCK_CONTROL_CM_BASE_ADDRESS, 71 CLOCK_CONTROL_CM_SIZE, (void **)&device->cm.clocks); 72 if (ret != EOK) 73 return ret; 74 75 ret = pio_enable((void *)MPU_CM_BASE_ADDRESS, 76 MPU_CM_SIZE, (void **)&device->cm.mpu); 77 if (ret != EOK) 78 return ret; 79 80 ret = pio_enable((void *)IVA2_CM_BASE_ADDRESS, 81 IVA2_CM_SIZE, (void **)&device->cm.iva2); 82 if (ret != EOK) 83 return ret; 84 85 ret = pio_enable((void *)CLOCK_CONTROL_PRM_BASE_ADDRESS, 86 CLOCK_CONTROL_PRM_SIZE, (void **)&device->prm.clocks); 87 if (ret != EOK) 88 return ret; 89 90 ret = pio_enable((void *)GLOBAL_REG_PRM_BASE_ADDRESS, 91 GLOBAL_REG_PRM_SIZE, (void **)&device->prm.global); 92 if (ret != EOK) 93 return ret; 94 95 ret = pio_enable((void *)AMDM37x_USBTLL_BASE_ADDRESS, 96 AMDM37x_USBTLL_SIZE, (void **)&device->tll); 97 if (ret != EOK) 98 return ret; 99 100 ret = pio_enable((void *)AMDM37x_UHH_BASE_ADDRESS, 101 AMDM37x_UHH_SIZE, (void **)&device->uhh); 102 102 if (ret != EOK) 103 103 return ret; 104 104 105 105 if (trace) { 106 pio_trace_enable(device->tll, AMDM37x_USBTLL_SIZE, log_message, (void *)AMDM37x_USBTLL_BASE_ADDRESS);107 pio_trace_enable(device->cm.clocks, CLOCK_CONTROL_CM_SIZE, log_message, (void *)CLOCK_CONTROL_CM_BASE_ADDRESS);108 pio_trace_enable(device->cm.core, CORE_CM_SIZE, log_message, (void *)CORE_CM_BASE_ADDRESS);109 pio_trace_enable(device->cm.mpu, MPU_CM_SIZE, log_message, (void *)MPU_CM_BASE_ADDRESS);110 pio_trace_enable(device->cm.iva2, IVA2_CM_SIZE, log_message, (void *)IVA2_CM_BASE_ADDRESS);111 pio_trace_enable(device->cm.usbhost, USBHOST_CM_SIZE, log_message, (void *)USBHOST_CM_BASE_ADDRESS);112 pio_trace_enable(device->uhh, AMDM37x_UHH_SIZE, log_message, (void *)AMDM37x_UHH_BASE_ADDRESS);113 pio_trace_enable(device->prm.clocks, CLOCK_CONTROL_PRM_SIZE, log_message, (void *)CLOCK_CONTROL_PRM_BASE_ADDRESS);114 pio_trace_enable(device->prm.global, GLOBAL_REG_PRM_SIZE, log_message, (void *)GLOBAL_REG_PRM_BASE_ADDRESS);106 pio_trace_enable(device->tll, AMDM37x_USBTLL_SIZE, log_message, (void *)AMDM37x_USBTLL_BASE_ADDRESS); 107 pio_trace_enable(device->cm.clocks, CLOCK_CONTROL_CM_SIZE, log_message, (void *)CLOCK_CONTROL_CM_BASE_ADDRESS); 108 pio_trace_enable(device->cm.core, CORE_CM_SIZE, log_message, (void *)CORE_CM_BASE_ADDRESS); 109 pio_trace_enable(device->cm.mpu, MPU_CM_SIZE, log_message, (void *)MPU_CM_BASE_ADDRESS); 110 pio_trace_enable(device->cm.iva2, IVA2_CM_SIZE, log_message, (void *)IVA2_CM_BASE_ADDRESS); 111 pio_trace_enable(device->cm.usbhost, USBHOST_CM_SIZE, log_message, (void *)USBHOST_CM_BASE_ADDRESS); 112 pio_trace_enable(device->uhh, AMDM37x_UHH_SIZE, log_message, (void *)AMDM37x_UHH_BASE_ADDRESS); 113 pio_trace_enable(device->prm.clocks, CLOCK_CONTROL_PRM_SIZE, log_message, (void *)CLOCK_CONTROL_PRM_BASE_ADDRESS); 114 pio_trace_enable(device->prm.global, GLOBAL_REG_PRM_SIZE, log_message, (void *)GLOBAL_REG_PRM_BASE_ADDRESS); 115 115 } 116 116 return EOK; … … 129 129 /* Get SYS_CLK value, it is used as reference clock by all DPLLs, 130 130 * NFI who sets this or why it is set to specific value. */ 131 const unsigned osc_clk = pio_read_32(&device->prm.clocks->clksel) 132 &CLOCK_CONTROL_PRM_CLKSEL_SYS_CLKIN_MASK;131 const unsigned osc_clk = pio_read_32(&device->prm.clocks->clksel) & 132 CLOCK_CONTROL_PRM_CLKSEL_SYS_CLKIN_MASK; 133 133 const unsigned clk_reg = pio_read_32(&device->prm.global->clksrc_ctrl); 134 const unsigned base_freq = sys_clk_freq_kHz(osc_clk) 135 /GLOBAL_REG_PRM_CLKSRC_CTRL_SYSCLKDIV_GET(clk_reg);134 const unsigned base_freq = sys_clk_freq_kHz(osc_clk) / 135 GLOBAL_REG_PRM_CLKSRC_CTRL_SYSCLKDIV_GET(clk_reg); 136 136 ddf_msg(LVL_NOTE, "Base frequency: %d.%dMhz", 137 137 base_freq / 1000, base_freq % 1000); … … 150 150 const uint32_t reg = pio_read_32(&mpu->clksel1_pll); 151 151 const unsigned multiplier = 152 (reg & MPU_CM_CLKSEL1_PLL_MPU_DPLL_MULT_MASK) 153 >>MPU_CM_CLKSEL1_PLL_MPU_DPLL_MULT_SHIFT;152 (reg & MPU_CM_CLKSEL1_PLL_MPU_DPLL_MULT_MASK) >> 153 MPU_CM_CLKSEL1_PLL_MPU_DPLL_MULT_SHIFT; 154 154 const unsigned divisor = 155 (reg & MPU_CM_CLKSEL1_PLL_MPU_DPLL_DIV_MASK) 156 >>MPU_CM_CLKSEL1_PLL_MPU_DPLL_DIV_SHIFT;155 (reg & MPU_CM_CLKSEL1_PLL_MPU_DPLL_DIV_MASK) >> 156 MPU_CM_CLKSEL1_PLL_MPU_DPLL_DIV_SHIFT; 157 157 const unsigned divisor2 = 158 (pio_read_32(&mpu->clksel2_pll) 159 &MPU_CM_CLKSEL2_PLL_MPU_DPLL_CLKOUT_DIV_MASK);158 (pio_read_32(&mpu->clksel2_pll) & 159 MPU_CM_CLKSEL2_PLL_MPU_DPLL_CLKOUT_DIV_MASK); 160 160 if (multiplier && divisor && divisor2) { 161 161 /** See AMDM37x TRM p. 300 for the formula */ 162 162 const unsigned freq = 163 ((base_freq * multiplier) / (divisor + 1)) 164 /divisor2;163 ((base_freq * multiplier) / (divisor + 1)) / 164 divisor2; 165 165 ddf_msg(LVL_NOTE, "MPU running at %d.%d MHz", 166 166 freq / 1000, freq % 1000); … … 174 174 const unsigned divisor = 175 175 MPU_CM_CLKSEL1_PLL_MPU_CLK_SRC_VAL( 176 176 pio_read_32(&mpu->clksel1_pll)); 177 177 ddf_msg(LVL_NOTE, "MPU DPLL in bypass mode, running at" 178 178 " CORE CLK / %d MHz", divisor); … … 226 226 freq / 1000, freq % 1000); 227 227 const unsigned l3_div = 228 pio_read_32(&device->cm.core->clksel) 229 &CORE_CM_CLKSEL_CLKSEL_L3_MASK;228 pio_read_32(&device->cm.core->clksel) & 229 CORE_CM_CLKSEL_CLKSEL_L3_MASK; 230 230 if (l3_div == CORE_CM_CLKSEL_CLKSEL_L3_DIVIDED1 || 231 231 l3_div == CORE_CM_CLKSEL_CLKSEL_L3_DIVIDED2) { … … 234 234 (freq / l3_div) % 1000); 235 235 } else { 236 ddf_msg(LVL_WARN, "L3 interface clock divisor is"236 ddf_msg(LVL_WARN, "L3 interface clock divisor is" 237 237 " invalid: %d", l3_div); 238 238 } … … 244 244 } else { 245 245 ddf_msg(LVL_WARN, "CORE CLK in bypass mode, fruunig at SYS_CLK" 246 " frreq of %d.%d MHz", base_freq / 1000, base_freq % 1000);246 " frreq of %d.%d MHz", base_freq / 1000, base_freq % 1000); 247 247 } 248 248 … … 268 268 */ 269 269 // TODO setup DPLL5 270 if ((pio_read_32(&device->cm.clocks->clken2_pll) 271 & CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_MASK)272 !=CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_LOCK) {270 if ((pio_read_32(&device->cm.clocks->clken2_pll) & 271 CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_MASK) != 272 CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_LOCK) { 273 273 /* Compute divisors and multiplier 274 274 * See AMDM37x TRM p. 300 for the formula */ … … 278 278 const unsigned div = (base_freq / 1000) - 1; 279 279 const unsigned div2 = 1; 280 if ( 280 if (((base_freq % 1000) != 0) || (div > 127)) { 281 281 ddf_msg(LVL_ERROR, "Rounding error, or divisor to big " 282 282 "freq: %d, div: %d", base_freq, div); … … 333 333 #if 0 334 334 printf("DPLL5 (and everything else) should be on: %" 335 PRIx32 " %"PRIx32".\n",335 PRIx32 " %" PRIx32 ".\n", 336 336 pio_read_32(&device->cm.clocks->idlest_ckgen), 337 337 pio_read_32(&device->cm.clocks->idlest2_ckgen)); … … 369 369 pio_set_32(&device->tll->sysconfig, TLL_SYSCONFIG_SOFTRESET_FLAG, 5); 370 370 ddf_msg(LVL_DEBUG2, "Waiting for USB TLL reset"); 371 while (!(pio_read_32(&device->tll->sysstatus) & TLL_SYSSTATUS_RESET_DONE_FLAG)); 371 while (!(pio_read_32(&device->tll->sysstatus) & TLL_SYSSTATUS_RESET_DONE_FLAG)) 372 ; 372 373 ddf_msg(LVL_DEBUG, "USB TLL Reset done."); 373 374
Note:
See TracChangeset
for help on using the changeset viewer.