PCI / PM: Block races between runtime PM and system sleep
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / m68k / emu / nfcon.c
blobab20dc0ff63bd47075075390abf074b735bb2850
1 /*
2 * ARAnyM console driver
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
6 * for more details.
7 */
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/console.h>
12 #include <linux/tty.h>
13 #include <linux/tty_driver.h>
14 #include <linux/tty_flip.h>
15 #include <linux/slab.h>
16 #include <linux/err.h>
17 #include <linux/uaccess.h>
19 #include <asm/natfeat.h>
21 static int stderr_id;
22 static struct tty_driver *nfcon_tty_driver;
24 static void nfputs(const char *str, unsigned int count)
26 char buf[68];
28 buf[64] = 0;
29 while (count > 64) {
30 memcpy(buf, str, 64);
31 nf_call(stderr_id, buf);
32 str += 64;
33 count -= 64;
35 memcpy(buf, str, count);
36 buf[count] = 0;
37 nf_call(stderr_id, buf);
40 static void nfcon_write(struct console *con, const char *str,
41 unsigned int count)
43 nfputs(str, count);
46 static struct tty_driver *nfcon_device(struct console *con, int *index)
48 *index = 0;
49 return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL;
52 static struct console nf_console = {
53 .name = "nfcon",
54 .write = nfcon_write,
55 .device = nfcon_device,
56 .flags = CON_PRINTBUFFER,
57 .index = -1,
61 static int nfcon_tty_open(struct tty_struct *tty, struct file *filp)
63 return 0;
66 static void nfcon_tty_close(struct tty_struct *tty, struct file *filp)
70 static int nfcon_tty_write(struct tty_struct *tty, const unsigned char *buf,
71 int count)
73 nfputs(buf, count);
74 return count;
77 static int nfcon_tty_put_char(struct tty_struct *tty, unsigned char ch)
79 char temp[2] = { ch, 0 };
81 nf_call(stderr_id, temp);
82 return 1;
85 static int nfcon_tty_write_room(struct tty_struct *tty)
87 return 64;
90 static const struct tty_operations nfcon_tty_ops = {
91 .open = nfcon_tty_open,
92 .close = nfcon_tty_close,
93 .write = nfcon_tty_write,
94 .put_char = nfcon_tty_put_char,
95 .write_room = nfcon_tty_write_room,
98 #ifndef MODULE
100 static int __init nf_debug_setup(char *arg)
102 if (strcmp(arg, "nfcon"))
103 return 0;
105 stderr_id = nf_get_id("NF_STDERR");
106 if (stderr_id) {
107 nf_console.flags |= CON_ENABLED;
108 register_console(&nf_console);
111 return 0;
114 early_param("debug", nf_debug_setup);
116 #endif /* !MODULE */
118 static int __init nfcon_init(void)
120 int res;
122 stderr_id = nf_get_id("NF_STDERR");
123 if (!stderr_id)
124 return -ENODEV;
126 nfcon_tty_driver = alloc_tty_driver(1);
127 if (!nfcon_tty_driver)
128 return -ENOMEM;
130 nfcon_tty_driver->owner = THIS_MODULE;
131 nfcon_tty_driver->driver_name = "nfcon";
132 nfcon_tty_driver->name = "nfcon";
133 nfcon_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
134 nfcon_tty_driver->subtype = SYSTEM_TYPE_TTY;
135 nfcon_tty_driver->init_termios = tty_std_termios;
136 nfcon_tty_driver->flags = TTY_DRIVER_REAL_RAW;
138 tty_set_operations(nfcon_tty_driver, &nfcon_tty_ops);
139 res = tty_register_driver(nfcon_tty_driver);
140 if (res) {
141 pr_err("failed to register nfcon tty driver\n");
142 put_tty_driver(nfcon_tty_driver);
143 return res;
146 if (!(nf_console.flags & CON_ENABLED))
147 register_console(&nf_console);
149 return 0;
152 static void __exit nfcon_exit(void)
154 unregister_console(&nf_console);
155 tty_unregister_driver(nfcon_tty_driver);
156 put_tty_driver(nfcon_tty_driver);
159 module_init(nfcon_init);
160 module_exit(nfcon_exit);
162 MODULE_LICENSE("GPL");