Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / hwtracing / stm / console.c
blob097a00ac43a754db00519076a6fbf3ac4e018591
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Simple kernel console driver for STM devices
4 * Copyright (c) 2014, Intel Corporation.
6 * STM console will send kernel messages over STM devices to a trace host.
7 */
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/console.h>
12 #include <linux/slab.h>
13 #include <linux/stm.h>
15 static int stm_console_link(struct stm_source_data *data);
16 static void stm_console_unlink(struct stm_source_data *data);
18 static struct stm_console {
19 struct stm_source_data data;
20 struct console console;
21 } stm_console = {
22 .data = {
23 .name = "console",
24 .nr_chans = 1,
25 .type = STM_USER,
26 .link = stm_console_link,
27 .unlink = stm_console_unlink,
31 static void
32 stm_console_write(struct console *con, const char *buf, unsigned len)
34 struct stm_console *sc = container_of(con, struct stm_console, console);
36 stm_source_write(&sc->data, 0, buf, len);
39 static int stm_console_link(struct stm_source_data *data)
41 struct stm_console *sc = container_of(data, struct stm_console, data);
43 strcpy(sc->console.name, "stm_console");
44 sc->console.write = stm_console_write;
45 sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
46 register_console(&sc->console);
48 return 0;
51 static void stm_console_unlink(struct stm_source_data *data)
53 struct stm_console *sc = container_of(data, struct stm_console, data);
55 unregister_console(&sc->console);
58 static int stm_console_init(void)
60 return stm_source_register_device(NULL, &stm_console.data);
63 static void stm_console_exit(void)
65 stm_source_unregister_device(&stm_console.data);
68 module_init(stm_console_init);
69 module_exit(stm_console_exit);
71 MODULE_LICENSE("GPL v2");
72 MODULE_DESCRIPTION("stm_console driver");
73 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");