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