Skip to content

Commit 5d23188

Browse files
Ulrich Hechtgregkh
authored andcommitted
serial: sh-sci: make RX FIFO parameters tunable via sysfs
Allows tuning of the RX FIFO fill threshold and timeout. (The latter is only applicable to SCIFA and SCIFB). Signed-off-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0394037 commit 5d23188

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

drivers/tty/serial/sh-sci.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,66 @@ static void rx_fifo_timer_fn(unsigned long arg)
10551055
scif_set_rtrg(port, 1);
10561056
}
10571057

1058+
static ssize_t rx_trigger_show(struct device *dev,
1059+
struct device_attribute *attr,
1060+
char *buf)
1061+
{
1062+
struct uart_port *port = dev_get_drvdata(dev);
1063+
struct sci_port *sci = to_sci_port(port);
1064+
1065+
return sprintf(buf, "%d\n", sci->rx_trigger);
1066+
}
1067+
1068+
static ssize_t rx_trigger_store(struct device *dev,
1069+
struct device_attribute *attr,
1070+
const char *buf,
1071+
size_t count)
1072+
{
1073+
struct uart_port *port = dev_get_drvdata(dev);
1074+
struct sci_port *sci = to_sci_port(port);
1075+
long r;
1076+
1077+
if (kstrtol(buf, 0, &r) == -EINVAL)
1078+
return -EINVAL;
1079+
sci->rx_trigger = scif_set_rtrg(port, r);
1080+
scif_set_rtrg(port, 1);
1081+
return count;
1082+
}
1083+
1084+
static DEVICE_ATTR(rx_fifo_trigger, 0644, rx_trigger_show, rx_trigger_store);
1085+
1086+
static ssize_t rx_fifo_timeout_show(struct device *dev,
1087+
struct device_attribute *attr,
1088+
char *buf)
1089+
{
1090+
struct uart_port *port = dev_get_drvdata(dev);
1091+
struct sci_port *sci = to_sci_port(port);
1092+
1093+
return sprintf(buf, "%d\n", sci->rx_fifo_timeout);
1094+
}
1095+
1096+
static ssize_t rx_fifo_timeout_store(struct device *dev,
1097+
struct device_attribute *attr,
1098+
const char *buf,
1099+
size_t count)
1100+
{
1101+
struct uart_port *port = dev_get_drvdata(dev);
1102+
struct sci_port *sci = to_sci_port(port);
1103+
long r;
1104+
1105+
if (kstrtol(buf, 0, &r) == -EINVAL)
1106+
return -EINVAL;
1107+
sci->rx_fifo_timeout = r;
1108+
scif_set_rtrg(port, 1);
1109+
if (r > 0)
1110+
setup_timer(&sci->rx_fifo_timer, rx_fifo_timer_fn,
1111+
(unsigned long)sci);
1112+
return count;
1113+
}
1114+
1115+
static DEVICE_ATTR(rx_fifo_timeout, 0644, rx_fifo_timeout_show, rx_fifo_timeout_store);
1116+
1117+
10581118
#ifdef CONFIG_SERIAL_SH_SCI_DMA
10591119
static void sci_dma_tx_complete(void *arg)
10601120
{
@@ -2886,6 +2946,15 @@ static int sci_remove(struct platform_device *dev)
28862946

28872947
sci_cleanup_single(port);
28882948

2949+
if (port->port.fifosize > 1) {
2950+
sysfs_remove_file(&dev->dev.kobj,
2951+
&dev_attr_rx_fifo_trigger.attr);
2952+
}
2953+
if (port->port.type == PORT_SCIFA || port->port.type == PORT_SCIFB) {
2954+
sysfs_remove_file(&dev->dev.kobj,
2955+
&dev_attr_rx_fifo_timeout.attr);
2956+
}
2957+
28892958
return 0;
28902959
}
28912960

@@ -3051,6 +3120,24 @@ static int sci_probe(struct platform_device *dev)
30513120
if (ret)
30523121
return ret;
30533122

3123+
if (sp->port.fifosize > 1) {
3124+
ret = sysfs_create_file(&dev->dev.kobj,
3125+
&dev_attr_rx_fifo_trigger.attr);
3126+
if (ret)
3127+
return ret;
3128+
}
3129+
if (sp->port.type == PORT_SCIFA || sp->port.type == PORT_SCIFB) {
3130+
ret = sysfs_create_file(&dev->dev.kobj,
3131+
&dev_attr_rx_fifo_timeout.attr);
3132+
if (ret) {
3133+
if (sp->port.fifosize > 1) {
3134+
sysfs_remove_file(&dev->dev.kobj,
3135+
&dev_attr_rx_fifo_trigger.attr);
3136+
}
3137+
return ret;
3138+
}
3139+
}
3140+
30543141
#ifdef CONFIG_SH_STANDARD_BIOS
30553142
sh_bios_gdb_detach();
30563143
#endif

0 commit comments

Comments
 (0)