serial.c 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * TI DaVinci serial driver
 *
 * Copyright (C) 2006 Texas Instruments.
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/serial_8250.h>
#include <linux/serial_reg.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/clk.h>
29
#include <linux/io.h>
30

31
#include <mach/serial.h>
32
#include <mach/cputype.h>
33

34 35
static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
					   int offset)
36 37
{
	offset <<= up->regshift;
38 39 40 41

	WARN_ONCE(!up->membase, "unmapped read: uart[%d]\n", offset);

	return (unsigned int)__raw_readl(up->membase + offset);
42 43
}

44 45
static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
				    int value)
46 47
{
	offset <<= p->regshift;
48 49 50 51

	WARN_ONCE(!p->membase, "unmapped write: uart[%d]\n", offset);

	__raw_writel(value, p->membase + offset);
52 53 54 55 56 57
}

static void __init davinci_serial_reset(struct plat_serial8250_port *p)
{
	unsigned int pwremu = 0;

58
	serial_write_reg(p, UART_IER, 0);  /* disable all interrupts */
59

60 61
	/* reset both transmitter and receiver: bits 14,13 = UTRST, URRST */
	serial_write_reg(p, UART_DAVINCI_PWREMU, pwremu);
62 63 64 65
	mdelay(10);

	pwremu |= (0x3 << 13);
	pwremu |= 0x1;
66 67 68 69 70 71 72
	serial_write_reg(p, UART_DAVINCI_PWREMU, pwremu);

	if (cpu_is_davinci_dm646x())
		serial_write_reg(p, UART_DM646X_SCR,
				 UART_DM646X_SCR_TX_WATERMARK);
}

73
int __init davinci_serial_init(struct davinci_uart_config *info)
74 75 76 77
{
	int i;
	char name[16];
	struct clk *uart_clk;
78 79 80
	struct davinci_soc_info *soc_info = &davinci_soc_info;
	struct device *dev = &soc_info->serial_dev->dev;
	struct plat_serial8250_port *p = dev->platform_data;
81 82 83

	/*
	 * Make sure the serial ports are muxed on at this point.
84
	 * You have to mux them off in device drivers later on if not needed.
85
	 */
86
	for (i = 0; p->flags; i++, p++) {
87
		if (!(info->enabled_uarts & (1 << i)))
88 89 90 91
			continue;

		sprintf(name, "uart%d", i);
		uart_clk = clk_get(dev, name);
92
		if (IS_ERR(uart_clk)) {
93 94
			printk(KERN_ERR "%s:%d: failed to get UART%d clock\n",
					__func__, __LINE__, i);
95
			continue;
96
		}
97 98 99 100 101 102 103 104 105 106 107 108 109

		clk_enable(uart_clk);
		p->uartclk = clk_get_rate(uart_clk);

		if (!p->membase && p->mapbase) {
			p->membase = ioremap(p->mapbase, SZ_4K);

			if (p->membase)
				p->flags &= ~UPF_IOREMAP;
			else
				pr_err("uart regs ioremap failed\n");
		}

110
		if (p->membase && p->type != PORT_AR7)
111
			davinci_serial_reset(p);
112
	}
113

114
	return platform_device_register(soc_info->serial_dev);
115
}