]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/serial/serial_sa1100.c
karo: tx6: factor out PMIC initialization
[karo-tx-uboot.git] / drivers / serial / serial_sa1100.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4  *
5  * (C) Copyright 2002
6  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Marius Groeger <mgroeger@sysgo.de>
8  *
9  * (C) Copyright 2002
10  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11  * Alex Zuepke <azu@sysgo.de>
12  *
13  * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
14  *
15  * SPDX-License-Identifier:     GPL-2.0+
16  */
17
18 #include <common.h>
19 #include <SA-1100.h>
20 #include <serial.h>
21 #include <linux/compiler.h>
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 static void sa1100_serial_setbrg(void)
26 {
27         unsigned int reg = 0;
28
29         if (gd->baudrate == 1200)
30                 reg = 191;
31         else if (gd->baudrate == 9600)
32                 reg = 23;
33         else if (gd->baudrate == 19200)
34                 reg = 11;
35         else if (gd->baudrate == 38400)
36                 reg = 5;
37         else if (gd->baudrate == 57600)
38                 reg = 3;
39         else if (gd->baudrate == 115200)
40                 reg = 1;
41         else
42                 hang ();
43
44 #ifdef CONFIG_SERIAL1
45         /* SA1110 uart function */
46         Ser1SDCR0 |= SDCR0_SUS;
47
48         /* Wait until port is ready ... */
49         while(Ser1UTSR1 & UTSR1_TBY) {}
50
51         /* init serial serial 1 */
52         Ser1UTCR3 = 0x00;
53         Ser1UTSR0 = 0xff;
54         Ser1UTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData );
55         Ser1UTCR1 = 0;
56         Ser1UTCR2 = (u32)reg;
57         Ser1UTCR3 = ( UTCR3_RXE | UTCR3_TXE );
58 #elif defined(CONFIG_SERIAL3)
59         /* Wait until port is ready ... */
60         while (Ser3UTSR1 & UTSR1_TBY) {
61         }
62
63         /* init serial serial 3 */
64         Ser3UTCR3 = 0x00;
65         Ser3UTSR0 = 0xff;
66         Ser3UTCR0 = (UTCR0_1StpBit | UTCR0_8BitData);
67         Ser3UTCR1 = 0;
68         Ser3UTCR2 = (u32) reg;
69         Ser3UTCR3 = (UTCR3_RXE | UTCR3_TXE);
70 #else
71 #error "Bad: you didn't configured serial ..."
72 #endif
73 }
74
75
76 /*
77  * Initialise the serial port with the given baudrate. The settings
78  * are always 8 data bits, no parity, 1 stop bit, no start bits.
79  *
80  */
81 static int sa1100_serial_init(void)
82 {
83         serial_setbrg ();
84
85         return (0);
86 }
87
88
89 /*
90  * Output a single byte to the serial port.
91  */
92 static void sa1100_serial_putc(const char c)
93 {
94 #ifdef CONFIG_SERIAL1
95         /* wait for room in the tx FIFO on SERIAL1 */
96         while ((Ser1UTSR0 & UTSR0_TFS) == 0);
97
98         Ser1UTDR = c;
99 #elif defined(CONFIG_SERIAL3)
100         /* wait for room in the tx FIFO on SERIAL3 */
101         while ((Ser3UTSR0 & UTSR0_TFS) == 0);
102
103         Ser3UTDR = c;
104 #endif
105
106         /* If \n, also do \r */
107         if (c == '\n')
108                 serial_putc ('\r');
109 }
110
111 /*
112  * Read a single byte from the serial port. Returns 1 on success, 0
113  * otherwise. When the function is succesfull, the character read is
114  * written into its argument c.
115  */
116 static int sa1100_serial_tstc(void)
117 {
118 #ifdef CONFIG_SERIAL1
119         return Ser1UTSR1 & UTSR1_RNE;
120 #elif defined(CONFIG_SERIAL3)
121         return Ser3UTSR1 & UTSR1_RNE;
122 #endif
123 }
124
125 /*
126  * Read a single byte from the serial port. Returns 1 on success, 0
127  * otherwise. When the function is succesfull, the character read is
128  * written into its argument c.
129  */
130 static int sa1100_serial_getc(void)
131 {
132 #ifdef CONFIG_SERIAL1
133         while (!(Ser1UTSR1 & UTSR1_RNE));
134
135         return (char) Ser1UTDR & 0xff;
136 #elif defined(CONFIG_SERIAL3)
137         while (!(Ser3UTSR1 & UTSR1_RNE));
138
139         return (char) Ser3UTDR & 0xff;
140 #endif
141 }
142
143 static struct serial_device sa1100_serial_drv = {
144         .name   = "sa1100_serial",
145         .start  = sa1100_serial_init,
146         .stop   = NULL,
147         .setbrg = sa1100_serial_setbrg,
148         .putc   = sa1100_serial_putc,
149         .puts   = default_serial_puts,
150         .getc   = sa1100_serial_getc,
151         .tstc   = sa1100_serial_tstc,
152 };
153
154 void sa1100_serial_initialize(void)
155 {
156         serial_register(&sa1100_serial_drv);
157 }
158
159 __weak struct serial_device *default_serial_console(void)
160 {
161         return &sa1100_serial_drv;
162 }