void uart_setbrg() { unsigned int byte,speed; unsigned int highspeed; unsigned int quot, divisor, remainder; unsigned int uartclk; unsigned short data, high_speed_div, sample_count, sample_point; unsigned int tmp_div; speed = g_brg; uartclk = (unsigned int)(mt6575_get_bus_freq()*1000/4); if (speed <= 115200 ) { highspeed = 0; quot = 16; } else { highspeed = 3; quot = 1; } if (highspeed < 3) { /*0~2*/ /* Set divisor DLL and DLH */ divisor = uartclk / (quot * speed); remainder = uartclk % (quot * speed); if (remainder >= (quot / 2) * speed) divisor += 1; DRV_WriteReg16(UART_HIGHSPEED(g_uart),highspeed); byte = DRV_Reg32(UART_LCR(g_uart)); /* DLAB start */ DRV_WriteReg32( UART_LCR(g_uart),(byte | UART_LCR_DLAB)); DRV_WriteReg32( UART_DLL(g_uart),(divisor & 0x00ff)); DRV_WriteReg32( UART_DLH(g_uart),((divisor >> 8)&0x00ff)); DRV_WriteReg32( UART_LCR(g_uart),byte); /* DLAB end */ }
/* * init uart through portid */ void emstartkit_uart_init(DW_APB_UART_STRUCT_PTR regs, uint32_t para, uint32_t baud) { regs->MCR = 0; regs->IIR = IIR_RCVR_FIFO_RESET | IIR_XMIT_FIFO_RESET; regs->IIR = IIR_FIFO_ENABLE; regs->LCR = LCR_DLAB; /* DLL is shared with DATA */ regs->DATA = UART_DLL(baud); /* DLH is shared with IER */ regs->IER = UART_DLH(baud); regs->LCR = 0; regs->LCR = para & 0xff; regs->IER = 0; /* no interrupt enable first */ }
/* Utility routines */ static inline int get_baud(struct bf535_serial *info) { unsigned long result = 115200; unsigned short int baud_lo, baud_hi; int i, idx = info->hub2; ACCESS_LATCH(idx) /* change access to divisor latch */ baud_lo = UART_DLL(idx); baud_hi = UART_DLH(idx); for (i=0; i<BAUD_TABLE_SIZE ; i++){ if ( baud_lo == hw_baud_table[i].dl_low && baud_hi == hw_baud_table[i].dl_high) { result = baud_table[i]; break; } } return result; }
_init_ (void) { unsigned long *src, *dest, *limit; #ifdef ARM_S3C4530 unsigned long syscfg; /* Set special register base address to 0x03ff0000. */ syscfg = ARM_SYSCFG_SRBBP_MASK; /* Set internal SRAM base address. */ syscfg |= ARM_SRAM_BASE >> 10; /* Cache mode - 4-kbyte SRAM, 4-kbyte cache. */ syscfg |= ARM_SYSCFG_CM_4R_4C; /* Enable write buffer. */ syscfg |= ARM_SYSCFG_WE; /* Disable round-robin for DMA-channels. */ syscfg |= ARM_SYSCFG_FP; ARM_SYSCFG = syscfg; #ifndef EMULATOR /* not needed on emulator */ /* Invalidate the entire cache. * Clear 1-kbyte tag memory. */ dest = (unsigned long*) ARM_CACHE_TAG_ADDR; limit = dest + 1024/4; while (dest < limit) *dest++ = 0; #endif /* Enable the cache */ syscfg |= ARM_SYSCFG_CE; ARM_SYSCFG = syscfg; #endif /* ARM_S3C4530 */ #if defined (ARM_AT91SAM) && !defined (AT91BOOTSTRAP) /* Enable RESET. */ *AT91C_RSTC_RMR = 0xA5000000 | (AT91C_RSTC_ERSTL & (4 << 8)) | AT91C_RSTC_URSTEN; #ifdef AT91C_MC_FMR /* Flash mode register: set 1 flash wait state and * a number of master clock cycles in 1.5 microseconds. */ *AT91C_MC_FMR = AT91C_MC_FWS_1FWS | (AT91C_MC_FMCN & (((KHZ * 3 + 1000) / 2000) << 16)); #endif /* Disable watchdog. */ *AT91C_WDTC_WDMR = AT91C_WDTC_WDDIS; /* Main oscillator register: enabling the main oscillator. * Slow clock is 32768 Hz, or 30.51 usec. * Start up time = OSCOUNT * 8 / SCK = 1,46 msec. * Worst case is 15ms, so OSCOUNT = 15 * SCK / 8000 = 61. */ *AT91C_PMC_MOR = AT91C_CKGR_MOSCEN | (AT91C_CKGR_OSCOUNT & (61 << 8)); while (! (*AT91C_PMC_SR & AT91C_PMC_MOSCS)) continue; /* PLL register: set multiplier and divider. */ #ifdef AT91C_PMC_PLLR /* SAM7 development board: we have quartz 18.432 MHz. * After multiplying by (25+1) and dividing by 5 * we have MCK = 95.8464 MHz. * PLL startup time estimated at 0.844 msec. */ *AT91C_PMC_PLLR = (AT91C_CKGR_DIV & 0x05) | (AT91C_CKGR_PLLCOUNT & (28 << 8)) | (AT91C_CKGR_MUL & (25 << 16)); while (! (*AT91C_PMC_SR & AT91C_PMC_LOCK)) continue; #else /* SAM9 development board: quartz 12 MHz. * Set PLLA to 200 MHz = 12 MHz * (99+1) / 6. * PLL startup time is 63 slow clocks, or about 2ms. */ *AT91C_PMC_PLLAR = AT91C_CKGR_SRCA | (AT91C_CKGR_MULA & (99 << 16)) | AT91C_CKGR_OUTA_2 | (AT91C_CKGR_PLLACOUNT & (63 << 8)) | (AT91C_CKGR_DIVA & 6); while (! (*AT91C_PMC_SR & AT91C_PMC_LOCKA)) continue; #endif while (! (*AT91C_PMC_SR & AT91C_PMC_MCKRDY)) continue; #ifdef ARM_AT91SAM7X256 /* Master clock register: selection of processor clock. * Use PLL clock divided by 2. */ *AT91C_PMC_MCKR = AT91C_PMC_PRES_CLK_2; #endif #ifdef ARM_AT91SAM9260 /* Set processor clock to PLLA=200MHz. * For master clock MCK use PLL clock divided by 2. */ *AT91C_PMC_MCKR = AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2; #endif while (! (*AT91C_PMC_SR & AT91C_PMC_MCKRDY)) continue; #ifdef AT91C_PMC_CSS_PLL_CLK *AT91C_PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK; #else *AT91C_PMC_MCKR |= AT91C_PMC_CSS_PLLA_CLK; #endif while (! (*AT91C_PMC_SR & AT91C_PMC_MCKRDY)) continue; #endif /* ARM_AT91SAM && !AT91BOOTSTRAP */ #ifdef ARM_OMAP44XX extern unsigned _undefined_ []; extern unsigned _swi_ []; extern unsigned _prefetch_ []; extern unsigned _abort_ []; extern unsigned _irq_ []; extern unsigned _fiq_ []; OMAP_UNDEF_EXCEPTION_VECT = (unsigned)_undefined_; OMAP_SWI_VECT = (unsigned)_swi_; OMAP_PREFETCH_ABORT_VECT = (unsigned)_prefetch_; OMAP_DATA_ABORT_VECT = (unsigned)_abort_; OMAP_IRQ_VECT = (unsigned)_irq_; OMAP_FIQ_VECT = (unsigned)_fiq_; ARM_ICCPMR = 0xFF; #if (KHZ_CLKIN==12000) CM_SYS_CLKSEL = 1; #elif (KHZ_CLKIN==16800) CM_SYS_CLKSEL = 3; #elif (KHZ_CLKIN==19200) CM_SYS_CLKSEL = 4; #elif (KHZ_CLKIN==26000) CM_SYS_CLKSEL = 5; #elif (KHZ_CLKIN==38400) CM_SYS_CLKSEL = 7; #else #error Bad KHZ_CLKIN in target.cfg #endif /* DPLL_PER (OPP100) recommended settings */ CM_CLKSEL_DPLL_PER = DPLL_DIV(1) | DPLL_MULT(40); CM_DIV_M2_DPLL_PER = DPLL_CLKx_DIV(8); CM_DIV_M3_DPLL_PER = DPLL_CLKx_DIV(6); CM_DIV_M4_DPLL_PER = DPLL_CLKx_DIV(12); CM_DIV_M5_DPLL_PER = DPLL_CLKx_DIV(9); CM_DIV_M6_DPLL_PER = DPLL_CLKx_DIV(4); CM_DIV_M7_DPLL_PER = DPLL_CLKx_DIV(5); /* DPLL_CORE (OPP100) recommended settings */ CM_CLKSEL_DPLL_CORE = DPLL_DIV(5) | DPLL_MULT(125); CM_DIV_M2_DPLL_CORE = DPLL_CLKx_DIV(1); CM_DIV_M3_DPLL_CORE = DPLL_CLKx_DIV(5); CM_DIV_M4_DPLL_CORE = DPLL_CLKx_DIV(8); CM_DIV_M5_DPLL_CORE = DPLL_CLKx_DIV(4); CM_DIV_M6_DPLL_CORE = DPLL_CLKx_DIV(6); CM_DIV_M7_DPLL_CORE = DPLL_CLKx_DIV(6); /* DPLL_MPU (OPP100) recommended settings */ CM_CLKSEL_DPLL_MPU = DPLL_DIV(7) | DPLL_MULT(125); CM_DIV_M2_DPLL_MPU = DPLL_CLKx_DIV(1); #endif #ifdef ARM_PANDABOARD /* Switch off watchdog timer */ *((unsigned *) 0x4A314010) |= 2; /* Enable clocks for UART3 */ CM_L4PER_UART3_CLKCTRL = MODULEMODE(2); /* Setting UART3 for debug output */ UART_MDR1(3) = UART_MODE_DISABLE; /* Set 115200 kbps */ UART_LCR(3) = UART_CONF_MODE_B; UART_DLL(3) = 0x1A; UART_DLH(3) = 0x00; /* Enable FIFOs */ UART_EFR(3) |= UART_EFR_ENHANCED_EN; UART_LCR(3) = UART_CONF_MODE_A; UART_MCR(3) |= UART_MCR_TCR_TLR; UART_FCR(3) |= UART_FCR_FIFO_EN; UART_MCR(3) &= ~UART_MCR_TCR_TLR; UART_LCR(3) = UART_CONF_MODE_B; UART_EFR(3) &= ~UART_EFR_ENHANCED_EN; /* Set frame format: 8 bit/char, no parity, 1 stop bit */ UART_LCR(3) = UART_LCR_CHAR_LENGTH_8_BIT; /* Enable UART mode with 16x divisor */ UART_MDR1(3) = UART_MODE_16X; /* Set pin functions for UART3 */ CONTROL_CORE_PAD0_UART3_RX_IRRX_PAD1_UART3_TX_IRTX = MUXMODE1(0) | INPUTENABLE1 | MUXMODE2(0) | INPUTENABLE2; #endif /* ARM_PANDABOARD */ #ifndef EMULATOR /* not needed on emulator */ /* Copy the .data image from flash to ram. * Linker places it at the end of .text segment. */ src = &_etext; dest = &__data_start; limit = &_edata; while (dest < limit) *dest++ = *src++; #endif /* Initialize .bss segment by zeroes. */ dest = &_edata; limit = &_end; while (dest < limit) *dest++ = 0; /* Set stack to end of internal SRAM. */ arm_set_stack_pointer ((void*) (ARM_SRAM_BASE + ARM_SRAM_SIZE)); #ifdef ARM_S3C4530 /* Uart 0 for debug output: baud 9600. */ ARM_UCON(0) = ARM_UCON_WL_8 | ARM_UCON_TMODE_IRQ; ARM_UBRDIV(0) = ((KHZ * 500L / 9600 + 8) / 16 - 1) << 4; /* On Cronyx board, hardware watchdog is attached to pin P21. */ ARM_IOPCON1 &= ~(1 << 21); ARM_IOPMOD |= 1 << 21; /* Global interrupt enable. */ ARM_INTMSK = 0x1fffff; #endif #ifdef ARM_AT91SAM #ifndef AT91BOOTSTRAP /* Set USART0 for debug output. * RXD0 and TXD0 lines: disable PIO and assign to A function. */ *AT91C_PIOA_PDR = 3; *AT91C_PIOA_ASR = 3; *AT91C_PIOA_BSR = 0; /* Enable the clock of USART and PIO/ */ *AT91C_PMC_PCER = 1 << AT91C_ID_US0; *AT91C_PMC_PCER = 1 << AT91C_ID_PIOA; *AT91C_PMC_PCER = 1 << AT91C_ID_PIOB; /* Reset receiver and transmitter */ *AT91C_US0_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ; /* Set baud rate divisor register: baud 115200. */ *AT91C_US0_BRGR = (KHZ * 1000 / 115200 + 8) / 16; /* Write the Timeguard Register */ *AT91C_US0_TTGR = 0; /* Set the USART mode */ *AT91C_US0_MR = AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE; /* Enable the RX and TX PDC transfer requests. */ *AT91C_US0_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; /* Enable USART0: RX receiver and TX transmiter. */ *AT91C_US0_CR = AT91C_US_TXEN | AT91C_US_RXEN; #endif /* !AT91BOOTSTRAP */ #ifdef ARM_AT91SAM9260 /* Use DBGU for debug output. * PIO and DBGU are already initialized by bootstrap. */ /* Setup exception vectors at address 0. */ { extern unsigned _start_ []; unsigned *p; for (p=0; p<(unsigned*)0x20; ++p) { *p = 0xe59ff018; /* ldr pc, [pc, #24] */ p[8] = *(unsigned*) ((unsigned) &_start_[8] + (unsigned) p); } } #endif /* ARM_AT91SAM9260 */ /* Setup interrupt vectors. */ { unsigned i; for (i=0; i<32; ++i) AT91C_AIC_SVR[i] = i; *AT91C_AIC_SPU = 32; } /* Disable and clear all interrupts. */ *AT91C_AIC_IDCR = ~0; *AT91C_AIC_ICCR = ~0; *AT91C_AIC_EOICR = 0; #endif /* ARM_AT91SAM */ main (); }