Skip to content

Commit d7875b4

Browse files
vvfedorenkoPaolo Abeni
authored andcommitted
ptp: ocp: convert serial ports to array
Simplify serial port management code by using array of ports and helpers to get the name of the port. This change is needed to make the next patch simplier. Signed-off-by: Vadim Fedorenko <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 2560db6 commit d7875b4

File tree

1 file changed

+57
-63
lines changed

1 file changed

+57
-63
lines changed

drivers/ptp/ptp_ocp.c

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ struct ptp_ocp_serial_port {
316316
#define OCP_SERIAL_LEN 6
317317
#define OCP_SMA_NUM 4
318318

319+
enum {
320+
PORT_GNSS,
321+
PORT_GNSS2,
322+
PORT_MAC, /* miniature atomic clock */
323+
PORT_NMEA,
324+
325+
__PORT_COUNT,
326+
};
327+
319328
struct ptp_ocp {
320329
struct pci_dev *pdev;
321330
struct device dev;
@@ -357,10 +366,7 @@ struct ptp_ocp {
357366
struct delayed_work sync_work;
358367
int id;
359368
int n_irqs;
360-
struct ptp_ocp_serial_port gnss_port;
361-
struct ptp_ocp_serial_port gnss2_port;
362-
struct ptp_ocp_serial_port mac_port; /* miniature atomic clock */
363-
struct ptp_ocp_serial_port nmea_port;
369+
struct ptp_ocp_serial_port port[__PORT_COUNT];
364370
bool fw_loader;
365371
u8 fw_tag;
366372
u16 fw_version;
@@ -655,28 +661,28 @@ static struct ocp_resource ocp_fb_resource[] = {
655661
},
656662
},
657663
{
658-
OCP_SERIAL_RESOURCE(gnss_port),
664+
OCP_SERIAL_RESOURCE(port[PORT_GNSS]),
659665
.offset = 0x00160000 + 0x1000, .irq_vec = 3,
660666
.extra = &(struct ptp_ocp_serial_port) {
661667
.baud = 115200,
662668
},
663669
},
664670
{
665-
OCP_SERIAL_RESOURCE(gnss2_port),
671+
OCP_SERIAL_RESOURCE(port[PORT_GNSS2]),
666672
.offset = 0x00170000 + 0x1000, .irq_vec = 4,
667673
.extra = &(struct ptp_ocp_serial_port) {
668674
.baud = 115200,
669675
},
670676
},
671677
{
672-
OCP_SERIAL_RESOURCE(mac_port),
678+
OCP_SERIAL_RESOURCE(port[PORT_MAC]),
673679
.offset = 0x00180000 + 0x1000, .irq_vec = 5,
674680
.extra = &(struct ptp_ocp_serial_port) {
675681
.baud = 57600,
676682
},
677683
},
678684
{
679-
OCP_SERIAL_RESOURCE(nmea_port),
685+
OCP_SERIAL_RESOURCE(port[PORT_NMEA]),
680686
.offset = 0x00190000 + 0x1000, .irq_vec = 10,
681687
},
682688
{
@@ -740,7 +746,7 @@ static struct ocp_resource ocp_art_resource[] = {
740746
.offset = 0x01000000, .size = 0x10000,
741747
},
742748
{
743-
OCP_SERIAL_RESOURCE(gnss_port),
749+
OCP_SERIAL_RESOURCE(port[PORT_GNSS]),
744750
.offset = 0x00160000 + 0x1000, .irq_vec = 3,
745751
.extra = &(struct ptp_ocp_serial_port) {
746752
.baud = 115200,
@@ -839,7 +845,7 @@ static struct ocp_resource ocp_art_resource[] = {
839845
},
840846
},
841847
{
842-
OCP_SERIAL_RESOURCE(mac_port),
848+
OCP_SERIAL_RESOURCE(port[PORT_MAC]),
843849
.offset = 0x00190000, .irq_vec = 7,
844850
.extra = &(struct ptp_ocp_serial_port) {
845851
.baud = 9600,
@@ -950,14 +956,14 @@ static struct ocp_resource ocp_adva_resource[] = {
950956
.offset = 0x00220000, .size = 0x1000,
951957
},
952958
{
953-
OCP_SERIAL_RESOURCE(gnss_port),
959+
OCP_SERIAL_RESOURCE(port[PORT_GNSS]),
954960
.offset = 0x00160000 + 0x1000, .irq_vec = 3,
955961
.extra = &(struct ptp_ocp_serial_port) {
956962
.baud = 9600,
957963
},
958964
},
959965
{
960-
OCP_SERIAL_RESOURCE(mac_port),
966+
OCP_SERIAL_RESOURCE(port[PORT_MAC]),
961967
.offset = 0x00180000 + 0x1000, .irq_vec = 5,
962968
.extra = &(struct ptp_ocp_serial_port) {
963969
.baud = 115200,
@@ -1649,6 +1655,15 @@ ptp_ocp_tod_gnss_name(int idx)
16491655
return gnss_name[idx];
16501656
}
16511657

1658+
static const char *
1659+
ptp_ocp_tty_port_name(int idx)
1660+
{
1661+
static const char * const tty_name[] = {
1662+
"GNSS", "GNSS2", "MAC", "NMEA"
1663+
};
1664+
return tty_name[idx];
1665+
}
1666+
16521667
struct ptp_ocp_nvmem_match_info {
16531668
struct ptp_ocp *bp;
16541669
const void * const tag;
@@ -3960,16 +3975,11 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)
39603975
bp = dev_get_drvdata(dev);
39613976

39623977
seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp->ptp));
3963-
if (bp->gnss_port.line != -1)
3964-
seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS1",
3965-
bp->gnss_port.line);
3966-
if (bp->gnss2_port.line != -1)
3967-
seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS2",
3968-
bp->gnss2_port.line);
3969-
if (bp->mac_port.line != -1)
3970-
seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->mac_port.line);
3971-
if (bp->nmea_port.line != -1)
3972-
seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->nmea_port.line);
3978+
for (i = 0; i < __PORT_COUNT; i++) {
3979+
if (bp->port[i].line != -1)
3980+
seq_printf(s, "%7s: /dev/ttyS%d\n", ptp_ocp_tty_port_name(i),
3981+
bp->port[i].line);
3982+
}
39733983

39743984
memset(sma_val, 0xff, sizeof(sma_val));
39753985
if (bp->sma_map1) {
@@ -4279,7 +4289,7 @@ ptp_ocp_dev_release(struct device *dev)
42794289
static int
42804290
ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
42814291
{
4282-
int err;
4292+
int i, err;
42834293

42844294
mutex_lock(&ptp_ocp_lock);
42854295
err = idr_alloc(&ptp_ocp_idr, bp, 0, 0, GFP_KERNEL);
@@ -4292,10 +4302,10 @@ ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
42924302

42934303
bp->ptp_info = ptp_ocp_clock_info;
42944304
spin_lock_init(&bp->lock);
4295-
bp->gnss_port.line = -1;
4296-
bp->gnss2_port.line = -1;
4297-
bp->mac_port.line = -1;
4298-
bp->nmea_port.line = -1;
4305+
4306+
for (i = 0; i < __PORT_COUNT; i++)
4307+
bp->port[i].line = -1;
4308+
42994309
bp->pdev = pdev;
43004310

43014311
device_initialize(&bp->dev);
@@ -4351,23 +4361,15 @@ ptp_ocp_complete(struct ptp_ocp *bp)
43514361
{
43524362
struct pps_device *pps;
43534363
char buf[32];
4364+
int i;
43544365

4355-
if (bp->gnss_port.line != -1) {
4356-
sprintf(buf, "ttyS%d", bp->gnss_port.line);
4357-
ptp_ocp_link_child(bp, buf, "ttyGNSS");
4358-
}
4359-
if (bp->gnss2_port.line != -1) {
4360-
sprintf(buf, "ttyS%d", bp->gnss2_port.line);
4361-
ptp_ocp_link_child(bp, buf, "ttyGNSS2");
4362-
}
4363-
if (bp->mac_port.line != -1) {
4364-
sprintf(buf, "ttyS%d", bp->mac_port.line);
4365-
ptp_ocp_link_child(bp, buf, "ttyMAC");
4366-
}
4367-
if (bp->nmea_port.line != -1) {
4368-
sprintf(buf, "ttyS%d", bp->nmea_port.line);
4369-
ptp_ocp_link_child(bp, buf, "ttyNMEA");
4366+
for (i = 0; i < __PORT_COUNT; i++) {
4367+
if (bp->port[i].line != -1) {
4368+
sprintf(buf, "ttyS%d", bp->port[i].line);
4369+
ptp_ocp_link_child(bp, buf, ptp_ocp_tty_port_name(i));
4370+
}
43704371
}
4372+
43714373
sprintf(buf, "ptp%d", ptp_clock_index(bp->ptp));
43724374
ptp_ocp_link_child(bp, buf, "ptp");
43734375

@@ -4416,23 +4418,20 @@ ptp_ocp_info(struct ptp_ocp *bp)
44164418
};
44174419
struct device *dev = &bp->pdev->dev;
44184420
u32 reg;
4421+
int i;
44194422

44204423
ptp_ocp_phc_info(bp);
44214424

4422-
ptp_ocp_serial_info(dev, "GNSS", bp->gnss_port.line,
4423-
bp->gnss_port.baud);
4424-
ptp_ocp_serial_info(dev, "GNSS2", bp->gnss2_port.line,
4425-
bp->gnss2_port.baud);
4426-
ptp_ocp_serial_info(dev, "MAC", bp->mac_port.line, bp->mac_port.baud);
4427-
if (bp->nmea_out && bp->nmea_port.line != -1) {
4428-
bp->nmea_port.baud = -1;
4425+
for (i = 0; i < __PORT_COUNT; i++) {
4426+
if (i == PORT_NMEA && bp->nmea_out && bp->port[PORT_NMEA].line != -1) {
4427+
bp->port[PORT_NMEA].baud = -1;
44294428

4430-
reg = ioread32(&bp->nmea_out->uart_baud);
4431-
if (reg < ARRAY_SIZE(nmea_baud))
4432-
bp->nmea_port.baud = nmea_baud[reg];
4433-
4434-
ptp_ocp_serial_info(dev, "NMEA", bp->nmea_port.line,
4435-
bp->nmea_port.baud);
4429+
reg = ioread32(&bp->nmea_out->uart_baud);
4430+
if (reg < ARRAY_SIZE(nmea_baud))
4431+
bp->port[PORT_NMEA].baud = nmea_baud[reg];
4432+
}
4433+
ptp_ocp_serial_info(dev, ptp_ocp_tty_port_name(i), bp->port[i].line,
4434+
bp->port[i].baud);
44364435
}
44374436
}
44384437

@@ -4473,14 +4472,9 @@ ptp_ocp_detach(struct ptp_ocp *bp)
44734472
for (i = 0; i < 4; i++)
44744473
if (bp->signal_out[i])
44754474
ptp_ocp_unregister_ext(bp->signal_out[i]);
4476-
if (bp->gnss_port.line != -1)
4477-
serial8250_unregister_port(bp->gnss_port.line);
4478-
if (bp->gnss2_port.line != -1)
4479-
serial8250_unregister_port(bp->gnss2_port.line);
4480-
if (bp->mac_port.line != -1)
4481-
serial8250_unregister_port(bp->mac_port.line);
4482-
if (bp->nmea_port.line != -1)
4483-
serial8250_unregister_port(bp->nmea_port.line);
4475+
for (i = 0; i < __PORT_COUNT; i++)
4476+
if (bp->port[i].line != -1)
4477+
serial8250_unregister_port(bp->port[i].line);
44844478
platform_device_unregister(bp->spi_flash);
44854479
platform_device_unregister(bp->i2c_ctrl);
44864480
if (bp->i2c_clk)

0 commit comments

Comments
 (0)