xref: /rk3399_rockchip-uboot/drivers/misc/cbmem_console.c (revision b012bc94ac5cf4fd530f1a64836d29a51c3a5d85)
1*b012bc94SVadim Bendebury /*
2*b012bc94SVadim Bendebury  * Copyright (C) 2011 The ChromiumOS Authors.  All rights reserved.
3*b012bc94SVadim Bendebury  *
4*b012bc94SVadim Bendebury  * This program is free software; you can redistribute it and/or modify
5*b012bc94SVadim Bendebury  * it under the terms of the GNU General Public License as published by
6*b012bc94SVadim Bendebury  * the Free Software Foundation; version 2 of the License.
7*b012bc94SVadim Bendebury  *
8*b012bc94SVadim Bendebury  * This program is distributed in the hope that it will be useful,
9*b012bc94SVadim Bendebury  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10*b012bc94SVadim Bendebury  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*b012bc94SVadim Bendebury  * GNU General Public License for more details.
12*b012bc94SVadim Bendebury  *
13*b012bc94SVadim Bendebury  * You should have received a copy of the GNU General Public License
14*b012bc94SVadim Bendebury  * along with this program; if not, write to the Free Software
15*b012bc94SVadim Bendebury  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
16*b012bc94SVadim Bendebury  */
17*b012bc94SVadim Bendebury 
18*b012bc94SVadim Bendebury #include <common.h>
19*b012bc94SVadim Bendebury 
20*b012bc94SVadim Bendebury #ifndef CONFIG_SYS_COREBOOT
21*b012bc94SVadim Bendebury #error This driver requires coreboot
22*b012bc94SVadim Bendebury #endif
23*b012bc94SVadim Bendebury 
24*b012bc94SVadim Bendebury #include <asm/arch/sysinfo.h>
25*b012bc94SVadim Bendebury 
26*b012bc94SVadim Bendebury struct cbmem_console {
27*b012bc94SVadim Bendebury 	u32 buffer_size;
28*b012bc94SVadim Bendebury 	u32 buffer_cursor;
29*b012bc94SVadim Bendebury 	u8  buffer_body[0];
30*b012bc94SVadim Bendebury }  __attribute__ ((__packed__));
31*b012bc94SVadim Bendebury 
32*b012bc94SVadim Bendebury static struct cbmem_console *cbmem_console_p;
33*b012bc94SVadim Bendebury 
34*b012bc94SVadim Bendebury void cbmemc_putc(char data)
35*b012bc94SVadim Bendebury {
36*b012bc94SVadim Bendebury 	int cursor;
37*b012bc94SVadim Bendebury 
38*b012bc94SVadim Bendebury 	cursor = cbmem_console_p->buffer_cursor++;
39*b012bc94SVadim Bendebury 	if (cursor < cbmem_console_p->buffer_size)
40*b012bc94SVadim Bendebury 		cbmem_console_p->buffer_body[cursor] = data;
41*b012bc94SVadim Bendebury }
42*b012bc94SVadim Bendebury 
43*b012bc94SVadim Bendebury void cbmemc_puts(const char *str)
44*b012bc94SVadim Bendebury {
45*b012bc94SVadim Bendebury 	char c;
46*b012bc94SVadim Bendebury 
47*b012bc94SVadim Bendebury 	while ((c = *str++) != 0)
48*b012bc94SVadim Bendebury 		cbmemc_putc(c);
49*b012bc94SVadim Bendebury }
50*b012bc94SVadim Bendebury 
51*b012bc94SVadim Bendebury int cbmemc_init(void)
52*b012bc94SVadim Bendebury {
53*b012bc94SVadim Bendebury 	int rc;
54*b012bc94SVadim Bendebury 	struct stdio_dev cons_dev;
55*b012bc94SVadim Bendebury 	cbmem_console_p = lib_sysinfo.cbmem_cons;
56*b012bc94SVadim Bendebury 
57*b012bc94SVadim Bendebury 	memset(&cons_dev, 0, sizeof(cons_dev));
58*b012bc94SVadim Bendebury 
59*b012bc94SVadim Bendebury 	strcpy(cons_dev.name, "cbmem");
60*b012bc94SVadim Bendebury 	cons_dev.flags = DEV_FLAGS_OUTPUT; /* Output only */
61*b012bc94SVadim Bendebury 	cons_dev.putc  = cbmemc_putc;
62*b012bc94SVadim Bendebury 	cons_dev.puts  = cbmemc_puts;
63*b012bc94SVadim Bendebury 
64*b012bc94SVadim Bendebury 	rc = stdio_register(&cons_dev);
65*b012bc94SVadim Bendebury 
66*b012bc94SVadim Bendebury 	return (rc == 0) ? 1 : rc;
67*b012bc94SVadim Bendebury }
68