Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset e6a356dd in mainline


Ignore:
Timestamp:
2012-03-04T20:37:27Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
05a6548
Parents:
b0e58c7
Message:

amdm37x: Simple UART driver implementation (only output).

Location:
kernel/genarch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/include/drivers/amdm37x_uart/amdm37x_uart.h

    rb0e58c7 re6a356dd  
    448448
    449449
    450 int amdm37x_uart_init(amdm37x_uart_t *, inr_t, uintptr_t, size_t);
     450bool amdm37x_uart_init(amdm37x_uart_t *, inr_t, uintptr_t, size_t);
    451451void amdm37x_uart_input_wire(amdm37x_uart_t *, indev_t *);
    452452
  • kernel/genarch/src/drivers/amdm37x_uart/amdm37x_uart.c

    rb0e58c7 re6a356dd  
    3535
    3636#include <genarch/drivers/amdm37x_uart/amdm37x_uart.h>
     37#include <str.h>
     38#include <mm/km.h>
    3739
    38 int amdm37x_uart_init(
     40static 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
     48static 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
     60static outdev_operations_t amdm37x_uart_ops = {
     61        .redraw = NULL,
     62        .write = amdm37x_uart_putchar,
     63};
     64
     65bool amdm37x_uart_init(
    3966    amdm37x_uart_t *uart, inr_t interrupt, uintptr_t addr, size_t size)
    4067{
    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;
    42113}
    43114
    44115void amdm37x_uart_input_wire(amdm37x_uart_t *uart, indev_t *indev)
    45116{
     117        // TODO implement
     118        // register interrupt
     119        // set rx fifo
     120        // set rx fifo threshold to 1
    46121}
    47122
Note: See TracChangeset for help on using the changeset viewer.