.. | .. |
---|
7 | 7 | * Based on sc26xx.c, by Thomas Bogendörfer (tsbogend@alpha.franken.de) |
---|
8 | 8 | */ |
---|
9 | 9 | |
---|
10 | | -#if defined(CONFIG_SERIAL_SCCNXP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
---|
11 | | -#define SUPPORT_SYSRQ |
---|
12 | | -#endif |
---|
13 | | - |
---|
14 | 10 | #include <linux/clk.h> |
---|
| 11 | +#include <linux/delay.h> |
---|
15 | 12 | #include <linux/err.h> |
---|
16 | 13 | #include <linux/module.h> |
---|
17 | 14 | #include <linux/mod_devicetable.h> |
---|
.. | .. |
---|
47 | 44 | # define MR2_STOP1 (7 << 0) |
---|
48 | 45 | # define MR2_STOP2 (0xf << 0) |
---|
49 | 46 | #define SCCNXP_SR_REG (0x01) |
---|
50 | | -#define SCCNXP_CSR_REG SCCNXP_SR_REG |
---|
51 | 47 | # define SR_RXRDY (1 << 0) |
---|
52 | 48 | # define SR_FULL (1 << 1) |
---|
53 | 49 | # define SR_TXRDY (1 << 2) |
---|
.. | .. |
---|
56 | 52 | # define SR_PE (1 << 5) |
---|
57 | 53 | # define SR_FE (1 << 6) |
---|
58 | 54 | # define SR_BRK (1 << 7) |
---|
| 55 | +#define SCCNXP_CSR_REG (SCCNXP_SR_REG) |
---|
| 56 | +# define CSR_TIMER_MODE (0x0d) |
---|
59 | 57 | #define SCCNXP_CR_REG (0x02) |
---|
60 | 58 | # define CR_RX_ENABLE (1 << 0) |
---|
61 | 59 | # define CR_RX_DISABLE (1 << 1) |
---|
.. | .. |
---|
82 | 80 | # define IMR_RXRDY (1 << 1) |
---|
83 | 81 | # define ISR_TXRDY(x) (1 << ((x * 4) + 0)) |
---|
84 | 82 | # define ISR_RXRDY(x) (1 << ((x * 4) + 1)) |
---|
| 83 | +#define SCCNXP_CTPU_REG (0x06) |
---|
| 84 | +#define SCCNXP_CTPL_REG (0x07) |
---|
85 | 85 | #define SCCNXP_IPR_REG (0x0d) |
---|
86 | 86 | #define SCCNXP_OPCR_REG SCCNXP_IPR_REG |
---|
87 | 87 | #define SCCNXP_SOP_REG (0x0e) |
---|
| 88 | +#define SCCNXP_START_COUNTER_REG SCCNXP_SOP_REG |
---|
88 | 89 | #define SCCNXP_ROP_REG (0x0f) |
---|
89 | 90 | |
---|
90 | 91 | /* Route helpers */ |
---|
.. | .. |
---|
103 | 104 | unsigned long freq_max; |
---|
104 | 105 | unsigned int flags; |
---|
105 | 106 | unsigned int fifosize; |
---|
| 107 | + /* Time between read/write cycles */ |
---|
| 108 | + unsigned int trwd; |
---|
106 | 109 | }; |
---|
107 | 110 | |
---|
108 | 111 | struct sccnxp_port { |
---|
.. | .. |
---|
137 | 140 | .freq_max = 4000000, |
---|
138 | 141 | .flags = SCCNXP_HAVE_IO, |
---|
139 | 142 | .fifosize = 3, |
---|
| 143 | + .trwd = 200, |
---|
140 | 144 | }; |
---|
141 | 145 | |
---|
142 | 146 | static const struct sccnxp_chip sc2691 = { |
---|
.. | .. |
---|
147 | 151 | .freq_max = 4000000, |
---|
148 | 152 | .flags = 0, |
---|
149 | 153 | .fifosize = 3, |
---|
| 154 | + .trwd = 150, |
---|
150 | 155 | }; |
---|
151 | 156 | |
---|
152 | 157 | static const struct sccnxp_chip sc2692 = { |
---|
.. | .. |
---|
157 | 162 | .freq_max = 4000000, |
---|
158 | 163 | .flags = SCCNXP_HAVE_IO, |
---|
159 | 164 | .fifosize = 3, |
---|
| 165 | + .trwd = 30, |
---|
160 | 166 | }; |
---|
161 | 167 | |
---|
162 | 168 | static const struct sccnxp_chip sc2891 = { |
---|
.. | .. |
---|
167 | 173 | .freq_max = 8000000, |
---|
168 | 174 | .flags = SCCNXP_HAVE_IO | SCCNXP_HAVE_MR0, |
---|
169 | 175 | .fifosize = 16, |
---|
| 176 | + .trwd = 27, |
---|
170 | 177 | }; |
---|
171 | 178 | |
---|
172 | 179 | static const struct sccnxp_chip sc2892 = { |
---|
.. | .. |
---|
177 | 184 | .freq_max = 8000000, |
---|
178 | 185 | .flags = SCCNXP_HAVE_IO | SCCNXP_HAVE_MR0, |
---|
179 | 186 | .fifosize = 16, |
---|
| 187 | + .trwd = 17, |
---|
180 | 188 | }; |
---|
181 | 189 | |
---|
182 | 190 | static const struct sccnxp_chip sc28202 = { |
---|
.. | .. |
---|
187 | 195 | .freq_max = 50000000, |
---|
188 | 196 | .flags = SCCNXP_HAVE_IO | SCCNXP_HAVE_MR0, |
---|
189 | 197 | .fifosize = 256, |
---|
| 198 | + .trwd = 10, |
---|
190 | 199 | }; |
---|
191 | 200 | |
---|
192 | 201 | static const struct sccnxp_chip sc68681 = { |
---|
.. | .. |
---|
197 | 206 | .freq_max = 4000000, |
---|
198 | 207 | .flags = SCCNXP_HAVE_IO, |
---|
199 | 208 | .fifosize = 3, |
---|
| 209 | + .trwd = 200, |
---|
200 | 210 | }; |
---|
201 | 211 | |
---|
202 | 212 | static const struct sccnxp_chip sc68692 = { |
---|
.. | .. |
---|
207 | 217 | .freq_max = 4000000, |
---|
208 | 218 | .flags = SCCNXP_HAVE_IO, |
---|
209 | 219 | .fifosize = 3, |
---|
| 220 | + .trwd = 200, |
---|
210 | 221 | }; |
---|
211 | 222 | |
---|
212 | | -static inline u8 sccnxp_read(struct uart_port *port, u8 reg) |
---|
| 223 | +static u8 sccnxp_read(struct uart_port *port, u8 reg) |
---|
213 | 224 | { |
---|
214 | | - return readb(port->membase + (reg << port->regshift)); |
---|
| 225 | + struct sccnxp_port *s = dev_get_drvdata(port->dev); |
---|
| 226 | + u8 ret; |
---|
| 227 | + |
---|
| 228 | + ret = readb(port->membase + (reg << port->regshift)); |
---|
| 229 | + |
---|
| 230 | + ndelay(s->chip->trwd); |
---|
| 231 | + |
---|
| 232 | + return ret; |
---|
215 | 233 | } |
---|
216 | 234 | |
---|
217 | | -static inline void sccnxp_write(struct uart_port *port, u8 reg, u8 v) |
---|
| 235 | +static void sccnxp_write(struct uart_port *port, u8 reg, u8 v) |
---|
218 | 236 | { |
---|
| 237 | + struct sccnxp_port *s = dev_get_drvdata(port->dev); |
---|
| 238 | + |
---|
219 | 239 | writeb(v, port->membase + (reg << port->regshift)); |
---|
| 240 | + |
---|
| 241 | + ndelay(s->chip->trwd); |
---|
220 | 242 | } |
---|
221 | 243 | |
---|
222 | | -static inline u8 sccnxp_port_read(struct uart_port *port, u8 reg) |
---|
| 244 | +static u8 sccnxp_port_read(struct uart_port *port, u8 reg) |
---|
223 | 245 | { |
---|
224 | 246 | return sccnxp_read(port, (port->line << 3) + reg); |
---|
225 | 247 | } |
---|
226 | 248 | |
---|
227 | | -static inline void sccnxp_port_write(struct uart_port *port, u8 reg, u8 v) |
---|
| 249 | +static void sccnxp_port_write(struct uart_port *port, u8 reg, u8 v) |
---|
228 | 250 | { |
---|
229 | 251 | sccnxp_write(port, (port->line << 3) + reg, v); |
---|
230 | 252 | } |
---|
.. | .. |
---|
233 | 255 | { |
---|
234 | 256 | int err = abs(a - b); |
---|
235 | 257 | |
---|
236 | | - if ((*besterr < 0) || (*besterr > err)) { |
---|
| 258 | + if (*besterr > err) { |
---|
237 | 259 | *besterr = err; |
---|
238 | 260 | return 0; |
---|
239 | 261 | } |
---|
.. | .. |
---|
281 | 303 | static int sccnxp_set_baud(struct uart_port *port, int baud) |
---|
282 | 304 | { |
---|
283 | 305 | struct sccnxp_port *s = dev_get_drvdata(port->dev); |
---|
284 | | - int div_std, tmp_baud, bestbaud = baud, besterr = -1; |
---|
| 306 | + int div_std, tmp_baud, bestbaud = INT_MAX, besterr = INT_MAX; |
---|
285 | 307 | struct sccnxp_chip *chip = s->chip; |
---|
286 | 308 | u8 i, acr = 0, csr = 0, mr0 = 0; |
---|
| 309 | + |
---|
| 310 | + /* Find divisor to load to the timer preset registers */ |
---|
| 311 | + div_std = DIV_ROUND_CLOSEST(port->uartclk, 2 * 16 * baud); |
---|
| 312 | + if ((div_std >= 2) && (div_std <= 0xffff)) { |
---|
| 313 | + bestbaud = DIV_ROUND_CLOSEST(port->uartclk, 2 * 16 * div_std); |
---|
| 314 | + sccnxp_update_best_err(baud, bestbaud, &besterr); |
---|
| 315 | + csr = CSR_TIMER_MODE; |
---|
| 316 | + sccnxp_port_write(port, SCCNXP_CTPU_REG, div_std >> 8); |
---|
| 317 | + sccnxp_port_write(port, SCCNXP_CTPL_REG, div_std); |
---|
| 318 | + /* Issue start timer/counter command */ |
---|
| 319 | + sccnxp_port_read(port, SCCNXP_START_COUNTER_REG); |
---|
| 320 | + } |
---|
287 | 321 | |
---|
288 | 322 | /* Find best baud from table */ |
---|
289 | 323 | for (i = 0; baud_std[i].baud && besterr; i++) { |
---|
.. | .. |
---|
923 | 957 | if (!s->poll) { |
---|
924 | 958 | s->irq = platform_get_irq(pdev, 0); |
---|
925 | 959 | if (s->irq < 0) { |
---|
926 | | - dev_err(&pdev->dev, "Missing irq resource data\n"); |
---|
927 | 960 | ret = -ENXIO; |
---|
928 | 961 | goto err_out; |
---|
929 | 962 | } |
---|
.. | .. |
---|
963 | 996 | s->port[i].regshift = s->pdata.reg_shift; |
---|
964 | 997 | s->port[i].uartclk = uartclk; |
---|
965 | 998 | s->port[i].ops = &sccnxp_ops; |
---|
| 999 | + s->port[i].has_sysrq = IS_ENABLED(CONFIG_SERIAL_SCCNXP_CONSOLE); |
---|
966 | 1000 | uart_add_one_port(&s->uart, &s->port[i]); |
---|
967 | 1001 | /* Set direction to input */ |
---|
968 | 1002 | if (s->chip->flags & SCCNXP_HAVE_IO) |
---|