Coverage Report

Created: 2026-10-13 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/drivers/serial/linux_console.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-only
2
/*
3
 * linux_console.c - Use stdin/stdout as a console device
4
 *
5
 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
6
 */
7
8
#include <common.h>
9
#include <driver.h>
10
#include <init.h>
11
#include <mach/linux.h>
12
#include <malloc.h>
13
#include <console.h>
14
#include <xfuncs.h>
15
16
static void linux_console_putc(struct console_device *cdev, char c)
17
208
{
18
208
  struct device *dev = cdev->dev;
19
208
  struct linux_console_data *d = dev->platform_data;
20
21
208
  linux_write(d->stdoutfd, &c, 1);
22
208
}
23
24
static int linux_console_tstc(struct console_device *cdev)
25
0
{
26
0
  struct device *dev = cdev->dev;
27
0
  struct linux_console_data *d = dev->platform_data;
28
29
0
  return linux_tstc(d->stdinfd);
30
0
}
31
32
static int linux_console_getc(struct console_device *cdev)
33
0
{
34
0
  struct device *dev = cdev->dev;
35
0
  struct linux_console_data *d = dev->platform_data;
36
0
  static char old_c;
37
0
  char c;
38
39
0
  linux_read(d->stdinfd, &c, 1);
40
41
0
  if (old_c == 0x1c && c == 'q')
42
0
    panic("^\\q pressed - exiting");
43
44
0
  old_c = c;
45
0
  return c;
46
0
}
47
48
static int linux_console_probe(struct device *dev)
49
26
{
50
26
  struct console_device *cdev;
51
26
  struct linux_console_data *data = dev->platform_data;
52
53
26
  cdev = xzalloc(sizeof(struct console_device));
54
26
  cdev->dev = dev;
55
26
  if (data->stdinfd >= 0) {
56
26
    cdev->tstc = linux_console_tstc;
57
26
    cdev->getc = linux_console_getc;
58
26
  }
59
26
  if (data->stdoutfd >= 0)
60
26
    cdev->putc = linux_console_putc;
61
62
26
  console_register(cdev);
63
64
26
  pr_info("%s: registered as %s%d\n", dev->name, cdev->class_dev.name,
65
26
    cdev->class_dev.id);
66
67
26
  return 0;
68
26
}
69
70
static struct driver linux_console_driver = {
71
        .name  = "console",
72
        .probe = linux_console_probe,
73
};
74
console_platform_driver(linux_console_driver);