static int ps2ser_getc_hw(void) { #ifdef CONFIG_MPC5xxx volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE; #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) NS16550_t com_port = (NS16550_t)COM_BASE; #endif int res = -1; #ifdef CONFIG_MPC5xxx if (psc->psc_status & PSC_SR_RXRDY) { res = (psc->psc_buffer_8); } #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) if (com_port->lsr & UART_LSR_DR) { res = com_port->rbr; } #else if (ps2ser_in(UART_LSR) & UART_LSR_DR) { res = (ps2ser_in(UART_RX)); } #endif return res; }
static void ps2ser_interrupt(void *dev_id) { #ifdef CONFIG_MPC5xxx volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE; #endif int chr; int status; do { chr = ps2ser_getc_hw(); #ifdef CONFIG_MPC5xxx status = psc->psc_status; #else status = ps2ser_in(UART_IIR); #endif if (chr < 0) continue; if (atomic_read(&ps2buf_cnt) < PS2BUF_SIZE) { ps2buf[ps2buf_in_idx++] = chr; ps2buf_in_idx &= (PS2BUF_SIZE - 1); atomic_inc(&ps2buf_cnt); } else { printf ("ps2ser.c: buffer overflow\n"); } #ifdef CONFIG_MPC5xxx } while (status & PSC_SR_RXRDY); #else } while (status & UART_IIR_RDI);
int ps2ser_init(void) { int quot; unsigned cval; state = rs_table + CONFIG_PS2SERIAL; quot = state->baud_base / PS2SER_BAUD; cval = 0x3; /* 8N1 - 8 data bits, no parity bits, 1 stop bit */ /* Set speed, enable interrupts, enable FIFO */ ps2ser_out(UART_LCR, cval | UART_LCR_DLAB); ps2ser_out(UART_DLL, quot & 0xff); ps2ser_out(UART_DLM, quot >> 8); ps2ser_out(UART_LCR, cval); ps2ser_out(UART_IER, UART_IER_RDI); ps2ser_out(UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS); ps2ser_out(UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); /* If we read 0xff from the LSR, there is no UART here */ if (ps2ser_in(UART_LSR) == 0xff) { printf ("ps2ser.c: no UART found\n"); return -1; } irq_install_handler(state->irq, ps2ser_interrupt, NULL); return 0; }
static void ps2ser_interrupt(void *dev_id) { #ifdef CONFIG_MPC5xxx volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE; #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) NS16550_t com_port = (NS16550_t)COM_BASE; #endif int chr; int status; do { chr = ps2ser_getc_hw(); #ifdef CONFIG_MPC5xxx status = psc->psc_status; #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) status = com_port->lsr; #else status = ps2ser_in(UART_IIR); #endif if (chr < 0) continue; if (atomic_read(&ps2buf_cnt) < PS2BUF_SIZE) { ps2buf[ps2buf_in_idx++] = chr; ps2buf_in_idx &= (PS2BUF_SIZE - 1); atomic_inc(&ps2buf_cnt); } else { printf ("ps2ser.c: buffer overflow\n"); } #ifdef CONFIG_MPC5xxx } while (status & PSC_SR_RXRDY); #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) } while (status & UART_LSR_DR);
void ps2ser_putc(int chr) { #ifdef CONFIG_MPC5xxx volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE; #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) NS16550_t com_port = (NS16550_t)COM_BASE; #endif #ifdef DEBUG printf(">>>> 0x%02x\n", chr); #endif #ifdef CONFIG_MPC5xxx while (!(psc->psc_status & PSC_SR_TXRDY)); psc->psc_buffer_8 = chr; #elif defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ defined(CONFIG_MPC8548) || defined(CONFIG_MPC8555) while ((com_port->lsr & UART_LSR_THRE) == 0); com_port->thr = chr; #else while (!(ps2ser_in(UART_LSR) & UART_LSR_THRE)); ps2ser_out(UART_TX, chr); #endif }
static int ps2ser_getc_hw(void) { #ifdef CONFIG_MPC5xxx volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE; #endif int res = -1; #ifdef CONFIG_MPC5xxx if (psc->psc_status & PSC_SR_RXRDY) { res = (psc->psc_buffer_8); } #else if (ps2ser_in(UART_LSR) & UART_LSR_DR) { res = (ps2ser_in(UART_RX)); } #endif return res; }
void ps2ser_putc(int chr) { #ifdef CONFIG_MPC5xxx volatile struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)PSC_BASE; #endif #ifdef DEBUG printf(">>>> 0x%02x\n", chr); #endif #ifdef CONFIG_MPC5xxx while (!(psc->psc_status & PSC_SR_TXRDY)); psc->psc_buffer_8 = chr; #else while (!(ps2ser_in(UART_LSR) & UART_LSR_THRE)); ps2ser_out(UART_TX, chr); #endif }