source: mainline/kernel/genarch/src/drivers/s3c24xx/uart.c@ 4b1c7c6f

Last change on this file since 4b1c7c6f was 4b1c7c6f, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Clean up PAGE_* flags.

Remove "nop flags", they are confusing for readers and any benefit they would
gain in self-documentation they lose in being used inconsistently.

Remove "PAGE_READ", the only place it's used meaningfully is the incomplete
RISC-V implementation, and most call sites assume read is implied.

  • Property mode set to 100644
File size: 4.7 KB
Line 
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
40#include <assert.h>
41#include <genarch/drivers/s3c24xx/uart.h>
42#include <console/chardev.h>
43#include <console/console.h>
44#include <arch/asm.h>
45#include <mm/slab.h>
46#include <mm/page.h>
47#include <mm/km.h>
48#include <sysinfo/sysinfo.h>
49#include <str.h>
50
51static void s3c24xx_uart_sendb(outdev_t *dev, uint8_t byte)
52{
53 s3c24xx_uart_t *uart =
54 (s3c24xx_uart_t *) dev->data;
55
56 /* Wait for space becoming available in Tx FIFO. */
57 while ((pio_read_32(&uart->io->ufstat) & S3C24XX_UFSTAT_TX_FULL) != 0)
58 ;
59
60 pio_write_32(&uart->io->utxh, byte);
61}
62
63static void s3c24xx_uart_putchar(outdev_t *dev, wchar_t ch)
64{
65 s3c24xx_uart_t *uart =
66 (s3c24xx_uart_t *) dev->data;
67
68 if ((!uart->parea.mapped) || (console_override)) {
69 if (!ascii_check(ch)) {
70 s3c24xx_uart_sendb(dev, U_SPECIAL);
71 } else {
72 if (ch == '\n')
73 s3c24xx_uart_sendb(dev, (uint8_t) '\r');
74 s3c24xx_uart_sendb(dev, (uint8_t) ch);
75 }
76 }
77}
78
79static irq_ownership_t s3c24xx_uart_claim(irq_t *irq)
80{
81 return IRQ_ACCEPT;
82}
83
84static void s3c24xx_uart_irq_handler(irq_t *irq)
85{
86 s3c24xx_uart_t *uart = irq->instance;
87
88 while ((pio_read_32(&uart->io->ufstat) & S3C24XX_UFSTAT_RX_COUNT) != 0) {
89 uint32_t data = pio_read_32(&uart->io->urxh);
90 pio_read_32(&uart->io->uerstat);
91 indev_push_character(uart->indev, data & 0xff);
92 }
93}
94
95static outdev_operations_t s3c24xx_uart_ops = {
96 .write = s3c24xx_uart_putchar,
97 .redraw = NULL,
98 .scroll_up = NULL,
99 .scroll_down = NULL
100};
101
102outdev_t *s3c24xx_uart_init(uintptr_t paddr, inr_t inr)
103{
104 outdev_t *uart_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
105 if (!uart_dev)
106 return NULL;
107
108 s3c24xx_uart_t *uart =
109 malloc(sizeof(s3c24xx_uart_t), FRAME_ATOMIC);
110 if (!uart) {
111 free(uart_dev);
112 return NULL;
113 }
114
115 outdev_initialize("s3c24xx_uart_dev", uart_dev, &s3c24xx_uart_ops);
116 uart_dev->data = uart;
117
118 uart->io = (s3c24xx_uart_io_t *) km_map(paddr, PAGE_SIZE,
119 PAGE_WRITE);
120 uart->indev = NULL;
121
122 /* Initialize IRQ structure. */
123 irq_initialize(&uart->irq);
124 uart->irq.inr = inr;
125 uart->irq.claim = s3c24xx_uart_claim;
126 uart->irq.handler = s3c24xx_uart_irq_handler;
127 uart->irq.instance = uart;
128
129 /* Enable FIFO, Tx trigger level: empty, Rx trigger level: 1 byte. */
130 pio_write_32(&uart->io->ufcon, UFCON_FIFO_ENABLE |
131 UFCON_TX_FIFO_TLEVEL_EMPTY | UFCON_RX_FIFO_TLEVEL_1B);
132
133 /* Set RX interrupt to pulse mode */
134 pio_write_32(&uart->io->ucon,
135 pio_read_32(&uart->io->ucon) & ~UCON_RX_INT_LEVEL);
136
137 link_initialize(&uart->parea.link);
138 uart->parea.pbase = paddr;
139 uart->parea.frames = 1;
140 uart->parea.unpriv = false;
141 uart->parea.mapped = false;
142 ddi_parea_register(&uart->parea);
143
144 if (!fb_exported) {
145 /*
146 * This is the necessary evil until
147 * the userspace driver is entirely
148 * self-sufficient.
149 */
150 sysinfo_set_item_val("fb", NULL, true);
151 sysinfo_set_item_val("fb.kind", NULL, 3);
152 sysinfo_set_item_val("fb.address.physical", NULL, paddr);
153
154 fb_exported = true;
155 }
156
157 return uart_dev;
158}
159
160void s3c24xx_uart_input_wire(s3c24xx_uart_t *uart, indev_t *indev)
161{
162 assert(uart);
163 assert(indev);
164
165 uart->indev = indev;
166 irq_register(&uart->irq);
167}
168
169/** @}
170 */
Note: See TracBrowser for help on using the repository browser.