1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * TI DaVinci serial driver
5 * Copyright (C) 2006 Texas Instruments.
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/serial_8250.h>
11 #include <linux/serial_reg.h>
12 #include <linux/platform_device.h>
13 #include <linux/delay.h>
14 #include <linux/clk.h>
17 #include <mach/serial.h>
18 #include <mach/cputype.h>
20 static inline void serial_write_reg(struct plat_serial8250_port
*p
, int offset
,
23 offset
<<= p
->regshift
;
25 WARN_ONCE(!p
->membase
, "unmapped write: uart[%d]\n", offset
);
27 __raw_writel(value
, p
->membase
+ offset
);
30 static void __init
davinci_serial_reset(struct plat_serial8250_port
*p
)
32 unsigned int pwremu
= 0;
34 serial_write_reg(p
, UART_IER
, 0); /* disable all interrupts */
36 /* reset both transmitter and receiver: bits 14,13 = UTRST, URRST */
37 serial_write_reg(p
, UART_DAVINCI_PWREMU
, pwremu
);
40 pwremu
|= (0x3 << 13);
42 serial_write_reg(p
, UART_DAVINCI_PWREMU
, pwremu
);
44 if (cpu_is_davinci_dm646x())
45 serial_write_reg(p
, UART_DM646X_SCR
,
46 UART_DM646X_SCR_TX_WATERMARK
);
49 int __init
davinci_serial_init(struct platform_device
*serial_dev
)
53 struct plat_serial8250_port
*p
;
57 * Make sure the serial ports are muxed on at this point.
58 * You have to mux them off in device drivers later on if not needed.
60 for (i
= 0; serial_dev
[i
].dev
.platform_data
!= NULL
; i
++) {
61 dev
= &serial_dev
[i
].dev
;
62 p
= dev
->platform_data
;
64 ret
= platform_device_register(&serial_dev
[i
]);
68 clk
= clk_get(dev
, NULL
);
70 pr_err("%s:%d: failed to get UART%d clock\n",
71 __func__
, __LINE__
, i
);
75 clk_prepare_enable(clk
);
77 p
->uartclk
= clk_get_rate(clk
);
79 if (!p
->membase
&& p
->mapbase
) {
80 p
->membase
= ioremap(p
->mapbase
, SZ_4K
);
83 p
->flags
&= ~UPF_IOREMAP
;
85 pr_err("uart regs ioremap failed\n");
88 if (p
->membase
&& p
->type
!= PORT_AR7
)
89 davinci_serial_reset(p
);