1 2 #include "kernel/kernel.h" 3 4 #if CONFIG_OXPCIE 5 6 /* Documentation is at http://www.plxtech.com/products/uart/oxpcie952 */ 7 8 #include "oxpcie.h" 9 #include "serial.h" 10 11 static unsigned char *oxpcie_vaddr = NULL; 12 13 void oxpcie_set_vaddr(unsigned char *vaddr) 14 { 15 oxpcie_vaddr = vaddr; 16 } 17 18 static void oxpcie_init(void) 19 { 20 printf("oxpcie_init\n"); 21 /* Enable access to EFR and DLM+DLL */ 22 OXPCIE_LCR = 0xBF; 23 24 /* Set FICR[1] to increase FIFO */ 25 OXPCIE_FICR = 0x01; 26 27 /* Set enhanced mode [4] 28 * no RTS/CTS [7:6] 29 * no special char detection [5] 30 * no in-band receive flow control [1:0] 31 * no in-band transmit flow control [3:2] 32 */ 33 OXPCIE_EFR = 0x10; 34 35 /* Set divisor register to 115200 baud. */ 36 OXPCIE_DLM = 0x00; 37 OXPCIE_DLL = 0x22; 38 39 /* Forget DLM and DLL, set LCR to config. */ 40 OXPCIE_LCR = LCR_CONFIG; 41 OXPCIE_LCR = LCR_CONFIG; 42 43 OXPCIE_TCR = 0x01; 44 OXPCIE_CPR = 0x20; 45 OXPCIE_CPR2 = 0; 46 } 47 48 void oxpcie_putc(char c) 49 { 50 static int inuse = 0; 51 52 if(vm_running && oxpcie_vaddr && !inuse) { 53 int i; 54 static int init_done; 55 inuse = 1; 56 57 if(!init_done) { 58 oxpcie_init(); 59 init_done = 1; 60 } 61 62 for (i= 0; i<100000; i++) { 63 if(OXPCIE_LSR & LSR_THRE) 64 break; 65 } 66 OXPCIE_THR = c; 67 inuse = 0; 68 } 69 } 70 71 int oxpcie_in(void) 72 { 73 if(vm_running && oxpcie_vaddr) { 74 int lsr; 75 lsr = OXPCIE_LSR; 76 if(lsr & LSR_DR) 77 return (int) OXPCIE_RBR; 78 } 79 80 return -1; 81 } 82 83 #endif 84