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 <arch/asm.h>
|
---|
43 | #include <mm/slab.h>
|
---|
44 | #include <console/console.h>
|
---|
45 | #include <sysinfo/sysinfo.h>
|
---|
46 | #include <str.h>
|
---|
47 |
|
---|
48 | /** S3C24xx UART register offsets */
|
---|
49 | #define S3C24XX_UTRSTAT 0x10
|
---|
50 | #define S3C24XX_UTXH 0x20
|
---|
51 |
|
---|
52 | /* Bits in UTXH register */
|
---|
53 | #define S3C24XX_UTXH_TX_EMPTY 0x4
|
---|
54 |
|
---|
55 | typedef struct {
|
---|
56 | ioport8_t *base;
|
---|
57 | } s3c24xx_uart_instance_t;
|
---|
58 |
|
---|
59 | static void s3c24xx_uart_sendb(outdev_t *dev, uint8_t byte)
|
---|
60 | {
|
---|
61 | s3c24xx_uart_instance_t *instance =
|
---|
62 | (s3c24xx_uart_instance_t *) dev->data;
|
---|
63 | ioport32_t *utrstat, *utxh;
|
---|
64 |
|
---|
65 | utrstat = (ioport32_t *) (instance->base + S3C24XX_UTRSTAT);
|
---|
66 | utxh = (ioport32_t *) (instance->base + S3C24XX_UTXH);
|
---|
67 |
|
---|
68 | /* Wait for transmitter to be empty. */
|
---|
69 | while ((pio_read_32(utrstat) & S3C24XX_UTXH_TX_EMPTY) == 0)
|
---|
70 | ;
|
---|
71 |
|
---|
72 | pio_write_32(utxh, byte);
|
---|
73 | }
|
---|
74 |
|
---|
75 | static void s3c24xx_uart_putchar(outdev_t *dev, wchar_t ch, bool silent)
|
---|
76 | {
|
---|
77 | if (!silent) {
|
---|
78 | if (!ascii_check(ch)) {
|
---|
79 | s3c24xx_uart_sendb(dev, U_SPECIAL);
|
---|
80 | } else {
|
---|
81 | if (ch == '\n')
|
---|
82 | s3c24xx_uart_sendb(dev, (uint8_t) '\r');
|
---|
83 | s3c24xx_uart_sendb(dev, (uint8_t) ch);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | static outdev_operations_t s3c24xx_uart_ops = {
|
---|
89 | .write = s3c24xx_uart_putchar,
|
---|
90 | .redraw = NULL
|
---|
91 | };
|
---|
92 |
|
---|
93 | outdev_t *s3c24xx_uart_init(ioport8_t *base)
|
---|
94 | {
|
---|
95 | outdev_t *uart_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
|
---|
96 | if (!uart_dev)
|
---|
97 | return NULL;
|
---|
98 |
|
---|
99 | s3c24xx_uart_instance_t *instance =
|
---|
100 | malloc(sizeof(s3c24xx_uart_instance_t), FRAME_ATOMIC);
|
---|
101 | if (!instance) {
|
---|
102 | free(uart_dev);
|
---|
103 | return NULL;
|
---|
104 | }
|
---|
105 |
|
---|
106 | outdev_initialize("s3c24xx_uart_dev", uart_dev, &s3c24xx_uart_ops);
|
---|
107 | uart_dev->data = instance;
|
---|
108 |
|
---|
109 | instance->base = base;
|
---|
110 |
|
---|
111 | if (!fb_exported) {
|
---|
112 | /*
|
---|
113 | * This is the necessary evil until the userspace driver is entirely
|
---|
114 | * self-sufficient.
|
---|
115 | */
|
---|
116 | sysinfo_set_item_val("fb", NULL, true);
|
---|
117 | sysinfo_set_item_val("fb.kind", NULL, 3);
|
---|
118 | sysinfo_set_item_val("fb.address.physical", NULL, KA2PA(base));
|
---|
119 |
|
---|
120 | fb_exported = true;
|
---|
121 | }
|
---|
122 |
|
---|
123 | return uart_dev;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /** @}
|
---|
127 | */
|
---|