From: Domenico Andreoli <[email-masked]>

Very easy implementation of the AMBA PL011 driver.

Signed-off-by: Domenico Andreoli <[email-masked]>

---
 drivers/tty/serial/amba-pl011.c |   51 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

Index: b/drivers/tty/serial/amba-pl011.c
===================================================================
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -43,6 +43,7 @@
 #include <linux/tty_flip.h>
 #include <linux/serial_core.h>
 #include <linux/serial.h>
+#include <linux/decompress/console.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/serial.h>
 #include <linux/clk.h>
@@ -2057,6 +2058,56 @@ static void __exit pl011_exit(void)
 arch_initcall(pl011_init);
 module_exit(pl011_exit);
 
+#define pl011_decomp_base(_drv)    (*(unsigned long *) (_drv)->devdata)
+
+static int __decomp_arch pl011_decomp_probe(struct decomp_console_drv *drv)
+{
+	unsigned long base = pl011_decomp_base(drv);
+	volatile uint32_t *cr;
+
+	/* this driver doesn't support probing of the base address */
+	if (!base)
+		return -EINVAL;
+
+	cr = (volatile uint32_t *) (base + UART011_CR);
+	return (*cr & UART01x_CR_UARTEN) ? 0 : -1;
+}
+
+static void __decomp_arch pl011_decomp_putc(struct decomp_console_drv *drv, int ch)
+{
+	unsigned long base = pl011_decomp_base(drv);
+	volatile uint32_t *fr, *dr;
+
+	fr = (volatile uint32_t *) (base + UART01x_FR);
+	while (*fr & UART01x_FR_TXFF)
+		barrier();
+
+	dr = (volatile uint32_t *) (base + UART01x_DR);
+	*dr = ch;
+}
+
+static void __decomp_arch pl011_decomp_flush(struct decomp_console_drv *drv)
+{
+	unsigned long base = pl011_decomp_base(drv);
+	volatile uint32_t *fr;
+
+	fr = (volatile uint32_t *) (base + UART01x_FR);
+	while (*fr & UART01x_FR_BUSY)
+		barrier();
+}
+
+static const char pl011_dt_compat[][16] __decomp_archdata = {
+	"amba-pl011",
+	"",
+};
+
+DECOMP_CONSOLE_START("ttyAMA")
+	.probe = pl011_decomp_probe,
+	.putc = pl011_decomp_putc,
+	.flush = pl011_decomp_flush,
+	.dt_compat = pl011_dt_compat,
+DECOMP_CONSOLE_END
+
 MODULE_AUTHOR("ARM Ltd/Deep Blue Solutions Ltd");
 MODULE_DESCRIPTION("ARM AMBA serial port driver");
 MODULE_LICENSE("GPL");