示例#1
0
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 */
	}
示例#2
0
void mtk_uart_init (U32 uartclk, U32 baudrate)
{
    //#define AP_PERI_GLOBALCON_RST0 (PERI_CON_BASE+0x0)
    #define AP_PERI_GLOBALCON_PDN0 (0x10000084)

    /* uartclk != 0, means use custom bus clock; uartclk == 0, means use defaul bus clk */
    if(0 == uartclk){ // default bus clk
        //uartclk = mtk_get_bus_freq()*1000/4;
	uartclk = UART_SRC_CLK;
    }

    mtk_serial_set_current_uart(CFG_UART_META);
    //PDN_Power_CONA_DOWN(PDN_PERI_UART1, 0);

    //UART_CLR_BITS(1 << 0, AP_PERI_GLOBALCON_RST0); /* Release UART1 reset signal */
    //UART_SET_BITS(1 << 24, AP_PERI_GLOBALCON_PDN0); /* Power on UART1 */
    //UART_CLR_BITS(1 << 10, AP_PERI_GLOBALCON_PDN0); /* Power on UART1 */
    mtk_uart_power_on(CFG_UART_META);

    UART_SET_BITS(UART_FCR_FIFO_INIT, UART_FCR(g_uart)); /* clear fifo */
    UART_WRITE16(UART_NONE_PARITY | UART_WLS_8 | UART_1_STOP, UART_LCR(g_uart));
    serial_setbrg(uartclk, CFG_META_BAUDRATE);

    mtk_serial_set_current_uart(CFG_UART_LOG);
    //PDN_Power_CONA_DOWN(PDN_PERI_UART4, 0);
    //UART_SET_BITS(1 << 12, APMCU_CG_CLR0);
    //UART_CLR_BITS(1 << 3, AP_PERI_GLOBALCON_RST0); /* Release UART2 reset signal */
    //UART_SET_BITS(1 << 27, AP_PERI_GLOBALCON_PDN0); /* Power on UART2 */
    //UART_CLR_BITS(1 << 11, AP_PERI_GLOBALCON_PDN0); /* Power on UART2 */
    mtk_uart_power_on(CFG_UART_LOG);

    UART_SET_BITS(UART_FCR_FIFO_INIT, UART_FCR(g_uart)); /* clear fifo */
    UART_WRITE16(UART_NONE_PARITY | UART_WLS_8 | UART_1_STOP, UART_LCR(g_uart));
    serial_setbrg(uartclk, baudrate);
}
示例#3
0
void serial_setbrg()
{
    unsigned int byte,speed;
    unsigned int highspeed;
    unsigned int quot, divisor, remainder;
    //unsigned int ratefix; 
    unsigned int uartclk;
    //unsigned int highclk = (UART_SRC_CLK/(speed*4)) > 10 ? (1) : 0;
    unsigned short data, high_speed_div, sample_count, sample_point;
    unsigned int tmp_div;

    speed = g_brg;
    //uartclk = UART_SRC_CLK;
    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;

        UART_WRITE16(highspeed, UART_HIGHSPEED(g_uart));
        byte = UART_READ32(UART_LCR(g_uart));     /* DLAB start */
        UART_WRITE32((byte | UART_LCR_DLAB), UART_LCR(g_uart));
        UART_WRITE32((divisor & 0x00ff), UART_DLL(g_uart));
        UART_WRITE32(((divisor >> 8)&0x00ff), UART_DLH(g_uart));
        UART_WRITE32(byte, UART_LCR(g_uart));     /* DLAB end */
    } else {
示例#4
0
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;
        ////FIXME Disable for MT6582 LK Porting
        uartclk = UART_SRC_CLK;
	//uartclk = (unsigned int)(mtk_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;

		mt65xx_reg_sync_writew(highspeed, UART_HIGHSPEED(g_uart));
		byte = DRV_Reg32(UART_LCR(g_uart));	  /* DLAB start */
		mt65xx_reg_sync_writel((byte | UART_LCR_DLAB), UART_LCR(g_uart));
		mt65xx_reg_sync_writel((divisor & 0x00ff), UART_DLL(g_uart));
		mt65xx_reg_sync_writel(((divisor >> 8)&0x00ff), UART_DLH(g_uart));
		mt65xx_reg_sync_writel(byte, UART_LCR(g_uart));	  /* DLAB end */
	}
示例#5
0
static void output_status(struct hfmodem_state *dev, int ptt)
{
    int dcd = 0;

    ptt = !!ptt;
    if (dev->ptt_out.flags & SP_SER) {
        outb(dcd | (ptt << 1), UART_MCR(dev->ptt_out.seriobase));
        outb(0x40 & (-ptt), UART_LCR(dev->ptt_out.seriobase));
    }
    if (dev->ptt_out.flags & SP_PAR) {
        outb(ptt | (dcd << 1), LPT_DATA(dev->ptt_out.pariobase));
    }
    if (dev->ptt_out.flags & SP_MIDI && ptt) {
        outb(0, MIDI_DATA(dev->ptt_out.midiiobase));
    }
}
示例#6
0
文件: sm.c 项目: dmgerman/original
void sm_output_status(struct sm_state *sm)
{
	int invert_dcd = 0;
	int invert_ptt = 0;

	int ptt = /*hdlcdrv_ptt(&sm->hdrv)*/(sm->dma.ptt_cnt > 0) ^ invert_ptt;
	int dcd = (!!sm->hdrv.hdlcrx.dcd) ^ invert_dcd;

	if (sm->hdrv.ptt_out.flags & SP_SER) {
		outb(dcd | (ptt << 1), UART_MCR(sm->hdrv.ptt_out.seriobase));
		outb(0x40 & (-ptt), UART_LCR(sm->hdrv.ptt_out.seriobase));
	}
	if (sm->hdrv.ptt_out.flags & SP_PAR && sm->pardev && sm->pardev->port)
		parport_write_data(sm->pardev->port, ptt | (dcd << 1));
	if (sm->hdrv.ptt_out.flags & SP_MIDI && hdlcdrv_ptt(&sm->hdrv))
		outb(0, MIDI_DATA(sm->hdrv.ptt_out.midiiobase));
}
示例#7
0
static void output_open(struct hfmodem_state *dev)
{
    dev->ptt_out.flags = 0;
    if (dev->ptt_out.seriobase > 0) {
        if (!check_region(dev->ptt_out.seriobase, SER_EXTENT)) {
            request_region(dev->ptt_out.seriobase, SER_EXTENT, "hfmodem ser ptt");
            dev->ptt_out.flags |= SP_SER;
            outb(0, UART_IER(dev->ptt_out.seriobase));
            /* 5 bits, 1 stop, no parity, no break, Div latch access */
            outb(0x80, UART_LCR(dev->ptt_out.seriobase));
            outb(0, UART_DLM(dev->ptt_out.seriobase));
            outb(1, UART_DLL(dev->ptt_out.seriobase)); /* as fast as possible */
            /* LCR and MCR set by output_status */
        } else
            printk(KERN_WARNING "%s: PTT output: serial port at 0x%x busy\n",
                   hfmodem_drvname, dev->ptt_out.seriobase);
    }
    if (dev->ptt_out.pariobase > 0) {
        if (parport_claim(dev->ptt_out.pardev))
            printk(KERN_WARNING "%s: PTT output: parallel port at 0x%x busy\n",
                   hfmodem_drvname, dev->ptt_out.pariobase);
        else
            dev->ptt_out.flags |= SP_PAR;
    }
    if (dev->ptt_out.midiiobase > 0) {
        if (!check_region(dev->ptt_out.midiiobase, MIDI_EXTENT)) {
            request_region(dev->ptt_out.midiiobase, MIDI_EXTENT, "hfmodem midi ptt");
            dev->ptt_out.flags |= SP_MIDI;
        } else
            printk(KERN_WARNING "%s: PTT output: midi port at 0x%x busy\n",
                   hfmodem_drvname, dev->ptt_out.midiiobase);
    }
    output_status(dev, 0);
    printk(KERN_INFO "%s: PTT output:", hfmodem_drvname);
    if (dev->ptt_out.flags & SP_SER)
        printk(" serial interface at 0x%x", dev->ptt_out.seriobase);
    if (dev->ptt_out.flags & SP_PAR)
        printk(" parallel interface at 0x%x", dev->ptt_out.pariobase);
    if (dev->ptt_out.flags & SP_MIDI)
        printk(" mpu401 (midi) interface at 0x%x", dev->ptt_out.midiiobase);
    if (!dev->ptt_out.flags)
        printk(" none");
    printk("\n");
}
示例#8
0
void serial_setbrg (U32 uartclk, U32 baudrate)
{
#if (CFG_FPGA_PLATFORM)
    #define MAX_SAMPLE_COUNT 256

    U16 tmp;
    U32 divisor;
    U32 sample_data;
    U32 sample_count;
    U32 sample_point;

    // Setup N81,(UART_WLS_8 | UART_NONE_PARITY | UART_1_STOP) = 0x03
    UART_WRITE32(0x0003, UART_LCR(g_uart));

   /*
    * NoteXXX: Below is the sample code to set UART baud rate.
    *          I assume that when system is reset, the UART clock rate is 26MHz
    *          and baud rate is 115200.
    *          use UART1_HIGHSPEED = 0x3 can get more sample count to get better UART sample rate
    *          based on baud_rate = uart clock frequency / (sampe_count * divisor)
    *          divisor = (DLH+DLL)
    */

    // In order to get better UART sample rate, set UART1_HIGHSPEED = 0x3.
    // And we can calculate sample count for reducing effect of UART sample rate variation
    UART_WRITE32(0x0003, UART_HIGHSPEED(g_uart));

    // calculate sample_data = sample_count*divisor
    // round off the result for approximating to the real baudrate
    sample_data = (uartclk+(baudrate/2))/baudrate;
    // calculate divisor
    divisor = (sample_data+(MAX_SAMPLE_COUNT-1))/MAX_SAMPLE_COUNT;
    // calculate sample count
    sample_count = sample_data/divisor;
    // calculate sample point (count from 0)
    sample_point = (sample_count-1)/2;
    // set sample count (count from 0)
    UART_WRITE32((sample_count-1), UART_SAMPLE_COUNT(g_uart));
    // set sample point
    UART_WRITE32(sample_point, UART_SAMPLE_POINT(g_uart));

    tmp = UART_READ32(UART_LCR(g_uart));        /* DLAB start */
    UART_WRITE32((tmp | UART_LCR_DLAB), UART_LCR(g_uart));

    UART_WRITE32((divisor&0xFF), UART_DLL(g_uart));
    UART_WRITE32(((divisor>>8)&0xFF), UART_DLH(g_uart));
    UART_WRITE32(tmp, UART_LCR(g_uart));

#else
    unsigned int byte;
    unsigned int highspeed;
    unsigned int quot, divisor, remainder;
    unsigned int ratefix;

    if (baudrate <= 115200 ) {
        highspeed = 0;
        quot = 16;
    } else {
        highspeed = 2;
        quot = 4;
    }

    /* Set divisor DLL and DLH  */
    divisor   =  uartclk / (quot * baudrate);
    remainder =  uartclk % (quot * baudrate);

    if (remainder >= (quot / 2) * baudrate)
        divisor += 1;

    UART_WRITE16(highspeed, UART_HIGHSPEED(g_uart));
    byte = UART_READ32(UART_LCR(g_uart));     /* DLAB start */
    UART_WRITE32((byte | UART_LCR_DLAB), UART_LCR(g_uart));
    UART_WRITE32((divisor & 0x00ff), UART_DLL(g_uart));
    UART_WRITE32(((divisor >> 8)&0x00ff), UART_DLH(g_uart));
    //UART_WRITE32(byte, UART_LCR(g_uart));     /* DLAB end */
    // Setup N81,(UART_WLS_8 | UART_NONE_PARITY | UART_1_STOP) = 0x03
    UART_WRITE32(0x0003, UART_LCR(g_uart));
#endif
}
示例#9
0
_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 ();
}
示例#10
0
/*
* UART Init function
*/
void uart_init(uart_num_t uart_num,
				uart_databit_t data_nb_bits,
				uart_stopbit_t data_nb_stop,
				uart_parity_t data_parity,
				uint16_t uart_divisor,
				uint8_t uart_divaddval,
				uint8_t uart_mulval)
{
	uint32_t lcr_config;
	uint32_t uart_port;

	uart_port = uart_num;

	switch(uart_num)
	{
		case UART0_NUM:
			/* use PLL1 as clock source for UART0 */
			CGU_BASE_UART0_CLK = (CGU_SRC_PLL1<<UART_CGU_BASE_CLK_SEL_SHIFT) | (1<<UART_CGU_AUTOBLOCK_CLOCK_BIT);
			break;

		case UART1_NUM:
			/* use PLL1 as clock source for UART1 */
			CGU_BASE_UART1_CLK = (CGU_SRC_PLL1<<UART_CGU_BASE_CLK_SEL_SHIFT) | (1<<UART_CGU_AUTOBLOCK_CLOCK_BIT);
			break;

		case UART2_NUM:
			/* use PLL1 as clock source for UART2 */
			CGU_BASE_UART2_CLK = (CGU_SRC_PLL1<<UART_CGU_BASE_CLK_SEL_SHIFT) | (1<<UART_CGU_AUTOBLOCK_CLOCK_BIT);
			break;

		case UART3_NUM:
			/* use PLL1 as clock source for UART3 */
			CGU_BASE_UART3_CLK = (CGU_SRC_PLL1<<UART_CGU_BASE_CLK_SEL_SHIFT) | (1<<UART_CGU_AUTOBLOCK_CLOCK_BIT);
			break;

		default:
			return; /* error */
	}

	/* FIFOs RX/TX Enabled and Reset RX/TX FIFO (DMA Mode is also cleared) */
	UART_FCR(uart_port) = ( UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS);
	/* Disable FIFO */
	UART_FCR(uart_port) = 0;

	// Dummy read (to clear existing data)
	while (UART_LSR(uart_port) & UART_LSR_RDR ) {
		dummy_read = UART_RBR(uart_port);
	}

	/* Wait end of TX & disable TX */
        UART_TER(uart_port) = UART_TER_TXEN;

        /* Wait for current transmit complete */
        while (!(UART_LSR(uart_port) & UART_LSR_THRE));

        /* Disable Tx */
        UART_TER(uart_port) = 0;

	/* Disable interrupt */
	UART_IER(uart_port) = 0;

	/* Set LCR to default state */
	UART_LCR(uart_port) = 0;

	/* Set ACR to default state */
	UART_ACR(uart_port) = 0;

	/* Dummy Read to Clear Status */
	dummy_read = UART_LSR(uart_port);

	/*
		Table 835. USART Fractional Divider Register:
		UARTbaudrate = PCLK / ( 16* (((256*DLM)+ DLL)*(1+(DivAddVal/MulVal))) )
		The value of MULVAL and DIVADDVAL should comply to the following conditions:
		1. 1 <= MULVAL <= 15
		2. 0 <= DIVADDVAL <= 14
		3. DIVADDVAL < MULVAL
	*/

	/* Set DLAB Bit */
	UART_LCR(uart_port) |= UART_LCR_DLAB_EN;
	UART_DLM(uart_port) = UART_LOAD_DLM(uart_divisor);
	UART_DLL(uart_port) = UART_LOAD_DLL(uart_divisor);
	/* Clear DLAB Bit */
	UART_LCR(uart_port) &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
	UART_FDR(uart_port) = (UART_FDR_MULVAL(uart_mulval) | UART_FDR_DIVADDVAL(uart_divaddval)) & UART_FDR_BITMASK;    

	/* Read LCR config & Force Enable of Divisor Latches Access */
	lcr_config = (UART_LCR(uart_port) & UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
	lcr_config |= data_nb_bits; /* Set Nb Data Bits */
	lcr_config |= data_nb_stop; /* Set Nb Stop Bits */
	lcr_config |= data_parity; /* Set Data Parity */

	/* Write LCR (only 8bits) */
	UART_LCR(uart_port) = (lcr_config & UART_LCR_BITMASK);

	/* Enable TX */
        UART_TER(uart_port) = UART_TER_TXEN;
}
示例#11
0
文件: sm.c 项目: dmgerman/original
static void sm_output_open(struct sm_state *sm, const char *ifname)
{
	enum uart u = c_uart_unknown;
	struct parport *pp = NULL;

	sm->hdrv.ptt_out.flags = 0;
	if (sm->hdrv.ptt_out.seriobase > 0 &&
	    sm->hdrv.ptt_out.seriobase <= 0x1000-SER_EXTENT &&
	    ((u = check_uart(sm->hdrv.ptt_out.seriobase))) != c_uart_unknown) {
		sm->hdrv.ptt_out.flags |= SP_SER;
		request_region(sm->hdrv.ptt_out.seriobase, SER_EXTENT, "sm ser ptt");
		outb(0, UART_IER(sm->hdrv.ptt_out.seriobase));
		/* 5 bits, 1 stop, no parity, no break, Div latch access */
		outb(0x80, UART_LCR(sm->hdrv.ptt_out.seriobase));
		outb(0, UART_DLM(sm->hdrv.ptt_out.seriobase));
		outb(1, UART_DLL(sm->hdrv.ptt_out.seriobase)); /* as fast as possible */
		/* LCR and MCR set by output_status */
	}
	sm->pardev = NULL;
	if (sm->hdrv.ptt_out.pariobase > 0) {
		pp = parport_enumerate();
		while (pp && pp->base != sm->hdrv.ptt_out.pariobase) 
			pp = pp->next;
		if (!pp)
			printk(KERN_WARNING "%s: parport at address 0x%x not found\n", sm_drvname, sm->hdrv.ptt_out.pariobase);
		else if ((~pp->modes) & (PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT))
			printk(KERN_WARNING "%s: parport at address 0x%x cannot be used\n", sm_drvname, sm->hdrv.ptt_out.pariobase);
		else {
			sm->pardev = parport_register_device(pp, ifname, NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
			if (!sm->pardev) {
				pp = NULL;
				printk(KERN_WARNING "%s: cannot register parport device (address 0x%x)\n", sm_drvname, sm->hdrv.ptt_out.pariobase);
			} else {
				if (parport_claim(sm->pardev)) {
					parport_unregister_device(sm->pardev);
					sm->pardev = NULL;
					printk(KERN_WARNING "%s: cannot claim parport at address 0x%x\n", sm_drvname, sm->hdrv.ptt_out.pariobase);
				} else
					sm->hdrv.ptt_out.flags |= SP_PAR;
			}
		}
	}
	if (sm->hdrv.ptt_out.midiiobase > 0 &&
	    sm->hdrv.ptt_out.midiiobase <= 0x1000-MIDI_EXTENT &&
	    check_midi(sm->hdrv.ptt_out.midiiobase)) {
		sm->hdrv.ptt_out.flags |= SP_MIDI;
		request_region(sm->hdrv.ptt_out.midiiobase, MIDI_EXTENT,
			       "sm midi ptt");
	}
	sm_output_status(sm);

	printk(KERN_INFO "%s: ptt output:", sm_drvname);
	if (sm->hdrv.ptt_out.flags & SP_SER)
		printk(" serial interface at 0x%x, uart %s", sm->hdrv.ptt_out.seriobase,
		       uart_str[u]);
	if (sm->hdrv.ptt_out.flags & SP_PAR)
		printk(" parallel interface at 0x%x", sm->hdrv.ptt_out.pariobase);
	if (sm->hdrv.ptt_out.flags & SP_MIDI)
		printk(" mpu401 (midi) interface at 0x%x", sm->hdrv.ptt_out.midiiobase);
	if (!sm->hdrv.ptt_out.flags)
		printk(" none");
	printk("\n");
}