1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+ 2728674a7SGreg Kroah-Hartman /* 3728674a7SGreg Kroah-Hartman * udbg interface to hvc_console.c 4728674a7SGreg Kroah-Hartman * 5728674a7SGreg Kroah-Hartman * (C) Copyright David Gibson, IBM Corporation 2008. 6728674a7SGreg Kroah-Hartman * 7728674a7SGreg Kroah-Hartman * This program is free software; you can redistribute it and/or modify 8728674a7SGreg Kroah-Hartman * it under the terms of the GNU General Public License as published by 9728674a7SGreg Kroah-Hartman * the Free Software Foundation; either version 2 of the License, or 10728674a7SGreg Kroah-Hartman * (at your option) any later version. 11728674a7SGreg Kroah-Hartman * 12728674a7SGreg Kroah-Hartman * This program is distributed in the hope that it will be useful, 13728674a7SGreg Kroah-Hartman * but WITHOUT ANY WARRANTY; without even the implied warranty of 14728674a7SGreg Kroah-Hartman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15728674a7SGreg Kroah-Hartman * GNU General Public License for more details. 16728674a7SGreg Kroah-Hartman * 17728674a7SGreg Kroah-Hartman * You should have received a copy of the GNU General Public License 18728674a7SGreg Kroah-Hartman * along with this program; if not, write to the Free Software 19728674a7SGreg Kroah-Hartman * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20728674a7SGreg Kroah-Hartman */ 21728674a7SGreg Kroah-Hartman 22728674a7SGreg Kroah-Hartman #include <linux/console.h> 23728674a7SGreg Kroah-Hartman #include <linux/delay.h> 24728674a7SGreg Kroah-Hartman #include <linux/err.h> 25728674a7SGreg Kroah-Hartman #include <linux/init.h> 26728674a7SGreg Kroah-Hartman #include <linux/moduleparam.h> 27728674a7SGreg Kroah-Hartman #include <linux/types.h> 28728674a7SGreg Kroah-Hartman #include <linux/irq.h> 29728674a7SGreg Kroah-Hartman 30728674a7SGreg Kroah-Hartman #include <asm/udbg.h> 31728674a7SGreg Kroah-Hartman 32728674a7SGreg Kroah-Hartman #include "hvc_console.h" 33728674a7SGreg Kroah-Hartman 34728674a7SGreg Kroah-Hartman struct hvc_struct *hvc_udbg_dev; 35728674a7SGreg Kroah-Hartman 36728674a7SGreg Kroah-Hartman static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count) 37728674a7SGreg Kroah-Hartman { 38728674a7SGreg Kroah-Hartman int i; 39728674a7SGreg Kroah-Hartman 407d3d897aSBenjamin Herrenschmidt for (i = 0; i < count && udbg_putc; i++) 41728674a7SGreg Kroah-Hartman udbg_putc(buf[i]); 42728674a7SGreg Kroah-Hartman 43728674a7SGreg Kroah-Hartman return i; 44728674a7SGreg Kroah-Hartman } 45728674a7SGreg Kroah-Hartman 46728674a7SGreg Kroah-Hartman static int hvc_udbg_get(uint32_t vtermno, char *buf, int count) 47728674a7SGreg Kroah-Hartman { 48728674a7SGreg Kroah-Hartman int i, c; 49728674a7SGreg Kroah-Hartman 50728674a7SGreg Kroah-Hartman if (!udbg_getc_poll) 51728674a7SGreg Kroah-Hartman return 0; 52728674a7SGreg Kroah-Hartman 53728674a7SGreg Kroah-Hartman for (i = 0; i < count; i++) { 54728674a7SGreg Kroah-Hartman if ((c = udbg_getc_poll()) == -1) 55728674a7SGreg Kroah-Hartman break; 56728674a7SGreg Kroah-Hartman buf[i] = c; 57728674a7SGreg Kroah-Hartman } 58728674a7SGreg Kroah-Hartman 59728674a7SGreg Kroah-Hartman return i; 60728674a7SGreg Kroah-Hartman } 61728674a7SGreg Kroah-Hartman 62728674a7SGreg Kroah-Hartman static const struct hv_ops hvc_udbg_ops = { 63728674a7SGreg Kroah-Hartman .get_chars = hvc_udbg_get, 64728674a7SGreg Kroah-Hartman .put_chars = hvc_udbg_put, 65728674a7SGreg Kroah-Hartman }; 66728674a7SGreg Kroah-Hartman 67728674a7SGreg Kroah-Hartman static int __init hvc_udbg_init(void) 68728674a7SGreg Kroah-Hartman { 69728674a7SGreg Kroah-Hartman struct hvc_struct *hp; 70728674a7SGreg Kroah-Hartman 717d3d897aSBenjamin Herrenschmidt if (!udbg_putc) 727d3d897aSBenjamin Herrenschmidt return -ENODEV; 737d3d897aSBenjamin Herrenschmidt 74728674a7SGreg Kroah-Hartman BUG_ON(hvc_udbg_dev); 75728674a7SGreg Kroah-Hartman 76d4e33facSAlan Cox hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16); 77728674a7SGreg Kroah-Hartman if (IS_ERR(hp)) 78728674a7SGreg Kroah-Hartman return PTR_ERR(hp); 79728674a7SGreg Kroah-Hartman 80728674a7SGreg Kroah-Hartman hvc_udbg_dev = hp; 81728674a7SGreg Kroah-Hartman 82728674a7SGreg Kroah-Hartman return 0; 83728674a7SGreg Kroah-Hartman } 844fedd0bfSPaul Gortmaker device_initcall(hvc_udbg_init); 85728674a7SGreg Kroah-Hartman 86728674a7SGreg Kroah-Hartman static int __init hvc_udbg_console_init(void) 87728674a7SGreg Kroah-Hartman { 887d3d897aSBenjamin Herrenschmidt if (!udbg_putc) 897d3d897aSBenjamin Herrenschmidt return -ENODEV; 907d3d897aSBenjamin Herrenschmidt 91728674a7SGreg Kroah-Hartman hvc_instantiate(0, 0, &hvc_udbg_ops); 92728674a7SGreg Kroah-Hartman add_preferred_console("hvc", 0, NULL); 93728674a7SGreg Kroah-Hartman 94728674a7SGreg Kroah-Hartman return 0; 95728674a7SGreg Kroah-Hartman } 96728674a7SGreg Kroah-Hartman console_initcall(hvc_udbg_console_init); 97