1 | /* This file contains the TTY driver for the serial ports. The driver |
---|
2 | * is layered so that different UART hardware can be used. It is implemented |
---|
3 | * using the Driver Manager. |
---|
4 | * |
---|
5 | * This driver uses the termios pseudo driver. |
---|
6 | * |
---|
7 | * COPYRIGHT (c) 2010. |
---|
8 | * Cobham Gaisler AB. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <bsp.h> |
---|
16 | #include <stdlib.h> |
---|
17 | #include <bsp/cons.h> |
---|
18 | #include <rtems/console.h> |
---|
19 | |
---|
20 | #ifdef RTEMS_DRVMGR_STARTUP |
---|
21 | |
---|
22 | /* Note that it is not possible to use the interrupt mode of the driver |
---|
23 | * together with the "old" APBUART and -u to GRMON. However the new |
---|
24 | * APBUART core (from 1.0.17-b2710) has the GRMON debug bit and can |
---|
25 | * handle interrupts. |
---|
26 | */ |
---|
27 | |
---|
28 | static int console_initialized = 0; |
---|
29 | |
---|
30 | #define FLAG_SYSCON 0x01 |
---|
31 | struct console_priv { |
---|
32 | int flags; /* 0x1=SystemConsole */ |
---|
33 | int minor; |
---|
34 | struct console_dev *dev; |
---|
35 | }; |
---|
36 | |
---|
37 | #define CONSOLE_MAX BSP_NUMBER_OF_TERMIOS_PORTS |
---|
38 | struct console_priv cons[CONSOLE_MAX] = {{0,0},}; |
---|
39 | |
---|
40 | /* Install Console in TERMIOS layer */ |
---|
41 | static void console_dev_init(struct console_priv *con) |
---|
42 | { |
---|
43 | char name[16], *fsname; |
---|
44 | rtems_status_code status; |
---|
45 | int minor; |
---|
46 | |
---|
47 | minor = con->minor; |
---|
48 | if (!con->dev->fsname) { |
---|
49 | strcpy(name, "/dev/console_a"); |
---|
50 | /* Special console name and MINOR for SYSTEM CONSOLE */ |
---|
51 | if (minor == 0) |
---|
52 | name[12] = '\0'; /* /dev/console */ |
---|
53 | name[13] += minor; /* when minor=0, this has no effect... */ |
---|
54 | fsname = name; |
---|
55 | } else { |
---|
56 | fsname = con->dev->fsname; |
---|
57 | } |
---|
58 | status = rtems_termios_device_install( |
---|
59 | fsname, |
---|
60 | con->dev->handler, |
---|
61 | NULL, |
---|
62 | &con->dev->base |
---|
63 | ); |
---|
64 | if (status != RTEMS_SUCCESSFUL) { |
---|
65 | rtems_fatal_error_occurred(status); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | /* Called by device driver to register itself to the cons interface. */ |
---|
70 | void console_dev_register(struct console_dev *dev) |
---|
71 | { |
---|
72 | int i, minor = 0; |
---|
73 | struct console_priv *con = NULL; |
---|
74 | |
---|
75 | if ((dev->flags & CONSOLE_FLAG_SYSCON) && !cons[0].dev) { |
---|
76 | con = &cons[0]; |
---|
77 | con->flags = FLAG_SYSCON; |
---|
78 | } else { |
---|
79 | for (i=1; i<CONSOLE_MAX; i++) { |
---|
80 | if (!cons[i].dev) { |
---|
81 | con = &cons[i]; |
---|
82 | con->flags = 0; |
---|
83 | minor = i; |
---|
84 | break; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | if (con == NULL) { |
---|
89 | /* Not enough console structures */ |
---|
90 | return; |
---|
91 | } |
---|
92 | dev->flags &= ~CONSOLE_FLAG_SYSCON_GRANT; |
---|
93 | if (con->flags & FLAG_SYSCON) { |
---|
94 | dev->flags |= CONSOLE_FLAG_SYSCON_GRANT; |
---|
95 | } |
---|
96 | |
---|
97 | /* Assign Console */ |
---|
98 | con->dev = dev; |
---|
99 | con->minor = minor; |
---|
100 | |
---|
101 | if (console_initialized) { |
---|
102 | /* Console layer is already initialized, that means that we can |
---|
103 | * register termios interface directly. |
---|
104 | */ |
---|
105 | console_dev_init(con); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | #if 0 |
---|
110 | void console_dev_unregister(struct console_dev *dev) |
---|
111 | { |
---|
112 | |
---|
113 | } |
---|
114 | #endif |
---|
115 | |
---|
116 | rtems_device_driver console_initialize( |
---|
117 | rtems_device_major_number major, |
---|
118 | rtems_device_minor_number minor, |
---|
119 | void *arg) |
---|
120 | { |
---|
121 | int i; |
---|
122 | |
---|
123 | rtems_termios_initialize(); |
---|
124 | |
---|
125 | /* Register all Console a file system device node */ |
---|
126 | for (i=0; i<CONSOLE_MAX; i++) { |
---|
127 | if (cons[i].dev) |
---|
128 | console_dev_init(&cons[i]); |
---|
129 | } |
---|
130 | |
---|
131 | console_initialized = 1; |
---|
132 | |
---|
133 | return RTEMS_SUCCESSFUL; |
---|
134 | } |
---|
135 | |
---|
136 | #endif |
---|