Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'tty-5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty

Pull tty/serial updates from Greg KH:
"Here is the "big" set of tty/serial driver patches for 5.2-rc1.

It's really pretty small, not much happening in this portion of the
kernel at the moment. When the "highlight" is the movement of the
documentation from .txt to .rst files, it's a good merge window.

There's a number of small fixes and updates over the various serial
drivers, and a new "tty null" driver for those embedded systems that
like to make things even smaller and not break things.

All of these have been in linux-next for a while with no reported
issues"

* tag 'tty-5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (45 commits)
tty: serial: add driver for the SiFive UART
dt-bindings: serial: add documentation for the SiFive UART driver
serial: uartps: Add support for cts-override
dt-bindings: xilinx-uartps: Add support for cts-override
serial: milbeaut_usio: Fix error handling in probe and remove
tty: rocket: deprecate the rp_ioctl
tty: rocket: Remove RCPK_GET_STRUCT ioctl
tty: update obsolete termios comment
tty: serial_core: fix error code returned by uart_register_driver()
serial: 8250-mtk: modify baudrate setting
serial: 8250-mtk: add follow control
docs: serial: convert docs to ReST and rename to *.rst
serial: 8250_exar: Adjust IOT2000 matching
TTY: serial_core, add ->install
serial: Fix using plain integer instead of Null pointer
tty:serial_core: Spelling mistake
tty: Add NULL TTY driver
tty: vt: keyboard: Allow Unicode compose base char
Revert "tty: fix NULL pointer issue when tty_port ops is not set"
serial: Add Milbeaut serial control
...

+3687 -919
+5
Documentation/devicetree/bindings/serial/cdns,uart.txt
··· 12 12 See ../clocks/clock-bindings.txt for details. 13 13 14 14 15 + Optional properties: 16 + - cts-override : Override the CTS modem status signal. This signal will 17 + always be reported as active instead of being obtained from the modem status 18 + register. Define this if your serial port does not use this pin 19 + 15 20 Example: 16 21 uart@e0000000 { 17 22 compatible = "cdns,uart-r1p8";
+2
Documentation/devicetree/bindings/serial/nxp,sc16is7xx.txt
··· 12 12 - reg: I2C address of the SC16IS7xx device. 13 13 - interrupts: Should contain the UART interrupt 14 14 - clocks: Reference to the IC source clock. 15 + OR (when there is no clock provider visible to the platform) 16 + - clock-frequency: The source clock frequency for the IC. 15 17 16 18 Optional properties: 17 19 - gpio-controller: Marks the device node as a GPIO controller.
+33
Documentation/devicetree/bindings/serial/sifive-serial.txt
··· 1 + SiFive asynchronous serial interface (UART) 2 + 3 + Required properties: 4 + 5 + - compatible: should be something similar to 6 + "sifive,<chip>-uart" for the UART as integrated 7 + on a particular chip, and "sifive,uart<version>" for the 8 + general UART IP block programming model. Supported 9 + compatible strings as of the date of this writing are: 10 + "sifive,fu540-c000-uart" for the SiFive UART v0 as 11 + integrated onto the SiFive FU540 chip, or "sifive,uart0" 12 + for the SiFive UART v0 IP block with no chip integration 13 + tweaks (if any) 14 + - reg: address and length of the register space 15 + - interrupts: Should contain the UART interrupt identifier 16 + - clocks: Should contain a clock identifier for the UART's parent clock 17 + 18 + 19 + UART HDL that corresponds to the IP block version numbers can be found 20 + here: 21 + 22 + https://github.com/sifive/sifive-blocks/tree/master/src/main/scala/devices/uart 23 + 24 + 25 + Example: 26 + 27 + uart0: serial@10010000 { 28 + compatible = "sifive,fu540-c000-uart", "sifive,uart0"; 29 + interrupt-parent = <&plic0>; 30 + interrupts = <80>; 31 + reg = <0x0 0x10010000 0x0 0x1000>; 32 + clocks = <&prci PRCI_CLK_TLCLK>; 33 + };
+15 -2
Documentation/devicetree/bindings/serial/sprd-uart.txt
··· 7 7 8 8 - reg: offset and length of the register set for the device 9 9 - interrupts: exactly one interrupt specifier 10 - - clocks: phandles to input clocks. 10 + - clock-names: Should contain following entries: 11 + "enable" for UART module enable clock, 12 + "uart" for UART clock, 13 + "source" for UART source (parent) clock. 14 + - clocks: Should contain a clock specifier for each entry in clock-names. 15 + UART clock and source clock are optional properties, but enable clock 16 + is required. 17 + 18 + Optional properties: 19 + - dma-names: Should contain "rx" for receive and "tx" for transmit channels. 20 + - dmas: A list of dma specifiers, one for each entry in dma-names. 11 21 12 22 Example: 13 23 uart0: serial@0 { ··· 25 15 "sprd,sc9836-uart"; 26 16 reg = <0x0 0x100>; 27 17 interrupts = <GIC_SPI 2 IRQ_TYPE_LEVEL_HIGH>; 28 - clocks = <&ext_26m>; 18 + dma-names = "rx", "tx"; 19 + dmas = <&ap_dma 19>, <&ap_dma 20>; 20 + clock-names = "enable", "uart", "source"; 21 + clocks = <&clk_ap_apb_gates 9>, <&clk_uart0>, <&ext_26m>; 29 22 };
+4 -1
Documentation/serial/README.cycladesZ Documentation/serial/cyclades_z.rst
··· 1 + ================ 2 + Cyclades-Z notes 3 + ================ 1 4 2 5 The Cyclades-Z must have firmware loaded onto the card before it will 3 6 operate. This operation should be performed during system startup, 4 7 5 8 The firmware, loader program and the latest device driver code are 6 9 available from Cyclades at 7 - ftp://ftp.cyclades.com/pub/cyclades/cyclades-z/linux/ 8 10 11 + ftp://ftp.cyclades.com/pub/cyclades/cyclades-z/linux/
+89 -26
Documentation/serial/driver Documentation/serial/driver.rst
··· 1 - 2 - Low Level Serial API 3 - -------------------- 1 + ==================== 2 + Low Level Serial API 3 + ==================== 4 4 5 5 6 6 This document is meant as a brief overview of some aspects of the new serial ··· 44 44 There are two locks. A per-port spinlock, and an overall semaphore. 45 45 46 46 From the core driver perspective, the port->lock locks the following 47 - data: 47 + data:: 48 48 49 49 port->mctrl 50 50 port->icount ··· 75 75 return TIOCSER_TEMT. 76 76 77 77 Locking: none. 78 + 78 79 Interrupts: caller dependent. 80 + 79 81 This call must not sleep 80 82 81 83 set_mctrl(port, mctrl) 82 84 This function sets the modem control lines for port described 83 85 by 'port' to the state described by mctrl. The relevant bits 84 86 of mctrl are: 87 + 85 88 - TIOCM_RTS RTS signal. 86 89 - TIOCM_DTR DTR signal. 87 90 - TIOCM_OUT1 OUT1 signal. 88 91 - TIOCM_OUT2 OUT2 signal. 89 92 - TIOCM_LOOP Set the port into loopback mode. 93 + 90 94 If the appropriate bit is set, the signal should be driven 91 95 active. If the bit is clear, the signal should be driven 92 96 inactive. 93 97 94 98 Locking: port->lock taken. 99 + 95 100 Interrupts: locally disabled. 101 + 96 102 This call must not sleep 97 103 98 104 get_mctrl(port) 99 105 Returns the current state of modem control inputs. The state 100 106 of the outputs should not be returned, since the core keeps 101 107 track of their state. The state information should include: 108 + 102 109 - TIOCM_CAR state of DCD signal 103 110 - TIOCM_CTS state of CTS signal 104 111 - TIOCM_DSR state of DSR signal 105 112 - TIOCM_RI state of RI signal 113 + 106 114 The bit is set if the signal is currently driven active. If 107 115 the port does not support CTS, DCD or DSR, the driver should 108 116 indicate that the signal is permanently active. If RI is 109 117 not available, the signal should not be indicated as active. 110 118 111 119 Locking: port->lock taken. 120 + 112 121 Interrupts: locally disabled. 122 + 113 123 This call must not sleep 114 124 115 125 stop_tx(port) ··· 131 121 possible. 132 122 133 123 Locking: port->lock taken. 124 + 134 125 Interrupts: locally disabled. 126 + 135 127 This call must not sleep 136 128 137 129 start_tx(port) 138 130 Start transmitting characters. 139 131 140 132 Locking: port->lock taken. 133 + 141 134 Interrupts: locally disabled. 135 + 142 136 This call must not sleep 143 137 144 138 throttle(port) ··· 152 138 This will be called only if hardware assisted flow control is enabled. 153 139 154 140 Locking: serialized with .unthrottle() and termios modification by the 155 - tty layer. 141 + tty layer. 156 142 157 143 unthrottle(port) 158 144 Notify the serial driver that characters can now be sent to the serial 159 145 port without fear of overrunning the input buffers of the line 160 146 disciplines. 147 + 161 148 This will be called only if hardware assisted flow control is enabled. 162 149 163 150 Locking: serialized with .throttle() and termios modification by the 164 - tty layer. 151 + tty layer. 165 152 166 153 send_xchar(port,ch) 167 154 Transmit a high priority character, even if the port is stopped. ··· 174 159 Do not transmit if ch == '\0' (__DISABLED_CHAR). 175 160 176 161 Locking: none. 162 + 177 163 Interrupts: caller dependent. 178 164 179 165 stop_rx(port) ··· 182 166 being closed. 183 167 184 168 Locking: port->lock taken. 169 + 185 170 Interrupts: locally disabled. 171 + 186 172 This call must not sleep 187 173 188 174 enable_ms(port) ··· 195 177 called. 196 178 197 179 Locking: port->lock taken. 180 + 198 181 Interrupts: locally disabled. 182 + 199 183 This call must not sleep 200 184 201 185 break_ctl(port,ctl) ··· 216 196 This method will only be called when the port is initially opened. 217 197 218 198 Locking: port_sem taken. 199 + 219 200 Interrupts: globally disabled. 220 201 221 202 shutdown(port) ··· 231 210 this port. 232 211 233 212 Locking: port_sem taken. 213 + 234 214 Interrupts: caller dependent. 235 215 236 216 flush_buffer(port) ··· 242 220 buffer is cleared. 243 221 244 222 Locking: port->lock taken. 223 + 245 224 Interrupts: locally disabled. 225 + 246 226 This call must not sleep 247 227 248 228 set_termios(port,termios,oldtermios) ··· 252 228 bits. Update read_status_mask and ignore_status_mask to indicate 253 229 the types of events we are interested in receiving. Relevant 254 230 termios->c_cflag bits are: 255 - CSIZE - word size 256 - CSTOPB - 2 stop bits 257 - PARENB - parity enable 258 - PARODD - odd parity (when PARENB is in force) 259 - CREAD - enable reception of characters (if not set, 231 + 232 + CSIZE 233 + - word size 234 + CSTOPB 235 + - 2 stop bits 236 + PARENB 237 + - parity enable 238 + PARODD 239 + - odd parity (when PARENB is in force) 240 + CREAD 241 + - enable reception of characters (if not set, 260 242 still receive characters from the port, but 261 243 throw them away. 262 - CRTSCTS - if set, enable CTS status change reporting 263 - CLOCAL - if not set, enable modem status change 244 + CRTSCTS 245 + - if set, enable CTS status change reporting 246 + CLOCAL 247 + - if not set, enable modem status change 264 248 reporting. 249 + 265 250 Relevant termios->c_iflag bits are: 266 - INPCK - enable frame and parity error events to be 251 + 252 + INPCK 253 + - enable frame and parity error events to be 267 254 passed to the TTY layer. 268 - BRKINT 269 - PARMRK - both of these enable break events to be 255 + BRKINT / PARMRK 256 + - both of these enable break events to be 270 257 passed to the TTY layer. 271 258 272 - IGNPAR - ignore parity and framing errors 273 - IGNBRK - ignore break errors, If IGNPAR is also 259 + IGNPAR 260 + - ignore parity and framing errors 261 + IGNBRK 262 + - ignore break errors, If IGNPAR is also 274 263 set, ignore overrun errors as well. 264 + 275 265 The interaction of the iflag bits is as follows (parity error 276 266 given as an example): 267 + 268 + =============== ======= ====== ============================= 277 269 Parity error INPCK IGNPAR 270 + =============== ======= ====== ============================= 278 271 n/a 0 n/a character received, marked as 279 272 TTY_NORMAL 280 273 None 1 n/a character received, marked as ··· 299 258 Yes 1 0 character received, marked as 300 259 TTY_PARITY 301 260 Yes 1 1 character discarded 261 + =============== ======= ====== ============================= 302 262 303 263 Other flags may be used (eg, xon/xoff characters) if your 304 264 hardware supports hardware "soft" flow control. 305 265 306 266 Locking: caller holds tty_port->mutex 267 + 307 268 Interrupts: caller dependent. 269 + 308 270 This call must not sleep 309 271 310 272 set_ldisc(port,termios) 311 - Notifier for discipline change. See Documentation/serial/tty.txt. 273 + Notifier for discipline change. See Documentation/serial/tty.rst. 312 274 313 275 Locking: caller holds tty_port->mutex 314 276 ··· 327 283 will occur even if CONFIG_PM is not set. 328 284 329 285 Locking: none. 286 + 330 287 Interrupts: caller dependent. 331 288 332 289 type(port) ··· 336 291 substituted. 337 292 338 293 Locking: none. 294 + 339 295 Interrupts: caller dependent. 340 296 341 297 release_port(port) ··· 344 298 the port. 345 299 346 300 Locking: none. 301 + 347 302 Interrupts: caller dependent. 348 303 349 304 request_port(port) ··· 353 306 returns, and it should return -EBUSY on failure. 354 307 355 308 Locking: none. 309 + 356 310 Interrupts: caller dependent. 357 311 358 312 config_port(port,type) ··· 369 321 internally hard wired (eg, system on a chip implementations). 370 322 371 323 Locking: none. 324 + 372 325 Interrupts: caller dependent. 373 326 374 327 verify_port(port,serinfo) ··· 377 328 suitable for this port type. 378 329 379 330 Locking: none. 331 + 380 332 Interrupts: caller dependent. 381 333 382 334 ioctl(port,cmd,arg) ··· 385 335 using the standard numbering system found in <asm/ioctl.h> 386 336 387 337 Locking: none. 338 + 388 339 Interrupts: caller dependent. 389 340 390 341 poll_init(port) ··· 394 343 this should not request interrupts. 395 344 396 345 Locking: tty_mutex and tty_port->mutex taken. 346 + 397 347 Interrupts: n/a. 398 348 399 349 poll_put_char(port,ch) ··· 402 350 port. It can and should block until there is space in the TX FIFO. 403 351 404 352 Locking: none. 353 + 405 354 Interrupts: caller dependent. 355 + 406 356 This call must not sleep 407 357 408 358 poll_get_char(port) ··· 413 359 the function should return NO_POLL_CHAR immediately. 414 360 415 361 Locking: none. 362 + 416 363 Interrupts: caller dependent. 364 + 417 365 This call must not sleep 418 366 419 367 Other functions ··· 426 370 number of bits, parity, stop bits and baud rate. 427 371 428 372 Locking: caller is expected to take port->lock 373 + 429 374 Interrupts: n/a 430 375 431 376 uart_get_baud_rate(port,termios,old,min,max) ··· 442 385 Note: min..max must always allow 9600 baud to be selected. 443 386 444 387 Locking: caller dependent. 388 + 445 389 Interrupts: n/a 446 390 447 391 uart_get_divisor(port,baud) ··· 453 395 custom divisor instead. 454 396 455 397 Locking: caller dependent. 398 + 456 399 Interrupts: n/a 457 400 458 401 uart_match_port(port1,port2) ··· 461 402 uart_port structures describe the same port. 462 403 463 404 Locking: n/a 405 + 464 406 Interrupts: n/a 465 407 466 408 uart_write_wakeup(port) ··· 469 409 characters in the transmit buffer have dropped below a threshold. 470 410 471 411 Locking: port->lock should be held. 412 + 472 413 Interrupts: n/a 473 414 474 415 uart_register_driver(drv) ··· 480 419 registered using uart_add_one_port after this call has succeeded. 481 420 482 421 Locking: none 422 + 483 423 Interrupts: enabled 484 424 485 425 uart_unregister_driver() ··· 489 427 uart_remove_one_port() if it registered them with uart_add_one_port(). 490 428 491 429 Locking: none 430 + 492 431 Interrupts: enabled 493 432 494 - uart_suspend_port() 433 + **uart_suspend_port()** 495 434 496 - uart_resume_port() 435 + **uart_resume_port()** 497 436 498 - uart_add_one_port() 437 + **uart_add_one_port()** 499 438 500 - uart_remove_one_port() 439 + **uart_remove_one_port()** 501 440 502 441 Other notes 503 442 ----------- ··· 507 444 allow low level drivers to register their own individual uart_port's with 508 445 the core. This will allow drivers to use uart_port as a pointer to a 509 446 structure containing both the uart_port entry with their own extensions, 510 - thus: 447 + thus:: 511 448 512 449 struct my_port { 513 450 struct uart_port port; ··· 522 459 mctrl_gpio_init(port, idx): 523 460 This will get the {cts,rts,...}-gpios from device tree if they are 524 461 present and request them, set direction etc, and return an 525 - allocated structure. devm_* functions are used, so there's no need 462 + allocated structure. `devm_*` functions are used, so there's no need 526 463 to call mctrl_gpio_free(). 527 464 As this sets up the irq handling make sure to not handle changes to the 528 465 gpio input lines in your driver, too. 529 466 530 467 mctrl_gpio_free(dev, gpios): 531 468 This will free the requested gpios in mctrl_gpio_init(). 532 - As devm_* functions are used, there's generally no need to call 469 + As `devm_*` functions are used, there's generally no need to call 533 470 this function. 534 471 535 472 mctrl_gpio_to_gpiod(gpios, gidx)
+32
Documentation/serial/index.rst
··· 1 + :orphan: 2 + 3 + ========================== 4 + Support for Serial devices 5 + ========================== 6 + 7 + .. toctree:: 8 + :maxdepth: 1 9 + 10 + 11 + driver 12 + tty 13 + 14 + Serial drivers 15 + ============== 16 + 17 + .. toctree:: 18 + :maxdepth: 1 19 + 20 + cyclades_z 21 + moxa-smartio 22 + n_gsm 23 + rocket 24 + serial-iso7816 25 + serial-rs485 26 + 27 + .. only:: subproject and html 28 + 29 + Indices 30 + ======= 31 + 32 + * :ref:`genindex`
-523
Documentation/serial/moxa-smartio
··· 1 - ============================================================================= 2 - MOXA Smartio/Industio Family Device Driver Installation Guide 3 - for Linux Kernel 2.4.x, 2.6.x 4 - Copyright (C) 2008, Moxa Inc. 5 - ============================================================================= 6 - Date: 01/21/2008 7 - 8 - Content 9 - 10 - 1. Introduction 11 - 2. System Requirement 12 - 3. Installation 13 - 3.1 Hardware installation 14 - 3.2 Driver files 15 - 3.3 Device naming convention 16 - 3.4 Module driver configuration 17 - 3.5 Static driver configuration for Linux kernel 2.4.x and 2.6.x. 18 - 3.6 Custom configuration 19 - 3.7 Verify driver installation 20 - 4. Utilities 21 - 5. Setserial 22 - 6. Troubleshooting 23 - 24 - ----------------------------------------------------------------------------- 25 - 1. Introduction 26 - 27 - The Smartio/Industio/UPCI family Linux driver supports following multiport 28 - boards. 29 - 30 - - 2 ports multiport board 31 - CP-102U, CP-102UL, CP-102UF 32 - CP-132U-I, CP-132UL, 33 - CP-132, CP-132I, CP132S, CP-132IS, 34 - CI-132, CI-132I, CI-132IS, 35 - (C102H, C102HI, C102HIS, C102P, CP-102, CP-102S) 36 - 37 - - 4 ports multiport board 38 - CP-104EL, 39 - CP-104UL, CP-104JU, 40 - CP-134U, CP-134U-I, 41 - C104H/PCI, C104HS/PCI, 42 - CP-114, CP-114I, CP-114S, CP-114IS, CP-114UL, 43 - C104H, C104HS, 44 - CI-104J, CI-104JS, 45 - CI-134, CI-134I, CI-134IS, 46 - (C114HI, CT-114I, C104P) 47 - POS-104UL, 48 - CB-114, 49 - CB-134I 50 - 51 - - 8 ports multiport board 52 - CP-118EL, CP-168EL, 53 - CP-118U, CP-168U, 54 - C168H/PCI, 55 - C168H, C168HS, 56 - (C168P), 57 - CB-108 58 - 59 - This driver and installation procedure have been developed upon Linux Kernel 60 - 2.4.x and 2.6.x. This driver supports Intel x86 hardware platform. In order 61 - to maintain compatibility, this version has also been properly tested with 62 - RedHat, Mandrake, Fedora and S.u.S.E Linux. However, if compatibility problem 63 - occurs, please contact Moxa at support@moxa.com.tw. 64 - 65 - In addition to device driver, useful utilities are also provided in this 66 - version. They are 67 - - msdiag Diagnostic program for displaying installed Moxa 68 - Smartio/Industio boards. 69 - - msmon Monitor program to observe data count and line status signals. 70 - - msterm A simple terminal program which is useful in testing serial 71 - ports. 72 - - io-irq.exe Configuration program to setup ISA boards. Please note that 73 - this program can only be executed under DOS. 74 - 75 - All the drivers and utilities are published in form of source code under 76 - GNU General Public License in this version. Please refer to GNU General 77 - Public License announcement in each source code file for more detail. 78 - 79 - In Moxa's Web sites, you may always find latest driver at http://www.moxa.com/. 80 - 81 - This version of driver can be installed as Loadable Module (Module driver) 82 - or built-in into kernel (Static driver). You may refer to following 83 - installation procedure for suitable one. Before you install the driver, 84 - please refer to hardware installation procedure in the User's Manual. 85 - 86 - We assume the user should be familiar with following documents. 87 - - Serial-HOWTO 88 - - Kernel-HOWTO 89 - 90 - ----------------------------------------------------------------------------- 91 - 2. System Requirement 92 - - Hardware platform: Intel x86 machine 93 - - Kernel version: 2.4.x or 2.6.x 94 - - gcc version 2.72 or later 95 - - Maximum 4 boards can be installed in combination 96 - 97 - ----------------------------------------------------------------------------- 98 - 3. Installation 99 - 100 - 3.1 Hardware installation 101 - 3.2 Driver files 102 - 3.3 Device naming convention 103 - 3.4 Module driver configuration 104 - 3.5 Static driver configuration for Linux kernel 2.4.x, 2.6.x. 105 - 3.6 Custom configuration 106 - 3.7 Verify driver installation 107 - 108 - 109 - 3.1 Hardware installation 110 - 111 - There are two types of buses, ISA and PCI, for Smartio/Industio 112 - family multiport board. 113 - 114 - ISA board 115 - --------- 116 - You'll have to configure CAP address, I/O address, Interrupt Vector 117 - as well as IRQ before installing this driver. Please refer to hardware 118 - installation procedure in User's Manual before proceed any further. 119 - Please make sure the JP1 is open after the ISA board is set properly. 120 - 121 - PCI/UPCI board 122 - -------------- 123 - You may need to adjust IRQ usage in BIOS to avoid from IRQ conflict 124 - with other ISA devices. Please refer to hardware installation 125 - procedure in User's Manual in advance. 126 - 127 - PCI IRQ Sharing 128 - ----------- 129 - Each port within the same multiport board shares the same IRQ. Up to 130 - 4 Moxa Smartio/Industio PCI Family multiport boards can be installed 131 - together on one system and they can share the same IRQ. 132 - 133 - 134 - 3.2 Driver files 135 - 136 - The driver file may be obtained from ftp, CD-ROM or floppy disk. The 137 - first step, anyway, is to copy driver file "mxser.tgz" into specified 138 - directory. e.g. /moxa. The execute commands as below. 139 - 140 - # cd / 141 - # mkdir moxa 142 - # cd /moxa 143 - # tar xvf /dev/fd0 144 - 145 - or 146 - 147 - # cd / 148 - # mkdir moxa 149 - # cd /moxa 150 - # cp /mnt/cdrom/<driver directory>/mxser.tgz . 151 - # tar xvfz mxser.tgz 152 - 153 - 154 - 3.3 Device naming convention 155 - 156 - You may find all the driver and utilities files in /moxa/mxser. 157 - Following installation procedure depends on the model you'd like to 158 - run the driver. If you prefer module driver, please refer to 3.4. 159 - If static driver is required, please refer to 3.5. 160 - 161 - Dialin and callout port 162 - ----------------------- 163 - This driver remains traditional serial device properties. There are 164 - two special file name for each serial port. One is dial-in port 165 - which is named "ttyMxx". For callout port, the naming convention 166 - is "cumxx". 167 - 168 - Device naming when more than 2 boards installed 169 - ----------------------------------------------- 170 - Naming convention for each Smartio/Industio multiport board is 171 - pre-defined as below. 172 - 173 - Board Num. Dial-in Port Callout port 174 - 1st board ttyM0 - ttyM7 cum0 - cum7 175 - 2nd board ttyM8 - ttyM15 cum8 - cum15 176 - 3rd board ttyM16 - ttyM23 cum16 - cum23 177 - 4th board ttyM24 - ttym31 cum24 - cum31 178 - 179 - 180 - !!!!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 181 - Under Kernel 2.6 the cum Device is Obsolete. So use ttyM* 182 - device instead. 183 - !!!!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 184 - 185 - Board sequence 186 - -------------- 187 - This driver will activate ISA boards according to the parameter set 188 - in the driver. After all specified ISA board activated, PCI board 189 - will be installed in the system automatically driven. 190 - Therefore the board number is sorted by the CAP address of ISA boards. 191 - For PCI boards, their sequence will be after ISA boards and C168H/PCI 192 - has higher priority than C104H/PCI boards. 193 - 194 - 3.4 Module driver configuration 195 - Module driver is easiest way to install. If you prefer static driver 196 - installation, please skip this paragraph. 197 - 198 - 199 - ------------- Prepare to use the MOXA driver-------------------- 200 - 3.4.1 Create tty device with correct major number 201 - Before using MOXA driver, your system must have the tty devices 202 - which are created with driver's major number. We offer one shell 203 - script "msmknod" to simplify the procedure. 204 - This step is only needed to be executed once. But you still 205 - need to do this procedure when: 206 - a. You change the driver's major number. Please refer the "3.7" 207 - section. 208 - b. Your total installed MOXA boards number is changed. Maybe you 209 - add/delete one MOXA board. 210 - c. You want to change the tty name. This needs to modify the 211 - shell script "msmknod" 212 - 213 - The procedure is: 214 - # cd /moxa/mxser/driver 215 - # ./msmknod 216 - 217 - This shell script will require the major number for dial-in 218 - device and callout device to create tty device. You also need 219 - to specify the total installed MOXA board number. Default major 220 - numbers for dial-in device and callout device are 30, 35. If 221 - you need to change to other number, please refer section "3.7" 222 - for more detailed procedure. 223 - Msmknod will delete any special files occupying the same device 224 - naming. 225 - 226 - 3.4.2 Build the MOXA driver and utilities 227 - Before using the MOXA driver and utilities, you need compile the 228 - all the source code. This step is only need to be executed once. 229 - But you still re-compile the source code if you modify the source 230 - code. For example, if you change the driver's major number (see 231 - "3.7" section), then you need to do this step again. 232 - 233 - Find "Makefile" in /moxa/mxser, then run 234 - 235 - # make clean; make install 236 - 237 - !!!!!!!!!! NOTE !!!!!!!!!!!!!!!!! 238 - For Red Hat 9, Red Hat Enterprise Linux AS3/ES3/WS3 & Fedora Core1: 239 - # make clean; make installsp1 240 - 241 - For Red Hat Enterprise Linux AS4/ES4/WS4: 242 - # make clean; make installsp2 243 - !!!!!!!!!! NOTE !!!!!!!!!!!!!!!!! 244 - 245 - The driver files "mxser.o" and utilities will be properly compiled 246 - and copied to system directories respectively. 247 - 248 - ------------- Load MOXA driver-------------------- 249 - 3.4.3 Load the MOXA driver 250 - 251 - # modprobe mxser <argument> 252 - 253 - will activate the module driver. You may run "lsmod" to check 254 - if "mxser" is activated. If the MOXA board is ISA board, the 255 - <argument> is needed. Please refer to section "3.4.5" for more 256 - information. 257 - 258 - 259 - ------------- Load MOXA driver on boot -------------------- 260 - 3.4.4 For the above description, you may manually execute 261 - "modprobe mxser" to activate this driver and run 262 - "rmmod mxser" to remove it. 263 - However, it's better to have a boot time configuration to 264 - eliminate manual operation. Boot time configuration can be 265 - achieved by rc file. We offer one "rc.mxser" file to simplify 266 - the procedure under "moxa/mxser/driver". 267 - 268 - But if you use ISA board, please modify the "modprobe ..." command 269 - to add the argument (see "3.4.5" section). After modifying the 270 - rc.mxser, please try to execute "/moxa/mxser/driver/rc.mxser" 271 - manually to make sure the modification is ok. If any error 272 - encountered, please try to modify again. If the modification is 273 - completed, follow the below step. 274 - 275 - Run following command for setting rc files. 276 - 277 - # cd /moxa/mxser/driver 278 - # cp ./rc.mxser /etc/rc.d 279 - # cd /etc/rc.d 280 - 281 - Check "rc.serial" is existed or not. If "rc.serial" doesn't exist, 282 - create it by vi, run "chmod 755 rc.serial" to change the permission. 283 - Add "/etc/rc.d/rc.mxser" in last line, 284 - 285 - Reboot and check if moxa.o activated by "lsmod" command. 286 - 287 - 3.4.5. If you'd like to drive Smartio/Industio ISA boards in the system, 288 - you'll have to add parameter to specify CAP address of given 289 - board while activating "mxser.o". The format for parameters are 290 - as follows. 291 - 292 - modprobe mxser ioaddr=0x???,0x???,0x???,0x??? 293 - | | | | 294 - | | | +- 4th ISA board 295 - | | +------ 3rd ISA board 296 - | +------------ 2nd ISA board 297 - +------------------- 1st ISA board 298 - 299 - 3.5 Static driver configuration for Linux kernel 2.4.x and 2.6.x 300 - 301 - Note: To use static driver, you must install the linux kernel 302 - source package. 303 - 304 - 3.5.1 Backup the built-in driver in the kernel. 305 - # cd /usr/src/linux/drivers/char 306 - # mv mxser.c mxser.c.old 307 - 308 - For Red Hat 7.x user, you need to create link: 309 - # cd /usr/src 310 - # ln -s linux-2.4 linux 311 - 312 - 3.5.2 Create link 313 - # cd /usr/src/linux/drivers/char 314 - # ln -s /moxa/mxser/driver/mxser.c mxser.c 315 - 316 - 3.5.3 Add CAP address list for ISA boards. For PCI boards user, 317 - please skip this step. 318 - 319 - In module mode, the CAP address for ISA board is given by 320 - parameter. In static driver configuration, you'll have to 321 - assign it within driver's source code. If you will not 322 - install any ISA boards, you may skip to next portion. 323 - The instructions to modify driver source code are as 324 - below. 325 - a. # cd /moxa/mxser/driver 326 - # vi mxser.c 327 - b. Find the array mxserBoardCAP[] as below. 328 - 329 - static int mxserBoardCAP[] 330 - = {0x00, 0x00, 0x00, 0x00}; 331 - 332 - c. Change the address within this array using vi. For 333 - example, to driver 2 ISA boards with CAP address 334 - 0x280 and 0x180 as 1st and 2nd board. Just to change 335 - the source code as follows. 336 - 337 - static int mxserBoardCAP[] 338 - = {0x280, 0x180, 0x00, 0x00}; 339 - 340 - 3.5.4 Setup kernel configuration 341 - 342 - Configure the kernel: 343 - 344 - # cd /usr/src/linux 345 - # make menuconfig 346 - 347 - You will go into a menu-driven system. Please select [Character 348 - devices][Non-standard serial port support], enable the [Moxa 349 - SmartIO support] driver with "[*]" for built-in (not "[M]"), then 350 - select [Exit] to exit this program. 351 - 352 - 3.5.5 Rebuild kernel 353 - The following are for Linux kernel rebuilding, for your 354 - reference only. 355 - For appropriate details, please refer to the Linux document. 356 - 357 - a. cd /usr/src/linux 358 - b. make clean /* take a few minutes */ 359 - c. make dep /* take a few minutes */ 360 - d. make bzImage /* take probably 10-20 minutes */ 361 - e. make install /* copy boot image to correct position */ 362 - f. Please make sure the boot kernel (vmlinuz) is in the 363 - correct position. 364 - g. If you use 'lilo' utility, you should check /etc/lilo.conf 365 - 'image' item specified the path which is the 'vmlinuz' path, 366 - or you will load wrong (or old) boot kernel image (vmlinuz). 367 - After checking /etc/lilo.conf, please run "lilo". 368 - 369 - Note that if the result of "make bzImage" is ERROR, then you have to 370 - go back to Linux configuration Setup. Type "make menuconfig" in 371 - directory /usr/src/linux. 372 - 373 - 374 - 3.5.6 Make tty device and special file 375 - # cd /moxa/mxser/driver 376 - # ./msmknod 377 - 378 - 3.5.7 Make utility 379 - # cd /moxa/mxser/utility 380 - # make clean; make install 381 - 382 - 3.5.8 Reboot 383 - 384 - 385 - 386 - 3.6 Custom configuration 387 - Although this driver already provides you default configuration, you 388 - still can change the device name and major number. The instruction to 389 - change these parameters are shown as below. 390 - 391 - Change Device name 392 - ------------------ 393 - If you'd like to use other device names instead of default naming 394 - convention, all you have to do is to modify the internal code 395 - within the shell script "msmknod". First, you have to open "msmknod" 396 - by vi. Locate each line contains "ttyM" and "cum" and change them 397 - to the device name you desired. "msmknod" creates the device names 398 - you need next time executed. 399 - 400 - Change Major number 401 - ------------------- 402 - If major number 30 and 35 had been occupied, you may have to select 403 - 2 free major numbers for this driver. There are 3 steps to change 404 - major numbers. 405 - 406 - 3.6.1 Find free major numbers 407 - In /proc/devices, you may find all the major numbers occupied 408 - in the system. Please select 2 major numbers that are available. 409 - e.g. 40, 45. 410 - 3.6.2 Create special files 411 - Run /moxa/mxser/driver/msmknod to create special files with 412 - specified major numbers. 413 - 3.6.3 Modify driver with new major number 414 - Run vi to open /moxa/mxser/driver/mxser.c. Locate the line 415 - contains "MXSERMAJOR". Change the content as below. 416 - #define MXSERMAJOR 40 417 - #define MXSERCUMAJOR 45 418 - 3.6.4 Run "make clean; make install" in /moxa/mxser/driver. 419 - 420 - 3.7 Verify driver installation 421 - You may refer to /var/log/messages to check the latest status 422 - log reported by this driver whenever it's activated. 423 - 424 - ----------------------------------------------------------------------------- 425 - 4. Utilities 426 - There are 3 utilities contained in this driver. They are msdiag, msmon and 427 - msterm. These 3 utilities are released in form of source code. They should 428 - be compiled into executable file and copied into /usr/bin. 429 - 430 - Before using these utilities, please load driver (refer 3.4 & 3.5) and 431 - make sure you had run the "msmknod" utility. 432 - 433 - msdiag - Diagnostic 434 - -------------------- 435 - This utility provides the function to display what Moxa Smartio/Industio 436 - board found by driver in the system. 437 - 438 - msmon - Port Monitoring 439 - ----------------------- 440 - This utility gives the user a quick view about all the MOXA ports' 441 - activities. One can easily learn each port's total received/transmitted 442 - (Rx/Tx) character count since the time when the monitoring is started. 443 - Rx/Tx throughputs per second are also reported in interval basis (e.g. 444 - the last 5 seconds) and in average basis (since the time the monitoring 445 - is started). You can reset all ports' count by <HOME> key. <+> <-> 446 - (plus/minus) keys to change the displaying time interval. Press <ENTER> 447 - on the port, that cursor stay, to view the port's communication 448 - parameters, signal status, and input/output queue. 449 - 450 - msterm - Terminal Emulation 451 - --------------------------- 452 - This utility provides data sending and receiving ability of all tty ports, 453 - especially for MOXA ports. It is quite useful for testing simple 454 - application, for example, sending AT command to a modem connected to the 455 - port or used as a terminal for login purpose. Note that this is only a 456 - dumb terminal emulation without handling full screen operation. 457 - 458 - ----------------------------------------------------------------------------- 459 - 5. Setserial 460 - 461 - Supported Setserial parameters are listed as below. 462 - 463 - uart set UART type(16450-->disable FIFO, 16550A-->enable FIFO) 464 - close_delay set the amount of time(in 1/100 of a second) that DTR 465 - should be kept low while being closed. 466 - closing_wait set the amount of time(in 1/100 of a second) that the 467 - serial port should wait for data to be drained while 468 - being closed, before the receiver is disable. 469 - spd_hi Use 57.6kb when the application requests 38.4kb. 470 - spd_vhi Use 115.2kb when the application requests 38.4kb. 471 - spd_shi Use 230.4kb when the application requests 38.4kb. 472 - spd_warp Use 460.8kb when the application requests 38.4kb. 473 - spd_normal Use 38.4kb when the application requests 38.4kb. 474 - spd_cust Use the custom divisor to set the speed when the 475 - application requests 38.4kb. 476 - divisor This option set the custom division. 477 - baud_base This option set the base baud rate. 478 - 479 - ----------------------------------------------------------------------------- 480 - 6. Troubleshooting 481 - 482 - The boot time error messages and solutions are stated as clearly as 483 - possible. If all the possible solutions fail, please contact our technical 484 - support team to get more help. 485 - 486 - 487 - Error msg: More than 4 Moxa Smartio/Industio family boards found. Fifth board 488 - and after are ignored. 489 - Solution: 490 - To avoid this problem, please unplug fifth and after board, because Moxa 491 - driver supports up to 4 boards. 492 - 493 - Error msg: Request_irq fail, IRQ(?) may be conflict with another device. 494 - Solution: 495 - Other PCI or ISA devices occupy the assigned IRQ. If you are not sure 496 - which device causes the situation, please check /proc/interrupts to find 497 - free IRQ and simply change another free IRQ for Moxa board. 498 - 499 - Error msg: Board #: C1xx Series(CAP=xxx) interrupt number invalid. 500 - Solution: 501 - Each port within the same multiport board shares the same IRQ. Please set 502 - one IRQ (IRQ doesn't equal to zero) for one Moxa board. 503 - 504 - Error msg: No interrupt vector be set for Moxa ISA board(CAP=xxx). 505 - Solution: 506 - Moxa ISA board needs an interrupt vector.Please refer to user's manual 507 - "Hardware Installation" chapter to set interrupt vector. 508 - 509 - Error msg: Couldn't install MOXA Smartio/Industio family driver! 510 - Solution: 511 - Load Moxa driver fail, the major number may conflict with other devices. 512 - Please refer to previous section 3.7 to change a free major number for 513 - Moxa driver. 514 - 515 - Error msg: Couldn't install MOXA Smartio/Industio family callout driver! 516 - Solution: 517 - Load Moxa callout driver fail, the callout device major number may 518 - conflict with other devices. Please refer to previous section 3.7 to 519 - change a free callout device major number for Moxa driver. 520 - 521 - 522 - ----------------------------------------------------------------------------- 523 -
+615
Documentation/serial/moxa-smartio.rst
··· 1 + ============================================================= 2 + MOXA Smartio/Industio Family Device Driver Installation Guide 3 + ============================================================= 4 + 5 + .. note:: 6 + 7 + This file is outdated. It needs some care in order to make it 8 + updated to Kernel 5.0 and upper 9 + 10 + Copyright (C) 2008, Moxa Inc. 11 + 12 + Date: 01/21/2008 13 + 14 + .. Content 15 + 16 + 1. Introduction 17 + 2. System Requirement 18 + 3. Installation 19 + 3.1 Hardware installation 20 + 3.2 Driver files 21 + 3.3 Device naming convention 22 + 3.4 Module driver configuration 23 + 3.5 Static driver configuration for Linux kernel 2.4.x and 2.6.x. 24 + 3.6 Custom configuration 25 + 3.7 Verify driver installation 26 + 4. Utilities 27 + 5. Setserial 28 + 6. Troubleshooting 29 + 30 + 1. Introduction 31 + ^^^^^^^^^^^^^^^ 32 + 33 + The Smartio/Industio/UPCI family Linux driver supports following multiport 34 + boards. 35 + 36 + - 2 ports multiport board 37 + CP-102U, CP-102UL, CP-102UF 38 + CP-132U-I, CP-132UL, 39 + CP-132, CP-132I, CP132S, CP-132IS, 40 + CI-132, CI-132I, CI-132IS, 41 + (C102H, C102HI, C102HIS, C102P, CP-102, CP-102S) 42 + 43 + - 4 ports multiport board 44 + CP-104EL, 45 + CP-104UL, CP-104JU, 46 + CP-134U, CP-134U-I, 47 + C104H/PCI, C104HS/PCI, 48 + CP-114, CP-114I, CP-114S, CP-114IS, CP-114UL, 49 + C104H, C104HS, 50 + CI-104J, CI-104JS, 51 + CI-134, CI-134I, CI-134IS, 52 + (C114HI, CT-114I, C104P), 53 + POS-104UL, 54 + CB-114, 55 + CB-134I 56 + 57 + - 8 ports multiport board 58 + CP-118EL, CP-168EL, 59 + CP-118U, CP-168U, 60 + C168H/PCI, 61 + C168H, C168HS, 62 + (C168P), 63 + CB-108 64 + 65 + This driver and installation procedure have been developed upon Linux Kernel 66 + 2.4.x and 2.6.x. This driver supports Intel x86 hardware platform. In order 67 + to maintain compatibility, this version has also been properly tested with 68 + RedHat, Mandrake, Fedora and S.u.S.E Linux. However, if compatibility problem 69 + occurs, please contact Moxa at support@moxa.com.tw. 70 + 71 + In addition to device driver, useful utilities are also provided in this 72 + version. They are: 73 + 74 + - msdiag 75 + Diagnostic program for displaying installed Moxa 76 + Smartio/Industio boards. 77 + - msmon 78 + Monitor program to observe data count and line status signals. 79 + - msterm A simple terminal program which is useful in testing serial 80 + ports. 81 + - io-irq.exe 82 + Configuration program to setup ISA boards. Please note that 83 + this program can only be executed under DOS. 84 + 85 + All the drivers and utilities are published in form of source code under 86 + GNU General Public License in this version. Please refer to GNU General 87 + Public License announcement in each source code file for more detail. 88 + 89 + In Moxa's Web sites, you may always find latest driver at http://www.moxa.com/. 90 + 91 + This version of driver can be installed as Loadable Module (Module driver) 92 + or built-in into kernel (Static driver). You may refer to following 93 + installation procedure for suitable one. Before you install the driver, 94 + please refer to hardware installation procedure in the User's Manual. 95 + 96 + We assume the user should be familiar with following documents. 97 + 98 + - Serial-HOWTO 99 + - Kernel-HOWTO 100 + 101 + 2. System Requirement 102 + ^^^^^^^^^^^^^^^^^^^^^ 103 + 104 + - Hardware platform: Intel x86 machine 105 + - Kernel version: 2.4.x or 2.6.x 106 + - gcc version 2.72 or later 107 + - Maximum 4 boards can be installed in combination 108 + 109 + 3. Installation 110 + ^^^^^^^^^^^^^^^ 111 + 112 + 3.1 Hardware installation 113 + ========================= 114 + 115 + There are two types of buses, ISA and PCI, for Smartio/Industio 116 + family multiport board. 117 + 118 + ISA board 119 + --------- 120 + 121 + You'll have to configure CAP address, I/O address, Interrupt Vector 122 + as well as IRQ before installing this driver. Please refer to hardware 123 + installation procedure in User's Manual before proceed any further. 124 + Please make sure the JP1 is open after the ISA board is set properly. 125 + 126 + PCI/UPCI board 127 + -------------- 128 + 129 + You may need to adjust IRQ usage in BIOS to avoid from IRQ conflict 130 + with other ISA devices. Please refer to hardware installation 131 + procedure in User's Manual in advance. 132 + 133 + PCI IRQ Sharing 134 + --------------- 135 + 136 + Each port within the same multiport board shares the same IRQ. Up to 137 + 4 Moxa Smartio/Industio PCI Family multiport boards can be installed 138 + together on one system and they can share the same IRQ. 139 + 140 + 141 + 3.2 Driver files 142 + ================ 143 + 144 + The driver file may be obtained from ftp, CD-ROM or floppy disk. The 145 + first step, anyway, is to copy driver file "mxser.tgz" into specified 146 + directory. e.g. /moxa. The execute commands as below:: 147 + 148 + # cd / 149 + # mkdir moxa 150 + # cd /moxa 151 + # tar xvf /dev/fd0 152 + 153 + or:: 154 + 155 + # cd / 156 + # mkdir moxa 157 + # cd /moxa 158 + # cp /mnt/cdrom/<driver directory>/mxser.tgz . 159 + # tar xvfz mxser.tgz 160 + 161 + 162 + 3.3 Device naming convention 163 + ============================ 164 + 165 + You may find all the driver and utilities files in /moxa/mxser. 166 + Following installation procedure depends on the model you'd like to 167 + run the driver. If you prefer module driver, please refer to 3.4. 168 + If static driver is required, please refer to 3.5. 169 + 170 + Dialin and callout port 171 + ----------------------- 172 + 173 + This driver remains traditional serial device properties. There are 174 + two special file name for each serial port. One is dial-in port 175 + which is named "ttyMxx". For callout port, the naming convention 176 + is "cumxx". 177 + 178 + Device naming when more than 2 boards installed 179 + ----------------------------------------------- 180 + 181 + Naming convention for each Smartio/Industio multiport board is 182 + pre-defined as below. 183 + 184 + ============ =============== ============== 185 + Board Num. Dial-in Port Callout port 186 + 1st board ttyM0 - ttyM7 cum0 - cum7 187 + 2nd board ttyM8 - ttyM15 cum8 - cum15 188 + 3rd board ttyM16 - ttyM23 cum16 - cum23 189 + 4th board ttyM24 - ttym31 cum24 - cum31 190 + ============ =============== ============== 191 + 192 + .. note:: 193 + 194 + Under Kernel 2.6 and upper, the cum Device is Obsolete. So use ttyM* 195 + device instead. 196 + 197 + Board sequence 198 + -------------- 199 + 200 + This driver will activate ISA boards according to the parameter set 201 + in the driver. After all specified ISA board activated, PCI board 202 + will be installed in the system automatically driven. 203 + Therefore the board number is sorted by the CAP address of ISA boards. 204 + For PCI boards, their sequence will be after ISA boards and C168H/PCI 205 + has higher priority than C104H/PCI boards. 206 + 207 + 3.4 Module driver configuration 208 + =============================== 209 + 210 + Module driver is easiest way to install. If you prefer static driver 211 + installation, please skip this paragraph. 212 + 213 + 214 + ------------- Prepare to use the MOXA driver -------------------- 215 + 216 + 3.4.1 Create tty device with correct major number 217 + ------------------------------------------------- 218 + 219 + Before using MOXA driver, your system must have the tty devices 220 + which are created with driver's major number. We offer one shell 221 + script "msmknod" to simplify the procedure. 222 + This step is only needed to be executed once. But you still 223 + need to do this procedure when: 224 + 225 + a. You change the driver's major number. Please refer the "3.7" 226 + section. 227 + b. Your total installed MOXA boards number is changed. Maybe you 228 + add/delete one MOXA board. 229 + c. You want to change the tty name. This needs to modify the 230 + shell script "msmknod" 231 + 232 + The procedure is:: 233 + 234 + # cd /moxa/mxser/driver 235 + # ./msmknod 236 + 237 + This shell script will require the major number for dial-in 238 + device and callout device to create tty device. You also need 239 + to specify the total installed MOXA board number. Default major 240 + numbers for dial-in device and callout device are 30, 35. If 241 + you need to change to other number, please refer section "3.7" 242 + for more detailed procedure. 243 + Msmknod will delete any special files occupying the same device 244 + naming. 245 + 246 + 3.4.2 Build the MOXA driver and utilities 247 + ----------------------------------------- 248 + 249 + Before using the MOXA driver and utilities, you need compile the 250 + all the source code. This step is only need to be executed once. 251 + But you still re-compile the source code if you modify the source 252 + code. For example, if you change the driver's major number (see 253 + "3.7" section), then you need to do this step again. 254 + 255 + Find "Makefile" in /moxa/mxser, then run 256 + 257 + # make clean; make install 258 + 259 + ..note:: 260 + 261 + For Red Hat 9, Red Hat Enterprise Linux AS3/ES3/WS3 & Fedora Core1: 262 + # make clean; make installsp1 263 + 264 + For Red Hat Enterprise Linux AS4/ES4/WS4: 265 + # make clean; make installsp2 266 + 267 + The driver files "mxser.o" and utilities will be properly compiled 268 + and copied to system directories respectively. 269 + 270 + ------------- Load MOXA driver-------------------- 271 + 272 + 3.4.3 Load the MOXA driver 273 + -------------------------- 274 + 275 + :: 276 + 277 + # modprobe mxser <argument> 278 + 279 + will activate the module driver. You may run "lsmod" to check 280 + if "mxser" is activated. If the MOXA board is ISA board, the 281 + <argument> is needed. Please refer to section "3.4.5" for more 282 + information. 283 + 284 + ------------- Load MOXA driver on boot -------------------- 285 + 286 + 3.4.4 Load the mxser driver 287 + --------------------------- 288 + 289 + 290 + For the above description, you may manually execute 291 + "modprobe mxser" to activate this driver and run 292 + "rmmod mxser" to remove it. 293 + 294 + However, it's better to have a boot time configuration to 295 + eliminate manual operation. Boot time configuration can be 296 + achieved by rc file. We offer one "rc.mxser" file to simplify 297 + the procedure under "moxa/mxser/driver". 298 + 299 + But if you use ISA board, please modify the "modprobe ..." command 300 + to add the argument (see "3.4.5" section). After modifying the 301 + rc.mxser, please try to execute "/moxa/mxser/driver/rc.mxser" 302 + manually to make sure the modification is ok. If any error 303 + encountered, please try to modify again. If the modification is 304 + completed, follow the below step. 305 + 306 + Run following command for setting rc files:: 307 + 308 + # cd /moxa/mxser/driver 309 + # cp ./rc.mxser /etc/rc.d 310 + # cd /etc/rc.d 311 + 312 + Check "rc.serial" is existed or not. If "rc.serial" doesn't exist, 313 + create it by vi, run "chmod 755 rc.serial" to change the permission. 314 + 315 + Add "/etc/rc.d/rc.mxser" in last line. 316 + 317 + Reboot and check if moxa.o activated by "lsmod" command. 318 + 319 + 3.4.5. specify CAP address 320 + -------------------------- 321 + 322 + If you'd like to drive Smartio/Industio ISA boards in the system, 323 + you'll have to add parameter to specify CAP address of given 324 + board while activating "mxser.o". The format for parameters are 325 + as follows.:: 326 + 327 + modprobe mxser ioaddr=0x???,0x???,0x???,0x??? 328 + | | | | 329 + | | | +- 4th ISA board 330 + | | +------ 3rd ISA board 331 + | +------------ 2nd ISA board 332 + +-------------------1st ISA board 333 + 334 + 3.5 Static driver configuration for Linux kernel 2.4.x and 2.6.x 335 + ================================================================ 336 + 337 + Note: 338 + To use static driver, you must install the linux kernel 339 + source package. 340 + 341 + 3.5.1 Backup the built-in driver in the kernel 342 + ---------------------------------------------- 343 + 344 + :: 345 + 346 + # cd /usr/src/linux/drivers/char 347 + # mv mxser.c mxser.c.old 348 + 349 + For Red Hat 7.x user, you need to create link: 350 + # cd /usr/src 351 + # ln -s linux-2.4 linux 352 + 353 + 3.5.2 Create link 354 + ----------------- 355 + :: 356 + 357 + # cd /usr/src/linux/drivers/char 358 + # ln -s /moxa/mxser/driver/mxser.c mxser.c 359 + 360 + 3.5.3 Add CAP address list for ISA boards. 361 + ------------------------------------------ 362 + 363 + For PCI boards user, please skip this step. 364 + 365 + In module mode, the CAP address for ISA board is given by 366 + parameter. In static driver configuration, you'll have to 367 + assign it within driver's source code. If you will not 368 + install any ISA boards, you may skip to next portion. 369 + The instructions to modify driver source code are as 370 + below. 371 + 372 + a. run:: 373 + 374 + # cd /moxa/mxser/driver 375 + # vi mxser.c 376 + 377 + b. Find the array mxserBoardCAP[] as below:: 378 + 379 + static int mxserBoardCAP[] = {0x00, 0x00, 0x00, 0x00}; 380 + 381 + c. Change the address within this array using vi. For 382 + example, to driver 2 ISA boards with CAP address 383 + 0x280 and 0x180 as 1st and 2nd board. Just to change 384 + the source code as follows:: 385 + 386 + static int mxserBoardCAP[] = {0x280, 0x180, 0x00, 0x00}; 387 + 388 + 3.5.4 Setup kernel configuration 389 + -------------------------------- 390 + 391 + Configure the kernel:: 392 + 393 + # cd /usr/src/linux 394 + # make menuconfig 395 + 396 + You will go into a menu-driven system. Please select [Character 397 + devices][Non-standard serial port support], enable the [Moxa 398 + SmartIO support] driver with "[*]" for built-in (not "[M]"), then 399 + select [Exit] to exit this program. 400 + 401 + 3.5.5 Rebuild kernel 402 + -------------------- 403 + 404 + The following are for Linux kernel rebuilding, for your 405 + reference only. 406 + 407 + For appropriate details, please refer to the Linux document: 408 + 409 + a. Run the following commands:: 410 + 411 + cd /usr/src/linux 412 + make clean # take a few minutes 413 + make dep # take a few minutes 414 + make bzImage # take probably 10-20 minutes 415 + make install # copy boot image to correct position 416 + 417 + f. Please make sure the boot kernel (vmlinuz) is in the 418 + correct position. 419 + g. If you use 'lilo' utility, you should check /etc/lilo.conf 420 + 'image' item specified the path which is the 'vmlinuz' path, 421 + or you will load wrong (or old) boot kernel image (vmlinuz). 422 + After checking /etc/lilo.conf, please run "lilo". 423 + 424 + Note that if the result of "make bzImage" is ERROR, then you have to 425 + go back to Linux configuration Setup. Type "make menuconfig" in 426 + directory /usr/src/linux. 427 + 428 + 429 + 3.5.6 Make tty device and special file 430 + -------------------------------------- 431 + 432 + :: 433 + # cd /moxa/mxser/driver 434 + # ./msmknod 435 + 436 + 3.5.7 Make utility 437 + ------------------ 438 + 439 + :: 440 + 441 + # cd /moxa/mxser/utility 442 + # make clean; make install 443 + 444 + 3.5.8 Reboot 445 + ------------ 446 + 447 + 448 + 449 + 3.6 Custom configuration 450 + ======================== 451 + 452 + Although this driver already provides you default configuration, you 453 + still can change the device name and major number. The instruction to 454 + change these parameters are shown as below. 455 + 456 + a. Change Device name 457 + 458 + If you'd like to use other device names instead of default naming 459 + convention, all you have to do is to modify the internal code 460 + within the shell script "msmknod". First, you have to open "msmknod" 461 + by vi. Locate each line contains "ttyM" and "cum" and change them 462 + to the device name you desired. "msmknod" creates the device names 463 + you need next time executed. 464 + 465 + b. Change Major number 466 + 467 + If major number 30 and 35 had been occupied, you may have to select 468 + 2 free major numbers for this driver. There are 3 steps to change 469 + major numbers. 470 + 471 + 3.6.1 Find free major numbers 472 + ----------------------------- 473 + 474 + In /proc/devices, you may find all the major numbers occupied 475 + in the system. Please select 2 major numbers that are available. 476 + e.g. 40, 45. 477 + 478 + 3.6.2 Create special files 479 + -------------------------- 480 + 481 + Run /moxa/mxser/driver/msmknod to create special files with 482 + specified major numbers. 483 + 484 + 3.6.3 Modify driver with new major number 485 + ----------------------------------------- 486 + 487 + Run vi to open /moxa/mxser/driver/mxser.c. Locate the line 488 + contains "MXSERMAJOR". Change the content as below:: 489 + 490 + #define MXSERMAJOR 40 491 + #define MXSERCUMAJOR 45 492 + 493 + 3.6.4 Run "make clean; make install" in /moxa/mxser/driver. 494 + 495 + 3.7 Verify driver installation 496 + ============================== 497 + 498 + You may refer to /var/log/messages to check the latest status 499 + log reported by this driver whenever it's activated. 500 + 501 + 4. Utilities 502 + ^^^^^^^^^^^^ 503 + 504 + There are 3 utilities contained in this driver. They are msdiag, msmon and 505 + msterm. These 3 utilities are released in form of source code. They should 506 + be compiled into executable file and copied into /usr/bin. 507 + 508 + Before using these utilities, please load driver (refer 3.4 & 3.5) and 509 + make sure you had run the "msmknod" utility. 510 + 511 + msdiag - Diagnostic 512 + =================== 513 + 514 + This utility provides the function to display what Moxa Smartio/Industio 515 + board found by driver in the system. 516 + 517 + msmon - Port Monitoring 518 + ======================= 519 + 520 + This utility gives the user a quick view about all the MOXA ports' 521 + activities. One can easily learn each port's total received/transmitted 522 + (Rx/Tx) character count since the time when the monitoring is started. 523 + 524 + Rx/Tx throughputs per second are also reported in interval basis (e.g. 525 + the last 5 seconds) and in average basis (since the time the monitoring 526 + is started). You can reset all ports' count by <HOME> key. <+> <-> 527 + (plus/minus) keys to change the displaying time interval. Press <ENTER> 528 + on the port, that cursor stay, to view the port's communication 529 + parameters, signal status, and input/output queue. 530 + 531 + msterm - Terminal Emulation 532 + =========================== 533 + 534 + This utility provides data sending and receiving ability of all tty ports, 535 + especially for MOXA ports. It is quite useful for testing simple 536 + application, for example, sending AT command to a modem connected to the 537 + port or used as a terminal for login purpose. Note that this is only a 538 + dumb terminal emulation without handling full screen operation. 539 + 540 + 5. Setserial 541 + ^^^^^^^^^^^^ 542 + 543 + Supported Setserial parameters are listed as below. 544 + 545 + ============== ========================================================= 546 + uart set UART type(16450-->disable FIFO, 16550A-->enable FIFO) 547 + close_delay set the amount of time(in 1/100 of a second) that DTR 548 + should be kept low while being closed. 549 + closing_wait set the amount of time(in 1/100 of a second) that the 550 + serial port should wait for data to be drained while 551 + being closed, before the receiver is disable. 552 + spd_hi Use 57.6kb when the application requests 38.4kb. 553 + spd_vhi Use 115.2kb when the application requests 38.4kb. 554 + spd_shi Use 230.4kb when the application requests 38.4kb. 555 + spd_warp Use 460.8kb when the application requests 38.4kb. 556 + spd_normal Use 38.4kb when the application requests 38.4kb. 557 + spd_cust Use the custom divisor to set the speed when the 558 + application requests 38.4kb. 559 + divisor This option set the custom division. 560 + baud_base This option set the base baud rate. 561 + ============== ========================================================= 562 + 563 + 6. Troubleshooting 564 + ^^^^^^^^^^^^^^^^^^ 565 + 566 + The boot time error messages and solutions are stated as clearly as 567 + possible. If all the possible solutions fail, please contact our technical 568 + support team to get more help. 569 + 570 + 571 + Error msg: 572 + More than 4 Moxa Smartio/Industio family boards found. Fifth board 573 + and after are ignored. 574 + 575 + Solution: 576 + To avoid this problem, please unplug fifth and after board, because Moxa 577 + driver supports up to 4 boards. 578 + 579 + Error msg: 580 + Request_irq fail, IRQ(?) may be conflict with another device. 581 + 582 + Solution: 583 + Other PCI or ISA devices occupy the assigned IRQ. If you are not sure 584 + which device causes the situation, please check /proc/interrupts to find 585 + free IRQ and simply change another free IRQ for Moxa board. 586 + 587 + Error msg: 588 + Board #: C1xx Series(CAP=xxx) interrupt number invalid. 589 + 590 + Solution: 591 + Each port within the same multiport board shares the same IRQ. Please set 592 + one IRQ (IRQ doesn't equal to zero) for one Moxa board. 593 + 594 + Error msg: 595 + No interrupt vector be set for Moxa ISA board(CAP=xxx). 596 + 597 + Solution: 598 + Moxa ISA board needs an interrupt vector.Please refer to user's manual 599 + "Hardware Installation" chapter to set interrupt vector. 600 + 601 + Error msg: 602 + Couldn't install MOXA Smartio/Industio family driver! 603 + 604 + Solution: 605 + Load Moxa driver fail, the major number may conflict with other devices. 606 + Please refer to previous section 3.7 to change a free major number for 607 + Moxa driver. 608 + 609 + Error msg: 610 + Couldn't install MOXA Smartio/Industio family callout driver! 611 + 612 + Solution: 613 + Load Moxa callout driver fail, the callout device major number may 614 + conflict with other devices. Please refer to previous section 3.7 to 615 + change a free callout device major number for Moxa driver.
+103
Documentation/serial/n_gsm.rst
··· 1 + ============================== 2 + GSM 0710 tty multiplexor HOWTO 3 + ============================== 4 + 5 + This line discipline implements the GSM 07.10 multiplexing protocol 6 + detailed in the following 3GPP document: 7 + 8 + http://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip 9 + 10 + This document give some hints on how to use this driver with GPRS and 3G 11 + modems connected to a physical serial port. 12 + 13 + How to use it 14 + ------------- 15 + 1. initialize the modem in 0710 mux mode (usually AT+CMUX= command) through 16 + its serial port. Depending on the modem used, you can pass more or less 17 + parameters to this command, 18 + 2. switch the serial line to using the n_gsm line discipline by using 19 + TIOCSETD ioctl, 20 + 3. configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl, 21 + 22 + Major parts of the initialization program : 23 + (a good starting point is util-linux-ng/sys-utils/ldattach.c):: 24 + 25 + #include <linux/gsmmux.h> 26 + #define N_GSM0710 21 /* GSM 0710 Mux */ 27 + #define DEFAULT_SPEED B115200 28 + #define SERIAL_PORT /dev/ttyS0 29 + 30 + int ldisc = N_GSM0710; 31 + struct gsm_config c; 32 + struct termios configuration; 33 + 34 + /* open the serial port connected to the modem */ 35 + fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY); 36 + 37 + /* configure the serial port : speed, flow control ... */ 38 + 39 + /* send the AT commands to switch the modem to CMUX mode 40 + and check that it's successful (should return OK) */ 41 + write(fd, "AT+CMUX=0\r", 10); 42 + 43 + /* experience showed that some modems need some time before 44 + being able to answer to the first MUX packet so a delay 45 + may be needed here in some case */ 46 + sleep(3); 47 + 48 + /* use n_gsm line discipline */ 49 + ioctl(fd, TIOCSETD, &ldisc); 50 + 51 + /* get n_gsm configuration */ 52 + ioctl(fd, GSMIOC_GETCONF, &c); 53 + /* we are initiator and need encoding 0 (basic) */ 54 + c.initiator = 1; 55 + c.encapsulation = 0; 56 + /* our modem defaults to a maximum size of 127 bytes */ 57 + c.mru = 127; 58 + c.mtu = 127; 59 + /* set the new configuration */ 60 + ioctl(fd, GSMIOC_SETCONF, &c); 61 + 62 + /* and wait for ever to keep the line discipline enabled */ 63 + daemon(0,0); 64 + pause(); 65 + 66 + 4. create the devices corresponding to the "virtual" serial ports (take care, 67 + each modem has its configuration and some DLC have dedicated functions, 68 + for example GPS), starting with minor 1 (DLC0 is reserved for the management 69 + of the mux):: 70 + 71 + MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}` 72 + for i in `seq 1 4`; do 73 + mknod /dev/ttygsm$i c $MAJOR $i 74 + done 75 + 76 + 5. use these devices as plain serial ports. 77 + 78 + for example, it's possible: 79 + 80 + - and to use gnokii to send / receive SMS on ttygsm1 81 + - to use ppp to establish a datalink on ttygsm2 82 + 83 + 6. first close all virtual ports before closing the physical port. 84 + 85 + Note that after closing the physical port the modem is still in multiplexing 86 + mode. This may prevent a successful re-opening of the port later. To avoid 87 + this situation either reset the modem if your hardware allows that or send 88 + a disconnect command frame manually before initializing the multiplexing mode 89 + for the second time. The byte sequence for the disconnect command frame is:: 90 + 91 + 0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9. 92 + 93 + Additional Documentation 94 + ------------------------ 95 + More practical details on the protocol and how it's supported by industrial 96 + modems can be found in the following documents : 97 + 98 + - http://www.telit.com/module/infopool/download.php?id=616 99 + - http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf 100 + - http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx 101 + - http://wm.sim.com/sim/News/photo/2010721161442.pdf 102 + 103 + 11-03-08 - Eric Bénard - <eric@eukrea.com>
-96
Documentation/serial/n_gsm.txt
··· 1 - n_gsm.c GSM 0710 tty multiplexor HOWTO 2 - =================================================== 3 - 4 - This line discipline implements the GSM 07.10 multiplexing protocol 5 - detailed in the following 3GPP document : 6 - http://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip 7 - 8 - This document give some hints on how to use this driver with GPRS and 3G 9 - modems connected to a physical serial port. 10 - 11 - How to use it 12 - ------------- 13 - 1- initialize the modem in 0710 mux mode (usually AT+CMUX= command) through 14 - its serial port. Depending on the modem used, you can pass more or less 15 - parameters to this command, 16 - 2- switch the serial line to using the n_gsm line discipline by using 17 - TIOCSETD ioctl, 18 - 3- configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl, 19 - 20 - Major parts of the initialization program : 21 - (a good starting point is util-linux-ng/sys-utils/ldattach.c) 22 - #include <linux/gsmmux.h> 23 - #define N_GSM0710 21 /* GSM 0710 Mux */ 24 - #define DEFAULT_SPEED B115200 25 - #define SERIAL_PORT /dev/ttyS0 26 - 27 - int ldisc = N_GSM0710; 28 - struct gsm_config c; 29 - struct termios configuration; 30 - 31 - /* open the serial port connected to the modem */ 32 - fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY); 33 - 34 - /* configure the serial port : speed, flow control ... */ 35 - 36 - /* send the AT commands to switch the modem to CMUX mode 37 - and check that it's successful (should return OK) */ 38 - write(fd, "AT+CMUX=0\r", 10); 39 - 40 - /* experience showed that some modems need some time before 41 - being able to answer to the first MUX packet so a delay 42 - may be needed here in some case */ 43 - sleep(3); 44 - 45 - /* use n_gsm line discipline */ 46 - ioctl(fd, TIOCSETD, &ldisc); 47 - 48 - /* get n_gsm configuration */ 49 - ioctl(fd, GSMIOC_GETCONF, &c); 50 - /* we are initiator and need encoding 0 (basic) */ 51 - c.initiator = 1; 52 - c.encapsulation = 0; 53 - /* our modem defaults to a maximum size of 127 bytes */ 54 - c.mru = 127; 55 - c.mtu = 127; 56 - /* set the new configuration */ 57 - ioctl(fd, GSMIOC_SETCONF, &c); 58 - 59 - /* and wait for ever to keep the line discipline enabled */ 60 - daemon(0,0); 61 - pause(); 62 - 63 - 4- create the devices corresponding to the "virtual" serial ports (take care, 64 - each modem has its configuration and some DLC have dedicated functions, 65 - for example GPS), starting with minor 1 (DLC0 is reserved for the management 66 - of the mux) 67 - 68 - MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}` 69 - for i in `seq 1 4`; do 70 - mknod /dev/ttygsm$i c $MAJOR $i 71 - done 72 - 73 - 5- use these devices as plain serial ports. 74 - for example, it's possible : 75 - - and to use gnokii to send / receive SMS on ttygsm1 76 - - to use ppp to establish a datalink on ttygsm2 77 - 78 - 6- first close all virtual ports before closing the physical port. 79 - 80 - Note that after closing the physical port the modem is still in multiplexing 81 - mode. This may prevent a successful re-opening of the port later. To avoid 82 - this situation either reset the modem if your hardware allows that or send 83 - a disconnect command frame manually before initializing the multiplexing mode 84 - for the second time. The byte sequence for the disconnect command frame is: 85 - 0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9. 86 - 87 - Additional Documentation 88 - ------------------------ 89 - More practical details on the protocol and how it's supported by industrial 90 - modems can be found in the following documents : 91 - http://www.telit.com/module/infopool/download.php?id=616 92 - http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf 93 - http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx 94 - http://wm.sim.com/sim/News/photo/2010721161442.pdf 95 - 96 - 11-03-08 - Eric Bénard - <eric@eukrea.com>
+70 -74
Documentation/serial/rocket.txt Documentation/serial/rocket.rst
··· 1 - Comtrol(tm) RocketPort(R)/RocketModem(TM) Series 1 + ================================================ 2 + Comtrol(tm) RocketPort(R)/RocketModem(TM) Series 3 + ================================================ 4 + 2 5 Device Driver for the Linux Operating System 6 + ============================================ 3 7 4 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 5 - 6 - PRODUCT OVERVIEW 8 + Product overview 7 9 ---------------- 8 10 9 11 This driver provides a loadable kernel driver for the Comtrol RocketPort 10 - and RocketModem PCI boards. These boards provide, 2, 4, 8, 16, or 32 12 + and RocketModem PCI boards. These boards provide, 2, 4, 8, 16, or 32 11 13 high-speed serial ports or modems. This driver supports up to a combination 12 14 of four RocketPort or RocketModems boards in one machine simultaneously. 13 15 This file assumes that you are using the RocketPort driver which is 14 - integrated into the kernel sources. 16 + integrated into the kernel sources. 15 17 16 - The driver can also be installed as an external module using the usual 17 - "make;make install" routine. This external module driver, obtainable 18 + The driver can also be installed as an external module using the usual 19 + "make;make install" routine. This external module driver, obtainable 18 20 from the Comtrol website listed below, is useful for updating the driver 19 21 or installing it into kernels which do not have the driver configured 20 22 into them. Installations instructions for the external module ··· 31 29 32 30 You pass the I/O port to the driver using the following module parameters: 33 31 34 - board1 : I/O port for the first ISA board 35 - board2 : I/O port for the second ISA board 36 - board3 : I/O port for the third ISA board 37 - board4 : I/O port for the fourth ISA board 32 + board1: 33 + I/O port for the first ISA board 34 + board2: 35 + I/O port for the second ISA board 36 + board3: 37 + I/O port for the third ISA board 38 + board4: 39 + I/O port for the fourth ISA board 38 40 39 41 There is a set of utilities and scripts provided with the external driver 40 - ( downloadable from http://www.comtrol.com ) that ease the configuration and 42 + (downloadable from http://www.comtrol.com) that ease the configuration and 41 43 setup of the ISA cards. 42 44 43 45 The RocketModem II PCI boards require firmware to be loaded into the card 44 46 before it will function. The driver has only been tested as a module for this 45 47 board. 46 48 47 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 48 - 49 - INSTALLATION PROCEDURES 49 + Installation Procedures 50 50 ----------------------- 51 51 52 - RocketPort/RocketModem PCI cards require no driver configuration, they are 52 + RocketPort/RocketModem PCI cards require no driver configuration, they are 53 53 automatically detected and configured. 54 54 55 - The RocketPort driver can be installed as a module (recommended) or built 55 + The RocketPort driver can be installed as a module (recommended) or built 56 56 into the kernel. This is selected, as for other drivers, through the `make config` 57 - command from the root of the Linux source tree during the kernel build process. 57 + command from the root of the Linux source tree during the kernel build process. 58 58 59 59 The RocketPort/RocketModem serial ports installed by this driver are assigned 60 - device major number 46, and will be named /dev/ttyRx, where x is the port number 60 + device major number 46, and will be named /dev/ttyRx, where x is the port number 61 61 starting at zero (ex. /dev/ttyR0, /devttyR1, ...). If you have multiple cards 62 62 installed in the system, the mapping of port names to serial ports is displayed 63 63 in the system log at /var/log/messages. 64 64 65 65 If installed as a module, the module must be loaded. This can be done 66 66 manually by entering "modprobe rocket". To have the module loaded automatically 67 - upon system boot, edit a /etc/modprobe.d/*.conf file and add the line 67 + upon system boot, edit a `/etc/modprobe.d/*.conf` file and add the line 68 68 "alias char-major-46 rocket". 69 69 70 70 In order to use the ports, their device names (nodes) must be created with mknod. 71 - This is only required once, the system will retain the names once created. To 72 - create the RocketPort/RocketModem device names, use the command 73 - "mknod /dev/ttyRx c 46 x" where x is the port number starting at zero. For example: 71 + This is only required once, the system will retain the names once created. To 72 + create the RocketPort/RocketModem device names, use the command 73 + "mknod /dev/ttyRx c 46 x" where x is the port number starting at zero. 74 74 75 - >mknod /dev/ttyR0 c 46 0 76 - >mknod /dev/ttyR1 c 46 1 77 - >mknod /dev/ttyR2 c 46 2 75 + For example:: 76 + 77 + > mknod /dev/ttyR0 c 46 0 78 + > mknod /dev/ttyR1 c 46 1 79 + > mknod /dev/ttyR2 c 46 2 78 80 79 81 The Linux script MAKEDEV will create the first 16 ttyRx device names (nodes) 80 - for you: 82 + for you:: 81 83 82 - >/dev/MAKEDEV ttyR 83 - 84 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 84 + >/dev/MAKEDEV ttyR 85 85 86 86 ISA Rocketport Boards 87 87 --------------------- ··· 93 89 switches on the Rocketport board. 94 90 95 91 96 - SETTING THE I/O ADDRESS 92 + Setting the I/O address 97 93 ----------------------- 98 94 99 95 Before installing RocketPort(R) or RocketPort RA boards, you must find ··· 134 130 need to set the second, third, or fourth board to one of the next available 135 131 blocks such as 0x180. 136 132 137 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 133 + RocketPort and RocketPort RA SW1 Settings:: 138 134 139 - RocketPort and RocketPort RA SW1 Settings: 135 + +-------------------------------+ 136 + | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 137 + +-------+-------+---------------+ 138 + | Unused| Card | I/O Port Block| 139 + +-------------------------------+ 140 140 141 - +-------------------------------+ 142 - | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 143 - +-------+-------+---------------+ 144 - | Unused| Card | I/O Port Block| 145 - +-------------------------------+ 141 + DIP Switches DIP Switches 142 + 7 8 6 5 143 + =================== =================== 144 + On On UNUSED, MUST BE ON. On On First Card <==== Default 145 + On Off Second Card 146 + Off On Third Card 147 + Off Off Fourth Card 146 148 147 - DIP Switches DIP Switches 148 - 7 8 6 5 149 - =================== =================== 150 - On On UNUSED, MUST BE ON. On On First Card <==== Default 151 - On Off Second Card 152 - Off On Third Card 153 - Off Off Fourth Card 149 + DIP Switches I/O Address Range 150 + 4 3 2 1 Used by the First Card 151 + ===================================== 152 + On Off On Off 100-143 153 + On Off Off On 140-183 154 + On Off Off Off 180-1C3 <==== Default 155 + Off On On Off 200-243 156 + Off On Off On 240-283 157 + Off On Off Off 280-2C3 158 + Off Off On Off 300-343 159 + Off Off Off On 340-383 160 + Off Off Off Off 380-3C3 154 161 155 - DIP Switches I/O Address Range 156 - 4 3 2 1 Used by the First Card 157 - ===================================== 158 - On Off On Off 100-143 159 - On Off Off On 140-183 160 - On Off Off Off 180-1C3 <==== Default 161 - Off On On Off 200-243 162 - Off On Off On 240-283 163 - Off On Off Off 280-2C3 164 - Off Off On Off 300-343 165 - Off Off Off On 340-383 166 - Off Off Off Off 380-3C3 167 - 168 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 169 - 170 - REPORTING BUGS 162 + Reporting Bugs 171 163 -------------- 172 164 173 165 For technical support, please provide the following ··· 171 171 kernel, and type of board you are using. Error messages and log 172 172 printouts port configuration details are especially helpful. 173 173 174 - USA 175 - Phone: (612) 494-4100 176 - FAX: (612) 494-4199 177 - email: support@comtrol.com 174 + USA: 175 + :Phone: (612) 494-4100 176 + :FAX: (612) 494-4199 177 + :email: support@comtrol.com 178 178 179 - Comtrol Europe 180 - Phone: +44 (0) 1 869 323-220 181 - FAX: +44 (0) 1 869 323-211 182 - email: support@comtrol.co.uk 179 + Comtrol Europe: 180 + :Phone: +44 (0) 1 869 323-220 181 + :FAX: +44 (0) 1 869 323-211 182 + :email: support@comtrol.co.uk 183 183 184 184 Web: http://www.comtrol.com 185 185 FTP: ftp.comtrol.com 186 - 187 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 188 - 189 -
+14 -7
Documentation/serial/serial-iso7816.txt Documentation/serial/serial-iso7816.rst
··· 1 - ISO7816 SERIAL COMMUNICATIONS 1 + ============================= 2 + ISO7816 Serial Communications 3 + ============================= 2 4 3 - 1. INTRODUCTION 5 + 1. Introduction 6 + =============== 4 7 5 8 ISO/IEC7816 is a series of standards specifying integrated circuit cards (ICC) 6 9 also known as smart cards. 7 10 8 - 2. HARDWARE-RELATED CONSIDERATIONS 11 + 2. Hardware-related considerations 12 + ================================== 9 13 10 14 Some CPUs/UARTs (e.g., Microchip AT91) contain a built-in mode capable of 11 15 handling communication with a smart card. ··· 19 15 available at user-level to allow switching from one mode to the other, and 20 16 vice versa. 21 17 22 - 3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL 18 + 3. Data Structures Already Available in the Kernel 19 + ================================================== 23 20 24 21 The Linux kernel provides the serial_iso7816 structure (see [1]) to handle 25 22 ISO7816 communications. This data structure is used to set and configure ··· 32 27 to TIOCGISO7816 and TIOCSISO7816 ioctls (see below). The iso7816_config 33 28 callback receives a pointer to struct serial_iso7816. 34 29 35 - 4. USAGE FROM USER-LEVEL 30 + 4. Usage from user-level 31 + ======================== 36 32 37 33 From user-level, ISO7816 configuration can be get/set using the previous 38 - ioctls. For instance, to set ISO7816 you can use the following code: 34 + ioctls. For instance, to set ISO7816 you can use the following code:: 39 35 40 36 #include <linux/serial.h> 41 37 ··· 84 78 /* Error handling. See errno. */ 85 79 } 86 80 87 - 5. REFERENCES 81 + 5. References 82 + ============= 88 83 89 84 [1] include/uapi/linux/serial.h
+15 -7
Documentation/serial/serial-rs485.txt Documentation/serial/serial-rs485.rst
··· 1 - RS485 SERIAL COMMUNICATIONS 1 + =========================== 2 + RS485 Serial Communications 3 + =========================== 2 4 3 - 1. INTRODUCTION 5 + 1. Introduction 6 + =============== 4 7 5 8 EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the 6 9 electrical characteristics of drivers and receivers for use in balanced ··· 12 9 because it can be used effectively over long distances and in electrically 13 10 noisy environments. 14 11 15 - 2. HARDWARE-RELATED CONSIDERATIONS 12 + 2. Hardware-related Considerations 13 + ================================== 16 14 17 15 Some CPUs/UARTs (e.g., Atmel AT91 or 16C950 UART) contain a built-in 18 16 half-duplex mode capable of automatically controlling line direction by ··· 26 22 available at user-level to allow switching from one mode to the other, and 27 23 vice versa. 28 24 29 - 3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL 25 + 3. Data Structures Already Available in the Kernel 26 + ================================================== 30 27 31 28 The Linux kernel provides the serial_rs485 structure (see [1]) to handle 32 29 RS485 communications. This data structure is used to set and configure RS485 ··· 43 38 to TIOCSRS485 and TIOCGRS485 ioctls (see below). The rs485_config callback 44 39 receives a pointer to struct serial_rs485. 45 40 46 - 4. USAGE FROM USER-LEVEL 41 + 4. Usage from user-level 42 + ======================== 47 43 48 44 From user-level, RS485 configuration can be get/set using the previous 49 - ioctls. For instance, to set RS485 you can use the following code: 45 + ioctls. For instance, to set RS485 you can use the following code:: 50 46 51 47 #include <linux/serial.h> 52 48 ··· 95 89 /* Error handling. See errno. */ 96 90 } 97 91 98 - 5. REFERENCES 92 + 5. References 93 + ============= 99 94 100 95 [1] include/uapi/linux/serial.h 96 + 101 97 [2] Documentation/devicetree/bindings/serial/rs485.txt
+63 -48
Documentation/serial/tty.txt Documentation/serial/tty.rst
··· 1 - 2 - The Lockronomicon 1 + ================= 2 + The Lockronomicon 3 + ================= 3 4 4 5 Your guide to the ancient and twisted locking policies of the tty layer and 5 6 the warped logic behind them. Beware all ye who read on. ··· 10 9 --------------- 11 10 12 11 Line disciplines are registered with tty_register_ldisc() passing the 13 - discipline number and the ldisc structure. At the point of registration the 12 + discipline number and the ldisc structure. At the point of registration the 14 13 discipline must be ready to use and it is possible it will get used before 15 14 the call returns success. If the call returns an error then it won't get 16 15 called. Do not re-use ldisc numbers as they are part of the userspace ABI 17 16 and writing over an existing ldisc will cause demons to eat your computer. 18 - After the return the ldisc data has been copied so you may free your own 17 + After the return the ldisc data has been copied so you may free your own 19 18 copy of the structure. You must not re-register over the top of the line 20 19 discipline even with the same data or your computer again will be eaten by 21 20 demons. ··· 27 26 28 27 Heed this warning: the reference count field of the registered copies of the 29 28 tty_ldisc structure in the ldisc table counts the number of lines using this 30 - discipline. The reference count of the tty_ldisc structure within a tty 29 + discipline. The reference count of the tty_ldisc structure within a tty 31 30 counts the number of active users of the ldisc at this instant. In effect it 32 31 counts the number of threads of execution within an ldisc method (plus those 33 32 about to enter and exit although this detail matters not). ··· 35 34 Line Discipline Methods 36 35 ----------------------- 37 36 38 - TTY side interfaces: 37 + TTY side interfaces 38 + ^^^^^^^^^^^^^^^^^^^ 39 39 40 - open() - Called when the line discipline is attached to 40 + ======================= ======================================================= 41 + open() Called when the line discipline is attached to 41 42 the terminal. No other call into the line 42 43 discipline for this tty will occur until it 43 44 completes successfully. Should initialize any ··· 50 47 Returning an error will prevent the ldisc from 51 48 being attached. Can sleep. 52 49 53 - close() - This is called on a terminal when the line 50 + close() This is called on a terminal when the line 54 51 discipline is being unplugged. At the point of 55 52 execution no further users will enter the 56 53 ldisc code for this tty. Can sleep. 57 54 58 - hangup() - Called when the tty line is hung up. 55 + hangup() Called when the tty line is hung up. 59 56 The line discipline should cease I/O to the tty. 60 57 No further calls into the ldisc code will occur. 61 58 The return value is ignored. Can sleep. 62 59 63 - read() - (optional) A process requests reading data from 60 + read() (optional) A process requests reading data from 64 61 the line. Multiple read calls may occur in parallel 65 62 and the ldisc must deal with serialization issues. 66 63 If not defined, the process will receive an EIO 67 64 error. May sleep. 68 65 69 - write() - (optional) A process requests writing data to the 66 + write() (optional) A process requests writing data to the 70 67 line. Multiple write calls are serialized by the 71 68 tty layer for the ldisc. If not defined, the 72 69 process will receive an EIO error. May sleep. 73 70 74 - flush_buffer() - (optional) May be called at any point between 71 + flush_buffer() (optional) May be called at any point between 75 72 open and close, and instructs the line discipline 76 73 to empty its input buffer. 77 74 78 - set_termios() - (optional) Called on termios structure changes. 75 + set_termios() (optional) Called on termios structure changes. 79 76 The caller passes the old termios data and the 80 77 current data is in the tty. Called under the 81 78 termios semaphore so allowed to sleep. Serialized 82 79 against itself only. 83 80 84 - poll() - (optional) Check the status for the poll/select 81 + poll() (optional) Check the status for the poll/select 85 82 calls. Multiple poll calls may occur in parallel. 86 83 May sleep. 87 84 88 - ioctl() - (optional) Called when an ioctl is handed to the 85 + ioctl() (optional) Called when an ioctl is handed to the 89 86 tty layer that might be for the ldisc. Multiple 90 87 ioctl calls may occur in parallel. May sleep. 91 88 92 - compat_ioctl() - (optional) Called when a 32 bit ioctl is handed 89 + compat_ioctl() (optional) Called when a 32 bit ioctl is handed 93 90 to the tty layer that might be for the ldisc. 94 91 Multiple ioctl calls may occur in parallel. 95 92 May sleep. 93 + ======================= ======================================================= 96 94 97 - Driver Side Interfaces: 95 + Driver Side Interfaces 96 + ^^^^^^^^^^^^^^^^^^^^^^ 98 97 99 - receive_buf() - (optional) Called by the low-level driver to hand 98 + ======================= ======================================================= 99 + receive_buf() (optional) Called by the low-level driver to hand 100 100 a buffer of received bytes to the ldisc for 101 101 processing. The number of bytes is guaranteed not 102 102 to exceed the current value of tty->receive_room. 103 103 All bytes must be processed. 104 104 105 - receive_buf2() - (optional) Called by the low-level driver to hand 105 + receive_buf2() (optional) Called by the low-level driver to hand 106 106 a buffer of received bytes to the ldisc for 107 107 processing. Returns the number of bytes processed. 108 108 109 109 If both receive_buf() and receive_buf2() are 110 110 defined, receive_buf2() should be preferred. 111 111 112 - write_wakeup() - May be called at any point between open and close. 112 + write_wakeup() May be called at any point between open and close. 113 113 The TTY_DO_WRITE_WAKEUP flag indicates if a call 114 114 is needed but always races versus calls. Thus the 115 115 ldisc must be careful about setting order and to ··· 123 117 is permitted to call the driver write method from 124 118 this function. In such a situation defer it. 125 119 126 - dcd_change() - Report to the tty line the current DCD pin status 120 + dcd_change() Report to the tty line the current DCD pin status 127 121 changes and the relative timestamp. The timestamp 128 122 cannot be NULL. 123 + ======================= ======================================================= 129 124 130 125 131 126 Driver Access 127 + ^^^^^^^^^^^^^ 132 128 133 129 Line discipline methods can call the following methods of the underlying 134 130 hardware driver through the function pointers within the tty->driver 135 131 structure: 136 132 133 + ======================= ======================================================= 137 134 write() Write a block of characters to the tty device. 138 135 Returns the number of characters accepted. The 139 136 character buffer passed to this method is already ··· 198 189 characters in its transmitter FIFO. 199 190 200 191 send_xchar() Send a high-priority XON/XOFF character to the device. 192 + ======================= ======================================================= 201 193 202 194 203 195 Flags 196 + ^^^^^ 204 197 205 198 Line discipline methods have access to tty->flags field containing the 206 199 following interesting flags: 207 200 201 + ======================= ======================================================= 208 202 TTY_THROTTLED Driver input is throttled. The ldisc should call 209 203 tty->driver->unthrottle() in order to resume 210 204 reception when it is ready to process more data. ··· 224 212 225 213 TTY_NO_WRITE_SPLIT Prevent driver from splitting up writes into 226 214 smaller chunks. 215 + ======================= ======================================================= 227 216 228 217 229 218 Locking 219 + ^^^^^^^ 230 220 231 221 Callers to the line discipline functions from the tty layer are required to 232 222 take line discipline locks. The same is true of calls from the driver side 233 223 but not yet enforced. 234 224 235 - Three calls are now provided 225 + Three calls are now provided:: 236 226 237 227 ldisc = tty_ldisc_ref(tty); 238 228 239 229 takes a handle to the line discipline in the tty and returns it. If no ldisc 240 230 is currently attached or the ldisc is being closed and re-opened at this 241 231 point then NULL is returned. While this handle is held the ldisc will not 242 - change or go away. 232 + change or go away:: 243 233 244 234 tty_ldisc_deref(ldisc) 245 235 246 236 Returns the ldisc reference and allows the ldisc to be closed. Returning the 247 237 reference takes away your right to call the ldisc functions until you take 248 - a new reference. 238 + a new reference:: 249 239 250 240 ldisc = tty_ldisc_ref_wait(tty); 251 241 252 242 Performs the same function as tty_ldisc_ref except that it will wait for an 253 - ldisc change to complete and then return a reference to the new ldisc. 243 + ldisc change to complete and then return a reference to the new ldisc. 254 244 255 245 While these functions are slightly slower than the old code they should have 256 246 minimal impact as most receive logic uses the flip buffers and they only 257 247 need to take a reference when they push bits up through the driver. 258 248 259 - A caution: The ldisc->open(), ldisc->close() and driver->set_ldisc 249 + A caution: The ldisc->open(), ldisc->close() and driver->set_ldisc 260 250 functions are called with the ldisc unavailable. Thus tty_ldisc_ref will 261 251 fail in this situation if used within these functions. Ldisc and driver 262 - code calling its own functions must be careful in this case. 252 + code calling its own functions must be careful in this case. 263 253 264 254 265 255 Driver Interface 266 256 ---------------- 267 257 268 - open() - Called when a device is opened. May sleep 258 + ======================= ======================================================= 259 + open() Called when a device is opened. May sleep 269 260 270 - close() - Called when a device is closed. At the point of 271 - return from this call the driver must make no 261 + close() Called when a device is closed. At the point of 262 + return from this call the driver must make no 272 263 further ldisc calls of any kind. May sleep 273 264 274 - write() - Called to write bytes to the device. May not 275 - sleep. May occur in parallel in special cases. 265 + write() Called to write bytes to the device. May not 266 + sleep. May occur in parallel in special cases. 276 267 Because this includes panic paths drivers generally 277 268 shouldn't try and do clever locking here. 278 269 279 - put_char() - Stuff a single character onto the queue. The 270 + put_char() Stuff a single character onto the queue. The 280 271 driver is guaranteed following up calls to 281 272 flush_chars. 282 273 283 - flush_chars() - Ask the kernel to write put_char queue 274 + flush_chars() Ask the kernel to write put_char queue 284 275 285 - write_room() - Return the number of characters that can be stuffed 276 + write_room() Return the number of characters that can be stuffed 286 277 into the port buffers without overflow (or less). 287 278 The ldisc is responsible for being intelligent 288 - about multi-threading of write_room/write calls 279 + about multi-threading of write_room/write calls 289 280 290 - ioctl() - Called when an ioctl may be for the driver 281 + ioctl() Called when an ioctl may be for the driver 291 282 292 - set_termios() - Called on termios change, serialized against 283 + set_termios() Called on termios change, serialized against 293 284 itself by a semaphore. May sleep. 294 285 295 - set_ldisc() - Notifier for discipline change. At the point this 286 + set_ldisc() Notifier for discipline change. At the point this 296 287 is done the discipline is not yet usable. Can now 297 288 sleep (I think) 298 289 299 - throttle() - Called by the ldisc to ask the driver to do flow 290 + throttle() Called by the ldisc to ask the driver to do flow 300 291 control. Serialization including with unthrottle 301 292 is the job of the ldisc layer. 302 293 303 - unthrottle() - Called by the ldisc to ask the driver to stop flow 294 + unthrottle() Called by the ldisc to ask the driver to stop flow 304 295 control. 305 296 306 - stop() - Ldisc notifier to the driver to stop output. As with 297 + stop() Ldisc notifier to the driver to stop output. As with 307 298 throttle the serializations with start() are down 308 299 to the ldisc layer. 309 300 310 - start() - Ldisc notifier to the driver to start output. 301 + start() Ldisc notifier to the driver to start output. 311 302 312 - hangup() - Ask the tty driver to cause a hangup initiated 303 + hangup() Ask the tty driver to cause a hangup initiated 313 304 from the host side. [Can sleep ??] 314 305 315 - break_ctl() - Send RS232 break. Can sleep. Can get called in 306 + break_ctl() Send RS232 break. Can sleep. Can get called in 316 307 parallel, driver must serialize (for now), and 317 308 with write calls. 318 309 319 - wait_until_sent() - Wait for characters to exit the hardware queue 310 + wait_until_sent() Wait for characters to exit the hardware queue 320 311 of the driver. Can sleep 321 312 322 - send_xchar() - Send XON/XOFF and if possible jump the queue with 313 + send_xchar() Send XON/XOFF and if possible jump the queue with 323 314 it in order to get fast flow control responses. 324 315 Cannot sleep ?? 325 - 316 + ======================= =======================================================
+2 -2
MAINTAINERS
··· 10466 10466 MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD 10467 10467 M: Jiri Slaby <jirislaby@gmail.com> 10468 10468 S: Maintained 10469 - F: Documentation/serial/moxa-smartio 10469 + F: Documentation/serial/moxa-smartio.rst 10470 10470 F: drivers/tty/mxser.* 10471 10471 10472 10472 MR800 AVERMEDIA USB FM RADIO DRIVER ··· 13376 13376 P: Comtrol Corp. 13377 13377 W: http://www.comtrol.com 13378 13378 S: Maintained 13379 - F: Documentation/serial/rocket.txt 13379 + F: Documentation/serial/rocket.rst 13380 13380 F: drivers/tty/rocket* 13381 13381 13382 13382 ROCKETPORT EXPRESS/INFINITY DRIVER
+2 -1
drivers/char/virtio_console.c
··· 75 75 /* All the console devices handled by this driver */ 76 76 struct list_head consoles; 77 77 }; 78 - static struct ports_driver_data pdrvdata; 78 + static struct ports_driver_data pdrvdata = { .next_vtermno = 1}; 79 79 80 80 static DEFINE_SPINLOCK(pdrvdata_lock); 81 81 static DECLARE_COMPLETION(early_console_added); ··· 1394 1394 port->async_queue = NULL; 1395 1395 1396 1396 port->cons.ws.ws_row = port->cons.ws.ws_col = 0; 1397 + port->cons.vtermno = 0; 1397 1398 1398 1399 port->host_connected = port->guest_connected = false; 1399 1400 port->stats = (struct port_stats) { 0 };
+17 -5
drivers/tty/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 config TTY 2 3 bool "Enable TTY" if EXPERT 3 4 default y ··· 84 83 config VT_HW_CONSOLE_BINDING 85 84 bool "Support for binding and unbinding console drivers" 86 85 depends on HW_CONSOLE 87 - default n 88 86 ---help--- 89 87 The virtual terminal is the device that interacts with the physical 90 88 terminal through console drivers. On these systems, at least one ··· 175 175 This driver supports Comtrol RocketPort and RocketModem PCI boards. 176 176 These boards provide 2, 4, 8, 16, or 32 high-speed serial ports or 177 177 modems. For information about the RocketPort/RocketModem boards 178 - and this driver read <file:Documentation/serial/rocket.txt>. 178 + and this driver read <file:Documentation/serial/rocket.rst>. 179 179 180 180 To compile this driver as a module, choose M here: the 181 181 module will be called rocket. ··· 193 193 your Linux box, for instance in order to become a dial-in server. 194 194 195 195 For information about the Cyclades-Z card, read 196 - <file:Documentation/serial/README.cycladesZ>. 196 + <file:Documentation/serial/cyclades_z.rst>. 197 197 198 198 To compile this driver as a module, choose M here: the 199 199 module will be called cyclades. ··· 312 312 config TRACE_ROUTER 313 313 tristate "Trace data router for MIPI P1149.7 cJTAG standard" 314 314 depends on TRACE_SINK 315 - default n 316 315 help 317 316 The trace router uses the Linux tty line discipline framework to 318 317 route trace data coming from a tty port (say UART for example) to ··· 327 328 328 329 config TRACE_SINK 329 330 tristate "Trace data sink for MIPI P1149.7 cJTAG standard" 330 - default n 331 331 help 332 332 The trace sink uses the Linux line discipline framework to receive 333 333 trace data coming from the trace router line discipline driver ··· 373 375 If the number you specify is not a valid byte channel handle, then 374 376 there simply will be no early console output. This is true also 375 377 if you don't boot under a hypervisor at all. 378 + 379 + config NULL_TTY 380 + tristate "NULL TTY driver" 381 + help 382 + Say Y here if you want a NULL TTY which simply discards messages. 383 + 384 + This is useful to allow userspace applications which expect a console 385 + device to work without modifications even when no console is 386 + available or desired. 387 + 388 + In order to use this driver, you should redirect the console to this 389 + TTY, or boot the kernel with console=ttynull. 390 + 391 + If unsure, say N. 376 392 377 393 config GOLDFISH_TTY 378 394 tristate "Goldfish TTY Driver"
+1
drivers/tty/Makefile
··· 25 25 obj-$(CONFIG_MOXA_INTELLIO) += moxa.o 26 26 obj-$(CONFIG_MOXA_SMARTIO) += mxser.o 27 27 obj-$(CONFIG_NOZOMI) += nozomi.o 28 + obj-$(CONFIG_NULL_TTY) += ttynull.o 28 29 obj-$(CONFIG_ROCKETPORT) += rocket.o 29 30 obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o 30 31 obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o
+1 -2
drivers/tty/hvc/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 if TTY 2 3 3 4 config HVC_DRIVER ··· 25 24 config HVC_OLD_HVSI 26 25 bool "Old driver for pSeries serial port (/dev/hvsi*)" 27 26 depends on HVC_CONSOLE 28 - default n 29 27 30 28 config HVC_OPAL 31 29 bool "OPAL Console support" ··· 73 73 bool "udbg based fake hypervisor console" 74 74 depends on PPC 75 75 select HVC_DRIVER 76 - default n 77 76 help 78 77 This is meant to be used during HW bring up or debugging when 79 78 no other console mechanism exist but udbg, to get you a quick
+1
drivers/tty/ipwireless/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Makefile for the IPWireless driver 3 4 #
+8
drivers/tty/ipwireless/main.c
··· 114 114 115 115 ipw->common_memory = ioremap(p_dev->resource[2]->start, 116 116 resource_size(p_dev->resource[2])); 117 + if (!ipw->common_memory) { 118 + ret = -ENOMEM; 119 + goto exit1; 120 + } 117 121 if (!request_mem_region(p_dev->resource[2]->start, 118 122 resource_size(p_dev->resource[2]), 119 123 IPWIRELESS_PCCARD_NAME)) { ··· 138 134 139 135 ipw->attr_memory = ioremap(p_dev->resource[3]->start, 140 136 resource_size(p_dev->resource[3])); 137 + if (!ipw->attr_memory) { 138 + ret = -ENOMEM; 139 + goto exit3; 140 + } 141 141 if (!request_mem_region(p_dev->resource[3]->start, 142 142 resource_size(p_dev->resource[3]), 143 143 IPWIRELESS_PCCARD_NAME)) {
+2 -2
drivers/tty/n_tty.c
··· 550 550 mutex_lock(&ldata->output_lock); 551 551 552 552 space = tty_write_room(tty); 553 - if (!space) { 553 + if (space <= 0) { 554 554 mutex_unlock(&ldata->output_lock); 555 - return 0; 555 + return space; 556 556 } 557 557 if (nr > space) 558 558 nr = space;
+10 -4
drivers/tty/rocket.c
··· 1283 1283 return -ENXIO; 1284 1284 1285 1285 switch (cmd) { 1286 - case RCKP_GET_STRUCT: 1287 - if (copy_to_user(argp, info, sizeof (struct r_port))) 1288 - ret = -EFAULT; 1289 - break; 1290 1286 case RCKP_GET_CONFIG: 1287 + dev_warn_ratelimited(tty->dev, 1288 + "RCKP_GET_CONFIG option is deprecated\n"); 1291 1289 ret = get_config(info, argp); 1292 1290 break; 1293 1291 case RCKP_SET_CONFIG: 1292 + dev_warn_ratelimited(tty->dev, 1293 + "RCKP_SET_CONFIG option is deprecated\n"); 1294 1294 ret = set_config(tty, info, argp); 1295 1295 break; 1296 1296 case RCKP_GET_PORTS: 1297 + dev_warn_ratelimited(tty->dev, 1298 + "RCKP_GET_PORTS option is deprecated\n"); 1297 1299 ret = get_ports(info, argp); 1298 1300 break; 1299 1301 case RCKP_RESET_RM2: 1302 + dev_warn_ratelimited(tty->dev, 1303 + "RCKP_RESET_RM2 option is deprecated\n"); 1300 1304 ret = reset_rm2(info, argp); 1301 1305 break; 1302 1306 case RCKP_GET_VERSION: 1307 + dev_warn_ratelimited(tty->dev, 1308 + "RCKP_GET_VERSION option is deprecated\n"); 1303 1309 ret = get_version(info, argp); 1304 1310 break; 1305 1311 default:
-1
drivers/tty/rocket.h
··· 71 71 /* 72 72 * Rocketport ioctls -- "RP" 73 73 */ 74 - #define RCKP_GET_STRUCT 0x00525001 75 74 #define RCKP_GET_CONFIG 0x00525002 76 75 #define RCKP_SET_CONFIG 0x00525003 77 76 #define RCKP_GET_PORTS 0x00525004
+1
drivers/tty/serdev/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Serial bus device driver configuration 3 4 #
+1
drivers/tty/serdev/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 serdev-objs := core.o 2 3 3 4 obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o
+5 -2
drivers/tty/serial/8250/8250_exar.c
··· 361 361 .register_gpio = iot2040_register_gpio, 362 362 }; 363 363 364 + /* 365 + * For SIMATIC IOT2000, only IOT2040 and its variants have the Exar device, 366 + * IOT2020 doesn't have. Therefore it is sufficient to match on the common 367 + * board name after the device was found. 368 + */ 364 369 static const struct dmi_system_id exar_platforms[] = { 365 370 { 366 371 .matches = { 367 372 DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"), 368 - DMI_EXACT_MATCH(DMI_BOARD_ASSET_TAG, 369 - "6ES7647-0AA00-1YA2"), 370 373 }, 371 374 .driver_data = (void *)&iot2040_platform, 372 375 },
+3 -2
drivers/tty/serial/8250/8250_fintek.c
··· 303 303 } 304 304 } 305 305 306 - void fintek_8250_set_termios(struct uart_port *port, struct ktermios *termios, 307 - struct ktermios *old) 306 + static void fintek_8250_set_termios(struct uart_port *port, 307 + struct ktermios *termios, 308 + struct ktermios *old) 308 309 { 309 310 struct fintek_8250 *pdata = port->private_data; 310 311 unsigned int baud = tty_termios_baud_rate(termios);
+1
drivers/tty/serial/8250/8250_men_mcb.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 #include <linux/device.h> 2 3 #include <linux/kernel.h> 3 4 #include <linux/module.h>
+139 -23
drivers/tty/serial/8250/8250_mtk.c
··· 21 21 22 22 #include "8250.h" 23 23 24 - #define UART_MTK_HIGHS 0x09 /* Highspeed register */ 25 - #define UART_MTK_SAMPLE_COUNT 0x0a /* Sample count register */ 26 - #define UART_MTK_SAMPLE_POINT 0x0b /* Sample point register */ 24 + #define MTK_UART_HIGHS 0x09 /* Highspeed register */ 25 + #define MTK_UART_SAMPLE_COUNT 0x0a /* Sample count register */ 26 + #define MTK_UART_SAMPLE_POINT 0x0b /* Sample point register */ 27 27 #define MTK_UART_RATE_FIX 0x0d /* UART Rate Fix Register */ 28 - 28 + #define MTK_UART_ESCAPE_DAT 0x10 /* Escape Character register */ 29 + #define MTK_UART_ESCAPE_EN 0x11 /* Escape Enable register */ 29 30 #define MTK_UART_DMA_EN 0x13 /* DMA Enable register */ 31 + #define MTK_UART_RXTRI_AD 0x14 /* RX Trigger address */ 32 + #define MTK_UART_FRACDIV_L 0x15 /* Fractional divider LSB address */ 33 + #define MTK_UART_FRACDIV_M 0x16 /* Fractional divider MSB address */ 34 + #define MTK_UART_IER_XOFFI 0x20 /* Enable XOFF character interrupt */ 35 + #define MTK_UART_IER_RTSI 0x40 /* Enable RTS Modem status interrupt */ 36 + #define MTK_UART_IER_CTSI 0x80 /* Enable CTS Modem status interrupt */ 37 + 38 + #define MTK_UART_EFR_EN 0x10 /* Enable enhancement feature */ 39 + #define MTK_UART_EFR_RTS 0x40 /* Enable hardware rx flow control */ 40 + #define MTK_UART_EFR_CTS 0x80 /* Enable hardware tx flow control */ 41 + #define MTK_UART_EFR_NO_SW_FC 0x0 /* no sw flow control */ 42 + #define MTK_UART_EFR_XON1_XOFF1 0xa /* XON1/XOFF1 as sw flow control */ 43 + #define MTK_UART_EFR_XON2_XOFF2 0x5 /* XON2/XOFF2 as sw flow control */ 44 + #define MTK_UART_EFR_SW_FC_MASK 0xf /* Enable CTS Modem status interrupt */ 45 + #define MTK_UART_EFR_HW_FC (MTK_UART_EFR_RTS | MTK_UART_EFR_CTS) 30 46 #define MTK_UART_DMA_EN_TX 0x2 31 47 #define MTK_UART_DMA_EN_RX 0x5 32 48 49 + #define MTK_UART_ESCAPE_CHAR 0x77 /* Escape char added under sw fc */ 33 50 #define MTK_UART_TX_SIZE UART_XMIT_SIZE 34 51 #define MTK_UART_RX_SIZE 0x8000 35 52 #define MTK_UART_TX_TRIGGER 1 ··· 63 46 struct mtk8250_data { 64 47 int line; 65 48 unsigned int rx_pos; 49 + unsigned int clk_count; 66 50 struct clk *uart_clk; 67 51 struct clk *bus_clk; 68 52 struct uart_8250_dma *dma; 69 53 #ifdef CONFIG_SERIAL_8250_DMA 70 54 enum dma_rx_status rx_status; 71 55 #endif 56 + }; 57 + 58 + /* flow control mode */ 59 + enum { 60 + MTK_UART_FC_NONE, 61 + MTK_UART_FC_SW, 62 + MTK_UART_FC_HW, 72 63 }; 73 64 74 65 #ifdef CONFIG_SERIAL_8250_DMA ··· 217 192 return serial8250_do_shutdown(port); 218 193 } 219 194 195 + static void mtk8250_disable_intrs(struct uart_8250_port *up, int mask) 196 + { 197 + serial_out(up, UART_IER, serial_in(up, UART_IER) & (~mask)); 198 + } 199 + 200 + static void mtk8250_enable_intrs(struct uart_8250_port *up, int mask) 201 + { 202 + serial_out(up, UART_IER, serial_in(up, UART_IER) | mask); 203 + } 204 + 205 + static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode) 206 + { 207 + struct uart_port *port = &up->port; 208 + int lcr = serial_in(up, UART_LCR); 209 + 210 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 211 + serial_out(up, UART_EFR, UART_EFR_ECB); 212 + serial_out(up, UART_LCR, lcr); 213 + lcr = serial_in(up, UART_LCR); 214 + 215 + switch (mode) { 216 + case MTK_UART_FC_NONE: 217 + serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR); 218 + serial_out(up, MTK_UART_ESCAPE_EN, 0x00); 219 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 220 + serial_out(up, UART_EFR, serial_in(up, UART_EFR) & 221 + (~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK))); 222 + serial_out(up, UART_LCR, lcr); 223 + mtk8250_disable_intrs(up, MTK_UART_IER_XOFFI | 224 + MTK_UART_IER_RTSI | MTK_UART_IER_CTSI); 225 + break; 226 + 227 + case MTK_UART_FC_HW: 228 + serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR); 229 + serial_out(up, MTK_UART_ESCAPE_EN, 0x00); 230 + serial_out(up, UART_MCR, UART_MCR_RTS); 231 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 232 + 233 + /*enable hw flow control*/ 234 + serial_out(up, UART_EFR, MTK_UART_EFR_HW_FC | 235 + (serial_in(up, UART_EFR) & 236 + (~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK)))); 237 + 238 + serial_out(up, UART_LCR, lcr); 239 + mtk8250_disable_intrs(up, MTK_UART_IER_XOFFI); 240 + mtk8250_enable_intrs(up, MTK_UART_IER_CTSI | MTK_UART_IER_RTSI); 241 + break; 242 + 243 + case MTK_UART_FC_SW: /*MTK software flow control */ 244 + serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR); 245 + serial_out(up, MTK_UART_ESCAPE_EN, 0x01); 246 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 247 + 248 + /*enable sw flow control */ 249 + serial_out(up, UART_EFR, MTK_UART_EFR_XON1_XOFF1 | 250 + (serial_in(up, UART_EFR) & 251 + (~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK)))); 252 + 253 + serial_out(up, UART_XON1, START_CHAR(port->state->port.tty)); 254 + serial_out(up, UART_XOFF1, STOP_CHAR(port->state->port.tty)); 255 + serial_out(up, UART_LCR, lcr); 256 + mtk8250_disable_intrs(up, MTK_UART_IER_CTSI|MTK_UART_IER_RTSI); 257 + mtk8250_enable_intrs(up, MTK_UART_IER_XOFFI); 258 + break; 259 + default: 260 + break; 261 + } 262 + } 263 + 220 264 static void 221 265 mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, 222 266 struct ktermios *old) 223 267 { 268 + unsigned short fraction_L_mapping[] = { 269 + 0, 1, 0x5, 0x15, 0x55, 0x57, 0x57, 0x77, 0x7F, 0xFF, 0xFF 270 + }; 271 + unsigned short fraction_M_mapping[] = { 272 + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3 273 + }; 224 274 struct uart_8250_port *up = up_to_u8250p(port); 275 + unsigned int baud, quot, fraction; 225 276 unsigned long flags; 226 - unsigned int baud, quot; 277 + int mode; 227 278 228 279 #ifdef CONFIG_SERIAL_8250_DMA 229 280 if (up->dma) { ··· 315 214 serial8250_do_set_termios(port, termios, old); 316 215 317 216 /* 318 - * Mediatek UARTs use an extra highspeed register (UART_MTK_HIGHS) 217 + * Mediatek UARTs use an extra highspeed register (MTK_UART_HIGHS) 319 218 * 320 219 * We need to recalcualte the quot register, as the claculation depends 321 220 * on the vaule in the highspeed register. ··· 331 230 port->uartclk / 16 / UART_DIV_MAX, 332 231 port->uartclk); 333 232 334 - if (baud <= 115200) { 335 - serial_port_out(port, UART_MTK_HIGHS, 0x0); 233 + if (baud < 115200) { 234 + serial_port_out(port, MTK_UART_HIGHS, 0x0); 336 235 quot = uart_get_divisor(port, baud); 337 - } else if (baud <= 576000) { 338 - serial_port_out(port, UART_MTK_HIGHS, 0x2); 339 - 340 - /* Set to next lower baudrate supported */ 341 - if ((baud == 500000) || (baud == 576000)) 342 - baud = 460800; 343 - quot = DIV_ROUND_UP(port->uartclk, 4 * baud); 344 236 } else { 345 - serial_port_out(port, UART_MTK_HIGHS, 0x3); 237 + serial_port_out(port, MTK_UART_HIGHS, 0x3); 346 238 quot = DIV_ROUND_UP(port->uartclk, 256 * baud); 347 239 } 348 240 ··· 352 258 /* reset DLAB */ 353 259 serial_port_out(port, UART_LCR, up->lcr); 354 260 355 - if (baud > 460800) { 261 + if (baud >= 115200) { 356 262 unsigned int tmp; 357 263 358 - tmp = DIV_ROUND_CLOSEST(port->uartclk, quot * baud); 359 - serial_port_out(port, UART_MTK_SAMPLE_COUNT, tmp - 1); 360 - serial_port_out(port, UART_MTK_SAMPLE_POINT, 361 - (tmp - 2) >> 1); 264 + tmp = (port->uartclk / (baud * quot)) - 1; 265 + serial_port_out(port, MTK_UART_SAMPLE_COUNT, tmp); 266 + serial_port_out(port, MTK_UART_SAMPLE_POINT, 267 + (tmp >> 1) - 1); 268 + 269 + /*count fraction to set fractoin register */ 270 + fraction = ((port->uartclk * 100) / baud / quot) % 100; 271 + fraction = DIV_ROUND_CLOSEST(fraction, 10); 272 + serial_port_out(port, MTK_UART_FRACDIV_L, 273 + fraction_L_mapping[fraction]); 274 + serial_port_out(port, MTK_UART_FRACDIV_M, 275 + fraction_M_mapping[fraction]); 362 276 } else { 363 - serial_port_out(port, UART_MTK_SAMPLE_COUNT, 0x00); 364 - serial_port_out(port, UART_MTK_SAMPLE_POINT, 0xff); 277 + serial_port_out(port, MTK_UART_SAMPLE_COUNT, 0x00); 278 + serial_port_out(port, MTK_UART_SAMPLE_POINT, 0xff); 279 + serial_port_out(port, MTK_UART_FRACDIV_L, 0x00); 280 + serial_port_out(port, MTK_UART_FRACDIV_M, 0x00); 365 281 } 282 + 283 + if ((termios->c_cflag & CRTSCTS) && (!(termios->c_iflag & CRTSCTS))) 284 + mode = MTK_UART_FC_HW; 285 + else if (termios->c_iflag & CRTSCTS) 286 + mode = MTK_UART_FC_SW; 287 + else 288 + mode = MTK_UART_FC_NONE; 289 + 290 + mtk8250_set_flow_ctrl(up, mode); 291 + 292 + if (uart_console(port)) 293 + up->port.cons->cflag = termios->c_cflag; 366 294 367 295 spin_unlock_irqrestore(&port->lock, flags); 368 296 /* Don't rewrite B0 */
+1
drivers/tty/serial/8250/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # The 8250/16550 serial drivers. You shouldn't be in this list unless 3 4 # you somehow have an implicit or explicit dependency on SERIAL_8250.
+51 -3
drivers/tty/serial/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Serial device configuration 3 4 # ··· 370 369 depends on SPI_MASTER 371 370 select SERIAL_CORE 372 371 select REGMAP_SPI if SPI_MASTER 373 - default n 374 372 help 375 373 This selects support for an advanced UART from Maxim (Dallas). 376 374 Supported ICs are MAX3107, MAX3108, MAX3109, MAX14830. ··· 652 652 config PDC_CONSOLE 653 653 bool "PDC software console support" 654 654 depends on PARISC && !SERIAL_MUX && VT 655 - default n 656 655 help 657 656 Saying Y here will enable the software based PDC console to be 658 657 used as the system console. This is useful for machines in ··· 1094 1095 your boot loader about how to pass options to the kernel at 1095 1096 boot time.) 1096 1097 1098 + config SERIAL_SIFIVE 1099 + tristate "SiFive UART support" 1100 + depends on OF 1101 + select SERIAL_CORE 1102 + help 1103 + Select this option if you are building a kernel for a device that 1104 + contains a SiFive UART IP block. This type of UART is present on 1105 + SiFive FU540 SoCs, among others. 1106 + 1107 + config SERIAL_SIFIVE_CONSOLE 1108 + bool "Console on SiFive UART" 1109 + depends on SERIAL_SIFIVE=y 1110 + select SERIAL_CORE_CONSOLE 1111 + help 1112 + Select this option if you would like to use a SiFive UART as the 1113 + system console. 1114 + 1115 + Even if you say Y here, the currently visible virtual console 1116 + (/dev/tty0) will still be used as the system console by default, but 1117 + you can alter that using a kernel command line option such as 1118 + "console=ttySIFx". (Try "man bootparam" or see the documentation of 1119 + your boot loader about how to pass options to the kernel at 1120 + boot time.) 1121 + 1097 1122 config SERIAL_LANTIQ 1098 1123 bool "Lantiq serial driver" 1099 1124 depends on LANTIQ ··· 1132 1109 depends on QUICC_ENGINE 1133 1110 select SERIAL_CORE 1134 1111 select FW_LOADER 1135 - default n 1136 1112 help 1137 1113 This driver supports the QE serial ports on Freescale embedded 1138 1114 PowerPC that contain a QUICC Engine. ··· 1603 1581 help 1604 1582 Say 'Y' here if you wish to use the RDA8810PL UART as the system 1605 1583 console. Only earlycon is implemented currently. 1584 + 1585 + config SERIAL_MILBEAUT_USIO 1586 + tristate "Milbeaut USIO/UART serial port support" 1587 + depends on ARCH_MILBEAUT || (COMPILE_TEST && OF) 1588 + default ARCH_MILBEAUT 1589 + select SERIAL_CORE 1590 + help 1591 + This selects the USIO/UART IP found in Socionext Milbeaut SoCs. 1592 + 1593 + config SERIAL_MILBEAUT_USIO_PORTS 1594 + int "Maximum number of CSIO/UART ports (1-8)" 1595 + range 1 8 1596 + depends on SERIAL_MILBEAUT_USIO 1597 + default "4" 1598 + 1599 + config SERIAL_MILBEAUT_USIO_CONSOLE 1600 + bool "Support for console on MILBEAUT USIO/UART serial port" 1601 + depends on SERIAL_MILBEAUT_USIO=y 1602 + default y 1603 + select SERIAL_CORE_CONSOLE 1604 + select SERIAL_EARLYCON 1605 + help 1606 + Say 'Y' here if you wish to use a USIO/UART of Socionext Milbeaut 1607 + SoCs as the system console (the system console is the device which 1608 + receives all kernel messages and warnings and which allows logins in 1609 + single user mode). 1606 1610 1607 1611 endmenu 1608 1612
+2
drivers/tty/serial/Makefile
··· 92 92 obj-$(CONFIG_SERIAL_MPS2_UART) += mps2-uart.o 93 93 obj-$(CONFIG_SERIAL_OWL) += owl-uart.o 94 94 obj-$(CONFIG_SERIAL_RDA) += rda-uart.o 95 + obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o 96 + obj-$(CONFIG_SERIAL_SIFIVE) += sifive.o 95 97 96 98 # GPIOLIB helpers for modem control lines 97 99 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
+1
drivers/tty/serial/cpm_uart/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Makefile for the Motorola 8xx FEC ethernet controller 3 4 #
+1
drivers/tty/serial/jsm/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Makefile for Jasmine adapter 3 4 #
+614
drivers/tty/serial/milbeaut_usio.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2018 Socionext Inc. 4 + */ 5 + 6 + #if defined(CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 7 + #define SUPPORT_SYSRQ 8 + #endif 9 + 10 + #include <linux/clk.h> 11 + #include <linux/console.h> 12 + #include <linux/module.h> 13 + #include <linux/of_irq.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/serial_core.h> 16 + #include <linux/tty.h> 17 + #include <linux/tty_flip.h> 18 + 19 + #define USIO_NAME "mlb-usio-uart" 20 + #define USIO_UART_DEV_NAME "ttyUSI" 21 + 22 + static struct uart_port mlb_usio_ports[CONFIG_SERIAL_MILBEAUT_USIO_PORTS]; 23 + 24 + #define RX 0 25 + #define TX 1 26 + static int mlb_usio_irq[CONFIG_SERIAL_MILBEAUT_USIO_PORTS][2]; 27 + 28 + #define MLB_USIO_REG_SMR 0 29 + #define MLB_USIO_REG_SCR 1 30 + #define MLB_USIO_REG_ESCR 2 31 + #define MLB_USIO_REG_SSR 3 32 + #define MLB_USIO_REG_DR 4 33 + #define MLB_USIO_REG_BGR 6 34 + #define MLB_USIO_REG_FCR 12 35 + #define MLB_USIO_REG_FBYTE 14 36 + 37 + #define MLB_USIO_SMR_SOE BIT(0) 38 + #define MLB_USIO_SMR_SBL BIT(3) 39 + #define MLB_USIO_SCR_TXE BIT(0) 40 + #define MLB_USIO_SCR_RXE BIT(1) 41 + #define MLB_USIO_SCR_TBIE BIT(2) 42 + #define MLB_USIO_SCR_TIE BIT(3) 43 + #define MLB_USIO_SCR_RIE BIT(4) 44 + #define MLB_USIO_SCR_UPCL BIT(7) 45 + #define MLB_USIO_ESCR_L_8BIT 0 46 + #define MLB_USIO_ESCR_L_5BIT 1 47 + #define MLB_USIO_ESCR_L_6BIT 2 48 + #define MLB_USIO_ESCR_L_7BIT 3 49 + #define MLB_USIO_ESCR_P BIT(3) 50 + #define MLB_USIO_ESCR_PEN BIT(4) 51 + #define MLB_USIO_ESCR_FLWEN BIT(7) 52 + #define MLB_USIO_SSR_TBI BIT(0) 53 + #define MLB_USIO_SSR_TDRE BIT(1) 54 + #define MLB_USIO_SSR_RDRF BIT(2) 55 + #define MLB_USIO_SSR_ORE BIT(3) 56 + #define MLB_USIO_SSR_FRE BIT(4) 57 + #define MLB_USIO_SSR_PE BIT(5) 58 + #define MLB_USIO_SSR_REC BIT(7) 59 + #define MLB_USIO_SSR_BRK BIT(8) 60 + #define MLB_USIO_FCR_FE1 BIT(0) 61 + #define MLB_USIO_FCR_FE2 BIT(1) 62 + #define MLB_USIO_FCR_FCL1 BIT(2) 63 + #define MLB_USIO_FCR_FCL2 BIT(3) 64 + #define MLB_USIO_FCR_FSET BIT(4) 65 + #define MLB_USIO_FCR_FTIE BIT(9) 66 + #define MLB_USIO_FCR_FDRQ BIT(10) 67 + #define MLB_USIO_FCR_FRIIE BIT(11) 68 + 69 + static void mlb_usio_stop_tx(struct uart_port *port) 70 + { 71 + writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FTIE, 72 + port->membase + MLB_USIO_REG_FCR); 73 + writeb(readb(port->membase + MLB_USIO_REG_SCR) & ~MLB_USIO_SCR_TBIE, 74 + port->membase + MLB_USIO_REG_SCR); 75 + } 76 + 77 + static void mlb_usio_tx_chars(struct uart_port *port) 78 + { 79 + struct circ_buf *xmit = &port->state->xmit; 80 + int count; 81 + 82 + writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FTIE, 83 + port->membase + MLB_USIO_REG_FCR); 84 + writeb(readb(port->membase + MLB_USIO_REG_SCR) & 85 + ~(MLB_USIO_SCR_TIE | MLB_USIO_SCR_TBIE), 86 + port->membase + MLB_USIO_REG_SCR); 87 + 88 + if (port->x_char) { 89 + writew(port->x_char, port->membase + MLB_USIO_REG_DR); 90 + port->icount.tx++; 91 + port->x_char = 0; 92 + return; 93 + } 94 + if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 95 + mlb_usio_stop_tx(port); 96 + return; 97 + } 98 + 99 + count = port->fifosize - 100 + (readw(port->membase + MLB_USIO_REG_FBYTE) & 0xff); 101 + 102 + do { 103 + writew(xmit->buf[xmit->tail], port->membase + MLB_USIO_REG_DR); 104 + 105 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 106 + port->icount.tx++; 107 + if (uart_circ_empty(xmit)) 108 + break; 109 + 110 + } while (--count > 0); 111 + 112 + writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FDRQ, 113 + port->membase + MLB_USIO_REG_FCR); 114 + 115 + writeb(readb(port->membase + MLB_USIO_REG_SCR) | MLB_USIO_SCR_TBIE, 116 + port->membase + MLB_USIO_REG_SCR); 117 + 118 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 119 + uart_write_wakeup(port); 120 + 121 + if (uart_circ_empty(xmit)) 122 + mlb_usio_stop_tx(port); 123 + } 124 + 125 + static void mlb_usio_start_tx(struct uart_port *port) 126 + { 127 + u16 fcr = readw(port->membase + MLB_USIO_REG_FCR); 128 + 129 + writew(fcr | MLB_USIO_FCR_FTIE, port->membase + MLB_USIO_REG_FCR); 130 + if (!(fcr & MLB_USIO_FCR_FDRQ)) 131 + return; 132 + 133 + writeb(readb(port->membase + MLB_USIO_REG_SCR) | MLB_USIO_SCR_TBIE, 134 + port->membase + MLB_USIO_REG_SCR); 135 + 136 + if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) 137 + mlb_usio_tx_chars(port); 138 + } 139 + 140 + static void mlb_usio_stop_rx(struct uart_port *port) 141 + { 142 + writeb(readb(port->membase + MLB_USIO_REG_SCR) & ~MLB_USIO_SCR_RIE, 143 + port->membase + MLB_USIO_REG_SCR); 144 + } 145 + 146 + static void mlb_usio_enable_ms(struct uart_port *port) 147 + { 148 + writeb(readb(port->membase + MLB_USIO_REG_SCR) | 149 + MLB_USIO_SCR_RIE | MLB_USIO_SCR_RXE, 150 + port->membase + MLB_USIO_REG_SCR); 151 + } 152 + 153 + static void mlb_usio_rx_chars(struct uart_port *port) 154 + { 155 + struct tty_port *ttyport = &port->state->port; 156 + unsigned long flag = 0; 157 + char ch = 0; 158 + u8 status; 159 + int max_count = 2; 160 + 161 + while (max_count--) { 162 + status = readb(port->membase + MLB_USIO_REG_SSR); 163 + 164 + if (!(status & MLB_USIO_SSR_RDRF)) 165 + break; 166 + 167 + if (!(status & (MLB_USIO_SSR_ORE | MLB_USIO_SSR_FRE | 168 + MLB_USIO_SSR_PE))) { 169 + ch = readw(port->membase + MLB_USIO_REG_DR); 170 + flag = TTY_NORMAL; 171 + port->icount.rx++; 172 + if (uart_handle_sysrq_char(port, ch)) 173 + continue; 174 + uart_insert_char(port, status, MLB_USIO_SSR_ORE, 175 + ch, flag); 176 + continue; 177 + } 178 + if (status & MLB_USIO_SSR_PE) 179 + port->icount.parity++; 180 + if (status & MLB_USIO_SSR_ORE) 181 + port->icount.overrun++; 182 + status &= port->read_status_mask; 183 + if (status & MLB_USIO_SSR_BRK) { 184 + flag = TTY_BREAK; 185 + ch = 0; 186 + } else 187 + if (status & MLB_USIO_SSR_PE) { 188 + flag = TTY_PARITY; 189 + ch = 0; 190 + } else 191 + if (status & MLB_USIO_SSR_FRE) { 192 + flag = TTY_FRAME; 193 + ch = 0; 194 + } 195 + if (flag) 196 + uart_insert_char(port, status, MLB_USIO_SSR_ORE, 197 + ch, flag); 198 + 199 + writeb(readb(port->membase + MLB_USIO_REG_SSR) | 200 + MLB_USIO_SSR_REC, 201 + port->membase + MLB_USIO_REG_SSR); 202 + 203 + max_count = readw(port->membase + MLB_USIO_REG_FBYTE) >> 8; 204 + writew(readw(port->membase + MLB_USIO_REG_FCR) | 205 + MLB_USIO_FCR_FE2 | MLB_USIO_FCR_FRIIE, 206 + port->membase + MLB_USIO_REG_FCR); 207 + } 208 + 209 + tty_flip_buffer_push(ttyport); 210 + } 211 + 212 + static irqreturn_t mlb_usio_rx_irq(int irq, void *dev_id) 213 + { 214 + struct uart_port *port = dev_id; 215 + 216 + spin_lock(&port->lock); 217 + mlb_usio_rx_chars(port); 218 + spin_unlock(&port->lock); 219 + 220 + return IRQ_HANDLED; 221 + } 222 + 223 + static irqreturn_t mlb_usio_tx_irq(int irq, void *dev_id) 224 + { 225 + struct uart_port *port = dev_id; 226 + 227 + spin_lock(&port->lock); 228 + if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) 229 + mlb_usio_tx_chars(port); 230 + spin_unlock(&port->lock); 231 + 232 + return IRQ_HANDLED; 233 + } 234 + 235 + static unsigned int mlb_usio_tx_empty(struct uart_port *port) 236 + { 237 + return (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) ? 238 + TIOCSER_TEMT : 0; 239 + } 240 + 241 + static void mlb_usio_set_mctrl(struct uart_port *port, unsigned int mctrl) 242 + { 243 + } 244 + 245 + static unsigned int mlb_usio_get_mctrl(struct uart_port *port) 246 + { 247 + return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; 248 + 249 + } 250 + 251 + static void mlb_usio_break_ctl(struct uart_port *port, int break_state) 252 + { 253 + } 254 + 255 + static int mlb_usio_startup(struct uart_port *port) 256 + { 257 + const char *portname = to_platform_device(port->dev)->name; 258 + unsigned long flags; 259 + int ret, index = port->line; 260 + unsigned char escr; 261 + 262 + ret = request_irq(mlb_usio_irq[index][RX], mlb_usio_rx_irq, 263 + 0, portname, port); 264 + if (ret) 265 + return ret; 266 + ret = request_irq(mlb_usio_irq[index][TX], mlb_usio_tx_irq, 267 + 0, portname, port); 268 + if (ret) { 269 + free_irq(mlb_usio_irq[index][RX], port); 270 + return ret; 271 + } 272 + 273 + escr = readb(port->membase + MLB_USIO_REG_ESCR); 274 + if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) 275 + escr |= MLB_USIO_ESCR_FLWEN; 276 + spin_lock_irqsave(&port->lock, flags); 277 + writeb(0, port->membase + MLB_USIO_REG_SCR); 278 + writeb(escr, port->membase + MLB_USIO_REG_ESCR); 279 + writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); 280 + writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); 281 + writew(0, port->membase + MLB_USIO_REG_FCR); 282 + writew(MLB_USIO_FCR_FCL1 | MLB_USIO_FCR_FCL2, 283 + port->membase + MLB_USIO_REG_FCR); 284 + writew(MLB_USIO_FCR_FE1 | MLB_USIO_FCR_FE2 | MLB_USIO_FCR_FRIIE, 285 + port->membase + MLB_USIO_REG_FCR); 286 + writew(0, port->membase + MLB_USIO_REG_FBYTE); 287 + writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); 288 + 289 + writeb(MLB_USIO_SCR_TXE | MLB_USIO_SCR_RIE | MLB_USIO_SCR_TBIE | 290 + MLB_USIO_SCR_RXE, port->membase + MLB_USIO_REG_SCR); 291 + spin_unlock_irqrestore(&port->lock, flags); 292 + 293 + return 0; 294 + } 295 + 296 + static void mlb_usio_shutdown(struct uart_port *port) 297 + { 298 + int index = port->line; 299 + 300 + free_irq(mlb_usio_irq[index][RX], port); 301 + free_irq(mlb_usio_irq[index][TX], port); 302 + } 303 + 304 + static void mlb_usio_set_termios(struct uart_port *port, 305 + struct ktermios *termios, struct ktermios *old) 306 + { 307 + unsigned int escr, smr = MLB_USIO_SMR_SOE; 308 + unsigned long flags, baud, quot; 309 + 310 + switch (termios->c_cflag & CSIZE) { 311 + case CS5: 312 + escr = MLB_USIO_ESCR_L_5BIT; 313 + break; 314 + case CS6: 315 + escr = MLB_USIO_ESCR_L_6BIT; 316 + break; 317 + case CS7: 318 + escr = MLB_USIO_ESCR_L_7BIT; 319 + break; 320 + case CS8: 321 + default: 322 + escr = MLB_USIO_ESCR_L_8BIT; 323 + break; 324 + } 325 + 326 + if (termios->c_cflag & CSTOPB) 327 + smr |= MLB_USIO_SMR_SBL; 328 + 329 + if (termios->c_cflag & PARENB) { 330 + escr |= MLB_USIO_ESCR_PEN; 331 + if (termios->c_cflag & PARODD) 332 + escr |= MLB_USIO_ESCR_P; 333 + } 334 + /* Set hard flow control */ 335 + if (of_property_read_bool(port->dev->of_node, "auto-flow-control") || 336 + (termios->c_cflag & CRTSCTS)) 337 + escr |= MLB_USIO_ESCR_FLWEN; 338 + 339 + baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk); 340 + if (baud > 1) 341 + quot = port->uartclk / baud - 1; 342 + else 343 + quot = 0; 344 + 345 + spin_lock_irqsave(&port->lock, flags); 346 + uart_update_timeout(port, termios->c_cflag, baud); 347 + port->read_status_mask = MLB_USIO_SSR_ORE | MLB_USIO_SSR_RDRF | 348 + MLB_USIO_SSR_TDRE; 349 + if (termios->c_iflag & INPCK) 350 + port->read_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; 351 + 352 + port->ignore_status_mask = 0; 353 + if (termios->c_iflag & IGNPAR) 354 + port->ignore_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; 355 + if ((termios->c_iflag & IGNBRK) && (termios->c_iflag & IGNPAR)) 356 + port->ignore_status_mask |= MLB_USIO_SSR_ORE; 357 + if ((termios->c_cflag & CREAD) == 0) 358 + port->ignore_status_mask |= MLB_USIO_SSR_RDRF; 359 + 360 + writeb(0, port->membase + MLB_USIO_REG_SCR); 361 + writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); 362 + writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); 363 + writew(0, port->membase + MLB_USIO_REG_FCR); 364 + writeb(smr, port->membase + MLB_USIO_REG_SMR); 365 + writeb(escr, port->membase + MLB_USIO_REG_ESCR); 366 + writew(quot, port->membase + MLB_USIO_REG_BGR); 367 + writew(0, port->membase + MLB_USIO_REG_FCR); 368 + writew(MLB_USIO_FCR_FCL1 | MLB_USIO_FCR_FCL2 | MLB_USIO_FCR_FE1 | 369 + MLB_USIO_FCR_FE2 | MLB_USIO_FCR_FRIIE, 370 + port->membase + MLB_USIO_REG_FCR); 371 + writew(0, port->membase + MLB_USIO_REG_FBYTE); 372 + writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); 373 + writeb(MLB_USIO_SCR_RIE | MLB_USIO_SCR_RXE | MLB_USIO_SCR_TBIE | 374 + MLB_USIO_SCR_TXE, port->membase + MLB_USIO_REG_SCR); 375 + spin_unlock_irqrestore(&port->lock, flags); 376 + } 377 + 378 + static const char *mlb_usio_type(struct uart_port *port) 379 + { 380 + return ((port->type == PORT_MLB_USIO) ? USIO_NAME : NULL); 381 + } 382 + 383 + static void mlb_usio_config_port(struct uart_port *port, int flags) 384 + { 385 + if (flags & UART_CONFIG_TYPE) 386 + port->type = PORT_MLB_USIO; 387 + } 388 + 389 + static const struct uart_ops mlb_usio_ops = { 390 + .tx_empty = mlb_usio_tx_empty, 391 + .set_mctrl = mlb_usio_set_mctrl, 392 + .get_mctrl = mlb_usio_get_mctrl, 393 + .stop_tx = mlb_usio_stop_tx, 394 + .start_tx = mlb_usio_start_tx, 395 + .stop_rx = mlb_usio_stop_rx, 396 + .enable_ms = mlb_usio_enable_ms, 397 + .break_ctl = mlb_usio_break_ctl, 398 + .startup = mlb_usio_startup, 399 + .shutdown = mlb_usio_shutdown, 400 + .set_termios = mlb_usio_set_termios, 401 + .type = mlb_usio_type, 402 + .config_port = mlb_usio_config_port, 403 + }; 404 + 405 + #ifdef CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE 406 + 407 + static void mlb_usio_console_putchar(struct uart_port *port, int c) 408 + { 409 + while (!(readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TDRE)) 410 + cpu_relax(); 411 + 412 + writew(c, port->membase + MLB_USIO_REG_DR); 413 + } 414 + 415 + static void mlb_usio_console_write(struct console *co, const char *s, 416 + unsigned int count) 417 + { 418 + struct uart_port *port = &mlb_usio_ports[co->index]; 419 + 420 + uart_console_write(port, s, count, mlb_usio_console_putchar); 421 + } 422 + 423 + static int __init mlb_usio_console_setup(struct console *co, char *options) 424 + { 425 + struct uart_port *port; 426 + int baud = 115200; 427 + int parity = 'n'; 428 + int flow = 'n'; 429 + int bits = 8; 430 + 431 + if (co->index >= CONFIG_SERIAL_MILBEAUT_USIO_PORTS) 432 + return -ENODEV; 433 + 434 + port = &mlb_usio_ports[co->index]; 435 + if (!port->membase) 436 + return -ENODEV; 437 + 438 + 439 + if (options) 440 + uart_parse_options(options, &baud, &parity, &bits, &flow); 441 + 442 + if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) 443 + flow = 'r'; 444 + 445 + return uart_set_options(port, co, baud, parity, bits, flow); 446 + } 447 + 448 + 449 + static struct uart_driver mlb_usio_uart_driver; 450 + static struct console mlb_usio_console = { 451 + .name = USIO_UART_DEV_NAME, 452 + .write = mlb_usio_console_write, 453 + .device = uart_console_device, 454 + .setup = mlb_usio_console_setup, 455 + .flags = CON_PRINTBUFFER, 456 + .index = -1, 457 + .data = &mlb_usio_uart_driver, 458 + }; 459 + 460 + static int __init mlb_usio_console_init(void) 461 + { 462 + register_console(&mlb_usio_console); 463 + return 0; 464 + } 465 + console_initcall(mlb_usio_console_init); 466 + 467 + 468 + static void mlb_usio_early_console_write(struct console *co, const char *s, 469 + u_int count) 470 + { 471 + struct earlycon_device *dev = co->data; 472 + 473 + uart_console_write(&dev->port, s, count, mlb_usio_console_putchar); 474 + } 475 + 476 + static int __init mlb_usio_early_console_setup(struct earlycon_device *device, 477 + const char *opt) 478 + { 479 + if (!device->port.membase) 480 + return -ENODEV; 481 + device->con->write = mlb_usio_early_console_write; 482 + return 0; 483 + } 484 + 485 + OF_EARLYCON_DECLARE(mlb_usio, "socionext,milbeaut-usio-uart", 486 + mlb_usio_early_console_setup); 487 + 488 + #define USIO_CONSOLE (&mlb_usio_console) 489 + #else 490 + #define USIO_CONSOLE NULL 491 + #endif 492 + 493 + static struct uart_driver mlb_usio_uart_driver = { 494 + .owner = THIS_MODULE, 495 + .driver_name = USIO_NAME, 496 + .dev_name = USIO_UART_DEV_NAME, 497 + .cons = USIO_CONSOLE, 498 + .nr = CONFIG_SERIAL_MILBEAUT_USIO_PORTS, 499 + }; 500 + 501 + static int mlb_usio_probe(struct platform_device *pdev) 502 + { 503 + struct clk *clk = devm_clk_get(&pdev->dev, NULL); 504 + struct uart_port *port; 505 + struct resource *res; 506 + int index = 0; 507 + int ret; 508 + 509 + if (IS_ERR(clk)) { 510 + dev_err(&pdev->dev, "Missing clock\n"); 511 + return PTR_ERR(clk); 512 + } 513 + ret = clk_prepare_enable(clk); 514 + if (ret) { 515 + dev_err(&pdev->dev, "Clock enable failed: %d\n", ret); 516 + return ret; 517 + } 518 + of_property_read_u32(pdev->dev.of_node, "index", &index); 519 + port = &mlb_usio_ports[index]; 520 + 521 + port->private_data = (void *)clk; 522 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 523 + if (res == NULL) { 524 + dev_err(&pdev->dev, "Missing regs\n"); 525 + ret = -ENODEV; 526 + goto failed; 527 + } 528 + port->membase = devm_ioremap(&pdev->dev, res->start, 529 + resource_size(res)); 530 + 531 + ret = platform_get_irq_byname(pdev, "rx"); 532 + mlb_usio_irq[index][RX] = ret; 533 + 534 + ret = platform_get_irq_byname(pdev, "tx"); 535 + mlb_usio_irq[index][TX] = ret; 536 + 537 + port->irq = mlb_usio_irq[index][RX]; 538 + port->uartclk = clk_get_rate(clk); 539 + port->fifosize = 128; 540 + port->iotype = UPIO_MEM32; 541 + port->flags = UPF_BOOT_AUTOCONF | UPF_SPD_VHI; 542 + port->line = index; 543 + port->ops = &mlb_usio_ops; 544 + port->dev = &pdev->dev; 545 + 546 + ret = uart_add_one_port(&mlb_usio_uart_driver, port); 547 + if (ret) { 548 + dev_err(&pdev->dev, "Adding port failed: %d\n", ret); 549 + goto failed; 550 + } 551 + return 0; 552 + 553 + failed: 554 + clk_disable_unprepare(clk); 555 + 556 + return ret; 557 + } 558 + 559 + static int mlb_usio_remove(struct platform_device *pdev) 560 + { 561 + struct uart_port *port = &mlb_usio_ports[pdev->id]; 562 + struct clk *clk = port->private_data; 563 + 564 + uart_remove_one_port(&mlb_usio_uart_driver, port); 565 + clk_disable_unprepare(clk); 566 + 567 + return 0; 568 + } 569 + 570 + static const struct of_device_id mlb_usio_dt_ids[] = { 571 + { .compatible = "socionext,milbeaut-usio-uart" }, 572 + { /* sentinel */ } 573 + }; 574 + MODULE_DEVICE_TABLE(of, mlb_usio_dt_ids); 575 + 576 + static struct platform_driver mlb_usio_driver = { 577 + .probe = mlb_usio_probe, 578 + .remove = mlb_usio_remove, 579 + .driver = { 580 + .name = USIO_NAME, 581 + .of_match_table = mlb_usio_dt_ids, 582 + }, 583 + }; 584 + 585 + static int __init mlb_usio_init(void) 586 + { 587 + int ret = uart_register_driver(&mlb_usio_uart_driver); 588 + 589 + if (ret) { 590 + pr_err("%s: uart registration failed: %d\n", __func__, ret); 591 + return ret; 592 + } 593 + ret = platform_driver_register(&mlb_usio_driver); 594 + if (ret) { 595 + uart_unregister_driver(&mlb_usio_uart_driver); 596 + pr_err("%s: drv registration failed: %d\n", __func__, ret); 597 + return ret; 598 + } 599 + 600 + return 0; 601 + } 602 + 603 + static void __exit mlb_usio_exit(void) 604 + { 605 + platform_driver_unregister(&mlb_usio_driver); 606 + uart_unregister_driver(&mlb_usio_uart_driver); 607 + } 608 + 609 + module_init(mlb_usio_init); 610 + module_exit(mlb_usio_exit); 611 + 612 + MODULE_AUTHOR("SOCIONEXT"); 613 + MODULE_DESCRIPTION("MILBEAUT_USIO/UART Driver"); 614 + MODULE_LICENSE("GPL");
+17 -17
drivers/tty/serial/sc16is7xx.c
··· 14 14 #include <linux/device.h> 15 15 #include <linux/gpio/driver.h> 16 16 #include <linux/i2c.h> 17 + #include <linux/mod_devicetable.h> 17 18 #include <linux/module.h> 18 - #include <linux/of.h> 19 - #include <linux/of_device.h> 19 + #include <linux/property.h> 20 20 #include <linux/regmap.h> 21 21 #include <linux/serial_core.h> 22 22 #include <linux/serial.h> ··· 1179 1179 struct regmap *regmap, int irq, unsigned long flags) 1180 1180 { 1181 1181 struct sched_param sched_param = { .sched_priority = MAX_RT_PRIO / 2 }; 1182 - unsigned long freq, *pfreq = dev_get_platdata(dev); 1182 + unsigned long freq = 0, *pfreq = dev_get_platdata(dev); 1183 + u32 uartclk = 0; 1183 1184 int i, ret; 1184 1185 struct sc16is7xx_port *s; 1185 1186 ··· 1194 1193 return -ENOMEM; 1195 1194 } 1196 1195 1196 + /* Always ask for fixed clock rate from a property. */ 1197 + device_property_read_u32(dev, "clock-frequency", &uartclk); 1198 + 1197 1199 s->clk = devm_clk_get(dev, NULL); 1198 1200 if (IS_ERR(s->clk)) { 1201 + if (uartclk) 1202 + freq = uartclk; 1199 1203 if (pfreq) 1200 1204 freq = *pfreq; 1205 + if (freq) 1206 + dev_dbg(dev, "Clock frequency: %luHz\n", freq); 1201 1207 else 1202 1208 return PTR_ERR(s->clk); 1203 1209 } else { ··· 1392 1384 return ret; 1393 1385 1394 1386 if (spi->dev.of_node) { 1395 - const struct of_device_id *of_id = 1396 - of_match_device(sc16is7xx_dt_ids, &spi->dev); 1397 - 1398 - if (!of_id) 1387 + devtype = device_get_match_data(&spi->dev); 1388 + if (!devtype) 1399 1389 return -ENODEV; 1400 - 1401 - devtype = (struct sc16is7xx_devtype *)of_id->data; 1402 1390 } else { 1403 1391 const struct spi_device_id *id_entry = spi_get_device_id(spi); 1404 1392 ··· 1430 1426 static struct spi_driver sc16is7xx_spi_uart_driver = { 1431 1427 .driver = { 1432 1428 .name = SC16IS7XX_NAME, 1433 - .of_match_table = of_match_ptr(sc16is7xx_dt_ids), 1429 + .of_match_table = sc16is7xx_dt_ids, 1434 1430 }, 1435 1431 .probe = sc16is7xx_spi_probe, 1436 1432 .remove = sc16is7xx_spi_remove, ··· 1449 1445 struct regmap *regmap; 1450 1446 1451 1447 if (i2c->dev.of_node) { 1452 - const struct of_device_id *of_id = 1453 - of_match_device(sc16is7xx_dt_ids, &i2c->dev); 1454 - 1455 - if (!of_id) 1448 + devtype = device_get_match_data(&i2c->dev); 1449 + if (!devtype) 1456 1450 return -ENODEV; 1457 - 1458 - devtype = (struct sc16is7xx_devtype *)of_id->data; 1459 1451 } else { 1460 1452 devtype = (struct sc16is7xx_devtype *)id->driver_data; 1461 1453 flags = IRQF_TRIGGER_FALLING; ··· 1484 1484 static struct i2c_driver sc16is7xx_i2c_uart_driver = { 1485 1485 .driver = { 1486 1486 .name = SC16IS7XX_NAME, 1487 - .of_match_table = of_match_ptr(sc16is7xx_dt_ids), 1487 + .of_match_table = sc16is7xx_dt_ids, 1488 1488 }, 1489 1489 .probe = sc16is7xx_i2c_probe, 1490 1490 .remove = sc16is7xx_i2c_remove,
+16 -14
drivers/tty/serial/serial_core.c
··· 130 130 struct uart_port *port; 131 131 unsigned long flags; 132 132 133 - if (!state) 134 - return; 135 - 136 133 port = uart_port_lock(state, flags); 137 134 __uart_start(tty); 138 135 uart_port_unlock(port, flags); ··· 726 729 struct uart_state *state = tty->driver_data; 727 730 upstat_t mask = UPSTAT_SYNC_FIFO; 728 731 struct uart_port *port; 729 - 730 - if (!state) 731 - return; 732 732 733 733 port = uart_port_ref(state); 734 734 if (!port) ··· 1508 1514 } 1509 1515 1510 1516 uart_change_speed(tty, state, old_termios); 1511 - /* reload cflag from termios; port driver may have overriden flags */ 1517 + /* reload cflag from termios; port driver may have overridden flags */ 1512 1518 cflag = tty->termios.c_cflag; 1513 1519 1514 1520 /* Handle transition to B0 status */ ··· 1741 1747 uart_port_deref(uport); 1742 1748 } 1743 1749 1750 + static int uart_install(struct tty_driver *driver, struct tty_struct *tty) 1751 + { 1752 + struct uart_driver *drv = driver->driver_state; 1753 + struct uart_state *state = drv->state + tty->index; 1754 + 1755 + tty->driver_data = state; 1756 + 1757 + return tty_standard_install(driver, tty); 1758 + } 1759 + 1744 1760 /* 1745 1761 * Calls to uart_open are serialised by the tty_lock in 1746 1762 * drivers/tty/tty_io.c:tty_open() ··· 1763 1759 */ 1764 1760 static int uart_open(struct tty_struct *tty, struct file *filp) 1765 1761 { 1766 - struct uart_driver *drv = tty->driver->driver_state; 1767 - int retval, line = tty->index; 1768 - struct uart_state *state = drv->state + line; 1769 - 1770 - tty->driver_data = state; 1762 + struct uart_state *state = tty->driver_data; 1763 + int retval; 1771 1764 1772 1765 retval = tty_port_open(&state->port, tty, filp); 1773 1766 if (retval > 0) ··· 2449 2448 #endif 2450 2449 2451 2450 static const struct tty_operations uart_ops = { 2451 + .install = uart_install, 2452 2452 .open = uart_open, 2453 2453 .close = uart_close, 2454 2454 .write = uart_write, ··· 2507 2505 int uart_register_driver(struct uart_driver *drv) 2508 2506 { 2509 2507 struct tty_driver *normal; 2510 - int i, retval; 2508 + int i, retval = -ENOMEM; 2511 2509 2512 2510 BUG_ON(drv->state); 2513 2511 ··· 2559 2557 out_kfree: 2560 2558 kfree(drv->state); 2561 2559 out: 2562 - return -ENOMEM; 2560 + return retval; 2563 2561 } 2564 2562 2565 2563 /**
+1056
drivers/tty/serial/sifive.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * SiFive UART driver 4 + * Copyright (C) 2018 Paul Walmsley <paul@pwsan.com> 5 + * Copyright (C) 2018-2019 SiFive 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + * Based partially on: 18 + * - drivers/tty/serial/pxa.c 19 + * - drivers/tty/serial/amba-pl011.c 20 + * - drivers/tty/serial/uartlite.c 21 + * - drivers/tty/serial/omap-serial.c 22 + * - drivers/pwm/pwm-sifive.c 23 + * 24 + * See the following sources for further documentation: 25 + * - Chapter 19 "Universal Asynchronous Receiver/Transmitter (UART)" of 26 + * SiFive FE310-G000 v2p3 27 + * - The tree/master/src/main/scala/devices/uart directory of 28 + * https://github.com/sifive/sifive-blocks/ 29 + * 30 + * The SiFive UART design is not 8250-compatible. The following common 31 + * features are not supported: 32 + * - Word lengths other than 8 bits 33 + * - Break handling 34 + * - Parity 35 + * - Flow control 36 + * - Modem signals (DSR, RI, etc.) 37 + * On the other hand, the design is free from the baggage of the 8250 38 + * programming model. 39 + */ 40 + 41 + #include <linux/clk.h> 42 + #include <linux/console.h> 43 + #include <linux/delay.h> 44 + #include <linux/init.h> 45 + #include <linux/io.h> 46 + #include <linux/irq.h> 47 + #include <linux/module.h> 48 + #include <linux/of.h> 49 + #include <linux/of_irq.h> 50 + #include <linux/platform_device.h> 51 + #include <linux/serial_core.h> 52 + #include <linux/serial_reg.h> 53 + #include <linux/slab.h> 54 + #include <linux/tty.h> 55 + #include <linux/tty_flip.h> 56 + 57 + /* 58 + * Register offsets 59 + */ 60 + 61 + /* TXDATA */ 62 + #define SIFIVE_SERIAL_TXDATA_OFFS 0x0 63 + #define SIFIVE_SERIAL_TXDATA_FULL_SHIFT 31 64 + #define SIFIVE_SERIAL_TXDATA_FULL_MASK (1 << SIFIVE_SERIAL_TXDATA_FULL_SHIFT) 65 + #define SIFIVE_SERIAL_TXDATA_DATA_SHIFT 0 66 + #define SIFIVE_SERIAL_TXDATA_DATA_MASK (0xff << SIFIVE_SERIAL_TXDATA_DATA_SHIFT) 67 + 68 + /* RXDATA */ 69 + #define SIFIVE_SERIAL_RXDATA_OFFS 0x4 70 + #define SIFIVE_SERIAL_RXDATA_EMPTY_SHIFT 31 71 + #define SIFIVE_SERIAL_RXDATA_EMPTY_MASK (1 << SIFIVE_SERIAL_RXDATA_EMPTY_SHIFT) 72 + #define SIFIVE_SERIAL_RXDATA_DATA_SHIFT 0 73 + #define SIFIVE_SERIAL_RXDATA_DATA_MASK (0xff << SIFIVE_SERIAL_RXDATA_DATA_SHIFT) 74 + 75 + /* TXCTRL */ 76 + #define SIFIVE_SERIAL_TXCTRL_OFFS 0x8 77 + #define SIFIVE_SERIAL_TXCTRL_TXCNT_SHIFT 16 78 + #define SIFIVE_SERIAL_TXCTRL_TXCNT_MASK (0x7 << SIFIVE_SERIAL_TXCTRL_TXCNT_SHIFT) 79 + #define SIFIVE_SERIAL_TXCTRL_NSTOP_SHIFT 1 80 + #define SIFIVE_SERIAL_TXCTRL_NSTOP_MASK (1 << SIFIVE_SERIAL_TXCTRL_NSTOP_SHIFT) 81 + #define SIFIVE_SERIAL_TXCTRL_TXEN_SHIFT 0 82 + #define SIFIVE_SERIAL_TXCTRL_TXEN_MASK (1 << SIFIVE_SERIAL_TXCTRL_TXEN_SHIFT) 83 + 84 + /* RXCTRL */ 85 + #define SIFIVE_SERIAL_RXCTRL_OFFS 0xC 86 + #define SIFIVE_SERIAL_RXCTRL_RXCNT_SHIFT 16 87 + #define SIFIVE_SERIAL_RXCTRL_RXCNT_MASK (0x7 << SIFIVE_SERIAL_TXCTRL_TXCNT_SHIFT) 88 + #define SIFIVE_SERIAL_RXCTRL_RXEN_SHIFT 0 89 + #define SIFIVE_SERIAL_RXCTRL_RXEN_MASK (1 << SIFIVE_SERIAL_RXCTRL_RXEN_SHIFT) 90 + 91 + /* IE */ 92 + #define SIFIVE_SERIAL_IE_OFFS 0x10 93 + #define SIFIVE_SERIAL_IE_RXWM_SHIFT 1 94 + #define SIFIVE_SERIAL_IE_RXWM_MASK (1 << SIFIVE_SERIAL_IE_RXWM_SHIFT) 95 + #define SIFIVE_SERIAL_IE_TXWM_SHIFT 0 96 + #define SIFIVE_SERIAL_IE_TXWM_MASK (1 << SIFIVE_SERIAL_IE_TXWM_SHIFT) 97 + 98 + /* IP */ 99 + #define SIFIVE_SERIAL_IP_OFFS 0x14 100 + #define SIFIVE_SERIAL_IP_RXWM_SHIFT 1 101 + #define SIFIVE_SERIAL_IP_RXWM_MASK (1 << SIFIVE_SERIAL_IP_RXWM_SHIFT) 102 + #define SIFIVE_SERIAL_IP_TXWM_SHIFT 0 103 + #define SIFIVE_SERIAL_IP_TXWM_MASK (1 << SIFIVE_SERIAL_IP_TXWM_SHIFT) 104 + 105 + /* DIV */ 106 + #define SIFIVE_SERIAL_DIV_OFFS 0x18 107 + #define SIFIVE_SERIAL_DIV_DIV_SHIFT 0 108 + #define SIFIVE_SERIAL_DIV_DIV_MASK (0xffff << SIFIVE_SERIAL_IP_DIV_SHIFT) 109 + 110 + /* 111 + * Config macros 112 + */ 113 + 114 + /* 115 + * SIFIVE_SERIAL_MAX_PORTS: maximum number of UARTs on a device that can 116 + * host a serial console 117 + */ 118 + #define SIFIVE_SERIAL_MAX_PORTS 8 119 + 120 + /* 121 + * SIFIVE_DEFAULT_BAUD_RATE: default baud rate that the driver should 122 + * configure itself to use 123 + */ 124 + #define SIFIVE_DEFAULT_BAUD_RATE 115200 125 + 126 + /* SIFIVE_SERIAL_NAME: our driver's name that we pass to the operating system */ 127 + #define SIFIVE_SERIAL_NAME "sifive-serial" 128 + 129 + /* SIFIVE_TTY_PREFIX: tty name prefix for SiFive serial ports */ 130 + #define SIFIVE_TTY_PREFIX "ttySIF" 131 + 132 + /* SIFIVE_TX_FIFO_DEPTH: depth of the TX FIFO (in bytes) */ 133 + #define SIFIVE_TX_FIFO_DEPTH 8 134 + 135 + /* SIFIVE_RX_FIFO_DEPTH: depth of the TX FIFO (in bytes) */ 136 + #define SIFIVE_RX_FIFO_DEPTH 8 137 + 138 + #if (SIFIVE_TX_FIFO_DEPTH != SIFIVE_RX_FIFO_DEPTH) 139 + #error Driver does not support configurations with different TX, RX FIFO sizes 140 + #endif 141 + 142 + /* 143 + * 144 + */ 145 + 146 + /** 147 + * sifive_serial_port - driver-specific data extension to struct uart_port 148 + * @port: struct uart_port embedded in this struct 149 + * @dev: struct device * 150 + * @ier: shadowed copy of the interrupt enable register 151 + * @clkin_rate: input clock to the UART IP block. 152 + * @baud_rate: UART serial line rate (e.g., 115200 baud) 153 + * @clk_notifier: clock rate change notifier for upstream clock changes 154 + * 155 + * Configuration data specific to this SiFive UART. 156 + */ 157 + struct sifive_serial_port { 158 + struct uart_port port; 159 + struct device *dev; 160 + unsigned char ier; 161 + unsigned long clkin_rate; 162 + unsigned long baud_rate; 163 + struct clk *clk; 164 + struct notifier_block clk_notifier; 165 + }; 166 + 167 + /* 168 + * Structure container-of macros 169 + */ 170 + 171 + #define port_to_sifive_serial_port(p) (container_of((p), \ 172 + struct sifive_serial_port, \ 173 + port)) 174 + 175 + #define notifier_to_sifive_serial_port(nb) (container_of((nb), \ 176 + struct sifive_serial_port, \ 177 + clk_notifier)) 178 + 179 + /* 180 + * Forward declarations 181 + */ 182 + static void sifive_serial_stop_tx(struct uart_port *port); 183 + 184 + /* 185 + * Internal functions 186 + */ 187 + 188 + /** 189 + * __ssp_early_writel() - write to a SiFive serial port register (early) 190 + * @port: pointer to a struct uart_port record 191 + * @offs: register address offset from the IP block base address 192 + * @v: value to write to the register 193 + * 194 + * Given a pointer @port to a struct uart_port record, write the value 195 + * @v to the IP block register address offset @offs. This function is 196 + * intended for early console use. 197 + * 198 + * Context: Intended to be used only by the earlyconsole code. 199 + */ 200 + static void __ssp_early_writel(u32 v, u16 offs, struct uart_port *port) 201 + { 202 + writel_relaxed(v, port->membase + offs); 203 + } 204 + 205 + /** 206 + * __ssp_early_readl() - read from a SiFive serial port register (early) 207 + * @port: pointer to a struct uart_port record 208 + * @offs: register address offset from the IP block base address 209 + * 210 + * Given a pointer @port to a struct uart_port record, read the 211 + * contents of the IP block register located at offset @offs from the 212 + * IP block base and return it. This function is intended for early 213 + * console use. 214 + * 215 + * Context: Intended to be called only by the earlyconsole code or by 216 + * __ssp_readl() or __ssp_writel() (in this driver) 217 + * 218 + * Returns: the register value read from the UART. 219 + */ 220 + static u32 __ssp_early_readl(struct uart_port *port, u16 offs) 221 + { 222 + return readl_relaxed(port->membase + offs); 223 + } 224 + 225 + /** 226 + * __ssp_writel() - write to a SiFive serial port register 227 + * @v: value to write to the register 228 + * @offs: register address offset from the IP block base address 229 + * @ssp: pointer to a struct sifive_serial_port record 230 + * 231 + * Write the value @v to the IP block register located at offset @offs from the 232 + * IP block base, given a pointer @ssp to a struct sifive_serial_port record. 233 + * 234 + * Context: Any context. 235 + */ 236 + static void __ssp_writel(u32 v, u16 offs, struct sifive_serial_port *ssp) 237 + { 238 + __ssp_early_writel(v, offs, &ssp->port); 239 + } 240 + 241 + /** 242 + * __ssp_readl() - read from a SiFive serial port register 243 + * @ssp: pointer to a struct sifive_serial_port record 244 + * @offs: register address offset from the IP block base address 245 + * 246 + * Read the contents of the IP block register located at offset @offs from the 247 + * IP block base, given a pointer @ssp to a struct sifive_serial_port record. 248 + * 249 + * Context: Any context. 250 + * 251 + * Returns: the value of the UART register 252 + */ 253 + static u32 __ssp_readl(struct sifive_serial_port *ssp, u16 offs) 254 + { 255 + return __ssp_early_readl(&ssp->port, offs); 256 + } 257 + 258 + /** 259 + * sifive_serial_is_txfifo_full() - is the TXFIFO full? 260 + * @ssp: pointer to a struct sifive_serial_port 261 + * 262 + * Read the transmit FIFO "full" bit, returning a non-zero value if the 263 + * TX FIFO is full, or zero if space remains. Intended to be used to prevent 264 + * writes to the TX FIFO when it's full. 265 + * 266 + * Returns: SIFIVE_SERIAL_TXDATA_FULL_MASK (non-zero) if the transmit FIFO 267 + * is full, or 0 if space remains. 268 + */ 269 + static int sifive_serial_is_txfifo_full(struct sifive_serial_port *ssp) 270 + { 271 + return __ssp_readl(ssp, SIFIVE_SERIAL_TXDATA_OFFS) & 272 + SIFIVE_SERIAL_TXDATA_FULL_MASK; 273 + } 274 + 275 + /** 276 + * __ssp_transmit_char() - enqueue a byte to transmit onto the TX FIFO 277 + * @ssp: pointer to a struct sifive_serial_port 278 + * @ch: character to transmit 279 + * 280 + * Enqueue a byte @ch onto the transmit FIFO, given a pointer @ssp to the 281 + * struct sifive_serial_port * to transmit on. Caller should first check to 282 + * ensure that the TXFIFO has space; see sifive_serial_is_txfifo_full(). 283 + * 284 + * Context: Any context. 285 + */ 286 + static void __ssp_transmit_char(struct sifive_serial_port *ssp, int ch) 287 + { 288 + __ssp_writel(ch, SIFIVE_SERIAL_TXDATA_OFFS, ssp); 289 + } 290 + 291 + /** 292 + * __ssp_transmit_chars() - enqueue multiple bytes onto the TX FIFO 293 + * @ssp: pointer to a struct sifive_serial_port 294 + * 295 + * Transfer up to a TX FIFO size's worth of characters from the Linux serial 296 + * transmit buffer to the SiFive UART TX FIFO. 297 + * 298 + * Context: Any context. Expects @ssp->port.lock to be held by caller. 299 + */ 300 + static void __ssp_transmit_chars(struct sifive_serial_port *ssp) 301 + { 302 + struct circ_buf *xmit = &ssp->port.state->xmit; 303 + int count; 304 + 305 + if (ssp->port.x_char) { 306 + __ssp_transmit_char(ssp, ssp->port.x_char); 307 + ssp->port.icount.tx++; 308 + ssp->port.x_char = 0; 309 + return; 310 + } 311 + if (uart_circ_empty(xmit) || uart_tx_stopped(&ssp->port)) { 312 + sifive_serial_stop_tx(&ssp->port); 313 + return; 314 + } 315 + count = SIFIVE_TX_FIFO_DEPTH; 316 + do { 317 + __ssp_transmit_char(ssp, xmit->buf[xmit->tail]); 318 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 319 + ssp->port.icount.tx++; 320 + if (uart_circ_empty(xmit)) 321 + break; 322 + } while (--count > 0); 323 + 324 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 325 + uart_write_wakeup(&ssp->port); 326 + 327 + if (uart_circ_empty(xmit)) 328 + sifive_serial_stop_tx(&ssp->port); 329 + } 330 + 331 + /** 332 + * __ssp_enable_txwm() - enable transmit watermark interrupts 333 + * @ssp: pointer to a struct sifive_serial_port 334 + * 335 + * Enable interrupt generation when the transmit FIFO watermark is reached 336 + * on the SiFive UART referred to by @ssp. 337 + */ 338 + static void __ssp_enable_txwm(struct sifive_serial_port *ssp) 339 + { 340 + if (ssp->ier & SIFIVE_SERIAL_IE_TXWM_MASK) 341 + return; 342 + 343 + ssp->ier |= SIFIVE_SERIAL_IE_TXWM_MASK; 344 + __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); 345 + } 346 + 347 + /** 348 + * __ssp_enable_rxwm() - enable receive watermark interrupts 349 + * @ssp: pointer to a struct sifive_serial_port 350 + * 351 + * Enable interrupt generation when the receive FIFO watermark is reached 352 + * on the SiFive UART referred to by @ssp. 353 + */ 354 + static void __ssp_enable_rxwm(struct sifive_serial_port *ssp) 355 + { 356 + if (ssp->ier & SIFIVE_SERIAL_IE_RXWM_MASK) 357 + return; 358 + 359 + ssp->ier |= SIFIVE_SERIAL_IE_RXWM_MASK; 360 + __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); 361 + } 362 + 363 + /** 364 + * __ssp_disable_txwm() - disable transmit watermark interrupts 365 + * @ssp: pointer to a struct sifive_serial_port 366 + * 367 + * Disable interrupt generation when the transmit FIFO watermark is reached 368 + * on the UART referred to by @ssp. 369 + */ 370 + static void __ssp_disable_txwm(struct sifive_serial_port *ssp) 371 + { 372 + if (!(ssp->ier & SIFIVE_SERIAL_IE_TXWM_MASK)) 373 + return; 374 + 375 + ssp->ier &= ~SIFIVE_SERIAL_IE_TXWM_MASK; 376 + __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); 377 + } 378 + 379 + /** 380 + * __ssp_disable_rxwm() - disable receive watermark interrupts 381 + * @ssp: pointer to a struct sifive_serial_port 382 + * 383 + * Disable interrupt generation when the receive FIFO watermark is reached 384 + * on the UART referred to by @ssp. 385 + */ 386 + static void __ssp_disable_rxwm(struct sifive_serial_port *ssp) 387 + { 388 + if (!(ssp->ier & SIFIVE_SERIAL_IE_RXWM_MASK)) 389 + return; 390 + 391 + ssp->ier &= ~SIFIVE_SERIAL_IE_RXWM_MASK; 392 + __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); 393 + } 394 + 395 + /** 396 + * __ssp_receive_char() - receive a byte from the UART 397 + * @ssp: pointer to a struct sifive_serial_port 398 + * @is_empty: char pointer to return whether the RX FIFO is empty 399 + * 400 + * Try to read a byte from the SiFive UART RX FIFO, referenced by 401 + * @ssp, and to return it. Also returns the RX FIFO empty bit in 402 + * the char pointed to by @ch. The caller must pass the byte back to the 403 + * Linux serial layer if needed. 404 + * 405 + * Returns: the byte read from the UART RX FIFO. 406 + */ 407 + static char __ssp_receive_char(struct sifive_serial_port *ssp, char *is_empty) 408 + { 409 + u32 v; 410 + u8 ch; 411 + 412 + v = __ssp_readl(ssp, SIFIVE_SERIAL_RXDATA_OFFS); 413 + 414 + if (!is_empty) 415 + WARN_ON(1); 416 + else 417 + *is_empty = (v & SIFIVE_SERIAL_RXDATA_EMPTY_MASK) >> 418 + SIFIVE_SERIAL_RXDATA_EMPTY_SHIFT; 419 + 420 + ch = (v & SIFIVE_SERIAL_RXDATA_DATA_MASK) >> 421 + SIFIVE_SERIAL_RXDATA_DATA_SHIFT; 422 + 423 + return ch; 424 + } 425 + 426 + /** 427 + * __ssp_receive_chars() - receive multiple bytes from the UART 428 + * @ssp: pointer to a struct sifive_serial_port 429 + * 430 + * Receive up to an RX FIFO's worth of bytes from the SiFive UART referred 431 + * to by @ssp and pass them up to the Linux serial layer. 432 + * 433 + * Context: Expects ssp->port.lock to be held by caller. 434 + */ 435 + static void __ssp_receive_chars(struct sifive_serial_port *ssp) 436 + { 437 + unsigned char ch; 438 + char is_empty; 439 + int c; 440 + 441 + for (c = SIFIVE_RX_FIFO_DEPTH; c > 0; --c) { 442 + ch = __ssp_receive_char(ssp, &is_empty); 443 + if (is_empty) 444 + break; 445 + 446 + ssp->port.icount.rx++; 447 + uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL); 448 + } 449 + 450 + spin_unlock(&ssp->port.lock); 451 + tty_flip_buffer_push(&ssp->port.state->port); 452 + spin_lock(&ssp->port.lock); 453 + } 454 + 455 + /** 456 + * __ssp_update_div() - calculate the divisor setting by the line rate 457 + * @ssp: pointer to a struct sifive_serial_port 458 + * 459 + * Calculate the appropriate value of the clock divisor for the UART 460 + * and target line rate referred to by @ssp and write it into the 461 + * hardware. 462 + */ 463 + static void __ssp_update_div(struct sifive_serial_port *ssp) 464 + { 465 + u16 div; 466 + 467 + div = DIV_ROUND_UP(ssp->clkin_rate, ssp->baud_rate) - 1; 468 + 469 + __ssp_writel(div, SIFIVE_SERIAL_DIV_OFFS, ssp); 470 + } 471 + 472 + /** 473 + * __ssp_update_baud_rate() - set the UART "baud rate" 474 + * @ssp: pointer to a struct sifive_serial_port 475 + * @rate: new target bit rate 476 + * 477 + * Calculate the UART divisor value for the target bit rate @rate for the 478 + * SiFive UART described by @ssp and program it into the UART. There may 479 + * be some error between the target bit rate and the actual bit rate implemented 480 + * by the UART due to clock ratio granularity. 481 + */ 482 + static void __ssp_update_baud_rate(struct sifive_serial_port *ssp, 483 + unsigned int rate) 484 + { 485 + if (ssp->baud_rate == rate) 486 + return; 487 + 488 + ssp->baud_rate = rate; 489 + __ssp_update_div(ssp); 490 + } 491 + 492 + /** 493 + * __ssp_set_stop_bits() - set the number of stop bits 494 + * @ssp: pointer to a struct sifive_serial_port 495 + * @nstop: 1 or 2 (stop bits) 496 + * 497 + * Program the SiFive UART referred to by @ssp to use @nstop stop bits. 498 + */ 499 + static void __ssp_set_stop_bits(struct sifive_serial_port *ssp, char nstop) 500 + { 501 + u32 v; 502 + 503 + if (nstop < 1 || nstop > 2) { 504 + WARN_ON(1); 505 + return; 506 + } 507 + 508 + v = __ssp_readl(ssp, SIFIVE_SERIAL_TXCTRL_OFFS); 509 + v &= ~SIFIVE_SERIAL_TXCTRL_NSTOP_MASK; 510 + v |= (nstop - 1) << SIFIVE_SERIAL_TXCTRL_NSTOP_SHIFT; 511 + __ssp_writel(v, SIFIVE_SERIAL_TXCTRL_OFFS, ssp); 512 + } 513 + 514 + /** 515 + * __ssp_wait_for_xmitr() - wait for an empty slot on the TX FIFO 516 + * @ssp: pointer to a struct sifive_serial_port 517 + * 518 + * Delay while the UART TX FIFO referred to by @ssp is marked as full. 519 + * 520 + * Context: Any context. 521 + */ 522 + static void __maybe_unused __ssp_wait_for_xmitr(struct sifive_serial_port *ssp) 523 + { 524 + while (sifive_serial_is_txfifo_full(ssp)) 525 + udelay(1); /* XXX Could probably be more intelligent here */ 526 + } 527 + 528 + /* 529 + * Linux serial API functions 530 + */ 531 + 532 + static void sifive_serial_stop_tx(struct uart_port *port) 533 + { 534 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 535 + 536 + __ssp_disable_txwm(ssp); 537 + } 538 + 539 + static void sifive_serial_stop_rx(struct uart_port *port) 540 + { 541 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 542 + 543 + __ssp_disable_rxwm(ssp); 544 + } 545 + 546 + static void sifive_serial_start_tx(struct uart_port *port) 547 + { 548 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 549 + 550 + __ssp_enable_txwm(ssp); 551 + } 552 + 553 + static irqreturn_t sifive_serial_irq(int irq, void *dev_id) 554 + { 555 + struct sifive_serial_port *ssp = dev_id; 556 + u32 ip; 557 + 558 + spin_lock(&ssp->port.lock); 559 + 560 + ip = __ssp_readl(ssp, SIFIVE_SERIAL_IP_OFFS); 561 + if (!ip) { 562 + spin_unlock(&ssp->port.lock); 563 + return IRQ_NONE; 564 + } 565 + 566 + if (ip & SIFIVE_SERIAL_IP_RXWM_MASK) 567 + __ssp_receive_chars(ssp); 568 + if (ip & SIFIVE_SERIAL_IP_TXWM_MASK) 569 + __ssp_transmit_chars(ssp); 570 + 571 + spin_unlock(&ssp->port.lock); 572 + 573 + return IRQ_HANDLED; 574 + } 575 + 576 + static unsigned int sifive_serial_tx_empty(struct uart_port *port) 577 + { 578 + return TIOCSER_TEMT; 579 + } 580 + 581 + static unsigned int sifive_serial_get_mctrl(struct uart_port *port) 582 + { 583 + return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR; 584 + } 585 + 586 + static void sifive_serial_set_mctrl(struct uart_port *port, unsigned int mctrl) 587 + { 588 + /* IP block does not support these signals */ 589 + } 590 + 591 + static void sifive_serial_break_ctl(struct uart_port *port, int break_state) 592 + { 593 + /* IP block does not support sending a break */ 594 + } 595 + 596 + static int sifive_serial_startup(struct uart_port *port) 597 + { 598 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 599 + 600 + __ssp_enable_rxwm(ssp); 601 + 602 + return 0; 603 + } 604 + 605 + static void sifive_serial_shutdown(struct uart_port *port) 606 + { 607 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 608 + 609 + __ssp_disable_rxwm(ssp); 610 + __ssp_disable_txwm(ssp); 611 + } 612 + 613 + /** 614 + * sifive_serial_clk_notifier() - clock post-rate-change notifier 615 + * @nb: pointer to the struct notifier_block, from the notifier code 616 + * @event: event mask from the notifier code 617 + * @data: pointer to the struct clk_notifier_data from the notifier code 618 + * 619 + * On the V0 SoC, the UART IP block is derived from the CPU clock source 620 + * after a synchronous divide-by-two divider, so any CPU clock rate change 621 + * requires the UART baud rate to be updated. This presumably could corrupt any 622 + * serial word currently being transmitted or received. It would probably 623 + * be better to stop receives and transmits, then complete the baud rate 624 + * change, then re-enable them. 625 + */ 626 + static int sifive_serial_clk_notifier(struct notifier_block *nb, 627 + unsigned long event, void *data) 628 + { 629 + struct clk_notifier_data *cnd = data; 630 + struct sifive_serial_port *ssp = notifier_to_sifive_serial_port(nb); 631 + 632 + if (event == POST_RATE_CHANGE && ssp->clkin_rate != cnd->new_rate) { 633 + ssp->clkin_rate = cnd->new_rate; 634 + __ssp_update_div(ssp); 635 + } 636 + 637 + return NOTIFY_OK; 638 + } 639 + 640 + static void sifive_serial_set_termios(struct uart_port *port, 641 + struct ktermios *termios, 642 + struct ktermios *old) 643 + { 644 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 645 + unsigned long flags; 646 + u32 v, old_v; 647 + int rate; 648 + char nstop; 649 + 650 + if ((termios->c_cflag & CSIZE) != CS8) 651 + dev_err_once(ssp->port.dev, "only 8-bit words supported\n"); 652 + if (termios->c_iflag & (INPCK | PARMRK)) 653 + dev_err_once(ssp->port.dev, "parity checking not supported\n"); 654 + if (termios->c_iflag & BRKINT) 655 + dev_err_once(ssp->port.dev, "BREAK detection not supported\n"); 656 + 657 + /* Set number of stop bits */ 658 + nstop = (termios->c_cflag & CSTOPB) ? 2 : 1; 659 + __ssp_set_stop_bits(ssp, nstop); 660 + 661 + /* Set line rate */ 662 + rate = uart_get_baud_rate(port, termios, old, 0, ssp->clkin_rate / 16); 663 + __ssp_update_baud_rate(ssp, rate); 664 + 665 + spin_lock_irqsave(&ssp->port.lock, flags); 666 + 667 + /* Update the per-port timeout */ 668 + uart_update_timeout(port, termios->c_cflag, rate); 669 + 670 + ssp->port.read_status_mask = 0; 671 + 672 + /* Ignore all characters if CREAD is not set */ 673 + v = __ssp_readl(ssp, SIFIVE_SERIAL_RXCTRL_OFFS); 674 + old_v = v; 675 + if ((termios->c_cflag & CREAD) == 0) 676 + v &= SIFIVE_SERIAL_RXCTRL_RXEN_MASK; 677 + else 678 + v |= SIFIVE_SERIAL_RXCTRL_RXEN_MASK; 679 + if (v != old_v) 680 + __ssp_writel(v, SIFIVE_SERIAL_RXCTRL_OFFS, ssp); 681 + 682 + spin_unlock_irqrestore(&ssp->port.lock, flags); 683 + } 684 + 685 + static void sifive_serial_release_port(struct uart_port *port) 686 + { 687 + } 688 + 689 + static int sifive_serial_request_port(struct uart_port *port) 690 + { 691 + return 0; 692 + } 693 + 694 + static void sifive_serial_config_port(struct uart_port *port, int flags) 695 + { 696 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 697 + 698 + ssp->port.type = PORT_SIFIVE_V0; 699 + } 700 + 701 + static int sifive_serial_verify_port(struct uart_port *port, 702 + struct serial_struct *ser) 703 + { 704 + return -EINVAL; 705 + } 706 + 707 + static const char *sifive_serial_type(struct uart_port *port) 708 + { 709 + return port->type == PORT_SIFIVE_V0 ? "SiFive UART v0" : NULL; 710 + } 711 + 712 + /* 713 + * Early console support 714 + */ 715 + 716 + #ifdef CONFIG_SERIAL_EARLYCON 717 + static void early_sifive_serial_putc(struct uart_port *port, int c) 718 + { 719 + while (__ssp_early_readl(port, SIFIVE_SERIAL_TXDATA_OFFS) & 720 + SIFIVE_SERIAL_TXDATA_FULL_MASK) 721 + cpu_relax(); 722 + 723 + __ssp_early_writel(c, SIFIVE_SERIAL_TXDATA_OFFS, port); 724 + } 725 + 726 + static void early_sifive_serial_write(struct console *con, const char *s, 727 + unsigned int n) 728 + { 729 + struct earlycon_device *dev = con->data; 730 + struct uart_port *port = &dev->port; 731 + 732 + uart_console_write(port, s, n, early_sifive_serial_putc); 733 + } 734 + 735 + static int __init early_sifive_serial_setup(struct earlycon_device *dev, 736 + const char *options) 737 + { 738 + struct uart_port *port = &dev->port; 739 + 740 + if (!port->membase) 741 + return -ENODEV; 742 + 743 + dev->con->write = early_sifive_serial_write; 744 + 745 + return 0; 746 + } 747 + 748 + OF_EARLYCON_DECLARE(sifive, "sifive,uart0", early_sifive_serial_setup); 749 + OF_EARLYCON_DECLARE(sifive, "sifive,fu540-c000-uart0", 750 + early_sifive_serial_setup); 751 + #endif /* CONFIG_SERIAL_EARLYCON */ 752 + 753 + /* 754 + * Linux console interface 755 + */ 756 + 757 + #ifdef CONFIG_SERIAL_SIFIVE_CONSOLE 758 + 759 + static struct sifive_serial_port *sifive_serial_console_ports[SIFIVE_SERIAL_MAX_PORTS]; 760 + 761 + static void sifive_serial_console_putchar(struct uart_port *port, int ch) 762 + { 763 + struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); 764 + 765 + __ssp_wait_for_xmitr(ssp); 766 + __ssp_transmit_char(ssp, ch); 767 + } 768 + 769 + static void sifive_serial_console_write(struct console *co, const char *s, 770 + unsigned int count) 771 + { 772 + struct sifive_serial_port *ssp = sifive_serial_console_ports[co->index]; 773 + unsigned long flags; 774 + unsigned int ier; 775 + int locked = 1; 776 + 777 + if (!ssp) 778 + return; 779 + 780 + local_irq_save(flags); 781 + if (ssp->port.sysrq) 782 + locked = 0; 783 + else if (oops_in_progress) 784 + locked = spin_trylock(&ssp->port.lock); 785 + else 786 + spin_lock(&ssp->port.lock); 787 + 788 + ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); 789 + __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); 790 + 791 + uart_console_write(&ssp->port, s, count, sifive_serial_console_putchar); 792 + 793 + __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); 794 + 795 + if (locked) 796 + spin_unlock(&ssp->port.lock); 797 + local_irq_restore(flags); 798 + } 799 + 800 + static int __init sifive_serial_console_setup(struct console *co, char *options) 801 + { 802 + struct sifive_serial_port *ssp; 803 + int baud = SIFIVE_DEFAULT_BAUD_RATE; 804 + int bits = 8; 805 + int parity = 'n'; 806 + int flow = 'n'; 807 + 808 + if (co->index < 0 || co->index >= SIFIVE_SERIAL_MAX_PORTS) 809 + return -ENODEV; 810 + 811 + ssp = sifive_serial_console_ports[co->index]; 812 + if (!ssp) 813 + return -ENODEV; 814 + 815 + if (options) 816 + uart_parse_options(options, &baud, &parity, &bits, &flow); 817 + 818 + return uart_set_options(&ssp->port, co, baud, parity, bits, flow); 819 + } 820 + 821 + static struct uart_driver sifive_serial_uart_driver; 822 + 823 + static struct console sifive_serial_console = { 824 + .name = SIFIVE_TTY_PREFIX, 825 + .write = sifive_serial_console_write, 826 + .device = uart_console_device, 827 + .setup = sifive_serial_console_setup, 828 + .flags = CON_PRINTBUFFER, 829 + .index = -1, 830 + .data = &sifive_serial_uart_driver, 831 + }; 832 + 833 + static int __init sifive_console_init(void) 834 + { 835 + register_console(&sifive_serial_console); 836 + return 0; 837 + } 838 + 839 + console_initcall(sifive_console_init); 840 + 841 + static void __ssp_add_console_port(struct sifive_serial_port *ssp) 842 + { 843 + sifive_serial_console_ports[ssp->port.line] = ssp; 844 + } 845 + 846 + static void __ssp_remove_console_port(struct sifive_serial_port *ssp) 847 + { 848 + sifive_serial_console_ports[ssp->port.line] = 0; 849 + } 850 + 851 + #define SIFIVE_SERIAL_CONSOLE (&sifive_serial_console) 852 + 853 + #else 854 + 855 + #define SIFIVE_SERIAL_CONSOLE NULL 856 + 857 + static void __ssp_add_console_port(struct sifive_serial_port *ssp) 858 + {} 859 + static void __ssp_remove_console_port(struct sifive_serial_port *ssp) 860 + {} 861 + 862 + #endif 863 + 864 + static const struct uart_ops sifive_serial_uops = { 865 + .tx_empty = sifive_serial_tx_empty, 866 + .set_mctrl = sifive_serial_set_mctrl, 867 + .get_mctrl = sifive_serial_get_mctrl, 868 + .stop_tx = sifive_serial_stop_tx, 869 + .start_tx = sifive_serial_start_tx, 870 + .stop_rx = sifive_serial_stop_rx, 871 + .break_ctl = sifive_serial_break_ctl, 872 + .startup = sifive_serial_startup, 873 + .shutdown = sifive_serial_shutdown, 874 + .set_termios = sifive_serial_set_termios, 875 + .type = sifive_serial_type, 876 + .release_port = sifive_serial_release_port, 877 + .request_port = sifive_serial_request_port, 878 + .config_port = sifive_serial_config_port, 879 + .verify_port = sifive_serial_verify_port, 880 + }; 881 + 882 + static struct uart_driver sifive_serial_uart_driver = { 883 + .owner = THIS_MODULE, 884 + .driver_name = SIFIVE_SERIAL_NAME, 885 + .dev_name = SIFIVE_TTY_PREFIX, 886 + .nr = SIFIVE_SERIAL_MAX_PORTS, 887 + .cons = SIFIVE_SERIAL_CONSOLE, 888 + }; 889 + 890 + static int sifive_serial_probe(struct platform_device *pdev) 891 + { 892 + struct sifive_serial_port *ssp; 893 + struct resource *mem; 894 + struct clk *clk; 895 + void __iomem *base; 896 + int irq, id, r; 897 + 898 + irq = platform_get_irq(pdev, 0); 899 + if (irq < 0) { 900 + dev_err(&pdev->dev, "could not acquire interrupt\n"); 901 + return -EPROBE_DEFER; 902 + } 903 + 904 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 905 + base = devm_ioremap_resource(&pdev->dev, mem); 906 + if (IS_ERR(base)) { 907 + dev_err(&pdev->dev, "could not acquire device memory\n"); 908 + return PTR_ERR(base); 909 + } 910 + 911 + clk = devm_clk_get(&pdev->dev, NULL); 912 + if (IS_ERR(clk)) { 913 + dev_err(&pdev->dev, "unable to find controller clock\n"); 914 + return PTR_ERR(clk); 915 + } 916 + 917 + id = of_alias_get_id(pdev->dev.of_node, "serial"); 918 + if (id < 0) { 919 + dev_err(&pdev->dev, "missing aliases entry\n"); 920 + return id; 921 + } 922 + 923 + #ifdef CONFIG_SERIAL_SIFIVE_CONSOLE 924 + if (id > SIFIVE_SERIAL_MAX_PORTS) { 925 + dev_err(&pdev->dev, "too many UARTs (%d)\n", id); 926 + return -EINVAL; 927 + } 928 + #endif 929 + 930 + ssp = devm_kzalloc(&pdev->dev, sizeof(*ssp), GFP_KERNEL); 931 + if (!ssp) 932 + return -ENOMEM; 933 + 934 + ssp->port.dev = &pdev->dev; 935 + ssp->port.type = PORT_SIFIVE_V0; 936 + ssp->port.iotype = UPIO_MEM; 937 + ssp->port.irq = irq; 938 + ssp->port.fifosize = SIFIVE_TX_FIFO_DEPTH; 939 + ssp->port.ops = &sifive_serial_uops; 940 + ssp->port.line = id; 941 + ssp->port.mapbase = mem->start; 942 + ssp->port.membase = base; 943 + ssp->dev = &pdev->dev; 944 + ssp->clk = clk; 945 + ssp->clk_notifier.notifier_call = sifive_serial_clk_notifier; 946 + 947 + r = clk_notifier_register(ssp->clk, &ssp->clk_notifier); 948 + if (r) { 949 + dev_err(&pdev->dev, "could not register clock notifier: %d\n", 950 + r); 951 + goto probe_out1; 952 + } 953 + 954 + /* Set up clock divider */ 955 + ssp->clkin_rate = clk_get_rate(ssp->clk); 956 + ssp->baud_rate = SIFIVE_DEFAULT_BAUD_RATE; 957 + __ssp_update_div(ssp); 958 + 959 + platform_set_drvdata(pdev, ssp); 960 + 961 + /* Enable transmits and set the watermark level to 1 */ 962 + __ssp_writel((1 << SIFIVE_SERIAL_TXCTRL_TXCNT_SHIFT) | 963 + SIFIVE_SERIAL_TXCTRL_TXEN_MASK, 964 + SIFIVE_SERIAL_TXCTRL_OFFS, ssp); 965 + 966 + /* Enable receives and set the watermark level to 0 */ 967 + __ssp_writel((0 << SIFIVE_SERIAL_RXCTRL_RXCNT_SHIFT) | 968 + SIFIVE_SERIAL_RXCTRL_RXEN_MASK, 969 + SIFIVE_SERIAL_RXCTRL_OFFS, ssp); 970 + 971 + r = request_irq(ssp->port.irq, sifive_serial_irq, ssp->port.irqflags, 972 + dev_name(&pdev->dev), ssp); 973 + if (r) { 974 + dev_err(&pdev->dev, "could not attach interrupt: %d\n", r); 975 + goto probe_out2; 976 + } 977 + 978 + __ssp_add_console_port(ssp); 979 + 980 + r = uart_add_one_port(&sifive_serial_uart_driver, &ssp->port); 981 + if (r != 0) { 982 + dev_err(&pdev->dev, "could not add uart: %d\n", r); 983 + goto probe_out3; 984 + } 985 + 986 + return 0; 987 + 988 + probe_out3: 989 + __ssp_remove_console_port(ssp); 990 + free_irq(ssp->port.irq, ssp); 991 + probe_out2: 992 + clk_notifier_unregister(ssp->clk, &ssp->clk_notifier); 993 + probe_out1: 994 + return r; 995 + } 996 + 997 + static int sifive_serial_remove(struct platform_device *dev) 998 + { 999 + struct sifive_serial_port *ssp = platform_get_drvdata(dev); 1000 + 1001 + __ssp_remove_console_port(ssp); 1002 + uart_remove_one_port(&sifive_serial_uart_driver, &ssp->port); 1003 + free_irq(ssp->port.irq, ssp); 1004 + clk_notifier_unregister(ssp->clk, &ssp->clk_notifier); 1005 + 1006 + return 0; 1007 + } 1008 + 1009 + static const struct of_device_id sifive_serial_of_match[] = { 1010 + { .compatible = "sifive,fu540-c000-uart0" }, 1011 + { .compatible = "sifive,uart0" }, 1012 + {}, 1013 + }; 1014 + MODULE_DEVICE_TABLE(of, sifive_serial_of_match); 1015 + 1016 + static struct platform_driver sifive_serial_platform_driver = { 1017 + .probe = sifive_serial_probe, 1018 + .remove = sifive_serial_remove, 1019 + .driver = { 1020 + .name = SIFIVE_SERIAL_NAME, 1021 + .of_match_table = of_match_ptr(sifive_serial_of_match), 1022 + }, 1023 + }; 1024 + 1025 + static int __init sifive_serial_init(void) 1026 + { 1027 + int r; 1028 + 1029 + r = uart_register_driver(&sifive_serial_uart_driver); 1030 + if (r) 1031 + goto init_out1; 1032 + 1033 + r = platform_driver_register(&sifive_serial_platform_driver); 1034 + if (r) 1035 + goto init_out2; 1036 + 1037 + return 0; 1038 + 1039 + init_out2: 1040 + uart_unregister_driver(&sifive_serial_uart_driver); 1041 + init_out1: 1042 + return r; 1043 + } 1044 + 1045 + static void __exit sifive_serial_exit(void) 1046 + { 1047 + platform_driver_unregister(&sifive_serial_platform_driver); 1048 + uart_unregister_driver(&sifive_serial_uart_driver); 1049 + } 1050 + 1051 + module_init(sifive_serial_init); 1052 + module_exit(sifive_serial_exit); 1053 + 1054 + MODULE_DESCRIPTION("SiFive UART serial driver"); 1055 + MODULE_LICENSE("GPL"); 1056 + MODULE_AUTHOR("Paul Walmsley <paul@pwsan.com>");
+1
drivers/tty/serial/sn_console.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * C-Brick Serial Port (and console) driver for SGI Altix machines. 3 4 *
+495 -30
drivers/tty/serial/sprd_serial.c
··· 10 10 #include <linux/clk.h> 11 11 #include <linux/console.h> 12 12 #include <linux/delay.h> 13 + #include <linux/dmaengine.h> 14 + #include <linux/dma-mapping.h> 15 + #include <linux/dma/sprd-dma.h> 13 16 #include <linux/io.h> 14 17 #include <linux/ioport.h> 15 18 #include <linux/kernel.h> ··· 78 75 79 76 /* control register 1 */ 80 77 #define SPRD_CTL1 0x001C 78 + #define SPRD_DMA_EN BIT(15) 81 79 #define RX_HW_FLOW_CTL_THLD BIT(6) 82 80 #define RX_HW_FLOW_CTL_EN BIT(7) 83 81 #define TX_HW_FLOW_CTL_EN BIT(8) ··· 90 86 #define THLD_TX_EMPTY 0x40 91 87 #define THLD_TX_EMPTY_SHIFT 8 92 88 #define THLD_RX_FULL 0x40 89 + #define THLD_RX_FULL_MASK GENMASK(6, 0) 93 90 94 91 /* config baud rate register */ 95 92 #define SPRD_CLKD0 0x0024 ··· 105 100 #define SPRD_IMSR_TX_FIFO_EMPTY BIT(1) 106 101 #define SPRD_IMSR_BREAK_DETECT BIT(7) 107 102 #define SPRD_IMSR_TIMEOUT BIT(13) 103 + #define SPRD_DEFAULT_SOURCE_CLK 26000000 104 + 105 + #define SPRD_RX_DMA_STEP 1 106 + #define SPRD_RX_FIFO_FULL 1 107 + #define SPRD_TX_FIFO_FULL 0x20 108 + #define SPRD_UART_RX_SIZE (UART_XMIT_SIZE / 4) 109 + 110 + struct sprd_uart_dma { 111 + struct dma_chan *chn; 112 + unsigned char *virt; 113 + dma_addr_t phys_addr; 114 + dma_cookie_t cookie; 115 + u32 trans_len; 116 + bool enable; 117 + }; 108 118 109 119 struct sprd_uart_port { 110 120 struct uart_port port; 111 121 char name[16]; 122 + struct clk *clk; 123 + struct sprd_uart_dma tx_dma; 124 + struct sprd_uart_dma rx_dma; 125 + dma_addr_t pos; 126 + unsigned char *rx_buf_tail; 112 127 }; 113 128 114 129 static struct sprd_uart_port *sprd_port[UART_NR_MAX]; 115 130 static int sprd_ports_num; 131 + 132 + static int sprd_start_dma_rx(struct uart_port *port); 133 + static int sprd_tx_dma_config(struct uart_port *port); 116 134 117 135 static inline unsigned int serial_in(struct uart_port *port, 118 136 unsigned int offset) ··· 167 139 /* nothing to do */ 168 140 } 169 141 170 - static void sprd_stop_tx(struct uart_port *port) 171 - { 172 - unsigned int ien, iclr; 173 - 174 - iclr = serial_in(port, SPRD_ICLR); 175 - ien = serial_in(port, SPRD_IEN); 176 - 177 - iclr |= SPRD_IEN_TX_EMPTY; 178 - ien &= ~SPRD_IEN_TX_EMPTY; 179 - 180 - serial_out(port, SPRD_ICLR, iclr); 181 - serial_out(port, SPRD_IEN, ien); 182 - } 183 - 184 - static void sprd_start_tx(struct uart_port *port) 185 - { 186 - unsigned int ien; 187 - 188 - ien = serial_in(port, SPRD_IEN); 189 - if (!(ien & SPRD_IEN_TX_EMPTY)) { 190 - ien |= SPRD_IEN_TX_EMPTY; 191 - serial_out(port, SPRD_IEN, ien); 192 - } 193 - } 194 - 195 142 static void sprd_stop_rx(struct uart_port *port) 196 143 { 144 + struct sprd_uart_port *sp = 145 + container_of(port, struct sprd_uart_port, port); 197 146 unsigned int ien, iclr; 147 + 148 + if (sp->rx_dma.enable) 149 + dmaengine_terminate_all(sp->rx_dma.chn); 198 150 199 151 iclr = serial_in(port, SPRD_ICLR); 200 152 ien = serial_in(port, SPRD_IEN); ··· 184 176 185 177 serial_out(port, SPRD_IEN, ien); 186 178 serial_out(port, SPRD_ICLR, iclr); 179 + } 180 + 181 + static void sprd_uart_dma_enable(struct uart_port *port, bool enable) 182 + { 183 + u32 val = serial_in(port, SPRD_CTL1); 184 + 185 + if (enable) 186 + val |= SPRD_DMA_EN; 187 + else 188 + val &= ~SPRD_DMA_EN; 189 + 190 + serial_out(port, SPRD_CTL1, val); 191 + } 192 + 193 + static void sprd_stop_tx_dma(struct uart_port *port) 194 + { 195 + struct sprd_uart_port *sp = 196 + container_of(port, struct sprd_uart_port, port); 197 + struct circ_buf *xmit = &port->state->xmit; 198 + struct dma_tx_state state; 199 + u32 trans_len; 200 + 201 + dmaengine_pause(sp->tx_dma.chn); 202 + 203 + dmaengine_tx_status(sp->tx_dma.chn, sp->tx_dma.cookie, &state); 204 + if (state.residue) { 205 + trans_len = state.residue - sp->tx_dma.phys_addr; 206 + xmit->tail = (xmit->tail + trans_len) & (UART_XMIT_SIZE - 1); 207 + port->icount.tx += trans_len; 208 + dma_unmap_single(port->dev, sp->tx_dma.phys_addr, 209 + sp->tx_dma.trans_len, DMA_TO_DEVICE); 210 + } 211 + 212 + dmaengine_terminate_all(sp->tx_dma.chn); 213 + sp->tx_dma.trans_len = 0; 214 + } 215 + 216 + static int sprd_tx_buf_remap(struct uart_port *port) 217 + { 218 + struct sprd_uart_port *sp = 219 + container_of(port, struct sprd_uart_port, port); 220 + struct circ_buf *xmit = &port->state->xmit; 221 + 222 + sp->tx_dma.trans_len = 223 + CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 224 + 225 + sp->tx_dma.phys_addr = dma_map_single(port->dev, 226 + (void *)&(xmit->buf[xmit->tail]), 227 + sp->tx_dma.trans_len, 228 + DMA_TO_DEVICE); 229 + return dma_mapping_error(port->dev, sp->tx_dma.phys_addr); 230 + } 231 + 232 + static void sprd_complete_tx_dma(void *data) 233 + { 234 + struct uart_port *port = (struct uart_port *)data; 235 + struct sprd_uart_port *sp = 236 + container_of(port, struct sprd_uart_port, port); 237 + struct circ_buf *xmit = &port->state->xmit; 238 + unsigned long flags; 239 + 240 + spin_lock_irqsave(&port->lock, flags); 241 + dma_unmap_single(port->dev, sp->tx_dma.phys_addr, 242 + sp->tx_dma.trans_len, DMA_TO_DEVICE); 243 + 244 + xmit->tail = (xmit->tail + sp->tx_dma.trans_len) & (UART_XMIT_SIZE - 1); 245 + port->icount.tx += sp->tx_dma.trans_len; 246 + 247 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 248 + uart_write_wakeup(port); 249 + 250 + if (uart_circ_empty(xmit) || sprd_tx_buf_remap(port) || 251 + sprd_tx_dma_config(port)) 252 + sp->tx_dma.trans_len = 0; 253 + 254 + spin_unlock_irqrestore(&port->lock, flags); 255 + } 256 + 257 + static int sprd_uart_dma_submit(struct uart_port *port, 258 + struct sprd_uart_dma *ud, u32 trans_len, 259 + enum dma_transfer_direction direction, 260 + dma_async_tx_callback callback) 261 + { 262 + struct dma_async_tx_descriptor *dma_des; 263 + unsigned long flags; 264 + 265 + flags = SPRD_DMA_FLAGS(SPRD_DMA_CHN_MODE_NONE, 266 + SPRD_DMA_NO_TRG, 267 + SPRD_DMA_FRAG_REQ, 268 + SPRD_DMA_TRANS_INT); 269 + 270 + dma_des = dmaengine_prep_slave_single(ud->chn, ud->phys_addr, trans_len, 271 + direction, flags); 272 + if (!dma_des) 273 + return -ENODEV; 274 + 275 + dma_des->callback = callback; 276 + dma_des->callback_param = port; 277 + 278 + ud->cookie = dmaengine_submit(dma_des); 279 + if (dma_submit_error(ud->cookie)) 280 + return dma_submit_error(ud->cookie); 281 + 282 + dma_async_issue_pending(ud->chn); 283 + 284 + return 0; 285 + } 286 + 287 + static int sprd_tx_dma_config(struct uart_port *port) 288 + { 289 + struct sprd_uart_port *sp = 290 + container_of(port, struct sprd_uart_port, port); 291 + u32 burst = sp->tx_dma.trans_len > SPRD_TX_FIFO_FULL ? 292 + SPRD_TX_FIFO_FULL : sp->tx_dma.trans_len; 293 + int ret; 294 + struct dma_slave_config cfg = { 295 + .dst_addr = port->mapbase + SPRD_TXD, 296 + .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 297 + .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 298 + .src_maxburst = burst, 299 + }; 300 + 301 + ret = dmaengine_slave_config(sp->tx_dma.chn, &cfg); 302 + if (ret < 0) 303 + return ret; 304 + 305 + return sprd_uart_dma_submit(port, &sp->tx_dma, sp->tx_dma.trans_len, 306 + DMA_MEM_TO_DEV, sprd_complete_tx_dma); 307 + } 308 + 309 + static void sprd_start_tx_dma(struct uart_port *port) 310 + { 311 + struct sprd_uart_port *sp = 312 + container_of(port, struct sprd_uart_port, port); 313 + struct circ_buf *xmit = &port->state->xmit; 314 + 315 + if (port->x_char) { 316 + serial_out(port, SPRD_TXD, port->x_char); 317 + port->icount.tx++; 318 + port->x_char = 0; 319 + return; 320 + } 321 + 322 + if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 323 + sprd_stop_tx_dma(port); 324 + return; 325 + } 326 + 327 + if (sp->tx_dma.trans_len) 328 + return; 329 + 330 + if (sprd_tx_buf_remap(port) || sprd_tx_dma_config(port)) 331 + sp->tx_dma.trans_len = 0; 332 + } 333 + 334 + static void sprd_rx_full_thld(struct uart_port *port, u32 thld) 335 + { 336 + u32 val = serial_in(port, SPRD_CTL2); 337 + 338 + val &= ~THLD_RX_FULL_MASK; 339 + val |= thld & THLD_RX_FULL_MASK; 340 + serial_out(port, SPRD_CTL2, val); 341 + } 342 + 343 + static int sprd_rx_alloc_buf(struct sprd_uart_port *sp) 344 + { 345 + sp->rx_dma.virt = dma_alloc_coherent(sp->port.dev, SPRD_UART_RX_SIZE, 346 + &sp->rx_dma.phys_addr, GFP_KERNEL); 347 + if (!sp->rx_dma.virt) 348 + return -ENOMEM; 349 + 350 + return 0; 351 + } 352 + 353 + static void sprd_rx_free_buf(struct sprd_uart_port *sp) 354 + { 355 + if (sp->rx_dma.virt) 356 + dma_free_coherent(sp->port.dev, SPRD_UART_RX_SIZE, 357 + sp->rx_dma.virt, sp->rx_dma.phys_addr); 358 + 359 + } 360 + 361 + static int sprd_rx_dma_config(struct uart_port *port, u32 burst) 362 + { 363 + struct sprd_uart_port *sp = 364 + container_of(port, struct sprd_uart_port, port); 365 + struct dma_slave_config cfg = { 366 + .src_addr = port->mapbase + SPRD_RXD, 367 + .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 368 + .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 369 + .src_maxburst = burst, 370 + }; 371 + 372 + return dmaengine_slave_config(sp->rx_dma.chn, &cfg); 373 + } 374 + 375 + static void sprd_uart_dma_rx(struct uart_port *port) 376 + { 377 + struct sprd_uart_port *sp = 378 + container_of(port, struct sprd_uart_port, port); 379 + struct tty_port *tty = &port->state->port; 380 + 381 + port->icount.rx += sp->rx_dma.trans_len; 382 + tty_insert_flip_string(tty, sp->rx_buf_tail, sp->rx_dma.trans_len); 383 + tty_flip_buffer_push(tty); 384 + } 385 + 386 + static void sprd_uart_dma_irq(struct uart_port *port) 387 + { 388 + struct sprd_uart_port *sp = 389 + container_of(port, struct sprd_uart_port, port); 390 + struct dma_tx_state state; 391 + enum dma_status status; 392 + 393 + status = dmaengine_tx_status(sp->rx_dma.chn, 394 + sp->rx_dma.cookie, &state); 395 + if (status == DMA_ERROR) 396 + sprd_stop_rx(port); 397 + 398 + if (!state.residue && sp->pos == sp->rx_dma.phys_addr) 399 + return; 400 + 401 + if (!state.residue) { 402 + sp->rx_dma.trans_len = SPRD_UART_RX_SIZE + 403 + sp->rx_dma.phys_addr - sp->pos; 404 + sp->pos = sp->rx_dma.phys_addr; 405 + } else { 406 + sp->rx_dma.trans_len = state.residue - sp->pos; 407 + sp->pos = state.residue; 408 + } 409 + 410 + sprd_uart_dma_rx(port); 411 + sp->rx_buf_tail += sp->rx_dma.trans_len; 412 + } 413 + 414 + static void sprd_complete_rx_dma(void *data) 415 + { 416 + struct uart_port *port = (struct uart_port *)data; 417 + struct sprd_uart_port *sp = 418 + container_of(port, struct sprd_uart_port, port); 419 + struct dma_tx_state state; 420 + enum dma_status status; 421 + unsigned long flags; 422 + 423 + spin_lock_irqsave(&port->lock, flags); 424 + 425 + status = dmaengine_tx_status(sp->rx_dma.chn, 426 + sp->rx_dma.cookie, &state); 427 + if (status != DMA_COMPLETE) { 428 + sprd_stop_rx(port); 429 + spin_unlock_irqrestore(&port->lock, flags); 430 + return; 431 + } 432 + 433 + if (sp->pos != sp->rx_dma.phys_addr) { 434 + sp->rx_dma.trans_len = SPRD_UART_RX_SIZE + 435 + sp->rx_dma.phys_addr - sp->pos; 436 + sprd_uart_dma_rx(port); 437 + sp->rx_buf_tail += sp->rx_dma.trans_len; 438 + } 439 + 440 + if (sprd_start_dma_rx(port)) 441 + sprd_stop_rx(port); 442 + 443 + spin_unlock_irqrestore(&port->lock, flags); 444 + } 445 + 446 + static int sprd_start_dma_rx(struct uart_port *port) 447 + { 448 + struct sprd_uart_port *sp = 449 + container_of(port, struct sprd_uart_port, port); 450 + int ret; 451 + 452 + if (!sp->rx_dma.enable) 453 + return 0; 454 + 455 + sp->pos = sp->rx_dma.phys_addr; 456 + sp->rx_buf_tail = sp->rx_dma.virt; 457 + sprd_rx_full_thld(port, SPRD_RX_FIFO_FULL); 458 + ret = sprd_rx_dma_config(port, SPRD_RX_DMA_STEP); 459 + if (ret) 460 + return ret; 461 + 462 + return sprd_uart_dma_submit(port, &sp->rx_dma, SPRD_UART_RX_SIZE, 463 + DMA_DEV_TO_MEM, sprd_complete_rx_dma); 464 + } 465 + 466 + static void sprd_release_dma(struct uart_port *port) 467 + { 468 + struct sprd_uart_port *sp = 469 + container_of(port, struct sprd_uart_port, port); 470 + 471 + sprd_uart_dma_enable(port, false); 472 + 473 + if (sp->rx_dma.enable) 474 + dma_release_channel(sp->rx_dma.chn); 475 + 476 + if (sp->tx_dma.enable) 477 + dma_release_channel(sp->tx_dma.chn); 478 + 479 + sp->tx_dma.enable = false; 480 + sp->rx_dma.enable = false; 481 + } 482 + 483 + static void sprd_request_dma(struct uart_port *port) 484 + { 485 + struct sprd_uart_port *sp = 486 + container_of(port, struct sprd_uart_port, port); 487 + 488 + sp->tx_dma.enable = true; 489 + sp->rx_dma.enable = true; 490 + 491 + sp->tx_dma.chn = dma_request_chan(port->dev, "tx"); 492 + if (IS_ERR(sp->tx_dma.chn)) { 493 + dev_err(port->dev, "request TX DMA channel failed, ret = %ld\n", 494 + PTR_ERR(sp->tx_dma.chn)); 495 + sp->tx_dma.enable = false; 496 + } 497 + 498 + sp->rx_dma.chn = dma_request_chan(port->dev, "rx"); 499 + if (IS_ERR(sp->rx_dma.chn)) { 500 + dev_err(port->dev, "request RX DMA channel failed, ret = %ld\n", 501 + PTR_ERR(sp->rx_dma.chn)); 502 + sp->rx_dma.enable = false; 503 + } 504 + } 505 + 506 + static void sprd_stop_tx(struct uart_port *port) 507 + { 508 + struct sprd_uart_port *sp = container_of(port, struct sprd_uart_port, 509 + port); 510 + unsigned int ien, iclr; 511 + 512 + if (sp->tx_dma.enable) { 513 + sprd_stop_tx_dma(port); 514 + return; 515 + } 516 + 517 + iclr = serial_in(port, SPRD_ICLR); 518 + ien = serial_in(port, SPRD_IEN); 519 + 520 + iclr |= SPRD_IEN_TX_EMPTY; 521 + ien &= ~SPRD_IEN_TX_EMPTY; 522 + 523 + serial_out(port, SPRD_IEN, ien); 524 + serial_out(port, SPRD_ICLR, iclr); 525 + } 526 + 527 + static void sprd_start_tx(struct uart_port *port) 528 + { 529 + struct sprd_uart_port *sp = container_of(port, struct sprd_uart_port, 530 + port); 531 + unsigned int ien; 532 + 533 + if (sp->tx_dma.enable) { 534 + sprd_start_tx_dma(port); 535 + return; 536 + } 537 + 538 + ien = serial_in(port, SPRD_IEN); 539 + if (!(ien & SPRD_IEN_TX_EMPTY)) { 540 + ien |= SPRD_IEN_TX_EMPTY; 541 + serial_out(port, SPRD_IEN, ien); 542 + } 187 543 } 188 544 189 545 /* The Sprd serial does not support this function. */ ··· 590 218 591 219 static inline void sprd_rx(struct uart_port *port) 592 220 { 221 + struct sprd_uart_port *sp = container_of(port, struct sprd_uart_port, 222 + port); 593 223 struct tty_port *tty = &port->state->port; 594 224 unsigned int ch, flag, lsr, max_count = SPRD_TIMEOUT; 225 + 226 + if (sp->rx_dma.enable) { 227 + sprd_uart_dma_irq(port); 228 + return; 229 + } 595 230 596 231 while ((serial_in(port, SPRD_STS1) & SPRD_RX_FIFO_CNT_MASK) && 597 232 max_count--) { ··· 683 304 return IRQ_HANDLED; 684 305 } 685 306 307 + static void sprd_uart_dma_startup(struct uart_port *port, 308 + struct sprd_uart_port *sp) 309 + { 310 + int ret; 311 + 312 + sprd_request_dma(port); 313 + if (!(sp->rx_dma.enable || sp->tx_dma.enable)) 314 + return; 315 + 316 + ret = sprd_start_dma_rx(port); 317 + if (ret) { 318 + sp->rx_dma.enable = false; 319 + dma_release_channel(sp->rx_dma.chn); 320 + dev_warn(port->dev, "fail to start RX dma mode\n"); 321 + } 322 + 323 + sprd_uart_dma_enable(port, true); 324 + } 325 + 686 326 static int sprd_startup(struct uart_port *port) 687 327 { 688 328 int ret = 0; ··· 730 332 /* allocate irq */ 731 333 sp = container_of(port, struct sprd_uart_port, port); 732 334 snprintf(sp->name, sizeof(sp->name), "sprd_serial%d", port->line); 335 + 336 + sprd_uart_dma_startup(port, sp); 337 + 733 338 ret = devm_request_irq(port->dev, port->irq, sprd_handle_irq, 734 339 IRQF_SHARED, sp->name, port); 735 340 if (ret) { ··· 747 346 /* enable interrupt */ 748 347 spin_lock_irqsave(&port->lock, flags); 749 348 ien = serial_in(port, SPRD_IEN); 750 - ien |= SPRD_IEN_RX_FULL | SPRD_IEN_BREAK_DETECT | SPRD_IEN_TIMEOUT; 349 + ien |= SPRD_IEN_BREAK_DETECT | SPRD_IEN_TIMEOUT; 350 + if (!sp->rx_dma.enable) 351 + ien |= SPRD_IEN_RX_FULL; 751 352 serial_out(port, SPRD_IEN, ien); 752 353 spin_unlock_irqrestore(&port->lock, flags); 753 354 ··· 758 355 759 356 static void sprd_shutdown(struct uart_port *port) 760 357 { 358 + sprd_release_dma(port); 761 359 serial_out(port, SPRD_IEN, 0); 762 360 serial_out(port, SPRD_ICLR, ~0); 763 361 devm_free_irq(port->dev, port->irq, port); ··· 895 491 return 0; 896 492 } 897 493 494 + static void sprd_pm(struct uart_port *port, unsigned int state, 495 + unsigned int oldstate) 496 + { 497 + struct sprd_uart_port *sup = 498 + container_of(port, struct sprd_uart_port, port); 499 + 500 + switch (state) { 501 + case UART_PM_STATE_ON: 502 + clk_prepare_enable(sup->clk); 503 + break; 504 + case UART_PM_STATE_OFF: 505 + clk_disable_unprepare(sup->clk); 506 + break; 507 + } 508 + } 509 + 898 510 static const struct uart_ops serial_sprd_ops = { 899 511 .tx_empty = sprd_tx_empty, 900 512 .get_mctrl = sprd_get_mctrl, ··· 927 507 .request_port = sprd_request_port, 928 508 .config_port = sprd_config_port, 929 509 .verify_port = sprd_verify_port, 510 + .pm = sprd_pm, 930 511 }; 931 512 932 513 #ifdef CONFIG_SERIAL_SPRD_CONSOLE ··· 1089 668 if (!sprd_ports_num) 1090 669 uart_unregister_driver(&sprd_uart_driver); 1091 670 671 + sprd_rx_free_buf(sup); 672 + 673 + return 0; 674 + } 675 + 676 + static int sprd_clk_init(struct uart_port *uport) 677 + { 678 + struct clk *clk_uart, *clk_parent; 679 + struct sprd_uart_port *u = sprd_port[uport->line]; 680 + 681 + clk_uart = devm_clk_get(uport->dev, "uart"); 682 + if (IS_ERR(clk_uart)) { 683 + dev_warn(uport->dev, "uart%d can't get uart clock\n", 684 + uport->line); 685 + clk_uart = NULL; 686 + } 687 + 688 + clk_parent = devm_clk_get(uport->dev, "source"); 689 + if (IS_ERR(clk_parent)) { 690 + dev_warn(uport->dev, "uart%d can't get source clock\n", 691 + uport->line); 692 + clk_parent = NULL; 693 + } 694 + 695 + if (!clk_uart || clk_set_parent(clk_uart, clk_parent)) 696 + uport->uartclk = SPRD_DEFAULT_SOURCE_CLK; 697 + else 698 + uport->uartclk = clk_get_rate(clk_uart); 699 + 700 + u->clk = devm_clk_get(uport->dev, "enable"); 701 + if (IS_ERR(u->clk)) { 702 + if (PTR_ERR(u->clk) != -EPROBE_DEFER) 703 + dev_err(uport->dev, "uart%d can't get enable clock\n", 704 + uport->line); 705 + return PTR_ERR(u->clk); 706 + } 707 + 1092 708 return 0; 1093 709 } 1094 710 ··· 1133 675 { 1134 676 struct resource *res; 1135 677 struct uart_port *up; 1136 - struct clk *clk; 1137 678 int irq; 1138 679 int index; 1139 680 int ret; ··· 1161 704 up->ops = &serial_sprd_ops; 1162 705 up->flags = UPF_BOOT_AUTOCONF; 1163 706 1164 - clk = devm_clk_get(&pdev->dev, NULL); 1165 - if (!IS_ERR_OR_NULL(clk)) 1166 - up->uartclk = clk_get_rate(clk); 707 + ret = sprd_clk_init(up); 708 + if (ret) 709 + return ret; 1167 710 1168 711 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1169 712 up->membase = devm_ioremap_resource(&pdev->dev, res); ··· 1178 721 return irq; 1179 722 } 1180 723 up->irq = irq; 724 + 725 + /* 726 + * Allocate one dma buffer to prepare for receive transfer, in case 727 + * memory allocation failure at runtime. 728 + */ 729 + ret = sprd_rx_alloc_buf(sprd_port[index]); 730 + if (ret) 731 + return ret; 1181 732 1182 733 if (!sprd_ports_num) { 1183 734 ret = uart_register_driver(&sprd_uart_driver);
+1 -1
drivers/tty/serial/ucc_uart.c
··· 1081 1081 } 1082 1082 /* UART operations 1083 1083 * 1084 - * Details on these functions can be found in Documentation/serial/driver 1084 + * Details on these functions can be found in Documentation/serial/driver.rst 1085 1085 */ 1086 1086 static const struct uart_ops qe_uart_pops = { 1087 1087 .tx_empty = qe_uart_tx_empty,
+12
drivers/tty/serial/xilinx_uartps.c
··· 193 193 int id; 194 194 struct notifier_block clk_rate_change_nb; 195 195 u32 quirks; 196 + bool cts_override; 196 197 }; 197 198 struct cdns_platform_data { 198 199 u32 quirks; ··· 1001 1000 */ 1002 1001 static unsigned int cdns_uart_get_mctrl(struct uart_port *port) 1003 1002 { 1003 + struct cdns_uart *cdns_uart_data = port->private_data; 1004 + 1005 + if (cdns_uart_data->cts_override) 1006 + return 0; 1007 + 1004 1008 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 1005 1009 } 1006 1010 ··· 1013 1007 { 1014 1008 u32 val; 1015 1009 u32 mode_reg; 1010 + struct cdns_uart *cdns_uart_data = port->private_data; 1011 + 1012 + if (cdns_uart_data->cts_override) 1013 + return; 1016 1014 1017 1015 val = readl(port->membase + CDNS_UART_MODEMCR); 1018 1016 mode_reg = readl(port->membase + CDNS_UART_MR); ··· 1675 1665 console_port = NULL; 1676 1666 #endif 1677 1667 1668 + cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node, 1669 + "cts-override"); 1678 1670 return 0; 1679 1671 1680 1672 err_out_pm_disable:
+3 -3
drivers/tty/sysrq.c
··· 208 208 #endif 209 209 210 210 #ifdef CONFIG_SMP 211 - static DEFINE_SPINLOCK(show_lock); 211 + static DEFINE_RAW_SPINLOCK(show_lock); 212 212 213 213 static void showacpu(void *dummy) 214 214 { ··· 218 218 if (idle_cpu(smp_processor_id())) 219 219 return; 220 220 221 - spin_lock_irqsave(&show_lock, flags); 221 + raw_spin_lock_irqsave(&show_lock, flags); 222 222 pr_info("CPU%d:\n", smp_processor_id()); 223 223 show_stack(NULL, NULL); 224 - spin_unlock_irqrestore(&show_lock, flags); 224 + raw_spin_unlock_irqrestore(&show_lock, flags); 225 225 } 226 226 227 227 static void sysrq_showregs_othercpus(struct work_struct *dummy)
+1 -1
drivers/tty/tty_io.c
··· 1173 1173 * tty_init_termios - helper for termios setup 1174 1174 * @tty: the tty to set up 1175 1175 * 1176 - * Initialise the termios structures for this tty. Thus runs under 1176 + * Initialise the termios structure for this tty. This runs under 1177 1177 * the tty_mutex currently so we can be relaxed about ordering. 1178 1178 */ 1179 1179
+2 -2
drivers/tty/tty_jobctrl.c
··· 44 44 tty_pgrp = tty->pgrp; 45 45 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 46 46 47 - if (tty_pgrp && pgrp != tty->pgrp) { 47 + if (tty_pgrp && pgrp != tty_pgrp) { 48 48 if (is_ignored(sig)) { 49 49 if (sig == SIGTTIN) 50 50 ret = -EIO; ··· 313 313 read_unlock(&tasklist_lock); 314 314 } 315 315 316 - /** 316 + /* 317 317 * 318 318 * no_tty - Ensure the current process does not have a controlling tty 319 319 */
+5 -5
drivers/tty/tty_port.c
··· 325 325 if (tty && C_HUPCL(tty)) 326 326 tty_port_lower_dtr_rts(port); 327 327 328 - if (port->ops && port->ops->shutdown) 328 + if (port->ops->shutdown) 329 329 port->ops->shutdown(port); 330 330 } 331 331 out: ··· 398 398 */ 399 399 int tty_port_carrier_raised(struct tty_port *port) 400 400 { 401 - if (!port->ops || !port->ops->carrier_raised) 401 + if (port->ops->carrier_raised == NULL) 402 402 return 1; 403 403 return port->ops->carrier_raised(port); 404 404 } ··· 414 414 */ 415 415 void tty_port_raise_dtr_rts(struct tty_port *port) 416 416 { 417 - if (port->ops && port->ops->dtr_rts) 417 + if (port->ops->dtr_rts) 418 418 port->ops->dtr_rts(port, 1); 419 419 } 420 420 EXPORT_SYMBOL(tty_port_raise_dtr_rts); ··· 429 429 */ 430 430 void tty_port_lower_dtr_rts(struct tty_port *port) 431 431 { 432 - if (port->ops && port->ops->dtr_rts) 432 + if (port->ops->dtr_rts) 433 433 port->ops->dtr_rts(port, 0); 434 434 } 435 435 EXPORT_SYMBOL(tty_port_lower_dtr_rts); ··· 684 684 685 685 if (!tty_port_initialized(port)) { 686 686 clear_bit(TTY_IO_ERROR, &tty->flags); 687 - if (port->ops && port->ops->activate) { 687 + if (port->ops->activate) { 688 688 int retval = port->ops->activate(port, tty); 689 689 if (retval) { 690 690 mutex_unlock(&port->mutex);
+109
drivers/tty/ttynull.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2019 Axis Communications AB 4 + * 5 + * Based on ttyprintk.c: 6 + * Copyright (C) 2010 Samo Pogacnik 7 + */ 8 + 9 + #include <linux/console.h> 10 + #include <linux/module.h> 11 + #include <linux/tty.h> 12 + 13 + static const struct tty_port_operations ttynull_port_ops; 14 + static struct tty_driver *ttynull_driver; 15 + static struct tty_port ttynull_port; 16 + 17 + static int ttynull_open(struct tty_struct *tty, struct file *filp) 18 + { 19 + return tty_port_open(&ttynull_port, tty, filp); 20 + } 21 + 22 + static void ttynull_close(struct tty_struct *tty, struct file *filp) 23 + { 24 + tty_port_close(&ttynull_port, tty, filp); 25 + } 26 + 27 + static void ttynull_hangup(struct tty_struct *tty) 28 + { 29 + tty_port_hangup(&ttynull_port); 30 + } 31 + 32 + static int ttynull_write(struct tty_struct *tty, const unsigned char *buf, 33 + int count) 34 + { 35 + return count; 36 + } 37 + 38 + static int ttynull_write_room(struct tty_struct *tty) 39 + { 40 + return 65536; 41 + } 42 + 43 + static const struct tty_operations ttynull_ops = { 44 + .open = ttynull_open, 45 + .close = ttynull_close, 46 + .hangup = ttynull_hangup, 47 + .write = ttynull_write, 48 + .write_room = ttynull_write_room, 49 + }; 50 + 51 + static struct tty_driver *ttynull_device(struct console *c, int *index) 52 + { 53 + *index = 0; 54 + return ttynull_driver; 55 + } 56 + 57 + static struct console ttynull_console = { 58 + .name = "ttynull", 59 + .device = ttynull_device, 60 + }; 61 + 62 + static int __init ttynull_init(void) 63 + { 64 + struct tty_driver *driver; 65 + int ret; 66 + 67 + driver = tty_alloc_driver(1, 68 + TTY_DRIVER_RESET_TERMIOS | 69 + TTY_DRIVER_REAL_RAW | 70 + TTY_DRIVER_UNNUMBERED_NODE); 71 + if (IS_ERR(driver)) 72 + return PTR_ERR(driver); 73 + 74 + tty_port_init(&ttynull_port); 75 + ttynull_port.ops = &ttynull_port_ops; 76 + 77 + driver->driver_name = "ttynull"; 78 + driver->name = "ttynull"; 79 + driver->type = TTY_DRIVER_TYPE_CONSOLE; 80 + driver->init_termios = tty_std_termios; 81 + driver->init_termios.c_oflag = OPOST | OCRNL | ONOCR | ONLRET; 82 + tty_set_operations(driver, &ttynull_ops); 83 + tty_port_link_device(&ttynull_port, driver, 0); 84 + 85 + ret = tty_register_driver(driver); 86 + if (ret < 0) { 87 + put_tty_driver(driver); 88 + tty_port_destroy(&ttynull_port); 89 + return ret; 90 + } 91 + 92 + ttynull_driver = driver; 93 + register_console(&ttynull_console); 94 + 95 + return 0; 96 + } 97 + 98 + static void __exit ttynull_exit(void) 99 + { 100 + unregister_console(&ttynull_console); 101 + tty_unregister_driver(ttynull_driver); 102 + put_tty_driver(ttynull_driver); 103 + tty_port_destroy(&ttynull_port); 104 + } 105 + 106 + module_init(ttynull_init); 107 + module_exit(ttynull_exit); 108 + 109 + MODULE_LICENSE("GPL v2");
+1
drivers/tty/vcc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* vcc.c: sun4v virtual channel concentrator 2 3 * 3 4 * Copyright (C) 2017 Oracle. All rights reserved.
+1
drivers/tty/vt/.gitignore
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 consolemap_deftbl.c 2 3 defkeymap.c
+4 -4
drivers/tty/vt/consolemap.c
··· 542 542 if (!ct) 543 543 return 0; 544 544 545 - unilist = memdup_user(list, ct * sizeof(struct unipair)); 545 + unilist = vmemdup_user(list, ct * sizeof(struct unipair)); 546 546 if (IS_ERR(unilist)) 547 547 return PTR_ERR(unilist); 548 548 ··· 641 641 642 642 out_unlock: 643 643 console_unlock(); 644 - kfree(unilist); 644 + kvfree(unilist); 645 645 return err; 646 646 } 647 647 ··· 743 743 struct uni_pagedir *p; 744 744 struct unipair *unilist; 745 745 746 - unilist = kmalloc_array(ct, sizeof(struct unipair), GFP_KERNEL); 746 + unilist = kvmalloc_array(ct, sizeof(struct unipair), GFP_KERNEL); 747 747 if (!unilist) 748 748 return -ENOMEM; 749 749 ··· 775 775 if (copy_to_user(list, unilist, min(ect, ct) * sizeof(struct unipair))) 776 776 ret = -EFAULT; 777 777 put_user(ect, uct); 778 - kfree(unilist); 778 + kvfree(unilist); 779 779 return ret ? ret : (ect <= ct) ? 0 : -ENOMEM; 780 780 } 781 781
+1
drivers/tty/vt/cp437.uni
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # Unicode table for IBM Codepage 437. Note that there are many more 3 4 # substitutions that could be conceived (for example, thick-line
+1
drivers/tty/vt/defkeymap.c_shipped
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* Do not edit this file! It was automatically generated by */ 2 3 /* loadkeys --mktable defkeymap.map > defkeymap.c */ 3 4
+1
drivers/tty/vt/defkeymap.map
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # Default kernel keymap. This uses 7 modifier combinations. 2 3 keymaps 0-2,4-5,8,12 3 4 # Change the above line into
+28 -7
drivers/tty/vt/keyboard.c
··· 123 123 static struct input_handler kbd_handler; 124 124 static DEFINE_SPINLOCK(kbd_event_lock); 125 125 static DEFINE_SPINLOCK(led_lock); 126 + static DEFINE_SPINLOCK(func_buf_lock); /* guard 'func_buf' and friends */ 126 127 static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ 127 128 static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ 128 129 static bool dead_key_next; ··· 1450 1449 KBD_UNICODE, &param); 1451 1450 if (rc != NOTIFY_STOP) 1452 1451 if (down && !raw_mode) 1453 - to_utf8(vc, keysym); 1452 + k_unicode(vc, keysym, !down); 1454 1453 return; 1455 1454 } 1456 1455 ··· 1991 1990 char *p; 1992 1991 u_char *q; 1993 1992 u_char __user *up; 1994 - int sz; 1993 + int sz, fnw_sz; 1995 1994 int delta; 1996 1995 char *first_free, *fj, *fnw; 1997 1996 int i, j, k; 1998 1997 int ret; 1998 + unsigned long flags; 1999 1999 2000 2000 if (!capable(CAP_SYS_TTY_CONFIG)) 2001 2001 perm = 0; ··· 2039 2037 goto reterr; 2040 2038 } 2041 2039 2040 + fnw = NULL; 2041 + fnw_sz = 0; 2042 + /* race aginst other writers */ 2043 + again: 2044 + spin_lock_irqsave(&func_buf_lock, flags); 2042 2045 q = func_table[i]; 2046 + 2047 + /* fj pointer to next entry after 'q' */ 2043 2048 first_free = funcbufptr + (funcbufsize - funcbufleft); 2044 2049 for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++) 2045 2050 ; ··· 2054 2045 fj = func_table[j]; 2055 2046 else 2056 2047 fj = first_free; 2057 - 2048 + /* buffer usage increase by new entry */ 2058 2049 delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string); 2050 + 2059 2051 if (delta <= funcbufleft) { /* it fits in current buf */ 2060 2052 if (j < MAX_NR_FUNC) { 2053 + /* make enough space for new entry at 'fj' */ 2061 2054 memmove(fj + delta, fj, first_free - fj); 2062 2055 for (k = j; k < MAX_NR_FUNC; k++) 2063 2056 if (func_table[k]) ··· 2072 2061 sz = 256; 2073 2062 while (sz < funcbufsize - funcbufleft + delta) 2074 2063 sz <<= 1; 2075 - fnw = kmalloc(sz, GFP_KERNEL); 2076 - if(!fnw) { 2077 - ret = -ENOMEM; 2078 - goto reterr; 2064 + if (fnw_sz != sz) { 2065 + spin_unlock_irqrestore(&func_buf_lock, flags); 2066 + kfree(fnw); 2067 + fnw = kmalloc(sz, GFP_KERNEL); 2068 + fnw_sz = sz; 2069 + if (!fnw) { 2070 + ret = -ENOMEM; 2071 + goto reterr; 2072 + } 2073 + goto again; 2079 2074 } 2080 2075 2081 2076 if (!q) 2082 2077 func_table[i] = fj; 2078 + /* copy data before insertion point to new location */ 2083 2079 if (fj > funcbufptr) 2084 2080 memmove(fnw, funcbufptr, fj - funcbufptr); 2085 2081 for (k = 0; k < j; k++) 2086 2082 if (func_table[k]) 2087 2083 func_table[k] = fnw + (func_table[k] - funcbufptr); 2088 2084 2085 + /* copy data after insertion point to new location */ 2089 2086 if (first_free > fj) { 2090 2087 memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj); 2091 2088 for (k = j; k < MAX_NR_FUNC; k++) ··· 2106 2087 funcbufleft = funcbufleft - delta + sz - funcbufsize; 2107 2088 funcbufsize = sz; 2108 2089 } 2090 + /* finally insert item itself */ 2109 2091 strcpy(func_table[i], kbs->kb_string); 2092 + spin_unlock_irqrestore(&func_buf_lock, flags); 2110 2093 break; 2111 2094 } 2112 2095 ret = 0;
+1 -1
drivers/tty/vt/vc_screen.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 3 * Provide access to virtual console memory. 4 - * /dev/vcs0: the screen as it is being viewed right now (possibly scrolled) 4 + * /dev/vcs: the screen as it is being viewed right now (possibly scrolled) 5 5 * /dev/vcsN: the screen of /dev/ttyN (1 <= N <= 63) 6 6 * [minor: N] 7 7 *
-2
drivers/tty/vt/vt.c
··· 4180 4180 return; 4181 4181 } 4182 4182 4183 - if (blank_state != blank_normal_wait) 4184 - return; 4185 4183 blank_state = blank_off; 4186 4184 4187 4185 /* don't blank graphics */
+1 -1
include/linux/serial_core.h
··· 45 45 46 46 /* 47 47 * This structure describes all the operations that can be done on the 48 - * physical hardware. See Documentation/serial/driver for details. 48 + * physical hardware. See Documentation/serial/driver.rst for details. 49 49 */ 50 50 struct uart_ops { 51 51 unsigned int (*tx_empty)(struct uart_port *);
+6
include/uapi/linux/serial_core.h
··· 287 287 /* RDA UART */ 288 288 #define PORT_RDA 118 289 289 290 + /* Socionext Milbeaut UART */ 291 + #define PORT_MLB_USIO 119 292 + 293 + /* SiFive UART */ 294 + #define PORT_SIFIVE_V0 120 295 + 290 296 #endif /* _UAPILINUX_SERIAL_CORE_H */