1f577ffd7STony Lindgren /* 2f30c2269SUwe Zeisberger * linux/arch/arm/mach-omap1/serial.c 3f577ffd7STony Lindgren * 465d873caSMarek Vašut * OMAP1 serial support. 5f577ffd7STony Lindgren * 6f577ffd7STony Lindgren * This program is free software; you can redistribute it and/or modify 7f577ffd7STony Lindgren * it under the terms of the GNU General Public License version 2 as 8f577ffd7STony Lindgren * published by the Free Software Foundation. 9f577ffd7STony Lindgren */ 10*2f8163baSRussell King #include <linux/gpio.h> 11f577ffd7STony Lindgren #include <linux/module.h> 12f577ffd7STony Lindgren #include <linux/kernel.h> 13f577ffd7STony Lindgren #include <linux/init.h> 14d533c128SThomas Gleixner #include <linux/irq.h> 15f577ffd7STony Lindgren #include <linux/delay.h> 16f577ffd7STony Lindgren #include <linux/serial.h> 17f577ffd7STony Lindgren #include <linux/tty.h> 18f577ffd7STony Lindgren #include <linux/serial_8250.h> 19f577ffd7STony Lindgren #include <linux/serial_reg.h> 20f8ce2547SRussell King #include <linux/clk.h> 21fced80c7SRussell King #include <linux/io.h> 22f577ffd7STony Lindgren 23f577ffd7STony Lindgren #include <asm/mach-types.h> 24f577ffd7STony Lindgren 25ce491cf8STony Lindgren #include <plat/board.h> 26ce491cf8STony Lindgren #include <plat/mux.h> 27ce491cf8STony Lindgren #include <plat/fpga.h> 28f577ffd7STony Lindgren 29706afddaSAaro Koskinen #include "pm.h" 30706afddaSAaro Koskinen 31120db2cbSTony Lindgren static struct clk * uart1_ck; 32120db2cbSTony Lindgren static struct clk * uart2_ck; 33120db2cbSTony Lindgren static struct clk * uart3_ck; 34f577ffd7STony Lindgren 35f577ffd7STony Lindgren static inline unsigned int omap_serial_in(struct plat_serial8250_port *up, 36f577ffd7STony Lindgren int offset) 37f577ffd7STony Lindgren { 38f577ffd7STony Lindgren offset <<= up->regshift; 39f577ffd7STony Lindgren return (unsigned int)__raw_readb(up->membase + offset); 40f577ffd7STony Lindgren } 41f577ffd7STony Lindgren 42f577ffd7STony Lindgren static inline void omap_serial_outp(struct plat_serial8250_port *p, int offset, 43f577ffd7STony Lindgren int value) 44f577ffd7STony Lindgren { 45f577ffd7STony Lindgren offset <<= p->regshift; 46f577ffd7STony Lindgren __raw_writeb(value, p->membase + offset); 47f577ffd7STony Lindgren } 48f577ffd7STony Lindgren 49f577ffd7STony Lindgren /* 50f577ffd7STony Lindgren * Internal UARTs need to be initialized for the 8250 autoconfig to work 51f577ffd7STony Lindgren * properly. Note that the TX watermark initialization may not be needed 52f577ffd7STony Lindgren * once the 8250.c watermark handling code is merged. 53f577ffd7STony Lindgren */ 54f577ffd7STony Lindgren static void __init omap_serial_reset(struct plat_serial8250_port *p) 55f577ffd7STony Lindgren { 56498cb951SAndrei Emeltchenko omap_serial_outp(p, UART_OMAP_MDR1, 57498cb951SAndrei Emeltchenko UART_OMAP_MDR1_DISABLE); /* disable UART */ 58f577ffd7STony Lindgren omap_serial_outp(p, UART_OMAP_SCR, 0x08); /* TX watermark */ 59498cb951SAndrei Emeltchenko omap_serial_outp(p, UART_OMAP_MDR1, 60498cb951SAndrei Emeltchenko UART_OMAP_MDR1_16X_MODE); /* enable UART */ 61f577ffd7STony Lindgren 6265d873caSMarek Vašut if (!cpu_is_omap15xx()) { 63f577ffd7STony Lindgren omap_serial_outp(p, UART_OMAP_SYSC, 0x01); 64f577ffd7STony Lindgren while (!(omap_serial_in(p, UART_OMAP_SYSC) & 0x01)); 65f577ffd7STony Lindgren } 66f577ffd7STony Lindgren } 67f577ffd7STony Lindgren 68f577ffd7STony Lindgren static struct plat_serial8250_port serial_platform_data[] = { 69f577ffd7STony Lindgren { 704f2c49feSTony Lindgren .mapbase = OMAP1_UART1_BASE, 71f577ffd7STony Lindgren .irq = INT_UART1, 72f577ffd7STony Lindgren .flags = UPF_BOOT_AUTOCONF, 73f577ffd7STony Lindgren .iotype = UPIO_MEM, 74f577ffd7STony Lindgren .regshift = 2, 75f577ffd7STony Lindgren .uartclk = OMAP16XX_BASE_BAUD * 16, 76f577ffd7STony Lindgren }, 77f577ffd7STony Lindgren { 784f2c49feSTony Lindgren .mapbase = OMAP1_UART2_BASE, 79f577ffd7STony Lindgren .irq = INT_UART2, 80f577ffd7STony Lindgren .flags = UPF_BOOT_AUTOCONF, 81f577ffd7STony Lindgren .iotype = UPIO_MEM, 82f577ffd7STony Lindgren .regshift = 2, 83f577ffd7STony Lindgren .uartclk = OMAP16XX_BASE_BAUD * 16, 84f577ffd7STony Lindgren }, 85f577ffd7STony Lindgren { 864f2c49feSTony Lindgren .mapbase = OMAP1_UART3_BASE, 87f577ffd7STony Lindgren .irq = INT_UART3, 88f577ffd7STony Lindgren .flags = UPF_BOOT_AUTOCONF, 89f577ffd7STony Lindgren .iotype = UPIO_MEM, 90f577ffd7STony Lindgren .regshift = 2, 91f577ffd7STony Lindgren .uartclk = OMAP16XX_BASE_BAUD * 16, 92f577ffd7STony Lindgren }, 93f577ffd7STony Lindgren { }, 94f577ffd7STony Lindgren }; 95f577ffd7STony Lindgren 96f577ffd7STony Lindgren static struct platform_device serial_device = { 97f577ffd7STony Lindgren .name = "serial8250", 986df29debSRussell King .id = PLAT8250_DEV_PLATFORM, 99f577ffd7STony Lindgren .dev = { 100f577ffd7STony Lindgren .platform_data = serial_platform_data, 101f577ffd7STony Lindgren }, 102f577ffd7STony Lindgren }; 103f577ffd7STony Lindgren 104f577ffd7STony Lindgren /* 105f577ffd7STony Lindgren * Note that on Innovator-1510 UART2 pins conflict with USB2. 106f577ffd7STony Lindgren * By default UART2 does not work on Innovator-1510 if you have 107f577ffd7STony Lindgren * USB OHCI enabled. To use UART2, you must disable USB2 first. 108f577ffd7STony Lindgren */ 1093179a019STony Lindgren void __init omap_serial_init(void) 110f577ffd7STony Lindgren { 111f577ffd7STony Lindgren int i; 112f577ffd7STony Lindgren 113d8723ae2SAlistair Buxton if (cpu_is_omap7xx()) { 114f577ffd7STony Lindgren serial_platform_data[0].regshift = 0; 115f577ffd7STony Lindgren serial_platform_data[1].regshift = 0; 116372b1c32SAlistair Buxton serial_platform_data[0].irq = INT_7XX_UART_MODEM_1; 117372b1c32SAlistair Buxton serial_platform_data[1].irq = INT_7XX_UART_MODEM_IRDA_2; 11856739a69SZebediah C. McClure } 11956739a69SZebediah C. McClure 12065d873caSMarek Vašut if (cpu_is_omap15xx()) { 121f577ffd7STony Lindgren serial_platform_data[0].uartclk = OMAP1510_BASE_BAUD * 16; 122f577ffd7STony Lindgren serial_platform_data[1].uartclk = OMAP1510_BASE_BAUD * 16; 123f577ffd7STony Lindgren serial_platform_data[2].uartclk = OMAP1510_BASE_BAUD * 16; 124f577ffd7STony Lindgren } 125f577ffd7STony Lindgren 1269d30b99fSAlexander Shishkin for (i = 0; i < ARRAY_SIZE(serial_platform_data) - 1; i++) { 127f577ffd7STony Lindgren 1288b8fbd39SCory Maccarrone /* Don't look at UARTs higher than 2 for omap7xx */ 1298b8fbd39SCory Maccarrone if (cpu_is_omap7xx() && i > 1) { 1308b8fbd39SCory Maccarrone serial_platform_data[i].membase = NULL; 1318b8fbd39SCory Maccarrone serial_platform_data[i].mapbase = 0; 1328b8fbd39SCory Maccarrone continue; 1338b8fbd39SCory Maccarrone } 1348b8fbd39SCory Maccarrone 13584f90c9cSTony Lindgren /* Static mapping, never released */ 13684f90c9cSTony Lindgren serial_platform_data[i].membase = 13784f90c9cSTony Lindgren ioremap(serial_platform_data[i].mapbase, SZ_2K); 13884f90c9cSTony Lindgren if (!serial_platform_data[i].membase) { 13984f90c9cSTony Lindgren printk(KERN_ERR "Could not ioremap uart%i\n", i); 14084f90c9cSTony Lindgren continue; 14184f90c9cSTony Lindgren } 142f577ffd7STony Lindgren switch (i) { 143f577ffd7STony Lindgren case 0: 144f577ffd7STony Lindgren uart1_ck = clk_get(NULL, "uart1_ck"); 145f577ffd7STony Lindgren if (IS_ERR(uart1_ck)) 146f577ffd7STony Lindgren printk("Could not get uart1_ck\n"); 147f577ffd7STony Lindgren else { 14830ff720bSTony Lindgren clk_enable(uart1_ck); 14965d873caSMarek Vašut if (cpu_is_omap15xx()) 150f577ffd7STony Lindgren clk_set_rate(uart1_ck, 12000000); 151f577ffd7STony Lindgren } 152f577ffd7STony Lindgren break; 153f577ffd7STony Lindgren case 1: 154f577ffd7STony Lindgren uart2_ck = clk_get(NULL, "uart2_ck"); 155f577ffd7STony Lindgren if (IS_ERR(uart2_ck)) 156f577ffd7STony Lindgren printk("Could not get uart2_ck\n"); 157f577ffd7STony Lindgren else { 15830ff720bSTony Lindgren clk_enable(uart2_ck); 15965d873caSMarek Vašut if (cpu_is_omap15xx()) 160f577ffd7STony Lindgren clk_set_rate(uart2_ck, 12000000); 161f577ffd7STony Lindgren else 162f577ffd7STony Lindgren clk_set_rate(uart2_ck, 48000000); 163f577ffd7STony Lindgren } 164f577ffd7STony Lindgren break; 165f577ffd7STony Lindgren case 2: 166f577ffd7STony Lindgren uart3_ck = clk_get(NULL, "uart3_ck"); 167f577ffd7STony Lindgren if (IS_ERR(uart3_ck)) 168f577ffd7STony Lindgren printk("Could not get uart3_ck\n"); 169f577ffd7STony Lindgren else { 17030ff720bSTony Lindgren clk_enable(uart3_ck); 17165d873caSMarek Vašut if (cpu_is_omap15xx()) 172f577ffd7STony Lindgren clk_set_rate(uart3_ck, 12000000); 173f577ffd7STony Lindgren } 174f577ffd7STony Lindgren break; 175f577ffd7STony Lindgren } 176f577ffd7STony Lindgren omap_serial_reset(&serial_platform_data[i]); 177f577ffd7STony Lindgren } 178f577ffd7STony Lindgren } 179f577ffd7STony Lindgren 1807c38cf02STony Lindgren #ifdef CONFIG_OMAP_SERIAL_WAKE 1817c38cf02STony Lindgren 1820cd61b68SLinus Torvalds static irqreturn_t omap_serial_wake_interrupt(int irq, void *dev_id) 1837c38cf02STony Lindgren { 1847c38cf02STony Lindgren /* Need to do something with serial port right after wake-up? */ 1857c38cf02STony Lindgren return IRQ_HANDLED; 1867c38cf02STony Lindgren } 1877c38cf02STony Lindgren 1887c38cf02STony Lindgren /* 1897c38cf02STony Lindgren * Reroutes serial RX lines to GPIO lines for the duration of 1907c38cf02STony Lindgren * sleep to allow waking up the device from serial port even 1917c38cf02STony Lindgren * in deep sleep. 1927c38cf02STony Lindgren */ 1937c38cf02STony Lindgren void omap_serial_wake_trigger(int enable) 1947c38cf02STony Lindgren { 1957c38cf02STony Lindgren if (!cpu_is_omap16xx()) 1967c38cf02STony Lindgren return; 1977c38cf02STony Lindgren 1987c38cf02STony Lindgren if (uart1_ck != NULL) { 1997c38cf02STony Lindgren if (enable) 2007c38cf02STony Lindgren omap_cfg_reg(V14_16XX_GPIO37); 2017c38cf02STony Lindgren else 2027c38cf02STony Lindgren omap_cfg_reg(V14_16XX_UART1_RX); 2037c38cf02STony Lindgren } 2047c38cf02STony Lindgren if (uart2_ck != NULL) { 2057c38cf02STony Lindgren if (enable) 2067c38cf02STony Lindgren omap_cfg_reg(R9_16XX_GPIO18); 2077c38cf02STony Lindgren else 2087c38cf02STony Lindgren omap_cfg_reg(R9_16XX_UART2_RX); 2097c38cf02STony Lindgren } 2107c38cf02STony Lindgren if (uart3_ck != NULL) { 2117c38cf02STony Lindgren if (enable) 2127c38cf02STony Lindgren omap_cfg_reg(L14_16XX_GPIO49); 2137c38cf02STony Lindgren else 2147c38cf02STony Lindgren omap_cfg_reg(L14_16XX_UART3_RX); 2157c38cf02STony Lindgren } 2167c38cf02STony Lindgren } 2177c38cf02STony Lindgren 2187c38cf02STony Lindgren static void __init omap_serial_set_port_wakeup(int gpio_nr) 2197c38cf02STony Lindgren { 2207c38cf02STony Lindgren int ret; 2217c38cf02STony Lindgren 222f2d18feaSJarkko Nikula ret = gpio_request(gpio_nr, "UART wake"); 2237c38cf02STony Lindgren if (ret < 0) { 2247c38cf02STony Lindgren printk(KERN_ERR "Could not request UART wake GPIO: %i\n", 2257c38cf02STony Lindgren gpio_nr); 2267c38cf02STony Lindgren return; 2277c38cf02STony Lindgren } 22840e3925bSDavid Brownell gpio_direction_input(gpio_nr); 22915f74b03SDavid Brownell ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt, 23052e405eaSThomas Gleixner IRQF_TRIGGER_RISING, "serial wakeup", NULL); 2317c38cf02STony Lindgren if (ret) { 232f2d18feaSJarkko Nikula gpio_free(gpio_nr); 2337c38cf02STony Lindgren printk(KERN_ERR "No interrupt for UART wake GPIO: %i\n", 2347c38cf02STony Lindgren gpio_nr); 2357c38cf02STony Lindgren return; 2367c38cf02STony Lindgren } 23715f74b03SDavid Brownell enable_irq_wake(gpio_to_irq(gpio_nr)); 2387c38cf02STony Lindgren } 2397c38cf02STony Lindgren 2407c38cf02STony Lindgren static int __init omap_serial_wakeup_init(void) 2417c38cf02STony Lindgren { 2427c38cf02STony Lindgren if (!cpu_is_omap16xx()) 2437c38cf02STony Lindgren return 0; 2447c38cf02STony Lindgren 2457c38cf02STony Lindgren if (uart1_ck != NULL) 2467c38cf02STony Lindgren omap_serial_set_port_wakeup(37); 2477c38cf02STony Lindgren if (uart2_ck != NULL) 2487c38cf02STony Lindgren omap_serial_set_port_wakeup(18); 2497c38cf02STony Lindgren if (uart3_ck != NULL) 2507c38cf02STony Lindgren omap_serial_set_port_wakeup(49); 2517c38cf02STony Lindgren 2527c38cf02STony Lindgren return 0; 2537c38cf02STony Lindgren } 2547c38cf02STony Lindgren late_initcall(omap_serial_wakeup_init); 2557c38cf02STony Lindgren 2567c38cf02STony Lindgren #endif /* CONFIG_OMAP_SERIAL_WAKE */ 2577c38cf02STony Lindgren 258f577ffd7STony Lindgren static int __init omap_init(void) 259f577ffd7STony Lindgren { 2607f9187c2STony Lindgren if (!cpu_class_is_omap1()) 2617f9187c2STony Lindgren return -ENODEV; 2627f9187c2STony Lindgren 263f577ffd7STony Lindgren return platform_device_register(&serial_device); 264f577ffd7STony Lindgren } 265f577ffd7STony Lindgren arch_initcall(omap_init); 266