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 23 static int stm_console_link(struct stm_source_data *data); 24 static void stm_console_unlink(struct stm_source_data *data); 25 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, 35 }, 36 }; 37 38 static void 39 stm_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 46 static 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 58 static 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 65 static int stm_console_init(void) 66 { 67 return stm_source_register_device(NULL, &stm_console.data); 68 } 69 70 static void stm_console_exit(void) 71 { 72 stm_source_unregister_device(&stm_console.data); 73 } 74 75 module_init(stm_console_init); 76 module_exit(stm_console_exit); 77 78 MODULE_LICENSE("GPL v2"); 79 MODULE_DESCRIPTION("stm_console driver"); 80 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>"); 81