Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 2 | /* |
| 3 | * TI DaVinci serial driver |
| 4 | * |
| 5 | * Copyright (C) 2006 Texas Instruments. |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 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> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 15 | #include <linux/io.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 16 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 17 | #include <mach/serial.h> |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 18 | #include <mach/cputype.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 19 | |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 20 | static inline void serial_write_reg(struct plat_serial8250_port *p, int offset, |
| 21 | int value) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 22 | { |
| 23 | offset <<= p->regshift; |
Cyril Chemparathy | 9ee1ace | 2010-05-02 14:28:13 -0400 | [diff] [blame] | 24 | |
| 25 | WARN_ONCE(!p->membase, "unmapped write: uart[%d]\n", offset); |
| 26 | |
| 27 | __raw_writel(value, p->membase + offset); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 28 | } |
| 29 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 30 | static void __init davinci_serial_reset(struct plat_serial8250_port *p) |
| 31 | { |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 32 | unsigned int pwremu = 0; |
| 33 | |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 34 | serial_write_reg(p, UART_IER, 0); /* disable all interrupts */ |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 35 | |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 36 | /* reset both transmitter and receiver: bits 14,13 = UTRST, URRST */ |
| 37 | serial_write_reg(p, UART_DAVINCI_PWREMU, pwremu); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 38 | mdelay(10); |
| 39 | |
| 40 | pwremu |= (0x3 << 13); |
| 41 | pwremu |= 0x1; |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 42 | serial_write_reg(p, UART_DAVINCI_PWREMU, pwremu); |
| 43 | |
| 44 | if (cpu_is_davinci_dm646x()) |
| 45 | serial_write_reg(p, UART_DM646X_SCR, |
| 46 | UART_DM646X_SCR_TX_WATERMARK); |
| 47 | } |
| 48 | |
Manjunathappa, Prakash | fcf7157 | 2013-06-19 14:45:42 +0530 | [diff] [blame] | 49 | int __init davinci_serial_init(struct platform_device *serial_dev) |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 50 | { |
Manjunathappa, Prakash | 19955c3 | 2013-06-19 14:45:38 +0530 | [diff] [blame] | 51 | int i, ret = 0; |
Manjunathappa, Prakash | 19955c3 | 2013-06-19 14:45:38 +0530 | [diff] [blame] | 52 | struct device *dev; |
| 53 | struct plat_serial8250_port *p; |
Manjunathappa, Prakash | 323761bb | 2013-06-19 14:45:42 +0530 | [diff] [blame] | 54 | struct clk *clk; |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * Make sure the serial ports are muxed on at this point. |
Mark A. Greer | 65e866a | 2009-03-18 12:36:08 -0500 | [diff] [blame] | 58 | * You have to mux them off in device drivers later on if not needed. |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 59 | */ |
Manjunathappa, Prakash | fcf7157 | 2013-06-19 14:45:42 +0530 | [diff] [blame] | 60 | for (i = 0; serial_dev[i].dev.platform_data != NULL; i++) { |
| 61 | dev = &serial_dev[i].dev; |
Manjunathappa, Prakash | 19955c3 | 2013-06-19 14:45:38 +0530 | [diff] [blame] | 62 | p = dev->platform_data; |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 63 | |
Manjunathappa, Prakash | fcf7157 | 2013-06-19 14:45:42 +0530 | [diff] [blame] | 64 | ret = platform_device_register(&serial_dev[i]); |
Manjunathappa, Prakash | 19955c3 | 2013-06-19 14:45:38 +0530 | [diff] [blame] | 65 | if (ret) |
| 66 | continue; |
| 67 | |
Manjunathappa, Prakash | 323761bb | 2013-06-19 14:45:42 +0530 | [diff] [blame] | 68 | clk = clk_get(dev, NULL); |
| 69 | if (IS_ERR(clk)) { |
| 70 | pr_err("%s:%d: failed to get UART%d clock\n", |
| 71 | __func__, __LINE__, i); |
Cyril Chemparathy | 9ee1ace | 2010-05-02 14:28:13 -0400 | [diff] [blame] | 72 | continue; |
Manjunathappa, Prakash | 323761bb | 2013-06-19 14:45:42 +0530 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | clk_prepare_enable(clk); |
| 76 | |
| 77 | p->uartclk = clk_get_rate(clk); |
Cyril Chemparathy | 9ee1ace | 2010-05-02 14:28:13 -0400 | [diff] [blame] | 78 | |
| 79 | if (!p->membase && p->mapbase) { |
| 80 | p->membase = ioremap(p->mapbase, SZ_4K); |
| 81 | |
| 82 | if (p->membase) |
| 83 | p->flags &= ~UPF_IOREMAP; |
| 84 | else |
| 85 | pr_err("uart regs ioremap failed\n"); |
| 86 | } |
| 87 | |
Cyril Chemparathy | e280000 | 2010-05-02 14:28:14 -0400 | [diff] [blame] | 88 | if (p->membase && p->type != PORT_AR7) |
Cyril Chemparathy | 9ee1ace | 2010-05-02 14:28:13 -0400 | [diff] [blame] | 89 | davinci_serial_reset(p); |
Kevin Hilman | 617b925 | 2009-04-14 08:04:26 -0500 | [diff] [blame] | 90 | } |
Manjunathappa, Prakash | 19955c3 | 2013-06-19 14:45:38 +0530 | [diff] [blame] | 91 | return ret; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 92 | } |