.. | .. |
---|
14 | 14 | #include <linux/dmaengine.h> |
---|
15 | 15 | #include <linux/dma/dw.h> |
---|
16 | 16 | |
---|
17 | | -#include "8250.h" |
---|
| 17 | +#include "8250_dwlib.h" |
---|
18 | 18 | |
---|
19 | 19 | #define PCI_DEVICE_ID_INTEL_QRK_UARTx 0x0936 |
---|
20 | 20 | |
---|
.. | .. |
---|
23 | 23 | |
---|
24 | 24 | #define PCI_DEVICE_ID_INTEL_BSW_UART1 0x228a |
---|
25 | 25 | #define PCI_DEVICE_ID_INTEL_BSW_UART2 0x228c |
---|
| 26 | + |
---|
| 27 | +#define PCI_DEVICE_ID_INTEL_EHL_UART0 0x4b96 |
---|
| 28 | +#define PCI_DEVICE_ID_INTEL_EHL_UART1 0x4b97 |
---|
| 29 | +#define PCI_DEVICE_ID_INTEL_EHL_UART2 0x4b98 |
---|
| 30 | +#define PCI_DEVICE_ID_INTEL_EHL_UART3 0x4b99 |
---|
| 31 | +#define PCI_DEVICE_ID_INTEL_EHL_UART4 0x4b9a |
---|
| 32 | +#define PCI_DEVICE_ID_INTEL_EHL_UART5 0x4b9b |
---|
26 | 33 | |
---|
27 | 34 | #define PCI_DEVICE_ID_INTEL_BDW_UART1 0x9ce3 |
---|
28 | 35 | #define PCI_DEVICE_ID_INTEL_BDW_UART2 0x9ce4 |
---|
.. | .. |
---|
48 | 55 | }; |
---|
49 | 56 | |
---|
50 | 57 | struct lpss8250 { |
---|
51 | | - int line; |
---|
| 58 | + struct dw8250_port_data data; |
---|
52 | 59 | struct lpss8250_board *board; |
---|
53 | 60 | |
---|
54 | 61 | /* DMA parameters */ |
---|
55 | | - struct uart_8250_dma dma; |
---|
56 | 62 | struct dw_dma_chip dma_chip; |
---|
57 | 63 | struct dw_dma_slave dma_param; |
---|
58 | 64 | u8 dma_maxburst; |
---|
59 | 65 | }; |
---|
60 | 66 | |
---|
| 67 | +static inline struct lpss8250 *to_lpss8250(struct dw8250_port_data *data) |
---|
| 68 | +{ |
---|
| 69 | + return container_of(data, struct lpss8250, data); |
---|
| 70 | +} |
---|
| 71 | + |
---|
61 | 72 | static void byt_set_termios(struct uart_port *p, struct ktermios *termios, |
---|
62 | 73 | struct ktermios *old) |
---|
63 | 74 | { |
---|
64 | 75 | unsigned int baud = tty_termios_baud_rate(termios); |
---|
65 | | - struct lpss8250 *lpss = p->private_data; |
---|
| 76 | + struct lpss8250 *lpss = to_lpss8250(p->private_data); |
---|
66 | 77 | unsigned long fref = lpss->board->freq, fuart = baud * 16; |
---|
67 | 78 | unsigned long w = BIT(15) - 1; |
---|
68 | 79 | unsigned long m, n; |
---|
.. | .. |
---|
109 | 120 | static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port) |
---|
110 | 121 | { |
---|
111 | 122 | struct dw_dma_slave *param = &lpss->dma_param; |
---|
112 | | - struct uart_8250_port *up = up_to_u8250p(port); |
---|
113 | 123 | struct pci_dev *pdev = to_pci_dev(port->dev); |
---|
114 | | - unsigned int dma_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); |
---|
115 | | - struct pci_dev *dma_dev = pci_get_slot(pdev->bus, dma_devfn); |
---|
| 124 | + struct pci_dev *dma_dev; |
---|
116 | 125 | |
---|
117 | 126 | switch (pdev->device) { |
---|
118 | 127 | case PCI_DEVICE_ID_INTEL_BYT_UART1: |
---|
.. | .. |
---|
131 | 140 | return -EINVAL; |
---|
132 | 141 | } |
---|
133 | 142 | |
---|
| 143 | + dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); |
---|
| 144 | + |
---|
134 | 145 | param->dma_dev = &dma_dev->dev; |
---|
135 | 146 | param->m_master = 0; |
---|
136 | 147 | param->p_master = 1; |
---|
137 | | - |
---|
138 | | - /* TODO: Detect FIFO size automaticaly for DesignWare 8250 */ |
---|
139 | | - port->fifosize = 64; |
---|
140 | | - up->tx_loadsz = 64; |
---|
141 | 148 | |
---|
142 | 149 | lpss->dma_maxburst = 16; |
---|
143 | 150 | |
---|
.. | .. |
---|
150 | 157 | return 0; |
---|
151 | 158 | } |
---|
152 | 159 | |
---|
| 160 | +static void byt_serial_exit(struct lpss8250 *lpss) |
---|
| 161 | +{ |
---|
| 162 | + struct dw_dma_slave *param = &lpss->dma_param; |
---|
| 163 | + |
---|
| 164 | + /* Paired with pci_get_slot() in the byt_serial_setup() above */ |
---|
| 165 | + put_device(param->dma_dev); |
---|
| 166 | +} |
---|
| 167 | + |
---|
| 168 | +static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port) |
---|
| 169 | +{ |
---|
| 170 | + return 0; |
---|
| 171 | +} |
---|
| 172 | + |
---|
| 173 | +static void ehl_serial_exit(struct lpss8250 *lpss) |
---|
| 174 | +{ |
---|
| 175 | + struct uart_8250_port *up = serial8250_get_port(lpss->data.line); |
---|
| 176 | + |
---|
| 177 | + up->dma = NULL; |
---|
| 178 | +} |
---|
| 179 | + |
---|
153 | 180 | #ifdef CONFIG_SERIAL_8250_DMA |
---|
154 | 181 | static const struct dw_dma_platform_data qrk_serial_dma_pdata = { |
---|
155 | 182 | .nr_channels = 2, |
---|
156 | | - .is_private = true, |
---|
157 | 183 | .chan_allocation_order = CHAN_ALLOCATION_ASCENDING, |
---|
158 | 184 | .chan_priority = CHAN_PRIORITY_ASCENDING, |
---|
159 | 185 | .block_size = 4095, |
---|
.. | .. |
---|
164 | 190 | |
---|
165 | 191 | static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) |
---|
166 | 192 | { |
---|
167 | | - struct uart_8250_dma *dma = &lpss->dma; |
---|
| 193 | + struct uart_8250_dma *dma = &lpss->data.dma; |
---|
168 | 194 | struct dw_dma_chip *chip = &lpss->dma_chip; |
---|
169 | 195 | struct dw_dma_slave *param = &lpss->dma_param; |
---|
170 | 196 | struct pci_dev *pdev = to_pci_dev(port->dev); |
---|
171 | 197 | int ret; |
---|
172 | 198 | |
---|
| 199 | + chip->pdata = &qrk_serial_dma_pdata; |
---|
173 | 200 | chip->dev = &pdev->dev; |
---|
| 201 | + chip->id = pdev->devfn; |
---|
174 | 202 | chip->irq = pci_irq_vector(pdev, 0); |
---|
175 | 203 | chip->regs = pci_ioremap_bar(pdev, 1); |
---|
176 | | - chip->pdata = &qrk_serial_dma_pdata; |
---|
| 204 | + if (!chip->regs) |
---|
| 205 | + return; |
---|
177 | 206 | |
---|
178 | 207 | /* Falling back to PIO mode if DMA probing fails */ |
---|
179 | 208 | ret = dw_dma_probe(chip); |
---|
.. | .. |
---|
196 | 225 | |
---|
197 | 226 | static void qrk_serial_exit_dma(struct lpss8250 *lpss) |
---|
198 | 227 | { |
---|
| 228 | + struct dw_dma_chip *chip = &lpss->dma_chip; |
---|
199 | 229 | struct dw_dma_slave *param = &lpss->dma_param; |
---|
200 | 230 | |
---|
201 | 231 | if (!param->dma_dev) |
---|
202 | 232 | return; |
---|
203 | | - dw_dma_remove(&lpss->dma_chip); |
---|
| 233 | + |
---|
| 234 | + dw_dma_remove(chip); |
---|
| 235 | + |
---|
| 236 | + pci_iounmap(to_pci_dev(chip->dev), chip->regs); |
---|
204 | 237 | } |
---|
205 | 238 | #else /* CONFIG_SERIAL_8250_DMA */ |
---|
206 | 239 | static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {} |
---|
.. | .. |
---|
209 | 242 | |
---|
210 | 243 | static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port) |
---|
211 | 244 | { |
---|
212 | | - struct pci_dev *pdev = to_pci_dev(port->dev); |
---|
213 | | - int ret; |
---|
214 | | - |
---|
215 | | - pci_set_master(pdev); |
---|
216 | | - |
---|
217 | | - ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); |
---|
218 | | - if (ret < 0) |
---|
219 | | - return ret; |
---|
220 | | - |
---|
221 | | - port->irq = pci_irq_vector(pdev, 0); |
---|
222 | | - |
---|
223 | 245 | qrk_serial_setup_dma(lpss, port); |
---|
224 | 246 | return 0; |
---|
225 | 247 | } |
---|
.. | .. |
---|
242 | 264 | |
---|
243 | 265 | static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port) |
---|
244 | 266 | { |
---|
245 | | - struct uart_8250_dma *dma = &lpss->dma; |
---|
| 267 | + struct uart_8250_dma *dma = &lpss->data.dma; |
---|
246 | 268 | struct dw_dma_slave *rx_param, *tx_param; |
---|
247 | 269 | struct device *dev = port->port.dev; |
---|
248 | 270 | |
---|
249 | | - if (!lpss->dma_param.dma_dev) |
---|
| 271 | + if (!lpss->dma_param.dma_dev) { |
---|
| 272 | + dma = port->dma; |
---|
| 273 | + if (dma) |
---|
| 274 | + goto out_configuration_only; |
---|
| 275 | + |
---|
250 | 276 | return 0; |
---|
| 277 | + } |
---|
251 | 278 | |
---|
252 | 279 | rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL); |
---|
253 | 280 | if (!rx_param) |
---|
.. | .. |
---|
258 | 285 | return -ENOMEM; |
---|
259 | 286 | |
---|
260 | 287 | *rx_param = lpss->dma_param; |
---|
261 | | - dma->rxconf.src_maxburst = lpss->dma_maxburst; |
---|
262 | | - |
---|
263 | 288 | *tx_param = lpss->dma_param; |
---|
264 | | - dma->txconf.dst_maxburst = lpss->dma_maxburst; |
---|
265 | 289 | |
---|
266 | 290 | dma->fn = lpss8250_dma_filter; |
---|
267 | 291 | dma->rx_param = rx_param; |
---|
268 | 292 | dma->tx_param = tx_param; |
---|
269 | 293 | |
---|
270 | 294 | port->dma = dma; |
---|
| 295 | + |
---|
| 296 | +out_configuration_only: |
---|
| 297 | + dma->rxconf.src_maxburst = lpss->dma_maxburst; |
---|
| 298 | + dma->txconf.dst_maxburst = lpss->dma_maxburst; |
---|
| 299 | + |
---|
271 | 300 | return 0; |
---|
272 | 301 | } |
---|
273 | 302 | |
---|
.. | .. |
---|
281 | 310 | if (ret) |
---|
282 | 311 | return ret; |
---|
283 | 312 | |
---|
| 313 | + pci_set_master(pdev); |
---|
| 314 | + |
---|
284 | 315 | lpss = devm_kzalloc(&pdev->dev, sizeof(*lpss), GFP_KERNEL); |
---|
285 | 316 | if (!lpss) |
---|
286 | 317 | return -ENOMEM; |
---|
| 318 | + |
---|
| 319 | + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); |
---|
| 320 | + if (ret < 0) |
---|
| 321 | + return ret; |
---|
287 | 322 | |
---|
288 | 323 | lpss->board = (struct lpss8250_board *)id->driver_data; |
---|
289 | 324 | |
---|
290 | 325 | memset(&uart, 0, sizeof(struct uart_8250_port)); |
---|
291 | 326 | |
---|
292 | 327 | uart.port.dev = &pdev->dev; |
---|
293 | | - uart.port.irq = pdev->irq; |
---|
294 | | - uart.port.private_data = lpss; |
---|
| 328 | + uart.port.irq = pci_irq_vector(pdev, 0); |
---|
| 329 | + uart.port.private_data = &lpss->data; |
---|
295 | 330 | uart.port.type = PORT_16550A; |
---|
296 | 331 | uart.port.iotype = UPIO_MEM; |
---|
297 | 332 | uart.port.regshift = 2; |
---|
.. | .. |
---|
307 | 342 | if (ret) |
---|
308 | 343 | return ret; |
---|
309 | 344 | |
---|
| 345 | + dw8250_setup_port(&uart.port); |
---|
| 346 | + |
---|
310 | 347 | ret = lpss8250_dma_setup(lpss, &uart); |
---|
311 | 348 | if (ret) |
---|
312 | 349 | goto err_exit; |
---|
.. | .. |
---|
315 | 352 | if (ret < 0) |
---|
316 | 353 | goto err_exit; |
---|
317 | 354 | |
---|
318 | | - lpss->line = ret; |
---|
| 355 | + lpss->data.line = ret; |
---|
319 | 356 | |
---|
320 | 357 | pci_set_drvdata(pdev, lpss); |
---|
321 | 358 | return 0; |
---|
322 | 359 | |
---|
323 | 360 | err_exit: |
---|
324 | | - if (lpss->board->exit) |
---|
325 | | - lpss->board->exit(lpss); |
---|
| 361 | + lpss->board->exit(lpss); |
---|
| 362 | + pci_free_irq_vectors(pdev); |
---|
326 | 363 | return ret; |
---|
327 | 364 | } |
---|
328 | 365 | |
---|
.. | .. |
---|
330 | 367 | { |
---|
331 | 368 | struct lpss8250 *lpss = pci_get_drvdata(pdev); |
---|
332 | 369 | |
---|
333 | | - serial8250_unregister_port(lpss->line); |
---|
| 370 | + serial8250_unregister_port(lpss->data.line); |
---|
334 | 371 | |
---|
335 | | - if (lpss->board->exit) |
---|
336 | | - lpss->board->exit(lpss); |
---|
| 372 | + lpss->board->exit(lpss); |
---|
| 373 | + pci_free_irq_vectors(pdev); |
---|
337 | 374 | } |
---|
338 | 375 | |
---|
339 | 376 | static const struct lpss8250_board byt_board = { |
---|
340 | 377 | .freq = 100000000, |
---|
341 | 378 | .base_baud = 2764800, |
---|
342 | 379 | .setup = byt_serial_setup, |
---|
| 380 | + .exit = byt_serial_exit, |
---|
| 381 | +}; |
---|
| 382 | + |
---|
| 383 | +static const struct lpss8250_board ehl_board = { |
---|
| 384 | + .freq = 200000000, |
---|
| 385 | + .base_baud = 12500000, |
---|
| 386 | + .setup = ehl_serial_setup, |
---|
| 387 | + .exit = ehl_serial_exit, |
---|
343 | 388 | }; |
---|
344 | 389 | |
---|
345 | 390 | static const struct lpss8250_board qrk_board = { |
---|
.. | .. |
---|
349 | 394 | .exit = qrk_serial_exit, |
---|
350 | 395 | }; |
---|
351 | 396 | |
---|
352 | | -#define LPSS_DEVICE(id, board) { PCI_VDEVICE(INTEL, id), (kernel_ulong_t)&board } |
---|
353 | | - |
---|
354 | 397 | static const struct pci_device_id pci_ids[] = { |
---|
355 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_QRK_UARTx, qrk_board), |
---|
356 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BYT_UART1, byt_board), |
---|
357 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BYT_UART2, byt_board), |
---|
358 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BSW_UART1, byt_board), |
---|
359 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BSW_UART2, byt_board), |
---|
360 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BDW_UART1, byt_board), |
---|
361 | | - LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BDW_UART2, byt_board), |
---|
362 | | - { }, |
---|
| 398 | + { PCI_DEVICE_DATA(INTEL, QRK_UARTx, &qrk_board) }, |
---|
| 399 | + { PCI_DEVICE_DATA(INTEL, EHL_UART0, &ehl_board) }, |
---|
| 400 | + { PCI_DEVICE_DATA(INTEL, EHL_UART1, &ehl_board) }, |
---|
| 401 | + { PCI_DEVICE_DATA(INTEL, EHL_UART2, &ehl_board) }, |
---|
| 402 | + { PCI_DEVICE_DATA(INTEL, EHL_UART3, &ehl_board) }, |
---|
| 403 | + { PCI_DEVICE_DATA(INTEL, EHL_UART4, &ehl_board) }, |
---|
| 404 | + { PCI_DEVICE_DATA(INTEL, EHL_UART5, &ehl_board) }, |
---|
| 405 | + { PCI_DEVICE_DATA(INTEL, BYT_UART1, &byt_board) }, |
---|
| 406 | + { PCI_DEVICE_DATA(INTEL, BYT_UART2, &byt_board) }, |
---|
| 407 | + { PCI_DEVICE_DATA(INTEL, BSW_UART1, &byt_board) }, |
---|
| 408 | + { PCI_DEVICE_DATA(INTEL, BSW_UART2, &byt_board) }, |
---|
| 409 | + { PCI_DEVICE_DATA(INTEL, BDW_UART1, &byt_board) }, |
---|
| 410 | + { PCI_DEVICE_DATA(INTEL, BDW_UART2, &byt_board) }, |
---|
| 411 | + { } |
---|
363 | 412 | }; |
---|
364 | 413 | MODULE_DEVICE_TABLE(pci, pci_ids); |
---|
365 | 414 | |
---|