11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
285278139SSumit Garg /*
385278139SSumit Garg * Copyright (C) 2015 Freescale Semiconductor, Inc.
41eacd17cSSumit Garg * Copyright (c) 2020, Linaro Limited
585278139SSumit Garg * All rights reserved.
685278139SSumit Garg *
785278139SSumit Garg * Redistribution and use in source and binary forms, with or without
885278139SSumit Garg * modification, are permitted provided that the following conditions are met:
985278139SSumit Garg *
1085278139SSumit Garg * 1. Redistributions of source code must retain the above copyright notice,
1185278139SSumit Garg * this list of conditions and the following disclaimer.
1285278139SSumit Garg *
1385278139SSumit Garg * 2. Redistributions in binary form must reproduce the above copyright notice,
1485278139SSumit Garg * this list of conditions and the following disclaimer in the documentation
1585278139SSumit Garg * and/or other materials provided with the distribution.
1685278139SSumit Garg *
1785278139SSumit Garg * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1885278139SSumit Garg * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1985278139SSumit Garg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2085278139SSumit Garg * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2185278139SSumit Garg * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2285278139SSumit Garg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2385278139SSumit Garg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2485278139SSumit Garg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2585278139SSumit Garg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2685278139SSumit Garg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2785278139SSumit Garg * POSSIBILITY OF SUCH DAMAGE.
2885278139SSumit Garg */
29*fbe66cf8SEtienne Carriere #ifndef __DRIVERS_NS16550_H
30*fbe66cf8SEtienne Carriere #define __DRIVERS_NS16550_H
3185278139SSumit Garg
322e5aa31bSJerome Forissier #include <drivers/serial.h>
331eacd17cSSumit Garg #include <io.h>
341eacd17cSSumit Garg #include <types_ext.h>
351eacd17cSSumit Garg
36199cc636SAlvin Chang #define NS16550_UART_REG_SIZE 0x1000
37199cc636SAlvin Chang
381eacd17cSSumit Garg #define IO_WIDTH_U8 0
391eacd17cSSumit Garg #define IO_WIDTH_U32 1
4085278139SSumit Garg
412e5aa31bSJerome Forissier struct ns16550_data {
422e5aa31bSJerome Forissier struct io_pa_va base;
432e5aa31bSJerome Forissier struct serial_chip chip;
441eacd17cSSumit Garg uint8_t io_width;
451eacd17cSSumit Garg uint8_t reg_shift;
462e5aa31bSJerome Forissier };
4785278139SSumit Garg
serial_in(vaddr_t addr,uint8_t io_width)481eacd17cSSumit Garg static inline unsigned int serial_in(vaddr_t addr, uint8_t io_width)
491eacd17cSSumit Garg {
501eacd17cSSumit Garg if (io_width == IO_WIDTH_U32)
511eacd17cSSumit Garg return io_read32(addr);
521eacd17cSSumit Garg else
531eacd17cSSumit Garg return io_read8(addr);
541eacd17cSSumit Garg }
551eacd17cSSumit Garg
serial_out(vaddr_t addr,uint8_t io_width,int ch)561eacd17cSSumit Garg static inline void serial_out(vaddr_t addr, uint8_t io_width, int ch)
571eacd17cSSumit Garg {
581eacd17cSSumit Garg if (io_width == IO_WIDTH_U32)
591eacd17cSSumit Garg io_write32(addr, ch);
601eacd17cSSumit Garg else
611eacd17cSSumit Garg io_write8(addr, ch);
621eacd17cSSumit Garg }
631eacd17cSSumit Garg
641eacd17cSSumit Garg void ns16550_init(struct ns16550_data *pd, paddr_t base, uint8_t io_width,
651eacd17cSSumit Garg uint8_t reg_shift);
6685278139SSumit Garg
67*fbe66cf8SEtienne Carriere #endif /* __DRIVERS_NS16550_H */
68