iPXE
Functions | Variables
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. More...
 
static void dwuart_remove (struct dt_device *dt)
 Remove devicetree device. More...
 

Variables

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

Detailed Description

DesignWare UART.

Definition in file dwuart.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dwuart_probe()

static 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:14
A generic UART.
Definition: uart.h:17
void * base
Register base address.
Definition: ns16550.h:82
unsigned int shift
Register shift.
Definition: ns16550.h:84
int uart_register(struct uart *uart)
Register UART.
Definition: uart.c:102
const char * name
Name.
Definition: uart.h:21
#define NS16550_CLK_DEFAULT
Default input clock rate (1.8432 MHz)
Definition: ns16550.h:95
#define ENOMEM
Not enough space.
Definition: errno.h:534
int fdt_u32(struct fdt *fdt, unsigned int offset, const char *name, uint32_t *value)
Get 32-bit integer property.
Definition: fdt.c:663
unsigned int clock
Input clock frequency.
Definition: ns16550.h:86
static void dt_set_drvdata(struct dt_device *dt, void *priv)
Set devicetree driver-private data.
Definition: devtree.h:66
void * priv
Driver-private data.
Definition: uart.h:31
A 16550-compatible UART.
Definition: ns16550.h:80
#define ENODEV
No such device.
Definition: errno.h:509
struct uart_operations ns16550_operations
16550 UART operations
Definition: ns16550.c:171
unsigned int uint32_t
Definition: stdint.h:12
const char * name
Device name.
Definition: devtree.h:19
void * dt_ioremap(struct dt_device *dt, unsigned int offset, unsigned int index, size_t len)
Map devicetree range.
Definition: devtree.c:52
struct uart_operations * op
UART operations.
Definition: uart.h:29
void iounmap(volatile const void *io_addr)
Unmap I/O address.
struct uart * alloc_uart(size_t priv_len)
Allocate UART.
Definition: uart.c:74
void uart_unregister(struct uart *uart)
Unregister UART.
Definition: uart.c:117
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44

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()

static 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 */
108  uart_unregister ( uart );
109 
110  /* Free UART */
111  iounmap ( ns16550->base );
112  uart_nullify ( uart );
113  uart_put ( uart );
114 }
A generic UART.
Definition: uart.h:17
void * base
Register base address.
Definition: ns16550.h:82
void * priv
Driver-private data.
Definition: uart.h:31
A 16550-compatible UART.
Definition: ns16550.h:80
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void uart_unregister(struct uart *uart)
Unregister UART.
Definition: uart.c:117
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition: devtree.h:76

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

Variable Documentation

◆ dwuart_ids

const char* dwuart_ids[]
static
Initial value:
= {
"snps,dw-apb-uart",
"ns16550a",
}

DesignWare UART compatible model identifiers.

Definition at line 117 of file dwuart.c.

◆ __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 struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
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

DesignWare UART devicetree driver.

Definition at line 123 of file dwuart.c.