2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-07-10 11:58:12 -07:00
|
|
|
/*
|
2006-10-03 14:01:26 -07:00
|
|
|
* linux/arch/arm/mach-omap1/serial.c
|
2005-07-10 11:58:12 -07:00
|
|
|
*
|
2006-12-06 18:13:56 -07:00
|
|
|
* OMAP1 serial support.
|
2005-07-10 11:58:12 -07:00
|
|
|
*/
|
2023-04-30 10:51:30 -07:00
|
|
|
#include <linux/gpio/machine.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
2005-07-10 11:58:12 -07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2006-07-01 14:32:35 -07:00
|
|
|
#include <linux/irq.h>
|
2005-07-10 11:58:12 -07:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/serial_8250.h>
|
|
|
|
#include <linux/serial_reg.h>
|
2006-01-07 09:15:52 -07:00
|
|
|
#include <linux/clk.h>
|
2008-09-06 04:10:45 -07:00
|
|
|
#include <linux/io.h>
|
2005-07-10 11:58:12 -07:00
|
|
|
|
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
2023-05-16 08:31:03 -07:00
|
|
|
#include "common.h"
|
2022-05-30 05:46:17 -07:00
|
|
|
#include "serial.h"
|
2019-08-06 07:16:03 -07:00
|
|
|
#include "mux.h"
|
2010-11-18 10:59:46 -07:00
|
|
|
#include "pm.h"
|
2015-05-21 14:50:23 -07:00
|
|
|
#include "soc.h"
|
2010-11-18 10:59:46 -07:00
|
|
|
|
2006-04-02 09:46:27 -07:00
|
|
|
static struct clk * uart1_ck;
|
|
|
|
static struct clk * uart2_ck;
|
|
|
|
static struct clk * uart3_ck;
|
2005-07-10 11:58:12 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2010-11-30 15:11:49 -07:00
|
|
|
omap_serial_outp(p, UART_OMAP_MDR1,
|
|
|
|
UART_OMAP_MDR1_DISABLE); /* disable UART */
|
2005-07-10 11:58:12 -07:00
|
|
|
omap_serial_outp(p, UART_OMAP_SCR, 0x08); /* TX watermark */
|
2010-11-30 15:11:49 -07:00
|
|
|
omap_serial_outp(p, UART_OMAP_MDR1,
|
|
|
|
UART_OMAP_MDR1_16X_MODE); /* enable UART */
|
2005-07-10 11:58:12 -07:00
|
|
|
|
2006-12-06 18:13:56 -07:00
|
|
|
if (!cpu_is_omap15xx()) {
|
2005-07-10 11:58:12 -07:00
|
|
|
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[] = {
|
|
|
|
{
|
2010-02-15 09:48:53 -07:00
|
|
|
.mapbase = OMAP1_UART1_BASE,
|
2005-07-10 11:58:12 -07:00
|
|
|
.irq = INT_UART1,
|
|
|
|
.flags = UPF_BOOT_AUTOCONF,
|
|
|
|
.iotype = UPIO_MEM,
|
|
|
|
.regshift = 2,
|
|
|
|
.uartclk = OMAP16XX_BASE_BAUD * 16,
|
|
|
|
},
|
|
|
|
{
|
2010-02-15 09:48:53 -07:00
|
|
|
.mapbase = OMAP1_UART2_BASE,
|
2005-07-10 11:58:12 -07:00
|
|
|
.irq = INT_UART2,
|
|
|
|
.flags = UPF_BOOT_AUTOCONF,
|
|
|
|
.iotype = UPIO_MEM,
|
|
|
|
.regshift = 2,
|
|
|
|
.uartclk = OMAP16XX_BASE_BAUD * 16,
|
|
|
|
},
|
|
|
|
{
|
2010-02-15 09:48:53 -07:00
|
|
|
.mapbase = OMAP1_UART3_BASE,
|
2005-07-10 11:58:12 -07:00
|
|
|
.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",
|
2005-09-08 08:04:41 -07:00
|
|
|
.id = PLAT8250_DEV_PLATFORM,
|
2005-07-10 11:58:12 -07:00
|
|
|
.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.
|
|
|
|
*/
|
2005-11-10 07:26:48 -07:00
|
|
|
void __init omap_serial_init(void)
|
2005-07-10 11:58:12 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-12-06 18:13:56 -07:00
|
|
|
if (cpu_is_omap15xx()) {
|
2005-07-10 11:58:12 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-22 11:10:47 -07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(serial_platform_data) - 1; i++) {
|
2009-10-16 09:53:00 -07:00
|
|
|
/* Static mapping, never released */
|
|
|
|
serial_platform_data[i].membase =
|
|
|
|
ioremap(serial_platform_data[i].mapbase, SZ_2K);
|
|
|
|
if (!serial_platform_data[i].membase) {
|
|
|
|
printk(KERN_ERR "Could not ioremap uart%i\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
2005-07-10 11:58:12 -07:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
uart1_ck = clk_get(NULL, "uart1_ck");
|
|
|
|
if (IS_ERR(uart1_ck))
|
|
|
|
printk("Could not get uart1_ck\n");
|
|
|
|
else {
|
2022-04-02 12:51:55 -07:00
|
|
|
clk_prepare_enable(uart1_ck);
|
2006-12-06 18:13:56 -07:00
|
|
|
if (cpu_is_omap15xx())
|
2005-07-10 11:58:12 -07:00
|
|
|
clk_set_rate(uart1_ck, 12000000);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
uart2_ck = clk_get(NULL, "uart2_ck");
|
|
|
|
if (IS_ERR(uart2_ck))
|
|
|
|
printk("Could not get uart2_ck\n");
|
|
|
|
else {
|
2022-04-02 12:51:55 -07:00
|
|
|
clk_prepare_enable(uart2_ck);
|
2006-12-06 18:13:56 -07:00
|
|
|
if (cpu_is_omap15xx())
|
2005-07-10 11:58:12 -07:00
|
|
|
clk_set_rate(uart2_ck, 12000000);
|
|
|
|
else
|
|
|
|
clk_set_rate(uart2_ck, 48000000);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
uart3_ck = clk_get(NULL, "uart3_ck");
|
|
|
|
if (IS_ERR(uart3_ck))
|
|
|
|
printk("Could not get uart3_ck\n");
|
|
|
|
else {
|
2022-04-02 12:51:55 -07:00
|
|
|
clk_prepare_enable(uart3_ck);
|
2006-12-06 18:13:56 -07:00
|
|
|
if (cpu_is_omap15xx())
|
2005-07-10 11:58:12 -07:00
|
|
|
clk_set_rate(uart3_ck, 12000000);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
omap_serial_reset(&serial_platform_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-08 15:07:38 -07:00
|
|
|
#ifdef CONFIG_OMAP_SERIAL_WAKE
|
|
|
|
|
2006-10-06 10:53:39 -07:00
|
|
|
static irqreturn_t omap_serial_wake_interrupt(int irq, void *dev_id)
|
2005-09-08 15:07:38 -07:00
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-30 10:51:30 -07:00
|
|
|
static void __init omap_serial_set_port_wakeup(int idx)
|
2005-09-08 15:07:38 -07:00
|
|
|
{
|
2023-04-30 10:51:30 -07:00
|
|
|
struct gpio_desc *d;
|
2005-09-08 15:07:38 -07:00
|
|
|
int ret;
|
|
|
|
|
2023-04-30 10:51:30 -07:00
|
|
|
d = gpiod_get_index(NULL, "wakeup", idx, GPIOD_IN);
|
|
|
|
if (IS_ERR(d)) {
|
|
|
|
pr_err("Unable to get UART wakeup GPIO descriptor\n");
|
2005-09-08 15:07:38 -07:00
|
|
|
return;
|
|
|
|
}
|
2023-04-30 10:51:30 -07:00
|
|
|
ret = request_irq(gpiod_to_irq(d), &omap_serial_wake_interrupt,
|
2006-07-02 17:20:05 -07:00
|
|
|
IRQF_TRIGGER_RISING, "serial wakeup", NULL);
|
2005-09-08 15:07:38 -07:00
|
|
|
if (ret) {
|
2023-04-30 10:51:30 -07:00
|
|
|
gpiod_put(d);
|
|
|
|
pr_err("No interrupt for UART%d wake GPIO\n", idx + 1);
|
2005-09-08 15:07:38 -07:00
|
|
|
return;
|
|
|
|
}
|
2023-04-30 10:51:30 -07:00
|
|
|
enable_irq_wake(gpiod_to_irq(d));
|
2005-09-08 15:07:38 -07:00
|
|
|
}
|
|
|
|
|
2023-04-30 10:51:30 -07:00
|
|
|
|
2012-04-25 22:49:29 -07:00
|
|
|
int __init omap_serial_wakeup_init(void)
|
2005-09-08 15:07:38 -07:00
|
|
|
{
|
|
|
|
if (!cpu_is_omap16xx())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (uart1_ck != NULL)
|
2023-04-30 10:51:30 -07:00
|
|
|
omap_serial_set_port_wakeup(0);
|
2005-09-08 15:07:38 -07:00
|
|
|
if (uart2_ck != NULL)
|
2023-04-30 10:51:30 -07:00
|
|
|
omap_serial_set_port_wakeup(1);
|
2005-09-08 15:07:38 -07:00
|
|
|
if (uart3_ck != NULL)
|
2023-04-30 10:51:30 -07:00
|
|
|
omap_serial_set_port_wakeup(2);
|
2005-09-08 15:07:38 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_OMAP_SERIAL_WAKE */
|
|
|
|
|
2005-07-10 11:58:12 -07:00
|
|
|
static int __init omap_init(void)
|
|
|
|
{
|
2010-12-10 10:46:24 -07:00
|
|
|
if (!cpu_class_is_omap1())
|
|
|
|
return -ENODEV;
|
|
|
|
|
2005-07-10 11:58:12 -07:00
|
|
|
return platform_device_register(&serial_device);
|
|
|
|
}
|
|
|
|
arch_initcall(omap_init);
|