source: mainline/kernel/genarch/src/drivers/s3c24xx_uart/s3c24xx_uart.c@ e4f8c77

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e4f8c77 was b366a6f4, checked in by Martin Decky <martin@…>, 14 years ago

automatic kernel console lockout

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