diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2010-08-04 03:43:56 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-08-06 19:09:38 +0200 |
commit | 907d7cb909bbec4afc3d3fafb934dcea17c55e39 (patch) | |
tree | 07bc04513a2030d63b4b442cea1c423983330dab /drivers | |
parent | dfcdce8eec30d61743cefa0edc001a79bc3e29d6 (diff) | |
download | barebox-907d7cb909bbec4afc3d3fafb934dcea17c55e39.tar.gz barebox-907d7cb909bbec4afc3d3fafb934dcea17c55e39.tar.xz |
amba: add pl011
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Andrea GALLO <andrea.gallo@stericsson.com>
Cc: Gael SALLES <gael.salles@stericsson.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/serial/Kconfig | 9 | ||||
-rw-r--r-- | drivers/serial/Makefile | 1 | ||||
-rw-r--r-- | drivers/serial/amba-pl011.c | 192 |
3 files changed, 202 insertions, 0 deletions
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 8a5056bc69..c7ea2d974d 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -4,6 +4,15 @@ config DRIVER_SERIAL_ARM_DCC depends on ARM bool "ARM Debug Communications Channel (DCC) serial driver" +config SERIAL_AMBA_PL011 + bool "ARM AMBA PL011 serial port support" + depends on ARM_AMBA + help + This selects the ARM(R) AMBA(R) PrimeCell PL011 UART. If you have + an Integrator/PP2, Integrator/CP or Versatile platform, say Y here. + + If unsure, say N. + config DRIVER_SERIAL_IMX depends on ARCH_IMX default y diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 9f203bbc06..959290e642 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -5,6 +5,7 @@ # serial_pl010.o # serial_xuartlite.o obj-$(CONFIG_DRIVER_SERIAL_ARM_DCC) += arm_dcc.o +obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o obj-$(CONFIG_DRIVER_SERIAL_IMX) += serial_imx.o obj-$(CONFIG_DRIVER_SERIAL_ATMEL) += atmel.o obj-$(CONFIG_DRIVER_SERIAL_NETX) += serial_netx.o diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c new file mode 100644 index 0000000000..07508d03b0 --- /dev/null +++ b/drivers/serial/amba-pl011.c @@ -0,0 +1,192 @@ +/* + * (C) Copyright 2000 + * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. + * + * (C) Copyright 2004 + * ARM Ltd. + * Philippe Robin, <philippe.robin@arm.com> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */ + +#include <common.h> +#include <driver.h> +#include <init.h> +#include <malloc.h> +#include <asm/io.h> +#include <linux/amba/serial.h> +#include <linux/clk.h> + +/* + * We wrap our port structure around the generic console_device. + */ +struct amba_uart_port { + struct console_device uart; /* uart */ + struct clk *clk; /* uart clock */ + u32 uartclk; +}; + +static inline struct amba_uart_port * +to_amba_uart_port(struct console_device *uart) +{ + return container_of(uart, struct amba_uart_port, uart); +} + +static int pl011_setbaudrate(struct console_device *cdev, int baudrate) +{ + struct device_d *dev = cdev->dev; + struct amba_uart_port *uart = to_amba_uart_port(cdev); + unsigned int temp; + unsigned int divider; + unsigned int remainder; + unsigned int fraction; + + /* + ** Set baud rate + ** + ** IBRD = UART_CLK / (16 * BAUD_RATE) + ** FBRD = ROUND((64 * MOD(UART_CLK,(16 * BAUD_RATE))) / (16 * BAUD_RATE)) + */ + temp = 16 * baudrate; + divider = uart->uartclk / temp; + remainder = uart->uartclk % temp; + temp = (8 * remainder) / baudrate; + fraction = (temp >> 1) + (temp & 1); + + writel(divider, dev->map_base + UART011_IBRD); + writel(fraction, dev->map_base + UART011_FBRD); + + return 0; +} + +static void pl011_putc(struct console_device *cdev, char c) +{ + struct device_d *dev = cdev->dev; + + /* Wait until there is space in the FIFO */ + while (readl(dev->map_base + UART01x_FR) & UART01x_FR_TXFF); + + /* Send the character */ + writel(c, dev->map_base + UART01x_DR); +} + +static int pl011_getc(struct console_device *cdev) +{ + struct device_d *dev = cdev->dev; + unsigned int data; + + /* Wait until there is data in the FIFO */ + while (readl(dev->map_base + UART01x_FR) & UART01x_FR_RXFE); + + data = readl(dev->map_base + UART01x_DR); + + /* Check for an error flag */ + if (data & 0xffffff00) { + /* Clear the error */ + writel(0xffffffff, dev->map_base + UART01x_ECR); + return -1; + } + + return (int)data; +} + +static int pl011_tstc(struct console_device *cdev) +{ + struct device_d *dev = cdev->dev; + + return !(readl(dev->map_base + UART01x_FR) & UART01x_FR_RXFE); +} + +int pl011_init_port (struct console_device *cdev) +{ + struct device_d *dev = cdev->dev; + struct amba_uart_port *uart = to_amba_uart_port(cdev); + + /* + ** First, disable everything. + */ + writel(0x0, dev->map_base + UART011_CR); + + /* + * Try to enable the clock producer. + */ + clk_enable(uart->clk); + + uart->uartclk = clk_get_rate(uart->clk); + + /* + * set baud rate + */ + pl011_setbaudrate(cdev, 115200); + /* + ** Set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled. + */ + writel((UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN), + dev->map_base + UART011_LCRH); + + /* + ** Finally, enable the UART + */ + writel((UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE), + dev->map_base + UART011_CR); + + return 0; +} + +static int pl011_probe(struct device_d *dev) +{ + struct amba_uart_port *uart; + struct console_device *cdev; + + uart = malloc(sizeof(struct amba_uart_port)); + + uart->clk = clk_get(dev, NULL); + + cdev = &uart->uart; + dev->type_data = cdev; + cdev->dev = dev; + cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR; + cdev->tstc = pl011_tstc; + cdev->putc = pl011_putc; + cdev->getc = pl011_getc; + cdev->setbrg = pl011_setbaudrate; + + pl011_init_port(cdev); + + /* Enable UART */ + + console_register(cdev); + + return 0; +} + +static struct driver_d pl011_driver = { + .name = "uart-pl011", + .probe = pl011_probe, +}; + +static int pl011_init(void) +{ + register_driver(&pl011_driver); + return 0; +} + +console_initcall(pl011_init); |