Files
linux/drivers/tty/serial/8250/8250_rsa.c
Linus Torvalds edf602a17b Merge tag 'tty-6.19-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 changes for 6.19-rc1. Nothing
  major at all, just small constant churn to make the tty layer
  "cleaner" as well as serial driver updates and even a new test added!
  Included in here are:

   - More tty/serial cleanups from Jiri

   - tty tiocsti test added to hopefully ensure we don't regress in this
     area again

   - sc16is7xx driver updates

   - imx serial driver updates

   - 8250 driver updates

   - new hardware device ids added

   - other minor serial/tty driver cleanups and tweaks

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

* tag 'tty-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (60 commits)
  serial: sh-sci: Fix deadlock during RSCI FIFO overrun error
  dt-bindings: serial: rsci: Drop "uart-has-rtscts: false"
  LoongArch: dts: Add uart new compatible string
  serial: 8250: Add Loongson uart driver support
  dt-bindings: serial: 8250: Add Loongson uart compatible
  serial: 8250: add driver for KEBA UART
  serial: Keep rs485 settings for devices without firmware node
  serial: qcom-geni: Enable Serial on SA8255p Qualcomm platforms
  serial: qcom-geni: Enable PM runtime for serial driver
  serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
  tty: serial: samsung: Declare earlycon for Exynos850
  serial: icom: Convert PCIBIOS_* return codes to errnos
  serial: 8250-of: Fix style issues in 8250_of.c
  serial: add support of CPCI cards
  serial: mux: Fix kernel doc for mux_poll()
  tty: replace use of system_unbound_wq with system_dfl_wq
  serial: 8250_platform: simplify IRQF_SHARED handling
  serial: 8250: make share_irqs local to 8250_platform
  serial: 8250: move skip_txen_test to core
  serial: drop SERIAL_8250_DEPRECATED_OPTIONS
  ...
2025-12-06 18:38:19 -08:00

212 lines
5.1 KiB
C

// SPDX-License-Identifier: GPL-2.0+
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/serial.h>
#include <linux/serial_8250.h>
#include "8250.h"
#define PORT_RSA_MAX 4
static unsigned long probe_rsa[PORT_RSA_MAX];
static unsigned int probe_rsa_count;
static const struct uart_ops *core_port_base_ops;
static int rsa8250_request_resource(struct uart_8250_port *up)
{
struct uart_port *port = &up->port;
unsigned long start = UART_RSA_BASE << port->regshift;
unsigned int size = 8 << port->regshift;
switch (port->iotype) {
case UPIO_HUB6:
case UPIO_PORT:
start += port->iobase;
if (!request_region(start, size, "serial-rsa"))
return -EBUSY;
return 0;
default:
return -EINVAL;
}
}
static void rsa8250_release_resource(struct uart_8250_port *up)
{
struct uart_port *port = &up->port;
unsigned long offset = UART_RSA_BASE << port->regshift;
unsigned int size = 8 << port->regshift;
switch (port->iotype) {
case UPIO_HUB6:
case UPIO_PORT:
release_region(port->iobase + offset, size);
break;
default:
break;
}
}
static void univ8250_config_port(struct uart_port *port, int flags)
{
struct uart_8250_port *up = up_to_u8250p(port);
unsigned int i;
up->probe &= ~UART_PROBE_RSA;
if (port->type == PORT_RSA) {
if (rsa8250_request_resource(up) == 0)
up->probe |= UART_PROBE_RSA;
} else if (flags & UART_CONFIG_TYPE) {
for (i = 0; i < probe_rsa_count; i++) {
if (probe_rsa[i] == up->port.iobase) {
if (rsa8250_request_resource(up) == 0)
up->probe |= UART_PROBE_RSA;
break;
}
}
}
core_port_base_ops->config_port(port, flags);
if (port->type != PORT_RSA && up->probe & UART_PROBE_RSA)
rsa8250_release_resource(up);
}
static int univ8250_request_port(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
int ret;
ret = core_port_base_ops->request_port(port);
if (ret == 0 && port->type == PORT_RSA) {
ret = rsa8250_request_resource(up);
if (ret < 0)
core_port_base_ops->release_port(port);
}
return ret;
}
static void univ8250_release_port(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
if (port->type == PORT_RSA)
rsa8250_release_resource(up);
core_port_base_ops->release_port(port);
}
/*
* It is not allowed to directly reference any symbols from 8250.ko here as
* that would result in a dependency loop between the 8250.ko and
* 8250_base.ko modules. This function is called from 8250.ko and is used to
* break the symbolic dependency cycle. Anything that is needed from 8250.ko
* has to be passed as pointers to this function which then can adjust those
* variables on 8250.ko side or store them locally as needed.
*/
void univ8250_rsa_support(struct uart_ops *ops, const struct uart_ops *core_ops)
{
core_port_base_ops = core_ops;
ops->config_port = univ8250_config_port;
ops->request_port = univ8250_request_port;
ops->release_port = univ8250_release_port;
}
EXPORT_SYMBOL_FOR_MODULES(univ8250_rsa_support, "8250");
module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444);
MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
/*
* Attempts to turn on the RSA FIFO. Returns zero on failure.
* We set the port uart clock rate if we succeed.
*/
static int __rsa_enable(struct uart_8250_port *up)
{
unsigned char mode;
int result;
mode = serial_in(up, UART_RSA_MSR);
result = mode & UART_RSA_MSR_FIFO;
if (!result) {
serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
mode = serial_in(up, UART_RSA_MSR);
result = mode & UART_RSA_MSR_FIFO;
}
if (result)
up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
return result;
}
/*
* If this is an RSA port, see if we can kick it up to the higher speed clock.
*/
void rsa_enable(struct uart_8250_port *up)
{
if (up->port.type != PORT_RSA)
return;
if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
guard(uart_port_lock_irq)(&up->port);
__rsa_enable(up);
}
if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
serial_out(up, UART_RSA_FRR, 0);
}
/*
* Attempts to turn off the RSA FIFO and resets the RSA board back to 115kbps compat mode. It is
* unknown why interrupts were disabled in here. However, the caller is expected to preserve this
* behaviour by grabbing the spinlock before calling this function.
*/
void rsa_disable(struct uart_8250_port *up)
{
unsigned char mode;
int result;
if (up->port.type != PORT_RSA)
return;
if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
return;
guard(uart_port_lock_irq)(&up->port);
mode = serial_in(up, UART_RSA_MSR);
result = !(mode & UART_RSA_MSR_FIFO);
if (!result) {
serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
mode = serial_in(up, UART_RSA_MSR);
result = !(mode & UART_RSA_MSR_FIFO);
}
if (result)
up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
}
void rsa_autoconfig(struct uart_8250_port *up)
{
/* Only probe for RSA ports if we got the region. */
if (up->port.type != PORT_16550A)
return;
if (!(up->probe & UART_PROBE_RSA))
return;
if (__rsa_enable(up))
up->port.type = PORT_RSA;
}
void rsa_reset(struct uart_8250_port *up)
{
if (up->port.type != PORT_RSA)
return;
serial_out(up, UART_RSA_FRR, 0);
}