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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1720cf9 was 3d9d948, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Operate S3C24xx UART in FIFO mode.

  • Property mode set to 100644
File size: 4.5 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 <sysinfo/sysinfo.h>
47#include <str.h>
48
49/* Bits in UTRSTAT register */
50#define S3C24XX_UTRSTAT_TX_EMPTY 0x4
51#define S3C24XX_UTRSTAT_RDATA 0x1
52
53#define S3C24XX_UFSTAT_TX_FULL 0x4000
54#define S3C24XX_UFSTAT_RX_FULL 0x0040
55#define S3C24XX_UFSTAT_RX_COUNT 0x002f
56
57static void s3c24xx_uart_sendb(outdev_t *dev, uint8_t byte)
58{
59 s3c24xx_uart_t *uart =
60 (s3c24xx_uart_t *) dev->data;
61
62 /* Wait for space becoming available in Tx FIFO. */
63 while ((pio_read_32(&uart->io->ufstat) & S3C24XX_UFSTAT_TX_FULL) != 0)
64 ;
65
66 pio_write_32(&uart->io->utxh, byte);
67}
68
69static void s3c24xx_uart_putchar(outdev_t *dev, wchar_t ch, bool silent)
70{
71 if (!silent) {
72 if (!ascii_check(ch)) {
73 s3c24xx_uart_sendb(dev, U_SPECIAL);
74 } else {
75 if (ch == '\n')
76 s3c24xx_uart_sendb(dev, (uint8_t) '\r');
77 s3c24xx_uart_sendb(dev, (uint8_t) ch);
78 }
79 }
80}
81
82static irq_ownership_t s3c24xx_uart_claim(irq_t *irq)
83{
84 return IRQ_ACCEPT;
85}
86
87static void s3c24xx_uart_irq_handler(irq_t *irq)
88{
89 s3c24xx_uart_t *uart = irq->instance;
90
91 while ((pio_read_32(&uart->io->ufstat) & S3C24XX_UFSTAT_RX_COUNT) != 0) {
92 uint32_t data = pio_read_32(&uart->io->urxh);
93 pio_read_32(&uart->io->uerstat);
94 indev_push_character(uart->indev, data & 0xff);
95 }
96}
97
98static outdev_operations_t s3c24xx_uart_ops = {
99 .write = s3c24xx_uart_putchar,
100 .redraw = NULL
101};
102
103outdev_t *s3c24xx_uart_init(s3c24xx_uart_io_t *io, inr_t inr)
104{
105 outdev_t *uart_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
106 if (!uart_dev)
107 return NULL;
108
109 s3c24xx_uart_t *uart =
110 malloc(sizeof(s3c24xx_uart_t), FRAME_ATOMIC);
111 if (!uart) {
112 free(uart_dev);
113 return NULL;
114 }
115
116 outdev_initialize("s3c24xx_uart_dev", uart_dev, &s3c24xx_uart_ops);
117 uart_dev->data = uart;
118
119 uart->io = io;
120 uart->indev = NULL;
121
122 /* Initialize IRQ structure. */
123 irq_initialize(&uart->irq);
124 uart->irq.devno = device_assign_devno();
125 uart->irq.inr = inr;
126 uart->irq.claim = s3c24xx_uart_claim;
127 uart->irq.handler = s3c24xx_uart_irq_handler;
128 uart->irq.instance = uart;
129
130 /* Enable FIFO, Tx trigger level: empty, Rx trigger level: 1 byte. */
131 pio_write_32(&uart->io->ufcon, 0x01);
132
133 /* Set RX interrupt to pulse mode */
134 pio_write_32(&uart->io->ucon,
135 pio_read_32(&uart->io->ucon) & ~(1 << 8));
136
137 if (!fb_exported) {
138 /*
139 * This is the necessary evil until the userspace driver is entirely
140 * self-sufficient.
141 */
142 sysinfo_set_item_val("fb", NULL, true);
143 sysinfo_set_item_val("fb.kind", NULL, 3);
144 sysinfo_set_item_val("fb.address.physical", NULL, KA2PA(io));
145
146 fb_exported = true;
147 }
148
149 return uart_dev;
150}
151
152void s3c24xx_uart_input_wire(s3c24xx_uart_t *uart, indev_t *indev)
153{
154 ASSERT(uart);
155 ASSERT(indev);
156
157 uart->indev = indev;
158 irq_register(&uart->irq);
159}
160
161/** @}
162 */
Note: See TracBrowser for help on using the repository browser.