serial.c 6.9 KB
Newer Older
1
/*
2
 * linux/arch/arm/mach-omap1/serial.c
3
 *
M
Marek Vašut 已提交
4
 * OMAP1 serial support.
5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
14
#include <linux/irq.h>
15 16 17 18 19
#include <linux/delay.h>
#include <linux/serial.h>
#include <linux/tty.h>
#include <linux/serial_8250.h>
#include <linux/serial_reg.h>
20
#include <linux/clk.h>
21
#include <linux/io.h>
22 23 24

#include <asm/mach-types.h>

25 26 27 28
#include <mach/board.h>
#include <mach/mux.h>
#include <mach/gpio.h>
#include <mach/fpga.h>
29

30 31 32
static struct clk * uart1_ck;
static struct clk * uart2_ck;
static struct clk * uart3_ck;
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

static inline unsigned int omap_serial_in(struct plat_serial8250_port *up,
					  int offset)
{
	offset <<= up->regshift;
	return (unsigned int)__raw_readb(up->membase + offset);
}

static inline void omap_serial_outp(struct plat_serial8250_port *p, int offset,
				    int value)
{
	offset <<= p->regshift;
	__raw_writeb(value, p->membase + offset);
}

/*
 * Internal UARTs need to be initialized for the 8250 autoconfig to work
 * properly. Note that the TX watermark initialization may not be needed
 * once the 8250.c watermark handling code is merged.
 */
static void __init omap_serial_reset(struct plat_serial8250_port *p)
{
	omap_serial_outp(p, UART_OMAP_MDR1, 0x07);	/* disable UART */
	omap_serial_outp(p, UART_OMAP_SCR, 0x08);	/* TX watermark */
	omap_serial_outp(p, UART_OMAP_MDR1, 0x00);	/* enable UART */

M
Marek Vašut 已提交
59
	if (!cpu_is_omap15xx()) {
60 61 62 63 64 65 66
		omap_serial_outp(p, UART_OMAP_SYSC, 0x01);
		while (!(omap_serial_in(p, UART_OMAP_SYSC) & 0x01));
	}
}

static struct plat_serial8250_port serial_platform_data[] = {
	{
67
		.membase	= OMAP1_IO_ADDRESS(OMAP_UART1_BASE),
68
		.mapbase	= OMAP_UART1_BASE,
69 70 71 72 73 74 75
		.irq		= INT_UART1,
		.flags		= UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
		.uartclk	= OMAP16XX_BASE_BAUD * 16,
	},
	{
76
		.membase	= OMAP1_IO_ADDRESS(OMAP_UART2_BASE),
77
		.mapbase	= OMAP_UART2_BASE,
78 79 80 81 82 83 84
		.irq		= INT_UART2,
		.flags		= UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
		.uartclk	= OMAP16XX_BASE_BAUD * 16,
	},
	{
85
		.membase	= OMAP1_IO_ADDRESS(OMAP_UART3_BASE),
86
		.mapbase	= OMAP_UART3_BASE,
87 88 89 90 91 92 93 94 95 96 97
		.irq		= INT_UART3,
		.flags		= UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
		.uartclk	= OMAP16XX_BASE_BAUD * 16,
	},
	{ },
};

static struct platform_device serial_device = {
	.name			= "serial8250",
98
	.id			= PLAT8250_DEV_PLATFORM,
99 100 101 102 103 104 105 106 107 108
	.dev			= {
		.platform_data	= serial_platform_data,
	},
};

/*
 * Note that on Innovator-1510 UART2 pins conflict with USB2.
 * By default UART2 does not work on Innovator-1510 if you have
 * USB OHCI enabled. To use UART2, you must disable USB2 first.
 */
109
void __init omap_serial_init(void)
110 111
{
	int i;
112
	const struct omap_uart_config *info;
113 114 115 116 117 118 119 120

	if (cpu_is_omap730()) {
		serial_platform_data[0].regshift = 0;
		serial_platform_data[1].regshift = 0;
		serial_platform_data[0].irq = INT_730_UART_MODEM_1;
		serial_platform_data[1].irq = INT_730_UART_MODEM_IRDA_2;
	}

121 122 123 124 125 126 127
	if (cpu_is_omap850()) {
		serial_platform_data[0].regshift = 0;
		serial_platform_data[1].regshift = 0;
		serial_platform_data[0].irq = INT_850_UART_MODEM_1;
		serial_platform_data[1].irq = INT_850_UART_MODEM_IRDA_2;
	}

M
Marek Vašut 已提交
128
	if (cpu_is_omap15xx()) {
129 130 131 132 133
		serial_platform_data[0].uartclk = OMAP1510_BASE_BAUD * 16;
		serial_platform_data[1].uartclk = OMAP1510_BASE_BAUD * 16;
		serial_platform_data[2].uartclk = OMAP1510_BASE_BAUD * 16;
	}

134 135 136 137
	info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
	if (info == NULL)
		return;

138 139 140
	for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
		unsigned char reg;

141
		if (!((1 << i) & info->enabled_uarts)) {
142 143 144 145 146 147 148 149 150 151 152
			serial_platform_data[i].membase = NULL;
			serial_platform_data[i].mapbase = 0;
			continue;
		}

		switch (i) {
		case 0:
			uart1_ck = clk_get(NULL, "uart1_ck");
			if (IS_ERR(uart1_ck))
				printk("Could not get uart1_ck\n");
			else {
153
				clk_enable(uart1_ck);
M
Marek Vašut 已提交
154
				if (cpu_is_omap15xx())
155 156
					clk_set_rate(uart1_ck, 12000000);
			}
M
Marek Vašut 已提交
157
			if (cpu_is_omap15xx()) {
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
				omap_cfg_reg(UART1_TX);
				omap_cfg_reg(UART1_RTS);
				if (machine_is_omap_innovator()) {
					reg = fpga_read(OMAP1510_FPGA_POWER);
					reg |= OMAP1510_FPGA_PCR_COM1_EN;
					fpga_write(reg, OMAP1510_FPGA_POWER);
					udelay(10);
				}
			}
			break;
		case 1:
			uart2_ck = clk_get(NULL, "uart2_ck");
			if (IS_ERR(uart2_ck))
				printk("Could not get uart2_ck\n");
			else {
173
				clk_enable(uart2_ck);
M
Marek Vašut 已提交
174
				if (cpu_is_omap15xx())
175 176 177 178
					clk_set_rate(uart2_ck, 12000000);
				else
					clk_set_rate(uart2_ck, 48000000);
			}
M
Marek Vašut 已提交
179
			if (cpu_is_omap15xx()) {
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
				omap_cfg_reg(UART2_TX);
				omap_cfg_reg(UART2_RTS);
				if (machine_is_omap_innovator()) {
					reg = fpga_read(OMAP1510_FPGA_POWER);
					reg |= OMAP1510_FPGA_PCR_COM2_EN;
					fpga_write(reg, OMAP1510_FPGA_POWER);
					udelay(10);
				}
			}
			break;
		case 2:
			uart3_ck = clk_get(NULL, "uart3_ck");
			if (IS_ERR(uart3_ck))
				printk("Could not get uart3_ck\n");
			else {
195
				clk_enable(uart3_ck);
M
Marek Vašut 已提交
196
				if (cpu_is_omap15xx())
197 198
					clk_set_rate(uart3_ck, 12000000);
			}
M
Marek Vašut 已提交
199
			if (cpu_is_omap15xx()) {
200 201 202 203 204 205 206 207 208
				omap_cfg_reg(UART3_TX);
				omap_cfg_reg(UART3_RX);
			}
			break;
		}
		omap_serial_reset(&serial_platform_data[i]);
	}
}

209 210
#ifdef CONFIG_OMAP_SERIAL_WAKE

211
static irqreturn_t omap_serial_wake_interrupt(int irq, void *dev_id)
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
{
	/* Need to do something with serial port right after wake-up? */
	return IRQ_HANDLED;
}

/*
 * Reroutes serial RX lines to GPIO lines for the duration of
 * sleep to allow waking up the device from serial port even
 * in deep sleep.
 */
void omap_serial_wake_trigger(int enable)
{
	if (!cpu_is_omap16xx())
		return;

	if (uart1_ck != NULL) {
		if (enable)
			omap_cfg_reg(V14_16XX_GPIO37);
		else
			omap_cfg_reg(V14_16XX_UART1_RX);
	}
	if (uart2_ck != NULL) {
		if (enable)
			omap_cfg_reg(R9_16XX_GPIO18);
		else
			omap_cfg_reg(R9_16XX_UART2_RX);
	}
	if (uart3_ck != NULL) {
		if (enable)
			omap_cfg_reg(L14_16XX_GPIO49);
		else
			omap_cfg_reg(L14_16XX_UART3_RX);
	}
}

static void __init omap_serial_set_port_wakeup(int gpio_nr)
{
	int ret;

251
	ret = gpio_request(gpio_nr, "UART wake");
252 253 254 255 256
	if (ret < 0) {
		printk(KERN_ERR "Could not request UART wake GPIO: %i\n",
		       gpio_nr);
		return;
	}
257
	gpio_direction_input(gpio_nr);
D
David Brownell 已提交
258
	ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt,
259
			  IRQF_TRIGGER_RISING, "serial wakeup", NULL);
260
	if (ret) {
261
		gpio_free(gpio_nr);
262 263 264 265
		printk(KERN_ERR "No interrupt for UART wake GPIO: %i\n",
		       gpio_nr);
		return;
	}
D
David Brownell 已提交
266
	enable_irq_wake(gpio_to_irq(gpio_nr));
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
}

static int __init omap_serial_wakeup_init(void)
{
	if (!cpu_is_omap16xx())
		return 0;

	if (uart1_ck != NULL)
		omap_serial_set_port_wakeup(37);
	if (uart2_ck != NULL)
		omap_serial_set_port_wakeup(18);
	if (uart3_ck != NULL)
		omap_serial_set_port_wakeup(49);

	return 0;
}
late_initcall(omap_serial_wakeup_init);

#endif	/* CONFIG_OMAP_SERIAL_WAKE */

287 288 289 290 291
static int __init omap_init(void)
{
	return platform_device_register(&serial_device);
}
arch_initcall(omap_init);