Changeset e6a356dd in mainline for kernel/genarch/src/drivers/amdm37x_uart/amdm37x_uart.c
- Timestamp:
- 2012-03-04T20:37:27Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 05a6548
- Parents:
- b0e58c7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/drivers/amdm37x_uart/amdm37x_uart.c
rb0e58c7 re6a356dd 35 35 36 36 #include <genarch/drivers/amdm37x_uart/amdm37x_uart.h> 37 #include <str.h> 38 #include <mm/km.h> 37 39 38 int amdm37x_uart_init( 40 static void amdm37x_uart_txb(amdm37x_uart_t *uart, uint8_t b) 41 { 42 /* Wait for buffer */ 43 while (uart->regs->ssr & AMDM37x_UART_SSR_TX_FIFO_FULL_FLAG); 44 /* Write to the outgoing fifo */ 45 uart->regs->thr = b; 46 } 47 48 static void amdm37x_uart_putchar(outdev_t *dev, wchar_t ch) 49 { 50 amdm37x_uart_t *uart = dev->data; 51 if (!ascii_check(ch)) { 52 amdm37x_uart_txb(uart, U_SPECIAL); 53 } else { 54 if (ch == '\n') 55 amdm37x_uart_txb(uart, '\r'); 56 amdm37x_uart_txb(uart, ch); 57 } 58 } 59 60 static outdev_operations_t amdm37x_uart_ops = { 61 .redraw = NULL, 62 .write = amdm37x_uart_putchar, 63 }; 64 65 bool amdm37x_uart_init( 39 66 amdm37x_uart_t *uart, inr_t interrupt, uintptr_t addr, size_t size) 40 67 { 41 return 0; 68 ASSERT(uart); 69 uart->regs = (void *)km_map(addr, size, PAGE_NOT_CACHEABLE); 70 71 /* See TI OMAP35X TRM ch 17.5.1.1 p. 2732 for startup routine */ 72 73 /* Soft reset the port */ 74 uart->regs->sysc = AMDM37x_UART_SYSC_SOFTRESET_FLAG; 75 while (uart->regs->syss & AMDM37x_UART_SYSS_RESETDONE_FLAG) ; 76 77 /* Enable access to EFR register */ 78 const uint8_t lcr = uart->regs->lcr; /* Save old value */ 79 uart->regs->lcr = 0xbf; /* Sets config mode B */ 80 81 /* Enable access to TCL_TLR register */ 82 const bool enhanced = uart->regs->efr & AMDM37x_UART_EFR_ENH_FLAG; 83 uart->regs->efr |= AMDM37x_UART_EFR_ENH_FLAG; /* Turn on enh. */ 84 uart->regs->lcr = 0x80; /* Config mode A */ 85 86 /* Set default (val 0) triggers, disable DMA enable FIFOs */ 87 const bool tcl_tlr = uart->regs->mcr & AMDM37x_UART_MCR_TCR_TLR_FLAG; 88 uart->regs->fcr = AMDM37x_UART_FCR_FIFO_EN_FLAG; 89 90 /* Enable fine granularity for rx trigger */ 91 uart->regs->lcr = 0xbf; /* Sets config mode B */ 92 uart->regs->scr = AMDM37x_UART_SCR_RX_TRIG_GRANU1_FLAG; 93 94 /* Restore enhanced */ 95 if (!enhanced) 96 uart->regs->efr &= ~AMDM37x_UART_EFR_ENH_FLAG; 97 98 uart->regs->lcr = 0x80; /* Config mode A */ 99 /* Restore tcl_lcr */ 100 if (!tcl_tlr) 101 uart->regs->mcr &= ~AMDM37x_UART_MCR_TCR_TLR_FLAG; 102 103 /* Restore tcl_lcr */ 104 uart->regs->lcr = lcr; 105 106 /* Disable interrupts */ 107 uart->regs->ier = 0; 108 109 /* Setup outdev */ 110 outdev_initialize("amdm37x_uart_dev", &uart->outdev, &amdm37x_uart_ops); 111 uart->outdev.data = uart; 112 return false; 42 113 } 43 114 44 115 void amdm37x_uart_input_wire(amdm37x_uart_t *uart, indev_t *indev) 45 116 { 117 // TODO implement 118 // register interrupt 119 // set rx fifo 120 // set rx fifo threshold to 1 46 121 } 47 122
Note:
See TracChangeset
for help on using the changeset viewer.