Blame view
drivers/serial/serial_xuartlite.c
3.27 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
507bbe3e8 * Patch by Yasush... |
2 |
/* |
93768393d serial: uartlite:... |
3 |
* (C) Copyright 2008 - 2015 Michal Simek <monstr@monstr.eu> |
53ea981c3 microblaze: Clean... |
4 |
* Clean driver and add xilinx constant from header file |
507bbe3e8 * Patch by Yasush... |
5 |
* |
53ea981c3 microblaze: Clean... |
6 |
* (C) Copyright 2004 Atmark Techno, Inc. |
507bbe3e8 * Patch by Yasush... |
7 |
* Yasushi SHOJI <yashi@atmark-techno.com> |
507bbe3e8 * Patch by Yasush... |
8 9 10 |
*/ #include <config.h> |
49a23e4a4 serial: uartlite:... |
11 |
#include <common.h> |
93768393d serial: uartlite:... |
12 |
#include <dm.h> |
53ea981c3 microblaze: Clean... |
13 |
#include <asm/io.h> |
49a23e4a4 serial: uartlite:... |
14 15 |
#include <linux/compiler.h> #include <serial.h> |
507bbe3e8 * Patch by Yasush... |
16 |
|
93768393d serial: uartlite:... |
17 18 19 20 |
#define SR_TX_FIFO_FULL BIT(3) /* transmit FIFO full */ #define SR_TX_FIFO_EMPTY BIT(2) /* transmit FIFO empty */ #define SR_RX_FIFO_VALID_DATA BIT(0) /* data in receive FIFO */ #define SR_RX_FIFO_FULL BIT(1) /* receive FIFO full */ |
507bbe3e8 * Patch by Yasush... |
21 |
|
8c3bd6b59 serial: uartlite:... |
22 23 |
#define ULITE_CONTROL_RST_TX 0x01 #define ULITE_CONTROL_RST_RX 0x02 |
49a23e4a4 serial: uartlite:... |
24 25 26 27 |
struct uartlite { unsigned int rx_fifo; unsigned int tx_fifo; unsigned int status; |
8c3bd6b59 serial: uartlite:... |
28 |
unsigned int control; |
49a23e4a4 serial: uartlite:... |
29 |
}; |
93768393d serial: uartlite:... |
30 31 |
struct uartlite_platdata { struct uartlite *regs; |
49a23e4a4 serial: uartlite:... |
32 |
}; |
93768393d serial: uartlite:... |
33 |
static int uartlite_serial_putc(struct udevice *dev, const char ch) |
49a23e4a4 serial: uartlite:... |
34 |
{ |
93768393d serial: uartlite:... |
35 36 |
struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; |
49a23e4a4 serial: uartlite:... |
37 |
|
93768393d serial: uartlite:... |
38 39 |
if (in_be32(®s->status) & SR_TX_FIFO_FULL) return -EAGAIN; |
49a23e4a4 serial: uartlite:... |
40 |
|
93768393d serial: uartlite:... |
41 |
out_be32(®s->tx_fifo, ch & 0xff); |
49a23e4a4 serial: uartlite:... |
42 |
|
93768393d serial: uartlite:... |
43 |
return 0; |
49a23e4a4 serial: uartlite:... |
44 |
} |
93768393d serial: uartlite:... |
45 |
static int uartlite_serial_getc(struct udevice *dev) |
49a23e4a4 serial: uartlite:... |
46 |
{ |
93768393d serial: uartlite:... |
47 48 49 50 51 |
struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; if (!(in_be32(®s->status) & SR_RX_FIFO_VALID_DATA)) return -EAGAIN; |
49a23e4a4 serial: uartlite:... |
52 |
|
49a23e4a4 serial: uartlite:... |
53 54 |
return in_be32(®s->rx_fifo) & 0xff; } |
93768393d serial: uartlite:... |
55 |
static int uartlite_serial_pending(struct udevice *dev, bool input) |
49a23e4a4 serial: uartlite:... |
56 |
{ |
93768393d serial: uartlite:... |
57 58 |
struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; |
507bbe3e8 * Patch by Yasush... |
59 |
|
93768393d serial: uartlite:... |
60 61 62 63 |
if (input) return in_be32(®s->status) & SR_RX_FIFO_VALID_DATA; return !(in_be32(®s->status) & SR_TX_FIFO_EMPTY); |
49a23e4a4 serial: uartlite:... |
64 |
} |
93768393d serial: uartlite:... |
65 |
static int uartlite_serial_probe(struct udevice *dev) |
25239e12d serial: uartlite:... |
66 |
{ |
93768393d serial: uartlite:... |
67 68 |
struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; |
8c3bd6b59 serial: uartlite:... |
69 |
|
93768393d serial: uartlite:... |
70 71 72 |
out_be32(®s->control, 0); out_be32(®s->control, ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX); in_be32(®s->control); |
25239e12d serial: uartlite:... |
73 |
|
93768393d serial: uartlite:... |
74 |
return 0; |
90bad891e serial: Properly ... |
75 |
} |
49a23e4a4 serial: uartlite:... |
76 |
|
93768393d serial: uartlite:... |
77 |
static int uartlite_serial_ofdata_to_platdata(struct udevice *dev) |
49a23e4a4 serial: uartlite:... |
78 |
{ |
93768393d serial: uartlite:... |
79 |
struct uartlite_platdata *plat = dev_get_platdata(dev); |
87d692295 serial: microblaz... |
80 |
|
a821c4af7 dm: Rename dev_ad... |
81 |
plat->regs = (struct uartlite *)devfdt_get_addr(dev); |
93768393d serial: uartlite:... |
82 83 |
return 0; |
87d692295 serial: microblaz... |
84 |
} |
93768393d serial: uartlite:... |
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
static const struct dm_serial_ops uartlite_serial_ops = { .putc = uartlite_serial_putc, .pending = uartlite_serial_pending, .getc = uartlite_serial_getc, }; static const struct udevice_id uartlite_serial_ids[] = { { .compatible = "xlnx,opb-uartlite-1.00.b", }, { .compatible = "xlnx,xps-uartlite-1.00.a" }, { } }; U_BOOT_DRIVER(serial_uartlite) = { .name = "serial_uartlite", .id = UCLASS_SERIAL, .of_match = uartlite_serial_ids, .ofdata_to_platdata = uartlite_serial_ofdata_to_platdata, .platdata_auto_alloc_size = sizeof(struct uartlite_platdata), .probe = uartlite_serial_probe, .ops = &uartlite_serial_ops, |
93768393d serial: uartlite:... |
106 |
}; |
4166ba3b2 serial: uartlite:... |
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#ifdef CONFIG_DEBUG_UART_UARTLITE #include <debug_uart.h> static inline void _debug_uart_init(void) { struct uartlite *regs = (struct uartlite *)CONFIG_DEBUG_UART_BASE; out_be32(®s->control, 0); out_be32(®s->control, ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX); in_be32(®s->control); } static inline void _debug_uart_putc(int ch) { struct uartlite *regs = (struct uartlite *)CONFIG_DEBUG_UART_BASE; while (in_be32(®s->status) & SR_TX_FIFO_FULL) ; out_be32(®s->tx_fifo, ch & 0xff); } DEBUG_UART_FUNCS #endif |