drivers: serial: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and dev->config instead. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
e8c15f68b2
commit
1674fec5b6
26 changed files with 700 additions and 623 deletions
|
@ -190,14 +190,6 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "NS16550(s) in DT need CONFIG_PCIE");
|
|||
#define MSR_RI 0x40 /* complement of ring signal */
|
||||
#define MSR_DCD 0x80 /* complement of dcd */
|
||||
|
||||
/* convenience defines */
|
||||
|
||||
#define DEV_CFG(dev) \
|
||||
((const struct uart_ns16550_device_config * const) \
|
||||
(dev)->config)
|
||||
#define DEV_DATA(dev) \
|
||||
((struct uart_ns16550_dev_data *)(dev)->data)
|
||||
|
||||
#define THR(dev) (get_port(dev) + REG_THR * reg_interval(dev))
|
||||
#define RDR(dev) (get_port(dev) + REG_RDR * reg_interval(dev))
|
||||
#define BRDL(dev) (get_port(dev) + REG_BRDL * reg_interval(dev))
|
||||
|
@ -212,7 +204,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "NS16550(s) in DT need CONFIG_PCIE");
|
|||
#define DLF(dev) (get_port(dev) + REG_DLF)
|
||||
#define PCP(dev) (get_port(dev) + REG_PCP)
|
||||
|
||||
#define IIRC(dev) (DEV_DATA(dev)->iir_cache)
|
||||
#define IIRC(dev) (((struct uart_ns16550_dev_data *)(dev)->data)->iir_cache)
|
||||
|
||||
#ifdef UART_NS16550_ACCESS_IOPORT
|
||||
#define INBYTE(x) sys_in8(x)
|
||||
|
@ -292,8 +284,10 @@ struct uart_ns16550_dev_data {
|
|||
#if UART_NS16550_REG_INTERVAL_ENABLED
|
||||
static inline uint8_t reg_interval(const struct device *dev)
|
||||
{
|
||||
if (DEV_CFG(dev)->reg_interval) {
|
||||
return DEV_CFG(dev)->reg_interval;
|
||||
const struct uart_ns16550_device_config *config = dev->config;
|
||||
|
||||
if (config->reg_interval) {
|
||||
return config->reg_interval;
|
||||
}
|
||||
|
||||
return DEFAULT_REG_INTERVAL;
|
||||
|
@ -309,14 +303,16 @@ static inline uintptr_t get_port(const struct device *dev)
|
|||
#ifndef UART_NS16550_ACCESS_IOPORT
|
||||
return DEVICE_MMIO_GET(dev);
|
||||
#else
|
||||
return DEV_CFG(dev)->port;
|
||||
const struct uart_ns16550_device_config *config = dev->config;
|
||||
|
||||
return config->port;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void set_baud_rate(const struct device *dev, uint32_t baud_rate)
|
||||
{
|
||||
const struct uart_ns16550_device_config * const dev_cfg = DEV_CFG(dev);
|
||||
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
|
||||
const struct uart_ns16550_device_config * const dev_cfg = dev->config;
|
||||
struct uart_ns16550_dev_data * const dev_data = dev->data;
|
||||
uint32_t divisor; /* baud rate divisor */
|
||||
uint8_t lcr_cache;
|
||||
|
||||
|
@ -344,8 +340,8 @@ static void set_baud_rate(const struct device *dev, uint32_t baud_rate)
|
|||
static int uart_ns16550_configure(const struct device *dev,
|
||||
const struct uart_config *cfg)
|
||||
{
|
||||
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
|
||||
const struct uart_ns16550_device_config * const dev_cfg = DEV_CFG(dev);
|
||||
struct uart_ns16550_dev_data * const dev_data = dev->data;
|
||||
const struct uart_ns16550_device_config * const dev_cfg = dev->config;
|
||||
uint8_t mdc = 0U;
|
||||
|
||||
/* temp for return value if error occurs in this locked region */
|
||||
|
@ -496,7 +492,7 @@ out:
|
|||
static int uart_ns16550_config_get(const struct device *dev,
|
||||
struct uart_config *cfg)
|
||||
{
|
||||
struct uart_ns16550_dev_data *data = DEV_DATA(dev);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
|
||||
cfg->baudrate = data->uart_config.baudrate;
|
||||
cfg->parity = data->uart_config.parity;
|
||||
|
@ -519,15 +515,18 @@ static int uart_ns16550_config_get(const struct device *dev,
|
|||
*/
|
||||
static int uart_ns16550_init(const struct device *dev)
|
||||
{
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
int ret;
|
||||
|
||||
ret = uart_ns16550_configure(dev, &DEV_DATA(dev)->uart_config);
|
||||
ret = uart_ns16550_configure(dev, &data->uart_config);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
DEV_CFG(dev)->irq_config_func(dev);
|
||||
const struct uart_ns16550_device_config *config = dev->config;
|
||||
|
||||
config->irq_config_func(dev);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@ -543,8 +542,9 @@ static int uart_ns16550_init(const struct device *dev)
|
|||
*/
|
||||
static int uart_ns16550_poll_in(const struct device *dev, unsigned char *c)
|
||||
{
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
int ret = -1;
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
if ((INBYTE(LSR(dev)) & LSR_RXRDY) != 0) {
|
||||
/* got a character */
|
||||
|
@ -552,7 +552,7 @@ static int uart_ns16550_poll_in(const struct device *dev, unsigned char *c)
|
|||
ret = 0;
|
||||
}
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -572,14 +572,15 @@ static int uart_ns16550_poll_in(const struct device *dev, unsigned char *c)
|
|||
static void uart_ns16550_poll_out(const struct device *dev,
|
||||
unsigned char c)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
while ((INBYTE(LSR(dev)) & LSR_THRE) == 0) {
|
||||
}
|
||||
|
||||
OUTBYTE(THR(dev), c);
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -592,10 +593,11 @@ static void uart_ns16550_poll_out(const struct device *dev,
|
|||
*/
|
||||
static int uart_ns16550_err_check(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
int check = (INBYTE(LSR(dev)) & LSR_EOB_MASK);
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return check >> 1;
|
||||
}
|
||||
|
@ -615,14 +617,15 @@ static int uart_ns16550_fifo_fill(const struct device *dev,
|
|||
const uint8_t *tx_data,
|
||||
int size)
|
||||
{
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
int i;
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
for (i = 0; (i < size) && (i < DEV_DATA(dev)->fifo_size); i++) {
|
||||
for (i = 0; (i < size) && (i < data->fifo_size); i++) {
|
||||
OUTBYTE(THR(dev), tx_data[i]);
|
||||
}
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -639,14 +642,15 @@ static int uart_ns16550_fifo_fill(const struct device *dev,
|
|||
static int uart_ns16550_fifo_read(const struct device *dev, uint8_t *rx_data,
|
||||
const int size)
|
||||
{
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
int i;
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
for (i = 0; (i < size) && (INBYTE(LSR(dev)) & LSR_RXRDY) != 0; i++) {
|
||||
rx_data[i] = INBYTE(RDR(dev));
|
||||
}
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -658,7 +662,8 @@ static int uart_ns16550_fifo_read(const struct device *dev, uint8_t *rx_data,
|
|||
*/
|
||||
static void uart_ns16550_irq_tx_enable(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_PM)
|
||||
struct uart_ns16550_dev_data *const dev_data = dev->data;
|
||||
|
@ -682,7 +687,7 @@ static void uart_ns16550_irq_tx_enable(const struct device *dev)
|
|||
#endif
|
||||
OUTBYTE(IER(dev), INBYTE(IER(dev)) | IER_TBE);
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -692,7 +697,8 @@ static void uart_ns16550_irq_tx_enable(const struct device *dev)
|
|||
*/
|
||||
static void uart_ns16550_irq_tx_disable(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
OUTBYTE(IER(dev), INBYTE(IER(dev)) & (~IER_TBE));
|
||||
|
||||
|
@ -716,7 +722,7 @@ static void uart_ns16550_irq_tx_disable(const struct device *dev)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -728,11 +734,12 @@ static void uart_ns16550_irq_tx_disable(const struct device *dev)
|
|||
*/
|
||||
static int uart_ns16550_irq_tx_ready(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
int ret = ((IIRC(dev) & IIR_ID) == IIR_THRE) ? 1 : 0;
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -746,12 +753,13 @@ static int uart_ns16550_irq_tx_ready(const struct device *dev)
|
|||
*/
|
||||
static int uart_ns16550_irq_tx_complete(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
int ret = ((INBYTE(LSR(dev)) & (LSR_TEMT | LSR_THRE))
|
||||
== (LSR_TEMT | LSR_THRE)) ? 1 : 0;
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -763,11 +771,12 @@ static int uart_ns16550_irq_tx_complete(const struct device *dev)
|
|||
*/
|
||||
static void uart_ns16550_irq_rx_enable(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
OUTBYTE(IER(dev), INBYTE(IER(dev)) | IER_RXRDY);
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -777,11 +786,12 @@ static void uart_ns16550_irq_rx_enable(const struct device *dev)
|
|||
*/
|
||||
static void uart_ns16550_irq_rx_disable(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
OUTBYTE(IER(dev), INBYTE(IER(dev)) & (~IER_RXRDY));
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -793,11 +803,12 @@ static void uart_ns16550_irq_rx_disable(const struct device *dev)
|
|||
*/
|
||||
static int uart_ns16550_irq_rx_ready(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
int ret = ((IIRC(dev) & IIR_ID) == IIR_RBRF) ? 1 : 0;
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -809,11 +820,12 @@ static int uart_ns16550_irq_rx_ready(const struct device *dev)
|
|||
*/
|
||||
static void uart_ns16550_irq_err_enable(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
OUTBYTE(IER(dev), INBYTE(IER(dev)) | IER_LSR);
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -825,11 +837,12 @@ static void uart_ns16550_irq_err_enable(const struct device *dev)
|
|||
*/
|
||||
static void uart_ns16550_irq_err_disable(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
OUTBYTE(IER(dev), INBYTE(IER(dev)) & (~IER_LSR));
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -841,11 +854,12 @@ static void uart_ns16550_irq_err_disable(const struct device *dev)
|
|||
*/
|
||||
static int uart_ns16550_irq_is_pending(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
int ret = (!(IIRC(dev) & IIR_NIP)) ? 1 : 0;
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -859,11 +873,12 @@ static int uart_ns16550_irq_is_pending(const struct device *dev)
|
|||
*/
|
||||
static int uart_ns16550_irq_update(const struct device *dev)
|
||||
{
|
||||
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
IIRC(dev) = INBYTE(IIR(dev));
|
||||
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -878,7 +893,7 @@ static void uart_ns16550_irq_callback_set(const struct device *dev,
|
|||
uart_irq_callback_user_data_t cb,
|
||||
void *cb_data)
|
||||
{
|
||||
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
|
||||
struct uart_ns16550_dev_data * const dev_data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
|
||||
|
||||
dev_data->cb = cb;
|
||||
|
@ -896,7 +911,7 @@ static void uart_ns16550_irq_callback_set(const struct device *dev,
|
|||
*/
|
||||
static void uart_ns16550_isr(const struct device *dev)
|
||||
{
|
||||
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
|
||||
struct uart_ns16550_dev_data * const dev_data = dev->data;
|
||||
|
||||
if (dev_data->cb) {
|
||||
dev_data->cb(dev, dev_data->cb_data);
|
||||
|
@ -926,6 +941,7 @@ static void uart_ns16550_isr(const struct device *dev)
|
|||
static int uart_ns16550_line_ctrl_set(const struct device *dev,
|
||||
uint32_t ctrl, uint32_t val)
|
||||
{
|
||||
struct uart_ns16550_dev_data *data = dev->data;
|
||||
uint32_t mdc, chg;
|
||||
k_spinlock_key_t key;
|
||||
|
||||
|
@ -936,7 +952,7 @@ static int uart_ns16550_line_ctrl_set(const struct device *dev,
|
|||
|
||||
case UART_LINE_CTRL_RTS:
|
||||
case UART_LINE_CTRL_DTR:
|
||||
key = k_spin_lock(&DEV_DATA(dev)->lock);
|
||||
key = k_spin_lock(&data->lock);
|
||||
mdc = INBYTE(MDC(dev));
|
||||
|
||||
if (ctrl == UART_LINE_CTRL_RTS) {
|
||||
|
@ -951,7 +967,7 @@ static int uart_ns16550_line_ctrl_set(const struct device *dev,
|
|||
mdc &= ~(chg);
|
||||
}
|
||||
OUTBYTE(MDC(dev), mdc);
|
||||
k_spin_unlock(&DEV_DATA(dev)->lock, key);
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -976,7 +992,7 @@ static int uart_ns16550_drv_cmd(const struct device *dev, uint32_t cmd,
|
|||
{
|
||||
#if UART_NS16550_DLF_ENABLED
|
||||
if (cmd == CMD_SET_DLF) {
|
||||
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
|
||||
struct uart_ns16550_dev_data * const dev_data = dev->data;
|
||||
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
|
||||
|
||||
dev_data->dlf = p;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue