Skip to content

Commit f0be3bb

Browse files
xuyanopsiff
authored andcommitted
uart-v2: phytium: Fix debug/heartbeat functional
issue Since the debug/heartbeat function does not work well in some circumstances, we update related inferfaces of phytium-uart-v2 driver. Signed-off-by: xuyan <xuyan1481@phytium.com.cn> Signed-off-by: Feng Jun <fengjun@phytium.com.cn> Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
1 parent 66d2694 commit f0be3bb

1 file changed

Lines changed: 29 additions & 34 deletions

File tree

drivers/tty/serial/phytium-uart-v2.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define cmd_id_type uint8_t
3131
#define cmd_subid_type uint8_t
3232
#define DEFAULT_CLK 10000000
33-
#define PHYT_UART_DRV_VER "1.1.0"
33+
#define PHYT_UART_DRV_VER "1.1.1"
3434
/*
3535
* We wrap our port structure around the generic uart_port.
3636
*/
@@ -43,8 +43,8 @@ struct phytium_uart_port {
4343
struct clk *clk;
4444
void __iomem *shmem_base;
4545
bool m_buf_empty;
46-
bool heartbeat_enable_flag;
47-
bool debug_enable_flag;
46+
bool heartbeat_enable;
47+
bool debug_enable;
4848
struct timer_list alive_timer;
4949
};
5050

@@ -1073,51 +1073,49 @@ static int phytium_register_port(struct phytium_uart_port *pup)
10731073
return rc;
10741074
}
10751075

1076-
#if defined(SERIAL_PHYTIUM_V2_DEBUG)
1076+
#if defined(CONFIG_SERIAL_PHYTIUM_V2_DEBUG)
10771077
static int phytium_uart_enable_debug(struct phytium_uart_port *pup,
1078-
bool new_enable_flag)
1078+
bool enable)
10791079
{
10801080
u32 dbg_regval;
1081-
static bool old_enable_flag;
10821081

1083-
if (old_enable_flag == new_enable_flag) {
1082+
if (pup->debug_enable == enable) {
10841083
pr_warn("PHYUART:set enable debug with repeative operation.\n");
1085-
return -1;
1084+
return -EINVAL;
10861085
}
1087-
old_enable_flag = new_enable_flag;
1086+
pup->debug_enable = enable;
10881087
dbg_regval = phytium_uart_read(pup, PHYUART_DBG_REG);
1089-
pr_info("PHYUART: %s debug_regval %x\n", __func__, dbg_regval);
1090-
if (!old_enable_flag && (dbg_regval & PHYUART_DBG_ENABLE_MASK))
1088+
if (!enable && (dbg_regval & PHYUART_DBG_ENABLE_MASK))
10911089
dbg_regval &= ~PHYUART_DBG_ENABLE_MASK;
1092-
else if (dbg_regval && !(dbg_regval & PHYUART_DBG_ENABLE_MASK))
1090+
else if (enable && !(dbg_regval & PHYUART_DBG_ENABLE_MASK))
10931091
dbg_regval |= PHYUART_DBG_ENABLE_MASK;
10941092

1095-
pr_info("final PHYUART: %s debug_regval %x\n", __func__, dbg_regval);
10961093
phytium_uart_write(dbg_regval, pup, PHYUART_DBG_REG);
10971094
return 0;
10981095
}
10991096

11001097
static int phytium_uart_enable_heartbeat(struct phytium_uart_port *pup,
1101-
bool new_heartbeat_flag)
1098+
bool enable)
11021099
{
11031100
u32 dbg_regval;
1104-
static bool old_heartbeat_flag;
11051101

1106-
if (old_heartbeat_flag == new_heartbeat_flag) {
1102+
if (pup->heartbeat_enable == enable) {
11071103
pr_warn("PHYUART:set heartbeat with repeative operation.\n");
1108-
return -1;
1104+
return -EINVAL;
11091105
}
1110-
old_heartbeat_flag = new_heartbeat_flag;
1106+
pup->heartbeat_enable = enable;
11111107
dbg_regval = phytium_uart_read(pup, PHYUART_DBG_REG);
1112-
pr_info("PHYUART: %s dbg_regval %x\n", __func__, dbg_regval);
1113-
if (!old_heartbeat_flag && (dbg_regval & PHYUART_DBG_HEARTBEAT_MASK))
1108+
if (!enable && (dbg_regval & PHYUART_DBG_HEARTBEAT_MASK)) {
11141109
dbg_regval &= ~PHYUART_DBG_HEARTBEAT_MASK;
1115-
else if (dbg_regval && !(dbg_regval & PHYUART_DBG_HEARTBEAT_MASK))
1110+
phytium_uart_write(dbg_regval, pup, PHYUART_DBG_REG);
1111+
del_timer(&pup->alive_timer);
1112+
} else if (enable && !(dbg_regval & PHYUART_DBG_HEARTBEAT_MASK)) {
11161113
dbg_regval |= PHYUART_DBG_HEARTBEAT_MASK
11171114
| PHYUART_DBG_HEARTBEAT_ENABLE_MASK;
1115+
phytium_uart_write(dbg_regval, pup, PHYUART_DBG_REG);
1116+
add_timer(&pup->alive_timer);
1117+
}
11181118

1119-
pr_info("final PHYUART: %s dbg_regval %x\n", __func__, dbg_regval);
1120-
phytium_uart_write(dbg_regval, pup, PHYUART_DBG_REG);
11211119
return 0;
11221120
}
11231121

@@ -1133,7 +1131,6 @@ static void alive_timer_routine(struct timer_list *tlist)
11331131
}
11341132

11351133
dbg_regval = phytium_uart_read(pup, PHYUART_DBG_REG);
1136-
pr_debug("PHYUART: %s debug_regval 0x%x\n", __func__, dbg_regval);
11371134
phytium_uart_write(dbg_regval | PHYUART_DBG_HEARTBEAT_MASK,
11381135
pup, PHYUART_DBG_REG);
11391136
mod_timer(&pup->alive_timer, jiffies + msecs_to_jiffies(5000));
@@ -1144,7 +1141,7 @@ static ssize_t debug_enable_show(struct device *dev,
11441141
{
11451142
struct phytium_uart_port *pup = dev_get_drvdata(dev);
11461143

1147-
return sprintf(buf, "%d\n", pup->debug_enable_flag);
1144+
return sprintf(buf, "%d\n", pup->debug_enable);
11481145
}
11491146

11501147
static ssize_t debug_enable_store(struct device *dev,
@@ -1159,8 +1156,7 @@ static ssize_t debug_enable_store(struct device *dev,
11591156
ret = -EINVAL;
11601157
return ret;
11611158
}
1162-
pup->debug_enable_flag = enable;
1163-
phytium_uart_enable_debug(pup, pup->debug_enable_flag);
1159+
phytium_uart_enable_debug(pup, enable);
11641160
return count;
11651161
}
11661162

@@ -1169,7 +1165,7 @@ static ssize_t heartbeat_enable_show(struct device *dev,
11691165
{
11701166
struct phytium_uart_port *pup = dev_get_drvdata(dev);
11711167

1172-
return sprintf(buf, "%d\n", pup->heartbeat_enable_flag);
1168+
return sprintf(buf, "%d\n", pup->heartbeat_enable);
11731169
}
11741170

11751171
static ssize_t heartbeat_enable_store(struct device *dev,
@@ -1184,8 +1180,7 @@ static ssize_t heartbeat_enable_store(struct device *dev,
11841180
ret = -EINVAL;
11851181
return ret;
11861182
}
1187-
pup->heartbeat_enable_flag = heartbeat_enable;
1188-
phytium_uart_enable_heartbeat(pup, pup->heartbeat_enable_flag);
1183+
phytium_uart_enable_heartbeat(pup, heartbeat_enable);
11891184
return count;
11901185
}
11911186
static DEVICE_ATTR_RW(debug_enable);
@@ -1267,9 +1262,9 @@ static int phytium_uart_probe(struct platform_device *pdev)
12671262
pup->old_cr = 0;
12681263
pup->m_buf_empty = true;
12691264
snprintf(pup->type, sizeof(pup->type), "phytium,uart-v2");
1270-
#if defined(SERIAL_PHYTIUM_V2_DEBUG)
1271-
pup->debug_enable_flag = false;
1272-
pup->heartbeat_enable_flag = false;
1265+
#if defined(CONFIG_SERIAL_PHYTIUM_V2_DEBUG)
1266+
pup->debug_enable = false;
1267+
pup->heartbeat_enable = false;
12731268

12741269
phytium_uart_enable_heartbeat(pup, true);
12751270
phytium_uart_enable_debug(pup, true);
@@ -1293,7 +1288,7 @@ static int phytium_uart_probe(struct platform_device *pdev)
12931288
platform_set_drvdata(pdev, pup);
12941289
return phytium_register_port(pup);
12951290

1296-
#if defined(SERIAL_PHYTIUM_V2_DEBUG)
1291+
#if defined(CONFIG_SERIAL_PHYTIUM_V2_DEBUG)
12971292
heartbeat_enable_free:
12981293
device_remove_file(pup->dev, &dev_attr_heartbeat_enable);
12991294
debug_enable_free:

0 commit comments

Comments
 (0)