console.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/console.h>
  19. #include <linux/slab.h>
  20. #include <linux/stm.h>
  21. static int stm_console_link(struct stm_source_data *data);
  22. static void stm_console_unlink(struct stm_source_data *data);
  23. static struct stm_console {
  24. struct stm_source_data data;
  25. struct console console;
  26. } stm_console = {
  27. .data = {
  28. .name = "console",
  29. .nr_chans = 1,
  30. .link = stm_console_link,
  31. .unlink = stm_console_unlink,
  32. },
  33. };
  34. static void
  35. stm_console_write(struct console *con, const char *buf, unsigned len)
  36. {
  37. struct stm_console *sc = container_of(con, struct stm_console, console);
  38. stm_source_write(&sc->data, 0, buf, len);
  39. }
  40. static int stm_console_link(struct stm_source_data *data)
  41. {
  42. 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);
  47. return 0;
  48. }
  49. static void stm_console_unlink(struct stm_source_data *data)
  50. {
  51. struct stm_console *sc = container_of(data, struct stm_console, data);
  52. unregister_console(&sc->console);
  53. }
  54. static int stm_console_init(void)
  55. {
  56. return stm_source_register_device(NULL, &stm_console.data);
  57. }
  58. static void stm_console_exit(void)
  59. {
  60. stm_source_unregister_device(&stm_console.data);
  61. }
  62. module_init(stm_console_init);
  63. module_exit(stm_console_exit);
  64. MODULE_LICENSE("GPL v2");
  65. MODULE_DESCRIPTION("stm_console driver");
  66. MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");