#include <linux/serial_core.h>
#include <linux/tty_flip.h>
#include <linux/types.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
#define SERIAL_NAME "ttyMPS"
#define DRIVER_NAME "mps2-uart"
.verify_port = mps2_uart_verify_port,
};
-static DEFINE_IDR(ports_idr);
+static DEFINE_XARRAY_ALLOC(ports);
#ifdef CONFIG_SERIAL_MPS2_UART_CONSOLE
static void mps2_uart_console_putchar(struct uart_port *port, int ch)
static void mps2_uart_console_write(struct console *co, const char *s, unsigned int cnt)
{
- struct mps2_uart_port *mps_port = idr_find(&ports_idr, co->index);
+ struct mps2_uart_port *mps_port = xa_load(&ports, co->index);
struct uart_port *port = &mps_port->port;
uart_console_write(port, s, cnt, mps2_uart_console_putchar);
if (co->index < 0 || co->index >= MPS2_MAX_PORTS)
return -ENODEV;
- mps_port = idr_find(&ports_idr, co->index);
+ mps_port = xa_load(&ports, co->index);
if (!mps_port)
return -ENODEV;
struct mps2_uart_port *mps_port)
{
struct device_node *np = pdev->dev.of_node;
- int id;
+ int id, err;
if (!np)
return -ENODEV;
id = of_alias_get_id(np, "serial");
- if (id < 0)
- id = idr_alloc_cyclic(&ports_idr, (void *)mps_port, 0, MPS2_MAX_PORTS, GFP_KERNEL);
- else
- id = idr_alloc(&ports_idr, (void *)mps_port, id, MPS2_MAX_PORTS, GFP_KERNEL);
+ if (id < 0) {
+ err = xa_alloc(&ports, &mps_port->port.line, mps_port,
+ XA_LIMIT(0, MPS2_MAX_PORTS - 1), GFP_KERNEL);
+ } else {
+ mps_port->port.line = id;
+ err = xa_insert(&ports, id, mps_port, GFP_KERNEL);
+ }
- if (id < 0)
- return id;
+ if (err < 0)
+ return err;
/* Only combined irq is presesnt */
if (platform_irq_count(pdev) == 1)
mps_port->flags |= UART_PORT_COMBINED_IRQ;
- mps_port->port.line = id;
-
return 0;
}