Linux 4.16.11
[linux/fpc-iii.git] / drivers / hwtracing / stm / console.c
blobc9d9a8d2ff52ef8ef97b0d7b71df93ae04b1e29b
1 /*
2 * Simple kernel console driver for STM devices
3 * Copyright (c) 2014, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * STM console will send kernel messages over STM devices to a trace host.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/console.h>
20 #include <linux/slab.h>
21 #include <linux/stm.h>
23 static int stm_console_link(struct stm_source_data *data);
24 static void stm_console_unlink(struct stm_source_data *data);
26 static struct stm_console {
27 struct stm_source_data data;
28 struct console console;
29 } stm_console = {
30 .data = {
31 .name = "console",
32 .nr_chans = 1,
33 .link = stm_console_link,
34 .unlink = stm_console_unlink,
38 static void
39 stm_console_write(struct console *con, const char *buf, unsigned len)
41 struct stm_console *sc = container_of(con, struct stm_console, console);
43 stm_source_write(&sc->data, 0, buf, len);
46 static int stm_console_link(struct stm_source_data *data)
48 struct stm_console *sc = container_of(data, struct stm_console, data);
50 strcpy(sc->console.name, "stm_console");
51 sc->console.write = stm_console_write;
52 sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
53 register_console(&sc->console);
55 return 0;
58 static void stm_console_unlink(struct stm_source_data *data)
60 struct stm_console *sc = container_of(data, struct stm_console, data);
62 unregister_console(&sc->console);
65 static int stm_console_init(void)
67 return stm_source_register_device(NULL, &stm_console.data);
70 static void stm_console_exit(void)
72 stm_source_unregister_device(&stm_console.data);
75 module_init(stm_console_init);
76 module_exit(stm_console_exit);
78 MODULE_LICENSE("GPL v2");
79 MODULE_DESCRIPTION("stm_console driver");
80 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");