aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/uart/uart_dev_ns8250.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC 359899: Correct baud rate error calculation.John Baldwin2020-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | Shifting right by 1 is not the same as dividing by 2 for signed values. In particular, dividing a signed value by 2 gives the integer ceiling of the (e.g. -5 / 2 == -2) whereas shifting right by 1 always gives the floor (-5 >> 1 == -3). An embedded board with a 25 Mhz base clock results in an error of -30.5% when used with a baud rate of 115200. Using division, this truncates to -30% and is permitted. Using the shift, this fails and is rejected causing TIOCSETA requests to fail with EINVAL and breaking getty(8). Using division gives the same error range for both over and under baud rates and also makes the code match the behavior documented in the existing comment about supporting boards with 25 Mhz clocks. Notes: svn path=/stable/12/; revision=365476
* MFC r352369: Relax TX draining in ns8250_bus_transmit().Alexander Motin2019-09-291-7/+2
| | | | | | | | | | | Since TX interrupt is generated when THRE is set, wait for TEMT set means wait for full character transmission time. At low speeds that may take awhile, burning CPU time while holding sc_hwmtx lock, also congested. This is partial revert of r317659. Notes: svn path=/stable/12/; revision=352861
* add snps IP uart support / genaralize UARTMatt Macy2018-08-191-0/+24
| | | | | | | | | | | | | | | | This is an amalgam of a patch by Doug Ambrisko to generalize uart_acpi_find_device, imp moving the ACPI table to uart_dev_ns8250.c and advice by jhb to work around a bug in the EPYC 3151 BIOS (the BIOS incorrectly marks the serial ports as disabled) Reviewed by: imp MFC after: 8 weeks Differential Revision: https://reviews.freebsd.org/D16432 Notes: svn path=/head/; revision=338074
* Add busy detect quirk to list of console optionsMatt Macy2018-07-221-0/+1
| | | | | | | | | | | | | | | | This change allows one to set the busy_detect flag required by the synopsys UART at the loader prompt. This is needed by the EPYC 3000 SoC. This will give users a working console up to the point where getty is required: hw.uart.console="mm:0xfedc9000,rs:2,bd:1" Reviewed by: imp MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D16399 Notes: svn path=/head/; revision=336623
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* uart: detect 256-byte FIFOsEd Maste2017-10-101-1/+4
| | | | | | | | Submitted by: Zakary Nafziger <worldofzak@gmail.com> Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=324503
* Make some UART consoles to not spin wait for data to be sent.Alexander Motin2017-05-011-6/+8
| | | | | | | | | | | At least with Tx FIFO enabled it shows me ~10% reduction of verbose boot time with serial console at 115200 baud. Reviewed by: marcel MFC after: 2 weeks Notes: svn path=/head/; revision=317659
* Add support for UART found in the Ingenic XBurst system on chips.Ruslan Bukin2016-11-171-6/+37
| | | | | | | | | | These CPUs has non-standard UART enable bit hidden in the UART FIFO Control Register. Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=308750
* sys/dev: minor spelling fixes.Pedro F. Giffuni2016-05-031-3/+3
| | | | | | | Most affect comments, very few have user-visible effects. Notes: svn path=/head/; revision=298955
* Move support for Synopsys Designware APB UART out of ns8250 and into aJared McNeill2016-04-011-12/+1
| | | | | | | | | | | | separate driver. Add support for activating clock and hwreset resources for these devices when the EXT_RESOURCES option is present. Reviewed by: andrew, mmel, Emmanuel Vadot <manu@bidouilliste.com> Approved by: adrian (mentor) Differential Revision: https://reviews.freebsd.org/D5749 Notes: svn path=/head/; revision=297496
* Add ns16550a compatible string in UART 8250 driverWojciech Macek2016-02-261-0/+1
| | | | | | | | | | | | Obtained from: Semihalf Submitted by: Michal Stanek <mst@semihalf.com> Sponsored by: Annapurna Labs Approved by: cognet (mentor) Reviewed by: imp, wma Differential revision: https://reviews.freebsd.org/D5404 Notes: svn path=/head/; revision=296082
* UART: Fix spurious interrupts generated by ns8250 and lpc drivers:Michal Meloun2016-02-121-2/+3
| | | | | | | | - don't enable transmitter empty interrupt before filling TX FIFO. - add missing uart_barrier() call in interrupt service routine Notes: svn path=/head/; revision=295557
* Fix busy-detect when using DesignWare UARTZbigniew Bodek2016-01-201-2/+5
| | | | | | | | | | | | | | | | uart_dev_ns8250 now relies on compatible property instead of additional 'busy-detect' cell. All drivers with compatible = "snps,dw-apb-uart" have busy detection turned on. DTS files of devices affected by the change were modified and 'busy-detect' property was removed. Reviewed by: andrew, ian, imp Obtained from: Semihalf Sponsored by: Stormshield Submitted by: Bartosz Szczepanek <bsz@semihalf.com> Differential revision: https://reviews.freebsd.org/D4218 Notes: svn path=/head/; revision=294424
* Add compatibility string for dw-apb-uart in ns8250 driverZbigniew Bodek2016-01-201-0/+1
| | | | | | | | | | | | | | This compatibility string is used in .dts file of Armada38x and isrequired for driver attachment. Reviewed by: andrew, ian, imp Obtained from: Semihalf Sponsored by: Stormshield Submitted by: Michal Stanek <mst@semihalf.com> Differential revision: https://reviews.freebsd.org/D4216 Notes: svn path=/head/; revision=294423
* Restore uart PPS signal capture polarity to its historical norm, and add anIan Lepore2016-01-121-16/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | option to invert the polarity in software. Also add an option to capture very narrow pulses by using the hardware's MSR delta-bit capability of latching line state changes. This effectively reverts the mistake I made in r286595 which was based on empirical measurements made on hardware using TTL-level signaling, in which the logic levels are inverted from RS-232. Thus, this re-syncs the polarity with the requirements of RFC 2783, which is writen in terms of RS-232 signaling. Narrow-pulse mode uses the ability of most ns8250 and similar chips to provide a delta indication in the modem status register. The hardware is able to notice and latch the change when the pulse width is shorter than interrupt latency, which results in the signal no longer being asserted by time the interrupt service code runs. When running in this mode we get notified only that "a pulse happened" so the driver synthesizes both an ASSERT and a CLEAR event (with the same timestamp for each). When the pulse width is about equal to the interrupt latency the driver may intermittantly see both edges of the pulse. To prevent generating spurious events, the driver implements a half-second lockout period after generating an event before it will generate another. Differential Revision: https://reviews.freebsd.org/D4477 Notes: svn path=/head/; revision=293781
* uart(4) - make the 8250 uart baudrate tolerance build time tweakable.Adrian Chadd2015-11-181-2/+13
| | | | | | | | | | | | | It turns out on a 16550 w/ a 25MHz SoC reference clock you get a little over 3% error at 115200 baud, which causes this to fail. Just .. cope. Things cope these days. Default to 30 (3.0%) as before, but allow UART_DEV_TOLERANCE_PCT to be set at build time to change that. Notes: svn path=/head/; revision=291010
* Actually check the DTS node value to enable the uart quirks.Luiz Otavio O Souza2015-05-301-4/+4
| | | | | | | | Without this fix, you cannot disable the quirks by setting it to 0, just the presence of the FDT node was enough to enable it. Notes: svn path=/head/; revision=283773
* Add support for the uart classes to set their default register shift value.Andrew Turner2015-04-111-1/+2
| | | | | | | | | | | | | | This is needed with the pl011 driver. Before this change it would default to a shift of 0, however the hardware places the registers at 4-byte addresses meaning the value should be 2. This patch fixes this for the pl011 when configured using the fdt. The other drivers have a default value of 0 to keep this a no-op. MFC after: 1 week Notes: svn path=/head/; revision=281438
* Move the uart_class definitions and fdt compat data into the individualIan Lepore2015-03-071-0/+11
| | | | | | | | | | uart implementations, and export them using the new linker-set mechanism. Differential Revision: https://reviews.freebsd.org/D1993 Submitted by: Michal Meloun Notes: svn path=/head/; revision=279724
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-2/+1
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-1/+2
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* In uart_bus_grab(), use the ier_mask instead of a custom hack for XScale.Olivier Houchard2014-05-291-5/+3
| | | | | | | Suggested by: jmg Notes: svn path=/head/; revision=266858
* In the grab function, keep the bit 6 on in the IER, on XScale, using 0Olivier Houchard2014-05-291-1/+6
| | | | | | | turns the UART off, which is unfortunate if one want to use it as a console. Notes: svn path=/head/; revision=266855
* Introduce grab and ungrab upcalls. When the kernel desires to grab theWarner Losh2014-01-191-0/+33
| | | | | | | | | | | | | | | console, it calls the grab functions. These functions should turn off the RX interrupts, and any others that interfere. This makes mountroot prompt work again. If there's more generalized need other than prompting, many of these routines should be expanded to do those new things. Should have been part of r260889, but waasn't due to command line typo. Reviewed by: bde (with reservations) Notes: svn path=/head/; revision=260890
* Wait for DesignWare UART transfers completion before accessing line controlZbigniew Bodek2013-10-261-1/+25
| | | | | | | | | | | | | | | | When using DW UART with BUSY detection it is necessary to wait until all serial transfers are finished before manipulating the line control. LCR will not be affected when UART is busy. In addition, if Divisor Latch Access Bit is being set in order to modify UART divisors: 1. We will get BUSY interrupt if interrupts are enabled. 2. Because LCR will not be affected the THR and (even worse) IER contents will be corrupted. This will lead to console hang. Approved by: cognet (mentor) Notes: svn path=/head/; revision=257170
* A final test with unmodified code has shown that a delay of 150msMarcel Moolenaar2013-08-301-1/+1
| | | | | | | | | | | | | | | | | is not giving us a 100% success rate. Bump the delay to 200ms as that seems to do the trick. Note that during testing the delay was added to uart_bus_attach() in uart_core.c. While having the delay in a different place can change the behaviour, it was not expected. Having to bump the delay with another 50ms could therefore be an indication that the problem can not be solved with delays. Reported by: kevlo@ Tested by: kevlo@ Notes: svn path=/head/; revision=255074
* Work-around a timing problem with the ITE IT8513E now that the coreMarcel Moolenaar2013-08-291-1/+13
| | | | | | | | | | | | | | calls ns8250_bus_ipend() almost immediately after ns8250_bus_attach(). As it appears, a line break condition is being signalled for almost all received characters due to this. A delay of 150ms seems enough to allow the H/W to settle and to avoid the problem. More analysis is needed, but for now a regression has been addressed. Reported by: kevlo@ Tested by: kevlo@ Notes: svn path=/head/; revision=255031
* Make the uart ns8250 high-level interface public rather than static.Ian Lepore2013-08-211-38/+13
| | | | | | | | | This makes it easier to implement new drivers which are "mostly ns8250" but with some small difference such as needing to enable clocks or poke a non-standard register at probe or attach time. Notes: svn path=/head/; revision=254597
* Add support for A10 uart.Ganbold Tsagaankhuu2013-03-011-5/+38
| | | | | | | | | | | | | | | A10 uart is derived from Synopsys DesignWare uart and requires to read Uart Status Register when IIR_BUSY has detected. Also this change includes FDT check, where it checks device specific properties defined in dts and sets the busy_detect variable. broken_txfifo is also needed to be set in order to make it work for A10 uart case. Reviewed by: marcel@ Approved by: gonzo@ Notes: svn path=/head/; revision=247519
* Add a loader tunable "hw.broken_txfifo" which enables a workaround for aColin Percival2013-01-271-1/+13
| | | | | | | | | | | | | bug in old versions of QEMU (and Xen, and other places using QEMU code). On those buggy emulated UARTs, the "TX idle" interrupt gets lost; with this workaround, we spinwait for the TX to happen and then send ourselves the interrupt. It's ugly but it works, while minimizing the impact on the code for the !broken_txfifo case. MFC after: 2 weeks Notes: svn path=/head/; revision=246016
* Disable the TX ready interrupts once we received one, some UART won't clearOlivier Houchard2011-11-021-2/+5
| | | | | | | | | the IIR_TXRDY bit upon reading. Reviewed by: marcel Notes: svn path=/head/; revision=227032
* Ignore MCR[6] during the probe to fix a false negative. Bit 6 of theMarcel Moolenaar2011-05-261-1/+7
| | | | | | | | | | | | | MCR register on the Sunix Sun1699 chip tends to be set but doesn't seem to have a function. That is, FreeBSD just works (provided the correct RCLK is used) regardless. PR: kern/129663 Diagnostics: Eygene Ryabinkin <rea-fbsd at codelabs.ru> MFC after: 3 days Notes: svn path=/head/; revision=222317
* Fix typos - remove duplicate "the".Rebecca Cran2011-02-211-1/+1
| | | | | | | | | PR: bin/154928 Submitted by: Eitan Adler <lists at eitanadler.com> MFC after: 3 days Notes: svn path=/head/; revision=218909
* Remove redundant checking of sc_leaving (uart_intr() already handles this).Marius Strobl2010-05-021-1/+1
| | | | | | | Approved by: marcel Notes: svn path=/head/; revision=207533
* Fix hangs caused by hardware that signals receive errorsMarcel Moolenaar2009-04-081-6/+9
| | | | | | | | | | | | (framing, parity, etc), but does not indicate characters being received. Since no chracters have been received, ignore the line errors. PR: 131006 MFC after: 3 days Notes: svn path=/head/; revision=190834
* The XScale PXA255 has three generally ns16x50 compatible UARTs. One of theBenno Rice2008-05-301-5/+31
| | | | | | | | | | | | | | | | | | variations from normal 16x50 behaviour however is the the use of a normally unused bit of IER to control RX timeout interrupts independently of the generally used RXRDY bit. If this bit is not enabled, we only ever get interrupts when the FIFO is full, never before. This is not very useful when the UART is being used as a console. In order to support this without causing potential problems on more "normal" 16x50 variants, this change introduces two hints for the uart device, ier_mask and ier_rxbits. These can be used to override which bits get set and cleared when we're enabling and disabling RX interrupts. Reviewed by: marcel Notes: svn path=/head/; revision=179420
* add device hints to control the rx FIFO interrupt level on 16550A partsSam Leffler2008-03-121-1/+14
| | | | | | | | | | PR: kern/121421 Submitted by: UEMURA Tetsuya Reviewed by: marcel MFC after: 2 weeks Notes: svn path=/head/; revision=177117
* Don't use a time-limiting loop that's defined in terms of the baudrateMarcel Moolenaar2007-04-031-13/+7
| | | | | | | | | | | | | | | | | | in the putc() method. Likewise, in the getc() method, don't check for received characters with an interval defined in terms of the baudrate. In both cases it works equally well to implement a fixed delay. More importantly, it avoids calculating a delay that's roughly 1/10th the time it takes to send/receive a character. The calculation is costly and happens for every character sent or received, affecting low-level console or debug port performance significantly. Secondly, when the RCLK is not available or unreliable, the delays could disrupt normal operation. The fixed delay is 1/10th the time it takes to send a character at 230400 bps. Notes: svn path=/head/; revision=168285
* Don't expose the uart_ops structure directly, but instead haveMarcel Moolenaar2007-04-021-2/+3
| | | | | | | | | | | | | | | it obtained through the uart_class structure. This allows us to declare the uart_class structure as weak and as such allows us to reference it even when it's not compiled-in. It also allows is to get the uart_ops structure by name, which makes it possible to implement the dt tag handling in uart_getenv(). The side-effect of all this is that we're using the uart_class structure more consistently which means that we now also have access to the size of the bus space block needed by the hardware when we map the bus space, eliminating any hardcoding. Notes: svn path=/head/; revision=168281
* For embedded UARTs compatible with the ns8250 family it is possibleMarcel Moolenaar2007-03-281-1/+3
| | | | | | | | | | | | that the driver clock is identical to the processor or bus clock. This is the case for the PowerQUICC processor. When the clock is high enough, overflows happen in the calculation of the time it takes to send 1/10 of a character, used in delay loops. Fix the overflows so as to fix bugs in the delay loops that can cause either insufficient delays or excessive delays. Notes: svn path=/head/; revision=168000
* - Add a uart_rxready() and corresponding device-specific implementationsMarius Strobl2007-01-181-6/+4
| | | | | | | | | | | | | | | | | | that can be used to check whether receive data is ready, i.e. whether the subsequent call of uart_poll() should return a char, and unlike uart_poll() doesn't actually receive data. - Remove the device-specific implementations of uart_poll() and implement uart_poll() in terms of uart_getc() and the newly added uart_rxready() in order to minimize code duplication. - In sunkbd(4) take advantage of uart_rxready() and use it to implement the polled mode part of sunkbd_check() so we don't need to buffer a potentially read char in the softc. - Fix some mis-indentation in sunkbd_read_char(). Discussed with: marcel Notes: svn path=/head/; revision=166100
* The lcr variable in ns8250_probe is now unused. Remove it.Benno Rice2006-05-231-1/+1
| | | | | | | Missed by: benno Notes: svn path=/head/; revision=158849
* Allow uart(4)'s ns8250 driver to work with devices whose regshift is > 0.Benno Rice2006-05-231-24/+16
| | | | | | | | | | | | | | | | - Rename REG_DL to REG_DLL and REG_DLH. - Always treat DLL and DLH as two separate 8-bit registers instead of one 16-bit register. Additionally, remove the probe for the high 4 bits of IER being 0 and don't assume we can always read/write 0 to/from those bits. These changes allow uart(4) to drive the UARTs on the Intel XScale PXA255. Reviewed by: marcel Notes: svn path=/head/; revision=158844
* Use 115200 and not 9600 as the initial baudrate. This speeds upMarcel Moolenaar2006-04-271-1/+1
| | | | | | | detection of the FIFO size. Especially for large FIFOs. Notes: svn path=/head/; revision=158069
* MFp4: Calculate the divisor before setting the DLAB bit. ThisMarcel Moolenaar2006-04-231-2/+2
| | | | | | | | prevents that there's a control flow that leaves the DLAB bit set. Notes: svn path=/head/; revision=157989
* Eliminate the sc_hasfifo flag from the softc. It was only used byMarcel Moolenaar2006-04-021-3/+3
| | | | | | | | | | the NS8250 class driver. The UART has FIFOs if sc_rxfifosz>1, so test for that instead. While here properly initialize sc_rxfifosz and sc_txfifosz in the case the UART doesn't have FIFOs. Notes: svn path=/head/; revision=157418
* Don't hold the hardware mutex across getc(). It can wait indefinitelyMarcel Moolenaar2006-04-011-5/+15
| | | | | | | | for a character to be received. Instead let getc() do any necesary locking. Notes: svn path=/head/; revision=157380
* Add support for scc(4).Marcel Moolenaar2006-03-301-18/+18
| | | | Notes: svn path=/head/; revision=157300
* Replace our local UART_SIGMASK_* with the global SER_MASK_*.Marcel Moolenaar2006-02-241-1/+1
| | | | Notes: svn path=/head/; revision=155973