iPXE
dwuart.c File Reference

DesignWare UART. More...

#include <errno.h>
#include <ipxe/uart.h>
#include <ipxe/ns16550.h>
#include <ipxe/devtree.h>
#include <ipxe/fdt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int dwuart_probe (struct dt_device *dt, unsigned int offset)
 Probe devicetree device.
static void dwuart_remove (struct dt_device *dt)
 Remove devicetree device.

Variables

static const char * dwuart_ids []
 DesignWare UART compatible model identifiers.
struct dt_driver dwuart_driver __dt_driver
 DesignWare UART devicetree driver.

Detailed Description

DesignWare UART.

Definition in file dwuart.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ dwuart_probe()

int dwuart_probe ( struct dt_device * dt,
unsigned int offset )
static

Probe devicetree device.

Parameters
dtDevicetree device
offsetStarting node offset
Return values
rcReturn status code

Definition at line 45 of file dwuart.c.

45 {
46 struct ns16550_uart *ns16550;
47 struct uart *uart;
48 uint32_t shift;
49 uint32_t clock;
50 int rc;
51
52 /* Allocate and initialise UART */
53 uart = alloc_uart ( sizeof ( *ns16550 ) );
54 if ( ! uart ) {
55 rc = -ENOMEM;
56 goto err_alloc;
57 }
58 uart->name = dt->name;
60 ns16550 = uart->priv;
61 dt_set_drvdata ( dt, uart );
62
63 /* Map registers */
64 ns16550->base = dt_ioremap ( dt, offset, 0, 0 );
65 if ( ! ns16550->base ) {
66 rc = -ENODEV;
67 goto err_ioremap;
68 }
69
70 /* Get register shift */
71 if ( ( rc = fdt_u32 ( &sysfdt, offset, "reg-shift", &shift ) ) != 0 )
72 shift = 0;
73 ns16550->shift = shift;
74
75 /* Get clock rate */
76 if ( ( rc = fdt_u32 ( &sysfdt, offset, "clock-frequency",
77 &clock ) ) != 0 ) {
78 clock = NS16550_CLK_DEFAULT;
79 }
80 ns16550->clock = clock;
81
82 /* Register UART */
83 if ( ( rc = uart_register ( uart ) ) != 0 )
84 goto err_register;
85
86 return 0;
87
89 err_register:
90 iounmap ( ns16550->base );
91 err_ioremap:
92 uart_nullify ( uart );
93 uart_put ( uart );
94 err_alloc:
95 return rc;
96}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned int uint32_t
Definition stdint.h:12
uint16_t offset
Offset to command line.
Definition bzimage.h:3
void * dt_ioremap(struct dt_device *dt, unsigned int offset, unsigned int index, size_t len)
Map devicetree range.
Definition devtree.c:52
static void dt_set_drvdata(struct dt_device *dt, void *priv)
Set devicetree driver-private data.
Definition devtree.h:72
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition fdt.c:664
struct fdt sysfdt
The system flattened device tree (if present)
Definition fdt.c:45
#define ENOMEM
Not enough space.
Definition errno.h:535
#define ENODEV
No such device.
Definition errno.h:510
void iounmap(volatile const void *io_addr)
Unmap I/O address.
#define NS16550_CLK_DEFAULT
Default input clock rate (1.8432 MHz)
Definition ns16550.h:95
struct uart_operations ns16550_operations
16550 UART operations
Definition ns16550.c:171
const char * name
Device name.
Definition devtree.h:19
A 16550-compatible UART.
Definition ns16550.h:80
unsigned int clock
Input clock frequency.
Definition ns16550.h:86
unsigned int shift
Register shift.
Definition ns16550.h:84
void * base
Register base address.
Definition ns16550.h:82
A generic UART.
Definition uart.h:17
const char * name
Name.
Definition uart.h:21
struct uart_operations * op
UART operations.
Definition uart.h:29
void * priv
Driver-private data.
Definition uart.h:31
void uart_unregister(struct uart *uart)
Unregister UART.
Definition uart.c:117
struct uart * alloc_uart(size_t priv_len)
Allocate UART.
Definition uart.c:74
int uart_register(struct uart *uart)
Register UART.
Definition uart.c:102

References alloc_uart(), ns16550_uart::base, ns16550_uart::clock, dt_ioremap(), dt_set_drvdata(), ENODEV, ENOMEM, fdt_u32(), iounmap(), dt_device::name, uart::name, NS16550_CLK_DEFAULT, ns16550_operations, offset, uart::op, uart::priv, rc, ns16550_uart::shift, sysfdt, uart_register(), and uart_unregister().

◆ dwuart_remove()

void dwuart_remove ( struct dt_device * dt)
static

Remove devicetree device.

Parameters
dtDevicetree device

Definition at line 103 of file dwuart.c.

103 {
104 struct uart *uart = dt_get_drvdata ( dt );
105 struct ns16550_uart *ns16550 = uart->priv;
106
107 /* Unregister UART */
109
110 /* Free UART */
111 iounmap ( ns16550->base );
112 uart_nullify ( uart );
113 uart_put ( uart );
114}
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition devtree.h:82

References ns16550_uart::base, dt_get_drvdata(), iounmap(), uart::priv, and uart_unregister().

Variable Documentation

◆ dwuart_ids

const char* dwuart_ids[]
static
Initial value:
= {
DT_ID ( "snps,dw-apb-uart", "DesignWare UART" ),
DT_ID ( "ns16550a", "NS16550-compatible" ),
}
#define DT_ID(_name, _desc)
Definition devtree.h:31

DesignWare UART compatible model identifiers.

Definition at line 117 of file dwuart.c.

117 {
118 DT_ID ( "snps,dw-apb-uart", "DesignWare UART" ),
119 DT_ID ( "ns16550a", "NS16550-compatible" ),
120};

◆ __dt_driver

struct dt_driver dwuart_driver __dt_driver
Initial value:
= {
.name = "dwuart",
.ids = dwuart_ids,
.id_count = ( sizeof ( dwuart_ids ) / sizeof ( dwuart_ids[0] ) ),
.probe = dwuart_probe,
}
static void dwuart_remove(struct dt_device *dt)
Remove devicetree device.
Definition dwuart.c:103
static const char * dwuart_ids[]
DesignWare UART compatible model identifiers.
Definition dwuart.c:117
static int dwuart_probe(struct dt_device *dt, unsigned int offset)
Probe devicetree device.
Definition dwuart.c:45
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40

DesignWare UART devicetree driver.

Definition at line 123 of file dwuart.c.

123 {
124 .name = "dwuart",
125 .ids = dwuart_ids,
126 .id_count = ( sizeof ( dwuart_ids ) / sizeof ( dwuart_ids[0] ) ),
127 .probe = dwuart_probe,
129};