serial: ns16550: Increase scope of ops functions

Increase scope of ops functions and do some clean up for usage in device
-specific UART drivers.

Remove the static functionality of ops functions and migrate certain macros
to header file for usage in device-specific drivers.

Signed-off-by: Gokul Praveen <g-praveen@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Gokul Praveen 2024-11-26 16:21:30 +05:30 committed by Tom Rini
parent 3881c6b903
commit a9c61ac04f
2 changed files with 26 additions and 17 deletions

View file

@ -12,7 +12,6 @@
#include <log.h>
#include <ns16550.h>
#include <reset.h>
#include <serial.h>
#include <spl.h>
#include <watchdog.h>
#include <asm/global_data.h>
@ -158,7 +157,7 @@ static inline int serial_in_dynamic(struct ns16550_plat *plat, u8 *addr)
#endif /* CONFIG_NS16550_DYNAMIC */
static void ns16550_writeb(struct ns16550 *port, int offset, int value)
void ns16550_writeb(struct ns16550 *port, int offset, int value)
{
struct ns16550_plat *plat = port->plat;
unsigned char *addr;
@ -193,13 +192,6 @@ static u32 ns16550_getfcr(struct ns16550 *port)
return plat->fcr;
}
/* We can clean these up once everything is moved to driver model */
#define serial_out(value, addr) \
ns16550_writeb(com_port, \
(unsigned char *)addr - (unsigned char *)com_port, value)
#define serial_in(addr) \
ns16550_readb(com_port, \
(unsigned char *)addr - (unsigned char *)com_port)
#else
static u32 ns16550_getfcr(struct ns16550 *port)
{
@ -214,7 +206,7 @@ int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate)
return DIV_ROUND_CLOSEST(clock, mode_x_div * baudrate);
}
static void ns16550_setbrg(struct ns16550 *com_port, int baud_divisor)
void ns16550_setbrg(struct ns16550 *com_port, int baud_divisor)
{
/* to keep serial format, read lcr before writing BKSE */
int lcr_val = serial_in(&com_port->lcr) & ~UART_LCR_BKSE;
@ -380,7 +372,7 @@ DEBUG_UART_FUNCS
#endif
#if CONFIG_IS_ENABLED(DM_SERIAL)
static int ns16550_serial_putc(struct udevice *dev, const char ch)
int ns16550_serial_putc(struct udevice *dev, const char ch)
{
struct ns16550 *const com_port = dev_get_priv(dev);
@ -400,7 +392,7 @@ static int ns16550_serial_putc(struct udevice *dev, const char ch)
return 0;
}
static int ns16550_serial_pending(struct udevice *dev, bool input)
int ns16550_serial_pending(struct udevice *dev, bool input)
{
struct ns16550 *const com_port = dev_get_priv(dev);
@ -410,7 +402,7 @@ static int ns16550_serial_pending(struct udevice *dev, bool input)
return (serial_in(&com_port->lsr) & UART_LSR_THRE) ? 0 : 1;
}
static int ns16550_serial_getc(struct udevice *dev)
int ns16550_serial_getc(struct udevice *dev)
{
struct ns16550 *const com_port = dev_get_priv(dev);
@ -420,7 +412,7 @@ static int ns16550_serial_getc(struct udevice *dev)
return serial_in(&com_port->rbr);
}
static int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
{
struct ns16550 *const com_port = dev_get_priv(dev);
struct ns16550_plat *plat = com_port->plat;
@ -433,7 +425,7 @@ static int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
return 0;
}
static int ns16550_serial_setconfig(struct udevice *dev, uint serial_config)
int ns16550_serial_setconfig(struct udevice *dev, uint serial_config)
{
struct ns16550 *const com_port = dev_get_priv(dev);
int lcr_val = UART_LCR_WLS_8;
@ -466,8 +458,7 @@ static int ns16550_serial_setconfig(struct udevice *dev, uint serial_config)
return 0;
}
static int ns16550_serial_getinfo(struct udevice *dev,
struct serial_device_info *info)
int ns16550_serial_getinfo(struct udevice *dev, struct serial_device_info *info)
{
struct ns16550 *const com_port = dev_get_priv(dev);
struct ns16550_plat *plat = com_port->plat;

View file

@ -25,6 +25,7 @@
#define __ns16550_h
#include <linux/types.h>
#include <serial.h>
#if CONFIG_IS_ENABLED(DM_SERIAL) || defined(CONFIG_NS16550_DYNAMIC) || \
defined(CONFIG_DEBUG_UART)
@ -116,6 +117,15 @@ struct ns16550 {
#endif
};
#if CONFIG_IS_ENABLED(DM_SERIAL)
#define serial_out(value, addr) \
ns16550_writeb(com_port, \
(unsigned char *)(addr) - (unsigned char *)com_port, value)
#define serial_in(addr) \
ns16550_readb(com_port, \
(unsigned char *)(addr) - (unsigned char *)com_port)
#endif
#define thr rbr
#define iir fcr
#define dll rbr
@ -225,6 +235,14 @@ void ns16550_putc(struct ns16550 *com_port, char c);
char ns16550_getc(struct ns16550 *com_port);
int ns16550_tstc(struct ns16550 *com_port);
void ns16550_reinit(struct ns16550 *com_port, int baud_divisor);
int ns16550_serial_putc(struct udevice *dev, const char ch);
int ns16550_serial_pending(struct udevice *dev, bool input);
int ns16550_serial_getc(struct udevice *dev);
int ns16550_serial_setbrg(struct udevice *dev, int baudrate);
int ns16550_serial_setconfig(struct udevice *dev, uint serial_config);
int ns16550_serial_getinfo(struct udevice *dev, struct serial_device_info *info);
void ns16550_writeb(struct ns16550 *port, int offset, int value);
void ns16550_setbrg(struct ns16550 *com_port, int baud_divisor);
/**
* ns16550_calc_divisor() - calculate the divisor given clock and baud rate