Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Simple kernel console driver for STM devices
4 * Copyright (c) 2014, Intel Corporation.
5 *
6 * STM console will send kernel messages over STM devices to a trace host.
7 */
8
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>
14
15static int stm_console_link(struct stm_source_data *data);
16static void stm_console_unlink(struct stm_source_data *data);
17
18static 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 .link = stm_console_link,
26 .unlink = stm_console_unlink,
27 },
28};
29
30static void
31stm_console_write(struct console *con, const char *buf, unsigned len)
32{
33 struct stm_console *sc = container_of(con, struct stm_console, console);
34
35 stm_source_write(&sc->data, 0, buf, len);
36}
37
38static int stm_console_link(struct stm_source_data *data)
39{
40 struct stm_console *sc = container_of(data, struct stm_console, data);
41
42 strcpy(sc->console.name, "stm_console");
43 sc->console.write = stm_console_write;
44 sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
45 register_console(&sc->console);
46
47 return 0;
48}
49
50static void stm_console_unlink(struct stm_source_data *data)
51{
52 struct stm_console *sc = container_of(data, struct stm_console, data);
53
54 unregister_console(&sc->console);
55}
56
57static int stm_console_init(void)
58{
59 return stm_source_register_device(NULL, &stm_console.data);
60}
61
62static void stm_console_exit(void)
63{
64 stm_source_unregister_device(&stm_console.data);
65}
66
67module_init(stm_console_init);
68module_exit(stm_console_exit);
69
70MODULE_LICENSE("GPL v2");
71MODULE_DESCRIPTION("stm_console driver");
72MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");
1/*
2 * Simple kernel console driver for STM devices
3 * Copyright (c) 2014, Intel Corporation.
4 *
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.
8 *
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.
13 *
14 * STM console will send kernel messages over STM devices to a trace host.
15 */
16
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>
22
23static int stm_console_link(struct stm_source_data *data);
24static void stm_console_unlink(struct stm_source_data *data);
25
26static 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,
35 },
36};
37
38static void
39stm_console_write(struct console *con, const char *buf, unsigned len)
40{
41 struct stm_console *sc = container_of(con, struct stm_console, console);
42
43 stm_source_write(&sc->data, 0, buf, len);
44}
45
46static int stm_console_link(struct stm_source_data *data)
47{
48 struct stm_console *sc = container_of(data, struct stm_console, data);
49
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);
54
55 return 0;
56}
57
58static void stm_console_unlink(struct stm_source_data *data)
59{
60 struct stm_console *sc = container_of(data, struct stm_console, data);
61
62 unregister_console(&sc->console);
63}
64
65static int stm_console_init(void)
66{
67 return stm_source_register_device(NULL, &stm_console.data);
68}
69
70static void stm_console_exit(void)
71{
72 stm_source_unregister_device(&stm_console.data);
73}
74
75module_init(stm_console_init);
76module_exit(stm_console_exit);
77
78MODULE_LICENSE("GPL v2");
79MODULE_DESCRIPTION("stm_console driver");
80MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");