#define ULITE_CONTROL_RST_TX 0x01
#define ULITE_CONTROL_RST_RX 0x02
+static bool little_endian;
+
struct uartlite {
unsigned int rx_fifo;
unsigned int tx_fifo;
struct uartlite *regs;
};
+static u32 uart_in32(void __iomem *addr)
+{
+ if (little_endian)
+ return in_le32(addr);
+ else
+ return in_be32(addr);
+}
+
+static void uart_out32(void __iomem *addr, u32 val)
+{
+ if (little_endian)
+ out_le32(addr, val);
+ else
+ out_be32(addr, val);
+}
+
static int uartlite_serial_putc(struct udevice *dev, const char ch)
{
struct uartlite_platdata *plat = dev_get_platdata(dev);
struct uartlite *regs = plat->regs;
- if (in_be32(®s->status) & SR_TX_FIFO_FULL)
+ if (uart_in32(®s->status) & SR_TX_FIFO_FULL)
return -EAGAIN;
- out_be32(®s->tx_fifo, ch & 0xff);
+ uart_out32(®s->tx_fifo, ch & 0xff);
return 0;
}
struct uartlite_platdata *plat = dev_get_platdata(dev);
struct uartlite *regs = plat->regs;
- if (!(in_be32(®s->status) & SR_RX_FIFO_VALID_DATA))
+ if (!(uart_in32(®s->status) & SR_RX_FIFO_VALID_DATA))
return -EAGAIN;
- return in_be32(®s->rx_fifo) & 0xff;
+ return uart_in32(®s->rx_fifo) & 0xff;
}
static int uartlite_serial_pending(struct udevice *dev, bool input)
struct uartlite *regs = plat->regs;
if (input)
- return in_be32(®s->status) & SR_RX_FIFO_VALID_DATA;
+ return uart_in32(®s->status) & SR_RX_FIFO_VALID_DATA;
- return !(in_be32(®s->status) & SR_TX_FIFO_EMPTY);
+ return !(uart_in32(®s->status) & SR_TX_FIFO_EMPTY);
}
static int uartlite_serial_probe(struct udevice *dev)
{
struct uartlite_platdata *plat = dev_get_platdata(dev);
struct uartlite *regs = plat->regs;
-
- out_be32(®s->control, 0);
- out_be32(®s->control, ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX);
- in_be32(®s->control);
+ int ret;
+
+ uart_out32(®s->control, 0);
+ uart_out32(®s->control, ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX);
+ ret = uart_in32(®s->status);
+ /* Endianness detection */
+ if ((ret & SR_TX_FIFO_EMPTY) != SR_TX_FIFO_EMPTY) {
+ little_endian = true;
+ uart_out32(®s->control, ULITE_CONTROL_RST_RX |
+ ULITE_CONTROL_RST_TX);
+ }
return 0;
}
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);
+ int ret;
+
+ uart_out32(®s->control, 0);
+ uart_out32(®s->control, ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX);
+ uart_in32(®s->status);
+ /* Endianness detection */
+ if ((ret & SR_TX_FIFO_EMPTY) != SR_TX_FIFO_EMPTY) {
+ little_endian = true;
+ uart_out32(®s->control, ULITE_CONTROL_RST_RX |
+ ULITE_CONTROL_RST_TX);
+ }
}
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)
+ while (uart_in32(®s->status) & SR_TX_FIFO_FULL)
;
- out_be32(®s->tx_fifo, ch & 0xff);
+ uart_out32(®s->tx_fifo, ch & 0xff);
}
DEBUG_UART_FUNCS