mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-03 16:18:51 -04:00
Use and adapt the UART driver from hekate/hwinit
This commit is contained in:
parent
a409016a88
commit
ff9322a468
4 changed files with 99 additions and 49 deletions
|
@ -5,25 +5,56 @@
|
|||
#include "memory_map.h"
|
||||
|
||||
/* Exosphere driver for the Tegra X1 UARTs. */
|
||||
/* Mostly copied from https://github.com/nwert/hekate/blob/master/hwinit/uart.h and https://github.com/nwert/hekate/blob/master/hwinit/uart.c */
|
||||
|
||||
/* TODO: Should we bother with support UARTB-D? */
|
||||
|
||||
static inline uintptr_t get_uarta_base(void) {
|
||||
return MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_UART_A);
|
||||
static inline uintptr_t get_uart_base(void) {
|
||||
return MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_UART);
|
||||
}
|
||||
|
||||
#define UARTA_BASE (get_uarta_base())
|
||||
#define UART_BASE (get_uart_base())
|
||||
|
||||
#define UART_THR_DLAB_0_0 MAKE_REG32(UARTA_BASE + 0x0)
|
||||
#define UART_IER_DLAB_0_0 MAKE_REG32(UARTA_BASE + 0x4)
|
||||
#define UART_IIR_FCR_0 MAKE_REG32(UARTA_BASE+ 0x8)
|
||||
#define UART_LCR_0 MAKE_REG32(UARTA_BASE + 0xC)
|
||||
#define UART_LSR_0 MAKE_REG32(UARTA_BASE + 0x14)
|
||||
/* Exosphère: add the clkreset values for UART C,D,E */
|
||||
typedef enum {
|
||||
UART_A = 0,
|
||||
UART_B = 1,
|
||||
UART_C = 2,
|
||||
UART_D = 3,
|
||||
UART_E = 4,
|
||||
} UartDevice;
|
||||
|
||||
void uart_select(unsigned int id);
|
||||
void uart_initialize(uint16_t divider);
|
||||
void uart_transmit_char(char ch);
|
||||
void uart_transmit_str(const char *str);
|
||||
void uart_transmit_hex(uint32_t value);
|
||||
#define BAUD_115200 115200
|
||||
|
||||
#define UART_TX_IDLE 0x00000001
|
||||
#define UART_RX_IDLE 0x00000002
|
||||
#define UART_TX_FIFO_FULL 0x100
|
||||
#define UART_RX_FIFO_EMPTY 0x200
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ uint32_t UART_THR_DLAB;
|
||||
/* 0x04 */ uint32_t UART_IER_DLAB;
|
||||
/* 0x08 */ uint32_t UART_IIR_FCR;
|
||||
/* 0x0C */ uint32_t UART_LCR;
|
||||
/* 0x10 */ uint32_t UART_MCR;
|
||||
/* 0x14 */ uint32_t UART_LSR;
|
||||
/* 0x18 */ uint32_t UART_MSR;
|
||||
/* 0x1C */ uint32_t UART_SPR;
|
||||
/* 0x20 */ uint32_t UART_IRDA_CSR;
|
||||
/* 0x24 */ uint32_t UART_RX_FIFO_CFG;
|
||||
/* 0x28 */ uint32_t UART_MIE;
|
||||
/* 0x2C */ uint32_t UART_VENDOR_STATUS;
|
||||
/* 0x30 */ uint8_t _pad_30[0x0C];
|
||||
/* 0x3C */ uint32_t UART_ASR;
|
||||
} uart_t;
|
||||
|
||||
void uart_select(UartDevice dev);
|
||||
void uart_init(UartDevice dev, uint32_t baud);
|
||||
void uart_wait_idle(UartDevice dev, uint32_t which);
|
||||
void uart_send(UartDevice dev, const void *buf, size_t len);
|
||||
void uart_recv(UartDevice dev, void *buf, size_t len);
|
||||
|
||||
static inline volatile uart_t *get_uart_device(UartDevice dev) {
|
||||
static const size_t offsets[] = {0, 0x40, 0x200, 0x300, 0x400};
|
||||
return (volatile uart_t *)(UART_BASE + offsets[dev]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue