[f1fc83a] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Martin Decky
|
---|
| 3 | * Copyright (c) 2010 Jiri Svoboda
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup genarch
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | * @brief Samsung S3C24xx on-chip UART driver.
|
---|
| 36 | *
|
---|
| 37 | * This UART is present on the Samsung S3C24xx CPU (on the gta02 platform).
|
---|
| 38 | */
|
---|
| 39 |
|
---|
[63e27ef] | 40 | #include <assert.h>
|
---|
[96b9724] | 41 | #include <genarch/drivers/s3c24xx/uart.h>
|
---|
[f1fc83a] | 42 | #include <console/chardev.h>
|
---|
[ec08286] | 43 | #include <console/console.h>
|
---|
| 44 | #include <ddi/device.h>
|
---|
[f1fc83a] | 45 | #include <arch/asm.h>
|
---|
| 46 | #include <mm/slab.h>
|
---|
[b366a6f4] | 47 | #include <mm/page.h>
|
---|
[d4673296] | 48 | #include <mm/km.h>
|
---|
[f1fc83a] | 49 | #include <sysinfo/sysinfo.h>
|
---|
| 50 | #include <str.h>
|
---|
| 51 |
|
---|
| 52 | static void s3c24xx_uart_sendb(outdev_t *dev, uint8_t byte)
|
---|
| 53 | {
|
---|
[277cf60] | 54 | s3c24xx_uart_t *uart =
|
---|
| 55 | (s3c24xx_uart_t *) dev->data;
|
---|
[f1fc83a] | 56 |
|
---|
[3d9d948] | 57 | /* Wait for space becoming available in Tx FIFO. */
|
---|
| 58 | while ((pio_read_32(&uart->io->ufstat) & S3C24XX_UFSTAT_TX_FULL) != 0)
|
---|
[f1fc83a] | 59 | ;
|
---|
| 60 |
|
---|
[277cf60] | 61 | pio_write_32(&uart->io->utxh, byte);
|
---|
[f1fc83a] | 62 | }
|
---|
| 63 |
|
---|
[b366a6f4] | 64 | static void s3c24xx_uart_putchar(outdev_t *dev, wchar_t ch)
|
---|
[f1fc83a] | 65 | {
|
---|
[b366a6f4] | 66 | s3c24xx_uart_t *uart =
|
---|
| 67 | (s3c24xx_uart_t *) dev->data;
|
---|
| 68 |
|
---|
| 69 | if ((!uart->parea.mapped) || (console_override)) {
|
---|
[f1fc83a] | 70 | if (!ascii_check(ch)) {
|
---|
| 71 | s3c24xx_uart_sendb(dev, U_SPECIAL);
|
---|
| 72 | } else {
|
---|
[b366a6f4] | 73 | if (ch == '\n')
|
---|
[f1fc83a] | 74 | s3c24xx_uart_sendb(dev, (uint8_t) '\r');
|
---|
| 75 | s3c24xx_uart_sendb(dev, (uint8_t) ch);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[ec08286] | 80 | static irq_ownership_t s3c24xx_uart_claim(irq_t *irq)
|
---|
| 81 | {
|
---|
| 82 | return IRQ_ACCEPT;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | static void s3c24xx_uart_irq_handler(irq_t *irq)
|
---|
| 86 | {
|
---|
[277cf60] | 87 | s3c24xx_uart_t *uart = irq->instance;
|
---|
[ec08286] | 88 |
|
---|
[3d9d948] | 89 | while ((pio_read_32(&uart->io->ufstat) & S3C24XX_UFSTAT_RX_COUNT) != 0) {
|
---|
[277cf60] | 90 | uint32_t data = pio_read_32(&uart->io->urxh);
|
---|
[3d9d948] | 91 | pio_read_32(&uart->io->uerstat);
|
---|
[277cf60] | 92 | indev_push_character(uart->indev, data & 0xff);
|
---|
[ec08286] | 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[f1fc83a] | 96 | static outdev_operations_t s3c24xx_uart_ops = {
|
---|
| 97 | .write = s3c24xx_uart_putchar,
|
---|
[7ddc2c7] | 98 | .redraw = NULL,
|
---|
| 99 | .scroll_up = NULL,
|
---|
| 100 | .scroll_down = NULL
|
---|
[f1fc83a] | 101 | };
|
---|
| 102 |
|
---|
[b366a6f4] | 103 | outdev_t *s3c24xx_uart_init(uintptr_t paddr, inr_t inr)
|
---|
[f1fc83a] | 104 | {
|
---|
| 105 | outdev_t *uart_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
|
---|
| 106 | if (!uart_dev)
|
---|
| 107 | return NULL;
|
---|
| 108 |
|
---|
[277cf60] | 109 | s3c24xx_uart_t *uart =
|
---|
| 110 | malloc(sizeof(s3c24xx_uart_t), FRAME_ATOMIC);
|
---|
| 111 | if (!uart) {
|
---|
[f1fc83a] | 112 | free(uart_dev);
|
---|
| 113 | return NULL;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | outdev_initialize("s3c24xx_uart_dev", uart_dev, &s3c24xx_uart_ops);
|
---|
[277cf60] | 117 | uart_dev->data = uart;
|
---|
[f1fc83a] | 118 |
|
---|
[adec5b45] | 119 | uart->io = (s3c24xx_uart_io_t *) km_map(paddr, PAGE_SIZE,
|
---|
| 120 | PAGE_WRITE | PAGE_NOT_CACHEABLE);
|
---|
[277cf60] | 121 | uart->indev = NULL;
|
---|
[ec08286] | 122 |
|
---|
| 123 | /* Initialize IRQ structure. */
|
---|
[277cf60] | 124 | irq_initialize(&uart->irq);
|
---|
| 125 | uart->irq.devno = device_assign_devno();
|
---|
| 126 | uart->irq.inr = inr;
|
---|
| 127 | uart->irq.claim = s3c24xx_uart_claim;
|
---|
| 128 | uart->irq.handler = s3c24xx_uart_irq_handler;
|
---|
| 129 | uart->irq.instance = uart;
|
---|
[ec08286] | 130 |
|
---|
[3d9d948] | 131 | /* Enable FIFO, Tx trigger level: empty, Rx trigger level: 1 byte. */
|
---|
[07c66cf] | 132 | pio_write_32(&uart->io->ufcon, UFCON_FIFO_ENABLE |
|
---|
| 133 | UFCON_TX_FIFO_TLEVEL_EMPTY | UFCON_RX_FIFO_TLEVEL_1B);
|
---|
[ec08286] | 134 |
|
---|
| 135 | /* Set RX interrupt to pulse mode */
|
---|
[277cf60] | 136 | pio_write_32(&uart->io->ucon,
|
---|
[07c66cf] | 137 | pio_read_32(&uart->io->ucon) & ~UCON_RX_INT_LEVEL);
|
---|
[b366a6f4] | 138 |
|
---|
| 139 | link_initialize(&uart->parea.link);
|
---|
| 140 | uart->parea.pbase = paddr;
|
---|
| 141 | uart->parea.frames = 1;
|
---|
| 142 | uart->parea.unpriv = false;
|
---|
| 143 | uart->parea.mapped = false;
|
---|
| 144 | ddi_parea_register(&uart->parea);
|
---|
| 145 |
|
---|
[f1fc83a] | 146 | if (!fb_exported) {
|
---|
| 147 | /*
|
---|
[b366a6f4] | 148 | * This is the necessary evil until
|
---|
| 149 | * the userspace driver is entirely
|
---|
[f1fc83a] | 150 | * self-sufficient.
|
---|
| 151 | */
|
---|
| 152 | sysinfo_set_item_val("fb", NULL, true);
|
---|
| 153 | sysinfo_set_item_val("fb.kind", NULL, 3);
|
---|
[b366a6f4] | 154 | sysinfo_set_item_val("fb.address.physical", NULL, paddr);
|
---|
[f1fc83a] | 155 |
|
---|
| 156 | fb_exported = true;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | return uart_dev;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[277cf60] | 162 | void s3c24xx_uart_input_wire(s3c24xx_uart_t *uart, indev_t *indev)
|
---|
[ec08286] | 163 | {
|
---|
[63e27ef] | 164 | assert(uart);
|
---|
| 165 | assert(indev);
|
---|
[ec08286] | 166 |
|
---|
[277cf60] | 167 | uart->indev = indev;
|
---|
| 168 | irq_register(&uart->irq);
|
---|
[ec08286] | 169 | }
|
---|
| 170 |
|
---|
[f1fc83a] | 171 | /** @}
|
---|
| 172 | */
|
---|