blob: 73d3abe71e794c38ac7e39b3d98eec8538f4ebee [file] [log] [blame]
Robert Love04896a72009-06-22 18:43:11 +01001/*
Robert Love04896a72009-06-22 18:43:11 +01002 * Copyright (C) 2007 Google, Inc.
3 * Author: Robert Love <rlove@google.com>
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -08004 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
Robert Love04896a72009-06-22 18:43:11 +01005 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef __DRIVERS_SERIAL_MSM_SERIAL_H
17#define __DRIVERS_SERIAL_MSM_SERIAL_H
18
19#define UART_MR1 0x0000
20
21#define UART_MR1_AUTO_RFR_LEVEL0 0x3F
22#define UART_MR1_AUTO_RFR_LEVEL1 0x3FF00
23#define UART_MR1_RX_RDY_CTL (1 << 7)
24#define UART_MR1_CTS_CTL (1 << 6)
25
26#define UART_MR2 0x0004
27#define UART_MR2_ERROR_MODE (1 << 6)
28#define UART_MR2_BITS_PER_CHAR 0x30
29#define UART_MR2_BITS_PER_CHAR_5 (0x0 << 4)
30#define UART_MR2_BITS_PER_CHAR_6 (0x1 << 4)
31#define UART_MR2_BITS_PER_CHAR_7 (0x2 << 4)
32#define UART_MR2_BITS_PER_CHAR_8 (0x3 << 4)
33#define UART_MR2_STOP_BIT_LEN_ONE (0x1 << 2)
34#define UART_MR2_STOP_BIT_LEN_TWO (0x3 << 2)
35#define UART_MR2_PARITY_MODE_NONE 0x0
36#define UART_MR2_PARITY_MODE_ODD 0x1
37#define UART_MR2_PARITY_MODE_EVEN 0x2
38#define UART_MR2_PARITY_MODE_SPACE 0x3
39#define UART_MR2_PARITY_MODE 0x3
40
Stephen Boyd6909dad2013-07-24 11:37:30 -070041#define UART_CSR 0x0008
Robert Love04896a72009-06-22 18:43:11 +010042
43#define UART_TF 0x000C
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -080044#define UARTDM_TF 0x0070
Robert Love04896a72009-06-22 18:43:11 +010045
46#define UART_CR 0x0010
47#define UART_CR_CMD_NULL (0 << 4)
48#define UART_CR_CMD_RESET_RX (1 << 4)
49#define UART_CR_CMD_RESET_TX (2 << 4)
50#define UART_CR_CMD_RESET_ERR (3 << 4)
51#define UART_CR_CMD_RESET_BREAK_INT (4 << 4)
52#define UART_CR_CMD_START_BREAK (5 << 4)
53#define UART_CR_CMD_STOP_BREAK (6 << 4)
54#define UART_CR_CMD_RESET_CTS (7 << 4)
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -080055#define UART_CR_CMD_RESET_STALE_INT (8 << 4)
Robert Love04896a72009-06-22 18:43:11 +010056#define UART_CR_CMD_PACKET_MODE (9 << 4)
57#define UART_CR_CMD_MODE_RESET (12 << 4)
58#define UART_CR_CMD_SET_RFR (13 << 4)
59#define UART_CR_CMD_RESET_RFR (14 << 4)
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -080060#define UART_CR_CMD_PROTECTION_EN (16 << 4)
61#define UART_CR_CMD_STALE_EVENT_ENABLE (80 << 4)
Stephen Boydf7e54d72014-01-14 12:34:55 -080062#define UART_CR_CMD_FORCE_STALE (4 << 8)
Stephen Boyd4a5662d2013-07-24 11:37:28 -070063#define UART_CR_CMD_RESET_TX_READY (3 << 8)
Robert Love04896a72009-06-22 18:43:11 +010064#define UART_CR_TX_DISABLE (1 << 3)
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -080065#define UART_CR_TX_ENABLE (1 << 2)
66#define UART_CR_RX_DISABLE (1 << 1)
67#define UART_CR_RX_ENABLE (1 << 0)
Robert Love04896a72009-06-22 18:43:11 +010068
69#define UART_IMR 0x0014
70#define UART_IMR_TXLEV (1 << 0)
71#define UART_IMR_RXSTALE (1 << 3)
72#define UART_IMR_RXLEV (1 << 4)
73#define UART_IMR_DELTA_CTS (1 << 5)
74#define UART_IMR_CURRENT_CTS (1 << 6)
75
76#define UART_IPR_RXSTALE_LAST 0x20
77#define UART_IPR_STALE_LSB 0x1F
78#define UART_IPR_STALE_TIMEOUT_MSB 0x3FF80
79
80#define UART_IPR 0x0018
81#define UART_TFWR 0x001C
82#define UART_RFWR 0x0020
83#define UART_HCR 0x0024
84
85#define UART_MREG 0x0028
86#define UART_NREG 0x002C
87#define UART_DREG 0x0030
88#define UART_MNDREG 0x0034
89#define UART_IRDA 0x0038
90#define UART_MISR_MODE 0x0040
91#define UART_MISR_RESET 0x0044
92#define UART_MISR_EXPORT 0x0048
93#define UART_MISR_VAL 0x004C
94#define UART_TEST_CTRL 0x0050
95
96#define UART_SR 0x0008
97#define UART_SR_HUNT_CHAR (1 << 7)
98#define UART_SR_RX_BREAK (1 << 6)
99#define UART_SR_PAR_FRAME_ERR (1 << 5)
100#define UART_SR_OVERRUN (1 << 4)
101#define UART_SR_TX_EMPTY (1 << 3)
102#define UART_SR_TX_READY (1 << 2)
103#define UART_SR_RX_FULL (1 << 1)
104#define UART_SR_RX_READY (1 << 0)
105
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -0800106#define UART_RF 0x000C
107#define UARTDM_RF 0x0070
108#define UART_MISR 0x0010
109#define UART_ISR 0x0014
110#define UART_ISR_TX_READY (1 << 7)
111
Stephen Boydf7e54d72014-01-14 12:34:55 -0800112#define UARTDM_RXFS 0x50
113#define UARTDM_RXFS_BUF_SHIFT 0x7
114#define UARTDM_RXFS_BUF_MASK 0x7
115
116#define UARTDM_DMEN 0x3C
117#define UARTDM_DMEN_RX_SC_ENABLE BIT(5)
118#define UARTDM_DMEN_TX_SC_ENABLE BIT(4)
119
Stepan Moskovchenkoec8f29e2010-12-21 12:38:05 -0800120#define UARTDM_DMRX 0x34
121#define UARTDM_NCF_TX 0x40
122#define UARTDM_RX_TOTAL_SNAP 0x38
Robert Love04896a72009-06-22 18:43:11 +0100123
Abhijeet Dharmapurikar18c79d72010-05-20 15:20:23 -0700124#define UART_TO_MSM(uart_port) ((struct msm_port *) uart_port)
125
126static inline
127void msm_write(struct uart_port *port, unsigned int val, unsigned int off)
128{
Stephen Boyd68252422014-06-30 14:54:01 -0700129 writel_relaxed(val, port->membase + off);
Abhijeet Dharmapurikar18c79d72010-05-20 15:20:23 -0700130}
131
132static inline
133unsigned int msm_read(struct uart_port *port, unsigned int off)
134{
Stephen Boyd68252422014-06-30 14:54:01 -0700135 return readl_relaxed(port->membase + off);
Abhijeet Dharmapurikar18c79d72010-05-20 15:20:23 -0700136}
137
138/*
139 * Setup the MND registers to use the TCXO clock.
140 */
141static inline void msm_serial_set_mnd_regs_tcxo(struct uart_port *port)
142{
143 msm_write(port, 0x06, UART_MREG);
144 msm_write(port, 0xF1, UART_NREG);
145 msm_write(port, 0x0F, UART_DREG);
146 msm_write(port, 0x1A, UART_MNDREG);
Stephen Boyd6909dad2013-07-24 11:37:30 -0700147 port->uartclk = 1843200;
Abhijeet Dharmapurikar18c79d72010-05-20 15:20:23 -0700148}
149
150/*
151 * Setup the MND registers to use the TCXO clock divided by 4.
152 */
153static inline void msm_serial_set_mnd_regs_tcxoby4(struct uart_port *port)
154{
155 msm_write(port, 0x18, UART_MREG);
156 msm_write(port, 0xF6, UART_NREG);
157 msm_write(port, 0x0F, UART_DREG);
158 msm_write(port, 0x0A, UART_MNDREG);
Stephen Boyd6909dad2013-07-24 11:37:30 -0700159 port->uartclk = 1843200;
Abhijeet Dharmapurikar18c79d72010-05-20 15:20:23 -0700160}
161
162static inline
163void msm_serial_set_mnd_regs_from_uartclk(struct uart_port *port)
164{
165 if (port->uartclk == 19200000)
166 msm_serial_set_mnd_regs_tcxo(port);
Stephen Boyd6909dad2013-07-24 11:37:30 -0700167 else if (port->uartclk == 4800000)
Abhijeet Dharmapurikar18c79d72010-05-20 15:20:23 -0700168 msm_serial_set_mnd_regs_tcxoby4(port);
169}
170
171/*
172 * TROUT has a specific defect that makes it report it's uartclk
173 * as 19.2Mhz (TCXO) when it's actually 4.8Mhz (TCXO/4). This special
174 * cases TROUT to use the right clock.
175 */
176#ifdef CONFIG_MACH_TROUT
177#define msm_serial_set_mnd_regs msm_serial_set_mnd_regs_tcxoby4
178#else
179#define msm_serial_set_mnd_regs msm_serial_set_mnd_regs_from_uartclk
180#endif
181
Robert Love04896a72009-06-22 18:43:11 +0100182#endif /* __DRIVERS_SERIAL_MSM_SERIAL_H */